xref: /kvmtool/riscv/include/kvm/kvm-arch.h (revision 5fe5eb04de80b8bc68f4d57443596d0b935907ef)
1 #ifndef KVM__KVM_ARCH_H
2 #define KVM__KVM_ARCH_H
3 
4 #include <stdbool.h>
5 #include <linux/const.h>
6 #include <linux/sizes.h>
7 #include <linux/types.h>
8 
9 #define MAX_PAGE_SIZE		SZ_4K
10 
11 #define RISCV_IOPORT		0x00000000ULL
12 #define RISCV_IOPORT_SIZE	SZ_64K
13 #define RISCV_PLIC		0x0c000000ULL
14 #define RISCV_PLIC_SIZE		SZ_64M
15 #define RISCV_MMIO		0x10000000ULL
16 #define RISCV_MMIO_SIZE		SZ_512M
17 #define RISCV_PCI		0x30000000ULL
18 /*
19  * KVMTOOL emulates legacy PCI config space with 24bits device address
20  * so 16M is sufficient but we reserve 256M to keep it future ready for
21  * PCIe config space with 28bits device address.
22  */
23 #define RISCV_PCI_CFG_SIZE	SZ_256M
24 #define RISCV_PCI_MMIO_SIZE	SZ_1G
25 #define RISCV_PCI_SIZE		(RISCV_PCI_CFG_SIZE + RISCV_PCI_MMIO_SIZE)
26 
27 #define RISCV_RAM		0x80000000ULL
28 
29 #define RISCV_LOMAP_MAX_MEMORY	((1ULL << 32) - RISCV_RAM)
30 #define RISCV_HIMAP_MAX_MEMORY	((1ULL << 40) - RISCV_RAM)
31 
32 #if __riscv_xlen == 64
33 #define RISCV_MAX_MEMORY(kvm)	RISCV_HIMAP_MAX_MEMORY
34 #elif __riscv_xlen == 32
35 #define RISCV_MAX_MEMORY(kvm)	RISCV_LOMAP_MAX_MEMORY
36 #endif
37 
38 #define KVM_IOPORT_AREA		RISCV_IOPORT
39 #define KVM_PCI_CFG_AREA	RISCV_PCI
40 #define KVM_PCI_MMIO_AREA	(KVM_PCI_CFG_AREA + RISCV_PCI_CFG_SIZE)
41 #define KVM_VIRTIO_MMIO_AREA	RISCV_MMIO
42 
43 #define KVM_IOEVENTFD_HAS_PIO	0
44 
45 #define KVM_IRQ_OFFSET		1
46 
47 #define KVM_VM_TYPE		0
48 
49 #define VIRTIO_DEFAULT_TRANS(kvm) \
50 	((kvm)->cfg.virtio_legacy ? VIRTIO_MMIO_LEGACY : VIRTIO_MMIO)
51 
52 #define VIRTIO_RING_ENDIAN	VIRTIO_ENDIAN_LE
53 
54 #define ARCH_HAS_PCI_EXP	1
55 
56 struct kvm;
57 
58 struct kvm_arch {
59 	/*
60 	 * We may have to align the guest memory for virtio, so keep the
61 	 * original pointers here for munmap.
62 	 */
63 	void	*ram_alloc_start;
64 	u64	ram_alloc_size;
65 
66 	/*
67 	 * Guest addresses for memory layout.
68 	 */
69 	u64	memory_guest_start;
70 	u64	kern_guest_start;
71 	u64	initrd_guest_start;
72 	u64	initrd_size;
73 	u64	dtb_guest_start;
74 };
75 
76 static inline bool riscv_addr_in_ioport_region(u64 phys_addr)
77 {
78 	u64 limit = KVM_IOPORT_AREA + RISCV_IOPORT_SIZE;
79 	return phys_addr >= KVM_IOPORT_AREA && phys_addr < limit;
80 }
81 
82 enum irq_type;
83 
84 void plic__generate_irq_prop(void *fdt, u8 irq, enum irq_type irq_type);
85 
86 void plic__irq_trig(struct kvm *kvm, int irq, int level, bool edge);
87 
88 void pci__generate_fdt_nodes(void *fdt);
89 
90 #endif /* KVM__KVM_ARCH_H */
91