30 #include <linux/module.h>
31 #include <linux/pci.h>
40 #include <linux/sched.h>
41 #include <linux/slab.h>
43 #include <asm/cacheflush.h>
44 #include <asm/pgtable.h>
72 static int agp_get_key(
void)
104 if (is_vmalloc_addr(mem->
pages)) {
113 static struct agp_memory *agp_create_user_memory(
unsigned long num_agp_pages)
116 unsigned long alloc_size = num_agp_pages*
sizeof(
struct page *);
125 new->key = agp_get_key();
134 if (new->pages ==
NULL) {
139 new->num_scratch_pages = 0;
151 new->key = agp_get_key();
160 if (new->pages ==
NULL) {
165 new->num_scratch_pages = scratch_pages;
194 if (curr->
type != 0) {
195 curr->
bridge->driver->free_by_type(curr);
199 if (curr->
bridge->driver->agp_destroy_pages) {
200 curr->
bridge->driver->agp_destroy_pages(curr);
204 curr->
bridge->driver->agp_destroy_page(
209 curr->
bridge->driver->agp_destroy_page(
221 #define ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(unsigned long))
247 (cur_memory + page_count < page_count))
258 new = bridge->
driver->alloc_by_type(page_count, type);
271 if (bridge->
driver->agp_alloc_pages) {
272 if (bridge->
driver->agp_alloc_pages(bridge,
new, page_count)) {
287 new->pages[
i] =
page;
290 new->bridge = bridge;
300 static int agp_return_size(
void)
309 current_size =
A_SIZE_8(temp)->size;
344 num_entries =
A_SIZE_8(temp)->num_entries;
347 num_entries =
A_SIZE_16(temp)->num_entries;
350 num_entries =
A_SIZE_32(temp)->num_entries;
435 curr->
bridge->driver->cache_flush();
439 ret_val = curr->
bridge->driver->insert_memory(curr, pg_start, curr->
type);
482 spin_lock(&curr->
bridge->mapped_lock);
484 spin_unlock(&curr->
bridge->mapped_lock);
494 static void agp_v2_parse_one(
u32 *requested_mode,
u32 *bridge_agpstat,
u32 *vga_agpstat)
500 *requested_mode & AGP2_RESERVED_MASK, *requested_mode);
501 *requested_mode &= ~AGP2_RESERVED_MASK;
514 switch (*bridge_agpstat & 7) {
518 "Fixing up support for x2 & x1\n");
523 "Fixing up support for x1\n");
530 tmp = *requested_mode & 7;
552 if (!((*bridge_agpstat &
AGPSTAT_SBA) && (*vga_agpstat &
AGPSTAT_SBA) && (*requested_mode & AGPSTAT_SBA)))
553 *bridge_agpstat &= ~AGPSTAT_SBA;
556 if (!((*bridge_agpstat &
AGPSTAT2_4X) && (*vga_agpstat &
AGPSTAT2_4X) && (*requested_mode & AGPSTAT2_4X)))
557 *bridge_agpstat &= ~AGPSTAT2_4X;
559 if (!((*bridge_agpstat &
AGPSTAT2_2X) && (*vga_agpstat &
AGPSTAT2_2X) && (*requested_mode & AGPSTAT2_2X)))
560 *bridge_agpstat &= ~AGPSTAT2_2X;
562 if (!((*bridge_agpstat &
AGPSTAT2_1X) && (*vga_agpstat &
AGPSTAT2_1X) && (*requested_mode & AGPSTAT2_1X)))
563 *bridge_agpstat &= ~AGPSTAT2_1X;
566 if (*bridge_agpstat & AGPSTAT2_4X)
569 if (*bridge_agpstat & AGPSTAT2_2X)
572 if (*bridge_agpstat & AGPSTAT2_1X)
580 *bridge_agpstat &= ~AGPSTAT_SBA;
588 if (*bridge_agpstat & AGPSTAT2_1X)
597 static void agp_v3_parse_one(
u32 *requested_mode,
u32 *bridge_agpstat,
u32 *vga_agpstat)
599 u32 origbridge=*bridge_agpstat, origvga=*vga_agpstat;
604 *requested_mode & AGP3_RESERVED_MASK, *requested_mode);
605 *requested_mode &= ~AGP3_RESERVED_MASK;
609 tmp = *requested_mode & 7;
616 *requested_mode = (*requested_mode & ~7) |
AGPSTAT3_8X;
643 if (*requested_mode & AGPSTAT2_4X) {
645 current->comm, *requested_mode);
646 *requested_mode &= ~AGPSTAT2_4X;
656 current->comm, *requested_mode);
657 *requested_mode &= ~(AGPSTAT2_4X | AGPSTAT2_2X |
AGPSTAT2_1X);
662 if (!(*bridge_agpstat & AGPSTAT3_8X)) {
668 if (!(*vga_agpstat & AGPSTAT3_8X)) {
690 if ((*bridge_agpstat & AGPSTAT3_8X) && (*vga_agpstat &
AGPSTAT3_8X)) {
692 "supported by bridge & card (x8).\n");
697 if (!(*bridge_agpstat & AGPSTAT3_8X)) {
699 *bridge_agpstat, origbridge);
703 if (!(*vga_agpstat & AGPSTAT3_8X)) {
705 *vga_agpstat, origvga);
718 *bridge_agpstat &= ~AGPSTAT_SBA;
757 pci_read_config_dword(device, cap_ptr+
PCI_AGP_STATUS, &vga_agpstat);
762 min_t(
u32, (bridge_agpstat & AGPSTAT_RQ_DEPTH), (vga_agpstat & AGPSTAT_RQ_DEPTH))));
767 (requested_mode & AGPSTAT_FW)))
768 bridge_agpstat &= ~AGPSTAT_FW;
772 agp_v3_parse_one(&requested_mode, &bridge_agpstat, &vga_agpstat);
774 agp_v2_parse_one(&requested_mode, &bridge_agpstat, &vga_agpstat);
777 return bridge_agpstat;
787 mode = bridge_agpstat & 0x7;
796 dev_info(&device->
dev,
"putting AGP V%d device into %dx mode\n",
797 agp_v3 ? 3 : 2, mode);
812 pci_read_config_dword(bridge->
dev, bridge->
capndx, &ncapid);
832 if (bridge_agpstat == 0)
840 if (bridge->
mode & AGPSTAT_MODE_3_0) {
848 bridge_agpstat &= ~(7<<10) ;
849 pci_read_config_dword(bridge->
dev,
852 pci_write_config_dword(bridge->
dev,
855 dev_info(&bridge->
dev->dev,
"bridge is in legacy mode, falling back to 2.x\n");
883 size = page_order = num_entries = 0;
887 switch (bridge->
driver->size_type) {
897 page_order =
A_SIZE_16(temp)->page_order;
898 num_entries =
A_SIZE_16(temp)->num_entries;
902 page_order =
A_SIZE_32(temp)->page_order;
903 num_entries =
A_SIZE_32(temp)->num_entries;
909 size = page_order = num_entries = 0;
917 switch (bridge->
driver->size_type) {
937 }
while (!table && (i < bridge->
driver->num_aperture_sizes));
951 SetPageReserved(page);
956 bridge->
driver->cache_flush();
965 bridge->
driver->cache_flush();
970 ClearPageReserved(page);
991 char *
table, *table_end;
997 switch (bridge->
driver->size_type) {
999 page_order =
A_SIZE_8(temp)->page_order;
1002 page_order =
A_SIZE_16(temp)->page_order;
1005 page_order =
A_SIZE_32(temp)->page_order;
1028 table_end = table + ((
PAGE_SIZE * (1 << page_order)) - 1);
1031 ClearPageReserved(page);
1063 switch (bridge->
driver->size_type) {
1065 num_entries =
A_SIZE_8(temp)->num_entries;
1068 num_entries =
A_SIZE_16(temp)->num_entries;
1071 num_entries =
A_SIZE_32(temp)->num_entries;
1085 if (num_entries < 0) num_entries = 0;
1087 if (type != mem->
type)
1090 mask_type = bridge->
driver->agp_type_to_mask_type(bridge, type);
1091 if (mask_type != 0) {
1096 if (((pg_start + mem->
page_count) > num_entries) ||
1109 bridge->
driver->cache_flush();
1113 for (i = 0, j = pg_start; i < mem->
page_count; i++, j++) {
1121 bridge->
driver->tlb_flush(mem);
1140 if (type != mem->
type)
1144 if (((pg_start + mem->
page_count) > num_entries) ||
1148 mask_type = bridge->
driver->agp_type_to_mask_type(bridge, type);
1149 if (mask_type != 0) {
1155 for (i = pg_start; i < (mem->
page_count + pg_start); i++) {
1160 bridge->
driver->tlb_flush(mem);
1186 new = agp_create_user_memory(page_count);
1191 new->pages[i] =
NULL;
1192 new->page_count = 0;
1194 new->num_scratch_pages = pages;
1307 bridge->
driver->agp_enable(bridge, mode);
1323 static void ipi_handler(
void *null)
1331 panic(
PFX "timed out waiting for the other CPUs!\n");
1339 if (bridge->
driver->masks)
1340 return addr | bridge->
driver->masks[0].mask;
1370 for (i = 0; i <
agp_bridge->driver->num_aperture_sizes; i++) {
1373 agp_bridge->current_size = (
void *) (values + i);
1376 return values[
i].
size;
1423 {4096, 1048576, 10,0x000},
1424 {2048, 524288, 9, 0x800},
1425 {1024, 262144, 8, 0xc00},
1426 { 512, 131072, 7, 0xe00},
1427 { 256, 65536, 6, 0xf00},
1428 { 128, 32768, 5, 0xf20},
1429 { 64, 16384, 4, 0xf30},
1430 { 32, 8192, 3, 0xf38},
1431 { 16, 4096, 2, 0xf3c},
1432 { 8, 2048, 1, 0xf3e},
1433 { 4, 1024, 0, 0xf3f}