mirror of
https://gitlab.freedesktop.org/mesa/drm.git
synced 2025-12-28 20:20:14 +01:00
Initial revision
This commit is contained in:
parent
f18a6d836b
commit
16bd14926e
69 changed files with 39532 additions and 0 deletions
197
bsd-core/ati_pcigart.c
Normal file
197
bsd-core/ati_pcigart.c
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
/* ati_pcigart.h -- ATI PCI GART support -*- linux-c -*-
|
||||
* Created: Wed Dec 13 21:52:19 2000 by gareth@valinux.com
|
||||
*
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
#if PAGE_SIZE == 8192
|
||||
# define ATI_PCIGART_TABLE_ORDER 2
|
||||
# define ATI_PCIGART_TABLE_PAGES (1 << 2)
|
||||
#elif PAGE_SIZE == 4096
|
||||
# define ATI_PCIGART_TABLE_ORDER 3
|
||||
# define ATI_PCIGART_TABLE_PAGES (1 << 3)
|
||||
#elif
|
||||
# error - PAGE_SIZE not 8K or 4K
|
||||
#endif
|
||||
|
||||
# define ATI_MAX_PCIGART_PAGES 8192 /* 32 MB aperture, 4K pages */
|
||||
# define ATI_PCIGART_PAGE_SIZE 4096 /* PCI GART page size */
|
||||
|
||||
static unsigned long DRM(ati_alloc_pcigart_table)( void )
|
||||
{
|
||||
unsigned long address;
|
||||
struct page *page;
|
||||
int i;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
address = __get_free_pages( GFP_KERNEL, ATI_PCIGART_TABLE_ORDER );
|
||||
if ( address == 0UL ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
page = virt_to_page( address );
|
||||
|
||||
for ( i = 0 ; i <= ATI_PCIGART_TABLE_PAGES ; i++, page++ ) {
|
||||
atomic_inc( &page->count );
|
||||
SetPageReserved( page );
|
||||
}
|
||||
|
||||
DRM_DEBUG( "%s: returning 0x%08lx\n", __FUNCTION__, address );
|
||||
return address;
|
||||
}
|
||||
|
||||
static void DRM(ati_free_pcigart_table)( unsigned long address )
|
||||
{
|
||||
struct page *page;
|
||||
int i;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
page = virt_to_page( address );
|
||||
|
||||
for ( i = 0 ; i <= ATI_PCIGART_TABLE_PAGES ; i++, page++ ) {
|
||||
atomic_dec( &page->count );
|
||||
ClearPageReserved( page );
|
||||
}
|
||||
|
||||
free_pages( address, ATI_PCIGART_TABLE_ORDER );
|
||||
}
|
||||
|
||||
int DRM(ati_pcigart_init)( drm_device_t *dev,
|
||||
unsigned long *addr,
|
||||
dma_addr_t *bus_addr)
|
||||
{
|
||||
drm_sg_mem_t *entry = dev->sg;
|
||||
unsigned long address = 0;
|
||||
unsigned long pages;
|
||||
u32 *pci_gart, page_base, bus_address = 0;
|
||||
int i, j, ret = 0;
|
||||
|
||||
if ( !entry ) {
|
||||
DRM_ERROR( "no scatter/gather memory!\n" );
|
||||
goto done;
|
||||
}
|
||||
|
||||
address = DRM(ati_alloc_pcigart_table)();
|
||||
if ( !address ) {
|
||||
DRM_ERROR( "cannot allocate PCI GART page!\n" );
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ( !dev->pdev ) {
|
||||
DRM_ERROR( "PCI device unknown!\n" );
|
||||
goto done;
|
||||
}
|
||||
|
||||
bus_address = pci_map_single(dev->pdev, (void *)address,
|
||||
ATI_PCIGART_TABLE_PAGES * PAGE_SIZE,
|
||||
PCI_DMA_TODEVICE);
|
||||
if (bus_address == 0) {
|
||||
DRM_ERROR( "unable to map PCIGART pages!\n" );
|
||||
DRM(ati_free_pcigart_table)( address );
|
||||
address = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
pci_gart = (u32 *)address;
|
||||
|
||||
pages = ( entry->pages <= ATI_MAX_PCIGART_PAGES )
|
||||
? entry->pages : ATI_MAX_PCIGART_PAGES;
|
||||
|
||||
memset( pci_gart, 0, ATI_MAX_PCIGART_PAGES * sizeof(u32) );
|
||||
|
||||
for ( i = 0 ; i < pages ; i++ ) {
|
||||
/* we need to support large memory configurations */
|
||||
entry->busaddr[i] = pci_map_single(dev->pdev,
|
||||
page_address( entry->pagelist[i] ),
|
||||
PAGE_SIZE,
|
||||
PCI_DMA_TODEVICE);
|
||||
if (entry->busaddr[i] == 0) {
|
||||
DRM_ERROR( "unable to map PCIGART pages!\n" );
|
||||
DRM(ati_pcigart_cleanup)( dev, address, bus_address );
|
||||
address = 0;
|
||||
bus_address = 0;
|
||||
goto done;
|
||||
}
|
||||
page_base = (u32) entry->busaddr[i];
|
||||
|
||||
for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
|
||||
*pci_gart++ = cpu_to_le32( page_base );
|
||||
page_base += ATI_PCIGART_PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
asm volatile ( "wbinvd" ::: "memory" );
|
||||
#else
|
||||
mb();
|
||||
#endif
|
||||
|
||||
done:
|
||||
*addr = address;
|
||||
*bus_addr = bus_address;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DRM(ati_pcigart_cleanup)( drm_device_t *dev,
|
||||
unsigned long addr,
|
||||
dma_addr_t bus_addr)
|
||||
{
|
||||
drm_sg_mem_t *entry = dev->sg;
|
||||
unsigned long pages;
|
||||
int i;
|
||||
|
||||
/* we need to support large memory configurations */
|
||||
if ( !entry ) {
|
||||
DRM_ERROR( "no scatter/gather memory!\n" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( bus_addr ) {
|
||||
pci_unmap_single(dev->pdev, bus_addr,
|
||||
ATI_PCIGART_TABLE_PAGES * PAGE_SIZE,
|
||||
PCI_DMA_TODEVICE);
|
||||
|
||||
pages = ( entry->pages <= ATI_MAX_PCIGART_PAGES )
|
||||
? entry->pages : ATI_MAX_PCIGART_PAGES;
|
||||
|
||||
for ( i = 0 ; i < pages ; i++ ) {
|
||||
if ( !entry->busaddr[i] ) break;
|
||||
pci_unmap_single(dev->pdev, entry->busaddr[i],
|
||||
PAGE_SIZE, PCI_DMA_TODEVICE);
|
||||
}
|
||||
}
|
||||
|
||||
if ( addr ) {
|
||||
DRM(ati_free_pcigart_table)( addr );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
166
bsd-core/drm_auth.c
Normal file
166
bsd-core/drm_auth.c
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
/* drm_auth.h -- IOCTLs for authentication -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
static int DRM(hash_magic)(drm_magic_t magic)
|
||||
{
|
||||
return magic & (DRM_HASH_SIZE-1);
|
||||
}
|
||||
|
||||
static drm_file_t *DRM(find_file)(drm_device_t *dev, drm_magic_t magic)
|
||||
{
|
||||
drm_file_t *retval = NULL;
|
||||
drm_magic_entry_t *pt;
|
||||
int hash = DRM(hash_magic)(magic);
|
||||
|
||||
DRM_OS_LOCK;
|
||||
for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
|
||||
if (pt->magic == magic) {
|
||||
retval = pt->priv;
|
||||
break;
|
||||
}
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
return retval;
|
||||
}
|
||||
|
||||
int DRM(add_magic)(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
|
||||
{
|
||||
int hash;
|
||||
drm_magic_entry_t *entry;
|
||||
|
||||
DRM_DEBUG("%d\n", magic);
|
||||
|
||||
hash = DRM(hash_magic)(magic);
|
||||
entry = (drm_magic_entry_t*) DRM(alloc)(sizeof(*entry), DRM_MEM_MAGIC);
|
||||
if (!entry) DRM_OS_RETURN(ENOMEM);
|
||||
entry->magic = magic;
|
||||
entry->priv = priv;
|
||||
entry->next = NULL;
|
||||
|
||||
DRM_OS_LOCK;
|
||||
if (dev->magiclist[hash].tail) {
|
||||
dev->magiclist[hash].tail->next = entry;
|
||||
dev->magiclist[hash].tail = entry;
|
||||
} else {
|
||||
dev->magiclist[hash].head = entry;
|
||||
dev->magiclist[hash].tail = entry;
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic)
|
||||
{
|
||||
drm_magic_entry_t *prev = NULL;
|
||||
drm_magic_entry_t *pt;
|
||||
int hash;
|
||||
|
||||
DRM_DEBUG("%d\n", magic);
|
||||
hash = DRM(hash_magic)(magic);
|
||||
|
||||
DRM_OS_LOCK;
|
||||
for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) {
|
||||
if (pt->magic == magic) {
|
||||
if (dev->magiclist[hash].head == pt) {
|
||||
dev->magiclist[hash].head = pt->next;
|
||||
}
|
||||
if (dev->magiclist[hash].tail == pt) {
|
||||
dev->magiclist[hash].tail = prev;
|
||||
}
|
||||
if (prev) {
|
||||
prev->next = pt->next;
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
DRM(free)(pt, sizeof(*pt), DRM_MEM_MAGIC);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
DRM(free)(pt, sizeof(*pt), DRM_MEM_MAGIC);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
int DRM(getmagic)(DRM_OS_IOCTL)
|
||||
{
|
||||
static drm_magic_t sequence = 0;
|
||||
drm_auth_t auth;
|
||||
static DRM_OS_SPINTYPE lock;
|
||||
static int first = 1;
|
||||
DRM_OS_DEVICE;
|
||||
DRM_OS_PRIV;
|
||||
|
||||
if (first) {
|
||||
DRM_OS_SPININIT(lock, "drm getmagic");
|
||||
first = 0;
|
||||
}
|
||||
|
||||
/* Find unique magic */
|
||||
if (priv->magic) {
|
||||
auth.magic = priv->magic;
|
||||
} else {
|
||||
do {
|
||||
DRM_OS_SPINLOCK(&lock);
|
||||
if (!sequence) ++sequence; /* reserve 0 */
|
||||
auth.magic = sequence++;
|
||||
DRM_OS_SPINUNLOCK(&lock);
|
||||
} while (DRM(find_file)(dev, auth.magic));
|
||||
priv->magic = auth.magic;
|
||||
DRM(add_magic)(dev, priv, auth.magic);
|
||||
}
|
||||
|
||||
DRM_DEBUG("%u\n", auth.magic);
|
||||
|
||||
DRM_OS_KRNTOUSR((drm_auth_t *)data, auth, sizeof(auth));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(authmagic)(DRM_OS_IOCTL)
|
||||
{
|
||||
drm_auth_t auth;
|
||||
drm_file_t *file;
|
||||
DRM_OS_DEVICE;
|
||||
|
||||
DRM_OS_KRNFROMUSR(auth, (drm_auth_t *)data, sizeof(auth));
|
||||
|
||||
DRM_DEBUG("%u\n", auth.magic);
|
||||
if ((file = DRM(find_file)(dev, auth.magic))) {
|
||||
file->authenticated = 1;
|
||||
DRM(remove_magic)(dev, auth.magic);
|
||||
return 0;
|
||||
}
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
1092
bsd-core/drm_bufs.c
Normal file
1092
bsd-core/drm_bufs.c
Normal file
File diff suppressed because it is too large
Load diff
730
bsd-core/drm_context.c
Normal file
730
bsd-core/drm_context.c
Normal file
|
|
@ -0,0 +1,730 @@
|
|||
/* drm_context.h -- IOCTLs for generic contexts -*- linux-c -*-
|
||||
* Created: Fri Nov 24 18:31:37 2000 by gareth@valinux.com
|
||||
*
|
||||
* Copyright 1999, 2000 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
#if __HAVE_CTX_BITMAP
|
||||
|
||||
/* ================================================================
|
||||
* Context bitmap support
|
||||
*/
|
||||
|
||||
void DRM(ctxbitmap_free)( drm_device_t *dev, int ctx_handle )
|
||||
{
|
||||
if ( ctx_handle < 0 ) goto failed;
|
||||
if ( !dev->ctx_bitmap ) goto failed;
|
||||
|
||||
if ( ctx_handle < DRM_MAX_CTXBITMAP ) {
|
||||
DRM_OS_LOCK;
|
||||
clear_bit( ctx_handle, dev->ctx_bitmap );
|
||||
dev->context_sareas[ctx_handle] = NULL;
|
||||
DRM_OS_UNLOCK;
|
||||
return;
|
||||
}
|
||||
failed:
|
||||
DRM_ERROR( "Attempt to free invalid context handle: %d\n",
|
||||
ctx_handle );
|
||||
return;
|
||||
}
|
||||
|
||||
int DRM(ctxbitmap_next)( drm_device_t *dev )
|
||||
{
|
||||
int bit;
|
||||
|
||||
if(!dev->ctx_bitmap) return -1;
|
||||
|
||||
DRM_OS_LOCK;
|
||||
bit = find_first_zero_bit( dev->ctx_bitmap, DRM_MAX_CTXBITMAP );
|
||||
if ( bit < DRM_MAX_CTXBITMAP ) {
|
||||
set_bit( bit, dev->ctx_bitmap );
|
||||
DRM_DEBUG( "drm_ctxbitmap_next bit : %d\n", bit );
|
||||
if((bit+1) > dev->max_context) {
|
||||
dev->max_context = (bit+1);
|
||||
if(dev->context_sareas) {
|
||||
drm_map_t **ctx_sareas;
|
||||
|
||||
ctx_sareas = DRM(realloc)(dev->context_sareas,
|
||||
(dev->max_context - 1) *
|
||||
sizeof(*dev->context_sareas),
|
||||
dev->max_context *
|
||||
sizeof(*dev->context_sareas),
|
||||
DRM_MEM_MAPS);
|
||||
if(!ctx_sareas) {
|
||||
clear_bit(bit, dev->ctx_bitmap);
|
||||
DRM_OS_UNLOCK;
|
||||
return -1;
|
||||
}
|
||||
dev->context_sareas = ctx_sareas;
|
||||
dev->context_sareas[bit] = NULL;
|
||||
} else {
|
||||
/* max_context == 1 at this point */
|
||||
dev->context_sareas = DRM(alloc)(
|
||||
dev->max_context *
|
||||
sizeof(*dev->context_sareas),
|
||||
DRM_MEM_MAPS);
|
||||
if(!dev->context_sareas) {
|
||||
clear_bit(bit, dev->ctx_bitmap);
|
||||
DRM_OS_UNLOCK;
|
||||
return -1;
|
||||
}
|
||||
dev->context_sareas[bit] = NULL;
|
||||
}
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
return bit;
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int DRM(ctxbitmap_init)( drm_device_t *dev )
|
||||
{
|
||||
int i;
|
||||
int temp;
|
||||
|
||||
DRM_OS_LOCK;
|
||||
dev->ctx_bitmap = (unsigned long *) DRM(alloc)( PAGE_SIZE,
|
||||
DRM_MEM_CTXBITMAP );
|
||||
if ( dev->ctx_bitmap == NULL ) {
|
||||
DRM_OS_UNLOCK;
|
||||
DRM_OS_RETURN(ENOMEM);
|
||||
}
|
||||
memset( (void *)dev->ctx_bitmap, 0, PAGE_SIZE );
|
||||
dev->context_sareas = NULL;
|
||||
dev->max_context = -1;
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
|
||||
temp = DRM(ctxbitmap_next)( dev );
|
||||
DRM_DEBUG( "drm_ctxbitmap_init : %d\n", temp );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DRM(ctxbitmap_cleanup)( drm_device_t *dev )
|
||||
{
|
||||
DRM_OS_LOCK;
|
||||
if( dev->context_sareas ) DRM(free)( dev->context_sareas,
|
||||
sizeof(*dev->context_sareas) *
|
||||
dev->max_context,
|
||||
DRM_MEM_MAPS );
|
||||
DRM(free)( (void *)dev->ctx_bitmap, PAGE_SIZE, DRM_MEM_CTXBITMAP );
|
||||
DRM_OS_UNLOCK;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
* Per Context SAREA Support
|
||||
*/
|
||||
|
||||
int DRM(getsareactx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_priv_map_t request;
|
||||
drm_map_t *map;
|
||||
|
||||
DRM_OS_KRNFROMUSR( request, (drm_ctx_priv_map_t *)data,
|
||||
sizeof(request) );
|
||||
|
||||
DRM_OS_LOCK;
|
||||
if (dev->max_context < 0 || request.ctx_id >= (unsigned) dev->max_context) {
|
||||
DRM_OS_UNLOCK;
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
map = dev->context_sareas[request.ctx_id];
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
request.handle = map->handle;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_priv_map_t *)data, request, sizeof(request) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(setsareactx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_priv_map_t request;
|
||||
drm_map_t *map = NULL;
|
||||
drm_map_list_entry_t *list;
|
||||
|
||||
DRM_OS_KRNFROMUSR( request, (drm_ctx_priv_map_t *)data,
|
||||
sizeof(request) );
|
||||
|
||||
DRM_OS_LOCK;
|
||||
TAILQ_FOREACH(list, dev->maplist, link) {
|
||||
map=list->map;
|
||||
if(map->handle == request.handle)
|
||||
goto found;
|
||||
}
|
||||
|
||||
bad:
|
||||
DRM_OS_UNLOCK;
|
||||
return -EINVAL;
|
||||
|
||||
found:
|
||||
map = list->map;
|
||||
if (!map) goto bad;
|
||||
if (dev->max_context < 0)
|
||||
goto bad;
|
||||
if (request.ctx_id >= (unsigned) dev->max_context)
|
||||
goto bad;
|
||||
dev->context_sareas[request.ctx_id] = map;
|
||||
DRM_OS_UNLOCK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
* The actual DRM context handling routines
|
||||
*/
|
||||
|
||||
int DRM(context_switch)( drm_device_t *dev, int old, int new )
|
||||
{
|
||||
char buf[64];
|
||||
|
||||
if ( test_and_set_bit( 0, &dev->context_flag ) ) {
|
||||
DRM_ERROR( "Reentering -- FIXME\n" );
|
||||
DRM_OS_RETURN(EBUSY);
|
||||
}
|
||||
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
dev->ctx_start = get_cycles();
|
||||
#endif
|
||||
|
||||
DRM_DEBUG( "Context switch from %d to %d\n", old, new );
|
||||
|
||||
if ( new == dev->last_context ) {
|
||||
clear_bit( 0, &dev->context_flag );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( DRM(flags) & DRM_FLAG_NOCTX ) {
|
||||
DRM(context_switch_complete)( dev, new );
|
||||
} else {
|
||||
sprintf( buf, "C %d %d\n", old, new );
|
||||
DRM(write_string)( dev, buf );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(context_switch_complete)( drm_device_t *dev, int new )
|
||||
{
|
||||
dev->last_context = new; /* PRE/POST: This is the _only_ writer. */
|
||||
dev->last_switch = jiffies;
|
||||
|
||||
if ( !_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) ) {
|
||||
DRM_ERROR( "Lock isn't held after context switch\n" );
|
||||
}
|
||||
|
||||
/* If a context switch is ever initiated
|
||||
when the kernel holds the lock, release
|
||||
that lock here. */
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
atomic_inc( &dev->histo.ctx[DRM(histogram_slot)(get_cycles()
|
||||
- dev->ctx_start)] );
|
||||
|
||||
#endif
|
||||
clear_bit( 0, &dev->context_flag );
|
||||
DRM_OS_WAKEUP( &dev->context_wait );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(resctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_ctx_res_t res;
|
||||
drm_ctx_t ctx;
|
||||
int i;
|
||||
|
||||
DRM_OS_KRNFROMUSR( res, (drm_ctx_res_t *)data, sizeof(res) );
|
||||
|
||||
if ( res.count >= DRM_RESERVED_CONTEXTS ) {
|
||||
memset( &ctx, 0, sizeof(ctx) );
|
||||
for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
|
||||
ctx.handle = i;
|
||||
if ( DRM_OS_COPYTOUSR( &res.contexts[i],
|
||||
&i, sizeof(i) ) )
|
||||
DRM_OS_RETURN(EFAULT);
|
||||
}
|
||||
}
|
||||
res.count = DRM_RESERVED_CONTEXTS;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_res_t *)data, res, sizeof(res) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(addctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
ctx.handle = DRM(ctxbitmap_next)( dev );
|
||||
if ( ctx.handle == DRM_KERNEL_CONTEXT ) {
|
||||
/* Skip kernel's context and get a new one. */
|
||||
ctx.handle = DRM(ctxbitmap_next)( dev );
|
||||
}
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
if ( ctx.handle == -1 ) {
|
||||
DRM_DEBUG( "Not enough free contexts.\n" );
|
||||
/* Should this return -EBUSY instead? */
|
||||
DRM_OS_RETURN(ENOMEM);
|
||||
}
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_t *)data, ctx, sizeof(ctx) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(modctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
/* This does nothing */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(getctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
/* This is 0, because we don't handle any context flags */
|
||||
ctx.flags = 0;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_t *)data, ctx, sizeof(ctx) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(switchctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
return DRM(context_switch)( dev, dev->last_context, ctx.handle );
|
||||
}
|
||||
|
||||
int DRM(newctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
DRM(context_switch_complete)( dev, ctx.handle );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(rmctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
if ( ctx.handle != DRM_KERNEL_CONTEXT ) {
|
||||
DRM(ctxbitmap_free)( dev, ctx.handle );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#else /* __HAVE_CTX_BITMAP */
|
||||
|
||||
/* ================================================================
|
||||
* Old-style context support
|
||||
*/
|
||||
|
||||
|
||||
int DRM(context_switch)(drm_device_t *dev, int old, int new)
|
||||
{
|
||||
char buf[64];
|
||||
drm_queue_t *q;
|
||||
|
||||
#if 0
|
||||
atomic_inc(&dev->total_ctx);
|
||||
#endif
|
||||
|
||||
if (test_and_set_bit(0, &dev->context_flag)) {
|
||||
DRM_ERROR("Reentering -- FIXME\n");
|
||||
DRM_OS_RETURN(EBUSY);
|
||||
}
|
||||
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
dev->ctx_start = get_cycles();
|
||||
#endif
|
||||
|
||||
DRM_DEBUG("Context switch from %d to %d\n", old, new);
|
||||
|
||||
if (new >= dev->queue_count) {
|
||||
clear_bit(0, &dev->context_flag);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
if (new == dev->last_context) {
|
||||
clear_bit(0, &dev->context_flag);
|
||||
return 0;
|
||||
}
|
||||
|
||||
q = dev->queuelist[new];
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) == 1) {
|
||||
atomic_dec(&q->use_count);
|
||||
clear_bit(0, &dev->context_flag);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
if (DRM(flags) & DRM_FLAG_NOCTX) {
|
||||
DRM(context_switch_complete)(dev, new);
|
||||
} else {
|
||||
sprintf(buf, "C %d %d\n", old, new);
|
||||
DRM(write_string)(dev, buf);
|
||||
}
|
||||
|
||||
atomic_dec(&q->use_count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(context_switch_complete)(drm_device_t *dev, int new)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
dev->last_context = new; /* PRE/POST: This is the _only_ writer. */
|
||||
dev->last_switch = jiffies;
|
||||
|
||||
if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) {
|
||||
DRM_ERROR("Lock isn't held after context switch\n");
|
||||
}
|
||||
|
||||
if (!dma || !(dma->next_buffer && dma->next_buffer->while_locked)) {
|
||||
if (DRM(lock_free)(dev, &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT)) {
|
||||
DRM_ERROR("Cannot free lock\n");
|
||||
}
|
||||
}
|
||||
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
atomic_inc(&dev->histo.ctx[DRM(histogram_slot)(get_cycles()
|
||||
- dev->ctx_start)]);
|
||||
|
||||
#endif
|
||||
clear_bit(0, &dev->context_flag);
|
||||
DRM_OS_WAKEUP_INT(&dev->context_wait);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DRM(init_queue)(drm_device_t *dev, drm_queue_t *q, drm_ctx_t *ctx)
|
||||
{
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
if (atomic_read(&q->use_count) != 1
|
||||
|| atomic_read(&q->finalization)
|
||||
|| atomic_read(&q->block_count)) {
|
||||
DRM_ERROR("New queue is already in use: u%ld f%ld b%ld\n",
|
||||
(unsigned long)atomic_read(&q->use_count),
|
||||
(unsigned long)atomic_read(&q->finalization),
|
||||
(unsigned long)atomic_read(&q->block_count));
|
||||
}
|
||||
|
||||
atomic_set(&q->finalization, 0);
|
||||
atomic_set(&q->block_count, 0);
|
||||
atomic_set(&q->block_read, 0);
|
||||
atomic_set(&q->block_write, 0);
|
||||
atomic_set(&q->total_queued, 0);
|
||||
atomic_set(&q->total_flushed, 0);
|
||||
atomic_set(&q->total_locks, 0);
|
||||
|
||||
q->write_queue = 0;
|
||||
q->read_queue = 0;
|
||||
q->flush_queue = 0;
|
||||
|
||||
q->flags = ctx->flags;
|
||||
|
||||
DRM(waitlist_create)(&q->waitlist, dev->dma->buf_count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* drm_alloc_queue:
|
||||
PRE: 1) dev->queuelist[0..dev->queue_count] is allocated and will not
|
||||
disappear (so all deallocation must be done after IOCTLs are off)
|
||||
2) dev->queue_count < dev->queue_slots
|
||||
3) dev->queuelist[i].use_count == 0 and
|
||||
dev->queuelist[i].finalization == 0 if i not in use
|
||||
POST: 1) dev->queuelist[i].use_count == 1
|
||||
2) dev->queue_count < dev->queue_slots */
|
||||
|
||||
static int DRM(alloc_queue)(drm_device_t *dev)
|
||||
{
|
||||
int i;
|
||||
drm_queue_t *queue;
|
||||
int oldslots;
|
||||
int newslots;
|
||||
/* Check for a free queue */
|
||||
for (i = 0; i < dev->queue_count; i++) {
|
||||
atomic_inc(&dev->queuelist[i]->use_count);
|
||||
if (atomic_read(&dev->queuelist[i]->use_count) == 1
|
||||
&& !atomic_read(&dev->queuelist[i]->finalization)) {
|
||||
DRM_DEBUG("%d (free)\n", i);
|
||||
return i;
|
||||
}
|
||||
atomic_dec(&dev->queuelist[i]->use_count);
|
||||
}
|
||||
/* Allocate a new queue */
|
||||
DRM_OS_LOCK;
|
||||
|
||||
queue = gamma_alloc(sizeof(*queue), DRM_MEM_QUEUES);
|
||||
memset(queue, 0, sizeof(*queue));
|
||||
atomic_set(&queue->use_count, 1);
|
||||
|
||||
++dev->queue_count;
|
||||
if (dev->queue_count >= dev->queue_slots) {
|
||||
oldslots = dev->queue_slots * sizeof(*dev->queuelist);
|
||||
if (!dev->queue_slots) dev->queue_slots = 1;
|
||||
dev->queue_slots *= 2;
|
||||
newslots = dev->queue_slots * sizeof(*dev->queuelist);
|
||||
|
||||
dev->queuelist = DRM(realloc)(dev->queuelist,
|
||||
oldslots,
|
||||
newslots,
|
||||
DRM_MEM_QUEUES);
|
||||
if (!dev->queuelist) {
|
||||
DRM_OS_UNLOCK;
|
||||
DRM_DEBUG("out of memory\n");
|
||||
DRM_OS_RETURN(ENOMEM);
|
||||
}
|
||||
}
|
||||
dev->queuelist[dev->queue_count-1] = queue;
|
||||
|
||||
DRM_OS_UNLOCK;
|
||||
DRM_DEBUG("%d (new)\n", dev->queue_count - 1);
|
||||
return dev->queue_count - 1;
|
||||
}
|
||||
|
||||
int DRM(resctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_ctx_res_t res;
|
||||
drm_ctx_t ctx;
|
||||
int i;
|
||||
|
||||
DRM_DEBUG("%d\n", DRM_RESERVED_CONTEXTS);
|
||||
|
||||
DRM_OS_KRNFROMUSR( res, (drm_ctx_res_t *)data, sizeof(res) );
|
||||
|
||||
if (res.count >= DRM_RESERVED_CONTEXTS) {
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
|
||||
ctx.handle = i;
|
||||
if (DRM_OS_COPYTOUSR(&res.contexts[i],
|
||||
&i,
|
||||
sizeof(i)))
|
||||
DRM_OS_RETURN(EFAULT);
|
||||
}
|
||||
}
|
||||
res.count = DRM_RESERVED_CONTEXTS;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_res_t *)data, res, sizeof(res) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(addctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
if ((ctx.handle = DRM(alloc_queue)(dev)) == DRM_KERNEL_CONTEXT) {
|
||||
/* Init kernel's context and get a new one. */
|
||||
DRM(init_queue)(dev, dev->queuelist[ctx.handle], &ctx);
|
||||
ctx.handle = DRM(alloc_queue)(dev);
|
||||
}
|
||||
DRM(init_queue)(dev, dev->queuelist[ctx.handle], &ctx);
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_t *)data, ctx, sizeof(ctx) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(modctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
drm_queue_t *q;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
|
||||
if (ctx.handle < 0 || ctx.handle >= dev->queue_count)
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
q = dev->queuelist[ctx.handle];
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) == 1) {
|
||||
/* No longer in use */
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
if (DRM_BUFCOUNT(&q->waitlist)) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_OS_RETURN(EBUSY);
|
||||
}
|
||||
|
||||
q->flags = ctx.flags;
|
||||
|
||||
atomic_dec(&q->use_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(getctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
drm_queue_t *q;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
|
||||
if (ctx.handle >= dev->queue_count)
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
q = dev->queuelist[ctx.handle];
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) == 1) {
|
||||
/* No longer in use */
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
ctx.flags = q->flags;
|
||||
atomic_dec(&q->use_count);
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_t *)data, ctx, sizeof(ctx) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(switchctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
return DRM(context_switch)(dev, dev->last_context, ctx.handle);
|
||||
}
|
||||
|
||||
int DRM(newctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
DRM(context_switch_complete)(dev, ctx.handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(rmctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
drm_queue_t *q;
|
||||
drm_buf_t *buf;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
|
||||
if (ctx.handle >= dev->queue_count) DRM_OS_RETURN(EINVAL);
|
||||
q = dev->queuelist[ctx.handle];
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) == 1) {
|
||||
/* No longer in use */
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
atomic_inc(&q->finalization); /* Mark queue in finalization state */
|
||||
atomic_sub(2, &q->use_count); /* Mark queue as unused (pending
|
||||
finalization) */
|
||||
|
||||
while (test_and_set_bit(0, &dev->interrupt_flag)) {
|
||||
static int never;
|
||||
int retcode;
|
||||
retcode = tsleep(&never, PZERO|PCATCH, "never", 1);
|
||||
if (retcode)
|
||||
return retcode;
|
||||
}
|
||||
/* Remove queued buffers */
|
||||
while ((buf = DRM(waitlist_get)(&q->waitlist))) {
|
||||
DRM(free_buffer)(dev, buf);
|
||||
}
|
||||
clear_bit(0, &dev->interrupt_flag);
|
||||
|
||||
/* Wakeup blocked processes */
|
||||
wakeup( &q->block_read );
|
||||
wakeup( &q->block_write );
|
||||
DRM_OS_WAKEUP_INT( &q->flush_queue );
|
||||
/* Finalization over. Queue is made
|
||||
available when both use_count and
|
||||
finalization become 0, which won't
|
||||
happen until all the waiting processes
|
||||
stop waiting. */
|
||||
atomic_dec(&q->finalization);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __HAVE_CTX_BITMAP */
|
||||
605
bsd-core/drm_dma.c
Normal file
605
bsd-core/drm_dma.c
Normal file
|
|
@ -0,0 +1,605 @@
|
|||
/* drm_dma.c -- DMA IOCTL and function support -*- linux-c -*-
|
||||
* Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999, 2000 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/rman.h>
|
||||
|
||||
#include "drmP.h"
|
||||
|
||||
#ifndef __HAVE_DMA_WAITQUEUE
|
||||
#define __HAVE_DMA_WAITQUEUE 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_RECLAIM
|
||||
#define __HAVE_DMA_RECLAIM 0
|
||||
#endif
|
||||
#ifndef __HAVE_SHARED_IRQ
|
||||
#define __HAVE_SHARED_IRQ 0
|
||||
#endif
|
||||
|
||||
#if __HAVE_SHARED_IRQ
|
||||
#define DRM_IRQ_TYPE SA_SHIRQ
|
||||
#else
|
||||
#define DRM_IRQ_TYPE 0
|
||||
#endif
|
||||
|
||||
#if __HAVE_DMA
|
||||
|
||||
int DRM(dma_setup)( drm_device_t *dev )
|
||||
{
|
||||
int i;
|
||||
|
||||
dev->dma = DRM(alloc)( sizeof(*dev->dma), DRM_MEM_DRIVER );
|
||||
if ( !dev->dma )
|
||||
DRM_OS_RETURN(ENOMEM);
|
||||
|
||||
memset( dev->dma, 0, sizeof(*dev->dma) );
|
||||
|
||||
for ( i = 0 ; i <= DRM_MAX_ORDER ; i++ )
|
||||
memset(&dev->dma->bufs[i], 0, sizeof(dev->dma->bufs[0]));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DRM(dma_takedown)(drm_device_t *dev)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int i, j;
|
||||
|
||||
if (!dma) return;
|
||||
|
||||
/* Clear dma buffers */
|
||||
for (i = 0; i <= DRM_MAX_ORDER; i++) {
|
||||
if (dma->bufs[i].seg_count) {
|
||||
DRM_DEBUG("order %d: buf_count = %d,"
|
||||
" seg_count = %d\n",
|
||||
i,
|
||||
dma->bufs[i].buf_count,
|
||||
dma->bufs[i].seg_count);
|
||||
for (j = 0; j < dma->bufs[i].seg_count; j++) {
|
||||
DRM(free_pages)(dma->bufs[i].seglist[j],
|
||||
dma->bufs[i].page_order,
|
||||
DRM_MEM_DMA);
|
||||
}
|
||||
DRM(free)(dma->bufs[i].seglist,
|
||||
dma->bufs[i].seg_count
|
||||
* sizeof(*dma->bufs[0].seglist),
|
||||
DRM_MEM_SEGS);
|
||||
}
|
||||
if(dma->bufs[i].buf_count) {
|
||||
for(j = 0; j < dma->bufs[i].buf_count; j++) {
|
||||
if(dma->bufs[i].buflist[j].dev_private) {
|
||||
DRM(free)(dma->bufs[i].buflist[j].dev_private,
|
||||
dma->bufs[i].buflist[j].dev_priv_size,
|
||||
DRM_MEM_BUFS);
|
||||
}
|
||||
}
|
||||
DRM(free)(dma->bufs[i].buflist,
|
||||
dma->bufs[i].buf_count *
|
||||
sizeof(*dma->bufs[0].buflist),
|
||||
DRM_MEM_BUFS);
|
||||
#if __HAVE_DMA_FREELIST
|
||||
DRM(freelist_destroy)(&dma->bufs[i].freelist);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (dma->buflist) {
|
||||
DRM(free)(dma->buflist,
|
||||
dma->buf_count * sizeof(*dma->buflist),
|
||||
DRM_MEM_BUFS);
|
||||
}
|
||||
|
||||
if (dma->pagelist) {
|
||||
DRM(free)(dma->pagelist,
|
||||
dma->page_count * sizeof(*dma->pagelist),
|
||||
DRM_MEM_PAGES);
|
||||
}
|
||||
DRM(free)(dev->dma, sizeof(*dev->dma), DRM_MEM_DRIVER);
|
||||
dev->dma = NULL;
|
||||
}
|
||||
|
||||
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
/* This is slow, but is useful for debugging. */
|
||||
int DRM(histogram_slot)(unsigned long count)
|
||||
{
|
||||
int value = DRM_DMA_HISTOGRAM_INITIAL;
|
||||
int slot;
|
||||
|
||||
for (slot = 0;
|
||||
slot < DRM_DMA_HISTOGRAM_SLOTS;
|
||||
++slot, value = DRM_DMA_HISTOGRAM_NEXT(value)) {
|
||||
if (count < value) return slot;
|
||||
}
|
||||
return DRM_DMA_HISTOGRAM_SLOTS - 1;
|
||||
}
|
||||
|
||||
void DRM(histogram_compute)(drm_device_t *dev, drm_buf_t *buf)
|
||||
{
|
||||
cycles_t queued_to_dispatched;
|
||||
cycles_t dispatched_to_completed;
|
||||
cycles_t completed_to_freed;
|
||||
int q2d, d2c, c2f, q2c, q2f;
|
||||
|
||||
if (buf->time_queued) {
|
||||
queued_to_dispatched = (buf->time_dispatched
|
||||
- buf->time_queued);
|
||||
dispatched_to_completed = (buf->time_completed
|
||||
- buf->time_dispatched);
|
||||
completed_to_freed = (buf->time_freed
|
||||
- buf->time_completed);
|
||||
|
||||
q2d = DRM(histogram_slot)(queued_to_dispatched);
|
||||
d2c = DRM(histogram_slot)(dispatched_to_completed);
|
||||
c2f = DRM(histogram_slot)(completed_to_freed);
|
||||
|
||||
q2c = DRM(histogram_slot)(queued_to_dispatched
|
||||
+ dispatched_to_completed);
|
||||
q2f = DRM(histogram_slot)(queued_to_dispatched
|
||||
+ dispatched_to_completed
|
||||
+ completed_to_freed);
|
||||
|
||||
atomic_inc(&dev->histo.total);
|
||||
atomic_inc(&dev->histo.queued_to_dispatched[q2d]);
|
||||
atomic_inc(&dev->histo.dispatched_to_completed[d2c]);
|
||||
atomic_inc(&dev->histo.completed_to_freed[c2f]);
|
||||
|
||||
atomic_inc(&dev->histo.queued_to_completed[q2c]);
|
||||
atomic_inc(&dev->histo.queued_to_freed[q2f]);
|
||||
|
||||
}
|
||||
buf->time_queued = 0;
|
||||
buf->time_dispatched = 0;
|
||||
buf->time_completed = 0;
|
||||
buf->time_freed = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf)
|
||||
{
|
||||
if (!buf) return;
|
||||
|
||||
buf->waiting = 0;
|
||||
buf->pending = 0;
|
||||
buf->pid = 0;
|
||||
buf->used = 0;
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
buf->time_completed = get_cycles();
|
||||
#endif
|
||||
|
||||
if ( buf->dma_wait ) {
|
||||
wakeup( &buf->dma_wait );
|
||||
buf->dma_wait = 0;
|
||||
}
|
||||
#if __HAVE_DMA_FREELIST
|
||||
else {
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
/* If processes are waiting, the last one
|
||||
to wake will put the buffer on the free
|
||||
list. If no processes are waiting, we
|
||||
put the buffer on the freelist here. */
|
||||
DRM(freelist_put)(dev, &dma->bufs[buf->order].freelist, buf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !__HAVE_DMA_RECLAIM
|
||||
void DRM(reclaim_buffers)(drm_device_t *dev, pid_t pid)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int i;
|
||||
|
||||
if (!dma) return;
|
||||
for (i = 0; i < dma->buf_count; i++) {
|
||||
if (dma->buflist[i]->pid == pid) {
|
||||
switch (dma->buflist[i]->list) {
|
||||
case DRM_LIST_NONE:
|
||||
DRM(free_buffer)(dev, dma->buflist[i]);
|
||||
break;
|
||||
case DRM_LIST_WAIT:
|
||||
dma->buflist[i]->list = DRM_LIST_RECLAIM;
|
||||
break;
|
||||
default:
|
||||
/* Buffer already on hardware. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* GH: This is a big hack for now...
|
||||
*/
|
||||
#if __HAVE_OLD_DMA
|
||||
|
||||
void DRM(clear_next_buffer)(drm_device_t *dev)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
dma->next_buffer = NULL;
|
||||
if (dma->next_queue && !DRM_BUFCOUNT(&dma->next_queue->waitlist)) {
|
||||
DRM_OS_WAKEUP_INT(&dma->next_queue->flush_queue);
|
||||
}
|
||||
dma->next_queue = NULL;
|
||||
}
|
||||
|
||||
int DRM(select_queue)(drm_device_t *dev, void (*wrapper)(unsigned long))
|
||||
{
|
||||
int i;
|
||||
int candidate = -1;
|
||||
int j = jiffies;
|
||||
|
||||
if (!dev) {
|
||||
DRM_ERROR("No device\n");
|
||||
return -1;
|
||||
}
|
||||
if (!dev->queuelist || !dev->queuelist[DRM_KERNEL_CONTEXT]) {
|
||||
/* This only happens between the time the
|
||||
interrupt is initialized and the time
|
||||
the queues are initialized. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Doing "while locked" DMA? */
|
||||
if (DRM_WAITCOUNT(dev, DRM_KERNEL_CONTEXT)) {
|
||||
return DRM_KERNEL_CONTEXT;
|
||||
}
|
||||
|
||||
/* If there are buffers on the last_context
|
||||
queue, and we have not been executing
|
||||
this context very long, continue to
|
||||
execute this context. */
|
||||
if (dev->last_switch <= j
|
||||
&& dev->last_switch + DRM_TIME_SLICE > j
|
||||
&& DRM_WAITCOUNT(dev, dev->last_context)) {
|
||||
return dev->last_context;
|
||||
}
|
||||
|
||||
/* Otherwise, find a candidate */
|
||||
for (i = dev->last_checked + 1; i < dev->queue_count; i++) {
|
||||
if (DRM_WAITCOUNT(dev, i)) {
|
||||
candidate = dev->last_checked = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (candidate < 0) {
|
||||
for (i = 0; i < dev->queue_count; i++) {
|
||||
if (DRM_WAITCOUNT(dev, i)) {
|
||||
candidate = dev->last_checked = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wrapper
|
||||
&& candidate >= 0
|
||||
&& candidate != dev->last_context
|
||||
&& dev->last_switch <= j
|
||||
&& dev->last_switch + DRM_TIME_SLICE > j) {
|
||||
int s = splclock();
|
||||
if (dev->timer.c_time != dev->last_switch + DRM_TIME_SLICE) {
|
||||
callout_reset(&dev->timer,
|
||||
dev->last_switch + DRM_TIME_SLICE - j,
|
||||
(void (*)(void *))wrapper,
|
||||
dev);
|
||||
}
|
||||
splx(s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return candidate;
|
||||
}
|
||||
|
||||
|
||||
int DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *d)
|
||||
{
|
||||
int i;
|
||||
drm_queue_t *q;
|
||||
drm_buf_t *buf;
|
||||
int idx;
|
||||
int while_locked = 0;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int error;
|
||||
|
||||
DRM_DEBUG("%d\n", d->send_count);
|
||||
|
||||
if (d->flags & _DRM_DMA_WHILE_LOCKED) {
|
||||
int context = dev->lock.hw_lock->lock;
|
||||
|
||||
if (!_DRM_LOCK_IS_HELD(context)) {
|
||||
DRM_ERROR("No lock held during \"while locked\""
|
||||
" request\n");
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
if (d->context != _DRM_LOCKING_CONTEXT(context)
|
||||
&& _DRM_LOCKING_CONTEXT(context) != DRM_KERNEL_CONTEXT) {
|
||||
DRM_ERROR("Lock held by %d while %d makes"
|
||||
" \"while locked\" request\n",
|
||||
_DRM_LOCKING_CONTEXT(context),
|
||||
d->context);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
q = dev->queuelist[DRM_KERNEL_CONTEXT];
|
||||
while_locked = 1;
|
||||
} else {
|
||||
q = dev->queuelist[d->context];
|
||||
}
|
||||
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->block_write)) {
|
||||
atomic_inc(&q->block_count);
|
||||
for (;;) {
|
||||
if (!atomic_read(&q->block_write)) break;
|
||||
error = tsleep(&q->block_write, PZERO|PCATCH,
|
||||
"dmawr", 0);
|
||||
if (error) {
|
||||
atomic_dec(&q->use_count);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
atomic_dec(&q->block_count);
|
||||
}
|
||||
|
||||
for (i = 0; i < d->send_count; i++) {
|
||||
idx = d->send_indices[i];
|
||||
if (idx < 0 || idx >= dma->buf_count) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Index %d (of %d max)\n",
|
||||
d->send_indices[i], dma->buf_count - 1);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
buf = dma->buflist[ idx ];
|
||||
if (buf->pid != DRM_OS_CURRENTPID) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Process %d using buffer owned by %d\n",
|
||||
DRM_OS_CURRENTPID, buf->pid);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
if (buf->list != DRM_LIST_NONE) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Process %d using buffer %d on list %d\n",
|
||||
DRM_OS_CURRENTPID, buf->idx, buf->list);
|
||||
}
|
||||
buf->used = d->send_sizes[i];
|
||||
buf->while_locked = while_locked;
|
||||
buf->context = d->context;
|
||||
if (!buf->used) {
|
||||
DRM_ERROR("Queueing 0 length buffer\n");
|
||||
}
|
||||
if (buf->pending) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Queueing pending buffer:"
|
||||
" buffer %d, offset %d\n",
|
||||
d->send_indices[i], i);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
if (buf->waiting) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Queueing waiting buffer:"
|
||||
" buffer %d, offset %d\n",
|
||||
d->send_indices[i], i);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
buf->waiting = 1;
|
||||
if (atomic_read(&q->use_count) == 1
|
||||
|| atomic_read(&q->finalization)) {
|
||||
DRM(free_buffer)(dev, buf);
|
||||
} else {
|
||||
DRM(waitlist_put)(&q->waitlist, buf);
|
||||
atomic_inc(&q->total_queued);
|
||||
}
|
||||
}
|
||||
atomic_dec(&q->use_count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DRM(dma_get_buffers_of_order)(drm_device_t *dev, drm_dma_t *d,
|
||||
int order)
|
||||
{
|
||||
int i;
|
||||
drm_buf_t *buf;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
for (i = d->granted_count; i < d->request_count; i++) {
|
||||
buf = DRM(freelist_get)(&dma->bufs[order].freelist,
|
||||
d->flags & _DRM_DMA_WAIT);
|
||||
if (!buf) break;
|
||||
if (buf->pending || buf->waiting) {
|
||||
DRM_ERROR("Free buffer %d in use by %d (w%d, p%d)\n",
|
||||
buf->idx,
|
||||
buf->pid,
|
||||
buf->waiting,
|
||||
buf->pending);
|
||||
}
|
||||
buf->pid = DRM_OS_CURRENTPID;
|
||||
if (DRM_OS_COPYTOUSR(&d->request_indices[i],
|
||||
&buf->idx,
|
||||
sizeof(buf->idx)))
|
||||
DRM_OS_RETURN(EFAULT);
|
||||
|
||||
if (DRM_OS_COPYTOUSR(&d->request_sizes[i],
|
||||
&buf->total,
|
||||
sizeof(buf->total)))
|
||||
DRM_OS_RETURN(EFAULT);
|
||||
|
||||
++d->granted_count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int DRM(dma_get_buffers)(drm_device_t *dev, drm_dma_t *dma)
|
||||
{
|
||||
int order;
|
||||
int retcode = 0;
|
||||
int tmp_order;
|
||||
|
||||
order = DRM(order)(dma->request_size);
|
||||
|
||||
dma->granted_count = 0;
|
||||
retcode = DRM(dma_get_buffers_of_order)(dev, dma, order);
|
||||
|
||||
if (dma->granted_count < dma->request_count
|
||||
&& (dma->flags & _DRM_DMA_SMALLER_OK)) {
|
||||
for (tmp_order = order - 1;
|
||||
!retcode
|
||||
&& dma->granted_count < dma->request_count
|
||||
&& tmp_order >= DRM_MIN_ORDER;
|
||||
--tmp_order) {
|
||||
|
||||
retcode = DRM(dma_get_buffers_of_order)(dev, dma,
|
||||
tmp_order);
|
||||
}
|
||||
}
|
||||
|
||||
if (dma->granted_count < dma->request_count
|
||||
&& (dma->flags & _DRM_DMA_LARGER_OK)) {
|
||||
for (tmp_order = order + 1;
|
||||
!retcode
|
||||
&& dma->granted_count < dma->request_count
|
||||
&& tmp_order <= DRM_MAX_ORDER;
|
||||
++tmp_order) {
|
||||
|
||||
retcode = DRM(dma_get_buffers_of_order)(dev, dma,
|
||||
tmp_order);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __HAVE_OLD_DMA */
|
||||
|
||||
|
||||
#if __HAVE_DMA_IRQ
|
||||
|
||||
int DRM(irq_install)( drm_device_t *dev, int irq )
|
||||
{
|
||||
int rid;
|
||||
int retcode;
|
||||
|
||||
if ( !irq )
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
|
||||
DRM_OS_LOCK;
|
||||
if ( dev->irq ) {
|
||||
DRM_OS_UNLOCK;
|
||||
DRM_OS_RETURN(EBUSY);
|
||||
}
|
||||
dev->irq = irq;
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
|
||||
|
||||
dev->context_flag = 0;
|
||||
dev->interrupt_flag = 0;
|
||||
dev->dma_flag = 0;
|
||||
|
||||
dev->dma->next_buffer = NULL;
|
||||
dev->dma->next_queue = NULL;
|
||||
dev->dma->this_buffer = NULL;
|
||||
|
||||
#if __HAVE_DMA_IRQ_BH
|
||||
TASK_INIT(&dev->task, 0, DRM(dma_immediate_bh), dev);
|
||||
#endif
|
||||
|
||||
/* Before installing handler */
|
||||
DRIVER_PREINSTALL();
|
||||
|
||||
/* Install handler */
|
||||
rid = 0;
|
||||
dev->irqr = bus_alloc_resource(dev->device, SYS_RES_IRQ, &rid,
|
||||
0, ~0, 1, RF_SHAREABLE);
|
||||
if (!dev->irqr)
|
||||
return ENOENT;
|
||||
|
||||
retcode = bus_setup_intr(dev->device, dev->irqr, INTR_TYPE_TTY,
|
||||
DRM(dma_service), dev, &dev->irqh);
|
||||
if ( retcode ) {
|
||||
DRM_OS_LOCK;
|
||||
bus_release_resource(dev->device, SYS_RES_IRQ, 0, dev->irqr);
|
||||
dev->irq = 0;
|
||||
DRM_OS_UNLOCK;
|
||||
return retcode;
|
||||
}
|
||||
|
||||
/* After installing handler */
|
||||
DRIVER_POSTINSTALL();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(irq_uninstall)( drm_device_t *dev )
|
||||
{
|
||||
int irq;
|
||||
|
||||
DRM_OS_LOCK;
|
||||
irq = dev->irq;
|
||||
dev->irq = 0;
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
if ( !irq )
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
|
||||
DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
|
||||
|
||||
DRIVER_UNINSTALL();
|
||||
|
||||
bus_teardown_intr(dev->device, dev->irqr, dev->irqh);
|
||||
bus_release_resource(dev->device, SYS_RES_IRQ, 0, dev->irqr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(control)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_control_t ctl;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctl, (drm_control_t *) data, sizeof(ctl) );
|
||||
|
||||
switch ( ctl.func ) {
|
||||
case DRM_INST_HANDLER:
|
||||
return DRM(irq_install)( dev, ctl.irq );
|
||||
case DRM_UNINST_HANDLER:
|
||||
return DRM(irq_uninstall)( dev );
|
||||
default:
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __HAVE_DMA_IRQ */
|
||||
|
||||
#endif /* __HAVE_DMA */
|
||||
50
bsd-core/drm_drawable.c
Normal file
50
bsd-core/drm_drawable.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/* drm_drawable.h -- IOCTLs for drawables -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
int DRM(adddraw)( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_draw_t draw;
|
||||
|
||||
draw.handle = 0; /* NOOP */
|
||||
DRM_DEBUG("%d\n", draw.handle);
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_draw_t *)data, draw, sizeof(draw) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(rmdraw)( DRM_OS_IOCTL )
|
||||
{
|
||||
return 0; /* NOOP */
|
||||
}
|
||||
1160
bsd-core/drm_drv.c
Normal file
1160
bsd-core/drm_drv.c
Normal file
File diff suppressed because it is too large
Load diff
223
bsd-core/drm_fops.c
Normal file
223
bsd-core/drm_fops.c
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
/* drm_fops.h -- File operations for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Daryll Strauss <daryll@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
drm_file_t *DRM(find_file_by_proc)(drm_device_t *dev, DRM_OS_STRUCTPROC *p)
|
||||
{
|
||||
#if __FreeBSD_version >= 500021
|
||||
uid_t uid = p->td_proc->p_ucred->cr_svuid;
|
||||
pid_t pid = p->td_proc->p_pid;
|
||||
#else
|
||||
uid_t uid = p->p_cred->p_svuid;
|
||||
pid_t pid = p->p_pid;
|
||||
#endif
|
||||
drm_file_t *priv;
|
||||
|
||||
TAILQ_FOREACH(priv, &dev->files, link)
|
||||
if (priv->pid == pid && priv->uid == uid)
|
||||
return priv;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* DRM(open) is called whenever a process opens /dev/drm. */
|
||||
|
||||
int DRM(open_helper)(dev_t kdev, int flags, int fmt, DRM_OS_STRUCTPROC *p,
|
||||
drm_device_t *dev)
|
||||
{
|
||||
int m = minor(kdev);
|
||||
drm_file_t *priv;
|
||||
|
||||
if (flags & O_EXCL)
|
||||
return EBUSY; /* No exclusive opens */
|
||||
dev->flags = flags;
|
||||
if (!DRM(cpu_valid)())
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
|
||||
DRM_DEBUG("pid = %d, minor = %d\n", DRM_OS_CURRENTPID, m);
|
||||
|
||||
/* FIXME: linux mallocs and bzeros here */
|
||||
priv = (drm_file_t *) DRM(find_file_by_proc)(dev, p);
|
||||
if (priv) {
|
||||
priv->refs++;
|
||||
} else {
|
||||
priv = (drm_file_t *) DRM(alloc)(sizeof(*priv), DRM_MEM_FILES);
|
||||
bzero(priv, sizeof(*priv));
|
||||
#if __FreeBSD_version >= 500000
|
||||
priv->uid = p->td_proc->p_ucred->cr_svuid;
|
||||
priv->pid = p->td_proc->p_pid;
|
||||
#else
|
||||
priv->uid = p->p_cred->p_svuid;
|
||||
priv->pid = p->p_pid;
|
||||
#endif
|
||||
|
||||
priv->refs = 1;
|
||||
priv->minor = m;
|
||||
priv->devXX = dev;
|
||||
priv->ioctl_count = 0;
|
||||
priv->authenticated = !DRM_OS_CHECKSUSER;
|
||||
lockmgr(&dev->dev_lock, LK_EXCLUSIVE, 0, p);
|
||||
TAILQ_INSERT_TAIL(&dev->files, priv, link);
|
||||
lockmgr(&dev->dev_lock, LK_RELEASE, 0, p);
|
||||
}
|
||||
|
||||
kdev->si_drv1 = dev;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* The drm_read and drm_write_string code (especially that which manages
|
||||
the circular buffer), is based on Alessandro Rubini's LINUX DEVICE
|
||||
DRIVERS (Cambridge: O'Reilly, 1998), pages 111-113. */
|
||||
|
||||
ssize_t DRM(read)(dev_t kdev, struct uio *uio, int ioflag)
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
int left;
|
||||
int avail;
|
||||
int send;
|
||||
int cur;
|
||||
int error = 0;
|
||||
|
||||
DRM_DEBUG("%p, %p\n", dev->buf_rp, dev->buf_wp);
|
||||
|
||||
while (dev->buf_rp == dev->buf_wp) {
|
||||
DRM_DEBUG(" sleeping\n");
|
||||
if (dev->flags & FASYNC)
|
||||
return EWOULDBLOCK;
|
||||
error = tsleep(&dev->buf_rp, PZERO|PCATCH, "drmrd", 0);
|
||||
if (error) {
|
||||
DRM_DEBUG(" interrupted\n");
|
||||
return error;
|
||||
}
|
||||
DRM_DEBUG(" awake\n");
|
||||
}
|
||||
|
||||
left = (dev->buf_rp + DRM_BSZ - dev->buf_wp) % DRM_BSZ;
|
||||
avail = DRM_BSZ - left;
|
||||
send = DRM_MIN(avail, uio->uio_resid);
|
||||
|
||||
while (send) {
|
||||
if (dev->buf_wp > dev->buf_rp) {
|
||||
cur = DRM_MIN(send, dev->buf_wp - dev->buf_rp);
|
||||
} else {
|
||||
cur = DRM_MIN(send, dev->buf_end - dev->buf_rp);
|
||||
}
|
||||
error = uiomove(dev->buf_rp, cur, uio);
|
||||
if (error)
|
||||
break;
|
||||
dev->buf_rp += cur;
|
||||
if (dev->buf_rp == dev->buf_end) dev->buf_rp = dev->buf;
|
||||
send -= cur;
|
||||
}
|
||||
|
||||
wakeup(&dev->buf_wp);
|
||||
return error;
|
||||
}
|
||||
|
||||
int DRM(write_string)(drm_device_t *dev, const char *s)
|
||||
{
|
||||
int left = (dev->buf_rp + DRM_BSZ - dev->buf_wp) % DRM_BSZ;
|
||||
int send = strlen(s);
|
||||
int count;
|
||||
|
||||
DRM_DEBUG("%d left, %d to send (%p, %p)\n",
|
||||
left, send, dev->buf_rp, dev->buf_wp);
|
||||
|
||||
if (left == 1 || dev->buf_wp != dev->buf_rp) {
|
||||
DRM_ERROR("Buffer not empty (%d left, wp = %p, rp = %p)\n",
|
||||
left,
|
||||
dev->buf_wp,
|
||||
dev->buf_rp);
|
||||
}
|
||||
|
||||
while (send) {
|
||||
if (dev->buf_wp >= dev->buf_rp) {
|
||||
count = DRM_MIN(send, dev->buf_end - dev->buf_wp);
|
||||
if (count == left) --count; /* Leave a hole */
|
||||
} else {
|
||||
count = DRM_MIN(send, dev->buf_rp - dev->buf_wp - 1);
|
||||
}
|
||||
strncpy(dev->buf_wp, s, count);
|
||||
dev->buf_wp += count;
|
||||
if (dev->buf_wp == dev->buf_end) dev->buf_wp = dev->buf;
|
||||
send -= count;
|
||||
}
|
||||
|
||||
if (dev->buf_selecting) {
|
||||
dev->buf_selecting = 0;
|
||||
selwakeup(&dev->buf_sel);
|
||||
}
|
||||
|
||||
DRM_DEBUG("dev->buf_sigio=%p\n", dev->buf_sigio);
|
||||
if (dev->buf_sigio) {
|
||||
DRM_DEBUG("dev->buf_sigio->sio_pgid=%d\n", dev->buf_sigio->sio_pgid);
|
||||
pgsigio(dev->buf_sigio, SIGIO, 0);
|
||||
}
|
||||
DRM_DEBUG("waking\n");
|
||||
wakeup(&dev->buf_rp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(poll)(dev_t kdev, int events, DRM_OS_STRUCTPROC *p)
|
||||
{
|
||||
drm_device_t *dev = kdev->si_drv1;
|
||||
int s;
|
||||
int revents = 0;
|
||||
|
||||
s = spldrm();
|
||||
if (events & (POLLIN | POLLRDNORM)) {
|
||||
int left = (dev->buf_rp + DRM_BSZ - dev->buf_wp) % DRM_BSZ;
|
||||
if (left > 0)
|
||||
revents |= events & (POLLIN | POLLRDNORM);
|
||||
else
|
||||
selrecord(p, &dev->buf_sel);
|
||||
}
|
||||
splx(s);
|
||||
|
||||
return revents;
|
||||
}
|
||||
|
||||
int DRM(write)(dev_t kdev, struct uio *uio, int ioflag)
|
||||
{
|
||||
DRM_DEBUG("pid = %d, device = %p, open_count = %d\n",
|
||||
curproc->p_pid, ((drm_device_t *)kdev->si_drv1)->device, ((drm_device_t *)kdev->si_drv1)->open_count);
|
||||
return 0;
|
||||
}
|
||||
237
bsd-core/drm_ioctl.c
Normal file
237
bsd-core/drm_ioctl.c
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
/* drm_ioctl.h -- IOCTL processing for DRM -*- linux-c -*-
|
||||
* Created: Fri Jan 8 09:01:26 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
#include <sys/bus.h>
|
||||
#include <pci/pcivar.h>
|
||||
|
||||
int DRM(irq_busid)( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_irq_busid_t id;
|
||||
devclass_t pci;
|
||||
device_t bus, dev;
|
||||
device_t *kids;
|
||||
int error, i, num_kids;
|
||||
|
||||
DRM_OS_KRNFROMUSR( id, (drm_irq_busid_t *)data, sizeof(id) );
|
||||
|
||||
pci = devclass_find("pci");
|
||||
if (!pci)
|
||||
return ENOENT;
|
||||
bus = devclass_get_device(pci, id.busnum);
|
||||
if (!bus)
|
||||
return ENOENT;
|
||||
error = device_get_children(bus, &kids, &num_kids);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
dev = 0;
|
||||
for (i = 0; i < num_kids; i++) {
|
||||
dev = kids[i];
|
||||
if (pci_get_slot(dev) == id.devnum
|
||||
&& pci_get_function(dev) == id.funcnum)
|
||||
break;
|
||||
}
|
||||
|
||||
free(kids, M_TEMP);
|
||||
|
||||
if (i != num_kids)
|
||||
id.irq = pci_get_irq(dev);
|
||||
else
|
||||
id.irq = 0;
|
||||
DRM_DEBUG("%d:%d:%d => IRQ %d\n",
|
||||
id.busnum, id.devnum, id.funcnum, id.irq);
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_irq_busid_t *)data, id, sizeof(id) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(getunique)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_unique_t u;
|
||||
|
||||
DRM_OS_KRNFROMUSR( u, (drm_unique_t *)data, sizeof(u) );
|
||||
|
||||
if (u.unique_len >= dev->unique_len) {
|
||||
if (DRM_OS_COPYTOUSR(u.unique, dev->unique, dev->unique_len))
|
||||
DRM_OS_RETURN(EFAULT);
|
||||
}
|
||||
u.unique_len = dev->unique_len;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_unique_t *)data, u, sizeof(u) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(setunique)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_unique_t u;
|
||||
|
||||
if (dev->unique_len || dev->unique)
|
||||
DRM_OS_RETURN(EBUSY);
|
||||
|
||||
DRM_OS_KRNFROMUSR( u, (drm_unique_t *)data, sizeof(u) );
|
||||
|
||||
if (!u.unique_len || u.unique_len > 1024)
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
|
||||
dev->unique_len = u.unique_len;
|
||||
dev->unique = DRM(alloc)(u.unique_len + 1, DRM_MEM_DRIVER);
|
||||
|
||||
if(!dev->unique) DRM_OS_RETURN(ENOMEM);
|
||||
|
||||
if (DRM_OS_COPYFROMUSR(dev->unique, u.unique, dev->unique_len))
|
||||
DRM_OS_RETURN(EFAULT);
|
||||
|
||||
dev->unique[dev->unique_len] = '\0';
|
||||
|
||||
dev->devname = DRM(alloc)(strlen(dev->name) + strlen(dev->unique) + 2,
|
||||
DRM_MEM_DRIVER);
|
||||
if(!dev->devname) {
|
||||
DRM(free)(dev->devname, sizeof(*dev->devname), DRM_MEM_DRIVER);
|
||||
DRM_OS_RETURN(ENOMEM);
|
||||
}
|
||||
sprintf(dev->devname, "%s@%s", dev->name, dev->unique);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int DRM(getmap)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_map_t map;
|
||||
drm_map_t *mapinlist;
|
||||
drm_map_list_entry_t *list;
|
||||
int idx;
|
||||
int i = 0;
|
||||
|
||||
DRM_OS_KRNFROMUSR( map, (drm_map_t *)data, sizeof(map) );
|
||||
|
||||
idx = map.offset;
|
||||
|
||||
DRM_OS_LOCK;
|
||||
if (idx < 0 || idx >= dev->map_count) {
|
||||
DRM_OS_UNLOCK;
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
TAILQ_FOREACH(list, dev->maplist, link) {
|
||||
mapinlist = list->map;
|
||||
if (i==idx) {
|
||||
map.offset = mapinlist->offset;
|
||||
map.size = mapinlist->size;
|
||||
map.type = mapinlist->type;
|
||||
map.flags = mapinlist->flags;
|
||||
map.handle = mapinlist->handle;
|
||||
map.mtrr = mapinlist->mtrr;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
if (!list)
|
||||
return EINVAL;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_map_t *)data, map, sizeof(map) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(getclient)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_client_t client;
|
||||
drm_file_t *pt;
|
||||
int idx;
|
||||
int i = 0;
|
||||
|
||||
DRM_OS_KRNFROMUSR( client, (drm_client_t *)data, sizeof(client) );
|
||||
|
||||
idx = client.idx;
|
||||
DRM_OS_LOCK;
|
||||
TAILQ_FOREACH(pt, &dev->files, link) {
|
||||
if (i==idx)
|
||||
{
|
||||
client.auth = pt->authenticated;
|
||||
client.pid = pt->pid;
|
||||
client.uid = pt->uid;
|
||||
client.magic = pt->magic;
|
||||
client.iocs = pt->ioctl_count;
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
*(drm_client_t *)data = client;
|
||||
return 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_client_t *)data, client, sizeof(client) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(getstats)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_stats_t stats;
|
||||
int i;
|
||||
|
||||
memset(&stats, 0, sizeof(stats));
|
||||
|
||||
DRM_OS_LOCK;
|
||||
|
||||
for (i = 0; i < dev->counters; i++) {
|
||||
if (dev->types[i] == _DRM_STAT_LOCK)
|
||||
stats.data[i].value
|
||||
= (dev->lock.hw_lock
|
||||
? dev->lock.hw_lock->lock : 0);
|
||||
else
|
||||
stats.data[i].value = atomic_read(&dev->counts[i]);
|
||||
stats.data[i].type = dev->types[i];
|
||||
}
|
||||
|
||||
stats.count = dev->counters;
|
||||
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_stats_t *)data, stats, sizeof(stats) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
244
bsd-core/drm_lock.c
Normal file
244
bsd-core/drm_lock.c
Normal file
|
|
@ -0,0 +1,244 @@
|
|||
/* lock.c -- IOCTLs for locking -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
int DRM(block)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_DEBUG("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(unblock)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_DEBUG("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(lock_take)(__volatile__ unsigned int *lock, unsigned int context)
|
||||
{
|
||||
unsigned int old, new;
|
||||
|
||||
char failed;
|
||||
|
||||
do {
|
||||
old = *lock;
|
||||
if (old & _DRM_LOCK_HELD) new = old | _DRM_LOCK_CONT;
|
||||
else new = context | _DRM_LOCK_HELD;
|
||||
_DRM_CAS(lock, old, new, failed);
|
||||
} while (failed);
|
||||
if (_DRM_LOCKING_CONTEXT(old) == context) {
|
||||
if (old & _DRM_LOCK_HELD) {
|
||||
if (context != DRM_KERNEL_CONTEXT) {
|
||||
DRM_ERROR("%d holds heavyweight lock\n",
|
||||
context);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (new == (context | _DRM_LOCK_HELD)) {
|
||||
/* Have lock */
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This takes a lock forcibly and hands it to context. Should ONLY be used
|
||||
inside *_unlock to give lock to kernel before calling *_dma_schedule. */
|
||||
int DRM(lock_transfer)(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock, unsigned int context)
|
||||
{
|
||||
unsigned int old, new;
|
||||
char failed;
|
||||
|
||||
dev->lock.pid = 0;
|
||||
do {
|
||||
old = *lock;
|
||||
new = context | _DRM_LOCK_HELD;
|
||||
_DRM_CAS(lock, old, new, failed);
|
||||
} while (failed);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DRM(lock_free)(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock, unsigned int context)
|
||||
{
|
||||
unsigned int old, new;
|
||||
pid_t pid = dev->lock.pid;
|
||||
char failed;
|
||||
|
||||
dev->lock.pid = 0;
|
||||
do {
|
||||
old = *lock;
|
||||
new = 0;
|
||||
_DRM_CAS(lock, old, new, failed);
|
||||
} while (failed);
|
||||
if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
|
||||
DRM_ERROR("%d freed heavyweight lock held by %d (pid %d)\n",
|
||||
context,
|
||||
_DRM_LOCKING_CONTEXT(old),
|
||||
pid);
|
||||
return 1;
|
||||
}
|
||||
DRM_OS_WAKEUP_INT(&dev->lock.lock_queue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DRM(flush_queue)(drm_device_t *dev, int context)
|
||||
{
|
||||
int error;
|
||||
int ret = 0;
|
||||
drm_queue_t *q = dev->queuelist[context];
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) > 1) {
|
||||
atomic_inc(&q->block_write);
|
||||
atomic_inc(&q->block_count);
|
||||
error = tsleep(&q->flush_queue, PZERO|PCATCH, "drmfq", 0);
|
||||
if (error)
|
||||
return error;
|
||||
atomic_dec(&q->block_count);
|
||||
}
|
||||
atomic_dec(&q->use_count);
|
||||
|
||||
/* NOTE: block_write is still incremented!
|
||||
Use drm_flush_unlock_queue to decrement. */
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int DRM(flush_unblock_queue)(drm_device_t *dev, int context)
|
||||
{
|
||||
drm_queue_t *q = dev->queuelist[context];
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) > 1) {
|
||||
if (atomic_read(&q->block_write)) {
|
||||
atomic_dec(&q->block_write);
|
||||
DRM_OS_WAKEUP_INT(&q->write_queue);
|
||||
}
|
||||
}
|
||||
atomic_dec(&q->use_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(flush_block_and_flush)(drm_device_t *dev, int context,
|
||||
drm_lock_flags_t flags)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
if (flags & _DRM_LOCK_FLUSH) {
|
||||
ret = DRM(flush_queue)(dev, DRM_KERNEL_CONTEXT);
|
||||
if (!ret) ret = DRM(flush_queue)(dev, context);
|
||||
}
|
||||
if (flags & _DRM_LOCK_FLUSH_ALL) {
|
||||
for (i = 0; !ret && i < dev->queue_count; i++) {
|
||||
ret = DRM(flush_queue)(dev, i);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DRM(flush_unblock)(drm_device_t *dev, int context, drm_lock_flags_t flags)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
if (flags & _DRM_LOCK_FLUSH) {
|
||||
ret = DRM(flush_unblock_queue)(dev, DRM_KERNEL_CONTEXT);
|
||||
if (!ret) ret = DRM(flush_unblock_queue)(dev, context);
|
||||
}
|
||||
if (flags & _DRM_LOCK_FLUSH_ALL) {
|
||||
for (i = 0; !ret && i < dev->queue_count; i++) {
|
||||
ret = DRM(flush_unblock_queue)(dev, i);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DRM(finish)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
int ret = 0;
|
||||
drm_lock_t lock;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
DRM_OS_KRNFROMUSR( lock, (drm_lock_t *)data, sizeof(lock) );
|
||||
|
||||
ret = DRM(flush_block_and_flush)(dev, lock.context, lock.flags);
|
||||
DRM(flush_unblock)(dev, lock.context, lock.flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* If we get here, it means that the process has called DRM_IOCTL_LOCK
|
||||
without calling DRM_IOCTL_UNLOCK.
|
||||
|
||||
If the lock is not held, then let the signal proceed as usual.
|
||||
|
||||
If the lock is held, then set the contended flag and keep the signal
|
||||
blocked.
|
||||
|
||||
|
||||
Return 1 if the signal should be delivered normally.
|
||||
Return 0 if the signal should be blocked. */
|
||||
|
||||
int DRM(notifier)(void *priv)
|
||||
{
|
||||
drm_sigdata_t *s = (drm_sigdata_t *)priv;
|
||||
unsigned int old, new;
|
||||
char failed;
|
||||
|
||||
|
||||
/* Allow signal delivery if lock isn't held */
|
||||
if (!_DRM_LOCK_IS_HELD(s->lock->lock)
|
||||
|| _DRM_LOCKING_CONTEXT(s->lock->lock) != s->context) return 1;
|
||||
|
||||
/* Otherwise, set flag to force call to
|
||||
drmUnlock */
|
||||
do {
|
||||
old = s->lock->lock;
|
||||
new = old | _DRM_LOCK_CONT;
|
||||
_DRM_CAS(&s->lock->lock, old, new, failed);
|
||||
} while (failed);
|
||||
return 0;
|
||||
}
|
||||
|
||||
433
bsd-core/drm_memory.c
Normal file
433
bsd-core/drm_memory.c
Normal file
|
|
@ -0,0 +1,433 @@
|
|||
/* drm_memory.h -- Memory management wrappers for DRM -*- linux-c -*-
|
||||
* Created: Thu Feb 4 14:00:34 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
#if __REALLY_HAVE_AGP
|
||||
#include <sys/agpio.h>
|
||||
#endif
|
||||
|
||||
#define malloctype DRM(M_DRM)
|
||||
/* The macros confliced in the MALLOC_DEFINE */
|
||||
|
||||
MALLOC_DEFINE(malloctype, "drm", "DRM Data Structures");
|
||||
|
||||
#undef malloctype
|
||||
|
||||
typedef struct drm_mem_stats {
|
||||
const char *name;
|
||||
int succeed_count;
|
||||
int free_count;
|
||||
int fail_count;
|
||||
unsigned long bytes_allocated;
|
||||
unsigned long bytes_freed;
|
||||
} drm_mem_stats_t;
|
||||
|
||||
static DRM_OS_SPINTYPE DRM(mem_lock);
|
||||
static unsigned long DRM(ram_available) = 0; /* In pages */
|
||||
static unsigned long DRM(ram_used) = 0;
|
||||
static drm_mem_stats_t DRM(mem_stats)[] = {
|
||||
[DRM_MEM_DMA] = { "dmabufs" },
|
||||
[DRM_MEM_SAREA] = { "sareas" },
|
||||
[DRM_MEM_DRIVER] = { "driver" },
|
||||
[DRM_MEM_MAGIC] = { "magic" },
|
||||
[DRM_MEM_IOCTLS] = { "ioctltab" },
|
||||
[DRM_MEM_MAPS] = { "maplist" },
|
||||
[DRM_MEM_VMAS] = { "vmalist" },
|
||||
[DRM_MEM_BUFS] = { "buflist" },
|
||||
[DRM_MEM_SEGS] = { "seglist" },
|
||||
[DRM_MEM_PAGES] = { "pagelist" },
|
||||
[DRM_MEM_FILES] = { "files" },
|
||||
[DRM_MEM_QUEUES] = { "queues" },
|
||||
[DRM_MEM_CMDS] = { "commands" },
|
||||
[DRM_MEM_MAPPINGS] = { "mappings" },
|
||||
[DRM_MEM_BUFLISTS] = { "buflists" },
|
||||
[DRM_MEM_AGPLISTS] = { "agplist" },
|
||||
[DRM_MEM_SGLISTS] = { "sglist" },
|
||||
[DRM_MEM_TOTALAGP] = { "totalagp" },
|
||||
[DRM_MEM_BOUNDAGP] = { "boundagp" },
|
||||
[DRM_MEM_CTXBITMAP] = { "ctxbitmap"},
|
||||
[DRM_MEM_STUB] = { "stub" },
|
||||
{ NULL, 0, } /* Last entry must be null */
|
||||
};
|
||||
|
||||
void DRM(mem_init)(void)
|
||||
{
|
||||
drm_mem_stats_t *mem;
|
||||
|
||||
DRM_OS_SPININIT(DRM(mem_lock), "drm memory");
|
||||
|
||||
for (mem = DRM(mem_stats); mem->name; ++mem) {
|
||||
mem->succeed_count = 0;
|
||||
mem->free_count = 0;
|
||||
mem->fail_count = 0;
|
||||
mem->bytes_allocated = 0;
|
||||
mem->bytes_freed = 0;
|
||||
}
|
||||
|
||||
DRM(ram_available) = 0; /* si.totalram */
|
||||
DRM(ram_used) = 0;
|
||||
}
|
||||
|
||||
/* drm_mem_info is called whenever a process reads /dev/drm/mem. */
|
||||
|
||||
static int DRM(_mem_info) DRM_SYSCTL_HANDLER_ARGS
|
||||
{
|
||||
drm_mem_stats_t *pt;
|
||||
char buf[128];
|
||||
int error;
|
||||
|
||||
DRM_SYSCTL_PRINT(" total counts "
|
||||
" | outstanding \n");
|
||||
DRM_SYSCTL_PRINT("type alloc freed fail bytes freed"
|
||||
" | allocs bytes\n\n");
|
||||
DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu |\n",
|
||||
"system", 0, 0, 0, DRM(ram_available));
|
||||
DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu |\n",
|
||||
"locked", 0, 0, 0, DRM(ram_used));
|
||||
DRM_SYSCTL_PRINT("\n");
|
||||
for (pt = DRM(mem_stats); pt->name; pt++) {
|
||||
DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu %10lu | %6d %10ld\n",
|
||||
pt->name,
|
||||
pt->succeed_count,
|
||||
pt->free_count,
|
||||
pt->fail_count,
|
||||
pt->bytes_allocated,
|
||||
pt->bytes_freed,
|
||||
pt->succeed_count - pt->free_count,
|
||||
(long)pt->bytes_allocated
|
||||
- (long)pt->bytes_freed);
|
||||
}
|
||||
SYSCTL_OUT(req, "", 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(mem_info) DRM_SYSCTL_HANDLER_ARGS
|
||||
{
|
||||
int ret;
|
||||
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
ret = DRM(_mem_info)(oidp, arg1, arg2, req);
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *DRM(alloc)(size_t size, int area)
|
||||
{
|
||||
void *pt;
|
||||
|
||||
if (!size) {
|
||||
DRM_MEM_ERROR(area, "Allocating 0 bytes\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(pt = malloc(size, DRM(M_DRM), M_NOWAIT))) {
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[area].fail_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return NULL;
|
||||
}
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[area].succeed_count;
|
||||
DRM(mem_stats)[area].bytes_allocated += size;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return pt;
|
||||
}
|
||||
|
||||
void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size, int area)
|
||||
{
|
||||
void *pt;
|
||||
|
||||
if (!(pt = DRM(alloc)(size, area))) return NULL;
|
||||
if (oldpt && oldsize) {
|
||||
memcpy(pt, oldpt, oldsize);
|
||||
DRM(free)(oldpt, oldsize, area);
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
|
||||
char *DRM(strdup)(const char *s, int area)
|
||||
{
|
||||
char *pt;
|
||||
int length = s ? strlen(s) : 0;
|
||||
|
||||
if (!(pt = DRM(alloc)(length+1, area))) return NULL;
|
||||
strcpy(pt, s);
|
||||
return pt;
|
||||
}
|
||||
|
||||
void DRM(strfree)(char *s, int area)
|
||||
{
|
||||
unsigned int size;
|
||||
|
||||
if (!s) return;
|
||||
|
||||
size = 1 + strlen(s);
|
||||
DRM(free)((void *)s, size, area);
|
||||
}
|
||||
|
||||
void DRM(free)(void *pt, size_t size, int area)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
|
||||
if (!pt) DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n");
|
||||
else free(pt, DRM(M_DRM));
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
DRM(mem_stats)[area].bytes_freed += size;
|
||||
free_count = ++DRM(mem_stats)[area].free_count;
|
||||
alloc_count = DRM(mem_stats)[area].succeed_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(area, "Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long DRM(alloc_pages)(int order, int area)
|
||||
{
|
||||
vm_offset_t address;
|
||||
unsigned long bytes = PAGE_SIZE << order;
|
||||
|
||||
|
||||
address = (vm_offset_t) contigmalloc(bytes, DRM(M_DRM), M_WAITOK, 0, ~0, 1, 0);
|
||||
if (!address) {
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[area].fail_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return 0;
|
||||
}
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[area].succeed_count;
|
||||
DRM(mem_stats)[area].bytes_allocated += bytes;
|
||||
DRM(ram_used) += bytes;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
|
||||
|
||||
/* Zero outside the lock */
|
||||
memset((void *)address, 0, bytes);
|
||||
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
void DRM(free_pages)(unsigned long address, int order, int area)
|
||||
{
|
||||
unsigned long bytes = PAGE_SIZE << order;
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
|
||||
if (!address) {
|
||||
DRM_MEM_ERROR(area, "Attempt to free address 0\n");
|
||||
} else {
|
||||
contigfree((void *) address, bytes, DRM(M_DRM));
|
||||
}
|
||||
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
free_count = ++DRM(mem_stats)[area].free_count;
|
||||
alloc_count = DRM(mem_stats)[area].succeed_count;
|
||||
DRM(mem_stats)[area].bytes_freed += bytes;
|
||||
DRM(ram_used) -= bytes;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(area,
|
||||
"Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
}
|
||||
|
||||
void *DRM(ioremap)(unsigned long offset, unsigned long size)
|
||||
{
|
||||
void *pt;
|
||||
|
||||
if (!size) {
|
||||
DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
|
||||
"Mapping 0 bytes at 0x%08lx\n", offset);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(pt = pmap_mapdev(offset, size))) {
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[DRM_MEM_MAPPINGS].fail_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return NULL;
|
||||
}
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[DRM_MEM_MAPPINGS].succeed_count;
|
||||
DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_allocated += size;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return pt;
|
||||
}
|
||||
|
||||
void DRM(ioremapfree)(void *pt, unsigned long size)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
|
||||
if (!pt)
|
||||
DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
|
||||
"Attempt to free NULL pointer\n");
|
||||
else
|
||||
pmap_unmapdev((vm_offset_t) pt, size);
|
||||
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_freed += size;
|
||||
free_count = ++DRM(mem_stats)[DRM_MEM_MAPPINGS].free_count;
|
||||
alloc_count = DRM(mem_stats)[DRM_MEM_MAPPINGS].succeed_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
|
||||
"Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
}
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
agp_memory *DRM(alloc_agp)(int pages, u32 type)
|
||||
{
|
||||
agp_memory *handle;
|
||||
|
||||
if (!pages) {
|
||||
DRM_MEM_ERROR(DRM_MEM_TOTALAGP, "Allocating 0 pages\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((handle = DRM(agp_allocate_memory)(pages, type))) {
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
|
||||
DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_allocated
|
||||
+= pages << PAGE_SHIFT;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return handle;
|
||||
}
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[DRM_MEM_TOTALAGP].fail_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int DRM(free_agp)(agp_memory *handle, int pages)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
|
||||
if (!handle) {
|
||||
DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
|
||||
"Attempt to free NULL AGP handle\n");
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
if (DRM(agp_free_memory)(handle)) {
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
free_count = ++DRM(mem_stats)[DRM_MEM_TOTALAGP].free_count;
|
||||
alloc_count = DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
|
||||
DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_freed
|
||||
+= pages << PAGE_SHIFT;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
|
||||
"Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
int DRM(bind_agp)(agp_memory *handle, unsigned int start)
|
||||
{
|
||||
int retcode;
|
||||
device_t dev = agp_find_device();
|
||||
struct agp_memory_info info;
|
||||
|
||||
if (!dev)
|
||||
return EINVAL;
|
||||
|
||||
if (!handle) {
|
||||
DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
|
||||
"Attempt to bind NULL AGP handle\n");
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
if (!(retcode = DRM(agp_bind_memory)(handle, start))) {
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
|
||||
agp_memory_info(dev, handle, &info);
|
||||
DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_allocated
|
||||
+= info.ami_size;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
DRM_OS_RETURN(0);
|
||||
}
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[DRM_MEM_BOUNDAGP].fail_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
DRM_OS_RETURN(retcode);
|
||||
}
|
||||
|
||||
int DRM(unbind_agp)(agp_memory *handle)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
int retcode = EINVAL;
|
||||
device_t dev = agp_find_device();
|
||||
struct agp_memory_info info;
|
||||
|
||||
if (!dev)
|
||||
return EINVAL;
|
||||
|
||||
if (!handle) {
|
||||
DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
|
||||
"Attempt to unbind NULL AGP handle\n");
|
||||
DRM_OS_RETURN(retcode);
|
||||
}
|
||||
|
||||
agp_memory_info(dev, handle, &info);
|
||||
|
||||
if ((retcode = DRM(agp_unbind_memory)(handle)))
|
||||
DRM_OS_RETURN(retcode);
|
||||
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
free_count = ++DRM(mem_stats)[DRM_MEM_BOUNDAGP].free_count;
|
||||
alloc_count = DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
|
||||
DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_freed
|
||||
+= info.ami_size;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
|
||||
"Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
DRM_OS_RETURN(retcode);
|
||||
}
|
||||
#endif
|
||||
237
bsd-core/drm_scatter.c
Normal file
237
bsd-core/drm_scatter.c
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
/* drm_scatter.h -- IOCTLs to manage scatter/gather memory -*- linux-c -*-
|
||||
* Created: Mon Dec 18 23:20:54 2000 by gareth@valinux.com
|
||||
*
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include <linux/config.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include "drmP.h"
|
||||
|
||||
#define DEBUG_SCATTER 0
|
||||
|
||||
void DRM(sg_cleanup)( drm_sg_mem_t *entry )
|
||||
{
|
||||
struct page *page;
|
||||
int i;
|
||||
|
||||
for ( i = 0 ; i < entry->pages ; i++ ) {
|
||||
page = entry->pagelist[i];
|
||||
if ( page )
|
||||
ClearPageReserved( page );
|
||||
}
|
||||
|
||||
vfree( entry->virtual );
|
||||
|
||||
DRM(free)( entry->busaddr,
|
||||
entry->pages * sizeof(*entry->busaddr),
|
||||
DRM_MEM_PAGES );
|
||||
DRM(free)( entry->pagelist,
|
||||
entry->pages * sizeof(*entry->pagelist),
|
||||
DRM_MEM_PAGES );
|
||||
DRM(free)( entry,
|
||||
sizeof(*entry),
|
||||
DRM_MEM_SGLISTS );
|
||||
}
|
||||
|
||||
int DRM(sg_alloc)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_scatter_gather_t request;
|
||||
drm_sg_mem_t *entry;
|
||||
unsigned long pages, i, j;
|
||||
pgd_t *pgd;
|
||||
pmd_t *pmd;
|
||||
pte_t *pte;
|
||||
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
if ( dev->sg )
|
||||
return -EINVAL;
|
||||
|
||||
if ( copy_from_user( &request,
|
||||
(drm_scatter_gather_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
entry = DRM(alloc)( sizeof(*entry), DRM_MEM_SGLISTS );
|
||||
if ( !entry )
|
||||
return -ENOMEM;
|
||||
|
||||
memset( entry, 0, sizeof(*entry) );
|
||||
|
||||
pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
|
||||
DRM_DEBUG( "sg size=%ld pages=%ld\n", request.size, pages );
|
||||
|
||||
entry->pages = pages;
|
||||
entry->pagelist = DRM(alloc)( pages * sizeof(*entry->pagelist),
|
||||
DRM_MEM_PAGES );
|
||||
if ( !entry->pagelist ) {
|
||||
DRM(free)( entry, sizeof(*entry), DRM_MEM_SGLISTS );
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
entry->busaddr = DRM(alloc)( pages * sizeof(*entry->busaddr),
|
||||
DRM_MEM_PAGES );
|
||||
if ( !entry->busaddr ) {
|
||||
DRM(free)( entry->pagelist,
|
||||
entry->pages * sizeof(*entry->pagelist),
|
||||
DRM_MEM_PAGES );
|
||||
DRM(free)( entry,
|
||||
sizeof(*entry),
|
||||
DRM_MEM_SGLISTS );
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset( (void *)entry->busaddr, 0, pages * sizeof(*entry->busaddr) );
|
||||
|
||||
entry->virtual = vmalloc_32( pages << PAGE_SHIFT );
|
||||
if ( !entry->virtual ) {
|
||||
DRM(free)( entry->busaddr,
|
||||
entry->pages * sizeof(*entry->busaddr),
|
||||
DRM_MEM_PAGES );
|
||||
DRM(free)( entry->pagelist,
|
||||
entry->pages * sizeof(*entry->pagelist),
|
||||
DRM_MEM_PAGES );
|
||||
DRM(free)( entry,
|
||||
sizeof(*entry),
|
||||
DRM_MEM_SGLISTS );
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* This also forces the mapping of COW pages, so our page list
|
||||
* will be valid. Please don't remove it...
|
||||
*/
|
||||
memset( entry->virtual, 0, pages << PAGE_SHIFT );
|
||||
|
||||
entry->handle = (unsigned long)entry->virtual;
|
||||
|
||||
DRM_DEBUG( "sg alloc handle = %08lx\n", entry->handle );
|
||||
DRM_DEBUG( "sg alloc virtual = %p\n", entry->virtual );
|
||||
|
||||
for ( i = entry->handle, j = 0 ; j < pages ; i += PAGE_SIZE, j++ ) {
|
||||
pgd = pgd_offset_k( i );
|
||||
if ( !pgd_present( *pgd ) )
|
||||
goto failed;
|
||||
|
||||
pmd = pmd_offset( pgd, i );
|
||||
if ( !pmd_present( *pmd ) )
|
||||
goto failed;
|
||||
|
||||
pte = pte_offset( pmd, i );
|
||||
if ( !pte_present( *pte ) )
|
||||
goto failed;
|
||||
|
||||
entry->pagelist[j] = pte_page( *pte );
|
||||
|
||||
SetPageReserved( entry->pagelist[j] );
|
||||
}
|
||||
|
||||
request.handle = entry->handle;
|
||||
|
||||
if ( copy_to_user( (drm_scatter_gather_t *)arg,
|
||||
&request,
|
||||
sizeof(request) ) ) {
|
||||
DRM(sg_cleanup)( entry );
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
dev->sg = entry;
|
||||
|
||||
#if DEBUG_SCATTER
|
||||
/* Verify that each page points to its virtual address, and vice
|
||||
* versa.
|
||||
*/
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
for ( i = 0 ; i < pages ; i++ ) {
|
||||
unsigned long *tmp;
|
||||
|
||||
tmp = page_address( entry->pagelist[i] );
|
||||
for ( j = 0 ;
|
||||
j < PAGE_SIZE / sizeof(unsigned long) ;
|
||||
j++, tmp++ ) {
|
||||
*tmp = 0xcafebabe;
|
||||
}
|
||||
tmp = (unsigned long *)((u8 *)entry->virtual +
|
||||
(PAGE_SIZE * i));
|
||||
for( j = 0 ;
|
||||
j < PAGE_SIZE / sizeof(unsigned long) ;
|
||||
j++, tmp++ ) {
|
||||
if ( *tmp != 0xcafebabe && error == 0 ) {
|
||||
error = 1;
|
||||
DRM_ERROR( "Scatter allocation error, "
|
||||
"pagelist does not match "
|
||||
"virtual mapping\n" );
|
||||
}
|
||||
}
|
||||
tmp = page_address( entry->pagelist[i] );
|
||||
for(j = 0 ;
|
||||
j < PAGE_SIZE / sizeof(unsigned long) ;
|
||||
j++, tmp++) {
|
||||
*tmp = 0;
|
||||
}
|
||||
}
|
||||
if (error == 0)
|
||||
DRM_ERROR( "Scatter allocation matches pagelist\n" );
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
failed:
|
||||
DRM(sg_cleanup)( entry );
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
int DRM(sg_free)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_scatter_gather_t request;
|
||||
drm_sg_mem_t *entry;
|
||||
|
||||
if ( copy_from_user( &request,
|
||||
(drm_scatter_gather_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
entry = dev->sg;
|
||||
dev->sg = NULL;
|
||||
|
||||
if ( !entry || entry->handle != request.handle )
|
||||
return -EINVAL;
|
||||
|
||||
DRM_DEBUG( "sg free virtual = %p\n", entry->virtual );
|
||||
|
||||
DRM(sg_cleanup)( entry );
|
||||
|
||||
return 0;
|
||||
}
|
||||
197
bsd/ati_pcigart.h
Normal file
197
bsd/ati_pcigart.h
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
/* ati_pcigart.h -- ATI PCI GART support -*- linux-c -*-
|
||||
* Created: Wed Dec 13 21:52:19 2000 by gareth@valinux.com
|
||||
*
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
#if PAGE_SIZE == 8192
|
||||
# define ATI_PCIGART_TABLE_ORDER 2
|
||||
# define ATI_PCIGART_TABLE_PAGES (1 << 2)
|
||||
#elif PAGE_SIZE == 4096
|
||||
# define ATI_PCIGART_TABLE_ORDER 3
|
||||
# define ATI_PCIGART_TABLE_PAGES (1 << 3)
|
||||
#elif
|
||||
# error - PAGE_SIZE not 8K or 4K
|
||||
#endif
|
||||
|
||||
# define ATI_MAX_PCIGART_PAGES 8192 /* 32 MB aperture, 4K pages */
|
||||
# define ATI_PCIGART_PAGE_SIZE 4096 /* PCI GART page size */
|
||||
|
||||
static unsigned long DRM(ati_alloc_pcigart_table)( void )
|
||||
{
|
||||
unsigned long address;
|
||||
struct page *page;
|
||||
int i;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
address = __get_free_pages( GFP_KERNEL, ATI_PCIGART_TABLE_ORDER );
|
||||
if ( address == 0UL ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
page = virt_to_page( address );
|
||||
|
||||
for ( i = 0 ; i <= ATI_PCIGART_TABLE_PAGES ; i++, page++ ) {
|
||||
atomic_inc( &page->count );
|
||||
SetPageReserved( page );
|
||||
}
|
||||
|
||||
DRM_DEBUG( "%s: returning 0x%08lx\n", __FUNCTION__, address );
|
||||
return address;
|
||||
}
|
||||
|
||||
static void DRM(ati_free_pcigart_table)( unsigned long address )
|
||||
{
|
||||
struct page *page;
|
||||
int i;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
page = virt_to_page( address );
|
||||
|
||||
for ( i = 0 ; i <= ATI_PCIGART_TABLE_PAGES ; i++, page++ ) {
|
||||
atomic_dec( &page->count );
|
||||
ClearPageReserved( page );
|
||||
}
|
||||
|
||||
free_pages( address, ATI_PCIGART_TABLE_ORDER );
|
||||
}
|
||||
|
||||
int DRM(ati_pcigart_init)( drm_device_t *dev,
|
||||
unsigned long *addr,
|
||||
dma_addr_t *bus_addr)
|
||||
{
|
||||
drm_sg_mem_t *entry = dev->sg;
|
||||
unsigned long address = 0;
|
||||
unsigned long pages;
|
||||
u32 *pci_gart, page_base, bus_address = 0;
|
||||
int i, j, ret = 0;
|
||||
|
||||
if ( !entry ) {
|
||||
DRM_ERROR( "no scatter/gather memory!\n" );
|
||||
goto done;
|
||||
}
|
||||
|
||||
address = DRM(ati_alloc_pcigart_table)();
|
||||
if ( !address ) {
|
||||
DRM_ERROR( "cannot allocate PCI GART page!\n" );
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ( !dev->pdev ) {
|
||||
DRM_ERROR( "PCI device unknown!\n" );
|
||||
goto done;
|
||||
}
|
||||
|
||||
bus_address = pci_map_single(dev->pdev, (void *)address,
|
||||
ATI_PCIGART_TABLE_PAGES * PAGE_SIZE,
|
||||
PCI_DMA_TODEVICE);
|
||||
if (bus_address == 0) {
|
||||
DRM_ERROR( "unable to map PCIGART pages!\n" );
|
||||
DRM(ati_free_pcigart_table)( address );
|
||||
address = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
pci_gart = (u32 *)address;
|
||||
|
||||
pages = ( entry->pages <= ATI_MAX_PCIGART_PAGES )
|
||||
? entry->pages : ATI_MAX_PCIGART_PAGES;
|
||||
|
||||
memset( pci_gart, 0, ATI_MAX_PCIGART_PAGES * sizeof(u32) );
|
||||
|
||||
for ( i = 0 ; i < pages ; i++ ) {
|
||||
/* we need to support large memory configurations */
|
||||
entry->busaddr[i] = pci_map_single(dev->pdev,
|
||||
page_address( entry->pagelist[i] ),
|
||||
PAGE_SIZE,
|
||||
PCI_DMA_TODEVICE);
|
||||
if (entry->busaddr[i] == 0) {
|
||||
DRM_ERROR( "unable to map PCIGART pages!\n" );
|
||||
DRM(ati_pcigart_cleanup)( dev, address, bus_address );
|
||||
address = 0;
|
||||
bus_address = 0;
|
||||
goto done;
|
||||
}
|
||||
page_base = (u32) entry->busaddr[i];
|
||||
|
||||
for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
|
||||
*pci_gart++ = cpu_to_le32( page_base );
|
||||
page_base += ATI_PCIGART_PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
asm volatile ( "wbinvd" ::: "memory" );
|
||||
#else
|
||||
mb();
|
||||
#endif
|
||||
|
||||
done:
|
||||
*addr = address;
|
||||
*bus_addr = bus_address;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DRM(ati_pcigart_cleanup)( drm_device_t *dev,
|
||||
unsigned long addr,
|
||||
dma_addr_t bus_addr)
|
||||
{
|
||||
drm_sg_mem_t *entry = dev->sg;
|
||||
unsigned long pages;
|
||||
int i;
|
||||
|
||||
/* we need to support large memory configurations */
|
||||
if ( !entry ) {
|
||||
DRM_ERROR( "no scatter/gather memory!\n" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( bus_addr ) {
|
||||
pci_unmap_single(dev->pdev, bus_addr,
|
||||
ATI_PCIGART_TABLE_PAGES * PAGE_SIZE,
|
||||
PCI_DMA_TODEVICE);
|
||||
|
||||
pages = ( entry->pages <= ATI_MAX_PCIGART_PAGES )
|
||||
? entry->pages : ATI_MAX_PCIGART_PAGES;
|
||||
|
||||
for ( i = 0 ; i < pages ; i++ ) {
|
||||
if ( !entry->busaddr[i] ) break;
|
||||
pci_unmap_single(dev->pdev, entry->busaddr[i],
|
||||
PAGE_SIZE, PCI_DMA_TODEVICE);
|
||||
}
|
||||
}
|
||||
|
||||
if ( addr ) {
|
||||
DRM(ati_free_pcigart_table)( addr );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
166
bsd/drm_auth.h
Normal file
166
bsd/drm_auth.h
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
/* drm_auth.h -- IOCTLs for authentication -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
static int DRM(hash_magic)(drm_magic_t magic)
|
||||
{
|
||||
return magic & (DRM_HASH_SIZE-1);
|
||||
}
|
||||
|
||||
static drm_file_t *DRM(find_file)(drm_device_t *dev, drm_magic_t magic)
|
||||
{
|
||||
drm_file_t *retval = NULL;
|
||||
drm_magic_entry_t *pt;
|
||||
int hash = DRM(hash_magic)(magic);
|
||||
|
||||
DRM_OS_LOCK;
|
||||
for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
|
||||
if (pt->magic == magic) {
|
||||
retval = pt->priv;
|
||||
break;
|
||||
}
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
return retval;
|
||||
}
|
||||
|
||||
int DRM(add_magic)(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
|
||||
{
|
||||
int hash;
|
||||
drm_magic_entry_t *entry;
|
||||
|
||||
DRM_DEBUG("%d\n", magic);
|
||||
|
||||
hash = DRM(hash_magic)(magic);
|
||||
entry = (drm_magic_entry_t*) DRM(alloc)(sizeof(*entry), DRM_MEM_MAGIC);
|
||||
if (!entry) DRM_OS_RETURN(ENOMEM);
|
||||
entry->magic = magic;
|
||||
entry->priv = priv;
|
||||
entry->next = NULL;
|
||||
|
||||
DRM_OS_LOCK;
|
||||
if (dev->magiclist[hash].tail) {
|
||||
dev->magiclist[hash].tail->next = entry;
|
||||
dev->magiclist[hash].tail = entry;
|
||||
} else {
|
||||
dev->magiclist[hash].head = entry;
|
||||
dev->magiclist[hash].tail = entry;
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic)
|
||||
{
|
||||
drm_magic_entry_t *prev = NULL;
|
||||
drm_magic_entry_t *pt;
|
||||
int hash;
|
||||
|
||||
DRM_DEBUG("%d\n", magic);
|
||||
hash = DRM(hash_magic)(magic);
|
||||
|
||||
DRM_OS_LOCK;
|
||||
for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) {
|
||||
if (pt->magic == magic) {
|
||||
if (dev->magiclist[hash].head == pt) {
|
||||
dev->magiclist[hash].head = pt->next;
|
||||
}
|
||||
if (dev->magiclist[hash].tail == pt) {
|
||||
dev->magiclist[hash].tail = prev;
|
||||
}
|
||||
if (prev) {
|
||||
prev->next = pt->next;
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
DRM(free)(pt, sizeof(*pt), DRM_MEM_MAGIC);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
DRM(free)(pt, sizeof(*pt), DRM_MEM_MAGIC);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
int DRM(getmagic)(DRM_OS_IOCTL)
|
||||
{
|
||||
static drm_magic_t sequence = 0;
|
||||
drm_auth_t auth;
|
||||
static DRM_OS_SPINTYPE lock;
|
||||
static int first = 1;
|
||||
DRM_OS_DEVICE;
|
||||
DRM_OS_PRIV;
|
||||
|
||||
if (first) {
|
||||
DRM_OS_SPININIT(lock, "drm getmagic");
|
||||
first = 0;
|
||||
}
|
||||
|
||||
/* Find unique magic */
|
||||
if (priv->magic) {
|
||||
auth.magic = priv->magic;
|
||||
} else {
|
||||
do {
|
||||
DRM_OS_SPINLOCK(&lock);
|
||||
if (!sequence) ++sequence; /* reserve 0 */
|
||||
auth.magic = sequence++;
|
||||
DRM_OS_SPINUNLOCK(&lock);
|
||||
} while (DRM(find_file)(dev, auth.magic));
|
||||
priv->magic = auth.magic;
|
||||
DRM(add_magic)(dev, priv, auth.magic);
|
||||
}
|
||||
|
||||
DRM_DEBUG("%u\n", auth.magic);
|
||||
|
||||
DRM_OS_KRNTOUSR((drm_auth_t *)data, auth, sizeof(auth));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(authmagic)(DRM_OS_IOCTL)
|
||||
{
|
||||
drm_auth_t auth;
|
||||
drm_file_t *file;
|
||||
DRM_OS_DEVICE;
|
||||
|
||||
DRM_OS_KRNFROMUSR(auth, (drm_auth_t *)data, sizeof(auth));
|
||||
|
||||
DRM_DEBUG("%u\n", auth.magic);
|
||||
if ((file = DRM(find_file)(dev, auth.magic))) {
|
||||
file->authenticated = 1;
|
||||
DRM(remove_magic)(dev, auth.magic);
|
||||
return 0;
|
||||
}
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
1092
bsd/drm_bufs.h
Normal file
1092
bsd/drm_bufs.h
Normal file
File diff suppressed because it is too large
Load diff
730
bsd/drm_context.h
Normal file
730
bsd/drm_context.h
Normal file
|
|
@ -0,0 +1,730 @@
|
|||
/* drm_context.h -- IOCTLs for generic contexts -*- linux-c -*-
|
||||
* Created: Fri Nov 24 18:31:37 2000 by gareth@valinux.com
|
||||
*
|
||||
* Copyright 1999, 2000 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
#if __HAVE_CTX_BITMAP
|
||||
|
||||
/* ================================================================
|
||||
* Context bitmap support
|
||||
*/
|
||||
|
||||
void DRM(ctxbitmap_free)( drm_device_t *dev, int ctx_handle )
|
||||
{
|
||||
if ( ctx_handle < 0 ) goto failed;
|
||||
if ( !dev->ctx_bitmap ) goto failed;
|
||||
|
||||
if ( ctx_handle < DRM_MAX_CTXBITMAP ) {
|
||||
DRM_OS_LOCK;
|
||||
clear_bit( ctx_handle, dev->ctx_bitmap );
|
||||
dev->context_sareas[ctx_handle] = NULL;
|
||||
DRM_OS_UNLOCK;
|
||||
return;
|
||||
}
|
||||
failed:
|
||||
DRM_ERROR( "Attempt to free invalid context handle: %d\n",
|
||||
ctx_handle );
|
||||
return;
|
||||
}
|
||||
|
||||
int DRM(ctxbitmap_next)( drm_device_t *dev )
|
||||
{
|
||||
int bit;
|
||||
|
||||
if(!dev->ctx_bitmap) return -1;
|
||||
|
||||
DRM_OS_LOCK;
|
||||
bit = find_first_zero_bit( dev->ctx_bitmap, DRM_MAX_CTXBITMAP );
|
||||
if ( bit < DRM_MAX_CTXBITMAP ) {
|
||||
set_bit( bit, dev->ctx_bitmap );
|
||||
DRM_DEBUG( "drm_ctxbitmap_next bit : %d\n", bit );
|
||||
if((bit+1) > dev->max_context) {
|
||||
dev->max_context = (bit+1);
|
||||
if(dev->context_sareas) {
|
||||
drm_map_t **ctx_sareas;
|
||||
|
||||
ctx_sareas = DRM(realloc)(dev->context_sareas,
|
||||
(dev->max_context - 1) *
|
||||
sizeof(*dev->context_sareas),
|
||||
dev->max_context *
|
||||
sizeof(*dev->context_sareas),
|
||||
DRM_MEM_MAPS);
|
||||
if(!ctx_sareas) {
|
||||
clear_bit(bit, dev->ctx_bitmap);
|
||||
DRM_OS_UNLOCK;
|
||||
return -1;
|
||||
}
|
||||
dev->context_sareas = ctx_sareas;
|
||||
dev->context_sareas[bit] = NULL;
|
||||
} else {
|
||||
/* max_context == 1 at this point */
|
||||
dev->context_sareas = DRM(alloc)(
|
||||
dev->max_context *
|
||||
sizeof(*dev->context_sareas),
|
||||
DRM_MEM_MAPS);
|
||||
if(!dev->context_sareas) {
|
||||
clear_bit(bit, dev->ctx_bitmap);
|
||||
DRM_OS_UNLOCK;
|
||||
return -1;
|
||||
}
|
||||
dev->context_sareas[bit] = NULL;
|
||||
}
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
return bit;
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int DRM(ctxbitmap_init)( drm_device_t *dev )
|
||||
{
|
||||
int i;
|
||||
int temp;
|
||||
|
||||
DRM_OS_LOCK;
|
||||
dev->ctx_bitmap = (unsigned long *) DRM(alloc)( PAGE_SIZE,
|
||||
DRM_MEM_CTXBITMAP );
|
||||
if ( dev->ctx_bitmap == NULL ) {
|
||||
DRM_OS_UNLOCK;
|
||||
DRM_OS_RETURN(ENOMEM);
|
||||
}
|
||||
memset( (void *)dev->ctx_bitmap, 0, PAGE_SIZE );
|
||||
dev->context_sareas = NULL;
|
||||
dev->max_context = -1;
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
|
||||
temp = DRM(ctxbitmap_next)( dev );
|
||||
DRM_DEBUG( "drm_ctxbitmap_init : %d\n", temp );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DRM(ctxbitmap_cleanup)( drm_device_t *dev )
|
||||
{
|
||||
DRM_OS_LOCK;
|
||||
if( dev->context_sareas ) DRM(free)( dev->context_sareas,
|
||||
sizeof(*dev->context_sareas) *
|
||||
dev->max_context,
|
||||
DRM_MEM_MAPS );
|
||||
DRM(free)( (void *)dev->ctx_bitmap, PAGE_SIZE, DRM_MEM_CTXBITMAP );
|
||||
DRM_OS_UNLOCK;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
* Per Context SAREA Support
|
||||
*/
|
||||
|
||||
int DRM(getsareactx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_priv_map_t request;
|
||||
drm_map_t *map;
|
||||
|
||||
DRM_OS_KRNFROMUSR( request, (drm_ctx_priv_map_t *)data,
|
||||
sizeof(request) );
|
||||
|
||||
DRM_OS_LOCK;
|
||||
if (dev->max_context < 0 || request.ctx_id >= (unsigned) dev->max_context) {
|
||||
DRM_OS_UNLOCK;
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
map = dev->context_sareas[request.ctx_id];
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
request.handle = map->handle;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_priv_map_t *)data, request, sizeof(request) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(setsareactx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_priv_map_t request;
|
||||
drm_map_t *map = NULL;
|
||||
drm_map_list_entry_t *list;
|
||||
|
||||
DRM_OS_KRNFROMUSR( request, (drm_ctx_priv_map_t *)data,
|
||||
sizeof(request) );
|
||||
|
||||
DRM_OS_LOCK;
|
||||
TAILQ_FOREACH(list, dev->maplist, link) {
|
||||
map=list->map;
|
||||
if(map->handle == request.handle)
|
||||
goto found;
|
||||
}
|
||||
|
||||
bad:
|
||||
DRM_OS_UNLOCK;
|
||||
return -EINVAL;
|
||||
|
||||
found:
|
||||
map = list->map;
|
||||
if (!map) goto bad;
|
||||
if (dev->max_context < 0)
|
||||
goto bad;
|
||||
if (request.ctx_id >= (unsigned) dev->max_context)
|
||||
goto bad;
|
||||
dev->context_sareas[request.ctx_id] = map;
|
||||
DRM_OS_UNLOCK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
* The actual DRM context handling routines
|
||||
*/
|
||||
|
||||
int DRM(context_switch)( drm_device_t *dev, int old, int new )
|
||||
{
|
||||
char buf[64];
|
||||
|
||||
if ( test_and_set_bit( 0, &dev->context_flag ) ) {
|
||||
DRM_ERROR( "Reentering -- FIXME\n" );
|
||||
DRM_OS_RETURN(EBUSY);
|
||||
}
|
||||
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
dev->ctx_start = get_cycles();
|
||||
#endif
|
||||
|
||||
DRM_DEBUG( "Context switch from %d to %d\n", old, new );
|
||||
|
||||
if ( new == dev->last_context ) {
|
||||
clear_bit( 0, &dev->context_flag );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( DRM(flags) & DRM_FLAG_NOCTX ) {
|
||||
DRM(context_switch_complete)( dev, new );
|
||||
} else {
|
||||
sprintf( buf, "C %d %d\n", old, new );
|
||||
DRM(write_string)( dev, buf );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(context_switch_complete)( drm_device_t *dev, int new )
|
||||
{
|
||||
dev->last_context = new; /* PRE/POST: This is the _only_ writer. */
|
||||
dev->last_switch = jiffies;
|
||||
|
||||
if ( !_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) ) {
|
||||
DRM_ERROR( "Lock isn't held after context switch\n" );
|
||||
}
|
||||
|
||||
/* If a context switch is ever initiated
|
||||
when the kernel holds the lock, release
|
||||
that lock here. */
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
atomic_inc( &dev->histo.ctx[DRM(histogram_slot)(get_cycles()
|
||||
- dev->ctx_start)] );
|
||||
|
||||
#endif
|
||||
clear_bit( 0, &dev->context_flag );
|
||||
DRM_OS_WAKEUP( &dev->context_wait );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(resctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_ctx_res_t res;
|
||||
drm_ctx_t ctx;
|
||||
int i;
|
||||
|
||||
DRM_OS_KRNFROMUSR( res, (drm_ctx_res_t *)data, sizeof(res) );
|
||||
|
||||
if ( res.count >= DRM_RESERVED_CONTEXTS ) {
|
||||
memset( &ctx, 0, sizeof(ctx) );
|
||||
for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
|
||||
ctx.handle = i;
|
||||
if ( DRM_OS_COPYTOUSR( &res.contexts[i],
|
||||
&i, sizeof(i) ) )
|
||||
DRM_OS_RETURN(EFAULT);
|
||||
}
|
||||
}
|
||||
res.count = DRM_RESERVED_CONTEXTS;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_res_t *)data, res, sizeof(res) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(addctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
ctx.handle = DRM(ctxbitmap_next)( dev );
|
||||
if ( ctx.handle == DRM_KERNEL_CONTEXT ) {
|
||||
/* Skip kernel's context and get a new one. */
|
||||
ctx.handle = DRM(ctxbitmap_next)( dev );
|
||||
}
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
if ( ctx.handle == -1 ) {
|
||||
DRM_DEBUG( "Not enough free contexts.\n" );
|
||||
/* Should this return -EBUSY instead? */
|
||||
DRM_OS_RETURN(ENOMEM);
|
||||
}
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_t *)data, ctx, sizeof(ctx) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(modctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
/* This does nothing */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(getctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
/* This is 0, because we don't handle any context flags */
|
||||
ctx.flags = 0;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_t *)data, ctx, sizeof(ctx) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(switchctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
return DRM(context_switch)( dev, dev->last_context, ctx.handle );
|
||||
}
|
||||
|
||||
int DRM(newctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
DRM(context_switch_complete)( dev, ctx.handle );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(rmctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
if ( ctx.handle != DRM_KERNEL_CONTEXT ) {
|
||||
DRM(ctxbitmap_free)( dev, ctx.handle );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#else /* __HAVE_CTX_BITMAP */
|
||||
|
||||
/* ================================================================
|
||||
* Old-style context support
|
||||
*/
|
||||
|
||||
|
||||
int DRM(context_switch)(drm_device_t *dev, int old, int new)
|
||||
{
|
||||
char buf[64];
|
||||
drm_queue_t *q;
|
||||
|
||||
#if 0
|
||||
atomic_inc(&dev->total_ctx);
|
||||
#endif
|
||||
|
||||
if (test_and_set_bit(0, &dev->context_flag)) {
|
||||
DRM_ERROR("Reentering -- FIXME\n");
|
||||
DRM_OS_RETURN(EBUSY);
|
||||
}
|
||||
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
dev->ctx_start = get_cycles();
|
||||
#endif
|
||||
|
||||
DRM_DEBUG("Context switch from %d to %d\n", old, new);
|
||||
|
||||
if (new >= dev->queue_count) {
|
||||
clear_bit(0, &dev->context_flag);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
if (new == dev->last_context) {
|
||||
clear_bit(0, &dev->context_flag);
|
||||
return 0;
|
||||
}
|
||||
|
||||
q = dev->queuelist[new];
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) == 1) {
|
||||
atomic_dec(&q->use_count);
|
||||
clear_bit(0, &dev->context_flag);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
if (DRM(flags) & DRM_FLAG_NOCTX) {
|
||||
DRM(context_switch_complete)(dev, new);
|
||||
} else {
|
||||
sprintf(buf, "C %d %d\n", old, new);
|
||||
DRM(write_string)(dev, buf);
|
||||
}
|
||||
|
||||
atomic_dec(&q->use_count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(context_switch_complete)(drm_device_t *dev, int new)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
dev->last_context = new; /* PRE/POST: This is the _only_ writer. */
|
||||
dev->last_switch = jiffies;
|
||||
|
||||
if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) {
|
||||
DRM_ERROR("Lock isn't held after context switch\n");
|
||||
}
|
||||
|
||||
if (!dma || !(dma->next_buffer && dma->next_buffer->while_locked)) {
|
||||
if (DRM(lock_free)(dev, &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT)) {
|
||||
DRM_ERROR("Cannot free lock\n");
|
||||
}
|
||||
}
|
||||
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
atomic_inc(&dev->histo.ctx[DRM(histogram_slot)(get_cycles()
|
||||
- dev->ctx_start)]);
|
||||
|
||||
#endif
|
||||
clear_bit(0, &dev->context_flag);
|
||||
DRM_OS_WAKEUP_INT(&dev->context_wait);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DRM(init_queue)(drm_device_t *dev, drm_queue_t *q, drm_ctx_t *ctx)
|
||||
{
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
if (atomic_read(&q->use_count) != 1
|
||||
|| atomic_read(&q->finalization)
|
||||
|| atomic_read(&q->block_count)) {
|
||||
DRM_ERROR("New queue is already in use: u%ld f%ld b%ld\n",
|
||||
(unsigned long)atomic_read(&q->use_count),
|
||||
(unsigned long)atomic_read(&q->finalization),
|
||||
(unsigned long)atomic_read(&q->block_count));
|
||||
}
|
||||
|
||||
atomic_set(&q->finalization, 0);
|
||||
atomic_set(&q->block_count, 0);
|
||||
atomic_set(&q->block_read, 0);
|
||||
atomic_set(&q->block_write, 0);
|
||||
atomic_set(&q->total_queued, 0);
|
||||
atomic_set(&q->total_flushed, 0);
|
||||
atomic_set(&q->total_locks, 0);
|
||||
|
||||
q->write_queue = 0;
|
||||
q->read_queue = 0;
|
||||
q->flush_queue = 0;
|
||||
|
||||
q->flags = ctx->flags;
|
||||
|
||||
DRM(waitlist_create)(&q->waitlist, dev->dma->buf_count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* drm_alloc_queue:
|
||||
PRE: 1) dev->queuelist[0..dev->queue_count] is allocated and will not
|
||||
disappear (so all deallocation must be done after IOCTLs are off)
|
||||
2) dev->queue_count < dev->queue_slots
|
||||
3) dev->queuelist[i].use_count == 0 and
|
||||
dev->queuelist[i].finalization == 0 if i not in use
|
||||
POST: 1) dev->queuelist[i].use_count == 1
|
||||
2) dev->queue_count < dev->queue_slots */
|
||||
|
||||
static int DRM(alloc_queue)(drm_device_t *dev)
|
||||
{
|
||||
int i;
|
||||
drm_queue_t *queue;
|
||||
int oldslots;
|
||||
int newslots;
|
||||
/* Check for a free queue */
|
||||
for (i = 0; i < dev->queue_count; i++) {
|
||||
atomic_inc(&dev->queuelist[i]->use_count);
|
||||
if (atomic_read(&dev->queuelist[i]->use_count) == 1
|
||||
&& !atomic_read(&dev->queuelist[i]->finalization)) {
|
||||
DRM_DEBUG("%d (free)\n", i);
|
||||
return i;
|
||||
}
|
||||
atomic_dec(&dev->queuelist[i]->use_count);
|
||||
}
|
||||
/* Allocate a new queue */
|
||||
DRM_OS_LOCK;
|
||||
|
||||
queue = gamma_alloc(sizeof(*queue), DRM_MEM_QUEUES);
|
||||
memset(queue, 0, sizeof(*queue));
|
||||
atomic_set(&queue->use_count, 1);
|
||||
|
||||
++dev->queue_count;
|
||||
if (dev->queue_count >= dev->queue_slots) {
|
||||
oldslots = dev->queue_slots * sizeof(*dev->queuelist);
|
||||
if (!dev->queue_slots) dev->queue_slots = 1;
|
||||
dev->queue_slots *= 2;
|
||||
newslots = dev->queue_slots * sizeof(*dev->queuelist);
|
||||
|
||||
dev->queuelist = DRM(realloc)(dev->queuelist,
|
||||
oldslots,
|
||||
newslots,
|
||||
DRM_MEM_QUEUES);
|
||||
if (!dev->queuelist) {
|
||||
DRM_OS_UNLOCK;
|
||||
DRM_DEBUG("out of memory\n");
|
||||
DRM_OS_RETURN(ENOMEM);
|
||||
}
|
||||
}
|
||||
dev->queuelist[dev->queue_count-1] = queue;
|
||||
|
||||
DRM_OS_UNLOCK;
|
||||
DRM_DEBUG("%d (new)\n", dev->queue_count - 1);
|
||||
return dev->queue_count - 1;
|
||||
}
|
||||
|
||||
int DRM(resctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_ctx_res_t res;
|
||||
drm_ctx_t ctx;
|
||||
int i;
|
||||
|
||||
DRM_DEBUG("%d\n", DRM_RESERVED_CONTEXTS);
|
||||
|
||||
DRM_OS_KRNFROMUSR( res, (drm_ctx_res_t *)data, sizeof(res) );
|
||||
|
||||
if (res.count >= DRM_RESERVED_CONTEXTS) {
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
|
||||
ctx.handle = i;
|
||||
if (DRM_OS_COPYTOUSR(&res.contexts[i],
|
||||
&i,
|
||||
sizeof(i)))
|
||||
DRM_OS_RETURN(EFAULT);
|
||||
}
|
||||
}
|
||||
res.count = DRM_RESERVED_CONTEXTS;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_res_t *)data, res, sizeof(res) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(addctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
if ((ctx.handle = DRM(alloc_queue)(dev)) == DRM_KERNEL_CONTEXT) {
|
||||
/* Init kernel's context and get a new one. */
|
||||
DRM(init_queue)(dev, dev->queuelist[ctx.handle], &ctx);
|
||||
ctx.handle = DRM(alloc_queue)(dev);
|
||||
}
|
||||
DRM(init_queue)(dev, dev->queuelist[ctx.handle], &ctx);
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_t *)data, ctx, sizeof(ctx) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(modctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
drm_queue_t *q;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
|
||||
if (ctx.handle < 0 || ctx.handle >= dev->queue_count)
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
q = dev->queuelist[ctx.handle];
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) == 1) {
|
||||
/* No longer in use */
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
if (DRM_BUFCOUNT(&q->waitlist)) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_OS_RETURN(EBUSY);
|
||||
}
|
||||
|
||||
q->flags = ctx.flags;
|
||||
|
||||
atomic_dec(&q->use_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(getctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
drm_queue_t *q;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
|
||||
if (ctx.handle >= dev->queue_count)
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
q = dev->queuelist[ctx.handle];
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) == 1) {
|
||||
/* No longer in use */
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
ctx.flags = q->flags;
|
||||
atomic_dec(&q->use_count);
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_ctx_t *)data, ctx, sizeof(ctx) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(switchctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
return DRM(context_switch)(dev, dev->last_context, ctx.handle);
|
||||
}
|
||||
|
||||
int DRM(newctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
DRM(context_switch_complete)(dev, ctx.handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(rmctx)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_ctx_t ctx;
|
||||
drm_queue_t *q;
|
||||
drm_buf_t *buf;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctx, (drm_ctx_t *)data, sizeof(ctx) );
|
||||
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
|
||||
if (ctx.handle >= dev->queue_count) DRM_OS_RETURN(EINVAL);
|
||||
q = dev->queuelist[ctx.handle];
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) == 1) {
|
||||
/* No longer in use */
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
atomic_inc(&q->finalization); /* Mark queue in finalization state */
|
||||
atomic_sub(2, &q->use_count); /* Mark queue as unused (pending
|
||||
finalization) */
|
||||
|
||||
while (test_and_set_bit(0, &dev->interrupt_flag)) {
|
||||
static int never;
|
||||
int retcode;
|
||||
retcode = tsleep(&never, PZERO|PCATCH, "never", 1);
|
||||
if (retcode)
|
||||
return retcode;
|
||||
}
|
||||
/* Remove queued buffers */
|
||||
while ((buf = DRM(waitlist_get)(&q->waitlist))) {
|
||||
DRM(free_buffer)(dev, buf);
|
||||
}
|
||||
clear_bit(0, &dev->interrupt_flag);
|
||||
|
||||
/* Wakeup blocked processes */
|
||||
wakeup( &q->block_read );
|
||||
wakeup( &q->block_write );
|
||||
DRM_OS_WAKEUP_INT( &q->flush_queue );
|
||||
/* Finalization over. Queue is made
|
||||
available when both use_count and
|
||||
finalization become 0, which won't
|
||||
happen until all the waiting processes
|
||||
stop waiting. */
|
||||
atomic_dec(&q->finalization);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __HAVE_CTX_BITMAP */
|
||||
605
bsd/drm_dma.h
Normal file
605
bsd/drm_dma.h
Normal file
|
|
@ -0,0 +1,605 @@
|
|||
/* drm_dma.c -- DMA IOCTL and function support -*- linux-c -*-
|
||||
* Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999, 2000 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/rman.h>
|
||||
|
||||
#include "drmP.h"
|
||||
|
||||
#ifndef __HAVE_DMA_WAITQUEUE
|
||||
#define __HAVE_DMA_WAITQUEUE 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_RECLAIM
|
||||
#define __HAVE_DMA_RECLAIM 0
|
||||
#endif
|
||||
#ifndef __HAVE_SHARED_IRQ
|
||||
#define __HAVE_SHARED_IRQ 0
|
||||
#endif
|
||||
|
||||
#if __HAVE_SHARED_IRQ
|
||||
#define DRM_IRQ_TYPE SA_SHIRQ
|
||||
#else
|
||||
#define DRM_IRQ_TYPE 0
|
||||
#endif
|
||||
|
||||
#if __HAVE_DMA
|
||||
|
||||
int DRM(dma_setup)( drm_device_t *dev )
|
||||
{
|
||||
int i;
|
||||
|
||||
dev->dma = DRM(alloc)( sizeof(*dev->dma), DRM_MEM_DRIVER );
|
||||
if ( !dev->dma )
|
||||
DRM_OS_RETURN(ENOMEM);
|
||||
|
||||
memset( dev->dma, 0, sizeof(*dev->dma) );
|
||||
|
||||
for ( i = 0 ; i <= DRM_MAX_ORDER ; i++ )
|
||||
memset(&dev->dma->bufs[i], 0, sizeof(dev->dma->bufs[0]));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DRM(dma_takedown)(drm_device_t *dev)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int i, j;
|
||||
|
||||
if (!dma) return;
|
||||
|
||||
/* Clear dma buffers */
|
||||
for (i = 0; i <= DRM_MAX_ORDER; i++) {
|
||||
if (dma->bufs[i].seg_count) {
|
||||
DRM_DEBUG("order %d: buf_count = %d,"
|
||||
" seg_count = %d\n",
|
||||
i,
|
||||
dma->bufs[i].buf_count,
|
||||
dma->bufs[i].seg_count);
|
||||
for (j = 0; j < dma->bufs[i].seg_count; j++) {
|
||||
DRM(free_pages)(dma->bufs[i].seglist[j],
|
||||
dma->bufs[i].page_order,
|
||||
DRM_MEM_DMA);
|
||||
}
|
||||
DRM(free)(dma->bufs[i].seglist,
|
||||
dma->bufs[i].seg_count
|
||||
* sizeof(*dma->bufs[0].seglist),
|
||||
DRM_MEM_SEGS);
|
||||
}
|
||||
if(dma->bufs[i].buf_count) {
|
||||
for(j = 0; j < dma->bufs[i].buf_count; j++) {
|
||||
if(dma->bufs[i].buflist[j].dev_private) {
|
||||
DRM(free)(dma->bufs[i].buflist[j].dev_private,
|
||||
dma->bufs[i].buflist[j].dev_priv_size,
|
||||
DRM_MEM_BUFS);
|
||||
}
|
||||
}
|
||||
DRM(free)(dma->bufs[i].buflist,
|
||||
dma->bufs[i].buf_count *
|
||||
sizeof(*dma->bufs[0].buflist),
|
||||
DRM_MEM_BUFS);
|
||||
#if __HAVE_DMA_FREELIST
|
||||
DRM(freelist_destroy)(&dma->bufs[i].freelist);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (dma->buflist) {
|
||||
DRM(free)(dma->buflist,
|
||||
dma->buf_count * sizeof(*dma->buflist),
|
||||
DRM_MEM_BUFS);
|
||||
}
|
||||
|
||||
if (dma->pagelist) {
|
||||
DRM(free)(dma->pagelist,
|
||||
dma->page_count * sizeof(*dma->pagelist),
|
||||
DRM_MEM_PAGES);
|
||||
}
|
||||
DRM(free)(dev->dma, sizeof(*dev->dma), DRM_MEM_DRIVER);
|
||||
dev->dma = NULL;
|
||||
}
|
||||
|
||||
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
/* This is slow, but is useful for debugging. */
|
||||
int DRM(histogram_slot)(unsigned long count)
|
||||
{
|
||||
int value = DRM_DMA_HISTOGRAM_INITIAL;
|
||||
int slot;
|
||||
|
||||
for (slot = 0;
|
||||
slot < DRM_DMA_HISTOGRAM_SLOTS;
|
||||
++slot, value = DRM_DMA_HISTOGRAM_NEXT(value)) {
|
||||
if (count < value) return slot;
|
||||
}
|
||||
return DRM_DMA_HISTOGRAM_SLOTS - 1;
|
||||
}
|
||||
|
||||
void DRM(histogram_compute)(drm_device_t *dev, drm_buf_t *buf)
|
||||
{
|
||||
cycles_t queued_to_dispatched;
|
||||
cycles_t dispatched_to_completed;
|
||||
cycles_t completed_to_freed;
|
||||
int q2d, d2c, c2f, q2c, q2f;
|
||||
|
||||
if (buf->time_queued) {
|
||||
queued_to_dispatched = (buf->time_dispatched
|
||||
- buf->time_queued);
|
||||
dispatched_to_completed = (buf->time_completed
|
||||
- buf->time_dispatched);
|
||||
completed_to_freed = (buf->time_freed
|
||||
- buf->time_completed);
|
||||
|
||||
q2d = DRM(histogram_slot)(queued_to_dispatched);
|
||||
d2c = DRM(histogram_slot)(dispatched_to_completed);
|
||||
c2f = DRM(histogram_slot)(completed_to_freed);
|
||||
|
||||
q2c = DRM(histogram_slot)(queued_to_dispatched
|
||||
+ dispatched_to_completed);
|
||||
q2f = DRM(histogram_slot)(queued_to_dispatched
|
||||
+ dispatched_to_completed
|
||||
+ completed_to_freed);
|
||||
|
||||
atomic_inc(&dev->histo.total);
|
||||
atomic_inc(&dev->histo.queued_to_dispatched[q2d]);
|
||||
atomic_inc(&dev->histo.dispatched_to_completed[d2c]);
|
||||
atomic_inc(&dev->histo.completed_to_freed[c2f]);
|
||||
|
||||
atomic_inc(&dev->histo.queued_to_completed[q2c]);
|
||||
atomic_inc(&dev->histo.queued_to_freed[q2f]);
|
||||
|
||||
}
|
||||
buf->time_queued = 0;
|
||||
buf->time_dispatched = 0;
|
||||
buf->time_completed = 0;
|
||||
buf->time_freed = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf)
|
||||
{
|
||||
if (!buf) return;
|
||||
|
||||
buf->waiting = 0;
|
||||
buf->pending = 0;
|
||||
buf->pid = 0;
|
||||
buf->used = 0;
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
buf->time_completed = get_cycles();
|
||||
#endif
|
||||
|
||||
if ( buf->dma_wait ) {
|
||||
wakeup( &buf->dma_wait );
|
||||
buf->dma_wait = 0;
|
||||
}
|
||||
#if __HAVE_DMA_FREELIST
|
||||
else {
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
/* If processes are waiting, the last one
|
||||
to wake will put the buffer on the free
|
||||
list. If no processes are waiting, we
|
||||
put the buffer on the freelist here. */
|
||||
DRM(freelist_put)(dev, &dma->bufs[buf->order].freelist, buf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !__HAVE_DMA_RECLAIM
|
||||
void DRM(reclaim_buffers)(drm_device_t *dev, pid_t pid)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int i;
|
||||
|
||||
if (!dma) return;
|
||||
for (i = 0; i < dma->buf_count; i++) {
|
||||
if (dma->buflist[i]->pid == pid) {
|
||||
switch (dma->buflist[i]->list) {
|
||||
case DRM_LIST_NONE:
|
||||
DRM(free_buffer)(dev, dma->buflist[i]);
|
||||
break;
|
||||
case DRM_LIST_WAIT:
|
||||
dma->buflist[i]->list = DRM_LIST_RECLAIM;
|
||||
break;
|
||||
default:
|
||||
/* Buffer already on hardware. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* GH: This is a big hack for now...
|
||||
*/
|
||||
#if __HAVE_OLD_DMA
|
||||
|
||||
void DRM(clear_next_buffer)(drm_device_t *dev)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
dma->next_buffer = NULL;
|
||||
if (dma->next_queue && !DRM_BUFCOUNT(&dma->next_queue->waitlist)) {
|
||||
DRM_OS_WAKEUP_INT(&dma->next_queue->flush_queue);
|
||||
}
|
||||
dma->next_queue = NULL;
|
||||
}
|
||||
|
||||
int DRM(select_queue)(drm_device_t *dev, void (*wrapper)(unsigned long))
|
||||
{
|
||||
int i;
|
||||
int candidate = -1;
|
||||
int j = jiffies;
|
||||
|
||||
if (!dev) {
|
||||
DRM_ERROR("No device\n");
|
||||
return -1;
|
||||
}
|
||||
if (!dev->queuelist || !dev->queuelist[DRM_KERNEL_CONTEXT]) {
|
||||
/* This only happens between the time the
|
||||
interrupt is initialized and the time
|
||||
the queues are initialized. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Doing "while locked" DMA? */
|
||||
if (DRM_WAITCOUNT(dev, DRM_KERNEL_CONTEXT)) {
|
||||
return DRM_KERNEL_CONTEXT;
|
||||
}
|
||||
|
||||
/* If there are buffers on the last_context
|
||||
queue, and we have not been executing
|
||||
this context very long, continue to
|
||||
execute this context. */
|
||||
if (dev->last_switch <= j
|
||||
&& dev->last_switch + DRM_TIME_SLICE > j
|
||||
&& DRM_WAITCOUNT(dev, dev->last_context)) {
|
||||
return dev->last_context;
|
||||
}
|
||||
|
||||
/* Otherwise, find a candidate */
|
||||
for (i = dev->last_checked + 1; i < dev->queue_count; i++) {
|
||||
if (DRM_WAITCOUNT(dev, i)) {
|
||||
candidate = dev->last_checked = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (candidate < 0) {
|
||||
for (i = 0; i < dev->queue_count; i++) {
|
||||
if (DRM_WAITCOUNT(dev, i)) {
|
||||
candidate = dev->last_checked = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wrapper
|
||||
&& candidate >= 0
|
||||
&& candidate != dev->last_context
|
||||
&& dev->last_switch <= j
|
||||
&& dev->last_switch + DRM_TIME_SLICE > j) {
|
||||
int s = splclock();
|
||||
if (dev->timer.c_time != dev->last_switch + DRM_TIME_SLICE) {
|
||||
callout_reset(&dev->timer,
|
||||
dev->last_switch + DRM_TIME_SLICE - j,
|
||||
(void (*)(void *))wrapper,
|
||||
dev);
|
||||
}
|
||||
splx(s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return candidate;
|
||||
}
|
||||
|
||||
|
||||
int DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *d)
|
||||
{
|
||||
int i;
|
||||
drm_queue_t *q;
|
||||
drm_buf_t *buf;
|
||||
int idx;
|
||||
int while_locked = 0;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int error;
|
||||
|
||||
DRM_DEBUG("%d\n", d->send_count);
|
||||
|
||||
if (d->flags & _DRM_DMA_WHILE_LOCKED) {
|
||||
int context = dev->lock.hw_lock->lock;
|
||||
|
||||
if (!_DRM_LOCK_IS_HELD(context)) {
|
||||
DRM_ERROR("No lock held during \"while locked\""
|
||||
" request\n");
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
if (d->context != _DRM_LOCKING_CONTEXT(context)
|
||||
&& _DRM_LOCKING_CONTEXT(context) != DRM_KERNEL_CONTEXT) {
|
||||
DRM_ERROR("Lock held by %d while %d makes"
|
||||
" \"while locked\" request\n",
|
||||
_DRM_LOCKING_CONTEXT(context),
|
||||
d->context);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
q = dev->queuelist[DRM_KERNEL_CONTEXT];
|
||||
while_locked = 1;
|
||||
} else {
|
||||
q = dev->queuelist[d->context];
|
||||
}
|
||||
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->block_write)) {
|
||||
atomic_inc(&q->block_count);
|
||||
for (;;) {
|
||||
if (!atomic_read(&q->block_write)) break;
|
||||
error = tsleep(&q->block_write, PZERO|PCATCH,
|
||||
"dmawr", 0);
|
||||
if (error) {
|
||||
atomic_dec(&q->use_count);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
atomic_dec(&q->block_count);
|
||||
}
|
||||
|
||||
for (i = 0; i < d->send_count; i++) {
|
||||
idx = d->send_indices[i];
|
||||
if (idx < 0 || idx >= dma->buf_count) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Index %d (of %d max)\n",
|
||||
d->send_indices[i], dma->buf_count - 1);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
buf = dma->buflist[ idx ];
|
||||
if (buf->pid != DRM_OS_CURRENTPID) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Process %d using buffer owned by %d\n",
|
||||
DRM_OS_CURRENTPID, buf->pid);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
if (buf->list != DRM_LIST_NONE) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Process %d using buffer %d on list %d\n",
|
||||
DRM_OS_CURRENTPID, buf->idx, buf->list);
|
||||
}
|
||||
buf->used = d->send_sizes[i];
|
||||
buf->while_locked = while_locked;
|
||||
buf->context = d->context;
|
||||
if (!buf->used) {
|
||||
DRM_ERROR("Queueing 0 length buffer\n");
|
||||
}
|
||||
if (buf->pending) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Queueing pending buffer:"
|
||||
" buffer %d, offset %d\n",
|
||||
d->send_indices[i], i);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
if (buf->waiting) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Queueing waiting buffer:"
|
||||
" buffer %d, offset %d\n",
|
||||
d->send_indices[i], i);
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
buf->waiting = 1;
|
||||
if (atomic_read(&q->use_count) == 1
|
||||
|| atomic_read(&q->finalization)) {
|
||||
DRM(free_buffer)(dev, buf);
|
||||
} else {
|
||||
DRM(waitlist_put)(&q->waitlist, buf);
|
||||
atomic_inc(&q->total_queued);
|
||||
}
|
||||
}
|
||||
atomic_dec(&q->use_count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DRM(dma_get_buffers_of_order)(drm_device_t *dev, drm_dma_t *d,
|
||||
int order)
|
||||
{
|
||||
int i;
|
||||
drm_buf_t *buf;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
for (i = d->granted_count; i < d->request_count; i++) {
|
||||
buf = DRM(freelist_get)(&dma->bufs[order].freelist,
|
||||
d->flags & _DRM_DMA_WAIT);
|
||||
if (!buf) break;
|
||||
if (buf->pending || buf->waiting) {
|
||||
DRM_ERROR("Free buffer %d in use by %d (w%d, p%d)\n",
|
||||
buf->idx,
|
||||
buf->pid,
|
||||
buf->waiting,
|
||||
buf->pending);
|
||||
}
|
||||
buf->pid = DRM_OS_CURRENTPID;
|
||||
if (DRM_OS_COPYTOUSR(&d->request_indices[i],
|
||||
&buf->idx,
|
||||
sizeof(buf->idx)))
|
||||
DRM_OS_RETURN(EFAULT);
|
||||
|
||||
if (DRM_OS_COPYTOUSR(&d->request_sizes[i],
|
||||
&buf->total,
|
||||
sizeof(buf->total)))
|
||||
DRM_OS_RETURN(EFAULT);
|
||||
|
||||
++d->granted_count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int DRM(dma_get_buffers)(drm_device_t *dev, drm_dma_t *dma)
|
||||
{
|
||||
int order;
|
||||
int retcode = 0;
|
||||
int tmp_order;
|
||||
|
||||
order = DRM(order)(dma->request_size);
|
||||
|
||||
dma->granted_count = 0;
|
||||
retcode = DRM(dma_get_buffers_of_order)(dev, dma, order);
|
||||
|
||||
if (dma->granted_count < dma->request_count
|
||||
&& (dma->flags & _DRM_DMA_SMALLER_OK)) {
|
||||
for (tmp_order = order - 1;
|
||||
!retcode
|
||||
&& dma->granted_count < dma->request_count
|
||||
&& tmp_order >= DRM_MIN_ORDER;
|
||||
--tmp_order) {
|
||||
|
||||
retcode = DRM(dma_get_buffers_of_order)(dev, dma,
|
||||
tmp_order);
|
||||
}
|
||||
}
|
||||
|
||||
if (dma->granted_count < dma->request_count
|
||||
&& (dma->flags & _DRM_DMA_LARGER_OK)) {
|
||||
for (tmp_order = order + 1;
|
||||
!retcode
|
||||
&& dma->granted_count < dma->request_count
|
||||
&& tmp_order <= DRM_MAX_ORDER;
|
||||
++tmp_order) {
|
||||
|
||||
retcode = DRM(dma_get_buffers_of_order)(dev, dma,
|
||||
tmp_order);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __HAVE_OLD_DMA */
|
||||
|
||||
|
||||
#if __HAVE_DMA_IRQ
|
||||
|
||||
int DRM(irq_install)( drm_device_t *dev, int irq )
|
||||
{
|
||||
int rid;
|
||||
int retcode;
|
||||
|
||||
if ( !irq )
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
|
||||
DRM_OS_LOCK;
|
||||
if ( dev->irq ) {
|
||||
DRM_OS_UNLOCK;
|
||||
DRM_OS_RETURN(EBUSY);
|
||||
}
|
||||
dev->irq = irq;
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
|
||||
|
||||
dev->context_flag = 0;
|
||||
dev->interrupt_flag = 0;
|
||||
dev->dma_flag = 0;
|
||||
|
||||
dev->dma->next_buffer = NULL;
|
||||
dev->dma->next_queue = NULL;
|
||||
dev->dma->this_buffer = NULL;
|
||||
|
||||
#if __HAVE_DMA_IRQ_BH
|
||||
TASK_INIT(&dev->task, 0, DRM(dma_immediate_bh), dev);
|
||||
#endif
|
||||
|
||||
/* Before installing handler */
|
||||
DRIVER_PREINSTALL();
|
||||
|
||||
/* Install handler */
|
||||
rid = 0;
|
||||
dev->irqr = bus_alloc_resource(dev->device, SYS_RES_IRQ, &rid,
|
||||
0, ~0, 1, RF_SHAREABLE);
|
||||
if (!dev->irqr)
|
||||
return ENOENT;
|
||||
|
||||
retcode = bus_setup_intr(dev->device, dev->irqr, INTR_TYPE_TTY,
|
||||
DRM(dma_service), dev, &dev->irqh);
|
||||
if ( retcode ) {
|
||||
DRM_OS_LOCK;
|
||||
bus_release_resource(dev->device, SYS_RES_IRQ, 0, dev->irqr);
|
||||
dev->irq = 0;
|
||||
DRM_OS_UNLOCK;
|
||||
return retcode;
|
||||
}
|
||||
|
||||
/* After installing handler */
|
||||
DRIVER_POSTINSTALL();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(irq_uninstall)( drm_device_t *dev )
|
||||
{
|
||||
int irq;
|
||||
|
||||
DRM_OS_LOCK;
|
||||
irq = dev->irq;
|
||||
dev->irq = 0;
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
if ( !irq )
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
|
||||
DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
|
||||
|
||||
DRIVER_UNINSTALL();
|
||||
|
||||
bus_teardown_intr(dev->device, dev->irqr, dev->irqh);
|
||||
bus_release_resource(dev->device, SYS_RES_IRQ, 0, dev->irqr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(control)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_control_t ctl;
|
||||
|
||||
DRM_OS_KRNFROMUSR( ctl, (drm_control_t *) data, sizeof(ctl) );
|
||||
|
||||
switch ( ctl.func ) {
|
||||
case DRM_INST_HANDLER:
|
||||
return DRM(irq_install)( dev, ctl.irq );
|
||||
case DRM_UNINST_HANDLER:
|
||||
return DRM(irq_uninstall)( dev );
|
||||
default:
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __HAVE_DMA_IRQ */
|
||||
|
||||
#endif /* __HAVE_DMA */
|
||||
50
bsd/drm_drawable.h
Normal file
50
bsd/drm_drawable.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/* drm_drawable.h -- IOCTLs for drawables -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
int DRM(adddraw)( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_draw_t draw;
|
||||
|
||||
draw.handle = 0; /* NOOP */
|
||||
DRM_DEBUG("%d\n", draw.handle);
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_draw_t *)data, draw, sizeof(draw) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(rmdraw)( DRM_OS_IOCTL )
|
||||
{
|
||||
return 0; /* NOOP */
|
||||
}
|
||||
1160
bsd/drm_drv.h
Normal file
1160
bsd/drm_drv.h
Normal file
File diff suppressed because it is too large
Load diff
223
bsd/drm_fops.h
Normal file
223
bsd/drm_fops.h
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
/* drm_fops.h -- File operations for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Daryll Strauss <daryll@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
drm_file_t *DRM(find_file_by_proc)(drm_device_t *dev, DRM_OS_STRUCTPROC *p)
|
||||
{
|
||||
#if __FreeBSD_version >= 500021
|
||||
uid_t uid = p->td_proc->p_ucred->cr_svuid;
|
||||
pid_t pid = p->td_proc->p_pid;
|
||||
#else
|
||||
uid_t uid = p->p_cred->p_svuid;
|
||||
pid_t pid = p->p_pid;
|
||||
#endif
|
||||
drm_file_t *priv;
|
||||
|
||||
TAILQ_FOREACH(priv, &dev->files, link)
|
||||
if (priv->pid == pid && priv->uid == uid)
|
||||
return priv;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* DRM(open) is called whenever a process opens /dev/drm. */
|
||||
|
||||
int DRM(open_helper)(dev_t kdev, int flags, int fmt, DRM_OS_STRUCTPROC *p,
|
||||
drm_device_t *dev)
|
||||
{
|
||||
int m = minor(kdev);
|
||||
drm_file_t *priv;
|
||||
|
||||
if (flags & O_EXCL)
|
||||
return EBUSY; /* No exclusive opens */
|
||||
dev->flags = flags;
|
||||
if (!DRM(cpu_valid)())
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
|
||||
DRM_DEBUG("pid = %d, minor = %d\n", DRM_OS_CURRENTPID, m);
|
||||
|
||||
/* FIXME: linux mallocs and bzeros here */
|
||||
priv = (drm_file_t *) DRM(find_file_by_proc)(dev, p);
|
||||
if (priv) {
|
||||
priv->refs++;
|
||||
} else {
|
||||
priv = (drm_file_t *) DRM(alloc)(sizeof(*priv), DRM_MEM_FILES);
|
||||
bzero(priv, sizeof(*priv));
|
||||
#if __FreeBSD_version >= 500000
|
||||
priv->uid = p->td_proc->p_ucred->cr_svuid;
|
||||
priv->pid = p->td_proc->p_pid;
|
||||
#else
|
||||
priv->uid = p->p_cred->p_svuid;
|
||||
priv->pid = p->p_pid;
|
||||
#endif
|
||||
|
||||
priv->refs = 1;
|
||||
priv->minor = m;
|
||||
priv->devXX = dev;
|
||||
priv->ioctl_count = 0;
|
||||
priv->authenticated = !DRM_OS_CHECKSUSER;
|
||||
lockmgr(&dev->dev_lock, LK_EXCLUSIVE, 0, p);
|
||||
TAILQ_INSERT_TAIL(&dev->files, priv, link);
|
||||
lockmgr(&dev->dev_lock, LK_RELEASE, 0, p);
|
||||
}
|
||||
|
||||
kdev->si_drv1 = dev;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* The drm_read and drm_write_string code (especially that which manages
|
||||
the circular buffer), is based on Alessandro Rubini's LINUX DEVICE
|
||||
DRIVERS (Cambridge: O'Reilly, 1998), pages 111-113. */
|
||||
|
||||
ssize_t DRM(read)(dev_t kdev, struct uio *uio, int ioflag)
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
int left;
|
||||
int avail;
|
||||
int send;
|
||||
int cur;
|
||||
int error = 0;
|
||||
|
||||
DRM_DEBUG("%p, %p\n", dev->buf_rp, dev->buf_wp);
|
||||
|
||||
while (dev->buf_rp == dev->buf_wp) {
|
||||
DRM_DEBUG(" sleeping\n");
|
||||
if (dev->flags & FASYNC)
|
||||
return EWOULDBLOCK;
|
||||
error = tsleep(&dev->buf_rp, PZERO|PCATCH, "drmrd", 0);
|
||||
if (error) {
|
||||
DRM_DEBUG(" interrupted\n");
|
||||
return error;
|
||||
}
|
||||
DRM_DEBUG(" awake\n");
|
||||
}
|
||||
|
||||
left = (dev->buf_rp + DRM_BSZ - dev->buf_wp) % DRM_BSZ;
|
||||
avail = DRM_BSZ - left;
|
||||
send = DRM_MIN(avail, uio->uio_resid);
|
||||
|
||||
while (send) {
|
||||
if (dev->buf_wp > dev->buf_rp) {
|
||||
cur = DRM_MIN(send, dev->buf_wp - dev->buf_rp);
|
||||
} else {
|
||||
cur = DRM_MIN(send, dev->buf_end - dev->buf_rp);
|
||||
}
|
||||
error = uiomove(dev->buf_rp, cur, uio);
|
||||
if (error)
|
||||
break;
|
||||
dev->buf_rp += cur;
|
||||
if (dev->buf_rp == dev->buf_end) dev->buf_rp = dev->buf;
|
||||
send -= cur;
|
||||
}
|
||||
|
||||
wakeup(&dev->buf_wp);
|
||||
return error;
|
||||
}
|
||||
|
||||
int DRM(write_string)(drm_device_t *dev, const char *s)
|
||||
{
|
||||
int left = (dev->buf_rp + DRM_BSZ - dev->buf_wp) % DRM_BSZ;
|
||||
int send = strlen(s);
|
||||
int count;
|
||||
|
||||
DRM_DEBUG("%d left, %d to send (%p, %p)\n",
|
||||
left, send, dev->buf_rp, dev->buf_wp);
|
||||
|
||||
if (left == 1 || dev->buf_wp != dev->buf_rp) {
|
||||
DRM_ERROR("Buffer not empty (%d left, wp = %p, rp = %p)\n",
|
||||
left,
|
||||
dev->buf_wp,
|
||||
dev->buf_rp);
|
||||
}
|
||||
|
||||
while (send) {
|
||||
if (dev->buf_wp >= dev->buf_rp) {
|
||||
count = DRM_MIN(send, dev->buf_end - dev->buf_wp);
|
||||
if (count == left) --count; /* Leave a hole */
|
||||
} else {
|
||||
count = DRM_MIN(send, dev->buf_rp - dev->buf_wp - 1);
|
||||
}
|
||||
strncpy(dev->buf_wp, s, count);
|
||||
dev->buf_wp += count;
|
||||
if (dev->buf_wp == dev->buf_end) dev->buf_wp = dev->buf;
|
||||
send -= count;
|
||||
}
|
||||
|
||||
if (dev->buf_selecting) {
|
||||
dev->buf_selecting = 0;
|
||||
selwakeup(&dev->buf_sel);
|
||||
}
|
||||
|
||||
DRM_DEBUG("dev->buf_sigio=%p\n", dev->buf_sigio);
|
||||
if (dev->buf_sigio) {
|
||||
DRM_DEBUG("dev->buf_sigio->sio_pgid=%d\n", dev->buf_sigio->sio_pgid);
|
||||
pgsigio(dev->buf_sigio, SIGIO, 0);
|
||||
}
|
||||
DRM_DEBUG("waking\n");
|
||||
wakeup(&dev->buf_rp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(poll)(dev_t kdev, int events, DRM_OS_STRUCTPROC *p)
|
||||
{
|
||||
drm_device_t *dev = kdev->si_drv1;
|
||||
int s;
|
||||
int revents = 0;
|
||||
|
||||
s = spldrm();
|
||||
if (events & (POLLIN | POLLRDNORM)) {
|
||||
int left = (dev->buf_rp + DRM_BSZ - dev->buf_wp) % DRM_BSZ;
|
||||
if (left > 0)
|
||||
revents |= events & (POLLIN | POLLRDNORM);
|
||||
else
|
||||
selrecord(p, &dev->buf_sel);
|
||||
}
|
||||
splx(s);
|
||||
|
||||
return revents;
|
||||
}
|
||||
|
||||
int DRM(write)(dev_t kdev, struct uio *uio, int ioflag)
|
||||
{
|
||||
DRM_DEBUG("pid = %d, device = %p, open_count = %d\n",
|
||||
curproc->p_pid, ((drm_device_t *)kdev->si_drv1)->device, ((drm_device_t *)kdev->si_drv1)->open_count);
|
||||
return 0;
|
||||
}
|
||||
110
bsd/drm_init.h
Normal file
110
bsd/drm_init.h
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/* drm_init.h -- Setup/Cleanup for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
#if 0 && DRM_DEBUG_CODE
|
||||
int DRM(flags) = DRM_FLAG_DEBUG;
|
||||
#else
|
||||
int DRM(flags) = 0;
|
||||
#endif
|
||||
|
||||
/* drm_parse_option parses a single option. See description for
|
||||
* drm_parse_options for details.
|
||||
*/
|
||||
static void DRM(parse_option)(char *s)
|
||||
{
|
||||
char *c, *r;
|
||||
|
||||
DRM_DEBUG("\"%s\"\n", s);
|
||||
if (!s || !*s) return;
|
||||
for (c = s; *c && *c != ':'; c++); /* find : or \0 */
|
||||
if (*c) r = c + 1; else r = NULL; /* remember remainder */
|
||||
*c = '\0'; /* terminate */
|
||||
if (!strcmp(s, "noctx")) {
|
||||
DRM(flags) |= DRM_FLAG_NOCTX;
|
||||
DRM_INFO("Server-mediated context switching OFF\n");
|
||||
return;
|
||||
}
|
||||
if (!strcmp(s, "debug")) {
|
||||
DRM(flags) |= DRM_FLAG_DEBUG;
|
||||
DRM_INFO("Debug messages ON\n");
|
||||
return;
|
||||
}
|
||||
DRM_ERROR("\"%s\" is not a valid option\n", s);
|
||||
return;
|
||||
}
|
||||
|
||||
/* drm_parse_options parse the insmod "drm_opts=" options, or the command-line
|
||||
* options passed to the kernel via LILO. The grammar of the format is as
|
||||
* follows:
|
||||
*
|
||||
* drm ::= 'drm_opts=' option_list
|
||||
* option_list ::= option [ ';' option_list ]
|
||||
* option ::= 'device:' major
|
||||
* | 'debug'
|
||||
* | 'noctx'
|
||||
* major ::= INTEGER
|
||||
*
|
||||
* Note that 's' contains option_list without the 'drm_opts=' part.
|
||||
*
|
||||
* device=major,minor specifies the device number used for /dev/drm
|
||||
* if major == 0 then the misc device is used
|
||||
* if major == 0 and minor == 0 then dynamic misc allocation is used
|
||||
* debug=on specifies that debugging messages will be printk'd
|
||||
* debug=trace specifies that each function call will be logged via printk
|
||||
* debug=off turns off all debugging options
|
||||
*
|
||||
*/
|
||||
|
||||
void DRM(parse_options)(char *s)
|
||||
{
|
||||
char *h, *t, *n;
|
||||
|
||||
DRM_DEBUG("\"%s\"\n", s ?: "");
|
||||
if (!s || !*s) return;
|
||||
|
||||
for (h = t = n = s; h && *h; h = n) {
|
||||
for (; *t && *t != ';'; t++); /* find ; or \0 */
|
||||
if (*t) n = t + 1; else n = NULL; /* remember next */
|
||||
*t = '\0'; /* terminate */
|
||||
DRM(parse_option)(h); /* parse */
|
||||
}
|
||||
}
|
||||
|
||||
/* drm_cpu_valid returns non-zero if the DRI will run on this CPU, and 0
|
||||
* otherwise.
|
||||
*/
|
||||
int DRM(cpu_valid)(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
237
bsd/drm_ioctl.h
Normal file
237
bsd/drm_ioctl.h
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
/* drm_ioctl.h -- IOCTL processing for DRM -*- linux-c -*-
|
||||
* Created: Fri Jan 8 09:01:26 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
#include <sys/bus.h>
|
||||
#include <pci/pcivar.h>
|
||||
|
||||
int DRM(irq_busid)( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_irq_busid_t id;
|
||||
devclass_t pci;
|
||||
device_t bus, dev;
|
||||
device_t *kids;
|
||||
int error, i, num_kids;
|
||||
|
||||
DRM_OS_KRNFROMUSR( id, (drm_irq_busid_t *)data, sizeof(id) );
|
||||
|
||||
pci = devclass_find("pci");
|
||||
if (!pci)
|
||||
return ENOENT;
|
||||
bus = devclass_get_device(pci, id.busnum);
|
||||
if (!bus)
|
||||
return ENOENT;
|
||||
error = device_get_children(bus, &kids, &num_kids);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
dev = 0;
|
||||
for (i = 0; i < num_kids; i++) {
|
||||
dev = kids[i];
|
||||
if (pci_get_slot(dev) == id.devnum
|
||||
&& pci_get_function(dev) == id.funcnum)
|
||||
break;
|
||||
}
|
||||
|
||||
free(kids, M_TEMP);
|
||||
|
||||
if (i != num_kids)
|
||||
id.irq = pci_get_irq(dev);
|
||||
else
|
||||
id.irq = 0;
|
||||
DRM_DEBUG("%d:%d:%d => IRQ %d\n",
|
||||
id.busnum, id.devnum, id.funcnum, id.irq);
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_irq_busid_t *)data, id, sizeof(id) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(getunique)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_unique_t u;
|
||||
|
||||
DRM_OS_KRNFROMUSR( u, (drm_unique_t *)data, sizeof(u) );
|
||||
|
||||
if (u.unique_len >= dev->unique_len) {
|
||||
if (DRM_OS_COPYTOUSR(u.unique, dev->unique, dev->unique_len))
|
||||
DRM_OS_RETURN(EFAULT);
|
||||
}
|
||||
u.unique_len = dev->unique_len;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_unique_t *)data, u, sizeof(u) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(setunique)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_unique_t u;
|
||||
|
||||
if (dev->unique_len || dev->unique)
|
||||
DRM_OS_RETURN(EBUSY);
|
||||
|
||||
DRM_OS_KRNFROMUSR( u, (drm_unique_t *)data, sizeof(u) );
|
||||
|
||||
if (!u.unique_len || u.unique_len > 1024)
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
|
||||
dev->unique_len = u.unique_len;
|
||||
dev->unique = DRM(alloc)(u.unique_len + 1, DRM_MEM_DRIVER);
|
||||
|
||||
if(!dev->unique) DRM_OS_RETURN(ENOMEM);
|
||||
|
||||
if (DRM_OS_COPYFROMUSR(dev->unique, u.unique, dev->unique_len))
|
||||
DRM_OS_RETURN(EFAULT);
|
||||
|
||||
dev->unique[dev->unique_len] = '\0';
|
||||
|
||||
dev->devname = DRM(alloc)(strlen(dev->name) + strlen(dev->unique) + 2,
|
||||
DRM_MEM_DRIVER);
|
||||
if(!dev->devname) {
|
||||
DRM(free)(dev->devname, sizeof(*dev->devname), DRM_MEM_DRIVER);
|
||||
DRM_OS_RETURN(ENOMEM);
|
||||
}
|
||||
sprintf(dev->devname, "%s@%s", dev->name, dev->unique);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int DRM(getmap)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_map_t map;
|
||||
drm_map_t *mapinlist;
|
||||
drm_map_list_entry_t *list;
|
||||
int idx;
|
||||
int i = 0;
|
||||
|
||||
DRM_OS_KRNFROMUSR( map, (drm_map_t *)data, sizeof(map) );
|
||||
|
||||
idx = map.offset;
|
||||
|
||||
DRM_OS_LOCK;
|
||||
if (idx < 0 || idx >= dev->map_count) {
|
||||
DRM_OS_UNLOCK;
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
TAILQ_FOREACH(list, dev->maplist, link) {
|
||||
mapinlist = list->map;
|
||||
if (i==idx) {
|
||||
map.offset = mapinlist->offset;
|
||||
map.size = mapinlist->size;
|
||||
map.type = mapinlist->type;
|
||||
map.flags = mapinlist->flags;
|
||||
map.handle = mapinlist->handle;
|
||||
map.mtrr = mapinlist->mtrr;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
if (!list)
|
||||
return EINVAL;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_map_t *)data, map, sizeof(map) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(getclient)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_client_t client;
|
||||
drm_file_t *pt;
|
||||
int idx;
|
||||
int i = 0;
|
||||
|
||||
DRM_OS_KRNFROMUSR( client, (drm_client_t *)data, sizeof(client) );
|
||||
|
||||
idx = client.idx;
|
||||
DRM_OS_LOCK;
|
||||
TAILQ_FOREACH(pt, &dev->files, link) {
|
||||
if (i==idx)
|
||||
{
|
||||
client.auth = pt->authenticated;
|
||||
client.pid = pt->pid;
|
||||
client.uid = pt->uid;
|
||||
client.magic = pt->magic;
|
||||
client.iocs = pt->ioctl_count;
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
*(drm_client_t *)data = client;
|
||||
return 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_client_t *)data, client, sizeof(client) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(getstats)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
drm_stats_t stats;
|
||||
int i;
|
||||
|
||||
memset(&stats, 0, sizeof(stats));
|
||||
|
||||
DRM_OS_LOCK;
|
||||
|
||||
for (i = 0; i < dev->counters; i++) {
|
||||
if (dev->types[i] == _DRM_STAT_LOCK)
|
||||
stats.data[i].value
|
||||
= (dev->lock.hw_lock
|
||||
? dev->lock.hw_lock->lock : 0);
|
||||
else
|
||||
stats.data[i].value = atomic_read(&dev->counts[i]);
|
||||
stats.data[i].type = dev->types[i];
|
||||
}
|
||||
|
||||
stats.count = dev->counters;
|
||||
|
||||
DRM_OS_UNLOCK;
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_stats_t *)data, stats, sizeof(stats) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
236
bsd/drm_lists.h
Normal file
236
bsd/drm_lists.h
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
/* drm_lists.h -- Buffer list handling routines -*- linux-c -*-
|
||||
* Created: Mon Apr 19 20:54:22 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
#if __HAVE_DMA_WAITLIST
|
||||
|
||||
int DRM(waitlist_create)(drm_waitlist_t *bl, int count)
|
||||
{
|
||||
if (bl->count)
|
||||
DRM_OS_RETURN( EINVAL );
|
||||
|
||||
bl->bufs = DRM(alloc)((bl->count + 2) * sizeof(*bl->bufs),
|
||||
DRM_MEM_BUFLISTS);
|
||||
|
||||
if(!bl->bufs) DRM_OS_RETURN(ENOMEM);
|
||||
|
||||
bl->count = count;
|
||||
bl->rp = bl->bufs;
|
||||
bl->wp = bl->bufs;
|
||||
bl->end = &bl->bufs[bl->count+1];
|
||||
DRM_OS_SPININIT( bl->write_lock, "writelock" );
|
||||
DRM_OS_SPININIT( bl->read_lock, "readlock" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(waitlist_destroy)(drm_waitlist_t *bl)
|
||||
{
|
||||
if (bl->rp != bl->wp)
|
||||
DRM_OS_RETURN( EINVAL );
|
||||
if (bl->bufs) DRM(free)(bl->bufs,
|
||||
(bl->count + 2) * sizeof(*bl->bufs),
|
||||
DRM_MEM_BUFLISTS);
|
||||
bl->count = 0;
|
||||
bl->bufs = NULL;
|
||||
bl->rp = NULL;
|
||||
bl->wp = NULL;
|
||||
bl->end = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(waitlist_put)(drm_waitlist_t *bl, drm_buf_t *buf)
|
||||
{
|
||||
int left;
|
||||
int s;
|
||||
left = DRM_LEFTCOUNT(bl);
|
||||
if (!left) {
|
||||
DRM_ERROR("Overflow while adding buffer %d from pid %d\n",
|
||||
buf->idx, buf->pid);
|
||||
DRM_OS_RETURN( EINVAL );
|
||||
}
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
getnanotime(&buf->time_queued);
|
||||
#endif
|
||||
buf->list = DRM_LIST_WAIT;
|
||||
|
||||
DRM_OS_SPINLOCK(&bl->write_lock);
|
||||
s = spldrm();
|
||||
*bl->wp = buf;
|
||||
if (++bl->wp >= bl->end) bl->wp = bl->bufs;
|
||||
splx(s);
|
||||
DRM_OS_SPINUNLOCK(&bl->write_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
drm_buf_t *DRM(waitlist_get)(drm_waitlist_t *bl)
|
||||
{
|
||||
drm_buf_t *buf;
|
||||
int s;
|
||||
|
||||
DRM_OS_SPINLOCK(&bl->read_lock);
|
||||
s = spldrm();
|
||||
buf = *bl->rp;
|
||||
if (bl->rp == bl->wp) {
|
||||
splx(s);
|
||||
DRM_OS_SPINUNLOCK(&bl->read_lock);
|
||||
return NULL;
|
||||
}
|
||||
if (++bl->rp >= bl->end) bl->rp = bl->bufs;
|
||||
splx(s);
|
||||
DRM_OS_SPINUNLOCK(&bl->read_lock);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
#endif /* __HAVE_DMA_WAITLIST */
|
||||
|
||||
|
||||
#if __HAVE_DMA_FREELIST
|
||||
|
||||
int DRM(freelist_create)(drm_freelist_t *bl, int count)
|
||||
{
|
||||
atomic_set(&bl->count, 0);
|
||||
bl->next = NULL;
|
||||
bl->waiting = 0;
|
||||
|
||||
bl->low_mark = 0;
|
||||
bl->high_mark = 0;
|
||||
atomic_set(&bl->wfh, 0);
|
||||
DRM_OS_SPININIT( bl->lock, "freelistlock" );
|
||||
++bl->initialized;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(freelist_destroy)(drm_freelist_t *bl)
|
||||
{
|
||||
atomic_set(&bl->count, 0);
|
||||
bl->next = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(freelist_put)(drm_device_t *dev, drm_freelist_t *bl, drm_buf_t *buf)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
if (!dma) {
|
||||
DRM_ERROR("No DMA support\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (buf->waiting || buf->pending || buf->list == DRM_LIST_FREE) {
|
||||
DRM_ERROR("Freed buffer %d: w%d, p%d, l%d\n",
|
||||
buf->idx, buf->waiting, buf->pending, buf->list);
|
||||
}
|
||||
if (!bl) return 1;
|
||||
#if __HAVE_DMA_HISTOGRAM
|
||||
getnanotime(&buf->time_queued);
|
||||
DRM(histogram_compute)(dev, buf);
|
||||
#endif
|
||||
buf->list = DRM_LIST_FREE;
|
||||
|
||||
DRM_OS_SPINLOCK( &bl->lock );
|
||||
buf->next = bl->next;
|
||||
bl->next = buf;
|
||||
DRM_OS_SPINUNLOCK( &bl->lock );
|
||||
|
||||
atomic_inc(&bl->count);
|
||||
if (atomic_read(&bl->count) > dma->buf_count) {
|
||||
DRM_ERROR("%ld of %d buffers free after addition of %d\n",
|
||||
(unsigned long)atomic_read(&bl->count),
|
||||
dma->buf_count, buf->idx);
|
||||
return 1;
|
||||
}
|
||||
/* Check for high water mark */
|
||||
if (atomic_read(&bl->wfh) && atomic_read(&bl->count)>=bl->high_mark) {
|
||||
atomic_set(&bl->wfh, 0);
|
||||
DRM_OS_WAKEUP_INT(&bl->waiting);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static drm_buf_t *DRM(freelist_try)(drm_freelist_t *bl)
|
||||
{
|
||||
drm_buf_t *buf;
|
||||
|
||||
if (!bl) return NULL;
|
||||
|
||||
/* Get buffer */
|
||||
DRM_OS_SPINLOCK(&bl->lock);
|
||||
if (!bl->next) {
|
||||
DRM_OS_SPINUNLOCK(&bl->lock);
|
||||
return NULL;
|
||||
}
|
||||
buf = bl->next;
|
||||
bl->next = bl->next->next;
|
||||
DRM_OS_SPINUNLOCK(&bl->lock);
|
||||
|
||||
atomic_dec(&bl->count);
|
||||
buf->next = NULL;
|
||||
buf->list = DRM_LIST_NONE;
|
||||
if (buf->waiting || buf->pending) {
|
||||
DRM_ERROR("Free buffer %d: w%d, p%d, l%d\n",
|
||||
buf->idx, buf->waiting, buf->pending, buf->list);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
drm_buf_t *DRM(freelist_get)(drm_freelist_t *bl, int block)
|
||||
{
|
||||
drm_buf_t *buf = NULL;
|
||||
int error;
|
||||
|
||||
if (!bl || !bl->initialized) return NULL;
|
||||
|
||||
/* Check for low water mark */
|
||||
if (atomic_read(&bl->count) <= bl->low_mark) /* Became low */
|
||||
atomic_set(&bl->wfh, 1);
|
||||
if (atomic_read(&bl->wfh)) {
|
||||
if (block) {
|
||||
for (;;) {
|
||||
if (!atomic_read(&bl->wfh)
|
||||
&& (buf = DRM(freelist_try(bl)))) break;
|
||||
error = tsleep(&bl->waiting, PZERO|PCATCH,
|
||||
"drmfg", 0);
|
||||
if (error)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
return DRM(freelist_try)(bl);
|
||||
}
|
||||
|
||||
#endif /* __HAVE_DMA_FREELIST */
|
||||
244
bsd/drm_lock.h
Normal file
244
bsd/drm_lock.h
Normal file
|
|
@ -0,0 +1,244 @@
|
|||
/* lock.c -- IOCTLs for locking -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
int DRM(block)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_DEBUG("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(unblock)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_DEBUG("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(lock_take)(__volatile__ unsigned int *lock, unsigned int context)
|
||||
{
|
||||
unsigned int old, new;
|
||||
|
||||
char failed;
|
||||
|
||||
do {
|
||||
old = *lock;
|
||||
if (old & _DRM_LOCK_HELD) new = old | _DRM_LOCK_CONT;
|
||||
else new = context | _DRM_LOCK_HELD;
|
||||
_DRM_CAS(lock, old, new, failed);
|
||||
} while (failed);
|
||||
if (_DRM_LOCKING_CONTEXT(old) == context) {
|
||||
if (old & _DRM_LOCK_HELD) {
|
||||
if (context != DRM_KERNEL_CONTEXT) {
|
||||
DRM_ERROR("%d holds heavyweight lock\n",
|
||||
context);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (new == (context | _DRM_LOCK_HELD)) {
|
||||
/* Have lock */
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This takes a lock forcibly and hands it to context. Should ONLY be used
|
||||
inside *_unlock to give lock to kernel before calling *_dma_schedule. */
|
||||
int DRM(lock_transfer)(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock, unsigned int context)
|
||||
{
|
||||
unsigned int old, new;
|
||||
char failed;
|
||||
|
||||
dev->lock.pid = 0;
|
||||
do {
|
||||
old = *lock;
|
||||
new = context | _DRM_LOCK_HELD;
|
||||
_DRM_CAS(lock, old, new, failed);
|
||||
} while (failed);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DRM(lock_free)(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock, unsigned int context)
|
||||
{
|
||||
unsigned int old, new;
|
||||
pid_t pid = dev->lock.pid;
|
||||
char failed;
|
||||
|
||||
dev->lock.pid = 0;
|
||||
do {
|
||||
old = *lock;
|
||||
new = 0;
|
||||
_DRM_CAS(lock, old, new, failed);
|
||||
} while (failed);
|
||||
if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
|
||||
DRM_ERROR("%d freed heavyweight lock held by %d (pid %d)\n",
|
||||
context,
|
||||
_DRM_LOCKING_CONTEXT(old),
|
||||
pid);
|
||||
return 1;
|
||||
}
|
||||
DRM_OS_WAKEUP_INT(&dev->lock.lock_queue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DRM(flush_queue)(drm_device_t *dev, int context)
|
||||
{
|
||||
int error;
|
||||
int ret = 0;
|
||||
drm_queue_t *q = dev->queuelist[context];
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) > 1) {
|
||||
atomic_inc(&q->block_write);
|
||||
atomic_inc(&q->block_count);
|
||||
error = tsleep(&q->flush_queue, PZERO|PCATCH, "drmfq", 0);
|
||||
if (error)
|
||||
return error;
|
||||
atomic_dec(&q->block_count);
|
||||
}
|
||||
atomic_dec(&q->use_count);
|
||||
|
||||
/* NOTE: block_write is still incremented!
|
||||
Use drm_flush_unlock_queue to decrement. */
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int DRM(flush_unblock_queue)(drm_device_t *dev, int context)
|
||||
{
|
||||
drm_queue_t *q = dev->queuelist[context];
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) > 1) {
|
||||
if (atomic_read(&q->block_write)) {
|
||||
atomic_dec(&q->block_write);
|
||||
DRM_OS_WAKEUP_INT(&q->write_queue);
|
||||
}
|
||||
}
|
||||
atomic_dec(&q->use_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(flush_block_and_flush)(drm_device_t *dev, int context,
|
||||
drm_lock_flags_t flags)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
if (flags & _DRM_LOCK_FLUSH) {
|
||||
ret = DRM(flush_queue)(dev, DRM_KERNEL_CONTEXT);
|
||||
if (!ret) ret = DRM(flush_queue)(dev, context);
|
||||
}
|
||||
if (flags & _DRM_LOCK_FLUSH_ALL) {
|
||||
for (i = 0; !ret && i < dev->queue_count; i++) {
|
||||
ret = DRM(flush_queue)(dev, i);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DRM(flush_unblock)(drm_device_t *dev, int context, drm_lock_flags_t flags)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
if (flags & _DRM_LOCK_FLUSH) {
|
||||
ret = DRM(flush_unblock_queue)(dev, DRM_KERNEL_CONTEXT);
|
||||
if (!ret) ret = DRM(flush_unblock_queue)(dev, context);
|
||||
}
|
||||
if (flags & _DRM_LOCK_FLUSH_ALL) {
|
||||
for (i = 0; !ret && i < dev->queue_count; i++) {
|
||||
ret = DRM(flush_unblock_queue)(dev, i);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DRM(finish)( DRM_OS_IOCTL )
|
||||
{
|
||||
DRM_OS_DEVICE;
|
||||
int ret = 0;
|
||||
drm_lock_t lock;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
DRM_OS_KRNFROMUSR( lock, (drm_lock_t *)data, sizeof(lock) );
|
||||
|
||||
ret = DRM(flush_block_and_flush)(dev, lock.context, lock.flags);
|
||||
DRM(flush_unblock)(dev, lock.context, lock.flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* If we get here, it means that the process has called DRM_IOCTL_LOCK
|
||||
without calling DRM_IOCTL_UNLOCK.
|
||||
|
||||
If the lock is not held, then let the signal proceed as usual.
|
||||
|
||||
If the lock is held, then set the contended flag and keep the signal
|
||||
blocked.
|
||||
|
||||
|
||||
Return 1 if the signal should be delivered normally.
|
||||
Return 0 if the signal should be blocked. */
|
||||
|
||||
int DRM(notifier)(void *priv)
|
||||
{
|
||||
drm_sigdata_t *s = (drm_sigdata_t *)priv;
|
||||
unsigned int old, new;
|
||||
char failed;
|
||||
|
||||
|
||||
/* Allow signal delivery if lock isn't held */
|
||||
if (!_DRM_LOCK_IS_HELD(s->lock->lock)
|
||||
|| _DRM_LOCKING_CONTEXT(s->lock->lock) != s->context) return 1;
|
||||
|
||||
/* Otherwise, set flag to force call to
|
||||
drmUnlock */
|
||||
do {
|
||||
old = s->lock->lock;
|
||||
new = old | _DRM_LOCK_CONT;
|
||||
_DRM_CAS(&s->lock->lock, old, new, failed);
|
||||
} while (failed);
|
||||
return 0;
|
||||
}
|
||||
|
||||
433
bsd/drm_memory.h
Normal file
433
bsd/drm_memory.h
Normal file
|
|
@ -0,0 +1,433 @@
|
|||
/* drm_memory.h -- Memory management wrappers for DRM -*- linux-c -*-
|
||||
* Created: Thu Feb 4 14:00:34 1999 by faith@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
#if __REALLY_HAVE_AGP
|
||||
#include <sys/agpio.h>
|
||||
#endif
|
||||
|
||||
#define malloctype DRM(M_DRM)
|
||||
/* The macros confliced in the MALLOC_DEFINE */
|
||||
|
||||
MALLOC_DEFINE(malloctype, "drm", "DRM Data Structures");
|
||||
|
||||
#undef malloctype
|
||||
|
||||
typedef struct drm_mem_stats {
|
||||
const char *name;
|
||||
int succeed_count;
|
||||
int free_count;
|
||||
int fail_count;
|
||||
unsigned long bytes_allocated;
|
||||
unsigned long bytes_freed;
|
||||
} drm_mem_stats_t;
|
||||
|
||||
static DRM_OS_SPINTYPE DRM(mem_lock);
|
||||
static unsigned long DRM(ram_available) = 0; /* In pages */
|
||||
static unsigned long DRM(ram_used) = 0;
|
||||
static drm_mem_stats_t DRM(mem_stats)[] = {
|
||||
[DRM_MEM_DMA] = { "dmabufs" },
|
||||
[DRM_MEM_SAREA] = { "sareas" },
|
||||
[DRM_MEM_DRIVER] = { "driver" },
|
||||
[DRM_MEM_MAGIC] = { "magic" },
|
||||
[DRM_MEM_IOCTLS] = { "ioctltab" },
|
||||
[DRM_MEM_MAPS] = { "maplist" },
|
||||
[DRM_MEM_VMAS] = { "vmalist" },
|
||||
[DRM_MEM_BUFS] = { "buflist" },
|
||||
[DRM_MEM_SEGS] = { "seglist" },
|
||||
[DRM_MEM_PAGES] = { "pagelist" },
|
||||
[DRM_MEM_FILES] = { "files" },
|
||||
[DRM_MEM_QUEUES] = { "queues" },
|
||||
[DRM_MEM_CMDS] = { "commands" },
|
||||
[DRM_MEM_MAPPINGS] = { "mappings" },
|
||||
[DRM_MEM_BUFLISTS] = { "buflists" },
|
||||
[DRM_MEM_AGPLISTS] = { "agplist" },
|
||||
[DRM_MEM_SGLISTS] = { "sglist" },
|
||||
[DRM_MEM_TOTALAGP] = { "totalagp" },
|
||||
[DRM_MEM_BOUNDAGP] = { "boundagp" },
|
||||
[DRM_MEM_CTXBITMAP] = { "ctxbitmap"},
|
||||
[DRM_MEM_STUB] = { "stub" },
|
||||
{ NULL, 0, } /* Last entry must be null */
|
||||
};
|
||||
|
||||
void DRM(mem_init)(void)
|
||||
{
|
||||
drm_mem_stats_t *mem;
|
||||
|
||||
DRM_OS_SPININIT(DRM(mem_lock), "drm memory");
|
||||
|
||||
for (mem = DRM(mem_stats); mem->name; ++mem) {
|
||||
mem->succeed_count = 0;
|
||||
mem->free_count = 0;
|
||||
mem->fail_count = 0;
|
||||
mem->bytes_allocated = 0;
|
||||
mem->bytes_freed = 0;
|
||||
}
|
||||
|
||||
DRM(ram_available) = 0; /* si.totalram */
|
||||
DRM(ram_used) = 0;
|
||||
}
|
||||
|
||||
/* drm_mem_info is called whenever a process reads /dev/drm/mem. */
|
||||
|
||||
static int DRM(_mem_info) DRM_SYSCTL_HANDLER_ARGS
|
||||
{
|
||||
drm_mem_stats_t *pt;
|
||||
char buf[128];
|
||||
int error;
|
||||
|
||||
DRM_SYSCTL_PRINT(" total counts "
|
||||
" | outstanding \n");
|
||||
DRM_SYSCTL_PRINT("type alloc freed fail bytes freed"
|
||||
" | allocs bytes\n\n");
|
||||
DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu |\n",
|
||||
"system", 0, 0, 0, DRM(ram_available));
|
||||
DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu |\n",
|
||||
"locked", 0, 0, 0, DRM(ram_used));
|
||||
DRM_SYSCTL_PRINT("\n");
|
||||
for (pt = DRM(mem_stats); pt->name; pt++) {
|
||||
DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu %10lu | %6d %10ld\n",
|
||||
pt->name,
|
||||
pt->succeed_count,
|
||||
pt->free_count,
|
||||
pt->fail_count,
|
||||
pt->bytes_allocated,
|
||||
pt->bytes_freed,
|
||||
pt->succeed_count - pt->free_count,
|
||||
(long)pt->bytes_allocated
|
||||
- (long)pt->bytes_freed);
|
||||
}
|
||||
SYSCTL_OUT(req, "", 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(mem_info) DRM_SYSCTL_HANDLER_ARGS
|
||||
{
|
||||
int ret;
|
||||
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
ret = DRM(_mem_info)(oidp, arg1, arg2, req);
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *DRM(alloc)(size_t size, int area)
|
||||
{
|
||||
void *pt;
|
||||
|
||||
if (!size) {
|
||||
DRM_MEM_ERROR(area, "Allocating 0 bytes\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(pt = malloc(size, DRM(M_DRM), M_NOWAIT))) {
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[area].fail_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return NULL;
|
||||
}
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[area].succeed_count;
|
||||
DRM(mem_stats)[area].bytes_allocated += size;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return pt;
|
||||
}
|
||||
|
||||
void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size, int area)
|
||||
{
|
||||
void *pt;
|
||||
|
||||
if (!(pt = DRM(alloc)(size, area))) return NULL;
|
||||
if (oldpt && oldsize) {
|
||||
memcpy(pt, oldpt, oldsize);
|
||||
DRM(free)(oldpt, oldsize, area);
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
|
||||
char *DRM(strdup)(const char *s, int area)
|
||||
{
|
||||
char *pt;
|
||||
int length = s ? strlen(s) : 0;
|
||||
|
||||
if (!(pt = DRM(alloc)(length+1, area))) return NULL;
|
||||
strcpy(pt, s);
|
||||
return pt;
|
||||
}
|
||||
|
||||
void DRM(strfree)(char *s, int area)
|
||||
{
|
||||
unsigned int size;
|
||||
|
||||
if (!s) return;
|
||||
|
||||
size = 1 + strlen(s);
|
||||
DRM(free)((void *)s, size, area);
|
||||
}
|
||||
|
||||
void DRM(free)(void *pt, size_t size, int area)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
|
||||
if (!pt) DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n");
|
||||
else free(pt, DRM(M_DRM));
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
DRM(mem_stats)[area].bytes_freed += size;
|
||||
free_count = ++DRM(mem_stats)[area].free_count;
|
||||
alloc_count = DRM(mem_stats)[area].succeed_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(area, "Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long DRM(alloc_pages)(int order, int area)
|
||||
{
|
||||
vm_offset_t address;
|
||||
unsigned long bytes = PAGE_SIZE << order;
|
||||
|
||||
|
||||
address = (vm_offset_t) contigmalloc(bytes, DRM(M_DRM), M_WAITOK, 0, ~0, 1, 0);
|
||||
if (!address) {
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[area].fail_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return 0;
|
||||
}
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[area].succeed_count;
|
||||
DRM(mem_stats)[area].bytes_allocated += bytes;
|
||||
DRM(ram_used) += bytes;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
|
||||
|
||||
/* Zero outside the lock */
|
||||
memset((void *)address, 0, bytes);
|
||||
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
void DRM(free_pages)(unsigned long address, int order, int area)
|
||||
{
|
||||
unsigned long bytes = PAGE_SIZE << order;
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
|
||||
if (!address) {
|
||||
DRM_MEM_ERROR(area, "Attempt to free address 0\n");
|
||||
} else {
|
||||
contigfree((void *) address, bytes, DRM(M_DRM));
|
||||
}
|
||||
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
free_count = ++DRM(mem_stats)[area].free_count;
|
||||
alloc_count = DRM(mem_stats)[area].succeed_count;
|
||||
DRM(mem_stats)[area].bytes_freed += bytes;
|
||||
DRM(ram_used) -= bytes;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(area,
|
||||
"Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
}
|
||||
|
||||
void *DRM(ioremap)(unsigned long offset, unsigned long size)
|
||||
{
|
||||
void *pt;
|
||||
|
||||
if (!size) {
|
||||
DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
|
||||
"Mapping 0 bytes at 0x%08lx\n", offset);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(pt = pmap_mapdev(offset, size))) {
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[DRM_MEM_MAPPINGS].fail_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return NULL;
|
||||
}
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[DRM_MEM_MAPPINGS].succeed_count;
|
||||
DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_allocated += size;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return pt;
|
||||
}
|
||||
|
||||
void DRM(ioremapfree)(void *pt, unsigned long size)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
|
||||
if (!pt)
|
||||
DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
|
||||
"Attempt to free NULL pointer\n");
|
||||
else
|
||||
pmap_unmapdev((vm_offset_t) pt, size);
|
||||
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_freed += size;
|
||||
free_count = ++DRM(mem_stats)[DRM_MEM_MAPPINGS].free_count;
|
||||
alloc_count = DRM(mem_stats)[DRM_MEM_MAPPINGS].succeed_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
|
||||
"Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
}
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
agp_memory *DRM(alloc_agp)(int pages, u32 type)
|
||||
{
|
||||
agp_memory *handle;
|
||||
|
||||
if (!pages) {
|
||||
DRM_MEM_ERROR(DRM_MEM_TOTALAGP, "Allocating 0 pages\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((handle = DRM(agp_allocate_memory)(pages, type))) {
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
|
||||
DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_allocated
|
||||
+= pages << PAGE_SHIFT;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return handle;
|
||||
}
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[DRM_MEM_TOTALAGP].fail_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int DRM(free_agp)(agp_memory *handle, int pages)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
|
||||
if (!handle) {
|
||||
DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
|
||||
"Attempt to free NULL AGP handle\n");
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
if (DRM(agp_free_memory)(handle)) {
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
free_count = ++DRM(mem_stats)[DRM_MEM_TOTALAGP].free_count;
|
||||
alloc_count = DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
|
||||
DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_freed
|
||||
+= pages << PAGE_SHIFT;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
|
||||
"Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
int DRM(bind_agp)(agp_memory *handle, unsigned int start)
|
||||
{
|
||||
int retcode;
|
||||
device_t dev = agp_find_device();
|
||||
struct agp_memory_info info;
|
||||
|
||||
if (!dev)
|
||||
return EINVAL;
|
||||
|
||||
if (!handle) {
|
||||
DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
|
||||
"Attempt to bind NULL AGP handle\n");
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
if (!(retcode = DRM(agp_bind_memory)(handle, start))) {
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
|
||||
agp_memory_info(dev, handle, &info);
|
||||
DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_allocated
|
||||
+= info.ami_size;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
DRM_OS_RETURN(0);
|
||||
}
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
++DRM(mem_stats)[DRM_MEM_BOUNDAGP].fail_count;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
DRM_OS_RETURN(retcode);
|
||||
}
|
||||
|
||||
int DRM(unbind_agp)(agp_memory *handle)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
int retcode = EINVAL;
|
||||
device_t dev = agp_find_device();
|
||||
struct agp_memory_info info;
|
||||
|
||||
if (!dev)
|
||||
return EINVAL;
|
||||
|
||||
if (!handle) {
|
||||
DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
|
||||
"Attempt to unbind NULL AGP handle\n");
|
||||
DRM_OS_RETURN(retcode);
|
||||
}
|
||||
|
||||
agp_memory_info(dev, handle, &info);
|
||||
|
||||
if ((retcode = DRM(agp_unbind_memory)(handle)))
|
||||
DRM_OS_RETURN(retcode);
|
||||
|
||||
DRM_OS_SPINLOCK(&DRM(mem_lock));
|
||||
free_count = ++DRM(mem_stats)[DRM_MEM_BOUNDAGP].free_count;
|
||||
alloc_count = DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
|
||||
DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_freed
|
||||
+= info.ami_size;
|
||||
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
|
||||
"Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
DRM_OS_RETURN(retcode);
|
||||
}
|
||||
#endif
|
||||
237
bsd/drm_scatter.h
Normal file
237
bsd/drm_scatter.h
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
/* drm_scatter.h -- IOCTLs to manage scatter/gather memory -*- linux-c -*-
|
||||
* Created: Mon Dec 18 23:20:54 2000 by gareth@valinux.com
|
||||
*
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include <linux/config.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include "drmP.h"
|
||||
|
||||
#define DEBUG_SCATTER 0
|
||||
|
||||
void DRM(sg_cleanup)( drm_sg_mem_t *entry )
|
||||
{
|
||||
struct page *page;
|
||||
int i;
|
||||
|
||||
for ( i = 0 ; i < entry->pages ; i++ ) {
|
||||
page = entry->pagelist[i];
|
||||
if ( page )
|
||||
ClearPageReserved( page );
|
||||
}
|
||||
|
||||
vfree( entry->virtual );
|
||||
|
||||
DRM(free)( entry->busaddr,
|
||||
entry->pages * sizeof(*entry->busaddr),
|
||||
DRM_MEM_PAGES );
|
||||
DRM(free)( entry->pagelist,
|
||||
entry->pages * sizeof(*entry->pagelist),
|
||||
DRM_MEM_PAGES );
|
||||
DRM(free)( entry,
|
||||
sizeof(*entry),
|
||||
DRM_MEM_SGLISTS );
|
||||
}
|
||||
|
||||
int DRM(sg_alloc)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_scatter_gather_t request;
|
||||
drm_sg_mem_t *entry;
|
||||
unsigned long pages, i, j;
|
||||
pgd_t *pgd;
|
||||
pmd_t *pmd;
|
||||
pte_t *pte;
|
||||
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
if ( dev->sg )
|
||||
return -EINVAL;
|
||||
|
||||
if ( copy_from_user( &request,
|
||||
(drm_scatter_gather_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
entry = DRM(alloc)( sizeof(*entry), DRM_MEM_SGLISTS );
|
||||
if ( !entry )
|
||||
return -ENOMEM;
|
||||
|
||||
memset( entry, 0, sizeof(*entry) );
|
||||
|
||||
pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
|
||||
DRM_DEBUG( "sg size=%ld pages=%ld\n", request.size, pages );
|
||||
|
||||
entry->pages = pages;
|
||||
entry->pagelist = DRM(alloc)( pages * sizeof(*entry->pagelist),
|
||||
DRM_MEM_PAGES );
|
||||
if ( !entry->pagelist ) {
|
||||
DRM(free)( entry, sizeof(*entry), DRM_MEM_SGLISTS );
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
entry->busaddr = DRM(alloc)( pages * sizeof(*entry->busaddr),
|
||||
DRM_MEM_PAGES );
|
||||
if ( !entry->busaddr ) {
|
||||
DRM(free)( entry->pagelist,
|
||||
entry->pages * sizeof(*entry->pagelist),
|
||||
DRM_MEM_PAGES );
|
||||
DRM(free)( entry,
|
||||
sizeof(*entry),
|
||||
DRM_MEM_SGLISTS );
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset( (void *)entry->busaddr, 0, pages * sizeof(*entry->busaddr) );
|
||||
|
||||
entry->virtual = vmalloc_32( pages << PAGE_SHIFT );
|
||||
if ( !entry->virtual ) {
|
||||
DRM(free)( entry->busaddr,
|
||||
entry->pages * sizeof(*entry->busaddr),
|
||||
DRM_MEM_PAGES );
|
||||
DRM(free)( entry->pagelist,
|
||||
entry->pages * sizeof(*entry->pagelist),
|
||||
DRM_MEM_PAGES );
|
||||
DRM(free)( entry,
|
||||
sizeof(*entry),
|
||||
DRM_MEM_SGLISTS );
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* This also forces the mapping of COW pages, so our page list
|
||||
* will be valid. Please don't remove it...
|
||||
*/
|
||||
memset( entry->virtual, 0, pages << PAGE_SHIFT );
|
||||
|
||||
entry->handle = (unsigned long)entry->virtual;
|
||||
|
||||
DRM_DEBUG( "sg alloc handle = %08lx\n", entry->handle );
|
||||
DRM_DEBUG( "sg alloc virtual = %p\n", entry->virtual );
|
||||
|
||||
for ( i = entry->handle, j = 0 ; j < pages ; i += PAGE_SIZE, j++ ) {
|
||||
pgd = pgd_offset_k( i );
|
||||
if ( !pgd_present( *pgd ) )
|
||||
goto failed;
|
||||
|
||||
pmd = pmd_offset( pgd, i );
|
||||
if ( !pmd_present( *pmd ) )
|
||||
goto failed;
|
||||
|
||||
pte = pte_offset( pmd, i );
|
||||
if ( !pte_present( *pte ) )
|
||||
goto failed;
|
||||
|
||||
entry->pagelist[j] = pte_page( *pte );
|
||||
|
||||
SetPageReserved( entry->pagelist[j] );
|
||||
}
|
||||
|
||||
request.handle = entry->handle;
|
||||
|
||||
if ( copy_to_user( (drm_scatter_gather_t *)arg,
|
||||
&request,
|
||||
sizeof(request) ) ) {
|
||||
DRM(sg_cleanup)( entry );
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
dev->sg = entry;
|
||||
|
||||
#if DEBUG_SCATTER
|
||||
/* Verify that each page points to its virtual address, and vice
|
||||
* versa.
|
||||
*/
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
for ( i = 0 ; i < pages ; i++ ) {
|
||||
unsigned long *tmp;
|
||||
|
||||
tmp = page_address( entry->pagelist[i] );
|
||||
for ( j = 0 ;
|
||||
j < PAGE_SIZE / sizeof(unsigned long) ;
|
||||
j++, tmp++ ) {
|
||||
*tmp = 0xcafebabe;
|
||||
}
|
||||
tmp = (unsigned long *)((u8 *)entry->virtual +
|
||||
(PAGE_SIZE * i));
|
||||
for( j = 0 ;
|
||||
j < PAGE_SIZE / sizeof(unsigned long) ;
|
||||
j++, tmp++ ) {
|
||||
if ( *tmp != 0xcafebabe && error == 0 ) {
|
||||
error = 1;
|
||||
DRM_ERROR( "Scatter allocation error, "
|
||||
"pagelist does not match "
|
||||
"virtual mapping\n" );
|
||||
}
|
||||
}
|
||||
tmp = page_address( entry->pagelist[i] );
|
||||
for(j = 0 ;
|
||||
j < PAGE_SIZE / sizeof(unsigned long) ;
|
||||
j++, tmp++) {
|
||||
*tmp = 0;
|
||||
}
|
||||
}
|
||||
if (error == 0)
|
||||
DRM_ERROR( "Scatter allocation matches pagelist\n" );
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
failed:
|
||||
DRM(sg_cleanup)( entry );
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
int DRM(sg_free)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_scatter_gather_t request;
|
||||
drm_sg_mem_t *entry;
|
||||
|
||||
if ( copy_from_user( &request,
|
||||
(drm_scatter_gather_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
entry = dev->sg;
|
||||
dev->sg = NULL;
|
||||
|
||||
if ( !entry || entry->handle != request.handle )
|
||||
return -EINVAL;
|
||||
|
||||
DRM_DEBUG( "sg free virtual = %p\n", entry->virtual );
|
||||
|
||||
DRM(sg_cleanup)( entry );
|
||||
|
||||
return 0;
|
||||
}
|
||||
93
bsd/gamma/gamma.h
Normal file
93
bsd/gamma/gamma.h
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/* gamma.c -- 3dlabs GMX 2000 driver -*- linux-c -*-
|
||||
* Created: Mon Jan 4 08:58:31 1999 by gareth@valinux.com
|
||||
*
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef __GAMMA_H__
|
||||
#define __GAMMA_H__
|
||||
|
||||
/* This remains constant for all DRM template files.
|
||||
*/
|
||||
#define DRM(x) gamma_##x
|
||||
|
||||
/* General customization:
|
||||
*/
|
||||
#define __HAVE_MTRR 1
|
||||
|
||||
/* DMA customization:
|
||||
*/
|
||||
#define __HAVE_DMA 1
|
||||
#define __HAVE_OLD_DMA 1
|
||||
#define __HAVE_PCI_DMA 1
|
||||
|
||||
#define __HAVE_MULTIPLE_DMA_QUEUES 1
|
||||
#define __HAVE_DMA_WAITQUEUE 1
|
||||
|
||||
#define __HAVE_DMA_WAITLIST 1
|
||||
#define __HAVE_DMA_FREELIST 1
|
||||
|
||||
#define __HAVE_DMA_FLUSH 1
|
||||
#define __HAVE_DMA_SCHEDULE 1
|
||||
|
||||
#define __HAVE_DMA_READY 1
|
||||
#define DRIVER_DMA_READY() do { \
|
||||
gamma_dma_ready(dev); \
|
||||
} while (0)
|
||||
|
||||
#define __HAVE_DMA_QUIESCENT 1
|
||||
#define DRIVER_DMA_QUIESCENT() do { \
|
||||
/* FIXME ! */ \
|
||||
gamma_dma_quiescent_dual(dev); \
|
||||
return 0; \
|
||||
} while (0)
|
||||
|
||||
#define __HAVE_DMA_IRQ 1
|
||||
#define __HAVE_DMA_IRQ_BH 1
|
||||
#define DRIVER_PREINSTALL() do { \
|
||||
drm_gamma_private_t *dev_priv = \
|
||||
(drm_gamma_private_t *)dev->dev_private;\
|
||||
GAMMA_WRITE( GAMMA_GCOMMANDMODE, 0x00000000 ); \
|
||||
GAMMA_WRITE( GAMMA_GDMACONTROL, 0x00000000 ); \
|
||||
} while (0)
|
||||
|
||||
#define DRIVER_POSTINSTALL() do { \
|
||||
drm_gamma_private_t *dev_priv = \
|
||||
(drm_gamma_private_t *)dev->dev_private;\
|
||||
GAMMA_WRITE( GAMMA_GINTENABLE, 0x00002001 ); \
|
||||
GAMMA_WRITE( GAMMA_COMMANDINTENABLE, 0x00000008 ); \
|
||||
GAMMA_WRITE( GAMMA_GDELAYTIMER, 0x00039090 ); \
|
||||
} while (0)
|
||||
|
||||
#define DRIVER_UNINSTALL() do { \
|
||||
drm_gamma_private_t *dev_priv = \
|
||||
(drm_gamma_private_t *)dev->dev_private;\
|
||||
GAMMA_WRITE( GAMMA_GDELAYTIMER, 0x00000000 ); \
|
||||
GAMMA_WRITE( GAMMA_COMMANDINTENABLE, 0x00000000 ); \
|
||||
GAMMA_WRITE( GAMMA_GINTENABLE, 0x00000000 ); \
|
||||
} while (0)
|
||||
|
||||
#endif /* __GAMMA_H__ */
|
||||
116
bsd/i810/i810.h
Normal file
116
bsd/i810/i810.h
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/* i810.h -- Intel i810/i815 DRM template customization -*- linux-c -*-
|
||||
* Created: Thu Feb 15 00:01:12 2001 by gareth@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef __I810_H__
|
||||
#define __I810_H__
|
||||
|
||||
/* This remains constant for all DRM template files.
|
||||
*/
|
||||
#define DRM(x) i810_##x
|
||||
|
||||
/* General customization:
|
||||
*/
|
||||
#define __HAVE_AGP 1
|
||||
#define __MUST_HAVE_AGP 1
|
||||
#define __HAVE_MTRR 1
|
||||
#define __HAVE_CTX_BITMAP 1
|
||||
|
||||
/* Driver customization:
|
||||
*/
|
||||
#define __HAVE_RELEASE 1
|
||||
#define DRIVER_RELEASE() do { \
|
||||
i810_reclaim_buffers( dev, priv->pid ); \
|
||||
} while (0)
|
||||
|
||||
/* DMA customization:
|
||||
*/
|
||||
#define __HAVE_DMA 1
|
||||
#define __HAVE_DMA_QUEUE 1
|
||||
#define __HAVE_DMA_WAITLIST 1
|
||||
#define __HAVE_DMA_RECLAIM 1
|
||||
|
||||
#define __HAVE_DMA_QUIESCENT 1
|
||||
#define DRIVER_DMA_QUIESCENT() do { \
|
||||
i810_dma_quiescent( dev ); \
|
||||
} while (0)
|
||||
|
||||
#define __HAVE_DMA_IRQ 1
|
||||
#define __HAVE_DMA_IRQ_BH 1
|
||||
#define __HAVE_SHARED_IRQ 1
|
||||
#define DRIVER_PREINSTALL() do { \
|
||||
drm_i810_private_t *dev_priv = \
|
||||
(drm_i810_private_t *)dev->dev_private; \
|
||||
u16 tmp; \
|
||||
tmp = I810_READ16( I810REG_HWSTAM ); \
|
||||
tmp = tmp & 0x6000; \
|
||||
I810_WRITE16( I810REG_HWSTAM, tmp ); \
|
||||
\
|
||||
tmp = I810_READ16( I810REG_INT_MASK_R ); \
|
||||
tmp = tmp & 0x6000; /* Unmask interrupts */ \
|
||||
I810_WRITE16( I810REG_INT_MASK_R, tmp ); \
|
||||
tmp = I810_READ16( I810REG_INT_ENABLE_R ); \
|
||||
tmp = tmp & 0x6000; /* Disable all interrupts */ \
|
||||
I810_WRITE16( I810REG_INT_ENABLE_R, tmp ); \
|
||||
} while (0)
|
||||
|
||||
#define DRIVER_POSTINSTALL() do { \
|
||||
drm_i810_private_t *dev_priv = \
|
||||
(drm_i810_private_t *)dev->dev_private; \
|
||||
u16 tmp; \
|
||||
tmp = I810_READ16( I810REG_INT_ENABLE_R ); \
|
||||
tmp = tmp & 0x6000; \
|
||||
tmp = tmp | 0x0003; /* Enable bp & user interrupts */ \
|
||||
I810_WRITE16( I810REG_INT_ENABLE_R, tmp ); \
|
||||
} while (0)
|
||||
|
||||
#define DRIVER_UNINSTALL() do { \
|
||||
drm_i810_private_t *dev_priv = \
|
||||
(drm_i810_private_t *)dev->dev_private; \
|
||||
u16 tmp; \
|
||||
if ( dev_priv ) { \
|
||||
tmp = I810_READ16( I810REG_INT_IDENTITY_R ); \
|
||||
tmp = tmp & ~(0x6000); /* Clear all interrupts */ \
|
||||
if ( tmp != 0 ) \
|
||||
I810_WRITE16( I810REG_INT_IDENTITY_R, tmp ); \
|
||||
\
|
||||
tmp = I810_READ16( I810REG_INT_ENABLE_R ); \
|
||||
tmp = tmp & 0x6000; /* Disable all interrupts */ \
|
||||
I810_WRITE16( I810REG_INT_ENABLE_R, tmp ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Buffer customization:
|
||||
*/
|
||||
|
||||
#define DRIVER_BUF_PRIV_T drm_i810_buf_priv_t
|
||||
|
||||
#define DRIVER_AGP_BUFFERS_MAP( dev ) \
|
||||
((drm_i810_private_t *)((dev)->dev_private))->buffer_map
|
||||
|
||||
#endif
|
||||
1220
bsd/i810/i810_dma.c
Normal file
1220
bsd/i810/i810_dma.c
Normal file
File diff suppressed because it is too large
Load diff
95
bsd/i810/i810_drv.c
Normal file
95
bsd/i810/i810_drv.c
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/* i810_drv.c -- I810 driver -*- linux-c -*-
|
||||
* Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Jeff Hartmann <jhartmann@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/bus.h>
|
||||
#include <pci/pcivar.h>
|
||||
#include <opt_drm_linux.h>
|
||||
|
||||
#include "i810.h"
|
||||
#include "drmP.h"
|
||||
#include "i810_drv.h"
|
||||
|
||||
#define DRIVER_AUTHOR "VA Linux Systems Inc."
|
||||
|
||||
#define DRIVER_NAME "i810"
|
||||
#define DRIVER_DESC "Intel i810"
|
||||
#define DRIVER_DATE "20010616"
|
||||
|
||||
#define DRIVER_MAJOR 1
|
||||
#define DRIVER_MINOR 2
|
||||
#define DRIVER_PATCHLEVEL 0
|
||||
|
||||
/* Device IDs unknown. Can someone help? anholt@teleport.com */
|
||||
drm_chipinfo_t DRM(devicelist)[] = {
|
||||
{0, 0, 0, NULL}
|
||||
};
|
||||
|
||||
#define DRIVER_IOCTLS \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I810_INIT)] = { i810_dma_init, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I810_VERTEX)] = { i810_dma_vertex, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I810_CLEAR)] = { i810_clear_bufs, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I810_FLUSH)] = { i810_flush_ioctl, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I810_GETAGE)] = { i810_getage, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I810_GETBUF)] = { i810_getbuf, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I810_SWAP)] = { i810_swap_bufs, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I810_COPY)] = { i810_copybuf, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I810_DOCOPY)] = { i810_docopy, 1, 0 },
|
||||
|
||||
|
||||
#define __HAVE_COUNTERS 4
|
||||
#define __HAVE_COUNTER6 _DRM_STAT_IRQ
|
||||
#define __HAVE_COUNTER7 _DRM_STAT_PRIMARY
|
||||
#define __HAVE_COUNTER8 _DRM_STAT_SECONDARY
|
||||
#define __HAVE_COUNTER9 _DRM_STAT_DMA
|
||||
|
||||
|
||||
#include "drm_agpsupport.h"
|
||||
#include "drm_auth.h"
|
||||
#include "drm_bufs.h"
|
||||
#include "drm_context.h"
|
||||
#include "drm_dma.h"
|
||||
#include "drm_drawable.h"
|
||||
#include "drm_drv.h"
|
||||
|
||||
|
||||
#include "drm_fops.h"
|
||||
#include "drm_init.h"
|
||||
#include "drm_ioctl.h"
|
||||
#include "drm_lock.h"
|
||||
#include "drm_lists.h"
|
||||
#include "drm_memory.h"
|
||||
#include "drm_vm.h"
|
||||
#include "drm_sysctl.h"
|
||||
|
||||
DRIVER_MODULE(i810, pci, i810_driver, i810_devclass, 0, 0);
|
||||
179
bsd/i810/i810_drv.h
Normal file
179
bsd/i810/i810_drv.h
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
/* i810_drv.h -- Private header for the Matrox g200/g400 driver -*- linux-c -*-
|
||||
* Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
|
||||
*
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors: Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Jeff Hartmann <jhartmann@valinux.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _I810_DRV_H_
|
||||
#define _I810_DRV_H_
|
||||
|
||||
typedef struct drm_i810_buf_priv {
|
||||
u32 *in_use;
|
||||
int my_use_idx;
|
||||
int currently_mapped;
|
||||
void *virtual;
|
||||
void *kernel_virtual;
|
||||
int map_count;
|
||||
struct vm_area_struct *vma;
|
||||
} drm_i810_buf_priv_t;
|
||||
|
||||
typedef struct _drm_i810_ring_buffer{
|
||||
int tail_mask;
|
||||
unsigned long Start;
|
||||
unsigned long End;
|
||||
unsigned long Size;
|
||||
u8 *virtual_start;
|
||||
int head;
|
||||
int tail;
|
||||
int space;
|
||||
} drm_i810_ring_buffer_t;
|
||||
|
||||
typedef struct drm_i810_private {
|
||||
drm_map_t *sarea_map;
|
||||
drm_map_t *buffer_map;
|
||||
drm_map_t *mmio_map;
|
||||
|
||||
drm_i810_sarea_t *sarea_priv;
|
||||
drm_i810_ring_buffer_t ring;
|
||||
|
||||
unsigned long hw_status_page;
|
||||
unsigned long counter;
|
||||
|
||||
atomic_t flush_done;
|
||||
wait_queue_head_t flush_queue; /* Processes waiting until flush */
|
||||
drm_buf_t *mmap_buffer;
|
||||
|
||||
|
||||
u32 front_di1, back_di1, zi1;
|
||||
|
||||
int back_offset;
|
||||
int depth_offset;
|
||||
int w, h;
|
||||
int pitch;
|
||||
} drm_i810_private_t;
|
||||
|
||||
/* i810_dma.c */
|
||||
extern int i810_dma_schedule(drm_device_t *dev, int locked);
|
||||
extern int i810_getbuf( DRM_OS_IOCTL );
|
||||
extern int i810_dma_init( DRM_OS_IOCTL );
|
||||
extern int i810_flush_ioctl( DRM_OS_IOCTL );
|
||||
extern int i810_getage( DRM_OS_IOCTL );
|
||||
extern int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma);
|
||||
extern int i810_copybuf( DRM_OS_IOCTL );
|
||||
extern int i810_docopy( DRM_OS_IOCTL );
|
||||
|
||||
extern void i810_dma_quiescent(drm_device_t *dev);
|
||||
|
||||
#define I810_VERBOSE 0
|
||||
|
||||
|
||||
int i810_dma_vertex( DRM_OS_IOCTL );
|
||||
int i810_swap_bufs( DRM_OS_IOCTL );
|
||||
int i810_clear_bufs( DRM_OS_IOCTL );
|
||||
|
||||
#define I810_BASE(reg) ((unsigned long) \
|
||||
dev_priv->mmio_map->handle)
|
||||
#define I810_ADDR(reg) (I810_BASE(reg) + reg)
|
||||
#define I810_DEREF(reg) *(__volatile__ int *)I810_ADDR(reg)
|
||||
#define I810_READ(reg) I810_DEREF(reg)
|
||||
#define I810_WRITE(reg,val) do { I810_DEREF(reg) = val; } while (0)
|
||||
#define I810_DEREF16(reg) *(__volatile__ u16 *)I810_ADDR(reg)
|
||||
#define I810_READ16(reg) I810_DEREF16(reg)
|
||||
#define I810_WRITE16(reg,val) do { I810_DEREF16(reg) = val; } while (0)
|
||||
|
||||
|
||||
#define GFX_OP_USER_INTERRUPT ((0<<29)|(2<<23))
|
||||
#define GFX_OP_BREAKPOINT_INTERRUPT ((0<<29)|(1<<23))
|
||||
#define CMD_REPORT_HEAD (7<<23)
|
||||
#define CMD_STORE_DWORD_IDX ((0x21<<23) | 0x1)
|
||||
#define CMD_OP_BATCH_BUFFER ((0x0<<29)|(0x30<<23)|0x1)
|
||||
|
||||
#define INST_PARSER_CLIENT 0x00000000
|
||||
#define INST_OP_FLUSH 0x02000000
|
||||
#define INST_FLUSH_MAP_CACHE 0x00000001
|
||||
|
||||
|
||||
#define BB1_START_ADDR_MASK (~0x7)
|
||||
#define BB1_PROTECTED (1<<0)
|
||||
#define BB1_UNPROTECTED (0<<0)
|
||||
#define BB2_END_ADDR_MASK (~0x7)
|
||||
|
||||
#define I810REG_HWSTAM 0x02098
|
||||
#define I810REG_INT_IDENTITY_R 0x020a4
|
||||
#define I810REG_INT_MASK_R 0x020a8
|
||||
#define I810REG_INT_ENABLE_R 0x020a0
|
||||
|
||||
#define LP_RING 0x2030
|
||||
#define HP_RING 0x2040
|
||||
#define RING_TAIL 0x00
|
||||
#define TAIL_ADDR 0x000FFFF8
|
||||
#define RING_HEAD 0x04
|
||||
#define HEAD_WRAP_COUNT 0xFFE00000
|
||||
#define HEAD_WRAP_ONE 0x00200000
|
||||
#define HEAD_ADDR 0x001FFFFC
|
||||
#define RING_START 0x08
|
||||
#define START_ADDR 0x00FFFFF8
|
||||
#define RING_LEN 0x0C
|
||||
#define RING_NR_PAGES 0x000FF000
|
||||
#define RING_REPORT_MASK 0x00000006
|
||||
#define RING_REPORT_64K 0x00000002
|
||||
#define RING_REPORT_128K 0x00000004
|
||||
#define RING_NO_REPORT 0x00000000
|
||||
#define RING_VALID_MASK 0x00000001
|
||||
#define RING_VALID 0x00000001
|
||||
#define RING_INVALID 0x00000000
|
||||
|
||||
#define GFX_OP_SCISSOR ((0x3<<29)|(0x1c<<24)|(0x10<<19))
|
||||
#define SC_UPDATE_SCISSOR (0x1<<1)
|
||||
#define SC_ENABLE_MASK (0x1<<0)
|
||||
#define SC_ENABLE (0x1<<0)
|
||||
|
||||
#define GFX_OP_SCISSOR_INFO ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
|
||||
#define SCI_YMIN_MASK (0xffff<<16)
|
||||
#define SCI_XMIN_MASK (0xffff<<0)
|
||||
#define SCI_YMAX_MASK (0xffff<<16)
|
||||
#define SCI_XMAX_MASK (0xffff<<0)
|
||||
|
||||
#define GFX_OP_COLOR_FACTOR ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
|
||||
#define GFX_OP_STIPPLE ((0x3<<29)|(0x1d<<24)|(0x83<<16))
|
||||
#define GFX_OP_MAP_INFO ((0x3<<29)|(0x1d<<24)|0x2)
|
||||
#define GFX_OP_DESTBUFFER_VARS ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
|
||||
#define GFX_OP_DRAWRECT_INFO ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
|
||||
#define GFX_OP_PRIMITIVE ((0x3<<29)|(0x1f<<24))
|
||||
|
||||
#define CMD_OP_Z_BUFFER_INFO ((0x0<<29)|(0x16<<23))
|
||||
#define CMD_OP_DESTBUFFER_INFO ((0x0<<29)|(0x15<<23))
|
||||
|
||||
#define BR00_BITBLT_CLIENT 0x40000000
|
||||
#define BR00_OP_COLOR_BLT 0x10000000
|
||||
#define BR00_OP_SRC_COPY_BLT 0x10C00000
|
||||
#define BR13_SOLID_PATTERN 0x80000000
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
25
bsd/i830/Makefile
Normal file
25
bsd/i830/Makefile
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# $FreeBSD$
|
||||
|
||||
KMOD= i830
|
||||
NOMAN= YES
|
||||
SRCS= i830_drv.c i830_dma.c
|
||||
SRCS+= device_if.h bus_if.h pci_if.h opt_drm_linux.h
|
||||
CFLAGS+= ${DEBUG_FLAGS} -I. -I..
|
||||
|
||||
@:
|
||||
ln -sf /sys @
|
||||
|
||||
machine:
|
||||
ln -sf /sys/i386/include machine
|
||||
|
||||
.if ${MACHINE_ARCH} == "i386"
|
||||
# This line enables linux ioctl handling
|
||||
# If you want support for this uncomment this line
|
||||
#I830_OPTS= "\#define DRM_LINUX" 1
|
||||
.endif
|
||||
|
||||
opt_drm_linux.h:
|
||||
touch opt_drm_linux.h
|
||||
echo $(I830_OPTS) >> opt_drm_linux.h
|
||||
|
||||
.include <bsd.kmod.mk>
|
||||
116
bsd/i830/i830.h
Normal file
116
bsd/i830/i830.h
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/* i830.h -- Intel I830 DRM template customization -*- linux-c -*-
|
||||
* Created: Thu Feb 15 00:01:12 2001 by gareth@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef __I830_H__
|
||||
#define __I830_H__
|
||||
|
||||
/* This remains constant for all DRM template files.
|
||||
*/
|
||||
#define DRM(x) i830_##x
|
||||
|
||||
/* General customization:
|
||||
*/
|
||||
#define __HAVE_AGP 1
|
||||
#define __MUST_HAVE_AGP 1
|
||||
#define __HAVE_MTRR 1
|
||||
#define __HAVE_CTX_BITMAP 1
|
||||
|
||||
/* Driver customization:
|
||||
*/
|
||||
#define __HAVE_RELEASE 1
|
||||
#define DRIVER_RELEASE() do { \
|
||||
i830_reclaim_buffers( dev, priv->pid ); \
|
||||
} while (0)
|
||||
|
||||
/* DMA customization:
|
||||
*/
|
||||
#define __HAVE_DMA 1
|
||||
#define __HAVE_DMA_QUEUE 1
|
||||
#define __HAVE_DMA_WAITLIST 1
|
||||
#define __HAVE_DMA_RECLAIM 1
|
||||
|
||||
#define __HAVE_DMA_QUIESCENT 1
|
||||
#define DRIVER_DMA_QUIESCENT() do { \
|
||||
i830_dma_quiescent( dev ); \
|
||||
} while (0)
|
||||
|
||||
#define __HAVE_DMA_IRQ 1
|
||||
#define __HAVE_DMA_IRQ_BH 1
|
||||
#define __HAVE_SHARED_IRQ 1
|
||||
#define DRIVER_PREINSTALL() do { \
|
||||
drm_i830_private_t *dev_priv = \
|
||||
(drm_i830_private_t *)dev->dev_private; \
|
||||
u16 tmp; \
|
||||
tmp = I830_READ16( I830REG_HWSTAM ); \
|
||||
tmp = tmp & 0x6000; \
|
||||
I830_WRITE16( I830REG_HWSTAM, tmp ); \
|
||||
\
|
||||
tmp = I830_READ16( I830REG_INT_MASK_R ); \
|
||||
tmp = tmp & 0x6000; /* Unmask interrupts */ \
|
||||
I830_WRITE16( I830REG_INT_MASK_R, tmp ); \
|
||||
tmp = I830_READ16( I830REG_INT_ENABLE_R ); \
|
||||
tmp = tmp & 0x6000; /* Disable all interrupts */ \
|
||||
I830_WRITE16( I830REG_INT_ENABLE_R, tmp ); \
|
||||
} while (0)
|
||||
|
||||
#define DRIVER_POSTINSTALL() do { \
|
||||
drm_i830_private_t *dev_priv = \
|
||||
(drm_i830_private_t *)dev->dev_private; \
|
||||
u16 tmp; \
|
||||
tmp = I830_READ16( I830REG_INT_ENABLE_R ); \
|
||||
tmp = tmp & 0x6000; \
|
||||
tmp = tmp | 0x0003; /* Enable bp & user interrupts */ \
|
||||
I830_WRITE16( I830REG_INT_ENABLE_R, tmp ); \
|
||||
} while (0)
|
||||
|
||||
#define DRIVER_UNINSTALL() do { \
|
||||
drm_i830_private_t *dev_priv = \
|
||||
(drm_i830_private_t *)dev->dev_private; \
|
||||
u16 tmp; \
|
||||
if ( dev_priv ) { \
|
||||
tmp = I830_READ16( I830REG_INT_IDENTITY_R ); \
|
||||
tmp = tmp & ~(0x6000); /* Clear all interrupts */ \
|
||||
if ( tmp != 0 ) \
|
||||
I830_WRITE16( I830REG_INT_IDENTITY_R, tmp ); \
|
||||
\
|
||||
tmp = I830_READ16( I830REG_INT_ENABLE_R ); \
|
||||
tmp = tmp & 0x6000; /* Disable all interrupts */ \
|
||||
I830_WRITE16( I830REG_INT_ENABLE_R, tmp ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Buffer customization:
|
||||
*/
|
||||
|
||||
#define DRIVER_BUF_PRIV_T drm_i830_buf_priv_t
|
||||
|
||||
#define DRIVER_AGP_BUFFERS_MAP( dev ) \
|
||||
((drm_i830_private_t *)((dev)->dev_private))->buffer_map
|
||||
|
||||
#endif
|
||||
1418
bsd/i830/i830_dma.c
Normal file
1418
bsd/i830/i830_dma.c
Normal file
File diff suppressed because it is too large
Load diff
102
bsd/i830/i830_drv.c
Normal file
102
bsd/i830/i830_drv.c
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/* i830_drv.c -- I810 driver -*- linux-c -*-
|
||||
* Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Jeff Hartmann <jhartmann@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
* Abraham vd Merwe <abraham@2d3d.co.za>
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include "i830.h"
|
||||
#include "drmP.h"
|
||||
#include "i830_drv.h"
|
||||
|
||||
#define DRIVER_AUTHOR "VA Linux Systems Inc."
|
||||
|
||||
#define DRIVER_NAME "i830"
|
||||
#define DRIVER_DESC "Intel 830M"
|
||||
#define DRIVER_DATE "20011004"
|
||||
|
||||
#define DRIVER_MAJOR 1
|
||||
#define DRIVER_MINOR 2
|
||||
#define DRIVER_PATCHLEVEL 0
|
||||
|
||||
#define DRIVER_IOCTLS \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_INIT)] = { i830_dma_init, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_VERTEX)] = { i830_dma_vertex, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_CLEAR)] = { i830_clear_bufs, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_FLUSH)] = { i830_flush_ioctl, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_GETAGE)] = { i830_getage, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_GETBUF)] = { i830_getbuf, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_SWAP)] = { i830_swap_bufs, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_COPY)] = { i830_copybuf, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_DOCOPY)] = { i830_docopy, 1, 0 },
|
||||
|
||||
#define __HAVE_COUNTERS 4
|
||||
#define __HAVE_COUNTER6 _DRM_STAT_IRQ
|
||||
#define __HAVE_COUNTER7 _DRM_STAT_PRIMARY
|
||||
#define __HAVE_COUNTER8 _DRM_STAT_SECONDARY
|
||||
#define __HAVE_COUNTER9 _DRM_STAT_DMA
|
||||
|
||||
|
||||
#include "drm_agpsupport.h"
|
||||
#include "drm_auth.h"
|
||||
#include "drm_bufs.h"
|
||||
#include "drm_context.h"
|
||||
#include "drm_dma.h"
|
||||
#include "drm_drawable.h"
|
||||
#include "drm_drv.h"
|
||||
|
||||
#ifndef MODULE
|
||||
/* DRM(options) is called by the kernel to parse command-line options
|
||||
* passed via the boot-loader (e.g., LILO). It calls the insmod option
|
||||
* routine, drm_parse_drm.
|
||||
*/
|
||||
|
||||
/* JH- We have to hand expand the string ourselves because of the cpp. If
|
||||
* anyone can think of a way that we can fit into the __setup macro without
|
||||
* changing it, then please send the solution my way.
|
||||
*/
|
||||
static int __init i830_options( char *str )
|
||||
{
|
||||
DRM(parse_options)( str );
|
||||
return 1;
|
||||
}
|
||||
|
||||
__setup( DRIVER_NAME "=", i830_options );
|
||||
#endif
|
||||
|
||||
#include "drm_fops.h"
|
||||
#include "drm_init.h"
|
||||
#include "drm_ioctl.h"
|
||||
#include "drm_lock.h"
|
||||
#include "drm_lists.h"
|
||||
#include "drm_memory.h"
|
||||
#include "drm_proc.h"
|
||||
#include "drm_vm.h"
|
||||
#include "drm_stub.h"
|
||||
213
bsd/i830/i830_drv.h
Normal file
213
bsd/i830/i830_drv.h
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
/* i830_drv.h -- Private header for the I830 driver -*- linux-c -*-
|
||||
* Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
|
||||
*
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors: Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Jeff Hartmann <jhartmann@valinux.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _I830_DRV_H_
|
||||
#define _I830_DRV_H_
|
||||
|
||||
typedef struct drm_i830_buf_priv {
|
||||
u32 *in_use;
|
||||
int my_use_idx;
|
||||
int currently_mapped;
|
||||
void *virtual;
|
||||
void *kernel_virtual;
|
||||
int map_count;
|
||||
struct vm_area_struct *vma;
|
||||
} drm_i830_buf_priv_t;
|
||||
|
||||
typedef struct _drm_i830_ring_buffer{
|
||||
int tail_mask;
|
||||
unsigned long Start;
|
||||
unsigned long End;
|
||||
unsigned long Size;
|
||||
u8 *virtual_start;
|
||||
int head;
|
||||
int tail;
|
||||
int space;
|
||||
} drm_i830_ring_buffer_t;
|
||||
|
||||
typedef struct drm_i830_private {
|
||||
drm_map_t *sarea_map;
|
||||
drm_map_t *buffer_map;
|
||||
drm_map_t *mmio_map;
|
||||
|
||||
drm_i830_sarea_t *sarea_priv;
|
||||
drm_i830_ring_buffer_t ring;
|
||||
|
||||
unsigned long hw_status_page;
|
||||
unsigned long counter;
|
||||
|
||||
atomic_t flush_done;
|
||||
wait_queue_head_t flush_queue; /* Processes waiting until flush */
|
||||
drm_buf_t *mmap_buffer;
|
||||
|
||||
u32 front_di1, back_di1, zi1;
|
||||
|
||||
int back_offset;
|
||||
int depth_offset;
|
||||
int w, h;
|
||||
int pitch;
|
||||
int back_pitch;
|
||||
int depth_pitch;
|
||||
unsigned int cpp;
|
||||
} drm_i830_private_t;
|
||||
|
||||
/* i830_dma.c */
|
||||
extern int i830_dma_schedule(drm_device_t *dev, int locked);
|
||||
extern int i830_getbuf(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int i830_dma_init(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int i830_flush_ioctl(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern void i830_reclaim_buffers(drm_device_t *dev, pid_t pid);
|
||||
extern int i830_getage(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg);
|
||||
extern int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma);
|
||||
extern int i830_copybuf(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int i830_docopy(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
extern void i830_dma_quiescent(drm_device_t *dev);
|
||||
|
||||
extern int i830_dma_vertex(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
extern int i830_swap_bufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
extern int i830_clear_bufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
#define I830_VERBOSE 0
|
||||
|
||||
#define I830_BASE(reg) ((unsigned long) \
|
||||
dev_priv->mmio_map->handle)
|
||||
#define I830_ADDR(reg) (I830_BASE(reg) + reg)
|
||||
#define I830_DEREF(reg) *(__volatile__ int *)I830_ADDR(reg)
|
||||
#define I830_READ(reg) I830_DEREF(reg)
|
||||
#define I830_WRITE(reg,val) do { I830_DEREF(reg) = val; } while (0)
|
||||
#define I830_DEREF16(reg) *(__volatile__ u16 *)I830_ADDR(reg)
|
||||
#define I830_READ16(reg) I830_DEREF16(reg)
|
||||
#define I830_WRITE16(reg,val) do { I830_DEREF16(reg) = val; } while (0)
|
||||
|
||||
#define GFX_OP_USER_INTERRUPT ((0<<29)|(2<<23))
|
||||
#define GFX_OP_BREAKPOINT_INTERRUPT ((0<<29)|(1<<23))
|
||||
#define CMD_REPORT_HEAD (7<<23)
|
||||
#define CMD_STORE_DWORD_IDX ((0x21<<23) | 0x1)
|
||||
#define CMD_OP_BATCH_BUFFER ((0x0<<29)|(0x30<<23)|0x1)
|
||||
|
||||
#define INST_PARSER_CLIENT 0x00000000
|
||||
#define INST_OP_FLUSH 0x02000000
|
||||
#define INST_FLUSH_MAP_CACHE 0x00000001
|
||||
|
||||
|
||||
#define BB1_START_ADDR_MASK (~0x7)
|
||||
#define BB1_PROTECTED (1<<0)
|
||||
#define BB1_UNPROTECTED (0<<0)
|
||||
#define BB2_END_ADDR_MASK (~0x7)
|
||||
|
||||
#define I830REG_HWSTAM 0x02098
|
||||
#define I830REG_INT_IDENTITY_R 0x020a4
|
||||
#define I830REG_INT_MASK_R 0x020a8
|
||||
#define I830REG_INT_ENABLE_R 0x020a0
|
||||
|
||||
#define LP_RING 0x2030
|
||||
#define HP_RING 0x2040
|
||||
#define RING_TAIL 0x00
|
||||
#define TAIL_ADDR 0x000FFFF8
|
||||
#define RING_HEAD 0x04
|
||||
#define HEAD_WRAP_COUNT 0xFFE00000
|
||||
#define HEAD_WRAP_ONE 0x00200000
|
||||
#define HEAD_ADDR 0x001FFFFC
|
||||
#define RING_START 0x08
|
||||
#define START_ADDR 0x00FFFFF8
|
||||
#define RING_LEN 0x0C
|
||||
#define RING_NR_PAGES 0x000FF000
|
||||
#define RING_REPORT_MASK 0x00000006
|
||||
#define RING_REPORT_64K 0x00000002
|
||||
#define RING_REPORT_128K 0x00000004
|
||||
#define RING_NO_REPORT 0x00000000
|
||||
#define RING_VALID_MASK 0x00000001
|
||||
#define RING_VALID 0x00000001
|
||||
#define RING_INVALID 0x00000000
|
||||
|
||||
#define GFX_OP_SCISSOR ((0x3<<29)|(0x1c<<24)|(0x10<<19))
|
||||
#define SC_UPDATE_SCISSOR (0x1<<1)
|
||||
#define SC_ENABLE_MASK (0x1<<0)
|
||||
#define SC_ENABLE (0x1<<0)
|
||||
|
||||
#define GFX_OP_SCISSOR_INFO ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
|
||||
#define SCI_YMIN_MASK (0xffff<<16)
|
||||
#define SCI_XMIN_MASK (0xffff<<0)
|
||||
#define SCI_YMAX_MASK (0xffff<<16)
|
||||
#define SCI_XMAX_MASK (0xffff<<0)
|
||||
|
||||
#define GFX_OP_SCISSOR_ENABLE ((0x3<<29)|(0x1c<<24)|(0x10<<19))
|
||||
#define GFX_OP_SCISSOR_RECT ((0x3<<29)|(0x1d<<24)|(0x81<<16)|1)
|
||||
#define GFX_OP_COLOR_FACTOR ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
|
||||
#define GFX_OP_STIPPLE ((0x3<<29)|(0x1d<<24)|(0x83<<16))
|
||||
#define GFX_OP_MAP_INFO ((0x3<<29)|(0x1d<<24)|0x4)
|
||||
#define GFX_OP_DESTBUFFER_VARS ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
|
||||
#define GFX_OP_DRAWRECT_INFO ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
|
||||
#define GFX_OP_PRIMITIVE ((0x3<<29)|(0x1f<<24))
|
||||
|
||||
#define CMD_OP_DESTBUFFER_INFO ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1)
|
||||
|
||||
|
||||
#define BR00_BITBLT_CLIENT 0x40000000
|
||||
#define BR00_OP_COLOR_BLT 0x10000000
|
||||
#define BR00_OP_SRC_COPY_BLT 0x10C00000
|
||||
#define BR13_SOLID_PATTERN 0x80000000
|
||||
|
||||
#define BUF_3D_ID_COLOR_BACK (0x3<<24)
|
||||
#define BUF_3D_ID_DEPTH (0x7<<24)
|
||||
#define BUF_3D_USE_FENCE (1<<23)
|
||||
#define BUF_3D_PITCH(x) (((x)/4)<<2)
|
||||
|
||||
#define CMD_OP_MAP_PALETTE_LOAD ((3<<29)|(0x1d<<24)|(0x82<<16)|255)
|
||||
#define MAP_PALETTE_NUM(x) ((x<<8) & (1<<8))
|
||||
#define MAP_PALETTE_BOTH (1<<11)
|
||||
|
||||
#define XY_COLOR_BLT_CMD ((2<<29)|(0x50<<22)|0x4)
|
||||
#define XY_COLOR_BLT_WRITE_ALPHA (1<<21)
|
||||
#define XY_COLOR_BLT_WRITE_RGB (1<<20)
|
||||
|
||||
#define XY_SRC_COPY_BLT_CMD ((2<<29)|(0x53<<22)|6)
|
||||
#define XY_SRC_COPY_BLT_WRITE_ALPHA (1<<21)
|
||||
#define XY_SRC_COPY_BLT_WRITE_RGB (1<<20)
|
||||
|
||||
#define MI_BATCH_BUFFER ((0x30<<23)|1)
|
||||
#define MI_BATCH_NON_SECURE (1)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
238
bsd/i830_drm.h
Normal file
238
bsd/i830_drm.h
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
#ifndef _I830_DRM_H_
|
||||
#define _I830_DRM_H_
|
||||
|
||||
/* WARNING: These defines must be the same as what the Xserver uses.
|
||||
* if you change them, you must change the defines in the Xserver.
|
||||
*/
|
||||
|
||||
#ifndef _I830_DEFINES_
|
||||
#define _I830_DEFINES_
|
||||
|
||||
#define I830_DMA_BUF_ORDER 12
|
||||
#define I830_DMA_BUF_SZ (1<<I830_DMA_BUF_ORDER)
|
||||
#define I830_DMA_BUF_NR 256
|
||||
#define I830_NR_SAREA_CLIPRECTS 8
|
||||
|
||||
/* Each region is a minimum of 64k, and there are at most 64 of them.
|
||||
*/
|
||||
#define I830_NR_TEX_REGIONS 64
|
||||
#define I830_LOG_MIN_TEX_REGION_SIZE 16
|
||||
|
||||
/* if defining I830_ENABLE_4_TEXTURES, do it in i830_3d_reg.h, too */
|
||||
#if !defined(I830_ENABLE_4_TEXTURES)
|
||||
#define I830_TEXTURE_COUNT 2
|
||||
#define I830_TEXBLEND_COUNT 2 /* always same as TEXTURE_COUNT? */
|
||||
#else /* defined(I830_ENABLE_4_TEXTURES) */
|
||||
#define I830_TEXTURE_COUNT 4
|
||||
#define I830_TEXBLEND_COUNT 4 /* always same as TEXTURE_COUNT? */
|
||||
#endif /* I830_ENABLE_4_TEXTURES */
|
||||
|
||||
#define I830_TEXBLEND_SIZE 12 /* (4 args + op) * 2 + COLOR_FACTOR */
|
||||
|
||||
#define I830_UPLOAD_CTX 0x1
|
||||
#define I830_UPLOAD_BUFFERS 0x2
|
||||
#define I830_UPLOAD_CLIPRECTS 0x4
|
||||
#define I830_UPLOAD_TEX0_IMAGE 0x100 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX0_CUBE 0x200 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX1_IMAGE 0x400 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX1_CUBE 0x800 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX2_IMAGE 0x1000 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX2_CUBE 0x2000 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX3_IMAGE 0x4000 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX3_CUBE 0x8000 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX_N_IMAGE(n) (0x100 << (n * 2))
|
||||
#define I830_UPLOAD_TEX_N_CUBE(n) (0x200 << (n * 2))
|
||||
#define I830_UPLOAD_TEXIMAGE_MASK 0xff00
|
||||
#define I830_UPLOAD_TEX0 0x10000
|
||||
#define I830_UPLOAD_TEX1 0x20000
|
||||
#define I830_UPLOAD_TEX2 0x40000
|
||||
#define I830_UPLOAD_TEX3 0x80000
|
||||
#define I830_UPLOAD_TEX_N(n) (0x10000 << (n))
|
||||
#define I830_UPLOAD_TEX_MASK 0xf0000
|
||||
#define I830_UPLOAD_TEXBLEND0 0x100000
|
||||
#define I830_UPLOAD_TEXBLEND1 0x200000
|
||||
#define I830_UPLOAD_TEXBLEND2 0x400000
|
||||
#define I830_UPLOAD_TEXBLEND3 0x800000
|
||||
#define I830_UPLOAD_TEXBLEND_N(n) (0x100000 << (n))
|
||||
#define I830_UPLOAD_TEXBLEND_MASK 0xf00000
|
||||
#define I830_UPLOAD_TEX_PALETTE_N(n) (0x1000000 << (n))
|
||||
#define I830_UPLOAD_TEX_PALETTE_SHARED 0x4000000
|
||||
|
||||
/* Indices into buf.Setup where various bits of state are mirrored per
|
||||
* context and per buffer. These can be fired at the card as a unit,
|
||||
* or in a piecewise fashion as required.
|
||||
*/
|
||||
|
||||
/* Destbuffer state
|
||||
* - backbuffer linear offset and pitch -- invarient in the current dri
|
||||
* - zbuffer linear offset and pitch -- also invarient
|
||||
* - drawing origin in back and depth buffers.
|
||||
*
|
||||
* Keep the depth/back buffer state here to acommodate private buffers
|
||||
* in the future.
|
||||
*/
|
||||
|
||||
#define I830_DESTREG_CBUFADDR 0
|
||||
/* Invarient */
|
||||
#define I830_DESTREG_DBUFADDR 1
|
||||
#define I830_DESTREG_DV0 2
|
||||
#define I830_DESTREG_DV1 3
|
||||
#define I830_DESTREG_SENABLE 4
|
||||
#define I830_DESTREG_SR0 5
|
||||
#define I830_DESTREG_SR1 6
|
||||
#define I830_DESTREG_SR2 7
|
||||
#define I830_DESTREG_DR0 8
|
||||
#define I830_DESTREG_DR1 9
|
||||
#define I830_DESTREG_DR2 10
|
||||
#define I830_DESTREG_DR3 11
|
||||
#define I830_DESTREG_DR4 12
|
||||
#define I830_DEST_SETUP_SIZE 13
|
||||
|
||||
/* Context state
|
||||
*/
|
||||
#define I830_CTXREG_STATE1 0
|
||||
#define I830_CTXREG_STATE2 1
|
||||
#define I830_CTXREG_STATE3 2
|
||||
#define I830_CTXREG_STATE4 3
|
||||
#define I830_CTXREG_STATE5 4
|
||||
#define I830_CTXREG_IALPHAB 5
|
||||
#define I830_CTXREG_STENCILTST 6
|
||||
#define I830_CTXREG_ENABLES_1 7
|
||||
#define I830_CTXREG_ENABLES_2 8
|
||||
#define I830_CTXREG_AA 9
|
||||
#define I830_CTXREG_FOGCOLOR 10
|
||||
#define I830_CTXREG_BLENDCOLR0 11
|
||||
#define I830_CTXREG_BLENDCOLR 12 /* Dword 1 of 2 dword command */
|
||||
#define I830_CTXREG_VF 13
|
||||
#define I830_CTXREG_VF2 14
|
||||
#define I830_CTXREG_MCSB0 15
|
||||
#define I830_CTXREG_MCSB1 16
|
||||
#define I830_CTX_SETUP_SIZE 17
|
||||
|
||||
/* Texture state (per tex unit)
|
||||
*/
|
||||
|
||||
#define I830_TEXREG_MI0 0 /* GFX_OP_MAP_INFO (6 dwords) */
|
||||
#define I830_TEXREG_MI1 1
|
||||
#define I830_TEXREG_MI2 2
|
||||
#define I830_TEXREG_MI3 3
|
||||
#define I830_TEXREG_MI4 4
|
||||
#define I830_TEXREG_MI5 5
|
||||
#define I830_TEXREG_MF 6 /* GFX_OP_MAP_FILTER */
|
||||
#define I830_TEXREG_MLC 7 /* GFX_OP_MAP_LOD_CTL */
|
||||
#define I830_TEXREG_MLL 8 /* GFX_OP_MAP_LOD_LIMITS */
|
||||
#define I830_TEXREG_MCS 9 /* GFX_OP_MAP_COORD_SETS */
|
||||
#define I830_TEX_SETUP_SIZE 10
|
||||
|
||||
#define I830_FRONT 0x1
|
||||
#define I830_BACK 0x2
|
||||
#define I830_DEPTH 0x4
|
||||
|
||||
#endif /* _I830_DEFINES_ */
|
||||
|
||||
typedef struct _drm_i830_init {
|
||||
enum {
|
||||
I830_INIT_DMA = 0x01,
|
||||
I830_CLEANUP_DMA = 0x02
|
||||
} func;
|
||||
unsigned int mmio_offset;
|
||||
unsigned int buffers_offset;
|
||||
int sarea_priv_offset;
|
||||
unsigned int ring_start;
|
||||
unsigned int ring_end;
|
||||
unsigned int ring_size;
|
||||
unsigned int front_offset;
|
||||
unsigned int back_offset;
|
||||
unsigned int depth_offset;
|
||||
unsigned int w;
|
||||
unsigned int h;
|
||||
unsigned int pitch;
|
||||
unsigned int pitch_bits;
|
||||
unsigned int back_pitch;
|
||||
unsigned int depth_pitch;
|
||||
unsigned int cpp;
|
||||
} drm_i830_init_t;
|
||||
|
||||
/* Warning: If you change the SAREA structure you must change the Xserver
|
||||
* structure as well */
|
||||
|
||||
typedef struct _drm_i830_tex_region {
|
||||
unsigned char next, prev; /* indices to form a circular LRU */
|
||||
unsigned char in_use; /* owned by a client, or free? */
|
||||
int age; /* tracked by clients to update local LRU's */
|
||||
} drm_i830_tex_region_t;
|
||||
|
||||
typedef struct _drm_i830_sarea {
|
||||
unsigned int ContextState[I830_CTX_SETUP_SIZE];
|
||||
unsigned int BufferState[I830_DEST_SETUP_SIZE];
|
||||
unsigned int TexState[I830_TEXTURE_COUNT][I830_TEX_SETUP_SIZE];
|
||||
unsigned int TexBlendState[I830_TEXBLEND_COUNT][I830_TEXBLEND_SIZE];
|
||||
unsigned int TexBlendStateWordsUsed[I830_TEXBLEND_COUNT];
|
||||
unsigned int Palette[2][256];
|
||||
unsigned int dirty;
|
||||
|
||||
unsigned int nbox;
|
||||
drm_clip_rect_t boxes[I830_NR_SAREA_CLIPRECTS];
|
||||
|
||||
/* Maintain an LRU of contiguous regions of texture space. If
|
||||
* you think you own a region of texture memory, and it has an
|
||||
* age different to the one you set, then you are mistaken and
|
||||
* it has been stolen by another client. If global texAge
|
||||
* hasn't changed, there is no need to walk the list.
|
||||
*
|
||||
* These regions can be used as a proxy for the fine-grained
|
||||
* texture information of other clients - by maintaining them
|
||||
* in the same lru which is used to age their own textures,
|
||||
* clients have an approximate lru for the whole of global
|
||||
* texture space, and can make informed decisions as to which
|
||||
* areas to kick out. There is no need to choose whether to
|
||||
* kick out your own texture or someone else's - simply eject
|
||||
* them all in LRU order.
|
||||
*/
|
||||
|
||||
drm_i830_tex_region_t texList[I830_NR_TEX_REGIONS+1];
|
||||
/* Last elt is sentinal */
|
||||
int texAge; /* last time texture was uploaded */
|
||||
int last_enqueue; /* last time a buffer was enqueued */
|
||||
int last_dispatch; /* age of the most recently dispatched buffer */
|
||||
int last_quiescent; /* */
|
||||
int ctxOwner; /* last context to upload state */
|
||||
|
||||
int vertex_prim;
|
||||
} drm_i830_sarea_t;
|
||||
|
||||
typedef struct _drm_i830_clear {
|
||||
int clear_color;
|
||||
int clear_depth;
|
||||
int flags;
|
||||
unsigned int clear_colormask;
|
||||
unsigned int clear_depthmask;
|
||||
} drm_i830_clear_t;
|
||||
|
||||
|
||||
|
||||
/* These may be placeholders if we have more cliprects than
|
||||
* I830_NR_SAREA_CLIPRECTS. In that case, the client sets discard to
|
||||
* false, indicating that the buffer will be dispatched again with a
|
||||
* new set of cliprects.
|
||||
*/
|
||||
typedef struct _drm_i830_vertex {
|
||||
int idx; /* buffer index */
|
||||
int used; /* nr bytes in use */
|
||||
int discard; /* client is finished with the buffer? */
|
||||
} drm_i830_vertex_t;
|
||||
|
||||
typedef struct _drm_i830_copy_t {
|
||||
int idx; /* buffer index */
|
||||
int used; /* nr bytes in use */
|
||||
void *address; /* Address to copy from */
|
||||
} drm_i830_copy_t;
|
||||
|
||||
typedef struct drm_i830_dma {
|
||||
void *virtual;
|
||||
int request_idx;
|
||||
int request_size;
|
||||
int granted;
|
||||
} drm_i830_dma_t;
|
||||
|
||||
#endif /* _I830_DRM_H_ */
|
||||
67
bsd/mga/mga.h
Normal file
67
bsd/mga/mga.h
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/* mga.h -- Matrox G200/G400 DRM template customization -*- linux-c -*-
|
||||
* Created: Thu Jan 11 21:29:32 2001 by gareth@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef __MGA_H__
|
||||
#define __MGA_H__
|
||||
|
||||
/* This remains constant for all DRM template files.
|
||||
*/
|
||||
#define DRM(x) mga_##x
|
||||
|
||||
/* General customization:
|
||||
*/
|
||||
#define __HAVE_AGP 1
|
||||
#define __MUST_HAVE_AGP 1
|
||||
#define __HAVE_MTRR 1
|
||||
#define __HAVE_CTX_BITMAP 1
|
||||
|
||||
/* Driver customization:
|
||||
*/
|
||||
#define DRIVER_PRETAKEDOWN() do { \
|
||||
if ( dev->dev_private ) mga_do_cleanup_dma( dev ); \
|
||||
} while (0)
|
||||
|
||||
/* DMA customization:
|
||||
*/
|
||||
#define __HAVE_DMA 1
|
||||
|
||||
#define __HAVE_DMA_QUIESCENT 1
|
||||
#define DRIVER_DMA_QUIESCENT() do { \
|
||||
drm_mga_private_t *dev_priv = dev->dev_private; \
|
||||
return mga_do_wait_for_idle( dev_priv ); \
|
||||
} while (0)
|
||||
|
||||
/* Buffer customization:
|
||||
*/
|
||||
#define DRIVER_BUF_PRIV_T drm_mga_buf_priv_t
|
||||
|
||||
#define DRIVER_AGP_BUFFERS_MAP( dev ) \
|
||||
((drm_mga_private_t *)((dev)->dev_private))->buffers
|
||||
|
||||
#endif
|
||||
11645
bsd/mga/mga_ucode.h
Normal file
11645
bsd/mga/mga_ucode.h
Normal file
File diff suppressed because it is too large
Load diff
210
bsd/mga/mga_warp.c
Normal file
210
bsd/mga/mga_warp.c
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
/* mga_warp.c -- Matrox G200/G400 WARP engine management -*- linux-c -*-
|
||||
* Created: Thu Jan 11 21:29:32 2001 by gareth@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "mga.h"
|
||||
#include "drmP.h"
|
||||
#include "mga_drv.h"
|
||||
#include "mga_ucode.h"
|
||||
|
||||
|
||||
#define MGA_WARP_CODE_ALIGN 256 /* in bytes */
|
||||
|
||||
#define WARP_UCODE_SIZE( which ) \
|
||||
((sizeof(which) / MGA_WARP_CODE_ALIGN + 1) * MGA_WARP_CODE_ALIGN)
|
||||
|
||||
#define WARP_UCODE_INSTALL( which, where ) \
|
||||
do { \
|
||||
DRM_DEBUG( " pcbase = 0x%08lx vcbase = %p\n", pcbase, vcbase );\
|
||||
dev_priv->warp_pipe_phys[where] = pcbase; \
|
||||
memcpy( vcbase, which, sizeof(which) ); \
|
||||
pcbase += WARP_UCODE_SIZE( which ); \
|
||||
vcbase += WARP_UCODE_SIZE( which ); \
|
||||
} while (0)
|
||||
|
||||
|
||||
static unsigned int mga_warp_g400_microcode_size( drm_mga_private_t *dev_priv )
|
||||
{
|
||||
unsigned int size;
|
||||
|
||||
size = ( WARP_UCODE_SIZE( warp_g400_tgz ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgza ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgzaf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgzf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgzs ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgzsa ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgzsaf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgzsf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gz ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gza ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gzaf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gzf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gzs ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gzsa ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gzsaf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gzsf ) );
|
||||
|
||||
size = PAGE_ALIGN( size );
|
||||
|
||||
DRM_DEBUG( "G400 ucode size = %d bytes\n", size );
|
||||
return size;
|
||||
}
|
||||
|
||||
static unsigned int mga_warp_g200_microcode_size( drm_mga_private_t *dev_priv )
|
||||
{
|
||||
unsigned int size;
|
||||
|
||||
size = ( WARP_UCODE_SIZE( warp_g200_tgz ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgza ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgzaf ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgzf ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgzs ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgzsa ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgzsaf ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgzsf ) );
|
||||
|
||||
size = PAGE_ALIGN( size );
|
||||
|
||||
DRM_DEBUG( "G200 ucode size = %d bytes\n", size );
|
||||
return size;
|
||||
}
|
||||
|
||||
static int mga_warp_install_g400_microcode( drm_mga_private_t *dev_priv )
|
||||
{
|
||||
unsigned char *vcbase = dev_priv->warp->handle;
|
||||
unsigned long pcbase = dev_priv->warp->offset;
|
||||
unsigned int size;
|
||||
|
||||
size = mga_warp_g400_microcode_size( dev_priv );
|
||||
if ( size > dev_priv->warp->size ) {
|
||||
DRM_ERROR( "microcode too large! (%u > %lu)\n",
|
||||
size, dev_priv->warp->size );
|
||||
DRM_OS_RETURN(ENOMEM);
|
||||
}
|
||||
|
||||
memset( dev_priv->warp_pipe_phys, 0,
|
||||
sizeof(dev_priv->warp_pipe_phys) );
|
||||
|
||||
WARP_UCODE_INSTALL( warp_g400_tgz, MGA_WARP_TGZ );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgzf, MGA_WARP_TGZF );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgza, MGA_WARP_TGZA );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgzaf, MGA_WARP_TGZAF );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgzs, MGA_WARP_TGZS );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgzsf, MGA_WARP_TGZSF );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgzsa, MGA_WARP_TGZSA );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgzsaf, MGA_WARP_TGZSAF );
|
||||
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gz, MGA_WARP_T2GZ );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gzf, MGA_WARP_T2GZF );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gza, MGA_WARP_T2GZA );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gzaf, MGA_WARP_T2GZAF );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gzs, MGA_WARP_T2GZS );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gzsf, MGA_WARP_T2GZSF );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gzsa, MGA_WARP_T2GZSA );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gzsaf, MGA_WARP_T2GZSAF );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mga_warp_install_g200_microcode( drm_mga_private_t *dev_priv )
|
||||
{
|
||||
unsigned char *vcbase = dev_priv->warp->handle;
|
||||
unsigned long pcbase = dev_priv->warp->offset;
|
||||
unsigned int size;
|
||||
|
||||
size = mga_warp_g200_microcode_size( dev_priv );
|
||||
if ( size > dev_priv->warp->size ) {
|
||||
DRM_ERROR( "microcode too large! (%u > %lu)\n",
|
||||
size, dev_priv->warp->size );
|
||||
DRM_OS_RETURN(ENOMEM);
|
||||
}
|
||||
|
||||
memset( dev_priv->warp_pipe_phys, 0,
|
||||
sizeof(dev_priv->warp_pipe_phys) );
|
||||
|
||||
WARP_UCODE_INSTALL( warp_g200_tgz, MGA_WARP_TGZ );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgzf, MGA_WARP_TGZF );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgza, MGA_WARP_TGZA );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgzaf, MGA_WARP_TGZAF );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgzs, MGA_WARP_TGZS );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgzsf, MGA_WARP_TGZSF );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgzsa, MGA_WARP_TGZSA );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgzsaf, MGA_WARP_TGZSAF );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_warp_install_microcode( drm_mga_private_t *dev_priv )
|
||||
{
|
||||
switch ( dev_priv->chipset ) {
|
||||
case MGA_CARD_TYPE_G400:
|
||||
return mga_warp_install_g400_microcode( dev_priv );
|
||||
case MGA_CARD_TYPE_G200:
|
||||
return mga_warp_install_g200_microcode( dev_priv );
|
||||
default:
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
}
|
||||
|
||||
#define WMISC_EXPECTED (MGA_WUCODECACHE_ENABLE | MGA_WMASTER_ENABLE)
|
||||
|
||||
int mga_warp_init( drm_mga_private_t *dev_priv )
|
||||
{
|
||||
u32 wmisc;
|
||||
|
||||
/* FIXME: Get rid of these damned magic numbers...
|
||||
*/
|
||||
switch ( dev_priv->chipset ) {
|
||||
case MGA_CARD_TYPE_G400:
|
||||
MGA_WRITE( MGA_WIADDR2, MGA_WMODE_SUSPEND );
|
||||
MGA_WRITE( MGA_WGETMSB, 0x00000E00 );
|
||||
MGA_WRITE( MGA_WVRTXSZ, 0x00001807 );
|
||||
MGA_WRITE( MGA_WACCEPTSEQ, 0x18000000 );
|
||||
break;
|
||||
case MGA_CARD_TYPE_G200:
|
||||
MGA_WRITE( MGA_WIADDR, MGA_WMODE_SUSPEND );
|
||||
MGA_WRITE( MGA_WGETMSB, 0x1606 );
|
||||
MGA_WRITE( MGA_WVRTXSZ, 7 );
|
||||
break;
|
||||
default:
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
MGA_WRITE( MGA_WMISC, (MGA_WUCODECACHE_ENABLE |
|
||||
MGA_WMASTER_ENABLE |
|
||||
MGA_WCACHEFLUSH_ENABLE) );
|
||||
wmisc = MGA_READ( MGA_WMISC );
|
||||
if ( wmisc != WMISC_EXPECTED ) {
|
||||
DRM_ERROR( "WARP engine config failed! 0x%x != 0x%x\n",
|
||||
wmisc, WMISC_EXPECTED );
|
||||
DRM_OS_RETURN(EINVAL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
81
bsd/r128/r128.h
Normal file
81
bsd/r128/r128.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* r128.h -- ATI Rage 128 DRM template customization -*- linux-c -*-
|
||||
* Created: Wed Feb 14 16:07:10 2001 by gareth@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef __R128_H__
|
||||
#define __R128_H__
|
||||
|
||||
/* This remains constant for all DRM template files.
|
||||
*/
|
||||
#define DRM(x) r128_##x
|
||||
|
||||
/* General customization:
|
||||
*/
|
||||
#define __HAVE_AGP 1
|
||||
#define __MUST_HAVE_AGP 0
|
||||
#define __HAVE_MTRR 1
|
||||
#define __HAVE_CTX_BITMAP 1
|
||||
#define __HAVE_SG 1
|
||||
#define __HAVE_PCI_DMA 1
|
||||
|
||||
/* Driver customization:
|
||||
*/
|
||||
#define DRIVER_PRERELEASE() do { \
|
||||
if ( dev->dev_private ) { \
|
||||
drm_r128_private_t *dev_priv = dev->dev_private; \
|
||||
if ( dev_priv->page_flipping ) { \
|
||||
r128_do_cleanup_pageflip( dev ); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define DRIVER_PRETAKEDOWN() do { \
|
||||
if ( dev->dev_private ) r128_do_cleanup_cce( dev ); \
|
||||
} while (0)
|
||||
|
||||
/* DMA customization:
|
||||
*/
|
||||
#define __HAVE_DMA 1
|
||||
|
||||
#if 0
|
||||
/* GH: Remove this for now... */
|
||||
#define __HAVE_DMA_QUIESCENT 1
|
||||
#define DRIVER_DMA_QUIESCENT() do { \
|
||||
drm_r128_private_t *dev_priv = dev->dev_private; \
|
||||
return r128_do_cce_idle( dev_priv ); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
/* Buffer customization:
|
||||
*/
|
||||
#define DRIVER_BUF_PRIV_T drm_r128_buf_priv_t
|
||||
|
||||
#define DRIVER_AGP_BUFFERS_MAP( dev ) \
|
||||
((drm_r128_private_t *)((dev)->dev_private))->buffers
|
||||
|
||||
#endif
|
||||
1022
bsd/r128/r128_cce.c
Normal file
1022
bsd/r128/r128_cce.c
Normal file
File diff suppressed because it is too large
Load diff
151
bsd/r128/r128_drv.c
Normal file
151
bsd/r128/r128_drv.c
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
/* r128_drv.c -- ATI Rage 128 driver -*- linux-c -*-
|
||||
* Created: Mon Dec 13 09:47:27 1999 by faith@precisioninsight.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/bus.h>
|
||||
#include <pci/pcivar.h>
|
||||
#include <opt_drm_linux.h>
|
||||
|
||||
#include "r128.h"
|
||||
#include "drmP.h"
|
||||
#include "r128_drv.h"
|
||||
#if __REALLY_HAVE_SG
|
||||
#include "ati_pcigart.h"
|
||||
#endif
|
||||
|
||||
#define DRIVER_AUTHOR "Gareth Hughes, VA Linux Systems Inc."
|
||||
|
||||
#define DRIVER_NAME "r128"
|
||||
#define DRIVER_DESC "ATI Rage 128"
|
||||
#define DRIVER_DATE "20010405"
|
||||
|
||||
#define DRIVER_MAJOR 2
|
||||
#define DRIVER_MINOR 2
|
||||
#define DRIVER_PATCHLEVEL 0
|
||||
|
||||
/* List acquired from http://www.yourvote.com/pci/pcihdr.h and xc/xc/programs/Xserver/hw/xfree86/common/xf86PciInfo.h
|
||||
* Please report to anholt@teleport.com inaccuracies or if a chip you have works that is marked unsupported here.
|
||||
*/
|
||||
drm_chipinfo_t DRM(devicelist)[] = {
|
||||
{0x1002, 0x4c45, 1, "ATI Rage 128 Mobility LE"},
|
||||
{0x1002, 0x4c46, 1, "ATI Rage 128 Mobility LF"},
|
||||
{0x1002, 0x4d46, 1, "ATI Rage 128 Mobility MF (AGP 4x)"},
|
||||
{0x1002, 0x4d4c, 1, "ATI Rage 128 Mobility ML"},
|
||||
{0x1002, 0x5041, 0, "ATI Rage 128 Pro PA (PCI)"},
|
||||
{0x1002, 0x5042, 1, "ATI Rage 128 Pro PB (AGP 2x)"},
|
||||
{0x1002, 0x5043, 1, "ATI Rage 128 Pro PC (AGP 4x)"},
|
||||
{0x1002, 0x5044, 0, "ATI Rage 128 Pro PD (PCI)"},
|
||||
{0x1002, 0x5045, 1, "ATI Rage 128 Pro PE (AGP 2x)"},
|
||||
{0x1002, 0x5046, 1, "ATI Rage 128 Pro PF (AGP 4x)"},
|
||||
{0x1002, 0x5047, 0, "ATI Rage 128 Pro PG (PCI)"},
|
||||
{0x1002, 0x5048, 1, "ATI Rage 128 Pro PH (AGP)"},
|
||||
{0x1002, 0x5049, 1, "ATI Rage 128 Pro PI (AGP)"},
|
||||
{0x1002, 0x504a, 0, "ATI Rage 128 Pro PJ (PCI)"},
|
||||
{0x1002, 0x504b, 1, "ATI Rage 128 Pro PK (AGP)"},
|
||||
{0x1002, 0x504c, 1, "ATI Rage 128 Pro PL (AGP)"},
|
||||
{0x1002, 0x504d, 0, "ATI Rage 128 Pro PM (PCI)"},
|
||||
{0x1002, 0x504e, 1, "ATI Rage 128 Pro PN (AGP)"},
|
||||
{0x1002, 0x505f, 1, "ATI Rage 128 Pro PO (AGP)"},
|
||||
{0x1002, 0x5050, 0, "ATI Rage 128 Pro PP (PCI)"},
|
||||
{0x1002, 0x5051, 1, "ATI Rage 128 Pro PQ (AGP)"},
|
||||
{0x1002, 0x5052, 1, "ATI Rage 128 Pro PR (AGP)"},
|
||||
{0x1002, 0x5053, 0, "ATI Rage 128 Pro PS (PCI)"},
|
||||
{0x1002, 0x5054, 1, "ATI Rage 128 Pro PT (AGP)"},
|
||||
{0x1002, 0x5055, 1, "ATI Rage 128 Pro PU (AGP)"},
|
||||
{0x1002, 0x5056, 0, "ATI Rage 128 Pro PV (PCI)"},
|
||||
{0x1002, 0x5057, 1, "ATI Rage 128 Pro PW (AGP)"},
|
||||
{0x1002, 0x5058, 1, "ATI Rage 128 Pro PX (AGP)"},
|
||||
{0x1002, 0x5245, 0, "ATI Rage 128 GL (PCI)"},
|
||||
{0x1002, 0x5246, 1, "ATI Rage 128 GL (AGP 2x)"},
|
||||
{0x1002, 0x524b, 0, "ATI Rage 128 VR (PCI)"},
|
||||
{0x1002, 0x524c, 1, "ATI Rage 128 VR (AGP 2x)"},
|
||||
{0x1002, 0x5345, 0, "ATI Rage 128 SE (PCI)"},
|
||||
{0x1002, 0x5346, 1, "ATI Rage 128 SF (AGP 2x)"},
|
||||
{0x1002, 0x5347, 1, "ATI Rage 128 SG (AGP 4x)"},
|
||||
{0x1002, 0x5348, 0, "ATI Rage 128 SH (unknown)"},
|
||||
{0x1002, 0x534b, 0, "ATI Rage 128 SK (PCI)"},
|
||||
{0x1002, 0x534c, 1, "ATI Rage 128 SL (AGP 2x)"},
|
||||
{0x1002, 0x534d, 1, "ATI Rage 128 SM (AGP 4x)"},
|
||||
{0x1002, 0x534e, 1, "ATI Rage 128 (AGP 4x?)"},
|
||||
{0, 0, 0, NULL}
|
||||
};
|
||||
|
||||
#define DRIVER_IOCTLS \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_DMA)] = { r128_cce_buffers, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_INIT)] = { r128_cce_init, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_CCE_START)] = { r128_cce_start, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_CCE_STOP)] = { r128_cce_stop, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_CCE_RESET)] = { r128_cce_reset, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_CCE_IDLE)] = { r128_cce_idle, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_RESET)] = { r128_engine_reset, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_FULLSCREEN)] = { r128_fullscreen, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_SWAP)] = { r128_cce_swap, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_CLEAR)] = { r128_cce_clear, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_VERTEX)] = { r128_cce_vertex, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_INDICES)] = { r128_cce_indices, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_BLIT)] = { r128_cce_blit, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_DEPTH)] = { r128_cce_depth, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_STIPPLE)] = { r128_cce_stipple, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_R128_INDIRECT)] = { r128_cce_indirect, 1, 1 },
|
||||
|
||||
|
||||
#if 0
|
||||
/* GH: Count data sent to card via ring or vertex/indirect buffers.
|
||||
*/
|
||||
#define __HAVE_COUNTERS 3
|
||||
#define __HAVE_COUNTER6 _DRM_STAT_IRQ
|
||||
#define __HAVE_COUNTER7 _DRM_STAT_PRIMARY
|
||||
#define __HAVE_COUNTER8 _DRM_STAT_SECONDARY
|
||||
#endif
|
||||
|
||||
|
||||
#include "drm_agpsupport.h"
|
||||
#include "drm_auth.h"
|
||||
#include "drm_bufs.h"
|
||||
#include "drm_context.h"
|
||||
#include "drm_dma.h"
|
||||
#include "drm_drawable.h"
|
||||
#include "drm_drv.h"
|
||||
|
||||
|
||||
#include "drm_fops.h"
|
||||
#include "drm_init.h"
|
||||
#include "drm_ioctl.h"
|
||||
#include "drm_lock.h"
|
||||
#include "drm_memory.h"
|
||||
#include "drm_sysctl.h"
|
||||
#include "drm_vm.h"
|
||||
#if __REALLY_HAVE_SG
|
||||
#include "drm_scatter.h"
|
||||
#endif
|
||||
|
||||
DRIVER_MODULE(r128, pci, r128_driver, r128_devclass, 0, 0);
|
||||
544
bsd/r128/r128_drv.h
Normal file
544
bsd/r128/r128_drv.h
Normal file
|
|
@ -0,0 +1,544 @@
|
|||
/* r128_drv.h -- Private header for r128 driver -*- linux-c -*-
|
||||
* Created: Mon Dec 13 09:51:11 1999 by faith@precisioninsight.com
|
||||
*
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Kevin E. Martin <martin@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
* Michel Dänzer <daenzerm@student.ethz.ch>
|
||||
*/
|
||||
|
||||
#include <machine/endian.h>
|
||||
#if BYTE_ORDER==LITTLE_ENDIAN
|
||||
#define le32_to_cpu(x) x
|
||||
#define cpu_to_le32(x) x
|
||||
#else
|
||||
#define le32_to_cpu(x) ntohl(x)
|
||||
#define cpu_to_le32(x) htonl(x)
|
||||
#endif
|
||||
|
||||
#ifndef __R128_DRV_H__
|
||||
#define __R128_DRV_H__
|
||||
|
||||
#define GET_RING_HEAD( ring ) le32_to_cpu( *(ring)->head )
|
||||
#define SET_RING_HEAD( ring, val ) *(ring)->head = cpu_to_le32( val )
|
||||
|
||||
typedef struct drm_r128_freelist {
|
||||
unsigned int age;
|
||||
drm_buf_t *buf;
|
||||
struct drm_r128_freelist *next;
|
||||
struct drm_r128_freelist *prev;
|
||||
} drm_r128_freelist_t;
|
||||
|
||||
typedef struct drm_r128_ring_buffer {
|
||||
u32 *start;
|
||||
u32 *end;
|
||||
int size;
|
||||
int size_l2qw;
|
||||
|
||||
volatile u32 *head;
|
||||
u32 tail;
|
||||
u32 tail_mask;
|
||||
int space;
|
||||
|
||||
int high_mark;
|
||||
} drm_r128_ring_buffer_t;
|
||||
|
||||
typedef struct drm_r128_private {
|
||||
drm_r128_ring_buffer_t ring;
|
||||
drm_r128_sarea_t *sarea_priv;
|
||||
|
||||
int cce_mode;
|
||||
int cce_fifo_size;
|
||||
int cce_running;
|
||||
|
||||
drm_r128_freelist_t *head;
|
||||
drm_r128_freelist_t *tail;
|
||||
|
||||
int usec_timeout;
|
||||
int is_pci;
|
||||
unsigned long phys_pci_gart;
|
||||
#if __REALLY_HAVE_SG
|
||||
dma_addr_t bus_pci_gart;
|
||||
#endif
|
||||
unsigned long cce_buffers_offset;
|
||||
|
||||
atomic_t idle_count;
|
||||
|
||||
int page_flipping;
|
||||
int current_page;
|
||||
u32 crtc_offset;
|
||||
u32 crtc_offset_cntl;
|
||||
|
||||
u32 color_fmt;
|
||||
unsigned int front_offset;
|
||||
unsigned int front_pitch;
|
||||
unsigned int back_offset;
|
||||
unsigned int back_pitch;
|
||||
|
||||
u32 depth_fmt;
|
||||
unsigned int depth_offset;
|
||||
unsigned int depth_pitch;
|
||||
unsigned int span_offset;
|
||||
|
||||
u32 front_pitch_offset_c;
|
||||
u32 back_pitch_offset_c;
|
||||
u32 depth_pitch_offset_c;
|
||||
u32 span_pitch_offset_c;
|
||||
|
||||
drm_map_t *sarea;
|
||||
drm_map_t *fb;
|
||||
drm_map_t *mmio;
|
||||
drm_map_t *cce_ring;
|
||||
drm_map_t *ring_rptr;
|
||||
drm_map_t *buffers;
|
||||
drm_map_t *agp_textures;
|
||||
} drm_r128_private_t;
|
||||
|
||||
typedef struct drm_r128_buf_priv {
|
||||
u32 age;
|
||||
int prim;
|
||||
int discard;
|
||||
int dispatched;
|
||||
drm_r128_freelist_t *list_entry;
|
||||
} drm_r128_buf_priv_t;
|
||||
|
||||
/* r128_cce.c */
|
||||
extern int r128_cce_init( DRM_OS_IOCTL );
|
||||
extern int r128_cce_start( DRM_OS_IOCTL );
|
||||
extern int r128_cce_stop( DRM_OS_IOCTL );
|
||||
extern int r128_cce_reset( DRM_OS_IOCTL );
|
||||
extern int r128_cce_idle( DRM_OS_IOCTL );
|
||||
extern int r128_engine_reset( DRM_OS_IOCTL );
|
||||
extern int r128_fullscreen( DRM_OS_IOCTL );
|
||||
extern int r128_cce_buffers( DRM_OS_IOCTL );
|
||||
|
||||
extern void r128_freelist_reset( drm_device_t *dev );
|
||||
extern drm_buf_t *r128_freelist_get( drm_device_t *dev );
|
||||
|
||||
extern int r128_wait_ring( drm_r128_private_t *dev_priv, int n );
|
||||
|
||||
static __inline__ void
|
||||
r128_update_ring_snapshot( drm_r128_ring_buffer_t *ring )
|
||||
{
|
||||
ring->space = (GET_RING_HEAD( ring ) - ring->tail) * sizeof(u32);
|
||||
if ( ring->space <= 0 )
|
||||
ring->space += ring->size;
|
||||
}
|
||||
|
||||
extern int r128_do_cce_idle( drm_r128_private_t *dev_priv );
|
||||
extern int r128_do_cleanup_cce( drm_device_t *dev );
|
||||
extern int r128_do_cleanup_pageflip( drm_device_t *dev );
|
||||
|
||||
/* r128_state.c */
|
||||
extern int r128_cce_clear( DRM_OS_IOCTL );
|
||||
extern int r128_cce_swap( DRM_OS_IOCTL );
|
||||
extern int r128_cce_vertex( DRM_OS_IOCTL );
|
||||
extern int r128_cce_indices( DRM_OS_IOCTL );
|
||||
extern int r128_cce_blit( DRM_OS_IOCTL );
|
||||
extern int r128_cce_depth( DRM_OS_IOCTL );
|
||||
extern int r128_cce_stipple( DRM_OS_IOCTL );
|
||||
extern int r128_cce_indirect( DRM_OS_IOCTL );
|
||||
|
||||
|
||||
/* Register definitions, register access macros and drmAddMap constants
|
||||
* for Rage 128 kernel driver.
|
||||
*/
|
||||
|
||||
#define R128_AUX_SC_CNTL 0x1660
|
||||
# define R128_AUX1_SC_EN (1 << 0)
|
||||
# define R128_AUX1_SC_MODE_OR (0 << 1)
|
||||
# define R128_AUX1_SC_MODE_NAND (1 << 1)
|
||||
# define R128_AUX2_SC_EN (1 << 2)
|
||||
# define R128_AUX2_SC_MODE_OR (0 << 3)
|
||||
# define R128_AUX2_SC_MODE_NAND (1 << 3)
|
||||
# define R128_AUX3_SC_EN (1 << 4)
|
||||
# define R128_AUX3_SC_MODE_OR (0 << 5)
|
||||
# define R128_AUX3_SC_MODE_NAND (1 << 5)
|
||||
#define R128_AUX1_SC_LEFT 0x1664
|
||||
#define R128_AUX1_SC_RIGHT 0x1668
|
||||
#define R128_AUX1_SC_TOP 0x166c
|
||||
#define R128_AUX1_SC_BOTTOM 0x1670
|
||||
#define R128_AUX2_SC_LEFT 0x1674
|
||||
#define R128_AUX2_SC_RIGHT 0x1678
|
||||
#define R128_AUX2_SC_TOP 0x167c
|
||||
#define R128_AUX2_SC_BOTTOM 0x1680
|
||||
#define R128_AUX3_SC_LEFT 0x1684
|
||||
#define R128_AUX3_SC_RIGHT 0x1688
|
||||
#define R128_AUX3_SC_TOP 0x168c
|
||||
#define R128_AUX3_SC_BOTTOM 0x1690
|
||||
|
||||
#define R128_BRUSH_DATA0 0x1480
|
||||
#define R128_BUS_CNTL 0x0030
|
||||
# define R128_BUS_MASTER_DIS (1 << 6)
|
||||
|
||||
#define R128_CLOCK_CNTL_INDEX 0x0008
|
||||
#define R128_CLOCK_CNTL_DATA 0x000c
|
||||
# define R128_PLL_WR_EN (1 << 7)
|
||||
#define R128_CONSTANT_COLOR_C 0x1d34
|
||||
#define R128_CRTC_OFFSET 0x0224
|
||||
#define R128_CRTC_OFFSET_CNTL 0x0228
|
||||
# define R128_CRTC_OFFSET_FLIP_CNTL (1 << 16)
|
||||
|
||||
#define R128_DP_GUI_MASTER_CNTL 0x146c
|
||||
# define R128_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0)
|
||||
# define R128_GMC_DST_PITCH_OFFSET_CNTL (1 << 1)
|
||||
# define R128_GMC_BRUSH_SOLID_COLOR (13 << 4)
|
||||
# define R128_GMC_BRUSH_NONE (15 << 4)
|
||||
# define R128_GMC_DST_16BPP (4 << 8)
|
||||
# define R128_GMC_DST_24BPP (5 << 8)
|
||||
# define R128_GMC_DST_32BPP (6 << 8)
|
||||
# define R128_GMC_DST_DATATYPE_SHIFT 8
|
||||
# define R128_GMC_SRC_DATATYPE_COLOR (3 << 12)
|
||||
# define R128_DP_SRC_SOURCE_MEMORY (2 << 24)
|
||||
# define R128_DP_SRC_SOURCE_HOST_DATA (3 << 24)
|
||||
# define R128_GMC_CLR_CMP_CNTL_DIS (1 << 28)
|
||||
# define R128_GMC_AUX_CLIP_DIS (1 << 29)
|
||||
# define R128_GMC_WR_MSK_DIS (1 << 30)
|
||||
# define R128_ROP3_S 0x00cc0000
|
||||
# define R128_ROP3_P 0x00f00000
|
||||
#define R128_DP_WRITE_MASK 0x16cc
|
||||
#define R128_DST_PITCH_OFFSET_C 0x1c80
|
||||
# define R128_DST_TILE (1 << 31)
|
||||
|
||||
#define R128_GEN_RESET_CNTL 0x00f0
|
||||
# define R128_SOFT_RESET_GUI (1 << 0)
|
||||
|
||||
#define R128_GUI_SCRATCH_REG0 0x15e0
|
||||
#define R128_GUI_SCRATCH_REG1 0x15e4
|
||||
#define R128_GUI_SCRATCH_REG2 0x15e8
|
||||
#define R128_GUI_SCRATCH_REG3 0x15ec
|
||||
#define R128_GUI_SCRATCH_REG4 0x15f0
|
||||
#define R128_GUI_SCRATCH_REG5 0x15f4
|
||||
|
||||
#define R128_GUI_STAT 0x1740
|
||||
# define R128_GUI_FIFOCNT_MASK 0x0fff
|
||||
# define R128_GUI_ACTIVE (1 << 31)
|
||||
|
||||
#define R128_MCLK_CNTL 0x000f
|
||||
# define R128_FORCE_GCP (1 << 16)
|
||||
# define R128_FORCE_PIPE3D_CP (1 << 17)
|
||||
# define R128_FORCE_RCP (1 << 18)
|
||||
|
||||
#define R128_PC_GUI_CTLSTAT 0x1748
|
||||
#define R128_PC_NGUI_CTLSTAT 0x0184
|
||||
# define R128_PC_FLUSH_GUI (3 << 0)
|
||||
# define R128_PC_RI_GUI (1 << 2)
|
||||
# define R128_PC_FLUSH_ALL 0x00ff
|
||||
# define R128_PC_BUSY (1 << 31)
|
||||
|
||||
#define R128_PCI_GART_PAGE 0x017c
|
||||
#define R128_PRIM_TEX_CNTL_C 0x1cb0
|
||||
|
||||
#define R128_SCALE_3D_CNTL 0x1a00
|
||||
#define R128_SEC_TEX_CNTL_C 0x1d00
|
||||
#define R128_SEC_TEXTURE_BORDER_COLOR_C 0x1d3c
|
||||
#define R128_SETUP_CNTL 0x1bc4
|
||||
#define R128_STEN_REF_MASK_C 0x1d40
|
||||
|
||||
#define R128_TEX_CNTL_C 0x1c9c
|
||||
# define R128_TEX_CACHE_FLUSH (1 << 23)
|
||||
|
||||
#define R128_WAIT_UNTIL 0x1720
|
||||
# define R128_EVENT_CRTC_OFFSET (1 << 0)
|
||||
#define R128_WINDOW_XY_OFFSET 0x1bcc
|
||||
|
||||
|
||||
/* CCE registers
|
||||
*/
|
||||
#define R128_PM4_BUFFER_OFFSET 0x0700
|
||||
#define R128_PM4_BUFFER_CNTL 0x0704
|
||||
# define R128_PM4_MASK (15 << 28)
|
||||
# define R128_PM4_NONPM4 (0 << 28)
|
||||
# define R128_PM4_192PIO (1 << 28)
|
||||
# define R128_PM4_192BM (2 << 28)
|
||||
# define R128_PM4_128PIO_64INDBM (3 << 28)
|
||||
# define R128_PM4_128BM_64INDBM (4 << 28)
|
||||
# define R128_PM4_64PIO_128INDBM (5 << 28)
|
||||
# define R128_PM4_64BM_128INDBM (6 << 28)
|
||||
# define R128_PM4_64PIO_64VCBM_64INDBM (7 << 28)
|
||||
# define R128_PM4_64BM_64VCBM_64INDBM (8 << 28)
|
||||
# define R128_PM4_64PIO_64VCPIO_64INDPIO (15 << 28)
|
||||
|
||||
#define R128_PM4_BUFFER_WM_CNTL 0x0708
|
||||
# define R128_WMA_SHIFT 0
|
||||
# define R128_WMB_SHIFT 8
|
||||
# define R128_WMC_SHIFT 16
|
||||
# define R128_WB_WM_SHIFT 24
|
||||
|
||||
#define R128_PM4_BUFFER_DL_RPTR_ADDR 0x070c
|
||||
#define R128_PM4_BUFFER_DL_RPTR 0x0710
|
||||
#define R128_PM4_BUFFER_DL_WPTR 0x0714
|
||||
# define R128_PM4_BUFFER_DL_DONE (1 << 31)
|
||||
|
||||
#define R128_PM4_VC_FPU_SETUP 0x071c
|
||||
|
||||
#define R128_PM4_IW_INDOFF 0x0738
|
||||
#define R128_PM4_IW_INDSIZE 0x073c
|
||||
|
||||
#define R128_PM4_STAT 0x07b8
|
||||
# define R128_PM4_FIFOCNT_MASK 0x0fff
|
||||
# define R128_PM4_BUSY (1 << 16)
|
||||
# define R128_PM4_GUI_ACTIVE (1 << 31)
|
||||
|
||||
#define R128_PM4_MICROCODE_ADDR 0x07d4
|
||||
#define R128_PM4_MICROCODE_RADDR 0x07d8
|
||||
#define R128_PM4_MICROCODE_DATAH 0x07dc
|
||||
#define R128_PM4_MICROCODE_DATAL 0x07e0
|
||||
|
||||
#define R128_PM4_BUFFER_ADDR 0x07f0
|
||||
#define R128_PM4_MICRO_CNTL 0x07fc
|
||||
# define R128_PM4_MICRO_FREERUN (1 << 30)
|
||||
|
||||
#define R128_PM4_FIFO_DATA_EVEN 0x1000
|
||||
#define R128_PM4_FIFO_DATA_ODD 0x1004
|
||||
|
||||
|
||||
/* CCE command packets
|
||||
*/
|
||||
#define R128_CCE_PACKET0 0x00000000
|
||||
#define R128_CCE_PACKET1 0x40000000
|
||||
#define R128_CCE_PACKET2 0x80000000
|
||||
#define R128_CCE_PACKET3 0xC0000000
|
||||
# define R128_CNTL_HOSTDATA_BLT 0x00009400
|
||||
# define R128_CNTL_PAINT_MULTI 0x00009A00
|
||||
# define R128_CNTL_BITBLT_MULTI 0x00009B00
|
||||
# define R128_3D_RNDR_GEN_INDX_PRIM 0x00002300
|
||||
|
||||
#define R128_CCE_PACKET_MASK 0xC0000000
|
||||
#define R128_CCE_PACKET_COUNT_MASK 0x3fff0000
|
||||
#define R128_CCE_PACKET0_REG_MASK 0x000007ff
|
||||
#define R128_CCE_PACKET1_REG0_MASK 0x000007ff
|
||||
#define R128_CCE_PACKET1_REG1_MASK 0x003ff800
|
||||
|
||||
#define R128_CCE_VC_CNTL_PRIM_TYPE_NONE 0x00000000
|
||||
#define R128_CCE_VC_CNTL_PRIM_TYPE_POINT 0x00000001
|
||||
#define R128_CCE_VC_CNTL_PRIM_TYPE_LINE 0x00000002
|
||||
#define R128_CCE_VC_CNTL_PRIM_TYPE_POLY_LINE 0x00000003
|
||||
#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST 0x00000004
|
||||
#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_FAN 0x00000005
|
||||
#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_STRIP 0x00000006
|
||||
#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2 0x00000007
|
||||
#define R128_CCE_VC_CNTL_PRIM_WALK_IND 0x00000010
|
||||
#define R128_CCE_VC_CNTL_PRIM_WALK_LIST 0x00000020
|
||||
#define R128_CCE_VC_CNTL_PRIM_WALK_RING 0x00000030
|
||||
#define R128_CCE_VC_CNTL_NUM_SHIFT 16
|
||||
|
||||
#define R128_DATATYPE_CI8 2
|
||||
#define R128_DATATYPE_ARGB1555 3
|
||||
#define R128_DATATYPE_RGB565 4
|
||||
#define R128_DATATYPE_RGB888 5
|
||||
#define R128_DATATYPE_ARGB8888 6
|
||||
#define R128_DATATYPE_RGB332 7
|
||||
#define R128_DATATYPE_RGB8 9
|
||||
#define R128_DATATYPE_ARGB4444 15
|
||||
|
||||
/* Constants */
|
||||
#define R128_AGP_OFFSET 0x02000000
|
||||
|
||||
#define R128_WATERMARK_L 16
|
||||
#define R128_WATERMARK_M 8
|
||||
#define R128_WATERMARK_N 8
|
||||
#define R128_WATERMARK_K 128
|
||||
|
||||
#define R128_MAX_USEC_TIMEOUT 100000 /* 100 ms */
|
||||
|
||||
#define R128_LAST_FRAME_REG R128_GUI_SCRATCH_REG0
|
||||
#define R128_LAST_DISPATCH_REG R128_GUI_SCRATCH_REG1
|
||||
#define R128_MAX_VB_AGE 0x7fffffff
|
||||
#define R128_MAX_VB_VERTS (0xffff)
|
||||
|
||||
#define R128_RING_HIGH_MARK 128
|
||||
|
||||
#define R128_PERFORMANCE_BOXES 0
|
||||
|
||||
|
||||
#define R128_BASE(reg) ((unsigned long)(dev_priv->mmio->handle))
|
||||
#define R128_ADDR(reg) (R128_BASE( reg ) + reg)
|
||||
|
||||
#define R128_DEREF(reg) *(volatile u32 *)R128_ADDR( reg )
|
||||
#ifdef __alpha__
|
||||
#define R128_READ(reg) (_R128_READ((u32 *)R128_ADDR(reg)))
|
||||
static inline u32 _R128_READ(u32 *addr)
|
||||
{
|
||||
DRM_OS_READMEMORYBARRIER;
|
||||
return *(volatile u32 *)addr;
|
||||
}
|
||||
#define R128_WRITE(reg,val) \
|
||||
do { \
|
||||
DRM_OS_WRITEMEMORYBARRIER; \
|
||||
R128_DEREF(reg) = val; \
|
||||
} while (0)
|
||||
#else
|
||||
#define R128_READ(reg) le32_to_cpu( R128_DEREF( reg ) )
|
||||
#define R128_WRITE(reg,val) \
|
||||
do { \
|
||||
R128_DEREF( reg ) = cpu_to_le32( val ); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#define R128_DEREF8(reg) *(volatile u8 *)R128_ADDR( reg )
|
||||
#ifdef __alpha__
|
||||
#define R128_READ8(reg) _R128_READ8((u8 *)R128_ADDR(reg))
|
||||
static inline u8 _R128_READ8(u8 *addr)
|
||||
{
|
||||
DRM_OS_READMEMORYBARRIER;
|
||||
return *(volatile u8 *)addr;
|
||||
}
|
||||
#define R128_WRITE8(reg,val) \
|
||||
do { \
|
||||
DRM_OS_WRITEMEMORYBARRIER; \
|
||||
R128_DEREF8(reg) = val; \
|
||||
} while (0)
|
||||
#else
|
||||
#define R128_READ8(reg) R128_DEREF8( reg )
|
||||
#define R128_WRITE8(reg,val) do { R128_DEREF8( reg ) = val; } while (0)
|
||||
#endif
|
||||
|
||||
#define R128_WRITE_PLL(addr,val) \
|
||||
do { \
|
||||
R128_WRITE8(R128_CLOCK_CNTL_INDEX, \
|
||||
((addr) & 0x1f) | R128_PLL_WR_EN); \
|
||||
R128_WRITE(R128_CLOCK_CNTL_DATA, (val)); \
|
||||
} while (0)
|
||||
|
||||
extern int R128_READ_PLL(drm_device_t *dev, int addr);
|
||||
|
||||
|
||||
#define CCE_PACKET0( reg, n ) (R128_CCE_PACKET0 | \
|
||||
((n) << 16) | ((reg) >> 2))
|
||||
#define CCE_PACKET1( reg0, reg1 ) (R128_CCE_PACKET1 | \
|
||||
(((reg1) >> 2) << 11) | ((reg0) >> 2))
|
||||
#define CCE_PACKET2() (R128_CCE_PACKET2)
|
||||
#define CCE_PACKET3( pkt, n ) (R128_CCE_PACKET3 | \
|
||||
(pkt) | ((n) << 16))
|
||||
|
||||
|
||||
/* ================================================================
|
||||
* Misc helper macros
|
||||
*/
|
||||
|
||||
#define LOCK_TEST_WITH_RETURN( dev ) \
|
||||
do { \
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
|
||||
dev->lock.pid != DRM_OS_CURRENTPID ) { \
|
||||
DRM_ERROR( "%s called without lock held\n", \
|
||||
__FUNCTION__ ); \
|
||||
DRM_OS_RETURN( EINVAL ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define RING_SPACE_TEST_WITH_RETURN( dev_priv ) \
|
||||
do { \
|
||||
drm_r128_ring_buffer_t *ring = &dev_priv->ring; int i; \
|
||||
if ( ring->space < ring->high_mark ) { \
|
||||
for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) { \
|
||||
r128_update_ring_snapshot( ring ); \
|
||||
if ( ring->space >= ring->high_mark ) \
|
||||
goto __ring_space_done; \
|
||||
DRM_OS_DELAY( 1 ); \
|
||||
} \
|
||||
DRM_ERROR( "ring space check failed!\n" ); \
|
||||
DRM_OS_RETURN( EBUSY ); \
|
||||
} \
|
||||
__ring_space_done: \
|
||||
} while (0)
|
||||
|
||||
#define VB_AGE_TEST_WITH_RETURN( dev_priv ) \
|
||||
do { \
|
||||
drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; \
|
||||
if ( sarea_priv->last_dispatch >= R128_MAX_VB_AGE ) { \
|
||||
int __ret = r128_do_cce_idle( dev_priv ); \
|
||||
if ( __ret < 0 ) return __ret; \
|
||||
sarea_priv->last_dispatch = 0; \
|
||||
r128_freelist_reset( dev ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define R128_WAIT_UNTIL_PAGE_FLIPPED() do { \
|
||||
OUT_RING( CCE_PACKET0( R128_WAIT_UNTIL, 0 ) ); \
|
||||
OUT_RING( R128_EVENT_CRTC_OFFSET ); \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* ================================================================
|
||||
* Ring control
|
||||
*/
|
||||
|
||||
#define r128_flush_write_combine() DRM_OS_READMEMORYBARRIER
|
||||
|
||||
|
||||
#define R128_VERBOSE 0
|
||||
|
||||
#define RING_LOCALS \
|
||||
int write; unsigned int tail_mask; volatile u32 *ring;
|
||||
|
||||
#define BEGIN_RING( n ) do { \
|
||||
if ( R128_VERBOSE ) { \
|
||||
DRM_INFO( "BEGIN_RING( %d ) in %s\n", \
|
||||
(n), __FUNCTION__ ); \
|
||||
} \
|
||||
if ( dev_priv->ring.space <= (n) * sizeof(u32) ) { \
|
||||
r128_wait_ring( dev_priv, (n) * sizeof(u32) ); \
|
||||
} \
|
||||
dev_priv->ring.space -= (n) * sizeof(u32); \
|
||||
ring = dev_priv->ring.start; \
|
||||
write = dev_priv->ring.tail; \
|
||||
tail_mask = dev_priv->ring.tail_mask; \
|
||||
} while (0)
|
||||
|
||||
/* You can set this to zero if you want. If the card locks up, you'll
|
||||
* need to keep this set. It works around a bug in early revs of the
|
||||
* Rage 128 chipset, where the CCE would read 32 dwords past the end of
|
||||
* the ring buffer before wrapping around.
|
||||
*/
|
||||
#define R128_BROKEN_CCE 1
|
||||
|
||||
#define ADVANCE_RING() do { \
|
||||
if ( R128_VERBOSE ) { \
|
||||
DRM_INFO( "ADVANCE_RING() wr=0x%06x tail=0x%06x\n", \
|
||||
write, dev_priv->ring.tail ); \
|
||||
} \
|
||||
if ( R128_BROKEN_CCE && write < 32 ) { \
|
||||
memcpy( dev_priv->ring.end, \
|
||||
dev_priv->ring.start, \
|
||||
write * sizeof(u32) ); \
|
||||
} \
|
||||
r128_flush_write_combine(); \
|
||||
dev_priv->ring.tail = write; \
|
||||
R128_WRITE( R128_PM4_BUFFER_DL_WPTR, write ); \
|
||||
} while (0)
|
||||
|
||||
#define OUT_RING( x ) do { \
|
||||
if ( R128_VERBOSE ) { \
|
||||
DRM_INFO( " OUT_RING( 0x%08x ) at 0x%x\n", \
|
||||
(unsigned int)(x), write ); \
|
||||
} \
|
||||
ring[write++] = cpu_to_le32( x ); \
|
||||
write &= tail_mask; \
|
||||
} while (0)
|
||||
|
||||
#endif /* __R128_DRV_H__ */
|
||||
1570
bsd/r128/r128_state.c
Normal file
1570
bsd/r128/r128_state.c
Normal file
File diff suppressed because it is too large
Load diff
81
bsd/radeon/radeon.h
Normal file
81
bsd/radeon/radeon.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* radeon.h -- ATI Radeon DRM template customization -*- linux-c -*-
|
||||
* Created: Wed Feb 14 17:07:34 2001 by gareth@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef __RADEON_H__
|
||||
#define __RADEON_H__
|
||||
|
||||
/* This remains constant for all DRM template files.
|
||||
*/
|
||||
#define DRM(x) radeon_##x
|
||||
|
||||
/* General customization:
|
||||
*/
|
||||
#define __HAVE_AGP 1
|
||||
#define __MUST_HAVE_AGP 0
|
||||
#define __HAVE_MTRR 1
|
||||
#define __HAVE_CTX_BITMAP 1
|
||||
#define __HAVE_SG 1
|
||||
#define __HAVE_PCI_DMA 1
|
||||
|
||||
/* Driver customization:
|
||||
*/
|
||||
#define DRIVER_PRERELEASE() do { \
|
||||
if ( dev->dev_private ) { \
|
||||
drm_radeon_private_t *dev_priv = dev->dev_private; \
|
||||
if ( dev_priv->page_flipping ) { \
|
||||
radeon_do_cleanup_pageflip( dev ); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define DRIVER_PRETAKEDOWN() do { \
|
||||
if ( dev->dev_private ) radeon_do_cleanup_cp( dev ); \
|
||||
} while (0)
|
||||
|
||||
/* DMA customization:
|
||||
*/
|
||||
#define __HAVE_DMA 1
|
||||
|
||||
#if 0
|
||||
/* GH: Remove this for now... */
|
||||
#define __HAVE_DMA_QUIESCENT 1
|
||||
#define DRIVER_DMA_QUIESCENT() do { \
|
||||
drm_radeon_private_t *dev_priv = dev->dev_private; \
|
||||
return radeon_do_cp_idle( dev_priv ); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
/* Buffer customization:
|
||||
*/
|
||||
#define DRIVER_BUF_PRIV_T drm_radeon_buf_priv_t
|
||||
|
||||
#define DRIVER_AGP_BUFFERS_MAP( dev ) \
|
||||
((drm_radeon_private_t *)((dev)->dev_private))->buffers
|
||||
|
||||
#endif
|
||||
1421
bsd/radeon/radeon_cp.c
Normal file
1421
bsd/radeon/radeon_cp.c
Normal file
File diff suppressed because it is too large
Load diff
114
bsd/radeon/radeon_drv.c
Normal file
114
bsd/radeon/radeon_drv.c
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/* radeon_drv.c -- ATI Radeon driver -*- linux-c -*-
|
||||
* Created: Wed Feb 14 17:10:04 2001 by gareth@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/bus.h>
|
||||
#include <pci/pcivar.h>
|
||||
#include <opt_drm_linux.h>
|
||||
|
||||
#include "radeon.h"
|
||||
#include "drmP.h"
|
||||
#include "radeon_drv.h"
|
||||
#if __REALLY_HAVE_SG
|
||||
#include "ati_pcigart.h"
|
||||
#endif
|
||||
|
||||
#define DRIVER_AUTHOR "Gareth Hughes, VA Linux Systems Inc."
|
||||
|
||||
#define DRIVER_NAME "radeon"
|
||||
#define DRIVER_DESC "ATI Radeon"
|
||||
#define DRIVER_DATE "20010405"
|
||||
|
||||
#define DRIVER_MAJOR 1
|
||||
#define DRIVER_MINOR 1
|
||||
#define DRIVER_PATCHLEVEL 1
|
||||
|
||||
/* List acquired from http://www.yourvote.com/pci/pcihdr.h and xc/xc/programs/Xserver/hw/xfree86/common/xf86PciInfo.h
|
||||
* Please report to anholt@teleport.com inaccuracies or if a chip you have works that is marked unsupported here.
|
||||
*/
|
||||
drm_chipinfo_t DRM(devicelist)[] = {
|
||||
{0x1002, 0x5144, 1, "ATI Radeon QD"},
|
||||
{0x1002, 0x5145, 1, "ATI Radeon QE"},
|
||||
{0x1002, 0x5146, 1, "ATI Radeon QF"},
|
||||
{0x1002, 0x5147, 1, "ATI Radeon QG"},
|
||||
{0x1002, 0x5159, 1, "ATI Radeon VE"},
|
||||
{0, 0, 0, NULL}
|
||||
};
|
||||
|
||||
#define DRIVER_IOCTLS \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_DMA)] = { radeon_cp_buffers, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_CP_INIT)] = { radeon_cp_init, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_CP_START)] = { radeon_cp_start, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_CP_STOP)] = { radeon_cp_stop, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_CP_RESET)] = { radeon_cp_reset, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_CP_IDLE)] = { radeon_cp_idle, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_RESET)] = { radeon_engine_reset, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_FULLSCREEN)] = { radeon_fullscreen, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_SWAP)] = { radeon_cp_swap, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_CLEAR)] = { radeon_cp_clear, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_VERTEX)] = { radeon_cp_vertex, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_INDICES)] = { radeon_cp_indices, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_TEXTURE)] = { radeon_cp_texture, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_STIPPLE)] = { radeon_cp_stipple, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RADEON_INDIRECT)] = { radeon_cp_indirect, 1, 1 },
|
||||
|
||||
|
||||
#if 0
|
||||
/* GH: Count data sent to card via ring or vertex/indirect buffers.
|
||||
*/
|
||||
#define __HAVE_COUNTERS 3
|
||||
#define __HAVE_COUNTER6 _DRM_STAT_IRQ
|
||||
#define __HAVE_COUNTER7 _DRM_STAT_PRIMARY
|
||||
#define __HAVE_COUNTER8 _DRM_STAT_SECONDARY
|
||||
#endif
|
||||
|
||||
|
||||
#include "drm_agpsupport.h"
|
||||
#include "drm_auth.h"
|
||||
#include "drm_bufs.h"
|
||||
#include "drm_context.h"
|
||||
#include "drm_dma.h"
|
||||
#include "drm_drawable.h"
|
||||
#include "drm_drv.h"
|
||||
|
||||
|
||||
#include "drm_fops.h"
|
||||
#include "drm_init.h"
|
||||
#include "drm_ioctl.h"
|
||||
#include "drm_lock.h"
|
||||
#include "drm_memory.h"
|
||||
#include "drm_vm.h"
|
||||
#include "drm_sysctl.h"
|
||||
#if __REALLY_HAVE_SG
|
||||
#include "drm_scatter.h"
|
||||
#endif
|
||||
|
||||
DRIVER_MODULE(radeon, pci, radeon_driver, radeon_devclass, 0, 0);
|
||||
725
bsd/radeon/radeon_drv.h
Normal file
725
bsd/radeon/radeon_drv.h
Normal file
|
|
@ -0,0 +1,725 @@
|
|||
/* radeon_drv.h -- Private header for radeon driver -*- linux-c -*-
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Fremont, 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors:
|
||||
* Kevin E. Martin <martin@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef __RADEON_DRV_H__
|
||||
#define __RADEON_DRV_H__
|
||||
|
||||
typedef struct drm_radeon_freelist {
|
||||
unsigned int age;
|
||||
drm_buf_t *buf;
|
||||
struct drm_radeon_freelist *next;
|
||||
struct drm_radeon_freelist *prev;
|
||||
} drm_radeon_freelist_t;
|
||||
|
||||
typedef struct drm_radeon_ring_buffer {
|
||||
u32 *start;
|
||||
u32 *end;
|
||||
int size;
|
||||
int size_l2qw;
|
||||
|
||||
volatile u32 *head;
|
||||
u32 tail;
|
||||
u32 tail_mask;
|
||||
int space;
|
||||
|
||||
int high_mark;
|
||||
} drm_radeon_ring_buffer_t;
|
||||
|
||||
typedef struct drm_radeon_depth_clear_t {
|
||||
u32 rb3d_cntl;
|
||||
u32 rb3d_zstencilcntl;
|
||||
u32 se_cntl;
|
||||
} drm_radeon_depth_clear_t;
|
||||
|
||||
typedef struct drm_radeon_private {
|
||||
drm_radeon_ring_buffer_t ring;
|
||||
drm_radeon_sarea_t *sarea_priv;
|
||||
|
||||
int agp_size;
|
||||
u32 agp_vm_start;
|
||||
unsigned long agp_buffers_offset;
|
||||
|
||||
int cp_mode;
|
||||
int cp_running;
|
||||
|
||||
drm_radeon_freelist_t *head;
|
||||
drm_radeon_freelist_t *tail;
|
||||
/* FIXME: ROTATE_BUFS is a hask to cycle through bufs until freelist
|
||||
code is used. Note this hides a problem with the scratch register
|
||||
(used to keep track of last buffer completed) being written to before
|
||||
the last buffer has actually completed rendering. */
|
||||
#define ROTATE_BUFS 1
|
||||
#if ROTATE_BUFS
|
||||
int last_buf;
|
||||
#endif
|
||||
volatile u32 *scratch;
|
||||
|
||||
int usec_timeout;
|
||||
int is_pci;
|
||||
unsigned long phys_pci_gart;
|
||||
#if __REALLY_HAVE_SG
|
||||
dma_addr_t bus_pci_gart;
|
||||
#endif
|
||||
|
||||
atomic_t idle_count;
|
||||
|
||||
int page_flipping;
|
||||
int current_page;
|
||||
u32 crtc_offset;
|
||||
u32 crtc_offset_cntl;
|
||||
|
||||
u32 color_fmt;
|
||||
unsigned int front_offset;
|
||||
unsigned int front_pitch;
|
||||
unsigned int back_offset;
|
||||
unsigned int back_pitch;
|
||||
|
||||
u32 depth_fmt;
|
||||
unsigned int depth_offset;
|
||||
unsigned int depth_pitch;
|
||||
|
||||
u32 front_pitch_offset;
|
||||
u32 back_pitch_offset;
|
||||
u32 depth_pitch_offset;
|
||||
|
||||
drm_radeon_depth_clear_t depth_clear;
|
||||
|
||||
drm_map_t *sarea;
|
||||
drm_map_t *fb;
|
||||
drm_map_t *mmio;
|
||||
drm_map_t *cp_ring;
|
||||
drm_map_t *ring_rptr;
|
||||
drm_map_t *buffers;
|
||||
drm_map_t *agp_textures;
|
||||
} drm_radeon_private_t;
|
||||
|
||||
typedef struct drm_radeon_buf_priv {
|
||||
u32 age;
|
||||
int prim;
|
||||
int discard;
|
||||
int dispatched;
|
||||
drm_radeon_freelist_t *list_entry;
|
||||
} drm_radeon_buf_priv_t;
|
||||
|
||||
/* radeon_cp.c */
|
||||
extern int radeon_cp_init( DRM_OS_IOCTL );
|
||||
extern int radeon_cp_start( DRM_OS_IOCTL );
|
||||
extern int radeon_cp_stop( DRM_OS_IOCTL );
|
||||
extern int radeon_cp_reset( DRM_OS_IOCTL );
|
||||
extern int radeon_cp_idle( DRM_OS_IOCTL );
|
||||
extern int radeon_engine_reset( DRM_OS_IOCTL );
|
||||
extern int radeon_fullscreen( DRM_OS_IOCTL );
|
||||
extern int radeon_cp_buffers( DRM_OS_IOCTL );
|
||||
|
||||
extern void radeon_freelist_reset( drm_device_t *dev );
|
||||
extern drm_buf_t *radeon_freelist_get( drm_device_t *dev );
|
||||
|
||||
extern int radeon_wait_ring( drm_radeon_private_t *dev_priv, int n );
|
||||
|
||||
static __inline__ void
|
||||
radeon_update_ring_snapshot( drm_radeon_ring_buffer_t *ring )
|
||||
{
|
||||
ring->space = (*(volatile int *)ring->head - ring->tail) * sizeof(u32);
|
||||
if ( ring->space <= 0 )
|
||||
ring->space += ring->size;
|
||||
}
|
||||
|
||||
extern int radeon_do_cp_idle( drm_radeon_private_t *dev_priv );
|
||||
extern int radeon_do_cleanup_cp( drm_device_t *dev );
|
||||
extern int radeon_do_cleanup_pageflip( drm_device_t *dev );
|
||||
|
||||
/* radeon_state.c */
|
||||
extern int radeon_cp_clear( DRM_OS_IOCTL );
|
||||
extern int radeon_cp_swap( DRM_OS_IOCTL );
|
||||
extern int radeon_cp_vertex( DRM_OS_IOCTL );
|
||||
extern int radeon_cp_indices( DRM_OS_IOCTL );
|
||||
extern int radeon_cp_texture( DRM_OS_IOCTL );
|
||||
extern int radeon_cp_stipple( DRM_OS_IOCTL );
|
||||
extern int radeon_cp_indirect( DRM_OS_IOCTL );
|
||||
|
||||
/* Register definitions, register access macros and drmAddMap constants
|
||||
* for Radeon kernel driver.
|
||||
*/
|
||||
|
||||
#define RADEON_AGP_COMMAND 0x0f60
|
||||
#define RADEON_AUX_SCISSOR_CNTL 0x26f0
|
||||
# define RADEON_EXCLUSIVE_SCISSOR_0 (1 << 24)
|
||||
# define RADEON_EXCLUSIVE_SCISSOR_1 (1 << 25)
|
||||
# define RADEON_EXCLUSIVE_SCISSOR_2 (1 << 26)
|
||||
# define RADEON_SCISSOR_0_ENABLE (1 << 28)
|
||||
# define RADEON_SCISSOR_1_ENABLE (1 << 29)
|
||||
# define RADEON_SCISSOR_2_ENABLE (1 << 30)
|
||||
|
||||
#define RADEON_BUS_CNTL 0x0030
|
||||
# define RADEON_BUS_MASTER_DIS (1 << 6)
|
||||
|
||||
#define RADEON_CLOCK_CNTL_DATA 0x000c
|
||||
# define RADEON_PLL_WR_EN (1 << 7)
|
||||
#define RADEON_CLOCK_CNTL_INDEX 0x0008
|
||||
#define RADEON_CONFIG_APER_SIZE 0x0108
|
||||
#define RADEON_CRTC_OFFSET 0x0224
|
||||
#define RADEON_CRTC_OFFSET_CNTL 0x0228
|
||||
# define RADEON_CRTC_TILE_EN (1 << 15)
|
||||
# define RADEON_CRTC_OFFSET_FLIP_CNTL (1 << 16)
|
||||
|
||||
#define RADEON_RB3D_COLORPITCH 0x1c48
|
||||
#define RADEON_RB3D_DEPTHCLEARVALUE 0x1c30
|
||||
#define RADEON_RB3D_DEPTHXY_OFFSET 0x1c60
|
||||
|
||||
#define RADEON_DP_GUI_MASTER_CNTL 0x146c
|
||||
# define RADEON_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0)
|
||||
# define RADEON_GMC_DST_PITCH_OFFSET_CNTL (1 << 1)
|
||||
# define RADEON_GMC_BRUSH_SOLID_COLOR (13 << 4)
|
||||
# define RADEON_GMC_BRUSH_NONE (15 << 4)
|
||||
# define RADEON_GMC_DST_16BPP (4 << 8)
|
||||
# define RADEON_GMC_DST_24BPP (5 << 8)
|
||||
# define RADEON_GMC_DST_32BPP (6 << 8)
|
||||
# define RADEON_GMC_DST_DATATYPE_SHIFT 8
|
||||
# define RADEON_GMC_SRC_DATATYPE_COLOR (3 << 12)
|
||||
# define RADEON_DP_SRC_SOURCE_MEMORY (2 << 24)
|
||||
# define RADEON_DP_SRC_SOURCE_HOST_DATA (3 << 24)
|
||||
# define RADEON_GMC_CLR_CMP_CNTL_DIS (1 << 28)
|
||||
# define RADEON_GMC_WR_MSK_DIS (1 << 30)
|
||||
# define RADEON_ROP3_S 0x00cc0000
|
||||
# define RADEON_ROP3_P 0x00f00000
|
||||
#define RADEON_DP_WRITE_MASK 0x16cc
|
||||
#define RADEON_DST_PITCH_OFFSET 0x142c
|
||||
#define RADEON_DST_PITCH_OFFSET_C 0x1c80
|
||||
# define RADEON_DST_TILE_LINEAR (0 << 30)
|
||||
# define RADEON_DST_TILE_MACRO (1 << 30)
|
||||
# define RADEON_DST_TILE_MICRO (2 << 30)
|
||||
# define RADEON_DST_TILE_BOTH (3 << 30)
|
||||
|
||||
#define RADEON_SCRATCH_REG0 0x15e0
|
||||
#define RADEON_SCRATCH_REG1 0x15e4
|
||||
#define RADEON_SCRATCH_REG2 0x15e8
|
||||
#define RADEON_SCRATCH_REG3 0x15ec
|
||||
#define RADEON_SCRATCH_REG4 0x15f0
|
||||
#define RADEON_SCRATCH_REG5 0x15f4
|
||||
#define RADEON_SCRATCH_UMSK 0x0770
|
||||
#define RADEON_SCRATCH_ADDR 0x0774
|
||||
|
||||
#define RADEON_HOST_PATH_CNTL 0x0130
|
||||
# define RADEON_HDP_SOFT_RESET (1 << 26)
|
||||
# define RADEON_HDP_WC_TIMEOUT_MASK (7 << 28)
|
||||
# define RADEON_HDP_WC_TIMEOUT_28BCLK (7 << 28)
|
||||
|
||||
#define RADEON_ISYNC_CNTL 0x1724
|
||||
# define RADEON_ISYNC_ANY2D_IDLE3D (1 << 0)
|
||||
# define RADEON_ISYNC_ANY3D_IDLE2D (1 << 1)
|
||||
# define RADEON_ISYNC_TRIG2D_IDLE3D (1 << 2)
|
||||
# define RADEON_ISYNC_TRIG3D_IDLE2D (1 << 3)
|
||||
# define RADEON_ISYNC_WAIT_IDLEGUI (1 << 4)
|
||||
# define RADEON_ISYNC_CPSCRATCH_IDLEGUI (1 << 5)
|
||||
|
||||
#define RADEON_MC_AGP_LOCATION 0x014c
|
||||
#define RADEON_MC_FB_LOCATION 0x0148
|
||||
#define RADEON_MCLK_CNTL 0x0012
|
||||
# define RADEON_FORCEON_MCLKA (1 << 16)
|
||||
# define RADEON_FORCEON_MCLKB (1 << 17)
|
||||
# define RADEON_FORCEON_YCLKA (1 << 18)
|
||||
# define RADEON_FORCEON_YCLKB (1 << 19)
|
||||
# define RADEON_FORCEON_MC (1 << 20)
|
||||
# define RADEON_FORCEON_AIC (1 << 21)
|
||||
|
||||
#define RADEON_PP_BORDER_COLOR_0 0x1d40
|
||||
#define RADEON_PP_BORDER_COLOR_1 0x1d44
|
||||
#define RADEON_PP_BORDER_COLOR_2 0x1d48
|
||||
#define RADEON_PP_CNTL 0x1c38
|
||||
# define RADEON_SCISSOR_ENABLE (1 << 1)
|
||||
#define RADEON_PP_LUM_MATRIX 0x1d00
|
||||
#define RADEON_PP_MISC 0x1c14
|
||||
#define RADEON_PP_ROT_MATRIX_0 0x1d58
|
||||
#define RADEON_PP_TXFILTER_0 0x1c54
|
||||
#define RADEON_PP_TXFILTER_1 0x1c6c
|
||||
#define RADEON_PP_TXFILTER_2 0x1c84
|
||||
|
||||
#define RADEON_RB2D_DSTCACHE_CTLSTAT 0x342c
|
||||
# define RADEON_RB2D_DC_FLUSH (3 << 0)
|
||||
# define RADEON_RB2D_DC_FREE (3 << 2)
|
||||
# define RADEON_RB2D_DC_FLUSH_ALL 0xf
|
||||
# define RADEON_RB2D_DC_BUSY (1 << 31)
|
||||
#define RADEON_RB3D_CNTL 0x1c3c
|
||||
# define RADEON_ALPHA_BLEND_ENABLE (1 << 0)
|
||||
# define RADEON_PLANE_MASK_ENABLE (1 << 1)
|
||||
# define RADEON_DITHER_ENABLE (1 << 2)
|
||||
# define RADEON_ROUND_ENABLE (1 << 3)
|
||||
# define RADEON_SCALE_DITHER_ENABLE (1 << 4)
|
||||
# define RADEON_DITHER_INIT (1 << 5)
|
||||
# define RADEON_ROP_ENABLE (1 << 6)
|
||||
# define RADEON_STENCIL_ENABLE (1 << 7)
|
||||
# define RADEON_Z_ENABLE (1 << 8)
|
||||
# define RADEON_DEPTH_XZ_OFFEST_ENABLE (1 << 9)
|
||||
# define RADEON_ZBLOCK8 (0 << 15)
|
||||
# define RADEON_ZBLOCK16 (1 << 15)
|
||||
#define RADEON_RB3D_DEPTHOFFSET 0x1c24
|
||||
#define RADEON_RB3D_PLANEMASK 0x1d84
|
||||
#define RADEON_RB3D_STENCILREFMASK 0x1d7c
|
||||
#define RADEON_RB3D_ZCACHE_MODE 0x3250
|
||||
#define RADEON_RB3D_ZCACHE_CTLSTAT 0x3254
|
||||
# define RADEON_RB3D_ZC_FLUSH (1 << 0)
|
||||
# define RADEON_RB3D_ZC_FREE (1 << 2)
|
||||
# define RADEON_RB3D_ZC_FLUSH_ALL 0x5
|
||||
# define RADEON_RB3D_ZC_BUSY (1 << 31)
|
||||
#define RADEON_RB3D_ZSTENCILCNTL 0x1c2c
|
||||
# define RADEON_Z_TEST_MASK (7 << 4)
|
||||
# define RADEON_Z_TEST_ALWAYS (7 << 4)
|
||||
# define RADEON_STENCIL_TEST_ALWAYS (7 << 12)
|
||||
# define RADEON_STENCIL_S_FAIL_KEEP (0 << 16)
|
||||
# define RADEON_STENCIL_ZPASS_KEEP (0 << 20)
|
||||
# define RADEON_STENCIL_ZFAIL_KEEP (0 << 20)
|
||||
# define RADEON_Z_WRITE_ENABLE (1 << 30)
|
||||
#define RADEON_RBBM_SOFT_RESET 0x00f0
|
||||
# define RADEON_SOFT_RESET_CP (1 << 0)
|
||||
# define RADEON_SOFT_RESET_HI (1 << 1)
|
||||
# define RADEON_SOFT_RESET_SE (1 << 2)
|
||||
# define RADEON_SOFT_RESET_RE (1 << 3)
|
||||
# define RADEON_SOFT_RESET_PP (1 << 4)
|
||||
# define RADEON_SOFT_RESET_E2 (1 << 5)
|
||||
# define RADEON_SOFT_RESET_RB (1 << 6)
|
||||
# define RADEON_SOFT_RESET_HDP (1 << 7)
|
||||
#define RADEON_RBBM_STATUS 0x0e40
|
||||
# define RADEON_RBBM_FIFOCNT_MASK 0x007f
|
||||
# define RADEON_RBBM_ACTIVE (1 << 31)
|
||||
#define RADEON_RE_LINE_PATTERN 0x1cd0
|
||||
#define RADEON_RE_MISC 0x26c4
|
||||
#define RADEON_RE_TOP_LEFT 0x26c0
|
||||
#define RADEON_RE_WIDTH_HEIGHT 0x1c44
|
||||
#define RADEON_RE_STIPPLE_ADDR 0x1cc8
|
||||
#define RADEON_RE_STIPPLE_DATA 0x1ccc
|
||||
|
||||
#define RADEON_SCISSOR_TL_0 0x1cd8
|
||||
#define RADEON_SCISSOR_BR_0 0x1cdc
|
||||
#define RADEON_SCISSOR_TL_1 0x1ce0
|
||||
#define RADEON_SCISSOR_BR_1 0x1ce4
|
||||
#define RADEON_SCISSOR_TL_2 0x1ce8
|
||||
#define RADEON_SCISSOR_BR_2 0x1cec
|
||||
#define RADEON_SE_COORD_FMT 0x1c50
|
||||
#define RADEON_SE_CNTL 0x1c4c
|
||||
# define RADEON_FFACE_CULL_CW (0 << 0)
|
||||
# define RADEON_BFACE_SOLID (3 << 1)
|
||||
# define RADEON_FFACE_SOLID (3 << 3)
|
||||
# define RADEON_FLAT_SHADE_VTX_LAST (3 << 6)
|
||||
# define RADEON_DIFFUSE_SHADE_FLAT (1 << 8)
|
||||
# define RADEON_DIFFUSE_SHADE_GOURAUD (2 << 8)
|
||||
# define RADEON_ALPHA_SHADE_FLAT (1 << 10)
|
||||
# define RADEON_ALPHA_SHADE_GOURAUD (2 << 10)
|
||||
# define RADEON_SPECULAR_SHADE_FLAT (1 << 12)
|
||||
# define RADEON_SPECULAR_SHADE_GOURAUD (2 << 12)
|
||||
# define RADEON_FOG_SHADE_FLAT (1 << 14)
|
||||
# define RADEON_FOG_SHADE_GOURAUD (2 << 14)
|
||||
# define RADEON_VPORT_XY_XFORM_ENABLE (1 << 24)
|
||||
# define RADEON_VPORT_Z_XFORM_ENABLE (1 << 25)
|
||||
# define RADEON_VTX_PIX_CENTER_OGL (1 << 27)
|
||||
# define RADEON_ROUND_MODE_TRUNC (0 << 28)
|
||||
# define RADEON_ROUND_PREC_8TH_PIX (1 << 30)
|
||||
#define RADEON_SE_CNTL_STATUS 0x2140
|
||||
#define RADEON_SE_LINE_WIDTH 0x1db8
|
||||
#define RADEON_SE_VPORT_XSCALE 0x1d98
|
||||
#define RADEON_SURFACE_ACCESS_FLAGS 0x0bf8
|
||||
#define RADEON_SURFACE_ACCESS_CLR 0x0bfc
|
||||
#define RADEON_SURFACE_CNTL 0x0b00
|
||||
# define RADEON_SURF_TRANSLATION_DIS (1 << 8)
|
||||
# define RADEON_NONSURF_AP0_SWP_MASK (3 << 20)
|
||||
# define RADEON_NONSURF_AP0_SWP_LITTLE (0 << 20)
|
||||
# define RADEON_NONSURF_AP0_SWP_BIG16 (1 << 20)
|
||||
# define RADEON_NONSURF_AP0_SWP_BIG32 (2 << 20)
|
||||
# define RADEON_NONSURF_AP1_SWP_MASK (3 << 22)
|
||||
# define RADEON_NONSURF_AP1_SWP_LITTLE (0 << 22)
|
||||
# define RADEON_NONSURF_AP1_SWP_BIG16 (1 << 22)
|
||||
# define RADEON_NONSURF_AP1_SWP_BIG32 (2 << 22)
|
||||
#define RADEON_SURFACE0_INFO 0x0b0c
|
||||
# define RADEON_SURF_PITCHSEL_MASK (0x1ff << 0)
|
||||
# define RADEON_SURF_TILE_MODE_MASK (3 << 16)
|
||||
# define RADEON_SURF_TILE_MODE_MACRO (0 << 16)
|
||||
# define RADEON_SURF_TILE_MODE_MICRO (1 << 16)
|
||||
# define RADEON_SURF_TILE_MODE_32BIT_Z (2 << 16)
|
||||
# define RADEON_SURF_TILE_MODE_16BIT_Z (3 << 16)
|
||||
#define RADEON_SURFACE0_LOWER_BOUND 0x0b04
|
||||
#define RADEON_SURFACE0_UPPER_BOUND 0x0b08
|
||||
#define RADEON_SURFACE1_INFO 0x0b1c
|
||||
#define RADEON_SURFACE1_LOWER_BOUND 0x0b14
|
||||
#define RADEON_SURFACE1_UPPER_BOUND 0x0b18
|
||||
#define RADEON_SURFACE2_INFO 0x0b2c
|
||||
#define RADEON_SURFACE2_LOWER_BOUND 0x0b24
|
||||
#define RADEON_SURFACE2_UPPER_BOUND 0x0b28
|
||||
#define RADEON_SURFACE3_INFO 0x0b3c
|
||||
#define RADEON_SURFACE3_LOWER_BOUND 0x0b34
|
||||
#define RADEON_SURFACE3_UPPER_BOUND 0x0b38
|
||||
#define RADEON_SURFACE4_INFO 0x0b4c
|
||||
#define RADEON_SURFACE4_LOWER_BOUND 0x0b44
|
||||
#define RADEON_SURFACE4_UPPER_BOUND 0x0b48
|
||||
#define RADEON_SURFACE5_INFO 0x0b5c
|
||||
#define RADEON_SURFACE5_LOWER_BOUND 0x0b54
|
||||
#define RADEON_SURFACE5_UPPER_BOUND 0x0b58
|
||||
#define RADEON_SURFACE6_INFO 0x0b6c
|
||||
#define RADEON_SURFACE6_LOWER_BOUND 0x0b64
|
||||
#define RADEON_SURFACE6_UPPER_BOUND 0x0b68
|
||||
#define RADEON_SURFACE7_INFO 0x0b7c
|
||||
#define RADEON_SURFACE7_LOWER_BOUND 0x0b74
|
||||
#define RADEON_SURFACE7_UPPER_BOUND 0x0b78
|
||||
#define RADEON_SW_SEMAPHORE 0x013c
|
||||
|
||||
#define RADEON_WAIT_UNTIL 0x1720
|
||||
# define RADEON_WAIT_CRTC_PFLIP (1 << 0)
|
||||
# define RADEON_WAIT_2D_IDLECLEAN (1 << 16)
|
||||
# define RADEON_WAIT_3D_IDLECLEAN (1 << 17)
|
||||
# define RADEON_WAIT_HOST_IDLECLEAN (1 << 18)
|
||||
|
||||
#define RADEON_RB3D_ZMASKOFFSET 0x1c34
|
||||
#define RADEON_RB3D_ZSTENCILCNTL 0x1c2c
|
||||
# define RADEON_DEPTH_FORMAT_16BIT_INT_Z (0 << 0)
|
||||
# define RADEON_DEPTH_FORMAT_24BIT_INT_Z (2 << 0)
|
||||
|
||||
|
||||
/* CP registers */
|
||||
#define RADEON_CP_ME_RAM_ADDR 0x07d4
|
||||
#define RADEON_CP_ME_RAM_RADDR 0x07d8
|
||||
#define RADEON_CP_ME_RAM_DATAH 0x07dc
|
||||
#define RADEON_CP_ME_RAM_DATAL 0x07e0
|
||||
|
||||
#define RADEON_CP_RB_BASE 0x0700
|
||||
#define RADEON_CP_RB_CNTL 0x0704
|
||||
#define RADEON_CP_RB_RPTR_ADDR 0x070c
|
||||
#define RADEON_CP_RB_RPTR 0x0710
|
||||
#define RADEON_CP_RB_WPTR 0x0714
|
||||
|
||||
#define RADEON_CP_RB_WPTR_DELAY 0x0718
|
||||
# define RADEON_PRE_WRITE_TIMER_SHIFT 0
|
||||
# define RADEON_PRE_WRITE_LIMIT_SHIFT 23
|
||||
|
||||
#define RADEON_CP_IB_BASE 0x0738
|
||||
|
||||
#define RADEON_CP_CSQ_CNTL 0x0740
|
||||
# define RADEON_CSQ_CNT_PRIMARY_MASK (0xff << 0)
|
||||
# define RADEON_CSQ_PRIDIS_INDDIS (0 << 28)
|
||||
# define RADEON_CSQ_PRIPIO_INDDIS (1 << 28)
|
||||
# define RADEON_CSQ_PRIBM_INDDIS (2 << 28)
|
||||
# define RADEON_CSQ_PRIPIO_INDBM (3 << 28)
|
||||
# define RADEON_CSQ_PRIBM_INDBM (4 << 28)
|
||||
# define RADEON_CSQ_PRIPIO_INDPIO (15 << 28)
|
||||
|
||||
#define RADEON_AIC_CNTL 0x01d0
|
||||
# define RADEON_PCIGART_TRANSLATE_EN (1 << 0)
|
||||
#define RADEON_AIC_STAT 0x01d4
|
||||
#define RADEON_AIC_PT_BASE 0x01d8
|
||||
#define RADEON_AIC_LO_ADDR 0x01dc
|
||||
#define RADEON_AIC_HI_ADDR 0x01e0
|
||||
#define RADEON_AIC_TLB_ADDR 0x01e4
|
||||
#define RADEON_AIC_TLB_DATA 0x01e8
|
||||
|
||||
/* CP command packets */
|
||||
#define RADEON_CP_PACKET0 0x00000000
|
||||
# define RADEON_ONE_REG_WR (1 << 15)
|
||||
#define RADEON_CP_PACKET1 0x40000000
|
||||
#define RADEON_CP_PACKET2 0x80000000
|
||||
#define RADEON_CP_PACKET3 0xC0000000
|
||||
# define RADEON_3D_RNDR_GEN_INDX_PRIM 0x00002300
|
||||
# define RADEON_WAIT_FOR_IDLE 0x00002600
|
||||
# define RADEON_3D_DRAW_IMMD 0x00002900
|
||||
# define RADEON_3D_CLEAR_ZMASK 0x00003200
|
||||
# define RADEON_CNTL_HOSTDATA_BLT 0x00009400
|
||||
# define RADEON_CNTL_PAINT_MULTI 0x00009A00
|
||||
# define RADEON_CNTL_BITBLT_MULTI 0x00009B00
|
||||
|
||||
#define RADEON_CP_PACKET_MASK 0xC0000000
|
||||
#define RADEON_CP_PACKET_COUNT_MASK 0x3fff0000
|
||||
#define RADEON_CP_PACKET0_REG_MASK 0x000007ff
|
||||
#define RADEON_CP_PACKET1_REG0_MASK 0x000007ff
|
||||
#define RADEON_CP_PACKET1_REG1_MASK 0x003ff800
|
||||
|
||||
#define RADEON_VTX_Z_PRESENT (1 << 31)
|
||||
|
||||
#define RADEON_PRIM_TYPE_NONE (0 << 0)
|
||||
#define RADEON_PRIM_TYPE_POINT (1 << 0)
|
||||
#define RADEON_PRIM_TYPE_LINE (2 << 0)
|
||||
#define RADEON_PRIM_TYPE_LINE_STRIP (3 << 0)
|
||||
#define RADEON_PRIM_TYPE_TRI_LIST (4 << 0)
|
||||
#define RADEON_PRIM_TYPE_TRI_FAN (5 << 0)
|
||||
#define RADEON_PRIM_TYPE_TRI_STRIP (6 << 0)
|
||||
#define RADEON_PRIM_TYPE_TRI_TYPE2 (7 << 0)
|
||||
#define RADEON_PRIM_TYPE_RECT_LIST (8 << 0)
|
||||
#define RADEON_PRIM_TYPE_3VRT_POINT_LIST (9 << 0)
|
||||
#define RADEON_PRIM_TYPE_3VRT_LINE_LIST (10 << 0)
|
||||
#define RADEON_PRIM_WALK_IND (1 << 4)
|
||||
#define RADEON_PRIM_WALK_LIST (2 << 4)
|
||||
#define RADEON_PRIM_WALK_RING (3 << 4)
|
||||
#define RADEON_COLOR_ORDER_BGRA (0 << 6)
|
||||
#define RADEON_COLOR_ORDER_RGBA (1 << 6)
|
||||
#define RADEON_MAOS_ENABLE (1 << 7)
|
||||
#define RADEON_VTX_FMT_R128_MODE (0 << 8)
|
||||
#define RADEON_VTX_FMT_RADEON_MODE (1 << 8)
|
||||
#define RADEON_NUM_VERTICES_SHIFT 16
|
||||
|
||||
#define RADEON_COLOR_FORMAT_CI8 2
|
||||
#define RADEON_COLOR_FORMAT_ARGB1555 3
|
||||
#define RADEON_COLOR_FORMAT_RGB565 4
|
||||
#define RADEON_COLOR_FORMAT_ARGB8888 6
|
||||
#define RADEON_COLOR_FORMAT_RGB332 7
|
||||
#define RADEON_COLOR_FORMAT_RGB8 9
|
||||
#define RADEON_COLOR_FORMAT_ARGB4444 15
|
||||
|
||||
#define RADEON_TXFORMAT_I8 0
|
||||
#define RADEON_TXFORMAT_AI88 1
|
||||
#define RADEON_TXFORMAT_RGB332 2
|
||||
#define RADEON_TXFORMAT_ARGB1555 3
|
||||
#define RADEON_TXFORMAT_RGB565 4
|
||||
#define RADEON_TXFORMAT_ARGB4444 5
|
||||
#define RADEON_TXFORMAT_ARGB8888 6
|
||||
#define RADEON_TXFORMAT_RGBA8888 7
|
||||
|
||||
/* Constants */
|
||||
#define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
|
||||
|
||||
#define RADEON_LAST_FRAME_REG RADEON_SCRATCH_REG0
|
||||
#define RADEON_LAST_DISPATCH_REG RADEON_SCRATCH_REG1
|
||||
#define RADEON_LAST_CLEAR_REG RADEON_SCRATCH_REG2
|
||||
#define RADEON_LAST_DISPATCH 1
|
||||
|
||||
#define RADEON_MAX_VB_AGE 0x7fffffff
|
||||
#define RADEON_MAX_VB_VERTS (0xffff)
|
||||
|
||||
#define RADEON_RING_HIGH_MARK 128
|
||||
|
||||
|
||||
#define RADEON_BASE(reg) ((unsigned long)(dev_priv->mmio->handle))
|
||||
#define RADEON_ADDR(reg) (RADEON_BASE( reg ) + reg)
|
||||
|
||||
#define RADEON_DEREF(reg) *(volatile u32 *)RADEON_ADDR( reg )
|
||||
#ifdef __alpha__
|
||||
#define RADEON_READ(reg) (_RADEON_READ((u32 *)RADEON_ADDR( reg )))
|
||||
static inline u32 _RADEON_READ(u32 *addr)
|
||||
{
|
||||
DRM_OS_READMEMORYBARRIER;
|
||||
return *(volatile u32 *)addr;
|
||||
}
|
||||
#define RADEON_WRITE(reg,val) \
|
||||
do { \
|
||||
DRM_OS_WRITEMEMORYBARRIER; \
|
||||
RADEON_DEREF(reg) = val; \
|
||||
} while (0)
|
||||
#else
|
||||
#define RADEON_READ(reg) RADEON_DEREF( reg )
|
||||
#define RADEON_WRITE(reg, val) do { RADEON_DEREF( reg ) = val; } while (0)
|
||||
#endif
|
||||
|
||||
#define RADEON_DEREF8(reg) *(volatile u8 *)RADEON_ADDR( reg )
|
||||
#ifdef __alpha__
|
||||
#define RADEON_READ8(reg) _RADEON_READ8((u8 *)RADEON_ADDR( reg ))
|
||||
static inline u8 _RADEON_READ8(u8 *addr)
|
||||
{
|
||||
DRM_OS_READMEMORYBARRIER;
|
||||
return *(volatile u8 *)addr;
|
||||
}
|
||||
#define RADEON_WRITE8(reg,val) \
|
||||
do { \
|
||||
DRM_OS_WRITEMEMORYBARRIER; \
|
||||
RADEON_DEREF8( reg ) = val; \
|
||||
} while (0)
|
||||
#else
|
||||
#define RADEON_READ8(reg) RADEON_DEREF8( reg )
|
||||
#define RADEON_WRITE8(reg, val) do { RADEON_DEREF8( reg ) = val; } while (0)
|
||||
#endif
|
||||
|
||||
#define RADEON_WRITE_PLL( addr, val ) \
|
||||
do { \
|
||||
RADEON_WRITE8( RADEON_CLOCK_CNTL_INDEX, \
|
||||
((addr) & 0x1f) | RADEON_PLL_WR_EN ); \
|
||||
RADEON_WRITE( RADEON_CLOCK_CNTL_DATA, (val) ); \
|
||||
} while (0)
|
||||
|
||||
extern int RADEON_READ_PLL( drm_device_t *dev, int addr );
|
||||
|
||||
|
||||
#define CP_PACKET0( reg, n ) \
|
||||
(RADEON_CP_PACKET0 | ((n) << 16) | ((reg) >> 2))
|
||||
#define CP_PACKET0_TABLE( reg, n ) \
|
||||
(RADEON_CP_PACKET0 | RADEON_ONE_REG_WR | ((n) << 16) | ((reg) >> 2))
|
||||
#define CP_PACKET1( reg0, reg1 ) \
|
||||
(RADEON_CP_PACKET1 | (((reg1) >> 2) << 15) | ((reg0) >> 2))
|
||||
#define CP_PACKET2() \
|
||||
(RADEON_CP_PACKET2)
|
||||
#define CP_PACKET3( pkt, n ) \
|
||||
(RADEON_CP_PACKET3 | (pkt) | ((n) << 16))
|
||||
|
||||
|
||||
/* ================================================================
|
||||
* Engine control helper macros
|
||||
*/
|
||||
|
||||
#define RADEON_WAIT_UNTIL_2D_IDLE() do { \
|
||||
OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) ); \
|
||||
OUT_RING( (RADEON_WAIT_2D_IDLECLEAN | \
|
||||
RADEON_WAIT_HOST_IDLECLEAN) ); \
|
||||
} while (0)
|
||||
|
||||
#define RADEON_WAIT_UNTIL_3D_IDLE() do { \
|
||||
OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) ); \
|
||||
OUT_RING( (RADEON_WAIT_3D_IDLECLEAN | \
|
||||
RADEON_WAIT_HOST_IDLECLEAN) ); \
|
||||
} while (0)
|
||||
|
||||
#define RADEON_WAIT_UNTIL_IDLE() do { \
|
||||
OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) ); \
|
||||
OUT_RING( (RADEON_WAIT_2D_IDLECLEAN | \
|
||||
RADEON_WAIT_3D_IDLECLEAN | \
|
||||
RADEON_WAIT_HOST_IDLECLEAN) ); \
|
||||
} while (0)
|
||||
|
||||
#define RADEON_WAIT_UNTIL_PAGE_FLIPPED() do { \
|
||||
OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) ); \
|
||||
OUT_RING( RADEON_WAIT_CRTC_PFLIP ); \
|
||||
} while (0)
|
||||
|
||||
#define RADEON_FLUSH_CACHE() do { \
|
||||
OUT_RING( CP_PACKET0( RADEON_RB2D_DSTCACHE_CTLSTAT, 0 ) ); \
|
||||
OUT_RING( RADEON_RB2D_DC_FLUSH ); \
|
||||
} while (0)
|
||||
|
||||
#define RADEON_PURGE_CACHE() do { \
|
||||
OUT_RING( CP_PACKET0( RADEON_RB2D_DSTCACHE_CTLSTAT, 0 ) ); \
|
||||
OUT_RING( RADEON_RB2D_DC_FLUSH_ALL ); \
|
||||
} while (0)
|
||||
|
||||
#define RADEON_FLUSH_ZCACHE() do { \
|
||||
OUT_RING( CP_PACKET0( RADEON_RB3D_ZCACHE_CTLSTAT, 0 ) ); \
|
||||
OUT_RING( RADEON_RB3D_ZC_FLUSH ); \
|
||||
} while (0)
|
||||
|
||||
#define RADEON_PURGE_ZCACHE() do { \
|
||||
OUT_RING( CP_PACKET0( RADEON_RB3D_ZCACHE_CTLSTAT, 0 ) ); \
|
||||
OUT_RING( RADEON_RB3D_ZC_FLUSH_ALL ); \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* ================================================================
|
||||
* Misc helper macros
|
||||
*/
|
||||
|
||||
#define LOCK_TEST_WITH_RETURN( dev ) \
|
||||
do { \
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
|
||||
dev->lock.pid != DRM_OS_CURRENTPID ) { \
|
||||
DRM_ERROR( "%s called without lock held\n", \
|
||||
__FUNCTION__ ); \
|
||||
DRM_OS_RETURN( EINVAL ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define RING_SPACE_TEST_WITH_RETURN( dev_priv ) \
|
||||
do { \
|
||||
drm_radeon_ring_buffer_t *ring = &dev_priv->ring; int i; \
|
||||
if ( ring->space < ring->high_mark ) { \
|
||||
for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) { \
|
||||
radeon_update_ring_snapshot( ring ); \
|
||||
if ( ring->space >= ring->high_mark ) \
|
||||
goto __ring_space_done; \
|
||||
DRM_OS_DELAY( 1 ); \
|
||||
} \
|
||||
DRM_ERROR( "ring space check failed!\n" ); \
|
||||
DRM_OS_RETURN( EBUSY ); \
|
||||
} \
|
||||
__ring_space_done: \
|
||||
} while (0)
|
||||
|
||||
#define VB_AGE_TEST_WITH_RETURN( dev_priv ) \
|
||||
do { \
|
||||
drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv; \
|
||||
if ( sarea_priv->last_dispatch >= RADEON_MAX_VB_AGE ) { \
|
||||
int __ret = radeon_do_cp_idle( dev_priv ); \
|
||||
if ( __ret ) return __ret; \
|
||||
sarea_priv->last_dispatch = 0; \
|
||||
radeon_freelist_reset( dev ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define RADEON_DISPATCH_AGE( age ) do { \
|
||||
OUT_RING( CP_PACKET0( RADEON_LAST_DISPATCH_REG, 0 ) ); \
|
||||
OUT_RING( age ); \
|
||||
} while (0)
|
||||
|
||||
#define RADEON_FRAME_AGE( age ) do { \
|
||||
OUT_RING( CP_PACKET0( RADEON_LAST_FRAME_REG, 0 ) ); \
|
||||
OUT_RING( age ); \
|
||||
} while (0)
|
||||
|
||||
#define RADEON_CLEAR_AGE( age ) do { \
|
||||
OUT_RING( CP_PACKET0( RADEON_LAST_CLEAR_REG, 0 ) ); \
|
||||
OUT_RING( age ); \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* ================================================================
|
||||
* Ring control
|
||||
*/
|
||||
|
||||
#define radeon_flush_write_combine() DRM_OS_READMEMORYBARRIER
|
||||
|
||||
|
||||
#define RADEON_VERBOSE 0
|
||||
|
||||
#define RING_LOCALS int write; unsigned int mask; volatile u32 *ring;
|
||||
|
||||
#define BEGIN_RING( n ) do { \
|
||||
if ( RADEON_VERBOSE ) { \
|
||||
DRM_INFO( "BEGIN_RING( %d ) in %s\n", \
|
||||
n, __FUNCTION__ ); \
|
||||
} \
|
||||
if ( dev_priv->ring.space <= (n) * sizeof(u32) ) { \
|
||||
radeon_wait_ring( dev_priv, (n) * sizeof(u32) ); \
|
||||
} \
|
||||
dev_priv->ring.space -= (n) * sizeof(u32); \
|
||||
ring = dev_priv->ring.start; \
|
||||
write = dev_priv->ring.tail; \
|
||||
mask = dev_priv->ring.tail_mask; \
|
||||
} while (0)
|
||||
|
||||
#define ADVANCE_RING() do { \
|
||||
if ( RADEON_VERBOSE ) { \
|
||||
DRM_INFO( "ADVANCE_RING() wr=0x%06x tail=0x%06x\n", \
|
||||
write, dev_priv->ring.tail ); \
|
||||
} \
|
||||
radeon_flush_write_combine(); \
|
||||
dev_priv->ring.tail = write; \
|
||||
RADEON_WRITE( RADEON_CP_RB_WPTR, write ); \
|
||||
} while (0)
|
||||
|
||||
#define OUT_RING( x ) do { \
|
||||
if ( RADEON_VERBOSE ) { \
|
||||
DRM_INFO( " OUT_RING( 0x%08x ) at 0x%x\n", \
|
||||
(unsigned int)(x), write ); \
|
||||
} \
|
||||
ring[write++] = (x); \
|
||||
write &= mask; \
|
||||
} while (0)
|
||||
|
||||
#define RADEON_PERFORMANCE_BOXES 0
|
||||
|
||||
#endif /* __RADEON_DRV_H__ */
|
||||
1461
bsd/radeon/radeon_state.c
Normal file
1461
bsd/radeon/radeon_state.c
Normal file
File diff suppressed because it is too large
Load diff
333
bsd/radeon_drm.h
Normal file
333
bsd/radeon_drm.h
Normal file
|
|
@ -0,0 +1,333 @@
|
|||
/* radeon_drm.h -- Public header for the radeon driver -*- linux-c -*-
|
||||
*
|
||||
* Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Fremont, 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors:
|
||||
* Kevin E. Martin <martin@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef __RADEON_DRM_H__
|
||||
#define __RADEON_DRM_H__
|
||||
|
||||
/* WARNING: If you change any of these defines, make sure to change the
|
||||
* defines in the X server file (radeon_sarea.h)
|
||||
*/
|
||||
#ifndef __RADEON_SAREA_DEFINES__
|
||||
#define __RADEON_SAREA_DEFINES__
|
||||
|
||||
/* What needs to be changed for the current vertex buffer?
|
||||
*/
|
||||
#define RADEON_UPLOAD_CONTEXT 0x00000001
|
||||
#define RADEON_UPLOAD_VERTFMT 0x00000002
|
||||
#define RADEON_UPLOAD_LINE 0x00000004
|
||||
#define RADEON_UPLOAD_BUMPMAP 0x00000008
|
||||
#define RADEON_UPLOAD_MASKS 0x00000010
|
||||
#define RADEON_UPLOAD_VIEWPORT 0x00000020
|
||||
#define RADEON_UPLOAD_SETUP 0x00000040
|
||||
#define RADEON_UPLOAD_TCL 0x00000080
|
||||
#define RADEON_UPLOAD_MISC 0x00000100
|
||||
#define RADEON_UPLOAD_TEX0 0x00000200
|
||||
#define RADEON_UPLOAD_TEX1 0x00000400
|
||||
#define RADEON_UPLOAD_TEX2 0x00000800
|
||||
#define RADEON_UPLOAD_TEX0IMAGES 0x00001000
|
||||
#define RADEON_UPLOAD_TEX1IMAGES 0x00002000
|
||||
#define RADEON_UPLOAD_TEX2IMAGES 0x00004000
|
||||
#define RADEON_UPLOAD_CLIPRECTS 0x00008000 /* handled client-side */
|
||||
#define RADEON_REQUIRE_QUIESCENCE 0x00010000
|
||||
#define RADEON_UPLOAD_ALL 0x0001ffff
|
||||
|
||||
#define RADEON_FRONT 0x1
|
||||
#define RADEON_BACK 0x2
|
||||
#define RADEON_DEPTH 0x4
|
||||
|
||||
/* Primitive types
|
||||
*/
|
||||
#define RADEON_POINTS 0x1
|
||||
#define RADEON_LINES 0x2
|
||||
#define RADEON_LINE_STRIP 0x3
|
||||
#define RADEON_TRIANGLES 0x4
|
||||
#define RADEON_TRIANGLE_FAN 0x5
|
||||
#define RADEON_TRIANGLE_STRIP 0x6
|
||||
|
||||
/* Vertex/indirect buffer size
|
||||
*/
|
||||
#define RADEON_BUFFER_SIZE 65536
|
||||
|
||||
/* Byte offsets for indirect buffer data
|
||||
*/
|
||||
#define RADEON_INDEX_PRIM_OFFSET 20
|
||||
#define RADEON_HOSTDATA_BLIT_OFFSET 32
|
||||
|
||||
#define RADEON_SCRATCH_REG_OFFSET 32
|
||||
|
||||
/* Keep these small for testing
|
||||
*/
|
||||
#define RADEON_NR_SAREA_CLIPRECTS 12
|
||||
|
||||
/* There are 2 heaps (local/AGP). Each region within a heap is a
|
||||
* minimum of 64k, and there are at most 64 of them per heap.
|
||||
*/
|
||||
#define RADEON_LOCAL_TEX_HEAP 0
|
||||
#define RADEON_AGP_TEX_HEAP 1
|
||||
#define RADEON_NR_TEX_HEAPS 2
|
||||
#define RADEON_NR_TEX_REGIONS 64
|
||||
#define RADEON_LOG_TEX_GRANULARITY 16
|
||||
|
||||
#define RADEON_MAX_TEXTURE_LEVELS 11
|
||||
#define RADEON_MAX_TEXTURE_UNITS 3
|
||||
|
||||
#endif /* __RADEON_SAREA_DEFINES__ */
|
||||
|
||||
typedef struct {
|
||||
unsigned int red;
|
||||
unsigned int green;
|
||||
unsigned int blue;
|
||||
unsigned int alpha;
|
||||
} radeon_color_regs_t;
|
||||
|
||||
typedef struct {
|
||||
/* Context state */
|
||||
unsigned int pp_misc; /* 0x1c14 */
|
||||
unsigned int pp_fog_color;
|
||||
unsigned int re_solid_color;
|
||||
unsigned int rb3d_blendcntl;
|
||||
unsigned int rb3d_depthoffset;
|
||||
unsigned int rb3d_depthpitch;
|
||||
unsigned int rb3d_zstencilcntl;
|
||||
|
||||
unsigned int pp_cntl; /* 0x1c38 */
|
||||
unsigned int rb3d_cntl;
|
||||
unsigned int rb3d_coloroffset;
|
||||
unsigned int re_width_height;
|
||||
unsigned int rb3d_colorpitch;
|
||||
unsigned int se_cntl;
|
||||
|
||||
/* Vertex format state */
|
||||
unsigned int se_coord_fmt; /* 0x1c50 */
|
||||
|
||||
/* Line state */
|
||||
unsigned int re_line_pattern; /* 0x1cd0 */
|
||||
unsigned int re_line_state;
|
||||
|
||||
unsigned int se_line_width; /* 0x1db8 */
|
||||
|
||||
/* Bumpmap state */
|
||||
unsigned int pp_lum_matrix; /* 0x1d00 */
|
||||
|
||||
unsigned int pp_rot_matrix_0; /* 0x1d58 */
|
||||
unsigned int pp_rot_matrix_1;
|
||||
|
||||
/* Mask state */
|
||||
unsigned int rb3d_stencilrefmask; /* 0x1d7c */
|
||||
unsigned int rb3d_ropcntl;
|
||||
unsigned int rb3d_planemask;
|
||||
|
||||
/* Viewport state */
|
||||
unsigned int se_vport_xscale; /* 0x1d98 */
|
||||
unsigned int se_vport_xoffset;
|
||||
unsigned int se_vport_yscale;
|
||||
unsigned int se_vport_yoffset;
|
||||
unsigned int se_vport_zscale;
|
||||
unsigned int se_vport_zoffset;
|
||||
|
||||
/* Setup state */
|
||||
unsigned int se_cntl_status; /* 0x2140 */
|
||||
|
||||
#ifdef TCL_ENABLE
|
||||
/* TCL state */
|
||||
radeon_color_regs_t se_tcl_material_emmissive; /* 0x2210 */
|
||||
radeon_color_regs_t se_tcl_material_ambient;
|
||||
radeon_color_regs_t se_tcl_material_diffuse;
|
||||
radeon_color_regs_t se_tcl_material_specular;
|
||||
unsigned int se_tcl_shininess;
|
||||
unsigned int se_tcl_output_vtx_fmt;
|
||||
unsigned int se_tcl_output_vtx_sel;
|
||||
unsigned int se_tcl_matrix_select_0;
|
||||
unsigned int se_tcl_matrix_select_1;
|
||||
unsigned int se_tcl_ucp_vert_blend_ctl;
|
||||
unsigned int se_tcl_texture_proc_ctl;
|
||||
unsigned int se_tcl_light_model_ctl;
|
||||
unsigned int se_tcl_per_light_ctl[4];
|
||||
#endif
|
||||
|
||||
/* Misc state */
|
||||
unsigned int re_top_left; /* 0x26c0 */
|
||||
unsigned int re_misc;
|
||||
} drm_radeon_context_regs_t;
|
||||
|
||||
/* Setup registers for each texture unit
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int pp_txfilter;
|
||||
unsigned int pp_txformat;
|
||||
unsigned int pp_txoffset;
|
||||
unsigned int pp_txcblend;
|
||||
unsigned int pp_txablend;
|
||||
unsigned int pp_tfactor;
|
||||
|
||||
unsigned int pp_border_color;
|
||||
|
||||
#ifdef CUBIC_ENABLE
|
||||
unsigned int pp_cubic_faces;
|
||||
unsigned int pp_cubic_offset[5];
|
||||
#endif
|
||||
} drm_radeon_texture_regs_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned char next, prev;
|
||||
unsigned char in_use;
|
||||
int age;
|
||||
} drm_radeon_tex_region_t;
|
||||
|
||||
typedef struct {
|
||||
/* The channel for communication of state information to the kernel
|
||||
* on firing a vertex buffer.
|
||||
*/
|
||||
drm_radeon_context_regs_t context_state;
|
||||
drm_radeon_texture_regs_t tex_state[RADEON_MAX_TEXTURE_UNITS];
|
||||
unsigned int dirty;
|
||||
unsigned int vertsize;
|
||||
unsigned int vc_format;
|
||||
|
||||
/* The current cliprects, or a subset thereof.
|
||||
*/
|
||||
drm_clip_rect_t boxes[RADEON_NR_SAREA_CLIPRECTS];
|
||||
unsigned int nbox;
|
||||
|
||||
/* Counters for client-side throttling of rendering clients.
|
||||
*/
|
||||
unsigned int last_frame;
|
||||
unsigned int last_dispatch;
|
||||
unsigned int last_clear;
|
||||
|
||||
drm_radeon_tex_region_t tex_list[RADEON_NR_TEX_HEAPS][RADEON_NR_TEX_REGIONS+1];
|
||||
int tex_age[RADEON_NR_TEX_HEAPS];
|
||||
int ctx_owner;
|
||||
} drm_radeon_sarea_t;
|
||||
|
||||
|
||||
/* WARNING: If you change any of these defines, make sure to change the
|
||||
* defines in the Xserver file (xf86drmRadeon.h)
|
||||
*/
|
||||
typedef struct drm_radeon_init {
|
||||
enum {
|
||||
RADEON_INIT_CP = 0x01,
|
||||
RADEON_CLEANUP_CP = 0x02
|
||||
} func;
|
||||
unsigned long sarea_priv_offset;
|
||||
int is_pci;
|
||||
int cp_mode;
|
||||
int agp_size;
|
||||
int ring_size;
|
||||
int usec_timeout;
|
||||
|
||||
unsigned int fb_bpp;
|
||||
unsigned int front_offset, front_pitch;
|
||||
unsigned int back_offset, back_pitch;
|
||||
unsigned int depth_bpp;
|
||||
unsigned int depth_offset, depth_pitch;
|
||||
|
||||
unsigned long fb_offset;
|
||||
unsigned long mmio_offset;
|
||||
unsigned long ring_offset;
|
||||
unsigned long ring_rptr_offset;
|
||||
unsigned long buffers_offset;
|
||||
unsigned long agp_textures_offset;
|
||||
} drm_radeon_init_t;
|
||||
|
||||
typedef struct drm_radeon_cp_stop {
|
||||
int flush;
|
||||
int idle;
|
||||
} drm_radeon_cp_stop_t;
|
||||
|
||||
typedef struct drm_radeon_fullscreen {
|
||||
enum {
|
||||
RADEON_INIT_FULLSCREEN = 0x01,
|
||||
RADEON_CLEANUP_FULLSCREEN = 0x02
|
||||
} func;
|
||||
} drm_radeon_fullscreen_t;
|
||||
|
||||
#define CLEAR_X1 0
|
||||
#define CLEAR_Y1 1
|
||||
#define CLEAR_X2 2
|
||||
#define CLEAR_Y2 3
|
||||
#define CLEAR_DEPTH 4
|
||||
|
||||
typedef union drm_radeon_clear_rect {
|
||||
float f[5];
|
||||
unsigned int ui[5];
|
||||
} drm_radeon_clear_rect_t;
|
||||
|
||||
typedef struct drm_radeon_clear {
|
||||
unsigned int flags;
|
||||
unsigned int clear_color;
|
||||
unsigned int clear_depth;
|
||||
unsigned int color_mask;
|
||||
unsigned int depth_mask;
|
||||
drm_radeon_clear_rect_t *depth_boxes;
|
||||
} drm_radeon_clear_t;
|
||||
|
||||
typedef struct drm_radeon_vertex {
|
||||
int prim;
|
||||
int idx; /* Index of vertex buffer */
|
||||
int count; /* Number of vertices in buffer */
|
||||
int discard; /* Client finished with buffer? */
|
||||
} drm_radeon_vertex_t;
|
||||
|
||||
typedef struct drm_radeon_indices {
|
||||
int prim;
|
||||
int idx;
|
||||
int start;
|
||||
int end;
|
||||
int discard; /* Client finished with buffer? */
|
||||
} drm_radeon_indices_t;
|
||||
|
||||
typedef struct drm_radeon_tex_image {
|
||||
unsigned int x, y; /* Blit coordinates */
|
||||
unsigned int width, height;
|
||||
const void *data;
|
||||
} drm_radeon_tex_image_t;
|
||||
|
||||
typedef struct drm_radeon_texture {
|
||||
int offset;
|
||||
int pitch;
|
||||
int format;
|
||||
int width; /* Texture image coordinates */
|
||||
int height;
|
||||
drm_radeon_tex_image_t *image;
|
||||
} drm_radeon_texture_t;
|
||||
|
||||
typedef struct drm_radeon_stipple {
|
||||
unsigned int *mask;
|
||||
} drm_radeon_stipple_t;
|
||||
|
||||
typedef struct drm_radeon_indirect {
|
||||
int idx;
|
||||
int start;
|
||||
int end;
|
||||
int discard;
|
||||
} drm_radeon_indirect_t;
|
||||
|
||||
#endif
|
||||
45
bsd/sis/sis.h
Normal file
45
bsd/sis/sis.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* sis_drv.h -- Private header for sis driver -*- linux-c -*-
|
||||
*
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
*/
|
||||
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/drm/kernel/sis/sis.h,v 1.1 2001/12/13 00:24:51 alanh Exp $ */
|
||||
|
||||
#ifndef __SIS_H__
|
||||
#define __SIS_H__
|
||||
|
||||
|
||||
/* General customization:
|
||||
*/
|
||||
#define __HAVE_AGP 1
|
||||
#define __MUST_HAVE_AGP 0
|
||||
#define __HAVE_MTRR 1
|
||||
#define __HAVE_CTX_BITMAP 1
|
||||
|
||||
/* Buffer customization:
|
||||
*/
|
||||
#define DRIVER_AGP_BUFFERS_MAP( dev ) \
|
||||
((drm_sis_private_t *)((dev)->dev_private))->buffers
|
||||
|
||||
#endif
|
||||
30
bsd/sis/sis_drm.h
Normal file
30
bsd/sis/sis_drm.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
#ifndef _sis_drm_public_h_
|
||||
#define _sis_drm_public_h_
|
||||
|
||||
typedef struct {
|
||||
int context;
|
||||
unsigned int offset;
|
||||
unsigned int size;
|
||||
unsigned int free;
|
||||
} drm_sis_mem_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int offset, size;
|
||||
} drm_sis_agp_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int left, right;
|
||||
} drm_sis_flip_t;
|
||||
|
||||
#if defined(__KERNEL__) || defined(_KERNEL)
|
||||
|
||||
int sis_fb_alloc(DRM_OS_IOCTL);
|
||||
int sis_fb_free(DRM_OS_IOCTL);
|
||||
int sisp_agp_init(DRM_OS_IOCTL);
|
||||
int sisp_agp_alloc(DRM_OS_IOCTL);
|
||||
int sisp_agp_free(DRM_OS_IOCTL);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
90
bsd/sis/sis_drv.c
Normal file
90
bsd/sis/sis_drv.c
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/* sis.c -- sis driver -*- linux-c -*-
|
||||
*
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/bus.h>
|
||||
#include <pci/pcivar.h>
|
||||
#include <opt_drm_linux.h>
|
||||
|
||||
#include "sis.h"
|
||||
#include "drmP.h"
|
||||
#include "sis_drm.h"
|
||||
#include "sis_drv.h"
|
||||
|
||||
#define DRIVER_AUTHOR "SIS"
|
||||
#define DRIVER_NAME "sis"
|
||||
#define DRIVER_DESC "SIS 300/630/540"
|
||||
#define DRIVER_DATE "20010503"
|
||||
#define DRIVER_MAJOR 1
|
||||
#define DRIVER_MINOR 0
|
||||
#define DRIVER_PATCHLEVEL 0
|
||||
|
||||
/* List acquired from http://www.yourvote.com/pci/pcihdr.h and xc/xc/programs/Xserver/hw/xfree86/common/xf86PciInfo.h
|
||||
* Please report to anholt@teleport.com inaccuracies or if a chip you have works that is marked unsupported here.
|
||||
*/
|
||||
drm_chipinfo_t DRM(devicelist)[] = {
|
||||
{0x1039, 0x0300, 1, "SIS 300"},
|
||||
{0x1039, 0x0540, 1, "SIS 540"},
|
||||
{0x1039, 0x0630, 1, "SIS 630"},
|
||||
{0, 0, 0, NULL}
|
||||
};
|
||||
|
||||
#define DRIVER_IOCTLS \
|
||||
[DRM_IOCTL_NR(SIS_IOCTL_FB_ALLOC)] = { sis_fb_alloc, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(SIS_IOCTL_FB_FREE)] = { sis_fb_free, 1, 1 }, \
|
||||
/* AGP Memory Management */ \
|
||||
[DRM_IOCTL_NR(SIS_IOCTL_AGP_INIT)] = { sisp_agp_init, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(SIS_IOCTL_AGP_ALLOC)] = { sisp_agp_alloc, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(SIS_IOCTL_AGP_FREE)] = { sisp_agp_free, 1, 1 }
|
||||
#if 0 /* these don't appear to be defined */
|
||||
/* SIS Stereo */
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = { sis_control, 1, 1 },
|
||||
[DRM_IOCTL_NR(SIS_IOCTL_FLIP)] = { sis_flip, 1, 1 },
|
||||
[DRM_IOCTL_NR(SIS_IOCTL_FLIP_INIT)] = { sis_flip_init, 1, 1 },
|
||||
[DRM_IOCTL_NR(SIS_IOCTL_FLIP_FINAL)] = { sis_flip_final, 1, 1 }
|
||||
#endif
|
||||
|
||||
#define __HAVE_COUNTERS 5
|
||||
|
||||
#include "drm_auth.h"
|
||||
#include "drm_agpsupport.h"
|
||||
#include "drm_bufs.h"
|
||||
#include "drm_context.h"
|
||||
#include "drm_dma.h"
|
||||
#include "drm_drawable.h"
|
||||
#include "drm_drv.h"
|
||||
#include "drm_fops.h"
|
||||
#include "drm_init.h"
|
||||
#include "drm_ioctl.h"
|
||||
#include "drm_lists.h"
|
||||
#include "drm_lock.h"
|
||||
#include "drm_memory.h"
|
||||
#include "drm_vm.h"
|
||||
#include "drm_sysctl.h"
|
||||
|
||||
DRIVER_MODULE(sis, pci, sis_driver, sis_devclass, 0, 0);
|
||||
42
bsd/sis/sis_drv.h
Normal file
42
bsd/sis/sis_drv.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* sis_drv.h -- Private header for sis driver -*- linux-c -*-
|
||||
*
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SIS_DRV_H_
|
||||
#define _SIS_DRV_H_
|
||||
|
||||
typedef struct drm_sis_private {
|
||||
drm_map_t *buffers;
|
||||
} drm_sis_private_t;
|
||||
|
||||
/* Stereo ? - this was never committed */
|
||||
|
||||
int sis_flip( DRM_OS_IOCTL );
|
||||
int sis_flip_init( DRM_OS_IOCTL );
|
||||
int sis_flip_final( DRM_OS_IOCTL );
|
||||
void flip_final(void);
|
||||
|
||||
#endif
|
||||
398
bsd/sis/sis_ds.c
Normal file
398
bsd/sis/sis_ds.c
Normal file
|
|
@ -0,0 +1,398 @@
|
|||
/* sis_ds.c -- Private header for Direct Rendering Manager -*- linux-c -*-
|
||||
* Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw
|
||||
*
|
||||
* Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors:
|
||||
* Sung-Ching Lin <sclin@sis.com.tw>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "sis.h"
|
||||
#include "drmP.h"
|
||||
#include "sis_ds.h"
|
||||
|
||||
/* Set Data Structure, not check repeated value
|
||||
* temporarily used
|
||||
*/
|
||||
|
||||
set_t *setInit(void)
|
||||
{
|
||||
int i;
|
||||
set_t *set;
|
||||
|
||||
set = (set_t *)SD_MALLOC(sizeof(set_t));
|
||||
for(i = 0; i < SET_SIZE; i++){
|
||||
set->list[i].free_next = i+1;
|
||||
set->list[i].alloc_next = -1;
|
||||
}
|
||||
set->list[SET_SIZE-1].free_next = -1;
|
||||
set->free = 0;
|
||||
set->alloc = -1;
|
||||
set->trace = -1;
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
int setAdd(set_t *set, ITEM_TYPE item)
|
||||
{
|
||||
int free = set->free;
|
||||
|
||||
if(free != -1){
|
||||
set->list[free].val = item;
|
||||
set->free = set->list[free].free_next;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set->list[free].alloc_next = set->alloc;
|
||||
set->alloc = free;
|
||||
set->list[free].free_next = -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int setDel(set_t *set, ITEM_TYPE item)
|
||||
{
|
||||
int alloc = set->alloc;
|
||||
int prev = -1;
|
||||
|
||||
while(alloc != -1){
|
||||
if(set->list[alloc].val == item){
|
||||
if(prev != -1)
|
||||
set->list[prev].alloc_next = set->list[alloc].alloc_next;
|
||||
else
|
||||
set->alloc = set->list[alloc].alloc_next;
|
||||
break;
|
||||
}
|
||||
prev = alloc;
|
||||
alloc = set->list[alloc].alloc_next;
|
||||
}
|
||||
|
||||
if(alloc == -1)
|
||||
return 0;
|
||||
|
||||
set->list[alloc].free_next = set->free;
|
||||
set->free = alloc;
|
||||
set->list[alloc].alloc_next = -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* setFirst -> setAdd -> setNext is wrong */
|
||||
|
||||
int setFirst(set_t *set, ITEM_TYPE *item)
|
||||
{
|
||||
if(set->alloc == -1)
|
||||
return 0;
|
||||
|
||||
*item = set->list[set->alloc].val;
|
||||
set->trace = set->list[set->alloc].alloc_next;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int setNext(set_t *set, ITEM_TYPE *item)
|
||||
{
|
||||
if(set->trace == -1)
|
||||
return 0;
|
||||
|
||||
*item = set->list[set->trace].val;
|
||||
set->trace = set->list[set->trace].alloc_next;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int setDestroy(set_t *set)
|
||||
{
|
||||
SD_FREE(set);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* GLX Hardware Device Driver common code
|
||||
* Copyright (C) 1999 Keith Whitwell
|
||||
*
|
||||
* 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 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
|
||||
* KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#define ISFREE(bptr) ((bptr)->free)
|
||||
|
||||
#define PRINTF(fmt, arg...) do{}while(0)
|
||||
#define fprintf(fmt, arg...) do{}while(0)
|
||||
|
||||
static void *calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *addr;
|
||||
addr = SD_MALLOC(nmemb*size);
|
||||
memset(addr, 0, nmemb*size);
|
||||
return addr;
|
||||
}
|
||||
|
||||
void mmDumpMemInfo( memHeap_t *heap )
|
||||
{
|
||||
TMemBlock *p;
|
||||
|
||||
PRINTF ("Memory heap %p:\n", heap);
|
||||
if (heap == 0) {
|
||||
PRINTF (" heap == 0\n");
|
||||
} else {
|
||||
p = (TMemBlock *)heap;
|
||||
while (p) {
|
||||
PRINTF (" Offset:%08x, Size:%08x, %c%c\n",p->ofs,p->size,
|
||||
p->free ? '.':'U',
|
||||
p->reserved ? 'R':'.');
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
PRINTF ("End of memory blocks\n");
|
||||
}
|
||||
|
||||
memHeap_t *mmInit(int ofs,
|
||||
int size)
|
||||
{
|
||||
PMemBlock blocks;
|
||||
|
||||
if (size <= 0) {
|
||||
return 0;
|
||||
}
|
||||
blocks = (TMemBlock *) calloc(1,sizeof(TMemBlock));
|
||||
if (blocks) {
|
||||
blocks->ofs = ofs;
|
||||
blocks->size = size;
|
||||
blocks->free = 1;
|
||||
return (memHeap_t *)blocks;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Kludgey workaround for existing i810 server. Remove soon.
|
||||
*/
|
||||
memHeap_t *mmAddRange( memHeap_t *heap,
|
||||
int ofs,
|
||||
int size )
|
||||
{
|
||||
PMemBlock blocks;
|
||||
blocks = (TMemBlock *) calloc(2,sizeof(TMemBlock));
|
||||
if (blocks) {
|
||||
blocks[0].size = size;
|
||||
blocks[0].free = 1;
|
||||
blocks[0].ofs = ofs;
|
||||
blocks[0].next = &blocks[1];
|
||||
|
||||
/* Discontinuity - stops JoinBlock from trying to join non-adjacent
|
||||
* ranges.
|
||||
*/
|
||||
blocks[1].size = 0;
|
||||
blocks[1].free = 0;
|
||||
blocks[1].ofs = ofs+size;
|
||||
blocks[1].next = (PMemBlock) heap;
|
||||
return (memHeap_t *)blocks;
|
||||
}
|
||||
else
|
||||
return heap;
|
||||
}
|
||||
|
||||
static TMemBlock* SliceBlock(TMemBlock *p,
|
||||
int startofs, int size,
|
||||
int reserved, int alignment)
|
||||
{
|
||||
TMemBlock *newblock;
|
||||
|
||||
/* break left */
|
||||
if (startofs > p->ofs) {
|
||||
newblock = (TMemBlock*) calloc(1,sizeof(TMemBlock));
|
||||
newblock->ofs = startofs;
|
||||
newblock->size = p->size - (startofs - p->ofs);
|
||||
newblock->free = 1;
|
||||
newblock->next = p->next;
|
||||
p->size -= newblock->size;
|
||||
p->next = newblock;
|
||||
p = newblock;
|
||||
}
|
||||
|
||||
/* break right */
|
||||
if (size < p->size) {
|
||||
newblock = (TMemBlock*) calloc(1,sizeof(TMemBlock));
|
||||
newblock->ofs = startofs + size;
|
||||
newblock->size = p->size - size;
|
||||
newblock->free = 1;
|
||||
newblock->next = p->next;
|
||||
p->size = size;
|
||||
p->next = newblock;
|
||||
}
|
||||
|
||||
/* p = middle block */
|
||||
p->align = alignment;
|
||||
p->free = 0;
|
||||
p->reserved = reserved;
|
||||
return p;
|
||||
}
|
||||
|
||||
PMemBlock mmAllocMem( memHeap_t *heap, int size, int align2, int startSearch)
|
||||
{
|
||||
int mask,startofs,endofs;
|
||||
TMemBlock *p;
|
||||
|
||||
if (!heap || align2 < 0 || size <= 0)
|
||||
return NULL;
|
||||
mask = (1 << align2)-1;
|
||||
startofs = 0;
|
||||
p = (TMemBlock *)heap;
|
||||
while (p) {
|
||||
if (ISFREE(p)) {
|
||||
startofs = (p->ofs + mask) & ~mask;
|
||||
if ( startofs < startSearch ) {
|
||||
startofs = startSearch;
|
||||
}
|
||||
endofs = startofs+size;
|
||||
if (endofs <= (p->ofs+p->size))
|
||||
break;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
if (!p)
|
||||
return NULL;
|
||||
p = SliceBlock(p,startofs,size,0,mask+1);
|
||||
p->heap = heap;
|
||||
return p;
|
||||
}
|
||||
|
||||
static __inline__ int Join2Blocks(TMemBlock *p)
|
||||
{
|
||||
if (p->free && p->next && p->next->free) {
|
||||
TMemBlock *q = p->next;
|
||||
p->size += q->size;
|
||||
p->next = q->next;
|
||||
SD_FREE(q);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mmFreeMem(PMemBlock b)
|
||||
{
|
||||
TMemBlock *p,*prev;
|
||||
|
||||
if (!b)
|
||||
return 0;
|
||||
if (!b->heap) {
|
||||
fprintf(stderr, "no heap\n");
|
||||
return -1;
|
||||
}
|
||||
p = b->heap;
|
||||
prev = NULL;
|
||||
while (p && p != b) {
|
||||
prev = p;
|
||||
p = p->next;
|
||||
}
|
||||
if (!p || p->free || p->reserved) {
|
||||
if (!p)
|
||||
fprintf(stderr, "block not found in heap\n");
|
||||
else if (p->free)
|
||||
fprintf(stderr, "block already free\n");
|
||||
else
|
||||
fprintf(stderr, "block is reserved\n");
|
||||
return -1;
|
||||
}
|
||||
p->free = 1;
|
||||
Join2Blocks(p);
|
||||
if (prev)
|
||||
Join2Blocks(prev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mmReserveMem(memHeap_t *heap, int offset,int size)
|
||||
{
|
||||
int endofs;
|
||||
TMemBlock *p;
|
||||
|
||||
if (!heap || size <= 0)
|
||||
return -1;
|
||||
endofs = offset+size;
|
||||
p = (TMemBlock *)heap;
|
||||
while (p && p->ofs <= offset) {
|
||||
if (ISFREE(p) && endofs <= (p->ofs+p->size)) {
|
||||
SliceBlock(p,offset,size,1,1);
|
||||
return 0;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mmFreeReserved(memHeap_t *heap, int offset)
|
||||
{
|
||||
TMemBlock *p,*prev;
|
||||
|
||||
if (!heap)
|
||||
return -1;
|
||||
p = (TMemBlock *)heap;
|
||||
prev = NULL;
|
||||
while (p && p->ofs != offset) {
|
||||
prev = p;
|
||||
p = p->next;
|
||||
}
|
||||
if (!p || !p->reserved)
|
||||
return -1;
|
||||
p->free = 1;
|
||||
p->reserved = 0;
|
||||
Join2Blocks(p);
|
||||
if (prev)
|
||||
Join2Blocks(prev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mmDestroy(memHeap_t *heap)
|
||||
{
|
||||
TMemBlock *p,*q;
|
||||
|
||||
if (!heap)
|
||||
return;
|
||||
p = (TMemBlock *)heap;
|
||||
while (p) {
|
||||
q = p->next;
|
||||
SD_FREE(p);
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
163
bsd/sis/sis_ds.h
Normal file
163
bsd/sis/sis_ds.h
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
/* sis_ds.h -- Private header for Direct Rendering Manager -*- linux-c -*-
|
||||
* Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw
|
||||
*
|
||||
* Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors:
|
||||
* Sung-Ching Lin <sclin@sis.com.tw>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _sis_ds_h_
|
||||
#define _sis_ds_h_
|
||||
|
||||
/* Set Data Structure */
|
||||
|
||||
#define SET_SIZE 5000
|
||||
#define SD_MALLOC(s) malloc( s, DRM(M_DRM), M_NOWAIT )
|
||||
#define SD_FREE(s) free( s, DRM(M_DRM) )
|
||||
|
||||
typedef unsigned int ITEM_TYPE;
|
||||
|
||||
typedef struct {
|
||||
ITEM_TYPE val;
|
||||
int alloc_next, free_next;
|
||||
} list_item_t;
|
||||
|
||||
typedef struct {
|
||||
int alloc;
|
||||
int free;
|
||||
int trace;
|
||||
list_item_t list[SET_SIZE];
|
||||
} set_t;
|
||||
|
||||
set_t *setInit(void);
|
||||
int setAdd(set_t *set, ITEM_TYPE item);
|
||||
int setDel(set_t *set, ITEM_TYPE item);
|
||||
int setFirst(set_t *set, ITEM_TYPE *item);
|
||||
int setNext(set_t *set, ITEM_TYPE *item);
|
||||
int setDestroy(set_t *set);
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* GLX Hardware Device Driver common code
|
||||
* Copyright (C) 1999 Keith Whitwell
|
||||
*
|
||||
* 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 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
|
||||
* KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MM_INC
|
||||
#define MM_INC
|
||||
|
||||
struct mem_block_t {
|
||||
struct mem_block_t *next;
|
||||
struct mem_block_t *heap;
|
||||
int ofs,size;
|
||||
int align;
|
||||
int free:1;
|
||||
int reserved:1;
|
||||
};
|
||||
typedef struct mem_block_t TMemBlock;
|
||||
typedef struct mem_block_t *PMemBlock;
|
||||
|
||||
/* a heap is just the first block in a chain */
|
||||
typedef struct mem_block_t memHeap_t;
|
||||
|
||||
static __inline__ int mmBlockSize(PMemBlock b)
|
||||
{ return b->size; }
|
||||
|
||||
static __inline__ int mmOffset(PMemBlock b)
|
||||
{ return b->ofs; }
|
||||
|
||||
static __inline__ void mmMarkReserved(PMemBlock b)
|
||||
{ b->reserved = 1; }
|
||||
|
||||
/*
|
||||
* input: total size in bytes
|
||||
* return: a heap pointer if OK, NULL if error
|
||||
*/
|
||||
memHeap_t *mmInit( int ofs, int size );
|
||||
|
||||
|
||||
|
||||
memHeap_t *mmAddRange( memHeap_t *heap,
|
||||
int ofs,
|
||||
int size );
|
||||
|
||||
|
||||
/*
|
||||
* Allocate 'size' bytes with 2^align2 bytes alignment,
|
||||
* restrict the search to free memory after 'startSearch'
|
||||
* depth and back buffers should be in different 4mb banks
|
||||
* to get better page hits if possible
|
||||
* input: size = size of block
|
||||
* align2 = 2^align2 bytes alignment
|
||||
* startSearch = linear offset from start of heap to begin search
|
||||
* return: pointer to the allocated block, 0 if error
|
||||
*/
|
||||
PMemBlock mmAllocMem( memHeap_t *heap, int size, int align2, int startSearch );
|
||||
|
||||
/*
|
||||
* Free block starts at offset
|
||||
* input: pointer to a block
|
||||
* return: 0 if OK, -1 if error
|
||||
*/
|
||||
int mmFreeMem( PMemBlock b );
|
||||
|
||||
/*
|
||||
* Reserve 'size' bytes block start at offset
|
||||
* This is used to prevent allocation of memory already used
|
||||
* by the X server for the front buffer, pixmaps, and cursor
|
||||
* input: size, offset
|
||||
* output: 0 if OK, -1 if error
|
||||
*/
|
||||
int mmReserveMem( memHeap_t *heap, int offset,int size );
|
||||
int mmFreeReserved( memHeap_t *heap, int offset );
|
||||
|
||||
/*
|
||||
* destroy MM
|
||||
*/
|
||||
void mmDestroy( memHeap_t *mmInit );
|
||||
|
||||
/* For debuging purpose. */
|
||||
void mmDumpMemInfo( memHeap_t *mmInit );
|
||||
|
||||
#endif
|
||||
300
bsd/sis/sis_mm.c
Normal file
300
bsd/sis/sis_mm.c
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
/* sis_mm.c -- Private header for Direct Rendering Manager -*- linux-c -*-
|
||||
* Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw
|
||||
*
|
||||
* Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors:
|
||||
* Sung-Ching Lin <sclin@sis.com.tw>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __linux
|
||||
#define __NO_VERSION__
|
||||
#include <linux/sisfb.h>
|
||||
#endif
|
||||
|
||||
#include "sis.h"
|
||||
#include "drmP.h"
|
||||
#include "sis_drm.h"
|
||||
#include "sis_drv.h"
|
||||
#include "sis_ds.h"
|
||||
|
||||
#define MAX_CONTEXT 100
|
||||
#define VIDEO_TYPE 0
|
||||
#define AGP_TYPE 1
|
||||
|
||||
typedef struct {
|
||||
int used;
|
||||
int context;
|
||||
set_t *sets[2]; /* 0 for video, 1 for AGP */
|
||||
} sis_context_t;
|
||||
|
||||
static sis_context_t global_ppriv[MAX_CONTEXT];
|
||||
|
||||
static int add_alloc_set(int context, int type, unsigned int val)
|
||||
{
|
||||
int i, retval = 0;
|
||||
|
||||
for(i = 0; i < MAX_CONTEXT; i++)
|
||||
if(global_ppriv[i].used && global_ppriv[i].context == context){
|
||||
retval = setAdd(global_ppriv[i].sets[type], val);
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int del_alloc_set(int context, int type, unsigned int val)
|
||||
{
|
||||
int i, retval = 0;
|
||||
for(i = 0; i < MAX_CONTEXT; i++)
|
||||
if(global_ppriv[i].used && global_ppriv[i].context == context){
|
||||
retval = setDel(global_ppriv[i].sets[type], val);
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* fb management via fb device */
|
||||
#if 1
|
||||
int sis_fb_alloc( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_sis_mem_t fb;
|
||||
struct sis_memreq req;
|
||||
int retval = 0;
|
||||
|
||||
DRM_OS_KRNFROMUSR( fb, (drm_sis_mem_t *) data, sizeof(fb) );
|
||||
|
||||
req.size = fb.size;
|
||||
sis_malloc(&req);
|
||||
if(req.offset){
|
||||
/* TODO */
|
||||
fb.offset = req.offset;
|
||||
fb.free = req.offset;
|
||||
if(!add_alloc_set(fb.context, VIDEO_TYPE, fb.free)){
|
||||
DRM_DEBUG("adding to allocation set fails");
|
||||
sis_free(req.offset);
|
||||
retval = -1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
fb.offset = 0;
|
||||
fb.size = 0;
|
||||
fb.free = 0;
|
||||
}
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_sis_mem_t *) data, fb, sizeof(fb) );
|
||||
|
||||
DRM_DEBUG("alloc fb, size = %d, offset = %ld\n", fb.size, req.offset);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int sis_fb_free( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_sis_mem_t fb;
|
||||
int retval = 0;
|
||||
|
||||
DRM_OS_KRNFROMUSR( fb, (drm_sis_mem_t *) data, sizeof(fb) );
|
||||
|
||||
if(!fb.free){
|
||||
return -1;
|
||||
}
|
||||
|
||||
sis_free(fb.free);
|
||||
if(!del_alloc_set(fb.context, VIDEO_TYPE, fb.free))
|
||||
retval = -1;
|
||||
|
||||
DRM_DEBUG("free fb, offset = %d\n", fb.free);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int sis_fb_alloc( DRM_OS_IOCTL )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sis_fb_free( DRM_OS_IOCTL )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* agp memory management */
|
||||
#if 1
|
||||
|
||||
static memHeap_t *AgpHeap = NULL;
|
||||
|
||||
int sisp_agp_init( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_sis_agp_t agp;
|
||||
|
||||
DRM_OS_KRNFROMUSR( agp, (drm_sis_agp_t *) data, sizeof(agp) );
|
||||
|
||||
AgpHeap = mmInit(agp.offset, agp.size);
|
||||
|
||||
DRM_DEBUG("offset = %u, size = %u", agp.offset, agp.size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sisp_agp_alloc( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_sis_mem_t agp;
|
||||
PMemBlock block;
|
||||
int retval = 0;
|
||||
|
||||
if(!AgpHeap)
|
||||
return -1;
|
||||
|
||||
DRM_OS_KRNFROMUSR( agp, (drm_sis_mem_t *) data, sizeof(agp));
|
||||
|
||||
block = mmAllocMem(AgpHeap, agp.size, 0, 0);
|
||||
if(block){
|
||||
/* TODO */
|
||||
agp.offset = block->ofs;
|
||||
agp.free = (unsigned int)block;
|
||||
if(!add_alloc_set(agp.context, AGP_TYPE, agp.free)){
|
||||
DRM_DEBUG("adding to allocation set fails");
|
||||
mmFreeMem((PMemBlock)agp.free);
|
||||
retval = -1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
agp.offset = 0;
|
||||
agp.size = 0;
|
||||
agp.free = 0;
|
||||
}
|
||||
|
||||
DRM_OS_KRNTOUSR( (drm_sis_mem_t *) data, agp, sizeof(agp) );
|
||||
|
||||
DRM_DEBUG("alloc agp, size = %d, offset = %d\n", agp.size, agp.offset);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int sisp_agp_free( DRM_OS_IOCTL )
|
||||
{
|
||||
drm_sis_mem_t agp;
|
||||
int retval = 0;
|
||||
|
||||
if(!AgpHeap)
|
||||
return -1;
|
||||
|
||||
DRM_OS_KRNFROMUSR( agp, (drm_sis_mem_t *) data, sizeof(agp));
|
||||
|
||||
if(!agp.free){
|
||||
return -1;
|
||||
}
|
||||
|
||||
mmFreeMem((PMemBlock)agp.free);
|
||||
if(!del_alloc_set(agp.context, AGP_TYPE, agp.free))
|
||||
retval = -1;
|
||||
|
||||
DRM_DEBUG("free agp, free = %d\n", agp.free);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int sis_init_context(int context)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < MAX_CONTEXT ; i++)
|
||||
if(global_ppriv[i].used && (global_ppriv[i].context == context))
|
||||
break;
|
||||
|
||||
if(i >= MAX_CONTEXT){
|
||||
for(i = 0; i < MAX_CONTEXT ; i++){
|
||||
if(!global_ppriv[i].used){
|
||||
global_ppriv[i].context = context;
|
||||
global_ppriv[i].used = 1;
|
||||
global_ppriv[i].sets[0] = setInit();
|
||||
global_ppriv[i].sets[1] = setInit();
|
||||
DRM_DEBUG("init allocation set, socket=%d, context = %d\n",
|
||||
i, context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if((i >= MAX_CONTEXT) || (global_ppriv[i].sets[0] == NULL) ||
|
||||
(global_ppriv[i].sets[1] == NULL)){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sis_final_context(int context)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=0; i<MAX_CONTEXT; i++)
|
||||
if(global_ppriv[i].used && (global_ppriv[i].context == context))
|
||||
break;
|
||||
|
||||
if(i < MAX_CONTEXT){
|
||||
set_t *set;
|
||||
unsigned int item;
|
||||
int retval;
|
||||
|
||||
DRM_DEBUG("find socket %d, context = %d\n", i, context);
|
||||
|
||||
/* Video Memory */
|
||||
set = global_ppriv[i].sets[0];
|
||||
retval = setFirst(set, &item);
|
||||
while(retval){
|
||||
DRM_DEBUG("free video memory 0x%x\n", item);
|
||||
#if 0
|
||||
sis_free(item);
|
||||
#endif
|
||||
retval = setNext(set, &item);
|
||||
}
|
||||
setDestroy(set);
|
||||
|
||||
/* AGP Memory */
|
||||
set = global_ppriv[i].sets[1];
|
||||
retval = setFirst(set, &item);
|
||||
while(retval){
|
||||
DRM_DEBUG("free agp memory 0x%x\n", item);
|
||||
mmFreeMem((PMemBlock)item);
|
||||
retval = setNext(set, &item);
|
||||
}
|
||||
setDestroy(set);
|
||||
|
||||
global_ppriv[i].used = 0;
|
||||
}
|
||||
|
||||
/* turn-off auto-flip */
|
||||
/* TODO */
|
||||
#if defined(SIS_STEREO)
|
||||
flip_final();
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
30
bsd/sis_drm.h
Normal file
30
bsd/sis_drm.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
#ifndef _sis_drm_public_h_
|
||||
#define _sis_drm_public_h_
|
||||
|
||||
typedef struct {
|
||||
int context;
|
||||
unsigned int offset;
|
||||
unsigned int size;
|
||||
unsigned int free;
|
||||
} drm_sis_mem_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int offset, size;
|
||||
} drm_sis_agp_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int left, right;
|
||||
} drm_sis_flip_t;
|
||||
|
||||
#if defined(__KERNEL__) || defined(_KERNEL)
|
||||
|
||||
int sis_fb_alloc(DRM_OS_IOCTL);
|
||||
int sis_fb_free(DRM_OS_IOCTL);
|
||||
int sisp_agp_init(DRM_OS_IOCTL);
|
||||
int sisp_agp_alloc(DRM_OS_IOCTL);
|
||||
int sisp_agp_free(DRM_OS_IOCTL);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
42
bsd/tdfx/tdfx.h
Normal file
42
bsd/tdfx/tdfx.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* tdfx.h -- 3dfx DRM template customization -*- linux-c -*-
|
||||
* Created: Wed Feb 14 12:32:32 2001 by gareth@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef __TDFX_H__
|
||||
#define __TDFX_H__
|
||||
|
||||
/* This remains constant for all DRM template files.
|
||||
*/
|
||||
#define DRM(x) tdfx_##x
|
||||
|
||||
/* General customization:
|
||||
*/
|
||||
#define __HAVE_MTRR 1
|
||||
#define __HAVE_CTX_BITMAP 1
|
||||
|
||||
#endif
|
||||
1418
linux-core/i830_dma.c
Normal file
1418
linux-core/i830_dma.c
Normal file
File diff suppressed because it is too large
Load diff
238
linux-core/i830_drm.h
Normal file
238
linux-core/i830_drm.h
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
#ifndef _I830_DRM_H_
|
||||
#define _I830_DRM_H_
|
||||
|
||||
/* WARNING: These defines must be the same as what the Xserver uses.
|
||||
* if you change them, you must change the defines in the Xserver.
|
||||
*/
|
||||
|
||||
#ifndef _I830_DEFINES_
|
||||
#define _I830_DEFINES_
|
||||
|
||||
#define I830_DMA_BUF_ORDER 12
|
||||
#define I830_DMA_BUF_SZ (1<<I830_DMA_BUF_ORDER)
|
||||
#define I830_DMA_BUF_NR 256
|
||||
#define I830_NR_SAREA_CLIPRECTS 8
|
||||
|
||||
/* Each region is a minimum of 64k, and there are at most 64 of them.
|
||||
*/
|
||||
#define I830_NR_TEX_REGIONS 64
|
||||
#define I830_LOG_MIN_TEX_REGION_SIZE 16
|
||||
|
||||
/* if defining I830_ENABLE_4_TEXTURES, do it in i830_3d_reg.h, too */
|
||||
#if !defined(I830_ENABLE_4_TEXTURES)
|
||||
#define I830_TEXTURE_COUNT 2
|
||||
#define I830_TEXBLEND_COUNT 2 /* always same as TEXTURE_COUNT? */
|
||||
#else /* defined(I830_ENABLE_4_TEXTURES) */
|
||||
#define I830_TEXTURE_COUNT 4
|
||||
#define I830_TEXBLEND_COUNT 4 /* always same as TEXTURE_COUNT? */
|
||||
#endif /* I830_ENABLE_4_TEXTURES */
|
||||
|
||||
#define I830_TEXBLEND_SIZE 12 /* (4 args + op) * 2 + COLOR_FACTOR */
|
||||
|
||||
#define I830_UPLOAD_CTX 0x1
|
||||
#define I830_UPLOAD_BUFFERS 0x2
|
||||
#define I830_UPLOAD_CLIPRECTS 0x4
|
||||
#define I830_UPLOAD_TEX0_IMAGE 0x100 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX0_CUBE 0x200 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX1_IMAGE 0x400 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX1_CUBE 0x800 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX2_IMAGE 0x1000 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX2_CUBE 0x2000 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX3_IMAGE 0x4000 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX3_CUBE 0x8000 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX_N_IMAGE(n) (0x100 << (n * 2))
|
||||
#define I830_UPLOAD_TEX_N_CUBE(n) (0x200 << (n * 2))
|
||||
#define I830_UPLOAD_TEXIMAGE_MASK 0xff00
|
||||
#define I830_UPLOAD_TEX0 0x10000
|
||||
#define I830_UPLOAD_TEX1 0x20000
|
||||
#define I830_UPLOAD_TEX2 0x40000
|
||||
#define I830_UPLOAD_TEX3 0x80000
|
||||
#define I830_UPLOAD_TEX_N(n) (0x10000 << (n))
|
||||
#define I830_UPLOAD_TEX_MASK 0xf0000
|
||||
#define I830_UPLOAD_TEXBLEND0 0x100000
|
||||
#define I830_UPLOAD_TEXBLEND1 0x200000
|
||||
#define I830_UPLOAD_TEXBLEND2 0x400000
|
||||
#define I830_UPLOAD_TEXBLEND3 0x800000
|
||||
#define I830_UPLOAD_TEXBLEND_N(n) (0x100000 << (n))
|
||||
#define I830_UPLOAD_TEXBLEND_MASK 0xf00000
|
||||
#define I830_UPLOAD_TEX_PALETTE_N(n) (0x1000000 << (n))
|
||||
#define I830_UPLOAD_TEX_PALETTE_SHARED 0x4000000
|
||||
|
||||
/* Indices into buf.Setup where various bits of state are mirrored per
|
||||
* context and per buffer. These can be fired at the card as a unit,
|
||||
* or in a piecewise fashion as required.
|
||||
*/
|
||||
|
||||
/* Destbuffer state
|
||||
* - backbuffer linear offset and pitch -- invarient in the current dri
|
||||
* - zbuffer linear offset and pitch -- also invarient
|
||||
* - drawing origin in back and depth buffers.
|
||||
*
|
||||
* Keep the depth/back buffer state here to acommodate private buffers
|
||||
* in the future.
|
||||
*/
|
||||
|
||||
#define I830_DESTREG_CBUFADDR 0
|
||||
/* Invarient */
|
||||
#define I830_DESTREG_DBUFADDR 1
|
||||
#define I830_DESTREG_DV0 2
|
||||
#define I830_DESTREG_DV1 3
|
||||
#define I830_DESTREG_SENABLE 4
|
||||
#define I830_DESTREG_SR0 5
|
||||
#define I830_DESTREG_SR1 6
|
||||
#define I830_DESTREG_SR2 7
|
||||
#define I830_DESTREG_DR0 8
|
||||
#define I830_DESTREG_DR1 9
|
||||
#define I830_DESTREG_DR2 10
|
||||
#define I830_DESTREG_DR3 11
|
||||
#define I830_DESTREG_DR4 12
|
||||
#define I830_DEST_SETUP_SIZE 13
|
||||
|
||||
/* Context state
|
||||
*/
|
||||
#define I830_CTXREG_STATE1 0
|
||||
#define I830_CTXREG_STATE2 1
|
||||
#define I830_CTXREG_STATE3 2
|
||||
#define I830_CTXREG_STATE4 3
|
||||
#define I830_CTXREG_STATE5 4
|
||||
#define I830_CTXREG_IALPHAB 5
|
||||
#define I830_CTXREG_STENCILTST 6
|
||||
#define I830_CTXREG_ENABLES_1 7
|
||||
#define I830_CTXREG_ENABLES_2 8
|
||||
#define I830_CTXREG_AA 9
|
||||
#define I830_CTXREG_FOGCOLOR 10
|
||||
#define I830_CTXREG_BLENDCOLR0 11
|
||||
#define I830_CTXREG_BLENDCOLR 12 /* Dword 1 of 2 dword command */
|
||||
#define I830_CTXREG_VF 13
|
||||
#define I830_CTXREG_VF2 14
|
||||
#define I830_CTXREG_MCSB0 15
|
||||
#define I830_CTXREG_MCSB1 16
|
||||
#define I830_CTX_SETUP_SIZE 17
|
||||
|
||||
/* Texture state (per tex unit)
|
||||
*/
|
||||
|
||||
#define I830_TEXREG_MI0 0 /* GFX_OP_MAP_INFO (6 dwords) */
|
||||
#define I830_TEXREG_MI1 1
|
||||
#define I830_TEXREG_MI2 2
|
||||
#define I830_TEXREG_MI3 3
|
||||
#define I830_TEXREG_MI4 4
|
||||
#define I830_TEXREG_MI5 5
|
||||
#define I830_TEXREG_MF 6 /* GFX_OP_MAP_FILTER */
|
||||
#define I830_TEXREG_MLC 7 /* GFX_OP_MAP_LOD_CTL */
|
||||
#define I830_TEXREG_MLL 8 /* GFX_OP_MAP_LOD_LIMITS */
|
||||
#define I830_TEXREG_MCS 9 /* GFX_OP_MAP_COORD_SETS */
|
||||
#define I830_TEX_SETUP_SIZE 10
|
||||
|
||||
#define I830_FRONT 0x1
|
||||
#define I830_BACK 0x2
|
||||
#define I830_DEPTH 0x4
|
||||
|
||||
#endif /* _I830_DEFINES_ */
|
||||
|
||||
typedef struct _drm_i830_init {
|
||||
enum {
|
||||
I830_INIT_DMA = 0x01,
|
||||
I830_CLEANUP_DMA = 0x02
|
||||
} func;
|
||||
unsigned int mmio_offset;
|
||||
unsigned int buffers_offset;
|
||||
int sarea_priv_offset;
|
||||
unsigned int ring_start;
|
||||
unsigned int ring_end;
|
||||
unsigned int ring_size;
|
||||
unsigned int front_offset;
|
||||
unsigned int back_offset;
|
||||
unsigned int depth_offset;
|
||||
unsigned int w;
|
||||
unsigned int h;
|
||||
unsigned int pitch;
|
||||
unsigned int pitch_bits;
|
||||
unsigned int back_pitch;
|
||||
unsigned int depth_pitch;
|
||||
unsigned int cpp;
|
||||
} drm_i830_init_t;
|
||||
|
||||
/* Warning: If you change the SAREA structure you must change the Xserver
|
||||
* structure as well */
|
||||
|
||||
typedef struct _drm_i830_tex_region {
|
||||
unsigned char next, prev; /* indices to form a circular LRU */
|
||||
unsigned char in_use; /* owned by a client, or free? */
|
||||
int age; /* tracked by clients to update local LRU's */
|
||||
} drm_i830_tex_region_t;
|
||||
|
||||
typedef struct _drm_i830_sarea {
|
||||
unsigned int ContextState[I830_CTX_SETUP_SIZE];
|
||||
unsigned int BufferState[I830_DEST_SETUP_SIZE];
|
||||
unsigned int TexState[I830_TEXTURE_COUNT][I830_TEX_SETUP_SIZE];
|
||||
unsigned int TexBlendState[I830_TEXBLEND_COUNT][I830_TEXBLEND_SIZE];
|
||||
unsigned int TexBlendStateWordsUsed[I830_TEXBLEND_COUNT];
|
||||
unsigned int Palette[2][256];
|
||||
unsigned int dirty;
|
||||
|
||||
unsigned int nbox;
|
||||
drm_clip_rect_t boxes[I830_NR_SAREA_CLIPRECTS];
|
||||
|
||||
/* Maintain an LRU of contiguous regions of texture space. If
|
||||
* you think you own a region of texture memory, and it has an
|
||||
* age different to the one you set, then you are mistaken and
|
||||
* it has been stolen by another client. If global texAge
|
||||
* hasn't changed, there is no need to walk the list.
|
||||
*
|
||||
* These regions can be used as a proxy for the fine-grained
|
||||
* texture information of other clients - by maintaining them
|
||||
* in the same lru which is used to age their own textures,
|
||||
* clients have an approximate lru for the whole of global
|
||||
* texture space, and can make informed decisions as to which
|
||||
* areas to kick out. There is no need to choose whether to
|
||||
* kick out your own texture or someone else's - simply eject
|
||||
* them all in LRU order.
|
||||
*/
|
||||
|
||||
drm_i830_tex_region_t texList[I830_NR_TEX_REGIONS+1];
|
||||
/* Last elt is sentinal */
|
||||
int texAge; /* last time texture was uploaded */
|
||||
int last_enqueue; /* last time a buffer was enqueued */
|
||||
int last_dispatch; /* age of the most recently dispatched buffer */
|
||||
int last_quiescent; /* */
|
||||
int ctxOwner; /* last context to upload state */
|
||||
|
||||
int vertex_prim;
|
||||
} drm_i830_sarea_t;
|
||||
|
||||
typedef struct _drm_i830_clear {
|
||||
int clear_color;
|
||||
int clear_depth;
|
||||
int flags;
|
||||
unsigned int clear_colormask;
|
||||
unsigned int clear_depthmask;
|
||||
} drm_i830_clear_t;
|
||||
|
||||
|
||||
|
||||
/* These may be placeholders if we have more cliprects than
|
||||
* I830_NR_SAREA_CLIPRECTS. In that case, the client sets discard to
|
||||
* false, indicating that the buffer will be dispatched again with a
|
||||
* new set of cliprects.
|
||||
*/
|
||||
typedef struct _drm_i830_vertex {
|
||||
int idx; /* buffer index */
|
||||
int used; /* nr bytes in use */
|
||||
int discard; /* client is finished with the buffer? */
|
||||
} drm_i830_vertex_t;
|
||||
|
||||
typedef struct _drm_i830_copy_t {
|
||||
int idx; /* buffer index */
|
||||
int used; /* nr bytes in use */
|
||||
void *address; /* Address to copy from */
|
||||
} drm_i830_copy_t;
|
||||
|
||||
typedef struct drm_i830_dma {
|
||||
void *virtual;
|
||||
int request_idx;
|
||||
int request_size;
|
||||
int granted;
|
||||
} drm_i830_dma_t;
|
||||
|
||||
#endif /* _I830_DRM_H_ */
|
||||
102
linux-core/i830_drv.c
Normal file
102
linux-core/i830_drv.c
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/* i830_drv.c -- I810 driver -*- linux-c -*-
|
||||
* Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Jeff Hartmann <jhartmann@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
* Abraham vd Merwe <abraham@2d3d.co.za>
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include "i830.h"
|
||||
#include "drmP.h"
|
||||
#include "i830_drv.h"
|
||||
|
||||
#define DRIVER_AUTHOR "VA Linux Systems Inc."
|
||||
|
||||
#define DRIVER_NAME "i830"
|
||||
#define DRIVER_DESC "Intel 830M"
|
||||
#define DRIVER_DATE "20011004"
|
||||
|
||||
#define DRIVER_MAJOR 1
|
||||
#define DRIVER_MINOR 2
|
||||
#define DRIVER_PATCHLEVEL 0
|
||||
|
||||
#define DRIVER_IOCTLS \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_INIT)] = { i830_dma_init, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_VERTEX)] = { i830_dma_vertex, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_CLEAR)] = { i830_clear_bufs, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_FLUSH)] = { i830_flush_ioctl, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_GETAGE)] = { i830_getage, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_GETBUF)] = { i830_getbuf, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_SWAP)] = { i830_swap_bufs, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_COPY)] = { i830_copybuf, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_DOCOPY)] = { i830_docopy, 1, 0 },
|
||||
|
||||
#define __HAVE_COUNTERS 4
|
||||
#define __HAVE_COUNTER6 _DRM_STAT_IRQ
|
||||
#define __HAVE_COUNTER7 _DRM_STAT_PRIMARY
|
||||
#define __HAVE_COUNTER8 _DRM_STAT_SECONDARY
|
||||
#define __HAVE_COUNTER9 _DRM_STAT_DMA
|
||||
|
||||
|
||||
#include "drm_agpsupport.h"
|
||||
#include "drm_auth.h"
|
||||
#include "drm_bufs.h"
|
||||
#include "drm_context.h"
|
||||
#include "drm_dma.h"
|
||||
#include "drm_drawable.h"
|
||||
#include "drm_drv.h"
|
||||
|
||||
#ifndef MODULE
|
||||
/* DRM(options) is called by the kernel to parse command-line options
|
||||
* passed via the boot-loader (e.g., LILO). It calls the insmod option
|
||||
* routine, drm_parse_drm.
|
||||
*/
|
||||
|
||||
/* JH- We have to hand expand the string ourselves because of the cpp. If
|
||||
* anyone can think of a way that we can fit into the __setup macro without
|
||||
* changing it, then please send the solution my way.
|
||||
*/
|
||||
static int __init i830_options( char *str )
|
||||
{
|
||||
DRM(parse_options)( str );
|
||||
return 1;
|
||||
}
|
||||
|
||||
__setup( DRIVER_NAME "=", i830_options );
|
||||
#endif
|
||||
|
||||
#include "drm_fops.h"
|
||||
#include "drm_init.h"
|
||||
#include "drm_ioctl.h"
|
||||
#include "drm_lock.h"
|
||||
#include "drm_lists.h"
|
||||
#include "drm_memory.h"
|
||||
#include "drm_proc.h"
|
||||
#include "drm_vm.h"
|
||||
#include "drm_stub.h"
|
||||
213
linux-core/i830_drv.h
Normal file
213
linux-core/i830_drv.h
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
/* i830_drv.h -- Private header for the I830 driver -*- linux-c -*-
|
||||
* Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
|
||||
*
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors: Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Jeff Hartmann <jhartmann@valinux.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _I830_DRV_H_
|
||||
#define _I830_DRV_H_
|
||||
|
||||
typedef struct drm_i830_buf_priv {
|
||||
u32 *in_use;
|
||||
int my_use_idx;
|
||||
int currently_mapped;
|
||||
void *virtual;
|
||||
void *kernel_virtual;
|
||||
int map_count;
|
||||
struct vm_area_struct *vma;
|
||||
} drm_i830_buf_priv_t;
|
||||
|
||||
typedef struct _drm_i830_ring_buffer{
|
||||
int tail_mask;
|
||||
unsigned long Start;
|
||||
unsigned long End;
|
||||
unsigned long Size;
|
||||
u8 *virtual_start;
|
||||
int head;
|
||||
int tail;
|
||||
int space;
|
||||
} drm_i830_ring_buffer_t;
|
||||
|
||||
typedef struct drm_i830_private {
|
||||
drm_map_t *sarea_map;
|
||||
drm_map_t *buffer_map;
|
||||
drm_map_t *mmio_map;
|
||||
|
||||
drm_i830_sarea_t *sarea_priv;
|
||||
drm_i830_ring_buffer_t ring;
|
||||
|
||||
unsigned long hw_status_page;
|
||||
unsigned long counter;
|
||||
|
||||
atomic_t flush_done;
|
||||
wait_queue_head_t flush_queue; /* Processes waiting until flush */
|
||||
drm_buf_t *mmap_buffer;
|
||||
|
||||
u32 front_di1, back_di1, zi1;
|
||||
|
||||
int back_offset;
|
||||
int depth_offset;
|
||||
int w, h;
|
||||
int pitch;
|
||||
int back_pitch;
|
||||
int depth_pitch;
|
||||
unsigned int cpp;
|
||||
} drm_i830_private_t;
|
||||
|
||||
/* i830_dma.c */
|
||||
extern int i830_dma_schedule(drm_device_t *dev, int locked);
|
||||
extern int i830_getbuf(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int i830_dma_init(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int i830_flush_ioctl(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern void i830_reclaim_buffers(drm_device_t *dev, pid_t pid);
|
||||
extern int i830_getage(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg);
|
||||
extern int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma);
|
||||
extern int i830_copybuf(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int i830_docopy(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
extern void i830_dma_quiescent(drm_device_t *dev);
|
||||
|
||||
extern int i830_dma_vertex(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
extern int i830_swap_bufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
extern int i830_clear_bufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
#define I830_VERBOSE 0
|
||||
|
||||
#define I830_BASE(reg) ((unsigned long) \
|
||||
dev_priv->mmio_map->handle)
|
||||
#define I830_ADDR(reg) (I830_BASE(reg) + reg)
|
||||
#define I830_DEREF(reg) *(__volatile__ int *)I830_ADDR(reg)
|
||||
#define I830_READ(reg) I830_DEREF(reg)
|
||||
#define I830_WRITE(reg,val) do { I830_DEREF(reg) = val; } while (0)
|
||||
#define I830_DEREF16(reg) *(__volatile__ u16 *)I830_ADDR(reg)
|
||||
#define I830_READ16(reg) I830_DEREF16(reg)
|
||||
#define I830_WRITE16(reg,val) do { I830_DEREF16(reg) = val; } while (0)
|
||||
|
||||
#define GFX_OP_USER_INTERRUPT ((0<<29)|(2<<23))
|
||||
#define GFX_OP_BREAKPOINT_INTERRUPT ((0<<29)|(1<<23))
|
||||
#define CMD_REPORT_HEAD (7<<23)
|
||||
#define CMD_STORE_DWORD_IDX ((0x21<<23) | 0x1)
|
||||
#define CMD_OP_BATCH_BUFFER ((0x0<<29)|(0x30<<23)|0x1)
|
||||
|
||||
#define INST_PARSER_CLIENT 0x00000000
|
||||
#define INST_OP_FLUSH 0x02000000
|
||||
#define INST_FLUSH_MAP_CACHE 0x00000001
|
||||
|
||||
|
||||
#define BB1_START_ADDR_MASK (~0x7)
|
||||
#define BB1_PROTECTED (1<<0)
|
||||
#define BB1_UNPROTECTED (0<<0)
|
||||
#define BB2_END_ADDR_MASK (~0x7)
|
||||
|
||||
#define I830REG_HWSTAM 0x02098
|
||||
#define I830REG_INT_IDENTITY_R 0x020a4
|
||||
#define I830REG_INT_MASK_R 0x020a8
|
||||
#define I830REG_INT_ENABLE_R 0x020a0
|
||||
|
||||
#define LP_RING 0x2030
|
||||
#define HP_RING 0x2040
|
||||
#define RING_TAIL 0x00
|
||||
#define TAIL_ADDR 0x000FFFF8
|
||||
#define RING_HEAD 0x04
|
||||
#define HEAD_WRAP_COUNT 0xFFE00000
|
||||
#define HEAD_WRAP_ONE 0x00200000
|
||||
#define HEAD_ADDR 0x001FFFFC
|
||||
#define RING_START 0x08
|
||||
#define START_ADDR 0x00FFFFF8
|
||||
#define RING_LEN 0x0C
|
||||
#define RING_NR_PAGES 0x000FF000
|
||||
#define RING_REPORT_MASK 0x00000006
|
||||
#define RING_REPORT_64K 0x00000002
|
||||
#define RING_REPORT_128K 0x00000004
|
||||
#define RING_NO_REPORT 0x00000000
|
||||
#define RING_VALID_MASK 0x00000001
|
||||
#define RING_VALID 0x00000001
|
||||
#define RING_INVALID 0x00000000
|
||||
|
||||
#define GFX_OP_SCISSOR ((0x3<<29)|(0x1c<<24)|(0x10<<19))
|
||||
#define SC_UPDATE_SCISSOR (0x1<<1)
|
||||
#define SC_ENABLE_MASK (0x1<<0)
|
||||
#define SC_ENABLE (0x1<<0)
|
||||
|
||||
#define GFX_OP_SCISSOR_INFO ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
|
||||
#define SCI_YMIN_MASK (0xffff<<16)
|
||||
#define SCI_XMIN_MASK (0xffff<<0)
|
||||
#define SCI_YMAX_MASK (0xffff<<16)
|
||||
#define SCI_XMAX_MASK (0xffff<<0)
|
||||
|
||||
#define GFX_OP_SCISSOR_ENABLE ((0x3<<29)|(0x1c<<24)|(0x10<<19))
|
||||
#define GFX_OP_SCISSOR_RECT ((0x3<<29)|(0x1d<<24)|(0x81<<16)|1)
|
||||
#define GFX_OP_COLOR_FACTOR ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
|
||||
#define GFX_OP_STIPPLE ((0x3<<29)|(0x1d<<24)|(0x83<<16))
|
||||
#define GFX_OP_MAP_INFO ((0x3<<29)|(0x1d<<24)|0x4)
|
||||
#define GFX_OP_DESTBUFFER_VARS ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
|
||||
#define GFX_OP_DRAWRECT_INFO ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
|
||||
#define GFX_OP_PRIMITIVE ((0x3<<29)|(0x1f<<24))
|
||||
|
||||
#define CMD_OP_DESTBUFFER_INFO ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1)
|
||||
|
||||
|
||||
#define BR00_BITBLT_CLIENT 0x40000000
|
||||
#define BR00_OP_COLOR_BLT 0x10000000
|
||||
#define BR00_OP_SRC_COPY_BLT 0x10C00000
|
||||
#define BR13_SOLID_PATTERN 0x80000000
|
||||
|
||||
#define BUF_3D_ID_COLOR_BACK (0x3<<24)
|
||||
#define BUF_3D_ID_DEPTH (0x7<<24)
|
||||
#define BUF_3D_USE_FENCE (1<<23)
|
||||
#define BUF_3D_PITCH(x) (((x)/4)<<2)
|
||||
|
||||
#define CMD_OP_MAP_PALETTE_LOAD ((3<<29)|(0x1d<<24)|(0x82<<16)|255)
|
||||
#define MAP_PALETTE_NUM(x) ((x<<8) & (1<<8))
|
||||
#define MAP_PALETTE_BOTH (1<<11)
|
||||
|
||||
#define XY_COLOR_BLT_CMD ((2<<29)|(0x50<<22)|0x4)
|
||||
#define XY_COLOR_BLT_WRITE_ALPHA (1<<21)
|
||||
#define XY_COLOR_BLT_WRITE_RGB (1<<20)
|
||||
|
||||
#define XY_SRC_COPY_BLT_CMD ((2<<29)|(0x53<<22)|6)
|
||||
#define XY_SRC_COPY_BLT_WRITE_ALPHA (1<<21)
|
||||
#define XY_SRC_COPY_BLT_WRITE_RGB (1<<20)
|
||||
|
||||
#define MI_BATCH_BUFFER ((0x30<<23)|1)
|
||||
#define MI_BATCH_NON_SECURE (1)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
116
linux/i830.h
Normal file
116
linux/i830.h
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/* i830.h -- Intel I830 DRM template customization -*- linux-c -*-
|
||||
* Created: Thu Feb 15 00:01:12 2001 by gareth@valinux.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef __I830_H__
|
||||
#define __I830_H__
|
||||
|
||||
/* This remains constant for all DRM template files.
|
||||
*/
|
||||
#define DRM(x) i830_##x
|
||||
|
||||
/* General customization:
|
||||
*/
|
||||
#define __HAVE_AGP 1
|
||||
#define __MUST_HAVE_AGP 1
|
||||
#define __HAVE_MTRR 1
|
||||
#define __HAVE_CTX_BITMAP 1
|
||||
|
||||
/* Driver customization:
|
||||
*/
|
||||
#define __HAVE_RELEASE 1
|
||||
#define DRIVER_RELEASE() do { \
|
||||
i830_reclaim_buffers( dev, priv->pid ); \
|
||||
} while (0)
|
||||
|
||||
/* DMA customization:
|
||||
*/
|
||||
#define __HAVE_DMA 1
|
||||
#define __HAVE_DMA_QUEUE 1
|
||||
#define __HAVE_DMA_WAITLIST 1
|
||||
#define __HAVE_DMA_RECLAIM 1
|
||||
|
||||
#define __HAVE_DMA_QUIESCENT 1
|
||||
#define DRIVER_DMA_QUIESCENT() do { \
|
||||
i830_dma_quiescent( dev ); \
|
||||
} while (0)
|
||||
|
||||
#define __HAVE_DMA_IRQ 1
|
||||
#define __HAVE_DMA_IRQ_BH 1
|
||||
#define __HAVE_SHARED_IRQ 1
|
||||
#define DRIVER_PREINSTALL() do { \
|
||||
drm_i830_private_t *dev_priv = \
|
||||
(drm_i830_private_t *)dev->dev_private; \
|
||||
u16 tmp; \
|
||||
tmp = I830_READ16( I830REG_HWSTAM ); \
|
||||
tmp = tmp & 0x6000; \
|
||||
I830_WRITE16( I830REG_HWSTAM, tmp ); \
|
||||
\
|
||||
tmp = I830_READ16( I830REG_INT_MASK_R ); \
|
||||
tmp = tmp & 0x6000; /* Unmask interrupts */ \
|
||||
I830_WRITE16( I830REG_INT_MASK_R, tmp ); \
|
||||
tmp = I830_READ16( I830REG_INT_ENABLE_R ); \
|
||||
tmp = tmp & 0x6000; /* Disable all interrupts */ \
|
||||
I830_WRITE16( I830REG_INT_ENABLE_R, tmp ); \
|
||||
} while (0)
|
||||
|
||||
#define DRIVER_POSTINSTALL() do { \
|
||||
drm_i830_private_t *dev_priv = \
|
||||
(drm_i830_private_t *)dev->dev_private; \
|
||||
u16 tmp; \
|
||||
tmp = I830_READ16( I830REG_INT_ENABLE_R ); \
|
||||
tmp = tmp & 0x6000; \
|
||||
tmp = tmp | 0x0003; /* Enable bp & user interrupts */ \
|
||||
I830_WRITE16( I830REG_INT_ENABLE_R, tmp ); \
|
||||
} while (0)
|
||||
|
||||
#define DRIVER_UNINSTALL() do { \
|
||||
drm_i830_private_t *dev_priv = \
|
||||
(drm_i830_private_t *)dev->dev_private; \
|
||||
u16 tmp; \
|
||||
if ( dev_priv ) { \
|
||||
tmp = I830_READ16( I830REG_INT_IDENTITY_R ); \
|
||||
tmp = tmp & ~(0x6000); /* Clear all interrupts */ \
|
||||
if ( tmp != 0 ) \
|
||||
I830_WRITE16( I830REG_INT_IDENTITY_R, tmp ); \
|
||||
\
|
||||
tmp = I830_READ16( I830REG_INT_ENABLE_R ); \
|
||||
tmp = tmp & 0x6000; /* Disable all interrupts */ \
|
||||
I830_WRITE16( I830REG_INT_ENABLE_R, tmp ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Buffer customization:
|
||||
*/
|
||||
|
||||
#define DRIVER_BUF_PRIV_T drm_i830_buf_priv_t
|
||||
|
||||
#define DRIVER_AGP_BUFFERS_MAP( dev ) \
|
||||
((drm_i830_private_t *)((dev)->dev_private))->buffer_map
|
||||
|
||||
#endif
|
||||
1418
linux/i830_dma.c
Normal file
1418
linux/i830_dma.c
Normal file
File diff suppressed because it is too large
Load diff
238
linux/i830_drm.h
Normal file
238
linux/i830_drm.h
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
#ifndef _I830_DRM_H_
|
||||
#define _I830_DRM_H_
|
||||
|
||||
/* WARNING: These defines must be the same as what the Xserver uses.
|
||||
* if you change them, you must change the defines in the Xserver.
|
||||
*/
|
||||
|
||||
#ifndef _I830_DEFINES_
|
||||
#define _I830_DEFINES_
|
||||
|
||||
#define I830_DMA_BUF_ORDER 12
|
||||
#define I830_DMA_BUF_SZ (1<<I830_DMA_BUF_ORDER)
|
||||
#define I830_DMA_BUF_NR 256
|
||||
#define I830_NR_SAREA_CLIPRECTS 8
|
||||
|
||||
/* Each region is a minimum of 64k, and there are at most 64 of them.
|
||||
*/
|
||||
#define I830_NR_TEX_REGIONS 64
|
||||
#define I830_LOG_MIN_TEX_REGION_SIZE 16
|
||||
|
||||
/* if defining I830_ENABLE_4_TEXTURES, do it in i830_3d_reg.h, too */
|
||||
#if !defined(I830_ENABLE_4_TEXTURES)
|
||||
#define I830_TEXTURE_COUNT 2
|
||||
#define I830_TEXBLEND_COUNT 2 /* always same as TEXTURE_COUNT? */
|
||||
#else /* defined(I830_ENABLE_4_TEXTURES) */
|
||||
#define I830_TEXTURE_COUNT 4
|
||||
#define I830_TEXBLEND_COUNT 4 /* always same as TEXTURE_COUNT? */
|
||||
#endif /* I830_ENABLE_4_TEXTURES */
|
||||
|
||||
#define I830_TEXBLEND_SIZE 12 /* (4 args + op) * 2 + COLOR_FACTOR */
|
||||
|
||||
#define I830_UPLOAD_CTX 0x1
|
||||
#define I830_UPLOAD_BUFFERS 0x2
|
||||
#define I830_UPLOAD_CLIPRECTS 0x4
|
||||
#define I830_UPLOAD_TEX0_IMAGE 0x100 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX0_CUBE 0x200 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX1_IMAGE 0x400 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX1_CUBE 0x800 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX2_IMAGE 0x1000 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX2_CUBE 0x2000 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX3_IMAGE 0x4000 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX3_CUBE 0x8000 /* handled clientside */
|
||||
#define I830_UPLOAD_TEX_N_IMAGE(n) (0x100 << (n * 2))
|
||||
#define I830_UPLOAD_TEX_N_CUBE(n) (0x200 << (n * 2))
|
||||
#define I830_UPLOAD_TEXIMAGE_MASK 0xff00
|
||||
#define I830_UPLOAD_TEX0 0x10000
|
||||
#define I830_UPLOAD_TEX1 0x20000
|
||||
#define I830_UPLOAD_TEX2 0x40000
|
||||
#define I830_UPLOAD_TEX3 0x80000
|
||||
#define I830_UPLOAD_TEX_N(n) (0x10000 << (n))
|
||||
#define I830_UPLOAD_TEX_MASK 0xf0000
|
||||
#define I830_UPLOAD_TEXBLEND0 0x100000
|
||||
#define I830_UPLOAD_TEXBLEND1 0x200000
|
||||
#define I830_UPLOAD_TEXBLEND2 0x400000
|
||||
#define I830_UPLOAD_TEXBLEND3 0x800000
|
||||
#define I830_UPLOAD_TEXBLEND_N(n) (0x100000 << (n))
|
||||
#define I830_UPLOAD_TEXBLEND_MASK 0xf00000
|
||||
#define I830_UPLOAD_TEX_PALETTE_N(n) (0x1000000 << (n))
|
||||
#define I830_UPLOAD_TEX_PALETTE_SHARED 0x4000000
|
||||
|
||||
/* Indices into buf.Setup where various bits of state are mirrored per
|
||||
* context and per buffer. These can be fired at the card as a unit,
|
||||
* or in a piecewise fashion as required.
|
||||
*/
|
||||
|
||||
/* Destbuffer state
|
||||
* - backbuffer linear offset and pitch -- invarient in the current dri
|
||||
* - zbuffer linear offset and pitch -- also invarient
|
||||
* - drawing origin in back and depth buffers.
|
||||
*
|
||||
* Keep the depth/back buffer state here to acommodate private buffers
|
||||
* in the future.
|
||||
*/
|
||||
|
||||
#define I830_DESTREG_CBUFADDR 0
|
||||
/* Invarient */
|
||||
#define I830_DESTREG_DBUFADDR 1
|
||||
#define I830_DESTREG_DV0 2
|
||||
#define I830_DESTREG_DV1 3
|
||||
#define I830_DESTREG_SENABLE 4
|
||||
#define I830_DESTREG_SR0 5
|
||||
#define I830_DESTREG_SR1 6
|
||||
#define I830_DESTREG_SR2 7
|
||||
#define I830_DESTREG_DR0 8
|
||||
#define I830_DESTREG_DR1 9
|
||||
#define I830_DESTREG_DR2 10
|
||||
#define I830_DESTREG_DR3 11
|
||||
#define I830_DESTREG_DR4 12
|
||||
#define I830_DEST_SETUP_SIZE 13
|
||||
|
||||
/* Context state
|
||||
*/
|
||||
#define I830_CTXREG_STATE1 0
|
||||
#define I830_CTXREG_STATE2 1
|
||||
#define I830_CTXREG_STATE3 2
|
||||
#define I830_CTXREG_STATE4 3
|
||||
#define I830_CTXREG_STATE5 4
|
||||
#define I830_CTXREG_IALPHAB 5
|
||||
#define I830_CTXREG_STENCILTST 6
|
||||
#define I830_CTXREG_ENABLES_1 7
|
||||
#define I830_CTXREG_ENABLES_2 8
|
||||
#define I830_CTXREG_AA 9
|
||||
#define I830_CTXREG_FOGCOLOR 10
|
||||
#define I830_CTXREG_BLENDCOLR0 11
|
||||
#define I830_CTXREG_BLENDCOLR 12 /* Dword 1 of 2 dword command */
|
||||
#define I830_CTXREG_VF 13
|
||||
#define I830_CTXREG_VF2 14
|
||||
#define I830_CTXREG_MCSB0 15
|
||||
#define I830_CTXREG_MCSB1 16
|
||||
#define I830_CTX_SETUP_SIZE 17
|
||||
|
||||
/* Texture state (per tex unit)
|
||||
*/
|
||||
|
||||
#define I830_TEXREG_MI0 0 /* GFX_OP_MAP_INFO (6 dwords) */
|
||||
#define I830_TEXREG_MI1 1
|
||||
#define I830_TEXREG_MI2 2
|
||||
#define I830_TEXREG_MI3 3
|
||||
#define I830_TEXREG_MI4 4
|
||||
#define I830_TEXREG_MI5 5
|
||||
#define I830_TEXREG_MF 6 /* GFX_OP_MAP_FILTER */
|
||||
#define I830_TEXREG_MLC 7 /* GFX_OP_MAP_LOD_CTL */
|
||||
#define I830_TEXREG_MLL 8 /* GFX_OP_MAP_LOD_LIMITS */
|
||||
#define I830_TEXREG_MCS 9 /* GFX_OP_MAP_COORD_SETS */
|
||||
#define I830_TEX_SETUP_SIZE 10
|
||||
|
||||
#define I830_FRONT 0x1
|
||||
#define I830_BACK 0x2
|
||||
#define I830_DEPTH 0x4
|
||||
|
||||
#endif /* _I830_DEFINES_ */
|
||||
|
||||
typedef struct _drm_i830_init {
|
||||
enum {
|
||||
I830_INIT_DMA = 0x01,
|
||||
I830_CLEANUP_DMA = 0x02
|
||||
} func;
|
||||
unsigned int mmio_offset;
|
||||
unsigned int buffers_offset;
|
||||
int sarea_priv_offset;
|
||||
unsigned int ring_start;
|
||||
unsigned int ring_end;
|
||||
unsigned int ring_size;
|
||||
unsigned int front_offset;
|
||||
unsigned int back_offset;
|
||||
unsigned int depth_offset;
|
||||
unsigned int w;
|
||||
unsigned int h;
|
||||
unsigned int pitch;
|
||||
unsigned int pitch_bits;
|
||||
unsigned int back_pitch;
|
||||
unsigned int depth_pitch;
|
||||
unsigned int cpp;
|
||||
} drm_i830_init_t;
|
||||
|
||||
/* Warning: If you change the SAREA structure you must change the Xserver
|
||||
* structure as well */
|
||||
|
||||
typedef struct _drm_i830_tex_region {
|
||||
unsigned char next, prev; /* indices to form a circular LRU */
|
||||
unsigned char in_use; /* owned by a client, or free? */
|
||||
int age; /* tracked by clients to update local LRU's */
|
||||
} drm_i830_tex_region_t;
|
||||
|
||||
typedef struct _drm_i830_sarea {
|
||||
unsigned int ContextState[I830_CTX_SETUP_SIZE];
|
||||
unsigned int BufferState[I830_DEST_SETUP_SIZE];
|
||||
unsigned int TexState[I830_TEXTURE_COUNT][I830_TEX_SETUP_SIZE];
|
||||
unsigned int TexBlendState[I830_TEXBLEND_COUNT][I830_TEXBLEND_SIZE];
|
||||
unsigned int TexBlendStateWordsUsed[I830_TEXBLEND_COUNT];
|
||||
unsigned int Palette[2][256];
|
||||
unsigned int dirty;
|
||||
|
||||
unsigned int nbox;
|
||||
drm_clip_rect_t boxes[I830_NR_SAREA_CLIPRECTS];
|
||||
|
||||
/* Maintain an LRU of contiguous regions of texture space. If
|
||||
* you think you own a region of texture memory, and it has an
|
||||
* age different to the one you set, then you are mistaken and
|
||||
* it has been stolen by another client. If global texAge
|
||||
* hasn't changed, there is no need to walk the list.
|
||||
*
|
||||
* These regions can be used as a proxy for the fine-grained
|
||||
* texture information of other clients - by maintaining them
|
||||
* in the same lru which is used to age their own textures,
|
||||
* clients have an approximate lru for the whole of global
|
||||
* texture space, and can make informed decisions as to which
|
||||
* areas to kick out. There is no need to choose whether to
|
||||
* kick out your own texture or someone else's - simply eject
|
||||
* them all in LRU order.
|
||||
*/
|
||||
|
||||
drm_i830_tex_region_t texList[I830_NR_TEX_REGIONS+1];
|
||||
/* Last elt is sentinal */
|
||||
int texAge; /* last time texture was uploaded */
|
||||
int last_enqueue; /* last time a buffer was enqueued */
|
||||
int last_dispatch; /* age of the most recently dispatched buffer */
|
||||
int last_quiescent; /* */
|
||||
int ctxOwner; /* last context to upload state */
|
||||
|
||||
int vertex_prim;
|
||||
} drm_i830_sarea_t;
|
||||
|
||||
typedef struct _drm_i830_clear {
|
||||
int clear_color;
|
||||
int clear_depth;
|
||||
int flags;
|
||||
unsigned int clear_colormask;
|
||||
unsigned int clear_depthmask;
|
||||
} drm_i830_clear_t;
|
||||
|
||||
|
||||
|
||||
/* These may be placeholders if we have more cliprects than
|
||||
* I830_NR_SAREA_CLIPRECTS. In that case, the client sets discard to
|
||||
* false, indicating that the buffer will be dispatched again with a
|
||||
* new set of cliprects.
|
||||
*/
|
||||
typedef struct _drm_i830_vertex {
|
||||
int idx; /* buffer index */
|
||||
int used; /* nr bytes in use */
|
||||
int discard; /* client is finished with the buffer? */
|
||||
} drm_i830_vertex_t;
|
||||
|
||||
typedef struct _drm_i830_copy_t {
|
||||
int idx; /* buffer index */
|
||||
int used; /* nr bytes in use */
|
||||
void *address; /* Address to copy from */
|
||||
} drm_i830_copy_t;
|
||||
|
||||
typedef struct drm_i830_dma {
|
||||
void *virtual;
|
||||
int request_idx;
|
||||
int request_size;
|
||||
int granted;
|
||||
} drm_i830_dma_t;
|
||||
|
||||
#endif /* _I830_DRM_H_ */
|
||||
102
linux/i830_drv.c
Normal file
102
linux/i830_drv.c
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/* i830_drv.c -- I810 driver -*- linux-c -*-
|
||||
* Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Jeff Hartmann <jhartmann@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
* Abraham vd Merwe <abraham@2d3d.co.za>
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include "i830.h"
|
||||
#include "drmP.h"
|
||||
#include "i830_drv.h"
|
||||
|
||||
#define DRIVER_AUTHOR "VA Linux Systems Inc."
|
||||
|
||||
#define DRIVER_NAME "i830"
|
||||
#define DRIVER_DESC "Intel 830M"
|
||||
#define DRIVER_DATE "20011004"
|
||||
|
||||
#define DRIVER_MAJOR 1
|
||||
#define DRIVER_MINOR 2
|
||||
#define DRIVER_PATCHLEVEL 0
|
||||
|
||||
#define DRIVER_IOCTLS \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_INIT)] = { i830_dma_init, 1, 1 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_VERTEX)] = { i830_dma_vertex, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_CLEAR)] = { i830_clear_bufs, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_FLUSH)] = { i830_flush_ioctl, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_GETAGE)] = { i830_getage, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_GETBUF)] = { i830_getbuf, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_SWAP)] = { i830_swap_bufs, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_COPY)] = { i830_copybuf, 1, 0 }, \
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_I830_DOCOPY)] = { i830_docopy, 1, 0 },
|
||||
|
||||
#define __HAVE_COUNTERS 4
|
||||
#define __HAVE_COUNTER6 _DRM_STAT_IRQ
|
||||
#define __HAVE_COUNTER7 _DRM_STAT_PRIMARY
|
||||
#define __HAVE_COUNTER8 _DRM_STAT_SECONDARY
|
||||
#define __HAVE_COUNTER9 _DRM_STAT_DMA
|
||||
|
||||
|
||||
#include "drm_agpsupport.h"
|
||||
#include "drm_auth.h"
|
||||
#include "drm_bufs.h"
|
||||
#include "drm_context.h"
|
||||
#include "drm_dma.h"
|
||||
#include "drm_drawable.h"
|
||||
#include "drm_drv.h"
|
||||
|
||||
#ifndef MODULE
|
||||
/* DRM(options) is called by the kernel to parse command-line options
|
||||
* passed via the boot-loader (e.g., LILO). It calls the insmod option
|
||||
* routine, drm_parse_drm.
|
||||
*/
|
||||
|
||||
/* JH- We have to hand expand the string ourselves because of the cpp. If
|
||||
* anyone can think of a way that we can fit into the __setup macro without
|
||||
* changing it, then please send the solution my way.
|
||||
*/
|
||||
static int __init i830_options( char *str )
|
||||
{
|
||||
DRM(parse_options)( str );
|
||||
return 1;
|
||||
}
|
||||
|
||||
__setup( DRIVER_NAME "=", i830_options );
|
||||
#endif
|
||||
|
||||
#include "drm_fops.h"
|
||||
#include "drm_init.h"
|
||||
#include "drm_ioctl.h"
|
||||
#include "drm_lock.h"
|
||||
#include "drm_lists.h"
|
||||
#include "drm_memory.h"
|
||||
#include "drm_proc.h"
|
||||
#include "drm_vm.h"
|
||||
#include "drm_stub.h"
|
||||
213
linux/i830_drv.h
Normal file
213
linux/i830_drv.h
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
/* i830_drv.h -- Private header for the I830 driver -*- linux-c -*-
|
||||
* Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
|
||||
*
|
||||
* 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
|
||||
* PRECISION INSIGHT 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.
|
||||
*
|
||||
* Authors: Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Jeff Hartmann <jhartmann@valinux.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _I830_DRV_H_
|
||||
#define _I830_DRV_H_
|
||||
|
||||
typedef struct drm_i830_buf_priv {
|
||||
u32 *in_use;
|
||||
int my_use_idx;
|
||||
int currently_mapped;
|
||||
void *virtual;
|
||||
void *kernel_virtual;
|
||||
int map_count;
|
||||
struct vm_area_struct *vma;
|
||||
} drm_i830_buf_priv_t;
|
||||
|
||||
typedef struct _drm_i830_ring_buffer{
|
||||
int tail_mask;
|
||||
unsigned long Start;
|
||||
unsigned long End;
|
||||
unsigned long Size;
|
||||
u8 *virtual_start;
|
||||
int head;
|
||||
int tail;
|
||||
int space;
|
||||
} drm_i830_ring_buffer_t;
|
||||
|
||||
typedef struct drm_i830_private {
|
||||
drm_map_t *sarea_map;
|
||||
drm_map_t *buffer_map;
|
||||
drm_map_t *mmio_map;
|
||||
|
||||
drm_i830_sarea_t *sarea_priv;
|
||||
drm_i830_ring_buffer_t ring;
|
||||
|
||||
unsigned long hw_status_page;
|
||||
unsigned long counter;
|
||||
|
||||
atomic_t flush_done;
|
||||
wait_queue_head_t flush_queue; /* Processes waiting until flush */
|
||||
drm_buf_t *mmap_buffer;
|
||||
|
||||
u32 front_di1, back_di1, zi1;
|
||||
|
||||
int back_offset;
|
||||
int depth_offset;
|
||||
int w, h;
|
||||
int pitch;
|
||||
int back_pitch;
|
||||
int depth_pitch;
|
||||
unsigned int cpp;
|
||||
} drm_i830_private_t;
|
||||
|
||||
/* i830_dma.c */
|
||||
extern int i830_dma_schedule(drm_device_t *dev, int locked);
|
||||
extern int i830_getbuf(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int i830_dma_init(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int i830_flush_ioctl(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern void i830_reclaim_buffers(drm_device_t *dev, pid_t pid);
|
||||
extern int i830_getage(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg);
|
||||
extern int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma);
|
||||
extern int i830_copybuf(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int i830_docopy(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
extern void i830_dma_quiescent(drm_device_t *dev);
|
||||
|
||||
extern int i830_dma_vertex(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
extern int i830_swap_bufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
extern int i830_clear_bufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
#define I830_VERBOSE 0
|
||||
|
||||
#define I830_BASE(reg) ((unsigned long) \
|
||||
dev_priv->mmio_map->handle)
|
||||
#define I830_ADDR(reg) (I830_BASE(reg) + reg)
|
||||
#define I830_DEREF(reg) *(__volatile__ int *)I830_ADDR(reg)
|
||||
#define I830_READ(reg) I830_DEREF(reg)
|
||||
#define I830_WRITE(reg,val) do { I830_DEREF(reg) = val; } while (0)
|
||||
#define I830_DEREF16(reg) *(__volatile__ u16 *)I830_ADDR(reg)
|
||||
#define I830_READ16(reg) I830_DEREF16(reg)
|
||||
#define I830_WRITE16(reg,val) do { I830_DEREF16(reg) = val; } while (0)
|
||||
|
||||
#define GFX_OP_USER_INTERRUPT ((0<<29)|(2<<23))
|
||||
#define GFX_OP_BREAKPOINT_INTERRUPT ((0<<29)|(1<<23))
|
||||
#define CMD_REPORT_HEAD (7<<23)
|
||||
#define CMD_STORE_DWORD_IDX ((0x21<<23) | 0x1)
|
||||
#define CMD_OP_BATCH_BUFFER ((0x0<<29)|(0x30<<23)|0x1)
|
||||
|
||||
#define INST_PARSER_CLIENT 0x00000000
|
||||
#define INST_OP_FLUSH 0x02000000
|
||||
#define INST_FLUSH_MAP_CACHE 0x00000001
|
||||
|
||||
|
||||
#define BB1_START_ADDR_MASK (~0x7)
|
||||
#define BB1_PROTECTED (1<<0)
|
||||
#define BB1_UNPROTECTED (0<<0)
|
||||
#define BB2_END_ADDR_MASK (~0x7)
|
||||
|
||||
#define I830REG_HWSTAM 0x02098
|
||||
#define I830REG_INT_IDENTITY_R 0x020a4
|
||||
#define I830REG_INT_MASK_R 0x020a8
|
||||
#define I830REG_INT_ENABLE_R 0x020a0
|
||||
|
||||
#define LP_RING 0x2030
|
||||
#define HP_RING 0x2040
|
||||
#define RING_TAIL 0x00
|
||||
#define TAIL_ADDR 0x000FFFF8
|
||||
#define RING_HEAD 0x04
|
||||
#define HEAD_WRAP_COUNT 0xFFE00000
|
||||
#define HEAD_WRAP_ONE 0x00200000
|
||||
#define HEAD_ADDR 0x001FFFFC
|
||||
#define RING_START 0x08
|
||||
#define START_ADDR 0x00FFFFF8
|
||||
#define RING_LEN 0x0C
|
||||
#define RING_NR_PAGES 0x000FF000
|
||||
#define RING_REPORT_MASK 0x00000006
|
||||
#define RING_REPORT_64K 0x00000002
|
||||
#define RING_REPORT_128K 0x00000004
|
||||
#define RING_NO_REPORT 0x00000000
|
||||
#define RING_VALID_MASK 0x00000001
|
||||
#define RING_VALID 0x00000001
|
||||
#define RING_INVALID 0x00000000
|
||||
|
||||
#define GFX_OP_SCISSOR ((0x3<<29)|(0x1c<<24)|(0x10<<19))
|
||||
#define SC_UPDATE_SCISSOR (0x1<<1)
|
||||
#define SC_ENABLE_MASK (0x1<<0)
|
||||
#define SC_ENABLE (0x1<<0)
|
||||
|
||||
#define GFX_OP_SCISSOR_INFO ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
|
||||
#define SCI_YMIN_MASK (0xffff<<16)
|
||||
#define SCI_XMIN_MASK (0xffff<<0)
|
||||
#define SCI_YMAX_MASK (0xffff<<16)
|
||||
#define SCI_XMAX_MASK (0xffff<<0)
|
||||
|
||||
#define GFX_OP_SCISSOR_ENABLE ((0x3<<29)|(0x1c<<24)|(0x10<<19))
|
||||
#define GFX_OP_SCISSOR_RECT ((0x3<<29)|(0x1d<<24)|(0x81<<16)|1)
|
||||
#define GFX_OP_COLOR_FACTOR ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
|
||||
#define GFX_OP_STIPPLE ((0x3<<29)|(0x1d<<24)|(0x83<<16))
|
||||
#define GFX_OP_MAP_INFO ((0x3<<29)|(0x1d<<24)|0x4)
|
||||
#define GFX_OP_DESTBUFFER_VARS ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
|
||||
#define GFX_OP_DRAWRECT_INFO ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
|
||||
#define GFX_OP_PRIMITIVE ((0x3<<29)|(0x1f<<24))
|
||||
|
||||
#define CMD_OP_DESTBUFFER_INFO ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1)
|
||||
|
||||
|
||||
#define BR00_BITBLT_CLIENT 0x40000000
|
||||
#define BR00_OP_COLOR_BLT 0x10000000
|
||||
#define BR00_OP_SRC_COPY_BLT 0x10C00000
|
||||
#define BR13_SOLID_PATTERN 0x80000000
|
||||
|
||||
#define BUF_3D_ID_COLOR_BACK (0x3<<24)
|
||||
#define BUF_3D_ID_DEPTH (0x7<<24)
|
||||
#define BUF_3D_USE_FENCE (1<<23)
|
||||
#define BUF_3D_PITCH(x) (((x)/4)<<2)
|
||||
|
||||
#define CMD_OP_MAP_PALETTE_LOAD ((3<<29)|(0x1d<<24)|(0x82<<16)|255)
|
||||
#define MAP_PALETTE_NUM(x) ((x<<8) & (1<<8))
|
||||
#define MAP_PALETTE_BOTH (1<<11)
|
||||
|
||||
#define XY_COLOR_BLT_CMD ((2<<29)|(0x50<<22)|0x4)
|
||||
#define XY_COLOR_BLT_WRITE_ALPHA (1<<21)
|
||||
#define XY_COLOR_BLT_WRITE_RGB (1<<20)
|
||||
|
||||
#define XY_SRC_COPY_BLT_CMD ((2<<29)|(0x53<<22)|6)
|
||||
#define XY_SRC_COPY_BLT_WRITE_ALPHA (1<<21)
|
||||
#define XY_SRC_COPY_BLT_WRITE_RGB (1<<20)
|
||||
|
||||
#define MI_BATCH_BUFFER ((0x30<<23)|1)
|
||||
#define MI_BATCH_NON_SECURE (1)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Add table
Reference in a new issue