Commit graph

1448 commits

Author SHA1 Message Date
Dimitry Andric
4bdad53c24 Fix statement with no effect in linuxkpi's xarray.h
When compiling the kernel with gcc 14, errors similar to the following
are emitted:

  sys/dev/cxgbe/iw_cxgbe/ev.c: In function 'c4iw_ev_handler':
  sys/compat/linuxkpi/common/include/linux/xarray.h:132:23: error: statement with no effect [-Werror=unused-value]
    132 |                 flags == 0; \
  sys/dev/cxgbe/iw_cxgbe/ev.c:274:17: note: in expansion of macro 'xa_unlock_irqrestore'
    274 |                 xa_unlock_irqrestore(&dev->cqs, flag);
        |                 ^~~~~~~~~~~~~~~~~~~~
  sys/compat/linuxkpi/common/include/linux/xarray.h:132:23: error: statement with no effect [-Werror=unused-value]
    132 |                 flags == 0; \
  sys/dev/cxgbe/iw_cxgbe/ev.c:283:17: note: in expansion of macro 'xa_unlock_irqrestore'
    283 |                 xa_unlock_irqrestore(&dev->cqs, flag);
        |                 ^~~~~~~~~~~~~~~~~~~~

It looks like the intent of the "flags == 0" statement was to make the
'flags' macro argument not unused, but it still results in a warning.
Use the construct "(void)flags" instead.

Reviewed by:	bz
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D59787

(cherry picked from commit aca53fc2a6879f45dcbe1a60f91f14a5f6d48448)
2026-10-07 07:54:13 +02:00
Vladimir Kondratyev
54d909cf71 LinuxKPI: Add PCI_EXP_TYPE_UPSTREAM and PCI_VENDOR_ID_AMD defines
Required by drm-kmod v6.12.105

Reviewed by:	bz, emaste
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D59734

(cherry picked from commit 52d1a0c62be1b4bd8e78ee57c86288246d948046)
2026-09-23 12:01:17 +02:00
Vladimir Kondratyev
1dcd68d294 LinuxKPI: implement __UNIQUE_ID() macro
Requred by drm-kmod v6.12.103

Obtained from:	OpenBSD

Reviewed by:	bz, emaste
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D59733

(cherry picked from commit 8b05d84be9e288d201e8631750ae180b07311ba7)
2026-09-23 12:01:16 +02:00
David Heidelberg
c30fff2e2f Implement vmemdup_{array}_user
This is what FreeBSD now does for memdup_user and memdup_array_user
(which is wrong for memdup, but correct for vmemdup).

The amdgpu DRM driver started this in Linux ~6.12.86+

Reviewed by:	wulf
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D57444

(cherry picked from commit 302c6d25da6907ec762ff8937fa86d380743b000)
2026-09-23 12:01:16 +02:00
Jean-Sébastien Pédron
bfede84116 linuxkpi: Add 'fd_empty()`
The DRM drivers generic code started to use it in Linux 6.13.

Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57582

(cherry picked from commit 50aa145171bc88edde8cf3b7eb13dbbf88a3f8a7)
2026-09-23 12:01:16 +02:00
Jean-Sébastien Pédron
f4f829a812 linuxkpi: Define DEFINE_CLASS() and CLASS()
`DEFINE_CLASS()` is in fact named `LINUXKPI_DEFINE_CLASS()` because it
conflicts with `DEFINE_CLASS()` defined in <sys/kobj.h>.

This macro defines a type and a pair of constructor/destructor
functions.

They are to be used by `CLASS()`: this one declares a variable,
initialise it with the constructor and set the `__cleanup()` attribute
to call the destructor once the variable goes out of scope.

The DRM drivers generic code started to use `CLASS()` in Linux 6.13. It
requires the `fd` class to be defined in <linux/file.h>.

Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57583

