Add support for the Epson RX8900 RTC to the aspeed board
Subsystems (2)
v3 cover Add support for the Epson RX8900 RTC to the aspeed board
From: Alastair D'Silva <[email protected]>
This patch series adds support for the Epson RX8900 RTC to the Aspeed board.
The tests use the existing imx25 infrastructure, and some minor changes have been made to uniquely identify the I2C buses.
A NULL check have been added to eliminate empty i2cslave init functions.
Support for named interrupts has been implemented in qtest to facilitate testing.
Changelog:
v3:
- Add a table to Aspeed for i2c devices
- Add range checks for time components
- Shorten trace messages
- Use qemu generated i2c bus names
- Address style comments from Alexey for rx8900 driver
- Fix long lines in qtest harness
- Remove trailing whitespace in hw/arm/pxa
- Remove stray headers from rx8900 driver
- Support low voltage detection in rx8900 driver
v2:
- Avoid using error_report
- Fix TIE behaviour
- Move temperature init out of reset, it should not change on a soft reset
- Fix IRQ in test failures
- Add a NULL check for i2c slave init callbacks, so that we no longer need to implement empty init functions.
- Refactor to use the existing qemu trace infrastructure
- Move the RX8900 definition into the aspeed machine init
- It it possible for check_update_interrupt_seconds in the rx8900 test to return 6, depending on the alignment with the wall clock.
- Support low voltage detection
Alastair D'Silva (7):
arm: Uniquely name imx25 I2C buses.
hw/arm: remove trailing whitespace
hw/i2c: Add a NULL check for i2c slave init callbacks
qtest: Support named interrupts
hw/timer: Add Epson RX8900 RTC support
tests: Test all implemented RX8900 functionality
arm: Add an RX8900 RTC to the ASpeed board
default-configs/arm-softmmu.mak | 1 + hw/arm/aspeed.c | 58 ++- hw/arm/imx25_pdk.c | 4 +- hw/arm/pxa2xx.c | 9 +- hw/arm/tosa.c | 7 - hw/arm/z2.c | 7 - hw/core/irq.c | 18 +- hw/i2c/core.c | 6 +- hw/i2c/imx_i2c.c | 2 +- hw/timer/Makefile.objs | 2 + hw/timer/ds1338.c | 6 - hw/timer/rx8900.c | 912 ++++++++++++++++++++++++++++++++++++++++ hw/timer/rx8900_regs.h | 141 +++++++ hw/timer/trace-events | 31 ++ include/hw/irq.h | 13 +- qtest.c | 102 +++-- tests/Makefile.include | 2 + tests/libqtest.c | 88 +++- tests/libqtest.h | 59 +++ tests/rx8900-test.c | 882 ++++++++++++++++++++++++++++++++++++++ 20 files changed, 2276 insertions(+), 74 deletions(-) create mode 100644 hw/timer/rx8900.c create mode 100644 hw/timer/rx8900_regs.h create mode 100644 tests/rx8900-test.c
Signature · 1 line
2.9.3
PATCH v3 1/7 arm: Uniquely name imx25 I2C buses.
From: Alastair D'Silva <[email protected]>
The imx25 chip provides 3 i2c buses, but they have all been named "i2c", which makes it difficult to predict which bus a device will be connected to when specified on the command line.
This patch addresses the issue by naming the buses uniquely:
i2c-bus.0 i2c-bus.1 i2c-bus.2
--- hw/arm/imx25_pdk.c | 4 +--- hw/i2c/imx_i2c.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-)
hw/arm/imx25_pdk.c +1 -3
@@ -138,9 +138,7 @@ static void imx25_pdk_init(MachineState *machine)* We add it here (only on qtest usage) to be able to do a bit * of simple qtest. See "make check" for details. */ -i2c_create_slave ((I2CBus *)qdev_get_child_bus (DEVICE (&s->soc.i2c[0 ]), -"i2c" ), -"ds1338" ,0x68 ); +i2c_create_slave (s->soc.i2c[0 ].bus,"ds1338" ,0x68 ); } }
hw/i2c/imx_i2c.c +1 -1
@@ -310,7 +310,7 @@ static void imx_i2c_realize(DeviceState *dev, Error **errp) IMX_I2C_MEM_SIZE);sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->iomem);sysbus_init_irq (SYS_BUS_DEVICE (dev), &s->irq); - s->bus =i2c_init_bus (DEVICE (dev),"i2c" ); + s->bus =i2c_init_bus (DEVICE (dev),NULL ); }static void imx_i2c_class_init (ObjectClass *klass,void *data)
Signature · 1 line
2.9.3
Re: [Qemu-arm] [PATCH v3 1/7] arm: Uniquely name imx25 I2C buses.
Quoted 20 lines · Alastair D'Silva
From: Alastair D'Silva <[email protected]>
The imx25 chip provides 3 i2c buses, but they have all been named "i2c", which makes it difficult to predict which bus a device will be connected to when specified on the command line.
This patch addresses the issue by naming the buses uniquely:
i2c-bus.0 i2c-bus.1 i2c-bus.2Signed-off-by Alastair D'Silva <[email protected]>--- hw/arm/imx25_pdk.c | 4 +--- hw/i2c/imx_i2c.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-)hw/arm/imx25_pdk.c +0
-0
hw/arm/imx25_pdk.c static void imx25_pdk_init(MachineState *machine) · line 141
Quoted 7 lines
hw/arm/imx25_pdk.c +1
-3@@ -138,9 +138,7 @@ static void imx25_pdk_init(MachineState *machine)* We add it here (only on qtest usage) to be able to do a bit * of simple qtest. See "make check" for details. */ -i2c_create_slave ((I2CBus *)qdev_get_child_bus (DEVICE (&s->soc.i2c[0 ]), -"i2c" ), -"ds1338" ,0x68 ); +i2c_create_slave (s->soc.i2c[0 ].bus,"ds1338" ,0x68 );
This bit doesn't look right. The board level code shouldn't be poking around inside the IMXI2CState struct, as that is private to the device implementation. That's why we're calling qdev_get_child_bus().
hw/arm/imx25_pdk.c static void imx25_pdk_init(MachineState *machine) · line 143
Quoted 2 lines
hw/arm/imx25_pdk.c +0
-0} }
thanks
-- PMM
Re: [Qemu-arm] [PATCH v3 1/7] arm: Uniquely name imx25 I2C buses.
Quoted 25 lines · Peter Maydell
Quoted 24 lines · Alastair D'Silva
From: Alastair D'Silva <[email protected]>
The imx25 chip provides 3 i2c buses, but they have all been named "i2c", which makes it difficult to predict which bus a device will be connected to when specified on the command line.
This patch addresses the issue by naming the buses uniquely:
i2c-bus.0 i2c-bus.1 i2c-bus.2Signed-off-by Alastair D'Silva <[email protected]>--- hw/arm/imx25_pdk.c | 4 +--- hw/i2c/imx_i2c.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-)hw/arm/imx25_pdk.c +0
-1@@ -138,9 +138,7 @@ static void imx25_pdk_init(MachineState *machine)* We add it here (only on qtest usage) to be able to do a bit * of simple qtest. See "make check" for details. */ - i2c_create_slave((I2CBus *)qdev_get_child_bus(DEVICE(&s->soc.i2c[0]),
Quoted 8 lines
hw/arm/imx25_pdk.c static void imx25_pdk_init(MachineState *machine) · line 141
Quoted 3 lines
hw/arm/imx25_pdk.c +1
-2- "i2c"), - "ds1338", 0x68); +i2c_create_slave (s->soc.i2c[0 ].bus,"ds1338" ,0x68 );This bit doesn't look right. The board level code shouldn't be poking around inside the IMXI2CState struct, as that is private to the device implementation. That's why we're calling
qdev_get_child_bus().
That was my suggestion. Sorry about that.
May be, we could use "i2c.0", now that we have numbered the I2C bus names ?
Thanks,
C.
PATCH v3 2/7 hw/arm: remove trailing whitespace
In reply to Alastair D'SilvaFrom: Alastair D'Silva <[email protected]>
Remove trailing whitespace in hw/arm/pxa2xx.c
--- hw/arm/pxa2xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/pxa2xx.c +1 -1
@@ -2070,7 +2070,7 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space, }if (!revision) revision ="pxa270" ; - + s->cpu =cpu_arm_init (revision);if (s->cpu ==NULL ) {fprintf (stderr,"Unable to find CPU definition\n" );
Signature · 1 line
2.9.3
Peter Maydell
AppliedRe: [Qemu-devel] [PATCH v3 2/7] hw/arm: remove trailing whitespace
Quoted 14 lines · Alastair D'Silva
From: Alastair D'Silva <[email protected]>
Remove trailing whitespace in
hw/arm/pxa2xx.cSigned-off-by Alastair D'Silva <[email protected]>--- hw/arm/pxa2xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/arm/pxa2xx.c +0
-0
hw/arm/pxa2xx.c PXA2xxState *pxa270_init(MemoryRegion *address_space,
Quoted 9 lines
hw/arm/pxa2xx.c +1
-2@@ -2070,7 +2070,7 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space, }if (!revision) revision ="pxa270" ; - + s->cpu =cpu_arm_init (revision);if (s->cpu ==NULL ) {fprintf (stderr,"Unable to find CPU definition\n" ); --
Applied this patch to target-arm.next for 2.9.
thanks
-- PMM
PATCH v3 3/7 hw/i2c: Add a NULL check for i2c slave init callbacks
In reply to Alastair D'SilvaFrom: Alastair D'Silva <[email protected]>
Add a NULL check for i2c slave init callbacks, so that we no longer need to implement empty init functions.
--- hw/arm/pxa2xx.c | 7 ------- hw/arm/tosa.c | 7 ------- hw/arm/z2.c | 7 ------- hw/i2c/core.c | 6 +++++- hw/timer/ds1338.c | 6 ------ 5 files changed, 5 insertions(+), 28 deletions(-)
hw/arm/pxa2xx.c +0 -7
@@ -1449,17 +1449,10 @@ static const VMStateDescription vmstate_pxa2xx_i2c = { } }; -static int pxa2xx_i2c_slave_init (I2CSlave *i2c) -{ -/* Nothing to do. */ -return 0 ; -} -static void pxa2xx_i2c_slave_class_init (ObjectClass *klass,void *data) {I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); - k->init = pxa2xx_i2c_slave_init; k->event = pxa2xx_i2c_event; k->recv = pxa2xx_i2c_rx; k->send = pxa2xx_i2c_tx;
hw/arm/tosa.c +0 -7
@@ -202,12 +202,6 @@ static int tosa_dac_recv(I2CSlave *s)return -1 ; } -static int tosa_dac_init (I2CSlave *i2c) -{ -/* Nothing to do. */ -return 0 ; -} -static void tosa_tg_init (PXA2xxState *cpu) {I2CBus *bus =pxa2xx_i2c_bus (cpu->i2c[0 ]);
@@ -275,7 +269,6 @@ static void tosa_dac_class_init(ObjectClass *klass, void *data) {I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); - k->init = tosa_dac_init; k->event = tosa_dac_event; k->recv = tosa_dac_recv; k->send = tosa_dac_send;
hw/arm/z2.c +0 -7
@@ -263,12 +263,6 @@ static int aer915_recv(I2CSlave *slave)return retval; } -static int aer915_init (I2CSlave *i2c) -{ -/* Nothing to do. */ -return 0 ; -} -static VMStateDescription vmstate_aer915_state = { .name ="aer915" , .version_id =1 ,
@@ -285,7 +279,6 @@ static void aer915_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass);I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); - k->init = aer915_init; k->event = aer915_event; k->recv = aer915_recv; k->send = aer915_send;
hw/i2c/core.c +5 -1
@@ -260,7 +260,11 @@ static int i2c_slave_qdev_init(DeviceState *dev)I2CSlave *s =I2C_SLAVE (dev);I2CSlaveClass *sc =I2C_SLAVE_GET_CLASS (s); -return sc->init (s); +if (sc->init) { +return sc->init (s); + }else { +return 0 ; + } }DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr)
hw/timer/ds1338.c +0 -6
@@ -198,11 +198,6 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data)return 0 ; } -static int ds1338_init (I2CSlave *i2c) -{ -return 0 ; -} -static void ds1338_reset (DeviceState *dev) {DS1338State *s =DS1338 (dev);
@@ -220,7 +215,6 @@ static void ds1338_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass);I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); - k->init = ds1338_init; k->event = ds1338_event; k->recv = ds1338_recv; k->send = ds1338_send;
Signature · 1 line
2.9.3
Peter Maydell
AppliedRe: [Qemu-arm] [PATCH v3 3/7] hw/i2c: Add a NULL check for i2c slave init callbacks
Quoted 4 lines · Alastair D'Silva
From: Alastair D'Silva <[email protected]>
Add a NULL check for i2c slave init callbacks, so that we no longer need to implement empty init functions.
Quoted 9 lines
Signed-off-by Alastair D'Silva <[email protected]>--- hw/arm/pxa2xx.c | 7 ------- hw/arm/tosa.c | 7 ------- hw/arm/z2.c | 7 ------- hw/i2c/core.c | 6 +++++- hw/timer/ds1338.c | 6 ------ 5 files changed, 5 insertions(+), 28 deletions(-)
Applied this patch to target-arm.next for 2.9.
thanks
-- PMM
PATCH v3 4/7 qtest: Support named interrupts
In reply to Alastair D'SilvaFrom: Alastair D'Silva <[email protected]>
The QTest framework cannot work with named interrupts. This patch adds support for them, as well as the ability to manipulate them from within a test.
Read actions are via callbacks, which allows for pulsed interrupts to be read (the polled method used for the unnamed interrupts cannot read pulsed interrupts as the value is reverted before the test sees the changes).
--- hw/core/irq.c | 18 +++++----- include/hw/irq.h | 13 +++++-- qtest.c | 102 ++++++++++++++++++++++++++++++++++++++++++------------- tests/libqtest.c | 88 ++++++++++++++++++++++++++++++++++++++++++++--- tests/libqtest.h | 59 ++++++++++++++++++++++++++++++++ 5 files changed, 241 insertions(+), 39 deletions(-)
hw/core/irq.c +10 -8
@@ -134,15 +134,17 @@ qemu_irq *qemu_irq_proxy(qemu_irq **target, int n)return qemu_allocate_irqs (proxy_irq_handler, target, n); } -void qemu_irq_intercept_in (qemu_irq *gpio_in,qemu_irq_handler handler,int n) +qemu_irq qemu_irq_dup (qemu_irq in) { -int i; -qemu_irq *old_irqs =qemu_allocate_irqs (NULL ,NULL , n); -for (i =0 ; i < n; i++) { - *old_irqs[i] = *gpio_in[i]; - gpio_in[i]->handler = handler; - gpio_in[i]->opaque = &old_irqs[i]; - } +qemu_irq out =qemu_allocate_irq (in->handler, in->opaque, in->n); +return out; +} + +void qemu_irq_intercept_in (qemu_irq gpio_in,qemu_irq_handler handler, +void *opaque) +{ + gpio_in->handler = handler; + gpio_in->opaque = opaque; }static const TypeInfo irq_type_info = {
include/hw/irq.h +10 -3
@@ -58,8 +58,15 @@ qemu_irq qemu_irq_split(qemu_irq irq1, qemu_irq irq2);*/ qemu_irq *qemu_irq_proxy (qemu_irq **target,int n); -/* For internal use in qtest. Similar to qemu_irq_split, but operating -on an existing vector of qemu_irq. */ -void qemu_irq_intercept_in (qemu_irq *gpio_in,qemu_irq_handler handler,int n); +/** +* Duplicate an IRQ +* @param in the IRQ to deplicate +* @return a copy of the IRQ +*/ +qemu_irq qemu_irq_dup (qemu_irq in); + +/* For internal use in qtest. */ +void qemu_irq_intercept_in (qemu_irq gpio_in,qemu_irq_handler handler, +void *opaque);#endif
qtest.c +78 -24
169 lines not on this page · raw message
tests/libqtest.c +84 -4
150 lines not on this page · raw message
tests/libqtest.h +59 -0
71 lines not on this page · raw message
Signature · 1 line
2.9.3
Re: [Qemu-arm] [PATCH v3 4/7] qtest: Support named interrupts
Quoted 24 lines · Alastair D'Silva
From: Alastair D'Silva <[email protected]>
The QTest framework cannot work with named interrupts. This patch adds support for them, as well as the ability to manipulate them from within a test.
Read actions are via callbacks, which allows for pulsed interrupts to be read (the polled method used for the unnamed interrupts cannot read pulsed interrupts as the value is reverted before the test sees the changes).
Signed-off-by Alastair D'Silva <[email protected]>qtest.c +0
-1@@ -40,7 +40,6 @@ static DeviceState *irq_intercept_dev;static FILE *qtest_log_fp;static CharBackend qtest_chr;static GString *inbuf; -static int irq_levels[MAX_IRQ ];static qemu_timeval start_time;static bool qtest_opened;
qtest.c static bool qtest_opened; · line 162
Quoted 4 lines
qtest.c +1
-0@@ -160,10 +159,16 @@ static bool qtest_opened;* * IRQ raise NUM * IRQ lower NUM +* IRQ_NAMED NAME NUM LEVEL
I think we should be consistent about the protocol here:
unnamed IRQs get 'raise' and 'lower' messages, so we should do the same for named IRQs.
qtest.c static bool qtest_opened; · line 171
Quoted 9 lines
qtest.c +5
-0* * where NUM is an IRQ number. For the PC, interrupts can be intercepted * simply with "irq_intercept_in ioapic" (note that IRQ0 comes out with * NUM=0 even though it is remapped to GSI 2). +* +* > irq_set NAME NUM LEVEL +* < OK +* +* Set the named input IRQ to the level (0/1)
I think adding support for raising and lowering device IRQs should be a separate patch, as it's a different feature. (I'm also not sure we should need it -- devices will be wired into the system, and qtest is testing the whole system from the point of view of the CPU. The CPU can't arbitrarily reach in and assert a device's outgoing interrupt line, so I'm not sure the tests should be able to do it either.)
(Everything else below here is trivial fixes.)
Quoted 51 lines
qtest.c +21
-7*/ static int hex2nib (char ch)@@ -243,17 +248,31 @@ static void GCC_FMT_ATTR(2, 3) qtest_sendf(CharBackend *chr,va_end (ap); } +typedef struct qtest_irq { +qemu_irq old_irq; +char *name; +bool last_level; +}qtest_irq ; +static void qtest_irq_handler (void *opaque,int n,int level) { -qemu_irq old_irq = *(qemu_irq *)opaque; -qemu_set_irq (old_irq, level); +qtest_irq *data = (qtest_irq *)opaque; + level = !!level; + +qemu_set_irq (data->old_irq, level); -if (irq_levels[n] != level) { +if (level != data->last_level) {CharBackend *chr = &qtest_chr; - irq_levels[n] = level;qtest_send_prefix (chr); -qtest_sendf (chr,"IRQ %s %d\n" , - level ?"raise" :"lower" , n); + +if (data->name) { +qtest_sendf (chr,"IRQ_NAMED %s %d %d\n" , + data->name, n, level); + }else { +qtest_sendf (chr,"IRQ %s %d\n" , level ?"raise" :"lower" , n); + } + + data->last_level = level; } }@@ -289,7 +308,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)if (!dev) {qtest_send_prefix (chr);qtest_send (chr,"FAIL Unknown device\n" ); -return ; +return ; }if (irq_intercept_dev) {
qtest.c static void qtest_process_command(CharBackend *chr, gchar **words) · line 322
Quoted 6 lines
qtest.c +1
-1@@ -299,33 +318,73 @@ static void qtest_process_command(CharBackend *chr, gchar **words) }else {qtest_send (chr,"OK\n" ); } -return ; +return ; }
Fixing whitespace issues is generally best done in a separate patch.
tests/libqtest.c line 25
Quoted 10 lines
tests/libqtest.c +2
-0@@ -21,12 +21,16 @@#include <sys/wait.h> #include <sys/un.h> +#include <glib.h> +
osdep.h pulls in glib for you.
tests/libqtest.c line 30
Quoted 5 lines
tests/libqtest.c +1
-0#include "qapi/qmp/json-parser.h" #include "qapi/qmp/json-streamer.h" #include "qapi/qmp/qjson.h" +
Stray whitespace change.
Quoted 8 lines
tests/libqtest.c +1
-0#define MAX_IRQ 256#define SOCKET_TIMEOUT 50 +#define IRQ_KEY_LENGTH 64QTestState *global_qtest;
tests/libqtest.c redo: · line 414
Quoted 7 lines
tests/libqtest.c +4
-0@@ -346,6 +408,17 @@ redo:g_strfreev (words); } +/* Defer processing of IRQ actions until all communications have been handled, +* otherwise, interrupt handler that cause further communication can disrupt +* the communication stream +*/
Bad indent on this comment.
Quoted 20 lines
tests/libqtest.c +7
-0+for (action_index =0 ; action_index < action_count; action_index++) { +irq_action *action = actions[action_index]; + action->cb (action->opaque, action->name, action->n, + action_raise[action_index]); + action->level = action_raise[action_index]; + } +return words; }/**
+ *irq_attach:
+ * @name: the name of the gpio list containing the IRQ
+ * @irq: The IRQ to attach to
+ * @irq_cb: The callback to execute when the interrupt changes
+ * @opaque: opaque info to pass to the callback
+ *
+ * Attach a callback to an intecepted interrupt
+ */
tests/libqtest.c
Quoted 9 lines
tests/libqtest.c +9
-0+static inline void irq_attach (const char *name,int irq, +void (*irq_cb)(void *opaque,const char *name,int irq,bool level), +void *opaque) +{ +qtest_irq_attach (global_qtest, name, irq, irq_cb, opaque); +} + +/** +* qtest_irq_set
Comment doesn't match function name (and missing ':').
Quoted 18 lines
+ * Set an interrupt level
+ * @id: the device to inject interrupts for
+ * @gpiolist: the GPIO list containing the line to seh
+ * @n: the line to set within the list
+ * @level: the IRQ level
+ */tests/libqtest.c +8
-1+static inline void irq_set (const char *id,const char *gpiolist,int n, +bool level) +{ +qtest_irq_set (global_qtest, id, gpiolist, n, level); +} + + +/** * outb: * @addr: I/O port to write to. * @value: Value being written. --
Quoted 1 line
2.9.3
thanks
-- PMM
Re: [Qemu-arm] [PATCH v3 4/7] qtest: Support named interrupts
Quoted 24 lines · Peter Maydell
Quoted 22 lines · Alastair D'Silva
From: Alastair D'Silva <[email protected]>
The QTest framework cannot work with named interrupts. This patch adds support for them, as well as the ability to manipulate them from within a test.
Read actions are via callbacks, which allows for pulsed interrupts to be read (the polled method used for the unnamed interrupts cannot read pulsed interrupts as the value is reverted before the test sees the changes).
Signed-off-by Alastair D'Silva <[email protected]>qtest.c +0
-1@@ -40,7 +40,6 @@ static DeviceState *irq_intercept_dev; static FILE *qtest_log_fp; static CharBackend qtest_chr; static GString *inbuf; -static int irq_levels[MAX_IRQ ]; static qemu_timeval start_time; static bool qtest_opened;
Quoted 10 lines
qtest.c static bool qtest_opened; · line 162
Quoted 5 lines
qtest.c +1
-0@@ -160,10 +159,16 @@ static bool qtest_opened; * * IRQ raise NUM * IRQ lower NUM + * IRQ_NAMED NAME NUM LEVELI think we should be consistent about the protocol here:
unnamed IRQs get 'raise' and 'lower' messages, so we should do the same for named IRQs.
Ok
Quoted 12 lines
Quoted 11 lines
qtest.c +0
-0* * where NUM is an IRQ number. For the PC, interrupts can beintercepted
* simply with "irq_intercept_inioapic" (note that IRQ0 comes out with
* NUM=0 even though it is remapped to GSI 2).
+ *
+ * >irq_setNAME NUM LEVEL
+ * < OK
+ *
+ * Set the named input IRQ to the level (0/1)
Quoted 9 lines
I think adding support for raising and lowering device IRQs should be a separate patch, as it's a different feature. (I'm also not sure we should need it -- devices will be wired into the system, and qtest is testing the whole system from the point of view of the CPU. The CPU can't arbitrarily reach in and assert a device's outgoing interrupt line, so I'm not sure the tests should be able to do it either.)
Unfortunately, from what I can see, the concepts of GPIO lines & IRQs are a bit mixed up in Qemu. The use case I have is that an input line to the chip (not an output) needs to be asserted during the test to change it's behaviour.
Quoted 54 lines
(Everything else below here is trivial fixes.)
Quoted 52 lines
*/
static int hex2nib(char ch)
qtest.c +20
-6@@ -243,17 +248,31 @@ static void GCC_FMT_ATTR(2, 3)qtest_sendf (CharBackend *chr, va_end(ap); } +typedef struct qtest_irq { + qemu_irq old_irq; + char *name; + bool last_level; +} qtest_irq; + static void qtest_irq_handler(void *opaque, int n, int level) { - qemu_irq old_irq = *(qemu_irq *)opaque; - qemu_set_irq(old_irq, level); + qtest_irq *data = (qtest_irq *)opaque; + level = !!level; + + qemu_set_irq(data->old_irq, level); - if (irq_levels[n] != level) { + if (level != data->last_level) { CharBackend *chr = &qtest_chr; - irq_levels[n] = level; qtest_send_prefix(chr); - qtest_sendf(chr, "IRQ %s %d\n", - level ? "raise" : "lower", n); + + if (data->name) { + qtest_sendf(chr, "IRQ_NAMED %s %d %d\n", + data->name, n, level); + } else { + qtest_sendf(chr, "IRQ %s %d\n", level ? "raise" :"lower" , n); + } + + data->last_level = level; }}
qtest.c +1
-1@@ -289,7 +308,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words) if (!dev) { qtest_send_prefix(chr); qtest_send(chr, "FAIL Unknown device\n"); - return; + return; }
Quoted 12 lines
qtest.c static void qtest_process_command(CharBackend · line 323
Quoted 9 lines
if (
irq_intercept_dev) {qtest.c +1
-1@@ -299,33 +318,73 @@ static void qtest_process_command(CharBackend *chr, gchar **words) } else { qtest_send(chr, "OK\n"); } - return; + return; }Fixing whitespace issues is generally best done in a separate patch.
Ok
Quoted 9 lines
Quoted 9 lines
tests/libqtest.c +0
-0@@ -21,12 +21,16 @@ #include <sys/wait.h> #include <sys/un.h>
Quoted 5 lines
tests/libqtest.c line 25
Quoted 2 lines
tests/libqtest.c +2
-0+#include <glib.h> +
osdep.hpulls in glib for you.
Ok
Quoted 7 lines
tests/libqtest.c line 30
Quoted 5 lines
tests/libqtest.c +1
-0#include "qapi/qmp/json-parser.h" #include "qapi/qmp/json-streamer.h" #include "qapi/qmp/qjson.h" +Stray whitespace change.
Ok
Quoted 12 lines
Quoted 12 lines
tests/libqtest.c +1
-0#define MAX_IRQ 256 #define SOCKET_TIMEOUT 50 +#define IRQ_KEY_LENGTH 64 QTestState *global_qtest;@@ -346,6 +408,17 @@ redo: g_strfreev(words); }
Quoted 8 lines
Quoted 6 lines
tests/libqtest.c +2
-0+/* Defer processing of IRQ actions until all communications have been handled, +* otherwise, interrupt handler that cause further communication can disrupt
+ * the communication stream
+ */Bad indent on this comment.
Ok
Quoted 25 lines
Quoted 25 lines
+ for (
action_index= 0;action_index<action_count; action_index++) {
+ irq_action *action = actions[action_index]; + action->cb(action->opaque,action->name,action->n, + action_raise[action_index]);
+ action->level = action_raise[action_index]; + }
+
return words;
}/**
+ *irq_attach:
+ * @name: the name of the gpio list containing the IRQ
+ * @irq: The IRQ to attach to
+ * @irq_cb: The callback to execute when the interrupt changes
+ * @opaque: opaque info to pass to the callback
+ *
+ * Attach a callback to an intecepted interrupt
+ */
+static inline void irq_attach(const char *name, int irq, + void (*irq_cb)(void *opaque, const char *name, int irq, bool level),
+ void *opaque)
Quoted 9 lines
tests/libqtest.c
Quoted 6 lines
tests/libqtest.c +6
-0+{ + qtest_irq_attach(global_qtest, name, irq, irq_cb, opaque); +} + +/** +* qtest_irq_set Comment doesn't match function name (and missing ':').
Ok
Quoted 24 lines
Quoted 15 lines
+ * Set an interrupt level
+ * @id: the device to inject interrupts for
+ * @gpiolist: the GPIO list containing the line to seh
+ * @n: the line to set within the list
+ * @level: the IRQ level
+ */
+static inline void irq_set(const char *id, const char *gpiolist, int n,
+ bool level)tests/libqtest.c +6
-0+{ + qtest_irq_set(global_qtest, id, gpiolist, n, level); +} + + +/** Quoted 5 lines
* outb:
* @addr: I/O port to write to.
* @value: Value being written.
--
2.9.3thanks
-- PMM
Signature · 4 lines
Alastair D'Silva Open Source Developer Linux Technology Centre, IBM Australia mob: 0423 762 819
PATCH v3 5/7 hw/timer: Add Epson RX8900 RTC support
In reply to Alastair D'SilvaFrom: Alastair D'Silva <[email protected]>
This patch adds support for the Epson RX8900 I2C RTC.
The following chip features are implemented:
- RTC (wallclock based, ptimer 10x oversampling to pick up wallclock transitions)
- Time update interrupt (per second/minute, wallclock based)
- Alarms (wallclock based)
- Temperature (set via a property)
- Countdown timer (emulated clock via ptimer)
- FOUT via GPIO (emulated clock via ptimer)
The following chip features are unimplemented:
- Low voltage detection
- i2c timeout
The implementation exports the following named GPIOs:
rx8900-interrupt-out
rx8900-fout-enable
rx8900-fout
--- default-configs/arm-softmmu.mak | 1 + hw/i2c/core.c | 4 +- hw/timer/Makefile.objs | 2 + hw/timer/rx8900.c | 912 ++++++++++++++++++++++++++++++++++++++++ hw/timer/rx8900_regs.h | 141 +++++++ hw/timer/trace-events | 31 ++ 6 files changed, 1089 insertions(+), 2 deletions(-) create mode 100644 hw/timer/rx8900.c create mode 100644 hw/timer/rx8900_regs.h
default-configs/arm-softmmu.mak +1 -0
@@ -29,6 +29,7 @@ CONFIG_SMC91C111=y CONFIG_ALLWINNER_EMAC=y CONFIG_IMX_FEC=y CONFIG_DS1338=y +CONFIG_RX8900=y CONFIG_PFLASH_CFI01=y CONFIG_PFLASH_CFI02=y CONFIG_MICRODRIVE=y
hw/i2c/core.c +2 -2
@@ -262,9 +262,9 @@ static int i2c_slave_qdev_init(DeviceState *dev)if (sc->init) {return sc->init (s); - }else { -return 0 ; } + +return 0 ; }DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr)
hw/timer/Makefile.objs +2 -0
@@ -3,6 +3,7 @@ common-obj-$(CONFIG_ARM_MPTIMER) += arm_mptimer.o common-obj-$(CONFIG_A9_GTIMER) += a9gtimer.o common-obj-$(CONFIG_CADENCE) += cadence_ttc.o common-obj-$(CONFIG_DS1338) += ds1338.o +common-obj-$(CONFIG_RX8900) += rx8900.o common-obj-$(CONFIG_HPET) += hpet.o common-obj-$(CONFIG_I8254) += i8254_common.o i8254.o common-obj-$(CONFIG_M48T59) += m48t59.o
@@ -17,6 +18,7 @@ common-obj-$(CONFIG_IMX) += imx_epit.o common-obj-$(CONFIG_IMX) += imx_gpt.o common-obj-$(CONFIG_LM32) += lm32_timer.o common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o +common-obj-$(CONFIG_RX8900) += rx8900.o obj-$(CONFIG_EXYNOS4) += exynos4210_mct.o obj-$(CONFIG_EXYNOS4) += exynos4210_pwm.o
hw/timer/rx8900.c new file +912 -0
912 lines not on this page · raw message
hw/timer/rx8900_regs.h new file +141 -0
141 lines not on this page · raw message
hw/timer/trace-events +31 -0
@@ -49,3 +49,34 @@ aspeed_timer_ctrl_pulse_enable(uint8_t i, bool enable) "Timer %" PRIu8 ": %d" aspeed_timer_set_ctrl2(uint32_t value) "Value: 0x%" PRIx32 aspeed_timer_set_value(int timer, int reg, uint32_t value) "Timer %d register %d: 0x%" PRIx32 aspeed_timer_read(uint64_t offset, unsigned size, uint64_t value) "From 0x%" PRIx64 ": of size %u: 0x%" PRIx64 + +# hw/timer/rx8900.c +rx8900_capture_current_time(int hour, int minute, int second, int weekday, int mday, int month, int year, int raw_hours, int raw_minutes, int raw_seconds, int raw_weekday, int raw_day, int raw_month, int raw_year) "Update current time to %02d:%02d:%02d %d %d/%d/%d (0x%02x%02x%02x%02x%02x%02x%02x)" +rx8900_regptr_update(uint32_t ptr) "Operating on register 0x%02x" +rx8900_regptr_overflow(void) "Register pointer has overflowed, wrapping to 0" +rx8900_event_weekday(int weekday, int weekmask, int weekday_offset) "Set weekday to %d (0x%02x), wday_offset=%d" +rx8900_read_register(int address, int val) "Read register 0x%x = 0x%x" +rx8900_set_fout(int hz) "Setting fout to %dHz" +rx8900_set_countdown_timer(int hz) "Setting countdown timer to %d Hz" +rx8900_set_countdown_timer_per_minute(void) "Setting countdown timer to per minute updates" +rx8900_enable_update_timer(void) "" +rx8900_enable_alarm(void) "" +rx8900_trigger_alarm(void) "" +rx8900_tick(void) "" +rx8900_fire_interrupt(void) "" +rx8900_disable_timer(void) "" +rx8900_enable_timer(void) "" +rx8900_disable_fout(void) "" +rx8900_enable_fout(void) "" +rx8900_fout_toggle(void) "" +rx8900_disable_countdown_timer(void) "" +rx8900_enable_countdown_timer(void) "" +rx8900_countdown_tick(int count) "Countdown tick, count=%d" +rx8900_countdown_elapsed(void) "" +rx8900_i2c_data_receive(uint8_t data) "Received I2C data 0x%02x" +rx8900_set_register(uint32_t addr, uint8_t data) "Set data 0x%02x=0x%02x" +rx8900_get_temperature(uint8_t raw, double val) "0x%x = %f°C" +rx8900_set_temperature(uint8_t raw, double val) "0x%x = %f°C" +rx8900_reset(void) "" +rx8900_pin_name(const char *type, const char *name) "'%s' pin is '%s'" +rx8900_set_voltage(double voltage) "Device voltage set to %f"
Signature · 1 line
2.9.3
Re: [Qemu-arm] [PATCH v3 5/7] hw/timer: Add Epson RX8900 RTC support
Quoted 52 lines · Alastair D'Silva
From: Alastair D'Silva <[email protected]>
This patch adds support for the Epson RX8900 I2C RTC.
The following chip features are implemented:
- RTC (wallclock based, ptimer 10x oversampling to pick up wallclock transitions)
- Time update interrupt (per second/minute, wallclock based)
- Alarms (wallclock based)
- Temperature (set via a property)
- Countdown timer (emulated clock via ptimer)
- FOUT via GPIO (emulated clock via ptimer)The following chip features are unimplemented:
- Low voltage detection
- i2c timeoutThe implementation exports the following named GPIOs:
rx8900-interrupt-out
rx8900-fout-enable
rx8900-foutSigned-off-by Alastair D'Silva <[email protected]>Signed-off-by Chris Smart <[email protected]>--- default-configs/arm-softmmu.mak | 1 + hw/i2c/core.c | 4 +- hw/timer/Makefile.objs | 2 + hw/timer/rx8900.c | 912 ++++++++++++++++++++++++++++++++++++++++ hw/timer/rx8900_regs.h | 141 +++++++ hw/timer/trace-events | 31 ++ 6 files changed, 1089 insertions(+), 2 deletions(-) create mode 100644 hw/timer/rx8900.c create mode 100644 hw/timer/rx8900_regs.hdefault-configs/arm-softmmu.mak +1
-0@@ -29,6 +29,7 @@ CONFIG_SMC91C111=y CONFIG_ALLWINNER_EMAC=y CONFIG_IMX_FEC=y CONFIG_DS1338=y +CONFIG_RX8900=y CONFIG_PFLASH_CFI01=y CONFIG_PFLASH_CFI02=y CONFIG_MICRODRIVE=yhw/i2c/core.c +0
-0
hw/i2c/core.c static int i2c_slave_qdev_init(DeviceState *dev) · line 269
Quoted 10 lines
hw/i2c/core.c +2
-2@@ -262,9 +262,9 @@ static int i2c_slave_qdev_init(DeviceState *dev)if (sc->init) {return sc->init (s); - }else { -return 0 ; } + +return 0 ; }
This change shouldn't be in this patch.
Quoted 14 lines
hw/i2c/core.c +0
-0DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr)hw/timer/Makefile.objs +1
-0@@ -3,6 +3,7 @@ common-obj-$(CONFIG_ARM_MPTIMER) += arm_mptimer.o common-obj-$(CONFIG_A9_GTIMER) += a9gtimer.o common-obj-$(CONFIG_CADENCE) += cadence_ttc.o common-obj-$(CONFIG_DS1338) += ds1338.o +common-obj-$(CONFIG_RX8900) += rx8900.o common-obj-$(CONFIG_HPET) += hpet.o common-obj-$(CONFIG_I8254) += i8254_common.o i8254.o common-obj-$(CONFIG_M48T59) += m48t59.o
hw/timer/Makefile.objs common-obj-$(CONFIG_IMX) += imx_epit.o
Quoted 10 lines
hw/timer/Makefile.objs +3
-0@@ -17,6 +18,7 @@ common-obj-$(CONFIG_IMX) += imx_epit.o common-obj-$(CONFIG_IMX) += imx_gpt.o common-obj-$(CONFIG_LM32) += lm32_timer.o common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o +common-obj-$(CONFIG_RX8900) += rx8900.o obj-$(CONFIG_EXYNOS4) += exynos4210_mct.o obj-$(CONFIG_EXYNOS4) += exynos4210_pwm.o +/** + * Get the device temperature in Celcius as a property
It's spelt "Celsius" -- please fix through the whole file.
hw/timer/Makefile.objs
Quoted 11 lines
+ * @param obj the device
+ * @param v
+ * @param name the property name
+ * @param opaque
+ * @param errp an error object to populate on failure
+ */hw/timer/Makefile.objs +5
-0+static void rx8900_get_temperature(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + RX8900State *s = RX8900(obj); + double value = (s->nvram[TEMPERATURE] * 2.0f - 187.1f) / 3.218f;
Why use 'double' for the variable when you're doing all your arithmetic at 'float' precision because of those 'f' suffixes? Unless there's a good reason I'd suggest dropping the 'f's and just doing all the arithmetic at double precision.
hw/timer/Makefile.objs
Quoted 13 lines
hw/timer/Makefile.objs +13
-0+static void rx8900_set_temperature(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + RX8900State *s = RX8900(obj); + Error *local_err = NULL; + double temp; /* degrees Celcius */ + visit_type_number(v, name, &temp, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + if (temp >= 100 || temp < -58) { + error_setg(errp, "value %f°C is out of range", temp);
Not sure that UTF-8 characters directly in error strings is a great idea. I'd stick to ASCII.
Quoted 98 lines
hw/timer/Makefile.objs +98
-0+ return; + } + + s->nvram[TEMPERATURE] = encode_temperature(temp); + + trace_rx8900_set_temperature(s->nvram[TEMPERATURE], temp); +} + +/** + * Get the device supply voltage as a property + * @param obj the device + * @param v + * @param name the property name + * @param opaque + * @param errp an error object to populate on failure + */ +static void rx8900_get_voltage(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + RX8900State *s = RX8900(obj); + + visit_type_number(v, name, &s->supply_voltage, errp); +} + +/** + * Set the device supply voltage as a property + * @param obj the device + * @param v + * @param name the property name + * @param opaque + * @param errp an error object to populate on failure + */ +static void rx8900_set_voltage(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + RX8900State *s = RX8900(obj); + Error *local_err = NULL; + double temp; + visit_type_number(v, name, &temp, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + s->supply_voltage = temp; + trace_rx8900_set_voltage(s->supply_voltage); + + check_voltage(s); +} + + +/** + * Configure device properties + * @param obj the device + */ +static void rx8900_initfn(Object *obj) +{ + object_property_add(obj, "temperature", "number", + rx8900_get_temperature, + rx8900_set_temperature, NULL, NULL, NULL); + + object_property_add(obj, "voltage", "number", + rx8900_get_voltage, + rx8900_set_voltage, NULL, NULL, NULL); +} + +/** + * Reset the device + * @param dev the RX8900 device to reset + */ +static void rx8900_reset(DeviceState *dev) +{ + RX8900State *s = RX8900(dev); + + trace_rx8900_reset(); + + /* The clock is running and synchronized with the host */ + s->offset = 0; + s->weekday = 7; /* Set to an invalid value */ + + s->nvram[EXTENSION_REGISTER] = EXT_MASK_TSEL1; + s->nvram[CONTROL_REGISTER] = CTRL_MASK_CSEL0; + s->nvram[FLAG_REGISTER] &= FLAG_MASK_VDET | FLAG_MASK_VLF; + + s->nvram_offset = 0; + + trace_rx8900_regptr_update(s->nvram_offset); + + s->addr_byte = false; +} + +/** + * Realize an RX8900 device instance + * Set up timers + * Configure GPIO lines + * @param dev the device instance to realize + * @param errp an error object to populate on error + */
hw/timer/Makefile.objs
Quoted 10 lines
hw/timer/Makefile.objs +10
-0+static void rx8900_realize(DeviceState *dev, Error **errp) +{ + RX8900State *s = RX8900(dev); + I2CSlave *i2c = I2C_SLAVE(dev); + QEMUBH *bh; + char name[64]; + + s->fout_state = false; + + memset(s->nvram, 0, RX8900_NVRAM_SIZE);
This looks like something you should be doing in reset.
hw/timer/Makefile.objs
Quoted 2 lines
hw/timer/Makefile.objs +2
-0+ /* Set the initial state to 25 degrees Celcius */ + s->nvram[TEMPERATURE] = encode_temperature(25.0f);
...and this.
Quoted 33 lines
hw/timer/Makefile.objs +33
-0+ + /* Set up timers */ + bh = qemu_bh_new(rx8900_timer_tick, s); + s->sec_timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT); + /* we trigger the timer at 10Hz and check for rollover, as the qemu + * clock does not advance in realtime in the test environment, + * leading to unstable test results + */ + ptimer_set_freq(s->sec_timer, 10); + ptimer_set_limit(s->sec_timer, 1, 1); + + bh = qemu_bh_new(rx8900_fout_tick, s); + s->fout_timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT); + /* frequency doubled to generate 50% duty cycle square wave */ + ptimer_set_freq(s->fout_timer, 32768 * 2); + ptimer_set_limit(s->fout_timer, 1, 1); + + bh = qemu_bh_new(rx8900_countdown_tick, s); + s->countdown_timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT); + ptimer_set_freq(s->countdown_timer, COUNTDOWN_TIMER_FREQ); + ptimer_set_limit(s->countdown_timer, COUNTDOWN_TIMER_FREQ, 1); + + + /* set up GPIO */ + snprintf(name, sizeof(name), "rx8900-interrupt-out"); + qdev_init_gpio_out_named(&i2c->qdev, &s->interrupt_pin, name, 1); + trace_rx8900_pin_name("Interrupt", name); + + snprintf(name, sizeof(name), "rx8900-fout-enable"); + qdev_init_gpio_in_named(&i2c->qdev, rx8900_fout_enable_handler, name, 1); + trace_rx8900_pin_name("Fout-enable", name); + + snprintf(name, sizeof(name), "rx8900-fout");
hw/timer/Makefile.objs
Quoted 10 lines
hw/timer/Makefile.objs +9
-0+ qdev_init_gpio_out_named(&i2c->qdev, &s->fout_pin, name, 1); + trace_rx8900_pin_name("Fout", name); + + /* Set up default voltage */ + s->supply_voltage = 3.3f; + trace_rx8900_set_voltage(s->supply_voltage); +} +rx8900_get_temperature(uint8_t raw, double val) "0x%x = %f°C" +rx8900_set_temperature(uint8_t raw, double val) "0x%x = %f°C"
Stick to ASCII here too.
thanks
-- PMM
Re: [Qemu-arm] [PATCH v3 5/7] hw/timer: Add Epson RX8900 RTC support
Quoted 58 lines · Peter Maydell
Quoted 56 lines · Alastair D'Silva
From: Alastair D'Silva <[email protected]>
This patch adds support for the Epson RX8900 I2C RTC.
The following chip features are implemented:
- RTC (wallclock based, ptimer 10x oversampling to pick up wallclock transitions)
- Time update interrupt (per second/minute, wallclock based)
- Alarms (wallclock based)
- Temperature (set via a property)
- Countdown timer (emulated clock via ptimer)
- FOUT via GPIO (emulated clock via ptimer)The following chip features are unimplemented:
- Low voltage detection
- i2c timeoutThe implementation exports the following named GPIOs:
rx8900-interrupt-out
rx8900-fout-enable
rx8900-foutSigned-off-by Alastair D'Silva <[email protected]>Signed-off-by Chris Smart <[email protected]>---
default-configs/arm-softmmu.mak | 1 +
hw/i2c/core.c | 4 +-
hw/timer/Makefile.objs | 2 +
hw/timer/rx8900.c | 912
++++++++++++++++++++++++++++++++++++++++
hw/timer/rx8900_regs.h | 141 +++++++
hw/timer/trace-events | 31 ++6 files changed, 1089 insertions(+), 2 deletions(-)create mode 100644
hw/timer/rx8900.c
create mode 100644hw/timer/rx8900_regs.hdefault-configs/arm- renamed from default-configs/arm-softmmu.mak +0
-0softmmu.mak
index 6de3e16..adb600e 100644default-configs/arm-softmmu.mak +0
-0@@ -29,6 +29,7 @@ CONFIG_SMC91C111=yCONFIG_ALLWINNER_EMAC=y
CONFIG_IMX_FEC=y
CONFIG_DS1338=y
+CONFIG_RX8900=y
CONFIG_PFLASH_CFI01=y
CONFIG_PFLASH_CFI02=y
CONFIG_MICRODRIVE=yhw/i2c/core.c +0
-0@@ -262,9 +262,9 @@ static int i2c_slave_qdev_init(DeviceState *dev)
Quoted 11 lines
hw/i2c/core.c static int i2c_slave_qdev_init(DeviceState *dev) · line 269
Quoted 9 lines
hw/i2c/core.c +2
-2if (sc->init) { return sc->init(s); - } else { - return 0; } + + return 0; }This change shouldn't be in this patch.
Ok
Quoted 21 lines
Quoted 21 lines
DeviceState *i2c_create_slave(I2CBus *bus, const char *name,
uint8_taddr)hw/timer/Makefile.objs +0
-0@@ -3,6 +3,7 @@ common-obj-$(CONFIG_ARM_MPTIMER) += arm_mptimer.ocommon-obj-$(CONFIG_A9_GTIMER) += a9gtimer.o common-obj-$(CONFIG_CADENCE) += cadence_ttc.o common-obj-$(CONFIG_DS1338) += ds1338.o +common-obj-$(CONFIG_RX8900) += rx8900.o common-obj-$(CONFIG_HPET) += hpet.o common-obj-$(CONFIG_I8254) += i8254_common.o i8254.o common-obj-$(CONFIG_M48T59) += m48t59.o
hw/timer/Makefile.objs +0
-0@@ -17,6 +18,7 @@ common-obj-$(CONFIG_IMX) += imx_epit.ocommon-obj-$(CONFIG_IMX) += imx_gpt.o common-obj-$(CONFIG_LM32) += lm32_timer.o common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o +common-obj-$(CONFIG_RX8900) += rx8900.o
Quoted 7 lines
Quoted 4 lines
obj-$(CONFIG_EXYNOS4) += exynos4210_mct.o obj-$(CONFIG_EXYNOS4) += exynos4210_pwm.o +/**
+ * Get the device temperature in Celcius as a propertyIt's spelt "Celsius" -- please fix through the whole file.
Whoops, thanks for that :)
Quoted 10 lines
Quoted 10 lines
+ * @param obj the device
+ * @param v
+ * @param name the property name
+ * @param opaque
+ * @param errp an error object to populate on failure
+ */
+static void rx8900_get_temperature(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp) +{
Quoted 8 lines
Quoted 3 lines
+ RX8900State *s = RX8900(obj);
+ double value = (s->nvram[TEMPERATURE] * 2.0f - 187.1f) / 3.218f;Why use 'double' for the variable when you're doing all your arithmetic at 'float' precision because of those 'f' suffixes? Unless there's a good reason I'd suggest dropping the 'f's and just doing all the arithmetic at double precision.
Ok
Quoted 9 lines
Quoted 9 lines
+static void rx8900_set_temperature(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp) +{
+ RX8900State *s = RX8900(obj);
+ Error*local_err= NULL;
+ double temp; /* degrees Celcius */
+ visit_type_number(v, name, &temp,&local_err);
+ if (local_err) {
Quoted 8 lines
Quoted 5 lines
+ error_propagate(errp,
local_err);
+ return;
+ }
+ if (temp >= 100 || temp < -58) {
+ error_setg(errp, "value %f°C is out of range", temp);Not sure that UTF-8 characters directly in error strings is a great idea. I'd stick to ASCII.
It is valid 8 bit ASCII, but is code-page dependent, Ok, I'll remove it.
Quoted 113 lines
Quoted 100 lines
+ return;
+ }hw/timer/Makefile.objs +15
-0+ + s->nvram[TEMPERATURE] = encode_temperature(temp); + + trace_rx8900_set_temperature(s->nvram[TEMPERATURE], temp); +} + +/** + * Get the device supply voltage as a property + * @param obj the device + * @param v + * @param name the property name + * @param opaque + * @param errp an error object to populate on failure + */ +static void rx8900_get_voltage(Object *obj, Visitor *v, const char*name,
+ void *opaque, Error **errp)hw/timer/Makefile.objs +15
-0+{ + RX8900State *s = RX8900(obj); + + visit_type_number(v, name, &s->supply_voltage, errp); +} + +/** + * Set the device supply voltage as a property + * @param obj the device + * @param v + * @param name the property name + * @param opaque + * @param errp an error object to populate on failure + */ +static void rx8900_set_voltage(Object *obj, Visitor *v, const char*name,
+ void *opaque, Error **errp)hw/timer/Makefile.objs +64
-0+{ + RX8900State *s = RX8900(obj); + Error *local_err = NULL; + double temp; + visit_type_number(v, name, &temp, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + s->supply_voltage = temp; + trace_rx8900_set_voltage(s->supply_voltage); + + check_voltage(s); +} + + +/** + * Configure device properties + * @param obj the device + */ +static void rx8900_initfn(Object *obj) +{ + object_property_add(obj, "temperature", "number", + rx8900_get_temperature, + rx8900_set_temperature, NULL, NULL, NULL); + + object_property_add(obj, "voltage", "number", + rx8900_get_voltage, + rx8900_set_voltage, NULL, NULL, NULL); +} + +/** + * Reset the device + * @param dev the RX8900 device to reset + */ +static void rx8900_reset(DeviceState *dev) +{ + RX8900State *s = RX8900(dev); + + trace_rx8900_reset(); + + /* The clock is running and synchronized with the host */ + s->offset = 0; + s->weekday = 7; /* Set to an invalid value */ + + s->nvram[EXTENSION_REGISTER] = EXT_MASK_TSEL1; + s->nvram[CONTROL_REGISTER] = CTRL_MASK_CSEL0; + s->nvram[FLAG_REGISTER] &= FLAG_MASK_VDET | FLAG_MASK_VLF; + + s->nvram_offset = 0; + + trace_rx8900_regptr_update(s->nvram_offset); + + s->addr_byte = false; +} + +/** + * Realize an RX8900 device instance + * Set up timers + * Configure GPIO lines + * @param dev the device instance to realize + * @param errp an error object to populate on error + */hw/timer/Makefile.objs
Quoted 10 lines
hw/timer/Makefile.objs +10
-0+static void rx8900_realize(DeviceState *dev, Error **errp) +{ + RX8900State *s = RX8900(dev); + I2CSlave *i2c = I2C_SLAVE(dev); + QEMUBH *bh; + char name[64]; + + s->fout_state = false; + + memset(s->nvram, 0, RX8900_NVRAM_SIZE);This looks like something you should be doing in reset.
Quoted 5 lines
Quoted 2 lines
+ /* Set the initial state to 25 degrees Celcius */ + s->nvram[TEMPERATURE] =
encode_temperature(25.0f);...and this.
I reuse the reset code for the soft-reset, which prevents me from doing these operations there.
Quoted 39 lines
Quoted 39 lines
+
+ /* Set up timers */
+ bh =qemu_bh_new(rx8900_timer_tick, s);
+ s->sec_timer =ptimer_init(bh, PTIMER_POLICY_DEFAULT); + /* we trigger the timer at 10Hz and check for rollover, as the qemu
+ * clock does not advance in realtime in the test environment, + * leading to unstable test results
+ */
+ ptimer_set_freq(s->sec_timer, 10);
+ ptimer_set_limit(s->sec_timer, 1, 1);hw/timer/Makefile.objs +16
-0+ + bh = qemu_bh_new(rx8900_fout_tick, s); + s->fout_timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT); + /* frequency doubled to generate 50% duty cycle square wave */ + ptimer_set_freq(s->fout_timer, 32768 * 2); + ptimer_set_limit(s->fout_timer, 1, 1); + + bh = qemu_bh_new(rx8900_countdown_tick, s); + s->countdown_timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT); + ptimer_set_freq(s->countdown_timer, COUNTDOWN_TIMER_FREQ); + ptimer_set_limit(s->countdown_timer, COUNTDOWN_TIMER_FREQ, 1); + + + /* set up GPIO */ + snprintf(name, sizeof(name), "rx8900-interrupt-out"); + qdev_init_gpio_out_named(&i2c->qdev, &s->interrupt_pin, name,1);
+ trace_rx8900_pin_name("Interrupt", name); +
+ snprintf(name, sizeof(name), "rx8900-fout-enable"); + qdev_init_gpio_in_named(&i2c->qdev,rx8900_fout_enable_handler, name, 1);
+ trace_rx8900_pin_name("Fout-enable", name);hw/timer/Makefile.objs +5
-0+ + snprintf(name, sizeof(name), "rx8900-fout"); + qdev_init_gpio_out_named(&i2c->qdev, &s->fout_pin, name, 1); + trace_rx8900_pin_name("Fout", name); +
Quoted 9 lines
hw/timer/Makefile.objs
Quoted 6 lines
+ /* Set up default voltage */
+ s->supply_voltage = 3.3f;
+ trace_rx8900_set_voltage(s->supply_voltage);hw/timer/Makefile.objs +3
-0+} +rx8900_get_temperature(uint8_t raw, double val) "0x%x = %f°C" +rx8900_set_temperature(uint8_t raw, double val) "0x%x = %f°C"Stick to ASCII here too.
Ok
Quoted 3 lines
thanks
-- PMM
PATCH v3 6/7 tests: Test all implemented RX8900 functionality
In reply to Alastair D'SilvaFrom: Alastair D'Silva <[email protected]>
--- tests/Makefile.include | 2 + tests/rx8900-test.c | 882 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 884 insertions(+) create mode 100644 tests/rx8900-test.c
tests/Makefile.include +2 -0
@@ -300,6 +300,7 @@ check-qtest-sparc64-y = tests/endianness-test$(EXESUF) check-qtest-arm-y = tests/tmp105-test$(EXESUF) check-qtest-arm-y += tests/ds1338-test$(EXESUF) +check-qtest-arm-y += tests/rx8900-test$(EXESUF) check-qtest-arm-y += tests/m25p80-test$(EXESUF) gcov-files-arm-y += hw/misc/tmp105.c check-qtest-arm-y += tests/virtio-blk-test$(EXESUF)
@@ -637,6 +638,7 @@ tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \ tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj-y) tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y) +tests/rx8900-test$(EXESUF): tests/rx8900-test.o $(libqos-imx-obj-y) tests/m25p80-test$(EXESUF): tests/m25p80-test.o tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) tests/q35-test$(EXESUF): tests/q35-test.o $(libqos-pc-obj-y)
tests/rx8900-test.c new file +882 -0
882 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH v3 7/7 arm: Add an RX8900 RTC to the ASpeed board
In reply to Alastair D'SilvaFrom: Alastair D'Silva <[email protected]>
Connect an RX8900 RTC to i2c12 of the AST2500 SOC at address 0x32
--- hw/arm/aspeed.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-)
hw/arm/aspeed.c +56 -2
@@ -26,6 +26,20 @@ static struct arm_boot_info aspeed_board_binfo = { .nb_cpus = 1, }; +typedef struct IRQConfig { +const char *name; +int irq; +int nvic_irq; +}IRQConfig ; + +typedef struct AspeedI2CDevice { +const char *type; +uint8_t address; +int bus; +/* device_inputs not yet implemented */ +const IRQConfig *device_outputs; +}AspeedI2CDevice ; + typedef struct AspeedBoardState { AspeedSoCState soc; MemoryRegion ram;
@@ -34,6 +48,7 @@ typedef struct AspeedBoardState {typedef struct AspeedBoardConfig {const char *soc_name;uint32_t hw_strap1; +const AspeedI2CDevice *i2c_devices; }AspeedBoardConfig ;enum {
@@ -64,9 +79,25 @@ enum { SCU_HW_STRAP_MAC0_RGMII) & \ ~SCU_HW_STRAP_2ND_BOOT_WDT) +static const IRQConfig rx8900_out[] = { + {"rx8900-interrupt-out" ,0 ,22 }, + {NULL } +}; + +static const AspeedI2CDevice ast2500_i2c_devices[] = { + {"rx8900" ,0x32 ,11 , rx8900_out}, + {NULL } +}; +static const AspeedBoardConfig aspeed_boards[] = { - [PALMETTO_BMC ] = {"ast2400-a0" ,PALMETTO_BMC_HW_STRAP1 }, - [AST2500_EVB ] = {"ast2500-a1" ,AST2500_EVB_HW_STRAP1 }, + [PALMETTO_BMC ] = { +"ast2400-a0" ,PALMETTO_BMC_HW_STRAP1 , +NULL + }, + [AST2500_EVB ] = { +"ast2500-a1" ,AST2500_EVB_HW_STRAP1 , + ast2500_i2c_devices + }, }; static void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype,
@@ -95,6 +126,27 @@ static void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype, } } +static void aspeed_i2c_init (AspeedBoardState *bmc, +const AspeedBoardConfig *cfg) +{ +AspeedSoCState *soc = &bmc->soc; +const AspeedI2CDevice *dev; +const IRQConfig *out; + +for (dev = cfg->i2c_devices; dev !=NULL && dev->type !=NULL ; dev++) { +I2CBus *i2c_bus =aspeed_i2c_get_bus ((DeviceState *)&soc->i2c, + dev->bus); +DeviceState *i2c_slave =i2c_create_slave (i2c_bus, dev->type, + dev->address); + +for (out = dev->device_outputs; out !=NULL && out->name !=NULL ; + out++) { +qdev_connect_gpio_out_named (i2c_slave, out->name, out->irq, +qdev_get_gpio_in (DEVICE (&soc->vic), out->nvic_irq)); + } + } +} +static void aspeed_board_init (MachineState *machine,const AspeedBoardConfig *cfg) {
@@ -137,6 +189,8 @@ static void aspeed_board_init(MachineState *machine, aspeed_board_binfo.ram_size = ram_size; aspeed_board_binfo.loader_start = sc->info->sdram_base; +aspeed_i2c_init (bmc, cfg); +arm_load_kernel (ARM_CPU (first_cpu), &aspeed_board_binfo); }
Signature · 1 line
2.9.3