Subversion Repositories Kolibri OS

Rev

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

Rev 3626 Rev 3908
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: 3626 $
24
$Revision: 3908 $
25
 
25
 
26
;***************************************************************************
26
;***************************************************************************
27
;   Function
27
;   Function
Line 99... Line 99...
99
 
99
 
Line 100... Line 100...
100
;; ============================================
100
;; ============================================
101
 
101
 
102
pci_fn_0:
102
pci_fn_0:
103
; PCI function 0: get pci version (AH.AL)
103
; PCI function 0: get pci version (AH.AL)
Line 104... Line 104...
104
        movzx   eax, word [BOOT_VAR+0x9022]
104
        movzx   eax, word [BOOT_VARS+0x9022]
105
        ret
105
        ret
106
 
106
 
107
pci_fn_1:
107
pci_fn_1:
Line 108... Line 108...
108
; PCI function 1: get last bus in AL
108
; PCI function 1: get last bus in AL
109
        mov     al, [BOOT_VAR+0x9021]
109
        mov     al, [BOOT_VARS+0x9021]
110
        ret
110
        ret
111
 
111
 
Line 112... Line 112...
112
pci_fn_2:
112
pci_fn_2:
113
; PCI function 2: get pci access mechanism
113
; PCI function 2: get pci access mechanism
114
        mov     al, [BOOT_VAR+0x9020]
114
        mov     al, [BOOT_VARS+0x9020]
Line 154... Line 154...
154
 
154
 
Line 155... Line 155...
155
align 4
155
align 4
156
 
156
 
157
pci_read_reg:
157
pci_read_reg:
158
        push    ebx esi
158
        push    ebx esi
Line 159... Line 159...
159
        cmp     byte [BOOT_VAR+0x9020], 2;what mechanism will we use?
159
        cmp     byte [BOOT_VARS+0x9020], 2;what mechanism will we use?
160
        je      pci_read_reg_2
160
        je      pci_read_reg_2
161
 
161
 
Line 285... Line 285...
285
 
285
 
Line 286... Line 286...
286
align 4
286
align 4
287
 
287
 
288
pci_write_reg:
288
pci_write_reg:
289
        push    esi ebx
289
        push    esi ebx
Line 290... Line 290...
290
        cmp     byte [BOOT_VAR+0x9020], 2;what mechanism will we use?
290
        cmp     byte [BOOT_VARS+0x9020], 2;what mechanism will we use?
291
        je      pci_write_reg_2
291
        je      pci_write_reg_2
292
 
292
 
Line 568... Line 568...
568
        ;-=-=-=-=-=-=-=-=
568
        ;-=-=-=-=-=-=-=-=
569
.emulate_bios:
569
.emulate_bios:
570
        cmp     ebp, 1                  ; PCI_FUNCTION_ID
570
        cmp     ebp, 1                  ; PCI_FUNCTION_ID
571
        jnz     .not_PCI_BIOS_PRESENT
571
        jnz     .not_PCI_BIOS_PRESENT
572
        mov     edx, 'PCI '
572
        mov     edx, 'PCI '
573
        mov     al, [BOOT_VAR + 0x9020]
573
        mov     al, [BOOT_VARS + 0x9020]
574
        mov     bx, [BOOT_VAR + 0x9022]
574
        mov     bx, [BOOT_VARS + 0x9022]
575
        mov     cl, [BOOT_VAR + 0x9021]
575
        mov     cl, [BOOT_VARS + 0x9021]
576
        xor     ah, ah
576
        xor     ah, ah
577
        jmp     .return_abcd
577
        jmp     .return_abcd
Line 578... Line 578...
578
 
578
 
579
.not_PCI_BIOS_PRESENT:
579
.not_PCI_BIOS_PRESENT:
Line 657... Line 657...
657
        mov     dword[esp + 20], ebx
657
        mov     dword[esp + 20], ebx
658
.return_a:
658
.return_a:
659
        mov     dword[esp + 32], eax
659
        mov     dword[esp + 32], eax
660
        ret
660
        ret
Line -... Line 661...
-
 
661
 
-
 
662
PCI_VENDOR_ID           equ 0x00
-
 
663
PCI_CLASS_REVISION      equ 0x08
-
 
664
PCI_HEADER_TYPE         equ 0x0E
-
 
665
PCI_SUBSYSTEM_VENDOR_ID equ 0x2c
-
 
