Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kumar Gala | 38449a4 | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 2 | /* |
Haiying Wang | 325a12f | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 3 | * Copyright 2008-2011 Freescale Semiconductor, Inc. |
Kumar Gala | 38449a4 | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 4 | */ |
| 5 | |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 6 | #include <linux/libfdt.h> |
Kumar Gala | 38449a4 | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 7 | #include <fdt_support.h> |
| 8 | |
| 9 | #include <asm/processor.h> |
| 10 | #include <asm/io.h> |
| 11 | |
| 12 | #include <asm/fsl_portals.h> |
| 13 | #include <asm/fsl_liodn.h> |
| 14 | |
Kumar Gala | 38449a4 | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 15 | /* Update portal containter to match LAW setup of portal in phy map */ |
| 16 | void fdt_portal(void *blob, const char *compat, const char *container, |
| 17 | u64 addr, u32 size) |
| 18 | { |
| 19 | int off; |
| 20 | |
| 21 | off = fdt_node_offset_by_compatible(blob, -1, compat); |
| 22 | if (off < 0) |
Bin Meng | 75a6a37 | 2022-10-26 12:40:07 +0800 | [diff] [blame] | 23 | return; |
Kumar Gala | 38449a4 | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 24 | |
| 25 | off = fdt_parent_offset(blob, off); |
| 26 | /* if non-zero assume we have a container */ |
| 27 | if (off > 0) { |
| 28 | char buf[60]; |
| 29 | const char *p, *name; |
| 30 | u32 *range; |
| 31 | int len; |
| 32 | |
| 33 | /* fixup ranges */ |
| 34 | range = fdt_getprop_w(blob, off, "ranges", &len); |
| 35 | if (range == NULL) { |
| 36 | printf("ERROR: container for %s has no ranges", compat); |
Bin Meng | 75a6a37 | 2022-10-26 12:40:07 +0800 | [diff] [blame] | 37 | return; |
Kumar Gala | 38449a4 | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | range[0] = 0; |
| 41 | if (len == 16) { |
| 42 | range[1] = addr >> 32; |
| 43 | range[2] = addr & 0xffffffff; |
| 44 | range[3] = size; |
| 45 | } else { |
| 46 | range[1] = addr & 0xffffffff; |
| 47 | range[2] = size; |
| 48 | } |
| 49 | fdt_setprop_inplace(blob, off, "ranges", range, len); |
| 50 | |
| 51 | /* fixup the name */ |
| 52 | name = fdt_get_name(blob, off, &len); |
| 53 | p = memchr(name, '@', len); |
| 54 | |
| 55 | if (p) |
| 56 | len = p - name; |
| 57 | |
| 58 | /* if we are given a container name check it |
| 59 | * against what we found, if it doesnt match exit out */ |
| 60 | if (container && (memcmp(container, name, len))) { |
| 61 | printf("WARNING: container names didn't match %s %s\n", |
| 62 | container, name); |
Bin Meng | 75a6a37 | 2022-10-26 12:40:07 +0800 | [diff] [blame] | 63 | return; |
Kumar Gala | 38449a4 | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | memcpy(&buf, name, len); |
| 67 | len += sprintf(&buf[len], "@%llx", addr); |
| 68 | fdt_set_name(blob, off, buf); |
Bin Meng | 75a6a37 | 2022-10-26 12:40:07 +0800 | [diff] [blame] | 69 | return; |
Kumar Gala | 38449a4 | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | printf("ERROR: %s isn't in a container. Not supported\n", compat); |
| 73 | } |