Subversion Repositories Kolibri OS

Rev

Rev 1462 | Rev 1598 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1462 Rev 1591
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
;;                                                              ;;
Line 19... Line 19...
19
;;                                                              ;;
19
;;                                                              ;;
20
;;  See file COPYING for details                                ;;
20
;;  See file COPYING for details                                ;;
21
;;                                                              ;;
21
;;                                                              ;;
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 23... Line 23...
23
 
23
 
Line 24... Line 24...
24
$Revision: 1462 $
24
$Revision: 1591 $
25
 
25
 
26
;***************************************************************************
26
;***************************************************************************
27
;   Function
27
;   Function
28
;      pci_api:
28
;      pci_api:
29
;
29
;
30
;   Description
30
;   Description
31
;       entry point for system PCI calls
31
;       entry point for system PCI calls
Line 32... Line 32...
32
;***************************************************************************
32
;***************************************************************************
33
;mmio_pci_addr	equ  0x400		 ; set actual PCI address here to activate user-MMIO
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 34... Line -...
34
 
-
 
Line -... Line 68...
-
 
68
	dd	pci_write_reg_2.1	;5 word
-
 
69
	dd	pci_write_reg_2.2	;6 dword
-
 
70
endg
35
 
71
 
36
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
Line -... Line 84...
-
 
84
        jb .not_support
-
 
85
end if	
37
 
86
        call dword [f62call+eax*4]
38
pci_api:
87
        mov	dword [esp+32],eax
39
 
88
        ret
-
 
89
 
40
	cmp  [pci_access_enabled],1
90
 
41
	jne  no_pci_access_for_applications
91
 
Line 42... Line 92...
42
 
92
;	or al,al
43
	or al,al
93
;	jnz pci_fn_1
44
	jnz pci_fn_1
94
	; PCI function 0: get pci version (AH.AL)
Line 45... Line 95...
45
	; PCI function 0: get pci version (AH.AL)
95
.0:
-
 
96
	movzx	eax, word [BOOT_VAR+0x9022]
46
	movzx eax,word [BOOT_VAR+0x9022]
97
	ret
47
	ret
98
 
Line 48... Line 99...
48
 
99
;pci_fn_1:
49
pci_fn_1:
100
;	cmp al,1
50
	cmp al,1
101
;	jnz pci_fn_2
51
	jnz pci_fn_2
102
 
-
 
103
	; PCI function 1: get last bus in AL
52
 
104
.1:
53
	; PCI function 1: get last bus in AL
105
	movzx	eax, byte [BOOT_VAR+0x9021]
54
	mov al,[BOOT_VAR+0x9021]
106
	ret
55
	ret
-
 
56
 
-
 
57
pci_fn_2:
-
 
58
	cmp al,2
-
 
59
	jne pci_fn_3
-
 
60
	; PCI function 2: get pci access mechanism
-
 
61
	mov al,[BOOT_VAR+0x9020]
-
 
62
	ret
-
 
63
pci_fn_3:
-
 
64
 
-
 
65
	cmp al,4
-
 
66
	jz pci_read_reg   ;byte
-
 
67
	cmp al,5
-
 
68
	jz pci_read_reg   ;word
-
 
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
69
	cmp al,6
121
;	cmp al,6
70
	jz pci_read_reg   ;dword
122
;	jz pci_read_reg   ;dword
71
 
123
 
72
	cmp al,8
124
;	cmp al,8
73
	jz pci_write_reg  ;byte
125
;	jz pci_write_reg  ;byte
74
	cmp al,9
126
;	cmp al,9
75
	jz pci_write_reg  ;word
127
;	jz pci_write_reg  ;word
76
	cmp al,10
128
;	cmp al,10
77
	jz pci_write_reg  ;dword
-
 
78
 
-
 
Line -... Line 129...
-
 
129
;	jz pci_write_reg  ;dword
-
 
130
 
79
if defined mmio_pci_addr
131
;if defined mmio_pci_addr
80
	cmp al,11	    ;  user-level MMIO functions 
-
 
81
	jz pci_mmio_init
