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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <linux/uaccess.h>
15 #include <linux/fcntl.h>
16 #include <linux/slab.h>
21 static int nvdimm_bus_major;
22 static struct class *nd_class;
24 int nvdimm_bus_create_ndctl(struct nvdimm_bus *nvdimm_bus)
26 dev_t devt = MKDEV(nvdimm_bus_major, nvdimm_bus->id);
29 dev = device_create(nd_class, &nvdimm_bus->dev, devt, nvdimm_bus,
30 "ndctl%d", nvdimm_bus->id);
33 dev_dbg(&nvdimm_bus->dev, "failed to register ndctl%d: %ld\n",
34 nvdimm_bus->id, PTR_ERR(dev));
40 void nvdimm_bus_destroy_ndctl(struct nvdimm_bus *nvdimm_bus)
42 device_destroy(nd_class, MKDEV(nvdimm_bus_major, nvdimm_bus->id));
45 static long nd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
50 static const struct file_operations nvdimm_bus_fops = {
52 .open = nonseekable_open,
53 .unlocked_ioctl = nd_ioctl,
54 .compat_ioctl = nd_ioctl,
55 .llseek = noop_llseek,
58 int __init nvdimm_bus_init(void)
62 rc = register_chrdev(0, "ndctl", &nvdimm_bus_fops);
65 nvdimm_bus_major = rc;
67 nd_class = class_create(THIS_MODULE, "nd");
74 unregister_chrdev(nvdimm_bus_major, "ndctl");
79 void __exit nvdimm_bus_exit(void)
81 class_destroy(nd_class);
82 unregister_chrdev(nvdimm_bus_major, "ndctl");