1 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_ids.h>
11 #include "northbridge.h"
12 #include <cpu/amd/gx2def.h>
13 #include <cpu/x86/msr.h>
14 #include <cpu/x86/cache.h>
16 /* put this here for now, we are not sure where it belongs */
19 unsigned long desc_name;
20 unsigned short desc_type;
24 struct gliutable gliu0table[] = {
25 {.desc_name=MSR_GLIU0_BASE1, .desc_type= BM,.hi= MSR_MC + 0x0,.lo= 0x0FFF80}, /* 0-7FFFF to MC*/
26 {.desc_name=MSR_GLIU0_BASE2, .desc_type= BM,.hi= MSR_MC + 0x0,.lo=(0x80 << 20) + 0x0FFFE0}, /* 80000-9ffff to Mc*/
27 {.desc_name=MSR_GLIU0_SHADOW, .desc_type= SC_SHADOW,.hi= MSR_MC + 0x0,.lo= 0x03}, /* C0000-Fffff split to MC and PCI (sub decode) A0000-Bffff handled by SoftVideo*/
28 {.desc_name=MSR_GLIU0_SYSMEM, .desc_type= R_SYSMEM,.hi= MSR_MC,.lo= 0x0}, /* Catch and fix dynamicly.*/
29 {.desc_name=MSR_GLIU0_DMM, .desc_type= BMO_DMM,.hi= MSR_MC,.lo= 0x0}, /* Catch and fix dynamicly.*/
30 {.desc_name=MSR_GLIU0_SMM, .desc_type= BMO_SMM,.hi= MSR_MC,.lo= 0x0}, /* Catch and fix dynamicly.*/
31 {.desc_name=GLIU0_GLD_MSR_COH,.desc_type= OTHER,.hi= 0x0,.lo= GL0_CPU},
32 {.desc_name=GL_END, .desc_type= GL_END,.hi= 0x0,.lo= 0x0},
36 struct gliutable gliu1table[] = {
37 {.desc_name=MSR_GLIU1_BASE1,.desc_type= BM,.hi= MSR_GL0 + 0x0,.lo= 0x0FFF80}, /* 0-7FFFF to MC*/
38 {.desc_name=MSR_GLIU1_BASE2,.desc_type= BM,.hi= MSR_GL0 + 0x0,.lo= (0x80 << 20) +0x0FFFE0}, /* 80000-9ffff to Mc*/
39 {.desc_name=MSR_GLIU1_SHADOW,.desc_type= SC_SHADOW,.hi= MSR_GL0 + 0x0,.lo= 0x03}, /* C0000-Fffff split to MC and PCI (sub decode)*/
40 {.desc_name=MSR_GLIU1_SYSMEM,.desc_type= R_SYSMEM,.hi= MSR_GL0,.lo= 0x0}, /* Cat0xc and fix dynamicly.*/
41 {.desc_name=MSR_GLIU1_DMM,.desc_type= BM_DMM,.hi= MSR_GL0,.lo= 0x0}, /* Cat0xc and fix dynamicly.*/
42 {.desc_name=MSR_GLIU1_SMM,.desc_type= BM_SMM,.hi= MSR_GL0,.lo= 0x0}, /* Cat0xc and fix dynamicly.*/
43 {.desc_name=GLIU1_GLD_MSR_COH,.desc_type= OTHER,.hi= 0x0,.lo= GL1_GLIU0},
44 {.desc_name=MSR_GLIU1_FPU_TRAP,.desc_type= SCIO,.hi= (GL1_GLCP << 29) + 0x0,.lo= 0x033000F0}, /* FooGlue FPU 0xF0*/
45 {.desc_name=GL_END,.desc_type= GL_END,.hi= 0x0,.lo= 0x0},
48 struct gliutable *gliutables[] = {gliu0table, gliu1table, 0};
55 struct msrinit ClockGatingDefault [] = {
56 {GLIU0_GLD_MSR_PM, {.hi=0x00,.lo=0x0005}},
57 /* MC must stay off in SDR mode. It is turned on in CPUBug??? lotus #77.142*/
58 {MC_GLD_MSR_PM, {.hi=0x00,.lo=0x0000}},
59 {GLIU1_GLD_MSR_PM, {.hi=0x00,.lo=0x0005}},
60 {VG_GLD_MSR_PM, {.hi=0x00,.lo=0x0000}}, /* lotus #77.163*/
61 {GP_GLD_MSR_PM, {.hi=0x00,.lo=0x0001}},
62 {DF_GLD_MSR_PM, {.hi=0x00,.lo=0x0155}},
63 {GLCP_GLD_MSR_PM, {.hi=0x00,.lo=0x0015}},
64 {GLPCI_GLD_MSR_PM, {.hi=0x00,.lo=0x0015}},
65 {FG_GLD_MSR_PM, {.hi=0x00,.lo=0x0000}}, /* Always on*/
66 {0xffffffff, {0xffffffff, 0xffffffff}},
69 struct msrinit ClockGatingAllOn[] = {
70 {GLIU0_GLD_MSR_PM, {.hi=0x00,.lo=0x0FFFFFFFF}},
71 {MC_GLD_MSR_PM, {.hi=0x00,.lo=0x0FFFFFFFF}},
72 {GLIU1_GLD_MSR_PM, {.hi=0x00,.lo=0x0FFFFFFFF}},
73 {VG_GLD_MSR_PM, {.hi=0x00, .lo=0x00}},
74 {GP_GLD_MSR_PM, {.hi=0x00,.lo=0x000000001}},
75 {DF_GLD_MSR_PM, {.hi=0x00,.lo=0x0FFFFFFFF}},
76 {GLCP_GLD_MSR_PM, {.hi=0x00,.lo=0x0FFFFFFFF}},
77 {GLPCI_GLD_MSR_PM, {.hi=0x00,.lo=0x0FFFFFFFF}},
78 {FG_GLD_MSR_PM, {.hi=0x00,.lo=0x0000}},
79 {0xffffffff, {0xffffffff, 0xffffffff}},
83 struct msrinit ClockGatingPerformance[] = {
84 {VG_GLD_MSR_PM, {.hi=0x00,.lo=0x0000}}, /* lotus #77.163*/
85 {GP_GLD_MSR_PM, {.hi=0x00,.lo=0x0001}},
86 {DF_GLD_MSR_PM, {.hi=0x00,.lo=0x0155}},
87 {GLCP_GLD_MSR_PM, {.hi=0x00,.lo=0x0015}},
88 {0xffffffff, {0xffffffff, 0xffffffff}},
91 /* SET GeodeLink PRIORITY*/
93 struct msrinit GeodeLinkPriorityTable [] = {
94 {CPU_GLD_MSR_CONFIG, {.hi=0x00,.lo=0x0220}}, /* CPU Priority.*/
95 {DF_GLD_MSR_MASTER_CONF, {.hi=0x00,.lo=0x0000}}, /* DF Priority.*/
96 {VG_GLD_MSR_CONFIG, {.hi=0x00,.lo=0x0720}}, /* VG Primary and Secondary Priority.*/
97 {GP_GLD_MSR_CONFIG, {.hi=0x00,.lo=0x0010}}, /* Graphics Priority.*/
98 {GLPCI_GLD_MSR_CONFIG, {.hi=0x00,.lo=0x0027}}, /* GLPCI Priority + PID*/
99 {GLCP_GLD_MSR_CONF, {.hi=0x00,.lo=0x0001}}, /* GLCP Priority + PID*/
100 {VIP_GLD_MSR_CONFIG, {.hi=0x00,.lo=0x0622}}, /* VIP PID*/
101 {AES_GLD_MSR_CONFIG, {.hi=0x00,.lo=0x0013}}, /* AES PID*/
102 {0x0FFFFFFFF, {0x0FFFFFFFF, 0x0FFFFFFFF}}, /* END*/
105 /* do we have dmi or not? assume NO per AMD */
109 writeglmsr(struct gliutable *gl){
114 wrmsr(gl->desc_name, msr); // MSR - see table above
115 printk(BIOS_DEBUG, "%s: write msr 0x%08lx, val 0x%08x:0x%08x\n", __func__, gl->desc_name, msr.hi, msr.lo);
116 /* they do this, so we do this */
117 msr = rdmsr(gl->desc_name);
118 printk(BIOS_DEBUG, "%s: AFTER write msr 0x%08lx, val 0x%08x:0x%08x\n", __func__, gl->desc_name, msr.hi, msr.lo);
122 ShadowInit(struct gliutable *gl)
126 msr = rdmsr(gl->desc_name);
133 /* NOTE: transcribed from assembly code. There is the usual redundant assembly nonsense in here.
136 /* yes, this duplicates later code, but it seems that is how they want it done.
139 SysmemInit(struct gliutable *gl)
142 int sizembytes, sizebytes;
145 * Figure out how much RAM is in the machine and alocate all to the
146 * system. We will adjust for SMM and DMM now and Frame Buffer later.
148 sizembytes = sizeram();
149 printk(BIOS_DEBUG, "%s: enable for %dm bytes\n", __func__, sizembytes);
150 sizebytes = sizembytes << 20;
152 sizebytes -= SMM_SIZE*1024 +1;
155 sizebytes -= DMM_SIZE * 1024 + 1;
158 msr.hi = (gl->hi & 0xFFFFFF00) | (sizebytes >> 24);
159 /* set up sizebytes to fit into msr.lo */
160 sizebytes <<= 8; /* what? well, we want bits 23:12 in bits 31:20. */
161 sizebytes &= 0xfff00000;
164 wrmsr(gl->desc_name, msr); // MSR - see table above
165 msr = rdmsr(gl->desc_name);
166 printk(BIOS_DEBUG, "%s: AFTER write msr 0x%08lx, val 0x%08x:0x%08x\n", __func__,
167 gl->desc_name, msr.hi, msr.lo);
171 DMMGL0Init(struct gliutable *gl) {
173 int sizebytes = sizeram()<<20;
179 printk(BIOS_DEBUG, "%s: %d bytes\n", __func__, sizebytes);
181 sizebytes -= DMM_SIZE*1024;
182 offset = sizebytes - DMM_OFFSET;
183 printk(BIOS_DEBUG, "%s: offset is 0x%08lx\n", __func__, offset);
185 msr.hi = (gl->hi) | (offset << 8);
186 /* I don't think this is needed */
187 msr.hi &= 0xffffff00;
188 msr.hi |= (DMM_OFFSET >> 24);
189 msr.lo = DMM_OFFSET << 8;
190 msr.lo |= ((~(DMM_SIZE*1024)+1)>>12)&0xfffff;
192 wrmsr(gl->desc_name, msr); // MSR - See table above
193 msr = rdmsr(gl->desc_name);
194 printk(BIOS_DEBUG, "%s: AFTER write msr 0x%08lx, val 0x%08x:0x%08x\n", __func__, gl->desc_name, msr.hi, msr.lo);
198 DMMGL1Init(struct gliutable *gl) {
204 printk(BIOS_DEBUG, "%s:\n", __func__ );
207 /* I don't think this is needed */
208 msr.hi &= 0xffffff00;
209 msr.hi |= (DMM_OFFSET >> 24);
210 msr.lo = DMM_OFFSET << 8;
211 /* hmm. AMD source has SMM here ... SMM, not DMM? We think DMM */
212 printk(BIOS_ERR, "%s: warning, using DMM_SIZE even though AMD used SMM_SIZE\n", __func__);
213 msr.lo |= ((~(DMM_SIZE*1024)+1)>>12)&0xfffff;
215 wrmsr(gl->desc_name, msr); // MSR - See table above
216 msr = rdmsr(gl->desc_name);
217 printk(BIOS_DEBUG, "%s: AFTER write msr 0x%08lx, val 0x%08x:0x%08x\n", __func__, gl->desc_name, msr.hi, msr.lo);
220 SMMGL0Init(struct gliutable *gl) {
222 int sizebytes = sizeram()<<20;
225 sizebytes -= SMM_SIZE*1024;
228 sizebytes -= DMM_SIZE * 1024;
230 printk(BIOS_DEBUG, "%s: %d bytes\n", __func__, sizebytes);
232 offset = sizebytes - SMM_OFFSET;
233 printk(BIOS_DEBUG, "%s: offset is 0x%08lx\n", __func__, offset);
236 msr.hi = offset << 8;
237 msr.hi |= SMM_OFFSET>>24;
239 msr.lo = SMM_OFFSET << 8;
240 msr.lo |= ((~(SMM_SIZE*1024)+1)>>12)&0xfffff;
242 wrmsr(gl->desc_name, msr); // MSR - See table above
243 msr = rdmsr(gl->desc_name);
244 printk(BIOS_DEBUG, "%s: AFTER write msr 0x%08lx, val 0x%08x:0x%08x\n", __func__, gl->desc_name, msr.hi, msr.lo);
247 SMMGL1Init(struct gliutable *gl) {
249 printk(BIOS_DEBUG, "%s:\n", __func__ );
252 /* I don't think this is needed */
253 msr.hi &= 0xffffff00;
254 msr.hi |= (SMM_OFFSET >> 24);
255 msr.lo = SMM_OFFSET << 8;
256 msr.lo |= ((~(SMM_SIZE*1024)+1)>>12)&0xfffff;
258 wrmsr(gl->desc_name, msr); // MSR - See table above
259 msr = rdmsr(gl->desc_name);
260 printk(BIOS_DEBUG, "%s: AFTER write msr 0x%08lx, val 0x%08x:0x%08x\n", __func__, gl->desc_name, msr.hi, msr.lo);
264 GLIUInit(struct gliutable *gl){
266 while (gl->desc_type != GL_END){
267 switch(gl->desc_type){
269 /* For Unknown types: Write then read MSR */
271 case SC_SHADOW: /* Check for a Shadow entry*/
275 case R_SYSMEM: /* check for a SYSMEM entry*/
279 case BMO_DMM: /* check for a DMM entry*/
283 case BM_DMM : /* check for a DMM entry*/
287 case BMO_SMM : /* check for a SMM entry*/
291 case BM_SMM : /* check for a SMM entry*/
299 /* ***************************************************************************/
303 /* * Set up GLPCI settings for reads/write into memory*/
305 /* * R1: 1MB - Top of System Memory*/
306 /* * R2: SMM Memory*/
307 /* * R3: Framebuffer? - not set up yet*/
314 /* ***************************************************************************/
315 static void GLPCIInit(void){
316 struct gliutable *gl = 0;
322 /* R0 - GLPCI settings for Conventional Memory space.*/
324 msr.hi = (0x09F000 >> 12) << GLPCI_RC_UPPER_TOP_SHIFT /* 640*/;
326 msr.lo |= GLPCI_RC_LOWER_EN_SET+ GLPCI_RC_LOWER_PF_SET + GLPCI_RC_LOWER_WC_SET;
331 /* R1 - GLPCI settings for SysMem space.*/
333 /* Get systop from GLIU0 SYSTOP Descriptor*/
334 for(i = 0; gliu0table[i].desc_name != GL_END; i++) {
335 if (gliu0table[i].desc_type == R_SYSMEM) {
341 unsigned long pah, pal;
342 msrnum = gl->desc_name;
344 /* example R_SYSMEM value: 20:00:00:0f:fb:f0:01:00
345 * translates to a base of 0x00100000 and top of 0xffbf0000
346 * base of 1M and top of around 256M
348 /* we have to create a page-aligned (4KB page) address for base and top */
349 /* So we need a high page aligned addresss (pah) and low page aligned address (pal)
350 * pah is from msr.hi << 12 | msr.low >> 20. pal is msr.lo << 12
352 printk(BIOS_DEBUG, "GLPCI r1: system msr.lo 0x%08x msr.hi 0x%08x\n", msr.lo, msr.hi);
353 pah = ((msr.hi &0xff) << 12) | ((msr.lo >> 20) & 0xfff);
354 /* we have the page address. Now make it a page-aligned address */
360 msr.lo |= GLPCI_RC_LOWER_EN_SET | GLPCI_RC_LOWER_PF_SET | GLPCI_RC_LOWER_WC_SET;
361 printk(BIOS_DEBUG, "GLPCI r1: system msr.lo 0x%08x msr.hi 0x%08x\n", msr.lo, msr.hi);
367 /* R2 - GLPCI settings for SMM space.*/
369 msr.hi = ((SMM_OFFSET+(SMM_SIZE*1024-1)) >> 12) << GLPCI_RC_UPPER_TOP_SHIFT;
370 msr.lo = (SMM_OFFSET >> 12) << GLPCI_RC_LOWER_BASE_SHIFT;
371 msr.lo |= GLPCI_RC_LOWER_EN_SET | GLPCI_RC_LOWER_PF_SET;
375 /* this is done elsewhere already, but it does no harm to do it more than once */
376 /* write serialize memory hole to PCI. Need to to unWS when something is shadowed regardless of cachablility.*/
377 msr.lo = 0x021212121 /* cache disabled and write serialized*/;
378 msr.hi = 0x021212121 /* cache disabled and write serialized*/;
380 msrnum = CPU_RCONF_A0_BF;
383 msrnum = CPU_RCONF_C0_DF;
386 msrnum = CPU_RCONF_E0_FF;
389 /* Set Non-Cacheable Read Only for NorthBound Transactions to Memory. The Enable bit is handled in the Shadow setup.*/
390 msrnum = GLPCI_A0_BF;
395 msrnum = GLPCI_C0_DF;
400 msrnum = GLPCI_E0_FF;
406 msrnum = CPU_DM_CONFIG0;
408 msr.hi &= ~ (7 << DM_CONFIG0_UPPER_WSREQ_SHIFT);
409 msr.hi |= 2 << DM_CONFIG0_UPPER_WSREQ_SHIFT ; /* reduce to 1 for safe mode.*/
412 /* we are ignoring the 5530 case for now, and perhaps forever. */
419 msr.hi |= GLPCI_ARB_UPPER_PRE0_SET | GLPCI_ARB_UPPER_PRE1_SET;
420 msr.lo |= GLPCI_ARB_LOWER_IIE_SET;
427 msr.lo |= GLPCI_CTRL_LOWER_ME_SET | GLPCI_CTRL_LOWER_OWC_SET | GLPCI_CTRL_LOWER_PCD_SET; /* (Out will be disabled in CPUBUG649 for < 2.0 parts .)*/
428 msr.lo |= GLPCI_CTRL_LOWER_LDE_SET;
430 msr.lo &= ~ (0x03 << GLPCI_CTRL_LOWER_IRFC_SHIFT);
431 msr.lo |= 0x02 << GLPCI_CTRL_LOWER_IRFC_SHIFT;
433 msr.lo &= ~ (0x07 << GLPCI_CTRL_LOWER_IRFT_SHIFT);
434 msr.lo |= 0x06 << GLPCI_CTRL_LOWER_IRFT_SHIFT;
436 msr.hi &= ~ (0x0f << GLPCI_CTRL_UPPER_FTH_SHIFT);
437 msr.hi |= 0x0F << GLPCI_CTRL_UPPER_FTH_SHIFT;
439 msr.hi &= ~ (0x0f << GLPCI_CTRL_UPPER_RTH_SHIFT);
440 msr.hi |= 0x0F << GLPCI_CTRL_UPPER_RTH_SHIFT;
442 msr.hi &= ~ (0x0f << GLPCI_CTRL_UPPER_SBRTH_SHIFT);
443 msr.hi |= 0x0F << GLPCI_CTRL_UPPER_SBRTH_SHIFT;
445 msr.hi &= ~ (0x03 << GLPCI_CTRL_UPPER_WTO_SHIFT);
446 msr.hi |= 0x06 << GLPCI_CTRL_UPPER_WTO_SHIFT;
448 msr.hi &= ~ (0x03 << GLPCI_CTRL_UPPER_ILTO_SHIFT);
449 msr.hi |= 0x00 << GLPCI_CTRL_UPPER_ILTO_SHIFT;
453 /* Set GLPCI Latency Timer.*/
456 msr.hi |= 0x1F << GLPCI_CTRL_UPPER_LAT_SHIFT; /* Change once 1.x is gone.*/
460 msrnum = GLPCI_SPARE;
463 msr.lo |= GLPCI_SPARE_LOWER_AILTO_SET | GLPCI_SPARE_LOWER_PPD_SET | GLPCI_SPARE_LOWER_PPC_SET | GLPCI_SPARE_LOWER_MPC_SET | GLPCI_SPARE_LOWER_NSE_SET | GLPCI_SPARE_LOWER_SUPO_SET;
470 /* ***************************************************************************/
472 /* * ClockGatingInit*/
474 /* * Enable Clock Gating.*/
480 /* ***************************************************************************/
482 ClockGatingInit (void){
484 struct msrinit *gating = ClockGatingDefault;
488 mov cx, TOKEN_CLK_GATE
489 NOSTACK bx, GetNVRAMValueBX
490 cmp al, TVALUE_CG_OFF
493 cmp al, TVALUE_CG_DEFAULT
496 lea si, ClockGatingDefault
500 lea si, ClockGatingAllOn
504 lea si, ClockGatingPerformance
507 for(i = 0; gating->msrnum != 0xffffffff; i++) {
508 msr = rdmsr(gating->msrnum);
509 printk(BIOS_DEBUG, "%s: MSR 0x%08lx is 0x%08x:0x%08x\n", __func__, gating->msrnum, msr.hi, msr.lo);
510 msr.hi |= gating->msr.hi;
511 msr.lo |= gating->msr.lo;
512 printk(BIOS_DEBUG, "%s: MSR 0x%08lx will be set to 0x%08x:0x%08x\n", __func__,
513 gating->msrnum, msr.hi, msr.lo);
514 wrmsr(gating->msrnum, msr); // MSR - See the table above
521 GeodeLinkPriority(void){
523 struct msrinit *prio = GeodeLinkPriorityTable;
526 for(i = 0; prio->msrnum != 0xffffffff; i++) {
527 msr = rdmsr(prio->msrnum);
528 printk(BIOS_DEBUG, "%s: MSR 0x%08lx is 0x%08x:0x%08x\n", __func__, prio->msrnum, msr.hi, msr.lo);
529 msr.hi |= prio->msr.hi;
531 msr.lo |= prio->msr.lo;
532 printk(BIOS_DEBUG, "%s: MSR 0x%08lx will be set to 0x%08x:0x%08x\n", __func__,
533 prio->msrnum, msr.hi, msr.lo);
534 wrmsr(prio->msrnum, msr); // MSR - See the table above
542 * Get the GLIU0 shadow register settings
543 * If the setShadow function is used then all shadow descriptors
546 static uint64_t getShadow(void)
549 msr = rdmsr(MSR_GLIU0_SHADOW);
550 return ( ( (uint64_t) msr.hi ) << 32 ) | msr.lo;
555 * Set the cache RConf registers for the memory hole.
556 * Keeps all cache shadow descriptors sync'ed.
557 * This is part of the PCI lockup solution
558 * Entry: EDX:EAX is the shadow settings
560 static void setShadowRCONF(uint32_t shadowHi, uint32_t shadowLo)
562 // ok this is whacky bit translation time.
566 shadowByte = (uint8_t) (shadowLo >> 16);
568 // load up D000 settings in edx.
569 for (bit = 8; (bit > 4); bit--) {
571 msr.hi |= 1; // cache disable PCI/Shadow memory
572 if (shadowByte && (1 << bit))
573 msr.hi |= 0x20; // write serialize PCI memory
576 // load up C000 settings in eax.
577 for ( ; bit; bit--) {
579 msr.lo |= 1; // cache disable PCI/Shadow memory
580 if (shadowByte && (1 << bit))
581 msr.lo |= 0x20; // write serialize PCI memory
584 wrmsr(CPU_RCONF_C0_DF, msr);
586 shadowByte = (uint8_t) (shadowLo >> 24);
588 // load up F000 settings in edx.
589 for (bit = 8; (bit > 4); bit--) {
591 msr.hi |= 1; // cache disable PCI/Shadow memory
592 if (shadowByte && (1 << bit))
593 msr.hi |= 0x20; // write serialize PCI memory
596 // load up E000 settings in eax.
597 for ( ; bit; bit--) {
599 msr.lo |= 1; // cache disable PCI/Shadow memory
600 if (shadowByte && (1 << bit))
601 msr.lo |= 0x20; // write serialize PCI memory
604 wrmsr(CPU_RCONF_E0_FF, msr);
609 * Set the GLPCI registers for the memory hole.
610 * Keeps all cache shadow descriptors sync'ed.
611 * Entry: EDX:EAX is the shadow settings
613 static void setShadowGLPCI(uint32_t shadowHi, uint32_t shadowLo)
617 // Set the Enable Register.
619 msr = rdmsr(GLPCI_REN);
620 msr.lo &= 0xFFFF00FF;
621 msr.lo |= ( (shadowLo & 0xFFFF0000) >> 8);
622 wrmsr(GLPCI_REN, msr);
627 * Set the GLIU SC register settings. Scans descriptor tables for SC_SHADOW.
628 * Keeps all shadow descriptors sync'ed.
629 * Entry: EDX:EAX is the shadow settings
631 static void setShadow(uint64_t shadowSettings)
635 struct gliutable* pTable;
636 uint32_t shadowLo, shadowHi;
638 shadowLo = (uint32_t) shadowSettings;
639 shadowHi = (uint32_t) (shadowSettings >> 32);
641 setShadowRCONF(shadowHi, shadowLo);
642 setShadowGLPCI(shadowHi, shadowLo);
644 for(i = 0; gliutables[i]; i++) {
645 for (pTable = gliutables[i]; pTable->desc_type != GL_END; pTable++) {
646 if (pTable->desc_type == SC_SHADOW) {
648 msr = rdmsr(pTable->desc_name);
649 msr.lo = (uint32_t) shadowSettings;
650 msr.hi &= 0xFFFF0000; // maintain PDID in upper EDX
651 msr.hi |= ((uint32_t) (shadowSettings >> 32)) & 0x0000FFFF;
652 wrmsr(pTable->desc_name, msr); // MSR - See the table above
659 /**************************************************************************
663 * Set up a stack for ease of further testing
669 **************************************************************************/
673 uint64_t shadowSettings = getShadow();
674 shadowSettings &= (uint64_t) 0xFFFF00000000FFFFULL; // Disable read & writes
675 shadowSettings |= (uint64_t) 0x00000000F0000000ULL; // Enable reads for F0000-FFFFF
676 setShadow(shadowSettings);
681 /***************************************************************************
684 * Set up RCONF_DEFAULT and any other RCONF registers needed
686 * DEVRC_RCONF_DEFAULT:
687 * ROMRC(63:56) = 04h ; write protect ROMBASE
688 * ROMBASE(36:55) = 0FFFC0h ; Top of PCI/bottom of rom chipselect area
689 * DEVRC(35:28) = 39h ; cache disabled in PCI memory + WS bit on + Write Combine + write burst.
690 * SYSTOP(27:8) = top of system memory
691 * SYSRC(7:0) = 00h ; writeback, can set to 08h to make writethrough
693 ***************************************************************************/
694 #define SYSMEM_RCONF_WRITETHROUGH 8
695 #define DEVRC_RCONF_DEFAULT 0x21
696 #define ROMBASE_RCONF_DEFAULT 0xFFFC0000
697 #define ROMRC_RCONF_DEFAULT 0x25
702 struct gliutable *gl = 0;
705 uint8_t SysMemCacheProp;
707 /* Locate SYSMEM entry in GLIU0table */
708 for(i = 0; gliu0table[i].desc_name != GL_END; i++) {
709 if (gliu0table[i].desc_type == R_SYSMEM) {
715 post_code(0xCE); /* POST_RCONFInitError */
720 /* found the descriptor... get its contents */
721 msr = rdmsr(gl->desc_name);
723 /* 20 bit address - The bottom 12 bits go into bits 20-31 in eax, the
724 * top 8 bits go into 0-7 of edx.
726 msr.lo = (msr.lo & 0xFFFFFF00) | (msr.hi & 0xFF);
727 msr.lo = ((msr.lo << 12) | (msr.lo >> 20)) & 0x000FFFFF;
728 msr.lo <<= RCONF_DEFAULT_LOWER_SYSTOP_SHIFT; // 8
730 // Set Default SYSMEM region properties
731 msr.lo &= ~SYSMEM_RCONF_WRITETHROUGH; // 8 (or ~8)
733 // Set PCI space cache properties
734 msr.hi = (DEVRC_RCONF_DEFAULT >> 4); // only need the bottom bits and lets clean the rest of edx
735 msr.lo |= (DEVRC_RCONF_DEFAULT << 28);
737 // Set the ROMBASE. This is usually FFFC0000h
738 msr.hi |= (ROMBASE_RCONF_DEFAULT >> 12) << RCONF_DEFAULT_UPPER_ROMBASE_SHIFT;
740 // Set ROMBASE cache properties.
741 msr.hi |= ((ROMRC_RCONF_DEFAULT >> 8) | (ROMRC_RCONF_DEFAULT << 24));
743 // now program RCONF_DEFAULT
744 wrmsr(CPU_RCONF_DEFAULT, msr);
746 // RCONF_BYPASS: Cache tablewalk properties and SMM/DMM header access properties.
747 // Set to match system memory cache properties.
748 msr = rdmsr(CPU_RCONF_DEFAULT);
749 SysMemCacheProp = (uint8_t) (msr.lo & 0xFF);
750 msr = rdmsr(CPU_RCONF_BYPASS);
751 msr.lo = (msr.lo & 0xFFFF0000) | (SysMemCacheProp << 8) | SysMemCacheProp;
752 wrmsr(CPU_RCONF_BYPASS, msr);
756 /* ***************************************************************************/
758 /* * northBridgeInit*/
760 /* * Core Logic initialization: Host bridge*/
766 /* ***************************************************************************/
769 northbridgeinit(void)
773 printk(BIOS_DEBUG, "Enter %s\n", __func__);
775 for(i = 0; gliutables[i]; i++)
776 GLIUInit(gliutables[i]);
782 // GeodeROM ensures that the BIOS waits the required 1 second before
783 // allowing anything to access PCI
788 // The cacheInit function in GeodeROM tests cache and, among other things,
789 // makes sure all INVD instructions are treated as WBINVD. We do this
790 // because we've found some programs which require this behavior.
791 // That subset of cacheInit() is implemented here:
792 msr = rdmsr(CPU_DM_CONFIG0);
793 msr.lo |= DM_CONFIG0_LOWER_WBINVD_SET;
794 wrmsr(CPU_DM_CONFIG0, msr);
796 /* Now that the descriptor to memory is set up.*/
797 /* The memory controller needs one read to synch its lines before it can be used.*/
803 /* CPUBugsFix -- called elsewhere */
804 printk(BIOS_DEBUG, "Exit %s\n", __func__);