Merge "intel: agilex: Fix memory controller driver" into integration
authorPaul Beesley <paul.beesley@arm.com>
Thu, 15 Aug 2019 15:30:51 +0000 (15:30 +0000)
committerTrustedFirmware Code Review <review@review.trustedfirmware.org>
Thu, 15 Aug 2019 15:30:51 +0000 (15:30 +0000)
19 files changed:
bl31/aarch64/crash_reporting.S
common/aarch64/debug.S
include/plat/arm/common/aarch64/arm_macros.S
lib/aarch32/arm32_aeabi_divmod.c
lib/extensions/ras/ras_common.c
lib/xlat_tables/aarch32/nonlpae_tables.c
plat/intel/soc/agilex/bl2_plat_setup.c
plat/intel/soc/agilex/include/agilex_clock_manager.h
plat/intel/soc/agilex/include/agilex_private.h
plat/intel/soc/agilex/include/agilex_system_manager.h
plat/intel/soc/agilex/soc/agilex_clock_manager.c
plat/rockchip/common/bl31_plat_setup.c
plat/rockchip/common/include/plat_private.h
plat/rockchip/common/params_setup.c
plat/rockchip/common/sp_min_plat_setup.c
plat/rockchip/px30/px30_def.h
plat/rockchip/rk3399/drivers/pmu/pmu.c
services/spd/opteed/opteed.mk
services/std_svc/spm/spm_buffers.c

index 40506785bf182c6108a01dc8d1e313a9dc6fdf37..2c41029813e7aef92049d8c225550750d25c5587 100644 (file)
@@ -28,7 +28,7 @@
         */
 .section .rodata.crash_prints, "aS"
 print_spacer:
-       .asciz  " =\t\t0x"
+       .asciz  "             = 0x"
 
 gp_regs:
        .asciz  "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",\
@@ -55,11 +55,11 @@ aarch32_regs:
 #endif /* CTX_INCLUDE_AARCH32_REGS */
 
 panic_msg:
-       .asciz "PANIC in EL3 at x30 = 0x"
+       .asciz "PANIC in EL3.\nx30"
 excpt_msg:
-       .asciz "Unhandled Exception in EL3.\nx30 =\t\t0x"
+       .asciz "Unhandled Exception in EL3.\nx30"
 intr_excpt_msg:
-       .asciz "Unhandled Interrupt Exception in EL3.\nx30 =\t\t0x"
+       .asciz "Unhandled Interrupt Exception in EL3.\nx30"
 
        /*
         * Helper function to print newline to console.
@@ -94,10 +94,11 @@ test_size_list:
        mov     x4, x6
        /* asm_print_str updates x4 to point to next entry in list */
        bl      asm_print_str
+       /* x0 = number of symbols printed + 1 */
+       sub     x0, x4, x6
        /* update x6 with the updated list pointer */
        mov     x6, x4
-       adr     x4, print_spacer
-       bl      asm_print_str
+       bl      print_alignment
        ldr     x4, [x7], #REGSZ
        bl      asm_print_hex
        bl      print_newline
@@ -107,6 +108,20 @@ exit_size_print:
        ret
 endfunc size_controlled_print
 
+       /* -----------------------------------------------------
+        * This function calculates and prints required number
+        * of space characters followed by "= 0x", based on the
+        * length of ascii register name.
+        * x0: length of ascii register name + 1
+        * ------------------------------------------------------
+        */
+func print_alignment
+       /* The minimum ascii length is 3, e.g. for "x0" */
+       adr     x4, print_spacer - 3
+       add     x4, x4, x0
+       b       asm_print_str
+endfunc print_alignment
+
        /*
         * Helper function to store x8 - x15 registers to
         * the crash buf. The system registers values are
@@ -189,7 +204,7 @@ endfunc report_unhandled_interrupt
         * -----------------------------------------------------
         */
 func el3_panic
-       msr     spsel, #1
+       msr     spsel, #MODE_SP_ELX
        prepare_crash_buf_save_x0_x1
        adr     x0, panic_msg
        mov     sp, x0
@@ -230,6 +245,9 @@ func do_crash_reporting
        /* Print the crash message. sp points to the crash message */
        mov     x4, sp
        bl      asm_print_str
+       /* Print spaces to align "x30" string */
+       mov     x0, #4
+       bl      print_alignment
        /* load the crash buf address */
        mrs     x0, tpidr_el3
        /* report x30 first from the crash buf */
index da740ef2201c3cadd3214e026e46e31c1179af8f..ac47cbe9ef217c30625c27e4f856e06f208e2088 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2017, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2014-2019, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -10,6 +10,7 @@
 
        .globl  asm_print_str
        .globl  asm_print_hex
+       .globl  asm_print_hex_bits
        .globl  asm_assert
        .globl  do_panic
 
@@ -107,8 +108,11 @@ endfunc asm_print_str
  * Clobber: x30, x0 - x3, x5
  */
 func asm_print_hex
-       mov     x3, x30
        mov     x5, #64  /* No of bits to convert to ascii */
+
+       /* Convert to ascii number of bits in x5 */
+asm_print_hex_bits:
+       mov     x3, x30
 1:
        sub     x5, x5, #4
        lsrv    x0, x4, x5
index 0bd0daf53b69334fa3c3722f8037736d88c2dc59..d47e4e0969505b5e94f03a870aa318d98edc3bc9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -22,11 +22,13 @@ icc_regs:
 
 /* Registers common to both GICv2 and GICv3 */
 gicd_pend_reg:
