diff options
author | 2012-12-04 10:42:04 +0000 | |
---|---|---|
committer | 2012-12-04 10:42:04 +0000 | |
commit | e476753737fb78c57a333771b7ccb2b71bd98709 (patch) | |
tree | 6c3ca3664023e5ad5045597394d11ad808520114 | |
parent | sync (diff) | |
download | wireguard-openbsd-e476753737fb78c57a333771b7ccb2b71bd98709.tar.xz wireguard-openbsd-e476753737fb78c57a333771b7ccb2b71bd98709.zip |
Add support for Uninorth AGP bridges found in most if not all the macppc
machines with a G3 or G4 microprocessor. It would not be difficult to add
support for U3 bridges found in G5 powered macppc to this driver but I
don't have such hardware.
-rw-r--r-- | sys/arch/macppc/conf/files.macppc | 5 | ||||
-rw-r--r-- | sys/arch/macppc/macppc/conf.c | 6 | ||||
-rw-r--r-- | sys/arch/macppc/pci/agp_machdep.c | 34 | ||||
-rw-r--r-- | sys/arch/macppc/pci/pchb.c | 29 | ||||
-rw-r--r-- | sys/dev/pci/agp_apple.c | 214 | ||||
-rw-r--r-- | sys/dev/pci/agpreg.h | 13 | ||||
-rw-r--r-- | sys/dev/pci/files.agp | 6 |
7 files changed, 290 insertions, 17 deletions
diff --git a/sys/arch/macppc/conf/files.macppc b/sys/arch/macppc/conf/files.macppc index 19d72347e88..dfea2ab76ef 100644 --- a/sys/arch/macppc/conf/files.macppc +++ b/sys/arch/macppc/conf/files.macppc @@ -1,4 +1,4 @@ -# $OpenBSD: files.macppc,v 1.67 2012/09/08 16:35:46 mpi Exp $ +# $OpenBSD: files.macppc,v 1.68 2012/12/04 10:42:04 mpi Exp $ # # macppc-specific configuration info @@ -91,12 +91,13 @@ include "dev/wscons/files.wscons" #file arch/macppc/pci/bandit.c pci #PCI-Host bridge chipsets -device pchb +device pchb: agpbus attach pchb at pci file arch/macppc/pci/pchb.c pchb # AGP bridge support. attach at pchb include "dev/pci/files.agp" +file arch/macppc/pci/agp_machdep.c agp # # Machine-independent ATAPI drivers diff --git a/sys/arch/macppc/macppc/conf.c b/sys/arch/macppc/macppc/conf.c index 81e32d33345..369b9f31cbe 100644 --- a/sys/arch/macppc/macppc/conf.c +++ b/sys/arch/macppc/macppc/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.49 2012/08/30 21:54:13 mpi Exp $ */ +/* $OpenBSD: conf.c,v 1.50 2012/12/04 10:42:04 mpi Exp $ */ /* * Copyright (c) 1997 Per Fogelstrom @@ -114,6 +114,8 @@ cdev_decl(com); #include "apm.h" #include "bthub.h" +#include "agp.h" +cdev_decl(agp); #include "drm.h" cdev_decl(drm); @@ -236,7 +238,7 @@ struct cdevsw cdevsw[] = { cdev_vscsi_init(NVSCSI,vscsi), /* 83: vscsi */ cdev_disk_init(1,diskmap), /* 84: disk mapper */ cdev_pppx_init(NPPPX,pppx), /* 85: pppx */ - cdev_notdef(), /* 86: agp */ + cdev_agp_init(NAGP,agp), /* 86: agp */ cdev_drm_init(NDRM,drm), /* 87: drm */ }; int nchrdev = nitems(cdevsw); diff --git a/sys/arch/macppc/pci/agp_machdep.c b/sys/arch/macppc/pci/agp_machdep.c new file mode 100644 index 00000000000..718d42da4e4 --- /dev/null +++ b/sys/arch/macppc/pci/agp_machdep.c @@ -0,0 +1,34 @@ +/* $OpenBSD: agp_machdep.c,v 1.1 2012/12/04 10:42:05 mpi Exp $ */ + +/* + * Copyright (c) 2012 Martin Pieuchot <mpi@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/device.h> +#include <sys/malloc.h> + +#include <dev/pci/pcivar.h> +#include <dev/pci/pcireg.h> +#include <dev/pci/pcidevs.h> + +#include <dev/pci/agpvar.h> + +void +agp_flush_cache(void) +{ + __asm __volatile("sync" : : : "memory"); +} diff --git a/sys/arch/macppc/pci/pchb.c b/sys/arch/macppc/pci/pchb.c index 700103a68ab..897e8f16177 100644 --- a/sys/arch/macppc/pci/pchb.c +++ b/sys/arch/macppc/pci/pchb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pchb.c,v 1.11 2008/06/26 05:42:12 ray Exp $ */ +/* $OpenBSD: pchb.c,v 1.12 2012/12/04 10:42:05 mpi Exp $ */ /* $NetBSD: pchb.c,v 1.4 2000/01/25 07:19:11 tsubai Exp $ */ /*- @@ -41,6 +41,10 @@ #include <dev/pci/pcireg.h> #include <dev/pci/pcidevs.h> +#include <dev/pci/agpvar.h> + +#include "agp.h" + int pchbmatch(struct device *, void *, void *); void pchbattach(struct device *, struct device *, void *); @@ -101,17 +105,20 @@ pchbmatch(struct device *parent, void *cf, void *aux) void pchbattach(struct device *parent, struct device *self, void *aux) { +#if NAGP > 0 + struct pci_attach_args *pa = aux; +#endif /* NAGP > 0 */ + printf("\n"); - /* - * All we do is print out a description. Eventually, we - * might want to add code that does something that's - * possibly chipset-specific. - */ +#if NAGP > 0 + if (pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_AGP, + NULL, NULL) != 0) { + struct agp_attach_args aa; + aa.aa_busname = "agp"; + aa.aa_pa = pa; - /* - pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof devinfo); - printf("%s: %s (rev. 0x%02x)\n", self->dv_xname, devinfo, - PCI_REVISION(pa->pa_class)); - */ + config_found(self, &aa, agpdev_print); + } +#endif /* NAGP > 0 */ } diff --git a/sys/dev/pci/agp_apple.c b/sys/dev/pci/agp_apple.c new file mode 100644 index 00000000000..10fed199f48 --- /dev/null +++ b/sys/dev/pci/agp_apple.c @@ -0,0 +1,214 @@ +/* $OpenBSD: agp_apple.c,v 1.1 2012/12/04 10:42:04 mpi Exp $ */ + +/* + * Copyright (c) 2012 Martin Pieuchot <mpi@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/kernel.h> +#include <sys/malloc.h> +#include <sys/systm.h> +#include <sys/conf.h> +#include <sys/device.h> +#include <sys/agpio.h> + +#include <dev/pci/pcivar.h> +#include <dev/pci/pcireg.h> +#include <dev/pci/pcidevs.h> +#include <dev/pci/agpvar.h> +#include <dev/pci/agpreg.h> + +#include <machine/bus.h> + +#define M (1024 * 1024) + +struct agp_apple_softc { + struct device dev; + struct agp_softc *agpdev; + struct agp_gatt *gatt; + pci_chipset_tag_t asc_pc; + pcitag_t asc_tag; + bus_addr_t asc_apaddr; + bus_size_t asc_apsize; +}; + +int agp_apple_match(struct device *, void *, void *); +void agp_apple_attach(struct device *, struct device *, void *); +bus_size_t agp_apple_get_aperture(void *); +int agp_apple_set_aperture(void *sc, bus_size_t); +void agp_apple_bind_page(void *, bus_addr_t, paddr_t, int); +void agp_apple_unbind_page(void *, bus_addr_t); +void agp_apple_flush_tlb(void *); + +const struct cfattach appleagp_ca = { + sizeof(struct agp_apple_softc), agp_apple_match, agp_apple_attach, +}; + +struct cfdriver appleagp_cd = { + NULL, "appleagp", DV_DULL +}; + +const struct agp_methods agp_apple_methods = { + agp_apple_bind_page, + agp_apple_unbind_page, + agp_apple_flush_tlb, +}; + +int +agp_apple_match(struct device *parent, void *match, void *aux) +{ + struct agp_attach_args *aa = aux; + struct pci_attach_args *pa = aa->aa_pa; + + if (agpbus_probe(aa) != 1 || PCI_VENDOR(pa->pa_id) != PCI_VENDOR_APPLE) + return (0); + + switch (PCI_PRODUCT(pa->pa_id)) { + case PCI_PRODUCT_APPLE_UNINORTH_AGP: + case PCI_PRODUCT_APPLE_PANGEA_AGP: + case PCI_PRODUCT_APPLE_UNINORTH2_AGP: + case PCI_PRODUCT_APPLE_UNINORTH_AGP3: + case PCI_PRODUCT_APPLE_INTREPID2_AGP: + return (1); +#if 0 + /* + * XXX Do not attach U3 bridges to this driver yet. + * + * Even though they share the same register layout they + * use a big-endian GART and need a different set of + * commands for flushing their TLB. They should also + * support an aperture of 512M. + */ + case PCI_PRODUCT_APPLE_U3_AGP: + case PCI_PRODUCT_APPLE_U3L_AGP: + case PCI_PRODUCT_APPLE_K2_AGP: + return (1); +#endif + } + + return (0); +} + +void +agp_apple_attach(struct device *parent, struct device *self, void *aux) +{ + struct agp_apple_softc *asc = (struct agp_apple_softc *)self; + struct agp_attach_args *aa = aux; + struct pci_attach_args *pa = aa->aa_pa; + struct agp_gatt *gatt; + + asc->asc_tag = pa->pa_tag; + asc->asc_pc = pa->pa_pc; + + /* + * XXX It looks like UniNorth GART only accepts an aperture + * base address of 0x00 certainly because it does not perform + * any physical-to-physical address translation. + */ + asc->asc_apaddr = 0x00; + pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_APPLE_APBASE, + asc->asc_apaddr); + + /* + * There's no way to read the aperture size but all UniNorth + * chips seem to support an aperture of 256M. + */ + asc->asc_apsize = 256 * M; + for (;;) { + gatt = agp_alloc_gatt(pa->pa_dmat, asc->asc_apsize); + if (gatt != NULL) + break; + + asc->asc_apsize /= 2; + } + asc->gatt = gatt; + + if (agp_apple_set_aperture(asc, asc->asc_apsize)) { + printf("failed to set aperture\n"); + return; + } + + agp_apple_flush_tlb(asc); + + asc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_apple_methods, + asc->asc_apaddr, asc->asc_apsize, &asc->dev); +} + +bus_size_t +agp_apple_get_aperture(void *dev) +{ + struct agp_apple_softc *asc = dev; + + return (asc->asc_apsize); +} + +int +agp_apple_set_aperture(void *dev, bus_size_t aperture) +{ + struct agp_apple_softc *asc = dev; + + if (aperture % (4 * M) || aperture < (4 * M) || aperture > (256 * M)) + return (EINVAL); + + pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_APPLE_ATTBASE, + (asc->gatt->ag_physical & 0xfffff000) | (aperture >> 22)); + + return (0); +} + +#define flushd(p) __asm __volatile("dcbst 0,%0; sync" ::"r"(p) : "memory") + +void +agp_apple_bind_page(void *v, bus_addr_t off, paddr_t pa, int flags) +{ + struct agp_apple_softc *asc = v; + + if (off >= (asc->gatt->ag_entries << AGP_PAGE_SHIFT)) + return; + + asc->gatt->ag_virtual[off >> AGP_PAGE_SHIFT] = htole32(pa | 0x01); + + flushd(&asc->gatt->ag_virtual[off >> AGP_PAGE_SHIFT]); +} + +void +agp_apple_unbind_page(void *v, bus_size_t off) +{ + struct agp_apple_softc *asc = v; + + if (off >= (asc->gatt->ag_entries << AGP_PAGE_SHIFT)) + return; + + asc->gatt->ag_virtual[off >> AGP_PAGE_SHIFT] = 0; + + flushd(&asc->gatt->ag_virtual[off >> AGP_PAGE_SHIFT]); +} + +#undef flushd + +void +agp_apple_flush_tlb(void *v) +{ + struct agp_apple_softc *asc = v; + + pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_APPLE_GARTCTRL, + AGP_APPLE_GART_ENABLE | AGP_APPLE_GART_INVALIDATE); + pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_APPLE_GARTCTRL, + AGP_APPLE_GART_ENABLE); + pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_APPLE_GARTCTRL, + AGP_APPLE_GART_ENABLE | AGP_APPLE_GART_2XRESET); + pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_APPLE_GARTCTRL, + AGP_APPLE_GART_ENABLE); +} diff --git a/sys/dev/pci/agpreg.h b/sys/dev/pci/agpreg.h index e5d6b238d42..67f959e849e 100644 --- a/sys/dev/pci/agpreg.h +++ b/sys/dev/pci/agpreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: agpreg.h,v 1.15 2011/10/24 15:42:33 oga Exp $ */ +/* $OpenBSD: agpreg.h,v 1.16 2012/12/04 10:42:04 mpi Exp $ */ /* $NetBSD: agpreg.h,v 1.1 2001/09/10 10:01:02 fvdl Exp $ */ /*- @@ -111,6 +111,17 @@ #define AGP_SIS_TLBFLUSH 0x98 /* + * Config offsets for Apple UniNorth & U3 AGP chipsets. + */ +#define AGP_APPLE_ATTBASE 0x8c +#define AGP_APPLE_APBASE 0x90 +#define AGP_APPLE_GARTCTRL 0x94 + +#define AGP_APPLE_GART_INVALIDATE 0x00001 +#define AGP_APPLE_GART_ENABLE 0x00100 +#define AGP_APPLE_GART_2XRESET 0x10000 + +/* * Config offsets for Ali AGP chipsets. */ #define AGP_ALI_AGPCTRL 0xb8 diff --git a/sys/dev/pci/files.agp b/sys/dev/pci/files.agp index 4c714b70c38..18486979e22 100644 --- a/sys/dev/pci/files.agp +++ b/sys/dev/pci/files.agp @@ -1,4 +1,4 @@ -# $OpenBSD: files.agp,v 1.4 2011/05/30 22:03:47 oga Exp $ +# $OpenBSD: files.agp,v 1.5 2012/12/04 10:42:04 mpi Exp $ define agpdev {} @@ -15,6 +15,10 @@ device amdagp: agpdev attach amdagp at agpbus file dev/pci/agp_amd.c amdagp +device appleagp: agpdev +attach appleagp at agpbus +file dev/pci/agp_apple.c appleagp + device intelagp: agpdev attach intelagp at agpbus file dev/pci/agp_intel.c intelagp |