printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / cpu / amd / model_10xxx / init_cpus.c
index 5c17a9a118b1baff5ab49e363d60d9cd4aa329f6..d0458dfed5d2a336747ed1482b06cd0c8fa0ccd2 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "defaults.h"
 
-//it takes the ENABLE_APIC_EXT_ID and APIC_ID_OFFSET and LIFT_BSP_APIC_ID
+//it takes the CONFIG_ENABLE_APIC_EXT_ID and CONFIG_APIC_ID_OFFSET and CONFIG_LIFT_BSP_APIC_ID
 #ifndef FAM10_SET_FIDVID
        #define FAM10_SET_FIDVID 1
 #endif
        #define FAM10_SET_FIDVID_CORE0_ONLY 0
 #endif
 
-static inline void print_initcpu8 (const char *strval, u8 val)
+static void print_initcpu8 (const char *strval, u8 val)
 {
-       printk_debug("%s%02x\n", strval, val);
+       printk(BIOS_DEBUG, "%s%02x\n", strval, val);
 }
 
-static inline void print_initcpu8_nocr (const char *strval, u8 val)
+static void print_initcpu8_nocr (const char *strval, u8 val)
 {
-       printk_debug("%s%02x", strval, val);
+       printk(BIOS_DEBUG, "%s%02x", strval, val);
 }
 
 
-static inline void print_initcpu16 (const char *strval, u16 val)
+static void print_initcpu16 (const char *strval, u16 val)
 {
-       printk_debug("%s%04x\n", strval, val);
+       printk(BIOS_DEBUG, "%s%04x\n", strval, val);
 }
 
 
-static inline void print_initcpu(const char *strval, u32 val)
+static void print_initcpu(const char *strval, u32 val)
 {
-       printk_debug("%s%08x\n", strval, val);
+       printk(BIOS_DEBUG, "%s%08x\n", strval, val);
 }
 
 
+void update_microcode(u32 cpu_deviceid);
 static void prep_fid_change(void);
 static void init_fidvid_stage2(u32 apicid, u32 nodeid);
 void cpuSetAMDMSR(void);
 
-#if PCI_IO_CFG_EXT == 1
-static inline void set_EnableCf8ExtCfg(void)
+#if CONFIG_PCI_IO_CFG_EXT == 1
+static void set_EnableCf8ExtCfg(void)
 {
        // set the NB_CFG[46]=1;
        msr_t msr;
        msr = rdmsr(NB_CFG_MSR);
-       // EnableCf8ExtCfg: We need that to access PCI_IO_CFG_EXT 4K range
+       // EnableCf8ExtCfg: We need that to access CONFIG_PCI_IO_CFG_EXT 4K range
        msr.hi |= (1<<(46-32));
        wrmsr(NB_CFG_MSR, msr);
 }
 #else
-static inline void set_EnableCf8ExtCfg(void) { }
+static void set_EnableCf8ExtCfg(void) { }
 #endif
 
 
@@ -77,14 +78,14 @@ static inline void set_EnableCf8ExtCfg(void) { }
 /* because we will use gs to store hi, so need to make sure lo can start
    from 0, So PCI_MMIO_BASE & 0x00ffffff should be equal to 0*/
 
