Update K8 FID/VID setup to match coreboot v2. Add support for 100MHz FIDs

(revG).

Signed-off-by: Marc Jones <marc.jones@amd.com>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>



git-svn-id: svn://coreboot.org/repository/coreboot-v3@979 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
Marc Jones 2008-11-04 17:00:07 +00:00
parent 4213668ab5
commit f77a0a29b1

View file

@ -80,59 +80,68 @@ static unsigned set_fidvid_without_init(unsigned fidvid)
static unsigned set_fidvid(unsigned apicid, unsigned fidvid, int showmessage) static unsigned set_fidvid(unsigned apicid, unsigned fidvid, int showmessage)
{ {
/* for (cur, new) there is one <1600MHz x8 to find out next_fid */
static const u8 next_fid_a[] = { /* CurrentFID--> 4x(00h) 5x(02h) 6x(04h) 7x(06h) ...
/* x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 */ * --------------------------------------
/* x4 */ 0, 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, * TargetFID | Next_FID, Next_FID, Next_FID, Next_FID ...
/* x5 */ 9, 0, 11, 11, 9, 9, 10, 11, 11, 11, 11, 11, * | | Next_FID, Next_FID, Next_FID, Next_FID ...
/* x6 */ 11, 11, 0, 13, 11, 11, 11, 11, 12, 13, 13, 13, * \|/ | Next_FID, Next_FID, Next_FID, Next_FID ...
/* x7 */ 13, 13, 13, 0, 13, 13, 13, 13, 13, 13, 14, 15, */
/* x8 */ 4, 9, 9, 9, 0, 9, 9, 9, 9, 9, 9, 9, static const u8 next_fid_200[] = {
/* x9 */ 4, 5, 10, 10, 8, 0, 0, 0, 0, 0, 0, 0, /* x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 */
/*x10 */ 9, 5, 11, 11, 9, 0, 0, 0, 0, 0, 0, 0, /* x4 */ 0, -1, -1, -1, 0, 0, 9, 10, 11, 12, 13, 14, 15, /* 800 */
/*x11 */ 10, 5, 6, 12, 10, 0, 0, 0, 0, 0, 0, 0, /* x5 */ -1, 0, -1, -1, -1, 5, 5, 5, 11, 12, 13, 14, 15, /* 1000 */
/*x12 */ 11, 11, 6, 13, 11, 0, 0, 0, 0, 0, 0, 0, /* x6 */ -1, -1, 0, -1, -1, -1, -1, 6, 6, 6, 13, 14, 15, /* 1200 */
/*x13 */ 12, 12, 6, 7, 12, 0, 0, 0, 0, 0, 0, 0, /* x7 */ -1, -1, -1, 0, -1, -1, -1, -1, -1, 7, 7, 7, 15, /* 1400 */
/*x14 */ 13, 13, 13, 7, 13, 0, 0, 0, 0, 0, 0, 0, /* lower table to upper table boarder (table 70 and 71 in BKDG) */
/*x15 */ 14, 14, 14, 7, 14, 0, 0, 0, 0, 0, 0, 0, /* x8 */ 8, -1, -1, -1, 0, 8, 9, 10, 11, 12, 13, 14, 15, /* 1600 */
/* 0:x4, 2:x5....BASE=4, MIN=4, MAX=25, INC=2 result = (xX-BASE)*INC */ /* x9 */ 9, 9, -1, -1, 9, 0, 9, 10, 11, 12, 13, 14, 15, /* 1800 */
/*x10 */ 9, 10, -1, -1, 9, 10, 0, 10, 11, 12, 13, 14, 15, /* 2000 */
/*x11 */ 9, 11, 11, -1, 9, 10, 11, 0, 11, 12, 13, 14, 15, /* 2200 */
/*x12 */ 9, 11, 12, -1, 9, 10, 11, 12, 0, 12, 13, 14, 15, /* 2400 */
/*x13 */ 9, 11, 13, 13, 9, 10, 11, 12, 13, 0, 13, 14, 15, /* 2600 */
/*x14 */ 9, 11, 13, 14, 9, 10, 11, 12, 13, 14, 0, 14, 15, /* 2800 */
/*x15 */ 9, 11, 13, 15, 9, 10, 11, 12, 13, 14, 15, 0, 15, /* 3000 */
/*x15 */ 9, 11, 13, 15, 9, 10, 11, 12, 13, 14, 15, 16, 0, /* 3200 */
}; };
struct msr msr; struct msr msr;
u32 vid; u32 vid_new;
u32 fid; u32 fid_new;
u32 vid_max; u32 vid_max;
u32 fid_max; u32 fid_max;
u32 vid_cur; u32 vid_cur;
u32 fid_cur; u32 fid_cur;
unsigned int apicidx; unsigned int apicidx;
int steps; int step_limit;
int loop; int loop;
apicidx = lapicid(); apicidx = lapicid();
if (apicid != apicidx) { if (apicid != apicidx) {
printk(BIOS_ERR, printk(BIOS_ERR,
"wrong apicid, we want change %x, but it is %x\n", apicid, apicidx); "wrong apicid, we want change %x, but it is %x\n",
apicid, apicidx);
return fidvid; return fidvid;
} }
fid = (fidvid >> 8) & 0x3f; fid_new = (fidvid >> 8) & 0x3f;
vid = (fidvid >> 16) & 0x3f; vid_new = (fidvid >> 16) & 0x3f;
msr = rdmsr(FIDVID_STATUS); msr = rdmsr(FIDVID_STATUS);
vid_cur = msr.hi & 0x3f; vid_cur = msr.hi & 0x3f;
fid_cur = msr.lo & 0x3f; fid_cur = msr.lo & 0x3f;
if ((vid_cur==vid) && (fid_cur==fid)) if ((vid_cur == vid_new) && (fid_cur == fid_new))
return fidvid; return fidvid;
vid_max = (msr.hi>>(48-32)) & 0x3f; vid_max = (msr.hi >> (48-32)) & 0x3f;
fid_max = ((msr.lo>>16) & 0x3f); /* max fid */ fid_max = ((msr.lo >> 16) & 0x3f); /* max fid */
#if FX_SUPPORT #if FX_SUPPORT
if (fid_max>=((25-4)*2)) { /* FX max fid is 5G */ if (fid_max >= ((25 - 4) * 2)) { /* FX max fid is 5G */
fid_max = ((msr.lo >> 8) & 0x3f) + 5 * 2; /* max FID is min fid + 1G */ fid_max = ((msr.lo >> 8) & 0x3f) + 5 * 2; /* max FID is min fid + 1G */
if (fid_max >= ((25-4) * 2)) { if (fid_max >= ((25-4) * 2)) {
fid_max = (10-4) * 2; /* hard set to 2G */ fid_max = (10-4) * 2; /* hard set to 2G */
@ -141,10 +150,20 @@ static unsigned set_fidvid(unsigned apicid, unsigned fidvid, int showmessage)
#endif #endif
/* set vid to max */ /* set vid to max */
/* TODO - make this more correct. Not a big deal for setting max...
* BKDG figure 11
* if TargetFID > InitialFID
* TargetVID = FinalVID - RVO
* else
* if CurrentVID > FinalVID
* TargetVID = FinalVID - RVO
* else
* TargetVID = CurrentVIDD - RVO
*/
msr.hi = 1; msr.hi = 1;
msr.lo = (vid_max << 8) | (fid_cur); msr.lo = (vid_max << 8) | (fid_cur);
#if SB_VFSMAF == 1 #if SB_VFSMAF == 1
msr.lo |= (1<<16); /* init changes */ msr.lo |= (1 << 16); /* init changes */
#endif #endif
wrmsr(FIDVID_CTL, msr); wrmsr(FIDVID_CTL, msr);
#if SB_VFSMAF == 0 #if SB_VFSMAF == 0
@ -152,38 +171,92 @@ static unsigned set_fidvid(unsigned apicid, unsigned fidvid, int showmessage)
#endif #endif
for (loop=0;loop<100000;loop++){ for (loop=0; loop < 100000; loop++){
msr = rdmsr(FIDVID_STATUS); msr = rdmsr(FIDVID_STATUS);
if (!(msr.lo & (1<<31))) if (!(msr.lo & (1 << 31)))
break; break;
} }
vid_cur = msr.hi & 0x3f; vid_cur = msr.hi & 0x3f;
steps = 8; //?? /* BKDG figure 12 and 13
while ((fid_cur != fid) && (steps-- > 0)) { * if current fid is odd
u32 fid_temp; * current fid -1 (next lower and even fid)(odd fid for rev G)
if ((fid_cur > (8-4)*2) && (fid> (8-4)*2)) { * if current fid in high-freq table
if (fid_cur<fid) { * while current fid < target fid
fid_temp = fid_cur + 2; * transition to next higher fid in table
} else { * else if target fid > VCO portal of current fid
fid_temp = fid_cur - 2; * transition to highest portal fid in higher fid table
} * while current fid < target fid
} else { * transition to next higher fid in table
/* there is one < 8, So we need to lookup the table to * else
* find the fid_cur */ * transition to target fid
int temp; */
temp = next_fid_a[(fid_cur/2)*12+(fid/2)]; printk(BIOS_DEBUG, "Current fid_cur: 0x%x, fid_max: 0x%x\n",
if (temp <= 0) break; fid_cur, fid_max);
fid_temp = (temp-4) * 2; printk(BIOS_DEBUG, "Requested fid_new: 0x%x\n", fid_new);
}
if (fid_temp > fid_max)
break;
fid_cur = fid_temp; step_limit = 8; /* max 8 steps just in case... */
while ((fid_cur != fid_new) && (step_limit--)) {
u32 fid_temp;
int step;
if (fid_cur < fid_new)
/* Force Fid steps even. step == 0 means 100MHz step */
step = ((fid_new/2) - (fid_cur/2)) * 2;
else
step = ((fid_cur/2) - (fid_new/2)) * 2;
/* If 200Mhz step OR past 3200 max table value */
if ((step == 2) || (fid_new >= 0x18 || fid_cur >= 0x18)) {
printk(BIOS_DEBUG, "200MHZ step ");
/* Step +/- 200MHz at a time */
if (fid_cur < fid_new)
fid_temp = fid_cur + 2;
else
fid_temp = fid_cur - 2;
} else if ( step > 2) { /* If more than a 200Mhz step */
int temp;
/* look it up in the table */
printk(BIOS_DEBUG, "FidVid table step ");
temp = next_fid_200[((fid_new/2) * 13) + (fid_cur/2)];
if (temp > 0)
fid_temp = (temp-4) * 2; /* Table 108 */
else if (temp == 0)
fid_temp = fid_new;
else
break; /* table error */
} else { /* step < 2 (100MHZ) */
printk(BIOS_DEBUG, "100MHZ step ");
/* The table adjust in 200MHz increments. If requested,
* do the 100MHz increment if the CPU supports it.*/
if (cpuid_edx(0x80000007) & (1 << 6)) {
fid_temp = fid_cur + 1;
} else {
/* 100 MHZ not supported. Get out of the loop */
printk(BIOS_DEBUG, "is not supported.\n");
break;
}
}
if (fid_temp > fid_max) {
printk(BIOS_DEBUG, "fid_temp 0x%x > fid_max 0x%x\n",
fid_temp, fid_max);
break;
}
printk(BIOS_DEBUG, "fidvid: 0x%x\n", fid_temp);
/* set target fid */ /* set target fid */
msr.hi = (100000/5); msr.hi = 0x190; /* 2 us for AMD NPT Family 0Fh Processors */
msr.lo = (vid_cur << 8) | fid_cur; msr.lo = (vid_cur << 8) | fid_temp;
#if SB_VFSMAF == 1 #if SB_VFSMAF == 1
msr.lo |= (1 << 16); /* init changes */ msr.lo |= (1 << 16); /* init changes */
#endif #endif
@ -207,15 +280,25 @@ static unsigned set_fidvid(unsigned apicid, unsigned fidvid, int showmessage)
#if K8_SET_FIDVID_DEBUG == 1 #if K8_SET_FIDVID_DEBUG == 1
if (showmessage) { if (showmessage) {
printk(BIOS_DEBUG, "status msr fid, vid %08x:%08x\n", printk(BIOS_DEBUG, "status msr fid, vid %08x:%08x\n",
msr.hi, msr.lo); msr.hi, msr.lo);
} }
#endif #endif
} }
/* set vid to final */ /* set vid to final */
/* TODO - make this more correct. Not a big deal for setting max...
* BKDG figure 11
* if TargetFID > InitialFID
* TargetVID = FinalVID - RVO
* else
* if CurrentVID > FinalVID
* TargetVID = FinalVID - RVO
* else
* TargetVID = CurrentVIDD - RVO
*/
msr.hi = 1; msr.hi = 1;
msr.lo = (vid << 8) | (fid_cur); msr.lo = (vid_new << 8) | (fid_cur);
#if SB_VFSMAF == 1 #if SB_VFSMAF == 1
msr.lo |= (1 << 16); // init changes msr.lo |= (1 << 16); // init changes
#endif #endif
@ -234,10 +317,10 @@ static unsigned set_fidvid(unsigned apicid, unsigned fidvid, int showmessage)
fidvid = (vid_cur << 16) | (fid_cur << 8); fidvid = (vid_cur << 16) | (fid_cur << 8);
if (showmessage) { if (showmessage) {
if (vid!=vid_cur) { if (vid_new != vid_cur) {
printk(BIOS_ERR, "set vid failed for apicid =%08x\n", apicidx); printk(BIOS_ERR, "set vid failed for apicid =%08x\n", apicidx);
} }
if (fid!=fid_cur) { if (fid_new != fid_cur) {
printk(BIOS_ERR, "set fid failed for apicid =%08x\n",apicidx); printk(BIOS_ERR, "set fid failed for apicid =%08x\n",apicidx);
} }
} }
@ -276,7 +359,7 @@ void init_fidvid_ap(unsigned bsp_apicid, unsigned apicid)
vid_cur = msr.hi & 0x3f; vid_cur = msr.hi & 0x3f;
fid_cur = msr.lo & 0x3f; fid_cur = msr.lo & 0x3f;
/* set to current */ /* set to current */
msr.hi = 1; msr.hi = 1;
msr.lo = (vid_cur << 8) | (fid_cur); msr.lo = (vid_cur << 8) | (fid_cur);
wrmsr(FIDVID_CTL, msr); wrmsr(FIDVID_CTL, msr);
@ -284,8 +367,8 @@ void init_fidvid_ap(unsigned bsp_apicid, unsigned apicid)
timeout = wait_cpu_state(bsp_apicid, 1); timeout = wait_cpu_state(bsp_apicid, 1);
if (timeout) { if (timeout) {
printk(BIOS_ERR, printk(BIOS_ERR,
"fidvid_ap_stage1: time out while reading from BSP on %08x\n", "fidvid_ap_stage1: time out while reading from BSP on %08x\n",
apicid); apicid);
} }
/* send signal to BSP about this AP max fid and vid */ /* send signal to BSP about this AP max fid and vid */
@ -311,10 +394,10 @@ void init_fidvid_ap(unsigned bsp_apicid, unsigned apicid)
/* send signal to BSP that this AP fid/vid is set */ /* send signal to BSP that this AP fid/vid is set */
/* allow to change state2 is together with apicid */ /* allow to change state2 is together with apicid */
/* AP at state that We set the requested fid/vid */ /* AP at state that We set the requested fid/vid */
send = (apicid<<24) | (readback & 0x00ffff00); send = (apicid << 24) | (readback & 0x00ffff00);
} else { } else {
printk(BIOS_ERR, printk(BIOS_ERR,
"fidvid_ap_stage2: time out while reading from BSP on %08x\n", "fidvid_ap_stage2: time out while reading from BSP on %08x\n",
apicid); apicid);
} }
@ -322,15 +405,15 @@ void init_fidvid_ap(unsigned bsp_apicid, unsigned apicid)
timeout = wait_cpu_state(bsp_apicid, 3); timeout = wait_cpu_state(bsp_apicid, 3);
if (timeout) { if (timeout) {
printk(BIOS_ERR, printk(BIOS_ERR,
"fidvid_ap_stage3: time out while reading from BSP on %08x\n", "fidvid_ap_stage3: time out while reading from BSP on %08x\n",
apicid); apicid);
} }
} }
static unsigned int calc_common_fidvid(unsigned int fidvid, unsigned int fidvidx) static unsigned int calc_common_fidvid(unsigned int fidvid, unsigned int fidvidx)
{ {
/* FIXME: need to check the change path to verify if it is reachable /* FIXME: need to check the change path to verify if it is reachable
* when common fid is small than 1.6G */ * when common fid is small than 1.6G */
if ((fidvid & 0xff00) <= (fidvidx & 0xff00)) { if ((fidvid & 0xff00) <= (fidvidx & 0xff00)) {
return fidvid; return fidvid;
@ -364,8 +447,8 @@ static void init_fidvid_bsp_stage1(unsigned int ap_apicid, void *gp )
} }
} }
if (timeout) { if (timeout) {
printk(BIOS_ERR, printk(BIOS_ERR,
"fidvid_bsp_stage1: time out while reading from ap %08x\n", "fidvid_bsp_stage1: time out while reading from ap %08x\n",
ap_apicid); ap_apicid);
return; return;
} }
@ -401,8 +484,8 @@ static void init_fidvid_bsp_stage2(unsigned ap_apicid, void *gp)
} }
if (timeout) { if (timeout) {
printk(BIOS_ERR, printk(BIOS_ERR,
"fidvid_bsp_stage2: time out while reading from ap %08x\n", "fidvid_bsp_stage2: time out while reading from ap %08x\n",
ap_apicid); ap_apicid);
return; return;
} }
@ -460,7 +543,7 @@ void init_fidvid_bsp(unsigned bsp_apicid)
/* let all ap trains to state 1 */ /* let all ap trains to state 1 */
lapic_write(LAPIC_MSG_REG, (bsp_apicid << 24) | 1); lapic_write(LAPIC_MSG_REG, (bsp_apicid << 24) | 1);
/* calculate the common max fid/vid that could be used for /* calculate the common max fid/vid that could be used for
* all APs and BSP */ * all APs and BSP */
#if K8_SET_FIDVID_STORE_AP_APICID_AT_FIRST == 1 #if K8_SET_FIDVID_STORE_AP_APICID_AT_FIRST == 1
ap_apicidx.num = 0; ap_apicidx.num = 0;