summaryrefslogtreecommitdiff
path: root/bsd-core
diff options
context:
space:
mode:
Diffstat (limited to 'bsd-core')
-rw-r--r--bsd-core/drm_agpsupport.c326
-rw-r--r--bsd-core/drm_os_freebsd.h375
-rw-r--r--bsd-core/drm_sysctl.c523
-rw-r--r--bsd-core/drm_vm.c81
-rw-r--r--bsd-core/mga/Makefile21
-rw-r--r--bsd-core/r128/Makefile25
-rw-r--r--bsd-core/radeon/Makefile25
-rw-r--r--bsd-core/sis/Makefile25
8 files changed, 1395 insertions, 6 deletions
diff --git a/bsd-core/drm_agpsupport.c b/bsd-core/drm_agpsupport.c
new file mode 100644
index 00000000..ac12c867
--- /dev/null
+++ b/bsd-core/drm_agpsupport.c
@@ -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-core/drm_os_freebsd.h b/bsd-core/drm_os_freebsd.h
new file mode 100644
index 00000000..72c5baf6
--- /dev/null
+++ b/bsd-core/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-core/drm_sysctl.c b/bsd-core/drm_sysctl.c
new file mode 100644
index 00000000..02e4b28d
--- /dev/null
+++ b/bsd-core/drm_sysctl.c
@@ -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-core/drm_vm.c b/bsd-core/drm_vm.c
new file mode 100644
index 00000000..a06fb448
--- /dev/null
+++ b/bsd-core/drm_vm.c
@@ -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-core/mga/Makefile b/bsd-core/mga/Makefile
index 226728b5..bbaeaa56 100644
--- a/bsd-core/mga/Makefile
+++ b/bsd-core/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-core/r128/Makefile b/bsd-core/r128/Makefile
new file mode 100644
index 00000000..ae5622ed
--- /dev/null
+++ b/bsd-core/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-core/radeon/Makefile b/bsd-core/radeon/Makefile
new file mode 100644
index 00000000..b1d77bf4
--- /dev/null
+++ b/bsd-core/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-core/sis/Makefile b/bsd-core/sis/Makefile
new file mode 100644
index 00000000..07b41caa
--- /dev/null
+++ b/bsd-core/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>