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