1 /* 2 * Copyright (c) 2019-2021 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /** 20 * DOC: qdf_dev 21 * QCA driver framework (QDF) device management APIs 22 */ 23 24 #if !defined(__I_QDF_DEV_H) 25 #define __I_QDF_DEV_H 26 27 /* Include Files */ 28 #include <qdf_types.h> 29 #include "qdf_util.h" 30 #include <linux/irq.h> 31 #ifdef CONFIG_SCHED_CORE_CTL 32 #include <linux/sched/core_ctl.h> 33 #endif 34 35 struct qdf_cpu_mask; 36 struct qdf_devm; 37 struct qdf_dev; 38 39 #define __qdf_cpumask_pr_args(maskp) cpumask_pr_args(maskp) 40 #define __qdf_for_each_possible_cpu(cpu) for_each_possible_cpu(cpu) 41 #define __qdf_for_each_online_cpu(cpu) for_each_online_cpu(cpu) 42 #define __qdf_for_each_cpu(cpu, maskp) \ 43 for_each_cpu(cpu, maskp) 44 #define __qdf_for_each_cpu_not(cpu, maskp) \ 45 for_each_cpu_not(cpu, maskp) 46 47 /** 48 * __qdf_dev_alloc_mem() - allocate memory 49 * @qdfdev: Device handle 50 * @mrptr: Pointer to the allocated memory 51 * @reqsize: Allocation request in bytes 52 * @mask: Property mask to be associated to the allocated memory 53 * 54 * This function will acquire memory to be associated with a device 55 * 56 * Return: QDF_STATUS_SUCCESS on success 57 */ 58 static inline QDF_STATUS 59 __qdf_dev_alloc_mem(struct qdf_dev *qdfdev, struct qdf_devm **mrptr, 60 uint32_t reqsize, uint32_t mask) 61 { 62 *mrptr = devm_kzalloc((struct device *)qdfdev, reqsize, mask); 63 64 if (!*mrptr) 65 return QDF_STATUS_E_NOMEM; 66 67 return QDF_STATUS_SUCCESS; 68 } 69 70 /** 71 * __qdf_dev_release_mem() - release memory 72 * @qdfdev: Device handle 73 * @mrptr: Pointer to the allocated memory 74 * 75 * This function will acquire memory to be associated with a device 76 * 77 * Return: QDF_STATUS_SUCCESS on success 78 */ 79 static inline QDF_STATUS 80 __qdf_dev_release_mem(struct qdf_dev *qdfdev, struct qdf_devm *mrptr) 81 { 82 devm_kfree((struct device *)qdfdev, mrptr); 83 84 return QDF_STATUS_SUCCESS; 85 } 86 87 /** 88 * __qdf_dev_modify_irq() - modify irq 89 * @irnum: irq number 90 * @cmask: Bitmap to be cleared for the property mask 91 * @smask: Bitmap to be set for the property mask 92 * 93 * This function will modify the properties of the irq associated with a device 94 * 95 * Return: QDF_STATUS_SUCCESS on success 96 */ 97 static inline QDF_STATUS 98 __qdf_dev_modify_irq_status(uint32_t irnum, unsigned long cmask, 99 unsigned long smask) 100 { 101 irq_modify_status(irnum, cmask, smask); 102 103 return QDF_STATUS_SUCCESS; 104 } 105 106 /** 107 * __qdf_dev_set_irq_affinity() - set irq affinity 108 * @irnum: irq number 109 * @cpmask: cpu affinity bitmap 110 * 111 * This function will set the affinity level for an irq 112 * 113 * Return: QDF_STATUS_SUCCESS on success 114 */ 115 static inline QDF_STATUS 116 __qdf_dev_set_irq_affinity(uint32_t irnum, struct qdf_cpu_mask *cpmask) 117 { 118 int ret; 119 120 ret = irq_set_affinity_hint(irnum, (struct cpumask *)cpmask); 121 return qdf_status_from_os_return(ret); 122 } 123 124 /** 125 * __qdf_topology_physical_package_id() - API to retrieve the 126 * cluster info 127 * @cpu: cpu core 128 * 129 * This function returns the cluster information for give cpu 130 * core 131 * 132 * Return: 1 for perf and 0 for non-perf cluster 133 */ 134 static inline int __qdf_topology_physical_package_id(unsigned int cpu) 135 { 136 return topology_physical_package_id(cpu); 137 } 138 139 /** 140 * __qdf_cpumask_subset() - API to check for subset in cpumasks 141 * @srcp1: first cpu mask 142 * @srcp1: second cpu mask 143 * 144 * This checks for *srcp1 & ~*srcp2 145 * 146 * Return: 1 if srcp1 is subset of srcp2 else 0 147 */ 148 static inline int __qdf_cpumask_subset(qdf_cpu_mask *srcp1, 149 const qdf_cpu_mask *srcp2) 150 { 151 return cpumask_subset(srcp1, srcp2); 152 } 153 154 /** 155 * __qdf_cpumask_intersects() - API to check if cpumasks 156 * intersect 157 * @srcp1: first cpu mask 158 * @srcp1: second cpu mask 159 * 160 * This checks for (*srcp1 & *srcp2) != 0 161 * 162 * Return: 1 if srcp1 and srcp2 intersect else 0 163 */ 164 static inline int __qdf_cpumask_intersects(qdf_cpu_mask *srcp1, 165 const qdf_cpu_mask *srcp2) 166 { 167 return cpumask_intersects(srcp1, srcp2); 168 } 169 170 #ifdef CONFIG_SCHED_CORE_CTL 171 /** 172 * __qdf_core_ctl_set_boost() - This API is used to move tasks 173 * to CPUs with higher capacity 174 * 175 * This function moves tasks to higher capacity CPUs than those 176 * where the tasks would have normally ended up. This is 177 * applicable only to defconfig builds. 178 * 179 * Return: 0 on success 180 */ 181 static inline int __qdf_core_ctl_set_boost(bool boost) 182 { 183 return core_ctl_set_boost(boost); 184 } 185 #else 186 static inline int __qdf_core_ctl_set_boost(bool boost) 187 { 188 return 0; 189 } 190 #endif 191 192 /** 193 * __qdf_dev_set_irq_status_flags() - set irq status flags 194 * @irnum: irq number 195 * @set: status flag to set 196 * 197 * This function will set the status for an irq 198 * 199 * Return: QDF_STATUS_SUCCESS on success 200 */ 201 static inline QDF_STATUS 202 __qdf_dev_set_irq_status_flags(unsigned int irnum, unsigned long set) 203 { 204 irq_set_status_flags(irnum, set); 205 206 return QDF_STATUS_SUCCESS; 207 } 208 209 /** 210 * __qdf_dev_clear_irq_status_flags() - clear irq status flags 211 * @irnum: irq number 212 * @clear: status flag to clear 213 * 214 * This function will set the status for an irq 215 * 216 * Return: QDF_STATUS_SUCCESS on success 217 */ 218 static inline QDF_STATUS 219 __qdf_dev_clear_irq_status_flags(unsigned int irnum, unsigned long clr) 220 { 221 irq_clear_status_flags(irnum, clr); 222 223 return QDF_STATUS_SUCCESS; 224 } 225 226 #endif /* __I_QDF_DEV_H */ 227