-static inline void set_pci_mmio_conf_reg(void)
+static void set_pci_mmio_conf_reg(void)
 {
-#if MMCONF_SUPPORT
+#if CONFIG_MMCONF_SUPPORT
        msr_t msr;
        msr = rdmsr(0xc0010058);
        msr.lo &= ~(0xfff00000 | (0xf << 2));
        // 256 bus per segment, MMIO reg will be 4G , enable MMIO Config space
-       msr.lo |= ((8+PCI_BUS_SEGN_BITS) << 2) | (1 << 0);
+       msr.lo |= ((8+CONFIG_PCI_BUS_SEGN_BITS) << 2) | (1 << 0);
        msr.hi &= ~(0x0000ffff);
        msr.hi |= (PCI_MMIO_BASE >> (32-8));
        wrmsr(0xc0010058, msr); // MMIO Config Base Address Reg
@@ -167,11 +168,11 @@ static void for_each_ap(u32 bsp_apicid, u32 core_range,
                for (j = jstart; j <= jend; j++) {
                        ap_apicid = i * (nb_cfg_54 ? (siblings + 1):1) + j * (nb_cfg_54 ? 1:64);
 
-               #if (ENABLE_APIC_EXT_ID == 1) && (APIC_ID_OFFSET > 0)
-                       #if LIFT_BSP_APIC_ID == 0
+               #if (CONFIG_ENABLE_APIC_EXT_ID == 1) && (CONFIG_APIC_ID_OFFSET > 0)
+                       #if CONFIG_LIFT_BSP_APIC_ID == 0
                        if( (i != 0) || (j != 0)) /* except bsp */
                        #endif
-                               ap_apicid += APIC_ID_OFFSET;
+                               ap_apicid += CONFIG_APIC_ID_OFFSET;
                #endif
 
                        if(ap_apicid == bsp_apicid) continue;
@@ -183,7 +184,7 @@ static void for_each_ap(u32 bsp_apicid, u32 core_range,
 }
 
 /* FIXME: Duplicate of what is in lapic.h? */
-static inline int lapic_remote_read(int apicid, int reg, u32 *pvalue)
+static int lapic_remote_read(int apicid, int reg, u32 *pvalue)
 {
        int timeout;
        u32 status;
@@ -222,7 +223,7 @@ static void init_fidvid_ap(u32 bsp_apicid, u32 apicid, u32 nodeid, u32 coreid);
 
 static inline __attribute__((always_inline)) void print_apicid_nodeid_coreid(u32 apicid, struct node_core_id id, const char *str)
 {
-               printk_debug("%s --- {   APICID = %02x NODEID = %02x COREID = %02x} ---\n", str, apicid, id.nodeid, id.coreid);
+               printk(BIOS_DEBUG, "%s --- {     APICID = %02x NODEID = %02x COREID = %02x} ---\n", str, apicid, id.nodeid, id.coreid);
 }
 
 
@@ -294,15 +295,17 @@ static void enable_apic_ext_id(u32 node)
 
 static void STOP_CAR_AND_CPU()
 {
+       msr_t msr;
+
+       /* Disable L2 IC to L3 connection (Only for CAR) */
+       msr = rdmsr(BU_CFG2);
+       msr.lo &= ~(1 << ClLinesToNbDis);
+       wrmsr(BU_CFG2, msr);
+
        disable_cache_as_ram(); // inline
        stop_this_cpu();
 }
 
-
-#ifndef MEM_TRAIN_SEQ
-#define MEM_TRAIN_SEQ 0
-#endif
-
 #if RAMINIT_SYSINFO == 1
 static u32 init_cpus(u32 cpu_init_detectedx ,struct sys_info *sysinfo)
 #else
@@ -329,7 +332,7 @@ static u32 init_cpus(u32 cpu_init_detectedx)
        if(id.coreid == 0) {
                set_apicid_cpuid_lo(); /* only set it on core0 */
                set_EnableCf8ExtCfg(); /* only set it on core0 */
-               #if (ENABLE_APIC_EXT_ID == 1)
+               #if (CONFIG_ENABLE_APIC_EXT_ID == 1)
                enable_apic_ext_id(id.nodeid);
                #endif
        }
@@ -337,23 +340,23 @@ static u32 init_cpus(u32 cpu_init_detectedx)
        enable_lapic();
 
 
-#if (ENABLE_APIC_EXT_ID == 1) && (APIC_ID_OFFSET > 0)
+#if (CONFIG_ENABLE_APIC_EXT_ID == 1) && (CONFIG_APIC_ID_OFFSET > 0)
        u32 initial_apicid = get_initial_apicid();
 
-       #if LIFT_BSP_APIC_ID == 0
+       #if CONFIG_LIFT_BSP_APIC_ID == 0
        if( initial_apicid != 0 ) // other than bsp
        #endif
        {
                /* use initial apic id to lift it */
                u32 dword = lapic_read(LAPIC_ID);
                dword &= ~(0xff << 24);
-               dword |= (((initial_apicid + APIC_ID_OFFSET) & 0xff) << 24);
+               dword |= (((initial_apicid + CONFIG_APIC_ID_OFFSET) & 0xff) << 24);
 
                lapic_write(LAPIC_ID, dword);
        }
 
-       #if LIFT_BSP_APIC_ID == 1
-       bsp_apicid += APIC_ID_OFFSET;
+       #if CONFIG_LIFT_BSP_APIC_ID == 1
+       bsp_apicid += CONFIG_APIC_ID_OFFSET;
        #endif
 
 #endif
@@ -391,6 +394,7 @@ static u32 init_cpus(u32 cpu_init_detectedx)
                 * This happens after HTinit.
                 * The BSP runs this code in it's own path.
                 */
+               update_microcode(cpuid_eax(1));
                cpuSetAMDMSR();
 
 
@@ -402,10 +406,10 @@ static u32 init_cpus(u32 cpu_init_detectedx)
                {
                // check warm(bios) reset to call stage2 otherwise do stage1
                        if (warm_reset_detect(id.nodeid)) {
-                               printk_debug("init_fidvid_stage2 apicid: %02x\n", apicid);
+                               printk(BIOS_DEBUG, "init_fidvid_stage2 apicid: %02x\n", apicid);
                                init_fidvid_stage2(apicid, id.nodeid);
                        } else {
-                               printk_debug("init_fidvid_ap(stage1) apicid: %02x\n", apicid);
+                               printk(BIOS_DEBUG, "init_fidvid_ap(stage1) apicid: %02x\n", apicid);
                                init_fidvid_ap(bsp_apicid, apicid, id.nodeid, id.coreid);
                        }
                }
@@ -417,10 +421,10 @@ static u32 init_cpus(u32 cpu_init_detectedx)
                 */
                //wait_till_sysinfo_in_ram();
 
-               set_init_ram_access();
+               set_var_mtrr(0, 0x00000000, CONFIG_RAMTOP, MTRR_TYPE_WRBACK);
 
                STOP_CAR_AND_CPU();
-               printk_debug("\nAP %02x should be halted but you are reading this....\n", apicid);
+               printk(BIOS_DEBUG, "\nAP %02x should be halted but you are reading this....\n", apicid);
        }
 
        return bsp_apicid;
@@ -445,12 +449,12 @@ static void wait_all_core0_started(void)
        u32 i;
        u32 nodes = get_nodes();
 
-       printk_debug("Wait all core0s started \n");
+       printk(BIOS_DEBUG, "Wait all core0s started \n");
        for(i=1;i<nodes;i++) { // skip bsp, because it is running on bsp
                while(!is_core0_started(i)) {}
                print_initcpu8("  Core0 started on node: ", i);
        }
-       printk_debug("Wait all core0s started done\n");
+       printk(BIOS_DEBUG, "Wait all core0s started done\n");
 }
 #if CONFIG_MAX_PHYSICAL_CPUS > 1
 /**
@@ -459,7 +463,7 @@ static void wait_all_core0_started(void)
  *  start the core0 in node, so it can generate HT packet to feature code.
  *
  * This function starts the AP nodes core0s. wait_all_core0_started() in
- * cache_as_ram_auto.c waits for all the AP to be finished before continuing
+ * romstage.c waits for all the AP to be finished before continuing
  * system init.
  */
 static void start_node(u8 node)
@@ -467,10 +471,10 @@ static void start_node(u8 node)
        u32 val;
 
        /* Enable routing table */
-       printk_debug("Start node %02x", node);
+       printk(BIOS_DEBUG, "Start node %02x", node);
 
-#if CAR_FAM10 == 1
-       /* For CAR_FAM10 support, we need to set Dram base/limit for the new node */
+#if CONFIG_NORTHBRIDGE_AMD_AMDFAM10
+       /* For FAM10 support, we need to set Dram base/limit for the new node */
        pci_write_config32(NODE_MP(node), 0x44, 0);
        pci_write_config32(NODE_MP(node), 0x40, 3);
 #endif
@@ -480,7 +484,7 @@ static void start_node(u8 node)
        val &= ~(1 << 1);
        pci_write_config32(NODE_HT(node), 0x6c, val);
 
-       printk_debug(" done.\n");
+       printk(BIOS_DEBUG, " done.\n");
 }
 
 
@@ -510,10 +514,10 @@ static void setup_remote_node(u8 node)
        };
        u16 i;
 
