Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2886 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2012. 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
 
12
; PCI Bus defines
13
 
14
        PCI_HEADER_TYPE                 = 0x0e          ; 8 bit
15
        PCI_BASE_ADDRESS_0              = 0x10          ; 32 bit
16
        PCI_BASE_ADDRESS_5              = 0x24          ; 32 bits
17
        PCI_BASE_ADDRESS_SPACE_IO       = 0x01
18
        PCI_VENDOR_ID                   = 0x00          ; 16 bit
19
        PCI_BASE_ADDRESS_IO_MASK        = 0xFFFFFFFC
20
 
21
; PCI programming
22
 
23
        PCI_REG_COMMAND                 = 0x4           ; command register
24
        PCI_REG_STATUS                  = 0x6           ; status register
25
        PCI_REG_LATENCY                 = 0xd           ; latency timer register
26
        PCI_REG_CAP_PTR                 = 0x34          ; capabilities pointer
27
        PCI_REG_CAPABILITY_ID           = 0x0           ; capapility ID in pm register block
28
        PCI_REG_PM_STATUS               = 0x4           ; power management status register
29
        PCI_REG_PM_CTRL                 = 0x4           ; power management control register
30
        PCI_BIT_PIO                     = 1             ; bit0: io space control
31
        PCI_BIT_MMIO                    = 2             ; bit1: memory space control
32
        PCI_BIT_MASTER                  = 4             ; bit2: device acts as a PCI master
33
 
34
 
35
macro   find_io bus, dev, io {
36
 
37
        local   .check, .inc, .got
38
 
39
        xor     eax, eax
40
        mov     esi, PCI_BASE_ADDRESS_0
41
        movzx   ecx, bus
42
        movzx   edx, dev
43
  .check:
44
        stdcall PciRead32, ecx ,edx ,esi
45
 
46
        test    eax, PCI_BASE_ADDRESS_IO_MASK
47
        jz      .inc
48
 
49
        test    eax, PCI_BASE_ADDRESS_SPACE_IO
50
        jz      .inc
51
 
52
        and     eax, PCI_BASE_ADDRESS_IO_MASK
53
        mov     io , eax
54
        jmp     .got
55
 
56
  .inc:
57
        add     esi, 4
58
        cmp     esi, PCI_BASE_ADDRESS_5
59
        jle     .check
60
 
61
  .got:
62
 
63
}
64
 
65
 
66
macro   find_mmio32 bus, dev, mmio32 {
67
 
68
        local   .check, .got
69
 
70
        xor     eax, eax
71
        mov     esi, PCI_BASE_ADDRESS_0
72
        movzx   ecx, bus
73
        movzx   edx, dev
74
  .check:
75
        stdcall PciRead32, ecx ,edx ,esi
76
 
77
        test    eax, not PCI_BASE_ADDRESS_IO_MASK
78
        jz      .got
79
 
80
        add     esi, 4
81
        cmp     esi, PCI_BASE_ADDRESS_5
82
        jle     .check
83
 
84
        xor     eax, eax
85
  .got:
86
        mov     mmio32, eax
87
 
88
}
89
 
90
macro   find_irq bus, dev, irq {
91
 
92
        push    eax edx ecx
93
        movzx   ecx, bus
94
        movzx   edx, dev
95
        stdcall PciRead8, ecx ,edx ,0x3c                                ; 0x3c is the offset where irq can be found
96
        mov     irq, al
97
        pop     ecx edx eax
98
 
99
}
100
 
101
macro   find_rev bus, dev, rev {
102
 
103
        push    eax edx ecx
104
        movzx   ecx, bus
105
        movzx   edx, dev
106
        stdcall PciRead8, ecx ,edx ,0x8
107
        mov     rev, al
108
        pop     ecx edx eax
109
 
110
}
111
 
112
macro   make_bus_master bus, dev {
113
 
114
        movzx   ecx, bus
115
        movzx   edx, dev
116
        stdcall PciRead32, ecx ,edx, PCI_REG_COMMAND
2911 hidnplayr 117
        or      al, PCI_BIT_MASTER
2886 hidnplayr 118
        stdcall PciWrite32, ecx, edx, PCI_REG_COMMAND, eax
119
 
2911 hidnplayr 120
}
2886 hidnplayr 121
 
2911 hidnplayr 122
macro   adjust_latency bus, dev, min {
123
 
124
        movzx   ecx, bus
125
        movzx   edx, dev
126
        stdcall PciRead8, ecx ,edx, PCI_REG_LATENCY
127
        cmp     al, min
128
        ja      @f
129
        mov     al, min
130
        stdcall PciWrite8, ecx, edx, PCI_REG_LATENCY, eax
131
  @@:
132
 
133
}