summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2020-11-14 15:00:20 +0000
committerkettenis <kettenis@openbsd.org>2020-11-14 15:00:20 +0000
commitd9e6dc4f546b80d62e1f0dc6acfec7ee122e4e4f (patch)
tree2eb7c78695bf487538c9a0cf1cda37b5bfbcbb36
parentwhitespace (diff)
downloadwireguard-openbsd-d9e6dc4f546b80d62e1f0dc6acfec7ee122e4e4f.tar.xz
wireguard-openbsd-d9e6dc4f546b80d62e1f0dc6acfec7ee122e4e4f.zip
Bring IDR function prototypes in line with modern Linux and implement
IDA functions in terms of IDR. Fixes issues with running out of PASIDs in amdgpu(4). ok jsg@
-rw-r--r--sys/dev/pci/drm/drm_linux.c35
-rw-r--r--sys/dev/pci/drm/include/linux/idr.h25
2 files changed, 23 insertions, 37 deletions
diff --git a/sys/dev/pci/drm/drm_linux.c b/sys/dev/pci/drm/drm_linux.c
index c1f35c48319..684b1028898 100644
--- a/sys/dev/pci/drm/drm_linux.c
+++ b/sys/dev/pci/drm/drm_linux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: drm_linux.c,v 1.67 2020/11/14 14:57:41 kettenis Exp $ */
+/* $OpenBSD: drm_linux.c,v 1.68 2020/11/14 15:00:20 kettenis Exp $ */
/*
* Copyright (c) 2013 Jonathan Gray <jsg@openbsd.org>
* Copyright (c) 2015, 2016 Mark Kettenis <kettenis@openbsd.org>
@@ -630,8 +630,7 @@ idr_preload(unsigned int gfp_mask)
}
int
-idr_alloc(struct idr *idr, void *ptr, int start, int end,
- unsigned int gfp_mask)
+idr_alloc(struct idr *idr, void *ptr, int start, int end, gfp_t gfp_mask)
{
int flags = (gfp_mask & GFP_NOWAIT) ? PR_NOWAIT : PR_WAITOK;
struct idr_entry *id;
@@ -669,7 +668,7 @@ idr_alloc(struct idr *idr, void *ptr, int start, int end,
}
void *
-idr_replace(struct idr *idr, void *ptr, int id)
+idr_replace(struct idr *idr, void *ptr, unsigned long id)
{
struct idr_entry find, *res;
void *old;
@@ -684,7 +683,7 @@ idr_replace(struct idr *idr, void *ptr, int id)
}
void *
-idr_remove(struct idr *idr, int id)
+idr_remove(struct idr *idr, unsigned long id)
{
struct idr_entry find, *res;
void *ptr = NULL;
@@ -700,7 +699,7 @@ idr_remove(struct idr *idr, int id)
}
void *
-idr_find(struct idr *idr, int id)
+idr_find(struct idr *idr, unsigned long id)
{
struct idr_entry find, *res;
@@ -752,38 +751,26 @@ SPLAY_GENERATE(idr_tree, idr_entry, entry, idr_cmp);
void
ida_init(struct ida *ida)
{
- ida->counter = 0;
+ idr_init(&ida->idr);
}
void
ida_destroy(struct ida *ida)
{
-}
-
-void
-ida_remove(struct ida *ida, int id)
-{
+ idr_destroy(&ida->idr);
}
int
ida_simple_get(struct ida *ida, unsigned int start, unsigned int end,
- int flags)
+ gfp_t gfp_mask)
{
- if (end <= 0)
- end = INT_MAX;
-
- if (start > ida->counter)
- ida->counter = start;
-
- if (ida->counter >= end)
- return -ENOSPC;
-
- return ida->counter++;
+ return idr_alloc(&ida->idr, NULL, start, end, gfp_mask);
}
void
-ida_simple_remove(struct ida *ida, int id)
+ida_simple_remove(struct ida *ida, unsigned int id)
{
+ idr_remove(&ida->idr, id);
}
int
diff --git a/sys/dev/pci/drm/include/linux/idr.h b/sys/dev/pci/drm/include/linux/idr.h
index b327fa9e4a4..8954a687f16 100644
--- a/sys/dev/pci/drm/include/linux/idr.h
+++ b/sys/dev/pci/drm/include/linux/idr.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: idr.h,v 1.3 2020/06/08 04:48:14 jsg Exp $ */
+/* $OpenBSD: idr.h,v 1.4 2020/11/14 15:00:20 kettenis Exp $ */
/*
* Copyright (c) 2016 Mark Kettenis
*
@@ -25,7 +25,7 @@
struct idr_entry {
SPLAY_ENTRY(idr_entry) entry;
- int id;
+ unsigned long id;
void *ptr;
};
@@ -35,11 +35,11 @@ struct idr {
void idr_init(struct idr *);
void idr_preload(unsigned int);
-int idr_alloc(struct idr *, void *, int, int, unsigned int);
+int idr_alloc(struct idr *, void *, int, int, gfp_t);
#define idr_preload_end()
-void *idr_find(struct idr *, int);
-void *idr_replace(struct idr *, void *ptr, int);
-void *idr_remove(struct idr *, int);
+void *idr_find(struct idr *, unsigned long);
+void *idr_replace(struct idr *, void *, unsigned long);
+void *idr_remove(struct idr *, unsigned long);
void idr_destroy(struct idr *);
int idr_for_each(struct idr *, int (*)(int, void *, void *), void *);
void *idr_get_next(struct idr *, int *);
@@ -55,18 +55,17 @@ idr_is_empty(const struct idr *idr)
}
struct ida {
- int counter;
+ struct idr idr;
};
-#define DEFINE_IDA(name) \
- struct ida name = { \
- .counter = 0 \
+#define DEFINE_IDA(name) \
+ struct ida name = { \
+ .idr = { SPLAY_INITIALIZER(&name.idr.tree) } \
}
void ida_init(struct ida *);
void ida_destroy(struct ida *);
-int ida_simple_get(struct ida *, unsigned int, unsigned nt, int);
-void ida_remove(struct ida *, int);
-void ida_simple_remove(struct ida *, int);
+int ida_simple_get(struct ida *, unsigned int, unsigned int, gfp_t);
+void ida_simple_remove(struct ida *, unsigned int);
#endif