-       .asciz "gicd_ispendr regs (Offsets 0x200 - 0x278)\n Offset:\t\t\tvalue\n"
+       .asciz "gicd_ispendr regs (Offsets 0x200-0x278)\nOffset\t\t\tValue\n"
 newline:
        .asciz "\n"
 spacer:
-       .asciz ":\t\t0x"
+       .asciz ":\t\t 0x"
+prefix:
+       .asciz "0x"
 
        /* ---------------------------------------------
         * The below utility macro prints out relevant GIC
@@ -77,7 +79,15 @@ gicd_ispendr_loop:
        sub     x4, x7, x16
        cmp     x4, #0x280
        b.eq    exit_print_gic_regs
-       bl      asm_print_hex
+
+       /* Print "0x" */
+       adr     x4, prefix
+       bl      asm_print_str
+
+       /* Print offset */
+       sub     x4, x7, x16
+       mov     x5, #12
+       bl      asm_print_hex_bits
 
        adr     x4, spacer
        bl      asm_print_str
index 0b36cb6cf43d63a462db210bc18c5ee1faca93e1..ea8e2bbca684c86ac645ed0f2d7727468cf905ea 100644 (file)
@@ -33,13 +33,11 @@ static void uint_div_qr(unsigned int numerator, unsigned int denominator,
 unsigned int __aeabi_uidivmod(unsigned int numerator, unsigned int denominator);
 
 unsigned int __aeabi_uidiv(unsigned int numerator, unsigned int denominator);
-unsigned int __aeabi_uimod(unsigned int numerator, unsigned int denominator);
 
 /* returns in R0 and R1 by tail calling an asm function */
 signed int __aeabi_idivmod(signed int numerator, signed int denominator);
 
 signed int __aeabi_idiv(signed int numerator, signed int denominator);
-signed int __aeabi_imod(signed int numerator, signed int denominator);
 
 /*
  * __ste_idivmod_ret_t __aeabi_idivmod(signed numerator, signed denominator)
@@ -106,15 +104,6 @@ unsigned int __aeabi_uidiv(unsigned int numerator, unsigned int denominator)
        return qr.q;
 }
 
-unsigned int __aeabi_uimod(unsigned int numerator, unsigned int denominator)
-{
-       struct qr qr = { .q_n = 0, .r_n = 0 };
-
-       uint_div_qr(numerator, denominator, &qr);
-
-       return qr.r;
-}
-
 unsigned int __aeabi_uidivmod(unsigned int numerator, unsigned int denominator)
 {
        struct qr qr = { .q_n = 0, .r_n = 0 };
@@ -145,42 +134,6 @@ signed int __aeabi_idiv(signed int numerator, signed int denominator)
        return qr.q;
 }
 
-signed int __aeabi_imod(signed int numerator, signed int denominator)
-{
-       signed int s;
-       signed int i;
-       signed int j;
-       signed int h;
-       struct qr qr = { .q_n = 0, .r_n = 0 };
-
-       /* in case modulo of a power of 2 */
-       for (i = 0, j = 0, h = 0, s = denominator; (s != 0) || (h > 1); i++) {
-               if (s & 1) {
-                       j = i;
-                       h++;
-               }
-               s = s >> 1;
-       }
-       if (h == 1)
-               return numerator >> j;
-
-       if (((numerator < 0) && (denominator > 0)) ||
-           ((numerator > 0) && (denominator < 0)))
-               qr.q_n = 1;     /* quotient shall be negate */
-
-       if (numerator < 0) {
-               numerator = -numerator;
-               qr.r_n = 1;     /* remainder shall be negate */
-       }
-
-       if (denominator < 0)
-               denominator = -denominator;
-
-       uint_div_qr(numerator, denominator, &qr);
-
-       return qr.r;
-}
-
 signed int __aeabi_idivmod(signed int numerator, signed int denominator)
 {
        struct qr qr = { .q_n = 0, .r_n = 0 };
index be8beceeb4972a89215b51c66870e7a7c287323a..64a48524b8a9b368fc99a17847688d72b5adda54 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -83,7 +83,8 @@ static int ras_interrupt_handler(uint32_t intr_raw, uint32_t flags,
 {
        struct ras_interrupt *ras_inrs = ras_interrupt_mappings.intrs;
        struct ras_interrupt *selected = NULL;
-       int start, end, mid, probe_data, ret __unused;
+       int probe_data = 0;
+       int start, end, mid, ret __unused;
 
        const struct err_handler_data err_data = {
                .version = ERR_HANDLER_VERSION,
index e31f9d8404cf11b5c9ee4e0b468e496c0bf94a50..bd6b152ef4e184506bad748702fdaf75a026d3d7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2016-2017, Linaro Limited. All rights reserved.
- * Copyright (c) 2014-2017, Arm Limited. All rights reserved.
+ * Copyright (c) 2014-2019, Arm Limited. All rights reserved.
  * Copyright (c) 2014, STMicroelectronics International N.V.
  * All rights reserved.
  *
@@ -445,7 +445,8 @@ static mmap_region_t *init_xlation_table_inner(mmap_region_t *mm,
                        } else {
                                xlat_table = (unsigned long)mmu_l2_base +
                                        next_xlat * MMU32B_L2_TABLE_SIZE;
-                               assert(++next_xlat <= MAX_XLAT_TABLES);
+                               next_xlat++;
+                               assert(next_xlat <= MAX_XLAT_TABLES);
                                memset((char *)xlat_table, 0,
                                        MMU32B_L2_TABLE_SIZE);
 
index 385065f95e5f14a6a5de46ba99dedd7f5c9f0e39..e9ab92850e8070aba1ddb89786d71e1fd06d53a8 100644 (file)
@@ -69,9 +69,9 @@ void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
        deassert_peripheral_reset();
        config_hps_hs_before_warm_reset();
 
-       watchdog_init(get_wdt_clk(&reverse_handoff_ptr));
+       watchdog_init(get_wdt_clk());
 
-       console_16550_register(PLAT_UART0_BASE, PLAT_UART_CLOCK, PLAT_BAUDRATE,
+       console_16550_register(PLAT_UART0_BASE, get_uart_clk(), PLAT_BAUDRATE,
                &console);
 
        socfpga_delay_timer_init();
@@ -105,7 +105,7 @@ void bl2_el3_plat_arch_setup(void)
 
        enable_mmu_el3(0);
 
-       dw_mmc_params_t params = EMMC_INIT_PARAMS(0x100000);
+       dw_mmc_params_t params = EMMC_INIT_PARAMS(0x100000, get_mmc_clk());
 
        info.mmc_dev_type = MMC_IS_SD;
        info.ocr_voltage = OCR_3_3_3_4 | OCR_3_2_3_3;
index c1a7546c7e592e3db888b1b20ed5c9304cbcdcfc..73e6c4e19a4bc64c53c830237bf470df890f1f82 100644 (file)
 #define CLKMGR_STAT_PERPLLLOCKED(x)            (((x) & 0x00010000) >> 16)
 #define CLKMGR_INTRCLR_MAINLOCKLOST_SET_MSK    0x00000004
 #define CLKMGR_INTRCLR_PERLOCKLOST_SET_MSK     0x00000008
+#define CLKMGR_INTOSC_HZ                       460000000
 
 /* Main PLL Macros */
 #define CLKMGR_MAINPLL_EN_RESET                        0x000000ff
-#define CLKMGR_MAINPLL_PLLM_MDIV(x)            ((x) & 0x000003ff)
-#define CLKMGR_MAINPLL_PLLGLOB_PD_SET_MSK      0x00000001
-#define CLKMGR_MAINPLL_PLLGLOB_RST_SET_MSK     0x00000002
-
-#define CLKMGR_MAINPLL_PLLGLOB_REFCLKDIV(x)    (((x) & 0x00003f00) >> 8)
-#define CLKMGR_MAINPLL_PLLGLOB_AREFCLKDIV(x)   (((x) & 0x00000f00) >> 8)
-#define CLKMGR_MAINPLL_PLLGLOB_DREFCLKDIV(x)   (((x) & 0x00003000) >> 12)
-
-#define CLKMGR_MAINPLL_PLLGLOB_PSRC(x)         (((x) & 0x00030000) >> 16)
-#define CLKMGR_MAINPLL_PLLGLOB_PSRC_EOSC1      0x0
-#define CLKMGR_MAINPLL_PLLGLOB_PSRC_INTOSC     0x1
-#define CLKMGR_MAINPLL_PLLGLOB_PSRC_F2S                0x2
-#define CLKMGR_MAINPLL_VCOCALIB_HSCNT_SET(x)   (((x) << 0) & 0x000003ff)
-#define CLKMGR_MAINPLL_VCOCALIB_MSCNT_SET(x)   (((x) << 16) & 0x00ff0000)
 
 /* Peripheral PLL Macros */
 #define CLKMGR_PERPLL_EN_RESET                 0x00000fff
-#define CLKMGR_PERPLL_PLLM_MDIV(x)             ((x) & 0x000003ff)
 #define CLKMGR_PERPLL_GPIODIV_GPIODBCLK_SET(x) (((x) << 0) & 0x0000ffff)
-#define CLKMGR_PERPLL_PLLGLOB_PD_SET_MSK       0x00000001
-
-#define CLKMGR_PERPLL_PLLGLOB_REFCLKDIV(x)     (((x) & 0x00003f00) >> 8)
-#define CLKMGR_PERPLL_PLLGLOB_AREFCLKDIV(x)    (((x) & 0x00000f00) >> 8)
-#define CLKMGR_PERPLL_PLLGLOB_DREFCLKDIV(x)    (((x) & 0x00003000) >> 12)
-
-#define CLKMGR_PERPLL_PLLGLOB_RST_SET_MSK      0x00000002
-#define CLKMGR_PERPLL_VCOCALIB_HSCNT_SET(x)    (((x) << 0) & 0x000003ff)
-#define CLKMGR_PERPLL_VCOCALIB_MSCNT_SET(x)    (((x) << 16) & 0x00ff0000)
 
 /* Altera Macros */
 #define CLKMGR_ALTERA_EXTCNTRST_RESET          0xff
 
+/* Shared Macros */
+#define CLKMGR_PSRC(x)                         (((x) & 0x00030000) >> 16)
+#define CLKMGR_PSRC_MAIN                       0
+#define CLKMGR_PSRC_PER                                1
+
+#define CLKMGR_PLLGLOB_PSRC_EOSC1              0x0
+#define CLKMGR_PLLGLOB_PSRC_INTOSC             0x1
+#define CLKMGR_PLLGLOB_PSRC_F2S                        0x2
+
+#define CLKMGR_PLLM_MDIV(x)                    ((x) & 0x000003ff)
+#define CLKMGR_PLLGLOB_PD_SET_MSK              0x00000001
+#define CLKMGR_PLLGLOB_RST_SET_MSK             0x00000002
+
+#define CLKMGR_PLLGLOB_REFCLKDIV(x)            (((x) & 0x00003f00) >> 8)
+#define CLKMGR_PLLGLOB_AREFCLKDIV(x)           (((x) & 0x00000f00) >> 8)
+#define CLKMGR_PLLGLOB_DREFCLKDIV(x)           (((x) & 0x00003000) >> 12)
+
+#define CLKMGR_VCOCALIB_HSCNT_SET(x)           (((x) << 0) & 0x000003ff)
+#define CLKMGR_VCOCALIB_MSCNT_SET(x)           (((x) << 16) & 0x00ff0000)
+
 
 typedef struct {
        uint32_t  clk_freq_of_eosc1;
@@ -123,6 +120,8 @@ typedef struct {
 } CLOCK_SOURCE_CONFIG;
 
 void config_clkmgr_handoff(handoff *hoff_ptr);
-int get_wdt_clk(handoff *hoff_ptr);
+uint32_t get_wdt_clk(void);
+uint32_t get_uart_clk(void);
+uint32_t get_mmc_clk(void);
 
 #endif
index 5ccbc8c3a7cfdb20ecead9b4a9870990e1413e41..fc0e9fddffab8c714c28e09fba49f126a5320189 100644 (file)
 #define AGX_MMC_REG_BASE       0xff808000
 
 #define EMMC_DESC_SIZE         (1<<20)
-#define EMMC_INIT_PARAMS(base)                 \
+#define EMMC_INIT_PARAMS(base, clk)            \
        {       .bus_width = MMC_BUS_WIDTH_4,   \
-               .clk_rate = 50000000,           \
+               .clk_rate = (clk),              \
                .desc_base = (base),            \
                .desc_size = EMMC_DESC_SIZE,    \
                .flags = 0,                     \
-               .reg_base = AGX_MMC_REG_BASE,   \
-               \
+               .reg_base = AGX_MMC_REG_BASE    \
        }
 
 typedef enum {
@@ -26,7 +25,7 @@ typedef enum {
        BOOT_SOURCE_SDMMC,
        BOOT_SOURCE_NAND,
        BOOT_SOURCE_RSVD,
-       BOOT_SOURCE_QSPI,
+       BOOT_SOURCE_QSPI
 } boot_source_type;
 
 void enable_nonsecure_access(void);
index 6ec208426e5e5c4330691b6139968a53024ccd7b..381c2d3551bafc3baf71fe131e0656960d49dfe3 100644 (file)
 #define AGX_CCU_NOC_CPU0_RAMSPACE0_0           0xf7004688
 #define AGX_CCU_NOC_IOM_RAMSPACE0_0            0xf7018628
 
+#define AGX_SYSMGR_CORE(x)                      (0xffd12000 + (x))
+#define SYSMGR_BOOT_SCRATCH_COLD_0             0x200
+#define SYSMGR_BOOT_SCRATCH_COLD_1             0x204
+#define SYSMGR_BOOT_SCRATCH_COLD_2             0x208
+
 #define DISABLE_BRIDGE_FIREWALL                        0x0ffe0101
 #define DISABLE_L4_FIREWALL    (BIT(0) | BIT(16) | BIT(24))
 
index 6e7b43e0958cfe77b6ac343f368980f7149d3097..218676a98fd6ab567bfa2db9f0fe7f8f628d4898 100644 (file)
 
 #include "agilex_clock_manager.h"
 #include "agilex_handoff.h"
+#include "agilex_system_manager.h"
 
-static const CLOCK_SOURCE_CONFIG  clk_source = {
-       /* clk_freq_of_eosc1 */
-       (uint32_t) 25000000,
-       /* clk_freq_of_f2h_free */
-       (uint32_t) 400000000,
-       /* clk_freq_of_cb_intosc_ls */
-       (uint32_t) 50000000,
-};
 
 uint32_t wait_pll_lock(void)
 {
@@ -114,18 +107,18 @@ void config_clkmgr_handoff(handoff *hoff_ptr)
 
        /* Put both PLL in reset and power down */
        mmio_clrbits_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLGLOB,
-                       CLKMGR_MAINPLL_PLLGLOB_PD_SET_MSK |
-                       CLKMGR_MAINPLL_PLLGLOB_RST_SET_MSK);
+                       CLKMGR_PLLGLOB_PD_SET_MSK |
+                       CLKMGR_PLLGLOB_RST_SET_MSK);
        mmio_clrbits_32(CLKMGR_PERPLL + CLKMGR_PERPLL_PLLGLOB,
-                       CLKMGR_PERPLL_PLLGLOB_PD_SET_MSK |
-                       CLKMGR_PERPLL_PLLGLOB_RST_SET_MSK);
+                       CLKMGR_PLLGLOB_PD_SET_MSK |
+                       CLKMGR_PLLGLOB_RST_SET_MSK);
 
        /* Setup main PLL dividers */
-       mdiv = CLKMGR_MAINPLL_PLLM_MDIV(hoff_ptr->main_pll_pllm);
+       mdiv = CLKMGR_PLLM_MDIV(hoff_ptr->main_pll_pllm);
 
-       arefclk_div = CLKMGR_MAINPLL_PLLGLOB_AREFCLKDIV(
+       arefclk_div = CLKMGR_PLLGLOB_AREFCLKDIV(
                        hoff_ptr->main_pll_pllglob);
-       drefclk_div = CLKMGR_MAINPLL_PLLGLOB_DREFCLKDIV(
+       drefclk_div = CLKMGR_PLLGLOB_DREFCLKDIV(
                        hoff_ptr->main_pll_pllglob);
 
        mscnt = 100 / (mdiv / BIT(drefclk_div));
@@ -134,8 +127,8 @@ void config_clkmgr_handoff(handoff *hoff_ptr)
        hscnt = (mdiv * mscnt * BIT(drefclk_div) / arefclk_div) - 4;
 
        mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_VCOCALIB,
-                       CLKMGR_MAINPLL_VCOCALIB_HSCNT_SET(hscnt) |
-                       CLKMGR_MAINPLL_VCOCALIB_MSCNT_SET(mscnt));
+                       CLKMGR_VCOCALIB_HSCNT_SET(hscnt) |
+                       CLKMGR_VCOCALIB_MSCNT_SET(mscnt));
 
        mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_NOCDIV,
                        hoff_ptr->main_pll_nocdiv);
@@ -159,11 +152,11 @@ void config_clkmgr_handoff(handoff *hoff_ptr)
                        hoff_ptr->main_pll_nocclk);
 
        /* Setup peripheral PLL dividers */
-       mdiv = CLKMGR_PERPLL_PLLM_MDIV(hoff_ptr->per_pll_pllm);
+       mdiv = CLKMGR_PLLM_MDIV(hoff_ptr->per_pll_pllm);
 
-       arefclk_div = CLKMGR_PERPLL_PLLGLOB_AREFCLKDIV(
+       arefclk_div = CLKMGR_PLLGLOB_AREFCLKDIV(
                        hoff_ptr->per_pll_pllglob);
-       drefclk_div = CLKMGR_PERPLL_PLLGLOB_DREFCLKDIV(
+       drefclk_div = CLKMGR_PLLGLOB_DREFCLKDIV(
                        hoff_ptr->per_pll_pllglob);
 
        mscnt = 100 / (mdiv / BIT(drefclk_div));
@@ -172,8 +165,8 @@ void config_clkmgr_handoff(handoff *hoff_ptr)
        hscnt = (mdiv * mscnt * BIT(drefclk_div) / arefclk_div) - 4;
 
        mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_VCOCALIB,
-                       CLKMGR_PERPLL_VCOCALIB_HSCNT_SET(hscnt) |
-                       CLKMGR_PERPLL_VCOCALIB_MSCNT_SET(mscnt));
+                       CLKMGR_VCOCALIB_HSCNT_SET(hscnt) |
+                       CLKMGR_VCOCALIB_MSCNT_SET(mscnt));
 
        mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_EMACCTL,
                        hoff_ptr->per_pll_emacctl);
@@ -197,11 +190,11 @@ void config_clkmgr_handoff(handoff *hoff_ptr)
 
        /* Take both PLL out of reset and power up */
        mmio_setbits_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLGLOB,
-                       CLKMGR_MAINPLL_PLLGLOB_PD_SET_MSK |
-                       CLKMGR_MAINPLL_PLLGLOB_RST_SET_MSK);
+                       CLKMGR_PLLGLOB_PD_SET_MSK |
+                       CLKMGR_PLLGLOB_RST_SET_MSK);
        mmio_setbits_32(CLKMGR_PERPLL + CLKMGR_PERPLL_PLLGLOB,
-                       CLKMGR_PERPLL_PLLGLOB_PD_SET_MSK |
-                       CLKMGR_PERPLL_PLLGLOB_RST_SET_MSK);
+                       CLKMGR_PLLGLOB_PD_SET_MSK |
+                       CLKMGR_PLLGLOB_RST_SET_MSK);
 
        wait_pll_lock();
 
