summaryrefslogtreecommitdiffstats
path: root/qemu/roms/SLOF/board-js2x/slof/pci-interrupts.fs
blob: 92851cd58f31a81a8b3114dc98763e6df6c42489 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
\ *****************************************************************************
\ * Copyright (c) 2004, 2008 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ *     IBM Corporation - initial implementation
\ ****************************************************************************/

\ define function pointer as forward declaration for get-interrupt-line
\ this is board wireing and southbridge dependent
\ returns the wired interrupt line for this config addr
\ ( config-addr -- irq-line )
DEFER pci-get-irq-line

\ define function pointer as forward declaration for get-interrupt-sense-type
\ this is board wireing and southbridge dependent
\ returns the wired interrupt sense type for this config addr
\ 0 - Edge rising
\ 1 - Level low
\ 2 - Level high
\ 3 - Edge falling
\ ( config-addr -- irq-sense )
DEFER pci-get-irq-sense


\ *****************************************************************************
\ Generic IRQ routines
\ *****************************************************************************



: unknown-slot ( -- 0 )
\	cr pci-vec ABORT" Unknown slot "
	0
;
\ 0c s" /ht/@1/@2"    PCI-X INTA & INTC Pnpirq0 -> irq12
\ 0e s" /ht/@1/@2"    PCI-X INTB & INTD Pnpirq1 -> irq14
\ 10 s" /ht/@8,1"     ATA         
\ 0f s" /ht/@1/@1"    Obsidian     Pnpirq2 -> irq15
\ 10 s" /ht/@7/@2"    Video / Exar Serial  PirqA
\ 11 s" /ht/@2/@4"    Ethernet     PirqB
\ 12 s" /ht/@2/@4,1"  Ethernet     PirqC
\ 13 s" /ht/@7/@0"    USB          PirqD
\ 13 s" /ht/@7/@0,1"  USB          PirqD
\ 13 s" /ht/@7/@0,2"  USB          PirqD

\ 14 s" /ht/@3/@0"    PCIe gpio28
\ 15 s" /ht/@4/@0"    PCIe gpio29
\ 16 s" /ht/@5/@0"    PCIe gpio30
\ 17 s" /ht/@6/@0"    PCIe gpio31


\ -----------------------------------------------------------------------------
\ Get the interrupt pin for a device on ht u4
: u4-get-irq-line ( config-addr -- irq-line )
\	cr s" u4-get-irq-line " type
	pci-device-vec c@ CASE 
		1 OF pci-device-vec-len 1 >= IF  
				pci-device-vec 1+ c@ CASE 
					1 OF f ENDOF
					2 OF dup pci-interrupt@ CASE
							1 OF c ENDOF
							3 OF e ENDOF
							2 OF c ENDOF
							4 OF e ENDOF
						ENDCASE
					ENDOF 
					dup OF unknown-slot  ENDOF
				ENDCASE
			ELSE
				unknown-slot
			THEN
		ENDOF
		2 OF pci-device-vec-len 1 >= IF  
				 pci-device-vec 1+ c@ CASE
					4 OF dup pci-addr2fn 1 >= IF 12 ELSE 11 THEN  ENDOF 
					dup OF unknown-slot  ENDOF
				ENDCASE
			ELSE
				unknown-slot
			THEN
		ENDOF
		3 OF 14 ENDOF
		4 OF 15 ENDOF
		5 OF 16 ENDOF
		6 OF 17 ENDOF
		7 OF pci-device-vec-len 1 >= IF  
				pci-device-vec 1+ c@ CASE 
					0 OF 13  ENDOF 
					2 OF 10  ENDOF 
					dup OF unknown-slot  ENDOF
				ENDCASE
			ELSE
				unknown-slot
			THEN
		ENDOF
		8 OF 10 ENDOF
                dup OF unknown-slot  ENDOF	
        ENDCASE
	swap drop
;

\ -----------------------------------------------------------------------------
\ Get the interrupt sense type for a device on ht u4
: u4-get-irq-sense ( config-addr -- irq-sense )
\	cr s" u4-get-irq-sense " type
        u4-get-irq-line CASE 
	0c OF 00 ENDOF
	0e OF 00 ENDOF
	dup OF 01  ENDOF
        ENDCASE
;

