Merge tag 'staging-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[sfrench/cifs-2.6.git] / drivers / staging / vc04_services / interface / vchiq_arm / vchiq_arm.h
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
4  * Copyright (c) 2010-2012 Broadcom. All rights reserved.
5  */
6
7 #ifndef VCHIQ_ARM_H
8 #define VCHIQ_ARM_H
9
10 #include <linux/mutex.h>
11 #include <linux/platform_device.h>
12 #include <linux/semaphore.h>
13 #include <linux/atomic.h>
14 #include "vchiq_core.h"
15 #include "vchiq_debugfs.h"
16
17 /* Some per-instance constants */
18 #define MAX_COMPLETIONS 128
19 #define MAX_SERVICES 64
20 #define MAX_ELEMENTS 8
21 #define MSG_QUEUE_SIZE 128
22
23 enum USE_TYPE_E {
24         USE_TYPE_SERVICE,
25         USE_TYPE_VCHIQ
26 };
27
28 struct user_service {
29         struct vchiq_service *service;
30         void __user *userdata;
31         struct vchiq_instance *instance;
32         char is_vchi;
33         char dequeue_pending;
34         char close_pending;
35         int message_available_pos;
36         int msg_insert;
37         int msg_remove;
38         struct completion insert_event;
39         struct completion remove_event;
40         struct completion close_event;
41         struct vchiq_header *msg_queue[MSG_QUEUE_SIZE];
42 };
43
44 struct bulk_waiter_node {
45         struct bulk_waiter bulk_waiter;
46         int pid;
47         struct list_head list;
48 };
49
50 struct vchiq_instance {
51         struct vchiq_state *state;
52         struct vchiq_completion_data_kernel completions[MAX_COMPLETIONS];
53         int completion_insert;
54         int completion_remove;
55         struct completion insert_event;
56         struct completion remove_event;
57         struct mutex completion_mutex;
58
59         int connected;
60         int closing;
61         int pid;
62         int mark;
63         int use_close_delivered;
64         int trace;
65
66         struct list_head bulk_waiter_list;
67         struct mutex bulk_waiter_list_mutex;
68
69         struct vchiq_debugfs_node debugfs_node;
70 };
71
72 extern spinlock_t msg_queue_spinlock;
73 extern struct vchiq_state g_state;
74
75 extern struct vchiq_state *
76 vchiq_get_state(void);
77
78 int
79 vchiq_use_service(struct vchiq_instance *instance, unsigned int handle);
80
81 extern int
82 vchiq_release_service(struct vchiq_instance *instance, unsigned int handle);
83
84 extern int
85 vchiq_check_service(struct vchiq_service *service);
86
87 extern void
88 vchiq_dump_platform_use_state(struct vchiq_state *state);
89
90 extern void
91 vchiq_dump_service_use_state(struct vchiq_state *state);
92
93 extern int
94 vchiq_use_internal(struct vchiq_state *state, struct vchiq_service *service,
95                    enum USE_TYPE_E use_type);
96 extern int
97 vchiq_release_internal(struct vchiq_state *state,
98                        struct vchiq_service *service);
99
100 extern struct vchiq_debugfs_node *
101 vchiq_instance_get_debugfs_node(struct vchiq_instance *instance);
102
103 extern int
104 vchiq_instance_get_use_count(struct vchiq_instance *instance);
105
106 extern int
107 vchiq_instance_get_pid(struct vchiq_instance *instance);
108
109 extern int
110 vchiq_instance_get_trace(struct vchiq_instance *instance);
111
112 extern void
113 vchiq_instance_set_trace(struct vchiq_instance *instance, int trace);
114
115 #if IS_ENABLED(CONFIG_VCHIQ_CDEV)
116
117 extern void
118 vchiq_deregister_chrdev(void);
119
120 extern int
121 vchiq_register_chrdev(struct device *parent);
122
123 #else
124
125 static inline void vchiq_deregister_chrdev(void) { }
126 static inline int vchiq_register_chrdev(struct device *parent) { return 0; }
127
128 #endif /* IS_ENABLED(CONFIG_VCHIQ_CDEV) */
129
130 extern int
131 service_callback(struct vchiq_instance *vchiq_instance, enum vchiq_reason reason,
132                  struct vchiq_header *header, unsigned int handle, void *bulk_userdata);
133
134 extern void
135 free_bulk_waiter(struct vchiq_instance *instance);
136
137 #endif /* VCHIQ_ARM_H */