|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v2 16/26] xen/riscv: create APLIC DT node for guest domains
Guests require a Device Tree description of the interrupt controller
topology. Add support for creating an APLIC node when building the
guest DT.
Provide stub for imsic_make_dt_node() it will be introduced properly
in follow-up patch.
Co-developed-by: Romain Caritey <Romain.Caritey@xxxxxxxxxxxxx>
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
---
Changes in v2:
- Avoid as max as possible of host properties inheritance. Only number of
APLIC's irqs are checked what leads to an introduction of
get_aplic_irqs_num().
- Move this patch earlier what leads to an introduction of
vimsic_make_domu_dt_node() stub.
- s/vimsic_make_domu_dt_node/imsic_make_domu_dt_node.
- Refactor vimsic_make_domu_dt_node() to avoid re-usage of APLIC host
properties.
- Drop next_phandle as it is now in common code.
- Drop const for kinfo argument of vimsic_make_domu_dt_node() is is
going to be updated inside vimsic_make_domu_dt_node().
- Use introduced before vintc->num_irqs.
---
xen/arch/riscv/aplic.c | 2 +
xen/arch/riscv/imsic.c | 7 +++
xen/arch/riscv/include/asm/aplic.h | 9 +++
xen/arch/riscv/include/asm/guest-layout.h | 2 +
xen/arch/riscv/include/asm/imsic.h | 3 +
xen/arch/riscv/vaplic.c | 77 ++++++++++++++++++++++-
6 files changed, 98 insertions(+), 2 deletions(-)
diff --git a/xen/arch/riscv/aplic.c b/xen/arch/riscv/aplic.c
index aba9f3945236..6ed9118485f3 100644
--- a/xen/arch/riscv/aplic.c
+++ b/xen/arch/riscv/aplic.c
@@ -12,8 +12,10 @@
#include <xen/const.h>
#include <xen/device_tree.h>
#include <xen/errno.h>
+#include <xen/fdt-kernel.h>
#include <xen/init.h>
#include <xen/irq.h>
+#include <xen/libfdt/libfdt.h>
#include <xen/mm.h>
#include <xen/sections.h>
#include <xen/spinlock.h>
diff --git a/xen/arch/riscv/imsic.c b/xen/arch/riscv/imsic.c
index 8b46419ca23b..ceea6778d9dc 100644
--- a/xen/arch/riscv/imsic.c
+++ b/xen/arch/riscv/imsic.c
@@ -14,6 +14,7 @@
#include <xen/cpumask.h>
#include <xen/device_tree.h>
#include <xen/errno.h>
+#include <xen/fdt-kernel.h>
#include <xen/init.h>
#include <xen/macros.h>
#include <xen/sched.h>
@@ -522,3 +523,9 @@ int __init imsic_init(const struct dt_device_node *node)
return rc;
}
+
+int __init vimsic_make_domu_dt_node(struct kernel_info *kinfo,
+ unsigned int *phandle)
+{
+ return -EOPNOTSUPP;
+}
diff --git a/xen/arch/riscv/include/asm/aplic.h
b/xen/arch/riscv/include/asm/aplic.h
index b0724fe6f360..b42b159496b8 100644
--- a/xen/arch/riscv/include/asm/aplic.h
+++ b/xen/arch/riscv/include/asm/aplic.h
@@ -15,6 +15,7 @@
#include <asm/imsic.h>
+#define APLIC_DOMAINCFG_RO80 (0x80U << 24)
#define APLIC_DOMAINCFG_IE BIT(8, U)
#define APLIC_DOMAINCFG_DM BIT(2, U)
@@ -27,6 +28,14 @@
#define APLIC_TARGET_HART_IDX_SHIFT 18
+#define APLIC_IDC_SIZE 32
+
+#define APLIC_MIN_SIZE 0x4000
+#define APLIC_SIZE_ALIGN(x) ROUNDUP(x, APLIC_MIN_SIZE)
+
+#define APLIC_SIZE(nr_cpus) (APLIC_MIN_SIZE + \
+ APLIC_SIZE_ALIGN(APLIC_IDC_SIZE * (nr_cpus)))
+
struct aplic_regs {
uint32_t domaincfg; /* 0x0000 */
uint32_t sourcecfg[1023]; /* 0x0004 */
diff --git a/xen/arch/riscv/include/asm/guest-layout.h
b/xen/arch/riscv/include/asm/guest-layout.h
index 68d95a09394c..9fc990c057f2 100644
--- a/xen/arch/riscv/include/asm/guest-layout.h
+++ b/xen/arch/riscv/include/asm/guest-layout.h
@@ -3,6 +3,8 @@
#include <public/xen.h>
+#define GUEST_APLIC_S_BASE 0xd000000
+
#define GUEST_RAM_BANKS 2
/*
diff --git a/xen/arch/riscv/include/asm/imsic.h
b/xen/arch/riscv/include/asm/imsic.h
index 2b84824cd377..604f88db9322 100644
--- a/xen/arch/riscv/include/asm/imsic.h
+++ b/xen/arch/riscv/include/asm/imsic.h
@@ -78,6 +78,7 @@ struct vimsic_state {
};
struct dt_device_node;
+struct kernel_info;
struct vcpu;
int imsic_init(const struct dt_device_node *node);
@@ -94,4 +95,6 @@ void vcpu_imsic_deinit(const struct vcpu *v);
unsigned int vcpu_guest_file_id(const struct vcpu *v);
void imsic_set_guest_file_id(const struct vcpu *v, unsigned int guest_file_id);
+int vimsic_make_domu_dt_node(struct kernel_info *kinfo, unsigned int *phandle);
+
#endif /* ASM_RISCV_IMSIC_H */
diff --git a/xen/arch/riscv/vaplic.c b/xen/arch/riscv/vaplic.c
index d2ec196668bc..3f967464335a 100644
--- a/xen/arch/riscv/vaplic.c
+++ b/xen/arch/riscv/vaplic.c
@@ -9,6 +9,8 @@
*/
#include <xen/errno.h>
+#include <xen/fdt-kernel.h>
+#include <xen/libfdt/libfdt.h>
#include <xen/sched.h>
#include <xen/xvmalloc.h>
@@ -19,8 +21,11 @@
#include "aplic-priv.h"
+#define VAPLIC_COMPATIBLE "riscv,aplic"
#define VAPLIC_NUM_SOURCES 96
+#define FDT_VAPLIC_INT_CELLS 2
+
static int cf_check vcpu_vaplic_init(struct vcpu *v)
{
int rc = 0;
@@ -47,6 +52,73 @@ static int cf_check vcpu_vaplic_init(struct vcpu *v)
return rc;
}
+static int __init cf_check vaplic_make_domu_dt_node(struct kernel_info *kinfo)
+{
+ int res = 0;
+ void *fdt = kinfo->fdt;
+ unsigned int msi_parent_phandle;
+ char vaplic_name[128];
+ paddr_t aplic_addr = GUEST_APLIC_S_BASE;
+ paddr_t aplic_size = APLIC_SIZE(kinfo->bd.d->max_vcpus);
+ const __be32 reg[] = {
+ cpu_to_be32(aplic_addr >> 32),
+ cpu_to_be32(aplic_addr),
+ cpu_to_be32(aplic_size >> 32),
+ cpu_to_be32(aplic_size),
+ };
+ struct vintc *vintc = kinfo->bd.d->arch.vintc;
+
+ res = snprintf(vaplic_name, sizeof(vaplic_name), "/soc/aplic@%x",
+ GUEST_APLIC_S_BASE);
+ if ( res >= sizeof(vaplic_name) )
+ {
+ dprintk(XENLOG_DEBUG, "vaplic name is truncated\n");
+ return -ENOBUFS;
+ }
+
+ res = vimsic_make_domu_dt_node(kinfo, &msi_parent_phandle);
+ if ( res )
+ return res;
+
+ res = fdt_begin_node(fdt, vaplic_name);
+ if ( res )
+ return res;
+
+ res = fdt_property_cell(fdt, "#interrupt-cells", FDT_VAPLIC_INT_CELLS);
+ if ( res )
+ return res;
+
+ res = fdt_property(fdt, "reg", reg, sizeof(reg));
+ if ( res )
+ return res;
+
+ res = fdt_property_cell(fdt, "riscv,num-sources", vintc->irq_nums);
+ if ( res )
+ return res;
+
+ res = fdt_property(fdt, "interrupt-controller", NULL, 0);
+ if ( res )
+ return res;
+
+ res = fdt_property_string(fdt, "compatible", VAPLIC_COMPATIBLE);
+ if ( res )
+ return res;
+
+ res = fdt_property_cell(fdt, "msi-parent", msi_parent_phandle);
+ if ( res )
+ return res;
+
+ res = fdt_property_cell(fdt, "phandle", kinfo->phandle_intc);
+ if ( res )
+ return res;
+
+ return fdt_end_node(fdt);
+}
+
+static const struct vintc_init_ops __initdata init_ops = {
+ .make_domu_dt_node = vaplic_make_domu_dt_node,
+};
+
static const struct vintc_ops vintc_ops = {
.vcpu_init = vcpu_vaplic_init,
};
@@ -60,13 +132,14 @@ int __init domain_vaplic_init(struct domain *d)
d->arch.vintc = &vaplic->vintc;
d->arch.vintc->ops = &vintc_ops;
+ d->arch.vintc->init_ops = &init_ops;
- vaplic->regs.domaincfg = APLIC_DOMAINCFG_IE | APLIC_DOMAINCFG_DM;
+ vaplic->regs.domaincfg = APLIC_DOMAINCFG_IE | APLIC_DOMAINCFG_DM |
+ APLIC_DOMAINCFG_RO80;
d->arch.vintc->irq_nums = min(intc_irq_nums(),
VAPLIC_NUM_SOURCES + 0U);
-
return 0;
}
--
2.54.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |