Subversion Repositories Kolibri OS

Rev

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

Rev 1598 Rev 1602
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2007. 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: 1598 $
24
$Revision: 1602 $
25
 
25
 
26
;***************************************************************************
26
;***************************************************************************
27
;   Function
27
;   Function
Line 33... Line 33...
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
Line 34... Line 34...
34
 
34
 
35
iglobal
35
iglobal
36
align 4
36
align 4
37
f62call:
37
f62call:
38
	dd	pci_api.0
38
	dd	pci_fn_0
39
	dd	pci_api.1
39
	dd	pci_fn_1
40
	dd	pci_api.2
40
	dd	pci_fn_2
41
	dd	pci_api.not_support	;3
41
	dd	pci_service_not_supported	;3
42
	dd	pci_read_reg		;4 byte
42
	dd	pci_read_reg		;4 byte
43
	dd	pci_read_reg            ;5 word
43
	dd	pci_read_reg            ;5 word
44
	dd	pci_read_reg            ;6 dword
44
	dd	pci_read_reg            ;6 dword
45
	dd	pci_api.not_support     ;7 
45
	dd	pci_service_not_supported   ;7 
46
	dd	pci_write_reg           ;8 byte
46
	dd	pci_write_reg           ;8 byte
47
	dd	pci_write_reg           ;9 word
47
	dd	pci_write_reg           ;9 word
48
	dd	pci_write_reg           ;10 dword
48
	dd	pci_write_reg           ;10 dword
49
if defined mmio_pci_addr
49
if defined mmio_pci_addr
50
	dd	pci_mmio_init		;11
50
	dd	pci_mmio_init		;11
51
	dd	pci_mmio_map		;12
51
	dd	pci_mmio_map		;12
52
	dd	pci_mmio_unmap		;13
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
-
 
68
	dd	pci_write_reg_2.1	;5 word
-
 
69
	dd	pci_write_reg_2.2	;6 dword
-
 
Line -... Line 53...
-
 
53
end if
Line 70... Line 54...
70
endg
54
 
-
 
55
endg
71
 
56
 
72
 
-
 
73
align 4
57
align 4
74
pci_api:
58
 
-
 
59
pci_api:
-
 
60
	cmp  [pci_access_enabled],1
-
 
61
	jne  pci_service_not_supported
-
 
62
 
-
 
63
;cross
-
 
64
	mov	eax,ebx
Line 75... Line 65...
75
        movzx	eax,bl
65
	mov	ebx,ecx
76
	cmp  [pci_access_enabled],1
66
	mov	ecx,edx
77
	jne  .no_pci_access_for_applications
67
;;;;;;;;;;;;;;;;;;;
78
 
68
 
79
if defined mmio_pci_addr
69
if defined mmio_pci_addr
80
        cmp eax, 13
70
        cmp eax, 13
81
        jb .not_support
71
        jb pci_service_not_supported
-
 
72
else
82
else
73
        cmp eax, 10
83
        cmp eax, 10
74
        jb pci_service_not_supported
84
        jb .not_support
75
end if
-
 
76
	
Line 85... Line -...
85
end if	
-
 
86
        call dword [f62call+eax*4]
-
 
87
        mov	dword [esp+32],eax
-
 
88
        ret
77
        call 	dword [f62call+eax*4]
89
 
78
        mov	dword [esp+32],eax
90
 
-
 
91
 
79
        ret
92
;	or al,al
80
;; ============================================
Line 93... Line 81...
93
;	jnz pci_fn_1
81
 
94
	; PCI function 0: get pci version (AH.AL)
-
 
95
.0:
-
 
96
	movzx	eax, word [BOOT_VAR+0x9022]
-
 
97
	ret
82
pci_fn_0:
98
 
-
 
99
;pci_fn_1:
83
; PCI function 0: get pci version (AH.AL)
100
;	cmp al,1
84
	movzx eax,word [BOOT_VAR+0x9022]
Line 101... Line 85...
101
;	jnz pci_fn_2
85
	ret
102
 
-
 
103
	; PCI function 1: get last bus in AL
-
 
104
.1:
86
 
105
	movzx	eax, byte [BOOT_VAR+0x9021]
-
 
106
	ret
87
pci_fn_1:
107
 
