1/*
2 * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com>
3 * Copyright (C) 2011 Kees Cook <keescook@chromium.org>
4 * Copyright (C) 2011 Google, Inc.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#ifndef __LINUX_PSTORE_RAM_H__
18#define __LINUX_PSTORE_RAM_H__
19
20#include <linux/compiler.h>
21#include <linux/device.h>
22#include <linux/init.h>
23#include <linux/kernel.h>
24#include <linux/list.h>
25#include <linux/pstore.h>
26#include <linux/types.h>
27
28/*
29 * Choose whether access to the RAM zone requires locking or not. If a zone
30 * can be written to from different CPUs like with ftrace for example, then
31 * PRZ_FLAG_NO_LOCK is used. For all other cases, locking is required.
32 */
33#define PRZ_FLAG_NO_LOCK BIT(0)
34/*
35 * If a PRZ should only have a single-boot lifetime, this marks it as
36 * getting wiped after its contents get copied out after boot.
37 */
38#define PRZ_FLAG_ZAP_OLD BIT(1)
39
40struct persistent_ram_buffer;
41struct rs_control;
42
43struct persistent_ram_ecc_info {
44 int block_size;
45 int ecc_size;
46 int symsize;
47 int poly;
48 uint16_t *par;
49};
50
51/**
52 * struct persistent_ram_zone - Details of a persistent RAM zone (PRZ)
53 * used as a pstore backend
54 *
55 * @paddr: physical address of the mapped RAM area
56 * @size: size of mapping
57 * @label: unique name of this PRZ
58 * @type: frontend type for this PRZ
59 * @flags: holds PRZ_FLAGS_* bits
60 *
61 * @buffer_lock:
62 * locks access to @buffer "size" bytes and "start" offset
63 * @buffer:
64 * pointer to actual RAM area managed by this PRZ
65 * @buffer_size:
66 * bytes in @buffer->data (not including any trailing ECC bytes)
67 *
68 * @par_buffer:
69 * pointer into @buffer->data containing ECC bytes for @buffer->data
70 * @par_header:
71 * pointer into @buffer->data containing ECC bytes for @buffer header
72 * (i.e. all fields up to @data)
73 * @rs_decoder:
74 * RSLIB instance for doing ECC calculations
75 * @corrected_bytes:
76 * ECC corrected bytes accounting since boot
77 * @bad_blocks:
78 * ECC uncorrectable bytes accounting since boot
79 * @ecc_info:
80 * ECC configuration details
81 *
82 * @old_log:
83 * saved copy of @buffer->data prior to most recent wipe
84 * @old_log_size:
85 * bytes contained in @old_log
86 *
87 */
88struct persistent_ram_zone {
89 phys_addr_t paddr;
90 size_t size;
91 void *vaddr;
92 char *label;
93 enum pstore_type_id type;
94 u32 flags;
95
96 raw_spinlock_t buffer_lock;
97 struct persistent_ram_buffer *buffer;
98 size_t buffer_size;
99
100 char *par_buffer;
101 char *par_header;
102 struct rs_control *rs_decoder;
103 int corrected_bytes;
104 int bad_blocks;
105 struct persistent_ram_ecc_info ecc_info;
106
107 char *old_log;
108 size_t old_log_size;
109};
110
111struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
112 u32 sig, struct persistent_ram_ecc_info *ecc_info,
113 unsigned int memtype, u32 flags, char *label);
114void persistent_ram_free(struct persistent_ram_zone *prz);
115void persistent_ram_zap(struct persistent_ram_zone *prz);
116
117int persistent_ram_write(struct persistent_ram_zone *prz, const void *s,
118 unsigned int count);
119int persistent_ram_write_user(struct persistent_ram_zone *prz,
120 const void __user *s, unsigned int count);
121
122void persistent_ram_save_old(struct persistent_ram_zone *prz);
123size_t persistent_ram_old_size(struct persistent_ram_zone *prz);
124void *persistent_ram_old(struct persistent_ram_zone *prz);
125void persistent_ram_free_old(struct persistent_ram_zone *prz);
126ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz,
127 char *str, size_t len);
128
129/*
130 * Ramoops platform data
131 * @mem_size memory size for ramoops
132 * @mem_address physical memory address to contain ramoops
133 */
134
135#define RAMOOPS_FLAG_FTRACE_PER_CPU BIT(0)
136
137struct ramoops_platform_data {
138 unsigned long mem_size;
139 phys_addr_t mem_address;
140 unsigned int mem_type;
141 unsigned long record_size;
142 unsigned long console_size;
143 unsigned long ftrace_size;
144 unsigned long pmsg_size;
145 int dump_oops;
146 u32 flags;
147 struct persistent_ram_ecc_info ecc_info;
148};
149
150#endif
151