Skip to content

Commit

Permalink
Update boot protocol to support extra memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-Velickovic authored and nspin committed Feb 5, 2024
1 parent c998966 commit 5f71dc4
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 20 deletions.
6 changes: 4 additions & 2 deletions include/arch/arm/arch/bootinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
* +1 for each MODE_RESERVED region, there might be none
* +1 to allow the kernel to release its own boot data region
* +1 for a possible gap between ELF images and rootserver objects
* +1 loader specified extra memory
*/
#define MAX_NUM_FREEMEM_REG (ARRAY_SIZE(avail_p_regs) + MODE_RESERVED + 1 + 1)
#define MAX_NUM_FREEMEM_REG (ARRAY_SIZE(avail_p_regs) + MODE_RESERVED + 1 + 1 + 1)

/* The regions reserved by the boot code are:
* +1 for kernel
* +1 for device tree binary
* +1 for user image.
* +1 extra_device
* +1 for each the MODE_RESERVED region, there might be none
*/
#define NUM_RESERVED_REGIONS (3 + MODE_RESERVED)
#define NUM_RESERVED_REGIONS (4 + MODE_RESERVED)


/* The maximum number of reserved regions is:
Expand Down
4 changes: 3 additions & 1 deletion include/arch/arm/arch/kernel/boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ void init_kernel(
sword_t pv_offset,
vptr_t v_entry,
paddr_t dtb_addr_p,
uint32_t dtb_size
uint64_t dtb_size,
paddr_t extra_device_addr_p,
uint64_t extra_device_size
);

3 changes: 2 additions & 1 deletion include/kernel/boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ bool_t provide_cap(cap_t root_cnode_cap, cap_t cap);
cap_t create_it_asid_pool(cap_t root_cnode_cap);
void write_it_pd_pts(cap_t root_cnode_cap, cap_t it_pd_cap);
void create_idle_thread(void);
bool_t create_untypeds(cap_t root_cnode_cap);
bool_t create_untypeds_for_region(cap_t root_cnode_cap, bool_t device_memory, region_t reg, seL4_SlotPos first_untyped_slot);
bool_t create_untypeds(cap_t root_cnode_cap, seL4_SlotPos first_untyped_slot);
void bi_finalise(void);
void create_domain_cap(cap_t root_cnode_cap);

Expand Down
14 changes: 10 additions & 4 deletions src/arch/arm/64/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@

.section .boot.text, "ax"
BEGIN_FUNC(_start)
/* Save x4 and x5 so we don't clobber it */
mov x7, x4
mov x8, x5
/* Save x4, x5, x6, x7 so we don't clobber it */
mov x14, x4
mov x15, x5
mov x16, x6
mov x17, x7

/* Make sure interrupts are disabled */
msr daifset, #DAIFSET_MASK
Expand Down Expand Up @@ -118,8 +120,10 @@ BEGIN_FUNC(_start)
/* Attempt to workaround any known ARM errata. */
stp x0, x1, [sp, #-16]!
stp x2, x3, [sp, #-16]!
stp x7, x8, [sp, #-16]!
stp x14, x15, [sp, #-16]!
stp x16, x17, [sp, #-16]!
bl arm_errata
ldp x6, x7, [sp], #16
ldp x4, x5, [sp], #16
ldp x2, x3, [sp], #16
ldp x0, x1, [sp], #16
Expand All @@ -131,6 +135,8 @@ BEGIN_FUNC(_start)
* x3: user image virtual entry address
* x4: DTB physical address (0 if there is none)
* x5: DTB size (0 if there is none)
* x6: extra device memory region (0 if there is none)
* x7: extra device size (0 if there is none)
*/
bl init_kernel

Expand Down
37 changes: 31 additions & 6 deletions src/arch/arm/kernel/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ BOOT_BSS static region_t reserved[NUM_RESERVED_REGIONS];

BOOT_CODE static bool_t arch_init_freemem(p_region_t ui_p_reg,
p_region_t dtb_p_reg,
p_region_t extra_device_p_reg,
v_region_t it_v_reg,
word_t extra_bi_size_bits)
{
Expand All @@ -60,6 +61,13 @@ BOOT_CODE static bool_t arch_init_freemem(p_region_t ui_p_reg,
index++;
}

/* add the extra device region, if it is not empty */
if (extra_device_p_reg.start) {
reserved[index].start = (pptr_t) paddr_to_pptr(extra_device_p_reg.start);
reserved[index].end = (pptr_t) paddr_to_pptr(extra_device_p_reg.end);
index++;
}

/* Reserve the user image region and the mode-reserved regions. For now,
* only one mode-reserved region is supported, because this is all that is
* needed.
Expand Down Expand Up @@ -332,7 +340,9 @@ static BOOT_CODE bool_t try_init_kernel(
sword_t pv_offset,
vptr_t v_entry,
paddr_t dtb_phys_addr,
word_t dtb_size
word_t dtb_size,
paddr_t extra_device_addr_start,
word_t extra_device_addr_size
)
{
cap_t root_cnode_cap;
Expand All @@ -342,6 +352,9 @@ static BOOT_CODE bool_t try_init_kernel(
p_region_t ui_p_reg = (p_region_t) {
ui_p_reg_start, ui_p_reg_end
};
p_region_t extra_device_p_reg = (p_region_t) {
extra_device_addr_start, extra_device_addr_start + extra_device_addr_size
};
region_t ui_reg = paddr_to_pptr_reg(ui_p_reg);
word_t extra_bi_size = 0;
pptr_t extra_bi_offset = 0;
Expand All @@ -350,6 +363,7 @@ static BOOT_CODE bool_t try_init_kernel(
vptr_t ipcbuf_vptr;
create_frames_of_region_ret_t create_frames_ret;
create_frames_of_region_ret_t extra_bi_ret;
seL4_SlotPos first_untyped_slot;

/* convert from physical addresses to userland vptrs */
v_region_t ui_v_reg = {
Expand Down Expand Up @@ -424,7 +438,7 @@ static BOOT_CODE bool_t try_init_kernel(
return false;
}

if (!arch_init_freemem(ui_p_reg, dtb_p_reg, it_v_reg, extra_bi_size_bits)) {
if (!arch_init_freemem(ui_p_reg, dtb_p_reg, extra_device_p_reg, it_v_reg, extra_bi_size_bits)) {
printf("ERROR: free memory management initialization failed\n");
return false;
}
Expand Down Expand Up @@ -583,8 +597,13 @@ static BOOT_CODE bool_t try_init_kernel(

init_core_state(initial);

first_untyped_slot = ndks_boot.slot_pos_cur;
if (extra_device_addr_start) {
create_untypeds_for_region(root_cnode_cap, true, paddr_to_pptr_reg(extra_device_p_reg), first_untyped_slot);
}

/* create all of the untypeds. Both devices and kernel window memory */
if (!create_untypeds(root_cnode_cap)) {
if (!create_untypeds(root_cnode_cap, first_untyped_slot)) {
printf("ERROR: could not create untypteds for kernel image boot memory\n");
return false;
}
Expand Down Expand Up @@ -632,7 +651,9 @@ BOOT_CODE VISIBLE void init_kernel(
sword_t pv_offset,
vptr_t v_entry,
paddr_t dtb_addr_p,
uint32_t dtb_size
uint64_t dtb_size,
paddr_t extra_device_addr_p,
uint64_t extra_device_size
)
{
bool_t result;
Expand All @@ -644,7 +665,9 @@ BOOT_CODE VISIBLE void init_kernel(
ui_p_reg_end,
pv_offset,
v_entry,
dtb_addr_p, dtb_size);
dtb_addr_p, dtb_size,
extra_device_addr_p, extra_device_size
);
} else {
result = try_init_kernel_secondary_core();
}
Expand All @@ -654,7 +677,9 @@ BOOT_CODE VISIBLE void init_kernel(
ui_p_reg_end,
pv_offset,
v_entry,
dtb_addr_p, dtb_size);
dtb_addr_p, dtb_size,
extra_device_addr_p, extra_device_size
);

#endif /* ENABLE_SMP_SUPPORT */

Expand Down
2 changes: 1 addition & 1 deletion src/arch/riscv/kernel/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ static BOOT_CODE bool_t try_init_kernel(
init_core_state(initial);

/* convert the remaining free memory into UT objects and provide the caps */
if (!create_untypeds(root_cnode_cap)) {
if (!create_untypeds(root_cnode_cap, ndks_boot.slot_pos_cur)) {
printf("ERROR: could not create untypteds for kernel image boot memory\n");
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86/kernel/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ BOOT_CODE bool_t init_sys_state(
#endif

/* create all of the untypeds. Both devices and kernel window memory */
if (!create_untypeds(root_cnode_cap)) {
if (!create_untypeds(root_cnode_cap, ndks_boot.slot_pos_cur)) {
return false;
}

Expand Down
6 changes: 2 additions & 4 deletions src/kernel/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ BOOT_CODE static bool_t provide_untyped_cap(
* @param first_untyped_slot First available untyped boot info slot.
* @return true on success, false on failure.
*/
BOOT_CODE static bool_t create_untypeds_for_region(
BOOT_CODE bool_t create_untypeds_for_region(
cap_t root_cnode_cap,
bool_t device_memory,
region_t reg,
Expand Down Expand Up @@ -763,10 +763,8 @@ BOOT_CODE static bool_t create_untypeds_for_region(
return true;
}

BOOT_CODE bool_t create_untypeds(cap_t root_cnode_cap)
BOOT_CODE bool_t create_untypeds(cap_t root_cnode_cap, seL4_SlotPos first_untyped_slot)
{
seL4_SlotPos first_untyped_slot = ndks_boot.slot_pos_cur;

paddr_t start = 0;
for (word_t i = 0; i < ndks_boot.resv_count; i++) {
if (start < ndks_boot.reserved[i].start) {
Expand Down

0 comments on commit 5f71dc4

Please sign in to comment.