diff options
Diffstat (limited to 'sys/arch/macppc/pci/mpcpcibus.c')
-rw-r--r-- | sys/arch/macppc/pci/mpcpcibus.c | 277 |
1 files changed, 92 insertions, 185 deletions
diff --git a/sys/arch/macppc/pci/mpcpcibus.c b/sys/arch/macppc/pci/mpcpcibus.c index 8a6bedd0602..a35cffb688a 100644 --- a/sys/arch/macppc/pci/mpcpcibus.c +++ b/sys/arch/macppc/pci/mpcpcibus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpcpcibus.c,v 1.20 2003/06/09 16:34:21 deraadt Exp $ */ +/* $OpenBSD: mpcpcibus.c,v 1.21 2003/10/15 23:00:57 drahn Exp $ */ /* * Copyright (c) 1997 Per Fogelstrom @@ -81,6 +81,8 @@ int of_ether_hw_addr(struct ppc_pci_chipset *, u_int8_t *); int find_node_intr (int parent, u_int32_t *addr, u_int32_t *intr); u_int32_t pci_iack(void); +void fix_node_irq(int node, struct pcibus_attach_args *pba); + struct cfattach mpcpcibr_ca = { sizeof(struct pcibr_softc), mpcpcibrmatch, mpcpcibrattach, }; @@ -138,9 +140,7 @@ struct powerpc_bus_dma_tag pci_bus_dma_tag = { */ #define TULIP_CRC32_POLY 0xEDB88320UL static __inline__ unsigned -srom_crc32( - const unsigned char *databuf, - size_t datalen) +srom_crc32(const unsigned char *databuf, size_t datalen) { u_int idx, bit, data, crc = 0xFFFFFFFFUL; @@ -151,9 +151,7 @@ srom_crc32( } int -mpcpcibrmatch(parent, match, aux) - struct device *parent; - void *match, *aux; +mpcpcibrmatch(struct device *parent, void *match, void *aux) { struct confargs *ca = aux; int found = 0; @@ -166,13 +164,9 @@ mpcpcibrmatch(parent, match, aux) return found; } -void fix_node_irq(int node, struct pcibus_attach_args *pba); - int pci_map_a = 0; void -mpcpcibrattach(parent, self, aux) - struct device *parent, *self; - void *aux; +mpcpcibrattach(struct device *parent, struct device *self, void *aux) { struct pcibr_softc *sc = (struct pcibr_softc *)self; struct confargs *ca = aux; @@ -198,10 +192,12 @@ mpcpcibrattach(parent, self, aux) if (err == 0) { switch (val) { /* supported ppc-pci bridges */ - case (PCI_VENDOR_MOT | ( PCI_PRODUCT_MOT_MPC105 <<16)): + case (PCI_VENDOR_MOT | + (PCI_PRODUCT_MOT_MPC105 <<16)): bridge = "MPC105"; break; - case (PCI_VENDOR_MOT | ( PCI_PRODUCT_MOT_MPC106 <<16)): + case (PCI_VENDOR_MOT | + (PCI_PRODUCT_MOT_MPC106 <<16)): bridge = "MPC106"; break; default: @@ -231,28 +227,24 @@ mpcpcibrattach(parent, self, aux) sc->sc_iobus_space.bus_base = MPC106_P_PCI_IO_SPACE; sc->sc_iobus_space.bus_reverse = 1; if ( bus_space_map(&(sc->sc_iobus_space), 0, NBPG, 0, - &lcp->ioh_cf8) != 0 ) - { + &lcp->ioh_cf8) != 0 ) panic("mpcpcibus: unable to map self"); - } + lcp->ioh_cfc = lcp->ioh_cf8; } else { sc->sc_membus_space.bus_base = - MPC106_P_PCI_MEM_SPACE_MAP_B; + MPC106_P_PCI_MEM_SPACE_MAP_B; sc->sc_membus_space.bus_reverse = 1; sc->sc_iobus_space.bus_base = - MPC106_P_PCI_IO_SPACE_MAP_B; + MPC106_P_PCI_IO_SPACE_MAP_B; sc->sc_iobus_space.bus_reverse = 1; if ( bus_space_map(&(sc->sc_iobus_space), 0xfec00000, - NBPG, 0, &lcp->ioh_cf8) != 0 ) - { + NBPG, 0, &lcp->ioh_cf8) != 0 ) panic("mpcpcibus: unable to map self"); - } + if ( bus_space_map(&(sc->sc_iobus_space), 0xfee00000, - NBPG, 0, &lcp->ioh_cfc) != 0 ) - { + NBPG, 0, &lcp->ioh_cfc) != 0 ) panic("mpcpcibus: unable to map self"); - } } lcp->lc_pc.pc_conf_v = lcp; @@ -276,11 +268,10 @@ mpcpcibrattach(parent, self, aux) printf(": %s, Revision 0x%x, ", bridge, mpc_cfg_read_1(lcp, MPC106_PCI_REVID)); - if (map == 1) { + if (map == 1) printf("Using Map A\n"); - } else { + else printf("Using Map B\n"); - } #if 0 /* Reset status */ mpc_cfg_write_2(lcp, MPC106_PCI_STAT, 0xff80); @@ -323,27 +314,25 @@ mpcpcibrattach(parent, self, aux) struct ranges_new *prange = (void *)&range_store; len=OF_getprop(ca->ca_node, "compatible", compat, - sizeof (compat)); + sizeof (compat)); if (len <= 0 ) { len=OF_getprop(ca->ca_node, "name", compat, sizeof (compat)); if (len <= 0) { printf(" compatible and name not" - " found\n"); + " found\n"); return; } compat[len] = 0; if (strcmp (compat, "bandit") != 0) { printf(" compatible not found and name" - " %s found\n", compat); + " %s found\n", compat); return; } } compat[len] = 0; if ((rangelen = OF_getprop(ca->ca_node, "ranges", - range_store, - sizeof (range_store))) <= 0) - { + range_store, sizeof (range_store))) <= 0) { printf("range lookup failed, node %x\n", ca->ca_node); } @@ -368,8 +357,7 @@ mpcpcibrattach(parent, self, aux) /* find io(config) base, flag == 0x01000000 */ found = 0; - for (i = 0; i < rangelen ; i++) - { + for (i = 0; i < rangelen ; i++) { if (prange[i].flags == 0x01000000) { /* find last? */ found = i; @@ -378,9 +366,9 @@ mpcpcibrattach(parent, self, aux) /* found the io space ranges */ if (prange[found].flags == 0x01000000) { sc->sc_iobus_space.bus_base = - prange[found].base; + prange[found].base; sc->sc_iobus_space.bus_size = - prange[found].size; + prange[found].size; } /* the mem space ranges @@ -393,8 +381,7 @@ mpcpcibrattach(parent, self, aux) * 0x80000000 * start with segment 1 not 0, 0 is config. */ - for (i = 0; i < rangelen ; i++) - { + for (i = 0; i < rangelen ; i++) { if (prange[i].flags == 0x02000000) { #if 0 printf("\nfound mem %x %x", @@ -404,10 +391,9 @@ mpcpcibrattach(parent, self, aux) if (base != 0) { if ((base + size) == - prange[i].base) - { - size += - prange[i].size; + prange[i].base) { + size += + prange[i].size; } else { base = prange[i].base; @@ -427,44 +413,38 @@ mpcpcibrattach(parent, self, aux) addr_offset = 0; for (i = 0; config_offsets[i].compat != NULL; i++) { if (strcmp(config_offsets[i].compat, compat) - == 0) - { + == 0) { addr_offset = config_offsets[i].addr; data_offset = config_offsets[i].data; lcp->config_type = - config_offsets[i].config_type; + config_offsets[i].config_type; break; } } if (addr_offset == 0) { printf("unable to find match for" - " compatible %s\n", compat); + " compatible %s\n", compat); return; } #ifdef DEBUG_FIXUP - printf(" mem base %x sz %x io base %x sz %x\n config addr %x" - " config data %x\n", - sc->sc_membus_space.bus_base, - sc->sc_membus_space.bus_size, - sc->sc_iobus_space.bus_base, - sc->sc_iobus_space.bus_size, - addr_offset, data_offset); + printf(" mem base %x sz %x io base %x sz %x\n" + " config addr %x config data %x\n", + sc->sc_membus_space.bus_base, + sc->sc_membus_space.bus_size, + sc->sc_iobus_space.bus_base, + sc->sc_iobus_space.bus_size, + addr_offset, data_offset); #endif - - if ( bus_space_map(&(sc->sc_iobus_space), addr_offset, NBPG, 0, &lcp->ioh_cf8) != 0 ) - { panic("mpcpcibus: unable to map self"); - } + if ( bus_space_map(&(sc->sc_iobus_space), data_offset, NBPG, 0, &lcp->ioh_cfc) != 0 ) - { panic("mpcpcibus: unable to map self"); - } - of_node = ca->ca_node; + of_node = ca->ca_node; lcp->node = ca->ca_node; lcp->lc_pc.pc_conf_v = lcp; @@ -486,7 +466,7 @@ mpcpcibrattach(parent, self, aux) lcp->lc_pc.pc_intr_disestablish = mpc_intr_disestablish; printf(": %s, Revision 0x%x\n", compat, - mpc_cfg_read_1(lcp, MPC106_PCI_REVID)); + mpc_cfg_read_1(lcp, MPC106_PCI_REVID)); pci_addr_fixup(sc, &lcp->lc_pc, 32); } @@ -499,7 +479,6 @@ mpcpcibrattach(parent, self, aux) pba.pba_dmat = &pci_bus_dma_tag; - pba.pba_busname = "pci"; pba.pba_iot = &sc->sc_iobus_space; pba.pba_memt = &sc->sc_membus_space; @@ -510,19 +489,18 @@ mpcpcibrattach(parent, self, aux) if (of_node != 0) { int nn; - for (node = OF_child(of_node); node; node = nn) - { + for (node = OF_child(of_node); node; node = nn) { char name[32]; int len; len = OF_getprop(node, "name", name, - sizeof(name)); + sizeof(name)); name[len] = 0; fix_node_irq(node, &pba); /* iterate section */ - if ((nn = OF_child(node)) != 0) { + if ((nn = OF_child(node)) != 0) continue; - } + while ((nn = OF_peer(node)) == 0) { node = OF_parent(node); if (node == of_node) { @@ -567,22 +545,22 @@ find_node_intr(int parent, u_int32_t *addr, u_int32_t *intr) if ((len == -1) || (mlen == -1)) goto nomap; + n_mlen = mlen/sizeof(u_int32_t); - for (i = 0; i < n_mlen; i++) { + for (i = 0; i < n_mlen; i++) maskedaddr[i] = addr[i] & imask[i]; - } + mp = map; /* calculate step size of interrupt-map * -- assumes that iparent will be same for all nodes */ iparent = mp[n_mlen]; step = 0; - for (i = (n_mlen)+1; i < len; i++) { + for (i = (n_mlen)+1; i < len; i++) if (mp[i] == iparent) { step = i - (n_mlen); break; } - } if (step == 0) { /* unable to determine step size */ return -1; @@ -599,9 +577,8 @@ find_node_intr(int parent, u_int32_t *addr, u_int32_t *intr) iparent = *mp1; /* recurse with new 'addr' */ return find_node_intr(iparent, &mp1[1], intr); - } else { + } else *intr = mp1[1]; - } return 1; } len -= step * sizeof(u_int32_t); @@ -612,9 +589,7 @@ nomap: } void -fix_node_irq(node, pba) - int node; - struct pcibus_attach_args *pba; +fix_node_irq(int node, struct pcibus_attach_args *pba) { struct { u_int32_t phys_hi, phys_mid, phys_lo; @@ -629,9 +604,8 @@ fix_node_irq(node, pba) pci_chipset_tag_t pc = pba->pba_pc; len = OF_getprop(node, "assigned-addresses", addr, sizeof(addr)); - if (len < sizeof(addr[0])) { + if (len < sizeof(addr[0])) return; - } /* if this node has a AAPL,interrupts property, firmware * has initialized the register correctly. @@ -651,8 +625,7 @@ fix_node_irq(node, pba) */ tag = pci_make_tag(pc, pcibus(addr[0].phys_hi), - pcidev(addr[0].phys_hi), - pcifunc(addr[0].phys_hi)); + pcidev(addr[0].phys_hi), pcifunc(addr[0].phys_hi)); intr = pci_conf_read(pc, tag, PCI_INTERRUPT_REG); intr &= ~PCI_INTERRUPT_LINE_MASK; @@ -661,9 +634,7 @@ fix_node_irq(node, pba) } static int -mpcpcibrprint(aux, pnp) - void *aux; - const char *pnp; +mpcpcibrprint(void *aux, const char *pnp) { struct pcibus_attach_args *pba = aux; @@ -679,8 +650,7 @@ mpcpcibrprint(aux, pnp) */ paddr_t -vtophys(pa) - paddr_t pa; +vtophys(paddr_t pa) { vaddr_t va = (vaddr_t) pa; @@ -693,9 +663,8 @@ vtophys(pa) } void -mpc_attach_hook(parent, self, pba) - struct device *parent, *self; - struct pcibus_attach_args *pba; +mpc_attach_hook(struct device *parent, struct device *self, + struct pcibus_attach_args *pba) { } @@ -738,18 +707,14 @@ of_ether_hw_addr(struct ppc_pci_chipset *lcpc, u_int8_t *oaddr) } int -mpc_ether_hw_addr(p, s) - struct ppc_pci_chipset *p; - u_int8_t *s; +mpc_ether_hw_addr(struct ppc_pci_chipset *p, u_int8_t *s) { printf("mpc_ether_hw_addr not supported\n"); return(0); } int -mpc_bus_maxdevs(cpv, busno) - void *cpv; - int busno; +mpc_bus_maxdevs(void *cpv, int busno) { return(32); } @@ -759,18 +724,13 @@ mpc_bus_maxdevs(cpv, busno) #define FNC_SHIFT 8 pcitag_t -mpc_make_tag(cpv, bus, dev, fnc) - void *cpv; - int bus, dev, fnc; +mpc_make_tag(void *cpv, int bus, int dev, int fnc) { return (bus << BUS_SHIFT) | (dev << DEVICE_SHIFT) | (fnc << FNC_SHIFT); } void -mpc_decompose_tag(cpv, tag, busp, devp, fncp) - void *cpv; - pcitag_t tag; - int *busp, *devp, *fncp; +mpc_decompose_tag(void *cpv, pcitag_t tag, int *busp, int *devp, int *fncp) { if (busp != NULL) *busp = (tag >> BUS_SHIFT) & 0xff; @@ -781,28 +741,19 @@ mpc_decompose_tag(cpv, tag, busp, devp, fncp) } u_int32_t -mpc_gen_config_reg(cpv, tag, offset) - void *cpv; - pcitag_t tag; - int offset; +mpc_gen_config_reg(void *cpv, pcitag_t tag, int offset) { struct pcibr_config *cp = cpv; unsigned int bus, dev, fcn; u_int32_t reg; - /* - static int spin = 0; - while (spin > 85); - spin++; - */ mpc_decompose_tag(cpv, tag, &bus, &dev, &fcn); if (cp->config_type & 1) { /* Config Mechanism #2 */ if (bus == 0) { - if (dev < 11) { + if (dev < 11) return 0xffffffff; - } /* * Need to do config type 0 operation * 1 << (11?+dev) | fcn << 8 | reg @@ -812,9 +763,8 @@ mpc_gen_config_reg(cpv, tag, offset) reg = 1 << (dev) | fcn << 8 | offset; } else { - if (dev > 15) { - return 0xffffffff; - } + if (dev > 15) + return 0xffffffff; /* * config type 1 */ @@ -833,10 +783,7 @@ mpc_gen_config_reg(cpv, tag, offset) /* #define DEBUG_CONFIG */ pcireg_t -mpc_conf_read(cpv, tag, offset) - void *cpv; - pcitag_t tag; - int offset; +mpc_conf_read(void *cpv, pcitag_t tag, int offset) { struct pcibr_config *cp = cpv; pcireg_t data; @@ -846,8 +793,6 @@ mpc_conf_read(cpv, tag, offset) faultbuf env; void *oldh; - - if (offset & 3 || offset < 0 || offset >= 0x100) { #ifdef DEBUG_CONFIG printf ("pci_conf_read: bad reg %x\n", offset); @@ -857,13 +802,11 @@ mpc_conf_read(cpv, tag, offset) reg = mpc_gen_config_reg(cpv, tag, offset); /* if invalid tag, return -1 */ - if (reg == 0xffffffff) { + if (reg == 0xffffffff) return(~0); - } - if ((cp->config_type & 2) && (offset & 0x04)) { + if ((cp->config_type & 2) && (offset & 0x04)) daddr += 4; - } s = splhigh(); @@ -898,11 +841,7 @@ mpc_conf_read(cpv, tag, offset) } void -mpc_conf_write(cpv, tag, offset, data) - void *cpv; - pcitag_t tag; - int offset; - pcireg_t data; +mpc_conf_write(void *cpv, pcitag_t tag, int offset, pcireg_t data) { struct pcibr_config *cp = cpv; u_int32_t reg; @@ -912,12 +851,12 @@ mpc_conf_write(cpv, tag, offset, data) reg = mpc_gen_config_reg(cpv, tag, offset); /* if invalid tag, return ??? */ - if (reg == 0xffffffff) { + if (reg == 0xffffffff) return; - } - if ((cp->config_type & 2) && (offset & 0x04)) { + + if ((cp->config_type & 2) && (offset & 0x04)) daddr += 4; - } + #ifdef DEBUG_CONFIG { unsigned int bus, dev, fcn; @@ -943,19 +882,14 @@ mpc_conf_write(cpv, tag, offset, data) /*ARGSUSED*/ int -mpc_intr_map(lcv, bustag, buspin, line, ihp) - void *lcv; - pcitag_t bustag; - int buspin, line; - pci_intr_handle_t *ihp; +mpc_intr_map(void *lcv, pcitag_t bustag, int buspin, int line, + pci_intr_handle_t *ihp) { int error = 0; *ihp = -1; - if (buspin == 0) { - /* No IRQ used. */ - error = 1; - } + if (buspin == 0) + error = 1; /* No IRQ used. */ else if (buspin > 4) { printf("mpc_intr_map: bad interrupt pin %d\n", buspin); error = 1; @@ -967,9 +901,7 @@ mpc_intr_map(lcv, bustag, buspin, line, ihp) } const char * -mpc_intr_string(lcv, ih) - void *lcv; - pci_intr_handle_t ih; +mpc_intr_string(void *lcv, pci_intr_handle_t ih) { static char str[16]; @@ -978,29 +910,21 @@ mpc_intr_string(lcv, ih) } int -mpc_intr_line(lcv, ih) - void *lcv; - pci_intr_handle_t ih; +mpc_intr_line(void *lcv, pci_intr_handle_t ih) { return (ih); } void * -mpc_intr_establish(lcv, ih, level, func, arg, name) - void *lcv; - pci_intr_handle_t ih; - int level; - int (*func)(void *); - void *arg; - char *name; +mpc_intr_establish(void *lcv, pci_intr_handle_t ih, int level, + int (*func)(void *), void *arg, char *name) { return (*intr_establish_func)(lcv, ih, IST_LEVEL, level, func, arg, name); } void -mpc_intr_disestablish(lcv, cookie) - void *lcv, *cookie; +mpc_intr_disestablish(void *lcv, void *cookie) { /* XXX We should probably do something clever here.... later */ } @@ -1018,24 +942,17 @@ pci_iack() } void -mpc_cfg_write_1(cp, reg, val) - struct pcibr_config *cp; - u_int32_t reg; - u_int8_t val; +mpc_cfg_write_1(struct pcibr_config *cp, u_int32_t reg, u_int8_t val) { int s; s = splhigh(); - bus_space_write_4(cp->lc_iot, cp->ioh_cf8, 0, - MPC106_REGOFFS(reg)); + bus_space_write_4(cp->lc_iot, cp->ioh_cf8, 0, MPC106_REGOFFS(reg)); bus_space_write_1(cp->lc_iot, cp->ioh_cfc, 0, val); splx(s); } void -mpc_cfg_write_2(cp, reg, val) - struct pcibr_config *cp; - u_int32_t reg; - u_int16_t val; +mpc_cfg_write_2(struct pcibr_config *cp, u_int32_t reg, u_int16_t val) { int s; s = splhigh(); @@ -1045,10 +962,7 @@ mpc_cfg_write_2(cp, reg, val) } void -mpc_cfg_write_4(cp, reg, val) - struct pcibr_config *cp; - u_int32_t reg; - u_int32_t val; +mpc_cfg_write_4(struct pcibr_config *cp, u_int32_t reg, u_int32_t val) { int s; @@ -1059,9 +973,7 @@ mpc_cfg_write_4(cp, reg, val) } u_int8_t -mpc_cfg_read_1(cp, reg) - struct pcibr_config *cp; - u_int32_t reg; +mpc_cfg_read_1(struct pcibr_config *cp, u_int32_t reg) { u_int8_t _v_; @@ -1074,9 +986,7 @@ mpc_cfg_read_1(cp, reg) } u_int16_t -mpc_cfg_read_2(cp, reg) - struct pcibr_config *cp; - u_int32_t reg; +mpc_cfg_read_2(struct pcibr_config *cp, u_int32_t reg) { u_int16_t _v_; @@ -1089,9 +999,7 @@ mpc_cfg_read_2(cp, reg) } u_int32_t -mpc_cfg_read_4(cp, reg) - struct pcibr_config *cp; - u_int32_t reg; +mpc_cfg_read_4(struct pcibr_config *cp, u_int32_t reg) { u_int32_t _v_; @@ -1104,8 +1012,7 @@ mpc_cfg_read_4(cp, reg) } int -pci_intr_line(ih) - pci_intr_handle_t ih; +pci_intr_line(pci_intr_handle_t ih) { return (ih); } |