/* * Copyright (c) 2004 Tim Kelly/Dialectronics * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * Product contains software written by Dialectronics.com for use * by operating systems running on PowerPC processors. The currently * supported version may be found at * http://www.dialectronics.com/OldWorldMacs/vci.c * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ /* * The chaos chip on Old World Macs behaves similar to Host/PCI Bridges * but doesn't like to be probed. It'll act like there's a device on * every node. The easiest way is to find control and Plan B (not included * here) and attach them. * * Code is a compilation from work done by Paul Mackerras, Chris G. Demetriou * et al, and independent research by Tim Kelly. */ /* * Chaos autoconfiguration. */ #include #include #include #include #include #include #define PCI_BANDIT 11 int vcimatch(struct device *, void *, void *); void vciattach(struct device *, struct device *, void *); int vci_matchbyid(struct pci_attach_args *pa, const struct pci_matchid *ids, int nent); // to make the compiler happy w/o namespace collision struct vci_softc { struct device sc_dev; pci_chipset_tag_t sc_pc; int sc_bus; }; struct cfattach vci_ca = { sizeof(struct vci_softc), vcimatch, vciattach }; struct cfdriver vci_cd = { NULL, "vci", DV_DULL }; int vciprint(void *, const char *); int vcimatch(parent, match, aux) struct device *parent; void *match, *aux; { struct cfdata *cf = match; struct pcibus_attach_args *pba = aux; if (strcmp(pba->pba_busname, cf->cf_driver->cd_name) == 0) return (1); return 0; } void vciattach(parent, self, aux) struct device *parent, *self; void *aux; { struct pcibus_attach_args *pba = aux; struct vci_softc *sc = (struct vci_softc *)self; { pcitag_t tag; pcireg_t id, class, intr; struct pci_attach_args pa; /* * We're pretty function specific here - we're looking * for control and control only * */ sc->sc_pc = pba->pba_pc; sc->sc_bus = pba->pba_bus; tag = pci_make_tag(pba->pba_pc, pba->pba_bus, PCI_BANDIT, 0); id = pci_conf_read(pba->pba_pc, tag, PCI_ID_REG); class = pci_conf_read(pba->pba_pc, tag, PCI_CLASS_REG); intr = pci_conf_read(pba->pba_pc, tag, PCI_INTERRUPT_REG); pa.pa_iot = pba->pba_iot; pa.pa_memt = pba->pba_memt; pa.pa_dmat = pba->pba_dmat; pa.pa_pc = pba->pba_pc; pa.pa_device = PCI_BANDIT; pa.pa_function = 0; pa.pa_bus = pba->pba_bus; pa.pa_tag = tag; pa.pa_id = id; // control is a "vga-like" frame buffer pa.pa_class = (PCI_CLASS_PREHISTORIC << 24) | (PCI_SUBCLASS_PREHISTORIC_VGA << 16) | (1 << 8); // I don't think control needs these: /* This is a simplification of the NetBSD code. We don't support turning off I/O or memory on broken hardware. */ pa.pa_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED; pa.pa_intrline = PCI_INTERRUPT_LINE(intr); pa.pa_intrpin = 0; /* done */ config_found(self, &pa, vciprint); } } int vciprint(aux, pnp) void *aux; const char *pnp; { register struct pci_attach_args *pa = aux; char devinfo[256]; if (pnp) { pci_devinfo(pa->pa_id, pa->pa_class, 1, devinfo, sizeof devinfo); printf("%s at %s", devinfo, pnp); } printf(" dev %d function %d", pa->pa_device, pa->pa_function); if (!pnp) { pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof devinfo); printf(" %s", devinfo); } return (UNCONF); } #if 0 int vci_matchbyid(struct pci_attach_args *pa, const struct pci_matchid *ids, int nent) { const struct pci_matchid *pm; int i; for (i = 0, pm = ids; i < nent; i++, pm++) if (PCI_VENDOR(pa->pa_id) == pm->pm_vid && PCI_PRODUCT(pa->pa_id) == pm->pm_pid) return (1); return (0); } #endif