kernel: add missing patch
[oweals/openwrt.git] / target / linux / generic / pending-4.9 / 404-mtd-add-more-helper-functions.patch
1 From: Gabor Juhos <juhosg@openwrt.org>
2 Subject: kernel/3.10: add separate rootfs partition parser
3
4 lede-commit: daec7ad7688415156e2730e401503d09bd3acf91
5 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
6 ---
7  drivers/mtd/mtdpart.c          | 29 +++++++++++++++++++++++++++++
8  include/linux/mtd/mtd.h        | 18 ++++++++++++++++++
9  include/linux/mtd/partitions.h |  2 ++
10  3 files changed, 49 insertions(+)
11
12 diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
13 index 28f76315dfa0..fce83882fd4e 100644
14 --- a/drivers/mtd/mtdpart.c
15 +++ b/drivers/mtd/mtdpart.c
16 @@ -791,6 +791,17 @@ run_parsers_by_type(struct mtd_part *slave, enum mtd_parser_type type)
17         return nr_parts;
18  }
19  
20 +static inline unsigned long
21 +mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
22 +{
23 +       unsigned long mask = mtd->erasesize - 1;
24 +
25 +       len += offset & mask;
26 +       len = (len + mask) & ~mask;
27 +       len -= offset & mask;
28 +       return len;
29 +}
30 +
31  #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
32  #define SPLIT_FIRMWARE_NAME    CONFIG_MTD_SPLIT_FIRMWARE_NAME
33  #else
34 @@ -1146,6 +1157,24 @@ int mtd_is_partition(const struct mtd_info *mtd)
35  }
36  EXPORT_SYMBOL_GPL(mtd_is_partition);
37  
38 +struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd)
39 +{
40 +       if (!mtd_is_partition(mtd))
41 +               return (struct mtd_info *)mtd;
42 +
43 +       return mtd_to_part(mtd)->parent;
44 +}
45 +EXPORT_SYMBOL_GPL(mtdpart_get_master);
46 +
47 +uint64_t mtdpart_get_offset(const struct mtd_info *mtd)
48 +{
49 +       if (!mtd_is_partition(mtd))
50 +               return 0;
51 +
52 +       return mtd_to_part(mtd)->offset;
53 +}
54 +EXPORT_SYMBOL_GPL(mtdpart_get_offset);
55 +
56  /* Returns the size of the entire flash chip */
57  uint64_t mtd_get_device_size(const struct mtd_info *mtd)
58  {
59 diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
60 index 5bb42c6dacdc..e7d5091bb447 100644
61 --- a/include/linux/mtd/mtd.h
62 +++ b/include/linux/mtd/mtd.h
63 @@ -485,6 +485,24 @@ static inline uint32_t mtd_mod_by_eb(uint64_t sz, struct mtd_info *mtd)
64         return do_div(sz, mtd->erasesize);
65  }
66  
67 +static inline uint64_t mtd_roundup_to_eb(uint64_t sz, struct mtd_info *mtd)
68 +{
69 +       if (mtd_mod_by_eb(sz, mtd) == 0)
70 +               return sz;
71 +
72 +       /* Round up to next erase block */
73 +       return (mtd_div_by_eb(sz, mtd) + 1) * mtd->erasesize;
74 +}
75 +
76 +static inline uint64_t mtd_rounddown_to_eb(uint64_t sz, struct mtd_info *mtd)
77 +{
78 +       if (mtd_mod_by_eb(sz, mtd) == 0)
79 +               return sz;
80 +
81 +       /* Round down to the start of the current erase block */
82 +       return (mtd_div_by_eb(sz, mtd)) * mtd->erasesize;
83 +}
84 +
85  static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
86  {
87         if (mtd->writesize_shift)
88 diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
89 index 356e29815aa2..c0937ff4797b 100644
90 --- a/include/linux/mtd/partitions.h
91 +++ b/include/linux/mtd/partitions.h
92 @@ -114,6 +114,8 @@ int mtd_is_partition(const struct mtd_info *mtd);
93  int mtd_add_partition(struct mtd_info *master, const char *name,
94                       long long offset, long long length);
95  int mtd_del_partition(struct mtd_info *master, int partno);
96 +struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd);
97 +uint64_t mtdpart_get_offset(const struct mtd_info *mtd);
98  uint64_t mtd_get_device_size(const struct mtd_info *mtd);
99  extern void __weak arch_split_mtd_part(struct mtd_info *master,
100                                        const char *name, int offset, int size);
101 -- 
102 2.11.0
103