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
Differential Revision: https://reviews.freebsd.org/D56446
This commit is contained in:
Jean-Sébastien Pédron
2026-04-13 23:44:16 +02:00
parent 783d018cf9
commit 796fff59a5
@@ -54,6 +54,18 @@ struct xarray {
uint32_t xa_flags; /* see XA_FLAGS_XXX */
};
#define DEFINE_XARRAY_FLAGS(name, flags) \
struct xarray name = { \
.xa_head.gfp_mask = GFP_NOWAIT, \
.xa_flags = flags, \
}; \
MTX_SYSINIT(name ## _mtx, &name.xa_lock, \
"linuxkpi_DEFINE_XARRAY(" #name ")", \
MTX_DEF | MTX_RECURSE)
#define DEFINE_XARRAY(name) DEFINE_XARRAY_FLAGS(name, 0)
#define DEFINE_XARRAY_ALLOC(name) DEFINE_XARRAY_FLAGS(name, XA_FLAGS_ALLOC)
struct xa_limit {
uint32_t max;
uint32_t min;