Deleted Added
full compact
vchiq_arm.h (278277) vchiq_arm.h (290245)
1/**
1/**
2 * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
2 * Copyright (c) 2010-2012 Broadcom. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions, and the following disclaimer,
9 * without modification.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The names of the above-listed copyright holders may not be used
14 * to endorse or promote products derived from this software without
15 * specific prior written permission.
16 *
17 * ALTERNATIVELY, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2, as published by the Free
19 * Software Foundation.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef VCHIQ_ARM_H
35#define VCHIQ_ARM_H
36
37#include "vchiq_core.h"
38
39
40enum vc_suspend_status {
41 VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
42 VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
43 VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
44 VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
45 VC_SUSPEND_REQUESTED, /* User has requested suspend */
46 VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
47 VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
48};
49
50enum vc_resume_status {
51 VC_RESUME_FAILED = -1, /* Videocore resume failed */
52 VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
53 VC_RESUME_REQUESTED, /* User has requested resume */
54 VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
55 VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
56};
57
58
59enum USE_TYPE_E {
60 USE_TYPE_SERVICE,
61 USE_TYPE_SERVICE_NO_RESUME,
62 USE_TYPE_VCHIQ
63};
64
65
66
67typedef struct vchiq_arm_state_struct {
68 /* Keepalive-related data */
69 VCHIQ_THREAD_T ka_thread;
70 struct completion ka_evt;
71 atomic_t ka_use_count;
72 atomic_t ka_use_ack_count;
73 atomic_t ka_release_count;
74
75 struct completion vc_suspend_complete;
76 struct completion vc_resume_complete;
77
78 rwlock_t susp_res_lock;
79 enum vc_suspend_status vc_suspend_state;
80 enum vc_resume_status vc_resume_state;
81
82 unsigned int wake_address;
83
84 struct timer_list suspend_timer;
85 int suspend_timer_timeout;
86 int suspend_timer_running;
87
88 /* Global use count for videocore.
89 ** This is equal to the sum of the use counts for all services. When
90 ** this hits zero the videocore suspend procedure will be initiated.
91 */
92 int videocore_use_count;
93
94 /* Use count to track requests from videocore peer.
95 ** This use count is not associated with a service, so needs to be
96 ** tracked separately with the state.
97 */
98 int peer_use_count;
99
100 /* Flag to indicate whether resume is blocked. This happens when the
101 ** ARM is suspending
102 */
103 struct completion resume_blocker;
104 int resume_blocked;
105 struct completion blocked_blocker;
106 int blocked_count;
107
108 int autosuspend_override;
109
110 /* Flag to indicate that the first vchiq connect has made it through.
111 ** This means that both sides should be fully ready, and we should
112 ** be able to suspend after this point.
113 */
114 int first_connect;
115
116 unsigned long long suspend_start_time;
117 unsigned long long sleep_start_time;
118 unsigned long long resume_start_time;
119 unsigned long long last_wake_time;
120
121} VCHIQ_ARM_STATE_T;
122
123extern int vchiq_arm_log_level;
124extern int vchiq_susp_log_level;
125
126extern int __init
127vchiq_platform_init(VCHIQ_STATE_T *state);
128
129extern void __exit
130vchiq_platform_exit(VCHIQ_STATE_T *state);
131
132extern VCHIQ_STATE_T *
133vchiq_get_state(void);
134
135extern VCHIQ_STATUS_T
136vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
137
138extern VCHIQ_STATUS_T
139vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
140
141extern int
142vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
143
144extern VCHIQ_STATUS_T
145vchiq_arm_vcresume(VCHIQ_STATE_T *state);
146
147extern VCHIQ_STATUS_T
148vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
149
150extern int
151vchiq_check_resume(VCHIQ_STATE_T *state);
152
153extern void
154vchiq_check_suspend(VCHIQ_STATE_T *state);
155
3 * Copyright (c) 2010-2012 Broadcom. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The names of the above-listed copyright holders may not be used
15 * to endorse or promote products derived from this software without
16 * specific prior written permission.
17 *
18 * ALTERNATIVELY, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") version 2, as published by the Free
20 * Software Foundation.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#ifndef VCHIQ_ARM_H
36#define VCHIQ_ARM_H
37
38#include "vchiq_core.h"
39
40
41enum vc_suspend_status {
42 VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
43 VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
44 VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
45 VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
46 VC_SUSPEND_REQUESTED, /* User has requested suspend */
47 VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
48 VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
49};
50
51enum vc_resume_status {
52 VC_RESUME_FAILED = -1, /* Videocore resume failed */
53 VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
54 VC_RESUME_REQUESTED, /* User has requested resume */
55 VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
56 VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
57};
58
59
60enum USE_TYPE_E {
61 USE_TYPE_SERVICE,
62 USE_TYPE_SERVICE_NO_RESUME,
63 USE_TYPE_VCHIQ
64};
65
66
67
68typedef struct vchiq_arm_state_struct {
69 /* Keepalive-related data */
70 VCHIQ_THREAD_T ka_thread;
71 struct completion ka_evt;
72 atomic_t ka_use_count;
73 atomic_t ka_use_ack_count;
74 atomic_t ka_release_count;
75
76 struct completion vc_suspend_complete;
77 struct completion vc_resume_complete;
78
79 rwlock_t susp_res_lock;
80 enum vc_suspend_status vc_suspend_state;
81 enum vc_resume_status vc_resume_state;
82
83 unsigned int wake_address;
84
85 struct timer_list suspend_timer;
86 int suspend_timer_timeout;
87 int suspend_timer_running;
88
89 /* Global use count for videocore.
90 ** This is equal to the sum of the use counts for all services. When
91 ** this hits zero the videocore suspend procedure will be initiated.
92 */
93 int videocore_use_count;
94
95 /* Use count to track requests from videocore peer.
96 ** This use count is not associated with a service, so needs to be
97 ** tracked separately with the state.
98 */
99 int peer_use_count;
100
101 /* Flag to indicate whether resume is blocked. This happens when the
102 ** ARM is suspending
103 */
104 struct completion resume_blocker;
105 int resume_blocked;
106 struct completion blocked_blocker;
107 int blocked_count;
108
109 int autosuspend_override;
110
111 /* Flag to indicate that the first vchiq connect has made it through.
112 ** This means that both sides should be fully ready, and we should
113 ** be able to suspend after this point.
114 */
115 int first_connect;
116
117 unsigned long long suspend_start_time;
118 unsigned long long sleep_start_time;
119 unsigned long long resume_start_time;
120 unsigned long long last_wake_time;
121
122} VCHIQ_ARM_STATE_T;
123
124extern int vchiq_arm_log_level;
125extern int vchiq_susp_log_level;
126
127extern int __init
128vchiq_platform_init(VCHIQ_STATE_T *state);
129
130extern void __exit
131vchiq_platform_exit(VCHIQ_STATE_T *state);
132
133extern VCHIQ_STATE_T *
134vchiq_get_state(void);
135
136extern VCHIQ_STATUS_T
137vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
138
139extern VCHIQ_STATUS_T
140vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
141
142extern int
143vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
144
145extern VCHIQ_STATUS_T
146vchiq_arm_vcresume(VCHIQ_STATE_T *state);
147
148extern VCHIQ_STATUS_T
149vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
150
151extern int
152vchiq_check_resume(VCHIQ_STATE_T *state);
153
154extern void
155vchiq_check_suspend(VCHIQ_STATE_T *state);
156
157VCHIQ_STATUS_T
158vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
159
156extern VCHIQ_STATUS_T
157vchiq_platform_suspend(VCHIQ_STATE_T *state);
158
159extern int
160vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
161
162extern int
163vchiq_platform_use_suspend_timer(void);
164
165extern void
166vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
167
168extern void
169vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
170
171extern VCHIQ_ARM_STATE_T*
172vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
173
174extern int
175vchiq_videocore_wanted(VCHIQ_STATE_T *state);
176
177extern VCHIQ_STATUS_T
178vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
179 enum USE_TYPE_E use_type);
180extern VCHIQ_STATUS_T
181vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
182
160extern VCHIQ_STATUS_T
161vchiq_platform_suspend(VCHIQ_STATE_T *state);
162
163extern int
164vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
165
166extern int
167vchiq_platform_use_suspend_timer(void);
168
169extern void
170vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
171
172extern void
173vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
174
175extern VCHIQ_ARM_STATE_T*
176vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
177
178extern int
179vchiq_videocore_wanted(VCHIQ_STATE_T *state);
180
181extern VCHIQ_STATUS_T
182vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
183 enum USE_TYPE_E use_type);
184extern VCHIQ_STATUS_T
185vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
186
183void
187#ifdef notyet
188extern VCHIQ_DEBUGFS_NODE_T *
189vchiq_instance_get_debugfs_node(VCHIQ_INSTANCE_T instance);
190#endif
191
192extern int
193vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance);
194
195extern int
196vchiq_instance_get_pid(VCHIQ_INSTANCE_T instance);
197
198extern int
199vchiq_instance_get_trace(VCHIQ_INSTANCE_T instance);
200
201extern void
202vchiq_instance_set_trace(VCHIQ_INSTANCE_T instance, int trace);
203
204extern void
184set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
185 enum vc_suspend_status new_state);
186
205set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
206 enum vc_suspend_status new_state);
207
187void
208extern void
188set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
189 enum vc_resume_status new_state);
190
209set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
210 enum vc_resume_status new_state);
211
191void
212extern void
192start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
193
213start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
214
194extern int vchiq_proc_init(void);
195extern void vchiq_proc_deinit(void);
196extern struct proc_dir_entry *vchiq_proc_top(void);
197extern struct proc_dir_entry *vchiq_clients_top(void);
198
199
200#endif /* VCHIQ_ARM_H */
215#endif /* VCHIQ_ARM_H */