@@ -256,24 +249,31 @@ void config_clkmgr_handoff(handoff *hoff_ptr)
                        CLKMGR_MAINPLL_EN_RESET);
        mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_EN,
                        CLKMGR_PERPLL_EN_RESET);
+
+       /* Pass clock source frequency into scratch register */
+       mmio_write_32(AGX_SYSMGR_CORE(SYSMGR_BOOT_SCRATCH_COLD_1),
+               hoff_ptr->hps_osc_clk_h);
+       mmio_write_32(AGX_SYSMGR_CORE(SYSMGR_BOOT_SCRATCH_COLD_2),
+               hoff_ptr->fpga_clk_hz);
 }
 
-int get_wdt_clk(handoff *hoff_ptr)
+/* Extract reference clock from platform clock source */
+uint32_t get_ref_clk(uint32_t pllglob)
 {
-       int main_noc_base_clk, l3_main_free_clk, l4_sys_free_clk;
-       int data32, mdiv, arefclkdiv, ref_clk;
-
-       data32 = mmio_read_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLGLOB);
+       uint32_t arefclkdiv, ref_clk;
+       uint32_t scr_reg;
 
-       switch (CLKMGR_MAINPLL_PLLGLOB_PSRC(data32)) {
-       case CLKMGR_MAINPLL_PLLGLOB_PSRC_EOSC1:
-               ref_clk = clk_source.clk_freq_of_eosc1;
+       switch (CLKMGR_PSRC(pllglob)) {
+       case CLKMGR_PLLGLOB_PSRC_EOSC1:
+               scr_reg = AGX_SYSMGR_CORE(SYSMGR_BOOT_SCRATCH_COLD_1);
+               ref_clk = mmio_read_32(scr_reg);
                break;
-       case CLKMGR_MAINPLL_PLLGLOB_PSRC_INTOSC:
-               ref_clk = clk_source.clk_freq_of_cb_intosc_ls;
+       case CLKMGR_PLLGLOB_PSRC_INTOSC:
+               ref_clk = CLKMGR_INTOSC_HZ;
                break;
-       case CLKMGR_MAINPLL_PLLGLOB_PSRC_F2S:
-               ref_clk = clk_source.clk_freq_of_f2h_free;
+       case CLKMGR_PLLGLOB_PSRC_F2S:
+               scr_reg = AGX_SYSMGR_CORE(SYSMGR_BOOT_SCRATCH_COLD_2);
+               ref_clk = mmio_read_32(scr_reg);
                break;
        default:
                ref_clk = 0;
@@ -281,13 +281,91 @@ int get_wdt_clk(handoff *hoff_ptr)
                break;
        }
 
-       arefclkdiv = CLKMGR_MAINPLL_PLLGLOB_AREFCLKDIV(data32);
-       mdiv = CLKMGR_MAINPLL_PLLM_MDIV(hoff_ptr->main_pll_pllm);
+       arefclkdiv = CLKMGR_PLLGLOB_AREFCLKDIV(pllglob);
+       ref_clk /= arefclkdiv;
+
+       return ref_clk;
+}
+
+/* Calculate clock frequency based on parameter */
+uint32_t get_clk_freq(uint32_t psrc_reg, uint32_t main_pllc, uint32_t per_pllc)
+{
+       uint32_t clk_psrc, mdiv, ref_clk;
+       uint32_t pllm_reg, pllc_reg, pllc_div, pllglob_reg;
+
+       clk_psrc = mmio_read_32(CLKMGR_MAINPLL + psrc_reg);
+
+       switch (CLKMGR_PSRC(clk_psrc)) {
+       case CLKMGR_PSRC_MAIN:
+               pllm_reg = CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLM;
+               pllc_reg = CLKMGR_MAINPLL + main_pllc;
+               pllglob_reg = CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLGLOB;
+               break;
+       case CLKMGR_PSRC_PER:
+               pllm_reg = CLKMGR_PERPLL + CLKMGR_PERPLL_PLLM;
+               pllc_reg = CLKMGR_PERPLL + per_pllc;
+               pllglob_reg = CLKMGR_PERPLL + CLKMGR_PERPLL_PLLGLOB;
+               break;
+       default:
+               return 0;
+       }
+
+       ref_clk = get_ref_clk(mmio_read_32(pllglob_reg));
+       mdiv = CLKMGR_PLLM_MDIV(mmio_read_32(pllm_reg));
+       ref_clk *= mdiv;
+
+       pllc_div = mmio_read_32(pllc_reg) & 0x7ff;
+
+       return ref_clk / pllc_div;
+}
+
+/* Return L3 interconnect clock */
+uint32_t get_l3_clk(void)
+{
+       uint32_t l3_clk;
+
+       l3_clk = get_clk_freq(CLKMGR_MAINPLL_NOCCLK, CLKMGR_MAINPLL_PLLC1,
+                               CLKMGR_PERPLL_PLLC1);
+       return l3_clk;
+}
+
+/* Calculate clock frequency to be used for watchdog timer */
+uint32_t get_wdt_clk(void)
+{
+       uint32_t l3_clk, l4_sys_clk;
+
+       l3_clk = get_l3_clk();
+       l4_sys_clk = l3_clk / 4;
+
+       return l4_sys_clk;
+}
+
+/* Calculate clock frequency to be used for UART driver */
+uint32_t get_uart_clk(void)
+{
+       uint32_t data32, l3_clk, l4_sp_clk;
+
+       l3_clk = get_l3_clk();
+
+       data32 = mmio_read_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_NOCDIV);
+       data32 = (data32 >> 16) & 0x3;
+
+       l4_sp_clk = l3_clk >> data32;
+
+       return l4_sp_clk;
+}
+
+/* Calculate clock frequency to be used for SDMMC driver */
+uint32_t get_mmc_clk(void)
+{
+       uint32_t data32, mmc_clk;
+
+       mmc_clk = get_clk_freq(CLKMGR_ALTERA_SDMMCCTR,
+               CLKMGR_MAINPLL_PLLC3, CLKMGR_PERPLL_PLLC3);
 
-       ref_clk = (ref_clk / arefclkdiv) * mdiv;
-       main_noc_base_clk = ref_clk / (hoff_ptr->main_pll_pllc1 & 0x7ff);
-       l3_main_free_clk = main_noc_base_clk / (hoff_ptr->main_pll_nocclk + 1);
-       l4_sys_free_clk = l3_main_free_clk / 4;
+       data32 = mmio_read_32(CLKMGR_ALTERA + CLKMGR_ALTERA_SDMMCCTR);
+       data32 = (data32 & 0x7ff) + 1;
+       mmc_clk = (mmc_clk / data32) / 4;
 
-       return l4_sys_free_clk;
+       return mmc_clk;
 }
