blob: 32a3dc273480eeb21afeca8fac085eb132484fe4 [file] [log] [blame]
Govindraj Rajabedf4ef2024-02-23 16:50:52 -06001/*
2 * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <stdint.h>
8
9#include <common/debug.h>
10#include <common/runtime_svc.h>
Govindraj Raja79cd7a02024-03-07 15:24:19 -060011#include <lib/debugfs.h>
Govindraj Rajacd29ad52024-04-15 12:42:13 -050012#include <lib/pmf/pmf.h>
Govindraj Rajabedf4ef2024-02-23 16:50:52 -060013#include <services/ven_el3_svc.h>
14#include <tools_share/uuid.h>
15
16/* vendor-specific EL3 UUID */
17DEFINE_SVC_UUID2(ven_el3_svc_uid,
18 0xb6011dca, 0x57c4, 0x407e, 0x83, 0xf0,
19 0xa7, 0xed, 0xda, 0xf0, 0xdf, 0x6c);
20
21static int ven_el3_svc_setup(void)
22{
Govindraj Raja79cd7a02024-03-07 15:24:19 -060023#if USE_DEBUGFS
24 if (debugfs_smc_setup() != 0) {
25 return 1;
26 }
27#endif /* USE_DEBUGFS */
28
Govindraj Rajacd29ad52024-04-15 12:42:13 -050029#if ENABLE_PMF
30 if (pmf_setup() != 0) {
31 return 1;
32 }
33#endif /* ENABLE_PMF */
34
Govindraj Rajabedf4ef2024-02-23 16:50:52 -060035 return 0;
36}
37
38/*
39 * This function handles Arm defined vendor-specific EL3 Service Calls.
40 */
41static uintptr_t ven_el3_svc_handler(unsigned int smc_fid,
42 u_register_t x1,
43 u_register_t x2,
44 u_register_t x3,
45 u_register_t x4,
46 void *cookie,
47 void *handle,
48 u_register_t flags)
49{
Govindraj Raja79cd7a02024-03-07 15:24:19 -060050#if USE_DEBUGFS
51 /*
52 * Dispatch debugfs calls to debugfs SMC handler and return its
53 * return value.
54 */
55 if (is_debugfs_fid(smc_fid)) {
56 return debugfs_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
57 handle, flags);
58 }
59#endif /* USE_DEBUGFS */
60
Govindraj Rajacd29ad52024-04-15 12:42:13 -050061#if ENABLE_PMF
62
63 /*
64 * Dispatch PMF calls to PMF SMC handler and return its return
65 * value
66 */
67 if (is_pmf_fid(smc_fid)) {
68 return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
69 handle, flags);
70 }
71
72#endif /* ENABLE_PMF */
73
Govindraj Rajabedf4ef2024-02-23 16:50:52 -060074 switch (smc_fid) {
75 case VEN_EL3_SVC_UID:
76 /* Return UID to the caller */
77 SMC_UUID_RET(handle, ven_el3_svc_uid);
78 break;
79 case VEN_EL3_SVC_VERSION:
80 SMC_RET2(handle, VEN_EL3_SVC_VERSION_MAJOR, VEN_EL3_SVC_VERSION_MINOR);
81 break;
82 default:
Govindraj Raja79cd7a02024-03-07 15:24:19 -060083 WARN("Unimplemented vendor-specific EL3 Service call: 0x%x\n", smc_fid);
Govindraj Rajabedf4ef2024-02-23 16:50:52 -060084 SMC_RET1(handle, SMC_UNK);
85 break;
86 }
87}
88
89/* Define a runtime service descriptor for fast SMC calls */
90DECLARE_RT_SVC(
91 ven_el3_svc,
92 OEN_VEN_EL3_START,
93 OEN_VEN_EL3_END,
94 SMC_TYPE_FAST,
95 ven_el3_svc_setup,
96 ven_el3_svc_handler
97);