88
; PCI function 1: get last bus in AL
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
-
 
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
-
 
129
;	jz pci_write_reg  ;dword
-
 
130
 
-
 
131
;if defined mmio_pci_addr
-
 
Line 132... Line 89...
132
;	cmp al,11	    ;  user-level MMIO functions 
89
	mov al,[BOOT_VAR+0x9021]
133
;	jz pci_mmio_init
-
 
134
;	cmp al,12
90
	ret
135
;	jz pci_mmio_map
91
 
Line 136... Line 92...
136
;	cmp al,13
92
pci_fn_2:
137
;	jz pci_mmio_unmap
93
; PCI function 2: get pci access mechanism
138
;end if
94
	mov al,[BOOT_VAR+0x9020]
139
 
95
	ret
140
.not_support:
96
 
141
.no_pci_access_for_applications:
97
pci_service_not_supported:
142
	or 	eax,-1
98
	or eax,-1
143
	ret
99
	ret
144
 
100
 
145
;***************************************************************************
101
;***************************************************************************
146
;   Function
102
;   Function
147
;      pci_make_config_cmd
103
;      pci_make_config_cmd
Line 148... Line 104...
148
;
104
;
Line 149... Line 105...
149
;   Description
105
;   Description
150
;       creates a command dword  for use with the PCI bus
106
;       creates a command dword  for use with the PCI bus
151
;       bus # in bh;ah
107
;       bus # in ah
152
;       device+func in ch;bh (dddddfff)
108
;       device+func in bh (dddddfff)
153
;       register in cl;bl
109
;       register in bl
154
;
110
;
Line 155... Line 111...
155
;      command dword returned in ebx;eax ( 10000000 bbbbbbbb dddddfff rrrrrr00 )
111
;      command dword returned in eax ( 10000000 bbbbbbbb dddddfff rrrrrr00 )
156
;***************************************************************************
112
;***************************************************************************
157
 
113
 
158
align 4
114
align 4
159
 
115
 
160
pci_make_config_cmd:
116
pci_make_config_cmd:
161
    shl     ebx,8;eax,8	   ; move bus to bits 16-23
117
    shl     eax,8	   ; move bus to bits 16-23
162
    mov     bx,cx;ax,bx	   ; combine all
118
    mov     ax,bx	   ; combine all
163
    and     ebx,0xffffff;eax,0xffffff
119
    and     eax,0xffffff
164
    or	    ebx,0x80000000;eax,0x80000000
120
    or	    eax,0x80000000
Line 165... Line 121...
165
    ret
121
    ret
Line 166... Line 122...
166
 
122
 
167
;***************************************************************************
123
;***************************************************************************
168
;   Function
124
;   Function
Line 169... Line 125...
169
;      pci_read_reg:
125
;      pci_read_reg:
170
;
126
;
171
;   Description
127
;   Description
172
;       read a register from the PCI config space into EAX/AX/AL
128
;       read a register from the PCI config space into EAX/AX/AL
Line 173... Line 129...
173
;       IN: bh=bus,device+func=ch,register address=cl
129
;       IN: ah=bus,device+func=bh,register address=bl
174
;           number of bytes to read (1,2,4) coded into BL, bits 0-1
130
;           number of bytes to read (1,2,4) coded into AL, bits 0-1
175
;           (0 - byte, 1 - word, 2 - dword)
131
;           (0 - byte, 1 - word, 2 - dword)
176
;***************************************************************************
132
;***************************************************************************
177
 
133
 
178
align 4
134
align 4
179
 
135
 
Line 199... Line 155...
199
		; get requested DWORD of config data
155
		; get requested DWORD of config data
200
	mov	dl,0xfc
156
	mov	dl,0xfc
201
	and	bl,3
157
	and	bl,3
202
	or	dl,bl	 ; add to port address first 2 bits of register address
158
	or	dl,bl	 ; add to port address first 2 bits of register address
Line 203... Line 159...
203
 
159
 
204
;	or	esi,esi
160
	or	esi,esi
205
;	jz	pci_read_byte1
161
	jz	pci_read_byte1
206
;	cmp	esi,1
162
	cmp	esi,1
207
;	jz	pci_read_word1
163
	jz	pci_read_word1
208
;	cmp	esi,2
164
	cmp	esi,2
