[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 40/43] hw/loongarch: Add LoongArch power manager support
From: |
Xiaojuan Yang |
Subject: |
[PATCH v6 40/43] hw/loongarch: Add LoongArch power manager support |
Date: |
Wed, 1 Jun 2022 18:25:06 +0800 |
Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
Signed-off-by: Song Gao <gaosong@loongson.cn>
---
hw/loongarch/loongson3.c | 45 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/hw/loongarch/loongson3.c b/hw/loongarch/loongson3.c
index 3c8fcb828c..658331f604 100644
--- a/hw/loongarch/loongson3.c
+++ b/hw/loongarch/loongson3.c
@@ -31,6 +31,44 @@
#include "target/loongarch/cpu.h"
+#define PM_BASE 0x10080000
+#define PM_SIZE 0x100
+#define PM_CTRL 0x10
+
+static uint64_t loongarch_virt_pm_read(void *opaque, hwaddr addr, unsigned
size)
+{
+ return 0;
+}
+
+static void loongarch_virt_pm_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+ if (addr != PM_CTRL) {
+ return;
+ }
+
+ switch (val) {
+ case 0x00:
+ qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
+ return;
+ case 0xff:
+ qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+ return;
+ default:
+ return;
+ }
+}
+
+static const MemoryRegionOps loongarch_virt_pm_ops = {
+ .read = loongarch_virt_pm_read,
+ .write = loongarch_virt_pm_write,
+ .endianness = DEVICE_NATIVE_ENDIAN,
+ .valid = {
+ .min_access_size = 1,
+ .max_access_size = 1
+ }
+};
+
static struct _loaderparams {
uint64_t ram_size;
const char *kernel_filename;
@@ -67,7 +105,7 @@ static void loongarch_devices_init(DeviceState *pch_pic)
SysBusDevice *d;
PCIBus *pci_bus;
MemoryRegion *ecam_alias, *ecam_reg, *pio_alias, *pio_reg;
- MemoryRegion *mmio_alias, *mmio_reg;
+ MemoryRegion *mmio_alias, *mmio_reg, *pm_mem;
int i;
gpex_dev = qdev_new(TYPE_GPEX_HOST);
@@ -132,6 +170,11 @@ static void loongarch_devices_init(DeviceState *pch_pic)
sysbus_create_simple("ls7a_rtc", LS7A_RTC_REG_BASE,
qdev_get_gpio_in(pch_pic,
LS7A_RTC_IRQ - PCH_PIC_IRQ_OFFSET));
+
+ pm_mem = g_new(MemoryRegion, 1);
+ memory_region_init_io(pm_mem, NULL, &loongarch_virt_pm_ops,
+ NULL, "loongarch_virt_pm", PM_SIZE);
+ memory_region_add_subregion(get_system_memory(), PM_BASE, pm_mem);
}
static void loongarch_irq_init(LoongArchMachineState *lams)
--
2.31.1
- [PATCH v6 21/43] target/loongarch: Implement qmp_query_cpu_definitions(), (continued)
- [PATCH v6 21/43] target/loongarch: Implement qmp_query_cpu_definitions(), Xiaojuan Yang, 2022/06/01
- [PATCH v6 04/43] target/loongarch: Add fixed point arithmetic instruction translation, Xiaojuan Yang, 2022/06/01
- [PATCH v6 38/43] hw/loongarch: Add LoongArch ls7a rtc device support, Xiaojuan Yang, 2022/06/01
- [PATCH v6 02/43] target/loongarch: Add core definition, Xiaojuan Yang, 2022/06/01
- [PATCH v6 18/43] target/loongarch: Add system emulation introduction, Xiaojuan Yang, 2022/06/01
- [PATCH v6 32/43] hw/intc: Add LoongArch ls7a interrupt controller support(PCH-PIC), Xiaojuan Yang, 2022/06/01
- [PATCH v6 05/43] target/loongarch: Add fixed point shift instruction translation, Xiaojuan Yang, 2022/06/01
- [PATCH v6 31/43] hw/loongarch: Add LoongArch ipi interrupt support(IPI), Xiaojuan Yang, 2022/06/01
- [PATCH v6 35/43] hw/loongarch: Add irq hierarchy for the system, Xiaojuan Yang, 2022/06/01
- [PATCH v6 40/43] hw/loongarch: Add LoongArch power manager support,
Xiaojuan Yang <=
- [PATCH v6 27/43] target/loongarch: Add TLB instruction support, Xiaojuan Yang, 2022/06/01
- [PATCH v6 43/43] target/loongarch: 'make check-tcg' support, Xiaojuan Yang, 2022/06/01
- [PATCH v6 42/43] tests/tcg/loongarch64: Add hello/memory test in loongarch64 system, Xiaojuan Yang, 2022/06/01
- [PATCH v6 29/43] target/loongarch: Add timer related instructions support., Xiaojuan Yang, 2022/06/01
- [PATCH v6 17/43] target/loongarch: Add target build suport, Xiaojuan Yang, 2022/06/01
- [PATCH v6 19/43] target/loongarch: Add CSRs definition, Xiaojuan Yang, 2022/06/01
- [PATCH v6 37/43] hw/loongarch: Add some devices support for 3A5000., Xiaojuan Yang, 2022/06/01
- [PATCH v6 28/43] target/loongarch: Add other core instructions support, Xiaojuan Yang, 2022/06/01
- [PATCH v6 26/43] target/loongarch: Add LoongArch IOCSR instruction, Xiaojuan Yang, 2022/06/01