History log of /openbsd-current/sys/dev/pci/drm/drm_linux.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.113 03-Jun-2024 claudio

Remove the now unsued s argument to SCHED_LOCK and SCHED_UNLOCK.

The SPL level is not tacked by the mutex and we no longer need to track
this in the callers.
OK miod@ mlarkin@ tb@ jca@


# 1.112 30-Mar-2024 mpi

Prevent a recursion inside wakeup(9) when scheduler tracepoints are enabled.

Tracepoints like "sched:enqueue" and "sched:unsleep" were called from inside
the loop iterating over sleeping threads as part of wakeup_proc(). When such
tracepoints were enabled they could result in another wakeup(9) possibly
corrupting the sleepqueue.

Rewrite wakeup(9) in two stages, first dequeue threads from the sleepqueue then
call setrunnable() and possible tracepoints for each of them.

This requires moving unsleep() outside of setrunnable() because it messes with
the sleepqueue.

ok claudio@


# 1.111 20-Mar-2024 jsg

add vmap_pfn()


# 1.110 20-Mar-2024 jsg

in vga_get_uninterruptible() return early if behind a bridge

remove KASSERT() that triggered on dg2


Revision tags: OPENBSD_7_5_BASE
# 1.109 21-Jan-2024 kettenis

Add support for multiple matches in the component code.

ok jsg@


# 1.108 16-Jan-2024 jsg

update drm to linux 6.6.12

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.107 13-Jan-2024 kettenis

Provide a more complete implementation of the "component" APIs. Also tweak
the "platform" interfaces to stash away the bits of fdt_attach_args that
we need later on instead of referencing it directly. This makes those
interfaces usable after attach time.

ok jsg@


# 1.106 06-Jan-2024 kettenis

Add more Linux compat code in preparation for the apple KMS driver.

ok jsg@


# 1.105 23-Dec-2023 kettenis

Provide more complete implementations of some of the Linux compat
interfaces that are needed for the upcoming apple kms driver.

ok jsg@


# 1.104 20-Oct-2023 jsg

add dma_fence_timestamp() for 6.1.59 drm


Revision tags: OPENBSD_7_4_BASE
# 1.103 04-Aug-2023 jsg

dma-buf: fix an error pointer vs NULL bug

From Dan Carpenter
c3d576baa6c8f0b34750a0b6f9b12e9d64625512 in linux-6.1.y/6.1.43
00ae1491f970acc454be0df63f50942d94825860 in mainline linux


# 1.102 04-Aug-2023 jsg

drm_syncobj.c now uses dma_fence_allocate_private_stub() with an arg


# 1.101 18-Jul-2023 claudio

With the update of the sleep API the linux emulation of their wait API,
schedule() and set_current_state() can be implemented in a much less
hacky way. This should remove some possible race conditions in the wait API.
Tested by many (kettenis, jsg, phessler, thfr)
OK kettenis@


# 1.100 14-Jul-2023 claudio

struct sleep_state is no longer used, remove it.
Also remove the priority argument to sleep_finish() the code can use
the p_flag P_SINTR flag to know if the signal check is needed or not.
OK cheloha@ kettenis@ mpi@


# 1.99 28-Jun-2023 claudio

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@


# 1.98 01-Jun-2023 claudio

Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must
be called with SCHED_LOCK() held. Also add an extra argument to update
the process flags p_flag so that the timeout handler can set the
P_TIMEOUT flag before making the process runnable.
OK mpi@


Revision tags: OPENBSD_7_3_BASE
# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.112 30-Mar-2024 mpi

Prevent a recursion inside wakeup(9) when scheduler tracepoints are enabled.

Tracepoints like "sched:enqueue" and "sched:unsleep" were called from inside
the loop iterating over sleeping threads as part of wakeup_proc(). When such
tracepoints were enabled they could result in another wakeup(9) possibly
corrupting the sleepqueue.

Rewrite wakeup(9) in two stages, first dequeue threads from the sleepqueue then
call setrunnable() and possible tracepoints for each of them.

This requires moving unsleep() outside of setrunnable() because it messes with
the sleepqueue.

ok claudio@


# 1.111 20-Mar-2024 jsg

add vmap_pfn()


# 1.110 20-Mar-2024 jsg

in vga_get_uninterruptible() return early if behind a bridge

remove KASSERT() that triggered on dg2


Revision tags: OPENBSD_7_5_BASE
# 1.109 21-Jan-2024 kettenis

Add support for multiple matches in the component code.

ok jsg@


# 1.108 16-Jan-2024 jsg

update drm to linux 6.6.12

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.107 13-Jan-2024 kettenis

Provide a more complete implementation of the "component" APIs. Also tweak
the "platform" interfaces to stash away the bits of fdt_attach_args that
we need later on instead of referencing it directly. This makes those
interfaces usable after attach time.

ok jsg@


# 1.106 06-Jan-2024 kettenis

Add more Linux compat code in preparation for the apple KMS driver.

ok jsg@


# 1.105 23-Dec-2023 kettenis

Provide more complete implementations of some of the Linux compat
interfaces that are needed for the upcoming apple kms driver.

ok jsg@


# 1.104 20-Oct-2023 jsg

add dma_fence_timestamp() for 6.1.59 drm


Revision tags: OPENBSD_7_4_BASE
# 1.103 04-Aug-2023 jsg

dma-buf: fix an error pointer vs NULL bug

From Dan Carpenter
c3d576baa6c8f0b34750a0b6f9b12e9d64625512 in linux-6.1.y/6.1.43
00ae1491f970acc454be0df63f50942d94825860 in mainline linux


# 1.102 04-Aug-2023 jsg

drm_syncobj.c now uses dma_fence_allocate_private_stub() with an arg


# 1.101 18-Jul-2023 claudio