209
;	jz	pci_read_dword1
165
	jz	pci_read_dword1
210
;	jmp	pci_fin_read1
-
 
Line 211... Line 166...
211
	jmp	dword [f62_rcall+esi*4]
166
	jmp	pci_fin_read1
212
 
167
 
213
.0:
168
pci_read_byte1:
214
	in	al,dx
169
	in	al,dx
215
	jmp .pci_fin_read1
170
	jmp pci_fin_read1
216
.1:
171
pci_read_word1:
217
	in	ax,dx
172
	in	ax,dx
218
	jmp .pci_fin_read1
173
	jmp pci_fin_read1
219
.2:
174
pci_read_dword1:
220
	in	eax,dx
175
	in	eax,dx
221
;	jmp	pci_fin_read1
176
	jmp	pci_fin_read1
222
.pci_fin_read1:
177
pci_fin_read1:
223
		; restore configuration control
178
		; restore configuration control
224
	xchg	eax,[esp]
179
	xchg	eax,[esp]
Line 225... Line 180...
225
	mov	dx,0xcf8
180
	mov	dx,0xcf8
226
	out	dx,eax
181
	out	dx,eax
227
 
182
 
228
	pop	eax
183
	pop	eax
Line 229... Line 184...
229
	;pop	esi
184
	pop	esi
230
	ret
185
	ret
Line 231... Line 186...
231
pci_read_reg_2:
186
pci_read_reg_2:
232
 
187
 
233
	test	ch,128;bh,128	;mech#2 only supports 16 devices per bus
188
	test	bh,128	;mech#2 only supports 16 devices per bus
Line 234... Line 189...
234
	jnz	pci_api.not_support
189
	jnz	pci_read_reg_err
235
 
-
 
236
;	push esi   ; save register size into ESI
190
 
237
	mov esi,ebx;eax
191
	push esi   ; save register size into ESI
238
	and esi,3
192
	mov esi,eax
239
 
193
	and esi,3
240
	push	ebx;eax
194
 
Line 253... Line 207...
253
		; out 0xcf8,0x80
207
		; out 0xcf8,0x80
254
	mov	dl,0xf8
208
	mov	dl,0xf8
255
	mov	al,0x80
209
	mov	al,0x80
256
	out	dx,al
210
	out	dx,al
257
		; compute addr
211
		; compute addr
258
	shr	ch,3;bh,3 ; func is ignored in mechanism 2
212
	shr	bh,3 ; func is ignored in mechanism 2
259
	or	ch,0xc0;bh,0xc0
213
	or	bh,0xc0
260
	mov	dx,cx;bx
214
	mov	dx,bx
261
 
-
 
262
;	or	esi,esi
-
 
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]
-
 
Line -... Line 215...
-
 
215
 
-
 
216
	or	esi,esi
-
 
217
	jz	pci_read_byte2
-
 
218
	cmp	esi,1
-
 
219
	jz	pci_read_word2
-
 
220
	cmp	esi,2
-
 
221
	jz	pci_read_dword2
270
 
222
	jmp	pci_fin_read2
-
 
223
 
271
.0:
224
pci_read_byte2:
272
	in	al,dx
225
	in	al,dx
273
	jmp .pci_fin_read2
226
	jmp pci_fin_read2
274
.1:
227
pci_read_word2:
275
	in	ax,dx
228
	in	ax,dx
276
	jmp .pci_fin_read2
229
	jmp pci_fin_read2
277
.2:
230
pci_read_dword2:
278
	in	eax,dx
231
	in	eax,dx
279
;       jmp pci_fin_read2
-
 
280
 
232
;       jmp pci_fin_read2
Line 281... Line 233...
281
.pci_fin_read2:
233
pci_fin_read2:
282
 
234
 
283
		; restore configuration space
235
		; restore configuration space
284
	xchg	eax,[esp]
236
	xchg	eax,[esp]
285
	mov	dx,0xcfa
237
	mov	dx,0xcfa
286
	out	dx,al
238
	out	dx,al
287
	mov	dl,0xf8
239
	mov	dl,0xf8
Line 288... Line 240...
288
	mov	al,ah
240
	mov	al,ah
289
	out	dx,al
241
	out	dx,al
290
 
242
 
Line 291... Line 243...
291
	pop	eax
