1 /* 2 * Copyright (c) 2019-2020 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 43 /** 44 * __qdf_dev_alloc_mem() - allocate memory 45 * @qdfdev: Device handle 46 * @mrptr: Pointer to the allocated memory 47 * @reqsize: Allocation request in bytes 48 * @mask: Property mask to be associated to the allocated memory 49 * 50 * This function will acquire memory to be associated with a device 51 * 52 * Return: QDF_STATUS_SUCCESS on success 53 */ 54 static inline QDF_STATUS 55 __qdf_dev_alloc_mem(struct qdf_dev *qdfdev, struct qdf_devm **mrptr, 56 uint32_t reqsize, uint32_t mask) 57 { 58 *mrptr = devm_kzalloc((struct device *)qdfdev, reqsize, mask); 59 60 if (!*mrptr) 61 return QDF_STATUS_E_NOMEM; 62 63 return QDF_STATUS_SUCCESS; 64 } 65 66 /** 67 * __qdf_dev_release_mem() - release memory 68 * @qdfdev: Device handle 69 * @mrptr: Pointer to the allocated memory 70 * 71 * This function will acquire memory to be associated with a device 72 * 73 * Return: QDF_STATUS_SUCCESS on success 74 */ 75 static inline QDF_STATUS 76 __qdf_dev_release_mem(struct qdf_dev *qdfdev, struct qdf_devm *mrptr) 77 { 78 devm_kfree((struct device *)qdfdev, mrptr); 79 80 return QDF_STATUS_SUCCESS; 81 } 82 83 /** 84 * __qdf_dev_modify_irq() - modify irq 85 * @irnum: irq number 86 * @cmask: Bitmap to be cleared for the property mask 87 * @smask: Bitmap to be set for the property mask 88 * 89 * This function will modify the properties of the irq associated with a device 90 * 91 * Return: QDF_STATUS_SUCCESS on success 92 */ 93 static inline QDF_STATUS 94 __qdf_dev_modify_irq_status(uint32_t irnum, unsigned long cmask, 95 unsigned long smask) 96 { 97 irq_modify_status(irnum, cmask, smask); 98 99 return QDF_STATUS_SUCCESS; 100 } 101 102 /** 103 * __qdf_dev_set_irq_affinity() - set irq affinity 104 * @irnum: irq number 105 * @cpmask: cpu affinity bitmap 106 * 107 * This function will set the affinity level for an irq 108 * 109 * Return: QDF_STATUS_SUCCESS on success 110 */ 111 static inline QDF_STATUS 112 __qdf_dev_set_irq_affinity(uint32_t irnum, struct qdf_cpu_mask *cpmask) 113 { 114 int ret; 115 116 ret = irq_set_affinity_hint(irnum, (struct cpumask *)cpmask); 117 return qdf_status_from_os_return(ret); 118 } 119 120 /** 121 * __qdf_topology_physical_package_id() - API to retrieve the 122 * cluster info 123 * @cpu: cpu core 124 * 125 * This function returns the cluster information for give cpu 126 * core 127 * 128 * Return: 1 for perf and 0 for non-perf cluster 129 */ 130 static inline int __qdf_topology_physical_package_id(unsigned int cpu) 131 { 132 return topology_physical_package_id(cpu); 133 } 134 135 /** 136 * __qdf_cpumask_subset() - API to check for subset in cpumasks 137 * @srcp1: first cpu mask 138 * @srcp1: second cpu mask 139 * 140 * This checks for *srcp1 & ~*srcp2 141 * 142 * Return: 1 if srcp1 is subset of srcp2 else 0 143 */ 144 static inline int __qdf_cpumask_subset(qdf_cpu_mask *srcp1, 145 const qdf_cpu_mask *srcp2) 146 { 147 return cpumask_subset(srcp1, srcp2); 148 } 149 150 /** 151 * __qdf_cpumask_intersects() - API to check if cpumasks 152 * intersect 153 * @srcp1: first cpu mask 154 * @srcp1: second cpu mask 155 * 156 * This checks for (*srcp1 & *srcp2) != 0 157 * 158 * Return: 1 if srcp1 and srcp2 intersect else 0 159 */ 160 static inline int __qdf_cpumask_intersects(qdf_cpu_mask *srcp1, 161 const qdf_cpu_mask *srcp2) 162 { 163 return cpumask_intersects(srcp1, srcp2); 164 } 165 166 #ifdef CONFIG_SCHED_CORE_CTL 167 /** 168 * __qdf_core_ctl_set_boost() - This API is used to move tasks 169 * to CPUs with higher capacity 170 * 171 * This function moves tasks to higher capacity CPUs than those 172 * where the tasks would have normally ended up. This is 173 * applicable only to defconfig builds. 174 * 175 * Return: 0 on success 176 */ 177 static inline int __qdf_core_ctl_set_boost(bool boost) 178 { 179 return core_ctl_set_boost(boost); 180 } 181 #else 182 static inline int __qdf_core_ctl_set_boost(bool boost) 183 { 184 return 0; 185 } 186 #endif 187 #endif /* __I_QDF_DEV_H */ 188