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 enum USE_TYPE_E {
18 	USE_TYPE_SERVICE,
19 	USE_TYPE_VCHIQ
20 };
21 
22 struct vchiq_arm_state {
23 	/* Keepalive-related data */
24 	struct task_struct *ka_thread;
25 	struct completion ka_evt;
26 	atomic_t ka_use_count;
27 	atomic_t ka_use_ack_count;
28 	atomic_t ka_release_count;
29 
30 	rwlock_t susp_res_lock;
31 
32 	struct vchiq_state *state;
33 
34 	/*
35 	 * Global use count for videocore.
36 	 * This is equal to the sum of the use counts for all services.  When
37 	 * this hits zero the videocore suspend procedure will be initiated.
38 	 */
39 	int videocore_use_count;
40 
41 	/*
42 	 * Use count to track requests from videocore peer.
43 	 * This use count is not associated with a service, so needs to be
44 	 * tracked separately with the state.
45 	 */
46 	int peer_use_count;
47 
48 	/*
49 	 * Flag to indicate that the first vchiq connect has made it through.
50 	 * This means that both sides should be fully ready, and we should
51 	 * be able to suspend after this point.
52 	 */
53 	int first_connect;
54 };
55 
56 struct vchiq_drvdata {
57 	const unsigned int cache_line_size;
58 	struct rpi_firmware *fw;
59 };
60 
61 extern int vchiq_arm_log_level;
62 extern int vchiq_susp_log_level;
63 
64 int vchiq_platform_init(struct platform_device *pdev,
65 			struct vchiq_state *state);
66 
67 extern struct vchiq_state *
68 vchiq_get_state(void);
69 
70 extern void
71 vchiq_arm_init_state(struct vchiq_state *state,
72 		     struct vchiq_arm_state *arm_state);
73 
74 extern void
75 vchiq_check_suspend(struct vchiq_state *state);
76 enum vchiq_status
77 vchiq_use_service(unsigned int handle);
78 
79 extern enum vchiq_status
80 vchiq_release_service(unsigned int handle);
81 
82 extern enum vchiq_status
83 vchiq_check_service(struct vchiq_service *service);
84 
85 extern void
86 vchiq_dump_platform_use_state(struct vchiq_state *state);
87 
88 extern void
89 vchiq_dump_service_use_state(struct vchiq_state *state);
90 
91 extern struct vchiq_arm_state*
92 vchiq_platform_get_arm_state(struct vchiq_state *state);
93 
94 
95 extern enum vchiq_status
96 vchiq_use_internal(struct vchiq_state *state, struct vchiq_service *service,
97 		   enum USE_TYPE_E use_type);
98 extern enum vchiq_status
99 vchiq_release_internal(struct vchiq_state *state,
100 		       struct vchiq_service *service);
101 
102 extern struct vchiq_debugfs_node *
103 vchiq_instance_get_debugfs_node(struct vchiq_instance *instance);
104 
105 extern int
106 vchiq_instance_get_use_count(struct vchiq_instance *instance);
107 
108 extern int
109 vchiq_instance_get_pid(struct vchiq_instance *instance);
110 
111 extern int
112 vchiq_instance_get_trace(struct vchiq_instance *instance);
113 
114 extern void
115 vchiq_instance_set_trace(struct vchiq_instance *instance, int trace);
116 
117 #endif /* VCHIQ_ARM_H */
118