132
;	cmp al,11	    ;  user-level MMIO functions 
Line 82... Line 133...
82
	cmp al,12
133
;	jz pci_mmio_init
83
	jz pci_mmio_map
134
;	cmp al,12
84
	cmp al,13
135
;	jz pci_mmio_map
85
	jz pci_mmio_unmap
136
;	cmp al,13
86
end if
137
;	jz pci_mmio_unmap
87
 
138
;end if
88
      no_pci_access_for_applications:
139
 
89
 
140
.not_support:
90
	or eax,-1
141
.no_pci_access_for_applications:
91
 
142
	or 	eax,-1
92
	ret
143
	ret
93
 
144
 
Line 94... Line 145...
94
;***************************************************************************
145
;***************************************************************************
Line 95... Line 146...
95
;   Function
146
;   Function
96
;      pci_make_config_cmd
147
;      pci_make_config_cmd
97
;
148
;
98
;   Description
149
;   Description
99
;       creates a command dword  for use with the PCI bus
150
;       creates a command dword  for use with the PCI bus
100
;       bus # in ah
151
;       bus # in bh;ah
Line 101... Line 152...
101
;       device+func in bh (dddddfff)
152
;       device+func in ch;bh (dddddfff)
102
;       register in bl
153
;       register in cl;bl
103
;
154
;
Line 129... Line 180...
129
pci_read_reg:
180
pci_read_reg:
130
	cmp	byte [BOOT_VAR+0x9020],2 ;what mechanism will we use?
181
	cmp	byte [BOOT_VAR+0x9020],2 ;what mechanism will we use?
131
	je	pci_read_reg_2
182
	je	pci_read_reg_2
Line 132... Line 183...
132
 
183
 
133
		; mechanism 1
184
		; mechanism 1
134
	push	esi   ; save register size into ESI
185
;	push	esi   ; save register size into ESI
135
	mov	esi,eax
186
	mov	esi,ebx;eax
Line 136... Line 187...
136
	and	esi,3
187
	and	esi,3
137
 
188
 
138
	call	pci_make_config_cmd
189
	call	pci_make_config_cmd
139
	mov	ebx,eax
190
	mov	eax,ebx;ebx,eax
140
		; get current state
191
		; get current state
141
	mov	dx,0xcf8
192
	mov	dx,0xcf8
142
	in	eax, dx
193
	in	eax, dx
Line 148... Line 199...
148
		; get requested DWORD of config data
199
		; get requested DWORD of config data
149
	mov	dl,0xfc
200
	mov	dl,0xfc
150
	and	bl,3
201
	and	bl,3
151
	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 152... Line 203...
152
 
203
 
153
	or	esi,esi
204
;	or	esi,esi
154
	jz	pci_read_byte1
205
;	jz	pci_read_byte1
155
	cmp	esi,1
206
;	cmp	esi,1
156
	jz	pci_read_word1
207
;	jz	pci_read_word1
157
	cmp	esi,2
208
;	cmp	esi,2
158
	jz	pci_read_dword1
209
;	jz	pci_read_dword1
-
 
210
;	jmp	pci_fin_read1
Line 159... Line 211...
159
	jmp	pci_fin_read1
211
	jmp	dword [f62_rcall+esi*4]
160
 
212
 
161
pci_read_byte1:
213
.0:
162
	in	al,dx
214
	in	al,dx
163
	jmp pci_fin_read1
215
	jmp .pci_fin_read1
164
pci_read_word1:
216
.1:
165
	in	ax,dx
217
	in	ax,dx
166
	jmp pci_fin_read1
218
	jmp .pci_fin_read1
167
pci_read_dword1:
219
.2:
168
	in	eax,dx
220
	in	eax,dx
169
	jmp	pci_fin_read1
221
;	jmp	pci_fin_read1
170
pci_fin_read1:
222
.pci_fin_read1:
171
		; restore configuration control
223
		; restore configuration control
172
	xchg	eax,[esp]
224
	xchg	eax,[esp]
Line 173... Line 225...
173
	mov	dx,0xcf8
225
	mov	dx,0xcf8
174
	out	dx,eax
226
	out	dx,eax
175
 
