blob: 40bfd9b01e3973e5e2865d2aef3eb280a99ff494 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
Dave Airlied985c102006-01-02 21:32:48 +11002 * \file drm_agpsupport.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * DRM support for AGP/GART backend
Dave Airlieb5e89ed2005-09-25 14:28:13 +10004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * \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/**
Dave Airlie7ab98402005-07-10 16:56:52 +100040 * Get AGP information.
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 *
42 * \param inode device inode.
43 * \param filp file pointer.
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 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +100051int drm_agp_info(drm_device_t * dev, drm_agp_info_t * info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Dave Airlieb5e89ed2005-09-25 14:28:13 +100053 DRM_AGP_KERN *kern;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 if (!dev->agp || !dev->agp->acquired)
56 return -EINVAL;
57
Dave Airlieb5e89ed2005-09-25 14:28:13 +100058 kern = &dev->agp->agp_info;
Dave Airlie7ab98402005-07-10 16:56:52 +100059 info->agp_version_major = kern->version.major;
60 info->agp_version_minor = kern->version.minor;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100061 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Dave Airlie7ab98402005-07-10 16:56:52 +100069 return 0;
70}
Dave Airlieb5e89ed2005-09-25 14:28:13 +100071
Dave Airlie7ab98402005-07-10 16:56:52 +100072EXPORT_SYMBOL(drm_agp_info);
73
74int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
Dave Airlieb5e89ed2005-09-25 14:28:13 +100075 unsigned int cmd, unsigned long arg)
Dave Airlie7ab98402005-07-10 16:56:52 +100076{
77 drm_file_t *priv = filp->private_data;
78 drm_device_t *dev = priv->head->dev;
79 drm_agp_info_t info;
80 int err;
81
82 err = drm_agp_info(dev, &info);
83 if (err)
84 return err;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100085
Dave Airlie7ab98402005-07-10 16:56:52 +100086 if (copy_to_user((drm_agp_info_t __user *) arg, &info, sizeof(info)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 return -EFAULT;
88 return 0;
89}
90
91/**
Dave Airlie7ab98402005-07-10 16:56:52 +100092 * Acquire the AGP device.
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 *
Dave Airlied985c102006-01-02 21:32:48 +110094 * \param dev DRM device that is to acquire AGP.
Dave Airlieb5e89ed2005-09-25 14:28:13 +100095 * \return zero on success or a negative number on failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 *
97 * Verifies the AGP device hasn't been acquired before and calls
Dave Airlie7ab98402005-07-10 16:56:52 +100098 * \c agp_backend_acquire.
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000100int drm_agp_acquire(drm_device_t * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 if (!dev->agp)
103 return -ENODEV;
104 if (dev->agp->acquired)
105 return -EBUSY;
106 if (!(dev->agp->bridge = agp_backend_acquire(dev->pdev)))
107 return -ENODEV;
108 dev->agp->acquired = 1;
109 return 0;
110}
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000111
Dave Airlie7ab98402005-07-10 16:56:52 +1000112EXPORT_SYMBOL(drm_agp_acquire);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114/**
Dave Airlie7ab98402005-07-10 16:56:52 +1000115 * Acquire the AGP device (ioctl).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 *
117 * \param inode device inode.
118 * \param filp file pointer.
119 * \param cmd command.
120 * \param arg user argument.
121 * \return zero on success or a negative number on failure.
122 *
Dave Airlie7ab98402005-07-10 16:56:52 +1000123 * Verifies the AGP device hasn't been acquired before and calls
124 * \c agp_backend_acquire.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 */
Dave Airlie7ab98402005-07-10 16:56:52 +1000126int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
127 unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
Dave Airlie7ab98402005-07-10 16:56:52 +1000129 drm_file_t *priv = filp->private_data;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000130
131 return drm_agp_acquire((drm_device_t *) priv->head->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
134/**
135 * Release the AGP device.
136 *
Dave Airlied985c102006-01-02 21:32:48 +1100137 * \param dev DRM device that is to release AGP.
Dave Airlie7ab98402005-07-10 16:56:52 +1000138 * \return zero on success or a negative number on failure.
139 *
140 * Verifies the AGP device has been acquired and calls \c agp_backend_release.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000142int drm_agp_release(drm_device_t * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Dave Airlie7ab98402005-07-10 16:56:52 +1000144 if (!dev->agp || !dev->agp->acquired)
145 return -EINVAL;
146 agp_backend_release(dev->agp->bridge);
147 dev->agp->acquired = 0;
148 return 0;
149}
150EXPORT_SYMBOL(drm_agp_release);
151
152int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
153 unsigned int cmd, unsigned long arg)
154{
155 drm_file_t *priv = filp->private_data;
156 drm_device_t *dev = priv->head->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000157
Dave Airlie7ab98402005-07-10 16:56:52 +1000158 return drm_agp_release(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
161/**
162 * Enable the AGP bus.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000163 *
Dave Airlie7ab98402005-07-10 16:56:52 +1000164 * \param dev DRM device that has previously acquired AGP.
165 * \param mode Requested AGP mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 * \return zero on success or a negative number on failure.
167 *
168 * Verifies the AGP device has been acquired but not enabled, and calls
Dave Airlie7ab98402005-07-10 16:56:52 +1000169 * \c agp_enable.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000171int drm_agp_enable(drm_device_t * dev, drm_agp_mode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 if (!dev->agp || !dev->agp->acquired)
174 return -EINVAL;
175
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000176 dev->agp->mode = mode.mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 agp_enable(dev->agp->bridge, mode.mode);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000178 dev->agp->base = dev->agp->agp_info.aper_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 dev->agp->enabled = 1;
180 return 0;
181}
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000182
Dave Airlie7ab98402005-07-10 16:56:52 +1000183EXPORT_SYMBOL(drm_agp_enable);
184
185int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000186 unsigned int cmd, unsigned long arg)
Dave Airlie7ab98402005-07-10 16:56:52 +1000187{
188 drm_file_t *priv = filp->private_data;
189 drm_device_t *dev = priv->head->dev;
190 drm_agp_mode_t mode;
191
Dave Airlie7ab98402005-07-10 16:56:52 +1000192 if (copy_from_user(&mode, (drm_agp_mode_t __user *) arg, sizeof(mode)))
193 return -EFAULT;
194
195 return drm_agp_enable(dev, mode);
196}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198/**
199 * Allocate AGP memory.
200 *
201 * \param inode device inode.
202 * \param filp file pointer.
203 * \param cmd command.
204 * \param arg pointer to a drm_agp_buffer structure.
205 * \return zero on success or a negative number on failure.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000206 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 * Verifies the AGP device is present and has been acquired, allocates the
208 * memory via alloc_agp() and creates a drm_agp_mem entry for it.
209 */
Dave Airlieefa58392005-11-11 22:33:39 +1100210int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000212 drm_agp_mem_t *entry;
213 DRM_AGP_MEM *memory;
214 unsigned long pages;
215 u32 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 if (!dev->agp || !dev->agp->acquired)
218 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 if (!(entry = drm_alloc(sizeof(*entry), DRM_MEM_AGPLISTS)))
220 return -ENOMEM;
221
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000222 memset(entry, 0, sizeof(*entry));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Dave Airlieefa58392005-11-11 22:33:39 +1100224 pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
225 type = (u32) request->type;
Dave Airlieb5d499c2005-07-10 18:17:42 +1000226 if (!(memory = drm_alloc_agp(dev, pages, type))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
228 return -ENOMEM;
229 }
230
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000231 entry->handle = (unsigned long)memory->key + 1;
232 entry->memory = memory;
233 entry->bound = 0;
234 entry->pages = pages;
235 entry->prev = NULL;
236 entry->next = dev->agp->memory;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 if (dev->agp->memory)
238 dev->agp->memory->prev = entry;
239 dev->agp->memory = entry;
240
Dave Airlieefa58392005-11-11 22:33:39 +1100241 request->handle = entry->handle;
242 request->physical = memory->physical;
243
244 return 0;
245}
246EXPORT_SYMBOL(drm_agp_alloc);
247
248int drm_agp_alloc_ioctl(struct inode *inode, struct file *filp,
249 unsigned int cmd, unsigned long arg)
250{
251 drm_file_t *priv = filp->private_data;
252 drm_device_t *dev = priv->head->dev;
253 drm_agp_buffer_t request;
254 drm_agp_buffer_t __user *argp = (void __user *)arg;
255 int err;
256
257 if (copy_from_user(&request, argp, sizeof(request)))
258 return -EFAULT;
259
260 err = drm_agp_alloc(dev, &request);
261 if (err)
262 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 if (copy_to_user(argp, &request, sizeof(request))) {
Dave Airlieefa58392005-11-11 22:33:39 +1100265 drm_agp_mem_t *entry = dev->agp->memory;
266
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000267 dev->agp->memory = entry->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 dev->agp->memory->prev = NULL;
Dave Airlieefa58392005-11-11 22:33:39 +1100269 drm_free_agp(entry->memory, entry->pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
271 return -EFAULT;
272 }
Dave Airlieefa58392005-11-11 22:33:39 +1100273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 return 0;
275}
276
277/**
278 * Search for the AGP memory entry associated with a handle.
279 *
280 * \param dev DRM device structure.
281 * \param handle AGP memory handle.
282 * \return pointer to the drm_agp_mem structure associated with \p handle.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000283 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 * Walks through drm_agp_head::memory until finding a matching handle.
285 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000286static drm_agp_mem_t *drm_agp_lookup_entry(drm_device_t * dev,
287 unsigned long handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
289 drm_agp_mem_t *entry;
290
291 for (entry = dev->agp->memory; entry; entry = entry->next) {
292 if (entry->handle == handle)
293 return entry;
294 }
295 return NULL;
296}
297
298/**
299 * Unbind AGP memory from the GATT (ioctl).
300 *
301 * \param inode device inode.
302 * \param filp file pointer.
303 * \param cmd command.
304 * \param arg pointer to a drm_agp_binding structure.
305 * \return zero on success or a negative number on failure.
306 *
307 * Verifies the AGP device is present and acquired, looks-up the AGP memory
308 * entry and passes it to the unbind_agp() function.
309 */
Dave Airlieefa58392005-11-11 22:33:39 +1100310int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000312 drm_agp_mem_t *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 int ret;
314
315 if (!dev->agp || !dev->agp->acquired)
316 return -EINVAL;
Dave Airlieefa58392005-11-11 22:33:39 +1100317 if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 return -EINVAL;
319 if (!entry->bound)
320 return -EINVAL;
321 ret = drm_unbind_agp(entry->memory);
322 if (ret == 0)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000323 entry->bound = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 return ret;
325}
Dave Airlieefa58392005-11-11 22:33:39 +1100326EXPORT_SYMBOL(drm_agp_unbind);
327
328int drm_agp_unbind_ioctl(struct inode *inode, struct file *filp,
329 unsigned int cmd, unsigned long arg)
330{
331 drm_file_t *priv = filp->private_data;
332 drm_device_t *dev = priv->head->dev;
333 drm_agp_binding_t request;
334
335 if (copy_from_user
336 (&request, (drm_agp_binding_t __user *) arg, sizeof(request)))
337 return -EFAULT;
338
339 return drm_agp_unbind(dev, &request);
340}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342/**
343 * Bind AGP memory into the GATT (ioctl)
344 *
345 * \param inode device inode.
346 * \param filp file pointer.
347 * \param cmd command.
348 * \param arg pointer to a drm_agp_binding structure.
349 * \return zero on success or a negative number on failure.
350 *
351 * Verifies the AGP device is present and has been acquired and that no memory
352 * is currently bound into the GATT. Looks-up the AGP memory entry and passes
353 * it to bind_agp() function.
354 */
Dave Airlieefa58392005-11-11 22:33:39 +1100355int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000357 drm_agp_mem_t *entry;
358 int retcode;
359 int page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361 if (!dev->agp || !dev->agp->acquired)
362 return -EINVAL;
Dave Airlieefa58392005-11-11 22:33:39 +1100363 if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 return -EINVAL;
365 if (entry->bound)
366 return -EINVAL;
Dave Airlieefa58392005-11-11 22:33:39 +1100367 page = (request->offset + PAGE_SIZE - 1) / PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 if ((retcode = drm_bind_agp(entry->memory, page)))
369 return retcode;
370 entry->bound = dev->agp->base + (page << PAGE_SHIFT);
371 DRM_DEBUG("base = 0x%lx entry->bound = 0x%lx\n",
372 dev->agp->base, entry->bound);
373 return 0;
374}
Dave Airlieefa58392005-11-11 22:33:39 +1100375EXPORT_SYMBOL(drm_agp_bind);
376
377int drm_agp_bind_ioctl(struct inode *inode, struct file *filp,
378 unsigned int cmd, unsigned long arg)
379{
380 drm_file_t *priv = filp->private_data;
381 drm_device_t *dev = priv->head->dev;
382 drm_agp_binding_t request;
383
384 if (copy_from_user
385 (&request, (drm_agp_binding_t __user *) arg, sizeof(request)))
386 return -EFAULT;
387
388 return drm_agp_bind(dev, &request);
389}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391/**
392 * Free AGP memory (ioctl).
393 *
394 * \param inode device inode.
395 * \param filp file pointer.
396 * \param cmd command.
397 * \param arg pointer to a drm_agp_buffer structure.
398 * \return zero on success or a negative number on failure.
399 *
400 * Verifies the AGP device is present and has been acquired and looks up the
401 * AGP memory entry. If the memory it's currently bound, unbind it via
402 * unbind_agp(). Frees it via free_agp() as well as the entry itself
403 * and unlinks from the doubly linked list it's inserted in.
404 */
Dave Airlieefa58392005-11-11 22:33:39 +1100405int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000407 drm_agp_mem_t *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 if (!dev->agp || !dev->agp->acquired)
410 return -EINVAL;
Dave Airlieefa58392005-11-11 22:33:39 +1100411 if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 return -EINVAL;
413 if (entry->bound)
414 drm_unbind_agp(entry->memory);
415
416 if (entry->prev)
417 entry->prev->next = entry->next;
418 else
419 dev->agp->memory = entry->next;
420
421 if (entry->next)
422 entry->next->prev = entry->prev;
423
424 drm_free_agp(entry->memory, entry->pages);
425 drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
426 return 0;
427}
Dave Airlieefa58392005-11-11 22:33:39 +1100428EXPORT_SYMBOL(drm_agp_free);
429
430int drm_agp_free_ioctl(struct inode *inode, struct file *filp,
431 unsigned int cmd, unsigned long arg)
432{
433 drm_file_t *priv = filp->private_data;
434 drm_device_t *dev = priv->head->dev;
435 drm_agp_buffer_t request;
436
437 if (copy_from_user
438 (&request, (drm_agp_buffer_t __user *) arg, sizeof(request)))
439 return -EFAULT;
440
441 return drm_agp_free(dev, &request);
442}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444/**
445 * Initialize the AGP resources.
446 *
447 * \return pointer to a drm_agp_head structure.
448 *
Dave Airlied985c102006-01-02 21:32:48 +1100449 * Gets the drm_agp_t structure which is made available by the agpgart module
450 * via the inter_module_* functions. Creates and initializes a drm_agp_head
451 * structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000453drm_agp_head_t *drm_agp_init(drm_device_t * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000455 drm_agp_head_t *head = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457 if (!(head = drm_alloc(sizeof(*head), DRM_MEM_AGPLISTS)))
458 return NULL;
459 memset((void *)head, 0, sizeof(*head));
460 head->bridge = agp_find_bridge(dev->pdev);
461 if (!head->bridge) {
462 if (!(head->bridge = agp_backend_acquire(dev->pdev))) {
463 drm_free(head, sizeof(*head), DRM_MEM_AGPLISTS);
464 return NULL;
465 }
466 agp_copy_info(head->bridge, &head->agp_info);
467 agp_backend_release(head->bridge);
468 } else {
469 agp_copy_info(head->bridge, &head->agp_info);
470 }
471 if (head->agp_info.chipset == NOT_SUPPORTED) {
472 drm_free(head, sizeof(*head), DRM_MEM_AGPLISTS);
473 return NULL;
474 }
475 head->memory = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 head->cant_use_aperture = head->agp_info.cant_use_aperture;
477 head->page_mask = head->agp_info.page_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479 return head;
480}
481
482/** Calls agp_allocate_memory() */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000483DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data * bridge,
484 size_t pages, u32 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
486 return agp_allocate_memory(bridge, pages, type);
487}
488
489/** Calls agp_free_memory() */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000490int drm_agp_free_memory(DRM_AGP_MEM * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
492 if (!handle)
493 return 0;
494 agp_free_memory(handle);
495 return 1;
496}
497
498/** Calls agp_bind_memory() */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000499int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
501 if (!handle)
502 return -EINVAL;
503 return agp_bind_memory(handle, start);
504}
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506/** Calls agp_unbind_memory() */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000507int drm_agp_unbind_memory(DRM_AGP_MEM * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508{
509 if (!handle)
510 return -EINVAL;
511 return agp_unbind_memory(handle);
512}
513
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000514#endif /* __OS_HAS_AGP */