Skip to content

Commit 1afa348

Browse files
committed
[TODO] platform: Add xuantie_pmp_ext_cfg
Used to disable permissions in S/U mode. The DTS configuration reference: pmp_ext@35000000 { compatible = "xuantie,pmp_ext"; reg = <0x0 0x35000000 0x0 0x4000000>; }; Signed-off-by: Chen Pei <cp0613@linux.alibaba.com>
1 parent 1e3fb39 commit 1afa348

6 files changed

Lines changed: 75 additions & 4 deletions

File tree

lib/sbi/sbi_hart.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,12 @@ static unsigned int sbi_hart_get_smepmp_flags(struct sbi_scratch *scratch,
374374
pmp_flags |= PMP_W;
375375
if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE)
376376
pmp_flags |= PMP_X;
377+
} else if (reg->flags & SBI_DOMAIN_MEMREGION_ENF_PERMISSIONS) {
378+
/*
379+
* If permissions are to be enforced for all modes on
380+
* this region, the lock bit should be set.
381+
*/
382+
pmp_flags |= PMP_L;
377383
}
378384

379385
return pmp_flags;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* SPDX-License-Identifier: BSD-2-Clause
3+
*/
4+
5+
#ifndef __RISCV_XUANTIE_PMP_EXT_H__
6+
#define __RISCV_XUANTIE_PMP_EXT_H__
7+
8+
#include <sbi/sbi_types.h>
9+
10+
int xuantie_pmp_ext_cfg(void);
11+
12+
#endif /* __RISCV_XUANTIE_PMP_EXT_H__ */

platform/generic/include/xuantie/xuantie_quirk.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
#ifndef __RISCV_XUANTIE_QUIRK_H__
66
#define __RISCV_XUANTIE_QUIRK_H__
77

8-
#define QUIRK_XUANTIE_PMC BIT(0)
9-
#define QUIRK_XUANTIE_LINK BIT(1)
8+
#define QUIRK_XUANTIE_PMC BIT(0)
9+
#define QUIRK_XUANTIE_LINK BIT(1)
10+
#define QUIRK_XUANTIE_PMP_EXT BIT(2)
1011

1112
struct xuantie_generic_quirks {
1213
u32 quirk;

platform/generic/xuantie/objects.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#
44

55
carray-platform_override_modules-$(CONFIG_PLATFORM_XUANTIE) += xuantie_dummy
6-
platform-objs-$(CONFIG_PLATFORM_XUANTIE) += xuantie/xuantie_dummy.o xuantie/xuantie_pmc.o xuantie/xuantie_link.o
6+
platform-objs-$(CONFIG_PLATFORM_XUANTIE) += xuantie/xuantie_dummy.o xuantie/xuantie_pmc.o xuantie/xuantie_link.o xuantie/xuantie_pmp_ext.o

platform/generic/xuantie/xuantie_dummy.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,20 @@
1313
#include <xuantie/xuantie_quirk.h>
1414
#include <xuantie/xuantie_pmc.h>
1515
#include <xuantie/xuantie_link.h>
16+
#include <xuantie/xuantie_pmp_ext.h>
1617

1718
static u32 gquirk = 0;
1819

20+
int xuantie_early_init(bool cold_boot)
21+
{
22+
if (cold_boot) {
23+
if (gquirk & QUIRK_XUANTIE_PMP_EXT)
24+
xuantie_pmp_ext_cfg();
25+
}
26+
27+
return generic_early_init(cold_boot);
28+
}
29+
1930
int xuantie_final_init(bool cold_boot)
2031
{
2132
if (cold_boot) {
@@ -34,13 +45,14 @@ static int xuantie_dummy_platform_init(const void *fdt, int nodeoff,
3445
const struct xuantie_generic_quirks *data = match->data;
3546

3647
gquirk = data->quirk;
48+
generic_platform_ops.early_init = xuantie_early_init;
3749
generic_platform_ops.final_init = xuantie_final_init;
3850

3951
return 0;
4052
}
4153

4254
static const struct xuantie_generic_quirks xuantie_quirks = {
43-
.quirk = QUIRK_XUANTIE_PMC | QUIRK_XUANTIE_LINK,
55+
.quirk = QUIRK_XUANTIE_PMC | QUIRK_XUANTIE_LINK | QUIRK_XUANTIE_PMP_EXT,
4456
};
4557

4658
static const struct xuantie_generic_quirks xuantie_pmc_quirks = {
@@ -51,10 +63,15 @@ static const struct xuantie_generic_quirks xuantie_link_quirks = {
5163
.quirk = QUIRK_XUANTIE_LINK,
5264
};
5365

66+
static const struct xuantie_generic_quirks xuantie_pmp_ext_quirks = {
67+
.quirk = QUIRK_XUANTIE_PMP_EXT,
68+
};
69+
5470
static const struct fdt_match xuantie_dummy_match[] = {
5571
{ .compatible = "xuantie,dummy", .data = &xuantie_quirks },
5672
{ .compatible = "xuantie,pmc", .data = &xuantie_pmc_quirks },
5773
{ .compatible = "xuantie,link", .data = &xuantie_link_quirks },
74+
{ .compatible = "riscv-virtio", .data = &xuantie_pmp_ext_quirks }, // qemu debug
5875
{ },
5976
};
6077

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* SPDX-License-Identifier: BSD-2-Clause
3+
*/
4+
5+
#include <libfdt.h>
6+
#include <sbi/sbi_error.h>
7+
#include <sbi/sbi_console.h>
8+
#include <sbi/riscv_io.h>
9+
#include <sbi_utils/fdt/fdt_fixup.h>
10+
#include <sbi_utils/fdt/fdt_helper.h>
11+
#include <xuantie/xuantie_pmp_ext.h>
12+
13+
/*
14+
sbi_domain_root_add_memrange needs to be called before sbi_domain_finalize,
15+
because sbi_domain_finalize sets domain_finalized = true, causing subsequent
16+
additions to fail.
17+
*/
18+
int xuantie_pmp_ext_cfg(void)
19+
{
20+
int nodeoffset, rc;
21+
uint64_t addr, size;
22+
void *fdt = fdt_get_address_rw();
23+
24+
nodeoffset = fdt_node_offset_by_compatible(fdt, -1, "xuantie,pmp_ext");
25+
if (nodeoffset < 0)
26+
return nodeoffset;
27+
28+
rc = fdt_get_node_addr_size(fdt, nodeoffset, 0, &addr, &size);
29+
if (rc)
30+
return SBI_ENODEV;
31+
32+
rc = sbi_domain_root_add_memrange(addr, size, size & (-size),
33+
SBI_DOMAIN_MEMREGION_ENF_PERMISSIONS);
34+
return rc;
35+
}

0 commit comments

Comments
 (0)