Rev 1560 | Rev 1599 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1560 | Rev 1587 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; ;; |
6 | ;; ;; |
7 | ;; PCI32.INC ;; |
7 | ;; PCI32.INC ;; |
8 | ;; ;; |
8 | ;; ;; |
9 | ;; 32 bit PCI driver code ;; |
9 | ;; 32 bit PCI driver code ;; |
10 | ;; ;; |
10 | ;; ;; |
11 | ;; Version 0.4 February 2nd, 2010 ;; |
- | |
12 | ;; Version 0.3 April 9, 2007 ;; |
11 | ;; Version 0.3 April 9, 2007 ;; |
13 | ;; Version 0.2 December 21st, 2002 ;; |
12 | ;; Version 0.2 December 21st, 2002 ;; |
14 | ;; ;; |
13 | ;; ;; |
15 | ;; Author: Victor Prodan, victorprodan@yahoo.com ;; |
14 | ;; Author: Victor Prodan, victorprodan@yahoo.com ;; |
16 | ;; Mihailov Ilia, ghost.nsk@gmail.com ;; |
15 | ;; Mihailov Ilia, ghost.nsk@gmail.com ;; |
17 | ;; Artem Jerdev, kolibri@jerdev.co.uk ;; |
- | |
18 | ;; Credits: ;; |
16 | ;; Credits: ;; |
19 | ;; Ralf Brown ;; |
17 | ;; Ralf Brown ;; |
20 | ;; Mike Hibbett, mikeh@oceanfree.net ;; |
18 | ;; Mike Hibbett, mikeh@oceanfree.net ;; |
21 | ;; ;; |
19 | ;; ;; |
22 | ;; See file COPYING for details ;; |
20 | ;; See file COPYING for details ;; |
23 | ;; ;; |
21 | ;; ;; |
24 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 25... | Line 23... | ||
25 | 23 | ||
Line 26... | Line 24... | ||
26 | $Revision: 1560 $ |
24 | $Revision: 1587 $ |
27 | 25 | ||
28 | ;*************************************************************************** |
26 | ;*************************************************************************** |
29 | ; Function |
27 | ; Function |
30 | ; pci_api: |
28 | ; pci_api: |
31 | ; |
29 | ; |
32 | ; Description |
30 | ; Description |
33 | ; entry point for system PCI calls |
31 | ; entry point for system PCI calls |
34 | ;*************************************************************************** |
- | |
Line -... | Line 32... | ||
- | 32 | ;*************************************************************************** |
|
35 | mmio_pci_addr dw 0x400 ; default PCI device bdf-address |
33 | mmio_pci_addr equ 0x400 ; set actual PCI address here to activate user-MMIO |
- | 34 | ||
- | 35 | iglobal |
|
- | 36 | align 4 |
|
- | 37 | f62call: |
|
- | 38 | dd pci_api.0 |
|
- | 39 | dd pci_api.1 |
|
- | 40 | dd pci_api.2 |
|
- | 41 | dd pci_api.not_support ;3 |
|
- | 42 | dd pci_read_reg ;4 byte |
|
- | 43 | dd pci_read_reg ;5 word |
|
- | 44 | dd pci_read_reg ;6 dword |
|
- | 45 | dd pci_api.not_support ;7 |
|
- | 46 | dd pci_write_reg ;8 byte |
|
- | 47 | dd pci_write_reg ;9 word |
|
- | 48 | dd pci_write_reg ;10 dword |
|
- | 49 | if defined mmio_pci_addr |
|
- | 50 | dd pci_mmio_init ;11 |
|
- | 51 | dd pci_mmio_map ;12 |
|
- | 52 | dd pci_mmio_unmap ;13 |
|
- | 53 | end if |
|
- | 54 | f62_rcall: |
|
- | 55 | dd pci_read_reg.0 ;4 byte |
|
- | 56 | dd pci_read_reg.1 ;5 word |
|
- | 57 | dd pci_read_reg.2 ;6 dword |
|
- | 58 | f62_rcall2: |
|
- | 59 | dd pci_read_reg_2.0 ;4 byte |
|
- | 60 | dd pci_read_reg_2.1 ;5 word |
|
- | 61 | dd pci_read_reg_2.2 ;6 dword |
|
- | 62 | f62_wcall: |
|
- | 63 | dd pci_write_reg.0 ;4 byte |
|
- | 64 | dd pci_write_reg.1 ;5 word |
|
- | 65 | dd pci_write_reg.2 ;6 dword |
|
- | 66 | f62_wcall2: |
|
- | 67 | dd pci_write_reg_2.0 ;4 byte |
|
Line 36... | Line -... | ||
36 | - | ||
Line -... | Line 68... | ||
- | 68 | dd pci_write_reg_2.1 ;5 word |
|
- | 69 | dd pci_write_reg_2.2 ;6 dword |
|
- | 70 | endg |
|
37 | 71 | ||
38 | align 4 |
72 | |
- | 73 | align 4 |
|
- | 74 | pci_api: |
|
- | 75 | movzx eax,bl |
|
- | 76 | cmp [pci_access_enabled],1 |
|
- | 77 | jne .no_pci_access_for_applications |
|
- | 78 | ||
- | 79 | if defined mmio_pci_addr |
|
- | 80 | cmp eax, 13 |
|
- | 81 | jb .not_support |
|
- | 82 | else |
|
- | 83 | cmp eax, 10 |
|
- | 84 | jb .not_support |
|
- | 85 | end if |
|
Line 39... | Line 86... | ||
39 | 86 | call dword [f62call+eax*4] |
|
40 | pci_api: |
87 | mov dword [esp+32],eax |
41 | 88 | ret |
|
- | 89 | ||
42 | cmp [pci_access_enabled],1 |
90 | |
43 | jne no_pci_access_for_applications |
91 | |
Line 44... | Line 92... | ||
44 | 92 | ; or al,al |
|
45 | or al,al |
93 | ; jnz pci_fn_1 |
46 | jnz pci_fn_1 |
94 | ; PCI function 0: get pci version (AH.AL) |
Line 47... | Line 95... | ||
47 | ; PCI function 0: get pci version (AH.AL) |
95 | .0: |
- | 96 | movzx eax, word [BOOT_VAR+0x9022] |
|
48 | movzx eax,word [BOOT_VAR+0x9022] |
97 | ret |
49 | ret |
98 | |
Line 50... | Line 99... | ||
50 | 99 | ;pci_fn_1: |
|
51 | pci_fn_1: |
100 | ; cmp al,1 |
52 | cmp al,1 |
101 | ; jnz pci_fn_2 |
53 | jnz pci_fn_2 |
102 | |
- | 103 | ; PCI function 1: get last bus in AL |
|
54 | 104 | .1: |
|
55 | ; PCI function 1: get last bus in AL |
105 | movzx eax, byte [BOOT_VAR+0x9021] |
56 | mov al,[BOOT_VAR+0x9021] |
106 | ret |
57 | ret |
- | |
58 | - | ||
59 | pci_fn_2: |
- | |
60 | cmp al,2 |
- | |
61 | jne pci_fn_3 |
- | |
62 | ; PCI function 2: get pci access mechanism |
- | |
63 | mov al,[BOOT_VAR+0x9020] |
- | |
64 | ret |
- | |
65 | pci_fn_3: |
- | |
66 | - | ||
67 | cmp al,4 |
- | |
68 | jz pci_read_reg ;byte |
- | |
69 | cmp al,5 |
- | |
70 | jz pci_read_reg ;word |
- | |
71 | cmp al,6 |
- | |
72 | jz pci_read_reg ;dword |
- | |
73 | - | ||
74 | cmp al,8 |
- | |
75 | jz pci_write_reg ;byte |
- | |
76 | cmp al,9 |
- | |
77 | jz pci_write_reg ;word |
- | |
78 | cmp al,10 |
- | |
Line -... | Line 107... | ||
- | 107 | ||
- | 108 | ;pci_fn_2: |
|
- | 109 | ; cmp al,2 |
|
- | 110 | ; jne pci_fn_3 |
|
- | 111 | ; PCI function 2: get pci access mechanism |
|
- | 112 | .2: |
|
- | 113 | movzx eax, byte [BOOT_VAR+0x9020] |
|
- | 114 | ret |
|
- | 115 | ;pci_fn_3: |
|
- | 116 | ||
- | 117 | ; cmp al,4 |
|
- | 118 | ; jz pci_read_reg ;byte |
|
- | 119 | ; cmp al,5 |
|
- | 120 | ; jz pci_read_reg ;word |
|
- | 121 | ; cmp al,6 |
|
79 | jz pci_write_reg ;dword |
122 | ; jz pci_read_reg ;dword |
- | 123 | ||
- | 124 | ; cmp al,8 |
|
- | 125 | ; jz pci_write_reg ;byte |
|
- | 126 | ; cmp al,9 |
|
- | 127 | ; jz pci_write_reg ;word |
|
- | 128 | ; cmp al,10 |
|
Line -... | Line 129... | ||
- | 129 | ; jz pci_write_reg ;dword |
|
- | 130 | ||
80 | 131 | ;if defined mmio_pci_addr |
|
81 | cmp al,11 ; user-level MMIO functions |
- | |
82 | jz pci_mmio_init |
132 | ; cmp al,11 ; user-level MMIO functions |
Line 83... | Line 133... | ||
83 | cmp al,12 |
133 | ; jz pci_mmio_init |
84 | jz pci_mmio_map |
134 | ; cmp al,12 |
85 | cmp al,13 |
135 | ; jz pci_mmio_map |
86 | jz pci_mmio_unmap |
136 | ; cmp al,13 |
87 | 137 | ; jz pci_mmio_unmap |
|
88 | 138 | ;end if |
|
89 | no_pci_access_for_applications: |
139 | |
90 | 140 | .not_support: |
|
91 | or eax,-1 |
141 | .no_pci_access_for_applications: |
92 | 142 | or eax,-1 |
|
93 | ret |
143 | ret |
94 | 144 | ||
Line 95... | Line 145... | ||
95 | ;*************************************************************************** |
145 | ;*************************************************************************** |
Line 96... | Line 146... | ||
96 | ; Function |
146 | ; Function |
97 | ; pci_make_config_cmd |
147 | ; pci_make_config_cmd |
98 | ; |
148 | ; |
99 | ; Description |
149 | ; Description |
100 | ; creates a command dword for use with the PCI bus |
150 | ; creates a command dword for use with the PCI bus |
101 | ; bus # in ah |
151 | ; bus # in bh;ah |
Line 102... | Line 152... | ||
102 | ; device+func in bh (dddddfff) |
152 | ; device+func in ch;bh (dddddfff) |
103 | ; register in bl |
153 | ; register in cl;bl |
104 | ; |
154 | ; |
Line 126... | Line 176... | ||
126 | ;*************************************************************************** |
176 | ;*************************************************************************** |
Line 127... | Line 177... | ||
127 | 177 | ||
Line 128... | Line 178... | ||
128 | align 4 |
178 | align 4 |
- | 179 | ||
- | 180 | pci_read_reg: |
|
- | 181 | cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? |
|
- | 182 | je pci_read_reg_2 |
|
129 | 183 | ||
130 | pci_read_reg: |
184 | ; mechanism 1 |
131 | push esi ; save register size into ESI |
185 | ; push esi ; save register size into ESI |
Line 132... | Line 186... | ||
132 | mov esi,eax |
186 | mov esi,ebx;eax |
133 | and esi,3 |
187 | and esi,3 |
134 | 188 | ||
135 | call pci_make_config_cmd |
189 | call pci_make_config_cmd |
136 | mov ebx,eax |
190 | mov eax,ebx;ebx,eax |
137 | ; get current state |
191 | ; get current state |
138 | mov dx,0xcf8 |
192 | mov dx,0xcf8 |
Line 145... | Line 199... | ||
145 | ; get requested DWORD of config data |
199 | ; get requested DWORD of config data |
146 | mov dl,0xfc |
200 | mov dl,0xfc |
147 | and bl,3 |
201 | and bl,3 |
148 | or dl,bl ; add to port address first 2 bits of register address |
202 | or dl,bl ; add to port address first 2 bits of register address |
Line 149... | Line 203... | ||
149 | 203 | ||
150 | or esi,esi |
204 | ; or esi,esi |
151 | jz pci_read_byte1 |
205 | ; jz pci_read_byte1 |
152 | cmp esi,1 |
206 | ; cmp esi,1 |
153 | jz pci_read_word1 |
207 | ; jz pci_read_word1 |
154 | cmp esi,2 |
208 | ; cmp esi,2 |
155 | jz pci_read_dword1 |
209 | ; jz pci_read_dword1 |
- | 210 | ; jmp pci_fin_read1 |
|
Line 156... | Line 211... | ||
156 | jmp pci_fin_read1 |
211 | jmp dword [f62_rcall+esi*4] |
157 | 212 | ||
158 | pci_read_byte1: |
213 | .0: |
159 | in al,dx |
214 | in al,dx |
160 | jmp pci_fin_read1 |
215 | jmp .pci_fin_read1 |
161 | pci_read_word1: |
216 | .1: |
162 | in ax,dx |
217 | in ax,dx |
163 | jmp pci_fin_read1 |
218 | jmp .pci_fin_read1 |
164 | pci_read_dword1: |
219 | .2: |
165 | in eax,dx |
220 | in eax,dx |
166 | jmp pci_fin_read1 |
221 | ; jmp pci_fin_read1 |
167 | pci_fin_read1: |
222 | .pci_fin_read1: |
168 | ; restore configuration control |
223 | ; restore configuration control |
169 | xchg eax,[esp] |
224 | xchg eax,[esp] |
Line 170... | Line 225... | ||
170 | mov dx,0xcf8 |
225 | mov dx,0xcf8 |
171 | out dx,eax |
226 | out dx,eax |
172 | 227 | ||
- | 228 | pop eax |
|
Line -... | Line 229... | ||
- | 229 | ;pop esi |
|
- | 230 | ret |
|
- | 231 | pci_read_reg_2: |
|
- | 232 | ||
- | 233 | test ch,128;bh,128 ;mech#2 only supports 16 devices per bus |
|
- | 234 | jnz pci_api.not_support |
|
- | 235 | ||
- | 236 | ; push esi ; save register size into ESI |
|
- | 237 | mov esi,ebx;eax |
|
- | 238 | and esi,3 |
|
- | 239 | ||
- | 240 | push ebx;eax |
|
- | 241 | mov eax,ebx |
|
- | 242 | ;store current state of config space |
|
- | 243 | mov dx,0xcf8 |
|
- | 244 | in al,dx |
|
- | 245 | mov ah,al |
|
- | 246 | mov dl,0xfa |
|
- | 247 | in al,dx |
|
- | 248 | ||
- | 249 | xchg eax,[esp] |
|
- | 250 | ; out 0xcfa,bus |
|
- | 251 | mov al,ah |
|
- | 252 | out dx,al |
|
- | 253 | ; out 0xcf8,0x80 |
|
- | 254 | mov dl,0xf8 |
|
- | 255 | mov al,0x80 |
|
- | 256 | out dx,al |
|
- | 257 | ; compute addr |
|
- | 258 | shr ch,3;bh,3 ; func is ignored in mechanism 2 |
|
- | 259 | or ch,0xc0;bh,0xc0 |
|
- | 260 | mov dx,cx;bx |
|
- | 261 | ||
- | 262 | ; or esi,esi |
|
173 | pop eax |
263 | ; jz pci_read_byte2 |
- | 264 | ; cmp esi,1 |
|
- | 265 | ; jz pci_read_word2 |
|
- | 266 | ; cmp esi,2 |
|
- | 267 | ; jz pci_read_dword2 |
|
- | 268 | ; jmp pci_fin_read2 |
|
- | 269 | jmp dword [f62_rcall2+esi*4] |
|
- | 270 | ||
- | 271 | .0: |
|
- | 272 | in al,dx |
|
- | 273 | jmp .pci_fin_read2 |
|
174 | pop esi |
274 | .1: |
- | 275 | in ax,dx |
|
- | 276 | jmp .pci_fin_read2 |
|
- | 277 | .2: |
|
- | 278 | in eax,dx |
|
- | 279 | ; jmp pci_fin_read2 |
|
- | 280 | ||
- | 281 | .pci_fin_read2: |
|
- | 282 | ||
- | 283 | ; restore configuration space |
|
- | 284 | xchg eax,[esp] |
|
- | 285 | mov dx,0xcfa |
|
- | 286 | out dx,al |
|
175 | ret |
287 | mov dl,0xf8 |
- | 288 | mov al,ah |
|
176 | 289 | out dx,al |
|
Line -... | Line 290... | ||
- | 290 | ||
- | 291 | pop eax |
|
- | 292 | ; pop esi |
|
- | 293 | ret |
|
Line 177... | Line 294... | ||
177 | pci_read_reg_err: |
294 | |
178 | xor eax,eax |
295 | ;pci_read_reg_err: |
179 | dec eax |
296 | ; or dword [esp+32],-1 |
180 | ret |
297 | ; ret |
Line 193... | Line 310... | ||
193 | ;*************************************************************************** |
310 | ;*************************************************************************** |
Line 194... | Line 311... | ||
194 | 311 | ||
Line 195... | Line 312... | ||
195 | align 4 |
312 | align 4 |
- | 313 | ||
- | 314 | pci_write_reg: |
|
- | 315 | cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? |
|
- | 316 | je pci_write_reg_2 |
|
196 | 317 | ||
197 | pci_write_reg: |
318 | ; mechanism 1 |
198 | push esi ; save register size into ESI |
319 | ; push esi ; save register size into ESI |
Line 199... | Line 320... | ||
199 | mov esi,eax |
320 | mov esi,ebx;eax |
200 | and esi,3 |
321 | and esi,3 ;not need |
- | 322 | ||
201 | 323 | call pci_make_config_cmd |
|
202 | call pci_make_config_cmd |
324 | mov eax,ebx;ebx,eax |
203 | mov ebx,eax |
325 | mov ecx,edx ;cross registers |
204 | ; get current state into ecx |
326 | ; get current state into ecx |
205 | mov dx,0xcf8 |
327 | mov dx,0xcf8 |
Line 213... | Line 335... | ||
213 | mov dl,0xfc |
335 | mov dl,0xfc |
214 | and bl,3 |
336 | and bl,3 |
215 | or dl,bl |
337 | or dl,bl |
216 | mov eax,ecx |
338 | mov eax,ecx |
Line 217... | Line 339... | ||
217 | 339 | ||
218 | or esi,esi |
340 | ; or esi,esi |
219 | jz pci_write_byte1 |
341 | ; jz pci_write_byte1 |
220 | cmp esi,1 |
342 | ; cmp esi,1 |
221 | jz pci_write_word1 |
343 | ; jz pci_write_word1 |
222 | cmp esi,2 |
344 | ; cmp esi,2 |
223 | jz pci_write_dword1 |
345 | ; jz pci_write_dword1 |
- | 346 | ; jmp pci_fin_write1 |
|
224 | jmp pci_fin_write1 |
347 | jmp dword [f62_wcall+esi*4] |
225 | - | ||
226 | pci_write_byte1: |
348 | .0: |
227 | out dx,al |
349 | out dx,al |
228 | jmp pci_fin_write1 |
350 | jmp .pci_fin_write1 |
229 | pci_write_word1: |
351 | .1: |
230 | out dx,ax |
352 | out dx,ax |
231 | jmp pci_fin_write1 |
353 | jmp .pci_fin_write1 |
232 | pci_write_dword1: |
354 | .2: |
233 | out dx,eax |
- | |
234 | jmp pci_fin_write1 |
355 | out dx,eax |
- | 356 | .pci_fin_write1: |
|
235 | pci_fin_write1: |
357 | |
236 | ; restore configuration control |
358 | ; restore configuration control |
237 | pop eax |
359 | pop eax |
238 | mov dl,0xf8 |
360 | mov dl,0xf8 |
Line 239... | Line 361... | ||
239 | out dx,eax |
361 | out dx,eax |
240 | 362 | ||
241 | xor eax,eax |
363 | xor eax,eax |
- | 364 | ;pop esi |
|
- | 365 | ret |
|
- | 366 | pci_write_reg_2: |
|
- | 367 | ||
- | 368 | test ch,128;bh,128 ;mech#2 only supports 16 devices per bus |
|
- | 369 | jnz pci_api.not_support |
|
- | 370 | ||
- | 371 | ||
- | 372 | ; push esi ; save register size into ESI |
|
- | 373 | mov esi,eax |
|
- | 374 | and esi,3 ;not need |
|
- | 375 | ||
- | 376 | push eax |
|
- | 377 | mov ecx,edx ;cross registers |
|
- | 378 | ;store current state of config space |
|
- | 379 | mov dx,0xcf8 |
|
- | 380 | in al,dx |
|
- | 381 | mov ah,al |
|
- | 382 | mov dl,0xfa |
|
- | 383 | in al,dx |
|
- | 384 | xchg eax,[esp] |
|
- | 385 | ; out 0xcfa,bus |
|
- | 386 | mov al,ah |
|
- | 387 | out dx,al |
|
- | 388 | ; out 0xcf8,0x80 |
|
- | 389 | mov dl,0xf8 |
|
- | 390 | mov al,0x80 |
|
- | 391 | out dx,al |
|
- | 392 | ; compute addr |
|
- | 393 | shr bh,3 ; func is ignored in mechanism 2 |
|
- | 394 | or bh,0xc0 |
|
- | 395 | mov dx,bx |
|
- | 396 | ; write register |
|
- | 397 | mov eax,ecx |
|
- | 398 | ||
- | 399 | ; or esi,esi |
|
- | 400 | ; jz pci_write_byte2 |
|
- | 401 | ; cmp esi,1 |
|
- | 402 | ; jz pci_write_word2 |
|
- | 403 | ; cmp esi,2 |
|
- | 404 | ; jz pci_write_dword2 |
|
- | 405 | ; jmp pci_fin_write2 |
|
- | 406 | jmp dword [f62_wcall2+esi*4] |
|
- | 407 | .0: |
|
- | 408 | out dx,al |
|
- | 409 | jmp .pci_fin_write2 |
|
- | 410 | .1: |
|
- | 411 | out dx,ax |
|
- | 412 | jmp .pci_fin_write2 |
|
- | 413 | .2: |
|
- | 414 | out dx,eax |
|
- | 415 | .pci_fin_write2: |
|
- | 416 | ; restore configuration space |
|
- | 417 | pop eax |
|
- | 418 | mov dx,0xcfa |
|
- | 419 | out dx,al |
|
- | 420 | mov dl,0xf8 |
|
Line 242... | Line -... | ||
242 | pop esi |
- | |
243 | ret |
421 | mov al,ah |
244 | 422 | out dx,al |
|
245 | pci_write_reg_err: |
423 | |
Line -... | Line 424... | ||
- | 424 | xor eax,eax |
|
- | 425 | ;pop esi |
|
- | 426 | ret |
|
- | 427 | ||
- | 428 | ;pci_write_reg_err: |
|
- | 429 | ; xor eax,eax |
|
246 | xor eax,eax |
430 | ; dec eax |
247 | dec eax |
431 | ; ret |
248 | ret |
432 | |
249 | 433 | if defined mmio_pci_addr ; must be set above |
|
250 | ;*************************************************************************** |
434 | ;*************************************************************************** |
251 | ; Function |
435 | ; Function |
252 | ; pci_mmio_init |
436 | ; pci_mmio_init |
253 | ; |
437 | ; |
254 | ; Description |
438 | ; Description |
- | 439 | ; IN: cx = device's PCI bus address (bbbbbbbbdddddfff) |
|
255 | ; IN: bx = device's PCI bus address (bbbbbbbbdddddfff) |
440 | ; Returns eax = user heap space available (bytes) |
256 | ; Returns eax = phys. address of user-accessible DMA block |
441 | ; Error codes |
257 | ; Error codes |
442 | ; eax = -1 : PCI user access blocked, |
258 | ; eax = -1 : PCI user access blocked, |
443 | ; eax = -2 : device not registered for uMMIO service |
- | 444 | ; eax = -3 : user heap initialization failure |
|
- | 445 | ;*************************************************************************** |
|
- | 446 | pci_mmio_init: |
|
259 | ; eax = -3 : user heap initialization failure |
447 | cmp cx, mmio_pci_addr |
260 | ;*************************************************************************** |
448 | jz @f |
261 | pci_mmio_init: |
449 | mov eax,-2 |
262 | mov [mmio_pci_addr],bx |
450 | ret |
263 | - | ||
264 | call init_heap ; (if not initialized yet) |
451 | @@: |
265 | or eax,eax |
452 | call init_heap ; (if not initialized yet) |
266 | jz @f |
453 | or eax,eax |
267 | mov eax, [UserDMAaddr] |
454 | jz @f |
Line 276... | Line 463... | ||
276 | ; pci_mmio_map |
463 | ; pci_mmio_map |
277 | ; |
464 | ; |
278 | ; Description |
465 | ; Description |
279 | ; maps a block of PCI memory to user-accessible linear address |
466 | ; maps a block of PCI memory to user-accessible linear address |
280 | ; |
467 | ; |
- | 468 | ; WARNING! This VERY EXPERIMENTAL service is for one chosen PCI device only! |
|
- | 469 | ; The target device address should be set in kernel var mmio_pci_addr |
|
281 | ; |
470 | ; |
282 | ; IN: ah = BAR#; or |
471 | ; IN: ah = BAR#; |
283 | ; IN: ah = 0xDA for DMA-mapping requests; |
- | |
284 | ; IN: ebx = block size (bytes); |
472 | ; IN: ebx = block size (bytes); |
285 | ; IN: ecx = offset in MMIO block (in 4K-pages, to avoid misaligned pages); |
473 | ; IN: ecx = offset in MMIO block (in 4K-pages, to avoid misaligned pages); |
286 | ; |
474 | ; |
287 | ; Returns eax = MMIO block's linear address in the userspace (if no error) |
475 | ; Returns eax = MMIO block's linear address in the userspace (if no error) |
288 | ; |
476 | ; |
Line 294... | Line 482... | ||
294 | ; eax = -4 : a port i/o BAR register referred |
482 | ; eax = -4 : a port i/o BAR register referred |
295 | ; eax = -5 : dynamic userspace allocation problem |
483 | ; eax = -5 : dynamic userspace allocation problem |
296 | ;*************************************************************************** |
484 | ;*************************************************************************** |
Line 297... | Line 485... | ||
297 | 485 | ||
- | 486 | pci_mmio_map: |
|
- | 487 | ;cross |
|
- | 488 | mov eax,ebx |
|
- | 489 | mov ebx,ecx |
|
- | 490 | mov ecx,edx |
|
298 | pci_mmio_map: |
491 | ;;;;;;;;;;;;;;;;;;; |
299 | and edx,0x0ffff |
- | |
300 | cmp ah, 0xDA |
- | |
301 | jz .dma_map |
492 | and edx,0x0ffff |
302 | cmp ah,6 |
493 | cmp ah,6 |
303 | jc .bar_0_5 |
494 | jc .bar_0_5 |
304 | jz .bar_rom |
495 | jz .bar_rom |
305 | mov eax,-2 |
496 | mov eax,-2 |
306 | ret |
- | |
307 | - | ||
308 | .dma_map: |
- | |
309 | push ecx |
- | |
310 | mov ecx,ebx |
- | |
311 | mov eax,[UserDMAaddr] |
- | |
312 | jmp .allocate_block |
- | |
313 | 497 | ret |
|
314 | .bar_rom: |
498 | .bar_rom: |
315 | mov ah, 8 ; bar6 = Expansion ROM base address |
499 | mov ah, 8 ; bar6 = Expansion ROM base address |
316 | .bar_0_5: |
500 | .bar_0_5: |
317 | push ecx |
501 | push ecx |
Line 320... | Line 504... | ||
320 | push ebx |
504 | push ebx |
321 | mov bl, ah ; bl = BAR# (0..5), however bl=8 for BAR6 |
505 | mov bl, ah ; bl = BAR# (0..5), however bl=8 for BAR6 |
322 | shl bl, 1 |
506 | shl bl, 1 |
323 | shl bl, 1 |
507 | shl bl, 1 |
324 | add bl, 0x10 ; now bl = BAR offset in PCI config. space |
508 | add bl, 0x10 ; now bl = BAR offset in PCI config. space |
325 | mov ax, [mmio_pci_addr] |
509 | mov ax, mmio_pci_addr |
326 | mov bh, al ; bh = dddddfff |
510 | mov bh, al ; bh = dddddfff |
327 | mov al, 2 ; al : DW to read |
511 | mov al, 2 ; al : DW to read |
328 | call pci_read_reg |
512 | call pci_read_reg |
329 | or eax, eax |
513 | or eax, eax |
330 | jnz @f |
514 | jnz @f |
Line 337... | Line 521... | ||
337 | jmp mmio_ret_fail |
521 | jmp mmio_ret_fail |
338 | @@: |
522 | @@: |
339 | pop ecx ; ecx = block size, bytes (expanded to whole page) |
523 | pop ecx ; ecx = block size, bytes (expanded to whole page) |
340 | mov ebx, ecx ; user_alloc destroys eax, ecx, edx, but saves ebx |
524 | mov ebx, ecx ; user_alloc destroys eax, ecx, edx, but saves ebx |
341 | and eax, 0xFFFFFFF0 |
525 | and eax, 0xFFFFFFF0 |
342 | - | ||
343 | .allocate_block: |
- | |
344 | push eax ; store MMIO physical address + keep the stack 2x4b deep |
526 | push eax ; store MMIO physical address + keep 2DWords in the stack |
345 | stdcall user_alloc, ecx |
527 | stdcall user_alloc, ecx |
346 | or eax, eax |
528 | or eax, eax |
347 | jnz mmio_map_over |
529 | jnz mmio_map_over |
348 | mov eax,-5 ; problem with page allocation |
530 | mov eax,-5 ; problem with page allocation |
Line 358... | Line 540... | ||
358 | mov ebx, eax ; ebx = linear address |
540 | mov ebx, eax ; ebx = linear address |
359 | pop eax ; eax = MMIO start |
541 | pop eax ; eax = MMIO start |
360 | pop edx ; edx = MMIO shift (pages) |
542 | pop edx ; edx = MMIO shift (pages) |
361 | shl edx, 12 ; edx = MMIO shift (bytes) |
543 | shl edx, 12 ; edx = MMIO shift (bytes) |
362 | add eax, edx ; eax = uMMIO physical address |
544 | add eax, edx ; eax = uMMIO physical address |
- | 545 | or eax, PG_SHARED |
|
- | 546 | or eax, PG_UW |
|
363 | or eax, (PG_SHARED+PG_UW+PG_NOCACHE) |
547 | or eax, PG_NOCACHE |
364 | mov edi, ebx |
548 | mov edi, ebx |
365 | call commit_pages |
549 | call commit_pages |
366 | mov eax, edi |
550 | mov eax, edi |
367 | ret |
551 | ret |
Line 380... | Line 564... | ||
380 | ; eax = -1 if no user PCI access allowed, |
564 | ; eax = -1 if no user PCI access allowed, |
381 | ; eax = 0 if unmapping failed |
565 | ; eax = 0 if unmapping failed |
382 | ;*************************************************************************** |
566 | ;*************************************************************************** |
Line 383... | Line 567... | ||
383 | 567 | ||
384 | pci_mmio_unmap: |
568 | pci_mmio_unmap: |
385 | stdcall user_free, ebx |
569 | stdcall user_free, ecx;ebx |
Line -... | Line 570... | ||
- | 570 | ret |
|
- | 571 | ||
386 | ret |
572 | end if |
387 | 573 | ||
388 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
574 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
389 | uglobal |
575 | uglobal |
390 | align 4 |
576 | align 4 |