hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/fs/pstore/ram.c
....@@ -1,23 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * RAM Oops/Panic logger
34 *
45 * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com>
56 * Copyright (C) 2011 Kees Cook <keescook@chromium.org>
6
- *
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License
9
- * version 2 as published by the Free Software Foundation.
10
- *
11
- * This program is distributed in the hope that it will be useful, but
12
- * WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- * General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19
- * 02110-1301 USA
20
- *
217 */
228
239 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -35,6 +21,12 @@
3521 #include <linux/pstore_ram.h>
3622 #include <linux/of.h>
3723 #include <linux/of_address.h>
24
+#include <linux/of_reserved_mem.h>
25
+#include "internal.h"
26
+
27
+#if IS_REACHABLE(CONFIG_ROCKCHIP_MINIDUMP)
28
+#include <soc/rockchip/rk_minidump.h>
29
+#endif
3830
3931 #define RAMOOPS_KERNMSG_HDR "===="
4032 #define MIN_MEM_SIZE 4096UL
....@@ -67,24 +59,63 @@
6759 "size of reserved RAM used to store oops/panic logs");
6860
6961 static unsigned int mem_type;
70
-module_param(mem_type, uint, 0600);
62
+module_param(mem_type, uint, 0400);
7163 MODULE_PARM_DESC(mem_type,
72
- "set to 1 to try to use unbuffered memory (default 0)");
64
+ "memory type: 0=write-combined (default), 1=unbuffered, 2=cached");
7365
74
-static int dump_oops = 1;
75
-module_param(dump_oops, int, 0600);
76
-MODULE_PARM_DESC(dump_oops,
77
- "set to 1 to dump oopses, 0 to only dump panics (default 1)");
66
+static int ramoops_max_reason = -1;
67
+module_param_named(max_reason, ramoops_max_reason, int, 0400);
68
+MODULE_PARM_DESC(max_reason,
69
+ "maximum reason for kmsg dump (default 2: Oops and Panic) ");
7870
7971 static int ramoops_ecc;
80
-module_param_named(ecc, ramoops_ecc, int, 0600);
72
+module_param_named(ecc, ramoops_ecc, int, 0400);
8173 MODULE_PARM_DESC(ramoops_ecc,
8274 "if non-zero, the option enables ECC support and specifies "
8375 "ECC buffer size in bytes (1 is a special value, means 16 "
8476 "bytes ECC)");
8577
78
+static int ramoops_dump_oops = -1;
79
+module_param_named(dump_oops, ramoops_dump_oops, int, 0400);
80
+MODULE_PARM_DESC(dump_oops,
81
+ "(deprecated: use max_reason instead) set to 1 to dump oopses & panics, 0 to only dump panics");
82
+
83
+struct ramoops_context {
84
+ struct persistent_ram_zone **dprzs; /* Oops dump zones */
85
+ struct persistent_ram_zone *cprz; /* Console zone */
86
+ struct persistent_ram_zone **fprzs; /* Ftrace zones */
87
+ struct persistent_ram_zone *mprz; /* PMSG zone */
88
+#ifdef CONFIG_PSTORE_BOOT_LOG
89
+ struct persistent_ram_zone **boot_przs; /* BOOT log zones */
90
+#endif
91
+ phys_addr_t phys_addr;
92
+ unsigned long size;
93
+ unsigned int memtype;
94
+ size_t record_size;
95
+ size_t console_size;
96
+ size_t ftrace_size;
97
+ size_t pmsg_size;
98
+#ifdef CONFIG_PSTORE_BOOT_LOG
99
+ size_t boot_log_size;
100
+#endif
101
+ u32 flags;
102
+ struct persistent_ram_ecc_info ecc_info;
103
+ unsigned int max_dump_cnt;
104
+ unsigned int dump_write_cnt;
105
+ /* _read_cnt need clear on ramoops_pstore_open */
106
+ unsigned int dump_read_cnt;
107
+ unsigned int console_read_cnt;
108
+ unsigned int max_ftrace_cnt;
109
+ unsigned int ftrace_read_cnt;
110
+ unsigned int pmsg_read_cnt;
111
+#ifdef CONFIG_PSTORE_BOOT_LOG
112
+ unsigned int boot_log_read_cnt;
113
+ unsigned int max_boot_log_cnt;
114
+#endif
115
+ struct pstore_info pstore;
116
+};
117
+
86118 static struct platform_device *dummy;
87
-static struct ramoops_platform_data *dummy_data;
88119
89120 static int ramoops_pstore_open(struct pstore_info *psi)
90121 {
....@@ -98,31 +129,28 @@
98129 }
99130
100131 static struct persistent_ram_zone *
101
-ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,
102
- u64 *id,
103
- enum pstore_type_id *typep, enum pstore_type_id type,
104
- bool update)
132
+ramoops_get_next_prz(struct persistent_ram_zone *przs[], int id,
133
+ struct pstore_record *record)
105134 {
106135 struct persistent_ram_zone *prz;
107
- int i = (*c)++;
108136
109137 /* Give up if we never existed or have hit the end. */
110
- if (!przs || i >= max)
138
+ if (!przs)
111139 return NULL;
112140
113
- prz = przs[i];
141
+ prz = przs[id];
114142 if (!prz)
115143 return NULL;
116144
117145 /* Update old/shadowed buffer. */
118
- if (update)
146
+ if (prz->type == PSTORE_TYPE_DMESG)
119147 persistent_ram_save_old(prz);
120148
121149 if (!persistent_ram_old_size(prz))
122150 return NULL;
123151
124
- *typep = type;
125
- *id = i;
152
+ record->type = prz->type;
153
+ record->id = id;
126154
127155 return prz;
128156 }
....@@ -160,57 +188,27 @@
160188 persistent_ram_ecc_string(prz, NULL, 0));
161189 }
162190
163
-static ssize_t ftrace_log_combine(struct persistent_ram_zone *dest,
164
- struct persistent_ram_zone *src)
191
+#ifdef CONFIG_PSTORE_BOOT_LOG
192
+ssize_t ramoops_pstore_read_for_boot_log(struct pstore_record *record)
165193 {
166
- size_t dest_size, src_size, total, dest_off, src_off;
167
- size_t dest_idx = 0, src_idx = 0, merged_idx = 0;
168
- void *merged_buf;
169
- struct pstore_ftrace_record *drec, *srec, *mrec;
170
- size_t record_size = sizeof(struct pstore_ftrace_record);
194
+ struct ramoops_context *cxt = record->psi->data;
195
+ struct persistent_ram_zone *prz;
171196
172
- dest_off = dest->old_log_size % record_size;
173
- dest_size = dest->old_log_size - dest_off;
197
+ if (!cxt)
198
+ return 0;
174199
175
- src_off = src->old_log_size % record_size;
176
- src_size = src->old_log_size - src_off;
200
+ prz = cxt->boot_przs[record->id];
177201
178
- total = dest_size + src_size;
179
- merged_buf = kmalloc(total, GFP_KERNEL);
180
- if (!merged_buf)
181
- return -ENOMEM;
202
+ if (!prz)
203
+ return 0;
182204
183
- drec = (struct pstore_ftrace_record *)(dest->old_log + dest_off);
184
- srec = (struct pstore_ftrace_record *)(src->old_log + src_off);
185
- mrec = (struct pstore_ftrace_record *)(merged_buf);
186
-
187
- while (dest_size > 0 && src_size > 0) {
188
- if (pstore_ftrace_read_timestamp(&drec[dest_idx]) <
189
- pstore_ftrace_read_timestamp(&srec[src_idx])) {
190
- mrec[merged_idx++] = drec[dest_idx++];
191
- dest_size -= record_size;
192
- } else {
193
- mrec[merged_idx++] = srec[src_idx++];
194
- src_size -= record_size;
195
- }
196
- }
197
-
198
- while (dest_size > 0) {
199
- mrec[merged_idx++] = drec[dest_idx++];
200
- dest_size -= record_size;
201
- }
202
-
203
- while (src_size > 0) {
204
- mrec[merged_idx++] = srec[src_idx++];
205
- src_size -= record_size;
206
- }
207
-
208
- kfree(dest->old_log);
209
- dest->old_log = merged_buf;
210
- dest->old_log_size = total;
211
-
212
- return 0;
205
+ persistent_ram_free_old(prz);
206
+ persistent_ram_save_old(prz);
207
+ record->buf = prz->old_log;
208
+ record->size = prz->old_log_size;
209
+ return record->size;
213210 }
211
+#endif
214212
215213 static ssize_t ramoops_pstore_read(struct pstore_record *record)
216214 {
....@@ -231,10 +229,8 @@
231229
232230 /* Find the next valid persistent_ram_zone for DMESG */
233231 while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) {
234
- prz = ramoops_get_next_prz(cxt->dprzs, &cxt->dump_read_cnt,
235
- cxt->max_dump_cnt, &record->id,
236
- &record->type,
237
- PSTORE_TYPE_DMESG, 1);
232
+ prz = ramoops_get_next_prz(cxt->dprzs, cxt->dump_read_cnt++,
233
+ record);
238234 if (!prz_ok(prz))
239235 continue;
240236 header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz),
....@@ -248,22 +244,18 @@
248244 }
249245 }
250246
251
- if (!prz_ok(prz))
252
- prz = ramoops_get_next_prz(&cxt->cprz, &cxt->console_read_cnt,
253
- 1, &record->id, &record->type,
254
- PSTORE_TYPE_CONSOLE, 0);
247
+ if (!prz_ok(prz) && !cxt->console_read_cnt++)
248
+ prz = ramoops_get_next_prz(&cxt->cprz, 0 /* single */, record);
255249
256
- if (!prz_ok(prz))
257
- prz = ramoops_get_next_prz(&cxt->mprz, &cxt->pmsg_read_cnt,
258
- 1, &record->id, &record->type,
259
- PSTORE_TYPE_PMSG, 0);
250
+ if (!prz_ok(prz) && !cxt->pmsg_read_cnt++)
251
+ prz = ramoops_get_next_prz(&cxt->mprz, 0 /* single */, record);
260252
261253 /* ftrace is last since it may want to dynamically allocate memory. */
262254 if (!prz_ok(prz)) {
263
- if (!(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU)) {
264
- prz = ramoops_get_next_prz(cxt->fprzs,
265
- &cxt->ftrace_read_cnt, 1, &record->id,
266
- &record->type, PSTORE_TYPE_FTRACE, 0);
255
+ if (!(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU) &&
256
+ !cxt->ftrace_read_cnt++) {
257
+ prz = ramoops_get_next_prz(cxt->fprzs, 0 /* single */,
258
+ record);
267259 } else {
268260 /*
269261 * Build a new dummy record which combines all the
....@@ -280,11 +272,7 @@
280272
281273 while (cxt->ftrace_read_cnt < cxt->max_ftrace_cnt) {
282274 prz_next = ramoops_get_next_prz(cxt->fprzs,
283
- &cxt->ftrace_read_cnt,
284
- cxt->max_ftrace_cnt,
285
- &record->id,
286
- &record->type,
287
- PSTORE_TYPE_FTRACE, 0);
275
+ cxt->ftrace_read_cnt++, record);
288276
289277 if (!prz_ok(prz_next))
290278 continue;
....@@ -293,7 +281,12 @@
293281 tmp_prz->corrected_bytes +=
294282 prz_next->corrected_bytes;
295283 tmp_prz->bad_blocks += prz_next->bad_blocks;
296
- size = ftrace_log_combine(tmp_prz, prz_next);
284
+
285
+ size = pstore_ftrace_combine_log(
286
+ &tmp_prz->old_log,
287
+ &tmp_prz->old_log_size,
288
+ prz_next->old_log,
289
+ prz_next->old_log_size);
297290 if (size)
298291 goto out;
299292 }
....@@ -304,10 +297,7 @@
304297 #ifdef CONFIG_PSTORE_BOOT_LOG
305298 if (!prz_ok(prz)) {
306299 while (cxt->boot_log_read_cnt < cxt->max_boot_log_cnt && !prz) {
307
- prz = ramoops_get_next_prz(cxt->boot_przs, &cxt->boot_log_read_cnt,
308
- cxt->max_boot_log_cnt, &record->id,
309
- &record->type,
310
- PSTORE_TYPE_BOOT_LOG, 0);
300
+ prz = ramoops_get_next_prz(cxt->boot_przs, cxt->boot_log_read_cnt++, record);
311301 if (!prz_ok(prz))
312302 continue;
313303 }
....@@ -319,12 +309,15 @@
319309 goto out;
320310 }
321311
322
- size = persistent_ram_old_size(prz) - header_length;
323312 #ifdef CONFIG_PSTORE_BOOT_LOG
324
- /* don't copy boot log */
325
- if (record->type == PSTORE_TYPE_BOOT_LOG)
326
- goto out;
313
+ if (record->type == PSTORE_TYPE_BOOT_LOG) {
314
+ persistent_ram_free_old(prz);
315
+ persistent_ram_save_old(prz);
316
+ }
327317 #endif
318
+
319
+ size = persistent_ram_old_size(prz) - header_length;
320
+
328321 /* ECC correction notice */
329322 record->ecc_notice_size = persistent_ram_ecc_string(prz, NULL, 0);
330323
....@@ -352,17 +345,15 @@
352345 static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
353346 struct pstore_record *record)
354347 {
355
- char *hdr;
348
+ char hdr[36]; /* "===="(4), %lld(20), "."(1), %06lu(6), "-%c\n"(3) */
356349 size_t len;
357350
358
- hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lld.%06lu-%c\n",
351
+ len = scnprintf(hdr, sizeof(hdr),
352
+ RAMOOPS_KERNMSG_HDR "%lld.%06lu-%c\n",
359353 (time64_t)record->time.tv_sec,
360354 record->time.tv_nsec / 1000,
361355 record->compressed ? 'C' : 'D');
362
- WARN_ON_ONCE(!hdr);
363
- len = hdr ? strlen(hdr) : 0;
364356 persistent_ram_write(prz, hdr, len);
365
- kfree(hdr);
366357
367358 return len;
368359 }
....@@ -403,16 +394,14 @@
403394 return -EINVAL;
404395
405396 /*
406
- * Out of the various dmesg dump types, ramoops is currently designed
407
- * to only store crash logs, rather than storing general kernel logs.
397
+ * We could filter on record->reason here if we wanted to (which
398
+ * would duplicate what happened before the "max_reason" setting
399
+ * was added), but that would defeat the purpose of a system
400
+ * changing printk.always_kmsg_dump, so instead log everything that
401
+ * the kmsg dumper sends us, since it should be doing the filtering
402
+ * based on the combination of printk.always_kmsg_dump and our
403
+ * requested "max_reason".
408404 */
409
- if (record->reason != KMSG_DUMP_OOPS &&
410
- record->reason != KMSG_DUMP_PANIC)
411
- return -EINVAL;
412
-
413
- /* Skip Oopes when configured to do so. */
414
- if (record->reason == KMSG_DUMP_OOPS && !cxt->dump_oops)
415
- return -EINVAL;
416405
417406 /*
418407 * Explicitly only take the first part of any new crash.
....@@ -441,6 +430,9 @@
441430
442431 /* Build header and append record contents. */
443432 hlen = ramoops_write_kmsg_hdr(prz, record);
433
+ if (!hlen)
434
+ return -ENOMEM;
435
+
444436 size = record->size;
445437 if (size + hlen > prz->buffer_size)
446438 size = prz->buffer_size - hlen;
....@@ -600,9 +592,17 @@
600592 goto fail;
601593
602594 for (i = 0; i < *cnt; i++) {
595
+ char *label;
596
+
597
+ if (*cnt == 1)
598
+ label = kasprintf(GFP_KERNEL, "ramoops:%s", name);
599
+ else
600
+ label = kasprintf(GFP_KERNEL, "ramoops:%s(%d/%d)",
601
+ name, i, *cnt - 1);
603602 prz_ar[i] = persistent_ram_new(*paddr, zone_sz, sig,
604
- &cxt->ecc_info,
605
- cxt->memtype, flags);
603
+ &cxt->ecc_info,
604
+ cxt->memtype, flags, label);
605
+ kfree(label);
606606 if (IS_ERR(prz_ar[i])) {
607607 err = PTR_ERR(prz_ar[i]);
608608 dev_err(dev, "failed to request %s mem region (0x%zx@0x%llx): %d\n",
....@@ -617,6 +617,7 @@
617617 goto fail;
618618 }
619619 *paddr += zone_sz;
620
+ prz_ar[i]->type = pstore_name_to_type(name);
620621 }
621622
622623 *przs = prz_ar;
....@@ -632,6 +633,8 @@
632633 struct persistent_ram_zone **prz,
633634 phys_addr_t *paddr, size_t sz, u32 sig)
634635 {
636
+ char *label;
637
+
635638 if (!sz)
636639 return 0;
637640
....@@ -642,8 +645,10 @@
642645 return -ENOMEM;
643646 }
644647
648
+ label = kasprintf(GFP_KERNEL, "ramoops:%s", name);
645649 *prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info,
646
- cxt->memtype, 0);
650
+ cxt->memtype, PRZ_FLAG_ZAP_OLD, label);
651
+ kfree(label);
647652 if (IS_ERR(*prz)) {
648653 int err = PTR_ERR(*prz);
649654
....@@ -652,26 +657,31 @@
652657 return err;
653658 }
654659
655
- persistent_ram_zap(*prz);
656
-
657660 *paddr += sz;
661
+ (*prz)->type = pstore_name_to_type(name);
658662
659663 return 0;
660664 }
661665
662
-static int ramoops_parse_dt_size(struct platform_device *pdev,
663
- const char *propname, u32 *value)
666
+/* Read a u32 from a dt property and make sure it's safe for an int. */
667
+static int ramoops_parse_dt_u32(struct platform_device *pdev,
668
+ const char *propname,
669
+ u32 default_value, u32 *value)
664670 {
665671 u32 val32 = 0;
666672 int ret;
667673
668674 ret = of_property_read_u32(pdev->dev.of_node, propname, &val32);
669
- if (ret < 0 && ret != -EINVAL) {
675
+ if (ret == -EINVAL) {
676
+ /* field is missing, use default value. */
677
+ val32 = default_value;
678
+ } else if (ret < 0) {
670679 dev_err(&pdev->dev, "failed to parse property %s: %d\n",
671680 propname, ret);
672681 return ret;
673682 }
674683
684
+ /* Sanity check our results. */
675685 if (val32 > INT_MAX) {
676686 dev_err(&pdev->dev, "%s %u > INT_MAX\n", propname, val32);
677687 return -EOVERFLOW;
....@@ -685,6 +695,8 @@
685695 struct ramoops_platform_data *pdata)
686696 {
687697 struct device_node *of_node = pdev->dev.of_node;
698
+ struct device_node *parent_node;
699
+ struct reserved_mem *rmem;
688700 struct resource *res;
689701 u32 value;
690702 int ret;
....@@ -693,37 +705,124 @@
693705
694706 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
695707 if (!res) {
696
- dev_err(&pdev->dev,
697
- "failed to locate DT /reserved-memory resource\n");
698
- return -EINVAL;
708
+ rmem = of_reserved_mem_lookup(of_node);
709
+ if (rmem) {
710
+ pdata->mem_size = rmem->size;
711
+ pdata->mem_address = rmem->base;
712
+ } else {
713
+ dev_err(&pdev->dev,
714
+ "failed to locate DT /reserved-memory resource\n");
715
+ return -EINVAL;
716
+ }
717
+ } else {
718
+ pdata->mem_size = resource_size(res);
719
+ pdata->mem_address = res->start;
699720 }
700721
701
- pdata->mem_size = resource_size(res);
702
- pdata->mem_address = res->start;
722
+ /*
723
+ * Setting "unbuffered" is deprecated and will be ignored if
724
+ * "mem_type" is also specified.
725
+ */
703726 pdata->mem_type = of_property_read_bool(of_node, "unbuffered");
704
- pdata->dump_oops = !of_property_read_bool(of_node, "no-dump-oops");
727
+ /*
728
+ * Setting "no-dump-oops" is deprecated and will be ignored if
729
+ * "max_reason" is also specified.
730
+ */
731
+ if (of_property_read_bool(of_node, "no-dump-oops"))
732
+ pdata->max_reason = KMSG_DUMP_PANIC;
733
+ else
734
+ pdata->max_reason = KMSG_DUMP_OOPS;
705735
706
-#define parse_size(name, field) { \
707
- ret = ramoops_parse_dt_size(pdev, name, &value); \
736
+#define parse_u32(name, field, default_value) { \
737
+ ret = ramoops_parse_dt_u32(pdev, name, default_value, \
738
+ &value); \
708739 if (ret < 0) \
709740 return ret; \
710741 field = value; \
711742 }
712743
713
- parse_size("record-size", pdata->record_size);
714
- parse_size("console-size", pdata->console_size);
715
- parse_size("ftrace-size", pdata->ftrace_size);
716
- parse_size("pmsg-size", pdata->pmsg_size);
717
- parse_size("ecc-size", pdata->ecc_info.ecc_size);
718
- parse_size("flags", pdata->flags);
744
+ parse_u32("mem-type", pdata->mem_type, pdata->mem_type);
745
+ parse_u32("record-size", pdata->record_size, 0);
746
+ parse_u32("console-size", pdata->console_size, 0);
747
+ parse_u32("ftrace-size", pdata->ftrace_size, 0);
748
+ parse_u32("pmsg-size", pdata->pmsg_size, 0);
749
+ parse_u32("ecc-size", pdata->ecc_info.ecc_size, 0);
750
+ parse_u32("flags", pdata->flags, 0);
751
+ parse_u32("max-reason", pdata->max_reason, pdata->max_reason);
719752 #ifdef CONFIG_PSTORE_BOOT_LOG
720
- parse_size("boot-log-size", pdata->boot_log_size);
721
- parse_size("boot-log-count", pdata->max_boot_log_cnt);
753
+ parse_u32("boot-log-size", pdata->boot_log_size, 0);
754
+ parse_u32("boot-log-count", pdata->max_boot_log_cnt, 0);
722755 #endif
723
-#undef parse_size
756
+
757
+#undef parse_u32
758
+
759
+ /*
760
+ * Some old Chromebooks relied on the kernel setting the
761
+ * console_size and pmsg_size to the record size since that's
762
+ * what the downstream kernel did. These same Chromebooks had
763
+ * "ramoops" straight under the root node which isn't
764
+ * according to the current upstream bindings (though it was
765
+ * arguably acceptable under a prior version of the bindings).
766
+ * Let's make those old Chromebooks work by detecting that
767
+ * we're not a child of "reserved-memory" and mimicking the
768
+ * expected behavior.
769
+ */
770
+ parent_node = of_get_parent(of_node);
771
+ if (!of_node_name_eq(parent_node, "reserved-memory") &&
772
+ !pdata->console_size && !pdata->ftrace_size &&
773
+ !pdata->pmsg_size && !pdata->ecc_info.ecc_size) {
774
+ pdata->console_size = pdata->record_size;
775
+ pdata->pmsg_size = pdata->record_size;
776
+ }
777
+ of_node_put(parent_node);
724778
725779 return 0;
726780 }
781
+
782
+#if IS_REACHABLE(CONFIG_ROCKCHIP_MINIDUMP)
783
+static void _ramoops_register_ram_zone_info_to_minidump(struct persistent_ram_zone *prz)
784
+{
785
+ struct md_region md_entry = {};
786
+
787
+ strscpy(md_entry.name, prz->label, sizeof(md_entry.name));
788
+
789
+ md_entry.virt_addr = (u64)prz->vaddr;
790
+ md_entry.phys_addr = prz->paddr;
791
+ md_entry.size = prz->size;
792
+
793
+ if (rk_minidump_add_region(&md_entry) < 0)
794
+ pr_err("Failed to add %s in Minidump\n", prz->label);
795
+}
796
+
797
+static void ramoops_register_ram_zone_info_to_minidump(struct ramoops_context *cxt)
798
+{
799
+ int i = 0;
800
+ struct persistent_ram_zone *prz = NULL;
801
+
802
+#ifdef CONFIG_PSTORE_BOOT_LOG
803
+ for (i = 0; i < cxt->max_boot_log_cnt; i++) {
804
+ prz = cxt->boot_przs[i];
805
+ _ramoops_register_ram_zone_info_to_minidump(prz);
806
+ }
807
+#endif
808
+
809
+ for (i = 0; i < cxt->max_dump_cnt; i++) {
810
+ prz = cxt->dprzs[i];
811
+ _ramoops_register_ram_zone_info_to_minidump(prz);
812
+ }
813
+
814
+ for (i = 0; i < cxt->max_ftrace_cnt; i++) {
815
+ prz = cxt->fprzs[i];
816
+ _ramoops_register_ram_zone_info_to_minidump(prz);
817
+ }
818
+
819
+ prz = cxt->cprz;
820
+ _ramoops_register_ram_zone_info_to_minidump(prz);
821
+
822
+ prz = cxt->mprz;
823
+ _ramoops_register_ram_zone_info_to_minidump(prz);
824
+}
825
+#endif
727826
728827 static int ramoops_probe(struct platform_device *pdev)
729828 {
....@@ -736,15 +835,6 @@
736835 int err = -EINVAL;
737836 int i = 0;
738837
739
- if (dev_of_node(dev) && !pdata) {
740
- pdata = &pdata_local;
741
- memset(pdata, 0, sizeof(*pdata));
742
-
743
- err = ramoops_parse_dt(pdev, pdata);
744
- if (err < 0)
745
- goto fail_out;
746
- }
747
-
748838 /*
749839 * Only a single ramoops area allowed at a time, so fail extra
750840 * probes.
....@@ -754,9 +844,19 @@
754844 goto fail_out;
755845 }
756846
847
+ if (dev_of_node(dev) && !pdata) {
848
+ pdata = &pdata_local;
849
+ memset(pdata, 0, sizeof(*pdata));
850
+
851
+ err = ramoops_parse_dt(pdev, pdata);
852
+ if (err < 0)
853
+ goto fail_out;
854
+ }
855
+
757856 /* Make sure we didn't get bogus platform data pointer. */
758857 if (!pdata) {
759858 pr_err("NULL platform data\n");
859
+ err = -EINVAL;
760860 goto fail_out;
761861 }
762862
....@@ -772,6 +872,7 @@
772872 !pdata->ftrace_size && !pdata->pmsg_size)) {
773873 pr_err("The memory size and the record/console size must be "
774874 "non-zero\n");
875
+ err = -EINVAL;
775876 goto fail_out;
776877 }
777878 #endif
....@@ -794,7 +895,6 @@
794895 cxt->console_size = pdata->console_size;
795896 cxt->ftrace_size = pdata->ftrace_size;
796897 cxt->pmsg_size = pdata->pmsg_size;
797
- cxt->dump_oops = pdata->dump_oops;
798898 cxt->flags = pdata->flags;
799899 cxt->ecc_info = pdata->ecc_info;
800900 #ifdef CONFIG_PSTORE_BOOT_LOG
....@@ -811,7 +911,7 @@
811911 #endif
812912
813913 #ifdef CONFIG_PSTORE_BOOT_LOG
814
- err = ramoops_init_przs("boot_log", dev, cxt, &cxt->boot_przs, &paddr,
914
+ err = ramoops_init_przs("boot-log", dev, cxt, &cxt->boot_przs, &paddr,
815915 cxt->boot_log_size, -1,
816916 &cxt->max_boot_log_cnt, 0, 0);
817917 if (err)
....@@ -821,7 +921,7 @@
821921 pr_info("boot-log-%d\t0x%zx@%pa\n", i, cxt->boot_przs[i]->size, &cxt->boot_przs[i]->paddr);
822922 #endif
823923
824
- err = ramoops_init_przs("dump", dev, cxt, &cxt->dprzs, &paddr,
924
+ err = ramoops_init_przs("dmesg", dev, cxt, &cxt->dprzs, &paddr,
825925 dump_mem_sz, cxt->record_size,
826926 &cxt->max_dump_cnt, 0, 0);
827927 if (err)
....@@ -855,7 +955,6 @@
855955 cxt->pmsg_size, 0);
856956 if (err)
857957 goto fail_init_mprz;
858
-
859958 if (cxt->pmsg_size > 0)
860959 pr_info("pmsg\t0x%zx@%pa\n", cxt->mprz->size, &cxt->mprz->paddr);
861960
....@@ -867,8 +966,10 @@
867966 * the single region size is how to check.
868967 */
869968 cxt->pstore.flags = 0;
870
- if (cxt->max_dump_cnt)
969
+ if (cxt->max_dump_cnt) {
871970 cxt->pstore.flags |= PSTORE_FLAGS_DMESG;
971
+ cxt->pstore.max_reason = pdata->max_reason;
972
+ }
872973 if (cxt->console_size)
873974 cxt->pstore.flags |= PSTORE_FLAGS_CONSOLE;
874975 if (cxt->max_ftrace_cnt)
....@@ -908,14 +1009,16 @@
9081009 mem_size = pdata->mem_size;
9091010 mem_address = pdata->mem_address;
9101011 record_size = pdata->record_size;
911
- dump_oops = pdata->dump_oops;
1012
+ ramoops_max_reason = pdata->max_reason;
9121013 ramoops_console_size = pdata->console_size;
9131014 ramoops_pmsg_size = pdata->pmsg_size;
9141015 ramoops_ftrace_size = pdata->ftrace_size;
915
-
916
- pr_info("attached 0x%lx@0x%llx, ecc: %d/%d\n",
1016
+#if IS_REACHABLE(CONFIG_ROCKCHIP_MINIDUMP)
1017
+ ramoops_register_ram_zone_info_to_minidump(cxt);
1018
+#endif
1019
+ pr_info("using 0x%lx@0x%llx, ecc: %d\n",
9171020 cxt->size, (unsigned long long)cxt->phys_addr,
918
- cxt->ecc_info.ecc_size, cxt->ecc_info.block_size);
1021
+ cxt->ecc_info.ecc_size);
9191022
9201023 return 0;
9211024
....@@ -967,13 +1070,12 @@
9671070 {
9681071 platform_device_unregister(dummy);
9691072 dummy = NULL;
970
-
971
- kfree(dummy_data);
972
- dummy_data = NULL;
9731073 }
9741074
9751075 static void __init ramoops_register_dummy(void)
9761076 {
1077
+ struct ramoops_platform_data pdata;
1078
+
9771079 /*
9781080 * Prepare a dummy platform data structure to carry the module
9791081 * parameters. If mem_size isn't set, then there are no module
....@@ -984,35 +1086,38 @@
9841086
9851087 pr_info("using module parameters\n");
9861088
987
- dummy_data = kzalloc(sizeof(*dummy_data), GFP_KERNEL);
988
- if (!dummy_data) {
989
- pr_info("could not allocate pdata\n");
990
- return;
991
- }
992
-
993
- dummy_data->mem_size = mem_size;
994
- dummy_data->mem_address = mem_address;
995
- dummy_data->mem_type = mem_type;
996
- dummy_data->record_size = record_size;
997
- dummy_data->console_size = ramoops_console_size;
998
- dummy_data->ftrace_size = ramoops_ftrace_size;
999
- dummy_data->pmsg_size = ramoops_pmsg_size;
1000
- dummy_data->dump_oops = dump_oops;
1001
- dummy_data->flags = RAMOOPS_FLAG_FTRACE_PER_CPU;
1089
+ memset(&pdata, 0, sizeof(pdata));
1090
+ pdata.mem_size = mem_size;
1091
+ pdata.mem_address = mem_address;
1092
+ pdata.mem_type = mem_type;
1093
+ pdata.record_size = record_size;
1094
+ pdata.console_size = ramoops_console_size;
1095
+ pdata.ftrace_size = ramoops_ftrace_size;
1096
+ pdata.pmsg_size = ramoops_pmsg_size;
1097
+ /* If "max_reason" is set, its value has priority over "dump_oops". */
1098
+ if (ramoops_max_reason >= 0)
1099
+ pdata.max_reason = ramoops_max_reason;
1100
+ /* Otherwise, if "dump_oops" is set, parse it into "max_reason". */
1101
+ else if (ramoops_dump_oops != -1)
1102
+ pdata.max_reason = ramoops_dump_oops ? KMSG_DUMP_OOPS
1103
+ : KMSG_DUMP_PANIC;
1104
+ /* And if neither are explicitly set, use the default. */
1105
+ else
1106
+ pdata.max_reason = KMSG_DUMP_OOPS;
1107
+ pdata.flags = RAMOOPS_FLAG_FTRACE_PER_CPU;
10021108
10031109 /*
10041110 * For backwards compatibility ramoops.ecc=1 means 16 bytes ECC
10051111 * (using 1 byte for ECC isn't much of use anyway).
10061112 */
1007
- dummy_data->ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc;
1113
+ pdata.ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc;
10081114
10091115 dummy = platform_device_register_data(NULL, "ramoops", -1,
1010
- dummy_data, sizeof(struct ramoops_platform_data));
1116
+ &pdata, sizeof(pdata));
10111117 if (IS_ERR(dummy)) {
10121118 pr_info("could not create platform device: %ld\n",
10131119 PTR_ERR(dummy));
10141120 dummy = NULL;
1015
- ramoops_unregister_dummy();
10161121 }
10171122 }
10181123