Commit graph

617 commits

Author SHA1 Message Date
Bjoern A. Zeeb
111619ff70 LinuxKPI: add bcd.h
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)
2021-11-21 18:15:58 +00:00
Bjoern A. Zeeb
9d2d8a27d0 LinuxKPI: add strreplace() to string.h
Add strreplace() needed by a driver.

(cherry picked from commit a5e2a27dca)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
4459c16279 LinuxKPI: add kstrtou8() and kstrtou8_from_user() to kernel.h
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)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
a6a1ab040f LinuxKPI: add simple_open() to fs.h
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)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
009e6b6e71 LinuxKPI: module.h add MODULE_SUPPORTED_DEVICE()
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)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
c7fc9ca779 LinuxKPI: pci.h make pci_dev argument const for pci_{read,write}_config*()
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)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
dc70c937b1 LinuxKPI: pci.h / linux_pci.c rename pci_driver field
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)
2021-11-19 00:01:26 +00:00
Bjoern A. Zeeb
aaf3364151 LinuxKPI: add netdev_features.h
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)
2021-11-19 00:01:25 +00:00
Bjoern A. Zeeb
37b2cf4e6a LinuxKPI: implement dma_set_coherent_mask()
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)
2021-11-19 00:01:24 +00:00
Bjoern A. Zeeb
d005c4c6de LinuxKPI: dma-mapping.h unify "mask" and "dma_mask"
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)
2021-11-19 00:01:24 +00:00
Bjoern A. Zeeb
870e31d839 LinuxKPI: disable device_release_driver()
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)
2021-11-19 00:01:24 +00:00
Bjoern A. Zeeb
20c9dcd2ed LinuxKPI: add fsleep()
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)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
9342ec5077 LinuxKPI: add read_poll_timeout()
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)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
4c8e296374 LinuxKPI: add module_pci_driver() and pci_alloc_irq_vectors()
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)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
034475d66c LinuxKPI: add sign_extend32()
Add sign_extend32() replicating the 64 version.  This is needed by
the rtw88 driver.

(cherry picked from commit ea4dea8394)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
3ce981ee8e LinuxKPI: fix bug in le32p_replace_bits()
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)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
2314243b4a LinuxKPI: bitfield.h cleanup
Add a missing tab and remove an unnecessary return.
No functional changes.

(cherry picked from commit 4c8af633d1)
2021-11-19 00:01:23 +00:00
Bjoern A. Zeeb
e41baaefc4 LinuxKPI: dmi.h do not rely on implicit includes
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)
2021-11-19 00:01:22 +00:00
Hans Petter Selasky
8ababf739a LinuxKPI: Add sysctl(8) knob to control verbosity of WARN_ON's.
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)
2021-11-12 15:31:24 +01:00
Jessica Clarke
fa82e6a103 LinuxKPI: Support lazy BAR allocation
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)
2021-10-24 19:51:15 +01:00
Jessica Clarke
feb3031f0a LinuxKPI: Implement _ioremap_attr for riscv
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)
2021-10-24 19:51:12 +01:00
Vladimir Kondratyev
e1f5bed753 LinuxKPI: Import linux_page.c and some dependent code from drm-kmod
No functional changes intended

Reviewed by:	hselasky, manu, markj
Differential revision:  https://reviews.freebsd.org/D32167

(cherry picked from commit c072f6e856)
2021-10-13 12:07:53 +03:00
Vladimir Kondratyev
c6fb23b292 LinuxKPI: Update pte_fn_t definition to match Linux 5.3
Reviewed by:	emaste, hselasky, manu
Differential revision:	https://reviews.freebsd.org/D32166

(cherry picked from commit 88531adbfb)
2021-10-13 12:07:24 +03:00
Vladimir Kondratyev
9441d948aa LinuxKPI: Implement backlight_enable and backlight_disable functions
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)
2021-10-13 12:06:51 +03:00
Vladimir Kondratyev
8cf87dd59f LinuxKPI: Cast offset_in_page() parameter to unsigned long
to reduce number of patches in drm-kmod

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D32093

(cherry picked from commit 37eba5b77a)
2021-10-13 12:04:58 +03:00
Vladimir Kondratyev
0ed3a19a38 LinuxKPI: Import linux/poison.h header
Required by drm-kmod 5.6

Reviewed by:	hselasky, imp, manu
Obtained from:	OpenBSD
Differential revision:	https://reviews.freebsd.org/D32092

(cherry picked from commit 6efabdeede)
2021-10-13 12:04:11 +03:00
Vladimir Kondratyev
7db428f0bb LinuxKPI: Add helper functions to store integers to linux/xarray.h
Required by drm-kmod.

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D32091