With the update of the sleep API the linux emulation of their wait API,
schedule() and set_current_state() can be implemented in a much less
hacky way. This should remove some possible race conditions in the wait API.
Tested by many (kettenis, jsg, phessler, thfr)
OK kettenis@


# 1.100 14-Jul-2023 claudio

struct sleep_state is no longer used, remove it.
Also remove the priority argument to sleep_finish() the code can use
the p_flag P_SINTR flag to know if the signal check is needed or not.
OK cheloha@ kettenis@ mpi@


# 1.99 28-Jun-2023 claudio

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@


# 1.98 01-Jun-2023 claudio

Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must
be called with SCHED_LOCK() held. Also add an extra argument to update
the process flags p_flag so that the timeout handler can set the
P_TIMEOUT flag before making the process runnable.
OK mpi@


Revision tags: OPENBSD_7_3_BASE
# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.111 20-Mar-2024 jsg

add vmap_pfn()


# 1.110 20-Mar-2024 jsg

in vga_get_uninterruptible() return early if behind a bridge

remove KASSERT() that triggered on dg2


Revision tags: OPENBSD_7_5_BASE
# 1.109 21-Jan-2024 kettenis

Add support for multiple matches in the component code.

ok jsg@


# 1.108 16-Jan-2024 jsg

update drm to linux 6.6.12

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.107 13-Jan-2024 kettenis

Provide a more complete implementation of the "component" APIs. Also tweak
the "platform" interfaces to stash away the bits of fdt_attach_args that
we need later on instead of referencing it directly. This makes those
interfaces usable after attach time.

ok jsg@


# 1.106 06-Jan-2024 kettenis

Add more Linux compat code in preparation for the apple KMS driver.

ok jsg@


# 1.105 23-Dec-2023 kettenis

Provide more complete implementations of some of the Linux compat
interfaces that are needed for the upcoming apple kms driver.

ok jsg@


# 1.104 20-Oct-2023 jsg

add dma_fence_timestamp() for 6.1.59 drm


Revision tags: OPENBSD_7_4_BASE
# 1.103 04-Aug-2023 jsg

dma-buf: fix an error pointer vs NULL bug

From Dan Carpenter
c3d576baa6c8f0b34750a0b6f9b12e9d64625512 in linux-6.1.y/6.1.43
00ae1491f970acc454be0df63f50942d94825860 in mainline linux


# 1.102 04-Aug-2023 jsg

drm_syncobj.c now uses dma_fence_allocate_private_stub() with an arg


# 1.101 18-Jul-2023 claudio

With the update of the sleep API the linux emulation of their wait API,
schedule() and set_current_state() can be implemented in a much less
hacky way. This should remove some possible race conditions in the wait API.
Tested by many (kettenis, jsg, phessler, thfr)
OK kettenis@


# 1.100 14-Jul-2023 claudio

struct sleep_state is no longer used, remove it.
Also remove the priority argument to sleep_finish() the code can use
the p_flag P_SINTR flag to know if the signal check is needed or not.
OK cheloha@ kettenis@ mpi@


# 1.99 28-Jun-2023 claudio

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@


# 1.98 01-Jun-2023 claudio

Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must
be called with SCHED_LOCK() held. Also add an extra argument to update
the process flags p_flag so that the timeout handler can set the
P_TIMEOUT flag before making the process runnable.
OK mpi@


Revision tags: OPENBSD_7_3_BASE
# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.109 21-Jan-2024 kettenis

Add support for multiple matches in the component code.

ok jsg@


# 1.108 16-Jan-2024 jsg

update drm to linux 6.6.12

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.107 13-Jan-2024 kettenis

Provide a more complete implementation of the "component" APIs. Also tweak
the "platform" interfaces to stash away the bits of fdt_attach_args that
we need later on instead of referencing it directly. This makes those
interfaces usable after attach time.

ok jsg@


# 1.106 06-Jan-2024 kettenis

Add more Linux compat code in preparation for the apple KMS driver.

ok jsg@


# 1.105 23-Dec-2023 kettenis

Provide more complete implementations of some of the Linux compat
interfaces that are needed for the upcoming apple kms driver.

ok jsg@


# 1.104 20-Oct-2023 jsg

add dma_fence_timestamp() for 6.1.59 drm


Revision tags: OPENBSD_7_4_BASE
# 1.103 04-Aug-2023 jsg

dma-buf: fix an error pointer vs NULL bug

From Dan Carpenter
c3d576baa6c8f0b34750a0b6f9b12e9d64625512 in linux-6.1.y/6.1.43
00ae1491f970acc454be0df63f50942d94825860 in mainline linux


# 1.102 04-Aug-2023 jsg

drm_syncobj.c now uses dma_fence_allocate_private_stub() with an arg


# 1.101 18-Jul-2023 claudio

With the update of the sleep API the linux emulation of their wait API,
schedule() and set_current_state() can be implemented in a much less
hacky way. This should remove some possible race conditions in the wait API.
Tested by many (kettenis, jsg, phessler, thfr)
OK kettenis@


# 1.100 14-Jul-2023 claudio

struct sleep_state is no longer used, remove it.
Also remove the priority argument to sleep_finish() the code can use
the p_flag P_SINTR flag to know if the signal check is needed or not.
OK cheloha@ kettenis@ mpi@


# 1.99 28-Jun-2023 claudio

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@


# 1.98 01-Jun-2023 claudio

Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must
be called with SCHED_LOCK() held. Also add an extra argument to update
the process flags p_flag so that the timeout handler can set the
P_TIMEOUT flag before making the process runnable.
OK mpi@


Revision tags: OPENBSD_7_3_BASE
# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.108 16-Jan-2024 jsg

update drm to linux 6.6.12

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.107 13-Jan-2024 kettenis

