libnvdimm/of_pmem: factor out region registration
Subsystems (3)
PATCH v3 1/3 libnvdimm/of_pmem: factor out region registration
From: Kenny Root <[email protected]>
Factor out region registration for 'reg' node. A follow-up change will use of_pmem_register_region() to handle memory-region nodes too.
---
[v3: adelva: remove duplicate "From:"]
drivers/nvdimm/of_pmem.c | 60 +++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 25 deletions(-)
drivers/nvdimm/of_pmem.c +35 -25
@@ -14,6 +14,39 @@ struct of_pmem_private {struct nvdimm_bus *bus; }; +static void of_pmem_register_region (struct platform_device *pdev, +struct nvdimm_bus *bus, +struct device_node *np, +struct resource *res,bool is_volatile) +{ +struct nd_region_desc ndr_desc; +struct nd_region *region; + +/* +* NB: libnvdimm copies the data from ndr_desc into it's own +* structures so passing a stack pointer is fine. +*/ +memset (&ndr_desc,0 ,sizeof (ndr_desc)); + ndr_desc.numa_node =dev_to_node (&pdev->dev); + ndr_desc.target_node = ndr_desc.numa_node; + ndr_desc.res = res; + ndr_desc.of_node = np; +set_bit (ND_REGION_PAGEMAP , &ndr_desc.flags); + +if (is_volatile) + region =nvdimm_volatile_region_create (bus, &ndr_desc); +else + region =nvdimm_pmem_region_create (bus, &ndr_desc); + +if (!region) +dev_warn (&pdev->dev, +"Unable to register region %pR from %pOF\n" , + ndr_desc.res, np); +else +dev_dbg (&pdev->dev,"Registered region %pR from %pOF\n" , + ndr_desc.res, np); +} +static int of_pmem_region_probe (struct platform_device *pdev) {struct of_pmem_private *priv;
@@ -46,31 +79,8 @@ static int of_pmem_region_probe(struct platform_device *pdev) is_volatile ? "volatile" : "non-volatile", np);for (i =0 ; i < pdev->num_resources; i++) { -struct nd_region_desc ndr_desc; -struct nd_region *region; - -/* -* NB: libnvdimm copies the data from ndr_desc into it's own -* structures so passing a stack pointer is fine. -*/ -memset (&ndr_desc,0 ,sizeof (ndr_desc)); - ndr_desc.numa_node =dev_to_node (&pdev->dev); - ndr_desc.target_node = ndr_desc.numa_node; - ndr_desc.res = &pdev->resource[i]; - ndr_desc.of_node = np; -set_bit (ND_REGION_PAGEMAP , &ndr_desc.flags); - -if (is_volatile) - region =nvdimm_volatile_region_create (bus, &ndr_desc); -else - region =nvdimm_pmem_region_create (bus, &ndr_desc); - -if (!region) -dev_warn (&pdev->dev,"Unable to register region %pR from %pOF\n" , - ndr_desc.res, np); -else -dev_dbg (&pdev->dev,"Registered region %pR from %pOF\n" , - ndr_desc.res, np); +of_pmem_register_region (pdev, bus, np, &pdev->resource[i], + is_volatile); }return 0 ;
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH v3 2/3 libnvdimm/of_pmem: handle memory-region in DT
From: Kenny Root <[email protected]>
Add support for parsing the 'memory-region' DT property in addition to the 'reg' DT property. This enables use cases where the pmem region is not in I/O address space or dedicated memory (e.g. a bootloader carveout).
---
[v3: adelva: remove duplicate "From:"]
drivers/nvdimm/of_pmem.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/nvdimm/of_pmem.c +18 -2
@@ -49,11 +49,12 @@ static void of_pmem_register_region(struct platform_device *pdev,static int of_pmem_region_probe (struct platform_device *pdev) { +struct device_node *mr_np, *np;struct of_pmem_private *priv; -struct device_node *np;struct nvdimm_bus *bus; +struct resource res;bool is_volatile; -int i; +int i, ret; np =dev_of_node (&pdev->dev);if (!np)
@@ -83,6 +84,21 @@ static int of_pmem_region_probe(struct platform_device *pdev) is_volatile); } + i =0 ; +while ((mr_np =of_parse_phandle (np,"memory-region" , i++))) { + ret =of_address_to_resource (mr_np,0 , &res); +if (ret) { +dev_warn ( + &pdev->dev, +"Unable to acquire memory-region from %pOF: %d\n" , + mr_np, ret); + }else { +of_pmem_register_region (pdev, bus, np, &res, + is_volatile); + } +of_node_put (mr_np); + } +return 0 ; }
Signature · 4 lines
2.25.0.265.gbab2e86ba0-goog _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
PATCH v3 3/3 dt-bindings: pmem-region: Document memory-region
In reply to Alistair DelvaFrom: Kenny Root <[email protected]>
Add documentation and example for memory-region in pmem.
---
[v3: adelva: remove duplicate "From:"]
.../devicetree/bindings/pmem/pmem-region.txt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+)
Documentation/devicetree/bindings/pmem/pmem-region.txt +29 -0
@@ -29,6 +29,18 @@ Required properties: in a separate device node. Having multiple address ranges in a node implies no special relationship between the two ranges. + This property may be replaced or supplemented with a + memory-region property. Only one of reg or memory-region + properties is required. + + - memory-region: + Reference to the reserved memory node. The reserved memory + node should be defined as per the bindings in + reserved-memory.txt + + This property may be replaced or supplemented with a reg + property. Only one of reg or memory-region is required. + Optional properties: - Any relevant NUMA assocativity properties for the target platform.
@@ -63,3 +75,20 @@ Examples: volatile; }; + + /* + * This example uses a reserved-memory entry instead of + * specifying the memory region directly in the node. + */ + + reserved-memory { + pmem_1: pmem@5000 { + no-map; + reg = <0x00005000 0x00001000>; + }; + }; + + pmem@1 { + compatible = "pmem-region"; + memory-region = <&pmem_1>; + };
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
Rob Herring
maintainerRe: [PATCH v3 3/3] dt-bindings: pmem-region: Document memory-region
Quoted 26 lines · Alistair Delva
From: Kenny Root <[email protected]>
Add documentation and example for memory-region in pmem.
Signed-off-by Kenny Root <[email protected]>Signed-off-by Alistair Delva <[email protected]>Cc "Oliver O'Halloran" <[email protected]>Cc Rob Herring <[email protected]>Cc Dan Williams <[email protected]>Cc Vishal Verma <[email protected]>Cc Dave Jiang <[email protected]>Cc Ira Weiny <[email protected]>---
[v3: adelva: remove duplicate "From:"].../devicetree/bindings/pmem/pmem-region.txt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+)Documentation/devicetree/bindings/pmem/pmem-region.txt +0
-0@@ -29,6 +29,18 @@ Required properties: in a separate device node. Having multiple address ranges in a
Documentation/devicetree/bindings/pmem/pmem-region.txt Required properties: · line 39
Quoted 10 lines
Documentation/devicetree/bindings/pmem/pmem-region.txt +8
-0node implies no special relationship between the two ranges. + This property may be replaced or supplemented with a + memory-region property. Only one of reg or memory-region + properties is required. + + - memory-region: + Reference to the reserved memory node. The reserved memory + node should be defined as per the bindings in + reserved-memory.txt
Though we've never enforced it, but /reserved-memory should be within the bounds of /memory node(s). Is that the intent here? If so, how does that work? Wouldn't all the memory be persistent then? Or some other system processor is preserving the contents?
Quoted 10 lines
Documentation/devicetree/bindings/pmem/pmem-region.txt +4
-0+ + This property may be replaced or supplemented with a reg + property. Only one of reg or memory-region is required. + Optional properties: - Any relevant NUMA assocativity properties for the target platform.@@ -63,3 +75,20 @@ Examples: volatile; };
Documentation/devicetree/bindings/pmem/pmem-region.txt Examples: · line 86
Quoted 10 lines
Documentation/devicetree/bindings/pmem/pmem-region.txt +9
-0+ + /* + * This example uses a reserved-memory entry instead of + * specifying the memory region directly in the node. + */ + + reserved-memory { + pmem_1: pmem@5000 { + no-map;
Just add 'compatible = "pmem-region";' here and be done with it. Why add a layer of indirection?
Documentation/devicetree/bindings/pmem/pmem-region.txt Examples: · line 91
Quoted 5 lines
Documentation/devicetree/bindings/pmem/pmem-region.txt +5
-0+ reg = <0x00005000 0x00001000>; + }; + }; + + pmem@1 {
No 'reg', so shouldn't have a unit-address here.
Quoted 6 lines
Documentation/devicetree/bindings/pmem/pmem-region.txt +3
-0+ compatible = "pmem-region"; + memory-region = <&pmem_1>; + };Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
Re: [PATCH v3 3/3] dt-bindings: pmem-region: Document memory-region
Hi Rob,
Thanks for reviewing.
Quoted 29 lines · Rob Herring
Quoted 29 lines · Alistair Delva
From: Kenny Root <[email protected]>
Add documentation and example for memory-region in pmem.
Signed-off-by Kenny Root <[email protected]>Signed-off-by Alistair Delva <[email protected]>Cc "Oliver O'Halloran" <[email protected]>Cc Rob Herring <[email protected]>Cc Dan Williams <[email protected]>Cc Vishal Verma <[email protected]>Cc Dave Jiang <[email protected]>Cc Ira Weiny <[email protected]>---
[v3: adelva: remove duplicate "From:"].../devicetree/bindings/pmem/pmem-region.txt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+)Documentation/devicetree/bindings/pmem/pmem-region.txt +0
-0@@ -29,6 +29,18 @@ Required properties: in a separate device node. Having multiple address ranges in a node implies no special relationship between the two ranges.
Quoted 13 lines
Documentation/devicetree/bindings/pmem/pmem-region.txt Required properties: · line 39
Quoted 8 lines
Documentation/devicetree/bindings/pmem/pmem-region.txt +8
-0+ This property may be replaced or supplemented with a + memory-region property. Only one of reg or memory-region + properties is required. + + - memory-region: + Reference to the reserved memory node. The reserved memory + node should be defined as per the bindings in + reserved-memory.txtThough we've never enforced it, but /reserved-memory should be within the bounds of /memory node(s). Is that the intent here? If so, how does that work? Wouldn't all the memory be persistent then? Or some other system processor is preserving the contents?
On the systems we're working with, the RAM remains refreshed across reboots, but the contents of RAM could be changed by something outside of Linux (i.e. the bootloader). By reserving this region in DT for pmem we are saying "this is persistent like the rest of RAM on this device, but it is also not going to be touched by anything besides this Linux driver".
Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/pmem/pmem-region.txt +4
-0+ + This property may be replaced or supplemented with a reg + property. Only one of reg or memory-region is required. + Optional properties: - Any relevant NUMA assocativity properties for the target platform.@@ -63,3 +75,20 @@ Examples: volatile; };
Quoted 12 lines
Documentation/devicetree/bindings/pmem/pmem-region.txt Examples: · line 86
Quoted 9 lines
Documentation/devicetree/bindings/pmem/pmem-region.txt +9
-0+ + /* + * This example uses a reserved-memory entry instead of + * specifying the memory region directly in the node. + */ + + reserved-memory { + pmem_1: pmem@5000 { + no-map;Just add 'compatible = "pmem-region";' here and be done with it. Why add a layer of indirection?
Sure, I'll do that..
Quoted 7 lines
Documentation/devicetree/bindings/pmem/pmem-region.txt Examples: · line 91
Quoted 5 lines
Documentation/devicetree/bindings/pmem/pmem-region.txt +5
-0+ reg = <0x00005000 0x00001000>; + }; + }; + + pmem@1 {No 'reg', so shouldn't have a unit-address here.
..then I guess I can just delete this. v4 incoming.
Quoted 10 lines
Quoted 6 lines
Documentation/devicetree/bindings/pmem/pmem-region.txt +3
-1+ compatible = "pmem-region"; + memory-region = <&pmem_1>; + }; --2.25.0.265.gbab2e86ba0-goog
--
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].