blob: 52e8cd70ff9b5d3a1ce6ad82f118d5cecd6d9c03 [file] [log] [blame]
Caesar Wangc1bf6462016-06-21 14:44:01 +08001/*
2 * Copyright (c) 2016, 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 *
Antonio Nino Diaz493bf332016-12-14 14:31:32 +00007 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
Caesar Wangc1bf6462016-06-21 14:44:01 +08009 *
Antonio Nino Diaz493bf332016-12-14 14:31:32 +000010 * Redistributions in binary form must reproduce the above copyright notice,
Caesar Wangc1bf6462016-06-21 14:44:01 +080011 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
Antonio Nino Diaz493bf332016-12-14 14:31:32 +000014 * 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 *
Caesar Wangc1bf6462016-06-21 14:44:01 +080018 * 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#include <assert.h>
32#include <debug.h>
33#include <mmio.h>
34#include <plat_sip_calls.h>
35#include <rockchip_sip_svc.h>
36#include <runtime_svc.h>
37#include <uuid.h>
38
39/* Rockchip SiP Service UUID */
40DEFINE_SVC_UUID(rk_sip_svc_uid,
41 0xe86fc7e2, 0x313e, 0x11e6, 0xb7, 0x0d,
42 0x8f, 0x88, 0xee, 0x74, 0x7b, 0x72);
43
44#pragma weak rockchip_plat_sip_handler
45uint64_t rockchip_plat_sip_handler(uint32_t smc_fid,
46 uint64_t x1,
47 uint64_t x2,
48 uint64_t x3,
49 uint64_t x4,
50 void *cookie,
51 void *handle,
52 uint64_t flags)
53{
54 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
55 SMC_RET1(handle, SMC_UNK);
56}
57
58/*
59 * This function is responsible for handling all SiP calls from the NS world
60 */
61uint64_t sip_smc_handler(uint32_t smc_fid,
62 uint64_t x1,
63 uint64_t x2,
64 uint64_t x3,
65 uint64_t x4,
66 void *cookie,
67 void *handle,
68 uint64_t flags)
69{
70 uint32_t ns;
71
72 /* Determine which security state this SMC originated from */
73 ns = is_caller_non_secure(flags);
74 if (!ns)
75 SMC_RET1(handle, SMC_UNK);
76
77 switch (smc_fid) {
78 case SIP_SVC_CALL_COUNT:
79 /* Return the number of Rockchip SiP Service Calls. */
80 SMC_RET1(handle,
81 RK_COMMON_SIP_NUM_CALLS + RK_PLAT_SIP_NUM_CALLS);
82
83 case SIP_SVC_UID:
84 /* Return UID to the caller */
85 SMC_UUID_RET(handle, rk_sip_svc_uid);
86 break;
87
88 case SIP_SVC_VERSION:
89 /* Return the version of current implementation */
90 SMC_RET2(handle, RK_SIP_SVC_VERSION_MAJOR,
91 RK_SIP_SVC_VERSION_MINOR);
92 break;
93
94 default:
95 return rockchip_plat_sip_handler(smc_fid, x1, x2, x3, x4,
96 cookie, handle, flags);
97 }
98}
99
100/* Define a runtime service descriptor for fast SMC calls */
101DECLARE_RT_SVC(
102 rockchip_sip_svc,
103 OEN_SIP_START,
104 OEN_SIP_END,
105 SMC_TYPE_FAST,
106 NULL,
107 sip_smc_handler
108);