diff options
author | Daniel Vetter <daniel.vetter@ffwll.ch> | 2010-11-05 08:30:14 -0400 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2010-11-23 15:14:42 -0500 |
commit | 820647b97a9cbdd976c7177f1b6047fc1f6dd5c0 (patch) | |
tree | 4d0ec4a52ac3daff3cf797b3578326bb2b27954f /drivers/char/agp/intel-gtt.c | |
parent | 625dd9d331d8a1ce5ee4e9924a22f3e55b7ac615 (diff) |
intel-gtt: switch i81x to the common initialization helpers
Still a separate agp_bridge_driver because of the i81x-only
dedicated vram support.
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'drivers/char/agp/intel-gtt.c')
-rw-r--r-- | drivers/char/agp/intel-gtt.c | 198 |
1 files changed, 71 insertions, 127 deletions
diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c index 9d17a6d51640..4b79a7b47522 100644 --- a/drivers/char/agp/intel-gtt.c +++ b/drivers/char/agp/intel-gtt.c | |||
@@ -39,26 +39,10 @@ | |||
39 | #define USE_PCI_DMA_API 0 | 39 | #define USE_PCI_DMA_API 0 |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | static const struct aper_size_info_fixed intel_i810_sizes[] = | ||
43 | { | ||
44 | {64, 16384, 4}, | ||
45 | /* The 32M mode still requires a 64k gatt */ | ||
46 | {32, 8192, 4} | ||
47 | }; | ||
48 | |||
49 | #define AGP_DCACHE_MEMORY 1 | 42 | #define AGP_DCACHE_MEMORY 1 |
50 | #define AGP_PHYS_MEMORY 2 | 43 | #define AGP_PHYS_MEMORY 2 |
51 | #define INTEL_AGP_CACHED_MEMORY 3 | 44 | #define INTEL_AGP_CACHED_MEMORY 3 |
52 | 45 | ||
53 | static struct gatt_mask intel_i810_masks[] = | ||
54 | { | ||
55 | {.mask = I810_PTE_VALID, .type = 0}, | ||
56 | {.mask = (I810_PTE_VALID | I810_PTE_LOCAL), .type = AGP_DCACHE_MEMORY}, | ||
57 | {.mask = I810_PTE_VALID, .type = 0}, | ||
58 | {.mask = I810_PTE_VALID | I830_PTE_SYSTEM_CACHED, | ||
59 | .type = INTEL_AGP_CACHED_MEMORY} | ||
60 | }; | ||
61 | |||
62 | struct intel_gtt_driver { | 46 | struct intel_gtt_driver { |
63 | unsigned int gen : 8; | 47 | unsigned int gen : 8; |
64 | unsigned int is_g33 : 1; | 48 | unsigned int is_g33 : 1; |
@@ -94,6 +78,7 @@ static struct _intel_private { | |||
94 | void __iomem *i9xx_flush_page; | 78 | void __iomem *i9xx_flush_page; |
95 | void *i8xx_flush_page; | 79 | void *i8xx_flush_page; |
96 | }; | 80 | }; |
81 | char *i81x_gtt_table; | ||
97 | struct page *i8xx_page; | 82 | struct page *i8xx_page; |
98 | struct resource ifp_resource; | 83 | struct resource ifp_resource; |
99 | int resource_valid; | 84 | int resource_valid; |
@@ -163,86 +148,6 @@ static void intel_agp_unmap_memory(struct agp_memory *mem) | |||
163 | intel_agp_free_sglist(mem); | 148 | intel_agp_free_sglist(mem); |
164 | } | 149 | } |
165 | 150 | ||
166 | static int intel_i810_fetch_size(void) | ||
167 | { | ||
168 | u32 smram_miscc; | ||
169 | struct aper_size_info_fixed *values; | ||
170 | |||
171 | pci_read_config_dword(intel_private.bridge_dev, | ||
172 | I810_SMRAM_MISCC, &smram_miscc); | ||
173 | values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes); | ||
174 | |||
175 | if ((smram_miscc & I810_GMS) == I810_GMS_DISABLE) { | ||
176 | dev_warn(&intel_private.bridge_dev->dev, "i810 is disabled\n"); | ||
177 | return 0; | ||
178 | } | ||
179 | if ((smram_miscc & I810_GFX_MEM_WIN_SIZE) == I810_GFX_MEM_WIN_32M) { | ||
180 | agp_bridge->current_size = (void *) (values + 1); | ||
181 | agp_bridge->aperture_size_idx = 1; | ||
182 | intel_private.base.gtt_total_entries = KB(32) / 4; | ||
183 | return values[1].size; | ||
184 | } else { | ||
185 | agp_bridge->current_size = (void *) (values); | ||
186 | agp_bridge->aperture_size_idx = 0; | ||
187 | intel_private.base.gtt_total_entries = KB(64) / 4; | ||
188 | return values[0].size; | ||
189 | } | ||
190 | |||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | static int intel_i810_configure(void) | ||
195 | { | ||
196 | struct aper_size_info_fixed *current_size; | ||
197 | u32 temp; | ||
198 | int i; | ||
199 | |||
200 | current_size = A_SIZE_FIX(agp_bridge->current_size); | ||
201 | |||
202 | if (!intel_private.registers) { | ||
203 | pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp); | ||
204 | temp &= 0xfff80000; | ||
205 | |||
206 | intel_private.registers = ioremap(temp, 128 * 4096); | ||
207 | if (!intel_private.registers) { | ||
208 | dev_err(&intel_private.pcidev->dev, | ||
209 | "can't remap memory\n"); | ||
210 | return -ENOMEM; | ||
211 | } | ||
212 | } | ||
213 | |||
214 | intel_private.gtt = intel_private.registers + I810_PTE_BASE; | ||
215 | intel_private.scratch_page_dma = agp_bridge->scratch_page & PAGE_MASK; | ||
216 | |||
217 | if ((readl(intel_private.registers+I810_DRAM_CTL) | ||
218 | & I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) { | ||
219 | /* This will need to be dynamically assigned */ | ||
220 | dev_info(&intel_private.pcidev->dev, | ||
221 | "detected 4MB dedicated video ram\n"); | ||
222 | intel_private.num_dcache_entries = 1024; | ||
223 | } | ||
224 | pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp); | ||
225 | agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK); | ||
226 | writel(agp_bridge->gatt_bus_addr | I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL); | ||
227 | readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */ | ||
228 | |||
229 | if (agp_bridge->driver->needs_scratch_page) { | ||
230 | for (i = 0; i < current_size->num_entries; i++) { | ||
231 | writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4)); | ||
232 | } | ||
233 | readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); /* PCI posting. */ | ||
234 | } | ||
235 | global_cache_flush(); | ||
236 | return 0; | ||
237 | } | ||
238 | |||
239 | static void intel_i810_cleanup(void) | ||
240 | { | ||
241 | writel(0, intel_private.registers+I810_PGETBL_CTL); | ||
242 | readl(intel_private.registers); /* PCI Posting. */ | ||
243 | iounmap(intel_private.registers); | ||
244 | } | ||
245 | |||
246 | static void intel_fake_agp_enable(struct agp_bridge_data *bridge, u32 mode) | 151 | static void intel_fake_agp_enable(struct agp_bridge_data *bridge, u32 mode) |
247 | { | 152 | { |
248 | return; | 153 | return; |
@@ -278,6 +183,46 @@ static void i8xx_destroy_pages(struct page *page) | |||
278 | atomic_dec(&agp_bridge->current_memory_agp); | 183 | atomic_dec(&agp_bridge->current_memory_agp); |
279 | } | 184 | } |
280 | 185 | ||
186 | #define I810_GTT_ORDER 4 | ||
187 | static int i810_setup(void) | ||
188 | { | ||
189 | u32 reg_addr; | ||
190 | char *gtt_table; | ||
191 | |||
192 | /* i81x does not preallocate the gtt. It's always 64kb in size. */ | ||
193 | gtt_table = alloc_gatt_pages(I810_GTT_ORDER); | ||
194 | if (gtt_table == NULL) | ||
195 | return -ENOMEM; | ||
196 | intel_private.i81x_gtt_table = gtt_table; | ||
197 | |||
198 | pci_read_config_dword(intel_private.pcidev, I810_MMADDR, ®_addr); | ||
199 | reg_addr &= 0xfff80000; | ||
200 | |||
201 | intel_private.registers = ioremap(reg_addr, KB(64)); | ||
202 | if (!intel_private.registers) | ||
203 | return -ENOMEM; | ||
204 | |||
205 | writel(virt_to_phys(gtt_table) | I810_PGETBL_ENABLED, | ||
206 | intel_private.registers+I810_PGETBL_CTL); | ||
207 | |||
208 | intel_private.gtt_bus_addr = reg_addr + I810_PTE_BASE; | ||
209 | |||
210 | if ((readl(intel_private.registers+I810_DRAM_CTL) | ||
211 | & I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) { | ||
212 | dev_info(&intel_private.pcidev->dev, | ||
213 | "detected 4MB dedicated video ram\n"); | ||
214 | intel_private.num_dcache_entries = 1024; | ||
215 | } | ||
216 | |||
217 | return 0; | ||
218 | } | ||
219 | |||
220 | static void i810_cleanup(void) | ||
221 | { | ||
222 | writel(0, intel_private.registers+I810_PGETBL_CTL); | ||
223 | free_gatt_pages(intel_private.i81x_gtt_table, I810_GTT_ORDER); | ||
224 | } | ||
225 | |||
281 | static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start, | 226 | static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start, |
282 | int type) | 227 | int type) |
283 | { | 228 | { |
@@ -363,13 +308,6 @@ static void intel_i810_free_by_type(struct agp_memory *curr) | |||
363 | kfree(curr); | 308 | kfree(curr); |
364 | } | 309 | } |
365 | 310 | ||
366 | static unsigned long intel_i810_mask_memory(struct agp_bridge_data *bridge, | ||
367 | dma_addr_t addr, int type) | ||
368 | { | ||
369 | /* Type checking must be done elsewhere */ | ||
370 | return addr | bridge->driver->masks[type].mask; | ||
371 | } | ||
372 | |||
373 | static int intel_gtt_setup_scratch_page(void) | 311 | static int intel_gtt_setup_scratch_page(void) |
374 | { | 312 | { |
375 | struct page *page; | 313 | struct page *page; |
@@ -414,9 +352,9 @@ static void i810_write_entry(dma_addr_t addr, unsigned int entry, | |||
414 | } | 352 | } |
415 | 353 | ||
416 | static const struct aper_size_info_fixed const intel_fake_agp_sizes[] = { | 354 | static const struct aper_size_info_fixed const intel_fake_agp_sizes[] = { |
355 | {32, 8192, 3}, | ||
356 | {64, 16384, 4}, | ||
417 | {128, 32768, 5}, | 357 | {128, 32768, 5}, |
418 | /* The 64M mode still requires a 128k gatt */ | ||
419 | {64, 16384, 5}, | ||
420 | {256, 65536, 6}, | 358 | {256, 65536, 6}, |
421 | {512, 131072, 7}, | 359 | {512, 131072, 7}, |
422 | }; | 360 | }; |
@@ -429,6 +367,9 @@ static unsigned int intel_gtt_stolen_size(void) | |||
429 | static const int ddt[4] = { 0, 16, 32, 64 }; | 367 | static const int ddt[4] = { 0, 16, 32, 64 }; |
430 | unsigned int stolen_size = 0; | 368 | unsigned int stolen_size = 0; |
431 | 369 | ||
370 | if (INTEL_GTT_GEN == 1) | ||
371 | return 0; /* no stolen mem on i81x */ | ||
372 | |||
432 | pci_read_config_word(intel_private.bridge_dev, | 373 | pci_read_config_word(intel_private.bridge_dev, |
433 | I830_GMCH_CTRL, &gmch_ctrl); | 374 | I830_GMCH_CTRL, &gmch_ctrl); |
434 | 375 | ||
@@ -677,7 +618,18 @@ static unsigned int intel_gtt_mappable_entries(void) | |||
677 | { | 618 | { |
678 | unsigned int aperture_size; | 619 | unsigned int aperture_size; |
679 | 620 | ||
680 | if (INTEL_GTT_GEN == 2) { | 621 | if (INTEL_GTT_GEN == 1) { |
622 | u32 smram_miscc; | ||
623 | |||
624 | pci_read_config_dword(intel_private.bridge_dev, | ||
625 | I810_SMRAM_MISCC, &smram_miscc); | ||
626 | |||
627 | if ((smram_miscc & I810_GFX_MEM_WIN_SIZE) | ||
628 | == I810_GFX_MEM_WIN_32M) | ||
629 | aperture_size = MB(32); | ||
630 | else | ||
631 | aperture_size = MB(64); | ||
632 | } else if (INTEL_GTT_GEN == 2) { | ||
681 | u16 gmch_ctrl; | 633 | u16 gmch_ctrl; |
682 | 634 | ||
683 | pci_read_config_word(intel_private.bridge_dev, | 635 | pci_read_config_word(intel_private.bridge_dev, |
@@ -751,14 +703,7 @@ static int intel_gtt_init(void) | |||
751 | 703 | ||
752 | global_cache_flush(); /* FIXME: ? */ | 704 | global_cache_flush(); /* FIXME: ? */ |
753 | 705 | ||
754 | /* we have to call this as early as possible after the MMIO base address is known */ | ||
755 | intel_private.base.stolen_size = intel_gtt_stolen_size(); | 706 | intel_private.base.stolen_size = intel_gtt_stolen_size(); |
756 | if (intel_private.base.stolen_size == 0) { | ||
757 | intel_private.driver->cleanup(); | ||
758 | iounmap(intel_private.registers); | ||
759 | iounmap(intel_private.gtt); | ||
760 | return -ENOMEM; | ||
761 | } | ||
762 | 707 | ||
763 | ret = intel_gtt_setup_scratch_page(); | 708 | ret = intel_gtt_setup_scratch_page(); |
764 | if (ret != 0) { | 709 | if (ret != 0) { |
@@ -851,7 +796,7 @@ static bool intel_enable_gtt(void) | |||
851 | u32 gma_addr; | 796 | u32 gma_addr; |
852 | u8 __iomem *reg; | 797 | u8 __iomem *reg; |
853 | 798 | ||
854 | if (INTEL_GTT_GEN == 2) | 799 | if (INTEL_GTT_GEN <= 2) |
855 | pci_read_config_dword(intel_private.pcidev, I810_GMADDR, | 800 | pci_read_config_dword(intel_private.pcidev, I810_GMADDR, |
856 | &gma_addr); | 801 | &gma_addr); |
857 | else | 802 | else |
@@ -1268,19 +1213,16 @@ static int i9xx_setup(void) | |||
1268 | 1213 | ||
1269 | static const struct agp_bridge_driver intel_810_driver = { | 1214 | static const struct agp_bridge_driver intel_810_driver = { |
1270 | .owner = THIS_MODULE, | 1215 | .owner = THIS_MODULE, |
1271 | .aperture_sizes = intel_i810_sizes, | ||
1272 | .size_type = FIXED_APER_SIZE, | 1216 | .size_type = FIXED_APER_SIZE, |
1273 | .num_aperture_sizes = 2, | 1217 | .aperture_sizes = intel_fake_agp_sizes, |
1274 | .needs_scratch_page = true, | 1218 | .num_aperture_sizes = ARRAY_SIZE(intel_fake_agp_sizes), |
1275 | .configure = intel_i810_configure, | 1219 | .configure = intel_fake_agp_configure, |
1276 | .fetch_size = intel_i810_fetch_size, | 1220 | .fetch_size = intel_fake_agp_fetch_size, |
1277 | .cleanup = intel_i810_cleanup, | 1221 | .cleanup = intel_gtt_cleanup, |
1278 | .mask_memory = intel_i810_mask_memory, | ||
1279 | .masks = intel_i810_masks, | ||
1280 | .agp_enable = intel_fake_agp_enable, | 1222 | .agp_enable = intel_fake_agp_enable, |
1281 | .cache_flush = global_cache_flush, | 1223 | .cache_flush = global_cache_flush, |
1282 | .create_gatt_table = agp_generic_create_gatt_table, | 1224 | .create_gatt_table = intel_fake_agp_create_gatt_table, |
1283 | .free_gatt_table = agp_generic_free_gatt_table, | 1225 | .free_gatt_table = intel_fake_agp_free_gatt_table, |
1284 | .insert_memory = intel_i810_insert_entries, | 1226 | .insert_memory = intel_i810_insert_entries, |
1285 | .remove_memory = intel_fake_agp_remove_entries, | 1227 | .remove_memory = intel_fake_agp_remove_entries, |
1286 | .alloc_by_type = intel_fake_agp_alloc_by_type, | 1228 | .alloc_by_type = intel_fake_agp_alloc_by_type, |
@@ -1289,7 +1231,6 @@ static const struct agp_bridge_driver intel_810_driver = { | |||
1289 | .agp_alloc_pages = agp_generic_alloc_pages, | 1231 | .agp_alloc_pages = agp_generic_alloc_pages, |
1290 | .agp_destroy_page = agp_generic_destroy_page, | 1232 | .agp_destroy_page = agp_generic_destroy_page, |
1291 | .agp_destroy_pages = agp_generic_destroy_pages, | 1233 | .agp_destroy_pages = agp_generic_destroy_pages, |
1292 | .agp_type_to_mask_type = agp_generic_type_to_mask_type, | ||
1293 | }; | 1234 | }; |
1294 | 1235 | ||
1295 | static const struct agp_bridge_driver intel_fake_agp_driver = { | 1236 | static const struct agp_bridge_driver intel_fake_agp_driver = { |
@@ -1317,7 +1258,10 @@ static const struct agp_bridge_driver intel_fake_agp_driver = { | |||
1317 | 1258 | ||
1318 | static const struct intel_gtt_driver i81x_gtt_driver = { | 1259 | static const struct intel_gtt_driver i81x_gtt_driver = { |
1319 | .gen = 1, | 1260 | .gen = 1, |
1261 | .has_pgtbl_enable = 1, | ||
1320 | .dma_mask_size = 32, | 1262 | .dma_mask_size = 32, |
1263 | .setup = i810_setup, | ||
1264 | .cleanup = i810_cleanup, | ||
1321 | .check_flags = i830_check_flags, | 1265 | .check_flags = i830_check_flags, |
1322 | .write_entry = i810_write_entry, | 1266 | .write_entry = i810_write_entry, |
1323 | }; | 1267 | }; |
@@ -1549,8 +1493,8 @@ int intel_gmch_probe(struct pci_dev *pdev, | |||
1549 | pci_set_consistent_dma_mask(intel_private.pcidev, | 1493 | pci_set_consistent_dma_mask(intel_private.pcidev, |
1550 | DMA_BIT_MASK(mask)); | 1494 | DMA_BIT_MASK(mask)); |
1551 | 1495 | ||
1552 | if (bridge->driver == &intel_810_driver) | 1496 | /*if (bridge->driver == &intel_810_driver) |
1553 | return 1; | 1497 | return 1;*/ |
1554 | 1498 | ||
1555 | if (intel_gtt_init() != 0) | 1499 | if (intel_gtt_init() != 0) |
1556 | return 0; | 1500 | return 0; |