i.MX: Add i.MX25 support through the PDK evaluation board
v11 cover i.MX: Add i.MX25 support through the PDK evaluation board
This series of patches add the support for the i.MX25 processor through the Freescale PDK evaluation board.
For now a limited set of devices is supported.
* GPT timers (from i.MX31)
* EPIT timers (from i.MX31)
* Serial ports (from i.MX31)
* Ethernet FEC port
* I2C controller
In the process the KZM platform was split into an i.MX31 SOC and a plateform part.
Also, I2C devices was added to the i.MX31 SOC.
This was tested by:
* booting a minimal linux system on the i.MX25 PDK platform
* booting the Xvisor hypervisor on the i.MX25 PDK platform
* booting a minimal linux system on the KZM platform
Jean-Christophe Dubois (19):
i.MX: Split UART emulator in a header file and a source file i.MX: Move serial initialization to init/realize of DeviceClass. i.MX:Fix Coding style for UART emulator.
i.MX: Split AVIC emulator in a header file and a source file i.MX: Fix Coding style for AVIC emulator.
i.MX: Split CCM emulator in a header file and a source file i.MX: Fix Coding style for CCM emulator
i.MX: Split EPIT emulator in a header file and a source file i.MX: Fix Coding style for EPIT emulator
i.MX: Split GPT emulator in a header file and a source file i.MX: Fix Coding style for GPT emulator
i.MX: Add SOC support for i.MX31
i.MX: KZM now uses the standalone i.MX31 SOC support i.MX: Add I2C controller emulator
i.MX: Add FEC Ethernet Emulator
i.MX: Add SOC support for i.MX25
i.MX: Add the i.MX25 PDK plateform
i.MX: Add qtest support for I2C device emulator. i.MX: Adding i2C devices to i.MX31 SOC
default-configs/arm-softmmu.mak | 6 + hw/arm/Makefile.objs | 4 +- hw/arm/fsl-imx25.c | 260 +++++++++++++++ hw/arm/fsl-imx31.c | 233 +++++++++++++ hw/arm/imx25_pdk.c | 162 +++++++++ hw/arm/kzm.c | 205 ++++++------ hw/char/imx_serial.c | 189 +++-------- hw/i2c/Makefile.objs | 1 + hw/i2c/imx_i2c.c | 339 +++++++++++++++++++ hw/intc/imx_avic.c | 56 +--- hw/misc/imx_ccm.c | 81 +---- hw/net/Makefile.objs | 1 + hw/net/imx_fec.c | 709 ++++++++++++++++++++++++++++++++++++++++ hw/timer/imx_epit.c | 75 +---- hw/timer/imx_gpt.c | 96 +----- include/hw/arm/fsl-imx25.h | 234 +++++++++++++ include/hw/arm/fsl-imx31.h | 110 +++++++ include/hw/arm/imx.h | 34 -- include/hw/char/imx_serial.h | 102 ++++++ include/hw/i2c/imx_i2c.h | 85 +++++ include/hw/intc/imx_avic.h | 55 ++++ include/hw/misc/imx_ccm.h | 91 ++++++ include/hw/net/imx_fec.h | 113 +++++++ include/hw/timer/imx_epit.h | 79 +++++ include/hw/timer/imx_gpt.h | 107 ++++++ tests/Makefile | 3 + tests/ds1338-test.c | 75 +++++ tests/libqos/i2c-imx.c | 209 ++++++++++++ tests/libqos/i2c.h | 3 + 29 files changed, 3157 insertions(+), 560 deletions(-) create mode 100644 hw/arm/fsl-imx25.c create mode 100644 hw/arm/fsl-imx31.c create mode 100644 hw/arm/imx25_pdk.c create mode 100644 hw/i2c/imx_i2c.c create mode 100644 hw/net/imx_fec.c create mode 100644 include/hw/arm/fsl-imx25.h create mode 100644 include/hw/arm/fsl-imx31.h delete mode 100644 include/hw/arm/imx.h create mode 100644 include/hw/char/imx_serial.h create mode 100644 include/hw/i2c/imx_i2c.h create mode 100644 include/hw/intc/imx_avic.h create mode 100644 include/hw/misc/imx_ccm.h create mode 100644 include/hw/net/imx_fec.h create mode 100644 include/hw/timer/imx_epit.h create mode 100644 include/hw/timer/imx_gpt.h create mode 100644 tests/ds1338-test.c create mode 100644 tests/libqos/i2c-imx.c
Signature · 1 line
2.1.4
PATCH v11 1/19 i.MX: Split UART emulator in a header file and a source file
---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* Splited the i.MX serial emulator into a header file and a source file
Changes since v8:
* no change
Changes since v9:
* Small style rework
Changes since v10:
* no change
hw/char/imx_serial.c | 82 +--------------------------------- include/hw/char/imx_serial.h | 102 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 80 deletions(-) create mode 100644 include/hw/char/imx_serial.h
hw/char/imx_serial.c +2 -80
@@ -4,6 +4,7 @@* Copyright (c) 2008 OKL * Originally Written by Hans Jiang * Copyright (c) 2011 NICTA Pty Ltd. +* Updated by Jean-Christophe Dubois <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory.
@@ -17,8 +18,7 @@* is a real serial device. */ -#include "hw/hw.h" -#include "hw/sysbus.h" +#include "hw/char/imx_serial.h" #include "sysemu/sysemu.h" #include "sysemu/char.h" #include "hw/arm/imx.h"
@@ -43,35 +43,6 @@ do { printf("imx_serial: " fmt , ##args); } while (0) # define IPRINTF(fmt, args...) do {} while (0)#endif -#define TYPE_IMX_SERIAL "imx-serial" -#define IMX_SERIAL (obj) OBJECT_CHECK(IMXSerialState, (obj), TYPE_IMX_SERIAL) - -typedef struct IMXSerialState { -SysBusDevice parent_obj; - -MemoryRegion iomem; -int32_t readbuff; - -uint32_t usr1; -uint32_t usr2; -uint32_t ucr1; -uint32_t ucr2; -uint32_t uts1; - -/* -* The registers below are implemented just so that the -* guest OS sees what it has written -*/ -uint32_t onems; -uint32_t ufcr; -uint32_t ubmr; -uint32_t ubrc; -uint32_t ucr3; - -qemu_irq irq; -CharDriverState *chr; -}IMXSerialState ; -static const VMStateDescription vmstate_imx_serial = { .name ="imx-serial" , .version_id =1 ,
@@ -91,55 +62,6 @@ static const VMStateDescription vmstate_imx_serial = { }, }; - -#define URXD_CHARRDY (1<<15)/* character read is valid */ -#define URXD_ERR (1<<14)/* Character has error */ -#define URXD_BRK (1<<11)/* Break received */ - -#define USR1_PARTYER (1<<15)/* Parity Error */ -#define USR1_RTSS (1<<14)/* RTS pin status */ -#define USR1_TRDY (1<<13)/* Tx ready */ -#define USR1_RTSD (1<<12)/* RTS delta: pin changed state */ -#define USR1_ESCF (1<<11)/* Escape sequence interrupt */ -#define USR1_FRAMERR (1<<10)/* Framing error */ -#define USR1_RRDY (1<<9)/* receiver ready */ -#define USR1_AGTIM (1<<8)/* Aging timer interrupt */ -#define USR1_DTRD (1<<7)/* DTR changed */ -#define USR1_RXDS (1<<6)/* Receiver is idle */ -#define USR1_AIRINT (1<<5)/* Aysnch IR interrupt */ -#define USR1_AWAKE (1<<4)/* Falling edge detected on RXd pin */ - -#define USR2_ADET (1<<15)/* Autobaud complete */ -#define USR2_TXFE (1<<14)/* Transmit FIFO empty */ -#define USR2_DTRF (1<<13)/* DTR/DSR transition */ -#define USR2_IDLE (1<<12)/* UART has been idle for too long */ -#define USR2_ACST (1<<11)/* Autobaud counter stopped */ -#define USR2_RIDELT (1<<10)/* Ring Indicator delta */ -#define USR2_RIIN (1<<9)/* Ring Indicator Input */ -#define USR2_IRINT (1<<8)/* Serial Infrared Interrupt */ -#define USR2_WAKE (1<<7)/* Start bit detected */ -#define USR2_DCDDELT (1<<6)/* Data Carrier Detect delta */ -#define USR2_DCDIN (1<<5)/* Data Carrier Detect Input */ -#define USR2_RTSF (1<<4)/* RTS transition */ -#define USR2_TXDC (1<<3)/* Transmission complete */ -#define USR2_BRCD (1<<2)/* Break condition detected */ -#define USR2_ORE (1<<1)/* Overrun error */ -#define USR2_RDR (1<<0)/* Receive data ready */ - -#define UCR1_TRDYEN (1<<13)/* Tx Ready Interrupt Enable */ -#define UCR1_RRDYEN (1<<9)/* Rx Ready Interrupt Enable */ -#define UCR1_TXMPTYEN (1<<6)/* Tx Empty Interrupt Enable */ -#define UCR1_UARTEN (1<<0)/* UART Enable */ - -#define UCR2_TXEN (1<<2)/* Transmitter enable */ -#define UCR2_RXEN (1<<1)/* Receiver enable */ -#define UCR2_SRST (1<<0)/* Reset complete */ - -#define UTS1_TXEMPTY (1<<6) -#define UTS1_RXEMPTY (1<<5) -#define UTS1_TXFULL (1<<4) -#define UTS1_RXFULL (1<<3) -static void imx_update (IMXSerialState *s) {uint32_t flags;
include/hw/char/imx_serial.h new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v11 2/19 i.MX: Move serial initialization to init/realize of DeviceClass.
In reply to Jean-Christophe DuboisMove constructor to DeviceClass methods
* imx_serial_init
* imx_serial_realize
imx32_serial_properties is renamed to imx_serial_properties.
Rework of Qdev construction helper function.
---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* not present on v7
Changes since v8:
* Remove Qdev construction helper
Changes since v9:
* Qdev construction helper is reintegrated and moved to a header file as an inline function.
Changes since v10:
* Qdev construction helper is put back in the main file.
* Qdev construction helper is reworked
* We don't use qemu_char_get_next_serial() anymore but the chardev property instead.
* Fix code to work with an unitialized (null) chardev property
hw/char/imx_serial.c | 98 +++++++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 44 deletions(-)
hw/char/imx_serial.c +54 -44
@@ -38,13 +38,13 @@ do { printf("imx_serial: " fmt , ##args); } while (0)//#define DEBUG_IMPLEMENTATION 1 #ifdef DEBUG_IMPLEMENTATION # define IPRINTF(fmt, args...) \ - do { fprintf(stderr, "imx_serial: " fmt, ##args); } while (0) + do { fprintf(stderr, "%s: " fmt, TYPE_IMX_SERIAL, ##args); } while (0)#else # define IPRINTF(fmt, args...) do {} while (0)#endif static const VMStateDescription vmstate_imx_serial = { - .name ="imx-serial" , + .name =TYPE_IMX_SERIAL , .version_id =1 , .minimum_version_id =1 , .fields = (VMStateField []) {
@@ -125,7 +125,9 @@ static uint64_t imx_serial_read(void *opaque, hwaddr offset, s->usr2 &= ~USR2_RDR ; s->uts1 |=UTS1_RXEMPTY ;imx_update (s); -qemu_chr_accept_input (s->chr); +if (s->chr) { +qemu_chr_accept_input (s->chr); + } }return c;
@@ -212,7 +214,9 @@ static void imx_serial_write(void *opaque, hwaddr offset, }if (value &UCR2_RXEN ) {if (!(s->ucr2 &UCR2_RXEN )) { -qemu_chr_accept_input (s->chr); +if (s->chr) { +qemu_chr_accept_input (s->chr); + } } } s->ucr2 = value &0xffff ;
@@ -299,23 +303,16 @@ static void imx_event(void *opaque, int event) } } -static const struct MemoryRegionOps imx_serial_ops = { .read = imx_serial_read, .write = imx_serial_write, .endianness =DEVICE_NATIVE_ENDIAN , }; -static int imx_serial_init (SysBusDevice *dev) +static void imx_serial_realize (DeviceState *dev,Error **errp) {IMXSerialState *s =IMX_SERIAL (dev); - -memory_region_init_io (&s->iomem,OBJECT (s), &imx_serial_ops, s, -"imx-serial" ,0x1000 ); -sysbus_init_mmio (dev, &s->iomem); -sysbus_init_irq (dev, &s->irq); -if (s->chr) {qemu_chr_add_handlers (s->chr, imx_can_receive, imx_receive, imx_event, s);
@@ -323,45 +320,58 @@ static int imx_serial_init(SysBusDevice *dev)DPRINTF ("No char dev for uart at 0x%lx\n" , (unsigned long )s->iomem.ram_addr); } +} + +static void imx_serial_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +IMXSerialState *s =IMX_SERIAL (obj); -return 0 ; +memory_region_init_io (&s->iomem, obj, &imx_serial_ops, s, +TYPE_IMX_SERIAL ,0x1000 ); +sysbus_init_mmio (sbd, &s->iomem); +sysbus_init_irq (sbd, &s->irq); }void imx_serial_create (int uart,const hwaddr addr,qemu_irq irq) {DeviceState *dev; -SysBusDevice *bus; -CharDriverState *chr; -const char chr_name[] ="serial" ; -char label[ARRAY_SIZE (chr_name) +1 ]; dev =qdev_create (NULL ,TYPE_IMX_SERIAL ); -if (uart >=MAX_SERIAL_PORTS ) { -hw_error ("Cannot assign uart %d: QEMU supports only %d ports\n" , - uart,MAX_SERIAL_PORTS ); - } - chr = serial_hds[uart]; -if (!chr) { -snprintf (label,ARRAY_SIZE (label),"%s%d" , chr_name, uart); - chr =qemu_chr_new (label,"null" ,NULL ); -if (!(chr)) { -hw_error ("Can't assign serial port to imx-uart%d.\n" , uart); +if (dev) { +SysBusDevice *bus; + +if (uart <MAX_SERIAL_PORTS ) { +CharDriverState *chr; + + chr = serial_hds[uart]; + +if (!chr) { +char label[20 ]; +snprintf (label,sizeof (label),"imx.uart%d" , uart); + chr =qemu_chr_new (label,"null" ,NULL ); +if (!(chr)) { +hw_error ("Can't assign serial port to %s.\n" , label); + } + } + +qdev_prop_set_chr (dev,"chardev" , chr); } - } -qdev_prop_set_chr (dev,"chardev" , chr); - bus =SYS_BUS_DEVICE (dev); -qdev_init_nofail (dev); -if (addr != (hwaddr)-1 ) { -sysbus_mmio_map (bus,0 , addr); - } -sysbus_connect_irq (bus,0 , irq); + bus =SYS_BUS_DEVICE (dev); -} +qdev_init_nofail (dev); + +if (addr != (hwaddr)-1 ) { +sysbus_mmio_map (bus,0 , addr); + } +sysbus_connect_irq (bus,0 , irq); + } +} -static Property imx32_serial_properties[] = { +static Property imx_serial_properties[] = {DEFINE_PROP_CHR ("chardev" , IMXSerialState, chr),DEFINE_PROP_END_OF_LIST (), };
@@ -369,21 +379,21 @@ static Property imx32_serial_properties[] = {static void imx_serial_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); -SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); - k->init = imx_serial_init; + dc->realize = imx_serial_realize; dc->vmsd = &vmstate_imx_serial; dc->reset = imx_serial_reset_at_boot;set_bit (DEVICE_CATEGORY_INPUT , dc->categories); dc->desc ="i.MX series UART" ; - dc->props = imx32_serial_properties; + dc->props = imx_serial_properties; }static const TypeInfo imx_serial_info = { - .name =TYPE_IMX_SERIAL , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (IMXSerialState), - .class_init = imx_serial_class_init, + .name =TYPE_IMX_SERIAL , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (IMXSerialState), + .instance_init = imx_serial_init, + .class_init = imx_serial_class_init, };static void imx_serial_register_types (void )
Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH v11 02/19] i.MX: Move serial initialization to init/realize of DeviceClass.
Quoted 81 lines · Jean-Christophe Dubois
Move constructor to DeviceClass methods
*imx_serial_init
*imx_serial_realize
imx32_serial_propertiesis renamed toimx_serial_properties.Rework of Qdev construction helper function.
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* not present on v1Changes since v2:
* not present on v2Changes since v3:
* not present on v3Changes since v4:
* not present on v4Changes since v5:
* not present on v5Changes since v6:
* not present on v6Changes since v7:
* not present on v7Changes since v8:
* Remove Qdev construction helperChanges since v9:
* Qdev construction helper is reintegrated and moved to a header file as an inline function.Changes since v10:
* Qdev construction helper is put back in the main file.
* Qdev construction helper is reworked
* We don't useqemu_char_get_next_serial()anymore but the chardev property instead.
* Fix code to work with an unitialized (null) chardev propertyhw/char/imx_serial.c | 98 +++++++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 44 deletions(-)hw/char/imx_serial.c +5
-3@@ -38,13 +38,13 @@ do { printf("imx_serial: " fmt , ##args); } while (0)//#define DEBUG_IMPLEMENTATION 1 #ifdef DEBUG_IMPLEMENTATION # define IPRINTF(fmt, args...) \ - do { fprintf(stderr, "imx_serial: " fmt, ##args); } while (0) + do { fprintf(stderr, "%s: " fmt, TYPE_IMX_SERIAL, ##args); } while (0)#else # define IPRINTF(fmt, args...) do {} while (0)#endif static const VMStateDescription vmstate_imx_serial = { - .name ="imx-serial" , + .name =TYPE_IMX_SERIAL , .version_id =1 , .minimum_version_id =1 , .fields = (VMStateField []) {@@ -125,7 +125,9 @@ static uint64_t imx_serial_read(void *opaque, hwaddr offset, s->usr2 &= ~USR2_RDR ; s->uts1 |=UTS1_RXEMPTY ;imx_update (s); -qemu_chr_accept_input (s->chr); +if (s->chr) { +qemu_chr_accept_input (s->chr); + } }return c;
hw/char/imx_serial.c static void imx_serial_write(void *opaque, hwaddr offset, · line 219
Quoted 7 lines
hw/char/imx_serial.c +3
-1@@ -212,7 +214,9 @@ static void imx_serial_write(void *opaque, hwaddr offset, }if (value &UCR2_RXEN ) {if (!(s->ucr2 &UCR2_RXEN )) { -qemu_chr_accept_input (s->chr); +if (s->chr) { +qemu_chr_accept_input (s->chr); + }
Looking around, imx serial is trying to be NULL safe except for these two cases. This and the hunk above is a full-on bugfix that should probably be split off and go to 2.4.
hw/char/imx_serial.c static void imx_event(void *opaque, int event) · line 302
Quoted 8 lines
hw/char/imx_serial.c +0
-1} } s->ucr2 = value &0xffff ;@@ -299,23 +303,16 @@ static void imx_event(void *opaque, int event) } } -
Out of scope style change.
Quoted 49 lines
hw/char/imx_serial.c +11
-13static const struct MemoryRegionOps imx_serial_ops = { .read = imx_serial_read, .write = imx_serial_write, .endianness =DEVICE_NATIVE_ENDIAN , }; -static int imx_serial_init (SysBusDevice *dev) +static void imx_serial_realize (DeviceState *dev,Error **errp) {IMXSerialState *s =IMX_SERIAL (dev); - -memory_region_init_io (&s->iomem,OBJECT (s), &imx_serial_ops, s, -"imx-serial" ,0x1000 ); -sysbus_init_mmio (dev, &s->iomem); -sysbus_init_irq (dev, &s->irq); -if (s->chr) {qemu_chr_add_handlers (s->chr, imx_can_receive, imx_receive, imx_event, s);@@ -323,45 +320,58 @@ static int imx_serial_init(SysBusDevice *dev)DPRINTF ("No char dev for uart at 0x%lx\n" , (unsigned long )s->iomem.ram_addr); } +} + +static void imx_serial_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +IMXSerialState *s =IMX_SERIAL (obj); -return 0 ; +memory_region_init_io (&s->iomem, obj, &imx_serial_ops, s, +TYPE_IMX_SERIAL ,0x1000 ); +sysbus_init_mmio (sbd, &s->iomem); +sysbus_init_irq (sbd, &s->irq); }void imx_serial_create (int uart,const hwaddr addr,qemu_irq irq) {DeviceState *dev; -SysBusDevice *bus; -CharDriverState *chr; -const char chr_name[] ="serial" ; -char label[ARRAY_SIZE (chr_name) +1 ]; dev =qdev_create (NULL ,TYPE_IMX_SERIAL ); -if (uart >=MAX_SERIAL_PORTS ) {
hw/char/imx_serial.c static int imx_serial_init(SysBusDevice *dev) · line 342
Quoted 10 lines
hw/char/imx_serial.c +1
-9-hw_error ("Cannot assign uart %d: QEMU supports only %d ports\n" , - uart,MAX_SERIAL_PORTS ); - } - chr = serial_hds[uart]; -if (!chr) { -snprintf (label,ARRAY_SIZE (label),"%s%d" , chr_name, uart); - chr =qemu_chr_new (label,"null" ,NULL ); -if (!(chr)) { -hw_error ("Can't assign serial port to imx-uart%d.\n" , uart); +if (dev) {
If dev is NULL I think you have big problems. If there is a valid reason why this can be NULL in a non-error case then it should just short return.
if (!dev) {
return;
}Quoted 29 lines
hw/char/imx_serial.c +18
-8+SysBusDevice *bus; + +if (uart <MAX_SERIAL_PORTS ) { +CharDriverState *chr; + + chr = serial_hds[uart]; + +if (!chr) { +char label[20 ]; +snprintf (label,sizeof (label),"imx.uart%d" , uart); + chr =qemu_chr_new (label,"null" ,NULL ); +if (!(chr)) { +hw_error ("Can't assign serial port to %s.\n" , label); + } + } + +qdev_prop_set_chr (dev,"chardev" , chr); } - } -qdev_prop_set_chr (dev,"chardev" , chr); - bus =SYS_BUS_DEVICE (dev); -qdev_init_nofail (dev); -if (addr != (hwaddr)-1 ) { -sysbus_mmio_map (bus,0 , addr); - } -sysbus_connect_irq (bus,0 , irq); + bus =SYS_BUS_DEVICE (dev);
hw/char/imx_serial.c static int imx_serial_init(SysBusDevice *dev) · line 372
Quoted 10 lines
hw/char/imx_serial.c +8
-1-} +qdev_init_nofail (dev); + +if (addr != (hwaddr)-1 ) { +sysbus_mmio_map (bus,0 , addr); + } +sysbus_connect_irq (bus,0 , irq); + } +}
So the change to _create looks correct, but it is still out of scope of the patch which by commit message is an init/realize conversion. Is there a reason the old _create implementation wont work with the new init/realize and allow a split?
Aside from the minor comments the code is good, but I would split this to 3 patches.
1: chr NULL guards, and send that as a single for 2.4. 2: realize and init conversion
3: _create rewrite.
Regards,
Peter
Quoted 39 lines
hw/char/imx_serial.c +8
-9-static Property imx32_serial_properties[] = { +static Property imx_serial_properties[] = {DEFINE_PROP_CHR ("chardev" , IMXSerialState, chr),DEFINE_PROP_END_OF_LIST (), };@@ -369,21 +379,21 @@ static Property imx32_serial_properties[] = {static void imx_serial_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); -SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); - k->init = imx_serial_init; + dc->realize = imx_serial_realize; dc->vmsd = &vmstate_imx_serial; dc->reset = imx_serial_reset_at_boot;set_bit (DEVICE_CATEGORY_INPUT , dc->categories); dc->desc ="i.MX series UART" ; - dc->props = imx32_serial_properties; + dc->props = imx_serial_properties; }static const TypeInfo imx_serial_info = { - .name =TYPE_IMX_SERIAL , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (IMXSerialState), - .class_init = imx_serial_class_init, + .name =TYPE_IMX_SERIAL , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (IMXSerialState), + .instance_init = imx_serial_init, + .class_init = imx_serial_class_init, };static void imx_serial_register_types (void ) --2.1.4
Re: [Qemu-devel] [PATCH v11 02/19] i.MX: Move serial initialization to init/realize of DeviceClass.
Quoted 82 lines · Peter Crosthwaite
Quoted 80 lines · Jean-Christophe Dubois
Move constructor to DeviceClass methods
*imx_serial_init
*imx_serial_realize
imx32_serial_propertiesis renamed toimx_serial_properties.Rework of Qdev construction helper function.
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* not present on v1Changes since v2:
* not present on v2Changes since v3:
* not present on v3Changes since v4:
* not present on v4Changes since v5:
* not present on v5Changes since v6:
* not present on v6Changes since v7:
* not present on v7Changes since v8:
* Remove Qdev construction helperChanges since v9:
* Qdev construction helper is reintegrated and moved to a header file as an inline function.Changes since v10:
* Qdev construction helper is put back in the main file.
* Qdev construction helper is reworked
* We don't useqemu_char_get_next_serial()anymore but the chardev property instead.
* Fix code to work with an unitialized (null) chardev propertyhw/char/imx_serial.c | 98 +++++++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 44 deletions(-)hw/char/imx_serial.c +5
-3@@ -38,13 +38,13 @@ do { printf("imx_serial: " fmt , ##args); } while (0)//#define DEBUG_IMPLEMENTATION 1 #ifdef DEBUG_IMPLEMENTATION # define IPRINTF(fmt, args...) \ - do { fprintf(stderr, "imx_serial: " fmt, ##args); } while (0) + do { fprintf(stderr, "%s: " fmt, TYPE_IMX_SERIAL, ##args); } while (0)#else # define IPRINTF(fmt, args...) do {} while (0)#endif static const VMStateDescription vmstate_imx_serial = { - .name ="imx-serial" , + .name =TYPE_IMX_SERIAL , .version_id =1 , .minimum_version_id =1 , .fields = (VMStateField []) {@@ -125,7 +125,9 @@ static uint64_t imx_serial_read(void *opaque, hwaddr offset, s->usr2 &= ~USR2_RDR ; s->uts1 |=UTS1_RXEMPTY ;imx_update (s); -qemu_chr_accept_input (s->chr); +if (s->chr) { +qemu_chr_accept_input (s->chr); + } }return c;
Quoted 11 lines
hw/char/imx_serial.c static void imx_serial_write(void *opaque, hwaddr offset, · line 219
Quoted 8 lines
hw/char/imx_serial.c +3
-1@@ -212,7 +214,9 @@ static void imx_serial_write(void *opaque, hwaddr offset, }if (value &UCR2_RXEN ) {if (!(s->ucr2 &UCR2_RXEN )) { -qemu_chr_accept_input (s->chr); +if (s->chr) { +qemu_chr_accept_input (s->chr); + }Looking around, imx serial is trying to be NULL safe except for these two cases. This and the hunk above is a full-on bugfix that should probably be split off and go to 2.4.
How do you provide a patch specifically for 2.4 (beside including it in my series)?
Quoted 59 lines
hw/char/imx_serial.c static void imx_event(void *opaque, int event) · line 302
Quoted 9 lines
hw/char/imx_serial.c +0
-1} } s->ucr2 = value &0xffff ;@@ -299,23 +303,16 @@ static void imx_event(void *opaque, int event) } } -Out of scope style change.
Quoted 48 lines
hw/char/imx_serial.c +11
-12static const struct MemoryRegionOps imx_serial_ops = { .read = imx_serial_read, .write = imx_serial_write, .endianness =DEVICE_NATIVE_ENDIAN , }; -static int imx_serial_init (SysBusDevice *dev) +static void imx_serial_realize (DeviceState *dev,Error **errp) {IMXSerialState *s =IMX_SERIAL (dev); - -memory_region_init_io (&s->iomem,OBJECT (s), &imx_serial_ops, s, -"imx-serial" ,0x1000 ); -sysbus_init_mmio (dev, &s->iomem); -sysbus_init_irq (dev, &s->irq); -if (s->chr) {qemu_chr_add_handlers (s->chr, imx_can_receive, imx_receive, imx_event, s);@@ -323,45 +320,58 @@ static int imx_serial_init(SysBusDevice *dev)DPRINTF ("No char dev for uart at 0x%lx\n" , (unsigned long )s->iomem.ram_addr); } +} + +static void imx_serial_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +IMXSerialState *s =IMX_SERIAL (obj); -return 0 ; +memory_region_init_io (&s->iomem, obj, &imx_serial_ops, s, +TYPE_IMX_SERIAL ,0x1000 ); +sysbus_init_mmio (sbd, &s->iomem); +sysbus_init_irq (sbd, &s->irq); }void imx_serial_create (int uart,const hwaddr addr,qemu_irq irq) {DeviceState *dev; -SysBusDevice *bus; -CharDriverState *chr; -const char chr_name[] ="serial" ; -char label[ARRAY_SIZE (chr_name) +1 ]; dev =qdev_create (NULL ,TYPE_IMX_SERIAL );
Quoted 14 lines
hw/char/imx_serial.c static int imx_serial_init(SysBusDevice *dev) · line 342
Quoted 11 lines
hw/char/imx_serial.c +1
-10-if (uart >=MAX_SERIAL_PORTS ) { -hw_error ("Cannot assign uart %d: QEMU supports only %d ports\n" , - uart,MAX_SERIAL_PORTS ); - } - chr = serial_hds[uart]; -if (!chr) { -snprintf (label,ARRAY_SIZE (label),"%s%d" , chr_name, uart); - chr =qemu_chr_new (label,"null" ,NULL ); -if (!(chr)) { -hw_error ("Can't assign serial port to imx-uart%d.\n" , uart); +if (dev) {If dev is NULL I think you have big problems. If there is a valid reason why this can be NULL in a non-error case then it should just short return.
It is obviously an error case (out of resource?) and therefore we should not ignore it (as it was previously the case). So I test for it here. Do you feel there should be another behavior (hw_error or something)?
Quoted 49 lines
if (!dev) { return; }Quoted 29 lines
hw/char/imx_serial.c +18
-8+SysBusDevice *bus; + +if (uart <MAX_SERIAL_PORTS ) { +CharDriverState *chr; + + chr = serial_hds[uart]; + +if (!chr) { +char label[20 ]; +snprintf (label,sizeof (label),"imx.uart%d" , uart); + chr =qemu_chr_new (label,"null" ,NULL ); +if (!(chr)) { +hw_error ("Can't assign serial port to %s.\n" , label); + } + } + +qdev_prop_set_chr (dev,"chardev" , chr); } - } -qdev_prop_set_chr (dev,"chardev" , chr); - bus =SYS_BUS_DEVICE (dev); -qdev_init_nofail (dev); -if (addr != (hwaddr)-1 ) { -sysbus_mmio_map (bus,0 , addr); - } -sysbus_connect_irq (bus,0 , irq); + bus =SYS_BUS_DEVICE (dev);hw/char/imx_serial.c static int imx_serial_init(SysBusDevice *dev) · line 372
Quoted 10 lines
hw/char/imx_serial.c +8
-1-} +qdev_init_nofail (dev); + +if (addr != (hwaddr)-1 ) { +sysbus_mmio_map (bus,0 , addr); + } +sysbus_connect_irq (bus,0 , irq); + } +}So the change to
_createlooks correct, but it is still out of scope of the patch which by commit message is an init/realize conversion. Is there a reason the old_createimplementation wont work with the new init/realize and allow a split?
Quoted 6 lines
Aside from the minor comments the code is good, but I would split this to 3 patches.
1: chr NULL guards, and send that as a single for 2.4. 2: realize and init conversion
3:_createrewrite.
OK, I'll do it even if I am spending quite some time on something that is going to be wiped out in a following patch.
Quoted 42 lines
Regards,
PeterQuoted 38 lines
hw/char/imx_serial.c +8
-9-static Property imx32_serial_properties[] = { +static Property imx_serial_properties[] = {DEFINE_PROP_CHR ("chardev" , IMXSerialState, chr),DEFINE_PROP_END_OF_LIST (), };@@ -369,21 +379,21 @@ static Property imx32_serial_properties[] = {static void imx_serial_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); -SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); - k->init = imx_serial_init; + dc->realize = imx_serial_realize; dc->vmsd = &vmstate_imx_serial; dc->reset = imx_serial_reset_at_boot;set_bit (DEVICE_CATEGORY_INPUT , dc->categories); dc->desc ="i.MX series UART" ; - dc->props = imx32_serial_properties; + dc->props = imx_serial_properties; }static const TypeInfo imx_serial_info = { - .name =TYPE_IMX_SERIAL , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (IMXSerialState), - .class_init = imx_serial_class_init, + .name =TYPE_IMX_SERIAL , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (IMXSerialState), + .instance_init = imx_serial_init, + .class_init = imx_serial_class_init, };static void imx_serial_register_types (void ) --2.1.4
Re: [Qemu-devel] [PATCH v11 02/19] i.MX: Move serial initialization to init/realize of DeviceClass.
Quoted 296 lines · Jean-Christophe DUBOIS
Quoted 88 lines · Peter Crosthwaite
Quoted 85 lines · Jean-Christophe Dubois
Move constructor to DeviceClass methods
*imx_serial_init
*imx_serial_realize
imx32_serial_propertiesis renamed toimx_serial_properties.Rework of Qdev construction helper function.
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* not present on v1Changes since v2:
* not present on v2Changes since v3:
* not present on v3Changes since v4:
* not present on v4Changes since v5:
* not present on v5Changes since v6:
* not present on v6Changes since v7:
* not present on v7Changes since v8:
* Remove Qdev construction helperChanges since v9:
* Qdev construction helper is reintegrated and moved to a header
file
as an inline function.Changes since v10:
* Qdev construction helper is put back in the main file.
* Qdev construction helper is reworked
* We don't useqemu_char_get_next_serial()anymore but the chardev property instead.
* Fix code to work with an unitialized (null) chardev propertyhw/char/imx_serial.c | 98 +++++++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 44 deletions(-)hw/char/imx_serial.c +2
-2@@ -38,13 +38,13 @@ do { printf("imx_serial: " fmt , ##args); } while (0)//#define DEBUG_IMPLEMENTATION 1 #ifdef DEBUG_IMPLEMENTATION # define IPRINTF(fmt, args...) \ - do { fprintf(stderr, "imx_serial: " fmt, ##args); } while (0) + do { fprintf(stderr, "%s: " fmt, TYPE_IMX_SERIAL, ##args); } while (0)#else # define IPRINTF(fmt, args...) do {} while (0)#endif static const VMStateDescription vmstate_imx_serial = { - .name ="imx-serial" , + .name =TYPE_IMX_SERIAL , .version_id =1 , .minimum_version_id =1 ,.fields = (VMStateField[]) {hw/char/imx_serial.c +3
-1@@ -125,7 +125,9 @@ static uint64_t imx_serial_read(void *opaque, hwaddr offset, s->usr2 &= ~USR2_RDR ; s->uts1 |=UTS1_RXEMPTY ;imx_update (s); -qemu_chr_accept_input (s->chr); +if (s->chr) { +qemu_chr_accept_input (s->chr); + } }return c;Quoted 13 lines
hw/char/imx_serial.c static void imx_serial_write(void *opaque, hwaddr · line 220
Quoted 9 lines
hw/char/imx_serial.c +3
-1@@ -212,7 +214,9 @@ static void imx_serial_write(void *opaque, hwaddr offset, }if (value &UCR2_RXEN ) {if (!(s->ucr2 &UCR2_RXEN )) { -qemu_chr_accept_input (s->chr); +if (s->chr) { +qemu_chr_accept_input (s->chr); + }Looking around, imx serial is trying to be NULL safe except for these two cases. This and the hunk above is a full-on bugfix that should probably be split off and go to 2.4.
How do you provide a patch specifically for 2.4 (beside including it in my series)?
Quoted 60 lines
hw/char/imx_serial.c static void imx_event(void *opaque, int event) · line 302
Quoted 9 lines
hw/char/imx_serial.c +0
-0} }s->ucr2 = value & 0xffff;hw/char/imx_serial.c +0
-1@@ -299,23 +303,16 @@ static void imx_event(void *opaque, int event) } } -Out of scope style change.
Quoted 48 lines
hw/char/imx_serial.c +11
-12static const struct MemoryRegionOps imx_serial_ops = { .read = imx_serial_read, .write = imx_serial_write, .endianness =DEVICE_NATIVE_ENDIAN , }; -static int imx_serial_init (SysBusDevice *dev) +static void imx_serial_realize (DeviceState *dev,Error **errp) {IMXSerialState *s =IMX_SERIAL (dev); - -memory_region_init_io (&s->iomem,OBJECT (s), &imx_serial_ops, s, -"imx-serial" ,0x1000 ); -sysbus_init_mmio (dev, &s->iomem); -sysbus_init_irq (dev, &s->irq); -if (s->chr) {qemu_chr_add_handlers (s->chr, imx_can_receive, imx_receive, imx_event, s);@@ -323,45 +320,58 @@ static int imx_serial_init(SysBusDevice *dev)DPRINTF ("No char dev for uart at 0x%lx\n" , (unsigned long )s->iomem.ram_addr); } +} + +static void imx_serial_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +IMXSerialState *s =IMX_SERIAL (obj); -return 0 ; +memory_region_init_io (&s->iomem, obj, &imx_serial_ops, s, +TYPE_IMX_SERIAL ,0x1000 ); +sysbus_init_mmio (sbd, &s->iomem); +sysbus_init_irq (sbd, &s->irq); }void imx_serial_create (int uart,const hwaddr addr,qemu_irq irq) {DeviceState *dev; -SysBusDevice *bus; -CharDriverState *chr; -const char chr_name[] ="serial" ; -char label[ARRAY_SIZE (chr_name) +1 ]; dev =qdev_create (NULL ,TYPE_IMX_SERIAL );Quoted 15 lines
hw/char/imx_serial.c static int imx_serial_init(SysBusDevice *dev) · line 342
Quoted 11 lines
hw/char/imx_serial.c +1
-10-if (uart >=MAX_SERIAL_PORTS ) { -hw_error ("Cannot assign uart %d: QEMU supports only %d ports\n" , - uart,MAX_SERIAL_PORTS ); - } - chr = serial_hds[uart]; -if (!chr) { -snprintf (label,ARRAY_SIZE (label),"%s%d" , chr_name, uart); - chr =qemu_chr_new (label,"null" ,NULL ); -if (!(chr)) { -hw_error ("Can't assign serial port to imx-uart%d.\n" , uart); +if (dev) {If dev is NULL I think you have big problems. If there is a valid reason why this can be NULL in a non-error case then it should just short return.
It is obviously an error case (out of resource?) and therefore we should not ignore it (as it was previously the case). So I test for it here. Do you feel there should be another behavior (
hw_erroror something)?Quoted 51 lines
if (!dev) { return; }Quoted 30 lines
hw/char/imx_serial.c +18
-8+SysBusDevice *bus; + +if (uart <MAX_SERIAL_PORTS ) { +CharDriverState *chr; + + chr = serial_hds[uart]; + +if (!chr) { +char label[20 ]; +snprintf (label,sizeof (label),"imx.uart%d" , uart); + chr =qemu_chr_new (label,"null" ,NULL ); +if (!(chr)) { +hw_error ("Can't assign serial port to %s.\n" , label); + } + } + +qdev_prop_set_chr (dev,"chardev" , chr); } - } -qdev_prop_set_chr (dev,"chardev" , chr); - bus =SYS_BUS_DEVICE (dev); -qdev_init_nofail (dev); -if (addr != (hwaddr)-1 ) { -sysbus_mmio_map (bus,0 , addr); - } -sysbus_connect_irq (bus,0 , irq); + bus =SYS_BUS_DEVICE (dev);hw/char/imx_serial.c static int imx_serial_init(SysBusDevice *dev) · line 372
Quoted 10 lines
hw/char/imx_serial.c +8
-1-} +qdev_init_nofail (dev); + +if (addr != (hwaddr)-1 ) { +sysbus_mmio_map (bus,0 , addr); + } +sysbus_connect_irq (bus,0 , irq); + } +}So the change to
_createlooks correct, but it is still out of scope of the patch which by commit message is an init/realize conversion. Is there a reason the old_createimplementation wont work with the new init/realize and allow a split?Quoted 6 lines
Aside from the minor comments the code is good, but I would split this to 3 patches.
1: chr NULL guards, and send that as a single for 2.4. 2: realize and init conversion
3:_createrewrite.OK, I'll do it even if I am spending quite some time on something that is going to be wiped out in a following patch.
Quoted 42 lines
Regards,
PeterQuoted 38 lines
hw/char/imx_serial.c +8
-9-static Property imx32_serial_properties[] = { +static Property imx_serial_properties[] = {DEFINE_PROP_CHR ("chardev" , IMXSerialState, chr),DEFINE_PROP_END_OF_LIST (), };@@ -369,21 +379,21 @@ static Property imx32_serial_properties[] = {static void imx_serial_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); -SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); - k->init = imx_serial_init; + dc->realize = imx_serial_realize; dc->vmsd = &vmstate_imx_serial; dc->reset = imx_serial_reset_at_boot;set_bit (DEVICE_CATEGORY_INPUT , dc->categories); dc->desc ="i.MX series UART" ; - dc->props = imx32_serial_properties; + dc->props = imx_serial_properties; }static const TypeInfo imx_serial_info = { - .name =TYPE_IMX_SERIAL , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (IMXSerialState), - .class_init = imx_serial_class_init, + .name =TYPE_IMX_SERIAL , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (IMXSerialState), + .instance_init = imx_serial_init, + .class_init = imx_serial_class_init, };static void imx_serial_register_types (void ) --2.1.4
Re: [Qemu-devel] [PATCH v11 02/19] i.MX: Move serial initialization to init/realize of DeviceClass.
sorry accidental send, comments inline below.
Quoted 105 lines · Peter Crosthwaite
Quoted 103 lines · Jean-Christophe DUBOIS
Quoted 101 lines · Peter Crosthwaite
Quoted 86 lines · Jean-Christophe Dubois
Move constructor to DeviceClass methods
*imx_serial_init
*imx_serial_realize
imx32_serial_propertiesis renamed toimx_serial_properties.Rework of Qdev construction helper function.
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* not present on v1Changes since v2:
* not present on v2Changes since v3:
* not present on v3Changes since v4:
* not present on v4Changes since v5:
* not present on v5Changes since v6:
* not present on v6Changes since v7:
* not present on v7Changes since v8:
* Remove Qdev construction helperChanges since v9:
* Qdev construction helper is reintegrated and moved to a header
file
as an inline function.Changes since v10:
* Qdev construction helper is put back in the main file.
* Qdev construction helper is reworked
* We don't useqemu_char_get_next_serial()anymore but the chardev property instead.
* Fix code to work with an unitialized (null) chardev propertyhw/char/imx_serial.c | 98 +++++++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 44 deletions(-)hw/char/imx_serial.c +2
-2@@ -38,13 +38,13 @@ do { printf("imx_serial: " fmt , ##args); } while (0)//#define DEBUG_IMPLEMENTATION 1 #ifdef DEBUG_IMPLEMENTATION # define IPRINTF(fmt, args...) \ - do { fprintf(stderr, "imx_serial: " fmt, ##args); } while (0) + do { fprintf(stderr, "%s: " fmt, TYPE_IMX_SERIAL, ##args); } while (0)#else # define IPRINTF(fmt, args...) do {} while (0)#endif static const VMStateDescription vmstate_imx_serial = { - .name ="imx-serial" , + .name =TYPE_IMX_SERIAL , .version_id =1 , .minimum_version_id =1 ,.fields = (VMStateField[]) {hw/char/imx_serial.c +3
-1@@ -125,7 +125,9 @@ static uint64_t imx_serial_read(void *opaque, hwaddr offset, s->usr2 &= ~USR2_RDR ; s->uts1 |=UTS1_RXEMPTY ;imx_update (s); -qemu_chr_accept_input (s->chr); +if (s->chr) { +qemu_chr_accept_input (s->chr); + } }return c;hw/char/imx_serial.c static void imx_serial_write(void *opaque, hwaddr · line 220
Quoted 8 lines
hw/char/imx_serial.c +3
-1@@ -212,7 +214,9 @@ static void imx_serial_write(void *opaque, hwaddr offset, }if (value &UCR2_RXEN ) {if (!(s->ucr2 &UCR2_RXEN )) { -qemu_chr_accept_input (s->chr); +if (s->chr) { +qemu_chr_accept_input (s->chr); + }Looking around, imx serial is trying to be NULL safe except for these two cases. This and the hunk above is a full-on bugfix that should probably be split off and go to 2.4.
Quoted 3 lines
Quoted 3 lines
How do you provide a patch specifically for 2.4 (beside including it in my series)?
Split it off as a single and send it alone, --subject-prefix="PATCH for-2.4" argument to git send-email.
Quoted 137 lines
Quoted 137 lines
Quoted 61 lines
hw/char/imx_serial.c static void imx_event(void *opaque, int event) · line 302
Quoted 10 lines
hw/char/imx_serial.c +0
-0} }s->ucr2 = value & 0xffff;hw/char/imx_serial.c +0
-1@@ -299,23 +303,16 @@ static void imx_event(void *opaque, int event) } } -Out of scope style change.
Quoted 48 lines
hw/char/imx_serial.c +11
-12static const struct MemoryRegionOps imx_serial_ops = { .read = imx_serial_read, .write = imx_serial_write, .endianness =DEVICE_NATIVE_ENDIAN , }; -static int imx_serial_init (SysBusDevice *dev) +static void imx_serial_realize (DeviceState *dev,Error **errp) {IMXSerialState *s =IMX_SERIAL (dev); - -memory_region_init_io (&s->iomem,OBJECT (s), &imx_serial_ops, s, -"imx-serial" ,0x1000 ); -sysbus_init_mmio (dev, &s->iomem); -sysbus_init_irq (dev, &s->irq); -if (s->chr) {qemu_chr_add_handlers (s->chr, imx_can_receive, imx_receive, imx_event, s);@@ -323,45 +320,58 @@ static int imx_serial_init(SysBusDevice *dev)DPRINTF ("No char dev for uart at 0x%lx\n" , (unsigned long )s->iomem.ram_addr); } +} + +static void imx_serial_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +IMXSerialState *s =IMX_SERIAL (obj); -return 0 ; +memory_region_init_io (&s->iomem, obj, &imx_serial_ops, s, +TYPE_IMX_SERIAL ,0x1000 ); +sysbus_init_mmio (sbd, &s->iomem); +sysbus_init_irq (sbd, &s->irq); }void imx_serial_create (int uart,const hwaddr addr,qemu_irq irq) {DeviceState *dev; -SysBusDevice *bus; -CharDriverState *chr; -const char chr_name[] ="serial" ; -char label[ARRAY_SIZE (chr_name) +1 ]; dev =qdev_create (NULL ,TYPE_IMX_SERIAL );Quoted 15 lines
hw/char/imx_serial.c static int imx_serial_init(SysBusDevice *dev) · line 342
Quoted 11 lines
hw/char/imx_serial.c +1
-10-if (uart >=MAX_SERIAL_PORTS ) { -hw_error ("Cannot assign uart %d: QEMU supports only %d ports\n" , - uart,MAX_SERIAL_PORTS ); - } - chr = serial_hds[uart]; -if (!chr) { -snprintf (label,ARRAY_SIZE (label),"%s%d" , chr_name, uart); - chr =qemu_chr_new (label,"null" ,NULL ); -if (!(chr)) { -hw_error ("Can't assign serial port to imx-uart%d.\n" , uart); +if (dev) {If dev is NULL I think you have big problems. If there is a valid reason why this can be NULL in a non-error case then it should just short return.
It is obviously an error case (out of resource?) and therefore we should not ignore it (as it was previously the case). So I test for it here. Do you feel there should be another behavior (
hw_erroror something)?Quoted 54 lines
if (!dev) { return; }Quoted 30 lines
hw/char/imx_serial.c +18
-8+SysBusDevice *bus; + +if (uart <MAX_SERIAL_PORTS ) { +CharDriverState *chr; + + chr = serial_hds[uart]; + +if (!chr) { +char label[20 ]; +snprintf (label,sizeof (label),"imx.uart%d" , uart); + chr =qemu_chr_new (label,"null" ,NULL ); +if (!(chr)) { +hw_error ("Can't assign serial port to %s.\n" , label); + } + } + +qdev_prop_set_chr (dev,"chardev" , chr); } - } -qdev_prop_set_chr (dev,"chardev" , chr); - bus =SYS_BUS_DEVICE (dev); -qdev_init_nofail (dev); -if (addr != (hwaddr)-1 ) { -sysbus_mmio_map (bus,0 , addr); - } -sysbus_connect_irq (bus,0 , irq); + bus =SYS_BUS_DEVICE (dev);hw/char/imx_serial.c static int imx_serial_init(SysBusDevice *dev) · line 372
Quoted 10 lines
hw/char/imx_serial.c +8
-1-} +qdev_init_nofail (dev); + +if (addr != (hwaddr)-1 ) { +sysbus_mmio_map (bus,0 , addr); + } +sysbus_connect_irq (bus,0 , irq); + } +}So the change to
_createlooks correct, but it is still out of scope of the patch which by commit message is an init/realize conversion. Is there a reason the old_createimplementation wont work with the new init/realize and allow a split?Aside from the minor comments the code is good, but I would split this to 3 patches.
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
1: chr NULL guards, and send that as a single for 2.4. 2: realize and init conversion
3:_createrewrite.OK, I'll do it even if I am spending quite some time on something that is going to be wiped out in a following patch.
Ok but why? Does an unchanged _create work? Note existing bugs are ok, you don't faciliate any of your new functionalities or fix existing issues (e.g. becoming NULL safe or deal with missing error paths) you just need to not cause a regression half way through the series. So if the existing _create just works with your realize change (which AFAICT it does) just leave it unchanged and nuke it later in the series. What am I missing that requires the change to _create at all?
Regards,
Peter
Quoted 45 lines
Quoted 45 lines
Quoted 43 lines
Regards,
PeterQuoted 38 lines
hw/char/imx_serial.c +8
-9-static Property imx32_serial_properties[] = { +static Property imx_serial_properties[] = {DEFINE_PROP_CHR ("chardev" , IMXSerialState, chr),DEFINE_PROP_END_OF_LIST (), };@@ -369,21 +379,21 @@ static Property imx32_serial_properties[] = {static void imx_serial_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); -SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); - k->init = imx_serial_init; + dc->realize = imx_serial_realize; dc->vmsd = &vmstate_imx_serial; dc->reset = imx_serial_reset_at_boot;set_bit (DEVICE_CATEGORY_INPUT , dc->categories); dc->desc ="i.MX series UART" ; - dc->props = imx32_serial_properties; + dc->props = imx_serial_properties; }static const TypeInfo imx_serial_info = { - .name =TYPE_IMX_SERIAL , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (IMXSerialState), - .class_init = imx_serial_class_init, + .name =TYPE_IMX_SERIAL , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (IMXSerialState), + .instance_init = imx_serial_init, + .class_init = imx_serial_class_init, };static void imx_serial_register_types (void ) --2.1.4
Re: [Qemu-devel] [PATCH v11 02/19] i.MX: Move serial initialization to init/realize of DeviceClass.
Quoted 248 lines · Peter Crosthwaite
sorry accidental send, comments inline below.
Quoted 101 lines · Peter Crosthwaite
Quoted 99 lines · Jean-Christophe DUBOIS
Quoted 98 lines · Peter Crosthwaite
Quoted 85 lines · Jean-Christophe Dubois
Move constructor to DeviceClass methods
*imx_serial_init
*imx_serial_realize
imx32_serial_propertiesis renamed toimx_serial_properties.Rework of Qdev construction helper function.
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* not present on v1Changes since v2:
* not present on v2Changes since v3:
* not present on v3Changes since v4:
* not present on v4Changes since v5:
* not present on v5Changes since v6:
* not present on v6Changes since v7:
* not present on v7Changes since v8:
* Remove Qdev construction helperChanges since v9:
* Qdev construction helper is reintegrated and moved to a header
file
as an inline function.Changes since v10:
* Qdev construction helper is put back in the main file.
* Qdev construction helper is reworked
* We don't useqemu_char_get_next_serial()anymore but the chardev property instead.
* Fix code to work with an unitialized (null) chardev propertyhw/char/imx_serial.c | 98 +++++++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 44 deletions(-)hw/char/imx_serial.c +2
-2@@ -38,13 +38,13 @@ do { printf("imx_serial: " fmt , ##args); } while (0)//#define DEBUG_IMPLEMENTATION 1 #ifdef DEBUG_IMPLEMENTATION # define IPRINTF(fmt, args...) \ - do { fprintf(stderr, "imx_serial: " fmt, ##args); } while (0) + do { fprintf(stderr, "%s: " fmt, TYPE_IMX_SERIAL, ##args); } while (0)#else # define IPRINTF(fmt, args...) do {} while (0)#endif static const VMStateDescription vmstate_imx_serial = { - .name ="imx-serial" , + .name =TYPE_IMX_SERIAL , .version_id =1 , .minimum_version_id =1 ,.fields = (VMStateField[]) {hw/char/imx_serial.c +3
-1@@ -125,7 +125,9 @@ static uint64_t imx_serial_read(void *opaque, hwaddr offset, s->usr2 &= ~USR2_RDR ; s->uts1 |=UTS1_RXEMPTY ;imx_update (s); -qemu_chr_accept_input (s->chr); +if (s->chr) { +qemu_chr_accept_input (s->chr); + } }return c;hw/char/imx_serial.c static void imx_serial_write(void *opaque, hwaddr · line 220
Quoted 8 lines
hw/char/imx_serial.c +3
-1@@ -212,7 +214,9 @@ static void imx_serial_write(void *opaque, hwaddr offset, }if (value &UCR2_RXEN ) {if (!(s->ucr2 &UCR2_RXEN )) { -qemu_chr_accept_input (s->chr); +if (s->chr) { +qemu_chr_accept_input (s->chr); + }Looking around, imx serial is trying to be NULL safe except for these two cases. This and the hunk above is a full-on bugfix that should probably be split off and go to 2.4.
Quoted 3 lines
Quoted 3 lines
How do you provide a patch specifically for 2.4 (beside including it in my series)?
Split it off as a single and send it alone, --subject-prefix="PATCH for-2.4" argument to git send-email.
Quoted 130 lines
Quoted 130 lines
Quoted 58 lines
hw/char/imx_serial.c static void imx_event(void *opaque, int event) · line 302
Quoted 8 lines
hw/char/imx_serial.c +0
-0} }s->ucr2 = value & 0xffff;hw/char/imx_serial.c +0
-1@@ -299,23 +303,16 @@ static void imx_event(void *opaque, int event) } } -Out of scope style change.
Quoted 48 lines
hw/char/imx_serial.c +11
-12static const struct MemoryRegionOps imx_serial_ops = { .read = imx_serial_read, .write = imx_serial_write, .endianness =DEVICE_NATIVE_ENDIAN , }; -static int imx_serial_init (SysBusDevice *dev) +static void imx_serial_realize (DeviceState *dev,Error **errp) {IMXSerialState *s =IMX_SERIAL (dev); - -memory_region_init_io (&s->iomem,OBJECT (s), &imx_serial_ops, s, -"imx-serial" ,0x1000 ); -sysbus_init_mmio (dev, &s->iomem); -sysbus_init_irq (dev, &s->irq); -if (s->chr) {qemu_chr_add_handlers (s->chr, imx_can_receive, imx_receive, imx_event, s);@@ -323,45 +320,58 @@ static int imx_serial_init(SysBusDevice *dev)DPRINTF ("No char dev for uart at 0x%lx\n" , (unsigned long )s->iomem.ram_addr); } +} + +static void imx_serial_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +IMXSerialState *s =IMX_SERIAL (obj); -return 0 ; +memory_region_init_io (&s->iomem, obj, &imx_serial_ops, s, +TYPE_IMX_SERIAL ,0x1000 ); +sysbus_init_mmio (sbd, &s->iomem); +sysbus_init_irq (sbd, &s->irq); }void imx_serial_create (int uart,const hwaddr addr,qemu_irq irq) {DeviceState *dev; -SysBusDevice *bus; -CharDriverState *chr; -const char chr_name[] ="serial" ; -char label[ARRAY_SIZE (chr_name) +1 ]; dev =qdev_create (NULL ,TYPE_IMX_SERIAL );Quoted 14 lines
hw/char/imx_serial.c static int imx_serial_init(SysBusDevice *dev) · line 342
Quoted 11 lines
hw/char/imx_serial.c +1
-10-if (uart >=MAX_SERIAL_PORTS ) { -hw_error ("Cannot assign uart %d: QEMU supports only %d ports\n" , - uart,MAX_SERIAL_PORTS ); - } - chr = serial_hds[uart]; -if (!chr) { -snprintf (label,ARRAY_SIZE (label),"%s%d" , chr_name, uart); - chr =qemu_chr_new (label,"null" ,NULL ); -if (!(chr)) { -hw_error ("Can't assign serial port to imx-uart%d.\n" , uart); +if (dev) {If dev is NULL I think you have big problems. If there is a valid reason why this can be NULL in a non-error case then it should just short return.
It is obviously an error case (out of resource?) and therefore we should not ignore it (as it was previously the case). So I test for it here. Do you feel there should be another behavior (
hw_erroror something)?Quoted 52 lines
if (!dev) { return; }Quoted 30 lines
hw/char/imx_serial.c +18
-8+SysBusDevice *bus; + +if (uart <MAX_SERIAL_PORTS ) { +CharDriverState *chr; + + chr = serial_hds[uart]; + +if (!chr) { +char label[20 ]; +snprintf (label,sizeof (label),"imx.uart%d" , uart); + chr =qemu_chr_new (label,"null" ,NULL ); +if (!(chr)) { +hw_error ("Can't assign serial port to %s.\n" , label); + } + } + +qdev_prop_set_chr (dev,"chardev" , chr); } - } -qdev_prop_set_chr (dev,"chardev" , chr); - bus =SYS_BUS_DEVICE (dev); -qdev_init_nofail (dev); -if (addr != (hwaddr)-1 ) { -sysbus_mmio_map (bus,0 , addr); - } -sysbus_connect_irq (bus,0 , irq); + bus =SYS_BUS_DEVICE (dev);hw/char/imx_serial.c static int imx_serial_init(SysBusDevice *dev) · line 372
Quoted 10 lines
hw/char/imx_serial.c +8
-1-} +qdev_init_nofail (dev); + +if (addr != (hwaddr)-1 ) { +sysbus_mmio_map (bus,0 , addr); + } +sysbus_connect_irq (bus,0 , irq); + } +}So the change to
_createlooks correct, but it is still out of scope of the patch which by commit message is an init/realize conversion. Is there a reason the old_createimplementation wont work with the new init/realize and allow a split?Aside from the minor comments the code is good, but I would split this to 3 patches.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
1: chr NULL guards, and send that as a single for 2.4. 2: realize and init conversion
3:_createrewrite.OK, I'll do it even if I am spending quite some time on something that is going to be wiped out in a following patch.
Quoted 7 lines
Ok but why? Does an unchanged
_creatework? Note existing bugs are ok, you don't faciliate any of your new functionalities or fix existing issues (e.g. becoming NULL safe or deal with missing error paths) you just need to not cause a regression half way through the series. So if the existing_createjust works with your realize change (which AFAICT it does) just leave it unchanged and nuke it later in the series. What am I missing that requires the change to_createat all?
It sure does work in the non error case.
So I'll remove my "fix" and let it as is until it is nuked when I use the i.MX31 SOC implementation.
Quoted 46 lines
Regards,
PeterQuoted 42 lines
Quoted 42 lines
Quoted 41 lines
Regards,
PeterQuoted 38 lines
hw/char/imx_serial.c +8
-9-static Property imx32_serial_properties[] = { +static Property imx_serial_properties[] = {DEFINE_PROP_CHR ("chardev" , IMXSerialState, chr),DEFINE_PROP_END_OF_LIST (), };@@ -369,21 +379,21 @@ static Property imx32_serial_properties[] = {static void imx_serial_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); -SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); - k->init = imx_serial_init; + dc->realize = imx_serial_realize; dc->vmsd = &vmstate_imx_serial; dc->reset = imx_serial_reset_at_boot;set_bit (DEVICE_CATEGORY_INPUT , dc->categories); dc->desc ="i.MX series UART" ; - dc->props = imx32_serial_properties; + dc->props = imx_serial_properties; }static const TypeInfo imx_serial_info = { - .name =TYPE_IMX_SERIAL , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (IMXSerialState), - .class_init = imx_serial_class_init, + .name =TYPE_IMX_SERIAL , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (IMXSerialState), + .instance_init = imx_serial_init, + .class_init = imx_serial_class_init, };static void imx_serial_register_types (void ) --2.1.4
PATCH v11 3/19 i.MX:Fix Coding style for UART emulator.
In reply to Jean-Christophe Dubois---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* not preset on v7
Changes since v8:
* Fix coding style
Changes since v9:
* no change
Changes since v10:
* no change
hw/char/imx_serial.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
hw/char/imx_serial.c +15 -15
@@ -26,7 +26,7 @@//#define DEBUG_SERIAL 1 #ifdef DEBUG_SERIAL #define DPRINTF(fmt, args...) \ -do { printf("imx_serial: " fmt , ##args); } while (0) +do { printf("%s: " fmt , TYPE_IMX_SERIAL, ##args); } while (0)#else #define DPRINTF(fmt, args...) do {} while (0)#endif
@@ -166,13 +166,13 @@ static uint64_t imx_serial_read(void *opaque, hwaddr offset,return 0x0 ;/* TODO */ default : -IPRINTF ("imx_serial_read: bad offset: 0x%x\n" , (int )offset); +IPRINTF ("%s: bad offset: 0x%x\n" , __func__, (int )offset);return 0 ; } }static void imx_serial_write (void *opaque,hwaddr offset, -uint64_t value,unsigned size) +uint64_t value,unsigned size) {IMXSerialState *s = (IMXSerialState *)opaque;unsigned char ch;
@@ -224,25 +224,25 @@ static void imx_serial_write(void *opaque, hwaddr offset,case 0x25 :/* USR1 */ value &=USR1_AWAKE |USR1_AIRINT |USR1_DTRD |USR1_AGTIM | -USR1_FRAMERR |USR1_ESCF |USR1_RTSD |USR1_PARTYER ; +USR1_FRAMERR |USR1_ESCF |USR1_RTSD |USR1_PARTYER ; s->usr1 &= ~value;break ;case 0x26 :/* USR2 */ -/* -* Writing 1 to some bits clears them; all other -* values are ignored -*/ +/* +* Writing 1 to some bits clears them; all other +* values are ignored +*/ value &=USR2_ADET |USR2_DTRF |USR2_IDLE |USR2_ACST | -USR2_RIDELT |USR2_IRINT |USR2_WAKE | -USR2_DCDDELT |USR2_RTSF |USR2_BRCD |USR2_ORE ; +USR2_RIDELT |USR2_IRINT |USR2_WAKE | +USR2_DCDDELT |USR2_RTSF |USR2_BRCD |USR2_ORE ; s->usr2 &= ~value;break ; -/* -* Linux expects to see what it writes to these registers -* We don't currently alter the baud rate -*/ +/* +* Linux expects to see what it writes to these registers +* We don't currently alter the baud rate +*/ case 0x29 :/* UBIR */ s->ubrc = value &0xffff ;break ;
@@ -270,7 +270,7 @@ static void imx_serial_write(void *opaque, hwaddr offset,break ;default : -IPRINTF ("imx_serial_write: Bad offset 0x%x\n" , (int )offset); +IPRINTF ("%s: Bad offset 0x%x\n" , __func__, (int )offset); } }
Signature · 1 line
2.1.4
PATCH v11 4/19 i.MX: Split AVIC emulator in a header file and a source file
In reply to Jean-Christophe Dubois---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* Splited the i.MX AVIC emulator into a header file and a source file
Changes since v8:
* no changes
Changes since v9:
* Small style rework.
Changes since v10:
* no change
hw/arm/kzm.c | 3 ++- hw/intc/imx_avic.c | 40 +++------------------------------ include/hw/intc/imx_avic.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 38 deletions(-) create mode 100644 include/hw/intc/imx_avic.h
hw/arm/kzm.c +2 -1
@@ -22,6 +22,7 @@#include "sysemu/sysemu.h" #include "hw/boards.h" #include "hw/char/serial.h" +#include "hw/intc/imx_avic.h" #include "hw/arm/imx.h" /* Memory map for Kzm Emulation Baseboard:
@@ -106,7 +107,7 @@ static void kzm_init(MachineState *machine)memory_region_init_ram (sram,NULL ,"kzm.sram" ,0x4000 , &error_abort);memory_region_add_subregion (address_space_mem,0x1FFFC000 , sram); - dev =sysbus_create_varargs ("imx_avic" ,0x68000000 , + dev =sysbus_create_varargs (TYPE_IMX_AVIC ,0x68000000 ,qdev_get_gpio_in (DEVICE (cpu),ARM_CPU_IRQ ),qdev_get_gpio_in (DEVICE (cpu),ARM_CPU_FIQ ),NULL );
hw/intc/imx_avic.c +3 -37
@@ -7,6 +7,7 @@* Copyright (c) 2008 OKL * Copyright (c) 2011 NICTA Pty Ltd * Originally written by Hans Jiang +* Updated by Jean-Christophe Dubois <[email protected]> * * This code is licensed under the GPL version 2 or later. See * the COPYING file in the top-level directory.
@@ -14,9 +15,7 @@* TODO: implement vectors. */ -#include "hw/hw.h" -#include "hw/sysbus.h" -#include "qemu/host-utils.h" +#include "hw/intc/imx_avic.h" #define DEBUG_INT 1#undef DEBUG_INT/* comment out for debugging */
@@ -40,39 +39,6 @@ do { printf("imx_avic: " fmt , ##args); } while (0) # define IPRINTF(fmt, args...) do {} while (0)#endif -#define IMX_AVIC_NUM_IRQS 64 - -/* Interrupt Control Bits */ -#define ABFLAG (1<<25) -#define ABFEN (1<<24) -#define NIDIS (1<<22)/* Normal Interrupt disable */ -#define FIDIS (1<<21)/* Fast interrupt disable */ -#define NIAD (1<<20)/* Normal Interrupt Arbiter Rise ARM level */ -#define FIAD (1<<19)/* Fast Interrupt Arbiter Rise ARM level */ -#define NM (1<<18)/* Normal interrupt mode */ - - -#define PRIO_PER_WORD (sizeof(uint32_t) * 8 / 4) -#define PRIO_WORDS (IMX_AVIC_NUM_IRQS/PRIO_PER_WORD) - -#define TYPE_IMX_AVIC "imx_avic" -#define IMX_AVIC (obj) \ - OBJECT_CHECK(IMXAVICState, (obj), TYPE_IMX_AVIC) - -typedef struct IMXAVICState { -SysBusDevice parent_obj; - -MemoryRegion iomem; -uint64_t pending; -uint64_t enabled; -uint64_t is_fiq; -uint32_t intcntl; -uint32_t intmask; -qemu_irq irq; -qemu_irq fiq; -uint32_t prio[PRIO_WORDS ];/* Priorities are 4-bits each */ -}IMXAVICState ; -static const VMStateDescription vmstate_imx_avic = { .name ="imx-avic" , .version_id =1 ,
@@ -370,7 +336,7 @@ static int imx_avic_init(SysBusDevice *sbd)IMXAVICState *s =IMX_AVIC (dev);memory_region_init_io (&s->iomem,OBJECT (s), &imx_avic_ops, s, -"imx_avic" ,0x1000 ); +TYPE_IMX_AVIC ,0x1000 );sysbus_init_mmio (sbd, &s->iomem);qdev_init_gpio_in (dev, imx_avic_set_irq,IMX_AVIC_NUM_IRQS );
include/hw/intc/imx_avic.h new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v11 5/19 i.MX: Fix Coding style for AVIC emulator.
In reply to Jean-Christophe Dubois---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* not present on v7
Changes since v8:
* improve log
* Do style cleaning
Changes since v9:
* Change patch title.
Changes since v10:
* no change.
hw/intc/imx_avic.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
hw/intc/imx_avic.c +7 -9
@@ -22,7 +22,7 @@#ifdef DEBUG_INT #define DPRINTF(fmt, args...) \ -do { printf("imx_avic: " fmt , ##args); } while (0) +do { printf("%s: " fmt , TYPE_IMX_AVIC, ##args); } while (0)#else #define DPRINTF(fmt, args...) do {} while (0)#endif
@@ -34,13 +34,13 @@ do { printf("imx_avic: " fmt , ##args); } while (0)#define DEBUG_IMPLEMENTATION 1#if DEBUG_IMPLEMENTATION # define IPRINTF(fmt, args...) \ - do { fprintf(stderr, "imx_avic: " fmt, ##args); } while (0) + do { fprintf(stderr, "%s: " fmt, TYPE_IMX_AVIC, ##args); } while (0)#else # define IPRINTF(fmt, args...) do {} while (0)#endif static const VMStateDescription vmstate_imx_avic = { - .name ="imx-avic" , + .name =TYPE_IMX_AVIC , .version_id =1 , .minimum_version_id =1 , .fields = (VMStateField []) {
@@ -54,8 +54,6 @@ static const VMStateDescription vmstate_imx_avic = { }, }; - -static inline int imx_avic_prio (IMXAVICState *s,int irq) {uint32_t word = irq /PRIO_PER_WORD ;
@@ -215,7 +213,7 @@ static uint64_t imx_avic_read(void *opaque,return 0x4 ;default : -IPRINTF ("imx_avic_read: Bad offset 0x%x\n" , (int )offset); +IPRINTF ("%s: Bad offset 0x%x\n" , __func__, (int )offset);return 0 ; } }
@@ -227,12 +225,12 @@ static void imx_avic_write(void *opaque, hwaddr offset,/* Vector Registers not yet supported */ if (offset >=0x100 && offset <=0x2fc ) { -IPRINTF ("imx_avic_write to vector register %d ignored\n" , +IPRINTF ("%s to vector register %d ignored\n" , __func__, (unsigned int )((offset -0x100 ) >>2 ));return ; } -DPRINTF ("imx_avic_write(0x%x) = %x\n" , +DPRINTF ("%s(0x%x) = %x\n" , __func__, (unsigned int )offset>>2 , (unsigned int )val);switch (offset >>2 ) {case 0 :/* Interrupt Control Register, INTCNTL */
@@ -307,7 +305,7 @@ static void imx_avic_write(void *opaque, hwaddr offset,return ;default : -IPRINTF ("imx_avic_write: Bad offset %x\n" , (int )offset); +IPRINTF ("%s: Bad offset %x\n" , __func__, (int )offset); }imx_avic_update (s); }
Signature · 1 line
2.1.4
PATCH v11 6/19 i.MX: Split CCM emulator in a header file and a source file
In reply to Jean-Christophe Dubois---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* Splited the i.MX CCM emulator into a header file and a source file
Changes since v8:
* no change
Changes since v9:
* change kzm to avoid run time error on CCM creation.
Changes since v10:
* no change
hw/arm/kzm.c | 2 +- hw/misc/imx_ccm.c | 70 ++---------------------------------- include/hw/arm/imx.h | 12 ++----- include/hw/misc/imx_ccm.h | 91 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 78 deletions(-) create mode 100644 include/hw/misc/imx_ccm.h
hw/arm/kzm.c +1 -1
@@ -115,7 +115,7 @@ static void kzm_init(MachineState *machine)imx_serial_create (0 ,0x43f90000 ,qdev_get_gpio_in (dev,45 ));imx_serial_create (1 ,0x43f94000 ,qdev_get_gpio_in (dev,32 )); - ccm =sysbus_create_simple ("imx_ccm" ,0x53f80000 ,NULL ); + ccm =sysbus_create_simple (TYPE_IMX_CCM ,0x53f80000 ,NULL );imx_timerp_create (0x53f94000 ,qdev_get_gpio_in (dev,28 ), ccm);imx_timerp_create (0x53f98000 ,qdev_get_gpio_in (dev,27 ), ccm);
hw/misc/imx_ccm.c +3 -67
100 lines not on this page · raw message
include/hw/arm/imx.h +2 -10
@@ -11,17 +11,9 @@#ifndef IMX_H #define IMX_H -void imx_serial_create (int uart,const hwaddr addr,qemu_irq irq); - -typedef enum { -NOCLK , -MCU , -HSP , -IPG , - CLK_32k -}IMXClk ; +#include "hw/misc/imx_ccm.h" -uint32_t imx_clock_frequency (DeviceState *s,IMXClk clock); +void imx_serial_create (int uart,const hwaddr addr,qemu_irq irq); void imx_timerp_create(const hwaddr addr, qemu_irq irq,
include/hw/misc/imx_ccm.h new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v11 7/19 i.MX: Fix Coding style for CCM emulator
In reply to Jean-Christophe Dubois---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* not present on v7
Changes since v8:
* Improve logs
Changes since v9:
* Change patch title.
Changes since v10:
* no change.
hw/misc/imx_ccm.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
hw/misc/imx_ccm.c +5 -6
@@ -16,11 +16,10 @@#define CKIH_FREQ 26000000/* 26MHz crystal input */ #define CKIL_FREQ 32768/* nominal 32khz clock */ -//#define DEBUG_CCM 1 #ifdef DEBUG_CCM #define DPRINTF(fmt, args...) \ -do { printf("imx_ccm: " fmt , ##args); } while (0) +do { printf("%s: " fmt , TYPE_IMX_CCM, ##args); } while (0)#else #define DPRINTF(fmt, args...) do {} while (0)#endif
@@ -28,7 +27,7 @@ do { printf("imx_ccm: " fmt , ##args); } while (0)static int imx_ccm_post_load (void *opaque,int version_id);static const VMStateDescription vmstate_imx_ccm = { - .name ="imx-ccm" , + .name =TYPE_IMX_CCM , .version_id =1 , .minimum_version_id =1 , .fields = (VMStateField []) {
@@ -110,7 +109,7 @@ static void update_clocks(IMXCCMState *s) s->hsp_clk_freq = s->mcu_clk_freq / (1 +EXTRACT (s->pdr0,HSP )); s->ipg_clk_freq = s->hsp_clk_freq / (1 +EXTRACT (s->pdr0,IPG )); -DPRINTF ("Clocks: mcu %uMHz, HSP %uMHz, IPG %uHz\n" , +DPRINTF ("%s: mcu %uMHz, HSP %uMHz, IPG %uHz\n" , __func__, s->mcu_clk_freq /1000000 , s->hsp_clk_freq /1000000 , s->ipg_clk_freq);
@@ -136,7 +135,7 @@ static uint64_t imx_ccm_read(void *opaque, hwaddr offset, {IMXCCMState *s = (IMXCCMState *)opaque; -DPRINTF ("read(offset=%x)" , offset >>2 ); +DPRINTF ("%s(offset=%x)" , __func__, offset >>2 );switch (offset >>2 ) {case 0 :/* CCMR */ DPRINTF (" ccmr = 0x%x\n" , s->ccmr);
@@ -177,7 +176,7 @@ static void imx_ccm_write(void *opaque, hwaddr offset, {IMXCCMState *s = (IMXCCMState *)opaque; -DPRINTF ("write(offset=%x, value = %x)\n" , +DPRINTF ("%s(offset=%x, value = %x)\n" , __func__, offset >>2 , (unsigned int )value);switch (offset >>2 ) {case 0 :
Signature · 1 line
2.1.4
PATCH v11 8/19 i.MX: Split EPIT emulator in a header file and a source file
In reply to Jean-Christophe Dubois---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* Splited the i.MX EPIT emulator into a header file and a source file
Changes since: v8:
* no change
Changes since v9:
* no change
Changes since v10:
* Coding style changes.
hw/timer/imx_epit.c | 52 ++--------------------------- include/hw/timer/imx_epit.h | 79 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 49 deletions(-) create mode 100644 include/hw/timer/imx_epit.h
hw/timer/imx_epit.c +3 -49
@@ -5,23 +5,18 @@* Copyright (c) 2011 NICTA Pty Ltd * Originally written by Hans Jiang * Updated by Peter Chubb -* Updated by Jean-Christophe Dubois +* Updated by Jean-Christophe Dubois <[email protected]> * * This code is licensed under GPL version 2 or later. See * the COPYING file in the top-level directory. * */ -#include "hw/hw.h" -#include "qemu/bitops.h" -#include "qemu/timer.h" -#include "hw/ptimer.h" -#include "hw/sysbus.h" #include "hw/arm/imx.h" +#include "hw/timer/imx_epit.h" +#include "hw/misc/imx_ccm.h" #include "qemu/main-loop.h" -#define TYPE_IMX_EPIT "imx.epit" -#define DEBUG_TIMER 0#if DEBUG_TIMER
@@ -61,30 +56,6 @@ static char const *imx_epit_reg_name(uint32_t reg) # define IPRINTF(fmt, args...) do {} while (0)#endif -#define IMX_EPIT (obj) \ - OBJECT_CHECK(IMXEPITState, (obj), TYPE_IMX_EPIT) - -/* -* EPIT: Enhanced periodic interrupt timer -*/ - -#define CR_EN (1 << 0) -#define CR_ENMOD (1 << 1) -#define CR_OCIEN (1 << 2) -#define CR_RLD (1 << 3) -#define CR_PRESCALE_SHIFT (4) -#define CR_PRESCALE_MASK (0xfff) -#define CR_SWR (1 << 16) -#define CR_IOVW (1 << 17) -#define CR_DBGEN (1 << 18) -#define CR_WAITEN (1 << 19) -#define CR_DOZEN (1 << 20) -#define CR_STOPEN (1 << 21) -#define CR_CLKSRC_SHIFT (24) -#define CR_CLKSRC_MASK (0x3 << CR_CLKSRC_SHIFT) - -#define EPIT_TIMER_MAX 0XFFFFFFFFUL -/* * Exact clock frequencies vary from board to board. * These are typical.
@@ -96,23 +67,6 @@ static const IMXClk imx_epit_clocks[] = { CLK_32k, /* 11 ipg_clk_32k -- ~32kHz */ }; -typedef struct { -SysBusDevice busdev; -ptimer_state *timer_reload; -ptimer_state *timer_cmp; -MemoryRegion iomem; -DeviceState *ccm; - -uint32_t cr; -uint32_t sr; -uint32_t lr; -uint32_t cmp; -uint32_t cnt; - -uint32_t freq; -qemu_irq irq; -}IMXEPITState ; -/* * Update interrupt status */
include/hw/timer/imx_epit.h new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v11 9/19 i.MX: Fix Coding style for EPIT emulator
In reply to Jean-Christophe Dubois---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* not present on v7
Changes since v8:
* Fix coding style
Changes since v9:
* no change
Changes since v10:
* no change.
hw/timer/imx_epit.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/timer/imx_epit.c +6 -6
@@ -128,9 +128,9 @@ static void imx_epit_reset(DeviceState *dev)static uint32_t imx_epit_update_count (IMXEPITState *s) { - s->cnt =ptimer_get_count (s->timer_reload); + s->cnt =ptimer_get_count (s->timer_reload); -return s->cnt; +return s->cnt; }static uint64_t imx_epit_read (void *opaque,hwaddr offset,unsigned size)
@@ -298,13 +298,13 @@ void imx_timerp_create(const hwaddr addr, qemu_irq irq, DeviceState *ccm) }static const MemoryRegionOps imx_epit_ops = { - .read = imx_epit_read, - .write = imx_epit_write, - .endianness =DEVICE_NATIVE_ENDIAN , + .read = imx_epit_read, + .write = imx_epit_write, + .endianness =DEVICE_NATIVE_ENDIAN , };static const VMStateDescription vmstate_imx_timer_epit = { - .name ="imx.epit" , + .name =TYPE_IMX_EPIT , .version_id =2 , .minimum_version_id =2 , .fields = (VMStateField []) {
Signature · 1 line
2.1.4
PATCH v11 10/19 i.MX: Split GPT emulator in a header file and a source file
In reply to Jean-Christophe Dubois---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* Splited the i.MX GPT emulator into a header file and a source file
Changes since v8:
* no change
Changes since v9:
* no change
Changes sinc v10:
* Fix coding style.
hw/timer/imx_gpt.c | 79 ++------------------------------- include/hw/timer/imx_gpt.h | 107 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 76 deletions(-) create mode 100644 include/hw/timer/imx_gpt.h
hw/timer/imx_gpt.c +3 -76
@@ -5,23 +5,18 @@* Copyright (c) 2011 NICTA Pty Ltd * Originally written by Hans Jiang * Updated by Peter Chubb -* Updated by Jean-Christophe Dubois +* Updated by Jean-Christophe Dubois <[email protected]> * * This code is licensed under GPL version 2 or later. See * the COPYING file in the top-level directory. * */ -#include "hw/hw.h" -#include "qemu/bitops.h" -#include "qemu/timer.h" -#include "hw/ptimer.h" -#include "hw/sysbus.h" #include "hw/arm/imx.h" +#include "hw/timer/imx_gpt.h" +#include "hw/misc/imx_ccm.h" #include "qemu/main-loop.h" -#define TYPE_IMX_GPT "imx.gpt" -/* * Define to 1 for debug messages */
@@ -74,74 +69,6 @@ static char const *imx_gpt_reg_name(uint32_t reg) # define IPRINTF(fmt, args...) do {} while (0)#endif -#define IMX_GPT (obj) \ - OBJECT_CHECK(IMXGPTState, (obj), TYPE_IMX_GPT) -/* -* GPT : General purpose timer -* -* This timer counts up continuously while it is enabled, resetting itself -* to 0 when it reaches GPT_TIMER_MAX (in freerun mode) or when it -* reaches the value of one of the ocrX (in periodic mode). -*/ - -#define GPT_TIMER_MAX 0XFFFFFFFFUL - -/* Control register. Not all of these bits have any effect (yet) */ -#define GPT_CR_EN (1 << 0)/* GPT Enable */ -#define GPT_CR_ENMOD (1 << 1)/* GPT Enable Mode */ -#define GPT_CR_DBGEN (1 << 2)/* GPT Debug mode enable */ -#define GPT_CR_WAITEN (1 << 3)/* GPT Wait Mode Enable */ -#define GPT_CR_DOZEN (1 << 4)/* GPT Doze mode enable */ -#define GPT_CR_STOPEN (1 << 5)/* GPT Stop Mode Enable */ -#define GPT_CR_CLKSRC_SHIFT (6) -#define GPT_CR_CLKSRC_MASK (0x7) - -#define GPT_CR_FRR (1 << 9)/* Freerun or Restart */ -#define GPT_CR_SWR (1 << 15)/* Software Reset */ -#define GPT_CR_IM1 (3 << 16)/* Input capture channel 1 mode (2 bits) */ -#define GPT_CR_IM2 (3 << 18)/* Input capture channel 2 mode (2 bits) */ -#define GPT_CR_OM1 (7 << 20)/* Output Compare Channel 1 Mode (3 bits) */ -#define GPT_CR_OM2 (7 << 23)/* Output Compare Channel 2 Mode (3 bits) */ -#define GPT_CR_OM3 (7 << 26)/* Output Compare Channel 3 Mode (3 bits) */ -#define GPT_CR_FO1 (1 << 29)/* Force Output Compare Channel 1 */ -#define GPT_CR_FO2 (1 << 30)/* Force Output Compare Channel 2 */ -#define GPT_CR_FO3 (1 << 31)/* Force Output Compare Channel 3 */ - -#define GPT_SR_OF1 (1 << 0) -#define GPT_SR_OF2 (1 << 1) -#define GPT_SR_OF3 (1 << 2) -#define GPT_SR_ROV (1 << 5) - -#define GPT_IR_OF1IE (1 << 0) -#define GPT_IR_OF2IE (1 << 1) -#define GPT_IR_OF3IE (1 << 2) -#define GPT_IR_ROVIE (1 << 5) - -typedef struct { -SysBusDevice busdev; -ptimer_state *timer; -MemoryRegion iomem; -DeviceState *ccm; - -uint32_t cr; -uint32_t pr; -uint32_t sr; -uint32_t ir; -uint32_t ocr1; -uint32_t ocr2; -uint32_t ocr3; -uint32_t icr1; -uint32_t icr2; -uint32_t cnt; - -uint32_t next_timeout; -uint32_t next_int; - -uint32_t freq; - -qemu_irq irq; -}IMXGPTState ; -static const VMStateDescription vmstate_imx_timer_gpt = { .name ="imx.gpt" , .version_id =3 ,
include/hw/timer/imx_gpt.h new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v11 11/19 i.MX: Fix Coding style for GPT emulator
In reply to Jean-Christophe Dubois---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* not present on v7
Changes since v8:
* Fix coding style
Changes since v9:
* no change
Changes since v10:
* no change.
hw/timer/imx_gpt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/timer/imx_gpt.c +3 -3
@@ -70,7 +70,7 @@ static char const *imx_gpt_reg_name(uint32_t reg)#endif static const VMStateDescription vmstate_imx_timer_gpt = { - .name ="imx.gpt" , + .name =TYPE_IMX_GPT , .version_id =3 , .minimum_version_id =3 , .fields = (VMStateField []) {
@@ -107,7 +107,7 @@ static void imx_gpt_set_freq(IMXGPTState *s) {uint32_t clksrc =extract32 (s->cr,GPT_CR_CLKSRC_SHIFT ,3 );uint32_t freq =imx_clock_frequency (s->ccm, imx_gpt_clocks[clksrc]) - / (1 + s->pr); + / (1 + s->pr); s->freq = freq;DPRINTF ("Setting clksrc %d to frequency %d\n" , clksrc, freq);
@@ -134,7 +134,7 @@ static uint32_t imx_gpt_update_count(IMXGPTState *s) }static inline uint32_t imx_gpt_find_limit (uint32_t count,uint32_t reg, -uint32_t timeout) +uint32_t timeout) {if ((count < reg) && (timeout > reg)) { timeout = reg;
Signature · 1 line
2.1.4
PATCH v11 12/19 i.MX: Add SOC support for i.MX31
In reply to Jean-Christophe DuboisFor now we support the following devices:
* CPU: ARM1136
* Interrupt Controller: AVIC
* CCM
* UART x 2
* EPIT x 2
* GPT
---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* not present on v7
Changes since v8:
* use defines instead of hardcoded values for IRQ and ADDR
* Add i.MX31 SOC support
Changes since v9:
* no change.
Changes since v10:
* added description of supported devices
* rework of UART init to use chardev property
* use memory_region_allocate_system_memory()
* Fix coding style.
default-configs/arm-softmmu.mak | 2 + hw/arm/Makefile.objs | 1 + hw/arm/fsl-imx31.c | 203 ++++++++++++++++++++++++++++++++++++++++ include/hw/arm/fsl-imx31.h | 98 +++++++++++++++++++ 4 files changed, 304 insertions(+) create mode 100644 hw/arm/fsl-imx31.c create mode 100644 include/hw/arm/fsl-imx31.h
default-configs/arm-softmmu.mak +2 -0
@@ -98,6 +98,8 @@ CONFIG_ALLWINNER_A10_PIT=y CONFIG_ALLWINNER_A10_PIC=y CONFIG_ALLWINNER_A10=y +CONFIG_FSL_IMX31=y + CONFIG_XIO3130=y CONFIG_IOH3420=y CONFIG_I82801B11=y
hw/arm/Makefile.objs +1 -0
@@ -13,3 +13,4 @@ obj-y += omap1.o omap2.o strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp.o xlnx-ep108.o +obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o
hw/arm/fsl-imx31.c new file +203 -0
203 lines not on this page · raw message
include/hw/arm/fsl-imx31.h new file +98 -0
98 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH v11 12/19] i.MX: Add SOC support for i.MX31
Quoted 9 lines · Jean-Christophe Dubois
For now we support the following devices:
* CPU: ARM1136
* Interrupt Controller: AVIC
* CCM
* UART x 2
* EPIT x 2
* GPTSigned-off-by Jean-Christophe Dubois <[email protected]>
Quoted 383 lines
---
Changes since v1:
* not present on v1Changes since v2:
* not present on v2Changes since v3:
* not present on v3Changes since v4:
* not present on v4Changes since v5:
* not present on v5Changes since v6:
* not present on v6Changes since v7:
* not present on v7Changes since v8:
* use defines instead of hardcoded values for IRQ and ADDR
* Add i.MX31 SOC supportChanges since v9:
* no change.Changes since v10:
* added description of supported devices
* rework of UART init to use chardev property
* usememory_region_allocate_system_memory()
* Fix coding style.default-configs/arm-softmmu.mak | 2 + hw/arm/Makefile.objs | 1 + hw/arm/fsl-imx31.c | 203 ++++++++++++++++++++++++++++++++++++++++ include/hw/arm/fsl-imx31.h | 98 +++++++++++++++++++ 4 files changed, 304 insertions(+) create mode 100644 hw/arm/fsl-imx31.c create mode 100644 include/hw/arm/fsl-imx31.hdefault-configs/arm-softmmu.mak +2
-0@@ -98,6 +98,8 @@ CONFIG_ALLWINNER_A10_PIT=y CONFIG_ALLWINNER_A10_PIC=y CONFIG_ALLWINNER_A10=y +CONFIG_FSL_IMX31=y + CONFIG_XIO3130=y CONFIG_IOH3420=y CONFIG_I82801B11=yhw/arm/Makefile.objs +1
-0@@ -13,3 +13,4 @@ obj-y += omap1.o omap2.o strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp.o xlnx-ep108.o +obj-$(CONFIG_FSL_IMX31) += fsl-imx31.ohw/arm/fsl-imx31.c new file +203
-0@@ -0,0 +1,203 @@ +/* +* Copyright (c) 2013 Jean-Christophe Dubois <[email protected]> +* +* i.MX31 SOC emulation. +* +* Based on hw/arm/fsl-imx31.c +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "hw/arm/fsl-imx31.h" +#include "sysemu/sysemu.h" +#include "exec/address-spaces.h" +#include "hw/boards.h" +#include "sysemu/char.h" + +static void fsl_imx31_init (Object *obj) +{ +FslIMX31State *s =FSL_IMX31 (obj); +int i; + +object_initialize (&s->cpu,sizeof (s->cpu),"arm1136-" TYPE_ARM_CPU ); + +object_initialize (&s->avic,sizeof (s->avic),TYPE_IMX_AVIC ); +qdev_set_parent_bus (DEVICE (&s->avic),sysbus_get_default ()); + +object_initialize (&s->ccm,sizeof (s->ccm),TYPE_IMX_CCM ); +qdev_set_parent_bus (DEVICE (&s->ccm),sysbus_get_default ()); + +for (i =0 ; i <FSL_IMX31_NUM_UARTS ; i++) { +object_initialize (&s->uart[i],sizeof (s->uart[i]),TYPE_IMX_SERIAL ); +qdev_set_parent_bus (DEVICE (&s->uart[i]),sysbus_get_default ()); + } + +object_initialize (&s->gpt,sizeof (s->gpt),TYPE_IMX_GPT ); +qdev_set_parent_bus (DEVICE (&s->gpt),sysbus_get_default ()); + +for (i =0 ; i <FSL_IMX31_NUM_EPITS ; i++) { +object_initialize (&s->epit[i],sizeof (s->epit[i]),TYPE_IMX_EPIT ); +qdev_set_parent_bus (DEVICE (&s->epit[i]),sysbus_get_default ()); + } +} + +static void fsl_imx31_realize (DeviceState *dev,Error **errp) +{ +FslIMX31State *s =FSL_IMX31 (dev); +uint16_t i; +Error *err =NULL ; + +object_property_set_bool (OBJECT (&s->cpu), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + +object_property_set_bool (OBJECT (&s->avic), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->avic),0 ,FSL_IMX31_AVIC_ADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->avic),0 , +qdev_get_gpio_in (DEVICE (&s->cpu),ARM_CPU_IRQ )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->avic),1 , +qdev_get_gpio_in (DEVICE (&s->cpu),ARM_CPU_FIQ )); + +object_property_set_bool (OBJECT (&s->ccm), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->ccm),0 ,FSL_IMX31_CCM_ADDR ); + +/* Initialize all UARTS */ +for (i =0 ; i <FSL_IMX31_NUM_UARTS ; i++) { +static const struct { +hwaddr addr; +unsigned int irq; + } serial_table[FSL_IMX31_NUM_UARTS ] = { + {FSL_IMX31_UART1_ADDR ,FSL_IMX31_UART1_IRQ }, + {FSL_IMX31_UART2_ADDR ,FSL_IMX31_UART2_IRQ }, + }; + +if (i <MAX_SERIAL_PORTS ) { +CharDriverState *chr; + + chr = serial_hds[i]; + +if (!chr) { +char label[20 ]; +snprintf (label,sizeof (label),"imx31.uart%d" , i); + chr =qemu_chr_new (label,"null" ,NULL ); + } + +qdev_prop_set_chr (DEVICE (&s->uart[i]),"chardev" , chr); + } + +object_property_set_bool (OBJECT (&s->uart[i]), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + +sysbus_mmio_map (SYS_BUS_DEVICE (&s->uart[i]),0 , serial_table[i].addr); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->uart[i]),0 , +qdev_get_gpio_in (DEVICE (&s->avic), + serial_table[i].irq)); + } + + s->gpt.ccm =DEVICE (&s->ccm); + +object_property_set_bool (OBJECT (&s->gpt), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + +sysbus_mmio_map (SYS_BUS_DEVICE (&s->gpt),0 ,FSL_IMX31_GPT_ADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->gpt),0 , +qdev_get_gpio_in (DEVICE (&s->avic),FSL_IMX31_GPT_IRQ )); + +/* Initialize all EPIT timers */ +for (i =0 ; i <FSL_IMX31_NUM_EPITS ; i++) { +static const struct { +hwaddr addr; +unsigned int irq; + } epit_table[FSL_IMX31_NUM_EPITS ] = { + {FSL_IMX31_EPIT1_ADDR ,FSL_IMX31_EPIT1_IRQ }, + {FSL_IMX31_EPIT2_ADDR ,FSL_IMX31_EPIT2_IRQ }, + }; + + s->epit[i].ccm =DEVICE (&s->ccm); + +object_property_set_bool (OBJECT (&s->epit[i]), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + +sysbus_mmio_map (SYS_BUS_DEVICE (&s->epit[i]),0 , epit_table[i].addr); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->epit[i]),0 , +qdev_get_gpio_in (DEVICE (&s->avic), + epit_table[i].irq)); + } + +/* On a real system, the first 16k is a `secure boot rom' */ +memory_region_init_rom_device (&s->secure_rom,NULL ,NULL ,NULL , +"imx31.secure_rom" , +FSL_IMX31_SECURE_ROM_SIZE , &err); +memory_region_add_subregion (get_system_memory (),FSL_IMX31_SECURE_ROM_ADDR , + &s->secure_rom); + +/* There is also a 16k ROM */ +memory_region_init_rom_device (&s->rom,NULL ,NULL ,NULL ,"imx31.rom" , +FSL_IMX31_ROM_SIZE , &err); +memory_region_add_subregion (get_system_memory (),FSL_IMX31_ROM_ADDR , + &s->rom); + +/* initialize internal RAM (16 KB) */ +memory_region_allocate_system_memory (&s->iram,NULL ,"imx31.iram" , +FSL_IMX31_IRAM_SIZE ); +memory_region_add_subregion (get_system_memory (),FSL_IMX31_IRAM_ADDR , + &s->iram); + +/* internal RAM (16 KB) is aliased over 256 MB - 16 KB */ +memory_region_init_alias (&s->iram_alias,NULL ,"imx31.iram_alias" , + &s->iram,0 ,FSL_IMX31_IRAM_ALIAS_SIZE ); +memory_region_add_subregion (get_system_memory (),FSL_IMX31_IRAM_ALIAS_ADDR , + &s->iram_alias); +} + +static void fsl_imx31_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = fsl_imx31_realize; +} + +static const TypeInfo fsl_imx31_type_info = { + .name =TYPE_FSL_IMX31 , + .parent =TYPE_DEVICE , + .instance_size =sizeof (FslIMX31State), + .instance_init = fsl_imx31_init, + .class_init = fsl_imx31_class_init, +}; + +static void fsl_imx31_register_types (void ) +{ +type_register_static (&fsl_imx31_type_info); +} + +type_init (fsl_imx31_register_types)include/hw/arm/fsl-imx31.h new file +98
-1@@ -0,0 +1,98 @@ +/* +* Freescale i.MX31 SoC emulation +* +* Copyright (C) 2015 Jean-Christophe Dubois <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +*/ + +#ifndef FSL_IMX31_H +#define FSL_IMX31_H + +#include "hw/arm/arm.h" +#include "hw/intc/imx_avic.h" +#include "hw/misc/imx_ccm.h" +#include "hw/char/imx_serial.h" +#include "hw/timer/imx_gpt.h" +#include "hw/timer/imx_epit.h" +#include "exec/memory.h" + +#define TYPE_FSL_IMX31 "fsl,imx31" +#define FSL_IMX31 (obj) OBJECT_CHECK(FslIMX31State, (obj), TYPE_FSL_IMX31) + +#define FSL_IMX31_NUM_UARTS 2 +#define FSL_IMX31_NUM_EPITS 2 + +typedef struct FslIMX31State { +/*< private >*/ +DeviceState parent_obj; + +/*< public >*/ +ARMCPU cpu; +IMXAVICState avic; +IMXCCMState ccm; +IMXSerialState uart[FSL_IMX31_NUM_UARTS ]; +IMXGPTState gpt; +IMXEPITState epit[FSL_IMX31_NUM_EPITS ]; +MemoryRegion secure_rom; +MemoryRegion rom; +MemoryRegion iram; +MemoryRegion iram_alias; +}FslIMX31State ; + +#define FSL_IMX31_SECURE_ROM_ADDR 0x00000000 +#define FSL_IMX31_SECURE_ROM_SIZE 0x4000 +#define FSL_IMX31_ROM_ADDR 0x00404000 +#define FSL_IMX31_ROM_SIZE 0x4000 +#define FSL_IMX31_IRAM_ALIAS_ADDR 0x10000000 +#define FSL_IMX31_IRAM_ALIAS_SIZE 0xFFC0000 +#define FSL_IMX31_IRAM_ADDR 0x1FFFC000 +#define FSL_IMX31_IRAM_SIZE 0x4000 +#define FSL_IMX31_UART1_ADDR 0x43F90000 +#define FSL_IMX31_UART1_SIZE 0x4000 +#define FSL_IMX31_UART2_ADDR 0x43F94000 +#define FSL_IMX31_UART2_SIZE 0x4000 +#define FSL_IMX31_CCM_ADDR 0x53F80000 +#define FSL_IMX31_CCM_SIZE 0x4000 +#define FSL_IMX31_GPT_ADDR 0x53F90000 +#define FSL_IMX31_GPT_SIZE 0x4000 +#define FSL_IMX31_EPIT1_ADDR 0x53F94000 +#define FSL_IMX31_EPIT1_SIZE 0x4000 +#define FSL_IMX31_EPIT2_ADDR 0x53F98000 +#define FSL_IMX31_EPIT2_SIZE 0x4000 +#define FSL_IMX31_AVIC_ADDR 0x68000000 +#define FSL_IMX31_AVIC_SIZE 0x100 +#define FSL_IMX31_SDRAM0_ADDR 0x80000000 +#define FSL_IMX31_SDRAM0_SIZE 0x10000000 +#define FSL_IMX31_SDRAM1_ADDR 0x90000000 +#define FSL_IMX31_SDRAM1_SIZE 0x10000000 +#define FSL_IMX31_FLASH0_ADDR 0xA0000000 +#define FSL_IMX31_FLASH0_SIZE 0x8000000 +#define FSL_IMX31_FLASH1_ADDR 0xA8000000 +#define FSL_IMX31_FLASH1_SIZE 0x8000000 +#define FSL_IMX31_CS2_ADDR 0xB0000000 +#define FSL_IMX31_CS2_SIZE 0x2000000 +#define FSL_IMX31_CS3_ADDR 0xB2000000 +#define FSL_IMX31_CS3_SIZE 0x2000000 +#define FSL_IMX31_CS4_ADDR 0xB4000000 +#define FSL_IMX31_CS4_SIZE 0x2000000 +#define FSL_IMX31_CS5_ADDR 0xB6000000 +#define FSL_IMX31_CS5_SIZE 0x2000000 +#define FSL_IMX31_NAND_ADDR 0xB8000000 +#define FSL_IMX31_NAND_SIZE 0x1000 + +#define FSL_IMX31_EPIT2_IRQ 27 +#define FSL_IMX31_EPIT1_IRQ 28 +#define FSL_IMX31_GPT_IRQ 29 +#define FSL_IMX31_UART2_IRQ 32 +#define FSL_IMX31_UART1_IRQ 45 + +#endif /* FSL_IMX31_H */ --2.1.4
PATCH v11 13/19 i.MX: KZM now uses the standalone i.MX31 SOC support
In reply to Jean-Christophe DuboisTested by booting a minimal Linux system on the emulated platform
---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* update KZM target to use new emulators
Changes since v8:
* update KZM to user i.MX31 SOC
* rework SDRAM memory initialisation
Changes since v9:
* remove all Qdev construction helper fucntions.
Changes since v10:
* use memory_region_allocate_system_memory()
* rework of memory initialization loop.
* remove all Qdev construction helper in device files.
hw/arm/Makefile.objs | 4 +- hw/arm/kzm.c | 206 +++++++++++++++++++++++++-------------------------- hw/char/imx_serial.c | 39 ---------- hw/timer/imx_epit.c | 11 --- hw/timer/imx_gpt.c | 11 --- include/hw/arm/imx.h | 26 ------- 6 files changed, 105 insertions(+), 192 deletions(-) delete mode 100644 include/hw/arm/imx.h
hw/arm/Makefile.objs +2 -2
@@ -1,6 +1,6 @@ obj-y += boot.o collie.o exynos4_boards.o gumstix.o highbank.o obj-$(CONFIG_DIGIC) += digic_boards.o -obj-y += integratorcp.o kzm.o mainstone.o musicpal.o nseries.o +obj-y += integratorcp.o mainstone.o musicpal.o nseries.o obj-y += omap_sx1.o palm.o realview.o spitz.o stellaris.o obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o obj-$(CONFIG_ACPI) += virt-acpi-build.o
@@ -13,4 +13,4 @@ obj-y += omap1.o omap2.o strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp.o xlnx-ep108.o -obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o +obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o
hw/arm/kzm.c +103 -103
234 lines not on this page · raw message
hw/char/imx_serial.c +0 -39
@@ -21,7 +21,6 @@#include "hw/char/imx_serial.h" #include "sysemu/sysemu.h" #include "sysemu/char.h" -#include "hw/arm/imx.h" //#define DEBUG_SERIAL 1 #ifdef DEBUG_SERIAL
@@ -333,44 +332,6 @@ static void imx_serial_init(Object *obj)sysbus_init_irq (sbd, &s->irq); } -void imx_serial_create (int uart,const hwaddr addr,qemu_irq irq) -{ -DeviceState *dev; - - dev =qdev_create (NULL ,TYPE_IMX_SERIAL ); - -if (dev) { -SysBusDevice *bus; - -if (uart <MAX_SERIAL_PORTS ) { -CharDriverState *chr; - - chr = serial_hds[uart]; - -if (!chr) { -char label[20 ]; -snprintf (label,sizeof (label),"imx.uart%d" , uart); - chr =qemu_chr_new (label,"null" ,NULL ); -if (!(chr)) { -hw_error ("Can't assign serial port to %s.\n" , label); - } - } - -qdev_prop_set_chr (dev,"chardev" , chr); - } - - bus =SYS_BUS_DEVICE (dev); - -qdev_init_nofail (dev); - -if (addr != (hwaddr)-1 ) { -sysbus_mmio_map (bus,0 , addr); - } - -sysbus_connect_irq (bus,0 , irq); - } -} -static Property imx_serial_properties[] = {DEFINE_PROP_CHR ("chardev" , IMXSerialState, chr),DEFINE_PROP_END_OF_LIST (),
hw/timer/imx_epit.c +0 -11
@@ -12,7 +12,6 @@* */ -#include "hw/arm/imx.h" #include "hw/timer/imx_epit.h" #include "hw/misc/imx_ccm.h" #include "qemu/main-loop.h"
@@ -287,16 +286,6 @@ static void imx_epit_cmp(void *opaque)imx_epit_update_int (s); } -void imx_timerp_create (const hwaddr addr,qemu_irq irq,DeviceState *ccm) -{ -IMXEPITState *pp; -DeviceState *dev; - - dev =sysbus_create_simple (TYPE_IMX_EPIT , addr, irq); - pp =IMX_EPIT (dev); - pp->ccm = ccm; -} -static const MemoryRegionOps imx_epit_ops = { .read = imx_epit_read, .write = imx_epit_write,
hw/timer/imx_gpt.c +0 -11
@@ -12,7 +12,6 @@* */ -#include "hw/arm/imx.h" #include "hw/timer/imx_gpt.h" #include "hw/misc/imx_ccm.h" #include "qemu/main-loop.h"
@@ -449,16 +448,6 @@ static void imx_gpt_realize(DeviceState *dev, Error **errp) s->timer =ptimer_init (bh); } -void imx_timerg_create (const hwaddr addr,qemu_irq irq,DeviceState *ccm) -{ -IMXGPTState *pp; -DeviceState *dev; - - dev =sysbus_create_simple (TYPE_IMX_GPT , addr, irq); - pp =IMX_GPT (dev); - pp->ccm = ccm; -} -static void imx_gpt_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
include/hw/arm/imx.h deleted +0 -26
@@ -1,26 +0,0 @@ -/* -* i.MX31 emulation -* -* Copyright (C) 2012 Peter Chubb -* NICTA -* -* This code is released under the GPL, version 2.0 or later -* See the file `../COPYING' for details. -*/ - -#ifndef IMX_H -#define IMX_H - -#include "hw/misc/imx_ccm.h" - -void imx_serial_create (int uart,const hwaddr addr,qemu_irq irq); - -void imx_timerp_create (const hwaddr addr, -qemu_irq irq, -DeviceState *ccm); -void imx_timerg_create (const hwaddr addr, -qemu_irq irq, -DeviceState *ccm); - - -#endif /* IMX_H */
Signature · 1 line
2.1.4
PATCH v11 14/19 i.MX: Add I2C controller emulator
In reply to Jean-Christophe DuboisThe slave mode is not implemented.
---
Changes since v1:
* none
Changes since v2:
* use QOM cast
* reworked debug printf
* use CamelCase for state type
* warn with qemu_log_mask(LOG_GUEST_ERROR) or qemu_log_mask(LOG_UNIMP)
* move to dma_memory_read/write API
* rework interrupt handling
* use qemu_flush_queued_packets() in rx_enable()
Changes since v3:
* use realise for device initialization
* More QOM cast
* reworked debug printf some more
* standardise GPL header
* use CamelCase for buffer descriptor type
Changes since v4:
* none
Changes since v5:
* replace hw_error() with qemu_log_mask(LOG_GUEST_ERROR, ...)
* remove reformating of imx.h header file.
* remove unnecessary spaces.
Changes since v6:
* port to new memory API
Change since v7:
* refactor emulator to be used by SOC
Changes since v8:
* no change
Changes since v9:
* no change
Changes since v10:
* no change.
default-configs/arm-softmmu.mak | 2 + hw/i2c/Makefile.objs | 1 + hw/i2c/imx_i2c.c | 339 ++++++++++++++++++++++++++++++++++++++++ include/hw/i2c/imx_i2c.h | 85 ++++++++++ 4 files changed, 427 insertions(+) create mode 100644 hw/i2c/imx_i2c.c create mode 100644 include/hw/i2c/imx_i2c.h
default-configs/arm-softmmu.mak +2 -0
@@ -100,6 +100,8 @@ CONFIG_ALLWINNER_A10=y CONFIG_FSL_IMX31=y +CONFIG_IMX_I2C=y + CONFIG_XIO3130=y CONFIG_IOH3420=y CONFIG_I82801B11=y
hw/i2c/Makefile.objs +1 -0
@@ -4,4 +4,5 @@ common-obj-$(CONFIG_ACPI_X86) += smbus_ich9.o common-obj-$(CONFIG_APM) += pm_smbus.o common-obj-$(CONFIG_BITBANG_I2C) += bitbang_i2c.o common-obj-$(CONFIG_EXYNOS4) += exynos4210_i2c.o +common-obj-$(CONFIG_IMX_I2C) += imx_i2c.o obj-$(CONFIG_OMAP) += omap_i2c.o
hw/i2c/imx_i2c.c new file +339 -0
339 lines not on this page · raw message
include/hw/i2c/imx_i2c.h new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v11 15/19 i.MX: Add FEC Ethernet Emulator
In reply to Jean-Christophe DuboisThis is based on mcf_fec.c FEC implementation for Coldfire
* A generic PHY was added (borrowwed from LAN9118)
* The buffer management is also modified as buffers are slightly different between Coldfire and i.MX
---
Changes since v1:
* none
Changes since v2:
* use QOM cast
* reworked debug printf
* use CamelCase for state type
* warn with qemu_log_mask(LOG_GUEST_ERROR) or qemu_log_mask(LOG_UNIMP)
* move to dma_memory_read/write API
* rework interrupt handling
* use qemu_flush_queued_packets() in rx_enable()
Changes since v3:
* use realise for device initialization
* More QOM cast
* reworked debug printf some more
* standardise GPL header
* use CamelCase for buffer descriptor type
Changes since v4:
* none
Changes since v5:
* replace hw_error() with qemu_log_mask(LOG_GUEST_ERROR, ...)
* remove reformating of imx.h header file.
* remove unnecessary spaces.
Changes since v6:
* port to new memory API
Changes since v7:
* refactor to be used by SOC
Changes since v8:
* no change
Changes since v9:
* no change
Changes since v10:
* no change
default-configs/arm-softmmu.mak | 1 + hw/net/Makefile.objs | 1 + hw/net/imx_fec.c | 709 ++++++++++++++++++++++++++++++++++++++++ include/hw/net/imx_fec.h | 113 +++++++ 4 files changed, 824 insertions(+) create mode 100644 hw/net/imx_fec.c create mode 100644 include/hw/net/imx_fec.h
default-configs/arm-softmmu.mak +1 -0
@@ -28,6 +28,7 @@ CONFIG_SSI_M25P80=y CONFIG_LAN9118=y CONFIG_SMC91C111=y CONFIG_ALLWINNER_EMAC=y +CONFIG_IMX_FEC=y CONFIG_DS1338=y CONFIG_PFLASH_CFI01=y CONFIG_PFLASH_CFI02=y
hw/net/Makefile.objs +1 -0
@@ -19,6 +19,7 @@ common-obj-$(CONFIG_XGMAC) += xgmac.o common-obj-$(CONFIG_MIPSNET) += mipsnet.o common-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.o common-obj-$(CONFIG_ALLWINNER_EMAC) += allwinner_emac.o +common-obj-$(CONFIG_IMX_FEC) += imx_fec.o common-obj-$(CONFIG_CADENCE) += cadence_gem.o common-obj-$(CONFIG_STELLARIS_ENET) += stellaris_enet.o
hw/net/imx_fec.c new file +709 -0
709 lines not on this page · raw message
include/hw/net/imx_fec.h new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v11 16/19 i.MX: Add SOC support for i.MX25
In reply to Jean-Christophe Dubois For now we support the following devices:
* CPU: ARM926
* Interrupt Controller: AVIC
* CCM
* UART x 5
* EPIT x 2
* GPT x 4
* FEC
* I2C x 3
---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* Added a SOC specific file for i.MX25
Changes since v8:
* use defines instead of hardcoded values for IRQ and ADDR
* reworked the memory allocation for SOC memory
Changes since v9:
* no change
Changes since v10:
* added deescription of supported devices
* rework of UART init to use chardev property
* use memory_region_allocate_system_memory()
* Fix coding style.
default-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/fsl-imx25.c | 260 ++++++++++++++++++++++++++++++++++++++++ include/hw/arm/fsl-imx25.h | 234 ++++++++++++++++++++++++++++++++++++ 4 files changed, 496 insertions(+) create mode 100644 hw/arm/fsl-imx25.c create mode 100644 include/hw/arm/fsl-imx25.h
default-configs/arm-softmmu.mak +1 -0
@@ -100,6 +100,7 @@ CONFIG_ALLWINNER_A10_PIC=y CONFIG_ALLWINNER_A10=y CONFIG_FSL_IMX31=y +CONFIG_FSL_IMX25=y CONFIG_IMX_I2C=y
hw/arm/Makefile.objs +1 -0
@@ -13,4 +13,5 @@ obj-y += omap1.o omap2.o strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp.o xlnx-ep108.o +obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o
hw/arm/fsl-imx25.c new file +260 -0
260 lines not on this page · raw message
include/hw/arm/fsl-imx25.h new file +234 -0
234 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v11 17/19 i.MX: Add the i.MX25 PDK plateform
In reply to Jean-Christophe DuboisTested by booting a minimal Linux system on the emulated platform Tested by booting the Xvisor hyprvisor on the emulated platform
---
Changes since v1:
* Added a ds1338 I2C device for qtest purpose.
Changes since v2:
* none
Changes since v3:
* Rework GPL header
* use I2C constructor helper.
Changes since v4:
* use sysbus_create_simple() instead of I2C constructor helper
Changes since v5:
* Add ds1338 only for qtest mode.
* small comment fixes.
Changes since v6:
* Allow for more than 4 serial if suppoted by Qemu.
Changes since v7:
* Move the SOC part into its own file.
Changes since v8:
* rework SDRAM memory initialisation
Changes since v9:
* no change
Changes since v10:
* rename board from 3DS to PDK
* use memory_region_allocate_system_memory()
* rework of memory initialization loop.
hw/arm/Makefile.objs | 2 +- hw/arm/imx25_pdk.c | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 hw/arm/imx25_pdk.c
hw/arm/Makefile.objs +1 -1
@@ -13,5 +13,5 @@ obj-y += omap1.o omap2.o strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp.o xlnx-ep108.o -obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o +obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o
hw/arm/imx25_pdk.c new file +162 -0
162 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v11 18/19 i.MX: Add qtest support for I2C device emulator.
In reply to Jean-Christophe DuboisThis is using a ds1338 RTC chip on the I2C bus. This RTC chip is not present on the real 3DS PDK board.
---
Changes since v1:
* not present on v1
Changes since v2:
* use a common header file for I2C regs definition
Changes since v3:
* rework GPL headers.
Changes since v4:
* none
Changes since v5:
* none
Changes since v6:
* none
Changes since v7:
* adapt to new i.MX I2C header file.
Changes since v8:
* no change
Changes since v9:
* no change
Changes since v10:
* no change
tests/Makefile | 3 + tests/ds1338-test.c | 75 ++++++++++++++++++ tests/libqos/i2c-imx.c | 209 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/i2c.h | 3 + 4 files changed, 290 insertions(+) create mode 100644 tests/ds1338-test.c create mode 100644 tests/libqos/i2c-imx.c
tests/Makefile +3 -0
@@ -193,6 +193,7 @@ check-qtest-sparc64-y = tests/endianness-test$(EXESUF) gcov-files-sparc-y += hw/timer/m48t59.c gcov-files-sparc64-y += hw/timer/m48t59.c check-qtest-arm-y = tests/tmp105-test$(EXESUF) +check-qtest-arm-y = tests/ds1338-test$(EXESUF) gcov-files-arm-y += hw/misc/tmp105.c check-qtest-arm-y += tests/virtio-blk-test$(EXESUF) gcov-files-arm-y += arm-softmmu/hw/block/virtio-blk.c
@@ -342,6 +343,7 @@ libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o libqos-pc-obj-y += tests/libqos/malloc-pc.o tests/libqos/libqos-pc.o libqos-pc-obj-y += tests/libqos/ahci.o libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o +libqos-imx-obj-y = $(libqos-obj-y) tests/libqos/i2c-imx.o libqos-usb-obj-y = $(libqos-pc-obj-y) tests/libqos/usb.o libqos-virtio-obj-y = $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o tests/libqos/malloc-generic.o
@@ -356,6 +358,7 @@ tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y) tests/bios-tables-test$(EXESUF): tests/bios-tables-test.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/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) tests/q35-test$(EXESUF): tests/q35-test.o $(libqos-pc-obj-y) tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y)
tests/ds1338-test.c new file +75 -0
75 lines not on this page · raw message
tests/libqos/i2c-imx.c new file +209 -0
209 lines not on this page · raw message
tests/libqos/i2c.h +3 -0
@@ -27,4 +27,7 @@ void i2c_recv(I2CAdapter *i2c, uint8_t addr,/* libi2c-omap.c */ I2CAdapter *omap_i2c_create (uint64_t addr); +/* libi2c-imx.c */ +I2CAdapter *imx_i2c_create (uint64_t addr); +#endif
Signature · 1 line
2.1.4
PATCH v11 19/19 i.MX: Adding i2C devices to i.MX31 SOC
In reply to Jean-Christophe Dubois---
Changes since v1:
* not present on v1
Changes since v2:
* not present on v2
Changes since v3:
* not present on v3
Changes since v4:
* not present on v4
Changes since v5:
* not present on v5
Changes since v6:
* not present on v6
Changes since v7:
* not present on v7
Changes since v8:
* not present on v8
Changes since v9:
* Added 3 I2C devices to i.MX31 SOC
Changes since v10:
* no change.
hw/arm/fsl-imx31.c | 30 ++++++++++++++++++++++++++++++ include/hw/arm/fsl-imx31.h | 12 ++++++++++++ 2 files changed, 42 insertions(+)
hw/arm/fsl-imx31.c +30 -0
@@ -50,6 +50,11 @@ static void fsl_imx31_init(Object *obj)object_initialize (&s->epit[i],sizeof (s->epit[i]),TYPE_IMX_EPIT );qdev_set_parent_bus (DEVICE (&s->epit[i]),sysbus_get_default ()); } + +for (i =0 ; i <FSL_IMX31_NUM_I2CS ; i++) { +object_initialize (&s->i2c[i],sizeof (s->i2c[i]),TYPE_IMX_I2C ); +qdev_set_parent_bus (DEVICE (&s->i2c[i]),sysbus_get_default ()); + } }static void fsl_imx31_realize (DeviceState *dev,Error **errp)
@@ -154,6 +159,31 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp) epit_table[i].irq)); } +/* Initialize all I2C */ +for (i =0 ; i <FSL_IMX31_NUM_I2CS ; i++) { +static const struct { +hwaddr addr; +unsigned int irq; + } i2c_table[FSL_IMX31_NUM_I2CS ] = { + {FSL_IMX31_I2C1_ADDR ,FSL_IMX31_I2C1_IRQ }, + {FSL_IMX31_I2C2_ADDR ,FSL_IMX31_I2C2_IRQ }, + {FSL_IMX31_I2C3_ADDR ,FSL_IMX31_I2C3_IRQ } + }; + +/* Initialize the I2C */ +object_property_set_bool (OBJECT (&s->i2c[i]), true,"realized" , &err); +if (err) { +error_propagate ((errp), (err)); +return ; + } +/* Map I2C memory */ +sysbus_mmio_map (SYS_BUS_DEVICE (&s->i2c[i]),0 , i2c_table[i].addr); +/* Connet I2C IRQ to PIC */ +sysbus_connect_irq (SYS_BUS_DEVICE (&s->i2c[i]),0 , +qdev_get_gpio_in (DEVICE (&s->avic), + i2c_table[i].irq)); + } +/* On a real system, the first 16k is a `secure boot rom' */ memory_region_init_rom_device(&s->secure_rom, NULL, NULL, NULL, "imx31.secure_rom",
include/hw/arm/fsl-imx31.h +12 -0
@@ -23,6 +23,7 @@#include "hw/char/imx_serial.h" #include "hw/timer/imx_gpt.h" #include "hw/timer/imx_epit.h" +#include "hw/i2c/imx_i2c.h" #include "exec/memory.h" #define TYPE_FSL_IMX31 "fsl,imx31"
@@ -30,6 +31,7 @@#define FSL_IMX31_NUM_UARTS 2#define FSL_IMX31_NUM_EPITS 2 +#define FSL_IMX31_NUM_I2CS 3 typedef struct FslIMX31State{ /*< private >*/
@@ -42,6 +44,7 @@ typedef struct FslIMX31State{IMXSerialState uart[FSL_IMX31_NUM_UARTS ];IMXGPTState gpt;IMXEPITState epit[FSL_IMX31_NUM_EPITS ]; +IMXI2CState i2c[FSL_IMX31_NUM_I2CS ];MemoryRegion secure_rom;MemoryRegion rom;MemoryRegion iram;
@@ -56,10 +59,16 @@ typedef struct FslIMX31State{#define FSL_IMX31_IRAM_ALIAS_SIZE 0xFFC0000#define FSL_IMX31_IRAM_ADDR 0x1FFFC000#define FSL_IMX31_IRAM_SIZE 0x4000 +#define FSL_IMX31_I2C1_ADDR 0x43F80000 +#define FSL_IMX31_I2C1_SIZE 0x4000 +#define FSL_IMX31_I2C3_ADDR 0x43F84000 +#define FSL_IMX31_I2C3_SIZE 0x4000#define FSL_IMX31_UART1_ADDR 0x43F90000#define FSL_IMX31_UART1_SIZE 0x4000#define FSL_IMX31_UART2_ADDR 0x43F94000#define FSL_IMX31_UART2_SIZE 0x4000 +#define FSL_IMX31_I2C2_ADDR 0x43F98000 +#define FSL_IMX31_I2C2_SIZE 0x4000#define FSL_IMX31_CCM_ADDR 0x53F80000#define FSL_IMX31_CCM_SIZE 0x4000#define FSL_IMX31_GPT_ADDR 0x53F90000
@@ -94,5 +103,8 @@ typedef struct FslIMX31State{#define FSL_IMX31_GPT_IRQ 29#define FSL_IMX31_UART2_IRQ 32#define FSL_IMX31_UART1_IRQ 45 +#define FSL_IMX31_I2C1_IRQ 10 +#define FSL_IMX31_I2C2_IRQ 4 +#define FSL_IMX31_I2C3_IRQ 3#endif /* FSL_IMX31_H */
Signature · 1 line
2.1.4