5 #include <linux/module.h>
11 #include <linux/slab.h>
14 #define AMD_MMBASE 0x14
15 #define AMD_APSIZE 0xac
16 #define AMD_MODECNTL 0xb0
17 #define AMD_MODECNTL2 0xb2
18 #define AMD_GARTENABLE 0x02
19 #define AMD_ATTBASE 0x04
20 #define AMD_TLBFLUSH 0x0c
21 #define AMD_CACHEENTRY 0x10
30 static struct _amd_irongate_private {
34 } amd_irongate_private;
36 static int amd_create_page_map(
struct amd_page_map *page_map)
55 static void amd_free_page_map(
struct amd_page_map *page_map)
61 static void amd_free_gatt_pages(
void)
67 tables = amd_irongate_private.gatt_pages;
68 for (i = 0; i < amd_irongate_private.num_tables; i++) {
72 amd_free_page_map(entry);
77 amd_irongate_private.gatt_pages =
NULL;
80 static int amd_create_gatt_pages(
int nr_tables)
91 for (i = 0; i < nr_tables; i++) {
98 retval = amd_create_page_map(entry);
102 amd_irongate_private.num_tables =
i;
103 amd_irongate_private.gatt_pages =
tables;
106 amd_free_gatt_pages();
115 #define GET_PAGE_DIR_OFF(addr) (addr >> 22)
116 #define GET_PAGE_DIR_IDX(addr) (GET_PAGE_DIR_OFF(addr) - \
117 GET_PAGE_DIR_OFF(agp_bridge->gart_bus_addr))
118 #define GET_GATT_OFF(addr) ((addr & 0x003ff000) >> 12)
119 #define GET_GATT(addr) (amd_irongate_private.gatt_pages[\
120 GET_PAGE_DIR_IDX(addr)]->remapped)
126 unsigned long __iomem *cur_gatt;
133 retval = amd_create_page_map(&page_dir);
137 retval = amd_create_gatt_pages(value->
num_entries / 1024);
139 amd_free_page_map(&page_dir);
157 for (i = 0; i < value->
num_entries / 1024; i++, addr += 0x00400000) {
180 amd_free_gatt_pages();
181 amd_free_page_map(&page_dir);
185 static int amd_irongate_fetch_size(
void)
192 temp = (temp & 0x0000000e);
194 for (i = 0; i <
agp_bridge->driver->num_aperture_sizes; i++) {
197 agp_bridge->current_size = (
void *) (values + i);
200 return values[
i].
size;
207 static int amd_irongate_configure(
void)
215 if (!amd_irongate_private.registers) {
219 amd_irongate_private.registers = (
volatile u8 __iomem *)
ioremap(temp, 4096);
220 if (!amd_irongate_private.registers)
236 enable_reg = (enable_reg | 0x0004);
242 temp = (((temp & ~(0x0000000e)) | current_size->
size_value) | 1);
251 static void amd_irongate_cleanup(
void)
260 enable_reg = (enable_reg & ~(0x0004));
266 temp = ((temp & ~(0x0000000f)) | previous_size->
size_value);
279 static void amd_irongate_tlbflush(
struct agp_memory *temp)
288 unsigned long __iomem *cur_gatt;
293 if (type != mem->
type ||
314 for (i = 0, j = pg_start; i < mem->
page_count; i++, j++) {
323 amd_irongate_tlbflush(mem);
327 static int amd_remove_memory(
struct agp_memory *mem,
off_t pg_start,
int type)
330 unsigned long __iomem *cur_gatt;
333 if (type != mem->
type ||
337 for (i = pg_start; i < (mem->
page_count + pg_start); i++) {
344 amd_irongate_tlbflush(mem);
350 {2048, 524288, 0x0000000c},
351 {1024, 262144, 0x0000000a},
352 {512, 131072, 0x00000008},
353 {256, 65536, 0x00000006},
354 {128, 32768, 0x00000004},
355 {64, 16384, 0x00000002},
356 {32, 8192, 0x00000000}
359 static const struct gatt_mask amd_irongate_masks[] =
361 {.mask = 1, .type = 0}
366 .aperture_sizes = amd_irongate_sizes,
368 .num_aperture_sizes = 7,
369 .needs_scratch_page =
true,
370 .configure = amd_irongate_configure,
371 .fetch_size = amd_irongate_fetch_size,
372 .cleanup = amd_irongate_cleanup,
373 .tlb_flush = amd_irongate_tlbflush,
375 .masks = amd_irongate_masks,
378 .create_gatt_table = amd_create_gatt_table,
379 .free_gatt_table = amd_free_gatt_table,
380 .insert_memory = amd_insert_memory,
381 .remove_memory = amd_remove_memory,
395 .chipset_name =
"Irongate",
399 .chipset_name =
"761",
403 .chipset_name =
"760MP",
419 j = ent - agp_amdk7_pci_table;
421 amd_agp_device_ids[j].chipset_name);
427 bridge->
driver = &amd_irongate_driver;
454 dev_info(&pdev->
dev,
"AMD 751 chipset with NVidia GeForce; forcing 1X due to errata\n");
470 dev_info(&pdev->
dev,
"AMD 761 chipset with errata; disabling AGP fast writes & SBA and forcing to 1X\n");
475 pci_read_config_dword(pdev,
479 pci_set_drvdata(pdev, bridge);
501 static int agp_amdk7_resume(
struct pci_dev *pdev)
542 static struct pci_driver agp_amdk7_pci_driver = {
543 .name =
"agpgart-amdk7",
544 .id_table = agp_amdk7_pci_table,
545 .probe = agp_amdk7_probe,
546 .remove = agp_amdk7_remove,
548 .suspend = agp_amdk7_suspend,
549 .resume = agp_amdk7_resume,
553 static int __init agp_amdk7_init(
void)
557 return pci_register_driver(&agp_amdk7_pci_driver);
560 static void __exit agp_amdk7_cleanup(
void)