summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/dev/pci/drm/drmP.h152
-rw-r--r--sys/dev/pci/drm/drm_crtc.c4
-rw-r--r--sys/dev/pci/drm/drm_drv.c141
-rw-r--r--sys/dev/pci/drm/i915/i915_drv.c6
-rw-r--r--sys/dev/pci/drm/i915/i915_gem_execbuffer.c4
-rw-r--r--sys/dev/pci/drm/radeon/radeon_kms.c9
6 files changed, 66 insertions, 250 deletions
diff --git a/sys/dev/pci/drm/drmP.h b/sys/dev/pci/drm/drmP.h
index d671f825f27..c989e57e9f9 100644
--- a/sys/dev/pci/drm/drmP.h
+++ b/sys/dev/pci/drm/drmP.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: drmP.h,v 1.207 2016/04/07 20:33:24 kettenis Exp $ */
+/* $OpenBSD: drmP.h,v 1.208 2016/04/08 08:27:53 kettenis Exp $ */
/* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
* Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com
*/
@@ -75,6 +75,22 @@
#include "drm_atomic.h"
#include "agp.h"
+/***********************************************************************/
+/** \name DRM template customization defaults */
+/*@{*/
+
+/* driver capabilities and requirements mask */
+#define DRIVER_USE_AGP 0x1
+#define DRIVER_PCI_DMA 0x8
+#define DRIVER_SG 0x10
+#define DRIVER_HAVE_DMA 0x20
+#define DRIVER_HAVE_IRQ 0x40
+#define DRIVER_IRQ_SHARED 0x80
+#define DRIVER_GEM 0x1000
+#define DRIVER_MODESET 0x2000
+#define DRIVER_PRIME 0x4000
+#define DRIVER_RENDER 0x8000
+
#define DRM_DEBUGBITS_DEBUG 0x1
#define DRM_DEBUGBITS_KMS 0x2
#define DRM_DEBUGBITS_FAILED_IOCTL 0x4
@@ -287,18 +303,6 @@ struct drm_ioctl_desc {
#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
[DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl}
-struct drm_buf {
- int idx; /* Index into master buflist */
- int total; /* Buffer size */
- int used; /* Amount of buffer in use (for DMA) */
- unsigned long offset; /* Byte offset (used internally) */
- void *address; /* KVA of buffer */
- unsigned long bus_address; /* Bus address of buffer */
- __volatile__ int pending; /* On hardware DMA queue */
- struct drm_file *file_priv; /* Unique identifier of holding process */
- void *dev_private; /* Per-buffer private storage */
-};
-
struct drm_dmamem {
bus_dmamap_t map;
caddr_t kva;
@@ -308,15 +312,6 @@ struct drm_dmamem {
};
typedef struct drm_dmamem drm_dma_handle_t;
-struct drm_buf_entry {
- struct drm_dmamem **seglist;
- struct drm_buf *buflist;
- int buf_count;
- int buf_size;
- int page_order;
- int seg_count;
-};
-
struct drm_pending_event {
struct drm_event *event;
struct list_head link;
@@ -326,24 +321,16 @@ struct drm_pending_event {
void (*destroy)(struct drm_pending_event *event);
};
+/** File private data */
struct drm_file {
- wait_queue_head_t event_wait;
- struct list_head event_list;
- int event_space;
-
- struct selinfo rsel;
- SPLAY_ENTRY(drm_file) link;
- int authenticated;
+ unsigned always_authenticated :1;
+ unsigned authenticated :1;
+ unsigned is_master :1; /* this file private is a master for a minor */
/* true when the client has asked us to expose stereo 3D mode flags */
- int stereo_allowed;
- unsigned long ioctl_count;
- dev_t kdev;
- drm_magic_t magic;
- int flags;
- int master;
- int minor;
- struct list_head fbs;
- struct rwlock fbs_lock;
+ unsigned stereo_allowed :1;
+
+ drm_magic_t magic;
+ int minor;
/** Mapping of mm object handles to object pointers. */
struct idr object_idr;
@@ -352,36 +339,22 @@ struct drm_file {
struct file *filp;
void *driver_priv;
-};
-/* This structure, in the struct drm_device, is always initialized while
- * the device is open. dev->dma_lock protects the incrementing of
- * dev->buf_use, which when set marks that no further bufs may be allocated
- * until device teardown occurs (when the last open of the device has closed).
- * The high/low watermarks of bufs are only touched by the X Server, and thus
- * not concurrently accessed, so no locking is needed.
- */
-struct drm_device_dma {
- struct rwlock dma_lock;
- struct drm_buf_entry bufs[DRM_MAX_ORDER+1];
- struct drm_buf **buflist; /* Vector of pointers info bufs*/
- unsigned long *pagelist;
- unsigned long byte_count;
- int buf_use; /* Buffers used no more alloc */
- int buf_count;
- int page_count;
- int seg_count;
- enum {
- _DRM_DMA_USE_AGP = 0x01,
- _DRM_DMA_USE_SG = 0x02
- } flags;
-};
+ /**
+ * fbs - List of framebuffers associated with this file.
+ *
+ * Protected by fbs_lock. Note that the fbs list holds a reference on
+ * the fb object to prevent it from untimely disappearing.
+ */
+ struct list_head fbs;
+ struct rwlock fbs_lock;
+
+ wait_queue_head_t event_wait;
+ struct list_head event_list;
+ int event_space;
-struct drm_agp_mem {
- void *handle;
- unsigned long bound; /* address */
- int pages;
- TAILQ_ENTRY(drm_agp_mem) link;
+ struct selinfo rsel;
+ SPLAY_ENTRY(drm_file) link;
};
struct drm_agp_head {
@@ -398,30 +371,6 @@ struct drm_agp_head {
int mtrr;
};
-struct drm_local_map {
- TAILQ_ENTRY(drm_local_map) link; /* Link for map list */
- struct drm_dmamem *dmamem;/* Handle to DMA mem */
- void *handle;/* KVA, if mapped */
- bus_space_tag_t bst; /* Tag for mapped pci mem */
- bus_space_handle_t bsh; /* Handle to mapped pci mem */
- u_long ext; /* extent for mmap */
- u_long offset;/* Physical address */
- u_long size; /* Physical size (bytes) */
- int mtrr; /* Boolean: MTRR used */
- enum drm_map_flags flags; /* Flags */
- enum drm_map_type type; /* Type of memory mapped */
-};
-
-/* Heap implementation for radeon and i915 legacy */
-TAILQ_HEAD(drm_heap, drm_mem);
-
-struct drm_mem {
- TAILQ_ENTRY(drm_mem) link;
- struct drm_file *file_priv; /* NULL: free, other: real files */
- int start;
- int size;
-};
-
/* location of GART table */
#define DRM_ATI_GART_MAIN 1
#define DRM_ATI_GART_FB 2
@@ -564,22 +513,10 @@ struct drm_driver_info {
const char *desc; /* Longer driver name */
const char *date; /* Date of last major changes. */
+ u32 driver_features;
const struct drm_ioctl_desc *ioctls;
int num_ioctls;
-#define DRIVER_AGP 0x1
-#define DRIVER_AGP_REQUIRE 0x2
-#define DRIVER_PCI_DMA 0x8
-#define DRIVER_SG 0x10
-#define DRIVER_HAVE_DMA 0x20
-#define DRIVER_HAVE_IRQ 0x40
-#define DRIVER_IRQ_SHARED 0x80
-#define DRIVER_GEM 0x1000
-#define DRIVER_MODESET 0x2000
-#define DRIVER_PRIME 0x4000
-
- u_int flags;
-#define driver_features flags
};
#include "drm_crtc.h"
@@ -655,13 +592,6 @@ struct drm_device {
SPLAY_HEAD(drm_file_tree, drm_file) files;
drm_magic_t magicid;
- /* Linked list of mappable regions. Protected by struct_mutex */
- struct extent *handle_ext;
- TAILQ_HEAD(drm_map_list, drm_local_map) maplist;
-
- /* DMA queues (contexts) */
- struct drm_device_dma *dma; /* Optional pointer for DMA support */
-
/* Context support */
int irq_enabled; /* True if the irq handler is enabled */
@@ -933,7 +863,7 @@ int drm_gem_dumb_destroy(struct drm_file *file,
static __inline__ int drm_core_check_feature(struct drm_device *dev,
int feature)
{
- return ((dev->driver->flags & feature) ? 1 : 0);
+ return ((dev->driver->driver_features & feature) ? 1 : 0);
}
static inline int drm_dev_to_irq(struct drm_device *dev)
diff --git a/sys/dev/pci/drm/drm_crtc.c b/sys/dev/pci/drm/drm_crtc.c
index c7108620b21..a7e5bfc0d7d 100644
--- a/sys/dev/pci/drm/drm_crtc.c
+++ b/sys/dev/pci/drm/drm_crtc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: drm_crtc.c,v 1.22 2016/04/07 20:33:24 kettenis Exp $ */
+/* $OpenBSD: drm_crtc.c,v 1.23 2016/04/08 08:27:53 kettenis Exp $ */
/*
* Copyright (c) 2006-2008 Intel Corporation
* Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
@@ -2759,7 +2759,7 @@ int drm_mode_getfb(struct drm_device *dev,
r->bpp = fb->bits_per_pixel;
r->pitch = fb->pitches[0];
if (fb->funcs->create_handle) {
- if (file_priv->master || capable(CAP_SYS_ADMIN)) {
+ if (file_priv->is_master || capable(CAP_SYS_ADMIN)) {
ret = fb->funcs->create_handle(fb, file_priv,
&r->handle);
} else {
diff --git a/sys/dev/pci/drm/drm_drv.c b/sys/dev/pci/drm/drm_drv.c
index b67b38cbd86..58fe240600c 100644
--- a/sys/dev/pci/drm/drm_drv.c
+++ b/sys/dev/pci/drm/drm_drv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: drm_drv.c,v 1.146 2016/04/05 08:22:50 kettenis Exp $ */
+/* $OpenBSD: drm_drv.c,v 1.147 2016/04/08 08:27:53 kettenis Exp $ */
/*-
* Copyright 2007-2009 Owain G. Ainsworth <oga@openbsd.org>
* Copyright © 2008 Intel Corporation
@@ -418,31 +418,14 @@ drm_attach(struct device *parent, struct device *self, void *aux)
mtx_init(&dev->event_lock, IPL_TTY);
mtx_init(&dev->quiesce_mtx, IPL_NONE);
- TAILQ_INIT(&dev->maplist);
SPLAY_INIT(&dev->files);
INIT_LIST_HEAD(&dev->vblank_event_list);
- /*
- * the dma buffers api is just weird. offset 1Gb to ensure we don't
- * conflict with it.
- */
- dev->handle_ext = extent_create("drmext", 1024*1024*1024, LONG_MAX,
- M_DRM, NULL, 0, EX_NOWAIT | EX_NOCOALESCE);
- if (dev->handle_ext == NULL) {
- DRM_ERROR("Failed to initialise handle extent\n");
- goto error;
- }
-
- if (dev->driver->flags & DRIVER_AGP) {
+ if (drm_core_check_feature(dev, DRIVER_USE_AGP)) {
#if __OS_HAS_AGP
if (da->is_agp)
dev->agp = drm_agp_init();
#endif
- if (dev->driver->flags & DRIVER_AGP_REQUIRE &&
- dev->agp == NULL) {
- printf(": couldn't find agp\n");
- goto error;
- }
if (dev->agp != NULL) {
if (drm_mtrr_add(dev->agp->info.ai_aperture_base,
dev->agp->info.ai_aperture_size, DRM_MTRR_WC) == 0)
@@ -450,14 +433,14 @@ drm_attach(struct device *parent, struct device *self, void *aux)
}
}
- if (dev->driver->flags & DRIVER_GEM) {
+ if (dev->driver->driver_features & DRIVER_GEM) {
KASSERT(dev->driver->gem_size >= sizeof(struct drm_gem_object));
/* XXX unique name */
pool_init(&dev->objpl, dev->driver->gem_size, 0, 0, 0,
"drmobjpl", NULL);
}
- if (dev->driver->flags & DRIVER_GEM) {
+ if (dev->driver->driver_features & DRIVER_GEM) {
ret = drm_gem_init(dev);
if (ret) {
DRM_ERROR("Cannot initialize graphics execution manager (GEM)\n");
@@ -480,14 +463,12 @@ drm_detach(struct device *self, int flags)
drm_lastclose(dev);
- if (dev->driver->flags & DRIVER_GEM)
+ if (dev->driver->driver_features & DRIVER_GEM)
drm_gem_destroy(dev);
- if (dev->driver->flags & DRIVER_GEM)
+ if (dev->driver->driver_features & DRIVER_GEM)
pool_destroy(&dev->objpl);
- extent_destroy(dev->handle_ext);
-
drm_vblank_cleanup(dev);
if (dev->agp && dev->agp->mtrr) {
@@ -666,8 +647,6 @@ drmopen(dev_t kdev, int flags, int fmt, struct proc *p)
goto err;
}
- file_priv->kdev = kdev;
- file_priv->flags = flags;
file_priv->filp = (void *)&file_priv;
file_priv->minor = minor(kdev);
INIT_LIST_HEAD(&file_priv->fbs);
@@ -678,7 +657,7 @@ drmopen(dev_t kdev, int flags, int fmt, struct proc *p)
/* for compatibility root is always authenticated */
file_priv->authenticated = DRM_SUSER(p);
- if (dev->driver->flags & DRIVER_GEM)
+ if (dev->driver->driver_features & DRIVER_GEM)
drm_gem_open(dev, file_priv);
if (dev->driver->open) {
@@ -696,7 +675,7 @@ drmopen(dev_t kdev, int flags, int fmt, struct proc *p)
goto free_priv;
}
- file_priv->master = SPLAY_EMPTY(&dev->files);
+ file_priv->is_master = SPLAY_EMPTY(&dev->files);
SPLAY_INSERT(drm_file_tree, &dev->files, file_priv);
mutex_unlock(&dev->struct_mutex);
@@ -761,10 +740,10 @@ drmclose(dev_t kdev, int flags, int fmt, struct proc *p)
mtx_leave(&dev->event_lock);
- if (dev->driver->flags & DRIVER_MODESET)
+ if (dev->driver->driver_features & DRIVER_MODESET)
drm_fb_release(dev, file_priv);
- if (dev->driver->flags & DRIVER_GEM)
+ if (dev->driver->driver_features & DRIVER_GEM)
drm_gem_release(dev, file_priv);
mutex_lock(&dev->struct_mutex);
@@ -805,8 +784,6 @@ drm_do_ioctl(struct drm_device *dev, int minor, u_long cmd, caddr_t data)
return -EINVAL;
}
- ++file_priv->ioctl_count;
-
DRM_DEBUG("pid=%d, cmd=0x%02lx, nr=0x%02x, dev 0x%lx, auth=%d\n",
DRM_CURRENTPID, cmd, (u_int)DRM_IOCTL_NR(cmd), (long)&dev->device,
file_priv->authenticated);
@@ -856,7 +833,7 @@ drm_do_ioctl(struct drm_device *dev, int minor, u_long cmd, caddr_t data)
if (((ioctl->flags & DRM_ROOT_ONLY) && !DRM_SUSER(curproc)) ||
((ioctl->flags & DRM_AUTH) && !file_priv->authenticated) ||
- ((ioctl->flags & DRM_MASTER) && !file_priv->master))
+ ((ioctl->flags & DRM_MASTER) && !file_priv->is_master))
return (-EACCES);
if (ioctl->flags & DRM_UNLOCKED)
@@ -1017,104 +994,10 @@ drmpoll(dev_t kdev, int events, struct proc *p)
return (revents);
}
-struct drm_local_map *
-drm_getsarea(struct drm_device *dev)
-{
- struct drm_local_map *map;
-
- mutex_lock(&dev->struct_mutex);
- TAILQ_FOREACH(map, &dev->maplist, link) {
- if (map->type == _DRM_SHM && (map->flags & _DRM_CONTAINS_LOCK))
- break;
- }
- mutex_unlock(&dev->struct_mutex);
- return (map);
-}
-
paddr_t
drmmmap(dev_t kdev, off_t offset, int prot)
{
- struct drm_device *dev = drm_get_device_from_kdev(kdev);
- struct drm_local_map *map;
- struct drm_file *file_priv;
- enum drm_map_type type;
-
- if (dev == NULL)
- return (-1);
-
- mutex_lock(&dev->struct_mutex);
- file_priv = drm_find_file_by_minor(dev, minor(kdev));
- mutex_unlock(&dev->struct_mutex);
- if (file_priv == NULL) {
- DRM_ERROR("can't find authenticator\n");
- return (-1);
- }
-
- if (!file_priv->authenticated)
- return (-1);
-
- if (dev->dma && offset >= 0 && offset < ptoa(dev->dma->page_count)) {
- struct drm_device_dma *dma = dev->dma;
- paddr_t phys = -1;
-
- rw_enter_write(&dma->dma_lock);
- if (dma->pagelist != NULL)
- phys = dma->pagelist[offset >> PAGE_SHIFT];
- rw_exit_write(&dma->dma_lock);
-
- return (phys);
- }
-
- /*
- * A sequential search of a linked list is
- * fine here because: 1) there will only be
- * about 5-10 entries in the list and, 2) a
- * DRI client only has to do this mapping
- * once, so it doesn't have to be optimized
- * for performance, even if the list was a
- * bit longer.
- */
- mutex_lock(&dev->struct_mutex);
- TAILQ_FOREACH(map, &dev->maplist, link) {
- if (offset >= map->ext &&
- offset < map->ext + map->size) {
- offset -= map->ext;
- break;
- }
- }
-
- if (map == NULL) {
- mutex_unlock(&dev->struct_mutex);
- DRM_DEBUG("can't find map\n");
- return (-1);
- }
- if (((map->flags & _DRM_RESTRICTED) && file_priv->master == 0)) {
- mutex_unlock(&dev->struct_mutex);
- DRM_DEBUG("restricted map\n");
- return (-1);
- }
- type = map->type;
- mutex_unlock(&dev->struct_mutex);
-
- switch (type) {
-#if __OS_HAS_AGP
- case _DRM_AGP:
- return agp_mmap(dev->agp->agpdev,
- offset + map->offset - dev->agp->base, prot);
-#endif
- case _DRM_FRAME_BUFFER:
- case _DRM_REGISTERS:
- return (offset + map->offset);
- break;
- case _DRM_SHM:
- case _DRM_CONSISTENT:
- return (bus_dmamem_mmap(dev->dmat, map->dmamem->segs,
- map->dmamem->nsegs, offset, prot, BUS_DMA_NOWAIT));
- default:
- DRM_ERROR("bad map type %d\n", type);
- return (-1); /* This should never happen. */
- }
- /* NOTREACHED */
+ return -1;
}
/*
diff --git a/sys/dev/pci/drm/i915/i915_drv.c b/sys/dev/pci/drm/i915/i915_drv.c
index 852ce57830e..7feafde541e 100644
--- a/sys/dev/pci/drm/i915/i915_drv.c
+++ b/sys/dev/pci/drm/i915/i915_drv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: i915_drv.c,v 1.99 2015/12/31 12:36:04 kettenis Exp $ */
+/* $OpenBSD: i915_drv.c,v 1.100 2016/04/08 08:27:53 kettenis Exp $ */
/*
* Copyright (c) 2008-2009 Owain G. Ainsworth <oga@openbsd.org>
*
@@ -475,7 +475,9 @@ static struct drm_driver_info inteldrm_driver = {
.minor = DRIVER_MINOR,
.patchlevel = DRIVER_PATCHLEVEL,
- .flags = DRIVER_HAVE_IRQ | DRIVER_GEM | DRIVER_MODESET,
+ .driver_features =
+ DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
+ DRIVER_MODESET,
};
const struct intel_device_info *
diff --git a/sys/dev/pci/drm/i915/i915_gem_execbuffer.c b/sys/dev/pci/drm/i915/i915_gem_execbuffer.c
index 94d48298733..01695edb522 100644
--- a/sys/dev/pci/drm/i915/i915_gem_execbuffer.c
+++ b/sys/dev/pci/drm/i915/i915_gem_execbuffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: i915_gem_execbuffer.c,v 1.40 2016/04/05 20:46:45 kettenis Exp $ */
+/* $OpenBSD: i915_gem_execbuffer.c,v 1.41 2016/04/08 08:27:53 kettenis Exp $ */
/*
* Copyright © 2008,2010 Intel Corporation
*
@@ -1031,7 +1031,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
flags = 0;
if (args->flags & I915_EXEC_SECURE) {
- if (!file->master || !capable(CAP_SYS_ADMIN))
+ if (!file->is_master || !capable(CAP_SYS_ADMIN))
return -EPERM;
flags |= I915_DISPATCH_SECURE;
diff --git a/sys/dev/pci/drm/radeon/radeon_kms.c b/sys/dev/pci/drm/radeon/radeon_kms.c
index ff26aca9238..45581befc91 100644
--- a/sys/dev/pci/drm/radeon/radeon_kms.c
+++ b/sys/dev/pci/drm/radeon/radeon_kms.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: radeon_kms.c,v 1.47 2016/02/03 07:42:14 kettenis Exp $ */
+/* $OpenBSD: radeon_kms.c,v 1.48 2016/04/08 08:27:53 kettenis Exp $ */
/*
* Copyright 2008 Advanced Micro Devices, Inc.
* Copyright 2008 Red Hat Inc.
@@ -209,9 +209,10 @@ const struct drm_pcidev radeondrm_pciidlist[] = {
};
static struct drm_driver_info kms_driver = {
- .flags =
- DRIVER_AGP | DRIVER_PCI_DMA | DRIVER_SG |
- DRIVER_HAVE_IRQ | DRIVER_HAVE_DMA | DRIVER_GEM | DRIVER_MODESET,
+ .driver_features =
+ DRIVER_USE_AGP |
+ DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
+ DRIVER_MODESET,
.buf_priv_size = 0,
.firstopen = radeon_driver_firstopen_kms,
.open = radeon_driver_open_kms,