port-work; won't compile or even work
[ppcskel.git] / irq.h
1 /*
2         ppcskel - a Free Software replacement for the Nintendo/BroadOn IOS.
3         IRQ support
4
5 Copyright (C) 2009              Bernhard Urban <lewurm@gmx.net>
6 Copyright (C) 2009              Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
7
8 # This code is licensed to you under the terms of the GNU GPL, version 2;
9 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
10 */
11
12 #ifndef __IRQ_H__
13 #define __IRQ_H__
14
15 #include "types.h"
16
17 #ifdef CAN_HAZ_IRQ
18 #define IRQ_TIMER       0
19 #define IRQ_NAND        1
20 #define IRQ_AES         2
21 #define IRQ_SHA1        3
22 #define IRQ_EHCI        4
23 #define IRQ_OHCI0       5
24 #define IRQ_OHCI1       6
25 #define IRQ_SDHC        7
26 #define IRQ_WIFI        8
27 #define IRQ_GPIO1B      10
28 #define IRQ_GPIO1       11
29 #define IRQ_RESET       17
30 #define IRQ_PPCIPC      30
31 #define IRQ_IPC         31
32
33 #define IRQF_TIMER      (1<<IRQ_TIMER)
34 #define IRQF_NAND       (1<<IRQ_NAND)
35 #define IRQF_AES        (1<<IRQ_AES)
36 #define IRQF_SDHC       (1<<IRQ_SDHC)
37 #define IRQF_GPIO1B     (1<<IRQ_GPIO1B)
38 #define IRQF_GPIO1      (1<<IRQ_GPIO1)
39 #define IRQF_RESET      (1<<IRQ_RESET)
40 #define IRQF_IPC        (1<<IRQ_IPC)
41 #define IRQF_OHCI0      (1<<IRQ_OHCI0)
42 #define IRQF_OHCI1      (1<<IRQ_OHCI1)
43
44 #define IRQF_ALL        ( \
45         IRQF_TIMER|IRQF_NAND|IRQF_GPIO1B|IRQF_GPIO1| \
46         IRQF_RESET|IRQF_IPC|IRQF_AES|IRQF_SDHC| \
47         IRQF_OHCI0|IRQF_OHCI1 \
48         )
49
50 /* broadway.h? :o */
51 /* broadway processor interface registers */
52 #define BW_PI_IRQFLAG (0x0c003000)
53 #define BW_PI_IRQMASK (0x0c003004)
54
55 // http://hitmen.c02.at/files/yagcd/yagcd/chap5.html#sec5.4
56 #define BW_PI_IRQ_RESET         1
57 #define BW_PI_IRQ_DI            2
58 #define BW_PI_IRQ_SI            3
59 #define BW_PI_IRQ_EXI           4
60 #define BW_PI_IRQ_AI            5
61 #define BW_PI_IRQ_DSP           6
62 #define BW_PI_IRQ_MEM           7
63 #define BW_PI_IRQ_VI            8
64 #define BW_PI_IRQ_PE_TOKEN      9
65 #define BW_PI_IRQ_PE_FINISH     10
66 #define BW_PI_IRQ_CP            11
67 #define BW_PI_IRQ_DEBUG         12
68 #define BW_PI_IRQ_HSP           13
69 #define BW_PI_IRQ_HW            14 //hollywood pic
70
71 /* stolen from libogc - gc/ogc/machine/processor.h */
72 #define _CPU_ISR_Enable() \
73         { register u32 _val = 0; \
74           __asm__ __volatile__ ( \
75                 "mfmsr %0\n" \
76                 "ori %0,%0,0x8000\n" \
77                 "mtmsr %0" \
78                 : "=&r" ((_val)) : "0" ((_val)) \
79           ); \
80         }
81
82 #define _CPU_ISR_Disable( _isr_cookie ) \
83   { register u32 _disable_mask = 0; \
84         _isr_cookie = 0; \
85     __asm__ __volatile__ ( \
86           "mfmsr %0\n" \
87           "rlwinm %1,%0,0,17,15\n" \
88           "mtmsr %1\n" \
89           "extrwi %0,%0,1,16" \
90           : "=&r" ((_isr_cookie)), "=&r" ((_disable_mask)) \
91           : "0" ((_isr_cookie)), "1" ((_disable_mask)) \
92         ); \
93   }
94
95 #define _CPU_ISR_Restore( _isr_cookie )  \
96   { register u32 _enable_mask = 0; \
97         __asm__ __volatile__ ( \
98     "    cmpwi %0,0\n" \
99         "    beq 1f\n" \
100         "    mfmsr %1\n" \
101         "    ori %1,%1,0x8000\n" \
102         "    mtmsr %1\n" \
103         "1:" \
104         : "=r"((_isr_cookie)),"=&r" ((_enable_mask)) \
105         : "0"((_isr_cookie)),"1" ((_enable_mask)) \
106         ); \
107   }
108
109 void irq_initialize(void);
110 void irq_shutdown(void);
111
112 void irq_handler(void);
113
114 void irq_bw_enable(u32 irq);
115 void irq_bw_disable(u32 irq);
116 void irq_hw_enable(u32 irq);
117 void irq_hw_disable(u32 irq);
118
119 u32 irq_kill(void);
120 void irq_restore(u32 cookie);
121
122 /* TODO: port to ppc 
123 static inline void irq_wait(void)
124 {
125         u32 data = 0;
126         __asm__ volatile ( "mcr\tp15, 0, %0, c7, c0, 4" : : "r" (data) );
127 }
128 */
129
130 #endif
131
132 #else
133 // stub functions allow us to avoid sprinkling other code with ifdefs
134 static inline u32 irq_kill(void) {
135         return 0;
136 }
137
138 static inline void irq_restore(u32 cookie) {
139         (void)cookie;
140 }
141 #endif
142
143