core.c (4d88a97aa9e8cfa6460aab119c5da60ad2267423) | core.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 --- 10 unchanged lines hidden (view full) --- 19#include <linux/slab.h> 20#include "nd-core.h" 21#include "nd.h" 22 23LIST_HEAD(nvdimm_bus_list); 24DEFINE_MUTEX(nvdimm_bus_list_mutex); 25static DEFINE_IDA(nd_ida); 26 | 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 --- 10 unchanged lines hidden (view full) --- 19#include <linux/slab.h> 20#include "nd-core.h" 21#include "nd.h" 22 23LIST_HEAD(nvdimm_bus_list); 24DEFINE_MUTEX(nvdimm_bus_list_mutex); 25static DEFINE_IDA(nd_ida); 26 |
27void nvdimm_bus_lock(struct device *dev) 28{ 29 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); 30 31 if (!nvdimm_bus) 32 return; 33 mutex_lock(&nvdimm_bus->reconfig_mutex); 34} 35EXPORT_SYMBOL(nvdimm_bus_lock); 36 37void nvdimm_bus_unlock(struct device *dev) 38{ 39 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); 40 41 if (!nvdimm_bus) 42 return; 43 mutex_unlock(&nvdimm_bus->reconfig_mutex); 44} 45EXPORT_SYMBOL(nvdimm_bus_unlock); 46 47bool is_nvdimm_bus_locked(struct device *dev) 48{ 49 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); 50 51 if (!nvdimm_bus) 52 return false; 53 return mutex_is_locked(&nvdimm_bus->reconfig_mutex); 54} 55EXPORT_SYMBOL(is_nvdimm_bus_locked); 56 |
|
27static void nvdimm_bus_release(struct device *dev) 28{ 29 struct nvdimm_bus *nvdimm_bus; 30 31 nvdimm_bus = container_of(dev, struct nvdimm_bus, dev); 32 ida_simple_remove(&nd_ida, nvdimm_bus->id); 33 kfree(nvdimm_bus); 34} --- 95 unchanged lines hidden (view full) --- 130 NULL, 131}; 132 133struct attribute_group nvdimm_bus_attribute_group = { 134 .attrs = nvdimm_bus_attributes, 135}; 136EXPORT_SYMBOL_GPL(nvdimm_bus_attribute_group); 137 | 57static void nvdimm_bus_release(struct device *dev) 58{ 59 struct nvdimm_bus *nvdimm_bus; 60 61 nvdimm_bus = container_of(dev, struct nvdimm_bus, dev); 62 ida_simple_remove(&nd_ida, nvdimm_bus->id); 63 kfree(nvdimm_bus); 64} --- 95 unchanged lines hidden (view full) --- 160 NULL, 161}; 162 163struct attribute_group nvdimm_bus_attribute_group = { 164 .attrs = nvdimm_bus_attributes, 165}; 166EXPORT_SYMBOL_GPL(nvdimm_bus_attribute_group); 167 |
138struct nvdimm_bus *nvdimm_bus_register(struct device *parent, 139 struct nvdimm_bus_descriptor *nd_desc) | 168struct nvdimm_bus *__nvdimm_bus_register(struct device *parent, 169 struct nvdimm_bus_descriptor *nd_desc, struct module *module) |
140{ 141 struct nvdimm_bus *nvdimm_bus; 142 int rc; 143 144 nvdimm_bus = kzalloc(sizeof(*nvdimm_bus), GFP_KERNEL); 145 if (!nvdimm_bus) 146 return NULL; 147 INIT_LIST_HEAD(&nvdimm_bus->list); 148 nvdimm_bus->id = ida_simple_get(&nd_ida, 0, 0, GFP_KERNEL); | 170{ 171 struct nvdimm_bus *nvdimm_bus; 172 int rc; 173 174 nvdimm_bus = kzalloc(sizeof(*nvdimm_bus), GFP_KERNEL); 175 if (!nvdimm_bus) 176 return NULL; 177 INIT_LIST_HEAD(&nvdimm_bus->list); 178 nvdimm_bus->id = ida_simple_get(&nd_ida, 0, 0, GFP_KERNEL); |
179 mutex_init(&nvdimm_bus->reconfig_mutex); |
|
149 if (nvdimm_bus->id < 0) { 150 kfree(nvdimm_bus); 151 return NULL; 152 } 153 nvdimm_bus->nd_desc = nd_desc; | 180 if (nvdimm_bus->id < 0) { 181 kfree(nvdimm_bus); 182 return NULL; 183 } 184 nvdimm_bus->nd_desc = nd_desc; |
185 nvdimm_bus->module = module; |
|
154 nvdimm_bus->dev.parent = parent; 155 nvdimm_bus->dev.release = nvdimm_bus_release; 156 nvdimm_bus->dev.groups = nd_desc->attr_groups; 157 dev_set_name(&nvdimm_bus->dev, "ndbus%d", nvdimm_bus->id); 158 rc = device_register(&nvdimm_bus->dev); 159 if (rc) { 160 dev_dbg(&nvdimm_bus->dev, "registration failed: %d\n", rc); 161 goto err; --- 7 unchanged lines hidden (view full) --- 169 list_add_tail(&nvdimm_bus->list, &nvdimm_bus_list); 170 mutex_unlock(&nvdimm_bus_list_mutex); 171 172 return nvdimm_bus; 173 err: 174 put_device(&nvdimm_bus->dev); 175 return NULL; 176} | 186 nvdimm_bus->dev.parent = parent; 187 nvdimm_bus->dev.release = nvdimm_bus_release; 188 nvdimm_bus->dev.groups = nd_desc->attr_groups; 189 dev_set_name(&nvdimm_bus->dev, "ndbus%d", nvdimm_bus->id); 190 rc = device_register(&nvdimm_bus->dev); 191 if (rc) { 192 dev_dbg(&nvdimm_bus->dev, "registration failed: %d\n", rc); 193 goto err; --- 7 unchanged lines hidden (view full) --- 201 list_add_tail(&nvdimm_bus->list, &nvdimm_bus_list); 202 mutex_unlock(&nvdimm_bus_list_mutex); 203 204 return nvdimm_bus; 205 err: 206 put_device(&nvdimm_bus->dev); 207 return NULL; 208} |
177EXPORT_SYMBOL_GPL(nvdimm_bus_register); | 209EXPORT_SYMBOL_GPL(__nvdimm_bus_register); |
178 179static int child_unregister(struct device *dev, void *data) 180{ 181 /* 182 * the singular ndctl class device per bus needs to be 183 * "device_destroy"ed, so skip it here 184 * 185 * i.e. remove classless children --- 27 unchanged lines hidden (view full) --- 213 int rc; 214 215 rc = nvdimm_bus_init(); 216 if (rc) 217 return rc; 218 rc = nvdimm_init(); 219 if (rc) 220 goto err_dimm; | 210 211static int child_unregister(struct device *dev, void *data) 212{ 213 /* 214 * the singular ndctl class device per bus needs to be 215 * "device_destroy"ed, so skip it here 216 * 217 * i.e. remove classless children --- 27 unchanged lines hidden (view full) --- 245 int rc; 246 247 rc = nvdimm_bus_init(); 248 if (rc) 249 return rc; 250 rc = nvdimm_init(); 251 if (rc) 252 goto err_dimm; |
253 rc = nd_region_init(); 254 if (rc) 255 goto err_region; |
|
221 return 0; | 256 return 0; |
257 err_region: 258 nvdimm_exit(); |
|
222 err_dimm: 223 nvdimm_bus_exit(); 224 return rc; 225} 226 227static __exit void libnvdimm_exit(void) 228{ 229 WARN_ON(!list_empty(&nvdimm_bus_list)); | 259 err_dimm: 260 nvdimm_bus_exit(); 261 return rc; 262} 263 264static __exit void libnvdimm_exit(void) 265{ 266 WARN_ON(!list_empty(&nvdimm_bus_list)); |
267 nd_region_exit(); |
|
230 nvdimm_exit(); 231 nvdimm_bus_exit(); 232} 233 234MODULE_LICENSE("GPL v2"); 235MODULE_AUTHOR("Intel Corporation"); 236subsys_initcall(libnvdimm_init); 237module_exit(libnvdimm_exit); | 268 nvdimm_exit(); 269 nvdimm_bus_exit(); 270} 271 272MODULE_LICENSE("GPL v2"); 273MODULE_AUTHOR("Intel Corporation"); 274subsys_initcall(libnvdimm_init); 275module_exit(libnvdimm_exit); |