2015-06-01 02:41:48 +08:00
|
|
|
/*
|
|
|
|
* Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*/
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/sizes.h>
|
|
|
|
#include <linux/ndctl.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/nd.h>
|
2015-06-10 04:09:36 +08:00
|
|
|
#include "label.h"
|
2015-06-01 02:41:48 +08:00
|
|
|
#include "nd.h"
|
|
|
|
|
|
|
|
static int nvdimm_probe(struct device *dev)
|
|
|
|
{
|
|
|
|
struct nvdimm_drvdata *ndd;
|
|
|
|
int rc;
|
|
|
|
|
2016-08-17 03:08:40 +08:00
|
|
|
rc = nvdimm_check_config_data(dev);
|
|
|
|
if (rc) {
|
|
|
|
/* not required for non-aliased nvdimm, ex. NVDIMM-N */
|
|
|
|
if (rc == -ENOTTY)
|
|
|
|
rc = 0;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2015-06-01 02:41:48 +08:00
|
|
|
ndd = kzalloc(sizeof(*ndd), GFP_KERNEL);
|
|
|
|
if (!ndd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
dev_set_drvdata(dev, ndd);
|
2015-06-10 04:09:36 +08:00
|
|
|
ndd->dpa.name = dev_name(dev);
|
|
|
|
ndd->ns_current = -1;
|
|
|
|
ndd->ns_next = -1;
|
|
|
|
ndd->dpa.start = 0;
|
|
|
|
ndd->dpa.end = -1;
|
2015-06-01 02:41:48 +08:00
|
|
|
ndd->dev = dev;
|
2015-06-18 05:14:46 +08:00
|
|
|
get_device(dev);
|
|
|
|
kref_init(&ndd->kref);
|
2015-06-01 02:41:48 +08:00
|
|
|
|
|
|
|
rc = nvdimm_init_nsarea(ndd);
|
2017-05-05 02:47:22 +08:00
|
|
|
if (rc == -EACCES)
|
|
|
|
nvdimm_set_locked(dev);
|
2015-06-01 02:41:48 +08:00
|
|
|
if (rc)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
rc = nvdimm_init_config_data(ndd);
|
2017-09-25 00:57:34 +08:00
|
|
|
if (rc == -EACCES)
|
|
|
|
nvdimm_set_locked(dev);
|
2015-06-01 02:41:48 +08:00
|
|
|
if (rc)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
dev_dbg(dev, "config data size: %d\n", ndd->nsarea.config_size);
|
|
|
|
|
2015-06-10 04:09:36 +08:00
|
|
|
nvdimm_bus_lock(dev);
|
|
|
|
ndd->ns_current = nd_label_validate(ndd);
|
|
|
|
ndd->ns_next = nd_label_next_nsindex(ndd->ns_current);
|
|
|
|
nd_label_copy(ndd, to_next_namespace_index(ndd),
|
|
|
|
to_current_namespace_index(ndd));
|
2018-04-07 02:25:38 +08:00
|
|
|
if (ndd->ns_current >= 0) {
|
|
|
|
rc = nd_label_reserve_dpa(ndd);
|
|
|
|
if (rc == 0)
|
|
|
|
nvdimm_set_aliasing(dev);
|
|
|
|
}
|
2017-09-26 02:01:31 +08:00
|
|
|
nvdimm_clear_locked(dev);
|
2015-06-10 04:09:36 +08:00
|
|
|
nvdimm_bus_unlock(dev);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
goto err;
|
|
|
|
|
2015-06-01 02:41:48 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
2015-06-18 05:14:46 +08:00
|
|
|
put_ndd(ndd);
|
2015-06-01 02:41:48 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nvdimm_remove(struct device *dev)
|
|
|
|
{
|
|
|
|
struct nvdimm_drvdata *ndd = dev_get_drvdata(dev);
|
|
|
|
|
2016-08-17 03:08:40 +08:00
|
|
|
if (!ndd)
|
|
|
|
return 0;
|
|
|
|
|
2015-06-10 04:09:36 +08:00
|
|
|
nvdimm_bus_lock(dev);
|
|
|
|
dev_set_drvdata(dev, NULL);
|
|
|
|
nvdimm_bus_unlock(dev);
|
2015-06-18 05:14:46 +08:00
|
|
|
put_ndd(ndd);
|
2015-06-01 02:41:48 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct nd_device_driver nvdimm_driver = {
|
|
|
|
.probe = nvdimm_probe,
|
|
|
|
.remove = nvdimm_remove,
|
|
|
|
.drv = {
|
|
|
|
.name = "nvdimm",
|
|
|
|
},
|
|
|
|
.type = ND_DRIVER_DIMM,
|
|
|
|
};
|
|
|
|
|
|
|
|
int __init nvdimm_init(void)
|
|
|
|
{
|
|
|
|
return nd_driver_register(&nvdimm_driver);
|
|
|
|
}
|
|
|
|
|
2015-06-01 03:02:11 +08:00
|
|
|
void nvdimm_exit(void)
|
2015-06-01 02:41:48 +08:00
|
|
|
{
|
|
|
|
driver_unregister(&nvdimm_driver.drv);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DIMM);
|