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) VIRTIO_MMIO 50 51 #define VIRTIO_RING_ENDIAN VIRTIO_ENDIAN_LE 52 53 #define ARCH_HAS_PCI_EXP 1 54 55 struct kvm; 56 57 struct kvm_arch { 58 /* 59 * We may have to align the guest memory for virtio, so keep the 60 * original pointers here for munmap. 61 */ 62 void *ram_alloc_start; 63 u64 ram_alloc_size; 64 65 /* 66 * Guest addresses for memory layout. 67 */ 68 u64 memory_guest_start; 69 u64 kern_guest_start; 70 u64 initrd_guest_start; 71 u64 initrd_size; 72 u64 dtb_guest_start; 73 }; 74 75 static inline bool riscv_addr_in_ioport_region(u64 phys_addr) 76 { 77 u64 limit = KVM_IOPORT_AREA + RISCV_IOPORT_SIZE; 78 return phys_addr >= KVM_IOPORT_AREA && phys_addr < limit; 79 } 80 81 enum irq_type; 82 83 #endif /* KVM__KVM_ARCH_H */ 84