2002-01-27 11:23:04 -07:00
|
|
|
/* drm_agpsupport.h -- DRM support for AGP/GART backend -*- linux-c -*-
|
|
|
|
* Created: Mon Dec 13 09:56:45 1999 by faith@precisioninsight.com
|
2005-04-15 21:02:52 -06:00
|
|
|
*/
|
|
|
|
/*-
|
2002-01-27 11:23:04 -07:00
|
|
|
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
|
|
|
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Rickard E. (Rik) Faith <faith@valinux.com>
|
|
|
|
* Gareth Hughes <gareth@valinux.com>
|
2003-08-18 18:41:00 -06:00
|
|
|
*
|
2002-01-27 11:23:04 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "drmP.h"
|
|
|
|
|
2005-01-17 13:24:52 -07:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#include <pci/agpreg.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#endif
|
|
|
|
|
2005-06-28 20:54:19 -06:00
|
|
|
/* Returns 1 if AGP or 0 if not. */
|
2005-07-20 15:17:47 -06:00
|
|
|
static int
|
|
|
|
drm_device_find_capability(drm_device_t *dev, int cap)
|
2004-11-05 18:41:47 -07:00
|
|
|
{
|
2005-06-28 20:54:19 -06:00
|
|
|
int ret;
|
|
|
|
|
2005-08-04 21:50:23 -06:00
|
|
|
if (dev->driver.device_is_agp != NULL) {
|
|
|
|
ret = (*dev->driver.device_is_agp)(dev);
|
2005-06-28 20:54:19 -06:00
|
|
|
|
|
|
|
if (ret != DRM_MIGHT_BE_AGP) {
|
|
|
|
return ret == 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-17 13:24:52 -07:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
/* Code taken from agp.c. IWBNI that was a public interface. */
|
|
|
|
u_int32_t status;
|
|
|
|
u_int8_t ptr, next;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the CAP_LIST bit of the PCI status register first.
|
|
|
|
*/
|
|
|
|
status = pci_read_config(dev->device, PCIR_STATUS, 2);
|
|
|
|
if (!(status & 0x10))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Traverse the capabilities list.
|
|
|
|
*/
|
|
|
|
for (ptr = pci_read_config(dev->device, AGP_CAPPTR, 1);
|
|
|
|
ptr != 0;
|
|
|
|
ptr = next) {
|
|
|
|
u_int32_t capid = pci_read_config(dev->device, ptr, 4);
|
|
|
|
next = AGP_CAPID_GET_NEXT_PTR(capid);
|
|
|
|
|
|
|
|
/*
|
2005-07-20 15:17:47 -06:00
|
|
|
* If this capability entry ID is cap, then we are done.
|
2005-01-17 13:24:52 -07:00
|
|
|
*/
|
2005-07-20 15:17:47 -06:00
|
|
|
if (AGP_CAPID_GET_CAP_ID(capid) == cap)
|
2005-01-17 13:24:52 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
/* XXX: fill me in for non-FreeBSD */
|
2004-11-05 18:41:47 -07:00
|
|
|
return 1;
|
2005-01-17 13:24:52 -07:00
|
|
|
#endif
|
2004-11-05 18:41:47 -07:00
|
|
|
}
|
|
|
|
|
2005-07-20 15:17:47 -06:00
|
|
|
int drm_device_is_agp(drm_device_t *dev)
|
|
|
|
{
|
|
|
|
return (drm_device_find_capability(dev, PCIY_AGP));
|
|
|
|
}
|
|
|
|
|
|
|
|
int drm_device_is_pcie(drm_device_t *dev)
|
|
|
|
{
|
|
|
|
return (drm_device_find_capability(dev, PCIY_EXPRESS));
|
|
|
|
}
|
|
|
|
|
2005-06-28 20:54:19 -06:00
|
|
|
int drm_agp_info(drm_device_t * dev, drm_agp_info_t *info)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
|
|
|
struct agp_info *kern;
|
|
|
|
|
2003-02-21 16:23:09 -07:00
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
2002-01-27 11:23:04 -07:00
|
|
|
|
|
|
|
kern = &dev->agp->info;
|
|
|
|
agp_get_info(dev->agp->agpdev, kern);
|
2005-06-28 20:54:19 -06:00
|
|
|
info->agp_version_major = 1;
|
|
|
|
info->agp_version_minor = 0;
|
|
|
|
info->mode = kern->ai_mode;
|
|
|
|
info->aperture_base = kern->ai_aperture_base;
|
|
|
|
info->aperture_size = kern->ai_aperture_size;
|
|
|
|
info->memory_allowed = kern->ai_memory_allowed;
|
|
|
|
info->memory_used = kern->ai_memory_used;
|
|
|
|
info->id_vendor = kern->ai_devid & 0xffff;
|
|
|
|
info->id_device = kern->ai_devid >> 16;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int drm_agp_info_ioctl(DRM_IOCTL_ARGS)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
drm_agp_info_t info;
|
|
|
|
DRM_DEVICE;
|
|
|
|
|
|
|
|
err = drm_agp_info(dev, &info);
|
|
|
|
if (err != 0)
|
|
|
|
return err;
|
2002-01-27 11:23:04 -07:00
|
|
|
|
|
|
|
*(drm_agp_info_t *) data = info;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-28 20:54:19 -06:00
|
|
|
int drm_agp_acquire_ioctl(DRM_IOCTL_ARGS)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
2002-07-05 02:31:11 -06:00
|
|
|
DRM_DEVICE;
|
2005-06-28 20:54:19 -06:00
|
|
|
|
|
|
|
return drm_agp_acquire(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int drm_agp_acquire(drm_device_t *dev)
|
|
|
|
{
|
|
|
|
int retcode;
|
2002-01-27 11:23:04 -07:00
|
|
|
|
2003-02-21 16:23:09 -07:00
|
|
|
if (!dev->agp || dev->agp->acquired)
|
|
|
|
return EINVAL;
|
2005-06-28 20:54:19 -06:00
|
|
|
|
2002-01-27 11:23:04 -07:00
|
|
|
retcode = agp_acquire(dev->agp->agpdev);
|
2003-02-21 16:23:09 -07:00
|
|
|
if (retcode)
|
|
|
|
return retcode;
|
2005-06-28 20:54:19 -06:00
|
|
|
|
2002-01-27 11:23:04 -07:00
|
|
|
dev->agp->acquired = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Adds support for PCI cards to MGA DRM
This patch adds serveral new ioctls and a new query to get_param query to
support PCI MGA cards.
Two ioctls were added to implement interrupt based waiting. With this
change, the client-side driver no longer needs to map the primary DMA
region or the MMIO region. Previously, end-of-frame waiting was done by
busy waiting in the client-side driver until one of the MMIO registers
(the current DMA pointer) matched a pointer to the end of primary DMA
space. By using interrupts, the busy waiting and the extra mappings are
removed.
A third ioctl was added to bootstrap DMA. This ioctl, which is used by the
X-server, moves a *LOT* of code from the X-server into the kernel. This
allows the kernel to do whatever needs to be done to setup DMA buffers.
The entire process and the locations of the buffers are hidden from
user-mode.
Additionally, a get_param query was added to differentiate between G4x0
cards and G550 cards. A gap was left in the numbering sequence so that,
if needed, G450 cards could be distinguished from G400 cards. According
to Ville Syrjälä, the G4x0 cards and the G550 cards handle
anisotropic filtering differently. This seems the most compatible way
to let the client-side driver know which card it's own. Doing this very
small change now eliminates the need to bump the DRM minor version
twice.
http://marc.theaimsgroup.com/?l=dri-devel&m=106625815319773&w=2
A number of ioctl handlers in linux-core were also modified so that they
could be called in-kernel. In these cases, the in-kernel callable
version kept the existing name (e.g., drm_agp_acquire) and the ioctl
handler added _ioctl to the name (e.g., drm_agp_acquire_ioctl).
This patch also replaces the drm_agp_do_release function with
drm_agp_release. drm_agp_release (drm_core_agp_release in the previous
patch) is very similar to drm_agp_do_release, and I saw no reason to
have both.
This commit *breaks the build* on BSD. Eric said that he would make the
required updates to the BSD side soon.
Xorg bug: 3259 Reviewed by: Eric Anholt
2005-06-14 16:34:11 -06:00
|
|
|
int drm_agp_release_ioctl(DRM_IOCTL_ARGS)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
2002-07-05 02:31:11 -06:00
|
|
|
DRM_DEVICE;
|
2002-01-27 11:23:04 -07:00
|
|
|
|
Adds support for PCI cards to MGA DRM
This patch adds serveral new ioctls and a new query to get_param query to
support PCI MGA cards.
Two ioctls were added to implement interrupt based waiting. With this
change, the client-side driver no longer needs to map the primary DMA
region or the MMIO region. Previously, end-of-frame waiting was done by
busy waiting in the client-side driver until one of the MMIO registers
(the current DMA pointer) matched a pointer to the end of primary DMA
space. By using interrupts, the busy waiting and the extra mappings are
removed.
A third ioctl was added to bootstrap DMA. This ioctl, which is used by the
X-server, moves a *LOT* of code from the X-server into the kernel. This
allows the kernel to do whatever needs to be done to setup DMA buffers.
The entire process and the locations of the buffers are hidden from
user-mode.
Additionally, a get_param query was added to differentiate between G4x0
cards and G550 cards. A gap was left in the numbering sequence so that,
if needed, G450 cards could be distinguished from G400 cards. According
to Ville Syrjälä, the G4x0 cards and the G550 cards handle
anisotropic filtering differently. This seems the most compatible way
to let the client-side driver know which card it's own. Doing this very
small change now eliminates the need to bump the DRM minor version
twice.
http://marc.theaimsgroup.com/?l=dri-devel&m=106625815319773&w=2
A number of ioctl handlers in linux-core were also modified so that they
could be called in-kernel. In these cases, the in-kernel callable
version kept the existing name (e.g., drm_agp_acquire) and the ioctl
handler added _ioctl to the name (e.g., drm_agp_acquire_ioctl).
This patch also replaces the drm_agp_do_release function with
drm_agp_release. drm_agp_release (drm_core_agp_release in the previous
patch) is very similar to drm_agp_do_release, and I saw no reason to
have both.
This commit *breaks the build* on BSD. Eric said that he would make the
required updates to the BSD side soon.
Xorg bug: 3259 Reviewed by: Eric Anholt
2005-06-14 16:34:11 -06:00
|
|
|
return drm_agp_release(dev);
|
|
|
|
}
|
|
|
|
|
2005-06-28 20:54:19 -06:00
|
|
|
int drm_agp_release(drm_device_t * dev)
|
Adds support for PCI cards to MGA DRM
This patch adds serveral new ioctls and a new query to get_param query to
support PCI MGA cards.
Two ioctls were added to implement interrupt based waiting. With this
change, the client-side driver no longer needs to map the primary DMA
region or the MMIO region. Previously, end-of-frame waiting was done by
busy waiting in the client-side driver until one of the MMIO registers
(the current DMA pointer) matched a pointer to the end of primary DMA
space. By using interrupts, the busy waiting and the extra mappings are
removed.
A third ioctl was added to bootstrap DMA. This ioctl, which is used by the
X-server, moves a *LOT* of code from the X-server into the kernel. This
allows the kernel to do whatever needs to be done to setup DMA buffers.
The entire process and the locations of the buffers are hidden from
user-mode.
Additionally, a get_param query was added to differentiate between G4x0
cards and G550 cards. A gap was left in the numbering sequence so that,
if needed, G450 cards could be distinguished from G400 cards. According
to Ville Syrjälä, the G4x0 cards and the G550 cards handle
anisotropic filtering differently. This seems the most compatible way
to let the client-side driver know which card it's own. Doing this very
small change now eliminates the need to bump the DRM minor version
twice.
http://marc.theaimsgroup.com/?l=dri-devel&m=106625815319773&w=2
A number of ioctl handlers in linux-core were also modified so that they
could be called in-kernel. In these cases, the in-kernel callable
version kept the existing name (e.g., drm_agp_acquire) and the ioctl
handler added _ioctl to the name (e.g., drm_agp_acquire_ioctl).
This patch also replaces the drm_agp_do_release function with
drm_agp_release. drm_agp_release (drm_core_agp_release in the previous
patch) is very similar to drm_agp_do_release, and I saw no reason to
have both.
This commit *breaks the build* on BSD. Eric said that he would make the
required updates to the BSD side soon.
Xorg bug: 3259 Reviewed by: Eric Anholt
2005-06-14 16:34:11 -06:00
|
|
|
{
|
2002-01-27 11:23:04 -07:00
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
|
|
|
agp_release(dev->agp->agpdev);
|
|
|
|
dev->agp->acquired = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-28 20:54:19 -06:00
|
|
|
int drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
|
|
|
|
2003-02-21 16:23:09 -07:00
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
2002-01-27 11:23:04 -07:00
|
|
|
|
|
|
|
dev->agp->mode = mode.mode;
|
|
|
|
agp_enable(dev->agp->agpdev, mode.mode);
|
|
|
|
dev->agp->base = dev->agp->info.ai_aperture_base;
|
|
|
|
dev->agp->enabled = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-28 20:54:19 -06:00
|
|
|
int drm_agp_enable_ioctl(DRM_IOCTL_ARGS)
|
|
|
|
{
|
|
|
|
drm_agp_mode_t mode;
|
|
|
|
DRM_DEVICE;
|
|
|
|
|
|
|
|
mode = *(drm_agp_mode_t *) data;
|
|
|
|
|
|
|
|
return drm_agp_enable(dev, mode);
|
|
|
|
}
|
|
|
|
|
2004-11-05 18:41:47 -07:00
|
|
|
int drm_agp_alloc(DRM_IOCTL_ARGS)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
2002-07-05 02:31:11 -06:00
|
|
|
DRM_DEVICE;
|
2002-01-27 11:23:04 -07:00
|
|
|
drm_agp_buffer_t request;
|
|
|
|
drm_agp_mem_t *entry;
|
|
|
|
void *handle;
|
|
|
|
unsigned long pages;
|
|
|
|
u_int32_t type;
|
|
|
|
struct agp_memory_info info;
|
|
|
|
|
2003-02-21 16:23:09 -07:00
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
2002-01-27 11:23:04 -07:00
|
|
|
|
|
|
|
request = *(drm_agp_buffer_t *) data;
|
|
|
|
|
2004-11-06 17:25:49 -07:00
|
|
|
entry = malloc(sizeof(*entry), M_DRM, M_NOWAIT | M_ZERO);
|
|
|
|
if (entry == NULL)
|
2002-01-27 11:23:04 -07:00
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
|
|
|
|
type = (u_int32_t) request.type;
|
|
|
|
|
2004-11-06 04:16:26 -07:00
|
|
|
if (!(handle = drm_agp_allocate_memory(pages, type))) {
|
2004-11-06 17:25:49 -07:00
|
|
|
free(entry, M_DRM);
|
2002-01-27 11:23:04 -07:00
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->handle = handle;
|
|
|
|
entry->bound = 0;
|
|
|
|
entry->pages = pages;
|
|
|
|
entry->prev = NULL;
|
|
|
|
entry->next = dev->agp->memory;
|
2003-02-21 16:23:09 -07:00
|
|
|
if (dev->agp->memory)
|
|
|
|
dev->agp->memory->prev = entry;
|
2002-01-27 11:23:04 -07:00
|
|
|
dev->agp->memory = entry;
|
|
|
|
|
|
|
|
agp_memory_info(dev->agp->agpdev, entry->handle, &info);
|
|
|
|
|
|
|
|
request.handle = (unsigned long) entry->handle;
|
|
|
|
request.physical = info.ami_physical;
|
|
|
|
|
|
|
|
*(drm_agp_buffer_t *) data = request;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-11-05 18:41:47 -07:00
|
|
|
static drm_agp_mem_t * drm_agp_lookup_entry(drm_device_t *dev, void *handle)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
|
|
|
drm_agp_mem_t *entry;
|
|
|
|
|
|
|
|
for (entry = dev->agp->memory; entry; entry = entry->next) {
|
|
|
|
if (entry->handle == handle) return entry;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-11-05 18:41:47 -07:00
|
|
|
int drm_agp_unbind(DRM_IOCTL_ARGS)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
2002-07-05 02:31:11 -06:00
|
|
|
DRM_DEVICE;
|
2002-01-27 11:23:04 -07:00
|
|
|
drm_agp_binding_t request;
|
|
|
|
drm_agp_mem_t *entry;
|
|
|
|
int retcode;
|
|
|
|
|
2003-02-21 16:23:09 -07:00
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
2002-01-27 11:23:04 -07:00
|
|
|
request = *(drm_agp_binding_t *) data;
|
2004-11-05 18:41:47 -07:00
|
|
|
if (!(entry = drm_agp_lookup_entry(dev, (void *)request.handle)))
|
2002-01-27 11:23:04 -07:00
|
|
|
return EINVAL;
|
|
|
|
if (!entry->bound) return EINVAL;
|
2004-11-06 04:16:26 -07:00
|
|
|
retcode = drm_agp_unbind_memory(entry->handle);
|
2002-01-27 11:23:04 -07:00
|
|
|
if (!retcode)
|
|
|
|
{
|
|
|
|
entry->bound=0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
|
2004-11-05 18:41:47 -07:00
|
|
|
int drm_agp_bind(DRM_IOCTL_ARGS)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
2002-07-05 02:31:11 -06:00
|
|
|
DRM_DEVICE;
|
2002-01-27 11:23:04 -07:00
|
|
|
drm_agp_binding_t request;
|
|
|
|
drm_agp_mem_t *entry;
|
|
|
|
int retcode;
|
|
|
|
int page;
|
|
|
|
|
|
|
|
DRM_DEBUG("agp_bind, page_size=%x\n", PAGE_SIZE);
|
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
|
|
|
request = *(drm_agp_binding_t *) data;
|
2004-11-05 18:41:47 -07:00
|
|
|
if (!(entry = drm_agp_lookup_entry(dev, (void *)request.handle)))
|
2002-01-27 11:23:04 -07:00
|
|
|
return EINVAL;
|
|
|
|
if (entry->bound) return EINVAL;
|
|
|
|
page = (request.offset + PAGE_SIZE - 1) / PAGE_SIZE;
|
2004-11-06 04:16:26 -07:00
|
|
|
if ((retcode = drm_agp_bind_memory(entry->handle, page)))
|
2002-01-27 11:23:04 -07:00
|
|
|
return retcode;
|
|
|
|
entry->bound = dev->agp->base + (page << PAGE_SHIFT);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-11-05 18:41:47 -07:00
|
|
|
int drm_agp_free(DRM_IOCTL_ARGS)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
2002-07-05 02:31:11 -06:00
|
|
|
DRM_DEVICE;
|
2002-01-27 11:23:04 -07:00
|
|
|
drm_agp_buffer_t request;
|
|
|
|
drm_agp_mem_t *entry;
|
|
|
|
|
2003-02-21 16:23:09 -07:00
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
2002-01-27 11:23:04 -07:00
|
|
|
request = *(drm_agp_buffer_t *) data;
|
2004-11-05 18:41:47 -07:00
|
|
|
if (!(entry = drm_agp_lookup_entry(dev, (void*)request.handle)))
|
2002-01-27 11:23:04 -07:00
|
|
|
return EINVAL;
|
2003-02-21 16:23:09 -07:00
|
|
|
if (entry->bound)
|
2004-11-06 04:16:26 -07:00
|
|
|
drm_agp_unbind_memory(entry->handle);
|
2002-01-27 11:23:04 -07:00
|
|
|
|
2003-02-21 16:23:09 -07:00
|
|
|
if (entry->prev)
|
|
|
|
entry->prev->next = entry->next;
|
|
|
|
else
|
|
|
|
dev->agp->memory = entry->next;
|
|
|
|
if (entry->next)
|
|
|
|
entry->next->prev = entry->prev;
|
2004-11-06 04:16:26 -07:00
|
|
|
drm_agp_free_memory(entry->handle);
|
2004-11-06 17:25:49 -07:00
|
|
|
free(entry, M_DRM);
|
2002-01-27 11:23:04 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-11-05 18:41:47 -07:00
|
|
|
drm_agp_head_t *drm_agp_init(void)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
|
|
|
device_t agpdev;
|
|
|
|
drm_agp_head_t *head = NULL;
|
|
|
|
int agp_available = 1;
|
|
|
|
|
2002-07-05 02:31:11 -06:00
|
|
|
agpdev = DRM_AGP_FIND_DEVICE();
|
2002-01-27 11:23:04 -07:00
|
|
|
if (!agpdev)
|
|
|
|
agp_available = 0;
|
|
|
|
|
|
|
|
DRM_DEBUG("agp_available = %d\n", agp_available);
|
|
|
|
|
|
|
|
if (agp_available) {
|
2004-11-06 17:25:49 -07:00
|
|
|
head = malloc(sizeof(*head), M_DRM, M_NOWAIT | M_ZERO);
|
|
|
|
if (head == NULL)
|
2002-01-27 11:23:04 -07:00
|
|
|
return NULL;
|
|
|
|
head->agpdev = agpdev;
|
|
|
|
agp_get_info(agpdev, &head->info);
|
|
|
|
head->memory = NULL;
|
2002-07-05 02:31:11 -06:00
|
|
|
DRM_INFO("AGP at 0x%08lx %dMB\n",
|
2002-09-26 01:21:05 -06:00
|
|
|
(long)head->info.ai_aperture_base,
|
2002-07-05 02:31:11 -06:00
|
|
|
(int)(head->info.ai_aperture_size >> 20));
|
2002-01-27 11:23:04 -07:00
|
|
|
}
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
2004-11-05 18:41:47 -07:00
|
|
|
void drm_agp_uninit(void)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
|
|
|
/* FIXME: What goes here */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-06 04:16:26 -07:00
|
|
|
void *drm_agp_allocate_memory(size_t pages, u32 type)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
|
|
|
device_t agpdev;
|
|
|
|
|
2002-07-05 02:31:11 -06:00
|
|
|
agpdev = DRM_AGP_FIND_DEVICE();
|
2002-01-27 11:23:04 -07:00
|
|
|
if (!agpdev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return agp_alloc_memory(agpdev, type, pages << AGP_PAGE_SHIFT);
|
|
|
|
}
|
|
|
|
|
2004-11-06 04:16:26 -07:00
|
|
|
int drm_agp_free_memory(void *handle)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
|
|
|
device_t agpdev;
|
|
|
|
|
2002-07-05 02:31:11 -06:00
|
|
|
agpdev = DRM_AGP_FIND_DEVICE();
|
2002-01-27 11:23:04 -07:00
|
|
|
if (!agpdev || !handle)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
agp_free_memory(agpdev, handle);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-11-06 04:16:26 -07:00
|
|
|
int drm_agp_bind_memory(void *handle, off_t start)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
|
|
|
device_t agpdev;
|
|
|
|
|
2002-07-05 02:31:11 -06:00
|
|
|
agpdev = DRM_AGP_FIND_DEVICE();
|
2002-01-27 11:23:04 -07:00
|
|
|
if (!agpdev || !handle)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
return agp_bind_memory(agpdev, handle, start * PAGE_SIZE);
|
|
|
|
}
|
|
|
|
|
2004-11-06 04:16:26 -07:00
|
|
|
int drm_agp_unbind_memory(void *handle)
|
2002-01-27 11:23:04 -07:00
|
|
|
{
|
|
|
|
device_t agpdev;
|
|
|
|
|
2002-07-05 02:31:11 -06:00
|
|
|
agpdev = DRM_AGP_FIND_DEVICE();
|
2002-01-27 11:23:04 -07:00
|
|
|
if (!agpdev || !handle)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
return agp_unbind_memory(agpdev, handle);
|
|
|
|
}
|