aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorRobert Noland <rnoland@FreeBSD.org>2008-10-03 16:59:11 +0000
committerRobert Noland <rnoland@FreeBSD.org>2008-10-03 16:59:11 +0000
commit4cd2e9581f9232a2134d2617e65d372149694c53 (patch)
tree2d4185c3ec896efd0d1b2735041e6ddeb6a750f1 /sys
parent0b36cd25fcb6fd26726efb8d9fd80b9c9733174f (diff)
downloadsrc-4cd2e9581f9232a2134d2617e65d372149694c53.tar.gz
src-4cd2e9581f9232a2134d2617e65d372149694c53.zip
Notes
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/drm/drm.h33
-rw-r--r--sys/dev/drm/drmP.h257
-rw-r--r--sys/dev/drm/drm_agpsupport.c49
-rw-r--r--sys/dev/drm/drm_atomic.h53
-rw-r--r--sys/dev/drm/drm_auth.c15
-rw-r--r--sys/dev/drm/drm_bufs.c252
-rw-r--r--sys/dev/drm/drm_context.c100
-rw-r--r--sys/dev/drm/drm_dma.c19
-rw-r--r--sys/dev/drm/drm_drawable.c4
-rw-r--r--sys/dev/drm/drm_drv.c403
-rw-r--r--sys/dev/drm/drm_fops.c91
-rw-r--r--sys/dev/drm/drm_ioctl.c42
-rw-r--r--sys/dev/drm/drm_irq.c90
-rw-r--r--sys/dev/drm/drm_lock.c170
-rw-r--r--sys/dev/drm/drm_memory.c50
-rw-r--r--sys/dev/drm/drm_pci.c27
-rw-r--r--sys/dev/drm/drm_scatter.c22
-rw-r--r--sys/dev/drm/drm_sysctl.c6
-rw-r--r--sys/dev/drm/drm_vm.c37
-rw-r--r--sys/dev/drm/i915_dma.c363
-rw-r--r--sys/dev/drm/i915_drm.h321
-rw-r--r--sys/dev/drm/i915_drv.c82
-rw-r--r--sys/dev/drm/i915_drv.h327
-rw-r--r--sys/dev/drm/i915_irq.c115
-rw-r--r--sys/dev/drm/i915_suspend.c4
-rw-r--r--sys/dev/drm/mach64_drv.c74
-rw-r--r--sys/dev/drm/mga_drv.c89
-rw-r--r--sys/dev/drm/r128_drv.c82
-rw-r--r--sys/dev/drm/radeon_cp.c6
-rw-r--r--sys/dev/drm/radeon_drv.c93
-rw-r--r--sys/dev/drm/savage_drv.c66
-rw-r--r--sys/dev/drm/sis_drv.c60
-rw-r--r--sys/dev/drm/tdfx_drv.c47
33 files changed, 1838 insertions, 1611 deletions
diff --git a/sys/dev/drm/drm.h b/sys/dev/drm/drm.h
index dffa18f7e02d..592b5b3e8213 100644
--- a/sys/dev/drm/drm.h
+++ b/sys/dev/drm/drm.h
@@ -962,6 +962,31 @@ struct drm_mm_info_arg {
uint64_t p_size;
};
+struct drm_gem_close {
+ /** Handle of the object to be closed. */
+ uint32_t handle;
+ uint32_t pad;
+};
+
+struct drm_gem_flink {
+ /** Handle for the object being named */
+ uint32_t handle;
+
+ /** Returned global name */
+ uint32_t name;
+};
+
+struct drm_gem_open {
+ /** Name of object being opened */
+ uint32_t name;
+
+ /** Returned handle for the object */
+ uint32_t handle;
+
+ /** Returned size of the object */
+ uint64_t size;
+};
+
/**
* \name Ioctls Definitions
*/
@@ -981,7 +1006,11 @@ struct drm_mm_info_arg {
#define DRM_IOCTL_GET_CLIENT DRM_IOWR(0x05, struct drm_client)
#define DRM_IOCTL_GET_STATS DRM_IOR( 0x06, struct drm_stats)
#define DRM_IOCTL_SET_VERSION DRM_IOWR(0x07, struct drm_set_version)
-#define DRM_IOCTL_MODESET_CTL DRM_IOW(0x08, struct drm_modeset_ctl)
+#define DRM_IOCTL_MODESET_CTL DRM_IOW(0x08, struct drm_modeset_ctl)
+
+#define DRM_IOCTL_GEM_CLOSE DRM_IOW (0x09, struct drm_gem_close)
+#define DRM_IOCTL_GEM_FLINK DRM_IOWR(0x0a, struct drm_gem_flink)
+#define DRM_IOCTL_GEM_OPEN DRM_IOWR(0x0b, struct drm_gem_open)
#define DRM_IOCTL_SET_UNIQUE DRM_IOW( 0x10, struct drm_unique)
#define DRM_IOCTL_AUTH_MAGIC DRM_IOW( 0x11, struct drm_auth)
@@ -1069,7 +1098,7 @@ struct drm_mm_info_arg {
#define DRM_COMMAND_END 0xA0
/* typedef area */
-#if !defined(__KERNEL__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
+#ifndef __KERNEL__
typedef struct drm_clip_rect drm_clip_rect_t;
typedef struct drm_tex_region drm_tex_region_t;
typedef struct drm_hw_lock drm_hw_lock_t;
diff --git a/sys/dev/drm/drmP.h b/sys/dev/drm/drmP.h
index 613276095c3f..414610ae9a8d 100644
--- a/sys/dev/drm/drmP.h
+++ b/sys/dev/drm/drmP.h
@@ -40,7 +40,7 @@ __FBSDID("$FreeBSD$");
#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>
@@ -73,10 +73,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
@@ -85,31 +85,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 "dev/drm/drm.h"
@@ -117,13 +95,11 @@ typedef struct drm_file drm_file_t;
#include "dev/drm/drm_atomic.h"
#include "dev/drm/drm_internal.h"
-#ifdef __FreeBSD__
#include <opt_drm.h>
#ifdef DRM_DEBUG
#undef DRM_DEBUG
#define DRM_DEBUG_DEFAULT_ON 1
#endif /* DRM_DEBUG */
-#endif
#if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__)
#include <sys/file.h>
@@ -138,6 +114,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 */
@@ -186,12 +173,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
@@ -209,21 +190,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;
@@ -237,16 +203,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
@@ -258,20 +216,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
@@ -309,7 +253,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) \
@@ -326,27 +269,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) \
@@ -355,13 +277,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)
@@ -384,7 +301,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) ; ) { \
@@ -396,17 +312,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, \
@@ -492,12 +397,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 {
@@ -514,19 +415,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 */
@@ -589,8 +490,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 */
@@ -653,9 +554,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 *,
@@ -665,9 +566,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,
@@ -708,16 +609,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_*. */
@@ -727,11 +619,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 */
@@ -739,21 +627,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;
@@ -763,7 +647,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 */
@@ -784,12 +668,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_* */
@@ -811,11 +691,7 @@ struct drm_device {
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;
@@ -835,45 +711,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);
@@ -883,6 +753,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);
@@ -897,13 +768,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) */
@@ -915,11 +784,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);
@@ -951,26 +820,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,
@@ -1008,7 +875,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,
@@ -1063,7 +930,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,
@@ -1098,10 +966,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/sys/dev/drm/drm_agpsupport.c b/sys/dev/drm/drm_agpsupport.c
index 1614c21fb028..37ef21bd6c8d 100644
--- a/sys/dev/drm/drm_agpsupport.c
+++ b/sys/dev/drm/drm_agpsupport.c
@@ -38,20 +38,17 @@ __FBSDID("$FreeBSD$");
#include "dev/drm/drmP.h"
-#ifdef __FreeBSD__
#if __FreeBSD_version >= 800004
#include <dev/agp/agpreg.h>
#else /* __FreeBSD_version >= 800004 */
#include <pci/agpreg.h>
#endif /* __FreeBSD_version >= 800004 */
#include <dev/pci/pcireg.h>
-#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);
@@ -85,21 +82,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;
}
@@ -112,7 +105,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;
@@ -138,13 +131,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;
}
@@ -186,7 +179,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)
@@ -201,14 +194,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;
@@ -254,16 +247,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;
}
@@ -279,7 +272,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;
@@ -304,10 +297,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);
@@ -316,7 +309,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;
@@ -345,10 +338,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);
@@ -357,7 +350,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;
@@ -390,10 +383,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/sys/dev/drm/drm_atomic.h b/sys/dev/drm/drm_atomic.h
index cf9d2068ceb7..e8cd81876789 100644
--- a/sys/dev/drm/drm_atomic.h
+++ b/sys/dev/drm/drm_atomic.h
@@ -36,65 +36,12 @@ __FBSDID("$FreeBSD$");
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/sys/dev/drm/drm_auth.c b/sys/dev/drm/drm_auth.c
index 0fe93b85e419..5ef3406ba1fe 100644
--- a/sys/dev/drm/drm_auth.c
+++ b/sys/dev/drm/drm_auth.c
@@ -46,7 +46,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);
@@ -66,7 +66,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;
@@ -78,7 +78,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;
@@ -139,9 +140,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 {
@@ -170,8 +171,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/sys/dev/drm/drm_bufs.c b/sys/dev/drm/drm_bufs.c
index b07359c66de7..e5f6d1c994f6 100644
--- a/sys/dev/drm/drm_bufs.c
+++ b/sys/dev/drm/drm_bufs.c
@@ -39,22 +39,6 @@ __FBSDID("$FreeBSD$");
#include "dev/drm/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.
@@ -105,7 +89,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;
@@ -155,7 +139,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;
}
@@ -165,7 +149,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))
@@ -177,15 +161,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) {
@@ -277,7 +261,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;
@@ -358,7 +342,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) {
@@ -405,7 +389,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;
@@ -429,20 +413,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
@@ -468,7 +452,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;
}
@@ -477,7 +461,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;
@@ -491,7 +475,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) {
@@ -506,7 +490,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,
@@ -518,15 +502,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;
@@ -536,7 +520,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;
@@ -558,11 +542,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;
@@ -581,23 +565,24 @@ 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);
@@ -612,16 +597,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;
@@ -634,7 +619,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) {
@@ -646,8 +631,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;
}
@@ -663,7 +648,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];
}
@@ -685,7 +670,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;
@@ -707,20 +692,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];
@@ -734,7 +719,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;
@@ -748,7 +733,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) {
@@ -758,15 +743,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,
@@ -778,15 +763,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;
@@ -796,7 +781,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;
@@ -827,7 +812,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;
@@ -861,7 +846,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;
@@ -898,7 +883,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)
@@ -914,7 +899,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;
@@ -923,16 +908,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;
@@ -940,17 +926,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;
}
}
@@ -963,11 +948,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);
@@ -993,30 +978,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;
}
@@ -1034,30 +1019,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 */
@@ -1066,8 +1034,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) {
@@ -1081,7 +1050,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,
@@ -1091,18 +1059,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;
@@ -1129,7 +1091,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/sys/dev/drm/drm_context.c b/sys/dev/drm/drm_context.c
index 7da4ae3c8f6b..d72ab869579d 100644
--- a/sys/dev/drm/drm_context.c
+++ b/sys/dev/drm/drm_context.c
@@ -65,7 +65,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;
@@ -111,7 +111,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;
}
@@ -119,9 +119,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;
@@ -143,7 +143,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();
@@ -164,7 +164,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();
@@ -191,49 +191,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;
}
}
@@ -244,23 +244,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();
}
@@ -275,7 +275,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;
@@ -286,17 +286,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;
@@ -304,13 +304,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/sys/dev/drm/drm_dma.c b/sys/dev/drm/drm_dma.c
index 1ba3fdf7c6e1..e630c2549e3c 100644
--- a/sys/dev/drm/drm_dma.c
+++ b/sys/dev/drm/drm_dma.c
@@ -61,14 +61,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]);
}
@@ -94,7 +92,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;
@@ -106,7 +105,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) {
@@ -128,9 +129,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/sys/dev/drm/drm_drawable.c b/sys/dev/drm/drm_drawable.c
index 1223a4128311..b8e3d89a75c4 100644
--- a/sys/dev/drm/drm_drawable.c
+++ b/sys/dev/drm/drm_drawable.c
@@ -71,7 +71,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),
@@ -92,7 +92,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);
diff --git a/sys/dev/drm/drm_drv.c b/sys/dev/drm/drm_drv.c
index b41b53d4edc1..4cabc7eab499 100644
--- a/sys/dev/drm/drm_drv.c
+++ b/sys/dev/drm/drm_drv.c
@@ -53,22 +53,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),
@@ -132,27 +123,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)
@@ -205,13 +184,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);
@@ -232,147 +210,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)
{
@@ -396,22 +233,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;
}
@@ -422,13 +259,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;
}
@@ -441,22 +274,22 @@ 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);
}
@@ -467,17 +300,17 @@ static int drm_lastclose(struct drm_device *dev)
drm_drawable_free_all(dev);
DRM_LOCK();
- /* Clear AGP information */
- if ( dev->agp ) {
+ /* 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);
@@ -501,7 +334,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);
@@ -514,10 +347,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;
@@ -532,9 +365,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;
@@ -545,13 +376,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");
@@ -560,10 +391,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;
@@ -589,31 +421,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->vbl_lock);
mtx_destroy(&dev->irq_lock);
mtx_destroy(&dev->dev_lock);
-#endif
-#endif
+
return retcode;
}
@@ -621,12 +449,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);
@@ -655,14 +481,14 @@ 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) {
+ if (dev->driver->unload != NULL) {
DRM_LOCK();
- dev->driver.unload(dev);
+ dev->driver->unload(dev);
DRM_UNLOCK();
}
@@ -673,19 +499,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->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 ) \
@@ -697,13 +521,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;
}
@@ -713,19 +537,17 @@ int drm_open(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p)
struct drm_device *dev = NULL;
int retcode = 0;
- dev = DRIVER_SOFTC(dev2unit(kdev));
+ 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();
}
@@ -733,103 +555,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);
@@ -837,18 +632,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.
@@ -862,55 +652,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) {
@@ -923,18 +692,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/sys/dev/drm/drm_fops.c b/sys/dev/drm/drm_fops.c
index f6eacd217fb5..9b7bc4068f8e 100644
--- a/sys/dev/drm/drm_fops.c
+++ b/sys/dev/drm/drm_fops.c
@@ -39,31 +39,12 @@ __FBSDID("$FreeBSD$");
#include "dev/drm/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 = dev2unit(kdev);
- drm_file_t *priv;
+ struct drm_file *priv;
+ int m = minor(kdev);
int retcode;
if (flags & O_EXCL)
@@ -72,50 +53,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/sys/dev/drm/drm_ioctl.c b/sys/dev/drm/drm_ioctl.c
index 2d708d8f9ba2..c919b684b57d 100644
--- a/sys/dev/drm/drm_ioctl.c
+++ b/sys/dev/drm/drm_ioctl.c
@@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$");
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))
@@ -64,7 +64,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;
@@ -144,7 +144,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;
@@ -158,7 +158,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;
@@ -181,16 +181,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;
@@ -208,21 +207,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;
@@ -238,8 +236,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
@@ -248,8 +246,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 ||
@@ -268,9 +266,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/sys/dev/drm/drm_irq.c b/sys/dev/drm/drm_irq.c
index 0cb8c70a08e4..4fde981954d0 100644
--- a/sys/dev/drm/drm_irq.c
+++ b/sys/dev/drm/drm_irq.c
@@ -41,7 +41,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 ||
@@ -52,22 +52,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)
{
@@ -84,6 +82,7 @@ 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;
@@ -92,8 +91,8 @@ static void vblank_disable_fn(void *arg)
dev->vblank[i].enabled) {
DRM_DEBUG("disabling vblank on crtc %d\n", i);
dev->vblank[i].last =
- dev->driver.get_vblank_counter(dev, i);
- dev->driver.disable_vblank(dev, i);
+ dev->driver->get_vblank_counter(dev, i);
+ dev->driver->disable_vblank(dev, i);
dev->vblank[i].enabled = 0;
}
}
@@ -105,7 +104,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);
@@ -134,6 +133,8 @@ int drm_vblank_init(struct drm_device *dev, int num_crtcs)
if (!dev->vblank)
goto err;
+ DRM_DEBUG("\n");
+
/* Zero per-crtc vblank stuff */
for (i = 0; i < num_crtcs; i++) {
DRM_INIT_WAITQUEUE(&dev->vblank[i].queue);
@@ -154,14 +155,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) {
@@ -172,12 +170,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);
@@ -196,22 +193,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);
@@ -219,44 +204,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;
@@ -264,22 +240,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);
@@ -306,12 +282,12 @@ 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);
+ 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",
+ DRM_DEBUG("vblank[%d].last=0x%x, cur_vblank=0x%x => diff=0x%x\n",
crtc, dev->vblank[crtc].last, cur_vblank, diff);
}
@@ -331,7 +307,7 @@ int drm_vblank_get(struct drm_device *dev, int 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);
+ ret = dev->driver->enable_vblank(dev, crtc);
if (ret)
atomic_dec(&dev->vblank[crtc].refcount);
else {
@@ -364,11 +340,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;
@@ -383,12 +361,14 @@ int drm_modeset_ctl(struct drm_device *dev, void *data,
*/
switch (modeset->cmd) {
case _DRM_PRE_MODESET:
+ 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:
+ DRM_DEBUG("post-modeset\n");
if (dev->vblank[crtc].inmodeset) {
DRM_SPINLOCK_IRQSAVE(&dev->vbl_lock, irqflags);
dev->vblank_disable_allowed = 1;
@@ -408,7 +388,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;
@@ -431,7 +411,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) {
@@ -508,7 +488,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);
@@ -536,7 +516,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;
@@ -550,7 +530,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/sys/dev/drm/drm_lock.c b/sys/dev/drm/drm_lock.c
index 938954c15f1e..668bce898553 100644
--- a/sys/dev/drm/drm_lock.c
+++ b/sys/dev/drm/drm_lock.c
@@ -52,89 +52,28 @@ __FBSDID("$FreeBSD$");
#include "dev/drm/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]);
@@ -142,13 +81,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;
}
@@ -160,34 +94,29 @@ 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;
-
- DRM_DEBUG("%d (pid %d) requests unlock (0x%08x), flags = 0x%08x\n",
- lock->context, DRM_CURRENTPID, dev->lock.hw_lock->lock,
- lock->flags);
+ struct drm_lock *lock = data;
if (lock->context == DRM_KERNEL_CONTEXT) {
DRM_ERROR("Process %d using kernel context %d\n",
DRM_CURRENTPID, lock->context);
return EINVAL;
}
-#if 0
/* Check that the context unlock being requested actually matches
* who currently holds the lock.
*/
if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) ||
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock) != lock->context)
return EINVAL;
-#endif
+
DRM_SPINLOCK(&dev->tsk_lock);
if (dev->locked_task_call != NULL) {
dev->locked_task_call(dev);
@@ -198,12 +127,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/sys/dev/drm/drm_memory.c b/sys/dev/drm/drm_memory.c
index 461d9fd369ed..8df769f465d4 100644
--- a/sys/dev/drm/drm_memory.c
+++ b/sys/dev/drm/drm_memory.c
@@ -45,9 +45,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)
@@ -72,7 +69,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;
@@ -83,29 +80,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)
{
@@ -133,30 +122,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/sys/dev/drm/drm_pci.c b/sys/dev/drm/drm_pci.c
index 4aa6d03522b4..7f8bc9ff1664 100644
--- a/sys/dev/drm/drm_pci.c
+++ b/sys/dev/drm/drm_pci.c
@@ -37,7 +37,6 @@ __FBSDID("$FreeBSD$");
/** \name PCI memory */
/*@{*/
-#if defined(__FreeBSD__)
static void
drm_pci_busdma_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
{
@@ -49,7 +48,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
@@ -73,10 +71,11 @@ drm_pci_alloc(struct drm_device *dev, size_t size,
if (dmah == NULL)
return NULL;
-#ifdef __FreeBSD__
/* 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");
@@ -107,24 +106,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;
}
@@ -138,12 +119,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/sys/dev/drm/drm_scatter.c b/sys/dev/drm/drm_scatter.c
index deef1c86bc98..a8c379f4ef41 100644
--- a/sys/dev/drm/drm_scatter.c
+++ b/sys/dev/drm/drm_scatter.c
@@ -48,27 +48,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;
}
@@ -84,7 +84,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;
@@ -104,10 +104,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;
@@ -115,7 +115,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();
@@ -123,10 +123,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/sys/dev/drm/drm_sysctl.c b/sys/dev/drm/drm_sysctl.c
index 5c4eacb306b1..b4c46710506a 100644
--- a/sys/dev/drm/drm_sysctl.c
+++ b/sys/dev/drm/drm_sysctl.c
@@ -135,7 +135,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) {
@@ -271,7 +271,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;
@@ -282,7 +282,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/sys/dev/drm/drm_vm.c b/sys/dev/drm/drm_vm.c
index c602eecdefae..e00684b96a82 100644
--- a/sys/dev/drm/drm_vm.c
+++ b/sys/dev/drm/drm_vm.c
@@ -31,34 +31,27 @@ __FBSDID("$FreeBSD$");
#include "dev/drm/drmP.h"
#include "dev/drm/drm.h"
-#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
int drm_mmap(struct cdev *kdev, vm_offset_t offset, vm_paddr_t *paddr,
int prot)
-#elif defined(__FreeBSD__)
-int drm_mmap(dev_t kdev, vm_offset_t offset, int prot)
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-paddr_t drm_mmap(dev_t kdev, off_t offset, int prot)
-#endif
{
struct drm_device *dev = drm_get_device_from_kdev(kdev);
+ struct drm_file *file_priv = NULL;
drm_local_map_t *map;
- drm_file_t *priv;
- drm_map_type_t type;
-#ifdef __FreeBSD__
+ enum drm_map_type type;
vm_paddr_t phys;
-#else
- paddr_t phys;
-#endif
+ int error;
- DRM_LOCK();
- priv = drm_find_file_by_proc(dev, DRM_CURPROC);
- DRM_UNLOCK();
- if (priv == NULL) {
- DRM_ERROR("can't find authenticator\n");
+ /* d_mmap gets called twice, we can only reference file_priv during
+ * the first call. We need to assume that if error is EBADF the
+ * call was succesful and the client is authenticated.
+ */
+ error = devfs_get_cdevpriv((void **)&file_priv);
+ if (error == ENOENT) {
+ DRM_ERROR("Could not find authenticator!\n");
return EINVAL;
}
- if (!priv->authenticated)
+ if (file_priv && !file_priv->authenticated)
return EACCES;
if (dev->dma && offset >= 0 && offset < ptoa(dev->dma->page_count)) {
@@ -71,12 +64,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;
@@ -127,11 +116,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/sys/dev/drm/i915_dma.c b/sys/dev/drm/i915_dma.c
index 79e687e46d91..39a0809c4336 100644
--- a/sys/dev/drm/i915_dma.c
+++ b/sys/dev/drm/i915_dma.c
@@ -44,10 +44,14 @@ int i915_wait_ring(struct drm_device * dev, int n, const char *caller)
drm_i915_private_t *dev_priv = dev->dev_private;
drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
u32 last_head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
+ u32 acthd_reg = IS_I965G(dev) ? ACTHD_I965 : ACTHD;
+ u32 last_acthd = I915_READ(acthd_reg);
+ u32 acthd;
int i;
- for (i = 0; i < 10000; i++) {
+ for (i = 0; i < 100000; i++) {
ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
+ acthd = I915_READ(acthd_reg);
ring->space = ring->head - (ring->tail + 8);
if (ring->space < 0)
ring->space += ring->Size;
@@ -57,13 +61,89 @@ int i915_wait_ring(struct drm_device * dev, int n, const char *caller)
if (ring->head != last_head)
i = 0;
+ if (acthd != last_acthd)
+ i = 0;
+
last_head = ring->head;
- DRM_UDELAY(1);
+ last_acthd = acthd;
+ DRM_UDELAY(10 * 1000);
}
return -EBUSY;
}
+int i915_init_hardware_status(struct drm_device *dev)
+{
+ drm_i915_private_t *dev_priv = dev->dev_private;
+ drm_dma_handle_t *dmah;
+
+ /* Program Hardware Status Page */
+#ifdef __FreeBSD__
+ DRM_UNLOCK();
+#endif
+ dmah = drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE, 0xffffffff);
+#ifdef __FreeBSD__
+ DRM_LOCK();
+#endif
+ if (!dmah) {
+ DRM_ERROR("Can not allocate hardware status page\n");
+ return -ENOMEM;
+ }
+
+ dev_priv->status_page_dmah = dmah;
+ dev_priv->hw_status_page = dmah->vaddr;
+ dev_priv->dma_status_page = dmah->busaddr;
+
+ memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
+
+ I915_WRITE(0x02080, dev_priv->dma_status_page);
+ DRM_DEBUG("Enabled hardware status page\n");
+ return 0;
+}
+
+void i915_free_hardware_status(struct drm_device *dev)
+{
+ drm_i915_private_t *dev_priv = dev->dev_private;
+ if (dev_priv->status_page_dmah) {
+ drm_pci_free(dev, dev_priv->status_page_dmah);
+ dev_priv->status_page_dmah = NULL;
+ /* Need to rewrite hardware status page */
+ I915_WRITE(0x02080, 0x1ffff000);
+ }
+
+ if (dev_priv->status_gfx_addr) {
+ dev_priv->status_gfx_addr = 0;
+ drm_core_ioremapfree(&dev_priv->hws_map, dev);
+ I915_WRITE(0x02080, 0x1ffff000);
+ }
+}
+
+#if I915_RING_VALIDATE
+/**
+ * Validate the cached ring tail value
+ *
+ * If the X server writes to the ring and DRM doesn't
+ * reload the head and tail pointers, it will end up writing
+ * data to the wrong place in the ring, causing havoc.
+ */
+void i915_ring_validate(struct drm_device *dev, const char *func, int line)
+{
+ drm_i915_private_t *dev_priv = dev->dev_private;
+ drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
+ u32 tail = I915_READ(PRB0_TAIL) & HEAD_ADDR;
+ u32 head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
+
+ if (tail != ring->tail) {
+ DRM_ERROR("%s:%d head sw %x, hw %x. tail sw %x hw %x\n",
+ func, line,
+ ring->head, head, ring->tail, tail);
+#ifdef __linux__
+ BUG_ON(1);
+#endif
+ }
+}
+#endif
+
void i915_kernel_lost_context(struct drm_device * dev)
{
drm_i915_private_t *dev_priv = dev->dev_private;
@@ -83,7 +163,7 @@ static int i915_dma_cleanup(struct drm_device * dev)
* may not have been called from userspace and after dev_private
* is freed, it's too late.
*/
- if (dev->irq)
+ if (dev->irq_enabled)
drm_irq_uninstall(dev);
if (dev_priv->ring.virtual_start) {
@@ -93,18 +173,8 @@ static int i915_dma_cleanup(struct drm_device * dev)
dev_priv->ring.map.size = 0;
}
- if (dev_priv->status_page_dmah) {
- drm_pci_free(dev, dev_priv->status_page_dmah);
- dev_priv->status_page_dmah = NULL;
- /* Need to rewrite hardware status page */
- I915_WRITE(0x02080, 0x1ffff000);
- }
-
- if (dev_priv->status_gfx_addr) {
- dev_priv->status_gfx_addr = 0;
- drm_core_ioremapfree(&dev_priv->hws_map, dev);
- I915_WRITE(0x02080, 0x1ffff000);
- }
+ if (I915_NEED_GFX_HWS(dev))
+ i915_free_hardware_status(dev);
return 0;
}
@@ -185,14 +255,6 @@ static int i915_initialize(struct drm_device * dev,
return -EINVAL;
}
- if (init->mmio_offset != 0)
- dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset);
- if (!dev_priv->mmio_map) {
- i915_dma_cleanup(dev);
- DRM_ERROR("can not find mmio map!\n");
- return -EINVAL;
- }
-
#ifdef I915_HAVE_BUFFER
dev_priv->max_validate_buffers = I915_MAX_VALIDATE_BUFFERS;
#endif
@@ -206,27 +268,27 @@ static int i915_initialize(struct drm_device * dev,
dev_priv->sarea_priv = NULL;
}
- dev_priv->ring.Start = init->ring_start;
- dev_priv->ring.End = init->ring_end;
- dev_priv->ring.Size = init->ring_size;
- dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
+ if (init->ring_size != 0) {
+ dev_priv->ring.Size = init->ring_size;
+ dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
- dev_priv->ring.map.offset = init->ring_start;
- dev_priv->ring.map.size = init->ring_size;
- dev_priv->ring.map.type = 0;
- dev_priv->ring.map.flags = 0;
- dev_priv->ring.map.mtrr = 0;
+ dev_priv->ring.map.offset = init->ring_start;
+ dev_priv->ring.map.size = init->ring_size;
+ dev_priv->ring.map.type = 0;
+ dev_priv->ring.map.flags = 0;
+ dev_priv->ring.map.mtrr = 0;
- drm_core_ioremap(&dev_priv->ring.map, dev);
+ drm_core_ioremap(&dev_priv->ring.map, dev);
- if (dev_priv->ring.map.handle == NULL) {
- i915_dma_cleanup(dev);
- DRM_ERROR("can not ioremap virtual address for"
- " ring buffer\n");
- return -ENOMEM;
- }
+ if (dev_priv->ring.map.handle == NULL) {
+ i915_dma_cleanup(dev);
+ DRM_ERROR("can not ioremap virtual address for"
+ " ring buffer\n");
+ return -ENOMEM;
+ }
- dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
+ dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
+ }
dev_priv->cpp = init->cpp;
@@ -236,9 +298,6 @@ static int i915_initialize(struct drm_device * dev,
/* We are using separate values as placeholders for mechanisms for
* private backbuffer/depthbuffer usage.
*/
- dev_priv->use_mi_batchbuffer_start = 0;
- if (IS_I965G(dev)) /* 965 doesn't support older method */
- dev_priv->use_mi_batchbuffer_start = 1;
/* Allow hardware batchbuffers unless told otherwise.
*/
@@ -248,30 +307,6 @@ static int i915_initialize(struct drm_device * dev,
*/
dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A;
- /* Program Hardware Status Page */
- if (!I915_NEED_GFX_HWS(dev)) {
- drm_dma_handle_t *dmah;
-#ifdef __FreeBSD__
- DRM_UNLOCK();
-#endif
- dmah = drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE, 0xffffffff);
-#ifdef __FreeBSD__
- DRM_LOCK();
-#endif
- if (!dmah) {
- i915_dma_cleanup(dev);
- DRM_ERROR("Can not allocate hardware status page\n");
- return -ENOMEM;
- }
- dev_priv->status_page_dmah = dmah;
- dev_priv->hw_status_page = dmah->vaddr;
- dev_priv->dma_status_page = dmah->busaddr;
-
- memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
-
- I915_WRITE(0x02080, dev_priv->dma_status_page);
- }
- DRM_DEBUG("Enabled hardware status page\n");
#ifdef I915_HAVE_BUFFER
mutex_init(&dev_priv->cmdbuf_mutex);
#endif
@@ -300,11 +335,6 @@ static int i915_dma_resume(struct drm_device * dev)
return -EINVAL;
}
- if (!dev_priv->mmio_map) {
- DRM_ERROR("can not find mmio map!\n");
- return -EINVAL;
- }
-
if (dev_priv->ring.map.handle == NULL) {
DRM_ERROR("can not ioremap virtual address for"
" ring buffer\n");
@@ -443,15 +473,20 @@ static int i915_emit_cmds(struct drm_device *dev, int __user *buffer,
for (i = 0; i < dwords;) {
int cmd, sz;
- cmd = buffer[i];
+ if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i], sizeof(cmd)))
+ return -EINVAL;
+
if ((sz = validate_cmd(cmd)) == 0 || i + sz > dwords)
return -EINVAL;
OUT_RING(cmd);
while (++i, --sz) {
+ if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i],
+ sizeof(cmd))) {
+ return -EINVAL;
+ }
OUT_RING(cmd);
- cmd = buffer[i];
}
}
@@ -463,15 +498,18 @@ static int i915_emit_cmds(struct drm_device *dev, int __user *buffer,
return 0;
}
-static int i915_emit_box(struct drm_device * dev,
- struct drm_clip_rect __user * boxes,
- int i, int DR1, int DR4)
+int i915_emit_box(struct drm_device * dev,
+ struct drm_clip_rect __user * boxes,
+ int i, int DR1, int DR4)
{
drm_i915_private_t *dev_priv = dev->dev_private;
struct drm_clip_rect box;
RING_LOCALS;
- box = boxes[i];
+ if (DRM_COPY_FROM_USER_UNCHECKED(&box, &boxes[i], sizeof(box))) {
+ return -EFAULT;
+ }
+
if (box.y2 <= box.y1 || box.x2 <= box.x1 || box.y2 <= 0 || box.x2 <= 0) {
DRM_ERROR("Bad box %d,%d..%d,%d\n",
box.x1, box.y1, box.x2, box.y2);
@@ -518,7 +556,7 @@ void i915_emit_breadcrumb(struct drm_device *dev)
BEGIN_LP_RING(4);
OUT_RING(MI_STORE_DWORD_INDEX);
- OUT_RING(20);
+ OUT_RING(5 << MI_STORE_DWORD_INDEX_SHIFT);
OUT_RING(dev_priv->counter);
OUT_RING(0);
ADVANCE_LP_RING();
@@ -611,7 +649,14 @@ int i915_dispatch_batchbuffer(struct drm_device * dev,
return ret;
}
- if (dev_priv->use_mi_batchbuffer_start) {
+ if (IS_I830(dev) || IS_845G(dev)) {
+ BEGIN_LP_RING(4);
+ OUT_RING(MI_BATCH_BUFFER);
+ OUT_RING(batch->start | MI_BATCH_NON_SECURE);
+ OUT_RING(batch->start + batch->used - 4);
+ OUT_RING(0);
+ ADVANCE_LP_RING();
+ } else {
BEGIN_LP_RING(2);
if (IS_I965G(dev)) {
OUT_RING(MI_BATCH_BUFFER_START | (2 << 6) | MI_BATCH_NON_SECURE_I965);
@@ -621,14 +666,6 @@ int i915_dispatch_batchbuffer(struct drm_device * dev,
OUT_RING(batch->start | MI_BATCH_NON_SECURE);
}
ADVANCE_LP_RING();
-
- } else {
- BEGIN_LP_RING(4);
- OUT_RING(MI_BATCH_BUFFER);
- OUT_RING(batch->start | MI_BATCH_NON_SECURE);
- OUT_RING(batch->start + batch->used - 4);
- OUT_RING(0);
- ADVANCE_LP_RING();
}
}
@@ -716,9 +753,19 @@ void i915_dispatch_flip(struct drm_device * dev, int planes, int sync)
int i915_quiescent(struct drm_device *dev)
{
drm_i915_private_t *dev_priv = dev->dev_private;
+ int ret;
i915_kernel_lost_context(dev);
- return i915_wait_ring(dev, dev_priv->ring.Size - 8, __FUNCTION__);
+ ret = i915_wait_ring(dev, dev_priv->ring.Size - 8, __FUNCTION__);
+ if (ret)
+ {
+ i915_kernel_lost_context (dev);
+ DRM_ERROR ("not quiescent head %08x tail %08x space %08x\n",
+ dev_priv->ring.head,
+ dev_priv->ring.tail,
+ dev_priv->ring.space);
+ }
+ return ret;
}
static int i915_flush_ioctl(struct drm_device *dev, void *data,
@@ -737,7 +784,6 @@ static int i915_batchbuffer(struct drm_device *dev, void *data,
drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
dev_priv->sarea_priv;
drm_i915_batchbuffer_t *batch = data;
- size_t cliplen;
int ret;
if (!dev_priv->allow_batchbuffer) {
@@ -750,29 +796,14 @@ static int i915_batchbuffer(struct drm_device *dev, void *data,
LOCK_TEST_WITH_RETURN(dev, file_priv);
- DRM_UNLOCK();
- cliplen = batch->num_cliprects * sizeof(drm_clip_rect_t);
if (batch->num_cliprects && DRM_VERIFYAREA_READ(batch->cliprects,
- cliplen)) {
- DRM_LOCK();
+ batch->num_cliprects *
+ sizeof(struct drm_clip_rect)))
return -EFAULT;
- }
- if (batch->num_cliprects) {
- ret = vslock(batch->cliprects, cliplen);
- if (ret) {
- DRM_ERROR("Fault wiring cliprects\n");
- DRM_LOCK();
- return -EFAULT;
- }
- }
- DRM_LOCK();
+
ret = i915_dispatch_batchbuffer(dev, batch);
sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
- DRM_UNLOCK();
- if (batch->num_cliprects)
- vsunlock(batch->cliprects, cliplen);
- DRM_LOCK();
return ret;
}
@@ -783,7 +814,6 @@ static int i915_cmdbuffer(struct drm_device *dev, void *data,
drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
dev_priv->sarea_priv;
drm_i915_cmdbuffer_t *cmdbuf = data;
- size_t cliplen;
int ret;
DRM_DEBUG("i915 cmdbuffer, buf %p sz %d cliprects %d\n",
@@ -791,42 +821,22 @@ static int i915_cmdbuffer(struct drm_device *dev, void *data,
LOCK_TEST_WITH_RETURN(dev, file_priv);
- DRM_UNLOCK();
- cliplen = cmdbuf->num_cliprects * sizeof(drm_clip_rect_t);
if (cmdbuf->num_cliprects &&
- DRM_VERIFYAREA_READ(cmdbuf->cliprects, cliplen)) {
+ DRM_VERIFYAREA_READ(cmdbuf->cliprects,
+ cmdbuf->num_cliprects *
+ sizeof(struct drm_clip_rect))) {
DRM_ERROR("Fault accessing cliprects\n");
- DRM_LOCK();
return -EFAULT;
}
- if (cmdbuf->num_cliprects) {
- ret = vslock(cmdbuf->cliprects, cliplen);
- if (ret) {
- DRM_ERROR("Fault wiring cliprects\n");
- DRM_LOCK();
- return -EFAULT;
- }
- ret = vslock(cmdbuf->buf, cmdbuf->sz);
- if (ret) {
- vsunlock(cmdbuf->cliprects, cliplen);
- DRM_ERROR("Fault wiring cmds\n");
- DRM_LOCK();
- return -EFAULT;
- }
- }
- DRM_LOCK();
+
ret = i915_dispatch_cmdbuffer(dev, cmdbuf);
- if (ret == 0)
- sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
- else
+ if (ret) {
DRM_ERROR("i915_dispatch_cmdbuffer failed\n");
- DRM_UNLOCK();
- if (cmdbuf->num_cliprects) {
- vsunlock(cmdbuf->buf, cmdbuf->sz);
- vsunlock(cmdbuf->cliprects, cliplen);
+ return ret;
}
- DRM_LOCK();
- return (ret);
+
+ sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
+ return 0;
}
#if defined(DRM_DEBUG_CODE)
@@ -892,7 +902,7 @@ static int i915_getparam(struct drm_device *dev, void *data,
switch (param->param) {
case I915_PARAM_IRQ_ACTIVE:
- value = dev->irq ? 1 : 0;
+ value = dev->irq_enabled ? 1 : 0;
break;
case I915_PARAM_ALLOW_BATCHBUFFER:
value = dev_priv->allow_batchbuffer ? 1 : 0;
@@ -903,6 +913,9 @@ static int i915_getparam(struct drm_device *dev, void *data,
case I915_PARAM_CHIPSET_ID:
value = dev->pci_device;
break;
+ case I915_PARAM_HAS_GEM:
+ value = 1;
+ break;
default:
DRM_ERROR("Unknown parameter %d\n", param->param);
return -EINVAL;
@@ -929,8 +942,6 @@ static int i915_setparam(struct drm_device *dev, void *data,
switch (param->param) {
case I915_SETPARAM_USE_MI_BATCHBUFFER_START:
- if (!IS_I965G(dev))
- dev_priv->use_mi_batchbuffer_start = param->value;
break;
case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY:
dev_priv->tex_lru_log_granularity = param->value;
@@ -1064,6 +1075,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
memset(dev_priv, 0, sizeof(drm_i915_private_t));
dev->dev_private = (void *)dev_priv;
+ dev_priv->dev = dev;
/* Add register map (needed for suspend/resume) */
base = drm_get_resource_start(dev, mmio_bar);
@@ -1071,7 +1083,9 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
ret = drm_addmap(dev, base, size, _DRM_REGISTERS,
_DRM_KERNEL | _DRM_DRIVER, &dev_priv->mmio_map);
-
+#ifdef I915_HAVE_GEM
+ i915_gem_load(dev);
+#endif
DRM_SPININIT(&dev_priv->swaps_lock, "swap");
DRM_SPININIT(&dev_priv->user_irq_lock, "userirq");
@@ -1084,6 +1098,13 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
#endif
#endif
+ /* Init HWS */
+ if (!I915_NEED_GFX_HWS(dev)) {
+ ret = i915_init_hardware_status(dev);
+ if(ret)
+ return ret;
+ }
+
return ret;
}
@@ -1091,8 +1112,9 @@ int i915_driver_unload(struct drm_device *dev)
{
struct drm_i915_private *dev_priv = dev->dev_private;
- if (dev_priv->mmio_map)
- drm_rmmap(dev, dev_priv->mmio_map);
+ i915_free_hardware_status(dev);
+
+ drm_rmmap(dev, dev_priv->mmio_map);
DRM_SPINUNINIT(&dev_priv->swaps_lock);
DRM_SPINUNINIT(&dev_priv->user_irq_lock);
@@ -1129,12 +1151,13 @@ void i915_driver_lastclose(struct drm_device * dev)
dev_priv->val_bufs = NULL;
}
#endif
-
- if (drm_getsarea(dev) && dev_priv->sarea_priv) {
+#ifdef I915_HAVE_GEM
+ i915_gem_lastclose(dev);
+#endif
+ if (drm_getsarea(dev) && dev_priv->sarea_priv)
i915_do_cleanup_pageflip(dev);
+ if (dev_priv->sarea_priv)
dev_priv->sarea_priv = NULL;
- dev_priv->sarea = NULL;
- }
if (dev_priv->agp_heap)
i915_mem_takedown(&(dev_priv->agp_heap));
#if defined(I915_HAVE_BUFFER)
@@ -1155,12 +1178,38 @@ void i915_driver_lastclose(struct drm_device * dev)
i915_dma_cleanup(dev);
}
+int i915_driver_open(struct drm_device *dev, struct drm_file *file_priv)
+{
+ struct drm_i915_file_private *i915_file_priv;
+
+ DRM_DEBUG("\n");
+ i915_file_priv = (struct drm_i915_file_private *)
+ drm_alloc(sizeof(*i915_file_priv), DRM_MEM_FILES);
+
+ if (!i915_file_priv)
+ return -ENOMEM;
+
+ file_priv->driver_priv = i915_file_priv;
+
+ i915_file_priv->mm.last_gem_seqno = 0;
+ i915_file_priv->mm.last_gem_throttle_seqno = 0;
+
+ return 0;
+}
+
void i915_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
{
drm_i915_private_t *dev_priv = dev->dev_private;
i915_mem_release(dev, file_priv, dev_priv->agp_heap);
}
+void i915_driver_postclose(struct drm_device *dev, struct drm_file *file_priv)
+{
+ struct drm_i915_file_private *i915_file_priv = file_priv->driver_priv;
+
+ drm_free(i915_file_priv, sizeof(*i915_file_priv), DRM_MEM_FILES);
+}
+
struct drm_ioctl_desc i915_ioctls[] = {
DRM_IOCTL_DEF(DRM_I915_INIT, i915_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
DRM_IOCTL_DEF(DRM_I915_FLUSH, i915_flush_ioctl, DRM_AUTH),
@@ -1183,6 +1232,24 @@ struct drm_ioctl_desc i915_ioctls[] = {
#ifdef I915_HAVE_BUFFER
DRM_IOCTL_DEF(DRM_I915_EXECBUFFER, i915_execbuffer, DRM_AUTH),
#endif
+#ifdef I915_HAVE_GEM
+ DRM_IOCTL_DEF(DRM_I915_GEM_INIT, i915_gem_init_ioctl, DRM_AUTH),
+ DRM_IOCTL_DEF(DRM_I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH),
+ DRM_IOCTL_DEF(DRM_I915_GEM_PIN, i915_gem_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
+ DRM_IOCTL_DEF(DRM_I915_GEM_UNPIN, i915_gem_unpin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
+ DRM_IOCTL_DEF(DRM_I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH),
+ DRM_IOCTL_DEF(DRM_I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH),
+ DRM_IOCTL_DEF(DRM_I915_GEM_ENTERVT, i915_gem_entervt_ioctl, DRM_AUTH),
+ DRM_IOCTL_DEF(DRM_I915_GEM_LEAVEVT, i915_gem_leavevt_ioctl, DRM_AUTH),
+ DRM_IOCTL_DEF(DRM_I915_GEM_CREATE, i915_gem_create_ioctl, 0),
+ DRM_IOCTL_DEF(DRM_I915_GEM_PREAD, i915_gem_pread_ioctl, 0),
+ DRM_IOCTL_DEF(DRM_I915_GEM_PWRITE, i915_gem_pwrite_ioctl, 0),
+ DRM_IOCTL_DEF(DRM_I915_GEM_MMAP, i915_gem_mmap_ioctl, 0),
+ DRM_IOCTL_DEF(DRM_I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, 0),
+ DRM_IOCTL_DEF(DRM_I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, 0),
+ DRM_IOCTL_DEF(DRM_I915_GEM_SET_TILING, i915_gem_set_tiling, 0),
+ DRM_IOCTL_DEF(DRM_I915_GEM_GET_TILING, i915_gem_get_tiling, 0),
+#endif
};
int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
diff --git a/sys/dev/drm/i915_drm.h b/sys/dev/drm/i915_drm.h
index 99092e4bd322..18db791dafa1 100644
--- a/sys/dev/drm/i915_drm.h
+++ b/sys/dev/drm/i915_drm.h
@@ -179,6 +179,22 @@ typedef struct drm_i915_sarea {
#define DRM_I915_MMIO 0x10
#define DRM_I915_HWS_ADDR 0x11
#define DRM_I915_EXECBUFFER 0x12
+#define DRM_I915_GEM_INIT 0x13
+#define DRM_I915_GEM_EXECBUFFER 0x14
+#define DRM_I915_GEM_PIN 0x15
+#define DRM_I915_GEM_UNPIN 0x16
+#define DRM_I915_GEM_BUSY 0x17
+#define DRM_I915_GEM_THROTTLE 0x18
+#define DRM_I915_GEM_ENTERVT 0x19
+#define DRM_I915_GEM_LEAVEVT 0x1a
+#define DRM_I915_GEM_CREATE 0x1b
+#define DRM_I915_GEM_PREAD 0x1c
+#define DRM_I915_GEM_PWRITE 0x1d
+#define DRM_I915_GEM_MMAP 0x1e
+#define DRM_I915_GEM_SET_DOMAIN 0x1f
+#define DRM_I915_GEM_SW_FINISH 0x20
+#define DRM_I915_GEM_SET_TILING 0x21
+#define DRM_I915_GEM_GET_TILING 0x22
#define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
#define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -198,6 +214,22 @@ typedef struct drm_i915_sarea {
#define DRM_IOCTL_I915_VBLANK_SWAP DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_VBLANK_SWAP, drm_i915_vblank_swap_t)
#define DRM_IOCTL_I915_MMIO DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_MMIO, drm_i915_mmio)
#define DRM_IOCTL_I915_EXECBUFFER DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_EXECBUFFER, struct drm_i915_execbuffer)
+#define DRM_IOCTL_I915_GEM_INIT DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_INIT, struct drm_i915_gem_init)
+#define DRM_IOCTL_I915_GEM_EXECBUFFER DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_EXECBUFFER, struct drm_i915_gem_execbuffer)
+#define DRM_IOCTL_I915_GEM_PIN DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_PIN, struct drm_i915_gem_pin)
+#define DRM_IOCTL_I915_GEM_UNPIN DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_UNPIN, struct drm_i915_gem_unpin)
+#define DRM_IOCTL_I915_GEM_BUSY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_BUSY, struct drm_i915_gem_busy)
+#define DRM_IOCTL_I915_GEM_THROTTLE DRM_IO ( DRM_COMMAND_BASE + DRM_I915_GEM_THROTTLE)
+#define DRM_IOCTL_I915_GEM_ENTERVT DRM_IO(DRM_COMMAND_BASE + DRM_I915_GEM_ENTERVT)
+#define DRM_IOCTL_I915_GEM_LEAVEVT DRM_IO(DRM_COMMAND_BASE + DRM_I915_GEM_LEAVEVT)
+#define DRM_IOCTL_I915_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_CREATE, struct drm_i915_gem_create)
+#define DRM_IOCTL_I915_GEM_PREAD DRM_IOW (DRM_COMMAND_BASE + DRM_I915_GEM_PREAD, struct drm_i915_gem_pread)
+#define DRM_IOCTL_I915_GEM_PWRITE DRM_IOW (DRM_COMMAND_BASE + DRM_I915_GEM_PWRITE, struct drm_i915_gem_pwrite)
+#define DRM_IOCTL_I915_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_MMAP, struct drm_i915_gem_mmap)
+#define DRM_IOCTL_I915_GEM_SET_DOMAIN DRM_IOW (DRM_COMMAND_BASE + DRM_I915_GEM_SET_DOMAIN, struct drm_i915_gem_set_domain)
+#define DRM_IOCTL_I915_GEM_SW_FINISH DRM_IOW (DRM_COMMAND_BASE + DRM_I915_GEM_SW_FINISH, struct drm_i915_gem_sw_finish)
+#define DRM_IOCTL_I915_GEM_SET_TILING DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_SET_TILING, struct drm_i915_gem_set_tiling)
+#define DRM_IOCTL_I915_GEM_GET_TILING DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_GET_TILING, struct drm_i915_gem_get_tiling)
/* Asynchronous page flipping:
*/
@@ -251,6 +283,7 @@ typedef struct drm_i915_irq_wait {
#define I915_PARAM_ALLOW_BATCHBUFFER 2
#define I915_PARAM_LAST_DISPATCH 3
#define I915_PARAM_CHIPSET_ID 4
+#define I915_PARAM_HAS_GEM 5
typedef struct drm_i915_getparam {
int param;
@@ -398,4 +431,292 @@ struct drm_i915_execbuffer {
struct drm_fence_arg fence_arg;
};
+struct drm_i915_gem_init {
+ /**
+ * Beginning offset in the GTT to be managed by the DRM memory
+ * manager.
+ */
+ uint64_t gtt_start;
+ /**
+ * Ending offset in the GTT to be managed by the DRM memory
+ * manager.
+ */
+ uint64_t gtt_end;
+};
+
+struct drm_i915_gem_create {
+ /**
+ * Requested size for the object.
+ *
+ * The (page-aligned) allocated size for the object will be returned.
+ */
+ uint64_t size;
+ /**
+ * Returned handle for the object.
+ *
+ * Object handles are nonzero.
+ */
+ uint32_t handle;
+ uint32_t pad;
+};
+
+struct drm_i915_gem_pread {
+ /** Handle for the object being read. */
+ uint32_t handle;
+ uint32_t pad;
+ /** Offset into the object to read from */
+ uint64_t offset;
+ /** Length of data to read */
+ uint64_t size;
+ /** Pointer to write the data into. */
+ uint64_t data_ptr; /* void *, but pointers are not 32/64 compatible */
+};
+
+struct drm_i915_gem_pwrite {
+ /** Handle for the object being written to. */
+ uint32_t handle;
+ uint32_t pad;
+ /** Offset into the object to write to */
+ uint64_t offset;
+ /** Length of data to write */
+ uint64_t size;
+ /** Pointer to read the data from. */
+ uint64_t data_ptr; /* void *, but pointers are not 32/64 compatible */
+};
+
+struct drm_i915_gem_mmap {
+ /** Handle for the object being mapped. */
+ uint32_t handle;
+ uint32_t pad;
+ /** Offset in the object to map. */
+ uint64_t offset;
+ /**
+ * Length of data to map.
+ *
+ * The value will be page-aligned.
+ */
+ uint64_t size;
+ /** Returned pointer the data was mapped at */
+ uint64_t addr_ptr; /* void *, but pointers are not 32/64 compatible */
+};
+
+struct drm_i915_gem_set_domain {
+ /** Handle for the object */
+ uint32_t handle;
+
+ /** New read domains */
+ uint32_t read_domains;
+
+ /** New write domain */
+ uint32_t write_domain;
+};
+
+struct drm_i915_gem_sw_finish {
+ /** Handle for the object */
+ uint32_t handle;
+};
+
+struct drm_i915_gem_relocation_entry {
+ /**
+ * Handle of the buffer being pointed to by this relocation entry.
+ *
+ * It's appealing to make this be an index into the mm_validate_entry
+ * list to refer to the buffer, but this allows the driver to create
+ * a relocation list for state buffers and not re-write it per
+ * exec using the buffer.
+ */
+ uint32_t target_handle;
+
+ /**
+ * Value to be added to the offset of the target buffer to make up
+ * the relocation entry.
+ */
+ uint32_t delta;
+
+ /** Offset in the buffer the relocation entry will be written into */
+ uint64_t offset;
+
+ /**
+ * Offset value of the target buffer that the relocation entry was last
+ * written as.
+ *
+ * If the buffer has the same offset as last time, we can skip syncing
+ * and writing the relocation. This value is written back out by
+ * the execbuffer ioctl when the relocation is written.
+ */
+ uint64_t presumed_offset;
+
+ /**
+ * Target memory domains read by this operation.
+ */
+ uint32_t read_domains;
+
+ /**
+ * Target memory domains written by this operation.
+ *
+ * Note that only one domain may be written by the whole
+ * execbuffer operation, so that where there are conflicts,
+ * the application will get -EINVAL back.
+ */
+ uint32_t write_domain;
+};
+
+/** @{
+ * Intel memory domains
+ *
+ * Most of these just align with the various caches in
+ * the system and are used to flush and invalidate as
+ * objects end up cached in different domains.
+ */
+/** CPU cache */
+#define I915_GEM_DOMAIN_CPU 0x00000001
+/** Render cache, used by 2D and 3D drawing */
+#define I915_GEM_DOMAIN_RENDER 0x00000002
+/** Sampler cache, used by texture engine */
+#define I915_GEM_DOMAIN_SAMPLER 0x00000004
+/** Command queue, used to load batch buffers */
+#define I915_GEM_DOMAIN_COMMAND 0x00000008
+/** Instruction cache, used by shader programs */
+#define I915_GEM_DOMAIN_INSTRUCTION 0x00000010
+/** Vertex address cache */
+#define I915_GEM_DOMAIN_VERTEX 0x00000020
+/** GTT domain - aperture and scanout */
+#define I915_GEM_DOMAIN_GTT 0x00000040
+/** @} */
+
+struct drm_i915_gem_exec_object {
+ /**
+ * User's handle for a buffer to be bound into the GTT for this
+ * operation.
+ */
+ uint32_t handle;
+
+ /** Number of relocations to be performed on this buffer */
+ uint32_t relocation_count;
+ /**
+ * Pointer to array of struct drm_i915_gem_relocation_entry containing
+ * the relocations to be performed in this buffer.
+ */
+ uint64_t relocs_ptr;
+
+ /** Required alignment in graphics aperture */
+ uint64_t alignment;
+
+ /**
+ * Returned value of the updated offset of the object, for future
+ * presumed_offset writes.
+ */
+ uint64_t offset;
+};
+
+struct drm_i915_gem_execbuffer {
+ /**
+ * List of buffers to be validated with their relocations to be
+ * performend on them.
+ *
+ * This is a pointer to an array of struct drm_i915_gem_validate_entry.
+ *
+ * These buffers must be listed in an order such that all relocations
+ * a buffer is performing refer to buffers that have already appeared
+ * in the validate list.
+ */
+ uint64_t buffers_ptr;
+ uint32_t buffer_count;
+
+ /** Offset in the batchbuffer to start execution from. */
+ uint32_t batch_start_offset;
+ /** Bytes used in batchbuffer from batch_start_offset */
+ uint32_t batch_len;
+ uint32_t DR1;
+ uint32_t DR4;
+ uint32_t num_cliprects;
+ uint64_t cliprects_ptr; /* struct drm_clip_rect *cliprects */
+};
+
+struct drm_i915_gem_pin {
+ /** Handle of the buffer to be pinned. */
+ uint32_t handle;
+ uint32_t pad;
+
+ /** alignment required within the aperture */
+ uint64_t alignment;
+
+ /** Returned GTT offset of the buffer. */
+ uint64_t offset;
+};
+
+struct drm_i915_gem_unpin {
+ /** Handle of the buffer to be unpinned. */
+ uint32_t handle;
+ uint32_t pad;
+};
+
+struct drm_i915_gem_busy {
+ /** Handle of the buffer to check for busy */
+ uint32_t handle;
+
+ /** Return busy status (1 if busy, 0 if idle) */
+ uint32_t busy;
+};
+
+#define I915_TILING_NONE 0
+#define I915_TILING_X 1
+#define I915_TILING_Y 2
+
+#define I915_BIT_6_SWIZZLE_NONE 0
+#define I915_BIT_6_SWIZZLE_9 1
+#define I915_BIT_6_SWIZZLE_9_10 2
+#define I915_BIT_6_SWIZZLE_9_11 3
+#define I915_BIT_6_SWIZZLE_9_10_11 4
+/* Not seen by userland */
+#define I915_BIT_6_SWIZZLE_UNKNOWN 5
+
+struct drm_i915_gem_set_tiling {
+ /** Handle of the buffer to have its tiling state updated */
+ uint32_t handle;
+
+ /**
+ * Tiling mode for the object (I915_TILING_NONE, I915_TILING_X,
+ * I915_TILING_Y).
+ *
+ * This value is to be set on request, and will be updated by the
+ * kernel on successful return with the actual chosen tiling layout.
+ *
+ * The tiling mode may be demoted to I915_TILING_NONE when the system
+ * has bit 6 swizzling that can't be managed correctly by GEM.
+ *
+ * Buffer contents become undefined when changing tiling_mode.
+ */
+ uint32_t tiling_mode;
+
+ /**
+ * Stride in bytes for the object when in I915_TILING_X or
+ * I915_TILING_Y.
+ */
+ uint32_t stride;
+
+ /**
+ * Returned address bit 6 swizzling required for CPU access through
+ * mmap mapping.
+ */
+ uint32_t swizzle_mode;
+};
+
+struct drm_i915_gem_get_tiling {
+ /** Handle of the buffer to get tiling state for. */
+ uint32_t handle;
+
+ /**
+ * Current tiling mode for the object (I915_TILING_NONE, I915_TILING_X,
+ * I915_TILING_Y).
+ */
+ uint32_t tiling_mode;
+
+ /**
+ * Returned address bit 6 swizzling required for CPU access through
+ * mmap mapping.
+ */
+ uint32_t swizzle_mode;
+};
+
#endif /* _I915_DRM_H_ */
diff --git a/sys/dev/drm/i915_drv.c b/sys/dev/drm/i915_drv.c
index 055643116642..945ef72cefdd 100644
--- a/sys/dev/drm/i915_drv.c
+++ b/sys/dev/drm/i915_drv.c
@@ -71,40 +71,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)
{
@@ -117,17 +113,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 }
};
@@ -149,7 +161,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/sys/dev/drm/i915_drv.h b/sys/dev/drm/i915_drv.h
index 42706cd58cb1..6342717332d7 100644
--- a/sys/dev/drm/i915_drv.h
+++ b/sys/dev/drm/i915_drv.h
@@ -40,11 +40,12 @@ __FBSDID("$FreeBSD$");
#define DRIVER_NAME "i915"
#define DRIVER_DESC "Intel Graphics"
-#define DRIVER_DATE "20080312"
+#define DRIVER_DATE "20080730"
#if defined(__linux__)
#define I915_HAVE_FENCE
#define I915_HAVE_BUFFER
+#define I915_HAVE_GEM
#endif
/* Interface history:
@@ -80,16 +81,23 @@ enum pipe {
struct drm_i915_validate_buffer;
#endif
+#define WATCH_COHERENCY 0
+#define WATCH_BUF 0
+#define WATCH_EXEC 0
+#define WATCH_LRU 0
+#define WATCH_RELOC 0
+#define WATCH_INACTIVE 0
+#define WATCH_PWRITE 0
+
typedef struct _drm_i915_ring_buffer {
int tail_mask;
- unsigned long Start;
- unsigned long End;
unsigned long Size;
u8 *virtual_start;
int head;
int tail;
int space;
drm_local_map_t map;
+ struct drm_gem_object *ring_obj;
} drm_i915_ring_buffer_t;
struct mem_block {
@@ -125,6 +133,8 @@ struct intel_opregion {
#endif
typedef struct drm_i915_private {
+ struct drm_device *dev;
+
drm_local_map_t *sarea;
drm_local_map_t *mmio_map;
@@ -137,13 +147,12 @@ typedef struct drm_i915_private {
uint32_t counter;
unsigned int status_gfx_addr;
drm_local_map_t hws_map;
+ struct drm_gem_object *hws_obj;
unsigned int cpp;
- int use_mi_batchbuffer_start;
wait_queue_head_t irq_queue;
atomic_t irq_received;
- atomic_t irq_emitted;
int tex_lru_log_granularity;
int allow_batchbuffer;
@@ -153,7 +162,7 @@ typedef struct drm_i915_private {
DRM_SPINTYPE user_irq_lock;
int user_irq_refcount;
int fence_irq_on;
- uint32_t irq_enable_reg;
+ uint32_t irq_mask_reg;
int irq_enabled;
#ifdef I915_HAVE_FENCE
@@ -270,8 +279,98 @@ typedef struct drm_i915_private {
u8 saveDACMASK;
u8 saveDACDATA[256*3]; /* 256 3-byte colors */
u8 saveCR[37];
+
+ struct {
+#ifdef __linux__
+ struct drm_mm gtt_space;
+#endif
+ /**
+ * List of objects currently involved in rendering from the
+ * ringbuffer.
+ *
+ * A reference is held on the buffer while on this list.
+ */
+ struct list_head active_list;
+
+ /**
+ * List of objects which are not in the ringbuffer but which
+ * still have a write_domain which needs to be flushed before
+ * unbinding.
+ *
+ * A reference is held on the buffer while on this list.
+ */
+ struct list_head flushing_list;
+
+ /**
+ * LRU list of objects which are not in the ringbuffer and
+ * are ready to unbind, but are still in the GTT.
+ *
+ * A reference is not held on the buffer while on this list,
+ * as merely being GTT-bound shouldn't prevent its being
+ * freed, and we'll pull it off the list in the free path.
+ */
+ struct list_head inactive_list;
+
+ /**
+ * List of breadcrumbs associated with GPU requests currently
+ * outstanding.
+ */
+ struct list_head request_list;
+#ifdef __linux__
+ /**
+ * We leave the user IRQ off as much as possible,
+ * but this means that requests will finish and never
+ * be retired once the system goes idle. Set a timer to
+ * fire periodically while the ring is running. When it
+ * fires, go retire requests.
+ */
+ struct delayed_work retire_work;
+#endif
+ uint32_t next_gem_seqno;
+
+ /**
+ * Waiting sequence number, if any
+ */
+ uint32_t waiting_gem_seqno;
+
+ /**
+ * Last seq seen at irq time
+ */
+ uint32_t irq_gem_seqno;
+
+ /**
+ * Flag if the X Server, and thus DRM, is not currently in
+ * control of the device.
+ *
+ * This is set between LeaveVT and EnterVT. It needs to be
+ * replaced with a semaphore. It also needs to be
+ * transitioned away from for kernel modesetting.
+ */
+ int suspended;
+
+ /**
+ * Flag if the hardware appears to be wedged.
+ *
+ * This is set when attempts to idle the device timeout.
+ * It prevents command submission from occuring and makes
+ * every pending request fail
+ */
+ int wedged;
+
+ /** Bit 6 swizzling required for X tiling */
+ uint32_t bit_6_swizzle_x;
+ /** Bit 6 swizzling required for Y tiling */
+ uint32_t bit_6_swizzle_y;
+ } mm;
} drm_i915_private_t;
+struct drm_i915_file_private {
+ struct {
+ uint32_t last_gem_seqno;
+ uint32_t last_gem_throttle_seqno;
+ } mm;
+};
+
enum intel_chip_family {
CHIP_I8XX = 0x01,
CHIP_I9XX = 0x02,
@@ -279,6 +378,83 @@ enum intel_chip_family {
CHIP_I965 = 0x08,
};
+/** driver private structure attached to each drm_gem_object */
+struct drm_i915_gem_object {
+ struct drm_gem_object *obj;
+
+ /** Current space allocated to this object in the GTT, if any. */
+ struct drm_mm_node *gtt_space;
+
+ /** This object's place on the active/flushing/inactive lists */
+ struct list_head list;
+
+ /**
+ * This is set if the object is on the active or flushing lists
+ * (has pending rendering), and is not set if it's on inactive (ready
+ * to be unbound).
+ */
+ int active;
+
+ /**
+ * This is set if the object has been written to since last bound
+ * to the GTT
+ */
+ int dirty;
+
+ /** AGP memory structure for our GTT binding. */
+ DRM_AGP_MEM *agp_mem;
+
+ struct page **page_list;
+
+ /**
+ * Current offset of the object in GTT space.
+ *
+ * This is the same as gtt_space->start
+ */
+ uint32_t gtt_offset;
+
+ /** Boolean whether this object has a valid gtt offset. */
+ int gtt_bound;
+
+ /** How many users have pinned this object in GTT space */
+ int pin_count;
+
+ /** Breadcrumb of last rendering to the buffer. */
+ uint32_t last_rendering_seqno;
+
+ /** Current tiling mode for the object. */
+ uint32_t tiling_mode;
+
+ /**
+ * Flagging of which individual pages are valid in GEM_DOMAIN_CPU when
+ * GEM_DOMAIN_CPU is not in the object's read domain.
+ */
+ uint8_t *page_cpu_valid;
+};
+
+/**
+ * Request queue structure.
+ *
+ * The request queue allows us to note sequence numbers that have been emitted
+ * and may be associated with active buffers to be retired.
+ *
+ * By keeping this list, we can avoid having to do questionable
+ * sequence-number comparisons on buffer last_rendering_seqnos, and associate
+ * an emission time with seqnos for tracking how far ahead of the GPU we are.
+ */
+struct drm_i915_gem_request {
+ /** GEM sequence number associated with this request. */
+ uint32_t seqno;
+
+ /** Time at which this request was emitted, in jiffies. */
+ unsigned long emitted_jiffies;
+
+ /** Cache domains that were flushed at the start of the request. */
+ uint32_t flush_domains;
+
+ struct list_head list;
+};
+
extern struct drm_ioctl_desc i915_ioctls[];
extern int i915_max_ioctl;
@@ -287,8 +463,11 @@ extern void i915_kernel_lost_context(struct drm_device * dev);
extern int i915_driver_load(struct drm_device *, unsigned long flags);
extern int i915_driver_unload(struct drm_device *);
extern void i915_driver_lastclose(struct drm_device * dev);
+extern int i915_driver_open(struct drm_device *dev, struct drm_file *file_priv);
extern void i915_driver_preclose(struct drm_device *dev,
struct drm_file *file_priv);
+extern void i915_driver_postclose(struct drm_device *dev,
+ struct drm_file *file_priv);
extern int i915_driver_device_is_agp(struct drm_device * dev);
extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg);
@@ -299,6 +478,12 @@ extern int i915_driver_firstopen(struct drm_device *dev);
extern int i915_dispatch_batchbuffer(struct drm_device * dev,
drm_i915_batchbuffer_t * batch);
extern int i915_quiescent(struct drm_device *dev);
+extern int i915_init_hardware_status(struct drm_device *dev);
+extern void i915_free_hardware_status(struct drm_device *dev);
+
+int i915_emit_box(struct drm_device * dev,
+ struct drm_clip_rect __user * boxes,
+ int i, int DR1, int DR4);
/* i915_irq.c */
extern int i915_irq_emit(struct drm_device *dev, void *data,
@@ -315,6 +500,7 @@ extern int i915_vblank_pipe_set(struct drm_device *dev, void *data,
extern int i915_vblank_pipe_get(struct drm_device *dev, void *data,
struct drm_file *file_priv);
extern int i915_emit_irq(struct drm_device * dev);
+extern int i915_wait_irq(struct drm_device * dev, int irq_nr);
extern int i915_enable_vblank(struct drm_device *dev, int crtc);
extern void i915_disable_vblank(struct drm_device *dev, int crtc);
extern u32 i915_get_vblank_counter(struct drm_device *dev, int crtc);
@@ -363,8 +549,66 @@ void i915_flush_ttm(struct drm_ttm *ttm);
/* i915_execbuf.c */
int i915_execbuffer(struct drm_device *dev, void *data,
struct drm_file *file_priv);
+/* i915_gem.c */
+int i915_gem_init_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_create_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_execbuffer(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_pin_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_entervt_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_leavevt_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_set_tiling(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int i915_gem_get_tiling(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+void i915_gem_load(struct drm_device *dev);
+int i915_gem_proc_init(struct drm_minor *minor);
+void i915_gem_proc_cleanup(struct drm_minor *minor);
+int i915_gem_init_object(struct drm_gem_object *obj);
+void i915_gem_free_object(struct drm_gem_object *obj);
+int i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment);
+void i915_gem_object_unpin(struct drm_gem_object *obj);
+void i915_gem_lastclose(struct drm_device *dev);
+uint32_t i915_get_gem_seqno(struct drm_device *dev);
+void i915_gem_retire_requests(struct drm_device *dev);
+void i915_gem_retire_work_handler(struct work_struct *work);
+void i915_gem_clflush_object(struct drm_gem_object *obj);
+#endif
+/* i915_gem_tiling.c */
+void i915_gem_detect_bit_6_swizzle(struct drm_device *dev);
+
+/* i915_gem_debug.c */
+#if WATCH_INACTIVE
+void i915_verify_inactive(struct drm_device *dev, char *file, int line);
+#else
+#define i915_verify_inactive(dev,file,line)
#endif
+void i915_gem_object_check_coherency(struct drm_gem_object *obj, int handle);
+void i915_gem_dump_object(struct drm_gem_object *obj, int len,
+ const char *where, uint32_t mark);
+void i915_dump_lru(struct drm_device *dev, const char *where);
#ifdef __linux__
/* i915_opregion.c */
@@ -393,16 +637,25 @@ typedef boolean_t bool;
#endif
#define I915_VERBOSE 0
+#define I915_RING_VALIDATE 0
#define PRIMARY_RINGBUFFER_SIZE (128*1024)
#define RING_LOCALS unsigned int outring, ringmask, outcount; \
volatile char *virt;
+#if I915_RING_VALIDATE
+void i915_ring_validate(struct drm_device *dev, const char *func, int line);
+#define I915_RING_DO_VALIDATE(dev) i915_ring_validate(dev, __FUNCTION__, __LINE__)
+#else
+#define I915_RING_DO_VALIDATE(dev)
+#endif
+
#define BEGIN_LP_RING(n) do { \
if (I915_VERBOSE) \
DRM_DEBUG("BEGIN_LP_RING(%d)\n", \
(n)); \
+ I915_RING_DO_VALIDATE(dev); \
if (dev_priv->ring.space < (n)*4) \
i915_wait_ring(dev, (n)*4, __FUNCTION__); \
outcount = 0; \
@@ -421,6 +674,7 @@ typedef boolean_t bool;
#define ADVANCE_LP_RING() do { \
if (I915_VERBOSE) DRM_DEBUG("ADVANCE_LP_RING %x\n", outring); \
+ I915_RING_DO_VALIDATE(dev); \
dev_priv->ring.tail = outring; \
dev_priv->ring.space -= outcount * 4; \
I915_WRITE(PRB0_TAIL, outring); \
@@ -428,6 +682,39 @@ typedef boolean_t bool;
extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
+#define BREADCRUMB_BITS 31
+#define BREADCRUMB_MASK ((1U << BREADCRUMB_BITS) - 1)
+
+#define READ_BREADCRUMB(dev_priv) (((volatile u32*)(dev_priv->hw_status_page))[5])
+/**
+ * Reads a dword out of the status page, which is written to from the command
+ * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
+ * MI_STORE_DATA_IMM.
+ *
+ * The following dwords have a reserved meaning:
+ * 0: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
+ * 4: ring 0 head pointer
+ * 5: ring 1 head pointer (915-class)
+ * 6: ring 2 head pointer (915-class)
+ *
+ * The area from dword 0x10 to 0x3ff is available for driver usage.
+ */
+#define READ_HWSP(dev_priv, reg) (((volatile u32*)(dev_priv->hw_status_page))[reg])
+#define I915_GEM_HWS_INDEX 0x10
+
+/* MCH MMIO space */
+/** 915-945 and GM965 MCH register controlling DRAM channel access */
+#define DCC 0x200
+#define DCC_ADDRESSING_MODE_SINGLE_CHANNEL (0 << 0)
+#define DCC_ADDRESSING_MODE_DUAL_CHANNEL_ASYMMETRIC (1 << 0)
+#define DCC_ADDRESSING_MODE_DUAL_CHANNEL_INTERLEAVED (2 << 0)
+#define DCC_ADDRESSING_MODE_MASK (3 << 0)
+#define DCC_CHANNEL_XOR_DISABLE (1 << 10)
+
+/** 965 MCH register controlling DRAM channel configuration */
+#define CHDECMISC 0x111
+#define CHDECMISC_FLEXMEMORY (1 << 1)
+
/*
* The Bridge device's PCI config space has information about the
* fb aperture size and the amount of pre-reserved memory.
@@ -528,33 +815,13 @@ extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
#define MI_STORE_DWORD_IMM MI_INSTR(0x20, 1)
#define MI_MEM_VIRTUAL (1 << 22) /* 965+ only */
#define MI_STORE_DWORD_INDEX MI_INSTR(0x21, 1)
+#define MI_STORE_DWORD_INDEX_SHIFT 2
#define MI_LOAD_REGISTER_IMM MI_INSTR(0x22, 1)
#define MI_BATCH_BUFFER MI_INSTR(0x30, 1)
#define MI_BATCH_NON_SECURE (1)
#define MI_BATCH_NON_SECURE_I965 (1<<8)
#define MI_BATCH_BUFFER_START MI_INSTR(0x31, 0)
-#define BREADCRUMB_BITS 31
-#define BREADCRUMB_MASK ((1U << BREADCRUMB_BITS) - 1)
-
-#define READ_BREADCRUMB(dev_priv) (((volatile u32*)(dev_priv->hw_status_page))[5])
-
-/**
- * Reads a dword out of the status page, which is written to from the command
- * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
- * MI_STORE_DATA_IMM.
- *
- * The following dwords have a reserved meaning:
- * 0: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
- * 4: ring 0 head pointer
- * 5: ring 1 head pointer (915-class)
- * 6: ring 2 head pointer (915-class)
- *
- * The area from dword 0x10 to 0x3ff is available for driver usage.
- */
-#define READ_HWSP(dev_priv, reg) (((volatile u32*)(dev_priv->hw_status_page))[reg])
-#define I915_GEM_HWS_INDEX 0x10
-
/*
* 3D instructions used by the kernel
*/
@@ -577,6 +844,7 @@ extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
#define GFX_OP_STIPPLE ((0x3<<29)|(0x1d<<24)|(0x83<<16))
#define GFX_OP_MAP_INFO ((0x3<<29)|(0x1d<<24)|0x4)
#define GFX_OP_DESTBUFFER_VARS ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
+#define GFX_OP_DESTBUFFER_INFO ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1)
#define GFX_OP_DRAWRECT_INFO ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
#define GFX_OP_DRAWRECT_INFO_I965 ((0x7900<<16)|0x2)
#define SRC_COPY_BLT_CMD ((2<<29)|(0x43<<22)|4)
@@ -620,7 +888,10 @@ extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
#define PRB1_HEAD 0x02044 /* 915+ only */
#define PRB1_START 0x02048 /* 915+ only */
#define PRB1_CTL 0x0204c /* 915+ only */
+#define ACTHD_I965 0x02074
#define HWS_PGA 0x02080
+#define HWS_ADDRESS_MASK 0xfffff000
+#define HWS_START_ADDRESS_SHIFT 4
#define IPEIR 0x02088
#define NOPID 0x02094
#define HWSTAM 0x02098
@@ -650,6 +921,7 @@ extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
#define EMR 0x020b4
#define ESR 0x020b8
#define INSTPM 0x020c0
+#define ACTHD 0x020c8
#define FW_BLC 0x020d8
#define FW_BLC_SELF 0x020e0 /* 915+ only */
#define MI_ARB_STATE 0x020e4 /* 915+ only */
@@ -699,7 +971,6 @@ extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
/*
* GPIO regs
*/
-
#define GPIOA 0x5010
#define GPIOB 0x5014
#define GPIOC 0x5018
diff --git a/sys/dev/drm/i915_irq.c b/sys/dev/drm/i915_irq.c
index 99e22c449148..4fd082e39d3b 100644
--- a/sys/dev/drm/i915_irq.c
+++ b/sys/dev/drm/i915_irq.c
@@ -36,6 +36,33 @@ __FBSDID("$FreeBSD$");
#define MAX_NOPID ((u32)~0)
+/*
+ * These are the interrupts used by the driver
+ */
+#define I915_INTERRUPT_ENABLE_MASK (I915_USER_INTERRUPT | \
+ I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \
+ I915_DISPLAY_PIPE_B_EVENT_INTERRUPT)
+
+static inline void
+i915_enable_irq(drm_i915_private_t *dev_priv, uint32_t mask)
+{
+ if ((dev_priv->irq_mask_reg & mask) != 0) {
+ dev_priv->irq_mask_reg &= ~mask;
+ I915_WRITE(IMR, dev_priv->irq_mask_reg);
+ (void) I915_READ(IMR);
+ }
+}
+
+static inline void
+i915_disable_irq(drm_i915_private_t *dev_priv, uint32_t mask)
+{
+ if ((dev_priv->irq_mask_reg & mask) != mask) {
+ dev_priv->irq_mask_reg |= mask;
+ I915_WRITE(IMR, dev_priv->irq_mask_reg);
+ (void) I915_READ(IMR);
+ }
+}
+
/**
* i915_get_pipe - return the the pipe associated with a given plane
* @dev: DRM device
@@ -406,12 +433,26 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
struct drm_device *dev = (struct drm_device *) arg;
drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
u32 iir;
- u32 pipea_stats, pipeb_stats;
+ u32 pipea_stats = 0, pipeb_stats = 0;
int vblank = 0;
-
+#ifdef __linux__
+ if (dev->pdev->msi_enabled)
+ I915_WRITE(IMR, ~0);
+#endif
iir = I915_READ(IIR);
- if (iir == 0)
+#if 0
+ DRM_DEBUG("flag=%08x\n", iir);
+#endif
+ atomic_inc(&dev_priv->irq_received);
+ if (iir == 0) {
+#ifdef __linux__
+ if (dev->pdev->msi_enabled) {
+ I915_WRITE(IMR, dev_priv->irq_mask_reg);
+ (void) I915_READ(IMR);
+ }
+#endif
return IRQ_NONE;
+ }
/*
* Clear the PIPE(A|B)STAT regs before the IIR otherwise
@@ -425,7 +466,6 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
vblank++;
drm_handle_vblank(dev, i915_get_plane(dev, 0));
}
-
I915_WRITE(PIPEASTAT, pipea_stats);
}
if (iir & I915_DISPLAY_PIPE_B_EVENT_INTERRUPT) {
@@ -465,9 +505,16 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
I915_WRITE(IIR, iir);
- (void) I915_READ(IIR);
+#ifdef __linux__
+ if (dev->pdev->msi_enabled)
+ I915_WRITE(IMR, dev_priv->irq_mask_reg);
+#endif
+ (void) I915_READ(IIR); /* Flush posted writes */
if (iir & I915_USER_INTERRUPT) {
+#ifdef I915_HAVE_GEM
+ dev_priv->mm.irq_gem_seqno = i915_get_gem_seqno(dev);
+#endif
DRM_WAKEUP(&dev_priv->irq_queue);
#ifdef I915_HAVE_FENCE
i915_fence_handler(dev);
@@ -504,35 +551,42 @@ int i915_emit_irq(struct drm_device *dev)
void i915_user_irq_on(drm_i915_private_t *dev_priv)
{
DRM_SPINLOCK(&dev_priv->user_irq_lock);
- if (dev_priv->irq_enabled && (++dev_priv->user_irq_refcount == 1)){
- dev_priv->irq_enable_reg |= I915_USER_INTERRUPT;
- I915_WRITE(IER, dev_priv->irq_enable_reg);
- }
+ if (dev_priv->irq_enabled && (++dev_priv->user_irq_refcount == 1))
+ i915_enable_irq(dev_priv, I915_USER_INTERRUPT);
DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
-
}
void i915_user_irq_off(drm_i915_private_t *dev_priv)
{
DRM_SPINLOCK(&dev_priv->user_irq_lock);
- if (dev_priv->irq_enabled && (--dev_priv->user_irq_refcount == 0)) {
- // dev_priv->irq_enable_reg &= ~I915_USER_INTERRUPT;
- // I915_WRITE(IER, dev_priv->irq_enable_reg);
- }
+#ifdef __linux__
+ BUG_ON(dev_priv->irq_enabled && dev_priv->user_irq_refcount <= 0);
+#endif
+ if (dev_priv->irq_enabled && (--dev_priv->user_irq_refcount == 0))
+ i915_disable_irq(dev_priv, I915_USER_INTERRUPT);
DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
}
-static int i915_wait_irq(struct drm_device * dev, int irq_nr)
+int i915_wait_irq(struct drm_device * dev, int irq_nr)
{
drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
int ret = 0;
+ if (!dev_priv) {
+ DRM_ERROR("called with no initialization\n");
+ return -EINVAL;
+ }
+
DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr,
READ_BREADCRUMB(dev_priv));
- if (READ_BREADCRUMB(dev_priv) >= irq_nr)
+ if (READ_BREADCRUMB(dev_priv) >= irq_nr) {
+ if (dev_priv->sarea_priv)
+ dev_priv->sarea_priv->last_dispatch =
+ READ_BREADCRUMB(dev_priv);
return 0;
+ }
i915_user_irq_on(dev_priv);
DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
@@ -597,16 +651,17 @@ int i915_enable_vblank(struct drm_device *dev, int plane)
drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
int pipe = i915_get_pipe(dev, plane);
u32 pipestat_reg = 0;
+ u32 mask_reg = 0;
u32 pipestat;
switch (pipe) {
case 0:
pipestat_reg = PIPEASTAT;
- dev_priv->irq_enable_reg |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
+ mask_reg |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
break;
case 1:
pipestat_reg = PIPEBSTAT;
- dev_priv->irq_enable_reg |= I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
+ mask_reg |= I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
break;
default:
DRM_ERROR("tried to enable vblank on non-existent pipe %d\n",
@@ -632,7 +687,9 @@ int i915_enable_vblank(struct drm_device *dev, int plane)
PIPE_VBLANK_INTERRUPT_STATUS);
I915_WRITE(pipestat_reg, pipestat);
}
- I915_WRITE(IER, dev_priv->irq_enable_reg);
+ DRM_SPINLOCK(&dev_priv->user_irq_lock);
+ i915_enable_irq(dev_priv, mask_reg);
+ DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
return 0;
}
@@ -642,16 +699,17 @@ void i915_disable_vblank(struct drm_device *dev, int plane)
drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
int pipe = i915_get_pipe(dev, plane);
u32 pipestat_reg = 0;
+ u32 mask_reg = 0;
u32 pipestat;
switch (pipe) {
case 0:
pipestat_reg = PIPEASTAT;
- dev_priv->irq_enable_reg &= ~I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
+ mask_reg |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
break;
case 1:
pipestat_reg = PIPEBSTAT;
- dev_priv->irq_enable_reg &= ~I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
+ mask_reg |= I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
break;
default:
DRM_ERROR("tried to disable vblank on non-existent pipe %d\n",
@@ -659,7 +717,9 @@ void i915_disable_vblank(struct drm_device *dev, int plane)
break;
}
- I915_WRITE(IER, dev_priv->irq_enable_reg);
+ DRM_SPINLOCK(&dev_priv->user_irq_lock);
+ i915_disable_irq(dev_priv, mask_reg);
+ DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
if (pipestat_reg)
{
@@ -672,14 +732,18 @@ void i915_disable_vblank(struct drm_device *dev, int plane)
pipestat |= (PIPE_START_VBLANK_INTERRUPT_STATUS |
PIPE_VBLANK_INTERRUPT_STATUS);
I915_WRITE(pipestat_reg, pipestat);
+ (void) I915_READ(pipestat_reg);
}
}
static void i915_enable_interrupt (struct drm_device *dev)
{
drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
-
- dev_priv->irq_enable_reg |= I915_USER_INTERRUPT;
+
+ dev_priv->irq_mask_reg = ~0;
+ I915_WRITE(IMR, dev_priv->irq_mask_reg);
+ I915_WRITE(IER, I915_INTERRUPT_ENABLE_MASK);
+ (void) I915_READ (IER);
#ifdef __linux__
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)
@@ -687,7 +751,6 @@ static void i915_enable_interrupt (struct drm_device *dev)
#endif
#endif
- I915_WRITE(IER, dev_priv->irq_enable_reg);
dev_priv->irq_enabled = 1;
}
@@ -901,7 +964,7 @@ int i915_driver_irq_postinstall(struct drm_device * dev)
dev_priv->swaps_pending = 0;
dev_priv->user_irq_refcount = 0;
- dev_priv->irq_enable_reg = 0;
+ dev_priv->irq_mask_reg = ~0;
ret = drm_vblank_init(dev, num_pipes);
if (ret)
diff --git a/sys/dev/drm/i915_suspend.c b/sys/dev/drm/i915_suspend.c
index 5e518ee5a8c6..9f8fad6f288c 100644
--- a/sys/dev/drm/i915_suspend.c
+++ b/sys/dev/drm/i915_suspend.c
@@ -1,4 +1,6 @@
-/*-
+/* i915_suspend.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
+ */
+/*
*
* Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
diff --git a/sys/dev/drm/mach64_drv.c b/sys/dev/drm/mach64_drv.c
index 11d243799c4c..24e8e6302906 100644
--- a/sys/dev/drm/mach64_drv.c
+++ b/sys/dev/drm/mach64_drv.c
@@ -49,36 +49,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)
{
@@ -91,15 +87,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 }
};
@@ -117,7 +129,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/sys/dev/drm/mga_drv.c b/sys/dev/drm/mga_drv.c
index e5de7d7c3498..049d54bb989b 100644
--- a/sys/dev/drm/mga_drv.c
+++ b/sys/dev/drm/mga_drv.c
@@ -89,42 +89,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)
{
@@ -137,15 +131,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 }
};
@@ -163,12 +173,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/sys/dev/drm/r128_drv.c b/sys/dev/drm/r128_drv.c
index a290d22cf3a1..93cdefe34594 100644
--- a/sys/dev/drm/r128_drv.c
+++ b/sys/dev/drm/r128_drv.c
@@ -47,38 +47,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)
{
@@ -91,15 +86,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 }
};
@@ -117,12 +128,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/sys/dev/drm/radeon_cp.c b/sys/dev/drm/radeon_cp.c
index 401a094188ca..e1570c94ddc9 100644
--- a/sys/dev/drm/radeon_cp.c
+++ b/sys/dev/drm/radeon_cp.c
@@ -631,9 +631,6 @@ static void radeon_cp_init_ring_buffer(struct drm_device * dev,
dev_priv->ring.size_l2qw);
#endif
- /* Start with assuming that writeback doesn't work */
- dev_priv->writeback_works = 0;
-
/* Initialize the scratch register pointer. This will cause
* the scratch register values to be written out to memory
* whenever they are updated.
@@ -1190,6 +1187,9 @@ static int radeon_do_init_cp(struct drm_device * dev, drm_radeon_init_t * init)
radeon_set_pcigart(dev_priv, 1);
}
+ /* Start with assuming that writeback doesn't work */
+ dev_priv->writeback_works = 0;
+
radeon_cp_load_microcode(dev_priv);
radeon_cp_init_ring_buffer(dev, dev_priv);
diff --git a/sys/dev/drm/radeon_drv.c b/sys/dev/drm/radeon_drv.c
index 96107e584272..5a4409390caf 100644
--- a/sys/dev/drm/radeon_drv.c
+++ b/sys/dev/drm/radeon_drv.c
@@ -47,44 +47,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)
{
@@ -97,15 +91,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 }
};
@@ -123,12 +133,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/sys/dev/drm/savage_drv.c b/sys/dev/drm/savage_drv.c
index 25c75db063af..3ce895b1a5aa 100644
--- a/sys/dev/drm/savage_drv.c
+++ b/sys/dev/drm/savage_drv.c
@@ -42,31 +42,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)
{
@@ -79,15 +77,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 }
};
@@ -105,7 +119,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/sys/dev/drm/sis_drv.c b/sys/dev/drm/sis_drv.c
index a07f60a2f2ad..6c6d02df8bdb 100644
--- a/sys/dev/drm/sis_drv.c
+++ b/sys/dev/drm/sis_drv.c
@@ -41,25 +41,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)
{
@@ -72,15 +71,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 }
};
@@ -98,12 +113,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/sys/dev/drm/tdfx_drv.c b/sys/dev/drm/tdfx_drv.c
index 5910cdcbdc5a..511f9eaf629f 100644
--- a/sys/dev/drm/tdfx_drv.c
+++ b/sys/dev/drm/tdfx_drv.c
@@ -46,21 +46,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)
{
@@ -73,15 +73,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 }
};
@@ -99,12 +115,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