integrator: fix Linux boot failure by emulating dbg
PATCH 1/1 integrator: fix Linux boot failure by emulating dbg
From: Alex Bennée <[email protected]>
Commit 9b8c69243 broke the ability to boot the kernel as the value returned by unassigned_mem_read returned non-zero and left the kernel looping forever waiting for it to change (see integrator_led_set in the kernel code).
Relying on a varying implementation detail is incorrect anyway so this introduces a memory region to emulate the debug/led region on the integrator board. It is currently a basic stub as I have no idea what the behaviour of this region should be so for now it simply returns 0's as the old unassigned_mem_read did.
--- hw/arm/integratorcp.c | 2 ++ hw/misc/Makefile.objs | 1 + hw/misc/arm_intdbg.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 hw/misc/arm_intdbg.c
hw/arm/integratorcp.c +2 -0
@@ -446,6 +446,7 @@ static void icp_control_init(hwaddr base) } +/* Board init. */ static struct arm_boot_info integrator_binfo = {
@@ -508,6 +509,7 @@ static void integratorcp_init(QEMUMachineInitArgs *args)icp_control_init (0xcb000000 );sysbus_create_simple ("pl050_keyboard" ,0x18000000 , pic[3 ]);sysbus_create_simple ("pl050_mouse" ,0x19000000 , pic[4 ]); +sysbus_create_simple ("integrator_dbg" ,0x1a000000 ,0 );sysbus_create_varargs ("pl181" ,0x1c000000 , pic[23 ], pic[24 ],NULL );if (nd_table[0 ].used)smc91c111_init (&nd_table[0 ],0xc8000000 , pic[27 ]);
hw/misc/Makefile.objs +1 -0
@@ -22,6 +22,7 @@ obj-$(CONFIG_LINUX) += vfio.o endif obj-$(CONFIG_REALVIEW) += arm_sysctl.o +obj-y += arm_intdbg.o obj-$(CONFIG_A9SCU) += a9scu.o obj-$(CONFIG_NSERIES) += cbus.o obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
hw/misc/arm_intdbg.c new file +90 -0
90 lines not on this page · raw message
Signature · 1 line
1.8.4
Quoted 11 lines · On 13 September 2013 15:58, <[email protected]> wrote:
From: Alex Bennée <[email protected]>
Commit
9b8c69243broke the ability to boot the kernel as the value returned byunassigned_mem_readreturned non-zero and left the kernel looping forever waiting for it to change (seeintegrator_led_setin the kernel code).Relying on a varying implementation detail is incorrect anyway so this introduces a memory region to emulate the debug/led region on the integrator board. It is currently a basic stub as I have no idea what the behaviour of this region should be
See the integrator board documentation:
http://infocenter.arm.com/help/topic/com.arm.doc.dui0159b/Babbfijf.html
Quoted 14 lines
so for now it simply returns 0's as
the oldunassigned_mem_readdid.--- hw/arm/integratorcp.c | 2 ++ hw/misc/Makefile.objs | 1 + hw/misc/arm_intdbg.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 hw/misc/arm_intdbg.chw/arm/integratorcp.c +0
-0
hw/arm/integratorcp.c static void icp_control_init(hwaddr base) · line 449
Quoted 4 lines
hw/arm/integratorcp.c +1
-0@@ -446,6 +446,7 @@ static void icp_control_init(hwaddr base) } +
Stray whitespace change.
Quoted 16 lines
hw/arm/integratorcp.c +1
-0/* Board init. */ static struct arm_boot_info integrator_binfo = {@@ -508,6 +509,7 @@ static void integratorcp_init(QEMUMachineInitArgs *args)icp_control_init (0xcb000000 );sysbus_create_simple ("pl050_keyboard" ,0x18000000 , pic[3 ]);sysbus_create_simple ("pl050_mouse" ,0x19000000 , pic[4 ]); +sysbus_create_simple ("integrator_dbg" ,0x1a000000 ,0 );sysbus_create_varargs ("pl181" ,0x1c000000 , pic[23 ], pic[24 ],NULL );if (nd_table[0 ].used)smc91c111_init (&nd_table[0 ],0xc8000000 , pic[27 ]);hw/misc/Makefile.objs +0
-0
hw/misc/Makefile.objs obj-$(CONFIG_LINUX) += vfio.o · line 25
Quoted 4 lines
hw/misc/Makefile.objs +1
-0@@ -22,6 +22,7 @@ obj-$(CONFIG_LINUX) += vfio.o endif obj-$(CONFIG_REALVIEW) += arm_sysctl.o +obj-y += arm_intdbg.o
The device isn't depending on anything target specific so it can go in common-obj-. It needs its own CONFIG_INTEGRATOR_DBG in default-configs/arm-softmmu.mak so you can make it common-obj-$(CONFIG_INTEGRATOR_DBG) +=.
Quoted 9 lines
hw/misc/Makefile.objs +0
-0obj-$(CONFIG_A9SCU) += a9scu.o obj-$(CONFIG_NSERIES) += cbus.o obj-$(CONFIG_ECCMEMCTL) += eccmemctl.ohw/misc/arm_intdbg.c new file +0
-0
hw/misc/arm_intdbg.c line 10
Quoted 10 lines
hw/misc/arm_intdbg.c new file +10
-0@@ -0,0 +1,90 @@ +/* +* LED, Switch and Debug control registers for ARM Integrator Boards +* +* This currently is a stub for this functionality written with +* reference to what the Linux kernel looks at. Previously we relied +* on the behaviour of unassigned_mem_read() in the core. +* +* Written by Alex Bennée +* +* This code is licensed under the GPL.
Would be nice to give a specific version of the GPL... ("2" or "2 or later" are your two basic options.)
Quoted 8 lines
hw/misc/arm_intdbg.c new file +8
-0+*/ + +#include "hw/hw.h" +#include "hw/sysbus.h" +#include "exec/address-spaces.h" + +#define TYPE_ARM_INTDBG "integrator_dbg" +#define ARM_INTDBG (obj) \
hw/misc/arm_intdbg.c line 28
Quoted 10 lines
hw/misc/arm_intdbg.c new file +10
-0+ OBJECT_CHECK(arm_intdbg_state, (obj), TYPE_ARM_INTDBG) + +typedef struct { +SysBusDevice parent_obj; +MemoryRegion iomem; + +uint32_t alpha; +uint32_t leds; +uint32_t switches; +}arm_intdbg_state ;
CODING_STYLE says type names should be camelcase, so ARMIntDbgState.
hw/misc/arm_intdbg.c line 39
Quoted 11 lines
hw/misc/arm_intdbg.c new file +11
-0+ +static uint64_t dbg_control_read (void *opaque,hwaddr offset, +unsigned size) +{ +switch (offset >>2 ) { +case 0 :/* ALPHA */ +return 0 ; +case 1 :/* LEDS */ +return 0 ; +case 2 :/* SWITCHES */ +return 0 ;
You could log these with qemu_log_mask(LOG_UNIMP, ...)
hw/misc/arm_intdbg.c line 41
Quoted 2 lines
hw/misc/arm_intdbg.c new file +2
-0+default : +hw_error ("dbg_control_read: Bad offset %x\n" , (int )offset);
Don't hw_error() for something a guest can provoke. You can just log the info to the debug log (if the user has enabled it) and press on:
qemu_log_mask(LOG_GUEST_ERROR,
"dbg_control_read: Bad offset %x\n", (int)offset);Quoted 5 lines
hw/misc/arm_intdbg.c new file +5
-0+return 0 ; + } +} + +static void dbg_control_write(void *opaque, hwaddr offset,
hw/misc/arm_intdbg.c line 56
Quoted 10 lines
hw/misc/arm_intdbg.c new file +10
-0+ uint64_t value, unsigned size) +{ +switch (offset >>2 ) { +case 1 :/* ALPHA */ +case 2 :/* LEDS */ +case 3 :/* SWITCHES */ +/* Nothing interesting implemented yet. */ +break ; +default : +hw_error ("dbg_control_write: Bad offset %x\n" , (int )offset);
Same remarks as above about logging unimplemented and bad guest behaviour.
Quoted 4 lines
hw/misc/arm_intdbg.c new file +4
-0+ } +} + +static const MemoryRegionOps dbg_control_ops = {
hw/misc/arm_intdbg.c line 70
Quoted 10 lines
hw/misc/arm_intdbg.c new file +10
-0+ .read = dbg_control_read, + .write = dbg_control_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void dbg_control_init (Object *obj) +{ +SysBusDevice *sd =SYS_BUS_DEVICE (obj); +arm_intdbg_state *s =ARM_INTDBG (obj); +memory_region_init_io (&s->iomem,NULL , &dbg_control_ops,NULL ,"dbgleds" ,0x1000 );
(Does this line overflow 80 characters? You can catch this and other style errors by running your patch through scripts/checkpatch.pl...)
The documentation says the size of this region is 16MB, ie 0x1000000. (Actually it says we effectively don't decode most of the address lines so it probably repeats every 16 bytes, but let's not worry about that right now.)
hw/misc/arm_intdbg.c line 76
Quoted 6 lines
hw/misc/arm_intdbg.c new file +6
-0+sysbus_init_mmio (sd, &s->iomem); +} + +/* +Hardware boilerplate +*/
You don't need to add a comment telling us QOM involves lots of boilerplate, we already know that :-)
Quoted 4 lines
hw/misc/arm_intdbg.c new file +4
-0+ +static const TypeInfo arm_intdbg_info = { + .name =TYPE_ARM_INTDBG , + .parent =TYPE_SYS_BUS_DEVICE ,
hw/misc/arm_intdbg.c line 90
Quoted 10 lines
hw/misc/arm_intdbg.c new file +10
-0+ .instance_size = sizeof(arm_intdbg_state), + .instance_init = dbg_control_init, +}; + +static void arm_intdbg_register_types (void ) +{ +type_register_static (&arm_intdbg_info); +} + +type_init (arm_intdbg_register_types)
thanks
-- PMM
Quoted 5 lines · Peter Maydell
Quoted 1 line · On 13 September 2013 15:58, <[email protected]> wrote:
+ * This code is licensed under the GPL.
Would be nice to give a specific version of the GPL... ("2" or "2 or later" are your two basic options.)
...but I forgot to mention that "2-or-later" is strongly preferred.
-- PMM
v2 cover integrator: fix Linux boot failure by emulating dbg
In reply to Peter MaydellHi,
I've applied the review comments from Peter.
Alex.
PATCH v2 1/1 integrator: fix Linux boot failure by emulating dbg
From: Alex Bennée <[email protected]>
Commit 9b8c69243 broke the ability to boot the kernel as the value returned by unassigned_mem_read returned non-zero and left the kernel looping forever waiting for it to change (see integrator_led_set in the kernel code).
Relying on a varying implementation detail is incorrect anyway so this introduces a memory region to emulate the debug/led region on the integrator board. It is currently a basic stub as I have no idea what the behaviour of this region should be so for now it simply returns 0's as the old unassigned_mem_read did.
--- default-configs/arm-softmmu.mak | 1 + hw/arm/integratorcp.c | 1 + hw/misc/Makefile.objs | 1 + hw/misc/arm_intdbg.c | 90 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 hw/misc/arm_intdbg.c
default-configs/arm-softmmu.mak +1 -0
@@ -80,3 +80,4 @@ CONFIG_VERSATILE_PCI=y CONFIG_VERSATILE_I2C=y CONFIG_SDHCI=y +CONFIG_INTEGRATOR_DBG=y
hw/arm/integratorcp.c +1 -0
@@ -508,6 +508,7 @@ static void integratorcp_init(QEMUMachineInitArgs *args)icp_control_init (0xcb000000 );sysbus_create_simple ("pl050_keyboard" ,0x18000000 , pic[3 ]);sysbus_create_simple ("pl050_mouse" ,0x19000000 , pic[4 ]); +sysbus_create_simple ("integrator_dbg" ,0x1a000000 ,0 );sysbus_create_varargs ("pl181" ,0x1c000000 , pic[23 ], pic[24 ],NULL );if (nd_table[0 ].used)smc91c111_init (&nd_table[0 ],0xc8000000 , pic[27 ]);
hw/misc/Makefile.objs +1 -0
@@ -10,6 +10,7 @@ obj-$(CONFIG_VMPORT) += vmport.o # ARM devices common-obj-$(CONFIG_PL310) += arm_l2x0.o +common-obj-$(CONFIG_INTEGRATOR_DBG) += arm_intdbg.o # PKUnity SoC devices common-obj-$(CONFIG_PUV3) += puv3_pm.o
hw/misc/arm_intdbg.c new file +90 -0
90 lines not on this page · raw message
Signature · 1 line
1.8.4
Quoted 6 lines · On 16 September 2013 13:50, <[email protected]> wrote:
From: Alex Bennée <[email protected]>
Commit
9b8c69243broke the ability to boot the kernel as the value returned byunassigned_mem_readreturned non-zero and left the kernel looping forever waiting for it to change (seeintegrator_led_setin the kernel code).
This generally looks OK, but I have a few nits.
Quoted 5 lines
Relying on a varying implementation detail is incorrect anyway so this introduces a memory region to emulate the debug/led region on the integrator board. It is currently a basic stub as I have no idea what the behaviour of this region should be so for now it simply returns 0's as the old
unassigned_mem_readdid.
It looks like you need to update the commit message -- you looked at the board docs, so we do know the correct behaviour.
hw/misc/arm_intdbg.c line 6
Quoted 8 lines
+++
b/hw/misc/arm_intdbg.chw/misc/arm_intdbg.c new file +6
-0@@ -0,0 +1,90 @@ +/* +* LED, Switch and Debug control registers for ARM Integrator Boards +* +* This currently is a stub for this functionality written with +* reference to what the Linux kernel looks at. Previously we relied +* on the behaviour of unassigned_mem_read() in the core.
This sounds like the code was written based on the kernel, not on the board docs, which is wrong, so I think it could use rephrasing. There's no need to mention previous behaviour either IMHO -- people who care can look at the commit history.
hw/misc/arm_intdbg.c line 11
Quoted 5 lines
hw/misc/arm_intdbg.c new file +5
-0+* +* The real h/w is described at: +* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0159b/Babbfijf.html +* +* Written by Alex Bennée
Assuming you wrote this with your Linaro hat on, the comment should have a
* Copyright (c) 2013 Linaro Limited
in it above your 'Written by' line.
Quoted 7 lines
hw/misc/arm_intdbg.c new file +6
-0+* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +static void dbg_control_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size)
hw/misc/arm_intdbg.c line 60
Quoted 10 lines
hw/misc/arm_intdbg.c new file +10
-0+{ +switch (offset >>2 ) { +case 1 :/* ALPHA */ +case 2 :/* LEDS */ +case 3 :/* SWITCHES */ +/* Nothing interesting implemented yet. */ +qemu_log_mask (LOG_UNIMP ,"dbg_control_write: ignoring write of %lx to %x:%d\n" , value, (int )offset, size); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"dbg_control_write: write of %lx to bad offset %x\n" , value, (int )offset);
This looks like an overlength line : checkpatch.pl should warn if so. (I think there are others too.)
thanks
-- PMM
Quoted 9 lines · [email protected] writes:
Quoted 6 lines · On 16 September 2013 13:50, <[email protected]> wrote:
From: Alex Bennée <[email protected]>
Commit
9b8c69243broke the ability to boot the kernel as the value returned byunassigned_mem_readreturned non-zero and left the kernel looping forever waiting for it to change (seeintegrator_led_setin the kernel code).This generally looks OK, but I have a few nits.
OK
Quoted 8 lines
Quoted 5 lines
Relying on a varying implementation detail is incorrect anyway so this introduces a memory region to emulate the debug/led region on the integrator board. It is currently a basic stub as I have no idea what the behaviour of this region should be so for now it simply returns 0's as the old
unassigned_mem_readdid.It looks like you need to update the commit message -- you looked at the board docs, so we do know the correct behaviour.
True, I shall update.
Quoted 5 lines
Quoted 5 lines
+++
b/hw/misc/arm_intdbg.chw/misc/arm_intdbg.c new file +3
-0@@ -0,0 +1,90 @@ +/* +* LED, Switch and Debug control registers for ARM Integrator Boards +*
Quoted 8 lines
hw/misc/arm_intdbg.c line 6
Quoted 3 lines
hw/misc/arm_intdbg.c new file +3
-0+* This currently is a stub for this functionality written with +* reference to what the Linux kernel looks at. Previously we relied +* on the behaviour of unassigned_mem_read() in the core. This sounds like the code was written based on the kernel, not on the board docs, which is wrong, so I think it could use rephrasing. There's no need to mention previous behaviour either IMHO -- people who care can look at the commit history.
Sure. I've got a bunch of other review comments to address so I can clean this up. Unfortunately I've been so busy with other stuff I haven't had a chance to go through them yet.
As it happens it looks like the integrator image is now running again on the current HEAD which has made this a little less urgent. However it does raise an interesting question as to why!
Quoted 11 lines
hw/misc/arm_intdbg.c line 11
Quoted 5 lines
hw/misc/arm_intdbg.c new file +5
-0+* +* The real h/w is described at: +* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0159b/Babbfijf.html +* +* Written by Alex Bennée Assuming you wrote this with your Linaro hat on, the comment should have a
* Copyright (c) 2013 Linaro Limitedin it above your 'Written by' line.
Yeah, I was holding off that until I was officially on the clock although as noticed I have been taking advantage of the email facilities as a handy place to have the mailing list go through.
<snip>
Quoted 8 lines
hw/misc/arm_intdbg.c line 60
Quoted 5 lines
hw/misc/arm_intdbg.c new file +5
-0+/* Nothing interesting implemented yet. */ +qemu_log_mask (LOG_UNIMP ,"dbg_control_write: ignoring write of %lx to %x:%d\n" , value, (int )offset, size); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"dbg_control_write: write of %lx to bad offset %x\n" , value, (int )offset);This looks like an overlength line : checkpatch.pl should warn if so. (I think there are others too.)
OK thanks.
Signature · 1 line
Alex Bennée
Quoted 6 lines · Alex Bennée
Quoted 4 lines · [email protected] writes:
This sounds like the code was written based on the kernel, not on the board docs, which is wrong, so I think it could use rephrasing. There's no need to mention previous behaviour either IMHO -- people who care can look at the commit history.
Quoted 7 lines
Sure. I've got a bunch of other review comments to address so I can clean this up. Unfortunately I've been so busy with other stuff I haven't had a chance to go through them yet.
As it happens it looks like the integrator image is now running again on the current HEAD which has made this a little less urgent. However it does raise an interesting question as to why!
Commits 3bb28b72 and 68a7439a1 reverted the changes to the behaviour of reads from unassigned regions (since they were causing widespread brokenness).
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
+ * Written by Alex Bennée
Assuming you wrote this with your Linaro hat on, the comment should have a
* Copyright (c) 2013 Linaro Limitedin it above your 'Written by' line.
Yeah, I was holding off that until I was officially on the clock although as noticed I have been taking advantage of the email facilities as a handy place to have the mailing list go through.
Well, it needs *some* copyright line, at least, for whichever entity has the rights to the code and ability to (re)license it...
thanks
-- PMM