Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Intel GTT (Graphics Translation Table) routines |
| 3 | * |
| 4 | * Caveat: This driver implements the linux agp interface, but this is far from |
| 5 | * a agp driver! GTT support ended up here for purely historical reasons: The |
| 6 | * old userspace intel graphics drivers needed an interface to map memory into |
| 7 | * the GTT. And the drm provides a default interface for graphic devices sitting |
| 8 | * on an agp port. So it made sense to fake the GTT support as an agp port to |
| 9 | * avoid having to create a new api. |
| 10 | * |
| 11 | * With gem this does not make much sense anymore, just needlessly complicates |
| 12 | * the code. But as long as the old graphics stack is still support, it's stuck |
| 13 | * here. |
| 14 | * |
| 15 | * /fairy-tale-mode off |
| 16 | */ |
| 17 | |
Daniel Vetter | e2404e7 | 2010-09-08 17:29:51 +0200 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/pci.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/pagemap.h> |
| 23 | #include <linux/agp_backend.h> |
| 24 | #include <asm/smp.h> |
| 25 | #include "agp.h" |
| 26 | #include "intel-agp.h" |
Daniel Vetter | 0ade638 | 2010-08-24 22:18:41 +0200 | [diff] [blame] | 27 | #include <drm/intel-gtt.h> |
Daniel Vetter | e2404e7 | 2010-09-08 17:29:51 +0200 | [diff] [blame] | 28 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 29 | /* |
| 30 | * If we have Intel graphics, we're not going to have anything other than |
| 31 | * an Intel IOMMU. So make the correct use of the PCI DMA API contingent |
| 32 | * on the Intel IOMMU support (CONFIG_DMAR). |
| 33 | * Only newer chipsets need to bother with this, of course. |
| 34 | */ |
| 35 | #ifdef CONFIG_DMAR |
| 36 | #define USE_PCI_DMA_API 1 |
Daniel Vetter | 0e87d2b | 2010-09-07 22:11:15 +0200 | [diff] [blame] | 37 | #else |
| 38 | #define USE_PCI_DMA_API 0 |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 39 | #endif |
| 40 | |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 41 | struct intel_gtt_driver { |
| 42 | unsigned int gen : 8; |
| 43 | unsigned int is_g33 : 1; |
| 44 | unsigned int is_pineview : 1; |
| 45 | unsigned int is_ironlake : 1; |
Chris Wilson | 100519e | 2010-10-31 10:37:02 +0000 | [diff] [blame] | 46 | unsigned int has_pgtbl_enable : 1; |
Daniel Vetter | 22533b4 | 2010-09-12 16:38:55 +0200 | [diff] [blame] | 47 | unsigned int dma_mask_size : 8; |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame] | 48 | /* Chipset specific GTT setup */ |
| 49 | int (*setup)(void); |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 50 | /* This should undo anything done in ->setup() save the unmapping |
| 51 | * of the mmio register file, that's done in the generic code. */ |
| 52 | void (*cleanup)(void); |
Daniel Vetter | 351bb27 | 2010-09-07 22:41:04 +0200 | [diff] [blame] | 53 | void (*write_entry)(dma_addr_t addr, unsigned int entry, unsigned int flags); |
| 54 | /* Flags is a more or less chipset specific opaque value. |
| 55 | * For chipsets that need to support old ums (non-gem) code, this |
| 56 | * needs to be identical to the various supported agp memory types! */ |
Daniel Vetter | 5cbecaf | 2010-09-11 21:31:04 +0200 | [diff] [blame] | 57 | bool (*check_flags)(unsigned int flags); |
Daniel Vetter | 1b263f2 | 2010-09-12 00:27:24 +0200 | [diff] [blame] | 58 | void (*chipset_flush)(void); |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 59 | }; |
| 60 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 61 | static struct _intel_private { |
Daniel Vetter | 0ade638 | 2010-08-24 22:18:41 +0200 | [diff] [blame] | 62 | struct intel_gtt base; |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 63 | const struct intel_gtt_driver *driver; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 64 | struct pci_dev *pcidev; /* device one */ |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 65 | struct pci_dev *bridge_dev; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 66 | u8 __iomem *registers; |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 67 | phys_addr_t gtt_bus_addr; |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame] | 68 | phys_addr_t gma_bus_addr; |
Daniel Vetter | b3eafc5 | 2010-09-23 20:04:17 +0200 | [diff] [blame] | 69 | u32 PGETBL_save; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 70 | u32 __iomem *gtt; /* I915G */ |
| 71 | int num_dcache_entries; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 72 | union { |
| 73 | void __iomem *i9xx_flush_page; |
| 74 | void *i8xx_flush_page; |
| 75 | }; |
Daniel Vetter | 820647b | 2010-11-05 13:30:14 +0100 | [diff] [blame] | 76 | char *i81x_gtt_table; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 77 | struct page *i8xx_page; |
| 78 | struct resource ifp_resource; |
| 79 | int resource_valid; |
Daniel Vetter | 0e87d2b | 2010-09-07 22:11:15 +0200 | [diff] [blame] | 80 | struct page *scratch_page; |
| 81 | dma_addr_t scratch_page_dma; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 82 | } intel_private; |
| 83 | |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 84 | #define INTEL_GTT_GEN intel_private.driver->gen |
| 85 | #define IS_G33 intel_private.driver->is_g33 |
| 86 | #define IS_PINEVIEW intel_private.driver->is_pineview |
| 87 | #define IS_IRONLAKE intel_private.driver->is_ironlake |
Chris Wilson | 100519e | 2010-10-31 10:37:02 +0000 | [diff] [blame] | 88 | #define HAS_PGTBL_EN intel_private.driver->has_pgtbl_enable |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 89 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 90 | int intel_gtt_map_memory(struct page **pages, unsigned int num_entries, |
| 91 | struct scatterlist **sg_list, int *num_sg) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 92 | { |
| 93 | struct sg_table st; |
| 94 | struct scatterlist *sg; |
| 95 | int i; |
| 96 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 97 | if (*sg_list) |
Daniel Vetter | fefaa70 | 2010-09-11 22:12:11 +0200 | [diff] [blame] | 98 | return 0; /* already mapped (for e.g. resume */ |
| 99 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 100 | DBG("try mapping %lu pages\n", (unsigned long)num_entries); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 101 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 102 | if (sg_alloc_table(&st, num_entries, GFP_KERNEL)) |
Chris Wilson | 831cd44 | 2010-07-24 18:29:37 +0100 | [diff] [blame] | 103 | goto err; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 104 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 105 | *sg_list = sg = st.sgl; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 106 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 107 | for (i = 0 ; i < num_entries; i++, sg = sg_next(sg)) |
| 108 | sg_set_page(sg, pages[i], PAGE_SIZE, 0); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 109 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 110 | *num_sg = pci_map_sg(intel_private.pcidev, *sg_list, |
| 111 | num_entries, PCI_DMA_BIDIRECTIONAL); |
| 112 | if (unlikely(!*num_sg)) |
Chris Wilson | 831cd44 | 2010-07-24 18:29:37 +0100 | [diff] [blame] | 113 | goto err; |
| 114 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 115 | return 0; |
Chris Wilson | 831cd44 | 2010-07-24 18:29:37 +0100 | [diff] [blame] | 116 | |
| 117 | err: |
| 118 | sg_free_table(&st); |
| 119 | return -ENOMEM; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 120 | } |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 121 | EXPORT_SYMBOL(intel_gtt_map_memory); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 122 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 123 | void intel_gtt_unmap_memory(struct scatterlist *sg_list, int num_sg) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 124 | { |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 125 | struct sg_table st; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 126 | DBG("try unmapping %lu pages\n", (unsigned long)mem->page_count); |
| 127 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 128 | pci_unmap_sg(intel_private.pcidev, sg_list, |
| 129 | num_sg, PCI_DMA_BIDIRECTIONAL); |
| 130 | |
| 131 | st.sgl = sg_list; |
| 132 | st.orig_nents = st.nents = num_sg; |
| 133 | |
| 134 | sg_free_table(&st); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 135 | } |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 136 | EXPORT_SYMBOL(intel_gtt_unmap_memory); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 137 | |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 138 | static void intel_fake_agp_enable(struct agp_bridge_data *bridge, u32 mode) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 139 | { |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | /* Exists to support ARGB cursors */ |
| 144 | static struct page *i8xx_alloc_pages(void) |
| 145 | { |
| 146 | struct page *page; |
| 147 | |
| 148 | page = alloc_pages(GFP_KERNEL | GFP_DMA32, 2); |
| 149 | if (page == NULL) |
| 150 | return NULL; |
| 151 | |
| 152 | if (set_pages_uc(page, 4) < 0) { |
| 153 | set_pages_wb(page, 4); |
| 154 | __free_pages(page, 2); |
| 155 | return NULL; |
| 156 | } |
| 157 | get_page(page); |
| 158 | atomic_inc(&agp_bridge->current_memory_agp); |
| 159 | return page; |
| 160 | } |
| 161 | |
| 162 | static void i8xx_destroy_pages(struct page *page) |
| 163 | { |
| 164 | if (page == NULL) |
| 165 | return; |
| 166 | |
| 167 | set_pages_wb(page, 4); |
| 168 | put_page(page); |
| 169 | __free_pages(page, 2); |
| 170 | atomic_dec(&agp_bridge->current_memory_agp); |
| 171 | } |
| 172 | |
Daniel Vetter | 820647b | 2010-11-05 13:30:14 +0100 | [diff] [blame] | 173 | #define I810_GTT_ORDER 4 |
| 174 | static int i810_setup(void) |
| 175 | { |
| 176 | u32 reg_addr; |
| 177 | char *gtt_table; |
| 178 | |
| 179 | /* i81x does not preallocate the gtt. It's always 64kb in size. */ |
| 180 | gtt_table = alloc_gatt_pages(I810_GTT_ORDER); |
| 181 | if (gtt_table == NULL) |
| 182 | return -ENOMEM; |
| 183 | intel_private.i81x_gtt_table = gtt_table; |
| 184 | |
| 185 | pci_read_config_dword(intel_private.pcidev, I810_MMADDR, ®_addr); |
| 186 | reg_addr &= 0xfff80000; |
| 187 | |
| 188 | intel_private.registers = ioremap(reg_addr, KB(64)); |
| 189 | if (!intel_private.registers) |
| 190 | return -ENOMEM; |
| 191 | |
| 192 | writel(virt_to_phys(gtt_table) | I810_PGETBL_ENABLED, |
| 193 | intel_private.registers+I810_PGETBL_CTL); |
| 194 | |
| 195 | intel_private.gtt_bus_addr = reg_addr + I810_PTE_BASE; |
| 196 | |
| 197 | if ((readl(intel_private.registers+I810_DRAM_CTL) |
| 198 | & I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) { |
| 199 | dev_info(&intel_private.pcidev->dev, |
| 200 | "detected 4MB dedicated video ram\n"); |
| 201 | intel_private.num_dcache_entries = 1024; |
| 202 | } |
| 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | static void i810_cleanup(void) |
| 208 | { |
| 209 | writel(0, intel_private.registers+I810_PGETBL_CTL); |
| 210 | free_gatt_pages(intel_private.i81x_gtt_table, I810_GTT_ORDER); |
| 211 | } |
| 212 | |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 213 | static int i810_insert_dcache_entries(struct agp_memory *mem, off_t pg_start, |
| 214 | int type) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 215 | { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 216 | int i; |
| 217 | |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 218 | if ((pg_start + mem->page_count) |
| 219 | > intel_private.num_dcache_entries) |
| 220 | return -EINVAL; |
Daniel Vetter | 625dd9d | 2010-11-04 20:07:57 +0100 | [diff] [blame] | 221 | |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 222 | if (!mem->is_flushed) |
| 223 | global_cache_flush(); |
Daniel Vetter | 625dd9d | 2010-11-04 20:07:57 +0100 | [diff] [blame] | 224 | |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 225 | for (i = pg_start; i < (pg_start + mem->page_count); i++) { |
| 226 | dma_addr_t addr = i << PAGE_SHIFT; |
| 227 | intel_private.driver->write_entry(addr, |
| 228 | i, type); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 229 | } |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 230 | readl(intel_private.gtt+i-1); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 231 | |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 232 | return 0; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /* |
| 236 | * The i810/i830 requires a physical address to program its mouse |
| 237 | * pointer into hardware. |
| 238 | * However the Xserver still writes to it through the agp aperture. |
| 239 | */ |
| 240 | static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type) |
| 241 | { |
| 242 | struct agp_memory *new; |
| 243 | struct page *page; |
| 244 | |
| 245 | switch (pg_count) { |
| 246 | case 1: page = agp_bridge->driver->agp_alloc_page(agp_bridge); |
| 247 | break; |
| 248 | case 4: |
| 249 | /* kludge to get 4 physical pages for ARGB cursor */ |
| 250 | page = i8xx_alloc_pages(); |
| 251 | break; |
| 252 | default: |
| 253 | return NULL; |
| 254 | } |
| 255 | |
| 256 | if (page == NULL) |
| 257 | return NULL; |
| 258 | |
| 259 | new = agp_create_memory(pg_count); |
| 260 | if (new == NULL) |
| 261 | return NULL; |
| 262 | |
| 263 | new->pages[0] = page; |
| 264 | if (pg_count == 4) { |
| 265 | /* kludge to get 4 physical pages for ARGB cursor */ |
| 266 | new->pages[1] = new->pages[0] + 1; |
| 267 | new->pages[2] = new->pages[1] + 1; |
| 268 | new->pages[3] = new->pages[2] + 1; |
| 269 | } |
| 270 | new->page_count = pg_count; |
| 271 | new->num_scratch_pages = pg_count; |
| 272 | new->type = AGP_PHYS_MEMORY; |
| 273 | new->physical = page_to_phys(new->pages[0]); |
| 274 | return new; |
| 275 | } |
| 276 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 277 | static void intel_i810_free_by_type(struct agp_memory *curr) |
| 278 | { |
| 279 | agp_free_key(curr->key); |
| 280 | if (curr->type == AGP_PHYS_MEMORY) { |
| 281 | if (curr->page_count == 4) |
| 282 | i8xx_destroy_pages(curr->pages[0]); |
| 283 | else { |
| 284 | agp_bridge->driver->agp_destroy_page(curr->pages[0], |
| 285 | AGP_PAGE_DESTROY_UNMAP); |
| 286 | agp_bridge->driver->agp_destroy_page(curr->pages[0], |
| 287 | AGP_PAGE_DESTROY_FREE); |
| 288 | } |
| 289 | agp_free_page_array(curr); |
| 290 | } |
| 291 | kfree(curr); |
| 292 | } |
| 293 | |
Daniel Vetter | 0e87d2b | 2010-09-07 22:11:15 +0200 | [diff] [blame] | 294 | static int intel_gtt_setup_scratch_page(void) |
| 295 | { |
| 296 | struct page *page; |
| 297 | dma_addr_t dma_addr; |
| 298 | |
| 299 | page = alloc_page(GFP_KERNEL | GFP_DMA32 | __GFP_ZERO); |
| 300 | if (page == NULL) |
| 301 | return -ENOMEM; |
| 302 | get_page(page); |
| 303 | set_pages_uc(page, 1); |
| 304 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 305 | if (intel_private.base.needs_dmar) { |
Daniel Vetter | 0e87d2b | 2010-09-07 22:11:15 +0200 | [diff] [blame] | 306 | dma_addr = pci_map_page(intel_private.pcidev, page, 0, |
| 307 | PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); |
| 308 | if (pci_dma_mapping_error(intel_private.pcidev, dma_addr)) |
| 309 | return -EINVAL; |
| 310 | |
| 311 | intel_private.scratch_page_dma = dma_addr; |
| 312 | } else |
| 313 | intel_private.scratch_page_dma = page_to_phys(page); |
| 314 | |
| 315 | intel_private.scratch_page = page; |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
Daniel Vetter | 625dd9d | 2010-11-04 20:07:57 +0100 | [diff] [blame] | 320 | static void i810_write_entry(dma_addr_t addr, unsigned int entry, |
| 321 | unsigned int flags) |
| 322 | { |
| 323 | u32 pte_flags = I810_PTE_VALID; |
| 324 | |
| 325 | switch (flags) { |
| 326 | case AGP_DCACHE_MEMORY: |
| 327 | pte_flags |= I810_PTE_LOCAL; |
| 328 | break; |
| 329 | case AGP_USER_CACHED_MEMORY: |
| 330 | pte_flags |= I830_PTE_SYSTEM_CACHED; |
| 331 | break; |
| 332 | } |
| 333 | |
| 334 | writel(addr | pte_flags, intel_private.gtt + entry); |
| 335 | } |
| 336 | |
Chris Wilson | 7bdc9ab | 2010-11-09 17:53:20 +0000 | [diff] [blame^] | 337 | static const struct aper_size_info_fixed intel_fake_agp_sizes[] = { |
Daniel Vetter | 820647b | 2010-11-05 13:30:14 +0100 | [diff] [blame] | 338 | {32, 8192, 3}, |
| 339 | {64, 16384, 4}, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 340 | {128, 32768, 5}, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 341 | {256, 65536, 6}, |
| 342 | {512, 131072, 7}, |
| 343 | }; |
| 344 | |
Chris Wilson | c64f7ba | 2010-11-23 14:24:24 +0000 | [diff] [blame] | 345 | static unsigned int intel_gtt_stolen_size(void) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 346 | { |
| 347 | u16 gmch_ctrl; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 348 | u8 rdct; |
| 349 | int local = 0; |
| 350 | static const int ddt[4] = { 0, 16, 32, 64 }; |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 351 | unsigned int stolen_size = 0; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 352 | |
Daniel Vetter | 820647b | 2010-11-05 13:30:14 +0100 | [diff] [blame] | 353 | if (INTEL_GTT_GEN == 1) |
| 354 | return 0; /* no stolen mem on i81x */ |
| 355 | |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 356 | pci_read_config_word(intel_private.bridge_dev, |
| 357 | I830_GMCH_CTRL, &gmch_ctrl); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 358 | |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 359 | if (intel_private.bridge_dev->device == PCI_DEVICE_ID_INTEL_82830_HB || |
| 360 | intel_private.bridge_dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 361 | switch (gmch_ctrl & I830_GMCH_GMS_MASK) { |
| 362 | case I830_GMCH_GMS_STOLEN_512: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 363 | stolen_size = KB(512); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 364 | break; |
| 365 | case I830_GMCH_GMS_STOLEN_1024: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 366 | stolen_size = MB(1); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 367 | break; |
| 368 | case I830_GMCH_GMS_STOLEN_8192: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 369 | stolen_size = MB(8); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 370 | break; |
| 371 | case I830_GMCH_GMS_LOCAL: |
| 372 | rdct = readb(intel_private.registers+I830_RDRAM_CHANNEL_TYPE); |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 373 | stolen_size = (I830_RDRAM_ND(rdct) + 1) * |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 374 | MB(ddt[I830_RDRAM_DDT(rdct)]); |
| 375 | local = 1; |
| 376 | break; |
| 377 | default: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 378 | stolen_size = 0; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 379 | break; |
| 380 | } |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 381 | } else if (INTEL_GTT_GEN == 6) { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 382 | /* |
| 383 | * SandyBridge has new memory control reg at 0x50.w |
| 384 | */ |
| 385 | u16 snb_gmch_ctl; |
| 386 | pci_read_config_word(intel_private.pcidev, SNB_GMCH_CTRL, &snb_gmch_ctl); |
| 387 | switch (snb_gmch_ctl & SNB_GMCH_GMS_STOLEN_MASK) { |
| 388 | case SNB_GMCH_GMS_STOLEN_32M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 389 | stolen_size = MB(32); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 390 | break; |
| 391 | case SNB_GMCH_GMS_STOLEN_64M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 392 | stolen_size = MB(64); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 393 | break; |
| 394 | case SNB_GMCH_GMS_STOLEN_96M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 395 | stolen_size = MB(96); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 396 | break; |
| 397 | case SNB_GMCH_GMS_STOLEN_128M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 398 | stolen_size = MB(128); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 399 | break; |
| 400 | case SNB_GMCH_GMS_STOLEN_160M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 401 | stolen_size = MB(160); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 402 | break; |
| 403 | case SNB_GMCH_GMS_STOLEN_192M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 404 | stolen_size = MB(192); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 405 | break; |
| 406 | case SNB_GMCH_GMS_STOLEN_224M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 407 | stolen_size = MB(224); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 408 | break; |
| 409 | case SNB_GMCH_GMS_STOLEN_256M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 410 | stolen_size = MB(256); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 411 | break; |
| 412 | case SNB_GMCH_GMS_STOLEN_288M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 413 | stolen_size = MB(288); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 414 | break; |
| 415 | case SNB_GMCH_GMS_STOLEN_320M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 416 | stolen_size = MB(320); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 417 | break; |
| 418 | case SNB_GMCH_GMS_STOLEN_352M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 419 | stolen_size = MB(352); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 420 | break; |
| 421 | case SNB_GMCH_GMS_STOLEN_384M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 422 | stolen_size = MB(384); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 423 | break; |
| 424 | case SNB_GMCH_GMS_STOLEN_416M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 425 | stolen_size = MB(416); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 426 | break; |
| 427 | case SNB_GMCH_GMS_STOLEN_448M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 428 | stolen_size = MB(448); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 429 | break; |
| 430 | case SNB_GMCH_GMS_STOLEN_480M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 431 | stolen_size = MB(480); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 432 | break; |
| 433 | case SNB_GMCH_GMS_STOLEN_512M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 434 | stolen_size = MB(512); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 435 | break; |
| 436 | } |
| 437 | } else { |
| 438 | switch (gmch_ctrl & I855_GMCH_GMS_MASK) { |
| 439 | case I855_GMCH_GMS_STOLEN_1M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 440 | stolen_size = MB(1); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 441 | break; |
| 442 | case I855_GMCH_GMS_STOLEN_4M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 443 | stolen_size = MB(4); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 444 | break; |
| 445 | case I855_GMCH_GMS_STOLEN_8M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 446 | stolen_size = MB(8); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 447 | break; |
| 448 | case I855_GMCH_GMS_STOLEN_16M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 449 | stolen_size = MB(16); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 450 | break; |
| 451 | case I855_GMCH_GMS_STOLEN_32M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 452 | stolen_size = MB(32); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 453 | break; |
| 454 | case I915_GMCH_GMS_STOLEN_48M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 455 | stolen_size = MB(48); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 456 | break; |
| 457 | case I915_GMCH_GMS_STOLEN_64M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 458 | stolen_size = MB(64); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 459 | break; |
| 460 | case G33_GMCH_GMS_STOLEN_128M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 461 | stolen_size = MB(128); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 462 | break; |
| 463 | case G33_GMCH_GMS_STOLEN_256M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 464 | stolen_size = MB(256); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 465 | break; |
| 466 | case INTEL_GMCH_GMS_STOLEN_96M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 467 | stolen_size = MB(96); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 468 | break; |
| 469 | case INTEL_GMCH_GMS_STOLEN_160M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 470 | stolen_size = MB(160); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 471 | break; |
| 472 | case INTEL_GMCH_GMS_STOLEN_224M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 473 | stolen_size = MB(224); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 474 | break; |
| 475 | case INTEL_GMCH_GMS_STOLEN_352M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 476 | stolen_size = MB(352); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 477 | break; |
| 478 | default: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 479 | stolen_size = 0; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 480 | break; |
| 481 | } |
| 482 | } |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 483 | |
Chris Wilson | 1b6064d | 2010-11-23 12:33:54 +0000 | [diff] [blame] | 484 | if (stolen_size > 0) { |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 485 | dev_info(&intel_private.bridge_dev->dev, "detected %dK %s memory\n", |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 486 | stolen_size / KB(1), local ? "local" : "stolen"); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 487 | } else { |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 488 | dev_info(&intel_private.bridge_dev->dev, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 489 | "no pre-allocated video memory detected\n"); |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 490 | stolen_size = 0; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 491 | } |
| 492 | |
Chris Wilson | c64f7ba | 2010-11-23 14:24:24 +0000 | [diff] [blame] | 493 | return stolen_size; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 494 | } |
| 495 | |
Daniel Vetter | 2017284 | 2010-09-24 18:25:59 +0200 | [diff] [blame] | 496 | static void i965_adjust_pgetbl_size(unsigned int size_flag) |
| 497 | { |
| 498 | u32 pgetbl_ctl, pgetbl_ctl2; |
| 499 | |
| 500 | /* ensure that ppgtt is disabled */ |
| 501 | pgetbl_ctl2 = readl(intel_private.registers+I965_PGETBL_CTL2); |
| 502 | pgetbl_ctl2 &= ~I810_PGETBL_ENABLED; |
| 503 | writel(pgetbl_ctl2, intel_private.registers+I965_PGETBL_CTL2); |
| 504 | |
| 505 | /* write the new ggtt size */ |
| 506 | pgetbl_ctl = readl(intel_private.registers+I810_PGETBL_CTL); |
| 507 | pgetbl_ctl &= ~I965_PGETBL_SIZE_MASK; |
| 508 | pgetbl_ctl |= size_flag; |
| 509 | writel(pgetbl_ctl, intel_private.registers+I810_PGETBL_CTL); |
| 510 | } |
| 511 | |
| 512 | static unsigned int i965_gtt_total_entries(void) |
| 513 | { |
| 514 | int size; |
| 515 | u32 pgetbl_ctl; |
| 516 | u16 gmch_ctl; |
| 517 | |
| 518 | pci_read_config_word(intel_private.bridge_dev, |
| 519 | I830_GMCH_CTRL, &gmch_ctl); |
| 520 | |
| 521 | if (INTEL_GTT_GEN == 5) { |
| 522 | switch (gmch_ctl & G4x_GMCH_SIZE_MASK) { |
| 523 | case G4x_GMCH_SIZE_1M: |
| 524 | case G4x_GMCH_SIZE_VT_1M: |
| 525 | i965_adjust_pgetbl_size(I965_PGETBL_SIZE_1MB); |
| 526 | break; |
| 527 | case G4x_GMCH_SIZE_VT_1_5M: |
| 528 | i965_adjust_pgetbl_size(I965_PGETBL_SIZE_1_5MB); |
| 529 | break; |
| 530 | case G4x_GMCH_SIZE_2M: |
| 531 | case G4x_GMCH_SIZE_VT_2M: |
| 532 | i965_adjust_pgetbl_size(I965_PGETBL_SIZE_2MB); |
| 533 | break; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | pgetbl_ctl = readl(intel_private.registers+I810_PGETBL_CTL); |
| 538 | |
| 539 | switch (pgetbl_ctl & I965_PGETBL_SIZE_MASK) { |
| 540 | case I965_PGETBL_SIZE_128KB: |
| 541 | size = KB(128); |
| 542 | break; |
| 543 | case I965_PGETBL_SIZE_256KB: |
| 544 | size = KB(256); |
| 545 | break; |
| 546 | case I965_PGETBL_SIZE_512KB: |
| 547 | size = KB(512); |
| 548 | break; |
| 549 | /* GTT pagetable sizes bigger than 512KB are not possible on G33! */ |
| 550 | case I965_PGETBL_SIZE_1MB: |
| 551 | size = KB(1024); |
| 552 | break; |
| 553 | case I965_PGETBL_SIZE_2MB: |
| 554 | size = KB(2048); |
| 555 | break; |
| 556 | case I965_PGETBL_SIZE_1_5MB: |
| 557 | size = KB(1024 + 512); |
| 558 | break; |
| 559 | default: |
| 560 | dev_info(&intel_private.pcidev->dev, |
| 561 | "unknown page table size, assuming 512KB\n"); |
| 562 | size = KB(512); |
| 563 | } |
| 564 | |
| 565 | return size/4; |
| 566 | } |
| 567 | |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 568 | static unsigned int intel_gtt_total_entries(void) |
| 569 | { |
| 570 | int size; |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 571 | |
Daniel Vetter | 2017284 | 2010-09-24 18:25:59 +0200 | [diff] [blame] | 572 | if (IS_G33 || INTEL_GTT_GEN == 4 || INTEL_GTT_GEN == 5) |
| 573 | return i965_gtt_total_entries(); |
| 574 | else if (INTEL_GTT_GEN == 6) { |
Daniel Vetter | 210b23c | 2010-08-28 16:14:32 +0200 | [diff] [blame] | 575 | u16 snb_gmch_ctl; |
| 576 | |
| 577 | pci_read_config_word(intel_private.pcidev, SNB_GMCH_CTRL, &snb_gmch_ctl); |
| 578 | switch (snb_gmch_ctl & SNB_GTT_SIZE_MASK) { |
| 579 | default: |
| 580 | case SNB_GTT_SIZE_0M: |
| 581 | printk(KERN_ERR "Bad GTT size mask: 0x%04x.\n", snb_gmch_ctl); |
| 582 | size = MB(0); |
| 583 | break; |
| 584 | case SNB_GTT_SIZE_1M: |
| 585 | size = MB(1); |
| 586 | break; |
| 587 | case SNB_GTT_SIZE_2M: |
| 588 | size = MB(2); |
| 589 | break; |
| 590 | } |
| 591 | return size/4; |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 592 | } else { |
| 593 | /* On previous hardware, the GTT size was just what was |
| 594 | * required to map the aperture. |
| 595 | */ |
Daniel Vetter | e5e408f | 2010-08-28 11:04:32 +0200 | [diff] [blame] | 596 | return intel_private.base.gtt_mappable_entries; |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 597 | } |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 598 | } |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 599 | |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 600 | static unsigned int intel_gtt_mappable_entries(void) |
| 601 | { |
| 602 | unsigned int aperture_size; |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 603 | |
Daniel Vetter | 820647b | 2010-11-05 13:30:14 +0100 | [diff] [blame] | 604 | if (INTEL_GTT_GEN == 1) { |
| 605 | u32 smram_miscc; |
| 606 | |
| 607 | pci_read_config_dword(intel_private.bridge_dev, |
| 608 | I810_SMRAM_MISCC, &smram_miscc); |
| 609 | |
| 610 | if ((smram_miscc & I810_GFX_MEM_WIN_SIZE) |
| 611 | == I810_GFX_MEM_WIN_32M) |
| 612 | aperture_size = MB(32); |
| 613 | else |
| 614 | aperture_size = MB(64); |
| 615 | } else if (INTEL_GTT_GEN == 2) { |
Chris Wilson | b1c5b0f | 2010-09-14 19:30:13 +0100 | [diff] [blame] | 616 | u16 gmch_ctrl; |
| 617 | |
| 618 | pci_read_config_word(intel_private.bridge_dev, |
| 619 | I830_GMCH_CTRL, &gmch_ctrl); |
| 620 | |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 621 | if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_64M) |
Chris Wilson | b1c5b0f | 2010-09-14 19:30:13 +0100 | [diff] [blame] | 622 | aperture_size = MB(64); |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 623 | else |
Chris Wilson | b1c5b0f | 2010-09-14 19:30:13 +0100 | [diff] [blame] | 624 | aperture_size = MB(128); |
Daniel Vetter | 239918f | 2010-08-31 22:30:43 +0200 | [diff] [blame] | 625 | } else { |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 626 | /* 9xx supports large sizes, just look at the length */ |
| 627 | aperture_size = pci_resource_len(intel_private.pcidev, 2); |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | return aperture_size >> PAGE_SHIFT; |
| 631 | } |
| 632 | |
Daniel Vetter | 0e87d2b | 2010-09-07 22:11:15 +0200 | [diff] [blame] | 633 | static void intel_gtt_teardown_scratch_page(void) |
| 634 | { |
| 635 | set_pages_wb(intel_private.scratch_page, 1); |
| 636 | pci_unmap_page(intel_private.pcidev, intel_private.scratch_page_dma, |
| 637 | PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); |
| 638 | put_page(intel_private.scratch_page); |
| 639 | __free_page(intel_private.scratch_page); |
| 640 | } |
| 641 | |
| 642 | static void intel_gtt_cleanup(void) |
| 643 | { |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 644 | intel_private.driver->cleanup(); |
| 645 | |
Daniel Vetter | 0e87d2b | 2010-09-07 22:11:15 +0200 | [diff] [blame] | 646 | iounmap(intel_private.gtt); |
| 647 | iounmap(intel_private.registers); |
Daniel Vetter | 625dd9d | 2010-11-04 20:07:57 +0100 | [diff] [blame] | 648 | |
Daniel Vetter | 0e87d2b | 2010-09-07 22:11:15 +0200 | [diff] [blame] | 649 | intel_gtt_teardown_scratch_page(); |
| 650 | } |
| 651 | |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 652 | static int intel_gtt_init(void) |
| 653 | { |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 654 | u32 gtt_map_size; |
Daniel Vetter | 3b15a9d | 2010-08-29 14:18:49 +0200 | [diff] [blame] | 655 | int ret; |
| 656 | |
Daniel Vetter | 3b15a9d | 2010-08-29 14:18:49 +0200 | [diff] [blame] | 657 | ret = intel_private.driver->setup(); |
| 658 | if (ret != 0) |
| 659 | return ret; |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 660 | |
| 661 | intel_private.base.gtt_mappable_entries = intel_gtt_mappable_entries(); |
| 662 | intel_private.base.gtt_total_entries = intel_gtt_total_entries(); |
| 663 | |
Daniel Vetter | b3eafc5 | 2010-09-23 20:04:17 +0200 | [diff] [blame] | 664 | /* save the PGETBL reg for resume */ |
| 665 | intel_private.PGETBL_save = |
| 666 | readl(intel_private.registers+I810_PGETBL_CTL) |
| 667 | & ~I810_PGETBL_ENABLED; |
Chris Wilson | 100519e | 2010-10-31 10:37:02 +0000 | [diff] [blame] | 668 | /* we only ever restore the register when enabling the PGTBL... */ |
| 669 | if (HAS_PGTBL_EN) |
| 670 | intel_private.PGETBL_save |= I810_PGETBL_ENABLED; |
Daniel Vetter | b3eafc5 | 2010-09-23 20:04:17 +0200 | [diff] [blame] | 671 | |
Daniel Vetter | 0af9e92 | 2010-09-12 14:04:03 +0200 | [diff] [blame] | 672 | dev_info(&intel_private.bridge_dev->dev, |
| 673 | "detected gtt size: %dK total, %dK mappable\n", |
| 674 | intel_private.base.gtt_total_entries * 4, |
| 675 | intel_private.base.gtt_mappable_entries * 4); |
| 676 | |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 677 | gtt_map_size = intel_private.base.gtt_total_entries * 4; |
| 678 | |
| 679 | intel_private.gtt = ioremap(intel_private.gtt_bus_addr, |
| 680 | gtt_map_size); |
| 681 | if (!intel_private.gtt) { |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 682 | intel_private.driver->cleanup(); |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 683 | iounmap(intel_private.registers); |
| 684 | return -ENOMEM; |
| 685 | } |
| 686 | |
| 687 | global_cache_flush(); /* FIXME: ? */ |
| 688 | |
Chris Wilson | c64f7ba | 2010-11-23 14:24:24 +0000 | [diff] [blame] | 689 | intel_private.base.stolen_size = intel_gtt_stolen_size(); |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 690 | |
Daniel Vetter | 0e87d2b | 2010-09-07 22:11:15 +0200 | [diff] [blame] | 691 | ret = intel_gtt_setup_scratch_page(); |
| 692 | if (ret != 0) { |
| 693 | intel_gtt_cleanup(); |
| 694 | return ret; |
| 695 | } |
| 696 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 697 | intel_private.base.needs_dmar = USE_PCI_DMA_API && INTEL_GTT_GEN > 2; |
| 698 | |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 699 | return 0; |
| 700 | } |
| 701 | |
Daniel Vetter | 3e921f9 | 2010-08-27 15:33:26 +0200 | [diff] [blame] | 702 | static int intel_fake_agp_fetch_size(void) |
| 703 | { |
Chris Wilson | 9e76e7b | 2010-09-14 12:12:11 +0100 | [diff] [blame] | 704 | int num_sizes = ARRAY_SIZE(intel_fake_agp_sizes); |
Daniel Vetter | 3e921f9 | 2010-08-27 15:33:26 +0200 | [diff] [blame] | 705 | unsigned int aper_size; |
| 706 | int i; |
Daniel Vetter | 3e921f9 | 2010-08-27 15:33:26 +0200 | [diff] [blame] | 707 | |
| 708 | aper_size = (intel_private.base.gtt_mappable_entries << PAGE_SHIFT) |
| 709 | / MB(1); |
| 710 | |
| 711 | for (i = 0; i < num_sizes; i++) { |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 712 | if (aper_size == intel_fake_agp_sizes[i].size) { |
Chris Wilson | 9e76e7b | 2010-09-14 12:12:11 +0100 | [diff] [blame] | 713 | agp_bridge->current_size = |
| 714 | (void *) (intel_fake_agp_sizes + i); |
Daniel Vetter | 3e921f9 | 2010-08-27 15:33:26 +0200 | [diff] [blame] | 715 | return aper_size; |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | return 0; |
| 720 | } |
| 721 | |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 722 | static void i830_cleanup(void) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 723 | { |
| 724 | kunmap(intel_private.i8xx_page); |
| 725 | intel_private.i8xx_flush_page = NULL; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 726 | |
| 727 | __free_page(intel_private.i8xx_page); |
| 728 | intel_private.i8xx_page = NULL; |
| 729 | } |
| 730 | |
| 731 | static void intel_i830_setup_flush(void) |
| 732 | { |
| 733 | /* return if we've already set the flush mechanism up */ |
| 734 | if (intel_private.i8xx_page) |
| 735 | return; |
| 736 | |
Jan Beulich | e61cb0d | 2010-09-24 13:25:30 +0100 | [diff] [blame] | 737 | intel_private.i8xx_page = alloc_page(GFP_KERNEL); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 738 | if (!intel_private.i8xx_page) |
| 739 | return; |
| 740 | |
| 741 | intel_private.i8xx_flush_page = kmap(intel_private.i8xx_page); |
| 742 | if (!intel_private.i8xx_flush_page) |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 743 | i830_cleanup(); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /* The chipset_flush interface needs to get data that has already been |
| 747 | * flushed out of the CPU all the way out to main memory, because the GPU |
| 748 | * doesn't snoop those buffers. |
| 749 | * |
| 750 | * The 8xx series doesn't have the same lovely interface for flushing the |
| 751 | * chipset write buffers that the later chips do. According to the 865 |
| 752 | * specs, it's 64 octwords, or 1KB. So, to get those previous things in |
| 753 | * that buffer out, we just fill 1KB and clflush it out, on the assumption |
| 754 | * that it'll push whatever was in there out. It appears to work. |
| 755 | */ |
Daniel Vetter | 1b263f2 | 2010-09-12 00:27:24 +0200 | [diff] [blame] | 756 | static void i830_chipset_flush(void) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 757 | { |
| 758 | unsigned int *pg = intel_private.i8xx_flush_page; |
| 759 | |
| 760 | memset(pg, 0, 1024); |
| 761 | |
| 762 | if (cpu_has_clflush) |
| 763 | clflush_cache_range(pg, 1024); |
| 764 | else if (wbinvd_on_all_cpus() != 0) |
| 765 | printk(KERN_ERR "Timed out waiting for cache flush.\n"); |
| 766 | } |
| 767 | |
Daniel Vetter | 351bb27 | 2010-09-07 22:41:04 +0200 | [diff] [blame] | 768 | static void i830_write_entry(dma_addr_t addr, unsigned int entry, |
| 769 | unsigned int flags) |
| 770 | { |
| 771 | u32 pte_flags = I810_PTE_VALID; |
Daniel Vetter | 625dd9d | 2010-11-04 20:07:57 +0100 | [diff] [blame] | 772 | |
Daniel Vetter | b47cf66 | 2010-11-04 18:41:50 +0100 | [diff] [blame] | 773 | if (flags == AGP_USER_CACHED_MEMORY) |
Daniel Vetter | 351bb27 | 2010-09-07 22:41:04 +0200 | [diff] [blame] | 774 | pte_flags |= I830_PTE_SYSTEM_CACHED; |
Daniel Vetter | 351bb27 | 2010-09-07 22:41:04 +0200 | [diff] [blame] | 775 | |
| 776 | writel(addr | pte_flags, intel_private.gtt + entry); |
| 777 | } |
| 778 | |
Chris Wilson | e380f60 | 2010-10-29 18:11:26 +0100 | [diff] [blame] | 779 | static bool intel_enable_gtt(void) |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame] | 780 | { |
Chris Wilson | 3f08e4e | 2010-09-14 20:15:22 +0100 | [diff] [blame] | 781 | u32 gma_addr; |
Chris Wilson | e380f60 | 2010-10-29 18:11:26 +0100 | [diff] [blame] | 782 | u8 __iomem *reg; |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame] | 783 | |
Daniel Vetter | 820647b | 2010-11-05 13:30:14 +0100 | [diff] [blame] | 784 | if (INTEL_GTT_GEN <= 2) |
Daniel Vetter | 2d2430c | 2010-08-29 17:35:30 +0200 | [diff] [blame] | 785 | pci_read_config_dword(intel_private.pcidev, I810_GMADDR, |
| 786 | &gma_addr); |
| 787 | else |
| 788 | pci_read_config_dword(intel_private.pcidev, I915_GMADDR, |
| 789 | &gma_addr); |
| 790 | |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame] | 791 | intel_private.gma_bus_addr = (gma_addr & PCI_BASE_ADDRESS_MEM_MASK); |
| 792 | |
Chris Wilson | e380f60 | 2010-10-29 18:11:26 +0100 | [diff] [blame] | 793 | if (INTEL_GTT_GEN >= 6) |
| 794 | return true; |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame] | 795 | |
Chris Wilson | 100519e | 2010-10-31 10:37:02 +0000 | [diff] [blame] | 796 | if (INTEL_GTT_GEN == 2) { |
| 797 | u16 gmch_ctrl; |
Chris Wilson | e380f60 | 2010-10-29 18:11:26 +0100 | [diff] [blame] | 798 | |
Chris Wilson | 100519e | 2010-10-31 10:37:02 +0000 | [diff] [blame] | 799 | pci_read_config_word(intel_private.bridge_dev, |
| 800 | I830_GMCH_CTRL, &gmch_ctrl); |
| 801 | gmch_ctrl |= I830_GMCH_ENABLED; |
| 802 | pci_write_config_word(intel_private.bridge_dev, |
| 803 | I830_GMCH_CTRL, gmch_ctrl); |
| 804 | |
| 805 | pci_read_config_word(intel_private.bridge_dev, |
| 806 | I830_GMCH_CTRL, &gmch_ctrl); |
| 807 | if ((gmch_ctrl & I830_GMCH_ENABLED) == 0) { |
| 808 | dev_err(&intel_private.pcidev->dev, |
| 809 | "failed to enable the GTT: GMCH_CTRL=%x\n", |
| 810 | gmch_ctrl); |
| 811 | return false; |
| 812 | } |
Chris Wilson | e380f60 | 2010-10-29 18:11:26 +0100 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | reg = intel_private.registers+I810_PGETBL_CTL; |
Chris Wilson | 100519e | 2010-10-31 10:37:02 +0000 | [diff] [blame] | 816 | writel(intel_private.PGETBL_save, reg); |
| 817 | if (HAS_PGTBL_EN && (readl(reg) & I810_PGETBL_ENABLED) == 0) { |
Chris Wilson | e380f60 | 2010-10-29 18:11:26 +0100 | [diff] [blame] | 818 | dev_err(&intel_private.pcidev->dev, |
Chris Wilson | 100519e | 2010-10-31 10:37:02 +0000 | [diff] [blame] | 819 | "failed to enable the GTT: PGETBL=%x [expected %x]\n", |
Chris Wilson | e380f60 | 2010-10-29 18:11:26 +0100 | [diff] [blame] | 820 | readl(reg), intel_private.PGETBL_save); |
| 821 | return false; |
| 822 | } |
| 823 | |
| 824 | return true; |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | static int i830_setup(void) |
| 828 | { |
| 829 | u32 reg_addr; |
| 830 | |
| 831 | pci_read_config_dword(intel_private.pcidev, I810_MMADDR, ®_addr); |
| 832 | reg_addr &= 0xfff80000; |
| 833 | |
| 834 | intel_private.registers = ioremap(reg_addr, KB(64)); |
| 835 | if (!intel_private.registers) |
| 836 | return -ENOMEM; |
| 837 | |
| 838 | intel_private.gtt_bus_addr = reg_addr + I810_PTE_BASE; |
| 839 | |
| 840 | intel_i830_setup_flush(); |
| 841 | |
| 842 | return 0; |
| 843 | } |
| 844 | |
Daniel Vetter | 3b15a9d | 2010-08-29 14:18:49 +0200 | [diff] [blame] | 845 | static int intel_fake_agp_create_gatt_table(struct agp_bridge_data *bridge) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 846 | { |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame] | 847 | agp_bridge->gatt_table_real = NULL; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 848 | agp_bridge->gatt_table = NULL; |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame] | 849 | agp_bridge->gatt_bus_addr = 0; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 850 | |
| 851 | return 0; |
| 852 | } |
| 853 | |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 854 | static int intel_fake_agp_free_gatt_table(struct agp_bridge_data *bridge) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 855 | { |
| 856 | return 0; |
| 857 | } |
| 858 | |
Daniel Vetter | 351bb27 | 2010-09-07 22:41:04 +0200 | [diff] [blame] | 859 | static int intel_fake_agp_configure(void) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 860 | { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 861 | int i; |
| 862 | |
Chris Wilson | e380f60 | 2010-10-29 18:11:26 +0100 | [diff] [blame] | 863 | if (!intel_enable_gtt()) |
| 864 | return -EIO; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 865 | |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame] | 866 | agp_bridge->gart_bus_addr = intel_private.gma_bus_addr; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 867 | |
Chris Wilson | c64f7ba | 2010-11-23 14:24:24 +0000 | [diff] [blame] | 868 | for (i = 0; i < intel_private.base.gtt_total_entries; i++) { |
Daniel Vetter | 351bb27 | 2010-09-07 22:41:04 +0200 | [diff] [blame] | 869 | intel_private.driver->write_entry(intel_private.scratch_page_dma, |
| 870 | i, 0); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 871 | } |
Daniel Vetter | 351bb27 | 2010-09-07 22:41:04 +0200 | [diff] [blame] | 872 | readl(intel_private.gtt+i-1); /* PCI Posting. */ |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 873 | |
| 874 | global_cache_flush(); |
| 875 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 876 | return 0; |
| 877 | } |
| 878 | |
Daniel Vetter | 5cbecaf | 2010-09-11 21:31:04 +0200 | [diff] [blame] | 879 | static bool i830_check_flags(unsigned int flags) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 880 | { |
Daniel Vetter | 5cbecaf | 2010-09-11 21:31:04 +0200 | [diff] [blame] | 881 | switch (flags) { |
| 882 | case 0: |
| 883 | case AGP_PHYS_MEMORY: |
| 884 | case AGP_USER_CACHED_MEMORY: |
| 885 | case AGP_USER_MEMORY: |
| 886 | return true; |
| 887 | } |
| 888 | |
| 889 | return false; |
| 890 | } |
| 891 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 892 | void intel_gtt_insert_sg_entries(struct scatterlist *sg_list, |
| 893 | unsigned int sg_len, |
| 894 | unsigned int pg_start, |
| 895 | unsigned int flags) |
Daniel Vetter | fefaa70 | 2010-09-11 22:12:11 +0200 | [diff] [blame] | 896 | { |
| 897 | struct scatterlist *sg; |
| 898 | unsigned int len, m; |
| 899 | int i, j; |
| 900 | |
| 901 | j = pg_start; |
| 902 | |
| 903 | /* sg may merge pages, but we have to separate |
| 904 | * per-page addr for GTT */ |
| 905 | for_each_sg(sg_list, sg, sg_len, i) { |
| 906 | len = sg_dma_len(sg) >> PAGE_SHIFT; |
| 907 | for (m = 0; m < len; m++) { |
| 908 | dma_addr_t addr = sg_dma_address(sg) + (m << PAGE_SHIFT); |
| 909 | intel_private.driver->write_entry(addr, |
| 910 | j, flags); |
| 911 | j++; |
| 912 | } |
| 913 | } |
| 914 | readl(intel_private.gtt+j-1); |
| 915 | } |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 916 | EXPORT_SYMBOL(intel_gtt_insert_sg_entries); |
| 917 | |
| 918 | void intel_gtt_insert_pages(unsigned int first_entry, unsigned int num_entries, |
| 919 | struct page **pages, unsigned int flags) |
| 920 | { |
| 921 | int i, j; |
| 922 | |
| 923 | for (i = 0, j = first_entry; i < num_entries; i++, j++) { |
| 924 | dma_addr_t addr = page_to_phys(pages[i]); |
| 925 | intel_private.driver->write_entry(addr, |
| 926 | j, flags); |
| 927 | } |
| 928 | readl(intel_private.gtt+j-1); |
| 929 | } |
| 930 | EXPORT_SYMBOL(intel_gtt_insert_pages); |
Daniel Vetter | fefaa70 | 2010-09-11 22:12:11 +0200 | [diff] [blame] | 931 | |
Daniel Vetter | 5cbecaf | 2010-09-11 21:31:04 +0200 | [diff] [blame] | 932 | static int intel_fake_agp_insert_entries(struct agp_memory *mem, |
| 933 | off_t pg_start, int type) |
| 934 | { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 935 | int ret = -EINVAL; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 936 | |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 937 | if (INTEL_GTT_GEN == 1 && type == AGP_DCACHE_MEMORY) |
| 938 | return i810_insert_dcache_entries(mem, pg_start, type); |
| 939 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 940 | if (mem->page_count == 0) |
| 941 | goto out; |
| 942 | |
Chris Wilson | c64f7ba | 2010-11-23 14:24:24 +0000 | [diff] [blame] | 943 | if (pg_start + mem->page_count > intel_private.base.gtt_total_entries) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 944 | goto out_err; |
| 945 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 946 | if (type != mem->type) |
| 947 | goto out_err; |
| 948 | |
Daniel Vetter | 5cbecaf | 2010-09-11 21:31:04 +0200 | [diff] [blame] | 949 | if (!intel_private.driver->check_flags(type)) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 950 | goto out_err; |
| 951 | |
| 952 | if (!mem->is_flushed) |
| 953 | global_cache_flush(); |
| 954 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 955 | if (intel_private.base.needs_dmar) { |
| 956 | ret = intel_gtt_map_memory(mem->pages, mem->page_count, |
| 957 | &mem->sg_list, &mem->num_sg); |
Daniel Vetter | fefaa70 | 2010-09-11 22:12:11 +0200 | [diff] [blame] | 958 | if (ret != 0) |
| 959 | return ret; |
| 960 | |
| 961 | intel_gtt_insert_sg_entries(mem->sg_list, mem->num_sg, |
| 962 | pg_start, type); |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 963 | } else |
| 964 | intel_gtt_insert_pages(pg_start, mem->page_count, mem->pages, |
| 965 | type); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 966 | |
| 967 | out: |
| 968 | ret = 0; |
| 969 | out_err: |
| 970 | mem->is_flushed = true; |
| 971 | return ret; |
| 972 | } |
| 973 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 974 | void intel_gtt_clear_range(unsigned int first_entry, unsigned int num_entries) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 975 | { |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 976 | unsigned int i; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 977 | |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 978 | for (i = first_entry; i < (first_entry + num_entries); i++) { |
Daniel Vetter | 5cbecaf | 2010-09-11 21:31:04 +0200 | [diff] [blame] | 979 | intel_private.driver->write_entry(intel_private.scratch_page_dma, |
| 980 | i, 0); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 981 | } |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 982 | readl(intel_private.gtt+i-1); |
Daniel Vetter | 4080775 | 2010-11-06 11:18:58 +0100 | [diff] [blame] | 983 | } |
| 984 | EXPORT_SYMBOL(intel_gtt_clear_range); |
| 985 | |
| 986 | static int intel_fake_agp_remove_entries(struct agp_memory *mem, |
| 987 | off_t pg_start, int type) |
| 988 | { |
| 989 | if (mem->page_count == 0) |
| 990 | return 0; |
| 991 | |
| 992 | if (intel_private.base.needs_dmar) { |
| 993 | intel_gtt_unmap_memory(mem->sg_list, mem->num_sg); |
| 994 | mem->sg_list = NULL; |
| 995 | mem->num_sg = 0; |
| 996 | } |
| 997 | |
| 998 | intel_gtt_clear_range(pg_start, mem->page_count); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 999 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1000 | return 0; |
| 1001 | } |
| 1002 | |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1003 | static struct agp_memory *intel_fake_agp_alloc_by_type(size_t pg_count, |
| 1004 | int type) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1005 | { |
Daniel Vetter | 625dd9d | 2010-11-04 20:07:57 +0100 | [diff] [blame] | 1006 | struct agp_memory *new; |
| 1007 | |
| 1008 | if (type == AGP_DCACHE_MEMORY && INTEL_GTT_GEN == 1) { |
| 1009 | if (pg_count != intel_private.num_dcache_entries) |
| 1010 | return NULL; |
| 1011 | |
| 1012 | new = agp_create_memory(1); |
| 1013 | if (new == NULL) |
| 1014 | return NULL; |
| 1015 | |
| 1016 | new->type = AGP_DCACHE_MEMORY; |
| 1017 | new->page_count = pg_count; |
| 1018 | new->num_scratch_pages = 0; |
| 1019 | agp_free_page_array(new); |
| 1020 | return new; |
| 1021 | } |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1022 | if (type == AGP_PHYS_MEMORY) |
| 1023 | return alloc_agpphysmem_i8xx(pg_count, type); |
| 1024 | /* always return NULL for other allocation types for now */ |
| 1025 | return NULL; |
| 1026 | } |
| 1027 | |
| 1028 | static int intel_alloc_chipset_flush_resource(void) |
| 1029 | { |
| 1030 | int ret; |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1031 | ret = pci_bus_alloc_resource(intel_private.bridge_dev->bus, &intel_private.ifp_resource, PAGE_SIZE, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1032 | PAGE_SIZE, PCIBIOS_MIN_MEM, 0, |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1033 | pcibios_align_resource, intel_private.bridge_dev); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1034 | |
| 1035 | return ret; |
| 1036 | } |
| 1037 | |
| 1038 | static void intel_i915_setup_chipset_flush(void) |
| 1039 | { |
| 1040 | int ret; |
| 1041 | u32 temp; |
| 1042 | |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1043 | pci_read_config_dword(intel_private.bridge_dev, I915_IFPADDR, &temp); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1044 | if (!(temp & 0x1)) { |
| 1045 | intel_alloc_chipset_flush_resource(); |
| 1046 | intel_private.resource_valid = 1; |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1047 | pci_write_config_dword(intel_private.bridge_dev, I915_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1048 | } else { |
| 1049 | temp &= ~1; |
| 1050 | |
| 1051 | intel_private.resource_valid = 1; |
| 1052 | intel_private.ifp_resource.start = temp; |
| 1053 | intel_private.ifp_resource.end = temp + PAGE_SIZE; |
| 1054 | ret = request_resource(&iomem_resource, &intel_private.ifp_resource); |
| 1055 | /* some BIOSes reserve this area in a pnp some don't */ |
| 1056 | if (ret) |
| 1057 | intel_private.resource_valid = 0; |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | static void intel_i965_g33_setup_chipset_flush(void) |
| 1062 | { |
| 1063 | u32 temp_hi, temp_lo; |
| 1064 | int ret; |
| 1065 | |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1066 | pci_read_config_dword(intel_private.bridge_dev, I965_IFPADDR + 4, &temp_hi); |
| 1067 | pci_read_config_dword(intel_private.bridge_dev, I965_IFPADDR, &temp_lo); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1068 | |
| 1069 | if (!(temp_lo & 0x1)) { |
| 1070 | |
| 1071 | intel_alloc_chipset_flush_resource(); |
| 1072 | |
| 1073 | intel_private.resource_valid = 1; |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1074 | pci_write_config_dword(intel_private.bridge_dev, I965_IFPADDR + 4, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1075 | upper_32_bits(intel_private.ifp_resource.start)); |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1076 | pci_write_config_dword(intel_private.bridge_dev, I965_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1077 | } else { |
| 1078 | u64 l64; |
| 1079 | |
| 1080 | temp_lo &= ~0x1; |
| 1081 | l64 = ((u64)temp_hi << 32) | temp_lo; |
| 1082 | |
| 1083 | intel_private.resource_valid = 1; |
| 1084 | intel_private.ifp_resource.start = l64; |
| 1085 | intel_private.ifp_resource.end = l64 + PAGE_SIZE; |
| 1086 | ret = request_resource(&iomem_resource, &intel_private.ifp_resource); |
| 1087 | /* some BIOSes reserve this area in a pnp some don't */ |
| 1088 | if (ret) |
| 1089 | intel_private.resource_valid = 0; |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | static void intel_i9xx_setup_flush(void) |
| 1094 | { |
| 1095 | /* return if already configured */ |
| 1096 | if (intel_private.ifp_resource.start) |
| 1097 | return; |
| 1098 | |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1099 | if (INTEL_GTT_GEN == 6) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1100 | return; |
| 1101 | |
| 1102 | /* setup a resource for this object */ |
| 1103 | intel_private.ifp_resource.name = "Intel Flush Page"; |
| 1104 | intel_private.ifp_resource.flags = IORESOURCE_MEM; |
| 1105 | |
| 1106 | /* Setup chipset flush for 915 */ |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1107 | if (IS_G33 || INTEL_GTT_GEN >= 4) { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1108 | intel_i965_g33_setup_chipset_flush(); |
| 1109 | } else { |
| 1110 | intel_i915_setup_chipset_flush(); |
| 1111 | } |
| 1112 | |
Chris Wilson | df51e7a | 2010-09-04 14:57:27 +0100 | [diff] [blame] | 1113 | if (intel_private.ifp_resource.start) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1114 | intel_private.i9xx_flush_page = ioremap_nocache(intel_private.ifp_resource.start, PAGE_SIZE); |
Chris Wilson | df51e7a | 2010-09-04 14:57:27 +0100 | [diff] [blame] | 1115 | if (!intel_private.i9xx_flush_page) |
| 1116 | dev_err(&intel_private.pcidev->dev, |
| 1117 | "can't ioremap flush page - no chipset flushing\n"); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1118 | } |
| 1119 | |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 1120 | static void i9xx_cleanup(void) |
| 1121 | { |
| 1122 | if (intel_private.i9xx_flush_page) |
| 1123 | iounmap(intel_private.i9xx_flush_page); |
| 1124 | if (intel_private.resource_valid) |
| 1125 | release_resource(&intel_private.ifp_resource); |
| 1126 | intel_private.ifp_resource.start = 0; |
| 1127 | intel_private.resource_valid = 0; |
| 1128 | } |
| 1129 | |
Daniel Vetter | 1b263f2 | 2010-09-12 00:27:24 +0200 | [diff] [blame] | 1130 | static void i9xx_chipset_flush(void) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1131 | { |
| 1132 | if (intel_private.i9xx_flush_page) |
| 1133 | writel(1, intel_private.i9xx_flush_page); |
| 1134 | } |
| 1135 | |
Daniel Vetter | a696359 | 2010-09-11 14:01:43 +0200 | [diff] [blame] | 1136 | static void i965_write_entry(dma_addr_t addr, unsigned int entry, |
| 1137 | unsigned int flags) |
| 1138 | { |
| 1139 | /* Shift high bits down */ |
| 1140 | addr |= (addr >> 28) & 0xf0; |
| 1141 | writel(addr | I810_PTE_VALID, intel_private.gtt + entry); |
| 1142 | } |
| 1143 | |
Daniel Vetter | 90cb149 | 2010-09-11 23:55:20 +0200 | [diff] [blame] | 1144 | static bool gen6_check_flags(unsigned int flags) |
| 1145 | { |
| 1146 | return true; |
| 1147 | } |
| 1148 | |
Daniel Vetter | 97ef1bd | 2010-09-09 17:52:20 +0200 | [diff] [blame] | 1149 | static void gen6_write_entry(dma_addr_t addr, unsigned int entry, |
| 1150 | unsigned int flags) |
| 1151 | { |
| 1152 | unsigned int type_mask = flags & ~AGP_USER_CACHED_MEMORY_GFDT; |
| 1153 | unsigned int gfdt = flags & AGP_USER_CACHED_MEMORY_GFDT; |
| 1154 | u32 pte_flags; |
| 1155 | |
Zhenyu Wang | 897ef19 | 2010-11-02 17:30:47 +0800 | [diff] [blame] | 1156 | if (type_mask == AGP_USER_MEMORY) |
Chris Wilson | 85ccc35 | 2010-10-22 14:59:29 +0100 | [diff] [blame] | 1157 | pte_flags = GEN6_PTE_UNCACHED | I810_PTE_VALID; |
Daniel Vetter | 97ef1bd | 2010-09-09 17:52:20 +0200 | [diff] [blame] | 1158 | else if (type_mask == AGP_USER_CACHED_MEMORY_LLC_MLC) { |
Zhenyu Wang | d110852 | 2010-11-02 17:30:46 +0800 | [diff] [blame] | 1159 | pte_flags = GEN6_PTE_LLC_MLC | I810_PTE_VALID; |
Daniel Vetter | 97ef1bd | 2010-09-09 17:52:20 +0200 | [diff] [blame] | 1160 | if (gfdt) |
| 1161 | pte_flags |= GEN6_PTE_GFDT; |
| 1162 | } else { /* set 'normal'/'cached' to LLC by default */ |
Zhenyu Wang | d110852 | 2010-11-02 17:30:46 +0800 | [diff] [blame] | 1163 | pte_flags = GEN6_PTE_LLC | I810_PTE_VALID; |
Daniel Vetter | 97ef1bd | 2010-09-09 17:52:20 +0200 | [diff] [blame] | 1164 | if (gfdt) |
| 1165 | pte_flags |= GEN6_PTE_GFDT; |
| 1166 | } |
| 1167 | |
| 1168 | /* gen6 has bit11-4 for physical addr bit39-32 */ |
| 1169 | addr |= (addr >> 28) & 0xff0; |
| 1170 | writel(addr | pte_flags, intel_private.gtt + entry); |
| 1171 | } |
| 1172 | |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 1173 | static void gen6_cleanup(void) |
| 1174 | { |
| 1175 | } |
| 1176 | |
Daniel Vetter | 2d2430c | 2010-08-29 17:35:30 +0200 | [diff] [blame] | 1177 | static int i9xx_setup(void) |
| 1178 | { |
| 1179 | u32 reg_addr; |
| 1180 | |
| 1181 | pci_read_config_dword(intel_private.pcidev, I915_MMADDR, ®_addr); |
| 1182 | |
| 1183 | reg_addr &= 0xfff80000; |
| 1184 | |
| 1185 | intel_private.registers = ioremap(reg_addr, 128 * 4096); |
| 1186 | if (!intel_private.registers) |
| 1187 | return -ENOMEM; |
| 1188 | |
| 1189 | if (INTEL_GTT_GEN == 3) { |
| 1190 | u32 gtt_addr; |
Chris Wilson | 3f08e4e | 2010-09-14 20:15:22 +0100 | [diff] [blame] | 1191 | |
Daniel Vetter | 2d2430c | 2010-08-29 17:35:30 +0200 | [diff] [blame] | 1192 | pci_read_config_dword(intel_private.pcidev, |
| 1193 | I915_PTEADDR, >t_addr); |
| 1194 | intel_private.gtt_bus_addr = gtt_addr; |
| 1195 | } else { |
| 1196 | u32 gtt_offset; |
| 1197 | |
| 1198 | switch (INTEL_GTT_GEN) { |
| 1199 | case 5: |
| 1200 | case 6: |
| 1201 | gtt_offset = MB(2); |
| 1202 | break; |
| 1203 | case 4: |
| 1204 | default: |
| 1205 | gtt_offset = KB(512); |
| 1206 | break; |
| 1207 | } |
| 1208 | intel_private.gtt_bus_addr = reg_addr + gtt_offset; |
| 1209 | } |
| 1210 | |
| 1211 | intel_i9xx_setup_flush(); |
| 1212 | |
| 1213 | return 0; |
| 1214 | } |
| 1215 | |
Daniel Vetter | e9b1cc8 | 2010-09-12 00:29:26 +0200 | [diff] [blame] | 1216 | static const struct agp_bridge_driver intel_fake_agp_driver = { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1217 | .owner = THIS_MODULE, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1218 | .size_type = FIXED_APER_SIZE, |
Chris Wilson | 9e76e7b | 2010-09-14 12:12:11 +0100 | [diff] [blame] | 1219 | .aperture_sizes = intel_fake_agp_sizes, |
| 1220 | .num_aperture_sizes = ARRAY_SIZE(intel_fake_agp_sizes), |
Daniel Vetter | a696359 | 2010-09-11 14:01:43 +0200 | [diff] [blame] | 1221 | .configure = intel_fake_agp_configure, |
Daniel Vetter | 3e921f9 | 2010-08-27 15:33:26 +0200 | [diff] [blame] | 1222 | .fetch_size = intel_fake_agp_fetch_size, |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 1223 | .cleanup = intel_gtt_cleanup, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1224 | .agp_enable = intel_fake_agp_enable, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1225 | .cache_flush = global_cache_flush, |
Daniel Vetter | 3b15a9d | 2010-08-29 14:18:49 +0200 | [diff] [blame] | 1226 | .create_gatt_table = intel_fake_agp_create_gatt_table, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1227 | .free_gatt_table = intel_fake_agp_free_gatt_table, |
Daniel Vetter | 450f2b3 | 2010-09-11 23:48:25 +0200 | [diff] [blame] | 1228 | .insert_memory = intel_fake_agp_insert_entries, |
| 1229 | .remove_memory = intel_fake_agp_remove_entries, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1230 | .alloc_by_type = intel_fake_agp_alloc_by_type, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1231 | .free_by_type = intel_i810_free_by_type, |
| 1232 | .agp_alloc_page = agp_generic_alloc_page, |
| 1233 | .agp_alloc_pages = agp_generic_alloc_pages, |
| 1234 | .agp_destroy_page = agp_generic_destroy_page, |
| 1235 | .agp_destroy_pages = agp_generic_destroy_pages, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1236 | }; |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1237 | |
Daniel Vetter | bdd3072 | 2010-09-12 12:34:44 +0200 | [diff] [blame] | 1238 | static const struct intel_gtt_driver i81x_gtt_driver = { |
| 1239 | .gen = 1, |
Daniel Vetter | 820647b | 2010-11-05 13:30:14 +0100 | [diff] [blame] | 1240 | .has_pgtbl_enable = 1, |
Daniel Vetter | 22533b4 | 2010-09-12 16:38:55 +0200 | [diff] [blame] | 1241 | .dma_mask_size = 32, |
Daniel Vetter | 820647b | 2010-11-05 13:30:14 +0100 | [diff] [blame] | 1242 | .setup = i810_setup, |
| 1243 | .cleanup = i810_cleanup, |
Daniel Vetter | 625dd9d | 2010-11-04 20:07:57 +0100 | [diff] [blame] | 1244 | .check_flags = i830_check_flags, |
| 1245 | .write_entry = i810_write_entry, |
Daniel Vetter | bdd3072 | 2010-09-12 12:34:44 +0200 | [diff] [blame] | 1246 | }; |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1247 | static const struct intel_gtt_driver i8xx_gtt_driver = { |
| 1248 | .gen = 2, |
Chris Wilson | 100519e | 2010-10-31 10:37:02 +0000 | [diff] [blame] | 1249 | .has_pgtbl_enable = 1, |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame] | 1250 | .setup = i830_setup, |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 1251 | .cleanup = i830_cleanup, |
Daniel Vetter | 351bb27 | 2010-09-07 22:41:04 +0200 | [diff] [blame] | 1252 | .write_entry = i830_write_entry, |
Daniel Vetter | 22533b4 | 2010-09-12 16:38:55 +0200 | [diff] [blame] | 1253 | .dma_mask_size = 32, |
Daniel Vetter | 5cbecaf | 2010-09-11 21:31:04 +0200 | [diff] [blame] | 1254 | .check_flags = i830_check_flags, |
Daniel Vetter | 1b263f2 | 2010-09-12 00:27:24 +0200 | [diff] [blame] | 1255 | .chipset_flush = i830_chipset_flush, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1256 | }; |
| 1257 | static const struct intel_gtt_driver i915_gtt_driver = { |
| 1258 | .gen = 3, |
Chris Wilson | 100519e | 2010-10-31 10:37:02 +0000 | [diff] [blame] | 1259 | .has_pgtbl_enable = 1, |
Daniel Vetter | 2d2430c | 2010-08-29 17:35:30 +0200 | [diff] [blame] | 1260 | .setup = i9xx_setup, |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 1261 | .cleanup = i9xx_cleanup, |
Daniel Vetter | 351bb27 | 2010-09-07 22:41:04 +0200 | [diff] [blame] | 1262 | /* i945 is the last gpu to need phys mem (for overlay and cursors). */ |
Daniel Vetter | 625dd9d | 2010-11-04 20:07:57 +0100 | [diff] [blame] | 1263 | .write_entry = i830_write_entry, |
Daniel Vetter | 22533b4 | 2010-09-12 16:38:55 +0200 | [diff] [blame] | 1264 | .dma_mask_size = 32, |
Daniel Vetter | fefaa70 | 2010-09-11 22:12:11 +0200 | [diff] [blame] | 1265 | .check_flags = i830_check_flags, |
Daniel Vetter | 1b263f2 | 2010-09-12 00:27:24 +0200 | [diff] [blame] | 1266 | .chipset_flush = i9xx_chipset_flush, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1267 | }; |
| 1268 | static const struct intel_gtt_driver g33_gtt_driver = { |
| 1269 | .gen = 3, |
| 1270 | .is_g33 = 1, |
Daniel Vetter | 2d2430c | 2010-08-29 17:35:30 +0200 | [diff] [blame] | 1271 | .setup = i9xx_setup, |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 1272 | .cleanup = i9xx_cleanup, |
Daniel Vetter | a696359 | 2010-09-11 14:01:43 +0200 | [diff] [blame] | 1273 | .write_entry = i965_write_entry, |
Daniel Vetter | 22533b4 | 2010-09-12 16:38:55 +0200 | [diff] [blame] | 1274 | .dma_mask_size = 36, |
Daniel Vetter | 450f2b3 | 2010-09-11 23:48:25 +0200 | [diff] [blame] | 1275 | .check_flags = i830_check_flags, |
Daniel Vetter | 1b263f2 | 2010-09-12 00:27:24 +0200 | [diff] [blame] | 1276 | .chipset_flush = i9xx_chipset_flush, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1277 | }; |
| 1278 | static const struct intel_gtt_driver pineview_gtt_driver = { |
| 1279 | .gen = 3, |
| 1280 | .is_pineview = 1, .is_g33 = 1, |
Daniel Vetter | 2d2430c | 2010-08-29 17:35:30 +0200 | [diff] [blame] | 1281 | .setup = i9xx_setup, |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 1282 | .cleanup = i9xx_cleanup, |
Daniel Vetter | a696359 | 2010-09-11 14:01:43 +0200 | [diff] [blame] | 1283 | .write_entry = i965_write_entry, |
Daniel Vetter | 22533b4 | 2010-09-12 16:38:55 +0200 | [diff] [blame] | 1284 | .dma_mask_size = 36, |
Daniel Vetter | 450f2b3 | 2010-09-11 23:48:25 +0200 | [diff] [blame] | 1285 | .check_flags = i830_check_flags, |
Daniel Vetter | 1b263f2 | 2010-09-12 00:27:24 +0200 | [diff] [blame] | 1286 | .chipset_flush = i9xx_chipset_flush, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1287 | }; |
| 1288 | static const struct intel_gtt_driver i965_gtt_driver = { |
| 1289 | .gen = 4, |
Chris Wilson | 100519e | 2010-10-31 10:37:02 +0000 | [diff] [blame] | 1290 | .has_pgtbl_enable = 1, |
Daniel Vetter | 2d2430c | 2010-08-29 17:35:30 +0200 | [diff] [blame] | 1291 | .setup = i9xx_setup, |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 1292 | .cleanup = i9xx_cleanup, |
Daniel Vetter | a696359 | 2010-09-11 14:01:43 +0200 | [diff] [blame] | 1293 | .write_entry = i965_write_entry, |
Daniel Vetter | 22533b4 | 2010-09-12 16:38:55 +0200 | [diff] [blame] | 1294 | .dma_mask_size = 36, |
Daniel Vetter | 450f2b3 | 2010-09-11 23:48:25 +0200 | [diff] [blame] | 1295 | .check_flags = i830_check_flags, |
Daniel Vetter | 1b263f2 | 2010-09-12 00:27:24 +0200 | [diff] [blame] | 1296 | .chipset_flush = i9xx_chipset_flush, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1297 | }; |
| 1298 | static const struct intel_gtt_driver g4x_gtt_driver = { |
| 1299 | .gen = 5, |
Daniel Vetter | 2d2430c | 2010-08-29 17:35:30 +0200 | [diff] [blame] | 1300 | .setup = i9xx_setup, |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 1301 | .cleanup = i9xx_cleanup, |
Daniel Vetter | a696359 | 2010-09-11 14:01:43 +0200 | [diff] [blame] | 1302 | .write_entry = i965_write_entry, |
Daniel Vetter | 22533b4 | 2010-09-12 16:38:55 +0200 | [diff] [blame] | 1303 | .dma_mask_size = 36, |
Daniel Vetter | 450f2b3 | 2010-09-11 23:48:25 +0200 | [diff] [blame] | 1304 | .check_flags = i830_check_flags, |
Daniel Vetter | 1b263f2 | 2010-09-12 00:27:24 +0200 | [diff] [blame] | 1305 | .chipset_flush = i9xx_chipset_flush, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1306 | }; |
| 1307 | static const struct intel_gtt_driver ironlake_gtt_driver = { |
| 1308 | .gen = 5, |
| 1309 | .is_ironlake = 1, |
Daniel Vetter | 2d2430c | 2010-08-29 17:35:30 +0200 | [diff] [blame] | 1310 | .setup = i9xx_setup, |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 1311 | .cleanup = i9xx_cleanup, |
Daniel Vetter | a696359 | 2010-09-11 14:01:43 +0200 | [diff] [blame] | 1312 | .write_entry = i965_write_entry, |
Daniel Vetter | 22533b4 | 2010-09-12 16:38:55 +0200 | [diff] [blame] | 1313 | .dma_mask_size = 36, |
Daniel Vetter | 450f2b3 | 2010-09-11 23:48:25 +0200 | [diff] [blame] | 1314 | .check_flags = i830_check_flags, |
Daniel Vetter | 1b263f2 | 2010-09-12 00:27:24 +0200 | [diff] [blame] | 1315 | .chipset_flush = i9xx_chipset_flush, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1316 | }; |
| 1317 | static const struct intel_gtt_driver sandybridge_gtt_driver = { |
| 1318 | .gen = 6, |
Daniel Vetter | 2d2430c | 2010-08-29 17:35:30 +0200 | [diff] [blame] | 1319 | .setup = i9xx_setup, |
Daniel Vetter | ae83dd5 | 2010-09-12 17:11:15 +0200 | [diff] [blame] | 1320 | .cleanup = gen6_cleanup, |
Daniel Vetter | 97ef1bd | 2010-09-09 17:52:20 +0200 | [diff] [blame] | 1321 | .write_entry = gen6_write_entry, |
Daniel Vetter | 22533b4 | 2010-09-12 16:38:55 +0200 | [diff] [blame] | 1322 | .dma_mask_size = 40, |
Daniel Vetter | 90cb149 | 2010-09-11 23:55:20 +0200 | [diff] [blame] | 1323 | .check_flags = gen6_check_flags, |
Daniel Vetter | 1b263f2 | 2010-09-12 00:27:24 +0200 | [diff] [blame] | 1324 | .chipset_flush = i9xx_chipset_flush, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1325 | }; |
| 1326 | |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1327 | /* Table to describe Intel GMCH and AGP/PCIE GART drivers. At least one of |
| 1328 | * driver and gmch_driver must be non-null, and find_gmch will determine |
| 1329 | * which one should be used if a gmch_chip_id is present. |
| 1330 | */ |
| 1331 | static const struct intel_gtt_driver_description { |
| 1332 | unsigned int gmch_chip_id; |
| 1333 | char *name; |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1334 | const struct intel_gtt_driver *gtt_driver; |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1335 | } intel_gtt_chipsets[] = { |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1336 | { PCI_DEVICE_ID_INTEL_82810_IG1, "i810", |
Daniel Vetter | bdd3072 | 2010-09-12 12:34:44 +0200 | [diff] [blame] | 1337 | &i81x_gtt_driver}, |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1338 | { PCI_DEVICE_ID_INTEL_82810_IG3, "i810", |
Daniel Vetter | bdd3072 | 2010-09-12 12:34:44 +0200 | [diff] [blame] | 1339 | &i81x_gtt_driver}, |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1340 | { PCI_DEVICE_ID_INTEL_82810E_IG, "i810", |
Daniel Vetter | bdd3072 | 2010-09-12 12:34:44 +0200 | [diff] [blame] | 1341 | &i81x_gtt_driver}, |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1342 | { PCI_DEVICE_ID_INTEL_82815_CGC, "i815", |
Daniel Vetter | bdd3072 | 2010-09-12 12:34:44 +0200 | [diff] [blame] | 1343 | &i81x_gtt_driver}, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1344 | { PCI_DEVICE_ID_INTEL_82830_CGC, "830M", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1345 | &i8xx_gtt_driver}, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1346 | { PCI_DEVICE_ID_INTEL_82845G_IG, "830M", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1347 | &i8xx_gtt_driver}, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1348 | { PCI_DEVICE_ID_INTEL_82854_IG, "854", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1349 | &i8xx_gtt_driver}, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1350 | { PCI_DEVICE_ID_INTEL_82855GM_IG, "855GM", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1351 | &i8xx_gtt_driver}, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1352 | { PCI_DEVICE_ID_INTEL_82865_IG, "865", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1353 | &i8xx_gtt_driver}, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1354 | { PCI_DEVICE_ID_INTEL_E7221_IG, "E7221 (i915)", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1355 | &i915_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1356 | { PCI_DEVICE_ID_INTEL_82915G_IG, "915G", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1357 | &i915_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1358 | { PCI_DEVICE_ID_INTEL_82915GM_IG, "915GM", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1359 | &i915_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1360 | { PCI_DEVICE_ID_INTEL_82945G_IG, "945G", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1361 | &i915_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1362 | { PCI_DEVICE_ID_INTEL_82945GM_IG, "945GM", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1363 | &i915_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1364 | { PCI_DEVICE_ID_INTEL_82945GME_IG, "945GME", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1365 | &i915_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1366 | { PCI_DEVICE_ID_INTEL_82946GZ_IG, "946GZ", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1367 | &i965_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1368 | { PCI_DEVICE_ID_INTEL_82G35_IG, "G35", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1369 | &i965_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1370 | { PCI_DEVICE_ID_INTEL_82965Q_IG, "965Q", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1371 | &i965_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1372 | { PCI_DEVICE_ID_INTEL_82965G_IG, "965G", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1373 | &i965_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1374 | { PCI_DEVICE_ID_INTEL_82965GM_IG, "965GM", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1375 | &i965_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1376 | { PCI_DEVICE_ID_INTEL_82965GME_IG, "965GME/GLE", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1377 | &i965_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1378 | { PCI_DEVICE_ID_INTEL_G33_IG, "G33", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1379 | &g33_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1380 | { PCI_DEVICE_ID_INTEL_Q35_IG, "Q35", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1381 | &g33_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1382 | { PCI_DEVICE_ID_INTEL_Q33_IG, "Q33", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1383 | &g33_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1384 | { PCI_DEVICE_ID_INTEL_PINEVIEW_M_IG, "GMA3150", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1385 | &pineview_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1386 | { PCI_DEVICE_ID_INTEL_PINEVIEW_IG, "GMA3150", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1387 | &pineview_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1388 | { PCI_DEVICE_ID_INTEL_GM45_IG, "GM45", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1389 | &g4x_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1390 | { PCI_DEVICE_ID_INTEL_EAGLELAKE_IG, "Eaglelake", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1391 | &g4x_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1392 | { PCI_DEVICE_ID_INTEL_Q45_IG, "Q45/Q43", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1393 | &g4x_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1394 | { PCI_DEVICE_ID_INTEL_G45_IG, "G45/G43", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1395 | &g4x_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1396 | { PCI_DEVICE_ID_INTEL_B43_IG, "B43", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1397 | &g4x_gtt_driver }, |
Chris Wilson | e9e5f8e | 2010-09-21 11:19:32 +0100 | [diff] [blame] | 1398 | { PCI_DEVICE_ID_INTEL_B43_1_IG, "B43", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1399 | &g4x_gtt_driver }, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1400 | { PCI_DEVICE_ID_INTEL_G41_IG, "G41", |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1401 | &g4x_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1402 | { PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG, |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1403 | "HD Graphics", &ironlake_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1404 | { PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG, |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1405 | "HD Graphics", &ironlake_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1406 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_GT1_IG, |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1407 | "Sandybridge", &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1408 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_GT2_IG, |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1409 | "Sandybridge", &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1410 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_GT2_PLUS_IG, |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1411 | "Sandybridge", &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1412 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_GT1_IG, |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1413 | "Sandybridge", &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1414 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_GT2_IG, |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1415 | "Sandybridge", &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1416 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_GT2_PLUS_IG, |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1417 | "Sandybridge", &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1418 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_S_IG, |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1419 | "Sandybridge", &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1420 | { 0, NULL, NULL } |
| 1421 | }; |
| 1422 | |
| 1423 | static int find_gmch(u16 device) |
| 1424 | { |
| 1425 | struct pci_dev *gmch_device; |
| 1426 | |
| 1427 | gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL); |
| 1428 | if (gmch_device && PCI_FUNC(gmch_device->devfn) != 0) { |
| 1429 | gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1430 | device, gmch_device); |
| 1431 | } |
| 1432 | |
| 1433 | if (!gmch_device) |
| 1434 | return 0; |
| 1435 | |
| 1436 | intel_private.pcidev = gmch_device; |
| 1437 | return 1; |
| 1438 | } |
| 1439 | |
Daniel Vetter | e2404e7 | 2010-09-08 17:29:51 +0200 | [diff] [blame] | 1440 | int intel_gmch_probe(struct pci_dev *pdev, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1441 | struct agp_bridge_data *bridge) |
| 1442 | { |
| 1443 | int i, mask; |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1444 | intel_private.driver = NULL; |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1445 | |
| 1446 | for (i = 0; intel_gtt_chipsets[i].name != NULL; i++) { |
| 1447 | if (find_gmch(intel_gtt_chipsets[i].gmch_chip_id)) { |
Daniel Vetter | 625dd9d | 2010-11-04 20:07:57 +0100 | [diff] [blame] | 1448 | intel_private.driver = |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1449 | intel_gtt_chipsets[i].gtt_driver; |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1450 | break; |
| 1451 | } |
| 1452 | } |
| 1453 | |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1454 | if (!intel_private.driver) |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1455 | return 0; |
| 1456 | |
Daniel Vetter | ff26860 | 2010-11-05 15:43:35 +0100 | [diff] [blame] | 1457 | bridge->driver = &intel_fake_agp_driver; |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1458 | bridge->dev_private_data = &intel_private; |
| 1459 | bridge->dev = pdev; |
| 1460 | |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1461 | intel_private.bridge_dev = pci_dev_get(pdev); |
| 1462 | |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1463 | dev_info(&pdev->dev, "Intel %s Chipset\n", intel_gtt_chipsets[i].name); |
| 1464 | |
Daniel Vetter | 22533b4 | 2010-09-12 16:38:55 +0200 | [diff] [blame] | 1465 | mask = intel_private.driver->dma_mask_size; |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1466 | if (pci_set_dma_mask(intel_private.pcidev, DMA_BIT_MASK(mask))) |
| 1467 | dev_err(&intel_private.pcidev->dev, |
| 1468 | "set gfx device dma mask %d-bit failed!\n", mask); |
| 1469 | else |
| 1470 | pci_set_consistent_dma_mask(intel_private.pcidev, |
| 1471 | DMA_BIT_MASK(mask)); |
| 1472 | |
Daniel Vetter | 820647b | 2010-11-05 13:30:14 +0100 | [diff] [blame] | 1473 | /*if (bridge->driver == &intel_810_driver) |
| 1474 | return 1;*/ |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 1475 | |
Daniel Vetter | 3b15a9d | 2010-08-29 14:18:49 +0200 | [diff] [blame] | 1476 | if (intel_gtt_init() != 0) |
| 1477 | return 0; |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 1478 | |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1479 | return 1; |
| 1480 | } |
Daniel Vetter | e2404e7 | 2010-09-08 17:29:51 +0200 | [diff] [blame] | 1481 | EXPORT_SYMBOL(intel_gmch_probe); |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1482 | |
Chris Wilson | c64f7ba | 2010-11-23 14:24:24 +0000 | [diff] [blame] | 1483 | const struct intel_gtt *intel_gtt_get(void) |
Daniel Vetter | 1996675 | 2010-09-06 20:08:44 +0200 | [diff] [blame] | 1484 | { |
| 1485 | return &intel_private.base; |
| 1486 | } |
| 1487 | EXPORT_SYMBOL(intel_gtt_get); |
| 1488 | |
Daniel Vetter | 40ce657 | 2010-11-05 18:12:18 +0100 | [diff] [blame] | 1489 | void intel_gtt_chipset_flush(void) |
| 1490 | { |
| 1491 | if (intel_private.driver->chipset_flush) |
| 1492 | intel_private.driver->chipset_flush(); |
| 1493 | } |
| 1494 | EXPORT_SYMBOL(intel_gtt_chipset_flush); |
| 1495 | |
Daniel Vetter | e2404e7 | 2010-09-08 17:29:51 +0200 | [diff] [blame] | 1496 | void intel_gmch_remove(struct pci_dev *pdev) |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1497 | { |
| 1498 | if (intel_private.pcidev) |
| 1499 | pci_dev_put(intel_private.pcidev); |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1500 | if (intel_private.bridge_dev) |
| 1501 | pci_dev_put(intel_private.bridge_dev); |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1502 | } |
Daniel Vetter | e2404e7 | 2010-09-08 17:29:51 +0200 | [diff] [blame] | 1503 | EXPORT_SYMBOL(intel_gmch_remove); |
| 1504 | |
| 1505 | MODULE_AUTHOR("Dave Jones <davej@redhat.com>"); |
| 1506 | MODULE_LICENSE("GPL and additional rights"); |