(cherry picked from commit f2a2e02ae54b836d1e23648756a050406f65111e)
2026-09-23 12:01:16 +02:00
Bjoern A. Zeeb
0272713d4c LinuxKPI: add can_wakeup option and accessor functions
We can implement device_set_wakeup_capable() in the !CONFIG_PM_SLEEP
case;  we do not have the infrastructure in place for the CONFIG_PM_SLEEP
case so leave a pr_debug TODO.

Needed by an upcoming wireless driver.

Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D58883

(cherry picked from commit a424fb3519ebf8fb972e7ba45ba19df322992b00)
2026-09-23 12:01:16 +02:00
Bjoern A. Zeeb
9f97f2ee1f LinuxKPI: pci: add reset_{prepare,done} to pci_error_handlers
Needed by an upcoming wireless driver.

Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D58882

(cherry picked from commit c40219c572df8b4b0c2392ee341d93bc82e6076b)
2026-09-23 12:01:16 +02:00
Bjoern A. Zeeb
31a9f04dd7 LinuxKPI: add PCI_IRQ_AFFINITY #define
Add the #define for PCI_IRQ_AFFINITY and leave a pr_debug note in
pci_alloc_irq_vectors() that it is unimplemented.

The flag is needed by an upcoming WiFi driver.

Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D58881

(cherry picked from commit b589e403a2c3bd2a94fb2ab88cd23255c68a9f05)
2026-09-23 12:01:16 +02:00
Bjoern A. Zeeb
93bc6dd45b LinuxKPI: implement dma_{alloc,free}_{noncoherent,attrs}
We use one to implement the other given direction stays unused.

This is needed by an upcoming wifi driver.

Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D58880

(cherry picked from commit c3fa17a6a331db8aad03e9cb89ba97e1811ab381)
2026-09-23 12:01:15 +02:00
Bjoern A. Zeeb
4ea2b7d5b0 LinuxKPI: fix argument type to lkpi_pci_msi_desc_alloc()
lkpi_pci_msi_desc_alloc() takes an unsigned int, not an int.
While here make sure the prototype is visibile in interrupt.h as
well before use to avoid -Wimplicit-function-declaration errors.

Discovered while working on a wireless driver.

Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D58879

(cherry picked from commit cfb23b01e269e8a0a84066637b82b746f01b46b4)
2026-09-23 12:01:15 +02:00
Bjoern A. Zeeb
e4f4048f91 LinuxKPI: pci: add pci_select_bars() and pci_msix_vec_count()
For pci_select_bars() we use the LinuxKPI internal information, while
for pci_select_bars() we fall back to the native PCI stack.

Needed by a wifi driver.

Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D58878

(cherry picked from commit 55c07af60172b211116be47010fc0831aafc99e8)
2026-09-23 12:01:15 +02:00
Bjoern A. Zeeb
fbfd96523f LinuxKPI: add typedef for clockid_t
Needed by a wireless driver (not really using it) to compile.

Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D58877

(cherry picked from commit 401d0922a4bfcf40d3ae1866a0d90f955264def0)
2026-09-23 12:01:15 +02:00
Bjoern A. Zeeb
64a386ba0b LinuxKPI: add #include of rculist.h to ethtool.h for Linux conformance
Add #include rculist.h to ethtool.h to fullfill expectations of
Linux drivers without having to modify them.

Reviewed by:	dumbbell, emaste
Differential Revision: https://reviews.freebsd.org/D58874

(cherry picked from commit 4570a1bf760a3cd63eb7dd9e3ebbc3cf103bda4d)
2026-09-23 12:01:15 +02:00
Bjoern A. Zeeb
1f025320c8 LinuxKPI: rcu: add optional condition to list_for_each_entry_rcu()
list_for_each_entry_rcu() can take an optional condition.  Add the
macro argument so code remains compiling but do not do anything with
it just yet.

Leave comments as list_for_each_entry_rcu() likely should have a
different implementation.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D59292

