~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/riscv/kernel/vdso/hwprobe.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Copyright 2023 Rivos, Inc
  4  */
  5 
  6 #include <linux/string.h>
  7 #include <linux/types.h>
  8 #include <vdso/datapage.h>
  9 #include <vdso/helpers.h>
 10 
 11 extern int riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
 12                          size_t cpusetsize, unsigned long *cpus,
 13                          unsigned int flags);
 14 
 15 static int riscv_vdso_get_values(struct riscv_hwprobe *pairs, size_t pair_count,
 16                                  size_t cpusetsize, unsigned long *cpus,
 17                                  unsigned int flags)
 18 {
 19         const struct vdso_data *vd = __arch_get_vdso_data();
 20         const struct arch_vdso_data *avd = &vd->arch_data;
 21         bool all_cpus = !cpusetsize && !cpus;
 22         struct riscv_hwprobe *p = pairs;
 23         struct riscv_hwprobe *end = pairs + pair_count;
 24 
 25         /*
 26          * Defer to the syscall for exotic requests. The vdso has answers
 27          * stashed away only for the "all cpus" case. If all CPUs are
 28          * homogeneous, then this function can handle requests for arbitrary
 29          * masks.
 30          */
 31         if ((flags != 0) || (!all_cpus && !avd->homogeneous_cpus))
 32                 return riscv_hwprobe(pairs, pair_count, cpusetsize, cpus, flags);
 33 
 34         /* This is something we can handle, fill out the pairs. */
 35         while (p < end) {
 36                 if (riscv_hwprobe_key_is_valid(p->key)) {
 37                         p->value = avd->all_cpu_hwprobe_values[p->key];
 38 
 39                 } else {
 40                         p->key = -1;
 41                         p->value = 0;
 42                 }
 43 
 44                 p++;
 45         }
 46 
 47         return 0;
 48 }
 49 
 50 static int riscv_vdso_get_cpus(struct riscv_hwprobe *pairs, size_t pair_count,
 51                                size_t cpusetsize, unsigned long *cpus,
 52                                unsigned int flags)
 53 {
 54         const struct vdso_data *vd = __arch_get_vdso_data();
 55         const struct arch_vdso_data *avd = &vd->arch_data;
 56         struct riscv_hwprobe *p = pairs;
 57         struct riscv_hwprobe *end = pairs + pair_count;
 58         unsigned char *c = (unsigned char *)cpus;
 59         bool empty_cpus = true;
 60         bool clear_all = false;
 61         int i;
 62 
 63         if (!cpusetsize || !cpus)
 64                 return -EINVAL;
 65 
 66         for (i = 0; i < cpusetsize; i++) {
 67                 if (c[i]) {
 68                         empty_cpus = false;
 69                         break;
 70                 }
 71         }
 72 
 73         if (empty_cpus || flags != RISCV_HWPROBE_WHICH_CPUS || !avd->homogeneous_cpus)
 74                 return riscv_hwprobe(pairs, pair_count, cpusetsize, cpus, flags);
 75 
 76         while (p < end) {
 77                 if (riscv_hwprobe_key_is_valid(p->key)) {
 78                         struct riscv_hwprobe t = {
 79                                 .key = p->key,
 80                                 .value = avd->all_cpu_hwprobe_values[p->key],
 81                         };
 82 
 83                         if (!riscv_hwprobe_pair_cmp(&t, p))
 84                                 clear_all = true;
 85                 } else {
 86                         clear_all = true;
 87                         p->key = -1;
 88                         p->value = 0;
 89                 }
 90                 p++;
 91         }
 92 
 93         if (clear_all) {
 94                 for (i = 0; i < cpusetsize; i++)
 95                         c[i] = 0;
 96         }
 97 
 98         return 0;
 99 }
100 
101 /* Add a prototype to avoid -Wmissing-prototypes warning. */
102 int __vdso_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
103                          size_t cpusetsize, unsigned long *cpus,
104                          unsigned int flags);
105 
106 int __vdso_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
107                          size_t cpusetsize, unsigned long *cpus,
108                          unsigned int flags)
109 {
110         if (flags & RISCV_HWPROBE_WHICH_CPUS)
111                 return riscv_vdso_get_cpus(pairs, pair_count, cpusetsize,
112                                            cpus, flags);
113 
114         return riscv_vdso_get_values(pairs, pair_count, cpusetsize,
115                                      cpus, flags);
116 }
117 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php