1 /*
2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <assert.h>
8 #include <stdint.h>
9
10 #include <arch.h>
11 #include <arch_helpers.h>
12 #include <common/debug.h>
13 #include <common/runtime_svc.h>
14 #include <plat/common/platform.h>
15 #include <tools_share/uuid.h>
16
17 #include <oem_svc.h>
18
19 /* OEM Service UUID */
20 DEFINE_SVC_UUID2(oem_svc_uid,
21 0xd0ad43b9, 0x9b06, 0xe411, 0x91, 0x91,
22 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66);
23
24 /* Setup OEM Services */
oem_svc_setup(void)25 static int32_t oem_svc_setup(void)
26 {
27 /*
28 * Invoke related module setup from here
29 */
30
31 return 0;
32 }
33
34 /*******************************************************************************
35 * OEM top level handler for servicing SMCs.
36 ******************************************************************************/
oem_smc_handler(uint32_t smc_fid,u_register_t x1,u_register_t x2,u_register_t x3,u_register_t x4,void * cookie,void * handle,u_register_t flags)37 uintptr_t oem_smc_handler(uint32_t smc_fid,
38 u_register_t x1,
39 u_register_t x2,
40 u_register_t x3,
41 u_register_t x4,
42 void *cookie,
43 void *handle,
44 u_register_t flags)
45 {
46 WARN("Unimplemented OEM Call: 0x%x\n", smc_fid);
47 SMC_RET1(handle, SMC_UNK);
48 }
49
50 /*
51 * Top-level OEM Service SMC handler. This handler will in turn dispatch
52 * calls to related SMC handler
53 */
oem_svc_smc_handler(uint32_t smc_fid,u_register_t x1,u_register_t x2,u_register_t x3,u_register_t x4,void * cookie,void * handle,u_register_t flags)54 uintptr_t oem_svc_smc_handler(uint32_t smc_fid,
55 u_register_t x1,
56 u_register_t x2,
57 u_register_t x3,
58 u_register_t x4,
59 void *cookie,
60 void *handle,
61 u_register_t flags)
62 {
63 /*
64 * Dispatch OEM calls to OEM Common handler and return its return value
65 */
66 if (is_oem_fid(smc_fid)) {
67 return oem_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
68 handle, flags);
69 }
70
71 switch (smc_fid) {
72 case OEM_SVC_CALL_COUNT:
73 /*
74 * Return the number of OEM Service Calls.
75 */
76 SMC_RET1(handle, OEM_SVC_NUM_CALLS);
77
78 case OEM_SVC_UID:
79 /* Return UID to the caller */
80 SMC_UUID_RET(handle, oem_svc_uid);
81
82 case OEM_SVC_VERSION:
83 /* Return the version of current implementation */
84 SMC_RET2(handle, OEM_VERSION_MAJOR, OEM_VERSION_MINOR);
85
86 default:
87 WARN("Unimplemented OEM Service Call: 0x%x\n", smc_fid);
88 SMC_RET1(handle, SMC_UNK);
89 }
90 }
91
92 /* Register OEM Service Calls as runtime service */
93 DECLARE_RT_SVC(
94 oem_svc,
95 OEN_OEM_START,
96 OEN_OEM_END,
97 SMC_TYPE_FAST,
98 oem_svc_setup,
99 oem_svc_smc_handler
100 );
101