diff options
author | Arjan van dev Ven <arjan@linux.intel.com> | 2008-02-05 23:16:00 -0500 |
---|---|---|
committer | Dave Airlie <airlied@linux.ie> | 2008-02-18 23:46:39 -0500 |
commit | fcea424d31868a78366ad5ee0cb3cc2a4cbe689b (patch) | |
tree | 9b3a2be661c07d8b094a5489ecafffe4befe5ec0 /drivers/char | |
parent | 16469a0ea0f6b7562eac98ebb8a7c41ce902d0b1 (diff) |
fix historic ioremap() abuse in AGP
Several AGP drivers right now use ioremap_nocache() on kernel ram in order
to turn a page of regular memory uncached.
There are two problems with this:
1) This is a total nightmare for the ioremap() implementation to keep
various mappings of the same page coherent.
2) It's a total nightmare for the AGP code since it adds a ton of
complexity in terms of keeping track of 2 different pointers to
the same thing, in terms of error handling etc etc.
This patch fixes this by making the AGP drivers use the new
set_memory_XX APIs instead.
Note: amd-k7-agp.c is built on Alpha too, and generic.c is built
on ia64 as well, which do not yet have the set_memory_*() APIs,
so for them some we have a few ugly #ifdefs - hopefully they'll
be fixed soon.
Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Dave Airlie <airlied@linux.ie>
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/agp/amd-k7-agp.c | 9 | ||||
-rw-r--r-- | drivers/char/agp/ati-agp.c | 16 | ||||
-rw-r--r-- | drivers/char/agp/generic.c | 9 | ||||
-rw-r--r-- | drivers/char/agp/sworks-agp.c | 18 |
4 files changed, 26 insertions, 26 deletions
diff --git a/drivers/char/agp/amd-k7-agp.c b/drivers/char/agp/amd-k7-agp.c index 87be46406daf..fca4d7f30443 100644 --- a/drivers/char/agp/amd-k7-agp.c +++ b/drivers/char/agp/amd-k7-agp.c | |||
@@ -41,6 +41,7 @@ static int amd_create_page_map(struct amd_page_map *page_map) | |||
41 | if (page_map->real == NULL) | 41 | if (page_map->real == NULL) |
42 | return -ENOMEM; | 42 | return -ENOMEM; |
43 | 43 | ||
44 | #ifndef CONFIG_X86 | ||
44 | SetPageReserved(virt_to_page(page_map->real)); | 45 | SetPageReserved(virt_to_page(page_map->real)); |
45 | global_cache_flush(); | 46 | global_cache_flush(); |
46 | page_map->remapped = ioremap_nocache(virt_to_gart(page_map->real), | 47 | page_map->remapped = ioremap_nocache(virt_to_gart(page_map->real), |
@@ -52,6 +53,10 @@ static int amd_create_page_map(struct amd_page_map *page_map) | |||
52 | return -ENOMEM; | 53 | return -ENOMEM; |
53 | } | 54 | } |
54 | global_cache_flush(); | 55 | global_cache_flush(); |
56 | #else | ||
57 | set_memory_uc(page_map->real, 1); | ||
58 | page_map->remapped = page_map->real; | ||
59 | #endif | ||
55 | 60 | ||
56 | for (i = 0; i < PAGE_SIZE / sizeof(unsigned long); i++) { | 61 | for (i = 0; i < PAGE_SIZE / sizeof(unsigned long); i++) { |
57 | writel(agp_bridge->scratch_page, page_map->remapped+i); | 62 | writel(agp_bridge->scratch_page, page_map->remapped+i); |
@@ -63,8 +68,12 @@ static int amd_create_page_map(struct amd_page_map *page_map) | |||
63 | 68 | ||
64 | static void amd_free_page_map(struct amd_page_map *page_map) | 69 | static void amd_free_page_map(struct amd_page_map *page_map) |
65 | { | 70 | { |
71 | #ifndef CONFIG_X86 | ||
66 | iounmap(page_map->remapped); | 72 | iounmap(page_map->remapped); |
67 | ClearPageReserved(virt_to_page(page_map->real)); | 73 | ClearPageReserved(virt_to_page(page_map->real)); |
74 | #else | ||
75 | set_memory_wb(page_map->real, 1); | ||
76 | #endif | ||
68 | free_page((unsigned long) page_map->real); | 77 | free_page((unsigned long) page_map->real); |
69 | } | 78 | } |
70 | 79 | ||
diff --git a/drivers/char/agp/ati-agp.c b/drivers/char/agp/ati-agp.c index 2d46b713c8f2..9ac3bef3bb7a 100644 --- a/drivers/char/agp/ati-agp.c +++ b/drivers/char/agp/ati-agp.c | |||
@@ -60,18 +60,9 @@ static int ati_create_page_map(struct ati_page_map *page_map) | |||
60 | if (page_map->real == NULL) | 60 | if (page_map->real == NULL) |
61 | return -ENOMEM; | 61 | return -ENOMEM; |
62 | 62 | ||
63 | SetPageReserved(virt_to_page(page_map->real)); | 63 | set_memory_uc(page_map->real, 1); |
64 | err = map_page_into_agp(virt_to_page(page_map->real)); | 64 | err = map_page_into_agp(virt_to_page(page_map->real)); |
65 | page_map->remapped = ioremap_nocache(virt_to_gart(page_map->real), | 65 | page_map->remapped = page_map->real; |
66 | PAGE_SIZE); | ||
67 | if (page_map->remapped == NULL || err) { | ||
68 | ClearPageReserved(virt_to_page(page_map->real)); | ||
69 | free_page((unsigned long) page_map->real); | ||
70 | page_map->real = NULL; | ||
71 | return -ENOMEM; | ||
72 | } | ||
73 | /*CACHE_FLUSH();*/ | ||
74 | global_cache_flush(); | ||
75 | 66 | ||
76 | for (i = 0; i < PAGE_SIZE / sizeof(unsigned long); i++) { | 67 | for (i = 0; i < PAGE_SIZE / sizeof(unsigned long); i++) { |
77 | writel(agp_bridge->scratch_page, page_map->remapped+i); | 68 | writel(agp_bridge->scratch_page, page_map->remapped+i); |
@@ -85,8 +76,7 @@ static int ati_create_page_map(struct ati_page_map *page_map) | |||
85 | static void ati_free_page_map(struct ati_page_map *page_map) | 76 | static void ati_free_page_map(struct ati_page_map *page_map) |
86 | { | 77 | { |
87 | unmap_page_from_agp(virt_to_page(page_map->real)); | 78 | unmap_page_from_agp(virt_to_page(page_map->real)); |
88 | iounmap(page_map->remapped); | 79 | set_memory_wb(page_map->real, 1); |
89 | ClearPageReserved(virt_to_page(page_map->real)); | ||
90 | free_page((unsigned long) page_map->real); | 80 | free_page((unsigned long) page_map->real); |
91 | } | 81 | } |
92 | 82 | ||
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c index 7484bc759c4c..7fc0c99a3a58 100644 --- a/drivers/char/agp/generic.c +++ b/drivers/char/agp/generic.c | |||
@@ -932,9 +932,14 @@ int agp_generic_create_gatt_table(struct agp_bridge_data *bridge) | |||
932 | agp_gatt_table = (void *)table; | 932 | agp_gatt_table = (void *)table; |
933 | 933 | ||
934 | bridge->driver->cache_flush(); | 934 | bridge->driver->cache_flush(); |
935 | #ifdef CONFIG_X86 | ||
936 | set_memory_uc((unsigned long)table, 1 << page_order); | ||
937 | bridge->gatt_table = (void *)table; | ||
938 | #else | ||
935 | bridge->gatt_table = ioremap_nocache(virt_to_gart(table), | 939 | bridge->gatt_table = ioremap_nocache(virt_to_gart(table), |
936 | (PAGE_SIZE * (1 << page_order))); | 940 | (PAGE_SIZE * (1 << page_order))); |
937 | bridge->driver->cache_flush(); | 941 | bridge->driver->cache_flush(); |
942 | #endif | ||
938 | 943 | ||
939 | if (bridge->gatt_table == NULL) { | 944 | if (bridge->gatt_table == NULL) { |
940 | for (page = virt_to_page(table); page <= virt_to_page(table_end); page++) | 945 | for (page = virt_to_page(table); page <= virt_to_page(table_end); page++) |
@@ -991,7 +996,11 @@ int agp_generic_free_gatt_table(struct agp_bridge_data *bridge) | |||
991 | * called, then all agp memory is deallocated and removed | 996 | * called, then all agp memory is deallocated and removed |
992 | * from the table. */ | 997 | * from the table. */ |
993 | 998 | ||
999 | #ifdef CONFIG_X86 | ||
1000 | set_memory_wb((unsigned long)bridge->gatt_table, 1 << page_order); | ||
1001 | #else | ||
994 | iounmap(bridge->gatt_table); | 1002 | iounmap(bridge->gatt_table); |
1003 | #endif | ||
995 | table = (char *) bridge->gatt_table_real; | 1004 | table = (char *) bridge->gatt_table_real; |
996 | table_end = table + ((PAGE_SIZE * (1 << page_order)) - 1); | 1005 | table_end = table + ((PAGE_SIZE * (1 << page_order)) - 1); |
997 | 1006 | ||
diff --git a/drivers/char/agp/sworks-agp.c b/drivers/char/agp/sworks-agp.c index 551ef25063ef..ae06f8982068 100644 --- a/drivers/char/agp/sworks-agp.c +++ b/drivers/char/agp/sworks-agp.c | |||
@@ -52,28 +52,20 @@ static int serverworks_create_page_map(struct serverworks_page_map *page_map) | |||
52 | if (page_map->real == NULL) { | 52 | if (page_map->real == NULL) { |
53 | return -ENOMEM; | 53 | return -ENOMEM; |
54 | } | 54 | } |
55 | SetPageReserved(virt_to_page(page_map->real)); | 55 | |
56 | global_cache_flush(); | 56 | set_memory_uc(page_map->real, 1); |
57 | page_map->remapped = ioremap_nocache(virt_to_gart(page_map->real), | 57 | page_map->remapped = page_map->real; |
58 | PAGE_SIZE); | ||
59 | if (page_map->remapped == NULL) { | ||
60 | ClearPageReserved(virt_to_page(page_map->real)); | ||
61 | free_page((unsigned long) page_map->real); | ||
62 | page_map->real = NULL; | ||
63 | return -ENOMEM; | ||
64 | } | ||
65 | global_cache_flush(); | ||
66 | 58 | ||
67 | for (i = 0; i < PAGE_SIZE / sizeof(unsigned long); i++) | 59 | for (i = 0; i < PAGE_SIZE / sizeof(unsigned long); i++) |
68 | writel(agp_bridge->scratch_page, page_map->remapped+i); | 60 | writel(agp_bridge->scratch_page, page_map->remapped+i); |
61 | /* Red Pen: Everyone else does pci posting flush here */ | ||
69 | 62 | ||
70 | return 0; | 63 | return 0; |
71 | } | 64 | } |
72 | 65 | ||
73 | static void serverworks_free_page_map(struct serverworks_page_map *page_map) | 66 | static void serverworks_free_page_map(struct serverworks_page_map *page_map) |
74 | { | 67 | { |
75 | iounmap(page_map->remapped); | 68 | set_memory_wb(page_map->real, 1); |
76 | ClearPageReserved(virt_to_page(page_map->real)); | ||
77 | free_page((unsigned long) page_map->real); | 69 | free_page((unsigned long) page_map->real); |
78 | } | 70 | } |
79 | 71 | ||