Add SparseMemoryRegion object
Signed-off-by: Alex Forencich <alex@alexforencich.com>
This commit is contained in:
@@ -27,7 +27,7 @@ from .version import __version__
|
|||||||
from .constants import AxiBurstType, AxiBurstSize, AxiLockType, AxiCacheBit, AxiProt, AxiResp
|
from .constants import AxiBurstType, AxiBurstSize, AxiLockType, AxiCacheBit, AxiProt, AxiResp
|
||||||
|
|
||||||
from .address_space import MemoryInterface, Window, WindowPool
|
from .address_space import MemoryInterface, Window, WindowPool
|
||||||
from .address_space import Region, MemoryRegion, PeripheralRegion
|
from .address_space import Region, MemoryRegion, SparseMemoryRegion, PeripheralRegion
|
||||||
from .address_space import AddressSpace, Pool
|
from .address_space import AddressSpace, Pool
|
||||||
|
|
||||||
from .axis import AxiStreamFrame, AxiStreamBus, AxiStreamSource, AxiStreamSink, AxiStreamMonitor
|
from .axis import AxiStreamFrame, AxiStreamBus, AxiStreamSource, AxiStreamSink, AxiStreamMonitor
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ THE SOFTWARE.
|
|||||||
import mmap
|
import mmap
|
||||||
|
|
||||||
from .buddy_allocator import BuddyAllocator
|
from .buddy_allocator import BuddyAllocator
|
||||||
|
from .sparse_memory import SparseMemory
|
||||||
from .utils import hexdump, hexdump_lines, hexdump_str
|
from .utils import hexdump, hexdump_lines, hexdump_str
|
||||||
|
|
||||||
|
|
||||||
@@ -216,6 +217,35 @@ class MemoryRegion(Region):
|
|||||||
return bytes(self.mem)
|
return bytes(self.mem)
|
||||||
|
|
||||||
|
|
||||||
|
class SparseMemoryRegion(Region):
|
||||||
|
def __init__(self, size=2**64, mem=None, **kwargs):
|
||||||
|
super().__init__(size, **kwargs)
|
||||||
|
if mem is None:
|
||||||
|
mem = SparseMemory(size)
|
||||||
|
self.mem = mem
|
||||||
|
|
||||||
|
async def _read(self, address, length, **kwargs):
|
||||||
|
return self.mem.read(address, length)
|
||||||
|
|
||||||
|
async def _write(self, address, data, **kwargs):
|
||||||
|
self.mem.write(address, data)
|
||||||
|
|
||||||
|
def hexdump(self, address, length, prefix=""):
|
||||||
|
self.mem.hexdump(address, length, prefix=prefix)
|
||||||
|
|
||||||
|
def hexdump_lines(self, address, length, prefix=""):
|
||||||
|
return self.mem.hexdump_lines(address, length, prefix=prefix)
|
||||||
|
|
||||||
|
def hexdump_str(self, address, length, prefix=""):
|
||||||
|
return self.mem.hexdump_str(address, length, prefix=prefix)
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
return self.mem[key]
|
||||||
|
|
||||||
|
def __setitem__(self, key, value):
|
||||||
|
self.mem[key] = value
|
||||||
|
|
||||||
|
|
||||||
class PeripheralRegion(Region):
|
class PeripheralRegion(Region):
|
||||||
def __init__(self, obj, size, **kwargs):
|
def __init__(self, obj, size, **kwargs):
|
||||||
super().__init__(size, **kwargs)
|
super().__init__(size, **kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user