20 for (
size_t i = 0; i < mdl->
amount; i++)
88 if (newSegments !=
NULL)
98 if (newSegments ==
NULL)
128 size_t remaining = size;
130 while (remaining > 0)
162 for (; i < mdl->
amount; i++)
173 size_t remaining =
count;
176 while (remaining > 0 && i < mdl->amount)
179 size_t toRead =
MIN(remaining, seg->
size - segOffset);
181 memcpy(ptr, addr, toRead);
189 return count - remaining;
201 for (; i < mdl->
amount; i++)
212 size_t remaining =
count;
215 while (remaining > 0 && i < mdl->amount)
218 size_t toWrite =
MIN(remaining, seg->
size - segOffset);
220 memcpy(addr, ptr, toWrite);
223 remaining -= toWrite;
228 return count - remaining;
EFI_PHYSICAL_ADDRESS buffer
uint64_t mdl_write(mdl_t *mdl, const void *buffer, size_t count, size_t offset)
Write to a Memory Descriptor List from a buffer.
void mdl_free_chain(mdl_t *mdl, void(*free)(void *))
Free a Memory Descriptor List chain.
void mdl_deinit(mdl_t *mdl)
Deinitialize a Memory Descriptor List.
uint64_t mdl_from_region(mdl_t *mdl, mdl_t *prev, space_t *space, const void *addr, size_t size)
Initialize a Memory Descriptor List from a memory region.
static void mdl_init(mdl_t *next, mdl_t *prev)
Initialize a Memory Descriptor List.
uint64_t mdl_add(mdl_t *mdl, space_t *space, const void *addr, size_t size)
Add a memory region to the Memory Descriptor List.
uint64_t mdl_read(mdl_t *mdl, void *buffer, size_t count, size_t offset)
Read from a Memory Descriptor List into a buffer.
uintptr_t phys_addr_t
Physical address type.
#define PHYS_TO_PFN(_addr)
Convert a physical address to its PFN.
#define PFN_TO_VIRT(_pfn)
Convert a PFN to its identity mapped higher half virtual address.
size_t pfn_t
Page Frame Number type.
static void pmm_ref_dec(pfn_t pfn, size_t count)
Decrement the reference count of a physical region.
uint64_t pmm_ref_inc(pfn_t pfn, size_t count)
Increment the reference count of a physical region.
phys_addr_t space_virt_to_phys(space_t *space, const void *virtAddr)
Translate a virtual address to a physical address in the address space.
#define EINVAL
Invalid argument.
#define EFAULT
Bad address.
#define ENOMEM
Out of memory.
#define EOVERFLOW
Value too large for defined data type.
#define errno
Error number variable.
#define BYTES_TO_PAGES(amount)
Convert a size in bytes to pages.
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define PAGE_SIZE
The size of a memory page in bytes.
static uint64_t mdl_push(mdl_t *mdl, phys_addr_t phys, size_t size)
_PUBLIC void * realloc(void *ptr, size_t size)
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
Memory Descriptor List Segment structure.
uint32_t offset
Offset in bytes within the first page.
pfn_t pfn
Page frame number.
uint32_t size
Size of the segment in bytes.
Memory Descriptor List structure.
uint32_t amount
Number of memory segments.
struct mdl * next
Pointer to the next MDL.
mdl_seg_t * segments
Pointer to segments array.
uint32_t capacity
Capacity of the large array.
mdl_seg_t small[MDL_SEGS_SMALL_MAX]
Statically allocated segments for small regions.
Virtual address space structure.