Sync DRM code with FreeBSD trunk rev 190433.
authorHasso Tepper <hasso@estpak.ee>
Thu, 26 Mar 2009 08:34:49 +0000 (10:34 +0200)
committerHasso Tepper <hasso@estpak.ee>
Fri, 27 Mar 2009 07:08:53 +0000 (09:08 +0200)
80 files changed:
sys/conf/files
sys/dev/drm/ati_pcigart.c
sys/dev/drm/drm.h
sys/dev/drm/drmP.h
sys/dev/drm/drm_agpsupport.c
sys/dev/drm/drm_atomic.h
sys/dev/drm/drm_auth.c
sys/dev/drm/drm_bufs.c
sys/dev/drm/drm_context.c
sys/dev/drm/drm_dma.c
sys/dev/drm/drm_drawable.c
sys/dev/drm/drm_drv.c
sys/dev/drm/drm_fops.c
sys/dev/drm/drm_internal.h
sys/dev/drm/drm_ioctl.c
sys/dev/drm/drm_irq.c
sys/dev/drm/drm_linux_list.h
sys/dev/drm/drm_lock.c
sys/dev/drm/drm_memory.c
sys/dev/drm/drm_pci.c
sys/dev/drm/drm_pciids.h
sys/dev/drm/drm_sarea.h
sys/dev/drm/drm_scatter.c
sys/dev/drm/drm_sysctl.c
sys/dev/drm/drm_vm.c
sys/dev/drm/i915/Makefile
sys/dev/drm/i915_dma.c
sys/dev/drm/i915_drm.h
sys/dev/drm/i915_drv.c
sys/dev/drm/i915_drv.h
sys/dev/drm/i915_irq.c
sys/dev/drm/i915_mem.c
sys/dev/drm/i915_reg.h [new file with mode: 0644]
sys/dev/drm/i915_suspend.c [new file with mode: 0644]
sys/dev/drm/mach64_dma.c
sys/dev/drm/mach64_drm.h
sys/dev/drm/mach64_drv.c
sys/dev/drm/mach64_drv.h
sys/dev/drm/mach64_irq.c
sys/dev/drm/mach64_state.c
sys/dev/drm/mga_dma.c
sys/dev/drm/mga_drm.h
sys/dev/drm/mga_drv.c
sys/dev/drm/mga_drv.h
sys/dev/drm/mga_irq.c
sys/dev/drm/mga_state.c
sys/dev/drm/mga_ucode.h
sys/dev/drm/mga_warp.c
sys/dev/drm/r128_cce.c
sys/dev/drm/r128_drm.h
sys/dev/drm/r128_drv.c
sys/dev/drm/r128_drv.h
sys/dev/drm/r128_irq.c
sys/dev/drm/r128_state.c
sys/dev/drm/r300_cmdbuf.c
sys/dev/drm/r300_reg.h
sys/dev/drm/r600_cp.c [new file with mode: 0644]
sys/dev/drm/r600_microcode.h [new file with mode: 0644]
sys/dev/drm/radeon/Makefile
sys/dev/drm/radeon_cp.c
sys/dev/drm/radeon_drm.h
sys/dev/drm/radeon_drv.c
sys/dev/drm/radeon_drv.h
sys/dev/drm/radeon_irq.c
sys/dev/drm/radeon_mem.c
sys/dev/drm/radeon_microcode.h [new file with mode: 0644]
sys/dev/drm/radeon_state.c
sys/dev/drm/savage_bci.c
sys/dev/drm/savage_drm.h
sys/dev/drm/savage_drv.c
sys/dev/drm/savage_drv.h
sys/dev/drm/savage_state.c
sys/dev/drm/sis_drm.h
sys/dev/drm/sis_drv.c
sys/dev/drm/sis_drv.h
sys/dev/drm/sis_ds.c
sys/dev/drm/sis_ds.h
sys/dev/drm/sis_mm.c
sys/dev/drm/tdfx_drv.c
sys/dev/drm/tdfx_drv.h

index 6672441..ce3ebf8 100644 (file)
@@ -1521,6 +1521,7 @@ dev/drm/i915_dma.c                        optional i915drm drm
 dev/drm/i915_drv.c                     optional i915drm drm
 dev/drm/i915_irq.c                     optional i915drm drm
 dev/drm/i915_mem.c                     optional i915drm drm
+dev/drm/i915_suspend.c                 optional i915drm drm
 dev/drm/mach64_dma.c                   optional mach64drm drm
 dev/drm/mach64_drv.c                   optional mach64drm drm
 dev/drm/mach64_irq.c                   optional mach64drm drm
@@ -1535,6 +1536,7 @@ dev/drm/r128_drv.c                        optional r128drm drm
 dev/drm/r128_state.c                   optional r128drm drm
 dev/drm/r128_irq.c                     optional r128drm drm
 dev/drm/r300_cmdbuf.c                  optional radeondrm drm
+dev/drm/r600_cp.c                      optional radeondrm drm
 dev/drm/radeon_cp.c                    optional radeondrm drm
 dev/drm/radeon_drv.c                   optional radeondrm drm
 dev/drm/radeon_state.c                 optional radeondrm drm
index 487348f..e75eafd 100644 (file)
@@ -24,7 +24,6 @@
  * Authors:
  *   Gareth Hughes <gareth@valinux.com>
  *
- * $DragonFly: src/sys/dev/drm/ati_pcigart.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file ati_pcigart.c
  * address space with addresses remapped to system memory.
  */
 
-#include "drmP.h"
+#include "dev/drm/drmP.h"
 
 #define ATI_PCIGART_PAGE_SIZE          4096    /* PCI GART page size */
+#define ATI_PCIGART_PAGE_MASK          (~(ATI_PCIGART_PAGE_SIZE-1))
 
-int drm_ati_pcigart_init(drm_device_t *dev, struct drm_ati_pcigart_info *gart_info)
+#define ATI_PCIE_WRITE 0x4
+#define ATI_PCIE_READ 0x8
+
+static void
+drm_ati_alloc_pcigart_table_cb(void *arg, bus_dma_segment_t *segs,
+                              int nsegs, int error)
 {
-       unsigned long pages;
-       u32 *pci_gart = NULL, page_base;
-       int i, j;
+       struct drm_dma_handle *dmah = arg;
+
+       if (error != 0)
+               return;
+
+       KASSERT(nsegs == 1,
+           ("drm_ati_alloc_pcigart_table_cb: bad dma segment count"));
+
+       dmah->busaddr = segs[0].ds_addr;
+}
+
+static int
+drm_ati_alloc_pcigart_table(struct drm_device *dev,
+                           struct drm_ati_pcigart_info *gart_info)
+{
+       struct drm_dma_handle *dmah;
+       int flags, ret;
+
+       dmah = malloc(sizeof(struct drm_dma_handle), DRM_MEM_DMA,
+           M_ZERO | M_NOWAIT);
+       if (dmah == NULL)
+               return ENOMEM;
+
+       DRM_UNLOCK();
+       ret = bus_dma_tag_create(NULL, PAGE_SIZE, 0, /* tag, align, boundary */
+           gart_info->table_mask, BUS_SPACE_MAXADDR, /* lowaddr, highaddr */
+           NULL, NULL, /* filtfunc, filtfuncargs */
+           gart_info->table_size, 1, /* maxsize, nsegs */
+           gart_info->table_size, /* maxsegsize */
+           0, /* flags */
+           &dmah->tag);
+       if (ret != 0) {
+               free(dmah, DRM_MEM_DMA);
+               return ENOMEM;
+       }
 
+       flags = BUS_DMA_WAITOK | BUS_DMA_ZERO;
+
+#if 0
+       if (gart_info->gart_reg_if == DRM_ATI_GART_IGP)
+           flags |= BUS_DMA_NOCACHE;
+#endif
+       
+       ret = bus_dmamem_alloc(dmah->tag, &dmah->vaddr, flags, &dmah->map);
+       if (ret != 0) {
+               bus_dma_tag_destroy(dmah->tag);
+               free(dmah, DRM_MEM_DMA);
+               return ENOMEM;
+       }
+       DRM_LOCK();
+
+       ret = bus_dmamap_load(dmah->tag, dmah->map, dmah->vaddr,
+           gart_info->table_size, drm_ati_alloc_pcigart_table_cb, dmah,
+           BUS_DMA_NOWAIT);
+       if (ret != 0) {
+               bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map);
+               bus_dma_tag_destroy(dmah->tag);
+               free(dmah, DRM_MEM_DMA);
+               return ENOMEM;
+       }
+
+       gart_info->dmah = dmah;
+
+       return 0;
+}
+
+static void
+drm_ati_free_pcigart_table(struct drm_device *dev,
+                          struct drm_ati_pcigart_info *gart_info)
+{
+       struct drm_dma_handle *dmah = gart_info->dmah;
+
+       bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map);
+       bus_dma_tag_destroy(dmah->tag);
+       free(dmah, DRM_MEM_DMA);
+       gart_info->dmah = NULL;
+}
+
+int
+drm_ati_pcigart_cleanup(struct drm_device *dev,
+                       struct drm_ati_pcigart_info *gart_info)
+{
+       /* we need to support large memory configurations */
        if (dev->sg == NULL) {
-               DRM_ERROR( "no scatter/gather memory!\n" );
+               DRM_ERROR("no scatter/gather memory!\n");
                return 0;
        }
 
+       if (gart_info->bus_addr) {
+               if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
+                       gart_info->bus_addr = 0;
+                       if (gart_info->dmah)
+                               drm_ati_free_pcigart_table(dev, gart_info);
+               }
+       }
+
+       return 1;
+}
+
+int
+drm_ati_pcigart_init(struct drm_device *dev,
+                    struct drm_ati_pcigart_info *gart_info)
+{
+       void *address = NULL;
+       unsigned long pages;
+       u32 *pci_gart, page_base;
+       dma_addr_t bus_address = 0;
+       dma_addr_t entry_addr;
+       int i, j, ret = 0;
+       int max_pages;
+
+       /* we need to support large memory configurations */
+       if (dev->sg == NULL) {
+               DRM_ERROR("no scatter/gather memory!\n");
+               goto done;
+       }
+
        if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
-               /* GART table in system memory */
-               dev->sg->dmah = drm_pci_alloc(dev, gart_info->table_size, 0,
-                   0xfffffffful);
-               if (dev->sg->dmah == NULL) {
-                       DRM_ERROR("cannot allocate PCI GART table!\n");
-                       return 0;
+               DRM_DEBUG("PCI: no table in VRAM: using normal RAM\n");
+
+               ret = drm_ati_alloc_pcigart_table(dev, gart_info);
+               if (ret) {
+                       DRM_ERROR("cannot allocate PCI GART page!\n");
+                       goto done;
                }
-       
-               gart_info->addr = (void *)dev->sg->dmah->vaddr;
-               gart_info->bus_addr = dev->sg->dmah->busaddr;
-               pci_gart = (u32 *)dev->sg->dmah->vaddr;
+
+               address = (void *)gart_info->dmah->vaddr;
+               bus_address = gart_info->dmah->busaddr;
        } else {
-               /* GART table in framebuffer memory */
-               pci_gart = gart_info->addr;
+               address = gart_info->addr;
+               bus_address = gart_info->bus_addr;
+               DRM_DEBUG("PCI: Gart Table: VRAM %08X mapped at %08lX\n",
+                         (unsigned int)bus_address, (unsigned long)address);
        }
-       
-       pages = DRM_MIN(dev->sg->pages, gart_info->table_size / sizeof(u32));
 
-       bzero(pci_gart, gart_info->table_size);
+       pci_gart = (u32 *) address;
 
-       KASSERT(PAGE_SIZE >= ATI_PCIGART_PAGE_SIZE, ("page size too small"));
+       max_pages = (gart_info->table_size / sizeof(u32));
+       pages = (dev->sg->pages <= max_pages)
+           ? dev->sg->pages : max_pages;
+
+       memset(pci_gart, 0, max_pages * sizeof(u32));
 
-       for ( i = 0 ; i < pages ; i++ ) {
-               page_base = (u32) dev->sg->busaddr[i];
+       KASSERT(PAGE_SIZE >= ATI_PCIGART_PAGE_SIZE, ("page size too small"));
 
+       for (i = 0; i < pages; i++) {
+               entry_addr = dev->sg->busaddr[i];
                for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
+                       page_base = (u32) entry_addr & ATI_PCIGART_PAGE_MASK;
                        switch(gart_info->gart_reg_if) {
                        case DRM_ATI_GART_IGP:
-                               *pci_gart = cpu_to_le32(page_base | 0xc);
+                               page_base |=
+                                   (upper_32_bits(entry_addr) & 0xff) << 4;
+                               page_base |= 0xc;
                                break;
                        case DRM_ATI_GART_PCIE:
-                               *pci_gart = cpu_to_le32((page_base >> 8) | 0xc);
+                               page_base >>= 8;
+                               page_base |=
+                                   (upper_32_bits(entry_addr) & 0xff) << 24;
+                               page_base |= ATI_PCIE_READ | ATI_PCIE_WRITE;
                                break;
                        default:
-                               *pci_gart = cpu_to_le32(page_base);
+                       case DRM_ATI_GART_PCI:
                                break;
                        }
+                       *pci_gart = cpu_to_le32(page_base);
                        pci_gart++;
-                       page_base += ATI_PCIGART_PAGE_SIZE;
+                       entry_addr += ATI_PCIGART_PAGE_SIZE;
                }
        }
 
-       DRM_MEMORYBARRIER();
+       ret = 1;
 
-       return 1;
-}
-
-int drm_ati_pcigart_cleanup(drm_device_t *dev, struct drm_ati_pcigart_info *gart_info)
-{
-       if (dev->sg == NULL) {
-               DRM_ERROR( "no scatter/gather memory!\n" );
-               return 0;
-       }
-
-       drm_pci_free(dev, dev->sg->dmah);
-
-       return 1;
+    done:
+       gart_info->addr = address;
+       gart_info->bus_addr = bus_address;
+       return ret;
 }
index c50f843..d4e8c90 100644 (file)
@@ -8,7 +8,7 @@
  * Dec 1999, Richard Henderson <rth@twiddle.net>, move to generic \c cmpxchg.
  */
 
-/*
+/*-
  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  * All rights reserved.
@@ -31,8 +31,6 @@
  * 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.
- *
- * $DragonFly: src/sys/dev/drm/drm.h,v 1.4 2008/04/05 18:12:29 hasso Exp $
  */
 
 /**
@@ -557,6 +555,20 @@ union drm_wait_vblank {
        struct drm_wait_vblank_reply reply;
 };
 
+
+#define _DRM_PRE_MODESET 1
+#define _DRM_POST_MODESET 2
+
+/**
+ * DRM_IOCTL_MODESET_CTL ioctl argument type
+ *
+ * \sa drmModesetCtl().
+ */
+struct drm_modeset_ctl {
+       uint32_t crtc;
+       uint32_t cmd;
+};
+
 /**
  * DRM_IOCTL_AGP_ENABLE ioctl argument type.
  *
@@ -632,8 +644,14 @@ struct drm_set_version {
 
 #define DRM_FENCE_FLAG_EMIT                0x00000001
 #define DRM_FENCE_FLAG_SHAREABLE           0x00000002
+/**
+ * On hardware with no interrupt events for operation completion,
+ * indicates that the kernel should sleep while waiting for any blocking
+ * operation to complete rather than spinning.
+ *
+ * Has no effect otherwise.
+ */
 #define DRM_FENCE_FLAG_WAIT_LAZY           0x00000004
-#define DRM_FENCE_FLAG_WAIT_IGNORE_SIGNALS 0x00000008
 #define DRM_FENCE_FLAG_NO_USER             0x00000010
 
 /* Reserved for driver use */
@@ -707,7 +725,14 @@ struct drm_fence_arg {
  */
 #define DRM_BO_FLAG_NO_MOVE     (1ULL << 8)
 
-/* Mask: Make sure the buffer is in cached memory when mapped
+/* Mask: Make sure the buffer is in cached memory when mapped.  In conjunction
+ * with DRM_BO_FLAG_CACHED it also allows the buffer to be bound into the GART
+ * with unsnooped PTEs instead of snooped, by using chipset-specific cache
+ * flushing at bind time.  A better name might be DRM_BO_FLAG_TT_UNSNOOPED,
+ * as the eviction to local memory (TTM unbind) on map is just a side effect
+ * to prevent aggressive cache prefetch from the GPU disturbing the cache
+ * management that the DRM is doing.
+ *
  * Flags: Acknowledge.
  * Buffers allocated with this flag should not be used for suballocators
  * This type may have issues on CPUs with over-aggressive caching
@@ -775,13 +800,12 @@ struct drm_fence_arg {
  * with it as a result of this operation
  */
 #define DRM_BO_HINT_DONT_FENCE  0x00000004
-/*
- * Sleep while waiting for the operation to complete.
- * Without this flag, the kernel will, instead, spin
- * until this operation has completed. I'm not sure
- * why you would ever want this, so please always
- * provide DRM_BO_HINT_WAIT_LAZY to any operation
- * which may block
+/**
+ * On hardware with no interrupt events for operation completion,
+ * indicates that the kernel should sleep while waiting for any blocking
+ * operation to complete rather than spinning.
+ *
+ * Has no effect otherwise.
  */
 #define DRM_BO_HINT_WAIT_LAZY   0x00000008
 /*
@@ -930,6 +954,36 @@ struct drm_mm_init_arg {
        uint64_t p_size;
 };
 
+struct drm_mm_info_arg {
+       unsigned int mem_type;
+       uint64_t p_size;
+};
+
+struct drm_gem_close {
+       /** Handle of the object to be closed. */
+       uint32_t handle;
+       uint32_t pad;
+};
+
+struct drm_gem_flink {
+       /** Handle for the object being named */
+       uint32_t handle;
+
+       /** Returned global name */
+       uint32_t name;
+};
+
+struct drm_gem_open {
+       /** Name of object being opened */
+       uint32_t name;
+
+       /** Returned handle for the object */
+       uint32_t handle;
+       
+       /** Returned size of the object */
+       uint64_t size;
+};
+
 /**
  * \name Ioctls Definitions
  */
@@ -949,6 +1003,11 @@ struct drm_mm_init_arg {
 #define DRM_IOCTL_GET_CLIENT            DRM_IOWR(0x05, struct drm_client)
 #define DRM_IOCTL_GET_STATS             DRM_IOR( 0x06, struct drm_stats)
 #define DRM_IOCTL_SET_VERSION          DRM_IOWR(0x07, struct drm_set_version)
+#define DRM_IOCTL_MODESET_CTL           DRM_IOW(0x08,  struct drm_modeset_ctl)
+
+#define DRM_IOCTL_GEM_CLOSE            DRM_IOW (0x09, struct drm_gem_close)
+#define DRM_IOCTL_GEM_FLINK            DRM_IOWR(0x0a, struct drm_gem_flink)
+#define DRM_IOCTL_GEM_OPEN             DRM_IOWR(0x0b, struct drm_gem_open)
 
 #define DRM_IOCTL_SET_UNIQUE           DRM_IOW( 0x10, struct drm_unique)
 #define DRM_IOCTL_AUTH_MAGIC           DRM_IOW( 0x11, struct drm_auth)
@@ -990,7 +1049,7 @@ struct drm_mm_init_arg {
 #define DRM_IOCTL_AGP_BIND             DRM_IOW( 0x36, struct drm_agp_binding)
 #define DRM_IOCTL_AGP_UNBIND           DRM_IOW( 0x37, struct drm_agp_binding)
 
-#define DRM_IOCTL_SG_ALLOC             DRM_IOW0x38, struct drm_scatter_gather)
+#define DRM_IOCTL_SG_ALLOC             DRM_IOWR(0x38, struct drm_scatter_gather)
 #define DRM_IOCTL_SG_FREE              DRM_IOW( 0x39, struct drm_scatter_gather)
 
 #define DRM_IOCTL_WAIT_VBLANK          DRM_IOWR(0x3a, union drm_wait_vblank)
@@ -1020,7 +1079,7 @@ struct drm_mm_init_arg {
 #define DRM_IOCTL_BO_INFO               DRM_IOWR(0xd4, struct drm_bo_reference_info_arg)
 #define DRM_IOCTL_BO_WAIT_IDLE          DRM_IOWR(0xd5, struct drm_bo_map_wait_idle_arg)
 #define DRM_IOCTL_BO_VERSION          DRM_IOR(0xd6, struct drm_bo_version_arg)
-
+#define DRM_IOCTL_MM_INFO               DRM_IOWR(0xd7, struct drm_mm_info_arg)
 
 /*@}*/
 
@@ -1036,8 +1095,7 @@ struct drm_mm_init_arg {
 #define DRM_COMMAND_END                 0xA0
 
 /* typedef area */
-#if !defined(__KERNEL__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
-    defined(__NetBSD__) || defined(__DragonFly__)
+#ifndef __KERNEL__
 typedef struct drm_clip_rect drm_clip_rect_t;
 typedef struct drm_tex_region drm_tex_region_t;
 typedef struct drm_hw_lock drm_hw_lock_t;
index 859e639..23ec340 100644 (file)
@@ -29,7 +29,6 @@
  *    Rickard E. (Rik) Faith <faith@valinux.com>
  *    Gareth Hughes <gareth@valinux.com>
  *
- * $DragonFly: src/sys/dev/drm/drmP.h,v 1.7 2008/07/24 01:27:47 swildner Exp $
  */
 
 #ifndef _DRM_P_H_
@@ -37,8 +36,8 @@
 
 #if defined(_KERNEL) || defined(__KERNEL__)
 
-typedef struct drm_device drm_device_t;
-typedef struct drm_file drm_file_t;
+struct drm_device;
+struct drm_file;
 
 #include <sys/param.h>
 #include <sys/queue.h>
@@ -67,72 +66,36 @@ typedef struct drm_file drm_file_t;
 #include <vm/vm_param.h>
 #include <machine/param.h>
 #include <machine/pmap.h>
-#ifdef __DragonFly__
 #include <sys/bus.h>
 #include <sys/resource.h>
-#else
-#include <machine/bus.h>
-#include <machine/resource.h>
-#endif
+#include <machine/specialreg.h>
 #include <machine/sysarch.h>
 #include <sys/endian.h>
 #include <sys/mman.h>
-#if defined(__FreeBSD__) || defined(__DragonFly__)
 #include <sys/rman.h>
 #include <sys/memrange.h>
-#if __FreeBSD_version >= 800004 || defined(__DragonFly__)
 #include <dev/agp/agpvar.h>
-#else /* __FreeBSD_version >= 800004 */
-#include <pci/agpvar.h>
-#endif /* __FreeBSD_version >= 800004 */
-#include <sys/agpio.h>
-#if defined(__DragonFly__)
-#include <sys/thread2.h>
 #include <sys/device.h>
+#include <sys/agpio.h>
+#include <sys/spinlock.h>
 #include <sys/spinlock2.h>
 #include <bus/pci/pcivar.h>
+#include <bus/pci/pcireg.h>
 #include <sys/selinfo.h>
-#elif __FreeBSD_version >= 500000
-#include <sys/mutex.h>
-#include <dev/pci/pcivar.h>
-#include <sys/selinfo.h>
-#else /* __FreeBSD_version >= 500000 */
-#include <pci/pcivar.h>
-#include <sys/select.h>
-#endif /* __FreeBSD_version < 500000 */
-#elif defined(__NetBSD__)
-#include <machine/mtrr.h>
-#include <sys/vnode.h>
-#include <sys/select.h>
-#include <sys/device.h>
-#include <sys/resourcevar.h>
-#include <sys/lkm.h>
-#include <sys/agpio.h>
-#include <sys/ttycom.h>
-#include <uvm/uvm.h>
-#include <dev/pci/pcireg.h>
-#include <dev/pci/pcivar.h>
-#include <dev/pci/agpvar.h>
-#elif defined(__OpenBSD__)
-#include <sys/lkm.h>
-#include <uvm/uvm.h>
-#endif
 #include <sys/bus.h>
 
-#include "drm.h"
-#include "drm_linux_list.h"
-#include "drm_atomic.h"
-#include "drm_internal.h"
+#include "dev/drm/drm.h"
+#include "dev/drm/drm_linux_list.h"
+#include "dev/drm/drm_atomic.h"
+#include "dev/drm/drm_internal.h"
 
-#ifdef __FreeBSD__
 #include <opt_drm.h>
 #ifdef DRM_DEBUG
 #undef DRM_DEBUG
 #define DRM_DEBUG_DEFAULT_ON 1
 #endif /* DRM_DEBUG */
-#endif
 
-#if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__)
+#if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__) && !defined(__DragonFly__) /* XXX */
 #include <sys/file.h>
 #include <sys/proc.h>
 #include <machine/../linux/linux.h>
@@ -145,31 +108,39 @@ typedef struct drm_file drm_file_t;
 #define DRM_LINUX 0
 #endif
 
+/* driver capabilities and requirements mask */
+#define DRIVER_USE_AGP     0x1
+#define DRIVER_REQUIRE_AGP 0x2
+#define DRIVER_USE_MTRR    0x4
+#define DRIVER_PCI_DMA     0x8
+#define DRIVER_SG          0x10
+#define DRIVER_HAVE_DMA    0x20
+#define DRIVER_HAVE_IRQ    0x40
+#define DRIVER_DMA_QUEUE   0x100
+
+
 #define DRM_HASH_SIZE        16 /* Size of key hash table                */
 #define DRM_KERNEL_CONTEXT    0         /* Change drm_resctx if changed          */
 #define DRM_RESERVED_CONTEXTS 1         /* Change drm_resctx if changed          */
 
-#define DRM_MEM_DMA       0
-#define DRM_MEM_SAREA     1
-#define DRM_MEM_DRIVER    2
-#define DRM_MEM_MAGIC     3
-#define DRM_MEM_IOCTLS    4
-#define DRM_MEM_MAPS      5
-#define DRM_MEM_BUFS      6
-#define DRM_MEM_SEGS      7
-#define DRM_MEM_PAGES     8
-#define DRM_MEM_FILES    9
-#define DRM_MEM_QUEUES   10
-#define DRM_MEM_CMDS     11
-#define DRM_MEM_MAPPINGS  12
-#define DRM_MEM_BUFLISTS  13
-#define DRM_MEM_AGPLISTS  14
-#define DRM_MEM_TOTALAGP  15
-#define DRM_MEM_BOUNDAGP  16
-#define DRM_MEM_CTXBITMAP 17
-#define DRM_MEM_STUB     18
-#define DRM_MEM_SGLISTS          19
-#define DRM_MEM_DRAWABLE  20
+MALLOC_DECLARE(DRM_MEM_DMA);
+MALLOC_DECLARE(DRM_MEM_SAREA);
+MALLOC_DECLARE(DRM_MEM_DRIVER);
+MALLOC_DECLARE(DRM_MEM_MAGIC);
+MALLOC_DECLARE(DRM_MEM_IOCTLS);
+MALLOC_DECLARE(DRM_MEM_MAPS);
+MALLOC_DECLARE(DRM_MEM_BUFS);
+MALLOC_DECLARE(DRM_MEM_SEGS);
+MALLOC_DECLARE(DRM_MEM_PAGES);
+MALLOC_DECLARE(DRM_MEM_FILES);
+MALLOC_DECLARE(DRM_MEM_QUEUES);
+MALLOC_DECLARE(DRM_MEM_CMDS);
+MALLOC_DECLARE(DRM_MEM_MAPPINGS);
+MALLOC_DECLARE(DRM_MEM_BUFLISTS);
+MALLOC_DECLARE(DRM_MEM_AGPLISTS);
+MALLOC_DECLARE(DRM_MEM_CTXBITMAP);
+MALLOC_DECLARE(DRM_MEM_SGLISTS);
+MALLOC_DECLARE(DRM_MEM_DRAWABLE);
 
 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
 
@@ -180,8 +151,6 @@ typedef struct drm_file drm_file_t;
 
 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
 
-MALLOC_DECLARE(M_DRM);
-
 #define __OS_HAS_AGP   1
 
 #define DRM_DEV_MODE   (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
@@ -193,62 +162,23 @@ MALLOC_DECLARE(M_DRM);
 #define DRM_WAKEUP_INT(w)      wakeup(w)
 #define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
 
-#if defined(__FreeBSD__) && __FreeBSD_version < 502109
-#define bus_alloc_resource_any(dev, type, rid, flags) \
-       bus_alloc_resource(dev, type, rid, 0ul, ~0ul, 1, flags)
-#endif
-
-#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
-#define DRM_CURPROC            curthread
-#define DRM_STRUCTPROC         struct thread
-#define DRM_SPINTYPE           struct mtx
-#define DRM_SPININIT(l,name)   mtx_init(l, name, NULL, MTX_DEF)
-#define DRM_SPINUNINIT(l)      mtx_destroy(l)
-#define DRM_SPINLOCK(l)                mtx_lock(l)
-#define DRM_SPINUNLOCK(u)      mtx_unlock(u)
-#define DRM_SPINLOCK_IRQSAVE(l, irqflags) do {         \
-       mtx_lock(l);                                    \
-       (void)irqflags;                                 \
-} while (0)
-#define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u)
-#define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED)
-#define DRM_CURRENTPID         curthread->td_proc->p_pid
-#define DRM_LOCK()             mtx_lock(&dev->dev_lock)
-#define DRM_UNLOCK()           mtx_unlock(&dev->dev_lock)
-#define DRM_SYSCTL_HANDLER_ARGS        (SYSCTL_HANDLER_ARGS)
-#elif defined(__DragonFly__)
 #define DRM_CURPROC            curthread
 #define DRM_STRUCTPROC         struct thread
-#define DRM_SPINTYPE           struct spinlock
-#define DRM_SPININIT(l,name)   spin_init(l)
-#define DRM_SPINUNINIT(l)      spin_uninit(l)
-#define DRM_SPINLOCK(l)                spin_lock_wr(l)
-#define DRM_SPINUNLOCK(u)      spin_unlock_wr(u)
+#define DRM_SPINTYPE           struct lock
+#define DRM_SPININIT(l,name)   lockinit(l, name, 0, LK_CANRECURSE)
+#define DRM_SPINUNINIT(l)
+#define DRM_SPINLOCK(l)                lockmgr(l, LK_EXCLUSIVE|LK_RETRY|LK_CANRECURSE)
+#define DRM_SPINUNLOCK(u)      lockmgr(u, LK_RELEASE)
 #define DRM_SPINLOCK_IRQSAVE(l, irqflags) do {         \
-       DRM_SPINLOCK(l);                                        \
+       DRM_SPINLOCK(l);                                \
        (void)irqflags;                                 \
 } while (0)
 #define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) DRM_SPINUNLOCK(u)
 #define DRM_SPINLOCK_ASSERT(l)
 #define DRM_CURRENTPID         curthread->td_proc->p_pid
 #define DRM_LOCK()             DRM_SPINLOCK(&dev->dev_lock)
-#define DRM_UNLOCK()           DRM_SPINUNLOCK(&dev->dev_lock)
+#define DRM_UNLOCK()           DRM_SPINUNLOCK(&dev->dev_lock)
 #define DRM_SYSCTL_HANDLER_ARGS        (SYSCTL_HANDLER_ARGS)
-#else /* __FreeBSD__ && __FreeBSD_version >= 500000 || __DragonFly__ */
-#define DRM_CURPROC            curproc
-#define DRM_STRUCTPROC         struct proc
-#define DRM_SPINTYPE           struct simplelock
-#define DRM_SPININIT(l,name)
-#define DRM_SPINUNINIT(l)
-#define DRM_SPINLOCK(l)        
-#define DRM_SPINUNLOCK(u)
-#define DRM_SPINLOCK_ASSERT(l)
-#define DRM_CURRENTPID         curproc->p_pid
-#define DRM_LOCK()
-#define DRM_UNLOCK()
-#define DRM_SYSCTL_HANDLER_ARGS        SYSCTL_HANDLER_ARGS
-#define spldrm()               spltty()
-#endif /* __NetBSD__ || __OpenBSD__ */
 
 #define DRM_IRQ_ARGS           void *arg
 typedef void                   irqreturn_t;
@@ -262,16 +192,8 @@ enum {
 };
 #define DRM_AGP_MEM            struct agp_memory_info
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
-#elif defined(__NetBSD__)
-#define drm_get_device_from_kdev(_kdev) device_lookup(&drm_cd, minor(_kdev))
-#elif defined(__OpenBSD__)
-#define drm_get_device_from_kdev(_kdev) device_lookup(&drm_cd, \
-    minor(_kdev)))->dv_cfdata->cf_driver->cd_devs[minor(_kdev)]
-#endif
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
 #define PAGE_ALIGN(addr) round_page(addr)
 /* DRM_SUSER returns true if the user is superuser */
 #define DRM_SUSER(p)           (priv_check(p, PRIV_DRIVER) == 0)
@@ -279,29 +201,6 @@ enum {
 #define DRM_MTRR_WC            MDF_WRITECOMBINE
 #define jiffies                        ticks
 
-#else /* __FreeBSD__ || __DragonFly__ */
-
-#define CDEV_MAJOR             34
-#define PAGE_ALIGN(addr)       (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
-/* DRM_SUSER returns true if the user is superuser */
-#define DRM_SUSER(p)           (suser(p->p_ucred, &p->p_acflag) == 0)
-#define DRM_AGP_FIND_DEVICE()  agp_find_device(0)
-#define DRM_MTRR_WC            MTRR_TYPE_WC
-#define jiffies                        hardclock_ticks
-
-typedef drm_device_t *device_t;
-extern struct cfdriver drm_cd;
-#endif /* !__FreeBSD__ && !__DragonFly__ */
-
-/* Capabilities taken from src/sys/dev/pci/pcireg.h. */
-#ifndef PCIY_AGP
-#define PCIY_AGP       0x02
-#endif
-
-#ifndef PCIY_EXPRESS
-#define PCIY_EXPRESS   0x10
-#endif
-
 typedef unsigned long dma_addr_t;
 typedef u_int64_t u64;
 typedef u_int32_t u32;
@@ -330,44 +229,28 @@ typedef u_int8_t u8;
                                        "lock; addl $0,0(%%rsp)" : : : "memory");
 #endif
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
 #define DRM_READ8(map, offset)                                         \
-       *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset))
+       *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) +           \
+           (vm_offset_t)(offset))
 #define DRM_READ16(map, offset)                                                \
-       *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset))
+       *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) +          \
+           (vm_offset_t)(offset))
 #define DRM_READ32(map, offset)                                                \
-       *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset))
+       *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) +          \
+           (vm_offset_t)(offset))
 #define DRM_WRITE8(map, offset, val)                                   \
-       *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset)) = val
+       *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) +           \
+           (vm_offset_t)(offset)) = val
 #define DRM_WRITE16(map, offset, val)                                  \
-       *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset)) = val
+       *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) +          \
+           (vm_offset_t)(offset)) = val
 #define DRM_WRITE32(map, offset, val)                                  \
-       *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset)) = val
+       *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) +          \
+           (vm_offset_t)(offset)) = val
 
 #define DRM_VERIFYAREA_READ( uaddr, size )             \
        (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
 
-#else /* __FreeBSD__ || __DragonFly__ */
-
-typedef vaddr_t vm_offset_t;
-
-#define DRM_READ8(map, offset)         \
-       bus_space_read_1( (map)->bst, (map)->bsh, (offset))
-#define DRM_READ16(map, offset)                \
-       bus_space_read_2( (map)->bst, (map)->bsh, (offset))
-#define DRM_READ32(map, offset)                \
-       bus_space_read_4( (map)->bst, (map)->bsh, (offset))
-#define DRM_WRITE8(map, offset, val)   \
-       bus_space_write_1((map)->bst, (map)->bsh, (offset), (val))
-#define DRM_WRITE16(map, offset, val)  \
-       bus_space_write_2((map)->bst, (map)->bsh, (offset), (val))
-#define DRM_WRITE32(map, offset, val)  \
-       bus_space_write_4((map)->bst, (map)->bsh, (offset), (val))
-
-#define DRM_VERIFYAREA_READ( uaddr, size )             \
-       (!uvm_useracc((caddr_t)uaddr, size, VM_PROT_READ))
-#endif /* !__FreeBSD__ && !__DragonFly__ */
-
 #define DRM_COPY_TO_USER(user, kern, size) \
        copyout(kern, user, size)
 #define DRM_COPY_FROM_USER(kern, user, size) \
@@ -376,13 +259,8 @@ typedef vaddr_t vm_offset_t;
        copyin(arg2, arg1, arg3)
 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3)   \
        copyout(arg2, arg1, arg3)
