[intel] Quirk away MSI support on 945G/GM.
[platform/upstream/libdrm.git] / linux-core / drm_agpsupport.c
1 /**
2  * \file drm_agpsupport.c
3  * DRM support for AGP/GART backend
4  *
5  * \author Rickard E. (Rik) Faith <faith@valinux.com>
6  * \author Gareth Hughes <gareth@valinux.com>
7  */
8
9 /*
10  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
11  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
12  * All Rights Reserved.
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the "Software"),
16  * to deal in the Software without restriction, including without limitation
17  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18  * and/or sell copies of the Software, and to permit persons to whom the
19  * Software is furnished to do so, subject to the following conditions:
20  *
21  * The above copyright notice and this permission notice (including the next
22  * paragraph) shall be included in all copies or substantial portions of the
23  * Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
28  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
29  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
31  * OTHER DEALINGS IN THE SOFTWARE.
32  */
33
34 #include "drmP.h"
35 #include <linux/module.h>
36
37 #if __OS_HAS_AGP
38
39 /**
40  * Get AGP information.
41  *
42  * \param inode device inode.
43  * \param file_priv DRM file private.
44  * \param cmd command.
45  * \param arg pointer to a (output) drm_agp_info structure.
46  * \return zero on success or a negative number on failure.
47  *
48  * Verifies the AGP device has been initialized and acquired and fills in the
49  * drm_agp_info structure with the information in drm_agp_head::agp_info.
50  */
51 int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info)
52 {
53         DRM_AGP_KERN *kern;
54
55         if (!dev->agp || !dev->agp->acquired)
56                 return -EINVAL;
57
58         kern = &dev->agp->agp_info;
59         info->agp_version_major = kern->version.major;
60         info->agp_version_minor = kern->version.minor;
61         info->mode = kern->mode;
62         info->aperture_base = kern->aper_base;
63         info->aperture_size = kern->aper_size * 1024 * 1024;
64         info->memory_allowed = kern->max_memory << PAGE_SHIFT;
65         info->memory_used = kern->current_memory << PAGE_SHIFT;
66         info->id_vendor = kern->device->vendor;
67         info->id_device = kern->device->device;
68
69         return 0;
70 }
71 EXPORT_SYMBOL(drm_agp_info);
72
73 int drm_agp_info_ioctl(struct drm_device *dev, void *data,
74                        struct drm_file *file_priv)
75 {
76         struct drm_agp_info *info = data;
77         int err;
78
79         err = drm_agp_info(dev, info);
80         if (err)
81                 return err;
82
83         return 0;
84 }
85
86 /**
87  * Acquire the AGP device.
88  *
89  * \param dev DRM device that is to acquire AGP.
90  * \return zero on success or a negative number on failure.
91  *
92  * Verifies the AGP device hasn't been acquired before and calls
93  * \c agp_backend_acquire.
94  */
95 int drm_agp_acquire(struct drm_device * dev)
96 {
97 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
98         int retcode;
99 #endif
100
101         if (!dev->agp)
102                 return -ENODEV;
103         if (dev->agp->acquired)
104                 return -EBUSY;
105 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
106         if ((retcode = agp_backend_acquire()))
107                 return retcode;
108 #else
109         if (!(dev->agp->bridge = agp_backend_acquire(dev->pdev)))
110                 return -ENODEV;
111 #endif
112
113         dev->agp->acquired = 1;
114         return 0;
115 }
116 EXPORT_SYMBOL(drm_agp_acquire);
117
118 /**
119  * Acquire the AGP device (ioctl).
120  *
121  * \param inode device inode.
122  * \param file_priv DRM file private.
123  * \param cmd command.
124  * \param arg user argument.
125  * \return zero on success or a negative number on failure.
126  *
127  * Verifies the AGP device hasn't been acquired before and calls
128  * \c agp_backend_acquire.
129  */
130 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
131                           struct drm_file *file_priv)
132 {
133         return drm_agp_acquire((struct drm_device *) file_priv->minor->dev);
134 }
135
136 /**
137  * Release the AGP device.
138  *
139  * \param dev DRM device that is to release AGP.
140  * \return zero on success or a negative number on failure.
141  *
142  * Verifies the AGP device has been acquired and calls \c agp_backend_release.
143  */
144 int drm_agp_release(struct drm_device *dev)
145 {
146         if (!dev->agp || !dev->agp->acquired)
147                 return -EINVAL;
148 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
149         agp_backend_release();
150 #else
151         agp_backend_release(dev->agp->bridge);
152 #endif
153         dev->agp->acquired = 0;
154         return 0;
155
156 }
157 EXPORT_SYMBOL(drm_agp_release);
158
159 int drm_agp_release_ioctl(struct drm_device *dev, void *data,
160                           struct drm_file *file_priv)
161 {
162         return drm_agp_release(dev);
163 }
164
165 /**
166  * Enable the AGP bus.
167  *
168  * \param dev DRM device that has previously acquired AGP.
169  * \param mode Requested AGP mode.
170  * \return zero on success or a negative number on failure.
171  *
172  * Verifies the AGP device has been acquired but not enabled, and calls
173  * \c agp_enable.
174  */
175 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode)
176 {
177         if (!dev->agp || !dev->agp->acquired)
178                 return -EINVAL;
179
180         dev->agp->mode = mode.mode;
181 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
182         agp_enable(mode.mode);
183 #else
184         agp_enable(dev->agp->bridge, mode.mode);
185 #endif
186         dev->agp->enabled = 1;
187         return 0;
188 }
189 EXPORT_SYMBOL(drm_agp_enable);
190
191 int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
192                          struct drm_file *file_priv)
193 {
194         struct drm_agp_mode *mode = data;
195
196         return drm_agp_enable(dev, *mode);
197 }
198
199 /**
200  * Allocate AGP memory.
201  *
202  * \param inode device inode.
203  * \param file_priv file private pointer.
204  * \param cmd command.
205  * \param arg pointer to a drm_agp_buffer structure.
206  * \return zero on success or a negative number on failure.
207  *
208  * Verifies the AGP device is present and has been acquired, allocates the
209  * memory via alloc_agp() and creates a drm_agp_mem entry for it.
210  */
211 int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request)
212 {
213         struct drm_agp_mem *entry;
214         DRM_AGP_MEM *memory;
215         unsigned long pages;
216         u32 type;
217
218         if (!dev->agp || !dev->agp->acquired)
219                 return -EINVAL;
220         if (!(entry = drm_alloc(sizeof(*entry), DRM_MEM_AGPLISTS)))
221                 return -ENOMEM;
222
223         memset(entry, 0, sizeof(*entry));
224
225         pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
226         type = (u32) request->type;
227         if (!(memory = drm_alloc_agp(dev, pages, type))) {
228                 drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
229                 return -ENOMEM;
230         }
231
232         entry->handle = (unsigned long)memory->key + 1;
233         entry->memory = memory;
234         entry->bound = 0;
235         entry->pages = pages;
236         list_add(&entry->head, &dev->agp->memory);
237
238         request->handle = entry->handle;
239         request->physical = memory->physical;
240
241         return 0;
242 }
243 EXPORT_SYMBOL(drm_agp_alloc);
244
245
246 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
247                         struct drm_file *file_priv)
248 {
249         struct drm_agp_buffer *request = data;
250
251         return drm_agp_alloc(dev, request);
252 }
253
254 /**
255  * Search for the AGP memory entry associated with a handle.
256  *
257  * \param dev DRM device structure.
258  * \param handle AGP memory handle.
259  * \return pointer to the drm_agp_mem structure associated with \p handle.
260  *
261  * Walks through drm_agp_head::memory until finding a matching handle.
262  */
263 static struct drm_agp_mem *drm_agp_lookup_entry(struct drm_device * dev,
264                                            unsigned long handle)
265 {
266         struct drm_agp_mem *entry;
267
268         list_for_each_entry(entry, &dev->agp->memory, head) {
269                 if (entry->handle == handle)
270                         return entry;
271         }
272         return NULL;
273 }
274
275 /**
276  * Unbind AGP memory from the GATT (ioctl).
277  *
278  * \param inode device inode.
279  * \param file_priv DRM file private.
280  * \param cmd command.
281  * \param arg pointer to a drm_agp_binding structure.
282  * \return zero on success or a negative number on failure.
283  *
284  * Verifies the AGP device is present and acquired, looks-up the AGP memory
285  * entry and passes it to the unbind_agp() function.
286  */
287 int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request)
288 {
289         struct drm_agp_mem *entry;
290         int ret;
291
292         if (!dev->agp || !dev->agp->acquired)
293                 return -EINVAL;
294         if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
295                 return -EINVAL;
296         if (!entry->bound)
297                 return -EINVAL;
298         ret = drm_unbind_agp(entry->memory);
299         if (ret == 0)
300                 entry->bound = 0;
301         return ret;
302 }
303 EXPORT_SYMBOL(drm_agp_unbind);
304
305
306 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
307                          struct drm_file *file_priv)
308 {
309         struct drm_agp_binding *request = data;
310
311         return drm_agp_unbind(dev, request);
312 }
313
314
315 /**
316  * Bind AGP memory into the GATT (ioctl)
317  *
318  * \param inode device inode.
319  * \param file_priv DRM file private.
320  * \param cmd command.
321  * \param arg pointer to a drm_agp_binding structure.
322  * \return zero on success or a negative number on failure.
323  *
324  * Verifies the AGP device is present and has been acquired and that no memory
325  * is currently bound into the GATT. Looks-up the AGP memory entry and passes
326  * it to bind_agp() function.
327  */
328 int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request)
329 {
330         struct drm_agp_mem *entry;
331         int retcode;
332         int page;
333
334         if (!dev->agp || !dev->agp->acquired)
335                 return -EINVAL;
336         if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
337                 return -EINVAL;
338         if (entry->bound)
339                 return -EINVAL;
340         page = (request->offset + PAGE_SIZE - 1) / PAGE_SIZE;
341         if ((retcode = drm_bind_agp(entry->memory, page)))
342                 return retcode;
343         entry->bound = dev->agp->base + (page << PAGE_SHIFT);
344         DRM_DEBUG("base = 0x%lx entry->bound = 0x%lx\n",
345                   dev->agp->base, entry->bound);
346         return 0;
347 }
348 EXPORT_SYMBOL(drm_agp_bind);
349
350
351 int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
352                        struct drm_file *file_priv)
353 {
354         struct drm_agp_binding *request = data;
355
356         return drm_agp_bind(dev, request);
357 }
358
359
360 /**
361  * Free AGP memory (ioctl).
362  *
363  * \param inode device inode.
364  * \param file_priv DRM file private.
365  * \param cmd command.
366  * \param arg pointer to a drm_agp_buffer structure.
367  * \return zero on success or a negative number on failure.
368  *
369  * Verifies the AGP device is present and has been acquired and looks up the
370  * AGP memory entry. If the memory it's currently bound, unbind it via
371  * unbind_agp(). Frees it via free_agp() as well as the entry itself
372  * and unlinks from the doubly linked list it's inserted in.
373  */
374 int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request)
375 {
376         struct drm_agp_mem *entry;
377
378         if (!dev->agp || !dev->agp->acquired)
379                 return -EINVAL;
380         if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
381                 return -EINVAL;
382         if (entry->bound)
383                 drm_unbind_agp(entry->memory);
384
385         list_del(&entry->head);
386
387         drm_free_agp(entry->memory, entry->pages);
388         drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
389         return 0;
390 }
391 EXPORT_SYMBOL(drm_agp_free);
392
393
394
395 int drm_agp_free_ioctl(struct drm_device *dev, void *data,
396                        struct drm_file *file_priv)
397 {
398         struct drm_agp_buffer *request = data;
399
400         return drm_agp_free(dev, request);
401 }
402
403
404 /**
405  * Initialize the AGP resources.
406  *
407  * \return pointer to a drm_agp_head structure.
408  *
409  * Gets the drm_agp_t structure which is made available by the agpgart module
410  * via the inter_module_* functions. Creates and initializes a drm_agp_head
411  * structure.
412  */
413 struct drm_agp_head *drm_agp_init(struct drm_device *dev)
414 {
415         struct drm_agp_head *head = NULL;
416
417         if (!(head = drm_alloc(sizeof(*head), DRM_MEM_AGPLISTS)))
418                 return NULL;
419         memset((void *)head, 0, sizeof(*head));
420
421 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
422         agp_copy_info(&head->agp_info);
423 #else
424         head->bridge = agp_find_bridge(dev->pdev);
425         if (!head->bridge) {
426                 if (!(head->bridge = agp_backend_acquire(dev->pdev))) {
427                         drm_free(head, sizeof(*head), DRM_MEM_AGPLISTS);
428                         return NULL;
429                 }
430                 agp_copy_info(head->bridge, &head->agp_info);
431                 agp_backend_release(head->bridge);
432         } else {
433                 agp_copy_info(head->bridge, &head->agp_info);
434         }
435 #endif
436         if (head->agp_info.chipset == NOT_SUPPORTED) {
437                 drm_free(head, sizeof(*head), DRM_MEM_AGPLISTS);
438                 return NULL;
439         }
440         INIT_LIST_HEAD(&head->memory);
441         head->cant_use_aperture = head->agp_info.cant_use_aperture;
442         head->page_mask = head->agp_info.page_mask;
443         head->base = head->agp_info.aper_base;
444         return head;
445 }
446
447 /** Calls agp_allocate_memory() */
448 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
449 DRM_AGP_MEM *drm_agp_allocate_memory(size_t pages, u32 type)
450 {
451         return agp_allocate_memory(pages, type);
452 }
453 #else
454 DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge,
455                                      size_t pages, u32 type)
456 {
457         return agp_allocate_memory(bridge, pages, type);
458 }
459 #endif
460
461 /** Calls agp_free_memory() */
462 int drm_agp_free_memory(DRM_AGP_MEM * handle)
463 {
464         if (!handle)
465                 return 0;
466         agp_free_memory(handle);
467         return 1;
468 }
469
470 /** Calls agp_bind_memory() */
471 int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start)
472 {
473         if (!handle)
474                 return -EINVAL;
475         return agp_bind_memory(handle, start);
476 }
477 EXPORT_SYMBOL(drm_agp_bind_memory);
478
479 /** Calls agp_unbind_memory() */
480 int drm_agp_unbind_memory(DRM_AGP_MEM * handle)
481 {
482         if (!handle)
483                 return -EINVAL;
484         return agp_unbind_memory(handle);
485 }
486
487 /**
488  * Binds a collection of pages into AGP memory at the given offset, returning
489  * the AGP memory structure containing them.
490  *
491  * No reference is held on the pages during this time -- it is up to the
492  * caller to handle that.
493  */
494 DRM_AGP_MEM *
495 drm_agp_bind_pages(struct drm_device *dev,
496                    struct page **pages,
497                    unsigned long num_pages,
498                    uint32_t gtt_offset)
499 {
500         DRM_AGP_MEM *mem;
501         int ret, i;
502
503         DRM_DEBUG("drm_agp_populate_ttm\n");
504 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
505         mem = drm_agp_allocate_memory(num_pages, AGP_USER_MEMORY);
506 #else
507         mem = drm_agp_allocate_memory(dev->agp->bridge, num_pages,
508                                       AGP_USER_MEMORY);
509 #endif
510         if (mem == NULL) {
511                 DRM_ERROR("Failed to allocate memory for %ld pages\n",
512                           num_pages);
513                 return NULL;
514         }
515
516         for (i = 0; i < num_pages; i++)
517                 mem->memory[i] = phys_to_gart(page_to_phys(pages[i]));
518         mem->page_count = num_pages;
519
520         mem->is_flushed = TRUE;
521         ret = drm_agp_bind_memory(mem, gtt_offset / PAGE_SIZE);
522         if (ret != 0) {
523                 DRM_ERROR("Failed to bind AGP memory: %d\n", ret);
524                 agp_free_memory(mem);
525                 return NULL;
526         }
527
528         return mem;
529 }
530 EXPORT_SYMBOL(drm_agp_bind_pages);
531
532 /*
533  * AGP ttm backend interface.
534  */
535
536 #ifndef AGP_USER_TYPES
537 #define AGP_USER_TYPES (1 << 16)
538 #define AGP_USER_MEMORY (AGP_USER_TYPES)
539 #define AGP_USER_CACHED_MEMORY (AGP_USER_TYPES + 1)
540 #endif
541 #define AGP_REQUIRED_MAJOR 0
542 #define AGP_REQUIRED_MINOR 102
543
544 static int drm_agp_needs_unbind_cache_adjust(struct drm_ttm_backend *backend)
545 {
546         return ((backend->flags & DRM_BE_FLAG_BOUND_CACHED) ? 0 : 1);
547 }
548
549
550 static int drm_agp_populate(struct drm_ttm_backend *backend,
551                             unsigned long num_pages, struct page **pages,
552                             struct page *dummy_read_page)
553 {
554         struct drm_agp_ttm_backend *agp_be =
555                 container_of(backend, struct drm_agp_ttm_backend, backend);
556         struct page **cur_page, **last_page = pages + num_pages;
557         DRM_AGP_MEM *mem;
558         int dummy_page_count = 0;
559
560         if (drm_alloc_memctl(num_pages * sizeof(void *)))
561                 return -1;
562
563         DRM_DEBUG("drm_agp_populate_ttm\n");
564 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
565         mem = drm_agp_allocate_memory(num_pages, AGP_USER_MEMORY);
566 #else
567         mem = drm_agp_allocate_memory(agp_be->bridge, num_pages, AGP_USER_MEMORY);
568 #endif
569         if (!mem) {
570                 drm_free_memctl(num_pages * sizeof(void *));
571                 return -1;
572         }
573
574         DRM_DEBUG("Current page count is %ld\n", (long) mem->page_count);
575         mem->page_count = 0;
576         for (cur_page = pages; cur_page < last_page; ++cur_page) {
577                 struct page *page = *cur_page;
578                 if (!page) {
579                         page = dummy_read_page;
580                         ++dummy_page_count;
581                 }
582                 mem->memory[mem->page_count++] = phys_to_gart(page_to_phys(page));
583         }
584         if (dummy_page_count)
585                 DRM_DEBUG("Mapped %d dummy pages\n", dummy_page_count);
586         agp_be->mem = mem;
587         return 0;
588 }
589
590 static int drm_agp_bind_ttm(struct drm_ttm_backend *backend,
591                             struct drm_bo_mem_reg *bo_mem)
592 {
593         struct drm_agp_ttm_backend *agp_be =
594                 container_of(backend, struct drm_agp_ttm_backend, backend);
595         DRM_AGP_MEM *mem = agp_be->mem;
596         int ret;
597         int snooped = (bo_mem->flags & DRM_BO_FLAG_CACHED) && !(bo_mem->flags & DRM_BO_FLAG_CACHED_MAPPED);
598
599         DRM_DEBUG("drm_agp_bind_ttm\n");
600         mem->is_flushed = TRUE;
601         mem->type = AGP_USER_MEMORY;
602         /* CACHED MAPPED implies not snooped memory */
603         if (snooped)
604                 mem->type = AGP_USER_CACHED_MEMORY;
605
606         ret = drm_agp_bind_memory(mem, bo_mem->mm_node->start);
607         if (ret)
608                 DRM_ERROR("AGP Bind memory failed\n");
609
610         DRM_FLAG_MASKED(backend->flags, (bo_mem->flags & DRM_BO_FLAG_CACHED) ?
611                         DRM_BE_FLAG_BOUND_CACHED : 0,
612                         DRM_BE_FLAG_BOUND_CACHED);
613         return ret;
614 }
615
616 static int drm_agp_unbind_ttm(struct drm_ttm_backend *backend)
617 {
618         struct drm_agp_ttm_backend *agp_be =
619                 container_of(backend, struct drm_agp_ttm_backend, backend);
620
621         DRM_DEBUG("drm_agp_unbind_ttm\n");
622         if (agp_be->mem->is_bound)
623                 return drm_agp_unbind_memory(agp_be->mem);
624         else
625                 return 0;
626 }
627
628 static void drm_agp_clear_ttm(struct drm_ttm_backend *backend)
629 {
630         struct drm_agp_ttm_backend *agp_be =
631                 container_of(backend, struct drm_agp_ttm_backend, backend);
632         DRM_AGP_MEM *mem = agp_be->mem;
633
634         DRM_DEBUG("drm_agp_clear_ttm\n");
635         if (mem) {
636                 unsigned long num_pages = mem->page_count;
637                 backend->func->unbind(backend);
638                 agp_free_memory(mem);
639                 drm_free_memctl(num_pages * sizeof(void *));
640         }
641         agp_be->mem = NULL;
642 }
643
644 static void drm_agp_destroy_ttm(struct drm_ttm_backend *backend)
645 {
646         struct drm_agp_ttm_backend *agp_be;
647
648         if (backend) {
649                 DRM_DEBUG("drm_agp_destroy_ttm\n");
650                 agp_be = container_of(backend, struct drm_agp_ttm_backend, backend);
651                 if (agp_be) {
652                         if (agp_be->mem)
653                                 backend->func->clear(backend);
654                         drm_ctl_free(agp_be, sizeof(*agp_be), DRM_MEM_TTM);
655                 }
656         }
657 }
658
659 static struct drm_ttm_backend_func agp_ttm_backend = {
660         .needs_ub_cache_adjust = drm_agp_needs_unbind_cache_adjust,
661         .populate = drm_agp_populate,
662         .clear = drm_agp_clear_ttm,
663         .bind = drm_agp_bind_ttm,
664         .unbind = drm_agp_unbind_ttm,
665         .destroy =  drm_agp_destroy_ttm,
666 };
667
668 struct drm_ttm_backend *drm_agp_init_ttm(struct drm_device *dev)
669 {
670
671         struct drm_agp_ttm_backend *agp_be;
672         struct agp_kern_info *info;
673
674         if (!dev->agp) {
675                 DRM_ERROR("AGP is not initialized.\n");
676                 return NULL;
677         }
678         info = &dev->agp->agp_info;
679
680         if (info->version.major != AGP_REQUIRED_MAJOR ||
681             info->version.minor < AGP_REQUIRED_MINOR) {
682                 DRM_ERROR("Wrong agpgart version %d.%d\n"
683                           "\tYou need at least version %d.%d.\n",
684                           info->version.major,
685                           info->version.minor,
686                           AGP_REQUIRED_MAJOR,
687                           AGP_REQUIRED_MINOR);
688                 return NULL;
689         }
690
691
692         agp_be = drm_ctl_calloc(1, sizeof(*agp_be), DRM_MEM_TTM);
693         if (!agp_be)
694                 return NULL;
695
696         agp_be->mem = NULL;
697
698         agp_be->bridge = dev->agp->bridge;
699         agp_be->populated = FALSE;
700         agp_be->backend.func = &agp_ttm_backend;
701         agp_be->backend.dev = dev;
702
703         return &agp_be->backend;
704 }
705 EXPORT_SYMBOL(drm_agp_init_ttm);
706
707 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
708 void drm_agp_chipset_flush(struct drm_device *dev)
709 {
710         agp_flush_chipset(dev->agp->bridge);
711 }
712 EXPORT_SYMBOL(drm_agp_chipset_flush);
713 #endif
714
715 #endif                          /* __OS_HAS_AGP */