2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 #include <linux/vmalloc.h>
14 #include <linux/module.h>
15 #include <linux/device.h>
16 #include <linux/sizes.h>
17 #include <linux/ndctl.h>
18 #include <linux/slab.h>
24 static int nvdimm_probe(struct device
*dev
)
26 struct nvdimm_drvdata
*ndd
;
29 rc
= nvdimm_check_config_data(dev
);
31 /* not required for non-aliased nvdimm, ex. NVDIMM-N */
37 ndd
= kzalloc(sizeof(*ndd
), GFP_KERNEL
);
41 dev_set_drvdata(dev
, ndd
);
42 ndd
->dpa
.name
= dev_name(dev
);
49 kref_init(&ndd
->kref
);
51 rc
= nvdimm_init_nsarea(ndd
);
53 nvdimm_set_locked(dev
);
57 rc
= nvdimm_init_config_data(ndd
);
61 dev_dbg(dev
, "config data size: %d\n", ndd
->nsarea
.config_size
);
64 ndd
->ns_current
= nd_label_validate(ndd
);
65 ndd
->ns_next
= nd_label_next_nsindex(ndd
->ns_current
);
66 nd_label_copy(ndd
, to_next_namespace_index(ndd
),
67 to_current_namespace_index(ndd
));
68 rc
= nd_label_reserve_dpa(ndd
);
69 if (ndd
->ns_current
>= 0)
70 nvdimm_set_aliasing(dev
);
71 nvdimm_clear_locked(dev
);
72 nvdimm_bus_unlock(dev
);
84 static int nvdimm_remove(struct device
*dev
)
86 struct nvdimm_drvdata
*ndd
= dev_get_drvdata(dev
);
92 dev_set_drvdata(dev
, NULL
);
93 nvdimm_bus_unlock(dev
);
99 static struct nd_device_driver nvdimm_driver
= {
100 .probe
= nvdimm_probe
,
101 .remove
= nvdimm_remove
,
105 .type
= ND_DRIVER_DIMM
,
108 int __init
nvdimm_init(void)
110 return nd_driver_register(&nvdimm_driver
);
113 void nvdimm_exit(void)
115 driver_unregister(&nvdimm_driver
.drv
);
118 MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DIMM
);