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 */
20 unsigned long desc_name;
21 unsigned short desc_type;
25 struct gliutable gliu0table[] = {
26 {.desc_name=GLIU0_P2D_BM_0, .desc_type= BM,.hi= MSR_MC + 0x0,.lo= 0x0FFF80}, /* 0-7FFFF to MC */
27 {.desc_name=GLIU0_P2D_BM_1, .desc_type= BM,.hi= MSR_MC + 0x0,.lo=(0x80 << 20) + 0x0FFFE0}, /* 80000-9ffff to Mc */
28 {.desc_name=GLIU0_P2D_SC_0, .desc_type= SC_SHADOW,.hi= MSR_MC + 0x0,.lo= 0x03}, /* C0000-Fffff split to MC and PCI (sub decode) A0000-Bffff handled by SoftVideo */
29 {.desc_name=GLIU0_P2D_R_0, .desc_type= R_SYSMEM,.hi= MSR_MC,.lo= 0x0}, /* Catch and fix dynamicly. */
30 {.desc_name=GLIU0_P2D_BMO_1, .desc_type= BMO_DMM,.hi= MSR_MC,.lo= 0x0}, /* Catch and fix dynamicly. */
31 {.desc_name=GLIU0_P2D_BMO_0, .desc_type= BMO_SMM,.hi= MSR_MC,.lo= 0x0}, /* Catch and fix dynamicly. */
32 {.desc_name=GLIU0_GLD_MSR_COH,.desc_type= OTHER,.hi= 0x0,.lo= GL0_CPU},
33 {.desc_name=GL_END, .desc_type= GL_END,.hi= 0x0,.lo= 0x0},
36 struct gliutable gliu1table[] = {
37 {.desc_name=GLIU1_P2D_BM_0,.desc_type= BM,.hi= MSR_GL0 + 0x0,.lo= 0x0FFF80}, /* 0-7FFFF to MC */
38 {.desc_name=GLIU1_P2D_BM_1,.desc_type= BM,.hi= MSR_GL0 + 0x0,.lo= (0x80 << 20) +0x0FFFE0}, /* 80000-9ffff to Mc */
39 {.desc_name=GLIU1_P2D_SC_0,.desc_type= SC_SHADOW,.hi= MSR_GL0 + 0x0,.lo= 0x03}, /* C0000-Fffff split to MC and PCI (sub decode) */
40 {.desc_name=GLIU1_P2D_R_0,.desc_type= R_SYSMEM,.hi= MSR_GL0,.lo= 0x0}, /* Catch and fix dynamicly. */
41 {.desc_name=GLIU1_P2D_BM_4,.desc_type= BM_DMM,.hi= MSR_GL0,.lo= 0x0}, /* Catch and fix dynamicly. */
42 {.desc_name=GLIU1_P2D_BM_3,.desc_type= BM_SMM,.hi= MSR_GL0,.lo= 0x0}, /* Catch and fix dynamicly. */
43 {.desc_name=GLIU1_GLD_MSR_COH,.desc_type= OTHER,.hi= 0x0,.lo= GL1_GLIU0},
44 {.desc_name=GLIU1_IOD_SC_0,.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};
56 struct msrinit ClockGatingDefault [] = {
57 {GLIU0_GLD_MSR_PM, {.hi=0x00,.lo=0x0005}},
58 /* MC must stay off in SDR mode. It is turned on in CPUBug??? lotus #77.142 */
59 {MC_GLD_MSR_PM, {.hi=0x00,.lo=0x0000}},
60 {GLIU1_GLD_MSR_PM, {.hi=0x00,.lo=0x0005}},
61 {VG_GLD_MSR_PM, {.hi=0x00,.lo=0x0000}}, /* lotus #77.163 */
62 {GP_GLD_MSR_PM, {.hi=0x00,.lo=0x0001}},
63 {DF_GLD_MSR_PM, {.hi=0x00,.lo=0x0155}},
64 {GLCP_GLD_MSR_PM, {.hi=0x00,.lo=0x0015}},
65 {GLPCI_GLD_MSR_PM, {.hi=0x00,.lo=0x0015}},
66 {FG_GLD_MSR_PM, {.hi=0x00,.lo=0x0000}}, /* Always on */
67 {0xffffffff, {0xffffffff, 0xffffffff}},
71 struct msrinit ClockGatingAllOn[] = {
72 {GLIU0_GLD_MSR_PM, {.hi=0x00,.lo=0x0FFFFFFFF}},
73 {MC_GLD_MSR_PM, {.hi=0x00,.lo=0x0FFFFFFFF}},
74 {GLIU1_GLD_MSR_PM, {.hi=0x00,.lo=0x0FFFFFFFF}},
75 {VG_GLD_MSR_PM, {.hi=0x00, .lo=0x00}},
76 {GP_GLD_MSR_PM, {.hi=0x00,.lo=0x000000001}},
77 {DF_GLD_MSR_PM, {.hi=0x00,.lo=0x0FFFFFFFF}},
78 {GLCP_GLD_MSR_PM, {.hi=0x00,.lo=0x0FFFFFFFF}},
79 {GLPCI_GLD_MSR_PM, {.hi=0x00,.lo=0x0FFFFFFFF}},
80 {FG_GLD_MSR_PM, {.hi=0x00,.lo=0x0000}},
81 {0xffffffff, {0xffffffff, 0xffffffff}},
85 struct msrinit ClockGatingPerformance[] = {
86 {VG_GLD_MSR_PM, {.hi=0x00,.lo=0x0000}}, /* lotus #77.163 */
87 {GP_GLD_MSR_PM, {.hi=0x00,.lo=0x0001}},
88 {DF_GLD_MSR_PM, {.hi=0x00,.lo=0x0155}},
89 {GLCP_GLD_MSR_PM, {.hi=0x00,.lo=0x0015}},
90 {0xffffffff, {0xffffffff, 0xffffffff}},
93 /* SET GeodeLink PRIORITY */
94 struct msrinit GeodeLinkPriorityTable [] = {
95 {CPU_GLD_MSR_CONFIG, {.hi=0x00,.lo=0x0220}}, /* CPU Priority. */
96 {DF_GLD_MSR_MASTER_CONF, {.hi=0x00,.lo=0x0000}}, /* DF Priority. */
97 {VG_GLD_MSR_CONFIG, {.hi=0x00,.lo=0x0720}}, /* VG Primary and Secondary Priority. */
98 {GP_GLD_MSR_CONFIG, {.hi=0x00,.lo=0x0010}}, /* Graphics Priority. */
99 {GLPCI_GLD_MSR_CONFIG, {.hi=0x00,.lo=0x0027}}, /* GLPCI Priority + PID */
100 {GLCP_GLD_MSR_CONF, {.hi=0x00,.lo=0x0001}}, /* GLCP Priority + PID */
101 {FG_GLD_MSR_CONFIG, {.hi=0x00,.lo=0x0622}}, /* FG PID */
102 {0x0FFFFFFFF, {0x0FFFFFFFF, 0x0FFFFFFFF}}, /* END */
105 /* do we have dmi or not? assume NO per AMD */
108 static void 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);
121 static void ShadowInit(struct gliutable *gl)
125 msr = rdmsr(gl->desc_name);
132 /* NOTE: transcribed from assembly code. There is the usual redundant assembly nonsense in here.
135 /* yes, this duplicates later code, but it seems that is how they want it done. */
136 static void SysmemInit(struct gliutable *gl)
139 int sizembytes, sizebytes;
141 /* Figure out how much RAM is in the machine and alocate all to the
142 * system. We will adjust for SMM and DMM now and Frame Buffer later.
144 sizembytes = sizeram();
145 printk(BIOS_DEBUG, "%s: enable for %dm bytes\n", __func__, sizembytes);
146 sizebytes = sizembytes << 20;
148 sizebytes -= SMM_SIZE*1024 +1;
151 sizebytes -= DMM_SIZE * 1024 + 1;
154 msr.hi = (gl->hi & 0xFFFFFF00) | (sizebytes >> 24);
155 /* set up sizebytes to fit into msr.lo */
156 sizebytes <<= 8; /* what? well, we want bits 23:12 in bits 31:20. */
157 sizebytes &= 0xfff00000;
160 wrmsr(gl->desc_name, msr); /* MSR - see table above */
161 msr = rdmsr(gl->desc_name);
162 printk(BIOS_DEBUG, "%s: AFTER write msr 0x%08lx, val 0x%08x:0x%08x\n", __func__,
163 gl->desc_name, msr.hi, msr.lo);
166 static void DMMGL0Init(struct gliutable *gl)
169 int sizebytes = sizeram()<<20;
175 printk(BIOS_DEBUG, "%s: %d bytes\n", __func__, sizebytes);
177 sizebytes -= DMM_SIZE*1024;
178 offset = sizebytes - DMM_OFFSET;
179 printk(BIOS_DEBUG, "%s: offset is 0x%08lx\n", __func__, offset);
181 msr.hi = (gl->hi) | (offset << 8);
182 /* I don't think this is needed */
183 msr.hi &= 0xffffff00;
184 msr.hi |= (DMM_OFFSET >> 24);
185 msr.lo = DMM_OFFSET << 8;
186 msr.lo |= ((~(DMM_SIZE*1024)+1)>>12)&0xfffff;
188 wrmsr(gl->desc_name, msr); /* MSR - See table above */
189 msr = rdmsr(gl->desc_name);
190 printk(BIOS_DEBUG, "%s: AFTER write msr 0x%08lx, val 0x%08x:0x%08x\n", __func__, gl->desc_name, msr.hi, msr.lo);
193 static void DMMGL1Init(struct gliutable *gl)
200 printk(BIOS_DEBUG, "%s:\n", __func__ );
203 /* I don't think this is needed */
204 msr.hi &= 0xffffff00;
205 msr.hi |= (DMM_OFFSET >> 24);
206 msr.lo = DMM_OFFSET << 8;
207 /* hmm. AMD source has SMM here ... SMM, not DMM? We think DMM */
208 printk(BIOS_ERR, "%s: warning, using DMM_SIZE even though AMD used SMM_SIZE\n", __func__);
209 msr.lo |= ((~(DMM_SIZE*1024)+1)>>12)&0xfffff;
211 wrmsr(gl->desc_name, msr); /* MSR - See table above */
212 msr = rdmsr(gl->desc_name);
213 printk(BIOS_DEBUG, "%s: AFTER write msr 0x%08lx, val 0x%08x:0x%08x\n", __func__, gl->desc_name, msr.hi, msr.lo);
216 static void SMMGL0Init(struct gliutable *gl)
219 int sizebytes = sizeram()<<20;
222 sizebytes -= SMM_SIZE*1024;
225 sizebytes -= DMM_SIZE * 1024;
227 printk(BIOS_DEBUG, "%s: %d bytes\n", __func__, sizebytes);
229 offset = sizebytes - SMM_OFFSET;
230 printk(BIOS_DEBUG, "%s: offset is 0x%08lx\n", __func__, offset);
233 msr.hi = offset << 8;
234 msr.hi |= SMM_OFFSET>>24;
236 msr.lo = SMM_OFFSET << 8;
237 msr.lo |= ((~(SMM_SIZE*1024)+1)>>12)&0xfffff;
239 wrmsr(gl->desc_name, msr); /* MSR - See table above */
240 msr = rdmsr(gl->desc_name);
241 printk(BIOS_DEBUG, "%s: AFTER write msr 0x%08lx, val 0x%08x:0x%08x\n", __func__, gl->desc_name, msr.hi, msr.lo);
244 static void SMMGL1Init(struct gliutable *gl)
247 printk(BIOS_DEBUG, "%s:\n", __func__ );
250 /* I don't think this is needed */
251 msr.hi &= 0xffffff00;
252 msr.hi |= (SMM_OFFSET >> 24);
253 msr.lo = SMM_OFFSET << 8;
254 msr.lo |= ((~(SMM_SIZE*1024)+1)>>12)&0xfffff;
256 wrmsr(gl->desc_name, msr); /* MSR - See table above */
257 msr = rdmsr(gl->desc_name);
258 printk(BIOS_DEBUG, "%s: AFTER write msr 0x%08lx, val 0x%08x:0x%08x\n", __func__, gl->desc_name, msr.hi, msr.lo);
261 static void GLIUInit(struct gliutable *gl)
263 while (gl->desc_type != GL_END){
264 switch(gl->desc_type){
266 /* For Unknown types: Write then read MSR */
268 case SC_SHADOW: /* Check for a Shadow entry */
272 case R_SYSMEM: /* check for a SYSMEM entry */
276 case BMO_DMM: /* check for a DMM entry */
280 case BM_DMM : /* check for a DMM entry */
284 case BMO_SMM : /* check for a SMM entry */
288 case BM_SMM : /* check for a SMM entry */
296 /* Set up GLPCI settings for reads/write into memory.
299 * R1: 1MB - Top of System Memory
301 * R3: Framebuffer? - not set up yet
304 static void GLPCIInit(void)
306 struct gliutable *gl = 0;
311 /* R0 - GLPCI settings for Conventional Memory space. */
312 msr.hi = (0x09F000 >> 12) << GLPCI_RC_UPPER_TOP_SHIFT; /* 640 */
314 msr.lo |= GLPCI_RC_LOWER_EN_SET+ GLPCI_RC_LOWER_PF_SET + GLPCI_RC_LOWER_WC_SET;
318 /* R1 - GLPCI settings for SysMem space. */
319 /* Get systop from GLIU0 SYSTOP Descriptor */
320 for(i = 0; gliu0table[i].desc_name != GL_END; i++) {
321 if (gliu0table[i].desc_type == R_SYSMEM) {
327 unsigned long pah, pal;
328 msrnum = gl->desc_name;
330 /* example R_SYSMEM value: 20:00:00:0f:fb:f0:01:00
331 * translates to a base of 0x00100000 and top of 0xffbf0000
332 * base of 1M and top of around 256M
334 /* we have to create a page-aligned (4KB page) address for base and top
335 * so we need a high page aligned addresss (pah) and low page aligned address (pal)
336 * pah is from msr.hi << 12 | msr.low >> 20. pal is msr.lo << 12
338 printk(BIOS_DEBUG, "GLPCI r1: system msr.lo 0x%08x msr.hi 0x%08x\n", msr.lo, msr.hi);
339 pah = ((msr.hi &0xff) << 12) | ((msr.lo >> 20) & 0xfff);
340 /* we have the page address. Now make it a page-aligned address */
346 msr.lo |= GLPCI_RC_LOWER_EN_SET | GLPCI_RC_LOWER_PF_SET | GLPCI_RC_LOWER_WC_SET;
347 printk(BIOS_DEBUG, "GLPCI r1: system msr.lo 0x%08x msr.hi 0x%08x\n", msr.lo, msr.hi);
352 /* R2 - GLPCI settings for SMM space. */
353 msr.hi = ((SMM_OFFSET+(SMM_SIZE*1024-1)) >> 12) << GLPCI_RC_UPPER_TOP_SHIFT;
354 msr.lo = (SMM_OFFSET >> 12) << GLPCI_RC_LOWER_BASE_SHIFT;
355 msr.lo |= GLPCI_RC_LOWER_EN_SET | GLPCI_RC_LOWER_PF_SET;
359 /* this is done elsewhere already, but it does no harm to do it more than once */
360 /* write serialize memory hole to PCI. Need to to unWS when something is shadowed regardless of cachablility. */
361 msr.lo = 0x021212121; /* cache disabled and write serialized */
362 msr.hi = 0x021212121; /* cache disabled and write serialized */
364 msrnum = CPU_RCONF_A0_BF;
367 msrnum = CPU_RCONF_C0_DF;
370 msrnum = CPU_RCONF_E0_FF;
373 /* Set Non-Cacheable Read Only for NorthBound Transactions to Memory. The Enable bit is handled in the Shadow setup. */
374 msrnum = GLPCI_A0_BF;
379 msrnum = GLPCI_C0_DF;
384 msrnum = GLPCI_E0_FF;
390 msrnum = CPU_DM_CONFIG0;
392 msr.hi &= ~ (7 << DM_CONFIG0_UPPER_WSREQ_SHIFT);
393 msr.hi |= 2 << DM_CONFIG0_UPPER_WSREQ_SHIFT ; /* reduce to 1 for safe mode. */
396 /* we are ignoring the 5530 case for now, and perhaps forever. */
401 msr.hi |= GLPCI_ARB_UPPER_PRE0_SET | GLPCI_ARB_UPPER_PRE1_SET;
402 msr.lo |= GLPCI_ARB_LOWER_IIE_SET;
408 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 .) */
409 msr.lo |= GLPCI_CTRL_LOWER_LDE_SET;
411 msr.lo &= ~ (0x03 << GLPCI_CTRL_LOWER_IRFC_SHIFT);
412 msr.lo |= 0x02 << GLPCI_CTRL_LOWER_IRFC_SHIFT;
414 msr.lo &= ~ (0x07 << GLPCI_CTRL_LOWER_IRFT_SHIFT);
415 msr.lo |= 0x06 << GLPCI_CTRL_LOWER_IRFT_SHIFT;
417 msr.hi &= ~ (0x0f << GLPCI_CTRL_UPPER_FTH_SHIFT);
418 msr.hi |= 0x0F << GLPCI_CTRL_UPPER_FTH_SHIFT;
420 msr.hi &= ~ (0x0f << GLPCI_CTRL_UPPER_RTH_SHIFT);
421 msr.hi |= 0x0F << GLPCI_CTRL_UPPER_RTH_SHIFT;
423 msr.hi &= ~ (0x0f << GLPCI_CTRL_UPPER_SBRTH_SHIFT);
424 msr.hi |= 0x0F << GLPCI_CTRL_UPPER_SBRTH_SHIFT;
426 msr.hi &= ~ (0x03 << GLPCI_CTRL_UPPER_WTO_SHIFT);
427 msr.hi |= 0x06 << GLPCI_CTRL_UPPER_WTO_SHIFT;
429 msr.hi &= ~ (0x03 << GLPCI_CTRL_UPPER_ILTO_SHIFT);
430 msr.hi |= 0x00 << GLPCI_CTRL_UPPER_ILTO_SHIFT;
433 /* Set GLPCI Latency Timer. */
436 msr.hi |= 0x1F << GLPCI_CTRL_UPPER_LAT_SHIFT; /* Change once 1.x is gone. */
440 msrnum = GLPCI_SPARE;
443 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;
447 /* Enable Clock Gating. */
448 static void ClockGatingInit (void)
451 struct msrinit *gating = ClockGatingDefault;
455 mov cx, TOKEN_CLK_GATE
456 NOSTACK bx, GetNVRAMValueBX
457 cmp al, TVALUE_CG_OFF
460 cmp al, TVALUE_CG_DEFAULT
463 lea si, ClockGatingDefault
467 lea si, ClockGatingAllOn
471 lea si, ClockGatingPerformance
474 for(i = 0; gating->msrnum != 0xffffffff; i++) {
475 msr = rdmsr(gating->msrnum);
476 printk(BIOS_DEBUG, "%s: MSR 0x%08lx is 0x%08x:0x%08x\n", __func__, gating->msrnum, msr.hi, msr.lo);
477 msr.hi |= gating->msr.hi;
478 msr.lo |= gating->msr.lo;
479 printk(BIOS_DEBUG, "%s: MSR 0x%08lx will be set to 0x%08x:0x%08x\n", __func__,
480 gating->msrnum, msr.hi, msr.lo);
481 wrmsr(gating->msrnum, msr); /* MSR - See the table above */
486 static void GeodeLinkPriority(void)
488 msr_t msr = { 0, 0 };
489 struct msrinit *prio = GeodeLinkPriorityTable;
492 for(i = 0; prio->msrnum != 0xffffffff; i++) {
493 msr = rdmsr(prio->msrnum);
494 printk(BIOS_DEBUG, "%s: MSR 0x%08lx is 0x%08x:0x%08x\n", __func__, prio->msrnum, msr.hi, msr.lo);
495 msr.hi |= prio->msr.hi;
497 msr.lo |= prio->msr.lo;
498 printk(BIOS_DEBUG, "%s: MSR 0x%08lx will be set to 0x%08x:0x%08x\n", __func__,
499 prio->msrnum, msr.hi, msr.lo);
500 wrmsr(prio->msrnum, msr); /* MSR - See the table above */
505 /* Get the GLIU0 shadow register settings.
507 * If the setShadow function is used then all shadow descriptors
510 static uint64_t getShadow(void)
513 msr = rdmsr(GLIU0_P2D_SC_0);
514 return ( ( (uint64_t) msr.hi ) << 32 ) | msr.lo;
517 /* Set the cache RConf registers for the memory hole.
519 * Keeps all cache shadow descriptors sync'ed.
520 * This is part of the PCI lockup solution.
522 * Entry: EDX:EAX is the shadow settings.
524 static void setShadowRCONF(uint32_t shadowHi, uint32_t shadowLo)
526 /* ok this is whacky bit translation time. */
529 msr_t msr = { 0, 0 };
530 shadowByte = (uint8_t) (shadowLo >> 16);
532 /* load up D000 settings in edx. */
533 for (bit = 8; (bit > 4); bit--) {
535 msr.hi |= 1; /* cache disable PCI/Shadow memory */
536 if (shadowByte && (1 << bit))
537 msr.hi |= 0x20; /* write serialize PCI memory */
540 /* load up C000 settings in eax. */
541 for ( ; bit; bit--) {
543 msr.lo |= 1; /* cache disable PCI/Shadow memory */
544 if (shadowByte && (1 << bit))
545 msr.lo |= 0x20; /* write serialize PCI memory */
548 wrmsr(CPU_RCONF_C0_DF, msr);
550 shadowByte = (uint8_t) (shadowLo >> 24);
552 /* load up F000 settings in edx. */
553 for (bit = 8; (bit > 4); bit--) {
555 msr.hi |= 1; /* cache disable PCI/Shadow memory */
556 if (shadowByte && (1 << bit))
557 msr.hi |= 0x20; /* write serialize PCI memory */
560 /* load up E000 settings in eax. */
561 for ( ; bit; bit--) {
563 msr.lo |= 1; /* cache disable PCI/Shadow memory */
564 if (shadowByte && (1 << bit))
565 msr.lo |= 0x20; /* write serialize PCI memory */
568 wrmsr(CPU_RCONF_E0_FF, msr);
571 /* Set the GLPCI registers for the memory hole.
572 * Keeps all cache shadow descriptors sync'ed.
573 * Entry: EDX:EAX is the shadow settings
575 static void setShadowGLPCI(uint32_t shadowHi, uint32_t shadowLo)
579 /* Set the Enable Register. */
580 msr = rdmsr(GLPCI_REN);
581 msr.lo &= 0xFFFF00FF;
582 msr.lo |= ( (shadowLo & 0xFFFF0000) >> 8);
583 wrmsr(GLPCI_REN, msr);
586 /* Set the GLIU SC register settings. Scans descriptor tables for SC_SHADOW.
587 * Keeps all shadow descriptors sync'ed.
588 * Entry: EDX:EAX is the shadow settings
590 static void setShadow(uint64_t shadowSettings)
594 struct gliutable* pTable;
595 uint32_t shadowLo, shadowHi;
597 shadowLo = (uint32_t) shadowSettings;
598 shadowHi = (uint32_t) (shadowSettings >> 32);
600 setShadowRCONF(shadowHi, shadowLo);
601 setShadowGLPCI(shadowHi, shadowLo);
603 for(i = 0; gliutables[i]; i++) {
604 for (pTable = gliutables[i]; pTable->desc_type != GL_END; pTable++) {
605 if (pTable->desc_type == SC_SHADOW) {
607 msr = rdmsr(pTable->desc_name);
608 msr.lo = (uint32_t) shadowSettings;
609 msr.hi &= 0xFFFF0000; /* maintain PDID in upper EDX */
610 msr.hi |= ((uint32_t) (shadowSettings >> 32)) & 0x0000FFFF;
611 wrmsr(pTable->desc_name, msr); /* MSR - See the table above */
618 /* Set up a stack for ease of further testing. */
619 static void shadowRom(void)
621 uint64_t shadowSettings = getShadow();
622 shadowSettings &= (uint64_t) 0xFFFF00000000FFFFULL; /* Disable read & writes */
623 shadowSettings |= (uint64_t) 0x0000FFFFFFFF0000ULL; /* Enable reads for C0000-FFFFF */
624 setShadow(shadowSettings);
627 /* Set up RCONF_DEFAULT and any other RCONF registers needed.
629 * DEVRC_RCONF_DEFAULT:
630 * ROMRC(63:56) = 04h ; write protect ROMBASE
631 * ROMBASE(36:55) = 0FFFC0h ; Top of PCI/bottom of rom chipselect area
632 * DEVRC(35:28) = 39h ; cache disabled in PCI memory + WS bit on + Write Combine + write burst.
633 * SYSTOP(27:8) = top of system memory
634 * SYSRC(7:0) = 00h ; writeback, can set to 08h to make writethrough
636 #define SYSMEM_RCONF_WRITETHROUGH 8
637 #define DEVRC_RCONF_DEFAULT 0x21
638 #define ROMBASE_RCONF_DEFAULT 0xFFFC0000
639 #define ROMRC_RCONF_DEFAULT 0x25
641 static void RCONFInit(void)
643 struct gliutable *gl = 0;
646 uint8_t SysMemCacheProp;
648 /* Locate SYSMEM entry in GLIU0table */
649 for(i = 0; gliu0table[i].desc_name != GL_END; i++) {
650 if (gliu0table[i].desc_type == R_SYSMEM) {
656 post_code(0xCE); /* POST_RCONFInitError */
661 /* found the descriptor... get its contents */
662 msr = rdmsr(gl->desc_name);
664 /* 20 bit address - The bottom 12 bits go into bits 20-31 in eax, the
665 * top 8 bits go into 0-7 of edx.
667 msr.lo = (msr.lo & 0xFFFFFF00) | (msr.hi & 0xFF);
668 msr.lo = ((msr.lo << 12) | (msr.lo >> 20)) & 0x000FFFFF;
669 msr.lo <<= RCONF_DEFAULT_LOWER_SYSTOP_SHIFT; /* 8 */
671 /* Set Default SYSMEM region properties */
672 msr.lo &= ~SYSMEM_RCONF_WRITETHROUGH; /* 8 (or ~8) */
674 /* Set PCI space cache properties */
675 msr.hi = (DEVRC_RCONF_DEFAULT >> 4); /* only need the bottom bits and lets clean the rest of edx */
676 msr.lo |= (DEVRC_RCONF_DEFAULT << 28);
678 /* Set the ROMBASE. This is usually FFFC0000h */
679 msr.hi |= (ROMBASE_RCONF_DEFAULT >> 12) << RCONF_DEFAULT_UPPER_ROMBASE_SHIFT;
681 /* Set ROMBASE cache properties. */
682 msr.hi |= ((ROMRC_RCONF_DEFAULT >> 8) | (ROMRC_RCONF_DEFAULT << 24));
684 /* now program RCONF_DEFAULT */
685 wrmsr(CPU_RCONF_DEFAULT, msr);
687 /* RCONF_BYPASS: Cache tablewalk properties and SMM/DMM header access properties. */
688 /* Set to match system memory cache properties. */
689 msr = rdmsr(CPU_RCONF_DEFAULT);
690 SysMemCacheProp = (uint8_t) (msr.lo & 0xFF);
691 msr = rdmsr(CPU_RCONF_BYPASS);
692 msr.lo = (msr.lo & 0xFFFF0000) | (SysMemCacheProp << 8) | SysMemCacheProp;
693 wrmsr(CPU_RCONF_BYPASS, msr);
696 uint32_t get_systop(void)
698 struct gliutable *gl = 0;
703 for (i = 0; gliu0table[i].desc_name != GL_END; i++) {
704 if (gliu0table[i].desc_type == R_SYSMEM) {
710 msr = rdmsr(gl->desc_name);
711 systop = ((msr.hi & 0xFF) << 24) | ((msr.lo & 0xFFF00000) >> 8);
712 systop += 0x1000; /* 4K */
715 ((sizeram() - CONFIG_VIDEO_MB) * 1024) - SMM_SIZE - 1024;
720 /* Core Logic initialization: Host bridge. */
721 void northbridge_init_early(void)
725 printk(BIOS_DEBUG, "Enter %s\n", __func__);
727 for(i = 0; gliutables[i]; i++)
728 GLIUInit(gliutables[i]);
736 /* The cacheInit function in GeodeROM tests cache and, among other things,
737 * makes sure all INVD instructions are treated as WBINVD. We do this
738 * because we've found some programs which require this behavior.
739 * That subset of cacheInit() is implemented here:
741 msr = rdmsr(CPU_DM_CONFIG0);
742 msr.lo |= DM_CONFIG0_LOWER_WBINVD_SET;
743 wrmsr(CPU_DM_CONFIG0, msr);
745 /* Now that the descriptor to memory is set up. */
746 /* The memory controller needs one read to synch its lines before it can be used. */
752 /* CPUBugsFix -- called elsewhere */
753 printk(BIOS_DEBUG, "Exit %s\n", __func__);