diff options
author | Owain Ainsworth <oga@cvs.openbsd.org> | 2009-05-10 16:57:45 +0000 |
---|---|---|
committer | Owain Ainsworth <oga@cvs.openbsd.org> | 2009-05-10 16:57:45 +0000 |
commit | 6e40785a24faa417986e316f87006eeb096679af (patch) | |
tree | 13a754e8f047f4d6da81fb213bedbbe08c26e273 /sys/dev/pci | |
parent | f30690eb1104dea186726aa4ff0270dc60621507 (diff) |
Change agp attach (again) so that the driver passes in the aperture size.
While the aperture size may change during attach, it never changes after
the end of the subdriver attach function, so getting this value with a
function is a waste of time. shrinks things slightly and makes the code
clearer.
Diffstat (limited to 'sys/dev/pci')
-rw-r--r-- | sys/dev/pci/agp.c | 19 | ||||
-rw-r--r-- | sys/dev/pci/agp_ali.c | 15 | ||||
-rw-r--r-- | sys/dev/pci/agp_amd.c | 15 | ||||
-rw-r--r-- | sys/dev/pci/agp_i810.c | 22 | ||||
-rw-r--r-- | sys/dev/pci/agp_intel.c | 15 | ||||
-rw-r--r-- | sys/dev/pci/agp_sis.c | 15 | ||||
-rw-r--r-- | sys/dev/pci/agp_via.c | 15 | ||||
-rw-r--r-- | sys/dev/pci/agpvar.h | 9 |
8 files changed, 56 insertions, 69 deletions
diff --git a/sys/dev/pci/agp.c b/sys/dev/pci/agp.c index 9d4c7501831..a4359e9a8d4 100644 --- a/sys/dev/pci/agp.c +++ b/sys/dev/pci/agp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agp.c,v 1.31 2009/05/10 15:28:45 oga Exp $ */ +/* $OpenBSD: agp.c,v 1.32 2009/05/10 16:57:44 oga Exp $ */ /*- * Copyright (c) 2000 Doug Rabson * All rights reserved. @@ -115,13 +115,14 @@ agpvga_match(struct pci_attach_args *pa) struct device * agp_attach_bus(struct pci_attach_args *pa, const struct agp_methods *methods, - bus_addr_t apaddr, struct device *dev) + bus_addr_t apaddr, bus_size_t apsize, struct device *dev) { struct agpbus_attach_args arg; arg.aa_methods = methods; arg.aa_pa = pa; arg.aa_apaddr = apaddr; + arg.aa_apsize = apsize; printf("\n"); /* newline from the driver that called us */ return (config_found(dev, &arg, agpdev_print)); @@ -149,6 +150,7 @@ agp_attach(struct device *parent, struct device *self, void *aux) sc->sc_chipc = parent; sc->sc_methods = aa->aa_methods; sc->sc_apaddr = aa->aa_apaddr; + sc->sc_apsize = aa->aa_apsize; static const int agp_max[][2] = { {0, 0}, @@ -192,7 +194,7 @@ agp_attach(struct device *parent, struct device *self, void *aux) &sc->sc_capoff, NULL); printf(": aperture at 0x%lx, size 0x%lx\n", (u_long)sc->sc_apaddr, - (u_long)sc->sc_methods->get_aperture(sc->sc_chipc)); + (u_long)sc->sc_apsize); } struct cfattach agp_ca = { @@ -211,7 +213,7 @@ agpmmap(void *v, off_t off, int prot) if (sc->sc_apaddr) { - if (off > sc->sc_methods->get_aperture(sc->sc_chipc)) + if (off > sc->sc_apsize) return (-1); /* @@ -475,9 +477,8 @@ 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 > - sc->sc_methods->get_aperture(sc->sc_chipc)) { + if (offset < 0 || (offset & (AGP_PAGE_SIZE - 1)) != 0 || + offset + mem->am_size > sc->sc_apsize) { printf("AGP: binding memory at bad offset %#lx\n", (unsigned long) offset); rw_exit_write(&sc->sc_lock); @@ -699,7 +700,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 = sc->sc_methods->get_aperture(sc->sc_chipc) >> 20; + info->aper_size = sc->sc_apsize >> 20; info->pg_total = info->pg_system = sc->sc_maxmem >> AGP_PAGE_SHIFT; info->pg_used = sc->sc_allocated >> AGP_PAGE_SHIFT; @@ -799,7 +800,7 @@ agp_get_info(void *dev, struct agp_info *info) else info->ai_mode = 0; /* i810 doesn't have real AGP */ info->ai_aperture_base = sc->sc_apaddr; - info->ai_aperture_size = sc->sc_methods->get_aperture(sc->sc_chipc); + info->ai_aperture_size = sc->sc_apsize; info->ai_memory_allowed = sc->sc_maxmem; info->ai_memory_used = sc->sc_allocated; } diff --git a/sys/dev/pci/agp_ali.c b/sys/dev/pci/agp_ali.c index 1fe96e3eaaa..5058ac0ca4c 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.9 2009/05/10 15:28:45 oga Exp $ */ +/* $OpenBSD: agp_ali.c,v 1.10 2009/05/10 16:57:44 oga Exp $ */ /* $NetBSD: agp_ali.c,v 1.2 2001/09/15 00:25:00 thorpej Exp $ */ @@ -56,7 +56,7 @@ struct agp_ali_softc { pci_chipset_tag_t asc_pc; pcitag_t asc_tag; bus_addr_t asc_apaddr; - bus_size_t initial_aperture; + bus_size_t asc_apsize; }; void agp_ali_attach(struct device *, struct device *, void *); @@ -76,7 +76,6 @@ struct cfdriver aliagp_cd = { }; const struct agp_methods agp_ali_methods = { - agp_ali_get_aperture, agp_ali_bind_page, agp_ali_unbind_page, agp_ali_flush_tlb, @@ -106,7 +105,7 @@ agp_ali_attach(struct device *parent, struct device *self, void *aux) asc->asc_tag = pa->pa_tag; asc->asc_pc = pa->pa_pc; - asc->initial_aperture = agp_ali_get_aperture(asc); + asc->asc_apsize = agp_ali_get_aperture(asc); if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, AGP_APBASE, PCI_MAPREG_TYPE_MEM, &asc->asc_apaddr, NULL, NULL) != 0) { @@ -115,15 +114,15 @@ agp_ali_attach(struct device *parent, struct device *self, void *aux) } for (;;) { - bus_size_t size = agp_ali_get_aperture(asc); - gatt = agp_alloc_gatt(pa->pa_dmat, size); + gatt = agp_alloc_gatt(pa->pa_dmat, asc->asc_apsize); if (gatt != NULL) break; /* * almost certainly error allocating contigious dma memory * so reduce aperture so that the gatt size reduces. */ - if (agp_ali_set_aperture(asc, size / 2)) { + asc->asc_apsize /= 2; + if (agp_ali_set_aperture(asc, asc->asc_apsize)) { printf("failed to set aperture\n"); return; } @@ -141,7 +140,7 @@ agp_ali_attach(struct device *parent, struct device *self, void *aux) pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_ALI_TLBCTRL, reg); asc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_ali_methods, - asc->asc_apaddr, &asc->dev); + asc->asc_apaddr, asc->asc_apsize, &asc->dev); return; } diff --git a/sys/dev/pci/agp_amd.c b/sys/dev/pci/agp_amd.c index f2d4cda07ca..58d0d582648 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.12 2009/05/10 15:28:45 oga Exp $ */ +/* $OpenBSD: agp_amd.c,v 1.13 2009/05/10 16:57:44 oga Exp $ */ /* $NetBSD: agp_amd.c,v 1.6 2001/10/06 02:48:50 thorpej Exp $ */ /*- @@ -73,7 +73,7 @@ struct agp_amd_softc { bus_space_handle_t ioh; bus_space_tag_t iot; bus_addr_t asc_apaddr; - bus_size_t initial_aperture; + bus_size_t asc_apsize; }; void agp_amd_attach(struct device *, struct device *, void *); @@ -94,7 +94,6 @@ struct cfdriver amdagp_cd = { }; const struct agp_methods agp_amd_methods = { - agp_amd_get_aperture, agp_amd_bind_page, agp_amd_unbind_page, agp_amd_flush_tlb, @@ -206,11 +205,10 @@ agp_amd_attach(struct device *parent, struct device *self, void *aux) return; } - asc->initial_aperture = agp_amd_get_aperture(asc); + asc->asc_apsize = agp_amd_get_aperture(asc); for (;;) { - bus_size_t size = agp_amd_get_aperture(asc); - gatt = agp_amd_alloc_gatt(pa->pa_dmat, size); + gatt = agp_amd_alloc_gatt(pa->pa_dmat, asc->asc_apsize); if (gatt != NULL) break; @@ -218,7 +216,8 @@ agp_amd_attach(struct device *parent, struct device *self, void *aux) * almost certainly error allocating contigious dma memory * so reduce aperture so that the gatt size reduces. */ - if (agp_amd_set_aperture(asc, size / 2)) { + asc->asc_apsize /= 2; + if (agp_amd_set_aperture(asc, asc->asc_apsize)) { printf(": failed to set aperture\n"); return; } @@ -239,7 +238,7 @@ agp_amd_attach(struct device *parent, struct device *self, void *aux) agp_amd_flush_tlb(asc); asc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_amd_methods, - asc->asc_apaddr, &asc->dev); + asc->asc_apaddr, asc->asc_apsize, &asc->dev); return; } diff --git a/sys/dev/pci/agp_i810.c b/sys/dev/pci/agp_i810.c index da7ef078622..3b1a18346ee 100644 --- a/sys/dev/pci/agp_i810.c +++ b/sys/dev/pci/agp_i810.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agp_i810.c,v 1.51 2009/05/10 15:28:45 oga Exp $ */ +/* $OpenBSD: agp_i810.c,v 1.52 2009/05/10 16:57:44 oga Exp $ */ /*- * Copyright (c) 2000 Doug Rabson @@ -69,7 +69,7 @@ struct agp_i810_softc { struct vga_pci_bar *map; struct vga_pci_bar *gtt_map; bus_addr_t isc_apaddr; - bus_size_t aperture; /* current aperture size */ + bus_size_t isc_apsize; /* current aperture size */ int chiptype; /* i810-like or i830 */ u_int32_t dcache_size; /* i810 only */ u_int32_t stolen; /* number of i830/845 gtt @@ -79,7 +79,6 @@ struct agp_i810_softc { 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 *); void agp_i810_bind_page(void *, bus_size_t, paddr_t, int); void agp_i810_unbind_page(void *, bus_size_t); void agp_i810_flush_tlb(void *); @@ -100,7 +99,6 @@ struct cfdriver intagp_cd = { }; struct agp_methods agp_i810_methods = { - agp_i810_get_aperture, agp_i810_bind_page, agp_i810_unbind_page, agp_i810_flush_tlb, @@ -231,8 +229,8 @@ agp_i810_attach(struct device *parent, struct device *self, void *aux) } if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, gmaddr, memtype, - &isc->isc_apaddr, &isc->aperture, NULL) != 0) { - printf("can't get aperture size\n"); + &isc->isc_apaddr, &isc->isc_apsize, NULL) != 0) { + printf("can't get aperture info\n"); return; } @@ -258,7 +256,7 @@ agp_i810_attach(struct device *parent, struct device *self, void *aux) } isc->gatt = gatt; - gatt->ag_entries = isc->aperture >> AGP_PAGE_SHIFT; + gatt->ag_entries = isc->isc_apsize >> AGP_PAGE_SHIFT; /* * Find the GMCH, some of the registers we need to read for @@ -459,7 +457,7 @@ agp_i810_attach(struct device *parent, struct device *self, void *aux) agp_flush_cache(); isc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_i810_methods, - isc->isc_apaddr, &isc->dev); + isc->isc_apaddr, isc->isc_apsize, &isc->dev); return; out: @@ -507,14 +505,6 @@ agp_i810_detach(struct agp_softc *sc) } #endif -bus_size_t -agp_i810_get_aperture(void *sc) -{ - struct agp_i810_softc *isc = sc; - - return (isc->aperture); -} - void agp_i810_bind_page(void *sc, bus_addr_t offset, paddr_t physical, int flags) { diff --git a/sys/dev/pci/agp_intel.c b/sys/dev/pci/agp_intel.c index 56905c35b5c..d8dde36e9ae 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.14 2009/05/10 15:28:45 oga Exp $ */ +/* $OpenBSD: agp_intel.c,v 1.15 2009/05/10 16:57:44 oga Exp $ */ /* $NetBSD: agp_intel.c,v 1.3 2001/09/15 00:25:00 thorpej Exp $ */ /*- @@ -54,6 +54,7 @@ struct agp_intel_softc { pci_chipset_tag_t isc_pc; pcitag_t isc_tag; bus_addr_t isc_apaddr; + bus_size_t isc_apsize; u_int aperture_mask; enum { CHIP_INTEL, @@ -63,7 +64,6 @@ struct agp_intel_softc { CHIP_I850, CHIP_I865 } chiptype; - bus_size_t initial_aperture; /* startup aperture size */ }; @@ -84,7 +84,6 @@ struct cfdriver intelagp_cd = { }; const struct agp_methods agp_intel_methods = { - agp_intel_get_aperture, agp_intel_bind_page, agp_intel_unbind_page, agp_intel_flush_tlb, @@ -176,11 +175,10 @@ agp_intel_attach(struct device *parent, struct device *self, void *aux) isc->aperture_mask = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_INTEL_APSIZE) & APSIZE_MASK; pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_INTEL_APSIZE, value); - isc->initial_aperture = agp_intel_get_aperture(isc); + isc->isc_apsize = agp_intel_get_aperture(isc); for (;;) { - bus_size_t size = agp_intel_get_aperture(isc); - gatt = agp_alloc_gatt(pa->pa_dmat, size); + gatt = agp_alloc_gatt(pa->pa_dmat, isc->isc_apsize); if (gatt != NULL) break; @@ -188,7 +186,8 @@ agp_intel_attach(struct device *parent, struct device *self, void *aux) * almost certainly error allocating contigious dma memory * so reduce aperture so that the gatt size reduces. */ - if (agp_intel_set_aperture(isc, size / 2)) { + isc->isc_apsize /= 2; + if (agp_intel_set_aperture(isc, isc->isc_apsize)) { printf(": failed to set aperture\n"); return; } @@ -255,7 +254,7 @@ agp_intel_attach(struct device *parent, struct device *self, void *aux) } isc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_intel_methods, - isc->isc_apaddr, &isc->dev); + isc->isc_apaddr, isc->isc_apsize, &isc->dev); return; } diff --git a/sys/dev/pci/agp_sis.c b/sys/dev/pci/agp_sis.c index e96199abcff..8a0f9e6426c 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.12 2009/05/10 15:28:45 oga Exp $ */ +/* $OpenBSD: agp_sis.c,v 1.13 2009/05/10 16:57:44 oga Exp $ */ /* $NetBSD: agp_sis.c,v 1.2 2001/09/15 00:25:00 thorpej Exp $ */ /*- @@ -55,7 +55,7 @@ struct agp_sis_softc { pci_chipset_tag_t ssc_pc; pcitag_t ssc_tag; bus_addr_t ssc_apaddr; - bus_size_t initial_aperture; + bus_size_t ssc_apsize; }; void agp_sis_attach(struct device *, struct device *, void *); @@ -75,7 +75,6 @@ struct cfdriver sisagp_cd = { }; const struct agp_methods agp_sis_methods = { - agp_sis_get_aperture, agp_sis_bind_page, agp_sis_unbind_page, agp_sis_flush_tlb, @@ -113,11 +112,10 @@ agp_sis_attach(struct device *parent, struct device *self, void *aux) ssc->ssc_pc = pa->pa_pc; ssc->ssc_tag = pa->pa_tag; - ssc->initial_aperture = agp_sis_get_aperture(ssc); + ssc->ssc_apsize = agp_sis_get_aperture(ssc); for (;;) { - bus_size_t size = agp_sis_get_aperture(ssc); - gatt = agp_alloc_gatt(pa->pa_dmat, size); + gatt = agp_alloc_gatt(pa->pa_dmat, ssc->ssc_apsize); if (gatt != NULL) break; @@ -125,7 +123,8 @@ agp_sis_attach(struct device *parent, struct device *self, void *aux) * Probably failed to alloc congigious memory. Try reducing the * aperture so that the gatt size reduces. */ - if (agp_sis_set_aperture(ssc, size / 2)) { + ssc->ssc_apsize /= 2; + if (agp_sis_set_aperture(ssc, ssc->ssc_apsize)) { printf("can't set aperture size\n"); return; } @@ -142,7 +141,7 @@ agp_sis_attach(struct device *parent, struct device *self, void *aux) pci_conf_write(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_WINCTRL, reg); ssc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_sis_methods, - ssc->ssc_apaddr, &ssc->dev); + ssc->ssc_apaddr, ssc->ssc_apsize, &ssc->dev); return; } diff --git a/sys/dev/pci/agp_via.c b/sys/dev/pci/agp_via.c index dd4f2cbac00..cdec2b29feb 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.13 2009/05/10 15:28:45 oga Exp $ */ +/* $OpenBSD: agp_via.c,v 1.14 2009/05/10 16:57:44 oga Exp $ */ /* $NetBSD: agp_via.c,v 1.2 2001/09/15 00:25:00 thorpej Exp $ */ /*- @@ -57,7 +57,6 @@ void agp_via_unbind_page(void *, bus_addr_t); void agp_via_flush_tlb(void *); const struct agp_methods agp_via_methods = { - agp_via_get_aperture, agp_via_bind_page, agp_via_unbind_page, agp_via_flush_tlb, @@ -71,7 +70,7 @@ struct agp_via_softc { pci_chipset_tag_t vsc_pc; pcitag_t vsc_tag; bus_addr_t vsc_apaddr; - bus_size_t initial_aperture; + bus_size_t vsc_apsize; }; struct cfattach viaagp_ca = { @@ -142,11 +141,10 @@ agp_via_attach(struct device *parent, struct device *self, void *aux) } - vsc->initial_aperture = agp_via_get_aperture(vsc); + vsc->vsc_apsize = agp_via_get_aperture(vsc); for (;;) { - bus_size_t size = agp_via_get_aperture(vsc); - gatt = agp_alloc_gatt(pa->pa_dmat, size); + gatt = agp_alloc_gatt(pa->pa_dmat, vsc->vsc_apsize); if (gatt != NULL) break; @@ -154,7 +152,8 @@ agp_via_attach(struct device *parent, struct device *self, void *aux) * Probably failed to alloc congigious memory. Try reducing the * aperture so that the gatt size reduces. */ - if (agp_via_set_aperture(vsc, size / 2)) { + vsc->vsc_apsize /= 2; + if (agp_via_set_aperture(vsc, vsc->vsc_apsize)) { printf(", can't set aperture size\n"); return; } @@ -180,7 +179,7 @@ agp_via_attach(struct device *parent, struct device *self, void *aux) gartctrl | (3 << 7)); } vsc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_via_methods, - vsc->vsc_apaddr, &vsc->dev); + vsc->vsc_apaddr, vsc->vsc_apsize, &vsc->dev); return; } diff --git a/sys/dev/pci/agpvar.h b/sys/dev/pci/agpvar.h index 331cdd90b1c..9ea6d3ed386 100644 --- a/sys/dev/pci/agpvar.h +++ b/sys/dev/pci/agpvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: agpvar.h,v 1.18 2009/05/10 15:28:45 oga Exp $ */ +/* $OpenBSD: agpvar.h,v 1.19 2009/05/10 16:57:44 oga Exp $ */ /* $NetBSD: agpvar.h,v 1.4 2001/10/01 21:54:48 fvdl Exp $ */ /*- @@ -53,6 +53,7 @@ struct agpbus_attach_args { struct pci_attach_args *aa_pa; const struct agp_methods *aa_methods; bus_addr_t aa_apaddr; + bus_size_t aa_apsize; }; enum agp_acquire_state { @@ -98,7 +99,6 @@ struct agp_memory_info { }; struct agp_methods { - bus_size_t (*get_aperture)(void *); void (*bind_page)(void *, bus_addr_t, paddr_t, int); void (*unbind_page)(void *, bus_addr_t); void (*flush_tlb)(void *); @@ -122,9 +122,10 @@ struct agp_softc { 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; + bus_addr_t sc_apaddr; + bus_size_t sc_apsize; pcireg_t sc_id; int sc_opened; @@ -149,7 +150,7 @@ struct agp_gatt { * Functions private to the AGP code. */ struct device *agp_attach_bus(struct pci_attach_args *, - const struct agp_methods *, bus_addr_t, + const struct agp_methods *, bus_addr_t, bus_size_t, struct device *); struct agp_gatt * agp_alloc_gatt(bus_dma_tag_t, u_int32_t); |