Add basic power management to raspi.
Subsystems (3)
PATCH v3 1/1 Add basic power management to raspi.
This is just enough to make reboot and poweroff work. Works for linux, u-boot, and the arm trusted firmware. Not tested, but should work for plan9, and bare-metal/hobby OSes, since they seem to generally do what linux does for reset.
The watchdog timer functionality is not yet implemented.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/64
--- hw/arm/bcm2835_peripherals.c | 13 ++- hw/misc/bcm2835_powermgt.c | 160 +++++++++++++++++++++++++++ hw/misc/meson.build | 1 + include/hw/arm/bcm2835_peripherals.h | 3 +- include/hw/misc/bcm2835_powermgt.h | 29 +++++ 5 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 hw/misc/bcm2835_powermgt.c create mode 100644 include/hw/misc/bcm2835_powermgt.h
arm/bcm2835_peripherals.c +12 -1
@@ -126,6 +126,10 @@ static void bcm2835_peripherals_init(Object *obj)object_property_add_const_link (OBJECT (&s->dwc2),"dma-mr" ,OBJECT (&s->gpu_bus_mr)); + +/* Power Management */ +object_initialize_child (obj,"powermgt" , &s->powermgt, +TYPE_BCM2835_POWERMGT ); }static void bcm2835_peripherals_realize (DeviceState *dev,Error **errp)
@@ -364,9 +368,16 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)qdev_get_gpio_in_named (DEVICE (&s->ic),BCM2835_IC_GPU_IRQ , INTERRUPT_USB)); +/* Power Management */ +if (!sysbus_realize (SYS_BUS_DEVICE (&s->powermgt), errp)) { +return ; + } + +memory_region_add_subregion (&s->peri_mr,PM_OFFSET , +sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->powermgt),0 )); +create_unimp (s, &s->txp,"bcm2835-txp" ,TXP_OFFSET ,0x1000 );create_unimp (s, &s->armtmr,"bcm2835-sp804" ,ARMCTRL_TIMER0_1_OFFSET ,0x40 ); -create_unimp (s, &s->powermgt,"bcm2835-powermgt" ,PM_OFFSET ,0x114 );create_unimp (s, &s->i2s,"bcm2835-i2s" ,I2S_OFFSET ,0x100 );create_unimp (s, &s->smi,"bcm2835-smi" ,SMI_OFFSET ,0x100 );create_unimp (s, &s->spi[0 ],"bcm2835-spi0" ,SPI0_OFFSET ,0x20 );
misc/bcm2835_powermgt.c new file +160 -0
160 lines not on this page · raw message
misc/meson.build +1 -0
@@ -82,6 +82,7 @@ softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files( 'bcm2835_rng.c', 'bcm2835_thermal.c', 'bcm2835_cprman.c', + 'bcm2835_powermgt.c', )) softmmu_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c')) softmmu_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c', 'zynq-xadc.c'))
hw/arm/bcm2835_peripherals.h +2 -1
@@ -24,6 +24,7 @@#include "hw/misc/bcm2835_mphi.h" #include "hw/misc/bcm2835_thermal.h" #include "hw/misc/bcm2835_cprman.h" +#include "hw/misc/bcm2835_powermgt.h" #include "hw/sd/sdhci.h" #include "hw/sd/bcm2835_sdhost.h" #include "hw/gpio/bcm2835_gpio.h"
@@ -48,7 +49,7 @@ struct BCM2835PeripheralState {BCM2835MphiState mphi;UnimplementedDeviceState txp;UnimplementedDeviceState armtmr; -UnimplementedDeviceState powermgt; +BCM2835PowerMgtState powermgt;BCM2835CprmanState cprman;PL011State uart0;BCM2835AuxState aux;
hw/misc/bcm2835_powermgt.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* BCM2835 Power Management emulation +* +* Copyright (C) 2017 Marcin Chojnacki <[email protected]> +* Copyright (C) 2021 Nolan Leake <[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. +*/ + +#ifndef BCM2835_POWERMGT_H +#define BCM2835_POWERMGT_H + +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_BCM2835_POWERMGT "bcm2835-powermgt" +OBJECT_DECLARE_SIMPLE_TYPE(BCM2835PowerMgtState, BCM2835_POWERMGT) + +struct BCM2835PowerMgtState { +SysBusDevice busdev; +MemoryRegion iomem; + +uint32_t rstc; +uint32_t rsts; +uint32_t wdog; +}; + +#endif
Signature · 1 line
2.30.2
Hi Nolan, Peter,
Quoted 8 lines · Nolan Leake
This is just enough to make reboot and poweroff work. Works for linux, u-boot, and the arm trusted firmware. Not tested, but should work for plan9, and bare-metal/hobby OSes, since they seem to generally do what linux does for reset.
The watchdog timer functionality is not yet implemented.
Please carry the tags from previous versions (if the changes are minor).
hw/arm/bcm2835_peripherals.c
Quoted 12 lines
Signed-off-by Nolan Leake <[email protected]>--- hw/arm/bcm2835_peripherals.c | 13 ++- hw/misc/bcm2835_powermgt.c | 160 +++++++++++++++++++++++++++ hw/misc/meson.build | 1 + include/hw/arm/bcm2835_peripherals.h | 3 +- include/hw/misc/bcm2835_powermgt.h | 29 +++++ 5 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 hw/misc/bcm2835_powermgt.c create mode 100644 include/hw/misc/bcm2835_powermgt.hhw/arm/bcm2835_peripherals.c +0
-0
Odd, usually the diff line comes with a/ b/ prefix, I can not apply your patch (git version 2.31.1, Fedora):
Applying: Add basic power management to raspi.
error: arm/bcm2835_peripherals.c: does not exist in index
error: misc/meson.build: does not exist in index
error: hw/arm/bcm2835_peripherals.h: does not exist in index Patch failed at 0001 Add basic power management to raspi.
But patchew succeeded:
https://patchew.org/QEMU/[email protected]/
Applying: Add basic power management to raspi.
Using index info to reconstruct a base tree...
A arm/bcm2835_peripherals.c A hw/arm/bcm2835_peripherals.h A misc/meson.build
Falling back to patching base and 3-way merge...
So I tested patchew's commit 7856ac0e804:
https://github.com/patchew-project/qemu/commit/7856ac0e8045d006f1008a03e1d4d8710b9d0612
Peter, when queueing this patch (maybe prepending hw/arm: or hw/arm/raspi: to the subject), can you take the corresponding test along - which is already reviewed?
https://www.mail-archive.com/[email protected]/msg811909.html
Thanks both,
Phil.
Peter Maydell
AppliedQuoted 20 lines · Philippe Mathieu-Daudé
Hi Nolan, Peter,
hw/arm/bcm2835_peripherals.c
Quoted 1 line · Nolan Leake
hw/arm/bcm2835_peripherals.c +0
-0Odd, usually the diff line comes with a/ b/ prefix, I can not apply your patch (git version 2.31.1, Fedora):
Applying: Add basic power management to raspi.
error:arm/bcm2835_peripherals.c: does not exist in index
error: misc/meson.build: does not exist in index
error:hw/arm/bcm2835_peripherals.h: does not exist in index Patch failed at 0001 Add basic power management to raspi.But patchew succeeded:
https://patchew.org/QEMU/[email protected]/Applying: Add basic power management to raspi.
Using index info to reconstruct a base tree...
Quoted 7 lines
A arm/bcm2835_peripherals.c A hw/arm/bcm2835_peripherals.h A misc/meson.buildFalling back to patching base and 3-way merge...
So I tested patchew's commit
7856ac0e804:
https://github.com/patchew-project/qemu/commit/7856ac0e8045d006f1008a03e1d4d8710b9d0612
It succeeded, but if you look at that tree you'll notice it was confused enough to create a new top level directory misc/ to put the .c file in! I'm not sure how the result manages to build :-)
I have fixed this up locally. I have also moved the bcm2835_powermgt.h file to include/hw/misc, to go with the other bcm2835 headers there, and I have fixed the region size.
Applied to target-arm.next, thanks.
thanks
-- PMM
Quoted 26 lines · Peter Maydell
Quoted 25 lines · Philippe Mathieu-Daudé
Hi Nolan, Peter,
hw/arm/bcm2835_peripherals.c
Quoted 1 line · Nolan Leake
hw/arm/bcm2835_peripherals.c +0
-0Odd, usually the diff line comes with a/ b/ prefix, I can not apply your patch (git version 2.31.1, Fedora):
Applying: Add basic power management to raspi.
error:arm/bcm2835_peripherals.c: does not exist in index
error: misc/meson.build: does not exist in index
error:hw/arm/bcm2835_peripherals.h: does not exist in index Patch failed at 0001 Add basic power management to raspi.But patchew succeeded:
https://patchew.org/QEMU/[email protected]/Applying: Add basic power management to raspi.
Using index info to reconstruct a base tree...A arm/bcm2835_peripherals.c A hw/arm/bcm2835_peripherals.h A misc/meson.buildFalling back to patching base and 3-way merge...
Quoted 6 lines
Quoted 2 lines
So I tested patchew's commit
7856ac0e804:
https://github.com/patchew-project/qemu/commit/7856ac0e8045d006f1008a03e1d4d8710b9d0612It succeeded, but if you look at that tree you'll notice it was confused enough to create a new top level directory misc/ to put the .c file in! I'm not sure how the result manages to build :-)
I had to do move bcm2835_peripherals.c to build (otherwise meson complains and refuses to finish the configure script). I assumed it was a problem on my side (or with my git version) and didn't noticed bcm2835_peripherals.h was not under include/.
Quoted 3 lines
I have fixed this up locally. I have also moved the
bcm2835_powermgt.hfile toinclude/hw/misc, to go with the other bcm2835 headers there, and I have fixed the region size.
Thank you.
Nolan, can you tell us what OS/distribution you are using? You used git v2.30.2 which might be badly packaged there, and could deserve a proper bug report.
Regards,
Phil.
Quoted 4 lines · Philippe Mathieu-Daudé
I had to do move
bcm2835_peripherals.cto build (otherwise meson complains and refuses to finish the configure script). I assumed it was a problem on my side (or with my git version) and didn't noticedbcm2835_peripherals.hwas not underinclude/.
This must have been an artifact of my busted diff, in my tree:
$ find . -name bcm2835_peripherals.h ./include/hw/arm/bcm2835_peripherals.h
Quoted 3 lines
Nolan, can you tell us what OS/distribution you are using? You used git v2.30.2 which might be badly packaged there, and could deserve a proper bug report.
Debian Bullseye. I had diff.noprefix=true set in my .gitconfig for some reason or another. I've removed it.
Quoted 25 lines · Nolan Leake
This is just enough to make reboot and poweroff work. Works for linux, u-boot, and the arm trusted firmware. Not tested, but should work for plan9, and bare-metal/hobby OSes, since they seem to generally do what linux does for reset.
The watchdog timer functionality is not yet implemented.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/64
Signed-off-by Nolan Leake <[email protected]>--- hw/arm/bcm2835_peripherals.c | 13 ++- hw/misc/bcm2835_powermgt.c | 160 +++++++++++++++++++++++++++ hw/misc/meson.build | 1 + include/hw/arm/bcm2835_peripherals.h | 3 +- include/hw/misc/bcm2835_powermgt.h | 29 +++++ 5 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 hw/misc/bcm2835_powermgt.c create mode 100644 include/hw/misc/bcm2835_powermgt.hcreate_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000); create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40); - create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114); create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100); create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100); create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20);
...
misc/bcm2835_powermgt.c line 125
Quoted 6 lines
misc/bcm2835_powermgt.c new file +6
-0+static void bcm2835_powermgt_init (Object *obj) +{ +BCM2835PowerMgtState *s =BCM2835_POWERMGT (obj); + +memory_region_init_io (&s->iomem, obj, &bcm2835_powermgt_ops, s, +TYPE_BCM2835_POWERMGT ,0x114 );
In case Peter asks you to resend your patch because can't apply it, please use a region size of 0x200 here.
Alternatively you can increase the odds to get your patch merged by resending it properly (I'm still not sure what broke it) before Peter review the ARM patches next week.