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 /* reset locked, to be validated below... */
38 nvdimm_clear_locked(dev
);
40 ndd
= kzalloc(sizeof(*ndd
), GFP_KERNEL
);
44 dev_set_drvdata(dev
, ndd
);
45 ndd
->dpa
.name
= dev_name(dev
);
52 kref_init(&ndd
->kref
);
55 * EACCES failures reading the namespace label-area-properties
56 * are interpreted as the DIMM capacity being locked but the
57 * namespace labels themselves being accessible.
59 rc
= nvdimm_init_nsarea(ndd
);
62 * See nvdimm_namespace_common_probe() where we fail to
63 * allow namespaces to probe while the DIMM is locked,
64 * but we do allow for namespace enumeration.
66 nvdimm_set_locked(dev
);
73 * EACCES failures reading the namespace label-data are
74 * interpreted as the label area being locked in addition to the
75 * DIMM capacity. We fail the dimm probe to prevent regions from
76 * attempting to parse the label area.
78 rc
= nvdimm_init_config_data(ndd
);
80 nvdimm_set_locked(dev
);
84 dev_dbg(dev
, "config data size: %d\n", ndd
->nsarea
.config_size
);
87 ndd
->ns_current
= nd_label_validate(ndd
);
88 ndd
->ns_next
= nd_label_next_nsindex(ndd
->ns_current
);
89 nd_label_copy(ndd
, to_next_namespace_index(ndd
),
90 to_current_namespace_index(ndd
));
91 if (ndd
->ns_current
>= 0) {
92 rc
= nd_label_reserve_dpa(ndd
);
94 nvdimm_set_aliasing(dev
);
96 nvdimm_bus_unlock(dev
);
108 static int nvdimm_remove(struct device
*dev
)
110 struct nvdimm_drvdata
*ndd
= dev_get_drvdata(dev
);
115 nvdimm_bus_lock(dev
);
116 dev_set_drvdata(dev
, NULL
);
117 nvdimm_bus_unlock(dev
);
123 static struct nd_device_driver nvdimm_driver
= {
124 .probe
= nvdimm_probe
,
125 .remove
= nvdimm_remove
,
129 .type
= ND_DRIVER_DIMM
,
132 int __init
nvdimm_init(void)
134 return nd_driver_register(&nvdimm_driver
);
137 void nvdimm_exit(void)
139 driver_unregister(&nvdimm_driver
.drv
);
142 MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DIMM
);