]> git.sur5r.net Git - u-boot/blobdiff - arch/powerpc/cpu/mpc8xxx/law.c
SPDX: Convert all of our single license tags to Linux Kernel style
[u-boot] / arch / powerpc / cpu / mpc8xxx / law.c
index 55ee12573f711bd94cec7aa71ae7a27a23aaef43..30f35e25e3e21967957cdae746ac8eb85489c8e4 100644 (file)
@@ -1,16 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2008-2011 Freescale Semiconductor, Inc.
  *
  * (C) Copyright 2000
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <linux/compiler.h>
 #include <asm/fsl_law.h>
 #include <asm/io.h>
+#include <linux/log2.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -187,7 +187,7 @@ int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id)
        if (start == 0)
                start_align = 1ull << (LAW_SIZE_32G + 1);
        else
-               start_align = 1ull << (ffs64(start) - 1);
+               start_align = 1ull << (__ffs64(start));
        law_sz = min(start_align, sz);
        law_sz_enc = __ilog2_u64(law_sz) - 1;
 
@@ -202,7 +202,7 @@ int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id)
        if (sz) {
                start += law_sz;
 
-               start_align = 1ull << (ffs64(start) - 1);
+               start_align = 1ull << (__ffs64(start));
                law_sz = min(start_align, sz);
                law_sz_enc = __ilog2_u64(law_sz) - 1;
 
@@ -221,6 +221,32 @@ int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id)
 }
 #endif /* not SPL */
 
+void disable_non_ddr_laws(void)
+{
+       int i;
+       int id;
+       for (i = 0; i < FSL_HW_NUM_LAWS; i++) {
+               u32 lawar = in_be32(LAWAR_ADDR(i));
+
+               if (lawar & LAW_EN) {
+                       id = (lawar & ~LAW_EN) >> 20;
+                       switch (id) {
+                       case LAW_TRGT_IF_DDR_1:
+                       case LAW_TRGT_IF_DDR_2:
+                       case LAW_TRGT_IF_DDR_3:
+                       case LAW_TRGT_IF_DDR_4:
+                       case LAW_TRGT_IF_DDR_INTRLV:
+                       case LAW_TRGT_IF_DDR_INTLV_34:
+                       case LAW_TRGT_IF_DDR_INTLV_123:
+                       case LAW_TRGT_IF_DDR_INTLV_1234:
+                                               continue;
+                       default:
+                                               disable_law(i);
+                       }
+               }
+       }
+}
+
 void init_laws(void)
 {
        int i;
@@ -242,6 +268,13 @@ void init_laws(void)
        disable_law(0);
 #endif
 
+#if !defined(CONFIG_SECURE_BOOT)
+       /*
+        * if any non DDR LAWs has been created earlier, remove them before
+        * LAW table is parsed.
+       */
+       disable_non_ddr_laws();
+#endif
 
        /*
         * Any LAWs that were set up before we booted assume they are meant to
@@ -254,15 +287,6 @@ void init_laws(void)
                        gd->arch.used_laws |= (1 << i);
        }
 
-#if (defined(CONFIG_NAND_U_BOOT) && !defined(CONFIG_NAND_SPL)) || \
-       (defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD))
-       /*
-        * in SPL boot we've already parsed the law_table and setup those LAWs
-        * so don't do it again.
-        */
-       return;
-#endif
-
        for (i = 0; i < num_law_entries; i++) {
                if (law_table[i].index == -1)
                        set_next_law(law_table[i].addr, law_table[i].size,