Subversion Repositories Kolibri OS

Rev

Rev 1947 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1356 diamond 1
;***************************************************************
132 diamond 2
; project name:    PCI Device Enumeration
475 Ghost 3
; target platform: KolibriOS
1351 art_zh 4
; compiler:        flat assembler 1.68
1981 yogev_ezra 5
; version:         2.21
1351 art_zh 6
; last update:     December 2007
475 Ghost 7
; maintained by:   Jason Delozier (cordata51@hotmail.com)
8
;                  Sergey Kuzmin (kuzmin_serg@list.ru)
9
;                  Mihailov Ilia (ghost.nsk@gmail.com)
1351 art_zh 10
;                  Artem Jerdev  (art_zh@yahoo.com)
205 heavyiron 11
; project site:    http://www.coolthemes.narod.ru/pcidev.html
132 diamond 12
;***************************************************************
13
;Summary: This program will attempt to scan the PCI Bus
14
;        and display basic information about each device
15
;        connected to the PCI Bus.
16
;***************************************************************
1364 diamond 17
include '../../../macros.inc'
1359 art_zh 18
;include 'macros.inc'
1351 art_zh 19
 
475 Ghost 20
MEOS_APP_START
21
CODE
22
	call draw_window
132 diamond 23
 
475 Ghost 24
still:	mcall	10			; wait here for event
25
	dec	eax			; redraw request ?
26
	jz	red
27
	dec	eax			; key in buffer ?
28
	jz	key
29
	dec	eax			; button in buffer ?
30
	jz	button
31
	jmp	still
132 diamond 32
 
475 Ghost 33
red:					; redraw
34
	mcall	9, Proc_Info, -1	; window redraw requested so get new window coordinates and size
485 heavyiron 35
	mov	eax, [Proc_Info.box.left]; store the window coordinates into the Form Structure
475 Ghost 36
	mov	[Form + 2], ax		; x start position
485 heavyiron 37
	mov	eax, [Proc_Info.box.top];
475 Ghost 38
	mov	[Form + 6], ax		; ystart position
485 heavyiron 39
	mov	eax, [Proc_Info.box.width]	;
475 Ghost 40
	mov	[Form], ax		; window width
485 heavyiron 41
	mov	eax, [Proc_Info.box.height]	;
475 Ghost 42
	mov	[Form + 4] ,ax		; window height
43
	call	draw_window		; go redraw window now
44
	jmp	still
132 diamond 45
 
475 Ghost 46
key:					; key
47
	mcall	2			; just read it and ignore
48
	jmp	still
1351 art_zh 49
button: 				; button
475 Ghost 50
	mcall	17			; get id
51
	cmp	ah, 1			; button id = 1 ?
52
	jne	still
53
	mcall	-1			; close this program
132 diamond 54
 
55
draw_window:
475 Ghost 56
	mov	byte [total], 0
57
	mcall	12, 1			; start of draw
58
	; DRAW WINDOW
59
	mcall	0, dword [Form], dword [Form + 4], 0x13ffffff, 0x805080d0, title
60
	; Insert horizontal bars  in list area
1351 art_zh 61
	mov	eax, 13 		; draw bar system function
62
	mov	ebx, 18 		; set Xstart position of bar
63
	shl	ebx, 16 		;
64
	mov	bx, word [Form] ; get width of window
475 Ghost 65
	sub	bx, 32			; bar is 32 pixels shorter then window width
66
	mov	ecx, 119 * 65536 + 10	; set Ystart(109) and Height(10) of bar   109
67
	mov	edx, 0xC0C0C0		; set color of bar
68
again:	;begin draw bar loop
69
	mcall				; draw bar to window area
1351 art_zh 70
	shr	ecx, 16 		; move the Ystart position to working area
71
	add	ecx, 34 		; add 34 pixels to Y Start (moves bar down)
475 Ghost 72
	cmp	cx, word [Form + 4]	; is the Ystart position outside of window area
73
	jae	nomo			; if so stop drawing bars
1351 art_zh 74
	sub	ecx, 14 		; if not, we only need 20 pixels between bar tops
75
	shl	ecx, 16 		; set that values as Ystart
76
	add	ecx, 10 		; Bar Height is always 10 pixels
475 Ghost 77
	jmp	again			; draw another bar
78
nomo:					;done drawing bars here
79
	; start PCI stuff
80
	call	Get_PCI_Info		; get pci version and last bus, scan for and draw each pci device
132 diamond 81
 
475 Ghost 82
	; Window inteface
83
	mov	cx, [PCI_Version]
84
	add	ch, '0'