666
PCI_IRQ_LINE            equ 0x3C
661
 
667
 
662
proc pci_enum
668
proc pci_enum
663
        push    ebp
669
        push    ebp
664
        mov     ebp, esp
670
        mov     ebp, esp
665
        push    0
671
        push    0
Line 669... Line 675...
669
end virtual
675
end virtual
670
.loop:
676
.loop:
671
        mov     ah, [.bus]
677
        mov     ah, [.bus]
672
        mov     al, 2
678
        mov     al, 2
673
        mov     bh, [.devfn]
679
        mov     bh, [.devfn]
674
        mov     bl, 0
680
        mov     bl, PCI_VENDOR_ID
675
        call    pci_read_reg
681
        call    pci_read_reg
676
        cmp     eax, 0xFFFFFFFF
682
        cmp     eax, 0xFFFFFFFF
677
        jnz     .has_device
683
        jnz     .has_device
678
        test    byte [.devfn], 7
684
        test    byte [.devfn], 7
679
        jnz     .next_func
685
        jnz     .next_func
Line 684... Line 690...
684
        call    malloc
690
        call    malloc
685
        pop     ecx
691
        pop     ecx
686
        test    eax, eax
692
        test    eax, eax
687
        jz      .nomemory
693
        jz      .nomemory
688
        mov     edi, eax
694
        mov     edi, eax
689
        mov     [edi+PCIDEV.vendor_device_id], ecx
695
        mov     [edi+PCIDEV.vid_did], ecx
690
        mov     eax, pcidev_list
696
        mov     edx, pcidev_list
691
        mov     ecx, [eax+PCIDEV.bk]
-
 
692
        mov     [edi+PCIDEV.bk], ecx
-
 
693
        mov     [edi+PCIDEV.fd], eax
697
        list_add_tail edi, edx
694
        mov     [ecx+PCIDEV.fd], edi
-
 
695
        mov     [eax+PCIDEV.bk], edi
-
 
696
        mov     eax, dword [.devfn]
698
        mov     eax, dword [.devfn]
697
        mov     word [edi+PCIDEV.devfn], ax
699
        mov     word [edi+PCIDEV.devfn], ax
698
        mov     bh, al
700
        mov     bh, al
699
        mov     al, 2
701
        mov     al, 2
700
        mov     bl, 8
702
        mov     bl, PCI_CLASS_REVISION
701
        call    pci_read_reg
703
        call    pci_read_reg
702
        shr     eax, 8
704
        shr     eax, 8                                ;FIXME use byte mask
703
        mov     [edi+PCIDEV.class], eax
705
        mov     [edi+PCIDEV.class], eax
-
 
706
 
-
 
707
        mov     ah, [.bus]
-
 
708
        mov     bh, byte [.devfn]
-
 
709
        mov     al, 2
-
 
710
        mov     bl, PCI_SUBSYSTEM_VENDOR_ID
-
 
711
        call    pci_read_reg
-
 
712
        mov     [edi+PCIDEV.svid_sdid], eax
-
 
713
 
-
 
714
        mov     ah, [.bus]
-
 
715
        mov     al, 0
-
 
716
        mov     bh, [.devfn]
-
 
717
        mov     bl, PCI_IRQ_LINE
-
 
718
        call    pci_read_reg
-
 
719
        mov     [edi+PCIDEV.irq_line], al
-
 
720
 
704
        test    byte [.devfn], 7
721
        test    byte [.devfn], 7
705
        jnz     .next_func
722
        jnz     .next_func
706
        mov     ah, [.bus]
723
        mov     ah, [.bus]
707
        mov     al, 0
724
        mov     al, 0
708
        mov     bh, [.devfn]
725
        mov     bh, [.devfn]
709
        mov     bl, 0Eh
726
        mov     bl, PCI_HEADER_TYPE
710
        call    pci_read_reg
727
        call    pci_read_reg
711
        test    al, al
728
        test    al, al
712
        js      .next_func
729
        js      .next_func
713
.no_device:
730
.no_device:
714
        or      byte [.devfn], 7
731
        or      byte [.devfn], 7
715
.next_func:
732
.next_func:
716
        inc     dword [.devfn]
733
        inc     dword [.devfn]
717
        mov     ah, [.bus]
734
        mov     ah, [.bus]
718
        cmp     ah, [BOOT_VAR+0x9021]
735
        cmp     ah, [BOOT_VARS+0x9021]
719
        jbe     .loop
