keystone.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Keystone2 based boards and SOC related code.
  4. *
  5. * Copyright 2013 Texas Instruments, Inc.
  6. * Cyril Chemparathy <[email protected]>
  7. * Santosh Shilimkar <[email protected]>
  8. */
  9. #include <linux/io.h>
  10. #include <linux/of.h>
  11. #include <linux/dma-map-ops.h>
  12. #include <linux/init.h>
  13. #include <linux/of_platform.h>
  14. #include <linux/of_address.h>
  15. #include <linux/memblock.h>
  16. #include <asm/setup.h>
  17. #include <asm/mach/map.h>
  18. #include <asm/mach/arch.h>
  19. #include <asm/mach/time.h>
  20. #include <asm/smp_plat.h>
  21. #include <asm/memory.h>
  22. #include "memory.h"
  23. #include "keystone.h"
  24. #ifdef CONFIG_ARM_LPAE
  25. static int keystone_platform_notifier(struct notifier_block *nb,
  26. unsigned long event, void *data)
  27. {
  28. struct device *dev = data;
  29. if (event != BUS_NOTIFY_ADD_DEVICE)
  30. return NOTIFY_DONE;
  31. if (!dev)
  32. return NOTIFY_BAD;
  33. if (!dev->of_node) {
  34. int ret = dma_direct_set_offset(dev, KEYSTONE_HIGH_PHYS_START,
  35. KEYSTONE_LOW_PHYS_START,
  36. KEYSTONE_HIGH_PHYS_SIZE);
  37. dev_err(dev, "set dma_offset%08llx%s\n",
  38. KEYSTONE_HIGH_PHYS_START - KEYSTONE_LOW_PHYS_START,
  39. ret ? " failed" : "");
  40. }
  41. return NOTIFY_OK;
  42. }
  43. static struct notifier_block platform_nb = {
  44. .notifier_call = keystone_platform_notifier,
  45. };
  46. #endif /* CONFIG_ARM_LPAE */
  47. static void __init keystone_init(void)
  48. {
  49. #ifdef CONFIG_ARM_LPAE
  50. if (PHYS_OFFSET >= KEYSTONE_HIGH_PHYS_START)
  51. bus_register_notifier(&platform_bus_type, &platform_nb);
  52. #endif
  53. keystone_pm_runtime_init();
  54. }
  55. static long long __init keystone_pv_fixup(void)
  56. {
  57. long long offset;
  58. u64 mem_start, mem_end;
  59. mem_start = memblock_start_of_DRAM();
  60. mem_end = memblock_end_of_DRAM();
  61. /* nothing to do if we are running out of the <32-bit space */
  62. if (mem_start >= KEYSTONE_LOW_PHYS_START &&
  63. mem_end <= KEYSTONE_LOW_PHYS_END)
  64. return 0;
  65. if (mem_start < KEYSTONE_HIGH_PHYS_START ||
  66. mem_end > KEYSTONE_HIGH_PHYS_END) {
  67. pr_crit("Invalid address space for memory (%08llx-%08llx)\n",
  68. mem_start, mem_end);
  69. return 0;
  70. }
  71. offset = KEYSTONE_HIGH_PHYS_START - KEYSTONE_LOW_PHYS_START;
  72. /* Populate the arch idmap hook */
  73. arch_phys_to_idmap_offset = -offset;
  74. return offset;
  75. }
  76. static const char *const keystone_match[] __initconst = {
  77. "ti,k2hk",
  78. "ti,k2e",
  79. "ti,k2l",
  80. "ti,k2g",
  81. "ti,keystone",
  82. NULL,
  83. };
  84. DT_MACHINE_START(KEYSTONE, "Keystone")
  85. #if defined(CONFIG_ZONE_DMA) && defined(CONFIG_ARM_LPAE)
  86. .dma_zone_size = SZ_2G,
  87. #endif
  88. .smp = smp_ops(keystone_smp_ops),
  89. .init_machine = keystone_init,
  90. .dt_compat = keystone_match,
  91. .pv_fixup = keystone_pv_fixup,
  92. MACHINE_END