18bd4da0fSKees Cook /* SPDX-License-Identifier: GPL-2.0-only */ 28bd4da0fSKees Cook /* 38bd4da0fSKees Cook * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com> 48bd4da0fSKees Cook * Copyright (C) 2011 Kees Cook <keescook@chromium.org> 58bd4da0fSKees Cook * Copyright (C) 2011 Google, Inc. 68bd4da0fSKees Cook */ 78bd4da0fSKees Cook 88bd4da0fSKees Cook #include <linux/pstore_ram.h> 98bd4da0fSKees Cook 108bd4da0fSKees Cook /* 118bd4da0fSKees Cook * Choose whether access to the RAM zone requires locking or not. If a zone 128bd4da0fSKees Cook * can be written to from different CPUs like with ftrace for example, then 138bd4da0fSKees Cook * PRZ_FLAG_NO_LOCK is used. For all other cases, locking is required. 148bd4da0fSKees Cook */ 158bd4da0fSKees Cook #define PRZ_FLAG_NO_LOCK BIT(0) 168bd4da0fSKees Cook /* 178bd4da0fSKees Cook * If a PRZ should only have a single-boot lifetime, this marks it as 188bd4da0fSKees Cook * getting wiped after its contents get copied out after boot. 198bd4da0fSKees Cook */ 208bd4da0fSKees Cook #define PRZ_FLAG_ZAP_OLD BIT(1) 218bd4da0fSKees Cook 228bd4da0fSKees Cook /** 238bd4da0fSKees Cook * struct persistent_ram_zone - Details of a persistent RAM zone (PRZ) 248bd4da0fSKees Cook * used as a pstore backend 258bd4da0fSKees Cook * 268bd4da0fSKees Cook * @paddr: physical address of the mapped RAM area 278bd4da0fSKees Cook * @size: size of mapping 288bd4da0fSKees Cook * @label: unique name of this PRZ 298bd4da0fSKees Cook * @type: frontend type for this PRZ 308bd4da0fSKees Cook * @flags: holds PRZ_FLAGS_* bits 318bd4da0fSKees Cook * 328bd4da0fSKees Cook * @buffer_lock: 338bd4da0fSKees Cook * locks access to @buffer "size" bytes and "start" offset 348bd4da0fSKees Cook * @buffer: 358bd4da0fSKees Cook * pointer to actual RAM area managed by this PRZ 368bd4da0fSKees Cook * @buffer_size: 378bd4da0fSKees Cook * bytes in @buffer->data (not including any trailing ECC bytes) 388bd4da0fSKees Cook * 398bd4da0fSKees Cook * @par_buffer: 408bd4da0fSKees Cook * pointer into @buffer->data containing ECC bytes for @buffer->data 418bd4da0fSKees Cook * @par_header: 428bd4da0fSKees Cook * pointer into @buffer->data containing ECC bytes for @buffer header 438bd4da0fSKees Cook * (i.e. all fields up to @data) 448bd4da0fSKees Cook * @rs_decoder: 458bd4da0fSKees Cook * RSLIB instance for doing ECC calculations 468bd4da0fSKees Cook * @corrected_bytes: 478bd4da0fSKees Cook * ECC corrected bytes accounting since boot 488bd4da0fSKees Cook * @bad_blocks: 498bd4da0fSKees Cook * ECC uncorrectable bytes accounting since boot 508bd4da0fSKees Cook * @ecc_info: 518bd4da0fSKees Cook * ECC configuration details 528bd4da0fSKees Cook * 538bd4da0fSKees Cook * @old_log: 548bd4da0fSKees Cook * saved copy of @buffer->data prior to most recent wipe 558bd4da0fSKees Cook * @old_log_size: 568bd4da0fSKees Cook * bytes contained in @old_log 578bd4da0fSKees Cook * 588bd4da0fSKees Cook */ 598bd4da0fSKees Cook struct persistent_ram_zone { 608bd4da0fSKees Cook phys_addr_t paddr; 618bd4da0fSKees Cook size_t size; 628bd4da0fSKees Cook void *vaddr; 638bd4da0fSKees Cook char *label; 648bd4da0fSKees Cook enum pstore_type_id type; 658bd4da0fSKees Cook u32 flags; 668bd4da0fSKees Cook 678bd4da0fSKees Cook raw_spinlock_t buffer_lock; 688bd4da0fSKees Cook struct persistent_ram_buffer *buffer; 698bd4da0fSKees Cook size_t buffer_size; 708bd4da0fSKees Cook 718bd4da0fSKees Cook char *par_buffer; 728bd4da0fSKees Cook char *par_header; 738bd4da0fSKees Cook struct rs_control *rs_decoder; 748bd4da0fSKees Cook int corrected_bytes; 758bd4da0fSKees Cook int bad_blocks; 768bd4da0fSKees Cook struct persistent_ram_ecc_info ecc_info; 778bd4da0fSKees Cook 788bd4da0fSKees Cook char *old_log; 798bd4da0fSKees Cook size_t old_log_size; 808bd4da0fSKees Cook }; 818bd4da0fSKees Cook 828bd4da0fSKees Cook struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, 838bd4da0fSKees Cook u32 sig, struct persistent_ram_ecc_info *ecc_info, 848bd4da0fSKees Cook unsigned int memtype, u32 flags, char *label); 85*06b4e09aSKees Cook void persistent_ram_free(struct persistent_ram_zone **_prz); 868bd4da0fSKees Cook void persistent_ram_zap(struct persistent_ram_zone *prz); 878bd4da0fSKees Cook 888bd4da0fSKees Cook int persistent_ram_write(struct persistent_ram_zone *prz, const void *s, 898bd4da0fSKees Cook unsigned int count); 908bd4da0fSKees Cook int persistent_ram_write_user(struct persistent_ram_zone *prz, 918bd4da0fSKees Cook const void __user *s, unsigned int count); 928bd4da0fSKees Cook 938bd4da0fSKees Cook void persistent_ram_save_old(struct persistent_ram_zone *prz); 948bd4da0fSKees Cook size_t persistent_ram_old_size(struct persistent_ram_zone *prz); 958bd4da0fSKees Cook void *persistent_ram_old(struct persistent_ram_zone *prz); 968bd4da0fSKees Cook void persistent_ram_free_old(struct persistent_ram_zone *prz); 978bd4da0fSKees Cook ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz, 988bd4da0fSKees Cook char *str, size_t len); 99