227
 
176
	pop	eax
228
	pop	eax
Line 177... Line 229...
177
	pop	esi
229
	;pop	esi
178
	ret
230
	ret
Line 179... Line 231...
179
pci_read_reg_2:
231
pci_read_reg_2:
180
 
232
 
181
	test	bh,128	;mech#2 only supports 16 devices per bus
233
	test	ch,128;bh,128	;mech#2 only supports 16 devices per bus
Line 182... Line 234...
182
	jnz	pci_read_reg_err
234
	jnz	pci_api.not_support
-
 
235
 
183
 
236
;	push esi   ; save register size into ESI
184
	push esi   ; save register size into ESI
237
	mov esi,ebx;eax
185
	mov esi,eax
238
	and esi,3
186
	and esi,3
239
 
187
 
240
	push	ebx;eax
Line 200... Line 253...
200
		; out 0xcf8,0x80
253
		; out 0xcf8,0x80
201
	mov	dl,0xf8
254
	mov	dl,0xf8
202
	mov	al,0x80
255
	mov	al,0x80
203
	out	dx,al
256
	out	dx,al
204
		; compute addr
257
		; compute addr
205
	shr	bh,3 ; func is ignored in mechanism 2
258
	shr	ch,3;bh,3 ; func is ignored in mechanism 2
206
	or	bh,0xc0
259
	or	ch,0xc0;bh,0xc0
207
	mov	dx,bx
260
	mov	dx,cx;bx
208
 
261
 
209
	or	esi,esi
262
;	or	esi,esi
210
	jz	pci_read_byte2
263
;	jz	pci_read_byte2
211
	cmp	esi,1
264
;	cmp	esi,1
212
	jz	pci_read_word2
265
;	jz	pci_read_word2
213
	cmp	esi,2
266
;	cmp	esi,2
214
	jz	pci_read_dword2
267
;	jz	pci_read_dword2
215
	jmp	pci_fin_read2
268
;	jmp	pci_fin_read2
-
 
269
	jmp	dword [f62_rcall2+esi*4]
Line 216... Line 270...
216
 
270
 
217
pci_read_byte2:
271
.0:
218
	in	al,dx
272
	in	al,dx
219
	jmp pci_fin_read2
273
	jmp .pci_fin_read2
220
pci_read_word2:
274
.1:
221
	in	ax,dx
275
	in	ax,dx
222
	jmp pci_fin_read2
276
	jmp .pci_fin_read2
223
pci_read_dword2:
277
.2:
224
	in	eax,dx
278
	in	eax,dx
-
 
279
;       jmp pci_fin_read2
225
;       jmp pci_fin_read2
280
 
Line 226... Line 281...
226
pci_fin_read2:
281
.pci_fin_read2:
227
 
282
 
228
		; restore configuration space
283
		; restore configuration space
229
	xchg	eax,[esp]
284
	xchg	eax,[esp]
230
	mov	dx,0xcfa
285
	mov	dx,0xcfa
231
	out	dx,al
286
	out	dx,al
232
	mov	dl,0xf8
287
	mov	dl,0xf8
Line 233... Line 288...
233
	mov	al,ah
288
	mov	al,ah
234
	out	dx,al
289
	out	dx,al
235
 
290
 
Line 236... Line 291...
236
	pop	eax
291
	pop	eax
237
	pop	esi
292
;	pop	esi
238
	ret
-
 
239
 
293
	ret
Line 240... Line 294...
240
pci_read_reg_err:
294
 
241
	xor	eax,eax
295
;pci_read_reg_err:
242
	dec	eax
296
;	or 	dword [esp+32],-1
Line 260... Line 314...
260
pci_write_reg:
314
pci_write_reg:
261
	cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use?
315
	cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use?
262
	je pci_write_reg_2
316
	je pci_write_reg_2
Line 263... Line 317...
263
 
317
 
264
		; mechanism 1
318
		; mechanism 1
265
	push	esi   ; save register size into ESI
319
;	push	esi   ; save register size into ESI
266
	mov	esi,eax
320
	mov	esi,ebx;eax
Line 267... Line 321...
267
	and	esi,3
