smp.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 <asm/irq.h>
  15. #include <plat/smp.h>
  16. static char smp_cpuinfo_buf[128];
  17. /*
  18. *-------------------------------------------------------------------
  19. * Platform specific callbacks expected by arch SMP code
  20. *-------------------------------------------------------------------
  21. */
  22. const char *arc_platform_smp_cpuinfo(void)
  23. {
  24. #define IS_AVAIL1(var, str) ((var) ? str : "")
  25. struct bcr_mp mp;
  26. READ_BCR(ARC_REG_MP_BCR, mp);
  27. sprintf(smp_cpuinfo_buf, "Extn [700-SMP]: v%d, arch(%d) %s %s %s\n",
  28. mp.ver, mp.mp_arch, IS_AVAIL1(mp.scu, "SCU"),
  29. IS_AVAIL1(mp.idu, "IDU"), IS_AVAIL1(mp.sdu, "SDU"));
  30. return smp_cpuinfo_buf;
  31. }
  32. /*
  33. * Master kick starting another CPU
  34. */
  35. void arc_platform_smp_wakeup_cpu(int cpu, unsigned long pc)
  36. {
  37. /* setup the start PC */
  38. write_aux_reg(ARC_AUX_XTL_REG_PARAM, pc);
  39. /* Trigger WRITE_PC cmd for this cpu */
  40. write_aux_reg(ARC_AUX_XTL_REG_CMD,
  41. (ARC_XTL_CMD_WRITE_PC | (cpu << 8)));
  42. /* Take the cpu out of Halt */
  43. write_aux_reg(ARC_AUX_XTL_REG_CMD,
  44. (ARC_XTL_CMD_CLEAR_HALT | (cpu << 8)));
  45. }
  46. /*
  47. * Any SMP specific init any CPU does when it comes up.
  48. * Here we setup the CPU to enable Inter-Processor-Interrupts
  49. * Called for each CPU
  50. * -Master : init_IRQ()
  51. * -Other(s) : start_kernel_secondary()
  52. */
  53. void iss_model_init_smp(unsigned int cpu)
  54. {
  55. /* Check if CPU is configured for more than 16 interrupts */
  56. if (NR_IRQS <= 16 || get_hw_config_num_irq() <= 16)
  57. panic("[arcfpga] IRQ system can't support IDU IPI\n");
  58. idu_disable();
  59. /****************************************************************
  60. * IDU provides a set of Common IRQs, each of which can be dynamically
  61. * attached to (1|many|all) CPUs.
  62. * The Common IRQs [0-15] are mapped as CPU pvt [16-31]
  63. *
  64. * Here we use a simple 1:1 mapping:
  65. * A CPU 'x' is wired to Common IRQ 'x'.
  66. * So an IDU ASSERT on IRQ 'x' will trigger Interupt on CPU 'x', which
  67. * makes up for our simple IPI plumbing.
  68. *
  69. * TBD: Have a dedicated multicast IRQ for sending IPIs to all CPUs
  70. * w/o having to do one-at-a-time
  71. ******************************************************************/
  72. /*
  73. * Claim an IRQ which would trigger IPI on this CPU.
  74. * In IDU parlance it involves setting up a cpu bitmask for the IRQ
  75. * The bitmap here contains only 1 CPU (self).
  76. */
  77. idu_irq_set_tgtcpu(cpu, 0x1 << cpu);
  78. /* Set the IRQ destination to use the bitmask above */
  79. idu_irq_set_mode(cpu, 7, /* XXX: IDU_IRQ_MOD_TCPU_ALLRECP: ISS bug */
  80. IDU_IRQ_MODE_PULSE_TRIG);
  81. idu_enable();
  82. /* Attach the arch-common IPI ISR to our IDU IRQ */
  83. smp_ipi_irq_setup(cpu, IDU_INTERRUPT_0 + cpu);
  84. }
  85. void arc_platform_ipi_send(const struct cpumask *callmap)
  86. {
  87. unsigned int cpu;
  88. for_each_cpu(cpu, callmap)
  89. idu_irq_assert(cpu);
  90. }
  91. void arc_platform_ipi_clear(int cpu, int irq)
  92. {
  93. idu_irq_clear(IDU_INTERRUPT_0 + cpu);
  94. }
  95. /*
  96. *-------------------------------------------------------------------
  97. * Low level Platform IPI Providers
  98. *-------------------------------------------------------------------
  99. */
  100. /* Set the Mode for the Common IRQ */
  101. void idu_irq_set_mode(uint8_t irq, uint8_t dest_mode, uint8_t trig_mode)
  102. {
  103. uint32_t par = IDU_IRQ_MODE_PARAM(dest_mode, trig_mode);
  104. IDU_SET_PARAM(par);
  105. IDU_SET_COMMAND(irq, IDU_IRQ_WMODE);
  106. }
  107. /* Set the target cpu Bitmask for Common IRQ */
  108. void idu_irq_set_tgtcpu(uint8_t irq, uint32_t mask)
  109. {
  110. IDU_SET_PARAM(mask);
  111. IDU_SET_COMMAND(irq, IDU_IRQ_WBITMASK);
  112. }
  113. /* Get the Interrupt Acknowledged status for IRQ (as CPU Bitmask) */
  114. bool idu_irq_get_ack(uint8_t irq)
  115. {
  116. uint32_t val;
  117. IDU_SET_COMMAND(irq, IDU_IRQ_ACK);
  118. val = IDU_GET_PARAM();
  119. return val & (1 << irq);
  120. }
  121. /*
  122. * Get the Interrupt Pending status for IRQ (as CPU Bitmask)
  123. * -Pending means CPU has not yet noticed the IRQ (e.g. disabled)
  124. * -After Interrupt has been taken, the IPI expcitily needs to be
  125. * cleared, to be acknowledged.
  126. */
  127. bool idu_irq_get_pend(uint8_t irq)
  128. {
  129. uint32_t val;
  130. IDU_SET_COMMAND(irq, IDU_IRQ_PEND);
  131. val = IDU_GET_PARAM();
  132. return val & (1 << irq);
  133. }