|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Syborg interrupt control and dispatch |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <syborg_priv.h> |
|
19 |
|
20 SInterruptHandler SyborgInterrupt::Handlers[KNumSyborgInts]; |
|
21 |
|
22 void SyborgInterrupt::DisableAndClearAll() |
|
23 { |
|
24 WriteReg(KHwBaseSic, 3, 0); |
|
25 } |
|
26 |
|
27 void SyborgInterrupt::Init1() |
|
28 { |
|
29 __KTRACE_OPT(KBOOT,Kern::Printf("SyborgInterrupt::Init1()")); |
|
30 |
|
31 for(TUint i = 0; i < KNumSyborgInts; i++) |
|
32 { |
|
33 Handlers[i].iPtr = (TAny*)i; |
|
34 Handlers[i].iIsr = Spurious; |
|
35 } |
|
36 |
|
37 DisableAndClearAll(); |
|
38 |
|
39 Arm::SetIrqHandler((TLinAddr)SyborgInterrupt::IrqDispatch); |
|
40 Arm::SetFiqHandler((TLinAddr)SyborgInterrupt::FiqDispatch); |
|
41 } |
|
42 |
|
43 void SyborgInterrupt::Init3() |
|
44 { |
|
45 __KTRACE_OPT(KHARDWARE,Kern::Printf("SyborgInterrupt::Init3()")); |
|
46 } |
|
47 |
|
48 void SyborgInterrupt::Spurious(TAny* anId) |
|
49 { |
|
50 // Handle an unexpected interrupt |
|
51 Kern::Fault("SpuriousInt", (TInt)anId); |
|
52 } |
|
53 |
|
54 EXPORT_C TInt Interrupt::Bind(TInt anId, TIsr anIsr, TAny* aPtr) |
|
55 { |
|
56 __KTRACE_OPT(KHARDWARE,Kern::Printf("Interrupt::Bind(anId=%d anIsr=0x%X aPtr=0x%X)",anId,anIsr,aPtr)); |
|
57 if((anId >= 0) && ((TUint)anId < KNumSyborgInts)) |
|
58 { |
|
59 SInterruptHandler& h = SyborgInterrupt::Handlers[anId]; |
|
60 TInt irq = NKern::DisableAllInterrupts(); |
|
61 TInt r; |
|
62 if(h.iIsr != SyborgInterrupt::Spurious) |
|
63 { |
|
64 r = KErrInUse; |
|
65 } |
|
66 else |
|
67 { |
|
68 h.iPtr = aPtr; |
|
69 h.iIsr = anIsr; |
|
70 r = KErrNone; |
|
71 } |
|
72 NKern::RestoreInterrupts(irq); |
|
73 return r; |
|
74 } |
|
75 return KErrArgument; |
|
76 } |
|
77 |
|
78 EXPORT_C TInt Interrupt::Unbind(TInt anId) |
|
79 { |
|
80 __KTRACE_OPT(KHARDWARE,Kern::Printf("Interrupt::Unbind(%d)",anId)); |
|
81 if((anId >= 0) && ((TUint)anId < KNumSyborgInts)) |
|
82 { |
|
83 SInterruptHandler& h = SyborgInterrupt::Handlers[anId]; |
|
84 TInt irq = NKern::DisableAllInterrupts(); |
|
85 TInt r; |
|
86 if(h.iIsr == SyborgInterrupt::Spurious) |
|
87 { |
|
88 r = KErrGeneral; |
|
89 } |
|
90 else |
|
91 { |
|
92 // Reset pointer to handler back to default |
|
93 h.iPtr = (TAny*)anId; |
|
94 h.iIsr = SyborgInterrupt::Spurious; |
|
95 // Disable the interrupt |
|
96 TSyborg::DisableInt(anId); |
|
97 r = KErrNone; |
|
98 } |
|
99 NKern::RestoreInterrupts(irq); |
|
100 return r; |
|
101 } |
|
102 return KErrArgument; |
|
103 } |
|
104 |
|
105 EXPORT_C TInt Interrupt::Enable(TInt anId) |
|
106 { |
|
107 __KTRACE_OPT(KHARDWARE,Kern::Printf("Interrupt::Enable(%d)",anId)); |
|
108 if((anId >= 0) && ((TUint)anId < KNumSyborgInts)) |
|
109 { |
|
110 if(SyborgInterrupt::Handlers[anId].iIsr == SyborgInterrupt::Spurious) |
|
111 { |
|
112 return KErrNotReady; |
|
113 } |
|
114 else |
|
115 { |
|
116 TSyborg::EnableInt(anId); |
|
117 return KErrNone; |
|
118 } |
|
119 } |
|
120 return KErrArgument; |
|
121 } |
|
122 |
|
123 EXPORT_C TInt Interrupt::Disable(TInt anId) |
|
124 { |
|
125 __KTRACE_OPT(KHARDWARE,Kern::Printf("Interrupt::Disable(%d)",anId)); |
|
126 if((anId >= 0) && ((TUint)anId < KNumSyborgInts)) |
|
127 { |
|
128 TSyborg::DisableInt(anId); |
|
129 return KErrNone; |
|
130 } |
|
131 return KErrArgument; |
|
132 } |
|
133 |
|
134 EXPORT_C TInt Interrupt::Clear(TInt anId) |
|
135 { |
|
136 __KTRACE_OPT(KHARDWARE,Kern::Printf("Interrupt::Clear(%d)",anId)); |
|
137 if((anId >= 0) && ((TUint)anId < KNumSyborgInts)) |
|
138 { |
|
139 return KErrNone; |
|
140 } |
|
141 return KErrArgument; |
|
142 } |
|
143 |
|
144 EXPORT_C TInt Interrupt::SetPriority(TInt anId, TInt aPriority) |
|
145 { |
|
146 __KTRACE_OPT(KHARDWARE,Kern::Printf("Interrupt::SetPriority(anId=%d aPriority=0x%X)",anId,aPriority)); |
|
147 return KErrNotSupported; |
|
148 } |
|
149 |