index a13ee495a202b7987c56b77f55e6e2af54dca6e0..c4a03592ea87dc8daef1df5652ae185fe0df3b3c 100644 (file)
@@ -14,7 +14,6 @@
 #include <drivers/console.h>
 #include <drivers/generic_delay_timer.h>
 #include <drivers/ti/uart/uart_16550.h>
-#include <lib/coreboot.h>
 #include <lib/mmio.h>
 #include <plat_private.h>
 #include <plat/common/platform.h>
@@ -62,16 +61,10 @@ void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
 
        params_early_setup(arg1);
 
-#if COREBOOT
-       if (coreboot_serial.type)
-               console_16550_register(coreboot_serial.baseaddr,
-                                      coreboot_serial.input_hertz,
-                                      coreboot_serial.baud,
-                                      &console);
-#else
-       console_16550_register(rockchip_get_uart_base(), PLAT_RK_UART_CLOCK,
-                              PLAT_RK_UART_BAUDRATE, &console);
-#endif
+       if (rockchip_get_uart_base() != 0)
+               console_16550_register(rockchip_get_uart_base(),
+                                      rockchip_get_uart_clock(),
+                                      rockchip_get_uart_baudrate(), &console);
 
        VERBOSE("bl31_setup\n");
 
index 714a8bf9e6f30546d09c59c4cb4131db1e9aebb8..990d1065fd9db797957f42748b9262e6ab1dd730 100644 (file)
@@ -139,6 +139,8 @@ extern uint32_t cpuson_flags[PLATFORM_CORE_COUNT];
 extern const mmap_region_t plat_rk_mmap[];
 
 uint32_t rockchip_get_uart_base(void);
