portals.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2008-2011 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <linux/libfdt.h>
  7. #include <fdt_support.h>
  8. #include <asm/processor.h>
  9. #include <asm/io.h>
  10. #include <asm/fsl_portals.h>
  11. #include <asm/fsl_liodn.h>
  12. /* Update portal containter to match LAW setup of portal in phy map */
  13. void fdt_portal(void *blob, const char *compat, const char *container,
  14. u64 addr, u32 size)
  15. {
  16. int off;
  17. off = fdt_node_offset_by_compatible(blob, -1, compat);
  18. if (off < 0)
  19. return ;
  20. off = fdt_parent_offset(blob, off);
  21. /* if non-zero assume we have a container */
  22. if (off > 0) {
  23. char buf[60];
  24. const char *p, *name;
  25. u32 *range;
  26. int len;
  27. /* fixup ranges */
  28. range = fdt_getprop_w(blob, off, "ranges", &len);
  29. if (range == NULL) {
  30. printf("ERROR: container for %s has no ranges", compat);
  31. return ;
  32. }
  33. range[0] = 0;
  34. if (len == 16) {
  35. range[1] = addr >> 32;
  36. range[2] = addr & 0xffffffff;
  37. range[3] = size;
  38. } else {
  39. range[1] = addr & 0xffffffff;
  40. range[2] = size;
  41. }
  42. fdt_setprop_inplace(blob, off, "ranges", range, len);
  43. /* fixup the name */
  44. name = fdt_get_name(blob, off, &len);
  45. p = memchr(name, '@', len);
  46. if (p)
  47. len = p - name;
  48. /* if we are given a container name check it
  49. * against what we found, if it doesnt match exit out */
  50. if (container && (memcmp(container, name, len))) {
  51. printf("WARNING: container names didn't match %s %s\n",
  52. container, name);
  53. return ;
  54. }
  55. memcpy(&buf, name, len);
  56. len += sprintf(&buf[len], "@%llx", addr);
  57. fdt_set_name(blob, off, buf);
  58. return ;
  59. }
  60. printf("ERROR: %s isn't in a container. Not supported\n", compat);
  61. }