321
	and	esi,3	;not need
268
 
322
 
-
 
323
	call	pci_make_config_cmd
269
	call	pci_make_config_cmd
324
	mov	eax,ebx;ebx,eax
270
	mov	ebx,eax
325
	mov	ecx,edx		;cross registers
271
		; get current state into ecx
326
		; get current state into ecx
272
	mov	dx,0xcf8
327
	mov	dx,0xcf8
273
	in	eax, dx
328
	in	eax, dx
Line 280... Line 335...
280
	mov	dl,0xfc
335
	mov	dl,0xfc
281
	and	bl,3
336
	and	bl,3
282
	or	dl,bl
337
	or	dl,bl
283
	mov	eax,ecx
338
	mov	eax,ecx
Line 284... Line 339...
284
 
339
 
285
	or	esi,esi
340
;	or	esi,esi
286
	jz	pci_write_byte1
341
;	jz	pci_write_byte1
287
	cmp	esi,1
342
;	cmp	esi,1
288
	jz	pci_write_word1
343
;	jz	pci_write_word1
289
	cmp	esi,2
344
;	cmp	esi,2
290
	jz	pci_write_dword1
345
;	jz	pci_write_dword1
-
 
346
;	jmp	pci_fin_write1
291
	jmp	pci_fin_write1
347
	jmp	dword [f62_wcall+esi*4]
292
 
-
 
293
pci_write_byte1:
348
.0:
294
	out	dx,al
349
	out	dx,al
295
	jmp pci_fin_write1
350
	jmp .pci_fin_write1
296
pci_write_word1:
351
.1:
297
	out	dx,ax
352
	out	dx,ax
298
	jmp pci_fin_write1
353
	jmp .pci_fin_write1
299
pci_write_dword1:
354
.2:
300
	out	dx,eax
-
 
301
	jmp	pci_fin_write1
355
	out	dx,eax
Line 302... Line 356...
302
pci_fin_write1:
356
.pci_fin_write1:
303
 
357
 
304
		; restore configuration control
358
		; restore configuration control
305
	pop	eax
359
	pop	eax
Line 306... Line 360...
306
	mov	dl,0xf8
360
	mov	dl,0xf8
307
	out	dx,eax
361
	out	dx,eax
308
 
-
 
309
	xor	eax,eax
362
 
310
	pop	esi
363
	xor	eax,eax
Line 311... Line 364...
311
 
364
	;pop	esi
312
	ret
365
	ret
Line 313... Line 366...
313
pci_write_reg_2:
366
pci_write_reg_2:
314
 
367
 
315
	test	bh,128	;mech#2 only supports 16 devices per bus
368
	test	ch,128;bh,128	;mech#2 only supports 16 devices per bus
Line 316... Line 369...
316
	jnz	pci_write_reg_err
369
	jnz	pci_api.not_support
-
 
370
 
317
 
371
 
318
 
372
;	push esi   ; save register size into ESI
319
	push esi   ; save register size into ESI
373
	mov esi,eax
320
	mov esi,eax
374
	and esi,3	;not need
321
	and esi,3
375
 
Line 340... Line 394...
340
	or	bh,0xc0
394
	or	bh,0xc0
341
	mov	dx,bx
395
	mov	dx,bx
342
		; write register
396
		; write register
343
	mov	eax,ecx
397
	mov	eax,ecx
Line 344... Line 398...
344
 
398
 
345
	or	esi,esi
399
;	or	esi,esi
346
	jz	pci_write_byte2
400
;	jz	pci_write_byte2
347
	cmp	esi,1
401
;	cmp	esi,1
348
	jz	pci_write_word2
402
;	jz	pci_write_word2
349
	cmp	esi,2
403
;	cmp	esi,2
350
	jz	pci_write_dword2
404
;	jz	pci_write_dword2
-
 
405
;	jmp	pci_fin_write2
351
	jmp	pci_fin_write2
406
	jmp	dword [f62_wcall2+esi*4]
352
 
-
 
353
pci_write_byte2:
407
.0:
354
	out	dx,al
408
	out	dx,al
355
	jmp pci_fin_write2
