aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/kernel/rtlx.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/mips/kernel/rtlx.c')
-rw-r--r--arch/mips/kernel/rtlx.c273
1 files changed, 62 insertions, 211 deletions
diff --git a/arch/mips/kernel/rtlx.c b/arch/mips/kernel/rtlx.c
index 2c12ea1668d1..31b1b763cb29 100644
--- a/arch/mips/kernel/rtlx.c
+++ b/arch/mips/kernel/rtlx.c
@@ -1,114 +1,51 @@
1/* 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 *
2 * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved. 6 * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.
3 * Copyright (C) 2005, 06 Ralf Baechle (ralf@linux-mips.org) 7 * Copyright (C) 2005, 06 Ralf Baechle (ralf@linux-mips.org)
4 * 8 * Copyright (C) 2013 Imagination Technologies Ltd.
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17 *
18 */ 9 */
19
20#include <linux/device.h>
21#include <linux/kernel.h> 10#include <linux/kernel.h>
22#include <linux/fs.h> 11#include <linux/fs.h>
23#include <linux/init.h>
24#include <asm/uaccess.h>
25#include <linux/list.h>
26#include <linux/vmalloc.h>
27#include <linux/elf.h>
28#include <linux/seq_file.h>
29#include <linux/syscalls.h> 12#include <linux/syscalls.h>
30#include <linux/moduleloader.h> 13#include <linux/moduleloader.h>
31#include <linux/interrupt.h> 14#include <linux/atomic.h>
32#include <linux/poll.h>
33#include <linux/sched.h>
34#include <linux/wait.h>
35#include <asm/mipsmtregs.h> 15#include <asm/mipsmtregs.h>
36#include <asm/mips_mt.h> 16#include <asm/mips_mt.h>
37#include <asm/cacheflush.h>
38#include <linux/atomic.h>
39#include <asm/cpu.h>
40#include <asm/processor.h> 17#include <asm/processor.h>
41#include <asm/vpe.h>
42#include <asm/rtlx.h> 18#include <asm/rtlx.h>
43#include <asm/setup.h> 19#include <asm/setup.h>
20#include <asm/vpe.h>
44 21
45static struct rtlx_info *rtlx;
46static int major;
47static char module_name[] = "rtlx";
48
49static struct chan_waitqueues {
50 wait_queue_head_t rt_queue;
51 wait_queue_head_t lx_queue;
52 atomic_t in_open;
53 struct mutex mutex;
54} channel_wqs[RTLX_CHANNELS];
55
56static struct vpe_notifications notify;
57static int sp_stopping; 22static int sp_stopping;
58 23struct rtlx_info *rtlx;
59extern void *vpe_get_shared(int index); 24struct chan_waitqueues channel_wqs[RTLX_CHANNELS];
60 25struct vpe_notifications rtlx_notify;
61static void rtlx_dispatch(void) 26void (*aprp_hook)(void) = NULL;
62{ 27EXPORT_SYMBOL(aprp_hook);
63 do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ);
64}
65
66
67/* Interrupt handler may be called before rtlx_init has otherwise had
68 a chance to run.
69*/
70static irqreturn_t rtlx_interrupt(int irq, void *dev_id)
71{
72 unsigned int vpeflags;
73 unsigned long flags;
74 int i;
75
76 /* Ought not to be strictly necessary for SMTC builds */
77 local_irq_save(flags);
78 vpeflags = dvpe();
79 set_c0_status(0x100 << MIPS_CPU_RTLX_IRQ);
80 irq_enable_hazard();
81 evpe(vpeflags);
82 local_irq_restore(flags);
83
84 for (i = 0; i < RTLX_CHANNELS; i++) {
85 wake_up(&channel_wqs[i].lx_queue);
86 wake_up(&channel_wqs[i].rt_queue);
87 }
88
89 return IRQ_HANDLED;
90}
91 28
92static void __used dump_rtlx(void) 29static void __used dump_rtlx(void)
93{ 30{
94 int i; 31 int i;
95 32
96 printk("id 0x%lx state %d\n", rtlx->id, rtlx->state); 33 pr_info("id 0x%lx state %d\n", rtlx->id, rtlx->state);
97 34
98 for (i = 0; i < RTLX_CHANNELS; i++) { 35 for (i = 0; i < RTLX_CHANNELS; i++) {
99 struct rtlx_channel *chan = &rtlx->channel[i]; 36 struct rtlx_channel *chan = &rtlx->channel[i];
100 37
101 printk(" rt_state %d lx_state %d buffer_size %d\n", 38 pr_info(" rt_state %d lx_state %d buffer_size %d\n",
102 chan->rt_state, chan->lx_state, chan->buffer_size); 39 chan->rt_state, chan->lx_state, chan->buffer_size);
103 40
104 printk(" rt_read %d rt_write %d\n", 41 pr_info(" rt_read %d rt_write %d\n",
105 chan->rt_read, chan->rt_write); 42 chan->rt_read, chan->rt_write);
106 43
107 printk(" lx_read %d lx_write %d\n", 44 pr_info(" lx_read %d lx_write %d\n",
108 chan->lx_read, chan->lx_write); 45 chan->lx_read, chan->lx_write);
109 46
110 printk(" rt_buffer <%s>\n", chan->rt_buffer); 47 pr_info(" rt_buffer <%s>\n", chan->rt_buffer);
111 printk(" lx_buffer <%s>\n", chan->lx_buffer); 48 pr_info(" lx_buffer <%s>\n", chan->lx_buffer);
112 } 49 }
113} 50}
114 51
@@ -116,8 +53,7 @@ static void __used dump_rtlx(void)
116static int rtlx_init(struct rtlx_info *rtlxi) 53static int rtlx_init(struct rtlx_info *rtlxi)
117{ 54{
118 if (rtlxi->id != RTLX_ID) { 55 if (rtlxi->id != RTLX_ID) {
119 printk(KERN_ERR "no valid RTLX id at 0x%p 0x%lx\n", 56 pr_err("no valid RTLX id at 0x%p 0x%lx\n", rtlxi, rtlxi->id);
120 rtlxi, rtlxi->id);
121 return -ENOEXEC; 57 return -ENOEXEC;
122 } 58 }
123 59
@@ -127,20 +63,20 @@ static int rtlx_init(struct rtlx_info *rtlxi)
127} 63}
128 64
129/* notifications */ 65/* notifications */
130static void starting(int vpe) 66void rtlx_starting(int vpe)
131{ 67{
132 int i; 68 int i;
133 sp_stopping = 0; 69 sp_stopping = 0;
134 70
135 /* force a reload of rtlx */ 71 /* force a reload of rtlx */
136 rtlx=NULL; 72 rtlx = NULL;
137 73
138 /* wake up any sleeping rtlx_open's */ 74 /* wake up any sleeping rtlx_open's */
139 for (i = 0; i < RTLX_CHANNELS; i++) 75 for (i = 0; i < RTLX_CHANNELS; i++)
140 wake_up_interruptible(&channel_wqs[i].lx_queue); 76 wake_up_interruptible(&channel_wqs[i].lx_queue);
141} 77}
142 78
143static void stopping(int vpe) 79void rtlx_stopping(int vpe)
144{ 80{
145 int i; 81 int i;
146 82
@@ -158,31 +94,30 @@ int rtlx_open(int index, int can_sleep)
158 int ret = 0; 94 int ret = 0;
159 95
160 if (index >= RTLX_CHANNELS) { 96 if (index >= RTLX_CHANNELS) {
161 printk(KERN_DEBUG "rtlx_open index out of range\n"); 97 pr_debug(KERN_DEBUG "rtlx_open index out of range\n");
162 return -ENOSYS; 98 return -ENOSYS;
163 } 99 }
164 100
165 if (atomic_inc_return(&channel_wqs[index].in_open) > 1) { 101 if (atomic_inc_return(&channel_wqs[index].in_open) > 1) {
166 printk(KERN_DEBUG "rtlx_open channel %d already opened\n", 102 pr_debug(KERN_DEBUG "rtlx_open channel %d already opened\n", index);
167 index);
168 ret = -EBUSY; 103 ret = -EBUSY;
169 goto out_fail; 104 goto out_fail;
170 } 105 }
171 106
172 if (rtlx == NULL) { 107 if (rtlx == NULL) {
173 if( (p = vpe_get_shared(tclimit)) == NULL) { 108 p = vpe_get_shared(aprp_cpu_index());
174 if (can_sleep) { 109 if (p == NULL) {
175 ret = __wait_event_interruptible( 110 if (can_sleep) {
111 ret = __wait_event_interruptible(
176 channel_wqs[index].lx_queue, 112 channel_wqs[index].lx_queue,
177 (p = vpe_get_shared(tclimit))); 113 (p = vpe_get_shared(aprp_cpu_index())));
178 if (ret) 114 if (ret)
115 goto out_fail;
116 } else {
117 pr_debug("No SP program loaded, and device opened with O_NONBLOCK\n");
118 ret = -ENOSYS;
179 goto out_fail; 119 goto out_fail;
180 } else { 120 }
181 printk(KERN_DEBUG "No SP program loaded, and device "
182 "opened with O_NONBLOCK\n");
183 ret = -ENOSYS;
184 goto out_fail;
185 }
186 } 121 }
187 122
188 smp_rmb(); 123 smp_rmb();
@@ -204,24 +139,24 @@ int rtlx_open(int index, int can_sleep)
204 ret = -ERESTARTSYS; 139 ret = -ERESTARTSYS;
205 goto out_fail; 140 goto out_fail;
206 } 141 }
207 finish_wait(&channel_wqs[index].lx_queue, &wait); 142 finish_wait(&channel_wqs[index].lx_queue,
143 &wait);
208 } else { 144 } else {
209 pr_err(" *vpe_get_shared is NULL. " 145 pr_err(" *vpe_get_shared is NULL. Has an SP program been loaded?\n");
210 "Has an SP program been loaded?\n");
211 ret = -ENOSYS; 146 ret = -ENOSYS;
212 goto out_fail; 147 goto out_fail;
213 } 148 }
214 } 149 }
215 150
216 if ((unsigned int)*p < KSEG0) { 151 if ((unsigned int)*p < KSEG0) {
217 printk(KERN_WARNING "vpe_get_shared returned an " 152 pr_warn("vpe_get_shared returned an invalid pointer maybe an error code %d\n",
218 "invalid pointer maybe an error code %d\n", 153 (int)*p);
219 (int)*p);
220 ret = -ENOSYS; 154 ret = -ENOSYS;
221 goto out_fail; 155 goto out_fail;
222 } 156 }
223 157
224 if ((ret = rtlx_init(*p)) < 0) 158 ret = rtlx_init(*p);
159 if (ret < 0)
225 goto out_ret; 160 goto out_ret;
226 } 161 }
227 162
@@ -352,7 +287,7 @@ ssize_t rtlx_write(int index, const void __user *buffer, size_t count)
352 size_t fl; 287 size_t fl;
353 288
354 if (rtlx == NULL) 289 if (rtlx == NULL)
355 return(-ENOSYS); 290 return -ENOSYS;
356 291
357 rt = &rtlx->channel[index]; 292 rt = &rtlx->channel[index];
358 293
@@ -361,8 +296,8 @@ ssize_t rtlx_write(int index, const void __user *buffer, size_t count)
361 rt_read = rt->rt_read; 296 rt_read = rt->rt_read;
362 297
363 /* total number of bytes to copy */ 298 /* total number of bytes to copy */
364 count = min(count, (size_t)write_spacefree(rt_read, rt->rt_write, 299 count = min_t(size_t, count, write_spacefree(rt_read, rt->rt_write,
365 rt->buffer_size)); 300 rt->buffer_size));
366 301
367 /* first bit from write pointer to the end of the buffer, or count */ 302 /* first bit from write pointer to the end of the buffer, or count */
368 fl = min(count, (size_t) rt->buffer_size - rt->rt_write); 303 fl = min(count, (size_t) rt->buffer_size - rt->rt_write);
@@ -372,9 +307,8 @@ ssize_t rtlx_write(int index, const void __user *buffer, size_t count)
372 goto out; 307 goto out;
373 308
374 /* if there's any left copy to the beginning of the buffer */ 309 /* if there's any left copy to the beginning of the buffer */
375 if (count - fl) { 310 if (count - fl)
376 failed = copy_from_user(rt->rt_buffer, buffer + fl, count - fl); 311 failed = copy_from_user(rt->rt_buffer, buffer + fl, count - fl);
377 }
378 312
379out: 313out:
380 count -= failed; 314 count -= failed;
@@ -384,6 +318,8 @@ out:
384 smp_wmb(); 318 smp_wmb();
385 mutex_unlock(&channel_wqs[index].mutex); 319 mutex_unlock(&channel_wqs[index].mutex);
386 320
321 _interrupt_sp();
322
387 return count; 323 return count;
388} 324}
389 325
@@ -398,7 +334,7 @@ static int file_release(struct inode *inode, struct file *filp)
398 return rtlx_release(iminor(inode)); 334 return rtlx_release(iminor(inode));
399} 335}
400 336
401static unsigned int file_poll(struct file *file, poll_table * wait) 337static unsigned int file_poll(struct file *file, poll_table *wait)
402{ 338{
403 int minor = iminor(file_inode(file)); 339 int minor = iminor(file_inode(file));
404 unsigned int mask = 0; 340 unsigned int mask = 0;
@@ -420,21 +356,20 @@ static unsigned int file_poll(struct file *file, poll_table * wait)
420 return mask; 356 return mask;
421} 357}
422 358
423static ssize_t file_read(struct file *file, char __user * buffer, size_t count, 359static ssize_t file_read(struct file *file, char __user *buffer, size_t count,
424 loff_t * ppos) 360 loff_t *ppos)
425{ 361{
426 int minor = iminor(file_inode(file)); 362 int minor = iminor(file_inode(file));
427 363
428 /* data available? */ 364 /* data available? */
429 if (!rtlx_read_poll(minor, (file->f_flags & O_NONBLOCK) ? 0 : 1)) { 365 if (!rtlx_read_poll(minor, (file->f_flags & O_NONBLOCK) ? 0 : 1))
430 return 0; // -EAGAIN makes cat whinge 366 return 0; /* -EAGAIN makes 'cat' whine */
431 }
432 367
433 return rtlx_read(minor, buffer, count); 368 return rtlx_read(minor, buffer, count);
434} 369}
435 370
436static ssize_t file_write(struct file *file, const char __user * buffer, 371static ssize_t file_write(struct file *file, const char __user *buffer,
437 size_t count, loff_t * ppos) 372 size_t count, loff_t *ppos)
438{ 373{
439 int minor = iminor(file_inode(file)); 374 int minor = iminor(file_inode(file));
440 375
@@ -454,100 +389,16 @@ static ssize_t file_write(struct file *file, const char __user * buffer,
454 return rtlx_write(minor, buffer, count); 389 return rtlx_write(minor, buffer, count);
455} 390}
456 391
457static const struct file_operations rtlx_fops = { 392const struct file_operations rtlx_fops = {
458 .owner = THIS_MODULE, 393 .owner = THIS_MODULE,
459 .open = file_open, 394 .open = file_open,
460 .release = file_release, 395 .release = file_release,
461 .write = file_write, 396 .write = file_write,
462 .read = file_read, 397 .read = file_read,
463 .poll = file_poll, 398 .poll = file_poll,
464 .llseek = noop_llseek, 399 .llseek = noop_llseek,
465}; 400};
466 401
467static struct irqaction rtlx_irq = {
468 .handler = rtlx_interrupt,
469 .name = "RTLX",
470};
471
472static int rtlx_irq_num = MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ;
473
474static char register_chrdev_failed[] __initdata =
475 KERN_ERR "rtlx_module_init: unable to register device\n";
476
477static int __init rtlx_module_init(void)
478{
479 struct device *dev;
480 int i, err;
481
482 if (!cpu_has_mipsmt) {
483 printk("VPE loader: not a MIPS MT capable processor\n");
484 return -ENODEV;
485 }
486
487 if (tclimit == 0) {
488 printk(KERN_WARNING "No TCs reserved for AP/SP, not "
489 "initializing RTLX.\nPass maxtcs=<n> argument as kernel "
490 "argument\n");
491
492 return -ENODEV;
493 }
494
495 major = register_chrdev(0, module_name, &rtlx_fops);
496 if (major < 0) {
497 printk(register_chrdev_failed);
498 return major;
499 }
500
501 /* initialise the wait queues */
502 for (i = 0; i < RTLX_CHANNELS; i++) {
503 init_waitqueue_head(&channel_wqs[i].rt_queue);
504 init_waitqueue_head(&channel_wqs[i].lx_queue);
505 atomic_set(&channel_wqs[i].in_open, 0);
506 mutex_init(&channel_wqs[i].mutex);
507
508 dev = device_create(mt_class, NULL, MKDEV(major, i), NULL,
509 "%s%d", module_name, i);
510 if (IS_ERR(dev)) {
511 err = PTR_ERR(dev);
512 goto out_chrdev;
513 }
514 }
515
516 /* set up notifiers */
517 notify.start = starting;
518 notify.stop = stopping;
519 vpe_notify(tclimit, &notify);
520
521 if (cpu_has_vint)
522 set_vi_handler(MIPS_CPU_RTLX_IRQ, rtlx_dispatch);
523 else {
524 pr_err("APRP RTLX init on non-vectored-interrupt processor\n");
525 err = -ENODEV;
526 goto out_chrdev;
527 }
528
529 rtlx_irq.dev_id = rtlx;
530 setup_irq(rtlx_irq_num, &rtlx_irq);
531
532 return 0;
533
534out_chrdev:
535 for (i = 0; i < RTLX_CHANNELS; i++)
536 device_destroy(mt_class, MKDEV(major, i));
537
538 return err;
539}
540
541static void __exit rtlx_module_exit(void)
542{
543 int i;
544
545 for (i = 0; i < RTLX_CHANNELS; i++)
546 device_destroy(mt_class, MKDEV(major, i));
547
548 unregister_chrdev(major, module_name);
549}
550
551module_init(rtlx_module_init); 402module_init(rtlx_module_init);
552module_exit(rtlx_module_exit); 403module_exit(rtlx_module_exit);
553 404