Skip to content

Commit

Permalink
boot: inline arch_init_freemem()
Browse files Browse the repository at this point in the history
  • Loading branch information
axel-h committed Jun 15, 2023
1 parent ddecb8a commit 883d08d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 100 deletions.
83 changes: 40 additions & 43 deletions src/arch/arm/kernel/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,6 @@
BOOT_BSS static volatile int node_boot_lock;
#endif /* ENABLE_SMP_SUPPORT */

BOOT_CODE static bool_t arch_init_freemem(p_region_t ui_p_reg,
p_region_t dtb_p_reg,
v_region_t it_v_reg,
word_t extra_bi_size_bits)
{
/* reserve the kernel image region */
if (!reserve_region(get_p_reg_kernel_img())) {
printf("ERROR: can't add reserved region for kernel image\n");
return false;
}

/* Reserve the user image region. */
if (!reserve_region(ui_p_reg)) {
printf("ERROR: can't add reserved region for user image\n");
return false;
}

/* Reserve the DTB region, it's ignored if the size is zero. */
if (!reserve_region(dtb_p_reg)) {
printf("ERROR: can't add reserved region for DTB\n");
return false;
}

#ifdef CONFIG_ARCH_AARCH32

/* Reserve the HW ASID region*/
assert(1 == MODE_RESERVED);
p_region_t hw_asid_p_reg = pptr_to_paddr_reg(mode_reserved_region[0]);
if (!reserve_region(hw_asid_p_reg)) {
printf("ERROR: can't add reserved region for HW ASIDs\n");
return false;
}

#endif

/* avail_p_regs comes from the auto-generated code */
return init_freemem(ARRAY_SIZE(avail_p_regs), avail_p_regs,
it_v_reg, extra_bi_size_bits);
}