243
	pop	eax
292
;	pop	esi
244
	pop	esi
-
 
245
	ret
293
	ret
246
 
Line 294... Line 247...
294
 
247
pci_read_reg_err:
295
;pci_read_reg_err:
248
	xor	eax,eax
296
;	or 	dword [esp+32],-1
249
	dec	eax
297
;	ret
250
	ret
298
 
251
 
299
 
252
 
300
;***************************************************************************
253
;***************************************************************************
301
;   Function
254
;   Function
302
;      pci_write_reg:
255
;      pci_write_reg:
303
;
256
;
304
;   Description
257
;   Description
Line 305... Line 258...
305
;       write a register from ECX/CX/CL into the PCI config space
258
;       write a register from ECX/CX/CL into the PCI config space
Line 306... Line 259...
306
;       IN: bh=bus,device+func=ch,register address (dword aligned)=cl,
259
;       IN: ah=bus,device+func=bh,register address (dword aligned)=bl,
307
;           value to write in edx
260
;           value to write in ecx
308
;           number of bytes to write (1,2,4) coded into BL, bits 0-1
261
;           number of bytes to write (1,2,4) coded into AL, bits 0-1
Line 309... Line 262...
309
;           (0 - byte, 1 - word, 2 - dword)
262
;           (0 - byte, 1 - word, 2 - dword)
310
;***************************************************************************
263
;***************************************************************************
311
 
264
 
312
align 4
265
align 4
Line 313... Line 266...
313
 
266
 
314
pci_write_reg:
267
pci_write_reg:
315
	cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use?
-
 
316
	je pci_write_reg_2
268
	cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use?
317
 
269
	je pci_write_reg_2
318
		; mechanism 1
270
 
319
;	push	esi   ; save register size into ESI
271
		; mechanism 1
320
	mov	esi,ebx;eax
272
	push	esi   ; save register size into ESI
Line 335... Line 287...
335
	mov	dl,0xfc
287
	mov	dl,0xfc
336
	and	bl,3
288
	and	bl,3
337
	or	dl,bl
289
	or	dl,bl
338
	mov	eax,ecx
290
	mov	eax,ecx
Line 339... Line 291...
339
 
291
 
340
;	or	esi,esi
292
	or	esi,esi
341
;	jz	pci_write_byte1
293
	jz	pci_write_byte1
342
;	cmp	esi,1
294
	cmp	esi,1
343
;	jz	pci_write_word1
295
	jz	pci_write_word1
344
;	cmp	esi,2
296
	cmp	esi,2
345
;	jz	pci_write_dword1
297
	jz	pci_write_dword1
346
;	jmp	pci_fin_write1
-
 
347
	jmp	dword [f62_wcall+esi*4]
298
	jmp	pci_fin_write1
-
 
299
 
348
.0:
300
pci_write_byte1:
349
	out	dx,al
301
	out	dx,al
350
	jmp .pci_fin_write1
302
	jmp pci_fin_write1
351
.1:
303
pci_write_word1:
352
	out	dx,ax
304
	out	dx,ax
353
	jmp .pci_fin_write1
305
	jmp pci_fin_write1
354
.2:
306
pci_write_dword1:
-
 
307
	out	dx,eax
355
	out	dx,eax
308
	jmp	pci_fin_write1
Line 356... Line 309...
356
.pci_fin_write1:
309
pci_fin_write1:
357
 
310
 
358
		; restore configuration control
311
		; restore configuration control
359
	pop	eax
312
	pop	eax
Line 360... Line 313...
360
	mov	dl,0xf8
313
	mov	dl,0xf8
361
	out	dx,eax
314
	out	dx,eax
-
 
315
 
362
 
316
	xor	eax,eax
363
	xor	eax,eax
317
	pop	esi
Line 364... Line 318...
364
	;pop	esi
318
 
365
	ret
319
	ret
Line 366... Line 320...
366
pci_write_reg_2:
320
pci_write_reg_2:
367
 
321
 
368
	test	ch,128;bh,128	;mech#2 only supports 16 devices per bus
322
	test	bh,128	;mech#2 only supports 16 devices per bus
Line 369... Line 323...
369
	jnz	pci_api.not_support
323
	jnz	pci_write_reg_err
370
 
-
 
371
 
324
 
