blob: b80e61a4c40be858d159cb212c69b9a66c67ea0a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
Dave Airlieb5e89ed2005-09-25 14:28:13 +10002 * \file drm_agpsupport.h
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 Airlie7ab98402005-07-10 16:56:52 +100094 * \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 Airlie7ab98402005-07-10 16:56:52 +1000137 * \param dev DRM device that is to release AGP
138 * \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}
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000150
Dave Airlie7ab98402005-07-10 16:56:52 +1000151EXPORT_SYMBOL(drm_agp_release);
152
153int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
154 unsigned int cmd, unsigned long arg)
155{
156 drm_file_t *priv = filp->private_data;
157 drm_device_t *dev = priv->head->dev;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000158
Dave Airlie7ab98402005-07-10 16:56:52 +1000159 return drm_agp_release(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
161
162/**
163 * Enable the AGP bus.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000164 *
Dave Airlie7ab98402005-07-10 16:56:52 +1000165 * \param dev DRM device that has previously acquired AGP.
166 * \param mode Requested AGP mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 * \return zero on success or a negative number on failure.
168 *
169 * Verifies the AGP device has been acquired but not enabled, and calls
Dave Airlie7ab98402005-07-10 16:56:52 +1000170 * \c agp_enable.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000172int drm_agp_enable(drm_device_t * dev, drm_agp_mode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 if (!dev->agp || !dev->agp->acquired)
175 return -EINVAL;
176
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000177 dev->agp->mode = mode.mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 agp_enable(dev->agp->bridge, mode.mode);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000179 dev->agp->base = dev->agp->agp_info.aper_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 dev->agp->enabled = 1;
181 return 0;
182}
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000183
Dave Airlie7ab98402005-07-10 16:56:52 +1000184EXPORT_SYMBOL(drm_agp_enable);
185
186int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000187 unsigned int cmd, unsigned long arg)
Dave Airlie7ab98402005-07-10 16:56:52 +1000188{
189 drm_file_t *priv = filp->private_data;
190 drm_device_t *dev = priv->head->dev;
191 drm_agp_mode_t mode;
192
Dave Airlie7ab98402005-07-10 16:56:52 +1000193 if (copy_from_user(&mode, (drm_agp_mode_t __user *) arg, sizeof(mode)))
194 return -EFAULT;
195
196 return drm_agp_enable(dev, mode);
197}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199/**
200 * Allocate AGP memory.
201 *
202 * \param inode device inode.
203 * \param filp file 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.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000207 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 * 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 */
Dave Airlieefa58392005-11-11 22:33:39 +1100211int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000213 drm_agp_mem_t *entry;
214 DRM_AGP_MEM *memory;
215 unsigned long pages;
216 u32 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218 if (!dev->agp || !dev->agp->acquired)
219 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 if (!(entry = drm_alloc(sizeof(*entry), DRM_MEM_AGPLISTS)))
221 return -ENOMEM;
222
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000223 memset(entry, 0, sizeof(*entry));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Dave Airlieefa58392005-11-11 22:33:39 +1100225 pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
226 type = (u32) request->type;
Dave Airlieb5d499c2005-07-10 18:17:42 +1000227 if (!(memory = drm_alloc_agp(dev, pages, type))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
229 return -ENOMEM;
230 }
231
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000232 entry->handle = (unsigned long)memory->key + 1;
233 entry->memory = memory;
234 entry->bound = 0;
235 entry->pages = pages;
236 entry->prev = NULL;
237 entry->next = dev->agp->memory;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 if (dev->agp->memory)
239 dev->agp->memory->prev = entry;
240 dev->agp->memory = entry;
241
Dave Airlieefa58392005-11-11 22:33:39 +1100242 request->handle = entry->handle;
243 request->physical = memory->physical;
244
245 return 0;
246}
247EXPORT_SYMBOL(drm_agp_alloc);
248
249int drm_agp_alloc_ioctl(struct inode *inode, struct file *filp,
250 unsigned int cmd, unsigned long arg)
251{
252 drm_file_t *priv = filp->private_data;
253 drm_device_t *dev = priv->head->dev;
254 drm_agp_buffer_t request;
255 drm_agp_buffer_t __user *argp = (void __user *)arg;
256 int err;
257
258 if (copy_from_user(&request, argp, sizeof(request)))
259 return -EFAULT;
260
261 err = drm_agp_alloc(dev, &request);
262 if (err)
263 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 if (copy_to_user(argp, &request, sizeof(request))) {
Dave Airlieefa58392005-11-11 22:33:39 +1100266 drm_agp_mem_t *entry = dev->agp->memory;
267
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000268 dev->agp->memory = entry->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 dev->agp->memory->prev = NULL;
Dave Airlieefa58392005-11-11 22:33:39 +1100270 drm_free_agp(entry->memory, entry->pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
272 return -EFAULT;
273 }
Dave Airlieefa58392005-11-11 22:33:39 +1100274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 return 0;
276}
277
278/**
279 * Search for the AGP memory entry associated with a handle.
280 *
281 * \param dev DRM device structure.
282 * \param handle AGP memory handle.
283 * \return pointer to the drm_agp_mem structure associated with \p handle.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000284 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 * Walks through drm_agp_head::memory until finding a matching handle.
286 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000287static drm_agp_mem_t *drm_agp_lookup_entry(drm_device_t * dev,
288 unsigned long handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
290 drm_agp_mem_t *entry;
291
292 for (entry = dev->agp->memory; entry; entry = entry->next) {
293 if (entry->handle == handle)
294 return entry;
295 }
296 return NULL;
297}
298
299/**
300 * Unbind AGP memory from the GATT (ioctl).
301 *
302 * \param inode device inode.
303 * \param filp file pointer.
304 * \param cmd command.
305 * \param arg pointer to a drm_agp_binding structure.
306 * \return zero on success or a negative number on failure.
307 *
308 * Verifies the AGP device is present and acquired, looks-up the AGP memory
309 * entry and passes it to the unbind_agp() function.
310 */
Dave Airlieefa58392005-11-11 22:33:39 +1100311int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000313 drm_agp_mem_t *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 int ret;
315
316 if (!dev->agp || !dev->agp->acquired)
317 return -EINVAL;
Dave Airlieefa58392005-11-11 22:33:39 +1100318 if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 return -EINVAL;
320 if (!entry->bound)
321 return -EINVAL;
322 ret = drm_unbind_agp(entry->memory);
323 if (ret == 0)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000324 entry->bound = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 return ret;
326}
Dave Airlieefa58392005-11-11 22:33:39 +1100327EXPORT_SYMBOL(drm_agp_unbind);
328
329int drm_agp_unbind_ioctl(struct inode *inode, struct file *filp,
330 unsigned int cmd, unsigned long arg)
331{
332 drm_file_t *priv = filp->private_data;
333 drm_device_t *dev = priv->head->dev;
334 drm_agp_binding_t request;
335
336 if (copy_from_user
337 (&request, (drm_agp_binding_t __user *) arg, sizeof(request)))
338 return -EFAULT;
339
340 return drm_agp_unbind(dev, &request);
341}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343/**
344 * Bind AGP memory into the GATT (ioctl)
345 *
346 * \param inode device inode.
347 * \param filp file pointer.
348 * \param cmd command.
349 * \param arg pointer to a drm_agp_binding structure.
350 * \return zero on success or a negative number on failure.
351 *
352 * Verifies the AGP device is present and has been acquired and that no memory
353 * is currently bound into the GATT. Looks-up the AGP memory entry and passes
354 * it to bind_agp() function.
355 */
Dave Airlieefa58392005-11-11 22:33:39 +1100356int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000358 drm_agp_mem_t *entry;
359 int retcode;
360 int page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 if (!dev->agp || !dev->agp->acquired)
363 return -EINVAL;
Dave Airlieefa58392005-11-11 22:33:39 +1100364 if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 return -EINVAL;
366 if (entry->bound)
367 return -EINVAL;
Dave Airlieefa58392005-11-11 22:33:39 +1100368 page = (request->offset + PAGE_SIZE - 1) / PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 if ((retcode = drm_bind_agp(entry->memory, page)))
370 return retcode;
371 entry->bound = dev->agp->base + (page << PAGE_SHIFT);
372 DRM_DEBUG("base = 0x%lx entry->bound = 0x%lx\n",
373 dev->agp->base, entry->bound);
374 return 0;
375}
Dave Airlieefa58392005-11-11 22:33:39 +1100376EXPORT_SYMBOL(drm_agp_bind);
377
378int drm_agp_bind_ioctl(struct inode *inode, struct file *filp,
379 unsigned int cmd, unsigned long arg)
380{
381 drm_file_t *priv = filp->private_data;
382 drm_device_t *dev = priv->head->dev;
383 drm_agp_binding_t request;
384
385 if (copy_from_user
386 (&request, (drm_agp_binding_t __user *) arg, sizeof(request)))
387 return -EFAULT;
388
389 return drm_agp_bind(dev, &request);
390}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392/**
393 * Free AGP memory (ioctl).
394 *
395 * \param inode device inode.
396 * \param filp file pointer.
397 * \param cmd command.
398 * \param arg pointer to a drm_agp_buffer structure.
399 * \return zero on success or a negative number on failure.
400 *
401 * Verifies the AGP device is present and has been acquired and looks up the
402 * AGP memory entry. If the memory it's currently bound, unbind it via
403 * unbind_agp(). Frees it via free_agp() as well as the entry itself
404 * and unlinks from the doubly linked list it's inserted in.
405 */
Dave Airlieefa58392005-11-11 22:33:39 +1100406int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000408 drm_agp_mem_t *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 if (!dev->agp || !dev->agp->acquired)
411 return -EINVAL;
Dave Airlieefa58392005-11-11 22:33:39 +1100412 if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 return -EINVAL;
414 if (entry->bound)
415 drm_unbind_agp(entry->memory);
416
417 if (entry->prev)
418 entry->prev->next = entry->next;
419 else
420 dev->agp->memory = entry->next;
421
422 if (entry->next)
423 entry->next->prev = entry->prev;
424
425 drm_free_agp(entry->memory, entry->pages);
426 drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
427 return 0;
428}
Dave Airlieefa58392005-11-11 22:33:39 +1100429EXPORT_SYMBOL(drm_agp_free);
430
431int drm_agp_free_ioctl(struct inode *inode, struct file *filp,
432 unsigned int cmd, unsigned long arg)
433{
434 drm_file_t *priv = filp->private_data;
435 drm_device_t *dev = priv->head->dev;
436 drm_agp_buffer_t request;
437
438 if (copy_from_user
439 (&request, (drm_agp_buffer_t __user *) arg, sizeof(request)))
440 return -EFAULT;
441
442 return drm_agp_free(dev, &request);
443}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445/**
446 * Initialize the AGP resources.
447 *
448 * \return pointer to a drm_agp_head structure.
449 *
450 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000451drm_agp_head_t *drm_agp_init(drm_device_t * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000453 drm_agp_head_t *head = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 if (!(head = drm_alloc(sizeof(*head), DRM_MEM_AGPLISTS)))
456 return NULL;
457 memset((void *)head, 0, sizeof(*head));
458 head->bridge = agp_find_bridge(dev->pdev);
459 if (!head->bridge) {
460 if (!(head->bridge = agp_backend_acquire(dev->pdev))) {
461 drm_free(head, sizeof(*head), DRM_MEM_AGPLISTS);
462 return NULL;
463 }
464 agp_copy_info(head->bridge, &head->agp_info);
465 agp_backend_release(head->bridge);
466 } else {
467 agp_copy_info(head->bridge, &head->agp_info);
468 }
469 if (head->agp_info.chipset == NOT_SUPPORTED) {
470 drm_free(head, sizeof(*head), DRM_MEM_AGPLISTS);
471 return NULL;
472 }
473 head->memory = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 head->cant_use_aperture = head->agp_info.cant_use_aperture;
475 head->page_mask = head->agp_info.page_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
477 return head;
478}
479
480/** Calls agp_allocate_memory() */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000481DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data * bridge,
482 size_t pages, u32 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
484 return agp_allocate_memory(bridge, pages, type);
485}
486
487/** Calls agp_free_memory() */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000488int drm_agp_free_memory(DRM_AGP_MEM * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
490 if (!handle)
491 return 0;
492 agp_free_memory(handle);
493 return 1;
494}
495
496/** Calls agp_bind_memory() */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000497int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
499 if (!handle)
500 return -EINVAL;
501 return agp_bind_memory(handle, start);
502}
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000503
Dave Airlied84f76d2005-07-10 17:04:22 +1000504EXPORT_SYMBOL(drm_agp_bind_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506/** 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 */