Rev 593 | Rev 750 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 593 | Rev 594 | ||
---|---|---|---|
- | 1 | $Revision: 594 $ |
|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
3 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
4 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
6 | ;; ;; |
6 | ;; ;; |
7 | ;; ;; |
7 | ;; PCI32.INC ;; |
8 | ;; PCI32.INC ;; |
8 | ;; ;; |
9 | ;; ;; |
9 | ;; 32 bit PCI driver code ;; |
10 | ;; 32 bit PCI driver code ;; |
10 | ;; ;; |
11 | ;; ;; |
11 | ;; Version 0.3 April 9, 2007 ;; |
12 | ;; Version 0.3 April 9, 2007 ;; |
12 | ;; Version 0.2 December 21st, 2002 ;; |
13 | ;; Version 0.2 December 21st, 2002 ;; |
13 | ;; ;; |
14 | ;; ;; |
14 | ;; Author: Victor Prodan, victorprodan@yahoo.com ;; |
15 | ;; Author: Victor Prodan, victorprodan@yahoo.com ;; |
15 | ;; Mihailov Ilia, ghost.nsk@gmail.com ;; |
16 | ;; Mihailov Ilia, ghost.nsk@gmail.com ;; |
16 | ;; Credits: ;; |
17 | ;; Credits: ;; |
17 | ;; Ralf Brown ;; |
18 | ;; Ralf Brown ;; |
18 | ;; Mike Hibbett, mikeh@oceanfree.net ;; |
19 | ;; Mike Hibbett, mikeh@oceanfree.net ;; |
19 | ;; ;; |
20 | ;; ;; |
20 | ;; See file COPYING for details ;; |
21 | ;; See file COPYING for details ;; |
21 | ;; ;; |
22 | ;; ;; |
22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
23 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
23 | - | ||
24 | $Revision: 593 $ |
- | |
25 | 24 | ||
26 | 25 | ||
27 | ;*************************************************************************** |
26 | ;*************************************************************************** |
28 | ; Function |
27 | ; Function |
29 | ; pci_api: |
28 | ; pci_api: |
30 | ; |
29 | ; |
31 | ; Description |
30 | ; Description |
32 | ; entry point for system PCI calls |
31 | ; entry point for system PCI calls |
33 | ;*************************************************************************** |
32 | ;*************************************************************************** |
34 | 33 | ||
35 | align 4 |
34 | align 4 |
36 | 35 | ||
37 | pci_api: |
36 | pci_api: |
38 | 37 | ||
39 | cmp [pci_access_enabled],1 |
38 | cmp [pci_access_enabled],1 |
40 | jne no_pci_access_for_applications |
39 | jne no_pci_access_for_applications |
41 | 40 | ||
42 | or al,al |
41 | or al,al |
43 | jnz pci_fn_1 |
42 | jnz pci_fn_1 |
44 | ; PCI function 0: get pci version (AH.AL) |
43 | ; PCI function 0: get pci version (AH.AL) |
45 | movzx eax,word [BOOT_VAR+0x9022] |
44 | movzx eax,word [BOOT_VAR+0x9022] |
46 | ret |
45 | ret |
47 | 46 | ||
48 | pci_fn_1: |
47 | pci_fn_1: |
49 | cmp al,1 |
48 | cmp al,1 |
50 | jnz pci_fn_2 |
49 | jnz pci_fn_2 |
51 | 50 | ||
52 | ; PCI function 1: get last bus in AL |
51 | ; PCI function 1: get last bus in AL |
53 | mov al,[BOOT_VAR+0x9021] |
52 | mov al,[BOOT_VAR+0x9021] |
54 | ret |
53 | ret |
55 | 54 | ||
56 | pci_fn_2: |
55 | pci_fn_2: |
57 | cmp al,2 |
56 | cmp al,2 |
58 | jne pci_fn_3 |
57 | jne pci_fn_3 |
59 | ; PCI function 2: get pci access mechanism |
58 | ; PCI function 2: get pci access mechanism |
60 | mov al,[BOOT_VAR+0x9020] |
59 | mov al,[BOOT_VAR+0x9020] |
61 | ret |
60 | ret |
62 | pci_fn_3: |
61 | pci_fn_3: |
63 | 62 | ||
64 | cmp al,4 |
63 | cmp al,4 |
65 | jz pci_read_reg ;byte |
64 | jz pci_read_reg ;byte |
66 | cmp al,5 |
65 | cmp al,5 |
67 | jz pci_read_reg ;word |
66 | jz pci_read_reg ;word |
68 | cmp al,6 |
67 | cmp al,6 |
69 | jz pci_read_reg ;dword |
68 | jz pci_read_reg ;dword |
70 | 69 | ||
71 | cmp al,8 |
70 | cmp al,8 |
72 | jz pci_write_reg ;byte |
71 | jz pci_write_reg ;byte |
73 | cmp al,9 |
72 | cmp al,9 |
74 | jz pci_write_reg ;word |
73 | jz pci_write_reg ;word |
75 | cmp al,10 |
74 | cmp al,10 |
76 | jz pci_write_reg ;dword |
75 | jz pci_write_reg ;dword |
77 | 76 | ||
78 | no_pci_access_for_applications: |
77 | no_pci_access_for_applications: |
79 | 78 | ||
80 | mov eax,-1 |
79 | mov eax,-1 |
81 | 80 | ||
82 | ret |
81 | ret |
83 | 82 | ||
84 | ;*************************************************************************** |
83 | ;*************************************************************************** |
85 | ; Function |
84 | ; Function |
86 | ; pci_make_config_cmd |
85 | ; pci_make_config_cmd |
87 | ; |
86 | ; |
88 | ; Description |
87 | ; Description |
89 | ; creates a command dword for use with the PCI bus |
88 | ; creates a command dword for use with the PCI bus |
90 | ; bus # in ah |
89 | ; bus # in ah |
91 | ; device+func in bh (dddddfff) |
90 | ; device+func in bh (dddddfff) |
92 | ; register in bl |
91 | ; register in bl |
93 | ; |
92 | ; |
94 | ; command dword returned in eax ( 10000000 bbbbbbbb dddddfff rrrrrr00 ) |
93 | ; command dword returned in eax ( 10000000 bbbbbbbb dddddfff rrrrrr00 ) |
95 | ;*************************************************************************** |
94 | ;*************************************************************************** |
96 | 95 | ||
97 | align 4 |
96 | align 4 |
98 | 97 | ||
99 | pci_make_config_cmd: |
98 | pci_make_config_cmd: |
100 | shl eax,8 ; move bus to bits 16-23 |
99 | shl eax,8 ; move bus to bits 16-23 |
101 | mov ax,bx ; combine all |
100 | mov ax,bx ; combine all |
102 | and eax,0xffffff |
101 | and eax,0xffffff |
103 | or eax,0x80000000 |
102 | or eax,0x80000000 |
104 | ret |
103 | ret |
105 | 104 | ||
106 | ;*************************************************************************** |
105 | ;*************************************************************************** |
107 | ; Function |
106 | ; Function |
108 | ; pci_read_reg: |
107 | ; pci_read_reg: |
109 | ; |
108 | ; |
110 | ; Description |
109 | ; Description |
111 | ; read a register from the PCI config space into EAX/AX/AL |
110 | ; read a register from the PCI config space into EAX/AX/AL |
112 | ; IN: ah=bus,device+func=bh,register address=bl |
111 | ; IN: ah=bus,device+func=bh,register address=bl |
113 | ; number of bytes to read (1,2,4) coded into AL, bits 0-1 |
112 | ; number of bytes to read (1,2,4) coded into AL, bits 0-1 |
114 | ; (0 - byte, 1 - word, 2 - dword) |
113 | ; (0 - byte, 1 - word, 2 - dword) |
115 | ;*************************************************************************** |
114 | ;*************************************************************************** |
116 | 115 | ||
117 | align 4 |
116 | align 4 |
118 | 117 | ||
119 | pci_read_reg: |
118 | pci_read_reg: |
120 | cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? |
119 | cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? |
121 | je pci_read_reg_2 |
120 | je pci_read_reg_2 |
122 | 121 | ||
123 | ; mechanism 1 |
122 | ; mechanism 1 |
124 | push esi ; save register size into ESI |
123 | push esi ; save register size into ESI |
125 | mov esi,eax |
124 | mov esi,eax |
126 | and esi,3 |
125 | and esi,3 |
127 | 126 | ||
128 | call pci_make_config_cmd |
127 | call pci_make_config_cmd |
129 | mov ebx,eax |
128 | mov ebx,eax |
130 | ; get current state |
129 | ; get current state |
131 | mov dx,0xcf8 |
130 | mov dx,0xcf8 |
132 | in eax, dx |
131 | in eax, dx |
133 | push eax |
132 | push eax |
134 | ; set up addressing to config data |
133 | ; set up addressing to config data |
135 | mov eax,ebx |
134 | mov eax,ebx |
136 | and al,0xfc ; make address dword-aligned |
135 | and al,0xfc ; make address dword-aligned |
137 | out dx,eax |
136 | out dx,eax |
138 | ; get requested DWORD of config data |
137 | ; get requested DWORD of config data |
139 | mov dl,0xfc |
138 | mov dl,0xfc |
140 | and bl,3 |
139 | and bl,3 |
141 | or dl,bl ; add to port address first 2 bits of register address |
140 | or dl,bl ; add to port address first 2 bits of register address |
142 | 141 | ||
143 | or esi,esi |
142 | or esi,esi |
144 | jz pci_read_byte1 |
143 | jz pci_read_byte1 |
145 | cmp esi,1 |
144 | cmp esi,1 |
146 | jz pci_read_word1 |
145 | jz pci_read_word1 |
147 | cmp esi,2 |
146 | cmp esi,2 |
148 | jz pci_read_dword1 |
147 | jz pci_read_dword1 |
149 | jmp pci_fin_read1 |
148 | jmp pci_fin_read1 |
150 | 149 | ||
151 | pci_read_byte1: |
150 | pci_read_byte1: |
152 | in al,dx |
151 | in al,dx |
153 | jmp pci_fin_read1 |
152 | jmp pci_fin_read1 |
154 | pci_read_word1: |
153 | pci_read_word1: |
155 | in ax,dx |
154 | in ax,dx |
156 | jmp pci_fin_read1 |
155 | jmp pci_fin_read1 |
157 | pci_read_dword1: |
156 | pci_read_dword1: |
158 | in eax,dx |
157 | in eax,dx |
159 | jmp pci_fin_read1 |
158 | jmp pci_fin_read1 |
160 | pci_fin_read1: |
159 | pci_fin_read1: |
161 | ; restore configuration control |
160 | ; restore configuration control |
162 | xchg eax,[esp] |
161 | xchg eax,[esp] |
163 | mov dx,0xcf8 |
162 | mov dx,0xcf8 |
164 | out dx,eax |
163 | out dx,eax |
165 | 164 | ||
166 | pop eax |
165 | pop eax |
167 | pop esi |
166 | pop esi |
168 | ret |
167 | ret |
169 | pci_read_reg_2: |
168 | pci_read_reg_2: |
170 | 169 | ||
171 | test bh,128 ;mech#2 only supports 16 devices per bus |
170 | test bh,128 ;mech#2 only supports 16 devices per bus |
172 | jnz pci_read_reg_err |
171 | jnz pci_read_reg_err |
173 | 172 | ||
174 | push esi ; save register size into ESI |
173 | push esi ; save register size into ESI |
175 | mov esi,eax |
174 | mov esi,eax |
176 | and esi,3 |
175 | and esi,3 |
177 | 176 | ||
178 | push eax |
177 | push eax |
179 | ;store current state of config space |
178 | ;store current state of config space |
180 | mov dx,0xcf8 |
179 | mov dx,0xcf8 |
181 | in al,dx |
180 | in al,dx |
182 | mov ah,al |
181 | mov ah,al |
183 | mov dl,0xfa |
182 | mov dl,0xfa |
184 | in al,dx |
183 | in al,dx |
185 | 184 | ||
186 | xchg eax,[esp] |
185 | xchg eax,[esp] |
187 | ; out 0xcfa,bus |
186 | ; out 0xcfa,bus |
188 | mov al,ah |
187 | mov al,ah |
189 | out dx,al |
188 | out dx,al |
190 | ; out 0xcf8,0x80 |
189 | ; out 0xcf8,0x80 |
191 | mov dl,0xf8 |
190 | mov dl,0xf8 |
192 | mov al,0x80 |
191 | mov al,0x80 |
193 | out dx,al |
192 | out dx,al |
194 | ; compute addr |
193 | ; compute addr |
195 | shr bh,3 ; func is ignored in mechanism 2 |
194 | shr bh,3 ; func is ignored in mechanism 2 |
196 | or bh,0xc0 |
195 | or bh,0xc0 |
197 | mov dx,bx |
196 | mov dx,bx |
198 | 197 | ||
199 | or esi,esi |
198 | or esi,esi |
200 | jz pci_read_byte2 |
199 | jz pci_read_byte2 |
201 | cmp esi,1 |
200 | cmp esi,1 |
202 | jz pci_read_word2 |
201 | jz pci_read_word2 |
203 | cmp esi,2 |
202 | cmp esi,2 |
204 | jz pci_read_dword2 |
203 | jz pci_read_dword2 |
205 | jmp pci_fin_read2 |
204 | jmp pci_fin_read2 |
206 | 205 | ||
207 | pci_read_byte2: |
206 | pci_read_byte2: |
208 | in al,dx |
207 | in al,dx |
209 | jmp pci_fin_read2 |
208 | jmp pci_fin_read2 |
210 | pci_read_word2: |
209 | pci_read_word2: |
211 | in ax,dx |
210 | in ax,dx |
212 | jmp pci_fin_read2 |
211 | jmp pci_fin_read2 |
213 | pci_read_dword2: |
212 | pci_read_dword2: |
214 | in eax,dx |
213 | in eax,dx |
215 | ; jmp pci_fin_read2 |
214 | ; jmp pci_fin_read2 |
216 | pci_fin_read2: |
215 | pci_fin_read2: |
217 | 216 | ||
218 | ; restore configuration space |
217 | ; restore configuration space |
219 | xchg eax,[esp] |
218 | xchg eax,[esp] |
220 | mov dx,0xcfa |
219 | mov dx,0xcfa |
221 | out dx,al |
220 | out dx,al |
222 | mov dl,0xf8 |
221 | mov dl,0xf8 |
223 | mov al,ah |
222 | mov al,ah |
224 | out dx,al |
223 | out dx,al |
225 | 224 | ||
226 | pop eax |
225 | pop eax |
227 | pop esi |
226 | pop esi |
228 | ret |
227 | ret |
229 | 228 | ||
230 | pci_read_reg_err: |
229 | pci_read_reg_err: |
231 | xor eax,eax |
230 | xor eax,eax |
232 | dec eax |
231 | dec eax |
233 | ret |
232 | ret |
234 | 233 | ||
235 | 234 | ||
236 | ;*************************************************************************** |
235 | ;*************************************************************************** |
237 | ; Function |
236 | ; Function |
238 | ; pci_write_reg: |
237 | ; pci_write_reg: |
239 | ; |
238 | ; |
240 | ; Description |
239 | ; Description |
241 | ; write a register from ECX/CX/CL into the PCI config space |
240 | ; write a register from ECX/CX/CL into the PCI config space |
242 | ; IN: ah=bus,device+func=bh,register address (dword aligned)=bl, |
241 | ; IN: ah=bus,device+func=bh,register address (dword aligned)=bl, |
243 | ; value to write in ecx |
242 | ; value to write in ecx |
244 | ; number of bytes to write (1,2,4) coded into AL, bits 0-1 |
243 | ; number of bytes to write (1,2,4) coded into AL, bits 0-1 |
245 | ; (0 - byte, 1 - word, 2 - dword) |
244 | ; (0 - byte, 1 - word, 2 - dword) |
246 | ;*************************************************************************** |
245 | ;*************************************************************************** |
247 | 246 | ||
248 | align 4 |
247 | align 4 |
249 | 248 | ||
250 | pci_write_reg: |
249 | pci_write_reg: |
251 | cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? |
250 | cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? |
252 | je pci_write_reg_2 |
251 | je pci_write_reg_2 |
253 | 252 | ||
254 | ; mechanism 1 |
253 | ; mechanism 1 |
255 | push esi ; save register size into ESI |
254 | push esi ; save register size into ESI |
256 | mov esi,eax |
255 | mov esi,eax |
257 | and esi,3 |
256 | and esi,3 |
258 | 257 | ||
259 | call pci_make_config_cmd |
258 | call pci_make_config_cmd |
260 | mov ebx,eax |
259 | mov ebx,eax |
261 | ; get current state into ecx |
260 | ; get current state into ecx |
262 | mov dx,0xcf8 |
261 | mov dx,0xcf8 |
263 | in eax, dx |
262 | in eax, dx |
264 | push eax |
263 | push eax |
265 | ; set up addressing to config data |
264 | ; set up addressing to config data |
266 | mov eax,ebx |
265 | mov eax,ebx |
267 | and al,0xfc ; make address dword-aligned |
266 | and al,0xfc ; make address dword-aligned |
268 | out dx,eax |
267 | out dx,eax |
269 | ; write DWORD of config data |
268 | ; write DWORD of config data |
270 | mov dl,0xfc |
269 | mov dl,0xfc |
271 | and bl,3 |
270 | and bl,3 |
272 | or dl,bl |
271 | or dl,bl |
273 | mov eax,ecx |
272 | mov eax,ecx |
274 | 273 | ||
275 | or esi,esi |
274 | or esi,esi |
276 | jz pci_write_byte1 |
275 | jz pci_write_byte1 |
277 | cmp esi,1 |
276 | cmp esi,1 |
278 | jz pci_write_word1 |
277 | jz pci_write_word1 |
279 | cmp esi,2 |
278 | cmp esi,2 |
280 | jz pci_write_dword1 |
279 | jz pci_write_dword1 |
281 | jmp pci_fin_write1 |
280 | jmp pci_fin_write1 |
282 | 281 | ||
283 | pci_write_byte1: |
282 | pci_write_byte1: |
284 | out dx,al |
283 | out dx,al |
285 | jmp pci_fin_write1 |
284 | jmp pci_fin_write1 |
286 | pci_write_word1: |
285 | pci_write_word1: |
287 | out dx,ax |
286 | out dx,ax |
288 | jmp pci_fin_write1 |
287 | jmp pci_fin_write1 |
289 | pci_write_dword1: |
288 | pci_write_dword1: |
290 | out dx,eax |
289 | out dx,eax |
291 | jmp pci_fin_write1 |
290 | jmp pci_fin_write1 |
292 | pci_fin_write1: |
291 | pci_fin_write1: |
293 | 292 | ||
294 | ; restore configuration control |
293 | ; restore configuration control |
295 | pop eax |
294 | pop eax |
296 | mov dl,0xf8 |
295 | mov dl,0xf8 |
297 | out dx,eax |
296 | out dx,eax |
298 | 297 | ||
299 | xor eax,eax |
298 | xor eax,eax |
300 | pop esi |
299 | pop esi |
301 | 300 | ||
302 | ret |
301 | ret |
303 | pci_write_reg_2: |
302 | pci_write_reg_2: |
304 | 303 | ||
305 | test bh,128 ;mech#2 only supports 16 devices per bus |
304 | test bh,128 ;mech#2 only supports 16 devices per bus |
306 | jnz pci_write_reg_err |
305 | jnz pci_write_reg_err |
307 | 306 | ||
308 | 307 | ||
309 | push esi ; save register size into ESI |
308 | push esi ; save register size into ESI |
310 | mov esi,eax |
309 | mov esi,eax |
311 | and esi,3 |
310 | and esi,3 |
312 | 311 | ||
313 | push eax |
312 | push eax |
314 | ;store current state of config space |
313 | ;store current state of config space |
315 | mov dx,0xcf8 |
314 | mov dx,0xcf8 |
316 | in al,dx |
315 | in al,dx |
317 | mov ah,al |
316 | mov ah,al |
318 | mov dl,0xfa |
317 | mov dl,0xfa |
319 | in al,dx |
318 | in al,dx |
320 | xchg eax,[esp] |
319 | xchg eax,[esp] |
321 | ; out 0xcfa,bus |
320 | ; out 0xcfa,bus |
322 | mov al,ah |
321 | mov al,ah |
323 | out dx,al |
322 | out dx,al |
324 | ; out 0xcf8,0x80 |
323 | ; out 0xcf8,0x80 |
325 | mov dl,0xf8 |
324 | mov dl,0xf8 |
326 | mov al,0x80 |
325 | mov al,0x80 |
327 | out dx,al |
326 | out dx,al |
328 | ; compute addr |
327 | ; compute addr |
329 | shr bh,3 ; func is ignored in mechanism 2 |
328 | shr bh,3 ; func is ignored in mechanism 2 |
330 | or bh,0xc0 |
329 | or bh,0xc0 |
331 | mov dx,bx |
330 | mov dx,bx |
332 | ; write register |
331 | ; write register |
333 | mov eax,ecx |
332 | mov eax,ecx |
334 | 333 | ||
335 | or esi,esi |
334 | or esi,esi |
336 | jz pci_write_byte2 |
335 | jz pci_write_byte2 |
337 | cmp esi,1 |
336 | cmp esi,1 |
338 | jz pci_write_word2 |
337 | jz pci_write_word2 |
339 | cmp esi,2 |
338 | cmp esi,2 |
340 | jz pci_write_dword2 |
339 | jz pci_write_dword2 |
341 | jmp pci_fin_write2 |
340 | jmp pci_fin_write2 |
342 | 341 | ||
343 | pci_write_byte2: |
342 | pci_write_byte2: |
344 | out dx,al |
343 | out dx,al |
345 | jmp pci_fin_write2 |
344 | jmp pci_fin_write2 |
346 | pci_write_word2: |
345 | pci_write_word2: |
347 | out dx,ax |
346 | out dx,ax |
348 | jmp pci_fin_write2 |
347 | jmp pci_fin_write2 |
349 | pci_write_dword2: |
348 | pci_write_dword2: |
350 | out dx,eax |
349 | out dx,eax |
351 | jmp pci_fin_write2 |
350 | jmp pci_fin_write2 |
352 | pci_fin_write2: |
351 | pci_fin_write2: |
353 | ; restore configuration space |
352 | ; restore configuration space |
354 | pop eax |
353 | pop eax |
355 | mov dx,0xcfa |
354 | mov dx,0xcfa |
356 | out dx,al |
355 | out dx,al |
357 | mov dl,0xf8 |
356 | mov dl,0xf8 |
358 | mov al,ah |
357 | mov al,ah |
359 | out dx,al |
358 | out dx,al |
360 | 359 | ||
361 | xor eax,eax |
360 | xor eax,eax |
362 | pop esi |
361 | pop esi |
363 | ret |
362 | ret |
364 | 363 | ||
365 | pci_write_reg_err: |
364 | pci_write_reg_err: |
366 | xor eax,eax |
365 | xor eax,eax |
367 | dec eax |
366 | dec eax |
368 | ret |
367 | ret |
369 | 368 | ||
370 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
369 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
371 | 370 | ||
372 | ; VendID (2), DevID (2), Revision = 0 (1), Class Code (3), FNum (1), Bus (1) |
371 | ; VendID (2), DevID (2), Revision = 0 (1), Class Code (3), FNum (1), Bus (1) |
373 | pci_emu_dat: times 30*10 db 0 |
372 | pci_emu_dat: times 30*10 db 0 |
374 | 373 | ||
375 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
374 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
376 | align 4 |
375 | align 4 |
377 | sys_pcibios: |
376 | sys_pcibios: |
378 | cmp [pci_access_enabled], 1 |
- | |
379 | jne .unsupported_func |
- | |
380 | mov edi, [pci_bios_entry] |
- | |
381 | test edi, edi |
- | |
382 | jz .emulate_bios |
- | |
383 | xchg ebx, eax |
377 | xchg ebx, eax |
384 | xchg ecx, eax |
378 | xchg ecx, eax |
385 | xchg edx, eax |
379 | xchg edx, eax |
386 | xchg esi, eax |
380 | xchg esi, eax |
387 | mov edi, eax |
381 | xchg edi, eax |
- | 382 | cmp [pci_access_enabled], 1 |
|
- | 383 | jne .unsupported_func |
|
- | 384 | cmp [pci_bios_entry], 0 |
|
- | 385 | jz .emulate_bios |
|
388 | 386 | ||
389 | push ds |
387 | push ds |
390 | mov ax, pci_data_sel |
388 | mov ax, pci_data_sel |
391 | mov ds, ax |
389 | mov ds, ax |
- | 390 | mov eax, ebp |
|
392 | mov eax, ebp |
391 | mov ah, 0B1h |
393 | call pword [cs:pci_bios_entry] |
392 | call pword [cs:pci_bios_entry] |
394 | pop ds |
393 | pop ds |
395 | 394 | ||
396 | jmp .return |
395 | jmp .return |
397 | ;-=-=-=-=-=-=-=-= |
396 | ;-=-=-=-=-=-=-=-= |
398 | .emulate_bios: |
397 | .emulate_bios: |
399 | cmp ebp, 1 ; PCI_FUNCTION_ID |
398 | cmp ebp, 1 ; PCI_FUNCTION_ID |
400 | jnz .not_PCI_BIOS_PRESENT |
399 | jnz .not_PCI_BIOS_PRESENT |
401 | mov edx, 'PCI ' |
400 | mov edx, 'PCI ' |
402 | xor ah, ah |
- | |
403 | mov al, [OS_BASE+0x2F0000 + 0x9020] |
401 | mov al, [OS_BASE+0x2F0000 + 0x9020] |
404 | mov bx, [OS_BASE+0x2F0000 + 0x9022] |
402 | mov bx, [OS_BASE+0x2F0000 + 0x9022] |
405 | mov cl, [OS_BASE+0x2F0000 + 0x9021] |
403 | mov cl, [OS_BASE+0x2F0000 + 0x9021] |
- | 404 | xor ah, ah |
|
406 | jmp .return |
405 | jmp .return_abcd |
407 | 406 | ||
408 | .not_PCI_BIOS_PRESENT: |
407 | .not_PCI_BIOS_PRESENT: |
409 | cmp ebp, 2 ; FIND_PCI_DEVICE |
408 | cmp ebp, 2 ; FIND_PCI_DEVICE |
410 | jne .not_FIND_PCI_DEVICE |
409 | jne .not_FIND_PCI_DEVICE |
411 | mov esi, pci_emu_dat |
410 | mov ebx, pci_emu_dat |
412 | ..nxt: cmp [esi], cx |
411 | ..nxt: cmp [ebx], dx |
413 | jne ..no |
412 | jne ..no |
414 | cmp [esi + 2], bx |
413 | cmp [ebx + 2], cx |
415 | jne ..no |
414 | jne ..no |
416 | dec dx |
415 | dec si |
417 | jns ..no |
416 | jns ..no |
418 | mov bx, [esi + 4] |
417 | mov bx, [ebx + 4] |
419 | xor ah, ah |
418 | xor ah, ah |
420 | jmp .return |
419 | jmp .return_ab |
421 | ..no: cmp word[esi], 0 |
420 | ..no: cmp word[ebx], 0 |
422 | je ..dev_not_found |
421 | je ..dev_not_found |
423 | add esi, 10 |
422 | add ebx, 10 |
424 | jmp ..nxt |
423 | jmp ..nxt |
425 | ..dev_not_found: |
424 | ..dev_not_found: |
426 | mov ah, 0x86 ; DEVICE_NOT_FOUND |
425 | mov ah, 0x86 ; DEVICE_NOT_FOUND |
427 | jmp .return |
426 | jmp .return_a |
428 | 427 | ||
429 | .not_FIND_PCI_DEVICE: |
428 | .not_FIND_PCI_DEVICE: |
430 | cmp ebp, 3 ; FIND_PCI_CLASS_CODE |
429 | cmp ebp, 3 ; FIND_PCI_CLASS_CODE |
431 | jne .not_FIND_PCI_CLASS_CODE |
430 | jne .not_FIND_PCI_CLASS_CODE |
432 | mov esi, pci_emu_dat |
431 | mov esi, pci_emu_dat |
433 | shl ebx, 8 |
432 | shl ecx, 8 |
434 | ..nxt2: cmp [esi], ebx |
433 | ..nxt2: cmp [esi], ecx |
435 | jne ..no2 |
434 | jne ..no2 |
436 | mov bx, [esi] |
435 | mov bx, [esi] |
437 | xor ah, ah |
436 | xor ah, ah |
438 | jmp .return |
437 | jmp .return_ab |
439 | ..no2: cmp dword[esi], 0 |
438 | ..no2: cmp dword[esi], 0 |
440 | je ..dev_not_found2 |
439 | je ..dev_not_found |
441 | add esi, 10 |
440 | add esi, 10 |
442 | jmp ..nxt2 |
441 | jmp ..nxt2 |
443 | ..dev_not_found2: |
- | |
444 | mov ah, 0x86 ; DEVICE_NOT_FOUND |
- | |
445 | jmp .return |
- | |
446 | 442 | ||
447 | .not_FIND_PCI_CLASS_CODE: |
443 | .not_FIND_PCI_CLASS_CODE: |
448 | cmp ebp, 8 ; READ_CONFIG_* |
444 | cmp ebp, 8 ; READ_CONFIG_* |
449 | jb .not_READ_CONFIG |
445 | jb .not_READ_CONFIG |
450 | cmp ebp, 0x0A |
446 | cmp ebp, 0x0A |
451 | ja .not_READ_CONFIG |
447 | ja .not_READ_CONFIG |
452 | mov ebx, esi |
448 | mov eax, ebp |
453 | mov bh, al |
449 | mov ah, bh |
454 | mov edx, ebp |
450 | mov edx, edi |
- | 451 | mov bh, bl |
|
455 | mov al, dl |
452 | mov bl, dl |
456 | call pci_read_reg |
453 | call pci_read_reg |
457 | mov ecx, eax |
454 | mov ecx, eax |
458 | xor ah, ah ; SUCCESSFUL |
455 | xor ah, ah ; SUCCESSFUL |
459 | jmp .return |
456 | jmp .return_abc |
460 | .not_READ_CONFIG: |
457 | .not_READ_CONFIG: |
461 | cmp ebp, 0x0B ; WRITE_CONFIG_* |
458 | cmp ebp, 0x0B ; WRITE_CONFIG_* |
462 | jb .not_WRITE_CONFIG |
459 | jb .not_WRITE_CONFIG |
463 | cmp ebp, 0x0D |
460 | cmp ebp, 0x0D |
464 | ja .not_WRITE_CONFIG |
461 | ja .not_WRITE_CONFIG |
465 | mov ecx, ebx |
462 | lea eax, [ebp+1] |
466 | mov ebx, esi |
463 | mov ah, bh |
467 | mov bh, al |
464 | mov edx, edi |
468 | mov edx, ebp |
465 | mov bh, bl |
469 | inc edx |
- | |
470 | mov al, dl |
466 | mov bl, dl |
471 | call pci_write_reg |
467 | call pci_write_reg |
472 | xor ah, ah ; SUCCESSFUL |
468 | xor ah, ah ; SUCCESSFUL |
473 | jmp .return |
469 | jmp .return_abc |
474 | .not_WRITE_CONFIG: |
470 | .not_WRITE_CONFIG: |
475 | .unsupported_func: |
471 | .unsupported_func: |
476 | mov ah, 0x81 ; FUNC_NOT_SUPPORTED |
472 | mov ah, 0x81 ; FUNC_NOT_SUPPORTED |
477 | .return:mov dword[esp + 8 ], edi |
473 | .return:mov dword[esp + 8 ], edi |
478 | mov dword[esp + 12], esi |
474 | mov dword[esp + 12], esi |
479 | mov dword[esp + 24], ebx |
475 | .return_abcd: |
480 | mov dword[esp + 28], edx |
476 | mov dword[esp + 28], edx |
- | 477 | .return_abc: |
|
481 | mov dword[esp + 32], ecx |
478 | mov dword[esp + 32], ecx |
- | 479 | .return_ab: |
|
- | 480 | mov dword[esp + 24], ebx |
|
- | 481 | .return_a: |
|
482 | mov dword[esp + 36], eax |
482 | mov dword[esp + 36], eax |
483 | ret |
483 | ret |