qemu-devel
[Top][All Lists]
Advanced

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

[RFC PATCH-for-6.1 2/9] hw/core/machine: Add machine_create_constant_clo


From: Philippe Mathieu-Daudé
Subject: [RFC PATCH-for-6.1 2/9] hw/core/machine: Add machine_create_constant_clock() helper
Date: Fri, 9 Apr 2021 08:23:54 +0200

Boards usually have crystal oscillators (at fixed frequency)
feeding their various clocked components.

Add a helper to create such constant clocks in the machine.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/hw/boards.h | 17 +++++++++++++++++
 hw/core/machine.c   | 11 +++++++++++
 2 files changed, 28 insertions(+)

diff --git a/include/hw/boards.h b/include/hw/boards.h
index ad6c8fd5376..c8100f7a33a 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -11,6 +11,7 @@
 #include "qemu/module.h"
 #include "qom/object.h"
 #include "hw/core/cpu.h"
+#include "hw/clock.h"
 
 #define TYPE_MACHINE_SUFFIX "-machine"
 
@@ -83,6 +84,22 @@ bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState 
*dev);
 MemoryRegion *machine_consume_memdev(MachineState *machine,
                                      HostMemoryBackend *backend);
 
+/**
+ * machine_create_constant_clock:
+ * @machine: the parent machine
+ * @name: the clock object name
+ * @freq_hz: the clock frequency (in Hz)
+ *
+ * Helper function to create a new constant clock (fixed frequency
+ * of @freq_hz) and parent it to @machine. There is no need to call
+ * clock_setup_canonical_path on the returned clock as it is done
+ * by this function.
+ *
+ * @return the newly created clock
+ */
+Clock *machine_create_constant_clock(MachineState *machine,
+                                     const char *name, unsigned freq_hz);
+
 /**
  * CPUArchId:
  * @arch_id - architecture-dependent CPU ID of present or possible CPU
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 40def78183a..41baf80559d 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -1233,6 +1233,17 @@ void machine_run_board_init(MachineState *machine)
     phase_advance(PHASE_MACHINE_INITIALIZED);
 }
 
+Clock *machine_create_constant_clock(MachineState *machine,
+                                     const char *name, unsigned freq_hz)
+{
+    Clock *clk;
+
+    clk = clock_new(OBJECT(machine), name);
+    clock_set_hz(clk, freq_hz);
+
+    return clk;
+}
+
 static NotifierList machine_init_done_notifiers =
     NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
 
-- 
2.26.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]