keystone.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Keystone2 based boards and SOC related code.
  3. *
  4. * Copyright 2013 Texas Instruments, Inc.
  5. * Cyril Chemparathy <cyril@ti.com>
  6. * Santosh Shilimkar <santosh.shillimkar@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms and conditions of the GNU General Public License,
  10. * version 2, as published by the Free Software Foundation.
  11. */
  12. #include <linux/io.h>
  13. #include <linux/of.h>
  14. #include <linux/init.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/of_address.h>
  17. #include <linux/memblock.h>
  18. #include <asm/setup.h>
  19. #include <asm/mach/map.h>
  20. #include <asm/mach/arch.h>
  21. #include <asm/mach/time.h>
  22. #include <asm/smp_plat.h>
  23. #include <asm/memory.h>
  24. #include "memory.h"
  25. #include "keystone.h"
  26. static struct notifier_block platform_nb;
  27. static unsigned long keystone_dma_pfn_offset __read_mostly;
  28. static int keystone_platform_notifier(struct notifier_block *nb,
  29. unsigned long event, void *data)
  30. {
  31. struct device *dev = data;
  32. if (event != BUS_NOTIFY_ADD_DEVICE)
  33. return NOTIFY_DONE;
  34. if (!dev)
  35. return NOTIFY_BAD;
  36. if (!dev->of_node) {
  37. dev->dma_pfn_offset = keystone_dma_pfn_offset;
  38. dev_err(dev, "set dma_pfn_offset%08lx\n",
  39. dev->dma_pfn_offset);
  40. }
  41. return NOTIFY_OK;
  42. }
  43. static void __init keystone_init(void)
  44. {
  45. keystone_pm_runtime_init();
  46. if (platform_nb.notifier_call)
  47. bus_register_notifier(&platform_bus_type, &platform_nb);
  48. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  49. }
  50. static phys_addr_t keystone_virt_to_idmap(unsigned long x)
  51. {
  52. return (phys_addr_t)(x) - CONFIG_PAGE_OFFSET + KEYSTONE_LOW_PHYS_START;
  53. }
  54. static void __init keystone_init_meminfo(void)
  55. {
  56. bool lpae = IS_ENABLED(CONFIG_ARM_LPAE);
  57. bool pvpatch = IS_ENABLED(CONFIG_ARM_PATCH_PHYS_VIRT);
  58. phys_addr_t offset = PHYS_OFFSET - KEYSTONE_LOW_PHYS_START;
  59. phys_addr_t mem_start, mem_end;
  60. mem_start = memblock_start_of_DRAM();
  61. mem_end = memblock_end_of_DRAM();
  62. /* nothing to do if we are running out of the <32-bit space */
  63. if (mem_start >= KEYSTONE_LOW_PHYS_START &&
  64. mem_end <= KEYSTONE_LOW_PHYS_END)
  65. return;
  66. if (!lpae || !pvpatch) {
  67. pr_crit("Enable %s%s%s to run outside 32-bit space\n",
  68. !lpae ? __stringify(CONFIG_ARM_LPAE) : "",
  69. (!lpae && !pvpatch) ? " and " : "",
  70. !pvpatch ? __stringify(CONFIG_ARM_PATCH_PHYS_VIRT) : "");
  71. }
  72. if (mem_start < KEYSTONE_HIGH_PHYS_START ||
  73. mem_end > KEYSTONE_HIGH_PHYS_END) {
  74. pr_crit("Invalid address space for memory (%08llx-%08llx)\n",
  75. (u64)mem_start, (u64)mem_end);
  76. }
  77. offset += KEYSTONE_HIGH_PHYS_START;
  78. __pv_phys_pfn_offset = PFN_DOWN(offset);
  79. __pv_offset = (offset - PAGE_OFFSET);
  80. /* Populate the arch idmap hook */
  81. arch_virt_to_idmap = keystone_virt_to_idmap;
  82. platform_nb.notifier_call = keystone_platform_notifier;
  83. keystone_dma_pfn_offset = PFN_DOWN(KEYSTONE_HIGH_PHYS_START -
  84. KEYSTONE_LOW_PHYS_START);
  85. pr_info("Switching to high address space at 0x%llx\n", (u64)offset);
  86. }
  87. static const char *keystone_match[] __initconst = {
  88. "ti,keystone",
  89. NULL,
  90. };
  91. DT_MACHINE_START(KEYSTONE, "Keystone")
  92. #if defined(CONFIG_ZONE_DMA) && defined(CONFIG_ARM_LPAE)
  93. .dma_zone_size = SZ_2G,
  94. #endif
  95. .smp = smp_ops(keystone_smp_ops),
  96. .init_machine = keystone_init,
  97. .dt_compat = keystone_match,
  98. .init_meminfo = keystone_init_meminfo,
  99. MACHINE_END