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
6 * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.
7 * Copyright (C) 2013 Imagination Technologies Ltd.
9 #include <linux/device.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>
17 #include <asm/mips_mt.h>
23 static void rtlx_dispatch(void)
25 if (read_c0_cause() & read_c0_status() & C_SW0
)
26 do_IRQ(MIPS_CPU_IRQ_BASE
+ MIPS_CPU_RTLX_IRQ
);
30 * Interrupt handler may be called before rtlx_init has otherwise had
33 static irqreturn_t
rtlx_interrupt(int irq
, void *dev_id
)
35 unsigned int vpeflags
;
39 local_irq_save(flags
);
41 set_c0_status(0x100 << MIPS_CPU_RTLX_IRQ
);
44 local_irq_restore(flags
);
46 for (i
= 0; i
< RTLX_CHANNELS
; i
++) {
47 wake_up(&channel_wqs
[i
].lx_queue
);
48 wake_up(&channel_wqs
[i
].rt_queue
);
54 static struct irqaction rtlx_irq
= {
55 .handler
= rtlx_interrupt
,
59 static int rtlx_irq_num
= MIPS_CPU_IRQ_BASE
+ MIPS_CPU_RTLX_IRQ
;
61 void _interrupt_sp(void)
65 local_irq_save(flags
);
68 write_vpe_c0_cause(read_vpe_c0_cause() | C_SW0
);
70 local_irq_restore(flags
);
73 int __init
rtlx_module_init(void)
78 if (!cpu_has_mipsmt
) {
79 pr_warn("VPE loader: not a MIPS MT capable processor\n");
83 if (aprp_cpu_index() == 0) {
84 pr_warn("No TCs reserved for AP/SP, not initializing RTLX.\n"
85 "Pass maxtcs=<n> argument as kernel argument\n");
90 major
= register_chrdev(0, RTLX_MODULE_NAME
, &rtlx_fops
);
92 pr_err("rtlx_module_init: unable to register device\n");
96 /* initialise the wait queues */
97 for (i
= 0; i
< RTLX_CHANNELS
; i
++) {
98 init_waitqueue_head(&channel_wqs
[i
].rt_queue
);
99 init_waitqueue_head(&channel_wqs
[i
].lx_queue
);
100 atomic_set(&channel_wqs
[i
].in_open
, 0);
101 mutex_init(&channel_wqs
[i
].mutex
);
103 dev
= device_create(mt_class
, NULL
, MKDEV(major
, i
), NULL
,
104 "%s%d", RTLX_MODULE_NAME
, i
);
107 device_destroy(mt_class
, MKDEV(major
, i
));
114 /* set up notifiers */
115 rtlx_notify
.start
= rtlx_starting
;
116 rtlx_notify
.stop
= rtlx_stopping
;
117 vpe_notify(aprp_cpu_index(), &rtlx_notify
);
120 aprp_hook
= rtlx_dispatch
;
122 pr_err("APRP RTLX init on non-vectored-interrupt processor\n");
127 rtlx_irq
.dev_id
= rtlx
;
128 err
= setup_irq(rtlx_irq_num
, &rtlx_irq
);
135 for (i
= 0; i
< RTLX_CHANNELS
; i
++)
136 device_destroy(mt_class
, MKDEV(major
, i
));
138 unregister_chrdev(major
, RTLX_MODULE_NAME
);
143 void __exit
rtlx_module_exit(void)
147 for (i
= 0; i
< RTLX_CHANNELS
; i
++)
148 device_destroy(mt_class
, MKDEV(major
, i
));
150 unregister_chrdev(major
, RTLX_MODULE_NAME
);