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