Rev 1354 | Rev 1370 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
586 | serge | 2 | ;; ;; |
431 | serge | 3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;; ;; |
||
586 | serge | 7 | ;; PCI32.INC ;; |
8 | ;; ;; |
||
9 | ;; 32 bit PCI driver code ;; |
||
10 | ;; ;; |
||
11 | ;; Version 0.3 April 9, 2007 ;; |
||
12 | ;; Version 0.2 December 21st, 2002 ;; |
||
13 | ;; ;; |
||
14 | ;; Author: Victor Prodan, victorprodan@yahoo.com ;; |
||
15 | ;; Mihailov Ilia, ghost.nsk@gmail.com ;; |
||
16 | ;; Credits: ;; |
||
17 | ;; Ralf Brown ;; |
||
18 | ;; Mike Hibbett, mikeh@oceanfree.net ;; |
||
19 | ;; ;; |
||
20 | ;; See file COPYING for details ;; |
||
21 | ;; ;; |
||
431 | serge | 22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ha | 23 | |
750 | victor | 24 | $Revision: 1358 $ |
1 | ha | 25 | |
26 | ;*************************************************************************** |
||
27 | ; Function |
||
28 | ; pci_api: |
||
29 | ; |
||
30 | ; Description |
||
31 | ; entry point for system PCI calls |
||
32 | ;*************************************************************************** |
||
33 | |||
34 | align 4 |
||
35 | |||
36 | pci_api: |
||
37 | |||
1348 | art_zh | 38 | cmp [pci_access_enabled],1 |
39 | jne no_pci_access_for_applications |
||
1 | ha | 40 | |
1348 | art_zh | 41 | or al,al |
42 | jnz pci_fn_1 |
||
43 | ; PCI function 0: get pci version (AH.AL) |
||
44 | movzx eax,word [BOOT_VAR+0x9022] |
||
45 | ret |
||
1 | ha | 46 | |
47 | pci_fn_1: |
||
1348 | art_zh | 48 | cmp al,1 |
49 | jnz pci_fn_2 |
||
1 | ha | 50 | |
1348 | art_zh | 51 | ; PCI function 1: get last bus in AL |
52 | mov al,[BOOT_VAR+0x9021] |
||
53 | ret |
||
1 | ha | 54 | |
55 | pci_fn_2: |
||
1348 | art_zh | 56 | cmp al,2 |
57 | jne pci_fn_3 |
||
58 | ; PCI function 2: get pci access mechanism |
||
59 | mov al,[BOOT_VAR+0x9020] |
||
60 | ret |
||
1 | ha | 61 | pci_fn_3: |
62 | |||
1348 | art_zh | 63 | cmp al,4 |
64 | jz pci_read_reg ;byte |
||
65 | cmp al,5 |
||
66 | jz pci_read_reg ;word |
||
67 | cmp al,6 |
||
68 | jz pci_read_reg ;dword |
||
1 | ha | 69 | |
1348 | art_zh | 70 | cmp al,8 |
71 | jz pci_write_reg ;byte |
||
72 | cmp al,9 |
||
73 | jz pci_write_reg ;word |
||
74 | cmp al,10 |
||
75 | jz pci_write_reg ;dword |
||
1 | ha | 76 | |
1354 | diamond | 77 | if defined mmio_pci_addr |
1348 | art_zh | 78 | cmp al,11 ; <<< user-level MMIO functions <<< NEW! |
79 | jz pci_mmio_init |
||
80 | cmp al,12 |
||
81 | jz pci_mmio_map |
||
82 | cmp al,13 |
||
83 | jz pci_mmio_unmap |
||
1354 | diamond | 84 | end if |
1348 | art_zh | 85 | |
1 | ha | 86 | no_pci_access_for_applications: |
87 | |||
1348 | art_zh | 88 | mov eax,-1 |
1 | ha | 89 | |
1348 | art_zh | 90 | ret |
1 | ha | 91 | |
92 | ;*************************************************************************** |
||
93 | ; Function |
||
94 | ; pci_make_config_cmd |
||
95 | ; |
||
96 | ; Description |
||
97 | ; creates a command dword for use with the PCI bus |
||
98 | ; bus # in ah |
||
99 | ; device+func in bh (dddddfff) |
||
100 | ; register in bl |
||
101 | ; |
||
102 | ; command dword returned in eax ( 10000000 bbbbbbbb dddddfff rrrrrr00 ) |
||
103 | ;*************************************************************************** |
||
104 | |||
105 | align 4 |
||
106 | |||
107 | pci_make_config_cmd: |
||
1348 | art_zh | 108 | shl eax,8 ; move bus to bits 16-23 |
109 | mov ax,bx ; combine all |
||
1 | ha | 110 | and eax,0xffffff |
1348 | art_zh | 111 | or eax,0x80000000 |
1 | ha | 112 | ret |
113 | |||
114 | ;*************************************************************************** |
||
115 | ; Function |
||
116 | ; pci_read_reg: |
||
117 | ; |
||
118 | ; Description |
||
119 | ; read a register from the PCI config space into EAX/AX/AL |
||
120 | ; IN: ah=bus,device+func=bh,register address=bl |
||
121 | ; number of bytes to read (1,2,4) coded into AL, bits 0-1 |
||
586 | serge | 122 | ; (0 - byte, 1 - word, 2 - dword) |
1 | ha | 123 | ;*************************************************************************** |
124 | |||
125 | align 4 |
||
126 | |||
127 | pci_read_reg: |
||
1348 | art_zh | 128 | cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? |
129 | je pci_read_reg_2 |
||
1 | ha | 130 | |
1348 | art_zh | 131 | ; mechanism 1 |
132 | push esi ; save register size into ESI |
||
133 | mov esi,eax |
||
134 | and esi,3 |
||
1 | ha | 135 | |
1348 | art_zh | 136 | call pci_make_config_cmd |
137 | mov ebx,eax |
||
138 | ; get current state |
||
139 | mov dx,0xcf8 |
||
140 | in eax, dx |
||
141 | push eax |
||
142 | ; set up addressing to config data |
||
143 | mov eax,ebx |
||
144 | and al,0xfc ; make address dword-aligned |
||
145 | out dx,eax |
||
146 | ; get requested DWORD of config data |
||
147 | mov dl,0xfc |
||
148 | and bl,3 |
||
149 | or dl,bl ; add to port address first 2 bits of register address |
||
1 | ha | 150 | |
1348 | art_zh | 151 | or esi,esi |
152 | jz pci_read_byte1 |
||
153 | cmp esi,1 |
||
154 | jz pci_read_word1 |
||
155 | cmp esi,2 |
||
156 | jz pci_read_dword1 |
||
157 | jmp pci_fin_read1 |
||
1 | ha | 158 | |
159 | pci_read_byte1: |
||
1348 | art_zh | 160 | in al,dx |
161 | jmp pci_fin_read1 |
||
1 | ha | 162 | pci_read_word1: |
1348 | art_zh | 163 | in ax,dx |
164 | jmp pci_fin_read1 |
||
1 | ha | 165 | pci_read_dword1: |
1348 | art_zh | 166 | in eax,dx |
167 | jmp pci_fin_read1 |
||
1 | ha | 168 | pci_fin_read1: |
1348 | art_zh | 169 | ; restore configuration control |
170 | xchg eax,[esp] |
||
171 | mov dx,0xcf8 |
||
172 | out dx,eax |
||
1 | ha | 173 | |
1348 | art_zh | 174 | pop eax |
175 | pop esi |
||
176 | ret |
||
1 | ha | 177 | pci_read_reg_2: |
178 | |||
1348 | art_zh | 179 | test bh,128 ;mech#2 only supports 16 devices per bus |
180 | jnz pci_read_reg_err |
||
1 | ha | 181 | |
1348 | art_zh | 182 | push esi ; save register size into ESI |
183 | mov esi,eax |
||
184 | and esi,3 |
||
1 | ha | 185 | |
1348 | art_zh | 186 | push eax |
187 | ;store current state of config space |
||
188 | mov dx,0xcf8 |
||
189 | in al,dx |
||
190 | mov ah,al |
||
191 | mov dl,0xfa |
||
192 | in al,dx |
||
1 | ha | 193 | |
1348 | art_zh | 194 | xchg eax,[esp] |
195 | ; out 0xcfa,bus |
||
196 | mov al,ah |
||
197 | out dx,al |
||
198 | ; out 0xcf8,0x80 |
||
199 | mov dl,0xf8 |
||
200 | mov al,0x80 |
||
201 | out dx,al |
||
202 | ; compute addr |
||
203 | shr bh,3 ; func is ignored in mechanism 2 |
||
204 | or bh,0xc0 |
||
205 | mov dx,bx |
||
1 | ha | 206 | |
1348 | art_zh | 207 | or esi,esi |
208 | jz pci_read_byte2 |
||
209 | cmp esi,1 |
||
210 | jz pci_read_word2 |
||
211 | cmp esi,2 |
||
212 | jz pci_read_dword2 |
||
213 | jmp pci_fin_read2 |
||
1 | ha | 214 | |
215 | pci_read_byte2: |
||