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