diff --git a/drivers/arm/css/scmi/scmi_ap_core_proto.c b/drivers/arm/css/scmi/scmi_ap_core_proto.c new file mode 100644 index 0000000..2caccc2 --- /dev/null +++ b/drivers/arm/css/scmi/scmi_ap_core_proto.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#include +#include +#include + +#include "scmi_private.h" + +/* + * API to set the SCMI AP core reset address and attributes + */ +int scmi_ap_core_set_reset_addr(void *p, uint64_t reset_addr, uint32_t attr) +{ + mailbox_mem_t *mbx_mem; + int token = 0, ret; + scmi_channel_t *ch = (scmi_channel_t *)p; + + validate_scmi_channel(ch); + + scmi_get_channel(ch); + + mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); + mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_AP_CORE_PROTO_ID, + SCMI_AP_CORE_RESET_ADDR_SET_MSG, token); + mbx_mem->len = SCMI_AP_CORE_RESET_ADDR_SET_MSG_LEN; + mbx_mem->flags = SCMI_FLAG_RESP_POLL; + SCMI_PAYLOAD_ARG3(mbx_mem->payload, reset_addr & 0xffffffff, + reset_addr >> 32, attr); + + scmi_send_sync_command(ch); + + /* Get the return values */ + SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret); + assert(mbx_mem->len == SCMI_AP_CORE_RESET_ADDR_SET_RESP_LEN); + assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); + + scmi_put_channel(ch); + + return ret; +} + +/* + * API to get the SCMI AP core reset address and attributes + */ +int scmi_ap_core_get_reset_addr(void *p, uint64_t *reset_addr, uint32_t *attr) +{ + mailbox_mem_t *mbx_mem; + int token = 0, ret; + scmi_channel_t *ch = (scmi_channel_t *)p; + uint32_t lo_addr, hi_addr; + + validate_scmi_channel(ch); + + scmi_get_channel(ch); + + mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); + mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_AP_CORE_PROTO_ID, + SCMI_AP_CORE_RESET_ADDR_GET_MSG, token); + mbx_mem->len = SCMI_AP_CORE_RESET_ADDR_GET_MSG_LEN; + mbx_mem->flags = SCMI_FLAG_RESP_POLL; + + scmi_send_sync_command(ch); + + /* Get the return values */ + SCMI_PAYLOAD_RET_VAL4(mbx_mem->payload, ret, lo_addr, hi_addr, *attr); + *reset_addr = lo_addr | (uint64_t)hi_addr << 32; + assert(mbx_mem->len == SCMI_AP_CORE_RESET_ADDR_GET_RESP_LEN); + assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); + + scmi_put_channel(ch); + + return ret; +} diff --git a/drivers/arm/css/scmi/scmi_common.c b/drivers/arm/css/scmi/scmi_common.c new file mode 100644 index 0000000..e2c353d --- /dev/null +++ b/drivers/arm/css/scmi/scmi_common.c @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#include +#include +#include + +#include "scmi_private.h" + +#if HW_ASSISTED_COHERENCY +#define scmi_lock_init(lock) +#define scmi_lock_get(lock) spin_lock(lock) +#define scmi_lock_release(lock) spin_unlock(lock) +#else +#define scmi_lock_init(lock) bakery_lock_init(lock) +#define scmi_lock_get(lock) bakery_lock_get(lock) +#define scmi_lock_release(lock) bakery_lock_release(lock) +#endif + + +/* + * Private helper function to get exclusive access to SCMI channel. + */ +void scmi_get_channel(scmi_channel_t *ch) +{ + assert(ch->lock); + scmi_lock_get(ch->lock); + + /* Make sure any previous command has finished */ + assert(SCMI_IS_CHANNEL_FREE( + ((mailbox_mem_t *)(ch->info->scmi_mbx_mem))->status)); +} + +/* + * Private helper function to transfer ownership of channel from AP to SCP. + */ +void scmi_send_sync_command(scmi_channel_t *ch) +{ + mailbox_mem_t *mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); + + SCMI_MARK_CHANNEL_BUSY(mbx_mem->status); + + /* + * Ensure that any write to the SCMI payload area is seen by SCP before + * we write to the doorbell register. If these 2 writes were reordered + * by the CPU then SCP would read stale payload data + */ + dmbst(); + + ch->info->ring_doorbell(ch->info); + /* + * Ensure that the write to the doorbell register is ordered prior to + * checking whether the channel is free. + */ + dmbsy(); + + /* Wait for channel to be free */ + while (!SCMI_IS_CHANNEL_FREE(mbx_mem->status)) + ; + + /* + * Ensure that any read to the SCMI payload area is done after reading + * mailbox status. If these 2 reads were reordered then the CPU would + * read invalid payload data + */ + dmbld(); +} + +/* + * Private helper function to release exclusive access to SCMI channel. + */ +void scmi_put_channel(scmi_channel_t *ch) +{ + /* Make sure any previous command has finished */ + assert(SCMI_IS_CHANNEL_FREE( + ((mailbox_mem_t *)(ch->info->scmi_mbx_mem))->status)); + + assert(ch->lock); + scmi_lock_release(ch->lock); +} + +/* + * API to query the SCMI protocol version. + */ +int scmi_proto_version(void *p, uint32_t proto_id, uint32_t *version) +{ + mailbox_mem_t *mbx_mem; + int token = 0, ret; + scmi_channel_t *ch = (scmi_channel_t *)p; + + validate_scmi_channel(ch); + + scmi_get_channel(ch); + + mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); + mbx_mem->msg_header = SCMI_MSG_CREATE(proto_id, SCMI_PROTO_VERSION_MSG, + token); + mbx_mem->len = SCMI_PROTO_VERSION_MSG_LEN; + mbx_mem->flags = SCMI_FLAG_RESP_POLL; + + scmi_send_sync_command(ch); + + /* Get the return values */ + SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *version); + assert(mbx_mem->len == SCMI_PROTO_VERSION_RESP_LEN); + assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); + + scmi_put_channel(ch); + + return ret; +} + +/* + * API to query the protocol message attributes for a SCMI protocol. + */ +int scmi_proto_msg_attr(void *p, uint32_t proto_id, + uint32_t command_id, uint32_t *attr) +{ + mailbox_mem_t *mbx_mem; + int token = 0, ret; + scmi_channel_t *ch = (scmi_channel_t *)p; + + validate_scmi_channel(ch); + + scmi_get_channel(ch); + + mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); + mbx_mem->msg_header = SCMI_MSG_CREATE(proto_id, + SCMI_PROTO_MSG_ATTR_MSG, token); + mbx_mem->len = SCMI_PROTO_MSG_ATTR_MSG_LEN; + mbx_mem->flags = SCMI_FLAG_RESP_POLL; + SCMI_PAYLOAD_ARG1(mbx_mem->payload, command_id); + + scmi_send_sync_command(ch); + + /* Get the return values */ + SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *attr); + assert(mbx_mem->len == SCMI_PROTO_MSG_ATTR_RESP_LEN); + assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); + + scmi_put_channel(ch); + + return ret; +} + +/* + * SCMI Driver initialization API. Returns initialized channel on success + * or NULL on error. The return type is an opaque void pointer. + */ +void *scmi_init(scmi_channel_t *ch) +{ + uint32_t version; + int ret; + + assert(ch && ch->info); + assert(ch->info->db_reg_addr); + assert(ch->info->db_modify_mask); + assert(ch->info->db_preserve_mask); + assert(ch->info->ring_doorbell != NULL); + + assert(ch->lock); + + scmi_lock_init(ch->lock); + + ch->is_initialized = 1; + + ret = scmi_proto_version(ch, SCMI_PWR_DMN_PROTO_ID, &version); + if (ret != SCMI_E_SUCCESS) { + WARN("SCMI power domain protocol version message failed"); + goto error; + } + + if (!is_scmi_version_compatible(SCMI_PWR_DMN_PROTO_VER, version)) { + WARN("SCMI power domain protocol version 0x%x incompatible with driver version 0x%x", + version, SCMI_PWR_DMN_PROTO_VER); + goto error; + } + + VERBOSE("SCMI power domain protocol version 0x%x detected\n", version); + + ret = scmi_proto_version(ch, SCMI_SYS_PWR_PROTO_ID, &version); + if ((ret != SCMI_E_SUCCESS)) { + WARN("SCMI system power protocol version message failed"); + goto error; + } + + if (!is_scmi_version_compatible(SCMI_SYS_PWR_PROTO_VER, version)) { + WARN("SCMI system power management protocol version 0x%x incompatible with driver version 0x%x", + version, SCMI_SYS_PWR_PROTO_VER); + goto error; + } + + VERBOSE("SCMI system power management protocol version 0x%x detected\n", + version); + + INFO("SCMI driver initialized\n"); + + return (void *)ch; + +error: + ch->is_initialized = 0; + return NULL; +} diff --git a/drivers/arm/css/scmi/scmi_private.h b/drivers/arm/css/scmi/scmi_private.h new file mode 100644 index 0000000..6530573 --- /dev/null +++ b/drivers/arm/css/scmi/scmi_private.h @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef SCMI_PRIVATE_H +#define SCMI_PRIVATE_H + +#include + +/* + * SCMI power domain management protocol message and response lengths. It is + * calculated as sum of length in bytes of the message header (4) and payload + * area (the number of bytes of parameters or return values in the payload). + */ +#define SCMI_PROTO_VERSION_MSG_LEN 4 +#define SCMI_PROTO_VERSION_RESP_LEN 12 + +#define SCMI_PROTO_MSG_ATTR_MSG_LEN 8 +#define SCMI_PROTO_MSG_ATTR_RESP_LEN 12 + +#define SCMI_AP_CORE_RESET_ADDR_SET_MSG_LEN 16 +#define SCMI_AP_CORE_RESET_ADDR_SET_RESP_LEN 8 + +#define SCMI_AP_CORE_RESET_ADDR_GET_MSG_LEN 4 +#define SCMI_AP_CORE_RESET_ADDR_GET_RESP_LEN 20 + +#define SCMI_PWR_STATE_SET_MSG_LEN 16 +#define SCMI_PWR_STATE_SET_RESP_LEN 8 + +#define SCMI_PWR_STATE_GET_MSG_LEN 8 +#define SCMI_PWR_STATE_GET_RESP_LEN 12 + +#define SCMI_SYS_PWR_STATE_SET_MSG_LEN 12 +#define SCMI_SYS_PWR_STATE_SET_RESP_LEN 8 + +#define SCMI_SYS_PWR_STATE_GET_MSG_LEN 4 +#define SCMI_SYS_PWR_STATE_GET_RESP_LEN 12 + +/* SCMI message header format bit field */ +#define SCMI_MSG_ID_SHIFT 0 +#define SCMI_MSG_ID_WIDTH 8 +#define SCMI_MSG_ID_MASK ((1 << SCMI_MSG_ID_WIDTH) - 1) + +#define SCMI_MSG_TYPE_SHIFT 8 +#define SCMI_MSG_TYPE_WIDTH 2 +#define SCMI_MSG_TYPE_MASK ((1 << SCMI_MSG_TYPE_WIDTH) - 1) + +#define SCMI_MSG_PROTO_ID_SHIFT 10 +#define SCMI_MSG_PROTO_ID_WIDTH 8 +#define SCMI_MSG_PROTO_ID_MASK ((1 << SCMI_MSG_PROTO_ID_WIDTH) - 1) + +#define SCMI_MSG_TOKEN_SHIFT 18 +#define SCMI_MSG_TOKEN_WIDTH 10 +#define SCMI_MSG_TOKEN_MASK ((1 << SCMI_MSG_TOKEN_WIDTH) - 1) + + +/* SCMI mailbox flags */ +#define SCMI_FLAG_RESP_POLL 0 +#define SCMI_FLAG_RESP_INT 1 + +/* SCMI power domain protocol `POWER_STATE_SET` message flags */ +#define SCMI_PWR_STATE_SET_FLAG_SYNC 0 +#define SCMI_PWR_STATE_SET_FLAG_ASYNC 1 + +/* + * Helper macro to create an SCMI message header given protocol, message id + * and token. + */ +#define SCMI_MSG_CREATE(_protocol, _msg_id, _token) \ + ((((_protocol) & SCMI_MSG_PROTO_ID_MASK) << SCMI_MSG_PROTO_ID_SHIFT) | \ + (((_msg_id) & SCMI_MSG_ID_MASK) << SCMI_MSG_ID_SHIFT) | \ + (((_token) & SCMI_MSG_TOKEN_MASK) << SCMI_MSG_TOKEN_SHIFT)) + +/* Helper macro to get the token from a SCMI message header */ +#define SCMI_MSG_GET_TOKEN(_msg) \ + (((_msg) >> SCMI_MSG_TOKEN_SHIFT) & SCMI_MSG_TOKEN_MASK) + +/* SCMI Channel Status bit fields */ +#define SCMI_CH_STATUS_RES0_MASK 0xFFFFFFFE +#define SCMI_CH_STATUS_FREE_SHIFT 0 +#define SCMI_CH_STATUS_FREE_WIDTH 1 +#define SCMI_CH_STATUS_FREE_MASK ((1 << SCMI_CH_STATUS_FREE_WIDTH) - 1) + +/* Helper macros to check and write the channel status */ +#define SCMI_IS_CHANNEL_FREE(status) \ + (!!(((status) >> SCMI_CH_STATUS_FREE_SHIFT) & SCMI_CH_STATUS_FREE_MASK)) + +#define SCMI_MARK_CHANNEL_BUSY(status) do { \ + assert(SCMI_IS_CHANNEL_FREE(status)); \ + (status) &= ~(SCMI_CH_STATUS_FREE_MASK << \ + SCMI_CH_STATUS_FREE_SHIFT); \ + } while (0) + +/* Helper macros to copy arguments to the mailbox payload */ +#define SCMI_PAYLOAD_ARG1(payld_arr, arg1) \ + mmio_write_32((uintptr_t)&payld_arr[0], arg1) + +#define SCMI_PAYLOAD_ARG2(payld_arr, arg1, arg2) do { \ + SCMI_PAYLOAD_ARG1(payld_arr, arg1); \ + mmio_write_32((uintptr_t)&payld_arr[1], arg2); \ + } while (0) + +#define SCMI_PAYLOAD_ARG3(payld_arr, arg1, arg2, arg3) do { \ + SCMI_PAYLOAD_ARG2(payld_arr, arg1, arg2); \ + mmio_write_32((uintptr_t)&payld_arr[2], arg3); \ + } while (0) + +/* Helper macros to read return values from the mailbox payload */ +#define SCMI_PAYLOAD_RET_VAL1(payld_arr, val1) \ + (val1) = mmio_read_32((uintptr_t)&payld_arr[0]) + +#define SCMI_PAYLOAD_RET_VAL2(payld_arr, val1, val2) do { \ + SCMI_PAYLOAD_RET_VAL1(payld_arr, val1); \ + (val2) = mmio_read_32((uintptr_t)&payld_arr[1]); \ + } while (0) + +#define SCMI_PAYLOAD_RET_VAL3(payld_arr, val1, val2, val3) do { \ + SCMI_PAYLOAD_RET_VAL2(payld_arr, val1, val2); \ + (val3) = mmio_read_32((uintptr_t)&payld_arr[2]); \ + } while (0) + +#define SCMI_PAYLOAD_RET_VAL4(payld_arr, val1, val2, val3, val4) do { \ + SCMI_PAYLOAD_RET_VAL3(payld_arr, val1, val2, val3); \ + (val4) = mmio_read_32((uintptr_t)&payld_arr[3]); \ + } while (0) + +/* + * Private data structure for representing the mailbox memory layout. Refer + * the SCMI specification for more details. + */ +typedef struct mailbox_mem { + uint32_t res_a; /* Reserved */ + volatile uint32_t status; + uint64_t res_b; /* Reserved */ + uint32_t flags; + volatile uint32_t len; + uint32_t msg_header; + uint32_t payload[]; +} mailbox_mem_t; + + +/* Private APIs for use within SCMI driver */ +void scmi_get_channel(scmi_channel_t *ch); +void scmi_send_sync_command(scmi_channel_t *ch); +void scmi_put_channel(scmi_channel_t *ch); + +static inline void validate_scmi_channel(scmi_channel_t *ch) +{ + assert(ch && ch->is_initialized); + assert(ch->info && ch->info->scmi_mbx_mem); +} + +#endif /* SCMI_PRIVATE_H */ diff --git a/drivers/arm/css/scmi/scmi_pwr_dmn_proto.c b/drivers/arm/css/scmi/scmi_pwr_dmn_proto.c new file mode 100644 index 0000000..70165de --- /dev/null +++ b/drivers/arm/css/scmi/scmi_pwr_dmn_proto.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#include +#include +#include + +#include "scmi_private.h" + +/* + * API to set the SCMI power domain power state. + */ +int scmi_pwr_state_set(void *p, uint32_t domain_id, + uint32_t scmi_pwr_state) +{ + mailbox_mem_t *mbx_mem; + int token = 0, ret; + + /* + * Only asynchronous mode of `set power state` command is allowed on + * application processors. + */ + uint32_t pwr_state_set_msg_flag = SCMI_PWR_STATE_SET_FLAG_ASYNC; + scmi_channel_t *ch = (scmi_channel_t *)p; + + validate_scmi_channel(ch); + + scmi_get_channel(ch); + + mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); + mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID, + SCMI_PWR_STATE_SET_MSG, token); + mbx_mem->len = SCMI_PWR_STATE_SET_MSG_LEN; + mbx_mem->flags = SCMI_FLAG_RESP_POLL; + SCMI_PAYLOAD_ARG3(mbx_mem->payload, pwr_state_set_msg_flag, + domain_id, scmi_pwr_state); + + scmi_send_sync_command(ch); + + /* Get the return values */ + SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret); + assert(mbx_mem->len == SCMI_PWR_STATE_SET_RESP_LEN); + assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); + + scmi_put_channel(ch); + + return ret; +} + +/* + * API to get the SCMI power domain power state. + */ +int scmi_pwr_state_get(void *p, uint32_t domain_id, + uint32_t *scmi_pwr_state) +{ + mailbox_mem_t *mbx_mem; + int token = 0, ret; + scmi_channel_t *ch = (scmi_channel_t *)p; + + validate_scmi_channel(ch); + + scmi_get_channel(ch); + + mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); + mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID, + SCMI_PWR_STATE_GET_MSG, token); + mbx_mem->len = SCMI_PWR_STATE_GET_MSG_LEN; + mbx_mem->flags = SCMI_FLAG_RESP_POLL; + SCMI_PAYLOAD_ARG1(mbx_mem->payload, domain_id); + + scmi_send_sync_command(ch); + + /* Get the return values */ + SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *scmi_pwr_state); + assert(mbx_mem->len == SCMI_PWR_STATE_GET_RESP_LEN); + assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); + + scmi_put_channel(ch); + + return ret; +} diff --git a/drivers/arm/css/scmi/scmi_sys_pwr_proto.c b/drivers/arm/css/scmi/scmi_sys_pwr_proto.c new file mode 100644 index 0000000..a27c4a5 --- /dev/null +++ b/drivers/arm/css/scmi/scmi_sys_pwr_proto.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#include +#include +#include + +#include "scmi_private.h" + +/* + * API to set the SCMI system power state + */ +int scmi_sys_pwr_state_set(void *p, uint32_t flags, uint32_t system_state) +{ + mailbox_mem_t *mbx_mem; + int token = 0, ret; + scmi_channel_t *ch = (scmi_channel_t *)p; + + validate_scmi_channel(ch); + + scmi_get_channel(ch); + + mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); + mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_SYS_PWR_PROTO_ID, + SCMI_SYS_PWR_STATE_SET_MSG, token); + mbx_mem->len = SCMI_SYS_PWR_STATE_SET_MSG_LEN; + mbx_mem->flags = SCMI_FLAG_RESP_POLL; + SCMI_PAYLOAD_ARG2(mbx_mem->payload, flags, system_state); + + scmi_send_sync_command(ch); + + /* Get the return values */ + SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret); + assert(mbx_mem->len == SCMI_SYS_PWR_STATE_SET_RESP_LEN); + assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); + + scmi_put_channel(ch); + + return ret; +} + +/* + * API to get the SCMI system power state + */ +int scmi_sys_pwr_state_get(void *p, uint32_t *system_state) +{ + mailbox_mem_t *mbx_mem; + int token = 0, ret; + scmi_channel_t *ch = (scmi_channel_t *)p; + + validate_scmi_channel(ch); + + scmi_get_channel(ch); + + mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); + mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_SYS_PWR_PROTO_ID, + SCMI_SYS_PWR_STATE_GET_MSG, token); + mbx_mem->len = SCMI_SYS_PWR_STATE_GET_MSG_LEN; + mbx_mem->flags = SCMI_FLAG_RESP_POLL; + + scmi_send_sync_command(ch); + + /* Get the return values */ + SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *system_state); + assert(mbx_mem->len == SCMI_SYS_PWR_STATE_GET_RESP_LEN); + assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); + + scmi_put_channel(ch); + + return ret; +} diff --git a/include/drivers/arm/css/scmi.h b/include/drivers/arm/css/scmi.h new file mode 100644 index 0000000..df259f7 --- /dev/null +++ b/include/drivers/arm/css/scmi.h @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef SCMI_H +#define SCMI_H + +#include +#include + +#include +#include +#include + +/* Supported SCMI Protocol Versions */ +#define SCMI_AP_CORE_PROTO_VER MAKE_SCMI_VERSION(1, 0) +#define SCMI_PWR_DMN_PROTO_VER MAKE_SCMI_VERSION(1, 0) +#define SCMI_SYS_PWR_PROTO_VER MAKE_SCMI_VERSION(1, 0) + +#define GET_SCMI_MAJOR_VER(ver) (((ver) >> 16) & 0xffff) +#define GET_SCMI_MINOR_VER(ver) ((ver) & 0xffff) + +#define MAKE_SCMI_VERSION(maj, min) \ + ((((maj) & 0xffff) << 16) | ((min) & 0xffff)) + +/* Macro to check if the driver is compatible with the SCMI version reported */ +#define is_scmi_version_compatible(drv, scmi) \ + ((GET_SCMI_MAJOR_VER(drv) == GET_SCMI_MAJOR_VER(scmi)) && \ + (GET_SCMI_MINOR_VER(drv) <= GET_SCMI_MINOR_VER(scmi))) + +/* SCMI Protocol identifiers */ +#define SCMI_PWR_DMN_PROTO_ID 0x11 +#define SCMI_SYS_PWR_PROTO_ID 0x12 +/* The AP core protocol is a CSS platform-specific extension */ +#define SCMI_AP_CORE_PROTO_ID 0x90 + +/* Mandatory messages IDs for all SCMI protocols */ +#define SCMI_PROTO_VERSION_MSG 0x0 +#define SCMI_PROTO_ATTR_MSG 0x1 +#define SCMI_PROTO_MSG_ATTR_MSG 0x2 + +/* SCMI power domain management protocol message IDs */ +#define SCMI_PWR_STATE_SET_MSG 0x4 +#define SCMI_PWR_STATE_GET_MSG 0x5 + +/* SCMI system power management protocol message IDs */ +#define SCMI_SYS_PWR_STATE_SET_MSG 0x3 +#define SCMI_SYS_PWR_STATE_GET_MSG 0x4 + +/* SCMI AP core protocol message IDs */ +#define SCMI_AP_CORE_RESET_ADDR_SET_MSG 0x3 +#define SCMI_AP_CORE_RESET_ADDR_GET_MSG 0x4 + +/* Helper macros for system power management protocol commands */ + +/* + * Macros to describe the bit-fields of the `attribute` of system power domain + * protocol PROTOCOL_MSG_ATTRIBUTE message. + */ +#define SYS_PWR_ATTR_WARM_RESET_SHIFT 31 +#define SCMI_SYS_PWR_WARM_RESET_SUPPORTED (1U << SYS_PWR_ATTR_WARM_RESET_SHIFT) + +#define SYS_PWR_ATTR_SUSPEND_SHIFT 30 +#define SCMI_SYS_PWR_SUSPEND_SUPPORTED (1 << SYS_PWR_ATTR_SUSPEND_SHIFT) + +/* + * Macros to describe the bit-fields of the `flags` parameter of system power + * domain protocol SYSTEM_POWER_STATE_SET message. + */ +#define SYS_PWR_SET_GRACEFUL_REQ_SHIFT 0 +#define SCMI_SYS_PWR_GRACEFUL_REQ (1 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT) +#define SCMI_SYS_PWR_FORCEFUL_REQ (0 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT) + +/* + * Macros to describe the `system_state` parameter of system power + * domain protocol SYSTEM_POWER_STATE_SET message. + */ +#define SCMI_SYS_PWR_SHUTDOWN 0x0 +#define SCMI_SYS_PWR_COLD_RESET 0x1 +#define SCMI_SYS_PWR_WARM_RESET 0x2 +#define SCMI_SYS_PWR_POWER_UP 0x3 +#define SCMI_SYS_PWR_SUSPEND 0x4 + +/* + * Macros to describe the bit-fields of the `attribute` of AP core protocol + * AP_CORE_RESET_ADDR set/get messages. + */ +#define SCMI_AP_CORE_LOCK_ATTR_SHIFT 0x0 +#define SCMI_AP_CORE_LOCK_ATTR (1U << SCMI_AP_CORE_LOCK_ATTR_SHIFT) + +/* SCMI Error code definitions */ +#define SCMI_E_QUEUED 1 +#define SCMI_E_SUCCESS 0 +#define SCMI_E_NOT_SUPPORTED -1 +#define SCMI_E_INVALID_PARAM -2 +#define SCMI_E_DENIED -3 +#define SCMI_E_NOT_FOUND -4 +#define SCMI_E_OUT_OF_RANGE -5 +#define SCMI_E_BUSY -6 + +/* + * SCMI driver platform information. The details of the doorbell mechanism + * can be found in the SCMI specification. + */ +typedef struct scmi_channel_plat_info { + /* SCMI mailbox memory */ + uintptr_t scmi_mbx_mem; + /* The door bell register address */ + uintptr_t db_reg_addr; + /* The bit mask that need to be preserved when ringing doorbell */ + uint32_t db_preserve_mask; + /* The bit mask that need to be set to ring doorbell */ + uint32_t db_modify_mask; + /* The handler for ringing doorbell */ + void (*ring_doorbell)(struct scmi_channel_plat_info *plat_info); + /* cookie is unused now. But added for future enhancements. */ + void *cookie; +} scmi_channel_plat_info_t; + + +#if HW_ASSISTED_COHERENCY +typedef spinlock_t scmi_lock_t; +#else +typedef bakery_lock_t scmi_lock_t; +#endif + +/* + * Structure to represent an SCMI channel. + */ +typedef struct scmi_channel { + scmi_channel_plat_info_t *info; + /* The lock for channel access */ + scmi_lock_t *lock; + /* Indicate whether the channel is initialized */ + int is_initialized; +} scmi_channel_t; + +/* External Common API */ +void *scmi_init(scmi_channel_t *ch); +int scmi_proto_msg_attr(void *p, uint32_t proto_id, uint32_t command_id, + uint32_t *attr); +int scmi_proto_version(void *p, uint32_t proto_id, uint32_t *version); + +/* + * Power domain protocol commands. Refer to the SCMI specification for more + * details on these commands. + */ +int scmi_pwr_state_set(void *p, uint32_t domain_id, uint32_t scmi_pwr_state); +int scmi_pwr_state_get(void *p, uint32_t domain_id, uint32_t *scmi_pwr_state); + +/* + * System power management protocol commands. Refer SCMI specification for more + * details on these commands. + */ +int scmi_sys_pwr_state_set(void *p, uint32_t flags, uint32_t system_state); +int scmi_sys_pwr_state_get(void *p, uint32_t *system_state); + +/* SCMI AP core configuration protocol commands. */ +int scmi_ap_core_set_reset_addr(void *p, uint64_t reset_addr, uint32_t attr); +int scmi_ap_core_get_reset_addr(void *p, uint64_t *reset_addr, uint32_t *attr); + +/* API to get the platform specific SCMI channel information. */ +scmi_channel_plat_info_t *plat_css_get_scmi_info(); + +/* API to override default PSCI callbacks for platforms that support SCMI. */ +const plat_psci_ops_t *css_scmi_override_pm_ops(plat_psci_ops_t *ops); + +#endif /* SCMI_H */ diff --git a/plat/arm/board/juno/juno_pm.c b/plat/arm/board/juno/juno_pm.c index 4864f48..cc80651 100644 --- a/plat/arm/board/juno/juno_pm.c +++ b/plat/arm/board/juno/juno_pm.c @@ -4,10 +4,9 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#include #include -#include - const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops) { #if CSS_USE_SCMI_SDS_DRIVER diff --git a/plat/arm/board/juno/juno_topology.c b/plat/arm/board/juno/juno_topology.c index 1402bbd..d83bd9a 100644 --- a/plat/arm/board/juno/juno_topology.c +++ b/plat/arm/board/juno/juno_topology.c @@ -4,12 +4,12 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#include #include #include #include #include -#include "../../css/drivers/scmi/scmi.h" #include "../../css/drivers/mhu/css_mhu_doorbell.h" #if CSS_USE_SCMI_SDS_DRIVER diff --git a/plat/arm/board/juno/platform.mk b/plat/arm/board/juno/platform.mk index 96c7e6c..a0281af 100644 --- a/plat/arm/board/juno/platform.mk +++ b/plat/arm/board/juno/platform.mk @@ -27,7 +27,6 @@ CSS_USE_SCMI_SDS_DRIVER := 1 PLAT_INCLUDES := -Iplat/arm/board/juno/include \ - -Iplat/arm/css/drivers/scmi \ -Iplat/arm/css/drivers/sds PLAT_BL_COMMON_SOURCES := plat/arm/board/juno/${ARCH}/juno_helpers.S \ diff --git a/plat/arm/board/n1sdp/n1sdp_bl31_setup.c b/plat/arm/board/n1sdp/n1sdp_bl31_setup.c index 93f2803..a1669b9 100644 --- a/plat/arm/board/n1sdp/n1sdp_bl31_setup.c +++ b/plat/arm/board/n1sdp/n1sdp_bl31_setup.c @@ -6,9 +6,9 @@ #include +#include #include -#include "../../css/drivers/scmi/scmi.h" #include "../../css/drivers/mhu/css_mhu_doorbell.h" static scmi_channel_plat_info_t n1sdp_scmi_plat_info = { diff --git a/plat/arm/css/common/css_common.mk b/plat/arm/css/common/css_common.mk index 0795306..b8e974f 100644 --- a/plat/arm/css/common/css_common.mk +++ b/plat/arm/css/common/css_common.mk @@ -30,11 +30,11 @@ plat/arm/css/drivers/mhu/css_mhu.c \ plat/arm/css/drivers/scpi/css_scpi.c else -BL31_SOURCES += plat/arm/css/drivers/scp/css_pm_scmi.c \ - plat/arm/css/drivers/scmi/scmi_ap_core_proto.c \ - plat/arm/css/drivers/scmi/scmi_common.c \ - plat/arm/css/drivers/scmi/scmi_pwr_dmn_proto.c \ - plat/arm/css/drivers/scmi/scmi_sys_pwr_proto.c \ +BL31_SOURCES += drivers/arm/css/scmi/scmi_ap_core_proto.c \ + drivers/arm/css/scmi/scmi_common.c \ + drivers/arm/css/scmi/scmi_pwr_dmn_proto.c \ + drivers/arm/css/scmi/scmi_sys_pwr_proto.c \ + plat/arm/css/drivers/scp/css_pm_scmi.c \ plat/arm/css/drivers/mhu/css_mhu_doorbell.c endif diff --git a/plat/arm/css/common/sp_min/css_sp_min.mk b/plat/arm/css/common/sp_min/css_sp_min.mk index 9fb280c..7c2dcf5 100644 --- a/plat/arm/css/common/sp_min/css_sp_min.mk +++ b/plat/arm/css/common/sp_min/css_sp_min.mk @@ -13,9 +13,9 @@ plat/arm/css/drivers/mhu/css_mhu.c \ plat/arm/css/drivers/scpi/css_scpi.c else -BL32_SOURCES += plat/arm/css/drivers/scp/css_pm_scmi.c \ - plat/arm/css/drivers/scmi/scmi_common.c \ - plat/arm/css/drivers/scmi/scmi_pwr_dmn_proto.c \ - plat/arm/css/drivers/scmi/scmi_sys_pwr_proto.c \ +BL32_SOURCES += drivers/arm/css/scmi/scmi_common.c \ + drivers/arm/css/scmi/scmi_pwr_dmn_proto.c \ + drivers/arm/css/scmi/scmi_sys_pwr_proto.c \ + plat/arm/css/drivers/scp/css_pm_scmi.c \ plat/arm/css/drivers/mhu/css_mhu_doorbell.c endif diff --git a/plat/arm/css/drivers/mhu/css_mhu_doorbell.c b/plat/arm/css/drivers/mhu/css_mhu_doorbell.c index 964428b..c031efa 100644 --- a/plat/arm/css/drivers/mhu/css_mhu_doorbell.c +++ b/plat/arm/css/drivers/mhu/css_mhu_doorbell.c @@ -7,9 +7,9 @@ #include #include +#include #include "css_mhu_doorbell.h" -#include "../scmi/scmi.h" void mhu_ring_doorbell(struct scmi_channel_plat_info *plat_info) { diff --git a/plat/arm/css/drivers/scmi/scmi.h b/plat/arm/css/drivers/scmi/scmi.h deleted file mode 100644 index df259f7..0000000 --- a/plat/arm/css/drivers/scmi/scmi.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef SCMI_H -#define SCMI_H - -#include -#include - -#include -#include -#include - -/* Supported SCMI Protocol Versions */ -#define SCMI_AP_CORE_PROTO_VER MAKE_SCMI_VERSION(1, 0) -#define SCMI_PWR_DMN_PROTO_VER MAKE_SCMI_VERSION(1, 0) -#define SCMI_SYS_PWR_PROTO_VER MAKE_SCMI_VERSION(1, 0) - -#define GET_SCMI_MAJOR_VER(ver) (((ver) >> 16) & 0xffff) -#define GET_SCMI_MINOR_VER(ver) ((ver) & 0xffff) - -#define MAKE_SCMI_VERSION(maj, min) \ - ((((maj) & 0xffff) << 16) | ((min) & 0xffff)) - -/* Macro to check if the driver is compatible with the SCMI version reported */ -#define is_scmi_version_compatible(drv, scmi) \ - ((GET_SCMI_MAJOR_VER(drv) == GET_SCMI_MAJOR_VER(scmi)) && \ - (GET_SCMI_MINOR_VER(drv) <= GET_SCMI_MINOR_VER(scmi))) - -/* SCMI Protocol identifiers */ -#define SCMI_PWR_DMN_PROTO_ID 0x11 -#define SCMI_SYS_PWR_PROTO_ID 0x12 -/* The AP core protocol is a CSS platform-specific extension */ -#define SCMI_AP_CORE_PROTO_ID 0x90 - -/* Mandatory messages IDs for all SCMI protocols */ -#define SCMI_PROTO_VERSION_MSG 0x0 -#define SCMI_PROTO_ATTR_MSG 0x1 -#define SCMI_PROTO_MSG_ATTR_MSG 0x2 - -/* SCMI power domain management protocol message IDs */ -#define SCMI_PWR_STATE_SET_MSG 0x4 -#define SCMI_PWR_STATE_GET_MSG 0x5 - -/* SCMI system power management protocol message IDs */ -#define SCMI_SYS_PWR_STATE_SET_MSG 0x3 -#define SCMI_SYS_PWR_STATE_GET_MSG 0x4 - -/* SCMI AP core protocol message IDs */ -#define SCMI_AP_CORE_RESET_ADDR_SET_MSG 0x3 -#define SCMI_AP_CORE_RESET_ADDR_GET_MSG 0x4 - -/* Helper macros for system power management protocol commands */ - -/* - * Macros to describe the bit-fields of the `attribute` of system power domain - * protocol PROTOCOL_MSG_ATTRIBUTE message. - */ -#define SYS_PWR_ATTR_WARM_RESET_SHIFT 31 -#define SCMI_SYS_PWR_WARM_RESET_SUPPORTED (1U << SYS_PWR_ATTR_WARM_RESET_SHIFT) - -#define SYS_PWR_ATTR_SUSPEND_SHIFT 30 -#define SCMI_SYS_PWR_SUSPEND_SUPPORTED (1 << SYS_PWR_ATTR_SUSPEND_SHIFT) - -/* - * Macros to describe the bit-fields of the `flags` parameter of system power - * domain protocol SYSTEM_POWER_STATE_SET message. - */ -#define SYS_PWR_SET_GRACEFUL_REQ_SHIFT 0 -#define SCMI_SYS_PWR_GRACEFUL_REQ (1 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT) -#define SCMI_SYS_PWR_FORCEFUL_REQ (0 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT) - -/* - * Macros to describe the `system_state` parameter of system power - * domain protocol SYSTEM_POWER_STATE_SET message. - */ -#define SCMI_SYS_PWR_SHUTDOWN 0x0 -#define SCMI_SYS_PWR_COLD_RESET 0x1 -#define SCMI_SYS_PWR_WARM_RESET 0x2 -#define SCMI_SYS_PWR_POWER_UP 0x3 -#define SCMI_SYS_PWR_SUSPEND 0x4 - -/* - * Macros to describe the bit-fields of the `attribute` of AP core protocol - * AP_CORE_RESET_ADDR set/get messages. - */ -#define SCMI_AP_CORE_LOCK_ATTR_SHIFT 0x0 -#define SCMI_AP_CORE_LOCK_ATTR (1U << SCMI_AP_CORE_LOCK_ATTR_SHIFT) - -/* SCMI Error code definitions */ -#define SCMI_E_QUEUED 1 -#define SCMI_E_SUCCESS 0 -#define SCMI_E_NOT_SUPPORTED -1 -#define SCMI_E_INVALID_PARAM -2 -#define SCMI_E_DENIED -3 -#define SCMI_E_NOT_FOUND -4 -#define SCMI_E_OUT_OF_RANGE -5 -#define SCMI_E_BUSY -6 - -/* - * SCMI driver platform information. The details of the doorbell mechanism - * can be found in the SCMI specification. - */ -typedef struct scmi_channel_plat_info { - /* SCMI mailbox memory */ - uintptr_t scmi_mbx_mem; - /* The door bell register address */ - uintptr_t db_reg_addr; - /* The bit mask that need to be preserved when ringing doorbell */ - uint32_t db_preserve_mask; - /* The bit mask that need to be set to ring doorbell */ - uint32_t db_modify_mask; - /* The handler for ringing doorbell */ - void (*ring_doorbell)(struct scmi_channel_plat_info *plat_info); - /* cookie is unused now. But added for future enhancements. */ - void *cookie; -} scmi_channel_plat_info_t; - - -#if HW_ASSISTED_COHERENCY -typedef spinlock_t scmi_lock_t; -#else -typedef bakery_lock_t scmi_lock_t; -#endif - -/* - * Structure to represent an SCMI channel. - */ -typedef struct scmi_channel { - scmi_channel_plat_info_t *info; - /* The lock for channel access */ - scmi_lock_t *lock; - /* Indicate whether the channel is initialized */ - int is_initialized; -} scmi_channel_t; - -/* External Common API */ -void *scmi_init(scmi_channel_t *ch); -int scmi_proto_msg_attr(void *p, uint32_t proto_id, uint32_t command_id, - uint32_t *attr); -int scmi_proto_version(void *p, uint32_t proto_id, uint32_t *version); - -/* - * Power domain protocol commands. Refer to the SCMI specification for more - * details on these commands. - */ -int scmi_pwr_state_set(void *p, uint32_t domain_id, uint32_t scmi_pwr_state); -int scmi_pwr_state_get(void *p, uint32_t domain_id, uint32_t *scmi_pwr_state); - -/* - * System power management protocol commands. Refer SCMI specification for more - * details on these commands. - */ -int scmi_sys_pwr_state_set(void *p, uint32_t flags, uint32_t system_state); -int scmi_sys_pwr_state_get(void *p, uint32_t *system_state); - -/* SCMI AP core configuration protocol commands. */ -int scmi_ap_core_set_reset_addr(void *p, uint64_t reset_addr, uint32_t attr); -int scmi_ap_core_get_reset_addr(void *p, uint64_t *reset_addr, uint32_t *attr); - -/* API to get the platform specific SCMI channel information. */ -scmi_channel_plat_info_t *plat_css_get_scmi_info(); - -/* API to override default PSCI callbacks for platforms that support SCMI. */ -const plat_psci_ops_t *css_scmi_override_pm_ops(plat_psci_ops_t *ops); - -#endif /* SCMI_H */ diff --git a/plat/arm/css/drivers/scmi/scmi_ap_core_proto.c b/plat/arm/css/drivers/scmi/scmi_ap_core_proto.c deleted file mode 100644 index e495dcc..0000000 --- a/plat/arm/css/drivers/scmi/scmi_ap_core_proto.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include - -#include -#include - -#include "scmi.h" -#include "scmi_private.h" - -/* - * API to set the SCMI AP core reset address and attributes - */ -int scmi_ap_core_set_reset_addr(void *p, uint64_t reset_addr, uint32_t attr) -{ - mailbox_mem_t *mbx_mem; - int token = 0, ret; - scmi_channel_t *ch = (scmi_channel_t *)p; - - validate_scmi_channel(ch); - - scmi_get_channel(ch); - - mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); - mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_AP_CORE_PROTO_ID, - SCMI_AP_CORE_RESET_ADDR_SET_MSG, token); - mbx_mem->len = SCMI_AP_CORE_RESET_ADDR_SET_MSG_LEN; - mbx_mem->flags = SCMI_FLAG_RESP_POLL; - SCMI_PAYLOAD_ARG3(mbx_mem->payload, reset_addr & 0xffffffff, - reset_addr >> 32, attr); - - scmi_send_sync_command(ch); - - /* Get the return values */ - SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret); - assert(mbx_mem->len == SCMI_AP_CORE_RESET_ADDR_SET_RESP_LEN); - assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); - - scmi_put_channel(ch); - - return ret; -} - -/* - * API to get the SCMI AP core reset address and attributes - */ -int scmi_ap_core_get_reset_addr(void *p, uint64_t *reset_addr, uint32_t *attr) -{ - mailbox_mem_t *mbx_mem; - int token = 0, ret; - scmi_channel_t *ch = (scmi_channel_t *)p; - uint32_t lo_addr, hi_addr; - - validate_scmi_channel(ch); - - scmi_get_channel(ch); - - mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); - mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_AP_CORE_PROTO_ID, - SCMI_AP_CORE_RESET_ADDR_GET_MSG, token); - mbx_mem->len = SCMI_AP_CORE_RESET_ADDR_GET_MSG_LEN; - mbx_mem->flags = SCMI_FLAG_RESP_POLL; - - scmi_send_sync_command(ch); - - /* Get the return values */ - SCMI_PAYLOAD_RET_VAL4(mbx_mem->payload, ret, lo_addr, hi_addr, *attr); - *reset_addr = lo_addr | (uint64_t)hi_addr << 32; - assert(mbx_mem->len == SCMI_AP_CORE_RESET_ADDR_GET_RESP_LEN); - assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); - - scmi_put_channel(ch); - - return ret; -} diff --git a/plat/arm/css/drivers/scmi/scmi_common.c b/plat/arm/css/drivers/scmi/scmi_common.c deleted file mode 100644 index 1b4ecb2..0000000 --- a/plat/arm/css/drivers/scmi/scmi_common.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include - -#include -#include - -#include "scmi.h" -#include "scmi_private.h" - -#if HW_ASSISTED_COHERENCY -#define scmi_lock_init(lock) -#define scmi_lock_get(lock) spin_lock(lock) -#define scmi_lock_release(lock) spin_unlock(lock) -#else -#define scmi_lock_init(lock) bakery_lock_init(lock) -#define scmi_lock_get(lock) bakery_lock_get(lock) -#define scmi_lock_release(lock) bakery_lock_release(lock) -#endif - - -/* - * Private helper function to get exclusive access to SCMI channel. - */ -void scmi_get_channel(scmi_channel_t *ch) -{ - assert(ch->lock); - scmi_lock_get(ch->lock); - - /* Make sure any previous command has finished */ - assert(SCMI_IS_CHANNEL_FREE( - ((mailbox_mem_t *)(ch->info->scmi_mbx_mem))->status)); -} - -/* - * Private helper function to transfer ownership of channel from AP to SCP. - */ -void scmi_send_sync_command(scmi_channel_t *ch) -{ - mailbox_mem_t *mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); - - SCMI_MARK_CHANNEL_BUSY(mbx_mem->status); - - /* - * Ensure that any write to the SCMI payload area is seen by SCP before - * we write to the doorbell register. If these 2 writes were reordered - * by the CPU then SCP would read stale payload data - */ - dmbst(); - - ch->info->ring_doorbell(ch->info); - /* - * Ensure that the write to the doorbell register is ordered prior to - * checking whether the channel is free. - */ - dmbsy(); - - /* Wait for channel to be free */ - while (!SCMI_IS_CHANNEL_FREE(mbx_mem->status)) - ; - - /* - * Ensure that any read to the SCMI payload area is done after reading - * mailbox status. If these 2 reads were reordered then the CPU would - * read invalid payload data - */ - dmbld(); -} - -/* - * Private helper function to release exclusive access to SCMI channel. - */ -void scmi_put_channel(scmi_channel_t *ch) -{ - /* Make sure any previous command has finished */ - assert(SCMI_IS_CHANNEL_FREE( - ((mailbox_mem_t *)(ch->info->scmi_mbx_mem))->status)); - - assert(ch->lock); - scmi_lock_release(ch->lock); -} - -/* - * API to query the SCMI protocol version. - */ -int scmi_proto_version(void *p, uint32_t proto_id, uint32_t *version) -{ - mailbox_mem_t *mbx_mem; - int token = 0, ret; - scmi_channel_t *ch = (scmi_channel_t *)p; - - validate_scmi_channel(ch); - - scmi_get_channel(ch); - - mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); - mbx_mem->msg_header = SCMI_MSG_CREATE(proto_id, SCMI_PROTO_VERSION_MSG, - token); - mbx_mem->len = SCMI_PROTO_VERSION_MSG_LEN; - mbx_mem->flags = SCMI_FLAG_RESP_POLL; - - scmi_send_sync_command(ch); - - /* Get the return values */ - SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *version); - assert(mbx_mem->len == SCMI_PROTO_VERSION_RESP_LEN); - assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); - - scmi_put_channel(ch); - - return ret; -} - -/* - * API to query the protocol message attributes for a SCMI protocol. - */ -int scmi_proto_msg_attr(void *p, uint32_t proto_id, - uint32_t command_id, uint32_t *attr) -{ - mailbox_mem_t *mbx_mem; - int token = 0, ret; - scmi_channel_t *ch = (scmi_channel_t *)p; - - validate_scmi_channel(ch); - - scmi_get_channel(ch); - - mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); - mbx_mem->msg_header = SCMI_MSG_CREATE(proto_id, - SCMI_PROTO_MSG_ATTR_MSG, token); - mbx_mem->len = SCMI_PROTO_MSG_ATTR_MSG_LEN; - mbx_mem->flags = SCMI_FLAG_RESP_POLL; - SCMI_PAYLOAD_ARG1(mbx_mem->payload, command_id); - - scmi_send_sync_command(ch); - - /* Get the return values */ - SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *attr); - assert(mbx_mem->len == SCMI_PROTO_MSG_ATTR_RESP_LEN); - assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); - - scmi_put_channel(ch); - - return ret; -} - -/* - * SCMI Driver initialization API. Returns initialized channel on success - * or NULL on error. The return type is an opaque void pointer. - */ -void *scmi_init(scmi_channel_t *ch) -{ - uint32_t version; - int ret; - - assert(ch && ch->info); - assert(ch->info->db_reg_addr); - assert(ch->info->db_modify_mask); - assert(ch->info->db_preserve_mask); - assert(ch->info->ring_doorbell != NULL); - - assert(ch->lock); - - scmi_lock_init(ch->lock); - - ch->is_initialized = 1; - - ret = scmi_proto_version(ch, SCMI_PWR_DMN_PROTO_ID, &version); - if (ret != SCMI_E_SUCCESS) { - WARN("SCMI power domain protocol version message failed"); - goto error; - } - - if (!is_scmi_version_compatible(SCMI_PWR_DMN_PROTO_VER, version)) { - WARN("SCMI power domain protocol version 0x%x incompatible with driver version 0x%x", - version, SCMI_PWR_DMN_PROTO_VER); - goto error; - } - - VERBOSE("SCMI power domain protocol version 0x%x detected\n", version); - - ret = scmi_proto_version(ch, SCMI_SYS_PWR_PROTO_ID, &version); - if ((ret != SCMI_E_SUCCESS)) { - WARN("SCMI system power protocol version message failed"); - goto error; - } - - if (!is_scmi_version_compatible(SCMI_SYS_PWR_PROTO_VER, version)) { - WARN("SCMI system power management protocol version 0x%x incompatible with driver version 0x%x", - version, SCMI_SYS_PWR_PROTO_VER); - goto error; - } - - VERBOSE("SCMI system power management protocol version 0x%x detected\n", - version); - - INFO("SCMI driver initialized\n"); - - return (void *)ch; - -error: - ch->is_initialized = 0; - return NULL; -} diff --git a/plat/arm/css/drivers/scmi/scmi_private.h b/plat/arm/css/drivers/scmi/scmi_private.h deleted file mode 100644 index 6530573..0000000 --- a/plat/arm/css/drivers/scmi/scmi_private.h +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef SCMI_PRIVATE_H -#define SCMI_PRIVATE_H - -#include - -/* - * SCMI power domain management protocol message and response lengths. It is - * calculated as sum of length in bytes of the message header (4) and payload - * area (the number of bytes of parameters or return values in the payload). - */ -#define SCMI_PROTO_VERSION_MSG_LEN 4 -#define SCMI_PROTO_VERSION_RESP_LEN 12 - -#define SCMI_PROTO_MSG_ATTR_MSG_LEN 8 -#define SCMI_PROTO_MSG_ATTR_RESP_LEN 12 - -#define SCMI_AP_CORE_RESET_ADDR_SET_MSG_LEN 16 -#define SCMI_AP_CORE_RESET_ADDR_SET_RESP_LEN 8 - -#define SCMI_AP_CORE_RESET_ADDR_GET_MSG_LEN 4 -#define SCMI_AP_CORE_RESET_ADDR_GET_RESP_LEN 20 - -#define SCMI_PWR_STATE_SET_MSG_LEN 16 -#define SCMI_PWR_STATE_SET_RESP_LEN 8 - -#define SCMI_PWR_STATE_GET_MSG_LEN 8 -#define SCMI_PWR_STATE_GET_RESP_LEN 12 - -#define SCMI_SYS_PWR_STATE_SET_MSG_LEN 12 -#define SCMI_SYS_PWR_STATE_SET_RESP_LEN 8 - -#define SCMI_SYS_PWR_STATE_GET_MSG_LEN 4 -#define SCMI_SYS_PWR_STATE_GET_RESP_LEN 12 - -/* SCMI message header format bit field */ -#define SCMI_MSG_ID_SHIFT 0 -#define SCMI_MSG_ID_WIDTH 8 -#define SCMI_MSG_ID_MASK ((1 << SCMI_MSG_ID_WIDTH) - 1) - -#define SCMI_MSG_TYPE_SHIFT 8 -#define SCMI_MSG_TYPE_WIDTH 2 -#define SCMI_MSG_TYPE_MASK ((1 << SCMI_MSG_TYPE_WIDTH) - 1) - -#define SCMI_MSG_PROTO_ID_SHIFT 10 -#define SCMI_MSG_PROTO_ID_WIDTH 8 -#define SCMI_MSG_PROTO_ID_MASK ((1 << SCMI_MSG_PROTO_ID_WIDTH) - 1) - -#define SCMI_MSG_TOKEN_SHIFT 18 -#define SCMI_MSG_TOKEN_WIDTH 10 -#define SCMI_MSG_TOKEN_MASK ((1 << SCMI_MSG_TOKEN_WIDTH) - 1) - - -/* SCMI mailbox flags */ -#define SCMI_FLAG_RESP_POLL 0 -#define SCMI_FLAG_RESP_INT 1 - -/* SCMI power domain protocol `POWER_STATE_SET` message flags */ -#define SCMI_PWR_STATE_SET_FLAG_SYNC 0 -#define SCMI_PWR_STATE_SET_FLAG_ASYNC 1 - -/* - * Helper macro to create an SCMI message header given protocol, message id - * and token. - */ -#define SCMI_MSG_CREATE(_protocol, _msg_id, _token) \ - ((((_protocol) & SCMI_MSG_PROTO_ID_MASK) << SCMI_MSG_PROTO_ID_SHIFT) | \ - (((_msg_id) & SCMI_MSG_ID_MASK) << SCMI_MSG_ID_SHIFT) | \ - (((_token) & SCMI_MSG_TOKEN_MASK) << SCMI_MSG_TOKEN_SHIFT)) - -/* Helper macro to get the token from a SCMI message header */ -#define SCMI_MSG_GET_TOKEN(_msg) \ - (((_msg) >> SCMI_MSG_TOKEN_SHIFT) & SCMI_MSG_TOKEN_MASK) - -/* SCMI Channel Status bit fields */ -#define SCMI_CH_STATUS_RES0_MASK 0xFFFFFFFE -#define SCMI_CH_STATUS_FREE_SHIFT 0 -#define SCMI_CH_STATUS_FREE_WIDTH 1 -#define SCMI_CH_STATUS_FREE_MASK ((1 << SCMI_CH_STATUS_FREE_WIDTH) - 1) - -/* Helper macros to check and write the channel status */ -#define SCMI_IS_CHANNEL_FREE(status) \ - (!!(((status) >> SCMI_CH_STATUS_FREE_SHIFT) & SCMI_CH_STATUS_FREE_MASK)) - -#define SCMI_MARK_CHANNEL_BUSY(status) do { \ - assert(SCMI_IS_CHANNEL_FREE(status)); \ - (status) &= ~(SCMI_CH_STATUS_FREE_MASK << \ - SCMI_CH_STATUS_FREE_SHIFT); \ - } while (0) - -/* Helper macros to copy arguments to the mailbox payload */ -#define SCMI_PAYLOAD_ARG1(payld_arr, arg1) \ - mmio_write_32((uintptr_t)&payld_arr[0], arg1) - -#define SCMI_PAYLOAD_ARG2(payld_arr, arg1, arg2) do { \ - SCMI_PAYLOAD_ARG1(payld_arr, arg1); \ - mmio_write_32((uintptr_t)&payld_arr[1], arg2); \ - } while (0) - -#define SCMI_PAYLOAD_ARG3(payld_arr, arg1, arg2, arg3) do { \ - SCMI_PAYLOAD_ARG2(payld_arr, arg1, arg2); \ - mmio_write_32((uintptr_t)&payld_arr[2], arg3); \ - } while (0) - -/* Helper macros to read return values from the mailbox payload */ -#define SCMI_PAYLOAD_RET_VAL1(payld_arr, val1) \ - (val1) = mmio_read_32((uintptr_t)&payld_arr[0]) - -#define SCMI_PAYLOAD_RET_VAL2(payld_arr, val1, val2) do { \ - SCMI_PAYLOAD_RET_VAL1(payld_arr, val1); \ - (val2) = mmio_read_32((uintptr_t)&payld_arr[1]); \ - } while (0) - -#define SCMI_PAYLOAD_RET_VAL3(payld_arr, val1, val2, val3) do { \ - SCMI_PAYLOAD_RET_VAL2(payld_arr, val1, val2); \ - (val3) = mmio_read_32((uintptr_t)&payld_arr[2]); \ - } while (0) - -#define SCMI_PAYLOAD_RET_VAL4(payld_arr, val1, val2, val3, val4) do { \ - SCMI_PAYLOAD_RET_VAL3(payld_arr, val1, val2, val3); \ - (val4) = mmio_read_32((uintptr_t)&payld_arr[3]); \ - } while (0) - -/* - * Private data structure for representing the mailbox memory layout. Refer - * the SCMI specification for more details. - */ -typedef struct mailbox_mem { - uint32_t res_a; /* Reserved */ - volatile uint32_t status; - uint64_t res_b; /* Reserved */ - uint32_t flags; - volatile uint32_t len; - uint32_t msg_header; - uint32_t payload[]; -} mailbox_mem_t; - - -/* Private APIs for use within SCMI driver */ -void scmi_get_channel(scmi_channel_t *ch); -void scmi_send_sync_command(scmi_channel_t *ch); -void scmi_put_channel(scmi_channel_t *ch); - -static inline void validate_scmi_channel(scmi_channel_t *ch) -{ - assert(ch && ch->is_initialized); - assert(ch->info && ch->info->scmi_mbx_mem); -} - -#endif /* SCMI_PRIVATE_H */ diff --git a/plat/arm/css/drivers/scmi/scmi_pwr_dmn_proto.c b/plat/arm/css/drivers/scmi/scmi_pwr_dmn_proto.c deleted file mode 100644 index f315621..0000000 --- a/plat/arm/css/drivers/scmi/scmi_pwr_dmn_proto.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include - -#include -#include - -#include "scmi.h" -#include "scmi_private.h" - -/* - * API to set the SCMI power domain power state. - */ -int scmi_pwr_state_set(void *p, uint32_t domain_id, - uint32_t scmi_pwr_state) -{ - mailbox_mem_t *mbx_mem; - int token = 0, ret; - - /* - * Only asynchronous mode of `set power state` command is allowed on - * application processors. - */ - uint32_t pwr_state_set_msg_flag = SCMI_PWR_STATE_SET_FLAG_ASYNC; - scmi_channel_t *ch = (scmi_channel_t *)p; - - validate_scmi_channel(ch); - - scmi_get_channel(ch); - - mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); - mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID, - SCMI_PWR_STATE_SET_MSG, token); - mbx_mem->len = SCMI_PWR_STATE_SET_MSG_LEN; - mbx_mem->flags = SCMI_FLAG_RESP_POLL; - SCMI_PAYLOAD_ARG3(mbx_mem->payload, pwr_state_set_msg_flag, - domain_id, scmi_pwr_state); - - scmi_send_sync_command(ch); - - /* Get the return values */ - SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret); - assert(mbx_mem->len == SCMI_PWR_STATE_SET_RESP_LEN); - assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); - - scmi_put_channel(ch); - - return ret; -} - -/* - * API to get the SCMI power domain power state. - */ -int scmi_pwr_state_get(void *p, uint32_t domain_id, - uint32_t *scmi_pwr_state) -{ - mailbox_mem_t *mbx_mem; - int token = 0, ret; - scmi_channel_t *ch = (scmi_channel_t *)p; - - validate_scmi_channel(ch); - - scmi_get_channel(ch); - - mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); - mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID, - SCMI_PWR_STATE_GET_MSG, token); - mbx_mem->len = SCMI_PWR_STATE_GET_MSG_LEN; - mbx_mem->flags = SCMI_FLAG_RESP_POLL; - SCMI_PAYLOAD_ARG1(mbx_mem->payload, domain_id); - - scmi_send_sync_command(ch); - - /* Get the return values */ - SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *scmi_pwr_state); - assert(mbx_mem->len == SCMI_PWR_STATE_GET_RESP_LEN); - assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); - - scmi_put_channel(ch); - - return ret; -} diff --git a/plat/arm/css/drivers/scmi/scmi_sys_pwr_proto.c b/plat/arm/css/drivers/scmi/scmi_sys_pwr_proto.c deleted file mode 100644 index 03c3c06..0000000 --- a/plat/arm/css/drivers/scmi/scmi_sys_pwr_proto.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include - -#include -#include - -#include "scmi.h" -#include "scmi_private.h" - -/* - * API to set the SCMI system power state - */ -int scmi_sys_pwr_state_set(void *p, uint32_t flags, uint32_t system_state) -{ - mailbox_mem_t *mbx_mem; - int token = 0, ret; - scmi_channel_t *ch = (scmi_channel_t *)p; - - validate_scmi_channel(ch); - - scmi_get_channel(ch); - - mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); - mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_SYS_PWR_PROTO_ID, - SCMI_SYS_PWR_STATE_SET_MSG, token); - mbx_mem->len = SCMI_SYS_PWR_STATE_SET_MSG_LEN; - mbx_mem->flags = SCMI_FLAG_RESP_POLL; - SCMI_PAYLOAD_ARG2(mbx_mem->payload, flags, system_state); - - scmi_send_sync_command(ch); - - /* Get the return values */ - SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret); - assert(mbx_mem->len == SCMI_SYS_PWR_STATE_SET_RESP_LEN); - assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); - - scmi_put_channel(ch); - - return ret; -} - -/* - * API to get the SCMI system power state - */ -int scmi_sys_pwr_state_get(void *p, uint32_t *system_state) -{ - mailbox_mem_t *mbx_mem; - int token = 0, ret; - scmi_channel_t *ch = (scmi_channel_t *)p; - - validate_scmi_channel(ch); - - scmi_get_channel(ch); - - mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); - mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_SYS_PWR_PROTO_ID, - SCMI_SYS_PWR_STATE_GET_MSG, token); - mbx_mem->len = SCMI_SYS_PWR_STATE_GET_MSG_LEN; - mbx_mem->flags = SCMI_FLAG_RESP_POLL; - - scmi_send_sync_command(ch); - - /* Get the return values */ - SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *system_state); - assert(mbx_mem->len == SCMI_SYS_PWR_STATE_GET_RESP_LEN); - assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); - - scmi_put_channel(ch); - - return ret; -} diff --git a/plat/arm/css/drivers/scp/css_pm_scmi.c b/plat/arm/css/drivers/scp/css_pm_scmi.c index ab9f5f5..2980d9a 100644 --- a/plat/arm/css/drivers/scp/css_pm_scmi.c +++ b/plat/arm/css/drivers/scp/css_pm_scmi.c @@ -9,12 +9,12 @@ #include #include +#include #include #include #include #include -#include "../scmi/scmi.h" #include "css_scp.h" /* diff --git a/plat/arm/css/sgi/sgi_bl31_setup.c b/plat/arm/css/sgi/sgi_bl31_setup.c index 5324482..82d8fed 100644 --- a/plat/arm/css/sgi/sgi_bl31_setup.c +++ b/plat/arm/css/sgi/sgi_bl31_setup.c @@ -10,12 +10,12 @@ #include #include +#include #include #include #include -#include "../../css/drivers/scmi/scmi.h" #include "../../css/drivers/mhu/css_mhu_doorbell.h" sgi_platform_info_t sgi_plat_info; diff --git a/plat/arm/css/sgm/sgm_bl31_setup.c b/plat/arm/css/sgm/sgm_bl31_setup.c index 03d88e8..d9490b1 100644 --- a/plat/arm/css/sgm/sgm_bl31_setup.c +++ b/plat/arm/css/sgm/sgm_bl31_setup.c @@ -6,10 +6,10 @@ #include #include +#include #include #include -#include "../../css/drivers/scmi/scmi.h" #include "../../css/drivers/mhu/css_mhu_doorbell.h" static scmi_channel_plat_info_t sgm775_scmi_plat_info = {