various ARM fixes
v4 cover various ARM fixes
This is a collection of fixes and additions to the models for various ARM devices. These changes are needed to support the forthcoming Calxeda Highbank SoC model.
Makefile.target | 2 + hw/a9mpcore.c | 43 +++++- hw/arm11mpcore.c | 14 +- hw/arm_gic.c | 63 +++++--- hw/arm_l2x0.c | 183 ++++++++++++++++++++++ hw/arm_timer.c | 24 +++- hw/armv7m_nvic.c | 7 +- hw/realview_gic.c | 3 +- hw/xgmac.c | 424 +++++++++++++++++++++++++++++++++++++++++++++++++++ target-arm/cpu.h | 1 + target-arm/helper.c | 14 ++ 11 files changed, 730 insertions(+), 48 deletions(-)
PATCH v4 1/7 arm: add missing scu registers
From: Rob Herring <[email protected]>
Add power control register to a9mpcore
---
Changes from v3
None
Changes from v2:
Better handling of byte and halfword writes to the power register Correct handling of VMState versions
Improved commit message
Changes from v1:
Added VMState support
Checked alignment of writes to the power control register
hw/a9mpcore.c | 36 +++++++++++++++++++++++++++++++++--- 1 files changed, 33 insertions(+), 3 deletions(-)
hw/a9mpcore.c +33 -3
@@ -29,6 +29,7 @@ gic_get_current_cpu(void) typedef struct a9mp_priv_state { gic_state gic; uint32_t scu_control; + uint32_t scu_status; uint32_t old_timer_status[8]; uint32_t num_cpu; qemu_irq *timer_irq;
@@ -48,7 +49,13 @@ static uint64_t a9_scu_read(void *opaque, target_phys_addr_t offset,case 0x04 :/* Configuration */ return (((1 << s->num_cpu) -1 ) <<4 ) | (s->num_cpu -1 );case 0x08 :/* CPU Power Status */ -return 0 ; +return s->scu_status; +case 0x09 :/* CPU status. */ +return s->scu_status >>8 ; +case 0x0a :/* CPU status. */ +return s->scu_status >>16 ; +case 0x0b :/* CPU status. */ +return s->scu_status >>24 ;case 0x0c :/* Invalidate All Registers In Secure State */ return 0 ;case 0x40 :/* Filtering Start Address Register */
@@ -67,12 +74,35 @@ static void a9_scu_write(void *opaque, target_phys_addr_t offset, uint64_t value, unsigned size) {a9mp_priv_state *s = (a9mp_priv_state *)opaque; +uint32_t mask; +uint32_t shift; +switch (size) { +case 1 : + mask =0xff ; +break ; +case 2 : + mask =0xffff ; +break ; +case 4 : + mask =0xffffffff ; +break ; +default : +fprintf (stderr,"Invalid size %u in write to a9 scu register %x\n" , + size, offset); +return ; + } +switch (offset) {case 0x00 :/* Control */ s->scu_control = value &1 ;break ;case 0x4 :/* Configuration: RO */ break ; +case 0x08 :case 0x09 :case 0x0A :case 0x0B :/* Power Control */ + shift = (offset -0x8 ) *8 ; + s->scu_status &= ~(mask << shift); + s->scu_status |= ((value & mask) << shift); +break ;case 0x0c :/* Invalidate All Registers In Secure State */ /* no-op as we do not implement caches */ break ;
@@ -80,7 +110,6 @@ static void a9_scu_write(void *opaque, target_phys_addr_t offset,case 0x44 :/* Filtering End Address Register */ /* RAZ/WI, like an implementation with only one AXI master */ break ; -case 0x8 :/* CPU Power Status */ case 0x50 :/* SCU Access Control Register */ case 0x54 :/* SCU Non-secure Access Control Register */ /* unimplemented, fall through */
@@ -169,11 +198,12 @@ static int a9mp_priv_init(SysBusDevice *dev)static const VMStateDescription vmstate_a9mp_priv = { .name ="a9mpcore_priv" , - .version_id =1 , + .version_id =2 , .minimum_version_id =1 , .fields = (VMStateField []) {VMSTATE_UINT32 (scu_control, a9mp_priv_state),VMSTATE_UINT32_ARRAY (old_timer_status, a9mp_priv_state,8 ), +VMSTATE_UINT32_V (scu_status, a9mp_priv_state,2 ),VMSTATE_END_OF_LIST () } };
Signature · 1 line
1.7.5.4
PATCH v4 4/7 arm: add dummy gic security registers
In reply to Mark LangsdorfFrom: Rob Herring <[email protected]>
Implement handling for the RAZ/WI gic security registers.
---
Changes from v2, v3
None
Changes from v1
Moved handling back inside the 0-0x100 block Added more clarifying comments
hw/arm_gic.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
hw/arm_gic.c +6 -0
@@ -282,6 +282,10 @@ static uint32_t gic_dist_readb(void *opaque, target_phys_addr_t offset)return ((GIC_NIRQ /32 ) -1 ) | ((NUM_CPU (s) -1 ) <<5 );if (offset <0x08 )return 0 ; +if (offset >=0x80 ) { +/* Interrupt Security , RAZ/WI */ +return 0 ; + }#endif goto bad_reg; }else if (offset <0x200 ) {
@@ -413,6 +417,8 @@ static void gic_dist_writeb(void *opaque, target_phys_addr_t offset,DPRINTF ("Distribution %sabled\n" , s->enabled ?"En" :"Dis" ); }else if (offset <4 ) {/* ignored. */ + }else if (offset >=0x80 ) { +/* Interrupt Security Registers, RAZ/WI */ }else { goto bad_reg; }
Signature · 1 line
1.7.5.4
PATCH v4 3/7 arm: add dummy v7 cp15 config_base_register
In reply to Mark LangsdorfAdd a cp15 config_base_register that currently defaults to 0. After the QOM CPU support is added, the value will be properly set to the periphal base value.
---
Changes from v3
None
Changes from v2
Added test against op2
Changes from v1
renamed the register
added comments about how it will change when QOM CPUs are added
target-arm/cpu.h | 1 + target-arm/helper.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 0 deletions(-)
target-arm/cpu.h +1 -0
@@ -149,6 +149,7 @@ typedef struct CPUARMState {uint32_t c15_i_max;/* Maximum D-cache dirty line index. */ uint32_t c15_i_min;/* Minimum D-cache dirty line index. */ uint32_t c15_threadid;/* TI debugger thread-ID. */ +uint32_t c15_config_base_address;/* SCU base address. */ } cp15;struct {
target-arm/helper.c +14 -0
@@ -2111,6 +2111,20 @@ uint32_t HELPER(get_cp15)(CPUState *env, uint32_t insn)* 0x200 << ($rn & 0xfff), when MMU is off. */ goto bad_reg; } +if (ARM_CPUID (env) ==ARM_CPUID_CORTEXA9 ) { +switch (crm) { +case 0 : +/* The config_base_address should hold the value of +* the peripheral base. ARM should get this from a CPU +* object property, but that support isn't available in +* December 2011. Default to 0 for now and board models +* that care can set it by a private hook */ +if ((op1 ==4 ) && (op2 ==0 )) { +return env->cp15.c15_config_base_address; + } + } + goto bad_reg; + }return 0 ; } bad_reg:
Signature · 1 line
1.7.5.4
PATCH v4 5/7 add L2x0/PL310 cache controller device
In reply to Mark LangsdorfFrom: Rob Herring <[email protected]>
This is just a dummy device for ARM L2 cache controllers, based on the pl310. The cache type parameter can be defined by a property value and has a meaningful default.
---
Changes from v3
Changed default value
Adding tracking of cache_type bits from aux_control
Changes from v2
Reformatted a couple of function definitions to be 80 lines long
Changes from v1
Corrected formatting
Clarified the copyrights
Clarified GPL revision
Clarified model version
Removed hw_error() calls
Added a reset function
Restructed everything as switch/case statements Added a type cache property
Makefile.target | 1 + hw/arm_l2x0.c | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+), 0 deletions(-) create mode 100644 hw/arm_l2x0.c
Makefile.target +1 -0
@@ -336,6 +336,7 @@ obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.o obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o +obj-arm-y += arm_l2x0.o obj-arm-y += arm_mptimer.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o
hw/arm_l2x0.c new file +183 -0
183 lines not on this page · raw message
Signature · 1 line
1.7.5.4
PATCH v4 2/7 arm: Set frequencies for arm_timer
In reply to Mark LangsdorfUse qdev properties to allow board modelers to set the frequencies for the sp804 timer. Each of the sp804's timers can have an individual frequency. The timers default to 1MHz.
---
Changes from v3
None
Changes from v2
Comment correctly describes behavior of properties freqX variables are defined as uint32_t, not int
Changes from v1
Simplified multiple timer frequency handling Removed the shared default
hw/arm_timer.c | 24 +++++++++++++++++++----- 1 files changed, 19 insertions(+), 5 deletions(-)
hw/arm_timer.c +19 -5
@@ -9,6 +9,8 @@#include "sysbus.h" #include "qemu-timer.h" +#include "qemu-common.h" +#include "qdev.h" /* Common timer implementation. */
@@ -178,6 +180,7 @@ typedef struct {SysBusDevice busdev;MemoryRegion iomem;arm_timer_state *timer[2 ]; +uint32_t freq0, freq1;int level[2 ];qemu_irq irq; } sp804_state;
@@ -269,10 +272,11 @@ static int sp804_init(SysBusDevice *dev) qi =qemu_allocate_irqs (sp804_set_irq, s,2 );sysbus_init_irq (dev, &s->irq); -/* ??? The timers are actually configurable between 32kHz and 1MHz, but -we don't implement that. */ - s->timer[0 ] =arm_timer_init (1000000 ); - s->timer[1 ] =arm_timer_init (1000000 ); +/* The timers are configurable between 32kHz and 1MHz +* defaulting to 1MHz but overrideable as individual properties */ + s->timer[0 ] =arm_timer_init (s->freq0); + s->timer[1 ] =arm_timer_init (s->freq1); + s->timer[0 ]->irq = qi[0 ]; s->timer[1 ]->irq = qi[1 ];memory_region_init_io (&s->iomem, &sp804_ops, s,"sp804" ,0x1000 );
@@ -281,6 +285,16 @@ static int sp804_init(SysBusDevice *dev)return 0 ; } +static SysBusDeviceInfo sp804_info = { + .init = sp804_init, + .qdev.name ="sp804" , + .qdev.size =sizeof (sp804_state), + .qdev.props = (Property []) { +DEFINE_PROP_UINT32 ("freq0" , sp804_state, freq0,1000000 ), +DEFINE_PROP_UINT32 ("freq1" , sp804_state, freq1,1000000 ), +DEFINE_PROP_END_OF_LIST (), + } +};/* Integrator/CP timer module. */
@@ -349,7 +363,7 @@ static int icp_pit_init(SysBusDevice *dev)static void arm_timer_register_devices (void ) {sysbus_register_dev ("integrator_pit" ,sizeof (icp_pit_state), icp_pit_init); -sysbus_register_dev ("sp804" ,sizeof (sp804_state), sp804_init); +sysbus_register_withprop (&sp804_info); }device_init (arm_timer_register_devices)
Signature · 1 line
1.7.5.4
PATCH v4 6/7 Add xgmac ethernet model
In reply to Mark LangsdorfThis adds very basic support for XG-mac ethernet core from Synopsis and others. Missing things include:
- statistics counters
- WoL support
- rx checksum offload
- chained descriptors (only linear descriptor ring)
- broadcast and multicast handling
---
Changes from v3
Added debug macro and cleaned up some debug code Refitted all lines to fit within 80 columns
Changes from v2
None
Changes from v1
Reformated most lines to fit within 80 columns Removed a bunch of unused variables in the state structures Got rid of some camelcase structure names
Added vmstate support
Makefile.target | 1 + hw/xgmac.c | 424 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 425 insertions(+), 0 deletions(-) create mode 100644 hw/xgmac.c
Makefile.target +1 -0
@@ -340,6 +340,7 @@ obj-arm-y += arm_l2x0.o obj-arm-y += arm_mptimer.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o +obj-arm-y += xgmac.o obj-arm-y += arm-semi.o obj-arm-y += pxa2xx.o pxa2xx_pic.o pxa2xx_gpio.o pxa2xx_timer.o pxa2xx_dma.o obj-arm-y += pxa2xx_lcd.o pxa2xx_mmci.o pxa2xx_pcmcia.o pxa2xx_keypad.o
hw/xgmac.c new file +424 -0
424 lines not on this page · raw message
Signature · 1 line
1.7.5.4
PATCH v4 7/7 arm: make the number of GIC interrupts configurable
In reply to Mark LangsdorfIncrease the maximum number of GIC interrupts for a9mp and a11mp to 256, and create a configurable property for each defaulting to 96 and 64 (respectively) so that device modelers can set the value appropriately for their SoC. Other ARM processors also set their maximum number of used IRQs appropriately.
Set the maximum theoretically number of GIC interrupts to 1020 and update the save/restore code to only use the appropriate number for each SoC.
---
Changes from v3
Increase maximum number of GIC interrupts to 1020 Remove SoC/implementation specific GIC_NIRQ #defs Added properties code to arm11mp
Changed error handling for too many interrupts Redid save/load handling
Changes from v2
Skipped
Changes from v1
Increase the number of a9mp interrupts to 192 Add a property defaulting to 96
Add a num_irq member in the gic state structure Use the num_irq value as appropriate
Add num_irq argument to gic_init()
Add num_irq to various CPU calls to gic_init
hw/a9mpcore.c | 7 +++-- hw/arm11mpcore.c | 14 +++++++----- hw/arm_gic.c | 57 +++++++++++++++++++++++++++++----------------------- hw/armv7m_nvic.c | 7 ++--- hw/realview_gic.c | 3 +- 5 files changed, 48 insertions(+), 40 deletions(-)
hw/a9mpcore.c +4 -3
@@ -11,9 +11,8 @@#include "sysbus.h" /* Configuration for arm_gic.c: -* number of external IRQ lines, max number of CPUs, how to ID current CPU +* max number of CPUs, how to ID current CPU */ -#define GIC_NIRQ 96#define NCPU 4 static inline int
@@ -37,6 +36,7 @@ typedef struct a9mp_priv_state {MemoryRegion ptimer_iomem;MemoryRegion container;DeviceState *mptimer; +uint32_t num_irq; } a9mp_priv_state; static uint64_t a9_scu_read(void *opaque, target_phys_addr_t offset,
@@ -153,7 +153,7 @@ static int a9mp_priv_init(SysBusDevice *dev)hw_error ("a9mp_priv_init: num-cpu may not be more than %d\n" ,NCPU ); } -gic_init (&s->gic, s->num_cpu); +gic_init (&s->gic, s->num_cpu, s->num_irq); s->mptimer =qdev_create (NULL ,"arm_mptimer" );qdev_prop_set_uint32 (s->mptimer,"num-cpu" , s->num_cpu);
@@ -216,6 +216,7 @@ static SysBusDeviceInfo a9mp_priv_info = { .qdev.reset = a9mp_priv_reset, .qdev.props = (Property []) {DEFINE_PROP_UINT32 ("num-cpu" , a9mp_priv_state, num_cpu,1 ), +DEFINE_PROP_UINT32 ("num-irq" , a9mp_priv_state, num_irq,256 ),DEFINE_PROP_END_OF_LIST (), } };
hw/arm11mpcore.c +8 -6
@@ -10,11 +10,6 @@#include "sysbus.h" #include "qemu-timer.h" -/* ??? The MPCore TRM says the on-chip controller has 224 external IRQ lines -(+ 32 internal). However my test chip only exposes/reports 32. -More importantly Linux falls over if more than 32 are present! */ -#define GIC_NIRQ 64 -#define NCPU 4 static inline int
@@ -37,6 +32,7 @@ typedef struct mpcore_priv_state {MemoryRegion iomem;MemoryRegion container;DeviceState *mptimer; +uint32_t num_irq; } mpcore_priv_state;/* Per-CPU private memory mapped IO. */
@@ -132,7 +128,7 @@ static int mpcore_priv_init(SysBusDevice *dev) {mpcore_priv_state *s =FROM_SYSBUSGIC (mpcore_priv_state, dev); -gic_init (&s->gic, s->num_cpu); +gic_init (&s->gic, s->num_cpu,GIC_NIRQ ); s->mptimer =qdev_create (NULL ,"arm_mptimer" );qdev_prop_set_uint32 (s->mptimer,"num-cpu" , s->num_cpu);qdev_init_nofail (s->mptimer);
@@ -221,6 +217,12 @@ static SysBusDeviceInfo mpcore_priv_info = { .qdev.size = sizeof(mpcore_priv_state), .qdev.props = (Property []) {DEFINE_PROP_UINT32 ("num-cpu" , mpcore_priv_state, num_cpu,1 ), +/* The MPCore TRM says the on-chip controller has 224 external +* IRQ lines (+ 32 internal). Some test chips only +* expose/report 32. More importantly Linux falls over if more +* than 32 are present! Set the default to 64 and let chips +* with more working lines set it higher */ +DEFINE_PROP_UINT32 ("num-irq" , mpcore_priv_state, num_irq,64 ),DEFINE_PROP_END_OF_LIST (), } };
hw/arm_gic.c +32 -25
206 lines not on this page · raw message
hw/armv7m_nvic.c +3 -4
@@ -15,9 +15,6 @@#include "arm-misc.h" #include "exec-memory.h" -/* 32 internal lines (16 used for system exceptions) plus 64 external -interrupt lines. */ -#define GIC_NIRQ 96#define NCPU 1#define NVIC 1
@@ -384,7 +381,9 @@ static int armv7m_nvic_init(SysBusDevice *dev) {nvic_state *s=FROM_SYSBUSGIC (nvic_state, dev); -gic_init (&s->gic); +/* 32 internal lines (16 used for system exceptions) plus 64 external +* interrupt lines. */ +gic_init (&s->gic,96 );memory_region_add_subregion (get_system_memory (),0xe000e000 , &s->gic.iomem); s->systick.timer =qemu_new_timer_ns (vm_clock, systick_timer_tick, s);vmstate_register (&dev->qdev,-1 , &vmstate_nvic, s);
hw/realview_gic.c +1 -2
@@ -9,7 +9,6 @@#include "sysbus.h" -#define GIC_NIRQ 96#define NCPU 1/* Only a single "CPU" interface is present. */
@@ -37,7 +36,7 @@ static int realview_gic_init(SysBusDevice *dev) {RealViewGICState *s =FROM_SYSBUSGIC (RealViewGICState, dev); -gic_init (&s->gic); +gic_init (&s->gic,96 );realview_gic_map_setup (s);sysbus_init_mmio (dev, &s->container);return 0 ;
Signature · 1 line
1.7.5.4
Re: [Qemu-devel] [PATCH v4 5/7] add L2x0/PL310 cache controller device
In reply to Mark LangsdorfQuoted 7 lines · Mark Langsdorf
+ case
0x104:
+ /*aux_ctrlvalues affectcache_typevalues */
+ s->aux_ctrl = value;
+ cache_data = (value & (7 << 17)) >> 15;
+ cache_data |= (value & (1 << 16)) >> 16;
+ s->cache_type |= (cache_data<< 18) | (cache_data<< 6);
+ break;
If you do this this way round, then cache_type is no longer constant, and you need to reset it in reset and save/load it in the vmstate. It's probably simpler to fill in the bits from aux_ctrl when cache_type is read rather than when aux_ctrl is written. (It seems pretty safe to assume neither happens very frequently.)
-- PMM
Re: [Qemu-devel] [PATCH v4 2/7] arm: Set frequencies for arm_timer
In reply to Mark LangsdorfAm 28.12.2011 02:24, schrieb Mark Langsdorf:
Quoted 6 lines
Use qdev properties to allow board modelers to set the frequencies for the sp804 timer. Each of the sp804's timers can have an individual frequency. The timers default to 1MHz.
Signed-off-by Mark Langsdorf <[email protected]>Reviewed-by Peter Maydell <[email protected]>
Thanks,
Andreas
Quoted 76 lines
---
Changes from v3
None
Changes from v2
Comment correctly describes behavior of properties freqX variables are defined asuint32_t, not int
Changes from v1
Simplified multiple timer frequency handling Removed the shared defaulthw/arm_timer.c | 24 +++++++++++++++++++----- 1 files changed, 19 insertions(+), 5 deletions(-)hw/arm_timer.c +19
-5@@ -9,6 +9,8 @@#include "sysbus.h" #include "qemu-timer.h" +#include "qemu-common.h" +#include "qdev.h" /* Common timer implementation. */ @@ -178,6 +180,7 @@ typedef struct {SysBusDevice busdev;MemoryRegion iomem;arm_timer_state *timer[2 ]; +uint32_t freq0, freq1;int level[2 ];qemu_irq irq; } sp804_state;@@ -269,10 +272,11 @@ static int sp804_init(SysBusDevice *dev) qi =qemu_allocate_irqs (sp804_set_irq, s,2 );sysbus_init_irq (dev, &s->irq); -/* ??? The timers are actually configurable between 32kHz and 1MHz, but -we don't implement that. */ - s->timer[0 ] =arm_timer_init (1000000 ); - s->timer[1 ] =arm_timer_init (1000000 ); +/* The timers are configurable between 32kHz and 1MHz +* defaulting to 1MHz but overrideable as individual properties */ + s->timer[0 ] =arm_timer_init (s->freq0); + s->timer[1 ] =arm_timer_init (s->freq1); + s->timer[0 ]->irq = qi[0 ]; s->timer[1 ]->irq = qi[1 ];memory_region_init_io (&s->iomem, &sp804_ops, s,"sp804" ,0x1000 );@@ -281,6 +285,16 @@ static int sp804_init(SysBusDevice *dev)return 0 ; } +static SysBusDeviceInfo sp804_info = { + .init = sp804_init, + .qdev.name ="sp804" , + .qdev.size =sizeof (sp804_state), + .qdev.props = (Property []) { +DEFINE_PROP_UINT32 ("freq0" , sp804_state, freq0,1000000 ), +DEFINE_PROP_UINT32 ("freq1" , sp804_state, freq1,1000000 ), +DEFINE_PROP_END_OF_LIST (), + } +};/* Integrator/CP timer module. */ @@ -349,7 +363,7 @@ static int icp_pit_init(SysBusDevice *dev)static void arm_timer_register_devices (void ) {sysbus_register_dev ("integrator_pit" ,sizeof (icp_pit_state), icp_pit_init); -sysbus_register_dev ("sp804" ,sizeof (sp804_state), sp804_init); +sysbus_register_withprop (&sp804_info); }device_init (arm_timer_register_devices)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg