int puc_cardbus_match(struct device *parent, void *match, void *aux) { struct cardbus_attach_args *ca = aux; struct cardbus_devfunc *ct = ca->ca_ct; cardbus_chipset_tag_t cc = ct->ct_cc; cardbus_function_tag_t cf = ct->ct_cf; cardbusreg_t bhlc, reg; bhlc = cardbus_conf_read(cc, cf, ca->ca_tag, CARDBUS_BHLC_REG); if (PCI_HDRTYPE_TYPE(bhlc) != 0) return(0); /* this one is some sort of a bridge and not a puc */ if (PCI_VENDOR(ca->ca_id) == PCI_VENDOR_OXFORD2 && PCI_PRODUCT(ca->ca_id) == PCI_PRODUCT_OXFORD2_EXSYS_EX41098) return (0); reg = cardbus_conf_read(cc, cf, ca->ca_tag, PCI_SUBSYS_ID_REG); if (puc_find_description(PCI_VENDOR(ca->ca_id), PCI_PRODUCT(ca->ca_id), PCI_VENDOR(reg), PCI_PRODUCT(reg))) return (10); return (0); }
int puc_pci_match(struct device *parent, void *match, void *aux) { struct pci_attach_args *pa = aux; const struct puc_device_description *desc; pcireg_t bhlc, subsys; bhlc = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG); if (PCI_HDRTYPE_TYPE(bhlc) != 0) return (0); subsys = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG); desc = puc_find_description(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id), PCI_VENDOR(subsys), PCI_PRODUCT(subsys)); if (desc != NULL) return (1); return (0); }
static int puc_match(device_t parent, cfdata_t match, void *aux) { struct pci_attach_args *pa = aux; const struct puc_device_description *desc; pcireg_t bhlc, subsys; bhlc = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG); if (PCI_HDRTYPE_TYPE(bhlc) != 0) return (0); subsys = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG); desc = puc_find_description(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id), PCI_VENDOR(subsys), PCI_PRODUCT(subsys)); if (desc != NULL) return (10); #if 0 /* * XXX this is obviously bogus. eventually, we might want * XXX to match communications/modem, etc., but that needs some * XXX special work in the match fn. */ /* * Match class/subclass, so we can tell people to compile kernel * with options that cause this driver to spew. */ if (PCI_CLASS(pa->pa_class) == PCI_CLASS_COMMUNICATIONS) { switch (PCI_SUBCLASS(pa->pa_class)) { case PCI_SUBCLASS_COMMUNICATIONS_SERIAL: case PCI_SUBCLASS_COMMUNICATIONS_MODEM: return (1); } } #endif return (0); }
int puc_cardbus_match(struct device *parent, void *match, void *aux) { struct cardbus_attach_args *ca = aux; pci_chipset_tag_t pc = ca->ca_pc; pcireg_t bhlc, reg; bhlc = pci_conf_read(pc, ca->ca_tag, PCI_BHLC_REG); if (PCI_HDRTYPE_TYPE(bhlc) != 0) return(0); /* this one is some sort of a bridge and not a puc */ if (PCI_VENDOR(ca->ca_id) == PCI_VENDOR_OXFORD2 && PCI_PRODUCT(ca->ca_id) == PCI_PRODUCT_OXFORD2_EXSYS_EX41098) return (0); reg = pci_conf_read(pc, ca->ca_tag, PCI_SUBSYS_ID_REG); if (puc_find_description(PCI_VENDOR(ca->ca_id), PCI_PRODUCT(ca->ca_id), PCI_VENDOR(reg), PCI_PRODUCT(reg))) return (10); return (0); }
void puc_cardbus_attach(struct device *parent, struct device *self, void *aux) { struct puc_cardbus_softc *csc = (struct puc_cardbus_softc *)self; struct puc_softc *sc = &csc->sc_psc; struct cardbus_attach_args *ca = aux; struct cardbus_devfunc *ct = ca->ca_ct; cardbus_chipset_tag_t cc = ct->ct_cc; pci_chipset_tag_t pc = ca->ca_pc; cardbus_function_tag_t cf = ct->ct_cf; struct puc_attach_args paa; pcireg_t reg; int i; Cardbus_function_enable(ct); csc->ct = ct; reg = pci_conf_read(pc, ca->ca_tag, PCI_SUBSYS_ID_REG); sc->sc_desc = puc_find_description(PCI_VENDOR(ca->ca_id), PCI_PRODUCT(ca->ca_id), PCI_VENDOR(reg), PCI_PRODUCT(reg)); puc_print_ports(sc->sc_desc); /* the fifth one is some memory we dunno */ for (i = 0; i < PUC_NBARS; i++) { pcireg_t type; int bar; sc->sc_bar_mappings[i].mapped = 0; bar = PCI_MAPREG_START + 4 * i; if (!pci_mapreg_probe(pc, ca->ca_tag, bar, &type)) continue; if (!(sc->sc_bar_mappings[i].mapped = !Cardbus_mapreg_map(ct, bar, type, 0, &sc->sc_bar_mappings[i].t, &sc->sc_bar_mappings[i].h, &sc->sc_bar_mappings[i].a, &sc->sc_bar_mappings[i].s))) printf("%s: couldn't map BAR at offset 0x%lx\n", sc->sc_dev.dv_xname, (long)bar); sc->sc_bar_mappings[i].type = type; } csc->intrline = ca->ca_intrline; if (pci_get_capability(pc, ca->ca_tag, PCI_CAP_PWRMGMT, ®, 0)) { reg = pci_conf_read(pc, ca->ca_tag, reg + 4) & 3; if (reg) { printf("%s: awakening from state D%d\n", sc->sc_dev.dv_xname, reg); pci_conf_write(pc, ca->ca_tag, reg + 4, 0); } } (*cf->cardbus_ctrl)(cc, CARDBUS_MEM_ENABLE); (*cf->cardbus_ctrl)(cc, CARDBUS_IO_ENABLE); (*cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE); paa.puc = sc; paa.hwtype = COM_UART_OX16C950; /* XXX */ paa.intr_string = &puc_cardbus_intr_string; paa.intr_establish = &puc_cardbus_intr_establish; puc_common_attach(sc, &paa); }
static bus_addr_t pucprobe_doit(struct consdev *cn) { struct pci_attach_args pa; int bus; static int dev = 0, func = 0; int maxdev, nfunctions = 0, i; /* XXX */ pcireg_t reg, bhlcr, subsys = 0; /* XXX */ int foundport = 0; const struct puc_device_description *desc; pcireg_t base; /* Fetch our tags */ if (cpu_comcnprobe(cn, &pa) != 0) { return 0; } puctag = pa.pa_iot; pci_decompose_tag(pa.pa_pc, pa.pa_tag, &bus, &maxdev, NULL); /* scan through devices */ for (; dev <= maxdev ; dev++) { pa.pa_tag = pci_make_tag(pa.pa_pc, bus, dev, 0); reg = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_ID_REG); if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID || PCI_VENDOR(reg) == 0) continue; bhlcr = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_BHLC_REG); if (PCI_HDRTYPE_MULTIFN(bhlcr)) { nfunctions = 8; } else { nfunctions = 1; } resume_scan: for (; func < nfunctions; func++) { pa.pa_tag = pci_make_tag(pa.pa_pc, bus, dev, func); reg = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_CLASS_REG); if (PCI_CLASS(reg) == PCI_CLASS_COMMUNICATIONS && PCI_SUBCLASS(reg) == PCI_SUBCLASS_COMMUNICATIONS_SERIAL) { pa.pa_id = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_ID_REG); subsys = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_SUBSYS_ID_REG); foundport = 1; break; } } if (foundport) break; func = 0; } if (!foundport) return 0; foundport = 0; desc = puc_find_description(PCI_VENDOR(pa.pa_id), PCI_PRODUCT(pa.pa_id), PCI_VENDOR(subsys), PCI_PRODUCT(subsys)); if (desc == NULL) { func++; goto resume_scan; } for (i = 0; PUC_PORT_VALID(desc, i); i++) { if (desc->ports[i].type != PUC_PORT_TYPE_COM) continue; base = pci_conf_read(pa.pa_pc, pa.pa_tag, desc->ports[i].bar); base += desc->ports[i].offset; if (PCI_MAPREG_TYPE(base) != PCI_MAPREG_TYPE_IO) continue; base = PCI_MAPREG_IO_ADDR(base); if (com_is_console(puctag, base, NULL)) continue; foundport = 1; break; } if (foundport == 0) { func++; goto resume_scan; } cn->cn_pri = CN_REMOTE; return PCI_MAPREG_IO_ADDR(base); }
void puc_pci_attach(struct device *parent, struct device *self, void *aux) { struct puc_pci_softc *psc = (struct puc_pci_softc *)self; struct puc_softc *sc = &psc->sc_psc; struct pci_attach_args *pa = aux; struct puc_attach_args paa; pcireg_t subsys; int i; subsys = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG); sc->sc_desc = puc_find_description(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id), PCI_VENDOR(subsys), PCI_PRODUCT(subsys)); puc_print_ports(sc->sc_desc); for (i = 0; i < PUC_NBARS; i++) { pcireg_t type; int bar; sc->sc_bar_mappings[i].mapped = 0; bar = PCI_MAPREG_START + 4 * i; if (!pci_mapreg_probe(pa->pa_pc, pa->pa_tag, bar, &type)) continue; sc->sc_bar_mappings[i].mapped = (pci_mapreg_map(pa, bar, type, 0, &sc->sc_bar_mappings[i].t, &sc->sc_bar_mappings[i].h, &sc->sc_bar_mappings[i].a, &sc->sc_bar_mappings[i].s, 0) == 0); if (sc->sc_bar_mappings[i].mapped) continue; /* * If a port on this card is used as serial console, * mapping the associated BAR will fail because the * bus space is already mapped. In that case, we try * to re-use the already existing mapping. * Unfortunately this means that if a BAR is used to * support multiple ports, only the first port will * work. */ if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, type, &sc->sc_bar_mappings[i].a, NULL, NULL) == 0 && pa->pa_iot == comconsiot && sc->sc_bar_mappings[i].a == comconsaddr) { sc->sc_bar_mappings[i].t = comconsiot; sc->sc_bar_mappings[i].h = comconsioh; sc->sc_bar_mappings[i].s = COM_NPORTS; sc->sc_bar_mappings[i].mapped = 1; continue; } printf("%s: couldn't map BAR at offset 0x%lx\n", sc->sc_dev.dv_xname, (long)bar); } /* Map interrupt. */ psc->pc = pa->pa_pc; if (pci_intr_map(pa, &psc->ih)) { printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname); return; } paa.puc = sc; paa.intr_string = &puc_pci_intr_string; paa.intr_establish = &puc_pci_intr_establish; puc_common_attach(sc, &paa); }
static void puc_attach(device_t parent, device_t self, void *aux) { struct puc_softc *sc = device_private(self); struct pci_attach_args *pa = aux; struct puc_attach_args paa; pci_intr_handle_t intrhandle; pcireg_t subsys; int i, barindex; bus_addr_t base; bus_space_tag_t tag; #ifdef PUCCN bus_space_handle_t ioh; #endif int locs[PUCCF_NLOCS]; subsys = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG); sc->sc_desc = puc_find_description(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id), PCI_VENDOR(subsys), PCI_PRODUCT(subsys)); if (sc->sc_desc == NULL) { /* * This was a class/subclass match, so tell people to compile * kernel with options that cause this driver to spew. */ #ifdef PUC_PRINT_REGS printf(":\n"); pci_conf_print(pa->pa_pc, pa->pa_tag, NULL); #else printf(": unknown PCI communications device\n"); printf("%s: compile kernel with PUC_PRINT_REGS and larger\n", device_xname(self)); printf("%s: mesage buffer (via 'options MSGBUFSIZE=...'),\n", device_xname(self)); printf("%s: and report the result with send-pr\n", device_xname(self)); #endif return; } printf(": %s (", sc->sc_desc->name); for (i = 0; PUC_PORT_VALID(sc->sc_desc, i); i++) printf("%s%s", i ? ", " : "", puc_port_type_name(sc->sc_desc->ports[i].type)); printf(")\n"); for (i = 0; i < 6; i++) { pcireg_t bar, type; sc->sc_bar_mappings[i].mapped = 0; bar = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START + 4 * i); /* XXX const */ if (bar == 0) /* BAR not implemented(?) */ continue; type = (PCI_MAPREG_TYPE(bar) == PCI_MAPREG_TYPE_IO ? PCI_MAPREG_TYPE_IO : PCI_MAPREG_MEM_TYPE(bar)); if (type == PCI_MAPREG_TYPE_IO) { tag = pa->pa_iot; base = PCI_MAPREG_IO_ADDR(bar); } else { tag = pa->pa_memt; base = PCI_MAPREG_MEM_ADDR(bar); } #ifdef PUCCN if (com_is_console(tag, base, &ioh)) { sc->sc_bar_mappings[i].mapped = 1; sc->sc_bar_mappings[i].a = base; sc->sc_bar_mappings[i].s = COM_NPORTS; sc->sc_bar_mappings[i].t = tag; sc->sc_bar_mappings[i].h = ioh; continue; } #endif sc->sc_bar_mappings[i].mapped = (pci_mapreg_map(pa, PCI_MAPREG_START + 4 * i, type, 0, &sc->sc_bar_mappings[i].t, &sc->sc_bar_mappings[i].h, &sc->sc_bar_mappings[i].a, &sc->sc_bar_mappings[i].s) == 0); if (sc->sc_bar_mappings[i].mapped) continue; aprint_error_dev(self, "couldn't map BAR at offset 0x%lx\n", (long)(PCI_MAPREG_START + 4 * i)); } /* Map interrupt. */ if (pci_intr_map(pa, &intrhandle)) { aprint_error_dev(self, "couldn't map interrupt\n"); return; } /* * XXX the sub-devices establish the interrupts, for the * XXX following reasons: * XXX * XXX * we can't really know what IPLs they'd want * XXX * XXX * the MD dispatching code can ("should") dispatch * XXX chained interrupts better than we can. * XXX * XXX It would be nice if we could indicate to the MD interrupt * XXX handling code that the interrupt line used by the device * XXX was a PCI (level triggered) interrupt. * XXX * XXX It's not pretty, but hey, what is? */ /* Configure each port. */ for (i = 0; PUC_PORT_VALID(sc->sc_desc, i); i++) { bus_space_handle_t subregion_handle; /* make sure the base address register is mapped */ barindex = PUC_PORT_BAR_INDEX(sc->sc_desc->ports[i].bar); if (!sc->sc_bar_mappings[barindex].mapped) { printf("%s: %s port uses unmapped BAR (0x%x)\n", device_xname(self), puc_port_type_name(sc->sc_desc->ports[i].type), sc->sc_desc->ports[i].bar); continue; } /* set up to configure the child device */ paa.port = i; paa.type = sc->sc_desc->ports[i].type; paa.flags = sc->sc_desc->ports[i].flags; paa.pc = pa->pa_pc; paa.tag = pa->pa_tag; paa.intrhandle = intrhandle; paa.a = sc->sc_bar_mappings[barindex].a; paa.t = sc->sc_bar_mappings[barindex].t; paa.dmat = pa->pa_dmat; paa.dmat64 = pa->pa_dmat64; if ( #ifdef PUCCN !com_is_console(sc->sc_bar_mappings[barindex].t, sc->sc_bar_mappings[barindex].a, &subregion_handle) && #endif bus_space_subregion(sc->sc_bar_mappings[barindex].t, sc->sc_bar_mappings[barindex].h, sc->sc_desc->ports[i].offset, sc->sc_bar_mappings[barindex].s - sc->sc_desc->ports[i].offset, &subregion_handle) != 0) { aprint_error_dev(self, "couldn't get subregion for port %d\n", i); continue; } paa.h = subregion_handle; #if 0 printf("%s: port %d: %s @ (index %d) 0x%x (0x%lx, 0x%lx)\n", device_xname(self), paa.port, puc_port_type_name(paa.type), barindex, (int)paa.a, (long)paa.t, (long)paa.h); #endif locs[PUCCF_PORT] = i; /* and configure it */ sc->sc_ports[i].dev = config_found_sm_loc(self, "puc", locs, &paa, puc_print, config_stdsubmatch); } }
static bus_addr_t pucprobe_doit(struct consdev *cn) { struct pci_attach_args pa; int bus; static int dev = 0, func = 0; int maxdev, nfunctions = 0, i; /* XXX */ pcireg_t reg, bhlcr, subsys = 0; /* XXX */ int foundport = 0; const struct puc_device_description *desc; pcireg_t base; /* Fetch our tags */ #if defined(amd64) || defined(i386) if (cpu_puc_cnprobe(cn, &pa) != 0) #endif return 0; pci_decompose_tag(pa.pa_pc, pa.pa_tag, &bus, &maxdev, NULL); /* Scan through devices and find a communication class device. */ for (; dev <= maxdev ; dev++) { pa.pa_tag = pci_make_tag(pa.pa_pc, bus, dev, 0); reg = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_ID_REG); if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID || PCI_VENDOR(reg) == 0) continue; bhlcr = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_BHLC_REG); if (PCI_HDRTYPE_MULTIFN(bhlcr)) { nfunctions = 8; } else { nfunctions = 1; } resume_scan: for (; func < nfunctions; func++) { pa.pa_tag = pci_make_tag(pa.pa_pc, bus, dev, func); reg = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_CLASS_REG); if (PCI_CLASS(reg) == PCI_CLASS_COMMUNICATIONS && PCI_SUBCLASS(reg) == PCI_SUBCLASS_COMMUNICATIONS_SERIAL) { pa.pa_id = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_ID_REG); subsys = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_SUBSYS_ID_REG); foundport = 1; break; } } if (foundport) break; func = 0; } /* * If all devices was scanned and couldn't find any communication * device, return with 0. */ if (!foundport) return 0; /* Clear foundport flag */ foundport = 0; /* Check whether the device is in the puc device table or not */ desc = puc_find_description(PCI_VENDOR(pa.pa_id), PCI_PRODUCT(pa.pa_id), PCI_VENDOR(subsys), PCI_PRODUCT(subsys)); /* If not, check the next communication device */ if (desc == NULL) { /* Resume from the next function */ func++; goto resume_scan; } /* * We found a device and it's on the puc table. Set the tag and * the base address. */ for (i = 0; PUC_PORT_VALID(desc, i); i++) { if (desc->ports[i].type != PUC_PORT_TYPE_COM) continue; puccnflags = desc->ports[i].flags; base = pci_conf_read(pa.pa_pc, pa.pa_tag, desc->ports[i].bar); base += desc->ports[i].offset; if (PCI_MAPREG_TYPE(base) == PCI_MAPREG_TYPE_IO) { puctag = pa.pa_iot; base = PCI_MAPREG_IO_ADDR(base); } #if 0 /* For MMIO device */ else { puctag = pa.pa_memt; base = PCI_MAPREG_MEM_ADDR(base); } #endif if (com_is_console(puctag, base, NULL)) continue; foundport = 1; break; } if (foundport == 0) { func++; goto resume_scan; } #if 0 cn->cn_pri = CN_REMOTE; #else if (cn) cn->cn_pri = CN_REMOTE; #endif return base; }