Add missing license headers to some Geode LX related files.
[coreboot.git] / src / cpu / amd / model_lx / cpureginit.c
1 /*
2  * This file is part of the LinuxBIOS project.
3  *
4  * Copyright (C) 2006 Indrek Kruusa <indrek.kruusa@artecdesign.ee>
5  * Copyright (C) 2006 Ronald G. Minnich <rminnich@gmail.com>
6  * Copyright (C) 2007 Advanced Micro Devices, Inc.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21  */
22
23 /* ***************************************************************************/
24 /* **/
25 /* *    BIST */
26 /* **/
27 /* *    GX2 BISTs need to be run before BTB or caches are enabled.*/
28 /* *    BIST result left in registers on failure to be checked with FS2.*/
29 /* **/
30 /* ***************************************************************************/
31 static void
32 BIST(void){
33         int msrnum;
34         msr_t msr;
35
36         /* DM*/
37         msrnum = CPU_DM_CONFIG0;
38         msr = rdmsr(msrnum);
39         msr.lo |=  DM_CONFIG0_LOWER_DCDIS_SET;
40         wrmsr(msrnum, msr);
41         
42         msr.lo =  0x00000003F;
43         msr.hi =  0x000000000;
44         msrnum = CPU_DM_BIST;
45         wrmsr(msrnum, msr);
46
47         outb(POST_CPU_DM_BIST_FAILURE, 0x80);                           /* 0x29*/
48         msr = rdmsr(msrnum);                                            /* read back for pass fail*/
49         msr.lo &= 0x0F3FF0000;
50         if (msr.lo != 0xfeff0000)
51                 goto BISTFail;
52  
53         msrnum = CPU_DM_CONFIG0;
54         msr = rdmsr(msrnum);
55         msr.lo &=  ~ DM_CONFIG0_LOWER_DCDIS_SET;
56         wrmsr(msrnum, msr);
57
58         /* FPU*/
59         msr.lo =  0x000000131;
60         msr.hi = 0;
61         msrnum = CPU_FP_UROM_BIST;
62         wrmsr(msrnum, msr);
63
64         outb(POST_CPU_FPU_BIST_FAILURE, 0x80);                          /* 0x89*/
65         inb(0x80);                                                                      /*  IO delay*/
66         msr = rdmsr(msrnum);                                                    /* read back for pass fail*/
67         while ((msr.lo&0x884) != 0x884)
68                 msr = rdmsr(msrnum);                                    /*  Endless loop if BIST is broken*/
69         if ((msr.lo&0x642) != 0x642)
70                 goto BISTFail;
71
72         msr.lo = msr.hi = 0;                            /*  clear FPU BIST bits*/
73         msrnum = CPU_FP_UROM_BIST;
74         wrmsr(msrnum, msr);
75
76
77         /* BTB*/
78         msr.lo =  0x000000303;
79         msr.hi =  0x000000000;
80         msrnum = CPU_PF_BTBRMA_BIST;
81         wrmsr(msrnum, msr);
82
83         outb(POST_CPU_BTB_BIST_FAILURE  , 0x80);                                /* 0x8A*/
84         msr = rdmsr(msrnum);                                                    /* read back for pass fail*/
85         if ((msr.lo & 0x3030) != 0x3030)
86                 goto BISTFail;
87
88         return;
89
90 BISTFail:
91         print_err("BIST failed!\n");
92         while(1);
93 }
94 /* ***************************************************************************/
95 /* *    cpuRegInit*/
96 /* ***************************************************************************/
97 void
98 cpuRegInit (void){
99         int msrnum;
100         msr_t msr;
101         
102         //GX3 suspend: what is desired?
103
104         /*  Enable Suspend on Halt*/
105         /*msrnum = CPU_XC_CONFIG;
106         msr = rdmsr(msrnum);
107         msr.lo |=  XC_CONFIG_SUSP_ON_HLT;
108         wrmsr(msrnum, msr);*/
109
110         /*  ENable SUSP and allow TSC to run in Suspend */
111         /*  to keep speed detection happy*/
112         /*msrnum = CPU_BC_CONF_0;
113         msr = rdmsr(msrnum);
114         msr.lo |=  TSC_SUSP_SET | SUSP_EN_SET;
115         wrmsr(msrnum, msr);*/
116
117         /*  Setup throttling to proper mode if it is ever enabled.*/
118         msrnum = 0x04C00001E;
119         msr.hi =  0x000000000;
120         msr.lo =  0x00000603C;
121         wrmsr(msrnum, msr);             // GX3 OK +/-
122
123
124 /*  Only do this if we are building for 5535*/
125 /* */
126 /*  FooGlue Setup*/
127 /* */
128 #if 0
129         /*  Enable CIS mode B in FooGlue*/
130         msrnum = MSR_FG + 0x10;
131         msr = rdmsr(msrnum);
132         msr.lo &= ~3;
133         msr.lo |= 2;                    /*  ModeB*/
134         wrmsr(msrnum, msr);
135 #endif
136
137 /* */
138 /*  Disable DOT PLL. Graphics init will enable it if needed.*/
139 /* */
140
141 // GX3: Disable DOT PLL? No. Lets tick.
142
143 /*      msrnum = GLCP_DOTPLL;
144         msr = rdmsr(msrnum);
145         msr.lo |= DOTPPL_LOWER_PD_SET;
146         wrmsr(msrnum, msr); */
147
148 /* */
149 /*  Enable RSDC*/
150 /* */
151         msrnum = 0x1301 ;
152         msr = rdmsr(msrnum);
153         msr.lo |=  0x08;
154         wrmsr(msrnum, msr);             //GX3 OK
155
156
157 /* */
158 /*  BIST*/
159 /* */
160         /*if (getnvram( TOKEN_BIST_ENABLE) & == TVALUE_DISABLE) {*/
161         {
162 //              BIST();
163         }
164
165
166 /* */
167 /*  Enable BTB*/
168 /* */
169         /*  I hate to put this check here but it doesn't really work in cpubug.asm*/
170
171 //GX3: BTB is enabled by default
172
173 /*      msrnum = MSR_GLCP+0x17;
174         msr = rdmsr(msrnum);
175         if (msr.lo >= CPU_REV_2_1){
176                 msrnum = CPU_PF_BTB_CONF;
177                 msr = rdmsr(msrnum);
178                 msr.lo |= BTB_ENABLE_SET | RETURN_STACK_ENABLE_SET;
179                 wrmsr(msrnum, msr);
180         }
181
182         */
183
184 /* */
185 /*  FPU impercise exceptions bit*/
186 /* */
187         /*if (getnvram( TOKEN_FPU_IE_ENABLE) != TVALUE_DISABLE) {*/
188
189
190
191 // GX3: FPU impercise exceptions bit - what's that?
192 /*      {
193                 msrnum = CPU_FPU_MSR_MODE;
194                 msr = rdmsr(msrnum);
195                 msr.lo |= FPU_IE_SET;
196                 wrmsr(msrnum, msr);
197         }
198
199         */
200
201 #if 0
202         /* */
203         /*  Cache Overides*/
204         /* */
205         /* This code disables the data cache.  Don't execute this
206          * unless you're testing something.
207          */ 
208         /*  Allow NVRam to override DM Setup*/
209         /*if (getnvram( TOKEN_CACHE_DM_MODE) != 1) {*/
210         {
211
212                 msrnum = CPU_DM_CONFIG0;
213                 msr = rdmsr(msrnum);
214                 msr.lo |=  DM_CONFIG0_LOWER_DCDIS_SET;
215                 wrmsr(msrnum, msr);
216         }
217         /* This code disables the instruction cache.  Don't execute
218          * this unless you're testing something.
219         */ 
220         /*  Allow NVRam to override IM Setup*/
221         /*if (getnvram( TOKEN_CACHE_IM_MODE) ==1) {*/
222         {
223                 msrnum = CPU_IM_CONFIG;
224                 msr = rdmsr(msrnum);
225                 msr.lo |=  IM_CONFIG_LOWER_ICD_SET;
226                 wrmsr(msrnum, msr);
227         }
228 #endif
229 }
230
231
232
233
234 /* ***************************************************************************/
235 /* **/
236 /* *    MTestPinCheckBX*/
237 /* **/
238 /* *    Set MTEST pins to expected values from OPTIONS.INC/NVRAM*/
239 /* *  This version is called when there isn't a stack available*/
240 /* **/
241 /* ***************************************************************************/
242 static void
243 MTestPinCheckBX (void){
244         int msrnum;
245         msr_t msr;
246
247         /*if (getnvram( TOKEN_MTEST_ENABLE) ==TVALUE_DISABLE ) {*/
248                         /* return ; */
249         /* } */
250
251         /*  Turn on MTEST*/
252         msrnum = MC_CFCLK_DBUG;
253         msr = rdmsr(msrnum);
254         msr.hi |=  CFCLK_UPPER_MTST_B2B_DIS_SET | CFCLK_UPPER_MTEST_EN_SET;
255         wrmsr(msrnum, msr);
256
257         msrnum = GLCP_SYS_RSTPLL                        /*  Get SDR/DDR mode from GLCP*/;
258         msr = rdmsr(msrnum);
259         msr.lo >>=  RSTPPL_LOWER_SDRMODE_SHIFT;
260         if (msr.lo & 1) {
261                 msrnum = MC_CFCLK_DBUG;                 /*  Turn on SDR MTEST stuff*/
262                 msr = rdmsr(msrnum);
263                 msr.lo |=  CFCLK_LOWER_SDCLK_SET;
264                 msr.hi |=  CFCLK_UPPER_MTST_DQS_EN_SET;
265                 wrmsr(msrnum, msr);
266         }
267
268         /*  Lock the cache down here.*/
269         __asm__("wbinvd\n");
270
271 }