-       printk_debug("setup_remote_node: %02x", node);
+       printk(BIOS_DEBUG, "setup_remote_node: %02x", node);
 
        /* copy the default resource map from node 0 */
-       for(i = 0; i < sizeof(pci_reg)/sizeof(pci_reg[0]); i++) {
+       for(i = 0; i < ARRAY_SIZE(pci_reg); i++) {
                u32 value;
                u16 reg;
                reg = pci_reg[i];
@@ -521,7 +525,7 @@ static void setup_remote_node(u8 node)
                pci_write_config32(NODE_MP(node), reg, value);
 
        }
-       printk_debug(" done\n");
+       printk(BIOS_DEBUG, " done\n");
 }
 #endif /* CONFIG_MAX_PHYSICAL_CPUS > 1 */
 
@@ -660,6 +664,35 @@ u32 get_platform_type(void)
 }
 
 
+void AMD_SetupPSIVID_d (u32 platform_type, u8 node)
+{
+       u32 dword;
+       int i;
+       msr_t msr;
+
+       if (platform_type & (AMD_PTYPE_MOB | AMD_PTYPE_DSK)) {
+
+       /* The following code sets the PSIVID to the lowest support P state
+        * assuming that the VID for the lowest power state is below
+        * the VDD voltage regulator threshold. (This also assumes that there
+        * is a Pstate lower than P0)
+        */
+
+               for( i = 4; i >= 0; i--) {
+                       msr = rdmsr(PS_REG_BASE + i);
+                       /*  Pstate valid? */
+                       if (msr.hi & PS_EN_MASK) {
+                               dword = pci_read_config32(NODE_PCI(i,3), 0xA0);
+                               dword &= ~0x7F;
+                               dword |= (msr.lo >> 9) & 0x7F;
+                               pci_write_config32(NODE_PCI(i,3), 0xA0, dword);
+                               break;
+                       }
+               }
+       }
+}
+
+
 /**
  * AMD_CpuFindCapability - Traverse PCI capability list to find host HT links.
  *  HT Phy operations are not valid on links that aren't present, so this
@@ -681,11 +714,13 @@ BOOL AMD_CpuFindCapability (u8 node, u8 cap_count, u8 *offset)
        do {
                val = pci_read_config32(NODE_PCI(node, 0), val);
                /* Is the capability block a HyperTransport capability block? */
