11/*
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+ *
26 * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.
37 * Copyright (C) 2005, 06 Ralf Baechle (ralf@linux-mips.org)
4- *
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- *
8+ * Copyright (C) 2013 Imagination Technologies Ltd.
189 */
19-
20- #include <linux/device.h>
2110#include <linux/kernel.h>
2211#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>
2912#include <linux/syscalls.h>
3013#include <linux/moduleloader.h>
31- #include <linux/interrupt.h>
32- #include <linux/poll.h>
33- #include <linux/sched.h>
34- #include <linux/wait.h>
14+ #include <linux/atomic.h>
3515#include <asm/mipsmtregs.h>
3616#include <asm/mips_mt.h>
37- #include <asm/cacheflush.h>
38- #include <linux/atomic.h>
39- #include <asm/cpu.h>
4017#include <asm/processor.h>
41- #include <asm/vpe.h>
4218#include <asm/rtlx.h>
4319#include <asm/setup.h>
20+ #include <asm/vpe.h>
4421
4522static int sp_stopping ;
4623struct rtlx_info * rtlx ;
@@ -53,31 +30,30 @@ static void __used dump_rtlx(void)
5330{
5431 int i ;
5532
56- printk ("id 0x%lx state %d\n" , rtlx -> id , rtlx -> state );
33+ pr_info ("id 0x%lx state %d\n" , rtlx -> id , rtlx -> state );
5734
5835 for (i = 0 ; i < RTLX_CHANNELS ; i ++ ) {
5936 struct rtlx_channel * chan = & rtlx -> channel [i ];
6037
61- printk (" rt_state %d lx_state %d buffer_size %d\n" ,
62- chan -> rt_state , chan -> lx_state , chan -> buffer_size );
38+ pr_info (" rt_state %d lx_state %d buffer_size %d\n" ,
39+ chan -> rt_state , chan -> lx_state , chan -> buffer_size );
6340
64- printk (" rt_read %d rt_write %d\n" ,
65- chan -> rt_read , chan -> rt_write );
41+ pr_info (" rt_read %d rt_write %d\n" ,
42+ chan -> rt_read , chan -> rt_write );
6643
67- printk (" lx_read %d lx_write %d\n" ,
68- chan -> lx_read , chan -> lx_write );
44+ pr_info (" lx_read %d lx_write %d\n" ,
45+ chan -> lx_read , chan -> lx_write );
6946
70- printk (" rt_buffer <%s>\n" , chan -> rt_buffer );
71- printk (" lx_buffer <%s>\n" , chan -> lx_buffer );
47+ pr_info (" rt_buffer <%s>\n" , chan -> rt_buffer );
48+ pr_info (" lx_buffer <%s>\n" , chan -> lx_buffer );
7249 }
7350}
7451
7552/* call when we have the address of the shared structure from the SP side. */
7653static int rtlx_init (struct rtlx_info * rtlxi )
7754{
7855 if (rtlxi -> id != RTLX_ID ) {
79- printk (KERN_ERR "no valid RTLX id at 0x%p 0x%lx\n" ,
80- rtlxi , rtlxi -> id );
56+ pr_err ("no valid RTLX id at 0x%p 0x%lx\n" , rtlxi , rtlxi -> id );
8157 return - ENOEXEC ;
8258 }
8359
@@ -93,7 +69,7 @@ void rtlx_starting(int vpe)
9369 sp_stopping = 0 ;
9470
9571 /* force a reload of rtlx */
96- rtlx = NULL ;
72+ rtlx = NULL ;
9773
9874 /* wake up any sleeping rtlx_open's */
9975 for (i = 0 ; i < RTLX_CHANNELS ; i ++ )
@@ -118,31 +94,30 @@ int rtlx_open(int index, int can_sleep)
11894 int ret = 0 ;
11995
12096 if (index >= RTLX_CHANNELS ) {
121- printk (KERN_DEBUG "rtlx_open index out of range\n" );
97+ pr_debug (KERN_DEBUG "rtlx_open index out of range\n" );
12298 return - ENOSYS ;
12399 }
124100
125101 if (atomic_inc_return (& channel_wqs [index ].in_open ) > 1 ) {
126- printk (KERN_DEBUG "rtlx_open channel %d already opened\n" ,
127- index );
102+ pr_debug (KERN_DEBUG "rtlx_open channel %d already opened\n" , index );
128103 ret = - EBUSY ;
129104 goto out_fail ;
130105 }
131106
132107 if (rtlx == NULL ) {
133- if ( (p = vpe_get_shared (tclimit )) == NULL ) {
134- if (can_sleep ) {
135- ret = __wait_event_interruptible (
108+ p = vpe_get_shared (aprp_cpu_index ());
109+ if (p == NULL ) {
110+ if (can_sleep ) {
111+ ret = __wait_event_interruptible (
136112 channel_wqs [index ].lx_queue ,
137- (p = vpe_get_shared (tclimit )));
138- if (ret )
113+ (p = vpe_get_shared (aprp_cpu_index ())));
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 ;
139119 goto out_fail ;
140- } else {
141- printk (KERN_DEBUG "No SP program loaded, and device "
142- "opened with O_NONBLOCK\n" );
143- ret = - ENOSYS ;
144- goto out_fail ;
145- }
120+ }
146121 }
147122
148123 smp_rmb ();
@@ -164,24 +139,24 @@ int rtlx_open(int index, int can_sleep)
164139 ret = - ERESTARTSYS ;
165140 goto out_fail ;
166141 }
167- finish_wait (& channel_wqs [index ].lx_queue , & wait );
142+ finish_wait (& channel_wqs [index ].lx_queue ,
143+ & wait );
168144 } else {
169- pr_err (" *vpe_get_shared is NULL. "
170- "Has an SP program been loaded?\n" );
145+ pr_err (" *vpe_get_shared is NULL. Has an SP program been loaded?\n" );
171146 ret = - ENOSYS ;
172147 goto out_fail ;
173148 }
174149 }
175150
176151 if ((unsigned int )* p < KSEG0 ) {
177- printk (KERN_WARNING "vpe_get_shared returned an "
178- "invalid pointer maybe an error code %d\n" ,
179- (int )* p );
152+ pr_warn ("vpe_get_shared returned an invalid pointer maybe an error code %d\n" ,
153+ (int )* p );
180154 ret = - ENOSYS ;
181155 goto out_fail ;
182156 }
183157
184- if ((ret = rtlx_init (* p )) < 0 )
158+ ret = rtlx_init (* p );
159+ if (ret < 0 )
185160 goto out_ret ;
186161 }
187162
@@ -312,7 +287,7 @@ ssize_t rtlx_write(int index, const void __user *buffer, size_t count)
312287 size_t fl ;
313288
314289 if (rtlx == NULL )
315- return ( - ENOSYS ) ;
290+ return - ENOSYS ;
316291
317292 rt = & rtlx -> channel [index ];
318293
@@ -321,8 +296,8 @@ ssize_t rtlx_write(int index, const void __user *buffer, size_t count)
321296 rt_read = rt -> rt_read ;
322297
323298 /* total number of bytes to copy */
324- count = min ( count , ( size_t ) write_spacefree (rt_read , rt -> rt_write ,
325- rt -> buffer_size ));
299+ count = min_t ( size_t , count , write_spacefree (rt_read , rt -> rt_write ,
300+ rt -> buffer_size ));
326301
327302 /* first bit from write pointer to the end of the buffer, or count */
328303 fl = min (count , (size_t ) rt -> buffer_size - rt -> rt_write );
@@ -332,9 +307,8 @@ ssize_t rtlx_write(int index, const void __user *buffer, size_t count)
332307 goto out ;
333308
334309 /* if there's any left copy to the beginning of the buffer */
335- if (count - fl ) {
310+ if (count - fl )
336311 failed = copy_from_user (rt -> rt_buffer , buffer + fl , count - fl );
337- }
338312
339313out :
340314 count -= failed ;
@@ -360,7 +334,7 @@ static int file_release(struct inode *inode, struct file *filp)
360334 return rtlx_release (iminor (inode ));
361335}
362336
363- static unsigned int file_poll (struct file * file , poll_table * wait )
337+ static unsigned int file_poll (struct file * file , poll_table * wait )
364338{
365339 int minor = iminor (file_inode (file ));
366340 unsigned int mask = 0 ;
@@ -382,21 +356,20 @@ static unsigned int file_poll(struct file *file, poll_table * wait)
382356 return mask ;
383357}
384358
385- static ssize_t file_read (struct file * file , char __user * buffer , size_t count ,
386- loff_t * ppos )
359+ static ssize_t file_read (struct file * file , char __user * buffer , size_t count ,
360+ loff_t * ppos )
387361{
388362 int minor = iminor (file_inode (file ));
389363
390364 /* data available? */
391- if (!rtlx_read_poll (minor , (file -> f_flags & O_NONBLOCK ) ? 0 : 1 )) {
392- return 0 ; // -EAGAIN makes cat whinge
393- }
365+ if (!rtlx_read_poll (minor , (file -> f_flags & O_NONBLOCK ) ? 0 : 1 ))
366+ return 0 ; /* -EAGAIN makes 'cat' whine */
394367
395368 return rtlx_read (minor , buffer , count );
396369}
397370
398- static ssize_t file_write (struct file * file , const char __user * buffer ,
399- size_t count , loff_t * ppos )
371+ static ssize_t file_write (struct file * file , const char __user * buffer ,
372+ size_t count , loff_t * ppos )
400373{
401374 int minor = iminor (file_inode (file ));
402375
@@ -418,11 +391,11 @@ static ssize_t file_write(struct file *file, const char __user * buffer,
418391
419392const struct file_operations rtlx_fops = {
420393 .owner = THIS_MODULE ,
421- .open = file_open ,
394+ .open = file_open ,
422395 .release = file_release ,
423396 .write = file_write ,
424- .read = file_read ,
425- .poll = file_poll ,
397+ .read = file_read ,
398+ .poll = file_poll ,
426399 .llseek = noop_llseek ,
427400};
428401
0 commit comments