1 // Copyright © 2024 Institute of Software, CAS. All rights reserved. 2 // Copyright 2020 Arm Limited (or its affiliates). All rights reserved. 3 // Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 // SPDX-License-Identifier: Apache-2.0 5 6 // 7 // Memory layout of RISC-V 64-bit guest: 8 // 9 // Physical +---------------------------------------------------------------+ 10 // address | | 11 // end | | 12 // ~ ~ ~ ~ 13 // | | 14 // | Highmem PCI MMIO space | 15 // | | 16 // RAM end +---------------------------------------------------------------+ 17 // (dynamic, | | 18 // including | | 19 // hotplug ~ ~ ~ ~ 20 // memory) | | 21 // | DRAM | 22 // | | 23 // | | 24 // | | 25 // | | 26 // 1 GB +---------------------------------------------------------------+ 27 // | | 28 // | PCI MMCONFIG space | 29 // | | 30 // 768 MB +---------------------------------------------------------------+ 31 // | | 32 // | | 33 // | PCI MMIO space | 34 // | | 35 // 256 MB +---------------------------------------------------------------| 36 // | | 37 // | Legacy devices space | 38 // | | 39 // 128 MB +---------------------------------------------------------------| 40 // | | 41 // | IMSICs | 42 // | | 43 // 64 MB +---------------------------------------------------------------+ 44 // | | 45 // | APLICs | 46 // | | 47 // 0 GB +---------------------------------------------------------------+ 48 // 49 // 50 51 use vm_memory::GuestAddress; 52 53 /// AIA related devices 54 /// See https://elixir.bootlin.com/linux/v6.10/source/arch/riscv/include/uapi/asm/kvm.h 55 /// 0x0 ~ 0x0400_0000 (64 MiB) resides APLICs 56 pub const APLIC_START: GuestAddress = GuestAddress(0); 57 pub const APLIC_SIZE: u64 = 0x4000; 58 59 /// 0x0400_0000 ~ 0x0800_0000 (64 MiB) resides IMSICs 60 pub const IMSIC_START: GuestAddress = GuestAddress(0x0400_0000); 61 pub const IMSIC_SIZE: u64 = 0x1000; 62 63 /// Below this address will reside the AIA, above this address will reside the MMIO devices. 64 const MAPPED_IO_START: GuestAddress = GuestAddress(0x0800_0000); 65 66 /// Space 0x0800_0000 ~ 0x1000_0000 is reserved for legacy devices. 67 pub const LEGACY_SERIAL_MAPPED_IO_START: GuestAddress = MAPPED_IO_START; 68 69 /// Space 0x0905_0000 ~ 0x0906_0000 is reserved for pcie io address 70 pub const MEM_PCI_IO_START: GuestAddress = GuestAddress(0x0905_0000); 71 pub const MEM_PCI_IO_SIZE: u64 = 0x1_0000; 72 73 /// Starting from 0x1000_0000 (256MiB) to 0x3000_0000 (768MiB) is used for PCIE MMIO 74 pub const MEM_32BIT_DEVICES_START: GuestAddress = GuestAddress(0x1000_0000); 75 pub const MEM_32BIT_DEVICES_SIZE: u64 = 0x2000_0000; 76 77 /// PCI MMCONFIG space (start: after the device space at 768MiB, length: 256MiB) 78 pub const PCI_MMCONFIG_START: GuestAddress = GuestAddress(0x3000_0000); 79 pub const PCI_MMCONFIG_SIZE: u64 = 256 << 20; 80 // One bus with potentially 256 devices (32 slots x 8 functions). 81 pub const PCI_MMIO_CONFIG_SIZE_PER_SEGMENT: u64 = 4096 * 256; 82 83 /// Start of RAM. 84 pub const RAM_START: GuestAddress = GuestAddress(0x4000_0000); 85 86 /// Kernel command line maximum size on RISC-V. 87 /// See https://elixir.bootlin.com/linux/v6.10/source/arch/riscv/include/uapi/asm/setup.h 88 pub const CMDLINE_MAX_SIZE: usize = 1024; 89 90 /// FDT is at the beginning of RAM. 91 pub const FDT_START: GuestAddress = RAM_START; 92 pub const FDT_MAX_SIZE: u64 = 0x1_0000; 93 94 /// Kernel start after FDT 95 pub const KERNEL_START: GuestAddress = GuestAddress(RAM_START.0 + FDT_MAX_SIZE); 96 97 /// Pci high memory base 98 pub const PCI_HIGH_BASE: GuestAddress = GuestAddress(0x2_0000_0000); 99 100 /// First usable interrupt on riscv64 101 pub const IRQ_BASE: u32 = 0; 102 103 // As per https://elixir.bootlin.com/linux/v6.10/source/arch/riscv/include/asm/kvm_host.h#L31 104 /// Number of supported interrupts 105 pub const IRQ_NUM: u32 = 1023; 106