+uint32_t rockchip_get_uart_baudrate(void);
+uint32_t rockchip_get_uart_clock(void);
 
 #endif /* __ASSEMBLER__ */
 
index d0fea4ffa6500dd91d3a69bf539a5fa62fb02e99..8c2e5e911b168d6deadb5b60aa08c211cdfd4f7c 100644 (file)
@@ -26,12 +26,6 @@ static struct bl_aux_gpio_info poweroff_gpio;
 static struct bl_aux_gpio_info suspend_gpio[10];
 uint32_t suspend_gpio_cnt;
 static struct bl_aux_rk_apio_info suspend_apio;
-static uint32_t rk_uart_base = PLAT_RK_UART_BASE;
-
-uint32_t rockchip_get_uart_base(void)
-{
-       return rk_uart_base;
-}
 
 #if COREBOOT
 static int dt_process_fdt(u_register_t param_from_bl2)
@@ -39,6 +33,9 @@ static int dt_process_fdt(u_register_t param_from_bl2)
        return -ENODEV;
 }
 #else
+static uint32_t rk_uart_base = PLAT_RK_UART_BASE;
+static uint32_t rk_uart_baudrate = PLAT_RK_UART_BAUDRATE;
+static uint32_t rk_uart_clock = PLAT_RK_UART_CLOCK;
 static uint8_t fdt_buffer[0x10000];
 
 void *plat_get_fdt(void)
