ns_access.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2014 Freescale Semiconductor
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <fsl_csu.h>
  9. #include <asm/arch/ns_access.h>
  10. #include <asm/arch/fsl_serdes.h>
  11. void set_devices_ns_access(unsigned long index, u16 val)
  12. {
  13. u32 *base = (u32 *)CONFIG_SYS_FSL_CSU_ADDR;
  14. u32 *reg;
  15. uint32_t tmp;
  16. reg = base + index / 2;
  17. tmp = in_be32(reg);
  18. if (index % 2 == 0) {
  19. tmp &= 0x0000ffff;
  20. tmp |= val << 16;
  21. } else {
  22. tmp &= 0xffff0000;
  23. tmp |= val;
  24. }
  25. out_be32(reg, tmp);
  26. }
  27. static void enable_devices_ns_access(struct csu_ns_dev *ns_dev, uint32_t num)
  28. {
  29. int i;
  30. for (i = 0; i < num; i++)
  31. set_devices_ns_access(ns_dev[i].ind, ns_dev[i].val);
  32. }
  33. void enable_layerscape_ns_access(void)
  34. {
  35. #ifdef CONFIG_ARM64
  36. if (current_el() == 3)
  37. #endif
  38. enable_devices_ns_access(ns_dev, ARRAY_SIZE(ns_dev));
  39. }
  40. void set_pcie_ns_access(int pcie, u16 val)
  41. {
  42. switch (pcie) {
  43. #ifdef CONFIG_PCIE1
  44. case PCIE1:
  45. set_devices_ns_access(CSU_CSLX_PCIE1, val);
  46. set_devices_ns_access(CSU_CSLX_PCIE1_IO, val);
  47. return;
  48. #endif
  49. #ifdef CONFIG_PCIE2
  50. case PCIE2:
  51. set_devices_ns_access(CSU_CSLX_PCIE2, val);
  52. set_devices_ns_access(CSU_CSLX_PCIE2_IO, val);
  53. return;
  54. #endif
  55. #ifdef CONFIG_PCIE3
  56. case PCIE3:
  57. set_devices_ns_access(CSU_CSLX_PCIE3, val);
  58. set_devices_ns_access(CSU_CSLX_PCIE3_IO, val);
  59. return;
  60. #endif
  61. default:
  62. debug("The PCIE%d doesn't exist!\n", pcie);
  63. return;
  64. }
  65. }