2 * Copyright 2006-2007 by Juniper Networks.
3 * Copyright 2008 Semihalf.
4 * Copyright 2010 The FreeBSD Foundation
7 * Portions of this software were developed by Semihalf
8 * under sponsorship from the FreeBSD Foundation.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * From: FreeBSD: src/sys/powerpc/mpc85xx/pci_ocp.c,v 1.9 2010/03/23 23:46:28 marcel
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
39 #include <sys/param.h>
40 #include <sys/systm.h>
42 #include <sys/sockio.h>
44 #include <sys/malloc.h>
45 #include <sys/kernel.h>
46 #include <sys/module.h>
47 #include <sys/socket.h>
48 #include <sys/queue.h>
51 #include <sys/mutex.h>
53 #include <sys/endian.h>
58 #include <dev/ofw/ofw_pci.h>
59 #include <dev/ofw/ofw_bus.h>
60 #include <dev/ofw/ofw_bus_subr.h>
61 #include <dev/pci/pcivar.h>
62 #include <dev/pci/pcireg.h>
63 #include <dev/pci/pcib_private.h>
65 #include <powerpc/ofw/ofw_pci.h>
67 #include "ofw_bus_if.h"
70 #include <machine/resource.h>
71 #include <machine/bus.h>
72 #include <machine/intr_machdep.h>
74 #include <powerpc/mpc85xx/mpc85xx.h>
76 #define REG_CFG_ADDR 0x0000
77 #define CONFIG_ACCESS_ENABLE 0x80000000
79 #define REG_CFG_DATA 0x0004
80 #define REG_INT_ACK 0x0008
82 #define REG_POTAR(n) (0x0c00 + 0x20 * (n))
83 #define REG_POTEAR(n) (0x0c04 + 0x20 * (n))
84 #define REG_POWBAR(n) (0x0c08 + 0x20 * (n))
85 #define REG_POWAR(n) (0x0c10 + 0x20 * (n))
87 #define REG_PITAR(n) (0x0e00 - 0x20 * (n))
88 #define REG_PIWBAR(n) (0x0e08 - 0x20 * (n))
89 #define REG_PIWBEAR(n) (0x0e0c - 0x20 * (n))
90 #define REG_PIWAR(n) (0x0e10 - 0x20 * (n))
92 #define REG_PEX_MES_DR 0x0020
93 #define REG_PEX_MES_IER 0x0028
94 #define REG_PEX_ERR_DR 0x0e00
95 #define REG_PEX_ERR_EN 0x0e08
97 #define PCIR_LTSSM 0x404
98 #define LTSSM_STAT_L0 0x16
100 #define DEVFN(b, s, f) ((b << 16) | (s << 8) | f)
102 struct fsl_pcib_softc {
103 struct ofw_pci_softc pci_sc;
107 bus_addr_t sc_iomem_alloc, sc_iomem_start, sc_iomem_end;
108 int sc_ioport_target;
109 bus_addr_t sc_ioport_alloc, sc_ioport_start, sc_ioport_end;
111 struct resource *sc_res;
112 bus_space_handle_t sc_bsh;
113 bus_space_tag_t sc_bst;
118 uint8_t sc_pcie_capreg; /* PCI-E Capability Reg Set */
120 /* Devices that need special attention. */
122 int sc_devfn_via_ide;
125 /* Local forward declerations. */
126 static uint32_t fsl_pcib_cfgread(struct fsl_pcib_softc *, u_int, u_int, u_int,
128 static void fsl_pcib_cfgwrite(struct fsl_pcib_softc *, u_int, u_int, u_int,
129 u_int, uint32_t, int);
130 static int fsl_pcib_decode_win(phandle_t, struct fsl_pcib_softc *);
131 static void fsl_pcib_err_init(device_t);
132 static void fsl_pcib_inbound(struct fsl_pcib_softc *, int, int, u_long,
134 static int fsl_pcib_init(struct fsl_pcib_softc *, int, int);
135 static void fsl_pcib_outbound(struct fsl_pcib_softc *, int, int, u_long,
138 /* Forward declerations. */
139 static int fsl_pcib_attach(device_t);
140 static int fsl_pcib_detach(device_t);
141 static int fsl_pcib_probe(device_t);
143 static int fsl_pcib_maxslots(device_t);
144 static uint32_t fsl_pcib_read_config(device_t, u_int, u_int, u_int, u_int, int);
145 static void fsl_pcib_write_config(device_t, u_int, u_int, u_int, u_int,
148 /* Configuration r/w mutex. */
149 struct mtx pcicfg_mtx;
150 static int mtx_initialized = 0;
153 * Bus interface definitions.
155 static device_method_t fsl_pcib_methods[] = {
156 /* Device interface */
157 DEVMETHOD(device_probe, fsl_pcib_probe),
158 DEVMETHOD(device_attach, fsl_pcib_attach),
159 DEVMETHOD(device_detach, fsl_pcib_detach),
162 DEVMETHOD(pcib_maxslots, fsl_pcib_maxslots),
163 DEVMETHOD(pcib_read_config, fsl_pcib_read_config),
164 DEVMETHOD(pcib_write_config, fsl_pcib_write_config),
169 static devclass_t fsl_pcib_devclass;
171 DEFINE_CLASS_1(pcib, fsl_pcib_driver, fsl_pcib_methods,
172 sizeof(struct fsl_pcib_softc), ofw_pci_driver);
173 DRIVER_MODULE(pcib, ofwbus, fsl_pcib_driver, fsl_pcib_devclass, 0, 0);
176 fsl_pcib_probe(device_t dev)
179 if (ofw_bus_get_type(dev) == NULL ||
180 strcmp(ofw_bus_get_type(dev), "pci") != 0)
183 if (!(ofw_bus_is_compatible(dev, "fsl,mpc8540-pci") ||
184 ofw_bus_is_compatible(dev, "fsl,mpc8548-pcie")))
187 device_set_desc(dev, "Freescale Integrated PCI/PCI-E Controller");
188 return (BUS_PROBE_DEFAULT);
192 fsl_pcib_attach(device_t dev)
194 struct fsl_pcib_softc *sc;
198 uint8_t ltssm, capptr;
200 sc = device_get_softc(dev);
204 sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_rid,
206 if (sc->sc_res == NULL) {
207 device_printf(dev, "could not map I/O memory\n");
210 sc->sc_bst = rman_get_bustag(sc->sc_res);
211 sc->sc_bsh = rman_get_bushandle(sc->sc_res);
214 if (!mtx_initialized) {
215 mtx_init(&pcicfg_mtx, "pcicfg", NULL, MTX_SPIN);
219 cfgreg = fsl_pcib_cfgread(sc, 0, 0, 0, PCIR_VENDOR, 2);
220 if (cfgreg != 0x1057 && cfgreg != 0x1957)
223 capptr = fsl_pcib_cfgread(sc, 0, 0, 0, PCIR_CAP_PTR, 1);
224 while (capptr != 0) {
225 cfgreg = fsl_pcib_cfgread(sc, 0, 0, 0, capptr, 2);
226 switch (cfgreg & 0xff) {
231 sc->sc_pcie_capreg = capptr;
234 capptr = (cfgreg >> 8) & 0xff;
237 node = ofw_bus_get_node(dev);
240 * Initialize generic OF PCI interface (ranges, etc.)
243 error = ofw_pci_init(dev);
248 * Configure decode windows for PCI(E) access.
250 if (fsl_pcib_decode_win(node, sc) != 0)
253 cfgreg = fsl_pcib_cfgread(sc, 0, 0, 0, PCIR_COMMAND, 2);
254 cfgreg |= PCIM_CMD_SERRESPEN | PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN |
256 fsl_pcib_cfgwrite(sc, 0, 0, 0, PCIR_COMMAND, cfgreg, 2);
258 sc->sc_devfn_tundra = -1;
259 sc->sc_devfn_via_ide = -1;
263 * Scan bus using firmware configured, 0 based bus numbering.
266 maxslot = (sc->sc_pcie) ? 0 : PCI_SLOTMAX;
267 fsl_pcib_init(sc, sc->sc_busnr, maxslot);
270 ltssm = fsl_pcib_cfgread(sc, 0, 0, 0, PCIR_LTSSM, 1);
271 if (ltssm < LTSSM_STAT_L0) {
273 printf("PCI %d: no PCIE link, skipping\n",
274 device_get_unit(dev));
279 fsl_pcib_err_init(dev);
281 return (ofw_pci_attach(dev));
288 fsl_pcib_cfgread(struct fsl_pcib_softc *sc, u_int bus, u_int slot, u_int func,
289 u_int reg, int bytes)
293 if (bus == sc->sc_busnr - 1)
296 addr = CONFIG_ACCESS_ENABLE;
297 addr |= (bus & 0xff) << 16;
298 addr |= (slot & 0x1f) << 11;
299 addr |= (func & 0x7) << 8;
302 addr |= (reg & 0xf00) << 16;
304 mtx_lock_spin(&pcicfg_mtx);
305 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_CFG_ADDR, addr);
309 data = bus_space_read_1(sc->sc_bst, sc->sc_bsh,
310 REG_CFG_DATA + (reg & 3));
313 data = le16toh(bus_space_read_2(sc->sc_bst, sc->sc_bsh,
314 REG_CFG_DATA + (reg & 2)));
317 data = le32toh(bus_space_read_4(sc->sc_bst, sc->sc_bsh,
324 mtx_unlock_spin(&pcicfg_mtx);
329 fsl_pcib_cfgwrite(struct fsl_pcib_softc *sc, u_int bus, u_int slot, u_int func,
330 u_int reg, uint32_t data, int bytes)
334 if (bus == sc->sc_busnr - 1)
337 addr = CONFIG_ACCESS_ENABLE;
338 addr |= (bus & 0xff) << 16;
339 addr |= (slot & 0x1f) << 11;
340 addr |= (func & 0x7) << 8;
343 addr |= (reg & 0xf00) << 16;
345 mtx_lock_spin(&pcicfg_mtx);
346 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_CFG_ADDR, addr);
350 bus_space_write_1(sc->sc_bst, sc->sc_bsh,
351 REG_CFG_DATA + (reg & 3), data);
354 bus_space_write_2(sc->sc_bst, sc->sc_bsh,
355 REG_CFG_DATA + (reg & 2), htole16(data));
358 bus_space_write_4(sc->sc_bst, sc->sc_bsh,
359 REG_CFG_DATA, htole32(data));
362 mtx_unlock_spin(&pcicfg_mtx);
367 dump(struct fsl_pcib_softc *sc)
371 #define RD(o) bus_space_read_4(sc->sc_bst, sc->sc_bsh, o)
372 for (i = 0; i < 5; i++) {
373 printf("POTAR%u =0x%08x\n", i, RD(REG_POTAR(i)));
374 printf("POTEAR%u =0x%08x\n", i, RD(REG_POTEAR(i)));
375 printf("POWBAR%u =0x%08x\n", i, RD(REG_POWBAR(i)));
376 printf("POWAR%u =0x%08x\n", i, RD(REG_POWAR(i)));
379 for (i = 1; i < 4; i++) {
380 printf("PITAR%u =0x%08x\n", i, RD(REG_PITAR(i)));
381 printf("PIWBAR%u =0x%08x\n", i, RD(REG_PIWBAR(i)));
382 printf("PIWBEAR%u=0x%08x\n", i, RD(REG_PIWBEAR(i)));
383 printf("PIWAR%u =0x%08x\n", i, RD(REG_PIWAR(i)));
388 for (i = 0; i < 0x48; i += 4) {
389 printf("cfg%02x=0x%08x\n", i, fsl_pcib_cfgread(sc, 0, 0, 0,
396 fsl_pcib_maxslots(device_t dev)
398 struct fsl_pcib_softc *sc = device_get_softc(dev);
400 return ((sc->sc_pcie) ? 0 : PCI_SLOTMAX);
404 fsl_pcib_read_config(device_t dev, u_int bus, u_int slot, u_int func,
405 u_int reg, int bytes)
407 struct fsl_pcib_softc *sc = device_get_softc(dev);
410 if (bus == sc->sc_busnr && !sc->sc_pcie && slot < 10)
412 devfn = DEVFN(bus, slot, func);
413 if (devfn == sc->sc_devfn_tundra)
415 if (devfn == sc->sc_devfn_via_ide && reg == PCIR_INTPIN)
417 return (fsl_pcib_cfgread(sc, bus, slot, func, reg, bytes));
421 fsl_pcib_write_config(device_t dev, u_int bus, u_int slot, u_int func,
422 u_int reg, uint32_t val, int bytes)
424 struct fsl_pcib_softc *sc = device_get_softc(dev);
426 if (bus == sc->sc_busnr && !sc->sc_pcie && slot < 10)
428 fsl_pcib_cfgwrite(sc, bus, slot, func, reg, val, bytes);
432 fsl_pcib_init_via(struct fsl_pcib_softc *sc, uint16_t device, int bus,
436 if (device == 0x0686) {
437 fsl_pcib_write_config(sc->sc_dev, bus, slot, fn, 0x52, 0x34, 1);
438 fsl_pcib_write_config(sc->sc_dev, bus, slot, fn, 0x77, 0x00, 1);
439 fsl_pcib_write_config(sc->sc_dev, bus, slot, fn, 0x83, 0x98, 1);
440 fsl_pcib_write_config(sc->sc_dev, bus, slot, fn, 0x85, 0x03, 1);
441 } else if (device == 0x0571) {
442 sc->sc_devfn_via_ide = DEVFN(bus, slot, fn);
443 fsl_pcib_write_config(sc->sc_dev, bus, slot, fn, 0x40, 0x0b, 1);
448 fsl_pcib_init_bar(struct fsl_pcib_softc *sc, int bus, int slot, int func,
452 uint32_t addr, mask, size;
455 reg = PCIR_BAR(barno);
457 if (DEVFN(bus, slot, func) == sc->sc_devfn_via_ide) {
459 case 0: addr = 0x1f0; break;
460 case 1: addr = 0x3f4; break;
461 case 2: addr = 0x170; break;
462 case 3: addr = 0x374; break;
463 case 4: addr = 0xcc0; break;
466 fsl_pcib_write_config(sc->sc_dev, bus, slot, func, reg, addr, 4);
470 fsl_pcib_write_config(sc->sc_dev, bus, slot, func, reg, ~0, 4);
471 size = fsl_pcib_read_config(sc->sc_dev, bus, slot, func, reg, 4);
474 width = ((size & 7) == 4) ? 2 : 1;
476 if (size & 1) { /* I/O port */
477 allocp = &sc->sc_ioport_alloc;
479 if ((size & 0xffff0000) == 0)
481 } else { /* memory */
482 allocp = &sc->sc_iomem_alloc;
487 /* Sanity check (must be a power of 2). */
491 addr = (*allocp + mask) & ~mask;
492 *allocp = addr + size;
495 printf("PCI %u:%u:%u:%u: reg %x: size=%08x: addr=%08x\n",
496 device_get_unit(sc->sc_dev), bus, slot, func, reg,
499 fsl_pcib_write_config(sc->sc_dev, bus, slot, func, reg, addr, 4);
501 fsl_pcib_write_config(sc->sc_dev, bus, slot, func, reg + 4,
507 fsl_pcib_init(struct fsl_pcib_softc *sc, int bus, int maxslot)
510 int old_pribus, old_secbus, old_subbus;
511 int new_pribus, new_secbus, new_subbus;
512 int slot, func, maxfunc;
514 uint16_t vendor, device;
515 uint8_t command, hdrtype, class, subclass;
518 for (slot = 0; slot <= maxslot; slot++) {
520 for (func = 0; func <= maxfunc; func++) {
521 hdrtype = fsl_pcib_read_config(sc->sc_dev, bus, slot,
522 func, PCIR_HDRTYPE, 1);
524 if ((hdrtype & PCIM_HDRTYPE) > PCI_MAXHDRTYPE)
527 if (func == 0 && (hdrtype & PCIM_MFDEV))
528 maxfunc = PCI_FUNCMAX;
530 vendor = fsl_pcib_read_config(sc->sc_dev, bus, slot,
531 func, PCIR_VENDOR, 2);
532 device = fsl_pcib_read_config(sc->sc_dev, bus, slot,
533 func, PCIR_DEVICE, 2);
535 if (vendor == 0x1957 && device == 0x3fff) {
536 sc->sc_devfn_tundra = DEVFN(bus, slot, func);
540 command = fsl_pcib_read_config(sc->sc_dev, bus, slot,
541 func, PCIR_COMMAND, 1);
542 command &= ~(PCIM_CMD_MEMEN | PCIM_CMD_PORTEN);
543 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
544 PCIR_COMMAND, command, 1);
546 if (vendor == 0x1106)
547 fsl_pcib_init_via(sc, device, bus, slot, func);
549 /* Program the base address registers. */
550 maxbar = (hdrtype & PCIM_HDRTYPE) ? 1 : 6;
553 bar += fsl_pcib_init_bar(sc, bus, slot, func,
556 /* Put a placeholder interrupt value */
557 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
558 PCIR_INTLINE, PCI_INVALID_IRQ, 1);
560 command |= PCIM_CMD_MEMEN | PCIM_CMD_PORTEN;
561 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
562 PCIR_COMMAND, command, 1);
565 * Handle PCI-PCI bridges
567 class = fsl_pcib_read_config(sc->sc_dev, bus, slot,
568 func, PCIR_CLASS, 1);
569 subclass = fsl_pcib_read_config(sc->sc_dev, bus, slot,
570 func, PCIR_SUBCLASS, 1);
572 /* Allow only proper PCI-PCI briges */
573 if (class != PCIC_BRIDGE)
575 if (subclass != PCIS_BRIDGE_PCI)
580 /* Program I/O decoder. */
581 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
582 PCIR_IOBASEL_1, sc->sc_ioport_start >> 8, 1);
583 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
584 PCIR_IOLIMITL_1, sc->sc_ioport_end >> 8, 1);
585 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
586 PCIR_IOBASEH_1, sc->sc_ioport_start >> 16, 2);
587 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
588 PCIR_IOLIMITH_1, sc->sc_ioport_end >> 16, 2);
590 /* Program (non-prefetchable) memory decoder. */
591 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
592 PCIR_MEMBASE_1, sc->sc_iomem_start >> 16, 2);
593 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
594 PCIR_MEMLIMIT_1, sc->sc_iomem_end >> 16, 2);
596 /* Program prefetchable memory decoder. */
597 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
598 PCIR_PMBASEL_1, 0x0010, 2);
599 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
600 PCIR_PMLIMITL_1, 0x000f, 2);
601 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
602 PCIR_PMBASEH_1, 0x00000000, 4);
603 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
604 PCIR_PMLIMITH_1, 0x00000000, 4);
606 /* Read currect bus register configuration */
607 old_pribus = fsl_pcib_read_config(sc->sc_dev, bus,
608 slot, func, PCIR_PRIBUS_1, 1);
609 old_secbus = fsl_pcib_read_config(sc->sc_dev, bus,
610 slot, func, PCIR_SECBUS_1, 1);
611 old_subbus = fsl_pcib_read_config(sc->sc_dev, bus,
612 slot, func, PCIR_SUBBUS_1, 1);
615 printf("PCI: reading firmware bus numbers for "
616 "secbus = %d (bus/sec/sub) = (%d/%d/%d)\n",
617 secbus, old_pribus, old_secbus, old_subbus);
622 secbus = fsl_pcib_init(sc, secbus,
623 (subclass == PCIS_BRIDGE_PCI) ? PCI_SLOTMAX : 0);
628 printf("PCI: translate firmware bus numbers "
629 "for secbus %d (%d/%d/%d) -> (%d/%d/%d)\n",
630 secbus, old_pribus, old_secbus, old_subbus,
631 new_pribus, new_secbus, new_subbus);
633 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
634 PCIR_PRIBUS_1, new_pribus, 1);
635 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
636 PCIR_SECBUS_1, new_secbus, 1);
637 fsl_pcib_write_config(sc->sc_dev, bus, slot, func,
638 PCIR_SUBBUS_1, new_subbus, 1);
646 fsl_pcib_inbound(struct fsl_pcib_softc *sc, int wnd, int tgt, u_long start,
647 u_long size, u_long pci_start)
649 uint32_t attr, bar, tar;
651 KASSERT(wnd > 0, ("%s: inbound window 0 is invalid", __func__));
654 /* XXX OCP85XX_TGTIF_RAM2, OCP85XX_TGTIF_RAM_INTL should be handled */
655 case OCP85XX_TGTIF_RAM1:
656 attr = 0xa0f55000 | (ffsl(size) - 2);
663 bar = pci_start >> 12;
665 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_PITAR(wnd), tar);
666 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_PIWBEAR(wnd), 0);
667 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_PIWBAR(wnd), bar);
668 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_PIWAR(wnd), attr);
672 fsl_pcib_outbound(struct fsl_pcib_softc *sc, int wnd, int res, u_long start,
673 u_long size, u_long pci_start)
675 uint32_t attr, bar, tar;
679 attr = 0x80044000 | (ffsl(size) - 2);
682 attr = 0x80088000 | (ffsl(size) - 2);
689 tar = pci_start >> 12;
691 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_POTAR(wnd), tar);
692 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_POTEAR(wnd), 0);
693 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_POWBAR(wnd), bar);
694 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_POWAR(wnd), attr);
699 fsl_pcib_err_init(device_t dev)
701 struct fsl_pcib_softc *sc;
702 uint16_t sec_stat, dsr;
703 uint32_t dcr, err_en;
705 sc = device_get_softc(dev);
707 sec_stat = fsl_pcib_cfgread(sc, 0, 0, 0, PCIR_SECSTAT_1, 2);
709 fsl_pcib_cfgwrite(sc, 0, 0, 0, PCIR_SECSTAT_1, 0xffff, 2);
711 /* Clear error bits */
712 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_PEX_MES_IER,
714 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_PEX_MES_DR,
716 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_PEX_ERR_DR,
719 dsr = fsl_pcib_cfgread(sc, 0, 0, 0,
720 sc->sc_pcie_capreg + PCIER_DEVICE_STA, 2);
722 fsl_pcib_cfgwrite(sc, 0, 0, 0,
723 sc->sc_pcie_capreg + PCIER_DEVICE_STA,
726 /* Enable all errors reporting */
728 bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_PEX_ERR_EN,
731 /* Enable error reporting: URR, FER, NFER */
732 dcr = fsl_pcib_cfgread(sc, 0, 0, 0,
733 sc->sc_pcie_capreg + PCIER_DEVICE_CTL, 4);
734 dcr |= PCIEM_CTL_URR_ENABLE | PCIEM_CTL_FER_ENABLE |
735 PCIEM_CTL_NFER_ENABLE;
736 fsl_pcib_cfgwrite(sc, 0, 0, 0,
737 sc->sc_pcie_capreg + PCIER_DEVICE_CTL, dcr, 4);
742 fsl_pcib_detach(device_t dev)
745 if (mtx_initialized) {
746 mtx_destroy(&pcicfg_mtx);
749 return (bus_generic_detach(dev));
753 fsl_pcib_decode_win(phandle_t node, struct fsl_pcib_softc *sc)
760 fsl_pcib_outbound(sc, 0, -1, 0, 0, 0);
763 * Configure LAW decode windows.
765 error = law_pci_target(sc->sc_res, &sc->sc_iomem_target,
766 &sc->sc_ioport_target);
768 device_printf(dev, "could not retrieve PCI LAW target info\n");
772 for (i = 0; i < sc->pci_sc.sc_nrange; i++) {
773 switch (sc->pci_sc.sc_range[i].pci_hi &
774 OFW_PCI_PHYS_HI_SPACEMASK) {
775 case OFW_PCI_PHYS_HI_SPACE_CONFIG:
777 case OFW_PCI_PHYS_HI_SPACE_IO:
778 trgt = sc->sc_ioport_target;
779 fsl_pcib_outbound(sc, 2, SYS_RES_IOPORT,
780 sc->pci_sc.sc_range[i].host,
781 sc->pci_sc.sc_range[i].size,
782 sc->pci_sc.sc_range[i].pci);
783 sc->sc_ioport_start = sc->pci_sc.sc_range[i].host;
784 sc->sc_ioport_end = sc->pci_sc.sc_range[i].host +
785 sc->pci_sc.sc_range[i].size;
786 sc->sc_ioport_alloc = 0x1000 + sc->pci_sc.sc_range[i].pci;
788 case OFW_PCI_PHYS_HI_SPACE_MEM32:
789 case OFW_PCI_PHYS_HI_SPACE_MEM64:
790 trgt = sc->sc_iomem_target;
791 fsl_pcib_outbound(sc, 1, SYS_RES_MEMORY,
792 sc->pci_sc.sc_range[i].host,
793 sc->pci_sc.sc_range[i].size,
794 sc->pci_sc.sc_range[i].pci);
795 sc->sc_iomem_start = sc->pci_sc.sc_range[i].host;
796 sc->sc_iomem_end = sc->pci_sc.sc_range[i].host +
797 sc->pci_sc.sc_range[i].size;
798 sc->sc_iomem_alloc = sc->pci_sc.sc_range[i].pci;
801 panic("Unknown range type %#x\n",
802 sc->pci_sc.sc_range[i].pci_hi &
803 OFW_PCI_PHYS_HI_SPACEMASK);
805 error = law_enable(trgt, sc->pci_sc.sc_range[i].host,
806 sc->pci_sc.sc_range[i].size);
808 device_printf(dev, "could not program LAW for range "
815 * Set outbout and inbound windows.
817 fsl_pcib_outbound(sc, 3, -1, 0, 0, 0);
818 fsl_pcib_outbound(sc, 4, -1, 0, 0, 0);
820 fsl_pcib_inbound(sc, 1, -1, 0, 0, 0);
821 fsl_pcib_inbound(sc, 2, -1, 0, 0, 0);
822 fsl_pcib_inbound(sc, 3, OCP85XX_TGTIF_RAM1, 0,
823 2U * 1024U * 1024U * 1024U, 0);