Colin Cross | c672528 | 2012-03-07 17:34:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Google, Inc. |
| 3 | * |
| 4 | * This software is licensed under the terms of the GNU General Public |
| 5 | * License version 2, as published by the Free Software Foundation, and |
| 6 | * may be copied, distributed, and modified under those terms. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #ifndef __LINUX_PERSISTENT_RAM_H__ |
| 16 | #define __LINUX_PERSISTENT_RAM_H__ |
| 17 | |
Colin Cross | 404a604 | 2012-03-07 17:34:34 -0800 | [diff] [blame] | 18 | #include <linux/device.h> |
Colin Cross | c672528 | 2012-03-07 17:34:32 -0800 | [diff] [blame] | 19 | #include <linux/kernel.h> |
Colin Cross | 404a604 | 2012-03-07 17:34:34 -0800 | [diff] [blame] | 20 | #include <linux/list.h> |
Colin Cross | c672528 | 2012-03-07 17:34:32 -0800 | [diff] [blame] | 21 | #include <linux/types.h> |
| 22 | |
| 23 | struct persistent_ram_buffer; |
| 24 | |
Colin Cross | 404a604 | 2012-03-07 17:34:34 -0800 | [diff] [blame] | 25 | struct persistent_ram_descriptor { |
| 26 | const char *name; |
| 27 | phys_addr_t size; |
| 28 | }; |
| 29 | |
| 30 | struct persistent_ram { |
| 31 | phys_addr_t start; |
| 32 | phys_addr_t size; |
| 33 | |
Arve Hjønnevåg | 6411d57 | 2012-05-22 16:33:23 -0700 | [diff] [blame] | 34 | int ecc_block_size; |
| 35 | int ecc_size; |
| 36 | int ecc_symsize; |
| 37 | int ecc_poly; |
| 38 | |
Colin Cross | 404a604 | 2012-03-07 17:34:34 -0800 | [diff] [blame] | 39 | int num_descs; |
| 40 | struct persistent_ram_descriptor *descs; |
| 41 | |
| 42 | struct list_head node; |
| 43 | }; |
| 44 | |
Colin Cross | c672528 | 2012-03-07 17:34:32 -0800 | [diff] [blame] | 45 | struct persistent_ram_zone { |
| 46 | struct list_head node; |
Colin Cross | 404a604 | 2012-03-07 17:34:34 -0800 | [diff] [blame] | 47 | void *vaddr; |
Colin Cross | c672528 | 2012-03-07 17:34:32 -0800 | [diff] [blame] | 48 | struct persistent_ram_buffer *buffer; |
| 49 | size_t buffer_size; |
Colin Cross | 9cc05ad | 2012-03-07 17:34:33 -0800 | [diff] [blame] | 50 | |
| 51 | /* ECC correction */ |
| 52 | bool ecc; |
Colin Cross | c672528 | 2012-03-07 17:34:32 -0800 | [diff] [blame] | 53 | char *par_buffer; |
| 54 | char *par_header; |
| 55 | struct rs_control *rs_decoder; |
| 56 | int corrected_bytes; |
| 57 | int bad_blocks; |
Colin Cross | 9cc05ad | 2012-03-07 17:34:33 -0800 | [diff] [blame] | 58 | int ecc_block_size; |
| 59 | int ecc_size; |
| 60 | int ecc_symsize; |
| 61 | int ecc_poly; |
| 62 | |
Colin Cross | c672528 | 2012-03-07 17:34:32 -0800 | [diff] [blame] | 63 | char *old_log; |
| 64 | size_t old_log_size; |
| 65 | size_t old_log_footer_size; |
| 66 | bool early; |
| 67 | }; |
| 68 | |
Colin Cross | 404a604 | 2012-03-07 17:34:34 -0800 | [diff] [blame] | 69 | int persistent_ram_early_init(struct persistent_ram *ram); |
| 70 | |
| 71 | struct persistent_ram_zone *persistent_ram_init_ringbuffer(struct device *dev, |
| 72 | bool ecc); |
Colin Cross | c672528 | 2012-03-07 17:34:32 -0800 | [diff] [blame] | 73 | |
| 74 | int persistent_ram_write(struct persistent_ram_zone *prz, const void *s, |
| 75 | unsigned int count); |
| 76 | |
| 77 | size_t persistent_ram_old_size(struct persistent_ram_zone *prz); |
| 78 | void *persistent_ram_old(struct persistent_ram_zone *prz); |
| 79 | void persistent_ram_free_old(struct persistent_ram_zone *prz); |
| 80 | ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz, |
| 81 | char *str, size_t len); |
| 82 | |
| 83 | #endif |