Provide a more complete implementation of the "component" APIs. Also tweak
the "platform" interfaces to stash away the bits of fdt_attach_args that
we need later on instead of referencing it directly. This makes those
interfaces usable after attach time.

ok jsg@


# 1.106 06-Jan-2024 kettenis

Add more Linux compat code in preparation for the apple KMS driver.

ok jsg@


# 1.105 23-Dec-2023 kettenis

Provide more complete implementations of some of the Linux compat
interfaces that are needed for the upcoming apple kms driver.

ok jsg@


# 1.104 20-Oct-2023 jsg

add dma_fence_timestamp() for 6.1.59 drm


Revision tags: OPENBSD_7_4_BASE
# 1.103 04-Aug-2023 jsg

dma-buf: fix an error pointer vs NULL bug

From Dan Carpenter
c3d576baa6c8f0b34750a0b6f9b12e9d64625512 in linux-6.1.y/6.1.43
00ae1491f970acc454be0df63f50942d94825860 in mainline linux


# 1.102 04-Aug-2023 jsg

drm_syncobj.c now uses dma_fence_allocate_private_stub() with an arg


# 1.101 18-Jul-2023 claudio

With the update of the sleep API the linux emulation of their wait API,
schedule() and set_current_state() can be implemented in a much less
hacky way. This should remove some possible race conditions in the wait API.
Tested by many (kettenis, jsg, phessler, thfr)
OK kettenis@


# 1.100 14-Jul-2023 claudio

struct sleep_state is no longer used, remove it.
Also remove the priority argument to sleep_finish() the code can use
the p_flag P_SINTR flag to know if the signal check is needed or not.
OK cheloha@ kettenis@ mpi@


# 1.99 28-Jun-2023 claudio

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@


# 1.98 01-Jun-2023 claudio

Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must
be called with SCHED_LOCK() held. Also add an extra argument to update
the process flags p_flag so that the timeout handler can set the
P_TIMEOUT flag before making the process runnable.
OK mpi@


Revision tags: OPENBSD_7_3_BASE
# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.107 13-Jan-2024 kettenis

Provide a more complete implementation of the "component" APIs. Also tweak
the "platform" interfaces to stash away the bits of fdt_attach_args that
we need later on instead of referencing it directly. This makes those
interfaces usable after attach time.

ok jsg@


# 1.106 06-Jan-2024 kettenis

Add more Linux compat code in preparation for the apple KMS driver.

ok jsg@


# 1.105 23-Dec-2023 kettenis

Provide more complete implementations of some of the Linux compat
interfaces that are needed for the upcoming apple kms driver.

ok jsg@


# 1.104 20-Oct-2023 jsg

add dma_fence_timestamp() for 6.1.59 drm


Revision tags: OPENBSD_7_4_BASE
# 1.103 04-Aug-2023 jsg

dma-buf: fix an error pointer vs NULL bug

From Dan Carpenter
c3d576baa6c8f0b34750a0b6f9b12e9d64625512 in linux-6.1.y/6.1.43
00ae1491f970acc454be0df63f50942d94825860 in mainline linux


# 1.102 04-Aug-2023 jsg

drm_syncobj.c now uses dma_fence_allocate_private_stub() with an arg


# 1.101 18-Jul-2023 claudio

With the update of the sleep API the linux emulation of their wait API,
schedule() and set_current_state() can be implemented in a much less
hacky way. This should remove some possible race conditions in the wait API.
Tested by many (kettenis, jsg, phessler, thfr)
OK kettenis@


# 1.100 14-Jul-2023 claudio

struct sleep_state is no longer used, remove it.
Also remove the priority argument to sleep_finish() the code can use
the p_flag P_SINTR flag to know if the signal check is needed or not.
OK cheloha@ kettenis@ mpi@


# 1.99 28-Jun-2023 claudio

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@


# 1.98 01-Jun-2023 claudio

Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must
be called with SCHED_LOCK() held. Also add an extra argument to update
the process flags p_flag so that the timeout handler can set the
P_TIMEOUT flag before making the process runnable.
OK mpi@


Revision tags: OPENBSD_7_3_BASE
# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.106 06-Jan-2024 kettenis

Add more Linux compat code in preparation for the apple KMS driver.

ok jsg@


# 1.105 23-Dec-2023 kettenis

Provide more complete implementations of some of the Linux compat
interfaces that are needed for the upcoming apple kms driver.

ok jsg@


# 1.104 20-Oct-2023 jsg

add dma_fence_timestamp() for 6.1.59 drm


Revision tags: OPENBSD_7_4_BASE
# 1.103 04-Aug-2023 jsg

dma-buf: fix an error pointer vs NULL bug

From Dan Carpenter
c3d576baa6c8f0b34750a0b6f9b12e9d64625512 in linux-6.1.y/6.1.43
00ae1491f970acc454be0df63f50942d94825860 in mainline linux


# 1.102 04-Aug-2023 jsg

drm_syncobj.c now uses dma_fence_allocate_private_stub() with an arg


# 1.101 18-Jul-2023 claudio

With the update of the sleep API the linux emulation of their wait API,
schedule() and set_current_state() can be implemented in a much less
hacky way. This should remove some possible race conditions in the wait API.
Tested by many (kettenis, jsg, phessler, thfr)
OK kettenis@


# 1.100 14-Jul-2023 claudio

struct sleep_state is no longer used, remove it.
Also remove the priority argument to sleep_finish() the code can use
the p_flag P_SINTR flag to know if the signal check is needed or not.
OK cheloha@ kettenis@ mpi@


# 1.99 28-Jun-2023 claudio

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@


# 1.98 01-Jun-2023 claudio

Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must
be called with SCHED_LOCK() held. Also add an extra argument to update
the process flags p_flag so that the timeout handler can set the
P_TIMEOUT flag before making the process runnable.
OK mpi@


