Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ endif
ifeq ($(arch_mem_prot),mpu)
build_macros+=-DMEM_PROT_MPU
endif
ifeq ($(plat_mem),non_unified)
build_macros+=-DMEM_NON_UNIFIED
endif

ifeq ($(CC_IS_GCC),y)
build_macros+=-DCC_IS_GCC
Expand Down
6 changes: 6 additions & 0 deletions scripts/config_defs_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ int main() {
printf("#define CONFIG_HYP_BASE_ADDR PLAT_BASE_ADDR\n");
}

if(config.hyp.data_relocate) {
printf("#define CONFIG_HYP_DATA_ADDR (0x%lx)\n", config.hyp.data_addr);
} else {
printf("#define CONFIG_HYP_DATA_ADDR PLAT_DATA_ADDR\n");
}

printf("#define CONFIG_REMIO_DEV_NUM %ld\n", remio_dev_num());

return 0;
Expand Down
14 changes: 14 additions & 0 deletions scripts/platform_defs_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ int main() {
printf("#define PLAT_CPU_NUM (%ld)\n", platform.cpu_num);
printf("#define PLAT_BASE_ADDR (0x%lx)\n", platform.regions[0].base);

for(size_t i = 1; i < platform.region_num; i++)
{
/*
* Selects the first memory region with RWX (read, write, execute) permissions, and defines
* it as PLAT_DATA_ADDR. This region is considered the main data memory that Bao will use
* for its own purposes.
*/
if(platform.regions[i].perms == MEM_RWX)
{
printf("#define PLAT_DATA_ADDR (0x%lx)\n", platform.regions[i].base);
break;
}
}

for(size_t i = 0; i < platform.region_num; i++)
{
size_t reg_size;
Expand Down
3 changes: 2 additions & 1 deletion src/arch/armv8/aarch32/boot.S
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ _reset_handler:
* Get base image load address.
*/
adr r1, _el2_entry
ldr r3, =img_addr
str r1, [r3] // store image load address in img_addr

/**
* Linearize cpu id according to the number of clusters and processors per cluster. We are only
Expand Down Expand Up @@ -227,4 +229,3 @@ set_loop:
cmp r5, r3 // last way reached yet?
ble way_loop // if not, iterate way_loop
bx lr

4 changes: 3 additions & 1 deletion src/arch/armv8/aarch64/boot.S
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ _reset_handler:
mrs x0, MPIDR_EL1
adrp x1, _image_start

ldr x2, =img_addr
str x1, [x2] // store image load address in img_addr

/*
* Install vector table physical address early, in case exception occurs during this
* initialization.
Expand Down Expand Up @@ -221,4 +224,3 @@ set_loop:
cmp x5, x3 // last way reached yet?
ble way_loop // if not, iterate way_loop
ret

5 changes: 3 additions & 2 deletions src/arch/armv8/armv8-r/inc/arch/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ struct addr_space_arch {
.prlar = (_prlar), \
})

#define PTE_INVALID PTE_FLAGS(0, 0)
#define PTE_HYP_FLAGS PTE_FLAGS(PRBAR_AP_RW_EL2 | PRBAR_SH_OS, PRLAR_ATTR(1) | PRLAR_EN)
#define PTE_INVALID PTE_FLAGS(0, 0)
#define PTE_HYP_FLAGS PTE_FLAGS(PRBAR_AP_RW_EL2 | PRBAR_SH_OS, PRLAR_ATTR(1) | PRLAR_EN)
#define PTE_HYP_FLAGS_CODE PTE_FLAGS(PRBAR_AP_RO_EL2 | PRBAR_SH_IS, PRLAR_ATTR(1) | PRLAR_EN)
#define PTE_HYP_DEV_FLAGS \
PTE_FLAGS(PRBAR_XN | PRBAR_AP_RW_EL2 | PRBAR_SH_IS, PRLAR_ATTR(2) | PRLAR_EN)
#define PTE_VM_FLAGS PTE_FLAGS(PRBAR_AP_RW_EL1_EL2 | PRBAR_SH_NS, PRLAR_ATTR(1) | PRLAR_EN)
Expand Down
4 changes: 4 additions & 0 deletions src/arch/riscv/boot.S
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ _reset_handler:

mv a2, a1
la a1, _image_start

LD_SYM a3, img_addr
STORE a1, 0(a3) // store image load address in img_addr

LD_SYM s6, _extra_allocated_phys_mem_sym

/**
Expand Down
15 changes: 6 additions & 9 deletions src/core/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@

#include <config.h>

static void config_adjust_vm_image_addr(paddr_t load_addr)
static void config_adjust_vm_image_addr(void)
{
for (size_t i = 0; i < config.vmlist_size; i++) {
struct vm_config* vm_config = &config.vmlist[i];
if (!vm_config->image.separately_loaded) {
vm_config->image.load_addr = (vm_config->image.load_addr - BAO_VAS_BASE) + load_addr;
vm_config->image.load_addr = (vm_config->image.load_addr - BAO_VAS_BASE) + img_addr;
}
}
}

__attribute__((weak)) void config_mem_prot_init(paddr_t load_addr)
{
UNUSED_ARG(load_addr);
}
__attribute__((weak)) void config_mem_prot_init(void) { }

void config_init(paddr_t load_addr)
void config_init(void)
{
config_adjust_vm_image_addr(load_addr);
config_mem_prot_init(load_addr);
config_adjust_vm_image_addr();
config_mem_prot_init();
}
4 changes: 2 additions & 2 deletions src/core/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ static size_t ipi_cpumsg_handler_num;

struct cpuif cpu_interfaces[PLAT_CPU_NUM];

void cpu_init(cpuid_t cpu_id, paddr_t load_addr)
void cpu_init(cpuid_t cpu_id)
{
cpu()->id = cpu_id;
cpu()->handling_msgs = false;
cpu()->interface = cpu_if(cpu()->id);

cpu_arch_init(cpu_id, load_addr);
cpu_arch_init(cpu_id, img_addr);

list_init(&cpu()->interface->event_list);

Expand Down
2 changes: 1 addition & 1 deletion src/core/inc/bao.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
console_printk("BAO ERROR: " __VA_ARGS__); \
while (true) { };

void init(cpuid_t cpu_id, paddr_t load_addr);
void init(cpuid_t cpu_id);

#endif /* __ASSEMBLER__ */

Expand Down
13 changes: 11 additions & 2 deletions src/core/inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ extern struct config {
bool relocate;
paddr_t base_addr;

/**
* Only meaningful for non-unified platforms. In such platforms, the hypervisor expects a
* base address for data memory and will default to the first RWX region defined in the
* target platform's description. If the user wishes to relocate it to another address,
* they must set data_relocate to true and provide the new base address.
*/
bool data_relocate;
paddr_t data_addr;

/* Hypervisor colors */
colormap_t colors;
} hyp;
Expand All @@ -126,7 +135,7 @@ extern struct config {

} config;

void config_init(paddr_t load_addr);
void config_mem_prot_init(paddr_t load_addr);
void config_init(void);
void config_mem_prot_init(void);

#endif /* __CONFIG_H__ */
2 changes: 1 addition & 1 deletion src/core/inc/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct cpu_synctoken {

extern struct cpu_synctoken cpu_glb_sync;

void cpu_init(cpuid_t cpu_id, paddr_t load_addr);
void cpu_init(cpuid_t cpu_id);
void cpu_send_msg(cpuid_t cpu, struct cpu_msg* msg);
bool cpu_get_msg(struct cpu_msg* msg);
void cpu_msg_handler(void);
Expand Down
15 changes: 13 additions & 2 deletions src/core/inc/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

#ifndef __ASSEMBLER__

enum MEM_PERMISSIONS {
MEM_RWX = 0, // This variant always has to be zero and therefore the first one
MEM_RX,
};

struct ppages {
paddr_t base;
size_t num_pages;
Expand All @@ -34,6 +39,7 @@ struct page_pool {
struct mem_region {
paddr_t base;
size_t size;
enum MEM_PERMISSIONS perms;
struct page_pool page_pool;
};

Expand Down Expand Up @@ -61,7 +67,7 @@ static inline bool all_clrs(colormap_t clrs)
return (masked_colors == 0) || (masked_colors == mask);
}

void mem_init(paddr_t load_addr);
void mem_init(void);
void* mem_alloc_page(size_t num_pages, enum AS_SEC sec, bool phys_aligned);
struct ppages mem_alloc_ppages(colormap_t colors, size_t num_pages, bool aligned);
vaddr_t mem_alloc_map(struct addr_space* as, enum AS_SEC section, struct ppages* page, vaddr_t at,
Expand Down Expand Up @@ -89,6 +95,11 @@ bool mem_translate(struct addr_space* as, vaddr_t va, paddr_t* pa);

extern struct list page_pool_list;

#endif /* |__ASSEMBLER__ */
/* The address where the Bao image is loaded in memory */
extern vaddr_t img_addr;
/* The address where the data section is loaded in memory */
extern vaddr_t data_addr;

#endif /* __ASSEMBLER__ */

#endif /* __MEM_H__ */
6 changes: 3 additions & 3 deletions src/core/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include <platform.h>
#include <vmm.h>

void init(cpuid_t cpu_id, paddr_t load_addr)
void init(cpuid_t cpu_id)
{
/**
* These initializations must be executed first and in fixed order.
*/

cpu_init(cpu_id, load_addr);
mem_init(load_addr);
cpu_init(cpu_id);
mem_init();

/* -------------------------------------------------------------- */

Expand Down
Loading