David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 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 | |
| 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->dev); |
| 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 | |
| 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 | |
| 44 | static int dax_pmem_compat_remove(struct device *dev) |
| 45 | { |
| 46 | device_for_each_child(dev, NULL, dax_pmem_compat_release); |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static struct nd_device_driver dax_pmem_compat_driver = { |
| 51 | .probe = dax_pmem_compat_probe, |
| 52 | .remove = dax_pmem_compat_remove, |
| 53 | .drv = { |
| 54 | .name = "dax_pmem_compat", |
| 55 | }, |
| 56 | .type = ND_DRIVER_DAX_PMEM, |
| 57 | }; |
| 58 | |
| 59 | static int __init dax_pmem_compat_init(void) |
| 60 | { |
| 61 | return nd_driver_register(&dax_pmem_compat_driver); |
| 62 | } |
| 63 | module_init(dax_pmem_compat_init); |
| 64 | |
| 65 | static void __exit dax_pmem_compat_exit(void) |
| 66 | { |
| 67 | driver_unregister(&dax_pmem_compat_driver.drv); |
| 68 | } |
| 69 | module_exit(dax_pmem_compat_exit); |
| 70 | |
| 71 | MODULE_LICENSE("GPL v2"); |
| 72 | MODULE_AUTHOR("Intel Corporation"); |
| 73 | MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DAX_PMEM); |