2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #if SYSTEM_MODULE_INTR
39 #include "athos_api.h"
43 * Interrupt Service Routine information, one for each interrupt that
44 * is known to the CPU. A single CPU-level interrupt is sometimes used
45 * for multiple interrupts. For example, all GPIO interrupts share a
46 * single "interrupt number" and all low frequency timers share a single
49 * Index into this table is a platform-dependent interrupt A_INUM_* number.
52 A_isr_t isr; /* function to call */
53 void *isr_arg; /* argument to pass */
54 } cmnos_isr_info[NUM_DIRECT_INTR];
58 //int cmnos_invalid_isr_count; /* Track these for debug purposes */
59 LOCAL uint32_t cmnos_enabled_interrupts = 0; /* Shadows enabled interrupts */
62 LOCAL uint32_t cmnos_intr_dummy(void *pParm)
64 // dummy function in case any intr coming calling the null and crash
69 * initialize all interrupt to diable, and setup all callback to dummy function
71 * p.s these are only level2 interrupt
78 // disable all at init
79 cmnos_enabled_interrupts = 0;
81 // install the dummy function
82 for(i=0; i<NUM_DIRECT_INTR; i++)
83 cmnos_isr_info[i].isr = cmnos_intr_dummy;
85 // set intrenable to disable all
86 A_INTR_SET_INTRENABLE(cmnos_enabled_interrupts);
92 cmnos_intr_mask_inum(uint32_t inum)
94 A_old_intr_t old_intr;
98 A_INTR_DISABLE(&old_intr);
99 oldval = A_INTR_GET_INTRENABLE();
100 cmnos_enabled_interrupts &= ~mask;
102 A_INTR_SET_INTRENABLE(oldval);
103 A_INTR_RESTORE(old_intr);
107 cmnos_intr_unmask_inum(uint32_t inum)
109 A_old_intr_t old_intr;
111 int unmask = 1 << inum;
113 A_INTR_DISABLE(&old_intr);
114 oldval = A_INTR_GET_INTRENABLE();
115 cmnos_enabled_interrupts |= unmask;
116 // if (!pending_dsr) {
119 A_INTR_SET_INTRENABLE(oldval);
120 A_INTR_RESTORE(old_intr);
125 cmnos_intr_attach_isr(uint32_t inum, A_isr_t isr, void *arg)
127 A_old_intr_t old_intr;
129 A_ASSERT(inum < NUM_DIRECT_INTR);
130 A_ASSERT(isr != NULL);
132 A_INTR_DISABLE(&old_intr);
134 cmnos_isr_info[inum].isr = isr;
135 cmnos_isr_info[inum].isr_arg = arg;
137 A_INTR_RESTORE(old_intr);
141 * Invoke the ISR corresponding to an interrupt number.
142 * Note that we expect interrupts for the given interrupt
143 * number to be blocked when this function is called. In
144 * fact, current ISRs assume that ALL non-fatal interrupts
145 * are blocked, and this allows the ISRs to avoid excessive
146 * calls to A_INTR_DISABLE/RESTORE which would otherwise be
147 * needed around calls to A_INTR_SET_INTRENABLE and such.
150 cmnos_intr_invoke_isr(uint32_t inum)
152 A_ASSERT(inum < NUM_DIRECT_INTR);
153 A_ASSERT(cmnos_isr_info[inum].isr != NULL);
155 // A_PRINTF("cmnos_intr_invoke_isr %d\n", inum);
157 return cmnos_isr_info[inum].isr(cmnos_isr_info[inum].isr_arg);
161 * NB: Whenever an "inum" is passed to an intr API, it is an A_INUM_*.
164 cmnos_intr_module_install(struct intr_api *tbl)
166 tbl->_intr_init = cmnos_intr_init;
167 tbl->_intr_invoke_isr = cmnos_intr_invoke_isr;
168 tbl->_intr_attach_isr = cmnos_intr_attach_isr;
169 tbl->_intr_mask_inum = cmnos_intr_mask_inum;
170 tbl->_intr_unmask_inum = cmnos_intr_unmask_inum;
173 * Note: These are all supplied elsewhere with platform-specific functions:
174 * tbl->_get_intrenable
175 * tbl->_set_intrenable
176 * tbl->_get_intrpending
177 * tbl->_unblock_all_intrlvl
182 #endif /* SYSTEM_MODULE_INTR */