@@ -53,9 +50,12 @@ static void plat_rockchip_dt_process_fdt_uart(void *fdt)
        int node_offset;
        int stdout_path_len;
        const char *stdout_path;
+       const char *separator;
+       const char *baud_start;
        char serial_char;
        int serial_no;
        uint32_t uart_base;
+       uint32_t baud;
 
        node_offset = fdt_path_offset(fdt, path_name);
        if (node_offset < 0)
@@ -68,7 +68,7 @@ static void plat_rockchip_dt_process_fdt_uart(void *fdt)
 
        /*
         * We expect something like:
-        *   "serial0:...""
+        *   "serial0:baudrate"
         */
        if (strncmp("serial", stdout_path, 6) != 0)
                return;
@@ -95,12 +95,39 @@ static void plat_rockchip_dt_process_fdt_uart(void *fdt)
        case 4:
                uart_base = UART4_BASE;
                break;
+#endif
+#ifdef UART5_BASE
+       case 5:
+               uart_base = UART5_BASE;
+               break;
 #endif
        default:
                return;
        }
 
        rk_uart_base = uart_base;
+
+       separator = strchr(stdout_path, ':');
+       if (!separator)
+               return;
+
+       baud = 0;
+       baud_start = separator + 1;
+       while (*baud_start != '\0') {
+               /*
+                * uart binding is <baud>{<parity>{<bits>{...}}}
+                * So the baudrate either is the whole string, or
+                * we end in the parity characters.
+                */
+               if (*baud_start == 'n' || *baud_start == 'o' ||
+                   *baud_start == 'e')
+                       break;
+
+               baud = baud * 10 + (*baud_start - '0');
+               baud_start++;
+       }
+
+       rk_uart_baudrate = baud;
 }
 
 static int dt_process_fdt(u_register_t param_from_bl2)