(cherry picked from commit e975ce86ff11a330128f5b21c7cd11c28d3aff87)
2026-09-23 12:01:15 +02:00
Kevin Bowling
61272c8a2a pci: Expose PME support by power state
The presence of the PCI power management capability does not imply that
a function can signal PME# from every power state.  Drivers which
advertise wake based only on pci_has_pm() can consequently expose wake
modes that cannot work.

Add pci_has_pme() to query the PME_Support bitmap for a specific state.
Use it to implement LinuxKPI pci_pme_capable(), removing its duplicate
PME_Support decoder.

Validated the helper against PCI PMC capability values from 82571EB,
82573L, 82579LM, I210, I225, and I226-V controllers.  The 82571 and
82573 reported PMC 0xc822, while the I226-V reported 0xc823.  In both
values, bits 15, 14, and 11 advertise PME from D3cold, D3hot, and D0;
the low-bit difference is only the PM capability version.

Sponsored by:	BBOX.io

(cherry picked from commit c4e24e95c3f905b817d4bfc6e93457eb297bfa4b)
2026-09-23 12:01:02 +02:00
Zishun Yi
8b0236dcbd LinuxKPI: Correct nents passed to dma_{un,}map_sg_attrs()
According to Linux documentation the nents argument to dma_unmap_sg()
must be the number one passed in, not the number of DMA addresses.

In LinuxKPI this means orig_nents and not nents, so adjust this.

Given nents and orig_nents should always be the same in LinuxKPI,
this should only be a NOP for correctness.

Reviewed by:	bz, aokblast (LGTM)
Differential Revision: https://reviews.freebsd.org/D57842

(cherry picked from commit 33574d47d9dea317b9a4bfe543c4f20be6a565ef)
2026-09-23 11:55:50 +02:00
Zishun Yi
4b9dac45f6 LinuxKPI: implement dma_sync_sg_for_{cpu, device}()
Implement dma_sync_sg_for_{cpu, device}() and
dma_sync_sgtable_for_device().
These functions are useful for my GSoC 2026 project, udmabuf.

Reviewed by:	bz
Differential Revision: https://reviews.freebsd.org/D57766

(cherry picked from commit 9dec0cd79c693951fc58d82a99918fc5a02cbcd0)
2026-09-23 11:55:50 +02:00
Zishun Yi
847607c85f LinuxKPI: Fix DMA_BIDIRECTIONAL and other mappings
In dma_sync_single_for_cpu(), the DMA_BIDIRECTIONAL direction currently
performs BUS_DMASYNC_POSTREAD followed by BUS_DMASYNC_PREREAD. This
patch corrects the mapping to use BUS_DMASYNC_POSTREAD |
BUS_DMASYNC_POSTWRITE.

When ownership of the DMA area is transferred to the CPU, we must assume
the previous device access was bidirectional. Both POST operations are
necessary to ensure the CPU sees a consistent view of memory after
potential device reads and writes. A PREREAD is unnecessary here because
the device will no longer access the memory since ownership has been
transferred to the CPU.

Conversely, for dma_sync_single_for_device(), ownership is being
transferred back to the hardware. The buffer must be prepared for
potential bidirectional access by the device, requiring
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE.

PR:		293381, 297155
Reported by:    Zishun Yi <zishun.yi.dev@gmail.com>
Reported by:	Kim Shrier (fbsdbugs westryn.net)
Fixes:		95edb10b47 ("LinuxKPI: implement dma_sync_single_for_*, apply to (un)map single/sg")
Signed-off-by:  Zishun Yi <zishun.yi.dev@gmail.com>
Reviewed by:	aokblast, bz
Differential Revision: https://reviews.freebsd.org/D55497

(cherry picked from commit 6e1436d748273be52fb155914db3efae075a8619)
2026-09-23 11:55:50 +02:00
Bjoern A. Zeeb
134ccad5c4 LinuxKPI: 802.11: add more defines, structures, ...
Add more defines, structures, sort struct field types, add inline
functions (partially implemented) all needed for the upcoming
espwl(4) wireless driver.

