Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Simple MTD partitioning layer |
| 3 | * |
| 4 | * (C) 2000 Nicolas Pitre <nico@cam.org> |
| 5 | * |
| 6 | * This code is GPL |
| 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * 02-21-2002 Thomas Gleixner <gleixner@autronix.de> |
| 9 | * added support for read_oob, write_oob |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 10 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/types.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/kmod.h> |
| 18 | #include <linux/mtd/mtd.h> |
| 19 | #include <linux/mtd/partitions.h> |
| 20 | #include <linux/mtd/compatmac.h> |
| 21 | |
| 22 | /* Our partition linked list */ |
| 23 | static LIST_HEAD(mtd_partitions); |
| 24 | |
| 25 | /* Our partition node structure */ |
| 26 | struct mtd_part { |
| 27 | struct mtd_info mtd; |
| 28 | struct mtd_info *master; |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 29 | uint64_t offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | int index; |
| 31 | struct list_head list; |
| 32 | int registered; |
| 33 | }; |
| 34 | |
| 35 | /* |
| 36 | * Given a pointer to the MTD object in the mtd_part structure, we can retrieve |
| 37 | * the pointer to that structure with this macro. |
| 38 | */ |
| 39 | #define PART(x) ((struct mtd_part *)(x)) |
| 40 | |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 41 | |
| 42 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | * MTD methods which simply translate the effective address and pass through |
| 44 | * to the _real_ device. |
| 45 | */ |
| 46 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 47 | static int part_read(struct mtd_info *mtd, loff_t from, size_t len, |
| 48 | size_t *retlen, u_char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | struct mtd_part *part = PART(mtd); |
Yauhen Kharuzhy | d8877f1 | 2009-03-27 00:41:09 +0200 | [diff] [blame] | 51 | struct mtd_ecc_stats stats; |
Thomas Gleixner | f1a28c0 | 2006-05-30 00:37:34 +0200 | [diff] [blame] | 52 | int res; |
| 53 | |
Yauhen Kharuzhy | d8877f1 | 2009-03-27 00:41:09 +0200 | [diff] [blame] | 54 | stats = part->master->ecc_stats; |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | if (from >= mtd->size) |
| 57 | len = 0; |
| 58 | else if (from + len > mtd->size) |
| 59 | len = mtd->size - from; |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 60 | res = part->master->read(part->master, from + part->offset, |
Thomas Gleixner | 9223a45 | 2006-05-23 17:21:03 +0200 | [diff] [blame] | 61 | len, retlen, buf); |
Thomas Gleixner | f1a28c0 | 2006-05-30 00:37:34 +0200 | [diff] [blame] | 62 | if (unlikely(res)) { |
| 63 | if (res == -EUCLEAN) |
Yauhen Kharuzhy | d8877f1 | 2009-03-27 00:41:09 +0200 | [diff] [blame] | 64 | mtd->ecc_stats.corrected += part->master->ecc_stats.corrected - stats.corrected; |
Thomas Gleixner | f1a28c0 | 2006-05-30 00:37:34 +0200 | [diff] [blame] | 65 | if (res == -EBADMSG) |
Yauhen Kharuzhy | d8877f1 | 2009-03-27 00:41:09 +0200 | [diff] [blame] | 66 | mtd->ecc_stats.failed += part->master->ecc_stats.failed - stats.failed; |
Thomas Gleixner | f1a28c0 | 2006-05-30 00:37:34 +0200 | [diff] [blame] | 67 | } |
| 68 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 71 | static int part_point(struct mtd_info *mtd, loff_t from, size_t len, |
| 72 | size_t *retlen, void **virt, resource_size_t *phys) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
| 74 | struct mtd_part *part = PART(mtd); |
| 75 | if (from >= mtd->size) |
| 76 | len = 0; |
| 77 | else if (from + len > mtd->size) |
| 78 | len = mtd->size - from; |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 79 | return part->master->point (part->master, from + part->offset, |
Jared Hulbert | a98889f | 2008-04-29 23:26:49 -0700 | [diff] [blame] | 80 | len, retlen, virt, phys); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
Thomas Gleixner | 9223a45 | 2006-05-23 17:21:03 +0200 | [diff] [blame] | 82 | |
Jared Hulbert | a98889f | 2008-04-29 23:26:49 -0700 | [diff] [blame] | 83 | static void part_unpoint(struct mtd_info *mtd, loff_t from, size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
| 85 | struct mtd_part *part = PART(mtd); |
| 86 | |
Jared Hulbert | a98889f | 2008-04-29 23:26:49 -0700 | [diff] [blame] | 87 | part->master->unpoint(part->master, from + part->offset, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
David Howells | 402d326 | 2009-02-12 10:40:00 +0000 | [diff] [blame] | 90 | static unsigned long part_get_unmapped_area(struct mtd_info *mtd, |
| 91 | unsigned long len, |
| 92 | unsigned long offset, |
| 93 | unsigned long flags) |
| 94 | { |
| 95 | struct mtd_part *part = PART(mtd); |
| 96 | |
| 97 | offset += part->offset; |
| 98 | return part->master->get_unmapped_area(part->master, len, offset, |
| 99 | flags); |
| 100 | } |
| 101 | |
Thomas Gleixner | 8593fbc | 2006-05-29 03:26:58 +0200 | [diff] [blame] | 102 | static int part_read_oob(struct mtd_info *mtd, loff_t from, |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 103 | struct mtd_oob_ops *ops) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
| 105 | struct mtd_part *part = PART(mtd); |
Thomas Gleixner | f1a28c0 | 2006-05-30 00:37:34 +0200 | [diff] [blame] | 106 | int res; |
Thomas Gleixner | 8593fbc | 2006-05-29 03:26:58 +0200 | [diff] [blame] | 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | if (from >= mtd->size) |
Thomas Gleixner | 8593fbc | 2006-05-29 03:26:58 +0200 | [diff] [blame] | 109 | return -EINVAL; |
Vitaly Wool | 7014568 | 2006-11-03 18:20:38 +0300 | [diff] [blame] | 110 | if (ops->datbuf && from + ops->len > mtd->size) |
Thomas Gleixner | 8593fbc | 2006-05-29 03:26:58 +0200 | [diff] [blame] | 111 | return -EINVAL; |
Thomas Gleixner | f1a28c0 | 2006-05-30 00:37:34 +0200 | [diff] [blame] | 112 | res = part->master->read_oob(part->master, from + part->offset, ops); |
| 113 | |
| 114 | if (unlikely(res)) { |
| 115 | if (res == -EUCLEAN) |
| 116 | mtd->ecc_stats.corrected++; |
| 117 | if (res == -EBADMSG) |
| 118 | mtd->ecc_stats.failed++; |
| 119 | } |
| 120 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 123 | static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from, |
| 124 | size_t len, size_t *retlen, u_char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
| 126 | struct mtd_part *part = PART(mtd); |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 127 | return part->master->read_user_prot_reg(part->master, from, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | len, retlen, buf); |
| 129 | } |
| 130 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 131 | static int part_get_user_prot_info(struct mtd_info *mtd, |
| 132 | struct otp_info *buf, size_t len) |
Nicolas Pitre | f77814d | 2005-02-08 17:11:19 +0000 | [diff] [blame] | 133 | { |
| 134 | struct mtd_part *part = PART(mtd); |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 135 | return part->master->get_user_prot_info(part->master, buf, len); |
Nicolas Pitre | f77814d | 2005-02-08 17:11:19 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 138 | static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, |
| 139 | size_t len, size_t *retlen, u_char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | { |
| 141 | struct mtd_part *part = PART(mtd); |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 142 | return part->master->read_fact_prot_reg(part->master, from, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | len, retlen, buf); |
| 144 | } |
| 145 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 146 | static int part_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf, |
| 147 | size_t len) |
Nicolas Pitre | f77814d | 2005-02-08 17:11:19 +0000 | [diff] [blame] | 148 | { |
| 149 | struct mtd_part *part = PART(mtd); |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 150 | return part->master->get_fact_prot_info(part->master, buf, len); |
Nicolas Pitre | f77814d | 2005-02-08 17:11:19 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 153 | static int part_write(struct mtd_info *mtd, loff_t to, size_t len, |
| 154 | size_t *retlen, const u_char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
| 156 | struct mtd_part *part = PART(mtd); |
| 157 | if (!(mtd->flags & MTD_WRITEABLE)) |
| 158 | return -EROFS; |
| 159 | if (to >= mtd->size) |
| 160 | len = 0; |
| 161 | else if (to + len > mtd->size) |
| 162 | len = mtd->size - to; |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 163 | return part->master->write(part->master, to + part->offset, |
Thomas Gleixner | 9223a45 | 2006-05-23 17:21:03 +0200 | [diff] [blame] | 164 | len, retlen, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 167 | static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len, |
| 168 | size_t *retlen, const u_char *buf) |
Richard Purdie | 388bbb0 | 2008-02-06 10:17:15 +0000 | [diff] [blame] | 169 | { |
| 170 | struct mtd_part *part = PART(mtd); |
| 171 | if (!(mtd->flags & MTD_WRITEABLE)) |
| 172 | return -EROFS; |
| 173 | if (to >= mtd->size) |
| 174 | len = 0; |
| 175 | else if (to + len > mtd->size) |
| 176 | len = mtd->size - to; |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 177 | return part->master->panic_write(part->master, to + part->offset, |
Richard Purdie | 388bbb0 | 2008-02-06 10:17:15 +0000 | [diff] [blame] | 178 | len, retlen, buf); |
| 179 | } |
| 180 | |
Thomas Gleixner | 8593fbc | 2006-05-29 03:26:58 +0200 | [diff] [blame] | 181 | static int part_write_oob(struct mtd_info *mtd, loff_t to, |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 182 | struct mtd_oob_ops *ops) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { |
| 184 | struct mtd_part *part = PART(mtd); |
Thomas Gleixner | 8593fbc | 2006-05-29 03:26:58 +0200 | [diff] [blame] | 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | if (!(mtd->flags & MTD_WRITEABLE)) |
| 187 | return -EROFS; |
Thomas Gleixner | 8593fbc | 2006-05-29 03:26:58 +0200 | [diff] [blame] | 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | if (to >= mtd->size) |
Thomas Gleixner | 8593fbc | 2006-05-29 03:26:58 +0200 | [diff] [blame] | 190 | return -EINVAL; |
Vitaly Wool | 7014568 | 2006-11-03 18:20:38 +0300 | [diff] [blame] | 191 | if (ops->datbuf && to + ops->len > mtd->size) |
Thomas Gleixner | 8593fbc | 2006-05-29 03:26:58 +0200 | [diff] [blame] | 192 | return -EINVAL; |
| 193 | return part->master->write_oob(part->master, to + part->offset, ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 196 | static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from, |
| 197 | size_t len, size_t *retlen, u_char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
| 199 | struct mtd_part *part = PART(mtd); |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 200 | return part->master->write_user_prot_reg(part->master, from, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | len, retlen, buf); |
| 202 | } |
| 203 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 204 | static int part_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, |
| 205 | size_t len) |
Nicolas Pitre | f77814d | 2005-02-08 17:11:19 +0000 | [diff] [blame] | 206 | { |
| 207 | struct mtd_part *part = PART(mtd); |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 208 | return part->master->lock_user_prot_reg(part->master, from, len); |
Nicolas Pitre | f77814d | 2005-02-08 17:11:19 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 211 | static int part_writev(struct mtd_info *mtd, const struct kvec *vecs, |
| 212 | unsigned long count, loff_t to, size_t *retlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
| 214 | struct mtd_part *part = PART(mtd); |
| 215 | if (!(mtd->flags & MTD_WRITEABLE)) |
| 216 | return -EROFS; |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 217 | return part->master->writev(part->master, vecs, count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | to + part->offset, retlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 221 | static int part_erase(struct mtd_info *mtd, struct erase_info *instr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
| 223 | struct mtd_part *part = PART(mtd); |
| 224 | int ret; |
| 225 | if (!(mtd->flags & MTD_WRITEABLE)) |
| 226 | return -EROFS; |
| 227 | if (instr->addr >= mtd->size) |
| 228 | return -EINVAL; |
| 229 | instr->addr += part->offset; |
| 230 | ret = part->master->erase(part->master, instr); |
Adrian Hunter | 74641d7 | 2007-03-08 12:20:12 +0200 | [diff] [blame] | 231 | if (ret) { |
Adrian Hunter | bb0eb21 | 2008-08-12 12:40:50 +0300 | [diff] [blame] | 232 | if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN) |
Adrian Hunter | 74641d7 | 2007-03-08 12:20:12 +0200 | [diff] [blame] | 233 | instr->fail_addr -= part->offset; |
| 234 | instr->addr -= part->offset; |
| 235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | return ret; |
| 237 | } |
| 238 | |
| 239 | void mtd_erase_callback(struct erase_info *instr) |
| 240 | { |
| 241 | if (instr->mtd->erase == part_erase) { |
| 242 | struct mtd_part *part = PART(instr->mtd); |
| 243 | |
Adrian Hunter | bb0eb21 | 2008-08-12 12:40:50 +0300 | [diff] [blame] | 244 | if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | instr->fail_addr -= part->offset; |
| 246 | instr->addr -= part->offset; |
| 247 | } |
| 248 | if (instr->callback) |
| 249 | instr->callback(instr); |
| 250 | } |
| 251 | EXPORT_SYMBOL_GPL(mtd_erase_callback); |
| 252 | |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 253 | static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
| 255 | struct mtd_part *part = PART(mtd); |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 256 | if ((len + ofs) > mtd->size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | return -EINVAL; |
| 258 | return part->master->lock(part->master, ofs + part->offset, len); |
| 259 | } |
| 260 | |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 261 | static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | { |
| 263 | struct mtd_part *part = PART(mtd); |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 264 | if ((len + ofs) > mtd->size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | return -EINVAL; |
| 266 | return part->master->unlock(part->master, ofs + part->offset, len); |
| 267 | } |
| 268 | |
| 269 | static void part_sync(struct mtd_info *mtd) |
| 270 | { |
| 271 | struct mtd_part *part = PART(mtd); |
| 272 | part->master->sync(part->master); |
| 273 | } |
| 274 | |
| 275 | static int part_suspend(struct mtd_info *mtd) |
| 276 | { |
| 277 | struct mtd_part *part = PART(mtd); |
| 278 | return part->master->suspend(part->master); |
| 279 | } |
| 280 | |
| 281 | static void part_resume(struct mtd_info *mtd) |
| 282 | { |
| 283 | struct mtd_part *part = PART(mtd); |
| 284 | part->master->resume(part->master); |
| 285 | } |
| 286 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 287 | static int part_block_isbad(struct mtd_info *mtd, loff_t ofs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
| 289 | struct mtd_part *part = PART(mtd); |
| 290 | if (ofs >= mtd->size) |
| 291 | return -EINVAL; |
| 292 | ofs += part->offset; |
| 293 | return part->master->block_isbad(part->master, ofs); |
| 294 | } |
| 295 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 296 | static int part_block_markbad(struct mtd_info *mtd, loff_t ofs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
| 298 | struct mtd_part *part = PART(mtd); |
Thomas Gleixner | f1a28c0 | 2006-05-30 00:37:34 +0200 | [diff] [blame] | 299 | int res; |
| 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | if (!(mtd->flags & MTD_WRITEABLE)) |
| 302 | return -EROFS; |
| 303 | if (ofs >= mtd->size) |
| 304 | return -EINVAL; |
| 305 | ofs += part->offset; |
Thomas Gleixner | f1a28c0 | 2006-05-30 00:37:34 +0200 | [diff] [blame] | 306 | res = part->master->block_markbad(part->master, ofs); |
| 307 | if (!res) |
| 308 | mtd->ecc_stats.badblocks++; |
| 309 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 312 | /* |
| 313 | * This function unregisters and destroy all slave MTD objects which are |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | * attached to the given master MTD object. |
| 315 | */ |
| 316 | |
| 317 | int del_mtd_partitions(struct mtd_info *master) |
| 318 | { |
Chris Malley | 71a928c | 2008-05-19 20:11:50 +0100 | [diff] [blame] | 319 | struct mtd_part *slave, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Chris Malley | 71a928c | 2008-05-19 20:11:50 +0100 | [diff] [blame] | 321 | list_for_each_entry_safe(slave, next, &mtd_partitions, list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | if (slave->master == master) { |
Chris Malley | 71a928c | 2008-05-19 20:11:50 +0100 | [diff] [blame] | 323 | list_del(&slave->list); |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 324 | if (slave->registered) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | del_mtd_device(&slave->mtd); |
| 326 | kfree(slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | return 0; |
| 330 | } |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 331 | EXPORT_SYMBOL(del_mtd_partitions); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 333 | static struct mtd_part *add_one_partition(struct mtd_info *master, |
| 334 | const struct mtd_partition *part, int partno, |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 335 | uint64_t cur_offset) |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 336 | { |
| 337 | struct mtd_part *slave; |
| 338 | |
| 339 | /* allocate the partition structure */ |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 340 | slave = kzalloc(sizeof(*slave), GFP_KERNEL); |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 341 | if (!slave) { |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 342 | printk(KERN_ERR"memory allocation error while creating partitions for \"%s\"\n", |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 343 | master->name); |
| 344 | del_mtd_partitions(master); |
| 345 | return NULL; |
| 346 | } |
| 347 | list_add(&slave->list, &mtd_partitions); |
| 348 | |
| 349 | /* set up the MTD object for this partition */ |
| 350 | slave->mtd.type = master->type; |
| 351 | slave->mtd.flags = master->flags & ~part->mask_flags; |
| 352 | slave->mtd.size = part->size; |
| 353 | slave->mtd.writesize = master->writesize; |
| 354 | slave->mtd.oobsize = master->oobsize; |
| 355 | slave->mtd.oobavail = master->oobavail; |
| 356 | slave->mtd.subpage_sft = master->subpage_sft; |
| 357 | |
| 358 | slave->mtd.name = part->name; |
| 359 | slave->mtd.owner = master->owner; |
David Howells | 402d326 | 2009-02-12 10:40:00 +0000 | [diff] [blame] | 360 | slave->mtd.backing_dev_info = master->backing_dev_info; |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 361 | |
David Brownell | 1f24b5a | 2009-03-26 00:42:41 -0700 | [diff] [blame] | 362 | /* NOTE: we don't arrange MTDs as a tree; it'd be error-prone |
| 363 | * to have the same data be in two different partitions. |
| 364 | */ |
| 365 | slave->mtd.dev.parent = master->dev.parent; |
| 366 | |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 367 | slave->mtd.read = part_read; |
| 368 | slave->mtd.write = part_write; |
| 369 | |
| 370 | if (master->panic_write) |
| 371 | slave->mtd.panic_write = part_panic_write; |
| 372 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 373 | if (master->point && master->unpoint) { |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 374 | slave->mtd.point = part_point; |
| 375 | slave->mtd.unpoint = part_unpoint; |
| 376 | } |
| 377 | |
David Howells | 402d326 | 2009-02-12 10:40:00 +0000 | [diff] [blame] | 378 | if (master->get_unmapped_area) |
| 379 | slave->mtd.get_unmapped_area = part_get_unmapped_area; |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 380 | if (master->read_oob) |
| 381 | slave->mtd.read_oob = part_read_oob; |
| 382 | if (master->write_oob) |
| 383 | slave->mtd.write_oob = part_write_oob; |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 384 | if (master->read_user_prot_reg) |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 385 | slave->mtd.read_user_prot_reg = part_read_user_prot_reg; |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 386 | if (master->read_fact_prot_reg) |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 387 | slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg; |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 388 | if (master->write_user_prot_reg) |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 389 | slave->mtd.write_user_prot_reg = part_write_user_prot_reg; |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 390 | if (master->lock_user_prot_reg) |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 391 | slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg; |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 392 | if (master->get_user_prot_info) |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 393 | slave->mtd.get_user_prot_info = part_get_user_prot_info; |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 394 | if (master->get_fact_prot_info) |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 395 | slave->mtd.get_fact_prot_info = part_get_fact_prot_info; |
| 396 | if (master->sync) |
| 397 | slave->mtd.sync = part_sync; |
David Woodhouse | 4704a78 | 2009-04-05 07:56:23 -0700 | [diff] [blame^] | 398 | if (!partno && !master->dev.class && master->suspend && master->resume) { |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 399 | slave->mtd.suspend = part_suspend; |
| 400 | slave->mtd.resume = part_resume; |
| 401 | } |
| 402 | if (master->writev) |
| 403 | slave->mtd.writev = part_writev; |
| 404 | if (master->lock) |
| 405 | slave->mtd.lock = part_lock; |
| 406 | if (master->unlock) |
| 407 | slave->mtd.unlock = part_unlock; |
| 408 | if (master->block_isbad) |
| 409 | slave->mtd.block_isbad = part_block_isbad; |
| 410 | if (master->block_markbad) |
| 411 | slave->mtd.block_markbad = part_block_markbad; |
| 412 | slave->mtd.erase = part_erase; |
| 413 | slave->master = master; |
| 414 | slave->offset = part->offset; |
| 415 | slave->index = partno; |
| 416 | |
| 417 | if (slave->offset == MTDPART_OFS_APPEND) |
| 418 | slave->offset = cur_offset; |
| 419 | if (slave->offset == MTDPART_OFS_NXTBLK) { |
| 420 | slave->offset = cur_offset; |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 421 | if (mtd_mod_by_eb(cur_offset, master) != 0) { |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 422 | /* Round up to next erasesize */ |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 423 | slave->offset = (mtd_div_by_eb(cur_offset, master) + 1) * master->erasesize; |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 424 | printk(KERN_NOTICE "Moving partition %d: " |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 425 | "0x%012llx -> 0x%012llx\n", partno, |
| 426 | (unsigned long long)cur_offset, (unsigned long long)slave->offset); |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | if (slave->mtd.size == MTDPART_SIZ_FULL) |
| 430 | slave->mtd.size = master->size - slave->offset; |
| 431 | |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 432 | printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n", (unsigned long long)slave->offset, |
| 433 | (unsigned long long)(slave->offset + slave->mtd.size), slave->mtd.name); |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 434 | |
| 435 | /* let's do some sanity checks */ |
| 436 | if (slave->offset >= master->size) { |
Atsushi Nemoto | f636ffb | 2008-07-19 01:01:22 +0900 | [diff] [blame] | 437 | /* let's register it anyway to preserve ordering */ |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 438 | slave->offset = 0; |
| 439 | slave->mtd.size = 0; |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 440 | printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n", |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 441 | part->name); |
Atsushi Nemoto | f636ffb | 2008-07-19 01:01:22 +0900 | [diff] [blame] | 442 | goto out_register; |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 443 | } |
| 444 | if (slave->offset + slave->mtd.size > master->size) { |
| 445 | slave->mtd.size = master->size - slave->offset; |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 446 | printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#llx\n", |
| 447 | part->name, master->name, (unsigned long long)slave->mtd.size); |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 448 | } |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 449 | if (master->numeraseregions > 1) { |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 450 | /* Deal with variable erase size stuff */ |
Atsushi Nemoto | 6910c13 | 2008-07-19 01:00:57 +0900 | [diff] [blame] | 451 | int i, max = master->numeraseregions; |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 452 | u64 end = slave->offset + slave->mtd.size; |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 453 | struct mtd_erase_region_info *regions = master->eraseregions; |
| 454 | |
Atsushi Nemoto | 6910c13 | 2008-07-19 01:00:57 +0900 | [diff] [blame] | 455 | /* Find the first erase regions which is part of this |
| 456 | * partition. */ |
| 457 | for (i = 0; i < max && regions[i].offset <= slave->offset; i++) |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 458 | ; |
Atsushi Nemoto | 6910c13 | 2008-07-19 01:00:57 +0900 | [diff] [blame] | 459 | /* The loop searched for the region _behind_ the first one */ |
| 460 | i--; |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 461 | |
Atsushi Nemoto | 6910c13 | 2008-07-19 01:00:57 +0900 | [diff] [blame] | 462 | /* Pick biggest erasesize */ |
| 463 | for (; i < max && regions[i].offset < end; i++) { |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 464 | if (slave->mtd.erasesize < regions[i].erasesize) { |
| 465 | slave->mtd.erasesize = regions[i].erasesize; |
| 466 | } |
| 467 | } |
Atsushi Nemoto | 6910c13 | 2008-07-19 01:00:57 +0900 | [diff] [blame] | 468 | BUG_ON(slave->mtd.erasesize == 0); |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 469 | } else { |
| 470 | /* Single erase size */ |
| 471 | slave->mtd.erasesize = master->erasesize; |
| 472 | } |
| 473 | |
| 474 | if ((slave->mtd.flags & MTD_WRITEABLE) && |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 475 | mtd_mod_by_eb(slave->offset, &slave->mtd)) { |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 476 | /* Doesn't start on a boundary of major erase size */ |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 477 | /* FIXME: Let it be writable if it is on a boundary of |
| 478 | * _minor_ erase size though */ |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 479 | slave->mtd.flags &= ~MTD_WRITEABLE; |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 480 | printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n", |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 481 | part->name); |
| 482 | } |
| 483 | if ((slave->mtd.flags & MTD_WRITEABLE) && |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 484 | mtd_mod_by_eb(slave->mtd.size, &slave->mtd)) { |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 485 | slave->mtd.flags &= ~MTD_WRITEABLE; |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 486 | printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n", |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 487 | part->name); |
| 488 | } |
| 489 | |
| 490 | slave->mtd.ecclayout = master->ecclayout; |
| 491 | if (master->block_isbad) { |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 492 | uint64_t offs = 0; |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 493 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 494 | while (offs < slave->mtd.size) { |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 495 | if (master->block_isbad(master, |
| 496 | offs + slave->offset)) |
| 497 | slave->mtd.ecc_stats.badblocks++; |
| 498 | offs += slave->mtd.erasesize; |
| 499 | } |
| 500 | } |
| 501 | |
Atsushi Nemoto | f636ffb | 2008-07-19 01:01:22 +0900 | [diff] [blame] | 502 | out_register: |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 503 | if (part->mtdp) { |
| 504 | /* store the object pointer (caller may or may not register it*/ |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 505 | *part->mtdp = &slave->mtd; |
| 506 | slave->registered = 0; |
| 507 | } else { |
| 508 | /* register our partition */ |
| 509 | add_mtd_device(&slave->mtd); |
| 510 | slave->registered = 1; |
| 511 | } |
| 512 | return slave; |
| 513 | } |
| 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | /* |
| 516 | * This function, given a master MTD object and a partition table, creates |
| 517 | * and registers slave MTD objects which are bound to the master according to |
| 518 | * the partition definitions. |
David Brownell | 1f24b5a | 2009-03-26 00:42:41 -0700 | [diff] [blame] | 519 | * |
| 520 | * We don't register the master, or expect the caller to have done so, |
| 521 | * for reasons of data integrity. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | */ |
| 523 | |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 524 | int add_mtd_partitions(struct mtd_info *master, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | const struct mtd_partition *parts, |
| 526 | int nbparts) |
| 527 | { |
| 528 | struct mtd_part *slave; |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 529 | uint64_t cur_offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | int i; |
| 531 | |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 532 | printk(KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
| 534 | for (i = 0; i < nbparts; i++) { |
Atsushi Nemoto | 7788ba7 | 2008-07-19 01:00:18 +0900 | [diff] [blame] | 535 | slave = add_one_partition(master, parts + i, i, cur_offset); |
| 536 | if (!slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | cur_offset = slave->offset + slave->mtd.size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | return 0; |
| 542 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | EXPORT_SYMBOL(add_mtd_partitions); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
| 545 | static DEFINE_SPINLOCK(part_parser_lock); |
| 546 | static LIST_HEAD(part_parsers); |
| 547 | |
| 548 | static struct mtd_part_parser *get_partition_parser(const char *name) |
| 549 | { |
Chris Malley | 71a928c | 2008-05-19 20:11:50 +0100 | [diff] [blame] | 550 | struct mtd_part_parser *p, *ret = NULL; |
| 551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | spin_lock(&part_parser_lock); |
| 553 | |
Chris Malley | 71a928c | 2008-05-19 20:11:50 +0100 | [diff] [blame] | 554 | list_for_each_entry(p, &part_parsers, list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | if (!strcmp(p->name, name) && try_module_get(p->owner)) { |
| 556 | ret = p; |
| 557 | break; |
| 558 | } |
Chris Malley | 71a928c | 2008-05-19 20:11:50 +0100 | [diff] [blame] | 559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | spin_unlock(&part_parser_lock); |
| 561 | |
| 562 | return ret; |
| 563 | } |
| 564 | |
| 565 | int register_mtd_parser(struct mtd_part_parser *p) |
| 566 | { |
| 567 | spin_lock(&part_parser_lock); |
| 568 | list_add(&p->list, &part_parsers); |
| 569 | spin_unlock(&part_parser_lock); |
| 570 | |
| 571 | return 0; |
| 572 | } |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 573 | EXPORT_SYMBOL_GPL(register_mtd_parser); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | int deregister_mtd_parser(struct mtd_part_parser *p) |
| 576 | { |
| 577 | spin_lock(&part_parser_lock); |
| 578 | list_del(&p->list); |
| 579 | spin_unlock(&part_parser_lock); |
| 580 | return 0; |
| 581 | } |
Atsushi Nemoto | b33a288 | 2008-07-19 01:00:33 +0900 | [diff] [blame] | 582 | EXPORT_SYMBOL_GPL(deregister_mtd_parser); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 584 | int parse_mtd_partitions(struct mtd_info *master, const char **types, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | struct mtd_partition **pparts, unsigned long origin) |
| 586 | { |
| 587 | struct mtd_part_parser *parser; |
| 588 | int ret = 0; |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | for ( ; ret <= 0 && *types; types++) { |
| 591 | parser = get_partition_parser(*types); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | if (!parser && !request_module("%s", *types)) |
| 593 | parser = get_partition_parser(*types); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | if (!parser) { |
| 595 | printk(KERN_NOTICE "%s partition parsing not available\n", |
| 596 | *types); |
| 597 | continue; |
| 598 | } |
| 599 | ret = (*parser->parse_fn)(master, pparts, origin); |
| 600 | if (ret > 0) { |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 601 | printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | ret, parser->name, master->name); |
| 603 | } |
| 604 | put_partition_parser(parser); |
| 605 | } |
| 606 | return ret; |
| 607 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | EXPORT_SYMBOL_GPL(parse_mtd_partitions); |