Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ad02b90
Implement memory regions iterators
moojek Apr 26, 2026
031526a
Allow arbitrary number of pairs in reg property
moojek May 2, 2026
c1f7472
Respect address and size cells in reserved memory regions lookup
moojek May 2, 2026
23fc0b0
Remove misplaced helper function from dt lib
moojek May 2, 2026
7b41f1c
Fix build
moojek May 2, 2026
b4a81ec
Do not check for node name when determining if memory node
moojek May 3, 2026
b20a8be
Remove redundant error checks for reserved memory node retrieval
moojek May 3, 2026
980fd9e
Simplify functions for getting memory regions
moojek May 3, 2026
77a96e8
Initialize fdt only once
moojek May 3, 2026
f826471
Remove redundant `has_node` flag
moojek May 3, 2026
a97d936
Do not change iter on failure
moojek May 3, 2026
ce93b8b
Simplify error handling
moojek May 3, 2026
02aa168
Fix logic flow
moojek May 23, 2026
92d5ce0
Add docs for memory regions management
moojek May 23, 2026
6bc5abf
Add test infrastructure (#101)
dawidpawliczek4 May 4, 2026
c9128fb
Implement clock controller (#93)
moojek May 6, 2026
63da598
Added hal address space interface (#102)
frogrammer9 May 6, 2026
a42e297
fixed code structure regarding clock and timer interfaces (#106)
frogrammer9 May 13, 2026
99acc82
added a utility library for version and updated docs (#108)
frogrammer9 May 21, 2026
68600e2
Fix formatting
moojek May 23, 2026
497b9d8
Fix merge issues
moojek May 23, 2026
9de9e76
Merge branch 'main' into memory_regions
moojek May 23, 2026
e844de2
Fix compiler warnings
moojek May 23, 2026
0980f6d
Add simple memory regions mgmt tests
moojek May 23, 2026
03e679a
Fix clang-tidy warnings
moojek May 25, 2026
b7823ca
Refactor FDT initialization logic
moojek Jun 7, 2026
ec26b67
Fix memory regions docs
moojek Jun 7, 2026
7fbeb1a
Merge branch 'main' into memory_regions
moojek Jun 7, 2026
db406a6
Fix merge
moojek Jun 7, 2026
ec6b4c9
Fix UT
moojek Jun 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions CMake/TestsConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@ function(SETUP_UNIT_TEST name)
add_executable(${name})
SETUP_COMMON(${name})

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS *.c)
file(GLOB_RECURSE HEADERS CONFIGURE_DEPENDS *.h)
file(GLOB_RECURSE HEADERS CONFIGURE_DEPENDS *.h)

target_sources(${name}
PRIVATE
${SOURCES}
${ARGN}
PRIVATE
FILE_SET HEADERS
BASE_DIRS .
FILES ${HEADERS}
)
# If explicit sources were passed to the macro, use them only.
if (ARGN)
set(EXPLICIT_SOURCES ${ARGN})
else()
file(GLOB_RECURSE EXPLICIT_SOURCES CONFIGURE_DEPENDS *.c)
endif()

target_link_libraries(${name} PRIVATE unity)
target_sources(${name}
PRIVATE
${EXPLICIT_SOURCES}
PRIVATE
FILE_SET HEADERS
BASE_DIRS .
FILES ${HEADERS}
)

# Link common libraries required by tests that reference core helpers and DT parsing.
target_link_libraries(${name} PRIVATE unity libcore libboot_dt)

add_test(NAME ${name} COMMAND ${name})

Expand Down
1 change: 1 addition & 0 deletions docs/doxygen/groups.dox
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@defgroup palloc Physical memory allocator
@defgroup kinit Kernel initialization
@defgroup hal Hardware abstraction layer
@defgroup hal_riscv_mem RISC-V memory regions
@defgroup libboot_dt
@defgroup libcore
@defgroup sbi
Expand Down
1 change: 1 addition & 0 deletions docs/source/pages/api/kernel/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Internal kernel APIs
:maxdepth: 1

mm/index
memory_regions

40 changes: 40 additions & 0 deletions docs/source/pages/api/kernel/memory_regions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
=======================
Memory regions
=======================

This module provides iterators to enumerate memory regions from the device tree:

- **Memory regions**: Physical memory regions available for use (from /memory nodes)
- **Reserved regions**: Memory ranges reserved by the system and must not be allocated
(from /reserved-memory node and memory reservations)

Usage Pattern
=============

Both iterators follow the same init-then-iterate pattern:

.. code-block:: c

// Initialize iterator
hal_memory_iterator_t iter;
if (hal_get_memory_regions_iterator(&iter) != ERR_NONE)
return; // Handle error

// Iterate through regions
physical_memory_region_t region;
while (hal_get_next_memory_region(&iter, &region) == ERR_NONE) {
// Process region
}
// Loop exits when hal_get_next_memory_region returns ERR_NOT_FOUND

Return Value Semantics
======================

- ``ERR_NONE``: Successfully retrieved next region; output parameter is valid
- ``ERR_NOT_FOUND``: End of iteration reached (normal termination, not an error)
- Other error codes: Actual error occurred; output parameters remain unchanged

API Reference
=============

.. doxygengroup:: hal_riscv_mem
13 changes: 13 additions & 0 deletions include/libboot/dt/dt.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,19 @@ error_t dt_get_prop_buffer(const fdt_t* fdt, dt_prop_t prop, buffer_t* bufOUT);
[[gnu::nonnull(3)]]
error_t dt_get_rsv_mem_entry(const fdt_t* fdt, u32 index, fdt_rsv_entry* entryOUT);

/**
* @brief Get #address-cells and #size-cells properties from a node.
* @param fdt Pointer to the fdt object.
* @param node The node to read cell counts from.
* @param[out] address_cellsOUT Number of address cells (default 2).
* @param[out] size_cellsOUT Number of size cells (default 1).
* @retval ERR_NONE on success
* @retval ERR_BAD_ARG on nullptr args
* @retval ERR_NOT_VALID if the FDT is invalid or cell counts exceed 2
*/
[[gnu::nonnull(3, 4)]]
error_t dt_get_reg_cell_counts(const fdt_t* fdt, dt_node_t node, u32* address_cellsOUT, u32* size_cellsOUT);

/// @}

#endif // !DT_DT
Loading
Loading