1351 art_zh 85
	mov	[PCIWin + 85], ch	; 0xBADCODE but it works !
475 Ghost 86
	mov	ch, cl
87
	shr	cl, 4
88
	and	ch, 0x0f
89
	add	cx, '00'
90
	mov	[PCIWin + 87], cx
1351 art_zh 91
	mov	cl, [PCI_LastBus]	; will only work if [PCI_LastBus] < 10
475 Ghost 92
	add	cl, '0'
1351 art_zh 93
	mov	[PCIWin + 106], cl
94
 
475 Ghost 95
	mov	edx, PCIWin
96
	mov	ebx, 20 * 65536 + 25	; x start, ystart of text
97
	mov	ecx, 0x224466		; color of text
98
	mov	eax, 4
99
@@:	movzx	esi, byte[edx]
100
	inc	edx
101
	mcall
102
	add	ebx, 10
103
	add	edx, esi
104
	cmp	byte[edx], -1
105
	jne	@b
106
	; Quantity of devices...
107
	movzx	ecx, byte [total]	; number to draw
108
	mcall	47, 0x00020000,,150 * 65536 + 65, 0x224466
1386 art_zh 109
 
110
	mov	ah, [MMIO_allowed]
111
	or 	ah, ah
112
	jz 	@f
113
	mov	ah, [MMIO_Bus]	; =255 if MMIO disabled / not found
114
	and	ah, 0x7f
115
	inc	ah
116
	jo	@f
1351 art_zh 117
	call	Try_MMIO
1386 art_zh 118
@@:
475 Ghost 119
	mcall	12, 2			; end of draw
120
	ret
132 diamond 121
 
475 Ghost 122
;------------------------------------------------------------------
205 heavyiron 123
;* Gets the PCI Version and Last Bus
132 diamond 124
Get_PCI_Info:
475 Ghost 125
	mcall	62, 0
126
	mov	word [PCI_Version], ax
127
	mcall	62, 1
128
	mov	byte [PCI_LastBus], al
129
	;----------------------------------------------------------
130
	;* Get all devices on PCI Bus
131
	cmp	al, 0xff		; 0xFF means no pci bus found
132
	jne	Pci_Exists		;
133
	ret				; if no bus then leave
132 diamond 134
Pci_Exists:
1351 art_zh 135
	mov	byte [V_Bus], 0 	; reset varibles
136
	mov	byte [V_Dev], 0 	;
475 Ghost 137
	mov	edx,  20 * 65536 + 110	; set start write position
132 diamond 138
Start_Enum:
475 Ghost 139
	mov	bl, 6			; get a dword
140
	mov	bh, byte [V_Bus]	; bus of pci device
141
	mov	ch, byte [V_Dev]	; device number/function
142
	mov	cl, 0			; offset to device/vendor id
143
	mcall	62			; get ID's
132 diamond 144
 
475 Ghost 145
	cmp	ax, 0			; Vendor ID should not be 0 or 0xFFFF
1351 art_zh 146
	je	nextDev 		; check next device if nothing exists here
475 Ghost 147
	cmp	ax, 0xffff		;
1351 art_zh 148
	je	nextDev 		;
132 diamond 149
 
475 Ghost 150
	mov	word [PCI_Vendor], ax	; There is a device here, save the ID's
1351 art_zh 151
	shr	eax, 16 		;
475 Ghost 152
	mov	word [PCI_Device], ax	;
153
	mov	bl, 4			; Read config byte
154
	mov	bh, byte [V_Bus]	; Bus #
155
	mov	ch, byte [V_Dev]	; Device # on bus
156
	mov	cl, 0x08		; Register to read (Get Revision)
157
	mcall	62			; Read it
158
	mov	byte [PCI_Rev], al	; Save it
159
	mov	cl, 0x0b		; Register to read (Get class)
160
	mcall	62			; Read it
1351 art_zh 161
 
475 Ghost 162
	mov	byte [PCI_Class], al	; Save it
163
	mov	cl, 0x0a		; Register to read (Get Subclass)
164
	mcall	62			; Read it
165
	mov	byte [PCI_SubClass], al; Save it
1351 art_zh 166
; by Mario79 august 2006
475 Ghost 167
	mov	cl, 0x09		; Register to read (Get Interface)
168
	mcall	62			; Read it
169
	mov  [PCI_Interface], al	; Save it
205 heavyiron 170
;
1351 art_zh 171
; by Ghost april 2007
475 Ghost 172
	mov	cl, 0x3c		; Register to read (Get IRQ)
173
@@:	mcall	62			; Read it
174
	mov	[PCI_IRQ], al		; Save it