736
        jbe     .loop
720
.nomemory:
737
.nomemory:
721
        leave
738
        leave
722
        ret
739
        ret
723
endp
740
endp
-
 
741
 
-
 
742
 
-
 
743
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
744
 
-
 
745
;internal functions
-
 
746
;ecx (bus << 8)|devfn
-
 
747
;edx register
-
 
748
 
-
 
749
align 4
-
 
750
pci_bus:
-
 
751
.conf1_index:
-
 
752
; dword CF8 = (0x80000000 | ((reg & 0xF00) << 16) | (bus << 16) | (devfn << 8) | (reg & 0xFC))
-
 
753
				push	edx
-
 
754
				mov		eax, edx                	; eax = reg
-
 
755
				shl		eax, 16                 	; eax = reg << 16
-
 
756
				shl   ecx, 8                  	; ecx = (bus << 16)|(devfn<<8)
-
 
757
				mov		al, dl                  	; eax = (reg << 16)|reg
-
 
758
				and		eax, 0x0F0000FC           ; eax = ((reg & 0xF00) << 16)|(reg & 0xFC)
-
 
759
				lea		eax, [0x80000000+eax+ecx]
-
 
760
				mov 	dx, 0xCF8
-
 
761
				out		dx, eax
-
 
762
				pop		edx
-
 
763
				xor		eax, eax
-
 
764
				ret
-
 
765
 
-
 
766
align 4
-
 
767
.conf2_index:
-
 
768
; byte CF8 = 0xF0 | (fn << 1)
-
 
769
; byte CFA = bus
-
 
770
				push	edx
-
 
771
				mov		eax, ecx                ; (bus << 8)|devfn
-
 
772
				and		al, 7            				; fn
-
 
773
				lea		eax, [0xF0+eax+eax]
-
 
774
				mov 	dx, 0xCF8
-
 
775
				out		dx, al
-
 
776
				mov		al, ch                  ; bus
-
 
777
				mov		dx, 0xCFA
-
 
778
				out   dx, al
-
 
779
				pop		edx
-
 
780
				xor		eax, eax
-
 
781
				ret
-
 
782
 
-
 
783
align 4
-
 
784
.conf1_read8:
-
 
785
				call  .conf1_index
-
 
786
				and 	dx, 3
-
 
787
				add		dx, 0xCFC
-
 
788
				in		al, dx
-
 
789
				ret
-
 
790
 
-
 
791
align 4
-
 
792
.conf1_read16:
-
 
793
				call  .conf1_index
-
 
794
				and 	dx, 2
-
 
795
				add		dx, 0xCFC
-
 
796
				in		ax, dx
-
 
797
				ret
-
 
798
 
-
 
799
align 4
-
 
800
.conf1_read32:
-
 
801
				call  .conf1_index
-
 
802
				mov  	dx, 0xCFC
-
 
803
				in		eax, dx
-
 
804
				ret
-
 
805
 
-
 
806
align 4
-
 
807
.conf1_write8:
-
 
808
				call  .conf1_index
-
 
809
				mov		eax, [esp+4]
-
 
810
				and 	dx, 3
-
 
811
				add		dx, 0xCFC
-
 
812
				out		dx, al
-
 
813
				ret   4
-
 
814
 
-
 
815
align 4
-
 
816
.conf1_write16:
-
 
817
				call  .conf1_index
-
 
818
				mov		eax, [esp+4]
-
 
819
				and 	dx, 2
-
 
820
				add		dx, 0xCFC
-
 
821
				out		dx, ax
-
 
822
				ret   4
-
 
823
 
-
 
824
align 4
-
 
825
.conf1_write32:
-
 
826
				call  .conf1_index
-
 
827
				mov		eax, [esp+4]
-
 
828
				mov		dx, 0xCFC
-
 
829
				out   dx, eax
-
 
830
				ret   4
-
 
831
 
-
 
832
align 4
-
 
833
.conf2_read8:
-
 
834
; in (0xC000 | (dev << 8) | reg)
-
 
835
				call  .conf2_index
-
 
836
				and		ecx, 0xF1               ;ecx = dev << 3
-
 
837
				shl		ecx, 5                  ;ecx = dev << 8
-
 
838
				lea   edx, [0xC000+edx+ecx]
-
 
839
				in		al, dx
-
 
840
				ret
-
 
841
 
-
 
842
align 4
-
 
843
.conf2_read16:
-
 