372
;	push esi   ; save register size into ESI
325
 
373
	mov esi,eax
326
	push esi   ; save register size into ESI
374
	and esi,3	;not need
327
	mov esi,eax
375
 
328
	and esi,3
Line 394... Line 347...
394
	or	bh,0xc0
347
	or	bh,0xc0
395
	mov	dx,bx
348
	mov	dx,bx
396
		; write register
349
		; write register
397
	mov	eax,ecx
350
	mov	eax,ecx
Line 398... Line 351...
398
 
351
 
399
;	or	esi,esi
352
	or	esi,esi
400
;	jz	pci_write_byte2
353
	jz	pci_write_byte2
401
;	cmp	esi,1
354
	cmp	esi,1
402
;	jz	pci_write_word2
355
	jz	pci_write_word2
403
;	cmp	esi,2
356
	cmp	esi,2
404
;	jz	pci_write_dword2
357
	jz	pci_write_dword2
405
;	jmp	pci_fin_write2
-
 
406
	jmp	dword [f62_wcall2+esi*4]
358
	jmp	pci_fin_write2
-
 
359
 
407
.0:
360
pci_write_byte2:
408
	out	dx,al
361
	out	dx,al
409
	jmp .pci_fin_write2
362
	jmp pci_fin_write2
410
.1:
363
pci_write_word2:
411
	out	dx,ax
364
	out	dx,ax
412
	jmp .pci_fin_write2
365
	jmp pci_fin_write2
413
.2:
366
pci_write_dword2:
-
 
367
	out	dx,eax
414
	out	dx,eax
368
	jmp	pci_fin_write2
415
.pci_fin_write2:
369
pci_fin_write2:
416
		; restore configuration space
370
		; restore configuration space
417
	pop	eax
371
	pop	eax
418
	mov	dx,0xcfa
372
	mov	dx,0xcfa
419
	out	dx,al
373
	out	dx,al
420
	mov	dl,0xf8
374
	mov	dl,0xf8
421
	mov	al,ah
375
	mov	al,ah
Line 422... Line 376...
422
	out	dx,al
376
	out	dx,al
423
 
377
 
424
	xor	eax,eax
378
	xor	eax,eax
Line 425... Line 379...
425
	;pop	esi
379
	pop	esi
426
	ret
380
	ret
427
 
381
 
428
;pci_write_reg_err:
382
pci_write_reg_err:
Line 429... Line 383...
429
;	xor	eax,eax
383
	xor	eax,eax
430
;	dec	eax
384
	dec	eax
431
;	ret
385
	ret
432
 
386
 
433
if defined mmio_pci_addr	; must be set above
387
if defined mmio_pci_addr	; must be set above
434
;***************************************************************************
388
;***************************************************************************
435
;   Function
389
;   Function
436
;      pci_mmio_init 
390
;      pci_mmio_init 
437
;
391
;
438
;   Description
392
;   Description
439
;       IN:  cx = device's PCI bus address (bbbbbbbbdddddfff)
393
;       IN:  bx = device's PCI bus address (bbbbbbbbdddddfff)
440
;   Returns  eax = user heap space available (bytes)
394
;   Returns  eax = user heap space available (bytes)
441
;   Error codes
395
;   Error codes
442
;       eax = -1 : PCI user access blocked,
396
;       eax = -1 : PCI user access blocked,
443
;       eax = -2 : device not registered for uMMIO service
397
;       eax = -2 : device not registered for uMMIO service
444
;       eax = -3 : user heap initialization failure
398
;       eax = -3 : user heap initialization failure
445
;***************************************************************************
399
;***************************************************************************
446
pci_mmio_init:
400
pci_mmio_init:
447
    cmp     cx, mmio_pci_addr	
401
    cmp     bx, mmio_pci_addr	
448
    jz	    @f
402
    jz	    @f