1946 clevermous 175
; by CleverMouse juny 2011
176
	mov	cl, 0x0e
177
	mcall	62
178
	push	eax
475 Ghost 179
	inc	byte [total]		; one more device found
180
	call	Print_New_Device	; print device info to screen
1946 clevermous 181
; don't scan for nonzero functions if zero function says "not multifunction device"
182
	pop	eax
183
	test	al, al
184
	js	nextDev
185
	test	byte [V_Dev], 7
1947 clevermous 186
	jnz	nextDev
1946 clevermous 187
	or	byte [V_Dev], 7
132 diamond 188
nextDev:
475 Ghost 189
	inc	byte [V_Dev]		; next device on this bus
190
	jnz	Start_Enum		; jump until we reach zero
191
	;(used to be JNO which caused bug!!! 30-4-2006, JMD)
1351 art_zh 192
	mov	byte [V_Dev], 0 	; reset device number
475 Ghost 193
	inc	byte [V_Bus]		; next bus
194
	mov	al, byte [PCI_LastBus]	; get last bus
195
	cmp	byte [V_Bus], al	; was it last bus
196
	jbe	Start_Enum		; if not jump to keep searching
197
	ret
132 diamond 198
 
1386 art_zh 199
no_ummio_allowed:
200
	xor 	al,al
201
	mov 	[MMIO_allowed],al		; re-enter the subroutine
475 Ghost 202
;------------------------------------------------------------------
132 diamond 203
;* Print device info to screen
1386 art_zh 204
 
132 diamond 205
Print_New_Device:
1386 art_zh 206
	xor 	esi, esi	    	; default text color
207
	mov 	cl, [MMIO_allowed]
208
	or	cl,cl
209
	jz	no_ummio_here
210
	mov 	ch, byte [V_Bus]
211
	mov 	cl, byte [V_Dev]
1351 art_zh 212
	mcall	62, 11		; detect uMMIO
1386 art_zh 213
	and	ax,0x7fff
214
	inc 	ax			; -1 returned?
215
	jo 	no_ummio_allowed
216
	inc 	ax			; -2 returned?
217
	jo 	no_ummio_here
218
	inc 	ax			; -3 returned?
219
	jo 	no_ummio_here
220
	mov 	esi, 0x990033   ; highlighted text color
221
	mov 	bh, byte [V_Bus]
222
	mov 	bl, byte [V_Dev]
223
	mov 	byte [MMIO_Bus], bh
224
	mov 	byte [MMIO_Dev], bl
225
	add 	bh,'0'
226
	mov 	[PCIWin + 129], bh	; uMMIO bus
227
	mov 	al, bl
228
	shr 	al, 1
229
	shr 	al, 1
230
	shr 	al, 1
231
	add 	al,'0'
232
	mov 	[PCIWin + 131], al	; uMMIO device
233
	and 	bl, 7
234
	add 	bl, '0'
235
	mov 	[PCIWin + 133], bl	; uMMIO function
1351 art_zh 236
 
237
no_ummio_here:
475 Ghost 238
	movzx	ecx,word [PCI_Vendor]	; Pointer to number to be written
239
	mcall	47, 0x00040100		; Write Vendor ID
240
	and	edx, 0xFFFF		;*****************************************
1351 art_zh 241
	or	edx, 54 * 65536 ; X start becomes 54
475 Ghost 242
	movzx	ecx, word [PCI_Device]	; get Vendor ID
243
	mcall				; Draw Vendor ID to Window
244
	and	edx, 0xFFFF		;*****************************************
1351 art_zh 245
	or	edx, 98 * 65536 ; X start becomes 98
475 Ghost 246
	movzx	ecx, byte [V_Bus]	; get bus number
247
	mcall	,0x00020100		; draw bus number to screen
248
	and	edx, 0xFFFF		;*****************************************
249
	or	edx, 128 * 65536	; X start becomes 128
250
	movzx	ecx, byte [V_Dev]	; get device number
251
	shr	ecx, 3			; device number is bits 3-7
252
	mcall				; Draw device Number To Window
1351 art_zh 253
 
475 Ghost 254
	and	edx, 0xFFFF		;*****************************************
255
	or	edx, 155 * 65536	; X start becomes 155
256
	movzx	ecx, byte [V_Dev]	; get Function number
257
	and	ecx, 7			; function is first 3 bits
258
	mcall				; Draw Function Number To Window
259
	and	edx, 0xFFFF		;*****************************************
260
	or	edx, 179 * 65536	; X start becomes 179
261
	movzx	ecx, byte [PCI_Rev]	; get revision number