-#if __FreeBSD_version > 500000
 #define DRM_GET_USER_UNCHECKED(val, uaddr)             \
        ((val) = fuword32(uaddr), 0)
-#else
-#define DRM_GET_USER_UNCHECKED(val, uaddr)             \
-       ((val) = fuword(uaddr), 0)
-#endif
 
 #define cpu_to_le32(x) htole32(x)
 #define le32_to_cpu(x) le32toh(x)
@@ -405,53 +283,30 @@ do {                                                                      \
        }                                                               \
 } while (0)
 
-#if defined(__FreeBSD__) && __FreeBSD_version > 500000
 /* Returns -errno to shared code */
 #define DRM_WAIT_ON( ret, queue, timeout, condition )          \
 for ( ret = 0 ; !ret && !(condition) ; ) {                     \
        DRM_UNLOCK();                                           \
-       mtx_lock(&dev->irq_lock);                               \
-       if (!(condition))                                       \
-          ret = -mtx_sleep(&(queue), &dev->irq_lock,           \
-                        PZERO | PCATCH, "drmwtq", (timeout));  \
-       mtx_unlock(&dev->irq_lock);                             \
-       DRM_LOCK();                                             \
-}
-#elif defined(__DragonFly__)
-#define DRM_WAIT_ON( ret, queue, timeout, condition )          \
-for ( ret = 0 ; !ret && !(condition) ; ) {                     \
-       DRM_UNLOCK();                                           \
        lwkt_serialize_enter(&dev->irq_lock);                   \
        if (!(condition)) {                                     \
-          crit_enter();                                        \
-          tsleep_interlock(&(queue));                          \
-          lwkt_serialize_exit(&dev->irq_lock);                 \
-          ret = -tsleep(&(queue), PCATCH,                      \
-                        "drmwtq", (timeout));                  \
-          crit_exit();                                         \
+            crit_enter();                                      \
+            tsleep_interlock(&(queue));                                \
+            lwkt_serialize_exit(&dev->irq_lock);               \
+            ret = -tsleep(&(queue), PCATCH,                    \
+                         "drmwtq", (timeout));                 \
+            crit_exit();                                       \
        } else {                                                \
                lwkt_serialize_exit(&dev->irq_lock);            \
        }                                                       \
        DRM_LOCK();                                             \
 }
-#else
-/* Returns -errno to shared code */
-#define DRM_WAIT_ON( ret, queue, timeout, condition )  \
-for ( ret = 0 ; !ret && !(condition) ; ) {             \
-        int s = spldrm();                              \
-       if (!(condition))                               \
-          ret = -tsleep( &(queue), PZERO | PCATCH,     \
-                        "drmwtq", (timeout) );         \
-       splx(s);                                        \
-}
-#endif
 
-#ifdef __DragonFly__
 #define printf kprintf
 #define snprintf ksnprintf
 #define sscanf ksscanf
 #define malloc kmalloc
 #define realloc        krealloc
+#define reallocf krealloc      /* XXX XXX XXX */
 
 __inline static void
 free(void *addr, struct malloc_type *type)
@@ -459,18 +314,17 @@ free(void *addr, struct malloc_type *type)
        if (addr != NULL)
                kfree(addr, type);
 }
-#endif
 
-#define DRM_ERROR(fmt, arg...) \
+#define DRM_ERROR(fmt, ...) \
        printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt,           \
-           DRM_CURRENTPID, __func__ , ## arg)
-
-#define DRM_INFO(fmt, arg...)  printf("info: [" DRM_NAME "] " fmt , ## arg)
+           DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
 
-#define DRM_DEBUG(fmt, arg...) do {                                    \
+#define DRM_INFO(fmt, ...)  printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
+       
+#define DRM_DEBUG(fmt, ...) do {                                       \
        if (drm_debug_flag)                                             \
                printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID,  \
-                       __func__ , ## arg);                             \
+                       __func__ , ##__VA_ARGS__);                      \
 } while (0)
 
 typedef struct drm_pci_id_list
@@ -481,12 +335,19 @@ typedef struct drm_pci_id_list
        char *name;
 } drm_pci_id_list_t;
 
+struct drm_msi_blacklist_entry
+{
+       int vendor;
+       int device;
+};
+
 #define DRM_AUTH       0x1
 #define DRM_MASTER     0x2
 #define DRM_ROOT_ONLY  0x4
 typedef struct drm_ioctl_desc {
        unsigned long cmd;
-       int (*func)(drm_device_t *dev, void *data, struct drm_file *file_priv);
+       int (*func)(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv);
        int flags;
 } drm_ioctl_desc_t;
 /**
@@ -544,12 +405,8 @@ typedef struct drm_freelist {
 typedef struct drm_dma_handle {
        void *vaddr;
        bus_addr_t busaddr;
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        bus_dma_tag_t tag;
        bus_dmamap_t map;
-#elif defined(__NetBSD__)
-       bus_dma_segment_t seg;
-#endif
 } drm_dma_handle_t;
 
 typedef struct drm_buf_entry {
@@ -566,6 +423,7 @@ typedef struct drm_buf_entry {
 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
 struct drm_file {
        TAILQ_ENTRY(drm_file) link;
+       struct drm_device *dev;
        int               authenticated;
        int               master;
        int               minor;
@@ -578,13 +436,14 @@ struct drm_file {
 };
 
 typedef struct drm_lock_data {
-       drm_hw_lock_t     *hw_lock;     /* Hardware lock                   */
+       struct drm_hw_lock      *hw_lock;       /* Hardware lock                   */
        struct drm_file   *file_priv;   /* Unique identifier of holding process (NULL is kernel)*/
        int               lock_queue;   /* Queue of blocked processes      */
        unsigned long     lock_time;    /* Time of last lock in jiffies    */
 } drm_lock_data_t;
 
-/* This structure, in the drm_device_t, is always initialized while the device
+/* This structure, in the struct drm_device, is always initialized while the
+ * device
  * is open.  dev->dma_lock protects the incrementing of dev->buf_use, which
  * when set marks that no further bufs may be allocated until device teardown
  * occurs (when the last open of the device has closed).  The high/low
@@ -628,11 +487,11 @@ typedef struct drm_agp_head {
 } drm_agp_head_t;
 
 typedef struct drm_sg_mem {
-       unsigned long   handle;
-       void            *virtual;
-       int             pages;
-       dma_addr_t      *busaddr;
-       drm_dma_handle_t *dmah; /* Handle to PCI memory for ATI PCIGART table */
+       unsigned long             handle;
+       void                     *virtual;
+       int                       pages;
+       dma_addr_t               *busaddr;
+       struct drm_dma_handle    *dmah;         /* Handle to PCI memory  */
 } drm_sg_mem_t;
 
 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
@@ -640,8 +499,8 @@ typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
 typedef struct drm_local_map {
        unsigned long   offset;  /* Physical address (0 for SAREA)*/
        unsigned long   size;    /* Physical size (bytes)           */
-       drm_map_type_t  type;    /* Type of memory mapped                   */
-       drm_map_flags_t flags;   /* Flags                                   */
+       enum drm_map_type       type;    /* Type of memory mapped                   */
+       enum drm_map_flags      flags;   /* Flags                                   */
        void            *handle; /* User-space: "Handle" to pass to mmap    */
                                 /* Kernel-space: kernel-virtual address    */
        int             mtrr;    /* Boolean: MTRR used */
@@ -662,6 +521,19 @@ typedef struct drm_vbl_sig {
        int             pid;
 } drm_vbl_sig_t;
 
+struct drm_vblank_info {
+       wait_queue_head_t queue;        /* vblank wait queue */
+       atomic_t count;                 /* number of VBLANK interrupts */
+                                       /* (driver must alloc the right number of counters) */
+       struct drm_vbl_sig_list sigs;   /* signal list to send on VBLANK */
+       atomic_t refcount;              /* number of users of vblank interrupts */
+       u32 last;                       /* protected by dev->vbl_lock, used */
+                                       /* for wraparound handling */
+       int enabled;                    /* so we don't call enable more than */
+                                       /* once per disable */
+       int inmodeset;                  /* Display driver is setting mode */
+};
+
 /* location of GART table */
 #define DRM_ATI_GART_MAIN 1
 #define DRM_ATI_GART_FB   2
@@ -675,38 +547,50 @@ struct drm_ati_pcigart_info {
        int gart_reg_if;
        void *addr;
        dma_addr_t bus_addr;
+       dma_addr_t table_mask;
+       dma_addr_t member_mask;
+       struct drm_dma_handle *table_handle;
        drm_local_map_t mapping;
        int table_size;
+       struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */
 };
 
+#ifndef DMA_BIT_MASK
+#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
+#endif
+
+#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
+
 struct drm_driver_info {
        int     (*load)(struct drm_device *, unsigned long flags);
        int     (*firstopen)(struct drm_device *);
-       int     (*open)(struct drm_device *, drm_file_t *);
+       int     (*open)(struct drm_device *, struct drm_file *);
        void    (*preclose)(struct drm_device *, struct drm_file *file_priv);
-       void    (*postclose)(struct drm_device *, drm_file_t *);
+       void    (*postclose)(struct drm_device *, struct drm_file *);
        void    (*lastclose)(struct drm_device *);
        int     (*unload)(struct drm_device *);
        void    (*reclaim_buffers_locked)(struct drm_device *,
                                          struct drm_file *file_priv);
-       int     (*dma_ioctl)(drm_device_t *dev, void *data, struct drm_file *file_priv);
+       int     (*dma_ioctl)(struct drm_device *dev, void *data,
+                            struct drm_file *file_priv);
        void    (*dma_ready)(struct drm_device *);
        int     (*dma_quiescent)(struct drm_device *);
        int     (*dma_flush_block_and_flush)(struct drm_device *, int context,
-                                            drm_lock_flags_t flags);
+                                            enum drm_lock_flags flags);
        int     (*dma_flush_unblock)(struct drm_device *, int context,
-                                    drm_lock_flags_t flags);
+                                    enum drm_lock_flags flags);
        int     (*context_ctor)(struct drm_device *dev, int context);
        int     (*context_dtor)(struct drm_device *dev, int context);
        int     (*kernel_context_switch)(struct drm_device *dev, int old,
                                         int new);
        int     (*kernel_context_switch_unlock)(struct drm_device *dev);
-       void    (*irq_preinstall)(drm_device_t *dev);
-       void    (*irq_postinstall)(drm_device_t *dev);
-       void    (*irq_uninstall)(drm_device_t *dev);
+       void    (*irq_preinstall)(struct drm_device *dev);
+       int     (*irq_postinstall)(struct drm_device *dev);
+       void    (*irq_uninstall)(struct drm_device *dev);
        void    (*irq_handler)(DRM_IRQ_ARGS);
-       int     (*vblank_wait)(drm_device_t *dev, unsigned int *sequence);
-       int     (*vblank_wait2)(drm_device_t *dev, unsigned int *sequence);
+       u32     (*get_vblank_counter)(struct drm_device *dev, int crtc);
+       int     (*enable_vblank)(struct drm_device *dev, int crtc);
+       void    (*disable_vblank)(struct drm_device *dev, int crtc);
 
        drm_pci_id_list_t *id_entry;    /* PCI ID, name, and chipset private */
 
@@ -735,30 +619,17 @@ struct drm_driver_info {
        const char *desc;               /* Longer driver name              */
        const char *date;               /* Date of last major changes.     */
 
-       unsigned use_agp :1;
-       unsigned require_agp :1;
-       unsigned use_sg :1;
-       unsigned use_dma :1;
-       unsigned use_pci_dma :1;
-       unsigned use_dma_queue :1;
-       unsigned use_irq :1;
-       unsigned use_vbl_irq :1;
-       unsigned use_vbl_irq2 :1;
-       unsigned use_mtrr :1;
+       u32 driver_features;
 };
 
 /* Length for the array of resource pointers for drm_get_resource_*. */
-#define DRM_MAX_PCI_RESOURCE   3
+#define DRM_MAX_PCI_RESOURCE   6
 
 /** 
  * DRM device functions structure
  */
 struct drm_device {
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-       struct device     device; /* softc is an extension of struct device */
-#endif
-
-       struct drm_driver_info driver;
+       struct drm_driver_info *driver;
        drm_pci_id_list_t *id_entry;    /* PCI ID, name, and chipset private */
 
        u_int16_t pci_device;           /* PCI device id */
@@ -766,24 +637,17 @@ struct drm_device {
 
        char              *unique;      /* Unique identifier: e.g., busid  */
        int               unique_len;   /* Length of unique field          */
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        device_t          device;       /* Device instance from newbus     */
-#endif
        struct cdev       *devnode;     /* Device number for mknod         */
        int               if_version;   /* Highest interface version set */
 
        int               flags;        /* Flags to open(2)                */
 
                                /* Locks */
-#if defined(__FreeBSD__) && __FreeBSD_version > 500000
-       struct mtx        dma_lock;     /* protects dev->dma */
-       struct mtx        irq_lock;     /* protects irq condition checks */
-       struct mtx        dev_lock;     /* protects everything else */
-#elif defined(__DragonFly__)
-       struct spinlock   dma_lock;     /* protects dev->dma */
+       DRM_SPINTYPE      vbl_lock;     /* protects vblank operations */
+       DRM_SPINTYPE      dma_lock;     /* protects dev->dma */
        struct lwkt_serialize irq_lock; /* protects irq condition checks */
-       struct spinlock   dev_lock;     /* protects everything else */
-#endif
+       DRM_SPINTYPE      dev_lock;     /* protects everything else */
        DRM_SPINTYPE      drw_lock;
 
                                /* Usage Counters */
@@ -792,7 +656,7 @@ struct drm_device {
 
                                /* Performance counters */
        unsigned long     counters;
-       drm_stat_type_t   types[15];
+       enum drm_stat_type      types[15];
        atomic_t          counts[15];
 
                                /* Authentication */
@@ -813,12 +677,9 @@ struct drm_device {
                                /* Context support */
        int               irq;          /* Interrupt used by board         */
        int               irq_enabled;  /* True if the irq handler is enabled */
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+       int               msi_enabled;  /* MSI enabled */
        int               irqrid;       /* Interrupt used by board */
        struct resource   *irqr;        /* Resource for interrupt used by board    */
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-       struct pci_attach_args  pa;
-#endif
        void              *irqh;        /* Handle from bus_setup_intr      */
 
        /* Storage of resource pointers for drm_get_resource_* */
@@ -832,15 +693,15 @@ struct drm_device {
 
        atomic_t          context_flag; /* Context swapping flag           */
        int               last_context; /* Last current context            */
-       int               vbl_queue;    /* vbl wait channel */
-       atomic_t          vbl_received;
-       atomic_t          vbl_received2;
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+       int               vblank_disable_allowed;
+       atomic_t          vbl_signal_pending;   /* number of signals pending on all crtcs */
+       struct callout    vblank_disable_timer;
+       u32               max_vblank_count;     /* size of vblank counter register */
+       struct drm_vblank_info *vblank;         /* per crtc vblank info */
+       int               num_crtcs;
+
        struct sigio      *buf_sigio;   /* Processes waiting for SIGIO     */
-#elif defined(__NetBSD__)
-       pid_t             buf_pgid;
-#endif
 
                                /* Sysctl support */
        struct drm_sysctl_info *sysctl;
@@ -852,232 +713,307 @@ struct drm_device {
        unsigned int      agp_buffer_token;
        drm_local_map_t   *agp_buffer_map;
 
-#ifdef __FreeBSD__
-       struct unrhdr     *drw_unrhdr;
-#endif
        /* RB tree of drawable infos */
        RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head;
-
-       struct task       locked_task;
-       void              (*locked_task_call)(drm_device_t *dev);
 };
 
+static __inline__ int drm_core_check_feature(struct drm_device *dev,
+                                            int feature)
+{
+       return ((dev->driver->driver_features & feature) ? 1 : 0);
+}
+
+#if __OS_HAS_AGP
+static inline int drm_core_has_AGP(struct drm_device *dev)
+{
+       return drm_core_check_feature(dev, DRIVER_USE_AGP);
+}
+#else
+#define drm_core_has_AGP(dev) (0)
+#endif
+
 extern int     drm_debug_flag;
 
 /* Device setup support (drm_drv.c) */
-#if defined(__FreeBSD__) || defined(__DragonFly__)
-int    drm_probe(device_t nbdev, drm_pci_id_list_t *idlist);
-int    drm_attach(device_t nbdev, drm_pci_id_list_t *idlist);
-int    drm_detach(device_t nbdev);
+int    drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
+int    drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
+void   drm_close(void *data);
+int    drm_detach(device_t kdev);
 d_ioctl_t drm_ioctl;
 d_open_t drm_open;
-d_close_t drm_close;
 d_read_t drm_read;
 d_poll_t drm_poll;
 d_mmap_t drm_mmap;
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-int    drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
-int    drm_attach(struct pci_attach_args *pa, dev_t kdev, drm_pci_id_list_t *idlist);
-dev_type_ioctl(drm_ioctl);
-dev_type_open(drm_open);
-dev_type_close(drm_close);
-dev_type_read(drm_read);
-dev_type_poll(drm_poll);
-dev_type_mmap(drm_mmap);
-#endif
-extern drm_local_map_t *drm_getsarea(drm_device_t *dev);
+extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
 
 /* File operations helpers (drm_fops.c) */
-#if defined(__FreeBSD__) || defined(__DragonFly__)
-extern int             drm_open_helper(struct cdev *kdev, int flags, int fmt, 
-                                        DRM_STRUCTPROC *p, drm_device_t *dev);
-extern drm_file_t      *drm_find_file_by_proc(drm_device_t *dev, 
-                                        DRM_STRUCTPROC *p);
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-extern int             drm_open_helper(dev_t kdev, int flags, int fmt, 
-                                       DRM_STRUCTPROC *p, drm_device_t *dev);
-extern drm_file_t      *drm_find_file_by_proc(drm_device_t *dev, 
-                                              DRM_STRUCTPROC *p);
-#endif /* __NetBSD__ || __OpenBSD__ */
+extern int             drm_open_helper(struct cdev *kdev, int flags, int fmt,
+                                        DRM_STRUCTPROC *p,
+                                       struct drm_device *dev);
+extern struct drm_file *drm_find_file_by_proc(struct drm_device *dev,
+                                       DRM_STRUCTPROC *p);
 
 /* Memory management support (drm_memory.c) */
 void   drm_mem_init(void);
 void   drm_mem_uninit(void);
-void   *drm_alloc(size_t size, int area);
-void   *drm_calloc(size_t nmemb, size_t size, int area);
-void   *drm_realloc(void *oldpt, size_t oldsize, size_t size,
-                                  int area);
-void   drm_free(void *pt, size_t size, int area);
-void   *drm_ioremap(drm_device_t *dev, drm_local_map_t *map);
+void   *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
+void   *drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
 void   drm_ioremapfree(drm_local_map_t *map);
 int    drm_mtrr_add(unsigned long offset, size_t size, int flags);
 int    drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
 
-int    drm_context_switch(drm_device_t *dev, int old, int new);
-int    drm_context_switch_complete(drm_device_t *dev, int new);
+int    drm_context_switch(struct drm_device *dev, int old, int new);
+int    drm_context_switch_complete(struct drm_device *dev, int new);
 
-int    drm_ctxbitmap_init(drm_device_t *dev);
-void   drm_ctxbitmap_cleanup(drm_device_t *dev);
-void   drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle);
-int    drm_ctxbitmap_next(drm_device_t *dev);
+int    drm_ctxbitmap_init(struct drm_device *dev);
+void   drm_ctxbitmap_cleanup(struct drm_device *dev);
+void   drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
+int    drm_ctxbitmap_next(struct drm_device *dev);
 
 /* Locking IOCTL support (drm_lock.c) */
-int    drm_lock_take(__volatile__ unsigned int *lock,
-                                   unsigned int context);
-int    drm_lock_transfer(drm_device_t *dev,
-                                       __volatile__ unsigned int *lock,
-                                       unsigned int context);
-int    drm_lock_free(drm_device_t *dev,
-                                   __volatile__ unsigned int *lock,
-                                   unsigned int context);
+int    drm_lock_take(struct drm_lock_data *lock_data,
+                     unsigned int context);
+int    drm_lock_transfer(struct drm_lock_data *lock_data,
+                         unsigned int context);
+int    drm_lock_free(struct drm_lock_data *lock_data,
+                     unsigned int context);
 
 /* Buffer management support (drm_bufs.c) */
-unsigned long drm_get_resource_start(drm_device_t *dev, unsigned int resource);
-unsigned long drm_get_resource_len(drm_device_t *dev, unsigned int resource);
-void   drm_rmmap(drm_device_t *dev, drm_local_map_t *map);
+unsigned long drm_get_resource_start(struct drm_device *dev,
+                                    unsigned int resource);
+unsigned long drm_get_resource_len(struct drm_device *dev,
+                                  unsigned int resource);
+void   drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
 int    drm_order(unsigned long size);
-int    drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size,
-                  drm_map_type_t type, drm_map_flags_t flags,
+int    drm_addmap(struct drm_device *dev, unsigned long offset,
+                  unsigned long size,
+                  enum drm_map_type type, enum drm_map_flags flags,
                   drm_local_map_t **map_ptr);
-int    drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request);
-int    drm_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request);
-int    drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request);
+int    drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request);
+int    drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request);
+int    drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request);
 
 /* DMA support (drm_dma.c) */
-int    drm_dma_setup(drm_device_t *dev);
-void   drm_dma_takedown(drm_device_t *dev);
-void   drm_free_buffer(drm_device_t *dev, drm_buf_t *buf);
-void   drm_reclaim_buffers(drm_device_t *dev, struct drm_file *file_priv);
+int    drm_dma_setup(struct drm_device *dev);
+void   drm_dma_takedown(struct drm_device *dev);
+void   drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
+void   drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
 #define drm_core_reclaim_buffers drm_reclaim_buffers
 
 /* IRQ support (drm_irq.c) */
-int    drm_irq_install(drm_device_t *dev);
-int    drm_irq_uninstall(drm_device_t *dev);
+int    drm_irq_install(struct drm_device *dev);
+int    drm_irq_uninstall(struct drm_device *dev);
 irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
-void   drm_driver_irq_preinstall(drm_device_t *dev);
-void   drm_driver_irq_postinstall(drm_device_t *dev);
-void   drm_driver_irq_uninstall(drm_device_t *dev);
-int    drm_vblank_wait(drm_device_t *dev, unsigned int *vbl_seq);
-void   drm_vbl_send_signals(drm_device_t *dev);
+void   drm_driver_irq_preinstall(struct drm_device *dev);
+void   drm_driver_irq_postinstall(struct drm_device *dev);
+void   drm_driver_irq_uninstall(struct drm_device *dev);
+void   drm_handle_vblank(struct drm_device *dev, int crtc);
+u32    drm_vblank_count(struct drm_device *dev, int crtc);
+int    drm_vblank_get(struct drm_device *dev, int crtc);
+void   drm_vblank_put(struct drm_device *dev, int crtc);
+void   drm_vblank_cleanup(struct drm_device *dev);
+int    drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
+int    drm_vblank_init(struct drm_device *dev, int num_crtcs);
+void   drm_vbl_send_signals(struct drm_device *dev, int crtc);
+int    drm_modeset_ctl(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
 
 /* AGP/PCI Express/GART support (drm_agpsupport.c) */
-int    drm_device_is_agp(drm_device_t *dev);
-int    drm_device_is_pcie(drm_device_t *dev);
+int    drm_device_is_agp(struct drm_device *dev);
+int    drm_device_is_pcie(struct drm_device *dev);
 drm_agp_head_t *drm_agp_init(void);
-int    drm_agp_acquire(drm_device_t *dev);
-int    drm_agp_release(drm_device_t *dev);
-int    drm_agp_info(drm_device_t * dev, drm_agp_info_t *info);
-int    drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode);
+int    drm_agp_acquire(struct drm_device *dev);
+int    drm_agp_release(struct drm_device *dev);
+int    drm_agp_info(struct drm_device * dev, struct drm_agp_info *info);
+int    drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
 void   *drm_agp_allocate_memory(size_t pages, u32 type);
 int    drm_agp_free_memory(void *handle);
 int    drm_agp_bind_memory(void *handle, off_t start);
 int    drm_agp_unbind_memory(void *handle);
-int    drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request);
-int    drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request);
-int    drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request);
-int    drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request);
+int    drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
+int    drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
+int    drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
+int    drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
 
 /* Scatter Gather Support (drm_scatter.c) */
 void   drm_sg_cleanup(drm_sg_mem_t *entry);
-int    drm_sg_alloc(drm_device_t * dev, drm_scatter_gather_t * request);
+int    drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
 /* sysctl support (drm_sysctl.h) */
-extern int             drm_sysctl_init(drm_device_t *dev);
-extern int             drm_sysctl_cleanup(drm_device_t *dev);
-#endif /* __FreeBSD__ || __DragonFly__ */
+extern int             drm_sysctl_init(struct drm_device *dev);
+extern int             drm_sysctl_cleanup(struct drm_device *dev);
 
 /* ATI PCIGART support (ati_pcigart.c) */
