104331d0bSMichael Clark /* 25b558380SMichael Clark * QEMU RISC-V VirtIO machine interface 304331d0bSMichael Clark * 404331d0bSMichael Clark * Copyright (c) 2017 SiFive, Inc. 504331d0bSMichael Clark * 604331d0bSMichael Clark * This program is free software; you can redistribute it and/or modify it 704331d0bSMichael Clark * under the terms and conditions of the GNU General Public License, 804331d0bSMichael Clark * version 2 or later, as published by the Free Software Foundation. 904331d0bSMichael Clark * 1004331d0bSMichael Clark * This program is distributed in the hope it will be useful, but WITHOUT 1104331d0bSMichael Clark * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1204331d0bSMichael Clark * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 1304331d0bSMichael Clark * more details. 1404331d0bSMichael Clark * 1504331d0bSMichael Clark * You should have received a copy of the GNU General Public License along with 1604331d0bSMichael Clark * this program. If not, see <http://www.gnu.org/licenses/>. 1704331d0bSMichael Clark */ 1804331d0bSMichael Clark 194996b128SMichael Clark #ifndef HW_RISCV_VIRT_H 204996b128SMichael Clark #define HW_RISCV_VIRT_H 2104331d0bSMichael Clark 22ec150c7eSMarkus Armbruster #include "hw/riscv/riscv_hart.h" 23ec150c7eSMarkus Armbruster #include "hw/sysbus.h" 2471eb522cSAlistair Francis #include "hw/block/flash.h" 25ec150c7eSMarkus Armbruster 26cdfc19e4SAlistair Francis #define TYPE_RISCV_VIRT_MACHINE MACHINE_TYPE_NAME("virt") 27cdfc19e4SAlistair Francis #define RISCV_VIRT_MACHINE(obj) \ 28cdfc19e4SAlistair Francis OBJECT_CHECK(RISCVVirtState, (obj), TYPE_RISCV_VIRT_MACHINE) 29cdfc19e4SAlistair Francis 3004331d0bSMichael Clark typedef struct { 3104331d0bSMichael Clark /*< private >*/ 32cdfc19e4SAlistair Francis MachineState parent; 3304331d0bSMichael Clark 3404331d0bSMichael Clark /*< public >*/ 3504331d0bSMichael Clark RISCVHartArrayState soc; 3604331d0bSMichael Clark DeviceState *plic; 3771eb522cSAlistair Francis PFlashCFI01 *flash[2]; 38cdfc19e4SAlistair Francis 3904331d0bSMichael Clark void *fdt; 4004331d0bSMichael Clark int fdt_size; 4104331d0bSMichael Clark } RISCVVirtState; 4204331d0bSMichael Clark 4304331d0bSMichael Clark enum { 4404331d0bSMichael Clark VIRT_DEBUG, 4504331d0bSMichael Clark VIRT_MROM, 4604331d0bSMichael Clark VIRT_TEST, 47*67b5ef30SAnup Patel VIRT_RTC, 4804331d0bSMichael Clark VIRT_CLINT, 4904331d0bSMichael Clark VIRT_PLIC, 5004331d0bSMichael Clark VIRT_UART0, 5104331d0bSMichael Clark VIRT_VIRTIO, 5271eb522cSAlistair Francis VIRT_FLASH, 536d56e396SAlistair Francis VIRT_DRAM, 546d56e396SAlistair Francis VIRT_PCIE_MMIO, 556d56e396SAlistair Francis VIRT_PCIE_PIO, 566d56e396SAlistair Francis VIRT_PCIE_ECAM 5704331d0bSMichael Clark }; 5804331d0bSMichael Clark 5904331d0bSMichael Clark enum { 6004331d0bSMichael Clark UART0_IRQ = 10, 61*67b5ef30SAnup Patel RTC_IRQ = 11, 6204331d0bSMichael Clark VIRTIO_IRQ = 1, /* 1 to 8 */ 6304331d0bSMichael Clark VIRTIO_COUNT = 8, 646d56e396SAlistair Francis PCIE_IRQ = 0x20, /* 32 to 35 */ 6563b695f2SAlistair Francis VIRTIO_NDEV = 0x35 /* Arbitrary maximum number of interrupts */ 6604331d0bSMichael Clark }; 6704331d0bSMichael Clark 6804331d0bSMichael Clark #define VIRT_PLIC_HART_CONFIG "MS" 6904331d0bSMichael Clark #define VIRT_PLIC_NUM_SOURCES 127 7004331d0bSMichael Clark #define VIRT_PLIC_NUM_PRIORITIES 7 710feb4a71SAlistair Francis #define VIRT_PLIC_PRIORITY_BASE 0x04 7204331d0bSMichael Clark #define VIRT_PLIC_PENDING_BASE 0x1000 7304331d0bSMichael Clark #define VIRT_PLIC_ENABLE_BASE 0x2000 7404331d0bSMichael Clark #define VIRT_PLIC_ENABLE_STRIDE 0x80 7504331d0bSMichael Clark #define VIRT_PLIC_CONTEXT_BASE 0x200000 7604331d0bSMichael Clark #define VIRT_PLIC_CONTEXT_STRIDE 0x1000 7704331d0bSMichael Clark 786d56e396SAlistair Francis #define FDT_PCI_ADDR_CELLS 3 796d56e396SAlistair Francis #define FDT_PCI_INT_CELLS 1 806d56e396SAlistair Francis #define FDT_PLIC_ADDR_CELLS 0 816d56e396SAlistair Francis #define FDT_PLIC_INT_CELLS 1 826d56e396SAlistair Francis #define FDT_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + 1 + \ 836d56e396SAlistair Francis FDT_PLIC_ADDR_CELLS + FDT_PLIC_INT_CELLS) 846d56e396SAlistair Francis 8504331d0bSMichael Clark #if defined(TARGET_RISCV32) 868903bf6eSAlistair Francis #define VIRT_CPU TYPE_RISCV_CPU_BASE32 8704331d0bSMichael Clark #elif defined(TARGET_RISCV64) 888903bf6eSAlistair Francis #define VIRT_CPU TYPE_RISCV_CPU_BASE64 8904331d0bSMichael Clark #endif 9004331d0bSMichael Clark 9104331d0bSMichael Clark #endif 92