Revision tags: OPENBSD_7_3_BASE
# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.105 23-Dec-2023 kettenis

Provide more complete implementations of some of the Linux compat
interfaces that are needed for the upcoming apple kms driver.

ok jsg@


# 1.104 20-Oct-2023 jsg

add dma_fence_timestamp() for 6.1.59 drm


Revision tags: OPENBSD_7_4_BASE
# 1.103 04-Aug-2023 jsg

dma-buf: fix an error pointer vs NULL bug

From Dan Carpenter
c3d576baa6c8f0b34750a0b6f9b12e9d64625512 in linux-6.1.y/6.1.43
00ae1491f970acc454be0df63f50942d94825860 in mainline linux


# 1.102 04-Aug-2023 jsg

drm_syncobj.c now uses dma_fence_allocate_private_stub() with an arg


# 1.101 18-Jul-2023 claudio

With the update of the sleep API the linux emulation of their wait API,
schedule() and set_current_state() can be implemented in a much less
hacky way. This should remove some possible race conditions in the wait API.
Tested by many (kettenis, jsg, phessler, thfr)
OK kettenis@


# 1.100 14-Jul-2023 claudio

struct sleep_state is no longer used, remove it.
Also remove the priority argument to sleep_finish() the code can use
the p_flag P_SINTR flag to know if the signal check is needed or not.
OK cheloha@ kettenis@ mpi@


# 1.99 28-Jun-2023 claudio

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@


# 1.98 01-Jun-2023 claudio

Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must
be called with SCHED_LOCK() held. Also add an extra argument to update
the process flags p_flag so that the timeout handler can set the
P_TIMEOUT flag before making the process runnable.
OK mpi@


Revision tags: OPENBSD_7_3_BASE
# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.104 20-Oct-2023 jsg

add dma_fence_timestamp() for 6.1.59 drm


Revision tags: OPENBSD_7_4_BASE
# 1.103 04-Aug-2023 jsg

dma-buf: fix an error pointer vs NULL bug

From Dan Carpenter
c3d576baa6c8f0b34750a0b6f9b12e9d64625512 in linux-6.1.y/6.1.43
00ae1491f970acc454be0df63f50942d94825860 in mainline linux


# 1.102 04-Aug-2023 jsg

drm_syncobj.c now uses dma_fence_allocate_private_stub() with an arg


# 1.101 18-Jul-2023 claudio

With the update of the sleep API the linux emulation of their wait API,
schedule() and set_current_state() can be implemented in a much less
hacky way. This should remove some possible race conditions in the wait API.
Tested by many (kettenis, jsg, phessler, thfr)
OK kettenis@


# 1.100 14-Jul-2023 claudio

struct sleep_state is no longer used, remove it.
Also remove the priority argument to sleep_finish() the code can use
the p_flag P_SINTR flag to know if the signal check is needed or not.
OK cheloha@ kettenis@ mpi@


# 1.99 28-Jun-2023 claudio

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@


# 1.98 01-Jun-2023 claudio

Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must
be called with SCHED_LOCK() held. Also add an extra argument to update
the process flags p_flag so that the timeout handler can set the
P_TIMEOUT flag before making the process runnable.
OK mpi@


Revision tags: OPENBSD_7_3_BASE
# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.103 04-Aug-2023 jsg

dma-buf: fix an error pointer vs NULL bug

From Dan Carpenter
c3d576baa6c8f0b34750a0b6f9b12e9d64625512 in linux-6.1.y/6.1.43
00ae1491f970acc454be0df63f50942d94825860 in mainline linux


# 1.102 04-Aug-2023 jsg

drm_syncobj.c now uses dma_fence_allocate_private_stub() with an arg


# 1.101 18-Jul-2023 claudio

With the update of the sleep API the linux emulation of their wait API,
schedule() and set_current_state() can be implemented in a much less
hacky way. This should remove some possible race conditions in the wait API.
Tested by many (kettenis, jsg, phessler, thfr)
OK kettenis@


# 1.100 14-Jul-2023 claudio

struct sleep_state is no longer used, remove it.
Also remove the priority argument to sleep_finish() the code can use
the p_flag P_SINTR flag to know if the signal check is needed or not.
OK cheloha@ kettenis@ mpi@


# 1.99 28-Jun-2023 claudio

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@


# 1.98 01-Jun-2023 claudio

Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must
be called with SCHED_LOCK() held. Also add an extra argument to update
the process flags p_flag so that the timeout handler can set the
P_TIMEOUT flag before making the process runnable.
OK mpi@


Revision tags: OPENBSD_7_3_BASE
# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.101 18-Jul-2023 claudio

With the update of the sleep API the linux emulation of their wait API,
schedule() and set_current_state() can be implemented in a much less
hacky way. This should remove some possible race conditions in the wait API.
Tested by many (kettenis, jsg, phessler, thfr)
OK kettenis@


# 1.100 14-Jul-2023 claudio

struct sleep_state is no longer used, remove it.
Also remove the priority argument to sleep_finish() the code can use
the p_flag P_SINTR flag to know if the signal check is needed or not.
OK cheloha@ kettenis@ mpi@


# 1.99 28-Jun-2023 claudio

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@


# 1.98 01-Jun-2023 claudio

Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must
be called with SCHED_LOCK() held. Also add an extra argument to update
the process flags p_flag so that the timeout handler can set the
P_TIMEOUT flag before making the process runnable.
OK mpi@


Revision tags: OPENBSD_7_3_BASE
# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.100 14-Jul-2023 claudio

struct sleep_state is no longer used, remove it.
Also remove the priority argument to sleep_finish() the code can use
the p_flag P_SINTR flag to know if the signal check is needed or not.
OK cheloha@ kettenis@ mpi@