-int    drm_ati_pcigart_init(drm_device_t *dev,
+int    drm_ati_pcigart_init(struct drm_device *dev,
                                struct drm_ati_pcigart_info *gart_info);
-int    drm_ati_pcigart_cleanup(drm_device_t *dev,
+int    drm_ati_pcigart_cleanup(struct drm_device *dev,
                                struct drm_ati_pcigart_info *gart_info);
 
 /* Locking IOCTL support (drm_drv.c) */
-int    drm_lock(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_unlock(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_version(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_setversion(drm_device_t *dev, void *data, struct drm_file *file_priv);
+int    drm_lock(struct drm_device *dev, void *data,
+                struct drm_file *file_priv);
+int    drm_unlock(struct drm_device *dev, void *data,
+                  struct drm_file *file_priv);
+int    drm_version(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv);
+int    drm_setversion(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv);
 
 /* Misc. IOCTL support (drm_ioctl.c) */
-int    drm_irq_by_busid(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_getunique(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_setunique(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_getmap(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_getclient(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_getstats(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_noop(drm_device_t *dev, void *data, struct drm_file *file_priv);
+int    drm_irq_by_busid(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+int    drm_getunique(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv);
+int    drm_setunique(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv);
+int    drm_getmap(struct drm_device *dev, void *data,
+                  struct drm_file *file_priv);
+int    drm_getclient(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv);
+int    drm_getstats(struct drm_device *dev, void *data,
+                    struct drm_file *file_priv);
+int    drm_noop(struct drm_device *dev, void *data,
+                struct drm_file *file_priv);
 
 /* Context IOCTL support (drm_context.c) */
-int    drm_resctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_addctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_modctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_getctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_switchctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_newctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_rmctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_setsareactx(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_getsareactx(drm_device_t *dev, void *data, struct drm_file *file_priv);
+int    drm_resctx(struct drm_device *dev, void *data,
+                  struct drm_file *file_priv);
+int    drm_addctx(struct drm_device *dev, void *data,
+                  struct drm_file *file_priv);
+int    drm_modctx(struct drm_device *dev, void *data,
+                  struct drm_file *file_priv);
+int    drm_getctx(struct drm_device *dev, void *data,
+                  struct drm_file *file_priv);
+int    drm_switchctx(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv);
+int    drm_newctx(struct drm_device *dev, void *data,
+                  struct drm_file *file_priv);
+int    drm_rmctx(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv);
+int    drm_setsareactx(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+int    drm_getsareactx(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
 
 /* Drawable IOCTL support (drm_drawable.c) */
-int    drm_adddraw(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_rmdraw(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_update_draw(drm_device_t *dev, void *data, struct drm_file *file_priv);
-struct drm_drawable_info *drm_get_drawable_info(drm_device_t *dev, int handle);
+int    drm_adddraw(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv);
+int    drm_rmdraw(struct drm_device *dev, void *data,
+                  struct drm_file *file_priv);
+int    drm_update_draw(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
+                                               int handle);
+
+/* Drawable support (drm_drawable.c) */
+void drm_drawable_free_all(struct drm_device *dev);
 
 /* Authentication IOCTL support (drm_auth.c) */
-int    drm_getmagic(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_authmagic(drm_device_t *dev, void *data, struct drm_file *file_priv);
+int    drm_getmagic(struct drm_device *dev, void *data,
+                    struct drm_file *file_priv);
+int    drm_authmagic(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv);
 
 /* Buffer management support (drm_bufs.c) */
-int    drm_addmap_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_rmmap_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_addbufs_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_infobufs(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_markbufs(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_freebufs(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_mapbufs(drm_device_t *dev, void *data, struct drm_file *file_priv);
+int    drm_addmap_ioctl(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+int    drm_rmmap_ioctl(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+int    drm_addbufs(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv);
+int    drm_infobufs(struct drm_device *dev, void *data,
+                    struct drm_file *file_priv);
+int    drm_markbufs(struct drm_device *dev, void *data,
+                    struct drm_file *file_priv);
+int    drm_freebufs(struct drm_device *dev, void *data,
+                    struct drm_file *file_priv);
+int    drm_mapbufs(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv);
 
 /* DMA support (drm_dma.c) */
-int    drm_dma(drm_device_t *dev, void *data, struct drm_file *file_priv);
+int    drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
 
 /* IRQ support (drm_irq.c) */
-int    drm_control(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_wait_vblank(drm_device_t *dev, void *data, struct drm_file *file_priv);
-void   drm_locked_tasklet(drm_device_t *dev,
-                          void (*tasklet)(drm_device_t *dev));
+int    drm_control(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv);
+int    drm_wait_vblank(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
 
 /* AGP/GART support (drm_agpsupport.c) */
-int    drm_agp_acquire_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_agp_release_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_agp_enable_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_agp_info_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_agp_alloc_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_agp_free_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_agp_unbind_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_agp_bind_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
+int    drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
+                             struct drm_file *file_priv);
+int    drm_agp_release_ioctl(struct drm_device *dev, void *data,
+                             struct drm_file *file_priv);
+int    drm_agp_enable_ioctl(struct drm_device *dev, void *data,
+                            struct drm_file *file_priv);
+int    drm_agp_info_ioctl(struct drm_device *dev, void *data,
+                          struct drm_file *file_priv);
+int    drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
+                           struct drm_file *file_priv);
+int    drm_agp_free_ioctl(struct drm_device *dev, void *data,
+                          struct drm_file *file_priv);
+int    drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
+                            struct drm_file *file_priv);
+int    drm_agp_bind_ioctl(struct drm_device *dev, void *data,
+                          struct drm_file *file_priv);
 
 /* Scatter Gather Support (drm_scatter.c) */
-int    drm_sg_alloc_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
-int    drm_sg_free(drm_device_t *dev, void *data, struct drm_file *file_priv);
+int    drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
+                          struct drm_file *file_priv);
+int    drm_sg_free(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv);
 
 /* consistent PCI memory functions (drm_pci.c) */
-drm_dma_handle_t *drm_pci_alloc(drm_device_t *dev, size_t size, size_t align,
-                               dma_addr_t maxaddr);
-void   drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah);
+drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
+                               size_t align, dma_addr_t maxaddr);
+void   drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
+
+/* Inline replacements for drm_alloc and friends */
+static __inline__ void *
+drm_alloc(size_t size, struct malloc_type *area)
+{
+       return malloc(size, area, M_NOWAIT);
+}
+
+static __inline__ void *
+drm_calloc(size_t nmemb, size_t size, struct malloc_type *area)
+{
+       return malloc(size * nmemb, area, M_NOWAIT | M_ZERO);
+}
+
+static __inline__ void *
+drm_realloc(void *oldpt, size_t oldsize, size_t size,
+    struct malloc_type *area)
+{
+       return reallocf(oldpt, size, area, M_NOWAIT);
+}
+
+static __inline__ void
+drm_free(void *pt, size_t size, struct malloc_type *area)
+{
+       free(pt, area);
+}
 
 /* Inline replacements for DRM_IOREMAP macros */
-static __inline__ void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
+static __inline__ void
+drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
+{
+       map->handle = drm_ioremap_wc(dev, map);
+}
+static __inline__ void
+drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
 {
        map->handle = drm_ioremap(dev, map);
 }
-static __inline__ void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
+static __inline__ void
+drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
 {
        if ( map->handle && map->size )
                drm_ioremapfree(map);
 }
 
-static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev, unsigned long offset)
+static __inline__ struct drm_local_map *
+drm_core_findmap(struct drm_device *dev, unsigned long offset)
 {
        drm_local_map_t *map;
 
index 36bc2de..c610c03 100644 (file)
@@ -26,7 +26,6 @@
  *    Rickard E. (Rik) Faith <faith@valinux.com>
  *    Gareth Hughes <gareth@valinux.com>
  *
- * $DragonFly: src/sys/dev/drm/drm_agpsupport.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_agpsupport.c
  * the DRM's AGP ioctls.
  */
 
-#include "drmP.h"
+#include "dev/drm/drmP.h"
 
-#ifdef __FreeBSD__
-#if __FreeBSD_version >= 800004
-#include <dev/agp/agpreg.h>
-#else /* __FreeBSD_version >= 800004 */
-#include <pci/agpreg.h>
-#endif /* __FreeBSD_version >= 800004 */
-#include <dev/pci/pcireg.h>
-#elif defined(__DragonFly__)
 #include <dev/agp/agpreg.h>
 #include <bus/pci/pcireg.h>
-#endif
 
 /* Returns 1 if AGP or 0 if not. */
 static int
-drm_device_find_capability(drm_device_t *dev, int cap)
+drm_device_find_capability(struct drm_device *dev, int cap)
 {
-#if defined(__FreeBSD__) || defined(__DragonFly__)
-#if __FreeBSD_version >= 602102
-
-       return (pci_find_extcap(dev->device, cap, NULL) == 0);
-#else
        /* Code taken from agp.c.  IWBNI that was a public interface. */
        u_int32_t status;
        u_int8_t ptr, next;
@@ -85,22 +70,17 @@ drm_device_find_capability(drm_device_t *dev, int cap)
        }
 
        return 0;
-#endif
-#else
-       /* XXX: fill me in for non-FreeBSD */
-       return 1;
-#endif
 }
 
-int drm_device_is_agp(drm_device_t *dev)
+int drm_device_is_agp(struct drm_device *dev)
 {
-       if (dev->driver.device_is_agp != NULL) {
+       if (dev->driver->device_is_agp != NULL) {
                int ret;
 
                /* device_is_agp returns a tristate, 0 = not AGP, 1 = definitely
                 * AGP, 2 = fall back to PCI capability
                 */
-               ret = (*dev->driver.device_is_agp)(dev);
+               ret = (*dev->driver->device_is_agp)(dev);
                if (ret != DRM_MIGHT_BE_AGP)
                        return ret;
        }
@@ -108,12 +88,12 @@ int drm_device_is_agp(drm_device_t *dev)
        return (drm_device_find_capability(dev, PCIY_AGP));
 }
 
-int drm_device_is_pcie(drm_device_t *dev)
+int drm_device_is_pcie(struct drm_device *dev)
 {
        return (drm_device_find_capability(dev, PCIY_EXPRESS));
 }
 
-int drm_agp_info(drm_device_t * dev, drm_agp_info_t *info)
+int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info)
 {
        struct agp_info *kern;
 
@@ -135,26 +115,28 @@ int drm_agp_info(drm_device_t * dev, drm_agp_info_t *info)
        return 0;
 }
 
-int drm_agp_info_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_agp_info_ioctl(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
 {
        int err;
-       drm_agp_info_t info;
+       struct drm_agp_info info;
 
        err = drm_agp_info(dev, &info);
        if (err != 0)
                return err;
 
-       *(drm_agp_info_t *) data = info;
+       *(struct drm_agp_info *) data = info;
        return 0;
 }
 
-int drm_agp_acquire_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
+                         struct drm_file *file_priv)
 {
 
        return drm_agp_acquire(dev);
 }
 
-int drm_agp_acquire(drm_device_t *dev)
+int drm_agp_acquire(struct drm_device *dev)
 {
        int retcode;
 
@@ -169,13 +151,14 @@ int drm_agp_acquire(drm_device_t *dev)
        return 0;
 }
 
-int drm_agp_release_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_agp_release_ioctl(struct drm_device *dev, void *data,
+                         struct drm_file *file_priv)
 {
 
        return drm_agp_release(dev);
 }
 
-int drm_agp_release(drm_device_t * dev)
+int drm_agp_release(struct drm_device * dev)
 {
        if (!dev->agp || !dev->agp->acquired)
                return EINVAL;
@@ -184,7 +167,7 @@ int drm_agp_release(drm_device_t * dev)
        return 0;
 }
 
-int drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode)
+int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode)
 {
 
        if (!dev->agp || !dev->agp->acquired)
@@ -196,16 +179,17 @@ int drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode)
        return 0;
 }
 
-int drm_agp_enable_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
 {
-       drm_agp_mode_t mode;
+       struct drm_agp_mode mode;
 
-       mode = *(drm_agp_mode_t *) data;
+       mode = *(struct drm_agp_mode *) data;
 
        return drm_agp_enable(dev, mode);
 }
 
-int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request)
+int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request)
 {
        drm_agp_mem_t    *entry;
        void             *handle;
@@ -216,7 +200,7 @@ int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request)
        if (!dev->agp || !dev->agp->acquired)
                return EINVAL;
 
-       entry = malloc(sizeof(*entry), M_DRM, M_NOWAIT | M_ZERO);
+       entry = malloc(sizeof(*entry), DRM_MEM_AGPLISTS, M_NOWAIT | M_ZERO);
        if (entry == NULL)
                return ENOMEM;
 
@@ -227,7 +211,7 @@ int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request)
        handle = drm_agp_allocate_memory(pages, type);
        DRM_LOCK();
        if (handle == NULL) {
-               free(entry, M_DRM);
+               free(entry, DRM_MEM_AGPLISTS);
                return ENOMEM;
        }
        
@@ -248,23 +232,25 @@ int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request)
        return 0;
 }
 
-int drm_agp_alloc_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv)
 {
-       drm_agp_buffer_t request;
+       struct drm_agp_buffer request;
        int retcode;
 
-       request = *(drm_agp_buffer_t *) data;
+       request = *(struct drm_agp_buffer *) data;
 
        DRM_LOCK();
        retcode = drm_agp_alloc(dev, &request);
        DRM_UNLOCK();
 
-       *(drm_agp_buffer_t *) data = request;
+       *(struct drm_agp_buffer *) data = request;
 
        return retcode;
 }
 
-static drm_agp_mem_t * drm_agp_lookup_entry(drm_device_t *dev, void *handle)
+static drm_agp_mem_t * drm_agp_lookup_entry(struct drm_device *dev,
+                                           void *handle)
 {
        drm_agp_mem_t *entry;
 
@@ -274,7 +260,7 @@ static drm_agp_mem_t * drm_agp_lookup_entry(drm_device_t *dev, void *handle)
        return NULL;
 }
 
-int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request)
+int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request)
 {
        drm_agp_mem_t     *entry;
        int retcode;
@@ -296,12 +282,13 @@ int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request)
        return retcode;
 }
 
-int drm_agp_unbind_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
 {
-       drm_agp_binding_t request;
+       struct drm_agp_binding request;
        int retcode;
 
-       request = *(drm_agp_binding_t *) data;
+       request = *(struct drm_agp_binding *) data;
 
        DRM_LOCK();
        retcode = drm_agp_unbind(dev, &request);
@@ -310,7 +297,7 @@ int drm_agp_unbind_ioctl(drm_device_t *dev, void *data, struct drm_file *file_pr
        return retcode;
 }
 
-int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request)
+int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request)
 {
        drm_agp_mem_t     *entry;
        int               retcode;
@@ -336,12 +323,13 @@ int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request)
        return retcode;
 }
 
-int drm_agp_bind_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
 {
-       drm_agp_binding_t request;
+       struct drm_agp_binding request;
        int retcode;
 
-       request = *(drm_agp_binding_t *) data;
+       request = *(struct drm_agp_binding *) data;
 
        DRM_LOCK();
        retcode = drm_agp_bind(dev, &request);
@@ -350,7 +338,7 @@ int drm_agp_bind_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv
        return retcode;
 }
 
-int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request)
+int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request)
 {
        drm_agp_mem_t    *entry;
        
@@ -374,18 +362,19 @@ int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request)
        drm_agp_free_memory(entry->handle);
        DRM_LOCK();
 
-       free(entry, M_DRM);
+       free(entry, DRM_MEM_AGPLISTS);
 
        return 0;
 
 }
 
-int drm_agp_free_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_agp_free_ioctl(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
 {
-       drm_agp_buffer_t request;
+       struct drm_agp_buffer request;
        int retcode;
 
-       request = *(drm_agp_buffer_t *) data;
+       request = *(struct drm_agp_buffer *) data;
 
        DRM_LOCK();
        retcode = drm_agp_free(dev, &request);
@@ -407,7 +396,8 @@ drm_agp_head_t *drm_agp_init(void)
        DRM_DEBUG("agp_available = %d\n", agp_available);
 
        if (agp_available) {
-               head = malloc(sizeof(*head), M_DRM, M_NOWAIT | M_ZERO);
+               head = malloc(sizeof(*head), DRM_MEM_AGPLISTS,
+                   M_NOWAIT | M_ZERO);
                if (head == NULL)
                        return NULL;
                head->agpdev = agpdev;
index 0f69dc2..10576d5 100644 (file)
  * 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.
- *
- * $DragonFly: src/sys/dev/drm/drm_atomic.h,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /* Many of these implementations are rather fake, but good enough. */
 
 typedef u_int32_t atomic_t;
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
 #define atomic_set(p, v)       (*(p) = (v))
 #define atomic_read(p)         (*(p))
 #define atomic_inc(p)          atomic_add_int(p, 1)
 #define atomic_dec(p)          atomic_subtract_int(p, 1)
 #define atomic_add(n, p)       atomic_add_int(p, n)
 #define atomic_sub(n, p)       atomic_subtract_int(p, n)
-#else /* __FreeBSD__ || __DragonFly__ */
-/* FIXME */
-#define atomic_set(p, v)       (*(p) = (v))
-#define atomic_read(p)         (*(p))
-#define atomic_inc(p)          (*(p) += 1)
-#define atomic_dec(p)          (*(p) -= 1)
-#define atomic_add(n, p)       (*(p) += (n))
-#define atomic_sub(n, p)       (*(p) -= (n))
-/* FIXME */
-#define atomic_add_int(p, v)      *(p) += v
-#define atomic_subtract_int(p, v) *(p) -= v
-#define atomic_set_int(p, bits)   *(p) |= (bits)
-#define atomic_clear_int(p, bits) *(p) &= ~(bits)
-#endif /* !__FreeBSD__ && !__DragonFly__ */
-
-#ifndef __DragonFly__
-#if !defined(__FreeBSD_version) || (__FreeBSD_version < 500000)
-#if defined(__i386__)
-/* The extra atomic functions from 5.0 haven't been merged to 4.x */
-static __inline int
-atomic_cmpset_int(volatile u_int *dst, u_int exp, u_int src)
-{
-       int res = exp;
-
-       __asm __volatile (
-       "       lock ;                  "
-       "       cmpxchgl %1,%2 ;        "
-       "       setz    %%al ;          "
-       "       movzbl  %%al,%0 ;       "
-       "1:                             "
-       "# atomic_cmpset_int"
-       : "+a" (res)                    /* 0 (result) */
-       : "r" (src),                    /* 1 */
-         "m" (*(dst))                  /* 2 */
-       : "memory");                             
-
-       return (res);
-}
-#else /* __i386__ */
-static __inline int
-atomic_cmpset_int(__volatile__ int *dst, int old, int new)
-{
-       int s = splhigh();
-       if (*dst==old) {
-               *dst = new;
-               splx(s);
-               return 1;
-       }
-       splx(s);
-       return 0;
-}
-#endif /* !__i386__ */
-#endif /* !__FreeBSD_version || __FreeBSD_version < 500000 */
-
-static __inline atomic_t
-test_and_set_bit(int b, volatile void *p)
-{
-       int s = splhigh();
-       unsigned int m = 1<<b;
-       unsigned int r = *(volatile int *)p & m;
-       *(volatile int *)p |= m;
-       splx(s);
-       return r;
-}
-
-#else  /* __DragonFly__ */
 
 static __inline atomic_t
 test_and_set_bit(int b, volatile void *p)
@@ -123,8 +54,6 @@ test_and_set_bit(int b, volatile void *p)
        return (o & m);
 }
 
-#endif /* __DragonFly__ */
-
 static __inline void
 clear_bit(int b, volatile void *p)
 {
index 9d3d7df..303722c 100644 (file)
@@ -26,7 +26,6 @@
  *    Rickard E. (Rik) Faith <faith@valinux.com>
  *    Gareth Hughes <gareth@valinux.com>
  *
- * $DragonFly: src/sys/dev/drm/drm_auth.c,v 1.2 2008/06/10 06:35:59 hasso Exp $
  */
 
 /** @file drm_auth.c
@@ -34,7 +33,7 @@
  * scheme between the master and clients.
  */
 
-#include "drmP.h"
+#include "dev/drm/drmP.h"
 
 static int drm_hash_magic(drm_magic_t magic)
 {
@@ -44,7 +43,7 @@ static int drm_hash_magic(drm_magic_t magic)
 /**
  * Returns the file private associated with the given magic number.
  */
-static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
+static struct drm_file *drm_find_file(struct drm_device *dev, drm_magic_t magic)
 {
        drm_magic_entry_t *pt;
        int hash = drm_hash_magic(magic);
@@ -64,7 +63,8 @@ static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
  * Inserts the given magic number into the hash table of used magic number
  * lists.
  */
-static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
+static int drm_add_magic(struct drm_device *dev, struct drm_file *priv,
+                        drm_magic_t magic)
 {
        int               hash;
        drm_magic_entry_t *entry;
@@ -74,8 +74,9 @@ static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
        DRM_SPINLOCK_ASSERT(&dev->dev_lock);
 
        hash = drm_hash_magic(magic);
-       entry = malloc(sizeof(*entry), M_DRM, M_ZERO | M_NOWAIT);
-       if (!entry) return ENOMEM;
+       entry = malloc(sizeof(*entry), DRM_MEM_MAGIC, M_ZERO | M_NOWAIT);
+       if (!entry)
+               return ENOMEM;
        entry->magic = magic;
        entry->priv  = priv;
        entry->next  = NULL;
@@ -95,7 +96,7 @@ static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
  * Removes the given magic number from the hash table of used magic number
  * lists.
  */
-static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic)
+static int drm_remove_magic(struct drm_device *dev, drm_magic_t magic)
 {
        drm_magic_entry_t *prev = NULL;
        drm_magic_entry_t *pt;
@@ -117,11 +118,11 @@ static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic)
                        if (prev) {
                                prev->next = pt->next;
                        }
+                       free(pt, DRM_MEM_MAGIC);
                        return 0;
                }
        }
 
-       free(pt, M_DRM);
        return EINVAL;
 }
 
@@ -133,12 +134,12 @@ static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic)
  * connection that the magic is passed over) to determine if the magic number
  * should be authenticated.
  */
-int drm_getmagic(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
        static drm_magic_t sequence = 0;
-       drm_auth_t *auth = data;
+       struct drm_auth *auth = data;
 
-                               /* Find unique magic */
+       /* Find unique magic */
        if (file_priv->magic) {
                auth->magic = file_priv->magic;
        } else {
@@ -164,10 +165,11 @@ int drm_getmagic(drm_device_t *dev, void *data, struct drm_file *file_priv)
 /**
  * Marks the client associated with the given magic number as authenticated.
  */
-int drm_authmagic(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_authmagic(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
 {
-       drm_auth_t *auth = data;
-       drm_file_t *priv;
+       struct drm_auth *auth = data;
+       struct drm_file *priv;
 
        DRM_DEBUG("%u\n", auth->magic);
 
index 4912c3f..9722483 100644 (file)
  *    Rickard E. (Rik) Faith <faith@valinux.com>
  *    Gareth Hughes <gareth@valinux.com>
  *
- * $DragonFly: src/sys/dev/drm/drm_bufs.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_bufs.c
  * Implementation of the ioctls for setup of DRM mappings and DMA buffers.
  */
 
-#ifdef __DragonFly__
-#include <bus/pci/pcireg.h>
-#else
-#include "dev/pci/pcireg.h"
-#endif
-
-#include "drmP.h"
-
-
-/*
- * Compute order.  Can be made faster.
- */
-int drm_order(unsigned long size)
-{
-       int order;
-       unsigned long tmp;
-
-       for ( order = 0, tmp = size ; tmp >>= 1 ; ++order );
+#include "bus/pci/pcireg.h"
 
-       if ( size & ~(1 << order) )
-               ++order;
-
-       return order;
-}
+#include "dev/drm/drmP.h"
 
 /* Allocation of PCI memory resources (framebuffer, registers, etc.) for
  * drm_get_resource_*.  Note that they are not RF_ACTIVE, so there's no virtual
  * address for accessing them.  Cleaned up at unload.
  */
-static int drm_alloc_resource(drm_device_t *dev, int resource)
+static int drm_alloc_resource(struct drm_device *dev, int resource)
 {
        if (resource >= DRM_MAX_PCI_RESOURCE) {
                DRM_ERROR("Resource %d too large\n", resource);
@@ -88,7 +66,8 @@ static int drm_alloc_resource(drm_device_t *dev, int resource)
        return 0;
 }
 
-unsigned long drm_get_resource_start(drm_device_t *dev, unsigned int resource)
+unsigned long drm_get_resource_start(struct drm_device *dev,
+                                    unsigned int resource)
 {
        if (drm_alloc_resource(dev, resource) != 0)
                return 0;
@@ -96,7 +75,8 @@ unsigned long drm_get_resource_start(drm_device_t *dev, unsigned int resource)
        return rman_get_start(dev->pcir[resource]);
 }
 
-unsigned long drm_get_resource_len(drm_device_t *dev, unsigned int resource)
+unsigned long drm_get_resource_len(struct drm_device *dev,
+                                  unsigned int resource)
 {
        if (drm_alloc_resource(dev, resource) != 0)
                return 0;
@@ -104,8 +84,9 @@ unsigned long drm_get_resource_len(drm_device_t *dev, unsigned int resource)
        return rman_get_size(dev->pcir[resource]);
 }
 
-int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size,
-    drm_map_type_t type, drm_map_flags_t flags, drm_local_map_t **map_ptr)
+int drm_addmap(struct drm_device * dev, unsigned long offset,
+              unsigned long size,
+    enum drm_map_type type, enum drm_map_flags flags, drm_local_map_t **map_ptr)
 {
        drm_local_map_t *map;
        int align;
@@ -154,16 +135,18 @@ int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size,
        /* Allocate a new map structure, fill it in, and do any type-specific
         * initialization necessary.
         */
-       map = malloc(sizeof(*map), M_DRM, M_ZERO | M_NOWAIT);
-       if ( !map )
+       map = malloc(sizeof(*map), DRM_MEM_MAPS, M_ZERO | M_NOWAIT);
+       if (!map) {
+               DRM_LOCK();
                return ENOMEM;
+       }
 
        map->offset = offset;
        map->size = size;
        map->type = type;
        map->flags = flags;
 
-       switch ( map->type ) {
+       switch (map->type) {
        case _DRM_REGISTERS:
                map->handle = drm_ioremap(dev, map);
                if (!(map->flags & _DRM_WRITE_COMBINING))
@@ -174,21 +157,22 @@ int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size,
                        map->mtrr = 1;
                break;
        case _DRM_SHM:
-               map->handle = malloc(map->size, M_DRM, M_NOWAIT);
-               DRM_DEBUG( "%lu %d %p\n",
-                          map->size, drm_order(map->size), map->handle );
-               if ( !map->handle ) {
-                       free(map, M_DRM);
+               map->handle = malloc(map->size, DRM_MEM_MAPS, M_NOWAIT);
+               DRM_DEBUG("%lu %d %p\n",
+                   map->size, drm_order(map->size), map->handle);
+               if (!map->handle) {
+                       free(map, DRM_MEM_MAPS);
+                       DRM_LOCK();
                        return ENOMEM;
                }
                map->offset = (unsigned long)map->handle;
-               if ( map->flags & _DRM_CONTAINS_LOCK ) {
+               if (map->flags & _DRM_CONTAINS_LOCK) {
                        /* Prevent a 2nd X Server from creating a 2nd lock */
                        DRM_LOCK();
                        if (dev->lock.hw_lock != NULL) {
                                DRM_UNLOCK();
-                               free(map->handle, M_DRM);
-                               free(map, M_DRM);
+                               free(map->handle, DRM_MEM_MAPS);
+                               free(map, DRM_MEM_MAPS);
                                return EBUSY;
                        }
                        dev->lock.hw_lock = map->handle; /* Pointer to lock */
@@ -218,16 +202,18 @@ int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size,
                        }
                }
                if (!valid) {
-                       free(map, M_DRM);
+                       free(map, DRM_MEM_MAPS);
+                       DRM_LOCK();
                        return EACCES;
                }*/
                break;
        case _DRM_SCATTER_GATHER:
                if (!dev->sg) {
-                       free(map, M_DRM);
+                       free(map, DRM_MEM_MAPS);
+                       DRM_LOCK();
                        return EINVAL;
                }
-               map->offset = map->offset + dev->sg->handle;
+               map->offset += dev->sg->handle;
                break;
        case _DRM_CONSISTENT:
                /* Unfortunately, we don't get any alignment specification from
@@ -241,7 +227,8 @@ int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size,
                        align = PAGE_SIZE;
                map->dmah = drm_pci_alloc(dev, map->size, align, 0xfffffffful);
                if (map->dmah == NULL) {
-                       free(map, M_DRM);
+                       free(map, DRM_MEM_MAPS);
+                       DRM_LOCK();
                        return ENOMEM;
                }
                map->handle = map->dmah->vaddr;
@@ -249,7 +236,8 @@ int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size,
                break;
        default:
                DRM_ERROR("Bad map type %d\n", map->type);
-               free(map, M_DRM);
+               free(map, DRM_MEM_MAPS);
+               DRM_LOCK();
                return EINVAL;
        }
 
@@ -267,9 +255,10 @@ done:
        return 0;
 }
 
-int drm_addmap_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_addmap_ioctl(struct drm_device *dev, void *data,
+                    struct drm_file *file_priv)
 {
-       drm_map_t *request = data;
+       struct drm_map *request = data;
        drm_local_map_t *map;
        int err;
 
@@ -300,7 +289,7 @@ int drm_addmap_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
        return 0;
 }
 
-void drm_rmmap(drm_device_t *dev, drm_local_map_t *map)
+void drm_rmmap(struct drm_device *dev, drm_local_map_t *map)
 {
        DRM_SPINLOCK_ASSERT(&dev->dev_lock);
 
@@ -321,7 +310,7 @@ void drm_rmmap(drm_device_t *dev, drm_local_map_t *map)
                }
                break;
        case _DRM_SHM:
-               free(map->handle, M_DRM);
+               free(map->handle, DRM_MEM_MAPS);
                break;
        case _DRM_AGP:
        case _DRM_SCATTER_GATHER:
@@ -339,17 +328,18 @@ void drm_rmmap(drm_device_t *dev, drm_local_map_t *map)
                    map->bsr);
        }
 
-       free(map, M_DRM);
+       free(map, DRM_MEM_MAPS);
 }
 
 /* Remove a map private from list and deallocate resources if the mapping
  * isn't in use.
  */
 
-int drm_rmmap_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_rmmap_ioctl(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv)
 {
        drm_local_map_t *map;
-       drm_map_t *request = data;
+       struct drm_map *request = data;
 
        DRM_LOCK();
        TAILQ_FOREACH(map, &dev->maplist, link) {
@@ -372,7 +362,8 @@ int drm_rmmap_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
 }
 
 
-static void drm_cleanup_buf_error(drm_device_t *dev, drm_buf_entry_t *entry)
+static void drm_cleanup_buf_error(struct drm_device *dev,
+                                 drm_buf_entry_t *entry)
 {
        int i;
 
@@ -380,22 +371,22 @@ static void drm_cleanup_buf_error(drm_device_t *dev, drm_buf_entry_t *entry)
                for (i = 0; i < entry->seg_count; i++) {
                        drm_pci_free(dev, entry->seglist[i]);
                }
-               free(entry->seglist, M_DRM);
+               free(entry->seglist, DRM_MEM_SEGS);
 
                entry->seg_count = 0;
        }
 
        if (entry->buf_count) {
                for (i = 0; i < entry->buf_count; i++) {
-                       free(entry->buflist[i].dev_private, M_DRM);
+                       free(entry->buflist[i].dev_private, DRM_MEM_BUFS);
                }
-               free(entry->buflist, M_DRM);
+               free(entry->buflist, DRM_MEM_BUFS);
 
                entry->buf_count = 0;
        }
 }
 
-static int drm_do_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
+static int drm_do_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request)
 {
        drm_device_dma_t *dma = dev->dma;
        drm_buf_entry_t *entry;
@@ -419,20 +410,20 @@ static int drm_do_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
        size = 1 << order;
 
        alignment  = (request->flags & _DRM_PAGE_ALIGN)
-               ? round_page(size) : size;
+           ? round_page(size) : size;
        page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
        total = PAGE_SIZE << page_order;
 
        byte_count = 0;
        agp_offset = dev->agp->base + request->agp_start;
 
-       DRM_DEBUG( "count:      %d\n",  count );
-       DRM_DEBUG( "order:      %d\n",  order );
-       DRM_DEBUG( "size:       %d\n",  size );
-       DRM_DEBUG( "agp_offset: 0x%lx\n", agp_offset );
-       DRM_DEBUG( "alignment:  %d\n",  alignment );
-       DRM_DEBUG( "page_order: %d\n",  page_order );
-       DRM_DEBUG( "total:      %d\n",  total );
+       DRM_DEBUG("count:      %d\n",  count);
+       DRM_DEBUG("order:      %d\n",  order);
+       DRM_DEBUG("size:       %d\n",  size);
+       DRM_DEBUG("agp_offset: 0x%lx\n", agp_offset);
+       DRM_DEBUG("alignment:  %d\n",  alignment);
+       DRM_DEBUG("page_order: %d\n",  page_order);
+       DRM_DEBUG("total:      %d\n",  total);
 
        /* Make sure buffers are located in AGP memory that we own */
        /* Breaks MGA due to drm_alloc_agp not setting up entries for the
@@ -456,9 +447,9 @@ static int drm_do_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
 
        entry = &dma->bufs[order];
 
-       entry->buflist = malloc(count * sizeof(*entry->buflist), M_DRM,
+       entry->buflist = malloc(count * sizeof(*entry->buflist), DRM_MEM_BUFS,
            M_NOWAIT | M_ZERO);
-       if ( !entry->buflist ) {
+       if (!entry->buflist) {
                return ENOMEM;
        }
 
@@ -467,7 +458,7 @@ static int drm_do_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
 
        offset = 0;
 
-       while ( entry->buf_count < count ) {
+       while (entry->buf_count < count) {
                buf          = &entry->buflist[entry->buf_count];
                buf->idx     = dma->buf_count + entry->buf_count;
                buf->total   = alignment;
@@ -481,8 +472,8 @@ static int drm_do_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
                buf->pending = 0;
                buf->file_priv = NULL;
 
-               buf->dev_priv_size = dev->driver.buf_priv_size;
-               buf->dev_private = malloc(buf->dev_priv_size, M_DRM,
+               buf->dev_priv_size = dev->driver->buf_priv_size;
+               buf->dev_private = malloc(buf->dev_priv_size, DRM_MEM_BUFS,
                    M_NOWAIT | M_ZERO);
                if (buf->dev_private == NULL) {
                        /* Set count correctly so we free the proper amount. */
@@ -496,11 +487,11 @@ static int drm_do_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
                byte_count += PAGE_SIZE << page_order;
        }
 
-       DRM_DEBUG( "byte_count: %d\n", byte_count );
+       DRM_DEBUG("byte_count: %d\n", byte_count);
 
        temp_buflist = realloc(dma->buflist,
-           (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), M_DRM,
-           M_NOWAIT);
+           (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist),
+           DRM_MEM_BUFS, M_NOWAIT);
        if (temp_buflist == NULL) {
                /* Free the entry because it isn't valid */
                drm_cleanup_buf_error(dev, entry);
@@ -508,15 +499,15 @@ static int drm_do_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
        }
        dma->buflist = temp_buflist;
 
-       for ( i = 0 ; i < entry->buf_count ; i++ ) {
+       for (i = 0; i < entry->buf_count; i++) {
                dma->buflist[i + dma->buf_count] = &entry->buflist[i];
        }
 
        dma->buf_count += entry->buf_count;
        dma->byte_count += byte_count;
 
-       DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count );
-       DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count );
+       DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
+       DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
 
        request->count = entry->buf_count;
        request->size = size;
@@ -526,7 +517,7 @@ static int drm_do_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
        return 0;
 }
 
-static int drm_do_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
+static int drm_do_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request)
 {
        drm_device_dma_t *dma = dev->dma;
        int count;
@@ -548,68 +539,71 @@ static int drm_do_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
        order = drm_order(request->size);
        size = 1 << order;
 
-       DRM_DEBUG( "count=%d, size=%d (%d), order=%d\n",
-                  request->count, request->size, size, order );
+       DRM_DEBUG("count=%d, size=%d (%d), order=%d\n",
+           request->count, request->size, size, order);
 
        alignment = (request->flags & _DRM_PAGE_ALIGN)
-               ? round_page(size) : size;
+           ? round_page(size) : size;
        page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
        total = PAGE_SIZE << page_order;
 
        entry = &dma->bufs[order];
 
-       entry->buflist = malloc(count * sizeof(*entry->buflist), M_DRM,
+       entry->buflist = malloc(count * sizeof(*entry->buflist), DRM_MEM_BUFS,
            M_NOWAIT | M_ZERO);
-       entry->seglist = malloc(count * sizeof(*entry->seglist), M_DRM,
+       entry->seglist = malloc(count * sizeof(*entry->seglist), DRM_MEM_SEGS,
            M_NOWAIT | M_ZERO);
 
        /* Keep the original pagelist until we know all the allocations
         * have succeeded
         */
        temp_pagelist = malloc((dma->page_count + (count << page_order)) *
-           sizeof(*dma->pagelist), M_DRM, M_NOWAIT);
+           sizeof(*dma->pagelist), DRM_MEM_PAGES, M_NOWAIT);
 
        if (entry->buflist == NULL || entry->seglist == NULL || 
            temp_pagelist == NULL) {
-               free(entry->buflist, M_DRM);
-               free(entry->seglist, M_DRM);
+               free(temp_pagelist, DRM_MEM_PAGES);
+               free(entry->seglist, DRM_MEM_SEGS);
+               free(entry->buflist, DRM_MEM_BUFS);
                return ENOMEM;
        }
-       
+
        memcpy(temp_pagelist, dma->pagelist, dma->page_count * 
            sizeof(*dma->pagelist));
 
-       DRM_DEBUG( "pagelist: %d entries\n",
-                  dma->page_count + (count << page_order) );
+       DRM_DEBUG("pagelist: %d entries\n",
+           dma->page_count + (count << page_order));
 
        entry->buf_size = size;
        entry->page_order = page_order;
        byte_count = 0;
        page_count = 0;
 
-       while ( entry->buf_count < count ) {
+       while (entry->buf_count < count) {
+               DRM_SPINUNLOCK(&dev->dma_lock);
                drm_dma_handle_t *dmah = drm_pci_alloc(dev, size, alignment,
                    0xfffffffful);
+               DRM_SPINLOCK(&dev->dma_lock);
                if (dmah == NULL) {
                        /* Set count correctly so we free the proper amount. */
                        entry->buf_count = count;
                        entry->seg_count = count;
                        drm_cleanup_buf_error(dev, entry);
-                       free(temp_pagelist, M_DRM);
+                       free(temp_pagelist, DRM_MEM_PAGES);
                        return ENOMEM;
                }
 
                entry->seglist[entry->seg_count++] = dmah;
-               for ( i = 0 ; i < (1 << page_order) ; i++ ) {
-                       DRM_DEBUG( "page %d @ %p\n",
-                                  dma->page_count + page_count,
-                                  (char *)dmah->vaddr + PAGE_SIZE * i );
+               for (i = 0; i < (1 << page_order); i++) {
+                       DRM_DEBUG("page %d @ %p\n",
+                           dma->page_count + page_count,
+                           (char *)dmah->vaddr + PAGE_SIZE * i);
                        temp_pagelist[dma->page_count + page_count++] = 
                            (long)dmah->vaddr + PAGE_SIZE * i;
                }
-               for ( offset = 0 ;
-                     offset + size <= total && entry->buf_count < count ;
-                     offset += alignment, ++entry->buf_count ) {
+               for (offset = 0;
+                   offset + size <= total && entry->buf_count < count;
+                   offset += alignment, ++entry->buf_count) {
                        buf          = &entry->buflist[entry->buf_count];
                        buf->idx     = dma->buf_count + entry->buf_count;
                        buf->total   = alignment;
@@ -622,43 +616,43 @@ static int drm_do_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
                        buf->pending = 0;
                        buf->file_priv = NULL;
 
-                       buf->dev_priv_size = dev->driver.buf_priv_size;
-                       buf->dev_private = malloc(buf->dev_priv_size, M_DRM,
-                           M_NOWAIT | M_ZERO);
+                       buf->dev_priv_size = dev->driver->buf_priv_size;
+                       buf->dev_private = malloc(buf->dev_priv_size,
+                           DRM_MEM_BUFS, M_NOWAIT | M_ZERO);
                        if (buf->dev_private == NULL) {
                                /* Set count correctly so we free the proper amount. */
                                entry->buf_count = count;
                                entry->seg_count = count;
                                drm_cleanup_buf_error(dev, entry);
-                               free(temp_pagelist, M_DRM);
+                               free(temp_pagelist, DRM_MEM_PAGES);
                                return ENOMEM;
                        }
 
-                       DRM_DEBUG( "buffer %d @ %p\n",
-                                  entry->buf_count, buf->address );
+                       DRM_DEBUG("buffer %d @ %p\n",
+                           entry->buf_count, buf->address);
                }
                byte_count += PAGE_SIZE << page_order;
        }
 
        temp_buflist = realloc(dma->buflist,
-           (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), M_DRM,
-           M_NOWAIT);
+           (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist),
+           DRM_MEM_BUFS, M_NOWAIT);
        if (temp_buflist == NULL) {
                /* Free the entry because it isn't valid */
                drm_cleanup_buf_error(dev, entry);
-               free(temp_pagelist, M_DRM);
+               free(temp_pagelist, DRM_MEM_PAGES);
                return ENOMEM;
        }
        dma->buflist = temp_buflist;
 
-       for ( i = 0 ; i < entry->buf_count ; i++ ) {
+       for (i = 0; i < entry->buf_count; i++) {
                dma->buflist[i + dma->buf_count] = &entry->buflist[i];
        }
 
        /* No allocations failed, so now we can replace the orginal pagelist
         * with the new one.
         */
-       free(dma->pagelist, M_DRM);
+       free(dma->pagelist, DRM_MEM_PAGES);
        dma->pagelist = temp_pagelist;
 
        dma->buf_count += entry->buf_count;
@@ -673,7 +667,7 @@ static int drm_do_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
 
 }
 
-static int drm_do_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
+static int drm_do_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request)
 {
        drm_device_dma_t *dma = dev->dma;
        drm_buf_entry_t *entry;
@@ -695,24 +689,24 @@ static int drm_do_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
        size = 1 << order;
 
        alignment  = (request->flags & _DRM_PAGE_ALIGN)
-               ? round_page(size) : size;
+           ? round_page(size) : size;
        page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
        total = PAGE_SIZE << page_order;
 
        byte_count = 0;
        agp_offset = request->agp_start;
 
-       DRM_DEBUG( "count:      %d\n",  count );
-       DRM_DEBUG( "order:      %d\n",  order );
-       DRM_DEBUG( "size:       %d\n",  size );
-       DRM_DEBUG( "agp_offset: %ld\n", agp_offset );
-       DRM_DEBUG( "alignment:  %d\n",  alignment );
-       DRM_DEBUG( "page_order: %d\n",  page_order );
-       DRM_DEBUG( "total:      %d\n",  total );
+       DRM_DEBUG("count:      %d\n",  count);
+       DRM_DEBUG("order:      %d\n",  order);
+       DRM_DEBUG("size:       %d\n",  size);
+       DRM_DEBUG("agp_offset: %ld\n", agp_offset);
+       DRM_DEBUG("alignment:  %d\n",  alignment);
+       DRM_DEBUG("page_order: %d\n",  page_order);
+       DRM_DEBUG("total:      %d\n",  total);
 
        entry = &dma->bufs[order];
 
-       entry->buflist = malloc(count * sizeof(*entry->buflist), M_DRM,
+       entry->buflist = malloc(count * sizeof(*entry->buflist), DRM_MEM_BUFS,
            M_NOWAIT | M_ZERO);
        if (entry->buflist == NULL)
                return ENOMEM;
@@ -722,7 +716,7 @@ static int drm_do_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
 
        offset = 0;
 
-       while ( entry->buf_count < count ) {
+       while (entry->buf_count < count) {
                buf          = &entry->buflist[entry->buf_count];
                buf->idx     = dma->buf_count + entry->buf_count;
                buf->total   = alignment;
@@ -736,8 +730,8 @@ static int drm_do_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
                buf->pending = 0;
                buf->file_priv = NULL;
 
-               buf->dev_priv_size = dev->driver.buf_priv_size;
-               buf->dev_private = malloc(buf->dev_priv_size, M_DRM,
+               buf->dev_priv_size = dev->driver->buf_priv_size;
+               buf->dev_private = malloc(buf->dev_priv_size, DRM_MEM_BUFS,
                    M_NOWAIT | M_ZERO);
                if (buf->dev_private == NULL) {
                        /* Set count correctly so we free the proper amount. */
@@ -746,19 +740,19 @@ static int drm_do_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
                        return ENOMEM;
                }
 
-               DRM_DEBUG( "buffer %d @ %p\n",
-                          entry->buf_count, buf->address );
+               DRM_DEBUG("buffer %d @ %p\n",
+                   entry->buf_count, buf->address);
 
                offset += alignment;
                entry->buf_count++;
                byte_count += PAGE_SIZE << page_order;
        }
 
-       DRM_DEBUG( "byte_count: %d\n", byte_count );
+       DRM_DEBUG("byte_count: %d\n", byte_count);
 
        temp_buflist = realloc(dma->buflist,
-           (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), M_DRM,
-           M_NOWAIT);
+           (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist),
+           DRM_MEM_BUFS, M_NOWAIT);
        if (temp_buflist == NULL) {
                /* Free the entry because it isn't valid */
                drm_cleanup_buf_error(dev, entry);
@@ -766,15 +760,15 @@ static int drm_do_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
        }
        dma->buflist = temp_buflist;
 
-       for ( i = 0 ; i < entry->buf_count ; i++ ) {
+       for (i = 0; i < entry->buf_count; i++) {
                dma->buflist[i + dma->buf_count] = &entry->buflist[i];
        }
 
        dma->buf_count += entry->buf_count;
        dma->byte_count += byte_count;
 
-       DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count );
-       DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count );
+       DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
+       DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
 
        request->count = entry->buf_count;
        request->size = size;
@@ -784,12 +778,10 @@ static int drm_do_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
        return 0;
 }
 
-int drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
+int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request)
 {
        int order, ret;
 
-       DRM_SPINLOCK(&dev->dma_lock);
-
        if (request->count < 0 || request->count > 4096)
                return EINVAL;
        
@@ -797,6 +789,8 @@ int drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
        if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
                return EINVAL;
 
+       DRM_SPINLOCK(&dev->dma_lock);
+
        /* No more allocations after first buffer-using ioctl. */
        if (dev->buf_use != 0) {
                DRM_SPINUNLOCK(&dev->dma_lock);
@@ -815,22 +809,22 @@ int drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
        return ret;
 }
 
-int drm_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
+int drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request)
 {
        int order, ret;
 
-       DRM_SPINLOCK(&dev->dma_lock);
-
        if (!DRM_SUSER(DRM_CURPROC))
                return EACCES;
 
        if (request->count < 0 || request->count > 4096)
                return EINVAL;
-       
+
        order = drm_order(request->size);
        if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
                return EINVAL;
 
+       DRM_SPINLOCK(&dev->dma_lock);
+
        /* No more allocations after first buffer-using ioctl. */
        if (dev->buf_use != 0) {
                DRM_SPINUNLOCK(&dev->dma_lock);
@@ -849,22 +843,22 @@ int drm_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
        return ret;
 }
 
-int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
+int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request)
 {
        int order, ret;
 
-       DRM_SPINLOCK(&dev->dma_lock);
-
        if (!DRM_SUSER(DRM_CURPROC))
                return EACCES;
 
        if (request->count < 0 || request->count > 4096)
                return EINVAL;
-       
+
        order = drm_order(request->size);
        if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
                return EINVAL;
 
+       DRM_SPINLOCK(&dev->dma_lock);
+
        /* No more allocations after first buffer-using ioctl. */
        if (dev->buf_use != 0) {
                DRM_SPINUNLOCK(&dev->dma_lock);
@@ -883,9 +877,9 @@ int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
        return ret;
 }
 
-int drm_addbufs_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_addbufs(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_buf_desc_t *request = data;
+       struct drm_buf_desc *request = data;
        int err;
 
        if (request->flags & _DRM_AGP_BUFFER)
@@ -898,10 +892,10 @@ int drm_addbufs_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
        return err;
 }
 
-int drm_infobufs(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_infobufs(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
        drm_device_dma_t *dma = dev->dma;
-       drm_buf_info_t *request = data;
+       struct drm_buf_info *request = data;
        int i;
        int count;
        int retcode = 0;
@@ -910,16 +904,17 @@ int drm_infobufs(drm_device_t *dev, void *data, struct drm_file *file_priv)
        ++dev->buf_use;         /* Can't allocate more after this call */
        DRM_SPINUNLOCK(&dev->dma_lock);
 
-       for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) {
-               if ( dma->bufs[i].buf_count ) ++count;
+       for (i = 0, count = 0; i < DRM_MAX_ORDER + 1; i++) {
+               if (dma->bufs[i].buf_count)
+                       ++count;
        }
 
-       DRM_DEBUG( "count = %d\n", count );
+       DRM_DEBUG("count = %d\n", count);
 
-       if ( request->count >= count ) {
-               for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) {
-                       if ( dma->bufs[i].buf_count ) {
-                               drm_buf_desc_t from;
+       if (request->count >= count) {
+               for (i = 0, count = 0; i < DRM_MAX_ORDER + 1; i++) {
+                       if (dma->bufs[i].buf_count) {
+                               struct drm_buf_desc from;
 
                                from.count = dma->bufs[i].buf_count;
                                from.size = dma->bufs[i].buf_size;
@@ -927,17 +922,16 @@ int drm_infobufs(drm_device_t *dev, void *data, struct drm_file *file_priv)
                                from.high_mark = dma->bufs[i].freelist.high_mark;
 
                                if (DRM_COPY_TO_USER(&request->list[count], &from,
-                                   sizeof(drm_buf_desc_t)) != 0) {
+                                   sizeof(struct drm_buf_desc)) != 0) {
                                        retcode = EFAULT;
                                        break;
                                }
 
-                               DRM_DEBUG( "%d %d %d %d %d\n",
-                                          i,
-                                          dma->bufs[i].buf_count,
-                                          dma->bufs[i].buf_size,
-                                          dma->bufs[i].freelist.low_mark,
-                                          dma->bufs[i].freelist.high_mark );
+                               DRM_DEBUG("%d %d %d %d %d\n",
+                                   i, dma->bufs[i].buf_count,
+                                   dma->bufs[i].buf_size,
+                                   dma->bufs[i].freelist.low_mark,
+                                   dma->bufs[i].freelist.high_mark);
                                ++count;
                        }
                }
@@ -947,14 +941,14 @@ int drm_infobufs(drm_device_t *dev, void *data, struct drm_file *file_priv)
        return retcode;
 }
 
-int drm_markbufs(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_markbufs(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
        drm_device_dma_t *dma = dev->dma;
-       drm_buf_desc_t *request = data;
+       struct drm_buf_desc *request = data;
        int order;
 
-       DRM_DEBUG( "%d, %d, %d\n",
-                  request->size, request->low_mark, request->high_mark );
+       DRM_DEBUG("%d, %d, %d\n",
+                 request->size, request->low_mark, request->high_mark);
        
 
        order = drm_order(request->size);       
@@ -966,6 +960,7 @@ int drm_markbufs(drm_device_t *dev, void *data, struct drm_file *file_priv)
        DRM_SPINLOCK(&dev->dma_lock);
        if (request->low_mark > dma->bufs[order].buf_count ||
            request->high_mark > dma->bufs[order].buf_count) {
+               DRM_SPINUNLOCK(&dev->dma_lock);
                return EINVAL;
        }
 
@@ -976,33 +971,33 @@ int drm_markbufs(drm_device_t *dev, void *data, struct drm_file *file_priv)
        return 0;
 }
 
-int drm_freebufs(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_freebufs(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
        drm_device_dma_t *dma = dev->dma;
-       drm_buf_free_t *request = data;
+       struct drm_buf_free *request = data;
        int i;
        int idx;
        drm_buf_t *buf;
        int retcode = 0;
 
-       DRM_DEBUG( "%d\n", request->count );
+       DRM_DEBUG("%d\n", request->count);
        
        DRM_SPINLOCK(&dev->dma_lock);
-       for ( i = 0 ; i < request->count ; i++ ) {
+       for (i = 0; i < request->count; i++) {
                if (DRM_COPY_FROM_USER(&idx, &request->list[i], sizeof(idx))) {
                        retcode = EFAULT;
                        break;
                }
-               if ( idx < 0 || idx >= dma->buf_count ) {
-                       DRM_ERROR( "Index %d (of %d max)\n",
-                                  idx, dma->buf_count - 1 );
+               if (idx < 0 || idx >= dma->buf_count) {
+                       DRM_ERROR("Index %d (of %d max)\n",
+                           idx, dma->buf_count - 1);
                        retcode = EINVAL;
                        break;
                }
                buf = dma->buflist[idx];
-               if ( buf->file_priv != file_priv ) {
+               if (buf->file_priv != file_priv) {
                        DRM_ERROR("Process %d freeing buffer not owned\n",
-                                  DRM_CURRENTPID);
+                           DRM_CURRENTPID);
                        retcode = EINVAL;
                        break;
                }
@@ -1013,37 +1008,20 @@ int drm_freebufs(drm_device_t *dev, void *data, struct drm_file *file_priv)
        return retcode;
 }
 
-int drm_mapbufs(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_mapbufs(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
        drm_device_dma_t *dma = dev->dma;
        int retcode = 0;
        const int zero = 0;
        vm_offset_t address;
        struct vmspace *vms;
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        vm_ooffset_t foff;
        vm_size_t size;
        vm_offset_t vaddr;
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-       struct vnode *vn;
-       voff_t foff;
-       vsize_t size;
-       vaddr_t vaddr;
-#endif /* __NetBSD__ || __OpenBSD__ */
-
-       drm_buf_map_t *request = data;
+       struct drm_buf_map *request = data;
        int i;
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-       if (!vfinddev(kdev, VCHR, &vn))
-               return 0;       /* FIXME: Shouldn't this be EINVAL or something? */
-#endif /* __NetBSD__ || __OpenBSD */
-
-#if defined(__FreeBSD__) && __FreeBSD_version >= 500000 || defined(__DragonFly__)
        vms = DRM_CURPROC->td_proc->p_vmspace;
-#else
-       vms = DRM_CURPROC->p_vmspace;
-#endif
 
        DRM_SPINLOCK(&dev->dma_lock);
        dev->buf_use++;         /* Can't allocate more after this call */
@@ -1052,8 +1030,9 @@ int drm_mapbufs(drm_device_t *dev, void *data, struct drm_file *file_priv)
        if (request->count < dma->buf_count)
                goto done;
 
-       if ((dev->driver.use_agp && (dma->flags & _DRM_DMA_USE_AGP)) ||
-           (dev->driver.use_sg && (dma->flags & _DRM_DMA_USE_SG))) {
+       if ((drm_core_has_AGP(dev) && (dma->flags & _DRM_DMA_USE_AGP)) ||
+           (drm_core_check_feature(dev, DRIVER_SG) &&
+           (dma->flags & _DRM_DMA_USE_SG))) {
                drm_local_map_t *map = dev->agp_buffer_map;
 
                if (map == NULL) {
@@ -1067,28 +1046,22 @@ int drm_mapbufs(drm_device_t *dev, void *data, struct drm_file *file_priv)
                foff = 0;
        }
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        vaddr = round_page((vm_offset_t)vms->vm_daddr + MAXDSIZ);
 #if __FreeBSD_version >= 600023
        retcode = vm_mmap(&vms->vm_map, &vaddr, size, PROT_READ | PROT_WRITE,
-           VM_PROT_ALL, MAP_SHARED, OBJT_DEVICE, dev->devnode, foff);
+           VM_PROT_ALL, MAP_SHARED | MAP_NOSYNC, OBJT_DEVICE,
+           dev->devnode, foff);
 #else
        retcode = vm_mmap(&vms->vm_map, &vaddr, size, PROT_READ | PROT_WRITE,
-           VM_PROT_ALL, MAP_SHARED, SLIST_FIRST(&dev->devnode->si_hlist),
-           foff);
+           VM_PROT_ALL, MAP_SHARED | MAP_NOSYNC,
+           SLIST_FIRST(&dev->devnode->si_hlist), foff);
 #endif
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-       vaddr = round_page((vaddr_t)vms->vm_daddr + MAXDSIZ);
-       retcode = uvm_mmap(&vms->vm_map, &vaddr, size,
-           UVM_PROT_READ | UVM_PROT_WRITE, UVM_PROT_ALL, MAP_SHARED,
-           &vn->v_uobj, foff, p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur);
-#endif /* __NetBSD__ || __OpenBSD */
        if (retcode)
                goto done;
 
        request->virtual = (void *)vaddr;
 
-       for ( i = 0 ; i < dma->buf_count ; i++ ) {
+       for (i = 0; i < dma->buf_count; i++) {
                if (DRM_COPY_TO_USER(&request->list[i].idx,
                    &dma->buflist[i]->idx, sizeof(request->list[0].idx))) {
                        retcode = EFAULT;
@@ -1115,7 +1088,24 @@ int drm_mapbufs(drm_device_t *dev, void *data, struct drm_file *file_priv)
  done:
        request->count = dma->buf_count;
 
-       DRM_DEBUG( "%d buffers, retcode = %d\n", request->count, retcode );
+       DRM_DEBUG("%d buffers, retcode = %d\n", request->count, retcode);
 
        return retcode;
 }
+
+/*
+ * Compute order.  Can be made faster.
+ */
+int drm_order(unsigned long size)
+{
+       int order;
+
+       if (size == 0)
+               return 0;
+
+       order = flsl(size) - 1;
+       if (size & ~(1ul << order))
+               ++order;
+
+       return order;
+}
index 2319bc7..ecc468d 100644 (file)
  *    Rickard E. (Rik) Faith <faith@valinux.com>
  *    Gareth Hughes <gareth@valinux.com>
  *
- * $DragonFly: src/sys/dev/drm/drm_context.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_context.c
  * Implementation of the context management ioctls.
  */
 
-#include "drmP.h"
+#include "dev/drm/drmP.h"
 
 /* ================================================================
  * Context bitmap support
  */
 
-void drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle)
+void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle)
 {
        if (ctx_handle < 0 || ctx_handle >= DRM_MAX_CTXBITMAP || 
            dev->ctx_bitmap == NULL) {
@@ -55,7 +54,7 @@ void drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle)
        return;
 }
 
-int drm_ctxbitmap_next(drm_device_t *dev)
+int drm_ctxbitmap_next(struct drm_device *dev)
 {
        int bit;
 
@@ -63,7 +62,7 @@ int drm_ctxbitmap_next(drm_device_t *dev)
                return -1;
 
        DRM_LOCK();
-       bit = find_first_zero_bit( dev->ctx_bitmap, DRM_MAX_CTXBITMAP );
+       bit = find_first_zero_bit(dev->ctx_bitmap, DRM_MAX_CTXBITMAP);
        if (bit >= DRM_MAX_CTXBITMAP) {
                DRM_UNLOCK();
                return -1;
@@ -78,7 +77,7 @@ int drm_ctxbitmap_next(drm_device_t *dev)
 
                        ctx_sareas = realloc(dev->context_sareas,
                            dev->max_context * sizeof(*dev->context_sareas),
-                           M_DRM, M_NOWAIT);
+                           DRM_MEM_SAREA, M_NOWAIT);
                        if (ctx_sareas == NULL) {
                                clear_bit(bit, dev->ctx_bitmap);
                                DRM_UNLOCK();
@@ -89,7 +88,8 @@ int drm_ctxbitmap_next(drm_device_t *dev)
                } else {
                        /* max_context == 1 at this point */
                        dev->context_sareas = malloc(dev->max_context * 
-                           sizeof(*dev->context_sareas), M_DRM, M_NOWAIT);
+                           sizeof(*dev->context_sareas), DRM_MEM_SAREA,
+                           M_NOWAIT);
                        if (dev->context_sareas == NULL) {
                                clear_bit(bit, dev->ctx_bitmap);
                                DRM_UNLOCK();
@@ -102,14 +102,15 @@ int drm_ctxbitmap_next(drm_device_t *dev)
        return bit;
 }
 
-int drm_ctxbitmap_init(drm_device_t *dev)
+int drm_ctxbitmap_init(struct drm_device *dev)
 {
        int i;
        int temp;
 
        DRM_LOCK();
-       dev->ctx_bitmap = malloc(PAGE_SIZE, M_DRM, M_NOWAIT | M_ZERO);
-       if ( dev->ctx_bitmap == NULL ) {
+       dev->ctx_bitmap = malloc(PAGE_SIZE, DRM_MEM_CTXBITMAP,
+           M_NOWAIT | M_ZERO);
+       if (dev->ctx_bitmap == NULL) {
                DRM_UNLOCK();
                return ENOMEM;
        }
@@ -117,20 +118,20 @@ int drm_ctxbitmap_init(drm_device_t *dev)
        dev->max_context = -1;
        DRM_UNLOCK();
 
-       for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
+       for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
                temp = drm_ctxbitmap_next(dev);
-               DRM_DEBUG( "drm_ctxbitmap_init : %d\n", temp );
+               DRM_DEBUG("drm_ctxbitmap_init : %d\n", temp);
        }
 
        return 0;
 }
 
-void drm_ctxbitmap_cleanup(drm_device_t *dev)
+void drm_ctxbitmap_cleanup(struct drm_device *dev)
 {
        DRM_LOCK();
        if (dev->context_sareas != NULL)
-               free(dev->context_sareas, M_DRM);
-       free(dev->ctx_bitmap, M_DRM);
+               free(dev->context_sareas, DRM_MEM_SAREA);
+       free(dev->ctx_bitmap, DRM_MEM_CTXBITMAP);
        DRM_UNLOCK();
 }
 
@@ -138,9 +139,10 @@ void drm_ctxbitmap_cleanup(drm_device_t *dev)
  * Per Context SAREA Support
  */
 
-int drm_getsareactx( drm_device_t *dev, void *data, struct drm_file *file_priv )
+int drm_getsareactx(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv)
 {
-       drm_ctx_priv_map_t *request = data;
+       struct drm_ctx_priv_map *request = data;
        drm_local_map_t *map;
 
        DRM_LOCK();
@@ -158,9 +160,10 @@ int drm_getsareactx( drm_device_t *dev, void *data, struct drm_file *file_priv )
        return 0;
 }
 
-int drm_setsareactx(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_setsareactx(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv)
 {
-       drm_ctx_priv_map_t *request = data;
+       struct drm_ctx_priv_map *request = data;
        drm_local_map_t *map = NULL;
 
        DRM_LOCK();
@@ -185,51 +188,51 @@ bad:
  * The actual DRM context handling routines
  */
 
-int drm_context_switch(drm_device_t *dev, int old, int new)
+int drm_context_switch(struct drm_device *dev, int old, int new)
 {
-        if ( test_and_set_bit( 0, &dev->context_flag ) ) {
-                DRM_ERROR( "Reentering -- FIXME\n" );
-                return EBUSY;
-        }
+       if (test_and_set_bit(0, &dev->context_flag)) {
+               DRM_ERROR("Reentering -- FIXME\n");
+               return EBUSY;
+       }
 
-        DRM_DEBUG( "Context switch from %d to %d\n", old, new );
+       DRM_DEBUG("Context switch from %d to %d\n", old, new);
 
-        if ( new == dev->last_context ) {
-                clear_bit( 0, &dev->context_flag );
-                return 0;
-        }
+       if (new == dev->last_context) {
+               clear_bit(0, &dev->context_flag);
+               return 0;
+       }
 
-        return 0;
+       return 0;
 }
 
-int drm_context_switch_complete(drm_device_t *dev, int new)
+int drm_context_switch_complete(struct drm_device *dev, int new)
 {
-        dev->last_context = new;  /* PRE/POST: This is the _only_ writer. */
+       dev->last_context = new;  /* PRE/POST: This is the _only_ writer. */
 
-        if ( !_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) ) {
-                DRM_ERROR( "Lock isn't held after context switch\n" );
-        }
+       if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) {
+               DRM_ERROR("Lock isn't held after context switch\n");
+       }
 
-                               /* If a context switch is ever initiated
-                                   when the kernel holds the lock, release
-                                   that lock here. */
-        clear_bit( 0, &dev->context_flag );
+       /* If a context switch is ever initiated
+          when the kernel holds the lock, release
+          that lock here. */
+       clear_bit(0, &dev->context_flag);
 
-        return 0;
+       return 0;
 }
 
-int drm_resctx(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_resctx(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_ctx_res_t *res = data;
-       drm_ctx_t ctx;
+       struct drm_ctx_res *res = data;
+       struct drm_ctx ctx;
        int i;
 
-       if ( res->count >= DRM_RESERVED_CONTEXTS ) {
+       if (res->count >= DRM_RESERVED_CONTEXTS) {
                bzero(&ctx, sizeof(ctx));
-               for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
+               for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
                        ctx.handle = i;
-                       if ( DRM_COPY_TO_USER( &res->contexts[i],
-                                          &ctx, sizeof(ctx) ) )
+                       if (DRM_COPY_TO_USER(&res->contexts[i],
+                           &ctx, sizeof(ctx)))
                                return EFAULT;
                }
        }
@@ -238,40 +241,40 @@ int drm_resctx(drm_device_t *dev, void *data, struct drm_file *file_priv)
        return 0;
 }
 
-int drm_addctx(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_addctx(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_ctx_t *ctx = data;
+       struct drm_ctx *ctx = data;
 
        ctx->handle = drm_ctxbitmap_next(dev);
-       if ( ctx->handle == DRM_KERNEL_CONTEXT ) {
-                               /* Skip kernel's context and get a new one. */
+       if (ctx->handle == DRM_KERNEL_CONTEXT) {
+               /* Skip kernel's context and get a new one. */
                ctx->handle = drm_ctxbitmap_next(dev);
        }
-       DRM_DEBUG( "%d\n", ctx->handle );
-       if ( ctx->handle == -1 ) {
-               DRM_DEBUG( "Not enough free contexts.\n" );
-                               /* Should this return -EBUSY instead? */
+       DRM_DEBUG("%d\n", ctx->handle);
+       if (ctx->handle == -1) {
+               DRM_DEBUG("Not enough free contexts.\n");
+               /* Should this return -EBUSY instead? */
                return ENOMEM;
        }
 
-       if (dev->driver.context_ctor && ctx->handle != DRM_KERNEL_CONTEXT) {
+       if (dev->driver->context_ctor && ctx->handle != DRM_KERNEL_CONTEXT) {
                DRM_LOCK();
-               dev->driver.context_ctor(dev, ctx->handle);
+               dev->driver->context_ctor(dev, ctx->handle);
                DRM_UNLOCK();
        }
 
        return 0;
 }
 
-int drm_modctx(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_modctx(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
        /* This does nothing */
        return 0;
 }
 
-int drm_getctx(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_getctx(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_ctx_t *ctx = data;
+       struct drm_ctx *ctx = data;
 
        /* This is 0, because we don't handle any context flags */
        ctx->flags = 0;
@@ -279,33 +282,34 @@ int drm_getctx(drm_device_t *dev, void *data, struct drm_file *file_priv)
        return 0;
 }
 
-int drm_switchctx(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_switchctx(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
 {
-       drm_ctx_t *ctx = data;
+       struct drm_ctx *ctx = data;
 
-       DRM_DEBUG( "%d\n", ctx->handle );
+       DRM_DEBUG("%d\n", ctx->handle);
        return drm_context_switch(dev, dev->last_context, ctx->handle);
 }
 
-int drm_newctx(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_newctx(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_ctx_t *ctx = data;
+       struct drm_ctx *ctx = data;
 
-       DRM_DEBUG( "%d\n", ctx->handle );
+       DRM_DEBUG("%d\n", ctx->handle);
        drm_context_switch_complete(dev, ctx->handle);
 
        return 0;
 }
 
-int drm_rmctx(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_rmctx(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_ctx_t *ctx = data;
+       struct drm_ctx *ctx = data;
 
-       DRM_DEBUG( "%d\n", ctx->handle );
-       if ( ctx->handle != DRM_KERNEL_CONTEXT ) {
-               if (dev->driver.context_dtor) {
+       DRM_DEBUG("%d\n", ctx->handle);
+       if (ctx->handle != DRM_KERNEL_CONTEXT) {
+               if (dev->driver->context_dtor) {
                        DRM_LOCK();
-                       dev->driver.context_dtor(dev, ctx->handle);
+                       dev->driver->context_dtor(dev, ctx->handle);
                        DRM_UNLOCK();
                }
 
index 82dff2f..0cc5f72 100644 (file)
@@ -26,7 +26,6 @@
  *    Rickard E. (Rik) Faith <faith@valinux.com>
  *    Gareth Hughes <gareth@valinux.com>
  *
- * $DragonFly: src/sys/dev/drm/drm_dma.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_dma.c
  * schemes evolved.
  */
 
-#include "drmP.h"
+#include "dev/drm/drmP.h"
 
-int drm_dma_setup(drm_device_t *dev)
+int drm_dma_setup(struct drm_device *dev)
 {
 
-       dev->dma = malloc(sizeof(*dev->dma), M_DRM, M_NOWAIT | M_ZERO);
+       dev->dma = malloc(sizeof(*dev->dma), DRM_MEM_DRIVER, M_NOWAIT | M_ZERO);
        if (dev->dma == NULL)
                return ENOMEM;
 
@@ -51,7 +50,7 @@ int drm_dma_setup(drm_device_t *dev)
        return 0;
 }
 
-void drm_dma_takedown(drm_device_t *dev)
+void drm_dma_takedown(struct drm_device *dev)
 {
        drm_device_dma_t  *dma = dev->dma;
        int               i, j;
@@ -59,52 +58,53 @@ void drm_dma_takedown(drm_device_t *dev)
        if (dma == NULL)
                return;
 
-                               /* Clear dma buffers */
+       /* Clear dma buffers */
        for (i = 0; i <= DRM_MAX_ORDER; i++) {
                if (dma->bufs[i].seg_count) {
                        DRM_DEBUG("order %d: buf_count = %d,"
-                                 " seg_count = %d\n",
-                                 i,
-                                 dma->bufs[i].buf_count,
-                                 dma->bufs[i].seg_count);
+                           " seg_count = %d\n", i, dma->bufs[i].buf_count,
+                           dma->bufs[i].seg_count);
                        for (j = 0; j < dma->bufs[i].seg_count; j++) {
                                drm_pci_free(dev, dma->bufs[i].seglist[j]);
                        }
-                       free(dma->bufs[i].seglist, M_DRM);
+                       free(dma->bufs[i].seglist, DRM_MEM_SEGS);
                }
 
                if (dma->bufs[i].buf_count) {
                        for (j = 0; j < dma->bufs[i].buf_count; j++) {
                                free(dma->bufs[i].buflist[j].dev_private,
-                                   M_DRM);
+                                   DRM_MEM_BUFS);
                        }
-                       free(dma->bufs[i].buflist, M_DRM);
+                       free(dma->bufs[i].buflist, DRM_MEM_BUFS);
                }
        }
 
-       free(dma->buflist, M_DRM);
-       free(dma->pagelist, M_DRM);
-       free(dev->dma, M_DRM);
+       free(dma->buflist, DRM_MEM_BUFS);
+       free(dma->pagelist, DRM_MEM_PAGES);
+       free(dev->dma, DRM_MEM_DRIVER);
        dev->dma = NULL;
        DRM_SPINUNINIT(&dev->dma_lock);
 }
 
 
-void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf)
+void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf)
 {
-       if (!buf) return;
+       if (!buf)
+               return;
 
        buf->pending  = 0;
        buf->file_priv= NULL;
        buf->used     = 0;
 }
 
-void drm_reclaim_buffers(drm_device_t *dev, struct drm_file *file_priv)
+void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv)
 {
        drm_device_dma_t *dma = dev->dma;
        int              i;
 
-       if (!dma) return;
+       if (!dma)
+               return;
+
        for (i = 0; i < dma->buf_count; i++) {
                if (dma->buflist[i]->file_priv == file_priv) {
                        switch (dma->buflist[i]->list) {
@@ -123,12 +123,12 @@ void drm_reclaim_buffers(drm_device_t *dev, struct drm_file *file_priv)
 }
 
 /* Call into the driver-specific DMA handler */
-int drm_dma(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
 
-       if (dev->driver.dma_ioctl) {
+       if (dev->driver->dma_ioctl) {
                /* shared code returns -errno */
-               return -dev->driver.dma_ioctl(dev, data, file_priv);
+               return -dev->driver->dma_ioctl(dev, data, file_priv);
        } else {
                DRM_DEBUG("DMA ioctl on driver with no dma handler\n");
                return EINVAL;
index c525a67..3ad40ea 100644 (file)
@@ -26,7 +26,6 @@
  *    Rickard E. (Rik) Faith <faith@valinux.com>
  *    Gareth Hughes <gareth@valinux.com>
  *
- * $DragonFly: src/sys/dev/drm/drm_drawable.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_drawable.c
@@ -34,7 +33,7 @@
  * such as the current set of cliprects for vblank-synced buffer swaps.
  */
 
-#include "drmP.h"
+#include "dev/drm/drmP.h"
 
 struct bsd_drm_drawable_info {
        struct drm_drawable_info info;
@@ -52,13 +51,14 @@ drm_drawable_compare(struct bsd_drm_drawable_info *a,
                return -1;
        return 0;
 }
+
 RB_PROTOTYPE_STATIC(drawable_tree, bsd_drm_drawable_info, tree,
     drm_drawable_compare);
 RB_GENERATE_STATIC(drawable_tree, bsd_drm_drawable_info, tree,
     drm_drawable_compare);
 
 struct drm_drawable_info *
-drm_get_drawable_info(drm_device_t *dev, int handle)
+drm_get_drawable_info(struct drm_device *dev, int handle)
 {
        struct bsd_drm_drawable_info find, *result;
 
@@ -68,24 +68,21 @@ drm_get_drawable_info(drm_device_t *dev, int handle)
        return &result->info;
 }
 
-int drm_adddraw(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_adddraw(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_draw_t *draw = data;
+       struct drm_draw *draw = data;
        struct bsd_drm_drawable_info *info;
 
-       info = drm_calloc(1, sizeof(struct bsd_drm_drawable_info),
-           DRM_MEM_DRAWABLE);
+       info = malloc(sizeof(struct bsd_drm_drawable_info), DRM_MEM_DRAWABLE,
+           M_NOWAIT | M_ZERO);
        if (info == NULL)
                return ENOMEM;
 
-#ifdef __FreeBSD__
-       info->handle = alloc_unr(dev->drw_unrhdr);
-#else
        /*
         * XXX Only valid for sizeof(int) == sizeof(void *)
         */
        info->handle = (int)info;
-#endif
+
        DRM_SPINLOCK(&dev->drw_lock);
        RB_INSERT(drawable_tree, &dev->drw_head, info);
        draw->handle = info->handle;
@@ -96,9 +93,9 @@ int drm_adddraw(drm_device_t *dev, void *data, struct drm_file *file_priv)
        return 0;
 }
 
-int drm_rmdraw(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_rmdraw(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_draw_t *draw = (drm_draw_t *)data;
+       struct drm_draw *draw = (struct drm_draw *)data;
        struct drm_drawable_info *info;
 
        DRM_SPINLOCK(&dev->drw_lock);
@@ -107,11 +104,8 @@ int drm_rmdraw(drm_device_t *dev, void *data, struct drm_file *file_priv)
                RB_REMOVE(drawable_tree, &dev->drw_head,
                    (struct bsd_drm_drawable_info *)info);
                DRM_SPINUNLOCK(&dev->drw_lock);
-#ifdef __FreeBSD__
-               free_unr(dev->drw_unrhdr, draw->handle);
-#endif
-               drm_free(info, sizeof(struct bsd_drm_drawable_info),
-                   DRM_MEM_DRAWABLE);
+               free(info->rects, DRM_MEM_DRAWABLE);
+               free(info, DRM_MEM_DRAWABLE);
                return 0;
        } else {
                DRM_SPINUNLOCK(&dev->drw_lock);
@@ -119,7 +113,8 @@ int drm_rmdraw(drm_device_t *dev, void *data, struct drm_file *file_priv)
        }
 }
 
-int drm_update_draw(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_update_draw(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv)
 {
        struct drm_drawable_info *info;
        struct drm_update_draw *update = (struct drm_update_draw *)data;
@@ -133,9 +128,7 @@ int drm_update_draw(drm_device_t *dev, void *data, struct drm_file *file_priv)
        case DRM_DRAWABLE_CLIPRECTS:
                DRM_SPINLOCK(&dev->drw_lock);
                if (update->num != info->num_rects) {
-                       drm_free(info->rects,
-                           sizeof(*info->rects) * info->num_rects,
-                           DRM_MEM_DRAWABLE);
+                       free(info->rects, DRM_MEM_DRAWABLE);
                        info->rects = NULL;
                        info->num_rects = 0;
                }
@@ -144,10 +137,12 @@ int drm_update_draw(drm_device_t *dev, void *data, struct drm_file *file_priv)
                        return 0;
                }
                if (info->rects == NULL) {
-                       info->rects = drm_alloc(sizeof(*info->rects) *
-                           update->num, DRM_MEM_DRAWABLE);
-                       if (info->rects == NULL)
+                       info->rects = malloc(sizeof(*info->rects) *
+                           update->num, DRM_MEM_DRAWABLE, M_NOWAIT);
+                       if (info->rects == NULL) {
+                               DRM_SPINUNLOCK(&dev->drw_lock);
                                return ENOMEM;
+                       }
                        info->num_rects = update->num;
                }
                /* For some reason the pointer arg is unsigned long long. */
@@ -159,3 +154,21 @@ int drm_update_draw(drm_device_t *dev, void *data, struct drm_file *file_priv)
                return EINVAL;
        }
 }
+
+void drm_drawable_free_all(struct drm_device *dev)
+{
+       struct bsd_drm_drawable_info *info, *next;
+
+       DRM_SPINLOCK(&dev->drw_lock);
+       for (info = RB_MIN(drawable_tree, &dev->drw_head);
+           info != NULL ; info = next) {
+               next = RB_NEXT(drawable_tree, &dev->drw_head, info);
+               RB_REMOVE(drawable_tree, &dev->drw_head,
+                   (struct bsd_drm_drawable_info *)info);
+               DRM_SPINUNLOCK(&dev->drw_lock);
+               free(info->info.rects, DRM_MEM_DRAWABLE);
+               free(info, DRM_MEM_DRAWABLE);
+               DRM_SPINLOCK(&dev->drw_lock);
+       }
+       DRM_SPINUNLOCK(&dev->drw_lock);
+}
index 1fc007d..482990b 100644 (file)
@@ -26,7 +26,6 @@
  *    Rickard E. (Rik) Faith <faith@valinux.com>
  *    Gareth Hughes <gareth@valinux.com>
  *
- * $DragonFly: src/sys/dev/drm/drm_drv.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_drv.c
  * open/close, and ioctl dispatch.
  */
 
-#ifdef __DragonFly__
 #include <machine/limits.h>
-#else
-#include <sys/limits.h>
-#endif
-#include "drmP.h"
-#include "drm.h"
-#include "drm_sarea.h"
+#include "dev/drm/drmP.h"
+#include "dev/drm/drm.h"
+#include "dev/drm/drm_sarea.h"
 
 #ifdef DRM_DEBUG_DEFAULT_ON
 int drm_debug_flag = 1;
@@ -49,27 +44,18 @@ int drm_debug_flag = 1;
 int drm_debug_flag = 0;
 #endif
 
-static int drm_load(drm_device_t *dev);
-static void drm_unload(drm_device_t *dev);
+static int drm_load(struct drm_device *dev);
+static void drm_unload(struct drm_device *dev);
 static drm_pci_id_list_t *drm_find_description(int vendor, int device,
     drm_pci_id_list_t *idlist);
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
 #define DRIVER_SOFTC(unit) \
-       ((drm_device_t *)devclass_get_softc(drm_devclass, unit))
+       ((struct drm_device *)devclass_get_softc(drm_devclass, unit))
 
 MODULE_VERSION(drm, 1);
 MODULE_DEPEND(drm, agp, 1, 1, 1);
 MODULE_DEPEND(drm, pci, 1, 1, 1);
-#if __FreeBSD_version > 502127
 MODULE_DEPEND(drm, mem, 1, 1, 1);
-#endif
-#endif /* __FreeBSD__ || __DragonFly__ */
-
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#define DRIVER_SOFTC(unit) \
-       ((drm_device_t *)device_lookup(&drm_cd, unit))
-#endif /* __NetBSD__ || __OpenBSD__ */
 
 static drm_ioctl_desc_t                  drm_ioctls[256] = {
        DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, 0),
@@ -92,7 +78,7 @@ static drm_ioctl_desc_t                 drm_ioctls[256] = {
        DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
        DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_getsareactx, DRM_AUTH),
 
-       DRM_IOCTL_DEF(DRM_IOCTL_ADD_CTX, drm_addctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_ADD_CTX, drm_addctx, DRM_AUTH|DRM_ROOT_ONLY),
        DRM_IOCTL_DEF(DRM_IOCTL_RM_CTX, drm_rmctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
        DRM_IOCTL_DEF(DRM_IOCTL_MOD_CTX, drm_modctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
        DRM_IOCTL_DEF(DRM_IOCTL_GET_CTX, drm_getctx, DRM_AUTH),
@@ -105,10 +91,11 @@ static drm_ioctl_desc_t              drm_ioctls[256] = {
 
        DRM_IOCTL_DEF(DRM_IOCTL_LOCK, drm_lock, DRM_AUTH),
        DRM_IOCTL_DEF(DRM_IOCTL_UNLOCK, drm_unlock, DRM_AUTH),
+
        DRM_IOCTL_DEF(DRM_IOCTL_FINISH, drm_noop, DRM_AUTH),
 
-       DRM_IOCTL_DEF(DRM_IOCTL_ADD_BUFS, drm_addbufs_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_MARK_BUFS, drm_markbufs, DRM_AUTH|DRM_MASTER),
+       DRM_IOCTL_DEF(DRM_IOCTL_ADD_BUFS, drm_addbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_MARK_BUFS, drm_markbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
        DRM_IOCTL_DEF(DRM_IOCTL_INFO_BUFS, drm_infobufs, DRM_AUTH),
        DRM_IOCTL_DEF(DRM_IOCTL_MAP_BUFS, drm_mapbufs, DRM_AUTH),
        DRM_IOCTL_DEF(DRM_IOCTL_FREE_BUFS, drm_freebufs, DRM_AUTH),
@@ -127,265 +114,169 @@ static drm_ioctl_desc_t           drm_ioctls[256] = {
 
        DRM_IOCTL_DEF(DRM_IOCTL_SG_ALLOC, drm_sg_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
        DRM_IOCTL_DEF(DRM_IOCTL_SG_FREE, drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-
        DRM_IOCTL_DEF(DRM_IOCTL_WAIT_VBLANK, drm_wait_vblank, 0),
+       DRM_IOCTL_DEF(DRM_IOCTL_MODESET_CTL, drm_modeset_ctl, 0),
        DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW, drm_update_draw, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
 };
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
-#ifdef __FreeBSD__
-static struct cdevsw drm_cdevsw = {
-#if __FreeBSD_version >= 502103
-       .d_version =    D_VERSION,
-#endif
-       .d_open =       drm_open,
-       .d_close =      drm_close,
-       .d_read =       drm_read,
-       .d_ioctl =      drm_ioctl,
-       .d_poll =       drm_poll,
-       .d_mmap =       drm_mmap,
-       .d_name =       "drm",
-#if __FreeBSD_version >= 502103
-       .d_flags =      D_TRACKCLOSE | D_NEEDGIANT,
-#else
-       .d_maj =        145,
-       .d_flags =      D_TRACKCLOSE,
-#endif
-#if __FreeBSD_version < 500000
-       .d_bmaj =       -1
-#endif
-};
-#else  /* __FreeBSD__ */
 static struct dev_ops drm_cdevsw = {
        { "drm", 145, D_TRACKCLOSE },
-       .d_open =       drm_open,
-       .d_close =      drm_close,
-       .d_read =       drm_read,
-       .d_ioctl =      drm_ioctl,
-       .d_poll =       drm_poll,
-       .d_mmap =       drm_mmap
+       .d_open =       drm_open,
+       .d_read =       drm_read,
+       .d_ioctl =      drm_ioctl,
+       .d_poll =       drm_poll,
+       .d_mmap =       drm_mmap
+};
+
+int drm_msi = 1;       /* Enable by default. */
+TUNABLE_INT("hw.drm.msi", &drm_msi);
+
+static struct drm_msi_blacklist_entry drm_msi_blacklist[] = {
+       {0x8086, 0x2772}, /* Intel i945G        */ \
+       {0x8086, 0x27A2}, /* Intel i945GM       */ \
+       {0x8086, 0x27AE}, /* Intel i945GME      */ \
+       {0, 0}
 };
-#endif /* !__FreeBSD__ */
 
-int drm_probe(device_t dev, drm_pci_id_list_t *idlist)
+static int drm_msi_is_blacklisted(int vendor, int device)
+{
+       int i = 0;
+       
+       for (i = 0; drm_msi_blacklist[i].vendor != 0; i++) {
+               if ((drm_msi_blacklist[i].vendor == vendor) &&
+                   (drm_msi_blacklist[i].device == device)) {
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
+int drm_probe(device_t kdev, drm_pci_id_list_t *idlist)
 {
        drm_pci_id_list_t *id_entry;
        int vendor, device;
-#if __FreeBSD_version < 700010
        device_t realdev;
 
-       if (!strcmp(device_get_name(dev), "drmsub"))
-               realdev = device_get_parent(dev);
+       if (!strcmp(device_get_name(kdev), "drmsub"))
+               realdev = device_get_parent(kdev);
        else
-               realdev = dev;
+               realdev = kdev;
        vendor = pci_get_vendor(realdev);
        device = pci_get_device(realdev);
-#else
-       vendor = pci_get_vendor(dev);
-       device = pci_get_device(dev);
+
+#if 0 /* XXX */
+       if (pci_get_class(kdev) != PCIC_DISPLAY
+           || pci_get_subclass(kdev) != PCIS_DISPLAY_VGA)
+               return ENXIO;
 #endif
 
        id_entry = drm_find_description(vendor, device, idlist);
        if (id_entry != NULL) {
-               device_set_desc(dev, id_entry->name);
+               if (!device_get_desc(kdev)) {
+                       DRM_DEBUG("desc : %s\n", device_get_desc(kdev));
+                       device_set_desc(kdev, id_entry->name);
+               }
                return 0;
        }
 
        return ENXIO;
 }
 
-int drm_attach(device_t nbdev, drm_pci_id_list_t *idlist)
+int drm_attach(device_t kdev, drm_pci_id_list_t *idlist)
 {
-       drm_device_t *dev;
+       struct drm_device *dev;
        drm_pci_id_list_t *id_entry;
        int unit;
+#if 0
+       int msicount;
+#endif
 
-       unit = device_get_unit(nbdev);
-       dev = device_get_softc(nbdev);
+       unit = device_get_unit(kdev);
+       dev = device_get_softc(kdev);
 
-#if __FreeBSD_version < 700010
-       if (!strcmp(device_get_name(nbdev), "drmsub"))
-               dev->device = device_get_parent(nbdev);
+       if (!strcmp(device_get_name(kdev), "drmsub"))
+               dev->device = device_get_parent(kdev);
        else
-               dev->device = nbdev;
-#else
-       dev->device = nbdev;
-#endif
-#ifdef __DragonFly__
+               dev->device = kdev;
+
        dev_ops_add(&drm_cdevsw, -1, unit);
-#endif
        dev->devnode = make_dev(&drm_cdevsw,
                        unit,
                        DRM_DEV_UID,
                        DRM_DEV_GID,
                        DRM_DEV_MODE,
                        "dri/card%d", unit);
-#if __FreeBSD_version >= 500000
-       mtx_init(&dev->dev_lock, "drm device", NULL, MTX_DEF);
-       mtx_init(&dev->drw_lock, "drmdrw", NULL, MTX_DEF);
-#elif defined(__DragonFly__)
-       DRM_SPININIT(&dev->dev_lock, "drm device");
-       DRM_SPININIT(&dev->drw_lock, "drmdrw");
-#endif
-
-       id_entry = drm_find_description(pci_get_vendor(dev->device),
-           pci_get_device(dev->device), idlist);
-       dev->id_entry = id_entry;
-
-       return drm_load(dev);
-}
-
-int drm_detach(device_t dev)
-{
-       drm_unload(device_get_softc(dev));
-       return 0;
-}
 
-#ifndef DRM_DEV_NAME
-#define DRM_DEV_NAME "drm"
-#endif
-
-devclass_t drm_devclass;
-
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-
-static struct cdevsw drm_cdevsw = {
-       drm_open,
-       drm_close,
-       drm_read,
-       nowrite,
-       drm_ioctl,
-       nostop,
-       notty,
-       drm_poll,
-       drm_mmap,
-       nokqfilter,
-       D_TTY
-};
+       dev->pci_domain = 0;
+       dev->pci_bus = pci_get_bus(dev->device);
+       dev->pci_slot = pci_get_slot(dev->device);
+       dev->pci_func = pci_get_function(dev->device);
 
-int drm_refcnt = 0;
+       dev->pci_vendor = pci_get_vendor(dev->device);
+       dev->pci_device = pci_get_device(dev->device);
 
-#if defined(__NetBSD__) && __NetBSD_Version__ >= 106080000
-MOD_DEV("drm", DRIVER_NAME, NULL, -1, &drm_cdevsw, CDEV_MAJOR);
-#else
-MOD_DEV("drm", LM_DT_CHAR, CDEV_MAJOR, &drm_cdevsw);
+       if (drm_msi &&
+           !drm_msi_is_blacklisted(dev->pci_vendor, dev->pci_device)) {
+#if 0
+               msicount = pci_msi_count(dev->device);
+               DRM_DEBUG("MSI count = %d\n", msicount);
+               if (msicount > 1)
+                       msicount = 1;
+
+               if (pci_alloc_msi(dev->device, &msicount) == 0) {
+                       DRM_INFO("MSI enabled %d message(s)\n", msicount);
+                       dev->msi_enabled = 1;
+                       dev->irqrid = 1;
+               }
 #endif
+       }
 
-int drm_lkmentry(struct lkm_table *lkmtp, int cmd, int ver);
-static int drm_lkmhandle(struct lkm_table *lkmtp, int cmd);
-
-int drm_modprobe(void);
-int drm_probe(struct pci_attach_args *pa);
-void drm_attach(struct pci_attach_args *pa, dev_t kdev);
-
-int drm_lkmentry(struct lkm_table *lkmtp, int cmd, int ver) {
-       DISPATCH(lkmtp, cmd, ver, drm_lkmhandle, drm_lkmhandle, drm_lkmhandle);
-}
-
-static int drm_lkmhandle(struct lkm_table *lkmtp, int cmd)
-{
-       int error = 0;
-
-       switch(cmd) {
-       case LKM_E_LOAD:
-               if (lkmexists(lkmtp))
-                       return EEXIST;
+       dev->irqr = bus_alloc_resource_any(dev->device, SYS_RES_IRQ,
+           &dev->irqrid, RF_SHAREABLE);
+       if (!dev->irqr) {
+               return ENOENT;
+       }
 
-               if(drm_modprobe())
-                       return 0;
+       dev->irq = (int) rman_get_start(dev->irqr);
 
-               return 1;
+       DRM_SPININIT(&dev->dev_lock, "drmdev");
+       lwkt_serialize_init(&dev->irq_lock);
+       DRM_SPININIT(&dev->vbl_lock, "drmvbl");
+       DRM_SPININIT(&dev->drw_lock, "drmdrw");
 
-       case LKM_E_UNLOAD:
-               if (drm_refcnt > 0)
-                       return (EBUSY);
-               break;
-       case LKM_E_STAT:
-               break;
+       id_entry = drm_find_description(dev->pci_vendor,
+           dev->pci_device, idlist);
+       dev->id_entry = id_entry;
 
-       default:
-               error = EIO;
-               break;
-       }
-       
-       return error;
+       return drm_load(dev);
 }
 
-int drm_modprobe(void)
+int drm_detach(device_t kdev)
 {
-       struct pci_attach_args pa;
-       int error;
+       struct drm_device *dev;
 
-       error = pci_find_device(&pa, drm_probe, idlist);
-       if (error != 0)
-               drm_attach(&pa, 0);
+       dev = device_get_softc(kdev);
 
-       return error;
-}
+       drm_unload(dev);
 
-int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t idlist)
-{
-       const char *desc;
-       drm_pci_id_list_t *id_entry;
+       bus_release_resource(dev->device, SYS_RES_IRQ, dev->irqrid, dev->irqr);
 
-       id_entry = drm_find_description(PCI_VENDOR(pa->pa_id),
-           PCI_PRODUCT(pa->pa_id), idlist);
-       if (id_entry != NULL) {
-               return 1;
+#if 0
+       if (dev->msi_enabled) {
+               pci_release_msi(dev->device);
+               DRM_INFO("MSI released\n");
        }
+#endif
 
        return 0;
 }
 
-void drm_attach(struct pci_attach_args *pa, dev_t kdev, 
-    drm_pci_id_list_t *idlist)
-{
-       int i;
-       drm_device_t *dev;
-       drm_pci_id_list_t *id_entry;
-
-       config_makeroom(kdev, &drm_cd);
-       drm_cd.cd_devs[(kdev)] = malloc(sizeof(drm_device_t), M_DRM, M_WAITOK);
-       dev = DRIVER_SOFTC(kdev);
-
-       memset(dev, 0, sizeof(drm_device_t));
-       memcpy(&dev->pa, pa, sizeof(dev->pa));
-
-       dev->irq = pa->pa_intrline;
-       dev->pci_domain = 0;
-       dev->pci_bus = pa->pa_bus;
-       dev->pci_slot = pa->pa_device;
-       dev->pci_func = pa->pa_function;
-       dev->dma_tag = pa->pa_dmat;
-
-       id_entry = drm_find_description(PCI_VENDOR(pa->pa_id),
-           PCI_PRODUCT(pa->pa_id), idlist);
-       dev->driver.pci_id_entry = id_entry;
-
-       DRM_INFO("%s", id_entry->name);
-       drm_load(dev);
-}
-
-int drm_detach(struct device *self, int flags)
-{
-       drm_unload((drm_device_t *)self);
-       return 0;
-}
+#ifndef DRM_DEV_NAME
+#define DRM_DEV_NAME "drm"
+#endif
 
-int drm_activate(struct device *self, enum devact act)
-{
-       switch (act) {
-       case DVACT_ACTIVATE:
-               return (EOPNOTSUPP);
-               break;
-
-       case DVACT_DEACTIVATE:
-               /* FIXME */
-               break;
-       }
-       return (0);
-}
-#endif /* __NetBSD__ || __OpenBSD__ */
+devclass_t drm_devclass;
 
 drm_pci_id_list_t *drm_find_description(int vendor, int device,
     drm_pci_id_list_t *idlist)
@@ -394,14 +285,15 @@ drm_pci_id_list_t *drm_find_description(int vendor, int device,
        
        for (i = 0; idlist[i].vendor != 0; i++) {
                if ((idlist[i].vendor == vendor) &&
-                   (idlist[i].device == device)) {
+                   ((idlist[i].device == device) ||
+                   (idlist[i].device == 0))) {
                        return &idlist[i];
                }
        }
        return NULL;
 }
 
-static int drm_firstopen(drm_device_t *dev)
+static int drm_firstopen(struct drm_device *dev)
 {
        drm_local_map_t *map;
        int i;
@@ -410,22 +302,22 @@ static int drm_firstopen(drm_device_t *dev)
 
        /* prebuild the SAREA */
        i = drm_addmap(dev, 0, SAREA_MAX, _DRM_SHM,
-                      _DRM_CONTAINS_LOCK, &map);
+           _DRM_CONTAINS_LOCK, &map);
        if (i != 0)
                return i;
 
-       if (dev->driver.firstopen)
-               dev->driver.firstopen(dev);
+       if (dev->driver->firstopen)
+               dev->driver->firstopen(dev);
 
        dev->buf_use = 0;
 
-       if (dev->driver.use_dma) {
+       if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)) {
                i = drm_dma_setup(dev);
                if (i != 0)
                        return i;
        }
 
-       for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) {
+       for (i = 0; i < DRM_HASH_SIZE; i++) {
                dev->magiclist[i].head = NULL;
                dev->magiclist[i].tail = NULL;
        }
@@ -436,18 +328,14 @@ static int drm_firstopen(drm_device_t *dev)
        dev->last_context = 0;
        dev->if_version = 0;
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        dev->buf_sigio = NULL;
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-       dev->buf_pgid = 0;
-#endif
 
-       DRM_DEBUG( "\n" );
+       DRM_DEBUG("\n");
 
        return 0;
 }
 
-static int drm_lastclose(drm_device_t *dev)
+static int drm_lastclose(struct drm_device *dev)
 {
        drm_magic_entry_t *pt, *next;
        drm_local_map_t *map, *mapsave;
@@ -455,42 +343,46 @@ static int drm_lastclose(drm_device_t *dev)
 
        DRM_SPINLOCK_ASSERT(&dev->dev_lock);
 
-       DRM_DEBUG( "\n" );
+       DRM_DEBUG("\n");
 
-       if (dev->driver.lastclose != NULL)
-               dev->driver.lastclose(dev);
+       if (dev->driver->lastclose != NULL)
+               dev->driver->lastclose(dev);
 
        if (dev->irq_enabled)
                drm_irq_uninstall(dev);
 
-       if ( dev->unique ) {
-               free(dev->unique, M_DRM);
+       if (dev->unique) {
+               free(dev->unique, 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 ) {
+       /* Clear pid list */
+       for (i = 0; i < DRM_HASH_SIZE; i++) {
+               for (pt = dev->magiclist[i].head; pt; pt = next) {
                        next = pt->next;
-                       free(pt, M_DRM);
+                       free(pt, DRM_MEM_MAGIC);
                }
                dev->magiclist[i].head = dev->magiclist[i].tail = NULL;
        }
 
-                               /* Clear AGP information */
-       if ( dev->agp ) {
+       DRM_UNLOCK();
+       drm_drawable_free_all(dev);
+       DRM_LOCK();
+
+       /* Clear AGP information */
+       if (dev->agp) {
                drm_agp_mem_t *entry;
                drm_agp_mem_t *nexte;
 
                /* Remove AGP resources, but leave dev->agp intact until
                 * drm_unload is called.
                 */
-               for ( entry = dev->agp->memory ; entry ; entry = nexte ) {
+               for (entry = dev->agp->memory; entry; entry = nexte) {
                        nexte = entry->next;
-                       if ( entry->bound )
+                       if (entry->bound)
                                drm_agp_unbind_memory(entry->handle);
                        drm_agp_free_memory(entry->handle);
-                       free(entry, M_DRM);
+                       free(entry, DRM_MEM_AGPLISTS);
                }
                dev->agp->memory = NULL;
 
@@ -511,7 +403,7 @@ static int drm_lastclose(drm_device_t *dev)
        }
 
        drm_dma_takedown(dev);
-       if ( dev->lock.hw_lock ) {
+       if (dev->lock.hw_lock) {
                dev->lock.hw_lock = NULL; /* SHM removed */
                dev->lock.file_priv = NULL;
                DRM_WAKEUP_INT((void *)&dev->lock.lock_queue);
@@ -520,31 +412,16 @@ static int drm_lastclose(drm_device_t *dev)
        return 0;
 }
 
-static int drm_load(drm_device_t *dev)
+static int drm_load(struct drm_device *dev)
 {
        int i, retcode;
 
-       DRM_DEBUG( "\n" );
-
-       dev->irq = pci_get_irq(dev->device);
-#if defined(__FreeBSD__) && __FreeBSD_version >= 700053
-       dev->pci_domain = pci_get_domain(dev->device);
-#else
-       dev->pci_domain = 0;
-#endif
-       dev->pci_bus = pci_get_bus(dev->device);
-       dev->pci_slot = pci_get_slot(dev->device);
-       dev->pci_func = pci_get_function(dev->device);
-
-       dev->pci_vendor = pci_get_vendor(dev->device);
-       dev->pci_device = pci_get_device(dev->device);
+       DRM_DEBUG("\n");
 
        TAILQ_INIT(&dev->maplist);
 
        drm_mem_init();
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        drm_sysctl_init(dev);
-#endif
        TAILQ_INIT(&dev->files);
 
        dev->counters  = 6;
@@ -555,23 +432,25 @@ static int drm_load(drm_device_t *dev)
        dev->types[4]  = _DRM_STAT_LOCKS;
        dev->types[5]  = _DRM_STAT_UNLOCKS;
 
-       for ( i = 0 ; i < DRM_ARRAY_SIZE(dev->counts) ; i++ )
-               atomic_set( &dev->counts[i], 0 );
+       for (i = 0; i < DRM_ARRAY_SIZE(dev->counts); i++)
+               atomic_set(&dev->counts[i], 0);
 
-       if (dev->driver.load != NULL) {
+       if (dev->driver->load != NULL) {
                DRM_LOCK();
                /* Shared code returns -errno. */
-               retcode = -dev->driver.load(dev,
+               retcode = -dev->driver->load(dev,
                    dev->id_entry->driver_private);
+               pci_enable_busmaster(dev->device);
                DRM_UNLOCK();
                if (retcode != 0)
                        goto error;
        }
 
-       if (dev->driver.use_agp) {
+       if (drm_core_has_AGP(dev)) {
                if (drm_device_is_agp(dev))
                        dev->agp = drm_agp_init();
-               if (dev->driver.require_agp && dev->agp == NULL) {
+               if (drm_core_check_feature(dev, DRIVER_REQUIRE_AGP) &&
+                   dev->agp == NULL) {
                        DRM_ERROR("Card isn't AGP, or couldn't initialize "
                            "AGP.\n");
                        retcode = ENOMEM;
@@ -590,51 +469,37 @@ static int drm_load(drm_device_t *dev)
                goto error;
        }
 
-#ifdef __FreeBSD__
-       dev->drw_unrhdr = new_unrhdr(1, INT_MAX, NULL);
-       if (dev->drw_unrhdr == NULL) {
-               DRM_ERROR("Couldn't allocate drawable number allocator\n");
-               goto error;
-       }
-#endif
-
        DRM_INFO("Initialized %s %d.%d.%d %s\n",
-               dev->driver.name,
-               dev->driver.major,
-               dev->driver.minor,
-               dev->driver.patchlevel,
-               dev->driver.date);
+           dev->driver->name,
+           dev->driver->major,
+           dev->driver->minor,
+           dev->driver->patchlevel,
+           dev->driver->date);
 
        return 0;
 
 error:
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        drm_sysctl_cleanup(dev);
-#endif
        DRM_LOCK();
        drm_lastclose(dev);
        DRM_UNLOCK();
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        destroy_dev(dev->devnode);
-#if __FreeBSD_version >= 500000
-       mtx_destroy(&dev->dev_lock);
-#elif defined(__DragonFly__)
+
+       DRM_SPINUNINIT(&dev->drw_lock);
+       DRM_SPINUNINIT(&dev->vbl_lock);
        DRM_SPINUNINIT(&dev->dev_lock);
-#endif
-#endif
+
        return retcode;
 }
 
-static void drm_unload(drm_device_t *dev)
+static void drm_unload(struct drm_device *dev)
 {
        int i;
 
-       DRM_DEBUG( "\n" );
+       DRM_DEBUG("\n");
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        drm_sysctl_cleanup(dev);
        destroy_dev(dev->devnode);
-#endif
 
        drm_ctxbitmap_cleanup(dev);
 
@@ -646,6 +511,8 @@ static void drm_unload(drm_device_t *dev)
                DRM_DEBUG("mtrr_del = %d", retcode);
        }
 
+       drm_vblank_cleanup(dev);
+
        DRM_LOCK();
        drm_lastclose(dev);
        DRM_UNLOCK();
@@ -663,30 +530,29 @@ static void drm_unload(drm_device_t *dev)
                dev->pcir[i] = NULL;
        }
 
-       if ( dev->agp ) {
-               free(dev->agp, M_DRM);
+       if (dev->agp) {
+               free(dev->agp, DRM_MEM_AGPLISTS);
                dev->agp = NULL;
        }
 
-       if (dev->driver.unload != NULL)
-               dev->driver.unload(dev);
-
-#ifdef __FreeBSD__
-       delete_unrhdr(dev->drw_unrhdr);
-#endif
+       if (dev->driver->unload != NULL) {
+               DRM_LOCK();
+               dev->driver->unload(dev);
+               DRM_UNLOCK();
+       }
 
        drm_mem_uninit();
-#if defined(__FreeBSD__) &&  __FreeBSD_version >= 500000
-       mtx_destroy(&dev->dev_lock);
-#elif defined(__DragonFly__)
+
+       pci_disable_busmaster(dev->device);
+
+       DRM_SPINUNINIT(&dev->drw_lock);
+       DRM_SPINUNINIT(&dev->vbl_lock);
        DRM_SPINUNINIT(&dev->dev_lock);
-#endif
 }
 
-
-int drm_version(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_version(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_version_t *version = data;
+       struct drm_version *version = data;
        int len;
 
 #define DRM_COPY( name, value )                                                \
@@ -698,44 +564,37 @@ int drm_version(drm_device_t *dev, void *data, struct drm_file *file_priv)
                        return EFAULT;                          \
        }
 
-       version->version_major          = dev->driver.major;
-       version->version_minor          = dev->driver.minor;
-       version->version_patchlevel     = dev->driver.patchlevel;
+       version->version_major          = dev->driver->major;
+       version->version_minor          = dev->driver->minor;
+       version->version_patchlevel     = dev->driver->patchlevel;
 
-       DRM_COPY(version->name, dev->driver.name);
-       DRM_COPY(version->date, dev->driver.date);
-       DRM_COPY(version->desc, dev->driver.desc);
+       DRM_COPY(version->name, dev->driver->name);
+       DRM_COPY(version->date, dev->driver->date);
+       DRM_COPY(version->desc, dev->driver->desc);
 
        return 0;
 }
 
-#ifndef __DragonFly__
-int drm_open(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p)
-{
-#else
 int drm_open(struct dev_open_args *ap)
 {
        struct cdev *kdev = ap->a_head.a_dev;
        int flags = ap->a_oflags;
        int fmt = 0;
        struct thread *p = curthread;
-#endif
-       drm_device_t *dev = NULL;
+       struct drm_device *dev = NULL;
        int retcode = 0;
 
        dev = DRIVER_SOFTC(minor(kdev));
 
-       DRM_DEBUG( "open_count = %d\n", dev->open_count );
+       DRM_DEBUG("open_count = %d\n", dev->open_count);
 
        retcode = drm_open_helper(kdev, flags, fmt, p, dev);
 
-       if ( !retcode ) {
-               atomic_inc( &dev->counts[_DRM_STAT_OPENS] );
+       if (!retcode) {
+               atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
                DRM_LOCK();
-#if defined(__FreeBSD__) || defined(__DragonFly__)
                device_busy(dev->device);
-#endif
-               if ( !dev->open_count++ )
+               if (!dev->open_count++)
                        retcode = drm_firstopen(dev);
                DRM_UNLOCK();
        }
@@ -743,84 +602,60 @@ int drm_open(struct dev_open_args *ap)
        return retcode;
 }
 
-#ifndef __DragonFly__
-int drm_close(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p)
+void drm_close(void *data)
 {
-#else
-int drm_close(struct dev_close_args *ap)
-{
-       struct cdev *kdev = ap->a_head.a_dev;
-       struct thread *p = curthread;
-#endif
-       drm_device_t *dev = drm_get_device_from_kdev(kdev);
-       drm_file_t *file_priv;
+       struct drm_file *file_priv = data;
+       struct drm_device *dev = file_priv->dev;
        int retcode = 0;
 
-       DRM_DEBUG( "open_count = %d\n", dev->open_count );
+       DRM_DEBUG("open_count = %d\n", dev->open_count);
 
        DRM_LOCK();
 
-       file_priv = drm_find_file_by_proc(dev, p);
-       if (!file_priv) {
-               DRM_UNLOCK();
-               DRM_ERROR("can't find authenticator\n");
-               return EINVAL;
-       }
-
        if (--file_priv->refs != 0)
                goto done;
 
-       if (dev->driver.preclose != NULL)
-               dev->driver.preclose(dev, file_priv);
+       if (dev->driver->preclose != NULL)
+               dev->driver->preclose(dev, file_priv);
 
        /* ========================================================
         * Begin inline drm_release
         */
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
-       DRM_DEBUG( "pid = %d, device = 0x%lx, open_count = %d\n",
-                  DRM_CURRENTPID, (long)dev->device, dev->open_count );
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-       DRM_DEBUG( "pid = %d, device = 0x%lx, open_count = %d\n",
-                  DRM_CURRENTPID, (long)&dev->device, dev->open_count);
-#endif
+       DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
+           DRM_CURRENTPID, (long)dev->device, dev->open_count);
 
        if (dev->lock.hw_lock && _DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)
            && dev->lock.file_priv == file_priv) {
                DRM_DEBUG("Process %d dead, freeing lock for context %d\n",
                          DRM_CURRENTPID,
                          _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
-               if (dev->driver.reclaim_buffers_locked != NULL)
-                       dev->driver.reclaim_buffers_locked(dev, file_priv);
+               if (dev->driver->reclaim_buffers_locked != NULL)
+                       dev->driver->reclaim_buffers_locked(dev, file_priv);
 
-               drm_lock_free(dev, &dev->lock.hw_lock->lock,
+               drm_lock_free(&dev->lock,
                    _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
                
                                /* FIXME: may require heavy-handed reset of
                                    hardware at this point, possibly
                                    processed via a callback to the X
                                    server. */
-       } else if (dev->driver.reclaim_buffers_locked != NULL &&
+       } else if (dev->driver->reclaim_buffers_locked != NULL &&
            dev->lock.hw_lock != NULL) {
                /* The lock is required to reclaim buffers */
                for (;;) {
-                       if ( !dev->lock.hw_lock ) {
+                       if (!dev->lock.hw_lock) {
                                /* Device has been unregistered */
                                retcode = EINTR;
                                break;
                        }
-                       if (drm_lock_take(&dev->lock.hw_lock->lock,
-                           DRM_KERNEL_CONTEXT)) {
+                       if (drm_lock_take(&dev->lock, DRM_KERNEL_CONTEXT)) {
                                dev->lock.file_priv = file_priv;
                                dev->lock.lock_time = jiffies;
-                                atomic_inc( &dev->counts[_DRM_STAT_LOCKS] );
+                               atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
                                break;  /* Got lock */
                        }
-                               /* Contention */
-#if defined(__FreeBSD__) && __FreeBSD_version > 500000
-                       retcode = mtx_sleep((void *)&dev->lock.lock_queue,
-                           &dev->dev_lock, PZERO | PCATCH, "drmlk2", 0);
-#elif defined(__DragonFly__)
+                       /* Contention */
                        crit_enter();
                        tsleep_interlock((void *)&dev->lock.lock_queue);
                        DRM_UNLOCK();
@@ -828,123 +663,79 @@ int drm_close(struct dev_close_args *ap)
                            PCATCH, "drmlk2", 0);
                        crit_exit();
                        DRM_LOCK();
-#else
-                       retcode = tsleep((void *)&dev->lock.lock_queue,
-                           PZERO | PCATCH, "drmlk2", 0);
-#endif
                        if (retcode)
                                break;
                }
                if (retcode == 0) {
-                       dev->driver.reclaim_buffers_locked(dev, file_priv);
-                       drm_lock_free(dev, &dev->lock.hw_lock->lock,
-                           DRM_KERNEL_CONTEXT);
+                       dev->driver->reclaim_buffers_locked(dev, file_priv);
+                       drm_lock_free(&dev->lock, DRM_KERNEL_CONTEXT);
                }
        }
 
-       if (dev->driver.use_dma && !dev->driver.reclaim_buffers_locked)
+       if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) &&
+           !dev->driver->reclaim_buffers_locked)
                drm_reclaim_buffers(dev, file_priv);
 
-#if defined (__FreeBSD__) && (__FreeBSD_version >= 500000)
-       funsetown(&dev->buf_sigio);
-#elif defined(__FreeBSD__) || defined(__DragonFly__)
        funsetown(dev->buf_sigio);
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-       dev->buf_pgid = 0;
-#endif /* __NetBSD__  || __OpenBSD__ */
 
-       if (dev->driver.postclose != NULL)
-               dev->driver.postclose(dev, file_priv);
+       if (dev->driver->postclose != NULL)
+               dev->driver->postclose(dev, file_priv);
        TAILQ_REMOVE(&dev->files, file_priv, link);
-       free(file_priv, M_DRM);
+       free(file_priv, DRM_MEM_FILES);
 
        /* ========================================================
         * End inline drm_release
         */
-
 done:
-       atomic_inc( &dev->counts[_DRM_STAT_CLOSES] );
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+       atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
        device_unbusy(dev->device);
-#endif
        if (--dev->open_count == 0) {
                retcode = drm_lastclose(dev);
        }
 
        DRM_UNLOCK();
-       
-       return retcode;
 }
 
 /* drm_ioctl is called whenever a process performs an ioctl on /dev/drm.
  */
-#ifndef __DragonFly__
-int drm_ioctl(struct cdev *kdev, u_long cmd, caddr_t data, int flags, 
-    DRM_STRUCTPROC *p)
-{
-#else
 int drm_ioctl(struct dev_ioctl_args *ap)
 {
        struct cdev *kdev = ap->a_head.a_dev;
        u_long cmd = ap->a_cmd;
        caddr_t data = ap->a_data;
        struct thread *p = curthread;
-#endif
-       drm_device_t *dev = drm_get_device_from_kdev(kdev);
+       struct drm_device *dev = drm_get_device_from_kdev(kdev);
        int retcode = 0;
        drm_ioctl_desc_t *ioctl;
-       int (*func)(drm_device_t *dev, void *data, struct drm_file *file_priv);
+       int (*func)(struct drm_device *dev, void *data, struct drm_file *file_priv);
        int nr = DRM_IOCTL_NR(cmd);
        int is_driver_ioctl = 0;
-       drm_file_t *file_priv;
+       struct drm_file *file_priv;
 
-       DRM_LOCK();
        file_priv = drm_find_file_by_proc(dev, p);
-       DRM_UNLOCK();
-       if (file_priv == NULL) {
+       if (!file_priv) {
                DRM_ERROR("can't find authenticator\n");
                return EINVAL;
        }
 
-       atomic_inc( &dev->counts[_DRM_STAT_IOCTLS] );
+       atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
        ++file_priv->ioctl_count;
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
-       DRM_DEBUG( "pid=%d, cmd=0x%02lx, nr=0x%02x, dev 0x%lx, auth=%d\n",
+       DRM_DEBUG("pid=%d, cmd=0x%02lx, nr=0x%02x, dev 0x%lx, auth=%d\n",
            DRM_CURRENTPID, cmd, nr, (long)dev->device,
-           file_priv->authenticated );
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-       DRM_DEBUG( "pid=%d, cmd=0x%02lx, nr=0x%02x, dev 0x%lx, auth=%d\n",
-           DRM_CURRENTPID, cmd, nr, (long)&dev->device,
-           file_priv->authenticated );
-#endif
+           file_priv->authenticated);
 
        switch (cmd) {
        case FIONBIO:
        case FIOASYNC:
                return 0;
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        case FIOSETOWN:
                return fsetown(*(int *)data, &dev->buf_sigio);
 
        case FIOGETOWN:
-#if (__FreeBSD_version >= 500000)
-               *(int *) data = fgetown(&dev->buf_sigio);
-#else
                *(int *) data = fgetown(dev->buf_sigio);
-#endif
-               return 0;
-#endif /* __FreeBSD__ || __DragonFly__ */
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-       case TIOCSPGRP:
-               dev->buf_pgid = *(int *)data;
-               return 0;
-
-       case TIOCGPGRP:
-               *(int *)data = dev->buf_pgid;
                return 0;
-#endif /* __NetBSD__ */
        }
 
        if (IOCGROUP(cmd) != DRM_IOCTL_BASE) {
@@ -957,18 +748,18 @@ int drm_ioctl(struct dev_ioctl_args *ap)
        if (ioctl->func == NULL && nr >= DRM_COMMAND_BASE) {
                /* The array entries begin at DRM_COMMAND_BASE ioctl nr */
                nr -= DRM_COMMAND_BASE;
-               if (nr > dev->driver.max_ioctl) {
+               if (nr > dev->driver->max_ioctl) {
                        DRM_DEBUG("Bad driver ioctl number, 0x%x (of 0x%x)\n",
-                           nr, dev->driver.max_ioctl);
+                           nr, dev->driver->max_ioctl);
                        return EINVAL;
                }
-               ioctl = &dev->driver.ioctls[nr];
+               ioctl = &dev->driver->ioctls[nr];
                is_driver_ioctl = 1;
        }
        func = ioctl->func;
 
        if (func == NULL) {
-               DRM_DEBUG( "no function\n" );
+               DRM_DEBUG("no function\n");
                return EINVAL;
        }
 
@@ -992,7 +783,7 @@ int drm_ioctl(struct dev_ioctl_args *ap)
        return retcode;
 }
 
-drm_local_map_t *drm_getsarea(drm_device_t *dev)
+drm_local_map_t *drm_getsarea(struct drm_device *dev)
 {
        drm_local_map_t *map;
 
index a094839..a6a4cd5 100644 (file)
@@ -27,7 +27,6 @@
  *    Daryll Strauss <daryll@valinux.com>
  *    Gareth Hughes <gareth@valinux.com>
  *
- * $DragonFly: src/sys/dev/drm/drm_fops.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_fops.c
  * open of the DRM device.
  */
 
-#include "drmP.h"
+#include "dev/drm/drmP.h"
 
-drm_file_t *drm_find_file_by_proc(drm_device_t *dev, DRM_STRUCTPROC *p)
+struct drm_file *drm_find_file_by_proc(struct drm_device *dev, DRM_STRUCTPROC *p)
 {
-#if __FreeBSD_version >= 500021
-       uid_t uid = p->td_ucred->cr_svuid;
-       pid_t pid = p->td_proc->p_pid;
-#elif defined(__DragonFly__)
        uid_t uid = p->td_proc->p_ucred->cr_svuid;
        pid_t pid = p->td_proc->p_pid;
-#else
-       uid_t uid = p->p_cred->p_svuid;
-       pid_t pid = p->p_pid;
-#endif
-       drm_file_t *priv;
-
-       DRM_SPINLOCK_ASSERT(&dev->dev_lock);
+       struct drm_file *priv;
 
        TAILQ_FOREACH(priv, &dev->files, link)
                if (priv->pid == pid && priv->uid == uid)
@@ -61,10 +50,10 @@ drm_file_t *drm_find_file_by_proc(drm_device_t *dev, DRM_STRUCTPROC *p)
 
 /* drm_open_helper is called whenever a process opens /dev/drm. */
 int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
-                   drm_device_t *dev)
+                   struct drm_device *dev)
 {
-       int          m = minor(kdev);
-       drm_file_t   *priv;
+       struct drm_file *priv;
+       int m = minor(kdev);
        int retcode;
 
        if (flags & O_EXCL)
@@ -72,79 +61,55 @@ int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
        dev->flags = flags;
 
        DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m);
-
-       DRM_LOCK();
-       priv = drm_find_file_by_proc(dev, p);
-       if (priv) {
-               priv->refs++;
-       } else {
-               priv = malloc(sizeof(*priv), M_DRM, M_NOWAIT | M_ZERO);
-               if (priv == NULL) {
-                       DRM_UNLOCK();
-                       return ENOMEM;
-               }
-#if __FreeBSD_version >= 500000
-               priv->uid               = p->td_ucred->cr_svuid;
-               priv->pid               = p->td_proc->p_pid;
-#elif defined(__DragonFly__)
-               priv->uid               = p->td_proc->p_ucred->cr_svuid;
-               priv->pid               = p->td_proc->p_pid;
-#else
-               priv->uid               = p->p_cred->p_svuid;
-               priv->pid               = p->p_pid;
-#endif
-
-               priv->refs              = 1;
-               priv->minor             = m;
-               priv->ioctl_count       = 0;
-
-               /* for compatibility root is always authenticated */
-               priv->authenticated     = DRM_SUSER(p);
-
-               if (dev->driver.open) {
-                       /* shared code returns -errno */
-                       retcode = -dev->driver.open(dev, priv);
-                       if (retcode != 0) {
-                               free(priv, M_DRM);
-                               DRM_UNLOCK();
-                               return retcode;
-                       }
-               }
-
-               /* first opener automatically becomes master */
-               priv->master = TAILQ_EMPTY(&dev->files);
-
-               TAILQ_INSERT_TAIL(&dev->files, priv, link);
+        DRM_LOCK();
+        priv = drm_find_file_by_proc(dev, p);
+        if (priv) {
+                priv->refs++;
+        } else {
+                priv = malloc(sizeof(*priv), DRM_MEM_FILES, M_NOWAIT | M_ZERO);
+                if (priv == NULL) {
+                        DRM_UNLOCK();
+                        return ENOMEM;
+                }
+                priv->uid               = p->td_proc->p_ucred->cr_svuid;
+                priv->pid               = p->td_proc->p_pid;
+                priv->refs              = 1;
+                priv->minor             = m;
+                priv->ioctl_count       = 0;
+
+                /* for compatibility root is always authenticated */
+                priv->authenticated     = DRM_SUSER(p);
+
+                if (dev->driver->open) {
+                        /* shared code returns -errno */
+                        retcode = -dev->driver->open(dev, priv);
+                        if (retcode != 0) {
+                                free(priv, DRM_MEM_FILES);
+                                DRM_UNLOCK();
+                                return retcode;
+                        }
+                }
+
+                /* first opener automatically becomes master */
+                priv->master = TAILQ_EMPTY(&dev->files);
+
+                TAILQ_INSERT_TAIL(&dev->files, priv, link);
        }
+
        DRM_UNLOCK();
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        kdev->si_drv1 = dev;
-#endif
        return 0;
 }
 
 
 /* The drm_read and drm_poll are stubs to prevent spurious errors
  * on older X Servers (4.3.0 and earlier) */
-
-#ifdef __DragonFly__
 int drm_read(struct dev_read_args *ap)
 {
-       return (0);
-}
-
-int drm_poll(struct dev_poll_args *ap)
-{
-       return (0);
-}
-#else
-int drm_read(struct cdev *kdev, struct uio *uio, int ioflag)
-{
        return 0;
 }
 
-int drm_poll(struct cdev *kdev, int events, DRM_STRUCTPROC *p)
+int drm_poll(struct dev_poll_args *ap)
 {
        return 0;
 }
-#endif
index 4d35e16..cd72ecd 100644 (file)
@@ -1,4 +1,4 @@
-/*
+/*-
  * Copyright 2007 Red Hat, Inc
  * All rights reserved.
  *
@@ -20,8 +20,6 @@
  * 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.
- *
- * $DragonFly: src/sys/dev/drm/drm_internal.h,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /* This header file holds function prototypes and data types that are
index daf5fe0..8676040 100644 (file)
@@ -26,7 +26,6 @@
  *    Rickard E. (Rik) Faith <faith@valinux.com>
  *    Gareth Hughes <gareth@valinux.com>
  *
- * $DragonFly: src/sys/dev/drm/drm_ioctl.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_ioctl.c
@@ -34,7 +33,7 @@
  * information and reporting DRM information to userland.
  */
 
-#include "drmP.h"
+#include "dev/drm/drmP.h"
 
 /*
  * Beginning in revision 1.1 of the DRM interface, getunique will return
  * before setunique has been called.  The format for the bus-specific part of
  * the unique is not defined for any other bus.
  */
-int drm_getunique(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_getunique(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
 {
-       drm_unique_t     *u = data;
+       struct drm_unique *u = data;
 
        if (u->unique_len >= dev->unique_len) {
                if (DRM_COPY_TO_USER(u->unique, dev->unique, dev->unique_len))
@@ -58,9 +58,10 @@ int drm_getunique(drm_device_t *dev, void *data, struct drm_file *file_priv)
 /* Deprecated in DRM version 1.1, and will return EBUSY when setversion has
  * requested version 1.1 or greater.
  */
-int drm_setunique(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_setunique(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
 {
-       drm_unique_t *u = data;
+       struct drm_unique *u = data;
        int domain, bus, slot, func, ret;
        char *busid;
 
@@ -68,12 +69,12 @@ int drm_setunique(drm_device_t *dev, void *data, struct drm_file *file_priv)
        if (!u->unique_len || u->unique_len > 1024)
                return EINVAL;
 
-       busid = malloc(u->unique_len + 1, M_DRM, M_WAITOK);
+       busid = malloc(u->unique_len + 1, DRM_MEM_DRIVER, M_WAITOK);
        if (busid == NULL)
                return ENOMEM;
 
        if (DRM_COPY_FROM_USER(busid, u->unique, u->unique_len)) {
-               free(busid, M_DRM);
+               free(busid, DRM_MEM_DRIVER);
                return EFAULT;
        }
        busid[u->unique_len] = '\0';
@@ -83,7 +84,7 @@ int drm_setunique(drm_device_t *dev, void *data, struct drm_file *file_priv)
         */
        ret = sscanf(busid, "PCI:%d:%d:%d", &bus, &slot, &func);
        if (ret != 3) {
-               free(busid, M_DRM);
+               free(busid, DRM_MEM_DRIVER);
                return EINVAL;
        }
        domain = bus >> 8;
@@ -93,7 +94,7 @@ int drm_setunique(drm_device_t *dev, void *data, struct drm_file *file_priv)
            (bus != dev->pci_bus) ||
            (slot != dev->pci_slot) ||
            (func != dev->pci_func)) {
-               free(busid, M_DRM);
+               free(busid, DRM_MEM_DRIVER);
                return EINVAL;
        }
 
@@ -113,7 +114,7 @@ int drm_setunique(drm_device_t *dev, void *data, struct drm_file *file_priv)
 
 
 static int
-drm_set_busid(drm_device_t *dev)
+drm_set_busid(struct drm_device *dev)
 {
 
        DRM_LOCK();
@@ -124,7 +125,7 @@ drm_set_busid(drm_device_t *dev)
        }
 
        dev->unique_len = 20;
-       dev->unique = malloc(dev->unique_len + 1, M_DRM, M_NOWAIT);
+       dev->unique = malloc(dev->unique_len + 1, DRM_MEM_DRIVER, M_NOWAIT);
        if (dev->unique == NULL) {
                DRM_UNLOCK();
                return ENOMEM;
@@ -138,9 +139,9 @@ drm_set_busid(drm_device_t *dev)
        return 0;
 }
 
-int drm_getmap(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_getmap(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_map_t    *map = data;
+       struct drm_map     *map = data;
        drm_local_map_t    *mapinlist;
        int          idx;
        int          i = 0;
@@ -154,7 +155,7 @@ int drm_getmap(drm_device_t *dev, void *data, struct drm_file *file_priv)
        }
 
        TAILQ_FOREACH(mapinlist, &dev->maplist, link) {
-               if (i==idx) {
+               if (i == idx) {
                        map->offset = mapinlist->offset;
                        map->size   = mapinlist->size;
                        map->type   = mapinlist->type;
@@ -174,18 +175,18 @@ int drm_getmap(drm_device_t *dev, void *data, struct drm_file *file_priv)
        return 0;
 }
 
-int drm_getclient(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_getclient(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
 {
-       drm_client_t *client = data;
-       drm_file_t   *pt;
-       int          idx;
-       int          i = 0;
+       struct drm_client *client = data;
+       struct drm_file *pt;
+       int idx;
+       int i = 0;
 
        idx = client->idx;
        DRM_LOCK();
        TAILQ_FOREACH(pt, &dev->files, link) {
-               if (i==idx)
-               {
+               if (i == idx) {
                        client->auth  = pt->authenticated;
                        client->pid   = pt->pid;
                        client->uid   = pt->uid;
@@ -201,23 +202,22 @@ int drm_getclient(drm_device_t *dev, void *data, struct drm_file *file_priv)
        return EINVAL;
 }
 
-int drm_getstats(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_getstats(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_stats_t  *stats = data;
+       struct drm_stats *stats = data;
        int          i;
 
-       memset(stats, 0, sizeof(drm_stats_t));
+       memset(stats, 0, sizeof(struct drm_stats));
        
        DRM_LOCK();
 
        for (i = 0; i < dev->counters; i++) {
                if (dev->types[i] == _DRM_STAT_LOCK)
-                       stats->data[i].value
-                               = (dev->lock.hw_lock
-                                  ? dev->lock.hw_lock->lock : 0);
+                       stats->data[i].value =
+                           (dev->lock.hw_lock ? dev->lock.hw_lock->lock : 0);
                else 
                        stats->data[i].value = atomic_read(&dev->counts[i]);
-               stats->data[i].type  = dev->types[i];
+               stats->data[i].type = dev->types[i];
        }
        
        stats->count = dev->counters;
@@ -230,10 +230,11 @@ int drm_getstats(drm_device_t *dev, void *data, struct drm_file *file_priv)
 #define DRM_IF_MAJOR   1
 #define DRM_IF_MINOR   2
 
-int drm_setversion(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_setversion(struct drm_device *dev, void *data,
+                  struct drm_file *file_priv)
 {
-       drm_set_version_t *sv = data;
-       drm_set_version_t ver;
+       struct drm_set_version *sv = data;
+       struct drm_set_version ver;
        int if_version;
 
        /* Save the incoming data, and set the response before continuing
@@ -242,8 +243,8 @@ int drm_setversion(drm_device_t *dev, void *data, struct drm_file *file_priv)
        ver = *sv;
        sv->drm_di_major = DRM_IF_MAJOR;
        sv->drm_di_minor = DRM_IF_MINOR;
-       sv->drm_dd_major = dev->driver.major;
-       sv->drm_dd_minor = dev->driver.minor;
+       sv->drm_dd_major = dev->driver->major;
+       sv->drm_dd_minor = dev->driver->minor;
 
        if (ver.drm_di_major != -1) {
                if (ver.drm_di_major != DRM_IF_MAJOR ||
@@ -262,9 +263,9 @@ int drm_setversion(drm_device_t *dev, void *data, struct drm_file *file_priv)
        }
 
        if (ver.drm_dd_major != -1) {
-               if (ver.drm_dd_major != dev->driver.major ||
+               if (ver.drm_dd_major != dev->driver->major ||
                    ver.drm_dd_minor < 0 ||
-                   ver.drm_dd_minor > dev->driver.minor)
+                   ver.drm_dd_minor > dev->driver->minor)
                {
                        return EINVAL;
                }
@@ -274,7 +275,7 @@ int drm_setversion(drm_device_t *dev, void *data, struct drm_file *file_priv)
 }
 
 
-int drm_noop(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_noop(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
        DRM_DEBUG("\n");
        return 0;
index e75daac..2681b26 100644 (file)
@@ -23,7 +23,6 @@
  * Authors:
  *    Eric Anholt <anholt@FreeBSD.org>
  *
- * $DragonFly: src/sys/dev/drm/drm_irq.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_irq.c
  * handing interrupt handlers off to the drivers.
  */
 
-#include "drmP.h"
-#include "drm.h"
+#include "dev/drm/drmP.h"
+#include "dev/drm/drm.h"
 
-static void drm_locked_task(void *context, int pending __unused);
-
-int drm_irq_by_busid(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_irq_by_busid(struct drm_device *dev, void *data,
+                    struct drm_file *file_priv)
 {
-       drm_irq_busid_t *irq = data;
+       struct drm_irq_busid *irq = data;
 
        if ((irq->busnum >> 8) != dev->pci_domain ||
            (irq->busnum & 0xff) != dev->pci_bus ||
@@ -49,34 +47,100 @@ int drm_irq_by_busid(drm_device_t *dev, void *data, struct drm_file *file_priv)
        irq->irq = dev->irq;
 
        DRM_DEBUG("%d:%d:%d => IRQ %d\n",
-                 irq->busnum, irq->devnum, irq->funcnum, irq->irq);
+           irq->busnum, irq->devnum, irq->funcnum, irq->irq);
 
        return 0;
 }
 
-#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
-static irqreturn_t
-drm_irq_handler_wrap(DRM_IRQ_ARGS)
+static void vblank_disable_fn(void *arg)
 {
-       drm_device_t *dev = (drm_device_t *)arg;
+       struct drm_device *dev = (struct drm_device *)arg;
+       int i;
 
-       DRM_SPINLOCK(&dev->irq_lock);
-       dev->driver.irq_handler(arg);
-       DRM_SPINUNLOCK(&dev->irq_lock);
+       if (callout_pending(&dev->vblank_disable_timer)) {
+               /* callout was reset */
+               return;
+       }
+       if (!callout_active(&dev->vblank_disable_timer)) {
+               /* callout was stopped */
+               return;
+       }
+       callout_deactivate(&dev->vblank_disable_timer);
+
+       DRM_DEBUG("vblank_disable: %s\n", dev->vblank_disable_allowed ?
+               "allowed" : "denied");
+       if (!dev->vblank_disable_allowed)
+               return;
+
+       for (i = 0; i < dev->num_crtcs; i++) {
+               if (atomic_read(&dev->vblank[i].refcount) == 0 &&
+                   dev->vblank[i].enabled && !dev->vblank[i].inmodeset) {
+                       DRM_DEBUG("disabling vblank on crtc %d\n", i);
+                       dev->vblank[i].last =
+                           dev->driver->get_vblank_counter(dev, i);
+                       dev->driver->disable_vblank(dev, i);
+                       dev->vblank[i].enabled = 0;
+               }
+       }
 }
-#endif
 
-int drm_irq_install(drm_device_t *dev)
+void drm_vblank_cleanup(struct drm_device *dev)
 {
-       int retcode;
-#ifdef __NetBSD__
-       pci_intr_handle_t ih;
-#endif
+       /* Bail if the driver didn't call drm_vblank_init() */
+       if (dev->num_crtcs == 0)
+               return;
+
+       DRM_SPINLOCK(&dev->vbl_lock);
+       callout_stop(&dev->vblank_disable_timer);
+       DRM_SPINUNLOCK(&dev->vbl_lock);
+
+       vblank_disable_fn((void *)dev);
+
+       free(dev->vblank, DRM_MEM_DRIVER);
+
+       dev->num_crtcs = 0;
+}
+
+int drm_vblank_init(struct drm_device *dev, int num_crtcs)
+{
+       int i, ret = ENOMEM;
+
+       callout_init(&dev->vblank_disable_timer);
+       atomic_set(&dev->vbl_signal_pending, 0);
+       dev->num_crtcs = num_crtcs;
+
+       dev->vblank = malloc(sizeof(struct drm_vblank_info) * num_crtcs,
+           DRM_MEM_DRIVER, M_NOWAIT | M_ZERO);
+       if (!dev->vblank)
+           goto err;
+
+       DRM_DEBUG("\n");
+
+       /* Zero per-crtc vblank stuff */
+       for (i = 0; i < num_crtcs; i++) {
+               DRM_INIT_WAITQUEUE(&dev->vblank[i].queue);
+               TAILQ_INIT(&dev->vblank[i].sigs);
+               atomic_set(&dev->vblank[i].count, 0);
+               atomic_set(&dev->vblank[i].refcount, 0);
+       }
+
+       dev->vblank_disable_allowed = 0;
+
+       return 0;
+
+err:
+       drm_vblank_cleanup(dev);
+       return ret;
+}
+
+int drm_irq_install(struct drm_device *dev)
+{
+       int crtc, retcode;
 
        if (dev->irq == 0 || dev->dev_private == NULL)
                return EINVAL;
 
-       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, dev->irq );
+       DRM_DEBUG("irq=%d\n", dev->irq);
 
        DRM_LOCK();
        if (dev->irq_enabled) {
@@ -87,130 +151,94 @@ int drm_irq_install(drm_device_t *dev)
 
        dev->context_flag = 0;
 
-#ifndef __DragonFly__
-       DRM_SPININIT(&dev->irq_lock, "DRM IRQ lock");
-#else
-       lwkt_serialize_init(&dev->irq_lock);
-#endif
-
-                               /* Before installing handler */
-       dev->driver.irq_preinstall(dev);
+       /* Before installing handler */
+       dev->driver->irq_preinstall(dev);
        DRM_UNLOCK();
 
-                               /* Install handler */
-#if defined(__FreeBSD__) || defined(__DragonFly__)
-       dev->irqrid = 0;
-       dev->irqr = bus_alloc_resource_any(dev->device, SYS_RES_IRQ, 
-                                     &dev->irqrid, RF_SHAREABLE);
-       if (!dev->irqr) {
-               retcode = ENOENT;
-               goto err;
-       }
-#if __FreeBSD_version >= 700031
-       retcode = bus_setup_intr(dev->device, dev->irqr,
-                                INTR_TYPE_TTY | INTR_MPSAFE,
-                                NULL, drm_irq_handler_wrap, dev, &dev->irqh);
-#elif defined(__DragonFly__)
-       retcode = bus_setup_intr(dev->device, dev->irqr,
-                                INTR_MPSAFE,
-                                dev->driver.irq_handler, dev, &dev->irqh,
+       /* Install handler */
+       retcode = bus_setup_intr(dev->device, dev->irqr, INTR_MPSAFE,
+                                dev->driver->irq_handler, dev, &dev->irqh,
                                 &dev->irq_lock);
-#else
-       retcode = bus_setup_intr(dev->device, dev->irqr,
-                                INTR_TYPE_TTY | INTR_MPSAFE,
-                                drm_irq_handler_wrap, dev, &dev->irqh);
-#endif
        if (retcode != 0)
                goto err;
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-       if (pci_intr_map(&dev->pa, &ih) != 0) {
-               retcode = ENOENT;
-               goto err;
-       }
-       dev->irqh = pci_intr_establish(&dev->pa.pa_pc, ih, IPL_TTY,
-           (irqreturn_t (*)(void *))dev->irq_handler, dev);
-       if (!dev->irqh) {
-               retcode = ENOENT;
-               goto err;
-       }
-#endif
 
-                               /* After installing handler */
+       /* After installing handler */
        DRM_LOCK();
-       dev->driver.irq_postinstall(dev);
+       dev->driver->irq_postinstall(dev);
        DRM_UNLOCK();
+       if (dev->driver->enable_vblank) {
+               DRM_SPINLOCK(&dev->vbl_lock);
+               for( crtc = 0 ; crtc < dev->num_crtcs ; crtc++) {
+                       if (dev->driver->enable_vblank(dev, crtc) == 0) {
+                               dev->vblank[crtc].enabled = 1;
+                       }
+               }
+               callout_reset(&dev->vblank_disable_timer, 5 * DRM_HZ,
+                   (timeout_t *)vblank_disable_fn, (void *)dev);
+               DRM_SPINUNLOCK(&dev->vbl_lock);
+       }
 
-       TASK_INIT(&dev->locked_task, 0, drm_locked_task, dev);
        return 0;
 err:
        DRM_LOCK();
        dev->irq_enabled = 0;
-#if defined(___FreeBSD__) || defined(__DragonFly__)
-       if (dev->irqrid != 0) {
-               bus_release_resource(dev->device, SYS_RES_IRQ, dev->irqrid,
-                   dev->irqr);
-               dev->irqrid = 0;
-       }
-#endif
-#ifndef __DragonFly__
-       DRM_SPINUNINIT(&dev->irq_lock);
-#endif
        DRM_UNLOCK();
+
        return retcode;
 }
 
-int drm_irq_uninstall(drm_device_t *dev)
+int drm_irq_uninstall(struct drm_device *dev)
 {
-#if defined(__FreeBSD__) || defined(__DragonFly__)
-       int irqrid;
-#endif
+       int crtc;
 
        if (!dev->irq_enabled)
                return EINVAL;
 
        dev->irq_enabled = 0;
-#if defined(__FreeBSD__) || defined(__DragonFly__)
-       irqrid = dev->irqrid;
-       dev->irqrid = 0;
-#endif
 
-       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, dev->irq );
+       /*
+       * Wake up any waiters so they don't hang.
+       */
+       DRM_SPINLOCK(&dev->vbl_lock);
+       for (crtc = 0; crtc < dev->num_crtcs; crtc++) {
+               if (dev->vblank[crtc].enabled) {
+                       DRM_WAKEUP(&dev->vblank[crtc].queue);
+                       dev->vblank[crtc].last =
+                           dev->driver->get_vblank_counter(dev, crtc);
+                       dev->vblank[crtc].enabled = 0;
+               }
+       }
+       DRM_SPINUNLOCK(&dev->vbl_lock);
 
-       dev->driver.irq_uninstall(dev);
+       DRM_DEBUG("irq=%d\n", dev->irq);
+
+       dev->driver->irq_uninstall(dev);
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        DRM_UNLOCK();
        bus_teardown_intr(dev->device, dev->irqr, dev->irqh);
-       bus_release_resource(dev->device, SYS_RES_IRQ, irqrid, dev->irqr);
        DRM_LOCK();
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-       pci_intr_disestablish(&dev->pa.pa_pc, dev->irqh);
-#endif
-#ifndef __DragonFly__
-       DRM_SPINUNINIT(&dev->irq_lock);
-#endif
 
        return 0;
 }
 
-int drm_control(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_control(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_control_t *ctl = data;
+       struct drm_control *ctl = data;
        int err;
 
-       switch ( ctl->func ) {
+       switch (ctl->func) {
        case DRM_INST_HANDLER:
                /* Handle drivers whose DRM used to require IRQ setup but the
                 * no longer does.
                 */
-               if (!dev->driver.use_irq)
+               if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
                        return 0;
                if (dev->if_version < DRM_IF_VERSION(1, 2) &&
                    ctl->irq != dev->irq)
                        return EINVAL;
                return drm_irq_install(dev);
        case DRM_UNINST_HANDLER:
-               if (!dev->driver.use_irq)
+               if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
                        return 0;
                DRM_LOCK();
                err = drm_irq_uninstall(dev);
@@ -221,12 +249,136 @@ int drm_control(drm_device_t *dev, void *data, struct drm_file *file_priv)
        }
 }
 
-int drm_wait_vblank(drm_device_t *dev, void *data, struct drm_file *file_priv)
+u32 drm_vblank_count(struct drm_device *dev, int crtc)
+{
+       return atomic_read(&dev->vblank[crtc].count);
+}
+
+static void drm_update_vblank_count(struct drm_device *dev, int crtc)
+{
+       u32 cur_vblank, diff;
+
+       /*
+        * Interrupts were disabled prior to this call, so deal with counter
+        * wrap if needed.
+        * NOTE!  It's possible we lost a full dev->max_vblank_count events
+        * here if the register is small or we had vblank interrupts off for
+        * a long time.
+        */
+       cur_vblank = dev->driver->get_vblank_counter(dev, crtc);
+       diff = cur_vblank - dev->vblank[crtc].last;
+       if (cur_vblank < dev->vblank[crtc].last) {
+               diff += dev->max_vblank_count;
+
+               DRM_DEBUG("vblank[%d].last=0x%x, cur_vblank=0x%x => diff=0x%x\n",
+                   crtc, dev->vblank[crtc].last, cur_vblank, diff);
+       }
+
+       DRM_DEBUG("enabling vblank interrupts on crtc %d, missed %d\n",
+           crtc, diff);
+
+       atomic_add(diff, &dev->vblank[crtc].count);
+}
+
+int drm_vblank_get(struct drm_device *dev, int crtc)
+{
+       int ret = 0;
+
+       DRM_SPINLOCK(&dev->vbl_lock);
+       /* Going from 0->1 means we have to enable interrupts again */
+       atomic_add_acq_int(&dev->vblank[crtc].refcount, 1);
+       if (dev->vblank[crtc].refcount == 1 &&
+           !dev->vblank[crtc].enabled) {
+               ret = dev->driver->enable_vblank(dev, crtc);
+               DRM_DEBUG("enabling vblank on crtc %d, ret: %d\n", crtc, ret);
+               if (ret)
+                       atomic_dec(&dev->vblank[crtc].refcount);
+               else {
+                       dev->vblank[crtc].enabled = 1;
+                       drm_update_vblank_count(dev, crtc);
+               }
+       }
+       DRM_SPINUNLOCK(&dev->vbl_lock);
+
+       return ret;
+}
+
+void drm_vblank_put(struct drm_device *dev, int crtc)
+{
+       KASSERT(atomic_read(&dev->vblank[crtc].refcount) > 0,
+           ("invalid refcount"));
+
+       /* Last user schedules interrupt disable */
+       atomic_subtract_acq_int(&dev->vblank[crtc].refcount, 1);
+
+       DRM_SPINLOCK(&dev->vbl_lock);
+       if (dev->vblank[crtc].refcount == 0)
+           callout_reset(&dev->vblank_disable_timer, 5 * DRM_HZ,
+               (timeout_t *)vblank_disable_fn, (void *)dev);
+       DRM_SPINUNLOCK(&dev->vbl_lock);
+}
+
+int drm_modeset_ctl(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv)
+{
+       struct drm_modeset_ctl *modeset = data;
+       int crtc, ret = 0;
+
+       DRM_DEBUG("num_crtcs=%d\n", dev->num_crtcs);
+       /* If drm_vblank_init() hasn't been called yet, just no-op */
+       if (!dev->num_crtcs)
+               goto out;
+
+       crtc = modeset->crtc;
+       DRM_DEBUG("crtc=%d\n", crtc);
+       if (crtc >= dev->num_crtcs) {
+               ret = EINVAL;
+               goto out;
+       }
+
+       /*
+        * To avoid all the problems that might happen if interrupts
+        * were enabled/disabled around or between these calls, we just
+        * have the kernel take a reference on the CRTC (just once though
+        * to avoid corrupting the count if multiple, mismatch calls occur),
+        * so that interrupts remain enabled in the interim.
+        */
+       switch (modeset->cmd) {
+       case _DRM_PRE_MODESET:
+               DRM_DEBUG("pre-modeset\n");
+               if (!dev->vblank[crtc].inmodeset) {
+                       dev->vblank[crtc].inmodeset = 0x1;
+                       if (drm_vblank_get(dev, crtc) == 0)
+                               dev->vblank[crtc].inmodeset |= 0x2;
+               }
+               break;
+       case _DRM_POST_MODESET:
+               DRM_DEBUG("post-modeset\n");
+               if (dev->vblank[crtc].inmodeset) {
+                       DRM_SPINLOCK(&dev->vbl_lock);
+                       dev->vblank_disable_allowed = 1;
+                       DRM_SPINUNLOCK(&dev->vbl_lock);
+
+                       if (dev->vblank[crtc].inmodeset & 0x2)
+                               drm_vblank_put(dev, crtc);
+
+                       dev->vblank[crtc].inmodeset = 0;
+               }
+               break;
+       default:
+               ret = EINVAL;
+               break;
+       }
+
+out:
+       return ret;
+}
+
+int drm_wait_vblank(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_wait_vblank_t *vblwait = data;
-       struct timeval now;
+       union drm_wait_vblank *vblwait = data;
+       unsigned int flags, seq, crtc;
        int ret = 0;
-       int flags, seq;
 
        if (!dev->irq_enabled)
                return EINVAL;
@@ -240,12 +392,17 @@ int drm_wait_vblank(drm_device_t *dev, void *data, struct drm_file *file_priv)
        }
 
        flags = vblwait->request.type & _DRM_VBLANK_FLAGS_MASK;
+       crtc = flags & _DRM_VBLANK_SECONDARY ? 1 : 0;
 
-       if ((flags & _DRM_VBLANK_SECONDARY) && !dev->driver.use_vbl_irq2)
+       if (crtc >= dev->num_crtcs)
                return EINVAL;
-       
-       seq = atomic_read((flags & _DRM_VBLANK_SECONDARY) ?
-           &dev->vbl_received2 : &dev->vbl_received);
+
+       ret = drm_vblank_get(dev, crtc);
+       if (ret) {
+               DRM_ERROR("failed to acquire vblank counter, %d\n", ret);
+               return ret;
+       }
+       seq = drm_vblank_count(dev, crtc);
 
        switch (vblwait->request.type & _DRM_VBLANK_TYPES_MASK) {
        case _DRM_VBLANK_RELATIVE:
@@ -254,7 +411,8 @@ int drm_wait_vblank(drm_device_t *dev, void *data, struct drm_file *file_priv)
        case _DRM_VBLANK_ABSOLUTE:
                break;
        default:
-               return EINVAL;
+               ret = EINVAL;
+               goto done;
        }
 
        if ((flags & _DRM_VBLANK_NEXTONMISS) &&
@@ -264,8 +422,8 @@ int drm_wait_vblank(drm_device_t *dev, void *data, struct drm_file *file_priv)
 
        if (flags & _DRM_VBLANK_SIGNAL) {
 #if 0 /* disabled */
-               drm_vbl_sig_t *vbl_sig = malloc(sizeof(drm_vbl_sig_t), M_DRM,
-                   M_NOWAIT | M_ZERO);
+               drm_vbl_sig_t *vbl_sig = malloc(sizeof(drm_vbl_sig_t),
+                   DRM_MEM_DRIVER, M_NOWAIT | M_ZERO);
                if (vbl_sig == NULL)
                        return ENOMEM;
 
@@ -275,39 +433,54 @@ int drm_wait_vblank(drm_device_t *dev, void *data, struct drm_file *file_priv)
 
                vblwait->reply.sequence = atomic_read(&dev->vbl_received);
                
-               DRM_SPINLOCK(&dev->irq_lock);
+               DRM_SPINLOCK(&dev->vbl_lock);
                TAILQ_INSERT_HEAD(&dev->vbl_sig_list, vbl_sig, link);
-               DRM_SPINUNLOCK(&dev->irq_lock);
+               DRM_SPINUNLOCK(&dev->vbl_lock);
                ret = 0;
 #endif
                ret = EINVAL;
        } else {
-               DRM_LOCK();
-               /* shared code returns -errno */
-               if (flags & _DRM_VBLANK_SECONDARY) {
-                       if (dev->driver.vblank_wait2)
-                               ret = -dev->driver.vblank_wait2(dev,
-                                   &vblwait->request.sequence);
-               } else if (dev->driver.vblank_wait)
-                       ret = -dev->driver.vblank_wait(dev,
-                           &vblwait->request.sequence);
-
-               DRM_UNLOCK();
+               DRM_DEBUG("waiting on vblank count %d, crtc %d\n",
+                   vblwait->request.sequence, crtc);
+               dev->vblank[crtc].last = vblwait->request.sequence;
+               for ( ret = 0 ; !ret && !(((drm_vblank_count(dev, crtc) -
+                   vblwait->request.sequence) <= (1 << 23)) ||
+                   !dev->irq_enabled) ; ) {
+                       lwkt_serialize_enter(&dev->irq_lock);
+                       if (!(((drm_vblank_count(dev, crtc) -
+                           vblwait->request.sequence) <= (1 << 23)) ||
+                           !dev->irq_enabled))
+                               ret = serialize_sleep(&dev->vblank[crtc].queue,
+                                   &dev->irq_lock, PCATCH, "vblwtq",
+                                   3 * DRM_HZ);
+                       lwkt_serialize_exit(&dev->irq_lock);
+               }
 
-               microtime(&now);
-               vblwait->reply.tval_sec = now.tv_sec;
-               vblwait->reply.tval_usec = now.tv_usec;
+               if (ret != EINTR && ret != ERESTART) {
+                       struct timeval now;
+
+                       microtime(&now);
+                       vblwait->reply.tval_sec = now.tv_sec;
+                       vblwait->reply.tval_usec = now.tv_usec;
+                       vblwait->reply.sequence = drm_vblank_count(dev, crtc);
+                       DRM_DEBUG("returning %d to client, irq_enabled %d\n",
+                           vblwait->reply.sequence, dev->irq_enabled);
+               } else {
+                       DRM_DEBUG("vblank wait interrupted by signal\n");
+               }
        }
 
+done:
+       drm_vblank_put(dev, crtc);
        return ret;
 }
 
-void drm_vbl_send_signals(drm_device_t *dev)
+void drm_vbl_send_signals(struct drm_device *dev, int crtc)
 {
 }
 
 #if 0 /* disabled */
-void drm_vbl_send_signals( drm_device_t *dev )
+void drm_vbl_send_signals(struct drm_device *dev, int crtc )
 {
        drm_vbl_sig_t *vbl_sig;
        unsigned int vbl_seq = atomic_read( &dev->vbl_received );
@@ -317,7 +490,7 @@ void drm_vbl_send_signals( drm_device_t *dev )
        while (vbl_sig != NULL) {
                drm_vbl_sig_t *next = TAILQ_NEXT(vbl_sig, link);
 
-               if ( ( vbl_seq - vbl_sig->sequence ) <= (1<<23) ) {
+               if ((vbl_seq - vbl_sig->sequence) <= (1 << 23)) {
                        p = pfind(vbl_sig->pid);
                        if (p != NULL)
                                psignal(p, vbl_sig->signo);
@@ -330,52 +503,10 @@ void drm_vbl_send_signals( drm_device_t *dev )
 }
 #endif
 
-static void drm_locked_task(void *context, int pending __unused)
+void drm_handle_vblank(struct drm_device *dev, int crtc)
 {
-       drm_device_t *dev = context;
-
-       DRM_LOCK();
-       for (;;) {
-               int ret;
-
-               if (drm_lock_take(&dev->lock.hw_lock->lock,
-                   DRM_KERNEL_CONTEXT))
-               {
-                       dev->lock.file_priv = NULL; /* kernel owned */
-                       dev->lock.lock_time = jiffies;
-                       atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
-                       break;  /* Got lock */
-               }
-
-               /* Contention */
-#if defined(__FreeBSD__) && __FreeBSD_version > 500000
-               ret = mtx_sleep((void *)&dev->lock.lock_queue, &dev->dev_lock,
-                   PZERO | PCATCH, "drmlk2", 0);
-#elif defined(__DragonFly__)
-               crit_enter();
-               tsleep_interlock((void *)&dev->lock.lock_queue);
-               DRM_UNLOCK();
-               ret = tsleep((void *)&dev->lock.lock_queue, PCATCH,
-                   "drmlk2", 0);
-               crit_exit();
-               DRM_LOCK();
-#else
-               ret = tsleep((void *)&dev->lock.lock_queue, PZERO | PCATCH,
-                   "drmlk2", 0);
-#endif
-               if (ret != 0)
-                       return;
-       }
-       DRM_UNLOCK();
-
-       dev->locked_task_call(dev);
-
-       drm_lock_free(dev, &dev->lock.hw_lock->lock, DRM_KERNEL_CONTEXT);
+       atomic_inc(&dev->vblank[crtc].count);
+       DRM_WAKEUP(&dev->vblank[crtc].queue);
+       drm_vbl_send_signals(dev, crtc);
 }
 
-void
-drm_locked_tasklet(drm_device_t *dev, void (*tasklet)(drm_device_t *dev))
-{
-       dev->locked_task_call = tasklet;
-       taskqueue_enqueue(taskqueue_swi, &dev->locked_task);
-}
index 686dce5..15c1b6e 100644 (file)
@@ -27,7 +27,6 @@
  * Authors:
  *    Eric Anholt <anholt@FreeBSD.org>
  *
- * $DragonFly: src/sys/dev/drm/drm_linux_list.h,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 struct list_head {
@@ -65,8 +64,12 @@ list_del(struct list_head *entry) {
 #define list_for_each(entry, head)                             \
     for (entry = (head)->next; entry != head; entry = (entry)->next)
 
+#define list_for_each_prev(entry, head) \
+        for (entry = (head)->prev; entry != (head); \
+                entry = entry->prev)
+
 #define list_for_each_safe(entry, temp, head)                  \
     for (entry = (head)->next, temp = (entry)->next;           \
-       temp != head;                                           \
-       entry = temp, temp = temp->next)
+       entry != head;                                          \
+       entry = temp, temp = entry->next)
 
index dfd3d1b..32c8419 100644 (file)
@@ -26,7 +26,6 @@
  *    Rickard E. (Rik) Faith <faith@valinux.com>
  *    Gareth Hughes <gareth@valinux.com>
  *
- * $DragonFly: src/sys/dev/drm/drm_lock.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_lock.c
  * contending client may be woken up.
  */
 
-#include "drmP.h"
+#include "dev/drm/drmP.h"
 
-int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context)
+int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       unsigned int old, new;
-
-       do {
-               old = *lock;
-               if (old & _DRM_LOCK_HELD) new = old | _DRM_LOCK_CONT;
-               else                      new = context | _DRM_LOCK_HELD;
-       } while (!atomic_cmpset_int(lock, old, new));
-
-       if (_DRM_LOCKING_CONTEXT(old) == context) {
-               if (old & _DRM_LOCK_HELD) {
-                       if (context != DRM_KERNEL_CONTEXT) {
-                               DRM_ERROR("%d holds heavyweight lock\n",
-                                         context);
-                       }
-                       return 0;
-               }
-       }
-       if (new == (context | _DRM_LOCK_HELD)) {
-                               /* Have lock */
-               return 1;
-       }
-       return 0;
-}
-
-/* This takes a lock forcibly and hands it to context. Should ONLY be used
-   inside *_unlock to give lock to kernel before calling *_dma_schedule. */
-int drm_lock_transfer(drm_device_t *dev,
-                      __volatile__ unsigned int *lock, unsigned int context)
-{
-       unsigned int old, new;
-
-       dev->lock.file_priv = NULL;
-       do {
-               old  = *lock;
-               new  = context | _DRM_LOCK_HELD;
-       } while (!atomic_cmpset_int(lock, old, new));
-
-       return 1;
-}
-
-int drm_lock_free(drm_device_t *dev,
-                  __volatile__ unsigned int *lock, unsigned int context)
-{
-       unsigned int old, new;
-
-       dev->lock.file_priv = NULL;
-       do {
-               old  = *lock;
-               new  = 0;
-       } while (!atomic_cmpset_int(lock, old, new));
-
-       if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
-               DRM_ERROR("%d freed heavyweight lock held by %d\n",
-                         context, _DRM_LOCKING_CONTEXT(old));
-               return 1;
-       }
-       DRM_WAKEUP_INT((void *)&dev->lock.lock_queue);
-       return 0;
-}
+       struct drm_lock *lock = data;
+       int ret = 0;
 
-int drm_lock(drm_device_t *dev, void *data, struct drm_file *file_priv)
-{
-        drm_lock_t *lock = data;
-        int ret = 0;
-
-        if (lock->context == DRM_KERNEL_CONTEXT) {
-                DRM_ERROR("Process %d using kernel context %d\n",
+       if (lock->context == DRM_KERNEL_CONTEXT) {
+               DRM_ERROR("Process %d using kernel context %d\n",
                    DRM_CURRENTPID, lock->context);
-                return EINVAL;
-        }
+               return EINVAL;
+       }
 
-        DRM_DEBUG("%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
+       DRM_DEBUG("%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
            lock->context, DRM_CURRENTPID, dev->lock.hw_lock->lock,
            lock->flags);
 
-        if (dev->driver.use_dma_queue && lock->context < 0)
-                return EINVAL;
+       if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) &&
+           lock->context < 0)
+               return EINVAL;
 
        DRM_LOCK();
        for (;;) {
-               if (drm_lock_take(&dev->lock.hw_lock->lock, lock->context)) {
+               if (drm_lock_take(&dev->lock, lock->context)) {
                        dev->lock.file_priv = file_priv;
                        dev->lock.lock_time = jiffies;
                        atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
@@ -140,10 +78,6 @@ int drm_lock(drm_device_t *dev, void *data, struct drm_file *file_priv)
                }
 
                /* Contention */
-#if defined(__FreeBSD__) && __FreeBSD_version > 500000
-               ret = mtx_sleep((void *)&dev->lock.lock_queue, &dev->dev_lock,
-                   PZERO | PCATCH, "drmlk2", 0);
-#elif defined(__DragonFly__)
                crit_enter();
                tsleep_interlock((void *)&dev->lock.lock_queue);
                DRM_UNLOCK();
@@ -151,53 +85,117 @@ int drm_lock(drm_device_t *dev, void *data, struct drm_file *file_priv)
                    "drmlk2", 0);
                crit_exit();
                DRM_LOCK();
-#else
-               ret = tsleep((void *)&dev->lock.lock_queue, PZERO | PCATCH,
-                   "drmlk2", 0);
-#endif
                if (ret != 0)
                        break;
        }
        DRM_UNLOCK();
-       DRM_DEBUG("%d %s\n", lock->context, ret ? "interrupted" : "has lock");
+
+       if (ret == ERESTART)
+               DRM_DEBUG("restarting syscall\n");
+       else
+               DRM_DEBUG("%d %s\n", lock->context,
+                   ret ? "interrupted" : "has lock");
 
        if (ret != 0)
                return ret;
 
        /* XXX: Add signal blocking here */
 
-       if (dev->driver.dma_quiescent != NULL &&
+       if (dev->driver->dma_quiescent != NULL &&
            (lock->flags & _DRM_LOCK_QUIESCENT))
-               dev->driver.dma_quiescent(dev);
+               dev->driver->dma_quiescent(dev);
 
        return 0;
 }
 
-int drm_unlock(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_lock_t *lock = data;
+       struct drm_lock *lock = data;
+
+       DRM_DEBUG("%d (pid %d) requests unlock (0x%08x), flags = 0x%08x\n",
+           lock->context, DRM_CURRENTPID, dev->lock.hw_lock->lock,
+           lock->flags);
 
        if (lock->context == DRM_KERNEL_CONTEXT) {
                DRM_ERROR("Process %d using kernel context %d\n",
                    DRM_CURRENTPID, lock->context);
                return EINVAL;
        }
-       /* Check that the context unlock being requested actually matches
-        * who currently holds the lock.
-        */
-       if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) ||
-           _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock) != lock->context)
-               return EINVAL;
 
        atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
 
        DRM_LOCK();
-       drm_lock_transfer(dev, &dev->lock.hw_lock->lock, DRM_KERNEL_CONTEXT);
+       drm_lock_transfer(&dev->lock, DRM_KERNEL_CONTEXT);
 
-       if (drm_lock_free(dev, &dev->lock.hw_lock->lock, DRM_KERNEL_CONTEXT)) {
+       if (drm_lock_free(&dev->lock, DRM_KERNEL_CONTEXT)) {
                DRM_ERROR("\n");
        }
        DRM_UNLOCK();
 
        return 0;
 }
+
+int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context)
+{
+       volatile unsigned int *lock = &lock_data->hw_lock->lock;
+       unsigned int old, new;
+
+       do {
+               old = *lock;
+               if (old & _DRM_LOCK_HELD)
+                       new = old | _DRM_LOCK_CONT;
+               else
+                       new = context | _DRM_LOCK_HELD;
+       } while (!atomic_cmpset_int(lock, old, new));
+
+       if (_DRM_LOCKING_CONTEXT(old) == context) {
+               if (old & _DRM_LOCK_HELD) {
+                       if (context != DRM_KERNEL_CONTEXT) {
+                               DRM_ERROR("%d holds heavyweight lock\n",
+                                   context);
+                       }
+                       return 0;
+               }
+       }
+       if (new == (context | _DRM_LOCK_HELD)) {
+               /* Have lock */
+               return 1;
+       }
+       return 0;
+}
+
+/* This takes a lock forcibly and hands it to context. Should ONLY be used
+   inside *_unlock to give lock to kernel before calling *_dma_schedule. */
+int drm_lock_transfer(struct drm_lock_data *lock_data, unsigned int context)
+{
+       volatile unsigned int *lock = &lock_data->hw_lock->lock;
+       unsigned int old, new;
+
+       lock_data->file_priv = NULL;
+       do {
+               old = *lock;
+               new = context | _DRM_LOCK_HELD;
+       } while (!atomic_cmpset_int(lock, old, new));
+
+       return 1;
+}
+
+int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context)
+{
+       volatile unsigned int *lock = &lock_data->hw_lock->lock;
+       unsigned int old, new;
+
+       lock_data->file_priv = NULL;
+       do {
+               old = *lock;
+               new = 0;
+       } while (!atomic_cmpset_int(lock, old, new));
+
+       if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
+               DRM_ERROR("%d freed heavyweight lock held by %d\n",
+                   context, _DRM_LOCKING_CONTEXT(old));
+               return 1;
+       }
+       DRM_WAKEUP_INT((void *)&lock_data->lock_queue);
+       return 0;
+}
index d4c7adc..85c0545 100644 (file)
@@ -26,7 +26,6 @@
  *    Rickard E. (Rik) Faith <faith@valinux.com>
  *    Gareth Hughes <gareth@valinux.com>
  *
- * $DragonFly: src/sys/dev/drm/drm_memory.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_memory.c
  * has been stripped out for now.
  */
 
-#include "drmP.h"
-
-MALLOC_DEFINE(M_DRM, "drm", "DRM Data Structures");
+#include "dev/drm/drmP.h"
+
+MALLOC_DEFINE(DRM_MEM_DMA, "drm_dma", "DRM DMA Data Structures");
+MALLOC_DEFINE(DRM_MEM_SAREA, "drm_sarea", "DRM SAREA Data Structures");
+MALLOC_DEFINE(DRM_MEM_DRIVER, "drm_driver", "DRM DRIVER Data Structures");
+MALLOC_DEFINE(DRM_MEM_MAGIC, "drm_magic", "DRM MAGIC Data Structures");
+MALLOC_DEFINE(DRM_MEM_IOCTLS, "drm_ioctls", "DRM IOCTL Data Structures");
+MALLOC_DEFINE(DRM_MEM_MAPS, "drm_maps", "DRM MAP Data Structures");
+MALLOC_DEFINE(DRM_MEM_BUFS, "drm_bufs", "DRM BUFFER Data Structures");
+MALLOC_DEFINE(DRM_MEM_SEGS, "drm_segs", "DRM SEGMENTS Data Structures");
+MALLOC_DEFINE(DRM_MEM_PAGES, "drm_pages", "DRM PAGES Data Structures");
+MALLOC_DEFINE(DRM_MEM_FILES, "drm_files", "DRM FILE Data Structures");
+MALLOC_DEFINE(DRM_MEM_QUEUES, "drm_queues", "DRM QUEUE Data Structures");
+MALLOC_DEFINE(DRM_MEM_CMDS, "drm_cmds", "DRM COMMAND Data Structures");
+MALLOC_DEFINE(DRM_MEM_MAPPINGS, "drm_mapping", "DRM MAPPING Data Structures");
+MALLOC_DEFINE(DRM_MEM_BUFLISTS, "drm_buflists", "DRM BUFLISTS Data Structures");
+MALLOC_DEFINE(DRM_MEM_AGPLISTS, "drm_agplists", "DRM AGPLISTS Data Structures");
+MALLOC_DEFINE(DRM_MEM_CTXBITMAP, "drm_ctxbitmap",
+    "DRM CTXBITMAP Data Structures");
+MALLOC_DEFINE(DRM_MEM_SGLISTS, "drm_sglists", "DRM SGLISTS Data Structures");
+MALLOC_DEFINE(DRM_MEM_DRAWABLE, "drm_drawable", "DRM DRAWABLE Data Structures");
 
 void drm_mem_init(void)
 {
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-       malloc_type_attach(M_DRM);
-#endif
 }
 
 void drm_mem_uninit(void)
 {
 }
 
-void *drm_alloc(size_t size, int area)
-{
-       return malloc(size, M_DRM, M_NOWAIT);
-}
-
-void *drm_calloc(size_t nmemb, size_t size, int area)
-{
-       return malloc(size * nmemb, M_DRM, M_NOWAIT | M_ZERO);
-}
-
-void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area)
+void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map)
 {
-       void *pt;
-
-       pt = malloc(size, M_DRM, M_NOWAIT);
-       if (pt == NULL)
-               return NULL;
-       if (oldpt && oldsize) {
-               memcpy(pt, oldpt, oldsize);
-               free(oldpt, M_DRM);
-       }
-       return pt;
-}
-
-void drm_free(void *pt, size_t size, int area)
-{
-       free(pt, M_DRM);
+#if 0 /* XXX */
+       return pmap_mapdev_attr(map->offset, map->size, PAT_WRITE_COMBINING);
+#endif
+       return pmap_mapdev(map->offset, map->size);
 }
 
-void *drm_ioremap(drm_device_t *dev, drm_local_map_t *map)
+void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map)
 {
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        return pmap_mapdev(map->offset, map->size);
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-       map->bst = dev->pa.pa_memt;
-       if (bus_space_map(map->bst, map->offset, map->size, 
-           BUS_SPACE_MAP_LINEAR, &map->bsh))
-               return NULL;
-       return bus_space_vaddr(map->bst, map->bsh);
-#endif
 }
 
 void drm_ioremapfree(drm_local_map_t *map)
 {
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        pmap_unmapdev((vm_offset_t) map->handle, map->size);
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-       bus_space_unmap(map->bst, map->bsh, map->size);
-#endif
 }
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
 int
 drm_mtrr_add(unsigned long offset, size_t size, int flags)
 {
@@ -131,30 +111,3 @@ drm_mtrr_del(int __unused handle, unsigned long offset, size_t size, int flags)
        strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner));
        return mem_range_attr_set(&mrdesc, &act);
 }
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-int
-drm_mtrr_add(unsigned long offset, size_t size, int flags)
-{
-       struct mtrr mtrrmap;
-       int one = 1;
-
-       mtrrmap.base = offset;
-       mtrrmap.len = size;
-       mtrrmap.type = flags;
-       mtrrmap.flags = MTRR_VALID;
-       return mtrr_set(&mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
-}
-
-int
-drm_mtrr_del(unsigned long offset, size_t size, int flags)
-{
-       struct mtrr mtrrmap;
-       int one = 1;
-
-       mtrrmap.base = offset;
-       mtrrmap.len = size;
-       mtrrmap.type = flags;
-       mtrrmap.flags = 0;
-       return mtrr_set(&mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
-}
-#endif
index 35facad..ce7ed36 100644 (file)
@@ -19,8 +19,6 @@
  * AUTHOR 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.
- *
- * $DragonFly: src/sys/dev/drm/drm_pci.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /**
  * \author Eric Anholt <anholt@FreeBSD.org>
  */
 
-#include "drmP.h"
+#include "dev/drm/drmP.h"
 
 /**********************************************************************/
 /** \name PCI memory */
 /*@{*/
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
 static void
 drm_pci_busdma_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
 {
@@ -48,14 +45,14 @@ drm_pci_busdma_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error
        KASSERT(nsegs == 1, ("drm_pci_busdma_callback: bad dma segment count"));
        dmah->busaddr = segs[0].ds_addr;
 }
-#endif
 
 /**
  * \brief Allocate a physically contiguous DMA-accessible consistent 
  * memory block.
  */
 drm_dma_handle_t *
-drm_pci_alloc(drm_device_t *dev, size_t size, size_t align, dma_addr_t maxaddr)
+drm_pci_alloc(struct drm_device *dev, size_t size,
+             size_t align, dma_addr_t maxaddr)
 {
        drm_dma_handle_t *dmah;
        int ret;
@@ -67,60 +64,48 @@ drm_pci_alloc(drm_device_t *dev, size_t size, size_t align, dma_addr_t maxaddr)
                return NULL;
        }
 
-       dmah = malloc(sizeof(drm_dma_handle_t), M_DRM, M_ZERO | M_NOWAIT);
+       dmah = malloc(sizeof(drm_dma_handle_t), DRM_MEM_DMA, M_ZERO | M_NOWAIT);
        if (dmah == NULL)
                return NULL;
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+#if 0 /* HT XXX XXX XXX */
+       /* Make sure we aren't holding locks here */
+       mtx_assert(&dev->dev_lock, MA_NOTOWNED);
+       if (mtx_owned(&dev->dev_lock))
+           DRM_ERROR("called while holding dev_lock\n");
+       mtx_assert(&dev->dma_lock, MA_NOTOWNED);
+       if (mtx_owned(&dev->dma_lock))
+           DRM_ERROR("called while holding dma_lock\n");
+#endif
+
        ret = bus_dma_tag_create(NULL, align, 0, /* tag, align, boundary */
            maxaddr, BUS_SPACE_MAXADDR, /* lowaddr, highaddr */
            NULL, NULL, /* filtfunc, filtfuncargs */
            size, 1, size, /* maxsize, nsegs, maxsegsize */
-           BUS_DMA_ALLOCNOW, /* flags */
-#ifdef __FreeBSD__
-           NULL, NULL, /* lockfunc, lockfuncargs */
-#endif
+           0, /* flags */
            &dmah->tag);
        if (ret != 0) {
-               free(dmah, M_DRM);
+               free(dmah, DRM_MEM_DMA);
                return NULL;
        }
 
-       ret = bus_dmamem_alloc(dmah->tag, &dmah->vaddr, BUS_DMA_NOWAIT,
-           &dmah->map);
+       ret = bus_dmamem_alloc(dmah->tag, &dmah->vaddr,
+           BUS_DMA_WAITOK | BUS_DMA_ZERO, &dmah->map);
        if (ret != 0) {
                bus_dma_tag_destroy(dmah->tag);
-               free(dmah, M_DRM);
+               free(dmah, DRM_MEM_DMA);
                return NULL;
        }
 
        ret = bus_dmamap_load(dmah->tag, dmah->map, dmah->vaddr, size,
-           drm_pci_busdma_callback, dmah, 0);
+           drm_pci_busdma_callback, dmah, BUS_DMA_NOWAIT);
        if (ret != 0) {
                bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map);
                bus_dma_tag_destroy(dmah->tag);
-               free(dmah, M_DRM);
-               return NULL;
-       }
-#elif defined(__NetBSD__)
-       ret = bus_dmamem_alloc(dev->dma_tag, size, align, PAGE_SIZE,
-           &dmah->seg, 1, &nsegs, BUS_DMA_NOWAIT);
-       if ((ret != 0) || (nsegs != 1)) {
-               free(dmah, M_DRM);
+               free(dmah, DRM_MEM_DMA);
                return NULL;
        }
 
-       ret = bus_dmamem_map(dev->dma_tag, &dmah->seg, 1, size, &dmah->addr,
-           BUS_DMA_NOWAIT);
-       if (ret != 0) {
-               bus_dmamem_free(dev->dma_tag, &dmah->seg, 1);
-               free(dmah, M_DRM);
-               return NULL;
-       }
-
-       dmah->dmaaddr = h->seg.ds_addr;
-#endif
-
        return dmah;
 }
 
@@ -128,19 +113,15 @@ drm_pci_alloc(drm_device_t *dev, size_t size, size_t align, dma_addr_t maxaddr)
  * \brief Free a DMA-accessible consistent memory block.
  */
 void
-drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah)
+drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah)
 {
        if (dmah == NULL)
                return;
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
        bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map);
        bus_dma_tag_destroy(dmah->tag);
-#elif defined(__NetBSD__)
-       bus_dmamem_free(dev->dma_tag, &dmah->seg, 1);
-#endif
 
-       free(dmah, M_DRM);
+       free(dmah, DRM_MEM_DMA);
 }
 
 /*@}*/
index 7daf212..32ae901 100644 (file)
@@ -1,4 +1,6 @@
-/* $DragonFly: src/sys/dev/drm/drm_pciids.h,v 1.1 2008/04/05 18:12:29 hasso Exp $ */
+/*
+ * $FreeBSD$
+ */
 /*
    This file is auto-generated from the drm_pciids.txt in the DRM CVS
    Please contact dri-devel@lists.sf.net to add new cards to this list
        {0x1002, 0x5460, CHIP_RV380|RADEON_IS_MOBILITY, "ATI Radeon Mobility X300 M22"}, \
        {0x1002, 0x5462, CHIP_RV380|RADEON_IS_MOBILITY, "ATI Radeon Mobility X600 SE M24C"}, \
        {0x1002, 0x5464, CHIP_RV380|RADEON_IS_MOBILITY, "ATI FireGL M22 GL 5464"}, \
-       {0x1002, 0x5548, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R423 X800"}, \
-       {0x1002, 0x5549, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R423 X800 Pro"}, \
-       {0x1002, 0x554A, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R423 X800 XT PE"}, \
-       {0x1002, 0x554B, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R423 X800 SE"}, \
-       {0x1002, 0x554C, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R430 X800 XTP"}, \
-       {0x1002, 0x554D, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R430 X800 XL"}, \
-       {0x1002, 0x554E, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R430 X800 SE"}, \
-       {0x1002, 0x554F, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R430 X800"}, \
-       {0x1002, 0x5550, CHIP_R420|RADEON_NEW_MEMMAP, "ATI FireGL V7100 R423"}, \
-       {0x1002, 0x5551, CHIP_R420|RADEON_NEW_MEMMAP, "ATI FireGL V5100 R423 UQ"}, \
-       {0x1002, 0x5552, CHIP_R420|RADEON_NEW_MEMMAP, "ATI FireGL unknown R423 UR"}, \
-       {0x1002, 0x5554, CHIP_R420|RADEON_NEW_MEMMAP, "ATI FireGL unknown R423 UT"}, \
+       {0x1002, 0x5548, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R423 X800"}, \
+       {0x1002, 0x5549, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R423 X800 Pro"}, \
+       {0x1002, 0x554A, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R423 X800 XT PE"}, \
+       {0x1002, 0x554B, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R423 X800 SE"}, \
+       {0x1002, 0x554C, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R430 X800 XTP"}, \
+       {0x1002, 0x554D, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R430 X800 XL"}, \
+       {0x1002, 0x554E, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R430 X800 SE"}, \
+       {0x1002, 0x554F, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R430 X800"}, \
+       {0x1002, 0x5550, CHIP_R423|RADEON_NEW_MEMMAP, "ATI FireGL V7100 R423"}, \
+       {0x1002, 0x5551, CHIP_R423|RADEON_NEW_MEMMAP, "ATI FireGL V5100 R423 UQ"}, \
+       {0x1002, 0x5552, CHIP_R423|RADEON_NEW_MEMMAP, "ATI FireGL unknown R423 UR"}, \
+       {0x1002, 0x5554, CHIP_R423|RADEON_NEW_MEMMAP, "ATI FireGL unknown R423 UT"}, \
        {0x1002, 0x564A, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility FireGL V5000 M26"}, \
        {0x1002, 0x564B, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility FireGL V5000 M26"}, \
        {0x1002, 0x564F, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Radeon Mobility X700 XL M26"}, \
        {0x1002, 0x5652, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Radeon Mobility X700 M26"}, \
        {0x1002, 0x5653, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Radeon Mobility X700 M26"}, \
+       {0x1002, 0x5657, CHIP_RV410|RADEON_NEW_MEMMAP, "ATI Radeon X550XTX"}, \
        {0x1002, 0x5834, CHIP_RS300|RADEON_IS_IGP, "ATI Radeon RS300 9100 IGP"}, \
        {0x1002, 0x5835, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY, "ATI Radeon RS300 Mobility IGP"}, \
-       {0x1002, 0x5954, CHIP_RS400|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART, "ATI RS480 XPRESS 200G"}, \
-       {0x1002, 0x5955, CHIP_RS400|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART, "ATI Radeon XPRESS 200M 5955"}, \
-       {0x1002, 0x5974, CHIP_RS400|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART, "ATI Radeon RS482 XPRESS 200"}, \
-       {0x1002, 0x5975, CHIP_RS400|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART, "ATI Radeon RS485 XPRESS 1100 IGP"}, \
+       {0x1002, 0x5954, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_IGPGART, "ATI RS480 XPRESS 200G"}, \
+       {0x1002, 0x5955, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART, "ATI Radeon XPRESS 200M 5955"}, \
+       {0x1002, 0x5974, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART, "ATI Radeon RS482 XPRESS 200"}, \
+       {0x1002, 0x5975, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART, "ATI Radeon RS485 XPRESS 1100 IGP"}, \
        {0x1002, 0x5960, CHIP_RV280, "ATI Radeon RV280 9250"}, \
        {0x1002, 0x5961, CHIP_RV280, "ATI Radeon RV280 9200"}, \
        {0x1002, 0x5962, CHIP_RV280, "ATI Radeon RV280 9200"}, \
        {0x1002, 0x5964, CHIP_RV280, "ATI Radeon RV280 9200 SE"}, \
        {0x1002, 0x5965, CHIP_RV280, "ATI FireMV 2200 PCI"}, \
        {0x1002, 0x5969, CHIP_RV100, "ATI ES1000 RN50"}, \
-       {0x1002, 0x5a41, CHIP_RS400|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART, "ATI Radeon RS400 XPRESS 200"}, \
-       {0x1002, 0x5a42, CHIP_RS400|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART, "ATI Radeon RS400 XPRESS 200M"}, \
-       {0x1002, 0x5a61, CHIP_RS400|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART, "ATI Radeon RC410 XPRESS 200"}, \
+       {0x1002, 0x5a41, CHIP_RS400|RADEON_IS_IGP|RADEON_IS_IGPGART, "ATI Radeon XPRESS 200 5A41 (PCIE)"}, \
+       {0x1002, 0x5a42, CHIP_RS400|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART, "ATI Radeon XPRESS 200M 5A42 (PCIE)"}, \
+       {0x1002, 0x5a61, CHIP_RS400|RADEON_IS_IGP|RADEON_IS_IGPGART, "ATI Radeon RC410 XPRESS 200"}, \
        {0x1002, 0x5a62, CHIP_RS400|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART, "ATI Radeon RC410 XPRESS 200M"}, \
        {0x1002, 0x5b60, CHIP_RV380|RADEON_NEW_MEMMAP, "ATI Radeon RV370 X300 SE"}, \
        {0x1002, 0x5b62, CHIP_RV380|RADEON_NEW_MEMMAP, "ATI Radeon RV370 X600 Pro"}, \
        {0x1002, 0x5b65, CHIP_RV380|RADEON_NEW_MEMMAP, "ATI FireMV 2200 PCIE (RV370) 5B65"}, \
        {0x1002, 0x5c61, CHIP_RV280|RADEON_IS_MOBILITY, "ATI Radeon RV280 Mobility"}, \
        {0x1002, 0x5c63, CHIP_RV280|RADEON_IS_MOBILITY, "ATI Radeon RV280 Mobility"}, \
-       {0x1002, 0x5d48, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon X800 XT M28"}, \
-       {0x1002, 0x5d49, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility FireGL V5100 M28"}, \
-       {0x1002, 0x5d4a, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon X800 M28"}, \
-       {0x1002, 0x5d4c, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R480 X850"}, \
-       {0x1002, 0x5d4d, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R480 X850 XT PE"}, \
-       {0x1002, 0x5d4e, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R480 X850 SE"}, \
-       {0x1002, 0x5d4f, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R480 X850 Pro"}, \
-       {0x1002, 0x5d50, CHIP_R420|RADEON_NEW_MEMMAP, "ATI unknown Radeon / FireGL R480"}, \
-       {0x1002, 0x5d52, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R480 X850 XT"}, \
-       {0x1002, 0x5d57, CHIP_R420|RADEON_NEW_MEMMAP, "ATI Radeon R423 X800 XT"}, \
+       {0x1002, 0x5d48, CHIP_R423|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon X800 XT M28"}, \
+       {0x1002, 0x5d49, CHIP_R423|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility FireGL V5100 M28"}, \
+       {0x1002, 0x5d4a, CHIP_R423|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon X800 M28"}, \
+       {0x1002, 0x5d4c, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R480 X850"}, \
+       {0x1002, 0x5d4d, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R480 X850 XT PE"}, \
+       {0x1002, 0x5d4e, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R480 X850 SE"}, \
+       {0x1002, 0x5d4f, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R480 X850 Pro"}, \
+       {0x1002, 0x5d50, CHIP_R423|RADEON_NEW_MEMMAP, "ATI unknown Radeon / FireGL R480"}, \
+       {0x1002, 0x5d52, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R480 X850 XT"}, \
+       {0x1002, 0x5d57, CHIP_R423|RADEON_NEW_MEMMAP, "ATI Radeon R423 X800 XT"}, \
        {0x1002, 0x5e48, CHIP_RV410|RADEON_NEW_MEMMAP, "ATI FireGL V5000 RV410"}, \
        {0x1002, 0x5e4a, CHIP_RV410|RADEON_NEW_MEMMAP, "ATI Radeon RV410 X700 XT"}, \
        {0x1002, 0x5e4b, CHIP_RV410|RADEON_NEW_MEMMAP, "ATI Radeon RV410 X700 Pro"}, \
        {0x1002, 0x71D6, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon X1700 XT"}, \
        {0x1002, 0x71DA, CHIP_RV530|RADEON_NEW_MEMMAP, "ATI FireGL V5200"}, \
        {0x1002, 0x71DE, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon X1700"}, \
-       {0x1002, 0x7200, CHIP_RV530|RADEON_NEW_MEMMAP, "ATI  Radeon X2300HD"}, \
-       {0x1002, 0x7210, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 2300"}, \
-       {0x1002, 0x7211, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 2300"}, \
+       {0x1002, 0x7200, CHIP_RV515|RADEON_NEW_MEMMAP, "ATI  Radeon X2300HD"}, \
+       {0x1002, 0x7210, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 2300"}, \
+       {0x1002, 0x7211, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 2300"}, \
        {0x1002, 0x7240, CHIP_R580|RADEON_NEW_MEMMAP, "ATI Radeon X1950"}, \
        {0x1002, 0x7243, CHIP_R580|RADEON_NEW_MEMMAP, "ATI Radeon X1900"}, \
        {0x1002, 0x7244, CHIP_R580|RADEON_NEW_MEMMAP, "ATI Radeon X1950"}, \
        {0x1002, 0x7297, CHIP_RV560|RADEON_NEW_MEMMAP, "ATI RV560"}, \
        {0x1002, 0x7834, CHIP_RS300|RADEON_IS_IGP|RADEON_NEW_MEMMAP, "ATI Radeon RS350 9000/9100 IGP"}, \
        {0x1002, 0x7835, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Radeon RS350 Mobility IGP"}, \
+       {0x1002, 0x793f, CHIP_RS600|RADEON_IS_IGP|RADEON_NEW_MEMMAP, "ATI Radeon X1200"}, \
+       {0x1002, 0x7941, CHIP_RS600|RADEON_IS_IGP|RADEON_NEW_MEMMAP, "ATI Radeon X1200"}, \
+       {0x1002, 0x7942, CHIP_RS600|RADEON_IS_IGP|RADEON_NEW_MEMMAP, "ATI Radeon X1200"}, \
+       {0x1002, 0x791e, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART, "ATI Radeon RS690 X1250 IGP"}, \
+       {0x1002, 0x791f, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART, "ATI Radeon RS690 X1270 IGP"}, \
+       {0x1002, 0x796c, CHIP_RS740|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART, "ATI Radeon RS740 HD2100 IGP"}, \
+       {0x1002, 0x796d, CHIP_RS740|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART, "ATI Radeon RS740 HD2100 IGP"}, \
+       {0x1002, 0x796e, CHIP_RS740|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART, "ATI Radeon RS740 HD2100 IGP"}, \
+       {0x1002, 0x796f, CHIP_RS740|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART, "ATI Radeon RS740 HD2100 IGP"}, \
+       {0x1002, 0x9400, CHIP_R600|RADEON_NEW_MEMMAP, "ATI Radeon HD 2900 XT"}, \
+       {0x1002, 0x9401, CHIP_R600|RADEON_NEW_MEMMAP, "ATI Radeon HD 2900 XT"}, \
+       {0x1002, 0x9402, CHIP_R600|RADEON_NEW_MEMMAP, "ATI Radeon HD 2900 XT"}, \
+       {0x1002, 0x9403, CHIP_R600|RADEON_NEW_MEMMAP, "ATI Radeon HD 2900 Pro"}, \
+       {0x1002, 0x9405, CHIP_R600|RADEON_NEW_MEMMAP, "ATI Radeon HD 2900 GT"}, \
+       {0x1002, 0x940A, CHIP_R600|RADEON_NEW_MEMMAP, "ATI FireGL V8650"}, \
+       {0x1002, 0x940B, CHIP_R600|RADEON_NEW_MEMMAP, "ATI FireGL V8600"}, \
+       {0x1002, 0x940F, CHIP_R600|RADEON_NEW_MEMMAP, "ATI FireGL V7600"}, \
+       {0x1002, 0x94C0, CHIP_RV610|RADEON_NEW_MEMMAP, "RV610"}, \
+       {0x1002, 0x94C1, CHIP_RV610|RADEON_NEW_MEMMAP, "Radeon HD 2400 XT"}, \
+       {0x1002, 0x94C3, CHIP_RV610|RADEON_NEW_MEMMAP, "Radeon HD 2400 Pro"}, \
+       {0x1002, 0x94C4, CHIP_RV610|RADEON_NEW_MEMMAP, "Radeon HD 2400 PRO AGP"}, \
+       {0x1002, 0x94C5, CHIP_RV610|RADEON_NEW_MEMMAP, "FireGL V4000"}, \
+       {0x1002, 0x94C6, CHIP_RV610|RADEON_NEW_MEMMAP, "RV610"}, \
+       {0x1002, 0x94C7, CHIP_RV610|RADEON_NEW_MEMMAP, "ATI Radeon HD 2350"}, \
+       {0x1002, 0x94C8, CHIP_RV610|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 2400 XT"}, \
+       {0x1002, 0x94C9, CHIP_RV610|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 2400"}, \
+       {0x1002, 0x94CB, CHIP_RV610|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI RADEON E2400"}, \
+       {0x1002, 0x94CC, CHIP_RV610|RADEON_NEW_MEMMAP, "ATI RV610"}, \
+       {0x1002, 0x94CD, CHIP_RV610|RADEON_NEW_MEMMAP, "ATI FireMV 2260"}, \
+       {0x1002, 0x9500, CHIP_RV670|RADEON_NEW_MEMMAP, "ATI RV670"}, \
+       {0x1002, 0x9501, CHIP_RV670|RADEON_NEW_MEMMAP, "ATI Radeon HD3870"}, \
+       {0x1002, 0x9504, CHIP_RV670|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 3850"}, \
+       {0x1002, 0x9505, CHIP_RV670|RADEON_NEW_MEMMAP, "ATI Radeon HD3850"}, \
+       {0x1002, 0x9506, CHIP_RV670|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 3850 X2"}, \
+       {0x1002, 0x9507, CHIP_RV670|RADEON_NEW_MEMMAP, "ATI RV670"}, \
+       {0x1002, 0x9508, CHIP_RV670|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 3870"}, \
+       {0x1002, 0x9509, CHIP_RV670|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 3870 X2"}, \
+       {0x1002, 0x950F, CHIP_RV670|RADEON_NEW_MEMMAP, "ATI Radeon HD3870 X2"}, \
+       {0x1002, 0x9511, CHIP_RV670|RADEON_NEW_MEMMAP, "ATI FireGL V7700"}, \
+       {0x1002, 0x9515, CHIP_RV670|RADEON_NEW_MEMMAP, "ATI Radeon HD3850"}, \
+       {0x1002, 0x9517, CHIP_RV670|RADEON_NEW_MEMMAP, "ATI Radeon HD3690"}, \
+       {0x1002, 0x9519, CHIP_RV670|RADEON_NEW_MEMMAP, "AMD Firestream 9170"}, \
+       {0x1002, 0x9580, CHIP_RV630|RADEON_NEW_MEMMAP, "ATI RV630"}, \
+       {0x1002, 0x9581, CHIP_RV630|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 2600"}, \
+       {0x1002, 0x9583, CHIP_RV630|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 2600 XT"}, \
+       {0x1002, 0x9586, CHIP_RV630|RADEON_NEW_MEMMAP, "ATI Radeon HD 2600 XT AGP"}, \
+       {0x1002, 0x9587, CHIP_RV630|RADEON_NEW_MEMMAP, "ATI Radeon HD 2600 Pro AGP"}, \
+       {0x1002, 0x9588, CHIP_RV630|RADEON_NEW_MEMMAP, "ATI Radeon HD 2600 XT"}, \
+       {0x1002, 0x9589, CHIP_RV630|RADEON_NEW_MEMMAP, "ATI Radeon HD 2600 Pro"}, \
+       {0x1002, 0x958A, CHIP_RV630|RADEON_NEW_MEMMAP, "ATI Gemini RV630"}, \
+       {0x1002, 0x958B, CHIP_RV630|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Gemini Mobility Radeon HD 2600 XT"}, \
+       {0x1002, 0x958C, CHIP_RV630|RADEON_NEW_MEMMAP, "ATI FireGL V5600"}, \
+       {0x1002, 0x958D, CHIP_RV630|RADEON_NEW_MEMMAP, "ATI FireGL V3600"}, \
+       {0x1002, 0x958E, CHIP_RV630|RADEON_NEW_MEMMAP, "ATI Radeon HD 2600 LE"}, \
+       {0x1002, 0x958F, CHIP_RV630|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility FireGL Graphics Processor"}, \
+       {0x1002, 0x95C0, CHIP_RV620|RADEON_NEW_MEMMAP, "ATI Radeon HD 3470"}, \
+       {0x1002, 0x95C5, CHIP_RV620|RADEON_NEW_MEMMAP, "ATI Radeon HD 3450"}, \
+       {0x1002, 0x95C6, CHIP_RV620|RADEON_NEW_MEMMAP, "ATI Radeon HD 3450"}, \
+       {0x1002, 0x95C7, CHIP_RV620|RADEON_NEW_MEMMAP, "ATI Radeon HD 3430"}, \
+       {0x1002, 0x95C9, CHIP_RV620|RADEON_NEW_MEMMAP, "ATI Radeon HD 3450"}, \
+       {0x1002, 0x95C2, CHIP_RV620|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 3430"}, \
+       {0x1002, 0x95C4, CHIP_RV620|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 3400 Series"}, \
+       {0x1002, 0x95CC, CHIP_RV620|RADEON_NEW_MEMMAP, "ATI FirePro V3700"}, \
+       {0x1002, 0x95CD, CHIP_RV620|RADEON_NEW_MEMMAP, "ATI FireMV 2450"}, \
+       {0x1002, 0x95CE, CHIP_RV620|RADEON_NEW_MEMMAP, "ATI FireMV 2260"}, \
+       {0x1002, 0x95CF, CHIP_RV620|RADEON_NEW_MEMMAP, "ATI FireMV 2260"}, \
+       {0x1002, 0x9590, CHIP_RV635|RADEON_NEW_MEMMAP, "ATI ATI Radeon HD 3600 Series"}, \
+       {0x1002, 0x9596, CHIP_RV635|RADEON_NEW_MEMMAP, "ATI ATI Radeon HD 3650 AGP"}, \
+       {0x1002, 0x9597, CHIP_RV635|RADEON_NEW_MEMMAP, "ATI ATI Radeon HD 3600 PRO"}, \
+       {0x1002, 0x9598, CHIP_RV635|RADEON_NEW_MEMMAP, "ATI ATI Radeon HD 3600 XT"}, \
+       {0x1002, 0x9599, CHIP_RV635|RADEON_NEW_MEMMAP, "ATI ATI Radeon HD 3600 PRO"}, \
+       {0x1002, 0x9591, CHIP_RV635|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 3650"}, \
+       {0x1002, 0x9593, CHIP_RV635|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 3670"}, \
+       {0x1002, 0x9595, CHIP_RV635|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility FireGL V5700"}, \
+       {0x1002, 0x959B, CHIP_RV635|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility FireGL V5725"}, \
+       {0x1002, 0x9610, CHIP_RS780|RADEON_NEW_MEMMAP|RADEON_IS_IGP, "ATI Radeon HD 3200 Graphics"}, \
+       {0x1002, 0x9611, CHIP_RS780|RADEON_NEW_MEMMAP|RADEON_IS_IGP, "ATI Radeon 3100 Graphics"}, \
+       {0x1002, 0x9612, CHIP_RS780|RADEON_NEW_MEMMAP|RADEON_IS_IGP, "ATI Radeon HD 3200 Graphics"}, \
+       {0x1002, 0x9613, CHIP_RS780|RADEON_NEW_MEMMAP|RADEON_IS_IGP, "ATI Radeon 3100 Graphics"}, \
+       {0x1002, 0x9614, CHIP_RS780|RADEON_NEW_MEMMAP|RADEON_IS_IGP, "ATI Radeon 3300 Graphics"}, \
+       {0x1002, 0x9615, CHIP_RS780|RADEON_NEW_MEMMAP|RADEON_IS_IGP, "ATI Radeon 3200 Graphics"}, \
+       {0x1002, 0x9616, CHIP_RS780|RADEON_NEW_MEMMAP|RADEON_IS_IGP, "ATI Radeon 3000 Graphics"}, \
+       {0x1002, 0x9440, CHIP_RV770|RADEON_NEW_MEMMAP, "ATI Radeon 4800 Series"}, \
+       {0x1002, 0x9441, CHIP_RV770|RADEON_NEW_MEMMAP, "ATI Radeon 4870 X2"}, \
+       {0x1002, 0x9442, CHIP_RV770|RADEON_NEW_MEMMAP, "ATI Radeon 4800 Series"}, \
+       {0x1002, 0x944C, CHIP_RV770|RADEON_NEW_MEMMAP, "ATI Radeon 4800 Series"}, \
+       {0x1002, 0x9450, CHIP_RV770|RADEON_NEW_MEMMAP, "AMD FireStream 9270"}, \
+       {0x1002, 0x9452, CHIP_RV770|RADEON_NEW_MEMMAP, "AMD FireStream 9250"}, \
+       {0x1002, 0x9444, CHIP_RV770|RADEON_NEW_MEMMAP, "ATI FirePro V8750 (FireGL)"}, \
+       {0x1002, 0x9446, CHIP_RV770|RADEON_NEW_MEMMAP, "ATI FirePro V7760 (FireGL)"}, \
+       {0x1002, 0x9456, CHIP_RV770|RADEON_NEW_MEMMAP, "ATI FirePro V8700 (FireGL)"}, \
+       {0x1002, 0x944E, CHIP_RV770|RADEON_NEW_MEMMAP, "ATI FirePro RV770"}, \
+       {0x1002, 0x944A, CHIP_RV770|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 4850"}, \
+       {0x1002, 0x944B, CHIP_RV770|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 4850 X2"}, \
+       {0x1002, 0x945A, CHIP_RV770|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 4870"}, \
+       {0x1002, 0x945B, CHIP_RV770|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon M98"}, \
+       {0x1002, 0x946A, CHIP_RV770|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI FirePro M7750"}, \
+       {0x1002, 0x946B, CHIP_RV770|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI M98"}, \
+       {0x1002, 0x947A, CHIP_RV770|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI M98"}, \
+       {0x1002, 0x947B, CHIP_RV770|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI M98"}, \
+       {0x1002, 0x9487, CHIP_RV730|RADEON_NEW_MEMMAP, "ATI Radeon RV730 (AGP)"}, \
+       {0x1002, 0x948F, CHIP_RV730|RADEON_NEW_MEMMAP, "ATI Radeon RV730 (AGP)"}, \
+       {0x1002, 0x9490, CHIP_RV730|RADEON_NEW_MEMMAP, "ATI Radeon HD 4670"}, \
+       {0x1002, 0x9498, CHIP_RV730|RADEON_NEW_MEMMAP, "ATI Radeon HD 4650"}, \
+       {0x1002, 0x9480, CHIP_RV730|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 4650"}, \
+       {0x1002, 0x9488, CHIP_RV730|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon HD 4670"}, \
+       {0x1002, 0x9489, CHIP_RV730|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI FirePro M5750"}, \
+       {0x1002, 0x9491, CHIP_RV730|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI RADEON E4600"}, \
+       {0x1002, 0x949C, CHIP_RV730|RADEON_NEW_MEMMAP, "ATI FirePro V7750 (FireGL)"}, \
+       {0x1002, 0x949E, CHIP_RV730|RADEON_NEW_MEMMAP, "ATI FirePro V5700 (FireGL)"}, \
+       {0x1002, 0x949F, CHIP_RV730|RADEON_NEW_MEMMAP, "ATI FirePro V3750 (FireGL)"}, \
+       {0x1002, 0x9540, CHIP_RV710|RADEON_NEW_MEMMAP, "ATI Radeon HD 4550"}, \
+       {0x1002, 0x9541, CHIP_RV710|RADEON_NEW_MEMMAP, "ATI Radeon RV710"}, \
+       {0x1002, 0x9542, CHIP_RV710|RADEON_NEW_MEMMAP, "ATI Radeon RV710"}, \
+       {0x1002, 0x954E, CHIP_RV710|RADEON_NEW_MEMMAP, "ATI Radeon RV710"}, \
+       {0x1002, 0x954F, CHIP_RV710|RADEON_NEW_MEMMAP, "ATI Radeon HD 4350"}, \
+       {0x1002, 0x9552, CHIP_RV710|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon 4300 Series"}, \
+       {0x1002, 0x9553, CHIP_RV710|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon 4500 Series"}, \
+       {0x1002, 0x9555, CHIP_RV710|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP, "ATI Mobility Radeon 4500 Series"}, \
        {0, 0, 0, NULL}
 
 #define r128_PCI_IDS \
        {0x8086, 0x3582, CHIP_I8XX, "Intel i852GM/i855GM GMCH"}, \
        {0x8086, 0x2572, CHIP_I8XX, "Intel i865G GMCH"}, \
        {0x8086, 0x2582, CHIP_I9XX|CHIP_I915, "Intel i915G"}, \
+       {0x8086, 0x258a, CHIP_I9XX|CHIP_I915, "Intel E7221 (i915)"}, \
        {0x8086, 0x2592, CHIP_I9XX|CHIP_I915, "Intel i915GM"}, \
        {0x8086, 0x2772, CHIP_I9XX|CHIP_I915, "Intel i945G"}, \
        {0x8086, 0x27A2, CHIP_I9XX|CHIP_I915, "Intel i945GM"}, \
        {0x8086, 0x29C2, CHIP_I9XX|CHIP_I915, "Intel G33"}, \
        {0x8086, 0x29B2, CHIP_I9XX|CHIP_I915, "Intel Q35"}, \
        {0x8086, 0x29D2, CHIP_I9XX|CHIP_I915, "Intel Q33"}, \
+       {0x8086, 0x2A42, CHIP_I9XX|CHIP_I965, "Mobile Intel® GM45 Express Chipset"}, \
+       {0x8086, 0x2E02, CHIP_I9XX|CHIP_I965, "Intel Integrated Graphics Device"}, \
+       {0x8086, 0x2E12, CHIP_I9XX|CHIP_I965, "Intel Q45/Q43"}, \
+       {0x8086, 0x2E22, CHIP_I9XX|CHIP_I965, "Intel G45/G43"}, \
        {0, 0, 0, NULL}
 
 #define imagine_PCI_IDS \
index 254c0bd..b2ffc05 100644 (file)
@@ -5,7 +5,7 @@
  * \author Michel D�zer <michel@daenzer.net>
  */
 
-/*
+/*-
  * Copyright 2002 Tungsten Graphics, Inc., Cedar Park, Texas.
  * All Rights Reserved.
  *
  * 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.
- *
- * $DragonFly: src/sys/dev/drm/drm_sarea.h,v 1.3 2008/04/05 18:12:29 hasso Exp $
  */
 
 #ifndef _DRM_SAREA_H_
 #define _DRM_SAREA_H_
 
-#include "drm.h"
+#include "dev/drm/drm.h"
 
 /* SAREA area needs to be at least a page */
 #if defined(__alpha__)
index bc46a6c..34a2bcc 100644 (file)
@@ -25,7 +25,6 @@
  *   Gareth Hughes <gareth@valinux.com>
  *   Eric Anholt <anholt@FreeBSD.org>
  *
- * $DragonFly: src/sys/dev/drm/drm_scatter.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_scatter.c
  * by drm_ati_pcigart_init().
  */
 
-#include "drmP.h"
+#include "dev/drm/drmP.h"
 
-#define DEBUG_SCATTER 0
+static void drm_sg_alloc_cb(void *arg, bus_dma_segment_t *segs,
+                           int nsegs, int error);
 
-void drm_sg_cleanup(drm_sg_mem_t *entry)
+int
+drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather *request)
 {
-       free((void *)entry->handle, M_DRM);
-       free(entry->busaddr, M_DRM);
-       free(entry, M_DRM);
-}
-
-int drm_sg_alloc(drm_device_t * dev, drm_scatter_gather_t * request)
-{
-       drm_sg_mem_t *entry;
+       struct drm_sg_mem *entry;
+       struct drm_dma_handle *dmah;
        unsigned long pages;
-       int i;
+       int ret;
 
-       if ( dev->sg )
+       if (dev->sg)
                return EINVAL;
 
-       entry = malloc(sizeof(*entry), M_DRM, M_WAITOK | M_ZERO);
-       if ( !entry )
+       entry = malloc(sizeof(*entry), DRM_MEM_SGLISTS, M_WAITOK | M_ZERO);
+       if (!entry)
                return ENOMEM;
 
        pages = round_page(request->size) / PAGE_SIZE;
-       DRM_DEBUG( "sg size=%ld pages=%ld\n", request->size, pages );
+       DRM_DEBUG("sg size=%ld pages=%ld\n", request->size, pages);
 
        entry->pages = pages;
 
-       entry->busaddr = malloc(pages * sizeof(*entry->busaddr), M_DRM,
+       entry->busaddr = malloc(pages * sizeof(*entry->busaddr), DRM_MEM_PAGES,
            M_WAITOK | M_ZERO);
-       if ( !entry->busaddr ) {
-               drm_sg_cleanup(entry);
+       if (!entry->busaddr) {
+               free(entry, DRM_MEM_SGLISTS);
                return ENOMEM;
        }
 
-       entry->handle = (long)malloc(pages << PAGE_SHIFT, M_DRM,
-           M_WAITOK | M_ZERO);
-       if (entry->handle == 0) {
-               drm_sg_cleanup(entry);
+       dmah = malloc(sizeof(struct drm_dma_handle), DRM_MEM_DMA,
+           M_ZERO | M_NOWAIT);
+       if (dmah == NULL) {
+               free(entry->busaddr, DRM_MEM_PAGES);
+               free(entry, DRM_MEM_SGLISTS);
+               return ENOMEM;
+       }
+
+       ret = bus_dma_tag_create(NULL, PAGE_SIZE, 0, /* tag, align, boundary */
+           BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, /* lowaddr, highaddr */
+           NULL, NULL, /* filtfunc, filtfuncargs */
+           request->size, pages, /* maxsize, nsegs */
+           PAGE_SIZE, 0, /* maxsegsize, flags */
+           &dmah->tag);
+       if (ret != 0) {
+               free(dmah, DRM_MEM_DMA);
+               free(entry->busaddr, DRM_MEM_PAGES);
+               free(entry, DRM_MEM_SGLISTS);
+               return ENOMEM;
+       }
+
+       /* XXX BUS_DMA_NOCACHE */
+       ret = bus_dmamem_alloc(dmah->tag, &dmah->vaddr,
+           BUS_DMA_WAITOK | BUS_DMA_ZERO , &dmah->map);
+       if (ret != 0) {
+               bus_dma_tag_destroy(dmah->tag);
+               free(dmah, DRM_MEM_DMA);
+               free(entry->busaddr, DRM_MEM_PAGES);
+               free(entry, DRM_MEM_SGLISTS);
                return ENOMEM;
        }
 
-       for (i = 0; i < pages; i++) {
-               entry->busaddr[i] = vtophys(entry->handle + i * PAGE_SIZE);
+       ret = bus_dmamap_load(dmah->tag, dmah->map, dmah->vaddr,
+           request->size, drm_sg_alloc_cb, entry, BUS_DMA_NOWAIT);
+       if (ret != 0) {
+               bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map);
+               bus_dma_tag_destroy(dmah->tag);
+               free(dmah, DRM_MEM_DMA);
+               free(entry->busaddr, DRM_MEM_PAGES);
+               free(entry, DRM_MEM_SGLISTS);
+               return ENOMEM;
        }
 
-       DRM_DEBUG( "sg alloc handle  = %08lx\n", entry->handle );
+       entry->dmah = dmah;
+       entry->handle = (unsigned long)dmah->vaddr;
+       
+       DRM_DEBUG("sg alloc handle  = %08lx\n", entry->handle);
 
        entry->virtual = (void *)entry->handle;
        request->handle = entry->handle;
@@ -99,31 +129,59 @@ int drm_sg_alloc(drm_device_t * dev, drm_scatter_gather_t * request)
        return 0;
 }
 
-int drm_sg_alloc_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv)
+static void
+drm_sg_alloc_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
 {
-       drm_scatter_gather_t *request = data;
-       int ret;
+       struct drm_sg_mem *entry = arg;
+       int i;
 
-       DRM_DEBUG( "%s\n", __FUNCTION__ );
+       if (error != 0)
+           return;
+
+       for(i = 0 ; i < nsegs ; i++) {
+               entry->busaddr[i] = segs[i].ds_addr;
+       }
+}
 
-       ret = drm_sg_alloc(dev, request);
-       return ret;
+int
+drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
+                  struct drm_file *file_priv)
+{
+       struct drm_scatter_gather *request = data;
+
+       DRM_DEBUG("\n");
+
+       return drm_sg_alloc(dev, request);
+}
+
+void
+drm_sg_cleanup(struct drm_sg_mem *entry)
+{
+       struct drm_dma_handle *dmah = entry->dmah;
+
+       bus_dmamap_unload(dmah->tag, dmah->map);
+       bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map);
+       bus_dma_tag_destroy(dmah->tag);
+       free(dmah, DRM_MEM_DMA);
+       free(entry->busaddr, DRM_MEM_PAGES);
+       free(entry, DRM_MEM_SGLISTS);
 }
 
-int drm_sg_free(drm_device_t *dev, void *data, struct drm_file *file_priv)
+int
+drm_sg_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_scatter_gather_t *request = data;
-       drm_sg_mem_t *entry;
+       struct drm_scatter_gather *request = data;
+       struct drm_sg_mem *entry;
 
        DRM_LOCK();
        entry = dev->sg;
        dev->sg = NULL;
        DRM_UNLOCK();
 
-       if ( !entry || entry->handle != request->handle )
+       if (!entry || entry->handle != request->handle)
                return EINVAL;
 
-       DRM_DEBUG( "sg free virtual  = 0x%lx\n", entry->handle );
+       DRM_DEBUG("sg free virtual = 0x%lx\n", entry->handle);
 
        drm_sg_cleanup(entry);
 
index 76ec514..4f4aeb1 100644 (file)
@@ -19,8 +19,6 @@
  * ERIC ANHOLT 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.
- *
- * $DragonFly: src/sys/dev/drm/drm_sysctl.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_sysctl.c
@@ -28,8 +26,8 @@
  * debug information.
  */
 
-#include "drmP.h"
-#include "drm.h"
+#include "dev/drm/drmP.h"
+#include "dev/drm/drm.h"
 
 #include <sys/sysctl.h>
 
@@ -54,14 +52,14 @@ struct drm_sysctl_info {
        char                   name[2];
 };
 
-int drm_sysctl_init(drm_device_t *dev)
+int drm_sysctl_init(struct drm_device *dev)
 {
        struct drm_sysctl_info *info;
        struct sysctl_oid *oid;
        struct sysctl_oid *top, *drioid;
        int               i;
 
-       info = malloc(sizeof *info, M_DRM, M_WAITOK | M_ZERO);
+       info = malloc(sizeof *info, DRM_MEM_DRIVER, M_WAITOK | M_ZERO);
        if ( !info )
                return 1;
        dev->sysctl = info;
@@ -108,12 +106,12 @@ int drm_sysctl_init(drm_device_t *dev)
        return 0;
 }
 
-int drm_sysctl_cleanup(drm_device_t *dev)
+int drm_sysctl_cleanup(struct drm_device *dev)
 {
        int error;
        error = sysctl_ctx_free( &dev->sysctl->ctx );
 
-       free(dev->sysctl, M_DRM);
+       free(dev->sysctl, DRM_MEM_DRIVER);
        dev->sysctl = NULL;
 
        return error;
@@ -129,12 +127,12 @@ do {                                                              \
 
 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
 {
-       drm_device_t *dev = arg1;
+       struct drm_device *dev = arg1;
        char buf[128];
        int retcode;
        int hasunique = 0;
 
-       DRM_SYSCTL_PRINT("%s 0x%x", dev->driver.name, dev2udev(dev->devnode));
+       DRM_SYSCTL_PRINT("%s 0x%x", dev->driver->name, dev2udev(dev->devnode));
        
        DRM_LOCK();
        if (dev->unique) {
@@ -154,7 +152,7 @@ done:
 
 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
 {
-       drm_device_t *dev = arg1;
+       struct drm_device *dev = arg1;
        drm_local_map_t *map, *tempmaps;
        const char   *types[] = { "FB", "REG", "SHM", "AGP", "SG" };
        const char *type, *yesno;
@@ -171,7 +169,8 @@ static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
        TAILQ_FOREACH(map, &dev->maplist, link)
                mapcount++;
 
-       tempmaps = malloc(sizeof(drm_local_map_t) * mapcount, M_DRM, M_NOWAIT);
+       tempmaps = malloc(sizeof(drm_local_map_t) * mapcount, DRM_MEM_DRIVER,
+           M_NOWAIT);
        if (tempmaps == NULL) {
                DRM_UNLOCK();
                return ENOMEM;
@@ -183,8 +182,8 @@ static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
 
        DRM_UNLOCK();
 
-       DRM_SYSCTL_PRINT("\nslot         offset       size type flags    "
-                        "address mtrr\n");
+       DRM_SYSCTL_PRINT("\nslot offset         size       "
+           "type flags address            mtrr\n");
 
        for (i = 0; i < mapcount; i++) {
                map = &tempmaps[i];
@@ -200,20 +199,20 @@ static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
                        yesno = "yes";
 
                DRM_SYSCTL_PRINT(
-                   "%4d 0x%08lx 0x%08lx %4.4s  0x%02x 0x%08lx %s\n", i,
+                   "%4d 0x%016lx 0x%08lx %4.4s  0x%02x 0x%016lx %s\n", i,
                    map->offset, map->size, type, map->flags,
                    (unsigned long)map->handle, yesno);
        }
        SYSCTL_OUT(req, "", 1);
 
 done:
-       free(tempmaps, M_DRM);
+       free(tempmaps, DRM_MEM_DRIVER);
        return retcode;
 }
 
 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
 {
-       drm_device_t     *dev = arg1;
+       struct drm_device        *dev = arg1;
        drm_device_dma_t *dma = dev->dma;
        drm_device_dma_t tempdma;
        int *templists;
@@ -231,7 +230,8 @@ static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
        }
        DRM_SPINLOCK(&dev->dma_lock);
        tempdma = *dma;
-       templists = malloc(sizeof(int) * dma->buf_count, M_DRM, M_NOWAIT);
+       templists = malloc(sizeof(int) * dma->buf_count, DRM_MEM_DRIVER,
+           M_NOWAIT);
        for (i = 0; i < dma->buf_count; i++)
                templists[i] = dma->buflist[i]->list;
        dma = &tempdma;
@@ -263,14 +263,14 @@ static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
 
        SYSCTL_OUT(req, "", 1);
 done:
-       free(templists, M_DRM);
+       free(templists, DRM_MEM_DRIVER);
        return retcode;
 }
 
 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
 {
-       drm_device_t *dev = arg1;
-       drm_file_t *priv, *tempprivs;
+       struct drm_device *dev = arg1;
+       struct drm_file *priv, *tempprivs;
        char buf[128];
        int retcode;
        int privcount, i;
@@ -281,7 +281,8 @@ static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
        TAILQ_FOREACH(priv, &dev->files, link)
                privcount++;
 
-       tempprivs = malloc(sizeof(drm_file_t) * privcount, M_DRM, M_NOWAIT);
+       tempprivs = malloc(sizeof(struct drm_file) * privcount, DRM_MEM_DRIVER,
+           M_NOWAIT);
        if (tempprivs == NULL) {
                DRM_UNLOCK();
                return ENOMEM;
@@ -306,6 +307,6 @@ static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
 
        SYSCTL_OUT(req, "", 1);
 done:
-       free(tempprivs, M_DRM);
+       free(tempprivs, DRM_MEM_DRIVER);
        return retcode;
 }
index fc581e1..1cbc313 100644 (file)
  * ERIC ANHOLT 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.
- *
- * $DragonFly: src/sys/dev/drm/drm_vm.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
  */
 
 /** @file drm_vm.c
  * Support code for mmaping of DRM maps.
  */
 
-#include "drmP.h"
-#include "drm.h"
+#include "dev/drm/drmP.h"
+#include "dev/drm/drm.h"
 
-#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
-int drm_mmap(struct cdev *kdev, vm_offset_t offset, vm_paddr_t *paddr,
-    int prot)
-#elif defined(__FreeBSD__)
-int drm_mmap(dev_t kdev, vm_offset_t offset, int prot)
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-paddr_t drm_mmap(dev_t kdev, off_t offset, int prot)
-#endif
-#ifdef __DragonFly__
 int drm_mmap(struct dev_mmap_args *ap)
 {
        struct cdev *kdev = ap->a_head.a_dev;
        vm_offset_t offset = ap->a_offset;
-#else
-{
-#endif
-       drm_device_t *dev = drm_get_device_from_kdev(kdev);
+       struct drm_device *dev = drm_get_device_from_kdev(kdev);
+       struct drm_file *file_priv = NULL;
        drm_local_map_t *map;
-       drm_file_t *priv;
-       drm_map_type_t type;
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+       enum drm_map_type type;
        vm_paddr_t phys;
-#else
-       paddr_t phys;
-#endif
 
-       DRM_LOCK();
-       priv = drm_find_file_by_proc(dev, DRM_CURPROC);
-       DRM_UNLOCK();
-       if (priv == NULL) {
-               DRM_ERROR("can't find authenticator\n");
-               return EINVAL;
-       }
+        DRM_LOCK();
+        file_priv = drm_find_file_by_proc(dev, DRM_CURPROC);
+        DRM_UNLOCK();
+
+        if (file_priv == NULL) {
+                DRM_ERROR("can't find authenticator\n");
+                return EINVAL;
+        }
 
-       if (!priv->authenticated)
-               return EACCES;
+        if (!file_priv->authenticated)
+                return EACCES;
 
-       if (dev->dma && offset >= 0 && offset < ptoa(dev->dma->page_count)) {
+       if (dev->dma && offset < ptoa(dev->dma->page_count)) {
                drm_device_dma_t *dma = dev->dma;
 
                DRM_SPINLOCK(&dev->dma_lock);
@@ -75,23 +58,13 @@ int drm_mmap(struct dev_mmap_args *ap)
                if (dma->pagelist != NULL) {
                        unsigned long page = offset >> PAGE_SHIFT;
                        unsigned long phys = dma->pagelist[page];
-
-#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
-                       *paddr = phys;
-                       DRM_SPINUNLOCK(&dev->dma_lock);
-                       return 0;
-#elif defined(__DragonFly__)
                        ap->a_result = atop(phys);
                        DRM_SPINUNLOCK(&dev->dma_lock);
-                       return (0);
-#else
-                       return atop(phys);
-#endif
+                       return 0;
                } else {
                        DRM_SPINUNLOCK(&dev->dma_lock);
                        return -1;
                }
-               DRM_SPINUNLOCK(&dev->dma_lock);
        }
 
                                /* A sequential search of a linked list is
@@ -108,8 +81,14 @@ int drm_mmap(struct dev_mmap_args *ap)
        }
 
        if (map == NULL) {
+               DRM_DEBUG("Can't find map, requested offset = %016lx\n",
+                   (unsigned long)offset);
+               TAILQ_FOREACH(map, &dev->maplist, link) {
+                       DRM_DEBUG("map offset = %016lx, handle = %016lx\n",
+                           (unsigned long)map->offset,
+                           (unsigned long)map->handle);
+               }
                DRM_UNLOCK();
-               DRM_DEBUG("can't find map\n");
                return -1;
        }
        if (((map->flags&_DRM_RESTRICTED) && !DRM_SUSER(DRM_CURPROC))) {
@@ -138,14 +117,7 @@ int drm_mmap(struct dev_mmap_args *ap)
                return -1;      /* This should never happen. */
        }
 
-#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
-       *paddr = phys;
-       return 0;
-#elif defined(__DragonFly__)
        ap->a_result = atop(phys);
-       return (0);
-#else
-       return atop(phys);
-#endif
+       return 0;
 }
 
index 36a2f5e..6a25e1c 100644 (file)
@@ -4,7 +4,7 @@
 KMOD   = i915
 KMODDEPS= drm
 NO_MAN = YES
-SRCS    = i915_dma.c i915_drv.c i915_irq.c i915_mem.c
+SRCS    = i915_dma.c i915_drv.c i915_irq.c i915_mem.c i915_suspend.c
 SRCS   += device_if.h bus_if.h pci_if.h opt_drm.h
 CFLAGS += ${DEBUG_FLAGS} -I. -I..
 
index bc82c15..667768d 100644 (file)
@@ -1,6 +1,6 @@
 /* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
  */
-/*
+/*-
  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  * All Rights Reserved.
  *
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
- * $DragonFly: src/sys/dev/drm/i915_dma.c,v 1.2 2008/10/27 03:42:33 hasso Exp $
  */
 
-#include "drmP.h"
-#include "drm.h"
-#include "i915_drm.h"
-#include "i915_drv.h"
+#include "dev/drm/drmP.h"
+#include "dev/drm/drm.h"
+#include "dev/drm/i915_drm.h"
+#include "dev/drm/i915_drv.h"
 
 /* Really want an OS-independent resettable timer.  Would like to have
  * this loop run for (eg) 3 sec, but have the timer reset every time
@@ -41,37 +40,99 @@ int i915_wait_ring(struct drm_device * dev, int n, const char *caller)
 {
        drm_i915_private_t *dev_priv = dev->dev_private;
        drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
-       u32 last_head = I915_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+       u32 last_head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
+       u32 acthd_reg = IS_I965G(dev) ? ACTHD_I965 : ACTHD;
+       u32 last_acthd = I915_READ(acthd_reg);
+       u32 acthd;
        int i;
 
-       for (i = 0; i < 10000; i++) {
-               ring->head = I915_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+       for (i = 0; i < 100000; i++) {
+               ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
+               acthd = I915_READ(acthd_reg);
                ring->space = ring->head - (ring->tail + 8);
                if (ring->space < 0)
                        ring->space += ring->Size;
                if (ring->space >= n)
                        return 0;
 
+               if (dev_priv->sarea_priv)
+                       dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
+
                if (ring->head != last_head)
                        i = 0;
 
+               if (acthd != last_acthd)
+                       i = 0;
+
                last_head = ring->head;
-               DRM_UDELAY(1);
+               last_acthd = acthd;
+               DRM_UDELAY(10 * 1000);
        }
 
        return -EBUSY;
 }
 
+/**
+ * Sets up the hardware status page for devices that need a physical address
+ * in the register.
+ */
+static int i915_init_phys_hws(struct drm_device *dev)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+
+       /* Program Hardware Status Page */
+       DRM_UNLOCK();
+       dev_priv->status_page_dmah =
+               drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE, 0xffffffff);
+       DRM_LOCK();
+       if (!dev_priv->status_page_dmah) {
+               DRM_ERROR("Can not allocate hardware status page\n");
+               return -ENOMEM;
+       }
+       dev_priv->hw_status_page = dev_priv->status_page_dmah->vaddr;
+       dev_priv->dma_status_page = dev_priv->status_page_dmah->busaddr;
+
+       memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
+
+       I915_WRITE(HWS_PGA, dev_priv->dma_status_page);
+       DRM_DEBUG("Enabled hardware status page\n");
+       return 0;
+}
+
+/**
+ * Frees the hardware status page, whether it's a physical address or a virtual
+ * address set up by the X Server.
+ */
+static void i915_free_hws(struct drm_device *dev)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       if (dev_priv->status_page_dmah) {
+               drm_pci_free(dev, dev_priv->status_page_dmah);
+               dev_priv->status_page_dmah = NULL;
+       }
+
+       if (dev_priv->status_gfx_addr) {
+               dev_priv->status_gfx_addr = 0;
+               drm_core_ioremapfree(&dev_priv->hws_map, dev);
+       }
+
+       /* Need to rewrite hardware status page */
+       I915_WRITE(HWS_PGA, 0x1ffff000);
+}
+
 void i915_kernel_lost_context(struct drm_device * dev)
 {
        drm_i915_private_t *dev_priv = dev->dev_private;
        drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
 
-       ring->head = I915_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-       ring->tail = I915_READ(LP_RING + RING_TAIL) & TAIL_ADDR;
+       ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
+       ring->tail = I915_READ(PRB0_TAIL) & TAIL_ADDR;
        ring->space = ring->head - (ring->tail + 8);
        if (ring->space < 0)
                ring->space += ring->Size;
+
+