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" |
| 27 | #include <linux/intel-gtt.h> |
Daniel Vetter | 0ade638 | 2010-08-24 22:18:41 +0200 | [diff] [blame] | 28 | #include <drm/intel-gtt.h> |
Daniel Vetter | e2404e7 | 2010-09-08 17:29:51 +0200 | [diff] [blame] | 29 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 30 | /* |
| 31 | * If we have Intel graphics, we're not going to have anything other than |
| 32 | * an Intel IOMMU. So make the correct use of the PCI DMA API contingent |
| 33 | * on the Intel IOMMU support (CONFIG_DMAR). |
| 34 | * Only newer chipsets need to bother with this, of course. |
| 35 | */ |
| 36 | #ifdef CONFIG_DMAR |
| 37 | #define USE_PCI_DMA_API 1 |
| 38 | #endif |
| 39 | |
Jesse Barnes | d1d6ca7 | 2010-07-08 09:22:46 -0700 | [diff] [blame] | 40 | /* Max amount of stolen space, anything above will be returned to Linux */ |
| 41 | int intel_max_stolen = 32 * 1024 * 1024; |
| 42 | EXPORT_SYMBOL(intel_max_stolen); |
| 43 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 44 | static const struct aper_size_info_fixed intel_i810_sizes[] = |
| 45 | { |
| 46 | {64, 16384, 4}, |
| 47 | /* The 32M mode still requires a 64k gatt */ |
| 48 | {32, 8192, 4} |
| 49 | }; |
| 50 | |
| 51 | #define AGP_DCACHE_MEMORY 1 |
| 52 | #define AGP_PHYS_MEMORY 2 |
| 53 | #define INTEL_AGP_CACHED_MEMORY 3 |
| 54 | |
| 55 | static struct gatt_mask intel_i810_masks[] = |
| 56 | { |
| 57 | {.mask = I810_PTE_VALID, .type = 0}, |
| 58 | {.mask = (I810_PTE_VALID | I810_PTE_LOCAL), .type = AGP_DCACHE_MEMORY}, |
| 59 | {.mask = I810_PTE_VALID, .type = 0}, |
| 60 | {.mask = I810_PTE_VALID | I830_PTE_SYSTEM_CACHED, |
| 61 | .type = INTEL_AGP_CACHED_MEMORY} |
| 62 | }; |
| 63 | |
Zhenyu Wang | f8f235e | 2010-08-27 11:08:57 +0800 | [diff] [blame] | 64 | #define INTEL_AGP_UNCACHED_MEMORY 0 |
| 65 | #define INTEL_AGP_CACHED_MEMORY_LLC 1 |
| 66 | #define INTEL_AGP_CACHED_MEMORY_LLC_GFDT 2 |
| 67 | #define INTEL_AGP_CACHED_MEMORY_LLC_MLC 3 |
| 68 | #define INTEL_AGP_CACHED_MEMORY_LLC_MLC_GFDT 4 |
| 69 | |
| 70 | static struct gatt_mask intel_gen6_masks[] = |
| 71 | { |
| 72 | {.mask = I810_PTE_VALID | GEN6_PTE_UNCACHED, |
| 73 | .type = INTEL_AGP_UNCACHED_MEMORY }, |
| 74 | {.mask = I810_PTE_VALID | GEN6_PTE_LLC, |
| 75 | .type = INTEL_AGP_CACHED_MEMORY_LLC }, |
| 76 | {.mask = I810_PTE_VALID | GEN6_PTE_LLC | GEN6_PTE_GFDT, |
| 77 | .type = INTEL_AGP_CACHED_MEMORY_LLC_GFDT }, |
| 78 | {.mask = I810_PTE_VALID | GEN6_PTE_LLC_MLC, |
| 79 | .type = INTEL_AGP_CACHED_MEMORY_LLC_MLC }, |
| 80 | {.mask = I810_PTE_VALID | GEN6_PTE_LLC_MLC | GEN6_PTE_GFDT, |
| 81 | .type = INTEL_AGP_CACHED_MEMORY_LLC_MLC_GFDT }, |
| 82 | }; |
| 83 | |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 84 | struct intel_gtt_driver { |
| 85 | unsigned int gen : 8; |
| 86 | unsigned int is_g33 : 1; |
| 87 | unsigned int is_pineview : 1; |
| 88 | unsigned int is_ironlake : 1; |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame^] | 89 | /* Chipset specific GTT setup */ |
| 90 | int (*setup)(void); |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 91 | }; |
| 92 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 93 | static struct _intel_private { |
Daniel Vetter | 0ade638 | 2010-08-24 22:18:41 +0200 | [diff] [blame] | 94 | struct intel_gtt base; |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 95 | const struct intel_gtt_driver *driver; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 96 | struct pci_dev *pcidev; /* device one */ |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 97 | struct pci_dev *bridge_dev; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 98 | u8 __iomem *registers; |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 99 | phys_addr_t gtt_bus_addr; |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame^] | 100 | phys_addr_t gma_bus_addr; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 101 | u32 __iomem *gtt; /* I915G */ |
| 102 | int num_dcache_entries; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 103 | union { |
| 104 | void __iomem *i9xx_flush_page; |
| 105 | void *i8xx_flush_page; |
| 106 | }; |
| 107 | struct page *i8xx_page; |
| 108 | struct resource ifp_resource; |
| 109 | int resource_valid; |
| 110 | } intel_private; |
| 111 | |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 112 | #define INTEL_GTT_GEN intel_private.driver->gen |
| 113 | #define IS_G33 intel_private.driver->is_g33 |
| 114 | #define IS_PINEVIEW intel_private.driver->is_pineview |
| 115 | #define IS_IRONLAKE intel_private.driver->is_ironlake |
| 116 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 117 | #ifdef USE_PCI_DMA_API |
| 118 | static int intel_agp_map_page(struct page *page, dma_addr_t *ret) |
| 119 | { |
| 120 | *ret = pci_map_page(intel_private.pcidev, page, 0, |
| 121 | PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); |
| 122 | if (pci_dma_mapping_error(intel_private.pcidev, *ret)) |
| 123 | return -EINVAL; |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static void intel_agp_unmap_page(struct page *page, dma_addr_t dma) |
| 128 | { |
| 129 | pci_unmap_page(intel_private.pcidev, dma, |
| 130 | PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); |
| 131 | } |
| 132 | |
| 133 | static void intel_agp_free_sglist(struct agp_memory *mem) |
| 134 | { |
| 135 | struct sg_table st; |
| 136 | |
| 137 | st.sgl = mem->sg_list; |
| 138 | st.orig_nents = st.nents = mem->page_count; |
| 139 | |
| 140 | sg_free_table(&st); |
| 141 | |
| 142 | mem->sg_list = NULL; |
| 143 | mem->num_sg = 0; |
| 144 | } |
| 145 | |
| 146 | static int intel_agp_map_memory(struct agp_memory *mem) |
| 147 | { |
| 148 | struct sg_table st; |
| 149 | struct scatterlist *sg; |
| 150 | int i; |
| 151 | |
| 152 | DBG("try mapping %lu pages\n", (unsigned long)mem->page_count); |
| 153 | |
| 154 | if (sg_alloc_table(&st, mem->page_count, GFP_KERNEL)) |
Chris Wilson | 831cd44 | 2010-07-24 18:29:37 +0100 | [diff] [blame] | 155 | goto err; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 156 | |
| 157 | mem->sg_list = sg = st.sgl; |
| 158 | |
| 159 | for (i = 0 ; i < mem->page_count; i++, sg = sg_next(sg)) |
| 160 | sg_set_page(sg, mem->pages[i], PAGE_SIZE, 0); |
| 161 | |
| 162 | mem->num_sg = pci_map_sg(intel_private.pcidev, mem->sg_list, |
| 163 | mem->page_count, PCI_DMA_BIDIRECTIONAL); |
Chris Wilson | 831cd44 | 2010-07-24 18:29:37 +0100 | [diff] [blame] | 164 | if (unlikely(!mem->num_sg)) |
| 165 | goto err; |
| 166 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 167 | return 0; |
Chris Wilson | 831cd44 | 2010-07-24 18:29:37 +0100 | [diff] [blame] | 168 | |
| 169 | err: |
| 170 | sg_free_table(&st); |
| 171 | return -ENOMEM; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static void intel_agp_unmap_memory(struct agp_memory *mem) |
| 175 | { |
| 176 | DBG("try unmapping %lu pages\n", (unsigned long)mem->page_count); |
| 177 | |
| 178 | pci_unmap_sg(intel_private.pcidev, mem->sg_list, |
| 179 | mem->page_count, PCI_DMA_BIDIRECTIONAL); |
| 180 | intel_agp_free_sglist(mem); |
| 181 | } |
| 182 | |
| 183 | static void intel_agp_insert_sg_entries(struct agp_memory *mem, |
| 184 | off_t pg_start, int mask_type) |
| 185 | { |
| 186 | struct scatterlist *sg; |
| 187 | int i, j; |
| 188 | |
| 189 | j = pg_start; |
| 190 | |
| 191 | WARN_ON(!mem->num_sg); |
| 192 | |
| 193 | if (mem->num_sg == mem->page_count) { |
| 194 | for_each_sg(mem->sg_list, sg, mem->page_count, i) { |
| 195 | writel(agp_bridge->driver->mask_memory(agp_bridge, |
| 196 | sg_dma_address(sg), mask_type), |
| 197 | intel_private.gtt+j); |
| 198 | j++; |
| 199 | } |
| 200 | } else { |
| 201 | /* sg may merge pages, but we have to separate |
| 202 | * per-page addr for GTT */ |
| 203 | unsigned int len, m; |
| 204 | |
| 205 | for_each_sg(mem->sg_list, sg, mem->num_sg, i) { |
| 206 | len = sg_dma_len(sg) / PAGE_SIZE; |
| 207 | for (m = 0; m < len; m++) { |
| 208 | writel(agp_bridge->driver->mask_memory(agp_bridge, |
| 209 | sg_dma_address(sg) + m * PAGE_SIZE, |
| 210 | mask_type), |
| 211 | intel_private.gtt+j); |
| 212 | j++; |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | readl(intel_private.gtt+j-1); |
| 217 | } |
| 218 | |
| 219 | #else |
| 220 | |
| 221 | static void intel_agp_insert_sg_entries(struct agp_memory *mem, |
| 222 | off_t pg_start, int mask_type) |
| 223 | { |
| 224 | int i, j; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 225 | |
| 226 | for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { |
| 227 | writel(agp_bridge->driver->mask_memory(agp_bridge, |
| 228 | page_to_phys(mem->pages[i]), mask_type), |
| 229 | intel_private.gtt+j); |
| 230 | } |
| 231 | |
| 232 | readl(intel_private.gtt+j-1); |
| 233 | } |
| 234 | |
| 235 | #endif |
| 236 | |
| 237 | static int intel_i810_fetch_size(void) |
| 238 | { |
| 239 | u32 smram_miscc; |
| 240 | struct aper_size_info_fixed *values; |
| 241 | |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 242 | pci_read_config_dword(intel_private.bridge_dev, |
| 243 | I810_SMRAM_MISCC, &smram_miscc); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 244 | values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes); |
| 245 | |
| 246 | if ((smram_miscc & I810_GMS) == I810_GMS_DISABLE) { |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 247 | dev_warn(&intel_private.bridge_dev->dev, "i810 is disabled\n"); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 248 | return 0; |
| 249 | } |
| 250 | if ((smram_miscc & I810_GFX_MEM_WIN_SIZE) == I810_GFX_MEM_WIN_32M) { |
Daniel Vetter | e158316 | 2010-04-14 00:29:58 +0200 | [diff] [blame] | 251 | agp_bridge->current_size = (void *) (values + 1); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 252 | agp_bridge->aperture_size_idx = 1; |
| 253 | return values[1].size; |
| 254 | } else { |
Daniel Vetter | e158316 | 2010-04-14 00:29:58 +0200 | [diff] [blame] | 255 | agp_bridge->current_size = (void *) (values); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 256 | agp_bridge->aperture_size_idx = 0; |
| 257 | return values[0].size; |
| 258 | } |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | static int intel_i810_configure(void) |
| 264 | { |
| 265 | struct aper_size_info_fixed *current_size; |
| 266 | u32 temp; |
| 267 | int i; |
| 268 | |
| 269 | current_size = A_SIZE_FIX(agp_bridge->current_size); |
| 270 | |
| 271 | if (!intel_private.registers) { |
| 272 | pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp); |
| 273 | temp &= 0xfff80000; |
| 274 | |
| 275 | intel_private.registers = ioremap(temp, 128 * 4096); |
| 276 | if (!intel_private.registers) { |
| 277 | dev_err(&intel_private.pcidev->dev, |
| 278 | "can't remap memory\n"); |
| 279 | return -ENOMEM; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | if ((readl(intel_private.registers+I810_DRAM_CTL) |
| 284 | & I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) { |
| 285 | /* This will need to be dynamically assigned */ |
| 286 | dev_info(&intel_private.pcidev->dev, |
| 287 | "detected 4MB dedicated video ram\n"); |
| 288 | intel_private.num_dcache_entries = 1024; |
| 289 | } |
| 290 | pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp); |
| 291 | agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK); |
| 292 | writel(agp_bridge->gatt_bus_addr | I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL); |
| 293 | readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */ |
| 294 | |
| 295 | if (agp_bridge->driver->needs_scratch_page) { |
| 296 | for (i = 0; i < current_size->num_entries; i++) { |
| 297 | writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4)); |
| 298 | } |
| 299 | readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); /* PCI posting. */ |
| 300 | } |
| 301 | global_cache_flush(); |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | static void intel_i810_cleanup(void) |
| 306 | { |
| 307 | writel(0, intel_private.registers+I810_PGETBL_CTL); |
| 308 | readl(intel_private.registers); /* PCI Posting. */ |
| 309 | iounmap(intel_private.registers); |
| 310 | } |
| 311 | |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 312 | 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] | 313 | { |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | /* Exists to support ARGB cursors */ |
| 318 | static struct page *i8xx_alloc_pages(void) |
| 319 | { |
| 320 | struct page *page; |
| 321 | |
| 322 | page = alloc_pages(GFP_KERNEL | GFP_DMA32, 2); |
| 323 | if (page == NULL) |
| 324 | return NULL; |
| 325 | |
| 326 | if (set_pages_uc(page, 4) < 0) { |
| 327 | set_pages_wb(page, 4); |
| 328 | __free_pages(page, 2); |
| 329 | return NULL; |
| 330 | } |
| 331 | get_page(page); |
| 332 | atomic_inc(&agp_bridge->current_memory_agp); |
| 333 | return page; |
| 334 | } |
| 335 | |
| 336 | static void i8xx_destroy_pages(struct page *page) |
| 337 | { |
| 338 | if (page == NULL) |
| 339 | return; |
| 340 | |
| 341 | set_pages_wb(page, 4); |
| 342 | put_page(page); |
| 343 | __free_pages(page, 2); |
| 344 | atomic_dec(&agp_bridge->current_memory_agp); |
| 345 | } |
| 346 | |
| 347 | static int intel_i830_type_to_mask_type(struct agp_bridge_data *bridge, |
| 348 | int type) |
| 349 | { |
| 350 | if (type < AGP_USER_TYPES) |
| 351 | return type; |
| 352 | else if (type == AGP_USER_CACHED_MEMORY) |
| 353 | return INTEL_AGP_CACHED_MEMORY; |
| 354 | else |
| 355 | return 0; |
| 356 | } |
| 357 | |
Zhenyu Wang | f8f235e | 2010-08-27 11:08:57 +0800 | [diff] [blame] | 358 | static int intel_gen6_type_to_mask_type(struct agp_bridge_data *bridge, |
| 359 | int type) |
| 360 | { |
| 361 | unsigned int type_mask = type & ~AGP_USER_CACHED_MEMORY_GFDT; |
| 362 | unsigned int gfdt = type & AGP_USER_CACHED_MEMORY_GFDT; |
| 363 | |
| 364 | if (type_mask == AGP_USER_UNCACHED_MEMORY) |
| 365 | return INTEL_AGP_UNCACHED_MEMORY; |
| 366 | else if (type_mask == AGP_USER_CACHED_MEMORY_LLC_MLC) |
| 367 | return gfdt ? INTEL_AGP_CACHED_MEMORY_LLC_MLC_GFDT : |
| 368 | INTEL_AGP_CACHED_MEMORY_LLC_MLC; |
| 369 | else /* set 'normal'/'cached' to LLC by default */ |
| 370 | return gfdt ? INTEL_AGP_CACHED_MEMORY_LLC_GFDT : |
| 371 | INTEL_AGP_CACHED_MEMORY_LLC; |
| 372 | } |
| 373 | |
| 374 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 375 | static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start, |
| 376 | int type) |
| 377 | { |
| 378 | int i, j, num_entries; |
| 379 | void *temp; |
| 380 | int ret = -EINVAL; |
| 381 | int mask_type; |
| 382 | |
| 383 | if (mem->page_count == 0) |
| 384 | goto out; |
| 385 | |
| 386 | temp = agp_bridge->current_size; |
| 387 | num_entries = A_SIZE_FIX(temp)->num_entries; |
| 388 | |
| 389 | if ((pg_start + mem->page_count) > num_entries) |
| 390 | goto out_err; |
| 391 | |
| 392 | |
| 393 | for (j = pg_start; j < (pg_start + mem->page_count); j++) { |
| 394 | if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+j))) { |
| 395 | ret = -EBUSY; |
| 396 | goto out_err; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | if (type != mem->type) |
| 401 | goto out_err; |
| 402 | |
| 403 | mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type); |
| 404 | |
| 405 | switch (mask_type) { |
| 406 | case AGP_DCACHE_MEMORY: |
| 407 | if (!mem->is_flushed) |
| 408 | global_cache_flush(); |
| 409 | for (i = pg_start; i < (pg_start + mem->page_count); i++) { |
| 410 | writel((i*4096)|I810_PTE_LOCAL|I810_PTE_VALID, |
| 411 | intel_private.registers+I810_PTE_BASE+(i*4)); |
| 412 | } |
| 413 | readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); |
| 414 | break; |
| 415 | case AGP_PHYS_MEMORY: |
| 416 | case AGP_NORMAL_MEMORY: |
| 417 | if (!mem->is_flushed) |
| 418 | global_cache_flush(); |
| 419 | for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { |
| 420 | writel(agp_bridge->driver->mask_memory(agp_bridge, |
| 421 | page_to_phys(mem->pages[i]), mask_type), |
| 422 | intel_private.registers+I810_PTE_BASE+(j*4)); |
| 423 | } |
| 424 | readl(intel_private.registers+I810_PTE_BASE+((j-1)*4)); |
| 425 | break; |
| 426 | default: |
| 427 | goto out_err; |
| 428 | } |
| 429 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 430 | out: |
| 431 | ret = 0; |
| 432 | out_err: |
| 433 | mem->is_flushed = true; |
| 434 | return ret; |
| 435 | } |
| 436 | |
| 437 | static int intel_i810_remove_entries(struct agp_memory *mem, off_t pg_start, |
| 438 | int type) |
| 439 | { |
| 440 | int i; |
| 441 | |
| 442 | if (mem->page_count == 0) |
| 443 | return 0; |
| 444 | |
| 445 | for (i = pg_start; i < (mem->page_count + pg_start); i++) { |
| 446 | writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4)); |
| 447 | } |
| 448 | readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); |
| 449 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | /* |
| 454 | * The i810/i830 requires a physical address to program its mouse |
| 455 | * pointer into hardware. |
| 456 | * However the Xserver still writes to it through the agp aperture. |
| 457 | */ |
| 458 | static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type) |
| 459 | { |
| 460 | struct agp_memory *new; |
| 461 | struct page *page; |
| 462 | |
| 463 | switch (pg_count) { |
| 464 | case 1: page = agp_bridge->driver->agp_alloc_page(agp_bridge); |
| 465 | break; |
| 466 | case 4: |
| 467 | /* kludge to get 4 physical pages for ARGB cursor */ |
| 468 | page = i8xx_alloc_pages(); |
| 469 | break; |
| 470 | default: |
| 471 | return NULL; |
| 472 | } |
| 473 | |
| 474 | if (page == NULL) |
| 475 | return NULL; |
| 476 | |
| 477 | new = agp_create_memory(pg_count); |
| 478 | if (new == NULL) |
| 479 | return NULL; |
| 480 | |
| 481 | new->pages[0] = page; |
| 482 | if (pg_count == 4) { |
| 483 | /* kludge to get 4 physical pages for ARGB cursor */ |
| 484 | new->pages[1] = new->pages[0] + 1; |
| 485 | new->pages[2] = new->pages[1] + 1; |
| 486 | new->pages[3] = new->pages[2] + 1; |
| 487 | } |
| 488 | new->page_count = pg_count; |
| 489 | new->num_scratch_pages = pg_count; |
| 490 | new->type = AGP_PHYS_MEMORY; |
| 491 | new->physical = page_to_phys(new->pages[0]); |
| 492 | return new; |
| 493 | } |
| 494 | |
| 495 | static struct agp_memory *intel_i810_alloc_by_type(size_t pg_count, int type) |
| 496 | { |
| 497 | struct agp_memory *new; |
| 498 | |
| 499 | if (type == AGP_DCACHE_MEMORY) { |
| 500 | if (pg_count != intel_private.num_dcache_entries) |
| 501 | return NULL; |
| 502 | |
| 503 | new = agp_create_memory(1); |
| 504 | if (new == NULL) |
| 505 | return NULL; |
| 506 | |
| 507 | new->type = AGP_DCACHE_MEMORY; |
| 508 | new->page_count = pg_count; |
| 509 | new->num_scratch_pages = 0; |
| 510 | agp_free_page_array(new); |
| 511 | return new; |
| 512 | } |
| 513 | if (type == AGP_PHYS_MEMORY) |
| 514 | return alloc_agpphysmem_i8xx(pg_count, type); |
| 515 | return NULL; |
| 516 | } |
| 517 | |
| 518 | static void intel_i810_free_by_type(struct agp_memory *curr) |
| 519 | { |
| 520 | agp_free_key(curr->key); |
| 521 | if (curr->type == AGP_PHYS_MEMORY) { |
| 522 | if (curr->page_count == 4) |
| 523 | i8xx_destroy_pages(curr->pages[0]); |
| 524 | else { |
| 525 | agp_bridge->driver->agp_destroy_page(curr->pages[0], |
| 526 | AGP_PAGE_DESTROY_UNMAP); |
| 527 | agp_bridge->driver->agp_destroy_page(curr->pages[0], |
| 528 | AGP_PAGE_DESTROY_FREE); |
| 529 | } |
| 530 | agp_free_page_array(curr); |
| 531 | } |
| 532 | kfree(curr); |
| 533 | } |
| 534 | |
| 535 | static unsigned long intel_i810_mask_memory(struct agp_bridge_data *bridge, |
| 536 | dma_addr_t addr, int type) |
| 537 | { |
| 538 | /* Type checking must be done elsewhere */ |
| 539 | return addr | bridge->driver->masks[type].mask; |
| 540 | } |
| 541 | |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 542 | static struct aper_size_info_fixed intel_fake_agp_sizes[] = |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 543 | { |
| 544 | {128, 32768, 5}, |
| 545 | /* The 64M mode still requires a 128k gatt */ |
| 546 | {64, 16384, 5}, |
| 547 | {256, 65536, 6}, |
| 548 | {512, 131072, 7}, |
| 549 | }; |
| 550 | |
Daniel Vetter | bfde067 | 2010-08-24 23:07:59 +0200 | [diff] [blame] | 551 | static unsigned int intel_gtt_stolen_entries(void) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 552 | { |
| 553 | u16 gmch_ctrl; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 554 | u8 rdct; |
| 555 | int local = 0; |
| 556 | static const int ddt[4] = { 0, 16, 32, 64 }; |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 557 | unsigned int overhead_entries, stolen_entries; |
| 558 | unsigned int stolen_size = 0; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 559 | |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 560 | pci_read_config_word(intel_private.bridge_dev, |
| 561 | I830_GMCH_CTRL, &gmch_ctrl); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 562 | |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 563 | if (INTEL_GTT_GEN > 4 || IS_PINEVIEW) |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 564 | overhead_entries = 0; |
| 565 | else |
| 566 | overhead_entries = intel_private.base.gtt_mappable_entries |
| 567 | / 1024; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 568 | |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 569 | overhead_entries += 1; /* BIOS popup */ |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 570 | |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 571 | if (intel_private.bridge_dev->device == PCI_DEVICE_ID_INTEL_82830_HB || |
| 572 | intel_private.bridge_dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 573 | switch (gmch_ctrl & I830_GMCH_GMS_MASK) { |
| 574 | case I830_GMCH_GMS_STOLEN_512: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 575 | stolen_size = KB(512); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 576 | break; |
| 577 | case I830_GMCH_GMS_STOLEN_1024: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 578 | stolen_size = MB(1); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 579 | break; |
| 580 | case I830_GMCH_GMS_STOLEN_8192: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 581 | stolen_size = MB(8); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 582 | break; |
| 583 | case I830_GMCH_GMS_LOCAL: |
| 584 | rdct = readb(intel_private.registers+I830_RDRAM_CHANNEL_TYPE); |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 585 | stolen_size = (I830_RDRAM_ND(rdct) + 1) * |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 586 | MB(ddt[I830_RDRAM_DDT(rdct)]); |
| 587 | local = 1; |
| 588 | break; |
| 589 | default: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 590 | stolen_size = 0; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 591 | break; |
| 592 | } |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 593 | } else if (INTEL_GTT_GEN == 6) { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 594 | /* |
| 595 | * SandyBridge has new memory control reg at 0x50.w |
| 596 | */ |
| 597 | u16 snb_gmch_ctl; |
| 598 | pci_read_config_word(intel_private.pcidev, SNB_GMCH_CTRL, &snb_gmch_ctl); |
| 599 | switch (snb_gmch_ctl & SNB_GMCH_GMS_STOLEN_MASK) { |
| 600 | case SNB_GMCH_GMS_STOLEN_32M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 601 | stolen_size = MB(32); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 602 | break; |
| 603 | case SNB_GMCH_GMS_STOLEN_64M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 604 | stolen_size = MB(64); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 605 | break; |
| 606 | case SNB_GMCH_GMS_STOLEN_96M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 607 | stolen_size = MB(96); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 608 | break; |
| 609 | case SNB_GMCH_GMS_STOLEN_128M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 610 | stolen_size = MB(128); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 611 | break; |
| 612 | case SNB_GMCH_GMS_STOLEN_160M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 613 | stolen_size = MB(160); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 614 | break; |
| 615 | case SNB_GMCH_GMS_STOLEN_192M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 616 | stolen_size = MB(192); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 617 | break; |
| 618 | case SNB_GMCH_GMS_STOLEN_224M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 619 | stolen_size = MB(224); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 620 | break; |
| 621 | case SNB_GMCH_GMS_STOLEN_256M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 622 | stolen_size = MB(256); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 623 | break; |
| 624 | case SNB_GMCH_GMS_STOLEN_288M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 625 | stolen_size = MB(288); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 626 | break; |
| 627 | case SNB_GMCH_GMS_STOLEN_320M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 628 | stolen_size = MB(320); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 629 | break; |
| 630 | case SNB_GMCH_GMS_STOLEN_352M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 631 | stolen_size = MB(352); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 632 | break; |
| 633 | case SNB_GMCH_GMS_STOLEN_384M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 634 | stolen_size = MB(384); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 635 | break; |
| 636 | case SNB_GMCH_GMS_STOLEN_416M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 637 | stolen_size = MB(416); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 638 | break; |
| 639 | case SNB_GMCH_GMS_STOLEN_448M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 640 | stolen_size = MB(448); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 641 | break; |
| 642 | case SNB_GMCH_GMS_STOLEN_480M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 643 | stolen_size = MB(480); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 644 | break; |
| 645 | case SNB_GMCH_GMS_STOLEN_512M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 646 | stolen_size = MB(512); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 647 | break; |
| 648 | } |
| 649 | } else { |
| 650 | switch (gmch_ctrl & I855_GMCH_GMS_MASK) { |
| 651 | case I855_GMCH_GMS_STOLEN_1M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 652 | stolen_size = MB(1); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 653 | break; |
| 654 | case I855_GMCH_GMS_STOLEN_4M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 655 | stolen_size = MB(4); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 656 | break; |
| 657 | case I855_GMCH_GMS_STOLEN_8M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 658 | stolen_size = MB(8); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 659 | break; |
| 660 | case I855_GMCH_GMS_STOLEN_16M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 661 | stolen_size = MB(16); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 662 | break; |
| 663 | case I855_GMCH_GMS_STOLEN_32M: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 664 | stolen_size = MB(32); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 665 | break; |
| 666 | case I915_GMCH_GMS_STOLEN_48M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 667 | stolen_size = MB(48); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 668 | break; |
| 669 | case I915_GMCH_GMS_STOLEN_64M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 670 | stolen_size = MB(64); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 671 | break; |
| 672 | case G33_GMCH_GMS_STOLEN_128M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 673 | stolen_size = MB(128); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 674 | break; |
| 675 | case G33_GMCH_GMS_STOLEN_256M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 676 | stolen_size = MB(256); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 677 | break; |
| 678 | case INTEL_GMCH_GMS_STOLEN_96M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 679 | stolen_size = MB(96); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 680 | break; |
| 681 | case INTEL_GMCH_GMS_STOLEN_160M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 682 | stolen_size = MB(160); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 683 | break; |
| 684 | case INTEL_GMCH_GMS_STOLEN_224M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 685 | stolen_size = MB(224); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 686 | break; |
| 687 | case INTEL_GMCH_GMS_STOLEN_352M: |
Daniel Vetter | 77ad498 | 2010-08-27 16:25:54 +0200 | [diff] [blame] | 688 | stolen_size = MB(352); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 689 | break; |
| 690 | default: |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 691 | stolen_size = 0; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 692 | break; |
| 693 | } |
| 694 | } |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 695 | |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 696 | if (!local && stolen_size > intel_max_stolen) { |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 697 | dev_info(&intel_private.bridge_dev->dev, |
Jesse Barnes | d1d6ca7 | 2010-07-08 09:22:46 -0700 | [diff] [blame] | 698 | "detected %dK stolen memory, trimming to %dK\n", |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 699 | stolen_size / KB(1), intel_max_stolen / KB(1)); |
| 700 | stolen_size = intel_max_stolen; |
| 701 | } else if (stolen_size > 0) { |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 702 | dev_info(&intel_private.bridge_dev->dev, "detected %dK %s memory\n", |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 703 | stolen_size / KB(1), local ? "local" : "stolen"); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 704 | } else { |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 705 | dev_info(&intel_private.bridge_dev->dev, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 706 | "no pre-allocated video memory detected\n"); |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 707 | stolen_size = 0; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 708 | } |
| 709 | |
Daniel Vetter | d8d9abc | 2010-08-27 16:13:52 +0200 | [diff] [blame] | 710 | stolen_entries = stolen_size/KB(4) - overhead_entries; |
| 711 | |
| 712 | return stolen_entries; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 713 | } |
| 714 | |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 715 | static unsigned int intel_gtt_total_entries(void) |
| 716 | { |
| 717 | int size; |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 718 | |
Daniel Vetter | 210b23c | 2010-08-28 16:14:32 +0200 | [diff] [blame] | 719 | if (IS_G33 || INTEL_GTT_GEN == 4 || INTEL_GTT_GEN == 5) { |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 720 | u32 pgetbl_ctl; |
| 721 | pgetbl_ctl = readl(intel_private.registers+I810_PGETBL_CTL); |
| 722 | |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 723 | switch (pgetbl_ctl & I965_PGETBL_SIZE_MASK) { |
| 724 | case I965_PGETBL_SIZE_128KB: |
Daniel Vetter | e5e408f | 2010-08-28 11:04:32 +0200 | [diff] [blame] | 725 | size = KB(128); |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 726 | break; |
| 727 | case I965_PGETBL_SIZE_256KB: |
Daniel Vetter | e5e408f | 2010-08-28 11:04:32 +0200 | [diff] [blame] | 728 | size = KB(256); |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 729 | break; |
| 730 | case I965_PGETBL_SIZE_512KB: |
Daniel Vetter | e5e408f | 2010-08-28 11:04:32 +0200 | [diff] [blame] | 731 | size = KB(512); |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 732 | break; |
| 733 | case I965_PGETBL_SIZE_1MB: |
Daniel Vetter | e5e408f | 2010-08-28 11:04:32 +0200 | [diff] [blame] | 734 | size = KB(1024); |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 735 | break; |
| 736 | case I965_PGETBL_SIZE_2MB: |
Daniel Vetter | e5e408f | 2010-08-28 11:04:32 +0200 | [diff] [blame] | 737 | size = KB(2048); |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 738 | break; |
| 739 | case I965_PGETBL_SIZE_1_5MB: |
Daniel Vetter | e5e408f | 2010-08-28 11:04:32 +0200 | [diff] [blame] | 740 | size = KB(1024 + 512); |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 741 | break; |
| 742 | default: |
| 743 | dev_info(&intel_private.pcidev->dev, |
| 744 | "unknown page table size, assuming 512KB\n"); |
Daniel Vetter | e5e408f | 2010-08-28 11:04:32 +0200 | [diff] [blame] | 745 | size = KB(512); |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 746 | } |
Daniel Vetter | e5e408f | 2010-08-28 11:04:32 +0200 | [diff] [blame] | 747 | |
| 748 | return size/4; |
Daniel Vetter | 210b23c | 2010-08-28 16:14:32 +0200 | [diff] [blame] | 749 | } else if (INTEL_GTT_GEN == 6) { |
| 750 | u16 snb_gmch_ctl; |
| 751 | |
| 752 | pci_read_config_word(intel_private.pcidev, SNB_GMCH_CTRL, &snb_gmch_ctl); |
| 753 | switch (snb_gmch_ctl & SNB_GTT_SIZE_MASK) { |
| 754 | default: |
| 755 | case SNB_GTT_SIZE_0M: |
| 756 | printk(KERN_ERR "Bad GTT size mask: 0x%04x.\n", snb_gmch_ctl); |
| 757 | size = MB(0); |
| 758 | break; |
| 759 | case SNB_GTT_SIZE_1M: |
| 760 | size = MB(1); |
| 761 | break; |
| 762 | case SNB_GTT_SIZE_2M: |
| 763 | size = MB(2); |
| 764 | break; |
| 765 | } |
| 766 | return size/4; |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 767 | } else { |
| 768 | /* On previous hardware, the GTT size was just what was |
| 769 | * required to map the aperture. |
| 770 | */ |
Daniel Vetter | e5e408f | 2010-08-28 11:04:32 +0200 | [diff] [blame] | 771 | return intel_private.base.gtt_mappable_entries; |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 772 | } |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 773 | } |
Daniel Vetter | fbe4078 | 2010-08-27 17:12:41 +0200 | [diff] [blame] | 774 | |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 775 | static unsigned int intel_gtt_mappable_entries(void) |
| 776 | { |
| 777 | unsigned int aperture_size; |
| 778 | u16 gmch_ctrl; |
| 779 | |
| 780 | aperture_size = 1024 * 1024; |
| 781 | |
| 782 | pci_read_config_word(intel_private.bridge_dev, |
| 783 | I830_GMCH_CTRL, &gmch_ctrl); |
| 784 | |
| 785 | switch (intel_private.pcidev->device) { |
| 786 | case PCI_DEVICE_ID_INTEL_82830_CGC: |
| 787 | case PCI_DEVICE_ID_INTEL_82845G_IG: |
| 788 | case PCI_DEVICE_ID_INTEL_82855GM_IG: |
| 789 | case PCI_DEVICE_ID_INTEL_82865_IG: |
| 790 | if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_64M) |
| 791 | aperture_size *= 64; |
| 792 | else |
| 793 | aperture_size *= 128; |
| 794 | break; |
| 795 | default: |
| 796 | /* 9xx supports large sizes, just look at the length */ |
| 797 | aperture_size = pci_resource_len(intel_private.pcidev, 2); |
| 798 | break; |
| 799 | } |
| 800 | |
| 801 | return aperture_size >> PAGE_SHIFT; |
| 802 | } |
| 803 | |
| 804 | static int intel_gtt_init(void) |
| 805 | { |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 806 | u32 gtt_map_size; |
| 807 | |
| 808 | intel_private.base.gtt_mappable_entries = intel_gtt_mappable_entries(); |
| 809 | intel_private.base.gtt_total_entries = intel_gtt_total_entries(); |
| 810 | |
| 811 | gtt_map_size = intel_private.base.gtt_total_entries * 4; |
| 812 | |
| 813 | intel_private.gtt = ioremap(intel_private.gtt_bus_addr, |
| 814 | gtt_map_size); |
| 815 | if (!intel_private.gtt) { |
| 816 | iounmap(intel_private.registers); |
| 817 | return -ENOMEM; |
| 818 | } |
| 819 | |
| 820 | global_cache_flush(); /* FIXME: ? */ |
| 821 | |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 822 | /* we have to call this as early as possible after the MMIO base address is known */ |
| 823 | intel_private.base.gtt_stolen_entries = intel_gtt_stolen_entries(); |
| 824 | if (intel_private.base.gtt_stolen_entries == 0) { |
| 825 | iounmap(intel_private.registers); |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 826 | iounmap(intel_private.gtt); |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 827 | return -ENOMEM; |
| 828 | } |
| 829 | |
| 830 | return 0; |
| 831 | } |
| 832 | |
Daniel Vetter | 3e921f9 | 2010-08-27 15:33:26 +0200 | [diff] [blame] | 833 | static int intel_fake_agp_fetch_size(void) |
| 834 | { |
| 835 | unsigned int aper_size; |
| 836 | int i; |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 837 | int num_sizes = ARRAY_SIZE(intel_fake_agp_sizes); |
Daniel Vetter | 3e921f9 | 2010-08-27 15:33:26 +0200 | [diff] [blame] | 838 | |
| 839 | aper_size = (intel_private.base.gtt_mappable_entries << PAGE_SHIFT) |
| 840 | / MB(1); |
| 841 | |
| 842 | for (i = 0; i < num_sizes; i++) { |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 843 | if (aper_size == intel_fake_agp_sizes[i].size) { |
| 844 | agp_bridge->current_size = intel_fake_agp_sizes + i; |
Daniel Vetter | 3e921f9 | 2010-08-27 15:33:26 +0200 | [diff] [blame] | 845 | return aper_size; |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | return 0; |
| 850 | } |
| 851 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 852 | static void intel_i830_fini_flush(void) |
| 853 | { |
| 854 | kunmap(intel_private.i8xx_page); |
| 855 | intel_private.i8xx_flush_page = NULL; |
| 856 | unmap_page_from_agp(intel_private.i8xx_page); |
| 857 | |
| 858 | __free_page(intel_private.i8xx_page); |
| 859 | intel_private.i8xx_page = NULL; |
| 860 | } |
| 861 | |
| 862 | static void intel_i830_setup_flush(void) |
| 863 | { |
| 864 | /* return if we've already set the flush mechanism up */ |
| 865 | if (intel_private.i8xx_page) |
| 866 | return; |
| 867 | |
| 868 | intel_private.i8xx_page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA32); |
| 869 | if (!intel_private.i8xx_page) |
| 870 | return; |
| 871 | |
| 872 | intel_private.i8xx_flush_page = kmap(intel_private.i8xx_page); |
| 873 | if (!intel_private.i8xx_flush_page) |
| 874 | intel_i830_fini_flush(); |
| 875 | } |
| 876 | |
| 877 | /* The chipset_flush interface needs to get data that has already been |
| 878 | * flushed out of the CPU all the way out to main memory, because the GPU |
| 879 | * doesn't snoop those buffers. |
| 880 | * |
| 881 | * The 8xx series doesn't have the same lovely interface for flushing the |
| 882 | * chipset write buffers that the later chips do. According to the 865 |
| 883 | * specs, it's 64 octwords, or 1KB. So, to get those previous things in |
| 884 | * that buffer out, we just fill 1KB and clflush it out, on the assumption |
| 885 | * that it'll push whatever was in there out. It appears to work. |
| 886 | */ |
| 887 | static void intel_i830_chipset_flush(struct agp_bridge_data *bridge) |
| 888 | { |
| 889 | unsigned int *pg = intel_private.i8xx_flush_page; |
| 890 | |
| 891 | memset(pg, 0, 1024); |
| 892 | |
| 893 | if (cpu_has_clflush) |
| 894 | clflush_cache_range(pg, 1024); |
| 895 | else if (wbinvd_on_all_cpus() != 0) |
| 896 | printk(KERN_ERR "Timed out waiting for cache flush.\n"); |
| 897 | } |
| 898 | |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame^] | 899 | static void intel_enable_gtt(void) |
| 900 | { |
| 901 | u32 ptetbl_addr, gma_addr; |
| 902 | u16 gmch_ctrl; |
| 903 | |
| 904 | ptetbl_addr = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000; |
| 905 | |
| 906 | pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &gma_addr); |
| 907 | intel_private.gma_bus_addr = (gma_addr & PCI_BASE_ADDRESS_MEM_MASK); |
| 908 | |
| 909 | pci_read_config_word(intel_private.bridge_dev, I830_GMCH_CTRL, &gmch_ctrl); |
| 910 | gmch_ctrl |= I830_GMCH_ENABLED; |
| 911 | pci_write_config_word(intel_private.bridge_dev, I830_GMCH_CTRL, gmch_ctrl); |
| 912 | |
| 913 | writel(ptetbl_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL); |
| 914 | readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */ |
| 915 | } |
| 916 | |
| 917 | static int i830_setup(void) |
| 918 | { |
| 919 | u32 reg_addr; |
| 920 | |
| 921 | pci_read_config_dword(intel_private.pcidev, I810_MMADDR, ®_addr); |
| 922 | reg_addr &= 0xfff80000; |
| 923 | |
| 924 | intel_private.registers = ioremap(reg_addr, KB(64)); |
| 925 | if (!intel_private.registers) |
| 926 | return -ENOMEM; |
| 927 | |
| 928 | intel_private.gtt_bus_addr = reg_addr + I810_PTE_BASE; |
| 929 | |
| 930 | intel_i830_setup_flush(); |
| 931 | |
| 932 | return 0; |
| 933 | } |
| 934 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 935 | /* The intel i830 automatically initializes the agp aperture during POST. |
| 936 | * Use the memory already set aside for in the GTT. |
| 937 | */ |
| 938 | static int intel_i830_create_gatt_table(struct agp_bridge_data *bridge) |
| 939 | { |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame^] | 940 | int ret; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 941 | |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame^] | 942 | ret = intel_private.driver->setup(); |
| 943 | if (ret != 0) |
| 944 | return ret; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 945 | |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 946 | ret = intel_gtt_init(); |
| 947 | if (ret != 0) |
| 948 | return ret; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 949 | |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame^] | 950 | agp_bridge->gatt_table_real = NULL; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 951 | agp_bridge->gatt_table = NULL; |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame^] | 952 | agp_bridge->gatt_bus_addr = 0; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 953 | |
| 954 | return 0; |
| 955 | } |
| 956 | |
| 957 | /* Return the gatt table to a sane state. Use the top of stolen |
| 958 | * memory for the GTT. |
| 959 | */ |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 960 | 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] | 961 | { |
| 962 | return 0; |
| 963 | } |
| 964 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 965 | static int intel_i830_configure(void) |
| 966 | { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 967 | int i; |
| 968 | |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame^] | 969 | intel_enable_gtt(); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 970 | |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame^] | 971 | agp_bridge->gart_bus_addr = intel_private.gma_bus_addr; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 972 | |
| 973 | if (agp_bridge->driver->needs_scratch_page) { |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame^] | 974 | for (i = intel_private.base.gtt_stolen_entries; |
| 975 | i < intel_private.base.gtt_total_entries; i++) { |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 976 | writel(agp_bridge->scratch_page, intel_private.gtt+i); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 977 | } |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 978 | readl(intel_private.gtt+i-1); /* PCI Posting. */ |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | global_cache_flush(); |
| 982 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 983 | return 0; |
| 984 | } |
| 985 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 986 | static int intel_i830_insert_entries(struct agp_memory *mem, off_t pg_start, |
| 987 | int type) |
| 988 | { |
| 989 | int i, j, num_entries; |
| 990 | void *temp; |
| 991 | int ret = -EINVAL; |
| 992 | int mask_type; |
| 993 | |
| 994 | if (mem->page_count == 0) |
| 995 | goto out; |
| 996 | |
| 997 | temp = agp_bridge->current_size; |
| 998 | num_entries = A_SIZE_FIX(temp)->num_entries; |
| 999 | |
Daniel Vetter | 0ade638 | 2010-08-24 22:18:41 +0200 | [diff] [blame] | 1000 | if (pg_start < intel_private.base.gtt_stolen_entries) { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1001 | dev_printk(KERN_DEBUG, &intel_private.pcidev->dev, |
Daniel Vetter | 0ade638 | 2010-08-24 22:18:41 +0200 | [diff] [blame] | 1002 | "pg_start == 0x%.8lx, gtt_stolen_entries == 0x%.8x\n", |
| 1003 | pg_start, intel_private.base.gtt_stolen_entries); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1004 | |
| 1005 | dev_info(&intel_private.pcidev->dev, |
| 1006 | "trying to insert into local/stolen memory\n"); |
| 1007 | goto out_err; |
| 1008 | } |
| 1009 | |
| 1010 | if ((pg_start + mem->page_count) > num_entries) |
| 1011 | goto out_err; |
| 1012 | |
| 1013 | /* The i830 can't check the GTT for entries since its read only, |
| 1014 | * depend on the caller to make the correct offset decisions. |
| 1015 | */ |
| 1016 | |
| 1017 | if (type != mem->type) |
| 1018 | goto out_err; |
| 1019 | |
| 1020 | mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type); |
| 1021 | |
| 1022 | if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY && |
| 1023 | mask_type != INTEL_AGP_CACHED_MEMORY) |
| 1024 | goto out_err; |
| 1025 | |
| 1026 | if (!mem->is_flushed) |
| 1027 | global_cache_flush(); |
| 1028 | |
| 1029 | for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { |
| 1030 | writel(agp_bridge->driver->mask_memory(agp_bridge, |
| 1031 | page_to_phys(mem->pages[i]), mask_type), |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 1032 | intel_private.gtt+j); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1033 | } |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 1034 | readl(intel_private.gtt+j-1); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1035 | |
| 1036 | out: |
| 1037 | ret = 0; |
| 1038 | out_err: |
| 1039 | mem->is_flushed = true; |
| 1040 | return ret; |
| 1041 | } |
| 1042 | |
| 1043 | static int intel_i830_remove_entries(struct agp_memory *mem, off_t pg_start, |
| 1044 | int type) |
| 1045 | { |
| 1046 | int i; |
| 1047 | |
| 1048 | if (mem->page_count == 0) |
| 1049 | return 0; |
| 1050 | |
Daniel Vetter | 0ade638 | 2010-08-24 22:18:41 +0200 | [diff] [blame] | 1051 | if (pg_start < intel_private.base.gtt_stolen_entries) { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1052 | dev_info(&intel_private.pcidev->dev, |
| 1053 | "trying to disable local/stolen memory\n"); |
| 1054 | return -EINVAL; |
| 1055 | } |
| 1056 | |
| 1057 | for (i = pg_start; i < (mem->page_count + pg_start); i++) { |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 1058 | writel(agp_bridge->scratch_page, intel_private.gtt+i); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1059 | } |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 1060 | readl(intel_private.gtt+i-1); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1061 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1062 | return 0; |
| 1063 | } |
| 1064 | |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1065 | static struct agp_memory *intel_fake_agp_alloc_by_type(size_t pg_count, |
| 1066 | int type) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1067 | { |
| 1068 | if (type == AGP_PHYS_MEMORY) |
| 1069 | return alloc_agpphysmem_i8xx(pg_count, type); |
| 1070 | /* always return NULL for other allocation types for now */ |
| 1071 | return NULL; |
| 1072 | } |
| 1073 | |
| 1074 | static int intel_alloc_chipset_flush_resource(void) |
| 1075 | { |
| 1076 | int ret; |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1077 | 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] | 1078 | PAGE_SIZE, PCIBIOS_MIN_MEM, 0, |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1079 | pcibios_align_resource, intel_private.bridge_dev); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1080 | |
| 1081 | return ret; |
| 1082 | } |
| 1083 | |
| 1084 | static void intel_i915_setup_chipset_flush(void) |
| 1085 | { |
| 1086 | int ret; |
| 1087 | u32 temp; |
| 1088 | |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1089 | pci_read_config_dword(intel_private.bridge_dev, I915_IFPADDR, &temp); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1090 | if (!(temp & 0x1)) { |
| 1091 | intel_alloc_chipset_flush_resource(); |
| 1092 | intel_private.resource_valid = 1; |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1093 | 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] | 1094 | } else { |
| 1095 | temp &= ~1; |
| 1096 | |
| 1097 | intel_private.resource_valid = 1; |
| 1098 | intel_private.ifp_resource.start = temp; |
| 1099 | intel_private.ifp_resource.end = temp + PAGE_SIZE; |
| 1100 | ret = request_resource(&iomem_resource, &intel_private.ifp_resource); |
| 1101 | /* some BIOSes reserve this area in a pnp some don't */ |
| 1102 | if (ret) |
| 1103 | intel_private.resource_valid = 0; |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | static void intel_i965_g33_setup_chipset_flush(void) |
| 1108 | { |
| 1109 | u32 temp_hi, temp_lo; |
| 1110 | int ret; |
| 1111 | |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1112 | pci_read_config_dword(intel_private.bridge_dev, I965_IFPADDR + 4, &temp_hi); |
| 1113 | pci_read_config_dword(intel_private.bridge_dev, I965_IFPADDR, &temp_lo); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1114 | |
| 1115 | if (!(temp_lo & 0x1)) { |
| 1116 | |
| 1117 | intel_alloc_chipset_flush_resource(); |
| 1118 | |
| 1119 | intel_private.resource_valid = 1; |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1120 | pci_write_config_dword(intel_private.bridge_dev, I965_IFPADDR + 4, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1121 | upper_32_bits(intel_private.ifp_resource.start)); |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1122 | 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] | 1123 | } else { |
| 1124 | u64 l64; |
| 1125 | |
| 1126 | temp_lo &= ~0x1; |
| 1127 | l64 = ((u64)temp_hi << 32) | temp_lo; |
| 1128 | |
| 1129 | intel_private.resource_valid = 1; |
| 1130 | intel_private.ifp_resource.start = l64; |
| 1131 | intel_private.ifp_resource.end = l64 + PAGE_SIZE; |
| 1132 | ret = request_resource(&iomem_resource, &intel_private.ifp_resource); |
| 1133 | /* some BIOSes reserve this area in a pnp some don't */ |
| 1134 | if (ret) |
| 1135 | intel_private.resource_valid = 0; |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | static void intel_i9xx_setup_flush(void) |
| 1140 | { |
| 1141 | /* return if already configured */ |
| 1142 | if (intel_private.ifp_resource.start) |
| 1143 | return; |
| 1144 | |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1145 | if (INTEL_GTT_GEN == 6) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1146 | return; |
| 1147 | |
| 1148 | /* setup a resource for this object */ |
| 1149 | intel_private.ifp_resource.name = "Intel Flush Page"; |
| 1150 | intel_private.ifp_resource.flags = IORESOURCE_MEM; |
| 1151 | |
| 1152 | /* Setup chipset flush for 915 */ |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1153 | if (IS_G33 || INTEL_GTT_GEN >= 4) { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1154 | intel_i965_g33_setup_chipset_flush(); |
| 1155 | } else { |
| 1156 | intel_i915_setup_chipset_flush(); |
| 1157 | } |
| 1158 | |
Chris Wilson | df51e7a | 2010-09-04 14:57:27 +0100 | [diff] [blame] | 1159 | if (intel_private.ifp_resource.start) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1160 | 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] | 1161 | if (!intel_private.i9xx_flush_page) |
| 1162 | dev_err(&intel_private.pcidev->dev, |
| 1163 | "can't ioremap flush page - no chipset flushing\n"); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1164 | } |
| 1165 | |
Chris Wilson | f1befe7 | 2010-05-18 12:24:51 +0100 | [diff] [blame] | 1166 | static int intel_i9xx_configure(void) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1167 | { |
| 1168 | struct aper_size_info_fixed *current_size; |
| 1169 | u32 temp; |
| 1170 | u16 gmch_ctrl; |
| 1171 | int i; |
| 1172 | |
| 1173 | current_size = A_SIZE_FIX(agp_bridge->current_size); |
| 1174 | |
| 1175 | pci_read_config_dword(intel_private.pcidev, I915_GMADDR, &temp); |
| 1176 | |
| 1177 | agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK); |
| 1178 | |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1179 | pci_read_config_word(intel_private.bridge_dev, I830_GMCH_CTRL, &gmch_ctrl); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1180 | gmch_ctrl |= I830_GMCH_ENABLED; |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1181 | pci_write_config_word(intel_private.bridge_dev, I830_GMCH_CTRL, gmch_ctrl); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1182 | |
| 1183 | writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL); |
| 1184 | readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */ |
| 1185 | |
| 1186 | if (agp_bridge->driver->needs_scratch_page) { |
Daniel Vetter | 0ade638 | 2010-08-24 22:18:41 +0200 | [diff] [blame] | 1187 | for (i = intel_private.base.gtt_stolen_entries; i < |
| 1188 | intel_private.base.gtt_total_entries; i++) { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1189 | writel(agp_bridge->scratch_page, intel_private.gtt+i); |
| 1190 | } |
| 1191 | readl(intel_private.gtt+i-1); /* PCI Posting. */ |
| 1192 | } |
| 1193 | |
| 1194 | global_cache_flush(); |
| 1195 | |
| 1196 | intel_i9xx_setup_flush(); |
| 1197 | |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 1201 | static void intel_gtt_cleanup(void) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1202 | { |
| 1203 | if (intel_private.i9xx_flush_page) |
| 1204 | iounmap(intel_private.i9xx_flush_page); |
| 1205 | if (intel_private.resource_valid) |
| 1206 | release_resource(&intel_private.ifp_resource); |
| 1207 | intel_private.ifp_resource.start = 0; |
| 1208 | intel_private.resource_valid = 0; |
| 1209 | iounmap(intel_private.gtt); |
| 1210 | iounmap(intel_private.registers); |
| 1211 | } |
| 1212 | |
| 1213 | static void intel_i915_chipset_flush(struct agp_bridge_data *bridge) |
| 1214 | { |
| 1215 | if (intel_private.i9xx_flush_page) |
| 1216 | writel(1, intel_private.i9xx_flush_page); |
| 1217 | } |
| 1218 | |
| 1219 | static int intel_i915_insert_entries(struct agp_memory *mem, off_t pg_start, |
| 1220 | int type) |
| 1221 | { |
| 1222 | int num_entries; |
| 1223 | void *temp; |
| 1224 | int ret = -EINVAL; |
| 1225 | int mask_type; |
| 1226 | |
| 1227 | if (mem->page_count == 0) |
| 1228 | goto out; |
| 1229 | |
| 1230 | temp = agp_bridge->current_size; |
| 1231 | num_entries = A_SIZE_FIX(temp)->num_entries; |
| 1232 | |
Daniel Vetter | 0ade638 | 2010-08-24 22:18:41 +0200 | [diff] [blame] | 1233 | if (pg_start < intel_private.base.gtt_stolen_entries) { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1234 | dev_printk(KERN_DEBUG, &intel_private.pcidev->dev, |
Daniel Vetter | 0ade638 | 2010-08-24 22:18:41 +0200 | [diff] [blame] | 1235 | "pg_start == 0x%.8lx, gtt_stolen_entries == 0x%.8x\n", |
| 1236 | pg_start, intel_private.base.gtt_stolen_entries); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1237 | |
| 1238 | dev_info(&intel_private.pcidev->dev, |
| 1239 | "trying to insert into local/stolen memory\n"); |
| 1240 | goto out_err; |
| 1241 | } |
| 1242 | |
| 1243 | if ((pg_start + mem->page_count) > num_entries) |
| 1244 | goto out_err; |
| 1245 | |
| 1246 | /* The i915 can't check the GTT for entries since it's read only; |
| 1247 | * depend on the caller to make the correct offset decisions. |
| 1248 | */ |
| 1249 | |
| 1250 | if (type != mem->type) |
| 1251 | goto out_err; |
| 1252 | |
| 1253 | mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type); |
| 1254 | |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1255 | if (INTEL_GTT_GEN != 6 && mask_type != 0 && |
| 1256 | mask_type != AGP_PHYS_MEMORY && |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1257 | mask_type != INTEL_AGP_CACHED_MEMORY) |
| 1258 | goto out_err; |
| 1259 | |
| 1260 | if (!mem->is_flushed) |
| 1261 | global_cache_flush(); |
| 1262 | |
| 1263 | intel_agp_insert_sg_entries(mem, pg_start, mask_type); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1264 | |
| 1265 | out: |
| 1266 | ret = 0; |
| 1267 | out_err: |
| 1268 | mem->is_flushed = true; |
| 1269 | return ret; |
| 1270 | } |
| 1271 | |
| 1272 | static int intel_i915_remove_entries(struct agp_memory *mem, off_t pg_start, |
| 1273 | int type) |
| 1274 | { |
| 1275 | int i; |
| 1276 | |
| 1277 | if (mem->page_count == 0) |
| 1278 | return 0; |
| 1279 | |
Daniel Vetter | 0ade638 | 2010-08-24 22:18:41 +0200 | [diff] [blame] | 1280 | if (pg_start < intel_private.base.gtt_stolen_entries) { |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1281 | dev_info(&intel_private.pcidev->dev, |
| 1282 | "trying to disable local/stolen memory\n"); |
| 1283 | return -EINVAL; |
| 1284 | } |
| 1285 | |
| 1286 | for (i = pg_start; i < (mem->page_count + pg_start); i++) |
| 1287 | writel(agp_bridge->scratch_page, intel_private.gtt+i); |
| 1288 | |
| 1289 | readl(intel_private.gtt+i-1); |
| 1290 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1291 | return 0; |
| 1292 | } |
| 1293 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1294 | /* The intel i915 automatically initializes the agp aperture during POST. |
| 1295 | * Use the memory already set aside for in the GTT. |
| 1296 | */ |
| 1297 | static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge) |
| 1298 | { |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 1299 | int page_order, ret; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1300 | struct aper_size_info_fixed *size; |
| 1301 | int num_entries; |
| 1302 | u32 temp, temp2; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1303 | |
| 1304 | size = agp_bridge->current_size; |
| 1305 | page_order = size->page_order; |
| 1306 | num_entries = size->num_entries; |
| 1307 | agp_bridge->gatt_table_real = NULL; |
| 1308 | |
| 1309 | pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp); |
| 1310 | pci_read_config_dword(intel_private.pcidev, I915_PTEADDR, &temp2); |
| 1311 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1312 | temp &= 0xfff80000; |
| 1313 | |
| 1314 | intel_private.registers = ioremap(temp, 128 * 4096); |
Daniel Vetter | ccc4e67 | 2010-09-08 21:20:12 +0200 | [diff] [blame] | 1315 | if (!intel_private.registers) |
| 1316 | return -ENOMEM; |
| 1317 | |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 1318 | intel_private.gtt_bus_addr = temp2; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1319 | temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1320 | |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 1321 | ret = intel_gtt_init(); |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 1322 | if (ret != 0) |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 1323 | return ret; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1324 | |
| 1325 | agp_bridge->gatt_table = NULL; |
| 1326 | |
| 1327 | agp_bridge->gatt_bus_addr = temp; |
| 1328 | |
| 1329 | return 0; |
| 1330 | } |
| 1331 | |
| 1332 | /* |
| 1333 | * The i965 supports 36-bit physical addresses, but to keep |
| 1334 | * the format of the GTT the same, the bits that don't fit |
| 1335 | * in a 32-bit word are shifted down to bits 4..7. |
| 1336 | * |
| 1337 | * Gcc is smart enough to notice that "(addr >> 28) & 0xf0" |
| 1338 | * is always zero on 32-bit architectures, so no need to make |
| 1339 | * this conditional. |
| 1340 | */ |
| 1341 | static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge, |
| 1342 | dma_addr_t addr, int type) |
| 1343 | { |
| 1344 | /* Shift high bits down */ |
| 1345 | addr |= (addr >> 28) & 0xf0; |
| 1346 | |
| 1347 | /* Type checking must be done elsewhere */ |
| 1348 | return addr | bridge->driver->masks[type].mask; |
| 1349 | } |
| 1350 | |
Zhenyu Wang | 3869d4a | 2010-07-09 10:40:58 -0700 | [diff] [blame] | 1351 | static unsigned long intel_gen6_mask_memory(struct agp_bridge_data *bridge, |
| 1352 | dma_addr_t addr, int type) |
| 1353 | { |
Zhenyu Wang | 8dfc2b1 | 2010-08-23 14:37:52 +0800 | [diff] [blame] | 1354 | /* gen6 has bit11-4 for physical addr bit39-32 */ |
| 1355 | addr |= (addr >> 28) & 0xff0; |
Zhenyu Wang | 3869d4a | 2010-07-09 10:40:58 -0700 | [diff] [blame] | 1356 | |
| 1357 | /* Type checking must be done elsewhere */ |
| 1358 | return addr | bridge->driver->masks[type].mask; |
| 1359 | } |
| 1360 | |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 1361 | static void intel_i965_get_gtt_range(int *gtt_offset) |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1362 | { |
Daniel Vetter | 210b23c | 2010-08-28 16:14:32 +0200 | [diff] [blame] | 1363 | switch (INTEL_GTT_GEN) { |
| 1364 | case 5: |
| 1365 | case 6: |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1366 | *gtt_offset = MB(2); |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1367 | break; |
Daniel Vetter | 210b23c | 2010-08-28 16:14:32 +0200 | [diff] [blame] | 1368 | case 4: |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1369 | default: |
Daniel Vetter | 210b23c | 2010-08-28 16:14:32 +0200 | [diff] [blame] | 1370 | *gtt_offset = KB(512); |
| 1371 | break; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | /* The intel i965 automatically initializes the agp aperture during POST. |
| 1376 | * Use the memory already set aside for in the GTT. |
| 1377 | */ |
| 1378 | static int intel_i965_create_gatt_table(struct agp_bridge_data *bridge) |
| 1379 | { |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 1380 | int page_order, ret; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1381 | struct aper_size_info_fixed *size; |
| 1382 | int num_entries; |
| 1383 | u32 temp; |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 1384 | int gtt_offset; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1385 | |
| 1386 | size = agp_bridge->current_size; |
| 1387 | page_order = size->page_order; |
| 1388 | num_entries = size->num_entries; |
| 1389 | agp_bridge->gatt_table_real = NULL; |
| 1390 | |
| 1391 | pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp); |
| 1392 | |
| 1393 | temp &= 0xfff00000; |
| 1394 | |
Daniel Vetter | 210b23c | 2010-08-28 16:14:32 +0200 | [diff] [blame] | 1395 | intel_private.registers = ioremap(temp, 128 * 4096); |
| 1396 | if (!intel_private.registers) |
| 1397 | return -ENOMEM; |
| 1398 | |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 1399 | intel_i965_get_gtt_range(>t_offset); |
| 1400 | intel_private.gtt_bus_addr = temp + gtt_offset; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1401 | temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1402 | |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 1403 | ret = intel_gtt_init(); |
Daniel Vetter | f67eab6 | 2010-08-29 17:27:36 +0200 | [diff] [blame] | 1404 | if (ret != 0) |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 1405 | return ret; |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1406 | |
| 1407 | agp_bridge->gatt_table = NULL; |
| 1408 | |
| 1409 | agp_bridge->gatt_bus_addr = temp; |
| 1410 | |
| 1411 | return 0; |
| 1412 | } |
| 1413 | |
| 1414 | static const struct agp_bridge_driver intel_810_driver = { |
| 1415 | .owner = THIS_MODULE, |
| 1416 | .aperture_sizes = intel_i810_sizes, |
| 1417 | .size_type = FIXED_APER_SIZE, |
| 1418 | .num_aperture_sizes = 2, |
| 1419 | .needs_scratch_page = true, |
| 1420 | .configure = intel_i810_configure, |
| 1421 | .fetch_size = intel_i810_fetch_size, |
| 1422 | .cleanup = intel_i810_cleanup, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1423 | .mask_memory = intel_i810_mask_memory, |
| 1424 | .masks = intel_i810_masks, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1425 | .agp_enable = intel_fake_agp_enable, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1426 | .cache_flush = global_cache_flush, |
| 1427 | .create_gatt_table = agp_generic_create_gatt_table, |
| 1428 | .free_gatt_table = agp_generic_free_gatt_table, |
| 1429 | .insert_memory = intel_i810_insert_entries, |
| 1430 | .remove_memory = intel_i810_remove_entries, |
| 1431 | .alloc_by_type = intel_i810_alloc_by_type, |
| 1432 | .free_by_type = intel_i810_free_by_type, |
| 1433 | .agp_alloc_page = agp_generic_alloc_page, |
| 1434 | .agp_alloc_pages = agp_generic_alloc_pages, |
| 1435 | .agp_destroy_page = agp_generic_destroy_page, |
| 1436 | .agp_destroy_pages = agp_generic_destroy_pages, |
| 1437 | .agp_type_to_mask_type = agp_generic_type_to_mask_type, |
| 1438 | }; |
| 1439 | |
| 1440 | static const struct agp_bridge_driver intel_830_driver = { |
| 1441 | .owner = THIS_MODULE, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1442 | .aperture_sizes = intel_fake_agp_sizes, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1443 | .size_type = FIXED_APER_SIZE, |
| 1444 | .num_aperture_sizes = 4, |
| 1445 | .needs_scratch_page = true, |
| 1446 | .configure = intel_i830_configure, |
Daniel Vetter | 3e921f9 | 2010-08-27 15:33:26 +0200 | [diff] [blame] | 1447 | .fetch_size = intel_fake_agp_fetch_size, |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 1448 | .cleanup = intel_gtt_cleanup, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1449 | .mask_memory = intel_i810_mask_memory, |
| 1450 | .masks = intel_i810_masks, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1451 | .agp_enable = intel_fake_agp_enable, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1452 | .cache_flush = global_cache_flush, |
| 1453 | .create_gatt_table = intel_i830_create_gatt_table, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1454 | .free_gatt_table = intel_fake_agp_free_gatt_table, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1455 | .insert_memory = intel_i830_insert_entries, |
| 1456 | .remove_memory = intel_i830_remove_entries, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1457 | .alloc_by_type = intel_fake_agp_alloc_by_type, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1458 | .free_by_type = intel_i810_free_by_type, |
| 1459 | .agp_alloc_page = agp_generic_alloc_page, |
| 1460 | .agp_alloc_pages = agp_generic_alloc_pages, |
| 1461 | .agp_destroy_page = agp_generic_destroy_page, |
| 1462 | .agp_destroy_pages = agp_generic_destroy_pages, |
| 1463 | .agp_type_to_mask_type = intel_i830_type_to_mask_type, |
| 1464 | .chipset_flush = intel_i830_chipset_flush, |
| 1465 | }; |
| 1466 | |
| 1467 | static const struct agp_bridge_driver intel_915_driver = { |
| 1468 | .owner = THIS_MODULE, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1469 | .aperture_sizes = intel_fake_agp_sizes, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1470 | .size_type = FIXED_APER_SIZE, |
| 1471 | .num_aperture_sizes = 4, |
| 1472 | .needs_scratch_page = true, |
Chris Wilson | f1befe7 | 2010-05-18 12:24:51 +0100 | [diff] [blame] | 1473 | .configure = intel_i9xx_configure, |
Daniel Vetter | 3e921f9 | 2010-08-27 15:33:26 +0200 | [diff] [blame] | 1474 | .fetch_size = intel_fake_agp_fetch_size, |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 1475 | .cleanup = intel_gtt_cleanup, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1476 | .mask_memory = intel_i810_mask_memory, |
| 1477 | .masks = intel_i810_masks, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1478 | .agp_enable = intel_fake_agp_enable, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1479 | .cache_flush = global_cache_flush, |
| 1480 | .create_gatt_table = intel_i915_create_gatt_table, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1481 | .free_gatt_table = intel_fake_agp_free_gatt_table, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1482 | .insert_memory = intel_i915_insert_entries, |
| 1483 | .remove_memory = intel_i915_remove_entries, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1484 | .alloc_by_type = intel_fake_agp_alloc_by_type, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1485 | .free_by_type = intel_i810_free_by_type, |
| 1486 | .agp_alloc_page = agp_generic_alloc_page, |
| 1487 | .agp_alloc_pages = agp_generic_alloc_pages, |
| 1488 | .agp_destroy_page = agp_generic_destroy_page, |
| 1489 | .agp_destroy_pages = agp_generic_destroy_pages, |
| 1490 | .agp_type_to_mask_type = intel_i830_type_to_mask_type, |
| 1491 | .chipset_flush = intel_i915_chipset_flush, |
| 1492 | #ifdef USE_PCI_DMA_API |
| 1493 | .agp_map_page = intel_agp_map_page, |
| 1494 | .agp_unmap_page = intel_agp_unmap_page, |
| 1495 | .agp_map_memory = intel_agp_map_memory, |
| 1496 | .agp_unmap_memory = intel_agp_unmap_memory, |
| 1497 | #endif |
| 1498 | }; |
| 1499 | |
| 1500 | static const struct agp_bridge_driver intel_i965_driver = { |
| 1501 | .owner = THIS_MODULE, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1502 | .aperture_sizes = intel_fake_agp_sizes, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1503 | .size_type = FIXED_APER_SIZE, |
| 1504 | .num_aperture_sizes = 4, |
| 1505 | .needs_scratch_page = true, |
Chris Wilson | f1befe7 | 2010-05-18 12:24:51 +0100 | [diff] [blame] | 1506 | .configure = intel_i9xx_configure, |
Daniel Vetter | 3e921f9 | 2010-08-27 15:33:26 +0200 | [diff] [blame] | 1507 | .fetch_size = intel_fake_agp_fetch_size, |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 1508 | .cleanup = intel_gtt_cleanup, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1509 | .mask_memory = intel_i965_mask_memory, |
| 1510 | .masks = intel_i810_masks, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1511 | .agp_enable = intel_fake_agp_enable, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1512 | .cache_flush = global_cache_flush, |
| 1513 | .create_gatt_table = intel_i965_create_gatt_table, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1514 | .free_gatt_table = intel_fake_agp_free_gatt_table, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1515 | .insert_memory = intel_i915_insert_entries, |
| 1516 | .remove_memory = intel_i915_remove_entries, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1517 | .alloc_by_type = intel_fake_agp_alloc_by_type, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1518 | .free_by_type = intel_i810_free_by_type, |
| 1519 | .agp_alloc_page = agp_generic_alloc_page, |
| 1520 | .agp_alloc_pages = agp_generic_alloc_pages, |
| 1521 | .agp_destroy_page = agp_generic_destroy_page, |
| 1522 | .agp_destroy_pages = agp_generic_destroy_pages, |
| 1523 | .agp_type_to_mask_type = intel_i830_type_to_mask_type, |
| 1524 | .chipset_flush = intel_i915_chipset_flush, |
| 1525 | #ifdef USE_PCI_DMA_API |
| 1526 | .agp_map_page = intel_agp_map_page, |
| 1527 | .agp_unmap_page = intel_agp_unmap_page, |
| 1528 | .agp_map_memory = intel_agp_map_memory, |
| 1529 | .agp_unmap_memory = intel_agp_unmap_memory, |
| 1530 | #endif |
| 1531 | }; |
| 1532 | |
Zhenyu Wang | 3869d4a | 2010-07-09 10:40:58 -0700 | [diff] [blame] | 1533 | static const struct agp_bridge_driver intel_gen6_driver = { |
| 1534 | .owner = THIS_MODULE, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1535 | .aperture_sizes = intel_fake_agp_sizes, |
Zhenyu Wang | 3869d4a | 2010-07-09 10:40:58 -0700 | [diff] [blame] | 1536 | .size_type = FIXED_APER_SIZE, |
| 1537 | .num_aperture_sizes = 4, |
| 1538 | .needs_scratch_page = true, |
| 1539 | .configure = intel_i9xx_configure, |
Daniel Vetter | 3e921f9 | 2010-08-27 15:33:26 +0200 | [diff] [blame] | 1540 | .fetch_size = intel_fake_agp_fetch_size, |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 1541 | .cleanup = intel_gtt_cleanup, |
Zhenyu Wang | 3869d4a | 2010-07-09 10:40:58 -0700 | [diff] [blame] | 1542 | .mask_memory = intel_gen6_mask_memory, |
Zhenyu Wang | f8f235e | 2010-08-27 11:08:57 +0800 | [diff] [blame] | 1543 | .masks = intel_gen6_masks, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1544 | .agp_enable = intel_fake_agp_enable, |
Zhenyu Wang | 3869d4a | 2010-07-09 10:40:58 -0700 | [diff] [blame] | 1545 | .cache_flush = global_cache_flush, |
| 1546 | .create_gatt_table = intel_i965_create_gatt_table, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1547 | .free_gatt_table = intel_fake_agp_free_gatt_table, |
Zhenyu Wang | 3869d4a | 2010-07-09 10:40:58 -0700 | [diff] [blame] | 1548 | .insert_memory = intel_i915_insert_entries, |
| 1549 | .remove_memory = intel_i915_remove_entries, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1550 | .alloc_by_type = intel_fake_agp_alloc_by_type, |
Zhenyu Wang | 3869d4a | 2010-07-09 10:40:58 -0700 | [diff] [blame] | 1551 | .free_by_type = intel_i810_free_by_type, |
| 1552 | .agp_alloc_page = agp_generic_alloc_page, |
| 1553 | .agp_alloc_pages = agp_generic_alloc_pages, |
| 1554 | .agp_destroy_page = agp_generic_destroy_page, |
| 1555 | .agp_destroy_pages = agp_generic_destroy_pages, |
Zhenyu Wang | f8f235e | 2010-08-27 11:08:57 +0800 | [diff] [blame] | 1556 | .agp_type_to_mask_type = intel_gen6_type_to_mask_type, |
Zhenyu Wang | 3869d4a | 2010-07-09 10:40:58 -0700 | [diff] [blame] | 1557 | .chipset_flush = intel_i915_chipset_flush, |
| 1558 | #ifdef USE_PCI_DMA_API |
| 1559 | .agp_map_page = intel_agp_map_page, |
| 1560 | .agp_unmap_page = intel_agp_unmap_page, |
| 1561 | .agp_map_memory = intel_agp_map_memory, |
| 1562 | .agp_unmap_memory = intel_agp_unmap_memory, |
| 1563 | #endif |
| 1564 | }; |
| 1565 | |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1566 | static const struct agp_bridge_driver intel_g33_driver = { |
| 1567 | .owner = THIS_MODULE, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1568 | .aperture_sizes = intel_fake_agp_sizes, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1569 | .size_type = FIXED_APER_SIZE, |
| 1570 | .num_aperture_sizes = 4, |
| 1571 | .needs_scratch_page = true, |
Chris Wilson | f1befe7 | 2010-05-18 12:24:51 +0100 | [diff] [blame] | 1572 | .configure = intel_i9xx_configure, |
Daniel Vetter | 3e921f9 | 2010-08-27 15:33:26 +0200 | [diff] [blame] | 1573 | .fetch_size = intel_fake_agp_fetch_size, |
Daniel Vetter | fdfb58a | 2010-08-29 00:15:03 +0200 | [diff] [blame] | 1574 | .cleanup = intel_gtt_cleanup, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1575 | .mask_memory = intel_i965_mask_memory, |
| 1576 | .masks = intel_i810_masks, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1577 | .agp_enable = intel_fake_agp_enable, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1578 | .cache_flush = global_cache_flush, |
| 1579 | .create_gatt_table = intel_i915_create_gatt_table, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1580 | .free_gatt_table = intel_fake_agp_free_gatt_table, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1581 | .insert_memory = intel_i915_insert_entries, |
| 1582 | .remove_memory = intel_i915_remove_entries, |
Daniel Vetter | ffdd751 | 2010-08-27 17:51:29 +0200 | [diff] [blame] | 1583 | .alloc_by_type = intel_fake_agp_alloc_by_type, |
Daniel Vetter | f51b766 | 2010-04-14 00:29:52 +0200 | [diff] [blame] | 1584 | .free_by_type = intel_i810_free_by_type, |
| 1585 | .agp_alloc_page = agp_generic_alloc_page, |
| 1586 | .agp_alloc_pages = agp_generic_alloc_pages, |
| 1587 | .agp_destroy_page = agp_generic_destroy_page, |
| 1588 | .agp_destroy_pages = agp_generic_destroy_pages, |
| 1589 | .agp_type_to_mask_type = intel_i830_type_to_mask_type, |
| 1590 | .chipset_flush = intel_i915_chipset_flush, |
| 1591 | #ifdef USE_PCI_DMA_API |
| 1592 | .agp_map_page = intel_agp_map_page, |
| 1593 | .agp_unmap_page = intel_agp_unmap_page, |
| 1594 | .agp_map_memory = intel_agp_map_memory, |
| 1595 | .agp_unmap_memory = intel_agp_unmap_memory, |
| 1596 | #endif |
| 1597 | }; |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1598 | |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1599 | static const struct intel_gtt_driver i8xx_gtt_driver = { |
| 1600 | .gen = 2, |
Daniel Vetter | 7380042 | 2010-08-29 17:29:50 +0200 | [diff] [blame^] | 1601 | .setup = i830_setup, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1602 | }; |
| 1603 | static const struct intel_gtt_driver i915_gtt_driver = { |
| 1604 | .gen = 3, |
| 1605 | }; |
| 1606 | static const struct intel_gtt_driver g33_gtt_driver = { |
| 1607 | .gen = 3, |
| 1608 | .is_g33 = 1, |
| 1609 | }; |
| 1610 | static const struct intel_gtt_driver pineview_gtt_driver = { |
| 1611 | .gen = 3, |
| 1612 | .is_pineview = 1, .is_g33 = 1, |
| 1613 | }; |
| 1614 | static const struct intel_gtt_driver i965_gtt_driver = { |
| 1615 | .gen = 4, |
| 1616 | }; |
| 1617 | static const struct intel_gtt_driver g4x_gtt_driver = { |
| 1618 | .gen = 5, |
| 1619 | }; |
| 1620 | static const struct intel_gtt_driver ironlake_gtt_driver = { |
| 1621 | .gen = 5, |
| 1622 | .is_ironlake = 1, |
| 1623 | }; |
| 1624 | static const struct intel_gtt_driver sandybridge_gtt_driver = { |
| 1625 | .gen = 6, |
| 1626 | }; |
| 1627 | |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1628 | /* Table to describe Intel GMCH and AGP/PCIE GART drivers. At least one of |
| 1629 | * driver and gmch_driver must be non-null, and find_gmch will determine |
| 1630 | * which one should be used if a gmch_chip_id is present. |
| 1631 | */ |
| 1632 | static const struct intel_gtt_driver_description { |
| 1633 | unsigned int gmch_chip_id; |
| 1634 | char *name; |
| 1635 | const struct agp_bridge_driver *gmch_driver; |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1636 | const struct intel_gtt_driver *gtt_driver; |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1637 | } intel_gtt_chipsets[] = { |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1638 | { PCI_DEVICE_ID_INTEL_82810_IG1, "i810", &intel_810_driver , NULL}, |
| 1639 | { PCI_DEVICE_ID_INTEL_82810_IG3, "i810", &intel_810_driver , NULL}, |
| 1640 | { PCI_DEVICE_ID_INTEL_82810E_IG, "i810", &intel_810_driver , NULL}, |
| 1641 | { PCI_DEVICE_ID_INTEL_82815_CGC, "i815", &intel_810_driver , NULL}, |
| 1642 | { PCI_DEVICE_ID_INTEL_82830_CGC, "830M", |
| 1643 | &intel_830_driver , &i8xx_gtt_driver}, |
| 1644 | { PCI_DEVICE_ID_INTEL_82845G_IG, "830M", |
| 1645 | &intel_830_driver , &i8xx_gtt_driver}, |
| 1646 | { PCI_DEVICE_ID_INTEL_82854_IG, "854", |
| 1647 | &intel_830_driver , &i8xx_gtt_driver}, |
| 1648 | { PCI_DEVICE_ID_INTEL_82855GM_IG, "855GM", |
| 1649 | &intel_830_driver , &i8xx_gtt_driver}, |
| 1650 | { PCI_DEVICE_ID_INTEL_82865_IG, "865", |
| 1651 | &intel_830_driver , &i8xx_gtt_driver}, |
| 1652 | { PCI_DEVICE_ID_INTEL_E7221_IG, "E7221 (i915)", |
| 1653 | &intel_915_driver , &i915_gtt_driver }, |
| 1654 | { PCI_DEVICE_ID_INTEL_82915G_IG, "915G", |
| 1655 | &intel_915_driver , &i915_gtt_driver }, |
| 1656 | { PCI_DEVICE_ID_INTEL_82915GM_IG, "915GM", |
| 1657 | &intel_915_driver , &i915_gtt_driver }, |
| 1658 | { PCI_DEVICE_ID_INTEL_82945G_IG, "945G", |
| 1659 | &intel_915_driver , &i915_gtt_driver }, |
| 1660 | { PCI_DEVICE_ID_INTEL_82945GM_IG, "945GM", |
| 1661 | &intel_915_driver , &i915_gtt_driver }, |
| 1662 | { PCI_DEVICE_ID_INTEL_82945GME_IG, "945GME", |
| 1663 | &intel_915_driver , &i915_gtt_driver }, |
| 1664 | { PCI_DEVICE_ID_INTEL_82946GZ_IG, "946GZ", |
| 1665 | &intel_i965_driver , &i965_gtt_driver }, |
| 1666 | { PCI_DEVICE_ID_INTEL_82G35_IG, "G35", |
| 1667 | &intel_i965_driver , &i965_gtt_driver }, |
| 1668 | { PCI_DEVICE_ID_INTEL_82965Q_IG, "965Q", |
| 1669 | &intel_i965_driver , &i965_gtt_driver }, |
| 1670 | { PCI_DEVICE_ID_INTEL_82965G_IG, "965G", |
| 1671 | &intel_i965_driver , &i965_gtt_driver }, |
| 1672 | { PCI_DEVICE_ID_INTEL_82965GM_IG, "965GM", |
| 1673 | &intel_i965_driver , &i965_gtt_driver }, |
| 1674 | { PCI_DEVICE_ID_INTEL_82965GME_IG, "965GME/GLE", |
| 1675 | &intel_i965_driver , &i965_gtt_driver }, |
| 1676 | { PCI_DEVICE_ID_INTEL_G33_IG, "G33", |
| 1677 | &intel_g33_driver , &g33_gtt_driver }, |
| 1678 | { PCI_DEVICE_ID_INTEL_Q35_IG, "Q35", |
| 1679 | &intel_g33_driver , &g33_gtt_driver }, |
| 1680 | { PCI_DEVICE_ID_INTEL_Q33_IG, "Q33", |
| 1681 | &intel_g33_driver , &g33_gtt_driver }, |
| 1682 | { PCI_DEVICE_ID_INTEL_PINEVIEW_M_IG, "GMA3150", |
| 1683 | &intel_g33_driver , &pineview_gtt_driver }, |
| 1684 | { PCI_DEVICE_ID_INTEL_PINEVIEW_IG, "GMA3150", |
| 1685 | &intel_g33_driver , &pineview_gtt_driver }, |
| 1686 | { PCI_DEVICE_ID_INTEL_GM45_IG, "GM45", |
| 1687 | &intel_i965_driver , &g4x_gtt_driver }, |
| 1688 | { PCI_DEVICE_ID_INTEL_EAGLELAKE_IG, "Eaglelake", |
| 1689 | &intel_i965_driver , &g4x_gtt_driver }, |
| 1690 | { PCI_DEVICE_ID_INTEL_Q45_IG, "Q45/Q43", |
| 1691 | &intel_i965_driver , &g4x_gtt_driver }, |
| 1692 | { PCI_DEVICE_ID_INTEL_G45_IG, "G45/G43", |
| 1693 | &intel_i965_driver , &g4x_gtt_driver }, |
| 1694 | { PCI_DEVICE_ID_INTEL_B43_IG, "B43", |
| 1695 | &intel_i965_driver , &g4x_gtt_driver }, |
| 1696 | { PCI_DEVICE_ID_INTEL_G41_IG, "G41", |
| 1697 | &intel_i965_driver , &g4x_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1698 | { PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1699 | "HD Graphics", &intel_i965_driver , &ironlake_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1700 | { PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1701 | "HD Graphics", &intel_i965_driver , &ironlake_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1702 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_GT1_IG, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1703 | "Sandybridge", &intel_gen6_driver , &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1704 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_GT2_IG, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1705 | "Sandybridge", &intel_gen6_driver , &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1706 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_GT2_PLUS_IG, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1707 | "Sandybridge", &intel_gen6_driver , &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1708 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_GT1_IG, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1709 | "Sandybridge", &intel_gen6_driver , &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1710 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_GT2_IG, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1711 | "Sandybridge", &intel_gen6_driver , &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1712 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_GT2_PLUS_IG, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1713 | "Sandybridge", &intel_gen6_driver , &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1714 | { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_S_IG, |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1715 | "Sandybridge", &intel_gen6_driver , &sandybridge_gtt_driver }, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1716 | { 0, NULL, NULL } |
| 1717 | }; |
| 1718 | |
| 1719 | static int find_gmch(u16 device) |
| 1720 | { |
| 1721 | struct pci_dev *gmch_device; |
| 1722 | |
| 1723 | gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL); |
| 1724 | if (gmch_device && PCI_FUNC(gmch_device->devfn) != 0) { |
| 1725 | gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 1726 | device, gmch_device); |
| 1727 | } |
| 1728 | |
| 1729 | if (!gmch_device) |
| 1730 | return 0; |
| 1731 | |
| 1732 | intel_private.pcidev = gmch_device; |
| 1733 | return 1; |
| 1734 | } |
| 1735 | |
Daniel Vetter | e2404e7 | 2010-09-08 17:29:51 +0200 | [diff] [blame] | 1736 | int intel_gmch_probe(struct pci_dev *pdev, |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1737 | struct agp_bridge_data *bridge) |
| 1738 | { |
| 1739 | int i, mask; |
| 1740 | bridge->driver = NULL; |
| 1741 | |
| 1742 | for (i = 0; intel_gtt_chipsets[i].name != NULL; i++) { |
| 1743 | if (find_gmch(intel_gtt_chipsets[i].gmch_chip_id)) { |
| 1744 | bridge->driver = |
| 1745 | intel_gtt_chipsets[i].gmch_driver; |
Daniel Vetter | 1a997ff | 2010-09-08 21:18:53 +0200 | [diff] [blame] | 1746 | intel_private.driver = |
| 1747 | intel_gtt_chipsets[i].gtt_driver; |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1748 | break; |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | if (!bridge->driver) |
| 1753 | return 0; |
| 1754 | |
| 1755 | bridge->dev_private_data = &intel_private; |
| 1756 | bridge->dev = pdev; |
| 1757 | |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1758 | intel_private.bridge_dev = pci_dev_get(pdev); |
| 1759 | |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1760 | dev_info(&pdev->dev, "Intel %s Chipset\n", intel_gtt_chipsets[i].name); |
| 1761 | |
| 1762 | if (bridge->driver->mask_memory == intel_gen6_mask_memory) |
| 1763 | mask = 40; |
| 1764 | else if (bridge->driver->mask_memory == intel_i965_mask_memory) |
| 1765 | mask = 36; |
| 1766 | else |
| 1767 | mask = 32; |
| 1768 | |
| 1769 | if (pci_set_dma_mask(intel_private.pcidev, DMA_BIT_MASK(mask))) |
| 1770 | dev_err(&intel_private.pcidev->dev, |
| 1771 | "set gfx device dma mask %d-bit failed!\n", mask); |
| 1772 | else |
| 1773 | pci_set_consistent_dma_mask(intel_private.pcidev, |
| 1774 | DMA_BIT_MASK(mask)); |
| 1775 | |
Daniel Vetter | 1784a5f | 2010-09-08 21:01:04 +0200 | [diff] [blame] | 1776 | if (bridge->driver == &intel_810_driver) |
| 1777 | return 1; |
| 1778 | |
| 1779 | intel_private.base.gtt_mappable_entries = intel_gtt_mappable_entries(); |
| 1780 | |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1781 | return 1; |
| 1782 | } |
Daniel Vetter | e2404e7 | 2010-09-08 17:29:51 +0200 | [diff] [blame] | 1783 | EXPORT_SYMBOL(intel_gmch_probe); |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1784 | |
Daniel Vetter | e2404e7 | 2010-09-08 17:29:51 +0200 | [diff] [blame] | 1785 | void intel_gmch_remove(struct pci_dev *pdev) |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1786 | { |
| 1787 | if (intel_private.pcidev) |
| 1788 | pci_dev_put(intel_private.pcidev); |
Daniel Vetter | d7cca2f | 2010-08-24 23:06:19 +0200 | [diff] [blame] | 1789 | if (intel_private.bridge_dev) |
| 1790 | pci_dev_put(intel_private.bridge_dev); |
Daniel Vetter | 02c026c | 2010-08-24 19:39:48 +0200 | [diff] [blame] | 1791 | } |
Daniel Vetter | e2404e7 | 2010-09-08 17:29:51 +0200 | [diff] [blame] | 1792 | EXPORT_SYMBOL(intel_gmch_remove); |
| 1793 | |
| 1794 | MODULE_AUTHOR("Dave Jones <davej@redhat.com>"); |
| 1795 | MODULE_LICENSE("GPL and additional rights"); |