2 * Copyright 2006-2007 by Juniper Networks.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/sockio.h>
37 #include <sys/malloc.h>
38 #include <sys/kernel.h>
39 #include <sys/module.h>
40 #include <sys/socket.h>
41 #include <sys/queue.h>
44 #include <sys/endian.h>
49 #include <dev/pci/pcivar.h>
50 #include <dev/pci/pcireg.h>
51 #include <dev/pci/pcib_private.h>
55 #include <machine/resource.h>
56 #include <machine/bus.h>
57 #include <machine/intr_machdep.h>
58 #include <machine/ocpbus.h>
59 #include <machine/spr.h>
61 #include <powerpc/mpc85xx/ocpbus.h>
63 #define REG_CFG_ADDR 0x0000
64 #define CONFIG_ACCESS_ENABLE 0x80000000
66 #define REG_CFG_DATA 0x0004
67 #define REG_INT_ACK 0x0008
69 #define REG_POTAR(n) (0x0c00 + 0x20 * (n))
70 #define REG_POTEAR(n) (0x0c04 + 0x20 * (n))
71 #define REG_POWBAR(n) (0x0c08 + 0x20 * (n))
72 #define REG_POWAR(n) (0x0c10 + 0x20 * (n))
74 #define REG_PITAR(n) (0x0e00 - 0x20 * (n))
75 #define REG_PIWBAR(n) (0x0e08 - 0x20 * (n))
76 #define REG_PIWBEAR(n) (0x0e0c - 0x20 * (n))
77 #define REG_PIWAR(n) (0x0e10 - 0x20 * (n))
79 #define PCIR_FSL_LTSSM 0x404
80 #define FSL_LTSSM_L0 0x16
82 #define DEVFN(b, s, f) ((b << 16) | (s << 8) | f)
84 struct pci_ocp_softc {
88 bus_addr_t sc_iomem_va; /* Virtual mapping. */
89 bus_addr_t sc_iomem_alloc; /* Next allocation. */
90 struct rman sc_ioport;
91 bus_addr_t sc_ioport_va; /* Virtual mapping. */
92 bus_addr_t sc_ioport_alloc; /* Next allocation. */
94 struct resource *sc_res;
95 bus_space_handle_t sc_bsh;
96 bus_space_tag_t sc_bst;
102 /* Devices that need special attention. */
104 int sc_devfn_via_ide;
107 static int pci_ocp_attach(device_t);
108 static int pci_ocp_probe(device_t);
110 static struct resource *pci_ocp_alloc_resource(device_t, device_t, int, int *,
111 u_long, u_long, u_long, u_int);
112 static int pci_ocp_read_ivar(device_t, device_t, int, uintptr_t *);
113 static int pci_ocp_release_resource(device_t, device_t, int, int,
115 static int pci_ocp_write_ivar(device_t, device_t, int, uintptr_t);
117 static int pci_ocp_maxslots(device_t);
118 static uint32_t pci_ocp_read_config(device_t, u_int, u_int, u_int, u_int, int);
119 static void pci_ocp_write_config(device_t, u_int, u_int, u_int, u_int,
123 * Bus interface definitions.
125 static device_method_t pci_ocp_methods[] = {
126 /* Device interface */
127 DEVMETHOD(device_probe, pci_ocp_probe),
128 DEVMETHOD(device_attach, pci_ocp_attach),
131 DEVMETHOD(bus_print_child, bus_generic_print_child),
132 DEVMETHOD(bus_read_ivar, pci_ocp_read_ivar),
133 DEVMETHOD(bus_write_ivar, pci_ocp_write_ivar),
134 DEVMETHOD(bus_alloc_resource, pci_ocp_alloc_resource),
135 DEVMETHOD(bus_release_resource, pci_ocp_release_resource),
136 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
137 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
138 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
139 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
142 DEVMETHOD(pcib_maxslots, pci_ocp_maxslots),
143 DEVMETHOD(pcib_read_config, pci_ocp_read_config),
144 DEVMETHOD(pcib_write_config, pci_ocp_write_config),
145 DEVMETHOD(pcib_route_interrupt, pcib_route_interrupt),
150 static driver_t pci_ocp_driver = {
153 sizeof(struct pci_ocp_softc),
156 devclass_t pcib_devclass;
158 DRIVER_MODULE(pcib, ocpbus, pci_ocp_driver, pcib_devclass, 0, 0);
161 pci_ocp_cfgread(struct pci_ocp_softc *sc, u_int bus, u_int slot, u_int func,
162 u_int reg, int bytes)
166 if (bus == sc->sc_busnr)
169 addr = CONFIG_ACCESS_ENABLE;
170 addr |= (bus & 0xff) << 16;
171 addr |= (slot & 0x1f) << 11;
172 addr |= (func & 0x7) << 8;
175 addr |= (reg & 0xf00) << 16;
176 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_CFG_ADDR, addr);
180 data = bus_space_read_1(sc->sc_bst, sc->sc_bsh,
181 REG_CFG_DATA + (reg & 3));
184 data = le16toh(bus_space_read_2(sc->sc_bst, sc->sc_bsh,
185 REG_CFG_DATA + (reg & 2)));
188 data = le32toh(bus_space_read_4(sc->sc_bst, sc->sc_bsh,
199 pci_ocp_cfgwrite(struct pci_ocp_softc *sc, u_int bus, u_int slot, u_int func,
200 u_int reg, uint32_t data, int bytes)
204 if (bus == sc->sc_busnr)
207 addr = CONFIG_ACCESS_ENABLE;
208 addr |= (bus & 0xff) << 16;
209 addr |= (slot & 0x1f) << 11;
210 addr |= (func & 0x7) << 8;
213 addr |= (reg & 0xf00) << 16;
214 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_CFG_ADDR, addr);
218 bus_space_write_1(sc->sc_bst, sc->sc_bsh,
219 REG_CFG_DATA + (reg & 3), data);
222 bus_space_write_2(sc->sc_bst, sc->sc_bsh,
223 REG_CFG_DATA + (reg & 2), htole16(data));
226 bus_space_write_4(sc->sc_bst, sc->sc_bsh,
227 REG_CFG_DATA, htole32(data));
234 dump(struct pci_ocp_softc *sc)
238 #define RD(o) bus_space_read_4(sc->sc_bst, sc->sc_bsh, o)
239 for (i = 0; i < 5; i++) {
240 printf("POTAR%u =0x%08x\n", i, RD(REG_POTAR(i)));
241 printf("POTEAR%u =0x%08x\n", i, RD(REG_POTEAR(i)));
242 printf("POWBAR%u =0x%08x\n", i, RD(REG_POWBAR(i)));
243 printf("POWAR%u =0x%08x\n", i, RD(REG_POWAR(i)));
246 for (i = 1; i < 4; i++) {
247 printf("PITAR%u =0x%08x\n", i, RD(REG_PITAR(i)));
248 printf("PIWBAR%u =0x%08x\n", i, RD(REG_PIWBAR(i)));
249 printf("PIWBEAR%u=0x%08x\n", i, RD(REG_PIWBEAR(i)));
250 printf("PIWAR%u =0x%08x\n", i, RD(REG_PIWAR(i)));
255 for (i = 0; i < 0x48; i += 4) {
256 printf("cfg%02x=0x%08x\n", i, pci_ocp_cfgread(sc, 0, 0, 0,
263 pci_ocp_maxslots(device_t dev)
265 struct pci_ocp_softc *sc = device_get_softc(dev);
267 return ((sc->sc_pcie_cap) ? 0 : 31);
271 pci_ocp_read_config(device_t dev, u_int bus, u_int slot, u_int func,
272 u_int reg, int bytes)
274 struct pci_ocp_softc *sc = device_get_softc(dev);
277 if (bus == sc->sc_busnr && !sc->sc_pcie_cap && slot < 10)
279 devfn = DEVFN(bus, slot, func);
281 * For the host controller itself, pretend to be a standard
282 * PCI bridge, rather than a PowerPC processor. That way the
283 * generic PCI code will enumerate all subordinate busses
284 * and devices as usual.
286 if (sc->sc_pcie_cap && devfn == 0) {
287 if (reg == PCIR_CLASS && bytes == 1)
288 return (PCIC_BRIDGE);
289 if (reg == PCIR_SUBCLASS && bytes == 1)
290 return (PCIS_BRIDGE_PCI);
292 if (devfn == sc->sc_devfn_tundra)
294 if (devfn == sc->sc_devfn_via_ide && reg == PCIR_INTPIN)
296 return (pci_ocp_cfgread(sc, bus, slot, func, reg, bytes));
300 pci_ocp_write_config(device_t dev, u_int bus, u_int slot, u_int func,
301 u_int reg, uint32_t val, int bytes)
303 struct pci_ocp_softc *sc = device_get_softc(dev);
305 if (bus == sc->sc_busnr && !sc->sc_pcie_cap && slot < 10)
307 pci_ocp_cfgwrite(sc, bus, slot, func, reg, val, bytes);
311 pci_ocp_probe(device_t dev)
314 struct pci_ocp_softc *sc;
323 parent = device_get_parent(dev);
324 error = BUS_READ_IVAR(parent, dev, OCPBUS_IVAR_DEVTYPE, &devtype);
327 if (devtype != OCPBUS_DEVTYPE_PCIB)
330 sc = device_get_softc(dev);
334 sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_rid,
336 if (sc->sc_res == NULL)
339 sc->sc_bst = rman_get_bustag(sc->sc_res);
340 sc->sc_bsh = rman_get_bushandle(sc->sc_res);
344 cfgreg = pci_ocp_cfgread(sc, 0, 0, 0, PCIR_VENDOR, 2);
345 if (cfgreg != 0x1057 && cfgreg != 0x1957)
348 cfgreg = pci_ocp_cfgread(sc, 0, 0, 0, PCIR_CLASS, 1);
349 if (cfgreg != PCIC_PROCESSOR)
352 cfgreg = pci_ocp_cfgread(sc, 0, 0, 0, PCIR_SUBCLASS, 1);
353 if (cfgreg != PCIS_PROCESSOR_POWERPC)
356 cfgreg = pci_ocp_cfgread(sc, 0, 0, 0, PCIR_PROGIF, 1);
357 if (cfgreg != 0) /* RC mode = 0, EP mode = 1 */
361 capptr = pci_ocp_cfgread(sc, 0, 0, 0, PCIR_CAP_PTR, 1);
362 while (capptr != 0) {
363 cfgreg = pci_ocp_cfgread(sc, 0, 0, 0, capptr, 2);
364 switch (cfgreg & 0xff) {
365 case PCIY_PCIX: /* PCI-X */
368 case PCIY_EXPRESS: /* PCI Express */
369 type = "PCI Express";
370 sc->sc_pcie_cap = capptr;
373 capptr = (cfgreg >> 8) & 0xff;
376 error = bus_get_resource(dev, SYS_RES_MEMORY, 1, &start, &size);
377 if (error || start == 0 || size == 0)
380 snprintf(buf, sizeof(buf),
381 "Freescale on-chip %s host controller", type);
382 device_set_desc_copy(dev, buf);
383 error = BUS_PROBE_DEFAULT;
386 bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_rid, sc->sc_res);
391 pci_ocp_init_via(struct pci_ocp_softc *sc, uint16_t device, int bus,
395 if (device == 0x0686) {
396 pci_ocp_write_config(sc->sc_dev, bus, slot, fn, 0x52, 0x34, 1);
397 pci_ocp_write_config(sc->sc_dev, bus, slot, fn, 0x77, 0x00, 1);
398 pci_ocp_write_config(sc->sc_dev, bus, slot, fn, 0x83, 0x98, 1);
399 pci_ocp_write_config(sc->sc_dev, bus, slot, fn, 0x85, 0x03, 1);
400 } else if (device == 0x0571) {
401 sc->sc_devfn_via_ide = DEVFN(bus, slot, fn);
402 pci_ocp_write_config(sc->sc_dev, bus, slot, fn, 0x40, 0x0b, 1);
407 pci_ocp_init_bar(struct pci_ocp_softc *sc, int bus, int slot, int func,
411 uint32_t addr, mask, size;
414 reg = PCIR_BAR(barno);
416 if (DEVFN(bus, slot, func) == sc->sc_devfn_via_ide) {
418 case 0: addr = 0x1f0; break;
419 case 1: addr = 0x3f4; break;
420 case 2: addr = 0x170; break;
421 case 3: addr = 0x374; break;
422 case 4: addr = 0xcc0; break;
425 pci_ocp_write_config(sc->sc_dev, bus, slot, func, reg, addr, 4);
429 pci_ocp_write_config(sc->sc_dev, bus, slot, func, reg, ~0, 4);
430 size = pci_ocp_read_config(sc->sc_dev, bus, slot, func, reg, 4);
433 width = ((size & 7) == 4) ? 2 : 1;
435 if (size & 1) { /* I/O port */
436 allocp = &sc->sc_ioport_alloc;
438 if ((size & 0xffff0000) == 0)
440 } else { /* memory */
441 allocp = &sc->sc_iomem_alloc;
446 /* Sanity check (must be a power of 2). */
450 addr = (*allocp + mask) & ~mask;
451 *allocp = addr + size;
454 printf("PCI %u:%u:%u:%u: reg %x: size=%08x: addr=%08x\n",
455 device_get_unit(sc->sc_dev), bus, slot, func, reg,
458 pci_ocp_write_config(sc->sc_dev, bus, slot, func, reg, addr, 4);
460 pci_ocp_write_config(sc->sc_dev, bus, slot, func, reg + 4,
466 pci_ocp_route_int(struct pci_ocp_softc *sc, u_int bus, u_int slot, u_int func,
469 u_int devfn, intline;
471 devfn = DEVFN(bus, slot, func);
472 if (devfn == sc->sc_devfn_via_ide)
474 else if (devfn == sc->sc_devfn_via_ide + 1)
476 else if (devfn == sc->sc_devfn_via_ide + 2)
480 intline = intpin - 1;
481 intline += (bus != sc->sc_busnr) ? slot : 0;
482 intline = PIC_IRQ_EXT(intline & 3);
488 printf("PCI %u:%u:%u:%u: intpin %u: intline=%u\n",
489 device_get_unit(sc->sc_dev), bus, slot, func,
496 pci_ocp_init(struct pci_ocp_softc *sc, int bus, int nslots)
501 uint16_t vendor, device;
502 uint8_t command, hdrtype, class, subclass;
503 uint8_t intline, intpin;
506 for (slot = 0; slot < nslots; slot++) {
508 for (func = 0; func <= maxfunc; func++) {
509 hdrtype = pci_ocp_read_config(sc->sc_dev, bus, slot,
510 func, PCIR_HDRTYPE, 1);
511 if ((hdrtype & PCIM_HDRTYPE) > PCI_MAXHDRTYPE)
514 if (func == 0 && (hdrtype & PCIM_MFDEV))
515 maxfunc = PCI_FUNCMAX;
517 vendor = pci_ocp_read_config(sc->sc_dev, bus, slot,
518 func, PCIR_VENDOR, 2);
519 device = pci_ocp_read_config(sc->sc_dev, bus, slot,
520 func, PCIR_DEVICE, 2);
522 if (vendor == 0x1957 && device == 0x3fff) {
523 sc->sc_devfn_tundra = DEVFN(bus, slot, func);
527 command = pci_ocp_read_config(sc->sc_dev, bus, slot,
528 func, PCIR_COMMAND, 1);
529 command &= ~(PCIM_CMD_MEMEN | PCIM_CMD_PORTEN);
530 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
531 PCIR_COMMAND, command, 1);
533 if (vendor == 0x1106)
534 pci_ocp_init_via(sc, device, bus, slot, func);
536 /* Program the base address registers. */
537 maxbar = (hdrtype & PCIM_HDRTYPE) ? 1 : 6;
540 bar += pci_ocp_init_bar(sc, bus, slot, func,
543 /* Perform interrupt routing. */
544 intpin = pci_ocp_read_config(sc->sc_dev, bus, slot,
545 func, PCIR_INTPIN, 1);
546 intline = pci_ocp_route_int(sc, bus, slot, func,
548 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
549 PCIR_INTLINE, intline, 1);
551 command |= PCIM_CMD_MEMEN | PCIM_CMD_PORTEN;
552 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
553 PCIR_COMMAND, command, 1);
556 * Handle PCI-PCI bridges
558 class = pci_ocp_read_config(sc->sc_dev, bus, slot,
559 func, PCIR_CLASS, 1);
560 if (class != PCIC_BRIDGE)
562 subclass = pci_ocp_read_config(sc->sc_dev, bus, slot,
563 func, PCIR_SUBCLASS, 1);
564 if (subclass != PCIS_BRIDGE_PCI)
569 /* Program I/O decoder. */
570 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
571 PCIR_IOBASEL_1, sc->sc_ioport.rm_start >> 8, 1);
572 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
573 PCIR_IOLIMITL_1, sc->sc_ioport.rm_end >> 8, 1);
574 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
575 PCIR_IOBASEH_1, sc->sc_ioport.rm_start >> 16, 2);
576 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
577 PCIR_IOLIMITH_1, sc->sc_ioport.rm_end >> 16, 2);
579 /* Program (non-prefetchable) memory decoder. */
580 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
581 PCIR_MEMBASE_1, sc->sc_iomem.rm_start >> 16, 2);
582 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
583 PCIR_MEMLIMIT_1, sc->sc_iomem.rm_end >> 16, 2);
585 /* Program prefetchable memory decoder. */
586 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
587 PCIR_PMBASEL_1, 0x0010, 2);
588 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
589 PCIR_PMLIMITL_1, 0x000f, 2);
590 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
591 PCIR_PMBASEH_1, 0x00000000, 4);
592 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
593 PCIR_PMLIMITH_1, 0x00000000, 4);
595 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
596 PCIR_PRIBUS_1, bus, 1);
597 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
598 PCIR_SECBUS_1, secbus, 1);
599 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
600 PCIR_SUBBUS_1, 0xff, 1);
602 secbus = pci_ocp_init(sc, secbus,
603 (subclass == PCIS_BRIDGE_PCI) ? 32 : 1);
605 pci_ocp_write_config(sc->sc_dev, bus, slot, func,
606 PCIR_SUBBUS_1, secbus, 1);
614 pci_ocp_inbound(struct pci_ocp_softc *sc, int wnd, int tgt, u_long start,
615 u_long size, u_long pci_start)
617 uint32_t attr, bar, tar;
619 KASSERT(wnd > 0, ("%s: inbound window 0 is invalid", __func__));
622 case OCP85XX_TGTIF_RAM1:
623 attr = 0xa0f55000 | (ffsl(size) - 2);
630 bar = pci_start >> 12;
632 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_PITAR(wnd), tar);
633 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_PIWBEAR(wnd), 0);
634 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_PIWBAR(wnd), bar);
635 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_PIWAR(wnd), attr);
639 pci_ocp_outbound(struct pci_ocp_softc *sc, int wnd, int res, u_long start,
640 u_long size, u_long pci_start)
642 uint32_t attr, bar, tar;
646 attr = 0x80044000 | (ffsl(size) - 2);
649 attr = 0x80088000 | (ffsl(size) - 2);
656 tar = pci_start >> 12;
658 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_POTAR(wnd), tar);
659 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_POTEAR(wnd), 0);
660 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_POWBAR(wnd), bar);
661 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_POWAR(wnd), attr);
665 pci_ocp_iorange(struct pci_ocp_softc *sc, int type, int wnd)
668 u_long start, end, size, alloc;
669 bus_addr_t pci_start, pci_end;
670 bus_addr_t *vap, *allocp;
673 error = bus_get_resource(sc->sc_dev, type, 1, &start, &size);
677 end = start + size - 1;
685 vap = &sc->sc_ioport_va;
686 allocp = &sc->sc_ioport_alloc;
693 vap = &sc->sc_iomem_va;
694 allocp = &sc->sc_iomem_alloc;
700 rm->rm_type = RMAN_ARRAY;
701 rm->rm_start = pci_start;
702 rm->rm_end = pci_end;
703 error = rman_init(rm);
707 error = rman_manage_region(rm, pci_start, pci_end);
713 *allocp = pci_start + alloc;
714 *vap = (uintptr_t)pmap_mapdev(start, size);
716 pci_ocp_outbound(sc, wnd, type, start, size, pci_start);
721 pci_ocp_attach(device_t dev)
723 struct pci_ocp_softc *sc;
727 sc = device_get_softc(dev);
731 sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_rid,
733 if (sc->sc_res == NULL) {
734 device_printf(dev, "could not map I/O memory\n");
737 sc->sc_bst = rman_get_bustag(sc->sc_res);
738 sc->sc_bsh = rman_get_bushandle(sc->sc_res);
740 cfgreg = pci_ocp_cfgread(sc, 0, 0, 0, PCIR_COMMAND, 2);
741 cfgreg |= PCIM_CMD_SERRESPEN | PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN |
743 pci_ocp_cfgwrite(sc, 0, 0, 0, PCIR_COMMAND, cfgreg, 2);
745 pci_ocp_outbound(sc, 0, -1, 0, 0, 0);
746 error = pci_ocp_iorange(sc, SYS_RES_MEMORY, 1);
747 error = pci_ocp_iorange(sc, SYS_RES_IOPORT, 2);
748 pci_ocp_outbound(sc, 3, -1, 0, 0, 0);
749 pci_ocp_outbound(sc, 4, -1, 0, 0, 0);
751 pci_ocp_inbound(sc, 1, -1, 0, 0, 0);
752 pci_ocp_inbound(sc, 2, -1, 0, 0, 0);
753 pci_ocp_inbound(sc, 3, OCP85XX_TGTIF_RAM1, 0, 2U*1024U*1024U*1024U, 0);
755 sc->sc_devfn_tundra = -1;
756 sc->sc_devfn_via_ide = -1;
759 * PCI Express host controllers require a link. We don't
760 * fail the attach if there's no link, but we also don't
761 * create a child pci(4) device.
763 if (sc->sc_pcie_cap) {
764 cfgreg = pci_ocp_cfgread(sc, 0, 0, 0, PCIR_FSL_LTSSM, 4);
765 if (cfgreg < FSL_LTSSM_L0)
769 nslots = (sc->sc_pcie_cap) ? 1 : 32;
770 pci_ocp_init(sc, sc->sc_busnr, nslots);
772 device_add_child(dev, "pci", -1);
773 return (bus_generic_attach(dev));
776 static struct resource *
777 pci_ocp_alloc_resource(device_t dev, device_t child, int type, int *rid,
778 u_long start, u_long end, u_long count, u_int flags)
780 struct pci_ocp_softc *sc = device_get_softc(dev);
782 struct resource *res;
788 va = sc->sc_ioport_va;
792 va = sc->sc_iomem_va;
795 if (start < PIC_IRQ_START) {
796 device_printf(dev, "%s requested ISA interrupt %lu\n",
797 device_get_nameunit(child), start);
799 flags |= RF_SHAREABLE;
800 return (BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
801 type, rid, start, end, count, flags));
806 res = rman_reserve_resource(rm, start, end, count, flags, child);
810 rman_set_bustag(res, &bs_le_tag);
811 rman_set_bushandle(res, va + rman_get_start(res) - rm->rm_start);
816 pci_ocp_release_resource(device_t dev, device_t child, int type, int rid,
817 struct resource *res)
820 return (rman_release_resource(res));
824 pci_ocp_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
826 struct pci_ocp_softc *sc = device_get_softc(dev);
830 *result = sc->sc_busnr;
832 case PCIB_IVAR_DOMAIN:
833 *result = device_get_unit(dev);
840 pci_ocp_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
842 struct pci_ocp_softc *sc = device_get_softc(dev);
846 sc->sc_busnr = value;