blob: 010bb8f794ed529c78c0b7e83532dd538d1b7244 [file] [log] [blame]
Jeenu Viswambharan1814a3e2014-02-28 10:08:33 +00001/*
Soby Mathewa0fedc42016-06-16 14:52:04 +01002 * Copyright (c) 2014-2016, ARM Limited and Contributors. All rights reserved.
Jeenu Viswambharan1814a3e2014-02-28 10:08:33 +00003 *
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
Soby Mathew8da89662016-09-19 17:21:15 +010031#include <assert.h>
dp-arm3cac7862016-09-19 11:18:44 +010032#include <cpu_data.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010033#include <debug.h>
dp-arm3cac7862016-09-19 11:18:44 +010034#include <pmf.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010035#include <psci.h>
dp-arm3cac7862016-09-19 11:18:44 +010036#include <runtime_instr.h>
Jeenu Viswambharan1814a3e2014-02-28 10:08:33 +000037#include <runtime_svc.h>
Soby Mathewd0194872016-04-29 19:01:30 +010038#include <smcc_helpers.h>
Jeenu Viswambharan1814a3e2014-02-28 10:08:33 +000039#include <std_svc.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010040#include <stdint.h>
41#include <uuid.h>
Jeenu Viswambharan1814a3e2014-02-28 10:08:33 +000042
43/* Standard Service UUID */
44DEFINE_SVC_UUID(arm_svc_uid,
45 0x108d905b, 0xf863, 0x47e8, 0xae, 0x2d,
46 0xc0, 0xfb, 0x56, 0x41, 0xf6, 0xe2);
47
Soby Mathew8da89662016-09-19 17:21:15 +010048/* Setup Standard Services */
49static int32_t std_svc_setup(void)
50{
51 uintptr_t svc_arg;
52
53 svc_arg = get_arm_std_svc_args(PSCI_FID_MASK);
54 assert(svc_arg);
55
56 /*
57 * PSCI is the only specification implemented as a Standard Service.
58 * The `psci_setup()` also does EL3 architectural setup.
59 */
60 return psci_setup((const psci_lib_args_t *)svc_arg);
61}
62
Jeenu Viswambharan1814a3e2014-02-28 10:08:33 +000063/*
64 * Top-level Standard Service SMC handler. This handler will in turn dispatch
65 * calls to PSCI SMC handler
66 */
Soby Mathewa0fedc42016-06-16 14:52:04 +010067uintptr_t std_svc_smc_handler(uint32_t smc_fid,
68 u_register_t x1,
69 u_register_t x2,
70 u_register_t x3,
71 u_register_t x4,
Jeenu Viswambharan1814a3e2014-02-28 10:08:33 +000072 void *cookie,
73 void *handle,
Soby Mathewa0fedc42016-06-16 14:52:04 +010074 u_register_t flags)
Jeenu Viswambharan1814a3e2014-02-28 10:08:33 +000075{
76 /*
77 * Dispatch PSCI calls to PSCI SMC handler and return its return
78 * value
79 */
80 if (is_psci_fid(smc_fid)) {
dp-arm3cac7862016-09-19 11:18:44 +010081 uint64_t ret;
82
83#if ENABLE_RUNTIME_INSTRUMENTATION
dp-armc93e21f2016-10-31 17:17:21 +000084
85 /*
86 * Flush cache line so that even if CPU power down happens
87 * the timestamp update is reflected in memory.
88 */
dp-arm3cac7862016-09-19 11:18:44 +010089 PMF_WRITE_TIMESTAMP(rt_instr_svc,
90 RT_INSTR_ENTER_PSCI,
dp-armc93e21f2016-10-31 17:17:21 +000091 PMF_CACHE_MAINT,
dp-arm3cac7862016-09-19 11:18:44 +010092 get_cpu_data(cpu_data_pmf_ts[CPU_DATA_PMF_TS0_IDX]));
93#endif
94
95 ret = psci_smc_handler(smc_fid, x1, x2, x3, x4,
96 cookie, handle, flags);
97
98#if ENABLE_RUNTIME_INSTRUMENTATION
99 PMF_CAPTURE_TIMESTAMP(rt_instr_svc,
100 RT_INSTR_EXIT_PSCI,
101 PMF_NO_CACHE_MAINT);
102#endif
103
104 SMC_RET1(handle, ret);
Jeenu Viswambharan1814a3e2014-02-28 10:08:33 +0000105 }
106
107 switch (smc_fid) {
108 case ARM_STD_SVC_CALL_COUNT:
109 /*
110 * Return the number of Standard Service Calls. PSCI is the only
111 * standard service implemented; so return number of PSCI calls
112 */
113 SMC_RET1(handle, PSCI_NUM_CALLS);
114
115 case ARM_STD_SVC_UID:
116 /* Return UID to the caller */
117 SMC_UUID_RET(handle, arm_svc_uid);
118
119 case ARM_STD_SVC_VERSION:
120 /* Return the version of current implementation */
121 SMC_RET2(handle, STD_SVC_VERSION_MAJOR, STD_SVC_VERSION_MINOR);
122
123 default:
124 WARN("Unimplemented Standard Service Call: 0x%x \n", smc_fid);
125 SMC_RET1(handle, SMC_UNK);
126 }
127}
128
129/* Register Standard Service Calls as runtime service */
130DECLARE_RT_SVC(
131 std_svc,
132
133 OEN_STD_START,
134 OEN_STD_END,
135 SMC_TYPE_FAST,
Soby Mathew8da89662016-09-19 17:21:15 +0100136 std_svc_setup,
Jeenu Viswambharan1814a3e2014-02-28 10:08:33 +0000137 std_svc_smc_handler
138);