Index: agp_i810.c =================================================================== RCS file: /home/ncvs/src/sys/pci/agp_i810.c,v retrieving revision 1.4 diff -u -r1.4 agp_i810.c --- agp_i810.c 5 Jul 2001 21:28:47 -0000 1.4 +++ agp_i810.c 26 Apr 2002 22:44:08 -0000 @@ -57,13 +57,15 @@ MALLOC_DECLARE(M_AGP); #define READ1(off) bus_space_read_1(sc->bst, sc->bsh, off) +#define READ4(off) bus_space_read_4(sc->bst, sc->bsh, off) #define WRITE4(off,v) bus_space_write_4(sc->bst, sc->bsh, off, v) struct agp_i810_softc { struct agp_softc agp; u_int32_t initial_aperture; /* aperture size at startup */ struct agp_gatt *gatt; - u_int32_t dcache_size; + u_int32_t dcache_size; /* i810 only */ + u_int32_t stolen; /* i830 gtt entries for stolen memory */ device_t bdev; /* bridge device */ struct resource *regs; /* memory mapped GC registers */ bus_space_tag_t bst; /* bus_space tag */ @@ -89,6 +91,9 @@ case 0x11328086: return ("Intel 82815 (i815 GMCH) SVGA controller"); + + case 0x35778086: + return ("Intel 82830 (i830M GMCH) SVGA controller"); }; return NULL; @@ -116,7 +121,8 @@ break; case 0x11328086: - devid = 0x11308086; + case 0x35778086: + devid -= 0x20000; break; }; if (device_get_children(device_get_parent(dev), &children, &nchildren)) @@ -151,14 +157,26 @@ return ENXIO; } - smram = pci_read_config(bdev, AGP_I810_SMRAM, 1); - if ((smram & AGP_I810_SMRAM_GMS) - == AGP_I810_SMRAM_GMS_DISABLED) { - if (bootverbose) - printf("I810: disabled, not probing\n"); - return ENXIO; + /* + * checking whether internal graphics device has been activated. + */ + if ( 0x35778086 != pci_get_devid(dev) ) { + smram = pci_read_config(bdev, AGP_I810_SMRAM, 1); + if ((smram & AGP_I810_SMRAM_GMS) + == AGP_I810_SMRAM_GMS_DISABLED) { + if (bootverbose) + printf("I810: disabled, not probing\n"); + return ENXIO; + } + } else { /* I830MG */ + unsigned int gcc1; + gcc1 = pci_read_config(bdev, AGP_I830_GCC1, 1); + if ((gcc1 & AGP_I830_GCC1_DEV2) == AGP_I830_GCC1_DEV2_DISABLED) { + if (bootverbose) + printf("I830: disabled, not probing\n"); + return ENXIO; + } } - device_verbose(dev); device_set_desc(dev, desc); return 0; @@ -182,6 +200,7 @@ if (error) return error; + /* Same for i810 and i830 */ rid = AGP_I810_MMADR; sc->regs = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0, ~0, 1, RF_ACTIVE); @@ -194,29 +213,67 @@ sc->initial_aperture = AGP_GET_APERTURE(dev); - if (READ1(AGP_I810_DRT) & AGP_I810_DRT_POPULATED) - sc->dcache_size = 4 * 1024 * 1024; - else - sc->dcache_size = 0; - - for (;;) { - gatt = agp_alloc_gatt(dev); - if (gatt) - break; + /* Some i810s have on-chip memory called dcache */ + if ( 0x35778086 != pci_get_devid(dev) ) { + if (READ1(AGP_I810_DRT) & AGP_I810_DRT_POPULATED) + sc->dcache_size = 4 * 1024 * 1024; + else + sc->dcache_size = 0; + } - /* - * Probably contigmalloc failure. Try reducing the - * aperture so that the gatt size reduces. - */ - if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2)) { + if ( 0x35778086 != pci_get_devid(dev) ) { + /* According to the specs the gatt on the i810 must be 64k */ + gatt = malloc( sizeof(struct agp_gatt), M_AGP, M_NOWAIT); + if (!gatt) { agp_generic_detach(dev); return ENOMEM; } - } - sc->gatt = gatt; + gatt->ag_entries = AGP_GET_APERTURE(dev) >> AGP_PAGE_SHIFT; + gatt->ag_virtual = contigmalloc( 64 * 1024, M_AGP, 0, + 0, ~0, PAGE_SIZE, 0); + if (!gatt->ag_virtual) { + if (bootverbose) + device_printf(dev, "contiguous allocation failed\n"); + free(gatt, M_AGP); + agp_generic_detach(dev); + return ENOMEM; + } + bzero(gatt->ag_virtual, gatt->ag_entries * sizeof(u_int32_t)); + + gatt->ag_physical = vtophys((vm_offset_t) gatt->ag_virtual); + agp_flush_cache(); + sc->gatt = gatt; - /* Install the GATT. */ - WRITE4(AGP_I810_PGTBL_CTL, gatt->ag_physical | 1); + /* Install the GATT. */ + WRITE4(AGP_I810_PGTBL_CTL, gatt->ag_physical | 1); + } else { + /* The i830 automatically initializes the 128k gatt on boot. */ + unsigned int gcc1, pgtblctl; + + gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 1); + switch (gcc1 & AGP_I830_GCC1_GMS) { + case AGP_I830_GCC1_GMS_STOLEN_512: + sc->stolen = (512*1024)/4096; + device_printf(dev, "detected 512k stolen memory\n"); + break; + case AGP_I830_GCC1_GMS_STOLEN_1024: + sc->stolen = (1024*1024)/4096; + device_printf(dev, "detected 1024k stolen memory\n"); + break; + case AGP_I830_GCC1_GMS_STOLEN_8192: + sc->stolen = (8192*1024)/4096; + device_printf(dev, "detected 8192k stolen memory\n"); + break; + default: + device_printf(dev, "unknown memory configuration, disabling\n"); + agp_generic_detach(dev); + return EINVAL; + } + /* GATT address is already in there, make sure it's enabled */ + pgtblctl = READ4(AGP_I810_PGTBL_CTL); + pgtblctl |= 1; + WRITE4(AGP_I810_PGTBL_CTL, pgtblctl); + } /* * Make sure the chipset can see everything. @@ -242,7 +299,8 @@ /* Put the aperture back the way it started. */ AGP_SET_APERTURE(dev, sc->initial_aperture); - agp_free_gatt(sc->gatt); + contigfree(sc->gatt->ag_virtual, 64 * 1024, M_AGP); + free(sc->gatt, M_AGP); bus_release_resource(dev, SYS_RES_MEMORY, AGP_I810_MMADR, sc->regs); @@ -256,11 +314,21 @@ struct agp_i810_softc *sc = device_get_softc(dev); u_int16_t miscc; - miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2); - if ((miscc & AGP_I810_MISCC_WINSIZE) == AGP_I810_MISCC_WINSIZE_32) - return 32 * 1024 * 1024; - else - return 64 * 1024 * 1024; + if ( 0x35778086 != pci_get_devid(dev) ) { + miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2); + if ((miscc & AGP_I810_MISCC_WINSIZE) == AGP_I810_MISCC_WINSIZE_32) + return 32 * 1024 * 1024; + else + return 64 * 1024 * 1024; + } else { /* I830 */ + unsigned int gcc1; + gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 2); + if ((gcc1 & AGP_I830_GCC1_GMASIZE) == AGP_I830_GCC1_GMASIZE_128) { + return 128 * 1024 * 1024; + } else { /* (gcc1 & AGP_I830_GCC1_GMASIZE) == AGP_I830_GCC1_GMASIZE_64) */ + return 64 * 1024 * 1024; + } + } } static int @@ -269,22 +337,41 @@ struct agp_i810_softc *sc = device_get_softc(dev); u_int16_t miscc; - /* - * Double check for sanity. - */ - if (aperture != 32 * 1024 * 1024 && aperture != 64 * 1024 * 1024) { - device_printf(dev, "bad aperture size %d\n", aperture); - return EINVAL; - } + if ( 0x35778086 != pci_get_devid(dev) ) { + /* + * Double check for sanity. + */ + if (aperture != 32 * 1024 * 1024 && aperture != 64 * 1024 * 1024) { + device_printf(dev, "bad aperture size %d\n", aperture); + return EINVAL; + } - miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2); - miscc &= ~AGP_I810_MISCC_WINSIZE; - if (aperture == 32 * 1024 * 1024) - miscc |= AGP_I810_MISCC_WINSIZE_32; - else - miscc |= AGP_I810_MISCC_WINSIZE_64; + miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2); + miscc &= ~AGP_I810_MISCC_WINSIZE; + if (aperture == 32 * 1024 * 1024) + miscc |= AGP_I810_MISCC_WINSIZE_32; + else + miscc |= AGP_I810_MISCC_WINSIZE_64; + + pci_write_config(sc->bdev, AGP_I810_MISCC, miscc, 2); + + } else { /* I830 */ + unsigned int gcc1; + + if (aperture != 64 * 1024 * 1024 && aperture != 128 * 1024 * 1024) { + device_printf(dev, "bad aperture size %d\n", aperture); + return EINVAL; + } - pci_write_config(sc->bdev, AGP_I810_MISCC, miscc, 2); + gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1_GMASIZE, 2); + gcc1 &= ~AGP_I830_GCC1_GMASIZE; + if (aperture == 64 * 1024 * 1024) + gcc1 |= AGP_I830_GCC1_GMASIZE_64; + else + gcc1 |= AGP_I830_GCC1_GMASIZE_128; + + pci_write_config(sc->bdev, AGP_I830_GCC1_GMASIZE, gcc1, 2); + } return 0; } @@ -296,6 +383,12 @@ if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT)) return EINVAL; + + if ( 0x35778086 == pci_get_devid(dev) ) { + if ( (offset >> AGP_PAGE_SHIFT) < sc->stolen ) + device_printf(dev, "trying to bind into stolen memory"); + return EINVAL; + } WRITE4(AGP_I810_GTT + (offset >> AGP_PAGE_SHIFT) * 4, physical | 1); return 0; @@ -308,6 +401,12 @@ if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT)) return EINVAL; + + if ( 0x35778086 == pci_get_devid(dev) ) { + if ( (offset >> AGP_PAGE_SHIFT) < sc->stolen ) + device_printf(dev, "trying to unbind from stolen memory"); + return EINVAL; + } WRITE4(AGP_I810_GTT + (offset >> AGP_PAGE_SHIFT) * 4, 0); return 0; @@ -342,8 +441,10 @@ if (type == 1) { /* - * Mapping local DRAM into GATT. + * Mapping local DRAM into GATT. Don't deal with this on i830 yet. */ + if ( 0x35778086 == pci_get_devid(dev) ) + return 0; if (size != sc->dcache_size) return 0; } else if (type == 2) { @@ -420,6 +521,9 @@ if (mem->am_type != 1) return agp_generic_bind_memory(dev, mem, offset); + if ( 0x35778086 == pci_get_devid(dev) ) + return EINVAL; /* Don't know if this applies to i830, be cautious */ + for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) { WRITE4(AGP_I810_GTT + (offset >> AGP_PAGE_SHIFT) * 4, i | 3); @@ -436,6 +540,9 @@ if (mem->am_type != 1) return agp_generic_unbind_memory(dev, mem); + + if ( 0x35778086 == pci_get_devid(dev) ) + return EINVAL; /* Don't know if this applies to i830, be cautious */ for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) WRITE4(AGP_I810_GTT + (i >> AGP_PAGE_SHIFT) * 4, 0); Index: agpreg.h =================================================================== RCS file: /home/ncvs/src/sys/pci/agpreg.h,v retrieving revision 1.5 diff -u -r1.5 agpreg.h --- agpreg.h 7 Dec 2001 05:41:26 -0000 1.5 +++ agpreg.h 26 Apr 2002 21:31:57 -0000 @@ -161,4 +161,19 @@ #define AGP_I810_DRT_POPULATED 0x01 #define AGP_I810_GTT 0x10000 +/* + * Config registers for i830MG device 0 + */ +#define AGP_I830_GCC1 0x52 +#define AGP_I830_GCC1_DEV2 0x08 +#define AGP_I830_GCC1_DEV2_ENABLED 0x00 +#define AGP_I830_GCC1_DEV2_DISABLED 0x08 +#define AGP_I830_GCC1_GMS 0x70 +#define AGP_I830_GCC1_GMS_STOLEN_512 0x20 +#define AGP_I830_GCC1_GMS_STOLEN_1024 0x30 +#define AGP_I830_GCC1_GMS_STOLEN_8192 0x40 +#define AGP_I830_GCC1_GMASIZE 0x01 +#define AGP_I830_GCC1_GMASIZE_64 0x01 +#define AGP_I830_GCC1_GMASIZE_128 0x00 + #endif /* !_PCI_AGPREG_H_ */