Line 466... Line 420...
466
;       maps a block of PCI memory to user-accessible linear address
420
;       maps a block of PCI memory to user-accessible linear address
467
;
421
;
468
;       WARNING! This VERY EXPERIMENTAL service is for one chosen PCI device only!
422
;       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
423
;       The target device address should be set in kernel var mmio_pci_addr
470
;
424
;
471
;       IN:  bh = BAR#;
425
;       IN:  ah = BAR#;
472
;       IN: ecx = block size (bytes);
426
;       IN: ebx = block size (bytes);
473
;       IN: edx = offset in MMIO block (in 4K-pages, to avoid misaligned pages);
427
;       IN: ecx = offset in MMIO block (in 4K-pages, to avoid misaligned pages);
474
;
428
;
475
;   Returns eax = MMIO block's linear address in the userspace (if no error)
429
;   Returns eax = MMIO block's linear address in the userspace (if no error)
476
;
430
;
477
;
431
;
478
;   Error codes
432
;   Error codes
Line 483... Line 437...
483
;       eax = -5 : dynamic userspace allocation problem
437
;       eax = -5 : dynamic userspace allocation problem
484
;***************************************************************************
438
;***************************************************************************
Line 485... Line 439...
485
 
439
 
486
pci_mmio_map:
440
pci_mmio_map:
487
    and     edx,0x0ffff
441
    and     edx,0x0ffff
488
    cmp     bh, 6
442
    cmp     ah,6
489
    jc     .bar_0_5
443
    jc     .bar_0_5
490
    jz     .bar_rom
444
    jz     .bar_rom
491
    mov     eax,-2
445
    mov     eax,-2
492
    ret
446
    ret
493
.bar_rom:
447
.bar_rom:
494
    mov    ah, 8	; bar6 = Expansion ROM base address
448
    mov    ah, 8	; bar6 = Expansion ROM base address
495
.bar_0_5:
-
 
496
    push    edx
-
 
497
    add     ecx, 4095
-
 
498
    and     ecx, 0xFFFFF000	; 4k-alignment
449
.bar_0_5:
-
 
450
    push    ecx
-
 
451
    add     ebx, 4095
-
 
452
    and     ebx,-4096
499
    push    ecx
453
    push    ebx
500
    mov     cl, bh	; cl = BAR# (0..5), however cl=8 for BAR6
454
    mov     bl, ah	; bl = BAR# (0..5), however bl=8 for BAR6
501
    shl     cl, 1
455
    shl     bl, 1
502
    shl     cl, 1
456
    shl     bl, 1
503
    add     cl, 0x10	; now cl = BAR offset in PCI config. space
457
    add     bl, 0x10	; now bl = BAR offset in PCI config. space
504
    mov     ax, mmio_pci_addr
458
    mov     ax, mmio_pci_addr
505
    mov     ch, al	; ch = dddddfff
459
    mov     bh, al	; bh = dddddfff
506
    mov     bl, 2		; bl : DW to read
460
    mov     al, 2	; al : DW to read
507
    call    pci_read_reg	; new call
461
    call    pci_read_reg
508
    or	    eax, eax
462
    or	    eax, eax
509
    jnz     @f
463
    jnz     @f
510
    mov     eax,-3	; empty I/O space
464
    mov     eax,-3	; empty I/O space
511
    jmp     mmio_ret_fail
465
    jmp     mmio_ret_fail
Line 515... Line 469...
515
    mov     eax,-4	; damned ports (not MMIO space)
469
    mov     eax,-4	; damned ports (not MMIO space)
516
    jmp     mmio_ret_fail
470
    jmp     mmio_ret_fail
517
@@:
471
@@:
518
    pop     ecx 		; ecx = block size, bytes (expanded to whole page)
472
    pop     ecx 	; ecx = block size, bytes (expanded to whole page)
519
    mov     ebx, ecx	; user_alloc destroys eax, ecx, edx, but saves ebx
473
    mov     ebx, ecx	; user_alloc destroys eax, ecx, edx, but saves ebx
520
    and     al, 0xF0	; clear flags 
474
    and     eax, 0xFFFFFFF0
521
    push    eax 	      ; store MMIO physical address + keep 2DWords in the stack
475
    push    eax 	      ; store MMIO physical address + keep 2DWords in the stack
522
    stdcall user_alloc, ecx
476
    stdcall user_alloc, ecx
523
    or	eax, eax
477
    or	    eax, eax
524
    jnz     mmio_map_over
478
    jnz     mmio_map_over
525
    mov     eax,-5	; problem with page allocation
479
    mov     eax,-5	; problem with page allocation
Line 535... Line 489...
535
    mov     ebx, eax	; ebx = linear address
