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