@@ -118,6 +145,33 @@ static int dt_process_fdt(u_register_t param_from_bl2)
 }
 #endif
 
+uint32_t rockchip_get_uart_base(void)
+{
+#if COREBOOT
+       return coreboot_serial.baseaddr;
+#else
+       return rk_uart_base;
+#endif
+}
+
+uint32_t rockchip_get_uart_baudrate(void)
+{
+#if COREBOOT
+       return coreboot_serial.baud;
+#else
+       return rk_uart_baudrate;
+#endif
+}
+
+uint32_t rockchip_get_uart_clock(void)
+{
+#if COREBOOT
+       return coreboot_serial.input_hertz;
+#else
+       return rk_uart_clock;
+#endif
+}
+
 struct bl_aux_gpio_info *plat_get_rockchip_gpio_reset(void)
 {
        return &rst_gpio;
index 7b1a0b58b73ccc342658aebdb98e3fb877e3188c..6d15075f2a848003fa6de64bf785d988a4c34e1a 100644 (file)
@@ -15,7 +15,6 @@
 #include <drivers/console.h>
 #include <drivers/generic_delay_timer.h>
 #include <drivers/ti/uart/uart_16550.h>
-#include <lib/coreboot.h>
 #include <lib/mmio.h>
 #include <plat_private.h>
 #include <plat/common/platform.h>
@@ -57,16 +56,11 @@ void sp_min_early_platform_setup2(u_register_t arg0, u_register_t arg1,
 
        params_early_setup(arg1);
 
-#if COREBOOT
-       if (coreboot_serial.type)
-               console_16550_register(coreboot_serial.baseaddr,
-                                      coreboot_serial.input_hertz,
-                                      coreboot_serial.baud,
-                                      &console);
-#else
-       console_16550_register(rockchip_get_uart_base(), PLAT_RK_UART_CLOCK,
-                              PLAT_RK_UART_BAUDRATE, &console);
-#endif
+       if (rockchip_get_uart_base() != 0)
+               console_16550_register(rockchip_get_uart_base(),
+                                      rockchip_get_uart_clock(),
+                                      rockchip_get_uart_baudrate(), &console);
+
        VERBOSE("sp_min_setup\n");
 
        bl31_params_parse_helper(arg0, NULL, &bl33_ep_info);
index 021165a4a3cb5954063c296d61a803eaac2b58e3..9b8ccfca63cef3cd7af51dcb68ecdd801ab2ef08 100644 (file)
@@ -54,6 +54,9 @@
 #define UART2_BASE             0xff160000
 #define UART2_SIZE             SIZE_K(64)
 
+#define UART5_BASE             0xff178000
+#define UART5_SIZE             SIZE_K(64)
+
 #define I2C0_BASE              0xff180000
 #define I2C0_SIZE              SIZE_K(64)
 
index a6b59736019241e26db3e30edb5fc37bd0f6d369..30941fd0771926687c4d36e5a8eae9a9ce605062 100644 (file)
@@ -1125,32 +1125,41 @@ static struct uart_debug uart_save;
 
 void suspend_uart(void)
 {
-       uart_save.uart_lcr = mmio_read_32(PLAT_RK_UART_BASE + UART_LCR);
-       uart_save.uart_ier = mmio_read_32(PLAT_RK_UART_BASE + UART_IER);
-       uart_save.uart_mcr = mmio_read_32(PLAT_RK_UART_BASE + UART_MCR);
-       mmio_write_32(PLAT_RK_UART_BASE + UART_LCR,
+       uint32_t uart_base = rockchip_get_uart_base();
+
+       if (uart_base == 0)
+               return;
+
+       uart_save.uart_lcr = mmio_read_32(uart_base + UART_LCR);
+       uart_save.uart_ier = mmio_read_32(uart_base + UART_IER);
+       uart_save.uart_mcr = mmio_read_32(uart_base + UART_MCR);
+       mmio_write_32(uart_base + UART_LCR,
                      uart_save.uart_lcr | UARTLCR_DLAB);
-       uart_save.uart_dll = mmio_read_32(PLAT_RK_UART_BASE + UART_DLL);
-       uart_save.uart_dlh = mmio_read_32(PLAT_RK_UART_BASE + UART_DLH);
-       mmio_write_32(PLAT_RK_UART_BASE + UART_LCR, uart_save.uart_lcr);
+       uart_save.uart_dll = mmio_read_32(uart_base + UART_DLL);
+       uart_save.uart_dlh = mmio_read_32(uart_base + UART_DLH);
+       mmio_write_32(uart_base + UART_LCR, uart_save.uart_lcr);
 }
 
 void resume_uart(void)
 {
+       uint32_t uart_base = rockchip_get_uart_base();
        uint32_t uart_lcr;
 
-       mmio_write_32(PLAT_RK_UART_BASE + UARTSRR,
+       if (uart_base == 0)
+               return;
+
+       mmio_write_32(uart_base + UARTSRR,
                      XMIT_FIFO_RESET | RCVR_FIFO_RESET | UART_RESET);
 
-       uart_lcr = mmio_read_32(PLAT_RK_UART_BASE + UART_LCR);
-       mmio_write_32(PLAT_RK_UART_BASE + UART_MCR, DIAGNOSTIC_MODE);
-       mmio_write_32(PLAT_RK_UART_BASE + UART_LCR, uart_lcr | UARTLCR_DLAB);
-       mmio_write_32(PLAT_RK_UART_BASE + UART_DLL, uart_save.uart_dll);
-       mmio_write_32(PLAT_RK_UART_BASE + UART_DLH, uart_save.uart_dlh);
-       mmio_write_32(PLAT_RK_UART_BASE + UART_LCR, uart_save.uart_lcr);
-       mmio_write_32(PLAT_RK_UART_BASE + UART_IER, uart_save.uart_ier);
-       mmio_write_32(PLAT_RK_UART_BASE + UART_FCR, UARTFCR_FIFOEN);
-       mmio_write_32(PLAT_RK_UART_BASE + UART_MCR, uart_save.uart_mcr);
+       uart_lcr = mmio_read_32(uart_base + UART_LCR);
+       mmio_write_32(uart_base + UART_MCR, DIAGNOSTIC_MODE);
+       mmio_write_32(uart_base + UART_LCR, uart_lcr | UARTLCR_DLAB);
+       mmio_write_32(uart_base + UART_DLL, uart_save.uart_dll);
+       mmio_write_32(uart_base + UART_DLH, uart_save.uart_dlh);
+       mmio_write_32(uart_base + UART_LCR, uart_save.uart_lcr);
+       mmio_write_32(uart_base + UART_IER, uart_save.uart_ier);
+       mmio_write_32(uart_base + UART_FCR, UARTFCR_FIFOEN);
+       mmio_write_32(uart_base + UART_MCR, uart_save.uart_mcr);
 }
 
 void save_usbphy(void)
index b1b21751f1a7e1e75e8234e89793286cd66057ec..643b0542421f56af6d8151acf5192a543fc55d39 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -13,3 +13,6 @@ SPD_SOURCES           :=      services/spd/opteed/opteed_common.c     \
                                services/spd/opteed/opteed_pm.c
 
 NEED_BL32              :=      yes
+
+# required so that optee code can control access to the timer registers
+NS_TIMER_SWITCH                :=      1
index 3e0c9496fce0244a63663f572c0d7e1d34e430f7..79398ba151e03a13357ad15ba0a4be4ec8c6d62c 100644 (file)
@@ -38,6 +38,8 @@ int spm_response_add(uint16_t client_id, uint16_t handle, uint32_t token,
                struct sprt_response *resp = &(responses[i]);
 
                if ((resp->is_valid == 1) && (resp->token == token)) {
+                       spin_unlock(&responses_lock);
+
                        return -1;
                }
        }