Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3545 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_1              = 0x14          ; 32 bits
17
        PCI_BASE_ADDRESS_2              = 0x18          ; 32 bits
18
        PCI_BASE_ADDRESS_3              = 0x1c          ; 32 bits
19
        PCI_BASE_ADDRESS_4              = 0x20          ; 32 bits
20
        PCI_BASE_ADDRESS_5              = 0x24          ; 32 bits
21
        PCI_BASE_ADDRESS_SPACE_IO       = 0x01
22
        PCI_BASE_ADDRESS_IO_MASK        = 0xFFFFFFFC
23
        PCI_BASE_ADDRESS_MEM_MASK       = 0xFFFFFFF0
24
 
25
; PCI programming
26
 
27
        PCI_VENDOR_ID                   = 0x00          ; 16 bit
28
        PCI_DEVICE_ID                   = 0x02          ; 16 bits
29
        PCI_REG_COMMAND                 = 0x4           ; command register
30
        PCI_REG_STATUS                  = 0x6           ; status register
31
        PCI_REVISION_ID                 = 0x08          ; 8 bits
32
        PCI_REG_LATENCY                 = 0xd           ; latency timer register
33
        PCI_REG_CAP_PTR                 = 0x34          ; capabilities pointer
34
        PCI_REG_IRQ                     = 0x3c
35
        PCI_REG_CAPABILITY_ID           = 0x0           ; capapility ID in pm register block
36
        PCI_REG_PM_STATUS               = 0x4           ; power management status register
37
        PCI_REG_PM_CTRL                 = 0x4           ; power management control register
38
        PCI_BIT_PIO                     = 1             ; bit0: io space control
39
        PCI_BIT_MMIO                    = 2             ; bit1: memory space control
40
        PCI_BIT_MASTER                  = 4             ; bit2: device acts as a PCI master
41
 
42
 
43
macro   PCI_find_io {
44
 
45
        local   .check, .inc, .got
46
 
47
        xor     eax, eax
48
        mov     esi, PCI_BASE_ADDRESS_0
49
  .check:
50
        stdcall PciRead32, [device.pci_bus], [device.pci_dev], esi
51
 
52
        test    eax, PCI_BASE_ADDRESS_IO_MASK
53
        jz      .inc
54
 
55
        test    eax, PCI_BASE_ADDRESS_SPACE_IO
56
        jz      .inc
57
 
58
        and     eax, PCI_BASE_ADDRESS_IO_MASK
59
        jmp     .got
60
 
61
  .inc:
62
        add     esi, 4
63
        cmp     esi, PCI_BASE_ADDRESS_5
64
        jbe     .check
65
        xor     eax, eax
66
 
67
  .got:
68
        mov     [device.io_addr], eax
69
 
70
}
71
 
72
 
73
macro   PCI_find_mmio32 {
74
 
75
        local   .check, .inc, .got
76
 
77
        mov     esi, PCI_BASE_ADDRESS_0
78
  .check:
79
        stdcall PciRead32, [device.pci_bus], [device.pci_dev], esi
80
 
81
        test    eax, PCI_BASE_ADDRESS_SPACE_IO  ; mmio address?
82
        jnz     .inc
83
 
84
        test    eax, 100b       ; 64 bit?
85
        jnz     .inc
86
        and     eax, not 1111b
87
        jmp     .got
88
 
89
  .inc:
90
        add     esi, 4
91
        cmp     esi, PCI_BASE_ADDRESS_5
92
        jbe     .check
93
        xor     eax, eax
94
 
95
  .got:
96
        mov     [device.mmio_addr], eax
97
}
98
 
99
macro   PCI_find_irq {
100
 
101
        stdcall PciRead8, [device.pci_bus], [device.pci_dev], PCI_REG_IRQ
102
        mov     [device.irq_line], al
103
 
104
}
105
 
106
macro   PCI_find_rev {
107
 
108
        stdcall PciRead8, [device.pci_bus], [device.pci_dev], PCI_REVISION_ID
109
        mov     [device.revision], al
110
 
111
}
112
 
113
macro   PCI_make_bus_master bus, dev {
114
 
115
        stdcall PciRead32, [device.pci_bus], [device.pci_dev], PCI_REG_COMMAND
116
        or      al, PCI_BIT_MASTER
117
        stdcall PciWrite32, [device.pci_bus], [device.pci_dev], PCI_REG_COMMAND, eax
118
 
119
}
120
 
121
macro   PCI_adjust_latency min {
122
 
123
        local   .not
124
 
125
        stdcall PciRead8, [device.pci_bus], [device.pci_dev], PCI_REG_LATENCY
126
        cmp     al, min
127
        ja      .not
128
        mov     al, min
129
        stdcall PciWrite8, [device.pci_bus], [device.pci_dev], PCI_REG_LATENCY, eax
130
  .not:
131
 
132
}