Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com>
0004  * Copyright (C) 2011 Kees Cook <keescook@chromium.org>
0005  * Copyright (C) 2011 Google, Inc.
0006  */
0007 
0008 #ifndef __LINUX_PSTORE_RAM_H__
0009 #define __LINUX_PSTORE_RAM_H__
0010 
0011 #include <linux/compiler.h>
0012 #include <linux/device.h>
0013 #include <linux/init.h>
0014 #include <linux/kernel.h>
0015 #include <linux/list.h>
0016 #include <linux/pstore.h>
0017 #include <linux/types.h>
0018 
0019 /*
0020  * Choose whether access to the RAM zone requires locking or not.  If a zone
0021  * can be written to from different CPUs like with ftrace for example, then
0022  * PRZ_FLAG_NO_LOCK is used. For all other cases, locking is required.
0023  */
0024 #define PRZ_FLAG_NO_LOCK    BIT(0)
0025 /*
0026  * If a PRZ should only have a single-boot lifetime, this marks it as
0027  * getting wiped after its contents get copied out after boot.
0028  */
0029 #define PRZ_FLAG_ZAP_OLD    BIT(1)
0030 
0031 struct persistent_ram_buffer;
0032 struct rs_control;
0033 
0034 struct persistent_ram_ecc_info {
0035     int block_size;
0036     int ecc_size;
0037     int symsize;
0038     int poly;
0039     uint16_t *par;
0040 };
0041 
0042 /**
0043  * struct persistent_ram_zone - Details of a persistent RAM zone (PRZ)
0044  *                              used as a pstore backend
0045  *
0046  * @paddr:  physical address of the mapped RAM area
0047  * @size:   size of mapping
0048  * @label:  unique name of this PRZ
0049  * @type:   frontend type for this PRZ
0050  * @flags:  holds PRZ_FLAGS_* bits
0051  *
0052  * @buffer_lock:
0053  *  locks access to @buffer "size" bytes and "start" offset
0054  * @buffer:
0055  *  pointer to actual RAM area managed by this PRZ
0056  * @buffer_size:
0057  *  bytes in @buffer->data (not including any trailing ECC bytes)
0058  *
0059  * @par_buffer:
0060  *  pointer into @buffer->data containing ECC bytes for @buffer->data
0061  * @par_header:
0062  *  pointer into @buffer->data containing ECC bytes for @buffer header
0063  *  (i.e. all fields up to @data)
0064  * @rs_decoder:
0065  *  RSLIB instance for doing ECC calculations
0066  * @corrected_bytes:
0067  *  ECC corrected bytes accounting since boot
0068  * @bad_blocks:
0069  *  ECC uncorrectable bytes accounting since boot
0070  * @ecc_info:
0071  *  ECC configuration details
0072  *
0073  * @old_log:
0074  *  saved copy of @buffer->data prior to most recent wipe
0075  * @old_log_size:
0076  *  bytes contained in @old_log
0077  *
0078  */
0079 struct persistent_ram_zone {
0080     phys_addr_t paddr;
0081     size_t size;
0082     void *vaddr;
0083     char *label;
0084     enum pstore_type_id type;
0085     u32 flags;
0086 
0087     raw_spinlock_t buffer_lock;
0088     struct persistent_ram_buffer *buffer;
0089     size_t buffer_size;
0090 
0091     char *par_buffer;
0092     char *par_header;
0093     struct rs_control *rs_decoder;
0094     int corrected_bytes;
0095     int bad_blocks;
0096     struct persistent_ram_ecc_info ecc_info;
0097 
0098     char *old_log;
0099     size_t old_log_size;
0100 };
0101 
0102 struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
0103             u32 sig, struct persistent_ram_ecc_info *ecc_info,
0104             unsigned int memtype, u32 flags, char *label);
0105 void persistent_ram_free(struct persistent_ram_zone *prz);
0106 void persistent_ram_zap(struct persistent_ram_zone *prz);
0107 
0108 int persistent_ram_write(struct persistent_ram_zone *prz, const void *s,
0109              unsigned int count);
0110 int persistent_ram_write_user(struct persistent_ram_zone *prz,
0111                   const void __user *s, unsigned int count);
0112 
0113 void persistent_ram_save_old(struct persistent_ram_zone *prz);
0114 size_t persistent_ram_old_size(struct persistent_ram_zone *prz);
0115 void *persistent_ram_old(struct persistent_ram_zone *prz);
0116 void persistent_ram_free_old(struct persistent_ram_zone *prz);
0117 ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz,
0118     char *str, size_t len);
0119 
0120 /*
0121  * Ramoops platform data
0122  * @mem_size    memory size for ramoops
0123  * @mem_address physical memory address to contain ramoops
0124  */
0125 
0126 #define RAMOOPS_FLAG_FTRACE_PER_CPU BIT(0)
0127 
0128 struct ramoops_platform_data {
0129     unsigned long   mem_size;
0130     phys_addr_t mem_address;
0131     unsigned int    mem_type;
0132     unsigned long   record_size;
0133     unsigned long   console_size;
0134     unsigned long   ftrace_size;
0135     unsigned long   pmsg_size;
0136     int     max_reason;
0137     u32     flags;
0138     struct persistent_ram_ecc_info ecc_info;
0139 };
0140 
0141 #endif