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