Add basic power management to raspi.
Subsystems (3)
PATCH v2 1/1 Add basic power management to raspi.
From: Nolan Leake <[email protected]>
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 | 159 +++++++++++++++++++++++++++ hw/misc/meson.build | 1 + include/hw/arm/bcm2835_peripherals.h | 3 +- include/hw/misc/bcm2835_powermgt.h | 29 +++++ 5 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 hw/misc/bcm2835_powermgt.c create mode 100644 include/hw/misc/bcm2835_powermgt.h
hw/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 );
hw/misc/bcm2835_powermgt.c new file +159 -0
159 lines not on this page · raw message
hw/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'))
include/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;
include/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