| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2005 MIPS Technologies, Inc.  All rights reserved. | 
| Ralf Baechle | a84c96e | 2006-01-15 18:11:28 +0000 | [diff] [blame] | 3 | * Copyright (C) 2005, 06 Ralf Baechle (ralf@linux-mips.org) | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 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 | * | 
|  | 18 | */ | 
|  | 19 |  | 
| Ralf Baechle | bb3d7c7 | 2007-02-07 15:36:56 +0000 | [diff] [blame] | 20 | #include <linux/device.h> | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 21 | #include <linux/kernel.h> | 
|  | 22 | #include <linux/module.h> | 
|  | 23 | #include <linux/fs.h> | 
|  | 24 | #include <linux/init.h> | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 25 | #include <asm/uaccess.h> | 
|  | 26 | #include <linux/slab.h> | 
|  | 27 | #include <linux/list.h> | 
|  | 28 | #include <linux/vmalloc.h> | 
|  | 29 | #include <linux/elf.h> | 
|  | 30 | #include <linux/seq_file.h> | 
| Jonathan Corbet | 7558da9 | 2008-05-15 09:10:50 -0600 | [diff] [blame] | 31 | #include <linux/smp_lock.h> | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 32 | #include <linux/syscalls.h> | 
|  | 33 | #include <linux/moduleloader.h> | 
| Ralf Baechle | a84c96e | 2006-01-15 18:11:28 +0000 | [diff] [blame] | 34 | #include <linux/interrupt.h> | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 35 | #include <linux/poll.h> | 
|  | 36 | #include <linux/sched.h> | 
|  | 37 | #include <linux/wait.h> | 
|  | 38 | #include <asm/mipsmtregs.h> | 
| Ralf Baechle | bb3d7c7 | 2007-02-07 15:36:56 +0000 | [diff] [blame] | 39 | #include <asm/mips_mt.h> | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 40 | #include <asm/cacheflush.h> | 
|  | 41 | #include <asm/atomic.h> | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 42 | #include <asm/cpu.h> | 
|  | 43 | #include <asm/processor.h> | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 44 | #include <asm/system.h> | 
|  | 45 | #include <asm/vpe.h> | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 46 | #include <asm/rtlx.h> | 
|  | 47 |  | 
| Ralf Baechle | afc4841 | 2005-10-31 00:30:39 +0000 | [diff] [blame] | 48 | static struct rtlx_info *rtlx; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 49 | static int major; | 
|  | 50 | static char module_name[] = "rtlx"; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 51 |  | 
|  | 52 | static struct chan_waitqueues { | 
|  | 53 | wait_queue_head_t rt_queue; | 
|  | 54 | wait_queue_head_t lx_queue; | 
| Ralf Baechle | c4c4018 | 2007-02-23 13:40:45 +0000 | [diff] [blame] | 55 | atomic_t in_open; | 
| Ralf Baechle | bc4809e | 2007-03-15 17:13:47 +0000 | [diff] [blame] | 56 | struct mutex mutex; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 57 | } channel_wqs[RTLX_CHANNELS]; | 
|  | 58 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 59 | static struct vpe_notifications notify; | 
| Ralf Baechle | 982f6ff | 2009-09-17 02:25:07 +0200 | [diff] [blame] | 60 | static int sp_stopping; | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 61 |  | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 62 | extern void *vpe_get_shared(int index); | 
|  | 63 |  | 
| Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 64 | static void rtlx_dispatch(void) | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 65 | { | 
| Atsushi Nemoto | 97dcb82 | 2007-01-08 02:14:29 +0900 | [diff] [blame] | 66 | do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ); | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 67 | } | 
|  | 68 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 69 |  | 
|  | 70 | /* Interrupt handler may be called before rtlx_init has otherwise had | 
|  | 71 | a chance to run. | 
|  | 72 | */ | 
| Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 73 | static irqreturn_t rtlx_interrupt(int irq, void *dev_id) | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 74 | { | 
| Ralf Baechle | 1bbfc20 | 2009-09-29 00:52:27 +0100 | [diff] [blame] | 75 | unsigned int vpeflags; | 
|  | 76 | unsigned long flags; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 77 | int i; | 
| Kevin D. Kissell | 1928cc8 | 2008-04-16 15:32:22 +0200 | [diff] [blame] | 78 |  | 
|  | 79 | /* Ought not to be strictly necessary for SMTC builds */ | 
|  | 80 | local_irq_save(flags); | 
|  | 81 | vpeflags = dvpe(); | 
|  | 82 | set_c0_status(0x100 << MIPS_CPU_RTLX_IRQ); | 
|  | 83 | irq_enable_hazard(); | 
|  | 84 | evpe(vpeflags); | 
|  | 85 | local_irq_restore(flags); | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 86 |  | 
|  | 87 | for (i = 0; i < RTLX_CHANNELS; i++) { | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 88 | wake_up(&channel_wqs[i].lx_queue); | 
|  | 89 | wake_up(&channel_wqs[i].rt_queue); | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 90 | } | 
|  | 91 |  | 
| Ralf Baechle | afc4841 | 2005-10-31 00:30:39 +0000 | [diff] [blame] | 92 | return IRQ_HANDLED; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 93 | } | 
|  | 94 |  | 
| David Rientjes | f5dbeaf | 2007-07-22 01:01:39 -0700 | [diff] [blame] | 95 | static void __used dump_rtlx(void) | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 96 | { | 
|  | 97 | int i; | 
|  | 98 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 99 | printk("id 0x%lx state %d\n", rtlx->id, rtlx->state); | 
|  | 100 |  | 
|  | 101 | for (i = 0; i < RTLX_CHANNELS; i++) { | 
|  | 102 | struct rtlx_channel *chan = &rtlx->channel[i]; | 
|  | 103 |  | 
|  | 104 | printk(" rt_state %d lx_state %d buffer_size %d\n", | 
|  | 105 | chan->rt_state, chan->lx_state, chan->buffer_size); | 
|  | 106 |  | 
|  | 107 | printk(" rt_read %d rt_write %d\n", | 
|  | 108 | chan->rt_read, chan->rt_write); | 
|  | 109 |  | 
|  | 110 | printk(" lx_read %d lx_write %d\n", | 
|  | 111 | chan->lx_read, chan->lx_write); | 
|  | 112 |  | 
|  | 113 | printk(" rt_buffer <%s>\n", chan->rt_buffer); | 
|  | 114 | printk(" lx_buffer <%s>\n", chan->lx_buffer); | 
|  | 115 | } | 
|  | 116 | } | 
|  | 117 |  | 
|  | 118 | /* call when we have the address of the shared structure from the SP side. */ | 
|  | 119 | static int rtlx_init(struct rtlx_info *rtlxi) | 
|  | 120 | { | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 121 | if (rtlxi->id != RTLX_ID) { | 
| Kevin D. Kissell | 1928cc8 | 2008-04-16 15:32:22 +0200 | [diff] [blame] | 122 | printk(KERN_ERR "no valid RTLX id at 0x%p 0x%lx\n", | 
|  | 123 | rtlxi, rtlxi->id); | 
| Ralf Baechle | afc4841 | 2005-10-31 00:30:39 +0000 | [diff] [blame] | 124 | return -ENOEXEC; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 125 | } | 
|  | 126 |  | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 127 | rtlx = rtlxi; | 
| Ralf Baechle | afc4841 | 2005-10-31 00:30:39 +0000 | [diff] [blame] | 128 |  | 
|  | 129 | return 0; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 130 | } | 
|  | 131 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 132 | /* notifications */ | 
|  | 133 | static void starting(int vpe) | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 134 | { | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 135 | int i; | 
|  | 136 | sp_stopping = 0; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 137 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 138 | /* force a reload of rtlx */ | 
|  | 139 | rtlx=NULL; | 
|  | 140 |  | 
|  | 141 | /* wake up any sleeping rtlx_open's */ | 
|  | 142 | for (i = 0; i < RTLX_CHANNELS; i++) | 
|  | 143 | wake_up_interruptible(&channel_wqs[i].lx_queue); | 
|  | 144 | } | 
|  | 145 |  | 
|  | 146 | static void stopping(int vpe) | 
|  | 147 | { | 
|  | 148 | int i; | 
|  | 149 |  | 
|  | 150 | sp_stopping = 1; | 
|  | 151 | for (i = 0; i < RTLX_CHANNELS; i++) | 
|  | 152 | wake_up_interruptible(&channel_wqs[i].lx_queue); | 
|  | 153 | } | 
|  | 154 |  | 
|  | 155 |  | 
|  | 156 | int rtlx_open(int index, int can_sleep) | 
|  | 157 | { | 
| Ralf Baechle | 9e34682 | 2007-03-15 17:08:28 +0000 | [diff] [blame] | 158 | struct rtlx_info **p; | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 159 | struct rtlx_channel *chan; | 
| Ralf Baechle | c4c4018 | 2007-02-23 13:40:45 +0000 | [diff] [blame] | 160 | enum rtlx_state state; | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 161 | int ret = 0; | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 162 |  | 
|  | 163 | if (index >= RTLX_CHANNELS) { | 
|  | 164 | printk(KERN_DEBUG "rtlx_open index out of range\n"); | 
|  | 165 | return -ENOSYS; | 
|  | 166 | } | 
|  | 167 |  | 
| Ralf Baechle | c4c4018 | 2007-02-23 13:40:45 +0000 | [diff] [blame] | 168 | if (atomic_inc_return(&channel_wqs[index].in_open) > 1) { | 
|  | 169 | printk(KERN_DEBUG "rtlx_open channel %d already opened\n", | 
|  | 170 | index); | 
|  | 171 | ret = -EBUSY; | 
|  | 172 | goto out_fail; | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 173 | } | 
|  | 174 |  | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 175 | if (rtlx == NULL) { | 
| Ralf Baechle | 07cc0c9 | 2007-07-27 19:31:10 +0100 | [diff] [blame] | 176 | if( (p = vpe_get_shared(tclimit)) == NULL) { | 
| Kevin D. Kissell | 1928cc8 | 2008-04-16 15:32:22 +0200 | [diff] [blame] | 177 | if (can_sleep) { | 
|  | 178 | __wait_event_interruptible(channel_wqs[index].lx_queue, | 
|  | 179 | (p = vpe_get_shared(tclimit)), ret); | 
|  | 180 | if (ret) | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 181 | goto out_fail; | 
| Kevin D. Kissell | 1928cc8 | 2008-04-16 15:32:22 +0200 | [diff] [blame] | 182 | } else { | 
|  | 183 | printk(KERN_DEBUG "No SP program loaded, and device " | 
|  | 184 | "opened with O_NONBLOCK\n"); | 
|  | 185 | ret = -ENOSYS; | 
|  | 186 | goto out_fail; | 
|  | 187 | } | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 188 | } | 
|  | 189 |  | 
| Ralf Baechle | 9e34682 | 2007-03-15 17:08:28 +0000 | [diff] [blame] | 190 | smp_rmb(); | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 191 | if (*p == NULL) { | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 192 | if (can_sleep) { | 
| Ralf Baechle | 9e34682 | 2007-03-15 17:08:28 +0000 | [diff] [blame] | 193 | DEFINE_WAIT(wait); | 
|  | 194 |  | 
|  | 195 | for (;;) { | 
| Kevin D. Kissell | 1928cc8 | 2008-04-16 15:32:22 +0200 | [diff] [blame] | 196 | prepare_to_wait( | 
|  | 197 | &channel_wqs[index].lx_queue, | 
|  | 198 | &wait, TASK_INTERRUPTIBLE); | 
| Ralf Baechle | 9e34682 | 2007-03-15 17:08:28 +0000 | [diff] [blame] | 199 | smp_rmb(); | 
|  | 200 | if (*p != NULL) | 
|  | 201 | break; | 
|  | 202 | if (!signal_pending(current)) { | 
|  | 203 | schedule(); | 
|  | 204 | continue; | 
|  | 205 | } | 
|  | 206 | ret = -ERESTARTSYS; | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 207 | goto out_fail; | 
| Ralf Baechle | 9e34682 | 2007-03-15 17:08:28 +0000 | [diff] [blame] | 208 | } | 
|  | 209 | finish_wait(&channel_wqs[index].lx_queue, &wait); | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 210 | } else { | 
| Kevin D. Kissell | 1928cc8 | 2008-04-16 15:32:22 +0200 | [diff] [blame] | 211 | pr_err(" *vpe_get_shared is NULL. " | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 212 | "Has an SP program been loaded?\n"); | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 213 | ret = -ENOSYS; | 
|  | 214 | goto out_fail; | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 215 | } | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 216 | } | 
|  | 217 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 218 | if ((unsigned int)*p < KSEG0) { | 
| Kevin D. Kissell | 1928cc8 | 2008-04-16 15:32:22 +0200 | [diff] [blame] | 219 | printk(KERN_WARNING "vpe_get_shared returned an " | 
|  | 220 | "invalid pointer maybe an error code %d\n", | 
|  | 221 | (int)*p); | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 222 | ret = -ENOSYS; | 
|  | 223 | goto out_fail; | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 224 | } | 
|  | 225 |  | 
| Ralf Baechle | c4c4018 | 2007-02-23 13:40:45 +0000 | [diff] [blame] | 226 | if ((ret = rtlx_init(*p)) < 0) | 
|  | 227 | goto out_ret; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 228 | } | 
|  | 229 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 230 | chan = &rtlx->channel[index]; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 231 |  | 
| Ralf Baechle | c4c4018 | 2007-02-23 13:40:45 +0000 | [diff] [blame] | 232 | state = xchg(&chan->lx_state, RTLX_STATE_OPENED); | 
|  | 233 | if (state == RTLX_STATE_OPENED) { | 
|  | 234 | ret = -EBUSY; | 
|  | 235 | goto out_fail; | 
|  | 236 | } | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 237 |  | 
|  | 238 | out_fail: | 
| Ralf Baechle | c4c4018 | 2007-02-23 13:40:45 +0000 | [diff] [blame] | 239 | smp_mb(); | 
|  | 240 | atomic_dec(&channel_wqs[index].in_open); | 
|  | 241 | smp_mb(); | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 242 |  | 
| Ralf Baechle | c4c4018 | 2007-02-23 13:40:45 +0000 | [diff] [blame] | 243 | out_ret: | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 244 | return ret; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 245 | } | 
|  | 246 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 247 | int rtlx_release(int index) | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 248 | { | 
| Kevin D. Kissell | 1928cc8 | 2008-04-16 15:32:22 +0200 | [diff] [blame] | 249 | if (rtlx == NULL) { | 
|  | 250 | pr_err("rtlx_release() with null rtlx\n"); | 
|  | 251 | return 0; | 
|  | 252 | } | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 253 | rtlx->channel[index].lx_state = RTLX_STATE_UNUSED; | 
| Ralf Baechle | afc4841 | 2005-10-31 00:30:39 +0000 | [diff] [blame] | 254 | return 0; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 255 | } | 
|  | 256 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 257 | unsigned int rtlx_read_poll(int index, int can_sleep) | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 258 | { | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 259 | struct rtlx_channel *chan; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 260 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 261 | if (rtlx == NULL) | 
|  | 262 | return 0; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 263 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 264 | chan = &rtlx->channel[index]; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 265 |  | 
|  | 266 | /* data available to read? */ | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 267 | if (chan->lx_read == chan->lx_write) { | 
|  | 268 | if (can_sleep) { | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 269 | int ret = 0; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 270 |  | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 271 | __wait_event_interruptible(channel_wqs[index].lx_queue, | 
| Kevin D. Kissell | 1928cc8 | 2008-04-16 15:32:22 +0200 | [diff] [blame] | 272 | (chan->lx_read != chan->lx_write) || | 
|  | 273 | sp_stopping, ret); | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 274 | if (ret) | 
|  | 275 | return ret; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 276 |  | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 277 | if (sp_stopping) | 
|  | 278 | return 0; | 
|  | 279 | } else | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 280 | return 0; | 
|  | 281 | } | 
|  | 282 |  | 
|  | 283 | return (chan->lx_write + chan->buffer_size - chan->lx_read) | 
|  | 284 | % chan->buffer_size; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 285 | } | 
|  | 286 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 287 | static inline int write_spacefree(int read, int write, int size) | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 288 | { | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 289 | if (read == write) { | 
|  | 290 | /* | 
|  | 291 | * Never fill the buffer completely, so indexes are always | 
|  | 292 | * equal if empty and only empty, or !equal if data available | 
|  | 293 | */ | 
|  | 294 | return size - 1; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 295 | } | 
|  | 296 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 297 | return ((read + size - write) % size) - 1; | 
|  | 298 | } | 
|  | 299 |  | 
|  | 300 | unsigned int rtlx_write_poll(int index) | 
|  | 301 | { | 
|  | 302 | struct rtlx_channel *chan = &rtlx->channel[index]; | 
| Kevin D. Kissell | 1928cc8 | 2008-04-16 15:32:22 +0200 | [diff] [blame] | 303 |  | 
|  | 304 | return write_spacefree(chan->rt_read, chan->rt_write, | 
|  | 305 | chan->buffer_size); | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 306 | } | 
|  | 307 |  | 
| Ralf Baechle | 7f5a771 | 2007-04-25 15:08:57 +0100 | [diff] [blame] | 308 | ssize_t rtlx_read(int index, void __user *buff, size_t count) | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 309 | { | 
| Ralf Baechle | 61dcc6f | 2007-03-15 17:10:16 +0000 | [diff] [blame] | 310 | size_t lx_write, fl = 0L; | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 311 | struct rtlx_channel *lx; | 
| Ralf Baechle | 46230aa | 2007-03-16 12:16:27 +0000 | [diff] [blame] | 312 | unsigned long failed; | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 313 |  | 
|  | 314 | if (rtlx == NULL) | 
|  | 315 | return -ENOSYS; | 
|  | 316 |  | 
|  | 317 | lx = &rtlx->channel[index]; | 
|  | 318 |  | 
| Ralf Baechle | bc4809e | 2007-03-15 17:13:47 +0000 | [diff] [blame] | 319 | mutex_lock(&channel_wqs[index].mutex); | 
| Ralf Baechle | 61dcc6f | 2007-03-15 17:10:16 +0000 | [diff] [blame] | 320 | smp_rmb(); | 
|  | 321 | lx_write = lx->lx_write; | 
|  | 322 |  | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 323 | /* find out how much in total */ | 
| Ralf Baechle | afc4841 | 2005-10-31 00:30:39 +0000 | [diff] [blame] | 324 | count = min(count, | 
| Ralf Baechle | 61dcc6f | 2007-03-15 17:10:16 +0000 | [diff] [blame] | 325 | (size_t)(lx_write + lx->buffer_size - lx->lx_read) | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 326 | % lx->buffer_size); | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 327 |  | 
|  | 328 | /* then how much from the read pointer onwards */ | 
| Ralf Baechle | 61dcc6f | 2007-03-15 17:10:16 +0000 | [diff] [blame] | 329 | fl = min(count, (size_t)lx->buffer_size - lx->lx_read); | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 330 |  | 
| Ralf Baechle | 46230aa | 2007-03-16 12:16:27 +0000 | [diff] [blame] | 331 | failed = copy_to_user(buff, lx->lx_buffer + lx->lx_read, fl); | 
|  | 332 | if (failed) | 
|  | 333 | goto out; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 334 |  | 
|  | 335 | /* and if there is anything left at the beginning of the buffer */ | 
| Ralf Baechle | 61dcc6f | 2007-03-15 17:10:16 +0000 | [diff] [blame] | 336 | if (count - fl) | 
| Ralf Baechle | 46230aa | 2007-03-16 12:16:27 +0000 | [diff] [blame] | 337 | failed = copy_to_user(buff + fl, lx->lx_buffer, count - fl); | 
|  | 338 |  | 
|  | 339 | out: | 
|  | 340 | count -= failed; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 341 |  | 
| Ralf Baechle | 61dcc6f | 2007-03-15 17:10:16 +0000 | [diff] [blame] | 342 | smp_wmb(); | 
|  | 343 | lx->lx_read = (lx->lx_read + count) % lx->buffer_size; | 
|  | 344 | smp_wmb(); | 
| Ralf Baechle | bc4809e | 2007-03-15 17:13:47 +0000 | [diff] [blame] | 345 | mutex_unlock(&channel_wqs[index].mutex); | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 346 |  | 
| Ralf Baechle | afc4841 | 2005-10-31 00:30:39 +0000 | [diff] [blame] | 347 | return count; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 348 | } | 
|  | 349 |  | 
| Ralf Baechle | 7f5a771 | 2007-04-25 15:08:57 +0100 | [diff] [blame] | 350 | ssize_t rtlx_write(int index, const void __user *buffer, size_t count) | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 351 | { | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 352 | struct rtlx_channel *rt; | 
| Ralf Baechle | 7f5a771 | 2007-04-25 15:08:57 +0100 | [diff] [blame] | 353 | unsigned long failed; | 
| Ralf Baechle | 61dcc6f | 2007-03-15 17:10:16 +0000 | [diff] [blame] | 354 | size_t rt_read; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 355 | size_t fl; | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 356 |  | 
|  | 357 | if (rtlx == NULL) | 
|  | 358 | return(-ENOSYS); | 
|  | 359 |  | 
|  | 360 | rt = &rtlx->channel[index]; | 
|  | 361 |  | 
| Ralf Baechle | bc4809e | 2007-03-15 17:13:47 +0000 | [diff] [blame] | 362 | mutex_lock(&channel_wqs[index].mutex); | 
| Ralf Baechle | 61dcc6f | 2007-03-15 17:10:16 +0000 | [diff] [blame] | 363 | smp_rmb(); | 
|  | 364 | rt_read = rt->rt_read; | 
|  | 365 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 366 | /* total number of bytes to copy */ | 
| Kevin D. Kissell | 1928cc8 | 2008-04-16 15:32:22 +0200 | [diff] [blame] | 367 | count = min(count, (size_t)write_spacefree(rt_read, rt->rt_write, | 
|  | 368 | rt->buffer_size)); | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 369 |  | 
|  | 370 | /* first bit from write pointer to the end of the buffer, or count */ | 
|  | 371 | fl = min(count, (size_t) rt->buffer_size - rt->rt_write); | 
|  | 372 |  | 
| Ralf Baechle | 46230aa | 2007-03-16 12:16:27 +0000 | [diff] [blame] | 373 | failed = copy_from_user(rt->rt_buffer + rt->rt_write, buffer, fl); | 
|  | 374 | if (failed) | 
|  | 375 | goto out; | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 376 |  | 
|  | 377 | /* if there's any left copy to the beginning of the buffer */ | 
| Ralf Baechle | 46230aa | 2007-03-16 12:16:27 +0000 | [diff] [blame] | 378 | if (count - fl) { | 
|  | 379 | failed = copy_from_user(rt->rt_buffer, buffer + fl, count - fl); | 
|  | 380 | } | 
|  | 381 |  | 
|  | 382 | out: | 
| Ralf Baechle | 7f5a771 | 2007-04-25 15:08:57 +0100 | [diff] [blame] | 383 | count -= failed; | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 384 |  | 
| Ralf Baechle | 61dcc6f | 2007-03-15 17:10:16 +0000 | [diff] [blame] | 385 | smp_wmb(); | 
|  | 386 | rt->rt_write = (rt->rt_write + count) % rt->buffer_size; | 
|  | 387 | smp_wmb(); | 
| Ralf Baechle | bc4809e | 2007-03-15 17:13:47 +0000 | [diff] [blame] | 388 | mutex_unlock(&channel_wqs[index].mutex); | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 389 |  | 
| Ralf Baechle | 61dcc6f | 2007-03-15 17:10:16 +0000 | [diff] [blame] | 390 | return count; | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 391 | } | 
|  | 392 |  | 
|  | 393 |  | 
|  | 394 | static int file_open(struct inode *inode, struct file *filp) | 
|  | 395 | { | 
| Ralf Baechle | 1bbfc20 | 2009-09-29 00:52:27 +0100 | [diff] [blame] | 396 | return rtlx_open(iminor(inode), (filp->f_flags & O_NONBLOCK) ? 0 : 1); | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 397 | } | 
|  | 398 |  | 
|  | 399 | static int file_release(struct inode *inode, struct file *filp) | 
|  | 400 | { | 
| Ralf Baechle | 1bbfc20 | 2009-09-29 00:52:27 +0100 | [diff] [blame] | 401 | return rtlx_release(iminor(inode)); | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 402 | } | 
|  | 403 |  | 
|  | 404 | static unsigned int file_poll(struct file *file, poll_table * wait) | 
|  | 405 | { | 
|  | 406 | int minor; | 
|  | 407 | unsigned int mask = 0; | 
|  | 408 |  | 
| Josef Sipek | 1b04fe9 | 2006-12-08 02:37:20 -0800 | [diff] [blame] | 409 | minor = iminor(file->f_path.dentry->d_inode); | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 410 |  | 
|  | 411 | poll_wait(file, &channel_wqs[minor].rt_queue, wait); | 
|  | 412 | poll_wait(file, &channel_wqs[minor].lx_queue, wait); | 
|  | 413 |  | 
|  | 414 | if (rtlx == NULL) | 
|  | 415 | return 0; | 
|  | 416 |  | 
|  | 417 | /* data available to read? */ | 
|  | 418 | if (rtlx_read_poll(minor, 0)) | 
|  | 419 | mask |= POLLIN | POLLRDNORM; | 
|  | 420 |  | 
|  | 421 | /* space to write */ | 
|  | 422 | if (rtlx_write_poll(minor)) | 
|  | 423 | mask |= POLLOUT | POLLWRNORM; | 
|  | 424 |  | 
|  | 425 | return mask; | 
|  | 426 | } | 
|  | 427 |  | 
|  | 428 | static ssize_t file_read(struct file *file, char __user * buffer, size_t count, | 
|  | 429 | loff_t * ppos) | 
|  | 430 | { | 
| Josef Sipek | 1b04fe9 | 2006-12-08 02:37:20 -0800 | [diff] [blame] | 431 | int minor = iminor(file->f_path.dentry->d_inode); | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 432 |  | 
|  | 433 | /* data available? */ | 
|  | 434 | if (!rtlx_read_poll(minor, (file->f_flags & O_NONBLOCK) ? 0 : 1)) { | 
|  | 435 | return 0;	// -EAGAIN makes cat whinge | 
|  | 436 | } | 
|  | 437 |  | 
| Ralf Baechle | 46230aa | 2007-03-16 12:16:27 +0000 | [diff] [blame] | 438 | return rtlx_read(minor, buffer, count); | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 439 | } | 
|  | 440 |  | 
|  | 441 | static ssize_t file_write(struct file *file, const char __user * buffer, | 
|  | 442 | size_t count, loff_t * ppos) | 
|  | 443 | { | 
|  | 444 | int minor; | 
|  | 445 | struct rtlx_channel *rt; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 446 |  | 
| Josef Sipek | 1b04fe9 | 2006-12-08 02:37:20 -0800 | [diff] [blame] | 447 | minor = iminor(file->f_path.dentry->d_inode); | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 448 | rt = &rtlx->channel[minor]; | 
|  | 449 |  | 
|  | 450 | /* any space left... */ | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 451 | if (!rtlx_write_poll(minor)) { | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 452 | int ret = 0; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 453 |  | 
|  | 454 | if (file->f_flags & O_NONBLOCK) | 
| Ralf Baechle | afc4841 | 2005-10-31 00:30:39 +0000 | [diff] [blame] | 455 | return -EAGAIN; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 456 |  | 
| Ralf Baechle | 67e2ccc | 2007-02-22 14:19:48 +0000 | [diff] [blame] | 457 | __wait_event_interruptible(channel_wqs[minor].rt_queue, | 
|  | 458 | rtlx_write_poll(minor), | 
|  | 459 | ret); | 
|  | 460 | if (ret) | 
|  | 461 | return ret; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 462 | } | 
|  | 463 |  | 
| Ralf Baechle | 46230aa | 2007-03-16 12:16:27 +0000 | [diff] [blame] | 464 | return rtlx_write(minor, buffer, count); | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 465 | } | 
|  | 466 |  | 
| Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 467 | static const struct file_operations rtlx_fops = { | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 468 | .owner =   THIS_MODULE, | 
|  | 469 | .open =    file_open, | 
|  | 470 | .release = file_release, | 
|  | 471 | .write =   file_write, | 
|  | 472 | .read =    file_read, | 
|  | 473 | .poll =    file_poll | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 474 | }; | 
|  | 475 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 476 | static struct irqaction rtlx_irq = { | 
|  | 477 | .handler	= rtlx_interrupt, | 
| Thomas Gleixner | f40298f | 2006-07-01 19:29:20 -0700 | [diff] [blame] | 478 | .flags		= IRQF_DISABLED, | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 479 | .name		= "RTLX", | 
|  | 480 | }; | 
|  | 481 |  | 
| Atsushi Nemoto | 97dcb82 | 2007-01-08 02:14:29 +0900 | [diff] [blame] | 482 | static int rtlx_irq_num = MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ; | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 483 |  | 
| Ralf Baechle | afc4841 | 2005-10-31 00:30:39 +0000 | [diff] [blame] | 484 | static char register_chrdev_failed[] __initdata = | 
|  | 485 | KERN_ERR "rtlx_module_init: unable to register device\n"; | 
|  | 486 |  | 
| Ralf Baechle | 9d5a3f5 | 2007-07-28 00:51:45 +0100 | [diff] [blame] | 487 | static int __init rtlx_module_init(void) | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 488 | { | 
| Ralf Baechle | bb3d7c7 | 2007-02-07 15:36:56 +0000 | [diff] [blame] | 489 | struct device *dev; | 
|  | 490 | int i, err; | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 491 |  | 
| Ralf Baechle | 07cc0c9 | 2007-07-27 19:31:10 +0100 | [diff] [blame] | 492 | if (!cpu_has_mipsmt) { | 
|  | 493 | printk("VPE loader: not a MIPS MT capable processor\n"); | 
|  | 494 | return -ENODEV; | 
|  | 495 | } | 
|  | 496 |  | 
|  | 497 | if (tclimit == 0) { | 
|  | 498 | printk(KERN_WARNING "No TCs reserved for AP/SP, not " | 
|  | 499 | "initializing RTLX.\nPass maxtcs=<n> argument as kernel " | 
|  | 500 | "argument\n"); | 
|  | 501 |  | 
|  | 502 | return -ENODEV; | 
|  | 503 | } | 
|  | 504 |  | 
| Ralf Baechle | afc4841 | 2005-10-31 00:30:39 +0000 | [diff] [blame] | 505 | major = register_chrdev(0, module_name, &rtlx_fops); | 
|  | 506 | if (major < 0) { | 
|  | 507 | printk(register_chrdev_failed); | 
|  | 508 | return major; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 509 | } | 
|  | 510 |  | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 511 | /* initialise the wait queues */ | 
|  | 512 | for (i = 0; i < RTLX_CHANNELS; i++) { | 
|  | 513 | init_waitqueue_head(&channel_wqs[i].rt_queue); | 
|  | 514 | init_waitqueue_head(&channel_wqs[i].lx_queue); | 
| Ralf Baechle | c4c4018 | 2007-02-23 13:40:45 +0000 | [diff] [blame] | 515 | atomic_set(&channel_wqs[i].in_open, 0); | 
| Ralf Baechle | bc4809e | 2007-03-15 17:13:47 +0000 | [diff] [blame] | 516 | mutex_init(&channel_wqs[i].mutex); | 
| Ralf Baechle | bb3d7c7 | 2007-02-07 15:36:56 +0000 | [diff] [blame] | 517 |  | 
| Greg Kroah-Hartman | a9b1261 | 2008-07-21 20:03:34 -0700 | [diff] [blame] | 518 | dev = device_create(mt_class, NULL, MKDEV(major, i), NULL, | 
|  | 519 | "%s%d", module_name, i); | 
| Ralf Baechle | bb3d7c7 | 2007-02-07 15:36:56 +0000 | [diff] [blame] | 520 | if (IS_ERR(dev)) { | 
|  | 521 | err = PTR_ERR(dev); | 
|  | 522 | goto out_chrdev; | 
|  | 523 | } | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 524 | } | 
|  | 525 |  | 
|  | 526 | /* set up notifiers */ | 
|  | 527 | notify.start = starting; | 
|  | 528 | notify.stop = stopping; | 
| Ralf Baechle | 07cc0c9 | 2007-07-27 19:31:10 +0100 | [diff] [blame] | 529 | vpe_notify(tclimit, ¬ify); | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 530 |  | 
|  | 531 | if (cpu_has_vint) | 
|  | 532 | set_vi_handler(MIPS_CPU_RTLX_IRQ, rtlx_dispatch); | 
| Kevin D. Kissell | 1928cc8 | 2008-04-16 15:32:22 +0200 | [diff] [blame] | 533 | else { | 
|  | 534 | pr_err("APRP RTLX init on non-vectored-interrupt processor\n"); | 
|  | 535 | err = -ENODEV; | 
|  | 536 | goto out_chrdev; | 
|  | 537 | } | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 538 |  | 
|  | 539 | rtlx_irq.dev_id = rtlx; | 
|  | 540 | setup_irq(rtlx_irq_num, &rtlx_irq); | 
|  | 541 |  | 
| Ralf Baechle | afc4841 | 2005-10-31 00:30:39 +0000 | [diff] [blame] | 542 | return 0; | 
| Ralf Baechle | bb3d7c7 | 2007-02-07 15:36:56 +0000 | [diff] [blame] | 543 |  | 
|  | 544 | out_chrdev: | 
|  | 545 | for (i = 0; i < RTLX_CHANNELS; i++) | 
|  | 546 | device_destroy(mt_class, MKDEV(major, i)); | 
|  | 547 |  | 
|  | 548 | return err; | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 549 | } | 
|  | 550 |  | 
| Ralf Baechle | afc4841 | 2005-10-31 00:30:39 +0000 | [diff] [blame] | 551 | static void __exit rtlx_module_exit(void) | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 552 | { | 
| Ralf Baechle | bb3d7c7 | 2007-02-07 15:36:56 +0000 | [diff] [blame] | 553 | int i; | 
|  | 554 |  | 
|  | 555 | for (i = 0; i < RTLX_CHANNELS; i++) | 
|  | 556 | device_destroy(mt_class, MKDEV(major, i)); | 
|  | 557 |  | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 558 | unregister_chrdev(major, module_name); | 
|  | 559 | } | 
|  | 560 |  | 
|  | 561 | module_init(rtlx_module_init); | 
|  | 562 | module_exit(rtlx_module_exit); | 
| Ralf Baechle | afc4841 | 2005-10-31 00:30:39 +0000 | [diff] [blame] | 563 |  | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 564 | MODULE_DESCRIPTION("MIPS RTLX"); | 
| Ralf Baechle | 2600990 | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 565 | MODULE_AUTHOR("Elizabeth Oldham, MIPS Technologies, Inc."); | 
| Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 566 | MODULE_LICENSE("GPL"); |