smp.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * ARC700 Simulation-only Extensions for SMP
  3. *
  4. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Vineet Gupta - 2012 : split off arch common and plat specific SMP
  11. * Rajeshwar Ranga - 2007 : Interrupt Distribution Unit API's
  12. */
  13. #include <linux/smp.h>
  14. #include <linux/irq.h>
  15. #include <plat/irq.h>
  16. #include <plat/smp.h>
  17. static char smp_cpuinfo_buf[128];
  18. /*
  19. *-------------------------------------------------------------------
  20. * Platform specific callbacks expected by arch SMP code
  21. *-------------------------------------------------------------------
  22. */
  23. /*
  24. * Master kick starting another CPU
  25. */
  26. static void iss_model_smp_wakeup_cpu(int cpu, unsigned long pc)
  27. {
  28. /* setup the start PC */
  29. write_aux_reg(ARC_AUX_XTL_REG_PARAM, pc);
  30. /* Trigger WRITE_PC cmd for this cpu */
  31. write_aux_reg(ARC_AUX_XTL_REG_CMD,
  32. (ARC_XTL_CMD_WRITE_PC | (cpu << 8)));
  33. /* Take the cpu out of Halt */
  34. write_aux_reg(ARC_AUX_XTL_REG_CMD,
  35. (ARC_XTL_CMD_CLEAR_HALT | (cpu << 8)));
  36. }
  37. static inline int get_hw_config_num_irq(void)
  38. {
  39. uint32_t val = read_aux_reg(ARC_REG_VECBASE_BCR);
  40. switch (val & 0x03) {
  41. case 0:
  42. return 16;
  43. case 1:
  44. return 32;
  45. case 2:
  46. return 8;
  47. default:
  48. return 0;
  49. }
  50. return 0;
  51. }
  52. /*
  53. * Any SMP specific init any CPU does when it comes up.
  54. * Here we setup the CPU to enable Inter-Processor-Interrupts
  55. * Called for each CPU
  56. * -Master : init_IRQ()
  57. * -Other(s) : start_kernel_secondary()
  58. */
  59. void iss_model_init_smp(unsigned int cpu)
  60. {
  61. /* Check if CPU is configured for more than 16 interrupts */
  62. if (NR_IRQS <= 16 || get_hw_config_num_irq() <= 16)
  63. panic("[arcfpga] IRQ system can't support IDU IPI\n");
  64. idu_disable();
  65. /****************************************************************
  66. * IDU provides a set of Common IRQs, each of which can be dynamically
  67. * attached to (1|many|all) CPUs.
  68. * The Common IRQs [0-15] are mapped as CPU pvt [16-31]
  69. *
  70. * Here we use a simple 1:1 mapping:
  71. * A CPU 'x' is wired to Common IRQ 'x'.
  72. * So an IDU ASSERT on IRQ 'x' will trigger Interupt on CPU 'x', which
  73. * makes up for our simple IPI plumbing.
  74. *
  75. * TBD: Have a dedicated multicast IRQ for sending IPIs to all CPUs
  76. * w/o having to do one-at-a-time
  77. ******************************************************************/
  78. /*
  79. * Claim an IRQ which would trigger IPI on this CPU.
  80. * In IDU parlance it involves setting up a cpu bitmask for the IRQ
  81. * The bitmap here contains only 1 CPU (self).
  82. */
  83. idu_irq_set_tgtcpu(cpu, 0x1 << cpu);
  84. /* Set the IRQ destination to use the bitmask above */
  85. idu_irq_set_mode(cpu, 7, /* XXX: IDU_IRQ_MOD_TCPU_ALLRECP: ISS bug */
  86. IDU_IRQ_MODE_PULSE_TRIG);
  87. idu_enable();
  88. /* Attach the arch-common IPI ISR to our IDU IRQ */
  89. smp_ipi_irq_setup(cpu, IDU_INTERRUPT_0 + cpu);
  90. }
  91. static void iss_model_ipi_send(int cpu)
  92. {
  93. idu_irq_assert(cpu);
  94. }
  95. static void iss_model_ipi_clear(int irq)
  96. {
  97. idu_irq_clear(IDU_INTERRUPT_0 + smp_processor_id());
  98. }
  99. void iss_model_init_early_smp(void)
  100. {
  101. #define IS_AVAIL1(var, str) ((var) ? str : "")
  102. struct bcr_mp mp;
  103. READ_BCR(ARC_REG_MP_BCR, mp);
  104. sprintf(smp_cpuinfo_buf, "Extn [ISS-SMP]: v%d, arch(%d) %s %s %s\n",
  105. mp.ver, mp.mp_arch, IS_AVAIL1(mp.scu, "SCU"),
  106. IS_AVAIL1(mp.idu, "IDU"), IS_AVAIL1(mp.sdu, "SDU"));
  107. plat_smp_ops.info = smp_cpuinfo_buf;
  108. plat_smp_ops.cpu_kick = iss_model_smp_wakeup_cpu;
  109. plat_smp_ops.ipi_send = iss_model_ipi_send;
  110. plat_smp_ops.ipi_clear = iss_model_ipi_clear;
  111. }
  112. /*
  113. *-------------------------------------------------------------------
  114. * Low level Platform IPI Providers
  115. *-------------------------------------------------------------------
  116. */
  117. /* Set the Mode for the Common IRQ */
  118. void idu_irq_set_mode(uint8_t irq, uint8_t dest_mode, uint8_t trig_mode)
  119. {
  120. uint32_t par = IDU_IRQ_MODE_PARAM(dest_mode, trig_mode);
  121. IDU_SET_PARAM(par);
  122. IDU_SET_COMMAND(irq, IDU_IRQ_WMODE);
  123. }
  124. /* Set the target cpu Bitmask for Common IRQ */
  125. void idu_irq_set_tgtcpu(uint8_t irq, uint32_t mask)
  126. {
  127. IDU_SET_PARAM(mask);
  128. IDU_SET_COMMAND(irq, IDU_IRQ_WBITMASK);
  129. }
  130. /* Get the Interrupt Acknowledged status for IRQ (as CPU Bitmask) */
  131. bool idu_irq_get_ack(uint8_t irq)
  132. {
  133. uint32_t val;
  134. IDU_SET_COMMAND(irq, IDU_IRQ_ACK);
  135. val = IDU_GET_PARAM();
  136. return val & (1 << irq);
  137. }
  138. /*
  139. * Get the Interrupt Pending status for IRQ (as CPU Bitmask)
  140. * -Pending means CPU has not yet noticed the IRQ (e.g. disabled)
  141. * -After Interrupt has been taken, the IPI expcitily needs to be
  142. * cleared, to be acknowledged.
  143. */
  144. bool idu_irq_get_pend(uint8_t irq)
  145. {
  146. uint32_t val;
  147. IDU_SET_COMMAND(irq, IDU_IRQ_PEND);
  148. val = IDU_GET_PARAM();
  149. return val & (1 << irq);
  150. }