mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-20 19:44:23 +00:00
Merge changes from topic "version/0.1-gic" into integration
* changes: feat(qemu-sbsa): handle GIC base feat(qemu-sbsa): handle platform version
This commit is contained in:
commit
e9736a01a1
6 changed files with 249 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
|
* Copyright (c) 2015-2023, ARM Limited and Contributors. All rights reserved.
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -55,6 +55,11 @@ void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
|
||||||
/* Initialize the console to provide early debug support */
|
/* Initialize the console to provide early debug support */
|
||||||
qemu_console_init();
|
qemu_console_init();
|
||||||
|
|
||||||
|
/* Platform names have to be lowercase. */
|
||||||
|
#ifdef PLAT_qemu_sbsa
|
||||||
|
sip_svc_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check params passed from BL2
|
* Check params passed from BL2
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015-2022, ARM Limited and Contributors. All rights reserved.
|
* Copyright (c) 2015-2023, ARM Limited and Contributors. All rights reserved.
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -18,6 +18,9 @@ unsigned int plat_qemu_calc_core_pos(u_register_t mpidr);
|
||||||
const mmap_region_t *plat_qemu_get_mmap(void);
|
const mmap_region_t *plat_qemu_get_mmap(void);
|
||||||
|
|
||||||
void qemu_console_init(void);
|
void qemu_console_init(void);
|
||||||
|
#ifdef PLAT_qemu_sbsa
|
||||||
|
void sip_svc_init(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
void plat_qemu_gic_init(void);
|
void plat_qemu_gic_init(void);
|
||||||
void qemu_pwr_gic_on_finish(void);
|
void qemu_pwr_gic_on_finish(void);
|
||||||
|
|
|
@ -215,6 +215,8 @@
|
||||||
/*
|
/*
|
||||||
* GIC related constants
|
* GIC related constants
|
||||||
* We use GICv3 where CPU Interface registers are not memory mapped
|
* We use GICv3 where CPU Interface registers are not memory mapped
|
||||||
|
*
|
||||||
|
* Legacy values - on platform version 0.1+ they are read from DT
|
||||||
*/
|
*/
|
||||||
#define GICD_BASE 0x40060000
|
#define GICD_BASE 0x40060000
|
||||||
#define GICR_BASE 0x40080000
|
#define GICR_BASE 0x40080000
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2019-2021, Linaro Limited and Contributors. All rights reserved.
|
# Copyright (c) 2019-2023, Linaro Limited and Contributors. All rights reserved.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
@ -89,14 +89,15 @@ endif
|
||||||
include drivers/arm/gic/v3/gicv3.mk
|
include drivers/arm/gic/v3/gicv3.mk
|
||||||
|
|
||||||
QEMU_GIC_SOURCES := ${GICV3_SOURCES} \
|
QEMU_GIC_SOURCES := ${GICV3_SOURCES} \
|
||||||
plat/common/plat_gicv3.c \
|
plat/common/plat_gicv3.c
|
||||||
${PLAT_QEMU_COMMON_PATH}/qemu_gicv3.c
|
|
||||||
|
|
||||||
BL31_SOURCES += ${QEMU_CPU_LIBS} \
|
BL31_SOURCES += ${QEMU_CPU_LIBS} \
|
||||||
lib/semihosting/semihosting.c \
|
lib/semihosting/semihosting.c \
|
||||||
lib/semihosting/${ARCH}/semihosting_call.S \
|
lib/semihosting/${ARCH}/semihosting_call.S \
|
||||||
plat/common/plat_psci_common.c \
|
plat/common/plat_psci_common.c \
|
||||||
|
${PLAT_QEMU_PATH}/sbsa_gic.c \
|
||||||
${PLAT_QEMU_PATH}/sbsa_pm.c \
|
${PLAT_QEMU_PATH}/sbsa_pm.c \
|
||||||
|
${PLAT_QEMU_PATH}/sbsa_sip_svc.c \
|
||||||
${PLAT_QEMU_PATH}/sbsa_topology.c \
|
${PLAT_QEMU_PATH}/sbsa_topology.c \
|
||||||
${PLAT_QEMU_COMMON_PATH}/aarch64/plat_helpers.S \
|
${PLAT_QEMU_COMMON_PATH}/aarch64/plat_helpers.S \
|
||||||
${PLAT_QEMU_COMMON_PATH}/qemu_bl31_setup.c \
|
${PLAT_QEMU_COMMON_PATH}/qemu_bl31_setup.c \
|
||||||
|
|
67
plat/qemu/qemu_sbsa/sbsa_gic.c
Normal file
67
plat/qemu/qemu_sbsa/sbsa_gic.c
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, Linaro Limited and Contributors. All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <drivers/arm/gicv3.h>
|
||||||
|
#include <plat/common/platform.h>
|
||||||
|
|
||||||
|
static const interrupt_prop_t qemu_interrupt_props[] = {
|
||||||
|
PLATFORM_G1S_PROPS(INTR_GROUP1S),
|
||||||
|
PLATFORM_G0_PROPS(INTR_GROUP0)
|
||||||
|
};
|
||||||
|
|
||||||
|
static uintptr_t qemu_rdistif_base_addrs[PLATFORM_CORE_COUNT];
|
||||||
|
|
||||||
|
static unsigned int qemu_mpidr_to_core_pos(unsigned long mpidr)
|
||||||
|
{
|
||||||
|
return plat_core_pos_by_mpidr(mpidr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gicv3_driver_data_t sbsa_gic_driver_data = {
|
||||||
|
/* we set those two values for compatibility with older QEMU */
|
||||||
|
.gicd_base = GICD_BASE,
|
||||||
|
.gicr_base = GICR_BASE,
|
||||||
|
.interrupt_props = qemu_interrupt_props,
|
||||||
|
.interrupt_props_num = ARRAY_SIZE(qemu_interrupt_props),
|
||||||
|
.rdistif_num = PLATFORM_CORE_COUNT,
|
||||||
|
.rdistif_base_addrs = qemu_rdistif_base_addrs,
|
||||||
|
.mpidr_to_core_pos = qemu_mpidr_to_core_pos
|
||||||
|
};
|
||||||
|
|
||||||
|
void sbsa_set_gic_bases(const uintptr_t gicd_base, const uintptr_t gicr_base)
|
||||||
|
{
|
||||||
|
sbsa_gic_driver_data.gicd_base = gicd_base;
|
||||||
|
sbsa_gic_driver_data.gicr_base = gicr_base;
|
||||||
|
}
|
||||||
|
|
||||||
|
uintptr_t sbsa_get_gicd(void)
|
||||||
|
{
|
||||||
|
return sbsa_gic_driver_data.gicd_base;
|
||||||
|
}
|
||||||
|
|
||||||
|
uintptr_t sbsa_get_gicr(void)
|
||||||
|
{
|
||||||
|
return sbsa_gic_driver_data.gicr_base;
|
||||||
|
}
|
||||||
|
|
||||||
|
void plat_qemu_gic_init(void)
|
||||||
|
{
|
||||||
|
gicv3_driver_init(&sbsa_gic_driver_data);
|
||||||
|
gicv3_distif_init();
|
||||||
|
gicv3_rdistif_init(plat_my_core_pos());
|
||||||
|
gicv3_cpuif_enable(plat_my_core_pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
void qemu_pwr_gic_on_finish(void)
|
||||||
|
{
|
||||||
|
gicv3_rdistif_init(plat_my_core_pos());
|
||||||
|
gicv3_cpuif_enable(plat_my_core_pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
void qemu_pwr_gic_off(void)
|
||||||
|
{
|
||||||
|
gicv3_cpuif_disable(plat_my_core_pos());
|
||||||
|
gicv3_rdistif_off(plat_my_core_pos());
|
||||||
|
}
|
166
plat/qemu/qemu_sbsa/sbsa_sip_svc.c
Normal file
166
plat/qemu/qemu_sbsa/sbsa_sip_svc.c
Normal file
|
@ -0,0 +1,166 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, Linaro Limited and Contributors. All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <common/fdt_wrappers.h>
|
||||||
|
#include <common/runtime_svc.h>
|
||||||
|
#include <libfdt.h>
|
||||||
|
#include <smccc_helpers.h>
|
||||||
|
|
||||||
|
/* default platform version is 0.0 */
|
||||||
|
static int platform_version_major;
|
||||||
|
static int platform_version_minor;
|
||||||
|
|
||||||
|
#define SMC_FASTCALL 0x80000000
|
||||||
|
#define SMC64_FUNCTION (SMC_FASTCALL | 0x40000000)
|
||||||
|
#define SIP_FUNCTION (SMC64_FUNCTION | 0x02000000)
|
||||||
|
#define SIP_FUNCTION_ID(n) (SIP_FUNCTION | (n))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We do not use SMCCC_ARCH_SOC_ID here because qemu_sbsa is virtual platform
|
||||||
|
* which uses SoC present in QEMU. And they can change on their own while we
|
||||||
|
* need version of whole 'virtual hardware platform'.
|
||||||
|
*/
|
||||||
|
#define SIP_SVC_VERSION SIP_FUNCTION_ID(1)
|
||||||
|
|
||||||
|
#define SIP_SVC_GET_GIC SIP_FUNCTION_ID(100)
|
||||||
|
|
||||||
|
void sbsa_set_gic_bases(const uintptr_t gicd_base, const uintptr_t gicr_base);
|
||||||
|
uintptr_t sbsa_get_gicd(void);
|
||||||
|
uintptr_t sbsa_get_gicr(void);
|
||||||
|
|
||||||
|
void read_platform_config_from_dt(void *dtb)
|
||||||
|
{
|
||||||
|
int node;
|
||||||
|
const fdt64_t *data;
|
||||||
|
int err;
|
||||||
|
uintptr_t gicd_base;
|
||||||
|
uintptr_t gicr_base;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* QEMU gives us this DeviceTree node:
|
||||||
|
*
|
||||||
|
* intc {
|
||||||
|
reg = < 0x00 0x40060000 0x00 0x10000
|
||||||
|
0x00 0x40080000 0x00 0x4000000>;
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
node = fdt_path_offset(dtb, "/intc");
|
||||||
|
if (node < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = fdt_getprop(dtb, node, "reg", NULL);
|
||||||
|
if (data == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = fdt_get_reg_props_by_index(dtb, node, 0, &gicd_base, NULL);
|
||||||
|
if (err < 0) {
|
||||||
|
ERROR("Failed to read GICD reg property of GIC node\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
INFO("GICD base = 0x%lx\n", gicd_base);
|
||||||
|
|
||||||
|
err = fdt_get_reg_props_by_index(dtb, node, 1, &gicr_base, NULL);
|
||||||
|
if (err < 0) {
|
||||||
|
ERROR("Failed to read GICR reg property of GIC node\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
INFO("GICR base = 0x%lx\n", gicr_base);
|
||||||
|
|
||||||
|
sbsa_set_gic_bases(gicd_base, gicr_base);
|
||||||
|
}
|
||||||
|
|
||||||
|
void read_platform_version(void *dtb)
|
||||||
|
{
|
||||||
|
int node;
|
||||||
|
|
||||||
|
node = fdt_path_offset(dtb, "/");
|
||||||
|
if (node >= 0) {
|
||||||
|
platform_version_major = fdt32_ld(fdt_getprop(dtb, node,
|
||||||
|
"machine-version-major", NULL));
|
||||||
|
platform_version_minor = fdt32_ld(fdt_getprop(dtb, node,
|
||||||
|
"machine-version-minor", NULL));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sip_svc_init(void)
|
||||||
|
{
|
||||||
|
/* Read DeviceTree data before MMU is enabled */
|
||||||
|
|
||||||
|
void *dtb = (void *)(uintptr_t)ARM_PRELOADED_DTB_BASE;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = fdt_open_into(dtb, dtb, PLAT_QEMU_DT_MAX_SIZE);
|
||||||
|
if (err < 0) {
|
||||||
|
ERROR("Invalid Device Tree at %p: error %d\n", dtb, err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = fdt_check_header(dtb);
|
||||||
|
if (err < 0) {
|
||||||
|
ERROR("Invalid DTB file passed\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
read_platform_version(dtb);
|
||||||
|
INFO("Platform version: %d.%d\n", platform_version_major, platform_version_minor);
|
||||||
|
|
||||||
|
read_platform_config_from_dt(dtb);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function is responsible for handling all SiP calls from the NS world
|
||||||
|
*/
|
||||||
|
uintptr_t sbsa_sip_smc_handler(uint32_t smc_fid,
|
||||||
|
u_register_t x1,
|
||||||
|
u_register_t x2,
|
||||||
|
u_register_t x3,
|
||||||
|
u_register_t x4,
|
||||||
|
void *cookie,
|
||||||
|
void *handle,
|
||||||
|
u_register_t flags)
|
||||||
|
{
|
||||||
|
uint32_t ns;
|
||||||
|
|
||||||
|
/* Determine which security state this SMC originated from */
|
||||||
|
ns = is_caller_non_secure(flags);
|
||||||
|
if (!ns) {
|
||||||
|
ERROR("%s: wrong world SMC (0x%x)\n", __func__, smc_fid);
|
||||||
|
SMC_RET1(handle, SMC_UNK);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (smc_fid) {
|
||||||
|
case SIP_SVC_VERSION:
|
||||||
|
INFO("Platform version requested\n");
|
||||||
|
SMC_RET3(handle, NULL, platform_version_major, platform_version_minor);
|
||||||
|
|
||||||
|
case SIP_SVC_GET_GIC:
|
||||||
|
SMC_RET3(handle, NULL, sbsa_get_gicd(), sbsa_get_gicr());
|
||||||
|
|
||||||
|
default:
|
||||||
|
ERROR("%s: unhandled SMC (0x%x) (function id: %d)\n", __func__, smc_fid,
|
||||||
|
smc_fid - SIP_FUNCTION);
|
||||||
|
SMC_RET1(handle, SMC_UNK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int sbsa_sip_smc_setup(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Define a runtime service descriptor for fast SMC calls */
|
||||||
|
DECLARE_RT_SVC(
|
||||||
|
sbsa_sip_svc,
|
||||||
|
OEN_SIP_START,
|
||||||
|
OEN_SIP_END,
|
||||||
|
SMC_TYPE_FAST,
|
||||||
|
sbsa_sip_smc_setup,
|
||||||
|
sbsa_sip_smc_handler
|
||||||
|
);
|
Loading…
Add table
Reference in a new issue