1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
;
; Copyright (c) 2006-2008 Advanced Micro Devices,Inc. ("AMD").
;
; This library is free software; you can redistribute it and/or modify
; it under the terms of the GNU Lesser General Public License as
; published by the Free Software Foundation; either version 2.1 of the
; License, or (at your option) any later version.
;
; This code is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; Lesser General Public License for more details.
;
; You should have received a copy of the GNU Lesser General
; Public License along with this library; if not, write to the
; Free Software Foundation, Inc., 59 Temple Place, Suite 330,
; Boston, MA 02111-1307 USA
;
;*******************************************************************************
;* This file contains PCI related library functions.
;*******************************************************************************
include sysmgr.inc
include pci.inc
include vsa2.inc
include gx2.inc
.model tiny,c
.586p
.CODE
externdef sys_system_call:proc
;**********************************************************************
; Writes the PCI Config Address
; Input:
; EAX = config address
; Output:
; DX = points to 0xCFC-0xCFF
;**********************************************************************
PCI_Common proc
mov dx, PCI_CONFIG_ADDRESS
ror eax, 16 ; Set 16 MSBs to 8000h
mov ax, 8000h
ror eax, 16
out dx, eax
add dl, 4 ; PCI_CONFIG_DATA + 2 LSBs
and al, 3
add dl, al
ret
PCI_Common endp
;**********************************************************************
; Reads a byte PCI register
;**********************************************************************
read_PCI_byte proc pascal PCI_Config_Addr:DWORD
mov eax, [PCI_Config_Addr]
call PCI_Common
in al, dx
ret
read_PCI_byte endp
;**********************************************************************
; Reads a word PCI register
;**********************************************************************
read_PCI_word proc pascal \
PCI_Config_Addr:DWORD
mov eax, [PCI_Config_Addr]
call PCI_Common
in ax, dx
ret
read_PCI_word endp
;**********************************************************************
; Reads a dword PCI register
;**********************************************************************
read_PCI_dword proc pascal \
PCI_Config_Addr:DWORD
mov eax, [PCI_Config_Addr]
call PCI_Common
in eax, dx
mov edx, eax
shr edx, 16
ret
read_PCI_dword endp
;**********************************************************************
; Writes a byte PCI register
;**********************************************************************
write_PCI_byte proc pascal \
PCI_Config_Addr: DWORD, \
Data: BYTE
mov eax, [PCI_Config_Addr]
call PCI_Common
mov al, [Data]
out dx, al
ret
write_PCI_byte endp
;**********************************************************************
; Writes a word PCI register
;**********************************************************************
write_PCI_word proc pascal \
PCI_Config_Addr:DWORD, \
Data:WORD
mov eax, [PCI_Config_Addr]
call PCI_Common
mov ax, [Data]
out dx, ax
ret
write_PCI_word endp
;**********************************************************************
; Writes a dword PCI register
;**********************************************************************
write_PCI_dword proc pascal \
PCI_Config_Addr: DWORD, \
Data: DWORD
mov eax, [PCI_Config_Addr]
call PCI_Common
mov eax, [Data]
out dx, eax
ret
write_PCI_dword endp
;**********************************************************************
; Disables PCI trapping (except virtualized PCI devices)
;**********************************************************************
Disable_PCI_Traps proc
; Has MPCI NB MSR been determined yet ?
mov ecx, [PBus_Addr]
or ecx, ecx
jnz GotPbus
; No, get routing address for MPCI NB
push bx
push ID_MPCI ; MBus ID
push 1 ; Instance
call sys_lookup_device
pop bx
mov cx, dx
shl ecx, 16
mov cx, MPCI_PBUS
mov [PBus_Addr], ecx
; Compute mask for virtual Southbridge
mov ax, word ptr (VSM_Header PTR ds:[0]).SysStuff.Southbridge
shr ah, 3
mov cl, ah
mov eax, 1
shl eax, cl
or al, 2 ; Assume Northbridge is at 0x80000800
mov [PBus_Mask], eax
GotPbus:
rdmsr
mov [PBus_Hi], edx ; Save original value for Restore_PCI_Traps
mov [PBus_Lo], eax
and eax, [PBus_Mask] ; Disable all except virtual NB & SB
wrmsr
ret
Disable_PCI_Traps endp
;**********************************************************************
; Restores PCI trapping
;**********************************************************************
Restore_PCI_Traps proc uses eax edx
mov edx, [PBus_Hi]
mov eax, [PBus_Lo]
wrmsr
ret
Restore_PCI_Traps endp
PBus_Addr dd 0
PBus_Hi dd 0
PBus_Lo dd 0
PBus_Mask dd 0
;**********************************************************************
; Performs a PCI configuration write cycle sans any PCI trapping except
; for virtualized PCI devices.
;**********************************************************************
write_PCI_no_trap proc pascal uses si \
PCI_Config_Addr:DWORD, \
Data: DWORD, \
DataSize: WORD
mov ebx, [PCI_Config_Addr]
mov si, [DataSize]
; Disable PCI trapping on all but virtualized PCI devices
call Disable_PCI_Traps
mov eax, ebx
call PCI_Common
mov eax, [Data]
cmp si, BYTE_IO
jne short NotByte
out dx, al
jmp short RestoreTraps
NotByte:
cmp si, WORD_IO
je short WordWrite
db 66h ; Make the following instruction an OUT DX,EAX
WordWrite:
out dx, ax
RestoreTraps:
call Restore_PCI_Traps ; Restore PCI trapping
Exit: ret
write_PCI_no_trap endp
;**********************************************************************
; Performs a PCI configuration read cycle sans any PCI trapping except
; for virtualized PCI devices.
;**********************************************************************
read_PCI_no_trap proc pascal uses si\
PCI_Config_Addr: DWORD, \
DataSize: WORD
mov ebx, [PCI_Config_Addr]
mov si, [DataSize]
; Disable PCI trapping on all but virtualized PCI devices
call Disable_PCI_Traps
mov eax, ebx ; Output PCI address
call PCI_Common
cmp si, BYTE_IO
jne short NotByte
in al, dx
jmp short RestoreTraps
NotByte:
cmp si, WORD_IO
je short WordRead
db 66h ; Makes the following instruction an IN EAX,DX
WordRead:
in ax, dx
RestoreTraps:
push eax
call Restore_PCI_Traps ; Restore PCI trapping
pop eax
mov edx, eax
shr edx, 16
Exit: ret
read_PCI_no_trap endp
END
|