# 1.99 28-Jun-2023 claudio

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@


# 1.98 01-Jun-2023 claudio

Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must
be called with SCHED_LOCK() held. Also add an extra argument to update
the process flags p_flag so that the timeout handler can set the
P_TIMEOUT flag before making the process runnable.
OK mpi@


Revision tags: OPENBSD_7_3_BASE
# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.99 28-Jun-2023 claudio

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@


# 1.98 01-Jun-2023 claudio

Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must
be called with SCHED_LOCK() held. Also add an extra argument to update
the process flags p_flag so that the timeout handler can set the
P_TIMEOUT flag before making the process runnable.
OK mpi@


Revision tags: OPENBSD_7_3_BASE
# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.97 15-Mar-2023 jsg

handle dmi_get_system_info(DMI_BIOS_VERSION)


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.96 10-Feb-2023 visa

Adjust knote(9) API

Make knote(9) lock the knote list internally, and add knote_locked(9)
for the typical situation where the list is already locked.

Remove the KNOTE(9) macro to simplify the API.

Manual page OK jmc@
OK mpi@ mvs@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.95 01-Jan-2023 jsg

update drm to linux 6.1.2

new hardware support includes

AMD
Raphael, Ryzen 7000 desktop, gfx1036/GC 10.3.6
Mendocino, Ryzen & Athlon 7020 Series mobile APU, gfx1037/GC 10.3.7
Navi 31, gfx1100 dGPU, GC 11.0.0, Radeon RX 7900 XT/XTX
gfx1101 dGPU
gfx1102 dGPU
gfx1103 APU

Thanks to the OpenBSD Foundation for sponsoring this work.


Revision tags: OPENBSD_7_2_BASE
# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.94 16-Sep-2022 jsg

mask non-chain fence sequence numbers to 32-bit for comparisons

Most of drm uses 32-bit sequence numbers in fences.
dma-fence-chain opts into 64-bit comparisons.

Wrapping is handled like i915_seqno_passed() except that if the sequence
numbers are the same one is not considered later than the other.


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.93 20-Jun-2022 visa

Remove unused struct fileops field fo_poll and callbacks.

OK mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.92 01-Mar-2022 jsg

__i2c_transfer() should not lock the bus
i2c_transfer() locks the bus


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.91 28-Feb-2022 jsg

add pcie_aspm_enabled() for the next linux 5.15.y release


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.90 07-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.89 21-Jan-2022 jsg

release mtx before pool_get() in __xa_alloc()/__xa_store() when
PR_WAITOK is used to not sleep with mtx held


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.88 20-Jan-2022 jsg

xa_pool is protected by xa_lock mtx so drop pool ipl to IPL_NONE


# 1.87 20-Jan-2022 jsg

initial support for drm sync files, fences associated with file
descriptors for explicit fencing

tested with libdrm's amdgpu_test syncobj timeline tests and vkcube on
intel broadwell with Mesa 21.3 (which hangs without sync file support
after the 'anv: Assume syncobj support' Mesa commit)

feedback and ok visa@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.86 17-Jan-2022 jsg

unstub dma_fence_chain_find_seqno() for non zero seqno


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.85 14-Jan-2022 jsg

update drm to linux 5.15.14

new hardware support includes

Intel
ehl/Elkhart Lake (embedded)
jsl/Jasper Lake (atom)
rkl/Rocket Lake (desktop)

AMD
van gogh APU (gfx1033)
yellow carp / rembrandt APU (gfx1035?)
Ryzen 6000 APU
navy flounder / navi 22 (gfx1031)
RX 6700, RX 6700 XT, RX 6700M, RX 6800M, RX 6850M XT
dimgrey cavefish / navi 23 (gfx1032)
Pro W6600, Pro W6600M, RX 6600, RX 6600 XT, RX 6600M,
RX 6600S, RX 6650M, RX 6650M XT, RX 6700S, RX 6800S
beige goby / navi 24 (gfx1034)
RX 6500 XT, RX 6400, RX 6500M, RX 6300M

Thanks to the OpenBSD Foundation for sponsoring this work
niklas@ for helping with ttm and amdgpu and patrick@ for adapting
rockchip drm.


Revision tags: OPENBSD_7_0_BASE
# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.84 11-Aug-2021 sthen

backout drm/include/linux/irq_work.h r1.4 and drm/drm_linux.c r1.83
problems with suspend on various ThinkPad machines seen by me, tb@, deraadt@,
benno@ seem to go away with this reverted.


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.83 07-Aug-2021 jsg

use taskq_del_barrier() instead of taskq_barrier() when flushing work

prompted by jcs@ reporting a protection fault trap in
drm_mode_rmfb_work_fn() while playing a youtube video in firefox on a
kaby lake machine. He later saw the same trace on tiger lake.

The arguments to drm_mode_rmfb_work_fn() are on the stack in
drm_mode_rmfb() with flush_work() called before return.

taskq_barrier() is only a barrier for running not queued tasks.

I suspect the linux functions expect any previously queued work to
complete not just any currently running work. I'm not sure if the
difference matters in practice.


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.82 28-Jul-2021 kettenis

Switch to an MI implementation of kmap_atomic() and implement
kmap_atomic_prot(). Use this to unstub ttm_copy_io_ttm_page()
and ttm_copy_ttm_io_page(). This fixes suspend/resume of machines
with certain radeondrm(4) hardware.

Based on a diff from jsg@. Tested by Edd Barrett and Alf Schlichting.
ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.81 26-Jul-2021 jsg

retry i2c transfers on -EAGAIN up to the number of times specified in
struct i2c_adapter

inteldrm gmbus returns -EAGAIN to fallback to gpio bitbanging


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.80 07-Jul-2021 jsg

update drm to linux 5.10.47