-               if ((val & 0xFF) == 0x08)
+               if ((val & 0xFF) == 0x08) {
                        /* Is the HT capability block an HT Host Capability? */
                        if ((val & 0xE0000000) == (1 << 29))
                                cap_count--;
-               val = (val >> 8) & 0xFF;
+               }
+               if (cap_count)
+                       val = (val >> 8) & 0xFF;
        } while (cap_count && val);
 
        *offset = (u8) val;
@@ -707,9 +742,9 @@ BOOL AMD_CpuFindCapability (u8 node, u8 cap_count, u8 *offset)
 u32 AMD_checkLinkType (u8 node, u8 link, u8 regoff)
 {
        u32 val;
-       u32 linktype;
+       u32 linktype = 0;
 
-       /* Check coherency */
+       /* Check connect, init and coherency */
        val = pci_read_config32(NODE_PCI(node, 0), regoff + 0x18);
        val &= 0x1F;
 
@@ -719,23 +754,24 @@ u32 AMD_checkLinkType (u8 node, u8 link, u8 regoff)
        if (val == 7)
                linktype |= HTPHY_LINKTYPE_NONCOHERENT;
 
-       /* Check gen3 */
-       val = pci_read_config32(NODE_PCI(node, 0), regoff + 0x08);
-
-       if (((val >> 8) & 0x0F) > 6)
-               linktype |= HTPHY_LINKTYPE_HT3;
-       else
-               linktype |= HTPHY_LINKTYPE_HT1;
+       if (linktype) {
+               /* Check gen3 */
+               val = pci_read_config32(NODE_PCI(node, 0), regoff + 0x08);
 
+               if (((val >> 8) & 0x0F) > 6)
+                       linktype |= HTPHY_LINKTYPE_HT3;
+               else
+                       linktype |= HTPHY_LINKTYPE_HT1;
 
-       /* Check ganged */
-       val = pci_read_config32(NODE_PCI(node, 0), (link << 2) + 0x170);
 
-       if ( val & 1)
-               linktype |= HTPHY_LINKTYPE_GANGED;
-       else
-               linktype |= HTPHY_LINKTYPE_UNGANGED;
+               /* Check ganged */
+               val = pci_read_config32(NODE_PCI(node, 0), (link << 2) + 0x170);
 
+               if ( val & 1)
+                       linktype |= HTPHY_LINKTYPE_GANGED;
+               else
+                       linktype |= HTPHY_LINKTYPE_UNGANGED;
+       }
        return linktype;
 }
 
