xref: /wlan-dirver/qca-wifi-host-cmn/hif/src/hif_io32.h (revision a4b8d357569709a7889c418ba927c180e2cd45dc)
1 /*
2  * Copyright (c) 2015-2017 The Linux Foundation. All rights reserved.
3  *
4  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5  *
6  *
7  * Permission to use, copy, modify, and/or distribute this software for
8  * any purpose with or without fee is hereby granted, provided that the
9  * above copyright notice and this permission notice appear in all
10  * copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19  * PERFORMANCE OF THIS SOFTWARE.
20  */
21 
22 /*
23  * This file was originally distributed by Qualcomm Atheros, Inc.
24  * under proprietary terms before Copyright ownership was assigned
25  * to the Linux Foundation.
26  */
27 
28 #ifndef __HIF_IO32_H__
29 #define __HIF_IO32_H__
30 
31 #include <linux/io.h>
32 #include "hif.h"
33 #include "hif_main.h"
34 
35 #define hif_read32_mb(addr)         ioread32((void __iomem *)addr)
36 #define hif_write32_mb(addr, value) \
37 	iowrite32((u32)(value), (void __iomem *)(addr))
38 
39 #define Q_TARGET_ACCESS_BEGIN(scn) \
40 	hif_target_sleep_state_adjust(scn, false, true)
41 #define Q_TARGET_ACCESS_END(scn) \
42 	hif_target_sleep_state_adjust(scn, true, false)
43 
44 /*
45  * A_TARGET_ACCESS_LIKELY will not wait for the target to wake up before
46  * continuing execution.  Because A_TARGET_ACCESS_LIKELY does not guarantee
47  * that the target is awake before continuing, Q_TARGET_ACCESS macros must
48  * protect the actual target access.  Since Q_TARGET_ACCESS protect the actual
49  * target access, A_TARGET_ACCESS_LIKELY hints are optional.
50  *
51  * To ignore "LIKELY" hints, set CONFIG_TARGET_ACCESS_LIKELY to 0
52  * (slightly worse performance, less power)
53  *
54  * To use "LIKELY" hints, set CONFIG_TARGET_ACCESS_LIKELY to 1
55  * (slightly better performance, more power)
56  *
57  * note: if a bus doesn't use hif_target_sleep_state_adjust, this will have
58  * no impact.
59  */
60 #define CONFIG_TARGET_ACCESS_LIKELY 0
61 #if CONFIG_TARGET_ACCESS_LIKELY
62 #define A_TARGET_ACCESS_LIKELY(scn) \
63 	hif_target_sleep_state_adjust(scn, false, false)
64 #define A_TARGET_ACCESS_UNLIKELY(scn) \
65 	hif_target_sleep_state_adjust(scn, true, false)
66 #else                           /* CONFIG_ATH_PCIE_ACCESS_LIKELY */
67 #define A_TARGET_ACCESS_LIKELY(scn) \
68 	do { \
69 		unsigned long unused = (unsigned long)(scn); \
70 		unused = unused; \
71 	} while (0)
72 
73 #define A_TARGET_ACCESS_UNLIKELY(scn) \
74 	do { \
75 		unsigned long unused = (unsigned long)(scn); \
76 		unused = unused; \
77 	} while (0)
78 #endif /* CONFIG_ATH_PCIE_ACCESS_LIKELY */
79 
80 
81 #ifdef HIF_PCI
82 #include "hif_io32_pci.h"
83 #endif
84 #ifdef HIF_SNOC
85 #include "hif_io32_snoc.h"
86 #endif /* HIF_PCI */
87 
88 #ifdef CONFIG_IO_MEM_ACCESS_DEBUG
89 uint32_t hif_target_read_checked(struct hif_softc *scn,
90 					uint32_t offset);
91 void hif_target_write_checked(struct hif_softc *scn, uint32_t offset,
92 				     uint32_t value);
93 
94 #define A_TARGET_READ(scn, offset) \
95 	hif_target_read_checked(scn, (offset))
96 #define A_TARGET_WRITE(scn, offset, value) \
97 	hif_target_write_checked(scn, (offset), (value))
98 #else                           /* CONFIG_ATH_PCIE_ACCESS_DEBUG */
99 #define A_TARGET_READ(scn, offset) \
100 	hif_read32_mb(scn->mem + (offset))
101 #define A_TARGET_WRITE(scn, offset, value) \
102 	hif_write32_mb((scn->mem) + (offset), value)
103 #endif
104 
105 void hif_irq_enable(struct hif_softc *scn, int irq_id);
106 void hif_irq_disable(struct hif_softc *scn, int irq_id);
107 
108 #endif /* __HIF_IO32_H__ */
109