1 /*
2  * Copyright (c) 2018,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  * This file provides OS dependent device related APIs
22  */
23 
24 #include "qdf_dev.h"
25 #include "qdf_mem.h"
26 #include "qdf_util.h"
27 #include "qdf_module.h"
28 #include <linux/irq.h>
29 
30 QDF_STATUS
qdf_dev_alloc_mem(struct qdf_dev * qdfdev,struct qdf_devm ** mrptr,uint32_t reqsize,uint32_t mask)31 qdf_dev_alloc_mem(struct qdf_dev *qdfdev, struct qdf_devm **mrptr,
32 		  uint32_t reqsize, uint32_t mask)
33 {
34 	struct qdf_devm *mptr;
35 
36 	if (!qdfdev)
37 		return QDF_STATUS_E_INVAL;
38 
39 	mptr = devm_kzalloc((struct device *)qdfdev, reqsize, mask);
40 
41 	if (!mrptr)
42 		return QDF_STATUS_E_NOMEM;
43 
44 	*mrptr = mptr;
45 
46 	return QDF_STATUS_SUCCESS;
47 }
48 
49 qdf_export_symbol(qdf_dev_alloc_mem);
50 
51 QDF_STATUS
qdf_dev_release_mem(struct qdf_dev * qdfdev,struct qdf_devm * mrptr)52 qdf_dev_release_mem(struct qdf_dev *qdfdev, struct qdf_devm *mrptr)
53 {
54 	if (!mrptr)
55 		return QDF_STATUS_E_INVAL;
56 
57 	devm_kfree((struct device *)qdfdev, mrptr);
58 
59 	return QDF_STATUS_SUCCESS;
60 }
61 
62 qdf_export_symbol(qdf_dev_release_mem);
63 
64 QDF_STATUS
qdf_dev_modify_irq_status(uint32_t irnum,unsigned long cmask,unsigned long smask)65 qdf_dev_modify_irq_status(uint32_t irnum, unsigned long cmask,
66 			  unsigned long smask)
67 {
68 	if (irnum <= 0)
69 		return QDF_STATUS_E_INVAL;
70 
71 	irq_modify_status(irnum, cmask, smask);
72 
73 	return QDF_STATUS_SUCCESS;
74 }
75 
76 qdf_export_symbol(qdf_dev_modify_irq_status);
77 
78 QDF_STATUS
qdf_dev_set_irq_affinity(uint32_t irnum,struct qdf_cpu_mask * cpmask)79 qdf_dev_set_irq_affinity(uint32_t irnum, struct qdf_cpu_mask *cpmask)
80 {
81 	int ret;
82 
83 	if (irnum <= 0)
84 		return QDF_STATUS_E_INVAL;
85 
86 	ret = irq_set_affinity_hint(irnum, (struct cpumask *)cpmask);
87 
88 	return qdf_status_from_os_return(ret);
89 }
90 
91 qdf_export_symbol(qdf_dev_set_irq_affinity);
92 
93 #ifdef ENHANCED_OS_ABSTRACTION
94 QDF_STATUS
qdf_dev_set_irq_status_flags(unsigned int irnum,unsigned long set)95 qdf_dev_set_irq_status_flags(unsigned int irnum, unsigned long set)
96 {
97 	if (irnum <= 0)
98 		return QDF_STATUS_E_INVAL;
99 
100 	irq_set_status_flags(irnum, set);
101 
102 	return QDF_STATUS_SUCCESS;
103 }
104 
105 qdf_export_symbol(qdf_dev_set_irq_status_flags);
106 
107 QDF_STATUS
qdf_dev_clear_irq_status_flags(unsigned int irnum,unsigned long clr)108 qdf_dev_clear_irq_status_flags(unsigned int irnum, unsigned long clr)
109 {
110 	if (irnum <= 0)
111 		return QDF_STATUS_E_INVAL;
112 
113 	irq_clear_status_flags(irnum, clr);
114 
115 	return QDF_STATUS_SUCCESS;
116 }
117 
118 qdf_export_symbol(qdf_dev_clear_irq_status_flags);
119 #endif
120