diff options
author | Owain Ainsworth <oga@cvs.openbsd.org> | 2008-11-09 15:11:20 +0000 |
---|---|---|
committer | Owain Ainsworth <oga@cvs.openbsd.org> | 2008-11-09 15:11:20 +0000 |
commit | c82365de6d1669d3aa8f37a7f91c598524aba316 (patch) | |
tree | b47841f2a3a7541cc4236df1638f5f4433c8f81e /sys/dev/pci | |
parent | 19e72e3b9f3138440f80b79260f2adaee85eae40 (diff) |
Rework that way that agp attaches.
previously, we had a static list of pcidevs and which agp driver would
be interanlly attached. Instead, split the agp drivers so they work like
audio(4), where we attach a driver, which sets up some callbacks and
initial state, then attaches the interface (agp(4)). Since this allows
us to attach different drivers in different places, and give them
/proper/ probe functions move most of the drivers back to attaching at
pchb, where they should, and intagp (formerly agp_i810) stays attaching
at vga, since it's part of the intel integrated graphics chips.
Diff shrinks the kernel slightly, gets rid of the annoying "no integrated
graphics" warning, and allows more cleanup later.
Tested by many. fix for alpha build (the only other vga_pci.c consumer)
suggested by miod.
Diffstat (limited to 'sys/dev/pci')
-rw-r--r-- | sys/dev/pci/agp.c | 388 | ||||
-rw-r--r-- | sys/dev/pci/agp_ali.c | 143 | ||||
-rw-r--r-- | sys/dev/pci/agp_amd.c | 177 | ||||
-rw-r--r-- | sys/dev/pci/agp_i810.c | 405 | ||||
-rw-r--r-- | sys/dev/pci/agp_intel.c | 267 | ||||
-rw-r--r-- | sys/dev/pci/agp_sis.c | 135 | ||||
-rw-r--r-- | sys/dev/pci/agp_via.c | 169 | ||||
-rw-r--r-- | sys/dev/pci/agpvar.h | 142 | ||||
-rw-r--r-- | sys/dev/pci/files.agp | 45 | ||||
-rw-r--r-- | sys/dev/pci/vga_pci.c | 53 |
10 files changed, 893 insertions, 1031 deletions
diff --git a/sys/dev/pci/agp.c b/sys/dev/pci/agp.c index 85475c592b9..91051ee9349 100644 --- a/sys/dev/pci/agp.c +++ b/sys/dev/pci/agp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agp.c,v 1.26 2008/09/26 21:15:53 mikeb Exp $ */ +/* $OpenBSD: agp.c,v 1.27 2008/11/09 15:11:19 oga Exp $ */ /*- * Copyright (c) 2000 Doug Rabson * All rights reserved. @@ -46,18 +46,48 @@ #include <dev/pci/agpvar.h> #include <dev/pci/agpreg.h> -#include "agp_ali.h" -#include "agp_amd.h" -#include "agp_amd64.h" -#include "agp_apple.h" -#include "agp_i810.h" -#include "agp_intel.h" -#include "agp_sis.h" -#include "agp_via.h" +/* + * the enable and {alloc, free, bind, unbind} memory routines have default + * fallbacks, these macros do the right thing. The callbacks with no fallback + * are called directly. These are mostly hacks around the weirdness of intel + * integrated graphics, since they are not technically a true agp chipset, + * but provide an almost identical interface. + */ +#define AGP_ENABLE(sc, m) ((sc->sc_methods->enable != NULL) ? \ + sc->sc_methods->enable(sc->sc_chipc, m) : \ + agp_generic_enable(sc, m)) + +#define AGP_ALLOC_MEMORY(sc, t, s) ((sc->sc_methods->alloc_memory != NULL) ? \ + sc->sc_methods->alloc_memory(sc->sc_chipc, t, s) : \ + agp_generic_alloc_memory(sc, t, s)) + +#define AGP_FREE_MEMORY(sc, m) ((sc->sc_methods->free_memory != NULL) ? \ + sc->sc_methods->free_memory(sc->sc_chipc, m) : \ + agp_generic_free_memory(sc, m)) + +#define AGP_BIND_MEMORY(sc, m, o) ((sc->sc_methods->bind_memory != NULL) ? \ + sc->sc_methods->bind_memory(sc->sc_chipc, m, o) : \ + agp_generic_bind_memory(sc, m, o)) + +#define AGP_UNBIND_MEMORY(sc, m) ((sc->sc_methods->unbind_memory != NULL) ? \ + sc->sc_methods->unbind_memory(sc->sc_chipc, m) : \ + agp_generic_unbind_memory(sc, m)) + +int agp_generic_enable(struct agp_softc *, u_int32_t); +struct agp_memory * + agp_generic_alloc_memory(struct agp_softc *, int, vsize_t size); +int agp_generic_free_memory(struct agp_softc *, struct agp_memory *); +void agp_attach(struct device *, struct device *, void *); +int agp_probe(struct device *, void *, void *); +int agpbusprint(void *, const char *); +paddr_t agpmmap(void *, off_t, int); +int agpioctl(dev_t, u_long, caddr_t, int, struct proc *); +int agpopen(dev_t, int, int, struct proc *); +int agpclose(dev_t, int, int , struct proc *); struct agp_memory *agp_find_memory(struct agp_softc *sc, int id); -const struct agp_product *agp_lookup(struct pci_attach_args *pa); /* userland ioctl functions */ +int agpvga_match(struct pci_attach_args *); int agp_info_user(void *, agp_info *); int agp_setup_user(void *, agp_setup *); int agp_allocate_user(void *, agp_allocate *); @@ -67,137 +97,133 @@ int agp_unbind_user(void *, agp_unbind *); int agp_acquire_helper(void *dev, enum agp_acquire_state state); int agp_release_helper(void *dev, enum agp_acquire_state state); -const struct agp_product agp_products[] = { -#if NAGP_ALI > 0 - { PCI_VENDOR_ALI, -1, agp_ali_attach }, -#endif -#if NAGP_AMD > 0 - { PCI_VENDOR_AMD, -1, agp_amd_attach }, -#endif -#if NAGP_I810 > 0 - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82810_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82810_DC100_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82810E_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82815_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82830M_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82845G_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82855GM_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82865G_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82915G_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82915GM_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82945G_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82945GM_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82945GME_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82G965_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82Q965_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82GM965_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82G33_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82G35_HB, agp_i810_attach }, - { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82Q35_HB, agp_i810_attach }, -#endif -#if NAGP_INTEL > 0 - { PCI_VENDOR_INTEL, -1, agp_intel_attach }, -#endif -#if NAGP_SIS > 0 - { PCI_VENDOR_SIS, -1, agp_sis_attach }, -#endif -#if NAGP_VIA > 0 - { PCI_VENDOR_VIATECH, -1, agp_via_attach }, -#endif - { 0, 0, NULL } -}; +int +agpdev_print(void *aux, const char *pnp) +{ + if (pnp) { + printf("agp at %s", pnp); + } + return (UNCONF); +} +int +agpbus_probe(struct agp_attach_args *aa) +{ + struct pci_attach_args *pa = aa->aa_pa; + + if (strncmp(aa->aa_busname, "agp", 3) == 0 && + PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE && + PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_HOST) + return (1); + return (0); +} +/* + * Find the video card hanging off the agp bus XXX assumes only one bus + */ int -agp_probe(struct device *parent, void *match, void *aux) +agpvga_match(struct pci_attach_args *pa) +{ + if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY && + PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_DISPLAY_VGA) { + if (pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_AGP, + NULL, NULL)) + return (1); + } + return (0); +} + +struct device * +agp_attach_bus(struct pci_attach_args *pa, const struct agp_methods *methods, + int bar, pcireg_t type, struct device *dev) { - struct agpbus_attach_args *aaa = aux; - struct pci_attach_args *pa = &aaa->apa_pci_args; + struct agpbus_attach_args arg; - /* pci_args must be a pchb */ - if (PCI_CLASS(pa->pa_class) != PCI_CLASS_BRIDGE || - PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_BRIDGE_HOST) - return (0); + arg.aa_methods = methods; + arg.aa_pa = pa; + arg.aa_bar = bar; + arg.aa_type = type; - if (agp_lookup(pa) == NULL) - return (0); + printf("\n"); /* newline from the driver that called us */ + return (config_found(dev, &arg, agpdev_print)); +} +int +agp_probe(struct device *parent, void *match, void *aux) +{ + /* + * we don't do any checking here, driver we're attaching this + * interface to should have already done it. + */ return (1); } void agp_attach(struct device *parent, struct device *self, void *aux) { - struct agpbus_attach_args *aaa = aux; - struct pci_attach_args *pa = &aaa->apa_pci_args; + struct agpbus_attach_args *aa = aux; + struct pci_attach_args *pa = aa->aa_pa; struct agp_softc *sc = (struct agp_softc *)self; - const struct agp_product *ap; u_int memsize; - int i, ret; - - ap = agp_lookup(pa); - if (ap) { - static const int agp_max[][2] = { - {0, 0}, - {32, 4}, - {64, 28}, - {128, 96}, - {256, 204}, - {512, 440}, - {1024, 942}, - {2048, 1920}, - {4096, 3932} - }; -#define agp_max_size (sizeof(agp_max)/sizeof(agp_max[0])) - - /* - * Work out an upper bound for agp memory allocation. This - * uses a heuristic table from the Linux driver. - */ - memsize = ptoa(physmem) >> 20; + int i; - for (i = 0; i < agp_max_size && memsize > agp_max[i][0]; i++) - ; - if (i == agp_max_size) - i = agp_max_size - 1; - sc->sc_maxmem = agp_max[i][1] << 20; + sc->sc_chipc = parent; + sc->sc_methods = aa->aa_methods; + + static const int agp_max[][2] = { + {0, 0}, + {32, 4}, + {64, 28}, + {128, 96}, + {256, 204}, + {512, 440}, + {1024, 942}, + {2048, 1920}, + {4096, 3932} + }; +#define agp_max_size (sizeof(agp_max)/sizeof(agp_max[0])) - /* - * The lock is used to prevent re-entry to - * agp_generic_bind_memory() since that function can sleep. - */ + /* + * Work out an upper bound for agp memory allocation. This + * uses a heuristic table from the Linux driver. + */ + memsize = ptoa(physmem) >> 20; - rw_init(&sc->sc_lock, "agplk"); + for (i = 0; i < agp_max_size && memsize > agp_max[i][0]; i++) + ; + if (i == agp_max_size) + i = agp_max_size - 1; + sc->sc_maxmem = agp_max[i][1] << 20; - TAILQ_INIT(&sc->sc_memory); + /* + * The lock is used to prevent re-entry to + * agp_generic_bind_memory() since that function can sleep. + */ + rw_init(&sc->sc_lock, "agplk"); - sc->sc_pcitag = pa->pa_tag; - sc->sc_pc = pa->pa_pc; - sc->sc_id = pa->pa_id; - sc->sc_dmat = pa->pa_dmat; - sc->sc_memt = pa->pa_memt; - sc->sc_vgapcitag = aaa->apa_vga_args.pa_tag; - sc->sc_vgapc = aaa->apa_vga_args.pa_pc; + TAILQ_INIT(&sc->sc_memory); - pci_get_capability(sc->sc_pc, sc->sc_pcitag, PCI_CAP_AGP, - &sc->sc_capoff, NULL); + sc->sc_pcitag = pa->pa_tag; + sc->sc_pc = pa->pa_pc; + sc->sc_id = pa->pa_id; + sc->sc_dmat = pa->pa_dmat; - sc->vga_softc = (struct vga_pci_softc *)parent; + pci_get_capability(sc->sc_pc, sc->sc_pcitag, PCI_CAP_AGP, + &sc->sc_capoff, NULL); - printf(": "); - ret = (*ap->ap_attach)(sc, pa); - if (ret == 0) - printf("aperture at 0x%lx, size 0x%lx\n", - (u_long)sc->sc_apaddr, - (u_long)AGP_GET_APERTURE(sc)); - else { - sc->sc_chipc = NULL; - } + printf(": "); + if (agp_map_aperture(pa, sc, aa->aa_bar, aa->aa_type) != 0) { + printf("can't map aperture\n"); + sc->sc_chipc = NULL; + return; } + + printf("aperture at 0x%lx, size 0x%lx\n", (u_long)sc->sc_apaddr, + (u_long)sc->sc_methods->get_aperture(sc->sc_chipc)); } struct cfattach agp_ca = { - sizeof (struct agp_softc), agp_probe, agp_attach, + sizeof(struct agp_softc), agp_probe, agp_attach, NULL, NULL }; @@ -212,7 +238,7 @@ agpmmap(void *v, off_t off, int prot) if (sc->sc_apaddr) { - if (off > AGP_GET_APERTURE(sc)) + if (off > sc->sc_methods->get_aperture(sc->sc_chipc)) return (-1); /* @@ -229,10 +255,7 @@ agpopen(dev_t dev, int oflags, int devtype, struct proc *p) { struct agp_softc *sc = agp_find_device(AGPUNIT(dev)); - if (sc == NULL) - return (ENXIO); - - if (sc->sc_chipc == NULL) + if (sc == NULL || sc->sc_chipc == NULL) return (ENXIO); if (!sc->sc_opened) @@ -249,7 +272,7 @@ agpioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *pb) { struct agp_softc *sc = agp_find_device(AGPUNIT(dev)); - if (sc ==NULL) + if (sc == NULL) return (ENODEV); if (sc->sc_methods == NULL || sc->sc_chipc == NULL) @@ -300,8 +323,9 @@ agpclose(dev_t dev, int flags, int devtype, struct proc *p) */ if (sc->sc_state == AGP_ACQUIRE_USER) { while ((mem = TAILQ_FIRST(&sc->sc_memory)) != 0) { - if (mem->am_is_bound) + if (mem->am_is_bound) { AGP_UNBIND_MEMORY(sc, mem); + } AGP_FREE_MEMORY(sc, mem); } agp_release_helper(sc, AGP_ACQUIRE_USER); @@ -325,78 +349,30 @@ agp_find_memory(struct agp_softc *sc, int id) return (0); } -const struct agp_product * -agp_lookup(struct pci_attach_args *pa) -{ - const struct agp_product *ap; - - /* First find the vendor. */ - for (ap = agp_products; ap->ap_attach != NULL; ap++) - if (ap->ap_vendor == PCI_VENDOR(pa->pa_id)) - break; - - if (ap->ap_attach == NULL) - return (NULL); - - /* Now find the product within the vendor's domain. */ - for (; ap->ap_attach != NULL; ap++) { - /* Ran out of this vendor's section of the table. */ - if (ap->ap_vendor != PCI_VENDOR(pa->pa_id)) - return (NULL); - - if (ap->ap_product == PCI_PRODUCT(pa->pa_id)) - break; /* Exact match. */ - if (ap->ap_product == (u_int32_t) -1) - break; /* Wildcard match. */ - } - - if (ap->ap_attach == NULL) - ap = NULL; - - return (ap); -} - int agp_map_aperture(struct pci_attach_args *pa, struct agp_softc *sc, u_int32_t bar, u_int32_t memtype) { /* Find the aperture. Don't map it (yet), this would eat KVA */ - if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, - memtype, &sc->sc_apaddr, &sc->sc_apsize, - &sc->sc_apflags) != 0) + if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, memtype, + &sc->sc_apaddr, NULL, NULL) != 0) return (ENXIO); return (0); } -u_int32_t -agp_generic_get_aperture(struct agp_softc *sc) -{ - return (sc->sc_apsize); -} - -int -agp_generic_set_aperture(struct agp_softc *sc, u_int32_t aperture) -{ - if (aperture != AGP_GET_APERTURE(sc)) - return (EINVAL); - - return (0); -} - struct agp_gatt * -agp_alloc_gatt(struct agp_softc *sc) +agp_alloc_gatt(bus_dma_tag_t dmat, u_int32_t apsize) { - u_int32_t apsize = AGP_GET_APERTURE(sc); - u_int32_t entries = apsize >> AGP_PAGE_SHIFT; - struct agp_gatt *gatt; - int nseg; + struct agp_gatt *gatt; + u_int32_t entries = apsize >> AGP_PAGE_SHIFT; + int nseg; gatt = malloc(sizeof(*gatt), M_AGP, M_NOWAIT | M_ZERO); if (!gatt) return (NULL); gatt->ag_entries = entries; - if (agp_alloc_dmamem(sc->sc_dmat, entries * sizeof(u_int32_t), + if (agp_alloc_dmamem(dmat, entries * sizeof(u_int32_t), 0, &gatt->ag_dmamap, (caddr_t *)&gatt->ag_virtual, &gatt->ag_physical, &gatt->ag_dmaseg, 1, &nseg) != 0) return (NULL); @@ -409,28 +385,22 @@ agp_alloc_gatt(struct agp_softc *sc) } void -agp_free_gatt(struct agp_softc *sc, struct agp_gatt *gatt) +agp_free_gatt(bus_dma_tag_t dmat, struct agp_gatt *gatt) { - agp_free_dmamem(sc->sc_dmat, gatt->ag_size, gatt->ag_dmamap, + agp_free_dmamem(dmat, gatt->ag_size, gatt->ag_dmamap, (caddr_t)gatt->ag_virtual, &gatt->ag_dmaseg, 1); free(gatt, M_AGP); } int -agp_generic_detach(struct agp_softc *sc) -{ - agp_flush_cache(); - return (0); -} - -int agp_generic_enable(struct agp_softc *sc, u_int32_t mode) { - pcireg_t tstatus, mstatus; - pcireg_t command; - int rq, sba, fw, rate, capoff; + struct pci_attach_args pa; + pcireg_t tstatus, mstatus, command; + int rq, sba, fw, rate, capoff; - if (pci_get_capability(sc->sc_vgapc, sc->sc_vgapcitag, PCI_CAP_AGP, + if (pci_find_device(&pa, agpvga_match) == 0 || + pci_get_capability(pa.pa_pc, pa.pa_tag, PCI_CAP_AGP, &capoff, NULL) == 0) { printf("agp_generic_enable: not an AGP capable device\n"); return (-1); @@ -439,7 +409,7 @@ agp_generic_enable(struct agp_softc *sc, u_int32_t mode) tstatus = pci_conf_read(sc->sc_pc, sc->sc_pcitag, sc->sc_capoff + AGP_STATUS); /* display agp mode */ - mstatus = pci_conf_read(sc->sc_vgapc, sc->sc_vgapcitag, + mstatus = pci_conf_read(pa.pa_pc, pa.pa_tag, capoff + AGP_STATUS); /* Set RQ to the min of mode, tstatus and mstatus */ @@ -479,8 +449,7 @@ agp_generic_enable(struct agp_softc *sc, u_int32_t mode) pci_conf_write(sc->sc_pc, sc->sc_pcitag, sc->sc_capoff + AGP_COMMAND, command); - pci_conf_write(sc->sc_vgapc, sc->sc_vgapcitag, capoff + AGP_COMMAND, - command); + pci_conf_write(pa.pa_pc, pa.pa_tag, capoff + AGP_COMMAND, command); return (0); } @@ -541,9 +510,9 @@ agp_generic_bind_memory(struct agp_softc *sc, struct agp_memory *mem, return (EINVAL); } - if (offset < 0 - || (offset & (AGP_PAGE_SIZE - 1)) != 0 - || offset + mem->am_size > AGP_GET_APERTURE(sc)) { + if (offset < 0 || (offset & (AGP_PAGE_SIZE - 1)) != 0 + || offset + mem->am_size > + sc->sc_methods->get_aperture(sc->sc_chipc)) { printf("AGP: binding memory at bad offset %#lx\n", (unsigned long) offset); rw_exit_write(&sc->sc_lock); @@ -606,14 +575,16 @@ agp_generic_bind_memory(struct agp_softc *sc, struct agp_memory *mem, AGP_DPF("binding offset %#lx to pa %#lx\n", (unsigned long)(offset + done + j), (unsigned long)pa); - error = AGP_BIND_PAGE(sc, offset + done + j, pa); + error = sc->sc_methods->bind_page(sc->sc_chipc, + offset + done + j, pa); if (error) { /* * Bail out. Reverse all the mappings * and unwire the pages. */ for (k = 0; k < done + j; k += AGP_PAGE_SIZE) - AGP_UNBIND_PAGE(sc, offset + k); + sc->sc_methods->unbind_page( + sc->sc_chipc, offset + k); bus_dmamap_unload(sc->sc_dmat, mem->am_dmamap); bus_dmamem_unmap(sc->sc_dmat, mem->am_virtual, @@ -638,7 +609,7 @@ agp_generic_bind_memory(struct agp_softc *sc, struct agp_memory *mem, /* * Make sure the chipset gets the new mappings. */ - AGP_FLUSH_TLB(sc); + sc->sc_methods->flush_tlb(sc->sc_chipc); mem->am_offset = offset; mem->am_is_bound = 1; @@ -667,10 +638,10 @@ agp_generic_unbind_memory(struct agp_softc *sc, struct agp_memory *mem) * TLB. Unwire the pages so they can be swapped. */ for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) - AGP_UNBIND_PAGE(sc, mem->am_offset + i); + sc->sc_methods->unbind_page(sc->sc_chipc, mem->am_offset + i); agp_flush_cache(); - AGP_FLUSH_TLB(sc); + sc->sc_methods->flush_tlb(sc->sc_chipc); bus_dmamap_unload(sc->sc_dmat, mem->am_dmamap); bus_dmamem_unmap(sc->sc_dmat, mem->am_virtual, mem->am_size); @@ -807,7 +778,7 @@ agp_info_user(void *dev, agp_info *info) else info->agp_mode = 0; /* i810 doesn't have real AGP */ info->aper_base = sc->sc_apaddr; - info->aper_size = AGP_GET_APERTURE(sc) >> 20; + info->aper_size = sc->sc_methods->get_aperture(sc->sc_chipc) >> 20; info->pg_total = info->pg_system = sc->sc_maxmem >> AGP_PAGE_SHIFT; info->pg_used = sc->sc_allocated >> AGP_PAGE_SHIFT; @@ -818,7 +789,7 @@ agp_info_user(void *dev, agp_info *info) int agp_setup_user(void *dev, agp_setup *setup) { - struct agp_softc *sc = (struct agp_softc *) dev; + struct agp_softc *sc = (struct agp_softc *)dev; return (AGP_ENABLE(sc, setup->agp_mode)); } @@ -826,7 +797,7 @@ agp_setup_user(void *dev, agp_setup *setup) int agp_allocate_user(void *dev, agp_allocate *alloc) { - struct agp_softc *sc = (struct agp_softc *) dev; + struct agp_softc *sc = (struct agp_softc *)dev; struct agp_memory* mem; size_t size = alloc->pg_count << AGP_PAGE_SHIFT; @@ -901,10 +872,13 @@ agp_get_info(void *dev, struct agp_info *info) { struct agp_softc *sc = (struct agp_softc *)dev; - info->ai_mode = pci_conf_read(sc->sc_pc, sc->sc_pcitag, - sc->sc_capoff + AGP_STATUS); + if (sc->sc_capoff != 0) + info->ai_mode = pci_conf_read(sc->sc_pc, sc->sc_pcitag, + AGP_STATUS + sc->sc_capoff); + else + info->ai_mode = 0; /* i810 doesn't have real AGP */ info->ai_aperture_base = sc->sc_apaddr; - info->ai_aperture_size = sc->sc_apsize; + info->ai_aperture_size = sc->sc_methods->get_aperture(sc->sc_chipc); info->ai_memory_allowed = sc->sc_maxmem; info->ai_memory_used = sc->sc_allocated; } @@ -938,7 +912,7 @@ agp_alloc_memory(void *dev, int type, vsize_t bytes) { struct agp_softc *sc = (struct agp_softc *)dev; - return ((void *) AGP_ALLOC_MEMORY(sc, type, bytes)); + return (AGP_ALLOC_MEMORY(sc, type, bytes)); } void diff --git a/sys/dev/pci/agp_ali.c b/sys/dev/pci/agp_ali.c index f6ed191562c..eea5d6b081f 100644 --- a/sys/dev/pci/agp_ali.c +++ b/sys/dev/pci/agp_ali.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agp_ali.c,v 1.5 2007/11/26 15:35:15 deraadt Exp $ */ +/* $OpenBSD: agp_ali.c,v 1.6 2008/11/09 15:11:19 oga Exp $ */ /* $NetBSD: agp_ali.c,v 1.2 2001/09/15 00:25:00 thorpej Exp $ */ @@ -30,8 +30,6 @@ * $FreeBSD: src/sys/pci/agp_ali.c,v 1.3 2001/07/05 21:28:46 jhb Exp $ */ - - #include <sys/param.h> #include <sys/kernel.h> #include <sys/malloc.h> @@ -44,6 +42,7 @@ #include <dev/pci/pcivar.h> #include <dev/pci/pcireg.h> +#include <dev/pci/pcidevs.h> #include <dev/pci/vga_pcivar.h> #include <dev/pci/agpvar.h> #include <dev/pci/agpreg.h> @@ -51,80 +50,91 @@ #include <machine/bus.h> struct agp_ali_softc { - u_int32_t initial_aperture; /* aperture size at startup */ - struct agp_gatt *gatt; + struct device dev; + struct agp_softc *agpdev; + struct agp_gatt *gatt; + pci_chipset_tag_t asc_pc; + pcitag_t asc_tag; + bus_size_t initial_aperture; }; -u_int32_t agp_ali_get_aperture(struct agp_softc *); -int agp_ali_set_aperture(struct agp_softc *sc, u_int32_t); -int agp_ali_bind_page(struct agp_softc *, off_t, bus_addr_t); -int agp_ali_unbind_page(struct agp_softc *, off_t); -void agp_ali_flush_tlb(struct agp_softc *); +void agp_ali_attach(struct device *, struct device *, void *); +int agp_ali_probe(struct device *, void *, void *); +bus_size_t agp_ali_get_aperture(void *); +int agp_ali_set_aperture(void *sc, bus_size_t); +int agp_ali_bind_page(void *, off_t, bus_addr_t); +int agp_ali_unbind_page(void *, off_t); +void agp_ali_flush_tlb(void *); + +struct cfattach aliagp_ca = { + sizeof(struct agp_ali_softc), agp_ali_probe, agp_ali_attach +}; -struct agp_methods agp_ali_methods = { +struct cfdriver aliagp_cd = { + NULL, "aliagp", DV_DULL +}; + +const struct agp_methods agp_ali_methods = { agp_ali_get_aperture, - agp_ali_set_aperture, agp_ali_bind_page, agp_ali_unbind_page, agp_ali_flush_tlb, - agp_generic_enable, - agp_generic_alloc_memory, - agp_generic_free_memory, - agp_generic_bind_memory, - agp_generic_unbind_memory, }; -int -agp_ali_attach(struct agp_softc *sc, struct pci_attach_args *pa) +int +agp_ali_probe(struct device *parent, void *match, void *aux) { - struct agp_ali_softc *asc; - struct agp_gatt *gatt; - pcireg_t reg; + struct agp_attach_args *aa = aux; + struct pci_attach_args *pa = aa->aa_pa; - asc = malloc(sizeof *asc, M_AGP, M_NOWAIT); - if (asc == NULL) { - printf("failed to allocate softc\n"); - return (ENOMEM); - } - sc->sc_chipc = asc; - sc->sc_methods = &agp_ali_methods; + /* Must be a pchb */ + if (agpbus_probe(aa) == 1 && PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ALI) + return (1); + return (0); +} - if (agp_map_aperture(pa, sc, AGP_APBASE, PCI_MAPREG_TYPE_MEM) != 0) { - printf("failed to map aperture\n"); - free(asc, M_AGP); - return (ENXIO); - } +void +agp_ali_attach(struct device *parent, struct device *self, void *aux) +{ + struct agp_ali_softc *asc = (struct agp_ali_softc *)self; + struct agp_gatt *gatt; + struct agp_attach_args *aa = aux; + struct pci_attach_args *pa = aa->aa_pa; + pcireg_t reg; - asc->initial_aperture = agp_ali_get_aperture(sc); + asc->asc_tag = pa->pa_tag; + asc->asc_pc = pa->pa_pc; + asc->initial_aperture = agp_ali_get_aperture(asc); for (;;) { - gatt = agp_alloc_gatt(sc); + bus_size_t size = agp_ali_get_aperture(asc); + gatt = agp_alloc_gatt(pa->pa_dmat, size); if (gatt != NULL) break; - /* - * Probably contigmalloc failure. Try reducing the - * aperture so that the gatt size reduces. + * almost certainly error allocating contigious dma memory + * so reduce aperture so that the gatt size reduces. */ - if (AGP_SET_APERTURE(sc, AGP_GET_APERTURE(sc) / 2)) { - agp_generic_detach(sc); + if (agp_ali_set_aperture(asc, size / 2)) { printf("failed to set aperture\n"); - return (ENOMEM); + return; } } asc->gatt = gatt; /* Install the gatt. */ - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_ALI_ATTBASE); + reg = pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_ALI_ATTBASE); reg = (reg & 0xff) | gatt->ag_physical; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_ALI_ATTBASE, reg); + pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_ALI_ATTBASE, reg); /* Enable the TLB. */ - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_ALI_TLBCTRL); + reg = pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_ALI_TLBCTRL); reg = (reg & ~0xff) | 0x10; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_ALI_TLBCTRL, reg); + pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_ALI_TLBCTRL, reg); - return (0); + asc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_ali_methods, + AGP_APBASE, PCI_MAPREG_TYPE_MEM, &asc->dev); + return; } #if 0 @@ -173,16 +183,17 @@ static const u_int32_t agp_ali_table[] = { }; #define agp_ali_table_size (sizeof(agp_ali_table) / sizeof(agp_ali_table[0])) -u_int32_t -agp_ali_get_aperture(struct agp_softc *sc) +bus_size_t +agp_ali_get_aperture(void *sc) { - int i; + struct agp_ali_softc *asc = sc; + int i; /* * The aperture size is derived from the low bits of attbase. * I'm not sure this is correct.. */ - i = (int)pci_conf_read(sc->sc_pc, sc->sc_pcitag, + i = (int)pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_ALI_ATTBASE) & 0xff; if (i >= agp_ali_table_size) return (0); @@ -190,10 +201,11 @@ agp_ali_get_aperture(struct agp_softc *sc) } int -agp_ali_set_aperture(struct agp_softc *sc, u_int32_t aperture) +agp_ali_set_aperture(void *sc, bus_size_t aperture) { - int i; - pcireg_t reg; + struct agp_ali_softc *asc = sc; + int i; + pcireg_t reg; for (i = 0; i < agp_ali_table_size; i++) if (agp_ali_table[i] == aperture) @@ -201,17 +213,17 @@ agp_ali_set_aperture(struct agp_softc *sc, u_int32_t aperture) if (i == agp_ali_table_size) return (EINVAL); - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_ALI_ATTBASE); + reg = pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_ALI_ATTBASE); reg &= ~0xff; reg |= i; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_ALI_ATTBASE, reg); + pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_ALI_ATTBASE, reg); return (0); } int -agp_ali_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical) +agp_ali_bind_page(void *sc, off_t offset, bus_addr_t physical) { - struct agp_ali_softc *asc = sc->sc_chipc; + struct agp_ali_softc *asc = sc; if (offset < 0 || offset >= (asc->gatt->ag_entries << AGP_PAGE_SHIFT)) return (EINVAL); @@ -221,9 +233,9 @@ agp_ali_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical) } int -agp_ali_unbind_page(struct agp_softc *sc, off_t offset) +agp_ali_unbind_page(void *sc, off_t offset) { - struct agp_ali_softc *asc = sc->sc_chipc; + struct agp_ali_softc *asc = sc; if (offset < 0 || offset >= (asc->gatt->ag_entries << AGP_PAGE_SHIFT)) return (EINVAL); @@ -233,16 +245,17 @@ agp_ali_unbind_page(struct agp_softc *sc, off_t offset) } void -agp_ali_flush_tlb(struct agp_softc *sc) +agp_ali_flush_tlb(void *sc) { - pcireg_t reg; + struct agp_ali_softc *asc = sc; + pcireg_t reg; - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_ALI_TLBCTRL); + reg = pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_ALI_TLBCTRL); reg &= ~0xff; reg |= 0x90; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_ALI_TLBCTRL, reg); + pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_ALI_TLBCTRL, reg); reg &= ~0xff; reg |= 0x10; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_ALI_TLBCTRL, reg); + pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_ALI_TLBCTRL, reg); } diff --git a/sys/dev/pci/agp_amd.c b/sys/dev/pci/agp_amd.c index 1c3a3e2b31d..714213f7b00 100644 --- a/sys/dev/pci/agp_amd.c +++ b/sys/dev/pci/agp_amd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agp_amd.c,v 1.8 2007/12/07 17:35:22 oga Exp $ */ +/* $OpenBSD: agp_amd.c,v 1.9 2008/11/09 15:11:19 oga Exp $ */ /* $NetBSD: agp_amd.c,v 1.6 2001/10/06 02:48:50 thorpej Exp $ */ /*- @@ -29,8 +29,6 @@ * $FreeBSD: src/sys/pci/agp_amd.c,v 1.6 2001/07/05 21:28:46 jhb Exp $ */ - - #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> @@ -67,39 +65,45 @@ struct agp_amd_gatt { }; struct agp_amd_softc { - u_int32_t initial_aperture; /* aperture size at startup */ - struct agp_amd_gatt *gatt; - bus_space_handle_t ioh; - bus_space_tag_t iot; + struct device dev; + struct agp_softc *agpdev; + struct agp_amd_gatt *gatt; + pci_chipset_tag_t asc_pc; + pcitag_t asc_tag; + bus_space_handle_t ioh; + bus_space_tag_t iot; + bus_size_t initial_aperture; }; -u_int32_t agp_amd_get_aperture(struct agp_softc *); -struct agp_amd_gatt * agp_amd_alloc_gatt(struct agp_softc *); -int agp_amd_set_aperture(struct agp_softc *, u_int32_t); -int agp_amd_bind_page(struct agp_softc *, off_t, bus_addr_t); -int agp_amd_unbind_page(struct agp_softc *, off_t); -void agp_amd_flush_tlb(struct agp_softc *); +void agp_amd_attach(struct device *, struct device *, void *); +int agp_amd_probe(struct device *, void *, void *); +bus_size_t agp_amd_get_aperture(void *); +struct agp_amd_gatt *agp_amd_alloc_gatt(bus_dma_tag_t, bus_size_t); +int agp_amd_set_aperture(void *, bus_size_t); +int agp_amd_bind_page(void *, off_t, bus_addr_t); +int agp_amd_unbind_page(void *, off_t); +void agp_amd_flush_tlb(void *); + +struct cfattach amdagp_ca = { + sizeof(struct agp_amd_softc), agp_amd_probe, agp_amd_attach +}; +struct cfdriver amdagp_cd = { + NULL, "amdagp", DV_DULL +}; -struct agp_methods agp_amd_methods = { +const struct agp_methods agp_amd_methods = { agp_amd_get_aperture, - agp_amd_set_aperture, agp_amd_bind_page, agp_amd_unbind_page, agp_amd_flush_tlb, - agp_generic_enable, - agp_generic_alloc_memory, - agp_generic_free_memory, - agp_generic_bind_memory, - agp_generic_unbind_memory, }; struct agp_amd_gatt * -agp_amd_alloc_gatt(struct agp_softc *sc) +agp_amd_alloc_gatt(bus_dma_tag_t dmat, bus_size_t apsize) { - u_int32_t apsize = AGP_GET_APERTURE(sc); - u_int32_t entries = apsize >> AGP_PAGE_SHIFT; + bus_size_t entries = apsize >> AGP_PAGE_SHIFT; struct agp_amd_gatt *gatt; int i, npages; caddr_t vdir; @@ -108,7 +112,7 @@ agp_amd_alloc_gatt(struct agp_softc *sc) if (!gatt) return (0); - if (agp_alloc_dmamem(sc->sc_dmat, + if (agp_alloc_dmamem(dmat, AGP_PAGE_SIZE + entries * sizeof(u_int32_t), 0, &gatt->ag_dmamap, &vdir, &gatt->ag_pdir, &gatt->ag_dmaseg, 1, &gatt->ag_nseg) != 0) { @@ -145,9 +149,9 @@ agp_amd_alloc_gatt(struct agp_softc *sc) #if 0 void -agp_amd_free_gatt(struct agp_softc *sc, struct agp_amd_gatt *gatt) +agp_amd_free_gatt(bus_dma_tag_t dmat, struct agp_amd_gatt *gatt) { - agp_free_dmamem(sc->sc_dmat, gatt->ag_size, + agp_free_dmamem(dmat, gatt->ag_size, gatt->ag_dmamap, (caddr_t)gatt->ag_virtual, &gatt->ag_dmaseg, gatt->ag_nseg); free(gatt, M_AGP); @@ -155,50 +159,55 @@ agp_amd_free_gatt(struct agp_softc *sc, struct agp_amd_gatt *gatt) #endif int -agp_amd_attach(struct agp_softc *sc, struct pci_attach_args *pa) +agp_amd_probe(struct device *parent, void *match, void *aux) { - struct agp_amd_softc *asc; - struct agp_amd_gatt *gatt; - pcireg_t reg; - int error; - - asc = malloc(sizeof *asc, M_AGP, M_NOWAIT | M_ZERO); - if (asc == NULL) { - printf("can't allocate softc\n"); - /* agp_generic_detach(sc) */ - return (ENOMEM); - } + struct agp_attach_args *aa = aux; + struct pci_attach_args *pa = aa->aa_pa; + + /* Must be a pchb */ + if (agpbus_probe(aa) == 1 && PCI_VENDOR(pa->pa_id) == PCI_VENDOR_AMD && + (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_AMD_SC751_SC || + PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_AMD_761_PCHB || + PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_AMD_762_PCHB)) + return (1); + return (0); +} + +void +agp_amd_attach(struct device *parent, struct device *self, void *aux) +{ + struct agp_amd_softc *asc = (struct agp_amd_softc *)self; + struct agp_attach_args *aa = aux; + struct pci_attach_args *pa = aa->aa_pa; + struct agp_amd_gatt *gatt; + pcireg_t reg; + int error; + + asc->asc_pc = pa->pa_pc; + asc->asc_tag = pa->pa_tag; error = pci_mapreg_map(pa, AGP_AMD751_REGISTERS, PCI_MAPREG_TYPE_MEM, 0, &asc->iot, &asc->ioh, NULL, NULL, 0); if (error != 0) { printf("can't map AGP registers\n"); - agp_generic_detach(sc); - return (error); + return; } - if (agp_map_aperture(pa, sc, AGP_APBASE, PCI_MAPREG_TYPE_MEM) != 0) { - printf("can't map aperture\n"); - agp_generic_detach(sc); - free(asc, M_AGP); - return (ENXIO); - } - sc->sc_methods = &agp_amd_methods; - sc->sc_chipc = asc; - asc->initial_aperture = AGP_GET_APERTURE(sc); + asc->initial_aperture = agp_amd_get_aperture(asc); for (;;) { - gatt = agp_amd_alloc_gatt(sc); - if (gatt) + bus_size_t size = agp_amd_get_aperture(asc); + gatt = agp_amd_alloc_gatt(pa->pa_dmat, size); + if (gatt != NULL) break; /* - * Probably contigmalloc failure. Try reducing the - * aperture so that the gatt size reduces. + * almost certainly error allocating contigious dma memory + * so reduce aperture so that the gatt size reduces. */ - if (AGP_SET_APERTURE(sc, AGP_GET_APERTURE(sc) / 2)) { - printf(": can't set aperture\n"); - return (ENOMEM); + if (agp_amd_set_aperture(asc, size / 2)) { + printf(": failed to set aperture\n"); + return; } } asc->gatt = gatt; @@ -207,41 +216,43 @@ agp_amd_attach(struct agp_softc *sc, struct pci_attach_args *pa) WRITE4(AGP_AMD751_ATTBASE, gatt->ag_physical); /* Enable synchronisation between host and agp. */ - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_AMD751_MODECTRL); + reg = pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_AMD751_MODECTRL); reg &= ~0x00ff00ff; reg |= (AGP_AMD751_MODECTRL_SYNEN) | (AGP_AMD751_MODECTRL2_GPDCE << 16); - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_AMD751_MODECTRL, reg); + pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_AMD751_MODECTRL, reg); /* Enable the TLB and flush */ WRITE2(AGP_AMD751_STATUS, READ2(AGP_AMD751_STATUS) | AGP_AMD751_STATUS_GCE); - AGP_FLUSH_TLB(sc); + agp_amd_flush_tlb(asc); - return (0); + asc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_amd_methods, + AGP_APBASE, PCI_MAPREG_TYPE_MEM, &asc->dev); + return; } #if 0 int -agp_amd_detach(struct agp_softc *sc) +agp_amd_detach(void *sc) { - pcireg_t reg; - struct agp_amd_softc *asc = sc->sc_chipc; + struct agp_amd_softc *asc = sc; + pcireg_t reg; /* Disable the TLB.. */ WRITE2(AGP_AMD751_STATUS, READ2(AGP_AMD751_STATUS) & ~AGP_AMD751_STATUS_GCE); /* Disable host-agp sync */ - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_AMD751_MODECTRL); + reg = pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_AMD751_MODECTRL); reg &= 0xffffff00; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_AMD751_MODECTRL, reg); + pci_conf_write(asc->asc_pc, asc->asc_pcitag, AGP_AMD751_MODECTRL, reg); /* Clear the GATT base */ WRITE4(AGP_AMD751_ATTBASE, 0); /* Put the aperture back the way it started. */ - AGP_SET_APERTURE(sc, asc->initial_aperture); + agp_amd_set_aperture(asc, asc->initial_aperture); - agp_amd_free_gatt(sc, asc->gatt); + agp_amd_free_gatt(asc, asc->gatt); /* XXXfvdl no pci_mapreg_unmap */ @@ -249,12 +260,13 @@ agp_amd_detach(struct agp_softc *sc) } #endif -u_int32_t -agp_amd_get_aperture(struct agp_softc *sc) +bus_size_t +agp_amd_get_aperture(void *sc) { - int vas; + struct agp_amd_softc *asc = sc; + int vas; - vas = (pci_conf_read(sc->sc_pc, sc->sc_pcitag, + vas = (pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_AMD751_APCTRL) & 0x06); vas >>= 1; /* @@ -264,10 +276,11 @@ agp_amd_get_aperture(struct agp_softc *sc) } int -agp_amd_set_aperture(struct agp_softc *sc, u_int32_t aperture) +agp_amd_set_aperture(void *sc, bus_size_t aperture) { - int vas; - pcireg_t reg; + struct agp_amd_softc *asc = sc; + int vas; + pcireg_t reg; /* * Check for a power of two and make sure its within the @@ -280,17 +293,17 @@ agp_amd_set_aperture(struct agp_softc *sc, u_int32_t aperture) vas = ffs(aperture / 32*1024*1024) - 1; - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_AMD751_APCTRL); + reg = pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_AMD751_APCTRL); reg = (reg & ~0x06) | (vas << 1); - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_AMD751_APCTRL, reg); + pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_AMD751_APCTRL, reg); return (0); } int -agp_amd_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical) +agp_amd_bind_page(void *sc, off_t offset, bus_addr_t physical) { - struct agp_amd_softc *asc = sc->sc_chipc; + struct agp_amd_softc *asc = sc; if (offset < 0 || offset >= (asc->gatt->ag_entries << AGP_PAGE_SHIFT)) return (EINVAL); @@ -300,9 +313,9 @@ agp_amd_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical) } int -agp_amd_unbind_page(struct agp_softc *sc, off_t offset) +agp_amd_unbind_page(void *sc, off_t offset) { - struct agp_amd_softc *asc = sc->sc_chipc; + struct agp_amd_softc *asc = sc; if (offset < 0 || offset >= (asc->gatt->ag_entries << AGP_PAGE_SHIFT)) return (EINVAL); @@ -312,9 +325,9 @@ agp_amd_unbind_page(struct agp_softc *sc, off_t offset) } void -agp_amd_flush_tlb(struct agp_softc *sc) +agp_amd_flush_tlb(void *sc) { - struct agp_amd_softc *asc = sc->sc_chipc; + struct agp_amd_softc *asc = sc; /* Set the cache invalidate bit and wait for the chipset to clear */ WRITE4(AGP_AMD751_TLBCTRL, 1); diff --git a/sys/dev/pci/agp_i810.c b/sys/dev/pci/agp_i810.c index f6fc0e5861f..f4bcbab8747 100644 --- a/sys/dev/pci/agp_i810.c +++ b/sys/dev/pci/agp_i810.c @@ -1,5 +1,4 @@ -/* $OpenBSD: agp_i810.c,v 1.41 2008/09/26 21:15:53 mikeb Exp $ */ -/* $NetBSD: agp_i810.c,v 1.15 2003/01/31 00:07:39 thorpej Exp $ */ +/* $OpenBSD: agp_i810.c,v 1.42 2008/11/09 15:11:19 oga Exp $ */ /*- * Copyright (c) 2000 Doug Rabson @@ -27,10 +26,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/pci/agp_i810.c,v 1.4 2001/07/05 21:28:47 jhb Exp $ */ - #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> @@ -50,57 +47,60 @@ #include <machine/bus.h> -#include "agp_intel.h" - -#define READ1(off) bus_space_read_1(isc->bst, isc->bsh, off) -#define READ4(off) bus_space_read_4(isc->bst, isc->bsh, off) -#define WRITE4(off,v) bus_space_write_4(isc->bst, isc->bsh, off, v) +#define READ1(off) bus_space_read_1(isc->map->bst, isc->map->bsh, off) +#define READ4(off) bus_space_read_4(isc->map->bst, isc->map->bsh, off) +#define WRITE4(off,v) bus_space_write_4(isc->map->bst, isc->map->bsh, off, v) -#define WRITEGTT(off,v) bus_space_write_4(isc->gtt_bst, isc->gtt_bsh, off, v) +#define WRITEGTT(off,v) bus_space_write_4(isc->gtt_map->bst, isc->gtt_map->bsh, off, v) #define WRITE_GATT(off,v) agp_i810_write_gatt(isc, off, v) - enum { - CHIP_I810 = 0, /* i810/i815 */ - CHIP_I830 = 1, /* i830/i845 */ - CHIP_I855 = 2, /* i852GM/i855GM/i865G */ - CHIP_I915 = 3, /* i915G/i915GM */ - CHIP_I965 = 4, /* i965/i965GM */ - CHIP_G33 = 5 /* G33/Q33/Q35 */ + CHIP_NONE = 0, /* not integrated graphics */ + CHIP_I810 = 1, /* i810/i815 */ + CHIP_I830 = 2, /* i830/i845 */ + CHIP_I855 = 3, /* i852GM/i855GM/i865G */ + CHIP_I915 = 4, /* i915G/i915GM */ + CHIP_I965 = 5, /* i965/i965GM */ + CHIP_G33 = 6 /* G33/Q33/Q35 */ }; struct agp_i810_softc { - u_int32_t initial_aperture;/* aperture size at startup */ - struct agp_gatt - *gatt; - int chiptype; /* i810-like or i830 */ - u_int32_t dcache_size; /* i810 only */ - u_int32_t stolen; /* number of i830/845 gtt entries - for stolen memory */ - bus_space_tag_t bst; /* bus_space tag */ - bus_space_handle_t bsh; /* bus_space handle */ - bus_size_t bsz; /* bus_space size */ - bus_space_tag_t gtt_bst; /* GATT bus_space tag */ - bus_space_handle_t gtt_bsh; /* GATT bus_space handle */ - struct pci_attach_args vga_pa; + struct device dev; + struct agp_softc *agpdev; + struct agp_gatt *gatt; + struct vga_pci_bar *map; + struct vga_pci_bar *gtt_map; + int chiptype; /* i810-like or i830 */ + bus_size_t aperture; /* current aperture size */ + u_int32_t dcache_size; /* i810 only */ + u_int32_t stolen; /* number of i830/845 gtt + entries for stolen memory */ }; -int agp_i810_vgamatch(struct pci_attach_args *); -int agp_i810_set_aperture(struct agp_softc *, u_int32_t); -int agp_i810_bind_page(struct agp_softc *, off_t, bus_addr_t); -int agp_i810_unbind_page(struct agp_softc *, off_t); -void agp_i810_flush_tlb(struct agp_softc *); -int agp_i810_enable(struct agp_softc *, u_int32_t mode); -struct agp_memory * agp_i810_alloc_memory(struct agp_softc *, int, vsize_t); -int agp_i810_free_memory(struct agp_softc *, struct agp_memory *); -int agp_i810_bind_memory(struct agp_softc *, struct agp_memory *, - off_t); -int agp_i810_unbind_memory(struct agp_softc *, struct agp_memory *); +void agp_i810_attach(struct device *, struct device *, void *); +int agp_i810_probe(struct device *, void *, void *); +int agp_i810_get_chiptype(struct pci_attach_args *); +bus_size_t agp_i810_get_aperture(void *); +int agp_i810_bind_page(void *, off_t, bus_addr_t); +int agp_i810_unbind_page(void *, off_t); +void agp_i810_flush_tlb(void *); +int agp_i810_enable(void *, u_int32_t mode); +struct agp_memory * agp_i810_alloc_memory(void *, int, vsize_t); +int agp_i810_free_memory(void *, struct agp_memory *); +int agp_i810_bind_memory(void *, struct agp_memory *, off_t); +int agp_i810_unbind_memory(void *, struct agp_memory *); void agp_i810_write_gatt(struct agp_i810_softc *, bus_size_t, u_int32_t); +struct cfattach intagp_ca = { + sizeof(struct agp_i810_softc), agp_i810_probe, agp_i810_attach +}; + +struct cfdriver intagp_cd = { + NULL, "intagp", DV_DULL +}; + struct agp_methods agp_i810_methods = { - agp_generic_get_aperture, - agp_i810_set_aperture, + agp_i810_get_aperture, agp_i810_bind_page, agp_i810_unbind_page, agp_i810_flush_tlb, @@ -111,104 +111,23 @@ struct agp_methods agp_i810_methods = { agp_i810_unbind_memory, }; -/* XXXthorpej -- duplicated code (see arch/i386/pci/pchb.c) */ int -agp_i810_vgamatch(struct pci_attach_args *pa) +agp_i810_get_chiptype(struct pci_attach_args *pa) { - - if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY || - PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA) - return (0); - switch (PCI_PRODUCT(pa->pa_id)) { case PCI_PRODUCT_INTEL_82810_IGD: case PCI_PRODUCT_INTEL_82810_DC100_IGD: case PCI_PRODUCT_INTEL_82810E_IGD: case PCI_PRODUCT_INTEL_82815_IGD: - case PCI_PRODUCT_INTEL_82830M_IGD: - case PCI_PRODUCT_INTEL_82845G_IGD: - case PCI_PRODUCT_INTEL_82855GM_IGD: - case PCI_PRODUCT_INTEL_82865G_IGD: - case PCI_PRODUCT_INTEL_82915G_IGD_1: - case PCI_PRODUCT_INTEL_82915G_IGD_2: - case PCI_PRODUCT_INTEL_82915GM_IGD_1: - case PCI_PRODUCT_INTEL_82915GM_IGD_2: - case PCI_PRODUCT_INTEL_82945G_IGD_1: - case PCI_PRODUCT_INTEL_82945G_IGD_2: - case PCI_PRODUCT_INTEL_82945GM_IGD_1: - case PCI_PRODUCT_INTEL_82945GM_IGD_2: - case PCI_PRODUCT_INTEL_82945GME_IGD_1: - case PCI_PRODUCT_INTEL_82G965_IGD_1: - case PCI_PRODUCT_INTEL_82G965_IGD_2: - case PCI_PRODUCT_INTEL_82Q965_IGD_1: - case PCI_PRODUCT_INTEL_82Q965_IGD_2: - case PCI_PRODUCT_INTEL_82GM965_IGD_1: - case PCI_PRODUCT_INTEL_82GM965_IGD_2: - case PCI_PRODUCT_INTEL_82GME965_IGD_1: - case PCI_PRODUCT_INTEL_82GME965_IGD_2: - case PCI_PRODUCT_INTEL_82G33_IGD_1: - case PCI_PRODUCT_INTEL_82G33_IGD_2: - case PCI_PRODUCT_INTEL_82G35_IGD_1: - case PCI_PRODUCT_INTEL_82G35_IGD_2: - case PCI_PRODUCT_INTEL_82Q35_IGD_1: - case PCI_PRODUCT_INTEL_82Q35_IGD_2: - return (1); - } - - return (0); -} - -int -agp_i810_attach(struct agp_softc *sc, struct pci_attach_args *pa) -{ - struct agp_i810_softc *isc; - struct agp_gatt *gatt; - bus_addr_t mmaddr, gmaddr; - struct vga_pci_bar *map; - int error; - u_int memtype = 0; - - isc = malloc(sizeof *isc, M_AGP, M_NOWAIT | M_ZERO); - if (isc == NULL) { - printf("can't allocate chipset-specific softc\n"); - return (ENOMEM); - } - sc->sc_chipc = isc; - sc->sc_methods = &agp_i810_methods; - - if (pci_find_device(&isc->vga_pa, agp_i810_vgamatch) == 0) { -#if NAGP_INTEL > 0 - - switch (PCI_PRODUCT(pa->pa_id)) { - case PCI_PRODUCT_INTEL_82815_HB: - case PCI_PRODUCT_INTEL_82845G_HB: - case PCI_PRODUCT_INTEL_82865G_HB: - return (agp_intel_attach(sc, pa)); - } -#endif - printf("no integrated graphics\n"); - free(isc, M_AGP); - return (ENOENT); - } - - /* XXXfvdl */ - sc->sc_dmat = isc->vga_pa.pa_dmat; - sc->sc_memt = isc->vga_pa.pa_memt; - - switch (PCI_PRODUCT(isc->vga_pa.pa_id)) { - case PCI_PRODUCT_INTEL_82810_IGD: - case PCI_PRODUCT_INTEL_82810_DC100_IGD: - case PCI_PRODUCT_INTEL_82810E_IGD: - case PCI_PRODUCT_INTEL_82815_IGD: - isc->chiptype = CHIP_I810; + return (CHIP_I810); break; case PCI_PRODUCT_INTEL_82830M_IGD: case PCI_PRODUCT_INTEL_82845G_IGD: - isc->chiptype = CHIP_I830; + return (CHIP_I830); break; case PCI_PRODUCT_INTEL_82855GM_IGD: case PCI_PRODUCT_INTEL_82865G_IGD: - isc->chiptype = CHIP_I855; + return (CHIP_I855); break; case PCI_PRODUCT_INTEL_82915G_IGD_1: case PCI_PRODUCT_INTEL_82915G_IGD_2: @@ -219,7 +138,7 @@ agp_i810_attach(struct agp_softc *sc, struct pci_attach_args *pa) case PCI_PRODUCT_INTEL_82945GM_IGD_1: case PCI_PRODUCT_INTEL_82945GM_IGD_2: case PCI_PRODUCT_INTEL_82945GME_IGD_1: - isc->chiptype = CHIP_I915; + return (CHIP_I915); break; case PCI_PRODUCT_INTEL_82Q965_IGD_1: case PCI_PRODUCT_INTEL_82Q965_IGD_2: @@ -231,15 +150,41 @@ agp_i810_attach(struct agp_softc *sc, struct pci_attach_args *pa) case PCI_PRODUCT_INTEL_82GME965_IGD_2: case PCI_PRODUCT_INTEL_82G35_IGD_1: case PCI_PRODUCT_INTEL_82G35_IGD_2: - isc->chiptype = CHIP_I965; + return (CHIP_I965); break; case PCI_PRODUCT_INTEL_82G33_IGD_1: case PCI_PRODUCT_INTEL_82G33_IGD_2: case PCI_PRODUCT_INTEL_82Q35_IGD_1: case PCI_PRODUCT_INTEL_82Q35_IGD_2: - isc->chiptype = CHIP_G33; + return (CHIP_G33); break; } + return (CHIP_NONE); +} + +int +agp_i810_probe(struct device *parent, void *match, void *aux) +{ + struct pci_attach_args *pa = aux; + + if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY || + PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA) + return (0); + + return (agp_i810_get_chiptype(pa) != CHIP_NONE); +} + +void +agp_i810_attach(struct device *parent, struct device *self, void *aux) +{ + struct agp_i810_softc *isc = (struct agp_i810_softc *)self; + struct agp_gatt *gatt; + struct pci_attach_args *pa = aux; + struct vga_pci_softc *vga = (struct vga_pci_softc *)parent; + bus_addr_t mmaddr, gmaddr; + pcireg_t memtype; + + isc->chiptype = agp_i810_get_chiptype(pa); switch (isc->chiptype) { case CHIP_I915: @@ -260,46 +205,35 @@ agp_i810_attach(struct agp_softc *sc, struct pci_attach_args *pa) break; } - error = agp_map_aperture(&isc->vga_pa, sc, gmaddr, memtype); - if (error != 0) { - printf("can't map aperture\n"); - free(isc, M_AGP); - return (error); + if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, gmaddr, memtype, + NULL, &isc->aperture, NULL) != 0) { + printf("can't get aperture size\n"); + return; } - map = vga_pci_bar_map(sc->vga_softc, mmaddr, 0, - BUS_SPACE_MAP_LINEAR); - if (map == NULL) { + isc->map = vga_pci_bar_map(vga, mmaddr, 0, BUS_SPACE_MAP_LINEAR); + if (isc->map == NULL) { printf("can't map mmadr registers\n"); - agp_generic_detach(sc); - return (error); + return; } - isc->bst = map->bst; - isc->bsh = map->bsh; - isc->bsz = map->size; if (isc->chiptype == CHIP_I915 || isc->chiptype == CHIP_G33) { - map = vga_pci_bar_map(sc->vga_softc, AGP_I915_GTTADR, - 0, BUS_SPACE_MAP_LINEAR); - if (map == NULL) { + isc->gtt_map = vga_pci_bar_map(vga, AGP_I915_GTTADR, 0, + BUS_SPACE_MAP_LINEAR); + if (isc->gtt_map == NULL) { printf("can't map gatt registers\n"); - agp_generic_detach(sc); - return (error); + goto out; } - isc->gtt_bst = map->bst; - isc->gtt_bsh = map->bsh; } - isc->initial_aperture = AGP_GET_APERTURE(sc); - - gatt = malloc(sizeof(struct agp_gatt), M_AGP, M_NOWAIT); - if (!gatt) { - agp_generic_detach(sc); - return (ENOMEM); + gatt = malloc(sizeof(*gatt), M_AGP, M_NOWAIT); + if (gatt == NULL) { + printf("can't alloc gatt\n"); + goto out; } isc->gatt = gatt; - gatt->ag_entries = AGP_GET_APERTURE(sc) >> AGP_PAGE_SHIFT; + gatt->ag_entries = isc->aperture >> AGP_PAGE_SHIFT; if (isc->chiptype == CHIP_I810) { int dummyseg; @@ -310,12 +244,10 @@ agp_i810_attach(struct agp_softc *sc, struct pci_attach_args *pa) isc->dcache_size = 0; /* According to the specs the gatt on the i810 must be 64k */ - if (agp_alloc_dmamem(sc->sc_dmat, 64 * 1024, + if (agp_alloc_dmamem(pa->pa_dmat, 64 * 1024, 0, &gatt->ag_dmamap, (caddr_t *)&gatt->ag_virtual, &gatt->ag_physical, &gatt->ag_dmaseg, 1, &dummyseg) != 0) { - free(gatt, M_AGP); - agp_generic_detach(sc); - return (ENOMEM); + goto out; } gatt->ag_size = gatt->ag_entries * sizeof(u_int32_t); @@ -330,7 +262,7 @@ agp_i810_attach(struct agp_softc *sc, struct pci_attach_args *pa) u_int32_t pgtblctl; u_int16_t gcc1; - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_I830_GCC1); + reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_I830_GCC1); gcc1 = (u_int16_t)(reg >> 16); switch (gcc1 & AGP_I830_GCC1_GMS) { case AGP_I830_GCC1_GMS_STOLEN_512: @@ -345,8 +277,7 @@ agp_i810_attach(struct agp_softc *sc, struct pci_attach_args *pa) default: isc->stolen = 0; printf("unknown memory configuration, disabling\n"); - agp_generic_detach(sc); - return (EINVAL); + goto out; } #ifdef DEBUG if (isc->stolen > 0) { @@ -372,7 +303,7 @@ agp_i810_attach(struct agp_softc *sc, struct pci_attach_args *pa) * BIOS display. */ - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_I855_GCC1); + reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_I855_GCC1); gcc1 = (u_int16_t)(reg >> 16); switch (isc->chiptype) { case CHIP_I855: @@ -411,8 +342,7 @@ agp_i810_attach(struct agp_softc *sc, struct pci_attach_args *pa) break; default: printf("bad chiptype\n"); - agp_generic_detach(sc); - return (EINVAL); + goto out; } switch (gcc1 & AGP_I855_GCC1_GMS) { @@ -446,8 +376,7 @@ agp_i810_attach(struct agp_softc *sc, struct pci_attach_args *pa) default: isc->stolen = 0; printf("unknown memory configuration, disabling\n"); - agp_generic_detach(sc); - return (EINVAL); + goto out; } #ifdef DEBUG if (isc->stolen > 0) { @@ -469,7 +398,16 @@ agp_i810_attach(struct agp_softc *sc, struct pci_attach_args *pa) */ agp_flush_cache(); - return (0); + isc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_i810_methods, + gmaddr, memtype, &isc->dev); + return; +out: + if (isc->gatt) + free(isc->gatt, M_AGP); + if (isc->gtt_map != NULL) + vga_pci_bar_unmap(isc->gtt_map); + if (isc->map != NULL) + vga_pci_bar_unmap(isc->map); } #if 0 @@ -493,9 +431,6 @@ agp_i810_detach(struct agp_softc *sc) WRITE4(AGP_I810_PGTBL_CTL, pgtblctl); } - /* Put the aperture back the way it started. */ - AGP_SET_APERTURE(sc, isc->initial_aperture); - if (sc->chiptype == CHIP_I810) { agp_free_dmamem(sc->sc_dmat, gatt->ag_size, gatt->ag_dmamap, (void *)gatt->ag_virtual, &gatt->ag_dmaseg, 1); @@ -506,74 +441,23 @@ agp_i810_detach(struct agp_softc *sc) } #endif -int -agp_i810_set_aperture(struct agp_softc *sc, u_int32_t aperture) +bus_size_t +agp_i810_get_aperture(void *sc) { - struct agp_i810_softc *isc = sc->sc_chipc; - pcireg_t reg; - u_int16_t gcc1, miscc; - - switch (isc->chiptype) { - case CHIP_I810: - /* - * Double check for sanity. - */ - if (aperture != (32 * 1024 * 1024) && - aperture != (64 * 1024 * 1024)) { - printf("agp: bad aperture size %d\n", aperture); - return (EINVAL); - } - - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_I810_SMRAM); - miscc = (u_int16_t)(reg >> 16); - miscc &= ~AGP_I810_MISCC_WINSIZE; - if (aperture == 32 * 1024 * 1024) - miscc |= AGP_I810_MISCC_WINSIZE_32; - else - miscc |= AGP_I810_MISCC_WINSIZE_64; + struct agp_i810_softc *isc = sc; - reg &= 0x0000ffff; - reg |= ((pcireg_t)miscc) << 16; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_I810_SMRAM, reg); - break; - case CHIP_I830: - if (aperture != (64 * 1024 * 1024) && - aperture != (128 * 1024 * 1024)) { - printf("agp: bad aperture size %d\n", aperture); - return (EINVAL); - } - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_I830_GCC0); - gcc1 = (u_int16_t)(reg >> 16); - gcc1 &= ~AGP_I830_GCC1_GMASIZE; - if (aperture == 64 * 1024 * 1024) - gcc1 |= AGP_I830_GCC1_GMASIZE_64; - else - gcc1 |= AGP_I830_GCC1_GMASIZE_128; - - reg &= 0x0000ffff; - reg |= ((pcireg_t)gcc1) << 16; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_I830_GCC0, reg); - break; - case CHIP_I855: - case CHIP_I915: - case CHIP_I965: - case CHIP_G33: - return agp_generic_set_aperture(sc, aperture); - } - - return (0); + return (isc->aperture); } int -agp_i810_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical) +agp_i810_bind_page(void *sc, off_t offset, bus_addr_t physical) { - struct agp_i810_softc *isc = sc->sc_chipc; + struct agp_i810_softc *isc = sc; if (offset < 0 || offset >= (isc->gatt->ag_entries << AGP_PAGE_SHIFT)) { #ifdef DEBUG printf("agp: failed: offset 0x%08x, shift %d, entries %d\n", - (int)offset, AGP_PAGE_SHIFT, - isc->gatt->ag_entries); + (int)offset, AGP_PAGE_SHIFT, isc->gatt->ag_entries); #endif return (EINVAL); } @@ -592,9 +476,9 @@ agp_i810_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical) } int -agp_i810_unbind_page(struct agp_softc *sc, off_t offset) +agp_i810_unbind_page(void *sc, off_t offset) { - struct agp_i810_softc *isc = sc->sc_chipc; + struct agp_i810_softc *isc = sc; if (offset < 0 || offset >= (isc->gatt->ag_entries << AGP_PAGE_SHIFT)) return (EINVAL); @@ -616,25 +500,26 @@ agp_i810_unbind_page(struct agp_softc *sc, off_t offset) * Writing via memory mapped registers already flushes all TLBs. */ void -agp_i810_flush_tlb(struct agp_softc *sc) +agp_i810_flush_tlb(void *sc) { } int -agp_i810_enable(struct agp_softc *sc, u_int32_t mode) +agp_i810_enable(void *sc, u_int32_t mode) { return (0); } struct agp_memory * -agp_i810_alloc_memory(struct agp_softc *sc, int type, vsize_t size) +agp_i810_alloc_memory(void *softc, int type, vsize_t size) { - struct agp_i810_softc *isc = sc->sc_chipc; - struct agp_memory *mem; - int error; + struct agp_i810_softc *isc = softc; + struct agp_softc *sc = isc->agpdev; + struct agp_memory *mem; + int error; if ((size & (AGP_PAGE_SIZE - 1)) != 0) - return (0); + return (NULL); if (sc->sc_allocated + size > sc->sc_maxmem) return (NULL); @@ -697,8 +582,11 @@ agp_i810_alloc_memory(struct agp_softc *sc, int type, vsize_t size) } int -agp_i810_free_memory(struct agp_softc *sc, struct agp_memory *mem) +agp_i810_free_memory(void *softc, struct agp_memory *mem) { + struct agp_i810_softc *isc = softc; + struct agp_softc *sc = isc->agpdev; + if (mem->am_is_bound) return (EBUSY); @@ -715,11 +603,10 @@ agp_i810_free_memory(struct agp_softc *sc, struct agp_memory *mem) } int -agp_i810_bind_memory(struct agp_softc *sc, struct agp_memory *mem, - off_t offset) +agp_i810_bind_memory(void *sc, struct agp_memory *mem, off_t offset) { - struct agp_i810_softc *isc = sc->sc_chipc; - u_int32_t regval, i; + struct agp_i810_softc *isc = sc; + u_int32_t regval, i; /* * XXX evil hack: the PGTBL_CTL appearently gets overwritten by the @@ -727,15 +614,11 @@ agp_i810_bind_memory(struct agp_softc *sc, struct agp_memory *mem, * to the GTT through the MMIO window. * Until the issue is solved, simply restore it. */ - - regval = bus_space_read_4(isc->bst, isc->bsh, AGP_I810_PGTBL_CTL); + regval = READ4(AGP_I810_PGTBL_CTL); if (regval != (isc->gatt->ag_physical | 1)) { -#if DEBUG printf("agp_i810_bind_memory: PGTBL_CTL is 0x%x - fixing\n", regval); -#endif - bus_space_write_4(isc->bst, isc->bsh, AGP_I810_PGTBL_CTL, - isc->gatt->ag_physical | 1); + WRITE4(AGP_I810_PGTBL_CTL, isc->gatt->ag_physical | 1); } if (mem->am_type == 2) { @@ -748,7 +631,7 @@ agp_i810_bind_memory(struct agp_softc *sc, struct agp_memory *mem, } if (mem->am_type != 1) - return (agp_generic_bind_memory(sc, mem, offset)); + return (agp_generic_bind_memory(isc->agpdev, mem, offset)); if (isc->chiptype != CHIP_I810) return (EINVAL); @@ -761,10 +644,10 @@ agp_i810_bind_memory(struct agp_softc *sc, struct agp_memory *mem, } int -agp_i810_unbind_memory(struct agp_softc *sc, struct agp_memory *mem) +agp_i810_unbind_memory(void *sc, struct agp_memory *mem) { - struct agp_i810_softc *isc = sc->sc_chipc; - u_int32_t i; + struct agp_i810_softc *isc = sc; + u_int32_t i; if (mem->am_type == 2) { for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) { @@ -776,7 +659,7 @@ agp_i810_unbind_memory(struct agp_softc *sc, struct agp_memory *mem) } if (mem->am_type != 1) - return (agp_generic_unbind_memory(sc, mem)); + return (agp_generic_unbind_memory(isc->agpdev, mem)); if (isc->chiptype != CHIP_I810) return (EINVAL); @@ -798,9 +681,9 @@ agp_i810_write_gatt(struct agp_i810_softc *isc, bus_size_t off, u_int32_t v) WRITEGTT((u_int32_t)((off) >> AGP_PAGE_SHIFT) * 4, v ? d : 0); else if (isc->chiptype == CHIP_I965) { d |= (v & 0x0000000f00000000ULL) >> 28; - WRITE4(AGP_I965_GTT + - (u_int32_t)((off) >> AGP_PAGE_SHIFT) * 4, v ? d : 0); + WRITE4(AGP_I965_GTT + (u_int32_t)((off) >> AGP_PAGE_SHIFT) * 4, + v ? d : 0); } else - WRITE4(AGP_I810_GTT + - (u_int32_t)((off) >> AGP_PAGE_SHIFT) * 4, v ? d : 0); + WRITE4(AGP_I810_GTT + (u_int32_t)((off) >> AGP_PAGE_SHIFT) * 4, + v ? d : 0); } diff --git a/sys/dev/pci/agp_intel.c b/sys/dev/pci/agp_intel.c index b2d6aeeb458..d6e99b19b1d 100644 --- a/sys/dev/pci/agp_intel.c +++ b/sys/dev/pci/agp_intel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agp_intel.c,v 1.11 2008/09/02 10:29:34 jsg Exp $ */ +/* $OpenBSD: agp_intel.c,v 1.12 2008/11/09 15:11:19 oga Exp $ */ /* $NetBSD: agp_intel.c,v 1.3 2001/09/15 00:25:00 thorpej Exp $ */ /*- @@ -29,7 +29,6 @@ * $FreeBSD: src/sys/pci/agp_intel.c,v 1.4 2001/07/05 21:28:47 jhb Exp $ */ - #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> @@ -40,7 +39,6 @@ #include <sys/device.h> #include <sys/agpio.h> - #include <dev/pci/pcivar.h> #include <dev/pci/pcireg.h> #include <dev/pci/pcidevs.h> @@ -50,200 +48,208 @@ #include <machine/bus.h> struct agp_intel_softc { - u_int32_t initial_aperture; /* aperture size at startup */ + struct device dev; + struct agp_softc *agpdev; struct agp_gatt *gatt; - struct pci_attach_args vga_pa; /* vga card */ - u_int aperture_mask; - int chiptype; -#define CHIP_INTEL 0x0 -#define CHIP_I443 0x1 -#define CHIP_I840 0x2 -#define CHIP_I845 0x3 -#define CHIP_I850 0x4 -#define CHIP_I865 0x5 + pci_chipset_tag_t isc_pc; + pcitag_t isc_tag; + u_int aperture_mask; + enum { + CHIP_INTEL, + CHIP_I443, + CHIP_I840, + CHIP_I845, + CHIP_I850, + CHIP_I865 + } chiptype; + bus_size_t initial_aperture; /* startup aperture size */ }; -int agp_intel_vgamatch(struct pci_attach_args *); -u_int32_t agp_intel_get_aperture(struct agp_softc *); -int agp_intel_set_aperture(struct agp_softc *, u_int32_t); -int agp_intel_bind_page(struct agp_softc *, off_t, bus_addr_t); -int agp_intel_unbind_page(struct agp_softc *, off_t); -void agp_intel_flush_tlb(struct agp_softc *); +void agp_intel_attach(struct device *, struct device *, void *); +int agp_intel_probe(struct device *, void *, void *); +bus_size_t agp_intel_get_aperture(void *); +int agp_intel_set_aperture(void *, bus_size_t); +int agp_intel_bind_page(void *, off_t, bus_addr_t); +int agp_intel_unbind_page(void *, off_t); +void agp_intel_flush_tlb(void *); + +struct cfattach intelagp_ca = { + sizeof(struct agp_intel_softc), agp_intel_probe, agp_intel_attach +}; + +struct cfdriver intelagp_cd = { + NULL, "intelagp", DV_DULL +}; -struct agp_methods agp_intel_methods = { +const struct agp_methods agp_intel_methods = { agp_intel_get_aperture, - agp_intel_set_aperture, agp_intel_bind_page, agp_intel_unbind_page, agp_intel_flush_tlb, - agp_generic_enable, - agp_generic_alloc_memory, - agp_generic_free_memory, - agp_generic_bind_memory, - agp_generic_unbind_memory, + /* default enable and memory routines */ }; int -agp_intel_vgamatch(struct pci_attach_args *pa) +agp_intel_probe(struct device *parent, void *match, void *aux) { + struct agp_attach_args *aa = aux; + struct pci_attach_args *pa = aa->aa_pa; + + /* Must be a pchb */ + if (agpbus_probe(aa) == 0) + return (0); + switch (PCI_PRODUCT(pa->pa_id)) { - case PCI_PRODUCT_INTEL_82443LX_AGP: - case PCI_PRODUCT_INTEL_82443BX_AGP: + case PCI_PRODUCT_INTEL_82443LX: + case PCI_PRODUCT_INTEL_82443BX: + case PCI_PRODUCT_INTEL_82440BX: case PCI_PRODUCT_INTEL_82440BX_AGP: - case PCI_PRODUCT_INTEL_82840_AGP: - case PCI_PRODUCT_INTEL_82845_AGP: - case PCI_PRODUCT_INTEL_82845G_AGP: - case PCI_PRODUCT_INTEL_82850_AGP: /* i850/i860 */ - case PCI_PRODUCT_INTEL_82855PM_AGP: - case PCI_PRODUCT_INTEL_82865G_AGP: - case PCI_PRODUCT_INTEL_82875P_AGP: + case PCI_PRODUCT_INTEL_82815_HB: + case PCI_PRODUCT_INTEL_82820_HB: + case PCI_PRODUCT_INTEL_82830M_HB: + case PCI_PRODUCT_INTEL_82840_HB: + case PCI_PRODUCT_INTEL_82845_HB: + case PCI_PRODUCT_INTEL_82845G_HB: + case PCI_PRODUCT_INTEL_82850_HB: + case PCI_PRODUCT_INTEL_82855PM_HB: + case PCI_PRODUCT_INTEL_82855GM_HB: + case PCI_PRODUCT_INTEL_82860_HB: + case PCI_PRODUCT_INTEL_82865G_HB: + case PCI_PRODUCT_INTEL_82875P_HB: return (1); } return (0); } -int -agp_intel_attach(struct agp_softc *sc, struct pci_attach_args *pa) +void +agp_intel_attach(struct device *parent, struct device *self, void *aux) { - struct agp_intel_softc *isc; - struct agp_gatt *gatt; - pcireg_t reg; - u_int32_t value; - - isc = malloc(sizeof *isc, M_AGP, M_NOWAIT | M_ZERO); - if (isc == NULL) { - printf("can't allocate chipset-specific softc\n"); - return (ENOMEM); - } - - sc->sc_methods = &agp_intel_methods; - sc->sc_chipc = isc; - - if (pci_find_device(&isc->vga_pa, agp_intel_vgamatch) == 0) - isc->chiptype = CHIP_INTEL; - - pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_AGP, &sc->sc_capoff, - NULL); + struct agp_intel_softc *isc = (struct agp_intel_softc *)self; + struct agp_attach_args *aa = aux; + struct pci_attach_args *pa = aa->aa_pa; + struct agp_gatt *gatt; + pcireg_t reg; + u_int32_t value; - if (agp_map_aperture(pa, sc, AGP_APBASE, PCI_MAPREG_TYPE_MEM) != 0) { - printf("can't map aperture\n"); - free(isc, M_AGP); - sc->sc_chipc = NULL; - return (ENXIO); - } + isc->isc_pc = pa->pa_pc; + isc->isc_tag = pa->pa_tag; - switch (PCI_PRODUCT(isc->vga_pa.pa_id)) { - case PCI_PRODUCT_INTEL_82443LX_AGP: - case PCI_PRODUCT_INTEL_82443BX_AGP: + switch (PCI_PRODUCT(pa->pa_id)) { + case PCI_PRODUCT_INTEL_82443LX: + case PCI_PRODUCT_INTEL_82443BX: + case PCI_PRODUCT_INTEL_82440BX: case PCI_PRODUCT_INTEL_82440BX_AGP: isc->chiptype = CHIP_I443; break; - case PCI_PRODUCT_INTEL_82840_AGP: + case PCI_PRODUCT_INTEL_82830M_HB: + case PCI_PRODUCT_INTEL_82840_HB: isc->chiptype = CHIP_I840; break; - case PCI_PRODUCT_INTEL_82845_AGP: - case PCI_PRODUCT_INTEL_82845G_AGP: - case PCI_PRODUCT_INTEL_82855PM_AGP: + case PCI_PRODUCT_INTEL_82845_HB: + case PCI_PRODUCT_INTEL_82845G_HB: + case PCI_PRODUCT_INTEL_82855PM_HB: isc->chiptype = CHIP_I845; break; - case PCI_PRODUCT_INTEL_82850_AGP: + case PCI_PRODUCT_INTEL_82850_HB: isc->chiptype = CHIP_I850; break; - case PCI_PRODUCT_INTEL_82865G_AGP: - case PCI_PRODUCT_INTEL_82875P_AGP: + case PCI_PRODUCT_INTEL_82865G_HB: + case PCI_PRODUCT_INTEL_82875P_HB: isc->chiptype = CHIP_I865; break; + default: + isc->chiptype = CHIP_INTEL; } /* Determine maximum supported aperture size. */ - value = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_APSIZE); - pci_conf_write(sc->sc_pc, sc->sc_pcitag, - AGP_INTEL_APSIZE, APSIZE_MASK); - isc->aperture_mask = pci_conf_read(sc->sc_pc, sc->sc_pcitag, + value = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_INTEL_APSIZE); + pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_INTEL_APSIZE, APSIZE_MASK); + isc->aperture_mask = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_INTEL_APSIZE) & APSIZE_MASK; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_APSIZE, value); - isc->initial_aperture = AGP_GET_APERTURE(sc); + pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_INTEL_APSIZE, value); + isc->initial_aperture = agp_intel_get_aperture(isc); for (;;) { - gatt = agp_alloc_gatt(sc); - if (gatt) + bus_size_t size = agp_intel_get_aperture(isc); + gatt = agp_alloc_gatt(pa->pa_dmat, size); + if (gatt != NULL) break; /* - * Probably contigmalloc failure. Try reducing the - * aperture so that the gatt size reduces. + * almost certainly error allocating contigious dma memory + * so reduce aperture so that the gatt size reduces. */ - if (AGP_SET_APERTURE(sc, AGP_GET_APERTURE(sc) / 2)) { - agp_generic_detach(sc); - printf("failed to set aperture\n"); - return (ENOMEM); + if (agp_intel_set_aperture(isc, size / 2)) { + printf(": failed to set aperture\n"); + return; } } isc->gatt = gatt; /* Install the gatt. */ - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_ATTBASE, + pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_INTEL_ATTBASE, gatt->ag_physical); /* Enable the GLTB and setup the control register. */ switch (isc->chiptype) { case CHIP_I443: - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_AGPCTRL, + pci_conf_write(isc->isc_pc, isc->isc_tag, AGP_INTEL_AGPCTRL, AGPCTRL_AGPRSE | AGPCTRL_GTLB); break; default: - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_AGPCTRL, - pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_AGPCTRL) - | AGPCTRL_GTLB); + pci_conf_write(isc->isc_pc, isc->isc_tag, AGP_INTEL_AGPCTRL, + pci_conf_read(isc->isc_pc, isc->isc_tag, + AGP_INTEL_AGPCTRL) | AGPCTRL_GTLB); } /* Enable things, clear errors etc. */ switch (isc->chiptype) { case CHIP_I845: case CHIP_I865: - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_I840_MCHCFG); + reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_I840_MCHCFG); reg |= MCHCFG_AAGN; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_I840_MCHCFG, reg); + pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_I840_MCHCFG, reg); break; case CHIP_I840: case CHIP_I850: - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_AGPCMD); + reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_INTEL_AGPCMD); reg |= AGPCMD_AGPEN; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_AGPCMD, + pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_INTEL_AGPCMD, reg); - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_I840_MCHCFG); + reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_I840_MCHCFG); reg |= MCHCFG_AAGN; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_I840_MCHCFG, + pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_I840_MCHCFG, reg); break; default: - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_NBXCFG); + reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_INTEL_NBXCFG); reg &= ~NBXCFG_APAE; reg |= NBXCFG_AAGN; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_NBXCFG, reg); + pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_INTEL_NBXCFG, reg); } /* Clear Error status */ switch (isc->chiptype) { case CHIP_I840: - pci_conf_write(sc->sc_pc, sc->sc_pcitag, + pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_INTEL_I8XX_ERRSTS, 0xc000); break; case CHIP_I845: case CHIP_I850: case CHIP_I865: - pci_conf_write(sc->sc_pc, sc->sc_pcitag, + pci_conf_write(isc->isc_pc, isc->isc_tag, AGP_INTEL_I8XX_ERRSTS, 0x00ff); break; default: - pci_conf_write(sc->sc_pc, sc->sc_pcitag, - AGP_INTEL_ERRSTS, 0x70); + pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_INTEL_ERRSTS, 0x70); } - - return (0); + + isc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_intel_methods, + AGP_APBASE, PCI_MAPREG_TYPE_MEM, &isc->dev); + return; } #if 0 @@ -259,11 +265,11 @@ agp_intel_detach(struct agp_softc *sc) return (error); /* XXX i845/i855PM/i840/i850E */ - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_NBXCFG); + reg = pci_conf_read(sc->sc_pc, sc->sc_tag, AGP_INTEL_NBXCFG); reg &= ~(1 << 9); printf("%s: set NBXCFG to %x\n", __FUNCTION__, reg); - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_NBXCFG, reg); - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_ATTBASE, 0); + pci_conf_write(sc->sc_pc, sc->sc_tag, AGP_INTEL_NBXCFG, reg); + pci_conf_write(sc->sc_pc, sc->sc_tag, AGP_INTEL_ATTBASE, 0); AGP_SET_APERTURE(sc, isc->initial_aperture); agp_free_gatt(sc, isc->gatt); @@ -271,13 +277,13 @@ agp_intel_detach(struct agp_softc *sc) } #endif -u_int32_t -agp_intel_get_aperture(struct agp_softc *sc) +bus_size_t +agp_intel_get_aperture(void *sc) { - struct agp_intel_softc *isc = sc->sc_chipc; - u_int32_t apsize; + struct agp_intel_softc *isc = sc; + bus_size_t apsize; - apsize = pci_conf_read(sc->sc_pc, sc->sc_pcitag, + apsize = pci_conf_read(isc->isc_pc, isc->isc_tag, AGP_INTEL_APSIZE) & isc->aperture_mask; /* @@ -291,10 +297,10 @@ agp_intel_get_aperture(struct agp_softc *sc) } int -agp_intel_set_aperture(struct agp_softc *sc, u_int32_t aperture) +agp_intel_set_aperture(void *sc, bus_size_t aperture) { - struct agp_intel_softc *isc = sc->sc_chipc; - u_int32_t apsize; + struct agp_intel_softc *isc = sc; + bus_size_t apsize; /* * Reverse the magic from get_aperture. @@ -308,15 +314,15 @@ agp_intel_set_aperture(struct agp_softc *sc, u_int32_t aperture) ((1 << 22) - 1)) + 1 != aperture) return (EINVAL); - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_APSIZE, apsize); + pci_conf_write(isc->isc_pc, isc->isc_tag, AGP_INTEL_APSIZE, apsize); return (0); } int -agp_intel_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical) +agp_intel_bind_page(void *sc, off_t offset, bus_addr_t physical) { - struct agp_intel_softc *isc = sc->sc_chipc; + struct agp_intel_softc *isc = sc; if (offset < 0 || offset >= (isc->gatt->ag_entries << AGP_PAGE_SHIFT)) return (EINVAL); @@ -326,9 +332,9 @@ agp_intel_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical) } int -agp_intel_unbind_page(struct agp_softc *sc, off_t offset) +agp_intel_unbind_page(void *sc, off_t offset) { - struct agp_intel_softc *isc = sc->sc_chipc; + struct agp_intel_softc *isc = sc; if (offset < 0 || offset >= (isc->gatt->ag_entries << AGP_PAGE_SHIFT)) return (EINVAL); @@ -338,9 +344,9 @@ agp_intel_unbind_page(struct agp_softc *sc, off_t offset) } void -agp_intel_flush_tlb(struct agp_softc *sc) +agp_intel_flush_tlb(void *sc) { - struct agp_intel_softc *isc = sc->sc_chipc; + struct agp_intel_softc *isc = sc; pcireg_t reg; switch (isc->chiptype) { @@ -349,17 +355,18 @@ agp_intel_flush_tlb(struct agp_softc *sc) case CHIP_I845: case CHIP_I840: case CHIP_I443: - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_AGPCTRL); + reg = pci_conf_read(isc->isc_pc, isc->isc_tag, + AGP_INTEL_AGPCTRL); reg &= ~AGPCTRL_GTLB; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_AGPCTRL, - reg); - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_AGPCTRL, + pci_conf_write(isc->isc_pc, isc->isc_tag, + AGP_INTEL_AGPCTRL, reg); + pci_conf_write(isc->isc_pc, isc->isc_tag, AGP_INTEL_AGPCTRL, reg | AGPCTRL_GTLB); break; default: /* XXX */ - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_AGPCTRL, + pci_conf_write(isc->isc_pc, isc->isc_tag, AGP_INTEL_AGPCTRL, 0x2200); - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_INTEL_AGPCTRL, + pci_conf_write(isc->isc_pc, isc->isc_tag, AGP_INTEL_AGPCTRL, 0x2280); } } diff --git a/sys/dev/pci/agp_sis.c b/sys/dev/pci/agp_sis.c index 9a3b8a59329..0bc46a241b7 100644 --- a/sys/dev/pci/agp_sis.c +++ b/sys/dev/pci/agp_sis.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agp_sis.c,v 1.7 2007/12/07 17:35:22 oga Exp $ */ +/* $OpenBSD: agp_sis.c,v 1.8 2008/11/09 15:11:19 oga Exp $ */ /* $NetBSD: agp_sis.c,v 1.2 2001/09/15 00:25:00 thorpej Exp $ */ /*- @@ -29,7 +29,6 @@ * $FreeBSD: src/sys/pci/agp_sis.c,v 1.3 2001/07/05 21:28:47 jhb Exp $ */ - #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> @@ -42,6 +41,7 @@ #include <dev/pci/pcivar.h> #include <dev/pci/pcireg.h> +#include <dev/pci/pcidevs.h> #include <dev/pci/vga_pcivar.h> #include <dev/pci/agpvar.h> #include <dev/pci/agpreg.h> @@ -49,80 +49,92 @@ #include <machine/bus.h> struct agp_sis_softc { - u_int32_t initial_aperture; /* aperture size at startup */ - struct agp_gatt *gatt; + struct device dev; + struct agp_softc *agpdev; + struct agp_gatt *gatt; + pci_chipset_tag_t ssc_pc; + pcitag_t ssc_tag; + bus_size_t initial_aperture; +}; + +void agp_sis_attach(struct device *, struct device *, void *); +int agp_sis_probe(struct device *, void *, void *); +bus_size_t agp_sis_get_aperture(void *); +int agp_sis_set_aperture(void *, bus_size_t); +int agp_sis_bind_page(void *, off_t, bus_addr_t); +int agp_sis_unbind_page(void *, off_t); +void agp_sis_flush_tlb(void *); + +struct cfattach sisagp_ca = { + sizeof(struct agp_sis_softc), agp_sis_probe, agp_sis_attach }; -u_int32_t agp_sis_get_aperture(struct agp_softc *); -int agp_sis_set_aperture(struct agp_softc *, u_int32_t); -int agp_sis_bind_page(struct agp_softc *, off_t, bus_addr_t); -int agp_sis_unbind_page(struct agp_softc *, off_t); -void agp_sis_flush_tlb(struct agp_softc *); +struct cfdriver sisagp_cd = { + NULL, "intelagp", DV_DULL +}; -struct agp_methods agp_sis_methods = { +const struct agp_methods agp_sis_methods = { agp_sis_get_aperture, - agp_sis_set_aperture, agp_sis_bind_page, agp_sis_unbind_page, agp_sis_flush_tlb, - agp_generic_enable, - agp_generic_alloc_memory, - agp_generic_free_memory, - agp_generic_bind_memory, - agp_generic_unbind_memory, }; - int -agp_sis_attach(struct agp_softc *sc, struct pci_attach_args *pa) +agp_sis_probe(struct device *parent, void *match, void *aux) { - struct agp_sis_softc *ssc; - struct agp_gatt *gatt; - pcireg_t reg; + struct agp_attach_args *aa = aux; + struct pci_attach_args *pa = aa->aa_pa; - ssc = malloc(sizeof *ssc, M_AGP, M_NOWAIT); - if (ssc == NULL) { - printf("can't allocate chipset-specific softc\n"); - return (ENOMEM); - } - sc->sc_methods = &agp_sis_methods; - sc->sc_chipc = ssc; + /* Must be a pchb */ + if (agpbus_probe(aa) == 1 && PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SIS) + return (1); + return (0); +} - if (agp_map_aperture(pa, sc, AGP_APBASE, PCI_MAPREG_TYPE_MEM) != 0) { - printf("can't map aperture\n"); - free(ssc, M_AGP); - return (ENXIO); - } - ssc->initial_aperture = AGP_GET_APERTURE(sc); +void +agp_sis_attach(struct device *parent, struct device *self, void *aux) +{ + struct agp_sis_softc *ssc = (struct agp_sis_softc *)self; + struct agp_attach_args *aa = aux; + struct pci_attach_args *pa = aa->aa_pa; + struct agp_gatt *gatt; + pcireg_t reg; + + ssc->ssc_pc = pa->pa_pc; + ssc->ssc_tag = pa->pa_tag; + ssc->initial_aperture = agp_sis_get_aperture(ssc); for (;;) { - gatt = agp_alloc_gatt(sc); - if (gatt) + bus_size_t size = agp_sis_get_aperture(ssc); + gatt = agp_alloc_gatt(pa->pa_dmat, size); + if (gatt != NULL) break; /* - * Probably contigmalloc failure. Try reducing the + * Probably failed to alloc congigious memory. Try reducing the * aperture so that the gatt size reduces. */ - if (AGP_SET_APERTURE(sc, AGP_GET_APERTURE(sc) / 2)) { - agp_generic_detach(sc); - printf("failed to set aperture\n"); - return (ENOMEM); + if (agp_sis_set_aperture(ssc, size / 2)) { + printf("can't set aperture size\n"); + return; } } ssc->gatt = gatt; /* Install the gatt. */ - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_SIS_ATTBASE, + pci_conf_write(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_ATTBASE, gatt->ag_physical); /* Enable the aperture and auto-tlb-inval */ - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_SIS_WINCTRL); + reg = pci_conf_read(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_WINCTRL); reg |= (0x05 << 24) | 3; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_SIS_WINCTRL, reg); + pci_conf_write(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_WINCTRL, reg); - return (0); + ssc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_sis_methods, + AGP_APBASE, PCI_MAPREG_TYPE_MEM, &ssc->dev); + return; } #if 0 @@ -150,22 +162,24 @@ agp_sis_detach(struct agp_softc *sc) } #endif -u_int32_t -agp_sis_get_aperture(struct agp_softc *sc) +bus_size_t +agp_sis_get_aperture(void *sc) { - int gws; + struct agp_sis_softc *ssc = sc; + int gws; /* * The aperture size is equal to 4M<<gws. */ - gws = (pci_conf_read(sc->sc_pc, sc->sc_pcitag, + gws = (pci_conf_read(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_WINCTRL)&0x70) >> 4; return ((4 * 1024 * 1024) << gws); } int -agp_sis_set_aperture(struct agp_softc *sc, u_int32_t aperture) +agp_sis_set_aperture(void *sc, bus_size_t aperture) { + struct agp_sis_softc *ssc = sc; int gws; pcireg_t reg; @@ -180,18 +194,18 @@ agp_sis_set_aperture(struct agp_softc *sc, u_int32_t aperture) gws = ffs(aperture / 4*1024*1024) - 1; - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_SIS_WINCTRL); + reg = pci_conf_read(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_WINCTRL); reg &= ~0x00000070; reg |= gws << 4; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_SIS_WINCTRL, reg); + pci_conf_write(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_WINCTRL, reg); return (0); } int -agp_sis_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical) +agp_sis_bind_page(void *sc, off_t offset, bus_addr_t physical) { - struct agp_sis_softc *ssc = sc->sc_chipc; + struct agp_sis_softc *ssc = sc; if (offset < 0 || offset >= (ssc->gatt->ag_entries << AGP_PAGE_SHIFT)) return (EINVAL); @@ -201,9 +215,9 @@ agp_sis_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical) } int -agp_sis_unbind_page(struct agp_softc *sc, off_t offset) +agp_sis_unbind_page(void *sc, off_t offset) { - struct agp_sis_softc *ssc = sc->sc_chipc; + struct agp_sis_softc *ssc = sc; if (offset < 0 || offset >= (ssc->gatt->ag_entries << AGP_PAGE_SHIFT)) return (EINVAL); @@ -213,12 +227,13 @@ agp_sis_unbind_page(struct agp_softc *sc, off_t offset) } void -agp_sis_flush_tlb(struct agp_softc *sc) +agp_sis_flush_tlb(void *sc) { - pcireg_t reg; + struct agp_sis_softc *ssc = sc; + pcireg_t reg; - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_SIS_TLBFLUSH); + reg = pci_conf_read(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_TLBFLUSH); reg &= 0xffffff00; reg |= 0x02; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_SIS_TLBFLUSH, reg); + pci_conf_write(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_TLBFLUSH, reg); } diff --git a/sys/dev/pci/agp_via.c b/sys/dev/pci/agp_via.c index ce4121dd6db..db7e92f2143 100644 --- a/sys/dev/pci/agp_via.c +++ b/sys/dev/pci/agp_via.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agp_via.c,v 1.8 2007/12/07 17:35:22 oga Exp $ */ +/* $OpenBSD: agp_via.c,v 1.9 2008/11/09 15:11:19 oga Exp $ */ /* $NetBSD: agp_via.c,v 1.2 2001/09/15 00:25:00 thorpej Exp $ */ /*- @@ -29,7 +29,6 @@ * $FreeBSD: src/sys/pci/agp_via.c,v 1.3 2001/07/05 21:28:47 jhb Exp $ */ - #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> @@ -42,35 +41,44 @@ #include <dev/pci/pcivar.h> #include <dev/pci/pcireg.h> +#include <dev/pci/pcidevs.h> #include <dev/pci/vga_pcivar.h> #include <dev/pci/agpvar.h> #include <dev/pci/agpreg.h> #include <machine/bus.h> -u_int32_t agp_via_get_aperture(struct agp_softc *); -int agp_via_set_aperture(struct agp_softc *, u_int32_t); -int agp_via_bind_page(struct agp_softc *, off_t, bus_addr_t); -int agp_via_unbind_page(struct agp_softc *, off_t); -void agp_via_flush_tlb(struct agp_softc *); +void agp_via_attach(struct device *, struct device *, void *); +int agp_via_probe(struct device *, void *, void *); +bus_size_t agp_via_get_aperture(void *); +int agp_via_set_aperture(void *, bus_size_t); +int agp_via_bind_page(void *, off_t, bus_addr_t); +int agp_via_unbind_page(void *, off_t); +void agp_via_flush_tlb(void *); -struct agp_methods agp_via_methods = { +const struct agp_methods agp_via_methods = { agp_via_get_aperture, - agp_via_set_aperture, agp_via_bind_page, agp_via_unbind_page, agp_via_flush_tlb, - agp_generic_enable, - agp_generic_alloc_memory, - agp_generic_free_memory, - agp_generic_bind_memory, - agp_generic_unbind_memory, }; struct agp_via_softc { - u_int32_t initial_aperture; /* aperture size at startup */ - struct agp_gatt *gatt; - int *regs; + struct device dev; + struct agp_softc *agpdev; + struct agp_gatt *gatt; + int *regs; + pci_chipset_tag_t vsc_pc; + pcitag_t vsc_tag; + bus_size_t initial_aperture; +}; + +struct cfattach viaagp_ca = { + sizeof(struct agp_via_softc), agp_via_probe, agp_via_attach +}; + +struct cfdriver viaagp_cd = { + NULL, "viaagp", DV_DULL }; #define REG_GARTCTRL 0 @@ -83,21 +91,31 @@ int via_v3_regs[] = { AGP3_VIA_GARTCTRL, AGP3_VIA_APSIZE, AGP3_VIA_ATTBASE }; int -agp_via_attach(struct agp_softc *sc, struct pci_attach_args *pa) +agp_via_probe(struct device *parent, void *match, void *aux) { - struct agp_via_softc *asc; - struct agp_gatt *gatt; - pcireg_t agpsel, capval; - - asc = malloc(sizeof *asc, M_AGP, M_NOWAIT | M_ZERO); - if (asc == NULL) { - printf("can't allocate chipset-specific softc\n"); - return (ENOMEM); - } - sc->sc_chipc = asc; - sc->sc_methods = &agp_via_methods; - pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_AGP, &sc->sc_capoff, - &capval); + struct agp_attach_args *aa = aux; + struct pci_attach_args *pa = aa->aa_pa; + + /* Must be a pchb */ + if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE && + PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_HOST && + PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH) + return (1); + return (0); +} + +void +agp_via_attach(struct device *parent, struct device *self, void *aux) +{ + struct agp_via_softc *asc = (struct agp_via_softc *)self; + struct agp_attach_args *aa = aux; + struct pci_attach_args *pa = aa->aa_pa; + struct agp_gatt *gatt; + pcireg_t agpsel, capval; + + asc->vsc_pc = pa->pa_pc; + asc->vsc_tag = pa->pa_tag; + pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_AGP, NULL, &capval); if (AGP_CAPID_GET_MAJOR(capval) >= 3) { agpsel = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_VIA_AGPSEL); @@ -113,27 +131,22 @@ agp_via_attach(struct agp_softc *sc, struct pci_attach_args *pa) printf("v2, "); } - if (agp_map_aperture(pa ,sc, AGP_APBASE, PCI_MAPREG_TYPE_MEM) != 0) { - printf("can't map aperture\n"); - free(asc, M_AGP); - return (ENXIO); - } - asc->initial_aperture = AGP_GET_APERTURE(sc); + asc->initial_aperture = agp_via_get_aperture(asc); for (;;) { - gatt = agp_alloc_gatt(sc); - if (gatt) + bus_size_t size = agp_via_get_aperture(asc); + gatt = agp_alloc_gatt(pa->pa_dmat, size); + if (gatt != NULL) break; /* - * Probably contigmalloc failure. Try reducing the + * Probably failed to alloc congigious memory. Try reducing the * aperture so that the gatt size reduces. */ - if (AGP_SET_APERTURE(sc, AGP_GET_APERTURE(sc) / 2)) { - agp_generic_detach(sc); + if (agp_via_set_aperture(asc, size / 2)) { printf("can't set aperture size\n"); - return (ENOMEM); + return; } } asc->gatt = gatt; @@ -156,8 +169,10 @@ agp_via_attach(struct agp_softc *sc, struct pci_attach_args *pa) pci_conf_write(pa->pa_pc, pa->pa_tag, asc->regs[REG_GARTCTRL], gartctrl | (3 << 7)); } + asc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_via_methods, + AGP_APBASE, PCI_MAPREG_TYPE_MEM, &asc->dev); - return (0); + return; } #if 0 @@ -180,14 +195,14 @@ agp_via_detach(struct agp_softc *sc) } #endif -u_int32_t -agp_via_get_aperture(struct agp_softc *sc) +bus_size_t +agp_via_get_aperture(void *sc) { - struct agp_via_softc *asc = sc->sc_chipc; - u_int32_t apsize; + struct agp_via_softc *vsc = sc; + bus_size_t apsize; - apsize = pci_conf_read(sc->sc_pc, sc->sc_pcitag, - asc->regs[REG_APSIZE]) & 0x1f; + apsize = pci_conf_read(vsc->vsc_pc, vsc->vsc_tag, + vsc->regs[REG_APSIZE]) & 0x1f; /* * The size is determined by the number of low bits of @@ -200,11 +215,11 @@ agp_via_get_aperture(struct agp_softc *sc) } int -agp_via_set_aperture(struct agp_softc *sc, u_int32_t aperture) +agp_via_set_aperture(void *sc, bus_size_t aperture) { - struct agp_via_softc *asc = sc->sc_chipc; - u_int32_t apsize; - pcireg_t reg; + struct agp_via_softc *vsc = sc; + bus_size_t apsize; + pcireg_t reg; /* * Reverse the magic from get_aperture. @@ -217,55 +232,55 @@ agp_via_set_aperture(struct agp_softc *sc, u_int32_t aperture) if ((((apsize ^ 0xff) << 20) | ((1 << 20) - 1)) + 1 != aperture) return (EINVAL); - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, asc->regs[REG_APSIZE]); + reg = pci_conf_read(vsc->vsc_pc, vsc->vsc_tag, vsc->regs[REG_APSIZE]); reg &= ~0xff; reg |= apsize; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, asc->regs[REG_APSIZE], reg); + pci_conf_write(vsc->vsc_pc, vsc->vsc_tag, vsc->regs[REG_APSIZE], reg); return (0); } int -agp_via_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical) +agp_via_bind_page(void *sc, off_t offset, bus_addr_t physical) { - struct agp_via_softc *asc = sc->sc_chipc; + struct agp_via_softc *vsc = sc; - if (offset < 0 || offset >= (asc->gatt->ag_entries << AGP_PAGE_SHIFT)) + if (offset < 0 || offset >= (vsc->gatt->ag_entries << AGP_PAGE_SHIFT)) return (EINVAL); - asc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = physical; + vsc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = physical; return (0); } int -agp_via_unbind_page(struct agp_softc *sc, off_t offset) +agp_via_unbind_page(void *sc, off_t offset) { - struct agp_via_softc *asc = sc->sc_chipc; + struct agp_via_softc *vsc = sc; - if (offset < 0 || offset >= (asc->gatt->ag_entries << AGP_PAGE_SHIFT)) + if (offset < 0 || offset >= (vsc->gatt->ag_entries << AGP_PAGE_SHIFT)) return (EINVAL); - asc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = 0; + vsc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = 0; return (0); } void -agp_via_flush_tlb(struct agp_softc *sc) +agp_via_flush_tlb(void *sc) { - struct agp_via_softc *asc = sc->sc_chipc; + struct agp_via_softc *vsc = sc; pcireg_t gartctrl; - if (asc->regs == via_v2_regs) { - pci_conf_write(sc->sc_pc, sc->sc_pcitag, asc->regs[REG_GARTCTRL], - 0x8f); - pci_conf_write(sc->sc_pc, sc->sc_pcitag, asc->regs[REG_GARTCTRL], - 0x0f); + if (vsc->regs == via_v2_regs) { + pci_conf_write(vsc->vsc_pc, vsc->vsc_tag, + vsc->regs[REG_GARTCTRL], 0x8f); + pci_conf_write(vsc->vsc_pc, vsc->vsc_tag, + vsc->regs[REG_GARTCTRL], 0x0f); } else { - gartctrl = pci_conf_read(sc->sc_pc, sc->sc_pcitag, - asc->regs[REG_GARTCTRL]); - pci_conf_write(sc->sc_pc, sc->sc_pcitag, asc->regs[REG_GARTCTRL], - gartctrl & ~(1 << 7)); - pci_conf_write(sc->sc_pc, sc->sc_pcitag, asc->regs[REG_GARTCTRL], - gartctrl); + gartctrl = pci_conf_read(vsc->vsc_pc, vsc->vsc_tag, + vsc->regs[REG_GARTCTRL]); + pci_conf_write(vsc->vsc_pc, vsc->vsc_tag, + vsc->regs[REG_GARTCTRL], gartctrl & ~(1 << 7)); + pci_conf_write(vsc->vsc_pc, vsc->vsc_tag, + vsc->regs[REG_GARTCTRL], gartctrl); } } diff --git a/sys/dev/pci/agpvar.h b/sys/dev/pci/agpvar.h index f363ae5e5a9..bd14c5ee33d 100644 --- a/sys/dev/pci/agpvar.h +++ b/sys/dev/pci/agpvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: agpvar.h,v 1.14 2008/07/12 17:31:06 oga Exp $ */ +/* $OpenBSD: agpvar.h,v 1.15 2008/11/09 15:11:19 oga Exp $ */ /* $NetBSD: agpvar.h,v 1.4 2001/10/01 21:54:48 fvdl Exp $ */ /*- @@ -43,9 +43,17 @@ #define AGPUNIT(x) minor(x) +struct agp_attach_args { + char *aa_busname; + struct pci_attach_args *aa_pa; +}; + struct agpbus_attach_args { - struct pci_attach_args apa_pci_args; - struct pci_attach_args apa_vga_args; + char *aa_busname; /*so pci doesn't conflict*/ + struct pci_attach_args *aa_pa; + const struct agp_methods *aa_methods; + int aa_bar; + pcireg_t aa_type; }; enum agp_acquire_state { @@ -91,67 +99,43 @@ struct agp_memory_info { int ami_is_bound; /* non-zero if bound */ }; -struct agp_softc; - struct agp_methods { - u_int32_t (*get_aperture)(struct agp_softc *); - int (*set_aperture)(struct agp_softc *, u_int32_t); - int (*bind_page)(struct agp_softc *, off_t, bus_addr_t); - int (*unbind_page)(struct agp_softc *, off_t); - void (*flush_tlb)(struct agp_softc *); - int (*enable)(struct agp_softc *, u_int32_t mode); + bus_size_t (*get_aperture)(void *); + int (*bind_page)(void *, off_t, bus_addr_t); + int (*unbind_page)(void *, off_t); + void (*flush_tlb)(void *); + int (*enable)(void *, u_int32_t mode); struct agp_memory * - (*alloc_memory)(struct agp_softc *, int, vsize_t); - int (*free_memory)(struct agp_softc *, struct agp_memory *); - int (*bind_memory)(struct agp_softc *, struct agp_memory *, - off_t); - int (*unbind_memory)(struct agp_softc *, struct agp_memory *); + (*alloc_memory)(void *, int, vsize_t); + int (*free_memory)(void *, struct agp_memory *); + int (*bind_memory)(void *, struct agp_memory *, off_t); + int (*unbind_memory)(void *, struct agp_memory *); }; -#define AGP_GET_APERTURE(sc) ((sc)->sc_methods->get_aperture(sc)) -#define AGP_SET_APERTURE(sc,a) ((sc)->sc_methods->set_aperture((sc),(a))) -#define AGP_BIND_PAGE(sc,o,p) ((sc)->sc_methods->bind_page((sc),(o),(p))) -#define AGP_UNBIND_PAGE(sc,o) ((sc)->sc_methods->unbind_page((sc), (o))) -#define AGP_FLUSH_TLB(sc) ((sc)->sc_methods->flush_tlb(sc)) -#define AGP_ENABLE(sc,m) ((sc)->sc_methods->enable((sc),(m))) -#define AGP_ALLOC_MEMORY(sc,t,s) ((sc)->sc_methods->alloc_memory((sc),(t),(s))) -#define AGP_FREE_MEMORY(sc,m) ((sc)->sc_methods->free_memory((sc),(m))) -#define AGP_BIND_MEMORY(sc,m,o) ((sc)->sc_methods->bind_memory((sc),(m),(o))) -#define AGP_UNBIND_MEMORY(sc,m) ((sc)->sc_methods->unbind_memory((sc),(m))) - /* * All chipset drivers must have this at the start of their softc. */ struct agp_softc { - struct device sc_dev; - - bus_space_tag_t sc_bt, sc_memt; - bus_space_handle_t sc_bh; - bus_addr_t sc_apaddr; - bus_size_t sc_apsize; - bus_dma_tag_t sc_dmat; - struct rwlock sc_lock; /* lock for access to GATT */ - pcitag_t sc_pcitag; /* PCI tag, in case we need it. */ - pcireg_t sc_id; - pci_chipset_tag_t sc_pc; - - pci_chipset_tag_t sc_vgapc; - pcitag_t sc_vgapcitag; - - struct agp_methods *sc_methods; - void *sc_chipc; /* chipset-dependent state */ - - int sc_opened; - int sc_capoff; - int sc_apflags; - int sc_nextid; /* next memory block id */ - - u_int32_t sc_maxmem; /* allocation upper bound */ - u_int32_t sc_allocated; /* amount allocated */ - enum agp_acquire_state sc_state; - struct agp_memory_list sc_memory; /* list of allocated memory */ - - struct vga_pci_softc *vga_softc; /* needed for shared mappings */ + struct device sc_dev; + + struct agp_memory_list sc_memory; /* mem blocks */ + struct rwlock sc_lock; /* GATT access lock */ + const struct agp_methods *sc_methods; /* callbacks */ + void *sc_chipc; /* chipset softc */ + + bus_dma_tag_t sc_dmat; + bus_addr_t sc_apaddr; + pci_chipset_tag_t sc_pc; + pcitag_t sc_pcitag; + pcireg_t sc_id; + + int sc_opened; + int sc_capoff; + int sc_nextid; /* next mem block id */ + enum agp_acquire_state sc_state; + + u_int32_t sc_maxmem; /* mem upper bound */ + u_int32_t sc_allocated; /* amount allocated */ }; struct agp_gatt { @@ -163,57 +147,27 @@ struct agp_gatt { size_t ag_size; }; - -struct agp_product { - int ap_vendor; - int ap_product; - int (*ap_attach)(struct agp_softc *, - struct pci_attach_args *); -}; -/* MD-defined */ -extern const struct agp_product agp_products[]; - -void agp_attach(struct device *, struct device *, void *); -int agp_probe(struct device *, void *, void *); -paddr_t agpmmap(void *, off_t, int); -int agpioctl(dev_t, u_long, caddr_t, int, struct proc *); -int agpopen(dev_t, int, int, struct proc *); -int agpclose(dev_t, int, int , struct proc *); -void agp_set_pchb(struct pci_attach_args*); /* * Functions private to the AGP code. */ - -int agp_find_caps(pci_chipset_tag_t, pcitag_t); +struct device *agp_attach_bus(struct pci_attach_args *, + const struct agp_methods *, int, pcireg_t, + struct device *); int agp_map_aperture(struct pci_attach_args *, struct agp_softc *, u_int32_t, u_int32_t); -u_int32_t agp_generic_get_aperture(struct agp_softc *); -int agp_generic_set_aperture(struct agp_softc *, u_int32_t); struct agp_gatt * - agp_alloc_gatt(struct agp_softc *); -void agp_free_gatt(struct agp_softc *, struct agp_gatt *); + agp_alloc_gatt(bus_dma_tag_t, u_int32_t); +void agp_free_gatt(bus_dma_tag_t, struct agp_gatt *); void agp_flush_cache(void); -int agp_generic_attach(struct agp_softc *); -int agp_generic_detach(struct agp_softc *); -int agp_generic_enable(struct agp_softc *, u_int32_t); -struct agp_memory * - agp_generic_alloc_memory(struct agp_softc *, int, vsize_t size); -int agp_generic_free_memory(struct agp_softc *, struct agp_memory *); -int agp_generic_bind_memory(struct agp_softc *, struct agp_memory *, - off_t); +int agp_generic_bind_memory(struct agp_softc *, struct agp_memory *, off_t); int agp_generic_unbind_memory(struct agp_softc *, struct agp_memory *); -int agp_ali_attach(struct agp_softc *, struct pci_attach_args *); -int agp_amd_attach(struct agp_softc *, struct pci_attach_args *); -int agp_i810_attach(struct agp_softc *, struct pci_attach_args *); -int agp_intel_attach(struct agp_softc *, struct pci_attach_args *); -int agp_via_attach(struct agp_softc *, struct pci_attach_args *); -int agp_sis_attach(struct agp_softc *, struct pci_attach_args *); - int agp_alloc_dmamem(bus_dma_tag_t, size_t, int, bus_dmamap_t *, caddr_t *, bus_addr_t *, bus_dma_segment_t *, int, int *); void agp_free_dmamem(bus_dma_tag_t, size_t, bus_dmamap_t, caddr_t, bus_dma_segment_t *, int nseg) ; +int agpdev_print(void *, const char *); +int agpbus_probe(struct agp_attach_args *aa); /* diff --git a/sys/dev/pci/files.agp b/sys/dev/pci/files.agp index cdd86684e62..b60209e0ca0 100644 --- a/sys/dev/pci/files.agp +++ b/sys/dev/pci/files.agp @@ -1,27 +1,34 @@ -# $OpenBSD: files.agp,v 1.2 2008/03/16 19:00:28 oga Exp $ +# $OpenBSD: files.agp,v 1.3 2008/11/09 15:11:19 oga Exp $ -file dev/pci/agp.c agp needs-flag +define agpdev {} -define agp_ali -file dev/pci/agp_ali.c agp_ali & agpbus needs-flag +# agpbus defined in /sys/conf/files +device agp: agpdev +attach agp at agpdev +file dev/pci/agp.c agp needs-flag -define agp_amd -file dev/pci/agp_amd.c agp_amd & agpbus needs-flag +device aliagp: agpdev +attach aliagp at agpbus +file dev/pci/agp_ali.c aliagp -define agp_apple -file dev/pci/agp_apple.c agp_apple & agpbus needs-flag +device amdagp: agpdev +attach amdagp at agpbus +file dev/pci/agp_amd.c amdagp -define agp_i810 -file dev/pci/agp_i810.c agp_i810 & agpbus needs-flag +device intelagp: agpdev +attach intelagp at agpbus +file dev/pci/agp_intel.c intelagp -define agp_intel -file dev/pci/agp_intel.c agp_intel & agpbus needs-flag +# agpint defined in /sys/conf/files since it attaches at vga +device intagp: agpdev +attach intagp at agpint +# intelagp needs file to check presence of IGD +file dev/pci/agp_i810.c intagp needs-flag -define agp_sis -file dev/pci/agp_sis.c agp_sis & agpbus needs-flag +device sisagp: agpdev +attach sisagp at agpbus +file dev/pci/agp_sis.c sisagp -define agp_via -file dev/pci/agp_via.c agp_via & agpbus needs-flag - -define agp_amd64 -file dev/pci/agp_amd64.c agp_amd64 & agpbus needs-flag +device viaagp: agpdev +attach viaagp at agpbus +file dev/pci/agp_via.c viaagp diff --git a/sys/dev/pci/vga_pci.c b/sys/dev/pci/vga_pci.c index 68fdf3e7e07..bcd4d6b8b8c 100644 --- a/sys/dev/pci/vga_pci.c +++ b/sys/dev/pci/vga_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vga_pci.c,v 1.37 2008/08/12 23:10:41 oga Exp $ */ +/* $OpenBSD: vga_pci.c,v 1.38 2008/11/09 15:11:19 oga Exp $ */ /* $NetBSD: vga_pci.c,v 1.3 1998/06/08 06:55:58 thorpej Exp $ */ /* @@ -95,7 +95,7 @@ #include <dev/vesa/vesabiosvar.h> #endif -#include "agp.h" +#include "intagp.h" #include "drmbase.h" int vga_pci_match(struct device *, void *, void *); @@ -103,9 +103,9 @@ void vga_pci_attach(struct device *, struct device *, void *); paddr_t vga_pci_mmap(void* v, off_t off, int prot); void vga_pci_bar_init(struct vga_pci_softc *, struct pci_attach_args *); -#if NAGP > 0 -int agpsubmatch(struct device *, void *, void *); -int agpbus_print(void *, const char *); +#if NINTAGP > 0 +int intagpsubmatch(struct device *, void *, void *); +int intagp_print(void *, const char *); #endif #if NDRMBASE > 0 int drmsubmatch(struct device *, void *, void *); @@ -121,20 +121,6 @@ struct cfattach vga_pci_ca = { sizeof(struct vga_pci_softc), vga_pci_match, vga_pci_attach, }; -#if NAGP > 0 -struct pci_attach_args agp_pchb_pa; -int agp_pchb_pa_set = 0; - -void -agp_set_pchb(struct pci_attach_args *pa) -{ - if (!agp_pchb_pa_set) { - memcpy(&agp_pchb_pa, pa, sizeof *pa); - agp_pchb_pa_set++; - } -} -#endif - int vga_pci_match(struct device *parent, void *match, void *aux) { @@ -166,9 +152,6 @@ void vga_pci_attach(struct device *parent, struct device *self, void *aux) { struct pci_attach_args *pa = aux; -#if NAGP >0 - struct agpbus_attach_args aba; -#endif pcireg_t reg; struct vga_pci_softc *sc = (struct vga_pci_softc *)self; @@ -194,15 +177,13 @@ vga_pci_attach(struct device *parent, struct device *self, void *aux) vga_pci_bar_init(sc, pa); -#if NAGP > 0 +#if NINTAGP > 0 /* - * attach agp here instead of pchb so it can share mappings - * with the DRM + * attach intagp here instead of pchb so it can share mappings + * with the DRM. */ - if (agp_pchb_pa_set) { - aba.apa_pci_args = agp_pchb_pa; - memcpy(&aba.apa_vga_args, pa, sizeof(struct pci_attach_args)); - config_found_sm(self, &aba, agpbus_print, agpsubmatch); + if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL) { + config_found_sm(self, aux, intagp_print, intagpsubmatch); } #endif @@ -212,24 +193,24 @@ vga_pci_attach(struct device *parent, struct device *self, void *aux) #endif } -#if NAGP > 0 +#if NINTAGP > 0 int -agpsubmatch(struct device *parent, void *match, void *aux) +intagpsubmatch(struct device *parent, void *match, void *aux) { - extern struct cfdriver agp_cd; + extern struct cfdriver intagp_cd; struct cfdata *cf = match; - /* only allow agp to attach */ - if (cf->cf_driver == &agp_cd) + /* only allow intagp to attach */ + if (cf->cf_driver == &intagp_cd) return ((*cf->cf_attach->ca_match)(parent, match, aux)); return (0); } int -agpbus_print(void *vaa, const char *pnp) +intagp_print(void *vaa, const char *pnp) { if (pnp) - printf("agp at %s", pnp); + printf("intagp at %s", pnp); return (UNCONF); } #endif |