rtlx-mt.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. local_irq_save(flags);
  35. vpeflags = dvpe();
  36. set_c0_status(0x100 << MIPS_CPU_RTLX_IRQ);
  37. irq_enable_hazard();
  38. evpe(vpeflags);
  39. local_irq_restore(flags);
  40. for (i = 0; i < RTLX_CHANNELS; i++) {
  41. wake_up(&channel_wqs[i].lx_queue);
  42. wake_up(&channel_wqs[i].rt_queue);
  43. }
  44. return IRQ_HANDLED;
  45. }
  46. static struct irqaction rtlx_irq = {
  47. .handler = rtlx_interrupt,
  48. .name = "RTLX",
  49. };
  50. static int rtlx_irq_num = MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ;
  51. void _interrupt_sp(void)
  52. {
  53. unsigned long flags;
  54. local_irq_save(flags);
  55. dvpe();
  56. settc(1);
  57. write_vpe_c0_cause(read_vpe_c0_cause() | C_SW0);
  58. evpe(EVPE_ENABLE);
  59. local_irq_restore(flags);
  60. }
  61. int __init rtlx_module_init(void)
  62. {
  63. struct device *dev;
  64. int i, err;
  65. if (!cpu_has_mipsmt) {
  66. pr_warn("VPE loader: not a MIPS MT capable processor\n");
  67. return -ENODEV;
  68. }
  69. if (aprp_cpu_index() == 0) {
  70. pr_warn("No TCs reserved for AP/SP, not initializing RTLX.\n"
  71. "Pass maxtcs=<n> argument as kernel argument\n");
  72. return -ENODEV;
  73. }
  74. major = register_chrdev(0, RTLX_MODULE_NAME, &rtlx_fops);
  75. if (major < 0) {
  76. pr_err("rtlx_module_init: unable to register device\n");
  77. return major;
  78. }
  79. /* initialise the wait queues */
  80. for (i = 0; i < RTLX_CHANNELS; i++) {
  81. init_waitqueue_head(&channel_wqs[i].rt_queue);
  82. init_waitqueue_head(&channel_wqs[i].lx_queue);
  83. atomic_set(&channel_wqs[i].in_open, 0);
  84. mutex_init(&channel_wqs[i].mutex);
  85. dev = device_create(mt_class, NULL, MKDEV(major, i), NULL,
  86. "%s%d", RTLX_MODULE_NAME, i);
  87. if (IS_ERR(dev)) {
  88. while (i--)
  89. device_destroy(mt_class, MKDEV(major, i));
  90. err = PTR_ERR(dev);
  91. goto out_chrdev;
  92. }
  93. }
  94. /* set up notifiers */
  95. rtlx_notify.start = rtlx_starting;
  96. rtlx_notify.stop = rtlx_stopping;
  97. vpe_notify(aprp_cpu_index(), &rtlx_notify);
  98. if (cpu_has_vint) {
  99. aprp_hook = rtlx_dispatch;
  100. } else {
  101. pr_err("APRP RTLX init on non-vectored-interrupt processor\n");
  102. err = -ENODEV;
  103. goto out_class;
  104. }
  105. rtlx_irq.dev_id = rtlx;
  106. err = setup_irq(rtlx_irq_num, &rtlx_irq);
  107. if (err)
  108. goto out_class;
  109. return 0;
  110. out_class:
  111. for (i = 0; i < RTLX_CHANNELS; i++)
  112. device_destroy(mt_class, MKDEV(major, i));
  113. out_chrdev:
  114. unregister_chrdev(major, RTLX_MODULE_NAME);
  115. return err;
  116. }
  117. void __exit rtlx_module_exit(void)
  118. {
  119. int i;
  120. for (i = 0; i < RTLX_CHANNELS; i++)
  121. device_destroy(mt_class, MKDEV(major, i));
  122. unregister_chrdev(major, RTLX_MODULE_NAME);
  123. aprp_hook = NULL;
  124. }