Initial cut of the open ath9k htc firmware.
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / target / inc / k2 / intr_api.h
1 #ifndef __INTR_API_H__
2 #define __INTR_API_H__
3
4 /*
5  * Interrupt handler, for application-managed interrupts.
6  * When an interrupt occurs, it is automatically disabled.
7  * See A_WMAC_INTR_ATTACH() and A_MBOX_INTR_ATTACH().
8  *
9  * If a handler returns A_HANDLER_DONE, the interrupt is
10  * re-enabled.  The OS calls the handler next time service
11  * is required.  This is the normal case for a handler.
12  *
13  * If a handler returns A_HANDLER_YIELD, the interrupt
14  * remains masked.  The handler is called again when
15  * it is "convenient".  This gives the OS an opportunity
16  * to run other code/handlers.  A handler should return
17  * A_HANDLER_YIELD if it might dominate the CPU for too
18  * long.
19  *
20  * If a handler returns A_HANDLER_NOENABLE, the interrupt
21  * remains disabled.  It is up to the application to re-enable
22  * the interrupt (via A_*_INTR_UNMASK) when it's appropriate.
23  *
24  * Note that many combinations of interrupt functions and
25  * interrupt vectors are NOT supported: Callers should use
26  * only the macros defined in cmnos_api.h to access the
27  * interrupt API.
28  */
29 #include "cmnos_api.h"
30
31 typedef uint32_t A_old_intr_t;
32
33 //////////////////////////////////////////////////////////////////
34 // this is copied from mercury/cmnos_xtensa.h
35 /*
36  * These are CMNOS interrupt manifest constants.
37  * They have specially-chosen values that align with hardware and or
38  * operating system values (see cmnos_interrupt_info).
39  */
40 #if defined(__XTENSA__)
41 /*
42  * Enumeration of low and medium priority interrupt numbers
43  * which match the CPU hardware configuration:
44  */
45
46 /* XTensa Level 1 interrupt */
47 #define A_INUM_SOFTWARE        0 /* currently unused */
48
49 /* XTensa Level2 interrupts */
50 #define A_INUM_XTTIMER              1  /* Tensilica timer */
51 #define A_INUM_TBD_2                2  /* TBD */
52 #define A_INUM_CPU_WDT              3  /* RST_CPU watchodg interrupt */
53 #define A_INUM_TBD_4                4  /* TBD */
54 #define A_INUM_TBD_5                5  /* TBD */
55 #define A_INUM_TBD_6                6  /* TBD */
56 #define A_INUM_CPU_GEN_TIMER        7  /* CPU general timer */
57 #define A_INUM_TBD_8                8  /* TBD */
58 #define A_INUM_TBD_9                9  /* TBD */
59 #define A_INUM_USB_CTRL             10 /* USB core control */
60 #define A_INUM_USB_DMA              11 /* USB DMA */
61 #define A_INUM_TBD_12               12 /* TBD */
62 #define A_INUM_TBD_13               13 /* TBD */
63 #define A_INUM_TBD_14               14 /* TBD */
64
65 /* Level 3 interrupts */
66 #define A_INUM_ERROR                15 /* Errors (e.g. access illegal address) */
67 #define A_INUM_TBD_16               16 /* TBD */
68 #define A_INUM_MAC                  17 /* MAC */
69
70 /* Level 5 interrupts */
71 #define A_INUM_CPU_NMI              18 /* CPU NMI */
72
73 /* Number of interrupts that map directly into CPU/hal interrupt bits. */
74 #define NUM_DIRECT_INTR             19
75
76 #endif
77 //////////////////////////////////////////////////////////////////
78
79 #define CMNOS_IMASK_XTTIMER         (1<<A_INUM_XTTIMER)
80 #define CMNOS_IMASK_CPU_WDT         (1<<A_INUM_CPU_WDT)
81 #define CMNOS_IMASK_CPU_GEN_TIMER   (1<<A_INUM_CPU_GEN_TIMER)
82 #define CMNOS_IMASK_USB_CTRL        (1<<A_INUM_USB_CTRL)
83 #define CMNOS_IMASK_USB_DMA         (1<<A_INUM_USB_DMA)
84 #define CMNOS_IMASK_ERROR           (1<<A_INUM_ERROR)
85 #define CMNOS_IMASK_MAC             (1<<A_INUM_MAC)
86 #define CMNOS_IMASK_CPU_NMI         (1<<A_INUM_CPU_NMI)
87
88 typedef enum inum_intr {
89         A_INTR_TIMER = 0,
90         A_INTR_USB_CTRL,
91         A_INTR_USB_DMA,
92         A_INTR_ERROR,
93         /* add intr above here */
94         A_INTR_NUM
95 } A_INUM_INTR_T;
96
97 //////////////////////////////////////////////////////////////////
98
99 /*
100  * An interrupt handler, which is a function called in response
101  * to a hardware interrupt, possibly as a Delayed Service Routine.
102  */
103 typedef int (* A_handler_t)(void *);
104 /* Return values from a handler/DSR, A_handler_t */
105 #define A_HANDLER_NOENABLE   0   /* do not re-enable interrupts */
106 #define A_HANDLER_DONE       1   /* all intrs handled, call on next intr */
107 #define A_HANDLER_YIELD      2   /* leave intrs disabled and
108                                     call back later regardless of intr state */
109
110 /*
111  * An Interrupt Service Routine, which must be called
112  * directly in interrupt context (not delayed), and which
113  * must be very small and may not have access to all OS
114  * functions.  These are for use only when interrupt
115  * latency is critical; otherwise, an A_handler_t ("dsr")
116  * is preferable.
117  */
118 typedef uint32_t (* A_isr_t)(void *);
119 /* Return values from an ISR */
120 #if defined(CYG_ISR_HANDLED)
121 #define A_ISR_HANDLED        CYG_ISR_HANDLED
122 #define A_ISR_CALL_DSR       CYG_ISR_CALL_DSR
123 #else
124 #define A_ISR_HANDLED        1
125 #define A_ISR_CALL_DSR       2
126 #endif
127
128 struct intr_api {
129         void (*_intr_init)(void);
130         uint32_t (* _intr_invoke_isr)(uint32_t inum);
131         A_old_intr_t(* _intr_disable)(void);
132         void (* _intr_restore)(A_old_intr_t);
133
134         void (* _intr_mask_inum)(uint32_t inum);
135         void (* _intr_unmask_inum)(uint32_t inum);
136         void (* _intr_attach_isr)(uint32_t inum, A_isr_t isr, void *arg);
137         /* Low-level interrupt access, intended for use by OS modules */
138         unsigned int (* _get_intrenable)(void);
139         void (* _set_intrenable)(unsigned int);
140         unsigned int (* _get_intrpending)(void);
141         void (* _unblock_all_intrlvl)(void);
142 };
143
144 #endif /* __INTR_API_H__ */