ip30-setup.c 3.3 KB

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