Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 2 | /* |
Poonam Aggrwal | 2ba3ee0 | 2011-01-13 21:39:27 +0530 | [diff] [blame] | 3 | * Copyright 2008-2011 Freescale Semiconductor, Inc. |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 4 | * |
| 5 | * (C) Copyright 2000 |
| 6 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 7 | */ |
| 8 | |
Simon Glass | 1ab1692 | 2022-07-31 12:28:48 -0600 | [diff] [blame] | 9 | #include <display_options.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 10 | #include <asm/bitops.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Kumar Gala | 6a74ade | 2011-02-03 09:02:13 -0600 | [diff] [blame] | 12 | #include <linux/compiler.h> |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 13 | #include <asm/fsl_law.h> |
| 14 | #include <asm/io.h> |
Fabio Estevam | 1a03a7e | 2015-11-05 12:43:40 -0200 | [diff] [blame] | 15 | #include <linux/log2.h> |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 16 | |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Kumar Gala | fe13711 | 2011-01-19 03:05:26 -0600 | [diff] [blame] | 19 | #define FSL_HW_NUM_LAWS CONFIG_SYS_FSL_NUM_LAWS |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 20 | |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 21 | #ifdef CONFIG_FSL_CORENET |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 22 | #define LAW_BASE (CFG_SYS_FSL_CORENET_CCM_ADDR) |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 23 | #define LAWAR_ADDR(x) (&((ccsr_local_t *)LAW_BASE)->law[x].lawar) |
| 24 | #define LAWBARH_ADDR(x) (&((ccsr_local_t *)LAW_BASE)->law[x].lawbarh) |
| 25 | #define LAWBARL_ADDR(x) (&((ccsr_local_t *)LAW_BASE)->law[x].lawbarl) |
| 26 | #define LAWBAR_SHIFT 0 |
| 27 | #else |
| 28 | #define LAW_BASE (CONFIG_SYS_IMMR + 0xc08) |
| 29 | #define LAWAR_ADDR(x) ((u32 *)LAW_BASE + 8 * x + 2) |
| 30 | #define LAWBAR_ADDR(x) ((u32 *)LAW_BASE + 8 * x) |
| 31 | #define LAWBAR_SHIFT 12 |
| 32 | #endif |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 33 | |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 34 | |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 35 | static inline phys_addr_t get_law_base_addr(int idx) |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 36 | { |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 37 | #ifdef CONFIG_FSL_CORENET |
| 38 | return (phys_addr_t) |
| 39 | ((u64)in_be32(LAWBARH_ADDR(idx)) << 32) | |
| 40 | in_be32(LAWBARL_ADDR(idx)); |
| 41 | #else |
| 42 | return (phys_addr_t)in_be32(LAWBAR_ADDR(idx)) << LAWBAR_SHIFT; |
| 43 | #endif |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 44 | } |
| 45 | |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 46 | static inline void set_law_base_addr(int idx, phys_addr_t addr) |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 47 | { |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 48 | #ifdef CONFIG_FSL_CORENET |
| 49 | out_be32(LAWBARL_ADDR(idx), addr & 0xffffffff); |
| 50 | out_be32(LAWBARH_ADDR(idx), (u64)addr >> 32); |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 51 | #else |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 52 | out_be32(LAWBAR_ADDR(idx), addr >> LAWBAR_SHIFT); |
| 53 | #endif |
| 54 | } |
| 55 | |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 56 | void set_law(u8 idx, phys_addr_t addr, enum law_size sz, enum law_trgt_if id) |
| 57 | { |
Simon Glass | c6622d6 | 2012-12-13 20:48:51 +0000 | [diff] [blame] | 58 | gd->arch.used_laws |= (1 << idx); |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 59 | |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 60 | out_be32(LAWAR_ADDR(idx), 0); |
| 61 | set_law_base_addr(idx, addr); |
| 62 | out_be32(LAWAR_ADDR(idx), LAW_EN | ((u32)id << 20) | (u32)sz); |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 63 | |
Timur Tabi | 52fa71f | 2009-09-04 17:05:24 -0500 | [diff] [blame] | 64 | /* Read back so that we sync the writes */ |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 65 | in_be32(LAWAR_ADDR(idx)); |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 66 | } |
| 67 | |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 68 | void disable_law(u8 idx) |
| 69 | { |
Simon Glass | c6622d6 | 2012-12-13 20:48:51 +0000 | [diff] [blame] | 70 | gd->arch.used_laws &= ~(1 << idx); |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 71 | |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 72 | out_be32(LAWAR_ADDR(idx), 0); |
| 73 | set_law_base_addr(idx, 0); |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 74 | |
| 75 | /* Read back so that we sync the writes */ |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 76 | in_be32(LAWAR_ADDR(idx)); |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 77 | |
| 78 | return; |
| 79 | } |
| 80 | |
Ying Zhang | ffc86e2 | 2013-08-16 15:16:10 +0800 | [diff] [blame] | 81 | #if !defined(CONFIG_NAND_SPL) && \ |
Tom Rini | 6b15c16 | 2022-05-13 12:26:35 -0400 | [diff] [blame] | 82 | (!defined(CONFIG_SPL_BUILD) || !CONFIG_IS_ENABLED(INIT_MINIMAL)) |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 83 | static int get_law_entry(u8 i, struct law_entry *e) |
| 84 | { |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 85 | u32 lawar; |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 86 | |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 87 | lawar = in_be32(LAWAR_ADDR(i)); |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 88 | |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 89 | if (!(lawar & LAW_EN)) |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 90 | return 0; |
| 91 | |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 92 | e->addr = get_law_base_addr(i); |
| 93 | e->size = lawar & 0x3f; |
| 94 | e->trgt_id = (lawar >> 20) & 0xff; |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 95 | |
| 96 | return 1; |
| 97 | } |
| 98 | #endif |
| 99 | |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 100 | int set_next_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id) |
| 101 | { |
Simon Glass | c6622d6 | 2012-12-13 20:48:51 +0000 | [diff] [blame] | 102 | u32 idx = ffz(gd->arch.used_laws); |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 103 | |
| 104 | if (idx >= FSL_HW_NUM_LAWS) |
| 105 | return -1; |
| 106 | |
| 107 | set_law(idx, addr, sz, id); |
| 108 | |
| 109 | return idx; |
| 110 | } |
| 111 | |
Ying Zhang | ffc86e2 | 2013-08-16 15:16:10 +0800 | [diff] [blame] | 112 | #if !defined(CONFIG_NAND_SPL) && \ |
Tom Rini | 6b15c16 | 2022-05-13 12:26:35 -0400 | [diff] [blame] | 113 | (!defined(CONFIG_SPL_BUILD) || !CONFIG_IS_ENABLED(INIT_MINIMAL)) |
Kumar Gala | a9abb00 | 2008-06-10 16:16:02 -0500 | [diff] [blame] | 114 | int set_last_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id) |
| 115 | { |
| 116 | u32 idx; |
| 117 | |
| 118 | /* we have no LAWs free */ |
Simon Glass | c6622d6 | 2012-12-13 20:48:51 +0000 | [diff] [blame] | 119 | if (gd->arch.used_laws == -1) |
Kumar Gala | a9abb00 | 2008-06-10 16:16:02 -0500 | [diff] [blame] | 120 | return -1; |
| 121 | |
| 122 | /* grab the last free law */ |
Simon Glass | c6622d6 | 2012-12-13 20:48:51 +0000 | [diff] [blame] | 123 | idx = __ilog2(~(gd->arch.used_laws)); |
Kumar Gala | a9abb00 | 2008-06-10 16:16:02 -0500 | [diff] [blame] | 124 | |
| 125 | if (idx >= FSL_HW_NUM_LAWS) |
| 126 | return -1; |
| 127 | |
| 128 | set_law(idx, addr, sz, id); |
| 129 | |
| 130 | return idx; |
| 131 | } |
| 132 | |
Pali Rohár | f40662d | 2024-06-06 18:33:23 +0200 | [diff] [blame^] | 133 | struct law_entry find_law_by_addr_id(phys_addr_t addr, enum law_trgt_if id) |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 134 | { |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 135 | struct law_entry entry; |
| 136 | int i; |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 137 | |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 138 | entry.index = -1; |
| 139 | entry.addr = 0; |
| 140 | entry.size = 0; |
| 141 | entry.trgt_id = 0; |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 142 | |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 143 | for (i = 0; i < FSL_HW_NUM_LAWS; i++) { |
| 144 | u64 upper; |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 145 | |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 146 | if (!get_law_entry(i, &entry)) |
| 147 | continue; |
| 148 | |
Pali Rohár | f40662d | 2024-06-06 18:33:23 +0200 | [diff] [blame^] | 149 | if (id != -1 && id != entry.trgt_id) |
| 150 | continue; |
| 151 | |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 152 | upper = entry.addr + (2ull << entry.size); |
| 153 | if ((addr >= entry.addr) && (addr < upper)) { |
| 154 | entry.index = i; |
| 155 | break; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | return entry; |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 160 | } |
| 161 | |
Becky Bruce | 2a15f75 | 2008-01-23 16:31:05 -0600 | [diff] [blame] | 162 | void print_laws(void) |
| 163 | { |
Becky Bruce | 2a15f75 | 2008-01-23 16:31:05 -0600 | [diff] [blame] | 164 | int i; |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 165 | u32 lawar; |
Becky Bruce | 2a15f75 | 2008-01-23 16:31:05 -0600 | [diff] [blame] | 166 | |
| 167 | printf("\nLocal Access Window Configuration\n"); |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 168 | for (i = 0; i < FSL_HW_NUM_LAWS; i++) { |
| 169 | lawar = in_be32(LAWAR_ADDR(i)); |
Becky Bruce | d58f8d5 | 2010-06-17 11:37:24 -0500 | [diff] [blame] | 170 | #ifdef CONFIG_FSL_CORENET |
| 171 | printf("LAWBARH%02d: 0x%08x LAWBARL%02d: 0x%08x", |
| 172 | i, in_be32(LAWBARH_ADDR(i)), |
| 173 | i, in_be32(LAWBARL_ADDR(i))); |
| 174 | #else |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 175 | printf("LAWBAR%02d: 0x%08x", i, in_be32(LAWBAR_ADDR(i))); |
Becky Bruce | d58f8d5 | 2010-06-17 11:37:24 -0500 | [diff] [blame] | 176 | #endif |
Kumar Gala | 978bb79 | 2011-02-12 15:34:08 -0600 | [diff] [blame] | 177 | printf(" LAWAR%02d: 0x%08x\n", i, lawar); |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 178 | printf("\t(EN: %d TGT: 0x%02x SIZE: ", |
| 179 | (lawar & LAW_EN) ? 1 : 0, (lawar >> 20) & 0xff); |
| 180 | print_size(lawar_size(lawar), ")\n"); |
Becky Bruce | 2a15f75 | 2008-01-23 16:31:05 -0600 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | return; |
| 184 | } |
| 185 | |
Kumar Gala | 61ed053 | 2008-08-26 15:01:28 -0500 | [diff] [blame] | 186 | /* use up to 2 LAWs for DDR, used the last available LAWs */ |
| 187 | int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id) |
| 188 | { |
| 189 | u64 start_align, law_sz; |
| 190 | int law_sz_enc; |
| 191 | |
| 192 | if (start == 0) |
| 193 | start_align = 1ull << (LAW_SIZE_32G + 1); |
| 194 | else |
Ashish kumar | e7d15f6 | 2016-01-22 15:50:10 +0530 | [diff] [blame] | 195 | start_align = 1ull << (__ffs64(start)); |
Kumar Gala | 61ed053 | 2008-08-26 15:01:28 -0500 | [diff] [blame] | 196 | law_sz = min(start_align, sz); |
| 197 | law_sz_enc = __ilog2_u64(law_sz) - 1; |
| 198 | |
| 199 | if (set_last_law(start, law_sz_enc, id) < 0) |
| 200 | return -1; |
| 201 | |
Kumar Gala | 894cc88 | 2009-04-04 10:21:02 -0500 | [diff] [blame] | 202 | /* recalculate size based on what was actually covered by the law */ |
| 203 | law_sz = 1ull << __ilog2_u64(law_sz); |
| 204 | |
Kumar Gala | 61ed053 | 2008-08-26 15:01:28 -0500 | [diff] [blame] | 205 | /* do we still have anything to map */ |
| 206 | sz = sz - law_sz; |
| 207 | if (sz) { |
| 208 | start += law_sz; |
| 209 | |
Ashish kumar | e7d15f6 | 2016-01-22 15:50:10 +0530 | [diff] [blame] | 210 | start_align = 1ull << (__ffs64(start)); |
Kumar Gala | 61ed053 | 2008-08-26 15:01:28 -0500 | [diff] [blame] | 211 | law_sz = min(start_align, sz); |
| 212 | law_sz_enc = __ilog2_u64(law_sz) - 1; |
| 213 | |
| 214 | if (set_last_law(start, law_sz_enc, id) < 0) |
| 215 | return -1; |
| 216 | } else { |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | /* do we still have anything to map */ |
| 221 | sz = sz - law_sz; |
| 222 | if (sz) |
| 223 | return 1; |
| 224 | |
| 225 | return 0; |
| 226 | } |
Scott Wood | 095b712 | 2012-09-20 19:02:18 -0500 | [diff] [blame] | 227 | #endif /* not SPL */ |
Kumar Gala | 61ed053 | 2008-08-26 15:01:28 -0500 | [diff] [blame] | 228 | |
Prabhakar Kushwaha | 21a2590 | 2014-04-08 19:12:46 +0530 | [diff] [blame] | 229 | void disable_non_ddr_laws(void) |
| 230 | { |
| 231 | int i; |
| 232 | int id; |
| 233 | for (i = 0; i < FSL_HW_NUM_LAWS; i++) { |
| 234 | u32 lawar = in_be32(LAWAR_ADDR(i)); |
| 235 | |
| 236 | if (lawar & LAW_EN) { |
| 237 | id = (lawar & ~LAW_EN) >> 20; |
| 238 | switch (id) { |
| 239 | case LAW_TRGT_IF_DDR_1: |
| 240 | case LAW_TRGT_IF_DDR_2: |
| 241 | case LAW_TRGT_IF_DDR_3: |
| 242 | case LAW_TRGT_IF_DDR_4: |
| 243 | case LAW_TRGT_IF_DDR_INTRLV: |
| 244 | case LAW_TRGT_IF_DDR_INTLV_34: |
| 245 | case LAW_TRGT_IF_DDR_INTLV_123: |
| 246 | case LAW_TRGT_IF_DDR_INTLV_1234: |
| 247 | continue; |
| 248 | default: |
| 249 | disable_law(i); |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 255 | void init_laws(void) |
| 256 | { |
| 257 | int i; |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 258 | |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 259 | #if FSL_HW_NUM_LAWS < 32 |
Simon Glass | c6622d6 | 2012-12-13 20:48:51 +0000 | [diff] [blame] | 260 | gd->arch.used_laws = ~((1 << FSL_HW_NUM_LAWS) - 1); |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 261 | #elif FSL_HW_NUM_LAWS == 32 |
Simon Glass | c6622d6 | 2012-12-13 20:48:51 +0000 | [diff] [blame] | 262 | gd->arch.used_laws = 0; |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 263 | #else |
| 264 | #error FSL_HW_NUM_LAWS can not be greater than 32 w/o code changes |
| 265 | #endif |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 266 | |
Udit Agarwal | d2dd2f7 | 2019-11-07 16:11:39 +0000 | [diff] [blame] | 267 | #if defined(CONFIG_NXP_ESBC) && defined(CONFIG_E500) && \ |
Aneesh Bansal | 060384a | 2014-03-11 23:21:45 +0530 | [diff] [blame] | 268 | !defined(CONFIG_E500MC) |
| 269 | /* ISBC (Boot ROM) creates a LAW 0 entry for non PBL platforms, |
| 270 | * which is not disabled before transferring the control to uboot. |
| 271 | * Disable the LAW 0 entry here. |
| 272 | */ |
| 273 | disable_law(0); |
| 274 | #endif |
| 275 | |
Udit Agarwal | d2dd2f7 | 2019-11-07 16:11:39 +0000 | [diff] [blame] | 276 | #if !defined(CONFIG_NXP_ESBC) |
Prabhakar Kushwaha | 21a2590 | 2014-04-08 19:12:46 +0530 | [diff] [blame] | 277 | /* |
| 278 | * if any non DDR LAWs has been created earlier, remove them before |
| 279 | * LAW table is parsed. |
| 280 | */ |
| 281 | disable_non_ddr_laws(); |
| 282 | #endif |
Aneesh Bansal | 060384a | 2014-03-11 23:21:45 +0530 | [diff] [blame] | 283 | |
Wolfgang Denk | 80f7021 | 2011-05-19 22:21:41 +0200 | [diff] [blame] | 284 | /* |
Kumar Gala | 6a74ade | 2011-02-03 09:02:13 -0600 | [diff] [blame] | 285 | * Any LAWs that were set up before we booted assume they are meant to |
| 286 | * be around and mark them used. |
| 287 | */ |
| 288 | for (i = 0; i < FSL_HW_NUM_LAWS; i++) { |
| 289 | u32 lawar = in_be32(LAWAR_ADDR(i)); |
Wolfgang Denk | 80f7021 | 2011-05-19 22:21:41 +0200 | [diff] [blame] | 290 | |
Kumar Gala | 6a74ade | 2011-02-03 09:02:13 -0600 | [diff] [blame] | 291 | if (lawar & LAW_EN) |
Simon Glass | c6622d6 | 2012-12-13 20:48:51 +0000 | [diff] [blame] | 292 | gd->arch.used_laws |= (1 << i); |
Kumar Gala | 6a74ade | 2011-02-03 09:02:13 -0600 | [diff] [blame] | 293 | } |
| 294 | |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 295 | for (i = 0; i < num_law_entries; i++) { |
| 296 | if (law_table[i].index == -1) |
| 297 | set_next_law(law_table[i].addr, law_table[i].size, |
| 298 | law_table[i].trgt_id); |
| 299 | else |
| 300 | set_law(law_table[i].index, law_table[i].addr, |
| 301 | law_table[i].size, law_table[i].trgt_id); |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 302 | } |
| 303 | |
Liu Gang | b4611ee | 2012-08-09 05:10:03 +0000 | [diff] [blame] | 304 | #ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE |
Liu Gang | e86e1a3 | 2012-08-09 05:10:00 +0000 | [diff] [blame] | 305 | /* check RCW to get which port is used for boot */ |
Tom Rini | d5c3bf2 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 306 | ccsr_gur_t *gur = (void *)CFG_SYS_MPC85xx_GUTS_ADDR; |
Liu Gang | e86e1a3 | 2012-08-09 05:10:00 +0000 | [diff] [blame] | 307 | u32 bootloc = in_be32(&gur->rcwsr[6]); |
Liu Gang | b4611ee | 2012-08-09 05:10:03 +0000 | [diff] [blame] | 308 | /* |
| 309 | * in SRIO or PCIE boot we need to set specail LAWs for |
| 310 | * SRIO or PCIE interfaces. |
| 311 | */ |
Liu Gang | e86e1a3 | 2012-08-09 05:10:00 +0000 | [diff] [blame] | 312 | switch ((bootloc & FSL_CORENET_RCWSR6_BOOT_LOC) >> 23) { |
Liu Gang | b4611ee | 2012-08-09 05:10:03 +0000 | [diff] [blame] | 313 | case 0x0: /* boot from PCIE1 */ |
Tom Rini | 40eb556 | 2022-11-16 13:10:40 -0500 | [diff] [blame] | 314 | set_next_law(CFG_SYS_SRIO_PCIE_BOOT_SLAVE_ADDR_PHYS, |
Liu Gang | b4611ee | 2012-08-09 05:10:03 +0000 | [diff] [blame] | 315 | LAW_SIZE_1M, |
| 316 | LAW_TRGT_IF_PCIE_1); |
Tom Rini | 40eb556 | 2022-11-16 13:10:40 -0500 | [diff] [blame] | 317 | set_next_law(CFG_SYS_SRIO_PCIE_BOOT_UCODE_ENV_ADDR_PHYS, |
Liu Gang | b4611ee | 2012-08-09 05:10:03 +0000 | [diff] [blame] | 318 | LAW_SIZE_1M, |
| 319 | LAW_TRGT_IF_PCIE_1); |
| 320 | break; |
| 321 | case 0x1: /* boot from PCIE2 */ |
Tom Rini | 40eb556 | 2022-11-16 13:10:40 -0500 | [diff] [blame] | 322 | set_next_law(CFG_SYS_SRIO_PCIE_BOOT_SLAVE_ADDR_PHYS, |
Liu Gang | b4611ee | 2012-08-09 05:10:03 +0000 | [diff] [blame] | 323 | LAW_SIZE_1M, |
| 324 | LAW_TRGT_IF_PCIE_2); |
Tom Rini | 40eb556 | 2022-11-16 13:10:40 -0500 | [diff] [blame] | 325 | set_next_law(CFG_SYS_SRIO_PCIE_BOOT_UCODE_ENV_ADDR_PHYS, |
Liu Gang | b4611ee | 2012-08-09 05:10:03 +0000 | [diff] [blame] | 326 | LAW_SIZE_1M, |
| 327 | LAW_TRGT_IF_PCIE_2); |
| 328 | break; |
| 329 | case 0x2: /* boot from PCIE3 */ |
Tom Rini | 40eb556 | 2022-11-16 13:10:40 -0500 | [diff] [blame] | 330 | set_next_law(CFG_SYS_SRIO_PCIE_BOOT_SLAVE_ADDR_PHYS, |
Liu Gang | b4611ee | 2012-08-09 05:10:03 +0000 | [diff] [blame] | 331 | LAW_SIZE_1M, |
| 332 | LAW_TRGT_IF_PCIE_3); |
Tom Rini | 40eb556 | 2022-11-16 13:10:40 -0500 | [diff] [blame] | 333 | set_next_law(CFG_SYS_SRIO_PCIE_BOOT_UCODE_ENV_ADDR_PHYS, |
Liu Gang | b4611ee | 2012-08-09 05:10:03 +0000 | [diff] [blame] | 334 | LAW_SIZE_1M, |
| 335 | LAW_TRGT_IF_PCIE_3); |
| 336 | break; |
Liu Gang | e86e1a3 | 2012-08-09 05:10:00 +0000 | [diff] [blame] | 337 | case 0x8: /* boot from SRIO1 */ |
Tom Rini | 40eb556 | 2022-11-16 13:10:40 -0500 | [diff] [blame] | 338 | set_next_law(CFG_SYS_SRIO_PCIE_BOOT_SLAVE_ADDR_PHYS, |
Liu Gang | e86e1a3 | 2012-08-09 05:10:00 +0000 | [diff] [blame] | 339 | LAW_SIZE_1M, |
| 340 | LAW_TRGT_IF_RIO_1); |
Tom Rini | 40eb556 | 2022-11-16 13:10:40 -0500 | [diff] [blame] | 341 | set_next_law(CFG_SYS_SRIO_PCIE_BOOT_UCODE_ENV_ADDR_PHYS, |
Liu Gang | e86e1a3 | 2012-08-09 05:10:00 +0000 | [diff] [blame] | 342 | LAW_SIZE_1M, |
| 343 | LAW_TRGT_IF_RIO_1); |
| 344 | break; |
| 345 | case 0x9: /* boot from SRIO2 */ |
Tom Rini | 40eb556 | 2022-11-16 13:10:40 -0500 | [diff] [blame] | 346 | set_next_law(CFG_SYS_SRIO_PCIE_BOOT_SLAVE_ADDR_PHYS, |
Liu Gang | e86e1a3 | 2012-08-09 05:10:00 +0000 | [diff] [blame] | 347 | LAW_SIZE_1M, |
| 348 | LAW_TRGT_IF_RIO_2); |
Tom Rini | 40eb556 | 2022-11-16 13:10:40 -0500 | [diff] [blame] | 349 | set_next_law(CFG_SYS_SRIO_PCIE_BOOT_UCODE_ENV_ADDR_PHYS, |
Liu Gang | e86e1a3 | 2012-08-09 05:10:00 +0000 | [diff] [blame] | 350 | LAW_SIZE_1M, |
| 351 | LAW_TRGT_IF_RIO_2); |
| 352 | break; |
| 353 | default: |
| 354 | break; |
| 355 | } |
| 356 | #endif |
| 357 | |
Bin Meng | 75a6a37 | 2022-10-26 12:40:07 +0800 | [diff] [blame] | 358 | return; |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 359 | } |