hardware support changes include
inteldrm: better support for tiger lake
amdgpu: support for navi12, navi21 "sienna_cichlid", arcturus
amdgpu: support for cezanne "green sardine" ryzen 5000 apu

Thanks to the OpenBSD Foundation for sponsoring this work,
patrick@ for helping adapt rockchip drm, kettenis@ and mpi@
for uvm discussions and various testers.


Revision tags: OPENBSD_6_9_BASE
# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.79 11-Apr-2021 kettenis

On systems that hide the PCI bridge device corresponding to a PCIe RC port
we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this
by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.78 14-Feb-2021 jsg

correct drm work flush behaviour

Don't set taskq to system_wq in INIT_WORK(). Test if taskq pointer is
non-NULL before calling taskq_barrier() in flush functions.

fixes a black screen on boot problem with 5.10.y drm using nano x1
bisected by jcs@ to
'drm/i915: Always flush the active worker before returning from the wait'


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.77 08-Feb-2021 mpi

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.76 13-Jan-2021 jsg

revert drm vmalloc changes

It is suspected they were to blame for a machine with inteldrm running X
(xterms and chromium) running out of resources after a few days.

ok kettenis@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.75 08-Jan-2021 kettenis

Bring the emulated Linux memory allocation interfaces more in line with
what Linux does. Let vmalloc() use km_alloc(9) instead of malloc(9) and
let kvmalloc() only use malloc(9) for small (less than a page) allocations
and atomic allocations. This should reduce the pressure on the
"interrupt-safe" map.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.74 31-Dec-2020 jsg

don't oversleep when waiting on fences

original diff from and ok cheloha@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.73 13-Dec-2020 jsg

set scatterlist to NULL after free


# 1.72 13-Dec-2020 jsg

remove unused wait interfaces


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.71 10-Dec-2020 jsg

use jiffies var instead of ticks when checking for timeout


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.70 14-Nov-2020 kettenis

Revise the initialization of the DRM Linux emulation layer such that we
only call it when the first drm(4) instance attaches. Also add a cleanup
function that gets called when the last drm(4) instance detaches.
This makes sure that statically initialized IDR instances always work.

ok jsg@, semarie@


# 1.69 14-Nov-2020 jsg

idr limit should be inclusive

ok kettenis@


# 1.68 14-Nov-2020 kettenis

Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs
in amdgpu(4).

ok jsg@


# 1.67 14-Nov-2020 kettenis

whitespace


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.66 09-Nov-2020 jsg

use a single preinitialised mutex for atomic64 fallback path

Previously we would initialise a variable specific mutex in
ATOMIC64_INIT() or atomic64_set() but the drm code in multiple places
zeroes memory and later accesses it without calling these resulting
in a mutex with IPL_NONE instead of IPL_HIGH.

Fixes a 'locking against myself' panic reported by Anthony Richardby
on macppc with PowerBook5,6 and RV350.
ok kettenis@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.65 17-Oct-2020 semarie

Avoid a possible dead-lock in kthread_stop(): when stopping, wakeup()
the caller of kthread_stop().

The thread should also be unparked as else it will not seen the
KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.

ok kettenis@


# 1.64 16-Oct-2020 jsg

implement linux interval tree functions

Adapt kettenis' amdgpu interval tree replacement functions for the
interval_tree.h functions radeondrm uses on cayman, aruba and GCN.


Revision tags: OPENBSD_6_8_BASE
# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.63 26-Aug-2020 visa

Declare hw_{prod,serial,uuid,vendor,ver} in <sys/systm.h>.

OK deraadt@, mpi@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.62 03-Aug-2020 jsg

remove timeval conversion interfaces no longer in linux


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.61 02-Jul-2020 jsg

remove unused timespec interfaces no longer in linux


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.60 14-Jun-2020 jsg

rename our kunmap() to kunmap_va()

In linux kunmap() has a page struct * argument our kunmap() has a void *
argument which results in uncoverted uses building but doing the wrong
thing. Renaming will catch any codepaths that need to be changed at
compile time.


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.59 08-Jun-2020 jsg

update drm to linux 5.7

adds kernel support for
amdgpu: vega20, raven2, renoir, navi10, navi14
inteldrm: icelake, tigerlake

Thanks to the OpenBSD Foundation for sponsoring this work, kettenis@ for
helping, patrick@ for helping adapt rockchip drm and many developers for
testing.


Revision tags: OPENBSD_6_7_BASE
# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.58 15-Mar-2020 claudio

kthread_park() and kthread_stop() don't need PCATCH the linux API does
not interrupt either and not checking the return value of tsleep_nsec()
could actually result in a infinite loop if a signal is pending.
Remove PCATCH also from kthread_parkme() for the same reason but this
function is only called for kthreads and those have no signals anyway.
OK kettenis@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.57 06-Mar-2020 kettenis

Release mutex before calling sleep_setup_signal() since this may stop
the process.

ok bluhm@, jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.56 16-Jan-2020 mpi

Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.

This moves most of the SCHED_LOCK() related to protecting the sleepqueue
and its states to kern/kern_sync.c

Name suggestion from jsg@, ok kettenis@, visa@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.55 05-Jan-2020 visa

Constify instances of struct fileops.

OK anton@, mpi@, bluhm@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.54 30-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.53 26-Dec-2019 jsg

implement unregister_shrinker()

ok kettenis@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.52 25-Dec-2019 kettenis

Hook up the shrinker for inteldrm(4). This is a "light" version that only
drops graphics buffers that are cached and not in active use.
Help from beck@ for pointing out how to hook this up to our pagedaemon.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.51 30-Nov-2019 visa

Move kernel locking inside the sleep machinery. This enables calling
rwsleep(9) with PCATCH and rw_enter(9) with RW_INTR without the kernel
lock. In addition, now tsleep(9) with PCATCH should be safe to use
without the kernel lock if the sleep is purely time-based.

