Page 1 of 1

PCI device detection

Posted: Mon Jun 03, 2013 1:25 pm
by IanSeyler
Is this the correct way to crawl through the connected PCI devices?

Code: Select all

pci:
	xor ebx, ebx			; Clear the Bus number
	xor ecx, ecx			; Clear the Device/Slot number
	mov edx, 2			; Register 2 for Class code/Subclass
pci_probe_next:
	call os_pci_read_reg
	shr eax, 16			; Move the Class/Subclass code to AX
	cmp ax, 0xFFFF			; 0xFFFF = non-existant device
	je pci_probe_next_skip
	call os_debug_dump_ax
	mov rsi, newline
	call os_output
pci_probe_next_skip:
	add ecx, 1
	cmp ecx, 32			; Maximum 32 devices per bus
	je pci_probe_next_bus
	jmp pci_probe_next
pci_probe_next_bus:
	xor ecx, ecx
	add ebx, 1
	cmp ebx, 256			; Maximum 256 buses
	jne pci_probe_next
	jmp os_command_line
os_pci_read_reg uses BL for Bus number, CL for Device/Slot number, and DL for Register number.

On a Asus P8H61-M LE/USB3 my OS does not detect any storage device (SATA or PATA). Linux detects it correctly (actually Linux detects more devices).

Partial linux output from 'lspci -vv -nn':

Code: Select all

00:1f.0 ISA bridge [0601]: Intel Corporation H61 Express Chipset Family LPC Controller [8086:1c5c] (rev 05)
	Subsystem: ASUSTeK Computer Inc. Device [1043:844d]
	Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
	Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 0
	Capabilities: [e0] Vendor Specific Information: Len=0c <?>
	Kernel driver in use: lpc_ich
	Kernel modules: lpc_ich

00:1f.2 SATA controller [0106]: Intel Corporation 6 Series/C200 Series Chipset Family SATA AHCI Controller [8086:1c02] (rev 05) (prog-if 01 [AHCI 1.0])
	Subsystem: ASUSTeK Computer Inc. P8P67 Deluxe Motherboard [1043:844d]
	Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
	Status: Cap+ 66MHz+ UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 0
	Interrupt: pin B routed to IRQ 41
	Region 0: I/O ports at f0b0 [size=8]
	Region 1: I/O ports at f0a0 [size=4]
	Region 2: I/O ports at f090 [size=8]
	Region 3: I/O ports at f080 [size=4]
	Region 4: I/O ports at f060 [size=32]
	Region 5: Memory at f7e06000 (32-bit, non-prefetchable) [size=2K]
	Capabilities: [80] MSI: Enable+ Count=1/1 Maskable- 64bit-
		Address: fee0f00c  Data: 4181
	Capabilities: [70] Power Management version 3
		Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA PME(D0-,D1-,D2-,D3hot+,D3cold-)
		Status: D0 NoSoftRst+ PME-Enable- DSel=0 DScale=0 PME-
	Capabilities: [a8] SATA HBA v1.0 BAR4 Offset=00000004
	Capabilities: [b0] PCI Advanced Features
		AFCap: TP+ FLR+
		AFCtrl: FLR-
		AFStatus: TP-
	Kernel driver in use: ahci

00:1f.3 SMBus [0c05]: Intel Corporation 6 Series/C200 Series Chipset Family SMBus Controller [8086:1c22] (rev 05)
	Subsystem: ASUSTeK Computer Inc. P8P67 Deluxe Motherboard [1043:844d]
	Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
	Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Interrupt: pin C routed to IRQ 18
	Region 0: Memory at f7e05000 (64-bit, non-prefetchable) [size=256]
	Region 4: I/O ports at f040 [size=32]
	Kernel modules: i2c-i801
BareMetal detects the ISA bridge but not the two following devices.

Re: PCI device detection

Posted: Mon Jun 03, 2013 2:50 pm
by Combuster
os_pci_read_reg uses BL for Bus number, CL for Device/Slot number, and DL for Register number.
You forgot function numbers there. Check the headertype as well while you're at it.

Re: PCI device detection

Posted: Tue Jun 04, 2013 7:21 am
by IanSeyler
Thanks Combuster! This was exactly the issue. My OS detects the same PCI device list that Linux was displaying.