diff options
author | Owain Ainsworth <oga@cvs.openbsd.org> | 2008-03-23 19:54:48 +0000 |
---|---|---|
committer | Owain Ainsworth <oga@cvs.openbsd.org> | 2008-03-23 19:54:48 +0000 |
commit | 9ab8a2db3e2f993b0439ea59e4ad8390ea30fde6 (patch) | |
tree | 1500b668dffa331279e61c63c116ac61573f7ed1 | |
parent | 22d6f5e4d5fcaba32cba4fa5ed6faef60269de06 (diff) |
Sometimes the registers claiming the aperture size on 9XX chipsets lie.
So instead, use the size of the aperture BAR to determine the aperture
size for agp_i810, and don't let the 855 and above have the aperture
set. Next to nothing uses it anyway so no harm.
introduce generic_{get,set} aperture which has this behaviour so other
drivers may use it if useful.
Change inspired by what freebsd did after i noticed my aperture size was
wrong.
Tested by many, ok kettenis@.
-rw-r--r-- | sys/dev/pci/agp.c | 17 | ||||
-rw-r--r-- | sys/dev/pci/agp_i810.c | 106 | ||||
-rw-r--r-- | sys/dev/pci/agpvar.h | 4 |
3 files changed, 32 insertions, 95 deletions
diff --git a/sys/dev/pci/agp.c b/sys/dev/pci/agp.c index 5ceac833b99..cfb0aa86ecc 100644 --- a/sys/dev/pci/agp.c +++ b/sys/dev/pci/agp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agp.c,v 1.18 2008/03/23 08:36:41 damien Exp $ */ +/* $OpenBSD: agp.c,v 1.19 2008/03/23 19:54:47 oga Exp $ */ /*- * Copyright (c) 2000 Doug Rabson * All rights reserved. @@ -361,6 +361,21 @@ agp_map_aperture(struct pci_attach_args *pa, struct agp_softc *sc, u_int32_t bar 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) { diff --git a/sys/dev/pci/agp_i810.c b/sys/dev/pci/agp_i810.c index ddf397cd12a..67fbb6ee66c 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.33 2008/03/23 08:36:41 damien Exp $ */ +/* $OpenBSD: agp_i810.c,v 1.34 2008/03/23 19:54:47 oga Exp $ */ /* $NetBSD: agp_i810.c,v 1.15 2003/01/31 00:07:39 thorpej Exp $ */ /*- @@ -86,7 +86,6 @@ struct agp_i810_softc { }; int agp_i810_vgamatch(struct pci_attach_args *); -u_int32_t agp_i810_get_aperture(struct agp_softc *); 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); @@ -100,7 +99,7 @@ int agp_i810_unbind_memory(struct agp_softc *, struct agp_memory *); void agp_i810_write_gatt(struct agp_i810_softc *, bus_size_t, u_int32_t); struct agp_methods agp_i810_methods = { - agp_i810_get_aperture, + agp_generic_get_aperture, agp_i810_set_aperture, agp_i810_bind_page, agp_i810_unbind_page, @@ -490,63 +489,15 @@ agp_i810_detach(struct agp_softc *sc) } #endif -u_int32_t -agp_i810_get_aperture(struct agp_softc *sc) -{ - struct agp_i810_softc *isc = sc->sc_chipc; - pcireg_t reg; - - if (isc->chiptype == CHIP_I810) { - u_int16_t miscc; - - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_I810_SMRAM); - miscc = (u_int16_t)(reg >> 16); - if ((miscc & AGP_I810_MISCC_WINSIZE) == - AGP_I810_MISCC_WINSIZE_32) - return (32 * 1024 * 1024); - else - return (64 * 1024 * 1024); - } else if (isc->chiptype == CHIP_I830) { - u_int16_t gcc1; - - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_I830_GCC0); - gcc1 = (u_int16_t)(reg >> 16); - if ((gcc1 & AGP_I830_GCC1_GMASIZE) == AGP_I830_GCC1_GMASIZE_64) - return (64 * 1024 * 1024); - else - return (128 * 1024 * 1024); - } else if (isc->chiptype == CHIP_I915 || isc->chiptype == CHIP_G33) { - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_I915_MSAC); - if ((reg & AGP_I915_MSAC_GMASIZE) == AGP_I915_MSAC_GMASIZE_128) { - return (128 * 1024 * 1024); - } else { - return (256 * 1024 * 1024); - } - } else if (isc->chiptype == CHIP_I965) { - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_I965_MSAC); - switch (reg & AGP_I965_MSAC_GMASIZE) { - case AGP_I965_MSAC_GMASIZE_128: - return (128 * 1024 * 1024); - case AGP_I965_MSAC_GMASIZE_256: - return (256 * 1024 * 1024); - case AGP_I965_MSAC_GMASIZE_512: - return (512 * 1024 * 1024); - } - } - - /* CHIP_I855 */ - return (128 * 1024 * 1024); -} - int agp_i810_set_aperture(struct agp_softc *sc, u_int32_t aperture) { struct agp_i810_softc *isc = sc->sc_chipc; pcireg_t reg; + u_int16_t gcc1, miscc; - if (isc->chiptype == CHIP_I810) { - u_int16_t miscc; - + switch (isc->chiptype) { + case CHIP_I810: /* * Double check for sanity. */ @@ -567,9 +518,8 @@ agp_i810_set_aperture(struct agp_softc *sc, u_int32_t aperture) reg &= 0x0000ffff; reg |= ((pcireg_t)miscc) << 16; pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_I810_SMRAM, reg); - } else if (isc->chiptype == CHIP_I830) { - u_int16_t gcc1; - + break; + case CHIP_I830: if (aperture != (64 * 1024 * 1024) && aperture != (128 * 1024 * 1024)) { printf("agp: bad aperture size %d\n", aperture); @@ -586,42 +536,12 @@ agp_i810_set_aperture(struct agp_softc *sc, u_int32_t aperture) reg &= 0x0000ffff; reg |= ((pcireg_t)gcc1) << 16; pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_I830_GCC0, reg); - } else if (isc->chiptype == CHIP_I915) { - if (aperture != (128 * 1024 * 1024) && - aperture != (256 * 1024 * 1024)) { - printf("agp: bad aperture size %d\n", aperture); - return (EINVAL); - } - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_I915_MSAC); - reg &= ~AGP_I915_MSAC_GMASIZE; - if (aperture == (128 * 1024 * 1024)) - reg |= AGP_I915_MSAC_GMASIZE_128; - else - reg |= AGP_I915_MSAC_GMASIZE_256; - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_I915_MSAC, reg); - } else if (isc->chiptype == CHIP_I965) { - reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, AGP_I965_MSAC); - reg &= ~AGP_I965_MSAC_GMASIZE; - switch (aperture) { - case (128 * 1024 * 1024): - reg |= AGP_I965_MSAC_GMASIZE_128; - break; - case (256 * 1024 * 1024): - reg |= AGP_I965_MSAC_GMASIZE_256; - break; - case (512 * 1024 * 1024): - reg |= AGP_I965_MSAC_GMASIZE_512; - break; - default: - printf("agp: bad aperture size %d\n", aperture); - return (EINVAL); - } - pci_conf_write(sc->sc_pc, sc->sc_pcitag, AGP_I965_MSAC, reg); - } else { /* CHIP_I855, CHIP_G33 */ - if (aperture != (128 * 1024 * 1024)) { - printf("agp: bad aperture size %d\n", aperture); - return (EINVAL); - } + break; + case CHIP_I855: + case CHIP_I915: + case CHIP_I965: + case CHIP_G33: + return agp_generic_set_aperture(sc, aperture); } return (0); diff --git a/sys/dev/pci/agpvar.h b/sys/dev/pci/agpvar.h index 2f8b9d9a495..5c5a0de6686 100644 --- a/sys/dev/pci/agpvar.h +++ b/sys/dev/pci/agpvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: agpvar.h,v 1.11 2008/03/16 19:00:28 oga Exp $ */ +/* $OpenBSD: agpvar.h,v 1.12 2008/03/23 19:54:47 oga Exp $ */ /* $NetBSD: agpvar.h,v 1.4 2001/10/01 21:54:48 fvdl Exp $ */ /*- @@ -181,6 +181,8 @@ void agp_set_pchb(struct pci_attach_args*); int agp_find_caps(pci_chipset_tag_t, pcitag_t); 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 *); |