1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * remote processor messaging bus internals
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (c) 2020 The Linux Foundation.
6*4882a593Smuzhiyun * Copyright (C) 2011 Texas Instruments, Inc.
7*4882a593Smuzhiyun * Copyright (C) 2011 Google, Inc.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * Ohad Ben-Cohen <ohad@wizery.com>
10*4882a593Smuzhiyun * Brian Swetland <swetland@google.com>
11*4882a593Smuzhiyun */
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #ifndef __RPMSG_INTERNAL_H__
14*4882a593Smuzhiyun #define __RPMSG_INTERNAL_H__
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #include <linux/rpmsg.h>
17*4882a593Smuzhiyun #include <linux/poll.h>
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun #define to_rpmsg_device(d) container_of(d, struct rpmsg_device, dev)
20*4882a593Smuzhiyun #define to_rpmsg_driver(d) container_of(d, struct rpmsg_driver, drv)
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun /**
23*4882a593Smuzhiyun * struct rpmsg_device_ops - indirection table for the rpmsg_device operations
24*4882a593Smuzhiyun * @create_ept: create backend-specific endpoint, required
25*4882a593Smuzhiyun * @announce_create: announce presence of new channel, optional
26*4882a593Smuzhiyun * @announce_destroy: announce destruction of channel, optional
27*4882a593Smuzhiyun *
28*4882a593Smuzhiyun * Indirection table for the operations that a rpmsg backend should implement.
29*4882a593Smuzhiyun * @announce_create and @announce_destroy are optional as the backend might
30*4882a593Smuzhiyun * advertise new channels implicitly by creating the endpoints.
31*4882a593Smuzhiyun */
32*4882a593Smuzhiyun struct rpmsg_device_ops {
33*4882a593Smuzhiyun struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev,
34*4882a593Smuzhiyun rpmsg_rx_cb_t cb, void *priv,
35*4882a593Smuzhiyun struct rpmsg_channel_info chinfo);
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun int (*announce_create)(struct rpmsg_device *ept);
38*4882a593Smuzhiyun int (*announce_destroy)(struct rpmsg_device *ept);
39*4882a593Smuzhiyun };
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun /**
42*4882a593Smuzhiyun * struct rpmsg_endpoint_ops - indirection table for rpmsg_endpoint operations
43*4882a593Smuzhiyun * @destroy_ept: see @rpmsg_destroy_ept(), required
44*4882a593Smuzhiyun * @send: see @rpmsg_send(), required
45*4882a593Smuzhiyun * @sendto: see @rpmsg_sendto(), optional
46*4882a593Smuzhiyun * @send_offchannel: see @rpmsg_send_offchannel(), optional
47*4882a593Smuzhiyun * @trysend: see @rpmsg_trysend(), required
48*4882a593Smuzhiyun * @trysendto: see @rpmsg_trysendto(), optional
49*4882a593Smuzhiyun * @trysend_offchannel: see @rpmsg_trysend_offchannel(), optional
50*4882a593Smuzhiyun * @poll: see @rpmsg_poll(), optional
51*4882a593Smuzhiyun * @get_signals: see @rpmsg_get_signals(), optional
52*4882a593Smuzhiyun * @set_signals: see @rpmsg_set_signals(), optional
53*4882a593Smuzhiyun *
54*4882a593Smuzhiyun * Indirection table for the operations that a rpmsg backend should implement.
55*4882a593Smuzhiyun * In addition to @destroy_ept, the backend must at least implement @send and
56*4882a593Smuzhiyun * @trysend, while the variants sending data off-channel are optional.
57*4882a593Smuzhiyun */
58*4882a593Smuzhiyun struct rpmsg_endpoint_ops {
59*4882a593Smuzhiyun void (*destroy_ept)(struct rpmsg_endpoint *ept);
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun int (*send)(struct rpmsg_endpoint *ept, void *data, int len);
62*4882a593Smuzhiyun int (*sendto)(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
63*4882a593Smuzhiyun int (*send_offchannel)(struct rpmsg_endpoint *ept, u32 src, u32 dst,
64*4882a593Smuzhiyun void *data, int len);
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun int (*trysend)(struct rpmsg_endpoint *ept, void *data, int len);
67*4882a593Smuzhiyun int (*trysendto)(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
68*4882a593Smuzhiyun int (*trysend_offchannel)(struct rpmsg_endpoint *ept, u32 src, u32 dst,
69*4882a593Smuzhiyun void *data, int len);
70*4882a593Smuzhiyun __poll_t (*poll)(struct rpmsg_endpoint *ept, struct file *filp,
71*4882a593Smuzhiyun poll_table *wait);
72*4882a593Smuzhiyun int (*get_signals)(struct rpmsg_endpoint *ept);
73*4882a593Smuzhiyun int (*set_signals)(struct rpmsg_endpoint *ept, u32 set, u32 clear);
74*4882a593Smuzhiyun };
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun int rpmsg_register_device(struct rpmsg_device *rpdev);
77*4882a593Smuzhiyun int rpmsg_unregister_device(struct device *parent,
78*4882a593Smuzhiyun struct rpmsg_channel_info *chinfo);
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun struct device *rpmsg_find_device(struct device *parent,
81*4882a593Smuzhiyun struct rpmsg_channel_info *chinfo);
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun /**
84*4882a593Smuzhiyun * rpmsg_chrdev_register_device() - register chrdev device based on rpdev
85*4882a593Smuzhiyun * @rpdev: prepared rpdev to be used for creating endpoints
86*4882a593Smuzhiyun *
87*4882a593Smuzhiyun * This function wraps rpmsg_register_device() preparing the rpdev for use as
88*4882a593Smuzhiyun * basis for the rpmsg chrdev.
89*4882a593Smuzhiyun */
rpmsg_chrdev_register_device(struct rpmsg_device * rpdev)90*4882a593Smuzhiyun static inline int rpmsg_chrdev_register_device(struct rpmsg_device *rpdev)
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun strcpy(rpdev->id.name, "rpmsg_chrdev");
93*4882a593Smuzhiyun rpdev->driver_override = "rpmsg_chrdev";
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun return rpmsg_register_device(rpdev);
96*4882a593Smuzhiyun }
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun #endif
99