Michal Simek | 9179436 | 2022-08-31 16:45:14 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved. |
| 3 | * Copyright (c) 2018-2022, Xilinx, Inc. All rights reserved. |
| 4 | * Copyright (C) 2022, Advanced Micro Devices, Inc. All rights reserved. |
| 5 | * |
| 6 | * SPDX-License-Identifier: BSD-3-Clause |
| 7 | */ |
| 8 | |
| 9 | /* Top level SMC handler for SiP calls. Dispatch PM calls to PM SMC handler. */ |
| 10 | |
Michal Simek | dc708ac | 2022-09-19 13:52:54 +0200 | [diff] [blame] | 11 | #include <errno.h> |
Michal Simek | 6e45f94 | 2023-02-15 12:39:22 +0100 | [diff] [blame] | 12 | #include <inttypes.h> |
Michal Simek | dc708ac | 2022-09-19 13:52:54 +0200 | [diff] [blame] | 13 | |
Michal Simek | 9179436 | 2022-08-31 16:45:14 +0200 | [diff] [blame] | 14 | #include <common/debug.h> |
| 15 | #include <common/runtime_svc.h> |
| 16 | #include <tools_share/uuid.h> |
| 17 | |
Michal Simek | aa5443e | 2022-09-19 14:04:55 +0200 | [diff] [blame] | 18 | #include "ipi_mailbox_svc.h" |
Michal Simek | dc708ac | 2022-09-19 13:52:54 +0200 | [diff] [blame] | 19 | #include "plat_private.h" |
| 20 | #include "pm_svc_main.h" |
| 21 | |
Michal Simek | 9179436 | 2022-08-31 16:45:14 +0200 | [diff] [blame] | 22 | /* SMC function IDs for SiP Service queries */ |
| 23 | #define VERSAL_NET_SIP_SVC_CALL_COUNT (0x8200ff00U) |
| 24 | #define VERSAL_NET_SIP_SVC_UID (0x8200ff01U) |
| 25 | #define VERSAL_NET_SIP_SVC_VERSION (0x8200ff03U) |
| 26 | |
| 27 | /* SiP Service Calls version numbers */ |
| 28 | #define SIP_SVC_VERSION_MAJOR (0U) |
| 29 | #define SIP_SVC_VERSION_MINOR (1U) |
| 30 | |
Michal Simek | aa5443e | 2022-09-19 14:04:55 +0200 | [diff] [blame] | 31 | /* These macros are used to identify PM calls from the SMC function ID */ |
Michal Simek | 6e45f94 | 2023-02-15 12:39:22 +0100 | [diff] [blame] | 32 | #define SIP_FID_MASK GENMASK(23, 16) |
| 33 | #define XLNX_FID_MASK GENMASK(23, 12) |
Michal Simek | aa5443e | 2022-09-19 14:04:55 +0200 | [diff] [blame] | 34 | #define PM_FID_VALUE 0u |
| 35 | #define IPI_FID_VALUE 0x1000u |
Michal Simek | 6e45f94 | 2023-02-15 12:39:22 +0100 | [diff] [blame] | 36 | #define is_pm_fid(_fid) (((_fid) & XLNX_FID_MASK) == PM_FID_VALUE) |
| 37 | #define is_ipi_fid(_fid) (((_fid) & XLNX_FID_MASK) == IPI_FID_VALUE) |
Michal Simek | aa5443e | 2022-09-19 14:04:55 +0200 | [diff] [blame] | 38 | |
Michal Simek | 9179436 | 2022-08-31 16:45:14 +0200 | [diff] [blame] | 39 | /* SiP Service UUID */ |
| 40 | DEFINE_SVC_UUID2(versal_net_sip_uuid, |
| 41 | 0x80d4c25a, 0xebaf, 0x11eb, 0x94, 0x68, |
| 42 | 0x0b, 0x4e, 0x3b, 0x8f, 0xc3, 0x60); |
| 43 | |
| 44 | /** |
| 45 | * sip_svc_setup() - Setup SiP Service |
| 46 | */ |
| 47 | static int32_t sip_svc_setup(void) |
| 48 | { |
Michal Simek | dc708ac | 2022-09-19 13:52:54 +0200 | [diff] [blame] | 49 | return sip_svc_setup_init(); |
Michal Simek | 9179436 | 2022-08-31 16:45:14 +0200 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /* |
| 53 | * sip_svc_smc_handler() - Top-level SiP Service SMC handler |
| 54 | * |
| 55 | * Handler for all SiP SMC calls. Handles standard SIP requests |
| 56 | * and calls PM SMC handler if the call is for a PM-API function. |
| 57 | */ |
| 58 | static uintptr_t sip_svc_smc_handler(uint32_t smc_fid, |
| 59 | u_register_t x1, |
| 60 | u_register_t x2, |
| 61 | u_register_t x3, |
| 62 | u_register_t x4, |
| 63 | void *cookie, |
| 64 | void *handle, |
| 65 | u_register_t flags) |
| 66 | { |
Michal Simek | 6e45f94 | 2023-02-15 12:39:22 +0100 | [diff] [blame] | 67 | VERBOSE("SMCID: 0x%08x, x1: 0x%016" PRIx64 ", x2: 0x%016" PRIx64 ", x3: 0x%016" PRIx64 ", x4: 0x%016" PRIx64 "\n", |
| 68 | smc_fid, x1, x2, x3, x4); |
| 69 | |
| 70 | if (smc_fid & SIP_FID_MASK) { |
| 71 | WARN("SMC out of SiP assinged range: 0x%x\n", smc_fid); |
| 72 | SMC_RET1(handle, SMC_UNK); |
| 73 | } |
| 74 | |
Michal Simek | 9179436 | 2022-08-31 16:45:14 +0200 | [diff] [blame] | 75 | /* Let PM SMC handler deal with PM-related requests */ |
Michal Simek | aa5443e | 2022-09-19 14:04:55 +0200 | [diff] [blame] | 76 | if (is_pm_fid(smc_fid)) { |
| 77 | return smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, |
| 78 | flags); |
| 79 | } |
| 80 | |
| 81 | /* Let IPI SMC handler deal with IPI-related requests if platform */ |
| 82 | if (is_ipi_fid(smc_fid)) { |
| 83 | return ipi_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags); |
| 84 | } |
| 85 | |
| 86 | /* Let PM SMC handler deal with PM-related requests */ |
Michal Simek | 9179436 | 2022-08-31 16:45:14 +0200 | [diff] [blame] | 87 | switch (smc_fid) { |
| 88 | case VERSAL_NET_SIP_SVC_CALL_COUNT: |
| 89 | /* PM functions + default functions */ |
| 90 | SMC_RET1(handle, 2); |
| 91 | |
| 92 | case VERSAL_NET_SIP_SVC_UID: |
| 93 | SMC_UUID_RET(handle, versal_net_sip_uuid); |
| 94 | |
| 95 | case VERSAL_NET_SIP_SVC_VERSION: |
| 96 | SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR); |
| 97 | |
| 98 | default: |
| 99 | WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid); |
| 100 | SMC_RET1(handle, SMC_UNK); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /* Register PM Service Calls as runtime service */ |
| 105 | DECLARE_RT_SVC( |
| 106 | sip_svc, |
| 107 | OEN_SIP_START, |
| 108 | OEN_SIP_END, |
| 109 | SMC_TYPE_FAST, |
| 110 | sip_svc_setup, |
| 111 | sip_svc_smc_handler); |