262
	mcall				; Draw Revision to screen
263
	and	edx, 0xFFFF		;*****************************************
264
	or	edx, 215*65536		; X start becomes 215
265
	movzx	ecx, byte [PCI_Class]	; get PCI_Class
266
	mcall				; Draw Class to screen
267
	and	edx, 0xFFFF		;*****************************************
268
	or	edx, 250*65536		; X start becomes 250
269
	movzx	ecx, byte [PCI_SubClass]; get sub class
270
	mcall				; Draw Sub Class to screen
205 heavyiron 271
; from Mario79 august 2006
475 Ghost 272
	and	edx, 0xFFFF		;*****************************************
273
	or	edx, 280 * 65536	; X start becomes 280
274
	movzx	ecx, [PCI_Interface]	; get Interface
275
	mcall
205 heavyiron 276
;
1351 art_zh 277
; from Ghost april 2007                 ;*****************************************
475 Ghost 278
	movzx	ecx, [PCI_IRQ]		; get Interface
279
	cmp	cl, 0x0f		; IRQ between 0..15
280
	ja	@f
281
	and	edx, 0xFFFF
282
	or	edx, 310 * 65536	; X start becomes 310
283
	mcall
284
@@:
285
;
286
	;Write Names
1351 art_zh 287
	movzx	ebx, dx 	; Set y position
475 Ghost 288
	or	ebx, 340 * 65536	; set Xposition to 340
132 diamond 289
 
475 Ghost 290
;------------------------------------------------------------------
291
; Prints the Vendor's Name based on Vendor ID
132 diamond 292
;
475 Ghost 293
; Modified on ??-04-2007 by Ghost for size
294
;------------------------------------------------------------------
295
	mov	edx, VendorsTab
296
	mov	cx, word[PCI_Vendor]
1351 art_zh 297
 
475 Ghost 298
.fn:	mov	ax, [edx]
299
	add	edx, 6
300
	test	ax, ax
301
	jz	.find
302
	cmp	ax, cx
303
	jne	.fn
304
.find:	mov	edx, [edx - 4]
305
	mcall	4,, 0x80000000		; lets print the vendor Name
132 diamond 306
 
307
;------------------------------------------------------------------
475 Ghost 308
; Get description based on Class/Subclass
309
;
310
; Modified on ??-04-2007 by Ghost for size
311
;------------------------------------------------------------------
312
	mov	eax, dword [PCI_Class]
313
	and	eax, 0xffffff
314
	xor	edx, edx
315
	xor	esi, esi
316
.fnc:	inc	esi
317
	mov	ecx, [Classes + esi * 8 - 8]
318
	cmp	cx, 0xffff
319
	je	.endfc
320
	cmp	cx, ax
321
	jne	.fnc
322
	test	ecx, 0xff000000
323
	jz	@f
324
	mov	edx, [Classes + esi * 8 - 4]
325
	jmp	.fnc
326
@@:	cmp	eax, ecx
327
	jne	.fnc
328
	xor	edx, edx
1351 art_zh 329
.endfc: test	edx, edx
475 Ghost 330
	jnz	@f
331
	mov	edx, [Classes + esi * 8 - 4]
1351 art_zh 332
@@:
333
	and	ebx, 0x0000FFFF 	; clear X position
475 Ghost 334
	or	ebx, 0x24E0000		; set X position to 590 pixels
335
	mcall	4,, 0x80000000,, 32	; draw the text
1351 art_zh 336
	movzx	edx, bx 	; get y coordinate
337
	add	edx, 0x0014000A 	; add 10 to y coordinate and set x coordinate to 20
338
	mov	[gr_pos], edx
475 Ghost 339
	ret
1351 art_zh 340
;------------------------------------------------------------------
341
; Get the user-MMIO related info
342
;
343
; Added on ??-12-2009 by art_zh
344
;------------------------------------------------------------------
345
Try_MMIO:
346
	xor	ebx, ebx
347
	mov	edx, ebx
1358 art_zh 348
	mov	bh, [MMIO_BAR]
1351 art_zh 349
	or	bx, 12			; function 12
350
	mov	ecx, 4096		; =1 page to map
351
	mcall	62
1358 art_zh 352
	mov	[MMIO_Map], eax 	; store MMIO lin.addr.
1351 art_zh 353
	mov	ecx, 0x80990022 	; print color : red
354
	add	bh, '0'
355
	cmp	eax, -3
356
	jne	@f
357
	mov	[bar_um+3], bh
358
	mov	ebx, [gr_pos]
359
	mov	edx, bar_um
360
	mcall	4
361
	jmp	mmio_next_bar
