blob: 782874d79d7ccf836a2647ff2c85c84f15efe68f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kumar Gala38449a42009-09-10 03:02:13 -05002/*
Haiying Wang325a12f2011-01-20 22:26:31 +00003 * Copyright 2008-2011 Freescale Semiconductor, Inc.
Kumar Gala38449a42009-09-10 03:02:13 -05004 */
5
Masahiro Yamada75f82d02018-03-05 01:20:11 +09006#include <linux/libfdt.h>
Kumar Gala38449a42009-09-10 03:02:13 -05007#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 Gala38449a42009-09-10 03:02:13 -050015/* Update portal containter to match LAW setup of portal in phy map */
16void 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 Meng75a6a372022-10-26 12:40:07 +080023 return;
Kumar Gala38449a42009-09-10 03:02:13 -050024
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 Meng75a6a372022-10-26 12:40:07 +080037 return;
Kumar Gala38449a42009-09-10 03:02:13 -050038 }
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 Meng75a6a372022-10-26 12:40:07 +080063 return;
Kumar Gala38449a42009-09-10 03:02:13 -050064 }
65
66 memcpy(&buf, name, len);
67 len += sprintf(&buf[len], "@%llx", addr);
68 fdt_set_name(blob, off, buf);
Bin Meng75a6a372022-10-26 12:40:07 +080069 return;
Kumar Gala38449a42009-09-10 03:02:13 -050070 }
71
72 printf("ERROR: %s isn't in a container. Not supported\n", compat);
73}