ulong *log2size)
{
if (plat && sbi_platform_ops(plat)->pmp_region_info)
- return sbi_platform_ops(plat)->pmp_region_info(hartid, index, prot, addr,
- log2size);
+ return sbi_platform_ops(plat)->pmp_region_info(hartid, index,
+ prot, addr,
+ log2size);
return 0;
}
static int pmp_init(struct sbi_scratch *scratch, u32 hartid)
{
- u32 i, count;
+ u32 i, pmp_idx = 0, count;
unsigned long fw_start, fw_size_log2;
ulong prot, addr, log2size;
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
if (!sbi_platform_has_pmp(plat))
return 0;
+ /* Firmware PMP region to protect OpenSBI firmware */
fw_size_log2 = log2roundup(scratch->fw_size);
- fw_start = scratch->fw_start & ~((1UL << fw_size_log2) - 1UL);
-
- pmp_set(0, 0, fw_start, fw_size_log2);
+ fw_start = scratch->fw_start & ~((1UL << fw_size_log2) - 1UL);
+ pmp_set(pmp_idx++, 0, fw_start, fw_size_log2);
+ /* Platform specific PMP regions */
count = sbi_platform_pmp_region_count(plat, hartid);
- if ((PMP_COUNT - 1) < count)
- count = (PMP_COUNT - 1);
-
- for (i = 0; i < count; i++) {
+ for (i = 0; i < count && pmp_idx < (PMP_COUNT - 1); i++) {
if (sbi_platform_pmp_region_info(plat, hartid, i, &prot, &addr,
&log2size))
continue;
- pmp_set(i + 1, prot, addr, log2size);
+ pmp_set(pmp_idx++, prot, addr, log2size);
}
+ /*
+ * Default PMP region for allowing S-mode and U-mode access to
+ * memory not covered by:
+ * 1) Firmware PMP region
+ * 2) Platform specific PMP regions
+ */
+ pmp_set(pmp_idx++, PMP_R | PMP_W | PMP_X, 0, __riscv_xlen);
+
return 0;
}
return 0;
}
-/* Get number of PMP regions for given HART. */
-static u32 ae350_pmp_region_count(u32 hartid)
-{
- return 1;
-}
-
-/*
- * Get PMP regions details (namely: protection, base address, and size) for
- * a given HART.
- */
-static int ae350_pmp_region_info(u32 hartid, u32 index, ulong *prot,
- ulong *addr, ulong *log2size)
-{
- int ret = 0;
-
- switch (index) {
- case 0:
- *prot = PMP_R | PMP_W | PMP_X;
- *addr = 0;
- *log2size = __riscv_xlen;
- break;
- default:
- ret = -1;
- break;
- };
-
- return ret;
-}
-
/* Initialize the platform console. */
static int ae350_console_init(void)
{
const struct sbi_platform_operations platform_ops = {
.final_init = ae350_final_init,
- .pmp_region_count = ae350_pmp_region_count,
- .pmp_region_info = ae350_pmp_region_info,
-
.console_init = ae350_console_init,
.console_putc = uart8250_putc,
.console_getc = uart8250_getc,
return 0;
}
-static u32 virt_pmp_region_count(u32 hartid)
-{
- return 1;
-}
-
-static int virt_pmp_region_info(u32 hartid, u32 index, ulong *prot, ulong *addr,
- ulong *log2size)
-{
- int ret = 0;
-
- switch (index) {
- case 0:
- *prot = PMP_R | PMP_W | PMP_X;
- *addr = 0;
- *log2size = __riscv_xlen;
- break;
- default:
- ret = -1;
- break;
- };
-
- return ret;
-}
-
static int virt_console_init(void)
{
return uart8250_init(VIRT_UART16550_ADDR, VIRT_UART_SHIFTREG_ADDR,
}
const struct sbi_platform_operations platform_ops = {
- .pmp_region_count = virt_pmp_region_count,
- .pmp_region_info = virt_pmp_region_info,
.final_init = virt_final_init,
.console_putc = uart8250_putc,
.console_getc = uart8250_getc,
return 0;
}
-static u32 fu540_pmp_region_count(u32 hartid)
-{
- return 1;
-}
-
-static int fu540_pmp_region_info(u32 hartid, u32 index, ulong *prot,
- ulong *addr, ulong *log2size)
-{
- int ret = 0;
-
- switch (index) {
- case 0:
- *prot = PMP_R | PMP_W | PMP_X;
- *addr = 0;
- *log2size = __riscv_xlen;
- break;
- default:
- ret = -1;
- break;
- };
-
- return ret;
-}
-
static int fu540_console_init(void)
{
unsigned long peri_in_freq;
}
const struct sbi_platform_operations platform_ops = {
- .pmp_region_count = fu540_pmp_region_count,
- .pmp_region_info = fu540_pmp_region_info,
.final_init = fu540_final_init,
.console_putc = sifive_uart_putc,
.console_getc = sifive_uart_getc,
return 0;
}
-static u32 spike_pmp_region_count(u32 hartid)
-{
- return 1;
-}
-
-static int spike_pmp_region_info(u32 hartid, u32 index, ulong *prot, ulong *addr,
- ulong *log2size)
-{
- int ret = 0;
-
- switch (index) {
- case 0:
- *prot = PMP_R | PMP_W | PMP_X;
- *addr = 0;
- *log2size = __riscv_xlen;
- break;
- default:
- ret = -1;
- break;
- };
-
- return ret;
-}
-
static int spike_console_init(void)
{
return 0;
}
const struct sbi_platform_operations platform_ops = {
- .pmp_region_count = spike_pmp_region_count,
- .pmp_region_info = spike_pmp_region_info,
.final_init = spike_final_init,
.console_putc = htif_putc,
.console_getc = htif_getc,
}
/*
- * Get number of PMP regions for given HART.
- */
-static u32 platform_pmp_region_count(u32 hartid)
-{
- return 0;
-}
-
-/*
- * Get PMP regions details (namely: protection, base address, and size) for
- * a given HART.
- */
-static int platform_pmp_region_info(u32 hartid, u32 index, ulong *prot,
- ulong *addr, ulong *log2size)
-{
- return 0;
-}
-
-/*
* Initialize the platform console.
*/
static int platform_console_init(void)
const struct sbi_platform_operations platform_ops = {
.early_init = platform_early_init,
.final_init = platform_final_init,
- .pmp_region_count = platform_pmp_region_count,
- .pmp_region_info = platform_pmp_region_info,
.console_putc = platform_console_putc,
.console_getc = platform_console_getc,
.console_init = platform_console_init,