(cherry picked from commit 9b13e6ce5b099af0958a824fa37c70538a8b6d2a)
2026-09-23 11:55:49 +02:00
Konstantin Belousov
5540145836 linuxkpi: stop inlining accesses to curthread->td_lkpi_task
(cherry picked from commit 6747bf7e223e5400af1c434618b14debd8dca0cf)
2026-09-23 11:55:49 +02:00
Bjoern A. Zeeb
889563e038 LinuxKPI: page.h: resort lines
Two of the "page macros" can be abstracted elsewhere in the upcoming
struct page work, so sort them away from the four which are here to
stay.

No functional change.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D58299

(cherry picked from commit 0b8d22019dcf708a8d047817963658783cd53c46)
2026-09-23 11:55:48 +02:00
Bjoern A. Zeeb
40754bcffb LinuxKPI: page.h: use atop() and ptoa() instead of PAGE_SHIFT
With upcoming changes to 'struct page' this will make the lines
easier to read by using the predefined macros from param.h.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	markj, kib
Differential Revision: https://reviews.freebsd.org/D58298

(cherry picked from commit f45506c6a6f4742cd5129d636902b61045c4754b)
2026-09-23 11:55:48 +02:00
Bjoern A. Zeeb
be0e8a3144 LinuxKPI: move clear_page() within the linux/page.h file
clear_page() would normally live in asm/page.h but adding the file
and fixing the dependencies would be too much for a single line.

Move the function to the end of the file with a clear separator
and make it clear that it does not operate on a 'struct page'
but on a page address by changing the argument name and leaving
a comment.

The function is currently used by at least mthca(4) as the only
in-tree consumer, and drm-kmod ttm_pool.c.

No functional changes.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D58296

(cherry picked from commit 0845efe88b355547b103dca90e69e46a3ebdd016)
2026-09-23 11:55:48 +02:00
Bjoern A. Zeeb
a0c646b0ec LinuxKPI: sg_page() remove superfluous ()
Sponsored by:	The FreeBSD Foundation
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D58295

(cherry picked from commit fe1784004d6e43b3080ab7b7115ee0ea3ba317f2)
2026-09-23 11:55:48 +02:00
Franco Fichtner
40b53042ce Revert "LinuxKPI: 802.11: add more defines, structures, ..."
This reverts commit fd73b91fe1.
2026-09-23 11:34:23 +02:00
Bjoern A. Zeeb
fd73b91fe1 LinuxKPI: 802.11: add more defines, structures, ...
Add more defines, structures, sort struct field types, add inline
functions (partially implemented) all needed for the upcoming
espwl(4) wireless driver.

(cherry picked from commit 9b13e6ce5b099af0958a824fa37c70538a8b6d2a)
2026-09-23 11:31:14 +02:00
Bjoern A. Zeeb
6a8496a4e6 LinuxKPI: scatterlist.h: implement sg_init_marker()
Add sg_init_marker() which is needed by mt76 drivers USB attachment.

Sponosored by:	The FreeBSD Foundation
Reviewed by:	emaste, dumbbell
Differential Revision: https://reviews.freebsd.org/D57594

(cherry picked from commit 3d0b6c69dced4936fccff6733912a0ef93214dbe)
2026-09-23 11:31:00 +02:00
Sourojeet A
5e137ec615 linuxkpi: Make pm_qos.h self-contained
Include <linux/types.h> for `false`.  This is needed by amdgpu somewhere
between Linux 6.12 and 6.15.

Reviewed by:	Minsoo Choo <minsoo@minsoo.io>, bz
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57415

(cherry picked from commit 67df313015906d84d90df8e37795885e81cf8da5)
2026-09-23 11:30:40 +02:00
John Baldwin
1e7a1849a5 sys: Use is_pci_device instead of direct comparisons to devclasses
Reviewed by:	bz
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D56997

