Add hibernation image area
[AGL/meta-agl.git] / meta-agl-bsp / meta-renesas / recipes-bsp / u-boot / u-boot / hibernation / 0002-Enable-swsusp-DMA-support.patch
1 From 33dfe19185b35fc61613070032836beee0f48c45 Mon Sep 17 00:00:00 2001
2 From: Yuichi Kusakabe <yuichi.kusakabe@jp.fujitsu.com>
3 Date: Fri, 9 Jun 2017 20:45:39 +0900
4 Subject: [PATCH 2/3] Enable swsusp DMA support
5
6 Signed-off-by: Yuichi Kusakabe <yuichi.kusakabe@jp.fujitsu.com>
7 ---
8  common/cmd_swsusp.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
9  1 file changed, 58 insertions(+)
10
11 diff --git a/common/cmd_swsusp.c b/common/cmd_swsusp.c
12 index ba05aa4..b1d6c22 100644
13 --- a/common/cmd_swsusp.c
14 +++ b/common/cmd_swsusp.c
15 @@ -226,6 +226,53 @@ static inline void *malloc_aligned(u32 size, u32 align)
16         return (void *)(((u32)malloc(size + align) + align - 1) & ~(align - 1));
17  }
18  
19 +static int block_read(u32 page, void *addr, u32 count)
20 +{
21 +       __u32 cnt;
22 +       int blk_per_page;
23 +
24 +       blk_per_page = PAGE_SIZE / swap_dev->blksz;
25 +       cnt = swap_dev->block_read(swap_dev->dev,
26 +                               swap_info.start + (page * blk_per_page),
27 +                               count * blk_per_page, addr);
28 +
29 +       return cnt != count * blk_per_page;
30 +}
31 +
32 +static int get_block(unsigned char *buffer, u32 size)
33 +{
34 +       int need_num_pages = size / PAGE_SIZE;
35 +       int read_pages = 0;
36 +       int count;
37 +       u64 start;
38 +
39 +       do {
40 +               u64 prev;
41 +               count = 0;
42 +
43 +               if (!get_meta())
44 +                       goto exit;
45 +
46 +               prev = start = meta_map->entries[meta_idx];
47 +               do {
48 +                       count++;
49 +                       meta_idx++;
50 +                       if (meta_map->entries[meta_idx] - prev > 1)
51 +                               break;
52 +                       prev = meta_map->entries[meta_idx];
53 +               } while (read_pages + count < need_num_pages &&
54 +                       meta_idx < ARRAY_SIZE(meta_map->entries));
55 +
56 +               if (block_read(start, buffer, count))
57 +                       return -1;
58 +               read_pages += count;
59 +               buffer += count * PAGE_SIZE;
60 +       } while (read_pages < need_num_pages);
61 +
62 +exit:
63 +       return read_pages * PAGE_SIZE;
64 +}
65 +
66  #endif
67  
68  static int page_read(u32 page, void *addr)
69 @@ -465,12 +512,23 @@ static int image_page_get_next(void *buffer)
70                         cmp_len = *(size_t *) cmp_buf;
71                         cmp_avail = PAGE_SIZE;
72  
73 +#ifdef CONFIG_SH_DMA
74 +                       while (cmp_avail < cmp_len + LZO_HEADER) {
75 +                               /* try to DMA-read whole block */
76 +                               ret = get_block(cmp_buf + cmp_avail,
77 +                                               cmp_len + LZO_HEADER);
78 +                               if (unlikely(ret <= 0))
79 +                                       return ret;
80 +                               cmp_avail += ret;
81 +                       }
82 +#else
83                         while (cmp_avail < cmp_len + LZO_HEADER) {
84                                 ret = raw_page_get_next(cmp_buf + cmp_avail);
85                                 if (unlikely(ret <= 0))
86                                         return ret;
87                                 cmp_avail += PAGE_SIZE;
88                         }
89 +#endif
90                         unc_len = LZO_UNC_SIZE;
91                         ret = lzo1x_decompress_safe(cmp_buf + LZO_HEADER,
92                                                 cmp_len, unc_buf, &unc_len);
93 -- 
94 1.8.3.1
95