Skip to content

Commit 529182e

Browse files
committed
ramoops: use DT reserved-memory bindings
Instead of a ramoops-specific node, use a child node of /reserved-memory. This requires that of_platform_device_create() be explicitly called for the node, though, since "/reserved-memory" does not have its own "compatible" property. Suggested-by: Rob Herring <robh@kernel.org> Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: Rob Herring <robh@kernel.org>
1 parent f38d2e5 commit 529182e

File tree

4 files changed

+56
-33
lines changed

4 files changed

+56
-33
lines changed

Documentation/devicetree/bindings/misc/ramoops.txt renamed to Documentation/devicetree/bindings/reserved-memory/ramoops.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ Ramoops oops/panic logger
22
=========================
33

44
ramoops provides persistent RAM storage for oops and panics, so they can be
5-
recovered after a reboot. It is a backend to pstore, so this node is named
6-
"ramoops" after the backend, rather than "pstore" which is the subsystem.
5+
recovered after a reboot. This is a child-node of "/reserved-memory", and
6+
is named "ramoops" after the backend, rather than "pstore" which is the
7+
subsystem.
78

89
Parts of this storage may be set aside for other persistent log buffers, such
910
as kernel log messages, or for optional ECC error-correction data. The total
@@ -21,8 +22,7 @@ Required properties:
2122

2223
- compatible: must be "ramoops"
2324

24-
- memory-region: phandle to a region of memory that is preserved between
25-
reboots
25+
- reg: region of memory that is preserved between reboots
2626

2727

2828
Optional properties:

Documentation/ramoops.txt

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,34 @@ corrupt, but usually it is restorable.
4545

4646
2. Setting the parameters
4747

48-
Setting the ramoops parameters can be done in 3 different manners:
49-
1. Use the module parameters (which have the names of the variables described
50-
as before).
51-
For quick debugging, you can also reserve parts of memory during boot
52-
and then use the reserved memory for ramoops. For example, assuming a machine
53-
with > 128 MB of memory, the following kernel command line will tell the
54-
kernel to use only the first 128 MB of memory, and place ECC-protected ramoops
55-
region at 128 MB boundary:
48+
Setting the ramoops parameters can be done in several different manners:
49+
50+
A. Use the module parameters (which have the names of the variables described
51+
as before). For quick debugging, you can also reserve parts of memory during
52+
boot and then use the reserved memory for ramoops. For example, assuming a
53+
machine with > 128 MB of memory, the following kernel command line will tell
54+
the kernel to use only the first 128 MB of memory, and place ECC-protected
55+
ramoops region at 128 MB boundary:
5656
"mem=128M ramoops.mem_address=0x8000000 ramoops.ecc=1"
57-
2. Use Device Tree bindings, as described in
58-
Documentation/device-tree/bindings/misc/ramoops.txt.
59-
3. Use a platform device and set the platform data. The parameters can then
57+
58+
B. Use Device Tree bindings, as described in
59+
Documentation/device-tree/bindings/reserved-memory/ramoops.txt.
60+
For example:
61+
62+
reserved-memory {
63+
#address-cells = <2>;
64+
#size-cells = <2>;
65+
ranges;
66+
67+
ramoops@8f000000 {
68+
compatible = "ramoops";
69+
reg = <0 0x8f000000 0 0x100000>;
70+
record-size = <0x4000>;
71+
console-size = <0x4000>;
72+
};
73+
};
74+
75+
C. Use a platform device and set the platform data. The parameters can then
6076
be set through that platform data. An example of doing that is:
6177

6278
#include <linux/pstore_ram.h>

drivers/of/platform.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,24 @@ EXPORT_SYMBOL_GPL(of_platform_default_populate);
499499

500500
static int __init of_platform_default_populate_init(void)
501501
{
502-
if (of_have_populated_dt())
503-
of_platform_default_populate(NULL, NULL, NULL);
502+
struct device_node *node;
503+
504+
if (!of_have_populated_dt())
505+
return -ENODEV;
506+
507+
/*
508+
* Handle ramoops explicitly, since it is inside /reserved-memory,
509+
* which lacks a "compatible" property.
510+
*/
511+
node = of_find_node_by_path("/reserved-memory");
512+
if (node) {
513+
node = of_find_compatible_node(node, NULL, "ramoops");
514+
if (node)
515+
of_platform_device_create(node, NULL, NULL);
516+
}
517+
518+
/* Populate everything else. */
519+
of_platform_default_populate(NULL, NULL, NULL);
504520

505521
return 0;
506522
}

fs/pstore/ram.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -486,30 +486,21 @@ static int ramoops_parse_dt(struct platform_device *pdev,
486486
struct ramoops_platform_data *pdata)
487487
{
488488
struct device_node *of_node = pdev->dev.of_node;
489-
struct device_node *mem_region;
490-
struct resource res;
489+
struct resource *res;
491490
u32 value;
492491
int ret;
493492

494493
dev_dbg(&pdev->dev, "using Device Tree\n");
495494

496-
mem_region = of_parse_phandle(of_node, "memory-region", 0);
497-
if (!mem_region) {
498-
dev_err(&pdev->dev, "no memory-region phandle\n");
499-
return -ENODEV;
500-
}
501-
502-
ret = of_address_to_resource(mem_region, 0, &res);
503-
of_node_put(mem_region);
504-
if (ret) {
495+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
496+
if (!res) {
505497
dev_err(&pdev->dev,
506-
"failed to translate memory-region to resource: %d\n",
507-
ret);
508-
return ret;
498+
"failed to locate DT /reserved-memory resource\n");
499+
return -EINVAL;
509500
}
510501

511-
pdata->mem_size = resource_size(&res);
512-
pdata->mem_address = res.start;
502+
pdata->mem_size = resource_size(res);
503+
pdata->mem_address = res->start;
513504
pdata->mem_type = of_property_read_bool(of_node, "unbuffered");
514505
pdata->dump_oops = !of_property_read_bool(of_node, "no-dump-oops");
515506

0 commit comments

Comments
 (0)