blob: ee0bf9a55b4850c34f110e86daad976c9a0f520c [file] [log] [blame]
Abdellatif El Khlifi2f403d12023-08-04 14:33:40 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
4 *
5 * Authors:
6 * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
7 */
8
9#include <common.h>
10#include <arm_ffa.h>
11#include <arm_ffa_priv.h>
12#include <dm.h>
13#include <log.h>
14#include <asm/global_data.h>
15#include <dm/device-internal.h>
16#include <linux/errno.h>
17
18DECLARE_GLOBAL_DATA_PTR;
19
20/**
21 * invoke_ffa_fn() - SMC wrapper
22 * @args: FF-A ABI arguments to be copied to Xn registers
23 * @res: FF-A ABI return data to be copied from Xn registers
24 *
25 * Calls low level SMC assembly function
26 */
27void invoke_ffa_fn(ffa_value_t args, ffa_value_t *res)
28{
29 arm_smccc_1_2_smc(&args, res);
30}
31
32/**
33 * arm_ffa_discover() - perform FF-A discovery
34 * @dev: The Arm FF-A bus device (arm_ffa)
35 * Try to discover the FF-A framework. Discovery is performed by
36 * querying the FF-A framework version from secure world using the FFA_VERSION ABI.
37 * Return:
38 *
39 * true on success. Otherwise, false.
40 */
41static bool arm_ffa_discover(struct udevice *dev)
42{
43 int ret;
44
Abdellatif El Khlifibf036192023-08-09 12:47:30 +010045 log_debug("Arm FF-A framework discovery\n");
Abdellatif El Khlifi2f403d12023-08-04 14:33:40 +010046
47 ret = ffa_get_version_hdlr(dev);
48 if (ret)
49 return false;
50
51 return true;
52}
53
54/**
55 * arm_ffa_is_supported() - FF-A bus discovery callback
56 * @invoke_fn: legacy SMC invoke function (not used)
57 *
58 * Perform FF-A discovery by calling arm_ffa_discover().
59 * Discovery is performed by querying the FF-A framework version from
60 * secure world using the FFA_VERSION ABI.
61 *
62 * The FF-A driver is registered as an SMCCC feature driver. So, features discovery
63 * callbacks are called by the PSCI driver (PSCI device is the SMCCC features
64 * root device).
65 *
66 * The FF-A driver supports the SMCCCv1.2 extended input/output registers.
67 * So, the legacy SMC invocation is not used.
68 *
69 * Return:
70 *
71 * 0 on success. Otherwise, failure
72 */
73static bool arm_ffa_is_supported(void (*invoke_fn)(ulong a0, ulong a1,
74 ulong a2, ulong a3,
75 ulong a4, ulong a5,
76 ulong a6, ulong a7,
77 struct arm_smccc_res *res))
78{
79 return arm_ffa_discover(NULL);
80}
81
82/* Arm FF-A driver operations */
83
84static const struct ffa_bus_ops ffa_ops = {
85 .partition_info_get = ffa_get_partitions_info_hdlr,
86 .sync_send_receive = ffa_msg_send_direct_req_hdlr,
87 .rxtx_unmap = ffa_unmap_rxtx_buffers_hdlr,
88};
89
90/* Registering the FF-A driver as an SMCCC feature driver */
91
92ARM_SMCCC_FEATURE_DRIVER(arm_ffa) = {
93 .driver_name = FFA_DRV_NAME,
94 .is_supported = arm_ffa_is_supported,
95};
96
97/* Declaring the FF-A driver under UCLASS_FFA */
98
99U_BOOT_DRIVER(arm_ffa) = {
100 .name = FFA_DRV_NAME,
101 .id = UCLASS_FFA,
102 .flags = DM_REMOVE_OS_PREPARE,
103 .ops = &ffa_ops,
104};