1371ebdbeSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
23baad68aSGreg Kroah-Hartman /*
371bad7f0Spopcornmix  * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
471bad7f0Spopcornmix  * Copyright (c) 2010-2012 Broadcom. All rights reserved.
571bad7f0Spopcornmix  */
671bad7f0Spopcornmix 
771bad7f0Spopcornmix #ifndef VCHIQ_ARM_H
871bad7f0Spopcornmix #define VCHIQ_ARM_H
971bad7f0Spopcornmix 
1071bad7f0Spopcornmix #include <linux/mutex.h>
1171bad7f0Spopcornmix #include <linux/platform_device.h>
1271bad7f0Spopcornmix #include <linux/semaphore.h>
1371bad7f0Spopcornmix #include <linux/atomic.h>
1471bad7f0Spopcornmix #include "vchiq_core.h"
1571bad7f0Spopcornmix #include "vchiq_debugfs.h"
1671bad7f0Spopcornmix 
17c405028fSOjaswin Mujoo /* Some per-instance constants */
18c405028fSOjaswin Mujoo #define MAX_COMPLETIONS 128
19c405028fSOjaswin Mujoo #define MAX_SERVICES 64
20c405028fSOjaswin Mujoo #define MAX_ELEMENTS 8
21c405028fSOjaswin Mujoo #define MSG_QUEUE_SIZE 128
22c405028fSOjaswin Mujoo 
2371bad7f0Spopcornmix enum USE_TYPE_E {
2471bad7f0Spopcornmix 	USE_TYPE_SERVICE,
2571bad7f0Spopcornmix 	USE_TYPE_VCHIQ
2671bad7f0Spopcornmix };
2771bad7f0Spopcornmix 
28c405028fSOjaswin Mujoo struct user_service {
29c405028fSOjaswin Mujoo 	struct vchiq_service *service;
30c405028fSOjaswin Mujoo 	void __user *userdata;
31c405028fSOjaswin Mujoo 	struct vchiq_instance *instance;
32c405028fSOjaswin Mujoo 	char is_vchi;
33c405028fSOjaswin Mujoo 	char dequeue_pending;
34c405028fSOjaswin Mujoo 	char close_pending;
35c405028fSOjaswin Mujoo 	int message_available_pos;
36c405028fSOjaswin Mujoo 	int msg_insert;
37c405028fSOjaswin Mujoo 	int msg_remove;
38c405028fSOjaswin Mujoo 	struct completion insert_event;
39c405028fSOjaswin Mujoo 	struct completion remove_event;
40c405028fSOjaswin Mujoo 	struct completion close_event;
41c405028fSOjaswin Mujoo 	struct vchiq_header *msg_queue[MSG_QUEUE_SIZE];
42c405028fSOjaswin Mujoo };
43c405028fSOjaswin Mujoo 
44c405028fSOjaswin Mujoo struct bulk_waiter_node {
45c405028fSOjaswin Mujoo 	struct bulk_waiter bulk_waiter;
46c405028fSOjaswin Mujoo 	int pid;
47c405028fSOjaswin Mujoo 	struct list_head list;
48c405028fSOjaswin Mujoo };
49c405028fSOjaswin Mujoo 
50c405028fSOjaswin Mujoo struct vchiq_instance {
51c405028fSOjaswin Mujoo 	struct vchiq_state *state;
52c405028fSOjaswin Mujoo 	struct vchiq_completion_data_kernel completions[MAX_COMPLETIONS];
53c405028fSOjaswin Mujoo 	int completion_insert;
54c405028fSOjaswin Mujoo 	int completion_remove;
55c405028fSOjaswin Mujoo 	struct completion insert_event;
56c405028fSOjaswin Mujoo 	struct completion remove_event;
57c405028fSOjaswin Mujoo 	struct mutex completion_mutex;
58c405028fSOjaswin Mujoo 
59c405028fSOjaswin Mujoo 	int connected;
60c405028fSOjaswin Mujoo 	int closing;
61c405028fSOjaswin Mujoo 	int pid;
62c405028fSOjaswin Mujoo 	int mark;
63c405028fSOjaswin Mujoo 	int use_close_delivered;
64c405028fSOjaswin Mujoo 	int trace;
65c405028fSOjaswin Mujoo 
66c405028fSOjaswin Mujoo 	struct list_head bulk_waiter_list;
67c405028fSOjaswin Mujoo 	struct mutex bulk_waiter_list_mutex;
68c405028fSOjaswin Mujoo 
69c405028fSOjaswin Mujoo 	struct vchiq_debugfs_node debugfs_node;
70c405028fSOjaswin Mujoo };
71c405028fSOjaswin Mujoo 
72c405028fSOjaswin Mujoo struct dump_context {
73c405028fSOjaswin Mujoo 	char __user *buf;
74c405028fSOjaswin Mujoo 	size_t actual;
75c405028fSOjaswin Mujoo 	size_t space;
76c405028fSOjaswin Mujoo 	loff_t offset;
77c405028fSOjaswin Mujoo };
78c405028fSOjaswin Mujoo 
7971bad7f0Spopcornmix extern int vchiq_arm_log_level;
8071bad7f0Spopcornmix extern int vchiq_susp_log_level;
8171bad7f0Spopcornmix 
82c405028fSOjaswin Mujoo extern spinlock_t msg_queue_spinlock;
83c405028fSOjaswin Mujoo extern struct vchiq_state g_state;
84c405028fSOjaswin Mujoo 
852d0a0291SDominic Braun extern struct vchiq_state *
8671bad7f0Spopcornmix vchiq_get_state(void);
8771bad7f0Spopcornmix 
8800d36494SJamal Shareef int
8914780bb1SAdrien Thierry vchiq_use_service(struct vchiq_instance *instance, unsigned int handle);
9071bad7f0Spopcornmix 
9100d36494SJamal Shareef extern int
9214780bb1SAdrien Thierry vchiq_release_service(struct vchiq_instance *instance, unsigned int handle);
9371bad7f0Spopcornmix 
9400d36494SJamal Shareef extern int
957926c328SDominic Braun vchiq_check_service(struct vchiq_service *service);
9671bad7f0Spopcornmix 
9771bad7f0Spopcornmix extern void
982d0a0291SDominic Braun vchiq_dump_platform_use_state(struct vchiq_state *state);
9971bad7f0Spopcornmix 
10071bad7f0Spopcornmix extern void
1012d0a0291SDominic Braun vchiq_dump_service_use_state(struct vchiq_state *state);
10271bad7f0Spopcornmix 
103*7d832993SArnd Bergmann extern int
1042d0a0291SDominic Braun vchiq_use_internal(struct vchiq_state *state, struct vchiq_service *service,
10571bad7f0Spopcornmix 		   enum USE_TYPE_E use_type);
106*7d832993SArnd Bergmann extern int
1072d0a0291SDominic Braun vchiq_release_internal(struct vchiq_state *state,
1082d0a0291SDominic Braun 		       struct vchiq_service *service);
10971bad7f0Spopcornmix 
110aa987e55SDominic Braun extern struct vchiq_debugfs_node *
1114ddf9a25SJamal Shareef vchiq_instance_get_debugfs_node(struct vchiq_instance *instance);
11271bad7f0Spopcornmix 
11371bad7f0Spopcornmix extern int
1144ddf9a25SJamal Shareef vchiq_instance_get_use_count(struct vchiq_instance *instance);
11571bad7f0Spopcornmix 
11671bad7f0Spopcornmix extern int
1174ddf9a25SJamal Shareef vchiq_instance_get_pid(struct vchiq_instance *instance);
11871bad7f0Spopcornmix 
11971bad7f0Spopcornmix extern int
1204ddf9a25SJamal Shareef vchiq_instance_get_trace(struct vchiq_instance *instance);
12171bad7f0Spopcornmix 
12271bad7f0Spopcornmix extern void
1234ddf9a25SJamal Shareef vchiq_instance_set_trace(struct vchiq_instance *instance, int trace);
12471bad7f0Spopcornmix 
1252b5930fbSOjaswin Mujoo #if IS_ENABLED(CONFIG_VCHIQ_CDEV)
1262b5930fbSOjaswin Mujoo 
127c405028fSOjaswin Mujoo extern void
128c405028fSOjaswin Mujoo vchiq_deregister_chrdev(void);
129c405028fSOjaswin Mujoo 
130c405028fSOjaswin Mujoo extern int
131c405028fSOjaswin Mujoo vchiq_register_chrdev(struct device *parent);
132c405028fSOjaswin Mujoo 
1332b5930fbSOjaswin Mujoo #else
1342b5930fbSOjaswin Mujoo 
vchiq_deregister_chrdev(void)1352b5930fbSOjaswin Mujoo static inline void vchiq_deregister_chrdev(void) { }
vchiq_register_chrdev(struct device * parent)1362b5930fbSOjaswin Mujoo static inline int vchiq_register_chrdev(struct device *parent) { return 0; }
1372b5930fbSOjaswin Mujoo 
1382b5930fbSOjaswin Mujoo #endif /* IS_ENABLED(CONFIG_VCHIQ_CDEV) */
1392b5930fbSOjaswin Mujoo 
140c405028fSOjaswin Mujoo extern int
141726e79f8SAdrien Thierry service_callback(struct vchiq_instance *vchiq_instance, enum vchiq_reason reason,
142726e79f8SAdrien Thierry 		 struct vchiq_header *header, unsigned int handle, void *bulk_userdata);
143c405028fSOjaswin Mujoo 
144c405028fSOjaswin Mujoo extern void
145c405028fSOjaswin Mujoo free_bulk_waiter(struct vchiq_instance *instance);
146c405028fSOjaswin Mujoo 
14771bad7f0Spopcornmix #endif /* VCHIQ_ARM_H */
148