blob: 28001a6ccd4ecbb0946490213af5ba730555266a [file] [log] [blame]
Dan Williams4d88a972015-05-31 14:41:48 -04001/*
2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
3 *
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.
7 *
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.
12 */
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>
19#include <linux/mm.h>
20#include <linux/nd.h>
21#include "nd.h"
22
23static void free_data(struct nvdimm_drvdata *ndd)
24{
25 if (!ndd)
26 return;
27
28 if (ndd->data && is_vmalloc_addr(ndd->data))
29 vfree(ndd->data);
30 else
31 kfree(ndd->data);
32 kfree(ndd);
33}
34
35static int nvdimm_probe(struct device *dev)
36{
37 struct nvdimm_drvdata *ndd;
38 int rc;
39
40 ndd = kzalloc(sizeof(*ndd), GFP_KERNEL);
41 if (!ndd)
42 return -ENOMEM;
43
44 dev_set_drvdata(dev, ndd);
45 ndd->dev = dev;
46
47 rc = nvdimm_init_nsarea(ndd);
48 if (rc)
49 goto err;
50
51 rc = nvdimm_init_config_data(ndd);
52 if (rc)
53 goto err;
54
55 dev_dbg(dev, "config data size: %d\n", ndd->nsarea.config_size);
56
57 return 0;
58
59 err:
60 free_data(ndd);
61 return rc;
62}
63
64static int nvdimm_remove(struct device *dev)
65{
66 struct nvdimm_drvdata *ndd = dev_get_drvdata(dev);
67
68 free_data(ndd);
69
70 return 0;
71}
72
73static struct nd_device_driver nvdimm_driver = {
74 .probe = nvdimm_probe,
75 .remove = nvdimm_remove,
76 .drv = {
77 .name = "nvdimm",
78 },
79 .type = ND_DRIVER_DIMM,
80};
81
82int __init nvdimm_init(void)
83{
84 return nd_driver_register(&nvdimm_driver);
85}
86
87void __exit nvdimm_exit(void)
88{
89 driver_unregister(&nvdimm_driver.drv);
90}
91
92MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DIMM);