ip30-setup.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * SGI IP30 miscellaneous setup bits.
  4. *
  5. * Copyright (C) 2004-2007 Stanislaw Skowronek <[email protected]>
  6. * 2007 Joshua Kinard <[email protected]>
  7. * 2009 Johannes Dickgreber <[email protected]>
  8. */
  9. #include <linux/init.h>
  10. #include <linux/io.h>
  11. #include <linux/kernel.h>
  12. #include <linux/types.h>
  13. #include <linux/percpu.h>
  14. #include <linux/memblock.h>
  15. #include <asm/smp-ops.h>
  16. #include <asm/sgialib.h>
  17. #include <asm/time.h>
  18. #include <asm/sgi/heart.h>
  19. #include "ip30-common.h"
  20. /* Structure of accessible HEART registers located in XKPHYS space. */
  21. struct ip30_heart_regs __iomem *heart_regs = HEART_XKPHYS_BASE;
  22. /*
  23. * ARCS will report up to the first 1GB of
  24. * memory if queried. Anything beyond that
  25. * is marked as reserved.
  26. */
  27. #define IP30_MAX_PROM_MEMORY _AC(0x40000000, UL)
  28. /*
  29. * Memory in the Octane starts at 512MB
  30. */
  31. #define IP30_MEMORY_BASE _AC(0x20000000, UL)
  32. /*
  33. * If using ARCS to probe for memory, then
  34. * remaining memory will start at this offset.
  35. */
  36. #define IP30_REAL_MEMORY_START (IP30_MEMORY_BASE + IP30_MAX_PROM_MEMORY)
  37. #define MEM_SHIFT(x) ((x) >> 20)
  38. static void __init ip30_mem_init(void)
  39. {
  40. unsigned long total_mem;
  41. phys_addr_t addr;
  42. phys_addr_t size;
  43. u32 memcfg;
  44. int i;
  45. total_mem = 0;
  46. for (i = 0; i < HEART_MEMORY_BANKS; i++) {
  47. memcfg = __raw_readl(&heart_regs->mem_cfg.l[i]);
  48. if (!(memcfg & HEART_MEMCFG_VALID))
  49. continue;
  50. addr = memcfg & HEART_MEMCFG_ADDR_MASK;
  51. addr <<= HEART_MEMCFG_UNIT_SHIFT;
  52. addr += IP30_MEMORY_BASE;
  53. size = memcfg & HEART_MEMCFG_SIZE_MASK;
  54. size >>= HEART_MEMCFG_SIZE_SHIFT;
  55. size += 1;
  56. size <<= HEART_MEMCFG_UNIT_SHIFT;
  57. total_mem += size;
  58. if (addr >= IP30_REAL_MEMORY_START)
  59. memblock_phys_free(addr, size);
  60. else if ((addr + size) > IP30_REAL_MEMORY_START)
  61. memblock_phys_free(IP30_REAL_MEMORY_START,
  62. size - IP30_MAX_PROM_MEMORY);
  63. }
  64. pr_info("Detected %luMB of physical memory.\n", MEM_SHIFT(total_mem));
  65. }
  66. /**
  67. * ip30_cpu_time_init - platform time initialization.
  68. */
  69. static void __init ip30_cpu_time_init(void)
  70. {
  71. int cpu = smp_processor_id();
  72. u64 heart_compare;
  73. unsigned int start, end;
  74. int time_diff;
  75. heart_compare = (heart_read(&heart_regs->count) +
  76. (HEART_CYCLES_PER_SEC / 10));
  77. start = read_c0_count();
  78. while ((heart_read(&heart_regs->count) - heart_compare) & 0x800000)
  79. cpu_relax();
  80. end = read_c0_count();
  81. time_diff = (int)end - (int)start;
  82. mips_hpt_frequency = time_diff * 10;
  83. pr_info("IP30: CPU%d: %d MHz CPU detected.\n", cpu,
  84. (mips_hpt_frequency * 2) / 1000000);
  85. }
  86. void __init ip30_per_cpu_init(void)
  87. {
  88. /* Disable all interrupts. */
  89. clear_c0_status(ST0_IM);
  90. ip30_cpu_time_init();
  91. #ifdef CONFIG_SMP
  92. ip30_install_ipi();
  93. #endif
  94. enable_percpu_irq(IP30_HEART_L0_IRQ, IRQ_TYPE_NONE);
  95. enable_percpu_irq(IP30_HEART_L1_IRQ, IRQ_TYPE_NONE);
  96. enable_percpu_irq(IP30_HEART_L2_IRQ, IRQ_TYPE_NONE);
  97. enable_percpu_irq(IP30_HEART_ERR_IRQ, IRQ_TYPE_NONE);
  98. }
  99. /**
  100. * plat_mem_setup - despite the name, misc setup happens here.
  101. */
  102. void __init plat_mem_setup(void)
  103. {
  104. ip30_mem_init();
  105. /* XXX: Hard lock on /sbin/init if this flag isn't specified. */
  106. prom_flags |= PROM_FLAG_DONT_FREE_TEMP;
  107. #ifdef CONFIG_SMP
  108. register_smp_ops(&ip30_smp_ops);
  109. #else
  110. ip30_per_cpu_init();
  111. #endif
  112. ioport_resource.start = 0;
  113. ioport_resource.end = ~0UL;
  114. set_io_port_base(IO_BASE);
  115. }