diff mbox series

[v8,5/6] riscv: Add ifunc helper method to hwprobe.h

Message ID 20230901235224.3304592-6-evan@rivosinc.com
State New
Headers show
Series RISC-V: ifunced memcpy using new kernel hwprobe interface | expand

Commit Message

Evan Green Sept. 1, 2023, 11:52 p.m. UTC
Add a little helper method so it's easier to fetch a single value from
the hwprobe function when used within an ifunc selector.

Signed-off-by: Evan Green <evan@rivosinc.com>

---

(no changes since v7)

Changes in v7:
 - Introduced static inline helper (Richard)

 sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h | 24 +++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox series

Patch

diff --git a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
index fd3be5a411..7378b1baa2 100644
--- a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
+++ b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
@@ -22,6 +22,7 @@ 
 
 #include <features.h>
 #include <stddef.h>
+#include <errno.h>
 #ifdef __has_include
 # if __has_include (<asm/hwprobe.h>)
 #  include <asm/hwprobe.h>
@@ -79,4 +80,27 @@  typedef int (*__riscv_hwprobe_t) (struct riscv_hwprobe *__pairs, size_t __pair_c
 
 __END_DECLS
 
+/* Helper function usable from ifunc selectors that probes a single key. */
+static inline int __riscv_hwprobe_one(__riscv_hwprobe_t hwprobe_func,
+                                      signed long long int key,
+                                      unsigned long long int *value)
+{
+  struct riscv_hwprobe pair;
+  int rc;
+
+  if (!hwprobe_func)
+    return ENOSYS;
+
+  pair.key = key;
+  rc = hwprobe_func(&pair, 1, 0, NULL, 0);
+  if (rc)
+    return rc;
+
+  if (pair.key < 0)
+    return ENOENT;
+
+  *value = pair.value;
+  return 0;
+}
+
 #endif /* sys/hwprobe.h */