rtlx-mt.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.
  7. * Copyright (C) 2013 Imagination Technologies Ltd.
  8. */
  9. #include <linux/device.h>
  10. #include <linux/fs.h>
  11. #include <linux/err.h>
  12. #include <linux/wait.h>
  13. #include <linux/sched.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/irq.h>
  16. #include <asm/mips_mt.h>
  17. #include <asm/vpe.h>
  18. #include <asm/rtlx.h>
  19. static int major;
  20. static void rtlx_dispatch(void)
  21. {
  22. if (read_c0_cause() & read_c0_status() & C_SW0)
  23. do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ);
  24. }
  25. /*
  26. * Interrupt handler may be called before rtlx_init has otherwise had
  27. * a chance to run.
  28. */
  29. static irqreturn_t rtlx_interrupt(int irq, void *dev_id)
  30. {
  31. unsigned int vpeflags;
  32. unsigned long flags;
  33. int i;
  34. /* Ought not to be strictly necessary for SMTC builds */
  35. local_irq_save(flags);
  36. vpeflags = dvpe();
  37. set_c0_status(0x100 << MIPS_CPU_RTLX_IRQ);
  38. irq_enable_hazard();
  39. evpe(vpeflags);
  40. local_irq_restore(flags);
  41. for (i = 0; i < RTLX_CHANNELS; i++) {
  42. wake_up(&channel_wqs[i].lx_queue);
  43. wake_up(&channel_wqs[i].rt_queue);
  44. }
  45. return IRQ_HANDLED;
  46. }
  47. static struct irqaction rtlx_irq = {
  48. .handler = rtlx_interrupt,
  49. .name = "RTLX",
  50. };
  51. static int rtlx_irq_num = MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ;
  52. void _interrupt_sp(void)
  53. {
  54. unsigned long flags;
  55. local_irq_save(flags);
  56. dvpe();
  57. settc(1);
  58. write_vpe_c0_cause(read_vpe_c0_cause() | C_SW0);
  59. evpe(EVPE_ENABLE);
  60. local_irq_restore(flags);
  61. }
  62. int __init rtlx_module_init(void)
  63. {
  64. struct device *dev;
  65. int i, err;
  66. if (!cpu_has_mipsmt) {
  67. pr_warn("VPE loader: not a MIPS MT capable processor\n");
  68. return -ENODEV;
  69. }
  70. if (aprp_cpu_index() == 0) {
  71. pr_warn("No TCs reserved for AP/SP, not initializing RTLX.\n"
  72. "Pass maxtcs=<n> argument as kernel argument\n");
  73. return -ENODEV;
  74. }
  75. major = register_chrdev(0, RTLX_MODULE_NAME, &rtlx_fops);
  76. if (major < 0) {
  77. pr_err("rtlx_module_init: unable to register device\n");
  78. return major;
  79. }
  80. /* initialise the wait queues */
  81. for (i = 0; i < RTLX_CHANNELS; i++) {
  82. init_waitqueue_head(&channel_wqs[i].rt_queue);
  83. init_waitqueue_head(&channel_wqs[i].lx_queue);
  84. atomic_set(&channel_wqs[i].in_open, 0);
  85. mutex_init(&channel_wqs[i].mutex);
  86. dev = device_create(mt_class, NULL, MKDEV(major, i), NULL,
  87. "%s%d", RTLX_MODULE_NAME, i);
  88. if (IS_ERR(dev)) {
  89. err = PTR_ERR(dev);
  90. goto out_chrdev;
  91. }
  92. }
  93. /* set up notifiers */
  94. rtlx_notify.start = rtlx_starting;
  95. rtlx_notify.stop = rtlx_stopping;
  96. vpe_notify(aprp_cpu_index(), &rtlx_notify);
  97. if (cpu_has_vint) {
  98. aprp_hook = rtlx_dispatch;
  99. } else {
  100. pr_err("APRP RTLX init on non-vectored-interrupt processor\n");
  101. err = -ENODEV;
  102. goto out_class;
  103. }
  104. rtlx_irq.dev_id = rtlx;
  105. err = setup_irq(rtlx_irq_num, &rtlx_irq);
  106. if (err)
  107. goto out_class;
  108. return 0;
  109. out_class:
  110. for (i = 0; i < RTLX_CHANNELS; i++)
  111. device_destroy(mt_class, MKDEV(major, i));
  112. out_chrdev:
  113. unregister_chrdev(major, RTLX_MODULE_NAME);
  114. return err;
  115. }
  116. void __exit rtlx_module_exit(void)
  117. {
  118. int i;
  119. for (i = 0; i < RTLX_CHANNELS; i++)
  120. device_destroy(mt_class, MKDEV(major, i));
  121. unregister_chrdev(major, RTLX_MODULE_NAME);
  122. aprp_hook = NULL;
  123. }