aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2011-06-10 10:18:28 -0400
committerArtem Bityutskiy <artem.bityutskiy@intel.com>2011-09-11 08:02:10 -0400
commitc7975330154af17aecc167b33ca866b6b3d98918 (patch)
treeb9895816b3f9bd53758410754ad1b1061986a8dd
parentf722013ee9fd24623df31dec9a91a6d02c3e2f2f (diff)
mtd: abstract last MTD partition parser argument
Encapsulate last MTD partition parser argument into a separate structure. Currently it holds only 'origin' field for RedBoot parser, but will be extended in future to contain at least device_node for OF devices. Amended commentary to make kerneldoc happy Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
-rw-r--r--drivers/mtd/afs.c4
-rw-r--r--drivers/mtd/ar7part.c2
-rw-r--r--drivers/mtd/cmdlinepart.c4
-rw-r--r--drivers/mtd/mtdcore.c6
-rw-r--r--drivers/mtd/mtdpart.c7
-rw-r--r--drivers/mtd/redboot.c13
-rw-r--r--include/linux/mtd/mtd.h3
-rw-r--r--include/linux/mtd/partitions.h15
8 files changed, 33 insertions, 21 deletions
diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c
index 302372c08b56..89a02f6f65dc 100644
--- a/drivers/mtd/afs.c
+++ b/drivers/mtd/afs.c
@@ -162,8 +162,8 @@ afs_read_iis(struct mtd_info *mtd, struct image_info_struct *iis, u_int ptr)
162} 162}
163 163
164static int parse_afs_partitions(struct mtd_info *mtd, 164static int parse_afs_partitions(struct mtd_info *mtd,
165 struct mtd_partition **pparts, 165 struct mtd_partition **pparts,
166 unsigned long origin) 166 struct mtd_part_parser_data *data)
167{ 167{
168 struct mtd_partition *parts; 168 struct mtd_partition *parts;
169 u_int mask, off, idx, sz; 169 u_int mask, off, idx, sz;
diff --git a/drivers/mtd/ar7part.c b/drivers/mtd/ar7part.c
index 6697a1ec72d0..71bfa2efb3ea 100644
--- a/drivers/mtd/ar7part.c
+++ b/drivers/mtd/ar7part.c
@@ -46,7 +46,7 @@ struct ar7_bin_rec {
46 46
47static int create_mtd_partitions(struct mtd_info *master, 47static int create_mtd_partitions(struct mtd_info *master,
48 struct mtd_partition **pparts, 48 struct mtd_partition **pparts,
49 unsigned long origin) 49 struct mtd_part_parser_data *data)
50{ 50{
51 struct ar7_bin_rec header; 51 struct ar7_bin_rec header;
52 unsigned int offset; 52 unsigned int offset;
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index be0c121f2f1b..1b11f94695e9 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -313,8 +313,8 @@ static int mtdpart_setup_real(char *s)
313 * the first one in the chain if a NULL mtd_id is passed in. 313 * the first one in the chain if a NULL mtd_id is passed in.
314 */ 314 */
315static int parse_cmdline_partitions(struct mtd_info *master, 315static int parse_cmdline_partitions(struct mtd_info *master,
316 struct mtd_partition **pparts, 316 struct mtd_partition **pparts,
317 unsigned long origin) 317 struct mtd_part_parser_data *data)
318{ 318{
319 unsigned long offset; 319 unsigned long offset;
320 int i; 320 int i;
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 13267477e4e9..e18639980f7a 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -457,7 +457,7 @@ EXPORT_SYMBOL_GPL(mtd_device_register);
457 * @mtd: the MTD device to register 457 * @mtd: the MTD device to register
458 * @types: the list of MTD partition probes to try, see 458 * @types: the list of MTD partition probes to try, see
459 * 'parse_mtd_partitions()' for more information 459 * 'parse_mtd_partitions()' for more information
460 * @origin: start address of MTD device, %0 unless you are sure you need this. 460 * @parser_data: MTD partition parser-specific data
461 * @parts: fallback partition information to register, if parsing fails; 461 * @parts: fallback partition information to register, if parsing fails;
462 * only valid if %nr_parts > %0 462 * only valid if %nr_parts > %0
463 * @nr_parts: the number of partitions in parts, if zero then the full 463 * @nr_parts: the number of partitions in parts, if zero then the full
@@ -480,14 +480,14 @@ EXPORT_SYMBOL_GPL(mtd_device_register);
480 * Returns zero in case of success and a negative error code in case of failure. 480 * Returns zero in case of success and a negative error code in case of failure.
481 */ 481 */
482int mtd_device_parse_register(struct mtd_info *mtd, const char **types, 482int mtd_device_parse_register(struct mtd_info *mtd, const char **types,
483 unsigned long origin, 483 struct mtd_part_parser_data *parser_data,
484 const struct mtd_partition *parts, 484 const struct mtd_partition *parts,
485 int nr_parts) 485 int nr_parts)
486{ 486{
487 int err; 487 int err;
488 struct mtd_partition *real_parts; 488 struct mtd_partition *real_parts;
489 489
490 err = parse_mtd_partitions(mtd, types, &real_parts, origin); 490 err = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
491 if (err <= 0 && nr_parts) { 491 if (err <= 0 && nr_parts) {
492 real_parts = kmemdup(parts, sizeof(*parts) * nr_parts, 492 real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,
493 GFP_KERNEL); 493 GFP_KERNEL);
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 2b71ccb00d39..34d582c2bdf3 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -736,7 +736,7 @@ static const char *default_mtd_part_types[] = {"cmdlinepart", NULL};
736 * @master: the master partition (describes whole MTD device) 736 * @master: the master partition (describes whole MTD device)
737 * @types: names of partition parsers to try or %NULL 737 * @types: names of partition parsers to try or %NULL
738 * @pparts: array of partitions found is returned here 738 * @pparts: array of partitions found is returned here
739 * @origin: MTD device start address (use %0 if unsure) 739 * @data: MTD partition parser-specific data
740 * 740 *
741 * This function tries to find partition on MTD device @master. It uses MTD 741 * This function tries to find partition on MTD device @master. It uses MTD
742 * partition parsers, specified in @types. However, if @types is %NULL, then 742 * partition parsers, specified in @types. However, if @types is %NULL, then
@@ -750,7 +750,8 @@ static const char *default_mtd_part_types[] = {"cmdlinepart", NULL};
750 * point to an array containing this number of &struct mtd_info objects. 750 * point to an array containing this number of &struct mtd_info objects.
751 */ 751 */
752int parse_mtd_partitions(struct mtd_info *master, const char **types, 752int parse_mtd_partitions(struct mtd_info *master, const char **types,
753 struct mtd_partition **pparts, unsigned long origin) 753 struct mtd_partition **pparts,
754 struct mtd_part_parser_data *data)
754{ 755{
755 struct mtd_part_parser *parser; 756 struct mtd_part_parser *parser;
756 int ret = 0; 757 int ret = 0;
@@ -764,7 +765,7 @@ int parse_mtd_partitions(struct mtd_info *master, const char **types,
764 parser = get_partition_parser(*types); 765 parser = get_partition_parser(*types);
765 if (!parser) 766 if (!parser)
766 continue; 767 continue;
767 ret = (*parser->parse_fn)(master, pparts, origin); 768 ret = (*parser->parse_fn)(master, pparts, data);
768 if (ret > 0) { 769 if (ret > 0) {
769 printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n", 770 printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n",
770 ret, parser->name, master->name); 771 ret, parser->name, master->name);
diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c
index 7a87d07cd79f..56e48ea7ff05 100644
--- a/drivers/mtd/redboot.c
+++ b/drivers/mtd/redboot.c
@@ -56,8 +56,8 @@ static inline int redboot_checksum(struct fis_image_desc *img)
56} 56}
57 57
58static int parse_redboot_partitions(struct mtd_info *master, 58static int parse_redboot_partitions(struct mtd_info *master,
59 struct mtd_partition **pparts, 59 struct mtd_partition **pparts,
60 unsigned long fis_origin) 60 struct mtd_part_parser_data *data)
61{ 61{
62 int nrparts = 0; 62 int nrparts = 0;
63 struct fis_image_desc *buf; 63 struct fis_image_desc *buf;
@@ -197,11 +197,10 @@ static int parse_redboot_partitions(struct mtd_info *master,
197 goto out; 197 goto out;
198 } 198 }
199 new_fl->img = &buf[i]; 199 new_fl->img = &buf[i];
200 if (fis_origin) { 200 if (data && data->origin)
201 buf[i].flash_base -= fis_origin; 201 buf[i].flash_base -= data->origin;
202 } else { 202 else
203 buf[i].flash_base &= master->size-1; 203 buf[i].flash_base &= master->size-1;
204 }
205 204
206 /* I'm sure the JFFS2 code has done me permanent damage. 205 /* I'm sure the JFFS2 code has done me permanent damage.
207 * I now think the following is _normal_ 206 * I now think the following is _normal_
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index d28a241e7b55..b2b454b45cb5 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -323,13 +323,14 @@ static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd)
323 /* Kernel-side ioctl definitions */ 323 /* Kernel-side ioctl definitions */
324 324
325struct mtd_partition; 325struct mtd_partition;
326struct mtd_part_parser_data;
326 327
327extern int mtd_device_register(struct mtd_info *master, 328extern int mtd_device_register(struct mtd_info *master,
328 const struct mtd_partition *parts, 329 const struct mtd_partition *parts,
329 int nr_parts); 330 int nr_parts);
330extern int mtd_device_parse_register(struct mtd_info *mtd, 331extern int mtd_device_parse_register(struct mtd_info *mtd,
331 const char **part_probe_types, 332 const char **part_probe_types,
332 unsigned long origin, 333 struct mtd_part_parser_data *parser_data,
333 const struct mtd_partition *defparts, 334 const struct mtd_partition *defparts,
334 int defnr_parts); 335 int defnr_parts);
335extern int mtd_device_unregister(struct mtd_info *master); 336extern int mtd_device_unregister(struct mtd_info *master);
diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
index 1431cf2609ed..5fdb963a5035 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -52,6 +52,15 @@ struct mtd_partition {
52 52
53struct mtd_info; 53struct mtd_info;
54 54
55/**
56 * struct mtd_part_parser_data - used to pass data to MTD partition parsers.
57 * @origin: for RedBoot, start address of MTD device
58 */
59struct mtd_part_parser_data {
60 unsigned long origin;
61};
62
63
55/* 64/*
56 * Functions dealing with the various ways of partitioning the space 65 * Functions dealing with the various ways of partitioning the space
57 */ 66 */
@@ -60,13 +69,15 @@ struct mtd_part_parser {
60 struct list_head list; 69 struct list_head list;
61 struct module *owner; 70 struct module *owner;
62 const char *name; 71 const char *name;
63 int (*parse_fn)(struct mtd_info *, struct mtd_partition **, unsigned long); 72 int (*parse_fn)(struct mtd_info *, struct mtd_partition **,
73 struct mtd_part_parser_data *);
64}; 74};
65 75
66extern int register_mtd_parser(struct mtd_part_parser *parser); 76extern int register_mtd_parser(struct mtd_part_parser *parser);
67extern int deregister_mtd_parser(struct mtd_part_parser *parser); 77extern int deregister_mtd_parser(struct mtd_part_parser *parser);
68extern int parse_mtd_partitions(struct mtd_info *master, const char **types, 78extern int parse_mtd_partitions(struct mtd_info *master, const char **types,
69 struct mtd_partition **pparts, unsigned long origin); 79 struct mtd_partition **pparts,
80 struct mtd_part_parser_data *data);
70 81
71#define put_partition_parser(p) do { module_put((p)->owner); } while(0) 82#define put_partition_parser(p) do { module_put((p)->owner); } while(0)
72 83