rtlx-cmp.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/smp.h>
  15. #include <asm/mips_mt.h>
  16. #include <asm/vpe.h>
  17. #include <asm/rtlx.h>
  18. static int major;
  19. static void rtlx_interrupt(void)
  20. {
  21. int i;
  22. struct rtlx_info *info;
  23. struct rtlx_info **p = vpe_get_shared(aprp_cpu_index());
  24. if (p == NULL || *p == NULL)
  25. return;
  26. info = *p;
  27. if (info->ap_int_pending == 1 && smp_processor_id() == 0) {
  28. for (i = 0; i < RTLX_CHANNELS; i++) {
  29. wake_up(&channel_wqs[i].lx_queue);
  30. wake_up(&channel_wqs[i].rt_queue);
  31. }
  32. info->ap_int_pending = 0;
  33. }
  34. }
  35. void _interrupt_sp(void)
  36. {
  37. smp_send_reschedule(aprp_cpu_index());
  38. }
  39. int __init rtlx_module_init(void)
  40. {
  41. struct device *dev;
  42. int i, err;
  43. if (!cpu_has_mipsmt) {
  44. pr_warn("VPE loader: not a MIPS MT capable processor\n");
  45. return -ENODEV;
  46. }
  47. if (num_possible_cpus() - aprp_cpu_index() < 1) {
  48. pr_warn("No TCs reserved for AP/SP, not initializing RTLX.\n"
  49. "Pass maxcpus=<n> argument as kernel argument\n");
  50. return -ENODEV;
  51. }
  52. major = register_chrdev(0, RTLX_MODULE_NAME, &rtlx_fops);
  53. if (major < 0) {
  54. pr_err("rtlx_module_init: unable to register device\n");
  55. return major;
  56. }
  57. /* initialise the wait queues */
  58. for (i = 0; i < RTLX_CHANNELS; i++) {
  59. init_waitqueue_head(&channel_wqs[i].rt_queue);
  60. init_waitqueue_head(&channel_wqs[i].lx_queue);
  61. atomic_set(&channel_wqs[i].in_open, 0);
  62. mutex_init(&channel_wqs[i].mutex);
  63. dev = device_create(mt_class, NULL, MKDEV(major, i), NULL,
  64. "%s%d", RTLX_MODULE_NAME, i);
  65. if (IS_ERR(dev)) {
  66. while (i--)
  67. device_destroy(mt_class, MKDEV(major, i));
  68. err = PTR_ERR(dev);
  69. goto out_chrdev;
  70. }
  71. }
  72. /* set up notifiers */
  73. rtlx_notify.start = rtlx_starting;
  74. rtlx_notify.stop = rtlx_stopping;
  75. vpe_notify(aprp_cpu_index(), &rtlx_notify);
  76. if (cpu_has_vint) {
  77. aprp_hook = rtlx_interrupt;
  78. } else {
  79. pr_err("APRP RTLX init on non-vectored-interrupt processor\n");
  80. err = -ENODEV;
  81. goto out_class;
  82. }
  83. return 0;
  84. out_class:
  85. for (i = 0; i < RTLX_CHANNELS; i++)
  86. device_destroy(mt_class, MKDEV(major, i));
  87. out_chrdev:
  88. unregister_chrdev(major, RTLX_MODULE_NAME);
  89. return err;
  90. }
  91. void __exit rtlx_module_exit(void)
  92. {
  93. int i;
  94. for (i = 0; i < RTLX_CHANNELS; i++)
  95. device_destroy(mt_class, MKDEV(major, i));
  96. unregister_chrdev(major, RTLX_MODULE_NAME);
  97. aprp_hook = NULL;
  98. }