summaryrefslogtreecommitdiff
path: root/bsd
diff options
context:
space:
mode:
Diffstat (limited to 'bsd')
-rw-r--r--bsd/drm_agpsupport.h326
-rw-r--r--bsd/drm_linux.h158
-rw-r--r--bsd/drm_os_freebsd.h375
-rw-r--r--bsd/drm_sysctl.h523
-rw-r--r--bsd/drm_vm.h81
-rw-r--r--bsd/gamma/gamma_dma.c526
-rw-r--r--bsd/gamma/gamma_drv.c634
-rw-r--r--bsd/gamma/gamma_drv.h86
-rw-r--r--bsd/i810/Makefile25
-rw-r--r--bsd/mga/Makefile21
-rw-r--r--bsd/r128/Makefile25
-rw-r--r--bsd/radeon/Makefile25
-rw-r--r--bsd/sis/Makefile25
13 files changed, 1829 insertions, 1001 deletions
diff --git a/bsd/drm_agpsupport.h b/bsd/drm_agpsupport.h
new file mode 100644
index 00000000..ac12c867
--- /dev/null
+++ b/bsd/drm_agpsupport.h
@@ -0,0 +1,326 @@
+/* drm_agpsupport.h -- DRM support for AGP/GART backend -*- linux-c -*-
+ * Created: Mon Dec 13 09:56:45 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.
+ *
+ * Author:
+ * Rickard E. (Rik) Faith <faith@valinux.com>
+ * Gareth Hughes <gareth@valinux.com>
+ */
+
+#include "drmP.h"
+
+#include <vm/vm.h>
+#include <vm/pmap.h>
+#if __REALLY_HAVE_AGP
+#include <sys/agpio.h>
+#endif
+
+int DRM(agp_info)(DRM_OS_IOCTL)
+{
+ drm_device_t *dev = kdev->si_drv1;
+ struct agp_info *kern;
+ drm_agp_info_t info;
+
+ if (!dev->agp || !dev->agp->acquired) return EINVAL;
+
+ kern = &dev->agp->info;
+ agp_get_info(dev->agp->agpdev, kern);
+ info.agp_version_major = 1;
+ info.agp_version_minor = 0;
+ info.mode = kern->ai_mode;
+ info.aperture_base = kern->ai_aperture_base;
+ info.aperture_size = kern->ai_aperture_size;
+ info.memory_allowed = kern->ai_memory_allowed;
+ info.memory_used = kern->ai_memory_used;
+ info.id_vendor = kern->ai_devid & 0xffff;
+ info.id_device = kern->ai_devid >> 16;
+
+ *(drm_agp_info_t *) data = info;
+ return 0;
+}
+
+int DRM(agp_acquire)(DRM_OS_IOCTL)
+{
+ drm_device_t *dev = kdev->si_drv1;
+ int retcode;
+
+ if (!dev->agp || dev->agp->acquired) return EINVAL;
+ retcode = agp_acquire(dev->agp->agpdev);
+ if (retcode) return retcode;
+ dev->agp->acquired = 1;
+ return 0;
+}
+
+int DRM(agp_release)(DRM_OS_IOCTL)
+{
+ drm_device_t *dev = kdev->si_drv1;
+
+ if (!dev->agp || !dev->agp->acquired)
+ return EINVAL;
+ agp_release(dev->agp->agpdev);
+ dev->agp->acquired = 0;
+ return 0;
+
+}
+
+void DRM(agp_do_release)(void)
+{
+ device_t agpdev;
+
+ agpdev = agp_find_device();
+ if (agpdev)
+ agp_release(agpdev);
+}
+
+int DRM(agp_enable)(DRM_OS_IOCTL)
+{
+ drm_device_t *dev = kdev->si_drv1;
+ drm_agp_mode_t mode;
+
+ if (!dev->agp || !dev->agp->acquired) return EINVAL;
+
+ mode = *(drm_agp_mode_t *) data;
+
+ dev->agp->mode = mode.mode;
+ agp_enable(dev->agp->agpdev, mode.mode);
+ dev->agp->base = dev->agp->info.ai_aperture_base;
+ dev->agp->enabled = 1;
+ return 0;
+}
+
+int DRM(agp_alloc)(DRM_OS_IOCTL)
+{
+ drm_device_t *dev = kdev->si_drv1;
+ drm_agp_buffer_t request;
+ drm_agp_mem_t *entry;
+ void *handle;
+ unsigned long pages;
+ u_int32_t type;
+ struct agp_memory_info info;
+
+ if (!dev->agp || !dev->agp->acquired) return EINVAL;
+
+ request = *(drm_agp_buffer_t *) data;
+
+ if (!(entry = DRM(alloc)(sizeof(*entry), DRM_MEM_AGPLISTS)))
+ return ENOMEM;
+
+ bzero(entry, sizeof(*entry));
+
+ pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
+ type = (u_int32_t) request.type;
+
+ if (!(handle = DRM(alloc_agp)(pages, type))) {
+ DRM(free)(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
+ return ENOMEM;
+ }
+
+ entry->handle = handle;
+ entry->bound = 0;
+ entry->pages = pages;
+ entry->prev = NULL;
+ entry->next = dev->agp->memory;
+ if (dev->agp->memory) dev->agp->memory->prev = entry;
+ dev->agp->memory = entry;
+
+ agp_memory_info(dev->agp->agpdev, entry->handle, &info);
+
+ request.handle = (unsigned long) entry->handle;
+ request.physical = info.ami_physical;
+
+ *(drm_agp_buffer_t *) data = request;
+
+ return 0;
+}
+
+static drm_agp_mem_t * DRM(agp_lookup_entry)(drm_device_t *dev, void *handle)
+{
+ drm_agp_mem_t *entry;
+
+ for (entry = dev->agp->memory; entry; entry = entry->next) {
+ if (entry->handle == handle) return entry;
+ }
+ return NULL;
+}
+
+int DRM(agp_unbind)(DRM_OS_IOCTL)
+{
+ drm_device_t *dev = kdev->si_drv1;
+ drm_agp_binding_t request;
+ drm_agp_mem_t *entry;
+ int retcode;
+
+ if (!dev->agp || !dev->agp->acquired) return EINVAL;
+ request = *(drm_agp_binding_t *) data;
+ if (!(entry = DRM(agp_lookup_entry)(dev, (void *) request.handle)))
+ return EINVAL;
+ if (!entry->bound) return EINVAL;
+ retcode=DRM(unbind_agp)(entry->handle);
+ if (!retcode)
+ {
+ entry->bound=0;
+ return 0;
+ }
+ else
+ return retcode;
+}
+
+int DRM(agp_bind)(DRM_OS_IOCTL)
+{
+ drm_device_t *dev = kdev->si_drv1;
+ drm_agp_binding_t request;
+ drm_agp_mem_t *entry;
+ int retcode;
+ int page;
+
+ DRM_DEBUG("agp_bind, page_size=%x\n", PAGE_SIZE);
+ if (!dev->agp || !dev->agp->acquired)
+ return EINVAL;
+ request = *(drm_agp_binding_t *) data;
+ if (!(entry = DRM(agp_lookup_entry)(dev, (void *) request.handle)))
+ return EINVAL;
+ if (entry->bound) return EINVAL;
+ page = (request.offset + PAGE_SIZE - 1) / PAGE_SIZE;
+ if ((retcode = DRM(bind_agp)(entry->handle, page)))
+ return retcode;
+ entry->bound = dev->agp->base + (page << PAGE_SHIFT);
+ return 0;
+}
+
+int DRM(agp_free)(DRM_OS_IOCTL)
+{
+ drm_device_t *dev = kdev->si_drv1;
+ drm_agp_buffer_t request;
+ drm_agp_mem_t *entry;
+
+ if (!dev->agp || !dev->agp->acquired) return EINVAL;
+ request = *(drm_agp_buffer_t *) data;
+ if (!(entry = DRM(agp_lookup_entry)(dev, (void*) request.handle)))
+ return EINVAL;
+ if (entry->bound) DRM(unbind_agp)(entry->handle);
+
+ if (entry->prev) entry->prev->next = entry->next;
+ else dev->agp->memory = entry->next;
+ if (entry->next) entry->next->prev = entry->prev;
+ DRM(free_agp)(entry->handle, entry->pages);
+ DRM(free)(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
+ return 0;
+}
+
+drm_agp_head_t *DRM(agp_init)(void)
+{
+ device_t agpdev;
+ drm_agp_head_t *head = NULL;
+ int agp_available = 1;
+
+ agpdev = agp_find_device();
+ if (!agpdev)
+ agp_available = 0;
+
+ DRM_DEBUG("agp_available = %d\n", agp_available);
+
+ if (agp_available) {
+ if (!(head = DRM(alloc)(sizeof(*head), DRM_MEM_AGPLISTS)))
+ return NULL;
+ bzero((void *)head, sizeof(*head));
+ head->agpdev = agpdev;
+ agp_get_info(agpdev, &head->info);
+ head->memory = NULL;
+#if 0 /* bogus */
+ switch (head->agp_info.chipset) {
+ case INTEL_GENERIC: head->chipset = "Intel"; break;
+ case INTEL_LX: head->chipset = "Intel 440LX"; break;
+ case INTEL_BX: head->chipset = "Intel 440BX"; break;
+ case INTEL_GX: head->chipset = "Intel 440GX"; break;
+ case INTEL_I810: head->chipset = "Intel i810"; break;
+ case VIA_GENERIC: head->chipset = "VIA"; break;
+ case VIA_VP3: head->chipset = "VIA VP3"; break;
+ case VIA_MVP3: head->chipset = "VIA MVP3"; break;
+ case VIA_APOLLO_PRO: head->chipset = "VIA Apollo Pro"; break;
+ case SIS_GENERIC: head->chipset = "SiS"; break;
+ case AMD_GENERIC: head->chipset = "AMD"; break;
+ case AMD_IRONGATE: head->chipset = "AMD Irongate"; break;
+ case ALI_GENERIC: head->chipset = "ALi"; break;
+ case ALI_M1541: head->chipset = "ALi M1541"; break;
+ default:
+ }
+#endif
+ DRM_INFO("AGP at 0x%08x %dMB\n",
+ head->info.ai_aperture_base,
+ head->info.ai_aperture_size >> 20);
+ }
+ return head;
+}
+
+void DRM(agp_uninit)(void)
+{
+/* FIXME: What goes here */
+}
+
+
+agp_memory *DRM(agp_allocate_memory)(size_t pages, u32 type)
+{
+ device_t agpdev;
+
+ agpdev = agp_find_device();
+ if (!agpdev)
+ return NULL;
+
+ return agp_alloc_memory(agpdev, type, pages << AGP_PAGE_SHIFT);
+}
+
+int DRM(agp_free_memory)(agp_memory *handle)
+{
+ device_t agpdev;
+
+ agpdev = agp_find_device();
+ if (!agpdev || !handle)
+ return 0;
+
+ agp_free_memory(agpdev, handle);
+ return 1;
+}
+
+int DRM(agp_bind_memory)(agp_memory *handle, off_t start)
+{
+ device_t agpdev;
+
+ agpdev = agp_find_device();
+ if (!agpdev || !handle)
+ return EINVAL;
+
+ return agp_bind_memory(agpdev, handle, start * PAGE_SIZE);
+}
+
+int DRM(agp_unbind_memory)(agp_memory *handle)
+{
+ device_t agpdev;
+
+ agpdev = agp_find_device();
+ if (!agpdev || !handle)
+ return EINVAL;
+
+ return agp_unbind_memory(agpdev, handle);
+}
diff --git a/bsd/drm_linux.h b/bsd/drm_linux.h
new file mode 100644
index 00000000..9e6f644b
--- /dev/null
+++ b/bsd/drm_linux.h
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2000 by Coleman Kane <cokane@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Gardner Buchanan.
+ * 4. The name of Gardner Buchanan may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/dev/tdfx/tdfx_linux.h,v 1.4 2000/08/22 05:57:55 marcel Exp $
+ */
+
+/* FIXME: There are IOCTLS to merge in here, see drm.h*/
+
+/* Query IOCTLs */
+/* XFree86 4.1.x DRI support */
+
+#define LINUX_DRM_IOCTL_VERSION 0x6400
+#define LINUX_DRM_IOCTL_GET_UNIQUE 0x6401
+#define LINUX_DRM_IOCTL_GET_MAGIC 0x6402
+#define LINUX_DRM_IOCTL_IRQ_BUSID 0x6403
+#define LINUX_DRM_IOCTL_GET_MAP 0x6404
+#define LINUX_DRM_IOCTL_GET_CLIENT 0x6405
+#define LINUX_DRM_IOCTL_GET_STATS 0x6406
+
+#define LINUX_DRM_IOCTL_SET_UNIQUE 0x6410
+#define LINUX_DRM_IOCTL_AUTH_MAGIC 0x6411
+#define LINUX_DRM_IOCTL_BLOCK 0x6412
+#define LINUX_DRM_IOCTL_UNBLOCK 0x6413
+#define LINUX_DRM_IOCTL_CONTROL 0x6414
+#define LINUX_DRM_IOCTL_ADD_MAP 0x6415
+#define LINUX_DRM_IOCTL_ADD_BUFS 0x6416
+#define LINUX_DRM_IOCTL_MARK_BUFS 0x6417
+#define LINUX_DRM_IOCTL_INFO_BUFS 0x6418
+#define LINUX_DRM_IOCTL_MAP_BUFS 0x6419
+#define LINUX_DRM_IOCTL_FREE_BUFS 0x641a
+
+#define LINUX_DRM_IOCTL_RM_MAP 0x641b
+
+#define LINUX_DRM_IOCTL_SET_SAREA_CTX 0x641c
+#define LINUX_DRM_IOCTL_GET_SAREA_CTX 0x641d
+
+#define LINUX_DRM_IOCTL_ADD_CTX 0x6420
+#define LINUX_DRM_IOCTL_RM_CTX 0x6421
+#define LINUX_DRM_IOCTL_MOD_CTX 0x6422
+#define LINUX_DRM_IOCTL_GET_CTX 0x6423
+#define LINUX_DRM_IOCTL_SWITCH_CTX 0x6424
+#define LINUX_DRM_IOCTL_NEW_CTX 0x6425
+#define LINUX_DRM_IOCTL_RES_CTX 0x6426
+#define LINUX_DRM_IOCTL_ADD_DRAW 0x6427
+#define LINUX_DRM_IOCTL_RM_DRAW 0x6428
+#define LINUX_DRM_IOCTL_DMA 0x6429
+#define LINUX_DRM_IOCTL_LOCK 0x642a
+#define LINUX_DRM_IOCTL_UNLOCK 0x642b
+#define LINUX_DRM_IOCTL_FINISH 0x642c
+
+#define LINUX_DRM_IOCTL_AGP_ACQUIRE 0x6430
+#define LINUX_DRM_IOCTL_AGP_RELEASE 0x6431
+#define LINUX_DRM_IOCTL_AGP_ENABLE 0x6432
+#define LINUX_DRM_IOCTL_AGP_INFO 0x6433
+#define LINUX_DRM_IOCTL_AGP_ALLOC 0x6434
+#define LINUX_DRM_IOCTL_AGP_FREE 0x6435
+#define LINUX_DRM_IOCTL_AGP_BIND 0x6436
+#define LINUX_DRM_IOCTL_AGP_UNBIND 0x6437
+
+#define LINUX_DRM_IOCTL_SG_ALLOC 0x6438
+#define LINUX_DRM_IOCTL_SG_FREE 0x6439
+
+/* MGA specific ioctls */
+#define LINUX_DRM_IOCTL_MGA_INIT 0x6440
+#define LINUX_DRM_IOCTL_MGA_FLUSH 0x6441
+#define LINUX_DRM_IOCTL_MGA_RESET 0x6442
+#define LINUX_DRM_IOCTL_MGA_SWAP 0x6443
+#define LINUX_DRM_IOCTL_MGA_CLEAR 0x6444
+#define LINUX_DRM_IOCTL_MGA_VERTEX 0x6445
+#define LINUX_DRM_IOCTL_MGA_INDICES 0x6446
+#define LINUX_DRM_IOCTL_MGA_ILOAD 0x6447
+#define LINUX_DRM_IOCTL_MGA_BLIT 0x6448
+
+/* i810 specific ioctls */
+#define LINUX_DRM_IOCTL_I810_INIT 0x6440
+#define LINUX_DRM_IOCTL_I810_VERTEX 0x6441
+#define LINUX_DRM_IOCTL_I810_CLEAR 0x6442
+#define LINUX_DRM_IOCTL_I810_FLUSH 0x6443
+#define LINUX_DRM_IOCTL_I810_GETAGE 0x6444
+#define LINUX_DRM_IOCTL_I810_GETBUF 0x6445
+#define LINUX_DRM_IOCTL_I810_SWAP 0x6446
+#define LINUX_DRM_IOCTL_I810_COPY 0x6447
+#define LINUX_DRM_IOCTL_I810_DOCOPY 0x6448
+
+/* I830 specific ioctls */
+#define LINUX_DRM_IOCTL_I830_INIT 0x6440
+#define LINUX_DRM_IOCTL_I830_VERTEX 0x6441
+#define LINUX_DRM_IOCTL_I830_CLEAR 0x6442
+#define LINUX_DRM_IOCTL_I830_FLUSH 0x6443
+#define LINUX_DRM_IOCTL_I830_GETAGE 0x6444
+#define LINUX_DRM_IOCTL_I830_GETBUF 0x6445
+#define LINUX_DRM_IOCTL_I830_SWAP 0x6446
+#define LINUX_DRM_IOCTL_I830_COPY 0x6447
+#define LINUX_DRM_IOCTL_I830_DOCOPY 0x6448
+
+/* Rage 128 specific ioctls */
+#define LINUX_DRM_IOCTL_R128_INIT 0x6440
+#define LINUX_DRM_IOCTL_R128_CCE_START 0x6441
+#define LINUX_DRM_IOCTL_R128_CCE_STOP 0x6442
+#define LINUX_DRM_IOCTL_R128_CCE_RESET 0x6443
+#define LINUX_DRM_IOCTL_R128_CCE_IDLE 0x6444
+#define LINUX_DRM_IOCTL_R128_RESET 0x6446
+#define LINUX_DRM_IOCTL_R128_SWAP 0x6447
+#define LINUX_DRM_IOCTL_R128_CLEAR 0x6448
+#define LINUX_DRM_IOCTL_R128_VERTEX 0x6449
+#define LINUX_DRM_IOCTL_R128_INDICES 0x644a
+#define LINUX_DRM_IOCTL_R128_BLIT 0x644b
+#define LINUX_DRM_IOCTL_R128_DEPTH 0x644c
+#define LINUX_DRM_IOCTL_R128_STIPPLE 0x644d
+#define LINUX_DRM_IOCTL_R128_INDIRECT 0x644f
+#define LINUX_DRM_IOCTL_R128_FULLSCREEN 0x6450
+
+/* Radeon specific ioctls */
+#define LINUX_DRM_IOCTL_RADEON_CP_INIT 0x6440
+#define LINUX_DRM_IOCTL_RADEON_CP_START 0x6441
+#define LINUX_DRM_IOCTL_RADEON_CP_STOP 0x6442
+#define LINUX_DRM_IOCTL_RADEON_CP_RESET 0x6443
+#define LINUX_DRM_IOCTL_RADEON_CP_IDLE 0x6444
+#define LINUX_DRM_IOCTL_RADEON_RESET 0x6445
+#define LINUX_DRM_IOCTL_RADEON_FULLSCREEN 0x6446
+#define LINUX_DRM_IOCTL_RADEON_SWAP 0x6447
+#define LINUX_DRM_IOCTL_RADEON_CLEAR 0x6448
+#define LINUX_DRM_IOCTL_RADEON_VERTEX 0x6449
+#define LINUX_DRM_IOCTL_RADEON_INDICES 0x644a
+#define LINUX_DRM_IOCTL_RADEON_STIPPLE 0x644c
+#define LINUX_DRM_IOCTL_RADEON_INDIRECT 0x644d
+#define LINUX_DRM_IOCTL_RADEON_TEXTURE 0x644e
+
+/* card specific ioctls may increase the DRM_MAX */
+#define LINUX_IOCTL_DRM_MIN LINUX_DRM_IOCTL_VERSION
+#define LINUX_IOCTL_DRM_MAX LINUX_DRM_IOCTL_R128_FULLSCREEN
diff --git a/bsd/drm_os_freebsd.h b/bsd/drm_os_freebsd.h
new file mode 100644
index 00000000..72c5baf6
--- /dev/null
+++ b/bsd/drm_os_freebsd.h
@@ -0,0 +1,375 @@
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/stat.h>
+#include <sys/proc.h>
+#include <sys/lock.h>
+#include <sys/fcntl.h>
+#include <sys/uio.h>
+#include <sys/filio.h>
+#include <sys/sysctl.h>
+#include <sys/select.h>
+#include <vm/vm.h>
+#include <vm/pmap.h>
+#include <machine/pmap.h>
+#if __FreeBSD_version >= 500000
+#include <sys/selinfo.h>
+#endif
+#include <sys/bus.h>
+#if __FreeBSD_version >= 400005
+#include <sys/taskqueue.h>
+#endif
+#if __FreeBSD_version >= 500000
+#include <sys/mutex.h>
+#endif
+
+#if __FreeBSD_version >= 400006
+#define __REALLY_HAVE_AGP __HAVE_AGP
+#endif
+
+#define __REALLY_HAVE_MTRR 0
+#define __REALLY_HAVE_SG 0
+
+#if __REALLY_HAVE_AGP
+#include <pci/agpvar.h>
+#endif
+
+#define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
+
+#define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
+#define DRM_DEV_UID 0
+#define DRM_DEV_GID 0
+
+
+#if __FreeBSD_version >= 500000
+#define DRM_OS_SPINTYPE struct mtx
+#define DRM_OS_SPININIT(l,name) mtx_init(&l, name, MTX_DEF)
+#define DRM_OS_SPINLOCK(l) mtx_lock(l)
+#define DRM_OS_SPINUNLOCK(u) mtx_unlock(u);
+#define DRM_OS_LOCK lockmgr(&dev->dev_lock, LK_EXCLUSIVE, 0, curthread)
+#define DRM_OS_UNLOCK lockmgr(&dev->dev_lock, LK_RELEASE, 0, curthread)
+#define DRM_OS_CURPROC curthread
+#define DRM_OS_STRUCTPROC struct thread
+#define DRM_OS_CURRENTPID curthread->td_proc->p_pid
+#define DRM_OS_IOCTL dev_t kdev, u_long cmd, caddr_t data, int flags, struct thread *p
+#define DRM_OS_CHECKSUSER suser(p->td_proc)
+#else
+#define DRM_OS_CURPROC curproc
+#define DRM_OS_STRUCTPROC struct proc
+#define DRM_OS_SPINTYPE struct simplelock
+#define DRM_OS_SPININIT(l,name) simple_lock_init(&l)
+#define DRM_OS_SPINLOCK(l) simple_lock(l)
+#define DRM_OS_SPINUNLOCK(u) simple_unlock(u);
+#define DRM_OS_IOCTL dev_t kdev, u_long cmd, caddr_t data, int flags, struct proc *p
+#define DRM_OS_LOCK lockmgr(&dev->dev_lock, LK_EXCLUSIVE, 0, curproc)
+#define DRM_OS_UNLOCK lockmgr(&dev->dev_lock, LK_RELEASE, 0, curproc)
+#define DRM_OS_CURRENTPID curproc->p_pid
+#define DRM_OS_CHECKSUSER suser(p)
+#endif
+
+#define DRM_OS_TASKQUEUE_ARGS void *dev, int pending
+#define DRM_OS_IRQ_ARGS void *device
+#define DRM_OS_DEVICE drm_device_t *dev = kdev->si_drv1
+#define DRM_OS_MALLOC(size) malloc( size, DRM(M_DRM), M_NOWAIT )
+#define DRM_OS_FREE(pt) free( pt, DRM(M_DRM) )
+#define DRM_OS_VTOPHYS(addr) vtophys(addr)
+
+#define DRM_OS_PRIV \
+ drm_file_t *priv = (drm_file_t *) DRM(find_file_by_proc)(dev, p); \
+ if (!priv) { \
+ DRM_DEBUG("can't find authenticator\n"); \
+ return EINVAL; \
+ }
+
+#define DRM_OS_DELAY( udelay ) \
+do { \
+ struct timeval tv1, tv2; \
+ microtime(&tv1); \
+ do { \
+ microtime(&tv2); \
+ } \
+ while (((tv2.tv_sec-tv1.tv_sec)*1000000 + tv2.tv_usec - tv1.tv_usec) < udelay ); \
+} while (0)
+
+#define DRM_OS_RETURN(v) return v;
+
+
+#define DRM_OS_KRNTOUSR(arg1, arg2, arg3) \
+ *arg1 = arg2
+#define DRM_OS_KRNFROMUSR(arg1, arg2, arg3) \
+ arg1 = *arg2
+#define DRM_OS_COPYTOUSR(arg1, arg2, arg3) \
+ copyout(arg2, arg1, arg3)
+#define DRM_OS_COPYFROMUSR(arg1, arg2, arg3) \
+ copyin(arg2, arg1, arg3)
+
+#define DRM_OS_READMEMORYBARRIER \
+{ \
+ int xchangeDummy; \
+ DRM_DEBUG("%s\n", __FUNCTION__); \
+ __asm__ volatile(" push %%eax ; xchg %%eax, %0 ; pop %%eax" : : "m" (xchangeDummy)); \
+ __asm__ volatile(" push %%eax ; push %%ebx ; push %%ecx ; push %%edx ;" \
+ " movl $0,%%eax ; cpuid ; pop %%edx ; pop %%ecx ; pop %%ebx ;" \
+ " pop %%eax" : /* no outputs */ : /* no inputs */ ); \
+} while (0);
+
+#define DRM_OS_WRITEMEMORYBARRIER DRM_OS_READMEMORYBARRIER
+
+#define DRM_OS_WAKEUP(w) wakeup(w)
+#define DRM_OS_WAKEUP_INT(w) wakeup(w)
+
+#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
+
+#define malloctype DRM(M_DRM)
+/* The macros confliced in the MALLOC_DEFINE */
+MALLOC_DECLARE(malloctype);
+#undef malloctype
+
+typedef struct drm_chipinfo
+{
+ int vendor;
+ int device;
+ int supported;
+ char *name;
+} drm_chipinfo_t;
+
+typedef unsigned long atomic_t;
+typedef u_int32_t cycles_t;
+typedef u_int32_t spinlock_t;
+typedef u_int32_t u32;
+typedef u_int16_t u16;
+typedef u_int8_t u8;
+#define atomic_set(p, v) (*(p) = (v))
+#define atomic_read(p) (*(p))
+#define atomic_inc(p) atomic_add_long(p, 1)
+#define atomic_dec(p) atomic_subtract_long(p, 1)
+#define atomic_add(n, p) atomic_add_long(p, n)
+#define atomic_sub(n, p) atomic_subtract_long(p, n)
+
+/* Fake this */
+static __inline unsigned int
+test_and_set_bit(int b, volatile unsigned long *p)
+{
+ int s = splhigh();
+ unsigned int m = 1<<b;
+ unsigned int r = *p & m;
+ *p |= m;
+ splx(s);
+ return r;
+}
+
+static __inline void
+clear_bit(int b, volatile unsigned long *p)
+{
+ atomic_clear_long(p + (b >> 5), 1 << (b & 0x1f));
+}
+
+static __inline void
+set_bit(int b, volatile unsigned long *p)
+{
+ atomic_set_long(p + (b >> 5), 1 << (b & 0x1f));
+}
+
+static __inline int
+test_bit(int b, volatile unsigned long *p)
+{
+ return p[b >> 5] & (1 << (b & 0x1f));
+}
+
+static __inline int
+find_first_zero_bit(volatile unsigned long *p, int max)
+{
+ int b;
+
+ for (b = 0; b < max; b += 32) {
+ if (p[b >> 5] != ~0) {
+ for (;;) {
+ if ((p[b >> 5] & (1 << (b & 0x1f))) == 0)
+ return b;
+ b++;
+ }
+ }
+ }
+ return max;
+}
+
+#define spldrm() spltty()
+
+#define memset(p, v, s) bzero(p, s)
+
+/*
+ * Fake out the module macros for versions of FreeBSD where they don't
+ * exist.
+ */
+#if (__FreeBSD_version < 500002 && __FreeBSD_version > 500000) || __FreeBSD_version < 420000
+/* FIXME: again, what's the exact date? */
+#define MODULE_VERSION(a,b) struct __hack
+#define MODULE_DEPEND(a,b,c,d,e) struct __hack
+
+#endif
+
+#define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
+#define _DRM_CAS(lock,old,new,__ret) \
+ do { \
+ int __dummy; /* Can't mark eax as clobbered */ \
+ __asm__ __volatile__( \
+ "lock ; cmpxchg %4,%1\n\t" \
+ "setnz %0" \
+ : "=d" (__ret), \
+ "=m" (__drm_dummy_lock(lock)), \
+ "=a" (__dummy) \
+ : "2" (old), \
+ "r" (new)); \
+ } while (0)
+
+/* Redefinitions to make templating easy */
+#define wait_queue_head_t long
+#define agp_memory void
+#define jiffies ticks
+
+ /* Macros to make printf easier */
+#define DRM_ERROR(fmt, arg...) \
+ printf("error: " "[" DRM_NAME ":" __FUNCTION__ "] *ERROR* " fmt , ##arg)
+#define DRM_MEM_ERROR(area, fmt, arg...) \
+ printf("error: " "[" DRM_NAME ":" __FUNCTION__ ":%s] *ERROR* " fmt , \
+ DRM(mem_stats)[area].name , ##arg)
+#define DRM_INFO(fmt, arg...) printf("info: " "[" DRM_NAME "] " fmt , ##arg)
+
+#if DRM_DEBUG_CODE
+#define DRM_DEBUG(fmt, arg...) \
+ do { \
+ if (DRM(flags) & DRM_FLAG_DEBUG) \
+ printf("[" DRM_NAME ":" __FUNCTION__ "] " fmt , \
+ ##arg); \
+ } while (0)
+#else
+#define DRM_DEBUG(fmt, arg...) do { } while (0)
+#endif
+
+#define DRM_PROC_LIMIT (PAGE_SIZE-80)
+
+#if (__FreeBSD_version >= 500000) || ((__FreeBSD_version < 500000) && (__FreeBSD_version >= 410002))
+#define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
+#else
+#define DRM_SYSCTL_HANDLER_ARGS SYSCTL_HANDLER_ARGS
+#endif
+
+#define DRM_SYSCTL_PRINT(fmt, arg...) \
+ snprintf(buf, sizeof(buf), fmt, ##arg); \
+ error = SYSCTL_OUT(req, buf, strlen(buf)); \
+ if (error) return error;
+
+#define DRM_SYSCTL_PRINT_RET(ret, fmt, arg...) \
+ snprintf(buf, sizeof(buf), fmt, ##arg); \
+ error = SYSCTL_OUT(req, buf, strlen(buf)); \
+ if (error) { ret; return error; }
+
+
+#define DRM_FIND_MAP(dest, o) \
+ do { \
+ drm_map_list_entry_t *listentry; \
+ TAILQ_FOREACH(listentry, dev->maplist, link) { \
+ if ( listentry->map->offset == o ) { \
+ dest = listentry->map; \
+ break; \
+ } \
+ } \
+ } while (0)
+
+
+/* Internal functions */
+
+/* drm_drv.h */
+extern d_ioctl_t DRM(ioctl);
+extern d_ioctl_t DRM(lock);
+extern d_ioctl_t DRM(unlock);
+extern d_open_t DRM(open);
+extern d_close_t DRM(close);
+extern d_read_t DRM(read);
+extern d_write_t DRM(write);
+extern d_poll_t DRM(poll);
+extern d_mmap_t DRM(mmap);
+extern int DRM(open_helper)(dev_t kdev, int flags, int fmt,
+ DRM_OS_STRUCTPROC *p, drm_device_t *dev);
+extern drm_file_t *DRM(find_file_by_proc)(drm_device_t *dev,
+ DRM_OS_STRUCTPROC *p);
+
+/* Misc. IOCTL support (drm_ioctl.h) */
+extern d_ioctl_t DRM(irq_busid);
+extern d_ioctl_t DRM(getunique);
+extern d_ioctl_t DRM(setunique);
+extern d_ioctl_t DRM(getmap);
+extern d_ioctl_t DRM(getclient);
+extern d_ioctl_t DRM(getstats);
+
+/* Context IOCTL support (drm_context.h) */
+extern d_ioctl_t DRM(resctx);
+extern d_ioctl_t DRM(addctx);
+extern d_ioctl_t DRM(modctx);
+extern d_ioctl_t DRM(getctx);
+extern d_ioctl_t DRM(switchctx);
+extern d_ioctl_t DRM(newctx);
+extern d_ioctl_t DRM(rmctx);
+extern d_ioctl_t DRM(setsareactx);
+extern d_ioctl_t DRM(getsareactx);
+
+/* Drawable IOCTL support (drm_drawable.h) */
+extern d_ioctl_t DRM(adddraw);
+extern d_ioctl_t DRM(rmdraw);
+
+/* Authentication IOCTL support (drm_auth.h) */
+extern d_ioctl_t DRM(getmagic);
+extern d_ioctl_t DRM(authmagic);
+
+/* Locking IOCTL support (drm_lock.h) */
+extern d_ioctl_t DRM(block);
+extern d_ioctl_t DRM(unblock);
+extern d_ioctl_t DRM(finish);
+
+/* Buffer management support (drm_bufs.h) */
+extern d_ioctl_t DRM(addmap);
+extern d_ioctl_t DRM(rmmap);
+#if __HAVE_DMA
+extern d_ioctl_t DRM(addbufs_agp);
+extern d_ioctl_t DRM(addbufs_pci);
+extern d_ioctl_t DRM(addbufs_sg);
+extern d_ioctl_t DRM(addbufs);
+extern d_ioctl_t DRM(infobufs);
+extern d_ioctl_t DRM(markbufs);
+extern d_ioctl_t DRM(freebufs);
+extern d_ioctl_t DRM(mapbufs);
+#endif
+
+/* Memory management support (drm_memory.h) */
+extern int DRM(mem_info) DRM_SYSCTL_HANDLER_ARGS;
+
+/* DMA support (drm_dma.h) */
+#if __HAVE_DMA_IRQ
+extern d_ioctl_t DRM(control);
+#endif
+
+/* AGP/GART support (drm_agpsupport.h) */
+#if __REALLY_HAVE_AGP
+extern d_ioctl_t DRM(agp_acquire);
+extern d_ioctl_t DRM(agp_release);
+extern d_ioctl_t DRM(agp_enable);
+extern d_ioctl_t DRM(agp_info);
+extern d_ioctl_t DRM(agp_alloc);
+extern d_ioctl_t DRM(agp_free);
+extern d_ioctl_t DRM(agp_unbind);
+extern d_ioctl_t DRM(agp_bind);
+#endif
+
+/* Scatter Gather Support (drm_scatter.h) */
+#if __HAVE_SG
+extern d_ioctl_t DRM(sg_alloc);
+extern d_ioctl_t DRM(sg_free);
+#endif
+
+/* SysCtl Support (drm_sysctl.h) */
+extern int DRM(sysctl_init)(drm_device_t *dev);
+extern int DRM(sysctl_cleanup)(drm_device_t *dev);
diff --git a/bsd/drm_sysctl.h b/bsd/drm_sysctl.h
new file mode 100644
index 00000000..02e4b28d
--- /dev/null
+++ b/bsd/drm_sysctl.h
@@ -0,0 +1,523 @@
+SYSCTL_NODE(_hw, OID_AUTO, dri, CTLFLAG_RW, 0, "DRI Graphics");
+
+static int DRM(name_info)DRM_SYSCTL_HANDLER_ARGS;
+static int DRM(vm_info)DRM_SYSCTL_HANDLER_ARGS;
+static int DRM(clients_info)DRM_SYSCTL_HANDLER_ARGS;
+static int DRM(queues_info)DRM_SYSCTL_HANDLER_ARGS;
+static int DRM(bufs_info)DRM_SYSCTL_HANDLER_ARGS;
+#if DRM_DEBUG_CODExx
+static int DRM(vma_info)DRM_SYSCTL_HANDLER_ARGS;
+#endif
+#if DRM_DMA_HISTOGRAM
+static int DRM(histo_info)DRM_SYSCTL_HANDLER_ARGS;
+#endif
+
+struct DRM(sysctl_list) {
+ const char *name;
+ int (*f) DRM_SYSCTL_HANDLER_ARGS;
+} DRM(sysctl_list)[] = {
+ { "name", DRM(name_info) },
+ { "mem", DRM(mem_info) },
+ { "vm", DRM(vm_info) },
+ { "clients", DRM(clients_info) },
+ { "queues", DRM(queues_info) },
+ { "bufs", DRM(bufs_info) },
+#if DRM_DEBUG_CODExx
+ { "vma", DRM(vma_info) },
+#endif
+#if DRM_DMA_HISTOGRAM
+ { "histo", drm_histo_info) },
+#endif
+};
+#define DRM_SYSCTL_ENTRIES (sizeof(DRM(sysctl_list))/sizeof(DRM(sysctl_list)[0]))
+
+struct drm_sysctl_info {
+ struct sysctl_oid oids[DRM_SYSCTL_ENTRIES + 1];
+ struct sysctl_oid_list list;
+ char name[2];
+};
+
+int DRM(sysctl_init)(drm_device_t *dev)
+{
+ struct drm_sysctl_info *info;
+ struct sysctl_oid *oid;
+ struct sysctl_oid *top;
+ int i;
+
+ /* Find the next free slot under hw.graphics */
+ i = 0;
+ SLIST_FOREACH(oid, &sysctl__hw_dri_children, oid_link) {
+ if (i <= oid->oid_arg2)
+ i = oid->oid_arg2 + 1;
+ }
+
+ info = DRM(alloc)(sizeof *info, DRM_MEM_DRIVER);
+ dev->sysctl = info;
+
+ /* Construct the node under hw.graphics */
+ info->name[0] = '0' + i;
+ info->name[1] = 0;
+ oid = &info->oids[DRM_SYSCTL_ENTRIES];
+ bzero(oid, sizeof(*oid));
+ oid->oid_parent = &sysctl__hw_dri_children;
+ oid->oid_number = OID_AUTO;
+ oid->oid_kind = CTLTYPE_NODE | CTLFLAG_RW;
+ oid->oid_arg1 = &info->list;
+ oid->oid_arg2 = i;
+ oid->oid_name = info->name;
+ oid->oid_handler = 0;
+ oid->oid_fmt = "N";
+ SLIST_INIT(&info->list);
+ sysctl_register_oid(oid);
+ top = oid;
+
+ for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
+ oid = &info->oids[i];
+ bzero(oid, sizeof(*oid));
+ oid->oid_parent = top->oid_arg1;
+ oid->oid_number = OID_AUTO;
+ oid->oid_kind = CTLTYPE_INT | CTLFLAG_RD;
+ oid->oid_arg1 = dev;
+ oid->oid_arg2 = 0;
+ oid->oid_name = DRM(sysctl_list)[i].name;
+ oid->oid_handler = DRM(sysctl_list[)i].f;
+ oid->oid_fmt = "A";
+ sysctl_register_oid(oid);
+ }
+
+ return 0;
+}
+
+int DRM(sysctl_cleanup)(drm_device_t *dev)
+{
+ int i;
+
+ DRM_DEBUG("dev->sysctl=%p\n", dev->sysctl);
+ for (i = 0; i < DRM_SYSCTL_ENTRIES + 1; i++)
+ sysctl_unregister_oid(&dev->sysctl->oids[i]);
+
+ DRM(free)(dev->sysctl, sizeof *dev->sysctl, DRM_MEM_DRIVER);
+ dev->sysctl = NULL;
+
+ return 0;
+}
+
+static int DRM(name_info)DRM_SYSCTL_HANDLER_ARGS
+{
+ drm_device_t *dev = arg1;
+ char buf[128];
+ int error;
+
+ if (dev->unique) {
+ DRM_SYSCTL_PRINT("%s 0x%x %s\n",
+ dev->name, dev2udev(dev->devnode), dev->unique);
+ } else {
+ DRM_SYSCTL_PRINT("%s 0x%x\n", dev->name, dev2udev(dev->devnode));
+ }
+
+ SYSCTL_OUT(req, "", 1);
+
+ return 0;
+}
+
+static int DRM(_vm_info)DRM_SYSCTL_HANDLER_ARGS
+{
+ drm_device_t *dev = arg1;
+ drm_map_t *map;
+ drm_map_list_entry_t *listentry;
+ const char *types[] = { "FB", "REG", "SHM" };
+ const char *type;
+ int i=0;
+ char buf[128];
+ int error;
+
+ DRM_SYSCTL_PRINT("slot offset size type flags "
+ "address mtrr\n\n");
+ error = SYSCTL_OUT(req, buf, strlen(buf));
+ if (error) return error;
+
+ if (dev->maplist != NULL) {
+ TAILQ_FOREACH(listentry, dev->maplist, link) {
+ map = listentry->map;
+ if (map->type < 0 || map->type > 2) type = "??";
+ else type = types[map->type];
+ DRM_SYSCTL_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx ",
+ i,
+ map->offset,
+ map->size,
+ type,
+ map->flags,
+ (unsigned long)map->handle);
+ if (map->mtrr < 0) {
+ DRM_SYSCTL_PRINT("none\n");
+ } else {
+ DRM_SYSCTL_PRINT("%4d\n", map->mtrr);
+ }
+ i++;
+ }
+ }
+ SYSCTL_OUT(req, "", 1);
+
+ return 0;
+}
+
+static int DRM(vm_info)DRM_SYSCTL_HANDLER_ARGS
+{
+ drm_device_t *dev = arg1;
+ int ret;
+
+ DRM_OS_LOCK;
+ ret = DRM(_vm_info)(oidp, arg1, arg2, req);
+ DRM_OS_UNLOCK;
+
+ return ret;
+}
+
+
+static int DRM(_queues_info)DRM_SYSCTL_HANDLER_ARGS
+{
+ drm_device_t *dev = arg1;
+ int i;
+ drm_queue_t *q;
+ char buf[128];
+ int error;
+
+ DRM_SYSCTL_PRINT(" ctx/flags use fin"
+ " blk/rw/rwf wait flushed queued"
+ " locks\n\n");
+ for (i = 0; i < dev->queue_count; i++) {
+ q = dev->queuelist[i];
+ atomic_inc(&q->use_count);
+ DRM_SYSCTL_PRINT_RET(atomic_dec(&q->use_count),
+ "%5d/0x%03x %5ld %5ld"
+ " %5ld/%c%c/%c%c%c %5d %10ld %10ld %10ld\n",
+ i,
+ q->flags,
+ atomic_read(&q->use_count),
+ atomic_read(&q->finalization),
+ atomic_read(&q->block_count),
+ atomic_read(&q->block_read) ? 'r' : '-',
+ atomic_read(&q->block_write) ? 'w' : '-',
+ q->read_queue ? 'r':'-',
+ q->write_queue ? 'w':'-',
+ q->flush_queue ? 'f':'-',
+ DRM_BUFCOUNT(&q->waitlist),
+ atomic_read(&q->total_flushed),
+ atomic_read(&q->total_queued),
+ atomic_read(&q->total_locks));
+ atomic_dec(&q->use_count);
+ }
+
+ SYSCTL_OUT(req, "", 1);
+ return 0;
+}
+
+static int DRM(queues_info) DRM_SYSCTL_HANDLER_ARGS
+{
+ drm_device_t *dev = arg1;
+ int ret;
+
+ DRM_OS_LOCK;
+ ret = DRM(_queues_info)(oidp, arg1, arg2, req);
+ DRM_OS_UNLOCK;
+ return ret;
+}
+
+/* drm_bufs_info is called whenever a process reads
+ hw.dri.0.bufs. */
+
+static int DRM(_bufs_info) DRM_SYSCTL_HANDLER_ARGS
+{
+ drm_device_t *dev = arg1;
+ drm_device_dma_t *dma = dev->dma;
+ int i;
+ char buf[128];
+ int error;
+
+ if (!dma) return 0;
+ DRM_SYSCTL_PRINT(" o size count free segs pages kB\n\n");
+ for (i = 0; i <= DRM_MAX_ORDER; i++) {
+ if (dma->bufs[i].buf_count)
+ DRM_SYSCTL_PRINT("%2d %8d %5d %5ld %5d %5d %5d\n",
+ i,
+ dma->bufs[i].buf_size,
+ dma->bufs[i].buf_count,
+ atomic_read(&dma->bufs[i]
+ .freelist.count),
+ dma->bufs[i].seg_count,
+ dma->bufs[i].seg_count
+ *(1 << dma->bufs[i].page_order),
+ (dma->bufs[i].seg_count
+ * (1 << dma->bufs[i].page_order))
+ * PAGE_SIZE / 1024);
+ }
+ DRM_SYSCTL_PRINT("\n");
+ for (i = 0; i < dma->buf_count; i++) {
+ if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
+ DRM_SYSCTL_PRINT(" %d", dma->buflist[i]->list);
+ }
+ DRM_SYSCTL_PRINT("\n");
+
+ SYSCTL_OUT(req, "", 1);
+ return 0;
+}
+
+static int DRM(bufs_info) DRM_SYSCTL_HANDLER_ARGS
+{
+ drm_device_t *dev = arg1;
+ int ret;
+
+ DRM_OS_LOCK;
+ ret = DRM(_bufs_info)(oidp, arg1, arg2, req);
+ DRM_OS_UNLOCK;
+ return ret;
+}
+
+
+static int DRM(_clients_info) DRM_SYSCTL_HANDLER_ARGS
+{
+ drm_device_t *dev = arg1;
+ drm_file_t *priv;
+ char buf[128];
+ int error;
+
+ DRM_SYSCTL_PRINT("a dev pid uid magic ioctls\n\n");
+ TAILQ_FOREACH(priv, &dev->files, link) {
+ DRM_SYSCTL_PRINT("%c %3d %5d %5d %10u %10lu\n",
+ priv->authenticated ? 'y' : 'n',
+ priv->minor,
+ priv->pid,
+ priv->uid,
+ priv->magic,
+ priv->ioctl_count);
+ }
+
+ SYSCTL_OUT(req, "", 1);
+ return 0;
+}
+
+static int DRM(clients_info)DRM_SYSCTL_HANDLER_ARGS
+{
+ drm_device_t *dev = arg1;
+ int ret;
+
+ DRM_OS_LOCK;
+ ret = DRM(_clients_info)(oidp, arg1, arg2, req);
+ DRM_OS_UNLOCK;
+ return ret;
+}
+
+#if DRM_DEBUG_CODExx
+
+static int DRM(_vma_info)DRM_SYSCTL_HANDLER_ARGS
+{
+ drm_device_t *dev = arg1;
+ drm_vma_entry_t *pt;
+ pgd_t *pgd;
+ pmd_t *pmd;
+ pte_t *pte;
+ unsigned long i;
+ struct vm_area_struct *vma;
+ unsigned long address;
+#if defined(__i386__)
+ unsigned int pgprot;
+#endif
+ char buf[128];
+ int error;
+
+ DRM_SYSCTL_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
+ atomic_read(&dev->vma_count),
+ high_memory, virt_to_phys(high_memory));
+ for (pt = dev->vmalist; pt; pt = pt->next) {
+ if (!(vma = pt->vma)) continue;
+ DRM_SYSCTL_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx",
+ pt->pid,
+ vma->vm_start,
+ vma->vm_end,
+ vma->vm_flags & VM_READ ? 'r' : '-',
+ vma->vm_flags & VM_WRITE ? 'w' : '-',
+ vma->vm_flags & VM_EXEC ? 'x' : '-',
+ vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
+ vma->vm_flags & VM_LOCKED ? 'l' : '-',
+ vma->vm_flags & VM_IO ? 'i' : '-',
+ vma->vm_offset );
+#if defined(__i386__)
+ pgprot = pgprot_val(vma->vm_page_prot);
+ DRM_SYSCTL_PRINT(" %c%c%c%c%c%c%c%c%c",
+ pgprot & _PAGE_PRESENT ? 'p' : '-',
+ pgprot & _PAGE_RW ? 'w' : 'r',
+ pgprot & _PAGE_USER ? 'u' : 's',
+ pgprot & _PAGE_PWT ? 't' : 'b',
+ pgprot & _PAGE_PCD ? 'u' : 'c',
+ pgprot & _PAGE_ACCESSED ? 'a' : '-',
+ pgprot & _PAGE_DIRTY ? 'd' : '-',
+ pgprot & _PAGE_4M ? 'm' : 'k',
+ pgprot & _PAGE_GLOBAL ? 'g' : 'l' );
+#endif
+ DRM_SYSCTL_PRINT("\n");
+ for (i = vma->vm_start; i < vma->vm_end; i += PAGE_SIZE) {
+ pgd = pgd_offset(vma->vm_mm, i);
+ pmd = pmd_offset(pgd, i);
+ pte = pte_offset(pmd, i);
+ if (pte_present(*pte)) {
+ address = __pa(pte_page(*pte))
+ + (i & (PAGE_SIZE-1));
+ DRM_SYSCTL_PRINT(" 0x%08lx -> 0x%08lx"
+ " %c%c%c%c%c\n",
+ i,
+ address,
+ pte_read(*pte) ? 'r' : '-',
+ pte_write(*pte) ? 'w' : '-',
+ pte_exec(*pte) ? 'x' : '-',
+ pte_dirty(*pte) ? 'd' : '-',
+ pte_young(*pte) ? 'a' : '-' );
+ } else {
+ DRM_SYSCTL_PRINT(" 0x%08lx\n", i);
+ }
+ }
+ }
+
+ SYSCTL_OUT(req, "", 1);
+ return 0;
+}
+
+static int DRM(vma_info)DRM_SYSCTL_HANDLER_ARGS
+{
+ drm_device_t *dev = arg1;
+ int ret;
+
+ DRM_OS_LOCK;
+ ret = DRM(_vma_info)(oidp, arg1, arg2, req);
+ DRM_OS_UNLOCK;
+ return ret;
+}
+#endif
+
+
+#if DRM_DMA_HISTOGRAM
+static int DRM(_histo_info)DRM_SYSCTL_HANDLER_ARGS
+{
+ drm_device_t *dev = arg1;
+ drm_device_dma_t *dma = dev->dma;
+ int i;
+ unsigned long slot_value = DRM_DMA_HISTOGRAM_INITIAL;
+ unsigned long prev_value = 0;
+ drm_buf_t *buffer;
+ char buf[128];
+ int error;
+
+ DRM_SYSCTL_PRINT("general statistics:\n");
+ DRM_SYSCTL_PRINT("total %10u\n", atomic_read(&dev->histo.total));
+ DRM_SYSCTL_PRINT("open %10u\n", atomic_read(&dev->total_open));
+ DRM_SYSCTL_PRINT("close %10u\n", atomic_read(&dev->total_close));
+ DRM_SYSCTL_PRINT("ioctl %10u\n", atomic_read(&dev->total_ioctl));
+ DRM_SYSCTL_PRINT("irq %10u\n", atomic_read(&dev->total_irq));
+ DRM_SYSCTL_PRINT("ctx %10u\n", atomic_read(&dev->total_ctx));
+
+ DRM_SYSCTL_PRINT("\nlock statistics:\n");
+ DRM_SYSCTL_PRINT("locks %10u\n", atomic_read(&dev->total_locks));
+ DRM_SYSCTL_PRINT("unlocks %10u\n", atomic_read(&dev->total_unlocks));
+ DRM_SYSCTL_PRINT("contends %10u\n", atomic_read(&dev->total_contends));
+ DRM_SYSCTL_PRINT("sleeps %10u\n", atomic_read(&dev->total_sleeps));
+
+
+ if (dma) {
+ DRM_SYSCTL_PRINT("\ndma statistics:\n");
+ DRM_SYSCTL_PRINT("prio %10u\n",
+ atomic_read(&dma->total_prio));
+ DRM_SYSCTL_PRINT("bytes %10u\n",
+ atomic_read(&dma->total_bytes));
+ DRM_SYSCTL_PRINT("dmas %10u\n",
+ atomic_read(&dma->total_dmas));
+ DRM_SYSCTL_PRINT("missed:\n");
+ DRM_SYSCTL_PRINT(" dma %10u\n",
+ atomic_read(&dma->total_missed_dma));
+ DRM_SYSCTL_PRINT(" lock %10u\n",
+ atomic_read(&dma->total_missed_lock));
+ DRM_SYSCTL_PRINT(" free %10u\n",
+ atomic_read(&dma->total_missed_free));
+ DRM_SYSCTL_PRINT(" sched %10u\n",
+ atomic_read(&dma->total_missed_sched));
+ DRM_SYSCTL_PRINT("tried %10u\n",
+ atomic_read(&dma->total_tried));
+ DRM_SYSCTL_PRINT("hit %10u\n",
+ atomic_read(&dma->total_hit));
+ DRM_SYSCTL_PRINT("lost %10u\n",
+ atomic_read(&dma->total_lost));
+
+ buffer = dma->next_buffer;
+ if (buffer) {
+ DRM_SYSCTL_PRINT("next_buffer %7d\n", buffer->idx);
+ } else {
+ DRM_SYSCTL_PRINT("next_buffer none\n");
+ }
+ buffer = dma->this_buffer;
+ if (buffer) {
+ DRM_SYSCTL_PRINT("this_buffer %7d\n", buffer->idx);
+ } else {
+ DRM_SYSCTL_PRINT("this_buffer none\n");
+ }
+ }
+
+
+ DRM_SYSCTL_PRINT("\nvalues:\n");
+ if (dev->lock.hw_lock) {
+ DRM_SYSCTL_PRINT("lock 0x%08x\n",
+ dev->lock.hw_lock->lock);
+ } else {
+ DRM_SYSCTL_PRINT("lock none\n");
+ }
+ DRM_SYSCTL_PRINT("context_flag 0x%08x\n", dev->context_flag);
+ DRM_SYSCTL_PRINT("interrupt_flag 0x%08x\n", dev->interrupt_flag);
+ DRM_SYSCTL_PRINT("dma_flag 0x%08x\n", dev->dma_flag);
+
+ DRM_SYSCTL_PRINT("queue_count %10d\n", dev->queue_count);
+ DRM_SYSCTL_PRINT("last_context %10d\n", dev->last_context);
+ DRM_SYSCTL_PRINT("last_switch %10u\n", dev->last_switch);
+ DRM_SYSCTL_PRINT("last_checked %10d\n", dev->last_checked);
+
+
+ DRM_SYSCTL_PRINT("\n q2d d2c c2f"
+ " q2c q2f dma sch"
+ " ctx lacq lhld\n\n");
+ for (i = 0; i < DRM_DMA_HISTOGRAM_SLOTS; i++) {
+ DRM_SYSCTL_PRINT("%s %10lu %10u %10u %10u %10u %10u"
+ " %10u %10u %10u %10u %10u\n",
+ i == DRM_DMA_HISTOGRAM_SLOTS - 1 ? ">=" : "< ",
+ i == DRM_DMA_HISTOGRAM_SLOTS - 1
+ ? prev_value : slot_value ,
+
+ atomic_read(&dev->histo
+ .queued_to_dispatched[i]),
+ atomic_read(&dev->histo
+ .dispatched_to_completed[i]),
+ atomic_read(&dev->histo
+ .completed_to_freed[i]),
+
+ atomic_read(&dev->histo
+ .queued_to_completed[i]),
+ atomic_read(&dev->histo
+ .queued_to_freed[i]),
+ atomic_read(&dev->histo.dma[i]),
+ atomic_read(&dev->histo.schedule[i]),
+ atomic_read(&dev->histo.ctx[i]),
+ atomic_read(&dev->histo.lacq[i]),
+ atomic_read(&dev->histo.lhld[i]));
+ prev_value = slot_value;
+ slot_value = DRM_DMA_HISTOGRAM_NEXT(slot_value);
+ }
+ SYSCTL_OUT(req, "", 1);
+ return 0;
+}
+
+static int DRM(histo_info)DRM_SYSCTL_HANDLER_ARGS
+{
+ drm_device_t *dev = arg1;
+ int ret;
+
+ DRM_OS_LOCK;
+ ret = _drm_histo_info(oidp, arg1, arg2, req);
+ DRM_OS_UNLOCK;
+ return ret;
+}
+#endif
diff --git a/bsd/drm_vm.h b/bsd/drm_vm.h
new file mode 100644
index 00000000..a06fb448
--- /dev/null
+++ b/bsd/drm_vm.h
@@ -0,0 +1,81 @@
+#include <vm/vm.h>
+#include <vm/pmap.h>
+
+static int DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, int prot)
+{
+ drm_device_t *dev = kdev->si_drv1;
+ drm_device_dma_t *dma = dev->dma;
+ unsigned long physical;
+ unsigned long page;
+
+ if (!dma) return -1; /* Error */
+ if (!dma->pagelist) return -1; /* Nothing allocated */
+
+ page = offset >> PAGE_SHIFT;
+ physical = dma->pagelist[page];
+
+ DRM_DEBUG("0x%08x (page %lu) => 0x%08lx\n", offset, page, physical);
+ return atop(physical);
+}
+
+int DRM(mmap)(dev_t kdev, vm_offset_t offset, int prot)
+{
+ drm_device_t *dev = kdev->si_drv1;
+ drm_map_t *map = NULL;
+ drm_map_list_entry_t *listentry=NULL;
+ /*drm_file_t *priv;*/
+
+/* DRM_DEBUG("offset = 0x%x\n", offset);*/
+
+ /*XXX Fixme */
+ /*priv = DRM(find_file_by_proc)(dev, p);
+ if (!priv) {
+ DRM_DEBUG("can't find authenticator\n");
+ return EINVAL;
+ }
+
+ if (!priv->authenticated) DRM_OS_RETURN(EACCES);*/
+
+ if (dev->dma
+ && offset >= 0
+ && offset < ptoa(dev->dma->page_count))
+ return DRM(dma_mmap)(kdev, offset, prot);
+
+ /* A sequential search of a linked list is
+ fine here because: 1) there will only be
+ about 5-10 entries in the list and, 2) a
+ DRI client only has to do this mapping
+ once, so it doesn't have to be optimized
+ for performance, even if the list was a
+ bit longer. */
+ TAILQ_FOREACH(listentry, dev->maplist, link) {
+ map = listentry->map;
+/* DRM_DEBUG("considering 0x%x..0x%x\n", map->offset, map->offset + map->size - 1);*/
+ if (offset >= map->offset
+ && offset < map->offset + map->size) break;
+ }
+
+ if (!listentry) {
+ DRM_DEBUG("can't find map\n");
+ return -1;
+ }
+ if (((map->flags&_DRM_RESTRICTED) && suser(curproc))) {
+ DRM_DEBUG("restricted map\n");
+ return -1;
+ }
+
+ switch (map->type) {
+ case _DRM_FRAME_BUFFER:
+ case _DRM_REGISTERS:
+ case _DRM_AGP:
+ return atop(offset);
+ case _DRM_SHM:
+ return atop(vtophys(offset));
+ default:
+ return -1; /* This should never happen. */
+ }
+ DRM_DEBUG("bailing out\n");
+
+ return -1;
+}
+
diff --git a/bsd/gamma/gamma_dma.c b/bsd/gamma/gamma_dma.c
index 07d8248b..fd0da710 100644
--- a/bsd/gamma/gamma_dma.c
+++ b/bsd/gamma/gamma_dma.c
@@ -1,4 +1,4 @@
-/* gamma_dma.c -- DMA support for GMX 2000 -*- c -*-
+/* gamma_dma.c -- DMA support for GMX 2000 -*- linux-c -*-
* Created: Fri Mar 19 14:30:16 1999 by faith@precisioninsight.com
*
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
@@ -11,11 +11,11 @@
* 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
@@ -23,77 +23,36 @@
* 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>
*
*/
-#define __NO_VERSION__
+
+
+#include "gamma.h"
#include "drmP.h"
#include "gamma_drv.h"
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-#include <vm/vm.h>
-#include <vm/pmap.h>
-
-/* WARNING!!! MAGIC NUMBER!!! The number of regions already added to the
- kernel must be specified here. Currently, the number is 2. This must
- match the order the X server uses for instantiating register regions ,
- or must be passed in a new ioctl. */
-#define GAMMA_REG(reg) \
- (2 \
- + ((reg < 0x1000) \
- ? 0 \
- : ((reg < 0x10000) ? 1 : ((reg < 0x11000) ? 2 : 3))))
-
-#define GAMMA_OFF(reg) \
- ((reg < 0x1000) \
- ? reg \
- : ((reg < 0x10000) \
- ? (reg - 0x1000) \
- : ((reg < 0x11000) \
- ? (reg - 0x10000) \
- : (reg - 0x11000))))
-
-#define GAMMA_BASE(reg) ((unsigned long)dev->maplist[GAMMA_REG(reg)]->handle)
-#define GAMMA_ADDR(reg) (GAMMA_BASE(reg) + GAMMA_OFF(reg))
-#define GAMMA_DEREF(reg) *(__volatile__ int *)GAMMA_ADDR(reg)
-#define GAMMA_READ(reg) GAMMA_DEREF(reg)
-#define GAMMA_WRITE(reg,val) do { GAMMA_DEREF(reg) = val; } while (0)
-
-#define GAMMA_BROADCASTMASK 0x9378
-#define GAMMA_COMMANDINTENABLE 0x0c48
-#define GAMMA_DMAADDRESS 0x0028
-#define GAMMA_DMACOUNT 0x0030
-#define GAMMA_FILTERMODE 0x8c00
-#define GAMMA_GCOMMANDINTFLAGS 0x0c50
-#define GAMMA_GCOMMANDMODE 0x0c40
-#define GAMMA_GCOMMANDSTATUS 0x0c60
-#define GAMMA_GDELAYTIMER 0x0c38
-#define GAMMA_GDMACONTROL 0x0060
-#define GAMMA_GINTENABLE 0x0808
-#define GAMMA_GINTFLAGS 0x0810
-#define GAMMA_INFIFOSPACE 0x0018
-#define GAMMA_OUTFIFOWORDS 0x0020
-#define GAMMA_OUTPUTFIFO 0x2000
-#define GAMMA_SYNC 0x8c40
-#define GAMMA_SYNC_TAG 0x0188
-
-static __inline void gamma_dma_dispatch(drm_device_t *dev,
- vm_offset_t address,
- vm_size_t length)
+
+static __inline__ void gamma_dma_dispatch(drm_device_t *dev, unsigned long address,
+ unsigned long length)
{
- GAMMA_WRITE(GAMMA_DMAADDRESS, vtophys(address));
+ drm_gamma_private_t *dev_priv =
+ (drm_gamma_private_t *)dev->dev_private;
+
+ GAMMA_WRITE(GAMMA_DMAADDRESS, DRM_OS_VTOPHYS((void *)address));
while (GAMMA_READ(GAMMA_GCOMMANDSTATUS) != 4)
;
GAMMA_WRITE(GAMMA_DMACOUNT, length / 4);
}
-static __inline void gamma_dma_quiescent_single(drm_device_t *dev)
+void gamma_dma_quiescent_single(drm_device_t *dev)
{
+ drm_gamma_private_t *dev_priv =
+ (drm_gamma_private_t *)dev->dev_private;
+
while (GAMMA_READ(GAMMA_DMACOUNT))
;
while (GAMMA_READ(GAMMA_INFIFOSPACE) < 3)
@@ -101,15 +60,18 @@ static __inline void gamma_dma_quiescent_single(drm_device_t *dev)
GAMMA_WRITE(GAMMA_FILTERMODE, 1 << 10);
GAMMA_WRITE(GAMMA_SYNC, 0);
-
+
do {
while (!GAMMA_READ(GAMMA_OUTFIFOWORDS))
;
} while (GAMMA_READ(GAMMA_OUTPUTFIFO) != GAMMA_SYNC_TAG);
}
-static __inline void gamma_dma_quiescent_dual(drm_device_t *dev)
+void gamma_dma_quiescent_dual(drm_device_t *dev)
{
+ drm_gamma_private_t *dev_priv =
+ (drm_gamma_private_t *)dev->dev_private;
+
while (GAMMA_READ(GAMMA_DMACOUNT))
;
while (GAMMA_READ(GAMMA_INFIFOSPACE) < 3)
@@ -119,7 +81,7 @@ static __inline void gamma_dma_quiescent_dual(drm_device_t *dev)
GAMMA_WRITE(GAMMA_FILTERMODE, 1 << 10);
GAMMA_WRITE(GAMMA_SYNC, 0);
-
+
/* Read from first MX */
do {
while (!GAMMA_READ(GAMMA_OUTFIFOWORDS))
@@ -133,43 +95,43 @@ static __inline void gamma_dma_quiescent_dual(drm_device_t *dev)
} while (GAMMA_READ(GAMMA_OUTPUTFIFO + 0x10000) != GAMMA_SYNC_TAG);
}
-static __inline void gamma_dma_ready(drm_device_t *dev)
+void gamma_dma_ready(drm_device_t *dev)
{
+ drm_gamma_private_t *dev_priv =
+ (drm_gamma_private_t *)dev->dev_private;
+
while (GAMMA_READ(GAMMA_DMACOUNT))
;
}
-static __inline int gamma_dma_is_ready(drm_device_t *dev)
+static __inline__ int gamma_dma_is_ready(drm_device_t *dev)
{
+ drm_gamma_private_t *dev_priv =
+ (drm_gamma_private_t *)dev->dev_private;
+
return !GAMMA_READ(GAMMA_DMACOUNT);
}
-static void gamma_dma_service(void *arg)
+void gamma_dma_service( DRM_OS_IRQ_ARGS)
{
- drm_device_t *dev = (drm_device_t *)arg;
- drm_device_dma_t *dma = dev->dma;
-
- atomic_inc(&dev->total_irq);
+ drm_device_t *dev = (drm_device_t *)device;
+ drm_device_dma_t *dma = dev->dma;
+ drm_gamma_private_t *dev_priv =
+ (drm_gamma_private_t *)dev->dev_private;
+
+ atomic_inc(&dev->counts[6]); /* _DRM_STAT_IRQ */
GAMMA_WRITE(GAMMA_GDELAYTIMER, 0xc350/2); /* 0x05S */
GAMMA_WRITE(GAMMA_GCOMMANDINTFLAGS, 8);
GAMMA_WRITE(GAMMA_GINTFLAGS, 0x2001);
if (gamma_dma_is_ready(dev)) {
/* Free previous buffer */
- if (test_and_set_bit(0, &dev->dma_flag)) {
- atomic_inc(&dma->total_missed_free);
- return;
- }
+ if (test_and_set_bit(0, &dev->dma_flag)) return;
if (dma->this_buffer) {
- drm_free_buffer(dev, dma->this_buffer);
+ gamma_free_buffer(dev, dma->this_buffer);
dma->this_buffer = NULL;
}
clear_bit(0, &dev->dma_flag);
-#if 0
- /* Dispatch new buffer */
- queue_task(&dev->tq, &tq_immediate);
- mark_bh(IMMEDIATE_BH);
-#endif
}
}
@@ -182,22 +144,19 @@ static int gamma_do_dma(drm_device_t *dev, int locked)
int retcode = 0;
drm_device_dma_t *dma = dev->dma;
#if DRM_DMA_HISTOGRAM
- struct timespec dma_start, dma_stop;
+ cycles_t dma_start, dma_stop;
#endif
- if (test_and_set_bit(0, &dev->dma_flag)) {
- atomic_inc(&dma->total_missed_dma);
- return EBUSY;
- }
-
+ if (test_and_set_bit(0, &dev->dma_flag)) DRM_OS_RETURN( EBUSY );
+
#if DRM_DMA_HISTOGRAM
- getnanotime(&dma_start);
+ dma_start = get_cycles();
#endif
if (!dma->next_buffer) {
DRM_ERROR("No next_buffer\n");
clear_bit(0, &dev->dma_flag);
- return EINVAL;
+ DRM_OS_RETURN( EINVAL );
}
buf = dma->next_buffer;
@@ -208,23 +167,23 @@ static int gamma_do_dma(drm_device_t *dev, int locked)
buf->context, buf->idx, length);
if (buf->list == DRM_LIST_RECLAIM) {
- drm_clear_next_buffer(dev);
- drm_free_buffer(dev, buf);
+ gamma_clear_next_buffer(dev);
+ gamma_free_buffer(dev, buf);
clear_bit(0, &dev->dma_flag);
- return EINVAL;
+ DRM_OS_RETURN( EINVAL );
}
if (!length) {
DRM_ERROR("0 length buffer\n");
- drm_clear_next_buffer(dev);
- drm_free_buffer(dev, buf);
+ gamma_clear_next_buffer(dev);
+ gamma_free_buffer(dev, buf);
clear_bit(0, &dev->dma_flag);
return 0;
}
-
+
if (!gamma_dma_is_ready(dev)) {
clear_bit(0, &dev->dma_flag);
- return EBUSY;
+ DRM_OS_RETURN( EBUSY );
}
if (buf->while_locked) {
@@ -234,11 +193,10 @@ static int gamma_do_dma(drm_device_t *dev, int locked)
buf->idx, buf->pid);
}
} else {
- if (!locked && !drm_lock_take(&dev->lock.hw_lock->lock,
+ if (!locked && !gamma_lock_take(&dev->lock.hw_lock->lock,
DRM_KERNEL_CONTEXT)) {
- atomic_inc(&dma->total_missed_lock);
clear_bit(0, &dev->dma_flag);
- return EBUSY;
+ DRM_OS_RETURN( EBUSY );
}
}
@@ -246,13 +204,14 @@ static int gamma_do_dma(drm_device_t *dev, int locked)
&& !(dev->queuelist[buf->context]->flags
& _DRM_CONTEXT_PRESERVED)) {
/* PRE: dev->last_context != buf->context */
- if (drm_context_switch(dev, dev->last_context, buf->context)) {
- drm_clear_next_buffer(dev);
- drm_free_buffer(dev, buf);
+ if (DRM(context_switch)(dev, dev->last_context,
+ buf->context)) {
+ DRM(clear_next_buffer)(dev);
+ DRM(free_buffer)(dev, buf);
}
retcode = EBUSY;
goto cleanup;
-
+
/* POST: we will wait for the context
switch and will dispatch on a later call
when dev->last_context == buf->context.
@@ -260,23 +219,23 @@ static int gamma_do_dma(drm_device_t *dev, int locked)
TIME! */
}
- drm_clear_next_buffer(dev);
+ gamma_clear_next_buffer(dev);
buf->pending = 1;
buf->waiting = 0;
buf->list = DRM_LIST_PEND;
#if DRM_DMA_HISTOGRAM
- getnanotime(&buf->time_dispatched);
+ buf->time_dispatched = get_cycles();
#endif
gamma_dma_dispatch(dev, address, length);
- drm_free_buffer(dev, dma->this_buffer);
+ gamma_free_buffer(dev, dma->this_buffer);
dma->this_buffer = buf;
- atomic_add(length, &dma->total_bytes);
- atomic_inc(&dma->total_dmas);
+ atomic_inc(&dev->counts[7]); /* _DRM_STAT_DMA */
+ atomic_add(length, &dev->counts[8]); /* _DRM_STAT_PRIMARY */
if (!buf->while_locked && !dev->context_flag && !locked) {
- if (drm_lock_free(dev, &dev->lock.hw_lock->lock,
+ if (gamma_lock_free(dev, &dev->lock.hw_lock->lock,
DRM_KERNEL_CONTEXT)) {
DRM_ERROR("\n");
}
@@ -286,15 +245,19 @@ cleanup:
clear_bit(0, &dev->dma_flag);
#if DRM_DMA_HISTOGRAM
- getnanotime(&dma_stop);
- timespecsub(&dma_stop, &dma_start);
- atomic_inc(&dev->histo.ctx[drm_histogram_slot(&dma_stop)]);
+ dma_stop = get_cycles();
+ atomic_inc(&dev->histo.dma[gamma_histogram_slot(dma_stop - dma_start)]);
#endif
- return retcode;
+ DRM_OS_RETURN( retcode );
}
-static void gamma_dma_schedule_wrapper(void *dev)
+static void gamma_dma_timer_bh(unsigned long dev)
+{
+ gamma_dma_schedule((drm_device_t *)dev, 0);
+}
+
+void gamma_dma_immediate_bh(DRM_OS_TASKQUEUE_ARGS)
{
gamma_dma_schedule(dev, 0);
}
@@ -310,24 +273,24 @@ int gamma_dma_schedule(drm_device_t *dev, int locked)
int expire = 20;
drm_device_dma_t *dma = dev->dma;
#if DRM_DMA_HISTOGRAM
- struct timespec schedule_start;
+ cycles_t schedule_start;
#endif
if (test_and_set_bit(0, &dev->interrupt_flag)) {
/* Not reentrant */
- atomic_inc(&dma->total_missed_sched);
- return EBUSY;
+ atomic_inc(&dev->counts[10]); /* _DRM_STAT_MISSED */
+ DRM_OS_RETURN( EBUSY );
}
- missed = atomic_read(&dma->total_missed_sched);
+ missed = atomic_read(&dev->counts[10]);
#if DRM_DMA_HISTOGRAM
- getnanotime(&schedule_start);
+ schedule_start = get_cycles();
#endif
again:
if (dev->context_flag) {
clear_bit(0, &dev->interrupt_flag);
- return EBUSY;
+ DRM_OS_RETURN( EBUSY );
}
if (dma->next_buffer) {
/* Unsent buffer that was previously
@@ -335,23 +298,18 @@ again:
because the lock could not be obtained
or the DMA engine wasn't ready. Try
again. */
- atomic_inc(&dma->total_tried);
- if (!(retcode = gamma_do_dma(dev, locked))) {
- atomic_inc(&dma->total_hit);
- ++processed;
- }
+ if (!(retcode = gamma_do_dma(dev, locked))) ++processed;
} else {
do {
- next = drm_select_queue(dev,
- gamma_dma_schedule_wrapper);
+ next = gamma_select_queue(dev, gamma_dma_timer_bh);
if (next >= 0) {
q = dev->queuelist[next];
- buf = drm_waitlist_get(&q->waitlist);
+ buf = gamma_waitlist_get(&q->waitlist);
dma->next_buffer = buf;
dma->next_queue = q;
if (buf && buf->list == DRM_LIST_RECLAIM) {
- drm_clear_next_buffer(dev);
- drm_free_buffer(dev, buf);
+ gamma_clear_next_buffer(dev);
+ gamma_free_buffer(dev, buf);
}
}
} while (next >= 0 && !dma->next_buffer);
@@ -363,33 +321,26 @@ again:
}
if (--expire) {
- if (missed != atomic_read(&dma->total_missed_sched)) {
- atomic_inc(&dma->total_lost);
+ if (missed != atomic_read(&dev->counts[10])) {
if (gamma_dma_is_ready(dev)) goto again;
}
if (processed && gamma_dma_is_ready(dev)) {
- atomic_inc(&dma->total_lost);
processed = 0;
goto again;
}
}
-
+
clear_bit(0, &dev->interrupt_flag);
-
+
#if DRM_DMA_HISTOGRAM
- {
- struct timespec ts;
- getnanotime(&ts);
- timespecsub(&ts, &schedule_start);
- atomic_inc(&dev->histo.schedule[drm_histogram_slot(&ts)]);
- }
+ atomic_inc(&dev->histo.schedule[gamma_histogram_slot(get_cycles()
+ - schedule_start)]);
#endif
return retcode;
}
static int gamma_dma_priority(drm_device_t *dev, drm_dma_t *d)
{
- struct proc *p = curproc;
unsigned long address;
unsigned long length;
int must_free = 0;
@@ -399,7 +350,7 @@ static int gamma_dma_priority(drm_device_t *dev, drm_dma_t *d)
drm_buf_t *buf;
drm_buf_t *last_buf = NULL;
drm_device_dma_t *dma = dev->dma;
- static int never;
+ static int never;
/* Turn off interrupt handling */
while (test_and_set_bit(0, &dev->interrupt_flag)) {
@@ -408,7 +359,7 @@ static int gamma_dma_priority(drm_device_t *dev, drm_dma_t *d)
return retcode;
}
if (!(d->flags & _DRM_DMA_WHILE_LOCKED)) {
- while (!drm_lock_take(&dev->lock.hw_lock->lock,
+ while (!gamma_lock_take(&dev->lock.hw_lock->lock,
DRM_KERNEL_CONTEXT)) {
retcode = tsleep(&never, PZERO|PCATCH, "gamp2", 1);
if (retcode)
@@ -416,7 +367,6 @@ static int gamma_dma_priority(drm_device_t *dev, drm_dma_t *d)
}
++must_free;
}
- atomic_inc(&dma->total_prio);
for (i = 0; i < d->send_count; i++) {
idx = d->send_indices[i];
@@ -426,15 +376,15 @@ static int gamma_dma_priority(drm_device_t *dev, drm_dma_t *d)
continue;
}
buf = dma->buflist[ idx ];
- if (buf->pid != p->p_pid) {
+ if (buf->pid != DRM_OS_CURRENTPID) {
DRM_ERROR("Process %d using buffer owned by %d\n",
- p->p_pid, buf->pid);
+ DRM_OS_CURRENTPID, buf->pid);
retcode = EINVAL;
goto cleanup;
}
if (buf->list != DRM_LIST_NONE) {
DRM_ERROR("Process %d using %d's buffer on list %d\n",
- p->p_pid, buf->pid, buf->list);
+ DRM_OS_CURRENTPID, buf->pid, buf->list);
retcode = EINVAL;
goto cleanup;
}
@@ -467,14 +417,13 @@ static int gamma_dma_priority(drm_device_t *dev, drm_dma_t *d)
goto cleanup;
}
buf->pending = 1;
-
+
if (dev->last_context != buf->context
&& !(dev->queuelist[buf->context]->flags
& _DRM_CONTEXT_PRESERVED)) {
- atomic_inc(&dev->context_wait);
- /* PRE: dev->last_context != buf->context */
- drm_context_switch(dev, dev->last_context,
- buf->context);
+ /* PRE: dev->last_context != buf->context */
+ DRM(context_switch)(dev, dev->last_context,
+ buf->context);
/* POST: we will wait for the context
switch and will dispatch on a later call
when dev->last_context == buf->context.
@@ -482,7 +431,6 @@ static int gamma_dma_priority(drm_device_t *dev, drm_dma_t *d)
TIME! */
retcode = tsleep(&dev->context_wait, PZERO|PCATCH,
"gamctx", 0);
- atomic_dec(&dev->context_wait);
if (retcode)
goto cleanup;
if (dev->last_context != buf->context) {
@@ -493,15 +441,15 @@ static int gamma_dma_priority(drm_device_t *dev, drm_dma_t *d)
}
#if DRM_DMA_HISTOGRAM
- getnanotime(&buf->time_queued);
+ buf->time_queued = get_cycles();
buf->time_dispatched = buf->time_queued;
#endif
gamma_dma_dispatch(dev, address, length);
- atomic_add(length, &dma->total_bytes);
- atomic_inc(&dma->total_dmas);
-
+ atomic_inc(&dev->counts[9]); /* _DRM_STAT_SPECIAL */
+ atomic_add(length, &dev->counts[8]); /* _DRM_STAT_PRIMARY */
+
if (last_buf) {
- drm_free_buffer(dev, last_buf);
+ gamma_free_buffer(dev, last_buf);
}
last_buf = buf;
}
@@ -510,40 +458,40 @@ static int gamma_dma_priority(drm_device_t *dev, drm_dma_t *d)
cleanup:
if (last_buf) {
gamma_dma_ready(dev);
- drm_free_buffer(dev, last_buf);
+ gamma_free_buffer(dev, last_buf);
}
-
+
if (must_free && !dev->context_flag) {
- if (drm_lock_free(dev, &dev->lock.hw_lock->lock,
+ if (gamma_lock_free(dev, &dev->lock.hw_lock->lock,
DRM_KERNEL_CONTEXT)) {
DRM_ERROR("\n");
}
}
clear_bit(0, &dev->interrupt_flag);
- return retcode;
+ DRM_OS_RETURN( retcode );
}
static int gamma_dma_send_buffers(drm_device_t *dev, drm_dma_t *d)
{
- struct proc *p = curproc;
drm_buf_t *last_buf = NULL;
int retcode = 0;
drm_device_dma_t *dma = dev->dma;
-
- if ((retcode = drm_dma_enqueue(dev, d))) {
- return retcode;
- }
-
- gamma_dma_schedule(dev, 0);
-
if (d->flags & _DRM_DMA_BLOCK) {
last_buf = dma->buflist[d->send_indices[d->send_count-1]];
atomic_inc(&last_buf->dma_wait);
}
+ if ((retcode = gamma_dma_enqueue(dev, d))) {
+ if (d->flags & _DRM_DMA_BLOCK)
+ atomic_dec(&last_buf->dma_wait);
+ return retcode;
+ }
+
+ gamma_dma_schedule(dev, 0);
+
if (d->flags & _DRM_DMA_BLOCK) {
- DRM_DEBUG("%d waiting\n", p->p_pid);
+ DRM_DEBUG("%d waiting\n", DRM_OS_CURRENTPID);
for (;;) {
retcode = tsleep(&last_buf->dma_wait, PZERO|PCATCH,
"gamdw", 0);
@@ -553,13 +501,12 @@ static int gamma_dma_send_buffers(drm_device_t *dev, drm_dma_t *d)
if (retcode)
break;
}
-
- DRM_DEBUG("%d running\n", p->p_pid);
atomic_dec(&last_buf->dma_wait);
+ DRM_DEBUG("%d running\n", DRM_OS_CURRENTPID);
if (!retcode
|| (last_buf->list==DRM_LIST_PEND && !last_buf->pending)) {
if (!last_buf->dma_wait) {
- drm_free_buffer(dev, last_buf);
+ gamma_free_buffer(dev, last_buf);
}
}
if (retcode) {
@@ -571,254 +518,49 @@ static int gamma_dma_send_buffers(drm_device_t *dev, drm_dma_t *d)
last_buf->idx,
last_buf->list,
last_buf->pid,
- p->p_pid);
+ DRM_OS_CURRENTPID);
}
}
- return retcode;
+ DRM_OS_RETURN( retcode );
}
-int gamma_dma(dev_t kdev, u_long cmd, caddr_t data, int flags, struct proc *p)
+int gamma_dma( DRM_OS_IOCTL )
{
- drm_device_t *dev = kdev->si_drv1;
+ DRM_OS_DEVICE;
drm_device_dma_t *dma = dev->dma;
int retcode = 0;
drm_dma_t d;
- d = *(drm_dma_t *) data;
- DRM_DEBUG("%d %d: %d send, %d req\n",
- p->p_pid, d.context, d.send_count, d.request_count);
+ DRM_OS_KRNFROMUSR(d, (drm_dma_t *) data, sizeof(d));
- if (d.context == DRM_KERNEL_CONTEXT || d.context >= dev->queue_slots) {
- DRM_ERROR("Process %d using context %d\n",
- p->p_pid, d.context);
- return EINVAL;
- }
if (d.send_count < 0 || d.send_count > dma->buf_count) {
DRM_ERROR("Process %d trying to send %d buffers (of %d max)\n",
- p->p_pid, d.send_count, dma->buf_count);
- return EINVAL;
+ DRM_OS_CURRENTPID, d.send_count, dma->buf_count);
+ DRM_OS_RETURN( EINVAL );
}
+
if (d.request_count < 0 || d.request_count > dma->buf_count) {
DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
- p->p_pid, d.request_count, dma->buf_count);
- return EINVAL;
+ DRM_OS_CURRENTPID, d.request_count, dma->buf_count);
+ DRM_OS_RETURN( EINVAL );
}
if (d.send_count) {
if (d.flags & _DRM_DMA_PRIORITY)
retcode = gamma_dma_priority(dev, &d);
- else
+ else
retcode = gamma_dma_send_buffers(dev, &d);
}
d.granted_count = 0;
if (!retcode && d.request_count) {
- retcode = drm_dma_get_buffers(dev, &d);
+ retcode = gamma_dma_get_buffers(dev, &d);
}
DRM_DEBUG("%d returning, granted = %d\n",
- p->p_pid, d.granted_count);
- *(drm_dma_t *) data = d;
+ DRM_OS_CURRENTPID, d.granted_count);
+ DRM_OS_KRNTOUSR((drm_dma_t *) data, d, sizeof(d));
return retcode;
}
-
-int gamma_irq_install(drm_device_t *dev, int irq)
-{
- int rid;
- int retcode;
-
- if (!irq) return EINVAL;
-
- lockmgr(&dev->dev_lock, LK_EXCLUSIVE, 0, curproc);
- if (dev->irq) {
- lockmgr(&dev->dev_lock, LK_RELEASE, 0, curproc);
- return EBUSY;
- }
- lockmgr(&dev->dev_lock, LK_RELEASE, 0, curproc);
-
- DRM_DEBUG("%d\n", 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 0
- dev->tq.next = NULL;
- dev->tq.sync = 0;
- dev->tq.routine = gamma_dma_schedule_tq_wrapper;
- dev->tq.data = dev;
-#endif
- /* Before installing handler */
- GAMMA_WRITE(GAMMA_GCOMMANDMODE, 0);
- GAMMA_WRITE(GAMMA_GDMACONTROL, 0);
-
- /* Install handler */
- rid = 0;
- dev->irq = bus_alloc_resource(dev->device, SYS_RES_IRQ, &rid,
- 0, ~0, 1, RF_SHAREABLE);
- if (!dev->irq)
- return ENOENT;
-
- retcode = bus_setup_intr(dev->device, dev->irq, INTR_TYPE_TTY,
- gamma_dma_service, dev, &dev->irqh);
- if (retcode) {
- bus_release_resource(dev->device, SYS_RES_IRQ, 0, dev->irq);
- dev->irq = 0;
- return retcode;
- }
-
- /* After installing handler */
- GAMMA_WRITE(GAMMA_GINTENABLE, 0x2001);
- GAMMA_WRITE(GAMMA_COMMANDINTENABLE, 0x0008);
- GAMMA_WRITE(GAMMA_GDELAYTIMER, 0x39090);
-
- return 0;
-}
-
-int gamma_irq_uninstall(drm_device_t *dev)
-{
- if (!dev->irq)
- return EINVAL;
-
- DRM_DEBUG("%ld\n", rman_get_start(dev->irq));
-
- GAMMA_WRITE(GAMMA_GDELAYTIMER, 0);
- GAMMA_WRITE(GAMMA_COMMANDINTENABLE, 0);
- GAMMA_WRITE(GAMMA_GINTENABLE, 0);
-
- bus_teardown_intr(dev->device, dev->irq, dev->irqh);
- bus_release_resource(dev->device, SYS_RES_IRQ, 0, dev->irq);
- dev->irq = 0;
-
- return 0;
-}
-
-
-int gamma_control(dev_t kdev, u_long cmd, caddr_t data,
- int flags, struct proc *p)
-{
- drm_device_t *dev = kdev->si_drv1;
- drm_control_t ctl;
- int retcode;
-
- ctl = *(drm_control_t *) data;
-
- switch (ctl.func) {
- case DRM_INST_HANDLER:
- if ((retcode = gamma_irq_install(dev, ctl.irq)))
- return retcode;
- break;
- case DRM_UNINST_HANDLER:
- if ((retcode = gamma_irq_uninstall(dev)))
- return retcode;
- break;
- default:
- return EINVAL;
- }
- return 0;
-}
-
-int gamma_lock(dev_t kdev, u_long cmd, caddr_t data, int flags, struct proc *p)
-{
- drm_device_t *dev = kdev->si_drv1;
- int ret = 0;
- drm_lock_t lock;
- drm_queue_t *q;
-#if DRM_DMA_HISTOGRAM
- struct timespec start;
-
- getnanotime(&start);
- dev->lck_start = start;
-#endif
-
- lock = *(drm_lock_t *) data;
-
- if (lock.context == DRM_KERNEL_CONTEXT) {
- DRM_ERROR("Process %d using kernel context %d\n",
- p->p_pid, lock.context);
- return EINVAL;
- }
-
- DRM_DEBUG("%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
- lock.context, p->p_pid, dev->lock.hw_lock->lock,
- lock.flags);
-
- if (lock.context < 0 || lock.context >= dev->queue_count)
- return EINVAL;
- q = dev->queuelist[lock.context];
-
- ret = drm_flush_block_and_flush(dev, lock.context, lock.flags);
-
- if (!ret) {
- if (_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock)
- != lock.context) {
- long j = ticks - dev->lock.lock_time;
-
- if (j > 0 && j <= DRM_LOCK_SLICE) {
- /* Can't take lock if we just had it and
- there is contention. */
- static int never;
- ret = tsleep(&never, PZERO|PCATCH,
- "gaml1", j);
- if (ret)
- return ret;
- }
- }
- atomic_inc(&dev->lock.lock_queue);
- for (;;) {
- if (!dev->lock.hw_lock) {
- /* Device has been unregistered */
- ret = EINTR;
- break;
- }
- if (drm_lock_take(&dev->lock.hw_lock->lock,
- lock.context)) {
- dev->lock.pid = p->p_pid;
- dev->lock.lock_time = ticks;
- atomic_inc(&dev->total_locks);
- atomic_inc(&q->total_locks);
- break; /* Got lock */
- }
-
- /* Contention */
- atomic_inc(&dev->total_sleeps);
- ret = tsleep(&dev->lock.lock_queue, PZERO|PCATCH,
- "gaml2", 0);
- if (ret)
- break;
- }
- atomic_dec(&dev->lock.lock_queue);
- }
-
- drm_flush_unblock(dev, lock.context, lock.flags); /* cleanup phase */
-
- if (!ret) {
- if (lock.flags & _DRM_LOCK_READY)
- gamma_dma_ready(dev);
- if (lock.flags & _DRM_LOCK_QUIESCENT) {
- if (gamma_found() == 1) {
- gamma_dma_quiescent_single(dev);
- } else {
- gamma_dma_quiescent_dual(dev);
- }
- }
- }
- DRM_DEBUG("%d %s\n", lock.context, ret ? "interrupted" : "has lock");
-
-#if DRM_DMA_HISTOGRAM
- {
- struct timespec ts;
- getnanotime(&ts);
- timespecsub(&ts, &start);
- atomic_inc(&dev->histo.lacq[drm_histogram_slot(&ts)]);
- }
-#endif
-
- return ret;
-}
diff --git a/bsd/gamma/gamma_drv.c b/bsd/gamma/gamma_drv.c
index 8663a2ac..e58d853c 100644
--- a/bsd/gamma/gamma_drv.c
+++ b/bsd/gamma/gamma_drv.c
@@ -1,4 +1,4 @@
-/* gamma.c -- 3dlabs GMX 2000 driver -*- c -*-
+/* gamma.c -- 3dlabs GMX 2000 driver -*- linux-c -*-
* Created: Mon Jan 4 08:58:31 1999 by faith@precisioninsight.com
*
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
@@ -11,11 +11,11 @@
* 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
@@ -23,607 +23,65 @@
* 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 "gamma.h"
#include "drmP.h"
#include "gamma_drv.h"
-#include <pci/pcivar.h>
-
-MODULE_DEPEND(gamma, drm, 1, 1, 1);
-
-#ifndef PCI_DEVICE_ID_3DLABS_GAMMA
-#define PCI_DEVICE_ID_3DLABS_GAMMA 0x0008
-#endif
-#ifndef PCI_DEVICE_ID_3DLABS_MX
-#define PCI_DEVICE_ID_3DLABS_MX 0x0006
-#endif
-#ifndef PCI_VENDOR_ID_3DLABS
-#define PCI_VENDOR_ID_3DLABS 0x3d3d
-#endif
-
-static int gamma_init(device_t nbdev);
-static void gamma_cleanup(device_t nbdev);
-
-static int gamma_probe(device_t dev)
-{
- const char *s = 0;
-
- switch (pci_get_devid(dev)) {
- case 0x00083d3d:
- s = "3D Labs Gamma graphics accelerator";
- break;
-
- case 0x00063d3d:
- s = "3D Labs MX graphics accelerator";
- break;
- }
-
- if (s) {
- device_set_desc(dev, s);
- return 0;
- }
-
- return ENXIO;
-}
-
-static int gamma_attach(device_t dev)
-{
- gamma_init(dev);
- return 0;
-}
-
-static int gamma_detach(device_t dev)
-{
- gamma_cleanup(dev);
- return 0;
-}
-
-static device_method_t gamma_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, gamma_probe),
- DEVMETHOD(device_attach, gamma_attach),
- DEVMETHOD(device_detach, gamma_detach),
-
- { 0, 0 }
-};
-
-static driver_t gamma_driver = {
- "drm",
- gamma_methods,
- sizeof(drm_device_t),
-};
-
-static devclass_t gamma_devclass;
-#define GAMMA_SOFTC(unit) \
- ((drm_device_t *) devclass_get_softc(gamma_devclass, unit))
-
-DRIVER_MODULE(if_gamma, pci, gamma_driver, gamma_devclass, 0, 0);
-
-#define GAMMA_NAME "gamma"
-#define GAMMA_DESC "3dlabs GMX 2000"
-#define GAMMA_DATE "20000606"
-#define GAMMA_MAJOR 1
-#define GAMMA_MINOR 0
-#define GAMMA_PATCHLEVEL 0
+#define DRIVER_AUTHOR "VA Linux Systems Inc."
-#define CDEV_MAJOR 200
+#define DRIVER_NAME "gamma"
+#define DRIVER_DESC "3DLabs gamma"
+#define DRIVER_DATE "20010216"
-static struct cdevsw gamma_cdevsw = {
- /* open */ gamma_open,
- /* close */ gamma_close,
- /* read */ drm_read,
- /* write */ drm_write,
- /* ioctl */ gamma_ioctl,
- /* poll */ nopoll,
- /* mmap */ drm_mmap,
- /* strategy */ nostrategy,
- /* name */ "gamma",
- /* maj */ CDEV_MAJOR,
- /* dump */ nodump,
- /* psize */ nopsize,
- /* flags */ D_TTY | D_TRACKCLOSE,
- /* bmaj */ -1
-};
+#define DRIVER_MAJOR 1
+#define DRIVER_MINOR 0
+#define DRIVER_PATCHLEVEL 0
-static drm_ioctl_desc_t gamma_ioctls[] = {
- [DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = { gamma_version, 0, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = { drm_getunique, 0, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = { drm_getmagic, 0, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)] = { drm_irq_busid, 0, 1 },
+#define DRIVER_IOCTLS \
+ [DRM_IOCTL_NR(DRM_IOCTL_DMA)] = { gamma_dma, 1, 0 }
- [DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)] = { drm_setunique, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_BLOCK)] = { drm_block, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)] = { drm_unblock, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = { gamma_control, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)] = { drm_authmagic, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)] = { drm_addmap, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)] = { drm_addbufs, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)] = { drm_markbufs, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)] = { drm_infobufs, 1, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)] = { drm_mapbufs, 1, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)] = { drm_freebufs, 1, 0 },
-
- [DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = { drm_addctx, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = { drm_rmctx, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = { drm_modctx, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = { drm_getctx, 1, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = { drm_switchctx, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)] = { drm_newctx, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)] = { drm_resctx, 1, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)] = { drm_adddraw, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)] = { drm_rmdraw, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_DMA)] = { gamma_dma, 1, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_LOCK)] = { gamma_lock, 1, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)] = { gamma_unlock, 1, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_FINISH)] = { drm_finish, 1, 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)[] = {
+ {0x3d3d, 0x0008, 1, "3DLabs Gamma"},
+ {0, 0, 0, NULL}
};
-#define GAMMA_IOCTL_COUNT DRM_ARRAY_SIZE(gamma_ioctls)
-
-static int devices = 0;
-
-static int gamma_setup(drm_device_t *dev)
-{
- int i;
-
- device_busy(dev->device);
-
- atomic_set(&dev->ioctl_count, 0);
- atomic_set(&dev->vma_count, 0);
- dev->buf_use = 0;
- atomic_set(&dev->buf_alloc, 0);
-
- drm_dma_setup(dev);
-
- atomic_set(&dev->total_open, 0);
- atomic_set(&dev->total_close, 0);
- atomic_set(&dev->total_ioctl, 0);
- atomic_set(&dev->total_irq, 0);
- atomic_set(&dev->total_ctx, 0);
- atomic_set(&dev->total_locks, 0);
- atomic_set(&dev->total_unlocks, 0);
- atomic_set(&dev->total_contends, 0);
- atomic_set(&dev->total_sleeps, 0);
-
- for (i = 0; i < DRM_HASH_SIZE; i++) {
- dev->magiclist[i].head = NULL;
- dev->magiclist[i].tail = NULL;
- }
- dev->maplist = NULL;
- dev->map_count = 0;
- dev->vmalist = NULL;
- dev->lock.hw_lock = NULL;
- dev->lock.lock_queue = 0;
- dev->queue_count = 0;
- dev->queue_reserved = 0;
- dev->queue_slots = 0;
- dev->queuelist = NULL;
- dev->irq = 0;
- dev->context_flag = 0;
- dev->interrupt_flag = 0;
- dev->dma_flag = 0;
- dev->last_context = 0;
- dev->last_switch = 0;
- dev->last_checked = 0;
- callout_init(&dev->timer);
- dev->context_wait = 0;
-#if DRM_DMA_HISTO
- memset(&dev->histo, 0, sizeof(dev->histo));
-#endif
- timespecclear(&dev->ctx_start);
- timespecclear(&dev->lck_start);
-
- dev->buf_rp = dev->buf;
- dev->buf_wp = dev->buf;
- dev->buf_end = dev->buf + DRM_BSZ;
- dev->buf_sigio = NULL;
-
- DRM_DEBUG("\n");
-
- /* The kernel's context could be created here, but is now created
- in drm_dma_enqueue. This is more resource-efficient for
- hardware that does not do DMA, but may mean that
- drm_select_queue fails between the time the interrupt is
- initialized and the time the queues are initialized. */
-
- return 0;
-}
-
-
-static int
-gamma_takedown(drm_device_t *dev)
-{
- int i;
- drm_magic_entry_t *pt, *next;
- drm_map_t *map;
- drm_vma_entry_t *vma, *vma_next;
-
- DRM_DEBUG("\n");
-
- if (dev->irq) gamma_irq_uninstall(dev);
-
- lockmgr(&dev->dev_lock, LK_EXCLUSIVE, 0, curproc);
- callout_stop(&dev->timer);
-
- if (dev->devname) {
- drm_free(dev->devname, strlen(dev->devname)+1, DRM_MEM_DRIVER);
- dev->devname = NULL;
- }
-
- if (dev->unique) {
- drm_free(dev->unique, strlen(dev->unique)+1, DRM_MEM_DRIVER);
- dev->unique = NULL;
- dev->unique_len = 0;
- }
- /* Clear pid list */
- for (i = 0; i < DRM_HASH_SIZE; i++) {
- for (pt = dev->magiclist[i].head; pt; pt = next) {
- next = pt->next;
- drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
- }
- dev->magiclist[i].head = dev->magiclist[i].tail = NULL;
- }
-
- /* Clear vma list (only built for debugging) */
- if (dev->vmalist) {
- for (vma = dev->vmalist; vma; vma = vma_next) {
- vma_next = vma->next;
- drm_free(vma, sizeof(*vma), DRM_MEM_VMAS);
- }
- dev->vmalist = NULL;
- }
-
- /* Clear map area and mtrr information */
- if (dev->maplist) {
- for (i = 0; i < dev->map_count; i++) {
- map = dev->maplist[i];
- switch (map->type) {
- case _DRM_REGISTERS:
- case _DRM_FRAME_BUFFER:
-#ifdef CONFIG_MTRR
- if (map->mtrr >= 0) {
- int retcode;
- retcode = mtrr_del(map->mtrr,
- map->offset,
- map->size);
- DRM_DEBUG("mtrr_del = %d\n", retcode);
- }
-#endif
- drm_ioremapfree(map->handle, map->size);
- break;
- case _DRM_SHM:
- drm_free_pages((unsigned long)map->handle,
- drm_order(map->size)
- - PAGE_SHIFT,
- DRM_MEM_SAREA);
- break;
- case _DRM_AGP:
- /* Do nothing here, because this is all
- handled in the AGP/GART driver. */
- break;
- }
- drm_free(map, sizeof(*map), DRM_MEM_MAPS);
- }
- drm_free(dev->maplist,
- dev->map_count * sizeof(*dev->maplist),
- DRM_MEM_MAPS);
- dev->maplist = NULL;
- dev->map_count = 0;
- }
-
- if (dev->queuelist) {
- for (i = 0; i < dev->queue_count; i++) {
- drm_waitlist_destroy(&dev->queuelist[i]->waitlist);
- if (dev->queuelist[i]) {
- drm_free(dev->queuelist[i],
- sizeof(*dev->queuelist[0]),
- DRM_MEM_QUEUES);
- dev->queuelist[i] = NULL;
- }
- }
- drm_free(dev->queuelist,
- dev->queue_slots * sizeof(*dev->queuelist),
- DRM_MEM_QUEUES);
- dev->queuelist = NULL;
- }
-
- drm_dma_takedown(dev);
-
- dev->queue_count = 0;
- if (dev->lock.hw_lock) {
- dev->lock.hw_lock = NULL; /* SHM removed */
- dev->lock.pid = 0;
- wakeup(&dev->lock.lock_queue);
- }
- lockmgr(&dev->dev_lock, LK_RELEASE, 0, curproc);
-
- device_unbusy(dev->device);
-
- return 0;
-}
-
-int gamma_found(void)
-{
- return devices;
-}
-
-static int
-gamma_find_devices(device_t dev)
-{
- device_t *children, child;
- int nchildren, i;
- int count = 0;
-
- if (device_get_children(device_get_parent(dev), &children, &nchildren))
- return 0;
-
- for (i = 0; i < nchildren; i++) {
- child = children[i];
-
- if (pci_get_slot(dev) == pci_get_slot(child) &&
- pci_get_vendor(child) == PCI_VENDOR_ID_3DLABS &&
- pci_get_device(child) == PCI_DEVICE_ID_3DLABS_MX) {
- count++;
- }
- }
- free(children, M_TEMP);
-
- /* we don't currently support more than two */
- if (count > 2) count = 2;
-
- return count;
-}
-
-/* gamma_init is called via gamma_attach at module load time */
-
-static int
-gamma_init(device_t nbdev)
-{
- drm_device_t *dev = device_get_softc(nbdev);
-
- DRM_DEBUG("\n");
-
- memset((void *)dev, 0, sizeof(*dev));
- simple_lock_init(&dev->count_lock);
- lockinit(&dev->dev_lock, PZERO, "drmlk", 0, 0);
-
-#if 0 /* XXX use getenv I guess */
- drm_parse_options(gamma);
-#endif
- devices = gamma_find_devices(nbdev);
- if (devices == 0) return -1;
-
-#if 0
- if ((retcode = misc_register(&gamma_misc))) {
- DRM_ERROR("Cannot register \"%s\"\n", GAMMA_NAME);
- return retcode;
- }
-#endif
- dev->device = nbdev;
- dev->devnode = make_dev(&gamma_cdevsw,
- device_get_unit(nbdev),
- DRM_DEV_UID,
- DRM_DEV_GID,
- DRM_DEV_MODE,
- GAMMA_NAME);
- dev->name = GAMMA_NAME;
-
- drm_mem_init();
- drm_sysctl_init(dev);
-
- DRM_INFO("Initialized %s %d.%d.%d %s on minor %d with %d MX devices\n",
- GAMMA_NAME,
- GAMMA_MAJOR,
- GAMMA_MINOR,
- GAMMA_PATCHLEVEL,
- GAMMA_DATE,
- device_get_unit(nbdev),
- devices);
-
- return 0;
-}
-
-/* gamma_cleanup is called via gamma_detach at module unload time. */
-
-static void
-gamma_cleanup(device_t nbdev)
-{
- drm_device_t *dev = device_get_softc(nbdev);
-
- DRM_DEBUG("\n");
-
- drm_sysctl_cleanup(dev);
-#if 0
- if (misc_deregister(&gamma_misc)) {
- DRM_ERROR("Cannot unload module\n");
- } else {
- DRM_INFO("Module unloaded\n");
- }
-#endif
- device_busy(dev->device);
- gamma_takedown(dev);
-}
-
-SYSUNINIT(gamma_cleanup, SI_SUB_DRIVERS, SI_ORDER_ANY, gamma_cleanup, 0);
-
-#if 0
-int gamma_version(struct inode *inode, struct file *filp, unsigned int cmd,
- unsigned long arg)
-{
- drm_version_t version;
- int len;
-
- copy_from_user_ret(&version,
- (drm_version_t *)arg,
- sizeof(version),
- -EFAULT);
-
-#define DRM_COPY(name,value) \
- len = strlen(value); \
- if (len > name##_len) len = name##_len; \
- name##_len = strlen(value); \
- if (len && name) { \
- copy_to_user_ret(name, value, len, -EFAULT); \
- }
-
- version.version_major = GAMMA_MAJOR;
- version.version_minor = GAMMA_MINOR;
- version.version_patchlevel = GAMMA_PATCHLEVEL;
-
- DRM_COPY(version.name, GAMMA_NAME);
- DRM_COPY(version.date, GAMMA_DATE);
- DRM_COPY(version.desc, GAMMA_DESC);
-
- copy_to_user_ret((drm_version_t *)arg,
- &version,
- sizeof(version),
- -EFAULT);
- return 0;
-}
-#endif
-
-int
-gamma_open(dev_t kdev, int flags, int fmt, struct proc *p)
-{
- drm_device_t *dev = GAMMA_SOFTC(minor(kdev));
- int retcode = 0;
-
- DRM_DEBUG("open_count = %d\n", dev->open_count);
-
- device_busy(dev->device);
- if (!(retcode = drm_open_helper(kdev, flags, fmt, p, dev))) {
- atomic_inc(&dev->total_open);
- simple_lock(&dev->count_lock);
- if (!dev->open_count++) {
- simple_unlock(&dev->count_lock);
- retcode = gamma_setup(dev);
- }
- simple_unlock(&dev->count_lock);
- }
- device_unbusy(dev->device);
-
- return retcode;
-}
-
-int
-gamma_close(dev_t kdev, int flags, int fmt, struct proc *p)
-{
- drm_device_t *dev = kdev->si_drv1;
- int retcode = 0;
-
- DRM_DEBUG("open_count = %d\n", dev->open_count);
- if (!(retcode = drm_close(kdev, flags, fmt, p))) {
- atomic_inc(&dev->total_close);
- simple_lock(&dev->count_lock);
- if (!--dev->open_count) {
- if (atomic_read(&dev->ioctl_count) || dev->blocked) {
- DRM_ERROR("Device busy: %d %d\n",
- atomic_read(&dev->ioctl_count),
- dev->blocked);
- simple_unlock(&dev->count_lock);
- return EBUSY;
- }
- simple_unlock(&dev->count_lock);
- return gamma_takedown(dev);
- }
- simple_unlock(&dev->count_lock);
- }
- return retcode;
-}
-
-/* drm_ioctl is called whenever a process performs an ioctl on /dev/drm. */
-
-int
-gamma_ioctl(dev_t kdev, u_long cmd, caddr_t data, int flags, struct proc *p)
-{
- int nr = DRM_IOCTL_NR(cmd);
- drm_device_t *dev = kdev->si_drv1;
- drm_file_t *priv;
- int retcode = 0;
- drm_ioctl_desc_t *ioctl;
- d_ioctl_t *func;
-
- priv = drm_find_file_by_proc(dev, p);
- if (!priv) {
- DRM_DEBUG("can't find authenticator\n");
- return EINVAL;
- }
-
- atomic_inc(&dev->ioctl_count);
- atomic_inc(&dev->total_ioctl);
- ++priv->ioctl_count;
-
- DRM_DEBUG("pid = %d, cmd = 0x%02lx, nr = 0x%02x, auth = %d\n",
- p->p_pid, cmd, nr, priv->authenticated);
-
- switch (cmd) {
- case FIOSETOWN:
- return fsetown(*(int *)data, &dev->buf_sigio);
- case FIOGETOWN:
- *(int *) data = fgetown(dev->buf_sigio);
- return 0;
- }
- if (nr >= GAMMA_IOCTL_COUNT) {
- retcode = EINVAL;
- } else {
- ioctl = &gamma_ioctls[nr];
- func = ioctl->func;
+#define __HAVE_COUNTERS 5
+#define __HAVE_COUNTER6 _DRM_STAT_IRQ
+#define __HAVE_COUNTER7 _DRM_STAT_DMA
+#define __HAVE_COUNTER8 _DRM_STAT_PRIMARY
+#define __HAVE_COUNTER9 _DRM_STAT_SPECIAL
+#define __HAVE_COUNTER10 _DRM_STAT_MISSED
- if (!func) {
- DRM_DEBUG("no function\n");
- retcode = EINVAL;
- } else if ((ioctl->root_only && suser(p))
- || (ioctl->auth_needed && !priv->authenticated)) {
- retcode = EACCES;
- } else {
- retcode = (func)(kdev, cmd, data, flags, p);
- }
- }
-
- atomic_dec(&dev->ioctl_count);
- return retcode;
-}
-int gamma_unlock(dev_t kdev, u_long cmd, caddr_t data, int flags, struct proc *p)
-{
- drm_device_t *dev = kdev->si_drv1;
- drm_lock_t *lockp = (drm_lock_t *) data;
+#include "drm_auth.h"
+#include "drm_bufs.h"
+#include "drm_context.h"
+#include "drm_dma.h"
+#include "drm_drawable.h"
+#include "drm_drv.h"
- if (lockp->context == DRM_KERNEL_CONTEXT) {
- DRM_ERROR("Process %d using kernel context %d\n",
- p->p_pid, lockp->context);
- return -EINVAL;
- }
- DRM_DEBUG("%d frees lock (%d holds)\n",
- lockp->context,
- _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
- atomic_inc(&dev->total_unlocks);
- if (_DRM_LOCK_IS_CONT(dev->lock.hw_lock->lock))
- atomic_inc(&dev->total_contends);
- drm_lock_transfer(dev, &dev->lock.hw_lock->lock, DRM_KERNEL_CONTEXT);
- gamma_dma_schedule(dev, 1);
- if (!dev->context_flag) {
- if (drm_lock_free(dev, &dev->lock.hw_lock->lock,
- DRM_KERNEL_CONTEXT)) {
- DRM_ERROR("\n");
- }
- }
+#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"
-#if DRM_DMA_HISTOGRAM
- {
- struct timespec ts;
- getnanotime(&ts);
- timespecsub(&ts, &dev->lck_start);
- atomic_inc(&dev->histo.lhld[drm_histogram_slot(&ts)]);
- }
-#endif
-
- return 0;
-}
+DRIVER_MODULE(gamma, pci, gamma_driver, gamma_devclass, 0, 0);
diff --git a/bsd/gamma/gamma_drv.h b/bsd/gamma/gamma_drv.h
index b7c6df5d..f8665516 100644
--- a/bsd/gamma/gamma_drv.h
+++ b/bsd/gamma/gamma_drv.h
@@ -1,4 +1,4 @@
-/* gamma_drv.h -- Private header for 3dlabs GMX 2000 driver -*- c -*-
+/* gamma_drv.h -- Private header for 3dlabs GMX 2000 driver -*- linux-c -*-
* Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com
*
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
@@ -11,11 +11,11 @@
* 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
@@ -23,26 +23,82 @@
* 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>
+ *
*/
#ifndef _GAMMA_DRV_H_
#define _GAMMA_DRV_H_
- /* gamma_drv.c */
-extern d_open_t gamma_open;
-extern d_close_t gamma_close;
-extern d_ioctl_t gamma_ioctl;
-extern d_ioctl_t gamma_version;
-extern d_ioctl_t gamma_dma;
-extern d_ioctl_t gamma_lock;
-extern d_ioctl_t gamma_unlock;
-extern d_ioctl_t gamma_control;
+
+typedef struct drm_gamma_private {
+ drm_map_t *buffers;
+ drm_map_t *mmio0;
+ drm_map_t *mmio1;
+ drm_map_t *mmio2;
+ drm_map_t *mmio3;
+} drm_gamma_private_t;
+
+#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)
+
+
+extern void gamma_dma_ready(drm_device_t *dev);
+extern void gamma_dma_quiescent_single(drm_device_t *dev);
+extern void gamma_dma_quiescent_dual(drm_device_t *dev);
/* gamma_dma.c */
extern int gamma_dma_schedule(drm_device_t *dev, int locked);
-extern int gamma_irq_install(drm_device_t *dev, int irq);
-extern int gamma_irq_uninstall(drm_device_t *dev);
+extern int gamma_dma( DRM_OS_IOCTL );
+extern int gamma_find_devices(void);
extern int gamma_found(void);
+
+#define GAMMA_OFF(reg) \
+ ((reg < 0x1000) \
+ ? reg \
+ : ((reg < 0x10000) \
+ ? (reg - 0x1000) \
+ : ((reg < 0x11000) \
+ ? (reg - 0x10000) \
+ : (reg - 0x11000))))
+
+#define GAMMA_BASE(reg) ((unsigned long) \
+ ((reg < 0x1000) ? dev_priv->mmio0->handle : \
+ ((reg < 0x10000) ? dev_priv->mmio1->handle : \
+ ((reg < 0x11000) ? dev_priv->mmio2->handle : \
+ dev_priv->mmio3->handle))))
+
+#define GAMMA_ADDR(reg) (GAMMA_BASE(reg) + GAMMA_OFF(reg))
+#define GAMMA_DEREF(reg) *(__volatile__ int *)GAMMA_ADDR(reg)
+#define GAMMA_READ(reg) GAMMA_DEREF(reg)
+#define GAMMA_WRITE(reg,val) do { GAMMA_DEREF(reg) = val; } while (0)
+
+#define GAMMA_BROADCASTMASK 0x9378
+#define GAMMA_COMMANDINTENABLE 0x0c48
+#define GAMMA_DMAADDRESS 0x0028
+#define GAMMA_DMACOUNT 0x0030
+#define GAMMA_FILTERMODE 0x8c00
+#define GAMMA_GCOMMANDINTFLAGS 0x0c50
+#define GAMMA_GCOMMANDMODE 0x0c40
+#define GAMMA_GCOMMANDSTATUS 0x0c60
+#define GAMMA_GDELAYTIMER 0x0c38
+#define GAMMA_GDMACONTROL 0x0060
+#define GAMMA_GINTENABLE 0x0808
+#define GAMMA_GINTFLAGS 0x0810
+#define GAMMA_INFIFOSPACE 0x0018
+#define GAMMA_OUTFIFOWORDS 0x0020
+#define GAMMA_OUTPUTFIFO 0x2000
+#define GAMMA_SYNC 0x8c40
+#define GAMMA_SYNC_TAG 0x0188
+
#endif
diff --git a/bsd/i810/Makefile b/bsd/i810/Makefile
new file mode 100644
index 00000000..c518c7ef
--- /dev/null
+++ b/bsd/i810/Makefile
@@ -0,0 +1,25 @@
+# $FreeBSD$
+
+KMOD= i810
+NOMAN= YES
+SRCS= i810_drv.c i810_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
+#I810_OPTS= "\#define DRM_LINUX" 1
+.endif
+
+opt_drm_linux.h:
+ touch opt_drm_linux.h
+ echo $(I810_OPTS) >> opt_drm_linux.h
+
+.include <bsd.kmod.mk>
diff --git a/bsd/mga/Makefile b/bsd/mga/Makefile
index 226728b5..bbaeaa56 100644
--- a/bsd/mga/Makefile
+++ b/bsd/mga/Makefile
@@ -1,11 +1,10 @@
# $FreeBSD$
-KMOD = mga
-SRCS = mga_drv.c mga_context.c mga_state.c mga_bufs.c mga_dma.c
-SRCS += device_if.h bus_if.h pci_if.h
-CFLAGS += ${DEBUG_FLAGS} -I..
-KERN = /usr/src/sys
-KMODDEPS = drm
+KMOD= mga
+NOMAN= YES
+SRCS= mga_drv.c mga_state.c mga_warp.c mga_dma.c
+SRCS+= device_if.h bus_if.h pci_if.h opt_drm_linux.h
+CFLAGS+= ${DEBUG_FLAGS} -I. -I..
@:
ln -sf /sys @
@@ -13,4 +12,14 @@ KMODDEPS = drm
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
+#MGA_OPTS= "\#define DRM_LINUX" 1
+.endif
+
+opt_drm_linux.h:
+ touch opt_drm_linux.h
+ echo $(MGA_OPTS) >> opt_drm_linux.h
+
.include <bsd.kmod.mk>
diff --git a/bsd/r128/Makefile b/bsd/r128/Makefile
new file mode 100644
index 00000000..ae5622ed
--- /dev/null
+++ b/bsd/r128/Makefile
@@ -0,0 +1,25 @@
+# $FreeBSD$
+
+KMOD = r128
+NOMAN= YES
+SRCS = r128_cce.c r128_drv.c r128_state.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
+#R128_OPTS= "\#define DRM_LINUX" 1
+.endif
+
+opt_drm_linux.h:
+ touch opt_drm_linux.h
+ echo $(R128_OPTS) >> opt_drm_linux.h
+
+.include <bsd.kmod.mk>
diff --git a/bsd/radeon/Makefile b/bsd/radeon/Makefile
new file mode 100644
index 00000000..b1d77bf4
--- /dev/null
+++ b/bsd/radeon/Makefile
@@ -0,0 +1,25 @@
+# $FreeBSD$
+
+KMOD = radeon
+NOMAN= YES
+SRCS = radeon_cp.c radeon_drv.c radeon_state.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
+#RADEON_OPTS= "\#define DRM_LINUX" 1
+.endif
+
+opt_drm_linux.h:
+ touch opt_drm_linux.h
+ echo $(RADEON_OPTS) >> opt_drm_linux.h
+
+.include <bsd.kmod.mk>
diff --git a/bsd/sis/Makefile b/bsd/sis/Makefile
new file mode 100644
index 00000000..07b41caa
--- /dev/null
+++ b/bsd/sis/Makefile
@@ -0,0 +1,25 @@
+# $FreeBSD$
+
+KMOD= sis
+NOMAN= YES
+SRCS= sis_drv.c sis_ds.c sis_mm.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
+#SIS_OPTS= "\#define DRM_LINUX" 1
+.endif
+
+opt_drm_linux.h:
+ touch opt_drm_linux.h
+ echo $(SIS_OPTS) >> opt_drm_linux.h
+
+.include <bsd.kmod.mk>