Clock framework API.
Subsystems (2)
v4 cover Clock framework API.
From: Damien Hedde <[email protected]>
This series corresponds to the v4 of "clock framework api" patches which were discussed in 2017, here:
https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg07218.html
It is a big refactoring trying to respond to comments and to integrate the clock gating cases I sent recently here:
https://lists.gnu.org/archive/html/qemu-devel/2018-07/msg05363.html
Note that, for now, the power cases are not considered in this patchset.
For the user, the framework is now very similar to the device's gpio API. Clocks inputs and outputs can be added in devices during initialization phase. Then an input can be connected to an output: it means every time the output clock changes, a callback in the input is trigerred allowing any action to be taken. A difference with gpios is that several inputs can be connected to a single output without doing any glue.
Compared to v3, the following notable changes happen:
- Bindings are now fixed during machine realisation,
- Input clock objects have been removed from the point of view of the
user, i.e. nothing need to be added in the device state. A device can now declare a input clock by calling qdev_init_clock_in() (similarly of what is done for GPIOs),
- Callbacks called on clock change now return void. The input owner is
responsible of making necessary updates accordingly (e.g. update another clock output, or modify its internal state) (again, mostly like GPIOs).
- For now, internal state have been removed. It could re-added as a
cached value to print it in info qtree, or to avoid unnecessary updates.
Behind the scene, there is 2 objects: a clock input which is a placeholder for a callback, and a clock output which is a list of inputs. The value transferred between an output and an input is a ClockState which contains 2 fields:
- an integer to store the frequency
- a boolean to indicate whether the clock domain reset is asserted or not
The reset flag has been added because it seems both signals are closely related and very often controlled by the same device.
Regarding the migration strategy, clocks do not hold the clock state internally, so there is nothing to migrate there. The consequence is that a device must update its output clocks in its post_load to propagate the migrated clock state. This allows migration from old-qemu-with-no-clock to new-qemu-with-clock-support: newly added clocks will be correctly initialized during migration.
But it is more complex for input clocks handling: there is no order guarantee between a device state migration and the update of its inputs clocks which will occur during other device state migrations.
I think that, for most the cases, this does not rise problems, although there might be some jitter/glitch during migration before hitting the right value (with consequences such as the baudrate of a character device changing several times during migration, I don't think it is a problem but may well be wrong here).
For example, if we have 2 devices A and B with a clock between them:
| dev A clk|>----->| dev B |
There is 2 migration scenarios (this can happen in our example implementation between the slcr and cadence_uart devices):
1. A before B:
- A is migrated:
+ A's state is loaded
+ A's post_load restore the clock which is propagated to B
+ B reacts to the clock change (eg: update serial baudrate with migrated clock value but old B state)
- B is migrated:
+ B's state is loaded
+ B's post_load reacts to new B's state (eg: update serial baudrate to the final right value)
2. B before A:
- B is migrated:
+ B's state is loaded
+ B's post_load reacts to ne B's state (eg: update serial baudrate with migrated B state but old clock value)
- A is migrated:
+ A's state is loaded
+ A's post_load restore the clock which is propagated to B
+ B reacts to the clock change (eg: update serial baudrate to the final right value)
Regarding clock gating. The 0 frequency value means the clock is gated. If need be, a gate device can be built taking an input gpio and clock and generating an output clock.
We are considering switching to a generic payload evolution of this API. For example by specifying the qom carried type when adding an input/output to a device. The current implementation is poorly dependent on what the data type is since only pointers are transferred between output and inputs. Changes would probably be minor.
This would allow us, for example, to add a power input port to handle power gating. We could also have the basic clock port (frequency-only) and the one we have here (frequency-reset).
Concerning this frequency-reset port, we can obviously go back to the simple frequency-only one if you think it is not a good idea.
I've tested this patchset running Xilinx's Linux on the xilinx-zynq-a9 machine. Clocks are correctly updated and we ends up with a configured baudrate of 115601 on the console uart (for a theorical 115200) which is nice. "cadence_uart*" and "clock*" traces can be enabled to see what's going on in this platform.
Any comments and suggestion are welcomed.
The patches are organised as follows:
+ Patches 1 to 4 adds the clock support in qemu.
+ Patch 5 add some documentation in docs/devel
+ Patch 6 adds support for a default clock in sysbus devices which control the mmios visibility.
+ Patches 7 to 10 adds the uart's clocks to the xilinx_zynq platform as an example for this framework. It updates the zynq's slcr clock controller, the cadence_uart device, and the zynq toplevel platform.
Thanks to the Xilinx QEMU team who sponsored this development.
Damien Hedde (10):
hw/core/clock-port: introduce clock port objects
qdev: add clock input&output support to devices.
qdev-monitor: print the device's clock with info qtree
qdev-clock: introduce an init array to ease the device construction docs/clocks: add device's clock documentation
sysbus: add bus_interface_clock feature to sysbus devices hw/misc/zynq_slcr: use standard register definition hw/misc/zynq_slcr: add clock generation for uarts hw/char/cadence_uart: add clock support hw/arm/xilinx_zynq: connect uart clocks to slcr
docs/devel/clock.txt | 144 ++++++++ Makefile.objs | 1 + include/hw/char/cadence_uart.h | 2 + include/hw/clock-port.h | 153 ++++++++ include/hw/qdev-clock.h | 129 +++++++ include/hw/qdev-core.h | 14 + include/hw/qdev.h | 1 + include/hw/sysbus.h | 22 ++ hw/arm/xilinx_zynq.c | 17 +- hw/char/cadence_uart.c | 73 +++- hw/core/clock-port.c | 145 ++++++++ hw/core/qdev-clock.c | 166 +++++++++ hw/core/qdev.c | 29 ++ hw/core/sysbus.c | 25 ++ hw/misc/zynq_slcr.c | 637 ++++++++++++++++++++------------- qdev-monitor.c | 6 + hw/char/trace-events | 3 + hw/core/Makefile.objs | 3 +- hw/core/trace-events | 6 + 19 files changed, 1324 insertions(+), 252 deletions(-) create mode 100644 docs/devel/clock.txt create mode 100644 include/hw/clock-port.h create mode 100644 include/hw/qdev-clock.h create mode 100644 hw/core/clock-port.c create mode 100644 hw/core/qdev-clock.c create mode 100644 hw/core/trace-events
Signature · 1 line
2.18.0
PATCH v4 1/10 hw/core/clock-port: introduce clock port objects
From: Damien Hedde <[email protected]>
Introduce clock port objects: ClockIn and ClockOut.
Theses ports may be used to distribute a clock from a object to several other objects. They do not contain any state and serve only as intermediate to carry a ClockState which contains 2 fields:
* an integer which represent the frequency in Hertz
* a boolean which represent the reset status of the clock domain Both are independent: eg the reset can be asserted while the clock running and vice versa.
A ClockIn may be connected to a ClockOut so that it receives update, through the callback, whenever the Clockout is updated using the ClockOut's set function.
This is based on the original work of Frederic Konrad.
--- Makefile.objs | 1 + include/hw/clock-port.h | 153 ++++++++++++++++++++++++++++++++++++++++ hw/core/clock-port.c | 145 +++++++++++++++++++++++++++++++++++++ hw/core/Makefile.objs | 1 + hw/core/trace-events | 6 ++ 5 files changed, 306 insertions(+) create mode 100644 include/hw/clock-port.h create mode 100644 hw/core/clock-port.c create mode 100644 hw/core/trace-events
Makefile.objs +1 -0
@@ -210,6 +210,7 @@ trace-events-subdirs += hw/audio trace-events-subdirs += hw/block trace-events-subdirs += hw/block/dataplane trace-events-subdirs += hw/char +trace-events-subdirs += hw/core trace-events-subdirs += hw/display trace-events-subdirs += hw/dma trace-events-subdirs += hw/hppa
include/hw/clock-port.h new file +153 -0
153 lines not on this page · raw message
hw/core/clock-port.c new file +145 -0
145 lines not on this page · raw message
hw/core/Makefile.objs +1 -0
@@ -6,6 +6,7 @@ common-obj-$(CONFIG_SOFTMMU) += fw-path-provider.o # irq.o needed for qdev GPIO handling: common-obj-y += irq.o common-obj-y += hotplug.o +common-obj-y += clock-port.o common-obj-$(CONFIG_SOFTMMU) += nmi.o common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
hw/core/trace-events new file +6 -0
@@ -0,0 +1,6 @@ +# See docs/devel/tracing.txt for syntax documentation. + +# hw/core/clock-port.c +clock_connect(const char *clk, const char *driver) "'%s' drived-by '%s'" +clock_disconnect(const char *clk) "'%s'" +clock_update(const char *clk, uint64_t freq, int reset) "'%s' frequency %" PRIu64 "Hz reset %d"
Signature · 1 line
2.18.0
Re: [Qemu-arm] [PATCH v4 01/10] hw/core/clock-port: introduce clock port objects
Quoted 65 lines · On 17 September 2018 at 09:40, <[email protected]> wrote:
From: Damien Hedde <[email protected]>
Introduce clock port objects: ClockIn and ClockOut.
Theses ports may be used to distribute a clock from a object to several other objects. They do not contain any state and serve only as intermediate to carry a ClockState which contains 2 fields:
* an integer which represent the frequency in Hertz
* a boolean which represent the reset status of the clock domain Both are independent: eg the reset can be asserted while the clock running and vice versa.A ClockIn may be connected to a ClockOut so that it receives update, through the callback, whenever the Clockout is updated using the ClockOut's set function.
This is based on the original work of Frederic Konrad.
Signed-off-by Damien Hedde <[email protected]>--- Makefile.objs | 1 + include/hw/clock-port.h | 153 ++++++++++++++++++++++++++++++++++++++++ hw/core/clock-port.c | 145 +++++++++++++++++++++++++++++++++++++ hw/core/Makefile.objs | 1 + hw/core/trace-events | 6 ++ 5 files changed, 306 insertions(+) create mode 100644 include/hw/clock-port.h create mode 100644 hw/core/clock-port.c create mode 100644 hw/core/trace-eventsMakefile.objs +1
-0@@ -210,6 +210,7 @@ trace-events-subdirs += hw/audio trace-events-subdirs += hw/block trace-events-subdirs += hw/block/dataplane trace-events-subdirs += hw/char +trace-events-subdirs += hw/core trace-events-subdirs += hw/display trace-events-subdirs += hw/dma trace-events-subdirs += hw/hppainclude/hw/clock-port.h new file +17
-0@@ -0,0 +1,153 @@ +#ifndef CLOCK_PORT_H +#define CLOCK_PORT_H + +#include "qom/object.h" +#include "hw/qdev-core.h" +#include "qemu/queue.h" + +#define TYPE_CLOCK_PORT "clock-port" +#define CLOCK_PORT(obj) OBJECT_CHECK(ClockPort, (obj), TYPE_CLOCK_PORT) +#define TYPE_CLOCK_IN "clock-in" +#define CLOCK_IN(obj) OBJECT_CHECK(ClockIn, (obj), TYPE_CLOCK_IN) +#define TYPE_CLOCK_OUT "clock-out" +#define CLOCK_OUT(obj) OBJECT_CHECK(ClockOut, (obj), TYPE_CLOCK_OUT) + +typedef struct ClockState { + uint64_t frequency; /* frequency of the clock in Hz */ + bool domain_reset; /* flag indicating if clock domain is under reset */
include/hw/clock-port.h line 27
Quoted 10 lines
include/hw/clock-port.h new file +10
-0+} ClockState; + +typedef void ClockCallback (void *opaque,ClockState *clk); + +typedef struct ClockPort { +/*< private >*/ +Object parent_obj; +/*< public >*/ +char *canonical_path;/* clock path shadow */ +}ClockPort ;
Having a ClockPort which ClockIn and ClockOut are derived from seems a bit heavyweight. When would you want to operate on a generic ClockPort rather than either a ClockIn or ClockOut ? Why would you want the name (canonical_path) to be different at the input and output ends -- is it possible to simplify to just having the output end keep the name string ?
hw/core/trace-events line 4
Quoted 7 lines
hw/core/trace-events new file +4
-0@@ -0,0 +1,6 @@ +# See docs/devel/tracing.txt for syntax documentation. + +# hw/core/clock-port.c +clock_connect(const char *clk, const char *driver) "'%s' drived-by '%s'"
"driven by"
Quoted 5 lines
hw/core/trace-events new file +2
-1+clock_disconnect(const char *clk) "'%s'" +clock_update(const char *clk, uint64_t freq, int reset) "'%s' frequency %" PRIu64 "Hz reset %d" --2.18.0
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 01/10] hw/core/clock-port: introduce clock port objects
Quoted 75 lines · Peter Maydell
Quoted 74 lines · On 17 September 2018 at 09:40, <[email protected]> wrote:
From: Damien Hedde <[email protected]>
Introduce clock port objects: ClockIn and ClockOut.
Theses ports may be used to distribute a clock from a object to several other objects. They do not contain any state and serve only as intermediate to carry a ClockState which contains 2 fields:
* an integer which represent the frequency in Hertz
* a boolean which represent the reset status of the clock domain Both are independent: eg the reset can be asserted while the clock running and vice versa.A ClockIn may be connected to a ClockOut so that it receives update, through the callback, whenever the Clockout is updated using the ClockOut's set function.
This is based on the original work of Frederic Konrad.
Signed-off-by Damien Hedde <[email protected]>--- Makefile.objs | 1 + include/hw/clock-port.h | 153 ++++++++++++++++++++++++++++++++++++++++ hw/core/clock-port.c | 145 +++++++++++++++++++++++++++++++++++++ hw/core/Makefile.objs | 1 + hw/core/trace-events | 6 ++ 5 files changed, 306 insertions(+) create mode 100644 include/hw/clock-port.h create mode 100644 hw/core/clock-port.c create mode 100644 hw/core/trace-eventsMakefile.objs +1
-0@@ -210,6 +210,7 @@ trace-events-subdirs += hw/audio trace-events-subdirs += hw/block trace-events-subdirs += hw/block/dataplane trace-events-subdirs += hw/char +trace-events-subdirs += hw/core trace-events-subdirs += hw/display trace-events-subdirs += hw/dma trace-events-subdirs += hw/hppainclude/hw/clock-port.h new file +26
-0@@ -0,0 +1,153 @@ +#ifndef CLOCK_PORT_H +#define CLOCK_PORT_H + +#include "qom/object.h" +#include "hw/qdev-core.h" +#include "qemu/queue.h" + +#define TYPE_CLOCK_PORT "clock-port" +#define CLOCK_PORT(obj) OBJECT_CHECK(ClockPort, (obj), TYPE_CLOCK_PORT) +#define TYPE_CLOCK_IN "clock-in" +#define CLOCK_IN(obj) OBJECT_CHECK(ClockIn, (obj), TYPE_CLOCK_IN) +#define TYPE_CLOCK_OUT "clock-out" +#define CLOCK_OUT(obj) OBJECT_CHECK(ClockOut, (obj), TYPE_CLOCK_OUT) + +typedef struct ClockState { + uint64_t frequency; /* frequency of the clock in Hz */ + bool domain_reset; /* flag indicating if clock domain is under reset */ +} ClockState; + +typedef void ClockCallback(void *opaque, ClockState *clk); + +typedef struct ClockPort { + /*< private >*/ + Object parent_obj; + /*< public >*/ + char *canonical_path; /* clock path shadow */
Quoted 8 lines
include/hw/clock-port.h line 27
Quoted 1 line
include/hw/clock-port.h new file +1
-0+} ClockPort;Having a ClockPort which ClockIn and ClockOut are derived from seems a bit heavyweight. When would you want to operate on a generic ClockPort rather than either a ClockIn or ClockOut ? Why would you want the name (
canonical_path) to be different at the input and output ends -- is it possible to simplify to just having the output end keep the name string ?
Here the canonical path is the full qom's canonical path. It is cached in the state to avoid recomputing it when needed. It is only used for log/trace purpose (without it, log is useless and calling object_get_canonical_path at every log seemed too costly to me). A connected ClockOut and ClockIn do not have the same (qom) parent, their canonical path is different.
For example, in the zynq platform, there are 2 uarts, each one having a
"refclk" input. There is also a clock controller (slcr) having 2
outputs "uart0_ref_clk" and "uart1_ref_clk". We end up with something like this concerning canonical path:
+ output "[...]/slcr/uart0_ref_clk" drives input "[...]/uart0/refclk"
+ output "[...]/slcr/uart1_ref_clk" drives input "[...]/uart1/refclk"
Right now, I log a line for every end (output and input) when the clock frequency change, which lead to a kind-of-duplicate log line (names differ, but clock frequencies are obviously the same). I could only log at the output end and drop the canonical path for the input or pust the path in both objects.
Anyway it is easily possible to drop the ClockPort common ancestor. A user never operates on it.
Quoted 20 lines
hw/core/trace-events line 4
Quoted 8 lines
hw/core/trace-events new file +4
-0@@ -0,0 +1,6 @@ +# See docs/devel/tracing.txt for syntax documentation. + +# hw/core/clock-port.c +clock_connect(const char *clk, const char *driver) "'%s' drived-by '%s'""driven by"
Quoted 5 lines
hw/core/trace-events new file +2
-1+clock_disconnect(const char *clk) "'%s'" +clock_update(const char *clk, uint64_t freq, int reset) "'%s' frequency %" PRIu64 "Hz reset %d" --2.18.0
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 01/10] hw/core/clock-port: introduce clock port objects
Quoted 23 lines · Damien Hedde
Quoted 6 lines · Peter Maydell
Having a ClockPort which ClockIn and ClockOut are derived from seems a bit heavyweight. When would you want to operate on a generic ClockPort rather than either a ClockIn or ClockOut ? Why would you want the name (
canonical_path) to be different at the input and output ends -- is it possible to simplify to just having the output end keep the name string ?Here the canonical path is the full qom's canonical path. It is cached in the state to avoid recomputing it when needed. It is only used for log/trace purpose (without it, log is useless and calling
object_get_canonical_pathat every log seemed too costly to me). A connected ClockOut and ClockIn do not have the same (qom) parent, their canonical path is different.
For example, in the zynq platform, there are 2 uarts, each one having a
"refclk" input. There is also a clock controller (slcr) having 2
outputs "uart0_ref_clk" and "uart1_ref_clk". We end up with something like this concerning canonical path:
+ output "[...]/slcr/uart0_ref_clk" drives input "[...]/uart0/refclk"
+ output "[...]/slcr/uart1_ref_clk" drives input "[...]/uart1/refclk"
Quoted 8 lines
Right now, I log a line for every end (output and input) when the clock frequency change, which lead to a kind-of-duplicate log line (names differ, but clock frequencies are obviously the same). I could only log at the output end and drop the canonical path for the input or pust the path in both objects.
Anyway it is easily possible to drop the ClockPort common ancestor. A user never operates on it.
I think that would be preferable -- having the debug logging drive the object hierarchy setup seems like the tail wagging the dog to me.
thanks
-- PMM
PATCH v4 2/10 qdev: add clock input&output support to devices.
In reply to [email protected]From: Damien Hedde <[email protected]>
Add functions to easily add input or output clocks to a device. The clock port objects are added as children of the device.
A function allows to connect two clocks together.
It should be called by some toplevel to make a connection between 2 (sub-)devices.
Also add a function which forwards a port to another device. This function allows, in the case of device composition, to expose a sub-device clock port as its own clock port.
This is really an alias: when forwarding an input, only one callback can be registered on it since there is only one Clockin object behind all aliases.
This is based on the original work of Frederic Konrad.
--- include/hw/qdev-clock.h | 62 ++++++++++++++++++ include/hw/qdev-core.h | 14 ++++ include/hw/qdev.h | 1 + hw/core/qdev-clock.c | 140 ++++++++++++++++++++++++++++++++++++++++ hw/core/qdev.c | 29 +++++++++ hw/core/Makefile.objs | 2 +- 6 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 include/hw/qdev-clock.h create mode 100644 hw/core/qdev-clock.c
include/hw/qdev-clock.h new file +62 -0
@@ -0,0 +1,62 @@ +#ifndef QDEV_CLOCK_H +#define QDEV_CLOCK_H + +#include "hw/clock-port.h" +#include "hw/qdev-core.h" +#include "qapi/error.h" + +/** +* qdev_init_clock_in: +* @dev: the device in which to add a clock +* @name: the name of the clock (can't be NULL). +* @callback: optional callback to be called on update or NULL. +* @opaque: argument for the callback +* @returns: a pointer to the newly added clock +* +* Add a input clock to device @dev as a clock named @name. +* This adds a child<> property. +* The callback will be called with @dev as opaque parameter. +*/ +ClockIn *qdev_init_clock_in (DeviceState *dev,const char *name, +ClockCallback *callback,void *opaque); + +/** +* qdev_init_clock_out: +* @dev: the device to add a clock to +* @name: the name of the clock (can't be NULL). +* @callback: optional callback to be called on update or NULL. +* @returns: a pointer to the newly added clock +* +* Add a output clock to device @dev as a clock named @name. +* This adds a child<> property. +*/ +ClockOut *qdev_init_clock_out (DeviceState *dev,const char *name); + +/** +* qdev_init_clock_forward: +* @dev: the device to forward the clock to +* @name: the name of the clock to be added (can't be NULL) +* @origin: the device which already has the clock +* @origin_name: the name of the clock in the src device +* +* Add a clock @name to @dev which forward to the clock @origin_name in @origin +*/ +void qdev_init_clock_forward (DeviceState *dev,const char *name, +DeviceState *origin,const char *origin_name); + +/** +* qdev_clock_connect: +* @dev: the drived clock device. +* @name: the drived clock name. +* @driver: the driving clock device. +* @driver_name: the driving clock name. +* @errp: error report +* +* Setup @driver_name output clock of @driver to drive @name input clock of +* @dev. Errors are trigerred if clock does not exists +*/ +void qdev_clock_connect (DeviceState *dev,const char *name, +DeviceState *driver,const char *driver_name, +Error **errp); + +#endif /* QDEV_CLOCK_H */
include/hw/qdev-core.h +14 -0
@@ -127,6 +127,19 @@ struct NamedGPIOList {QLIST_ENTRY (NamedGPIOList) node; }; +typedef struct NamedClockList NamedClockList ; + +typedef struct ClockIn ClockIn ; +typedef struct ClockOut ClockOut ; + +struct NamedClockList { +char *name; +bool forward; +ClockIn *in; +ClockOut *out; +QLIST_ENTRY (NamedClockList) node; +}; +/** * DeviceState: * @realized: Indicates whether the device has been fully constructed.
@@ -147,6 +160,7 @@ struct DeviceState {int hotplugged;BusState *parent_bus; QLIST_HEAD(, NamedGPIOList) gpios; + QLIST_HEAD(, NamedClockList) clocks; QLIST_HEAD(, BusState) child_bus;int num_child_bus;int instance_id_alias;
include/hw/qdev.h +1 -0
@@ -4,5 +4,6 @@#include "hw/hw.h" #include "hw/qdev-core.h" #include "hw/qdev-properties.h" +#include "hw/qdev-clock.h" #endif
hw/core/qdev-clock.c new file +140 -0
140 lines not on this page · raw message
hw/core/qdev.c +29 -0
@@ -790,6 +790,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp)DeviceClass *dc =DEVICE_GET_CLASS (dev);HotplugHandler *hotplug_ctrl;BusState *bus; +NamedClockList *clk;Error *local_err =NULL ;bool unattached_parent = false;static int unattached_count;
@@ -846,6 +847,15 @@ static void device_set_realized(Object *obj, bool value, Error **errp)*/ g_free (dev->canonical_path); dev->canonical_path =object_get_canonical_path (OBJECT (dev)); + QLIST_FOREACH(clk, &dev->clocks, node) { +if (clk->forward) { +continue ; + }else if (clk->in !=NULL ) { +clock_setup_canonical_path (CLOCK_PORT (clk->in)); + }else { +clock_setup_canonical_path (CLOCK_PORT (clk->out)); + } + }if (qdev_get_vmsd (dev)) { if (vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
@@ -972,6 +982,7 @@ static void device_initfn(Object *obj) (Object **)&dev->parent_bus,NULL ,0 , &error_abort);QLIST_INIT (&dev->gpios); +QLIST_INIT (&dev->clocks); }static void device_post_init (Object *obj)
@@ -983,6 +994,7 @@ static void device_post_init(Object *obj)static void device_finalize (Object *obj) {NamedGPIOList *ngl, *next; +NamedClockList *clk, *clk_next;DeviceState *dev =DEVICE (obj);
@@ -996,6 +1008,23 @@ static void device_finalize(Object *obj)*/ } + QLIST_FOREACH_SAFE(clk, &dev->clocks, node, clk_next) { +QLIST_REMOVE (clk, node); +if (!clk->forward && clk->in) { +/* +* if this clock is not forwarded, clk->in & clk->out are child of +* dev. +* At this point the properties and associated reference are +* already deleted but we kept a ref on clk->in to ensure we +* don't have a lost callback to a deleted device somewhere. +*/ +clock_clear_callback (clk->in); +object_unref (OBJECT (clk->in)); + } +g_free (clk->name); +g_free (clk); + } +/* Only send event if the device had been completely realized */ if (dev->pending_deleted_event) {g_assert (dev->canonical_path);
hw/core/Makefile.objs +1 -1
@@ -1,5 +1,5 @@ # core qdev-related obj files, also used by *-user: -common-obj-y += qdev.o qdev-properties.o +common-obj-y += qdev.o qdev-properties.o qdev-clock.o common-obj-y += bus.o reset.o common-obj-$(CONFIG_SOFTMMU) += qdev-fw.o common-obj-$(CONFIG_SOFTMMU) += fw-path-provider.o
Signature · 1 line
2.18.0
PATCH v4 3/10 qdev-monitor: print the device's clock with info qtree
In reply to [email protected]From: Damien Hedde <[email protected]>
This prints the clocks attached to a DeviceState when using "info qtree" monitor command. For every clock, it displays the direction, the name and if the clock is forwarded.
This is based on the original work of Frederic Konrad.
--- qdev-monitor.c | 6 ++++++ 1 file changed, 6 insertions(+)
qdev-monitor.c +6 -0
@@ -682,6 +682,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)ObjectClass *class;BusState *child;NamedGPIOList *ngl; +NamedClockList *clk;qdev_printf ("dev: %s, id \"%s\"\n" ,object_get_typename (OBJECT (dev)), dev->id ? dev->id :"" );
@@ -696,6 +697,11 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) ngl->num_out); } } + QLIST_FOREACH(clk, &dev->clocks, node) { +qdev_printf ("clock-%s \"%s\"%s\n" , + clk->out ?"out" :"in" , clk->name, + clk->forward ?" FW" :"" ); + } class =object_get_class (OBJECT (dev)); do { qdev_print_props(mon, dev, DEVICE_CLASS(class)->props, indent);
Signature · 1 line
2.18.0
PATCH v4 4/10 qdev-clock: introduce an init array to ease the device construction
In reply to [email protected]From: Damien Hedde <[email protected]>
Introduce a function and macro helpers to setup several clocks in a device from a static array description.
An element of the array describes the clock (name and direction) as well as the related callback and an optional offset to store the created object pointer in the device state structure.
The array must be terminated by a special element QDEV_CLOCK_END.
This is based on the original work of Frederic Konrad.
--- include/hw/qdev-clock.h | 67 +++++++++++++++++++++++++++++++++++++++++ hw/core/qdev-clock.c | 26 ++++++++++++++++ 2 files changed, 93 insertions(+)
include/hw/qdev-clock.h +67 -0
@@ -59,4 +59,71 @@ void qdev_clock_connect(DeviceState *dev, const char *name, DeviceState *driver, const char *driver_name, Error **errp); +/** +* ClockInitElem: +* @name: name of the clock (can't be NULL) +* @output: indicates whether the clock is input or output +* @callback: for inputs, optional callback to be called on clock's update +* with device as opaque +* @offset: optional offset to store the clock pointer in device'state +* structure (0 means unused) +*/ +struct ClockPortInitElem { +const char *name; +bool output; +ClockCallback *callback; +size_t offset; +}; + +#define clock_offset_value (_type, _devstate, _field) \ + (offsetof(_devstate, _field) + \ + type_check(_type *, typeof_field(_devstate, _field))) + +#define QDEV_CLOCK (_output, _type, _devstate, _field, _callback) { \ + .name = (stringify(_field)), \ + .output = _output, \ + .callback = _callback, \ + .offset = clock_offset_value(_type, _devstate, _field), \ +} + +/** +* QDEV_CLOCK_(IN|OUT): +* @_devstate: structure type. @dev argument of qdev_init_clocks below must be +* a pointer to that same type. +* @_field: a field in @_devstate (must be ClockIn* or ClockOut*) +* @_callback: (for input only) callback (or NULL) to be called with the device +* state as argument +* +* The name of the clock will be derived from @_field +*/ +#define QDEV_CLOCK_IN (_devstate, _field, _callback) \ + QDEV_CLOCK(false, ClockIn, _devstate, _field, _callback) + +#define QDEV_CLOCK_OUT (_devstate, _field) \ + QDEV_CLOCK(true, ClockOut, _devstate, _field, NULL) + +/** +* QDEV_CLOCK_IN_NOFIELD: +* @_name: name of the clock +* @_callback: callback (or NULL) to be called with the device state as argument +*/ +#define QDEV_CLOCK_IN_NOFIELD (_name, _callback) { \ + .name = _name, \ + .output = false, \ + .callback = _callback, \ + .offset = 0, \ +} + +#define QDEV_CLOCK_END { .name = NULL } + +typedef struct ClockPortInitElem ClockPortInitArray []; + +/** +* qdev_init_clocks: +* @dev: the device to add clocks +* @clocks: a QDEV_CLOCK_END-terminated array which contains the +* clocks information. +*/ +void qdev_init_clocks (DeviceState *dev,const ClockPortInitArray clocks); +#endif /* QDEV_CLOCK_H */
hw/core/qdev-clock.c +26 -0
@@ -138,3 +138,29 @@ void qdev_clock_connect(DeviceState *dev, const char *name,clock_connect (ncl->in , drv_ncl->out); } + +void qdev_init_clocks (DeviceState *dev,const ClockPortInitArray clocks) +{ +const struct ClockPortInitElem *elem; + +assert (dev); +assert (clocks); + +for (elem = &clocks[0 ]; elem->name !=NULL ; elem++) { +/* offset cannot be inside the DeviceState part */ +assert (elem->offset ==0 || elem->offset >sizeof (DeviceState)); +if (elem->output) { +ClockOut *clk; + clk =qdev_init_clock_out (dev, elem->name); +if (elem->offset) { + *(ClockOut **)(((void *) dev) + elem->offset) = clk; + } + }else { +ClockIn *clk; + clk =qdev_init_clock_in (dev, elem->name, elem->callback, dev); +if (elem->offset) { + *(ClockIn **)(((void *) dev) + elem->offset) = clk; + } + } + } +}
Signature · 1 line
2.18.0
PATCH v4 5/10 docs/clocks: add device's clock documentation
In reply to [email protected]From: Damien Hedde <[email protected]>
Add the documentation about the clock inputs and outputs in devices.
This is based on the original work of Frederic Konrad.
--- docs/devel/clock.txt | 144 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 docs/devel/clock.txt
docs/devel/clock.txt new file +144 -0
@@ -0,0 +1,144 @@ + +What are device's clocks +======================== + +Clocks are ports representing input and output clocks of a device. They are QOM +objects developed for the purpose of modeling the distribution of clocks in +QEMU. + +It allows to model the clock distribution of a platform and detect configuration +errors in the clock tree such as badly configured PLL, clock source selection or +disabled clock. + +The objects are CLOCK_IN for the input and CLOCK_OUT for the output. + +The clock value: ClockState +=========================== + +The ClockState is the structure carried by the CLOCK_OUT and CLOCK_IN objects. + +It actually contains two fields: ++ an integer representing the frequency of the clock in Hertz, ++ and a boolean representing the clock domain reset assertion signal. + +It only simulates the clock by transmitting the frequency value and +doesn't model the signal itself such as pin toggle or duty cycle. +The special value 0 as a frequency is legal and represent the clock being +inactive or gated. + +Reset is also carried in the structure since both signals are closely related. +But they remain value-independent, the frequency can be non-zero and the reset +asserted as well as the opposite. + +Adding clocks to a device +========================= + +Adding clocks to a device must be done during the init phase of the Device +object. + +To add an input clock to a device, the function qdev_init_clock_in must be used. +It takes the name, a callback, and an opaque parameter for the clock. +output is more simple, only the name is required. Typically: +qdev_init_clock_in(DEVICE(dev), "clk-in", clk_in_callback, dev); +qdev_init_clock_out(DEVICE(dev), "clk-out"); + +Both functions return the created CLOCK_IN/OUT pointer. For an output, it should +be saved in the device's state structure in order to be able to change the +clock. For an input, it can be saved it one need to change the callback. + +Note that it is possible to create a static array describing clock inputs and +outputs. The function qdev_init_clocks must be called with the array as +parameters to initialize the clocks: it has the same behaviour as calling the +qdev_init_clock/out for each clock. + +Forwarding clocks +================= + +Sometimes, one needs to forward, or inherit, a clock from another device. +Typically, when doing device composition, a device might exposes a sub-device's +clock without interfering with it. +The function qdev_init_clock_forward can be used to achieve this behaviour. +Note, that it is possible to expose the clock under a different name. +This works for both inputs or outputs. + +For example, if device B is a child of device A, device_a_instance_init may +do something like this: +void device_a_instance_init(Object *obj) +{ + AState *A = DEVICE_A(obj); + BState *B; + [...] /* create B object as child of A */ + qdev_init_clock_forward(A, "b_clk", B, "clk"); + /* + * Now A has a clock "b_clk" which forwards to + * the "clk" of its child B. + */ +} + +This function does not returns any clock object. It is not possible to add +a callback on a forwarded input clock. + +Connecting two clocks together +============================== + +Let's say we have 2 devices A and B. A has an output clock named "clkout" and B +has an input clock named "clkin". + +The clocks are connected together using the function qdev_clock_connect: +qdev_clock_connect(B, "clkin", A, "clkout", &error_abort); +The device which has the input must be the first argument. + +It is possible to connect several input clock to the same output. Every +input callback will be called during the output changes. + +It is not possible to disconnect a clock neither to change the clock connection +after it is done. + +Changing a clock output +======================= + +A device can change its outputs using the clock_set function. It will trigger +updates on any connected inputs. + +For example, let's say that we have an output clock "clkout" and we have pointer +on it in the device state because we did the following in init phase: +dev->clkout = qdev_init_clock_out(DEVICE(dev), "clkout"); + +Then at any time, it is possible to change the clock value by doing: +ClockState state; +state.frequency = 1000 * 1000 * 1000; /* 1MHz */ +clock_set(dev->clkout, &state); + +Outputs must be initialized in the device_reset method to ensure every connected +inputs is updated at machine startup. + +Callback on input clock change +============================== + +Here is an example of an input callback: +void clock_callback(void *opaque, ClockState *state) { + MyDeviceState *s = (MyDeviceState *) opaque; + /* + * opaque may not be the device state pointer, but most probably it is. + * (It depends on what is given to the qdev_init_clock_in function) + */ + + /* do something with the state */ + fprintf(stdout, "device new frequency is %" PRIu64 "Hz\n", + clock_state_get_frequency(state)); + + /* optionally store the value for later use in our state */ + clock_state_copy(&s->clkin_shadow, state); +} + +The state argument needs only to be copied if the device needs to use the value +later: the state pointer argument of the pointer will not be valid anymore +after the end of the function. + +Migration +========= + +State is not stored in clock input or output. A device is responsible for +setting its output clock correctly in the post_load function (using clock_set) +after its state has been loaded. This way, during the migration process, all +clocks will be correctly restored.
Signature · 1 line
2.18.0
Re: [Qemu-devel] [PATCH v4 05/10] docs/clocks: add device's clock documentation
Quoted 7 lines · On 17 September 2018 at 09:40, <[email protected]> wrote:
From: Damien Hedde <[email protected]>
Add the documentation about the clock inputs and outputs in devices.
This is based on the original work of Frederic Konrad.
Signed-off-by Damien Hedde <[email protected]>
I thought I might as well review the docs changes, since they're a good overview of the API. I have one or two semantic changes to suggest, a few function name alterations and some minor typo fixes below.
Quoted 11 lines
--- docs/devel/clock.txt | 144 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 docs/devel/clock.txtdocs/devel/clock.txt new file +0
-0
docs/devel/clock.txt line 9
Quoted 9 lines
docs/devel/clock.txt new file +9
-0@@ -0,0 +1,144 @@ + +What are device's clocks +======================== + +Clocks are ports representing input and output clocks of a device. They are QOM +objects developed for the purpose of modeling the distribution of clocks in +QEMU. + +It allows to model the clock distribution of a platform and detect configuration
"This allows us to model"
Quoted 22 lines
docs/devel/clock.txt new file +22
-0+errors in the clock tree such as badly configured PLL, clock source selection or +disabled clock. + +The objects are CLOCK_IN for the input and CLOCK_OUT for the output. + +The clock value: ClockState +=========================== + +The ClockState is the structure carried by the CLOCK_OUT and CLOCK_IN objects. + +It actually contains two fields: ++ an integer representing the frequency of the clock in Hertz, ++ and a boolean representing the clock domain reset assertion signal. + +It only simulates the clock by transmitting the frequency value and +doesn't model the signal itself such as pin toggle or duty cycle. +The special value 0 as a frequency is legal and represent the clock being +inactive or gated. + +Reset is also carried in the structure since both signals are closely related. +But they remain value-independent, the frequency can be non-zero and the reset +asserted as well as the opposite.
docs/devel/clock.txt line 41
Quoted 10 lines
docs/devel/clock.txt new file +10
-0+ +Adding clocks to a device +========================= + +Adding clocks to a device must be done during the init phase of the Device +object. + +To add an input clock to a device, the function qdev_init_clock_in must be used. +It takes the name, a callback, and an opaque parameter for the clock. +output is more simple, only the name is required. Typically:
"Output"
docs/devel/clock.txt line 47
Quoted 6 lines
docs/devel/clock.txt new file +6
-0+qdev_init_clock_in(DEVICE(dev), "clk-in", clk_in_callback, dev); +qdev_init_clock_out(DEVICE(dev), "clk-out"); + +Both functions return the created CLOCK_IN/OUT pointer. For an output, it should +be saved in the device's state structure in order to be able to change the +clock. For an input, it can be saved it one need to change the callback.
I think we should just simplify this to say that "pointer, which should be saved in the device's state structure."
(Is freeing of the allocated memory handled by the usual QOM reference-counting ?)
docs/devel/clock.txt line 58
Quoted 11 lines
docs/devel/clock.txt new file +11
-0+ +Note that it is possible to create a static array describing clock inputs and +outputs. The function qdev_init_clocks must be called with the array as +parameters to initialize the clocks: it has the same behaviour as calling the +qdev_init_clock/out for each clock. + +Forwarding clocks +================= + +Sometimes, one needs to forward, or inherit, a clock from another device. +Typically, when doing device composition, a device might exposes a sub-device's
"expose"
Quoted 11 lines
docs/devel/clock.txt new file +11
-0+clock without interfering with it. +The function qdev_init_clock_forward can be used to achieve this behaviour. +Note, that it is possible to expose the clock under a different name. +This works for both inputs or outputs. + +For example, if device B is a child of device A, device_a_instance_init may +do something like this: +void device_a_instance_init(Object *obj) +{ + AState *A = DEVICE_A(obj); + BState *B;
docs/devel/clock.txt line 79
Quoted 10 lines
docs/devel/clock.txt new file +10
-0+ [...] /* create B object as child of A */ + qdev_init_clock_forward(A, "b_clk", B, "clk"); + /* + * Now A has a clock "b_clk" which forwards to + * the "clk" of its child B. + */ +} + +This function does not returns any clock object. It is not possible to add +a callback on a forwarded input clock.
I suggest naming this function qdev_pass_clock():
* it isn't doing the same thing qdev_init_clock_in/out do (which return a clock object)
* this brings the name into line with the similar qdev_pass_gpios()
docs/devel/clock.txt line 88
Quoted 9 lines
docs/devel/clock.txt new file +9
-0+ +Connecting two clocks together +============================== + +Let's say we have 2 devices A and B. A has an output clock named "clkout" and B +has an input clock named "clkin". + +The clocks are connected together using the function qdev_clock_connect: +qdev_clock_connect(B, "clkin", A, "clkout", &error_abort);
I suggest calling this qdev_connect_clock() (which then parallels the existing qdev_connect_gpio_out*())
docs/devel/clock.txt line 91
Quoted 3 lines
docs/devel/clock.txt new file +3
-0+The device which has the input must be the first argument. + +It is possible to connect several input clock to the same output. Every
"clocks"
docs/devel/clock.txt line 92
Quoted 1 line
docs/devel/clock.txt new file +1
-0+input callback will be called during the output changes.
"when"
docs/devel/clock.txt line 94
Quoted 2 lines
docs/devel/clock.txt new file +2
-0+ +It is not possible to disconnect a clock neither to change the clock connection
"or", not "neither"
docs/devel/clock.txt line 103
Quoted 9 lines
docs/devel/clock.txt new file +9
-0+after it is done. + +Changing a clock output +======================= + +A device can change its outputs using the clock_set function. It will trigger +updates on any connected inputs. + +For example, let's say that we have an output clock "clkout" and we have pointer
"a pointer to it"
docs/devel/clock.txt line 110
Quoted 7 lines
docs/devel/clock.txt new file +7
-0+on it in the device state because we did the following in init phase: +dev->clkout = qdev_init_clock_out(DEVICE(dev), "clkout"); + +Then at any time, it is possible to change the clock value by doing: +ClockState state; +state.frequency = 1000 * 1000 * 1000; /* 1MHz */ +clock_set(dev->clkout, &state);
This seems a bit indirect. Why doesn't clock_set() just take the frequency as a direct argument ?
docs/devel/clock.txt line 113
Quoted 3 lines
docs/devel/clock.txt new file +3
-0+ +Outputs must be initialized in the device_reset method to ensure every connected +inputs is updated at machine startup.
device_reset should not set outputs.
Quoted 8 lines
docs/devel/clock.txt new file +8
-0+ +Callback on input clock change +============================== + +Here is an example of an input callback: +void clock_callback(void *opaque, ClockState *state) { + MyDeviceState *s = (MyDeviceState *) opaque; + /*
docs/devel/clock.txt line 131
Quoted 10 lines
docs/devel/clock.txt new file +10
-0+ * opaque may not be the device state pointer, but most probably it is. + * (It depends on what is given to the qdev_init_clock_in function) + */ + + /* do something with the state */ + fprintf(stdout, "device new frequency is %" PRIu64 "Hz\n", + clock_state_get_frequency(state)); + + /* optionally store the value for later use in our state */ + clock_state_copy(&s->clkin_shadow, state);
This seems odd to me. Why do we have a clock_state_copy() at all? The input end of a device has a pointer to the input end of the clock, and there should just be a function for "what is the current frequency of this CLOCK_IN ?".
The callback function should probably be passed a parameter which is the CLOCK_IN it corresponds to, not an arbitrary ClockState. (I'm not sure how useful the ClockState struct is.)
Quoted 14 lines
docs/devel/clock.txt new file +13
-1+} + +The state argument needs only to be copied if the device needs to use the value +later: the state pointer argument of the pointer will not be valid anymore +after the end of the function. + +Migration +========= + +State is not stored in clock input or output. A device is responsible for +setting its output clock correctly in the post_load function (using clock_set) +after its state has been loaded. This way, during the migration process, all +clocks will be correctly restored. --
Quoted 2 lines
2.18.0
thanks
-- PMM
Re: [Qemu-arm] [Qemu-devel] [PATCH v4 05/10] docs/clocks: add device's clock documentation
Quoted 5 lines · Peter Maydell
Quoted 4 lines · On 17 September 2018 at 09:40, <[email protected]> wrote:
From: Damien Hedde <[email protected]>
Add the documentation about the clock inputs and outputs in devices.
Quoted 8 lines
Quoted 3 lines
This is based on the original work of Frederic Konrad.
Signed-off-by Damien Hedde <[email protected]>I thought I might as well review the docs changes, since they're a good overview of the API. I have one or two semantic changes to suggest, a few function name alterations and some minor typo fixes below.
I've only kept the parts I'm responding to. I'll do the suggested name changes.
Quoted 35 lines
Quoted 12 lines
--- docs/devel/clock.txt | 144 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 docs/devel/clock.txtdocs/devel/clock.txt new file +0
-0docs/devel/clock.txt line 10
Quoted 10 lines
docs/devel/clock.txt new file +10
-0@@ -0,0 +1,144 @@ + +Adding clocks to a device +========================= + +Adding clocks to a device must be done during the init phase of the Device +object. + +To add an input clock to a device, the function qdev_init_clock_in must be used. +It takes the name, a callback, and an opaque parameter for the clock. +output is more simple, only the name is required. Typically:"Output"
docs/devel/clock.txt line 47
Quoted 6 lines
docs/devel/clock.txt new file +6
-0+qdev_init_clock_in(DEVICE(dev), "clk-in", clk_in_callback, dev); +qdev_init_clock_out(DEVICE(dev), "clk-out"); + +Both functions return the created CLOCK_IN/OUT pointer. For an output, it should +be saved in the device's state structure in order to be able to change the +clock. For an input, it can be saved it one need to change the callback.I think we should just simplify this to say that "pointer, which should be saved in the device's state structure."
Quoted 2 lines
(Is freeing of the allocated memory handled by the usual QOM reference-counting ?)
Yes. I will add a note to signal not to worry about that.
Quoted 12 lines
docs/devel/clock.txt line 103
Quoted 9 lines
docs/devel/clock.txt new file +8
-0+ +Changing a clock output +======================= + +A device can change its outputs using the clock_set function. It will trigger +updates on any connected inputs. + +For example, let's say that we have an output clock "clkout" and we have pointer"a pointer to it"
Quoted 11 lines
docs/devel/clock.txt line 110
Quoted 7 lines
docs/devel/clock.txt new file +7
-0+on it in the device state because we did the following in init phase: +dev->clkout = qdev_init_clock_out(DEVICE(dev), "clkout"); + +Then at any time, it is possible to change the clock value by doing: +ClockState state; +state.frequency = 1000 * 1000 * 1000; /* 1MHz */ +clock_set(dev->clkout, &state);This seems a bit indirect. Why doesn't
clock_set()just take the frequency as a direct argument ?
The structure ClockState is here because it contains 2 fields (frequency value and reset flag).
Since I am removing the reset, I can replace ClockState pointer by the frequency integer as you say.
Quoted 6 lines
docs/devel/clock.txt line 113
Quoted 4 lines
docs/devel/clock.txt new file +3
-0+ +Outputs must be initialized in the device_reset method to ensure every connected +inputs is updated at machine startup.
device_resetshould not set outputs.
How do the initialization then ?
Only alternative I see is to initialize a clock input when it is connected to an output.
If device_reset does not set outputs (which are a direct consequence of a internal device state being reset). It means calling device_reset at any other point than simulation startup will break things. Is that the semantic behind device_reset ?
Quoted 26 lines
Quoted 9 lines
docs/devel/clock.txt new file +8
-0+ +Callback on input clock change +============================== + +Here is an example of an input callback: +void clock_callback(void *opaque, ClockState *state) { + MyDeviceState *s = (MyDeviceState *) opaque; + /*docs/devel/clock.txt line 131
Quoted 10 lines
docs/devel/clock.txt new file +10
-0+ * opaque may not be the device state pointer, but most probably it is. + * (It depends on what is given to the qdev_init_clock_in function) + */ + + /* do something with the state */ + fprintf(stdout, "device new frequency is %" PRIu64 "Hz\n", + clock_state_get_frequency(state)); + + /* optionally store the value for later use in our state */ + clock_state_copy(&s->clkin_shadow, state);This seems odd to me. Why do we have a
clock_state_copy()at all? The input end of a device has a pointer to the input end of the clock, and there should just be a function for "what is the current frequency of thisCLOCK_IN?".
Quoted 4 lines
The callback function should probably be passed a parameter which is the
CLOCK_INit corresponds to, not an arbitrary ClockState. (I'm not sure how useful the ClockState struct is.)
Right now, there is no clock state in the input end and in consequence no way to have current frequency. Hence, if one wants to access the frequency later on, he has to save it himself.
Since we're talking to add the state in the clock object to handle the migration, the copy function become useless too and we may also drop the ClockState pointer argument because we will be able to request the current frequency.
Thanks
--
Damien
Re: [Qemu-arm] [Qemu-devel] [PATCH v4 05/10] docs/clocks: add device's clock documentation
Quoted 9 lines · Damien Hedde
Quoted 5 lines · Peter Maydell
docs/devel/clock.txt line 113
Quoted 2 lines · On 17 September 2018 at 09:40, <[email protected]> wrote:
docs/devel/clock.txt new file +2
-0+Outputs must be initialized in the device_reset method to ensure every connected +inputs is updated at machine startup.
device_resetshould not set outputs.
Quoted 8 lines
How do the initialization then ?
Only alternative I see is to initialize a clock input when it is connected to an output.If
device_resetdoes not set outputs (which are a direct consequence of a internal device state being reset). It means callingdevice_resetat any other point than simulation startup will break things. Is that the semantic behinddevice_reset?
device_reset's semantics are not great, but basically they are "power on reset", equivalent to a complete simulation restart. If a device has some other kind of warm reset triggered by eg a register write it needs to implement that itself, perhaps sharing code with the device reset method. A warm reset triggered by a register write can obviously assert output signals.
I have some thoughts about trying to clean up our reset semantics which I need to write up later this week.
thanks
-- PMM
PATCH v4 6/10 sysbus: add bus_interface_clock feature to sysbus devices
In reply to [email protected]From: Damien Hedde <[email protected]>
Add an optional bus interface clock to sysbus devices.
This clock can be added by the subclasses if required using the sysbus_init_bus_interface_clock function given the target name of the clock.
The default behavior of the clock is to enable or disable the mmios in function of the clock status (mmios are enabled iff the clock is running and the reset not asserted).
This behavior may be changed by overriding the clock callback using sysbus_get_bus_interface_clock and clock_set_callback functions.
--- include/hw/sysbus.h | 22 ++++++++++++++++++++++ hw/core/sysbus.c | 25 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+)
include/hw/sysbus.h +22 -0
@@ -73,6 +73,7 @@ struct SysBusDevice { } mmio[QDEV_MAX_MMIO ];int num_pio;uint32_t pio[QDEV_MAX_PIO ]; +ClockIn *bus_itf_clk; };typedef void FindSysbusDeviceFunc (SysBusDevice *sbdev,void *opaque);
@@ -135,4 +136,25 @@ static inline DeviceState *sysbus_try_create_simple(const char *name, return sysbus_try_create_varargs(name, addr, irq, NULL); } +/** +* sysbus_init_bus_interface_clock: +* @dev: the sysbus device +* @name: the name of the clock +* +* Add the bus interface clock to the device. Mmios will be enabled/disabled +* according to the clock status. Must not be called more than once on the same +* device. +* +* Note: if this clock remains unconnected, the sysbus device will work as if +* the clock was absent (no side-effect). +*/ +void sysbus_init_bus_interface_clock (SysBusDevice *dev,const char *name); + +/** +* sysbus_init_get_interface_clock: +* @dev: the sysbus device +* @retuns: the clock previously added by sysbus_init_bus_interface_clock. +*/ +ClockIn *sysbus_get_bus_interface_clock (SysBusDevice *dev); +#endif /* HW_SYSBUS_H */
hw/core/sysbus.c +25 -0
@@ -324,6 +324,31 @@ MemoryRegion *sysbus_address_space(SysBusDevice *dev)return get_system_memory (); } +static void sysbus_device_clock_callback (void *opaque,ClockState *clk) +{ +SysBusDevice *dev = opaque; +bool enable =clock_state_is_domain_running (clk); +int i; + +/* set/clear mmio visible flag on clock change */ +for (i =0 ; i < dev->num_mmio && i <QDEV_MAX_MMIO ; i++) { +MemoryRegion *mr =sysbus_mmio_get_region (dev, i); +memory_region_set_enabled (mr, enable); + } +} + +void sysbus_init_bus_interface_clock (SysBusDevice *dev,const char *name) +{ +assert (dev->bus_itf_clk ==NULL ); + dev->bus_itf_clk =qdev_init_clock_in (DEVICE (dev), name, + sysbus_device_clock_callback, dev); +} + +ClockIn *sysbus_get_bus_interface_clock (SysBusDevice *dev) +{ +return dev->bus_itf_clk; +} +static void sysbus_device_class_init (ObjectClass *klass,void *data) {DeviceClass *k =DEVICE_CLASS (klass);
Signature · 1 line
2.18.0
PATCH v4 7/10 hw/misc/zynq_slcr: use standard register definition
In reply to [email protected]From: Damien Hedde <[email protected]>
Replace the zynq_slcr registers enum and macros using the hw/registerfields.h macros.
--- hw/misc/zynq_slcr.c | 468 ++++++++++++++++++++++---------------------- 1 file changed, 234 insertions(+), 234 deletions(-)
hw/misc/zynq_slcr.c +234 -234
@@ -20,6 +20,7 @@#include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/log.h" +#include "hw/registerfields.h" #ifndef ZYNQ_SLCR_ERR_DEBUG #define ZYNQ_SLCR_ERR_DEBUG 0
@@ -35,138 +36,135 @@#define XILINX_LOCK_KEY 0x767b#define XILINX_UNLOCK_KEY 0xdf0d -#define R_PSS_RST_CTRL_SOFT_RST 0x1 +REG32(SCL, 0x000) +REG32(LOCK, 0x004) +REG32(UNLOCK, 0x008) +REG32(LOCKSTA, 0x00c) -enum { -SCL =0x000 /4 , -LOCK , -UNLOCK , -LOCKSTA , +REG32(ARM_PLL_CTRL, 0x100) +REG32(DDR_PLL_CTRL, 0x104) +REG32(IO_PLL_CTRL, 0x108) +REG32(PLL_STATUS, 0x10c) +REG32(ARM_PLL_CFG, 0x110) +REG32(DDR_PLL_CFG, 0x114) +REG32(IO_PLL_CFG, 0x118) -ARM_PLL_CTRL =0x100 /4 , -DDR_PLL_CTRL , -IO_PLL_CTRL , -PLL_STATUS , -ARM_PLL_CFG , -DDR_PLL_CFG , -IO_PLL_CFG , - -ARM_CLK_CTRL =0x120 /4 , -DDR_CLK_CTRL , -DCI_CLK_CTRL , -APER_CLK_CTRL , -USB0_CLK_CTRL , -USB1_CLK_CTRL , -GEM0_RCLK_CTRL , -GEM1_RCLK_CTRL , -GEM0_CLK_CTRL , -GEM1_CLK_CTRL , -SMC_CLK_CTRL , -LQSPI_CLK_CTRL , -SDIO_CLK_CTRL , -UART_CLK_CTRL , -SPI_CLK_CTRL , -CAN_CLK_CTRL , -CAN_MIOCLK_CTRL , -DBG_CLK_CTRL , -PCAP_CLK_CTRL , -TOPSW_CLK_CTRL , +REG32(ARM_CLK_CTRL, 0x120) +REG32(DDR_CLK_CTRL, 0x124) +REG32(DCI_CLK_CTRL, 0x128) +REG32(APER_CLK_CTRL, 0x12c) +REG32(USB0_CLK_CTRL, 0x130) +REG32(USB1_CLK_CTRL, 0x134) +REG32(GEM0_RCLK_CTRL, 0x138) +REG32(GEM1_RCLK_CTRL, 0x13c) +REG32(GEM0_CLK_CTRL, 0x140) +REG32(GEM1_CLK_CTRL, 0x144) +REG32(SMC_CLK_CTRL, 0x148) +REG32(LQSPI_CLK_CTRL, 0x14c) +REG32(SDIO_CLK_CTRL, 0x150) +REG32(UART_CLK_CTRL, 0x154) +REG32(SPI_CLK_CTRL, 0x158) +REG32(CAN_CLK_CTRL, 0x15c) +REG32(CAN_MIOCLK_CTRL, 0x160) +REG32(DBG_CLK_CTRL, 0x164) +REG32(PCAP_CLK_CTRL, 0x168) +REG32(TOPSW_CLK_CTRL, 0x16c)#define FPGA_CTRL_REGS (n, start) \ - FPGA ## n ## _CLK_CTRL = (start) / 4, \ - FPGA ## n ## _THR_CTRL, \ - FPGA ## n ## _THR_CNT, \ - FPGA ## n ## _THR_STA, - FPGA_CTRL_REGS(0, 0x170) - FPGA_CTRL_REGS(1, 0x180) - FPGA_CTRL_REGS(2, 0x190) - FPGA_CTRL_REGS(3, 0x1a0) - -BANDGAP_TRIP =0x1b8 /4 , -PLL_PREDIVISOR =0x1c0 /4 , -CLK_621_TRUE , - -PSS_RST_CTRL =0x200 /4 , -DDR_RST_CTRL , -TOPSW_RESET_CTRL , -DMAC_RST_CTRL , -USB_RST_CTRL , -GEM_RST_CTRL , -SDIO_RST_CTRL , -SPI_RST_CTRL , -CAN_RST_CTRL , -I2C_RST_CTRL , -UART_RST_CTRL , -GPIO_RST_CTRL , -LQSPI_RST_CTRL , -SMC_RST_CTRL , -OCM_RST_CTRL , -FPGA_RST_CTRL =0x240 /4 , -A9_CPU_RST_CTRL , - -RS_AWDT_CTRL =0x24c /4 , -RST_REASON , - -REBOOT_STATUS =0x258 /4 , -BOOT_MODE , - -APU_CTRL =0x300 /4 , -WDT_CLK_SEL , - -TZ_DMA_NS =0x440 /4 , -TZ_DMA_IRQ_NS , -TZ_DMA_PERIPH_NS , - -PSS_IDCODE =0x530 /4 , - -DDR_URGENT =0x600 /4 , -DDR_CAL_START =0x60c /4 , -DDR_REF_START =0x614 /4 , -DDR_CMD_STA , -DDR_URGENT_SEL , -DDR_DFI_STATUS , - -MIO =0x700 /4 , + REG32(FPGA ## n ## _CLK_CTRL, (start)) \ + REG32(FPGA ## n ## _THR_CTRL, (start) + 0x4)\ + REG32(FPGA ## n ## _THR_CNT, (start) + 0x8)\ + REG32(FPGA ## n ## _THR_STA, (start) + 0xc) +FPGA_CTRL_REGS(0, 0x170) +FPGA_CTRL_REGS(1, 0x180) +FPGA_CTRL_REGS(2, 0x190) +FPGA_CTRL_REGS(3, 0x1a0) + +REG32(BANDGAP_TRIP, 0x1b8) +REG32(PLL_PREDIVISOR, 0x1c0) +REG32(CLK_621_TRUE, 0x1c4) + +REG32(PSS_RST_CTRL, 0x200) + FIELD(PSS_RST_CTRL, SOFT_RST, 0, 1) +REG32(DDR_RST_CTRL, 0x204) +REG32(TOPSW_RESET_CTRL, 0x208) +REG32(DMAC_RST_CTRL, 0x20c) +REG32(USB_RST_CTRL, 0x210) +REG32(GEM_RST_CTRL, 0x214) +REG32(SDIO_RST_CTRL, 0x218) +REG32(SPI_RST_CTRL, 0x21c) +REG32(CAN_RST_CTRL, 0x220) +REG32(I2C_RST_CTRL, 0x224) +REG32(UART_RST_CTRL, 0x228) +REG32(GPIO_RST_CTRL, 0x22c) +REG32(LQSPI_RST_CTRL, 0x230) +REG32(SMC_RST_CTRL, 0x234) +REG32(OCM_RST_CTRL, 0x238) +REG32(FPGA_RST_CTRL, 0x240) +REG32(A9_CPU_RST_CTRL, 0x244) + +REG32(RS_AWDT_CTRL, 0x24c) +REG32(RST_REASON, 0x250) + +REG32(REBOOT_STATUS, 0x258) +REG32(BOOT_MODE, 0x25c) + +REG32(APU_CTRL, 0x300) +REG32(WDT_CLK_SEL, 0x304) + +REG32(TZ_DMA_NS, 0x440) +REG32(TZ_DMA_IRQ_NS, 0x444) +REG32(TZ_DMA_PERIPH_NS, 0x448) + +REG32(PSS_IDCODE, 0x530) + +REG32(DDR_URGENT, 0x600) +REG32(DDR_CAL_START, 0x60c) +REG32(DDR_REF_START, 0x614) +REG32(DDR_CMD_STA, 0x618) +REG32(DDR_URGENT_SEL, 0x61c) +REG32(DDR_DFI_STATUS, 0x620) + +REG32(MIO, 0x700)#define MIO_LENGTH 54 -MIO_LOOPBACK =0x804 /4 , -MIO_MST_TRI0 , -MIO_MST_TRI1 , +REG32(MIO_LOOPBACK, 0x804) +REG32(MIO_MST_TRI0, 0x808) +REG32(MIO_MST_TRI1, 0x80c) -SD0_WP_CD_SEL =0x830 /4 , -SD1_WP_CD_SEL , +REG32(SD0_WP_CD_SEL, 0x830) +REG32(SD1_WP_CD_SEL, 0x834) -LVL_SHFTR_EN =0x900 /4 , -OCM_CFG =0x910 /4 , +REG32(LVL_SHFTR_EN, 0x900) +REG32(OCM_CFG, 0x910) -CPU_RAM =0xa00 /4 , +REG32(CPU_RAM, 0xa00) -IOU =0xa30 /4 , +REG32(IOU, 0xa30) -DMAC_RAM =0xa50 /4 , +REG32(DMAC_RAM, 0xa50) -AFI0 =0xa60 /4 , -AFI1 =AFI0 +3 , -AFI2 =AFI1 +3 , -AFI3 =AFI2 +3 , +REG32(AFI0, 0xa60) +REG32(AFI1, 0xa6c) +REG32(AFI2, 0xa78) +REG32(AFI3, 0xa84)#define AFI_LENGTH 3 -OCM =0xa90 /4 , +REG32(OCM, 0xa90) -DEVCI_RAM =0xaa0 /4 , +REG32(DEVCI_RAM, 0xaa0) -CSG_RAM =0xab0 /4 , +REG32(CSG_RAM, 0xab0) -GPIOB_CTRL =0xb00 /4 , -GPIOB_CFG_CMOS18 , -GPIOB_CFG_CMOS25 , -GPIOB_CFG_CMOS33 , -GPIOB_CFG_HSTL =0xb14 /4 , -GPIOB_DRVR_BIAS_CTRL , +REG32(GPIOB_CTRL, 0xb00) +REG32(GPIOB_CFG_CMOS18, 0xb04) +REG32(GPIOB_CFG_CMOS25, 0xb08) +REG32(GPIOB_CFG_CMOS33, 0xb0c) +REG32(GPIOB_CFG_HSTL, 0xb14) +REG32(GPIOB_DRVR_BIAS_CTRL, 0xb18) -DDRIOB =0xb40 /4 , +REG32(DDRIOB, 0xb40)#define DDRIOB_LENGTH 14 -};#define ZYNQ_SLCR_MMIO_SIZE 0x1000#define ZYNQ_SLCR_NUM_REGS (ZYNQ_SLCR_MMIO_SIZE / 4)
@@ -189,150 +187,152 @@ static void zynq_slcr_reset(DeviceState *d)DB_PRINT ("RESET\n" ); - s->regs[LOCKSTA ] =1 ; + s->regs[R_LOCKSTA ] =1 ;/* 0x100 - 0x11C */ - s->regs[ARM_PLL_CTRL ] =0x0001A008 ; - s->regs[DDR_PLL_CTRL ] =0x0001A008 ; - s->regs[IO_PLL_CTRL ] =0x0001A008 ; - s->regs[PLL_STATUS ] =0x0000003F ; - s->regs[ARM_PLL_CFG ] =0x00014000 ; - s->regs[DDR_PLL_CFG ] =0x00014000 ; - s->regs[IO_PLL_CFG ] =0x00014000 ; + s->regs[R_ARM_PLL_CTRL ] =0x0001A008 ; + s->regs[R_DDR_PLL_CTRL ] =0x0001A008 ; + s->regs[R_IO_PLL_CTRL ] =0x0001A008 ; + s->regs[R_PLL_STATUS ] =0x0000003F ; + s->regs[R_ARM_PLL_CFG ] =0x00014000 ; + s->regs[R_DDR_PLL_CFG ] =0x00014000 ; + s->regs[R_IO_PLL_CFG ] =0x00014000 ;/* 0x120 - 0x16C */ - s->regs[ARM_CLK_CTRL ] =0x1F000400 ; - s->regs[DDR_CLK_CTRL ] =0x18400003 ; - s->regs[DCI_CLK_CTRL ] =0x01E03201 ; - s->regs[APER_CLK_CTRL ] =0x01FFCCCD ; - s->regs[USB0_CLK_CTRL ] = s->regs[USB1_CLK_CTRL ] =0x00101941 ; - s->regs[GEM0_RCLK_CTRL ] = s->regs[GEM1_RCLK_CTRL ] =0x00000001 ; - s->regs[GEM0_CLK_CTRL ] = s->regs[GEM1_CLK_CTRL ] =0x00003C01 ; - s->regs[SMC_CLK_CTRL ] =0x00003C01 ; - s->regs[LQSPI_CLK_CTRL ] =0x00002821 ; - s->regs[SDIO_CLK_CTRL ] =0x00001E03 ; - s->regs[UART_CLK_CTRL ] =0x00003F03 ; - s->regs[SPI_CLK_CTRL ] =0x00003F03 ; - s->regs[CAN_CLK_CTRL ] =0x00501903 ; - s->regs[DBG_CLK_CTRL ] =0x00000F03 ; - s->regs[PCAP_CLK_CTRL ] =0x00000F01 ; + s->regs[R_ARM_CLK_CTRL ] =0x1F000400 ; + s->regs[R_DDR_CLK_CTRL ] =0x18400003 ; + s->regs[R_DCI_CLK_CTRL ] =0x01E03201 ; + s->regs[R_APER_CLK_CTRL ] =0x01FFCCCD ; + s->regs[R_USB0_CLK_CTRL ] = s->regs[R_USB1_CLK_CTRL ] =0x00101941 ; + s->regs[R_GEM0_RCLK_CTRL ] = s->regs[R_GEM1_RCLK_CTRL ] =0x00000001 ; + s->regs[R_GEM0_CLK_CTRL ] = s->regs[R_GEM1_CLK_CTRL ] =0x00003C01 ; + s->regs[R_SMC_CLK_CTRL ] =0x00003C01 ; + s->regs[R_LQSPI_CLK_CTRL ] =0x00002821 ; + s->regs[R_SDIO_CLK_CTRL ] =0x00001E03 ; + s->regs[R_UART_CLK_CTRL ] =0x00003F03 ; + s->regs[R_SPI_CLK_CTRL ] =0x00003F03 ; + s->regs[R_CAN_CLK_CTRL ] =0x00501903 ; + s->regs[R_DBG_CLK_CTRL ] =0x00000F03 ; + s->regs[R_PCAP_CLK_CTRL ] =0x00000F01 ;/* 0x170 - 0x1AC */ - s->regs[FPGA0_CLK_CTRL ] = s->regs[FPGA1_CLK_CTRL ] = s->regs[FPGA2_CLK_CTRL ] - = s->regs[FPGA3_CLK_CTRL ] =0x00101800 ; - s->regs[FPGA0_THR_STA ] = s->regs[FPGA1_THR_STA ] = s->regs[FPGA2_THR_STA ] - = s->regs[FPGA3_THR_STA ] =0x00010000 ; + s->regs[R_FPGA0_CLK_CTRL ] = s->regs[R_FPGA1_CLK_CTRL ] + = s->regs[R_FPGA2_CLK_CTRL ] + = s->regs[R_FPGA3_CLK_CTRL ] =0x00101800 ; + s->regs[R_FPGA0_THR_STA ] = s->regs[R_FPGA1_THR_STA ] + = s->regs[R_FPGA2_THR_STA ] + = s->regs[R_FPGA3_THR_STA ] =0x00010000 ;/* 0x1B0 - 0x1D8 */ - s->regs[BANDGAP_TRIP ] =0x0000001F ; - s->regs[PLL_PREDIVISOR ] =0x00000001 ; - s->regs[CLK_621_TRUE ] =0x00000001 ; + s->regs[R_BANDGAP_TRIP ] =0x0000001F ; + s->regs[R_PLL_PREDIVISOR ] =0x00000001 ; + s->regs[R_CLK_621_TRUE ] =0x00000001 ;/* 0x200 - 0x25C */ - s->regs[FPGA_RST_CTRL ] =0x01F33F0F ; - s->regs[RST_REASON ] =0x00000040 ; + s->regs[R_FPGA_RST_CTRL ] =0x01F33F0F ; + s->regs[R_RST_REASON ] =0x00000040 ; - s->regs[BOOT_MODE ] =0x00000001 ; + s->regs[R_BOOT_MODE ] =0x00000001 ;/* 0x700 - 0x7D4 */ for (i =0 ; i <54 ; i++) { - s->regs[MIO + i] =0x00001601 ; + s->regs[R_MIO + i] =0x00001601 ; }for (i =2 ; i <=8 ; i++) { - s->regs[MIO + i] =0x00000601 ; + s->regs[R_MIO + i] =0x00000601 ; } - s->regs[MIO_MST_TRI0 ] = s->regs[MIO_MST_TRI1 ] =0xFFFFFFFF ; + s->regs[R_MIO_MST_TRI0 ] = s->regs[R_MIO_MST_TRI1 ] =0xFFFFFFFF ; - s->regs[CPU_RAM +0 ] = s->regs[CPU_RAM +1 ] = s->regs[CPU_RAM +3 ] - = s->regs[CPU_RAM +4 ] = s->regs[CPU_RAM +7 ] - =0x00010101 ; - s->regs[CPU_RAM +2 ] = s->regs[CPU_RAM +5 ] =0x01010101 ; - s->regs[CPU_RAM +6 ] =0x00000001 ; + s->regs[R_CPU_RAM +0 ] = s->regs[R_CPU_RAM +1 ] = s->regs[R_CPU_RAM +3 ] + = s->regs[R_CPU_RAM +4 ] = s->regs[R_CPU_RAM +7 ] + =0x00010101 ; + s->regs[R_CPU_RAM +2 ] = s->regs[R_CPU_RAM +5 ] =0x01010101 ; + s->regs[R_CPU_RAM +6 ] =0x00000001 ; - s->regs[IOU +0 ] = s->regs[IOU +1 ] = s->regs[IOU +2 ] = s->regs[IOU +3 ] - =0x09090909 ; - s->regs[IOU +4 ] = s->regs[IOU +5 ] =0x00090909 ; - s->regs[IOU +6 ] =0x00000909 ; + s->regs[R_IOU +0 ] = s->regs[R_IOU +1 ] = s->regs[R_IOU +2 ] + = s->regs[R_IOU +3 ] =0x09090909 ; + s->regs[R_IOU +4 ] = s->regs[R_IOU +5 ] =0x00090909 ; + s->regs[R_IOU +6 ] =0x00000909 ; - s->regs[DMAC_RAM ] =0x00000009 ; + s->regs[R_DMAC_RAM ] =0x00000009 ; - s->regs[AFI0 +0 ] = s->regs[AFI0 +1 ] =0x09090909 ; - s->regs[AFI1 +0 ] = s->regs[AFI1 +1 ] =0x09090909 ; - s->regs[AFI2 +0 ] = s->regs[AFI2 +1 ] =0x09090909 ; - s->regs[AFI3 +0 ] = s->regs[AFI3 +1 ] =0x09090909 ; - s->regs[AFI0 +2 ] = s->regs[AFI1 +2 ] = s->regs[AFI2 +2 ] - = s->regs[AFI3 +2 ] =0x00000909 ; + s->regs[R_AFI0 +0 ] = s->regs[R_AFI0 +1 ] =0x09090909 ; + s->regs[R_AFI1 +0 ] = s->regs[R_AFI1 +1 ] =0x09090909 ; + s->regs[R_AFI2 +0 ] = s->regs[R_AFI2 +1 ] =0x09090909 ; + s->regs[R_AFI3 +0 ] = s->regs[R_AFI3 +1 ] =0x09090909 ; + s->regs[R_AFI0 +2 ] = s->regs[R_AFI1 +2 ] = s->regs[R_AFI2 +2 ] + = s->regs[R_AFI3 +2 ] =0x00000909 ; - s->regs[OCM +0 ] =0x01010101 ; - s->regs[OCM +1 ] = s->regs[OCM +2 ] =0x09090909 ; + s->regs[R_OCM +0 ] =0x01010101 ; + s->regs[R_OCM +1 ] = s->regs[R_OCM +2 ] =0x09090909 ; - s->regs[DEVCI_RAM ] =0x00000909 ; - s->regs[CSG_RAM ] =0x00000001 ; + s->regs[R_DEVCI_RAM ] =0x00000909 ; + s->regs[R_CSG_RAM ] =0x00000001 ; - s->regs[DDRIOB +0 ] = s->regs[DDRIOB +1 ] = s->regs[DDRIOB +2 ] - = s->regs[DDRIOB +3 ] =0x00000e00 ; - s->regs[DDRIOB +4 ] = s->regs[DDRIOB +5 ] = s->regs[DDRIOB +6 ] - =0x00000e00 ; - s->regs[DDRIOB +12 ] =0x00000021 ; + s->regs[R_DDRIOB +0 ] = s->regs[R_DDRIOB +1 ] = s->regs[R_DDRIOB +2 ] + = s->regs[R_DDRIOB +3 ] =0x00000e00 ; + s->regs[R_DDRIOB +4 ] = s->regs[R_DDRIOB +5 ] = s->regs[R_DDRIOB +6 ] + =0x00000e00 ; + s->regs[R_DDRIOB +12 ] =0x00000021 ; }static bool zynq_slcr_check_offset (hwaddr offset,bool rnw) {switch (offset) { -case LOCK : -case UNLOCK : -case DDR_CAL_START : -case DDR_REF_START : +case R_LOCK : +case R_UNLOCK : +case R_DDR_CAL_START : +case R_DDR_REF_START :return !rnw;/* Write only */ -case LOCKSTA : -case FPGA0_THR_STA : -case FPGA1_THR_STA : -case FPGA2_THR_STA : -case FPGA3_THR_STA : -case BOOT_MODE : -case PSS_IDCODE : -case DDR_CMD_STA : -case DDR_DFI_STATUS : -case PLL_STATUS : +case R_LOCKSTA : +case R_FPGA0_THR_STA : +case R_FPGA1_THR_STA : +case R_FPGA2_THR_STA : +case R_FPGA3_THR_STA : +case R_BOOT_MODE : +case R_PSS_IDCODE : +case R_DDR_CMD_STA : +case R_DDR_DFI_STATUS : +case R_PLL_STATUS :return rnw;/* read only */ -case SCL : - case ARM_PLL_CTRL ... IO_PLL_CTRL: - case ARM_PLL_CFG ... IO_PLL_CFG: - case ARM_CLK_CTRL ... TOPSW_CLK_CTRL: - case FPGA0_CLK_CTRL ... FPGA0_THR_CNT: - case FPGA1_CLK_CTRL ... FPGA1_THR_CNT: - case FPGA2_CLK_CTRL ... FPGA2_THR_CNT: - case FPGA3_CLK_CTRL ... FPGA3_THR_CNT: -case BANDGAP_TRIP : -case PLL_PREDIVISOR : -case CLK_621_TRUE : - case PSS_RST_CTRL ... A9_CPU_RST_CTRL: -case RS_AWDT_CTRL : -case RST_REASON : -case REBOOT_STATUS : -case APU_CTRL : -case WDT_CLK_SEL : - case TZ_DMA_NS ... TZ_DMA_PERIPH_NS: -case DDR_URGENT : -case DDR_URGENT_SEL : - case MIO ... MIO + MIO_LENGTH - 1: - case MIO_LOOPBACK ... MIO_MST_TRI1: -case SD0_WP_CD_SEL : -case SD1_WP_CD_SEL : -case LVL_SHFTR_EN : -case OCM_CFG : -case CPU_RAM : -case IOU : -case DMAC_RAM : - case AFI0 ... AFI3 + AFI_LENGTH - 1: -case OCM : -case DEVCI_RAM : -case CSG_RAM : - case GPIOB_CTRL ... GPIOB_CFG_CMOS33: -case GPIOB_CFG_HSTL : -case GPIOB_DRVR_BIAS_CTRL : - case DDRIOB ... DDRIOB + DDRIOB_LENGTH - 1: +case R_SCL : + case R_ARM_PLL_CTRL ... R_IO_PLL_CTRL: + case R_ARM_PLL_CFG ... R_IO_PLL_CFG: + case R_ARM_CLK_CTRL ... R_TOPSW_CLK_CTRL: + case R_FPGA0_CLK_CTRL ... R_FPGA0_THR_CNT: + case R_FPGA1_CLK_CTRL ... R_FPGA1_THR_CNT: + case R_FPGA2_CLK_CTRL ... R_FPGA2_THR_CNT: + case R_FPGA3_CLK_CTRL ... R_FPGA3_THR_CNT: +case R_BANDGAP_TRIP : +case R_PLL_PREDIVISOR : +case R_CLK_621_TRUE : + case R_PSS_RST_CTRL ... R_A9_CPU_RST_CTRL: +case R_RS_AWDT_CTRL : +case R_RST_REASON : +case R_REBOOT_STATUS : +case R_APU_CTRL : +case R_WDT_CLK_SEL : + case R_TZ_DMA_NS ... R_TZ_DMA_PERIPH_NS: +case R_DDR_URGENT : +case R_DDR_URGENT_SEL : + case R_MIO ... R_MIO + MIO_LENGTH - 1: + case R_MIO_LOOPBACK ... R_MIO_MST_TRI1: +case R_SD0_WP_CD_SEL : +case R_SD1_WP_CD_SEL : +case R_LVL_SHFTR_EN : +case R_OCM_CFG : +case R_CPU_RAM : +case R_IOU : +case R_DMAC_RAM : + case R_AFI0 ... R_AFI3 + AFI_LENGTH - 1: +case R_OCM : +case R_DEVCI_RAM : +case R_CSG_RAM : + case R_GPIOB_CTRL ... R_GPIOB_CFG_CMOS33: +case R_GPIOB_CFG_HSTL : +case R_GPIOB_DRVR_BIAS_CTRL : + case R_DDRIOB ... R_DDRIOB + DDRIOB_LENGTH - 1:return true;default :return false;
@@ -370,24 +370,24 @@ static void zynq_slcr_write(void *opaque, hwaddr offset, }switch (offset) { -case SCL : - s->regs[SCL ] = val &0x1 ; +case R_SCL : + s->regs[R_SCL ] = val &0x1 ;return ; -case LOCK : +case R_LOCK :if ((val &0xFFFF ) ==XILINX_LOCK_KEY ) {DB_PRINT ("XILINX LOCK 0xF8000000 + 0x%x <= 0x%x\n" , (int )offset, (unsigned )val &0xFFFF ); - s->regs[LOCKSTA ] =1 ; + s->regs[R_LOCKSTA ] =1 ; }else {DB_PRINT ("WRONG XILINX LOCK KEY 0xF8000000 + 0x%x <= 0x%x\n" , (int )offset, (unsigned )val &0xFFFF ); }return ; -case UNLOCK : +case R_UNLOCK :if ((val &0xFFFF ) ==XILINX_UNLOCK_KEY ) {DB_PRINT ("XILINX UNLOCK 0xF8000000 + 0x%x <= 0x%x\n" , (int )offset, (unsigned )val &0xFFFF ); - s->regs[LOCKSTA ] =0 ; + s->regs[R_LOCKSTA ] =0 ; }else {DB_PRINT ("WRONG XILINX UNLOCK KEY 0xF8000000 + 0x%x <= 0x%x\n" , (int )offset, (unsigned )val &0xFFFF );
@@ -395,7 +395,7 @@ static void zynq_slcr_write(void *opaque, hwaddr offset,return ; } -if (s->regs[LOCKSTA ]) { +if (s->regs[R_LOCKSTA ]) {qemu_log_mask (LOG_GUEST_ERROR ,"SCLR registers are locked. Unlock them first\n" );return ;
@@ -403,8 +403,8 @@ static void zynq_slcr_write(void *opaque, hwaddr offset, s->regs[offset] = val;switch (offset) { -case PSS_RST_CTRL : -if (val &R_PSS_RST_CTRL_SOFT_RST ) { +case R_PSS_RST_CTRL : +if (FIELD_EX32 (val,PSS_RST_CTRL ,SOFT_RST )) {qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET ); }break ;
Signature · 1 line
2.18.0
Re: [Qemu-arm] [PATCH v4 07/10] hw/misc/zynq_slcr: use standard register definition
Quoted 4 lines · On 9/17/18 10:40 AM, [email protected] wrote:
From: Damien Hedde <[email protected]>
Replace the
zynq_slcrregisters enum and macros using thehw/registerfields.hmacros.
This looks cleaner, indeed.
Quoted 2 lines
Signed-off-by Damien Hedde <[email protected]>
Quoted 582 lines
--- hw/misc/zynq_slcr.c | 468 ++++++++++++++++++++++---------------------- 1 file changed, 234 insertions(+), 234 deletions(-)hw/misc/zynq_slcr.c +234
-234@@ -20,6 +20,7 @@#include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/log.h" +#include "hw/registerfields.h" #ifndef ZYNQ_SLCR_ERR_DEBUG #define ZYNQ_SLCR_ERR_DEBUG 0@@ -35,138 +36,135 @@#define XILINX_LOCK_KEY 0x767b#define XILINX_UNLOCK_KEY 0xdf0d -#define R_PSS_RST_CTRL_SOFT_RST 0x1 +REG32(SCL, 0x000) +REG32(LOCK, 0x004) +REG32(UNLOCK, 0x008) +REG32(LOCKSTA, 0x00c) -enum { -SCL =0x000 /4 , -LOCK , -UNLOCK , -LOCKSTA , +REG32(ARM_PLL_CTRL, 0x100) +REG32(DDR_PLL_CTRL, 0x104) +REG32(IO_PLL_CTRL, 0x108) +REG32(PLL_STATUS, 0x10c) +REG32(ARM_PLL_CFG, 0x110) +REG32(DDR_PLL_CFG, 0x114) +REG32(IO_PLL_CFG, 0x118) -ARM_PLL_CTRL =0x100 /4 , -DDR_PLL_CTRL , -IO_PLL_CTRL , -PLL_STATUS , -ARM_PLL_CFG , -DDR_PLL_CFG , -IO_PLL_CFG , - -ARM_CLK_CTRL =0x120 /4 , -DDR_CLK_CTRL , -DCI_CLK_CTRL , -APER_CLK_CTRL , -USB0_CLK_CTRL , -USB1_CLK_CTRL , -GEM0_RCLK_CTRL , -GEM1_RCLK_CTRL , -GEM0_CLK_CTRL , -GEM1_CLK_CTRL , -SMC_CLK_CTRL , -LQSPI_CLK_CTRL , -SDIO_CLK_CTRL , -UART_CLK_CTRL , -SPI_CLK_CTRL , -CAN_CLK_CTRL , -CAN_MIOCLK_CTRL , -DBG_CLK_CTRL , -PCAP_CLK_CTRL , -TOPSW_CLK_CTRL , +REG32(ARM_CLK_CTRL, 0x120) +REG32(DDR_CLK_CTRL, 0x124) +REG32(DCI_CLK_CTRL, 0x128) +REG32(APER_CLK_CTRL, 0x12c) +REG32(USB0_CLK_CTRL, 0x130) +REG32(USB1_CLK_CTRL, 0x134) +REG32(GEM0_RCLK_CTRL, 0x138) +REG32(GEM1_RCLK_CTRL, 0x13c) +REG32(GEM0_CLK_CTRL, 0x140) +REG32(GEM1_CLK_CTRL, 0x144) +REG32(SMC_CLK_CTRL, 0x148) +REG32(LQSPI_CLK_CTRL, 0x14c) +REG32(SDIO_CLK_CTRL, 0x150) +REG32(UART_CLK_CTRL, 0x154) +REG32(SPI_CLK_CTRL, 0x158) +REG32(CAN_CLK_CTRL, 0x15c) +REG32(CAN_MIOCLK_CTRL, 0x160) +REG32(DBG_CLK_CTRL, 0x164) +REG32(PCAP_CLK_CTRL, 0x168) +REG32(TOPSW_CLK_CTRL, 0x16c)#define FPGA_CTRL_REGS (n, start) \ - FPGA ## n ## _CLK_CTRL = (start) / 4, \ - FPGA ## n ## _THR_CTRL, \ - FPGA ## n ## _THR_CNT, \ - FPGA ## n ## _THR_STA, - FPGA_CTRL_REGS(0, 0x170) - FPGA_CTRL_REGS(1, 0x180) - FPGA_CTRL_REGS(2, 0x190) - FPGA_CTRL_REGS(3, 0x1a0) - -BANDGAP_TRIP =0x1b8 /4 , -PLL_PREDIVISOR =0x1c0 /4 , -CLK_621_TRUE , - -PSS_RST_CTRL =0x200 /4 , -DDR_RST_CTRL , -TOPSW_RESET_CTRL , -DMAC_RST_CTRL , -USB_RST_CTRL , -GEM_RST_CTRL , -SDIO_RST_CTRL , -SPI_RST_CTRL , -CAN_RST_CTRL , -I2C_RST_CTRL , -UART_RST_CTRL , -GPIO_RST_CTRL , -LQSPI_RST_CTRL , -SMC_RST_CTRL , -OCM_RST_CTRL , -FPGA_RST_CTRL =0x240 /4 , -A9_CPU_RST_CTRL , - -RS_AWDT_CTRL =0x24c /4 , -RST_REASON , - -REBOOT_STATUS =0x258 /4 , -BOOT_MODE , - -APU_CTRL =0x300 /4 , -WDT_CLK_SEL , - -TZ_DMA_NS =0x440 /4 , -TZ_DMA_IRQ_NS , -TZ_DMA_PERIPH_NS , - -PSS_IDCODE =0x530 /4 , - -DDR_URGENT =0x600 /4 , -DDR_CAL_START =0x60c /4 , -DDR_REF_START =0x614 /4 , -DDR_CMD_STA , -DDR_URGENT_SEL , -DDR_DFI_STATUS , - -MIO =0x700 /4 , + REG32(FPGA ## n ## _CLK_CTRL, (start)) \ + REG32(FPGA ## n ## _THR_CTRL, (start) + 0x4)\ + REG32(FPGA ## n ## _THR_CNT, (start) + 0x8)\ + REG32(FPGA ## n ## _THR_STA, (start) + 0xc) +FPGA_CTRL_REGS(0, 0x170) +FPGA_CTRL_REGS(1, 0x180) +FPGA_CTRL_REGS(2, 0x190) +FPGA_CTRL_REGS(3, 0x1a0) + +REG32(BANDGAP_TRIP, 0x1b8) +REG32(PLL_PREDIVISOR, 0x1c0) +REG32(CLK_621_TRUE, 0x1c4) + +REG32(PSS_RST_CTRL, 0x200) + FIELD(PSS_RST_CTRL, SOFT_RST, 0, 1) +REG32(DDR_RST_CTRL, 0x204) +REG32(TOPSW_RESET_CTRL, 0x208) +REG32(DMAC_RST_CTRL, 0x20c) +REG32(USB_RST_CTRL, 0x210) +REG32(GEM_RST_CTRL, 0x214) +REG32(SDIO_RST_CTRL, 0x218) +REG32(SPI_RST_CTRL, 0x21c) +REG32(CAN_RST_CTRL, 0x220) +REG32(I2C_RST_CTRL, 0x224) +REG32(UART_RST_CTRL, 0x228) +REG32(GPIO_RST_CTRL, 0x22c) +REG32(LQSPI_RST_CTRL, 0x230) +REG32(SMC_RST_CTRL, 0x234) +REG32(OCM_RST_CTRL, 0x238) +REG32(FPGA_RST_CTRL, 0x240) +REG32(A9_CPU_RST_CTRL, 0x244) + +REG32(RS_AWDT_CTRL, 0x24c) +REG32(RST_REASON, 0x250) + +REG32(REBOOT_STATUS, 0x258) +REG32(BOOT_MODE, 0x25c) + +REG32(APU_CTRL, 0x300) +REG32(WDT_CLK_SEL, 0x304) + +REG32(TZ_DMA_NS, 0x440) +REG32(TZ_DMA_IRQ_NS, 0x444) +REG32(TZ_DMA_PERIPH_NS, 0x448) + +REG32(PSS_IDCODE, 0x530) + +REG32(DDR_URGENT, 0x600) +REG32(DDR_CAL_START, 0x60c) +REG32(DDR_REF_START, 0x614) +REG32(DDR_CMD_STA, 0x618) +REG32(DDR_URGENT_SEL, 0x61c) +REG32(DDR_DFI_STATUS, 0x620) + +REG32(MIO, 0x700)#define MIO_LENGTH 54 -MIO_LOOPBACK =0x804 /4 , -MIO_MST_TRI0 , -MIO_MST_TRI1 , +REG32(MIO_LOOPBACK, 0x804) +REG32(MIO_MST_TRI0, 0x808) +REG32(MIO_MST_TRI1, 0x80c) -SD0_WP_CD_SEL =0x830 /4 , -SD1_WP_CD_SEL , +REG32(SD0_WP_CD_SEL, 0x830) +REG32(SD1_WP_CD_SEL, 0x834) -LVL_SHFTR_EN =0x900 /4 , -OCM_CFG =0x910 /4 , +REG32(LVL_SHFTR_EN, 0x900) +REG32(OCM_CFG, 0x910) -CPU_RAM =0xa00 /4 , +REG32(CPU_RAM, 0xa00) -IOU =0xa30 /4 , +REG32(IOU, 0xa30) -DMAC_RAM =0xa50 /4 , +REG32(DMAC_RAM, 0xa50) -AFI0 =0xa60 /4 , -AFI1 =AFI0 +3 , -AFI2 =AFI1 +3 , -AFI3 =AFI2 +3 , +REG32(AFI0, 0xa60) +REG32(AFI1, 0xa6c) +REG32(AFI2, 0xa78) +REG32(AFI3, 0xa84)#define AFI_LENGTH 3 -OCM =0xa90 /4 , +REG32(OCM, 0xa90) -DEVCI_RAM =0xaa0 /4 , +REG32(DEVCI_RAM, 0xaa0) -CSG_RAM =0xab0 /4 , +REG32(CSG_RAM, 0xab0) -GPIOB_CTRL =0xb00 /4 , -GPIOB_CFG_CMOS18 , -GPIOB_CFG_CMOS25 , -GPIOB_CFG_CMOS33 , -GPIOB_CFG_HSTL =0xb14 /4 , -GPIOB_DRVR_BIAS_CTRL , +REG32(GPIOB_CTRL, 0xb00) +REG32(GPIOB_CFG_CMOS18, 0xb04) +REG32(GPIOB_CFG_CMOS25, 0xb08) +REG32(GPIOB_CFG_CMOS33, 0xb0c) +REG32(GPIOB_CFG_HSTL, 0xb14) +REG32(GPIOB_DRVR_BIAS_CTRL, 0xb18) -DDRIOB =0xb40 /4 , +REG32(DDRIOB, 0xb40)#define DDRIOB_LENGTH 14 -};#define ZYNQ_SLCR_MMIO_SIZE 0x1000#define ZYNQ_SLCR_NUM_REGS (ZYNQ_SLCR_MMIO_SIZE / 4)@@ -189,150 +187,152 @@ static void zynq_slcr_reset(DeviceState *d)DB_PRINT ("RESET\n" ); - s->regs[LOCKSTA ] =1 ; + s->regs[R_LOCKSTA ] =1 ;/* 0x100 - 0x11C */ - s->regs[ARM_PLL_CTRL ] =0x0001A008 ; - s->regs[DDR_PLL_CTRL ] =0x0001A008 ; - s->regs[IO_PLL_CTRL ] =0x0001A008 ; - s->regs[PLL_STATUS ] =0x0000003F ; - s->regs[ARM_PLL_CFG ] =0x00014000 ; - s->regs[DDR_PLL_CFG ] =0x00014000 ; - s->regs[IO_PLL_CFG ] =0x00014000 ; + s->regs[R_ARM_PLL_CTRL ] =0x0001A008 ; + s->regs[R_DDR_PLL_CTRL ] =0x0001A008 ; + s->regs[R_IO_PLL_CTRL ] =0x0001A008 ; + s->regs[R_PLL_STATUS ] =0x0000003F ; + s->regs[R_ARM_PLL_CFG ] =0x00014000 ; + s->regs[R_DDR_PLL_CFG ] =0x00014000 ; + s->regs[R_IO_PLL_CFG ] =0x00014000 ;/* 0x120 - 0x16C */ - s->regs[ARM_CLK_CTRL ] =0x1F000400 ; - s->regs[DDR_CLK_CTRL ] =0x18400003 ; - s->regs[DCI_CLK_CTRL ] =0x01E03201 ; - s->regs[APER_CLK_CTRL ] =0x01FFCCCD ; - s->regs[USB0_CLK_CTRL ] = s->regs[USB1_CLK_CTRL ] =0x00101941 ; - s->regs[GEM0_RCLK_CTRL ] = s->regs[GEM1_RCLK_CTRL ] =0x00000001 ; - s->regs[GEM0_CLK_CTRL ] = s->regs[GEM1_CLK_CTRL ] =0x00003C01 ; - s->regs[SMC_CLK_CTRL ] =0x00003C01 ; - s->regs[LQSPI_CLK_CTRL ] =0x00002821 ; - s->regs[SDIO_CLK_CTRL ] =0x00001E03 ; - s->regs[UART_CLK_CTRL ] =0x00003F03 ; - s->regs[SPI_CLK_CTRL ] =0x00003F03 ; - s->regs[CAN_CLK_CTRL ] =0x00501903 ; - s->regs[DBG_CLK_CTRL ] =0x00000F03 ; - s->regs[PCAP_CLK_CTRL ] =0x00000F01 ; + s->regs[R_ARM_CLK_CTRL ] =0x1F000400 ; + s->regs[R_DDR_CLK_CTRL ] =0x18400003 ; + s->regs[R_DCI_CLK_CTRL ] =0x01E03201 ; + s->regs[R_APER_CLK_CTRL ] =0x01FFCCCD ; + s->regs[R_USB0_CLK_CTRL ] = s->regs[R_USB1_CLK_CTRL ] =0x00101941 ; + s->regs[R_GEM0_RCLK_CTRL ] = s->regs[R_GEM1_RCLK_CTRL ] =0x00000001 ; + s->regs[R_GEM0_CLK_CTRL ] = s->regs[R_GEM1_CLK_CTRL ] =0x00003C01 ; + s->regs[R_SMC_CLK_CTRL ] =0x00003C01 ; + s->regs[R_LQSPI_CLK_CTRL ] =0x00002821 ; + s->regs[R_SDIO_CLK_CTRL ] =0x00001E03 ; + s->regs[R_UART_CLK_CTRL ] =0x00003F03 ; + s->regs[R_SPI_CLK_CTRL ] =0x00003F03 ; + s->regs[R_CAN_CLK_CTRL ] =0x00501903 ; + s->regs[R_DBG_CLK_CTRL ] =0x00000F03 ; + s->regs[R_PCAP_CLK_CTRL ] =0x00000F01 ;/* 0x170 - 0x1AC */ - s->regs[FPGA0_CLK_CTRL ] = s->regs[FPGA1_CLK_CTRL ] = s->regs[FPGA2_CLK_CTRL ] - = s->regs[FPGA3_CLK_CTRL ] =0x00101800 ; - s->regs[FPGA0_THR_STA ] = s->regs[FPGA1_THR_STA ] = s->regs[FPGA2_THR_STA ] - = s->regs[FPGA3_THR_STA ] =0x00010000 ; + s->regs[R_FPGA0_CLK_CTRL ] = s->regs[R_FPGA1_CLK_CTRL ] + = s->regs[R_FPGA2_CLK_CTRL ] + = s->regs[R_FPGA3_CLK_CTRL ] =0x00101800 ; + s->regs[R_FPGA0_THR_STA ] = s->regs[R_FPGA1_THR_STA ] + = s->regs[R_FPGA2_THR_STA ] + = s->regs[R_FPGA3_THR_STA ] =0x00010000 ;/* 0x1B0 - 0x1D8 */ - s->regs[BANDGAP_TRIP ] =0x0000001F ; - s->regs[PLL_PREDIVISOR ] =0x00000001 ; - s->regs[CLK_621_TRUE ] =0x00000001 ; + s->regs[R_BANDGAP_TRIP ] =0x0000001F ; + s->regs[R_PLL_PREDIVISOR ] =0x00000001 ; + s->regs[R_CLK_621_TRUE ] =0x00000001 ;/* 0x200 - 0x25C */ - s->regs[FPGA_RST_CTRL ] =0x01F33F0F ; - s->regs[RST_REASON ] =0x00000040 ; + s->regs[R_FPGA_RST_CTRL ] =0x01F33F0F ; + s->regs[R_RST_REASON ] =0x00000040 ; - s->regs[BOOT_MODE ] =0x00000001 ; + s->regs[R_BOOT_MODE ] =0x00000001 ;/* 0x700 - 0x7D4 */ for (i =0 ; i <54 ; i++) { - s->regs[MIO + i] =0x00001601 ; + s->regs[R_MIO + i] =0x00001601 ; }for (i =2 ; i <=8 ; i++) { - s->regs[MIO + i] =0x00000601 ; + s->regs[R_MIO + i] =0x00000601 ; } - s->regs[MIO_MST_TRI0 ] = s->regs[MIO_MST_TRI1 ] =0xFFFFFFFF ; + s->regs[R_MIO_MST_TRI0 ] = s->regs[R_MIO_MST_TRI1 ] =0xFFFFFFFF ; - s->regs[CPU_RAM +0 ] = s->regs[CPU_RAM +1 ] = s->regs[CPU_RAM +3 ] - = s->regs[CPU_RAM +4 ] = s->regs[CPU_RAM +7 ] - =0x00010101 ; - s->regs[CPU_RAM +2 ] = s->regs[CPU_RAM +5 ] =0x01010101 ; - s->regs[CPU_RAM +6 ] =0x00000001 ; + s->regs[R_CPU_RAM +0 ] = s->regs[R_CPU_RAM +1 ] = s->regs[R_CPU_RAM +3 ] + = s->regs[R_CPU_RAM +4 ] = s->regs[R_CPU_RAM +7 ] + =0x00010101 ; + s->regs[R_CPU_RAM +2 ] = s->regs[R_CPU_RAM +5 ] =0x01010101 ; + s->regs[R_CPU_RAM +6 ] =0x00000001 ; - s->regs[IOU +0 ] = s->regs[IOU +1 ] = s->regs[IOU +2 ] = s->regs[IOU +3 ] - =0x09090909 ; - s->regs[IOU +4 ] = s->regs[IOU +5 ] =0x00090909 ; - s->regs[IOU +6 ] =0x00000909 ; + s->regs[R_IOU +0 ] = s->regs[R_IOU +1 ] = s->regs[R_IOU +2 ] + = s->regs[R_IOU +3 ] =0x09090909 ; + s->regs[R_IOU +4 ] = s->regs[R_IOU +5 ] =0x00090909 ; + s->regs[R_IOU +6 ] =0x00000909 ; - s->regs[DMAC_RAM ] =0x00000009 ; + s->regs[R_DMAC_RAM ] =0x00000009 ; - s->regs[AFI0 +0 ] = s->regs[AFI0 +1 ] =0x09090909 ; - s->regs[AFI1 +0 ] = s->regs[AFI1 +1 ] =0x09090909 ; - s->regs[AFI2 +0 ] = s->regs[AFI2 +1 ] =0x09090909 ; - s->regs[AFI3 +0 ] = s->regs[AFI3 +1 ] =0x09090909 ; - s->regs[AFI0 +2 ] = s->regs[AFI1 +2 ] = s->regs[AFI2 +2 ] - = s->regs[AFI3 +2 ] =0x00000909 ; + s->regs[R_AFI0 +0 ] = s->regs[R_AFI0 +1 ] =0x09090909 ; + s->regs[R_AFI1 +0 ] = s->regs[R_AFI1 +1 ] =0x09090909 ; + s->regs[R_AFI2 +0 ] = s->regs[R_AFI2 +1 ] =0x09090909 ; + s->regs[R_AFI3 +0 ] = s->regs[R_AFI3 +1 ] =0x09090909 ; + s->regs[R_AFI0 +2 ] = s->regs[R_AFI1 +2 ] = s->regs[R_AFI2 +2 ] + = s->regs[R_AFI3 +2 ] =0x00000909 ; - s->regs[OCM +0 ] =0x01010101 ; - s->regs[OCM +1 ] = s->regs[OCM +2 ] =0x09090909 ; + s->regs[R_OCM +0 ] =0x01010101 ; + s->regs[R_OCM +1 ] = s->regs[R_OCM +2 ] =0x09090909 ; - s->regs[DEVCI_RAM ] =0x00000909 ; - s->regs[CSG_RAM ] =0x00000001 ; + s->regs[R_DEVCI_RAM ] =0x00000909 ; + s->regs[R_CSG_RAM ] =0x00000001 ; - s->regs[DDRIOB +0 ] = s->regs[DDRIOB +1 ] = s->regs[DDRIOB +2 ] - = s->regs[DDRIOB +3 ] =0x00000e00 ; - s->regs[DDRIOB +4 ] = s->regs[DDRIOB +5 ] = s->regs[DDRIOB +6 ] - =0x00000e00 ; - s->regs[DDRIOB +12 ] =0x00000021 ; + s->regs[R_DDRIOB +0 ] = s->regs[R_DDRIOB +1 ] = s->regs[R_DDRIOB +2 ] + = s->regs[R_DDRIOB +3 ] =0x00000e00 ; + s->regs[R_DDRIOB +4 ] = s->regs[R_DDRIOB +5 ] = s->regs[R_DDRIOB +6 ] + =0x00000e00 ; + s->regs[R_DDRIOB +12 ] =0x00000021 ; }static bool zynq_slcr_check_offset (hwaddr offset,bool rnw) {switch (offset) { -case LOCK : -case UNLOCK : -case DDR_CAL_START : -case DDR_REF_START : +case R_LOCK : +case R_UNLOCK : +case R_DDR_CAL_START : +case R_DDR_REF_START :return !rnw;/* Write only */ -case LOCKSTA : -case FPGA0_THR_STA : -case FPGA1_THR_STA : -case FPGA2_THR_STA : -case FPGA3_THR_STA : -case BOOT_MODE : -case PSS_IDCODE : -case DDR_CMD_STA : -case DDR_DFI_STATUS : -case PLL_STATUS : +case R_LOCKSTA : +case R_FPGA0_THR_STA : +case R_FPGA1_THR_STA : +case R_FPGA2_THR_STA : +case R_FPGA3_THR_STA : +case R_BOOT_MODE : +case R_PSS_IDCODE : +case R_DDR_CMD_STA : +case R_DDR_DFI_STATUS : +case R_PLL_STATUS :return rnw;/* read only */ -case SCL : - case ARM_PLL_CTRL ... IO_PLL_CTRL: - case ARM_PLL_CFG ... IO_PLL_CFG: - case ARM_CLK_CTRL ... TOPSW_CLK_CTRL: - case FPGA0_CLK_CTRL ... FPGA0_THR_CNT: - case FPGA1_CLK_CTRL ... FPGA1_THR_CNT: - case FPGA2_CLK_CTRL ... FPGA2_THR_CNT: - case FPGA3_CLK_CTRL ... FPGA3_THR_CNT: -case BANDGAP_TRIP : -case PLL_PREDIVISOR : -case CLK_621_TRUE : - case PSS_RST_CTRL ... A9_CPU_RST_CTRL: -case RS_AWDT_CTRL : -case RST_REASON : -case REBOOT_STATUS : -case APU_CTRL : -case WDT_CLK_SEL : - case TZ_DMA_NS ... TZ_DMA_PERIPH_NS: -case DDR_URGENT : -case DDR_URGENT_SEL : - case MIO ... MIO + MIO_LENGTH - 1: - case MIO_LOOPBACK ... MIO_MST_TRI1: -case SD0_WP_CD_SEL : -case SD1_WP_CD_SEL : -case LVL_SHFTR_EN : -case OCM_CFG : -case CPU_RAM : -case IOU : -case DMAC_RAM : - case AFI0 ... AFI3 + AFI_LENGTH - 1: -case OCM : -case DEVCI_RAM : -case CSG_RAM : - case GPIOB_CTRL ... GPIOB_CFG_CMOS33: -case GPIOB_CFG_HSTL : -case GPIOB_DRVR_BIAS_CTRL : - case DDRIOB ... DDRIOB + DDRIOB_LENGTH - 1: +case R_SCL : + case R_ARM_PLL_CTRL ... R_IO_PLL_CTRL: + case R_ARM_PLL_CFG ... R_IO_PLL_CFG: + case R_ARM_CLK_CTRL ... R_TOPSW_CLK_CTRL: + case R_FPGA0_CLK_CTRL ... R_FPGA0_THR_CNT: + case R_FPGA1_CLK_CTRL ... R_FPGA1_THR_CNT: + case R_FPGA2_CLK_CTRL ... R_FPGA2_THR_CNT: + case R_FPGA3_CLK_CTRL ... R_FPGA3_THR_CNT: +case R_BANDGAP_TRIP : +case R_PLL_PREDIVISOR : +case R_CLK_621_TRUE : + case R_PSS_RST_CTRL ... R_A9_CPU_RST_CTRL: +case R_RS_AWDT_CTRL : +case R_RST_REASON : +case R_REBOOT_STATUS : +case R_APU_CTRL : +case R_WDT_CLK_SEL : + case R_TZ_DMA_NS ... R_TZ_DMA_PERIPH_NS: +case R_DDR_URGENT : +case R_DDR_URGENT_SEL : + case R_MIO ... R_MIO + MIO_LENGTH - 1: + case R_MIO_LOOPBACK ... R_MIO_MST_TRI1: +case R_SD0_WP_CD_SEL : +case R_SD1_WP_CD_SEL : +case R_LVL_SHFTR_EN : +case R_OCM_CFG : +case R_CPU_RAM : +case R_IOU : +case R_DMAC_RAM : + case R_AFI0 ... R_AFI3 + AFI_LENGTH - 1: +case R_OCM : +case R_DEVCI_RAM : +case R_CSG_RAM : + case R_GPIOB_CTRL ... R_GPIOB_CFG_CMOS33: +case R_GPIOB_CFG_HSTL : +case R_GPIOB_DRVR_BIAS_CTRL : + case R_DDRIOB ... R_DDRIOB + DDRIOB_LENGTH - 1:return true;default :return false;@@ -370,24 +370,24 @@ static void zynq_slcr_write(void *opaque, hwaddr offset, }switch (offset) { -case SCL : - s->regs[SCL ] = val &0x1 ; +case R_SCL : + s->regs[R_SCL ] = val &0x1 ;return ; -case LOCK : +case R_LOCK :if ((val &0xFFFF ) ==XILINX_LOCK_KEY ) {DB_PRINT ("XILINX LOCK 0xF8000000 + 0x%x <= 0x%x\n" , (int )offset, (unsigned )val &0xFFFF ); - s->regs[LOCKSTA ] =1 ; + s->regs[R_LOCKSTA ] =1 ; }else {DB_PRINT ("WRONG XILINX LOCK KEY 0xF8000000 + 0x%x <= 0x%x\n" , (int )offset, (unsigned )val &0xFFFF ); }return ; -case UNLOCK : +case R_UNLOCK :if ((val &0xFFFF ) ==XILINX_UNLOCK_KEY ) {DB_PRINT ("XILINX UNLOCK 0xF8000000 + 0x%x <= 0x%x\n" , (int )offset, (unsigned )val &0xFFFF ); - s->regs[LOCKSTA ] =0 ; + s->regs[R_LOCKSTA ] =0 ; }else {DB_PRINT ("WRONG XILINX UNLOCK KEY 0xF8000000 + 0x%x <= 0x%x\n" , (int )offset, (unsigned )val &0xFFFF );@@ -395,7 +395,7 @@ static void zynq_slcr_write(void *opaque, hwaddr offset,return ; } -if (s->regs[LOCKSTA ]) { +if (s->regs[R_LOCKSTA ]) {qemu_log_mask (LOG_GUEST_ERROR ,"SCLR registers are locked. Unlock them first\n" );return ;@@ -403,8 +403,8 @@ static void zynq_slcr_write(void *opaque, hwaddr offset, s->regs[offset] = val;switch (offset) { -case PSS_RST_CTRL : -if (val &R_PSS_RST_CTRL_SOFT_RST ) { +case R_PSS_RST_CTRL : +if (FIELD_EX32 (val,PSS_RST_CTRL ,SOFT_RST )) {qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET ); }break ;
PATCH v4 8/10 hw/misc/zynq_slcr: add clock generation for uarts
In reply to [email protected]From: Damien Hedde <[email protected]>
Add 2 clock outputs for each uart (uart0 & 1):
+ the reference clock
+ the bus interface clock
The clock frequencies, and their respective resets, are computed using the internal pll & uart configuration registers.
All clocks depend on the main input clock (ps_clk), which is hard-coded to 33.33MHz (zcu102 evaluation board frequency and frequency specified in Xilinx's device tree file)
--- hw/misc/zynq_slcr.c | 155 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+)
hw/misc/zynq_slcr.c +155 -0
@@ -33,6 +33,8 @@ } \ } while (0) +#define INPUT_PS_REF_CLK_FREQUENCY (33333333) +#define XILINX_LOCK_KEY 0x767b#define XILINX_UNLOCK_KEY 0xdf0d
@@ -44,15 +46,27 @@ REG32(LOCKSTA, 0x00c) REG32(ARM_PLL_CTRL, 0x100) REG32(DDR_PLL_CTRL, 0x104)REG32 (IO_PLL_CTRL ,0x108 ) +/* fields for [ARM|DDR|IO_PLL]_CTRL registers */ + FIELD(xxx_PLL_CTRL, PLL_RESET, 0, 1) + FIELD(xxx_PLL_CTRL, PLL_PWRDWN, 1, 1) + FIELD(xxx_PLL_CTRL, PLL_BYPASS_QUAL, 3, 1) + FIELD(xxx_PLL_CTRL, PLL_BYPASS_FORCE, 4, 1) + FIELD(xxx_PLL_CTRL, PLL_FPDIV, 12, 7) REG32(PLL_STATUS, 0x10c) REG32(ARM_PLL_CFG, 0x110) REG32(DDR_PLL_CFG, 0x114) REG32(IO_PLL_CFG, 0x118) REG32(ARM_CLK_CTRL, 0x120) + FIELD(ARM_CLK_CTRL, SRCSEL, 4, 2) + FIELD(ARM_CLK_CTRL, DIVISOR, 8, 6) + FIELD(ARM_CLK_CTRL, CPU_1XCLKACT, 27, 1) + FIELD(ARM_CLK_CTRL, CPU_PERI_CLKACT, 28, 1) REG32(DDR_CLK_CTRL, 0x124) REG32(DCI_CLK_CTRL, 0x128) REG32(APER_CLK_CTRL, 0x12c) + FIELD(APER_CLK_CTRL, UART0_CPU1XCLKACT, 20, 1) + FIELD(APER_CLK_CTRL, UART1_CPU1XCLKACT, 21, 1) REG32(USB0_CLK_CTRL, 0x130) REG32(USB1_CLK_CTRL, 0x134)REG32 (GEM0_RCLK_CTRL ,0x138 )
@@ -63,12 +77,19 @@ REG32(SMC_CLK_CTRL, 0x148) REG32(LQSPI_CLK_CTRL, 0x14c) REG32(SDIO_CLK_CTRL, 0x150) REG32(UART_CLK_CTRL, 0x154) + FIELD(UART_CLK_CTRL, CLKACT0, 0, 1) + FIELD(UART_CLK_CTRL, CLKACT1, 1, 1) + FIELD(UART_CLK_CTRL, SRCSEL, 4, 2) + FIELD(UART_CLK_CTRL, DIVISOR, 8, 6) REG32(SPI_CLK_CTRL, 0x158) REG32(CAN_CLK_CTRL, 0x15c) REG32(CAN_MIOCLK_CTRL, 0x160) REG32(DBG_CLK_CTRL, 0x164) REG32(PCAP_CLK_CTRL, 0x168)REG32 (TOPSW_CLK_CTRL ,0x16c ) +/* common fields to lots of *_CLK_CTRL registers */ + FIELD(xxx_CLK_CTRL, SRCSEL, 4, 2) + FIELD(xxx_CLK_CTRL, DIVISOR, 8, 6)#define FPGA_CTRL_REGS (n, start) \ REG32(FPGA ## n ## _CLK_CTRL, (start)) \
@@ -96,6 +117,10 @@ REG32(SPI_RST_CTRL, 0x21c) REG32(CAN_RST_CTRL, 0x220) REG32(I2C_RST_CTRL, 0x224) REG32(UART_RST_CTRL, 0x228) + FIELD(UART_RST_CTRL, UART0_CPU1X_RST, 0, 1) + FIELD(UART_RST_CTRL, UART1_CPU1X_RST, 1, 1) + FIELD(UART_RST_CTRL, UART0_REF_RST, 2, 1) + FIELD(UART_RST_CTRL, UART1_REF_RST, 3, 1) REG32(GPIO_RST_CTRL, 0x22c) REG32(LQSPI_RST_CTRL, 0x230)REG32 (SMC_RST_CTRL ,0x234 )
@@ -178,8 +203,107 @@ typedef struct ZynqSLCRState {MemoryRegion iomem;uint32_t regs[ZYNQ_SLCR_NUM_REGS ]; + +ClockOut *uart0_amba_clk; +ClockOut *uart1_amba_clk; +ClockOut *uart0_ref_clk; +ClockOut *uart1_ref_clk; } ZynqSLCRState; +/* +* return the output frequency of ARM/DDR/IO pll +* using input frequency and PLL_CTRL register +*/ +static uint64_t zynq_slcr_compute_pll (uint64_t input,uint32_t ctrl_reg) +{ +uint32_t mult = ((ctrl_reg & R_xxx_PLL_CTRL_PLL_FPDIV_MASK) >> + R_xxx_PLL_CTRL_PLL_FPDIV_SHIFT); + +/* first, check if pll is bypassed */ +if (ctrl_reg & R_xxx_PLL_CTRL_PLL_BYPASS_FORCE_MASK) { +return input; + } + +/* is pll disabled ? */ +if (ctrl_reg & (R_xxx_PLL_CTRL_PLL_RESET_MASK | + R_xxx_PLL_CTRL_PLL_PWRDWN_MASK)) { +return 0 ; + } + +return input * mult; +} + +/* +* return the output frequency of a clock given: +* + the pll's frequencies in an array corresponding to mux's indexes +* + the register xxx_CLK_CTRL value +* + enable bit index in ctrl register +* +* This function make the assumption that ctrl_reg value is organized as follow: +* + bits[13:8] clock divisor +* + bits[5:4] clock mux selector (index in array) +* + bits[index] clock enable +*/ +static uint64_t zynq_slcr_compute_clock (const uint64_t plls[], +uint32_t ctrl_reg, +unsigned index) +{ +uint32_t divisor =FIELD_EX32 (ctrl_reg, xxx_CLK_CTRL,DIVISOR ); +uint32_t srcsel =FIELD_EX32 (ctrl_reg, xxx_CLK_CTRL,SRCSEL ); + +if ((ctrl_reg & (1u << index)) ==0 ) { +return 0 ; + } + +return plls[srcsel] / (divisor ? divisor :1u ); +} + +#define ZYNQ_CLOCK (_state, _plls, _reg, _enable_field) \ + zynq_slcr_compute_clock((_plls), (_state)->regs[R_ ## _reg], \ + R_ ## _reg ## _ ## _enable_field ## _SHIFT) +#define ZYNQ_CLOCK_GATE (_state, _clk, _reg, _field) \ + (ARRAY_FIELD_EX32((_state)->regs, _reg, _field) ? (_clk) : 0) +#define ZYNQ_CLOCK_RESET (_state, _reg, _field) \ + (ARRAY_FIELD_EX32((_state)->regs, _reg, _field) != 0) + +static void zynq_clock_set (ClockOut *clk,uint64_t freq,bool reset) +{ +ClockState value = { + .frequency = freq, + .domain_reset = reset, + }; +clock_set (clk, &value); +} + +static void zynq_slcr_compute_clocks (ZynqSLCRState *s) +{ +uint64_t ps_clk =INPUT_PS_REF_CLK_FREQUENCY ; +uint64_t io_pll =zynq_slcr_compute_pll (ps_clk, s->regs[R_IO_PLL_CTRL ]); +uint64_t arm_pll =zynq_slcr_compute_pll (ps_clk, s->regs[R_ARM_PLL_CTRL ]); +uint64_t ddr_pll =zynq_slcr_compute_pll (ps_clk, s->regs[R_DDR_PLL_CTRL ]); +uint64_t cpu_mux[4 ] = {arm_pll, arm_pll, ddr_pll, io_pll}; +uint64_t uart_mux[4 ] = {io_pll, io_pll, arm_pll, ddr_pll}; +uint64_t cpu1x_clk; + +/* compute uartX amba clocks */ + cpu1x_clk =ZYNQ_CLOCK (s, cpu_mux,ARM_CLK_CTRL ,CPU_PERI_CLKACT ); + cpu1x_clk =ZYNQ_CLOCK_GATE (s, cpu1x_clk,ARM_CLK_CTRL ,CPU_1XCLKACT ); +zynq_clock_set (s->uart0_amba_clk, +ZYNQ_CLOCK_GATE (s, cpu1x_clk,APER_CLK_CTRL ,UART0_CPU1XCLKACT ), +ZYNQ_CLOCK_RESET (s,UART_RST_CTRL ,UART0_CPU1X_RST )); +zynq_clock_set (s->uart1_amba_clk, +ZYNQ_CLOCK_GATE (s, cpu1x_clk,APER_CLK_CTRL ,UART1_CPU1XCLKACT ), +ZYNQ_CLOCK_RESET (s,UART_RST_CTRL ,UART1_CPU1X_RST )); + +/* compute uartX ref clocks */ +zynq_clock_set (s->uart0_ref_clk, +ZYNQ_CLOCK (s, uart_mux,UART_CLK_CTRL ,CLKACT0 ), +ZYNQ_CLOCK_RESET (s,UART_RST_CTRL ,UART0_REF_RST )); +zynq_clock_set (s->uart1_ref_clk, +ZYNQ_CLOCK (s, uart_mux,UART_CLK_CTRL ,CLKACT1 ), +ZYNQ_CLOCK_RESET (s,UART_RST_CTRL ,UART1_REF_RST )); +} +static void zynq_slcr_reset (DeviceState *d) {ZynqSLCRState *s =ZYNQ_SLCR (d);
@@ -274,6 +398,8 @@ static void zynq_slcr_reset(DeviceState *d) s->regs[R_DDRIOB +4 ] = s->regs[R_DDRIOB +5 ] = s->regs[R_DDRIOB +6 ] =0x00000e00 ; s->regs[R_DDRIOB +12 ] =0x00000021 ; + +zynq_slcr_compute_clocks (s); }
@@ -408,6 +534,15 @@ static void zynq_slcr_write(void *opaque, hwaddr offset,qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET ); }break ; +case R_IO_PLL_CTRL : +case R_ARM_PLL_CTRL : +case R_DDR_PLL_CTRL : +case R_ARM_CLK_CTRL : +case R_APER_CLK_CTRL : +case R_UART_CLK_CTRL : +case R_UART_RST_CTRL : +zynq_slcr_compute_clocks (s); +break ; } }
@@ -417,6 +552,14 @@ static const MemoryRegionOps slcr_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static const ClockPortInitArray zynq_slcr_clocks = { +QDEV_CLOCK_OUT (ZynqSLCRState, uart0_amba_clk), +QDEV_CLOCK_OUT (ZynqSLCRState, uart1_amba_clk), +QDEV_CLOCK_OUT (ZynqSLCRState, uart0_ref_clk), +QDEV_CLOCK_OUT (ZynqSLCRState, uart1_ref_clk), +QDEV_CLOCK_END , +}; +static void zynq_slcr_init (Object *obj) {ZynqSLCRState *s =ZYNQ_SLCR (obj);
@@ -424,12 +567,24 @@ static void zynq_slcr_init(Object *obj)memory_region_init_io (&s->iomem, obj, &slcr_ops, s,"slcr" ,ZYNQ_SLCR_MMIO_SIZE );sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->iomem); + +qdev_init_clocks (DEVICE (obj), zynq_slcr_clocks); +} + +static int zynq_slcr_post_load (void *opaque,int version_id) +{ +ZynqSLCRState *s = opaque; + +/* we need to setup all clock ports after migration */ +zynq_slcr_compute_clocks (s); +return 0 ; }static const VMStateDescription vmstate_zynq_slcr = { .name ="zynq_slcr" , .version_id =2 , .minimum_version_id =2 , + .post_load = zynq_slcr_post_load, .fields = (VMStateField []) {VMSTATE_UINT32_ARRAY (regs, ZynqSLCRState,ZYNQ_SLCR_NUM_REGS ),VMSTATE_END_OF_LIST ()
Signature · 1 line
2.18.0
PATCH v4 9/10 hw/char/cadence_uart: add clock support
In reply to [email protected]From: Damien Hedde <[email protected]>
Add bus interface and uart reference clock inputs.
Note: it is hard to find out from the doc what is the behavior when only one of the clock is disabled and what does each clock domain reset.
Right now, register access needs both clock being active.
The bus interface control the mmios visibility. Its associated reset does nothing apart from disabling the mmios.
The reference clock controls the baudrate generation. If it disabled, any input characters and events are ignored. Also register accesses are conditioned to the clock being enabled (but is it really the case in reality ?) and a guest error is triggerred if that is not the case. Its associated reset triggers the cadence_uart reset.
If theses clocks remains unconnected, the uart behaves as before.
--- include/hw/char/cadence_uart.h | 2 + hw/char/cadence_uart.c | 73 ++++++++++++++++++++++++++++++++-- hw/char/trace-events | 3 ++ 3 files changed, 74 insertions(+), 4 deletions(-)
include/hw/char/cadence_uart.h +2 -0
@@ -21,6 +21,7 @@#include "hw/sysbus.h" #include "chardev/char-fe.h" #include "qemu/timer.h" +#include "hw/clock-port.h" #define CADENCE_UART_RX_FIFO_SIZE 16#define CADENCE_UART_TX_FIFO_SIZE 16
@@ -47,6 +48,7 @@ typedef struct {CharBackend chr;qemu_irq irq;QEMUTimer *fifo_trigger_handle; +ClockState refclk; } CadenceUARTState; static inline DeviceState *cadence_uart_create(hwaddr addr,
hw/char/cadence_uart.c +69 -4
140 lines not on this page · raw message
hw/char/trace-events +3 -0
@@ -73,3 +73,6 @@ cmsdk_apb_uart_receive(uint8_t c) "CMSDK APB UART: got character 0x%x from backe cmsdk_apb_uart_tx_pending(void) "CMSDK APB UART: character send to backend pending" cmsdk_apb_uart_tx(uint8_t c) "CMSDK APB UART: character 0x%x sent to backend" cmsdk_apb_uart_set_params(int speed) "CMSDK APB UART: params set to %d 8N1" + +# hw/char/cadence_uart.c +cadence_uart_baudrate(unsigned baudrate) "baudrate %u"
Signature · 1 line
2.18.0
PATCH v4 10/10 hw/arm/xilinx_zynq: connect uart clocks to slcr
In reply to [email protected]From: Damien Hedde <[email protected]>
Add the connection between the slcr's output clocks and the uarts inputs.
--- hw/arm/xilinx_zynq.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
hw/arm/xilinx_zynq.c +11 -6
@@ -166,7 +166,7 @@ static void zynq_init(MachineState *machine)MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *ext_ram =g_new (MemoryRegion,1 );MemoryRegion *ocm_ram =g_new (MemoryRegion,1 ); -DeviceState *dev; +DeviceState *dev, *slcr;SysBusDevice *busdev;qemu_irq pic[64 ];int n;
@@ -212,9 +212,10 @@ static void zynq_init(MachineState *machine)1 ,0x0066 ,0x0022 ,0x0000 ,0x0000 ,0x0555 ,0x2aa , 0); - dev =qdev_create (NULL ,"xilinx,zynq_slcr" ); -qdev_init_nofail (dev); -sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,0xF8000000 ); +/* Create slcr, keep a pointer to connect clocks */ + slcr =qdev_create (NULL ,"xilinx,zynq_slcr" ); +qdev_init_nofail (slcr); +sysbus_mmio_map (SYS_BUS_DEVICE (slcr),0 ,0xF8000000 ); dev =qdev_create (NULL ,TYPE_A9MPCORE_PRIV );qdev_prop_set_uint32 (dev,"num-cpu" ,1 );
@@ -235,8 +236,12 @@ static void zynq_init(MachineState *machine)sysbus_create_simple ("xlnx,ps7-usb" ,0xE0002000 , pic[53 -IRQ_OFFSET ]);sysbus_create_simple ("xlnx,ps7-usb" ,0xE0003000 , pic[76 -IRQ_OFFSET ]); -cadence_uart_create (0xE0000000 , pic[59 -IRQ_OFFSET ],serial_hd (0 )); -cadence_uart_create (0xE0001000 , pic[82 -IRQ_OFFSET ],serial_hd (1 )); + dev =cadence_uart_create (0xE0000000 , pic[59 -IRQ_OFFSET ],serial_hd (0 )); +qdev_clock_connect (dev,"busclk" , slcr,"uart0_amba_clk" , &error_abort); +qdev_clock_connect (dev,"refclk" , slcr,"uart0_ref_clk" , &error_abort); + dev =cadence_uart_create (0xE0001000 , pic[82 -IRQ_OFFSET ],serial_hd (1 )); +qdev_clock_connect (dev,"busclk" , slcr,"uart1_amba_clk" , &error_abort); +qdev_clock_connect (dev,"refclk" , slcr,"uart1_ref_clk" , &error_abort);sysbus_create_varargs ("cadence_ttc" ,0xF8001000 , pic[42 -IRQ_OFFSET ], pic[43 -IRQ_OFFSET ], pic[44 -IRQ_OFFSET ],NULL );
Signature · 1 line
2.18.0
Quoted 6 lines · On 17 September 2018 at 01:40, <[email protected]> wrote:
Regarding the migration strategy, clocks do not hold the clock state internally, so there is nothing to migrate there. The consequence is that a device must update its output clocks in its
post_loadto propagate the migrated clock state. This allows migration from old-qemu-with-no-clock to new-qemu-with-clock-support: newly added clocks will be correctly initialized during migration.
Quoted 8 lines
But it is more complex for input clocks handling: there is no order guarantee between a device state migration and the update of its inputs clocks which will occur during other device state migrations.
I think that, for most the cases, this does not rise problems, although there might be some jitter/glitch during migration before hitting the right value (with consequences such as the baudrate of a character device changing several times during migration, I don't think it is a problem but may well be wrong here).
This doesn't seem like a good idea to me, since as you say there is no guarantee on migration order. It breaks a general principle that devices should migrate their own state and not do anything that disturbs other devices.
There are several possible approaches here I think:
(1) the "clock" object holds no internal state; if a device on the
destination end of a clock connection cares about clock state then it keeps and updates a copy of that state when the callback is called, and it is responsible for migrating that copy along with all its other state. This is how qemu_irq/gpio lines work.
(2) the "clock" object does hold internal state, and it is owned
by the source-end device, which is responsible for migrating that state. This is how ptimer objects work -- hw/core/ptimer.c defines a vmstate struct, but it is the devices that use a ptimer that put a VMSTATE_PTIMER entry in their vmstate structs to migrate the data.
(3) the "clock" object can be a fully fledged device (ie a subclass
of TYPE_DEVICE) which migrates its state entirely by itself.
I don't have a firm view currently on which would be best here, but I guess I lean towards 2. 1 has the advantage of "just like qemu_irq" but the disadvantage that the destination end has no way to query the current clock value so has to manually track it itself. 3 is probably overkill here (and also makes it hard to retain migration backward compatibility when adding clock tree support to an existing machine model).
Quoted 2 lines
Concerning this frequency-reset port, we can obviously go back to the simple frequency-only one if you think it is not a good idea.
I don't really understand why reset is related here. Clock trees and reset domains don't sit in a 1-to-1 relationship, generally. Reset is a complicated and painful area and I think I would prefer to see a patchset which aimed to solve the clocktree modelling problem without dragging in the complexities of reset modelling.
thanks
-- PMM
Quoted 36 lines · Peter Maydell
Quoted 6 lines · On 17 September 2018 at 01:40, <[email protected]> wrote:
Regarding the migration strategy, clocks do not hold the clock state internally, so there is nothing to migrate there. The consequence is that a device must update its output clocks in its
post_loadto propagate the migrated clock state. This allows migration from old-qemu-with-no-clock to new-qemu-with-clock-support: newly added clocks will be correctly initialized during migration.Quoted 8 lines
But it is more complex for input clocks handling: there is no order guarantee between a device state migration and the update of its inputs clocks which will occur during other device state migrations.
I think that, for most the cases, this does not rise problems, although there might be some jitter/glitch during migration before hitting the right value (with consequences such as the baudrate of a character device changing several times during migration, I don't think it is a problem but may well be wrong here).This doesn't seem like a good idea to me, since as you say there is no guarantee on migration order. It breaks a general principle that devices should migrate their own state and not do anything that disturbs other devices.
There are several possible approaches here I think:
(1) the "clock" object holds no internal state; if a device on the
destination end of a clock connection cares about clock state then it keeps and updates a copy of that state when the callback is called, and it is responsible for migrating that copy along with all its other state. This is how qemu_irq/gpio lines work.
(2) the "clock" object does hold internal state, and it is owned
by the source-end device, which is responsible for migrating that state. This is how ptimer objects work --hw/core/ptimer.cdefines a vmstate struct, but it is the devices that use a ptimer that put aVMSTATE_PTIMERentry in their vmstate structs to migrate the data.
(3) the "clock" object can be a fully fledged device (ie a subclass
ofTYPE_DEVICE) which migrates its state entirely by itself.
Quoted 7 lines
I don't have a firm view currently on which would be best here, but I guess I lean towards 2. 1 has the advantage of "just like
qemu_irq" but the disadvantage that the destination end has no way to query the current clock value so has to manually track it itself. 3 is probably overkill here (and also makes it hard to retain migration backward compatibility when adding clock tree support to an existing machine model).
I agree with you on doing approach 2. If the clock state needs to be at the end, it seems best to put in inside the clock object. It will save codelines in devices. Thanks for the tips about ptimer.
I don't see how approach 3 solves the problem since the clock state will still be migrated by another object (instead of begin the device which generate the clock, it is now the clock input object). So a device (with an input clock) has no guarantee on the clock value being correct when it will handle its own migration. I think the clock vmstate entry needs to be present in the device's vmsd (or am I missing something ?).
Regarding backward compatibility on migration, I think we have 2 options:
(A) keep updating outputs clocks in post_load.
(B) rely on device with an input clock to setup a "good" default value to unmigrated input clocks.
(A) has the advantage of ensuring an unmigrated input clock have right value just at the end of backward migration. But there's still the migration order jitter. (B) does not have the jitter, but unmigrated input clocks will be at their default values after the migration and will be updated maybe later on.
Given your statement about disturbing other devices, (B) seems the way to go.
Quoted 9 lines
Quoted 3 lines
Concerning this frequency-reset port, we can obviously go back to the simple frequency-only one if you think it is not a good idea.
I don't really understand why reset is related here. Clock trees and reset domains don't sit in a 1-to-1 relationship, generally. Reset is a complicated and painful area and I think I would prefer to see a patchset which aimed to solve the clocktree modelling problem without dragging in the complexities of reset modelling.
OK.
Do you think I should do a reroll right now with this 2 modifications without waiting further review ?
Thanks,
--
Damien