BOOT_CODE static void init_irqs(cap_t root_cnode_cap)
{
Expand Down Expand Up @@ -291,7 +251,6 @@ static BOOT_CODE bool_t try_init_kernel(
cap_t it_ap_cap;
cap_t it_pd_cap;
cap_t ipcbuf_cap;
p_region_t ui_p_reg = { .start = ui_p_reg_start, .end = ui_p_reg_end };
word_t extra_bi_size = 0;
pptr_t extra_bi_offset = 0;
vptr_t extra_bi_frame_vptr;
Expand Down Expand Up @@ -325,6 +284,34 @@ static BOOT_CODE bool_t try_init_kernel(
/* initialise the platform */
init_plat();

/* Reserve the kernel image region. */
if (!reserve_region(get_p_reg_kernel_img())) {
printf("ERROR: can't add reserved region for kernel image\n");
return false;
}

/* Reserve the user image region. */
p_region_t ui_p_reg = {
.start = ui_p_reg_start,
.end = ui_p_reg_end
};
if (!reserve_region(ui_p_reg)) {
printf("ERROR: can't add reserved region for user image\n");
return false;
}

#ifdef CONFIG_ARCH_AARCH32

/* Reserve the HW ASID region*/
assert(1 == MODE_RESERVED);
p_region_t hw_asid_p_reg = pptr_to_paddr_reg(mode_reserved_region[0]);
if (!reserve_region(hw_asid_p_reg)) {
printf("ERROR: can't add reserved region for HW ASIDs\n");
return false;
}

#endif

/* If a DTB was provided, pass the data on as extra bootinfo */
p_region_t dtb_p_reg = P_REG_EMPTY;
if (dtb_size > 0) {
Expand Down Expand Up @@ -354,6 +341,12 @@ static BOOT_CODE bool_t try_init_kernel(
.start = dtb_phys_addr,
.end = dtb_phys_end
};

/* Reserve the DTB region */
if (!reserve_region(dtb_p_reg)) {
printf("ERROR: can't add reserved region for DTB\n");
return false;
}
}

/* The region of the initial thread is the user image + ipcbuf and boot info */
Expand All @@ -373,8 +366,12 @@ 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)) {
printf("ERROR: free memory management initialization failed\n");
/* make the free memory available to alloc_region(), avail_p_regs comes from
* the auto-generated code.
*/
if (!init_freemem(ARRAY_SIZE(avail_p_regs), avail_p_regs, it_v_reg,
extra_bi_size_bits)) {
printf("ERROR: free memory initn faiuled\n");
return false;
}

Expand Down
60 changes: 28 additions & 32 deletions src/arch/riscv/kernel/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,6 @@ BOOT_CODE cap_t create_mapped_it_frame_cap(cap_t pd_cap, pptr_t pptr, vptr_t vpt
return cap;
}

BOOT_CODE static bool_t arch_init_freemem(p_region_t ui_p_reg,
p_region_t dtb_p_reg,
v_region_t it_v_reg,
word_t extra_bi_size_bits)
{
/* reserve the kernel image region */
if (!reserve_region(get_p_reg_kernel_img())) {
printf("ERROR: can't add reserved region for kernel image\n");
return false;
}

/* Reserve the user image region. */
if (!reserve_region(ui_p_reg)) {
printf("ERROR: can't add reserved region for user image\n");
return false;
}

/* Reserve the DTB region, it's ignored if the size is zero. */
if (!reserve_region(dtb_p_reg)) {
printf("ERROR: can't add reserved region for DTB\n");
return false;
}

/* avail_p_regs comes from the auto-generated code */
return init_freemem(ARRAY_SIZE(avail_p_regs), avail_p_regs,
it_v_reg, extra_bi_size_bits);
}

BOOT_CODE static void init_irqs(cap_t root_cnode_cap)
{
irq_t i;
Expand Down Expand Up @@ -189,7 +161,6 @@ static BOOT_CODE bool_t try_init_kernel(
cap_t it_pd_cap;
cap_t it_ap_cap;
cap_t ipcbuf_cap;
p_region_t ui_p_reg = { .start = ui_p_reg_start, .end = ui_p_reg_end };
word_t extra_bi_size = 0;
pptr_t extra_bi_offset = 0;
vptr_t extra_bi_frame_vptr;
Expand Down Expand Up @@ -218,6 +189,22 @@ static BOOT_CODE bool_t try_init_kernel(
/* initialize the platform */
init_plat();

/* Reserve the kernel image region. */
if (!reserve_region(get_p_reg_kernel_img())) {
printf("ERROR: can't add reserved region for kernel image\n");
return false;
}

/* Reserve the user image region. */
p_region_t ui_p_reg = {
.start = ui_p_reg_start,
.end = ui_p_reg_end
};
if (!reserve_region(ui_p_reg)) {
printf("ERROR: can't add reserved region for user image\n");
return false;
}

/* If a DTB was provided, pass the data on as extra bootinfo */
p_region_t dtb_p_reg = P_REG_EMPTY;
if (dtb_size > 0) {
Expand Down Expand Up @@ -254,6 +241,12 @@ static BOOT_CODE bool_t try_init_kernel(
.start = dtb_phys_addr,
.end = dtb_phys_end
};

/* Reserve the DTB region. */
if (!reserve_region(dtb_p_reg)) {
printf("ERROR: can't add reserved region for DTB\n");
return false;
}
}

/* The region of the initial thread is the user image + ipcbuf + boot info + extra */
Expand All @@ -273,9 +266,12 @@ static BOOT_CODE bool_t try_init_kernel(
return false;
}

/* make the free memory available to alloc_region() */
if (!arch_init_freemem(ui_p_reg, dtb_p_reg, it_v_reg, extra_bi_size_bits)) {
printf("ERROR: free memory management initialization failed\n");
/* make the free memory available to alloc_region(), avail_p_regs comes from
* the auto-generated code.
*/
if (!init_freemem(ARRAY_SIZE(avail_p_regs), avail_p_regs, it_v_reg,
extra_bi_size_bits)) {
printf("ERROR: free memory initn faiuled\n");
return false;
}

Expand Down
39 changes: 14 additions & 25 deletions src/arch/x86/kernel/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,6 @@ BOOT_CODE static void init_irqs(cap_t root_cnode_cap)
write_slot(SLOT_PTR(pptr_of_cap(root_cnode_cap), seL4_CapIRQControl), cap_irq_control_cap_new());
}

BOOT_CODE static bool_t arch_init_freemem(p_region_t ui_p_reg,
v_region_t it_v_reg,
mem_p_regs_t *mem_p_regs,
word_t extra_bi_size_bits)
{
/* The reserved region is not only the user image, but starts at the base of
* the kernel image. KERNEL_ELF_PADDR_BASE is the lowest physical load
* address used in the x86 linker script.
*/
p_region_t ui_p_reg = {
.start = 0,
.end = ui_p_end
};
if (!reserve_region(ui_p_reg)) {
printf("ERROR: can't add reserved region for user image\n");
return false;
}

return init_freemem(mem_p_regs->count, mem_p_regs->list, it_v_reg,
extra_bi_size_bits);
}

/* This function initialises a node's kernel state. It does NOT initialise the CPU. */

BOOT_CODE bool_t init_sys_state(
Expand Down Expand Up @@ -115,6 +93,16 @@ BOOT_CODE bool_t init_sys_state(
create_frames_of_region_ret_t create_frames_ret;
create_frames_of_region_ret_t extra_bi_ret;

/* Reserve the user image region. */
p_region_t ui_p_reg = {
.start = 0,
.end = ui_info.p_reg.end
};
if (!reserve_region(ui_p_reg)) {
printf("ERROR: can't add reserved region for user image\n");
return false;
}

/* convert from physical addresses to kernel pptrs */
region_t ui_reg = paddr_to_pptr_reg(ui_info.p_reg);

Expand Down Expand Up @@ -155,9 +143,10 @@ BOOT_CODE bool_t init_sys_state(
}
#endif /* CONFIG_IOMMU */

if (!arch_init_freemem(ui_info.p_reg.end, it_v_reg, mem_p_regs,
extra_bi_size_bits)) {
printf("ERROR: free memory management initialization failed\n");
/* make the free memory available to alloc_region() */
if (!init_freemem(mem_p_regs->count, mem_p_regs->list, it_v_reg,
extra_bi_size_bits)) {
printf("ERROR: free memory initn faiuled\n");
return false;
}

Expand Down

0 comments on commit 883d08d

Please sign in to comment.