firmware: arm_ffa: Add support for SMCCC as transport to FFA driver
[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
9#include <linux/cdev.h>
10#include <linux/device.h>
11#include <linux/module.h>
12#include <linux/types.h>
13#include <linux/uuid.h>
14
15/* FFA Bus/Device/Driver related */
16struct ffa_device {
17 int vm_id;
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);
51
52#else
53static inline
54struct ffa_device *ffa_device_register(const uuid_t *uuid, int vm_id)
55{
56 return NULL;
57}
58
59static inline void ffa_device_unregister(struct ffa_device *dev) {}
60
61static inline int
62ffa_driver_register(struct ffa_driver *driver, struct module *owner,
63 const char *mod_name)
64{
65 return -EINVAL;
66}
67
68static inline void ffa_driver_unregister(struct ffa_driver *driver) {}
69
70static inline
71bool ffa_device_is_valid(struct ffa_device *ffa_dev) { return false; }
72
73#endif /* CONFIG_ARM_FFA_TRANSPORT */
74
75#define ffa_register(driver) \
76 ffa_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
77#define ffa_unregister(driver) \
78 ffa_driver_unregister(driver)
79
80/**
81 * module_ffa_driver() - Helper macro for registering a psa_ffa driver
82 * @__ffa_driver: ffa_driver structure
83 *
84 * Helper macro for psa_ffa drivers to set up proper module init / exit
85 * functions. Replaces module_init() and module_exit() and keeps people from
86 * printing pointless things to the kernel log when their driver is loaded.
87 */
88#define module_ffa_driver(__ffa_driver) \
89 module_driver(__ffa_driver, ffa_register, ffa_unregister)
90
91#endif /* _LINUX_ARM_FFA_H */