firmware: arm_ffa: Setup in-kernel users of FFA partitions
[linux-2.6-block.git] / include / linux / arm_ffa.h
CommitLineData
e7818584
SH
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2021 ARM Ltd.
4 */
5
6#ifndef _LINUX_ARM_FFA_H
7#define _LINUX_ARM_FFA_H
8
e7818584
SH
9#include <linux/device.h>
10#include <linux/module.h>
11#include <linux/types.h>
12#include <linux/uuid.h>
13
14/* FFA Bus/Device/Driver related */
15struct ffa_device {
16 int vm_id;
d0c0bce8 17 bool mode_32bit;
e7818584
SH
18 uuid_t uuid;
19 struct device dev;
20};
21
22#define to_ffa_dev(d) container_of(d, struct ffa_device, dev)
23
24struct ffa_device_id {
25 uuid_t uuid;
26};
27
28struct ffa_driver {
29 const char *name;
30 int (*probe)(struct ffa_device *sdev);
31 void (*remove)(struct ffa_device *sdev);
32 const struct ffa_device_id *id_table;
33
34 struct device_driver driver;
35};
36
37#define to_ffa_driver(d) container_of(d, struct ffa_driver, driver)
38
39static inline void ffa_dev_set_drvdata(struct ffa_device *fdev, void *data)
40{
41 fdev->dev.driver_data = data;
42}
43
44#if IS_REACHABLE(CONFIG_ARM_FFA_TRANSPORT)
45struct ffa_device *ffa_device_register(const uuid_t *uuid, int vm_id);
46void ffa_device_unregister(struct ffa_device *ffa_dev);
47int ffa_driver_register(struct ffa_driver *driver, struct module *owner,
48 const char *mod_name);
49void ffa_driver_unregister(struct ffa_driver *driver);
50bool ffa_device_is_valid(struct ffa_device *ffa_dev);
d0c0bce8 51const struct ffa_dev_ops *ffa_dev_ops_get(struct ffa_device *dev);
e7818584
SH
52
53#else
54static inline
55struct ffa_device *ffa_device_register(const uuid_t *uuid, int vm_id)
56{
57 return NULL;
58}
59
60static inline void ffa_device_unregister(struct ffa_device *dev) {}
61
62static inline int
63ffa_driver_register(struct ffa_driver *driver, struct module *owner,
64 const char *mod_name)
65{
66 return -EINVAL;
67}
68
69static inline void ffa_driver_unregister(struct ffa_driver *driver) {}
70
71static inline
72bool ffa_device_is_valid(struct ffa_device *ffa_dev) { return false; }
73
d0c0bce8
SH
74static inline
75const struct ffa_dev_ops *ffa_dev_ops_get(struct ffa_device *dev)
76{
77 return NULL;
78}
e7818584
SH
79#endif /* CONFIG_ARM_FFA_TRANSPORT */
80
81#define ffa_register(driver) \
82 ffa_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
83#define ffa_unregister(driver) \
84 ffa_driver_unregister(driver)
85
86/**
87 * module_ffa_driver() - Helper macro for registering a psa_ffa driver
88 * @__ffa_driver: ffa_driver structure
89 *
90 * Helper macro for psa_ffa drivers to set up proper module init / exit
91 * functions. Replaces module_init() and module_exit() and keeps people from
92 * printing pointless things to the kernel log when their driver is loaded.
93 */
94#define module_ffa_driver(__ffa_driver) \
95 module_driver(__ffa_driver, ffa_register, ffa_unregister)
96
d0c0bce8
SH
97/* FFA transport related */
98struct ffa_partition_info {
99 u16 id;
100 u16 exec_ctxt;
101/* partition supports receipt of direct requests */
102#define FFA_PARTITION_DIRECT_RECV BIT(0)
103/* partition can send direct requests. */
104#define FFA_PARTITION_DIRECT_SEND BIT(1)
105/* partition can send and receive indirect messages. */
106#define FFA_PARTITION_INDIRECT_MSG BIT(2)
107 u32 properties;
108};
109
110/* For use with FFA_MSG_SEND_DIRECT_{REQ,RESP} which pass data via registers */
111struct ffa_send_direct_data {
112 unsigned long data0; /* w3/x3 */
113 unsigned long data1; /* w4/x4 */
114 unsigned long data2; /* w5/x5 */
115 unsigned long data3; /* w6/x6 */
116 unsigned long data4; /* w7/x7 */
117};
118
119struct ffa_dev_ops {
120 u32 (*api_version_get)(void);
121 int (*partition_info_get)(const char *uuid_str,
122 struct ffa_partition_info *buffer);
123 void (*mode_32bit_set)(struct ffa_device *dev);
124 int (*sync_send_receive)(struct ffa_device *dev,
125 struct ffa_send_direct_data *data);
126};
127
e7818584 128#endif /* _LINUX_ARM_FFA_H */