1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
3 * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
4 * Copyright (c) 2010-2012 Broadcom. All rights reserved.
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"
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
23 #define VCHIQ_DRV_MAX_CALLBACKS 10
33 struct vchiq_platform_info {
34 unsigned int cache_line_size;
37 struct vchiq_drv_mgmt {
38 struct rpi_firmware *fw;
39 const struct vchiq_platform_info *info;
42 int num_deferred_callbacks;
43 /* Protects connected and num_deferred_callbacks */
44 struct mutex connected_mutex;
46 void (*deferred_callback[VCHIQ_DRV_MAX_CALLBACKS])(void);
48 struct semaphore free_fragments_sema;
49 struct semaphore free_fragments_mutex;
52 unsigned int fragments_size;
56 struct vchiq_state state;
60 struct vchiq_service *service;
61 void __user *userdata;
62 struct vchiq_instance *instance;
66 int message_available_pos;
69 struct completion insert_event;
70 struct completion remove_event;
71 struct completion close_event;
72 struct vchiq_header *msg_queue[MSG_QUEUE_SIZE];
75 struct bulk_waiter_node {
76 struct bulk_waiter bulk_waiter;
78 struct list_head list;
81 struct vchiq_instance {
82 struct vchiq_state *state;
83 struct vchiq_completion_data_kernel completions[MAX_COMPLETIONS];
84 int completion_insert;
85 int completion_remove;
86 struct completion insert_event;
87 struct completion remove_event;
88 struct mutex completion_mutex;
94 int use_close_delivered;
97 struct list_head bulk_waiter_list;
98 struct mutex bulk_waiter_list_mutex;
100 struct vchiq_debugfs_node debugfs_node;
104 vchiq_use_service(struct vchiq_instance *instance, unsigned int handle);
107 vchiq_release_service(struct vchiq_instance *instance, unsigned int handle);
110 vchiq_check_service(struct vchiq_service *service);
113 vchiq_dump_service_use_state(struct vchiq_state *state);
116 vchiq_use_internal(struct vchiq_state *state, struct vchiq_service *service,
117 enum USE_TYPE_E use_type);
119 vchiq_release_internal(struct vchiq_state *state,
120 struct vchiq_service *service);
122 extern struct vchiq_debugfs_node *
123 vchiq_instance_get_debugfs_node(struct vchiq_instance *instance);
126 vchiq_instance_get_use_count(struct vchiq_instance *instance);
129 vchiq_instance_get_pid(struct vchiq_instance *instance);
132 vchiq_instance_get_trace(struct vchiq_instance *instance);
135 vchiq_instance_set_trace(struct vchiq_instance *instance, int trace);
138 vchiq_add_connected_callback(struct vchiq_device *device,
139 void (*callback)(void));
141 #if IS_ENABLED(CONFIG_VCHIQ_CDEV)
144 vchiq_deregister_chrdev(void);
147 vchiq_register_chrdev(struct device *parent);
151 static inline void vchiq_deregister_chrdev(void) { }
152 static inline int vchiq_register_chrdev(struct device *parent) { return 0; }
154 #endif /* IS_ENABLED(CONFIG_VCHIQ_CDEV) */
157 service_callback(struct vchiq_instance *vchiq_instance, enum vchiq_reason reason,
158 struct vchiq_header *header, unsigned int handle, void *bulk_userdata);
161 free_bulk_waiter(struct vchiq_instance *instance);
163 #endif /* VCHIQ_ARM_H */