summaryrefslogtreecommitdiff
path: root/bsd-core
diff options
context:
space:
mode:
Diffstat (limited to 'bsd-core')
-rw-r--r--bsd-core/ati_pcigart.c96
-rw-r--r--bsd-core/drmP.h287
-rw-r--r--bsd-core/drm_agpsupport.c49
-rw-r--r--bsd-core/drm_atomic.h53
-rw-r--r--bsd-core/drm_auth.c17
-rw-r--r--bsd-core/drm_bufs.c254
-rw-r--r--bsd-core/drm_context.c100
-rw-r--r--bsd-core/drm_dma.c19
-rw-r--r--bsd-core/drm_drawable.c23
-rw-r--r--bsd-core/drm_drv.c414
-rw-r--r--bsd-core/drm_fops.c91
-rw-r--r--bsd-core/drm_ioctl.c42
-rw-r--r--bsd-core/drm_irq.c189
-rw-r--r--bsd-core/drm_lock.c163
-rw-r--r--bsd-core/drm_memory.c50
-rw-r--r--bsd-core/drm_pci.c38
-rw-r--r--bsd-core/drm_scatter.c22
-rw-r--r--bsd-core/drm_sysctl.c6
-rw-r--r--bsd-core/drm_vm.c34
-rw-r--r--bsd-core/i915_drv.c82
-rw-r--r--bsd-core/mach64_drv.c74
-rw-r--r--bsd-core/mga_drv.c89
-rw-r--r--bsd-core/r128_drv.c82
-rw-r--r--bsd-core/radeon_drv.c93
-rw-r--r--bsd-core/savage_drv.c66
-rw-r--r--bsd-core/sis_drv.c60
-rw-r--r--bsd-core/tdfx_drv.c47
-rw-r--r--bsd-core/via_drv.c80
28 files changed, 1081 insertions, 1539 deletions
diff --git a/bsd-core/ati_pcigart.c b/bsd-core/ati_pcigart.c
index f8d3f18d..5feeeba8 100644
--- a/bsd-core/ati_pcigart.c
+++ b/bsd-core/ati_pcigart.c
@@ -39,26 +39,86 @@
#define ATI_PCIE_WRITE 0x4
#define ATI_PCIE_READ 0x8
-static int drm_ati_alloc_pcigart_table(struct drm_device *dev,
- struct drm_ati_pcigart_info *gart_info)
+static void
+drm_ati_alloc_pcigart_table_cb(void *arg, bus_dma_segment_t *segs,
+ int nsegs, int error)
{
- dev->sg->dmah = drm_pci_alloc(dev, gart_info->table_size,
- PAGE_SIZE,
- gart_info->table_mask);
- if (dev->sg->dmah == NULL)
+ 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), M_DRM, 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 */
+ BUS_DMA_ALLOCNOW, NULL, NULL, /* flags, lockfunc, lockfuncargs */
+ &dmah->tag);
+ if (ret != 0) {
+ free(dmah, M_DRM);
+ return ENOMEM;
+ }
+
+ flags = BUS_DMA_NOWAIT | BUS_DMA_ZERO;
+ if (gart_info->gart_reg_if == DRM_ATI_GART_IGP)
+ flags |= BUS_DMA_NOCACHE;
+
+ ret = bus_dmamem_alloc(dmah->tag, &dmah->vaddr, flags, &dmah->map);
+ if (ret != 0) {
+ bus_dma_tag_destroy(dmah->tag);
+ free(dmah, M_DRM);
+ 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, 0);
+ if (ret != 0) {
+ bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map);
+ bus_dma_tag_destroy(dmah->tag);
+ free(dmah, M_DRM);
+ return ENOMEM;
+ }
+
+ dev->sg->dmah = dmah;
+
return 0;
}
-static void drm_ati_free_pcigart_table(struct drm_device *dev,
- struct drm_ati_pcigart_info *gart_info)
+static void
+drm_ati_free_pcigart_table(struct drm_device *dev,
+ struct drm_ati_pcigart_info *gart_info)
{
- drm_pci_free(dev, dev->sg->dmah);
+ struct drm_dma_handle *dmah = dev->sg->dmah;
+
+ bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map);
+ bus_dma_tag_destroy(dmah->tag);
+ free(dmah, M_DRM);
dev->sg->dmah = NULL;
}
-int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info)
+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) {
@@ -77,17 +137,17 @@ int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info
return 1;
}
-int drm_ati_pcigart_init(struct drm_device *dev,
- struct drm_ati_pcigart_info *gart_info)
+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;
- dma_addr_t entry_addr;
/* we need to support large memory configurations */
if (dev->sg == NULL) {
@@ -129,12 +189,14 @@ int drm_ati_pcigart_init(struct drm_device *dev,
page_base = (u32) entry_addr & ATI_PCIGART_PAGE_MASK;
switch(gart_info->gart_reg_if) {
case DRM_ATI_GART_IGP:
- page_base |= (upper_32_bits(entry_addr) & 0xff) << 4;
+ page_base |=
+ (upper_32_bits(entry_addr) & 0xff) << 4;
page_base |= 0xc;
break;
case DRM_ATI_GART_PCIE:
page_base >>= 8;
- page_base |= (upper_32_bits(entry_addr) & 0xff) << 24;
+ page_base |=
+ (upper_32_bits(entry_addr) & 0xff) << 24;
page_base |= ATI_PCIE_READ | ATI_PCIE_WRITE;
break;
default:
@@ -147,8 +209,6 @@ int drm_ati_pcigart_init(struct drm_device *dev,
}
}
- DRM_MEMORYBARRIER();
-
ret = 1;
done:
diff --git a/bsd-core/drmP.h b/bsd-core/drmP.h
index 326b2202..fcce9066 100644
--- a/bsd-core/drmP.h
+++ b/bsd-core/drmP.h
@@ -37,7 +37,7 @@
#if defined(_KERNEL) || defined(__KERNEL__)
struct drm_device;
-typedef struct drm_file drm_file_t;
+struct drm_file;
#include <sys/param.h>
#include <sys/queue.h>
@@ -70,10 +70,10 @@ typedef struct drm_file drm_file_t;
#include <machine/pmap.h>
#include <machine/bus.h>
#include <machine/resource.h>
+#include <machine/specialreg.h>
#include <machine/sysarch.h>
#include <sys/endian.h>
#include <sys/mman.h>
-#if defined(__FreeBSD__)
#include <sys/rman.h>
#include <sys/memrange.h>
#if __FreeBSD_version >= 800004
@@ -82,31 +82,9 @@ typedef struct drm_file drm_file_t;
#include <pci/agpvar.h>
#endif /* __FreeBSD_version >= 800004 */
#include <sys/agpio.h>
-#if __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"
@@ -114,13 +92,11 @@ typedef struct drm_file drm_file_t;
#include "drm_atomic.h"
#include "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__)
#include <sys/file.h>
@@ -135,6 +111,17 @@ 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 */
@@ -183,12 +170,6 @@ 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
@@ -206,21 +187,6 @@ MALLOC_DECLARE(M_DRM);
#define DRM_LOCK() mtx_lock(&dev->dev_lock)
#define DRM_UNLOCK() mtx_unlock(&dev->dev_lock)
#define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
-#else /* __FreeBSD__ && __FreeBSD_version >= 500000 */
-#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;
@@ -234,16 +200,8 @@ enum {
};
#define DRM_AGP_MEM struct agp_memory_info
-#if defined(__FreeBSD__)
#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__)
#define PAGE_ALIGN(addr) round_page(addr)
/* DRM_SUSER returns true if the user is superuser */
#if __FreeBSD_version >= 700000
@@ -255,20 +213,6 @@ enum {
#define DRM_MTRR_WC MDF_WRITECOMBINE
#define jiffies ticks
-#else /* __FreeBSD__ */
-
-#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 struct drm_device *device_t;
-extern struct cfdriver drm_cd;
-#endif /* !__FreeBSD__ */
-
/* Capabilities taken from src/sys/dev/pci/pcireg.h. */
#ifndef PCIY_AGP
#define PCIY_AGP 0x02
@@ -306,7 +250,6 @@ typedef u_int8_t u8;
"lock; addl $0,0(%%rsp)" : : : "memory");
#endif
-#ifdef __FreeBSD__
#define DRM_READ8(map, offset) \
*(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset))
#define DRM_READ16(map, offset) \
@@ -323,27 +266,6 @@ typedef u_int8_t u8;
#define DRM_VERIFYAREA_READ( uaddr, size ) \
(!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
-#else /* __FreeBSD__ */
-
-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__ */
-
#define DRM_COPY_TO_USER(user, kern, size) \
copyout(kern, user, size)
#define DRM_COPY_FROM_USER(kern, user, size) \
@@ -352,13 +274,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)
@@ -381,7 +298,6 @@ 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) ; ) { \
@@ -393,17 +309,6 @@ for ( ret = 0 ; !ret && !(condition) ; ) { \
mtx_unlock(&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
#define DRM_ERROR(fmt, arg...) \
printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
@@ -489,12 +394,8 @@ typedef struct drm_freelist {
typedef struct drm_dma_handle {
void *vaddr;
bus_addr_t busaddr;
-#if defined(__FreeBSD__)
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 {
@@ -511,19 +412,19 @@ 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;
pid_t pid;
uid_t uid;
- int refs;
drm_magic_t magic;
unsigned long ioctl_count;
void *driver_priv;
};
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 */
@@ -586,8 +487,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 */
@@ -608,6 +509,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
@@ -637,9 +551,9 @@ struct drm_ati_pcigart_info {
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 *,
@@ -649,9 +563,9 @@ struct drm_driver_info {
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,
@@ -692,16 +606,7 @@ 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_*. */
@@ -711,11 +616,7 @@ struct drm_driver_info {
* 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 */
@@ -723,21 +624,17 @@ struct drm_device {
char *unique; /* Unique identifier: e.g., busid */
int unique_len; /* Length of unique field */
-#ifdef __FreeBSD__
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 vbl_lock; /* protects vblank operations */
struct mtx dma_lock; /* protects dev->dma */
struct mtx irq_lock; /* protects irq condition checks */
struct mtx dev_lock; /* protects everything else */
-#endif
DRM_SPINTYPE drw_lock;
DRM_SPINTYPE tsk_lock;
@@ -747,7 +644,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 */
@@ -768,12 +665,8 @@ struct drm_device {
/* Context support */
int irq; /* Interrupt used by board */
int irq_enabled; /* True if the irq handler is enabled */
-#ifdef __FreeBSD__
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_* */
@@ -787,27 +680,15 @@ struct drm_device {
atomic_t context_flag; /* Context swapping flag */
int last_context; /* Last current context */
+
int vblank_disable_allowed;
- wait_queue_head_t *vbl_queue; /* vblank wait queue */
- atomic_t *_vblank_count; /* number of VBLANK interrupts */
- /* (driver must alloc the right number of counters) */
- struct drm_vbl_sig_list *vbl_sigs; /* signal list to send on VBLANK */
- atomic_t vbl_signal_pending; /* number of signals pending on all crtcs*/
- atomic_t *vblank_refcount; /* number of users of vblank interrupts per crtc */
- u32 *last_vblank; /* protected by dev->vbl_lock, used */
- /* for wraparound handling */
- int *vblank_enabled; /* so we don't call enable more than */
- /* once per disable */
- int *vblank_inmodeset; /* Display driver is setting mode */
+ 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;
-#ifdef __FreeBSD__
struct sigio *buf_sigio; /* Processes waiting for SIGIO */
-#elif defined(__NetBSD__)
- pid_t buf_pgid;
-#endif
/* Sysctl support */
struct drm_sysctl_info *sysctl;
@@ -827,45 +708,39 @@ struct drm_device {
void (*locked_task_call)(struct drm_device *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) */
-#ifdef __FreeBSD__
int drm_probe(device_t nbdev, drm_pci_id_list_t *idlist);
int drm_attach(device_t nbdev, drm_pci_id_list_t *idlist);
+void drm_close(void *data);
int drm_detach(device_t nbdev);
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(struct drm_device *dev);
/* File operations helpers (drm_fops.c) */
-#ifdef __FreeBSD__
extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
DRM_STRUCTPROC *p,
struct drm_device *dev);
-extern drm_file_t *drm_find_file_by_proc(struct drm_device *dev,
- DRM_STRUCTPROC *p);
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-extern int drm_open_helper(dev_t kdev, int flags, int fmt,
- DRM_STRUCTPROC *p,
- struct drm_device *dev);
-extern drm_file_t *drm_find_file_by_proc(struct drm_device *dev,
- DRM_STRUCTPROC *p);
-#endif /* __NetBSD__ || __OpenBSD__ */
/* Memory management support (drm_memory.c) */
void drm_mem_init(void);
@@ -875,6 +750,7 @@ 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_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);
@@ -889,13 +765,11 @@ 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(struct drm_device *dev,
- __volatile__ unsigned int *lock,
+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_device *dev,
- __volatile__ unsigned int *lock,
+int drm_lock_free(struct drm_lock_data *lock_data,
unsigned int context);
/* Buffer management support (drm_bufs.c) */
@@ -907,11 +781,11 @@ void drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
int drm_order(unsigned long size);
int drm_addmap(struct drm_device *dev, unsigned long offset,
unsigned long size,
- drm_map_type_t type, drm_map_flags_t flags,
+ enum drm_map_type type, enum drm_map_flags flags,
drm_local_map_t **map_ptr);
-int drm_addbufs_pci(struct drm_device *dev, drm_buf_desc_t *request);
-int drm_addbufs_sg(struct drm_device *dev, drm_buf_desc_t *request);
-int drm_addbufs_agp(struct drm_device *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(struct drm_device *dev);
@@ -943,26 +817,24 @@ int drm_device_is_pcie(struct drm_device *dev);
drm_agp_head_t *drm_agp_init(void);
int drm_agp_acquire(struct drm_device *dev);
int drm_agp_release(struct drm_device *dev);
-int drm_agp_info(struct drm_device * dev, drm_agp_info_t *info);
-int drm_agp_enable(struct drm_device *dev, drm_agp_mode_t mode);
+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(struct drm_device *dev, drm_agp_buffer_t *request);
-int drm_agp_free(struct drm_device *dev, drm_agp_buffer_t *request);
-int drm_agp_bind(struct drm_device *dev, drm_agp_binding_t *request);
-int drm_agp_unbind(struct drm_device *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(struct drm_device *dev, drm_scatter_gather_t * request);
+int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
-#ifdef __FreeBSD__
/* sysctl support (drm_sysctl.h) */
extern int drm_sysctl_init(struct drm_device *dev);
extern int drm_sysctl_cleanup(struct drm_device *dev);
-#endif /* __FreeBSD__ */
/* ATI PCIGART support (ati_pcigart.c) */
int drm_ati_pcigart_init(struct drm_device *dev,
@@ -1000,7 +872,7 @@ int drm_noop(struct drm_device *dev, void *data,
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);
+ 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,
@@ -1026,6 +898,9 @@ int drm_update_draw(struct drm_device *dev, void *data,
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(struct drm_device *dev, void *data,
struct drm_file *file_priv);
@@ -1052,7 +927,8 @@ int drm_mapbufs(struct drm_device *dev, void *data,
int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
/* IRQ support (drm_irq.c) */
-int drm_control(struct drm_device *dev, void *data, struct drm_file *file_priv);
+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);
void drm_locked_tasklet(struct drm_device *dev,
@@ -1087,10 +963,13 @@ 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);
-#define drm_core_ioremap_wc drm_core_ioremap
-
/* Inline replacements for DRM_IOREMAP macros */
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);
diff --git a/bsd-core/drm_agpsupport.c b/bsd-core/drm_agpsupport.c
index 97613d21..a568c5a5 100644
--- a/bsd-core/drm_agpsupport.c
+++ b/bsd-core/drm_agpsupport.c
@@ -35,20 +35,17 @@
#include "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>
-#endif
/* Returns 1 if AGP or 0 if not. */
static int
drm_device_find_capability(struct drm_device *dev, int cap)
{
-#ifdef __FreeBSD__
#if __FreeBSD_version >= 602102
return (pci_find_extcap(dev->device, cap, NULL) == 0);
@@ -82,21 +79,17 @@ drm_device_find_capability(struct drm_device *dev, int cap)
return 0;
#endif
-#else
- /* XXX: fill me in for non-FreeBSD */
- return 1;
-#endif
}
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;
}
@@ -109,7 +102,7 @@ int drm_device_is_pcie(struct drm_device *dev)
return (drm_device_find_capability(dev, PCIY_EXPRESS));
}
-int drm_agp_info(struct drm_device * dev, drm_agp_info_t *info)
+int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info)
{
struct agp_info *kern;
@@ -135,13 +128,13 @@ 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;
}
@@ -183,7 +176,7 @@ int drm_agp_release(struct drm_device * dev)
return 0;
}
-int drm_agp_enable(struct drm_device *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)
@@ -198,14 +191,14 @@ int drm_agp_enable(struct drm_device *dev, drm_agp_mode_t mode)
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(struct drm_device *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;
@@ -251,16 +244,16 @@ int drm_agp_alloc(struct drm_device *dev, drm_agp_buffer_t *request)
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;
}
@@ -276,7 +269,7 @@ static drm_agp_mem_t * drm_agp_lookup_entry(struct drm_device *dev,
return NULL;
}
-int drm_agp_unbind(struct drm_device *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;
@@ -301,10 +294,10 @@ int drm_agp_unbind(struct drm_device *dev, drm_agp_binding_t *request)
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);
@@ -313,7 +306,7 @@ int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
return retcode;
}
-int drm_agp_bind(struct drm_device *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;
@@ -342,10 +335,10 @@ int drm_agp_bind(struct drm_device *dev, drm_agp_binding_t *request)
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);
@@ -354,7 +347,7 @@ int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
return retcode;
}
-int drm_agp_free(struct drm_device *dev, drm_agp_buffer_t *request)
+int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request)
{
drm_agp_mem_t *entry;
@@ -387,10 +380,10 @@ int drm_agp_free(struct drm_device *dev, drm_agp_buffer_t *request)
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);
diff --git a/bsd-core/drm_atomic.h b/bsd-core/drm_atomic.h
index b499fc96..76de7a2f 100644
--- a/bsd-core/drm_atomic.h
+++ b/bsd-core/drm_atomic.h
@@ -33,65 +33,12 @@
typedef u_int32_t atomic_t;
-#ifdef __FreeBSD__
#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__ */
-/* 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__ */
-
-#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)
diff --git a/bsd-core/drm_auth.c b/bsd-core/drm_auth.c
index f3aafe44..b5fc5587 100644
--- a/bsd-core/drm_auth.c
+++ b/bsd-core/drm_auth.c
@@ -43,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(struct drm_device *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);
@@ -63,7 +63,7 @@ static drm_file_t *drm_find_file(struct drm_device *dev, drm_magic_t magic)
* Inserts the given magic number into the hash table of used magic number
* lists.
*/
-static int drm_add_magic(struct drm_device *dev, drm_file_t *priv,
+static int drm_add_magic(struct drm_device *dev, struct drm_file *priv,
drm_magic_t magic)
{
int hash;
@@ -75,7 +75,8 @@ static int drm_add_magic(struct drm_device *dev, drm_file_t *priv,
hash = drm_hash_magic(magic);
entry = malloc(sizeof(*entry), M_DRM, M_ZERO | M_NOWAIT);
- if (!entry) return ENOMEM;
+ if (!entry)
+ return ENOMEM;
entry->magic = magic;
entry->priv = priv;
entry->next = NULL;
@@ -117,11 +118,11 @@ static int drm_remove_magic(struct drm_device *dev, drm_magic_t magic)
if (prev) {
prev->next = pt->next;
}
+ free(pt, M_DRM);
return 0;
}
}
- free(pt, M_DRM);
return EINVAL;
}
@@ -136,9 +137,9 @@ static int drm_remove_magic(struct drm_device *dev, drm_magic_t magic)
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 {
@@ -167,8 +168,8 @@ 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)
{
- drm_auth_t *auth = data;
- drm_file_t *priv;
+ struct drm_auth *auth = data;
+ struct drm_file *priv;
DRM_DEBUG("%u\n", auth->magic);
diff --git a/bsd-core/drm_bufs.c b/bsd-core/drm_bufs.c
index c793634b..c9b5dc4e 100644
--- a/bsd-core/drm_bufs.c
+++ b/bsd-core/drm_bufs.c
@@ -36,22 +36,6 @@
#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 );
-
- if ( size & ~(1 << order) )
- ++order;
-
- return order;
-}
-
/* 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.
@@ -102,7 +86,7 @@ unsigned long drm_get_resource_len(struct drm_device *dev,
int drm_addmap(struct drm_device * dev, unsigned long offset,
unsigned long size,
- drm_map_type_t type, drm_map_flags_t flags, drm_local_map_t **map_ptr)
+ enum drm_map_type type, enum drm_map_flags flags, drm_local_map_t **map_ptr)
{
drm_local_map_t *map;
int align;
@@ -152,7 +136,7 @@ int drm_addmap(struct drm_device * dev, unsigned long offset,
* initialization necessary.
*/
map = malloc(sizeof(*map), M_DRM, M_ZERO | M_NOWAIT);
- if ( !map ) {
+ if (!map) {
DRM_LOCK();
return ENOMEM;
}
@@ -162,7 +146,7 @@ int drm_addmap(struct drm_device * dev, unsigned long offset,
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,15 +158,15 @@ int drm_addmap(struct drm_device * dev, unsigned long offset,
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 ) {
+ DRM_DEBUG("%lu %d %p\n",
+ map->size, drm_order(map->size), map->handle);
+ if (!map->handle) {
free(map, M_DRM);
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) {
@@ -274,7 +258,7 @@ done:
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;
@@ -355,7 +339,7 @@ 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) {
@@ -402,7 +386,7 @@ static void drm_cleanup_buf_error(struct drm_device *dev,
}
}
-static int drm_do_addbufs_agp(struct drm_device *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;
@@ -426,20 +410,20 @@ static int drm_do_addbufs_agp(struct drm_device *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
@@ -465,7 +449,7 @@ static int drm_do_addbufs_agp(struct drm_device *dev, drm_buf_desc_t *request)
entry->buflist = malloc(count * sizeof(*entry->buflist), M_DRM,
M_NOWAIT | M_ZERO);
- if ( !entry->buflist ) {
+ if (!entry->buflist) {
return ENOMEM;
}
@@ -474,7 +458,7 @@ static int drm_do_addbufs_agp(struct drm_device *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;
@@ -488,7 +472,7 @@ static int drm_do_addbufs_agp(struct drm_device *dev, drm_buf_desc_t *request)
buf->pending = 0;
buf->file_priv = NULL;
- buf->dev_priv_size = dev->driver.buf_priv_size;
+ buf->dev_priv_size = dev->driver->buf_priv_size;
buf->dev_private = malloc(buf->dev_priv_size, M_DRM,
M_NOWAIT | M_ZERO);
if (buf->dev_private == NULL) {
@@ -503,7 +487,7 @@ static int drm_do_addbufs_agp(struct drm_device *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,
@@ -515,15 +499,15 @@ static int drm_do_addbufs_agp(struct drm_device *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;
@@ -533,7 +517,7 @@ static int drm_do_addbufs_agp(struct drm_device *dev, drm_buf_desc_t *request)
return 0;
}
-static int drm_do_addbufs_pci(struct drm_device *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;
@@ -555,11 +539,11 @@ static int drm_do_addbufs_pci(struct drm_device *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;
@@ -578,25 +562,28 @@ static int drm_do_addbufs_pci(struct drm_device *dev, drm_buf_desc_t *request)
if (entry->buflist == NULL || entry->seglist == NULL ||
temp_pagelist == NULL) {
- free(entry->buflist, M_DRM);
+ free(temp_pagelist, M_DRM);
free(entry->seglist, M_DRM);
+ free(entry->buflist, M_DRM);
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;
@@ -607,16 +594,16 @@ static int drm_do_addbufs_pci(struct drm_device *dev, drm_buf_desc_t *request)
}
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;
@@ -629,7 +616,7 @@ static int drm_do_addbufs_pci(struct drm_device *dev, drm_buf_desc_t *request)
buf->pending = 0;
buf->file_priv = NULL;
- buf->dev_priv_size = dev->driver.buf_priv_size;
+ buf->dev_priv_size = dev->driver->buf_priv_size;
buf->dev_private = malloc(buf->dev_priv_size, M_DRM,
M_NOWAIT | M_ZERO);
if (buf->dev_private == NULL) {
@@ -641,8 +628,8 @@ static int drm_do_addbufs_pci(struct drm_device *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);
}
byte_count += PAGE_SIZE << page_order;
}
@@ -658,7 +645,7 @@ static int drm_do_addbufs_pci(struct drm_device *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];
}
@@ -680,7 +667,7 @@ static int drm_do_addbufs_pci(struct drm_device *dev, drm_buf_desc_t *request)
}
-static int drm_do_addbufs_sg(struct drm_device *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;
@@ -702,20 +689,20 @@ static int drm_do_addbufs_sg(struct drm_device *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];
@@ -729,7 +716,7 @@ static int drm_do_addbufs_sg(struct drm_device *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;
@@ -743,7 +730,7 @@ static int drm_do_addbufs_sg(struct drm_device *dev, drm_buf_desc_t *request)
buf->pending = 0;
buf->file_priv = NULL;
- buf->dev_priv_size = dev->driver.buf_priv_size;
+ buf->dev_priv_size = dev->driver->buf_priv_size;
buf->dev_private = malloc(buf->dev_priv_size, M_DRM,
M_NOWAIT | M_ZERO);
if (buf->dev_private == NULL) {
@@ -753,15 +740,15 @@ static int drm_do_addbufs_sg(struct drm_device *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,
@@ -773,15 +760,15 @@ static int drm_do_addbufs_sg(struct drm_device *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;
@@ -791,7 +778,7 @@ static int drm_do_addbufs_sg(struct drm_device *dev, drm_buf_desc_t *request)
return 0;
}
-int drm_addbufs_agp(struct drm_device *dev, drm_buf_desc_t *request)
+int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request)
{
int order, ret;
@@ -822,7 +809,7 @@ int drm_addbufs_agp(struct drm_device *dev, drm_buf_desc_t *request)
return ret;
}
-int drm_addbufs_sg(struct drm_device *dev, drm_buf_desc_t *request)
+int drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request)
{
int order, ret;
@@ -856,7 +843,7 @@ int drm_addbufs_sg(struct drm_device *dev, drm_buf_desc_t *request)
return ret;
}
-int drm_addbufs_pci(struct drm_device *dev, drm_buf_desc_t *request)
+int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request)
{
int order, ret;
@@ -893,7 +880,7 @@ int drm_addbufs_pci(struct drm_device *dev, drm_buf_desc_t *request)
int drm_addbufs_ioctl(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)
@@ -909,7 +896,7 @@ int drm_addbufs_ioctl(struct drm_device *dev, void *data,
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;
@@ -918,16 +905,17 @@ int drm_infobufs(struct drm_device *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;
@@ -935,17 +923,16 @@ int drm_infobufs(struct drm_device *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;
}
}
@@ -958,11 +945,11 @@ 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)
{
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);
@@ -988,30 +975,30 @@ 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)
{
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;
}
@@ -1029,30 +1016,13 @@ int drm_mapbufs(struct drm_device *dev, void *data, struct drm_file *file_priv)
const int zero = 0;
vm_offset_t address;
struct vmspace *vms;
-#ifdef __FreeBSD__
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
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 */
@@ -1061,8 +1031,9 @@ int drm_mapbufs(struct drm_device *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) {
@@ -1076,7 +1047,6 @@ int drm_mapbufs(struct drm_device *dev, void *data, struct drm_file *file_priv)
foff = 0;
}
-#ifdef __FreeBSD__
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,
@@ -1086,18 +1056,12 @@ int drm_mapbufs(struct drm_device *dev, void *data, struct drm_file *file_priv)
VM_PROT_ALL, MAP_SHARED, 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;
@@ -1124,7 +1088,23 @@ int drm_mapbufs(struct drm_device *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;
+ unsigned long tmp;
+
+ for (order = 0, tmp = size; tmp >>= 1; ++order);
+
+ if (size & ~(1 << order))
+ ++order;
+
+ return order;
+}
diff --git a/bsd-core/drm_context.c b/bsd-core/drm_context.c
index 6d44fbec..bca899cb 100644
--- a/bsd-core/drm_context.c
+++ b/bsd-core/drm_context.c
@@ -62,7 +62,7 @@ int drm_ctxbitmap_next(struct drm_device *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;
@@ -108,7 +108,7 @@ int drm_ctxbitmap_init(struct drm_device *dev)
DRM_LOCK();
dev->ctx_bitmap = malloc(PAGE_SIZE, M_DRM, M_NOWAIT | M_ZERO);
- if ( dev->ctx_bitmap == NULL ) {
+ if (dev->ctx_bitmap == NULL) {
DRM_UNLOCK();
return ENOMEM;
}
@@ -116,9 +116,9 @@ int drm_ctxbitmap_init(struct drm_device *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;
@@ -140,7 +140,7 @@ void drm_ctxbitmap_cleanup(struct drm_device *dev)
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();
@@ -161,7 +161,7 @@ int drm_getsareactx(struct drm_device *dev, void *data,
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();
@@ -188,49 +188,49 @@ bad:
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(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(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;
}
}
@@ -241,23 +241,23 @@ 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)
{
- 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();
}
@@ -272,7 +272,7 @@ 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)
{
- drm_ctx_t *ctx = data;
+ struct drm_ctx *ctx = data;
/* This is 0, because we don't handle any context flags */
ctx->flags = 0;
@@ -283,17 +283,17 @@ 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)
{
- 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(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;
@@ -301,13 +301,13 @@ 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)
{
- 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();
}
diff --git a/bsd-core/drm_dma.c b/bsd-core/drm_dma.c
index c2586fa0..51f60683 100644
--- a/bsd-core/drm_dma.c
+++ b/bsd-core/drm_dma.c
@@ -58,14 +58,12 @@ void drm_dma_takedown(struct drm_device *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]);
}
@@ -91,7 +89,8 @@ void drm_dma_takedown(struct drm_device *dev)
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;
@@ -103,7 +102,9 @@ 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) {
@@ -125,9 +126,9 @@ void drm_reclaim_buffers(struct drm_device *dev, 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;
diff --git a/bsd-core/drm_drawable.c b/bsd-core/drm_drawable.c
index 268b956c..018db57d 100644
--- a/bsd-core/drm_drawable.c
+++ b/bsd-core/drm_drawable.c
@@ -68,7 +68,7 @@ drm_get_drawable_info(struct drm_device *dev, int handle)
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),
@@ -89,7 +89,7 @@ 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)
{
- 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);
@@ -151,3 +151,22 @@ int drm_update_draw(struct drm_device *dev, void *data,
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_unr(dev->drw_unrhdr, info->handle);
+ drm_free(info, sizeof(struct bsd_drm_drawable_info),
+ DRM_MEM_DRAWABLE);
+ DRM_SPINLOCK(&dev->drw_lock);
+ }
+ DRM_SPINUNLOCK(&dev->drw_lock);
+}
diff --git a/bsd-core/drm_drv.c b/bsd-core/drm_drv.c
index 771e5554..a35d60a7 100644
--- a/bsd-core/drm_drv.c
+++ b/bsd-core/drm_drv.c
@@ -50,22 +50,13 @@ 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);
-#ifdef __FreeBSD__
#define DRIVER_SOFTC(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__ */
-
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#define DRIVER_SOFTC(unit) \
- ((struct drm_device *)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),
@@ -129,27 +120,15 @@ static drm_ioctl_desc_t drm_ioctls[256] = {
DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW, drm_update_draw, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
};
-#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
+ .d_flags = D_TRACKCLOSE | D_NEEDGIANT
};
int drm_probe(device_t dev, drm_pci_id_list_t *idlist)
@@ -202,13 +181,12 @@ int drm_attach(device_t nbdev, drm_pci_id_list_t *idlist)
DRM_DEV_GID,
DRM_DEV_MODE,
"dri/card%d", unit);
-#if __FreeBSD_version >= 500000
+
mtx_init(&dev->dev_lock, "drmdev", NULL, MTX_DEF);
mtx_init(&dev->irq_lock, "drmirq", NULL, MTX_DEF);
mtx_init(&dev->vbl_lock, "drmvbl", NULL, MTX_DEF);
mtx_init(&dev->drw_lock, "drmdrw", NULL, MTX_DEF);
mtx_init(&dev->tsk_lock, "drmtsk", NULL, MTX_DEF);
-#endif
id_entry = drm_find_description(pci_get_vendor(dev->device),
pci_get_device(dev->device), idlist);
@@ -229,147 +207,6 @@ int drm_detach(device_t dev)
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
-};
-
-int drm_refcnt = 0;
-
-#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);
-#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;
-
- if(drm_modprobe())
- return 0;
-
- return 1;
-
- case LKM_E_UNLOAD:
- if (drm_refcnt > 0)
- return (EBUSY);
- break;
- case LKM_E_STAT:
- break;
-
- default:
- error = EIO;
- break;
- }
-
- return error;
-}
-
-int drm_modprobe(void)
-{
- struct pci_attach_args pa;
- int error;
-
- error = pci_find_device(&pa, drm_probe, idlist);
- if (error != 0)
- drm_attach(&pa, 0);
-
- return error;
-}
-
-int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t idlist)
-{
- const char *desc;
- drm_pci_id_list_t *id_entry;
-
- id_entry = drm_find_description(PCI_VENDOR(pa->pa_id),
- PCI_PRODUCT(pa->pa_id), idlist);
- if (id_entry != NULL) {
- return 1;
- }
-
- return 0;
-}
-
-void drm_attach(struct pci_attach_args *pa, dev_t kdev,
- drm_pci_id_list_t *idlist)
-{
- int i;
- struct drm_device *dev;
- drm_pci_id_list_t *id_entry;
-
- config_makeroom(kdev, &drm_cd);
- drm_cd.cd_devs[(kdev)] = malloc(sizeof(struct drm_device),
- M_DRM, M_WAITOK);
- dev = DRIVER_SOFTC(kdev);
-
- memset(dev, 0, sizeof(struct drm_device));
- 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((struct drm_device *)self);
- return 0;
-}
-
-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__ */
-
drm_pci_id_list_t *drm_find_description(int vendor, int device,
drm_pci_id_list_t *idlist)
{
@@ -393,22 +230,22 @@ static int drm_firstopen(struct drm_device *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;
}
@@ -419,13 +256,9 @@ static int drm_firstopen(struct drm_device *dev)
dev->last_context = 0;
dev->if_version = 0;
-#ifdef __FreeBSD__
dev->buf_sigio = NULL;
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
- dev->buf_pgid = 0;
-#endif
- DRM_DEBUG( "\n" );
+ DRM_DEBUG("\n");
return 0;
}
@@ -438,39 +271,43 @@ static int drm_lastclose(struct drm_device *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 ) {
+ if (dev->unique) {
free(dev->unique, M_DRM);
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);
}
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);
@@ -494,7 +331,7 @@ static int drm_lastclose(struct drm_device *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);
@@ -507,10 +344,10 @@ static int drm_load(struct drm_device *dev)
{
int i, retcode;
- DRM_DEBUG( "\n" );
+ DRM_DEBUG("\n");
dev->irq = pci_get_irq(dev->device);
-#if defined(__FreeBSD__) && __FreeBSD_version >= 700053
+#if __FreeBSD_version >= 700053
dev->pci_domain = pci_get_domain(dev->device);
#else
dev->pci_domain = 0;
@@ -525,9 +362,7 @@ static int drm_load(struct drm_device *dev)
TAILQ_INIT(&dev->maplist);
drm_mem_init();
-#ifdef __FreeBSD__
drm_sysctl_init(dev);
-#endif
TAILQ_INIT(&dev->files);
dev->counters = 6;
@@ -538,13 +373,13 @@ static int drm_load(struct drm_device *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);
if (pci_enable_busmaster(dev->device))
DRM_ERROR("Request to enable bus-master failed.\n");
@@ -553,10 +388,11 @@ static int drm_load(struct drm_device *dev)
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;
@@ -582,30 +418,27 @@ static int drm_load(struct drm_device *dev)
}
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:
-#ifdef __FreeBSD__
drm_sysctl_cleanup(dev);
-#endif
DRM_LOCK();
drm_lastclose(dev);
DRM_UNLOCK();
-#ifdef __FreeBSD__
destroy_dev(dev->devnode);
-#if __FreeBSD_version >= 500000
+
+ mtx_destroy(&dev->tsk_lock);
mtx_destroy(&dev->drw_lock);
- mtx_destroy(&dev->irq_lock);
mtx_destroy(&dev->vbl_lock);
+ mtx_destroy(&dev->irq_lock);
mtx_destroy(&dev->dev_lock);
-#endif
-#endif
+
return retcode;
}
@@ -613,12 +446,10 @@ static void drm_unload(struct drm_device *dev)
{
int i;
- DRM_DEBUG( "\n" );
+ DRM_DEBUG("\n");
-#ifdef __FreeBSD__
drm_sysctl_cleanup(dev);
destroy_dev(dev->devnode);
-#endif
drm_ctxbitmap_cleanup(dev);
@@ -647,13 +478,16 @@ static void drm_unload(struct drm_device *dev)
dev->pcir[i] = NULL;
}
- if ( dev->agp ) {
+ if (dev->agp) {
free(dev->agp, M_DRM);
dev->agp = NULL;
}
- if (dev->driver.unload != NULL)
- dev->driver.unload(dev);
+ if (dev->driver->unload != NULL) {
+ DRM_LOCK();
+ dev->driver->unload(dev);
+ DRM_UNLOCK();
+ }
delete_unrhdr(dev->drw_unrhdr);
@@ -662,18 +496,17 @@ static void drm_unload(struct drm_device *dev)
if (pci_disable_busmaster(dev->device))
DRM_ERROR("Request to disable bus-master failed.\n");
-#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
+ mtx_destroy(&dev->tsk_lock);
mtx_destroy(&dev->drw_lock);
- mtx_destroy(&dev->irq_lock);
mtx_destroy(&dev->vbl_lock);
+ mtx_destroy(&dev->irq_lock);
mtx_destroy(&dev->dev_lock);
-#endif
}
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 ) \
@@ -685,13 +518,13 @@ int drm_version(struct drm_device *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;
}
@@ -703,17 +536,15 @@ int drm_open(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p)
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();
-#ifdef __FreeBSD__
device_busy(dev->device);
-#endif
- if ( !dev->open_count++ )
+ if (!dev->open_count++)
retcode = drm_firstopen(dev);
DRM_UNLOCK();
}
@@ -721,103 +552,76 @@ int drm_open(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p)
return retcode;
}
-int drm_close(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p)
+void drm_close(void *data)
{
- struct drm_device *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
*/
-#ifdef __FreeBSD__
- 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
+ /* Contention */
retcode = mtx_sleep((void *)&dev->lock.lock_queue,
&dev->dev_lock, PZERO | PCATCH, "drmlk2", 0);
-#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__)
- 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);
@@ -825,18 +629,13 @@ int drm_close(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p)
* End inline drm_release
*/
-done:
- atomic_inc( &dev->counts[_DRM_STAT_CLOSES] );
-#ifdef __FreeBSD__
+ 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.
@@ -850,55 +649,34 @@ int drm_ioctl(struct cdev *kdev, u_long cmd, caddr_t data, int flags,
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);
+ retcode = devfs_get_cdevpriv((void **)&file_priv);
DRM_UNLOCK();
- if (file_priv == NULL) {
+ if (retcode != 0) {
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;
-#ifdef __FreeBSD__
- 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;
-#ifdef __FreeBSD__
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__ */
-#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) {
@@ -911,18 +689,18 @@ int drm_ioctl(struct cdev *kdev, u_long cmd, caddr_t data, int flags,
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;
}
diff --git a/bsd-core/drm_fops.c b/bsd-core/drm_fops.c
index 062b1d59..6850f489 100644
--- a/bsd-core/drm_fops.c
+++ b/bsd-core/drm_fops.c
@@ -36,31 +36,12 @@
#include "drmP.h"
-drm_file_t *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;
-#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);
-
- TAILQ_FOREACH(priv, &dev->files, link)
- if (priv->pid == pid && priv->uid == uid)
- return priv;
- return NULL;
-}
-
/* 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,
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)
@@ -69,50 +50,44 @@ int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m);
+ priv = malloc(sizeof(*priv), M_DRM, M_NOWAIT | M_ZERO);
+ if (priv == NULL) {
+ return ENOMEM;
+ }
+
+ retcode = devfs_set_cdevpriv(priv, drm_close);
+ if (retcode != 0) {
+ free(priv, M_DRM);
+ return retcode;
+ }
+
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) {
+ priv->dev = dev;
+ priv->uid = p->td_ucred->cr_svuid;
+ priv->pid = p->td_proc->p_pid;
+ 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) {
+ devfs_clear_cdevpriv();
+ free(priv, M_DRM);
DRM_UNLOCK();
- return ENOMEM;
- }
-#if __FreeBSD_version >= 500000
- priv->uid = p->td_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;
- }
+ return retcode;
}
+ }
- /* first opener automatically becomes master */
- priv->master = TAILQ_EMPTY(&dev->files);
+ /* first opener automatically becomes master */
+ priv->master = TAILQ_EMPTY(&dev->files);
- TAILQ_INSERT_TAIL(&dev->files, priv, link);
- }
+ TAILQ_INSERT_TAIL(&dev->files, priv, link);
DRM_UNLOCK();
-#ifdef __FreeBSD__
kdev->si_drv1 = dev;
-#endif
return 0;
}
diff --git a/bsd-core/drm_ioctl.c b/bsd-core/drm_ioctl.c
index c00e63c2..0523291e 100644
--- a/bsd-core/drm_ioctl.c
+++ b/bsd-core/drm_ioctl.c
@@ -44,7 +44,7 @@
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))
@@ -61,7 +61,7 @@ int drm_getunique(struct drm_device *dev, void *data,
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;
@@ -141,7 +141,7 @@ drm_set_busid(struct drm_device *dev)
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;
@@ -155,7 +155,7 @@ int drm_getmap(struct drm_device *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;
@@ -178,16 +178,15 @@ 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)
{
- 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;
@@ -205,21 +204,20 @@ int drm_getclient(struct drm_device *dev, void *data,
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;
@@ -235,8 +233,8 @@ int drm_getstats(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)
{
- 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
@@ -245,8 +243,8 @@ int drm_setversion(struct drm_device *dev, void *data,
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 ||
@@ -265,9 +263,9 @@ int drm_setversion(struct drm_device *dev, void *data,
}
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;
}
diff --git a/bsd-core/drm_irq.c b/bsd-core/drm_irq.c
index 6e21d41c..00d4b31e 100644
--- a/bsd-core/drm_irq.c
+++ b/bsd-core/drm_irq.c
@@ -38,7 +38,7 @@ static void drm_locked_task(void *context, int pending __unused);
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,22 +49,20 @@ int drm_irq_by_busid(struct drm_device *dev, void *data,
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)
{
struct drm_device *dev = arg;
DRM_SPINLOCK(&dev->irq_lock);
- dev->driver.irq_handler(arg);
+ dev->driver->irq_handler(arg);
DRM_SPINUNLOCK(&dev->irq_lock);
}
-#endif
static void vblank_disable_fn(void *arg)
{
@@ -81,17 +79,18 @@ static void vblank_disable_fn(void *arg)
}
callout_deactivate(&dev->vblank_disable_timer);
+ DRM_DEBUG("vblank_disable_allowed=%d\n", dev->vblank_disable_allowed);
if (!dev->vblank_disable_allowed)
return;
for (i = 0; i < dev->num_crtcs; i++) {
- if (atomic_read(&dev->vblank_refcount[i]) == 0 &&
- dev->vblank_enabled[i]) {
+ if (atomic_read(&dev->vblank[i].refcount) == 0 &&
+ dev->vblank[i].enabled) {
DRM_DEBUG("disabling vblank on crtc %d\n", i);
- dev->last_vblank[i] =
- dev->driver.get_vblank_counter(dev, i);
- dev->driver.disable_vblank(dev, i);
- dev->vblank_enabled[i] = 0;
+ dev->vblank[i].last =
+ dev->driver->get_vblank_counter(dev, i);
+ dev->driver->disable_vblank(dev, i);
+ dev->vblank[i].enabled = 0;
}
}
}
@@ -102,7 +101,7 @@ static void drm_vblank_cleanup(struct drm_device *dev)
/* Bail if the driver didn't call drm_vblank_init() */
if (dev->num_crtcs == 0)
- return;
+ return;
DRM_SPINLOCK_IRQSAVE(&dev->vbl_lock, irqflags);
callout_stop(&dev->vblank_disable_timer);
@@ -112,20 +111,8 @@ static void drm_vblank_cleanup(struct drm_device *dev)
vblank_disable_fn((void *)dev);
- drm_free(dev->vbl_queue, sizeof(*dev->vbl_queue) * dev->num_crtcs,
- DRM_MEM_DRIVER);
- drm_free(dev->vbl_sigs, sizeof(*dev->vbl_sigs) * dev->num_crtcs,
+ drm_free(dev->vblank, sizeof(struct drm_vblank_info) * dev->num_crtcs,
DRM_MEM_DRIVER);
- drm_free(dev->_vblank_count, sizeof(*dev->_vblank_count) *
- dev->num_crtcs, DRM_MEM_DRIVER);
- drm_free(dev->vblank_refcount, sizeof(*dev->vblank_refcount) *
- dev->num_crtcs, DRM_MEM_DRIVER);
- drm_free(dev->vblank_enabled, sizeof(*dev->vblank_enabled) *
- dev->num_crtcs, DRM_MEM_DRIVER);
- drm_free(dev->last_vblank, sizeof(*dev->last_vblank) * dev->num_crtcs,
- DRM_MEM_DRIVER);
- drm_free(dev->vblank_inmodeset, sizeof(*dev->vblank_inmodeset) *
- dev->num_crtcs, DRM_MEM_DRIVER);
dev->num_crtcs = 0;
}
@@ -138,46 +125,19 @@ int drm_vblank_init(struct drm_device *dev, int num_crtcs)
atomic_set(&dev->vbl_signal_pending, 0);
dev->num_crtcs = num_crtcs;
- dev->vbl_queue = drm_alloc(sizeof(wait_queue_head_t) * num_crtcs,
+ dev->vblank = drm_calloc(num_crtcs, sizeof(struct drm_vblank_info),
DRM_MEM_DRIVER);
- if (!dev->vbl_queue)
- goto err;
-
- dev->vbl_sigs = drm_alloc(sizeof(struct drm_vbl_sig) * num_crtcs,
- DRM_MEM_DRIVER);
- if (!dev->vbl_sigs)
- goto err;
-
- dev->_vblank_count = drm_alloc(sizeof(atomic_t) * num_crtcs,
- DRM_MEM_DRIVER);
- if (!dev->_vblank_count)
- goto err;
-
- dev->vblank_refcount = drm_alloc(sizeof(atomic_t) * num_crtcs,
- DRM_MEM_DRIVER);
- if (!dev->vblank_refcount)
- goto err;
-
- dev->vblank_enabled = drm_calloc(num_crtcs, sizeof(int),
- DRM_MEM_DRIVER);
- if (!dev->vblank_enabled)
- goto err;
-
- dev->last_vblank = drm_calloc(num_crtcs, sizeof(u32), DRM_MEM_DRIVER);
- if (!dev->last_vblank)
+ if (!dev->vblank)
goto err;
- dev->vblank_inmodeset = drm_calloc(num_crtcs, sizeof(int),
- DRM_MEM_DRIVER);
- if (!dev->vblank_inmodeset)
- goto err;
+ DRM_DEBUG("\n");
/* Zero per-crtc vblank stuff */
for (i = 0; i < num_crtcs; i++) {
- DRM_INIT_WAITQUEUE(&dev->vbl_queue[i]);
- TAILQ_INIT(&dev->vbl_sigs[i]);
- atomic_set(&dev->_vblank_count[i], 0);
- atomic_set(&dev->vblank_refcount[i], 0);
+ 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;
@@ -192,14 +152,11 @@ err:
int drm_irq_install(struct drm_device *dev)
{
int retcode;
-#ifdef __NetBSD__
- pci_intr_handle_t ih;
-#endif
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) {
@@ -210,12 +167,11 @@ int drm_irq_install(struct drm_device *dev)
dev->context_flag = 0;
- /* Before installing handler */
- dev->driver.irq_preinstall(dev);
+ /* Before installing handler */
+ dev->driver->irq_preinstall(dev);
DRM_UNLOCK();
- /* Install handler */
-#ifdef __FreeBSD__
+ /* Install handler */
dev->irqrid = 0;
dev->irqr = bus_alloc_resource_any(dev->device, SYS_RES_IRQ,
&dev->irqrid, RF_SHAREABLE);
@@ -234,22 +190,10 @@ int drm_irq_install(struct drm_device *dev)
#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();
TASK_INIT(&dev->locked_task, 0, drm_locked_task, dev);
@@ -257,44 +201,35 @@ int drm_irq_install(struct drm_device *dev)
err:
DRM_LOCK();
dev->irq_enabled = 0;
-#ifdef ___FreeBSD__
if (dev->irqrid != 0) {
bus_release_resource(dev->device, SYS_RES_IRQ, dev->irqrid,
dev->irqr);
dev->irqrid = 0;
}
-#endif
DRM_UNLOCK();
return retcode;
}
int drm_irq_uninstall(struct drm_device *dev)
{
-#ifdef __FreeBSD__
int irqrid;
-#endif
if (!dev->irq_enabled)
return EINVAL;
dev->irq_enabled = 0;
-#ifdef __FreeBSD__
irqrid = dev->irqrid;
dev->irqrid = 0;
-#endif
- DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, dev->irq );
+ DRM_DEBUG("irq=%d\n", dev->irq);
- dev->driver.irq_uninstall(dev);
+ dev->driver->irq_uninstall(dev);
-#ifdef __FreeBSD__
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
+
drm_vblank_cleanup(dev);
return 0;
@@ -302,22 +237,22 @@ int drm_irq_uninstall(struct drm_device *dev)
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);
@@ -330,7 +265,7 @@ int drm_control(struct drm_device *dev, void *data, struct drm_file *file_priv)
u32 drm_vblank_count(struct drm_device *dev, int crtc)
{
- return atomic_read(&dev->_vblank_count[crtc]);
+ return atomic_read(&dev->vblank[crtc].count);
}
static void drm_update_vblank_count(struct drm_device *dev, int crtc)
@@ -344,19 +279,19 @@ static void drm_update_vblank_count(struct drm_device *dev, int crtc)
* 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->last_vblank[crtc];
- if (cur_vblank < dev->last_vblank[crtc]) {
+ 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("last_vblank[%d]=0x%x, cur_vblank=0x%x => diff=0x%x\n",
- crtc, dev->last_vblank[crtc], cur_vblank, diff);
+ 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_count[crtc]);
+ atomic_add(diff, &dev->vblank[crtc].count);
}
int drm_vblank_get(struct drm_device *dev, int crtc)
@@ -366,14 +301,14 @@ int drm_vblank_get(struct drm_device *dev, int crtc)
DRM_SPINLOCK_IRQSAVE(&dev->vbl_lock, irqflags);
/* Going from 0->1 means we have to enable interrupts again */
- atomic_add_acq_int(&dev->vblank_refcount[crtc], 1);
- if (dev->vblank_refcount[crtc] == 1 &&
- !dev->vblank_enabled[crtc]) {
- ret = dev->driver.enable_vblank(dev, crtc);
+ 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);
if (ret)
- atomic_dec(&dev->vblank_refcount[crtc]);
+ atomic_dec(&dev->vblank[crtc].refcount);
else {
- dev->vblank_enabled[crtc] = 1;
+ dev->vblank[crtc].enabled = 1;
drm_update_vblank_count(dev, crtc);
}
}
@@ -388,8 +323,8 @@ void drm_vblank_put(struct drm_device *dev, int crtc)
DRM_SPINLOCK_IRQSAVE(&dev->vbl_lock, irqflags);
/* Last user schedules interrupt disable */
- atomic_subtract_acq_int(&dev->vblank_refcount[crtc], 1);
- if (dev->vblank_refcount[crtc] == 0)
+ atomic_subtract_acq_int(&dev->vblank[crtc].refcount, 1);
+ if (dev->vblank[crtc].refcount == 0)
callout_reset(&dev->vblank_disable_timer, 5 * DRM_HZ,
(timeout_t *)vblank_disable_fn, (void *)dev);
DRM_SPINUNLOCK_IRQRESTORE(&dev->vbl_lock, irqflags);
@@ -402,11 +337,13 @@ int drm_modeset_ctl(struct drm_device *dev, void *data,
unsigned long irqflags;
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;
+ goto out;
crtc = modeset->crtc;
+ DRM_DEBUG("crtc=%d\n", crtc);
if (crtc >= dev->num_crtcs) {
ret = EINVAL;
goto out;
@@ -421,16 +358,18 @@ int drm_modeset_ctl(struct drm_device *dev, void *data,
*/
switch (modeset->cmd) {
case _DRM_PRE_MODESET:
- if (!dev->vblank_inmodeset[crtc]) {
- dev->vblank_inmodeset[crtc] = 1;
+ DRM_DEBUG("pre-modeset\n");
+ if (!dev->vblank[crtc].inmodeset) {
+ dev->vblank[crtc].inmodeset = 1;
drm_vblank_get(dev, crtc);
}
break;
case _DRM_POST_MODESET:
- if (dev->vblank_inmodeset[crtc]) {
+ DRM_DEBUG("post-modeset\n");
+ if (dev->vblank[crtc].inmodeset) {
DRM_SPINLOCK_IRQSAVE(&dev->vbl_lock, irqflags);
dev->vblank_disable_allowed = 1;
- dev->vblank_inmodeset[crtc] = 0;
+ dev->vblank[crtc].inmodeset = 0;
DRM_SPINUNLOCK_IRQRESTORE(&dev->vbl_lock, irqflags);
drm_vblank_put(dev, crtc);
}
@@ -446,7 +385,7 @@ out:
int drm_wait_vblank(struct drm_device *dev, void *data, struct drm_file *file_priv)
{
- drm_wait_vblank_t *vblwait = data;
+ union drm_wait_vblank *vblwait = data;
int ret = 0;
int flags, seq, crtc;
@@ -469,7 +408,7 @@ int drm_wait_vblank(struct drm_device *dev, void *data, struct drm_file *file_pr
ret = drm_vblank_get(dev, crtc);
if (ret)
- return ret;
+ return ret;
seq = drm_vblank_count(dev, crtc);
switch (vblwait->request.type & _DRM_VBLANK_TYPES_MASK) {
@@ -511,7 +450,7 @@ int drm_wait_vblank(struct drm_device *dev, void *data, struct drm_file *file_pr
DRM_LOCK();
/* shared code returns -errno */
- DRM_WAIT_ON(ret, dev->vbl_queue[crtc], 3 * DRM_HZ,
+ DRM_WAIT_ON(ret, dev->vblank[crtc].queue, 3 * DRM_HZ,
((drm_vblank_count(dev, crtc)
- vblwait->request.sequence) <= (1 << 23)));
DRM_UNLOCK();
@@ -546,7 +485,7 @@ void drm_vbl_send_signals(struct drm_device *dev, int crtc )
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);
@@ -561,8 +500,8 @@ void drm_vbl_send_signals(struct drm_device *dev, int crtc )
void drm_handle_vblank(struct drm_device *dev, int crtc)
{
- atomic_inc(&dev->_vblank_count[crtc]);
- DRM_WAKEUP(&dev->vbl_queue[crtc]);
+ atomic_inc(&dev->vblank[crtc].count);
+ DRM_WAKEUP(&dev->vblank[crtc].queue);
drm_vbl_send_signals(dev, crtc);
}
@@ -574,7 +513,7 @@ static void drm_locked_task(void *context, int pending __unused)
DRM_LOCK(); /* XXX drm_lock_take() should do it's own locking */
if (dev->locked_task_call == NULL ||
- drm_lock_take(&dev->lock.hw_lock->lock, DRM_KERNEL_CONTEXT) == 0) {
+ drm_lock_take(&dev->lock, DRM_KERNEL_CONTEXT) == 0) {
DRM_UNLOCK();
DRM_SPINUNLOCK(&dev->tsk_lock);
return;
@@ -588,7 +527,7 @@ static void drm_locked_task(void *context, int pending __unused)
dev->locked_task_call(dev);
- drm_lock_free(dev, &dev->lock.hw_lock->lock, DRM_KERNEL_CONTEXT);
+ drm_lock_free(&dev->lock, DRM_KERNEL_CONTEXT);
dev->locked_task_call = NULL;
diff --git a/bsd-core/drm_lock.c b/bsd-core/drm_lock.c
index 80ebb71d..685b0ea3 100644
--- a/bsd-core/drm_lock.c
+++ b/bsd-core/drm_lock.c
@@ -49,89 +49,28 @@
#include "drmP.h"
-int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context)
-{
- 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_device *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(struct drm_device *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;
-}
-
int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
{
- drm_lock_t *lock = data;
- int ret = 0;
+ struct drm_lock *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]);
@@ -139,13 +78,8 @@ int drm_lock(struct drm_device *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);
-#else
- ret = tsleep((void *)&dev->lock.lock_queue, PZERO | PCATCH,
- "drmlk2", 0);
-#endif
if (ret != 0)
break;
}
@@ -157,16 +91,16 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
/* 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(struct drm_device *dev, void *data, struct drm_file *file_priv)
{
- drm_lock_t *lock = data;
+ struct drm_lock *lock = data;
if (lock->context == DRM_KERNEL_CONTEXT) {
DRM_ERROR("Process %d using kernel context %d\n",
@@ -190,12 +124,77 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
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;
+}
diff --git a/bsd-core/drm_memory.c b/bsd-core/drm_memory.c
index 05343f3f..2dfd2b8e 100644
--- a/bsd-core/drm_memory.c
+++ b/bsd-core/drm_memory.c
@@ -42,9 +42,6 @@ MALLOC_DEFINE(M_DRM, "drm", "DRM Data Structures");
void drm_mem_init(void)
{
-#if defined(__NetBSD__) || defined(__OpenBSD__)
- malloc_type_attach(M_DRM);
-#endif
}
void drm_mem_uninit(void)
@@ -69,7 +66,7 @@ void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area)
if (pt == NULL)
return NULL;
if (oldpt && oldsize) {
- memcpy(pt, oldpt, oldsize);
+ memcpy(pt, oldpt, DRM_MIN(oldsize,size));
free(oldpt, M_DRM);
}
return pt;
@@ -80,29 +77,21 @@ void drm_free(void *pt, size_t size, int area)
free(pt, M_DRM);
}
+void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map)
+{
+ return pmap_mapdev_attr(map->offset, map->size, PAT_WRITE_COMBINING);
+}
+
void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map)
{
-#ifdef __FreeBSD__
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)
{
-#ifdef __FreeBSD__
pmap_unmapdev((vm_offset_t) map->handle, map->size);
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
- bus_space_unmap(map->bst, map->bsh, map->size);
-#endif
}
-#ifdef __FreeBSD__
int
drm_mtrr_add(unsigned long offset, size_t size, int flags)
{
@@ -130,30 +119,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
diff --git a/bsd-core/drm_pci.c b/bsd-core/drm_pci.c
index f23b2a5b..e21715b2 100644
--- a/bsd-core/drm_pci.c
+++ b/bsd-core/drm_pci.c
@@ -34,7 +34,6 @@
/** \name PCI memory */
/*@{*/
-#if defined(__FreeBSD__)
static void
drm_pci_busdma_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
{
@@ -46,7 +45,6 @@ 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
@@ -70,8 +68,14 @@ drm_pci_alloc(struct drm_device *dev, size_t size,
if (dmah == NULL)
return NULL;
-#ifdef __FreeBSD__
- DRM_UNLOCK();
+ /* 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");
+
ret = bus_dma_tag_create(NULL, align, 0, /* tag, align, boundary */
maxaddr, BUS_SPACE_MAXADDR, /* lowaddr, highaddr */
NULL, NULL, /* filtfunc, filtfuncargs */
@@ -80,7 +84,6 @@ drm_pci_alloc(struct drm_device *dev, size_t size,
&dmah->tag);
if (ret != 0) {
free(dmah, M_DRM);
- DRM_LOCK();
return NULL;
}
@@ -89,10 +92,9 @@ drm_pci_alloc(struct drm_device *dev, size_t size,
if (ret != 0) {
bus_dma_tag_destroy(dmah->tag);
free(dmah, M_DRM);
- DRM_LOCK();
return NULL;
}
- DRM_LOCK();
+
ret = bus_dmamap_load(dmah->tag, dmah->map, dmah->vaddr, size,
drm_pci_busdma_callback, dmah, 0);
if (ret != 0) {
@@ -101,24 +103,6 @@ drm_pci_alloc(struct drm_device *dev, size_t size,
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);
- 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;
}
@@ -132,12 +116,8 @@ drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah)
if (dmah == NULL)
return;
-#if defined(__FreeBSD__)
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);
}
diff --git a/bsd-core/drm_scatter.c b/bsd-core/drm_scatter.c
index 3ebd4628..550e6f88 100644
--- a/bsd-core/drm_scatter.c
+++ b/bsd-core/drm_scatter.c
@@ -45,27 +45,27 @@ void drm_sg_cleanup(drm_sg_mem_t *entry)
free(entry, M_DRM);
}
-int drm_sg_alloc(struct drm_device * dev, drm_scatter_gather_t * request)
+int drm_sg_alloc(struct drm_device * dev, struct drm_scatter_gather * request)
{
drm_sg_mem_t *entry;
unsigned long pages;
int i;
- if ( dev->sg )
+ if (dev->sg)
return EINVAL;
entry = malloc(sizeof(*entry), M_DRM, M_WAITOK | M_ZERO);
- if ( !entry )
+ 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,
M_WAITOK | M_ZERO);
- if ( !entry->busaddr ) {
+ if (!entry->busaddr) {
drm_sg_cleanup(entry);
return ENOMEM;
}
@@ -81,7 +81,7 @@ int drm_sg_alloc(struct drm_device * dev, drm_scatter_gather_t * request)
entry->busaddr[i] = vtophys(entry->handle + i * PAGE_SIZE);
}
- DRM_DEBUG( "sg alloc handle = %08lx\n", entry->handle );
+ DRM_DEBUG("sg alloc handle = %08lx\n", entry->handle);
entry->virtual = (void *)entry->handle;
request->handle = entry->handle;
@@ -101,10 +101,10 @@ int drm_sg_alloc(struct drm_device * dev, drm_scatter_gather_t * request)
int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
- drm_scatter_gather_t *request = data;
+ struct drm_scatter_gather *request = data;
int ret;
- DRM_DEBUG( "%s\n", __FUNCTION__ );
+ DRM_DEBUG("%s\n", __FUNCTION__);
ret = drm_sg_alloc(dev, request);
return ret;
@@ -112,7 +112,7 @@ int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
int drm_sg_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
{
- drm_scatter_gather_t *request = data;
+ struct drm_scatter_gather *request = data;
drm_sg_mem_t *entry;
DRM_LOCK();
@@ -120,10 +120,10 @@ int drm_sg_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
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);
diff --git a/bsd-core/drm_sysctl.c b/bsd-core/drm_sysctl.c
index a6adf0fc..f9cfd9cf 100644
--- a/bsd-core/drm_sysctl.c
+++ b/bsd-core/drm_sysctl.c
@@ -132,7 +132,7 @@ static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
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) {
@@ -268,7 +268,7 @@ done:
static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
{
struct drm_device *dev = arg1;
- drm_file_t *priv, *tempprivs;
+ struct drm_file *priv, *tempprivs;
char buf[128];
int retcode;
int privcount, i;
@@ -279,7 +279,7 @@ 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, M_DRM, M_NOWAIT);
if (tempprivs == NULL) {
DRM_UNLOCK();
return ENOMEM;
diff --git a/bsd-core/drm_vm.c b/bsd-core/drm_vm.c
index 9950c37e..8ee49a28 100644
--- a/bsd-core/drm_vm.c
+++ b/bsd-core/drm_vm.c
@@ -28,34 +28,24 @@
#include "drmP.h"
#include "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
{
struct drm_device *dev = drm_get_device_from_kdev(kdev);
+ struct drm_file *file_priv;
drm_local_map_t *map;
- drm_file_t *priv;
- drm_map_type_t type;
-#ifdef __FreeBSD__
+ 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);
+ TAILQ_FOREACH(file_priv, &dev->files, link)
+ if (file_priv->pid == curthread->td_proc->p_pid &&
+ file_priv->uid == curthread->td_ucred->cr_svuid &&
+ file_priv->authenticated == 1)
+ break;
DRM_UNLOCK();
- if (priv == NULL) {
- DRM_ERROR("can't find authenticator\n");
- return EINVAL;
- }
- if (!priv->authenticated)
+ if (!file_priv)
return EACCES;
if (dev->dma && offset >= 0 && offset < ptoa(dev->dma->page_count)) {
@@ -68,12 +58,8 @@ paddr_t drm_mmap(dev_t kdev, off_t offset, int prot)
unsigned long phys = dma->pagelist[page];
DRM_SPINUNLOCK(&dev->dma_lock);
-#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
*paddr = phys;
return 0;
-#else
- return atop(phys);
-#endif
} else {
DRM_SPINUNLOCK(&dev->dma_lock);
return -1;
@@ -124,11 +110,7 @@ paddr_t drm_mmap(dev_t kdev, off_t offset, int prot)
return -1; /* This should never happen. */
}
-#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
*paddr = phys;
return 0;
-#else
- return atop(phys);
-#endif
}
diff --git a/bsd-core/i915_drv.c b/bsd-core/i915_drv.c
index c19ef5db..def35f0b 100644
--- a/bsd-core/i915_drv.c
+++ b/bsd-core/i915_drv.c
@@ -68,40 +68,36 @@ static int i915_resume(device_t nbdev)
static void i915_configure(struct drm_device *dev)
{
- dev->driver.buf_priv_size = sizeof(drm_i915_private_t);
- dev->driver.load = i915_driver_load;
- dev->driver.unload = i915_driver_unload;
- dev->driver.firstopen = i915_driver_firstopen;
- dev->driver.preclose = i915_driver_preclose;
- dev->driver.lastclose = i915_driver_lastclose;
- dev->driver.device_is_agp = i915_driver_device_is_agp;
- dev->driver.get_vblank_counter = i915_get_vblank_counter;
- dev->driver.enable_vblank = i915_enable_vblank;
- dev->driver.disable_vblank = i915_disable_vblank;
- dev->driver.irq_preinstall = i915_driver_irq_preinstall;
- dev->driver.irq_postinstall = i915_driver_irq_postinstall;
- dev->driver.irq_uninstall = i915_driver_irq_uninstall;
- dev->driver.irq_handler = i915_driver_irq_handler;
-
- dev->driver.ioctls = i915_ioctls;
- dev->driver.max_ioctl = i915_max_ioctl;
-
- dev->driver.name = DRIVER_NAME;
- dev->driver.desc = DRIVER_DESC;
- dev->driver.date = DRIVER_DATE;
- dev->driver.major = DRIVER_MAJOR;
- dev->driver.minor = DRIVER_MINOR;
- dev->driver.patchlevel = DRIVER_PATCHLEVEL;
-
- dev->driver.use_agp = 1;
- dev->driver.require_agp = 1;
- dev->driver.use_mtrr = 1;
- dev->driver.use_irq = 1;
- dev->driver.use_vbl_irq = 1;
- dev->driver.use_vbl_irq2 = 1;
+ dev->driver->driver_features =
+ DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
+ DRIVER_HAVE_IRQ;
+
+ dev->driver->buf_priv_size = sizeof(drm_i915_private_t);
+ dev->driver->load = i915_driver_load;
+ dev->driver->unload = i915_driver_unload;
+ dev->driver->firstopen = i915_driver_firstopen;
+ dev->driver->preclose = i915_driver_preclose;
+ dev->driver->lastclose = i915_driver_lastclose;
+ dev->driver->device_is_agp = i915_driver_device_is_agp;
+ dev->driver->get_vblank_counter = i915_get_vblank_counter;
+ dev->driver->enable_vblank = i915_enable_vblank;
+ dev->driver->disable_vblank = i915_disable_vblank;
+ dev->driver->irq_preinstall = i915_driver_irq_preinstall;
+ dev->driver->irq_postinstall = i915_driver_irq_postinstall;
+ dev->driver->irq_uninstall = i915_driver_irq_uninstall;
+ dev->driver->irq_handler = i915_driver_irq_handler;
+
+ dev->driver->ioctls = i915_ioctls;
+ dev->driver->max_ioctl = i915_max_ioctl;
+
+ dev->driver->name = DRIVER_NAME;
+ dev->driver->desc = DRIVER_DESC;
+ dev->driver->date = DRIVER_DATE;
+ dev->driver->major = DRIVER_MAJOR;
+ dev->driver->minor = DRIVER_MINOR;
+ dev->driver->patchlevel = DRIVER_PATCHLEVEL;
}
-#ifdef __FreeBSD__
static int
i915_probe(device_t dev)
{
@@ -114,17 +110,33 @@ i915_attach(device_t nbdev)
struct drm_device *dev = device_get_softc(nbdev);
bzero(dev, sizeof(struct drm_device));
+
+ dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO);
i915_configure(dev);
+
return drm_attach(nbdev, i915_pciidlist);
}
+static int
+i915_detach(device_t nbdev)
+{
+ struct drm_device *dev = device_get_softc(nbdev);
+ int ret;
+
+ ret = drm_detach(nbdev);
+
+ free(dev->driver, M_DRM);
+
+ return ret;
+}
+
static device_method_t i915_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, i915_probe),
DEVMETHOD(device_attach, i915_attach),
DEVMETHOD(device_suspend, i915_suspend),
DEVMETHOD(device_resume, i915_resume),
- DEVMETHOD(device_detach, drm_detach),
+ DEVMETHOD(device_detach, i915_detach),
{ 0, 0 }
};
@@ -146,7 +158,3 @@ DRIVER_MODULE(i915, vgapci, i915_driver, drm_devclass, 0, 0);
DRIVER_MODULE(i915, agp, i915_driver, drm_devclass, 0, 0);
#endif
MODULE_DEPEND(i915, drm, 1, 1, 1);
-
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-CFDRIVER_DECL(i915, DV_TTY, NULL);
-#endif
diff --git a/bsd-core/mach64_drv.c b/bsd-core/mach64_drv.c
index 06e0133d..adb83d3a 100644
--- a/bsd-core/mach64_drv.c
+++ b/bsd-core/mach64_drv.c
@@ -46,36 +46,32 @@ static drm_pci_id_list_t mach64_pciidlist[] = {
static void mach64_configure(struct drm_device *dev)
{
- dev->driver.buf_priv_size = 1; /* No dev_priv */
- dev->driver.lastclose = mach64_driver_lastclose;
- dev->driver.get_vblank_counter = mach64_get_vblank_counter;
- dev->driver.enable_vblank = mach64_enable_vblank;
- dev->driver.disable_vblank = mach64_disable_vblank;
- dev->driver.irq_preinstall = mach64_driver_irq_preinstall;
- dev->driver.irq_postinstall = mach64_driver_irq_postinstall;
- dev->driver.irq_uninstall = mach64_driver_irq_uninstall;
- dev->driver.irq_handler = mach64_driver_irq_handler;
- dev->driver.dma_ioctl = mach64_dma_buffers;
-
- dev->driver.ioctls = mach64_ioctls;
- dev->driver.max_ioctl = mach64_max_ioctl;
-
- dev->driver.name = DRIVER_NAME;
- dev->driver.desc = DRIVER_DESC;
- dev->driver.date = DRIVER_DATE;
- dev->driver.major = DRIVER_MAJOR;
- dev->driver.minor = DRIVER_MINOR;
- dev->driver.patchlevel = DRIVER_PATCHLEVEL;
-
- dev->driver.use_agp = 1;
- dev->driver.use_mtrr = 1;
- dev->driver.use_pci_dma = 1;
- dev->driver.use_dma = 1;
- dev->driver.use_irq = 1;
- dev->driver.use_vbl_irq = 1;
+ dev->driver->driver_features =
+ DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
+ DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ;
+
+ dev->driver->buf_priv_size = 1; /* No dev_priv */
+ dev->driver->lastclose = mach64_driver_lastclose;
+ dev->driver->get_vblank_counter = mach64_get_vblank_counter;
+ dev->driver->enable_vblank = mach64_enable_vblank;
+ dev->driver->disable_vblank = mach64_disable_vblank;
+ dev->driver->irq_preinstall = mach64_driver_irq_preinstall;
+ dev->driver->irq_postinstall = mach64_driver_irq_postinstall;
+ dev->driver->irq_uninstall = mach64_driver_irq_uninstall;
+ dev->driver->irq_handler = mach64_driver_irq_handler;
+ dev->driver->dma_ioctl = mach64_dma_buffers;
+
+ dev->driver->ioctls = mach64_ioctls;
+ dev->driver->max_ioctl = mach64_max_ioctl;
+
+ dev->driver->name = DRIVER_NAME;
+ dev->driver->desc = DRIVER_DESC;
+ dev->driver->date = DRIVER_DATE;
+ dev->driver->major = DRIVER_MAJOR;
+ dev->driver->minor = DRIVER_MINOR;
+ dev->driver->patchlevel = DRIVER_PATCHLEVEL;
}
-#ifdef __FreeBSD__
static int
mach64_probe(device_t dev)
{
@@ -88,15 +84,31 @@ mach64_attach(device_t nbdev)
struct drm_device *dev = device_get_softc(nbdev);
bzero(dev, sizeof(struct drm_device));
+
+ dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO);
mach64_configure(dev);
+
return drm_attach(nbdev, mach64_pciidlist);
}
+static int
+mach64_detach(device_t nbdev)
+{
+ struct drm_device *dev = device_get_softc(nbdev);
+ int ret;
+
+ ret = drm_detach(nbdev);
+
+ free(dev->driver, M_DRM);
+
+ return ret;
+}
+
static device_method_t mach64_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, mach64_probe),
DEVMETHOD(device_attach, mach64_attach),
- DEVMETHOD(device_detach, drm_detach),
+ DEVMETHOD(device_detach, mach64_detach),
{ 0, 0 }
};
@@ -114,7 +126,3 @@ DRIVER_MODULE(mach64, vgapci, mach64_driver, drm_devclass, 0, 0);
DRIVER_MODULE(mach64, pci, mach64_driver, drm_devclass, 0, 0);
#endif
MODULE_DEPEND(mach64, drm, 1, 1, 1);
-
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-CFDRIVER_DECL(mach64, DV_TTY, NULL);
-#endif
diff --git a/bsd-core/mga_drv.c b/bsd-core/mga_drv.c
index 15d8175c..5554236a 100644
--- a/bsd-core/mga_drv.c
+++ b/bsd-core/mga_drv.c
@@ -86,42 +86,36 @@ static int mga_driver_device_is_agp(struct drm_device * dev)
static void mga_configure(struct drm_device *dev)
{
- dev->driver.buf_priv_size = sizeof(drm_mga_buf_priv_t);
- dev->driver.load = mga_driver_load;
- dev->driver.unload = mga_driver_unload;
- dev->driver.lastclose = mga_driver_lastclose;
- dev->driver.get_vblank_counter = mga_get_vblank_counter;
- dev->driver.enable_vblank = mga_enable_vblank;
- dev->driver.disable_vblank = mga_disable_vblank;
- dev->driver.irq_preinstall = mga_driver_irq_preinstall;
- dev->driver.irq_postinstall = mga_driver_irq_postinstall;
- dev->driver.irq_uninstall = mga_driver_irq_uninstall;
- dev->driver.irq_handler = mga_driver_irq_handler;
- dev->driver.dma_ioctl = mga_dma_buffers;
- dev->driver.dma_quiescent = mga_driver_dma_quiescent;
- dev->driver.device_is_agp = mga_driver_device_is_agp;
-
- dev->driver.ioctls = mga_ioctls;
- dev->driver.max_ioctl = mga_max_ioctl;
-
- dev->driver.name = DRIVER_NAME;
- dev->driver.desc = DRIVER_DESC;
- dev->driver.date = DRIVER_DATE;
- dev->driver.major = DRIVER_MAJOR;
- dev->driver.minor = DRIVER_MINOR;
- dev->driver.patchlevel = DRIVER_PATCHLEVEL;
-
- dev->driver.use_agp = 1;
- dev->driver.require_agp = 1;
- dev->driver.use_mtrr = 1;
- dev->driver.use_dma = 1;
- dev->driver.use_irq = 1;
- dev->driver.use_vbl_irq = 1;
+ dev->driver->driver_features =
+ DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
+ DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ;
+
+ dev->driver->buf_priv_size = sizeof(drm_mga_buf_priv_t);
+ dev->driver->load = mga_driver_load;
+ dev->driver->unload = mga_driver_unload;
+ dev->driver->lastclose = mga_driver_lastclose;
+ dev->driver->get_vblank_counter = mga_get_vblank_counter;
+ dev->driver->enable_vblank = mga_enable_vblank;
+ dev->driver->disable_vblank = mga_disable_vblank;
+ dev->driver->irq_preinstall = mga_driver_irq_preinstall;
+ dev->driver->irq_postinstall = mga_driver_irq_postinstall;
+ dev->driver->irq_uninstall = mga_driver_irq_uninstall;
+ dev->driver->irq_handler = mga_driver_irq_handler;
+ dev->driver->dma_ioctl = mga_dma_buffers;
+ dev->driver->dma_quiescent = mga_driver_dma_quiescent;
+ dev->driver->device_is_agp = mga_driver_device_is_agp;
+
+ dev->driver->ioctls = mga_ioctls;
+ dev->driver->max_ioctl = mga_max_ioctl;
+
+ dev->driver->name = DRIVER_NAME;
+ dev->driver->desc = DRIVER_DESC;
+ dev->driver->date = DRIVER_DATE;
+ dev->driver->major = DRIVER_MAJOR;
+ dev->driver->minor = DRIVER_MINOR;
+ dev->driver->patchlevel = DRIVER_PATCHLEVEL;
}
-
-
-#ifdef __FreeBSD__
static int
mga_probe(device_t dev)
{
@@ -134,15 +128,31 @@ mga_attach(device_t nbdev)
struct drm_device *dev = device_get_softc(nbdev);
bzero(dev, sizeof(struct drm_device));
+
+ dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO);
mga_configure(dev);
+
return drm_attach(nbdev, mga_pciidlist);
}
+static int
+mga_detach(device_t nbdev)
+{
+ struct drm_device *dev = device_get_softc(nbdev);
+ int ret;
+
+ ret = drm_detach(nbdev);
+
+ free(dev->driver, M_DRM);
+
+ return ret;
+}
+
static device_method_t mga_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, mga_probe),
DEVMETHOD(device_attach, mga_attach),
- DEVMETHOD(device_detach, drm_detach),
+ DEVMETHOD(device_detach, mga_detach),
{ 0, 0 }
};
@@ -160,12 +170,3 @@ DRIVER_MODULE(mga, vgapci, mga_driver, drm_devclass, 0, 0);
DRIVER_MODULE(mga, pci, mga_driver, drm_devclass, 0, 0);
#endif
MODULE_DEPEND(mga, drm, 1, 1, 1);
-
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-#ifdef _LKM
-CFDRIVER_DECL(mga, DV_TTY, NULL);
-#else
-CFATTACH_DECL(mga, sizeof(struct drm_device), drm_probe, drm_attach, drm_detach,
- drm_activate);
-#endif
-#endif
diff --git a/bsd-core/r128_drv.c b/bsd-core/r128_drv.c
index b149d512..4c20af4d 100644
--- a/bsd-core/r128_drv.c
+++ b/bsd-core/r128_drv.c
@@ -44,38 +44,33 @@ static drm_pci_id_list_t r128_pciidlist[] = {
static void r128_configure(struct drm_device *dev)
{
- dev->driver.buf_priv_size = sizeof(drm_r128_buf_priv_t);
- dev->driver.preclose = r128_driver_preclose;
- dev->driver.lastclose = r128_driver_lastclose;
- dev->driver.get_vblank_counter = r128_get_vblank_counter;
- dev->driver.enable_vblank = r128_enable_vblank;
- dev->driver.disable_vblank = r128_disable_vblank;
- dev->driver.irq_preinstall = r128_driver_irq_preinstall;
- dev->driver.irq_postinstall = r128_driver_irq_postinstall;
- dev->driver.irq_uninstall = r128_driver_irq_uninstall;
- dev->driver.irq_handler = r128_driver_irq_handler;
- dev->driver.dma_ioctl = r128_cce_buffers;
-
- dev->driver.ioctls = r128_ioctls;
- dev->driver.max_ioctl = r128_max_ioctl;
-
- dev->driver.name = DRIVER_NAME;
- dev->driver.desc = DRIVER_DESC;
- dev->driver.date = DRIVER_DATE;
- dev->driver.major = DRIVER_MAJOR;
- dev->driver.minor = DRIVER_MINOR;
- dev->driver.patchlevel = DRIVER_PATCHLEVEL;
-
- dev->driver.use_agp = 1;
- dev->driver.use_mtrr = 1;
- dev->driver.use_pci_dma = 1;
- dev->driver.use_sg = 1;
- dev->driver.use_dma = 1;
- dev->driver.use_irq = 1;
- dev->driver.use_vbl_irq = 1;
+ dev->driver->driver_features =
+ DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
+ DRIVER_SG | DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ;
+
+ dev->driver->buf_priv_size = sizeof(drm_r128_buf_priv_t);
+ dev->driver->preclose = r128_driver_preclose;
+ dev->driver->lastclose = r128_driver_lastclose;
+ dev->driver->get_vblank_counter = r128_get_vblank_counter;
+ dev->driver->enable_vblank = r128_enable_vblank;
+ dev->driver->disable_vblank = r128_disable_vblank;
+ dev->driver->irq_preinstall = r128_driver_irq_preinstall;
+ dev->driver->irq_postinstall = r128_driver_irq_postinstall;
+ dev->driver->irq_uninstall = r128_driver_irq_uninstall;
+ dev->driver->irq_handler = r128_driver_irq_handler;
+ dev->driver->dma_ioctl = r128_cce_buffers;
+
+ dev->driver->ioctls = r128_ioctls;
+ dev->driver->max_ioctl = r128_max_ioctl;
+
+ dev->driver->name = DRIVER_NAME;
+ dev->driver->desc = DRIVER_DESC;
+ dev->driver->date = DRIVER_DATE;
+ dev->driver->major = DRIVER_MAJOR;
+ dev->driver->minor = DRIVER_MINOR;
+ dev->driver->patchlevel = DRIVER_PATCHLEVEL;
}
-#ifdef __FreeBSD__
static int
r128_probe(device_t dev)
{
@@ -88,15 +83,31 @@ r128_attach(device_t nbdev)
struct drm_device *dev = device_get_softc(nbdev);
bzero(dev, sizeof(struct drm_device));
+
+ dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO);
r128_configure(dev);
+
return drm_attach(nbdev, r128_pciidlist);
}
+static int
+r128_detach(device_t nbdev)
+{
+ struct drm_device *dev = device_get_softc(nbdev);
+ int ret;
+
+ ret = drm_detach(nbdev);
+
+ free(dev->driver, M_DRM);
+
+ return ret;
+}
+
static device_method_t r128_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, r128_probe),
DEVMETHOD(device_attach, r128_attach),
- DEVMETHOD(device_detach, drm_detach),
+ DEVMETHOD(device_detach, r128_detach),
{ 0, 0 }
};
@@ -114,12 +125,3 @@ DRIVER_MODULE(r128, vgapci, r128_driver, drm_devclass, 0, 0);
DRIVER_MODULE(r128, pci, r128_driver, drm_devclass, 0, 0);
#endif
MODULE_DEPEND(r128, drm, 1, 1, 1);
-
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-#ifdef _LKM
-CFDRIVER_DECL(r128, DV_TTY, NULL);
-#else
-CFATTACH_DECL(r128, sizeof(struct drm_device), drm_probe, drm_attach,
- drm_detach, drm_activate);
-#endif
-#endif
diff --git a/bsd-core/radeon_drv.c b/bsd-core/radeon_drv.c
index 0b4dba18..8ab3e995 100644
--- a/bsd-core/radeon_drv.c
+++ b/bsd-core/radeon_drv.c
@@ -44,44 +44,38 @@ static drm_pci_id_list_t radeon_pciidlist[] = {
static void radeon_configure(struct drm_device *dev)
{
- dev->driver.buf_priv_size = sizeof(drm_radeon_buf_priv_t);
- dev->driver.load = radeon_driver_load;
- dev->driver.unload = radeon_driver_unload;
- dev->driver.firstopen = radeon_driver_firstopen;
- dev->driver.open = radeon_driver_open;
- dev->driver.preclose = radeon_driver_preclose;
- dev->driver.postclose = radeon_driver_postclose;
- dev->driver.lastclose = radeon_driver_lastclose;
- dev->driver.get_vblank_counter = radeon_get_vblank_counter;
- dev->driver.enable_vblank = radeon_enable_vblank;
- dev->driver.disable_vblank = radeon_disable_vblank;
- dev->driver.irq_preinstall = radeon_driver_irq_preinstall;
- dev->driver.irq_postinstall = radeon_driver_irq_postinstall;
- dev->driver.irq_uninstall = radeon_driver_irq_uninstall;
- dev->driver.irq_handler = radeon_driver_irq_handler;
- dev->driver.dma_ioctl = radeon_cp_buffers;
-
- dev->driver.ioctls = radeon_ioctls;
- dev->driver.max_ioctl = radeon_max_ioctl;
-
- dev->driver.name = DRIVER_NAME;
- dev->driver.desc = DRIVER_DESC;
- dev->driver.date = DRIVER_DATE;
- dev->driver.major = DRIVER_MAJOR;
- dev->driver.minor = DRIVER_MINOR;
- dev->driver.patchlevel = DRIVER_PATCHLEVEL;
-
- dev->driver.use_agp = 1;
- dev->driver.use_mtrr = 1;
- dev->driver.use_pci_dma = 1;
- dev->driver.use_sg = 1;
- dev->driver.use_dma = 1;
- dev->driver.use_irq = 1;
- dev->driver.use_vbl_irq = 1;
- dev->driver.use_vbl_irq2 = 1;
+ dev->driver->driver_features =
+ DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
+ DRIVER_SG | DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ;
+
+ dev->driver->buf_priv_size = sizeof(drm_radeon_buf_priv_t);
+ dev->driver->load = radeon_driver_load;
+ dev->driver->unload = radeon_driver_unload;
+ dev->driver->firstopen = radeon_driver_firstopen;
+ dev->driver->open = radeon_driver_open;
+ dev->driver->preclose = radeon_driver_preclose;
+ dev->driver->postclose = radeon_driver_postclose;
+ dev->driver->lastclose = radeon_driver_lastclose;
+ dev->driver->get_vblank_counter = radeon_get_vblank_counter;
+ dev->driver->enable_vblank = radeon_enable_vblank;
+ dev->driver->disable_vblank = radeon_disable_vblank;
+ dev->driver->irq_preinstall = radeon_driver_irq_preinstall;
+ dev->driver->irq_postinstall = radeon_driver_irq_postinstall;
+ dev->driver->irq_uninstall = radeon_driver_irq_uninstall;
+ dev->driver->irq_handler = radeon_driver_irq_handler;
+ dev->driver->dma_ioctl = radeon_cp_buffers;
+
+ dev->driver->ioctls = radeon_ioctls;
+ dev->driver->max_ioctl = radeon_max_ioctl;
+
+ dev->driver->name = DRIVER_NAME;
+ dev->driver->desc = DRIVER_DESC;
+ dev->driver->date = DRIVER_DATE;
+ dev->driver->major = DRIVER_MAJOR;
+ dev->driver->minor = DRIVER_MINOR;
+ dev->driver->patchlevel = DRIVER_PATCHLEVEL;
}
-#ifdef __FreeBSD__
static int
radeon_probe(device_t dev)
{
@@ -94,15 +88,31 @@ radeon_attach(device_t nbdev)
struct drm_device *dev = device_get_softc(nbdev);
bzero(dev, sizeof(struct drm_device));
+
+ dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO);
radeon_configure(dev);
+
return drm_attach(nbdev, radeon_pciidlist);
}
+static int
+radeon_detach(device_t nbdev)
+{
+ struct drm_device *dev = device_get_softc(nbdev);
+ int ret;
+
+ ret = drm_detach(nbdev);
+
+ free(dev->driver, M_DRM);
+
+ return ret;
+}
+
static device_method_t radeon_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, radeon_probe),
DEVMETHOD(device_attach, radeon_attach),
- DEVMETHOD(device_detach, drm_detach),
+ DEVMETHOD(device_detach, radeon_detach),
{ 0, 0 }
};
@@ -120,12 +130,3 @@ DRIVER_MODULE(radeon, vgapci, radeon_driver, drm_devclass, 0, 0);
DRIVER_MODULE(radeon, pci, radeon_driver, drm_devclass, 0, 0);
#endif
MODULE_DEPEND(radeon, drm, 1, 1, 1);
-
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-#ifdef _LKM
-CFDRIVER_DECL(radeon, DV_TTY, NULL);
-#else
-CFATTACH_DECL(radeon, sizeof(struct drm_device), drm_probe, drm_attach,
- drm_detach, drm_activate);
-#endif
-#endif /* __FreeBSD__ */
diff --git a/bsd-core/savage_drv.c b/bsd-core/savage_drv.c
index 6235bcd1..35fcdfa3 100644
--- a/bsd-core/savage_drv.c
+++ b/bsd-core/savage_drv.c
@@ -39,31 +39,29 @@ static drm_pci_id_list_t savage_pciidlist[] = {
static void savage_configure(struct drm_device *dev)
{
- dev->driver.buf_priv_size = sizeof(drm_savage_buf_priv_t);
- dev->driver.load = savage_driver_load;
- dev->driver.firstopen = savage_driver_firstopen;
- dev->driver.lastclose = savage_driver_lastclose;
- dev->driver.unload = savage_driver_unload;
- dev->driver.reclaim_buffers_locked = savage_reclaim_buffers;
- dev->driver.dma_ioctl = savage_bci_buffers;
-
- dev->driver.ioctls = savage_ioctls;
- dev->driver.max_ioctl = savage_max_ioctl;
-
- dev->driver.name = DRIVER_NAME;
- dev->driver.desc = DRIVER_DESC;
- dev->driver.date = DRIVER_DATE;
- dev->driver.major = DRIVER_MAJOR;
- dev->driver.minor = DRIVER_MINOR;
- dev->driver.patchlevel = DRIVER_PATCHLEVEL;
-
- dev->driver.use_agp = 1;
- dev->driver.use_mtrr = 1;
- dev->driver.use_pci_dma = 1;
- dev->driver.use_dma = 1;
+ dev->driver->driver_features =
+ DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
+ DRIVER_HAVE_DMA;
+
+ dev->driver->buf_priv_size = sizeof(drm_savage_buf_priv_t);
+ dev->driver->load = savage_driver_load;
+ dev->driver->firstopen = savage_driver_firstopen;
+ dev->driver->lastclose = savage_driver_lastclose;
+ dev->driver->unload = savage_driver_unload;
+ dev->driver->reclaim_buffers_locked = savage_reclaim_buffers;
+ dev->driver->dma_ioctl = savage_bci_buffers;
+
+ dev->driver->ioctls = savage_ioctls;
+ dev->driver->max_ioctl = savage_max_ioctl;
+
+ dev->driver->name = DRIVER_NAME;
+ dev->driver->desc = DRIVER_DESC;
+ dev->driver->date = DRIVER_DATE;
+ dev->driver->major = DRIVER_MAJOR;
+ dev->driver->minor = DRIVER_MINOR;
+ dev->driver->patchlevel = DRIVER_PATCHLEVEL;
}
-#ifdef __FreeBSD__
static int
savage_probe(device_t dev)
{
@@ -76,15 +74,31 @@ savage_attach(device_t nbdev)
struct drm_device *dev = device_get_softc(nbdev);
bzero(dev, sizeof(struct drm_device));
+
+ dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO);
savage_configure(dev);
+
return drm_attach(nbdev, savage_pciidlist);
}
+static int
+savage_detach(device_t nbdev)
+{
+ struct drm_device *dev = device_get_softc(nbdev);
+ int ret;
+
+ ret = drm_detach(nbdev);
+
+ free(dev->driver, M_DRM);
+
+ return ret;
+}
+
static device_method_t savage_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, savage_probe),
DEVMETHOD(device_attach, savage_attach),
- DEVMETHOD(device_detach, drm_detach),
+ DEVMETHOD(device_detach, savage_detach),
{ 0, 0 }
};
@@ -102,7 +116,3 @@ DRIVER_MODULE(savage, vgapci, savage_driver, drm_devclass, 0, 0);
DRIVER_MODULE(savage, pci, savage_driver, drm_devclass, 0, 0);
#endif
MODULE_DEPEND(savage, drm, 1, 1, 1);
-
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-CFDRIVER_DECL(savage, DV_TTY, NULL);
-#endif
diff --git a/bsd-core/sis_drv.c b/bsd-core/sis_drv.c
index 9f76a689..2ae1bff0 100644
--- a/bsd-core/sis_drv.c
+++ b/bsd-core/sis_drv.c
@@ -38,25 +38,24 @@ static drm_pci_id_list_t sis_pciidlist[] = {
static void sis_configure(struct drm_device *dev)
{
- dev->driver.buf_priv_size = 1; /* No dev_priv */
- dev->driver.context_ctor = sis_init_context;
- dev->driver.context_dtor = sis_final_context;
-
- dev->driver.ioctls = sis_ioctls;
- dev->driver.max_ioctl = sis_max_ioctl;
-
- dev->driver.name = DRIVER_NAME;
- dev->driver.desc = DRIVER_DESC;
- dev->driver.date = DRIVER_DATE;
- dev->driver.major = DRIVER_MAJOR;
- dev->driver.minor = DRIVER_MINOR;
- dev->driver.patchlevel = DRIVER_PATCHLEVEL;
-
- dev->driver.use_agp = 1;
- dev->driver.use_mtrr = 1;
+ dev->driver->driver_features =
+ DRIVER_USE_AGP | DRIVER_USE_MTRR;
+
+ dev->driver->buf_priv_size = 1; /* No dev_priv */
+ dev->driver->context_ctor = sis_init_context;
+ dev->driver->context_dtor = sis_final_context;
+
+ dev->driver->ioctls = sis_ioctls;
+ dev->driver->max_ioctl = sis_max_ioctl;
+
+ dev->driver->name = DRIVER_NAME;
+ dev->driver->desc = DRIVER_DESC;
+ dev->driver->date = DRIVER_DATE;
+ dev->driver->major = DRIVER_MAJOR;
+ dev->driver->minor = DRIVER_MINOR;
+ dev->driver->patchlevel = DRIVER_PATCHLEVEL;
}
-#ifdef __FreeBSD__
static int
sis_probe(device_t dev)
{
@@ -69,15 +68,31 @@ sis_attach(device_t nbdev)
struct drm_device *dev = device_get_softc(nbdev);
bzero(dev, sizeof(struct drm_device));
+
+ dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO);
sis_configure(dev);
+
return drm_attach(nbdev, sis_pciidlist);
}
+static int
+sis_detach(device_t nbdev)
+{
+ struct drm_device *dev = device_get_softc(nbdev);
+ int ret;
+
+ ret = drm_detach(nbdev);
+
+ free(dev->driver, M_DRM);
+
+ return ret;
+}
+
static device_method_t sis_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, sis_probe),
DEVMETHOD(device_attach, sis_attach),
- DEVMETHOD(device_detach, drm_detach),
+ DEVMETHOD(device_detach, sis_detach),
{ 0, 0 }
};
@@ -95,12 +110,3 @@ DRIVER_MODULE(sisdrm, vgapci, sis_driver, drm_devclass, 0, 0);
DRIVER_MODULE(sisdrm, pci, sis_driver, drm_devclass, 0, 0);
#endif
MODULE_DEPEND(sisdrm, drm, 1, 1, 1);
-
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-#ifdef _LKM
-CFDRIVER_DECL(sis, DV_TTY, NULL);
-#else
-CFATTACH_DECL(sis, sizeof(struct drm_device), drm_probe, drm_attach, drm_detach,
- drm_activate);
-#endif
-#endif
diff --git a/bsd-core/tdfx_drv.c b/bsd-core/tdfx_drv.c
index 6d4e74b0..44948b5c 100644
--- a/bsd-core/tdfx_drv.c
+++ b/bsd-core/tdfx_drv.c
@@ -43,21 +43,21 @@ static drm_pci_id_list_t tdfx_pciidlist[] = {
static void tdfx_configure(struct drm_device *dev)
{
- dev->driver.buf_priv_size = 1; /* No dev_priv */
+ dev->driver->driver_features =
+ DRIVER_USE_MTRR;
- dev->driver.max_ioctl = 0;
+ dev->driver->buf_priv_size = 1; /* No dev_priv */
- dev->driver.name = DRIVER_NAME;
- dev->driver.desc = DRIVER_DESC;
- dev->driver.date = DRIVER_DATE;
- dev->driver.major = DRIVER_MAJOR;
- dev->driver.minor = DRIVER_MINOR;
- dev->driver.patchlevel = DRIVER_PATCHLEVEL;
+ dev->driver->max_ioctl = 0;
- dev->driver.use_mtrr = 1;
+ dev->driver->name = DRIVER_NAME;
+ dev->driver->desc = DRIVER_DESC;
+ dev->driver->date = DRIVER_DATE;
+ dev->driver->major = DRIVER_MAJOR;
+ dev->driver->minor = DRIVER_MINOR;
+ dev->driver->patchlevel = DRIVER_PATCHLEVEL;
}
-#ifdef __FreeBSD__
static int
tdfx_probe(device_t dev)
{
@@ -70,15 +70,31 @@ tdfx_attach(device_t nbdev)
struct drm_device *dev = device_get_softc(nbdev);
bzero(dev, sizeof(struct drm_device));
+
+ dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO);
tdfx_configure(dev);
+
return drm_attach(nbdev, tdfx_pciidlist);
}
+static int
+tdfx_detach(device_t nbdev)
+{
+ struct drm_device *dev = device_get_softc(nbdev);
+ int ret;
+
+ ret = drm_detach(nbdev);
+
+ free(dev->driver, M_DRM);
+
+ return ret;
+}
+
static device_method_t tdfx_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, tdfx_probe),
DEVMETHOD(device_attach, tdfx_attach),
- DEVMETHOD(device_detach, drm_detach),
+ DEVMETHOD(device_detach, tdfx_detach),
{ 0, 0 }
};
@@ -96,12 +112,3 @@ DRIVER_MODULE(tdfx, vgapci, tdfx_driver, drm_devclass, 0, 0);
DRIVER_MODULE(tdfx, pci, tdfx_driver, drm_devclass, 0, 0);
#endif
MODULE_DEPEND(tdfx, drm, 1, 1, 1);
-
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-#ifdef _LKM
-CFDRIVER_DECL(tdfx, DV_TTY, NULL);
-#else
-CFATTACH_DECL(tdfx, sizeof(struct drm_device), drm_probe, drm_attach,
- drm_detach, drm_activate);
-#endif
-#endif
diff --git a/bsd-core/via_drv.c b/bsd-core/via_drv.c
index 1d784eed..e5f7d493 100644
--- a/bsd-core/via_drv.c
+++ b/bsd-core/via_drv.c
@@ -41,35 +41,34 @@ static drm_pci_id_list_t via_pciidlist[] = {
static void via_configure(struct drm_device *dev)
{
- dev->driver.buf_priv_size = 1;
- dev->driver.load = via_driver_load;
- dev->driver.unload = via_driver_unload;
- dev->driver.context_ctor = via_init_context;
- dev->driver.context_dtor = via_final_context;
- dev->driver.vblank_wait = via_driver_vblank_wait;
- dev->driver.irq_preinstall = via_driver_irq_preinstall;
- dev->driver.irq_postinstall = via_driver_irq_postinstall;
- dev->driver.irq_uninstall = via_driver_irq_uninstall;
- dev->driver.irq_handler = via_driver_irq_handler;
- dev->driver.dma_quiescent = via_driver_dma_quiescent;
-
- dev->driver.ioctls = via_ioctls;
- dev->driver.max_ioctl = via_max_ioctl;
-
- dev->driver.name = DRIVER_NAME;
- dev->driver.desc = DRIVER_DESC;
- dev->driver.date = DRIVER_DATE;
- dev->driver.major = DRIVER_MAJOR;
- dev->driver.minor = DRIVER_MINOR;
- dev->driver.patchlevel = DRIVER_PATCHLEVEL;
-
- dev->driver.use_agp = 1;
- dev->driver.use_mtrr = 1;
- dev->driver.use_irq = 1;
- dev->driver.use_vbl_irq = 1;
+ dev->driver->driver_features =
+ DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_IRQ;
+
+ dev->driver->buf_priv_size = 1;
+ dev->driver->load = via_driver_load;
+ dev->driver->unload = via_driver_unload;
+ dev->driver->context_ctor = via_init_context;
+ dev->driver->context_dtor = via_final_context;
+ dev->driver->get_vblank_counter = via_get_vblank_counter;
+ dev->driver->enable_vblank = via_enable_vblank;
+ dev->driver->disable_vblank = via_disable_vblank;
+ dev->driver->irq_preinstall = via_driver_irq_preinstall;
+ dev->driver->irq_postinstall = via_driver_irq_postinstall;
+ dev->driver->irq_uninstall = via_driver_irq_uninstall;
+ dev->driver->irq_handler = via_driver_irq_handler;
+ dev->driver->dma_quiescent = via_driver_dma_quiescent;
+
+ dev->driver->ioctls = via_ioctls;
+ dev->driver->max_ioctl = via_max_ioctl;
+
+ dev->driver->name = DRIVER_NAME;
+ dev->driver->desc = DRIVER_DESC;
+ dev->driver->date = DRIVER_DATE;
+ dev->driver->major = DRIVER_MAJOR;
+ dev->driver->minor = DRIVER_MINOR;
+ dev->driver->patchlevel = DRIVER_PATCHLEVEL;
}
-#ifdef __FreeBSD__
static int
via_probe(device_t dev)
{
@@ -82,15 +81,31 @@ via_attach(device_t nbdev)
struct drm_device *dev = device_get_softc(nbdev);
bzero(dev, sizeof(struct drm_device));
+
+ dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO);
via_configure(dev);
+
return drm_attach(nbdev, via_pciidlist);
}
+static int
+via_detach(device_t nbdev)
+{
+ struct drm_device *dev = device_get_softc(nbdev);
+ int ret;
+
+ ret = drm_detach(nbdev);
+
+ free(dev->driver, M_DRM);
+
+ return ret;
+}
+
static device_method_t via_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, via_probe),
DEVMETHOD(device_attach, via_attach),
- DEVMETHOD(device_detach, drm_detach),
+ DEVMETHOD(device_detach, via_detach),
{ 0, 0 }
};
@@ -104,12 +119,3 @@ static driver_t via_driver = {
extern devclass_t drm_devclass;
DRIVER_MODULE(via, pci, via_driver, drm_devclass, 0, 0);
MODULE_DEPEND(via, drm, 1, 1, 1);
-
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-#ifdef _LKM
-CFDRIVER_DECL(via, DV_TTY, NULL);
-#else
-CFATTACH_DECL(via, sizeof(struct drm_device), drm_probe, drm_attach, drm_detach,
- drm_activate);
-#endif
-#endif