362
@@:
363
	cmp	eax, -4
364
	jne	@f
365
	mov	[bar_io+3], bh
366
	mov	ebx, [gr_pos]
367
	mov	edx, bar_io
368
	mcall	4
369
	jmp	mmio_next_bar
370
@@:
1358 art_zh 371
	cmp	bh, '6' 	; expansion ROM ?
372
	je	@f
1351 art_zh 373
	mov	[bar_ram+3], bh
374
	mov	ebx, [gr_pos]
375
	mov	edx, bar_ram
376
	mcall	4
1358 art_zh 377
	jmp	mmio_dump
1353 art_zh 378
@@:
379
	mov	ebx, [gr_pos]
380
	mov	edx, bar_rom
381
	mcall	4
205 heavyiron 382
 
1353 art_zh 383
mmio_dump:
1358 art_zh 384
	mov	edx, [MMIO_Map]
1351 art_zh 385
	mov	esi, 64
386
	mov	ecx, 0x099		; dump color : blue
387
	add	ebx, 10
388
	mov	[gr_pos], ebx
389
	mcall	4
1358 art_zh 390
	mov	ecx, [MMIO_Map] 	; release the tried page
1351 art_zh 391
	mcall	62,13
392
 
393
mmio_next_bar:
394
	mov	bh, [MMIO_BAR]
395
	inc	bh
1353 art_zh 396
	cmp	bh,7
1351 art_zh 397
	je	@f
398
	mov	[MMIO_BAR], bh
399
	add	[gr_pos], 10
400
	jmp	Try_MMIO
401
 
402
@@:
403
	xor	bh,bh
404
	mov	[MMIO_BAR], bh
405
	ret
406
 
407
 
1728 clevermous 408
include 'vendors.inc'
132 diamond 409
;------------------------------------------------------------------
410
; DATA AREA
475 Ghost 411
DATA
132 diamond 412
 
413
 
475 Ghost 414
Form:	dw 800 ; window width (no more, special for 800x600)
415
	dw 100 ; window x start
1358 art_zh 416
	dw 620 ; window height
417
	dw 20 ; window y start
205 heavyiron 418
 
1981 yogev_ezra 419
title	db 'PCI Device Enumerator v 2.21 by J.Delozier, S.Kuzmin, V.Hanla, M.Zakiyanov, A.Jerdev', 0
205 heavyiron 420
 
475 Ghost 421
PCIWin mls \
1351 art_zh 422
	'   Don`t forget to enable PCI Access to Applications in Setup Menu.',\
475 Ghost 423
	'',\
1351 art_zh 424
	'PCI Version  = x.xx; Last PCI Bus = x',\
425
	'User MMIO channel = 0F.F:F ',\
426
	'Number of PCI units =',\
475 Ghost 427
	'',\
428
	'VenID DevID Bus# Dev# Fnc Rev  Class  Subclass/ IRQ                 Company                      Description',\
429
	'                                      Interface',\
430
	'----- ----- ---- ---- --- ---  -----  --------- --- ------------------------------------------ ----------------'
205 heavyiron 431
 
1351 art_zh 432
bar_ram db 'BARx: MMIO block', 0
433
bar_io	db 'BARx: IO ports',0
434
bar_um	db 'BARx: unmapped',0
1358 art_zh 435
bar_rom db 'BAR6: Expansion ROM', 0
1351 art_zh 436
 
475 Ghost 437
;------------------------------------------------------------------
438
; UNINITIALIZED DATA AREA
439
UDATA
205 heavyiron 440
 
475 Ghost 441
total		db ?
442
V_Bus		db ?
443
V_Dev		db ?
444
PCI_Version	dw ?
445
PCI_LastBus	db ?
446
PCI_Device	dw ?
447
PCI_Vendor	dw ?
1351 art_zh 448
PCI_Bus 	db ?
449
PCI_Dev 	db ?
450
PCI_Rev 	db ?
475 Ghost 451
; don`t change order!!!
452
PCI_Class	db ?
453
PCI_SubClass	db ?
454
PCI_Interface	db ?
1351 art_zh 455
PCI_IRQ 	db ?
205 heavyiron 456
 
1351 art_zh 457
align 4
1386 art_zh 458
MMIO_Bus	db 255
459
MMIO_Dev	db 255
1351 art_zh 460
MMIO_BAR	db 0
1386 art_zh 461
MMIO_allowed	db 1
1351 art_zh 462
MMIO_Map	rd 8
463
 
464
gr_pos		dd ?
465
 
475 Ghost 466
Proc_Info	process_information
467
MEOS_APP_END
1351 art_zh 468