Tested by anton@, cheloha@, chris@
OK anton@, cheloha@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.50 23-Oct-2019 jsg

Use baseboard specific vendor, product and serial strings for DMI_BOARD_*
instead of using hw_vendor and hw_prod which are set from the
system information structure possibly falling back to baseboard structure.
Remove currently unused DMI_BOARD_VERSION case.

Should fix the GPD Pocket panel rotation quirk that depends on baseboard
vendor of 'AMI Corporation' while the system information vendor is
'Default string'. Reported by Alexander Shendi on bugs@.


Revision tags: OPENBSD_6_6_BASE
# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.49 27-Aug-2019 kettenis

Error paths in radeondrm(4) call unregister_acpi_notifier() unconditionally
so check whether a notifier is on the list before trying to remove it.
Fixes a crash found by semarie@.

ok semarie@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.48 18-Aug-2019 kettenis

Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.47 05-Aug-2019 anton

Allow concurrent reads of the f_offset field of struct file by
serializing both read/write operations using the existing file mutex.
The vnode lock still grants exclusive write access to the offset; the
mutex is only used to make the actual write atomic and prevent any
concurrent reader from observing intermediate values.

ok mpi@ visa@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.46 15-Jul-2019 jsg

put smbios date access under NBIOS > 0 instead of CONFIG_DMI


# 1.45 15-Jul-2019 jsg

Add dmi functions used by drm_panel_orientation_quirks.c and enable
CONFIG_DMI path.

ok mlarkin@ kettenis@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.44 12-Jul-2019 solene

Revert anton@ changes about read/write unlocking
https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2

ok anton@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.43 10-Jul-2019 anton

Make read/write of the f_offset field belonging to struct file MP-safe;
as part of the effort to unlock the kernel. Instead of relying on the
vnode lock, introduce a dedicated lock per file. Exclusive write access
is granted using the new foffset_enter and foffset_leave API. A
convenience function foffset_get is also available for threads that only
need to read the current offset.

The lock acquisition order in vn_write has been changed to match the one
in vn_read in order to avoid a potential deadlock. This change also gets
rid of a documented race in vn_read().

Inspired by the FreeBSD implementation.

With help and ok mpi@ visa@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.42 10-Jul-2019 kettenis

Implement Linux kthread interfaces.

ok jsg@


# 1.41 09-Jul-2019 jsg

Use wake_up_process() instead of wakeup() in dma_fence_default_wait_cb()
as there is code which uses schedule_timeout() for dma fences.

suggested by kettenis@


# 1.40 09-Jul-2019 jsg

add dma_fence_wait_any_timeout() required for parts of amdgpu
ok kettenis@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.39 05-Jul-2019 kettenis

Use multi-threaded task queues to prevent deadlocks in the case where a
tasks sleeps and expects to be woken up by a task that will be submitted
to the same task queue. That scenario happens in the output hotplug code.

We probably should spend some time on tuning the number of threads but
let's make things work correctly first.

Based on some serious debugging done by Sven M. Hallberg.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.38 09-Jun-2019 kettenis

Let drm(4) allocate memory without constraints if the hardware supports
64-bit DMA. Should reduce the pressure on DMA-reachable memory, which is
important since there are still cases where the pagedaemon ends up being
triggered continuously if we run out of DMA-reachable memory but have
plenty of memory left.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.37 04-Jun-2019 jsg

Move a function used as a callback out of a header so there will only be
one function with a single address.


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.36 11-May-2019 jsg

implement dma_fence_array


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.35 10-May-2019 kettenis

Fix idr_get_next() such that idr_for_each_entry() actually works.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.34 23-Apr-2019 jsg

Linux code expects to find struct file in fs.h so include sys/file.h
there. As sys/file.h does not have an include guard don't include it in
drm_linux.c which indirectly includes fs.h via drmP.h.


# 1.33 14-Apr-2019 jsg

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.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.32 11-Sep-2018 kettenis

Only look for acpi tables if acpi(4) attached. Fixes radeondrm(4) crash
on arm64 when using a device tree.


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.31 25-Aug-2018 kettenis

Use __HAVE_ACPI to decide whether ACPI support should be considered.

ok deraadt@, krw@, jca@


# 1.30 20-Aug-2018 mpi

Reorder checks in the read/write(2) family of syscalls to prepare making
file operations mp-safe.

