qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

hw/arm/allwinner-h3: add System Control module

The Allwinner H3 System on Chip has an System Control
module that provides system wide generic controls and
device information. This commit adds support for the
Allwinner H3 System Control module.

Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20200311221854.30370-6-nieklinnenbank@gmail.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

authored by

Niek Linnenbank and committed by
Peter Maydell
7e83c9dd 2e4dfe80

+219 -1
+8 -1
hw/arm/allwinner-h3.c
··· 37 37 [AW_H3_SRAM_A1] = 0x00000000, 38 38 [AW_H3_SRAM_A2] = 0x00044000, 39 39 [AW_H3_SRAM_C] = 0x00010000, 40 + [AW_H3_SYSCTRL] = 0x01c00000, 40 41 [AW_H3_EHCI0] = 0x01c1a000, 41 42 [AW_H3_OHCI0] = 0x01c1a400, 42 43 [AW_H3_EHCI1] = 0x01c1b000, ··· 66 67 } unimplemented[] = { 67 68 { "d-engine", 0x01000000, 4 * MiB }, 68 69 { "d-inter", 0x01400000, 128 * KiB }, 69 - { "syscon", 0x01c00000, 4 * KiB }, 70 70 { "dma", 0x01c02000, 4 * KiB }, 71 71 { "nfdc", 0x01c03000, 4 * KiB }, 72 72 { "ts", 0x01c06000, 4 * KiB }, ··· 192 192 193 193 sysbus_init_child_obj(obj, "ccu", &s->ccu, sizeof(s->ccu), 194 194 TYPE_AW_H3_CCU); 195 + 196 + sysbus_init_child_obj(obj, "sysctrl", &s->sysctrl, sizeof(s->sysctrl), 197 + TYPE_AW_H3_SYSCTRL); 195 198 } 196 199 197 200 static void allwinner_h3_realize(DeviceState *dev, Error **errp) ··· 300 303 /* Clock Control Unit */ 301 304 qdev_init_nofail(DEVICE(&s->ccu)); 302 305 sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccu), 0, s->memmap[AW_H3_CCU]); 306 + 307 + /* System Control */ 308 + qdev_init_nofail(DEVICE(&s->sysctrl)); 309 + sysbus_mmio_map(SYS_BUS_DEVICE(&s->sysctrl), 0, s->memmap[AW_H3_SYSCTRL]); 303 310 304 311 /* Universal Serial Bus */ 305 312 sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
+1
hw/misc/Makefile.objs
··· 29 29 common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o 30 30 31 31 common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o 32 + common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o 32 33 common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o 33 34 common-obj-$(CONFIG_NSERIES) += cbus.o 34 35 common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
+140
hw/misc/allwinner-h3-sysctrl.c
··· 1 + /* 2 + * Allwinner H3 System Control emulation 3 + * 4 + * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com> 5 + * 6 + * This program is free software: you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation, either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include "qemu/osdep.h" 21 + #include "qemu/units.h" 22 + #include "hw/sysbus.h" 23 + #include "migration/vmstate.h" 24 + #include "qemu/log.h" 25 + #include "qemu/module.h" 26 + #include "hw/misc/allwinner-h3-sysctrl.h" 27 + 28 + /* System Control register offsets */ 29 + enum { 30 + REG_VER = 0x24, /* Version */ 31 + REG_EMAC_PHY_CLK = 0x30, /* EMAC PHY Clock */ 32 + }; 33 + 34 + #define REG_INDEX(offset) (offset / sizeof(uint32_t)) 35 + 36 + /* System Control register reset values */ 37 + enum { 38 + REG_VER_RST = 0x0, 39 + REG_EMAC_PHY_CLK_RST = 0x58000, 40 + }; 41 + 42 + static uint64_t allwinner_h3_sysctrl_read(void *opaque, hwaddr offset, 43 + unsigned size) 44 + { 45 + const AwH3SysCtrlState *s = AW_H3_SYSCTRL(opaque); 46 + const uint32_t idx = REG_INDEX(offset); 47 + 48 + if (idx >= AW_H3_SYSCTRL_REGS_NUM) { 49 + qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n", 50 + __func__, (uint32_t)offset); 51 + return 0; 52 + } 53 + 54 + return s->regs[idx]; 55 + } 56 + 57 + static void allwinner_h3_sysctrl_write(void *opaque, hwaddr offset, 58 + uint64_t val, unsigned size) 59 + { 60 + AwH3SysCtrlState *s = AW_H3_SYSCTRL(opaque); 61 + const uint32_t idx = REG_INDEX(offset); 62 + 63 + if (idx >= AW_H3_SYSCTRL_REGS_NUM) { 64 + qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n", 65 + __func__, (uint32_t)offset); 66 + return; 67 + } 68 + 69 + switch (offset) { 70 + case REG_VER: /* Version */ 71 + break; 72 + default: 73 + s->regs[idx] = (uint32_t) val; 74 + break; 75 + } 76 + } 77 + 78 + static const MemoryRegionOps allwinner_h3_sysctrl_ops = { 79 + .read = allwinner_h3_sysctrl_read, 80 + .write = allwinner_h3_sysctrl_write, 81 + .endianness = DEVICE_NATIVE_ENDIAN, 82 + .valid = { 83 + .min_access_size = 4, 84 + .max_access_size = 4, 85 + }, 86 + .impl.min_access_size = 4, 87 + }; 88 + 89 + static void allwinner_h3_sysctrl_reset(DeviceState *dev) 90 + { 91 + AwH3SysCtrlState *s = AW_H3_SYSCTRL(dev); 92 + 93 + /* Set default values for registers */ 94 + s->regs[REG_INDEX(REG_VER)] = REG_VER_RST; 95 + s->regs[REG_INDEX(REG_EMAC_PHY_CLK)] = REG_EMAC_PHY_CLK_RST; 96 + } 97 + 98 + static void allwinner_h3_sysctrl_init(Object *obj) 99 + { 100 + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); 101 + AwH3SysCtrlState *s = AW_H3_SYSCTRL(obj); 102 + 103 + /* Memory mapping */ 104 + memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_h3_sysctrl_ops, s, 105 + TYPE_AW_H3_SYSCTRL, 4 * KiB); 106 + sysbus_init_mmio(sbd, &s->iomem); 107 + } 108 + 109 + static const VMStateDescription allwinner_h3_sysctrl_vmstate = { 110 + .name = "allwinner-h3-sysctrl", 111 + .version_id = 1, 112 + .minimum_version_id = 1, 113 + .fields = (VMStateField[]) { 114 + VMSTATE_UINT32_ARRAY(regs, AwH3SysCtrlState, AW_H3_SYSCTRL_REGS_NUM), 115 + VMSTATE_END_OF_LIST() 116 + } 117 + }; 118 + 119 + static void allwinner_h3_sysctrl_class_init(ObjectClass *klass, void *data) 120 + { 121 + DeviceClass *dc = DEVICE_CLASS(klass); 122 + 123 + dc->reset = allwinner_h3_sysctrl_reset; 124 + dc->vmsd = &allwinner_h3_sysctrl_vmstate; 125 + } 126 + 127 + static const TypeInfo allwinner_h3_sysctrl_info = { 128 + .name = TYPE_AW_H3_SYSCTRL, 129 + .parent = TYPE_SYS_BUS_DEVICE, 130 + .instance_init = allwinner_h3_sysctrl_init, 131 + .instance_size = sizeof(AwH3SysCtrlState), 132 + .class_init = allwinner_h3_sysctrl_class_init, 133 + }; 134 + 135 + static void allwinner_h3_sysctrl_register(void) 136 + { 137 + type_register_static(&allwinner_h3_sysctrl_info); 138 + } 139 + 140 + type_init(allwinner_h3_sysctrl_register)
+3
include/hw/arm/allwinner-h3.h
··· 40 40 #include "hw/timer/allwinner-a10-pit.h" 41 41 #include "hw/intc/arm_gic.h" 42 42 #include "hw/misc/allwinner-h3-ccu.h" 43 + #include "hw/misc/allwinner-h3-sysctrl.h" 43 44 #include "target/arm/cpu.h" 44 45 45 46 /** ··· 56 57 AW_H3_SRAM_A1, 57 58 AW_H3_SRAM_A2, 58 59 AW_H3_SRAM_C, 60 + AW_H3_SYSCTRL, 59 61 AW_H3_EHCI0, 60 62 AW_H3_OHCI0, 61 63 AW_H3_EHCI1, ··· 108 110 const hwaddr *memmap; 109 111 AwA10PITState timer; 110 112 AwH3ClockCtlState ccu; 113 + AwH3SysCtrlState sysctrl; 111 114 GICState gic; 112 115 MemoryRegion sram_a1; 113 116 MemoryRegion sram_a2;
+67
include/hw/misc/allwinner-h3-sysctrl.h
··· 1 + /* 2 + * Allwinner H3 System Control emulation 3 + * 4 + * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com> 5 + * 6 + * This program is free software: you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation, either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #ifndef HW_MISC_ALLWINNER_H3_SYSCTRL_H 21 + #define HW_MISC_ALLWINNER_H3_SYSCTRL_H 22 + 23 + #include "qom/object.h" 24 + #include "hw/sysbus.h" 25 + 26 + /** 27 + * @name Constants 28 + * @{ 29 + */ 30 + 31 + /** Highest register address used by System Control device */ 32 + #define AW_H3_SYSCTRL_REGS_MAXADDR (0x30) 33 + 34 + /** Total number of known registers */ 35 + #define AW_H3_SYSCTRL_REGS_NUM ((AW_H3_SYSCTRL_REGS_MAXADDR / \ 36 + sizeof(uint32_t)) + 1) 37 + 38 + /** @} */ 39 + 40 + /** 41 + * @name Object model 42 + * @{ 43 + */ 44 + 45 + #define TYPE_AW_H3_SYSCTRL "allwinner-h3-sysctrl" 46 + #define AW_H3_SYSCTRL(obj) \ 47 + OBJECT_CHECK(AwH3SysCtrlState, (obj), TYPE_AW_H3_SYSCTRL) 48 + 49 + /** @} */ 50 + 51 + /** 52 + * Allwinner H3 System Control object instance state 53 + */ 54 + typedef struct AwH3SysCtrlState { 55 + /*< private >*/ 56 + SysBusDevice parent_obj; 57 + /*< public >*/ 58 + 59 + /** Maps I/O registers in physical memory */ 60 + MemoryRegion iomem; 61 + 62 + /** Array of hardware registers */ 63 + uint32_t regs[AW_H3_SYSCTRL_REGS_NUM]; 64 + 65 + } AwH3SysCtrlState; 66 + 67 + #endif /* HW_MISC_ALLWINNER_H3_SYSCTRL_H */