xref: /qemu/include/hw/arm/virt.h (revision e9a8e474)
1afe0b380SShannon Zhao /*
2afe0b380SShannon Zhao  *
3afe0b380SShannon Zhao  * Copyright (c) 2015 Linaro Limited
4afe0b380SShannon Zhao  *
5afe0b380SShannon Zhao  * This program is free software; you can redistribute it and/or modify it
6afe0b380SShannon Zhao  * under the terms and conditions of the GNU General Public License,
7afe0b380SShannon Zhao  * version 2 or later, as published by the Free Software Foundation.
8afe0b380SShannon Zhao  *
9afe0b380SShannon Zhao  * This program is distributed in the hope it will be useful, but WITHOUT
10afe0b380SShannon Zhao  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11afe0b380SShannon Zhao  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12afe0b380SShannon Zhao  * more details.
13afe0b380SShannon Zhao  *
14afe0b380SShannon Zhao  * You should have received a copy of the GNU General Public License along with
15afe0b380SShannon Zhao  * this program.  If not, see <http://www.gnu.org/licenses/>.
16afe0b380SShannon Zhao  *
17afe0b380SShannon Zhao  * Emulate a virtual board which works by passing Linux all the information
18afe0b380SShannon Zhao  * it needs about what devices are present via the device tree.
19afe0b380SShannon Zhao  * There are some restrictions about what we can do here:
20afe0b380SShannon Zhao  *  + we can only present devices whose Linux drivers will work based
21afe0b380SShannon Zhao  *    purely on the device tree with no platform data at all
22afe0b380SShannon Zhao  *  + we want to present a very stripped-down minimalist platform,
23afe0b380SShannon Zhao  *    both because this reduces the security attack surface from the guest
24afe0b380SShannon Zhao  *    and also because it reduces our exposure to being broken when
25afe0b380SShannon Zhao  *    the kernel updates its device tree bindings and requires further
26afe0b380SShannon Zhao  *    information in a device binding that we aren't providing.
27afe0b380SShannon Zhao  * This is essentially the same approach kvmtool uses.
28afe0b380SShannon Zhao  */
29afe0b380SShannon Zhao 
30afe0b380SShannon Zhao #ifndef QEMU_ARM_VIRT_H
31afe0b380SShannon Zhao #define QEMU_ARM_VIRT_H
32afe0b380SShannon Zhao 
33afe0b380SShannon Zhao #include "qemu-common.h"
3433c11879SPaolo Bonzini #include "exec/hwaddr.h"
35d05fdab4SAndrew Jones #include "qemu/notify.h"
36a72d4363SAndrew Jones #include "hw/boards.h"
37a72d4363SAndrew Jones #include "hw/arm/arm.h"
38afe0b380SShannon Zhao 
39bd204e63SChristoffer Dall #define NUM_GICV2M_SPIS       64
40afe0b380SShannon Zhao #define NUM_VIRTIO_TRANSPORTS 32
41afe0b380SShannon Zhao 
42ee246400SShannon Zhao #define ARCH_TIMER_VIRT_IRQ   11
43ee246400SShannon Zhao #define ARCH_TIMER_S_EL1_IRQ  13
44ee246400SShannon Zhao #define ARCH_TIMER_NS_EL1_IRQ 14
45ee246400SShannon Zhao #define ARCH_TIMER_NS_EL2_IRQ 10
46ee246400SShannon Zhao 
4701fe6b60SShannon Zhao #define VIRTUAL_PMU_IRQ 7
4801fe6b60SShannon Zhao 
4901fe6b60SShannon Zhao #define PPI(irq) ((irq) + 16)
5001fe6b60SShannon Zhao 
51afe0b380SShannon Zhao enum {
52afe0b380SShannon Zhao     VIRT_FLASH,
53afe0b380SShannon Zhao     VIRT_MEM,
54afe0b380SShannon Zhao     VIRT_CPUPERIPHS,
55afe0b380SShannon Zhao     VIRT_GIC_DIST,
56afe0b380SShannon Zhao     VIRT_GIC_CPU,
57b92ad394SPavel Fedin     VIRT_GIC_V2M,
58b92ad394SPavel Fedin     VIRT_GIC_ITS,
59b92ad394SPavel Fedin     VIRT_GIC_REDIST,
60afe0b380SShannon Zhao     VIRT_UART,
61afe0b380SShannon Zhao     VIRT_MMIO,
62afe0b380SShannon Zhao     VIRT_RTC,
63afe0b380SShannon Zhao     VIRT_FW_CFG,
64afe0b380SShannon Zhao     VIRT_PCIE,
656a1f001bSShannon Zhao     VIRT_PCIE_MMIO,
666a1f001bSShannon Zhao     VIRT_PCIE_PIO,
676a1f001bSShannon Zhao     VIRT_PCIE_ECAM,
685f7a5a0eSEric Auger     VIRT_PLATFORM_BUS,
695125f9cdSPavel Fedin     VIRT_PCIE_MMIO_HIGH,
70b0a3721eSShannon Zhao     VIRT_GPIO,
713df708ebSPeter Maydell     VIRT_SECURE_UART,
7283ec1923SPeter Maydell     VIRT_SECURE_MEM,
73afe0b380SShannon Zhao };
74afe0b380SShannon Zhao 
75afe0b380SShannon Zhao typedef struct MemMapEntry {
76afe0b380SShannon Zhao     hwaddr base;
77afe0b380SShannon Zhao     hwaddr size;
78afe0b380SShannon Zhao } MemMapEntry;
79afe0b380SShannon Zhao 
80d05fdab4SAndrew Jones typedef struct VirtGuestInfo {
81d05fdab4SAndrew Jones     int smp_cpus;
82d05fdab4SAndrew Jones     FWCfgState *fw_cfg;
83d05fdab4SAndrew Jones     const MemMapEntry *memmap;
84d05fdab4SAndrew Jones     const int *irqmap;
85d05fdab4SAndrew Jones     bool use_highmem;
86d05fdab4SAndrew Jones     int gic_version;
87d05fdab4SAndrew Jones     bool no_its;
88d05fdab4SAndrew Jones } VirtGuestInfo;
89afe0b380SShannon Zhao 
90a72d4363SAndrew Jones typedef struct {
91a72d4363SAndrew Jones     MachineClass parent;
92a72d4363SAndrew Jones     bool disallow_affinity_adjustment;
93a72d4363SAndrew Jones     bool no_its;
94a72d4363SAndrew Jones     bool no_pmu;
95a72d4363SAndrew Jones     bool claim_edge_triggered_timers;
96a72d4363SAndrew Jones } VirtMachineClass;
97a72d4363SAndrew Jones 
98a72d4363SAndrew Jones typedef struct {
99a72d4363SAndrew Jones     MachineState parent;
100a72d4363SAndrew Jones     VirtGuestInfo acpi_guest_info;
101a72d4363SAndrew Jones     Notifier machine_done;
102a72d4363SAndrew Jones     bool secure;
103a72d4363SAndrew Jones     bool highmem;
104a72d4363SAndrew Jones     int32_t gic_version;
105a72d4363SAndrew Jones     struct arm_boot_info bootinfo;
106a72d4363SAndrew Jones     const MemMapEntry *memmap;
107a72d4363SAndrew Jones     const int *irqmap;
108a72d4363SAndrew Jones     int smp_cpus;
109a72d4363SAndrew Jones     void *fdt;
110a72d4363SAndrew Jones     int fdt_size;
111a72d4363SAndrew Jones     uint32_t clock_phandle;
112a72d4363SAndrew Jones     uint32_t gic_phandle;
113a72d4363SAndrew Jones     uint32_t msi_phandle;
114a72d4363SAndrew Jones     bool using_psci;
115a72d4363SAndrew Jones } VirtMachineState;
116a72d4363SAndrew Jones 
117a72d4363SAndrew Jones #define TYPE_VIRT_MACHINE   MACHINE_TYPE_NAME("virt")
118a72d4363SAndrew Jones #define VIRT_MACHINE(obj) \
119a72d4363SAndrew Jones     OBJECT_CHECK(VirtMachineState, (obj), TYPE_VIRT_MACHINE)
120a72d4363SAndrew Jones #define VIRT_MACHINE_GET_CLASS(obj) \
121a72d4363SAndrew Jones     OBJECT_GET_CLASS(VirtMachineClass, obj, TYPE_VIRT_MACHINE)
122a72d4363SAndrew Jones #define VIRT_MACHINE_CLASS(klass) \
123a72d4363SAndrew Jones     OBJECT_CLASS_CHECK(VirtMachineClass, klass, TYPE_VIRT_MACHINE)
124a72d4363SAndrew Jones 
125*e9a8e474SAndrew Jones void virt_acpi_setup(VirtMachineState *vms);
126d05fdab4SAndrew Jones 
127d05fdab4SAndrew Jones #endif /* QEMU_ARM_VIRT_H */
128