844
				call  .conf2_index
-
 
845
				and		ecx, 0xF1
-
 
846
				shl		ecx, 5
-
 
847
				lea   edx, [0xC000+edx+ecx]
-
 
848
				in		ax, dx
-
 
849
				ret
-
 
850
 
-
 
851
align 4
-
 
852
.conf2_read32:
-
 
853
				call  .conf2_index
-
 
854
				and		ecx, 0xF1
-
 
855
				shl		ecx, 5
-
 
856
				lea   edx, [0xC000+edx+ecx]
-
 
857
				in		eax, dx
-
 
858
				ret
-
 
859
 
-
 
860
;proc pci_read8   stdcall, bus:dword, devfn:dword, reg:dword
-
 
861
;proc pci_read16  stdcall, bus:dword, devfn:dword, reg:dword
-
 
862
;proc pci_read32  stdcall, bus:dword, devfn:dword, reg:dword
-
 
863
 
-
 
864
;proc pci_write8  stdcall, bus:dword, devfn:dword, reg:dword, val:dword
-
 
865
;proc pci_write16 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
-
 
866
;proc pci_write32 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
-
 
867
 
-
 
868
PCI_R8	equ 0
-
 
869
PCI_R16	equ 4
-
 
870
PCI_R32 equ 8
-
 
871
 
-
 
872
PCI_W8	equ 12
-
 
873
PCI_W16	equ 16
-
 
874
PCI_W32 equ 20
-
 
875
 
-
 
876
align 8
-
 
877
pci_fn_table:
-
 
878
pci_bus_read8		dd pci_bus.conf1_read8           ;0
-
 
879
pci_bus_read16	dd pci_bus.conf1_read16          ;4
-
 
880
pci_bus_read32	dd pci_bus.conf1_read32          ;8
-
 
881
pci_bus_write8	dd pci_bus.conf1_write8          ;12
-
 
882
pci_bus_write16	dd pci_bus.conf1_write16         ;16
-
 
883
pci_bus_write32 dd pci_bus.conf1_write32         ;20
-
 
884
 
-
 
885
align 4
-
 
886
pci_read8:
-
 
887
				mov		eax, PCI_R8
-
 
888
				jmp		@F
-
 
889
 
-
 
890
align 4
-
 
891
pci_read16:
-
 
892
				mov		eax, PCI_R16
-
 
893
				jmp		@F
-
 
894
 
-
 
895
align 4
-
 
896
pci_read32:
-
 
897
				mov		eax, PCI_R32
-
 
898
 
-
 
899
align 4
-
 
900
@@:
-
 
901
.bus			equ esp+4
-
 
902
.devfn 		equ esp+8
-
 
903
.pci_reg 	equ esp+12
-
 
904
 
-
 
905
				xor		ecx, ecx
-
 
906
				mov   ch, [.bus]
-
 
907
				mov   cl, [.devfn]
-
 
908
				movzx edx, word [.pci_reg]
-
 
909
 
-
 
910
				pushfd
-
 
911
				cli
-
 
912
 
-
 
913
				call	dword [pci_fn_table+eax]
-
 
914
 
-
 
915
				popfd
-
 
916
 
-
 
917
				ret 	12
-
 
918
 
-
 
919
align 4
-
 
920
pci_write8:
-
 
921
				mov		eax, PCI_W8
-
 
922
				jmp		@F
-
 
923
 
-
 
924
align 4
-
 
925
pci_write16:
-
 
926
				mov		eax, PCI_W16
-
 
927
				jmp		@F
-
 
928
 
-
 
929
align 4
-
 
930
pci_write32:
-
 
931
				mov		eax, PCI_W32
-
 
932
 
-
 
933
align 4
-
 
934
@@:
-
 
935
.bus			equ esp+4
-
 
936
.devfn 		equ esp+8
-
 
937
.pci_reg 	equ esp+12
-
 
938
.val      equ esp+16
-
 
939
 
-
 
940
				xor		ecx, ecx
-
 
941
				mov   ch, [.bus]
-
 
942
				mov   cl, [.devfn]
-
 
943
				movzx edx, word [.pci_reg]
-
 
944
 
-
 
945
				pushfd
-
 
946
				cli
-
 
947
 
-
 
948
				push  dword [esp+20]
-
 
949
				call	dword [pci_fn_table+eax]
-
 
950
 
-
 
951
				popfd
-
 
952
 
-
 
953
				ret 	16