(cherry picked from commit 6dc813301a173e2e1993c3064df162e6218c1231)
2026-09-23 11:30:15 +02:00
John Baldwin
09b76bc039 LinuxKPI: Check the devclass of the parent device in dev_is_pci
Reviewed by:	bz
Fixes:		c41d83548b ("LinuxKPI: pci.h add more defines and functions")
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D57066
(cherry picked from commit 6a043d0814a29e756f5d26e7b59a360e1d6dfa45)
2026-09-23 11:30:12 +02:00
Bjoern A. Zeeb
5c28edd624 LinuxKPI: add KERNEL_VERSION() macro
Add a KERNEL_VERSION() macro which normally would be in linux/version.h.
On Linux that file is auto-generated and we are supporting more than
one Linux version in LinuxKPI anyway so any further defines in there
would likely be wrong.

Adding the macro helps to support (vendor/out of tree) drivers more
easily which are supporting multiple Linux versions.

Reviewed by:	dumbbell
Differential Revision: https://reviews.freebsd.org/D57590

(cherry picked from commit c5d6e2085a471cbb75cc7b88b37a2fe6276c16f8)
2026-09-23 11:29:03 +02:00
Mitchell Horne
41297fcd71 linux/io: handle memtype_wc mapping for !DMAP range
The amdgpu driver in drm-kmod will attempt to update/reserve certain GPU
VRAM ranges as write-combining. Depending on the system, this address
range may fall outside of FreeBSD's constructed DMAP. We cannot use
pmap_change_attr() in this case.

When INVARIANTS is enabled, this results in the following:

  panic: physical address 0x880000000 not covered by the DMAP

Add a guard against triggering the KASSERT in PHYS_TO_DMAP().

This limitation in our implementation of arch_io_reserve_memtype_wc() is
already known in drm-kmod's amdgpu_bo_init(), and errors are ignored
there (see "BSDFIXME"). This change is only to eliminate the preventable
assertion failure within this scheme.

Tested by:	kevans
Reviewed by:	kib, emaste
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D56971

(cherry picked from commit 988c03980452a56fb0fbb15e18b0a644602d0ab3)
2026-09-23 11:28:35 +02:00
Hans Rosenfeld
993bdd5706 sys/cdefs.h: Introduce __maybe_unused attribute
The __maybe_unused attribute should be used for variables which may or
may not be used, such as when their only use is in an assertion. This
attribute is functionally identical to __unused, suppressing compiler
warnings for particular variable if it remains unused.

Reviewed by:	Minsoo Choo <minsoo@minsoo.io>, imp
Differential Revision:	https://reviews.freebsd.org/D56517

(cherry picked from commit 84a95741805d84f0074a34d61b93ccf86f422cf3)
2026-09-23 11:28:12 +02:00
Kyle Evans
816b72bd2f linuxkpi: work with numpages > 1 in the set_pages_*() KPIs
These calls are used for buddy pages at least in drm's ttm_pool, which
leads to a panic when we invoke lowmem handlers and drm tries to shrink
the pool.

Cope with numpages > 1 by traversing the contiguous pages and executing
the adjustment there, as well, as suggested by markj@.  Previous
versions have tried to use the corresponding `set_memory_*()` functions,
but it is believed that not updating `md.pat_mode` breaks subsequent
userspace mappings in ways that may result in things like screen tearing
or other artifacts when running i915kms.

This stabilized my amdgpu laptop running two VMs, chromium and a
concurrent buildworld.

Reviewed by:	bz, markj

(cherry picked from commit 67f7f2781daa9bd398b424ffe2bd0be67f37f03d)
(cherry picked from commit 8dad29555a5807bf21941807752e1589e20312de)
2026-09-23 11:26:47 +02:00
Bjoern A. Zeeb
640bc87f2d LinuxKPI: 802.11: add print masks for tx status flags
Add print masks for tx status flags and use them in the TX tracing
in order to more easily debug TX problems.

As a result it was easier to determine that some dirver like the mt7921
(or mt76) do not always zero the status bits of the tx status information
(it is a union with the control bits passed on TX) and thus we get bogus
values back (rather than having flags in a different place than we thought).

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 0cb3b9229876a2a83d217779cf5ecd09eb153fc3)
2026-09-23 11:25:14 +02:00
Bjoern A. Zeeb
a14e47668c LinuxKPI: skbuff: add initial page pool support
Add an internal flag which is set by skb_mark_for_recycle() and upon
"skb_free" then selects whether the skb is freed or returned to the
page pool.
There will likely be more details to figure out once the LinuxKPI page
work is done and we support more of the page pool than the bare minimum.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit e4795d3dbee71c463429e2901dad111fbc2d08fc)
2026-09-23 10:56:32 +02:00
Bjoern A. Zeeb
467e914b35 LinuxKPI: skbuff: implement __skb_linearize()
skb_linearize() is used by mt7921, mt7925, and in the general mt76 tx dma
code. __skb_linearize() is used in the general iwlwifi TX code but given
the way we currently create TX skbs in LinuxKPI 802.11 we never hit that
case.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 9de11cc26ab61d7f80e8af84dbc55d8cbd6f832d)
2026-09-23 10:56:00 +02:00
Bjoern A. Zeeb
842558b5ae LinuxKPI: skbuff: implement napi_build_skb()
Implement napi_build_skb() around linuxkpi_build_skb().

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit b36460e5ec4659d0fa14b35c9342c5a154b3db7d)
2026-09-23 10:55:47 +02:00
Bjoern A. Zeeb
c312822718 LinuxKPI: skbuff: add skb_put_zero()
Add skb_put_zero() as a simple wrapper around __skb_put_zero().

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 32c983449a7c802bf47578d5304c6d505db7821a)
2026-09-23 10:55:32 +02:00
Bjoern A. Zeeb
167b9010f9 LinuxKPI: skbuff: improve debugging
Deal with SKB_TRACE_FMT optional arguments; while here properly indent.

Add KASSERT to __skb_unlink() to catch incorrect skbuffs encountered
while debugging a wireless driver (which had other pre-conditions failing).

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit e5bcf7b99fcbe06d381525ffdd5027b846cdc1d3)
2026-09-23 10:55:21 +02:00
Bjoern A. Zeeb
879cb0bf77 LinuxKPI: add system_percpu_wq
In Linux v6.17 system_wq was replaced (renamed to) system_percpu_wq,
with the old name still present.

We just alias system_percpu_wq to linux_system_short_wq like we do
for system_wq to keep both around for the forseeable future.

Note: the original system_wq was a per-cpu queue upstream as well
based on my understanding but we never implemented it as such.
That means we are still lacking a per-cpu implementation for
system_percpu_wq but at least we do not change the status-quo
of the LinuxKPI implementation with this.

Note2: we should add a check somewhere for LINUXKPI_VESION >=
61700 to print a warning if anyone still uses the system_wq
to detect any possible sami-native or out-of-tree drivers
relying on this and not properly updating.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	dumbbell; emaste (comments on previous review)
Differential Revision: https://reviews.freebsd.org/D57730

(cherry picked from commit 058ce52660fb52ada41462d339fb1ce6aca48cf3)
2026-09-23 10:54:29 +02:00
Sourojeet A
f9406c9837 linuxkpi: Add pm_runtime_resume_and_get
pm_runtime_resume_and_get is used by new versions of amdgpu, and began
use between Linux kernel version 6.12, and 6.14.

Reviewed by:	dumbbell
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57463

(cherry picked from commit 7e1245aafeece1a56af292c2652c6b835ccb6f10)
2026-09-23 10:54:15 +02:00
Jean-Sébastien Pédron
123476ad84 linuxkpi: Implement module_*() APIs as static functions
This fixes an "unused variable" warning when building DRM drivers.

Approved by:	re (cperciva)
Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D56780

(cherry picked from commit 658bb99db9c7872f92ccb86ed2674c72636436d2)
(cherry picked from commit c81f516512111fa5ac8d5a9f3f7e64c2fb5ab5a3)
2026-05-07 10:24:52 -07:00
Jean-Sébastien Pédron
4a85d68009
sx: Add sx_has_waiters() macro
This macro will return non-zero if there are threads waiting for this
lock; otherwise, it will return zero.

The function assumes (but does not assert) that the caller already holds
the lock and that it is interested in other threads waiting for it to
release the lock.

The motivation to add this is the implementation of
`rwsem_is_contended()` in linuxkpi.

This Linux function indicates the same thing to the caller: if other
threads are waiting for this semaphore.

The amdgpu DRM driver started to use `rwsem_is_contended()` in Linux
6.12.

Reviewed by:	bz, olce
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit eebb643bb3799ae90dd248f0b5047ec481b26f68)
2026-04-30 20:07:13 +02:00
Jean-Sébastien Pédron
8da614f980
linuxkpi: Add copy_from_user_inatomic_nontemporal() function
In Linux 7.1, `__copy_from_user_inatomic_nocache()` was renamed to
`copy_from_user_inatomic_nontemporal()`. This change was backported to
several LTS branches.

This includes Linux 6.12.x and the i915 DRM driver started to use it in
that version.

Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 713b4ce8ef46d7df4ffe50ab6733bb128dbe3cbd)
2026-04-30 20:07:13 +02:00
Jean-Sébastien Pédron
bf671f422d
linuxkpi: Define DEFINE_XARRAY*() macros
The `DEFINE_XARRAY*()` macros are used to declare a static xarray.

As the structure embeds a mutex(9), we also need to declare the static
mutex after the `struct xarray`. Thus the slightly awkward definition
of `DEFINE_XARRAY_FLAGS()`.

The DRM generic code started to use `DEFINE_XARRAY_ALLOC()` in Linux
6.12.

Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 796fff59a5d32bc3be14feaeb228fc15ef43eb32)
2026-04-30 20:07:12 +02:00
Jean-Sébastien Pédron
56afbcce0a
linuxkpi: Add struct xa_limit support to xarray
The `xa_alloc*()` functions family takes a `struct xa_limit` to describe
the range of IDs the caller wants to allocate. We were using a single
mask to qualify a maximum ID only.

This commit changes that to use the same `struct xa_limit`. The logic
did not change, except it now supports a minimum ID as well.

The definition of `XA_LIMIT()` macro is adapted, as well as the
definitions of `xa_limit_*` (only `xa_limit_32b` existed, the other two
are added with this commit).

The DRM generic code started to use this `struct xa_limit` in Linux
6.12.

Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 783d018cf954f99032a0a4f655af8916024598a8)
2026-04-30 20:07:12 +02:00
Jean-Sébastien Pédron
bffaea6818
linuxkpi: Implement __GFP_THISNODE in alloc_pages()
It indicates to `alloc_pages()` to allocate the pages from the current
NUMA domain. If it couldn't, it should not retry elsewhere and return
failure.

Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 06a51a510a60ca29193b2cdb8120b630ea9ef18c)
2026-04-29 23:04:30 +02:00
Jean-Sébastien Pédron
1feb0effa0
linuxkpi: Define GFP_KERNEL_ACCOUNT flag
This flag combines `GFP_KERNEL` and `__GFP_ACCOUNT`. The latter is also
defined in this commit. It is defined as a no-op flag as it is not
implemented.

The DRM generic code started to use it in Linux 6.12.x.

Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit af01ffbfb1c0a0104d3a4c7dd1342ed7c81c6c54)
2026-04-29 23:04:28 +02:00