blob: 8bcfa6e3c972127d8d2fc9bf0fdbc779dc308822 [file] [log] [blame]
Soren Brinkmann76fcae32016-03-06 20:16:27 -08001/*
2 * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/* Top level SMC handler for SiP calls. Dispatch PM calls to PM SMC handler. */
32
33#include <runtime_svc.h>
34#include <uuid.h>
35#include "pm_svc_main.h"
36
37/* SMC function IDs for SiP Service queries */
38#define ZYNQMP_SIP_SVC_CALL_COUNT 0x8200ff00
39#define ZYNQMP_SIP_SVC_UID 0x8200ff01
40#define ZYNQMP_SIP_SVC_VERSION 0x8200ff03
41
42/* SiP Service Calls version numbers */
43#define SIP_SVC_VERSION_MAJOR 0
44#define SIP_SVC_VERSION_MINOR 1
45
46/* These macros are used to identify PM calls from the SMC function ID */
47#define PM_FID_MASK 0xf000u
48#define PM_FID_VALUE 0u
49#define is_pm_fid(_fid) (((_fid) & PM_FID_MASK) == PM_FID_VALUE)
50
51/* SiP Service UUID */
52DEFINE_SVC_UUID(zynqmp_sip_uuid,
53 0x2a1d9b5c, 0x8605, 0x4023, 0xa6, 0x1b,
54 0xb9, 0x25, 0x82, 0x2d, 0xe3, 0xa5);
55
56/**
57 * sip_svc_setup() - Setup SiP Service
58 *
59 * Invokes PM setup
60 */
61static int32_t sip_svc_setup(void)
62{
63 /* PM implementation as SiP Service */
64 pm_setup();
65
66 return 0;
67}
68
69/**
70 * sip_svc_smc_handler() - Top-level SiP Service SMC handler
71 *
72 * Handler for all SiP SMC calls. Handles standard SIP requests
73 * and calls PM SMC handler if the call is for a PM-API function.
74 */
75uint64_t sip_svc_smc_handler(uint32_t smc_fid,
76 uint64_t x1,
77 uint64_t x2,
78 uint64_t x3,
79 uint64_t x4,
80 void *cookie,
81 void *handle,
82 uint64_t flags)
83{
84 /* Let PM SMC handler deal with PM-related requests */
85 if (is_pm_fid(smc_fid)) {
86 return pm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
87 flags);
88 }
89
90 switch (smc_fid) {
91 case ZYNQMP_SIP_SVC_CALL_COUNT:
92 /* PM functions + default functions */
93 SMC_RET1(handle, PM_API_MAX + 2);
94
95 case ZYNQMP_SIP_SVC_UID:
96 SMC_UUID_RET(handle, zynqmp_sip_uuid);
97
98 case ZYNQMP_SIP_SVC_VERSION:
99 SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR);
100
101 default:
102 WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid);
103 SMC_RET1(handle, SMC_UNK);
104 }
105}
106
107/* Register PM Service Calls as runtime service */
108DECLARE_RT_SVC(
109 sip_svc,
110 OEN_SIP_START,
111 OEN_SIP_END,
112 SMC_TYPE_FAST,
113 sip_svc_setup,
114 sip_svc_smc_handler);