blob: 404c496a7717fa34c40006499e2c041e19d6aeaf [file] [log] [blame]
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +05301/*
Tejas Patel354fe572018-12-14 00:55:37 -08002 * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +05303 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/* Top level SMC handler for SiP calls. Dispatch PM calls to PM SMC handler. */
8
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <common/debug.h>
10#include <common/runtime_svc.h>
11#include <tools_share/uuid.h>
Tejas Patel354fe572018-12-14 00:55:37 -080012#include "pm_svc_main.h"
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +053013
14/* SMC function IDs for SiP Service queries */
15#define VERSAL_SIP_SVC_CALL_COUNT 0x8200ff00
16#define VERSAL_SIP_SVC_UID 0x8200ff01
17#define VERSAL_SIP_SVC_VERSION 0x8200ff03
18
19/* SiP Service Calls version numbers */
20#define SIP_SVC_VERSION_MAJOR 0
21#define SIP_SVC_VERSION_MINOR 1
22
23/* These macros are used to identify PM calls from the SMC function ID */
24#define PM_FID_MASK 0xf000u
25#define PM_FID_VALUE 0u
26#define is_pm_fid(_fid) (((_fid) & PM_FID_MASK) == PM_FID_VALUE)
27
28/* SiP Service UUID */
29DEFINE_SVC_UUID2(versal_sip_uuid,
30 0x2ab9e4ec, 0x93b9, 0x11e7, 0xa0, 0x19,
31 0xdf, 0xe0, 0xdb, 0xad, 0x0a, 0xe0);
32
33/**
34 * sip_svc_setup() - Setup SiP Service
35 *
36 * Invokes PM setup
37 */
38static int32_t sip_svc_setup(void)
39{
Tejas Patel354fe572018-12-14 00:55:37 -080040 /* PM implementation as SiP Service */
41 pm_setup();
42
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +053043 return 0;
44}
45
46/**
47 * sip_svc_smc_handler() - Top-level SiP Service SMC handler
48 *
49 * Handler for all SiP SMC calls. Handles standard SIP requests
50 * and calls PM SMC handler if the call is for a PM-API function.
51 */
52uintptr_t sip_svc_smc_handler(uint32_t smc_fid,
53 u_register_t x1,
54 u_register_t x2,
55 u_register_t x3,
56 u_register_t x4,
57 void *cookie,
58 void *handle,
59 u_register_t flags)
60{
61 /* Let PM SMC handler deal with PM-related requests */
Tejas Patel59c608a2019-01-09 04:10:29 -080062 if (is_pm_fid(smc_fid)) {
63 return pm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
64 flags);
65 }
66
67 /* Let PM SMC handler deal with PM-related requests */
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +053068 switch (smc_fid) {
69 case VERSAL_SIP_SVC_CALL_COUNT:
70 /* PM functions + default functions */
71 SMC_RET1(handle, 2);
72
73 case VERSAL_SIP_SVC_UID:
74 SMC_UUID_RET(handle, versal_sip_uuid);
75
76 case VERSAL_SIP_SVC_VERSION:
77 SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR);
78
79 default:
80 WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid);
81 SMC_RET1(handle, SMC_UNK);
82 }
83}
84
85/* Register PM Service Calls as runtime service */
86DECLARE_RT_SVC(
87 sip_svc,
88 OEN_SIP_START,
89 OEN_SIP_END,
90 SMC_TYPE_FAST,
91 sip_svc_setup,
92 sip_svc_smc_handler);