15 #include <linux/device.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
21 #include <linux/list.h>
24 #include <linux/slab.h>
36 #define PERSISTENT_RAM_SIG (0x43474244)
88 memset(par, 0,
sizeof(par));
89 encode_rs8(prz->
rs_decoder, data, len, par, 0);
95 void *data,
size_t len,
uint8_t *ecc)
102 return decode_rs8(prz->
rs_decoder, data, par, len,
120 block = buffer->
data + (start & ~(ecc_block_size - 1));
124 if (block + ecc_block_size > buffer_end)
125 size = buffer_end -
block;
126 persistent_ram_encode_rs8(prz, block, size, par);
127 block += ecc_block_size;
139 persistent_ram_encode_rs8(prz, (
uint8_t *)buffer,
sizeof(*buffer),
152 block = buffer->
data;
159 numerr = persistent_ram_decode_rs8(prz, block, size, par);
161 pr_devel(
"persistent_ram: error in block %p, %d\n",
164 }
else if (numerr < 0) {
165 pr_devel(
"persistent_ram: uncorrectable error in block %p\n",
182 int ecc_poly = 0x11d;
191 ecc_total = (ecc_blocks + 1) * prz->
ecc_size;
193 pr_err(
"%s: invalid ecc_size %u (total %zu, buffer size %zu)\n",
208 pr_info(
"persistent_ram: init_rs failed\n");
215 numerr = persistent_ram_decode_rs8(prz, buffer,
sizeof(*buffer),
218 pr_info(
"persistent_ram: error in header, %d\n", numerr);
220 }
else if (numerr < 0) {
221 pr_info(
"persistent_ram: uncorrectable error in header\n");
229 char *
str,
size_t len)
235 "\n%d Corrected bytes, %d unrecoverable blocks\n",
238 ret =
snprintf(str, len,
"\nNo errors detected\n");
244 const void *
s,
unsigned int start,
unsigned int count)
248 persistent_ram_update_ecc(prz, start, count);
255 size_t start = buffer_start(prz);
261 persistent_ram_ecc_old(prz);
265 pr_err(
"persistent_ram: failed to allocate buffer\n");
275 const void *
s,
unsigned int count)
286 buffer_size_add(prz, c);
288 start = buffer_start_add(prz, c);
292 persistent_ram_update(prz, s, start, rem);
297 persistent_ram_update(prz, s, start, c);
299 persistent_ram_update_header_ecc(prz);
325 persistent_ram_update_header_ecc(prz);
328 static void *persistent_ram_vmap(
phys_addr_t start,
size_t size)
332 unsigned int page_count;
344 pr_err(
"%s: Failed to allocate array for %u pages\n", __func__,
349 for (i = 0; i < page_count; i++) {
353 vaddr =
vmap(pages, page_count,
VM_MAP, prot);
359 static void *persistent_ram_iomap(
phys_addr_t start,
size_t size)
362 pr_err(
"request mem region (0x%llx@0x%llx) failed\n",
363 (
unsigned long long)size, (
unsigned long long)start);
377 prz->
vaddr = persistent_ram_vmap(start, size);
379 prz->
vaddr = persistent_ram_iomap(start, size);
382 pr_err(
"%s: Failed to map 0x%llx pages at 0x%llx\n", __func__,
383 (
unsigned long long)size, (
unsigned long long)start);
398 ret = persistent_ram_init_ecc(prz, ecc_size);
404 if (prz->
buffer->sig == sig) {
407 pr_info(
"persistent_ram: found existing invalid buffer,"
408 " size %zu, start %zu\n",
411 pr_debug(
"persistent_ram: found existing buffer,"
412 " size %zu, start %zu\n",
418 pr_debug(
"persistent_ram: no valid data in buffer"
419 " (sig = 0x%08x)\n", prz->
buffer->sig);
447 size_t size,
u32 sig,
455 pr_err(
"persistent_ram: failed to allocate persistent ram zone\n");
459 ret = persistent_ram_buffer_map(start, size, prz);
463 ret = persistent_ram_post_init(prz, sig, ecc_size);