This source file includes following definitions.
- s3c_pm_run_res
- s3c_pm_run_sysram
- s3c_pm_countram
- s3c_pm_check_prepare
- s3c_pm_makecheck
- s3c_pm_check_store
- in_region
- s3c_pm_runcheck
- s3c_pm_check_restore
- s3c_pm_check_cleanup
1
2
3
4
5
6
7
8
9
10
11 #include <linux/kernel.h>
12 #include <linux/suspend.h>
13 #include <linux/init.h>
14 #include <linux/crc32.h>
15 #include <linux/ioport.h>
16 #include <linux/slab.h>
17
18 #include <plat/pm-common.h>
19
20 #if CONFIG_SAMSUNG_PM_CHECK_CHUNKSIZE < 1
21 #error CONFIG_SAMSUNG_PM_CHECK_CHUNKSIZE must be a positive non-zero value
22 #endif
23
24
25
26
27
28
29
30
31
32
33
34 #define CHECK_CHUNKSIZE (CONFIG_SAMSUNG_PM_CHECK_CHUNKSIZE * 1024)
35
36 static u32 crc_size;
37 static u32 *crcs;
38
39 typedef u32 *(run_fn_t)(struct resource *ptr, u32 *arg);
40
41
42
43
44
45
46 static void s3c_pm_run_res(struct resource *ptr, run_fn_t fn, u32 *arg)
47 {
48 while (ptr != NULL) {
49 if (ptr->child != NULL)
50 s3c_pm_run_res(ptr->child, fn, arg);
51
52 if ((ptr->flags & IORESOURCE_SYSTEM_RAM)
53 == IORESOURCE_SYSTEM_RAM) {
54 S3C_PMDBG("Found system RAM at %08lx..%08lx\n",
55 (unsigned long)ptr->start,
56 (unsigned long)ptr->end);
57 arg = (fn)(ptr, arg);
58 }
59
60 ptr = ptr->sibling;
61 }
62 }
63
64 static void s3c_pm_run_sysram(run_fn_t fn, u32 *arg)
65 {
66 s3c_pm_run_res(&iomem_resource, fn, arg);
67 }
68
69 static u32 *s3c_pm_countram(struct resource *res, u32 *val)
70 {
71 u32 size = (u32)resource_size(res);
72
73 size += CHECK_CHUNKSIZE-1;
74 size /= CHECK_CHUNKSIZE;
75
76 S3C_PMDBG("Area %08lx..%08lx, %d blocks\n",
77 (unsigned long)res->start, (unsigned long)res->end, size);
78
79 *val += size * sizeof(u32);
80 return val;
81 }
82
83
84
85
86
87
88
89
90
91 void s3c_pm_check_prepare(void)
92 {
93 crc_size = 0;
94
95 s3c_pm_run_sysram(s3c_pm_countram, &crc_size);
96
97 S3C_PMDBG("s3c_pm_prepare_check: %u checks needed\n", crc_size);
98
99 crcs = kmalloc(crc_size+4, GFP_KERNEL);
100 if (crcs == NULL)
101 printk(KERN_ERR "Cannot allocated CRC save area\n");
102 }
103
104 static u32 *s3c_pm_makecheck(struct resource *res, u32 *val)
105 {
106 unsigned long addr, left;
107
108 for (addr = res->start; addr < res->end;
109 addr += CHECK_CHUNKSIZE) {
110 left = res->end - addr;
111
112 if (left > CHECK_CHUNKSIZE)
113 left = CHECK_CHUNKSIZE;
114
115 *val = crc32_le(~0, phys_to_virt(addr), left);
116 val++;
117 }
118
119 return val;
120 }
121
122
123
124
125
126
127
128 void s3c_pm_check_store(void)
129 {
130 if (crcs != NULL)
131 s3c_pm_run_sysram(s3c_pm_makecheck, crcs);
132 }
133
134
135
136
137
138
139
140 static inline int in_region(void *ptr, int size, void *what, size_t whatsz)
141 {
142 if ((what+whatsz) < ptr)
143 return 0;
144
145 if (what > (ptr+size))
146 return 0;
147
148 return 1;
149 }
150
151
152
153
154
155
156
157
158
159
160
161 static u32 *s3c_pm_runcheck(struct resource *res, u32 *val)
162 {
163 unsigned long addr;
164 unsigned long left;
165 void *stkpage;
166 void *ptr;
167 u32 calc;
168
169 stkpage = (void *)((u32)&calc & ~PAGE_MASK);
170
171 for (addr = res->start; addr < res->end;
172 addr += CHECK_CHUNKSIZE) {
173 left = res->end - addr;
174
175 if (left > CHECK_CHUNKSIZE)
176 left = CHECK_CHUNKSIZE;
177
178 ptr = phys_to_virt(addr);
179
180 if (in_region(ptr, left, stkpage, 4096)) {
181 S3C_PMDBG("skipping %08lx, has stack in\n", addr);
182 goto skip_check;
183 }
184
185 if (in_region(ptr, left, crcs, crc_size)) {
186 S3C_PMDBG("skipping %08lx, has crc block in\n", addr);
187 goto skip_check;
188 }
189
190
191
192 calc = crc32_le(~0, ptr, left);
193 if (calc != *val) {
194 printk(KERN_ERR "Restore CRC error at "
195 "%08lx (%08x vs %08x)\n", addr, calc, *val);
196
197 S3C_PMDBG("Restore CRC error at %08lx (%08x vs %08x)\n",
198 addr, calc, *val);
199 }
200
201 skip_check:
202 val++;
203 }
204
205 return val;
206 }
207
208
209
210
211
212
213
214 void s3c_pm_check_restore(void)
215 {
216 if (crcs != NULL)
217 s3c_pm_run_sysram(s3c_pm_runcheck, crcs);
218 }
219
220
221
222
223
224
225
226
227
228 void s3c_pm_check_cleanup(void)
229 {
230 kfree(crcs);
231 crcs = NULL;
232 }
233