mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20200430-1' into staging
target-arm queue: * xlnx-zdma: Fix endianness handling of descriptor loading * nrf51: Fix last GPIO CNF address * gicv3: Use gicr_typer in arm_gicv3_icc_reset * msf2: Add EMAC block to SmartFusion2 SoC * New clock modelling framework * hw/arm: versal: Setup the ADMA with 128bit bus-width * Cadence: gem: fix wraparound in 64bit descriptors * cadence_gem: clear RX control descriptor * target/arm: Vectorize integer comparison vs zero * hw/arm/virt: dt: add kaslr-seed property * hw/arm: xlnx-zcu102: Disable unsupported FDT firmware nodes # gpg: Signature made Thu 30 Apr 2020 15:43:54 BST # gpg: using RSA key E1A5C593CD419DE28E8315CF3C2525ED14360CDE # gpg: issuer "peter.maydell@linaro.org" # gpg: Good signature from "Peter Maydell <peter.maydell@linaro.org>" [ultimate] # gpg: aka "Peter Maydell <pmaydell@gmail.com>" [ultimate] # gpg: aka "Peter Maydell <pmaydell@chiark.greenend.org.uk>" [ultimate] # Primary key fingerprint: E1A5 C593 CD41 9DE2 8E83 15CF 3C25 25ED 1436 0CDE * remotes/pmaydell/tags/pull-target-arm-20200430-1: (30 commits) hw/arm: xlnx-zcu102: Disable unsupported FDT firmware nodes hw/arm: xlnx-zcu102: Move arm_boot_info into XlnxZCU102 device_tree: Constify compat in qemu_fdt_node_path() device_tree: Allow name wildcards in qemu_fdt_node_path() target/arm/cpu: Update coding style to make checkpatch.pl happy target/arm: Make cpu_register() available for other files target/arm: Restrict the Address Translate write operation to TCG accel hw/arm/virt: dt: add kaslr-seed property hw/arm/virt: dt: move creation of /secure-chosen to create_fdt() target/arm: Vectorize integer comparison vs zero net: cadence_gem: clear RX control descriptor Cadence: gem: fix wraparound in 64bit descriptors hw/arm: versal: Setup the ADMA with 128bit bus-width qdev-monitor: print the device's clock with info qtree hw/arm/xilinx_zynq: connect uart clocks to slcr hw/char/cadence_uart: add clock support hw/misc/zynq_slcr: add clock generation for uarts docs/clocks: add device's clock documentation qdev-clock: introduce an init array to ease the device construction qdev: add clock input&output support to devices. ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
@@ -921,6 +921,8 @@ F: include/hw/arm/msf2-soc.h
|
||||
F: include/hw/misc/msf2-sysreg.h
|
||||
F: include/hw/timer/mss-timer.h
|
||||
F: include/hw/ssi/mss-spi.h
|
||||
F: hw/net/msf2-emac.c
|
||||
F: include/hw/net/msf2-emac.h
|
||||
|
||||
Emcraft M2S-FG484
|
||||
M: Subbaraya Sundeep <sundeep.lkml@gmail.com>
|
||||
|
||||
+2
-2
@@ -291,7 +291,7 @@ char **qemu_fdt_node_unit_path(void *fdt, const char *name, Error **errp)
|
||||
return path_array;
|
||||
}
|
||||
|
||||
char **qemu_fdt_node_path(void *fdt, const char *name, char *compat,
|
||||
char **qemu_fdt_node_path(void *fdt, const char *name, const char *compat,
|
||||
Error **errp)
|
||||
{
|
||||
int offset, len, ret;
|
||||
@@ -308,7 +308,7 @@ char **qemu_fdt_node_path(void *fdt, const char *name, char *compat,
|
||||
offset = len;
|
||||
break;
|
||||
}
|
||||
if (!strcmp(iter_name, name)) {
|
||||
if (!name || !strcmp(iter_name, name)) {
|
||||
char *path;
|
||||
|
||||
path = g_malloc(path_len);
|
||||
|
||||
@@ -0,0 +1,391 @@
|
||||
Modelling a clock tree in QEMU
|
||||
==============================
|
||||
|
||||
What are clocks?
|
||||
----------------
|
||||
|
||||
Clocks are QOM objects developed for the purpose of modelling the
|
||||
distribution of clocks in QEMU.
|
||||
|
||||
They allow us 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 object is *Clock* and its QOM name is ``clock`` (in C code, the macro
|
||||
``TYPE_CLOCK``).
|
||||
|
||||
Clocks are typically used with devices where they are used to model inputs
|
||||
and outputs. They are created in a similar way to GPIOs. Inputs and outputs
|
||||
of different devices can be connected together.
|
||||
|
||||
In these cases a Clock object is a child of a Device object, but this
|
||||
is not a requirement. Clocks can be independent of devices. For
|
||||
example it is possible to create a clock outside of any device to
|
||||
model the main clock source of a machine.
|
||||
|
||||
Here is an example of clocks::
|
||||
|
||||
+---------+ +----------------------+ +--------------+
|
||||
| Clock 1 | | Device B | | Device C |
|
||||
| | | +-------+ +-------+ | | +-------+ |
|
||||
| |>>-+-->>|Clock 2| |Clock 3|>>--->>|Clock 6| |
|
||||
+---------+ | | | (in) | | (out) | | | | (in) | |
|
||||
| | +-------+ +-------+ | | +-------+ |
|
||||
| | +-------+ | +--------------+
|
||||
| | |Clock 4|>>
|
||||
| | | (out) | | +--------------+
|
||||
| | +-------+ | | Device D |
|
||||
| | +-------+ | | +-------+ |
|
||||
| | |Clock 5|>>--->>|Clock 7| |
|
||||
| | | (out) | | | | (in) | |
|
||||
| | +-------+ | | +-------+ |
|
||||
| +----------------------+ | |
|
||||
| | +-------+ |
|
||||
+----------------------------->>|Clock 8| |
|
||||
| | (in) | |
|
||||
| +-------+ |
|
||||
+--------------+
|
||||
|
||||
Clocks are defined in the ``include/hw/clock.h`` header and device
|
||||
related functions are defined in the ``include/hw/qdev-clock.h``
|
||||
header.
|
||||
|
||||
The clock state
|
||||
---------------
|
||||
|
||||
The state of a clock is its period; it is stored as an integer
|
||||
representing it in units of 2 :sup:`-32` ns. The special value of 0 is used to
|
||||
represent the clock being inactive or gated. The clocks do not model
|
||||
the signal itself (pin toggling) or other properties such as the duty
|
||||
cycle.
|
||||
|
||||
All clocks contain this state: outputs as well as inputs. This allows
|
||||
the current period of a clock to be fetched at any time. When a clock
|
||||
is updated, the value is immediately propagated to all connected
|
||||
clocks in the tree.
|
||||
|
||||
To ease interaction with clocks, helpers with a unit suffix are defined for
|
||||
every clock state setter or getter. The suffixes are:
|
||||
|
||||
- ``_ns`` for handling periods in nanoseconds
|
||||
- ``_hz`` for handling frequencies in hertz
|
||||
|
||||
The 0 period value is converted to 0 in hertz and vice versa. 0 always means
|
||||
that the clock is disabled.
|
||||
|
||||
Adding a new clock
|
||||
------------------
|
||||
|
||||
Adding clocks to a device must be done during the init method of the Device
|
||||
instance.
|
||||
|
||||
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 callback (this will be explained in a following section).
|
||||
Output is simpler; 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 pointer, which should be saved in the
|
||||
device's state structure for further use.
|
||||
|
||||
These objects will be automatically deleted by the QOM reference mechanism.
|
||||
|
||||
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
|
||||
parameter to initialize the clocks: it has the same behaviour as calling the
|
||||
``qdev_init_clock_in/out()`` for each clock in the array. To ease the array
|
||||
construction, some macros are defined in ``include/hw/qdev-clock.h``.
|
||||
As an example, the following creates 2 clocks to a device: one input and one
|
||||
output.
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
/* device structure containing pointers to the clock objects */
|
||||
typedef struct MyDeviceState {
|
||||
DeviceState parent_obj;
|
||||
Clock *clk_in;
|
||||
Clock *clk_out;
|
||||
} MyDeviceState;
|
||||
|
||||
/*
|
||||
* callback for the input clock (see "Callback on input clock
|
||||
* change" section below for more information).
|
||||
*/
|
||||
static void clk_in_callback(void *opaque);
|
||||
|
||||
/*
|
||||
* static array describing clocks:
|
||||
* + a clock input named "clk_in", whose pointer is stored in
|
||||
* the clk_in field of a MyDeviceState structure with callback
|
||||
* clk_in_callback.
|
||||
* + a clock output named "clk_out" whose pointer is stored in
|
||||
* the clk_out field of a MyDeviceState structure.
|
||||
*/
|
||||
static const ClockPortInitArray mydev_clocks = {
|
||||
QDEV_CLOCK_IN(MyDeviceState, clk_in, clk_in_callback),
|
||||
QDEV_CLOCK_OUT(MyDeviceState, clk_out),
|
||||
QDEV_CLOCK_END
|
||||
};
|
||||
|
||||
/* device initialization function */
|
||||
static void mydev_init(Object *obj)
|
||||
{
|
||||
/* cast to MyDeviceState */
|
||||
MyDeviceState *mydev = MYDEVICE(obj);
|
||||
/* create and fill the pointer fields in the MyDeviceState */
|
||||
qdev_init_clocks(mydev, mydev_clocks);
|
||||
[...]
|
||||
}
|
||||
|
||||
An alternative way to create a clock is to simply call
|
||||
``object_new(TYPE_CLOCK)``. In that case the clock will neither be an
|
||||
input nor an output of a device. After the whole QOM hierarchy of the
|
||||
clock has been set ``clock_setup_canonical_path()`` should be called.
|
||||
|
||||
At creation, the period of the clock is 0: the clock is disabled. You can
|
||||
change it using ``clock_set_ns()`` or ``clock_set_hz()``.
|
||||
|
||||
Note that if you are creating a clock with a fixed period which will never
|
||||
change (for example the main clock source of a board), then you'll have
|
||||
nothing else to do. This value will be propagated to other clocks when
|
||||
connecting the clocks together and devices will fetch the right value during
|
||||
the first reset.
|
||||
|
||||
Retrieving clocks from a device
|
||||
-------------------------------
|
||||
|
||||
``qdev_get_clock_in()`` and ``dev_get_clock_out()`` are available to
|
||||
get the clock inputs or outputs of a device. For example:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
Clock *clk = qdev_get_clock_in(DEVICE(mydev), "clk_in");
|
||||
|
||||
or:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
Clock *clk = qdev_get_clock_out(DEVICE(mydev), "clk_out");
|
||||
|
||||
Connecting two clocks together
|
||||
------------------------------
|
||||
|
||||
To connect two clocks together, use the ``clock_set_source()`` function.
|
||||
Given two clocks ``clk1``, and ``clk2``, ``clock_set_source(clk2, clk1);``
|
||||
configures ``clk2`` to follow the ``clk1`` period changes. Every time ``clk1``
|
||||
is updated, ``clk2`` will be updated too.
|
||||
|
||||
When connecting clock between devices, prefer using the
|
||||
``qdev_connect_clock_in()`` function to set the source of an input
|
||||
device clock. For example, to connect the input clock ``clk2`` of
|
||||
``devB`` to the output clock ``clk1`` of ``devA``, do:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
qdev_connect_clock_in(devB, "clk2", qdev_get_clock_out(devA, "clk1"))
|
||||
|
||||
We used ``qdev_get_clock_out()`` above, but any clock can drive an
|
||||
input clock, even another input clock. The following diagram shows
|
||||
some examples of connections. Note also that a clock can drive several
|
||||
other clocks.
|
||||
|
||||
::
|
||||
|
||||
+------------+ +--------------------------------------------------+
|
||||
| Device A | | Device B |
|
||||
| | | +---------------------+ |
|
||||
| | | | Device C | |
|
||||
| +-------+ | | +-------+ | +-------+ +-------+ | +-------+ |
|
||||
| |Clock 1|>>-->>|Clock 2|>>+-->>|Clock 3| |Clock 5|>>>>|Clock 6|>>
|
||||
| | (out) | | | | (in) | | | | (in) | | (out) | | | (out) | |
|
||||
| +-------+ | | +-------+ | | +-------+ +-------+ | +-------+ |
|
||||
+------------+ | | +---------------------+ |
|
||||
| | |
|
||||
| | +--------------+ |
|
||||
| | | Device D | |
|
||||
| | | +-------+ | |
|
||||
| +-->>|Clock 4| | |
|
||||
| | | (in) | | |
|
||||
| | +-------+ | |
|
||||
| +--------------+ |
|
||||
+--------------------------------------------------+
|
||||
|
||||
In the above example, when *Clock 1* is updated by *Device A*, three
|
||||
clocks get the new clock period value: *Clock 2*, *Clock 3* and *Clock 4*.
|
||||
|
||||
It is not possible to disconnect a clock or to change the clock connection
|
||||
after it is connected.
|
||||
|
||||
Unconnected input clocks
|
||||
------------------------
|
||||
|
||||
A newly created input clock is disabled (period of 0). This means the
|
||||
clock will be considered as disabled until the period is updated. If
|
||||
the clock remains unconnected it will always keep its initial value
|
||||
of 0. If this is not the desired behaviour, ``clock_set()``,
|
||||
``clock_set_ns()`` or ``clock_set_hz()`` should be called on the Clock
|
||||
object during device instance init. For example:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
clk = qdev_init_clock_in(DEVICE(dev), "clk-in", clk_in_callback,
|
||||
dev);
|
||||
/* set initial value to 10ns / 100MHz */
|
||||
clock_set_ns(clk, 10);
|
||||
|
||||
Fetching clock frequency/period
|
||||
-------------------------------
|
||||
|
||||
To get the current state of a clock, use the functions ``clock_get()``,
|
||||
``clock_get_ns()`` or ``clock_get_hz()``.
|
||||
|
||||
It is also possible to register a callback on clock frequency changes.
|
||||
Here is an example:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
void clock_callback(void *opaque) {
|
||||
MyDeviceState *s = (MyDeviceState *) opaque;
|
||||
/*
|
||||
* 'opaque' is the argument passed to qdev_init_clock_in();
|
||||
* usually this will be the device state pointer.
|
||||
*/
|
||||
|
||||
/* do something with the new period */
|
||||
fprintf(stdout, "device new period is %" PRIu64 "ns\n",
|
||||
clock_get_ns(dev->my_clk_input));
|
||||
}
|
||||
|
||||
Changing a clock period
|
||||
-----------------------
|
||||
|
||||
A device can change its outputs using the ``clock_update()``,
|
||||
``clock_update_ns()`` or ``clock_update_hz()`` function. It will trigger
|
||||
updates on every connected input.
|
||||
|
||||
For example, let's say that we have an output clock *clkout* and we
|
||||
have a pointer to it in the device state because we did the following
|
||||
in init phase:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
dev->clkout = qdev_init_clock_out(DEVICE(dev), "clkout");
|
||||
|
||||
Then at any time (apart from the cases listed below), it is possible to
|
||||
change the clock value by doing:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
clock_update_hz(dev->clkout, 1000 * 1000 * 1000); /* 1GHz */
|
||||
|
||||
Because updating a clock may trigger any side effects through
|
||||
connected clocks and their callbacks, this operation must be done
|
||||
while holding the qemu io lock.
|
||||
|
||||
For the same reason, one can update clocks only when it is allowed to have
|
||||
side effects on other objects. In consequence, it is forbidden:
|
||||
|
||||
* during migration,
|
||||
* and in the enter phase of reset.
|
||||
|
||||
Note that calling ``clock_update[_ns|_hz]()`` is equivalent to calling
|
||||
``clock_set[_ns|_hz]()`` (with the same arguments) then
|
||||
``clock_propagate()`` on the clock. Thus, setting the clock value can
|
||||
be separated from triggering the side-effects. This is often required
|
||||
to factorize code to handle reset and migration in devices.
|
||||
|
||||
Aliasing clocks
|
||||
---------------
|
||||
|
||||
Sometimes, one needs to forward, or inherit, a clock from another
|
||||
device. Typically, when doing device composition, a device might
|
||||
expose a sub-device's clock without interfering with it. The function
|
||||
``qdev_alias_clock()`` can be used to achieve this behaviour. Note
|
||||
that it is possible to expose the clock under a different name.
|
||||
``qdev_alias_clock()`` works for both input and output clocks.
|
||||
|
||||
For example, if device B is a child of device A,
|
||||
``device_a_instance_init()`` may do something like this:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
void device_a_instance_init(Object *obj)
|
||||
{
|
||||
AState *A = DEVICE_A(obj);
|
||||
BState *B;
|
||||
/* create object B as child of A */
|
||||
[...]
|
||||
qdev_alias_clock(B, "clk", A, "b_clk");
|
||||
/*
|
||||
* Now A has a clock "b_clk" which is an alias to
|
||||
* the clock "clk" of its child B.
|
||||
*/
|
||||
}
|
||||
|
||||
This function does not return any clock object. The new clock has the
|
||||
same direction (input or output) as the original one. This function
|
||||
only adds a link to the existing clock. In the above example, object B
|
||||
remains the only object allowed to use the clock and device A must not
|
||||
try to change the clock period or set a callback to the clock. This
|
||||
diagram describes the example with an input clock::
|
||||
|
||||
+--------------------------+
|
||||
| Device A |
|
||||
| +--------------+ |
|
||||
| | Device B | |
|
||||
| | +-------+ | |
|
||||
>>"b_clk">>>| "clk" | | |
|
||||
| (in) | | (in) | | |
|
||||
| | +-------+ | |
|
||||
| +--------------+ |
|
||||
+--------------------------+
|
||||
|
||||
Migration
|
||||
---------
|
||||
|
||||
Clock state is not migrated automatically. Every device must handle its
|
||||
clock migration. Alias clocks must not be migrated.
|
||||
|
||||
To ensure clock states are restored correctly during migration, there
|
||||
are two solutions.
|
||||
|
||||
Clock states can be migrated by adding an entry into the device
|
||||
vmstate description. You should use the ``VMSTATE_CLOCK`` macro for this.
|
||||
This is typically used to migrate an input clock state. For example:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
MyDeviceState {
|
||||
DeviceState parent_obj;
|
||||
[...] /* some fields */
|
||||
Clock *clk;
|
||||
};
|
||||
|
||||
VMStateDescription my_device_vmstate = {
|
||||
.name = "my_device",
|
||||
.fields = (VMStateField[]) {
|
||||
[...], /* other migrated fields */
|
||||
VMSTATE_CLOCK(clk, MyDeviceState),
|
||||
VMSTATE_END_OF_LIST()
|
||||
}
|
||||
};
|
||||
|
||||
The second solution is to restore the clock state using information already
|
||||
at our disposal. This can be used to restore output clock states using the
|
||||
device state. The functions ``clock_set[_ns|_hz]()`` can be used during the
|
||||
``post_load()`` migration callback.
|
||||
|
||||
When adding clock support to an existing device, if you care about
|
||||
migration compatibility you will need to be careful, as simply adding
|
||||
a ``VMSTATE_CLOCK()`` line will break compatibility. Instead, you can
|
||||
put the ``VMSTATE_CLOCK()`` line into a vmstate subsection with a
|
||||
suitable ``needed`` function, and use ``clock_set()`` in a
|
||||
``pre_load()`` function to set the default value that will be used if
|
||||
the source virtual machine in the migration does not send the clock
|
||||
state.
|
||||
|
||||
Care should be taken not to use ``clock_update[_ns|_hz]()`` or
|
||||
``clock_propagate()`` during the whole migration procedure because it
|
||||
will trigger side effects to other devices in an unknown state.
|
||||
@@ -27,3 +27,4 @@ Contents:
|
||||
bitops
|
||||
reset
|
||||
s390-dasd-ipl
|
||||
clocks
|
||||
|
||||
+1
-1
@@ -222,7 +222,7 @@ void cpu_hotplug_hw_init(MemoryRegion *as, Object *owner,
|
||||
state->devs[i].arch_id = id_list->cpus[i].arch_id;
|
||||
}
|
||||
memory_region_init_io(&state->ctrl_reg, owner, &cpu_hotplug_ops, state,
|
||||
"acpi-mem-hotplug", ACPI_CPU_HOTPLUG_REG_LEN);
|
||||
"acpi-cpu-hotplug", ACPI_CPU_HOTPLUG_REG_LEN);
|
||||
memory_region_add_subregion(as, base_addr, &state->ctrl_reg);
|
||||
}
|
||||
|
||||
|
||||
+24
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SmartFusion2 SoC emulation.
|
||||
*
|
||||
* Copyright (c) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com>
|
||||
* Copyright (c) 2017-2020 Subbaraya Sundeep <sundeep.lkml@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -35,11 +35,14 @@
|
||||
|
||||
#define MSF2_TIMER_BASE 0x40004000
|
||||
#define MSF2_SYSREG_BASE 0x40038000
|
||||
#define MSF2_EMAC_BASE 0x40041000
|
||||
|
||||
#define ENVM_BASE_ADDRESS 0x60000000
|
||||
|
||||
#define SRAM_BASE_ADDRESS 0x20000000
|
||||
|
||||
#define MSF2_EMAC_IRQ 12
|
||||
|
||||
#define MSF2_ENVM_MAX_SIZE (512 * KiB)
|
||||
|
||||
/*
|
||||
@@ -81,6 +84,13 @@ static void m2sxxx_soc_initfn(Object *obj)
|
||||
sysbus_init_child_obj(obj, "spi[*]", &s->spi[i], sizeof(s->spi[i]),
|
||||
TYPE_MSS_SPI);
|
||||
}
|
||||
|
||||
sysbus_init_child_obj(obj, "emac", &s->emac, sizeof(s->emac),
|
||||
TYPE_MSS_EMAC);
|
||||
if (nd_table[0].used) {
|
||||
qemu_check_nic_model(&nd_table[0], TYPE_MSS_EMAC);
|
||||
qdev_set_nic_properties(DEVICE(&s->emac), &nd_table[0]);
|
||||
}
|
||||
}
|
||||
|
||||
static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
|
||||
@@ -192,6 +202,19 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
|
||||
g_free(bus_name);
|
||||
}
|
||||
|
||||
dev = DEVICE(&s->emac);
|
||||
object_property_set_link(OBJECT(&s->emac), OBJECT(get_system_memory()),
|
||||
"ahb-bus", &error_abort);
|
||||
object_property_set_bool(OBJECT(&s->emac), true, "realized", &err);
|
||||
if (err != NULL) {
|
||||
error_propagate(errp, err);
|
||||
return;
|
||||
}
|
||||
busdev = SYS_BUS_DEVICE(dev);
|
||||
sysbus_mmio_map(busdev, 0, MSF2_EMAC_BASE);
|
||||
sysbus_connect_irq(busdev, 0,
|
||||
qdev_get_gpio_in(armv7m, MSF2_EMAC_IRQ));
|
||||
|
||||
/* Below devices are not modelled yet. */
|
||||
create_unimplemented_device("i2c_0", 0x40002000, 0x1000);
|
||||
create_unimplemented_device("dma", 0x40003000, 0x1000);
|
||||
@@ -202,7 +225,6 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
|
||||
create_unimplemented_device("can", 0x40015000, 0x1000);
|
||||
create_unimplemented_device("rtc", 0x40017000, 0x1000);
|
||||
create_unimplemented_device("apb_config", 0x40020000, 0x10000);
|
||||
create_unimplemented_device("emac", 0x40041000, 0x1000);
|
||||
create_unimplemented_device("usb", 0x40043000, 0x1000);
|
||||
}
|
||||
|
||||
|
||||
+19
-1
@@ -77,6 +77,7 @@
|
||||
#include "hw/acpi/generic_event_device.h"
|
||||
#include "hw/virtio/virtio-iommu.h"
|
||||
#include "hw/char/pl011.h"
|
||||
#include "qemu/guest-random.h"
|
||||
|
||||
#define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \
|
||||
static void virt_##major##_##minor##_class_init(ObjectClass *oc, \
|
||||
@@ -213,6 +214,18 @@ static bool cpu_type_valid(const char *cpu)
|
||||
return false;
|
||||
}
|
||||
|
||||
static void create_kaslr_seed(VirtMachineState *vms, const char *node)
|
||||
{
|
||||
Error *err = NULL;
|
||||
uint64_t seed;
|
||||
|
||||
if (qemu_guest_getrandom(&seed, sizeof(seed), &err)) {
|
||||
error_free(err);
|
||||
return;
|
||||
}
|
||||
qemu_fdt_setprop_u64(vms->fdt, node, "kaslr-seed", seed);
|
||||
}
|
||||
|
||||
static void create_fdt(VirtMachineState *vms)
|
||||
{
|
||||
MachineState *ms = MACHINE(vms);
|
||||
@@ -233,6 +246,12 @@ static void create_fdt(VirtMachineState *vms)
|
||||
|
||||
/* /chosen must exist for load_dtb to fill in necessary properties later */
|
||||
qemu_fdt_add_subnode(fdt, "/chosen");
|
||||
create_kaslr_seed(vms, "/chosen");
|
||||
|
||||
if (vms->secure) {
|
||||
qemu_fdt_add_subnode(fdt, "/secure-chosen");
|
||||
create_kaslr_seed(vms, "/secure-chosen");
|
||||
}
|
||||
|
||||
/* Clock node, for the benefit of the UART. The kernel device tree
|
||||
* binding documentation claims the PL011 node clock properties are
|
||||
@@ -761,7 +780,6 @@ static void create_uart(const VirtMachineState *vms, int uart,
|
||||
qemu_fdt_setprop_string(vms->fdt, nodename, "status", "disabled");
|
||||
qemu_fdt_setprop_string(vms->fdt, nodename, "secure-status", "okay");
|
||||
|
||||
qemu_fdt_add_subnode(vms->fdt, "/secure-chosen");
|
||||
qemu_fdt_setprop_string(vms->fdt, "/secure-chosen", "stdout-path",
|
||||
nodename);
|
||||
}
|
||||
|
||||
+49
-8
@@ -35,6 +35,15 @@
|
||||
#include "hw/char/cadence_uart.h"
|
||||
#include "hw/net/cadence_gem.h"
|
||||
#include "hw/cpu/a9mpcore.h"
|
||||
#include "hw/qdev-clock.h"
|
||||
#include "sysemu/reset.h"
|
||||
|
||||
#define TYPE_ZYNQ_MACHINE MACHINE_TYPE_NAME("xilinx-zynq-a9")
|
||||
#define ZYNQ_MACHINE(obj) \
|
||||
OBJECT_CHECK(ZynqMachineState, (obj), TYPE_ZYNQ_MACHINE)
|
||||
|
||||
/* board base frequency: 33.333333 MHz */
|
||||
#define PS_CLK_FREQUENCY (100 * 1000 * 1000 / 3)
|
||||
|
||||
#define NUM_SPI_FLASHES 4
|
||||
#define NUM_QSPI_FLASHES 2
|
||||
@@ -75,6 +84,11 @@ static const int dma_irqs[8] = {
|
||||
0xe3401000 + ARMV7_IMM16(extract32((val), 16, 16)), /* movt r1 ... */ \
|
||||
0xe5801000 + (addr)
|
||||
|
||||
typedef struct ZynqMachineState {
|
||||
MachineState parent;
|
||||
Clock *ps_clk;
|
||||
} ZynqMachineState;
|
||||
|
||||
static void zynq_write_board_setup(ARMCPU *cpu,
|
||||
const struct arm_boot_info *info)
|
||||
{
|
||||
@@ -159,10 +173,11 @@ static inline void zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq,
|
||||
|
||||
static void zynq_init(MachineState *machine)
|
||||
{
|
||||
ZynqMachineState *zynq_machine = ZYNQ_MACHINE(machine);
|
||||
ARMCPU *cpu;
|
||||
MemoryRegion *address_space_mem = get_system_memory();
|
||||
MemoryRegion *ocm_ram = g_new(MemoryRegion, 1);
|
||||
DeviceState *dev;
|
||||
DeviceState *dev, *slcr;
|
||||
SysBusDevice *busdev;
|
||||
qemu_irq pic[64];
|
||||
int n;
|
||||
@@ -206,9 +221,18 @@ 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);
|
||||
|
||||
/* Create the main clock source, and feed slcr with it */
|
||||
zynq_machine->ps_clk = CLOCK(object_new(TYPE_CLOCK));
|
||||
object_property_add_child(OBJECT(zynq_machine), "ps_clk",
|
||||
OBJECT(zynq_machine->ps_clk), &error_abort);
|
||||
object_unref(OBJECT(zynq_machine->ps_clk));
|
||||
clock_set_hz(zynq_machine->ps_clk, PS_CLK_FREQUENCY);
|
||||
qdev_connect_clock_in(slcr, "ps_clk", zynq_machine->ps_clk);
|
||||
|
||||
dev = qdev_create(NULL, TYPE_A9MPCORE_PRIV);
|
||||
qdev_prop_set_uint32(dev, "num-cpu", 1);
|
||||
@@ -229,8 +253,12 @@ static void zynq_init(MachineState *machine)
|
||||
sysbus_create_simple(TYPE_CHIPIDEA, 0xE0002000, pic[53 - IRQ_OFFSET]);
|
||||
sysbus_create_simple(TYPE_CHIPIDEA, 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_connect_clock_in(dev, "refclk",
|
||||
qdev_get_clock_out(slcr, "uart0_ref_clk"));
|
||||
dev = cadence_uart_create(0xE0001000, pic[82 - IRQ_OFFSET], serial_hd(1));
|
||||
qdev_connect_clock_in(dev, "refclk",
|
||||
qdev_get_clock_out(slcr, "uart1_ref_clk"));
|
||||
|
||||
sysbus_create_varargs("cadence_ttc", 0xF8001000,
|
||||
pic[42-IRQ_OFFSET], pic[43-IRQ_OFFSET], pic[44-IRQ_OFFSET], NULL);
|
||||
@@ -308,8 +336,9 @@ static void zynq_init(MachineState *machine)
|
||||
arm_load_kernel(ARM_CPU(first_cpu), machine, &zynq_binfo);
|
||||
}
|
||||
|
||||
static void zynq_machine_init(MachineClass *mc)
|
||||
static void zynq_machine_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
MachineClass *mc = MACHINE_CLASS(oc);
|
||||
mc->desc = "Xilinx Zynq Platform Baseboard for Cortex-A9";
|
||||
mc->init = zynq_init;
|
||||
mc->max_cpus = 1;
|
||||
@@ -319,4 +348,16 @@ static void zynq_machine_init(MachineClass *mc)
|
||||
mc->default_ram_id = "zynq.ext_ram";
|
||||
}
|
||||
|
||||
DEFINE_MACHINE("xilinx-zynq-a9", zynq_machine_init)
|
||||
static const TypeInfo zynq_machine_type = {
|
||||
.name = TYPE_ZYNQ_MACHINE,
|
||||
.parent = TYPE_MACHINE,
|
||||
.class_init = zynq_machine_class_init,
|
||||
.instance_size = sizeof(ZynqMachineState),
|
||||
};
|
||||
|
||||
static void zynq_machine_register_types(void)
|
||||
{
|
||||
type_register_static(&zynq_machine_type);
|
||||
}
|
||||
|
||||
type_init(zynq_machine_register_types)
|
||||
|
||||
@@ -205,6 +205,8 @@ static void versal_create_admas(Versal *s, qemu_irq *pic)
|
||||
|
||||
dev = qdev_create(NULL, "xlnx.zdma");
|
||||
s->lpd.iou.adma[i] = SYS_BUS_DEVICE(dev);
|
||||
object_property_set_int(OBJECT(s->lpd.iou.adma[i]), 128, "bus-width",
|
||||
&error_abort);
|
||||
object_property_add_child(OBJECT(s), name, OBJECT(dev), &error_fatal);
|
||||
qdev_init_nofail(dev);
|
||||
|
||||
|
||||
+35
-4
@@ -23,6 +23,7 @@
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/log.h"
|
||||
#include "sysemu/qtest.h"
|
||||
#include "sysemu/device_tree.h"
|
||||
|
||||
typedef struct XlnxZCU102 {
|
||||
MachineState parent_obj;
|
||||
@@ -31,13 +32,14 @@ typedef struct XlnxZCU102 {
|
||||
|
||||
bool secure;
|
||||
bool virt;
|
||||
|
||||
struct arm_boot_info binfo;
|
||||
} XlnxZCU102;
|
||||
|
||||
#define TYPE_ZCU102_MACHINE MACHINE_TYPE_NAME("xlnx-zcu102")
|
||||
#define ZCU102_MACHINE(obj) \
|
||||
OBJECT_CHECK(XlnxZCU102, (obj), TYPE_ZCU102_MACHINE)
|
||||
|
||||
static struct arm_boot_info xlnx_zcu102_binfo;
|
||||
|
||||
static bool zcu102_get_secure(Object *obj, Error **errp)
|
||||
{
|
||||
@@ -67,6 +69,34 @@ static void zcu102_set_virt(Object *obj, bool value, Error **errp)
|
||||
s->virt = value;
|
||||
}
|
||||
|
||||
static void zcu102_modify_dtb(const struct arm_boot_info *binfo, void *fdt)
|
||||
{
|
||||
XlnxZCU102 *s = container_of(binfo, XlnxZCU102, binfo);
|
||||
bool method_is_hvc;
|
||||
char **node_path;
|
||||
const char *r;
|
||||
int prop_len;
|
||||
int i;
|
||||
|
||||
/* If EL3 is enabled, we keep all firmware nodes active. */
|
||||
if (!s->secure) {
|
||||
node_path = qemu_fdt_node_path(fdt, NULL, "xlnx,zynqmp-firmware",
|
||||
&error_fatal);
|
||||
|
||||
for (i = 0; node_path && node_path[i]; i++) {
|
||||
r = qemu_fdt_getprop(fdt, node_path[i], "method", &prop_len, NULL);
|
||||
method_is_hvc = r && !strcmp("hvc", r);
|
||||
|
||||
/* Allow HVC based firmware if EL2 is enabled. */
|
||||
if (method_is_hvc && s->virt) {
|
||||
continue;
|
||||
}
|
||||
qemu_fdt_setprop_string(fdt, node_path[i], "status", "disabled");
|
||||
}
|
||||
g_strfreev(node_path);
|
||||
}
|
||||
}
|
||||
|
||||
static void xlnx_zcu102_init(MachineState *machine)
|
||||
{
|
||||
XlnxZCU102 *s = ZCU102_MACHINE(machine);
|
||||
@@ -166,9 +196,10 @@ static void xlnx_zcu102_init(MachineState *machine)
|
||||
|
||||
/* TODO create and connect IDE devices for ide_drive_get() */
|
||||
|
||||
xlnx_zcu102_binfo.ram_size = ram_size;
|
||||
xlnx_zcu102_binfo.loader_start = 0;
|
||||
arm_load_kernel(s->soc.boot_cpu_ptr, machine, &xlnx_zcu102_binfo);
|
||||
s->binfo.ram_size = ram_size;
|
||||
s->binfo.loader_start = 0;
|
||||
s->binfo.modify_dtb = zcu102_modify_dtb;
|
||||
arm_load_kernel(s->soc.boot_cpu_ptr, machine, &s->binfo);
|
||||
}
|
||||
|
||||
static void xlnx_zcu102_machine_instance_init(Object *obj)
|
||||
|
||||
+63
-10
@@ -31,6 +31,8 @@
|
||||
#include "qemu/module.h"
|
||||
#include "hw/char/cadence_uart.h"
|
||||
#include "hw/irq.h"
|
||||
#include "hw/qdev-clock.h"
|
||||
#include "trace.h"
|
||||
|
||||
#ifdef CADENCE_UART_ERR_DEBUG
|
||||
#define DB_PRINT(...) do { \
|
||||
@@ -97,7 +99,7 @@
|
||||
#define LOCAL_LOOPBACK (0x2 << UART_MR_CHMODE_SH)
|
||||
#define REMOTE_LOOPBACK (0x3 << UART_MR_CHMODE_SH)
|
||||
|
||||
#define UART_INPUT_CLK 50000000
|
||||
#define UART_DEFAULT_REF_CLK (50 * 1000 * 1000)
|
||||
|
||||
#define R_CR (0x00/4)
|
||||
#define R_MR (0x04/4)
|
||||
@@ -171,12 +173,15 @@ static void uart_send_breaks(CadenceUARTState *s)
|
||||
static void uart_parameters_setup(CadenceUARTState *s)
|
||||
{
|
||||
QEMUSerialSetParams ssp;
|
||||
unsigned int baud_rate, packet_size;
|
||||
unsigned int baud_rate, packet_size, input_clk;
|
||||
input_clk = clock_get_hz(s->refclk);
|
||||
|
||||
baud_rate = (s->r[R_MR] & UART_MR_CLKS) ?
|
||||
UART_INPUT_CLK / 8 : UART_INPUT_CLK;
|
||||
baud_rate = (s->r[R_MR] & UART_MR_CLKS) ? input_clk / 8 : input_clk;
|
||||
baud_rate /= (s->r[R_BRGR] * (s->r[R_BDIV] + 1));
|
||||
trace_cadence_uart_baudrate(baud_rate);
|
||||
|
||||
ssp.speed = baud_rate;
|
||||
|
||||
ssp.speed = baud_rate / (s->r[R_BRGR] * (s->r[R_BDIV] + 1));
|
||||
packet_size = 1;
|
||||
|
||||
switch (s->r[R_MR] & UART_MR_PAR) {
|
||||
@@ -215,6 +220,13 @@ static void uart_parameters_setup(CadenceUARTState *s)
|
||||
}
|
||||
|
||||
packet_size += ssp.data_bits + ssp.stop_bits;
|
||||
if (ssp.speed == 0) {
|
||||
/*
|
||||
* Avoid division-by-zero below.
|
||||
* TODO: find something better
|
||||
*/
|
||||
ssp.speed = 1;
|
||||
}
|
||||
s->char_tx_time = (NANOSECONDS_PER_SECOND / ssp.speed) * packet_size;
|
||||
qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
|
||||
}
|
||||
@@ -340,6 +352,11 @@ static void uart_receive(void *opaque, const uint8_t *buf, int size)
|
||||
CadenceUARTState *s = opaque;
|
||||
uint32_t ch_mode = s->r[R_MR] & UART_MR_CHMODE;
|
||||
|
||||
/* ignore characters when unclocked or in reset */
|
||||
if (!clock_is_enabled(s->refclk) || device_is_in_reset(DEVICE(s))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ch_mode == NORMAL_MODE || ch_mode == ECHO_MODE) {
|
||||
uart_write_rx_fifo(opaque, buf, size);
|
||||
}
|
||||
@@ -353,6 +370,11 @@ static void uart_event(void *opaque, QEMUChrEvent event)
|
||||
CadenceUARTState *s = opaque;
|
||||
uint8_t buf = '\0';
|
||||
|
||||
/* ignore characters when unclocked or in reset */
|
||||
if (!clock_is_enabled(s->refclk) || device_is_in_reset(DEVICE(s))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event == CHR_EVENT_BREAK) {
|
||||
uart_write_rx_fifo(opaque, &buf, 1);
|
||||
}
|
||||
@@ -462,9 +484,9 @@ static const MemoryRegionOps uart_ops = {
|
||||
.endianness = DEVICE_NATIVE_ENDIAN,
|
||||
};
|
||||
|
||||
static void cadence_uart_reset(DeviceState *dev)
|
||||
static void cadence_uart_reset_init(Object *obj, ResetType type)
|
||||
{
|
||||
CadenceUARTState *s = CADENCE_UART(dev);
|
||||
CadenceUARTState *s = CADENCE_UART(obj);
|
||||
|
||||
s->r[R_CR] = 0x00000128;
|
||||
s->r[R_IMR] = 0;
|
||||
@@ -473,6 +495,11 @@ static void cadence_uart_reset(DeviceState *dev)
|
||||
s->r[R_BRGR] = 0x0000028B;
|
||||
s->r[R_BDIV] = 0x0000000F;
|
||||
s->r[R_TTRIG] = 0x00000020;
|
||||
}
|
||||
|
||||
static void cadence_uart_reset_hold(Object *obj)
|
||||
{
|
||||
CadenceUARTState *s = CADENCE_UART(obj);
|
||||
|
||||
uart_rx_reset(s);
|
||||
uart_tx_reset(s);
|
||||
@@ -491,6 +518,14 @@ static void cadence_uart_realize(DeviceState *dev, Error **errp)
|
||||
uart_event, NULL, s, NULL, true);
|
||||
}
|
||||
|
||||
static void cadence_uart_refclk_update(void *opaque)
|
||||
{
|
||||
CadenceUARTState *s = opaque;
|
||||
|
||||
/* recompute uart's speed on clock change */
|
||||
uart_parameters_setup(s);
|
||||
}
|
||||
|
||||
static void cadence_uart_init(Object *obj)
|
||||
{
|
||||
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
||||
@@ -500,9 +535,23 @@ static void cadence_uart_init(Object *obj)
|
||||
sysbus_init_mmio(sbd, &s->iomem);
|
||||
sysbus_init_irq(sbd, &s->irq);
|
||||
|
||||
s->refclk = qdev_init_clock_in(DEVICE(obj), "refclk",
|
||||
cadence_uart_refclk_update, s);
|
||||
/* initialize the frequency in case the clock remains unconnected */
|
||||
clock_set_hz(s->refclk, UART_DEFAULT_REF_CLK);
|
||||
|
||||
s->char_tx_time = (NANOSECONDS_PER_SECOND / 9600) * 10;
|
||||
}
|
||||
|
||||
static int cadence_uart_pre_load(void *opaque)
|
||||
{
|
||||
CadenceUARTState *s = opaque;
|
||||
|
||||
/* the frequency will be overriden if the refclk field is present */
|
||||
clock_set_hz(s->refclk, UART_DEFAULT_REF_CLK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cadence_uart_post_load(void *opaque, int version_id)
|
||||
{
|
||||
CadenceUARTState *s = opaque;
|
||||
@@ -521,8 +570,9 @@ static int cadence_uart_post_load(void *opaque, int version_id)
|
||||
|
||||
static const VMStateDescription vmstate_cadence_uart = {
|
||||
.name = "cadence_uart",
|
||||
.version_id = 2,
|
||||
.version_id = 3,
|
||||
.minimum_version_id = 2,
|
||||
.pre_load = cadence_uart_pre_load,
|
||||
.post_load = cadence_uart_post_load,
|
||||
.fields = (VMStateField[]) {
|
||||
VMSTATE_UINT32_ARRAY(r, CadenceUARTState, CADENCE_UART_R_MAX),
|
||||
@@ -534,8 +584,9 @@ static const VMStateDescription vmstate_cadence_uart = {
|
||||
VMSTATE_UINT32(tx_count, CadenceUARTState),
|
||||
VMSTATE_UINT32(rx_wpos, CadenceUARTState),
|
||||
VMSTATE_TIMER_PTR(fifo_trigger_handle, CadenceUARTState),
|
||||
VMSTATE_CLOCK_V(refclk, CadenceUARTState, 3),
|
||||
VMSTATE_END_OF_LIST()
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
static Property cadence_uart_properties[] = {
|
||||
@@ -546,10 +597,12 @@ static Property cadence_uart_properties[] = {
|
||||
static void cadence_uart_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||
ResettableClass *rc = RESETTABLE_CLASS(klass);
|
||||
|
||||
dc->realize = cadence_uart_realize;
|
||||
dc->vmsd = &vmstate_cadence_uart;
|
||||
dc->reset = cadence_uart_reset;
|
||||
rc->phases.enter = cadence_uart_reset_init;
|
||||
rc->phases.hold = cadence_uart_reset_hold;
|
||||
device_class_set_props(dc, cadence_uart_properties);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,3 +97,6 @@ exynos_uart_wo_read(uint32_t channel, const char *name, uint32_t reg) "UART%d: T
|
||||
exynos_uart_rxsize(uint32_t channel, uint32_t size) "UART%d: Rx FIFO size: %d"
|
||||
exynos_uart_channel_error(uint32_t channel) "Wrong UART channel number: %d"
|
||||
exynos_uart_rx_timeout(uint32_t channel, uint32_t stat, uint32_t intsp) "UART%d: Rx timeout stat=0x%x intsp=0x%x"
|
||||
|
||||
# hw/char/cadence_uart.c
|
||||
cadence_uart_baudrate(unsigned baudrate) "baudrate %u"
|
||||
|
||||
@@ -7,6 +7,7 @@ common-obj-y += hotplug.o
|
||||
common-obj-y += vmstate-if.o
|
||||
# irq.o needed for qdev GPIO handling:
|
||||
common-obj-y += irq.o
|
||||
common-obj-y += clock.o qdev-clock.o
|
||||
|
||||
common-obj-$(CONFIG_SOFTMMU) += reset.o
|
||||
common-obj-$(CONFIG_SOFTMMU) += qdev-fw.o
|
||||
@@ -20,6 +21,7 @@ common-obj-$(CONFIG_SOFTMMU) += null-machine.o
|
||||
common-obj-$(CONFIG_SOFTMMU) += loader.o
|
||||
common-obj-$(CONFIG_SOFTMMU) += machine-hmp-cmds.o
|
||||
common-obj-$(CONFIG_SOFTMMU) += numa.o
|
||||
common-obj-$(CONFIG_SOFTMMU) += clock-vmstate.o
|
||||
obj-$(CONFIG_SOFTMMU) += machine-qmp-cmds.o
|
||||
|
||||
common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Clock migration structure
|
||||
*
|
||||
* Copyright GreenSocs 2019-2020
|
||||
*
|
||||
* Authors:
|
||||
* Damien Hedde
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "migration/vmstate.h"
|
||||
#include "hw/clock.h"
|
||||
|
||||
const VMStateDescription vmstate_clock = {
|
||||
.name = "clock",
|
||||
.version_id = 0,
|
||||
.minimum_version_id = 0,
|
||||
.fields = (VMStateField[]) {
|
||||
VMSTATE_UINT64(period, Clock),
|
||||
VMSTATE_END_OF_LIST()
|
||||
}
|
||||
};
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Hardware Clocks
|
||||
*
|
||||
* Copyright GreenSocs 2016-2020
|
||||
*
|
||||
* Authors:
|
||||
* Frederic Konrad
|
||||
* Damien Hedde
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "hw/clock.h"
|
||||
#include "trace.h"
|
||||
|
||||
#define CLOCK_PATH(_clk) (_clk->canonical_path)
|
||||
|
||||
void clock_setup_canonical_path(Clock *clk)
|
||||
{
|
||||
g_free(clk->canonical_path);
|
||||
clk->canonical_path = object_get_canonical_path(OBJECT(clk));
|
||||
}
|
||||
|
||||
void clock_set_callback(Clock *clk, ClockCallback *cb, void *opaque)
|
||||
{
|
||||
clk->callback = cb;
|
||||
clk->callback_opaque = opaque;
|
||||
}
|
||||
|
||||
void clock_clear_callback(Clock *clk)
|
||||
{
|
||||
clock_set_callback(clk, NULL, NULL);
|
||||
}
|
||||
|
||||
void clock_set(Clock *clk, uint64_t period)
|
||||
{
|
||||
trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_NS(clk->period),
|
||||
CLOCK_PERIOD_TO_NS(period));
|
||||
clk->period = period;
|
||||
}
|
||||
|
||||
static void clock_propagate_period(Clock *clk, bool call_callbacks)
|
||||
{
|
||||
Clock *child;
|
||||
|
||||
QLIST_FOREACH(child, &clk->children, sibling) {
|
||||
if (child->period != clk->period) {
|
||||
child->period = clk->period;
|
||||
trace_clock_update(CLOCK_PATH(child), CLOCK_PATH(clk),
|
||||
CLOCK_PERIOD_TO_NS(clk->period),
|
||||
call_callbacks);
|
||||
if (call_callbacks && child->callback) {
|
||||
child->callback(child->callback_opaque);
|
||||
}
|
||||
clock_propagate_period(child, call_callbacks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clock_propagate(Clock *clk)
|
||||
{
|
||||
assert(clk->source == NULL);
|
||||
trace_clock_propagate(CLOCK_PATH(clk));
|
||||
clock_propagate_period(clk, true);
|
||||
}
|
||||
|
||||
void clock_set_source(Clock *clk, Clock *src)
|
||||
{
|
||||
/* changing clock source is not supported */
|
||||
assert(!clk->source);
|
||||
|
||||
trace_clock_set_source(CLOCK_PATH(clk), CLOCK_PATH(src));
|
||||
|
||||
clk->period = src->period;
|
||||
QLIST_INSERT_HEAD(&src->children, clk, sibling);
|
||||
clk->source = src;
|
||||
clock_propagate_period(clk, false);
|
||||
}
|
||||
|
||||
static void clock_disconnect(Clock *clk)
|
||||
{
|
||||
if (clk->source == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
trace_clock_disconnect(CLOCK_PATH(clk));
|
||||
|
||||
clk->source = NULL;
|
||||
QLIST_REMOVE(clk, sibling);
|
||||
}
|
||||
|
||||
static void clock_initfn(Object *obj)
|
||||
{
|
||||
Clock *clk = CLOCK(obj);
|
||||
|
||||
QLIST_INIT(&clk->children);
|
||||
}
|
||||
|
||||
static void clock_finalizefn(Object *obj)
|
||||
{
|
||||
Clock *clk = CLOCK(obj);
|
||||
Clock *child, *next;
|
||||
|
||||
/* clear our list of children */
|
||||
QLIST_FOREACH_SAFE(child, &clk->children, sibling, next) {
|
||||
clock_disconnect(child);
|
||||
}
|
||||
|
||||
/* remove us from source's children list */
|
||||
clock_disconnect(clk);
|
||||
|
||||
g_free(clk->canonical_path);
|
||||
}
|
||||
|
||||
static const TypeInfo clock_info = {
|
||||
.name = TYPE_CLOCK,
|
||||
.parent = TYPE_OBJECT,
|
||||
.instance_size = sizeof(Clock),
|
||||
.instance_init = clock_initfn,
|
||||
.instance_finalize = clock_finalizefn,
|
||||
};
|
||||
|
||||
static void clock_register_types(void)
|
||||
{
|
||||
type_register_static(&clock_info);
|
||||
}
|
||||
|
||||
type_init(clock_register_types)
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Device's clock input and output
|
||||
*
|
||||
* Copyright GreenSocs 2016-2020
|
||||
*
|
||||
* Authors:
|
||||
* Frederic Konrad
|
||||
* Damien Hedde
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "hw/qdev-clock.h"
|
||||
#include "hw/qdev-core.h"
|
||||
#include "qapi/error.h"
|
||||
|
||||
/*
|
||||
* qdev_init_clocklist:
|
||||
* Add a new clock in a device
|
||||
*/
|
||||
static NamedClockList *qdev_init_clocklist(DeviceState *dev, const char *name,
|
||||
bool output, Clock *clk)
|
||||
{
|
||||
NamedClockList *ncl;
|
||||
|
||||
/*
|
||||
* Clock must be added before realize() so that we can compute the
|
||||
* clock's canonical path during device_realize().
|
||||
*/
|
||||
assert(!dev->realized);
|
||||
|
||||
/*
|
||||
* The ncl structure is freed by qdev_finalize_clocklist() which will
|
||||
* be called during @dev's device_finalize().
|
||||
*/
|
||||
ncl = g_new0(NamedClockList, 1);
|
||||
ncl->name = g_strdup(name);
|
||||
ncl->output = output;
|
||||
ncl->alias = (clk != NULL);
|
||||
|
||||
/*
|
||||
* Trying to create a clock whose name clashes with some other
|
||||
* clock or property is a bug in the caller and we will abort().
|
||||
*/
|
||||
if (clk == NULL) {
|
||||
clk = CLOCK(object_new(TYPE_CLOCK));
|
||||
object_property_add_child(OBJECT(dev), name, OBJECT(clk), &error_abort);
|
||||
if (output) {
|
||||
/*
|
||||
* Remove object_new()'s initial reference.
|
||||
* Note that for inputs, the reference created by object_new()
|
||||
* will be deleted in qdev_finalize_clocklist().
|
||||
*/
|
||||
object_unref(OBJECT(clk));
|
||||
}
|
||||
} else {
|
||||
object_property_add_link(OBJECT(dev), name,
|
||||
object_get_typename(OBJECT(clk)),
|
||||
(Object **) &ncl->clock,
|
||||
NULL, OBJ_PROP_LINK_STRONG, &error_abort);
|
||||
}
|
||||
|
||||
ncl->clock = clk;
|
||||
|
||||
QLIST_INSERT_HEAD(&dev->clocks, ncl, node);
|
||||
return ncl;
|
||||
}
|
||||
|
||||
void qdev_finalize_clocklist(DeviceState *dev)
|
||||
{
|
||||
/* called by @dev's device_finalize() */
|
||||
NamedClockList *ncl, *ncl_next;
|
||||
|
||||
QLIST_FOREACH_SAFE(ncl, &dev->clocks, node, ncl_next) {
|
||||
QLIST_REMOVE(ncl, node);
|
||||
if (!ncl->output && !ncl->alias) {
|
||||
/*
|
||||
* We kept a reference on the input clock to ensure it lives up to
|
||||
* this point so we can safely remove the callback.
|
||||
* It avoids having a callback to a deleted object if ncl->clock
|
||||
* is still referenced somewhere else (eg: by a clock output).
|
||||
*/
|
||||
clock_clear_callback(ncl->clock);
|
||||
object_unref(OBJECT(ncl->clock));
|
||||
}
|
||||
g_free(ncl->name);
|
||||
g_free(ncl);
|
||||
}
|
||||
}
|
||||
|
||||
Clock *qdev_init_clock_out(DeviceState *dev, const char *name)
|
||||
{
|
||||
NamedClockList *ncl;
|
||||
|
||||
assert(name);
|
||||
|
||||
ncl = qdev_init_clocklist(dev, name, true, NULL);
|
||||
|
||||
return ncl->clock;
|
||||
}
|
||||
|
||||
Clock *qdev_init_clock_in(DeviceState *dev, const char *name,
|
||||
ClockCallback *callback, void *opaque)
|
||||
{
|
||||
NamedClockList *ncl;
|
||||
|
||||
assert(name);
|
||||
|
||||
ncl = qdev_init_clocklist(dev, name, false, NULL);
|
||||
|
||||
if (callback) {
|
||||
clock_set_callback(ncl->clock, callback, opaque);
|
||||
}
|
||||
return ncl->clock;
|
||||
}
|
||||
|
||||
void qdev_init_clocks(DeviceState *dev, const ClockPortInitArray clocks)
|
||||
{
|
||||
const struct ClockPortInitElem *elem;
|
||||
|
||||
for (elem = &clocks[0]; elem->name != NULL; elem++) {
|
||||
Clock **clkp;
|
||||
/* offset cannot be inside the DeviceState part */
|
||||
assert(elem->offset > sizeof(DeviceState));
|
||||
clkp = (Clock **)(((void *) dev) + elem->offset);
|
||||
if (elem->is_output) {
|
||||
*clkp = qdev_init_clock_out(dev, elem->name);
|
||||
} else {
|
||||
*clkp = qdev_init_clock_in(dev, elem->name, elem->callback, dev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static NamedClockList *qdev_get_clocklist(DeviceState *dev, const char *name)
|
||||
{
|
||||
NamedClockList *ncl;
|
||||
|
||||
QLIST_FOREACH(ncl, &dev->clocks, node) {
|
||||
if (strcmp(name, ncl->name) == 0) {
|
||||
return ncl;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Clock *qdev_get_clock_in(DeviceState *dev, const char *name)
|
||||
{
|
||||
NamedClockList *ncl;
|
||||
|
||||
assert(name);
|
||||
|
||||
ncl = qdev_get_clocklist(dev, name);
|
||||
assert(!ncl->output);
|
||||
|
||||
return ncl->clock;
|
||||
}
|
||||
|
||||
Clock *qdev_get_clock_out(DeviceState *dev, const char *name)
|
||||
{
|
||||
NamedClockList *ncl;
|
||||
|
||||
assert(name);
|
||||
|
||||
ncl = qdev_get_clocklist(dev, name);
|
||||
assert(ncl->output);
|
||||
|
||||
return ncl->clock;
|
||||
}
|
||||
|
||||
Clock *qdev_alias_clock(DeviceState *dev, const char *name,
|
||||
DeviceState *alias_dev, const char *alias_name)
|
||||
{
|
||||
NamedClockList *ncl;
|
||||
|
||||
assert(name && alias_name);
|
||||
|
||||
ncl = qdev_get_clocklist(dev, name);
|
||||
|
||||
qdev_init_clocklist(alias_dev, alias_name, ncl->output, ncl->clock);
|
||||
|
||||
return ncl->clock;
|
||||
}
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "hw/qdev-properties.h"
|
||||
#include "hw/boards.h"
|
||||
#include "hw/sysbus.h"
|
||||
#include "hw/qdev-clock.h"
|
||||
#include "migration/vmstate.h"
|
||||
#include "trace.h"
|
||||
|
||||
@@ -855,6 +856,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
|
||||
DeviceClass *dc = DEVICE_GET_CLASS(dev);
|
||||
HotplugHandler *hotplug_ctrl;
|
||||
BusState *bus;
|
||||
NamedClockList *ncl;
|
||||
Error *local_err = NULL;
|
||||
bool unattached_parent = false;
|
||||
static int unattached_count;
|
||||
@@ -902,6 +904,13 @@ 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(ncl, &dev->clocks, node) {
|
||||
if (ncl->alias) {
|
||||
continue;
|
||||
} else {
|
||||
clock_setup_canonical_path(ncl->clock);
|
||||
}
|
||||
}
|
||||
|
||||
if (qdev_get_vmsd(dev)) {
|
||||
if (vmstate_register_with_alias_id(VMSTATE_IF(dev),
|
||||
@@ -1025,6 +1034,7 @@ static void device_initfn(Object *obj)
|
||||
dev->allow_unplug_during_migration = false;
|
||||
|
||||
QLIST_INIT(&dev->gpios);
|
||||
QLIST_INIT(&dev->clocks);
|
||||
}
|
||||
|
||||
static void device_post_init(Object *obj)
|
||||
@@ -1054,6 +1064,8 @@ static void device_finalize(Object *obj)
|
||||
*/
|
||||
}
|
||||
|
||||
qdev_finalize_clocklist(dev);
|
||||
|
||||
/* Only send event if the device had been completely realized */
|
||||
if (dev->pending_deleted_event) {
|
||||
g_assert(dev->canonical_path);
|
||||
|
||||
@@ -27,3 +27,10 @@ resettable_phase_exit_begin(void *obj, const char *objtype, unsigned count, int
|
||||
resettable_phase_exit_exec(void *obj, const char *objtype, int has_method) "obj=%p(%s) method=%d"
|
||||
resettable_phase_exit_end(void *obj, const char *objtype, unsigned count) "obj=%p(%s) count=%d"
|
||||
resettable_transitional_function(void *obj, const char *objtype) "obj=%p(%s)"
|
||||
|
||||
# clock.c
|
||||
clock_set_source(const char *clk, const char *src) "'%s', src='%s'"
|
||||
clock_disconnect(const char *clk) "'%s'"
|
||||
clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', ns=%"PRIu64"->%"PRIu64
|
||||
clock_propagate(const char *clk) "'%s'"
|
||||
clock_update(const char *clk, const char *src, uint64_t val, int cb) "'%s', src='%s', ns=%"PRIu64", cb=%d"
|
||||
|
||||
+17
-8
@@ -299,19 +299,30 @@ static void zdma_put_regaddr64(XlnxZDMA *s, unsigned int basereg, uint64_t addr)
|
||||
s->regs[basereg + 1] = addr >> 32;
|
||||
}
|
||||
|
||||
static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr, void *buf)
|
||||
static void zdma_load_descriptor_reg(XlnxZDMA *s, unsigned int reg,
|
||||
XlnxZDMADescr *descr)
|
||||
{
|
||||
descr->addr = zdma_get_regaddr64(s, reg);
|
||||
descr->size = s->regs[reg + 2];
|
||||
descr->attr = s->regs[reg + 3];
|
||||
}
|
||||
|
||||
static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr,
|
||||
XlnxZDMADescr *descr)
|
||||
{
|
||||
/* ZDMA descriptors must be aligned to their own size. */
|
||||
if (addr % sizeof(XlnxZDMADescr)) {
|
||||
qemu_log_mask(LOG_GUEST_ERROR,
|
||||
"zdma: unaligned descriptor at %" PRIx64,
|
||||
addr);
|
||||
memset(buf, 0x0, sizeof(XlnxZDMADescr));
|
||||
memset(descr, 0x0, sizeof(XlnxZDMADescr));
|
||||
s->error = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
address_space_read(s->dma_as, addr, s->attr, buf, sizeof(XlnxZDMADescr));
|
||||
descr->addr = address_space_ldq_le(s->dma_as, addr, s->attr, NULL);
|
||||
descr->size = address_space_ldl_le(s->dma_as, addr + 8, s->attr, NULL);
|
||||
descr->attr = address_space_ldl_le(s->dma_as, addr + 12, s->attr, NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -321,8 +332,7 @@ static void zdma_load_src_descriptor(XlnxZDMA *s)
|
||||
unsigned int ptype = ARRAY_FIELD_EX32(s->regs, ZDMA_CH_CTRL0, POINT_TYPE);
|
||||
|
||||
if (ptype == PT_REG) {
|
||||
memcpy(&s->dsc_src, &s->regs[R_ZDMA_CH_SRC_DSCR_WORD0],
|
||||
sizeof(s->dsc_src));
|
||||
zdma_load_descriptor_reg(s, R_ZDMA_CH_SRC_DSCR_WORD0, &s->dsc_src);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -344,7 +354,7 @@ static void zdma_update_descr_addr(XlnxZDMA *s, bool type,
|
||||
} else {
|
||||
addr = zdma_get_regaddr64(s, basereg);
|
||||
addr += sizeof(s->dsc_dst);
|
||||
address_space_read(s->dma_as, addr, s->attr, (void *) &next, 8);
|
||||
next = address_space_ldq_le(s->dma_as, addr, s->attr, NULL);
|
||||
}
|
||||
|
||||
zdma_put_regaddr64(s, basereg, next);
|
||||
@@ -357,8 +367,7 @@ static void zdma_load_dst_descriptor(XlnxZDMA *s)
|
||||
bool dst_type;
|
||||
|
||||
if (ptype == PT_REG) {
|
||||
memcpy(&s->dsc_dst, &s->regs[R_ZDMA_CH_DST_DSCR_WORD0],
|
||||
sizeof(s->dsc_dst));
|
||||
zdma_load_descriptor_reg(s, R_ZDMA_CH_DST_DSCR_WORD0, &s->dsc_dst);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -658,13 +658,11 @@ static void kvm_arm_gicv3_get(GICv3State *s)
|
||||
|
||||
static void arm_gicv3_icc_reset(CPUARMState *env, const ARMCPRegInfo *ri)
|
||||
{
|
||||
ARMCPU *cpu;
|
||||
GICv3State *s;
|
||||
GICv3CPUState *c;
|
||||
|
||||
c = (GICv3CPUState *)env->gicv3state;
|
||||
s = c->gic;
|
||||
cpu = ARM_CPU(c->cpu);
|
||||
|
||||
c->icc_pmr_el1 = 0;
|
||||
c->icc_bpr[GICV3_G0] = GIC_MIN_BPR;
|
||||
@@ -681,7 +679,7 @@ static void arm_gicv3_icc_reset(CPUARMState *env, const ARMCPRegInfo *ri)
|
||||
|
||||
/* Initialize to actual HW supported configuration */
|
||||
kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS,
|
||||
KVM_VGIC_ATTR(ICC_CTLR_EL1, cpu->mp_affinity),
|
||||
KVM_VGIC_ATTR(ICC_CTLR_EL1, c->gicr_typer),
|
||||
&c->icc_ctlr_el1[GICV3_NS], false, &error_abort);
|
||||
|
||||
c->icc_ctlr_el1[GICV3_S] = c->icc_ctlr_el1[GICV3_NS];
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user