@@ -809,12 +845,12 @@ void cpuSetAMDMSR(void)
        u8 i;
        u32 revision, platform;
 
-       printk_debug("cpuSetAMDMSR ");
+       printk(BIOS_DEBUG, "cpuSetAMDMSR ");
 
        revision = mctGetLogicalCPUID(0xFF);
        platform = get_platform_type();
 
-       for(i = 0; i < sizeof(fam10_msr_default)/sizeof(fam10_msr_default[0]); i++) {
+       for(i = 0; i < ARRAY_SIZE(fam10_msr_default); i++) {
                if ((fam10_msr_default[i].revision & revision) &&
                    (fam10_msr_default[i].platform & platform)) {
                        msr = rdmsr(fam10_msr_default[i].msr);
@@ -827,7 +863,7 @@ void cpuSetAMDMSR(void)
        }
        AMD_Errata298();
 
-       printk_debug(" done\n");
+       printk(BIOS_DEBUG, " done\n");
 }
 
 
@@ -843,12 +879,15 @@ void cpuSetAMDPCI(u8 node)
        u32 val;
        u8 offset;
 
-       printk_debug("cpuSetAMDPCI %02d", node);
+       printk(BIOS_DEBUG, "cpuSetAMDPCI %02d", node);
+
 
        revision = mctGetLogicalCPUID(node);
        platform = get_platform_type();
 
-       for(i = 0; i < sizeof(fam10_pci_default)/sizeof(fam10_pci_default[0]); i++) {
+       AMD_SetupPSIVID_d(platform, node);      /* Set PSIVID offset which is not table driven */
+
+       for(i = 0; i < ARRAY_SIZE(fam10_pci_default); i++) {
                if ((fam10_pci_default[i].revision & revision) &&
                    (fam10_pci_default[i].platform & platform)) {
                        val = pci_read_config32(NODE_PCI(node,
@@ -862,7 +901,7 @@ void cpuSetAMDPCI(u8 node)
                }
        }
 
-       for(i = 0; i < sizeof(fam10_htphy_default)/sizeof(fam10_htphy_default[0]); i++) {
+       for(i = 0; i < ARRAY_SIZE(fam10_htphy_default); i++) {
                if ((fam10_htphy_default[i].revision & revision) &&
                    (fam10_htphy_default[i].platform & platform)) {
                        /* HT Phy settings either apply to both sublinks or have
@@ -894,7 +933,7 @@ void cpuSetAMDPCI(u8 node)
        if (revision & (AMD_DR_B2 | AMD_DR_B3))
                dctPhyDiag(); */
 
-       printk_debug(" done\n");
+       printk(BIOS_DEBUG, " done\n");
 }