diff mbox series

[6/9] ppc440_bamboo.c: handle clock freq read error in load_device_tree

Message ID 20220630194249.886747-7-danielhb413@gmail.com
State New
Headers show
Series cleanup error handling in kvmppc_read_int_cpu_dt() | expand

Commit Message

Daniel Henrique Barboza June 30, 2022, 7:42 p.m. UTC
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 <danielhb413@gmail.com>
---
 hw/ppc/ppc440_bamboo.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

Comments

Cédric Le Goater July 2, 2022, 6:23 a.m. UTC | #1
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 <danielhb413@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",
diff mbox series

Patch

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) {
+            clock_freq = PPC440EP_CLOCK_FREQ;
+        }
     }
 
     qemu_fdt_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency",