From owner-p4-projects@FreeBSD.ORG Sat Oct 4 00:54:07 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 782F31065692; Sat, 4 Oct 2008 00:54:07 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3B29C1065688 for ; Sat, 4 Oct 2008 00:54:07 +0000 (UTC) (envelope-from nwhitehorn@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 2728D8FC12 for ; Sat, 4 Oct 2008 00:54:07 +0000 (UTC) (envelope-from nwhitehorn@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id m940s7Ih022629 for ; Sat, 4 Oct 2008 00:54:07 GMT (envelope-from nwhitehorn@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id m940s71A022627 for perforce@freebsd.org; Sat, 4 Oct 2008 00:54:07 GMT (envelope-from nwhitehorn@freebsd.org) Date: Sat, 4 Oct 2008 00:54:07 GMT Message-Id: <200810040054.m940s71A022627@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to nwhitehorn@freebsd.org using -f From: Nathan Whitehorn To: Perforce Change Reviews Cc: Subject: PERFORCE change 150915 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Oct 2008 00:54:08 -0000 http://perforce.freebsd.org/chv.cgi?CH=150915 Change 150915 by nwhitehorn@nwhitehorn_trantor on 2008/10/04 00:53:24 Make PCI buses into OFW buses. This fixes the weird interrupt problems with Apple ATA controllers, and decreases the general level of hackery. Changes should be harmless. MFP4 after: 2 weeks Affected files ... .. //depot/projects/ppc-g5/sys/powerpc/aim/ofw_machdep.c#3 edit .. //depot/projects/ppc-g5/sys/powerpc/ofw/ofw_pci.c#3 delete .. //depot/projects/ppc-g5/sys/powerpc/ofw/ofw_pci.h#2 delete .. //depot/projects/ppc-g5/sys/powerpc/ofw/ofw_pcib_pci.c#2 edit .. //depot/projects/ppc-g5/sys/powerpc/ofw/ofw_pcibus.c#1 add .. //depot/projects/ppc-g5/sys/powerpc/powermac/ata_kauai.c#4 edit .. //depot/projects/ppc-g5/sys/powerpc/powermac/cpcht.c#2 edit .. //depot/projects/ppc-g5/sys/powerpc/powermac/grackle.c#2 edit .. //depot/projects/ppc-g5/sys/powerpc/powermac/macio.c#3 edit .. //depot/projects/ppc-g5/sys/powerpc/powermac/uninorth.c#3 edit .. //depot/projects/ppc-g5/sys/powerpc/powermac/uninorthvar.h#3 edit Differences ... ==== //depot/projects/ppc-g5/sys/powerpc/aim/ofw_machdep.c#3 (text+ko) ==== @@ -32,7 +32,7 @@ */ #include -__FBSDID("$FreeBSD: src/sys/powerpc/aim/ofw_machdep.c,v 1.20 2008/02/12 20:55:51 marcel Exp $"); +__FBSDID("$FreeBSD: head/sys/powerpc/aim/ofw_machdep.c 176222 2008-02-12 20:55:51Z marcel $"); #include #include @@ -47,6 +47,7 @@ #include #include +#include #include #include @@ -56,7 +57,6 @@ #include #include #include -#include #define OFMEM_REGIONS 32 static struct mem_region OFmem[OFMEM_REGIONS + 1], OFavail[OFMEM_REGIONS + 3]; @@ -310,7 +310,7 @@ { phandle_t node; - node = ofw_pci_find_node(dev); + node = ofw_bus_get_node(dev); OF_getprop(node, "local-mac-address", addr, ETHER_ADDR_LEN); } ==== //depot/projects/ppc-g5/sys/powerpc/ofw/ofw_pcib_pci.c#2 (text+ko) ==== @@ -24,7 +24,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/powerpc/ofw/ofw_pcib_pci.c,v 1.5 2006/01/06 19:22:19 jhb Exp $ + * $FreeBSD: head/sys/powerpc/ofw/ofw_pcib_pci.c 154079 2006-01-06 19:22:19Z jhb $ */ #include @@ -35,8 +35,7 @@ #include #include - -#include +#include #include #include @@ -46,6 +45,7 @@ static int ofw_pcib_pci_probe(device_t bus); static int ofw_pcib_pci_attach(device_t bus); +static phandle_t ofw_pcib_pci_get_node(device_t bus, device_t dev); static device_method_t ofw_pcib_pci_methods[] = { /* Device interface */ @@ -72,6 +72,9 @@ DEVMETHOD(pcib_write_config, pcib_write_config), DEVMETHOD(pcib_route_interrupt, pcib_route_interrupt), + /* ofw_bus interface */ + DEVMETHOD(ofw_bus_get_node, ofw_pcib_pci_get_node), + {0, 0} }; @@ -89,29 +92,29 @@ (pci_get_subclass(dev) != PCIS_BRIDGE_PCI)) { return (ENXIO); } - if (ofw_pci_find_node(dev) == 0) { + + if (ofw_bus_get_node(dev) == 0) return (ENXIO); - } - device_set_desc(dev, "Open Firmware PCI-PCI bridge"); - return (-1000); + device_set_desc(dev, "OFW PCI-PCI bridge"); + return (0); } static int ofw_pcib_pci_attach(device_t dev) { - phandle_t node; - uint32_t busrange[2]; - - node = ofw_pci_find_node(dev); - if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) != 8) - return (ENXIO); - pcib_attach_common(dev); - ofw_pci_fixup(dev, busrange[0], node); - device_add_child(dev, "pci", -1); return (bus_generic_attach(dev)); } + +phandle_t +ofw_pcib_pci_get_node(device_t bridge, device_t dev) +{ + /* We have only one child, the PCI bus, so pass it our node */ + + return (ofw_bus_get_node(bridge)); +} + ==== //depot/projects/ppc-g5/sys/powerpc/powermac/ata_kauai.c#4 (text+ko) ==== @@ -26,7 +26,7 @@ * */ #include -__FBSDID("$FreeBSD: src/sys/powerpc/powermac/ata_kauai.c,v 1.15 2008/09/27 15:13:44 nwhitehorn Exp $"); +__FBSDID("$FreeBSD: head/sys/powerpc/powermac/ata_kauai.c 183409 2008-09-27 15:13:44Z nwhitehorn $"); /* * Mac 'Kauai' PCI ATA controller @@ -50,7 +50,7 @@ #include #include -#include +#include #include #include @@ -194,11 +194,10 @@ { struct ata_channel *ch; struct ata_kauai_softc *sc; - u_long startp, countp; u_int32_t devid; phandle_t node; char *compatstring = NULL; - int i, found, rid, status; + int i, found, rid; found = 0; devid = pci_get_devid(dev); @@ -212,60 +211,15 @@ if (!found) return (ENXIO); - node = ofw_pci_find_node(dev); + node = ofw_bus_get_node(dev); sc = device_get_softc(dev); bzero(sc, sizeof(struct ata_kauai_softc)); ch = &sc->sc_ch.sc_ch; - OF_getprop_alloc(node, "compatible", 1, (void **)&compatstring); - if (strcmp(compatstring,"shasta-ata") == 0) + compatstring = ofw_bus_get_compatible(node); + if (compatstring != NULL && strcmp(compatstring,"shasta-ata") == 0) sc->shasta = 1; - free(compatstring, M_OFWPROP); - - - /* - * This device seems to ignore writes to the interrupt - * config register, resulting in interrupt resources - * not being attached. If this is the case, use - * Open Firmware to determine the irq, and then attach - * the resource. This allows the ATA common code to - * allocate the irq. - */ - status = bus_get_resource(dev, SYS_RES_IRQ, 0, &startp, &countp); - if (status == ENOENT) { - int *irq; - phandle_t iparent; - int icells, nintr, i; - - /* - * Horrible hack to handle Kauai devices that have their IRQs - * set up in an utterly wrong way - */ - if (!sc->shasta) - bus_set_resource(dev, SYS_RES_IRQ, 0, 39, 1); - - /* - * For the rest of the interrupts, and the main Shasta - * interrupt, get the IRQs from firmware. - */ - if (OF_getprop(node, "interrupt-parent", &iparent, - sizeof(iparent)) == sizeof(iparent)) { - OF_getprop(iparent, "#interrupt-cells", &icells, - sizeof(icells)) ; - } - - nintr = OF_getprop_alloc(node, "interrupts", sizeof(*irq), - (void **)&irq); - - for (i = 0; i < nintr; i += icells) - bus_set_resource(dev, SYS_RES_IRQ, - i/icells + !sc->shasta, irq[i], 1); - - free(irq, M_OFWPROP); - } - - rid = PCIR_BARS; sc->sc_memr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); ==== //depot/projects/ppc-g5/sys/powerpc/powermac/cpcht.c#2 (text+ko) ==== @@ -1,5 +1,5 @@ /*- - * Copyright (C) 2002 Benno Rice. + * Copyright (C) 2008 Nathan Whitehorn * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -46,7 +46,6 @@ #include -#include #include #include #include @@ -194,6 +193,12 @@ static int cpcpci_route_interrupt(device_t, device_t, int); /* + * ofw_bus interface + */ + +static phandle_t cpcpci_get_node(device_t bus, device_t child); + +/* * Driver methods. */ static device_method_t cpcpci_methods[] = { @@ -215,6 +220,8 @@ DEVMETHOD(pcib_write_config, cpcpci_write_config), DEVMETHOD(pcib_route_interrupt, cpcpci_route_interrupt), + /* ofw_bus interface */ + DEVMETHOD(ofw_bus_get_node, cpcpci_get_node), { 0, 0 } }; @@ -345,13 +352,16 @@ } } +#if 0 /* * Write out the correct PIC interrupt values to config space * of all devices on the bus. */ ofw_pci_fixup(dev, sc->sc_bus, node); +#endif device_add_child(dev, "pci", device_get_unit(dev)); + return (bus_generic_attach(dev)); } @@ -413,13 +423,6 @@ } static int -cpcpci_route_interrupt(device_t bus, device_t dev, int pin) -{ - - return (0); -} - -static int cpcpci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) { struct cpcpci_softc *sc; @@ -533,4 +536,19 @@ return (rman_activate_resource(res)); } +static phandle_t +cpcpci_get_node(device_t bus, device_t dev) +{ + struct cpcpci_softc *sc; + + sc = device_get_softc(bus); + /* We only have one child, the PCI bus, which needs our own node. */ + return (sc->sc_node); +} + +static int +cpcpci_route_interrupt(device_t bus, device_t dev, int pin) +{ + return (0); +} ==== //depot/projects/ppc-g5/sys/powerpc/powermac/grackle.c#2 (text+ko) ==== @@ -24,7 +24,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/powerpc/powermac/grackle.c,v 1.13 2008/06/12 02:28:58 kevlo Exp $ + * $FreeBSD: head/sys/powerpc/powermac/grackle.c 179746 2008-06-12 02:28:58Z kevlo $ */ #include @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -48,7 +49,6 @@ #include -#include #include #include @@ -92,6 +92,11 @@ static int grackle_route_interrupt(device_t, device_t, int); /* + * ofw_bus interface + */ +static phandle_t grackle_get_node(device_t bus, device_t dev); + +/* * Local routines. */ static int grackle_enable_config(struct grackle_softc *, u_int, @@ -122,6 +127,9 @@ DEVMETHOD(pcib_write_config, grackle_write_config), DEVMETHOD(pcib_route_interrupt, grackle_route_interrupt), + /* ofw_bus interface */ + DEVMETHOD(ofw_bus_get_node, grackle_get_node), + { 0, 0 } }; @@ -244,12 +252,6 @@ } } - /* - * Write out the correct PIC interrupt values to config space - * of all devices on the bus. - */ - ofw_pci_fixup(dev, sc->sc_bus, sc->sc_node); - device_add_child(dev, "pci", device_get_unit(dev)); return (bus_generic_attach(dev)); } @@ -511,6 +513,17 @@ out32rb(sc->sc_addr, 0); } +static phandle_t +grackle_get_node(device_t bus, device_t dev) +{ + struct grackle_softc *sc; + + sc = device_get_softc(bus); + /* We only have one child, the PCI bus, which needs our own node. */ + + return sc->sc_node; +} + /* * Driver to swallow Grackle host bridges from the PCI bus side. */ ==== //depot/projects/ppc-g5/sys/powerpc/powermac/macio.c#3 (text+ko) ==== @@ -24,7 +24,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/powerpc/powermac/macio.c,v 1.25 2008/06/12 02:28:58 kevlo Exp $ + * $FreeBSD: head/sys/powerpc/powermac/macio.c 179746 2008-06-12 02:28:58Z kevlo $ */ /* @@ -272,7 +272,7 @@ int error, quirks; sc = device_get_softc(dev); - root = sc->sc_node = OF_finddevice("mac-io"); + root = sc->sc_node = ofw_bus_get_node(dev); /* * Locate the device node and it's base address ==== //depot/projects/ppc-g5/sys/powerpc/powermac/uninorth.c#3 (text+ko) ==== @@ -22,7 +22,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/powerpc/powermac/uninorth.c,v 1.20 2008/06/12 02:28:58 kevlo Exp $ + * $FreeBSD: head/sys/powerpc/powermac/uninorth.c 179746 2008-06-12 02:28:58Z kevlo $ */ #include @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -46,7 +47,6 @@ #include -#include #include #include @@ -84,6 +84,12 @@ static int uninorth_route_interrupt(device_t, device_t, int); /* + * OFW Bus interface + */ + +static phandle_t uninorth_get_node(device_t bus, device_t dev); + +/* * Local routines. */ static int uninorth_enable_config(struct uninorth_softc *, u_int, @@ -112,6 +118,9 @@ DEVMETHOD(pcib_write_config, uninorth_write_config), DEVMETHOD(pcib_route_interrupt, uninorth_route_interrupt), + /* ofw_bus interface */ + DEVMETHOD(ofw_bus_get_node, uninorth_get_node), + { 0, 0 } }; @@ -154,12 +163,12 @@ uninorth_attach(device_t dev) { struct uninorth_softc *sc; + char *compatible; phandle_t node; phandle_t child; u_int32_t reg[2], busrange[2]; struct uninorth_range *rp, *io, *mem[2]; int nmem, i, error; - u_int32_t cells; node = nexus_get_node(dev); sc = device_get_softc(dev); @@ -170,18 +179,24 @@ if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) != 8) return (ENXIO); - cells = 1; - OF_getprop(node,"#size-cells",&cells,sizeof(cells)); - cells--; + sc->sc_agp = 0; + compatible = nexus_get_compatible(dev); + if (strcmp(compatible,"u3-agp") == 0) + sc->sc_agp = 1; sc->sc_dev = dev; sc->sc_node = node; - sc->sc_addr = (vm_offset_t)pmap_mapdev(reg[cells] + 0x800000, PAGE_SIZE); - sc->sc_data = (vm_offset_t)pmap_mapdev(reg[cells] + 0xc00000, PAGE_SIZE); + if (sc->sc_agp) { + sc->sc_addr = (vm_offset_t)pmap_mapdev(reg[1] + 0x800000, PAGE_SIZE); + sc->sc_data = (vm_offset_t)pmap_mapdev(reg[1] + 0xc00000, PAGE_SIZE); + } else { + sc->sc_addr = (vm_offset_t)pmap_mapdev(reg[0] + 0x800000, PAGE_SIZE); + sc->sc_data = (vm_offset_t)pmap_mapdev(reg[0] + 0xc00000, PAGE_SIZE); + } sc->sc_bus = busrange[0]; bzero(sc->sc_range, sizeof(sc->sc_range)); - if (cells > 0) { + if (sc->sc_agp) { /* * On Apple U3 systems, we have an otherwise standard * Uninorth controller driving AGP. The one difference @@ -245,13 +260,6 @@ panic("uninorth_attach: failed to set up I/O rman"); } -#if 0 - printf("I/O Size: %d bytes\n",io->size_lo); - printf("I/O Mapped at: %#x\n",io->pci_lo); - printf("I/O Start: %#x\n",io->host); - panic("Observe!"); -#endif - if (nmem == 0) { device_printf(dev, "can't find mem ranges\n"); return (ENXIO); @@ -287,13 +295,6 @@ } } - /* - * Write out the correct PIC interrupt values to config space - * of all devices on the bus. This has to be done after the GEM - * cell is enabled above. - */ - ofw_pci_fixup(dev, sc->sc_bus, node); - device_add_child(dev, "pci", device_get_unit(dev)); return (bus_generic_attach(dev)); } @@ -317,7 +318,7 @@ if (uninorth_enable_config(sc, bus, slot, func, reg) != 0) { switch (width) { - case 1: + case 1: return (in8rb(caoff)); break; case 2: @@ -509,6 +510,17 @@ return (1); } +static phandle_t +uninorth_get_node(device_t bus, device_t dev) +{ + struct uninorth_softc *sc; + + sc = device_get_softc(bus); + /* We only have one child, the PCI bus, which needs our own node. */ + + return sc->sc_node; +} + /* * Driver to swallow UniNorth host bridges from the PCI bus side. */ ==== //depot/projects/ppc-g5/sys/powerpc/powermac/uninorthvar.h#3 (text+ko) ==== @@ -22,7 +22,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/powerpc/powermac/uninorthvar.h,v 1.4 2005/01/07 02:29:20 imp Exp $ + * $FreeBSD: head/sys/powerpc/powermac/uninorthvar.h 139825 2005-01-07 02:29:27Z imp $ */ #ifndef _POWERPC_POWERMAC_UNINORTHVAR_H_ @@ -61,6 +61,8 @@ bus_space_tag_t sc_iot; bus_space_tag_t sc_memt; bus_dma_tag_t sc_dmat; + + int sc_agp; }; struct unin_chip_softc {