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