summaryrefslogtreecommitdiff
path: root/cpu/amd/geode_lx/gplvsa_ii/sysmgr/chip.asm
blob: 1630d754eba41d6ecb11ba3702509d1824af0c08 (plain)
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
; 
; 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 the Southbridge specific code.  
;********************************************************************************




include smimac.mac
include chipset.inc
include pci.inc
include sysmgr.inc
include init.inc
include cs5536.inc


.model small,c
.586
.CODE


externdef Errors:	word
externdef Device_ID:	word
externdef Chipset_Base:	dword

;***********************************************************************
; Clear all SMI source registers
;***********************************************************************
Clear_SMIs proc

	mov	ax, [Device_ID]		; Get Southbridge Device ID
	cmp	ax, DEVICE_ID_5536	; If CS5536, exit
	clc
	je	Exit
	
	or	[Errors], ERR_NO_CHIPSET
	stc
	jmp	Exit
	
Exit:	ret

Clear_SMIs endp




;****************************************************************
; Returns information about the Southbridge
;
; On Exit, if CF clear:
;   EBX = PCI address of Southbridge
;    CL = Chipset Revision
;    DX = Device ID
;****************************************************************
Get_Sbridge_Info proc

	mov	ebx, 80000000h+(15 SHL 11) ; Start at Bus 0;  DevNum 15
SouthbridgeLoop:
	call	Read_PCI32
	cmp	ax, VENDOR_ID_CYRIX	; Is it a Cyrix chipset ?
	je	short CorrectVendorID
	cmp	ax, VENDOR_ID_NATIONAL	; Is it a National Semiconductor chipset ?
	je	short CorrectVendorID
	cmp	ax, VENDOR_ID_AMD	; Is it an AMD chipset ?
	jne	short NextDevice
CorrectVendorID:
	shr	eax, 16
	push	ax			; Save device ID

	mov	bl, 8			; Read Class Code & Rev ID
	call	Read_PCI32
	mov	cl, al			; Save revision in CL
	shr	eax, 16	
	cmp	ax, 0601h		; Is it an ISA bridge ?
	pop	dx
	mov	bl, 0			; Vendor & Device ID
	je	Exit			; CF is cleared 


	; Check the DeviceID
	cmp	dx, DEVICE_ID_5536-1	; Hardware CS5536 Device ID
	jne	NextDevice
FoundSB:
	; On CS5536, the virtualized Device ID is h/w Device ID + 1
	inc	dx
	push	cx
	push	dx
	mov	ecx, 5100002Fh		; Write-post I/O to port 84h for debug
	mov	edx, 00084001h
	mov	eax, edx
	or	al, 8
	wrmsr
	pop	dx
	pop	cx
	jmp	Exit

NextDevice:
	add	bh, 8			; Next device
	cmp	bh, (19 SHL 3)		; Last possible DevNum ?
	jbe	SouthbridgeLoop

	; Can't find supported Southbridge chipset
	or	[Errors], ERR_NO_CHIPSET
	stc
	
Exit:	ret

Get_Sbridge_Info endp


;****************************************************************
; Generates a s/w SMI
;****************************************************************
Software_SMI proc

	smint
	ret
	
Software_SMI endp	


;*********************************************************************************
; Reads 32-bit PCI config register specified by EBX
;*********************************************************************************
Read_PCI32 proc

	mov	dx, PCI_CONFIG_ADDRESS
	mov	eax, ebx
	out	dx, eax
	mov 	dx, PCI_CONFIG_DATA
	in	eax, dx
	ret

Read_PCI32 endp




;*********************************************************************************
; Writes a 32 bit Southbridge register
; Input:
;   DL - register offset
;  EAX - value to write
;*********************************************************************************
SetReg_32 proc uses bx

	push	eax
	mov	bl, dl
	call	Address8
	pop	eax
	out	dx, eax
	ret

SetReg_32 endp


;*********************************************************************************
; Writes an 8 bit register
; Input:
;   BL = register #
;   BH = Data
;*********************************************************************************
SetReg_8 proc

	call	Address8
	mov	al, bh
	out	dx, al
	ret

SetReg_8 endp



;*********************************************************************************
; Reads an 8 bit register
; Input:
;   BL = register #
; Output:
;   AL = Data
;*********************************************************************************
GetReg_8 proc

	call	Address8
	in	al, dx
	ret

GetReg_8 endp

;*********************************************************************************
; Helper routine for SetReg_32, SetReg_8 & GetReg_8
;*********************************************************************************
Address8 proc

	mov	dx, PCI_CONFIG_ADDRESS
	mov	eax, [Chipset_Base]
	mov	al, bl
	and	al, NOT 3
	out	dx, eax
	mov	dx, PCI_CONFIG_DATA
	and	bl, 3
	add	dl, bl
	ret

Address8 endp





;*********************************************************************************
; Determines the base address of the top-level SMI status register
; On Exit:
;   EAX = address
;*********************************************************************************
Get_SMI_Base proc
	
	mov	ebx, [Chipset_Base]		; Patch SMI_Base
	add	bx, PM_FUNCTION + BAR0
	call	Read_PCI32
	mov	al, SMI_STATUS
	ret

Get_SMI_Base endp	
	


;*********************************************************************************
; Determines the base address of the internal IRQ register
; On Exit:
;   EAX = address
;*********************************************************************************
Get_IRQ_Base proc
	
	mov	ebx, [Chipset_Base]		; Patch SMI_Base
	add	bx, AUDIO_FUNCTION + BAR0	; Patch IRQ_Base
	call	Read_PCI32
	mov	al, 1Ah
	ret

Get_IRQ_Base endp



	END