; ===========================================================================
; Toolbox.asm contains PCI bus routines
; ===========================================================================

PCIHARDWARE  db 0
PCIVERSION   dw 0
PCIBUSCOUNT  db 0
pcibus       db 0
pcitype      dw 0

is_pcibios proc far
; AX = 0 no pci bios
_det_pcibios:
           mov  ax, 0b101h
           int  1ah
           jc   _dh_isa
           or   ah, ah
           jnz  _dh_isa
           mov  PCIHARDWARE, al
           mov  byte ptr PCIVERSION, bh
           mov  byte ptr PCIVERSION+2, bl    
           mov  PCIBUSCOUNT, cl
           mov  al, 1
           jmp  short _dh_ret
_dh_isa:
           xor  ax, ax
_dh_ret:   ret
is_pcibios endp

pcidevicefound db 0
pci_bn         db 0
pci_fn         db 0

detectpcidevice proc far
; Input:  AX = DeviceID
;         BX = VendorID
; OutPut: AX = true/false
;         BH = Busnumber
;         BL = FunctionNumber
          xor  dx, dx
          mov  pci_bn, dl
          mov  pci_fn, dl
          mov  pcidevicefound, dl
          db 66h
          pusha
          mov  cx, ax ; device id
          mov  dx, bx ; vendor id
          mov  ax, 0b102h
          xor  si, si
          int  1ah
          jc   @nodevice
          mov  al, 1
          mov pcidevicefound, al
          mov pci_bn,BH
          mov pci_fn,BL
@nodevice:
          db 66h
          popa
          mov  bh, pci_bn ; busnumber
          mov  bl, pci_fn ; function number
          xor  ax, ax
          mov  al, pcidevicefound
        ret
detectpcidevice endp

readpcireg proc far
; Input:  AX = registernumber
;         BX = Bus
;         CX = FunctionNumber
; Output: AX = true/false
;         BX = result

        ret
readpcireg endp
; readpciword
; readpcidword

writepcireg proc far
; Input:  AX = registernumber
;         BX = Bus
;         CX = FunctionNumber
; Output: AX = true/false
;         BX = result

        ret
writepcireg endp
; writepciword
; writepcidword
