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_security_setup_events(dev);
31 dev_err(dev, "security event setup failed: %d\n", rc);
35 rc = nvdimm_check_config_data(dev);
37 /* not required for non-aliased nvdimm, ex. NVDIMM-N */
44 * The locked status bit reflects explicit status codes from the
45 * label reading commands, revalidate it each time the driver is
46 * activated and re-reads the label area.
48 nvdimm_clear_locked(dev);
50 ndd = kzalloc(sizeof(*ndd), GFP_KERNEL);
54 dev_set_drvdata(dev, ndd);
55 ndd->dpa.name = dev_name(dev);
62 kref_init(&ndd->kref);
65 * Attempt to unlock, if the DIMM supports security commands,
66 * otherwise the locked indication is determined by explicit
67 * status codes from the label reading commands.
69 rc = nvdimm_security_unlock(dev);
71 dev_dbg(dev, "failed to unlock dimm: %d\n", rc);
75 * EACCES failures reading the namespace label-area-properties
76 * are interpreted as the DIMM capacity being locked but the
77 * namespace labels themselves being accessible.
79 rc = nvdimm_init_nsarea(ndd);
82 * See nvdimm_namespace_common_probe() where we fail to
83 * allow namespaces to probe while the DIMM is locked,
84 * but we do allow for namespace enumeration.
86 nvdimm_set_locked(dev);
93 * EACCES failures reading the namespace label-data are
94 * interpreted as the label area being locked in addition to the
95 * DIMM capacity. We fail the dimm probe to prevent regions from
96 * attempting to parse the label area.
98 rc = nd_label_data_init(ndd);
100 nvdimm_set_locked(dev);
104 dev_dbg(dev, "config data size: %d\n", ndd->nsarea.config_size);
106 nvdimm_bus_lock(dev);
107 if (ndd->ns_current >= 0) {
108 rc = nd_label_reserve_dpa(ndd);
110 nvdimm_set_aliasing(dev);
112 nvdimm_bus_unlock(dev);
124 static int nvdimm_remove(struct device *dev)
126 struct nvdimm_drvdata *ndd = dev_get_drvdata(dev);
131 nvdimm_bus_lock(dev);
132 dev_set_drvdata(dev, NULL);
133 nvdimm_bus_unlock(dev);
139 static struct nd_device_driver nvdimm_driver = {
140 .probe = nvdimm_probe,
141 .remove = nvdimm_remove,
145 .type = ND_DRIVER_DIMM,
148 int __init nvdimm_init(void)
150 return nd_driver_register(&nvdimm_driver);
153 void nvdimm_exit(void)
155 driver_unregister(&nvdimm_driver.drv);
158 MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DIMM);