summaryrefslogtreecommitdiff
path: root/drivers/dax/pmem/compat.c
blob: 863c114fd88ce1cb810ca59ec6eec9e1445160c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: GPL-2.0
/* Copyright(c) 2016 - 2018 Intel Corporation. All rights reserved. */
#include <linux/percpu-refcount.h>
#include <linux/memremap.h>
#include <linux/module.h>
#include <linux/pfn_t.h>
#include <linux/nd.h>
#include "../bus.h"

/* we need the private definitions to implement compat suport */
#include "../dax-private.h"

static int dax_pmem_compat_probe(struct device *dev)
{
	struct dev_dax *dev_dax = __dax_pmem_probe(dev, DEV_DAX_CLASS);
	int rc;

	if (IS_ERR(dev_dax))
		return PTR_ERR(dev_dax);

        if (!devres_open_group(&dev_dax->dev, dev_dax, GFP_KERNEL))
		return -ENOMEM;

	device_lock(&dev_dax->dev);
	rc = dev_dax_probe(dev_dax);
	device_unlock(&dev_dax->dev);

	devres_close_group(&dev_dax->dev, dev_dax);
	if (rc)
		devres_release_group(&dev_dax->dev, dev_dax);

	return rc;
}

static int dax_pmem_compat_release(struct device *dev, void *data)
{
	device_lock(dev);
	devres_release_group(dev, to_dev_dax(dev));
	device_unlock(dev);

	return 0;
}

static int dax_pmem_compat_remove(struct device *dev)
{
	device_for_each_child(dev, NULL, dax_pmem_compat_release);
	return 0;
}

static struct nd_device_driver dax_pmem_compat_driver = {
	.probe = dax_pmem_compat_probe,
	.remove = dax_pmem_compat_remove,
	.drv = {
		.name = "dax_pmem_compat",
	},
	.type = ND_DRIVER_DAX_PMEM,
};

static int __init dax_pmem_compat_init(void)
{
	return nd_driver_register(&dax_pmem_compat_driver);
}
module_init(dax_pmem_compat_init);

static void __exit dax_pmem_compat_exit(void)
{
	driver_unregister(&dax_pmem_compat_driver.drv);
}
module_exit(dax_pmem_compat_exit);

MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Intel Corporation");
MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DAX_PMEM);