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