blob: c5c4fd54d797221256e147a8a0be5278a8806df5 [file] [log] [blame]
Ralf Baechlee01402b2005-07-14 15:57:16 +00001/*
Steven J. Hill5792bf62014-01-01 16:35:32 +01002 * 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 *
Ralf Baechlee01402b2005-07-14 15:57:16 +00006 * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.
Ralf Baechlea84c96e2006-01-15 18:11:28 +00007 * Copyright (C) 2005, 06 Ralf Baechle (ralf@linux-mips.org)
Steven J. Hill5792bf62014-01-01 16:35:32 +01008 * Copyright (C) 2013 Imagination Technologies Ltd.
Ralf Baechlee01402b2005-07-14 15:57:16 +00009 */
Ralf Baechlee01402b2005-07-14 15:57:16 +000010#include <linux/kernel.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000011#include <linux/fs.h>
Ralf Baechle26009902006-04-05 09:45:45 +010012#include <linux/syscalls.h>
13#include <linux/moduleloader.h>
Steven J. Hill5792bf62014-01-01 16:35:32 +010014#include <linux/atomic.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000015#include <asm/mipsmtregs.h>
Ralf Baechlebb3d7c72007-02-07 15:36:56 +000016#include <asm/mips_mt.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000017#include <asm/processor.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000018#include <asm/rtlx.h>
Yoichi Yuasa406b5ee2013-05-28 01:23:22 +000019#include <asm/setup.h>
Steven J. Hill5792bf62014-01-01 16:35:32 +010020#include <asm/vpe.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000021
Ralf Baechle982f6ff2009-09-17 02:25:07 +020022static int sp_stopping;
Deng-Cheng Zhu2c973ef2014-01-01 16:26:46 +010023struct rtlx_info *rtlx;
24struct chan_waitqueues channel_wqs[RTLX_CHANNELS];
25struct vpe_notifications rtlx_notify;
26void (*aprp_hook)(void) = NULL;
27EXPORT_SYMBOL(aprp_hook);
Ralf Baechlee01402b2005-07-14 15:57:16 +000028
David Rientjesf5dbeaf2007-07-22 01:01:39 -070029static void __used dump_rtlx(void)
Ralf Baechlee01402b2005-07-14 15:57:16 +000030{
31 int i;
32
Steven J. Hill5792bf62014-01-01 16:35:32 +010033 pr_info("id 0x%lx state %d\n", rtlx->id, rtlx->state);
Ralf Baechle26009902006-04-05 09:45:45 +010034
35 for (i = 0; i < RTLX_CHANNELS; i++) {
36 struct rtlx_channel *chan = &rtlx->channel[i];
37
Steven J. Hill5792bf62014-01-01 16:35:32 +010038 pr_info(" rt_state %d lx_state %d buffer_size %d\n",
39 chan->rt_state, chan->lx_state, chan->buffer_size);
Ralf Baechle26009902006-04-05 09:45:45 +010040
Steven J. Hill5792bf62014-01-01 16:35:32 +010041 pr_info(" rt_read %d rt_write %d\n",
42 chan->rt_read, chan->rt_write);
Ralf Baechle26009902006-04-05 09:45:45 +010043
Steven J. Hill5792bf62014-01-01 16:35:32 +010044 pr_info(" lx_read %d lx_write %d\n",
45 chan->lx_read, chan->lx_write);
Ralf Baechle26009902006-04-05 09:45:45 +010046
Steven J. Hill5792bf62014-01-01 16:35:32 +010047 pr_info(" rt_buffer <%s>\n", chan->rt_buffer);
48 pr_info(" lx_buffer <%s>\n", chan->lx_buffer);
Ralf Baechle26009902006-04-05 09:45:45 +010049 }
50}
51
52/* call when we have the address of the shared structure from the SP side. */
53static int rtlx_init(struct rtlx_info *rtlxi)
54{
Ralf Baechlee01402b2005-07-14 15:57:16 +000055 if (rtlxi->id != RTLX_ID) {
Steven J. Hill5792bf62014-01-01 16:35:32 +010056 pr_err("no valid RTLX id at 0x%p 0x%lx\n", rtlxi, rtlxi->id);
Ralf Baechleafc48412005-10-31 00:30:39 +000057 return -ENOEXEC;
Ralf Baechlee01402b2005-07-14 15:57:16 +000058 }
59
Ralf Baechlee01402b2005-07-14 15:57:16 +000060 rtlx = rtlxi;
Ralf Baechleafc48412005-10-31 00:30:39 +000061
62 return 0;
Ralf Baechlee01402b2005-07-14 15:57:16 +000063}
64
Ralf Baechle26009902006-04-05 09:45:45 +010065/* notifications */
Deng-Cheng Zhu2c973ef2014-01-01 16:26:46 +010066void rtlx_starting(int vpe)
Ralf Baechlee01402b2005-07-14 15:57:16 +000067{
Ralf Baechle26009902006-04-05 09:45:45 +010068 int i;
69 sp_stopping = 0;
Ralf Baechlee01402b2005-07-14 15:57:16 +000070
Ralf Baechle26009902006-04-05 09:45:45 +010071 /* force a reload of rtlx */
Steven J. Hill5792bf62014-01-01 16:35:32 +010072 rtlx = NULL;
Ralf Baechle26009902006-04-05 09:45:45 +010073
74 /* wake up any sleeping rtlx_open's */
75 for (i = 0; i < RTLX_CHANNELS; i++)
76 wake_up_interruptible(&channel_wqs[i].lx_queue);
77}
78
Deng-Cheng Zhu2c973ef2014-01-01 16:26:46 +010079void rtlx_stopping(int vpe)
Ralf Baechle26009902006-04-05 09:45:45 +010080{
81 int i;
82
83 sp_stopping = 1;
84 for (i = 0; i < RTLX_CHANNELS; i++)
85 wake_up_interruptible(&channel_wqs[i].lx_queue);
86}
87
88
89int rtlx_open(int index, int can_sleep)
90{
Ralf Baechle9e346822007-03-15 17:08:28 +000091 struct rtlx_info **p;
Ralf Baechle67e2ccc2007-02-22 14:19:48 +000092 struct rtlx_channel *chan;
Ralf Baechlec4c40182007-02-23 13:40:45 +000093 enum rtlx_state state;
Ralf Baechle67e2ccc2007-02-22 14:19:48 +000094 int ret = 0;
Ralf Baechle26009902006-04-05 09:45:45 +010095
96 if (index >= RTLX_CHANNELS) {
Masanari Iida3dc4bf32014-10-07 12:57:45 +090097 pr_debug("rtlx_open index out of range\n");
Ralf Baechle26009902006-04-05 09:45:45 +010098 return -ENOSYS;
99 }
100
Ralf Baechlec4c40182007-02-23 13:40:45 +0000101 if (atomic_inc_return(&channel_wqs[index].in_open) > 1) {
Masanari Iida3dc4bf32014-10-07 12:57:45 +0900102 pr_debug("rtlx_open channel %d already opened\n", index);
Ralf Baechlec4c40182007-02-23 13:40:45 +0000103 ret = -EBUSY;
104 goto out_fail;
Ralf Baechle26009902006-04-05 09:45:45 +0100105 }
106
Ralf Baechlee01402b2005-07-14 15:57:16 +0000107 if (rtlx == NULL) {
Steven J. Hill5792bf62014-01-01 16:35:32 +0100108 p = vpe_get_shared(aprp_cpu_index());
109 if (p == NULL) {
110 if (can_sleep) {
111 ret = __wait_event_interruptible(
Peter Zijlstra35a2af92013-10-02 11:22:33 +0200112 channel_wqs[index].lx_queue,
Steven J. Hill5792bf62014-01-01 16:35:32 +0100113 (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;
Ralf Baechle67e2ccc2007-02-22 14:19:48 +0000119 goto out_fail;
Steven J. Hill5792bf62014-01-01 16:35:32 +0100120 }
Ralf Baechlee01402b2005-07-14 15:57:16 +0000121 }
122
Ralf Baechle9e346822007-03-15 17:08:28 +0000123 smp_rmb();
Ralf Baechlee01402b2005-07-14 15:57:16 +0000124 if (*p == NULL) {
Ralf Baechle26009902006-04-05 09:45:45 +0100125 if (can_sleep) {
Ralf Baechle9e346822007-03-15 17:08:28 +0000126 DEFINE_WAIT(wait);
127
128 for (;;) {
Kevin D. Kissell1928cc82008-04-16 15:32:22 +0200129 prepare_to_wait(
130 &channel_wqs[index].lx_queue,
131 &wait, TASK_INTERRUPTIBLE);
Ralf Baechle9e346822007-03-15 17:08:28 +0000132 smp_rmb();
133 if (*p != NULL)
134 break;
135 if (!signal_pending(current)) {
136 schedule();
137 continue;
138 }
139 ret = -ERESTARTSYS;
Ralf Baechle67e2ccc2007-02-22 14:19:48 +0000140 goto out_fail;
Ralf Baechle9e346822007-03-15 17:08:28 +0000141 }
Steven J. Hill5792bf62014-01-01 16:35:32 +0100142 finish_wait(&channel_wqs[index].lx_queue,
143 &wait);
Ralf Baechle67e2ccc2007-02-22 14:19:48 +0000144 } else {
Steven J. Hill5792bf62014-01-01 16:35:32 +0100145 pr_err(" *vpe_get_shared is NULL. Has an SP program been loaded?\n");
Ralf Baechle67e2ccc2007-02-22 14:19:48 +0000146 ret = -ENOSYS;
147 goto out_fail;
Ralf Baechle26009902006-04-05 09:45:45 +0100148 }
Ralf Baechlee01402b2005-07-14 15:57:16 +0000149 }
150
Ralf Baechle26009902006-04-05 09:45:45 +0100151 if ((unsigned int)*p < KSEG0) {
Steven J. Hill5792bf62014-01-01 16:35:32 +0100152 pr_warn("vpe_get_shared returned an invalid pointer maybe an error code %d\n",
153 (int)*p);
Ralf Baechle67e2ccc2007-02-22 14:19:48 +0000154 ret = -ENOSYS;
155 goto out_fail;
Ralf Baechle26009902006-04-05 09:45:45 +0100156 }
157
Steven J. Hill5792bf62014-01-01 16:35:32 +0100158 ret = rtlx_init(*p);
159 if (ret < 0)
Ralf Baechlec4c40182007-02-23 13:40:45 +0000160 goto out_ret;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000161 }
162
Ralf Baechle26009902006-04-05 09:45:45 +0100163 chan = &rtlx->channel[index];
Ralf Baechlee01402b2005-07-14 15:57:16 +0000164
Ralf Baechlec4c40182007-02-23 13:40:45 +0000165 state = xchg(&chan->lx_state, RTLX_STATE_OPENED);
166 if (state == RTLX_STATE_OPENED) {
167 ret = -EBUSY;
168 goto out_fail;
169 }
Ralf Baechle67e2ccc2007-02-22 14:19:48 +0000170
171out_fail:
Ralf Baechlec4c40182007-02-23 13:40:45 +0000172 smp_mb();
173 atomic_dec(&channel_wqs[index].in_open);
174 smp_mb();
Ralf Baechle67e2ccc2007-02-22 14:19:48 +0000175
Ralf Baechlec4c40182007-02-23 13:40:45 +0000176out_ret:
Ralf Baechle67e2ccc2007-02-22 14:19:48 +0000177 return ret;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000178}
179
Ralf Baechle26009902006-04-05 09:45:45 +0100180int rtlx_release(int index)
Ralf Baechlee01402b2005-07-14 15:57:16 +0000181{
Kevin D. Kissell1928cc82008-04-16 15:32:22 +0200182 if (rtlx == NULL) {
183 pr_err("rtlx_release() with null rtlx\n");
184 return 0;
185 }
Ralf Baechle26009902006-04-05 09:45:45 +0100186 rtlx->channel[index].lx_state = RTLX_STATE_UNUSED;
Ralf Baechleafc48412005-10-31 00:30:39 +0000187 return 0;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000188}
189
Ralf Baechle26009902006-04-05 09:45:45 +0100190unsigned int rtlx_read_poll(int index, int can_sleep)
Ralf Baechlee01402b2005-07-14 15:57:16 +0000191{
Ralf Baechle70342282013-01-22 12:59:30 +0100192 struct rtlx_channel *chan;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000193
Ralf Baechle70342282013-01-22 12:59:30 +0100194 if (rtlx == NULL)
195 return 0;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000196
Ralf Baechle70342282013-01-22 12:59:30 +0100197 chan = &rtlx->channel[index];
Ralf Baechlee01402b2005-07-14 15:57:16 +0000198
199 /* data available to read? */
Ralf Baechle26009902006-04-05 09:45:45 +0100200 if (chan->lx_read == chan->lx_write) {
201 if (can_sleep) {
Peter Zijlstra35a2af92013-10-02 11:22:33 +0200202 int ret = __wait_event_interruptible(
203 channel_wqs[index].lx_queue,
Kevin D. Kissell1928cc82008-04-16 15:32:22 +0200204 (chan->lx_read != chan->lx_write) ||
Peter Zijlstra35a2af92013-10-02 11:22:33 +0200205 sp_stopping);
Ralf Baechle67e2ccc2007-02-22 14:19:48 +0000206 if (ret)
207 return ret;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000208
Ralf Baechle67e2ccc2007-02-22 14:19:48 +0000209 if (sp_stopping)
210 return 0;
211 } else
Ralf Baechle26009902006-04-05 09:45:45 +0100212 return 0;
213 }
214
215 return (chan->lx_write + chan->buffer_size - chan->lx_read)
216 % chan->buffer_size;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000217}
218
Ralf Baechle26009902006-04-05 09:45:45 +0100219static inline int write_spacefree(int read, int write, int size)
Ralf Baechlee01402b2005-07-14 15:57:16 +0000220{
Ralf Baechle26009902006-04-05 09:45:45 +0100221 if (read == write) {
222 /*
223 * Never fill the buffer completely, so indexes are always
224 * equal if empty and only empty, or !equal if data available
225 */
226 return size - 1;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000227 }
228
Ralf Baechle26009902006-04-05 09:45:45 +0100229 return ((read + size - write) % size) - 1;
230}
231
232unsigned int rtlx_write_poll(int index)
233{
234 struct rtlx_channel *chan = &rtlx->channel[index];
Kevin D. Kissell1928cc82008-04-16 15:32:22 +0200235
236 return write_spacefree(chan->rt_read, chan->rt_write,
237 chan->buffer_size);
Ralf Baechle26009902006-04-05 09:45:45 +0100238}
239
Ralf Baechle7f5a7712007-04-25 15:08:57 +0100240ssize_t rtlx_read(int index, void __user *buff, size_t count)
Ralf Baechle26009902006-04-05 09:45:45 +0100241{
Ralf Baechle61dcc6f2007-03-15 17:10:16 +0000242 size_t lx_write, fl = 0L;
Ralf Baechle26009902006-04-05 09:45:45 +0100243 struct rtlx_channel *lx;
Ralf Baechle46230aa2007-03-16 12:16:27 +0000244 unsigned long failed;
Ralf Baechle26009902006-04-05 09:45:45 +0100245
246 if (rtlx == NULL)
247 return -ENOSYS;
248
249 lx = &rtlx->channel[index];
250
Ralf Baechlebc4809e2007-03-15 17:13:47 +0000251 mutex_lock(&channel_wqs[index].mutex);
Ralf Baechle61dcc6f2007-03-15 17:10:16 +0000252 smp_rmb();
253 lx_write = lx->lx_write;
254
Ralf Baechlee01402b2005-07-14 15:57:16 +0000255 /* find out how much in total */
Ralf Baechleafc48412005-10-31 00:30:39 +0000256 count = min(count,
Ralf Baechle61dcc6f2007-03-15 17:10:16 +0000257 (size_t)(lx_write + lx->buffer_size - lx->lx_read)
Ralf Baechle26009902006-04-05 09:45:45 +0100258 % lx->buffer_size);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000259
260 /* then how much from the read pointer onwards */
Ralf Baechle61dcc6f2007-03-15 17:10:16 +0000261 fl = min(count, (size_t)lx->buffer_size - lx->lx_read);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000262
Ralf Baechle46230aa2007-03-16 12:16:27 +0000263 failed = copy_to_user(buff, lx->lx_buffer + lx->lx_read, fl);
264 if (failed)
265 goto out;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000266
267 /* and if there is anything left at the beginning of the buffer */
Ralf Baechle61dcc6f2007-03-15 17:10:16 +0000268 if (count - fl)
Ralf Baechle46230aa2007-03-16 12:16:27 +0000269 failed = copy_to_user(buff + fl, lx->lx_buffer, count - fl);
270
271out:
272 count -= failed;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000273
Ralf Baechle61dcc6f2007-03-15 17:10:16 +0000274 smp_wmb();
275 lx->lx_read = (lx->lx_read + count) % lx->buffer_size;
276 smp_wmb();
Ralf Baechlebc4809e2007-03-15 17:13:47 +0000277 mutex_unlock(&channel_wqs[index].mutex);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000278
Ralf Baechleafc48412005-10-31 00:30:39 +0000279 return count;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000280}
281
Ralf Baechle7f5a7712007-04-25 15:08:57 +0100282ssize_t rtlx_write(int index, const void __user *buffer, size_t count)
Ralf Baechlee01402b2005-07-14 15:57:16 +0000283{
Ralf Baechlee01402b2005-07-14 15:57:16 +0000284 struct rtlx_channel *rt;
Ralf Baechle7f5a7712007-04-25 15:08:57 +0100285 unsigned long failed;
Ralf Baechle61dcc6f2007-03-15 17:10:16 +0000286 size_t rt_read;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000287 size_t fl;
Ralf Baechle26009902006-04-05 09:45:45 +0100288
289 if (rtlx == NULL)
Steven J. Hill5792bf62014-01-01 16:35:32 +0100290 return -ENOSYS;
Ralf Baechle26009902006-04-05 09:45:45 +0100291
292 rt = &rtlx->channel[index];
293
Ralf Baechlebc4809e2007-03-15 17:13:47 +0000294 mutex_lock(&channel_wqs[index].mutex);
Ralf Baechle61dcc6f2007-03-15 17:10:16 +0000295 smp_rmb();
296 rt_read = rt->rt_read;
297
Ralf Baechle26009902006-04-05 09:45:45 +0100298 /* total number of bytes to copy */
Steven J. Hill5792bf62014-01-01 16:35:32 +0100299 count = min_t(size_t, count, write_spacefree(rt_read, rt->rt_write,
300 rt->buffer_size));
Ralf Baechle26009902006-04-05 09:45:45 +0100301
302 /* first bit from write pointer to the end of the buffer, or count */
303 fl = min(count, (size_t) rt->buffer_size - rt->rt_write);
304
Ralf Baechle46230aa2007-03-16 12:16:27 +0000305 failed = copy_from_user(rt->rt_buffer + rt->rt_write, buffer, fl);
306 if (failed)
307 goto out;
Ralf Baechle26009902006-04-05 09:45:45 +0100308
309 /* if there's any left copy to the beginning of the buffer */
Steven J. Hill5792bf62014-01-01 16:35:32 +0100310 if (count - fl)
Ralf Baechle46230aa2007-03-16 12:16:27 +0000311 failed = copy_from_user(rt->rt_buffer, buffer + fl, count - fl);
Ralf Baechle46230aa2007-03-16 12:16:27 +0000312
313out:
Ralf Baechle7f5a7712007-04-25 15:08:57 +0100314 count -= failed;
Ralf Baechle26009902006-04-05 09:45:45 +0100315
Ralf Baechle61dcc6f2007-03-15 17:10:16 +0000316 smp_wmb();
317 rt->rt_write = (rt->rt_write + count) % rt->buffer_size;
318 smp_wmb();
Ralf Baechlebc4809e2007-03-15 17:13:47 +0000319 mutex_unlock(&channel_wqs[index].mutex);
Ralf Baechle26009902006-04-05 09:45:45 +0100320
Deng-Cheng Zhu2c973ef2014-01-01 16:26:46 +0100321 _interrupt_sp();
322
Ralf Baechle61dcc6f2007-03-15 17:10:16 +0000323 return count;
Ralf Baechle26009902006-04-05 09:45:45 +0100324}
325
326
327static int file_open(struct inode *inode, struct file *filp)
328{
Ralf Baechle1bbfc202009-09-29 00:52:27 +0100329 return rtlx_open(iminor(inode), (filp->f_flags & O_NONBLOCK) ? 0 : 1);
Ralf Baechle26009902006-04-05 09:45:45 +0100330}
331
332static int file_release(struct inode *inode, struct file *filp)
333{
Ralf Baechle1bbfc202009-09-29 00:52:27 +0100334 return rtlx_release(iminor(inode));
Ralf Baechle26009902006-04-05 09:45:45 +0100335}
336
Steven J. Hill5792bf62014-01-01 16:35:32 +0100337static unsigned int file_poll(struct file *file, poll_table *wait)
Ralf Baechle26009902006-04-05 09:45:45 +0100338{
Al Viro496ad9a2013-01-23 17:07:38 -0500339 int minor = iminor(file_inode(file));
Ralf Baechle26009902006-04-05 09:45:45 +0100340 unsigned int mask = 0;
341
Ralf Baechle26009902006-04-05 09:45:45 +0100342 poll_wait(file, &channel_wqs[minor].rt_queue, wait);
343 poll_wait(file, &channel_wqs[minor].lx_queue, wait);
344
345 if (rtlx == NULL)
346 return 0;
347
348 /* data available to read? */
349 if (rtlx_read_poll(minor, 0))
350 mask |= POLLIN | POLLRDNORM;
351
352 /* space to write */
353 if (rtlx_write_poll(minor))
354 mask |= POLLOUT | POLLWRNORM;
355
356 return mask;
357}
358
Steven J. Hill5792bf62014-01-01 16:35:32 +0100359static ssize_t file_read(struct file *file, char __user *buffer, size_t count,
360 loff_t *ppos)
Ralf Baechle26009902006-04-05 09:45:45 +0100361{
Al Viro496ad9a2013-01-23 17:07:38 -0500362 int minor = iminor(file_inode(file));
Ralf Baechle26009902006-04-05 09:45:45 +0100363
364 /* data available? */
Steven J. Hill5792bf62014-01-01 16:35:32 +0100365 if (!rtlx_read_poll(minor, (file->f_flags & O_NONBLOCK) ? 0 : 1))
366 return 0; /* -EAGAIN makes 'cat' whine */
Ralf Baechle26009902006-04-05 09:45:45 +0100367
Ralf Baechle46230aa2007-03-16 12:16:27 +0000368 return rtlx_read(minor, buffer, count);
Ralf Baechle26009902006-04-05 09:45:45 +0100369}
370
Steven J. Hill5792bf62014-01-01 16:35:32 +0100371static ssize_t file_write(struct file *file, const char __user *buffer,
372 size_t count, loff_t *ppos)
Ralf Baechle26009902006-04-05 09:45:45 +0100373{
Al Viro496ad9a2013-01-23 17:07:38 -0500374 int minor = iminor(file_inode(file));
Ralf Baechlee01402b2005-07-14 15:57:16 +0000375
376 /* any space left... */
Ralf Baechle26009902006-04-05 09:45:45 +0100377 if (!rtlx_write_poll(minor)) {
Peter Zijlstra35a2af92013-10-02 11:22:33 +0200378 int ret;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000379
380 if (file->f_flags & O_NONBLOCK)
Ralf Baechleafc48412005-10-31 00:30:39 +0000381 return -EAGAIN;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000382
Peter Zijlstra35a2af92013-10-02 11:22:33 +0200383 ret = __wait_event_interruptible(channel_wqs[minor].rt_queue,
384 rtlx_write_poll(minor));
Ralf Baechle67e2ccc2007-02-22 14:19:48 +0000385 if (ret)
386 return ret;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000387 }
388
Ralf Baechle46230aa2007-03-16 12:16:27 +0000389 return rtlx_write(minor, buffer, count);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000390}
391
Deng-Cheng Zhu2c973ef2014-01-01 16:26:46 +0100392const struct file_operations rtlx_fops = {
Ralf Baechle26009902006-04-05 09:45:45 +0100393 .owner = THIS_MODULE,
Steven J. Hill5792bf62014-01-01 16:35:32 +0100394 .open = file_open,
Ralf Baechle26009902006-04-05 09:45:45 +0100395 .release = file_release,
396 .write = file_write,
Steven J. Hill5792bf62014-01-01 16:35:32 +0100397 .read = file_read,
398 .poll = file_poll,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200399 .llseek = noop_llseek,
Ralf Baechlee01402b2005-07-14 15:57:16 +0000400};
401
Ralf Baechlee01402b2005-07-14 15:57:16 +0000402module_init(rtlx_module_init);
403module_exit(rtlx_module_exit);
Ralf Baechleafc48412005-10-31 00:30:39 +0000404
Ralf Baechlee01402b2005-07-14 15:57:16 +0000405MODULE_DESCRIPTION("MIPS RTLX");
Ralf Baechle26009902006-04-05 09:45:45 +0100406MODULE_AUTHOR("Elizabeth Oldham, MIPS Technologies, Inc.");
Ralf Baechlee01402b2005-07-14 15:57:16 +0000407MODULE_LICENSE("GPL");