(cherry picked from commit b59ffedae8)
2021-10-13 12:03:29 +03:00
Vladimir Kondratyev
4fba1853b5 LinuxKPI: stub anon_inode_getfile
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)
2021-10-13 12:02:17 +03:00
Vladimir Kondratyev
847ffc18dd LinuxKPI: Factor out vmf_insert_pfn_prot() routine
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)
2021-10-13 12:01:32 +03:00
Vladimir Kondratyev
2c26756366 LinuxKPI: implement _IOC_TYPE and _IOC_NR macros in linux/ioctl.h
They are used by drm-kmod

Reviewed by:	emaste, hselasky, manu
Differential revision:	https://reviews.freebsd.org/D31674

(cherry picked from commit b58c916f11)
2021-10-13 11:59:25 +03:00
Vladimir Kondratyev
fd6adf784e LinuxKPI: Remove FreeBSD struct resource from all LKPI headers
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)
2021-10-13 11:58:39 +03:00
Vladimir Kondratyev
a029968046 LinuxKPI: Implement get_file_rcu()
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)
2021-10-13 11:57:46 +03:00
Jessica Clarke
e79989d823 LinuxKPI: Add more #ifdef VM_MEMATTR_WRITE_COMBINING guards
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)
2021-10-10 14:36:53 +01:00
Warner Losh
0437d10e35 direct commit: fix KBI for pci_dev
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
2021-09-22 09:00:16 -06:00
Vladimir Kondratyev
801a4bcab6 LinuxKPI: Implement sequence counters and sequential locks
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)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
22310af02d LinuxKPI: Implement strscpy
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)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
80b8638e12 LinuxKPI: Use macro for implementation of some dma_map_* functions
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)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
907f980064 LinuxKPI: Implement irq_work_sync() routine.
irq_work_sync() performs draining of irq_work task.
Required by drm-kmod.

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D30818

(cherry picked from commit 864b11007a)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
ddebb8c0f7 LinuxKPI: Add compiler barriers to list_for_each_entry_lockless macro
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)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
71d815861f LinuxKPI: Change flags parameter type of atomic_dec_and_lock_irqsave
On Linux atomic_dec_and_lock_irqsave is a wrapper macro which provides
a reference to third parameter rather than parameter value itself to
implementation routine called _atomic_dec_and_lock_irqsave [1].

While here, implement a fast path.

[1] https://github.com/torvalds/linux/blob/master/include/linux/spinlock.h#L476

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D30781

(cherry picked from commit c77ec79b57)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
6279188417 LinuxKPI: Add #defines required by drm-kmod v5.5
Reviewed by:	hselasky, manu
Differential revision:	https://reviews.freebsd.org/D30767

(cherry picked from commit 78a02d8b33)
2021-07-21 01:43:52 +03:00
Vladimir Kondratyev
10235ad056 LinuxKPI: Allow kmem_cache_free() to be called from critical sections
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)
2021-07-21 01:43:52 +03:00
Neel Chauhan
511bbe502e linuxkpi: Add spin_trylock_irqsave() macro
This is needed by the drm-kmod 5.6 update.

Reviewed by:		hselasky
Differential Revision:	https://reviews.freebsd.org/D30706

(cherry picked from commit 086cfe4df8)
2021-07-17 18:08:06 -07:00
Bjoern A. Zeeb
f9fa2908cf LinuxKPI: avoid userret: Returning with with pinned thread
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)
2021-07-18 00:35:04 +00:00
Bjoern A. Zeeb
d2c8c4d15a LinuxKPI: fix sg_pcopy_from_buffer()
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)
2021-07-18 00:35:04 +00:00
Bjoern A. Zeeb
3a606aadf2 LinuxKPI: pci: cleanup some code and add support for "pcim" (managed)
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)
2021-07-18 00:35:04 +00:00
Bjoern A. Zeeb
1eaaada457 LinuxKPI: enhance the irq KPI for managed and threaded operations.
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)
2021-07-18 00:35:03 +00:00
Bjoern A. Zeeb
40a215e38a LinuxKPI: extend pci.h by various functions for wireless driver
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)
2021-07-18 00:35:03 +00:00
Bjoern A. Zeeb
af13c69522 LinuxKPI: add dmam_pool_create() support
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)
2021-07-18 00:35:03 +00:00
Bjoern A. Zeeb
05cb0d21ed LinuxKPI: add device_reprobe() and device_release_driver()
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)
2021-07-18 00:35:03 +00:00