dbell.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Author: Kumar Gala <galak@kernel.crashing.org>
  3. *
  4. * Copyright 2009 Freescale Semiconductor Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/stddef.h>
  12. #include <linux/kernel.h>
  13. #include <linux/smp.h>
  14. #include <linux/threads.h>
  15. #include <linux/percpu.h>
  16. #include <asm/dbell.h>
  17. #ifdef CONFIG_SMP
  18. struct doorbell_cpu_info {
  19. unsigned long messages; /* current messages bits */
  20. unsigned int tag; /* tag value */
  21. };
  22. static DEFINE_PER_CPU(struct doorbell_cpu_info, doorbell_cpu_info);
  23. void doorbell_setup_this_cpu(void)
  24. {
  25. struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
  26. info->messages = 0;
  27. info->tag = mfspr(SPRN_PIR) & 0x3fff;
  28. }
  29. void doorbell_message_pass(int target, int msg)
  30. {
  31. struct doorbell_cpu_info *info;
  32. int i;
  33. if (target < NR_CPUS) {
  34. info = &per_cpu(doorbell_cpu_info, target);
  35. set_bit(msg, &info->messages);
  36. ppc_msgsnd(PPC_DBELL, 0, info->tag);
  37. }
  38. else if (target == MSG_ALL_BUT_SELF) {
  39. for_each_online_cpu(i) {
  40. if (i == smp_processor_id())
  41. continue;
  42. info = &per_cpu(doorbell_cpu_info, i);
  43. set_bit(msg, &info->messages);
  44. ppc_msgsnd(PPC_DBELL, 0, info->tag);
  45. }
  46. }
  47. else { /* target == MSG_ALL */
  48. for_each_online_cpu(i) {
  49. info = &per_cpu(doorbell_cpu_info, i);
  50. set_bit(msg, &info->messages);
  51. }
  52. ppc_msgsnd(PPC_DBELL, PPC_DBELL_MSG_BRDCAST, 0);
  53. }
  54. }
  55. void doorbell_exception(struct pt_regs *regs)
  56. {
  57. struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
  58. int msg;
  59. /* Warning: regs can be NULL when called from irq enable */
  60. if (!info->messages || (num_online_cpus() < 2))
  61. return;
  62. for (msg = 0; msg < 4; msg++)
  63. if (test_and_clear_bit(msg, &info->messages))
  64. smp_message_recv(msg);
  65. }
  66. #else /* CONFIG_SMP */
  67. void doorbell_exception(struct pt_regs *regs)
  68. {
  69. printk(KERN_WARNING "Received doorbell on non-smp system\n");
  70. }
  71. #endif /* CONFIG_SMP */