Index: agp_i810.c =================================================================== RCS file: /home/ncvs/src/sys/pci/agp_i810.c,v retrieving revision 1.7 diff -u -r1.7 agp_i810.c --- agp_i810.c 21 Jul 2002 04:07:26 -0000 1.7 +++ agp_i810.c 23 Jul 2002 07:22:09 -0000 @@ -57,13 +57,19 @@ 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) +#define CHIP_I810 0 /* i810/i815 */ +#define CHIP_I830 1 /* i830/i845 */ + 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; + 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 */ device_t bdev; /* bridge device */ struct resource *regs; /* memory mapped GC registers */ bus_space_tag_t bst; /* bus_space tag */ @@ -89,6 +95,12 @@ case 0x11328086: return ("Intel 82815 (i815 GMCH) SVGA controller"); + + case 0x35778086: + return ("Intel 82830 (i830M GMCH) SVGA controller"); + + case 0x25628086: + return ("Intel 82845 (i845 GMCH) SVGA controller"); }; return NULL; @@ -116,7 +128,9 @@ break; case 0x11328086: - devid = 0x11308086; + case 0x35778086: + case 0x25628086: + devid -= 0x20000; break; }; if (device_get_children(device_get_parent(dev), &children, &nchildren)) @@ -143,6 +157,7 @@ if (desc) { device_t bdev; u_int8_t smram; + int devid = pci_get_devid(dev); bdev = agp_i810_find_bridge(dev); if (!bdev) { @@ -151,12 +166,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 ( (devid != 0x35778086 ) && + (devid != 0x25628086 ) ) { + 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); @@ -182,6 +211,18 @@ if (error) return error; + switch (pci_get_devid(dev)) { + case 0x71218086: + case 0x71238086: + case 0x71258086: + case 0x11328086: + sc->chiptype = CHIP_I810; + case 0x35778086: + case 0x25628086: + sc->chiptype = CHIP_I830; + }; + + /* 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 +235,68 @@ 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; + gatt = malloc( sizeof(struct agp_gatt), M_AGP, M_NOWAIT); + if (!gatt) { + agp_generic_detach(dev); + return ENOMEM; + } + sc->gatt = gatt; - for (;;) { - gatt = agp_alloc_gatt(dev); - if (gatt) - break; + gatt->ag_entries = AGP_GET_APERTURE(dev) >> AGP_PAGE_SHIFT; - /* - * Probably contigmalloc failure. Try reducing the - * aperture so that the gatt size reduces. - */ - if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2)) { + if ( sc->chiptype == CHIP_I810 ) { + /* Some i810s have on-chip memory called dcache */ + if (READ1(AGP_I810_DRT) & AGP_I810_DRT_POPULATED) + sc->dcache_size = 4 * 1024 * 1024; + else + sc->dcache_size = 0; + + /* According to the specs the gatt on the i810 must be 64k */ + 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; } - } - sc->gatt = gatt; + bzero(gatt->ag_virtual, gatt->ag_entries * sizeof(u_int32_t)); + + gatt->ag_physical = vtophys((vm_offset_t) gatt->ag_virtual); + agp_flush_cache(); + /* 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); - /* Install the GATT. */ - WRITE4(AGP_I810_PGTBL_CTL, gatt->ag_physical | 1); + gatt->ag_physical = pgtblctl & ~1; + } /* * Make sure the chipset can see everything. @@ -237,12 +317,22 @@ return error; /* Clear the GATT base. */ - WRITE4(AGP_I810_PGTBL_CTL, 0); + if ( sc->chiptype == CHIP_I810 ) { + WRITE4(AGP_I810_PGTBL_CTL, 0); + } else { + unsigned int pgtblctl; + pgtblctl = READ4(AGP_I810_PGTBL_CTL); + pgtblctl &= ~1; + WRITE4(AGP_I810_PGTBL_CTL, pgtblctl); + } /* Put the aperture back the way it started. */ AGP_SET_APERTURE(dev, sc->initial_aperture); - agp_free_gatt(sc->gatt); + if ( sc->chiptype == CHIP_I810 ) { + 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); @@ -269,22 +359,39 @@ 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; - } - - 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; + if ( sc->chiptype == CHIP_I810 ) { + /* + * 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; + + 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; + } + 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_I810_MISCC, miscc, 2); + pci_write_config(sc->bdev, AGP_I830_GCC1_GMASIZE, gcc1, 2); + } return 0; } @@ -297,6 +404,12 @@ if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT)) return EINVAL; + if ( sc->chiptype == CHIP_I830 ) { + 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; } @@ -309,6 +422,12 @@ if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT)) return EINVAL; + if ( sc->chiptype == CHIP_I830 ) { + 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; } @@ -344,6 +463,8 @@ /* * Mapping local DRAM into GATT. */ + if ( sc->chiptype == CHIP_I830 ) + return 0; if (size != sc->dcache_size) return 0; } else if (type == 2) { @@ -426,6 +547,9 @@ if (mem->am_type != 1) return agp_generic_bind_memory(dev, mem, offset); + if ( sc->chiptype == CHIP_I830 ) + return EINVAL; + for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) { WRITE4(AGP_I810_GTT + (offset >> AGP_PAGE_SHIFT) * 4, i | 3); @@ -442,6 +566,9 @@ if (mem->am_type != 1) return agp_generic_unbind_memory(dev, mem); + + if ( sc->chiptype == CHIP_I830 ) + return EINVAL; 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 22 Jul 2002 21:05:35 -0000 @@ -160,5 +160,20 @@ #define AGP_I810_DRT_UNPOPULATED 0x00 #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_ */