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 RISCV_UART_MMIO_BASE RISCV_MMIO 39 #define RISCV_UART_MMIO_SIZE 0x10000 40 41 #define RISCV_RTC_MMIO_BASE (RISCV_UART_MMIO_BASE + RISCV_UART_MMIO_SIZE) 42 #define RISCV_RTC_MMIO_SIZE 0x10000 43 44 #define KVM_IOPORT_AREA RISCV_IOPORT 45 #define KVM_PCI_CFG_AREA RISCV_PCI 46 #define KVM_PCI_MMIO_AREA (KVM_PCI_CFG_AREA + RISCV_PCI_CFG_SIZE) 47 #define KVM_VIRTIO_MMIO_AREA (RISCV_RTC_MMIO_BASE + RISCV_RTC_MMIO_SIZE) 48 49 #define KVM_IOEVENTFD_HAS_PIO 0 50 51 #define KVM_IRQ_OFFSET 1 52 53 #define KVM_VM_TYPE 0 54 55 #define VIRTIO_RING_ENDIAN VIRTIO_ENDIAN_LE 56 57 #define ARCH_HAS_PCI_EXP 1 58 59 struct kvm; 60 61 struct kvm_arch { 62 /* 63 * We may have to align the guest memory for virtio, so keep the 64 * original pointers here for munmap. 65 */ 66 void *ram_alloc_start; 67 u64 ram_alloc_size; 68 69 /* 70 * Guest addresses for memory layout. 71 */ 72 u64 memory_guest_start; 73 u64 kern_guest_start; 74 u64 initrd_guest_start; 75 u64 initrd_size; 76 u64 dtb_guest_start; 77 }; 78 79 static inline bool riscv_addr_in_ioport_region(u64 phys_addr) 80 { 81 u64 limit = KVM_IOPORT_AREA + RISCV_IOPORT_SIZE; 82 return phys_addr >= KVM_IOPORT_AREA && phys_addr < limit; 83 } 84 85 enum irq_type; 86 87 void plic__generate_irq_prop(void *fdt, u8 irq, enum irq_type irq_type); 88 89 void plic__irq_trig(struct kvm *kvm, int irq, int level, bool edge); 90 91 void pci__generate_fdt_nodes(void *fdt); 92 93 #endif /* KVM__KVM_ARCH_H */ 94