summaryrefslogtreecommitdiffstats
path: root/sys/dev/pci/drm/include/linux
diff options
context:
space:
mode:
authorjsg <jsg@openbsd.org>2019-04-14 10:14:50 +0000
committerjsg <jsg@openbsd.org>2019-04-14 10:14:50 +0000
commit7f4dd37977dc50fdbac8c09deb3ed9ed9b8d0c87 (patch)
tree6c75a844a113c0987bd29861e921b2d54ba0752c /sys/dev/pci/drm/include/linux
parentAdd lock order checking for timeouts (diff)
downloadwireguard-openbsd-7f4dd37977dc50fdbac8c09deb3ed9ed9b8d0c87.tar.xz
wireguard-openbsd-7f4dd37977dc50fdbac8c09deb3ed9ed9b8d0c87.zip
Update shared drm code, inteldrm(4) and radeondrm(4) from linux 4.4 to
linux 4.19.34. Adds support for more Intel hardware: Broxton/Apollo Lake (was is_preliminary in 4.4) Amber Lake (another Kaby Lake refresh) Gemini Lake Coffee Lake Whiskey Lake Cannon Lake (though no hardware with Intel graphics ever shipped) Ice Lake (alpha support, hardware not released) This does not add support for new radeon hardware on the AMD side as newer radeons have a different kernel driver (amdgpu). Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for helping and a bunch of other developers for testing.
Diffstat (limited to 'sys/dev/pci/drm/include/linux')
-rw-r--r--sys/dev/pci/drm/include/linux/acpi.h25
-rw-r--r--sys/dev/pci/drm/include/linux/agp_backend.h13
-rw-r--r--sys/dev/pci/drm/include/linux/anon_inodes.h0
-rw-r--r--sys/dev/pci/drm/include/linux/async.h18
-rw-r--r--sys/dev/pci/drm/include/linux/atomic.h425
-rw-r--r--sys/dev/pci/drm/include/linux/backlight.h46
-rw-r--r--sys/dev/pci/drm/include/linux/bitmap.h88
-rw-r--r--sys/dev/pci/drm/include/linux/bitops.h102
-rw-r--r--sys/dev/pci/drm/include/linux/bottom_half.h9
-rw-r--r--sys/dev/pci/drm/include/linux/bug.h81
-rw-r--r--sys/dev/pci/drm/include/linux/cache.h0
-rw-r--r--sys/dev/pci/drm/include/linux/capability.h19
-rw-r--r--sys/dev/pci/drm/include/linux/cdev.h0
-rw-r--r--sys/dev/pci/drm/include/linux/circ_buf.h0
-rw-r--r--sys/dev/pci/drm/include/linux/compat.h0
-rw-r--r--sys/dev/pci/drm/include/linux/compiler.h33
-rw-r--r--sys/dev/pci/drm/include/linux/completion.h132
-rw-r--r--sys/dev/pci/drm/include/linux/component.h0
-rw-r--r--sys/dev/pci/drm/include/linux/console.h10
-rw-r--r--sys/dev/pci/drm/include/linux/cpufreq.h8
-rw-r--r--sys/dev/pci/drm/include/linux/cpumask.h9
-rw-r--r--sys/dev/pci/drm/include/linux/ctype.h46
-rw-r--r--sys/dev/pci/drm/include/linux/debugfs.h0
-rw-r--r--sys/dev/pci/drm/include/linux/delay.h34
-rw-r--r--sys/dev/pci/drm/include/linux/device.h68
-rw-r--r--sys/dev/pci/drm/include/linux/dma-buf.h60
-rw-r--r--sys/dev/pci/drm/include/linux/dma-fence-array.h40
-rw-r--r--sys/dev/pci/drm/include/linux/dma-fence.h346
-rw-r--r--sys/dev/pci/drm/include/linux/dma-mapping.h12
-rw-r--r--sys/dev/pci/drm/include/linux/dma_remapping.h0
-rw-r--r--sys/dev/pci/drm/include/linux/dmi.h12
-rw-r--r--sys/dev/pci/drm/include/linux/efi.h0
-rw-r--r--sys/dev/pci/drm/include/linux/err.h47
-rw-r--r--sys/dev/pci/drm/include/linux/errno.h15
-rw-r--r--sys/dev/pci/drm/include/linux/export.h13
-rw-r--r--sys/dev/pci/drm/include/linux/fault-inject.h0
-rw-r--r--sys/dev/pci/drm/include/linux/fb.h45
-rw-r--r--sys/dev/pci/drm/include/linux/fdtable.h0
-rw-r--r--sys/dev/pci/drm/include/linux/file.h21
-rw-r--r--sys/dev/pci/drm/include/linux/firmware.h48
-rw-r--r--sys/dev/pci/drm/include/linux/fs.h17
-rw-r--r--sys/dev/pci/drm/include/linux/gcd.h52
-rw-r--r--sys/dev/pci/drm/include/linux/gfp.h63
-rw-r--r--sys/dev/pci/drm/include/linux/gpio/consumer.h0
-rw-r--r--sys/dev/pci/drm/include/linux/hardirq.h8
-rw-r--r--sys/dev/pci/drm/include/linux/hash.h32
-rw-r--r--sys/dev/pci/drm/include/linux/hashtable.h60
-rw-r--r--sys/dev/pci/drm/include/linux/hdmi.h339
-rw-r--r--sys/dev/pci/drm/include/linux/highmem.h58
-rw-r--r--sys/dev/pci/drm/include/linux/hrtimer.h21
-rw-r--r--sys/dev/pci/drm/include/linux/hwmon-sysfs.h0
-rw-r--r--sys/dev/pci/drm/include/linux/hwmon.h0
-rw-r--r--sys/dev/pci/drm/include/linux/i2c-algo-bit.h0
-rw-r--r--sys/dev/pci/drm/include/linux/i2c.h90
-rw-r--r--sys/dev/pci/drm/include/linux/idr.h64
-rw-r--r--sys/dev/pci/drm/include/linux/init.h0
-rw-r--r--sys/dev/pci/drm/include/linux/input.h0
-rw-r--r--sys/dev/pci/drm/include/linux/intel-iommu.h0
-rw-r--r--sys/dev/pci/drm/include/linux/interrupt.h95
-rw-r--r--sys/dev/pci/drm/include/linux/interval_tree.h0
-rw-r--r--sys/dev/pci/drm/include/linux/interval_tree_generic.h0
-rw-r--r--sys/dev/pci/drm/include/linux/io-mapping.h8
-rw-r--r--sys/dev/pci/drm/include/linux/io.h71
-rw-r--r--sys/dev/pci/drm/include/linux/iommu.h0
-rw-r--r--sys/dev/pci/drm/include/linux/ioport.h25
-rw-r--r--sys/dev/pci/drm/include/linux/irq.h8
-rw-r--r--sys/dev/pci/drm/include/linux/irq_work.h0
-rw-r--r--sys/dev/pci/drm/include/linux/irqdomain.h0
-rw-r--r--sys/dev/pci/drm/include/linux/irqflags.h21
-rw-r--r--sys/dev/pci/drm/include/linux/irqreturn.h12
-rw-r--r--sys/dev/pci/drm/include/linux/jiffies.h45
-rw-r--r--sys/dev/pci/drm/include/linux/kconfig.h37
-rw-r--r--sys/dev/pci/drm/include/linux/kernel.h138
-rw-r--r--sys/dev/pci/drm/include/linux/kfifo.h0
-rw-r--r--sys/dev/pci/drm/include/linux/kgdb.h17
-rw-r--r--sys/dev/pci/drm/include/linux/kobject.h64
-rw-r--r--sys/dev/pci/drm/include/linux/kref.h95
-rw-r--r--sys/dev/pci/drm/include/linux/kthread.h17
-rw-r--r--sys/dev/pci/drm/include/linux/ktime.h141
-rw-r--r--sys/dev/pci/drm/include/linux/linkage.h9
-rw-r--r--sys/dev/pci/drm/include/linux/list.h311
-rw-r--r--sys/dev/pci/drm/include/linux/list_sort.h0
-rw-r--r--sys/dev/pci/drm/include/linux/llist.h70
-rw-r--r--sys/dev/pci/drm/include/linux/lockdep.h16
-rw-r--r--sys/dev/pci/drm/include/linux/log2.h26
-rw-r--r--sys/dev/pci/drm/include/linux/math64.h59
-rw-r--r--sys/dev/pci/drm/include/linux/media-bus-format.h0
-rw-r--r--sys/dev/pci/drm/include/linux/mem_encrypt.h0
-rw-r--r--sys/dev/pci/drm/include/linux/mempolicy.h0
-rw-r--r--sys/dev/pci/drm/include/linux/mfd/core.h0
-rw-r--r--sys/dev/pci/drm/include/linux/miscdevice.h0
-rw-r--r--sys/dev/pci/drm/include/linux/mm.h81
-rw-r--r--sys/dev/pci/drm/include/linux/mm_types.h0
-rw-r--r--sys/dev/pci/drm/include/linux/mman.h0
-rw-r--r--sys/dev/pci/drm/include/linux/mmu_context.h0
-rw-r--r--sys/dev/pci/drm/include/linux/mmu_notifier.h0
-rw-r--r--sys/dev/pci/drm/include/linux/mod_devicetable.h42
-rw-r--r--sys/dev/pci/drm/include/linux/module.h20
-rw-r--r--sys/dev/pci/drm/include/linux/moduleparam.h12
-rw-r--r--sys/dev/pci/drm/include/linux/mount.h0
-rw-r--r--sys/dev/pci/drm/include/linux/mutex.h22
-rw-r--r--sys/dev/pci/drm/include/linux/nospec.h8
-rw-r--r--sys/dev/pci/drm/include/linux/notifier.h16
-rw-r--r--sys/dev/pci/drm/include/linux/of_device.h0
-rw-r--r--sys/dev/pci/drm/include/linux/oom.h0
-rw-r--r--sys/dev/pci/drm/include/linux/overflow.h8
-rw-r--r--sys/dev/pci/drm/include/linux/pagemap.h0
-rw-r--r--sys/dev/pci/drm/include/linux/pagevec.h50
-rw-r--r--sys/dev/pci/drm/include/linux/pci.h301
-rw-r--r--sys/dev/pci/drm/include/linux/perf_event.h9
-rw-r--r--sys/dev/pci/drm/include/linux/pfn_t.h0
-rw-r--r--sys/dev/pci/drm/include/linux/pid.h8
-rw-r--r--sys/dev/pci/drm/include/linux/platform_device.h0
-rw-r--r--sys/dev/pci/drm/include/linux/pm.h11
-rw-r--r--sys/dev/pci/drm/include/linux/pm_qos.h17
-rw-r--r--sys/dev/pci/drm/include/linux/pm_runtime.h26
-rw-r--r--sys/dev/pci/drm/include/linux/pnp.h0
-rw-r--r--sys/dev/pci/drm/include/linux/poll.h8
-rw-r--r--sys/dev/pci/drm/include/linux/power_supply.h13
-rw-r--r--sys/dev/pci/drm/include/linux/preempt.h9
-rw-r--r--sys/dev/pci/drm/include/linux/prefetch.h8
-rw-r--r--sys/dev/pci/drm/include/linux/printk.h61
-rw-r--r--sys/dev/pci/drm/include/linux/processor.h22
-rw-r--r--sys/dev/pci/drm/include/linux/pwm.h50
-rw-r--r--sys/dev/pci/drm/include/linux/radix-tree.h84
-rw-r--r--sys/dev/pci/drm/include/linux/random.h30
-rw-r--r--sys/dev/pci/drm/include/linux/ratelimit.h11
-rw-r--r--sys/dev/pci/drm/include/linux/rbtree.h165
-rw-r--r--sys/dev/pci/drm/include/linux/rcupdate.h36
-rw-r--r--sys/dev/pci/drm/include/linux/reboot.h11
-rw-r--r--sys/dev/pci/drm/include/linux/refcount.h15
-rw-r--r--sys/dev/pci/drm/include/linux/relay.h0
-rw-r--r--sys/dev/pci/drm/include/linux/reservation.h290
-rw-r--r--sys/dev/pci/drm/include/linux/rwlock_types.h10
-rw-r--r--sys/dev/pci/drm/include/linux/scatterlist.h127
-rw-r--r--sys/dev/pci/drm/include/linux/sched.h52
-rw-r--r--sys/dev/pci/drm/include/linux/sched/clock.h19
-rw-r--r--sys/dev/pci/drm/include/linux/sched/mm.h0
-rw-r--r--sys/dev/pci/drm/include/linux/sched/signal.h12
-rw-r--r--sys/dev/pci/drm/include/linux/seq_file.h17
-rw-r--r--sys/dev/pci/drm/include/linux/seqlock.h137
-rw-r--r--sys/dev/pci/drm/include/linux/shmem_fs.h0
-rw-r--r--sys/dev/pci/drm/include/linux/sizes.h13
-rw-r--r--sys/dev/pci/drm/include/linux/slab.h47
-rw-r--r--sys/dev/pci/drm/include/linux/smp.h12
-rw-r--r--sys/dev/pci/drm/include/linux/sort.h0
-rw-r--r--sys/dev/pci/drm/include/linux/spinlock.h55
-rw-r--r--sys/dev/pci/drm/include/linux/spinlock_types.h13
-rw-r--r--sys/dev/pci/drm/include/linux/stop_machine.h20
-rw-r--r--sys/dev/pci/drm/include/linux/string.h79
-rw-r--r--sys/dev/pci/drm/include/linux/stringify.h9
-rw-r--r--sys/dev/pci/drm/include/linux/swap.h14
-rw-r--r--sys/dev/pci/drm/include/linux/swiotlb.h0
-rw-r--r--sys/dev/pci/drm/include/linux/sync_file.h26
-rw-r--r--sys/dev/pci/drm/include/linux/sysfs.h11
-rw-r--r--sys/dev/pci/drm/include/linux/sysrq.h8
-rw-r--r--sys/dev/pci/drm/include/linux/time.h75
-rw-r--r--sys/dev/pci/drm/include/linux/timekeeping.h21
-rw-r--r--sys/dev/pci/drm/include/linux/timer.h45
-rw-r--r--sys/dev/pci/drm/include/linux/tracepoint.h24
-rw-r--r--sys/dev/pci/drm/include/linux/tty.h0
-rw-r--r--sys/dev/pci/drm/include/linux/typecheck.h8
-rw-r--r--sys/dev/pci/drm/include/linux/types.h67
-rw-r--r--sys/dev/pci/drm/include/linux/uaccess.h136
-rw-r--r--sys/dev/pci/drm/include/linux/uuid.h8
-rw-r--r--sys/dev/pci/drm/include/linux/version.h0
-rw-r--r--sys/dev/pci/drm/include/linux/vga_switcheroo.h17
-rw-r--r--sys/dev/pci/drm/include/linux/vgaarb.h21
-rw-r--r--sys/dev/pci/drm/include/linux/vmalloc.h49
-rw-r--r--sys/dev/pci/drm/include/linux/vt.h0
-rw-r--r--sys/dev/pci/drm/include/linux/wait.h267
-rw-r--r--sys/dev/pci/drm/include/linux/wait_bit.h10
-rw-r--r--sys/dev/pci/drm/include/linux/workqueue.h218
-rw-r--r--sys/dev/pci/drm/include/linux/ww_mutex.h248
-rw-r--r--sys/dev/pci/drm/include/linux/zlib.h0
175 files changed, 7253 insertions, 0 deletions
diff --git a/sys/dev/pci/drm/include/linux/acpi.h b/sys/dev/pci/drm/include/linux/acpi.h
new file mode 100644
index 00000000000..89c990fdd08
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/acpi.h
@@ -0,0 +1,25 @@
+/* Public domain. */
+
+#ifndef _LINUX_ACPI_H
+#define _LINUX_ACPI_H
+
+#include <sys/types.h>
+#include <sys/param.h>
+
+#ifdef __HAVE_ACPI
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+#endif
+
+typedef size_t acpi_size;
+typedef int acpi_status;
+
+struct acpi_table_header;
+
+#define ACPI_SUCCESS(x) ((x) == 0)
+
+#define AE_NOT_FOUND 0x0005
+
+acpi_status acpi_get_table(const char *, int, struct acpi_table_header **);
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/agp_backend.h b/sys/dev/pci/drm/include/linux/agp_backend.h
new file mode 100644
index 00000000000..452d8e92834
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/agp_backend.h
@@ -0,0 +1,13 @@
+/* Public domain. */
+
+#ifndef _LINUX_AGP_BACKEND_H
+#define _LINUX_AGP_BACKEND_H
+
+#include <machine/bus.h>
+
+#if defined(__amd64__) || defined(__i386__)
+#define AGP_USER_MEMORY 0
+#define AGP_USER_CACHED_MEMORY BUS_DMA_COHERENT
+#endif
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/anon_inodes.h b/sys/dev/pci/drm/include/linux/anon_inodes.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/anon_inodes.h
diff --git a/sys/dev/pci/drm/include/linux/async.h b/sys/dev/pci/drm/include/linux/async.h
new file mode 100644
index 00000000000..5cc703cfa5c
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/async.h
@@ -0,0 +1,18 @@
+/* Public domain. */
+
+#ifndef _LINUX_ASYNC_H
+#define _LINUX_ASYNC_H
+
+#include <sys/types.h>
+
+typedef uint64_t async_cookie_t;
+typedef void (*async_func_t) (void *, async_cookie_t);
+
+static inline async_cookie_t
+async_schedule(async_func_t func, void *data)
+{
+ func(data, 0);
+ return 0;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/atomic.h b/sys/dev/pci/drm/include/linux/atomic.h
new file mode 100644
index 00000000000..9d12bb2adf2
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/atomic.h
@@ -0,0 +1,425 @@
+/* $OpenBSD: atomic.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/**
+ * \file drm_atomic.h
+ * Atomic operations used in the DRM which may or may not be provided by the OS.
+ *
+ * \author Eric Anholt <anholt@FreeBSD.org>
+ */
+
+/*-
+ * Copyright 2004 Eric Anholt
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _DRM_LINUX_ATOMIC_H_
+#define _DRM_LINUX_ATOMIC_H_
+
+#include <sys/types.h>
+#include <sys/mutex.h>
+#include <machine/intr.h>
+#include <machine/atomic.h>
+#include <linux/types.h>
+
+#define atomic_set(p, v) (*(p) = (v))
+#define atomic_read(p) (*(p))
+#define atomic_inc(p) __sync_fetch_and_add(p, 1)
+#define atomic_dec(p) __sync_fetch_and_sub(p, 1)
+#define atomic_add(n, p) __sync_fetch_and_add(p, n)
+#define atomic_sub(n, p) __sync_fetch_and_sub(p, n)
+#define atomic_add_return(n, p) __sync_add_and_fetch(p, n)
+#define atomic_sub_return(n, p) __sync_sub_and_fetch(p, n)
+#define atomic_inc_return(v) atomic_add_return(1, (v))
+#define atomic_dec_return(v) atomic_sub_return(1, (v))
+#define atomic_dec_and_test(v) (atomic_dec_return(v) == 0)
+#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
+#define atomic_or(n, p) atomic_setbits_int(p, n)
+#define atomic_cmpxchg(p, o, n) __sync_val_compare_and_swap(p, o, n)
+#define atomic_set_release(p, v) atomic_set((p), (v))
+
+static inline int
+atomic_xchg(volatile int *v, int n)
+{
+ __sync_synchronize();
+ return __sync_lock_test_and_set(v, n);
+}
+
+#define xchg(v, n) __sync_lock_test_and_set(v, n)
+
+static inline int
+atomic_add_unless(volatile int *v, int n, int u)
+{
+ int o = *v;
+
+ do {
+ o = *v;
+ if (o == u)
+ return 0;
+ } while (__sync_val_compare_and_swap(v, o, o +n) != o);
+
+ return 1;
+}
+
+static inline int
+atomic_dec_if_positive(volatile int *v)
+{
+ int r, o;
+
+ do {
+ o = *v;
+ r = o - 1;
+ if (r < 0)
+ break;
+ } while (__sync_val_compare_and_swap(v, o, r) != o);
+
+ return r;
+}
+
+#define atomic_long_read(p) (*(p))
+
+#ifdef __LP64__
+typedef int64_t atomic64_t;
+
+#define atomic64_set(p, v) (*(p) = (v))
+#define atomic64_read(p) (*(p))
+
+static inline int64_t
+atomic64_xchg(volatile int64_t *v, int64_t n)
+{
+ __sync_synchronize();
+ return __sync_lock_test_and_set(v, n);
+}
+
+#define atomic64_add(n, p) __sync_fetch_and_add_8(p, n)
+#define atomic64_sub(n, p) __sync_fetch_and_sub_8(p, n)
+#define atomic64_inc(p) __sync_fetch_and_add_8(p, 1)
+#define atomic64_add_return(n, p) __sync_add_and_fetch_8(p, n)
+#define atomic64_inc_return(p) __sync_add_and_fetch_8(p, 1)
+
+#else
+
+typedef struct {
+ volatile int64_t val;
+ struct mutex lock;
+} atomic64_t;
+
+static inline void
+atomic64_set(atomic64_t *v, int64_t i)
+{
+ mtx_init(&v->lock, IPL_HIGH);
+ v->val = i;
+}
+
+static inline int64_t
+atomic64_read(atomic64_t *v)
+{
+ int64_t val;
+
+ mtx_enter(&v->lock);
+ val = v->val;
+ mtx_leave(&v->lock);
+
+ return val;
+}
+
+static inline int64_t
+atomic64_xchg(atomic64_t *v, int64_t n)
+{
+ int64_t val;
+
+ mtx_enter(&v->lock);
+ val = v->val;
+ v->val = n;
+ mtx_leave(&v->lock);
+
+ return val;
+}
+
+static inline void
+atomic64_add(int i, atomic64_t *v)
+{
+ mtx_enter(&v->lock);
+ v->val += i;
+ mtx_leave(&v->lock);
+}
+
+#define atomic64_inc(p) atomic64_add(p, 1)
+
+static inline int64_t
+atomic64_add_return(int i, atomic64_t *v)
+{
+ int64_t val;
+
+ mtx_enter(&v->lock);
+ val = v->val + i;
+ v->val = val;
+ mtx_leave(&v->lock);
+
+ return val;
+}
+
+#define atomic64_inc_return(p) atomic64_add_return(p, 1)
+
+static inline void
+atomic64_sub(int i, atomic64_t *v)
+{
+ mtx_enter(&v->lock);
+ v->val -= i;
+ mtx_leave(&v->lock);
+}
+#endif
+
+#ifdef __LP64__
+typedef int64_t atomic_long_t;
+#define atomic_long_set(p, v) atomic64_set(p, v)
+#define atomic_long_xchg(v, n) atomic64_xchg(v, n)
+#define atomic_long_cmpxchg(p, o, n) atomic_cmpxchg(p, o, n)
+#else
+typedef int32_t atomic_long_t;
+#define atomic_long_set(p, v) atomic_set(p, v)
+#define atomic_long_xchg(v, n) atomic_xchg(v, n)
+#define atomic_long_cmpxchg(p, o, n) atomic_cmpxchg(p, o, n)
+#endif
+
+static inline int
+atomic_inc_not_zero(atomic_t *p)
+{
+ if (*p == 0)
+ return (0);
+
+ *(p) += 1;
+ return (*p);
+}
+
+/* FIXME */
+#define atomic_set_int(p, bits) atomic_setbits_int(p,bits)
+#define atomic_set_mask(bits, p) atomic_setbits_int(p,bits)
+#define atomic_clear_int(p, bits) atomic_clearbits_int(p,bits)
+#define atomic_clear_mask(bits, p) atomic_clearbits_int(p,bits)
+#define atomic_andnot(bits, p) atomic_clearbits_int(p,bits)
+#define atomic_fetchadd_int(p, n) __sync_fetch_and_add(p, n)
+#define atomic_fetchsub_int(p, n) __sync_fetch_and_sub(p, n)
+#define atomic_fetch_inc(p) __sync_fetch_and_add(p, 1)
+#define atomic_fetch_xor(n, p) __sync_fetch_and_xor(p, n)
+
+static inline atomic_t
+test_and_set_bit(u_int b, volatile void *p)
+{
+ unsigned int m = 1 << (b & 0x1f);
+ unsigned int prev = __sync_fetch_and_or((volatile u_int *)p + (b >> 5), m);
+ return (prev & m) != 0;
+}
+
+static inline void
+clear_bit(u_int b, volatile void *p)
+{
+ atomic_clear_int(((volatile u_int *)p) + (b >> 5), 1 << (b & 0x1f));
+}
+
+static inline void
+set_bit(u_int b, volatile void *p)
+{
+ atomic_set_int(((volatile u_int *)p) + (b >> 5), 1 << (b & 0x1f));
+}
+
+static inline void
+__clear_bit(u_int b, volatile void *p)
+{
+ volatile u_int *ptr = (volatile u_int *)p;
+ ptr[b >> 5] &= ~(1 << (b & 0x1f));
+}
+
+static inline void
+__set_bit(u_int b, volatile void *p)
+{
+ volatile u_int *ptr = (volatile u_int *)p;
+ ptr[b >> 5] |= (1 << (b & 0x1f));
+}
+
+static inline int
+test_bit(u_int b, const volatile void *p)
+{
+ return !!(((volatile u_int *)p)[b >> 5] & (1 << (b & 0x1f)));
+}
+
+static inline int
+__test_and_set_bit(u_int b, volatile void *p)
+{
+ unsigned int m = 1 << (b & 0x1f);
+ volatile u_int *ptr = (volatile u_int *)p;
+ unsigned int prev = ptr[b >> 5];
+ ptr[b >> 5] |= m;
+
+ return (prev & m) != 0;
+}
+
+static inline int
+test_and_clear_bit(u_int b, volatile void *p)
+{
+ unsigned int m = 1 << (b & 0x1f);
+ unsigned int prev = __sync_fetch_and_and((volatile u_int *)p + (b >> 5), ~m);
+ return (prev & m) != 0;
+}
+
+static inline int
+__test_and_clear_bit(u_int b, volatile void *p)
+{
+ volatile u_int *ptr = (volatile u_int *)p;
+ int rv = !!(ptr[b >> 5] & (1 << (b & 0x1f)));
+ ptr[b >> 5] &= ~(1 << (b & 0x1f));
+ return rv;
+}
+
+static inline int
+find_first_zero_bit(volatile void *p, int max)
+{
+ int b;
+ volatile u_int *ptr = (volatile u_int *)p;
+
+ for (b = 0; b < max; b += 32) {
+ if (ptr[b >> 5] != ~0) {
+ for (;;) {
+ if ((ptr[b >> 5] & (1 << (b & 0x1f))) == 0)
+ return b;
+ b++;
+ }
+ }
+ }
+ return max;
+}
+
+static inline int
+find_next_zero_bit(volatile void *p, int max, int b)
+{
+ volatile u_int *ptr = (volatile u_int *)p;
+
+ for (; b < max; b += 32) {
+ if (ptr[b >> 5] != ~0) {
+ for (;;) {
+ if ((ptr[b >> 5] & (1 << (b & 0x1f))) == 0)
+ return b;
+ b++;
+ }
+ }
+ }
+ return max;
+}
+
+static inline int
+find_first_bit(volatile void *p, int max)
+{
+ int b;
+ volatile u_int *ptr = (volatile u_int *)p;
+
+ for (b = 0; b < max; b += 32) {
+ if (ptr[b >> 5] != 0) {
+ for (;;) {
+ if (ptr[b >> 5] & (1 << (b & 0x1f)))
+ return b;
+ b++;
+ }
+ }
+ }
+ return max;
+}
+
+static inline int
+find_next_bit(volatile void *p, int max, int b)
+{
+ volatile u_int *ptr = (volatile u_int *)p;
+
+ for (; b < max; b+= 32) {
+ if (ptr[b >> 5] != 0) {
+ for (;;) {
+ if (ptr[b >> 5] & (1 << (b & 0x1f)))
+ return b;
+ b++;
+ }
+ }
+ }
+ return max;
+}
+
+#define for_each_set_bit(b, p, max) \
+ for ((b) = find_first_bit((p), (max)); \
+ (b) < (max); \
+ (b) = find_next_bit((p), (max), (b) + 1))
+
+#define for_each_clear_bit(b, p, max) \
+ for ((b) = find_first_zero_bit((p), (max)); \
+ (b) < (max); \
+ (b) = find_next_zero_bit((p), (max), (b) + 1))
+
+/* DRM_READMEMORYBARRIER() prevents reordering of reads.
+ * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
+ * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
+ */
+#if defined(__i386__)
+#define DRM_READMEMORYBARRIER() __asm __volatile( \
+ "lock; addl $0,0(%%esp)" : : : "memory");
+#define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
+#define DRM_MEMORYBARRIER() __asm __volatile( \
+ "lock; addl $0,0(%%esp)" : : : "memory");
+#elif defined(__alpha__)
+#define DRM_READMEMORYBARRIER() alpha_mb();
+#define DRM_WRITEMEMORYBARRIER() alpha_wmb();
+#define DRM_MEMORYBARRIER() alpha_mb();
+#elif defined(__amd64__)
+#define DRM_READMEMORYBARRIER() __asm __volatile( \
+ "lock; addl $0,0(%%rsp)" : : : "memory");
+#define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
+#define DRM_MEMORYBARRIER() __asm __volatile( \
+ "lock; addl $0,0(%%rsp)" : : : "memory");
+#elif defined(__aarch64__)
+#define DRM_READMEMORYBARRIER() __membar("dsb ld")
+#define DRM_WRITEMEMORYBARRIER() __membar("dsb st")
+#define DRM_MEMORYBARRIER() __membar("dsb sy")
+#elif defined(__mips64__)
+#define DRM_READMEMORYBARRIER() DRM_MEMORYBARRIER()
+#define DRM_WRITEMEMORYBARRIER() DRM_MEMORYBARRIER()
+#define DRM_MEMORYBARRIER() mips_sync()
+#elif defined(__powerpc__)
+#define DRM_READMEMORYBARRIER() DRM_MEMORYBARRIER()
+#define DRM_WRITEMEMORYBARRIER() DRM_MEMORYBARRIER()
+#define DRM_MEMORYBARRIER() __asm __volatile("sync" : : : "memory");
+#elif defined(__sparc64__)
+#define DRM_READMEMORYBARRIER() DRM_MEMORYBARRIER()
+#define DRM_WRITEMEMORYBARRIER() DRM_MEMORYBARRIER()
+#define DRM_MEMORYBARRIER() membar_sync()
+#endif
+
+#define smp_mb__before_atomic() DRM_MEMORYBARRIER()
+#define smp_mb__after_atomic() DRM_MEMORYBARRIER()
+#define smp_mb__before_atomic_dec() DRM_MEMORYBARRIER()
+#define smp_mb__after_atomic_dec() DRM_MEMORYBARRIER()
+#define smp_mb__before_atomic_inc() DRM_MEMORYBARRIER()
+#define smp_mb__after_atomic_inc() DRM_MEMORYBARRIER()
+
+#define smp_store_mb(x, v) do { x = v; DRM_MEMORYBARRIER(); } while (0)
+
+#define mb() DRM_MEMORYBARRIER()
+#define rmb() DRM_READMEMORYBARRIER()
+#define wmb() DRM_WRITEMEMORYBARRIER()
+#define smp_rmb() DRM_READMEMORYBARRIER()
+#define smp_wmb() DRM_WRITEMEMORYBARRIER()
+#define mmiowb() DRM_WRITEMEMORYBARRIER()
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/backlight.h b/sys/dev/pci/drm/include/linux/backlight.h
new file mode 100644
index 00000000000..a766ffdc2d3
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/backlight.h
@@ -0,0 +1,46 @@
+/* Public domain. */
+
+#ifndef _LINUX_BACKLIGHT_H
+#define _LINUX_BACKLIGHT_H
+
+#include <sys/task.h>
+
+struct backlight_device;
+
+struct backlight_properties {
+ int type;
+ int max_brightness;
+ int brightness;
+ int power;
+};
+
+struct backlight_ops {
+ int (*update_status)(struct backlight_device *);
+ int (*get_brightness)(struct backlight_device *);
+};
+
+struct backlight_device {
+ const struct backlight_ops *ops;
+ struct backlight_properties props;
+ struct task task;
+ void *data;
+};
+
+#define bl_get_data(bd) (bd)->data
+
+#define BACKLIGHT_RAW 0
+#define BACKLIGHT_FIRMWARE 1
+
+struct backlight_device *backlight_device_register(const char *, void *,
+ void *, const struct backlight_ops *, struct backlight_properties *);
+void backlight_device_unregister(struct backlight_device *);
+
+static inline void
+backlight_update_status(struct backlight_device *bd)
+{
+ bd->ops->update_status(bd);
+}
+
+void backlight_schedule_update_status(struct backlight_device *);
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/bitmap.h b/sys/dev/pci/drm/include/linux/bitmap.h
new file mode 100644
index 00000000000..f54b9df2bdf
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/bitmap.h
@@ -0,0 +1,88 @@
+/* $OpenBSD: bitmap.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2013, 2014, 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_BITMAP_H
+#define _LINUX_BITMAP_H
+
+#include <linux/bitops.h>
+
+#define bitmap_empty(p, n) (find_first_bit(p, n) == n)
+
+static inline void
+bitmap_set(void *p, int b, u_int n)
+{
+ u_int end = b + n;
+
+ for (; b < end; b++)
+ __set_bit(b, p);
+}
+
+static inline void
+bitmap_clear(void *p, int b, u_int n)
+{
+ u_int end = b + n;
+
+ for (; b < end; b++)
+ __clear_bit(b, p);
+}
+
+static inline void
+bitmap_zero(void *p, u_int n)
+{
+ u_int *ptr = p;
+ u_int b;
+
+ for (b = 0; b < n; b += 32)
+ ptr[b >> 5] = 0;
+}
+
+static inline void
+bitmap_or(void *d, void *s1, void *s2, u_int n)
+{
+ u_int *dst = d;
+ u_int *src1 = s1;
+ u_int *src2 = s2;
+ u_int b;
+
+ for (b = 0; b < n; b += 32)
+ dst[b >> 5] = src1[b >> 5] | src2[b >> 5];
+}
+
+static inline void
+bitmap_complement(void *d, void *s, u_int n)
+{
+ u_int *dst = d;
+ u_int *src = s;
+ u_int b;
+
+ for (b = 0; b < n; b += 32)
+ dst[b >> 5] = ~src[b >> 5];
+}
+
+static inline int
+bitmap_weight(void *p, u_int n)
+{
+ u_int *ptr = p;
+ u_int b;
+ int sum = 0;
+
+ for (b = 0; b < n; b += 32)
+ sum += hweight32(ptr[b >> 5]);
+ return sum;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/bitops.h b/sys/dev/pci/drm/include/linux/bitops.h
new file mode 100644
index 00000000000..0255df1332e
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/bitops.h
@@ -0,0 +1,102 @@
+/* $OpenBSD: bitops.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2013, 2014, 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_BITOPS_H
+#define _LINUX_BITOPS_H
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <asm/bitsperlong.h>
+#include <linux/atomic.h>
+
+#define BIT(x) (1UL << (x))
+#define BIT_ULL(x) (1ULL << (x))
+#define BITS_PER_BYTE 8
+
+#define GENMASK(h, l) (((~0UL) >> (BITS_PER_LONG - (h) - 1)) & ((~0UL) << (l)))
+#define GENMASK_ULL(h, l) (((~0ULL) >> (BITS_PER_LONG_LONG - (h) - 1)) & ((~0ULL) << (l)))
+
+#define BITS_TO_LONGS(x) howmany((x), 8 * sizeof(long))
+
+static inline uint8_t
+hweight8(uint32_t x)
+{
+ x = (x & 0x55) + ((x & 0xaa) >> 1);
+ x = (x & 0x33) + ((x & 0xcc) >> 2);
+ x = (x + (x >> 4)) & 0x0f;
+ return (x);
+}
+
+static inline uint16_t
+hweight16(uint32_t x)
+{
+ x = (x & 0x5555) + ((x & 0xaaaa) >> 1);
+ x = (x & 0x3333) + ((x & 0xcccc) >> 2);
+ x = (x + (x >> 4)) & 0x0f0f;
+ x = (x + (x >> 8)) & 0x00ff;
+ return (x);
+}
+
+static inline uint32_t
+hweight32(uint32_t x)
+{
+ x = (x & 0x55555555) + ((x & 0xaaaaaaaa) >> 1);
+ x = (x & 0x33333333) + ((x & 0xcccccccc) >> 2);
+ x = (x + (x >> 4)) & 0x0f0f0f0f;
+ x = (x + (x >> 8));
+ x = (x + (x >> 16)) & 0x000000ff;
+ return x;
+}
+
+static inline uint32_t
+hweight64(uint64_t x)
+{
+ x = (x & 0x5555555555555555ULL) + ((x & 0xaaaaaaaaaaaaaaaaULL) >> 1);
+ x = (x & 0x3333333333333333ULL) + ((x & 0xccccccccccccccccULL) >> 2);
+ x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
+ x = (x + (x >> 8));
+ x = (x + (x >> 16));
+ x = (x + (x >> 32)) & 0x000000ff;
+ return x;
+}
+
+static inline uint64_t
+sign_extend64(uint64_t value, int index)
+{
+ uint8_t shift = 63 - index;
+ return ((int64_t)(value << shift) >> shift);
+}
+
+static inline int
+fls64(long long mask)
+{
+ int bit;
+
+ if (mask == 0)
+ return (0);
+ for (bit = 1; mask != 1; bit++)
+ mask = (unsigned long long)mask >> 1;
+ return (bit);
+}
+
+static inline uint32_t
+ror32(uint32_t word, unsigned int shift)
+{
+ return (word >> shift) | (word << (32 - shift));
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/bottom_half.h b/sys/dev/pci/drm/include/linux/bottom_half.h
new file mode 100644
index 00000000000..1261bf12fe1
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/bottom_half.h
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#ifndef _LINUX_BOTTOM_HALF_H
+#define _LINUX_BOTTOM_HALF_H
+
+#define local_bh_disable()
+#define local_bh_enable()
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/bug.h b/sys/dev/pci/drm/include/linux/bug.h
new file mode 100644
index 00000000000..dc90126538e
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/bug.h
@@ -0,0 +1,81 @@
+/* $OpenBSD: bug.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2013, 2014, 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_BUG_H
+#define _LINUX_BUG_H
+
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <linux/compiler.h>
+
+#define BUG() \
+do { \
+ panic("BUG at %s:%d", __FILE__, __LINE__); \
+} while (0)
+
+#ifndef DIAGNOSTIC
+#define BUG_ON(x) ((void)(x))
+#else
+#define BUG_ON(x) KASSERT(!(x))
+#endif
+
+#define BUILD_BUG()
+#define BUILD_BUG_ON(x) CTASSERT(!(x))
+#define BUILD_BUG_ON_NOT_POWER_OF_2(x) 0
+#define BUILD_BUG_ON_MSG(x, y) do { } while (0)
+#define BUILD_BUG_ON_INVALID(x) ((void)0)
+#define BUILD_BUG_ON_ZERO(x) 0
+
+#define WARN(condition, fmt...) ({ \
+ int __ret = !!(condition); \
+ if (__ret) \
+ printf(fmt); \
+ unlikely(__ret); \
+})
+
+#define WARN_ONCE(condition, fmt...) ({ \
+ static int __warned; \
+ int __ret = !!(condition); \
+ if (__ret && !__warned) { \
+ printf(fmt); \
+ __warned = 1; \
+ } \
+ unlikely(__ret); \
+})
+
+#define _WARN_STR(x) #x
+
+#define WARN_ON(condition) ({ \
+ int __ret = !!(condition); \
+ if (__ret) \
+ printf("WARNING %s failed at %s:%d\n", \
+ _WARN_STR(condition), __FILE__, __LINE__); \
+ unlikely(__ret); \
+})
+
+#define WARN_ON_ONCE(condition) ({ \
+ static int __warned; \
+ int __ret = !!(condition); \
+ if (__ret && !__warned) { \
+ printf("WARNING %s failed at %s:%d\n", \
+ _WARN_STR(condition), __FILE__, __LINE__); \
+ __warned = 1; \
+ } \
+ unlikely(__ret); \
+})
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/cache.h b/sys/dev/pci/drm/include/linux/cache.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/cache.h
diff --git a/sys/dev/pci/drm/include/linux/capability.h b/sys/dev/pci/drm/include/linux/capability.h
new file mode 100644
index 00000000000..c265f92fdd8
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/capability.h
@@ -0,0 +1,19 @@
+/* Public domain. */
+
+#ifndef _LINUX_CAPABILITY_H
+#define _LINUX_CAPABILITY_H
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/ucred.h>
+#include <machine/cpu.h>
+
+#define CAP_SYS_ADMIN 0x1
+static inline int
+capable(int cap)
+{
+ KASSERT(cap == CAP_SYS_ADMIN);
+ return suser(curproc);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/cdev.h b/sys/dev/pci/drm/include/linux/cdev.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/cdev.h
diff --git a/sys/dev/pci/drm/include/linux/circ_buf.h b/sys/dev/pci/drm/include/linux/circ_buf.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/circ_buf.h
diff --git a/sys/dev/pci/drm/include/linux/compat.h b/sys/dev/pci/drm/include/linux/compat.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/compat.h
diff --git a/sys/dev/pci/drm/include/linux/compiler.h b/sys/dev/pci/drm/include/linux/compiler.h
new file mode 100644
index 00000000000..c2f09e25afe
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/compiler.h
@@ -0,0 +1,33 @@
+/* Public domain. */
+
+#ifndef _LINUX_COMPILER_H
+#define _LINUX_COMPILER_H
+
+#include <linux/kconfig.h>
+
+#define unlikely(x) __builtin_expect(!!(x), 0)
+#define likely(x) __builtin_expect(!!(x), 1)
+
+#define __force
+#define __always_unused __unused
+#define __maybe_unused
+#define __read_mostly
+#define __iomem
+#define __must_check
+#define __init
+#define __exit
+#define __deprecated
+#define __always_inline inline
+#define noinline __attribute__((noinline))
+
+#ifndef __user
+#define __user
+#endif
+
+#define barrier() __asm __volatile("" : : : "memory")
+
+#define __printf(x, y)
+
+#define uninitialized_var(x) x
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/completion.h b/sys/dev/pci/drm/include/linux/completion.h
new file mode 100644
index 00000000000..051c3d7613a
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/completion.h
@@ -0,0 +1,132 @@
+/* $OpenBSD: completion.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2015, 2018 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_COMPLETION_H
+#define _LINUX_COMPLETION_H
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mutex.h>
+#include <linux/wait.h>
+
+struct completion {
+ u_int done;
+ wait_queue_head_t wait;
+};
+
+static inline void
+init_completion(struct completion *x)
+{
+ x->done = 0;
+ mtx_init(&x->wait.lock, IPL_TTY);
+}
+
+static inline u_long
+_wait_for_completion_timeout(struct completion *x, u_long timo LOCK_FL_VARS)
+{
+ int ret;
+
+ KASSERT(!cold);
+
+ _mtx_enter(&x->wait.lock LOCK_FL_ARGS);
+ while (x->done == 0) {
+ ret = msleep(x, &x->wait.lock, 0, "wfct", timo);
+ if (ret) {
+ _mtx_leave(&x->wait.lock LOCK_FL_ARGS);
+ return (ret == EWOULDBLOCK) ? 0 : -ret;
+ }
+ }
+ x->done--;
+ _mtx_leave(&x->wait.lock LOCK_FL_ARGS);
+
+ return 1;
+}
+#define wait_for_completion_timeout(x, timo) \
+ _wait_for_completion_timeout(x, timo LOCK_FILE_LINE)
+
+static inline u_long
+_wait_for_completion_interruptible(struct completion *x LOCK_FL_VARS)
+{
+ int ret;
+
+ KASSERT(!cold);
+
+ _mtx_enter(&x->wait.lock LOCK_FL_ARGS);
+ while (x->done == 0) {
+ ret = msleep(x, &x->wait.lock, PCATCH, "wfci", 0);
+ if (ret) {
+ _mtx_leave(&x->wait.lock LOCK_FL_ARGS);
+ return (ret == EWOULDBLOCK) ? 0 : -ret;
+ }
+ }
+ x->done--;
+ _mtx_leave(&x->wait.lock LOCK_FL_ARGS);
+
+ return 0;
+}
+#define wait_for_completion_interruptible(x) \
+ _wait_for_completion_interruptible(x LOCK_FILE_LINE)
+
+static inline u_long
+_wait_for_completion_interruptible_timeout(struct completion *x, u_long timo
+ LOCK_FL_VARS)
+{
+ int ret;
+
+ KASSERT(!cold);
+
+ _mtx_enter(&x->wait.lock LOCK_FL_ARGS);
+ while (x->done == 0) {
+ ret = msleep(x, &x->wait.lock, PCATCH, "wfcit", timo);
+ if (ret) {
+ _mtx_leave(&x->wait.lock LOCK_FL_ARGS);
+ return (ret == EWOULDBLOCK) ? 0 : -ret;
+ }
+ }
+ x->done--;
+ _mtx_leave(&x->wait.lock LOCK_FL_ARGS);
+
+ return 1;
+}
+#define wait_for_completion_interruptible_timeout(x, timo) \
+ _wait_for_completion_interruptible_timeout(x, timo LOCK_FILE_LINE)
+
+static inline void
+_complete_all(struct completion *x LOCK_FL_VARS)
+{
+ _mtx_enter(&x->wait.lock LOCK_FL_ARGS);
+ x->done = UINT_MAX;
+ _mtx_leave(&x->wait.lock LOCK_FL_ARGS);
+ wakeup(x);
+}
+#define complete_all(x) _complete_all(x LOCK_FILE_LINE)
+
+static inline bool
+_try_wait_for_completion(struct completion *x LOCK_FL_VARS)
+{
+ _mtx_enter(&x->wait.lock LOCK_FL_ARGS);
+ if (x->done == 0) {
+ _mtx_leave(&x->wait.lock LOCK_FL_ARGS);
+ return false;
+ }
+ x->done--;
+ _mtx_leave(&x->wait.lock LOCK_FL_ARGS);
+ return true;
+}
+#define try_wait_for_completion(x) _try_wait_for_completion(x LOCK_FILE_LINE)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/component.h b/sys/dev/pci/drm/include/linux/component.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/component.h
diff --git a/sys/dev/pci/drm/include/linux/console.h b/sys/dev/pci/drm/include/linux/console.h
new file mode 100644
index 00000000000..d243c2e19c7
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/console.h
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#ifndef _LINUX_CONSOLE_H
+#define _LINUX_CONSOLE_H
+
+#define console_lock()
+#define console_trylock() 1
+#define console_unlock()
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/cpufreq.h b/sys/dev/pci/drm/include/linux/cpufreq.h
new file mode 100644
index 00000000000..70ac7489b19
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/cpufreq.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUX_CPUFREQ_H
+#define _LINUX_CPUFREQ_H
+
+#include <linux/kobject.h>
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/cpumask.h b/sys/dev/pci/drm/include/linux/cpumask.h
new file mode 100644
index 00000000000..c42d20d5d7a
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/cpumask.h
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#ifndef _LINUX_CPUMASK_H
+#define _LINUX_CPUMASK_H
+
+#include <linux/bitmap.h>
+#include <linux/bug.h>
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/ctype.h b/sys/dev/pci/drm/include/linux/ctype.h
new file mode 100644
index 00000000000..2c933cae196
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/ctype.h
@@ -0,0 +1,46 @@
+/* $OpenBSD: ctype.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_CTYPE_H
+#define _LINUX_CTYPE_H
+
+#define _U 0x01
+#define _L 0x02
+#define _N 0x04
+#define _S 0x08
+#define _P 0x10
+#define _C 0x20
+#define _X 0x40
+#define _B 0x80
+
+static inline int
+isascii(int c)
+{
+ return ((unsigned int)c <= 0177);
+}
+
+static inline int
+isprint(int c)
+{
+ if (c == -1)
+ return (0);
+ if ((unsigned char)c >= 040 && (unsigned char)c <= 0176)
+ return (1);
+ return (0);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/debugfs.h b/sys/dev/pci/drm/include/linux/debugfs.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/debugfs.h
diff --git a/sys/dev/pci/drm/include/linux/delay.h b/sys/dev/pci/drm/include/linux/delay.h
new file mode 100644
index 00000000000..157ef90c3f3
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/delay.h
@@ -0,0 +1,34 @@
+/* Public domain. */
+
+#ifndef _LINUX_DELAY_H
+#define _LINUX_DELAY_H
+
+#include <sys/param.h>
+
+static inline void
+udelay(unsigned long usecs)
+{
+ DELAY(usecs);
+}
+
+static inline void
+ndelay(unsigned long nsecs)
+{
+ DELAY(MAX(nsecs / 1000, 1));
+}
+
+static inline void
+usleep_range(unsigned long min, unsigned long max)
+{
+ DELAY(min);
+}
+
+static inline void
+mdelay(unsigned long msecs)
+{
+ int loops = msecs;
+ while (loops--)
+ DELAY(1000);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/device.h b/sys/dev/pci/drm/include/linux/device.h
new file mode 100644
index 00000000000..21bcf29e1ad
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/device.h
@@ -0,0 +1,68 @@
+/* Public domain. */
+
+#ifndef _LINUX_DEVICE_H
+#define _LINUX_DEVICE_H
+
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <linux/slab.h>
+#include <linux/ioport.h>
+#include <linux/lockdep.h>
+#include <linux/pm.h>
+
+struct device_node;
+
+struct device_driver {
+ struct device *dev;
+};
+
+struct device_attribute {
+};
+
+#define DEVICE_ATTR(_name, _mode, _show, _store) \
+ struct device_attribute dev_attr_##_name
+
+#define device_create_file(a, b) 0
+#define device_remove_file(a, b)
+
+#define dev_get_drvdata(x) NULL
+#define dev_set_drvdata(x, y)
+#define dev_name(dev) ""
+
+#define dev_pm_set_driver_flags(x, y)
+
+#define devm_kzalloc(x, y, z) kzalloc(y, z)
+
+#define dev_warn(dev, fmt, arg...) \
+ printf("drm:pid%d:%s *WARNING* " fmt, curproc->p_p->ps_pid, \
+ __func__ , ## arg)
+#define dev_notice(dev, fmt, arg...) \
+ printf("drm:pid%d:%s *NOTICE* " fmt, curproc->p_p->ps_pid, \
+ __func__ , ## arg)
+#define dev_crit(dev, fmt, arg...) \
+ printf("drm:pid%d:%s *ERROR* " fmt, curproc->p_p->ps_pid, \
+ __func__ , ## arg)
+#define dev_err(dev, fmt, arg...) \
+ printf("drm:pid%d:%s *ERROR* " fmt, curproc->p_p->ps_pid, \
+ __func__ , ## arg)
+#define dev_printk(level, dev, fmt, arg...) \
+ printf("drm:pid%d:%s *PRINTK* " fmt, curproc->p_p->ps_pid, \
+ __func__ , ## arg)
+
+#ifdef DRMDEBUG
+#define dev_info(dev, fmt, arg...) \
+ printf("drm: " fmt, ## arg)
+#define dev_dbg(dev, fmt, arg...) \
+ printf("drm:pid%d:%s *DEBUG* " fmt, curproc->p_p->ps_pid, \
+ __func__ , ## arg)
+#else
+#define dev_info(dev, fmt, arg...) \
+ do { } while(0)
+#define dev_dbg(dev, fmt, arg...) \
+ do { } while(0)
+#endif
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/dma-buf.h b/sys/dev/pci/drm/include/linux/dma-buf.h
new file mode 100644
index 00000000000..69ee26eea33
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/dma-buf.h
@@ -0,0 +1,60 @@
+/* $OpenBSD: dma-buf.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2018 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_DMA_BUF_H
+#define _LINUX_DMA_BUF_H
+
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <linux/reservation.h>
+
+struct dma_buf_ops;
+
+struct dma_buf {
+ const struct dma_buf_ops *ops;
+ void *priv;
+ size_t size;
+ struct file *file;
+};
+
+struct dma_buf_attachment;
+
+void get_dma_buf(struct dma_buf *);
+struct dma_buf *dma_buf_get(int);
+void dma_buf_put(struct dma_buf *);
+int dma_buf_fd(struct dma_buf *, int);
+
+struct dma_buf_ops {
+ void (*release)(struct dma_buf *);
+};
+
+struct dma_buf_export_info {
+ const struct dma_buf_ops *ops;
+ size_t size;
+ int flags;
+ void *priv;
+ struct reservation_object *resv;
+};
+
+#define DEFINE_DMA_BUF_EXPORT_INFO(x) struct dma_buf_export_info x
+
+struct dma_buf *dma_buf_export(const struct dma_buf_export_info *);
+
+#define dma_buf_attach(x, y) NULL
+#define dma_buf_detach(x, y) panic("dma_buf_detach")
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/dma-fence-array.h b/sys/dev/pci/drm/include/linux/dma-fence-array.h
new file mode 100644
index 00000000000..da49d7cf7cc
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/dma-fence-array.h
@@ -0,0 +1,40 @@
+/* Public domain. */
+
+#ifndef _LINUX_DMA_FENCE_ARRAY_H
+#define _LINUX_DMA_FENCE_ARRAY_H
+
+#include <linux/dma-fence.h>
+
+#ifndef STUB
+#include <sys/types.h>
+#include <sys/systm.h>
+#define STUB() do { printf("%s: stub\n", __func__); } while(0)
+#endif
+
+struct dma_fence_array {
+ struct dma_fence base;
+ unsigned int num_fences;
+ struct dma_fence **fences;
+};
+
+static inline struct dma_fence_array *
+to_dma_fence_array(struct dma_fence *fence)
+{
+ return NULL;
+}
+
+static inline bool
+dma_fence_is_array(struct dma_fence *fence)
+{
+ return false;
+}
+
+static inline struct dma_fence_array *
+dma_fence_array_create(int num_fences, struct dma_fence **fences, u64 context,
+ unsigned seqno, bool signal_on_any)
+{
+ STUB();
+ return NULL;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/dma-fence.h b/sys/dev/pci/drm/include/linux/dma-fence.h
new file mode 100644
index 00000000000..03be00f2db6
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/dma-fence.h
@@ -0,0 +1,346 @@
+/* Public domain. */
+
+#ifndef _LINUX_DMA_FENCE_H
+#define _LINUX_DMA_FENCE_H
+
+#include <sys/types.h>
+#include <sys/malloc.h>
+#include <sys/mutex.h>
+#include <linux/kref.h>
+#include <linux/list.h>
+#include <linux/bug.h>
+#include <linux/sched.h>
+#include <linux/rcupdate.h>
+
+#define DMA_FENCE_TRACE(fence, fmt, args...) do {} while(0)
+
+struct dma_fence {
+ struct kref refcount;
+ const struct dma_fence_ops *ops;
+ unsigned long flags;
+ unsigned int context;
+ unsigned int seqno;
+ struct mutex *lock;
+ struct list_head cb_list;
+ int error;
+ struct rcu_head rcu;
+};
+
+enum dma_fence_flag_bits {
+ DMA_FENCE_FLAG_SIGNALED_BIT,
+ DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
+ DMA_FENCE_FLAG_USER_BITS,
+};
+
+struct dma_fence_ops {
+ const char * (*get_driver_name)(struct dma_fence *);
+ const char * (*get_timeline_name)(struct dma_fence *);
+ bool (*enable_signaling)(struct dma_fence *);
+ bool (*signaled)(struct dma_fence *);
+ long (*wait)(struct dma_fence *, bool, long);
+ void (*release)(struct dma_fence *);
+};
+
+struct dma_fence_cb;
+typedef void (*dma_fence_func_t)(struct dma_fence *fence, struct dma_fence_cb *cb);
+
+struct dma_fence_cb {
+ struct list_head node;
+ dma_fence_func_t func;
+};
+
+unsigned int dma_fence_context_alloc(unsigned int);
+
+static inline struct dma_fence *
+dma_fence_get(struct dma_fence *fence)
+{
+ if (fence)
+ kref_get(&fence->refcount);
+ return fence;
+}
+
+static inline struct dma_fence *
+dma_fence_get_rcu(struct dma_fence *fence)
+{
+ if (fence)
+ kref_get(&fence->refcount);
+ return fence;
+}
+
+static inline struct dma_fence *
+dma_fence_get_rcu_safe(struct dma_fence **dfp)
+{
+ struct dma_fence *fence;
+ if (dfp == NULL)
+ return NULL;
+ fence = *dfp;
+ if (fence)
+ kref_get(&fence->refcount);
+ return fence;
+}
+
+static inline void
+dma_fence_release(struct kref *ref)
+{
+ struct dma_fence *fence = container_of(ref, struct dma_fence, refcount);
+ if (fence->ops && fence->ops->release)
+ fence->ops->release(fence);
+ else
+ free(fence, M_DRM, 0);
+}
+
+static inline void
+dma_fence_free(struct dma_fence *fence)
+{
+ free(fence, M_DRM, 0);
+}
+
+static inline void
+dma_fence_put(struct dma_fence *fence)
+{
+ if (fence)
+ kref_put(&fence->refcount, dma_fence_release);
+}
+
+static inline int
+dma_fence_signal(struct dma_fence *fence)
+{
+ if (fence == NULL)
+ return -EINVAL;
+
+ if (test_and_set_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
+ return -EINVAL;
+
+ if (test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags)) {
+ struct dma_fence_cb *cur, *tmp;
+
+ mtx_enter(fence->lock);
+ list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {
+ list_del_init(&cur->node);
+ cur->func(fence, cur);
+ }
+ mtx_leave(fence->lock);
+ }
+
+ return 0;
+}
+
+static inline int
+dma_fence_signal_locked(struct dma_fence *fence)
+{
+ struct dma_fence_cb *cur, *tmp;
+
+ if (fence == NULL)
+ return -EINVAL;
+
+ if (test_and_set_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
+ return -EINVAL;
+
+ list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {
+ list_del_init(&cur->node);
+ cur->func(fence, cur);
+ }
+
+ return 0;
+}
+
+static inline bool
+dma_fence_is_signaled(struct dma_fence *fence)
+{
+ if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
+ return true;
+
+ if (fence->ops->signaled && fence->ops->signaled(fence)) {
+ dma_fence_signal(fence);
+ return true;
+ }
+
+ return false;
+}
+
+static inline bool
+dma_fence_is_signaled_locked(struct dma_fence *fence)
+{
+ if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
+ return true;
+
+ if (fence->ops->signaled && fence->ops->signaled(fence)) {
+ dma_fence_signal_locked(fence);
+ return true;
+ }
+
+ return false;
+}
+
+static void
+dma_fence_default_wait_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
+{
+ wakeup(fence);
+}
+
+static inline long
+dma_fence_default_wait(struct dma_fence *fence, bool intr, signed long timeout)
+{
+ long ret = timeout ? timeout : 1;
+ int err;
+ struct dma_fence_cb cb;
+ bool was_set;
+
+ if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
+ return ret;
+
+ mtx_enter(fence->lock);
+
+ was_set = test_and_set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
+ &fence->flags);
+
+ if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
+ goto out;
+
+ if (!was_set && fence->ops->enable_signaling) {
+ if (!fence->ops->enable_signaling(fence)) {
+ dma_fence_signal_locked(fence);
+ goto out;
+ }
+ }
+
+ if (timeout == 0) {
+ ret = 0;
+ goto out;
+ }
+
+ cb.func = dma_fence_default_wait_cb;
+ list_add(&cb.node, &fence->cb_list);
+
+ while (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
+ err = msleep(fence, fence->lock, intr ? PCATCH : 0, "dmafence",
+ timeout);
+ if (err == EINTR || err == ERESTART) {
+ ret = -ERESTARTSYS;
+ break;
+ } else if (err == EWOULDBLOCK) {
+ ret = 0;
+ break;
+ }
+ }
+
+ if (!list_empty(&cb.node))
+ list_del(&cb.node);
+out:
+ mtx_leave(fence->lock);
+
+ return ret;
+}
+
+static inline long
+dma_fence_wait_timeout(struct dma_fence *fence, bool intr, signed long timeout)
+{
+ if (timeout < 0)
+ return -EINVAL;
+
+ if (fence->ops->wait)
+ return fence->ops->wait(fence, intr, timeout);
+ else
+ return dma_fence_default_wait(fence, intr, timeout);
+}
+
+static inline long
+dma_fence_wait(struct dma_fence *fence, bool intr)
+{
+ return dma_fence_wait_timeout(fence, intr, MAX_SCHEDULE_TIMEOUT);
+}
+
+static inline void
+dma_fence_enable_sw_signaling(struct dma_fence *fence)
+{
+ if (!test_and_set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags) &&
+ !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags) &&
+ fence->ops->enable_signaling) {
+ mtx_enter(fence->lock);
+ if (!fence->ops->enable_signaling(fence))
+ dma_fence_signal_locked(fence);
+ mtx_leave(fence->lock);
+ }
+}
+
+static inline void
+dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
+ struct mutex *lock, unsigned context, unsigned seqno)
+{
+ fence->ops = ops;
+ fence->lock = lock;
+ fence->context = context;
+ fence->seqno = seqno;
+ fence->flags = 0;
+ fence->error = 0;
+ kref_init(&fence->refcount);
+ INIT_LIST_HEAD(&fence->cb_list);
+}
+
+static inline int
+dma_fence_add_callback(struct dma_fence *fence, struct dma_fence_cb *cb,
+ dma_fence_func_t func)
+{
+ int ret = 0;
+ bool was_set;
+
+ if (WARN_ON(!fence || !func))
+ return -EINVAL;
+
+ if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
+ INIT_LIST_HEAD(&cb->node);
+ return -ENOENT;
+ }
+
+ mtx_enter(fence->lock);
+
+ was_set = test_and_set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags);
+
+ if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
+ ret = -ENOENT;
+ else if (!was_set && fence->ops->enable_signaling) {
+ if (!fence->ops->enable_signaling(fence)) {
+ dma_fence_signal_locked(fence);
+ ret = -ENOENT;
+ }
+ }
+
+ if (!ret) {
+ cb->func = func;
+ list_add_tail(&cb->node, &fence->cb_list);
+ } else
+ INIT_LIST_HEAD(&cb->node);
+ mtx_leave(fence->lock);
+
+ return ret;
+}
+
+static inline bool
+dma_fence_remove_callback(struct dma_fence *fence, struct dma_fence_cb *cb)
+{
+ bool ret;
+
+ mtx_enter(fence->lock);
+
+ ret = !list_empty(&cb->node);
+ if (ret)
+ list_del_init(&cb->node);
+
+ mtx_leave(fence->lock);
+
+ return ret;
+}
+
+static inline bool
+dma_fence_is_later(struct dma_fence *a, struct dma_fence *b)
+{
+ return (a->seqno > b->seqno);
+}
+
+static inline void
+dma_fence_set_error(struct dma_fence *fence, int error)
+{
+ fence->error = error;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/dma-mapping.h b/sys/dev/pci/drm/include/linux/dma-mapping.h
new file mode 100644
index 00000000000..7b3d77a52bf
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/dma-mapping.h
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#ifndef _LINUX_DMA_MAPPING_H
+#define _LINUX_DMA_MAPPING_H
+
+#include <linux/sizes.h>
+
+#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) -1)
+
+#define dma_set_coherent_mask(x, y) 0
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/dma_remapping.h b/sys/dev/pci/drm/include/linux/dma_remapping.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/dma_remapping.h
diff --git a/sys/dev/pci/drm/include/linux/dmi.h b/sys/dev/pci/drm/include/linux/dmi.h
new file mode 100644
index 00000000000..1e55ca6a8ab
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/dmi.h
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#ifndef _LINUX_DMI_H
+#define _LINUX_DMI_H
+
+#include <sys/types.h>
+#include <linux/mod_devicetable.h>
+
+int dmi_check_system(const struct dmi_system_id *);
+bool dmi_match(int, const char *);
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/efi.h b/sys/dev/pci/drm/include/linux/efi.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/efi.h
diff --git a/sys/dev/pci/drm/include/linux/err.h b/sys/dev/pci/drm/include/linux/err.h
new file mode 100644
index 00000000000..c4fb448802e
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/err.h
@@ -0,0 +1,47 @@
+/* Public domain. */
+
+#ifndef _LINUX_ERR_H
+#define _LINUX_ERR_H
+
+#include <sys/errno.h>
+#include <linux/compiler.h>
+
+#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-ELAST)
+
+static inline void *
+ERR_PTR(long error)
+{
+ return (void *) error;
+}
+
+static inline long
+PTR_ERR(const void *ptr)
+{
+ return (long) ptr;
+}
+
+static inline long
+IS_ERR(const void *ptr)
+{
+ return IS_ERR_VALUE((unsigned long)ptr);
+}
+
+static inline long
+IS_ERR_OR_NULL(const void *ptr)
+{
+ return !ptr || IS_ERR_VALUE((unsigned long)ptr);
+}
+
+static inline void *
+ERR_CAST(const void *ptr)
+{
+ return (void *)ptr;
+}
+
+static inline int
+PTR_ERR_OR_ZERO(const void *ptr)
+{
+ return IS_ERR(ptr)? PTR_ERR(ptr) : 0;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/errno.h b/sys/dev/pci/drm/include/linux/errno.h
new file mode 100644
index 00000000000..99c6d662fcf
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/errno.h
@@ -0,0 +1,15 @@
+/* Public domain. */
+
+#ifndef _LINUX_ERRNO_H
+#define _LINUX_ERRNO_H
+
+#include <sys/errno.h>
+
+#define ERESTARTSYS EINTR
+#define ETIME ETIMEDOUT
+#define EREMOTEIO EIO
+#define ENOTSUPP ENOTSUP
+#define ENODATA ENOTSUP
+#define ECHRNG EINVAL
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/export.h b/sys/dev/pci/drm/include/linux/export.h
new file mode 100644
index 00000000000..e57f5ec12de
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/export.h
@@ -0,0 +1,13 @@
+/* Public domain. */
+
+#ifndef _LINUX_EXPORT_H
+#define _LINUX_EXPORT_H
+
+#include <linux/kconfig.h>
+
+#define EXPORT_SYMBOL(x)
+#define EXPORT_SYMBOL_GPL(x)
+
+#define THIS_MODULE NULL
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/fault-inject.h b/sys/dev/pci/drm/include/linux/fault-inject.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/fault-inject.h
diff --git a/sys/dev/pci/drm/include/linux/fb.h b/sys/dev/pci/drm/include/linux/fb.h
new file mode 100644
index 00000000000..463de7f2cf7
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/fb.h
@@ -0,0 +1,45 @@
+/* Public domain. */
+
+#ifndef _LINUX_FB_H
+#define _LINUX_FB_H
+
+#include <sys/types.h>
+#include <linux/slab.h>
+#include <linux/notifier.h>
+#include <linux/backlight.h>
+#include <linux/kgdb.h>
+
+struct fb_var_screeninfo {
+ int pixclock;
+ uint32_t width;
+ uint32_t height;
+};
+
+struct fb_info {
+ struct fb_var_screeninfo var;
+ char *screen_buffer;
+ void *par;
+ int fbcon_rotate_hint;
+ bool skip_vt_switch;
+};
+
+#define FB_BLANK_UNBLANK 0
+#define FB_BLANK_NORMAL 1
+#define FB_BLANK_HSYNC_SUSPEND 2
+#define FB_BLANK_VSYNC_SUSPEND 3
+#define FB_BLANK_POWERDOWN 4
+
+#define FBINFO_STATE_RUNNING 0
+#define FBINFO_STATE_SUSPENDED 1
+
+#define FB_ROTATE_UR 0
+#define FB_ROTATE_CW 1
+#define FB_ROTATE_UD 2
+#define FB_ROTATE_CCW 3
+
+#define framebuffer_alloc(flags, device) \
+ kzalloc(sizeof(struct fb_info), GFP_KERNEL)
+
+#define fb_set_suspend(x, y)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/fdtable.h b/sys/dev/pci/drm/include/linux/fdtable.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/fdtable.h
diff --git a/sys/dev/pci/drm/include/linux/file.h b/sys/dev/pci/drm/include/linux/file.h
new file mode 100644
index 00000000000..69c80d7161a
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/file.h
@@ -0,0 +1,21 @@
+/* Public domain. */
+
+#ifndef _LINUX_FILE_H
+#define _LINUX_FILE_H
+
+/* both for printf */
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#define fput(a)
+#define fd_install(a, b)
+#define put_unused_fd(a)
+
+static inline int
+get_unused_fd_flags(unsigned int flags)
+{
+ printf("%s: stub\n", __func__);
+ return -1;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/firmware.h b/sys/dev/pci/drm/include/linux/firmware.h
new file mode 100644
index 00000000000..4f06d4de2a4
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/firmware.h
@@ -0,0 +1,48 @@
+/* Public domain. */
+
+#ifndef _LINUX_FIRMWARE_H
+#define _LINUX_FIRMWARE_H
+
+#include <sys/types.h>
+#include <sys/malloc.h>
+#include <sys/device.h>
+#include <linux/types.h>
+
+#ifndef __DECONST
+#define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var))
+#endif
+
+struct firmware {
+ size_t size;
+ const u8 *data;
+};
+
+static inline int
+request_firmware(const struct firmware **fw, const char *name,
+ struct device *device)
+{
+ int r;
+ struct firmware *f = malloc(sizeof(struct firmware), M_DRM,
+ M_WAITOK | M_ZERO);
+ r = loadfirmware(name, __DECONST(u_char **, &f->data), &f->size);
+ if (r != 0) {
+ free(f, M_DRM, sizeof(struct firmware));
+ *fw = NULL;
+ return -r;
+ } else {
+ *fw = f;
+ return 0;
+ }
+}
+
+#define request_firmware_nowait(a, b, c, d, e, f, g) -EINVAL
+
+static inline void
+release_firmware(const struct firmware *fw)
+{
+ if (fw)
+ free(__DECONST(u_char *, fw->data), M_DEVBUF, fw->size);
+ free(__DECONST(struct firmware *, fw), M_DRM, sizeof(*fw));
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/fs.h b/sys/dev/pci/drm/include/linux/fs.h
new file mode 100644
index 00000000000..42d5e95178a
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/fs.h
@@ -0,0 +1,17 @@
+/* Public domain. */
+
+#ifndef _LINUX_FS_H
+#define _LINUX_FS_H
+
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <linux/capability.h>
+#include <linux/linkage.h>
+#include <linux/uuid.h>
+#include <linux/pid.h>
+#include <linux/radix-tree.h>
+#include <linux/wait_bit.h>
+
+struct address_space;
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/gcd.h b/sys/dev/pci/drm/include/linux/gcd.h
new file mode 100644
index 00000000000..efc890f17f2
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/gcd.h
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_GCD_H
+#define _LINUX_GCD_H
+
+/*
+ * Compute the greatest common divisor of a and b.
+ * from libc getopt_long.c
+ */
+static inline unsigned long
+gcd(unsigned long a, unsigned long b)
+{
+ unsigned long c;
+
+ c = a % b;
+ while (c != 0) {
+ a = b;
+ b = c;
+ c = a % b;
+ }
+
+ return (b);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/gfp.h b/sys/dev/pci/drm/include/linux/gfp.h
new file mode 100644
index 00000000000..d3dd930b285
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/gfp.h
@@ -0,0 +1,63 @@
+/* Public domain. */
+
+#ifndef _LINUX_GFP_H
+#define _LINUX_GFP_H
+
+#include <sys/types.h>
+#include <sys/malloc.h>
+#include <uvm/uvm_extern.h>
+
+#define GFP_ATOMIC M_NOWAIT
+#define GFP_NOWAIT M_NOWAIT
+#define GFP_KERNEL (M_WAITOK | M_CANFAIL)
+#define GFP_USER (M_WAITOK | M_CANFAIL)
+#define GFP_TEMPORARY (M_WAITOK | M_CANFAIL)
+#define GFP_HIGHUSER 0
+#define GFP_DMA32 0
+#define __GFP_NOWARN 0
+#define __GFP_NORETRY 0
+#define __GFP_ZERO M_ZERO
+#define __GFP_RETRY_MAYFAIL 0
+#define __GFP_MOVABLE 0
+#define __GFP_COMP 0
+#define GFP_TRANSHUGE_LIGHT 0
+#define __GFP_KSWAPD_RECLAIM 0
+#define __GFP_HIGHMEM 0
+#define __GFP_RECLAIMABLE 0
+#define __GFP_DMA32 0
+
+static inline bool
+gfpflags_allow_blocking(const unsigned int flags)
+{
+ return (flags & M_WAITOK) != 0;
+}
+
+struct vm_page *alloc_pages(unsigned int, unsigned int);
+void __free_pages(struct vm_page *, unsigned int);
+
+static inline struct vm_page *
+alloc_page(unsigned int gfp_mask)
+{
+ return alloc_pages(gfp_mask, 0);
+}
+
+static inline void
+__free_page(struct vm_page *page)
+{
+ return __free_pages(page, 0);
+}
+
+static inline unsigned long
+__get_free_page(unsigned int gfp_mask)
+{
+ void *addr = km_alloc(PAGE_SIZE, &kv_page, &kp_dirty, &kd_nowait);
+ return (unsigned long)addr;
+}
+
+static inline void
+free_page(unsigned long addr)
+{
+ km_free((void *)addr, PAGE_SIZE, &kv_page, &kp_dirty);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/gpio/consumer.h b/sys/dev/pci/drm/include/linux/gpio/consumer.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/gpio/consumer.h
diff --git a/sys/dev/pci/drm/include/linux/hardirq.h b/sys/dev/pci/drm/include/linux/hardirq.h
new file mode 100644
index 00000000000..6144bb0dc32
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/hardirq.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUX_HARDIRQ_H
+#define _LINUX_HARDIRQ_H
+
+#define synchronize_irq(x)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/hash.h b/sys/dev/pci/drm/include/linux/hash.h
new file mode 100644
index 00000000000..c0898474ebc
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/hash.h
@@ -0,0 +1,32 @@
+/* Public domain. */
+
+#ifndef _LINUX_HASH_H
+#define _LINUX_HASH_H
+
+#include <sys/types.h>
+
+/* 2^32 * ((sqrt(5) - 1) / 2) from Knuth */
+#define GOLDEN_RATIO_32 0x9e3779b9
+
+static inline uint32_t
+hash_32(uint32_t val, unsigned int bits)
+{
+ return (val * GOLDEN_RATIO_32) >> (32 - bits);
+}
+
+/* 2^64 * ((sqrt(5) - 1) / 2) from Knuth */
+#define GOLDEN_RATIO_64 0x9e3779b97f4a7c16ULL
+
+static inline uint32_t
+hash_64(uint64_t val, unsigned int bits)
+{
+ return (val * GOLDEN_RATIO_64) >> (64 - bits);
+}
+
+#ifdef __LP64__
+#define hash_long(val, bits) hash_64(val, bits)
+#else
+#define hash_long(val, bits) hash_32(val, bits)
+#endif
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/hashtable.h b/sys/dev/pci/drm/include/linux/hashtable.h
new file mode 100644
index 00000000000..26660bf65bf
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/hashtable.h
@@ -0,0 +1,60 @@
+/* $OpenBSD: hashtable.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2017 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_HASHTABLE_H
+#define _LINUX_HASHTABLE_H
+
+#include <linux/list.h>
+
+#define DECLARE_HASHTABLE(name, bits) struct hlist_head name[1 << (bits)]
+
+static inline void
+__hash_init(struct hlist_head *table, u_int size)
+{
+ u_int i;
+
+ for (i = 0; i < size; i++)
+ INIT_HLIST_HEAD(&table[i]);
+}
+
+static inline bool
+__hash_empty(struct hlist_head *table, u_int size)
+{
+ u_int i;
+
+ for (i = 0; i < size; i++) {
+ if (!hlist_empty(&table[i]))
+ return false;
+ }
+
+ return true;
+}
+
+#define __hash(table, key) &table[key % (nitems(table) - 1)]
+
+#define hash_init(table) __hash_init(table, nitems(table))
+#define hash_add(table, node, key) \
+ hlist_add_head(node, __hash(table, key))
+#define hash_del(node) hlist_del_init(node)
+#define hash_empty(table) __hash_empty(table, nitems(table))
+#define hash_for_each_possible(table, obj, member, key) \
+ hlist_for_each_entry(obj, __hash(table, key), member)
+#define hash_for_each_safe(table, i, tmp, obj, member) \
+ for (i = 0; i < nitems(table); i++) \
+ hlist_for_each_entry_safe(obj, tmp, &table[i], member)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/hdmi.h b/sys/dev/pci/drm/include/linux/hdmi.h
new file mode 100644
index 00000000000..4f3febc0f97
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/hdmi.h
@@ -0,0 +1,339 @@
+/*
+ * Copyright (C) 2012 Avionic Design GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __LINUX_HDMI_H_
+#define __LINUX_HDMI_H_
+
+#include <linux/types.h>
+#include <linux/device.h>
+
+enum hdmi_infoframe_type {
+ HDMI_INFOFRAME_TYPE_VENDOR = 0x81,
+ HDMI_INFOFRAME_TYPE_AVI = 0x82,
+ HDMI_INFOFRAME_TYPE_SPD = 0x83,
+ HDMI_INFOFRAME_TYPE_AUDIO = 0x84,
+};
+
+#define HDMI_IEEE_OUI 0x000c03
+#define HDMI_FORUM_IEEE_OUI 0xc45dd8
+#define HDMI_INFOFRAME_HEADER_SIZE 4
+#define HDMI_AVI_INFOFRAME_SIZE 13
+#define HDMI_SPD_INFOFRAME_SIZE 25
+#define HDMI_AUDIO_INFOFRAME_SIZE 10
+
+#define HDMI_INFOFRAME_SIZE(type) \
+ (HDMI_INFOFRAME_HEADER_SIZE + HDMI_ ## type ## _INFOFRAME_SIZE)
+
+struct hdmi_any_infoframe {
+ enum hdmi_infoframe_type type;
+ unsigned char version;
+ unsigned char length;
+};
+
+enum hdmi_colorspace {
+ HDMI_COLORSPACE_RGB,
+ HDMI_COLORSPACE_YUV422,
+ HDMI_COLORSPACE_YUV444,
+ HDMI_COLORSPACE_YUV420,
+ HDMI_COLORSPACE_RESERVED4,
+ HDMI_COLORSPACE_RESERVED5,
+ HDMI_COLORSPACE_RESERVED6,
+ HDMI_COLORSPACE_IDO_DEFINED,
+};
+
+enum hdmi_scan_mode {
+ HDMI_SCAN_MODE_NONE,
+ HDMI_SCAN_MODE_OVERSCAN,
+ HDMI_SCAN_MODE_UNDERSCAN,
+ HDMI_SCAN_MODE_RESERVED,
+};
+
+enum hdmi_colorimetry {
+ HDMI_COLORIMETRY_NONE,
+ HDMI_COLORIMETRY_ITU_601,
+ HDMI_COLORIMETRY_ITU_709,
+ HDMI_COLORIMETRY_EXTENDED,
+};
+
+enum hdmi_picture_aspect {
+ HDMI_PICTURE_ASPECT_NONE,
+ HDMI_PICTURE_ASPECT_4_3,
+ HDMI_PICTURE_ASPECT_16_9,
+ HDMI_PICTURE_ASPECT_64_27,
+ HDMI_PICTURE_ASPECT_256_135,
+ HDMI_PICTURE_ASPECT_RESERVED,
+};
+
+enum hdmi_active_aspect {
+ HDMI_ACTIVE_ASPECT_16_9_TOP = 2,
+ HDMI_ACTIVE_ASPECT_14_9_TOP = 3,
+ HDMI_ACTIVE_ASPECT_16_9_CENTER = 4,
+ HDMI_ACTIVE_ASPECT_PICTURE = 8,
+ HDMI_ACTIVE_ASPECT_4_3 = 9,
+ HDMI_ACTIVE_ASPECT_16_9 = 10,
+ HDMI_ACTIVE_ASPECT_14_9 = 11,
+ HDMI_ACTIVE_ASPECT_4_3_SP_14_9 = 13,
+ HDMI_ACTIVE_ASPECT_16_9_SP_14_9 = 14,
+ HDMI_ACTIVE_ASPECT_16_9_SP_4_3 = 15,
+};
+
+enum hdmi_extended_colorimetry {
+ HDMI_EXTENDED_COLORIMETRY_XV_YCC_601,
+ HDMI_EXTENDED_COLORIMETRY_XV_YCC_709,
+ HDMI_EXTENDED_COLORIMETRY_S_YCC_601,
+ HDMI_EXTENDED_COLORIMETRY_OPYCC_601,
+ HDMI_EXTENDED_COLORIMETRY_OPRGB,
+
+ /* The following EC values are only defined in CEA-861-F. */
+ HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM,
+ HDMI_EXTENDED_COLORIMETRY_BT2020,
+ HDMI_EXTENDED_COLORIMETRY_RESERVED,
+};
+
+enum hdmi_quantization_range {
+ HDMI_QUANTIZATION_RANGE_DEFAULT,
+ HDMI_QUANTIZATION_RANGE_LIMITED,
+ HDMI_QUANTIZATION_RANGE_FULL,
+ HDMI_QUANTIZATION_RANGE_RESERVED,
+};
+
+/* non-uniform picture scaling */
+enum hdmi_nups {
+ HDMI_NUPS_UNKNOWN,
+ HDMI_NUPS_HORIZONTAL,
+ HDMI_NUPS_VERTICAL,
+ HDMI_NUPS_BOTH,
+};
+
+enum hdmi_ycc_quantization_range {
+ HDMI_YCC_QUANTIZATION_RANGE_LIMITED,
+ HDMI_YCC_QUANTIZATION_RANGE_FULL,
+};
+
+enum hdmi_content_type {
+ HDMI_CONTENT_TYPE_GRAPHICS,
+ HDMI_CONTENT_TYPE_PHOTO,
+ HDMI_CONTENT_TYPE_CINEMA,
+ HDMI_CONTENT_TYPE_GAME,
+};
+
+struct hdmi_avi_infoframe {
+ enum hdmi_infoframe_type type;
+ unsigned char version;
+ unsigned char length;
+ enum hdmi_colorspace colorspace;
+ enum hdmi_scan_mode scan_mode;
+ enum hdmi_colorimetry colorimetry;
+ enum hdmi_picture_aspect picture_aspect;
+ enum hdmi_active_aspect active_aspect;
+ bool itc;
+ enum hdmi_extended_colorimetry extended_colorimetry;
+ enum hdmi_quantization_range quantization_range;
+ enum hdmi_nups nups;
+ unsigned char video_code;
+ enum hdmi_ycc_quantization_range ycc_quantization_range;
+ enum hdmi_content_type content_type;
+ unsigned char pixel_repeat;
+ unsigned short top_bar;
+ unsigned short bottom_bar;
+ unsigned short left_bar;
+ unsigned short right_bar;
+};
+
+int hdmi_avi_infoframe_init(struct hdmi_avi_infoframe *frame);
+ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void *buffer,
+ size_t size);
+
+enum hdmi_spd_sdi {
+ HDMI_SPD_SDI_UNKNOWN,
+ HDMI_SPD_SDI_DSTB,
+ HDMI_SPD_SDI_DVDP,
+ HDMI_SPD_SDI_DVHS,
+ HDMI_SPD_SDI_HDDVR,
+ HDMI_SPD_SDI_DVC,
+ HDMI_SPD_SDI_DSC,
+ HDMI_SPD_SDI_VCD,
+ HDMI_SPD_SDI_GAME,
+ HDMI_SPD_SDI_PC,
+ HDMI_SPD_SDI_BD,
+ HDMI_SPD_SDI_SACD,
+ HDMI_SPD_SDI_HDDVD,
+ HDMI_SPD_SDI_PMP,
+};
+
+struct hdmi_spd_infoframe {
+ enum hdmi_infoframe_type type;
+ unsigned char version;
+ unsigned char length;
+ char vendor[8];
+ char product[16];
+ enum hdmi_spd_sdi sdi;
+};
+
+int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
+ const char *vendor, const char *product);
+ssize_t hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe *frame, void *buffer,
+ size_t size);
+
+enum hdmi_audio_coding_type {
+ HDMI_AUDIO_CODING_TYPE_STREAM,
+ HDMI_AUDIO_CODING_TYPE_PCM,
+ HDMI_AUDIO_CODING_TYPE_AC3,
+ HDMI_AUDIO_CODING_TYPE_MPEG1,
+ HDMI_AUDIO_CODING_TYPE_MP3,
+ HDMI_AUDIO_CODING_TYPE_MPEG2,
+ HDMI_AUDIO_CODING_TYPE_AAC_LC,
+ HDMI_AUDIO_CODING_TYPE_DTS,
+ HDMI_AUDIO_CODING_TYPE_ATRAC,
+ HDMI_AUDIO_CODING_TYPE_DSD,
+ HDMI_AUDIO_CODING_TYPE_EAC3,
+ HDMI_AUDIO_CODING_TYPE_DTS_HD,
+ HDMI_AUDIO_CODING_TYPE_MLP,
+ HDMI_AUDIO_CODING_TYPE_DST,
+ HDMI_AUDIO_CODING_TYPE_WMA_PRO,
+ HDMI_AUDIO_CODING_TYPE_CXT,
+};
+
+enum hdmi_audio_sample_size {
+ HDMI_AUDIO_SAMPLE_SIZE_STREAM,
+ HDMI_AUDIO_SAMPLE_SIZE_16,
+ HDMI_AUDIO_SAMPLE_SIZE_20,
+ HDMI_AUDIO_SAMPLE_SIZE_24,
+};
+
+enum hdmi_audio_sample_frequency {
+ HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_32000,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_44100,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_48000,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_88200,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_96000,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_176400,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_192000,
+};
+
+enum hdmi_audio_coding_type_ext {
+ /* Refer to Audio Coding Type (CT) field in Data Byte 1 */
+ HDMI_AUDIO_CODING_TYPE_EXT_CT,
+
+ /*
+ * The next three CXT values are defined in CEA-861-E only.
+ * They do not exist in older versions, and in CEA-861-F they are
+ * defined as 'Not in use'.
+ */
+ HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC,
+ HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC_V2,
+ HDMI_AUDIO_CODING_TYPE_EXT_MPEG_SURROUND,
+
+ /* The following CXT values are only defined in CEA-861-F. */
+ HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC,
+ HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_V2,
+ HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC,
+ HDMI_AUDIO_CODING_TYPE_EXT_DRA,
+ HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_SURROUND,
+ HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC_SURROUND = 10,
+};
+
+struct hdmi_audio_infoframe {
+ enum hdmi_infoframe_type type;
+ unsigned char version;
+ unsigned char length;
+ unsigned char channels;
+ enum hdmi_audio_coding_type coding_type;
+ enum hdmi_audio_sample_size sample_size;
+ enum hdmi_audio_sample_frequency sample_frequency;
+ enum hdmi_audio_coding_type_ext coding_type_ext;
+ unsigned char channel_allocation;
+ unsigned char level_shift_value;
+ bool downmix_inhibit;
+
+};
+
+int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame);
+ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame,
+ void *buffer, size_t size);
+
+enum hdmi_3d_structure {
+ HDMI_3D_STRUCTURE_INVALID = -1,
+ HDMI_3D_STRUCTURE_FRAME_PACKING = 0,
+ HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE,
+ HDMI_3D_STRUCTURE_LINE_ALTERNATIVE,
+ HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL,
+ HDMI_3D_STRUCTURE_L_DEPTH,
+ HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH,
+ HDMI_3D_STRUCTURE_TOP_AND_BOTTOM,
+ HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF = 8,
+};
+
+
+struct hdmi_vendor_infoframe {
+ enum hdmi_infoframe_type type;
+ unsigned char version;
+ unsigned char length;
+ unsigned int oui;
+ u8 vic;
+ enum hdmi_3d_structure s3d_struct;
+ unsigned int s3d_ext_data;
+};
+
+int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe *frame);
+ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
+ void *buffer, size_t size);
+
+union hdmi_vendor_any_infoframe {
+ struct {
+ enum hdmi_infoframe_type type;
+ unsigned char version;
+ unsigned char length;
+ unsigned int oui;
+ } any;
+ struct hdmi_vendor_infoframe hdmi;
+};
+
+/**
+ * union hdmi_infoframe - overall union of all abstract infoframe representations
+ * @any: generic infoframe
+ * @avi: avi infoframe
+ * @spd: spd infoframe
+ * @vendor: union of all vendor infoframes
+ * @audio: audio infoframe
+ *
+ * This is used by the generic pack function. This works since all infoframes
+ * have the same header which also indicates which type of infoframe should be
+ * packed.
+ */
+union hdmi_infoframe {
+ struct hdmi_any_infoframe any;
+ struct hdmi_avi_infoframe avi;
+ struct hdmi_spd_infoframe spd;
+ union hdmi_vendor_any_infoframe vendor;
+ struct hdmi_audio_infoframe audio;
+};
+
+ssize_t
+hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer, size_t size);
+int hdmi_infoframe_unpack(union hdmi_infoframe *frame, void *buffer);
+void hdmi_infoframe_log(const char *level, struct device *dev,
+ union hdmi_infoframe *frame);
+
+#endif /* _DRM_HDMI_H */
diff --git a/sys/dev/pci/drm/include/linux/highmem.h b/sys/dev/pci/drm/include/linux/highmem.h
new file mode 100644
index 00000000000..39385671748
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/highmem.h
@@ -0,0 +1,58 @@
+/* $OpenBSD: highmem.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2013, 2014, 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_HIGHMEM_H
+#define _LINUX_HIGHMEM_H
+
+#include <uvm/uvm_extern.h>
+#include <linux/uaccess.h>
+
+void *kmap(struct vm_page *);
+void kunmap(void *addr);
+
+#define kmap_to_page(ptr) (ptr)
+
+#if defined(__i386__) || defined(__amd64__)
+
+static inline void *
+kmap_atomic(struct vm_page *pg)
+{
+ vaddr_t va;
+
+#if defined (__HAVE_PMAP_DIRECT)
+ va = pmap_map_direct(pg);
+#else
+ extern vaddr_t pmap_tmpmap_pa(paddr_t);
+ va = pmap_tmpmap_pa(VM_PAGE_TO_PHYS(pg));
+#endif
+ return (void *)va;
+}
+
+static inline void
+kunmap_atomic(void *addr)
+{
+#if defined (__HAVE_PMAP_DIRECT)
+ pmap_unmap_direct((vaddr_t)addr);
+#else
+ extern void pmap_tmpunmap_pa(void);
+ pmap_tmpunmap_pa();
+#endif
+}
+
+#endif /* defined(__i386__) || defined(__amd64__) */
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/hrtimer.h b/sys/dev/pci/drm/include/linux/hrtimer.h
new file mode 100644
index 00000000000..d0d9b5e1703
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/hrtimer.h
@@ -0,0 +1,21 @@
+/* Public domain. */
+
+#ifndef _LINUX_HRTIMER_H
+#define _LINUX_HRTIMER_H
+
+#include <sys/types.h>
+#include <sys/timeout.h>
+#include <linux/ktime.h>
+#include <linux/rbtree.h>
+
+enum hrtimer_restart { HRTIMER_NORESTART, HRTIMER_RESTART };
+struct hrtimer {
+ enum hrtimer_restart (*function)(struct hrtimer *);
+};
+
+#define HRTIMER_MODE_REL 1
+
+#define hrtimer_cancel(x) timeout_del(x)
+#define hrtimer_active(x) timeout_pending(x)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/hwmon-sysfs.h b/sys/dev/pci/drm/include/linux/hwmon-sysfs.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/hwmon-sysfs.h
diff --git a/sys/dev/pci/drm/include/linux/hwmon.h b/sys/dev/pci/drm/include/linux/hwmon.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/hwmon.h
diff --git a/sys/dev/pci/drm/include/linux/i2c-algo-bit.h b/sys/dev/pci/drm/include/linux/i2c-algo-bit.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/i2c-algo-bit.h
diff --git a/sys/dev/pci/drm/include/linux/i2c.h b/sys/dev/pci/drm/include/linux/i2c.h
new file mode 100644
index 00000000000..3a91dc8dcd3
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/i2c.h
@@ -0,0 +1,90 @@
+/* $OpenBSD: i2c.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2017 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_I2C_H
+#define _LINUX_I2C_H
+
+#include <sys/stdint.h>
+#include <sys/rwlock.h>
+#include <linux/workqueue.h>
+#include <linux/seq_file.h>
+
+#include <dev/i2c/i2cvar.h>
+
+struct i2c_algorithm;
+
+#define I2C_FUNC_I2C 0
+#define I2C_FUNC_SMBUS_EMUL 0
+#define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0
+#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0
+#define I2C_FUNC_10BIT_ADDR 0
+
+struct i2c_adapter {
+ struct i2c_controller ic;
+
+ char name[48];
+ const struct i2c_algorithm *algo;
+ void *algo_data;
+ int retries;
+
+ void *data;
+};
+
+#define I2C_NAME_SIZE 20
+
+struct i2c_msg {
+ uint16_t addr;
+ uint16_t flags;
+ uint16_t len;
+ uint8_t *buf;
+};
+
+#define I2C_M_RD 0x0001
+#define I2C_M_NOSTART 0x0002
+#define I2C_M_STOP 0x0004
+
+struct i2c_algorithm {
+ int (*master_xfer)(struct i2c_adapter *, struct i2c_msg *, int);
+ uint32_t (*functionality)(struct i2c_adapter *);
+};
+
+extern struct i2c_algorithm i2c_bit_algo;
+
+struct i2c_algo_bit_data {
+ struct i2c_controller ic;
+};
+
+int i2c_transfer(struct i2c_adapter *, struct i2c_msg *, int);
+#define i2c_add_adapter(x) 0
+#define i2c_del_adapter(x)
+#define __i2c_transfer(adap, msgs, num) i2c_transfer(adap, msgs, num)
+
+static inline void *
+i2c_get_adapdata(struct i2c_adapter *adap)
+{
+ return adap->data;
+}
+
+static inline void
+i2c_set_adapdata(struct i2c_adapter *adap, void *data)
+{
+ adap->data = data;
+}
+
+int i2c_bit_add_bus(struct i2c_adapter *);
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/idr.h b/sys/dev/pci/drm/include/linux/idr.h
new file mode 100644
index 00000000000..cebbad8a3f9
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/idr.h
@@ -0,0 +1,64 @@
+/* $OpenBSD: idr.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2016 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_IDR_H
+#define _LINUX_IDR_H
+
+#include <sys/tree.h>
+
+struct idr_entry {
+ SPLAY_ENTRY(idr_entry) entry;
+ int id;
+ void *ptr;
+};
+
+struct idr {
+ SPLAY_HEAD(idr_tree, idr_entry) tree;
+};
+
+void idr_init(struct idr *);
+void idr_preload(unsigned int);
+int idr_alloc(struct idr *, void *, int, int, unsigned int);
+#define idr_preload_end()
+void *idr_find(struct idr *, int);
+void *idr_replace(struct idr *, void *ptr, int);
+void *idr_remove(struct idr *, int);
+void idr_destroy(struct idr *);
+int idr_for_each(struct idr *, int (*)(int, void *, void *), void *);
+void *idr_get_next(struct idr *, int *);
+#define idr_init_base(idr, base) idr_init(idr)
+
+#define idr_for_each_entry(idp, entry, id) \
+ for (id = 0; ((entry) = idr_get_next(idp, &(id))) != NULL; id++)
+
+
+struct ida {
+ int counter;
+};
+
+#define DEFINE_IDA(name) \
+ struct ida name = { \
+ .counter = 0 \
+ }
+
+void ida_init(struct ida *);
+void ida_destroy(struct ida *);
+int ida_simple_get(struct ida *, unsigned int, unsigned nt, int);
+void ida_remove(struct ida *, int);
+void ida_simple_remove(struct ida *, int);
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/init.h b/sys/dev/pci/drm/include/linux/init.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/init.h
diff --git a/sys/dev/pci/drm/include/linux/input.h b/sys/dev/pci/drm/include/linux/input.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/input.h
diff --git a/sys/dev/pci/drm/include/linux/intel-iommu.h b/sys/dev/pci/drm/include/linux/intel-iommu.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/intel-iommu.h
diff --git a/sys/dev/pci/drm/include/linux/interrupt.h b/sys/dev/pci/drm/include/linux/interrupt.h
new file mode 100644
index 00000000000..242e35aa112
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/interrupt.h
@@ -0,0 +1,95 @@
+/* Public domain. */
+
+#ifndef _LINUX_INTERRUPT_H
+#define _LINUX_INTERRUPT_H
+
+#include <sys/task.h>
+
+#include <machine/intr.h>
+#include <linux/hardirq.h>
+#include <linux/irqflags.h>
+#include <linux/atomic.h>
+#include <linux/compiler.h>
+
+#ifndef STUB
+#include <sys/types.h>
+#include <sys/systm.h>
+#define STUB() do { printf("%s: stub\n", __func__); } while(0)
+#endif
+
+#define IRQF_SHARED 0
+
+#define disable_irq(x) intr_disable()
+#define enable_irq(x) intr_enable()
+
+#define request_irq(irq, hdlr, flags, name, dev) (0)
+#define free_irq(irq, dev)
+
+struct tasklet_struct {
+ void (*func)(unsigned long);
+ unsigned long data;
+ unsigned long state;
+ atomic_t count;
+ struct task task;
+};
+
+#define TASKLET_STATE_SCHED 1
+#define TASKLET_STATE_RUN 0
+
+extern struct taskq *taskletq;
+void tasklet_run(void *);
+
+static inline void
+tasklet_init(struct tasklet_struct *ts, void (*func)(unsigned long),
+ unsigned long data)
+{
+ ts->func = func;
+ ts->data = data;
+ ts->state = 0;
+ atomic_set(&ts->count, 0);
+ task_set(&ts->task, tasklet_run, ts);
+}
+
+static inline int
+tasklet_trylock(struct tasklet_struct *ts)
+{
+ return !test_and_set_bit(TASKLET_STATE_RUN, &ts->state);
+}
+
+static inline void
+tasklet_unlock(struct tasklet_struct *ts)
+{
+ smp_mb__before_atomic();
+ clear_bit(TASKLET_STATE_RUN, &ts->state);
+}
+
+static inline void
+tasklet_unlock_wait(struct tasklet_struct *ts)
+{
+ while (test_bit(TASKLET_STATE_RUN, &ts->state))
+ barrier();
+}
+
+static inline void
+tasklet_kill(struct tasklet_struct *ts)
+{
+ clear_bit(TASKLET_STATE_SCHED, &ts->state);
+ task_del(taskletq, &ts->task);
+ tasklet_unlock_wait(ts);
+}
+
+static inline void
+tasklet_schedule(struct tasklet_struct *ts)
+{
+ set_bit(TASKLET_STATE_SCHED, &ts->state);
+ task_add(taskletq, &ts->task);
+}
+
+static inline void
+tasklet_hi_schedule(struct tasklet_struct *ts)
+{
+ set_bit(TASKLET_STATE_SCHED, &ts->state);
+ task_add(taskletq, &ts->task);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/interval_tree.h b/sys/dev/pci/drm/include/linux/interval_tree.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/interval_tree.h
diff --git a/sys/dev/pci/drm/include/linux/interval_tree_generic.h b/sys/dev/pci/drm/include/linux/interval_tree_generic.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/interval_tree_generic.h
diff --git a/sys/dev/pci/drm/include/linux/io-mapping.h b/sys/dev/pci/drm/include/linux/io-mapping.h
new file mode 100644
index 00000000000..c42fe81773e
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/io-mapping.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUX_IO_MAPPING_H
+#define _LINUX_IO_MAPPING_H
+
+#include <linux/bitmap.h>
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/io.h b/sys/dev/pci/drm/include/linux/io.h
new file mode 100644
index 00000000000..2b9e956c3fc
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/io.h
@@ -0,0 +1,71 @@
+/* Public domain. */
+
+#ifndef _LINUX_IO_H
+#define _LINUX_IO_H
+
+#include <sys/systm.h>
+#include <linux/types.h>
+#include <linux/compiler.h>
+
+#define memcpy_toio(d, s, n) memcpy(d, s, n)
+#define memcpy_fromio(d, s, n) memcpy(d, s, n)
+#define memset_io(d, b, n) memset(d, b, n)
+
+static inline u8
+ioread8(const volatile void __iomem *addr)
+{
+ return (*(volatile uint8_t *)addr);
+}
+
+static inline u16
+ioread16(const volatile void __iomem *addr)
+{
+ return (*(volatile uint16_t *)addr);
+}
+
+static inline u32
+ioread32(const volatile void __iomem *addr)
+{
+ return (*(volatile uint32_t *)addr);
+}
+
+static inline u64
+ioread64(const volatile void __iomem *addr)
+{
+ return (*(volatile uint64_t *)addr);
+}
+
+static inline void
+iowrite8(u8 val, volatile void __iomem *addr)
+{
+ *(volatile uint8_t *)addr = val;
+}
+
+static inline void
+iowrite16(u16 val, volatile void __iomem *addr)
+{
+ *(volatile uint16_t *)addr = val;
+}
+
+static inline void
+iowrite32(u32 val, volatile void __iomem *addr)
+{
+ *(volatile uint32_t *)addr = val;
+}
+
+static inline void
+iowrite64(u64 val, volatile void __iomem *addr)
+{
+ *(volatile uint64_t *)addr = val;
+}
+
+#define readb(p) ioread8(p)
+#define writeb(v, p) iowrite8(v, p)
+#define readw(p) ioread16(p)
+#define writew(v, p) iowrite16(v, p)
+#define readl(p) ioread32(p)
+#define writel(v, p) iowrite32(v, p)
+#define readq(p) ioread64(p)
+#define writeq(v, p) iowrite64(v, p)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/iommu.h b/sys/dev/pci/drm/include/linux/iommu.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/iommu.h
diff --git a/sys/dev/pci/drm/include/linux/ioport.h b/sys/dev/pci/drm/include/linux/ioport.h
new file mode 100644
index 00000000000..d36b7597c9b
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/ioport.h
@@ -0,0 +1,25 @@
+/* Public domain. */
+
+#ifndef _LINUX_IOPORT_H
+#define _LINUX_IOPORT_H
+
+#include <sys/types.h>
+
+struct resource {
+ u_long start;
+ u_long end;
+};
+
+static inline resource_size_t
+resource_size(const struct resource *r)
+{
+ return r->end - r->start + 1;
+}
+
+#define DEFINE_RES_MEM(_start, _size) \
+ { \
+ .start = (_start), \
+ .end = (_start) + (_size) - 1, \
+ }
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/irq.h b/sys/dev/pci/drm/include/linux/irq.h
new file mode 100644
index 00000000000..426f489fe92
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/irq.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUX_IRQ_H
+#define _LINUX_IRQ_H
+
+#include <linux/irqreturn.h>
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/irq_work.h b/sys/dev/pci/drm/include/linux/irq_work.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/irq_work.h
diff --git a/sys/dev/pci/drm/include/linux/irqdomain.h b/sys/dev/pci/drm/include/linux/irqdomain.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/irqdomain.h
diff --git a/sys/dev/pci/drm/include/linux/irqflags.h b/sys/dev/pci/drm/include/linux/irqflags.h
new file mode 100644
index 00000000000..1c85fb7ab48
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/irqflags.h
@@ -0,0 +1,21 @@
+/* Public domain. */
+
+#ifndef _LINUX_IRQFLAGS_H
+#define _LINUX_IRQFLAGS_H
+
+#include <machine/intr.h>
+
+#define local_irq_save(x) (x) = splhigh()
+#define local_irq_restore(x) splx((x))
+
+#define local_irq_disable() intr_disable()
+#define local_irq_enable() intr_enable()
+
+static inline int
+irqs_disabled(void)
+{
+ /* XXX not quite true */
+ return (1);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/irqreturn.h b/sys/dev/pci/drm/include/linux/irqreturn.h
new file mode 100644
index 00000000000..f89f850c48b
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/irqreturn.h
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#ifndef _LINUX_IRQRETURN_H
+#define _LINUX_IRQRETURN_H
+
+typedef int irqreturn_t;
+enum irqreturn {
+ IRQ_NONE = 0,
+ IRQ_HANDLED = 1
+};
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/jiffies.h b/sys/dev/pci/drm/include/linux/jiffies.h
new file mode 100644
index 00000000000..861e76a05b8
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/jiffies.h
@@ -0,0 +1,45 @@
+/* Public domain. */
+
+#ifndef _LINUX_JIFFIES_H
+#define _LINUX_JIFFIES_H
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/limits.h>
+#include <sys/kernel.h>
+
+extern volatile unsigned long jiffies;
+#define jiffies_64 jiffies /* XXX */
+#undef HZ
+#define HZ hz
+
+#define MAX_JIFFY_OFFSET ((INT_MAX >> 1) - 1)
+
+#define time_in_range(x, min, max) ((x) >= (min) && (x) <= (max))
+
+#define jiffies_to_msecs(x) (((uint64_t)(x)) * 1000 / hz)
+#define jiffies_to_usecs(x) (((uint64_t)(x)) * 1000000 / hz)
+#define msecs_to_jiffies(x) (((uint64_t)(x)) * hz / 1000)
+#define usecs_to_jiffies(x) (((uint64_t)(x)) * hz / 1000000)
+#define nsecs_to_jiffies(x) (((uint64_t)(x)) * hz / 1000000000)
+#define nsecs_to_jiffies64(x) (((uint64_t)(x)) * hz / 1000000000)
+#define get_jiffies_64() jiffies
+#define time_after(a,b) ((long)(b) - (long)(a) < 0)
+#define time_after32(a,b) ((uint32_t)(b) - (uint32_t)(a) < 0)
+#define time_after_eq(a,b) ((long)(b) - (long)(a) <= 0)
+#define time_before(a,b) ((long)(a) - (long)(b) < 0)
+
+static inline unsigned long
+timespec_to_jiffies(const struct timespec *ts)
+{
+ long long to_ticks;
+
+ to_ticks = (long long)hz * ts->tv_sec + ts->tv_nsec / (tick * 1000);
+ if (to_ticks > INT_MAX)
+ to_ticks = INT_MAX;
+
+ return ((int)to_ticks);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/kconfig.h b/sys/dev/pci/drm/include/linux/kconfig.h
new file mode 100644
index 00000000000..21d227670f5
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/kconfig.h
@@ -0,0 +1,37 @@
+/* Public domain. */
+
+#ifndef _LINUX_KCONFIG_H
+#define _LINUX_KCONFIG_H
+
+#include "agp.h"
+
+#include <sys/endian.h>
+
+#define IS_ENABLED(x) x - 0
+#define IS_BUILTIN(x) 1
+
+#define CONFIG_DRM_FBDEV_OVERALLOC 0
+#define CONFIG_DRM_I915_DEBUG 0
+#define CONFIG_DRM_I915_DEBUG_GEM 0
+#define CONFIG_DRM_I915_FBDEV 1
+#define CONFIG_DRM_I915_ALPHA_SUPPORT 0
+#define CONFIG_DRM_I915_CAPTURE_ERROR 1
+#define CONFIG_DRM_I915_GVT 0
+#define CONFIG_DRM_I915_SW_FENCE_CHECK_DAG 0
+#define CONFIG_PM 0
+#define CONFIG_DRM_AMD_DC 1
+#define CONFIG_DRM_AMD_DC_DCN1_0 1
+#define CONFIG_DRM_AMDGPU_CIK 1
+#define CONFIG_DRM_AMDGPU_SI 1
+
+#if BYTE_ORDER == BIG_ENDIAN
+#define __BIG_ENDIAN
+#else
+#define __LITTLE_ENDIAN
+#endif
+
+#if NAGP > 0
+#define CONFIG_AGP 1
+#endif
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/kernel.h b/sys/dev/pci/drm/include/linux/kernel.h
new file mode 100644
index 00000000000..188efad2f4f
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/kernel.h
@@ -0,0 +1,138 @@
+/* Public domain. */
+
+#ifndef _LINUX_KERNEL_H
+#define _LINUX_KERNEL_H
+
+#include <sys/stdint.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/stdarg.h>
+#include <sys/malloc.h>
+
+#include <ddb/db_var.h>
+
+#include <linux/types.h>
+#include <linux/compiler.h>
+#include <linux/bitops.h>
+#include <linux/log2.h>
+#include <linux/linkage.h>
+#include <linux/printk.h>
+#include <linux/typecheck.h>
+#include <asm/byteorder.h>
+
+#define swap(a, b) \
+ do { __typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
+
+#define container_of(ptr, type, member) ({ \
+ const __typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
+
+#define S8_MAX INT8_MAX
+#define S16_MAX INT16_MAX
+#define S32_MAX INT32_MAX
+#define S64_MAX INT64_MAX
+
+#define U8_MAX UINT8_MAX
+#define U16_MAX UINT16_MAX
+#define U32_MAX UINT32_MAX
+#define U64_C(x) UINT64_C(x)
+#define U64_MAX UINT64_MAX
+
+#define IS_ALIGNED(x, y) (((x) & ((y) - 1)) == 0)
+
+#define ARRAY_SIZE nitems
+
+#define lower_32_bits(n) ((u32)(n))
+#define upper_32_bits(_val) ((u32)(((_val) >> 16) >> 16))
+
+#define scnprintf(str, size, fmt, arg...) snprintf(str, size, fmt, ## arg)
+
+#define min_t(t, a, b) ({ \
+ t __min_a = (a); \
+ t __min_b = (b); \
+ __min_a < __min_b ? __min_a : __min_b; })
+
+#define max_t(t, a, b) ({ \
+ t __max_a = (a); \
+ t __max_b = (b); \
+ __max_a > __max_b ? __max_a : __max_b; })
+
+#define clamp_t(t, x, a, b) min_t(t, max_t(t, x, a), b)
+#define clamp(x, a, b) clamp_t(__typeof(x), x, a, b)
+#define clamp_val(x, a, b) clamp_t(__typeof(x), x, a, b)
+
+#define min(a, b) MIN(a, b)
+#define max(a, b) MAX(a, b)
+#define min3(x, y, z) MIN(x, MIN(y, z))
+#define max3(x, y, z) MAX(x, MAX(y, z))
+
+#define mult_frac(x, n, d) (((x) * (n)) / (d))
+
+#define round_up(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
+#define round_down(x, y) (((x) / (y)) * (y)) /* y is power of two */
+#define rounddown(x, y) (((x) / (y)) * (y)) /* arbitary y */
+#define DIV_ROUND_UP(x, y) (((x) + ((y) - 1)) / (y))
+#define DIV_ROUND_UP_ULL(x, y) DIV_ROUND_UP(x, y)
+#define DIV_ROUND_DOWN(x, y) ((x) / (y))
+#define DIV_ROUND_DOWN_ULL(x, y) DIV_ROUND_DOWN(x, y)
+#define DIV_ROUND_CLOSEST(x, y) (((x) + ((y) / 2)) / (y))
+#define DIV_ROUND_CLOSEST_ULL(x, y) DIV_ROUND_CLOSEST(x, y)
+
+static inline char *
+kasprintf(int flags, const char *fmt, ...)
+{
+ char *buf;
+ size_t len;
+ va_list ap;
+
+ va_start(ap, fmt);
+ len = vsnprintf(NULL, 0, fmt, ap);
+ va_end(ap);
+
+ buf = malloc(len, M_DRM, flags);
+ if (buf) {
+ va_start(ap, fmt);
+ vsnprintf(buf, len, fmt, ap);
+ va_end(ap);
+ }
+
+ return buf;
+}
+
+static inline char *
+kvasprintf(int flags, const char *fmt, va_list ap)
+{
+ char *buf;
+ size_t len;
+
+ len = vsnprintf(NULL, 0, fmt, ap);
+
+ buf = malloc(len, M_DRM, flags);
+ if (buf) {
+ vsnprintf(buf, len, fmt, ap);
+ }
+
+ return buf;
+}
+
+static inline int
+_in_dbg_master(void)
+{
+#ifdef DDB
+ return (db_is_active);
+#endif
+ return (0);
+}
+
+#define oops_in_progress _in_dbg_master()
+
+#define might_sleep()
+#define might_sleep_if(x)
+
+#define add_taint(x, y)
+#define TAINT_MACHINE_CHECK 0
+#define LOCKDEP_STILL_OK 0
+
+#define u64_to_user_ptr(x) ((void *)(uintptr_t)(x))
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/kfifo.h b/sys/dev/pci/drm/include/linux/kfifo.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/kfifo.h
diff --git a/sys/dev/pci/drm/include/linux/kgdb.h b/sys/dev/pci/drm/include/linux/kgdb.h
new file mode 100644
index 00000000000..73759b3be75
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/kgdb.h
@@ -0,0 +1,17 @@
+/* Public domain. */
+
+#ifndef _LINUX_KGDB_H
+#define _LINUX_KGDB_H
+
+#include <ddb/db_var.h>
+
+static inline int
+in_dbg_master(void)
+{
+#ifdef DDB
+ return (db_is_active);
+#endif
+ return (0);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/kobject.h b/sys/dev/pci/drm/include/linux/kobject.h
new file mode 100644
index 00000000000..48a308a5fd0
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/kobject.h
@@ -0,0 +1,64 @@
+/* Public domain. */
+
+#ifndef _LINUX_KOBJECT_H
+#define _LINUX_KOBJECT_H
+
+#include <linux/kref.h>
+#include <linux/kernel.h>
+#include <linux/sysfs.h>
+
+struct kobject {
+ struct kref kref;
+ struct kobj_type *type;
+};
+
+struct kobj_type {
+ void (*release)(struct kobject *);
+};
+
+static inline void
+kobject_init(struct kobject *obj, struct kobj_type *type)
+{
+ kref_init(&obj->kref);
+ obj->type = type;
+}
+
+static inline int
+kobject_init_and_add(struct kobject *obj, struct kobj_type *type,
+ struct kobject *parent, const char *fmt, ...)
+{
+ kobject_init(obj, type);
+ return (0);
+}
+
+static inline struct kobject *
+kobject_get(struct kobject *obj)
+{
+ if (obj != NULL)
+ kref_get(&obj->kref);
+ return (obj);
+}
+
+static inline void
+kobject_release(struct kref *ref)
+{
+ struct kobject *obj = container_of(ref, struct kobject, kref);
+ if (obj->type && obj->type->release)
+ obj->type->release(obj);
+}
+
+static inline void
+kobject_put(struct kobject *obj)
+{
+ if (obj != NULL)
+ kref_put(&obj->kref, kobject_release);
+}
+
+static inline void
+kobject_del(struct kobject *obj)
+{
+}
+
+#define kobject_uevent_env(obj, act, envp)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/kref.h b/sys/dev/pci/drm/include/linux/kref.h
new file mode 100644
index 00000000000..1fbf37133cf
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/kref.h
@@ -0,0 +1,95 @@
+/* $OpenBSD: kref.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_KREF_H
+#define _LINUX_KREF_H
+
+#include <sys/types.h>
+#include <sys/rwlock.h>
+#include <sys/atomic.h>
+#include <linux/atomic.h>
+#include <linux/compiler.h>
+#include <linux/refcount.h>
+
+struct kref {
+ uint32_t refcount;
+};
+
+static inline void
+kref_init(struct kref *ref)
+{
+ ref->refcount = 1;
+}
+
+static inline unsigned int
+kref_read(const struct kref *ref)
+{
+ return atomic_read(&ref->refcount);
+}
+
+static inline void
+kref_get(struct kref *ref)
+{
+ atomic_inc_int(&ref->refcount);
+}
+
+static inline int
+kref_get_unless_zero(struct kref *ref)
+{
+ if (ref->refcount != 0) {
+ atomic_inc_int(&ref->refcount);
+ return (1);
+ } else {
+ return (0);
+ }
+}
+
+static inline int
+kref_put(struct kref *ref, void (*release)(struct kref *ref))
+{
+ if (atomic_dec_int_nv(&ref->refcount) == 0) {
+ release(ref);
+ return 1;
+ }
+ return 0;
+}
+
+static inline void
+kref_sub(struct kref *ref, unsigned int v, void (*release)(struct kref *ref))
+{
+ if (atomic_sub_int_nv(&ref->refcount, v) == 0)
+ release(ref);
+}
+
+static inline int
+kref_put_mutex(struct kref *kref, void (*release)(struct kref *kref),
+ struct rwlock *lock)
+{
+ if (!atomic_add_unless(&kref->refcount, -1, 1)) {
+ rw_enter_write(lock);
+ if (likely(atomic_dec_and_test(&kref->refcount))) {
+ release(kref);
+ return 1;
+ }
+ rw_exit_write(lock);
+ return 0;
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/kthread.h b/sys/dev/pci/drm/include/linux/kthread.h
new file mode 100644
index 00000000000..398cc1a1c30
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/kthread.h
@@ -0,0 +1,17 @@
+/* Public domain. */
+
+#ifndef _LINUX_KTHREAD_H
+#define _LINUX_KTHREAD_H
+
+/* both for printf */
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#define kthread_stop(a) do { printf("%s: stub\n", __func__); } while(0)
+#define kthread_park(a) do { printf("%s: stub\n", __func__); } while(0)
+#define kthread_unpark(a) do { printf("%s: stub\n", __func__); } while(0)
+#define kthread_should_stop() 0
+#define kthread_should_park() 0
+#define kthread_parkme()
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/ktime.h b/sys/dev/pci/drm/include/linux/ktime.h
new file mode 100644
index 00000000000..c4e78551b10
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/ktime.h
@@ -0,0 +1,141 @@
+/* $OpenBSD: ktime.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2013, 2014, 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_KTIME_H
+#define _LINUX_KTIME_H
+
+#include <sys/time.h>
+#include <linux/time.h>
+#include <linux/jiffies.h>
+
+typedef struct timeval ktime_t;
+
+static inline struct timeval
+ktime_get(void)
+{
+ struct timeval tv;
+
+ getmicrouptime(&tv);
+ return tv;
+}
+
+static inline struct timeval
+ktime_get_raw(void)
+{
+ struct timeval tv;
+
+ microuptime(&tv);
+ return tv;
+}
+
+static inline struct timeval
+ktime_get_monotonic_offset(void)
+{
+ struct timeval tv = {0, 0};
+ return tv;
+}
+
+static inline int64_t
+ktime_to_ms(struct timeval tv)
+{
+ return timeval_to_ms(&tv);
+}
+
+static inline int64_t
+ktime_to_us(struct timeval tv)
+{
+ return timeval_to_us(&tv);
+}
+
+static inline int64_t
+ktime_to_ns(struct timeval tv)
+{
+ return timeval_to_ns(&tv);
+}
+
+static inline int64_t
+ktime_get_raw_ns(void)
+{
+ return ktime_to_ns(ktime_get());
+}
+
+#define ktime_to_timeval(tv) (tv)
+
+static inline struct timespec64
+ktime_to_timespec64(struct timeval tv)
+{
+ struct timespec64 ts;
+ ts.tv_sec = tv.tv_sec;
+ ts.tv_nsec = tv.tv_usec * NSEC_PER_USEC;
+ return ts;
+}
+
+static inline struct timeval
+ktime_sub(struct timeval a, struct timeval b)
+{
+ struct timeval res;
+ timersub(&a, &b, &res);
+ return res;
+}
+
+static inline struct timeval
+ktime_add(struct timeval a, struct timeval b)
+{
+ struct timeval res;
+ timeradd(&a, &b, &res);
+ return res;
+}
+
+static inline struct timeval
+ktime_add_ns(struct timeval tv, int64_t ns)
+{
+ return ns_to_timeval(timeval_to_ns(&tv) + ns);
+}
+
+static inline struct timeval
+ktime_sub_ns(struct timeval tv, int64_t ns)
+{
+ return ns_to_timeval(timeval_to_ns(&tv) - ns);
+}
+
+static inline int64_t
+ktime_us_delta(struct timeval a, struct timeval b)
+{
+ return ktime_to_us(ktime_sub(a, b));
+}
+
+static inline int64_t
+ktime_ms_delta(struct timeval a, struct timeval b)
+{
+ return ktime_to_ms(ktime_sub(a, b));
+}
+
+static inline bool
+ktime_after(const struct timeval a, const struct timeval b)
+{
+ return timercmp(&a, &b, >);
+}
+
+static inline struct timeval
+ns_to_ktime(uint64_t ns)
+{
+ return ns_to_timeval(ns);
+}
+
+#include <linux/timekeeping.h>
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/linkage.h b/sys/dev/pci/drm/include/linux/linkage.h
new file mode 100644
index 00000000000..48c70f7816f
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/linkage.h
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#ifndef _LINUX_LINKAGE_H
+#define _LINUX_LINKAGE_H
+
+#include <linux/export.h>
+#include <linux/stringify.h>
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/list.h b/sys/dev/pci/drm/include/linux/list.h
new file mode 100644
index 00000000000..cf05e6f7ad7
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/list.h
@@ -0,0 +1,311 @@
+/* $OpenBSD: list.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/* drm_linux_list.h -- linux list functions for the BSDs.
+ * Created: Mon Apr 7 14:30:16 1999 by anholt@FreeBSD.org
+ */
+/*-
+ * Copyright 2003 Eric Anholt
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Eric Anholt <anholt@FreeBSD.org>
+ *
+ */
+
+#ifndef _DRM_LINUX_LIST_H_
+#define _DRM_LINUX_LIST_H_
+
+#include <sys/param.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+
+#define list_entry(ptr, type, member) container_of(ptr, type, member)
+
+static inline void
+INIT_LIST_HEAD(struct list_head *head) {
+ (head)->next = head;
+ (head)->prev = head;
+}
+
+#define LIST_HEAD_INIT(name) { &(name), &(name) }
+
+#define DRM_LIST_HEAD(name) \
+ struct list_head name = LIST_HEAD_INIT(name)
+
+static inline int
+list_empty(const struct list_head *head) {
+ return (head)->next == head;
+}
+
+static inline int
+list_is_singular(const struct list_head *head) {
+ return !list_empty(head) && ((head)->next == (head)->prev);
+}
+
+static inline int
+list_is_last(const struct list_head *list,
+ const struct list_head *head)
+{
+ return list->next == head;
+}
+
+static inline void
+list_add(struct list_head *new, struct list_head *head) {
+ (head)->next->prev = new;
+ (new)->next = (head)->next;
+ (new)->prev = head;
+ (head)->next = new;
+}
+
+static inline void
+list_add_tail(struct list_head *entry, struct list_head *head) {
+ (entry)->prev = (head)->prev;
+ (entry)->next = head;
+ (head)->prev->next = entry;
+ (head)->prev = entry;
+}
+
+static inline void
+list_del(struct list_head *entry) {
+ (entry)->next->prev = (entry)->prev;
+ (entry)->prev->next = (entry)->next;
+}
+
+#define __list_del_entry(x) list_del(x)
+
+static inline void list_replace(struct list_head *old,
+ struct list_head *new)
+{
+ new->next = old->next;
+ new->next->prev = new;
+ new->prev = old->prev;
+ new->prev->next = new;
+}
+
+static inline void list_replace_init(struct list_head *old,
+ struct list_head *new)
+{
+ list_replace(old, new);
+ INIT_LIST_HEAD(old);
+}
+
+static inline void list_move(struct list_head *list, struct list_head *head)
+{
+ list_del(list);
+ list_add(list, head);
+}
+
+static inline void list_move_tail(struct list_head *list,
+ struct list_head *head)
+{
+ list_del(list);
+ list_add_tail(list, head);
+}
+
+static inline void
+list_del_init(struct list_head *entry) {
+ (entry)->next->prev = (entry)->prev;
+ (entry)->prev->next = (entry)->next;
+ INIT_LIST_HEAD(entry);
+}
+
+#define list_next_entry(pos, member) \
+ list_entry(((pos)->member.next), typeof(*(pos)), member)
+
+#define list_prev_entry(pos, member) \
+ list_entry(((pos)->member.prev), typeof(*(pos)), member)
+
+#define list_for_each(entry, head) \
+ for (entry = (head)->next; entry != head; entry = (entry)->next)
+
+#define list_for_each_prev(entry, head) \
+ for (entry = (head)->prev; entry != (head); \
+ entry = entry->prev)
+
+#define list_for_each_safe(entry, temp, head) \
+ for (entry = (head)->next, temp = (entry)->next; \
+ entry != head; \
+ entry = temp, temp = entry->next)
+
+#define list_for_each_entry_safe_reverse(pos, n, head, member) \
+ for (pos = list_entry((head)->prev, __typeof(*pos), member), \
+ n = list_entry((pos)->member.prev, __typeof(*pos), member); \
+ &(pos)->member != (head); \
+ pos = n, n = list_entry(n->member.prev, __typeof(*n), member))
+
+#define list_for_each_entry_safe_from(pos, n, head, member) \
+ for (n = list_entry(pos->member.next, __typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry(n->member.next, __typeof(*n), member))
+
+#define list_for_each_entry(pos, head, member) \
+ for (pos = list_entry((head)->next, __typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = list_entry(pos->member.next, __typeof(*pos), member))
+
+#define list_for_each_entry_from(pos, head, member) \
+ for (; \
+ &pos->member != (head); \
+ pos = list_entry(pos->member.next, __typeof(*pos), member))
+
+#define list_for_each_entry_reverse(pos, head, member) \
+ for (pos = list_entry((head)->prev, __typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = list_entry(pos->member.prev, __typeof(*pos), member))
+
+#define list_for_each_entry_from_reverse(pos, head, member) \
+ for (; \
+ &pos->member != (head); \
+ pos = list_entry(pos->member.prev, __typeof(*pos), member))
+
+#define list_for_each_entry_continue(pos, head, member) \
+ for (pos = list_entry((pos)->member.next, __typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = list_entry(pos->member.next, __typeof(*pos), member))
+
+#define list_for_each_entry_continue_reverse(pos, head, member) \
+ for (pos = list_entry(pos->member.prev, __typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = list_entry(pos->member.prev, __typeof(*pos), member))
+
+/**
+ * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_safe(pos, n, head, member) \
+ for (pos = list_entry((head)->next, __typeof(*pos), member), \
+ n = list_entry(pos->member.next, __typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry(n->member.next, __typeof(*n), member))
+
+#define list_first_entry(ptr, type, member) \
+ list_entry((ptr)->next, type, member)
+
+#define list_first_entry_or_null(ptr, type, member) \
+ (list_empty(ptr) ? NULL : list_first_entry(ptr, type, member))
+
+#define list_last_entry(ptr, type, member) \
+ list_entry((ptr)->prev, type, member)
+
+static inline void
+__list_splice(const struct list_head *list, struct list_head *prev,
+ struct list_head *next)
+{
+ struct list_head *first = list->next;
+ struct list_head *last = list->prev;
+
+ first->prev = prev;
+ prev->next = first;
+
+ last->next = next;
+ next->prev = last;
+}
+
+static inline void
+list_splice(const struct list_head *list, struct list_head *head)
+{
+ if (list_empty(list))
+ return;
+
+ __list_splice(list, head, head->next);
+}
+
+static inline void
+list_splice_init(struct list_head *list, struct list_head *head)
+{
+ if (list_empty(list))
+ return;
+
+ __list_splice(list, head, head->next);
+ INIT_LIST_HEAD(list);
+}
+
+static inline void
+list_splice_tail(const struct list_head *list, struct list_head *head)
+{
+ if (list_empty(list))
+ return;
+
+ __list_splice(list, head->prev, head);
+}
+
+static inline void
+list_splice_tail_init(struct list_head *list, struct list_head *head)
+{
+ if (list_empty(list))
+ return;
+
+ __list_splice(list, head->prev, head);
+ INIT_LIST_HEAD(list);
+}
+
+void list_sort(void *, struct list_head *,
+ int (*)(void *, struct list_head *, struct list_head *));
+
+#define hlist_entry(ptr, type, member) \
+ ((ptr) ? container_of(ptr, type, member) : NULL)
+
+static inline void
+INIT_HLIST_HEAD(struct hlist_head *head) {
+ head->first = NULL;
+}
+
+static inline int
+hlist_empty(const struct hlist_head *head) {
+ return head->first == NULL;
+}
+
+static inline void
+hlist_add_head(struct hlist_node *new, struct hlist_head *head)
+{
+ if ((new->next = head->first) != NULL)
+ head->first->prev = &new->next;
+ head->first = new;
+ new->prev = &head->first;
+}
+
+static inline void
+hlist_del_init(struct hlist_node *node)
+{
+ if (node->next != NULL)
+ node->next->prev = node->prev;
+ *(node->prev) = node->next;
+ node->next = NULL;
+ node->prev = NULL;
+}
+
+#define hlist_for_each(pos, head) \
+ for (pos = (head)->first; pos != NULL; pos = pos->next)
+
+#define hlist_for_each_entry(pos, head, member) \
+ for (pos = hlist_entry((head)->first, __typeof(*pos), member); \
+ pos != NULL; \
+ pos = hlist_entry((pos)->member.next, __typeof(*pos), member))
+
+#define hlist_for_each_entry_safe(pos, n, head, member) \
+ for (pos = hlist_entry((head)->first, __typeof(*pos), member); \
+ pos != NULL && (n = pos->member.next, 1); \
+ pos = hlist_entry(n, __typeof(*pos), member))
+
+#endif /* _DRM_LINUX_LIST_H_ */
diff --git a/sys/dev/pci/drm/include/linux/list_sort.h b/sys/dev/pci/drm/include/linux/list_sort.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/list_sort.h
diff --git a/sys/dev/pci/drm/include/linux/llist.h b/sys/dev/pci/drm/include/linux/llist.h
new file mode 100644
index 00000000000..aea86b4faff
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/llist.h
@@ -0,0 +1,70 @@
+/* Public domain. */
+
+#ifndef _LINUX_LLIST_H
+#define _LINUX_LLIST_H
+
+#include <sys/atomic.h>
+
+struct llist_node {
+ struct llist_node *next;
+};
+
+struct llist_head {
+ struct llist_node *first;
+};
+
+#define llist_entry(ptr, type, member) \
+ ((ptr) ? container_of(ptr, type, member) : NULL)
+
+static inline struct llist_node *
+llist_del_all(struct llist_head *head)
+{
+ return atomic_swap_ptr(&head->first, NULL);
+}
+
+static inline struct llist_node *
+llist_del_first(struct llist_head *head)
+{
+ struct llist_node *first, *next;
+
+ do {
+ first = head->first;
+ if (first == NULL)
+ return NULL;
+ next = first->next;
+ } while (atomic_cas_ptr(&head->first, first, next) != first);
+
+ return first;
+}
+
+static inline bool
+llist_add(struct llist_node *new, struct llist_head *head)
+{
+ struct llist_node *first;
+
+ do {
+ new->next = first = head->first;
+ } while (atomic_cas_ptr(&head->first, first, new) != first);
+
+ return (first == NULL);
+}
+
+static inline void
+init_llist_head(struct llist_head *head)
+{
+ head->first = NULL;
+}
+
+static inline bool
+llist_empty(struct llist_head *head)
+{
+ return (head->first == NULL);
+}
+
+#define llist_for_each_entry_safe(pos, n, node, member) \
+ for (pos = llist_entry((node), __typeof(*pos), member); \
+ pos != NULL && \
+ (n = llist_entry(pos->member.next, __typeof(*pos), member), pos); \
+ pos = n)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/lockdep.h b/sys/dev/pci/drm/include/linux/lockdep.h
new file mode 100644
index 00000000000..a6407a1d645
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/lockdep.h
@@ -0,0 +1,16 @@
+/* Public domain. */
+
+#ifndef _LINUX_LOCKDEP_H
+#define _LINUX_LOCKDEP_H
+
+struct lock_class_key {
+};
+
+#define might_lock(lock)
+#define lockdep_assert_held(lock) do { (void)(lock); } while(0)
+#define lock_acquire(lock, a, b, c, d, e, f)
+#define lock_release(lock, a, b)
+#define lock_acquire_shared_recursive(lock, a, b, c, d)
+#define lockdep_set_subclass(a, b)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/log2.h b/sys/dev/pci/drm/include/linux/log2.h
new file mode 100644
index 00000000000..8351b473b1f
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/log2.h
@@ -0,0 +1,26 @@
+/* Public domain. */
+
+#ifndef _LINUX_LOG2_H
+#define _LINUX_LOG2_H
+
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#define ilog2(x) ((sizeof(x) <= 4) ? (fls(x) - 1) : (flsl(x) - 1))
+
+#define is_power_of_2(x) (((x) != 0) && (((x) - 1) & (x)) == 0)
+#define order_base_2(x) drm_order(x)
+
+static inline unsigned long
+roundup_pow_of_two(unsigned long x)
+{
+ return (1UL << flsl(x - 1));
+}
+
+static inline unsigned long
+rounddown_pow_of_two(unsigned long x)
+{
+ return (1UL << (flsl(x) - 1));
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/math64.h b/sys/dev/pci/drm/include/linux/math64.h
new file mode 100644
index 00000000000..7ca4f3b5808
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/math64.h
@@ -0,0 +1,59 @@
+/* Public domain. */
+
+#ifndef _LINUX_MATH64_H
+#define _LINUX_MATH64_H
+
+#include <sys/types.h>
+#include <asm/div64.h>
+
+static inline uint64_t
+div_u64(uint64_t x, uint32_t y)
+{
+ return (x / y);
+}
+
+static inline int64_t
+div_s64(int64_t x, int64_t y)
+{
+ return (x / y);
+}
+
+static inline uint64_t
+div64_u64(uint64_t x, uint64_t y)
+{
+ return (x / y);
+}
+
+static inline uint64_t
+div64_u64_rem(uint64_t x, uint64_t y, uint64_t *rem)
+{
+ *rem = x % y;
+ return (x / y);
+}
+
+static inline uint64_t
+div_u64_rem(uint64_t x, uint32_t y, uint32_t *rem)
+{
+ *rem = x % y;
+ return (x / y);
+}
+
+static inline int64_t
+div64_s64(int64_t x, int64_t y)
+{
+ return (x / y);
+}
+
+static inline uint64_t
+mul_u32_u32(uint32_t x, uint32_t y)
+{
+ return (uint64_t)x * y;
+}
+
+static inline uint64_t
+mul_u64_u32_div(uint64_t x, uint32_t y, uint32_t div)
+{
+ return (x * y) / div;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/media-bus-format.h b/sys/dev/pci/drm/include/linux/media-bus-format.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/media-bus-format.h
diff --git a/sys/dev/pci/drm/include/linux/mem_encrypt.h b/sys/dev/pci/drm/include/linux/mem_encrypt.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/mem_encrypt.h
diff --git a/sys/dev/pci/drm/include/linux/mempolicy.h b/sys/dev/pci/drm/include/linux/mempolicy.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/mempolicy.h
diff --git a/sys/dev/pci/drm/include/linux/mfd/core.h b/sys/dev/pci/drm/include/linux/mfd/core.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/mfd/core.h
diff --git a/sys/dev/pci/drm/include/linux/miscdevice.h b/sys/dev/pci/drm/include/linux/miscdevice.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/miscdevice.h
diff --git a/sys/dev/pci/drm/include/linux/mm.h b/sys/dev/pci/drm/include/linux/mm.h
new file mode 100644
index 00000000000..2723690beec
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/mm.h
@@ -0,0 +1,81 @@
+/* Public domain. */
+
+#ifndef _LINUX_MM_H
+#define _LINUX_MM_H
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/malloc.h>
+#include <sys/stdint.h>
+#include <sys/atomic.h>
+#include <machine/cpu.h>
+#include <uvm/uvm_extern.h>
+#include <linux/fs.h>
+#include <asm/pgtable.h>
+
+#define unmap_mapping_range(mapping, holebegin, holeend, even_cows)
+
+#define PageHighMem(x) 0
+
+#define page_address(x) VM_PAGE_TO_PHYS(x)
+#define page_to_phys(page) (VM_PAGE_TO_PHYS(page))
+#define page_to_pfn(pp) (VM_PAGE_TO_PHYS(pp) / PAGE_SIZE)
+#define pfn_to_page(pfn) (PHYS_TO_VM_PAGE(ptoa(pfn)))
+#define nth_page(page, n) (&(page)[(n)])
+#define offset_in_page(off) ((off) & PAGE_MASK)
+#define set_page_dirty(page) atomic_clearbits_int(&page->pg_flags, PG_CLEAN)
+
+#define PAGE_ALIGN(addr) (((addr) + PAGE_MASK) & ~PAGE_MASK)
+
+#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
+#define PFN_DOWN(x) ((x) >> PAGE_SHIFT)
+
+#define is_vmalloc_addr(ptr) true
+
+static inline void *
+kvmalloc(size_t size, gfp_t flags)
+{
+ return malloc(size, M_DRM, flags);
+}
+
+static inline void *
+kvmalloc_array(size_t n, size_t size, int flags)
+{
+ if (n == 0 || SIZE_MAX / n < size)
+ return NULL;
+ return malloc(n * size, M_DRM, flags);
+}
+
+static inline void *
+kvcalloc(size_t n, size_t size, int flags)
+{
+ return kvmalloc_array(n, size, flags | M_ZERO);
+}
+
+static inline void *
+kvzalloc(size_t size, int flags)
+{
+ return malloc(size, M_DRM, flags | M_ZERO);
+}
+
+static inline void
+kvfree(const void *objp)
+{
+ free((void *)objp, M_DRM, 0);
+}
+
+static inline long
+si_mem_available(void)
+{
+ return uvmexp.free;
+}
+
+#define MAX_ORDER 11
+
+static inline unsigned int
+get_order(size_t size)
+{
+ return flsl((size - 1) >> PAGE_SHIFT);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/mm_types.h b/sys/dev/pci/drm/include/linux/mm_types.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/mm_types.h
diff --git a/sys/dev/pci/drm/include/linux/mman.h b/sys/dev/pci/drm/include/linux/mman.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/mman.h
diff --git a/sys/dev/pci/drm/include/linux/mmu_context.h b/sys/dev/pci/drm/include/linux/mmu_context.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/mmu_context.h
diff --git a/sys/dev/pci/drm/include/linux/mmu_notifier.h b/sys/dev/pci/drm/include/linux/mmu_notifier.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/mmu_notifier.h
diff --git a/sys/dev/pci/drm/include/linux/mod_devicetable.h b/sys/dev/pci/drm/include/linux/mod_devicetable.h
new file mode 100644
index 00000000000..1a7bef7dc37
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/mod_devicetable.h
@@ -0,0 +1,42 @@
+/* Public domain. */
+
+#ifndef _LINUX_MOD_DEVICETABLE_H
+#define _LINUX_MOD_DEVICETABLE_H
+
+enum dmi_field {
+ DMI_NONE,
+ DMI_BIOS_VENDOR,
+ DMI_BIOS_VERSION,
+ DMI_BIOS_DATE,
+ DMI_SYS_VENDOR,
+ DMI_PRODUCT_NAME,
+ DMI_PRODUCT_VERSION,
+ DMI_PRODUCT_SERIAL,
+ DMI_PRODUCT_UUID,
+ DMI_BOARD_VENDOR,
+ DMI_BOARD_NAME,
+ DMI_BOARD_VERSION,
+ DMI_BOARD_SERIAL,
+ DMI_BOARD_ASSET_TAG,
+ DMI_CHASSIS_VENDOR,
+ DMI_CHASSIS_TYPE,
+ DMI_CHASSIS_VERSION,
+ DMI_CHASSIS_SERIAL,
+ DMI_CHASSIS_ASSET_TAG,
+ DMI_STRING_MAX,
+};
+
+struct dmi_strmatch {
+ unsigned char slot;
+ char substr[79];
+};
+
+struct dmi_system_id {
+ int (*callback)(const struct dmi_system_id *);
+ const char *ident;
+ struct dmi_strmatch matches[4];
+};
+#define DMI_MATCH(a, b) {(a), (b)}
+#define DMI_EXACT_MATCH(a, b) {(a), (b)}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/module.h b/sys/dev/pci/drm/include/linux/module.h
new file mode 100644
index 00000000000..416077c072c
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/module.h
@@ -0,0 +1,20 @@
+/* Public domain. */
+
+#ifndef _LINUX_MODULE_H
+#define _LINUX_MODULE_H
+
+#include <linux/export.h>
+#include <linux/moduleparam.h>
+
+struct module;
+
+#define MODULE_AUTHOR(x)
+#define MODULE_DESCRIPTION(x)
+#define MODULE_LICENSE(x)
+#define MODULE_FIRMWARE(x)
+#define MODULE_DEVICE_TABLE(x, y)
+#define module_init(x)
+#define module_exit(x)
+#define symbol_put(x)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/moduleparam.h b/sys/dev/pci/drm/include/linux/moduleparam.h
new file mode 100644
index 00000000000..c94fe7b45ad
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/moduleparam.h
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#ifndef _LINUX_MODULEPARAM_H
+#define _LINUX_MODULEPARAM_H
+
+#define MODULE_PARM_DESC(parm, desc)
+#define module_param(name, type, perm)
+#define module_param_named(name, value, type, perm)
+#define module_param_named_unsafe(name, value, type, perm)
+#define module_param_unsafe(name, type, perm)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/mount.h b/sys/dev/pci/drm/include/linux/mount.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/mount.h
diff --git a/sys/dev/pci/drm/include/linux/mutex.h b/sys/dev/pci/drm/include/linux/mutex.h
new file mode 100644
index 00000000000..ec0abdbbe69
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/mutex.h
@@ -0,0 +1,22 @@
+/* Public domain. */
+
+#ifndef _LINUX_MUTEX_H
+#define _LINUX_MUTEX_H
+
+#include <sys/stdint.h>
+#include <sys/rwlock.h>
+#include <linux/list.h>
+#include <linux/spinlock_types.h>
+
+#define DEFINE_MUTEX(x) struct rwlock x
+
+#define mutex_lock_interruptible(rwl) -rw_enter(rwl, RW_WRITE | RW_INTR)
+#define mutex_lock(rwl) rw_enter_write(rwl)
+#define mutex_lock_nest_lock(rwl, sub) rw_enter_write(rwl)
+#define mutex_lock_nested(rwl, sub) rw_enter_write(rwl)
+#define mutex_trylock(rwl) (rw_enter(rwl, RW_WRITE | RW_NOSLEEP) == 0)
+#define mutex_unlock(rwl) rw_exit_write(rwl)
+#define mutex_is_locked(rwl) (rw_status(rwl) == RW_WRITE)
+#define mutex_destroy(rwl)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/nospec.h b/sys/dev/pci/drm/include/linux/nospec.h
new file mode 100644
index 00000000000..ddbbbbd9745
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/nospec.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUX_NOSPEC_H
+#define _LINUX_NOSPEC_H
+
+#define array_index_nospec(a, b) (a)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/notifier.h b/sys/dev/pci/drm/include/linux/notifier.h
new file mode 100644
index 00000000000..ff376a2cc3f
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/notifier.h
@@ -0,0 +1,16 @@
+/* Public domain. */
+
+#ifndef _LINUX_NOTIFIER_H
+#define _LINUX_NOTIFIER_H
+
+struct notifier_block {
+ void *notifier_call;
+};
+
+#define ATOMIC_INIT_NOTIFIER_HEAD(x)
+
+#define NOTIFY_DONE 0
+#define NOTIFY_OK 1
+#define NOTIFY_BAD 2
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/of_device.h b/sys/dev/pci/drm/include/linux/of_device.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/of_device.h
diff --git a/sys/dev/pci/drm/include/linux/oom.h b/sys/dev/pci/drm/include/linux/oom.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/oom.h
diff --git a/sys/dev/pci/drm/include/linux/overflow.h b/sys/dev/pci/drm/include/linux/overflow.h
new file mode 100644
index 00000000000..ea8fa45e399
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/overflow.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUX_OVERFLOW_H
+#define _LINUX_OVERFLOW_H
+
+#define array_size(x, y) ((x) * (y))
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/pagemap.h b/sys/dev/pci/drm/include/linux/pagemap.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/pagemap.h
diff --git a/sys/dev/pci/drm/include/linux/pagevec.h b/sys/dev/pci/drm/include/linux/pagevec.h
new file mode 100644
index 00000000000..27b8631338a
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/pagevec.h
@@ -0,0 +1,50 @@
+/* Public domain. */
+
+#ifndef _LINUX_PAGEVEC_H
+#define _LINUX_PAGEVEC_H
+
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/errno.h>
+
+#define PAGEVEC_SIZE 15
+
+struct pagevec {
+ uint8_t nr;
+ struct vm_page *pages[PAGEVEC_SIZE];
+};
+
+void __pagevec_release(struct pagevec *);
+
+static inline unsigned int
+pagevec_space(struct pagevec *pvec)
+{
+ return PAGEVEC_SIZE - pvec->nr;
+}
+
+static inline void
+pagevec_init(struct pagevec *pvec)
+{
+ pvec->nr = 0;
+}
+
+static inline void
+pagevec_reinit(struct pagevec *pvec)
+{
+ pvec->nr = 0;
+}
+
+static inline unsigned int
+pagevec_count(struct pagevec *pvec)
+{
+ return pvec->nr;
+}
+
+static inline unsigned int
+pagevec_add(struct pagevec *pvec, struct vm_page *page)
+{
+ pvec->pages[pvec->nr++] = page;
+ return PAGEVEC_SIZE - pvec->nr;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/pci.h b/sys/dev/pci/drm/include/linux/pci.h
new file mode 100644
index 00000000000..cf0ffcc6eea
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/pci.h
@@ -0,0 +1,301 @@
+/* $OpenBSD: pci.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_PCI_H
+#define _LINUX_PCI_H
+
+#include <sys/types.h>
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+/* sparc64 cpu.h needs time.h and siginfo.h (indirect via param.h) */
+#include <sys/param.h>
+#include <machine/cpu.h>
+#include <uvm/uvm_extern.h>
+
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/kobject.h>
+
+struct pci_dev;
+
+struct pci_bus {
+ pci_chipset_tag_t pc;
+ unsigned char number;
+ pcitag_t *bridgetag;
+ struct pci_dev *self;
+};
+
+struct pci_dev {
+ struct pci_bus _bus;
+ struct pci_bus *bus;
+
+ unsigned int devfn;
+ uint16_t vendor;
+ uint16_t device;
+ uint16_t subsystem_vendor;
+ uint16_t subsystem_device;
+ uint8_t revision;
+
+ pci_chipset_tag_t pc;
+ pcitag_t tag;
+ struct pci_softc *pci;
+
+ int irq;
+ int msi_enabled;
+ uint8_t no_64bit_msi;
+};
+#define PCI_ANY_ID (uint16_t) (~0U)
+
+#define PCI_VENDOR_ID_APPLE PCI_VENDOR_APPLE
+#define PCI_VENDOR_ID_ASUSTEK PCI_VENDOR_ASUSTEK
+#define PCI_VENDOR_ID_ATI PCI_VENDOR_ATI
+#define PCI_VENDOR_ID_DELL PCI_VENDOR_DELL
+#define PCI_VENDOR_ID_HP PCI_VENDOR_HP
+#define PCI_VENDOR_ID_IBM PCI_VENDOR_IBM
+#define PCI_VENDOR_ID_INTEL PCI_VENDOR_INTEL
+#define PCI_VENDOR_ID_SONY PCI_VENDOR_SONY
+#define PCI_VENDOR_ID_VIA PCI_VENDOR_VIATECH
+
+#define PCI_DEVICE_ID_ATI_RADEON_QY PCI_PRODUCT_ATI_RADEON_QY
+
+#define PCI_SUBVENDOR_ID_REDHAT_QUMRANET 0x1af4
+#define PCI_SUBDEVICE_ID_QEMU 0x1100
+
+#define PCI_DEVFN(slot, func) ((slot) << 3 | (func))
+#define PCI_SLOT(devfn) ((devfn) >> 3)
+#define PCI_FUNC(devfn) ((devfn) & 0x7)
+
+#define pci_dev_put(x)
+
+#define PCI_EXP_DEVSTA 0x0a
+#define PCI_EXP_DEVSTA_TRPND 0x0020
+#define PCI_EXP_LNKCAP 0x0c
+#define PCI_EXP_LNKCAP_CLKPM 0x00040000
+#define PCI_EXP_LNKCTL 0x10
+#define PCI_EXP_LNKCTL_HAWD 0x0200
+#define PCI_EXP_LNKCTL2 0x30
+
+#define PCI_COMMAND PCI_COMMAND_STATUS_REG
+#define PCI_COMMAND_MEMORY PCI_COMMAND_MEM_ENABLE
+
+static inline int
+pci_read_config_dword(struct pci_dev *pdev, int reg, u32 *val)
+{
+ *val = pci_conf_read(pdev->pc, pdev->tag, reg);
+ return 0;
+}
+
+static inline int
+pci_read_config_word(struct pci_dev *pdev, int reg, u16 *val)
+{
+ uint32_t v;
+
+ v = pci_conf_read(pdev->pc, pdev->tag, (reg & ~0x2));
+ *val = (v >> ((reg & 0x2) * 8));
+ return 0;
+}
+
+static inline int
+pci_read_config_byte(struct pci_dev *pdev, int reg, u8 *val)
+{
+ uint32_t v;
+
+ v = pci_conf_read(pdev->pc, pdev->tag, (reg & ~0x3));
+ *val = (v >> ((reg & 0x3) * 8));
+ return 0;
+}
+
+static inline int
+pci_write_config_dword(struct pci_dev *pdev, int reg, u32 val)
+{
+ pci_conf_write(pdev->pc, pdev->tag, reg, val);
+ return 0;
+}
+
+static inline int
+pci_write_config_word(struct pci_dev *pdev, int reg, u16 val)
+{
+ uint32_t v;
+
+ v = pci_conf_read(pdev->pc, pdev->tag, (reg & ~0x2));
+ v &= ~(0xffff << ((reg & 0x2) * 8));
+ v |= (val << ((reg & 0x2) * 8));
+ pci_conf_write(pdev->pc, pdev->tag, (reg & ~0x2), v);
+ return 0;
+}
+
+static inline int
+pci_write_config_byte(struct pci_dev *pdev, int reg, u8 val)
+{
+ uint32_t v;
+
+ v = pci_conf_read(pdev->pc, pdev->tag, (reg & ~0x3));
+ v &= ~(0xff << ((reg & 0x3) * 8));
+ v |= (val << ((reg & 0x3) * 8));
+ pci_conf_write(pdev->pc, pdev->tag, (reg & ~0x3), v);
+ return 0;
+}
+
+static inline int
+pci_bus_read_config_word(struct pci_bus *bus, unsigned int devfn,
+ int reg, u16 *val)
+{
+ pcitag_t tag = pci_make_tag(bus->pc, bus->number,
+ PCI_SLOT(devfn), PCI_FUNC(devfn));
+ uint32_t v;
+
+ v = pci_conf_read(bus->pc, tag, (reg & ~0x2));
+ *val = (v >> ((reg & 0x2) * 8));
+ return 0;
+}
+
+static inline int
+pci_bus_read_config_byte(struct pci_bus *bus, unsigned int devfn,
+ int reg, u8 *val)
+{
+ pcitag_t tag = pci_make_tag(bus->pc, bus->number,
+ PCI_SLOT(devfn), PCI_FUNC(devfn));
+ uint32_t v;
+
+ v = pci_conf_read(bus->pc, tag, (reg & ~0x3));
+ *val = (v >> ((reg & 0x3) * 8));
+ return 0;
+}
+
+static inline int
+pci_bus_write_config_byte(struct pci_bus *bus, unsigned int devfn,
+ int reg, u8 val)
+{
+ pcitag_t tag = pci_make_tag(bus->pc, bus->number,
+ PCI_SLOT(devfn), PCI_FUNC(devfn));
+ uint32_t v;
+
+ v = pci_conf_read(bus->pc, tag, (reg & ~0x3));
+ v &= ~(0xff << ((reg & 0x3) * 8));
+ v |= (val << ((reg & 0x3) * 8));
+ pci_conf_write(bus->pc, tag, (reg & ~0x3), v);
+ return 0;
+}
+
+static inline int
+pci_pcie_cap(struct pci_dev *pdev)
+{
+ int pos;
+ if (!pci_get_capability(pdev->pc, pdev->tag, PCI_CAP_PCIEXPRESS,
+ &pos, NULL))
+ return -EINVAL;
+ return pos;
+}
+
+static inline bool
+pci_is_root_bus(struct pci_bus *pbus)
+{
+ return (pbus->bridgetag == NULL);
+}
+
+static inline int
+pcie_capability_read_dword(struct pci_dev *pdev, int off, u32 *val)
+{
+ int pos;
+ if (!pci_get_capability(pdev->pc, pdev->tag, PCI_CAP_PCIEXPRESS,
+ &pos, NULL)) {
+ *val = 0;
+ return -EINVAL;
+ }
+ *val = pci_conf_read(pdev->pc, pdev->tag, pos + off);
+ return 0;
+}
+
+#define pci_set_master(x)
+#define pci_clear_master(x)
+
+#define pci_save_state(x)
+#define pci_restore_state(x)
+
+#define pci_enable_msi(x) 0
+#define pci_disable_msi(x)
+
+typedef enum {
+ PCI_D0,
+ PCI_D1,
+ PCI_D2,
+ PCI_D3hot,
+ PCI_D3cold
+} pci_power_t;
+
+enum pci_bus_speed {
+ PCIE_SPEED_2_5GT,
+ PCIE_SPEED_5_0GT,
+ PCIE_SPEED_8_0GT,
+ PCIE_SPEED_16_0GT,
+ PCI_SPEED_UNKNOWN
+};
+
+enum pcie_link_width {
+ PCIE_LNK_X1 = 1,
+ PCIE_LNK_X2 = 2,
+ PCIE_LNK_X4 = 4,
+ PCIE_LNK_X8 = 8,
+ PCIE_LNK_X12 = 12,
+ PCIE_LNK_X16 = 16,
+ PCIE_LNK_X32 = 32,
+ PCIE_LNK_WIDTH_UNKNOWN = 0xff
+};
+
+enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *);
+enum pcie_link_width pcie_get_width_cap(struct pci_dev *);
+int pci_resize_resource(struct pci_dev *, int, int);
+
+#define pci_save_state(x)
+#define pci_enable_device(x) 0
+#define pci_disable_device(x)
+#define pci_is_thunderbolt_attached(x) false
+#define pci_set_drvdata(x, y)
+
+static inline int
+pci_set_power_state(struct pci_dev *dev, int state)
+{
+ return 0;
+}
+
+#if defined(__amd64__) || defined(__i386__)
+
+#define PCI_DMA_BIDIRECTIONAL 0
+
+static inline dma_addr_t
+pci_map_page(struct pci_dev *pdev, struct vm_page *page, unsigned long offset, size_t size, int direction)
+{
+ return VM_PAGE_TO_PHYS(page);
+}
+
+static inline void
+pci_unmap_page(struct pci_dev *pdev, dma_addr_t dma_address, size_t size, int direction)
+{
+}
+
+static inline int
+pci_dma_mapping_error(struct pci_dev *pdev, dma_addr_t dma_addr)
+{
+ return 0;
+}
+
+#define pci_set_dma_mask(x, y) 0
+#define pci_set_consistent_dma_mask(x, y) 0
+
+#endif /* defined(__amd64__) || defined(__i386__) */
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/perf_event.h b/sys/dev/pci/drm/include/linux/perf_event.h
new file mode 100644
index 00000000000..935fd59b5fb
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/perf_event.h
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#ifndef _LINUX_PERF_EVENT_H
+#define _LINUX_PERF_EVENT_H
+
+struct pmu {
+};
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/pfn_t.h b/sys/dev/pci/drm/include/linux/pfn_t.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/pfn_t.h
diff --git a/sys/dev/pci/drm/include/linux/pid.h b/sys/dev/pci/drm/include/linux/pid.h
new file mode 100644
index 00000000000..5aa09ef5322
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/pid.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUX_PID_H
+#define _LINUX_PID_H
+
+#define put_pid(x)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/platform_device.h b/sys/dev/pci/drm/include/linux/platform_device.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/platform_device.h
diff --git a/sys/dev/pci/drm/include/linux/pm.h b/sys/dev/pci/drm/include/linux/pm.h
new file mode 100644
index 00000000000..35c166bf79f
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/pm.h
@@ -0,0 +1,11 @@
+/* Public domain. */
+
+#ifndef _LINUX_PM_H
+#define _LINUX_PM_H
+
+#include <linux/completion.h>
+
+struct dev_pm_domain {
+};
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/pm_qos.h b/sys/dev/pci/drm/include/linux/pm_qos.h
new file mode 100644
index 00000000000..2a4e938b757
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/pm_qos.h
@@ -0,0 +1,17 @@
+/* Public domain. */
+
+#ifndef _LINUX_PM_QOS_H
+#define _LINUX_PM_QOS_H
+
+struct pm_qos_request {
+};
+
+#define PM_QOS_CPU_DMA_LATENCY 1
+
+#define PM_QOS_DEFAULT_VALUE -1
+
+#define pm_qos_update_request(a, b)
+#define pm_qos_add_request(a, b, c)
+#define pm_qos_remove_request(a)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/pm_runtime.h b/sys/dev/pci/drm/include/linux/pm_runtime.h
new file mode 100644
index 00000000000..efbcfaa86bb
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/pm_runtime.h
@@ -0,0 +1,26 @@
+/* Public domain. */
+
+#ifndef _LINUX_PM_RUNTIME_H
+#define _LINUX_PM_RUNTIME_H
+
+#include <sys/types.h>
+#include <sys/device.h>
+#include <linux/pm.h>
+
+#define pm_runtime_mark_last_busy(x)
+#define pm_runtime_use_autosuspend(x)
+#define pm_runtime_put_autosuspend(x)
+#define pm_runtime_set_autosuspend_delay(x, y)
+#define pm_runtime_set_active(x)
+#define pm_runtime_allow(x)
+#define pm_runtime_put_noidle(x)
+#define pm_runtime_forbid(x)
+#define pm_runtime_get_noresume(x)
+
+static inline int
+pm_runtime_get_sync(struct device *dev)
+{
+ return 0;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/pnp.h b/sys/dev/pci/drm/include/linux/pnp.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/pnp.h
diff --git a/sys/dev/pci/drm/include/linux/poll.h b/sys/dev/pci/drm/include/linux/poll.h
new file mode 100644
index 00000000000..1ba9509bba9
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/poll.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUX_POLL_H
+#define _LINUX_POLL_H
+
+#include <linux/ktime.h>
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/power_supply.h b/sys/dev/pci/drm/include/linux/power_supply.h
new file mode 100644
index 00000000000..20391f528ae
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/power_supply.h
@@ -0,0 +1,13 @@
+/* Public domain. */
+
+#ifndef _LINUX_POWER_SUPPLY_H
+#define _LINUX_POWER_SUPPLY_H
+
+static inline int
+power_supply_is_system_supplied(void)
+{
+ /* XXX return 0 if on battery */
+ return (1);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/preempt.h b/sys/dev/pci/drm/include/linux/preempt.h
new file mode 100644
index 00000000000..61bd674e12d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/preempt.h
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#ifndef _LINUX_PREEMPT_H
+#define _LINUX_PREEMPT_H
+
+#define preempt_enable()
+#define preempt_disable()
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/prefetch.h b/sys/dev/pci/drm/include/linux/prefetch.h
new file mode 100644
index 00000000000..b3dd6c3969f
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/prefetch.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUX_PREFETCH_H
+#define _LINUX_PREFETCH_H
+
+#define prefetchw(x) __builtin_prefetch(x,1)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/printk.h b/sys/dev/pci/drm/include/linux/printk.h
new file mode 100644
index 00000000000..854cdfb6598
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/printk.h
@@ -0,0 +1,61 @@
+/* Public domain. */
+
+#ifndef _LINUX_PRINTK_H
+#define _LINUX_PRINTK_H
+
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/stdarg.h>
+
+#define KERN_INFO ""
+#define KERN_WARNING ""
+#define KERN_NOTICE ""
+#define KERN_DEBUG ""
+#define KERN_CRIT ""
+#define KERN_ERR ""
+
+#ifndef pr_fmt
+#define pr_fmt(fmt) fmt
+#endif
+
+#define printk_once(fmt, arg...) ({ \
+ static int __warned; \
+ if (!__warned) { \
+ printf(fmt, ## arg); \
+ __warned = 1; \
+ } \
+})
+
+#define printk(fmt, arg...) printf(fmt, ## arg)
+#define pr_warn(fmt, arg...) printf(pr_fmt(fmt), ## arg)
+#define pr_warn_once(fmt, arg...) printk_once(pr_fmt(fmt), ## arg)
+#define pr_notice(fmt, arg...) printf(pr_fmt(fmt), ## arg)
+#define pr_crit(fmt, arg...) printf(pr_fmt(fmt), ## arg)
+#define pr_err(fmt, arg...) printf(pr_fmt(fmt), ## arg)
+#define pr_cont(fmt, arg...) printf(pr_fmt(fmt), ## arg)
+
+#ifdef DRMDEBUG
+#define pr_info(fmt, arg...) printf(pr_fmt(fmt), ## arg)
+#define pr_info_once(fmt, arg...) printk_once(pr_fmt(fmt), ## arg)
+#define pr_debug(fmt, arg...) printf(pr_fmt(fmt), ## arg)
+#else
+#define pr_info(fmt, arg...) do { } while(0)
+#define pr_info_once(fmt, arg...) do { } while(0)
+#define pr_debug(fmt, arg...) do { } while(0)
+#endif
+
+enum {
+ DUMP_PREFIX_NONE,
+ DUMP_PREFIX_ADDRESS,
+ DUMP_PREFIX_OFFSET
+};
+
+void print_hex_dump(const char *, const char *, int, int, int,
+ const void *, size_t, bool);
+
+struct va_format {
+ const char *fmt;
+ va_list *va;
+};
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/processor.h b/sys/dev/pci/drm/include/linux/processor.h
new file mode 100644
index 00000000000..9ddf8c3a753
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/processor.h
@@ -0,0 +1,22 @@
+/* Public domain. */
+
+#ifndef _LINUX_PROCESSOR_H
+#define _LINUX_PROCESSOR_H
+
+#include <sys/systm.h>
+/* sparc64 cpu.h needs time.h and siginfo.h (indirect via param.h) */
+#include <sys/param.h>
+#include <machine/cpu.h>
+#include <linux/jiffies.h>
+
+static inline void
+cpu_relax(void)
+{
+ CPU_BUSY_CYCLE();
+ if (cold) {
+ delay(tick);
+ jiffies++;
+ }
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/pwm.h b/sys/dev/pci/drm/include/linux/pwm.h
new file mode 100644
index 00000000000..c2f54f3cc26
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/pwm.h
@@ -0,0 +1,50 @@
+/* Public domain. */
+
+#ifndef _LINUX_PWM_H
+#define _LINUX_PWM_H
+
+#include <sys/errno.h>
+#include <linux/err.h>
+
+struct pwm_device;
+
+static inline struct pwm_device *
+pwm_get(struct device *dev, const char *consumer)
+{
+ return ERR_PTR(-ENODEV);
+}
+
+static inline void
+pwm_put(struct pwm_device *pwm)
+{
+}
+
+static inline unsigned int
+pwm_get_duty_cycle(const struct pwm_device *pwm)
+{
+ return 0;
+}
+
+static inline int
+pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
+{
+ return -EINVAL;
+}
+
+static inline int
+pwm_enable(struct pwm_device *pwm)
+{
+ return -EINVAL;
+}
+
+static inline void
+pwm_disable(struct pwm_device *pwm)
+{
+}
+
+static inline void
+pwm_apply_args(struct pwm_device *pwm)
+{
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/radix-tree.h b/sys/dev/pci/drm/include/linux/radix-tree.h
new file mode 100644
index 00000000000..104ebafbe9f
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/radix-tree.h
@@ -0,0 +1,84 @@
+/*-
+ * Copyright (c) 2010 Isilon Systems, Inc.
+ * Copyright (c) 2010 iX Systems, Inc.
+ * Copyright (c) 2010 Panasas, Inc.
+ * Copyright (c) 2013-2018 Mellanox Technologies, Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: head/sys/compat/linuxkpi/common/include/linux/radix-tree.h 334483 2018-06-01 11:42:09Z hselasky $
+ */
+#ifndef _LINUX_RADIX_TREE_H_
+#define _LINUX_RADIX_TREE_H_
+
+#include <linux/types.h>
+
+#define RADIX_TREE_MAP_SHIFT 6
+#define RADIX_TREE_MAP_SIZE (1UL << RADIX_TREE_MAP_SHIFT)
+#define RADIX_TREE_MAP_MASK (RADIX_TREE_MAP_SIZE - 1UL)
+#define RADIX_TREE_MAX_HEIGHT \
+ howmany(sizeof(long) * NBBY, RADIX_TREE_MAP_SHIFT)
+
+#define RADIX_TREE_ENTRY_MASK 3UL
+#define RADIX_TREE_EXCEPTIONAL_ENTRY 2UL
+#define RADIX_TREE_EXCEPTIONAL_SHIFT 2
+
+struct radix_tree_node {
+ void *slots[RADIX_TREE_MAP_SIZE];
+ int count;
+};
+
+struct radix_tree_root {
+ struct radix_tree_node *rnode;
+ gfp_t gfp_mask;
+ int height;
+};
+
+struct radix_tree_iter {
+ unsigned long index;
+};
+
+#define RADIX_TREE_INIT(mask) \
+ { .rnode = NULL, .gfp_mask = mask, .height = 0 };
+#define INIT_RADIX_TREE(root, mask) \
+ { (root)->rnode = NULL; (root)->gfp_mask = mask; (root)->height = 0; }
+#define RADIX_TREE(name, mask) \
+ struct radix_tree_root name = RADIX_TREE_INIT(mask)
+
+#define radix_tree_for_each_slot(slot, root, iter, start) \
+ for ((iter)->index = (start); \
+ radix_tree_iter_find(root, iter, &(slot)); (iter)->index++)
+
+static inline int
+radix_tree_exception(void *arg)
+{
+ return ((uintptr_t)arg & RADIX_TREE_ENTRY_MASK);
+}
+
+void *radix_tree_lookup(struct radix_tree_root *, unsigned long);
+void *radix_tree_delete(struct radix_tree_root *, unsigned long);
+int radix_tree_insert(struct radix_tree_root *, unsigned long, void *);
+bool radix_tree_iter_find(struct radix_tree_root *, struct radix_tree_iter *, void ***);
+void radix_tree_iter_delete(struct radix_tree_root *, struct radix_tree_iter *, void **);
+
+#endif /* _LINUX_RADIX_TREE_H_ */
diff --git a/sys/dev/pci/drm/include/linux/random.h b/sys/dev/pci/drm/include/linux/random.h
new file mode 100644
index 00000000000..17d3611c862
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/random.h
@@ -0,0 +1,30 @@
+/* Public domain. */
+
+#ifndef _LINUX_RANDOM_H
+#define _LINUX_RANDOM_H
+
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#define get_random_u32() arc4random()
+#define get_random_int() arc4random()
+
+static inline uint64_t
+get_random_u64(void)
+{
+ uint64_t r;
+ arc4random_buf(&r, sizeof(r));
+ return r;
+}
+
+static inline unsigned long
+get_random_long(void)
+{
+#ifdef __LP64__
+ return get_random_u64();
+#else
+ return get_random_u32();
+#endif
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/ratelimit.h b/sys/dev/pci/drm/include/linux/ratelimit.h
new file mode 100644
index 00000000000..a5f03f0eae4
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/ratelimit.h
@@ -0,0 +1,11 @@
+/* Public domain. */
+
+#ifndef _LINUX_RATELIMIT_H
+#define _LINUX_RATELIMIT_H
+
+#define DEFINE_RATELIMIT_STATE(name, interval, burst) \
+ int name __used = 1;
+
+#define __ratelimit(x) (1)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/rbtree.h b/sys/dev/pci/drm/include/linux/rbtree.h
new file mode 100644
index 00000000000..9bcb814baaf
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/rbtree.h
@@ -0,0 +1,165 @@
+/*-
+ * Copyright (c) 2010 Isilon Systems, Inc.
+ * Copyright (c) 2010 iX Systems, Inc.
+ * Copyright (c) 2010 Panasas, Inc.
+ * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _LINUX_RBTREE_H_
+#define _LINUX_RBTREE_H_
+
+/* for printf */
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#include <sys/tree.h>
+
+struct rb_node {
+ RB_ENTRY(rb_node) __entry;
+};
+#define rb_left __entry.rbe_left
+#define rb_right __entry.rbe_right
+
+/*
+ * We provide a false structure that has the same bit pattern as tree.h
+ * presents so it matches the member names expected by linux.
+ */
+struct rb_root {
+ struct rb_node *rb_node;
+};
+
+struct rb_root_cached {
+ struct rb_node *rb_node;
+};
+
+/*
+ * In linux all of the comparisons are done by the caller.
+ */
+int panic_cmp(struct rb_node *one, struct rb_node *two);
+
+RB_HEAD(linux_root, rb_node);
+RB_PROTOTYPE(linux_root, rb_node, __entry, panic_cmp);
+
+#define rb_parent(r) RB_PARENT(r, __entry)
+#define rb_color(r) RB_COLOR(r, __entry)
+#define rb_is_red(r) (rb_color(r) == RB_RED)
+#define rb_is_black(r) (rb_color(r) == RB_BLACK)
+#define rb_set_parent(r, p) rb_parent((r)) = (p)
+#define rb_set_color(r, c) rb_color((r)) = (c)
+#define rb_entry(ptr, type, member) container_of(ptr, type, member)
+#define rb_entry_safe(ptr, type, member) \
+ (ptr ? rb_entry(ptr, type, member) : NULL)
+
+#define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL)
+#define RB_EMPTY_NODE(node) (rb_parent(node) == node)
+#define RB_CLEAR_NODE(node) (rb_set_parent(node, node))
+
+#define rb_insert_color(node, root) \
+ linux_root_RB_INSERT_COLOR((struct linux_root *)(root), (node))
+#define rb_insert_color_cached(node, root, leftmost) \
+ linux_root_RB_INSERT_COLOR((struct linux_root *)(root), (node))
+#define rb_erase(node, root) \
+ linux_root_RB_REMOVE((struct linux_root *)(root), (node))
+#define rb_erase_cached(node, root) \
+ linux_root_RB_REMOVE((struct linux_root *)(root), (node))
+#define rb_next(node) RB_NEXT(linux_root, NULL, (node))
+#define rb_prev(node) RB_PREV(linux_root, NULL, (node))
+#define rb_first(root) RB_MIN(linux_root, (struct linux_root *)(root))
+#define rb_first_cached(root) RB_MIN(linux_root, (struct linux_root *)(root))
+#define rb_last(root) RB_MAX(linux_root, (struct linux_root *)(root))
+#define rbtree_postorder_for_each_entry_safe(x, y, head, member) \
+ for ((x) = rb_entry_safe(RB_MIN(linux_root, (struct linux_root *)head), \
+ __typeof(*x), member); \
+ ((x) != NULL) && ({(y) = \
+ rb_entry_safe(linux_root_RB_NEXT(&x->member), typeof(*x), member); 1; }); \
+ (x) = (y))
+
+static inline void
+rb_link_node(struct rb_node *node, struct rb_node *parent,
+ struct rb_node **rb_link)
+{
+ rb_set_parent(node, parent);
+ rb_set_color(node, RB_RED);
+ node->__entry.rbe_left = node->__entry.rbe_right = NULL;
+ *rb_link = node;
+}
+
+static inline void
+rb_replace_node(struct rb_node *victim, struct rb_node *new,
+ struct rb_root *root)
+{
+ struct rb_node *p;
+
+ p = rb_parent(victim);
+ if (p) {
+ if (p->rb_left == victim)
+ p->rb_left = new;
+ else
+ p->rb_right = new;
+ } else
+ root->rb_node = new;
+ if (victim->rb_left)
+ rb_set_parent(victim->rb_left, new);
+ if (victim->rb_right)
+ rb_set_parent(victim->rb_right, new);
+ *new = *victim;
+}
+
+#undef RB_ROOT
+#define RB_ROOT (struct rb_root) { NULL }
+#define RB_ROOT_CACHED (struct rb_root_cached) { NULL }
+
+struct interval_tree_node {
+ struct rb_node rb;
+ unsigned long start;
+ unsigned long last;
+};
+
+static inline struct interval_tree_node *
+interval_tree_iter_first(struct rb_root *root,
+ unsigned long start, unsigned long last)
+{
+#ifdef DRMDEBUG
+ printf("%s: stub start: 0x%lx last: 0x%lx\n", __func__, start, last);
+#endif
+ return NULL;
+}
+
+static inline void
+interval_tree_insert(struct interval_tree_node *node, struct rb_root *root)
+{
+#ifdef DRMDEBUG
+ printf("%s: stub start: 0x%lx last: 0x%lx\n", __func__, node->start, node->last);
+#endif
+}
+
+static inline void
+interval_tree_remove(struct interval_tree_node *node, struct rb_root *root)
+{
+#ifdef DRMDEBUG
+ printf("%s: stub start: 0x%lx last: 0x%lx\n", __func__, node->start, node->last);
+#endif
+}
+
+#endif /* _LINUX_RBTREE_H_ */
diff --git a/sys/dev/pci/drm/include/linux/rcupdate.h b/sys/dev/pci/drm/include/linux/rcupdate.h
new file mode 100644
index 00000000000..3bb821befcf
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/rcupdate.h
@@ -0,0 +1,36 @@
+/* Public domain. */
+
+#ifndef LINUX_RCUPDATE_H
+#define LINUX_RCUPDATE_H
+
+#include <linux/cpumask.h>
+
+struct rcu_head {
+};
+
+#define __rcu
+#define rcu_dereference(p) (p)
+#define rcu_dereference_raw(p) (p)
+#define rcu_dereference_protected(p, c) (p)
+#define rcu_access_pointer(p) (p)
+#define RCU_INIT_POINTER(p, v) do { (p) = (v); } while(0)
+#define rcu_assign_pointer(p, v) do { (p) = (v); } while(0)
+#define rcu_read_lock()
+#define rcu_read_unlock()
+#define rcu_pointer_handoff(p) (p)
+
+#define kfree_rcu(objp, name) do { free((void *)objp, M_DRM, 0); } while(0)
+
+#define rcu_barrier() __asm __volatile("" : : : "memory")
+
+typedef void (*rcu_callback_t)(struct rcu_head *head);
+
+static inline void
+call_rcu(struct rcu_head *head, void (*fn)(struct rcu_head *))
+{
+ fn(head);
+}
+
+#define synchronize_rcu()
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/reboot.h b/sys/dev/pci/drm/include/linux/reboot.h
new file mode 100644
index 00000000000..49aa47a8040
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/reboot.h
@@ -0,0 +1,11 @@
+/* Public domain. */
+
+#ifndef _LINUX_REBOOT_H
+#define _LINUX_REBOOT_H
+
+#define register_reboot_notifier(x)
+#define unregister_reboot_notifier(x)
+
+#define SYS_RESTART 0
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/refcount.h b/sys/dev/pci/drm/include/linux/refcount.h
new file mode 100644
index 00000000000..402a985406e
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/refcount.h
@@ -0,0 +1,15 @@
+/* Public domain. */
+
+#ifndef _LINUX_REFCOUNT_H
+#define _LINUX_REFCOUNT_H
+
+#include <sys/types.h>
+#include <linux/atomic.h>
+
+static inline bool
+refcount_dec_and_test(uint32_t *p)
+{
+ return atomic_dec_and_test(p);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/relay.h b/sys/dev/pci/drm/include/linux/relay.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/relay.h
diff --git a/sys/dev/pci/drm/include/linux/reservation.h b/sys/dev/pci/drm/include/linux/reservation.h
new file mode 100644
index 00000000000..02166e815af
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/reservation.h
@@ -0,0 +1,290 @@
+/*
+ * Header file for reservations for dma-buf and ttm
+ *
+ * Copyright(C) 2011 Linaro Limited. All rights reserved.
+ * Copyright (C) 2012-2013 Canonical Ltd
+ * Copyright (C) 2012 Texas Instruments
+ *
+ * Authors:
+ * Rob Clark <robdclark@gmail.com>
+ * Maarten Lankhorst <maarten.lankhorst@canonical.com>
+ * Thomas Hellstrom <thellstrom-at-vmware-dot-com>
+ *
+ * Based on bo.c which bears the following copyright notice,
+ * but is dual licensed:
+ *
+ * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef _LINUX_RESERVATION_H
+#define _LINUX_RESERVATION_H
+
+#include <linux/ww_mutex.h>
+#include <linux/dma-fence.h>
+#include <linux/slab.h>
+#include <linux/seqlock.h>
+#include <linux/rcupdate.h>
+
+extern struct ww_class reservation_ww_class;
+extern struct lock_class_key reservation_seqcount_class;
+extern const char reservation_seqcount_string[];
+
+/**
+ * struct reservation_object_list - a list of shared fences
+ * @rcu: for internal use
+ * @shared_count: table of shared fences
+ * @shared_max: for growing shared fence table
+ * @shared: shared fence table
+ */
+struct reservation_object_list {
+ struct rcu_head rcu;
+ u32 shared_count, shared_max;
+ struct dma_fence __rcu *shared[];
+};
+
+/**
+ * struct reservation_object - a reservation object manages fences for a buffer
+ * @lock: update side lock
+ * @seq: sequence count for managing RCU read-side synchronization
+ * @fence_excl: the exclusive fence, if there is one currently
+ * @fence: list of current shared fences
+ * @staged: staged copy of shared fences for RCU updates
+ */
+struct reservation_object {
+ struct ww_mutex lock;
+ seqcount_t seq;
+
+ struct dma_fence __rcu *fence_excl;
+ struct reservation_object_list __rcu *fence;
+ struct reservation_object_list *staged;
+};
+
+#define reservation_object_held(obj) lockdep_is_held(&(obj)->lock.base)
+#define reservation_object_assert_held(obj) \
+ lockdep_assert_held(&(obj)->lock.base)
+
+/**
+ * reservation_object_init - initialize a reservation object
+ * @obj: the reservation object
+ */
+static inline void
+reservation_object_init(struct reservation_object *obj)
+{
+ ww_mutex_init(&obj->lock, &reservation_ww_class);
+
+ __seqcount_init(&obj->seq, reservation_seqcount_string, &reservation_seqcount_class);
+ RCU_INIT_POINTER(obj->fence, NULL);
+ RCU_INIT_POINTER(obj->fence_excl, NULL);
+ obj->staged = NULL;
+}
+
+/**
+ * reservation_object_fini - destroys a reservation object
+ * @obj: the reservation object
+ */
+static inline void
+reservation_object_fini(struct reservation_object *obj)
+{
+ int i;
+ struct reservation_object_list *fobj;
+ struct dma_fence *excl;
+
+ /*
+ * This object should be dead and all references must have
+ * been released to it, so no need to be protected with rcu.
+ */
+ excl = rcu_dereference_protected(obj->fence_excl, 1);
+ if (excl)
+ dma_fence_put(excl);
+
+ fobj = rcu_dereference_protected(obj->fence, 1);
+ if (fobj) {
+ for (i = 0; i < fobj->shared_count; ++i)
+ dma_fence_put(rcu_dereference_protected(fobj->shared[i], 1));
+
+ kfree(fobj);
+ }
+ kfree(obj->staged);
+
+ ww_mutex_destroy(&obj->lock);
+}
+
+/**
+ * reservation_object_get_list - get the reservation object's
+ * shared fence list, with update-side lock held
+ * @obj: the reservation object
+ *
+ * Returns the shared fence list. Does NOT take references to
+ * the fence. The obj->lock must be held.
+ */
+static inline struct reservation_object_list *
+reservation_object_get_list(struct reservation_object *obj)
+{
+ return rcu_dereference_protected(obj->fence,
+ reservation_object_held(obj));
+}
+
+/**
+ * reservation_object_lock - lock the reservation object
+ * @obj: the reservation object
+ * @ctx: the locking context
+ *
+ * Locks the reservation object for exclusive access and modification. Note,
+ * that the lock is only against other writers, readers will run concurrently
+ * with a writer under RCU. The seqlock is used to notify readers if they
+ * overlap with a writer.
+ *
+ * As the reservation object may be locked by multiple parties in an
+ * undefined order, a #ww_acquire_ctx is passed to unwind if a cycle
+ * is detected. See ww_mutex_lock() and ww_acquire_init(). A reservation
+ * object may be locked by itself by passing NULL as @ctx.
+ */
+static inline int
+reservation_object_lock(struct reservation_object *obj,
+ struct ww_acquire_ctx *ctx)
+{
+ return ww_mutex_lock(&obj->lock, ctx);
+}
+
+/**
+ * reservation_object_lock_interruptible - lock the reservation object
+ * @obj: the reservation object
+ * @ctx: the locking context
+ *
+ * Locks the reservation object interruptible for exclusive access and
+ * modification. Note, that the lock is only against other writers, readers
+ * will run concurrently with a writer under RCU. The seqlock is used to
+ * notify readers if they overlap with a writer.
+ *
+ * As the reservation object may be locked by multiple parties in an
+ * undefined order, a #ww_acquire_ctx is passed to unwind if a cycle
+ * is detected. See ww_mutex_lock() and ww_acquire_init(). A reservation
+ * object may be locked by itself by passing NULL as @ctx.
+ */
+static inline int
+reservation_object_lock_interruptible(struct reservation_object *obj,
+ struct ww_acquire_ctx *ctx)
+{
+ return ww_mutex_lock_interruptible(&obj->lock, ctx);
+}
+
+
+/**
+ * reservation_object_trylock - trylock the reservation object
+ * @obj: the reservation object
+ *
+ * Tries to lock the reservation object for exclusive access and modification.
+ * Note, that the lock is only against other writers, readers will run
+ * concurrently with a writer under RCU. The seqlock is used to notify readers
+ * if they overlap with a writer.
+ *
+ * Also note that since no context is provided, no deadlock protection is
+ * possible.
+ *
+ * Returns true if the lock was acquired, false otherwise.
+ */
+static inline bool __must_check
+reservation_object_trylock(struct reservation_object *obj)
+{
+ return ww_mutex_trylock(&obj->lock);
+}
+
+/**
+ * reservation_object_unlock - unlock the reservation object
+ * @obj: the reservation object
+ *
+ * Unlocks the reservation object following exclusive access.
+ */
+static inline void
+reservation_object_unlock(struct reservation_object *obj)
+{
+ ww_mutex_unlock(&obj->lock);
+}
+
+/**
+ * reservation_object_get_excl - get the reservation object's
+ * exclusive fence, with update-side lock held
+ * @obj: the reservation object
+ *
+ * Returns the exclusive fence (if any). Does NOT take a
+ * reference. The obj->lock must be held.
+ *
+ * RETURNS
+ * The exclusive fence or NULL
+ */
+static inline struct dma_fence *
+reservation_object_get_excl(struct reservation_object *obj)
+{
+ return rcu_dereference_protected(obj->fence_excl,
+ reservation_object_held(obj));
+}
+
+/**
+ * reservation_object_get_excl_rcu - get the reservation object's
+ * exclusive fence, without lock held.
+ * @obj: the reservation object
+ *
+ * If there is an exclusive fence, this atomically increments it's
+ * reference count and returns it.
+ *
+ * RETURNS
+ * The exclusive fence or NULL if none
+ */
+static inline struct dma_fence *
+reservation_object_get_excl_rcu(struct reservation_object *obj)
+{
+ struct dma_fence *fence;
+
+ if (!rcu_access_pointer(obj->fence_excl))
+ return NULL;
+
+ rcu_read_lock();
+ fence = dma_fence_get_rcu_safe(&obj->fence_excl);
+ rcu_read_unlock();
+
+ return fence;
+}
+
+int reservation_object_reserve_shared(struct reservation_object *obj);
+void reservation_object_add_shared_fence(struct reservation_object *obj,
+ struct dma_fence *fence);
+
+void reservation_object_add_excl_fence(struct reservation_object *obj,
+ struct dma_fence *fence);
+
+int reservation_object_get_fences_rcu(struct reservation_object *obj,
+ struct dma_fence **pfence_excl,
+ unsigned *pshared_count,
+ struct dma_fence ***pshared);
+
+int reservation_object_copy_fences(struct reservation_object *dst,
+ struct reservation_object *src);
+
+long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
+ bool wait_all, bool intr,
+ unsigned long timeout);
+
+bool reservation_object_test_signaled_rcu(struct reservation_object *obj,
+ bool test_all);
+
+#endif /* _LINUX_RESERVATION_H */
diff --git a/sys/dev/pci/drm/include/linux/rwlock_types.h b/sys/dev/pci/drm/include/linux/rwlock_types.h
new file mode 100644
index 00000000000..36b1f7feab1
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/rwlock_types.h
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#ifndef _LINUX_RWLOCK_TYPES_H
+#define _LINUX_RWLOCK_TYPES_H
+
+#include <sys/rwlock.h>
+
+typedef struct rwlock rwlock_t;
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/scatterlist.h b/sys/dev/pci/drm/include/linux/scatterlist.h
new file mode 100644
index 00000000000..4ec58c80de0
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/scatterlist.h
@@ -0,0 +1,127 @@
+/* $OpenBSD: scatterlist.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2013, 2014, 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_SCATTERLIST_H
+#define _LINUX_SCATTERLIST_H
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <uvm/uvm_extern.h>
+
+struct scatterlist {
+ dma_addr_t dma_address;
+ unsigned int offset;
+ unsigned int length;
+ bool end;
+};
+
+struct sg_table {
+ struct scatterlist *sgl;
+ unsigned int nents;
+ unsigned int orig_nents;
+};
+
+struct sg_page_iter {
+ struct scatterlist *sg;
+ unsigned int sg_pgoffset;
+ unsigned int __nents;
+};
+
+#define sg_is_chain(sg) false
+#define sg_is_last(sg) ((sg)->end)
+#define sg_chain_ptr(sg) NULL
+
+static inline struct scatterlist *
+sg_next(struct scatterlist *sgl)
+{
+ return sg_is_last(sgl) ? NULL : ++sgl;
+}
+
+int sg_alloc_table(struct sg_table *, unsigned int, gfp_t);
+void sg_free_table(struct sg_table *);
+
+static inline void
+sg_mark_end(struct scatterlist *sgl)
+{
+ sgl->end = true;
+}
+
+static inline void
+__sg_page_iter_start(struct sg_page_iter *iter, struct scatterlist *sgl,
+ unsigned int nents, unsigned long pgoffset)
+{
+ iter->sg = sgl;
+ iter->sg_pgoffset = pgoffset - 1;
+ iter->__nents = nents;
+}
+
+static inline bool
+__sg_page_iter_next(struct sg_page_iter *iter)
+{
+ iter->sg_pgoffset++;
+ while (iter->__nents > 0 &&
+ iter->sg_pgoffset >= (iter->sg->length / PAGE_SIZE)) {
+ iter->sg_pgoffset -= (iter->sg->length / PAGE_SIZE);
+ iter->sg++;
+ iter->__nents--;
+ }
+
+ return (iter->__nents > 0);
+}
+
+static inline paddr_t
+sg_page_iter_dma_address(struct sg_page_iter *iter)
+{
+ return iter->sg->dma_address + (iter->sg_pgoffset << PAGE_SHIFT);
+}
+
+static inline struct vm_page *
+sg_page_iter_page(struct sg_page_iter *iter)
+{
+ return PHYS_TO_VM_PAGE(sg_page_iter_dma_address(iter));
+}
+
+static inline struct vm_page *
+sg_page(struct scatterlist *sgl)
+{
+ return PHYS_TO_VM_PAGE(sgl->dma_address);
+}
+
+static inline void
+sg_set_page(struct scatterlist *sgl, struct vm_page *page,
+ unsigned int length, unsigned int offset)
+{
+ sgl->dma_address = VM_PAGE_TO_PHYS(page);
+ sgl->offset = offset;
+ sgl->length = length;
+ sgl->end = false;
+}
+
+#define sg_dma_address(sg) ((sg)->dma_address)
+#define sg_dma_len(sg) ((sg)->length)
+
+#define for_each_sg(sgl, sg, nents, i) \
+ for (i = 0, sg = (sgl); i < (nents); i++, sg = sg_next(sg))
+
+#define for_each_sg_page(sgl, iter, nents, pgoffset) \
+ __sg_page_iter_start((iter), (sgl), (nents), (pgoffset)); \
+ while (__sg_page_iter_next(iter))
+
+size_t sg_copy_from_buffer(struct scatterlist *, unsigned int,
+ const void *, size_t);
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/sched.h b/sys/dev/pci/drm/include/linux/sched.h
new file mode 100644
index 00000000000..00fa85d4294
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/sched.h
@@ -0,0 +1,52 @@
+/* $OpenBSD: sched.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2013, 2014, 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_SCHED_H
+#define _LINUX_SCHED_H
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/stdint.h>
+#include <sys/mutex.h>
+#include <sys/proc.h>
+#include <linux/wait.h>
+#include <linux/hrtimer.h>
+
+#define TASK_NORMAL 1
+#define TASK_UNINTERRUPTIBLE 0
+#define TASK_INTERRUPTIBLE PCATCH
+#define TASK_RUNNING -1
+
+#define MAX_SCHEDULE_TIMEOUT (INT32_MAX)
+
+#define TASK_COMM_LEN (MAXCOMLEN + 1)
+
+#define cond_resched() sched_pause(yield)
+#define drm_need_resched() \
+ (curcpu()->ci_schedstate.spc_schedflags & SPCF_SHOULDYIELD)
+
+void set_current_state(int);
+void __set_current_state(int);
+void schedule(void);
+long schedule_timeout(long);
+
+#define io_schedule_timeout(x) schedule_timeout(x)
+
+int wake_up_process(struct proc *p);
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/sched/clock.h b/sys/dev/pci/drm/include/linux/sched/clock.h
new file mode 100644
index 00000000000..3604ee1ac17
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/sched/clock.h
@@ -0,0 +1,19 @@
+/* Public domain. */
+
+#ifndef _LINUX_SCHED_CLOCK_H
+#define _LINUX_SCHED_CLOCK_H
+
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include <linux/smp.h>
+
+static inline uint64_t
+local_clock(void)
+{
+ struct timespec ts;
+ nanouptime(&ts);
+ return (ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/sched/mm.h b/sys/dev/pci/drm/include/linux/sched/mm.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/sched/mm.h
diff --git a/sys/dev/pci/drm/include/linux/sched/signal.h b/sys/dev/pci/drm/include/linux/sched/signal.h
new file mode 100644
index 00000000000..5b21079d6cf
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/sched/signal.h
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#ifndef _LINUX_SCHED_SIGNAL_H
+#define _LINUX_SCHED_SIGNAL_H
+
+#include <sys/systm.h>
+#include <sys/signalvar.h>
+
+#define signal_pending_state(x, y) CURSIG(curproc)
+#define signal_pending(y) CURSIG(curproc)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/seq_file.h b/sys/dev/pci/drm/include/linux/seq_file.h
new file mode 100644
index 00000000000..ced4cc09d49
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/seq_file.h
@@ -0,0 +1,17 @@
+/* Public domain. */
+
+#ifndef _LINUX_SEQ_FILE_H
+#define _LINUX_SEQ_FILE_H
+
+#include <linux/bug.h>
+#include <linux/string.h>
+
+struct seq_file;
+
+static inline void
+seq_printf(struct seq_file *m, const char *fmt, ...) {};
+
+static inline void
+seq_puts(struct seq_file *m, const char *s) {};
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/seqlock.h b/sys/dev/pci/drm/include/linux/seqlock.h
new file mode 100644
index 00000000000..edfb8648bf6
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/seqlock.h
@@ -0,0 +1,137 @@
+/* Public domain. */
+
+#ifndef _LINUX_SEQLOCK_H
+#define _LINUX_SEQLOCK_H
+
+#include <sys/types.h>
+#include <sys/mutex.h>
+#include <sys/atomic.h>
+#include <linux/lockdep.h>
+#include <linux/processor.h>
+#include <linux/preempt.h>
+#include <linux/compiler.h>
+
+typedef struct {
+ unsigned int sequence;
+} seqcount_t;
+
+static inline void
+__seqcount_init(seqcount_t *s, const char *name,
+ struct lock_class_key *key)
+{
+ s->sequence = 0;
+}
+
+static inline unsigned int
+__read_seqcount_begin(const seqcount_t *s)
+{
+ unsigned int r;
+ for (;;) {
+ r = s->sequence;
+ if ((r & 1) == 0)
+ break;
+ cpu_relax();
+ }
+ return r;
+}
+
+static inline unsigned int
+read_seqcount_begin(const seqcount_t *s)
+{
+ unsigned int r = __read_seqcount_begin(s);
+ membar_consumer();
+ return r;
+}
+
+static inline int
+__read_seqcount_retry(const seqcount_t *s, unsigned start)
+{
+ return (s->sequence != start);
+}
+
+static inline int
+read_seqcount_retry(const seqcount_t *s, unsigned start)
+{
+ membar_consumer();
+ return __read_seqcount_retry(s, start);
+}
+
+static inline void
+write_seqcount_begin(seqcount_t *s)
+{
+ s->sequence++;
+ membar_producer();
+}
+
+static inline void
+write_seqcount_end(seqcount_t *s)
+{
+ membar_producer();
+ s->sequence++;
+}
+
+static inline unsigned int
+raw_read_seqcount(const seqcount_t *s)
+{
+ unsigned int r = s->sequence;
+ membar_consumer();
+ return r;
+}
+
+typedef struct {
+ unsigned int seq;
+ struct mutex lock;
+} seqlock_t;
+
+static inline void
+seqlock_init(seqlock_t *sl)
+{
+ sl->seq = 0;
+ mtx_init(&sl->lock, IPL_NONE);
+}
+
+static inline void
+write_seqlock(seqlock_t *sl)
+{
+ mtx_enter(&sl->lock);
+ sl->seq++;
+ membar_producer();
+}
+
+static inline void
+write_seqlock_irqsave(seqlock_t *sl, __unused long flags)
+{
+ mtx_enter(&sl->lock);
+ sl->seq++;
+ membar_producer();
+}
+
+static inline void
+write_sequnlock(seqlock_t *sl)
+{
+ membar_producer();
+ sl->seq++;
+ mtx_leave(&sl->lock);
+}
+
+static inline void
+write_sequnlock_irqrestore(seqlock_t *sl, __unused long flags)
+{
+ membar_producer();
+ sl->seq++;
+ mtx_leave(&sl->lock);
+}
+
+static inline unsigned int
+read_seqbegin(seqlock_t *sl)
+{
+ return READ_ONCE(sl->seq);
+}
+
+static inline unsigned int
+read_seqretry(seqlock_t *sl, unsigned int pos)
+{
+ return sl->seq != pos;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/shmem_fs.h b/sys/dev/pci/drm/include/linux/shmem_fs.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/shmem_fs.h
diff --git a/sys/dev/pci/drm/include/linux/sizes.h b/sys/dev/pci/drm/include/linux/sizes.h
new file mode 100644
index 00000000000..01a1dc4a269
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/sizes.h
@@ -0,0 +1,13 @@
+/* Public domain. */
+
+#ifndef _LINUX_SIZES_H
+#define _LINUX_SIZES_H
+
+#define SZ_4K (1024 * 4)
+#define SZ_8K (1024 * 8)
+#define SZ_32K (1024 * 32)
+#define SZ_128K (1024 * 128)
+#define SZ_1M (1024 * 1024)
+#define SZ_16M (16 * 1024 * 1024)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/slab.h b/sys/dev/pci/drm/include/linux/slab.h
new file mode 100644
index 00000000000..b0b65b71a93
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/slab.h
@@ -0,0 +1,47 @@
+/* Public domain. */
+
+#ifndef _LINUX_SLAB_H
+#define _LINUX_SLAB_H
+
+#include <sys/types.h>
+#include <sys/malloc.h>
+
+#include <linux/types.h>
+#include <linux/workqueue.h>
+#include <linux/gfp.h>
+
+static inline void *
+kmalloc(size_t size, int flags)
+{
+ return malloc(size, M_DRM, flags);
+}
+
+static inline void *
+kmalloc_array(size_t n, size_t size, int flags)
+{
+ if (n == 0 || SIZE_MAX / n < size)
+ return NULL;
+ return malloc(n * size, M_DRM, flags);
+}
+
+static inline void *
+kcalloc(size_t n, size_t size, int flags)
+{
+ if (n == 0 || SIZE_MAX / n < size)
+ return NULL;
+ return malloc(n * size, M_DRM, flags | M_ZERO);
+}
+
+static inline void *
+kzalloc(size_t size, int flags)
+{
+ return malloc(size, M_DRM, flags | M_ZERO);
+}
+
+static inline void
+kfree(const void *objp)
+{
+ free((void *)objp, M_DRM, 0);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/smp.h b/sys/dev/pci/drm/include/linux/smp.h
new file mode 100644
index 00000000000..354bf92be3c
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/smp.h
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#ifndef _LINUX_SMP_H
+#define _LINUX_SMP_H
+
+/* sparc64 cpu.h needs time.h and siginfo.h (indirect via param.h) */
+#include <sys/param.h>
+#include <machine/cpu.h>
+
+#define smp_processor_id() (curcpu()->ci_cpuid)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/sort.h b/sys/dev/pci/drm/include/linux/sort.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/sort.h
diff --git a/sys/dev/pci/drm/include/linux/spinlock.h b/sys/dev/pci/drm/include/linux/spinlock.h
new file mode 100644
index 00000000000..acf04cd96b9
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/spinlock.h
@@ -0,0 +1,55 @@
+/* Public domain. */
+
+#ifndef _LINUX_SPINLOCK_H
+#define _LINUX_SPINLOCK_H
+
+#include <linux/kernel.h>
+#include <linux/spinlock_types.h>
+#include <linux/preempt.h>
+#include <linux/bottom_half.h>
+
+static inline void
+_spin_lock_irqsave(struct mutex *mtxp, __unused unsigned long flags
+ LOCK_FL_VARS)
+{
+ _mtx_enter(mtxp LOCK_FL_ARGS);
+}
+static inline void
+_spin_lock_irqsave_nested(struct mutex *mtxp, __unused unsigned long flags,
+ __unused int subclass LOCK_FL_VARS)
+{
+ _mtx_enter(mtxp LOCK_FL_ARGS);
+}
+static inline void
+_spin_unlock_irqrestore(struct mutex *mtxp, __unused unsigned long flags
+ LOCK_FL_VARS)
+{
+ _mtx_leave(mtxp LOCK_FL_ARGS);
+}
+#define spin_lock_irqsave(m, fl) \
+ _spin_lock_irqsave(m, fl LOCK_FILE_LINE)
+#define spin_lock_irqsave_nested(m, fl, subc) \
+ _spin_lock_irqsave_nested(m, fl, subc LOCK_FILE_LINE)
+#define spin_unlock_irqrestore(m, fl) \
+ _spin_unlock_irqrestore(m, fl LOCK_FILE_LINE)
+
+#define spin_lock(mtxp) mtx_enter(mtxp)
+#define spin_lock_nested(mtxp, l) mtx_enter(mtxp)
+#define spin_unlock(mtxp) mtx_leave(mtxp)
+#define spin_lock_irq(mtxp) mtx_enter(mtxp)
+#define spin_unlock_irq(mtxp) mtx_leave(mtxp)
+#define assert_spin_locked(mtxp) MUTEX_ASSERT_LOCKED(mtxp)
+#define spin_trylock_irq(mtxp) mtx_enter_try(mtxp)
+
+#define down_read(rwl) rw_enter_read(rwl)
+#define down_read_trylock(rwl) (rw_enter(rwl, RW_READ | RW_NOSLEEP) == 0)
+#define up_read(rwl) rw_exit_read(rwl)
+#define down_write(rwl) rw_enter_write(rwl)
+#define up_write(rwl) rw_exit_write(rwl)
+#define downgrade_write(rwl) rw_enter(rwl, RW_DOWNGRADE)
+#define read_lock(rwl) rw_enter_read(rwl)
+#define read_unlock(rwl) rw_exit_read(rwl)
+#define write_lock(rwl) rw_enter_write(rwl)
+#define write_unlock(rwl) rw_exit_write(rwl)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/spinlock_types.h b/sys/dev/pci/drm/include/linux/spinlock_types.h
new file mode 100644
index 00000000000..37b42507759
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/spinlock_types.h
@@ -0,0 +1,13 @@
+/* Public domain. */
+
+#ifndef _LINUX_SPINLOCK_TYPES_H
+#define _LINUX_SPINLOCK_TYPES_H
+
+#include <sys/types.h>
+#include <sys/mutex.h>
+#include <linux/rwlock_types.h>
+
+typedef struct mutex spinlock_t;
+#define DEFINE_SPINLOCK(x) struct mutex x
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/stop_machine.h b/sys/dev/pci/drm/include/linux/stop_machine.h
new file mode 100644
index 00000000000..a7e34d02144
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/stop_machine.h
@@ -0,0 +1,20 @@
+/* Public domain. */
+
+#ifndef _LINUX_STOP_MACHINE_H
+#define _LINUX_STOP_MACHINE_H
+
+#include <machine/intr.h>
+
+typedef int (*cpu_stop_fn_t)(void *arg);
+
+static inline int
+stop_machine(cpu_stop_fn_t fn, void *arg, void *cpus)
+{
+ int r;
+ intr_disable();
+ r = (*fn)(arg);
+ intr_enable();
+ return r;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/string.h b/sys/dev/pci/drm/include/linux/string.h
new file mode 100644
index 00000000000..b77067b1bcc
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/string.h
@@ -0,0 +1,79 @@
+/* Public domain. */
+
+#ifndef _LINUX_STRING_H
+#define _LINUX_STRING_H
+
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/stdint.h>
+#include <sys/errno.h>
+
+void *memchr_inv(const void *, int, size_t);
+
+static inline void *
+memset32(uint32_t *b, uint32_t c, size_t len)
+{
+ uint32_t *dst = b;
+ while (len--)
+ *dst++ = c;
+ return b;
+}
+
+static inline void *
+memset64(uint64_t *b, uint64_t c, size_t len)
+{
+ uint64_t *dst = b;
+ while (len--)
+ *dst++ = c;
+ return b;
+}
+
+static inline void *
+memset_p(void **p, void *v, size_t n)
+{
+#ifdef __LP64__
+ return memset64((uint64_t *)p, (uintptr_t)v, n);
+#else
+ return memset32((uint32_t *)p, (uintptr_t)v, n);
+#endif
+}
+
+static inline void *
+kmemdup(const void *src, size_t len, int flags)
+{
+ void *p = malloc(len, M_DRM, flags);
+ if (p)
+ memcpy(p, src, len);
+ return (p);
+}
+
+static inline void *
+kstrdup(const char *str, int flags)
+{
+ size_t len;
+ char *p;
+
+ len = strlen(str) + 1;
+ p = malloc(len, M_DRM, flags);
+ if (p)
+ memcpy(p, str, len);
+ return (p);
+}
+
+static inline int
+match_string(const char * const *array, size_t n, const char *str)
+{
+ int i;
+
+ for (i = 0; i < n; i++) {
+ if (array[i] == NULL)
+ break;
+ if (!strcmp(array[i], str))
+ return i;
+ }
+
+ return -EINVAL;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/stringify.h b/sys/dev/pci/drm/include/linux/stringify.h
new file mode 100644
index 00000000000..a541ba6594c
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/stringify.h
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#ifndef _LINUX_STRINGIFY_H
+#define _LINUX_STRINGIFY_H
+
+#define ___stringify(x...) #x
+#define __stringify(x...) ___stringify(x)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/swap.h b/sys/dev/pci/drm/include/linux/swap.h
new file mode 100644
index 00000000000..98827081640
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/swap.h
@@ -0,0 +1,14 @@
+/* Public domain. */
+
+#ifndef _LINUX_SWAP_H
+#define _LINUX_SWAP_H
+
+#include <uvm/uvm_extern.h>
+
+static inline long
+get_nr_swap_pages(void)
+{
+ return uvmexp.swpages - uvmexp.swpginuse;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/swiotlb.h b/sys/dev/pci/drm/include/linux/swiotlb.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/swiotlb.h
diff --git a/sys/dev/pci/drm/include/linux/sync_file.h b/sys/dev/pci/drm/include/linux/sync_file.h
new file mode 100644
index 00000000000..e8daa6d7877
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/sync_file.h
@@ -0,0 +1,26 @@
+/* Public domain. */
+
+#ifndef _LINUX_SYNC_FILE_H
+#define _LINUX_SYNC_FILE_H
+
+#include <linux/dma-fence.h>
+#include <linux/ktime.h>
+
+struct sync_file {
+};
+
+static inline struct dma_fence *
+sync_file_get_fence(int fd)
+{
+ printf("%s: stub\n", __func__);
+ return NULL;
+}
+
+static inline struct sync_file *
+sync_file_create(struct dma_fence *fence)
+{
+ printf("%s: stub\n", __func__);
+ return NULL;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/sysfs.h b/sys/dev/pci/drm/include/linux/sysfs.h
new file mode 100644
index 00000000000..c9be9a48fba
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/sysfs.h
@@ -0,0 +1,11 @@
+/* Public domain. */
+
+#ifndef _LINUX_SYSFS_H
+#define _LINUX_SYSFS_H
+
+#define sysfs_create_link(x, y, z) 0
+#define sysfs_remove_link(x, y)
+#define sysfs_create_group(x, y) 0
+#define sysfs_remove_group(x, y)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/sysrq.h b/sys/dev/pci/drm/include/linux/sysrq.h
new file mode 100644
index 00000000000..1805e30387a
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/sysrq.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUX_SYSRQ_H
+#define _LINUX_SYSRQ_H
+
+#define register_sysrq_key(x, y)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/time.h b/sys/dev/pci/drm/include/linux/time.h
new file mode 100644
index 00000000000..c8a97b94b1a
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/time.h
@@ -0,0 +1,75 @@
+/* $OpenBSD: time.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2013, 2014, 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_TIME_H
+#define _LINUX_TIME_H
+
+#include <sys/time.h>
+#include <linux/math64.h>
+
+#define NSEC_PER_USEC 1000L
+#define NSEC_PER_MSEC 1000000L
+#define NSEC_PER_SEC 1000000000L
+
+extern struct timespec ns_to_timespec(const int64_t);
+extern int64_t timeval_to_ms(const struct timeval *);
+extern int64_t timeval_to_ns(const struct timeval *);
+extern int64_t timeval_to_us(const struct timeval *);
+extern struct timeval ns_to_timeval(const int64_t);
+
+struct timespec64 {
+ time_t tv_sec;
+ long tv_nsec;
+};
+
+static inline struct timespec
+timespec_sub(struct timespec t1, struct timespec t2)
+{
+ struct timespec diff;
+
+ timespecsub(&t1, &t2, &diff);
+ return diff;
+}
+
+static inline void
+set_normalized_timespec(struct timespec *ts, time_t sec, int64_t nsec)
+{
+ while (nsec > NSEC_PER_SEC) {
+ nsec -= NSEC_PER_SEC;
+ sec++;
+ }
+
+ ts->tv_sec = sec;
+ ts->tv_nsec = nsec;
+}
+
+static inline int64_t
+timespec_to_ns(const struct timespec *ts)
+{
+ return ((ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec);
+}
+
+static inline int
+timespec_valid(const struct timespec *ts)
+{
+ if (ts->tv_sec < 0 || ts->tv_sec > 100000000 ||
+ ts->tv_nsec < 0 || ts->tv_nsec >= 1000000000)
+ return (0);
+ return (1);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/timekeeping.h b/sys/dev/pci/drm/include/linux/timekeeping.h
new file mode 100644
index 00000000000..fc27e921cd5
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/timekeeping.h
@@ -0,0 +1,21 @@
+/* Public domain. */
+
+#ifndef _LINUX_TIMEKEEPING_H
+#define _LINUX_TIMEKEEPING_H
+
+#define get_seconds() time_second
+#define getrawmonotonic(x) nanouptime(x)
+
+#define ktime_mono_to_real(x) (x)
+#define ktime_get_real() ktime_get()
+#define ktime_get_boottime() ktime_get()
+
+#define do_gettimeofday(tv) getmicrouptime(tv)
+
+static inline int64_t
+ktime_get_real_seconds(void)
+{
+ return ktime_get().tv_sec;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/timer.h b/sys/dev/pci/drm/include/linux/timer.h
new file mode 100644
index 00000000000..b1f11a2c916
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/timer.h
@@ -0,0 +1,45 @@
+/* $OpenBSD: timer.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2013, 2014, 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_TIMER_H
+#define _LINUX_TIMER_H
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/timeout.h>
+#include <sys/kernel.h>
+#include <linux/ktime.h>
+
+#define setup_timer(x, y, z) timeout_set((x), (void (*)(void *))(y), (void *)(z))
+#define mod_timer(x, y) timeout_add((x), (y - jiffies))
+#define mod_timer_pinned(x, y) timeout_add((x), (y - jiffies))
+#define del_timer_sync(x) timeout_del((x))
+#define timer_pending(x) timeout_pending((x))
+
+static inline unsigned long
+round_jiffies_up(unsigned long j)
+{
+ return roundup(j, hz);
+}
+
+static inline unsigned long
+round_jiffies_up_relative(unsigned long j)
+{
+ return roundup(j, hz);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/tracepoint.h b/sys/dev/pci/drm/include/linux/tracepoint.h
new file mode 100644
index 00000000000..a28216f65ac
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/tracepoint.h
@@ -0,0 +1,24 @@
+/* Public domain. */
+
+#ifndef _LINUX_TRACEPOINT_H
+#define _LINUX_TRACEPOINT_H
+
+#define TP_PROTO(x...) x
+
+#define DEFINE_EVENT(template, name, proto, args) \
+static inline void trace_##name(proto) {} \
+static inline bool trace_##name##_enabled(void) { return false; }
+
+#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
+static inline void trace_##name(proto) {}
+
+#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
+static inline void trace_##name(proto) {}
+
+#define TRACE_EVENT_CONDITION(name, proto, args, cond, tstruct, assign, print) \
+static inline void trace_##name(proto) {}
+
+#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
+static inline void trace_##name(proto) {}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/tty.h b/sys/dev/pci/drm/include/linux/tty.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/tty.h
diff --git a/sys/dev/pci/drm/include/linux/typecheck.h b/sys/dev/pci/drm/include/linux/typecheck.h
new file mode 100644
index 00000000000..f92cd3785d9
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/typecheck.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUX_TYPECHECK_H
+#define _LINUX_TYPECHECK_H
+
+#define typecheck(x, y) 1
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/types.h b/sys/dev/pci/drm/include/linux/types.h
new file mode 100644
index 00000000000..5ec2b85b594
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/types.h
@@ -0,0 +1,67 @@
+/* Public domain. */
+
+#ifndef _LINUX_TYPES_H
+#define _LINUX_TYPES_H
+
+#include <sys/types.h>
+#include <sys/stdint.h>
+/*
+ * sparc64 bus.h needs _null.h (indirect via param.h)
+ * sparc64 busop.h needs machine/ctlreg.h (indirect via param.h)
+ */
+#include <sys/param.h>
+#include <machine/bus.h>
+
+typedef int8_t __s8;
+typedef uint8_t __u8;
+typedef int16_t __s16;
+typedef uint16_t __u16;
+typedef int32_t __s32;
+typedef uint32_t __u32;
+typedef int64_t __s64;
+typedef uint64_t __u64;
+
+typedef int8_t s8;
+typedef uint8_t u8;
+typedef int16_t s16;
+typedef uint16_t u16;
+typedef int32_t s32;
+typedef uint32_t u32;
+typedef int64_t s64;
+typedef uint64_t u64;
+
+typedef uint16_t __le16;
+typedef uint16_t __be16;
+typedef uint32_t __le32;
+typedef uint32_t __be32;
+
+typedef bus_addr_t dma_addr_t;
+typedef bus_addr_t phys_addr_t;
+typedef bus_addr_t resource_size_t;
+
+typedef off_t loff_t;
+
+typedef __ptrdiff_t ptrdiff_t;
+
+typedef unsigned int gfp_t;
+
+typedef unsigned long pgoff_t;
+typedef int pgprot_t;
+
+typedef int atomic_t;
+
+struct list_head {
+ struct list_head *next, *prev;
+};
+
+struct hlist_node {
+ struct hlist_node *next, **prev;
+};
+
+struct hlist_head {
+ struct hlist_node *first;
+};
+
+#define DECLARE_BITMAP(x, y) unsigned long x[BITS_TO_LONGS(y)];
+
+#endif /* _LINUX_TYPES_H_ */
diff --git a/sys/dev/pci/drm/include/linux/uaccess.h b/sys/dev/pci/drm/include/linux/uaccess.h
new file mode 100644
index 00000000000..97027a21c8f
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/uaccess.h
@@ -0,0 +1,136 @@
+/* $OpenBSD: uaccess.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_UACCESS_H
+#define _LINUX_UACCESS_H
+
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <linux/sched.h>
+
+#define user_access_begin()
+#define user_access_end()
+
+static inline unsigned long
+__copy_to_user(void *to, const void *from, unsigned len)
+{
+ if (copyout(from, to, len))
+ return len;
+ return 0;
+}
+
+static inline unsigned long
+copy_to_user(void *to, const void *from, unsigned len)
+{
+ return __copy_to_user(to, from, len);
+}
+
+static inline unsigned long
+__copy_from_user(void *to, const void *from, unsigned len)
+{
+ if (copyin(from, to, len))
+ return len;
+ return 0;
+}
+
+static inline unsigned long
+copy_from_user(void *to, const void *from, unsigned len)
+{
+ return __copy_from_user(to, from, len);
+}
+
+#define get_user(x, ptr) -copyin(ptr, &(x), sizeof(x))
+#define put_user(x, ptr) ({ \
+ __typeof((x)) __tmp = (x); \
+ -copyout(&(__tmp), ptr, sizeof(__tmp)); \
+})
+#define __get_user(x, ptr) get_user((x), (ptr))
+#define __put_user(x, ptr) put_user((x), (ptr))
+
+#define unsafe_put_user(x, ptr, err) ({ \
+ __typeof((x)) __tmp = (x); \
+ if (copyout(&(__tmp), ptr, sizeof(__tmp)) != 0) \
+ goto err; \
+})
+
+#define VERIFY_READ 0x1
+#define VERIFY_WRITE 0x2
+static inline int
+access_ok(int type, const void *addr, unsigned long size)
+{
+ return true;
+}
+
+#if defined(__i386__) || defined(__amd64__)
+
+static inline void
+pagefault_disable(void)
+{
+ KASSERT(curcpu()->ci_inatomic == 0);
+ curcpu()->ci_inatomic = 1;
+}
+
+static inline void
+pagefault_enable(void)
+{
+ KASSERT(curcpu()->ci_inatomic == 1);
+ curcpu()->ci_inatomic = 0;
+}
+
+static inline int
+pagefault_disabled(void)
+{
+ return curcpu()->ci_inatomic;
+}
+
+static inline unsigned long
+__copy_to_user_inatomic(void *to, const void *from, unsigned len)
+{
+ struct cpu_info *ci = curcpu();
+ int inatomic = ci->ci_inatomic;
+ int error;
+
+ ci->ci_inatomic = 1;
+ error = copyout(from, to, len);
+ ci->ci_inatomic = inatomic;
+
+ return (error ? len : 0);
+}
+
+static inline unsigned long
+__copy_from_user_inatomic(void *to, const void *from, unsigned len)
+{
+ struct cpu_info *ci = curcpu();
+ int inatomic = ci->ci_inatomic;
+ int error;
+
+ ci->ci_inatomic = 1;
+ error = copyin(from, to, len);
+ ci->ci_inatomic = inatomic;
+
+ return (error ? len : 0);
+}
+
+static inline unsigned long
+__copy_from_user_inatomic_nocache(void *to, const void *from, unsigned len)
+{
+ return __copy_from_user_inatomic(to, from, len);
+}
+
+#endif /* defined(__i386__) || defined(__amd64__) */
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/uuid.h b/sys/dev/pci/drm/include/linux/uuid.h
new file mode 100644
index 00000000000..ebe23cfeec0
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/uuid.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUX_UUID_H
+#define _LINUX_UUID_H
+
+#define UUID_STRING_LEN 36
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/version.h b/sys/dev/pci/drm/include/linux/version.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/version.h
diff --git a/sys/dev/pci/drm/include/linux/vga_switcheroo.h b/sys/dev/pci/drm/include/linux/vga_switcheroo.h
new file mode 100644
index 00000000000..ccdb11c5a97
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/vga_switcheroo.h
@@ -0,0 +1,17 @@
+/* Public domain. */
+
+#ifndef _LINUX_VGA_SWITCHEROO_H
+#define _LINUX_VGA_SWITCHEROO_H
+
+#define vga_switcheroo_register_client(a, b, c) 0
+#define vga_switcheroo_unregister_client(a)
+#define vga_switcheroo_process_delayed_switch()
+#define vga_switcheroo_fini_domain_pm_ops(x)
+#define vga_switcheroo_lock_ddc(x)
+#define vga_switcheroo_unlock_ddc(x)
+#define vga_switcheroo_handler_flags() 0
+#define vga_switcheroo_client_fb_set(a, b)
+
+#define VGA_SWITCHEROO_CAN_SWITCH_DDC 1
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/vgaarb.h b/sys/dev/pci/drm/include/linux/vgaarb.h
new file mode 100644
index 00000000000..8a5721af5da
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/vgaarb.h
@@ -0,0 +1,21 @@
+/* Public domain. */
+
+#ifndef _LINUX_VGAARB_H
+#define _LINUX_VGAARB_H
+
+#include <sys/errno.h>
+
+#define VGA_RSRC_LEGACY_IO 0x01
+
+struct pci_dev;
+
+void vga_get_uninterruptible(struct pci_dev *, int);
+void vga_put(struct pci_dev *, int);
+
+static inline int
+vga_client_register(struct pci_dev *a, void *b, void *c, void *d)
+{
+ return -ENODEV;
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/vmalloc.h b/sys/dev/pci/drm/include/linux/vmalloc.h
new file mode 100644
index 00000000000..7daa7bea5bd
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/vmalloc.h
@@ -0,0 +1,49 @@
+/* $OpenBSD: vmalloc.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2013, 2014, 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_VMALLOC_H
+#define _LINUX_VMALLOC_H
+
+#include <sys/types.h>
+#include <sys/malloc.h>
+#include <uvm/uvm_extern.h>
+#include <linux/types.h>
+#include <linux/overflow.h>
+
+void *vmap(struct vm_page **, unsigned int, unsigned long, pgprot_t);
+void vunmap(void *, size_t);
+
+static inline void *
+vmalloc(unsigned long size)
+{
+ return malloc(size, M_DRM, M_WAITOK | M_CANFAIL);
+}
+
+static inline void *
+vzalloc(unsigned long size)
+{
+ return malloc(size, M_DRM, M_WAITOK | M_CANFAIL | M_ZERO);
+}
+
+static inline void
+vfree(void *objp)
+{
+ free(objp, M_DRM, 0);
+}
+
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/vt.h b/sys/dev/pci/drm/include/linux/vt.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/vt.h
diff --git a/sys/dev/pci/drm/include/linux/wait.h b/sys/dev/pci/drm/include/linux/wait.h
new file mode 100644
index 00000000000..5c8ef223f02
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/wait.h
@@ -0,0 +1,267 @@
+/* $OpenBSD: wait.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2013, 2014, 2015 Mark Kettenis
+ * Copyright (c) 2017 Martin Pieuchot
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_WAIT_H
+#define _LINUX_WAIT_H
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mutex.h>
+
+#include <linux/list.h>
+#include <linux/errno.h>
+#include <linux/spinlock.h>
+
+struct wait_queue_entry {
+ unsigned int flags;
+ void *private;
+ int (*func)(struct wait_queue_entry *, unsigned, int, void *);
+ struct proc *proc;
+ struct list_head entry;
+};
+
+typedef struct wait_queue_entry wait_queue_entry_t;
+
+extern struct mutex sch_mtx;
+extern volatile struct proc *sch_proc;
+extern volatile void *sch_ident;
+extern int sch_priority;
+
+struct wait_queue_head {
+ struct mutex lock;
+ unsigned int count;
+ struct list_head head;
+};
+typedef struct wait_queue_head wait_queue_head_t;
+
+static inline void
+init_waitqueue_head(wait_queue_head_t *wqh)
+{
+ mtx_init(&wqh->lock, IPL_TTY);
+ wqh->count = 0;
+ INIT_LIST_HEAD(&wqh->head);
+}
+
+#define __init_waitqueue_head(wq, name, key) init_waitqueue_head(wq)
+
+int default_wake_function(struct wait_queue_entry *, unsigned int, int, void *);
+int autoremove_wake_function(struct wait_queue_entry *, unsigned int, int, void *);
+
+static inline void
+init_wait_entry(wait_queue_entry_t *wqe, int flags)
+{
+ wqe->flags = flags;
+ wqe->private = NULL;
+ wqe->func = autoremove_wake_function;
+ wqe->proc = NULL;
+ INIT_LIST_HEAD(&wqe->entry);
+}
+
+static inline void
+__add_wait_queue(wait_queue_head_t *wqh, wait_queue_entry_t *wqe)
+{
+ list_add(&wqe->entry, &wqh->head);
+}
+
+static inline void
+__add_wait_queue_entry_tail(wait_queue_head_t *wqh, wait_queue_entry_t *wqe)
+{
+ list_add_tail(&wqe->entry, &wqh->head);
+}
+
+static inline void
+add_wait_queue(wait_queue_head_t *head, wait_queue_entry_t *new)
+{
+ mtx_enter(&head->lock);
+ new->proc = curproc;
+ __add_wait_queue(head, new);
+ mtx_leave(&head->lock);
+}
+
+static inline void
+__remove_wait_queue(wait_queue_head_t *wqh, wait_queue_entry_t *wqe)
+{
+ list_del(&wqe->entry);
+}
+
+static inline void
+remove_wait_queue(wait_queue_head_t *head, wait_queue_entry_t *old)
+{
+ mtx_enter(&head->lock);
+ __remove_wait_queue(head, old);
+ old->proc = NULL;
+ mtx_leave(&head->lock);
+}
+
+#define __wait_event_intr_timeout(wq, condition, timo, prio) \
+({ \
+ long ret = timo; \
+ do { \
+ int deadline, __error; \
+ \
+ KASSERT(!cold); \
+ \
+ mtx_enter(&sch_mtx); \
+ atomic_inc_int(&(wq).count); \
+ deadline = ticks + ret; \
+ __error = msleep(&wq, &sch_mtx, prio, "drmweti", ret); \
+ ret = deadline - ticks; \
+ atomic_dec_int(&(wq).count); \
+ if (__error == ERESTART || __error == EINTR) { \
+ ret = -ERESTARTSYS; \
+ mtx_leave(&sch_mtx); \
+ break; \
+ } \
+ if (timo && (ret <= 0 || __error == EWOULDBLOCK)) { \
+ mtx_leave(&sch_mtx); \
+ ret = ((condition)) ? 1 : 0; \
+ break; \
+ } \
+ mtx_leave(&sch_mtx); \
+ } while (ret > 0 && !(condition)); \
+ ret; \
+})
+
+/*
+ * Sleep until `condition' gets true.
+ */
+#define wait_event(wq, condition) \
+do { \
+ if (!(condition)) \
+ __wait_event_intr_timeout(wq, condition, 0, 0); \
+} while (0)
+
+#define wait_event_interruptible(wq, condition) \
+({ \
+ int __ret = 0; \
+ if (!(condition)) \
+ __ret = __wait_event_intr_timeout(wq, condition, 0, PCATCH); \
+ __ret; \
+})
+
+#define wait_event_interruptible_locked(wq, condition) \
+({ \
+ int __ret = 0; \
+ if (!(condition)) \
+ __ret = __wait_event_intr_timeout(wq, condition, 0, PCATCH); \
+ __ret; \
+})
+
+/*
+ * Sleep until `condition' gets true or `timo' expires.
+ *
+ * Returns 0 if `condition' is still false when `timo' expires or
+ * the remaining (>=1) ticks otherwise.
+ */
+#define wait_event_timeout(wq, condition, timo) \
+({ \
+ long __ret = timo; \
+ if (!(condition)) \
+ __ret = __wait_event_intr_timeout(wq, condition, timo, 0); \
+ __ret; \
+})
+
+/*
+ * Sleep until `condition' gets true, `timo' expires or the process
+ * receives a signal.
+ *
+ * Returns -ERESTARTSYS if interrupted by a signal.
+ * Returns 0 if `condition' is still false when `timo' expires or
+ * the remaining (>=1) ticks otherwise.
+ */
+#define wait_event_interruptible_timeout(wq, condition, timo) \
+({ \
+ long __ret = timo; \
+ if (!(condition)) \
+ __ret = __wait_event_intr_timeout(wq, condition, timo, PCATCH);\
+ __ret; \
+})
+
+static inline void
+_wake_up(wait_queue_head_t *wqh LOCK_FL_VARS)
+{
+ wait_queue_entry_t *wqe;
+ wait_queue_entry_t *tmp;
+ _mtx_enter(&wqh->lock LOCK_FL_ARGS);
+
+ list_for_each_entry_safe(wqe, tmp, &wqh->head, entry) {
+ if (wqe->func != NULL)
+ wqe->func(wqe, 0, wqe->flags, NULL);
+ }
+ wakeup(wqh);
+ _mtx_leave(&wqh->lock LOCK_FL_ARGS);
+}
+
+#define wake_up(wq) _wake_up(wq LOCK_FILE_LINE)
+#define wake_up_all(wq) _wake_up(wq LOCK_FILE_LINE)
+
+static inline void
+wake_up_all_locked(wait_queue_head_t *wqh)
+{
+ wait_queue_entry_t *wqe;
+ wait_queue_entry_t *tmp;
+
+ list_for_each_entry_safe(wqe, tmp, &wqh->head, entry) {
+ if (wqe->func != NULL)
+ wqe->func(wqe, 0, wqe->flags, NULL);
+ }
+ wakeup(wqh);
+}
+
+#define wake_up_interruptible(wq) _wake_up(wq LOCK_FILE_LINE)
+#define waitqueue_active(wq) ((wq)->count > 0)
+
+#define DEFINE_WAIT(name) \
+ struct wait_queue_entry name = { \
+ .private = NULL, \
+ .func = autoremove_wake_function, \
+ .entry = LIST_HEAD_INIT((name).entry), \
+ }
+#define DEFINE_WAIT_FUNC(name, cb) \
+ struct wait_queue_entry name = { \
+ .private = NULL, \
+ .func = cb, \
+ .entry = LIST_HEAD_INIT((name).entry), \
+ }
+
+static inline void
+prepare_to_wait(wait_queue_head_t *wqh, wait_queue_entry_t *wqe, int state)
+{
+ if (wqe->flags == 0) {
+ mtx_enter(&sch_mtx);
+ wqe->flags = 1;
+ }
+ MUTEX_ASSERT_LOCKED(&sch_mtx);
+ if (list_empty(&wqe->entry))
+ __add_wait_queue(wqh, wqe);
+ sch_proc = curproc;
+ sch_ident = wqe;
+ sch_priority = state;
+}
+
+static inline void
+finish_wait(wait_queue_head_t *wqh, wait_queue_entry_t *wqe)
+{
+ MUTEX_ASSERT_LOCKED(&sch_mtx);
+ sch_ident = NULL;
+ if (!list_empty(&wqe->entry))
+ list_del_init(&wqe->entry);
+ mtx_leave(&sch_mtx);
+}
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/wait_bit.h b/sys/dev/pci/drm/include/linux/wait_bit.h
new file mode 100644
index 00000000000..6f30fdc1ede
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/wait_bit.h
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#ifndef _LINUX_WAIT_BIT_H
+#define _LINUX_WAIT_BIT_H
+
+int wait_on_bit(unsigned long *, int, unsigned);
+int wait_on_bit_timeout(unsigned long *, int, unsigned, int);
+void wake_up_bit(void *, int);
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/workqueue.h b/sys/dev/pci/drm/include/linux/workqueue.h
new file mode 100644
index 00000000000..138ff8e7409
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/workqueue.h
@@ -0,0 +1,218 @@
+/* $OpenBSD: workqueue.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */
+/*
+ * Copyright (c) 2015 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_WORKQUEUE_H
+#define _LINUX_WORKQUEUE_H
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/task.h>
+#include <sys/timeout.h>
+#include <linux/bitops.h>
+#include <linux/atomic.h>
+#include <linux/rcupdate.h>
+#include <linux/kernel.h>
+#include <linux/lockdep.h>
+#include <linux/timer.h>
+
+struct workqueue_struct;
+
+extern struct workqueue_struct *system_wq;
+extern struct workqueue_struct *system_unbound_wq;
+extern struct workqueue_struct *system_long_wq;
+
+#define WQ_HIGHPRI 1
+#define WQ_FREEZABLE 2
+#define WQ_UNBOUND 4
+
+static inline struct workqueue_struct *
+alloc_workqueue(const char *name, int flags, int max_active)
+{
+ struct taskq *tq = taskq_create(name, 1, IPL_TTY, 0);
+ return (struct workqueue_struct *)tq;
+}
+
+static inline struct workqueue_struct *
+alloc_ordered_workqueue(const char *name, int flags)
+{
+ struct taskq *tq = taskq_create(name, 1, IPL_TTY, 0);
+ return (struct workqueue_struct *)tq;
+}
+
+static inline struct workqueue_struct *
+create_singlethread_workqueue(const char *name)
+{
+ struct taskq *tq = taskq_create(name, 1, IPL_TTY, 0);
+ return (struct workqueue_struct *)tq;
+}
+
+static inline void
+destroy_workqueue(struct workqueue_struct *wq)
+{
+ taskq_destroy((struct taskq *)wq);
+}
+
+struct work_struct {
+ struct task task;
+ struct taskq *tq;
+};
+
+typedef void (*work_func_t)(struct work_struct *);
+
+static inline void
+INIT_WORK(struct work_struct *work, work_func_t func)
+{
+ work->tq = (struct taskq *)system_wq;
+ task_set(&work->task, (void (*)(void *))func, work);
+}
+
+#define INIT_WORK_ONSTACK(x, y) INIT_WORK((x), (y))
+
+static inline bool
+queue_work(struct workqueue_struct *wq, struct work_struct *work)
+{
+ work->tq = (struct taskq *)wq;
+ return task_add(work->tq, &work->task);
+}
+
+static inline void
+cancel_work_sync(struct work_struct *work)
+{
+ task_del(work->tq, &work->task);
+}
+
+#define work_pending(work) task_pending(&(work)->task)
+
+struct delayed_work {
+ struct work_struct work;
+ struct timeout to;
+ struct taskq *tq;
+};
+
+struct irq_work {
+ struct task task;
+ struct taskq *tq;
+};
+
+typedef void (*irq_work_func_t)(struct irq_work *);
+
+static inline void
+init_irq_work(struct irq_work *work, irq_work_func_t func)
+{
+ work->tq = (struct taskq *)system_wq;
+ task_set(&work->task, (void (*)(void *))func, work);
+}
+
+static inline bool
+irq_work_queue(struct irq_work *work)
+{
+ return task_add(work->tq, &work->task);
+}
+
+#define system_power_efficient_wq ((struct workqueue_struct *)systq)
+
+static inline struct delayed_work *
+to_delayed_work(struct work_struct *work)
+{
+ return container_of(work, struct delayed_work, work);
+}
+
+static void
+__delayed_work_tick(void *arg)
+{
+ struct delayed_work *dwork = arg;
+
+ task_add(dwork->tq, &dwork->work.task);
+}
+
+static inline void
+INIT_DELAYED_WORK(struct delayed_work *dwork, work_func_t func)
+{
+ INIT_WORK(&dwork->work, func);
+ timeout_set(&dwork->to, __delayed_work_tick, &dwork->work);
+}
+
+static inline void
+INIT_DELAYED_WORK_ONSTACK(struct delayed_work *dwork, work_func_t func)
+{
+ INIT_WORK(&dwork->work, func);
+ timeout_set(&dwork->to, __delayed_work_tick, &dwork->work);
+}
+
+static inline bool
+schedule_work(struct work_struct *work)
+{
+ return task_add(work->tq, &work->task);
+}
+
+static inline bool
+schedule_delayed_work(struct delayed_work *dwork, int jiffies)
+{
+ dwork->tq = (struct taskq *)system_wq;
+ return timeout_add(&dwork->to, jiffies);
+}
+
+static inline bool
+queue_delayed_work(struct workqueue_struct *wq,
+ struct delayed_work *dwork, int jiffies)
+{
+ dwork->tq = (struct taskq *)wq;
+ return timeout_add(&dwork->to, jiffies);
+}
+
+static inline bool
+mod_delayed_work(struct workqueue_struct *wq,
+ struct delayed_work *dwork, int jiffies)
+{
+ dwork->tq = (struct taskq *)wq;
+ return (timeout_add(&dwork->to, jiffies) == 0);
+}
+
+static inline bool
+cancel_delayed_work(struct delayed_work *dwork)
+{
+ if (timeout_del(&dwork->to))
+ return true;
+ return task_del(dwork->tq, &dwork->work.task);
+}
+
+static inline bool
+cancel_delayed_work_sync(struct delayed_work *dwork)
+{
+ if (timeout_del(&dwork->to))
+ return true;
+ return task_del(dwork->tq, &dwork->work.task);
+}
+
+static inline bool
+delayed_work_pending(struct delayed_work *dwork)
+{
+ if (timeout_pending(&dwork->to))
+ return true;
+ return task_pending(&dwork->work.task);
+}
+
+void flush_workqueue(struct workqueue_struct *);
+bool flush_work(struct work_struct *);
+bool flush_delayed_work(struct delayed_work *);
+#define flush_scheduled_work() flush_workqueue(system_wq)
+#define drain_workqueue(x) flush_workqueue(x)
+
+#define destroy_work_on_stack(x)
+#define destroy_delayed_work_on_stack(x)
+
+#endif
diff --git a/sys/dev/pci/drm/include/linux/ww_mutex.h b/sys/dev/pci/drm/include/linux/ww_mutex.h
new file mode 100644
index 00000000000..ef7416e43eb
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/ww_mutex.h
@@ -0,0 +1,248 @@
+/*
+ * Copyright (c) 2015 Michael Neumann <mneumann@ntecs.de>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_WW_MUTEX_H_
+#define _LINUX_WW_MUTEX_H_
+
+/*
+ * A basic, unoptimized implementation of wound/wait mutexes for DragonFly
+ * modelled after the Linux API [1].
+ *
+ * [1]: http://lxr.free-electrons.com/source/include/linux/ww_mutex.h
+ */
+
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/param.h>
+#include <sys/mutex.h>
+#include <machine/intr.h>
+#include <linux/compiler.h>
+#include <linux/mutex.h>
+
+struct ww_class {
+ volatile u_long stamp;
+ const char *name;
+};
+
+struct ww_acquire_ctx {
+ u_long stamp;
+ struct ww_class *ww_class;
+};
+
+struct ww_mutex {
+ struct mutex base;
+ volatile int acquired;
+ volatile struct ww_acquire_ctx *ctx;
+ volatile struct proc *owner;
+};
+
+#define DEFINE_WW_CLASS(classname) \
+ struct ww_class classname = { \
+ .stamp = 0, \
+ .name = #classname \
+ }
+
+#define DEFINE_WD_CLASS(classname) \
+ struct ww_class classname = { \
+ .stamp = 0, \
+ .name = #classname \
+ }
+
+static inline void
+ww_acquire_init(struct ww_acquire_ctx *ctx, struct ww_class *ww_class) {
+ ctx->stamp = __sync_fetch_and_add(&ww_class->stamp, 1);
+ ctx->ww_class = ww_class;
+}
+
+static inline void
+ww_acquire_done(__unused struct ww_acquire_ctx *ctx) {
+}
+
+static inline void
+ww_acquire_fini(__unused struct ww_acquire_ctx *ctx) {
+}
+
+static inline void
+ww_mutex_init(struct ww_mutex *lock, struct ww_class *ww_class) {
+ mtx_init(&lock->base, IPL_NONE);
+ lock->acquired = 0;
+ lock->ctx = NULL;
+ lock->owner = NULL;
+}
+
+static inline bool
+ww_mutex_is_locked(struct ww_mutex *lock) {
+ bool res = false;
+ mtx_enter(&lock->base);
+ if (lock->acquired > 0) res = true;
+ mtx_leave(&lock->base);
+ return res;
+}
+
+/*
+ * Return 1 if lock could be acquired, else 0 (contended).
+ */
+static inline int
+ww_mutex_trylock(struct ww_mutex *lock) {
+ int res = 0;
+
+ mtx_enter(&lock->base);
+ /*
+ * In case no one holds the ww_mutex yet, we acquire it.
+ */
+ if (lock->acquired == 0) {
+ KASSERT(lock->ctx == NULL);
+ lock->acquired = 1;
+ lock->owner = curproc;
+ res = 1;
+ }
+ mtx_leave(&lock->base);
+ return res;
+}
+
+/*
+ * When `slow` is `true`, it will always block if the ww_mutex is contended.
+ * It is assumed that the called will not hold any (ww_mutex) resources when
+ * calling the slow path as this could lead to deadlocks.
+ *
+ * When `intr` is `true`, the ssleep will be interruptable.
+ */
+static inline int
+__ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx, bool slow, bool intr) {
+ int err;
+
+ mtx_enter(&lock->base);
+ for (;;) {
+ /*
+ * In case no one holds the ww_mutex yet, we acquire it.
+ */
+ if (lock->acquired == 0) {
+ KASSERT(lock->ctx == NULL);
+ lock->acquired = 1;
+ lock->ctx = ctx;
+ lock->owner = curproc;
+ err = 0;
+ break;
+ }
+ /*
+ * In case we already hold the return -EALREADY.
+ */
+ else if (lock->owner == curproc) {
+ err = -EALREADY;
+ break;
+ }
+ /*
+ * This is the contention case where the ww_mutex is
+ * already held by another context.
+ */
+ else {
+ /*
+ * Three cases:
+ *
+ * - We are in the slow-path (first lock to obtain).
+ *
+ * - No context was specified. We assume a single
+ * resouce, so there is no danger of a deadlock.
+ *
+ * - An `older` process (`ctx`) tries to acquire a
+ * lock already held by a `younger` process.
+ * We put the `older` process to sleep until
+ * the `younger` process gives up all it's
+ * resources.
+ */
+ if (slow || ctx == NULL ||
+ (lock->ctx && ctx->stamp < lock->ctx->stamp)) {
+ KASSERT(!cold);
+ int s = msleep(lock, &lock->base,
+ intr ? PCATCH : 0,
+ ctx ? ctx->ww_class->name : "ww_mutex_lock", 0);
+ if (intr && (s == EINTR || s == ERESTART)) {
+ // XXX: Should we handle ERESTART?
+ err = -EINTR;
+ break;
+ }
+ }
+ /*
+ * If a `younger` process tries to acquire a lock
+ * already held by an `older` process, we `wound` it,
+ * i.e. we return -EDEADLK because there is a potential
+ * risk for a deadlock. The `younger` process then
+ * should give up all it's resources and try again to
+ * acquire the lock in question, this time in a
+ * blocking manner.
+ */
+ else {
+ err = -EDEADLK;
+ break;
+ }
+ }
+
+ } /* for */
+ mtx_leave(&lock->base);
+ return err;
+}
+
+static inline int
+ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) {
+ return __ww_mutex_lock(lock, ctx, false, false);
+}
+
+static inline void
+ww_mutex_lock_slow(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) {
+ (void)__ww_mutex_lock(lock, ctx, true, false);
+}
+
+static inline int
+ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) {
+ return __ww_mutex_lock(lock, ctx, false, true);
+}
+
+static inline int __must_check
+ww_mutex_lock_slow_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) {
+ return __ww_mutex_lock(lock, ctx, true, true);
+}
+
+static inline void
+ww_mutex_unlock(struct ww_mutex *lock) {
+ mtx_enter(&lock->base);
+ KASSERT(lock->owner == curproc);
+ KASSERT(lock->acquired == 1);
+
+ lock->acquired = 0;
+ lock->ctx = NULL;
+ lock->owner = NULL;
+ mtx_leave(&lock->base);
+ wakeup(lock);
+}
+
+static inline void
+ww_mutex_destroy(struct ww_mutex *lock) {
+ KASSERT(lock->acquired == 0);
+ KASSERT(lock->ctx == NULL);
+ KASSERT(lock->owner == NULL);
+}
+
+#endif /* _LINUX_WW_MUTEX_H_ */
diff --git a/sys/dev/pci/drm/include/linux/zlib.h b/sys/dev/pci/drm/include/linux/zlib.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/dev/pci/drm/include/linux/zlib.h