fconf_mpmm_getter.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2021, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <common/debug.h>
  9. #include <common/fdt_wrappers.h>
  10. #include <lib/fconf/fconf.h>
  11. #include <lib/fconf/fconf_mpmm_getter.h>
  12. #include <libfdt.h>
  13. #include <plat/common/platform.h>
  14. struct fconf_mpmm_config fconf_mpmm_config;
  15. static struct mpmm_topology fconf_mpmm_topology;
  16. /*
  17. * Within a `cpu` node, determine support for MPMM via the `supports-mpmm`
  18. * property.
  19. *
  20. * Returns `0` on success, or a negative integer representing an error code.
  21. */
  22. static int fconf_populate_mpmm_cpu(const void *fdt, int off, uintptr_t mpidr)
  23. {
  24. int ret, len;
  25. int core_pos;
  26. struct mpmm_core *core;
  27. core_pos = plat_core_pos_by_mpidr(mpidr);
  28. if (core_pos < 0) {
  29. return -FDT_ERR_BADVALUE;
  30. }
  31. core = &fconf_mpmm_topology.cores[core_pos];
  32. fdt_getprop(fdt, off, "supports-mpmm", &len);
  33. if (len >= 0) {
  34. core->supported = true;
  35. ret = 0;
  36. } else {
  37. core->supported = false;
  38. ret = len;
  39. }
  40. return ret;
  41. }
  42. /*
  43. * Populates the global `fconf_mpmm_config` structure based on what's described
  44. * by the hardware configuration device tree blob.
  45. *
  46. * The device tree is expected to provide a `supports-mpmm` property for each
  47. * `cpu` node, like so:
  48. *
  49. * cpu@0 {
  50. * supports-mpmm;
  51. * };
  52. *
  53. * This property indicates whether the core implements MPMM, as we cannot detect
  54. * support for it dynamically.
  55. */
  56. static int fconf_populate_mpmm(uintptr_t config)
  57. {
  58. int ret = fdtw_for_each_cpu(
  59. (const void *)config, fconf_populate_mpmm_cpu);
  60. if (ret == 0) {
  61. fconf_mpmm_config.topology = &fconf_mpmm_topology;
  62. } else {
  63. ERROR("FCONF: failed to configure MPMM: %d\n", ret);
  64. }
  65. return ret;
  66. }
  67. FCONF_REGISTER_POPULATOR(HW_CONFIG, mpmm, fconf_populate_mpmm);