1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2016 - 2018 Intel Corporation. All rights reserved. */
3 #include <linux/percpu-refcount.h>
4 #include <linux/memremap.h>
5 #include <linux/module.h>
6 #include <linux/pfn_t.h>
7 #include <linux/nd.h>
8 #include "../bus.h"
9
10 /* we need the private definitions to implement compat suport */
11 #include "../dax-private.h"
12
dax_pmem_compat_probe(struct device * dev)13 static int dax_pmem_compat_probe(struct device *dev)
14 {
15 struct dev_dax *dev_dax = __dax_pmem_probe(dev, DEV_DAX_CLASS);
16 int rc;
17
18 if (IS_ERR(dev_dax))
19 return PTR_ERR(dev_dax);
20
21 if (!devres_open_group(&dev_dax->dev, dev_dax, GFP_KERNEL))
22 return -ENOMEM;
23
24 device_lock(&dev_dax->dev);
25 rc = dev_dax_probe(dev_dax);
26 device_unlock(&dev_dax->dev);
27
28 devres_close_group(&dev_dax->dev, dev_dax);
29 if (rc)
30 devres_release_group(&dev_dax->dev, dev_dax);
31
32 return rc;
33 }
34
dax_pmem_compat_release(struct device * dev,void * data)35 static int dax_pmem_compat_release(struct device *dev, void *data)
36 {
37 device_lock(dev);
38 devres_release_group(dev, to_dev_dax(dev));
39 device_unlock(dev);
40
41 return 0;
42 }
43
dax_pmem_compat_remove(struct device * dev)44 static void dax_pmem_compat_remove(struct device *dev)
45 {
46 device_for_each_child(dev, NULL, dax_pmem_compat_release);
47 }
48
49 static struct nd_device_driver dax_pmem_compat_driver = {
50 .probe = dax_pmem_compat_probe,
51 .remove = dax_pmem_compat_remove,
52 .drv = {
53 .name = "dax_pmem_compat",
54 },
55 .type = ND_DRIVER_DAX_PMEM,
56 };
57
dax_pmem_compat_init(void)58 static int __init dax_pmem_compat_init(void)
59 {
60 return nd_driver_register(&dax_pmem_compat_driver);
61 }
62 module_init(dax_pmem_compat_init);
63
dax_pmem_compat_exit(void)64 static void __exit dax_pmem_compat_exit(void)
65 {
66 driver_unregister(&dax_pmem_compat_driver.drv);
67 }
68 module_exit(dax_pmem_compat_exit);
69
70 MODULE_LICENSE("GPL v2");
71 MODULE_AUTHOR("Intel Corporation");
72 MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DAX_PMEM);
73