tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: General device properties API



> On Aug 15, 2021, at 9:56 AM, Taylor R Campbell <campbell+netbsd-tech-kern%mumble.net@localhost> wrote:
> 
> Cool, thanks!  Can you expand on what it would look like instead with
> the new API?  Do you have any diffs to particulary compelling messy
> drivers or buses to show off how this makes things better?

Here’s a pretty solid example:

Index: arm/arm_cpu_topology.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/arm/arm_cpu_topology.c,v
retrieving revision 1.5
diff -u -p -r1.5 arm_cpu_topology.c
--- arm/arm_cpu_topology.c      29 Mar 2020 08:27:41 -0000      1.5
+++ arm/arm_cpu_topology.c      15 Aug 2021 21:11:26 -0000
@@ -71,14 +71,12 @@ arm_cpu_do_topology(struct cpu_info *con
 #ifdef MULTIPROCESSOR
        struct cpu_info *ci;
        CPU_INFO_ITERATOR cii;
-       prop_dictionary_t dict;
-       uint32_t capacity_dmips_mhz = 0;
        static uint32_t best_cap = 0;
 
-       dict = device_properties(newci->ci_dev);
-       if (prop_dictionary_get_uint32(dict, "capacity_dmips_mhz",
-           &capacity_dmips_mhz))
-               newci->ci_capacity_dmips_mhz = capacity_dmips_mhz;
+       if (device_getprop_uint32(newci->ci_dev, "capacity-dmips-mhz",
+                                 &newci->ci_capacity_dmips_mhz) != 0) {
+               newci->ci_capacity_dmips_mhz = 0;
+       }
 
        if (newci->ci_capacity_dmips_mhz > best_cap)
                best_cap = newci->ci_capacity_dmips_mhz;
Index: fdt/cpu_fdt.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/fdt/cpu_fdt.c,v
retrieving revision 1.40
diff -u -p -r1.40 cpu_fdt.c
--- fdt/cpu_fdt.c       7 Aug 2021 16:18:43 -0000       1.40
+++ fdt/cpu_fdt.c       15 Aug 2021 21:11:26 -0000
@@ -84,21 +84,10 @@ cpu_fdt_attach(device_t parent, device_t
        struct fdt_attach_args * const faa = aux;
        const int phandle = faa->faa_phandle;
        bus_addr_t cpuid;
-       const uint32_t *cap_ptr;
-       int len;
 
        sc->sc_dev = self;
        sc->sc_phandle = phandle;
 
-       cap_ptr = fdtbus_get_prop(phandle, "capacity-dmips-mhz", &len);
-       if (cap_ptr && len == 4) {
-               prop_dictionary_t dict = device_properties(self);
-               uint32_t capacity_dmips_mhz = be32toh(*cap_ptr);
-
-               prop_dictionary_set_uint32(dict, "capacity_dmips_mhz",
-                   capacity_dmips_mhz);
-       }
-
        if (fdtbus_get_reg(phandle, 0, &cpuid, NULL) != 0)
                cpuid = 0;
 
Index: include/cpu_topology.h
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/include/cpu_topology.h,v
retrieving revision 1.2
diff -u -p -r1.2 cpu_topology.h
--- include/cpu_topology.h      15 Feb 2020 08:16:11 -0000      1.2
+++ include/cpu_topology.h      15 Aug 2021 21:11:26 -0000
@@ -39,9 +39,8 @@
  * Call arm_cpu_do_topology() in cpu_attach(). It will update the topology
  * view of relative speed.
  *
- * The CPU frontend can set the "capacity_dmips_mhz" property for this CPU,
- * and arm_cpu_do_topology() will update the system view of this and other
- * CPUs relative speeds
+ * arm_cpu_do_topology() will update the system view of this and other
+ * CPUs relative speeds by querying the "capacity-dmips-mhz" property.
  *
  * arm_cpu_topology_set(cpuinfo, mpidr)
  *

-- thorpej



Home | Main Index | Thread Index | Old Index