409
	jmp .pci_fin_write2
356
pci_write_word2:
410
.1:
357
	out	dx,ax
411
	out	dx,ax
358
	jmp pci_fin_write2
412
	jmp .pci_fin_write2
359
pci_write_dword2:
413
.2:
360
	out	dx,eax
-
 
361
	jmp	pci_fin_write2
414
	out	dx,eax
362
pci_fin_write2:
415
.pci_fin_write2:
363
		; restore configuration space
416
		; restore configuration space
364
	pop	eax
417
	pop	eax
365
	mov	dx,0xcfa
418
	mov	dx,0xcfa
366
	out	dx,al
419
	out	dx,al
367
	mov	dl,0xf8
420
	mov	dl,0xf8
368
	mov	al,ah
421
	mov	al,ah
Line 369... Line 422...
369
	out	dx,al
422
	out	dx,al
370
 
423
 
371
	xor	eax,eax
424
	xor	eax,eax
Line 372... Line 425...
372
	pop	esi
425
	;pop	esi
373
	ret
426
	ret
374
 
427
 
375
pci_write_reg_err:
428
;pci_write_reg_err:
Line 376... Line 429...
376
	xor	eax,eax
429
;	xor	eax,eax
377
	dec	eax
430
;	dec	eax
378
	ret
431
;	ret
379
 
432
 
380
if defined mmio_pci_addr	; must be set above
433
if defined mmio_pci_addr	; must be set above
381
;***************************************************************************
434
;***************************************************************************
382
;   Function
435
;   Function
383
;      pci_mmio_init 
436
;      pci_mmio_init 
384
;
437
;
385
;   Description
438
;   Description
386
;       IN:  bx = device's PCI bus address (bbbbbbbbdddddfff)
439
;       IN:  cx = device's PCI bus address (bbbbbbbbdddddfff)
387
;   Returns  eax = user heap space available (bytes)
440
;   Returns  eax = user heap space available (bytes)
388
;   Error codes
441
;   Error codes
389
;       eax = -1 : PCI user access blocked,
442
;       eax = -1 : PCI user access blocked,
390
;       eax = -2 : device not registered for uMMIO service
443
;       eax = -2 : device not registered for uMMIO service
391
;       eax = -3 : user heap initialization failure
444
;       eax = -3 : user heap initialization failure
392
;***************************************************************************
445
;***************************************************************************
393
pci_mmio_init:
446
pci_mmio_init:
394
    cmp     bx, mmio_pci_addr	
447
    cmp     cx, mmio_pci_addr	
395
    jz	    @f
448
    jz	    @f
Line 429... Line 482...
429
;       eax = -4 : a port i/o BAR register referred
482
;       eax = -4 : a port i/o BAR register referred
430
;       eax = -5 : dynamic userspace allocation problem
483
;       eax = -5 : dynamic userspace allocation problem
431
;***************************************************************************
484
;***************************************************************************
Line 432... Line 485...
432
 
485
 
-
 
486
pci_mmio_map:
-
 
487
;cross
-
 
488
	mov	eax,ebx
-
 
489
	mov	ebx,ecx
-
 
490
	mov	ecx,edx
433
pci_mmio_map:
491
;;;;;;;;;;;;;;;;;;;
434
    and     edx,0x0ffff
492
    and     edx,0x0ffff
435
    cmp     ah,6
493
    cmp     ah,6
436
    jc     .bar_0_5
494
    jc     .bar_0_5
437
    jz     .bar_rom
495
    jz     .bar_rom
Line 506... Line 564...
506
;       eax = -1 if no user PCI access allowed,
564
;       eax = -1 if no user PCI access allowed,
507
;       eax =  0 if unmapping failed
565
;       eax =  0 if unmapping failed
508
;***************************************************************************
566
;***************************************************************************
Line 509... Line 567...
509
 
567
 
510
pci_mmio_unmap:
568
pci_mmio_unmap:
511
    stdcall user_free, ebx
569
    stdcall user_free, ecx;ebx
Line 512... Line 570...
512
    ret
570
    ret
Line 513... Line 571...
513
 
571