Add bcd2bin() in bcd.h.
Libkern does provide a bcd2bin() which cannot be used cirectly leaving
us with a conflict (see comment in file).
Rather than having code to re-define bcd2bin() for the LinuxKPI
make sure libkern.h is always included before the LinuxKPI version.
Then only re-define our local LinuxKPI implementation. [1]
From the argument truncating wrapper call the libkern version.
If we change our libkern implementation in the future we can save
us the remainder of the hassle. [2].
Suggested by: Johannes Berg (johannes sipsolutions.net) [1]
Suggested by: ian [2]
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 548ada00e5)
(cherry picked from commit ae2268efd5)
Analogous to the other sized version of kstrto[u]<type>() and
kstrtobool_from_user() add the "u8" versions needed by a driver.
(cherry picked from commit b382b78503)
Add a dummy simple_open() to fs.h as we have for other
(unsupported) functions.
This is needed by a wireless driver.
(cherry picked from commit 41dee251ee)
Add a dummy MODULE_SUPPORTED_DEVICE define as we do for other
MODULE_* macros. This is needed by a wireless driver.
(cherry picked from commit c5eec7b57c)
Make the struct pci_dev argument to the pci_{read,write}_config*()
functions "const" to match the Linux definition as some drivers
try to pass in a const argument which we currently fail to honor.
Sponsored by: The FreeBSD Foundation
(cherry picked from commit ed5600f532)
Rename the struct pci_driver {} field to the list_head from links
to node as a driver is actually initialsing this to {} which seems
questionable but it will at least make us match the Linux structure
field name.
Reviewed by: manu, hselasky
(cherry picked from commit cf89934842)
Add netdev_features.h as a spearate file from the future netdevice.h
implementation to avoid include problems with a future skbuff.h.
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 490f9d8f0e)
Coherent is lower 32bit only by default in Linux and our only default
dma mask is 64bit currently which violates expectations unless
dma_set_coherent_mask() was called explicitly with a different mask.
Implement coherent by creating a second tag, and storing the tags in the
objects and use the tag from the object wherever possible.
This currently does not update the scatterlist or pool (both could be
converted but S/G cannot be MFCed as easily).
There is a 2nd change embedded in the updated logic of
linux_dma_alloc_coherent() to always zero the allocation as
otherwise some drivers get cranky on uninialised garbage.
Sponsored by: The FreeBSD Foundation
(cherry picked from commit c39eefe715)
(cherry picked from commit 1269873159)
In some places we are using "mask" and others "dma_mask" for the
same thing. Harmonize the various places to "dma_mask" as used in
linux_pci.c. For the declaration remove the argument names to
avoid the entire problem.
This is in preparation for an upcoming change.
No functional changes intended.
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 72c89ce97b)
As reported by multiple people testing iwlwifi, device_release_driver()
can lead to a panic on secondary errors (usually during attach).
Disable device_release_driver() for the short-term to prevent the panic
but leave it in place so it can be re-worked and fixed properly for
the long-term more easily.
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 93b14194ac)
Add fsleep() function now required by rtw88. This seems to be
making a decision depending on time to sleep on how to sleep.
Given our compat framework already is lenient on how long to sleep,
this is a cut down version.
(cherry picked from commit cc2723370b)
Add an implementation of read_poll_timeout() and the atomic variant
which I did at some point last year for rtw88 and now updated based
on feedback.
(cherry picked from commit fed248a6ac)
Add the two new functions needed by rtw88 to register the driver and
handle the module bits as well as a version of pci_alloc_irq_vectors()
for what is needed.
(cherry picked from commit 366d68f283)
Fix a bug that slipped in in 90707c4e44
using the correct field in le32p_replace_bits().
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 22e20d852f)
Add sys/types.h to dmi.h and do not rely on other files to include
all needed headers in Linux land. I ran into compile problems with
rtw88 otherwise.
(cherry picked from commit ac134e762e)
The purpose of this change is to reduce the amount of dmesg(8) noise when
VT switching after a panic.
Submitted by: Greg V <greg@unrelenting.technology>
Differential Revision: https://reviews.freebsd.org/D30174
Sponsored by: NVIDIA Networking
(cherry picked from commit 2390a1441e)
Linux KPIs like pci_resource_start/len assume that BARs have been
allocated, but FreeBSD lazily allocates BARs if it cannot allocate the
firmware-allocated BARs. Thus using the Linux KPIs must force allocation
of the BARs rather than returning 0 for the start and length, which can
crash drm-kmod drivers that assume the BARs are valid. This is needed
for the AMDGPU driver to be able to attach on SiFive's HiFive Unmatched.
Reviewed by: hselasky, jhb, mav
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D32447
(cherry picked from commit 82098c8bb5)
Now that riscv implements pmap_mapdev_attr we can enable the non-stub
implementation for riscv, which is needed for drm-kmod to not fail at
run time for drivers that need to map I/O regions.
Reviewed by: hselasky, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D32446
(cherry picked from commit 60d962e041)
For now, disable backlight if brightness level is set to 0.
In the future we may implement separate knob in backlight(8).
Required by drm-kmod v5.6
Reviewed by: hselasky, manu
Differential revision: https://reviews.freebsd.org/D32165
(cherry picked from commit b52e363840)
Although drm-kmod contains better implementation which is able to
allocate real entries on pseudofs, this feature has never been used.
Starting from drm-kmod v5.6 old implementation began to leak entries
on each drm device close(). Now just drop pseudofs support instead of
fixing it in drm-kmod and provide stub in base.
Reviewed by: hselasky, manu
Differential revision: https://reviews.freebsd.org/D32069
(cherry picked from commit bd6d55adb4)
from GEM and TTM page fault handlers and move it in to base system. This
code is tightly integrated with LKPI mmap support to belong to drm-kmod.
As this routine requires associated vm_object to be locked, it got
additional _locked suffix.
Reviewed by: hselasky, markj
Differential revision: https://reviews.freebsd.org/D32068
(cherry picked from commit f6823dac8f)
except linux/pci.h to avoid conflicts with Linux version.
This allows to #define resource in drm-kmod globally and strip some #ifdef-s
Reviewed by: hselasky, manu
Differential revision: https://reviews.freebsd.org/D31673
(cherry picked from commit 66ea390652)
get_file_rcu() grabs a file if the file->f_count is not zero.
Required by drm-kmod 5.6
Reviewed by: hselasky, manu (previous version)
Differential revision: https://reviews.freebsd.org/D31672
(cherry picked from commit a81b36c6d3)
One of the three uses is already guarded; this guards the remaining ones
to support architectures like riscv that do not provide write-combining,
and is needed to build drm-kmod on riscv.
Reviewed by: hselasky, manu
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D31999
(cherry picked from commit 8167c92f65)
Move all the new elemenets to the end of the structure for 13. We
allocate this inside the linuxkpi code, so the size isn't enccoded in
client modules. However, the offsets to the different fields are
encoded. Tihs modifies 04456f7118, 40a215e38a, and 3a606aadf2
and will likely create merge conflicts there (and that's a good thing
since the elements need to be moved to the end of the structure when
merging).
Tweak irq_ent to be binary compatible. Since this is inlined into the
clients, all clients have to agree on the irq_ent offsets.
Restore visibility to linux_kmem_cache_free_rcu
linux_kmem_cache_free_rcu was made static in 10235ad056, however
client drivers depended on calling it directly. Make it visible again to
restore the 13.0-Release KBI for linuxkpi.
Bump FreeBSD_version to 1300515 for restoration of 13.0 KBI. Since this
commmit changes the linuxkpi KBI (this time back to 13.0 release to
restore the status quo of), you'll need to recompile everything that
uses it (you needed to earlier as well, but those were silent
recompilation events). The plus side is that our packages (built using
13.0) for drm-kmod 5.4 work again on -stable systems.
Reviewed by: bz, wulf
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D31363
as a thin wrapper around native version found in sys/seqc.h.
This replaces out-of-base GPLv2-licensed code used by drm-kmod.
Reviewed by: hselasky
Differential revision: https://reviews.freebsd.org/D31006
(cherry picked from commit 8b33cb8303)
strscpy copies the src string, or as much of it as fits, into the dst
buffer. The dst buffer is always NUL terminated, unless it's zero-sized.
strscpy returns the number of characters copied (not including the
trailing NUL) or -E2BIG if len is 0 or src was truncated.
Currently drm-kmod replaces strscpy with strncpy that is not quite
correct as strncpy does not NUL-terminate truncated strings and returns
different values on exit.
Reviewed by: hselasky, imp, manu
Differential revision: https://reviews.freebsd.org/D31005
(cherry picked from commit 019391bf85)
This allows to remove unimplemented attrs parameter which type differs
between Linux kernel versions and to compile both drm-kmod and ofed
callers unmodified.
Also convert it to 'unsigned long' type to match modern Linuxes.
Reviewed by: hselasky
Differential revision: https://reviews.freebsd.org/D30932
(cherry picked from commit 98a6984a9e)
so this list-traversal primitive may safely run concurrently with the
_rcu list-mutation primitives such as list_add_rcu() as long as the
traversal is guarded by rcu_read_lock().
Do it by reusing the "list_for_each_entry_rcu" macro which does the same.
On Linux it implements some additional lockdep stuff which we skip.
Also move the macro to linux/rculist.h where it resides on Linux.
Reviewed by: hselasky
Differential revision: https://reviews.freebsd.org/D30795
(cherry picked from commit c0862b2b1f)
as it is required by i915kms driver from Linux kernel v 5.5.
This is done with asynchronous freeing of requested memory areas from
taskqueue thread. As memory to be freed is reused to store linked list
entry, backing UMA zone item size is rounded up to pointer size.
While here, make struct linux_kmem_cache private to LKPI to reduce amount
of BSD headers included by linux/slab.h and switch RCU code to usage of
LKPI's linux_irq_work_tq taskqueue to avoid injection of current into
system-wide taskqueue_fast thread context.
Submitted by: nc (initial version for drm-kmod)
Reviewed by: manu, nc
Differential revision: https://reviews.freebsd.org/D30760
(cherry picked from commit a2b83b59db)
Some code manually calls local_bh_disable() and spin_lock() but
then calls spin_unlock_bh() (or vice versa).
Our code then calls local_bh_disable() again from spin_lock()
which means we have the thread pin count increased twice and that
means we get out of synch and are still pinned when returning to
user space.
Avoid this by adding the explicit local_bh_{enable,disable}() to
the spin_[un]lock_bh() versions.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30711
(cherry picked from commit 46ae23a402)
In sg_pcopy_from_buffer() is an error in that skip can underflow
and lead to bogus page arithmetics which may lead to memory corruption
or more likely panics. Once we found a s/g page to copy into there
is nothing to skip anymore so simply set skip to 0.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30676
(cherry picked from commit edfcdffefc)
Restructure some code and add support for various "managed" versions
for PCI resource management.
This is beyond of what iwlwifi needs but some was found with other
wireless drivers and it mostly all goes together.
Add one FreeBSD sepcific feature returning the resource rather than
the handle to allow us to use bus_*() functions in drivers directly.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30558
(cherry picked from commit d4a4960c65)
(cherry picked from commit 5f88df77a6)
(cherry picked from commit 539228d372)
Move request_irq() to an internal function which serves request_irq()
and the newly added request_threaded_irq() and devm_request_threaded_irq().
Likewise factor out parts of free_irq() to also be used with
devm_free_irq(). Add the storage and call to a thread_handler in case
of IRQ_WAKE_THREAD.
This is needed for the iwlwifi driver.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30549
(cherry picked from commit d16b6cb178)
Add dummy functions for dealing with "HotPlug" events which we currently
do not support.
Add pci_dev_get(), pci_find_ext_capability() and pci_pme_capable().
The added pcie_find_root_port() is a bit special as we need to create
another linux pci device; for that make lkpinew_pci_dev() public
which is also helpful for other cases when we want to use the Linux
routines to check for device identifiers only and need a container
for the "bsddev" to use natively. This has proven to avoid basic
checking code for the sake of rewriting it to native field names
elsewhere. Given we cache the newly created "root" we also need to
make sure we clean it up.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30521
(cherry picked from commit 8e106c5230)
dmam_pool_create() is a "managed" version of dma_pool_create() which
will cleanup everything left when the device goes away using the
devres framework. For that add an internal cleanup function to be
called from devres release.
This is used by at least one wireless driver.
Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D30520
(cherry picked from commit 2afeed13b5)
Add two new (though untested) functions to linux/device.h which are
dealing with manually managing the device/driver and are used by
at least one wireless driver. We may have to re-fine them in the
future.
Move the devres declarations further up so they can be used earlier
in the file.
Sponsored by: The FreeBSD Foundation
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D30519
(cherry picked from commit 644b4f1176)