Re: [U-Boot] [PATCH 19/40] x86: broadwell: Split CPU init

2019-02-21 Thread Bin Meng
On Wed, Jan 30, 2019 at 12:00 PM Simon Glass  wrote:
>
> Split the CPU init into two parts - the 'full' init which happens in the
> first U-Boot phase, and the rest of the init that happens on subsequent
> stages.
>
> Signed-off-by: Simon Glass 
> ---
>
>  arch/x86/cpu/broadwell/Makefile   |   1 +
>  arch/x86/cpu/broadwell/cpu.c  | 673 -
>  arch/x86/cpu/broadwell/cpu_full.c | 694 ++
>  3 files changed, 695 insertions(+), 673 deletions(-)
>  create mode 100644 arch/x86/cpu/broadwell/cpu_full.c
>

Reviewed-by: Bin Meng 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 19/40] x86: broadwell: Split CPU init

2019-01-29 Thread Simon Glass
Split the CPU init into two parts - the 'full' init which happens in the
first U-Boot phase, and the rest of the init that happens on subsequent
stages.

Signed-off-by: Simon Glass 
---

 arch/x86/cpu/broadwell/Makefile   |   1 +
 arch/x86/cpu/broadwell/cpu.c  | 673 -
 arch/x86/cpu/broadwell/cpu_full.c | 694 ++
 3 files changed, 695 insertions(+), 673 deletions(-)
 create mode 100644 arch/x86/cpu/broadwell/cpu_full.c

diff --git a/arch/x86/cpu/broadwell/Makefile b/arch/x86/cpu/broadwell/Makefile
index 55f2c93719..303d2b274b 100644
--- a/arch/x86/cpu/broadwell/Makefile
+++ b/arch/x86/cpu/broadwell/Makefile
@@ -3,6 +3,7 @@
 # Copyright (c) 2016 Google, Inc
 
 obj-y += cpu.o
+obj-y += cpu_full.o
 obj-y += iobp.o
 obj-y += lpc.o
 obj-y += me.o
diff --git a/arch/x86/cpu/broadwell/cpu.c b/arch/x86/cpu/broadwell/cpu.c
index d53c7b863f..bb7c361408 100644
--- a/arch/x86/cpu/broadwell/cpu.c
+++ b/arch/x86/cpu/broadwell/cpu.c
@@ -21,68 +21,6 @@
 #include 
 #include 
 
-struct cpu_broadwell_priv {
-   bool ht_disabled;
-};
-
-/* Convert time in seconds to POWER_LIMIT_1_TIME MSR value */
-static const u8 power_limit_time_sec_to_msr[] = {
-   [0]   = 0x00,
-   [1]   = 0x0a,
-   [2]   = 0x0b,
-   [3]   = 0x4b,
-   [4]   = 0x0c,
-   [5]   = 0x2c,
-   [6]   = 0x4c,
-   [7]   = 0x6c,
-   [8]   = 0x0d,
-   [10]  = 0x2d,
-   [12]  = 0x4d,
-   [14]  = 0x6d,
-   [16]  = 0x0e,
-   [20]  = 0x2e,
-   [24]  = 0x4e,
-   [28]  = 0x6e,
-   [32]  = 0x0f,
-   [40]  = 0x2f,
-   [48]  = 0x4f,
-   [56]  = 0x6f,
-   [64]  = 0x10,
-   [80]  = 0x30,
-   [96]  = 0x50,
-   [112] = 0x70,
-   [128] = 0x11,
-};
-
-/* Convert POWER_LIMIT_1_TIME MSR value to seconds */
-static const u8 power_limit_time_msr_to_sec[] = {
-   [0x00] = 0,
-   [0x0a] = 1,
-   [0x0b] = 2,
-   [0x4b] = 3,
-   [0x0c] = 4,
-   [0x2c] = 5,
-   [0x4c] = 6,
-   [0x6c] = 7,
-   [0x0d] = 8,
-   [0x2d] = 10,
-   [0x4d] = 12,
-   [0x6d] = 14,
-   [0x0e] = 16,
-   [0x2e] = 20,
-   [0x4e] = 24,
-   [0x6e] = 28,
-   [0x0f] = 32,
-   [0x2f] = 40,
-   [0x4f] = 48,
-   [0x6f] = 56,
-   [0x10] = 64,
-   [0x30] = 80,
-   [0x50] = 96,
-   [0x70] = 112,
-   [0x11] = 128,
-};
-
 int arch_cpu_init_dm(void)
 {
struct udevice *dev;
@@ -168,614 +106,3 @@ void board_debug_uart_init(void)
pci_x86_write_config(bus, PCH_DEV_LPC, LPC_EN, COMA_LPC_EN,
 PCI_SIZE_16);
 }
-
-/*
- * The core 100MHz BLCK is disabled in deeper c-states. One needs to calibrate
- * the 100MHz BCLCK against the 24MHz BLCK to restore the clocks properly
- * when a core is woken up
- */
-static int pcode_ready(void)
-{
-   int wait_count;
-   const int delay_step = 10;
-
-   wait_count = 0;
-   do {
-   if (!(readl(MCHBAR_REG(BIOS_MAILBOX_INTERFACE)) &
-   MAILBOX_RUN_BUSY))
-   return 0;
-   wait_count += delay_step;
-   udelay(delay_step);
-   } while (wait_count < 1000);
-
-   return -ETIMEDOUT;
-}
-
-static u32 pcode_mailbox_read(u32 command)
-{
-   int ret;
-
-   ret = pcode_ready();
-   if (ret) {
-   debug("PCODE: mailbox timeout on wait ready\n");
-   return ret;
-   }
-
-   /* Send command and start transaction */
-   writel(command | MAILBOX_RUN_BUSY, MCHBAR_REG(BIOS_MAILBOX_INTERFACE));
-
-   ret = pcode_ready();
-   if (ret) {
-   debug("PCODE: mailbox timeout on completion\n");
-   return ret;
-   }
-
-   /* Read mailbox */
-   return readl(MCHBAR_REG(BIOS_MAILBOX_DATA));
-}
-
-static int pcode_mailbox_write(u32 command, u32 data)
-{
-   int ret;
-
-   ret = pcode_ready();
-   if (ret) {
-   debug("PCODE: mailbox timeout on wait ready\n");
-   return ret;
-   }
-
-   writel(data, MCHBAR_REG(BIOS_MAILBOX_DATA));
-
-   /* Send command and start transaction */
-   writel(command | MAILBOX_RUN_BUSY, MCHBAR_REG(BIOS_MAILBOX_INTERFACE));
-
-   ret = pcode_ready();
-   if (ret) {
-   debug("PCODE: mailbox timeout on completion\n");
-   return ret;
-   }
-
-   return 0;
-}
-
-/* @dev is the CPU device */
-static void initialize_vr_config(struct udevice *dev)
-{
-   int ramp, min_vid;
-   msr_t msr;
-
-   debug("Initializing VR config\n");
-
-   /* Configure VR_CURRENT_CONFIG */
-   msr = msr_read(MSR_VR_CURRENT_CONFIG);
-   /*
-* Preserve bits 63 and 62. Bit 62 is PSI4 enable, but it is only valid
-* on ULT systems
-*/
-   msr.hi &= 0xc000;
-   msr.hi |= (0x01 << (52 - 32)); /* PSI3 threshold -  1A */
-   msr.hi |= (0x05 << (42 - 32)); /* PSI2 threshold -  5A */
-