This change makes it clear that `f_offset' is only accessed in vn_read()
and vn_write(), which will help taking it out of the KERNEL_LOCK().

This refactoring uncovered a race in vn_read() which is now documented
and will be addressed in a later diff.

ok visa@


# 1.29 20-Aug-2018 visa

Make fnew() return a new file with only one reference. This makes
the API more logical.

OK kettenis@ mpi@


# 1.28 15-Aug-2018 visa

Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This prevents
a scenario where MP-unsafe code gets run without the kernel lock
as a consequence of an unlocked system call.

OK mpi@, kettenis@


# 1.27 12-Aug-2018 kettenis

Drop reference to dmabuf "file" as fnew() returns one that has two
references.

ok visa@, deraadt@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.26 03-Jul-2018 kettenis

Add a new so_seek member to "struct file" such that we can have seekable
files that aren't vnodes. Move the vnode-specific code into its own
function. Add an implementation for the "DMA buffers" that can be used
by DRI3/prime code to find out the size of the graphics buffer.
This implementation is very limited and only supports offset 0 and only
for SEEK_SET and SEEK_END. This doesn't really make sense; implementing
stat(2) would be a more obvious choice. But this is what Linux does.

ok guenther@, visa@


# 1.25 01-Jul-2018 kettenis

Use fnew() to allocate a struct file. Simplifies the code.

ok mpi@, visa@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.24 25-Jun-2018 kettenis

Implement DRI3/prime support. This allows graphics buffers to be passed
between processes using file descriptors. This provides an alternative to
eporting them with guesable 32-bit IDs. This implementation does not (yet)
allow sharing of graphics buffers between GPUs.

ok mpi@, visa@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.23 25-Apr-2018 jsg

update ttm and radeondrm(4) to Linux 4.4.129

Compared to the previous Linux 3.8 based port this adds support for
KAVERI/KABINI/MULLINS APUs and OLAND/BONAIRE/HAINAN/HAWAII GPUs.

Thanks to the OpenBSD Foundation for sponsoring this work.


# 1.22 20-Apr-2018 deraadt

oops, snapshot tests not ready yet


# 1.21 20-Apr-2018 deraadt

sync


Revision tags: OPENBSD_6_3_BASE
# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.20 31-Jan-2018 jsg

add dmi_match() and change dmi_found() to use it


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.19 30-Jan-2018 jsg

add i2c_bit_add_bus()


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@


# 1.18 15-Jan-2018 kettenis

Switch the inteldrm(4) i2c code over to the Linux code base. This gives us
several quirks that wre absent in the old OpenBSD-specific reimplementation.
Fixes several issues with external connectors on several generations of
hardware.

ok deraadt@, benno@


# 1.17 13-Jan-2018 robert

add kqueue support to drm(4) by making the drm_sysfs_hotplug_event()
available on OpenBSD well and by notifying listeners of a device
state change using EVFILT_DEVICE and NOTE_CHANGE.

drm_sysfs_hotplug_event() gets called when a state change of the device
occured, like an hdmi cable has been plugged, this in the future will
be used by the modesetting xorg driver to notify desktop environments
via randr events to update their screen configuration

ok kettenis@


# 1.16 12-Jan-2018 jsg

Constrain alloc_pages() to the dma_constraint range. Avoids a
"Non dma-reachable buffer" panic when trying to use it from ttm code on
a machine with 8GB of physmem and a radeon.

ok kettenis@ dlg@ visa@ deraadt@


Revision tags: OPENBSD_6_2_BASE
# 1.15 12-Jul-2017 kettenis

Add a "Backlight" property to connectors with an associated backlight
controller for the inteldrm(4) driver. If wscons(4) provides backlight
control, prefer ir over raw hardware control and attach it to LVDS, eDP
and DSI connectors which are the connector types typically connected to
laptop screens.


# 1.14 05-Jul-2017 kettenis

Fix native/raw backlight support in inteldrm(4).


# 1.13 01-Jul-2017 kettenis

Update inteldrm(4) to code based on Linux 4.4.70. This brings us support for
Skylake and Cherryview and better support for Broadwell and Valleyview. Also
adds MST support. Some tweaks to the TTM code and radeondrm(4) to keep it
working with the updated generic DRM code needed for inteldrm(4).

Tested by many.


Revision tags: OPENBSD_6_1_BASE
# 1.12 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.11 07-Apr-2016 kettenis

Return -ENOSPC if idr_alloc() fails to allocate an unused id instead of
spinning forever.


# 1.10 05-Apr-2016 kettenis

Add an implementation of the Linux "idr" API.


# 1.9 05-Apr-2016 kettenis

Split out the generic GEM code (like Linux did) and switch it over to
the vma offset manager. This brings us a little bit more isolation between
applications as GEM buffers are now tied to a specific /dev/drmX clone.

ok jsg@


Revision tags: OPENBSD_5_9_BASE
# 1.8 05-Feb-2016 kettenis

Implement acpi_get_table_with_size(). Will soon be used to read VFCT
tables in radeondrm(4).


# 1.7 01-Jan-2016 kettenis

Reimplement vga_put() such that it compiles on i386 as well.


# 1.6 31-Dec-2015 kettenis

Provide a minimal implementation of the Linux vga_get/vga_put API and use it
in inteldrm(4).

The Intel integrated graphics device has a major design flaw where it needs
legacy VGA io access to disable VGA mode completely. This only works if
legacy VGA io routing is setup such that it actually reaches the IGD. This
typically isn't the case if the primary VGA device is a discrete graphics
device. To make sure we don't whack that device we have to temporarily
route legacy VGA io access to the IGD.

Fixes the "black screen" issue reported by Timo Myrra and others.


# 1.5 26-Sep-2015 kettenis

Make the PPGTT code work. Seems to fix the caching issues on Broadwell.
Comments on some of the later Broadwell-related commits in the Linux tree
seem to say that the PPAT flags in for the (global) GTT are simply broken in
the hardware.


Revision tags: OPENBSD_5_8_BASE
# 1.4 08-Apr-2015 jsg

Move vmap back to kernel_map/uvm_km_valloc as it's allowed to fail.
This should help dlg's dell 2950 that gets stuck during boot with vmap
in the trace.

ok kettenis@


# 1.3 08-Apr-2015 jsg

ttm has it's own version of kmap/kunmap that uses
kernel_map/uvm_km_valloc and i915 has a version that uses
phys_map/uvm_km_valloc_wait as calling code assumes kmap would
sleep if no memory is available.

Move these and ttm's vmap/vunmap into the linux compat files
and make them all use phys_map/uvm_km_valloc_wait.

looks good kettenis@


# 1.2 06-Apr-2015 jsg

move some inline linux compat into the dedicated files


# 1.1 05-Apr-2015 kettenis

Another round of reducing diffs with Linux. This one moves the various
copy_to_user and copy_from_user functions into drm_linux.h and uses them
instead of copyin/copyout and DRM_COPY_*. Also move the timespec functions,
and put i915_gem_object_is_purgable() where it belongs.

Uncovered a bug where the arguments to copyout() were in the wrong order.

ok jsg@