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
6 Signed-off-by: Yuichi Kusakabe <yuichi.kusakabe@jp.fujitsu.com>
8 common/cmd_swsusp.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
9 1 file changed, 58 insertions(+)
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));
19 +static int block_read(u32 page, void *addr, u32 count)
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);
29 + return cnt != count * blk_per_page;
32 +static int get_block(unsigned char *buffer, u32 size)
34 + int need_num_pages = size / PAGE_SIZE;
46 + prev = start = meta_map->entries[meta_idx];
50 + if (meta_map->entries[meta_idx] - prev > 1)
52 + prev = meta_map->entries[meta_idx];
53 + } while (read_pages + count < need_num_pages &&
54 + meta_idx < ARRAY_SIZE(meta_map->entries));
56 + if (block_read(start, buffer, count))
58 + read_pages += count;
59 + buffer += count * PAGE_SIZE;
60 + } while (read_pages < need_num_pages);
63 + return read_pages * PAGE_SIZE;
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;
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))
83 while (cmp_avail < cmp_len + LZO_HEADER) {
84 ret = raw_page_get_next(cmp_buf + cmp_avail);
85 if (unlikely(ret <= 0))
87 cmp_avail += PAGE_SIZE;
90 unc_len = LZO_UNC_SIZE;
91 ret = lzo1x_decompress_safe(cmp_buf + LZO_HEADER,
92 cmp_len, unc_buf, &unc_len);