Author: bdragon
Date: Mon Sep 14 15:20:37 2020
New Revision: 365723
URL: https://svnweb.freebsd.org/changeset/base/365723

Log:
  [PowerPC] Make cpu frequency detection endian-independent
  
  On ibm,extended-clock-frequency, ensure we be64toh() the value.
  
  On clock-frequency, remove the right-shifting hack (which was needed due to
  reading a 32 bit value into a 64 bit variable) and switch to OF_getencprop()
  for reading (which will handle endian conversion internally.)
  
  Reviewed by:  jhibbits (in irc)
  Sponsored by: Tag1 Consulting, Inc.

Modified:
  head/sys/powerpc/powerpc/cpu.c

Modified: head/sys/powerpc/powerpc/cpu.c
==============================================================================
--- head/sys/powerpc/powerpc/cpu.c      Mon Sep 14 14:53:09 2020        
(r365722)
+++ head/sys/powerpc/powerpc/cpu.c      Mon Sep 14 15:20:37 2020        
(r365723)
@@ -72,6 +72,7 @@
 #include <sys/sysctl.h>
 #include <sys/sched.h>
 #include <sys/smp.h>
+#include <sys/endian.h>
 
 #include <machine/bus.h>
 #include <machine/cpu.h>
@@ -358,6 +359,7 @@ cpu_est_clockrate(int cpu_id, uint64_t *cps)
        uint16_t        vers;
        register_t      msr;
        phandle_t       cpu, dev, root;
+       uint32_t        freq32;
        int             res  = 0;
        char            buf[8];
 
@@ -428,10 +430,11 @@ cpu_est_clockrate(int cpu_id, uint64_t *cps)
                                return (ENOENT);
                        if (OF_getprop(cpu, "ibm,extended-clock-frequency",
                            cps, sizeof(*cps)) >= 0) {
+                               *cps = be64toh(*cps);
                                return (0);
-                       } else if (OF_getprop(cpu, "clock-frequency", cps, 
-                           sizeof(cell_t)) >= 0) {
-                               *cps >>= 32;
+                       } else if (OF_getencprop(cpu, "clock-frequency",
+                           &freq32, sizeof(freq32)) >= 0) {
+                               *cps = freq32;
                                return (0);
                        } else {
                                return (ENOENT);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to