|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// Copyright (C) 2022 Akira Moroo |
| 3 | +// Copyright (c) 2021-2022 Andre Richter <andre.o.richter@gmail.com> |
| 4 | + |
| 5 | +use core::ops::RangeInclusive; |
| 6 | + |
| 7 | +use super::paging::*; |
| 8 | + |
| 9 | +pub mod map { |
| 10 | + pub const END: usize = 0x1_0000_0000; |
| 11 | + |
| 12 | + pub mod fw { |
| 13 | + pub const START: usize = 0x0000_0000; |
| 14 | + pub const END: usize = 0x0040_0000; |
| 15 | + } |
| 16 | + pub mod mmio { |
| 17 | + pub const START: usize = super::fw::END; |
| 18 | + pub const PL011_START: usize = 0x0900_0000; |
| 19 | + pub const PL031_START: usize = 0x0901_0000; |
| 20 | + pub const END: usize = 0x4000_0000; |
| 21 | + } |
| 22 | + |
| 23 | + pub mod dram { |
| 24 | + const FDT_SIZE: usize = 0x0020_0000; |
| 25 | + const ACPI_SIZE: usize = 0x0020_0000; |
| 26 | + pub const STACK_SIZE: usize = 0x0800_0000; |
| 27 | + |
| 28 | + pub const START: usize = super::mmio::END; |
| 29 | + pub const FDT_START: usize = START; |
| 30 | + pub const ACPI_START: usize = FDT_START + FDT_SIZE; |
| 31 | + pub const KERNEL_START: usize = ACPI_START + ACPI_SIZE; |
| 32 | + pub const STACK_START: usize = STACK_END - STACK_SIZE; |
| 33 | + pub const STACK_END: usize = RESERVED_START; |
| 34 | + pub const RESERVED_START: usize = 0xfc00_0000; |
| 35 | + pub const END: usize = super::END; |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +pub type KernelAddrSpace = AddressSpace<{ map::END }>; |
| 40 | + |
| 41 | +const NUM_MEM_RANGES: usize = 3; |
| 42 | + |
| 43 | +pub static LAYOUT: KernelVirtualLayout<NUM_MEM_RANGES> = KernelVirtualLayout::new( |
| 44 | + map::END - 1, |
| 45 | + [ |
| 46 | + TranslationDescriptor { |
| 47 | + name: "Firmware", |
| 48 | + virtual_range: RangeInclusive::new(map::fw::START, map::fw::END - 1), |
| 49 | + physical_range_translation: Translation::Identity, |
| 50 | + attribute_fields: AttributeFields { |
| 51 | + mem_attributes: MemAttributes::CacheableDRAM, |
| 52 | + acc_perms: AccessPermissions::ReadWrite, |
| 53 | + execute_never: false, |
| 54 | + }, |
| 55 | + }, |
| 56 | + TranslationDescriptor { |
| 57 | + name: "Device MMIO", |
| 58 | + virtual_range: RangeInclusive::new(map::mmio::START, map::mmio::END - 1), |
| 59 | + physical_range_translation: Translation::Identity, |
| 60 | + attribute_fields: AttributeFields { |
| 61 | + mem_attributes: MemAttributes::Device, |
| 62 | + acc_perms: AccessPermissions::ReadWrite, |
| 63 | + execute_never: true, |
| 64 | + }, |
| 65 | + }, |
| 66 | + TranslationDescriptor { |
| 67 | + name: "System Memory", |
| 68 | + virtual_range: RangeInclusive::new(map::dram::START, map::dram::END - 1), |
| 69 | + physical_range_translation: Translation::Identity, |
| 70 | + attribute_fields: AttributeFields { |
| 71 | + mem_attributes: MemAttributes::CacheableDRAM, |
| 72 | + acc_perms: AccessPermissions::ReadWrite, // FIXME |
| 73 | + execute_never: false, |
| 74 | + }, |
| 75 | + }, |
| 76 | + ], |
| 77 | +); |
| 78 | + |
| 79 | +pub fn virt_mem_layout() -> &'static KernelVirtualLayout<NUM_MEM_RANGES> { |
| 80 | + &LAYOUT |
| 81 | +} |
0 commit comments