sync with OpenBSD -current

This commit is contained in:
purplerain 2024-10-02 00:06:39 +00:00
parent 665ee5434a
commit 5c45f68af5
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
20 changed files with 207 additions and 131 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: drm_linux.c,v 1.115 2024/07/13 15:38:21 kettenis Exp $ */
/* $OpenBSD: drm_linux.c,v 1.119 2024/09/30 12:21:17 jsg Exp $ */
/*
* Copyright (c) 2013 Jonathan Gray <jsg@openbsd.org>
* Copyright (c) 2015, 2016 Mark Kettenis <kettenis@openbsd.org>
@ -982,18 +982,12 @@ SPLAY_GENERATE(xarray_tree, xarray_entry, entry, xarray_cmp);
void
xa_init_flags(struct xarray *xa, gfp_t flags)
{
static int initialized;
if (!initialized) {
pool_init(&xa_pool, sizeof(struct xarray_entry), 0, IPL_NONE, 0,
"xapl", NULL);
initialized = 1;
}
SPLAY_INIT(&xa->xa_tree);
if (flags & XA_FLAGS_LOCK_IRQ)
mtx_init(&xa->xa_lock, IPL_TTY);
else
mtx_init(&xa->xa_lock, IPL_NONE);
xa->xa_flags = flags;
}
void
@ -1009,11 +1003,15 @@ xa_destroy(struct xarray *xa)
/* Don't wrap ids. */
int
__xa_alloc(struct xarray *xa, u32 *id, void *entry, int limit, gfp_t gfp)
__xa_alloc(struct xarray *xa, u32 *id, void *entry, struct xarray_range xr,
gfp_t gfp)
{
struct xarray_entry *xid;
int start = (xa->xa_flags & XA_FLAGS_ALLOC1) ? 1 : 0;
int begin;
uint32_t start = xr.start;
uint32_t end = xr.end;
if (start == 0 && (xa->xa_flags & XA_FLAGS_ALLOC1))
start = 1;
if (gfp & GFP_NOWAIT) {
xid = pool_get(&xa_pool, PR_NOWAIT);
@ -1026,17 +1024,14 @@ __xa_alloc(struct xarray *xa, u32 *id, void *entry, int limit, gfp_t gfp)
if (xid == NULL)
return -ENOMEM;
if (limit <= 0)
limit = INT_MAX;
xid->id = begin = start;
xid->id = start;
while (SPLAY_INSERT(xarray_tree, &xa->xa_tree, xid)) {
if (xid->id == limit)
if (xid->id == end)
xid->id = start;
else
xid->id++;
if (xid->id == begin) {
if (xid->id == start) {
pool_put(&xa_pool, xid);
return -EBUSY;
}
@ -1052,10 +1047,10 @@ __xa_alloc(struct xarray *xa, u32 *id, void *entry, int limit, gfp_t gfp)
* The only caller of this (i915_drm_client.c) doesn't use next id.
*/
int
__xa_alloc_cyclic(struct xarray *xa, u32 *id, void *entry, int limit, u32 *next,
gfp_t gfp)
__xa_alloc_cyclic(struct xarray *xa, u32 *id, void *entry,
struct xarray_range xr, u32 *next, gfp_t gfp)
{
int r = __xa_alloc(xa, id, entry, limit, gfp);
int r = __xa_alloc(xa, id, entry, xr, gfp);
*next = *id + 1;
return r;
}
@ -2853,6 +2848,8 @@ drm_linux_init(void)
pool_init(&idr_pool, sizeof(struct idr_entry), 0, IPL_TTY, 0,
"idrpl", NULL);
pool_init(&xa_pool, sizeof(struct xarray_entry), 0, IPL_NONE, 0,
"xapl", NULL);
kmap_atomic_va =
(vaddr_t)km_alloc(PAGE_SIZE, &kv_any, &kp_none, &kd_waitok);
@ -2868,6 +2865,7 @@ drm_linux_init(void)
void
drm_linux_exit(void)
{
pool_destroy(&xa_pool);
pool_destroy(&idr_pool);
taskq_destroy(taskletq);
@ -2946,20 +2944,25 @@ unregister_shrinker(struct shrinker *shrinker)
TAILQ_REMOVE(&shrinkers, shrinker, next);
}
void
unsigned long
drmbackoff(long npages)
{
struct shrink_control sc;
struct shrinker *shrinker;
u_long ret;
u_long ret, freed = 0;
shrinker = TAILQ_FIRST(&shrinkers);
while (shrinker && npages > 0) {
sc.nr_to_scan = npages;
ret = shrinker->scan_objects(shrinker, &sc);
if (ret == SHRINK_STOP)
break;
npages -= ret;
freed += ret;
shrinker = TAILQ_NEXT(shrinker, next);
}
return freed;
}
void *

View file

@ -7,9 +7,9 @@
#include <sys/tree.h>
#define XA_FLAGS_ALLOC 1
#define XA_FLAGS_ALLOC1 2
#define XA_FLAGS_LOCK_IRQ 4
#define XA_FLAGS_ALLOC (1 << 0)
#define XA_FLAGS_ALLOC1 (1 << 1)
#define XA_FLAGS_LOCK_IRQ (1 << 2)
/*
* lower bits of pointer are tagged:
@ -29,10 +29,19 @@ struct xarray {
SPLAY_HEAD(xarray_tree, xarray_entry) xa_tree;
};
struct xarray_range {
uint32_t start;
uint32_t end;
};
#define XA_LIMIT(_start, _end) (struct xarray_range){ _start, _end }
#define xa_limit_32b XA_LIMIT(0, UINT_MAX)
void xa_init_flags(struct xarray *, gfp_t);
void xa_destroy(struct xarray *);
int __xa_alloc(struct xarray *, u32 *, void *, int, gfp_t);
int __xa_alloc_cyclic(struct xarray *, u32 *, void *, int, u32 *, gfp_t);
int __xa_alloc(struct xarray *, u32 *, void *, struct xarray_range, gfp_t);
int __xa_alloc_cyclic(struct xarray *, u32 *, void *, struct xarray_range,
u32 *, gfp_t);
void *__xa_load(struct xarray *, unsigned long);
void *__xa_store(struct xarray *, unsigned long, void *, gfp_t);
void *__xa_erase(struct xarray *, unsigned long);
@ -41,8 +50,6 @@ void *xa_get_next(struct xarray *, unsigned long *);
#define xa_for_each(xa, index, entry) \
for (index = 0; ((entry) = xa_get_next(xa, &(index))) != NULL; index++)
#define xa_limit_32b 0
#define xa_lock(_xa) do { \
mtx_enter(&(_xa)->xa_lock); \
} while (0)
@ -112,11 +119,12 @@ xa_is_err(const void *e)
}
static inline int
xa_alloc(struct xarray *xa, u32 *id, void *entry, int limit, gfp_t gfp)
xa_alloc(struct xarray *xa, u32 *id, void *entry, struct xarray_range xr,
gfp_t gfp)
{
int r;
mtx_enter(&xa->xa_lock);
r = __xa_alloc(xa, id, entry, limit, gfp);
r = __xa_alloc(xa, id, entry, xr, gfp);
mtx_leave(&xa->xa_lock);
return r;
}