rtlx-mt.c 3.2 KB

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