Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / nvdimm / of_pmem.c
blob10dbdcdfb9ce9137b79896d61568596cf14b03d5
1 // SPDX-License-Identifier: GPL-2.0+
3 #define pr_fmt(fmt) "of_pmem: " fmt
5 #include <linux/of_platform.h>
6 #include <linux/of_address.h>
7 #include <linux/libnvdimm.h>
8 #include <linux/module.h>
9 #include <linux/ioport.h>
10 #include <linux/slab.h>
12 struct of_pmem_private {
13 struct nvdimm_bus_descriptor bus_desc;
14 struct nvdimm_bus *bus;
17 static int of_pmem_region_probe(struct platform_device *pdev)
19 struct of_pmem_private *priv;
20 struct device_node *np;
21 struct nvdimm_bus *bus;
22 bool is_volatile;
23 int i;
25 np = dev_of_node(&pdev->dev);
26 if (!np)
27 return -ENXIO;
29 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
30 if (!priv)
31 return -ENOMEM;
33 priv->bus_desc.provider_name = kstrdup(pdev->name, GFP_KERNEL);
34 priv->bus_desc.module = THIS_MODULE;
35 priv->bus_desc.of_node = np;
37 priv->bus = bus = nvdimm_bus_register(&pdev->dev, &priv->bus_desc);
38 if (!bus) {
39 kfree(priv);
40 return -ENODEV;
42 platform_set_drvdata(pdev, priv);
44 is_volatile = !!of_find_property(np, "volatile", NULL);
45 dev_dbg(&pdev->dev, "Registering %s regions from %pOF\n",
46 is_volatile ? "volatile" : "non-volatile", np);
48 for (i = 0; i < pdev->num_resources; i++) {
49 struct nd_region_desc ndr_desc;
50 struct nd_region *region;
53 * NB: libnvdimm copies the data from ndr_desc into it's own
54 * structures so passing a stack pointer is fine.
56 memset(&ndr_desc, 0, sizeof(ndr_desc));
57 ndr_desc.numa_node = dev_to_node(&pdev->dev);
58 ndr_desc.target_node = ndr_desc.numa_node;
59 ndr_desc.res = &pdev->resource[i];
60 ndr_desc.of_node = np;
61 set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
63 if (is_volatile)
64 region = nvdimm_volatile_region_create(bus, &ndr_desc);
65 else {
66 set_bit(ND_REGION_PERSIST_MEMCTRL, &ndr_desc.flags);
67 region = nvdimm_pmem_region_create(bus, &ndr_desc);
70 if (!region)
71 dev_warn(&pdev->dev, "Unable to register region %pR from %pOF\n",
72 ndr_desc.res, np);
73 else
74 dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
75 ndr_desc.res, np);
78 return 0;
81 static int of_pmem_region_remove(struct platform_device *pdev)
83 struct of_pmem_private *priv = platform_get_drvdata(pdev);
85 nvdimm_bus_unregister(priv->bus);
86 kfree(priv);
88 return 0;
91 static const struct of_device_id of_pmem_region_match[] = {
92 { .compatible = "pmem-region" },
93 { .compatible = "pmem-region-v2" },
94 { },
97 static struct platform_driver of_pmem_region_driver = {
98 .probe = of_pmem_region_probe,
99 .remove = of_pmem_region_remove,
100 .driver = {
101 .name = "of_pmem",
102 .of_match_table = of_pmem_region_match,
106 module_platform_driver(of_pmem_region_driver);
107 MODULE_DEVICE_TABLE(of, of_pmem_region_match);
108 MODULE_LICENSE("GPL");
109 MODULE_AUTHOR("IBM Corporation");