\ 10 s" /ht/@4,1"    set-pci-interrupt \ ATA
\ 13 s" /ht/@3/@0"   set-pci-interrupt \ USB
\ 13 s" /ht/@3/@0,1" set-pci-interrupt \ USB
\ 13 s" /ht/@3/@0,2" set-pci-interrupt \ USB
\ 1c s" /ht/@2/@1"   set-pci-interrupt \ Ethernet
\ 1d s" /ht/@2/@1,1" set-pci-interrupt \ Ethernet

\ -----------------------------------------------------------------------------
\ Get the interrupt pin for a device on ht u3
: u3-get-irq-line ( config-addr -- irq-line )
\	cr s" u3-get-irq-line " type
	pci-device-vec c@ CASE 
		2 OF pci-device-vec-len 1 >= IF  
				pci-device-vec 1+ c@ CASE 
					1 OF dup pci-addr2fn 1 >= IF 1d ELSE 1c THEN  ENDOF 
					dup OF unknown-slot  ENDOF
				ENDCASE
			ELSE
				unknown-slot
			THEN
		ENDOF
		3 OF 13 ENDOF
		4 OF 10 ENDOF
                dup OF unknown-slot  ENDOF	
        ENDCASE
	swap drop
;

\ -----------------------------------------------------------------------------
\ Get the interrupt sense type for a device on ht u3
: u3-get-irq-sense ( config-addr -- irq-sense )
\	cr s" u3-get-irq-sense " type
        u3-get-irq-line CASE 
	dup OF 01  ENDOF
        ENDCASE
;



\ -----------------------------------------------------------------------------
\ Get the interrupt pin for a device on attu
: pcie-get-irq-line ( config-addr -- irq-line )
\	cr s" pcie-get-irq-line " type
	drop
	3
;


\ -----------------------------------------------------------------------------
\ Get the interrupt sense type for a device on attu
: pcie-get-irq-sense ( config-addr -- irq-sense )
\ 	cr s" pcie-get-irq-sense " type
       drop
        01
;

\ -----------------------------------------------------------------------------
\ Set up the special routines for HT irq handling
: ht-irq-init ( -- )
\	cr s" ht-irq-init " type
	u4? IF
       		['] u4-get-irq-line TO pci-get-irq-line
       		['] u4-get-irq-sense TO pci-get-irq-sense
	ELSE
        	['] u3-get-irq-line TO pci-get-irq-line
	       	['] u3-get-irq-sense TO pci-get-irq-sense
	THEN
;

\ -----------------------------------------------------------------------------
\ Set up the special routines for PCI-e irq handling
: pcie-irq-init ( -- )
\	cr s" pcie-irq-init " type
        ['] pcie-get-irq-sense TO pci-get-irq-sense
        ['] pcie-get-irq-line TO pci-get-irq-line
;

\ -----------------------------------------------------------------------------
\ Set up the special routines for irq handling
0 VALUE mpic
: pci-irq-init ( mpic puid -- mpic )
        over TO mpic
        18 rshift FF and
        CASE
                F1 OF pcie-irq-init ENDOF
                F2 OF ht-irq-init ENDOF
                dup OF ABORT" Wrong PUID! in pci-irq-init" ENDOF
        ENDCASE
;

\ -----------------------------------------------------------------------------
\ Set the interrupt pin for a device
: pci-set-irq-line ( config-addr -- )
\	cr pci-vec
        dup pci-get-irq-line 
\	." ->" dup .
        swap pci-irq-line!
;

\ -----------------------------------------------------------------------------
\ Add an irq entry for the device at config-addr into the irq map
\ each entry consists of 7 integer values
\ Structure of an entry:
\             +----------+---+---+------------+--------------+---------+---------------+
\  Number#    |    0     | 1 | 2 |     3      |      4       |    5    |      6        |
\             +----------+---+---+------------+--------------+---------+---------------+
\  meaning    |  config  |   |   |      int#  |  phandle     | intr nr | pos edge (0)  |
\             |   addr   |   |   | (1=a, 2=b, |  intr contr  |         | act ll   (1)  |
\             +----------+---+---+------------+--------------+---------+---------------+
\  value      | pci slot | 0 | 0 |    1       |        mpic  |     7   |     0|1       |
\             +----------+---+---+------------+--------------+---------+---------------+
: pci-gen-irq-entry ( prop-addr prop-len config-addr -- prop-addr prop-len )
        dup >r encode-int+ 0    encode-64+      \ config addr
        r@ pci-interrupt@       encode-int+     \ interrupt type
        mpic                    encode-int+     \ phandle to MPIC
        r@ pci-irq-line@        encode-int+     \ interrupt number
        r> pci-get-irq-sense    encode-int+     \ trigger type
;