2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2002-04-27 20:47:57 +00: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-19 02:57:31 +00:00
|
|
|
*
|
2002-04-27 20:47:57 +00:00
|
|
|
*/
|
|
|
|
|
2005-11-28 23:13:57 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
/** @file drm_agpsupport.c
|
|
|
|
* Support code for tying the kernel AGP support to DRM drivers and
|
|
|
|
* the DRM's AGP ioctls.
|
|
|
|
*/
|
|
|
|
|
2002-04-27 20:47:57 +00:00
|
|
|
#include "dev/drm/drmP.h"
|
|
|
|
|
2007-11-12 21:51:38 +00:00
|
|
|
#if __FreeBSD_version >= 800004
|
|
|
|
#include <dev/agp/agpreg.h>
|
2008-08-23 20:59:12 +00:00
|
|
|
#else /* __FreeBSD_version >= 800004 */
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
#include <pci/agpreg.h>
|
2008-08-23 20:59:12 +00:00
|
|
|
#endif /* __FreeBSD_version >= 800004 */
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
|
2005-11-28 23:13:57 +00:00
|
|
|
/* Returns 1 if AGP or 0 if not. */
|
2005-07-20 21:10:57 +00:00
|
|
|
static int
|
2008-08-23 20:59:12 +00:00
|
|
|
drm_device_find_capability(struct drm_device *dev, int cap)
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
{
|
2006-12-28 21:55:47 +00:00
|
|
|
#if __FreeBSD_version >= 602102
|
2005-12-20 22:44:36 +00:00
|
|
|
|
2011-03-23 13:10:15 +00:00
|
|
|
return (pci_find_cap(dev->device, cap, NULL) == 0);
|
2005-12-20 22:44:36 +00:00
|
|
|
#else
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
/* 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 21:10:57 +00:00
|
|
|
* If this capability entry ID is cap, then we are done.
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
*/
|
2005-07-20 21:10:57 +00:00
|
|
|
if (AGP_CAPID_GET_CAP_ID(capid) == cap)
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2005-12-20 22:44:36 +00:00
|
|
|
#endif
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_device_is_agp(struct drm_device *dev)
|
2005-07-20 21:10:57 +00:00
|
|
|
{
|
2008-10-03 16:59:11 +00:00
|
|
|
if (dev->driver->device_is_agp != NULL) {
|
2005-11-28 23:13:57 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* device_is_agp returns a tristate, 0 = not AGP, 1 = definitely
|
|
|
|
* AGP, 2 = fall back to PCI capability
|
|
|
|
*/
|
2008-10-03 16:59:11 +00:00
|
|
|
ret = (*dev->driver->device_is_agp)(dev);
|
2006-04-09 20:45:45 +00:00
|
|
|
if (ret != DRM_MIGHT_BE_AGP)
|
2005-11-28 23:13:57 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-07-20 21:10:57 +00:00
|
|
|
return (drm_device_find_capability(dev, PCIY_AGP));
|
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_device_is_pcie(struct drm_device *dev)
|
2005-07-20 21:10:57 +00:00
|
|
|
{
|
|
|
|
return (drm_device_find_capability(dev, PCIY_EXPRESS));
|
|
|
|
}
|
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
|
|
|
struct agp_info *kern;
|
|
|
|
|
2003-03-09 02:08:30 +00:00
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
2002-04-27 20:47:57 +00:00
|
|
|
|
|
|
|
kern = &dev->agp->info;
|
|
|
|
agp_get_info(dev->agp->agpdev, kern);
|
2005-11-28 23:13:57 +00: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;
|
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_agp_info_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2005-11-28 23:13:57 +00:00
|
|
|
{
|
|
|
|
int err;
|
2008-10-03 16:59:11 +00:00
|
|
|
struct drm_agp_info info;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
err = drm_agp_info(dev, &info);
|
|
|
|
if (err != 0)
|
|
|
|
return err;
|
2002-04-27 20:47:57 +00:00
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
*(struct drm_agp_info *) data = info;
|
2002-04-27 20:47:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
return drm_agp_acquire(dev);
|
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_agp_acquire(struct drm_device *dev)
|
2005-11-28 23:13:57 +00:00
|
|
|
{
|
|
|
|
int retcode;
|
2002-04-27 20:47:57 +00:00
|
|
|
|
2003-03-09 02:08:30 +00:00
|
|
|
if (!dev->agp || dev->agp->acquired)
|
|
|
|
return EINVAL;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
2002-04-27 20:47:57 +00:00
|
|
|
retcode = agp_acquire(dev->agp->agpdev);
|
2003-03-09 02:08:30 +00:00
|
|
|
if (retcode)
|
|
|
|
return retcode;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
2002-04-27 20:47:57 +00:00
|
|
|
dev->agp->acquired = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_agp_release_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
|
|
|
|
2005-11-28 23:13:57 +00:00
|
|
|
return drm_agp_release(dev);
|
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_agp_release(struct drm_device * dev)
|
2005-11-28 23:13:57 +00:00
|
|
|
{
|
2002-04-27 20:47:57 +00:00
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
|
|
|
agp_release(dev->agp->agpdev);
|
|
|
|
dev->agp->acquired = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
|
|
|
|
2003-03-09 02:08:30 +00:00
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
2002-04-27 20:47:57 +00:00
|
|
|
|
|
|
|
dev->agp->mode = mode.mode;
|
|
|
|
agp_enable(dev->agp->agpdev, mode.mode);
|
|
|
|
dev->agp->enabled = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
2008-10-03 16:59:11 +00:00
|
|
|
struct drm_agp_mode mode;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
mode = *(struct drm_agp_mode *) data;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
return drm_agp_enable(dev, mode);
|
|
|
|
}
|
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request)
|
2005-11-28 23:13:57 +00:00
|
|
|
{
|
2002-04-27 20:47:57 +00:00
|
|
|
drm_agp_mem_t *entry;
|
|
|
|
void *handle;
|
|
|
|
unsigned long pages;
|
|
|
|
u_int32_t type;
|
|
|
|
struct agp_memory_info info;
|
|
|
|
|
2003-03-09 02:08:30 +00:00
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
2002-04-27 20:47:57 +00:00
|
|
|
|
2008-10-13 18:03:27 +00:00
|
|
|
entry = malloc(sizeof(*entry), DRM_MEM_AGPLISTS, M_NOWAIT | M_ZERO);
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
if (entry == NULL)
|
2002-04-27 20:47:57 +00:00
|
|
|
return ENOMEM;
|
|
|
|
|
2005-11-28 23:13:57 +00:00
|
|
|
pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
|
|
|
|
type = (u_int32_t) request->type;
|
2002-04-27 20:47:57 +00:00
|
|
|
|
2005-11-28 23:13:57 +00:00
|
|
|
DRM_UNLOCK();
|
|
|
|
handle = drm_agp_allocate_memory(pages, type);
|
|
|
|
DRM_LOCK();
|
|
|
|
if (handle == NULL) {
|
2008-10-13 18:03:27 +00:00
|
|
|
free(entry, DRM_MEM_AGPLISTS);
|
2002-04-27 20:47:57 +00:00
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->handle = handle;
|
|
|
|
entry->bound = 0;
|
|
|
|
entry->pages = pages;
|
|
|
|
entry->prev = NULL;
|
|
|
|
entry->next = dev->agp->memory;
|
2003-03-09 02:08:30 +00:00
|
|
|
if (dev->agp->memory)
|
|
|
|
dev->agp->memory->prev = entry;
|
2002-04-27 20:47:57 +00:00
|
|
|
dev->agp->memory = entry;
|
|
|
|
|
|
|
|
agp_memory_info(dev->agp->agpdev, entry->handle, &info);
|
|
|
|
|
2005-11-28 23:13:57 +00:00
|
|
|
request->handle = (unsigned long) entry->handle;
|
|
|
|
request->physical = info.ami_physical;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2005-11-28 23:13:57 +00:00
|
|
|
{
|
2008-10-03 16:59:11 +00:00
|
|
|
struct drm_agp_buffer request;
|
2005-11-28 23:13:57 +00:00
|
|
|
int retcode;
|
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
request = *(struct drm_agp_buffer *) data;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
DRM_LOCK();
|
|
|
|
retcode = drm_agp_alloc(dev, &request);
|
|
|
|
DRM_UNLOCK();
|
2002-04-27 20:47:57 +00:00
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
*(struct drm_agp_buffer *) data = request;
|
2002-04-27 20:47:57 +00:00
|
|
|
|
2005-11-28 23:13:57 +00:00
|
|
|
return retcode;
|
2002-04-27 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
static drm_agp_mem_t * drm_agp_lookup_entry(struct drm_device *dev,
|
|
|
|
void *handle)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
|
|
|
drm_agp_mem_t *entry;
|
|
|
|
|
|
|
|
for (entry = dev->agp->memory; entry; entry = entry->next) {
|
|
|
|
if (entry->handle == handle) return entry;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
|
|
|
drm_agp_mem_t *entry;
|
|
|
|
int retcode;
|
|
|
|
|
2003-03-09 02:08:30 +00:00
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
entry = drm_agp_lookup_entry(dev, (void *)request->handle);
|
|
|
|
if (entry == NULL || !entry->bound)
|
2002-04-27 20:47:57 +00:00
|
|
|
return EINVAL;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
DRM_UNLOCK();
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
retcode = drm_agp_unbind_memory(entry->handle);
|
2005-11-28 23:13:57 +00:00
|
|
|
DRM_LOCK();
|
|
|
|
|
|
|
|
if (retcode == 0)
|
|
|
|
entry->bound = 0;
|
|
|
|
|
|
|
|
return retcode;
|
2002-04-27 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
2008-10-03 16:59:11 +00:00
|
|
|
struct drm_agp_binding request;
|
2005-11-28 23:13:57 +00:00
|
|
|
int retcode;
|
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
request = *(struct drm_agp_binding *) data;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
DRM_LOCK();
|
|
|
|
retcode = drm_agp_unbind(dev, &request);
|
|
|
|
DRM_UNLOCK();
|
|
|
|
|
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request)
|
2005-11-28 23:13:57 +00:00
|
|
|
{
|
2002-04-27 20:47:57 +00:00
|
|
|
drm_agp_mem_t *entry;
|
|
|
|
int retcode;
|
|
|
|
int page;
|
|
|
|
|
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
2010-11-16 03:43:06 +00:00
|
|
|
DRM_DEBUG("agp_bind, page_size=%x\n", (int)PAGE_SIZE);
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
entry = drm_agp_lookup_entry(dev, (void *)request->handle);
|
|
|
|
if (entry == NULL || entry->bound)
|
2002-04-27 20:47:57 +00:00
|
|
|
return EINVAL;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
page = (request->offset + PAGE_SIZE - 1) / PAGE_SIZE;
|
|
|
|
|
|
|
|
DRM_UNLOCK();
|
|
|
|
retcode = drm_agp_bind_memory(entry->handle, page);
|
|
|
|
DRM_LOCK();
|
|
|
|
if (retcode == 0)
|
|
|
|
entry->bound = dev->agp->base + (page << PAGE_SHIFT);
|
|
|
|
|
|
|
|
return retcode;
|
2002-04-27 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
2008-10-03 16:59:11 +00:00
|
|
|
struct drm_agp_binding request;
|
2005-11-28 23:13:57 +00:00
|
|
|
int retcode;
|
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
request = *(struct drm_agp_binding *) data;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
DRM_LOCK();
|
|
|
|
retcode = drm_agp_bind(dev, &request);
|
|
|
|
DRM_UNLOCK();
|
|
|
|
|
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request)
|
2005-11-28 23:13:57 +00:00
|
|
|
{
|
2002-04-27 20:47:57 +00:00
|
|
|
drm_agp_mem_t *entry;
|
|
|
|
|
2003-03-09 02:08:30 +00:00
|
|
|
if (!dev->agp || !dev->agp->acquired)
|
|
|
|
return EINVAL;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
entry = drm_agp_lookup_entry(dev, (void*)request->handle);
|
|
|
|
if (entry == NULL)
|
2002-04-27 20:47:57 +00:00
|
|
|
return EINVAL;
|
|
|
|
|
2003-03-09 02:08:30 +00:00
|
|
|
if (entry->prev)
|
|
|
|
entry->prev->next = entry->next;
|
|
|
|
else
|
|
|
|
dev->agp->memory = entry->next;
|
|
|
|
if (entry->next)
|
|
|
|
entry->next->prev = entry->prev;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
DRM_UNLOCK();
|
|
|
|
if (entry->bound)
|
|
|
|
drm_agp_unbind_memory(entry->handle);
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
drm_agp_free_memory(entry->handle);
|
2005-11-28 23:13:57 +00:00
|
|
|
DRM_LOCK();
|
|
|
|
|
2008-10-13 18:03:27 +00:00
|
|
|
free(entry, DRM_MEM_AGPLISTS);
|
2005-11-28 23:13:57 +00:00
|
|
|
|
2002-04-27 20:47:57 +00:00
|
|
|
return 0;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_agp_free_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2005-11-28 23:13:57 +00:00
|
|
|
{
|
2008-10-03 16:59:11 +00:00
|
|
|
struct drm_agp_buffer request;
|
2005-11-28 23:13:57 +00:00
|
|
|
int retcode;
|
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
request = *(struct drm_agp_buffer *) data;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
DRM_LOCK();
|
|
|
|
retcode = drm_agp_free(dev, &request);
|
|
|
|
DRM_UNLOCK();
|
|
|
|
|
|
|
|
return retcode;
|
2002-04-27 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
drm_agp_head_t *drm_agp_init(void)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
|
|
|
device_t agpdev;
|
|
|
|
drm_agp_head_t *head = NULL;
|
|
|
|
int agp_available = 1;
|
|
|
|
|
2003-03-09 02:08:30 +00:00
|
|
|
agpdev = DRM_AGP_FIND_DEVICE();
|
2002-04-27 20:47:57 +00:00
|
|
|
if (!agpdev)
|
|
|
|
agp_available = 0;
|
|
|
|
|
|
|
|
DRM_DEBUG("agp_available = %d\n", agp_available);
|
|
|
|
|
|
|
|
if (agp_available) {
|
2008-10-13 18:03:27 +00:00
|
|
|
head = malloc(sizeof(*head), DRM_MEM_AGPLISTS,
|
|
|
|
M_NOWAIT | M_ZERO);
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
if (head == NULL)
|
2002-04-27 20:47:57 +00:00
|
|
|
return NULL;
|
|
|
|
head->agpdev = agpdev;
|
|
|
|
agp_get_info(agpdev, &head->info);
|
2008-08-23 20:59:12 +00:00
|
|
|
head->base = head->info.ai_aperture_base;
|
2002-04-27 20:47:57 +00:00
|
|
|
head->memory = NULL;
|
2003-03-09 02:08:30 +00:00
|
|
|
DRM_INFO("AGP at 0x%08lx %dMB\n",
|
|
|
|
(long)head->info.ai_aperture_base,
|
|
|
|
(int)(head->info.ai_aperture_size >> 20));
|
2002-04-27 20:47:57 +00:00
|
|
|
}
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
void *drm_agp_allocate_memory(size_t pages, u32 type)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
|
|
|
device_t agpdev;
|
|
|
|
|
2003-03-09 02:08:30 +00:00
|
|
|
agpdev = DRM_AGP_FIND_DEVICE();
|
2002-04-27 20:47:57 +00:00
|
|
|
if (!agpdev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return agp_alloc_memory(agpdev, type, pages << AGP_PAGE_SHIFT);
|
|
|
|
}
|
|
|
|
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
int drm_agp_free_memory(void *handle)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
|
|
|
device_t agpdev;
|
|
|
|
|
2003-03-09 02:08:30 +00:00
|
|
|
agpdev = DRM_AGP_FIND_DEVICE();
|
2002-04-27 20:47:57 +00:00
|
|
|
if (!agpdev || !handle)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
agp_free_memory(agpdev, handle);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
int drm_agp_bind_memory(void *handle, off_t start)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
|
|
|
device_t agpdev;
|
|
|
|
|
2003-03-09 02:08:30 +00:00
|
|
|
agpdev = DRM_AGP_FIND_DEVICE();
|
2002-04-27 20:47:57 +00:00
|
|
|
if (!agpdev || !handle)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
return agp_bind_memory(agpdev, handle, start * PAGE_SIZE);
|
|
|
|
}
|
|
|
|
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
int drm_agp_unbind_memory(void *handle)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
|
|
|
device_t agpdev;
|
|
|
|
|
2003-03-09 02:08:30 +00:00
|
|
|
agpdev = DRM_AGP_FIND_DEVICE();
|
2002-04-27 20:47:57 +00:00
|
|
|
if (!agpdev || !handle)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
return agp_unbind_memory(agpdev, handle);
|
|
|
|
}
|