Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
4522 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;          GNU GENERAL PUBLIC LICENSE                             ;;
7
;;             Version 2, June 1991                                ;;
8
;;                                                                 ;;
9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10
 
11
struct  PCI_header
12
 
13
        vendor_id       dw ?
14
        device_id       dw ?
15
        command         dw ?
16
        status          dw ?
17
        revision_id     db ?
18
        prog_if         db ?
19
        subclass        db ?
20
        class_code      db ?
21
        cache_line_size db ?
22
        latency_timer   db ?
23
        header_type     db ?
24
        bist            db ?
25
 
26
ends
27
 
28
struct  PCI_header00    PCI_header
29
 
30
        base_addr_0     dd ?
31
        base_addr_1     dd ?
32
        base_addr_2     dd ?
33
        base_addr_3     dd ?
34
        base_addr_4     dd ?
35
        base_addr_5     dd ?
36
        cardbus_cis_ptr dd ?
37
        subsys_vendor   dw ?
38
        subsys_id       dw ?
39
        exp_rom_addr    dd ?
40
        cap_ptr         db ?
41
        reserved        rb 7
42
        interrupt_line  db ?
43
        interrupt_pin   db ?
44
        min_grant       db ?
45
        max_latency     db ?
46
 
47
ends
48
 
49
; Base address bits
50
        PCI_BASE_ADDRESS_SPACE_IO       = 0x01
51
        PCI_BASE_ADDRESS_IO_MASK        = 0xFFFFFFFC
52
        PCI_BASE_ADDRESS_MEM_MASK       = 0xFFFFFFF0
53
 
54
; command bits
55
        PCI_CMD_PIO                     = 1             ; bit0: io space control
56
        PCI_CMD_MMIO                    = 2             ; bit1: memory space control
57
        PCI_CMD_MASTER                  = 4             ; bit2: device acts as a PCI master
58
 
59
 
60
if used PCI_find_io
61
proc PCI_find_io stdcall bus, dev
62
 
63
        push    esi
64
        xor     eax, eax
4532 hidnplayr 65
        mov     esi, PCI_header00.base_addr_0
4522 hidnplayr 66
  .check:
67
        invoke  PciRead32, [bus], [dev], esi
68
        test    eax, PCI_BASE_ADDRESS_IO_MASK
69
        jz      .inc
70
        test    eax, PCI_BASE_ADDRESS_SPACE_IO
71
        jz      .inc
72
        and     eax, PCI_BASE_ADDRESS_IO_MASK
73
        pop     esi
74
        ret
75
 
76
  .inc:
77
        add     esi, 4
4532 hidnplayr 78
        cmp     esi, PCI_header00.base_addr_5
4522 hidnplayr 79
        jbe     .check
80
        pop     esi
81
        xor     eax, eax
82
        ret
83
 
84
endp
85
end if
86
 
87
 
88
if used PCI_find_mmio32
89
proc PCI_find_mmio32 stdcall bus, dev
90
 
91
        push    esi
92
        mov     esi, PCI_header00.base_addr_0
93
  .check:
94
        invoke  PciRead32, [bus], [dev], esi
95
        test    eax, PCI_BASE_ADDRESS_SPACE_IO  ; mmio address?
96
        jnz     .inc
97
        test    eax, 100b       ; 64 bit?
98
        jnz     .inc
99
        and     eax, not 1111b
100
        pop     esi
101
        ret
102
 
103
  .inc:
104
        add     esi, 4
105
        cmp     esi, PCI_header00.base_addr_5
106
        jbe     .check
107
        xor     eax, eax
108
        pop     esi
109
        ret
110
 
111
endp
112
end if