1use remain::sorted;
8use serde::Deserialize;
9use serde::Serialize;
10use thiserror::Error;
11
12pub use crate::address_range::AddressRange;
13pub use crate::pci_address::Error as PciAddressError;
14pub use crate::pci_address::PciAddress;
15pub use crate::system_allocator::AllocOptions;
16pub use crate::system_allocator::MmioType;
17pub use crate::system_allocator::SystemAllocator;
18pub use crate::system_allocator::SystemAllocatorConfig;
19
20pub mod address_allocator;
21mod address_range;
22mod pci_address;
23mod system_allocator;
24
25#[derive(Debug, Eq, PartialEq, Hash, Copy, Clone, Serialize, Deserialize)]
27pub enum Alloc {
28 Anon(usize),
32 PciBar { bus: u8, dev: u8, func: u8, bar: u8 },
34 GpuRenderNode,
36 PmemDevice(usize),
38 Pstore,
40 PciBridgeWindow { bus: u8, dev: u8, func: u8 },
42 PciBridgePrefetchWindow { bus: u8, dev: u8, func: u8 },
44 FileBacked(u64),
46}
47
48#[sorted]
49#[derive(Error, Debug, Eq, PartialEq)]
50pub enum Error {
51 #[error("Allocation cannot have size of 0")]
52 AllocSizeZero,
53 #[error("Pool alignment must be a power of 2")]
54 BadAlignment,
55 #[error("Alloc does not exist: {0:?}")]
56 BadAlloc(Alloc),
57 #[error("Alloc already exists: {0:?}")]
58 ExistingAlloc(Alloc),
59 #[error("Invalid Alloc: {0:?}")]
60 InvalidAlloc(Alloc),
61 #[error("IO port out of range: {0}")]
62 IOPortOutOfRange(AddressRange),
63 #[error("Platform MMIO address range not specified")]
64 MissingPlatformMMIOAddresses,
65 #[error("No IO address range specified")]
66 NoIoAllocator,
67 #[error("Out of bounds")]
68 OutOfBounds,
69 #[error("Out of space")]
70 OutOfSpace,
71 #[error("base={base} + size={size} overflows")]
72 PoolOverflow { base: u64, size: u64 },
73 #[error("Overlapping region {0}")]
74 RegionOverlap(AddressRange),
75}
76
77pub type Result<T> = std::result::Result<T, Error>;