]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
a1452a37 DW |
2 | * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org> |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1da177e4 LT |
17 | * |
18 | */ | |
19 | ||
15fdc52f TG |
20 | #include <linux/device.h> |
21 | #include <linux/fs.h> | |
0c1eafdb | 22 | #include <linux/mm.h> |
9c74034f | 23 | #include <linux/err.h> |
15fdc52f | 24 | #include <linux/init.h> |
1da177e4 LT |
25 | #include <linux/kernel.h> |
26 | #include <linux/module.h> | |
15fdc52f TG |
27 | #include <linux/slab.h> |
28 | #include <linux/sched.h> | |
5aa82940 | 29 | #include <linux/mutex.h> |
402d3265 | 30 | #include <linux/backing-dev.h> |
97718540 | 31 | #include <linux/compat.h> |
cd874237 | 32 | #include <linux/mount.h> |
15fdc52f | 33 | |
1da177e4 | 34 | #include <linux/mtd/mtd.h> |
dd02b67d | 35 | #include <linux/mtd/map.h> |
1da177e4 | 36 | |
15fdc52f | 37 | #include <asm/uaccess.h> |
9bc7b387 | 38 | |
cd874237 | 39 | #define MTD_INODE_FS_MAGIC 0x11307854 |
5aa82940 | 40 | static DEFINE_MUTEX(mtd_mutex); |
cd874237 | 41 | static struct vfsmount *mtd_inode_mnt __read_mostly; |
1da177e4 | 42 | |
045e9a5d | 43 | /* |
f1a28c02 TG |
44 | * Data structure to hold the pointer to the mtd device as well |
45 | * as mode information ofr various use cases. | |
045e9a5d | 46 | */ |
f1a28c02 TG |
47 | struct mtd_file_info { |
48 | struct mtd_info *mtd; | |
cd874237 | 49 | struct inode *ino; |
f1a28c02 TG |
50 | enum mtd_file_modes mode; |
51 | }; | |
31f4233b | 52 | |
1da177e4 LT |
53 | static loff_t mtd_lseek (struct file *file, loff_t offset, int orig) |
54 | { | |
f1a28c02 TG |
55 | struct mtd_file_info *mfi = file->private_data; |
56 | struct mtd_info *mtd = mfi->mtd; | |
1da177e4 LT |
57 | |
58 | switch (orig) { | |
ea59830d | 59 | case SEEK_SET: |
1da177e4 | 60 | break; |
ea59830d | 61 | case SEEK_CUR: |
8b491d75 | 62 | offset += file->f_pos; |
1da177e4 | 63 | break; |
ea59830d | 64 | case SEEK_END: |
8b491d75 | 65 | offset += mtd->size; |
1da177e4 LT |
66 | break; |
67 | default: | |
68 | return -EINVAL; | |
69 | } | |
70 | ||
1887f517 | 71 | if (offset >= 0 && offset <= mtd->size) |
8b491d75 | 72 | return file->f_pos = offset; |
1da177e4 | 73 | |
8b491d75 | 74 | return -EINVAL; |
1da177e4 LT |
75 | } |
76 | ||
77 | ||
78 | ||
79 | static int mtd_open(struct inode *inode, struct file *file) | |
80 | { | |
81 | int minor = iminor(inode); | |
82 | int devnum = minor >> 1; | |
6071239e | 83 | int ret = 0; |
1da177e4 | 84 | struct mtd_info *mtd; |
f1a28c02 | 85 | struct mtd_file_info *mfi; |
cd874237 | 86 | struct inode *mtd_ino; |
1da177e4 LT |
87 | |
88 | DEBUG(MTD_DEBUG_LEVEL0, "MTD_open\n"); | |
89 | ||
1da177e4 | 90 | /* You can't open the RO devices RW */ |
aeb5d727 | 91 | if ((file->f_mode & FMODE_WRITE) && (minor & 1)) |
1da177e4 LT |
92 | return -EACCES; |
93 | ||
5aa82940 | 94 | mutex_lock(&mtd_mutex); |
1da177e4 | 95 | mtd = get_mtd_device(NULL, devnum); |
97894cda | 96 | |
6071239e JC |
97 | if (IS_ERR(mtd)) { |
98 | ret = PTR_ERR(mtd); | |
99 | goto out; | |
100 | } | |
97894cda | 101 | |
402d3265 | 102 | if (mtd->type == MTD_ABSENT) { |
1da177e4 | 103 | put_mtd_device(mtd); |
6071239e JC |
104 | ret = -ENODEV; |
105 | goto out; | |
1da177e4 LT |
106 | } |
107 | ||
cd874237 KS |
108 | mtd_ino = iget_locked(mtd_inode_mnt->mnt_sb, devnum); |
109 | if (!mtd_ino) { | |
110 | put_mtd_device(mtd); | |
111 | ret = -ENOMEM; | |
112 | goto out; | |
113 | } | |
114 | if (mtd_ino->i_state & I_NEW) { | |
115 | mtd_ino->i_private = mtd; | |
116 | mtd_ino->i_mode = S_IFCHR; | |
117 | mtd_ino->i_data.backing_dev_info = mtd->backing_dev_info; | |
118 | unlock_new_inode(mtd_ino); | |
119 | } | |
120 | file->f_mapping = mtd_ino->i_mapping; | |
402d3265 | 121 | |
1da177e4 | 122 | /* You can't open it RW if it's not a writeable device */ |
aeb5d727 | 123 | if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) { |
cd874237 | 124 | iput(mtd_ino); |
1da177e4 | 125 | put_mtd_device(mtd); |
6071239e JC |
126 | ret = -EACCES; |
127 | goto out; | |
1da177e4 | 128 | } |
97894cda | 129 | |
f1a28c02 TG |
130 | mfi = kzalloc(sizeof(*mfi), GFP_KERNEL); |
131 | if (!mfi) { | |
cd874237 | 132 | iput(mtd_ino); |
f1a28c02 | 133 | put_mtd_device(mtd); |
6071239e JC |
134 | ret = -ENOMEM; |
135 | goto out; | |
f1a28c02 | 136 | } |
cd874237 | 137 | mfi->ino = mtd_ino; |
f1a28c02 TG |
138 | mfi->mtd = mtd; |
139 | file->private_data = mfi; | |
140 | ||
6071239e | 141 | out: |
5aa82940 | 142 | mutex_unlock(&mtd_mutex); |
6071239e | 143 | return ret; |
1da177e4 LT |
144 | } /* mtd_open */ |
145 | ||
146 | /*====================================================================*/ | |
147 | ||
148 | static int mtd_close(struct inode *inode, struct file *file) | |
149 | { | |
f1a28c02 TG |
150 | struct mtd_file_info *mfi = file->private_data; |
151 | struct mtd_info *mtd = mfi->mtd; | |
1da177e4 LT |
152 | |
153 | DEBUG(MTD_DEBUG_LEVEL0, "MTD_close\n"); | |
154 | ||
7eafaed5 | 155 | /* Only sync if opened RW */ |
aeb5d727 | 156 | if ((file->f_mode & FMODE_WRITE) && mtd->sync) |
1da177e4 | 157 | mtd->sync(mtd); |
97894cda | 158 | |
cd874237 KS |
159 | iput(mfi->ino); |
160 | ||
1da177e4 | 161 | put_mtd_device(mtd); |
f1a28c02 TG |
162 | file->private_data = NULL; |
163 | kfree(mfi); | |
1da177e4 LT |
164 | |
165 | return 0; | |
166 | } /* mtd_close */ | |
167 | ||
168 | /* FIXME: This _really_ needs to die. In 2.5, we should lock the | |
169 | userspace buffer down and use it directly with readv/writev. | |
170 | */ | |
171 | #define MAX_KMALLOC_SIZE 0x20000 | |
172 | ||
173 | static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t *ppos) | |
174 | { | |
f1a28c02 TG |
175 | struct mtd_file_info *mfi = file->private_data; |
176 | struct mtd_info *mtd = mfi->mtd; | |
1da177e4 LT |
177 | size_t retlen=0; |
178 | size_t total_retlen=0; | |
179 | int ret=0; | |
180 | int len; | |
181 | char *kbuf; | |
97894cda | 182 | |
1da177e4 LT |
183 | DEBUG(MTD_DEBUG_LEVEL0,"MTD_read\n"); |
184 | ||
185 | if (*ppos + count > mtd->size) | |
186 | count = mtd->size - *ppos; | |
187 | ||
188 | if (!count) | |
189 | return 0; | |
97894cda | 190 | |
1da177e4 LT |
191 | /* FIXME: Use kiovec in 2.5 to lock down the user's buffers |
192 | and pass them directly to the MTD functions */ | |
b802c074 TG |
193 | |
194 | if (count > MAX_KMALLOC_SIZE) | |
195 | kbuf=kmalloc(MAX_KMALLOC_SIZE, GFP_KERNEL); | |
196 | else | |
197 | kbuf=kmalloc(count, GFP_KERNEL); | |
198 | ||
199 | if (!kbuf) | |
200 | return -ENOMEM; | |
201 | ||
1da177e4 | 202 | while (count) { |
b802c074 | 203 | |
97894cda | 204 | if (count > MAX_KMALLOC_SIZE) |
1da177e4 LT |
205 | len = MAX_KMALLOC_SIZE; |
206 | else | |
207 | len = count; | |
208 | ||
f1a28c02 TG |
209 | switch (mfi->mode) { |
210 | case MTD_MODE_OTP_FACTORY: | |
31f4233b NP |
211 | ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf); |
212 | break; | |
213 | case MTD_MODE_OTP_USER: | |
214 | ret = mtd->read_user_prot_reg(mtd, *ppos, len, &retlen, kbuf); | |
215 | break; | |
f1a28c02 TG |
216 | case MTD_MODE_RAW: |
217 | { | |
218 | struct mtd_oob_ops ops; | |
219 | ||
220 | ops.mode = MTD_OOB_RAW; | |
221 | ops.datbuf = kbuf; | |
222 | ops.oobbuf = NULL; | |
223 | ops.len = len; | |
224 | ||
225 | ret = mtd->read_oob(mtd, *ppos, &ops); | |
226 | retlen = ops.retlen; | |
227 | break; | |
228 | } | |
31f4233b | 229 | default: |
f4a43cfc | 230 | ret = mtd->read(mtd, *ppos, len, &retlen, kbuf); |
31f4233b | 231 | } |
1da177e4 LT |
232 | /* Nand returns -EBADMSG on ecc errors, but it returns |
233 | * the data. For our userspace tools it is important | |
97894cda | 234 | * to dump areas with ecc errors ! |
9a1fcdfd TG |
235 | * For kernel internal usage it also might return -EUCLEAN |
236 | * to signal the caller that a bitflip has occured and has | |
237 | * been corrected by the ECC algorithm. | |
1da177e4 LT |
238 | * Userspace software which accesses NAND this way |
239 | * must be aware of the fact that it deals with NAND | |
240 | */ | |
9a1fcdfd | 241 | if (!ret || (ret == -EUCLEAN) || (ret == -EBADMSG)) { |
1da177e4 LT |
242 | *ppos += retlen; |
243 | if (copy_to_user(buf, kbuf, retlen)) { | |
f4a43cfc | 244 | kfree(kbuf); |
1da177e4 LT |
245 | return -EFAULT; |
246 | } | |
247 | else | |
248 | total_retlen += retlen; | |
249 | ||
250 | count -= retlen; | |
251 | buf += retlen; | |
31f4233b NP |
252 | if (retlen == 0) |
253 | count = 0; | |
1da177e4 LT |
254 | } |
255 | else { | |
256 | kfree(kbuf); | |
257 | return ret; | |
258 | } | |
97894cda | 259 | |
1da177e4 LT |
260 | } |
261 | ||
b802c074 | 262 | kfree(kbuf); |
1da177e4 LT |
263 | return total_retlen; |
264 | } /* mtd_read */ | |
265 | ||
266 | static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count,loff_t *ppos) | |
267 | { | |
f1a28c02 TG |
268 | struct mtd_file_info *mfi = file->private_data; |
269 | struct mtd_info *mtd = mfi->mtd; | |
1da177e4 LT |
270 | char *kbuf; |
271 | size_t retlen; | |
272 | size_t total_retlen=0; | |
273 | int ret=0; | |
274 | int len; | |
275 | ||
276 | DEBUG(MTD_DEBUG_LEVEL0,"MTD_write\n"); | |
97894cda | 277 | |
1da177e4 LT |
278 | if (*ppos == mtd->size) |
279 | return -ENOSPC; | |
97894cda | 280 | |
1da177e4 LT |
281 | if (*ppos + count > mtd->size) |
282 | count = mtd->size - *ppos; | |
283 | ||
284 | if (!count) | |
285 | return 0; | |
286 | ||
b802c074 TG |
287 | if (count > MAX_KMALLOC_SIZE) |
288 | kbuf=kmalloc(MAX_KMALLOC_SIZE, GFP_KERNEL); | |
289 | else | |
290 | kbuf=kmalloc(count, GFP_KERNEL); | |
291 | ||
292 | if (!kbuf) | |
293 | return -ENOMEM; | |
294 | ||
1da177e4 | 295 | while (count) { |
b802c074 | 296 | |
97894cda | 297 | if (count > MAX_KMALLOC_SIZE) |
1da177e4 LT |
298 | len = MAX_KMALLOC_SIZE; |
299 | else | |
300 | len = count; | |
301 | ||
1da177e4 LT |
302 | if (copy_from_user(kbuf, buf, len)) { |
303 | kfree(kbuf); | |
304 | return -EFAULT; | |
305 | } | |
97894cda | 306 | |
f1a28c02 TG |
307 | switch (mfi->mode) { |
308 | case MTD_MODE_OTP_FACTORY: | |
31f4233b NP |
309 | ret = -EROFS; |
310 | break; | |
311 | case MTD_MODE_OTP_USER: | |
312 | if (!mtd->write_user_prot_reg) { | |
313 | ret = -EOPNOTSUPP; | |
314 | break; | |
315 | } | |
316 | ret = mtd->write_user_prot_reg(mtd, *ppos, len, &retlen, kbuf); | |
317 | break; | |
f1a28c02 TG |
318 | |
319 | case MTD_MODE_RAW: | |
320 | { | |
321 | struct mtd_oob_ops ops; | |
322 | ||
323 | ops.mode = MTD_OOB_RAW; | |
324 | ops.datbuf = kbuf; | |
325 | ops.oobbuf = NULL; | |
326 | ops.len = len; | |
327 | ||
328 | ret = mtd->write_oob(mtd, *ppos, &ops); | |
329 | retlen = ops.retlen; | |
330 | break; | |
331 | } | |
332 | ||
31f4233b NP |
333 | default: |
334 | ret = (*(mtd->write))(mtd, *ppos, len, &retlen, kbuf); | |
335 | } | |
1da177e4 LT |
336 | if (!ret) { |
337 | *ppos += retlen; | |
338 | total_retlen += retlen; | |
339 | count -= retlen; | |
340 | buf += retlen; | |
341 | } | |
342 | else { | |
343 | kfree(kbuf); | |
344 | return ret; | |
345 | } | |
1da177e4 LT |
346 | } |
347 | ||
b802c074 | 348 | kfree(kbuf); |
1da177e4 LT |
349 | return total_retlen; |
350 | } /* mtd_write */ | |
351 | ||
352 | /*====================================================================== | |
353 | ||
354 | IOCTL calls for getting device parameters. | |
355 | ||
356 | ======================================================================*/ | |
357 | static void mtdchar_erase_callback (struct erase_info *instr) | |
358 | { | |
359 | wake_up((wait_queue_head_t *)instr->priv); | |
360 | } | |
361 | ||
34a82443 | 362 | #ifdef CONFIG_HAVE_MTD_OTP |
f1a28c02 TG |
363 | static int otp_select_filemode(struct mtd_file_info *mfi, int mode) |
364 | { | |
365 | struct mtd_info *mtd = mfi->mtd; | |
366 | int ret = 0; | |
367 | ||
368 | switch (mode) { | |
369 | case MTD_OTP_FACTORY: | |
370 | if (!mtd->read_fact_prot_reg) | |
371 | ret = -EOPNOTSUPP; | |
372 | else | |
373 | mfi->mode = MTD_MODE_OTP_FACTORY; | |
374 | break; | |
375 | case MTD_OTP_USER: | |
376 | if (!mtd->read_fact_prot_reg) | |
377 | ret = -EOPNOTSUPP; | |
378 | else | |
379 | mfi->mode = MTD_MODE_OTP_USER; | |
380 | break; | |
381 | default: | |
382 | ret = -EINVAL; | |
383 | case MTD_OTP_OFF: | |
384 | break; | |
385 | } | |
386 | return ret; | |
387 | } | |
388 | #else | |
389 | # define otp_select_filemode(f,m) -EOPNOTSUPP | |
390 | #endif | |
391 | ||
97718540 KC |
392 | static int mtd_do_writeoob(struct file *file, struct mtd_info *mtd, |
393 | uint64_t start, uint32_t length, void __user *ptr, | |
394 | uint32_t __user *retp) | |
395 | { | |
396 | struct mtd_oob_ops ops; | |
397 | uint32_t retlen; | |
398 | int ret = 0; | |
399 | ||
400 | if (!(file->f_mode & FMODE_WRITE)) | |
401 | return -EPERM; | |
402 | ||
403 | if (length > 4096) | |
404 | return -EINVAL; | |
405 | ||
406 | if (!mtd->write_oob) | |
407 | ret = -EOPNOTSUPP; | |
408 | else | |
0040476b | 409 | ret = access_ok(VERIFY_READ, ptr, length) ? 0 : -EFAULT; |
97718540 KC |
410 | |
411 | if (ret) | |
412 | return ret; | |
413 | ||
414 | ops.ooblen = length; | |
415 | ops.ooboffs = start & (mtd->oobsize - 1); | |
416 | ops.datbuf = NULL; | |
417 | ops.mode = MTD_OOB_PLACE; | |
418 | ||
419 | if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs)) | |
420 | return -EINVAL; | |
421 | ||
df1f1d1c JL |
422 | ops.oobbuf = memdup_user(ptr, length); |
423 | if (IS_ERR(ops.oobbuf)) | |
424 | return PTR_ERR(ops.oobbuf); | |
97718540 KC |
425 | |
426 | start &= ~((uint64_t)mtd->oobsize - 1); | |
427 | ret = mtd->write_oob(mtd, start, &ops); | |
428 | ||
429 | if (ops.oobretlen > 0xFFFFFFFFU) | |
430 | ret = -EOVERFLOW; | |
431 | retlen = ops.oobretlen; | |
432 | if (copy_to_user(retp, &retlen, sizeof(length))) | |
433 | ret = -EFAULT; | |
434 | ||
435 | kfree(ops.oobbuf); | |
436 | return ret; | |
437 | } | |
438 | ||
439 | static int mtd_do_readoob(struct mtd_info *mtd, uint64_t start, | |
440 | uint32_t length, void __user *ptr, uint32_t __user *retp) | |
441 | { | |
442 | struct mtd_oob_ops ops; | |
443 | int ret = 0; | |
444 | ||
445 | if (length > 4096) | |
446 | return -EINVAL; | |
447 | ||
448 | if (!mtd->read_oob) | |
449 | ret = -EOPNOTSUPP; | |
450 | else | |
451 | ret = access_ok(VERIFY_WRITE, ptr, | |
452 | length) ? 0 : -EFAULT; | |
453 | if (ret) | |
454 | return ret; | |
455 | ||
456 | ops.ooblen = length; | |
457 | ops.ooboffs = start & (mtd->oobsize - 1); | |
458 | ops.datbuf = NULL; | |
459 | ops.mode = MTD_OOB_PLACE; | |
460 | ||
461 | if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs)) | |
462 | return -EINVAL; | |
463 | ||
464 | ops.oobbuf = kmalloc(length, GFP_KERNEL); | |
465 | if (!ops.oobbuf) | |
466 | return -ENOMEM; | |
467 | ||
468 | start &= ~((uint64_t)mtd->oobsize - 1); | |
469 | ret = mtd->read_oob(mtd, start, &ops); | |
470 | ||
471 | if (put_user(ops.oobretlen, retp)) | |
472 | ret = -EFAULT; | |
473 | else if (ops.oobretlen && copy_to_user(ptr, ops.oobbuf, | |
474 | ops.oobretlen)) | |
475 | ret = -EFAULT; | |
476 | ||
477 | kfree(ops.oobbuf); | |
478 | return ret; | |
479 | } | |
480 | ||
55929332 | 481 | static int mtd_ioctl(struct file *file, u_int cmd, u_long arg) |
1da177e4 | 482 | { |
f1a28c02 TG |
483 | struct mtd_file_info *mfi = file->private_data; |
484 | struct mtd_info *mtd = mfi->mtd; | |
1da177e4 LT |
485 | void __user *argp = (void __user *)arg; |
486 | int ret = 0; | |
487 | u_long size; | |
73c619ea | 488 | struct mtd_info_user info; |
97894cda | 489 | |
1da177e4 LT |
490 | DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n"); |
491 | ||
492 | size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT; | |
493 | if (cmd & IOC_IN) { | |
494 | if (!access_ok(VERIFY_READ, argp, size)) | |
495 | return -EFAULT; | |
496 | } | |
497 | if (cmd & IOC_OUT) { | |
498 | if (!access_ok(VERIFY_WRITE, argp, size)) | |
499 | return -EFAULT; | |
500 | } | |
97894cda | 501 | |
1da177e4 LT |
502 | switch (cmd) { |
503 | case MEMGETREGIONCOUNT: | |
504 | if (copy_to_user(argp, &(mtd->numeraseregions), sizeof(int))) | |
505 | return -EFAULT; | |
506 | break; | |
507 | ||
508 | case MEMGETREGIONINFO: | |
509 | { | |
b67c5f87 ZW |
510 | uint32_t ur_idx; |
511 | struct mtd_erase_region_info *kr; | |
bcc98a46 | 512 | struct region_info_user __user *ur = argp; |
1da177e4 | 513 | |
b67c5f87 | 514 | if (get_user(ur_idx, &(ur->regionindex))) |
1da177e4 LT |
515 | return -EFAULT; |
516 | ||
b67c5f87 ZW |
517 | kr = &(mtd->eraseregions[ur_idx]); |
518 | ||
519 | if (put_user(kr->offset, &(ur->offset)) | |
520 | || put_user(kr->erasesize, &(ur->erasesize)) | |
521 | || put_user(kr->numblocks, &(ur->numblocks))) | |
1da177e4 | 522 | return -EFAULT; |
b67c5f87 | 523 | |
1da177e4 LT |
524 | break; |
525 | } | |
526 | ||
527 | case MEMGETINFO: | |
73c619ea JE |
528 | info.type = mtd->type; |
529 | info.flags = mtd->flags; | |
530 | info.size = mtd->size; | |
531 | info.erasesize = mtd->erasesize; | |
532 | info.writesize = mtd->writesize; | |
533 | info.oobsize = mtd->oobsize; | |
64f60710 AB |
534 | /* The below fields are obsolete */ |
535 | info.ecctype = -1; | |
536 | info.eccsize = 0; | |
73c619ea | 537 | if (copy_to_user(argp, &info, sizeof(struct mtd_info_user))) |
1da177e4 LT |
538 | return -EFAULT; |
539 | break; | |
540 | ||
541 | case MEMERASE: | |
0dc54e9f | 542 | case MEMERASE64: |
1da177e4 LT |
543 | { |
544 | struct erase_info *erase; | |
545 | ||
aeb5d727 | 546 | if(!(file->f_mode & FMODE_WRITE)) |
1da177e4 LT |
547 | return -EPERM; |
548 | ||
95b93a0c | 549 | erase=kzalloc(sizeof(struct erase_info),GFP_KERNEL); |
1da177e4 LT |
550 | if (!erase) |
551 | ret = -ENOMEM; | |
552 | else { | |
553 | wait_queue_head_t waitq; | |
554 | DECLARE_WAITQUEUE(wait, current); | |
555 | ||
556 | init_waitqueue_head(&waitq); | |
557 | ||
0dc54e9f KC |
558 | if (cmd == MEMERASE64) { |
559 | struct erase_info_user64 einfo64; | |
560 | ||
561 | if (copy_from_user(&einfo64, argp, | |
562 | sizeof(struct erase_info_user64))) { | |
563 | kfree(erase); | |
564 | return -EFAULT; | |
565 | } | |
566 | erase->addr = einfo64.start; | |
567 | erase->len = einfo64.length; | |
568 | } else { | |
569 | struct erase_info_user einfo32; | |
570 | ||
571 | if (copy_from_user(&einfo32, argp, | |
572 | sizeof(struct erase_info_user))) { | |
573 | kfree(erase); | |
574 | return -EFAULT; | |
575 | } | |
576 | erase->addr = einfo32.start; | |
577 | erase->len = einfo32.length; | |
1da177e4 LT |
578 | } |
579 | erase->mtd = mtd; | |
580 | erase->callback = mtdchar_erase_callback; | |
581 | erase->priv = (unsigned long)&waitq; | |
97894cda | 582 | |
1da177e4 LT |
583 | /* |
584 | FIXME: Allow INTERRUPTIBLE. Which means | |
585 | not having the wait_queue head on the stack. | |
97894cda | 586 | |
1da177e4 LT |
587 | If the wq_head is on the stack, and we |
588 | leave because we got interrupted, then the | |
589 | wq_head is no longer there when the | |
590 | callback routine tries to wake us up. | |
591 | */ | |
592 | ret = mtd->erase(mtd, erase); | |
593 | if (!ret) { | |
594 | set_current_state(TASK_UNINTERRUPTIBLE); | |
595 | add_wait_queue(&waitq, &wait); | |
596 | if (erase->state != MTD_ERASE_DONE && | |
597 | erase->state != MTD_ERASE_FAILED) | |
598 | schedule(); | |
599 | remove_wait_queue(&waitq, &wait); | |
600 | set_current_state(TASK_RUNNING); | |
601 | ||
602 | ret = (erase->state == MTD_ERASE_FAILED)?-EIO:0; | |
603 | } | |
604 | kfree(erase); | |
605 | } | |
606 | break; | |
607 | } | |
608 | ||
609 | case MEMWRITEOOB: | |
610 | { | |
611 | struct mtd_oob_buf buf; | |
97718540 | 612 | struct mtd_oob_buf __user *buf_user = argp; |
1da177e4 | 613 | |
97718540 KC |
614 | /* NOTE: writes return length to buf_user->length */ |
615 | if (copy_from_user(&buf, argp, sizeof(buf))) | |
1da177e4 | 616 | ret = -EFAULT; |
97718540 KC |
617 | else |
618 | ret = mtd_do_writeoob(file, mtd, buf.start, buf.length, | |
619 | buf.ptr, &buf_user->length); | |
1da177e4 | 620 | break; |
1da177e4 LT |
621 | } |
622 | ||
623 | case MEMREADOOB: | |
624 | { | |
625 | struct mtd_oob_buf buf; | |
97718540 | 626 | struct mtd_oob_buf __user *buf_user = argp; |
8593fbc6 | 627 | |
97718540 KC |
628 | /* NOTE: writes return length to buf_user->start */ |
629 | if (copy_from_user(&buf, argp, sizeof(buf))) | |
1da177e4 | 630 | ret = -EFAULT; |
97718540 KC |
631 | else |
632 | ret = mtd_do_readoob(mtd, buf.start, buf.length, | |
633 | buf.ptr, &buf_user->start); | |
1da177e4 LT |
634 | break; |
635 | } | |
636 | ||
aea7cea9 KC |
637 | case MEMWRITEOOB64: |
638 | { | |
639 | struct mtd_oob_buf64 buf; | |
640 | struct mtd_oob_buf64 __user *buf_user = argp; | |
641 | ||
642 | if (copy_from_user(&buf, argp, sizeof(buf))) | |
643 | ret = -EFAULT; | |
644 | else | |
645 | ret = mtd_do_writeoob(file, mtd, buf.start, buf.length, | |
646 | (void __user *)(uintptr_t)buf.usr_ptr, | |
647 | &buf_user->length); | |
648 | break; | |
649 | } | |
650 | ||
651 | case MEMREADOOB64: | |
652 | { | |
653 | struct mtd_oob_buf64 buf; | |
654 | struct mtd_oob_buf64 __user *buf_user = argp; | |
655 | ||
656 | if (copy_from_user(&buf, argp, sizeof(buf))) | |
657 | ret = -EFAULT; | |
658 | else | |
659 | ret = mtd_do_readoob(mtd, buf.start, buf.length, | |
660 | (void __user *)(uintptr_t)buf.usr_ptr, | |
661 | &buf_user->length); | |
662 | break; | |
663 | } | |
664 | ||
1da177e4 LT |
665 | case MEMLOCK: |
666 | { | |
175428b2 | 667 | struct erase_info_user einfo; |
1da177e4 | 668 | |
175428b2 | 669 | if (copy_from_user(&einfo, argp, sizeof(einfo))) |
1da177e4 LT |
670 | return -EFAULT; |
671 | ||
672 | if (!mtd->lock) | |
673 | ret = -EOPNOTSUPP; | |
674 | else | |
175428b2 | 675 | ret = mtd->lock(mtd, einfo.start, einfo.length); |
1da177e4 LT |
676 | break; |
677 | } | |
678 | ||
679 | case MEMUNLOCK: | |
680 | { | |
175428b2 | 681 | struct erase_info_user einfo; |
1da177e4 | 682 | |
175428b2 | 683 | if (copy_from_user(&einfo, argp, sizeof(einfo))) |
1da177e4 LT |
684 | return -EFAULT; |
685 | ||
686 | if (!mtd->unlock) | |
687 | ret = -EOPNOTSUPP; | |
688 | else | |
175428b2 | 689 | ret = mtd->unlock(mtd, einfo.start, einfo.length); |
1da177e4 LT |
690 | break; |
691 | } | |
692 | ||
9938424f RC |
693 | case MEMISLOCKED: |
694 | { | |
695 | struct erase_info_user einfo; | |
696 | ||
697 | if (copy_from_user(&einfo, argp, sizeof(einfo))) | |
698 | return -EFAULT; | |
699 | ||
700 | if (!mtd->is_locked) | |
701 | ret = -EOPNOTSUPP; | |
702 | else | |
703 | ret = mtd->is_locked(mtd, einfo.start, einfo.length); | |
704 | break; | |
705 | } | |
706 | ||
5bd34c09 | 707 | /* Legacy interface */ |
1da177e4 LT |
708 | case MEMGETOOBSEL: |
709 | { | |
5bd34c09 TG |
710 | struct nand_oobinfo oi; |
711 | ||
712 | if (!mtd->ecclayout) | |
713 | return -EOPNOTSUPP; | |
714 | if (mtd->ecclayout->eccbytes > ARRAY_SIZE(oi.eccpos)) | |
715 | return -EINVAL; | |
716 | ||
717 | oi.useecc = MTD_NANDECC_AUTOPLACE; | |
718 | memcpy(&oi.eccpos, mtd->ecclayout->eccpos, sizeof(oi.eccpos)); | |
719 | memcpy(&oi.oobfree, mtd->ecclayout->oobfree, | |
720 | sizeof(oi.oobfree)); | |
d25ade71 | 721 | oi.eccbytes = mtd->ecclayout->eccbytes; |
5bd34c09 TG |
722 | |
723 | if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo))) | |
1da177e4 LT |
724 | return -EFAULT; |
725 | break; | |
726 | } | |
727 | ||
728 | case MEMGETBADBLOCK: | |
729 | { | |
730 | loff_t offs; | |
97894cda | 731 | |
1da177e4 LT |
732 | if (copy_from_user(&offs, argp, sizeof(loff_t))) |
733 | return -EFAULT; | |
734 | if (!mtd->block_isbad) | |
735 | ret = -EOPNOTSUPP; | |
736 | else | |
737 | return mtd->block_isbad(mtd, offs); | |
738 | break; | |
739 | } | |
740 | ||
741 | case MEMSETBADBLOCK: | |
742 | { | |
743 | loff_t offs; | |
744 | ||
745 | if (copy_from_user(&offs, argp, sizeof(loff_t))) | |
746 | return -EFAULT; | |
747 | if (!mtd->block_markbad) | |
748 | ret = -EOPNOTSUPP; | |
749 | else | |
750 | return mtd->block_markbad(mtd, offs); | |
751 | break; | |
752 | } | |
753 | ||
34a82443 | 754 | #ifdef CONFIG_HAVE_MTD_OTP |
31f4233b NP |
755 | case OTPSELECT: |
756 | { | |
757 | int mode; | |
758 | if (copy_from_user(&mode, argp, sizeof(int))) | |
759 | return -EFAULT; | |
f1a28c02 TG |
760 | |
761 | mfi->mode = MTD_MODE_NORMAL; | |
762 | ||
763 | ret = otp_select_filemode(mfi, mode); | |
764 | ||
81dba488 | 765 | file->f_pos = 0; |
31f4233b NP |
766 | break; |
767 | } | |
768 | ||
769 | case OTPGETREGIONCOUNT: | |
770 | case OTPGETREGIONINFO: | |
771 | { | |
772 | struct otp_info *buf = kmalloc(4096, GFP_KERNEL); | |
773 | if (!buf) | |
774 | return -ENOMEM; | |
775 | ret = -EOPNOTSUPP; | |
f1a28c02 TG |
776 | switch (mfi->mode) { |
777 | case MTD_MODE_OTP_FACTORY: | |
31f4233b NP |
778 | if (mtd->get_fact_prot_info) |
779 | ret = mtd->get_fact_prot_info(mtd, buf, 4096); | |
780 | break; | |
781 | case MTD_MODE_OTP_USER: | |
782 | if (mtd->get_user_prot_info) | |
783 | ret = mtd->get_user_prot_info(mtd, buf, 4096); | |
784 | break; | |
f1a28c02 TG |
785 | default: |
786 | break; | |
31f4233b NP |
787 | } |
788 | if (ret >= 0) { | |
789 | if (cmd == OTPGETREGIONCOUNT) { | |
790 | int nbr = ret / sizeof(struct otp_info); | |
791 | ret = copy_to_user(argp, &nbr, sizeof(int)); | |
792 | } else | |
793 | ret = copy_to_user(argp, buf, ret); | |
794 | if (ret) | |
795 | ret = -EFAULT; | |
796 | } | |
797 | kfree(buf); | |
798 | break; | |
799 | } | |
800 | ||
801 | case OTPLOCK: | |
802 | { | |
175428b2 | 803 | struct otp_info oinfo; |
31f4233b | 804 | |
f1a28c02 | 805 | if (mfi->mode != MTD_MODE_OTP_USER) |
31f4233b | 806 | return -EINVAL; |
175428b2 | 807 | if (copy_from_user(&oinfo, argp, sizeof(oinfo))) |
31f4233b NP |
808 | return -EFAULT; |
809 | if (!mtd->lock_user_prot_reg) | |
810 | return -EOPNOTSUPP; | |
175428b2 | 811 | ret = mtd->lock_user_prot_reg(mtd, oinfo.start, oinfo.length); |
31f4233b NP |
812 | break; |
813 | } | |
814 | #endif | |
815 | ||
f1a28c02 TG |
816 | case ECCGETLAYOUT: |
817 | { | |
818 | if (!mtd->ecclayout) | |
819 | return -EOPNOTSUPP; | |
820 | ||
d25ade71 | 821 | if (copy_to_user(argp, mtd->ecclayout, |
f1a28c02 TG |
822 | sizeof(struct nand_ecclayout))) |
823 | return -EFAULT; | |
824 | break; | |
825 | } | |
826 | ||
827 | case ECCGETSTATS: | |
828 | { | |
829 | if (copy_to_user(argp, &mtd->ecc_stats, | |
830 | sizeof(struct mtd_ecc_stats))) | |
831 | return -EFAULT; | |
832 | break; | |
833 | } | |
834 | ||
835 | case MTDFILEMODE: | |
836 | { | |
837 | mfi->mode = 0; | |
838 | ||
839 | switch(arg) { | |
840 | case MTD_MODE_OTP_FACTORY: | |
841 | case MTD_MODE_OTP_USER: | |
842 | ret = otp_select_filemode(mfi, arg); | |
843 | break; | |
844 | ||
845 | case MTD_MODE_RAW: | |
846 | if (!mtd->read_oob || !mtd->write_oob) | |
847 | return -EOPNOTSUPP; | |
848 | mfi->mode = arg; | |
849 | ||
850 | case MTD_MODE_NORMAL: | |
851 | break; | |
852 | default: | |
853 | ret = -EINVAL; | |
854 | } | |
855 | file->f_pos = 0; | |
856 | break; | |
857 | } | |
858 | ||
1da177e4 LT |
859 | default: |
860 | ret = -ENOTTY; | |
861 | } | |
862 | ||
863 | return ret; | |
864 | } /* memory_ioctl */ | |
865 | ||
55929332 AB |
866 | static long mtd_unlocked_ioctl(struct file *file, u_int cmd, u_long arg) |
867 | { | |
868 | int ret; | |
869 | ||
5aa82940 | 870 | mutex_lock(&mtd_mutex); |
55929332 | 871 | ret = mtd_ioctl(file, cmd, arg); |
5aa82940 | 872 | mutex_unlock(&mtd_mutex); |
55929332 AB |
873 | |
874 | return ret; | |
875 | } | |
876 | ||
97718540 KC |
877 | #ifdef CONFIG_COMPAT |
878 | ||
879 | struct mtd_oob_buf32 { | |
880 | u_int32_t start; | |
881 | u_int32_t length; | |
882 | compat_caddr_t ptr; /* unsigned char* */ | |
883 | }; | |
884 | ||
885 | #define MEMWRITEOOB32 _IOWR('M', 3, struct mtd_oob_buf32) | |
886 | #define MEMREADOOB32 _IOWR('M', 4, struct mtd_oob_buf32) | |
887 | ||
888 | static long mtd_compat_ioctl(struct file *file, unsigned int cmd, | |
889 | unsigned long arg) | |
890 | { | |
891 | struct mtd_file_info *mfi = file->private_data; | |
892 | struct mtd_info *mtd = mfi->mtd; | |
0b6585ce | 893 | void __user *argp = compat_ptr(arg); |
97718540 KC |
894 | int ret = 0; |
895 | ||
5aa82940 | 896 | mutex_lock(&mtd_mutex); |
97718540 KC |
897 | |
898 | switch (cmd) { | |
899 | case MEMWRITEOOB32: | |
900 | { | |
901 | struct mtd_oob_buf32 buf; | |
902 | struct mtd_oob_buf32 __user *buf_user = argp; | |
903 | ||
904 | if (copy_from_user(&buf, argp, sizeof(buf))) | |
905 | ret = -EFAULT; | |
906 | else | |
907 | ret = mtd_do_writeoob(file, mtd, buf.start, | |
908 | buf.length, compat_ptr(buf.ptr), | |
909 | &buf_user->length); | |
910 | break; | |
911 | } | |
912 | ||
913 | case MEMREADOOB32: | |
914 | { | |
915 | struct mtd_oob_buf32 buf; | |
916 | struct mtd_oob_buf32 __user *buf_user = argp; | |
917 | ||
918 | /* NOTE: writes return length to buf->start */ | |
919 | if (copy_from_user(&buf, argp, sizeof(buf))) | |
920 | ret = -EFAULT; | |
921 | else | |
922 | ret = mtd_do_readoob(mtd, buf.start, | |
923 | buf.length, compat_ptr(buf.ptr), | |
924 | &buf_user->start); | |
925 | break; | |
926 | } | |
927 | default: | |
55929332 | 928 | ret = mtd_ioctl(file, cmd, (unsigned long)argp); |
97718540 KC |
929 | } |
930 | ||
5aa82940 | 931 | mutex_unlock(&mtd_mutex); |
97718540 KC |
932 | |
933 | return ret; | |
934 | } | |
935 | ||
936 | #endif /* CONFIG_COMPAT */ | |
937 | ||
402d3265 DH |
938 | /* |
939 | * try to determine where a shared mapping can be made | |
940 | * - only supported for NOMMU at the moment (MMU can't doesn't copy private | |
941 | * mappings) | |
942 | */ | |
943 | #ifndef CONFIG_MMU | |
944 | static unsigned long mtd_get_unmapped_area(struct file *file, | |
945 | unsigned long addr, | |
946 | unsigned long len, | |
947 | unsigned long pgoff, | |
948 | unsigned long flags) | |
949 | { | |
950 | struct mtd_file_info *mfi = file->private_data; | |
951 | struct mtd_info *mtd = mfi->mtd; | |
952 | ||
953 | if (mtd->get_unmapped_area) { | |
954 | unsigned long offset; | |
955 | ||
956 | if (addr != 0) | |
957 | return (unsigned long) -EINVAL; | |
958 | ||
959 | if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT)) | |
960 | return (unsigned long) -EINVAL; | |
961 | ||
962 | offset = pgoff << PAGE_SHIFT; | |
963 | if (offset > mtd->size - len) | |
964 | return (unsigned long) -EINVAL; | |
965 | ||
966 | return mtd->get_unmapped_area(mtd, len, offset, flags); | |
967 | } | |
968 | ||
969 | /* can't map directly */ | |
970 | return (unsigned long) -ENOSYS; | |
971 | } | |
972 | #endif | |
973 | ||
974 | /* | |
975 | * set up a mapping for shared memory segments | |
976 | */ | |
977 | static int mtd_mmap(struct file *file, struct vm_area_struct *vma) | |
978 | { | |
979 | #ifdef CONFIG_MMU | |
980 | struct mtd_file_info *mfi = file->private_data; | |
981 | struct mtd_info *mtd = mfi->mtd; | |
dd02b67d AG |
982 | struct map_info *map = mtd->priv; |
983 | unsigned long start; | |
984 | unsigned long off; | |
985 | u32 len; | |
986 | ||
987 | if (mtd->type == MTD_RAM || mtd->type == MTD_ROM) { | |
988 | off = vma->vm_pgoff << PAGE_SHIFT; | |
989 | start = map->phys; | |
990 | len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size); | |
991 | start &= PAGE_MASK; | |
992 | if ((vma->vm_end - vma->vm_start + off) > len) | |
993 | return -EINVAL; | |
994 | ||
995 | off += start; | |
996 | vma->vm_pgoff = off >> PAGE_SHIFT; | |
997 | vma->vm_flags |= VM_IO | VM_RESERVED; | |
998 | ||
999 | #ifdef pgprot_noncached | |
1000 | if (file->f_flags & O_DSYNC || off >= __pa(high_memory)) | |
1001 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); | |
1002 | #endif | |
1003 | if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, | |
1004 | vma->vm_end - vma->vm_start, | |
1005 | vma->vm_page_prot)) | |
1006 | return -EAGAIN; | |
402d3265 | 1007 | |
402d3265 | 1008 | return 0; |
dd02b67d | 1009 | } |
402d3265 DH |
1010 | return -ENOSYS; |
1011 | #else | |
1012 | return vma->vm_flags & VM_SHARED ? 0 : -ENOSYS; | |
1013 | #endif | |
1014 | } | |
1015 | ||
d54b1fdb | 1016 | static const struct file_operations mtd_fops = { |
1da177e4 LT |
1017 | .owner = THIS_MODULE, |
1018 | .llseek = mtd_lseek, | |
1019 | .read = mtd_read, | |
1020 | .write = mtd_write, | |
55929332 | 1021 | .unlocked_ioctl = mtd_unlocked_ioctl, |
97718540 KC |
1022 | #ifdef CONFIG_COMPAT |
1023 | .compat_ioctl = mtd_compat_ioctl, | |
1024 | #endif | |
1da177e4 LT |
1025 | .open = mtd_open, |
1026 | .release = mtd_close, | |
402d3265 DH |
1027 | .mmap = mtd_mmap, |
1028 | #ifndef CONFIG_MMU | |
1029 | .get_unmapped_area = mtd_get_unmapped_area, | |
1030 | #endif | |
1da177e4 LT |
1031 | }; |
1032 | ||
51139ada AV |
1033 | static struct dentry *mtd_inodefs_mount(struct file_system_type *fs_type, |
1034 | int flags, const char *dev_name, void *data) | |
cd874237 | 1035 | { |
51139ada | 1036 | return mount_pseudo(fs_type, "mtd_inode:", NULL, MTD_INODE_FS_MAGIC); |
cd874237 KS |
1037 | } |
1038 | ||
1039 | static struct file_system_type mtd_inodefs_type = { | |
1040 | .name = "mtd_inodefs", | |
51139ada | 1041 | .mount = mtd_inodefs_mount, |
cd874237 KS |
1042 | .kill_sb = kill_anon_super, |
1043 | }; | |
1044 | ||
1045 | static void mtdchar_notify_add(struct mtd_info *mtd) | |
1046 | { | |
1047 | } | |
1048 | ||
1049 | static void mtdchar_notify_remove(struct mtd_info *mtd) | |
1050 | { | |
1051 | struct inode *mtd_ino = ilookup(mtd_inode_mnt->mnt_sb, mtd->index); | |
1052 | ||
1053 | if (mtd_ino) { | |
1054 | /* Destroy the inode if it exists */ | |
1055 | mtd_ino->i_nlink = 0; | |
1056 | iput(mtd_ino); | |
1057 | } | |
1058 | } | |
1059 | ||
1060 | static struct mtd_notifier mtdchar_notifier = { | |
1061 | .add = mtdchar_notify_add, | |
1062 | .remove = mtdchar_notify_remove, | |
1063 | }; | |
1064 | ||
1da177e4 LT |
1065 | static int __init init_mtdchar(void) |
1066 | { | |
cd874237 | 1067 | int ret; |
1f24b5a8 | 1068 | |
cd874237 | 1069 | ret = __register_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, |
dad0db31 | 1070 | "mtd", &mtd_fops); |
cd874237 KS |
1071 | if (ret < 0) { |
1072 | pr_notice("Can't allocate major number %d for " | |
1073 | "Memory Technology Devices.\n", MTD_CHAR_MAJOR); | |
1074 | return ret; | |
9bc7b387 TP |
1075 | } |
1076 | ||
cd874237 KS |
1077 | ret = register_filesystem(&mtd_inodefs_type); |
1078 | if (ret) { | |
1079 | pr_notice("Can't register mtd_inodefs filesystem: %d\n", ret); | |
1080 | goto err_unregister_chdev; | |
1081 | } | |
1082 | ||
1083 | mtd_inode_mnt = kern_mount(&mtd_inodefs_type); | |
1084 | if (IS_ERR(mtd_inode_mnt)) { | |
1085 | ret = PTR_ERR(mtd_inode_mnt); | |
1086 | pr_notice("Error mounting mtd_inodefs filesystem: %d\n", ret); | |
1087 | goto err_unregister_filesystem; | |
1088 | } | |
1089 | register_mtd_user(&mtdchar_notifier); | |
1090 | ||
1091 | return ret; | |
1092 | ||
1093 | err_unregister_filesystem: | |
1094 | unregister_filesystem(&mtd_inodefs_type); | |
1095 | err_unregister_chdev: | |
1096 | __unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd"); | |
1097 | return ret; | |
1da177e4 LT |
1098 | } |
1099 | ||
1100 | static void __exit cleanup_mtdchar(void) | |
1101 | { | |
cd874237 KS |
1102 | unregister_mtd_user(&mtdchar_notifier); |
1103 | mntput(mtd_inode_mnt); | |
1104 | unregister_filesystem(&mtd_inodefs_type); | |
dad0db31 | 1105 | __unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd"); |
1da177e4 LT |
1106 | } |
1107 | ||
1108 | module_init(init_mtdchar); | |
1109 | module_exit(cleanup_mtdchar); | |
1110 | ||
1f24b5a8 | 1111 | MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR); |
1da177e4 LT |
1112 | |
1113 | MODULE_LICENSE("GPL"); | |
1114 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); | |
1115 | MODULE_DESCRIPTION("Direct character-device access to MTD devices"); | |
90160e13 | 1116 | MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR); |