489
    mov     ebx, eax	; ebx = linear address
536
    pop     eax 		; eax = MMIO start
490
    pop     eax 	; eax = MMIO start
537
    pop     edx 		; edx = MMIO shift (pages)
491
    pop     edx 	; edx = MMIO shift (pages)
538
    shl     edx, 12	; edx = MMIO shift (bytes)
492
    shl     edx, 12	; edx = MMIO shift (bytes)
539
    add     eax, edx	; eax = uMMIO physical address
493
    add     eax, edx	; eax = uMMIO physical address
-
 
494
    or	    eax, PG_SHARED
-
 
495
    or	    eax, PG_UW
540
    or	eax, PG_SHARED+PG_UW+PG_NOCACHE
496
    or	    eax, PG_NOCACHE
541
    mov     edi, ebx
497
    mov     edi, ebx
542
    call    commit_pages
498
    call    commit_pages
543
    mov     eax, edi
499
    mov     eax, edi
544
    ret
500
    ret
Line 557... Line 513...
557
;       eax = -1 if no user PCI access allowed,
513
;       eax = -1 if no user PCI access allowed,
558
;       eax =  0 if unmapping failed
514
;       eax =  0 if unmapping failed
559
;***************************************************************************
515
;***************************************************************************
Line 560... Line 516...
560
 
516
 
561
pci_mmio_unmap:
517
pci_mmio_unmap:
562
    stdcall user_free, ecx;ebx
518
    stdcall user_free, ebx
Line 563... Line 519...
563
    ret
519
    ret
Line 564... Line 520...
564
 
520
 
Line 633... Line 589...
633
	je	..dev_not_found
589
	je	..dev_not_found
634
	add	esi, 10
590
	add	esi, 10
635
	jmp	..nxt2
591
	jmp	..nxt2
Line 636... Line 592...
636
 
592
 
637
.not_FIND_PCI_CLASS_CODE:
-
 
638
	mov	edx, ecx
593
.not_FIND_PCI_CLASS_CODE:
639
	cmp	ebp, 8			; READ_CONFIG_*
594
	cmp	ebp, 8			; READ_CONFIG_*
640
	jb	.not_READ_CONFIG
595
	jb	.not_READ_CONFIG
641
	cmp	ebp, 0x0A
596
	cmp	ebp, 0x0A
642
	ja	.not_READ_CONFIG
597
	ja	.not_READ_CONFIG
643
	mov	eax, ebp	; -- ?? 
598
	mov	eax, ebp
644
;	mov	ah, bh	; bus
599
	mov	ah, bh
645
	mov	ecx, edi
600
	mov	edx, edi
646
	mov	ch, bl	; dev+fn
601
	mov	bh, bl
647
;	mov	cl, dl	; reg#
602
	mov	bl, dl
648
	call	pci_read_reg	
603
	call	pci_read_reg
649
	mov	edx, eax
604
	mov	ecx, eax
650
	xor	ah, ah			; SUCCESSFUL
605
	xor	ah, ah			; SUCCESSFUL
651
	jmp	.return_abc
606
	jmp	.return_abc
652
.not_READ_CONFIG:
607
.not_READ_CONFIG:
653
	cmp	ebp, 0x0B		; WRITE_CONFIG_*
608
	cmp	ebp, 0x0B		; WRITE_CONFIG_*
654
	jb	.not_WRITE_CONFIG
609
	jb	.not_WRITE_CONFIG
655
	cmp	ebp, 0x0D
610
	cmp	ebp, 0x0D
656
	ja	.not_WRITE_CONFIG
611
	ja	.not_WRITE_CONFIG
657
	lea	eax, [ebp+1]
612
	lea	eax, [ebp+1]
658
;	mov	ah, bh	; bus
613
	mov	ah, bh
659
	mov	ecx, edi	
614
	mov	edx, edi
660
	mov	ch, bl
615
	mov	bh, bl
661
;	mov	cl, dl
616
	mov	bl, dl
662
	call	pci_write_reg
617
	call	pci_write_reg
663
	xor	ah, ah			; SUCCESSFUL
618
	xor	ah, ah			; SUCCESSFUL
664
	jmp	.return_abc
619
	jmp	.return_abc
665
.not_WRITE_CONFIG:
620
.not_WRITE_CONFIG: