aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linuxkpi
Commit message (Collapse)AuthorAgeFilesLines
* linuxkpi: fix 32-bit arm buildKyle Evans15 hours2-2/+2
| | | | | | | | | | | | | The new KPI is only used in <asm/set_memory.h>, but it's provided in linux_page.c. The latter only includes the former indirectly by way of <linux/io.h>, and that's only conditionally included outside of 32-bit ARM there. All of our archs have the necessary pmap_page_set_memattr(), so just move the declaration into <linux/page.h> instead of trying to reason about the usability of <asm/set_memory.h> directly in linux_page.c. Reported by: jenkins (via ivy)
* linuxkpi: work with numpages > 1 in the set_pages_*() KPIsKyle Evans25 hours2-12/+26
| | | | | | | | | | | | | | | | | | | 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 Differential Revision: https://reviews.freebsd.org/D57004
* sys: Use is_pci_device instead of direct comparisons to devclassesJohn Baldwin34 hours1-4/+2
| | | | | | Reviewed by: bz Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D56997
* LinuxKPI: Check the devclass of the parent device in dev_is_pciJohn Baldwin34 hours1-2/+2
| | | | | | | Reviewed by: bz Fixes: c41d83548b6c ("LinuxKPI: pci.h add more defines and functions") Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D57066
* linux/io: handle memtype_wc mapping for !DMAP rangeMitchell Horne6 days1-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | 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
* power: Rename sleep typesAymeric Wibo8 days1-1/+1
| | | | | | | | | | Make sleep type names clearer and more consistent, and allow space for something like "os_hibernate" once that gets added to FreeBSD. Reviewed by: jaeyoon, olce, markj Approved by: jaeyoon, olce, markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56920
* sys/cdefs.h: Introduce __maybe_unused attributeHans Rosenfeld13 days1-1/+0
| | | | | | | | | | 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
* linuxkpi: Implement `module_*()` APIs as static functionsJean-Sébastien Pédron2026-05-041-3/+8
| | | | | | | | | This fixes an "unused variable" warning when building DRM drivers. Reviewed by: emaste MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56780
* sx: Add `sx_has_waiters()` macroJean-Sébastien Pédron2026-04-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | 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 Differential Revision: https://reviews.freebsd.org/D56443
* linuxkpi: Define `VFM_*()` macros in <asm/cpu_device_id.h>Jean-Sébastien Pédron2026-04-302-0/+42
| | | | | | | | | | | | | | They use another set of constants and macros in <asm/intel-family.h>. All these macros are defined regardless of the architecture, even though they are specific to x86. Perhaps we should restrict them using #ifdefs. The amdgpu DRM driver started to used `VFM_MODEL()` and the `INTEL_*LAKE*` constants in Linux 6.12.x. Reviewed by: bz, olce Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56585
* linuxkpi: Add `copy_from_user_inatomic_nontemporal()` functionJean-Sébastien Pédron2026-04-301-0/+7
| | | | | | | | | | | | | 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 Differential Revision: https://reviews.freebsd.org/D56719
* linuxkpi: Define `DEFINE_XARRAY*()` macrosJean-Sébastien Pédron2026-04-301-0/+12
| | | | | | | | | | | | | | | 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 Differential Revision: https://reviews.freebsd.org/D56446
* linuxkpi: Add `struct xa_limit` support to xarrayJean-Sébastien Pédron2026-04-302-33/+34
| | | | | | | | | | | | | | | | | | | | 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 Differential Revision: https://reviews.freebsd.org/D56445
* DMAP_TO_VM_PAGE: Wrapper macro to map direct map address to a pageJohn Baldwin2026-04-231-1/+1
| | | | | | | | Effort: CHERI upstreaming Suggested by: kib Reviewed by: kib Sponsored by: AFRL, DARPA Pull Request: https://github.com/freebsd/freebsd-src/pull/2068
* PHYS_TO_DMAP: Return a void * instead of a vm_offset_tJohn Baldwin2026-04-234-8/+7
| | | | | | | | | | Add a new PHYS_TO_DMAP_ADDR that still returns an address for use in places that only need an address and not a pointer. Effort: CHERI upstreaming Reviewed by: kib Sponsored by: AFRL, DARPA Pull Request: https://github.com/freebsd/freebsd-src/pull/2068
* kva_alloc/free: Use void * instead of vm_offset_tJohn Baldwin2026-04-231-3/+3
| | | | | | | Effort: CHERI upstreaming Reviewed by: kib Sponsored by: AFRL, DARPA Pull Request: https://github.com/freebsd/freebsd-src/pull/2068
* pmap_qenter/qremove: Use void * instead of vm_offset_tJohn Baldwin2026-04-231-11/+12
| | | | | | | Effort: CHERI upstreaming Reviewed by: kib Sponsored by: AFRL, DARPA Pull Request: https://github.com/freebsd/freebsd-src/pull/2068
* sf_buf_kva: Return a pointer instead of a vm_offset_tJohn Baldwin2026-04-232-2/+2
| | | | | | | | | This removes the need for several casts to pointer in callers. Effort: CHERI upstreaming Reviewed by: kib Sponsored by: AFRL, DARPA Pull Request: https://github.com/freebsd/freebsd-src/pull/2068
* pmap_change_attr: Use void * instead of vm_offset_tJohn Baldwin2026-04-232-5/+5
| | | | | | | Effort: CHERI upstreaming Reviewed by: kib Sponsored by: AFRL, DARPA Pull Request: https://github.com/freebsd/freebsd-src/pull/2068
* LinuxKPI: Update seq_file to properly implement the iterator interfaceJohn Baldwin2026-04-232-7/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The seq_file.rst documentation in the Linux kernel documents the iterator interface for the seq_file structure. In particular, the ppos passed to seq_read is a logical offset into a seq_file managed by the iterator interface, not an offset into the generated data. For example, if a seq_file outputs state for each node in a linked-list or array, *ppos might be used as the index of the node to output, not a byte offset. Rewrite seq_read to honor this contract which fixes a few bugs: - Treat *ppos as a logical iterator offset that is only updated by the next callback after outputting a single item via the show method. - Use a loop to permit outputting descriptions of multiple items if the user buffer is large enough. - Always invoke the stop method after terminating the loop to cleanup any state setup by start (e.g. if start allocated a buffer or obtained a lock, the stop method is called to cleanup). While here, implement support for SEQ_SKIP as documented in the Linux documentation even though it is not currently used in the tree. Reviewed by: bz Sponsored by: AFRL, DARPA Differential Revision: https://reviews.freebsd.org/D55899
* linuxkpi: Implement __GFP_THISNODE in alloc_pages()Jean-Sébastien Pédron2026-04-222-4/+13
| | | | | | | | | | 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 Differential Revision: https://reviews.freebsd.org/D56590
* linuxkpi: Define `GFP_KERNEL_ACCOUNT` flagJean-Sébastien Pédron2026-04-221-0/+2
| | | | | | | | | | | | 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 Differential Revision: https://reviews.freebsd.org/D56587
* linuxkpi: Fix strlcpy size in linuxkpi_alloc_netdev()Weixie Cui2026-04-221-1/+1
| | | | | | | | | | `sizeof(*ndev->name)` is `sizeof(char)`, not IFNAMSIZ, so the interface name was effectively limited to a single byte. Use `sizeof(ndev->name)` for the `char name[IFNAMSIZ]` member. Signed-off-by: Weixie Cui <cuiweixie@gmail.com> Reviewed by: pouria Pull-Request: https://github.com/freebsd/freebsd-src/pull/2111
* linuxkpi: Move `GENMASK()` to <linux/bits.h>Jean-Sébastien Pédron2026-04-222-2/+16
| | | | | | | | | | | | | ... from <linux/bitops.h>. This matches the location on Linux. <linux/bits.h> is also included from <linux/bitops.h>. Therefore it will not break anything. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56584
* linuxkpi: Add `pci_dev_is_disconnected()`Jean-Sébastien Pédron2026-04-221-0/+7
| | | | | | | | | | | | For now, it is an empty stub that always return false. On Linux, it looks at an internal error state of the device to determine if it is disconnected. The amdgpu DRM driver started this in Linux 6.12.x. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56582
* linuxkpi: Define `min_array()` and `max_array()`Jean-Sébastien Pédron2026-04-221-0/+10
| | | | | | | | | | | They are macros that return the minimum or maximum values of an array of integers. They assume that the array contains elements. The i915 DRM driver started to use `min_array()` in Linux 6.12.x. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56583
* linuxkpi: Add `memdup_array_user()`Jean-Sébastien Pédron2026-04-221-0/+11
| | | | | | | | The amdgpu DRM driver started this in Linux 6.12.x. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56574
* linuxkpi: Move `ARRAY_SIZE` to <linux/array_size.h>Jean-Sébastien Pédron2026-04-224-2/+20
| | | | | | | | | | | | | The DRM generic code started to import this header directly in Linux 6.12.x. Let's move the definition of `ARRAY_SIZE()` (the only thing that <linux/array_size.h> defines) to this header. Also, include <linux/array_size.h> from the same headers as Linux. This includes <linux/kernel.h>, so the change should not break anything. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56570
* linuxkpi: Add Linux 6.12 variant of `kvrealloc()`Jean-Sébastien Pédron2026-04-222-16/+61
| | | | | | | | | | | In Linux 6.12, the API changed to be closer to `krealloc()`: * The function does not take the old size anymore * The function becomes a wrapper around `krealloc()` with a fallback mechanism. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56453
* linuxkpi: Move {lower,upper}_32_bits macros to <linux/wordpart.h>Jean-Sébastien Pédron2026-04-223-3/+14
| | | | | | | | | | | | | | | | ... from <linux/compiler.h>. <linux/wordpart.h> is the header defining them on Linux 6.12 (I didn't check older versions). <linux/wordpart.h> is also included from <linux/kernel.h>. The DRM generic code started to depend on <linux/wordpart.h> in Linux 6.12. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56441
* linuxkpi: Add `rb_add()`Jean-Sébastien Pédron2026-04-221-0/+20
| | | | | | | | | | | It is the same as `rb_add_cached()` but it works on `struct rb_root`, not a `struc rb_root_cached`. It also does not return anything. The DRM generic code started to use this in Linux 6.12.x. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56577
* linuxkpi: Define `DIV_U64_ROUND_UP()`Jean-Sébastien Pédron2026-04-221-0/+9
| | | | | | | | | | | It is the same as `DIV64_U64_ROUND_UP()` but takes a 32-bit integer as the divisor. The amdgpu DRM driver started to use this in Linux 6.12.x. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56576
* linuxkpi: Define `system_state`Jean-Sébastien Pédron2026-04-222-0/+13
| | | | | | | | | | | | | | | This is a global variable used to track the state of the system, like booting, running, halting and so on. This variable is based on the `enum system_states` enumeration. For now, always set `system_state` to `SYSTEM_RUNNING`. The amdgpu DRM driver started to use this in Linux 6.12.x. Reviewed by: emaste Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56575
* linuxkpi: Add `atomic_read_acquire()`Jean-Sébastien Pédron2026-04-223-0/+34
| | | | | | | | | | | | | This function calls `raw_atomic_read_acquire()` which is also added. They are located in <linux/atomic/*.h> headers, both included from <linux/atomic.h>. The amdgpu DRM driver started to use this in Linux 6.12.x. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56573
* linuxkpi: Add `register_pm_notifier()` and `unregister_pm_notifier()`Jean-Sébastien Pédron2026-04-221-1/+20
| | | | | | | | | | | | | They are empty stub returning success for now, like the previously defined stubs in this header. Several constant are also defined in the process. The amdgpu DRM driver started to use them in Linux 6.12.x. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56572
* linuxkpi: Define a guard for the `mutex` typeJean-Sébastien Pédron2026-04-221-0/+2
| | | | | | | | The amdgpu DRM driver started to use `guard(mutex)` in Linux 6.12.x. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56571
* linuxkpi: <asm/unaligned.h> is moved to <linux/unaligned.h> in Linux 6.12Jean-Sébastien Pédron2026-04-222-0/+12
| | | | | | Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56454
* linuxkpi: Add `kmemdup_array()`Jean-Sébastien Pédron2026-04-221-0/+6
| | | | | | | | | | | It is similar to `kmemdup()` but takes a number of elements to duplicate and their size. The i915 DRM driver started to use it in Linux 6.12. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56444
* linuxkpi: Add `mem_is_zero()`Jean-Sébastien Pédron2026-04-221-0/+6
| | | | | | | | | | The DRM generic code and the i915 DRM driver started to replace the use of `memchr_inv()` by a `mem_is_zero()` in Linux 6.12. We reuse the previous use of `memchr_inv()` to implement `mem_is_zero()`. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56442
* linuxkpi: Define `fd_file()`Jean-Sébastien Pédron2026-04-221-0/+2
| | | | | | | | | | | This macro simply returns the `file` field of the `struct fd`. The DRM generic code and the amdgpu driver started to use it in Linux 6.12. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56440
* linuxkpi: Add more `struct folio`-related functionsJean-Sébastien Pédron2026-04-222-0/+23
| | | | | | | | | | | | | | | | The i915 DRM driver started to replace the use of `struct page` by `struct folio` in its GEM shmem code in Linux 6.12. linuxkpi were missing a few more functions: `kmap_local_folio()`, `memcpy_to_folio()` and `offset_in_folio()`. They are equivalent of their `struct page` counterparts. One difference is that `kmap_local_folio()` takes an offset argument and the returned address takes this offset into account. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56438
* linuxkpi: Add `struct kmsg_dump_detail`Jean-Sébastien Pédron2026-04-221-0/+9
| | | | | | | | | | | | This structure is used in a modified definition of `struct kmsg_dumper` field `dump` in Linux 6.12. Therefore this field has two definitions put behind the values of `LINUXKPI_VERSION`. The DRM generic code started to use it in Linux 6.12. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56433
* linuxkpi: Passing a size of zero to `krealloc()` frees the pointerJean-Sébastien Pédron2026-04-211-0/+5
| | | | | | | | This matches the API on Linux. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56452
* linuxkpi: Pass a `const void *` to `krealloc()`Jean-Sébastien Pédron2026-04-212-5/+5
| | | | | | | | This matches the API on Linux. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56451
* linuxkpi: Add `fop_flags` to `struct file_operations`Jean-Sébastien Pédron2026-04-211-0/+11
| | | | | | | | | | | | | ... along with the `FOP_*` flag constants. Note that this `fop_flags` field is not used on FreeBSD. It is added to make the DRM drivers compile out of the box. The DRM generic code and drivers started this in Linux 6.12. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56450
* linuxkpi: Include <linux/uuid.h> from <linux/mod_devicetable.h>Jean-Sébastien Pédron2026-04-211-0/+1
| | | | | | | | | The DRM generic code started to deppend on this indirect include of <linux/uuid.h> in Linux 6.12. Reviewed by: bz, emaste Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56449
* linuxkpi: Add several `guid_*()` functionsJean-Sébastien Pédron2026-04-212-0/+30
| | | | | | | | | The DRM generic code and the amdgpu DRM driver started to use several of these functions in Linux 6.12. Likewise for `UUID_SIZE`. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56448
* linuxkpi: Define `MINORBITS`Jean-Sébastien Pédron2026-04-211-0/+15
| | | | | | | | | | | | | | | | | We can't really define a proper value for this constant because minor and major are encoded in a complex way on FreeBSD which cannot be represented with a simple shift. The DRM generic code started to use it in Linux 6.12. In this context, `MINORBITS` is used to define an upper limit passed to `xa_alloc()`. Therefore it is not used to encode or decode minors. It is used as an arbitrary value. Therefore, we define the constant to 20, like on Linux. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56447
* linuxkpi: Define `sort_r()`Jean-Sébastien Pédron2026-04-211-0/+5
| | | | | | | | | | | Like Linux `sort()` and FreeBSD `qsort()`, `sort_r()` is a wrapper around FreeBSD `qsort_r()`. The i915 DRM driver started to use it in Linux 6.12. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56437
* linuxkpi: Define `__GFP_THISNODE`Jean-Sébastien Pédron2026-04-211-1/+2
| | | | | | | | | | | | It is used to force the NUMA node to allocate from. This flag is unimplemented for now because we don't have an implementation of `alloc_pages_node()` yet. The DRM TTM code started to use this flag in Linux 6.12. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56436