Merge branch '2019-05-19-master-imports'
[oweals/u-boot.git] / arch / arm / cpu / armv8 / fsl-layerscape / ppa.c
index 26c47a183c668c4f8754d7727230704b10646b37..d391f93041528b7591baafaf4162abfe70def8b2 100644 (file)
@@ -1,7 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2016 NXP Semiconductor, Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 #include <common.h>
 #include <malloc.h>
@@ -32,8 +31,10 @@ DECLARE_GLOBAL_DATA_PTR;
 
 int ppa_init(void)
 {
+       unsigned int el = current_el();
        void *ppa_fit_addr;
        u32 *boot_loc_ptr_l, *boot_loc_ptr_h;
+       u32 *loadable_l, *loadable_h;
        int ret;
 
 #ifdef CONFIG_CHAIN_OF_TRUST
@@ -45,6 +46,12 @@ int ppa_init(void)
 #endif
 #endif
 
+       /* Skip if running at lower exception level */
+       if (el < 3) {
+               debug("Skipping PPA init, running at EL%d\n", el);
+               return 0;
+       }
+
 #ifdef CONFIG_SYS_LS_PPA_FW_IN_XIP
        ppa_fit_addr = (void *)CONFIG_SYS_LS_PPA_FW_ADDR;
        debug("%s: PPA image load from XIP\n", __func__);
@@ -92,7 +99,7 @@ int ppa_init(void)
        cnt = DIV_ROUND_UP(fdt_header_len, 512);
        debug("%s: MMC read PPA FIT header: dev # %u, block # %u, count %u\n",
              __func__, dev, blk, cnt);
-       ret = mmc->block_dev.block_read(&mmc->block_dev, blk, cnt, fitp);
+       ret = blk_dread(mmc_get_blk_desc(mmc), blk, cnt, fitp);
        if (ret != cnt) {
                free(fitp);
                printf("MMC/SD read of PPA FIT header at offset 0x%x failed\n",
@@ -100,9 +107,6 @@ int ppa_init(void)
                return -EIO;
        }
 
-       /* flush cache after read */
-       flush_cache((ulong)fitp, cnt * 512);
-
        ret = fdt_check_header(fitp);
        if (ret) {
                free(fitp);
@@ -119,7 +123,7 @@ int ppa_init(void)
 
        blk = CONFIG_SYS_LS_PPA_ESBC_ADDR >> 9;
        cnt = DIV_ROUND_UP(CONFIG_LS_PPA_ESBC_HDR_SIZE, 512);
-       ret = mmc->block_dev.block_read(&mmc->block_dev, blk, cnt, ppa_hdr_ddr);
+       ret = blk_dread(mmc_get_blk_desc(mmc), blk, cnt, ppa_hdr_ddr);
        if (ret != cnt) {
                free(ppa_hdr_ddr);
                printf("MMC/SD read of PPA header failed\n");
@@ -127,9 +131,6 @@ int ppa_init(void)
        }
        debug("Read PPA header to 0x%p\n", ppa_hdr_ddr);
 
-       /* flush cache after read */
-       flush_cache((ulong)ppa_hdr_ddr, cnt * 512);
-
        ppa_esbc_hdr = (uintptr_t)ppa_hdr_ddr;
 #endif
 
@@ -148,8 +149,7 @@ int ppa_init(void)
        cnt = DIV_ROUND_UP(fw_length, 512);
        debug("%s: MMC read PPA FIT image: dev # %u, block # %u, count %u\n",
              __func__, dev, blk, cnt);
-       ret = mmc->block_dev.block_read(&mmc->block_dev,
-                                       blk, cnt, ppa_fit_addr);
+       ret = blk_dread(mmc_get_blk_desc(mmc), blk, cnt, ppa_fit_addr);
        if (ret != cnt) {
                free(ppa_fit_addr);
                printf("MMC/SD read of PPA FIT header at offset 0x%x failed\n",
@@ -157,17 +157,15 @@ int ppa_init(void)
                return -EIO;
        }
 
-       /* flush cache after read */
-       flush_cache((ulong)ppa_fit_addr, cnt * 512);
-
 #elif defined(CONFIG_SYS_LS_PPA_FW_IN_NAND)
        struct fdt_header fit;
 
        debug("%s: PPA image load from NAND\n", __func__);
 
        nand_init();
-       ret = nand_read(nand_info[0], (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
-                      &fdt_header_len, (u_char *)&fit);
+       ret = nand_read(get_nand_dev_by_index(0),
+                       (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
+                       &fdt_header_len, (u_char *)&fit);
        if (ret == -EUCLEAN) {
                printf("NAND read of PPA FIT header at offset 0x%x failed\n",
                       CONFIG_SYS_LS_PPA_FW_ADDR);
@@ -189,8 +187,9 @@ int ppa_init(void)
 
        fw_length = CONFIG_LS_PPA_ESBC_HDR_SIZE;
 
-       ret = nand_read(nand_info[0], (loff_t)CONFIG_SYS_LS_PPA_ESBC_ADDR,
-                      &fw_length, (u_char *)ppa_hdr_ddr);
+       ret = nand_read(get_nand_dev_by_index(0),
+                       (loff_t)CONFIG_SYS_LS_PPA_ESBC_ADDR,
+                       &fw_length, (u_char *)ppa_hdr_ddr);
        if (ret == -EUCLEAN) {
                free(ppa_hdr_ddr);
                printf("NAND read of PPA firmware at offset 0x%x failed\n",
@@ -199,9 +198,6 @@ int ppa_init(void)
        }
        debug("Read PPA header to 0x%p\n", ppa_hdr_ddr);
 
-       /* flush cache after read */
-       flush_cache((ulong)ppa_hdr_ddr, fw_length);
-
        ppa_esbc_hdr = (uintptr_t)ppa_hdr_ddr;
 #endif
 
@@ -214,17 +210,15 @@ int ppa_init(void)
                return -ENOMEM;
        }
 
-       ret = nand_read(nand_info[0], (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
-                      &fw_length, (u_char *)ppa_fit_addr);
+       ret = nand_read(get_nand_dev_by_index(0),
+                       (loff_t)CONFIG_SYS_LS_PPA_FW_ADDR,
+                       &fw_length, (u_char *)ppa_fit_addr);
        if (ret == -EUCLEAN) {
                free(ppa_fit_addr);
                printf("NAND read of PPA firmware at offset 0x%x failed\n",
                       CONFIG_SYS_LS_PPA_FW_ADDR);
                return -EIO;
        }
-
-       /* flush cache after read */
-       flush_cache((ulong)ppa_fit_addr, fw_length);
 #else
 #error "No CONFIG_SYS_LS_PPA_FW_IN_xxx defined"
 #endif
@@ -245,9 +239,9 @@ int ppa_init(void)
                                           PPA_KEY_HASH,
                                           &ppa_img_addr);
                if (ret != 0)
-                       printf("PPA validation failed\n");
+                       printf("SEC firmware(s) validation failed\n");
                else
-                       printf("PPA validation Successful\n");
+                       printf("SEC firmware(s) validation Successful\n");
        }
 #if defined(CONFIG_SYS_LS_PPA_FW_IN_MMC) || \
        defined(CONFIG_SYS_LS_PPA_FW_IN_NAND)
@@ -259,15 +253,24 @@ int ppa_init(void)
        struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
        boot_loc_ptr_l = &gur->bootlocptrl;
        boot_loc_ptr_h = &gur->bootlocptrh;
+
+       /* Assign addresses to loadable ptrs */
+       loadable_l = &gur->scratchrw[4];
+       loadable_h = &gur->scratchrw[5];
 #elif defined(CONFIG_FSL_LSCH2)
        struct ccsr_scfg __iomem *scfg = (void *)(CONFIG_SYS_FSL_SCFG_ADDR);
        boot_loc_ptr_l = &scfg->scratchrw[1];
        boot_loc_ptr_h = &scfg->scratchrw[0];
+
+       /* Assign addresses to loadable ptrs */
+       loadable_l = &scfg->scratchrw[2];
+       loadable_h = &scfg->scratchrw[3];
 #endif
 
        debug("fsl-ppa: boot_loc_ptr_l = 0x%p, boot_loc_ptr_h =0x%p\n",
              boot_loc_ptr_l, boot_loc_ptr_h);
-       ret = sec_firmware_init(ppa_fit_addr, boot_loc_ptr_l, boot_loc_ptr_h);
+       ret = sec_firmware_init(ppa_fit_addr, boot_loc_ptr_l, boot_loc_ptr_h,
+                               loadable_l, loadable_h);
 
 #if defined(CONFIG_SYS_LS_PPA_FW_IN_MMC) || \
        defined(CONFIG_SYS_LS_PPA_FW_IN_NAND)