bus.c (4d88a97aa9e8cfa6460aab119c5da60ad2267423) | bus.c (3d88002e4a7bd40f355550284c6cd140e6fe29dc) |
---|---|
1/* 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#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14#include <linux/vmalloc.h> 15#include <linux/uaccess.h> | 1/* 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#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14#include <linux/vmalloc.h> 15#include <linux/uaccess.h> |
16#include <linux/module.h> |
|
16#include <linux/fcntl.h> 17#include <linux/async.h> 18#include <linux/ndctl.h> 19#include <linux/sched.h> 20#include <linux/slab.h> 21#include <linux/fs.h> 22#include <linux/io.h> 23#include <linux/mm.h> --- 4 unchanged lines hidden (view full) --- 28int nvdimm_major; 29static int nvdimm_bus_major; 30static struct class *nd_class; 31 32static int to_nd_device_type(struct device *dev) 33{ 34 if (is_nvdimm(dev)) 35 return ND_DEVICE_DIMM; | 17#include <linux/fcntl.h> 18#include <linux/async.h> 19#include <linux/ndctl.h> 20#include <linux/sched.h> 21#include <linux/slab.h> 22#include <linux/fs.h> 23#include <linux/io.h> 24#include <linux/mm.h> --- 4 unchanged lines hidden (view full) --- 29int nvdimm_major; 30static int nvdimm_bus_major; 31static struct class *nd_class; 32 33static int to_nd_device_type(struct device *dev) 34{ 35 if (is_nvdimm(dev)) 36 return ND_DEVICE_DIMM; |
37 else if (is_nd_pmem(dev)) 38 return ND_DEVICE_REGION_PMEM; 39 else if (is_nd_blk(dev)) 40 return ND_DEVICE_REGION_BLK; 41 else if (is_nd_pmem(dev->parent) || is_nd_blk(dev->parent)) 42 return nd_region_to_nstype(to_nd_region(dev->parent)); |
|
36 37 return 0; 38} 39 40static int nvdimm_bus_uevent(struct device *dev, struct kobj_uevent_env *env) 41{ 42 return add_uevent_var(env, "MODALIAS=" ND_DEVICE_MODALIAS_FMT, 43 to_nd_device_type(dev)); 44} 45 46static int nvdimm_bus_match(struct device *dev, struct device_driver *drv) 47{ 48 struct nd_device_driver *nd_drv = to_nd_device_driver(drv); 49 50 return test_bit(to_nd_device_type(dev), &nd_drv->type); 51} 52 | 43 44 return 0; 45} 46 47static int nvdimm_bus_uevent(struct device *dev, struct kobj_uevent_env *env) 48{ 49 return add_uevent_var(env, "MODALIAS=" ND_DEVICE_MODALIAS_FMT, 50 to_nd_device_type(dev)); 51} 52 53static int nvdimm_bus_match(struct device *dev, struct device_driver *drv) 54{ 55 struct nd_device_driver *nd_drv = to_nd_device_driver(drv); 56 57 return test_bit(to_nd_device_type(dev), &nd_drv->type); 58} 59 |
60static struct module *to_bus_provider(struct device *dev) 61{ 62 /* pin bus providers while regions are enabled */ 63 if (is_nd_pmem(dev) || is_nd_blk(dev)) { 64 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); 65 66 return nvdimm_bus->module; 67 } 68 return NULL; 69} 70 |
|
53static int nvdimm_bus_probe(struct device *dev) 54{ 55 struct nd_device_driver *nd_drv = to_nd_device_driver(dev->driver); | 71static int nvdimm_bus_probe(struct device *dev) 72{ 73 struct nd_device_driver *nd_drv = to_nd_device_driver(dev->driver); |
74 struct module *provider = to_bus_provider(dev); |
|
56 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); 57 int rc; 58 | 75 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); 76 int rc; 77 |
78 if (!try_module_get(provider)) 79 return -ENXIO; 80 |
|
59 rc = nd_drv->probe(dev); 60 dev_dbg(&nvdimm_bus->dev, "%s.probe(%s) = %d\n", dev->driver->name, 61 dev_name(dev), rc); | 81 rc = nd_drv->probe(dev); 82 dev_dbg(&nvdimm_bus->dev, "%s.probe(%s) = %d\n", dev->driver->name, 83 dev_name(dev), rc); |
84 if (rc != 0) 85 module_put(provider); |
|
62 return rc; 63} 64 65static int nvdimm_bus_remove(struct device *dev) 66{ 67 struct nd_device_driver *nd_drv = to_nd_device_driver(dev->driver); | 86 return rc; 87} 88 89static int nvdimm_bus_remove(struct device *dev) 90{ 91 struct nd_device_driver *nd_drv = to_nd_device_driver(dev->driver); |
92 struct module *provider = to_bus_provider(dev); |
|
68 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); 69 int rc; 70 71 rc = nd_drv->remove(dev); 72 dev_dbg(&nvdimm_bus->dev, "%s.remove(%s) = %d\n", dev->driver->name, 73 dev_name(dev), rc); | 93 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); 94 int rc; 95 96 rc = nd_drv->remove(dev); 97 dev_dbg(&nvdimm_bus->dev, "%s.remove(%s) = %d\n", dev->driver->name, 98 dev_name(dev), rc); |
99 module_put(provider); |
|
74 return rc; 75} 76 77static struct bus_type nvdimm_bus_type = { 78 .name = "nd", 79 .uevent = nvdimm_bus_uevent, 80 .match = nvdimm_bus_match, 81 .probe = nvdimm_bus_probe, --- 496 unchanged lines hidden --- | 100 return rc; 101} 102 103static struct bus_type nvdimm_bus_type = { 104 .name = "nd", 105 .uevent = nvdimm_bus_uevent, 106 .match = nvdimm_bus_match, 107 .probe = nvdimm_bus_probe, --- 496 unchanged lines hidden --- |