Unverified Commit fca0a51f authored by Antonio Niño Díaz's avatar Antonio Niño Díaz Committed by GitHub
Browse files

Merge pull request #1707 from antonio-nino-diaz-arm/an/spm

SPM: Initial prototype based on SPCI and SPRT
parents 19122fca 2ada829d
......@@ -501,6 +501,10 @@ CRTTOOL ?= ${CRTTOOLPATH}/cert_create${BIN_EXT}
FIPTOOLPATH ?= tools/fiptool
FIPTOOL ?= ${FIPTOOLPATH}/fiptool${BIN_EXT}
# Variables for use with sptool
SPTOOLPATH ?= tools/sptool
SPTOOL ?= ${SPTOOLPATH}/sptool${BIN_EXT}
# Variables for use with ROMLIB
ROMLIBPATH ?= lib/romlib
......@@ -570,6 +574,7 @@ $(eval $(call assert_boolean,RESET_TO_BL31))
$(eval $(call assert_boolean,SAVE_KEYS))
$(eval $(call assert_boolean,SEPARATE_CODE_AND_RODATA))
$(eval $(call assert_boolean,SPIN_ON_BL1_EXIT))
$(eval $(call assert_boolean,SPM_DEPRECATED))
$(eval $(call assert_boolean,TRUSTED_BOARD_BOOT))
$(eval $(call assert_boolean,USE_COHERENT_MEM))
$(eval $(call assert_boolean,USE_ROMLIB))
......@@ -623,6 +628,7 @@ $(eval $(call add_define,RECLAIM_INIT_CODE))
$(eval $(call add_define,SMCCC_MAJOR_VERSION))
$(eval $(call add_define,SPD_${SPD}))
$(eval $(call add_define,SPIN_ON_BL1_EXIT))
$(eval $(call add_define,SPM_DEPRECATED))
$(eval $(call add_define,TRUSTED_BOARD_BOOT))
$(eval $(call add_define,USE_COHERENT_MEM))
$(eval $(call add_define,USE_ROMLIB))
......@@ -657,7 +663,7 @@ endif
# Build targets
################################################################################
.PHONY: all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool fip fwu_fip certtool dtbs
.PHONY: all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip fwu_fip certtool dtbs
.SUFFIXES:
all: msg_start
......@@ -744,6 +750,7 @@ realclean distclean:
$(call SHELL_REMOVE_DIR,${BUILD_BASE})
$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
${Q}${MAKE} --no-print-directory -C ${SPTOOLPATH} clean
${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
......@@ -824,6 +831,11 @@ fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
${FIPTOOL}:
${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${FIPTOOLPATH}
sptool: ${SPTOOL}
.PHONY: ${SPTOOL}
${SPTOOL}:
${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${SPTOOLPATH}
.PHONY: libraries
romlib.bin: libraries
${Q}${MAKE} BUILD_PLAT=${BUILD_PLAT} INCLUDES='${INCLUDES}' DEFINES='${DEFINES}' --no-print-directory -C ${ROMLIBPATH} all
......@@ -863,6 +875,7 @@ help:
@echo " distclean Remove all build artifacts for all platforms"
@echo " certtool Build the Certificate generation tool"
@echo " fiptool Build the Firmware Image Package (FIP) creation tool"
@echo " sptool Build the Secure Partition Package creation tool"
@echo " dtbs Build the Device Tree Blobs (if required for the platform)"
@echo ""
@echo "Note: most build targets require PLAT to be set to a specific platform."
......
......@@ -382,8 +382,16 @@ smc_handler64:
*/
tbz x0, #(FUNCID_NAMESPACE_SHIFT + 1), compat_or_vendor
/* Namespaces SPRT and SPCI currently unimplemented */
/* Namespace is b'10 (SPRT) or b'11 (SPCI) */
#if ENABLE_SPM
tst x0, #(1 << FUNCID_NAMESPACE_SHIFT)
adr x15, spci_smc_handler
adr x16, sprt_smc_handler
csel x15, x15, x16, ne
b prepare_enter_handler
#else
b smc_unknown
#endif
compat_or_vendor:
......@@ -401,6 +409,8 @@ compat_or_vendor:
load_rt_svc_desc_pointer
prepare_enter_handler:
#endif /* SMCCC_MAJOR_VERSION */
/*
......
......@@ -8,11 +8,16 @@
# Include SPM Makefile
################################################################################
ifeq (${ENABLE_SPM},1)
ifeq (${EL3_EXCEPTION_HANDLING},0)
$(error EL3_EXCEPTION_HANDLING must be 1 for SPM support)
endif
$(info Including SPM makefile)
include services/std_svc/spm/spm.mk
ifeq (${SPM_DEPRECATED},1)
ifeq (${EL3_EXCEPTION_HANDLING},0)
$(error EL3_EXCEPTION_HANDLING must be 1 for SPM support)
endif
$(info Including deprecated SPM makefile)
include services/std_svc/spm_deprecated/spm.mk
else
$(info Including SPM makefile)
include services/std_svc/spm/spm.mk
endif
endif
......
/*
* Copyright (c) 2018, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SPRT_COMMON_H
#define SPRT_COMMON_H
#define SPRT_MAX_MSG_ARGS 6
/*
* Message types supported.
*/
#define SPRT_MSG_TYPE_SERVICE_HANDLE_OPEN 1
#define SPRT_MSG_TYPE_SERVICE_HANDLE_CLOSE 2
/* TODO: Add other types of SPRT messages. */
#define SPRT_MSG_TYPE_SERVICE_TUN_REQUEST 10
/*
* Struct that defines the layout of the fields corresponding to a request in
* shared memory.
*/
struct __attribute__((__packed__)) sprt_queue_entry_message {
uint32_t type; /* Type of message (result of an SPCI call). */
uint16_t client_id; /* SPCI client ID */
uint16_t service_handle;/* SPCI service handle */
uint32_t session_id; /* Optional SPCI session ID */
uint32_t token; /* SPCI request token */
uint64_t args[SPRT_MAX_MSG_ARGS];
};
#define SPRT_QUEUE_ENTRY_MSG_SIZE (sizeof(struct sprt_queue_entry_message))
#define SPRT_QUEUE_NUM_BLOCKING 0
#define SPRT_QUEUE_NUM_NON_BLOCKING 1
#endif /* SPRT_COMMON_H */
/*
* Copyright (c) 2018, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SPRT_HOST_H
#define SPRT_HOST_H
#include <stddef.h>
#include "sprt_common.h"
/*
* Initialize the specified buffer to be used by SPM.
*/
void sprt_initialize_queues(void *buffer_base, size_t buffer_size);
/*
* Push a message to the queue number `queue_num` in a buffer that has been
* initialized by `sprt_initialize_queues`.
*/
int sprt_push_message(void *buffer_base,
const struct sprt_queue_entry_message *message,
int queue_num);
#endif /* SPRT_HOST_H */
......@@ -208,6 +208,17 @@ typedef struct xlat_ctx xlat_ctx_t;
void init_xlat_tables(void);
void init_xlat_tables_ctx(xlat_ctx_t *ctx);
/*
* Fill all fields of a dynamic translation tables context. It must be done
* either statically with REGISTER_XLAT_CONTEXT() or at runtime with this
* function.
*/
void xlat_setup_dynamic_ctx(xlat_ctx_t *ctx, unsigned long long pa_max,
uintptr_t va_max, struct mmap_region *mmap,
unsigned int mmap_num, uint64_t **tables,
unsigned int tables_num, uint64_t *base_table,
int xlat_regime, int *mapped_regions);
/*
* Add a static region with defined base PA and base VA. This function can only
* be used before initializing the translation tables. The region cannot be
......
......@@ -10,6 +10,31 @@
#include <utils_def.h>
#include <xlat_tables_defs.h>
/*
* Reserve 4 MiB for binaries of Secure Partitions and Resource Description
* blobs.
*/
#define PLAT_SP_PACKAGE_BASE BL32_BASE
#define PLAT_SP_PACKAGE_SIZE ULL(0x400000)
#define PLAT_MAP_SP_PACKAGE_MEM_RO MAP_REGION_FLAT( \
PLAT_SP_PACKAGE_BASE, \
PLAT_SP_PACKAGE_SIZE, \
MT_MEMORY | MT_RO | MT_SECURE)
#define PLAT_MAP_SP_PACKAGE_MEM_RW MAP_REGION_FLAT( \
PLAT_SP_PACKAGE_BASE, \
PLAT_SP_PACKAGE_SIZE, \
MT_MEMORY | MT_RW | MT_SECURE)
/*
* The rest of the memory reserved for BL32 is free for SPM to use it as memory
* pool to allocate memory regions requested in the resource description.
*/
#define PLAT_SPM_HEAP_BASE (PLAT_SP_PACKAGE_BASE + PLAT_SP_PACKAGE_SIZE)
#define PLAT_SPM_HEAP_SIZE (BL32_LIMIT - BL32_BASE - PLAT_SP_PACKAGE_SIZE)
#if SPM_DEPRECATED
/*
* If BL31 is placed in DRAM, place the Secure Partition in DRAM right after the
* region used by BL31. If BL31 it is placed in SRAM, put the Secure Partition
......@@ -27,6 +52,7 @@
ARM_SP_IMAGE_SIZE, \
MT_MEMORY | MT_RW | MT_SECURE)
#endif
#ifdef IMAGE_BL31
/* SPM Payload memory. Mapped as code in S-EL1 */
#define ARM_SP_IMAGE_MMAP MAP_REGION2( \
......@@ -96,8 +122,23 @@
/* Total number of memory regions with distinct properties */
#define ARM_SP_IMAGE_NUM_MEM_REGIONS 6
#endif /* SPM_DEPRECATED */
/* Cookies passed to the Secure Partition at boot. Not used by ARM platforms. */
#define PLAT_SPM_COOKIE_0 ULL(0)
#define PLAT_SPM_COOKIE_1 ULL(0)
/*
* Max number of elements supported by SPM in this platform. The defines below
* are used to allocate memory at compile time for different arrays in SPM.
*/
#define PLAT_SPM_MAX_PARTITIONS U(2)
#define PLAT_SPM_MEM_REGIONS_MAX U(80)
#define PLAT_SPM_NOTIFICATIONS_MAX U(30)
#define PLAT_SPM_SERVICES_MAX U(30)
#define PLAT_SPCI_HANDLES_MAX_NUM U(20)
#define PLAT_SPM_RESPONSES_MAX U(30)
#endif /* ARM_SPM_DEF_H */
......@@ -37,7 +37,7 @@ typedef struct arm_tzc_regions_info {
* - Region 1 with secure access only;
* - the remaining DRAM regions access from the given Non-Secure masters.
******************************************************************************/
#if ENABLE_SPM
#if ENABLE_SPM && SPM_DEPRECATED
#define ARM_TZC_REGIONS_DEF \
{ARM_AP_TZC_DRAM1_BASE, ARM_EL3_TZC_DRAM1_END, \
TZC_REGION_S_RDWR, 0}, \
......
......@@ -22,6 +22,7 @@ struct bl_load_info;
struct bl_params;
struct mmap_region;
struct secure_partition_boot_info;
struct sp_res_desc;
/*******************************************************************************
* plat_get_rotpk_info() flags
......@@ -266,6 +267,9 @@ int plat_set_nv_ctr2(void *cookie, const struct auth_img_desc_s *img_desc,
const struct mmap_region *plat_get_secure_partition_mmap(void *cookie);
const struct secure_partition_boot_info *plat_get_secure_partition_boot_info(
void *cookie);
int plat_spm_sp_rd_load(struct sp_res_desc *rd, const void *ptr, size_t size);
int plat_spm_sp_get_next_address(void **sp_base, size_t *sp_size,
void **rd_base, size_t *rd_size);
/*******************************************************************************
* Mandatory BL image load functions(may be overridden).
......
......@@ -7,6 +7,8 @@
#ifndef MM_SVC_H
#define MM_SVC_H
#if SPM_DEPRECATED
#include <utils_def.h>
#define MM_VERSION_MAJOR U(1)
......@@ -28,4 +30,6 @@
#define MM_COMMUNICATE_AARCH64 U(0xC4000041)
#define MM_COMMUNICATE_AARCH32 U(0x84000041)
#endif /* SPM_DEPRECATED */
#endif /* MM_SVC_H */
......@@ -7,6 +7,8 @@
#ifndef SECURE_PARTITION_H
#define SECURE_PARTITION_H
#if SPM_DEPRECATED
#include <stdint.h>
#include <utils_def.h>
......@@ -46,4 +48,6 @@ typedef struct secure_partition_boot_info {
secure_partition_mp_info_t *mp_info;
} secure_partition_boot_info_t;
#endif /* SPM_DEPRECATED */
#endif /* SECURE_PARTITION_H */
/*
* Copyright (c) 2018, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SPM_RES_DESC_H
#define SPM_RES_DESC_H
#include <stdint.h>
#include <sp_res_desc_def.h>
/*******************************************************************************
* Attribute Section
******************************************************************************/
struct sp_rd_sect_attribute {
/*
* Version of the resource description.
*/
uint16_t version;
/*
* Type of the Secure Partition:
* - bit[0]: SP Type
* - b'0: UP SP
* - b'1: MP SP
* If UP SP:
* - bit[1]: Type of UP SP
* - b'0: Migratable UP SP
* - b'1: Pinned UP SP
*/
uint16_t sp_type;
/*
* If this is a Pinned UP SP, PE on which the Pinned UP SP will run.
*/
uint32_t pe_mpidr;
/*
* Run-Time Exception Level:
* - 0: SEL0 SP
* - 1: SEL1 SP
*/
uint8_t runtime_el;
/*
* Type of Execution:
* - 0: Init-time only
* - 1: Run-time Execution
*/
uint8_t exec_type;
/*
* Expected behavior upon failure:
* - 0: Restartable
* - 1: One-Shot
*/
uint8_t panic_policy;
/*
* Translation Granule to use in the SP translation regime:
* - 0: 4KB
* - 1: 16KB
* - 2: 64KB
*/
uint8_t xlat_granule;
/*
* Size of the SP binary in bytes.
*/
uint32_t binary_size;
/*
* - If SP is NOT PIE:
* - VA Address where the SP expects to be loaded.
* - If SP is PIE:
* - Ignored.
*/
uint64_t load_address;
/*
* Initial execution address. This is a VA as the SP sees it.
*/
uint64_t entrypoint;
};
/*******************************************************************************
* Memory Region Section
******************************************************************************/
struct sp_rd_sect_mem_region {
/*
* Name of a Memory region, including null terminator. Reserved names:
* - "Client Shared Memory Region":
* Memory region where memory shared by clients shall be mapped.
* - "Queue Memory Region":
* Memory region shared with SPM for SP queue management.
*/
char name[RD_MEM_REGION_NAME_LEN];
/*
* Memory Attributes:
* - bits[3:0]: Type of memory
* - 0: Device
* - 1: Code
* - 2: Data
* - 3: BSS
* - 4: Read-only Data
* - 5: SPM-to-SP Shared Memory Region
* - 6: Client Shared Memory Region
* - 7: Miscellaneous
* - If memory is { SPM-to-SP shared Memory, Client Shared Memory,
* Miscellaneous }
* - bits[4]: Position Independent
* - b'0: Position Dependent
* - b'1: Position Independent
*/
uint32_t attr;
/*
* Base address of the memory region.
*/
uint64_t base;
/*
* Size of the memory region.
*/
uint64_t size;
/*
* Pointer to next memory region (or NULL if this is the last one).
*/
struct sp_rd_sect_mem_region *next;
};
/*******************************************************************************
* Notification Section
******************************************************************************/
struct sp_rd_sect_notification {
/*
* Notification attributes:
* - bit[31]: Notification Type
* - b'0: Platform Notification
* - b'1: Interrupt
* If Notification Type == Platform Notification
* - bits[15:0]: Implementation-defined Notification ID
* If Notification Type == Interrupt
* - bits[15:0]: IRQ number
* - bits[23:16]: Interrupt Priority
* - bit[24]: Trigger Type
* - b'0: Edge Triggered
* - b'1: Level Triggered
* - bit[25]: Trigger Level
* - b'0: Falling or Low
* - b'1: Rising or High
*/
uint32_t attr;
/*
* Processing Element.
* If Notification Type == Interrupt && IRQ number is { SGI, LPI }
* - PE ID to which IRQ will be forwarded
*/
uint32_t pe;
/*
* Pointer to next notification (or NULL if this is the last one).
*/
struct sp_rd_sect_notification *next;
};
/*******************************************************************************
* Service Description Section
******************************************************************************/
struct sp_rd_sect_service {
/*
* Service identifier.
*/
uint32_t uuid[4];
/*
* Accessibility Options:
* - bit[0]: Accessibility by secure-world clients
* - b'0: Not Accessible
* - b'1: Accessible
* - bit[1]: Accessible by EL3
* - b'0: Not Accessible
* - b'1: Accessible
* - bit[2]: Accessible by normal-world clients
* - b'0: Not Accessible
* - b'1: Accessible
*/
uint8_t accessibility;
/*
* Request type supported:
* - bit[0]: Blocking request
* - b'0: Not Enable
* - b'1: Enable
* - bit[1]: Non-blocking request
* - b'0: Not Enable
* - b'1: Enable
*/
uint8_t request_type;
/*
* Maximum number of client connections that the service can support.
*/
uint16_t connection_quota;
/*
* If the service requires secure world memory to be shared with its
* clients:
* - Maximum amount of secure world memory in bytes to reserve from the
* secure world memory pool for the service.
*/
uint32_t secure_mem_size;
/*
* Interrupt number used to notify the SP for the service.
* - Should also be enabled in the Notification Section.
*/
uint32_t interrupt_num;
/*
* Pointer to next service (or NULL if this is the last one).
*/
struct sp_rd_sect_service *next;
};
/*******************************************************************************
* Complete resource description struct
******************************************************************************/
struct sp_res_desc {
/* Attribute Section */
struct sp_rd_sect_attribute attribute;
/* System Resource Section */
struct sp_rd_sect_mem_region *mem_region;
struct sp_rd_sect_notification *notification;
/* Service Section */
struct sp_rd_sect_service *service;
};
#endif /* SPM_RES_DESC_H */
/*
* Copyright (c) 2018, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SPM_RES_DESC_DEFS_H
#define SPM_RES_DESC_DEFS_H
#include <utils_def.h>
/*******************************************************************************
* Attribute Section
******************************************************************************/
#define RD_ATTR_TYPE_UP_MIGRATABLE U(0)
#define RD_ATTR_TYPE_UP_PINNED U(2)
#define RD_ATTR_TYPE_MP U(1)
#define RD_ATTR_RUNTIME_SEL0 U(0)
#define RD_ATTR_RUNTIME_SEL1 U(1)
#define RD_ATTR_INIT_ONLY U(0)
#define RD_ATTR_RUNTIME U(1)
#define RD_ATTR_PANIC_RESTART U(0)
#define RD_ATTR_PANIC_ONESHOT U(1)
#define RD_ATTR_XLAT_GRANULE_4KB U(0)
#define RD_ATTR_XLAT_GRANULE_16KB U(1)
#define RD_ATTR_XLAT_GRANULE_64KB U(2)
/*******************************************************************************
* Memory Region Section
******************************************************************************/
#define RD_MEM_REGION_NAME_LEN U(32)
#define RD_MEM_DEVICE U(0)
#define RD_MEM_NORMAL_CODE U(1)
#define RD_MEM_NORMAL_DATA U(2)
#define RD_MEM_NORMAL_BSS U(3)
#define RD_MEM_NORMAL_RODATA U(4)
#define RD_MEM_NORMAL_SPM_SP_SHARED_MEM U(5)
#define RD_MEM_NORMAL_CLIENT_SHARED_MEM U(6)
#define RD_MEM_NORMAL_MISCELLANEOUS U(7)
#define RD_MEM_MASK U(15)
#define RD_MEM_IS_PIE (U(1) << 4)
/*******************************************************************************
* Notification Section
******************************************************************************/
#define RD_NOTIF_TYPE_PLATFORM (U(0) << 31)
#define RD_NOTIF_TYPE_INTERRUPT (U(1) << 31)
#define RD_NOTIF_PLAT_ID_MASK U(0xFFFF)
#define RD_NOTIF_PLAT_ID_SHIFT U(0)
#define RD_NOTIF_PLATFORM(id) \
(RD_NOTIF_TYPE_PLATFORM \
| (((id) & RD_NOTIF_PLAT_ID_MASK) << RD_NOTIF_PLAT_ID_SHIFT))
#define RD_NOTIF_IRQ_NUM_MASK U(0xFFFF)
#define RD_NOTIF_IRQ_NUM_SHIFT U(0)
#define RD_NOTIF_IRQ_PRIO_MASK U(0xFF)
#define RD_NOTIF_IRQ_PRIO_SHIFT U(16)
#define RD_NOTIF_IRQ_EDGE_FALLING U(0)
#define RD_NOTIF_IRQ_EDGE_RISING U(2)
#define RD_NOTIF_IRQ_LEVEL_LOW U(1)
#define RD_NOTIF_IRQ_LEVEL_HIGH U(3)
#define RD_NOTIF_IRQ_TRIGGER_SHIFT U(24)
#define RD_NOTIF_IRQ(num, prio, trig) \
(RD_NOTIF_TYPE_IRQ \
| (((num) & RD_NOTIF_IRQ_NUM_MASK) << RD_NOTIF_IRQ_NUM_SHIFT) \
| (((prio) & RD_NOTIF_IRQ_PRIO_MASK) << RD_NOTIF_IRQ_PRIO_SHIFT) \
| (((trig) << RD_NOTIF_IRQ_TRIGGER_SHIFT)))
/*******************************************************************************
* Service Description Section
******************************************************************************/
#define RD_SERV_ACCESS_SECURE (U(1) << 0)
#define RD_SERV_ACCESS_EL3 (U(1) << 1)
#define RD_SERV_ACCESS_NORMAL (U(1) << 2)
#define RD_SERV_SUPPORT_BLOCKING (U(1) << 0)
#define RD_SERV_SUPPORT_NON_BLOCKING (U(1) << 0)
#endif /* SPM_RES_DESC_DEFS_H */
/*
* Copyright (c) 2018, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SPCI_SVC_H
#define SPCI_SVC_H
#include <smccc.h>
#include <utils_def.h>
/* SPCI_VERSION helpers */
#define SPCI_VERSION_MAJOR U(0)
#define SPCI_VERSION_MAJOR_SHIFT 16
#define SPCI_VERSION_MAJOR_MASK U(0x7FFF)
#define SPCI_VERSION_MINOR U(1)
#define SPCI_VERSION_MINOR_SHIFT 0
#define SPCI_VERSION_MINOR_MASK U(0xFFFF)
#define SPCI_VERSION_FORM(major, minor) ((((major) & SPCI_VERSION_MAJOR_MASK) \
<< SPCI_VERSION_MAJOR_SHIFT) | \
((minor) & SPCI_VERSION_MINOR_MASK))
#define SPCI_VERSION_COMPILED SPCI_VERSION_FORM(SPCI_VERSION_MAJOR, \
SPCI_VERSION_MINOR)
/* Definitions to build the complete SMC ID */
#define SPCI_FID_MISC_FLAG (U(0) << 27)
#define SPCI_FID_MISC_SHIFT U(20)
#define SPCI_FID_MISC_MASK U(0x7F)
#define SPCI_FID_TUN_FLAG (U(1) << 27)
#define SPCI_FID_TUN_SHIFT U(24)
#define SPCI_FID_TUN_MASK U(0x7)
#define SPCI_SMC(spci_fid) ((FUNCID_NAMESPACE_SPCI << FUNCID_NAMESPACE_SHIFT) | \
(U(1) << 31) | (spci_fid))
#define SPCI_MISC_32(misc_fid) ((SMC_32 << FUNCID_CC_SHIFT) | \
SPCI_FID_MISC_FLAG | \
SPCI_SMC((misc_fid) << SPCI_FID_MISC_SHIFT))
#define SPCI_MISC_64(misc_fid) ((SMC_64 << FUNCID_CC_SHIFT) | \
SPCI_FID_MISC_FLAG | \
SPCI_SMC((misc_fid) << SPCI_FID_MISC_SHIFT))
#define SPCI_TUN_32(tun_fid) ((SMC_32 << FUNCID_CC_SHIFT) | \
SPCI_FID_TUN_FLAG | \
SPCI_SMC((tun_fid) << SPCI_FID_TUN_SHIFT))
#define SPCI_TUN_64(tun_fid) ((SMC_64 << FUNCID_CC_SHIFT) | \
SPCI_FID_TUN_FLAG | \
SPCI_SMC((tun_fid) << SPCI_FID_TUN_SHIFT))
/* SPCI miscellaneous functions */
#define SPCI_FID_VERSION U(0x0)
#define SPCI_FID_SERVICE_HANDLE_OPEN U(0x2)
#define SPCI_FID_SERVICE_HANDLE_CLOSE U(0x3)
#define SPCI_FID_SERVICE_MEM_REGISTER U(0x4)
#define SPCI_FID_SERVICE_MEM_UNREGISTER U(0x5)
#define SPCI_FID_SERVICE_MEM_PUBLISH U(0x6)
#define SPCI_FID_SERVICE_REQUEST_BLOCKING U(0x7)
#define SPCI_FID_SERVICE_REQUEST_START U(0x8)
#define SPCI_FID_SERVICE_GET_RESPONSE U(0x9)
#define SPCI_FID_SERVICE_RESET_CLIENT_STATE U(0xA)
/* SPCI tunneling functions */
#define SPCI_FID_SERVICE_TUN_REQUEST_START U(0x0)
#define SPCI_FID_SERVICE_REQUEST_RESUME U(0x1)
#define SPCI_FID_SERVICE_TUN_REQUEST_BLOCKING U(0x2)
/* Complete SMC IDs and associated values */
#define SPCI_VERSION SPCI_MISC_32(SPCI_FID_VERSION)
#define SPCI_SERVICE_HANDLE_OPEN SPCI_MISC_32(SPCI_FID_SERVICE_HANDLE_OPEN)
#define SPCI_SERVICE_HANDLE_OPEN_NOTIFY_BIT U(1)
#define SPCI_SERVICE_HANDLE_CLOSE SPCI_MISC_32(SPCI_FID_SERVICE_HANDLE_CLOSE)
#define SPCI_SERVICE_MEM_REGISTER_AARCH32 SPCI_MISC_32(SPCI_FID_SERVICE_MEM_REGISTER)
#define SPCI_SERVICE_MEM_REGISTER_AARCH64 SPCI_MISC_64(SPCI_FID_SERVICE_MEM_REGISTER)
#define SPCI_SERVICE_MEM_UNREGISTER_AARCH32 SPCI_MISC_32(SPCI_FID_SERVICE_MEM_UNREGISTER)
#define SPCI_SERVICE_MEM_UNREGISTER_AARCH64 SPCI_MISC_64(SPCI_FID_SERVICE_MEM_UNREGISTER)
#define SPCI_SERVICE_MEM_PUBLISH_AARCH32 SPCI_MISC_32(SPCI_FID_SERVICE_MEM_PUBLISH)
#define SPCI_SERVICE_MEM_PUBLISH_AARCH64 SPCI_MISC_64(SPCI_FID_SERVICE_MEM_PUBLISH)
#define SPCI_SERVICE_REQUEST_BLOCKING_AARCH32 SPCI_MISC_32(SPCI_FID_SERVICE_REQUEST_BLOCKING)
#define SPCI_SERVICE_REQUEST_BLOCKING_AARCH64 SPCI_MISC_64(SPCI_FID_SERVICE_REQUEST_BLOCKING)
#define SPCI_SERVICE_REQUEST_START_AARCH32 SPCI_MISC_32(SPCI_FID_SERVICE_REQUEST_START)
#define SPCI_SERVICE_REQUEST_START_AARCH64 SPCI_MISC_64(SPCI_FID_SERVICE_REQUEST_START)
#define SPCI_SERVICE_GET_RESPONSE_AARCH32 SPCI_MISC_32(SPCI_FID_SERVICE_GET_RESPONSE)
#define SPCI_SERVICE_GET_RESPONSE_AARCH64 SPCI_MISC_64(SPCI_FID_SERVICE_GET_RESPONSE)
#define SPCI_SERVICE_RESET_CLIENT_STATE_AARCH32 SPCI_MISC_32(SPCI_FID_SERVICE_RESET_CLIENT_STATE)
#define SPCI_SERVICE_RESET_CLIENT_STATE_AARCH64 SPCI_MISC_64(SPCI_FID_SERVICE_RESET_CLIENT_STATE)
#define SPCI_SERVICE_TUN_REQUEST_START_AARCH32 SPCI_TUN_32(SPCI_FID_SERVICE_TUN_REQUEST_START)
#define SPCI_SERVICE_TUN_REQUEST_START_AARCH64 SPCI_TUN_64(SPCI_FID_SERVICE_TUN_REQUEST_START)
#define SPCI_SERVICE_REQUEST_RESUME_AARCH32 SPCI_TUN_32(SPCI_FID_SERVICE_REQUEST_RESUME)
#define SPCI_SERVICE_REQUEST_RESUME_AARCH64 SPCI_TUN_64(SPCI_FID_SERVICE_REQUEST_RESUME)
#define SPCI_SERVICE_TUN_REQUEST_BLOCKING_AARCH32 SPCI_TUN_32(SPCI_FID_SERVICE_TUN_REQUEST_BLOCKING)
#define SPCI_SERVICE_TUN_REQUEST_BLOCKING_AARCH64 SPCI_TUN_64(SPCI_FID_SERVICE_TUN_REQUEST_BLOCKING)
/* SPCI error codes. */
#define SPCI_SUCCESS 0
#define SPCI_NOT_SUPPORTED -1
#define SPCI_INVALID_PARAMETER -2
#define SPCI_NO_MEMORY -3
#define SPCI_BUSY -4
#define SPCI_QUEUED -5
#define SPCI_DENIED -6
#define SPCI_NOT_PRESENT -7
#endif /* SPCI_SVC_H */
......@@ -7,6 +7,8 @@
#ifndef SPM_SVC_H
#define SPM_SVC_H
#if SPM_DEPRECATED
#include <utils_def.h>
#define SPM_VERSION_MAJOR U(0)
......@@ -59,12 +61,16 @@
#define SPM_DENIED -3
#define SPM_NO_MEMORY -5
#endif /* SPM_DEPRECATED */
#ifndef __ASSEMBLY__
#include <stdint.h>
int32_t spm_setup(void);
#if SPM_DEPRECATED
uint64_t spm_smc_handler(uint32_t smc_fid,
uint64_t x1,
uint64_t x2,
......@@ -77,6 +83,8 @@ uint64_t spm_smc_handler(uint32_t smc_fid,
/* Helper to enter a Secure Partition */
uint64_t spm_sp_call(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3);
#endif /* SPM_DEPRECATED */
#endif /* __ASSEMBLY__ */
#endif /* SPM_SVC_H */
/*
* Copyright (c) 2018, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SPRT_SVC_H
#define SPRT_SVC_H
#include <smccc.h>
#include <utils_def.h>
/* SPRT_VERSION helpers */
#define SPRT_VERSION_MAJOR U(0)
#define SPRT_VERSION_MAJOR_SHIFT 16
#define SPRT_VERSION_MAJOR_MASK U(0x7FFF)
#define SPRT_VERSION_MINOR U(1)
#define SPRT_VERSION_MINOR_SHIFT 0
#define SPRT_VERSION_MINOR_MASK U(0xFFFF)
#define SPRT_VERSION_FORM(major, minor) ((((major) & SPRT_VERSION_MAJOR_MASK) \
<< SPRT_VERSION_MAJOR_SHIFT) | \
((minor) & SPRT_VERSION_MINOR_MASK))
#define SPRT_VERSION_COMPILED SPRT_VERSION_FORM(SPRT_VERSION_MAJOR, \
SPRT_VERSION_MINOR)
/* SPRT function IDs */
#define SPRT_FID_VERSION U(0x0)
#define SPRT_FID_PUT_RESPONSE U(0x1)
#define SPRT_FID_YIELD U(0x5)
#define SPRT_FID_PANIC U(0x7)
#define SPRT_FID_MEMORY_PERM_ATTR_GET U(0xB)
#define SPRT_FID_MEMORY_PERM_ATTR_SET U(0xC)
#define SPRT_FID_MASK U(0xFF)
/* Definitions to build the complete SMC ID */
#define SPRT_SMC_64(sprt_fid) ((FUNCID_NAMESPACE_SPRT << FUNCID_NAMESPACE_SHIFT) | \
(U(1) << 31) | ((sprt_fid) & SPRT_FID_MASK) | \
(SMC_64 << FUNCID_CC_SHIFT))
#define SPRT_SMC_32(sprt_fid) ((FUNCID_NAMESPACE_SPRT << FUNCID_NAMESPACE_SHIFT) | \
(U(1) << 31) | ((sprt_fid) & SPRT_FID_MASK) | \
(SMC_32 << FUNCID_CC_SHIFT))
/* Complete SMC IDs */
#define SPRT_VERSION SPRT_SMC_32(SPRT_FID_VERSION)
#define SPRT_PUT_RESPONSE_AARCH64 SPRT_SMC_64(SPRT_FID_PUT_RESPONSE)
#define SPRT_YIELD_AARCH64 SPRT_SMC_64(SPRT_FID_YIELD)
#define SPRT_PANIC_AARCH64 SPRT_SMC_64(SPRT_FID_PANIC)
#define SPRT_MEMORY_PERM_ATTR_GET_AARCH64 SPRT_SMC_64(SPRT_FID_MEMORY_PERM_ATTR_GET)
#define SPRT_MEMORY_PERM_ATTR_SET_AARCH64 SPRT_SMC_64(SPRT_FID_MEMORY_PERM_ATTR_SET)
/* Defines used by SPRT_MEMORY_PERM_ATTR_{GET,SET}_AARCH64 */
#define SPRT_MEMORY_PERM_ATTR_RO U(0)
#define SPRT_MEMORY_PERM_ATTR_RW U(1)
#define SPRT_MEMORY_PERM_ATTR_RO_EXEC U(2)
/* U(3) is reserved */
#define SPRT_MEMORY_PERM_ATTR_MASK U(3)
#define SPRT_MEMORY_PERM_ATTR_SHIFT 3
/* SPRT error codes. */
#define SPRT_SUCCESS 0
#define SPRT_NOT_SUPPORTED -1
#define SPRT_INVALID_PARAMETER -2
#endif /* SPRT_SVC_H */
/*
* Copyright (c) 2018, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SPTOOL_H
#define SPTOOL_H
#include <stdint.h>
/* Header for a secure partition package. There is one per package. */
struct sp_pkg_header {
uint64_t version;
uint64_t number_of_sp;
};
/*
* Entry descriptor in a secure partition package. Each entry comprises a
* secure partition and its resource description.
*/
struct sp_pkg_entry {
uint64_t sp_offset;
uint64_t sp_size;
uint64_t rd_offset;
uint64_t rd_size;
};
#endif /* SPTOOL_H */
/*
* Copyright (c) 2018, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include "sprt_common.h"
#include "sprt_queue.h"
void sprt_initialize_queues(void *buffer_base, size_t buffer_size)
{
/* Initialize queue for blocking messages */
void *blocking_base = buffer_base;
uint32_t blocking_num = 4U;
size_t blocking_size = SPRT_QUEUE_HEADER_SIZE +
SPRT_QUEUE_ENTRY_MSG_SIZE * blocking_num;
sprt_queue_init(blocking_base, blocking_num, SPRT_QUEUE_ENTRY_MSG_SIZE);
/* Initialize queue for non-blocking messages */
void *non_blocking_base = (void *)((uintptr_t)blocking_base + blocking_size);
size_t non_blocking_size = buffer_size - blocking_size;
uint32_t non_blocking_num = (non_blocking_size - SPRT_QUEUE_HEADER_SIZE) /
SPRT_QUEUE_ENTRY_MSG_SIZE;
sprt_queue_init(non_blocking_base, non_blocking_num, SPRT_QUEUE_ENTRY_MSG_SIZE);
}
int sprt_push_message(void *buffer_base,
const struct sprt_queue_entry_message *message,
int queue_num)
{
struct sprt_queue *q = buffer_base;
while (queue_num-- > 0) {
uintptr_t next_addr = (uintptr_t)q + sizeof(struct sprt_queue) +
q->entry_num * q->entry_size;
q = (struct sprt_queue *) next_addr;
}
return sprt_queue_push(q, message);
}
#
# Copyright (c) 2018, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
SPRT_LIB_SOURCES := $(addprefix lib/sprt/, \
sprt_host.c \
sprt_queue.c)
SPRT_LIB_INCLUDES := -Iinclude/lib/sprt/
/*
* Copyright (c) 2018, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <string.h>
#include "sprt_queue.h"
void sprt_queue_init(void *queue_base, uint32_t entry_num, uint32_t entry_size)
{
assert(queue_base != NULL);
assert(entry_size > 0U);
assert(entry_num > 0U);
struct sprt_queue *queue = (struct sprt_queue *)queue_base;
queue->entry_num = entry_num;
queue->entry_size = entry_size;
queue->idx_write = 0U;
queue->idx_read = 0U;
memset(queue->data, 0, entry_num * entry_size);
}
int sprt_queue_is_empty(void *queue_base)
{
assert(queue_base != NULL);
struct sprt_queue *queue = (struct sprt_queue *)queue_base;
return (queue->idx_write == queue->idx_read);
}
int sprt_queue_is_full(void *queue_base)
{
assert(queue_base != NULL);
struct sprt_queue *queue = (struct sprt_queue *)queue_base;
uint32_t idx_next_write = (queue->idx_write + 1) % queue->entry_num;
return (idx_next_write == queue->idx_read);
}
int sprt_queue_push(void *queue_base, const void *entry)
{
assert(entry != NULL);
assert(queue_base != NULL);
if (sprt_queue_is_full(queue_base) != 0) {
return -ENOMEM;
}
struct sprt_queue *queue = (struct sprt_queue *)queue_base;
uint8_t *dst_entry = &queue->data[queue->entry_size * queue->idx_write];
memcpy(dst_entry, entry, queue->entry_size);
/*
* Make sure that the message data is visible before increasing the
* counter of available messages.
*/
__asm__ volatile("dmb st" ::: "memory");
queue->idx_write = (queue->idx_write + 1) % queue->entry_num;
__asm__ volatile("dmb st" ::: "memory");
return 0;
}
int sprt_queue_pop(void *queue_base, void *entry)
{
assert(entry != NULL);
assert(queue_base != NULL);
if (sprt_queue_is_empty(queue_base) != 0) {
return -ENOENT;
}
struct sprt_queue *queue = (struct sprt_queue *)queue_base;
uint8_t *src_entry = &queue->data[queue->entry_size * queue->idx_read];
memcpy(entry, src_entry, queue->entry_size);
/*
* Make sure that the message data is visible before increasing the
* counter of read messages.
*/
__asm__ volatile("dmb st" ::: "memory");
queue->idx_read = (queue->idx_read + 1) % queue->entry_num;
__asm__ volatile("dmb st" ::: "memory");
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment