On 6/30/22 21:42, Daniel Henrique Barboza wrote:
Let's put the default clock and timebase freq value in macros for better
readability.  Use PPC440EP_CLOCK_FREQ as the default value of
'clock_freq' if kvmppc_get_clockfreq() throws an error.

Signed-off-by: Daniel Henrique Barboza <danielhb...@gmail.com>
---
  hw/ppc/ppc440_bamboo.c | 17 ++++++++++++++---
  1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/hw/ppc/ppc440_bamboo.c b/hw/ppc/ppc440_bamboo.c
index d23f881d9d..6318112393 100644
--- a/hw/ppc/ppc440_bamboo.c
+++ b/hw/ppc/ppc440_bamboo.c
@@ -50,6 +50,10 @@
#define PPC440EP_SDRAM_NR_BANKS 4 +#define PPC440EP_TB_FREQ 400000000
+#define PPC440EP_CLOCK_FREQ     400000000
+
+
  static const ram_addr_t ppc440ep_sdram_bank_sizes[] = {
      256 * MiB, 128 * MiB, 64 * MiB, 32 * MiB, 16 * MiB, 8 * MiB, 0
  };
@@ -67,8 +71,8 @@ static int bamboo_load_device_tree(hwaddr addr,
      char *filename;
      int fdt_size;
      void *fdt;
-    uint32_t tb_freq = 400000000;
-    uint32_t clock_freq = 400000000;
+    uint32_t tb_freq = PPC440EP_TB_FREQ;
+    uint32_t clock_freq = PPC440EP_CLOCK_FREQ;
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
      if (!filename) {
@@ -106,8 +110,15 @@ static int bamboo_load_device_tree(hwaddr addr,
       * directly access the timebase without host involvement, we must expose
       * the correct frequencies. */
      if (kvm_enabled()) {
+        Error *local_err = NULL;
+
          tb_freq = kvmppc_get_tbfreq();
-        clock_freq = kvmppc_get_clockfreq(NULL);
+        clock_freq = kvmppc_get_clockfreq(&local_err);
+
+        /* Use default clock if we're unable to read it from the DT */
+        if (local_err) {

may be report the error to the user ?

+            clock_freq = PPC440EP_CLOCK_FREQ;
+        }
      }
qemu_fdt_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency",


Reply via email to