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