Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
York Sun | e12ce98 | 2011-08-26 11:32:44 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2011 Freescale Semiconductor, Inc. |
York Sun | e12ce98 | 2011-08-26 11:32:44 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 6 | #include <log.h> |
York Sun | e12ce98 | 2011-08-26 11:32:44 -0700 | [diff] [blame] | 7 | #include <asm/fsl_law.h> |
| 8 | #include <asm/mmu.h> |
Fabio Estevam | 1a03a7e | 2015-11-05 12:43:40 -0200 | [diff] [blame] | 9 | #include <linux/log2.h> |
York Sun | e12ce98 | 2011-08-26 11:32:44 -0700 | [diff] [blame] | 10 | |
| 11 | int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id) |
| 12 | { |
| 13 | immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
| 14 | law83xx_t *ecm = &immap->sysconf.ddrlaw[0]; |
| 15 | u64 start_align, law_sz; |
| 16 | int law_sz_enc; |
| 17 | |
| 18 | if (start == 0) |
| 19 | start_align = 1ull << (LAW_SIZE_2G + 1); |
| 20 | else |
Ashish kumar | e7d15f6 | 2016-01-22 15:50:10 +0530 | [diff] [blame] | 21 | start_align = 1ull << (__ffs64(start)); |
York Sun | e12ce98 | 2011-08-26 11:32:44 -0700 | [diff] [blame] | 22 | law_sz = min(start_align, sz); |
| 23 | law_sz_enc = __ilog2_u64(law_sz) - 1; |
| 24 | |
| 25 | /* |
| 26 | * Set up LAWBAR for all of DDR. |
| 27 | */ |
| 28 | ecm->bar = start & 0xfffff000; |
| 29 | ecm->ar = (LAWAR_EN | (id << 20) | (LAWAR_SIZE & law_sz_enc)); |
| 30 | debug("DDR:bar=0x%08x\n", ecm->bar); |
| 31 | debug("DDR:ar=0x%08x\n", ecm->ar); |
| 32 | |
| 33 | /* recalculate size based on what was actually covered by the law */ |
| 34 | law_sz = 1ull << __ilog2_u64(law_sz); |
| 35 | |
| 36 | /* do we still have anything to map */ |
| 37 | sz = sz - law_sz; |
| 38 | if (sz) { |
| 39 | start += law_sz; |
| 40 | |
Ashish kumar | e7d15f6 | 2016-01-22 15:50:10 +0530 | [diff] [blame] | 41 | start_align = 1ull << (__ffs64(start)); |
York Sun | e12ce98 | 2011-08-26 11:32:44 -0700 | [diff] [blame] | 42 | law_sz = min(start_align, sz); |
| 43 | law_sz_enc = __ilog2_u64(law_sz) - 1; |
| 44 | ecm = &immap->sysconf.ddrlaw[1]; |
| 45 | ecm->bar = start & 0xfffff000; |
| 46 | ecm->ar = (LAWAR_EN | (id << 20) | (LAWAR_SIZE & law_sz_enc)); |
| 47 | debug("DDR:bar=0x%08x\n", ecm->bar); |
| 48 | debug("DDR:ar=0x%08x\n", ecm->ar); |
| 49 | } else { |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | /* do we still have anything to map */ |
| 54 | sz = sz - law_sz; |
| 55 | if (sz) |
| 56 | return 1; |
| 57 | |
| 58 | return 0; |
| 59 | } |