Subversion Repositories Kolibri OS

Rev

Rev 3199 | 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
2935 hidnplayr 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
2886 hidnplayr 20
        PCI_BASE_ADDRESS_5              = 0x24          ; 32 bits
21
        PCI_BASE_ADDRESS_SPACE_IO       = 0x01
22
        PCI_BASE_ADDRESS_IO_MASK        = 0xFFFFFFFC
2935 hidnplayr 23
        PCI_BASE_ADDRESS_MEM_MASK       = 0xFFFFFFF0
2886 hidnplayr 24
 
25
; PCI programming
26
 
2935 hidnplayr 27
        PCI_VENDOR_ID                   = 0x00          ; 16 bit
28
        PCI_DEVICE_ID                   = 0x02          ; 16 bits
2886 hidnplayr 29
        PCI_REG_COMMAND                 = 0x4           ; command register
30
        PCI_REG_STATUS                  = 0x6           ; status register
2935 hidnplayr 31
        PCI_REVISION_ID                 = 0x08          ; 8 bits
2886 hidnplayr 32
        PCI_REG_LATENCY                 = 0xd           ; latency timer register
33
        PCI_REG_CAP_PTR                 = 0x34          ; capabilities pointer
2935 hidnplayr 34
        PCI_REG_IRQ                     = 0x3c
2886 hidnplayr 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
 
3205 hidnplayr 43
macro   PCI_find_io {
2886 hidnplayr 44
 
45
        local   .check, .inc, .got
46
 
47
        xor     eax, eax
48
        mov     esi, PCI_BASE_ADDRESS_0
49
  .check:
3205 hidnplayr 50
        stdcall PciRead32, [device.pci_bus], [device.pci_dev], esi
2886 hidnplayr 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
2922 hidnplayr 64
        jbe     .check
65
        xor     eax, eax
2886 hidnplayr 66
 
67
  .got:
3205 hidnplayr 68
        mov     [device.io_addr], eax
2886 hidnplayr 69
 
70
}
71
 
72
 
3205 hidnplayr 73
macro   PCI_find_mmio32 {
2886 hidnplayr 74
 
2922 hidnplayr 75
        local   .check, .inc, .got
2886 hidnplayr 76
 
77
        mov     esi, PCI_BASE_ADDRESS_0
78
  .check:
3205 hidnplayr 79
        stdcall PciRead32, [device.pci_bus], [device.pci_dev], esi
2886 hidnplayr 80
 
2922 hidnplayr 81
        test    eax, PCI_BASE_ADDRESS_SPACE_IO  ; mmio address?
82
        jnz     .inc
2886 hidnplayr 83
 
2922 hidnplayr 84
        test    eax, 100b       ; 64 bit?
85
        jnz     .inc
86
        and     eax, not 1111b
87
        jmp     .got
88
 
89
  .inc:
2886 hidnplayr 90
        add     esi, 4
91
        cmp     esi, PCI_BASE_ADDRESS_5
2922 hidnplayr 92
        jbe     .check
93
        xor     eax, eax
2886 hidnplayr 94
 
95
  .got:
3205 hidnplayr 96
        mov     [device.mmio_addr], eax
2886 hidnplayr 97
}
98
 
3205 hidnplayr 99
macro   PCI_find_irq {
2886 hidnplayr 100
 
3205 hidnplayr 101
        stdcall PciRead8, [device.pci_bus], [device.pci_dev], PCI_REG_IRQ
102
        mov     [device.irq_line], al
2886 hidnplayr 103
 
104
}
105
 
3205 hidnplayr 106
macro   PCI_find_rev {
2886 hidnplayr 107
 
3205 hidnplayr 108
        stdcall PciRead8, [device.pci_bus], [device.pci_dev], PCI_REVISION_ID
109
        mov     [device.revision], al
2886 hidnplayr 110
 
111
}
112
 
3205 hidnplayr 113
macro   PCI_make_bus_master bus, dev {
2886 hidnplayr 114
 
3205 hidnplayr 115
        stdcall PciRead32, [device.pci_bus], [device.pci_dev], PCI_REG_COMMAND
2911 hidnplayr 116
        or      al, PCI_BIT_MASTER
3205 hidnplayr 117
        stdcall PciWrite32, [device.pci_bus], [device.pci_dev], PCI_REG_COMMAND, eax
2886 hidnplayr 118
 
2911 hidnplayr 119
}
2886 hidnplayr 120
 
3205 hidnplayr 121
macro   PCI_adjust_latency min {
2911 hidnplayr 122
 
3205 hidnplayr 123
        local   .not
124
 
125
        stdcall PciRead8, [device.pci_bus], [device.pci_dev], PCI_REG_LATENCY
2911 hidnplayr 126
        cmp     al, min
3205 hidnplayr 127
        ja      .not
2911 hidnplayr 128
        mov     al, min
3205 hidnplayr 129
        stdcall PciWrite8, [device.pci_bus], [device.pci_dev], PCI_REG_LATENCY, eax
130
  .not:
2911 hidnplayr 131
 
132
}