aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/agp/generic.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/agp/generic.c')
-rw-r--r--drivers/char/agp/generic.c58
1 files changed, 18 insertions, 40 deletions
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index d2abf5143983..b072648dc3f6 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -81,13 +81,6 @@ static int agp_get_key(void)
81 return -1; 81 return -1;
82} 82}
83 83
84void agp_flush_chipset(struct agp_bridge_data *bridge)
85{
86 if (bridge->driver->chipset_flush)
87 bridge->driver->chipset_flush(bridge);
88}
89EXPORT_SYMBOL(agp_flush_chipset);
90
91/* 84/*
92 * Use kmalloc if possible for the page list. Otherwise fall back to 85 * Use kmalloc if possible for the page list. Otherwise fall back to
93 * vmalloc. This speeds things up and also saves memory for small AGP 86 * vmalloc. This speeds things up and also saves memory for small AGP
@@ -122,6 +115,9 @@ static struct agp_memory *agp_create_user_memory(unsigned long num_agp_pages)
122 struct agp_memory *new; 115 struct agp_memory *new;
123 unsigned long alloc_size = num_agp_pages*sizeof(struct page *); 116 unsigned long alloc_size = num_agp_pages*sizeof(struct page *);
124 117
118 if (INT_MAX/sizeof(struct page *) < num_agp_pages)
119 return NULL;
120
125 new = kzalloc(sizeof(struct agp_memory), GFP_KERNEL); 121 new = kzalloc(sizeof(struct agp_memory), GFP_KERNEL);
126 if (new == NULL) 122 if (new == NULL)
127 return NULL; 123 return NULL;
@@ -241,11 +237,14 @@ struct agp_memory *agp_allocate_memory(struct agp_bridge_data *bridge,
241 int scratch_pages; 237 int scratch_pages;
242 struct agp_memory *new; 238 struct agp_memory *new;
243 size_t i; 239 size_t i;
240 int cur_memory;
244 241
245 if (!bridge) 242 if (!bridge)
246 return NULL; 243 return NULL;
247 244
248 if ((atomic_read(&bridge->current_memory_agp) + page_count) > bridge->max_memory_agp) 245 cur_memory = atomic_read(&bridge->current_memory_agp);
246 if ((cur_memory + page_count > bridge->max_memory_agp) ||
247 (cur_memory + page_count < page_count))
249 return NULL; 248 return NULL;
250 249
251 if (type >= AGP_USER_TYPES) { 250 if (type >= AGP_USER_TYPES) {
@@ -437,11 +436,6 @@ int agp_bind_memory(struct agp_memory *curr, off_t pg_start)
437 curr->is_flushed = true; 436 curr->is_flushed = true;
438 } 437 }
439 438
440 if (curr->bridge->driver->agp_map_memory) {
441 ret_val = curr->bridge->driver->agp_map_memory(curr);
442 if (ret_val)
443 return ret_val;
444 }
445 ret_val = curr->bridge->driver->insert_memory(curr, pg_start, curr->type); 439 ret_val = curr->bridge->driver->insert_memory(curr, pg_start, curr->type);
446 440
447 if (ret_val != 0) 441 if (ret_val != 0)
@@ -483,9 +477,6 @@ int agp_unbind_memory(struct agp_memory *curr)
483 if (ret_val != 0) 477 if (ret_val != 0)
484 return ret_val; 478 return ret_val;
485 479
486 if (curr->bridge->driver->agp_unmap_memory)
487 curr->bridge->driver->agp_unmap_memory(curr);
488
489 curr->is_bound = false; 480 curr->is_bound = false;
490 curr->pg_start = 0; 481 curr->pg_start = 0;
491 spin_lock(&curr->bridge->mapped_lock); 482 spin_lock(&curr->bridge->mapped_lock);
@@ -495,26 +486,6 @@ int agp_unbind_memory(struct agp_memory *curr)
495} 486}
496EXPORT_SYMBOL(agp_unbind_memory); 487EXPORT_SYMBOL(agp_unbind_memory);
497 488
498/**
499 * agp_rebind_emmory - Rewrite the entire GATT, useful on resume
500 */
501int agp_rebind_memory(void)
502{
503 struct agp_memory *curr;
504 int ret_val = 0;
505
506 spin_lock(&agp_bridge->mapped_lock);
507 list_for_each_entry(curr, &agp_bridge->mapped_list, mapped_list) {
508 ret_val = curr->bridge->driver->insert_memory(curr,
509 curr->pg_start,
510 curr->type);
511 if (ret_val != 0)
512 break;
513 }
514 spin_unlock(&agp_bridge->mapped_lock);
515 return ret_val;
516}
517EXPORT_SYMBOL(agp_rebind_memory);
518 489
519/* End - Routines for handling swapping of agp_memory into the GATT */ 490/* End - Routines for handling swapping of agp_memory into the GATT */
520 491
@@ -984,7 +955,9 @@ int agp_generic_create_gatt_table(struct agp_bridge_data *bridge)
984 955
985 bridge->driver->cache_flush(); 956 bridge->driver->cache_flush();
986#ifdef CONFIG_X86 957#ifdef CONFIG_X86
987 set_memory_uc((unsigned long)table, 1 << page_order); 958 if (set_memory_uc((unsigned long)table, 1 << page_order))
959 printk(KERN_WARNING "Could not set GATT table memory to UC!");
960
988 bridge->gatt_table = (void *)table; 961 bridge->gatt_table = (void *)table;
989#else 962#else
990 bridge->gatt_table = ioremap_nocache(virt_to_phys(table), 963 bridge->gatt_table = ioremap_nocache(virt_to_phys(table),
@@ -1122,8 +1095,8 @@ int agp_generic_insert_memory(struct agp_memory * mem, off_t pg_start, int type)
1122 return -EINVAL; 1095 return -EINVAL;
1123 } 1096 }
1124 1097
1125 /* AK: could wrap */ 1098 if (((pg_start + mem->page_count) > num_entries) ||
1126 if ((pg_start + mem->page_count) > num_entries) 1099 ((pg_start + mem->page_count) < pg_start))
1127 return -EINVAL; 1100 return -EINVAL;
1128 1101
1129 j = pg_start; 1102 j = pg_start;
@@ -1157,7 +1130,7 @@ int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
1157{ 1130{
1158 size_t i; 1131 size_t i;
1159 struct agp_bridge_data *bridge; 1132 struct agp_bridge_data *bridge;
1160 int mask_type; 1133 int mask_type, num_entries;
1161 1134
1162 bridge = mem->bridge; 1135 bridge = mem->bridge;
1163 if (!bridge) 1136 if (!bridge)
@@ -1169,6 +1142,11 @@ int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
1169 if (type != mem->type) 1142 if (type != mem->type)
1170 return -EINVAL; 1143 return -EINVAL;
1171 1144
1145 num_entries = agp_num_entries();
1146 if (((pg_start + mem->page_count) > num_entries) ||
1147 ((pg_start + mem->page_count) < pg_start))
1148 return -EINVAL;
1149
1172 mask_type = bridge->driver->agp_type_to_mask_type(bridge, type); 1150 mask_type = bridge->driver->agp_type_to_mask_type(bridge, type);
1173 if (mask_type != 0) { 1151 if (mask_type != 0) {
1174 /* The generic routines know nothing of memory types */ 1152 /* The generic routines know nothing of memory types */