blob: 44b32a829ddfe9a94084c05b0135a1ffe8a343e8 [file] [log] [blame]
Abdellatif El Khlifi4970d5b2023-08-04 14:33:41 +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 */
Abdellatif El Khlifi4970d5b2023-08-04 14:33:41 +01008#include <arm_ffa.h>
9#include <dm.h>
10#include <log.h>
11#include <asm/global_data.h>
12#include <asm/sandbox_arm_ffa_priv.h>
13#include <dm/device-internal.h>
14#include <linux/errno.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18/**
19 * sandbox_ffa_discover() - perform sandbox FF-A discovery
20 * @dev: The sandbox FF-A bus device
21 * Try to discover the FF-A framework. Discovery is performed by
22 * querying the FF-A framework version from secure world using the FFA_VERSION ABI.
23 * Return:
24 *
25 * 0 on success. Otherwise, failure
26 */
27static int sandbox_ffa_discover(struct udevice *dev)
28{
29 int ret;
30 struct udevice *emul;
31
Abdellatif El Khlifibf036192023-08-09 12:47:30 +010032 log_debug("Emulated FF-A framework discovery\n");
Abdellatif El Khlifi4970d5b2023-08-04 14:33:41 +010033
34 ret = ffa_emul_find(dev, &emul);
35 if (ret) {
36 log_err("Cannot find FF-A emulator\n");
37 return ret;
38 }
39
40 ret = ffa_get_version_hdlr(dev);
41 if (ret)
42 return ret;
43
44 return 0;
45}
46
47/**
48 * sandbox_ffa_probe() - The sandbox FF-A driver probe function
49 * @dev: the sandbox-arm-ffa device
50 * Save the emulator device in uc_priv.
51 * Return:
52 *
53 * 0 on success.
54 */
55static int sandbox_ffa_probe(struct udevice *dev)
56{
57 int ret;
58 struct ffa_priv *uc_priv = dev_get_uclass_priv(dev);
59
60 ret = uclass_first_device_err(UCLASS_FFA_EMUL, &uc_priv->emul);
61 if (ret) {
62 log_err("Cannot find FF-A emulator\n");
63 return ret;
64 }
65
66 return 0;
67}
68
69/**
70 * sandbox_ffa_bind() - The sandbox FF-A driver bind function
71 * @dev: the sandbox-arm-ffa device
72 * Try to discover the emulated FF-A bus.
73 * Return:
74 *
75 * 0 on success.
76 */
77static int sandbox_ffa_bind(struct udevice *dev)
78{
79 int ret;
80
81 ret = sandbox_ffa_discover(dev);
82 if (ret)
83 return ret;
84
85 return 0;
86}
87
88/* Sandbox Arm FF-A emulator operations */
89
90static const struct ffa_bus_ops sandbox_ffa_ops = {
91 .partition_info_get = ffa_get_partitions_info_hdlr,
92 .sync_send_receive = ffa_msg_send_direct_req_hdlr,
93 .rxtx_unmap = ffa_unmap_rxtx_buffers_hdlr,
94};
95
96static const struct udevice_id sandbox_ffa_id[] = {
97 { "sandbox,arm-ffa", 0 },
98 { },
99};
100
101/* Declaring the sandbox FF-A driver under UCLASS_FFA */
102U_BOOT_DRIVER(sandbox_arm_ffa) = {
103 .name = "sandbox_arm_ffa",
104 .of_match = sandbox_ffa_id,
105 .id = UCLASS_FFA,
106 .bind = sandbox_ffa_bind,
107 .probe = sandbox_ffa_probe,
108 .ops = &sandbox_ffa_ops,
109};