Before this commit, a continuous memory region can only be backed by
either a single ArcMemPages or a single MmioRange.
If a guest memory region contains both mmap()-ed pages and emulated
MMIO regions, we then need to split it into sub-regions. However,
once these sub-regions are added to the memory bus as slots, we can
no longer tell if a slot is a sub-region or a not.
It becomes difficult to handle when a guest tries to relocate
a region to a different physical address. For example, a PCI device
can re-program its BARs. We do not know if a few slots need to be
moved as a whole or not.
This commit re-designs the module `mem` by introducing `MemRegion`.
* From guest's point of view, it can have multiple sub-regions of
different e820 types.
* From host's point of view, it is a collection of mmap()-ed host
memories, emulated MMIO regions, and maybe some holes in between.
Backends are grouped so they can be moved easily.
It also enables us to allocate the address for a group of slots.
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
Similar to b82af2a ("refactor(mmio): simplify MmioBus
implementation"), a future commit will provide a general solution
for both mmap()-ed pages and emulated MMIO regions.
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
The name `UserMem` was from KVM. `MemPages` sounds more
straightforward, indicating it is just a few pages requested directly
from the OS.
The name `ArcMemPages` indicates that it is cheap to call clone().
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
Remove the mapped(), ummapped() method from the Mmio trait, since
generally mmap()-ed pages should also have these callbacks. A future
commit will provide a general solution.
Remove the unnecessary intermediate struct MmioRange.
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
There is no need to introduce a new module to model the IO bus.
MMIO and IO are basically the same thing except the address width.
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
If the last 0x2000 bytes of the address range have been occupied,
adding another backend for the last 0x1000 bytes is supposed to
fail, but does not with the current implementation, due to the
numeric overflow in addr_end().
Signed-off-by: Changyuan Lyu <changyuanl@google.com>