dimm_devs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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/device.h>
  16. #include <linux/ndctl.h>
  17. #include <linux/slab.h>
  18. #include <linux/io.h>
  19. #include <linux/fs.h>
  20. #include <linux/mm.h>
  21. #include "nd-core.h"
  22. #include "label.h"
  23. #include "nd.h"
  24. static DEFINE_IDA(dimm_ida);
  25. /*
  26. * Retrieve bus and dimm handle and return if this bus supports
  27. * get_config_data commands
  28. */
  29. int nvdimm_check_config_data(struct device *dev)
  30. {
  31. struct nvdimm *nvdimm = to_nvdimm(dev);
  32. if (!nvdimm->cmd_mask ||
  33. !test_bit(ND_CMD_GET_CONFIG_DATA, &nvdimm->cmd_mask)) {
  34. if (test_bit(NDD_ALIASING, &nvdimm->flags))
  35. return -ENXIO;
  36. else
  37. return -ENOTTY;
  38. }
  39. return 0;
  40. }
  41. static int validate_dimm(struct nvdimm_drvdata *ndd)
  42. {
  43. int rc;
  44. if (!ndd)
  45. return -EINVAL;
  46. rc = nvdimm_check_config_data(ndd->dev);
  47. if (rc)
  48. dev_dbg(ndd->dev, "%pf: %s error: %d\n",
  49. __builtin_return_address(0), __func__, rc);
  50. return rc;
  51. }
  52. /**
  53. * nvdimm_init_nsarea - determine the geometry of a dimm's namespace area
  54. * @nvdimm: dimm to initialize
  55. */
  56. int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd)
  57. {
  58. struct nd_cmd_get_config_size *cmd = &ndd->nsarea;
  59. struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(ndd->dev);
  60. struct nvdimm_bus_descriptor *nd_desc;
  61. int rc = validate_dimm(ndd);
  62. int cmd_rc = 0;
  63. if (rc)
  64. return rc;
  65. if (cmd->config_size)
  66. return 0; /* already valid */
  67. memset(cmd, 0, sizeof(*cmd));
  68. nd_desc = nvdimm_bus->nd_desc;
  69. rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev),
  70. ND_CMD_GET_CONFIG_SIZE, cmd, sizeof(*cmd), &cmd_rc);
  71. if (rc < 0)
  72. return rc;
  73. return cmd_rc;
  74. }
  75. int nvdimm_init_config_data(struct nvdimm_drvdata *ndd)
  76. {
  77. struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(ndd->dev);
  78. struct nd_cmd_get_config_data_hdr *cmd;
  79. struct nvdimm_bus_descriptor *nd_desc;
  80. int rc = validate_dimm(ndd);
  81. u32 max_cmd_size, config_size;
  82. size_t offset;
  83. if (rc)
  84. return rc;
  85. if (ndd->data)
  86. return 0;
  87. if (ndd->nsarea.status || ndd->nsarea.max_xfer == 0
  88. || ndd->nsarea.config_size < ND_LABEL_MIN_SIZE) {
  89. dev_dbg(ndd->dev, "failed to init config data area: (%d:%d)\n",
  90. ndd->nsarea.max_xfer, ndd->nsarea.config_size);
  91. return -ENXIO;
  92. }
  93. ndd->data = kvmalloc(ndd->nsarea.config_size, GFP_KERNEL);
  94. if (!ndd->data)
  95. return -ENOMEM;
  96. max_cmd_size = min_t(u32, PAGE_SIZE, ndd->nsarea.max_xfer);
  97. cmd = kzalloc(max_cmd_size + sizeof(*cmd), GFP_KERNEL);
  98. if (!cmd)
  99. return -ENOMEM;
  100. nd_desc = nvdimm_bus->nd_desc;
  101. for (config_size = ndd->nsarea.config_size, offset = 0;
  102. config_size; config_size -= cmd->in_length,
  103. offset += cmd->in_length) {
  104. cmd->in_length = min(config_size, max_cmd_size);
  105. cmd->in_offset = offset;
  106. rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev),
  107. ND_CMD_GET_CONFIG_DATA, cmd,
  108. cmd->in_length + sizeof(*cmd), NULL);
  109. if (rc || cmd->status) {
  110. rc = -ENXIO;
  111. break;
  112. }
  113. memcpy(ndd->data + offset, cmd->out_buf, cmd->in_length);
  114. }
  115. dev_dbg(ndd->dev, "%s: len: %zu rc: %d\n", __func__, offset, rc);
  116. kfree(cmd);
  117. return rc;
  118. }
  119. int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset,
  120. void *buf, size_t len)
  121. {
  122. int rc = validate_dimm(ndd);
  123. size_t max_cmd_size, buf_offset;
  124. struct nd_cmd_set_config_hdr *cmd;
  125. struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(ndd->dev);
  126. struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc;
  127. if (rc)
  128. return rc;
  129. if (!ndd->data)
  130. return -ENXIO;
  131. if (offset + len > ndd->nsarea.config_size)
  132. return -ENXIO;
  133. max_cmd_size = min_t(u32, PAGE_SIZE, len);
  134. max_cmd_size = min_t(u32, max_cmd_size, ndd->nsarea.max_xfer);
  135. cmd = kzalloc(max_cmd_size + sizeof(*cmd) + sizeof(u32), GFP_KERNEL);
  136. if (!cmd)
  137. return -ENOMEM;
  138. for (buf_offset = 0; len; len -= cmd->in_length,
  139. buf_offset += cmd->in_length) {
  140. size_t cmd_size;
  141. u32 *status;
  142. cmd->in_offset = offset + buf_offset;
  143. cmd->in_length = min(max_cmd_size, len);
  144. memcpy(cmd->in_buf, buf + buf_offset, cmd->in_length);
  145. /* status is output in the last 4-bytes of the command buffer */
  146. cmd_size = sizeof(*cmd) + cmd->in_length + sizeof(u32);
  147. status = ((void *) cmd) + cmd_size - sizeof(u32);
  148. rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev),
  149. ND_CMD_SET_CONFIG_DATA, cmd, cmd_size, NULL);
  150. if (rc || *status) {
  151. rc = rc ? rc : -ENXIO;
  152. break;
  153. }
  154. }
  155. kfree(cmd);
  156. return rc;
  157. }
  158. void nvdimm_set_aliasing(struct device *dev)
  159. {
  160. struct nvdimm *nvdimm = to_nvdimm(dev);
  161. set_bit(NDD_ALIASING, &nvdimm->flags);
  162. }
  163. void nvdimm_set_locked(struct device *dev)
  164. {
  165. struct nvdimm *nvdimm = to_nvdimm(dev);
  166. set_bit(NDD_LOCKED, &nvdimm->flags);
  167. }
  168. static void nvdimm_release(struct device *dev)
  169. {
  170. struct nvdimm *nvdimm = to_nvdimm(dev);
  171. ida_simple_remove(&dimm_ida, nvdimm->id);
  172. kfree(nvdimm);
  173. }
  174. static struct device_type nvdimm_device_type = {
  175. .name = "nvdimm",
  176. .release = nvdimm_release,
  177. };
  178. bool is_nvdimm(struct device *dev)
  179. {
  180. return dev->type == &nvdimm_device_type;
  181. }
  182. struct nvdimm *to_nvdimm(struct device *dev)
  183. {
  184. struct nvdimm *nvdimm = container_of(dev, struct nvdimm, dev);
  185. WARN_ON(!is_nvdimm(dev));
  186. return nvdimm;
  187. }
  188. EXPORT_SYMBOL_GPL(to_nvdimm);
  189. struct nvdimm *nd_blk_region_to_dimm(struct nd_blk_region *ndbr)
  190. {
  191. struct nd_region *nd_region = &ndbr->nd_region;
  192. struct nd_mapping *nd_mapping = &nd_region->mapping[0];
  193. return nd_mapping->nvdimm;
  194. }
  195. EXPORT_SYMBOL_GPL(nd_blk_region_to_dimm);
  196. struct nvdimm_drvdata *to_ndd(struct nd_mapping *nd_mapping)
  197. {
  198. struct nvdimm *nvdimm = nd_mapping->nvdimm;
  199. WARN_ON_ONCE(!is_nvdimm_bus_locked(&nvdimm->dev));
  200. return dev_get_drvdata(&nvdimm->dev);
  201. }
  202. EXPORT_SYMBOL(to_ndd);
  203. void nvdimm_drvdata_release(struct kref *kref)
  204. {
  205. struct nvdimm_drvdata *ndd = container_of(kref, typeof(*ndd), kref);
  206. struct device *dev = ndd->dev;
  207. struct resource *res, *_r;
  208. dev_dbg(dev, "%s\n", __func__);
  209. nvdimm_bus_lock(dev);
  210. for_each_dpa_resource_safe(ndd, res, _r)
  211. nvdimm_free_dpa(ndd, res);
  212. nvdimm_bus_unlock(dev);
  213. kvfree(ndd->data);
  214. kfree(ndd);
  215. put_device(dev);
  216. }
  217. void get_ndd(struct nvdimm_drvdata *ndd)
  218. {
  219. kref_get(&ndd->kref);
  220. }
  221. void put_ndd(struct nvdimm_drvdata *ndd)
  222. {
  223. if (ndd)
  224. kref_put(&ndd->kref, nvdimm_drvdata_release);
  225. }
  226. const char *nvdimm_name(struct nvdimm *nvdimm)
  227. {
  228. return dev_name(&nvdimm->dev);
  229. }
  230. EXPORT_SYMBOL_GPL(nvdimm_name);
  231. struct kobject *nvdimm_kobj(struct nvdimm *nvdimm)
  232. {
  233. return &nvdimm->dev.kobj;
  234. }
  235. EXPORT_SYMBOL_GPL(nvdimm_kobj);
  236. unsigned long nvdimm_cmd_mask(struct nvdimm *nvdimm)
  237. {
  238. return nvdimm->cmd_mask;
  239. }
  240. EXPORT_SYMBOL_GPL(nvdimm_cmd_mask);
  241. void *nvdimm_provider_data(struct nvdimm *nvdimm)
  242. {
  243. if (nvdimm)
  244. return nvdimm->provider_data;
  245. return NULL;
  246. }
  247. EXPORT_SYMBOL_GPL(nvdimm_provider_data);
  248. static ssize_t commands_show(struct device *dev,
  249. struct device_attribute *attr, char *buf)
  250. {
  251. struct nvdimm *nvdimm = to_nvdimm(dev);
  252. int cmd, len = 0;
  253. if (!nvdimm->cmd_mask)
  254. return sprintf(buf, "\n");
  255. for_each_set_bit(cmd, &nvdimm->cmd_mask, BITS_PER_LONG)
  256. len += sprintf(buf + len, "%s ", nvdimm_cmd_name(cmd));
  257. len += sprintf(buf + len, "\n");
  258. return len;
  259. }
  260. static DEVICE_ATTR_RO(commands);
  261. static ssize_t state_show(struct device *dev, struct device_attribute *attr,
  262. char *buf)
  263. {
  264. struct nvdimm *nvdimm = to_nvdimm(dev);
  265. /*
  266. * The state may be in the process of changing, userspace should
  267. * quiesce probing if it wants a static answer
  268. */
  269. nvdimm_bus_lock(dev);
  270. nvdimm_bus_unlock(dev);
  271. return sprintf(buf, "%s\n", atomic_read(&nvdimm->busy)
  272. ? "active" : "idle");
  273. }
  274. static DEVICE_ATTR_RO(state);
  275. static ssize_t available_slots_show(struct device *dev,
  276. struct device_attribute *attr, char *buf)
  277. {
  278. struct nvdimm_drvdata *ndd = dev_get_drvdata(dev);
  279. ssize_t rc;
  280. u32 nfree;
  281. if (!ndd)
  282. return -ENXIO;
  283. nvdimm_bus_lock(dev);
  284. nfree = nd_label_nfree(ndd);
  285. if (nfree - 1 > nfree) {
  286. dev_WARN_ONCE(dev, 1, "we ate our last label?\n");
  287. nfree = 0;
  288. } else
  289. nfree--;
  290. rc = sprintf(buf, "%d\n", nfree);
  291. nvdimm_bus_unlock(dev);
  292. return rc;
  293. }
  294. static DEVICE_ATTR_RO(available_slots);
  295. static struct attribute *nvdimm_attributes[] = {
  296. &dev_attr_state.attr,
  297. &dev_attr_commands.attr,
  298. &dev_attr_available_slots.attr,
  299. NULL,
  300. };
  301. struct attribute_group nvdimm_attribute_group = {
  302. .attrs = nvdimm_attributes,
  303. };
  304. EXPORT_SYMBOL_GPL(nvdimm_attribute_group);
  305. struct nvdimm *nvdimm_create(struct nvdimm_bus *nvdimm_bus, void *provider_data,
  306. const struct attribute_group **groups, unsigned long flags,
  307. unsigned long cmd_mask, int num_flush,
  308. struct resource *flush_wpq)
  309. {
  310. struct nvdimm *nvdimm = kzalloc(sizeof(*nvdimm), GFP_KERNEL);
  311. struct device *dev;
  312. if (!nvdimm)
  313. return NULL;
  314. nvdimm->id = ida_simple_get(&dimm_ida, 0, 0, GFP_KERNEL);
  315. if (nvdimm->id < 0) {
  316. kfree(nvdimm);
  317. return NULL;
  318. }
  319. nvdimm->provider_data = provider_data;
  320. nvdimm->flags = flags;
  321. nvdimm->cmd_mask = cmd_mask;
  322. nvdimm->num_flush = num_flush;
  323. nvdimm->flush_wpq = flush_wpq;
  324. atomic_set(&nvdimm->busy, 0);
  325. dev = &nvdimm->dev;
  326. dev_set_name(dev, "nmem%d", nvdimm->id);
  327. dev->parent = &nvdimm_bus->dev;
  328. dev->type = &nvdimm_device_type;
  329. dev->devt = MKDEV(nvdimm_major, nvdimm->id);
  330. dev->groups = groups;
  331. nd_device_register(dev);
  332. return nvdimm;
  333. }
  334. EXPORT_SYMBOL_GPL(nvdimm_create);
  335. int alias_dpa_busy(struct device *dev, void *data)
  336. {
  337. resource_size_t map_end, blk_start, new;
  338. struct blk_alloc_info *info = data;
  339. struct nd_mapping *nd_mapping;
  340. struct nd_region *nd_region;
  341. struct nvdimm_drvdata *ndd;
  342. struct resource *res;
  343. int i;
  344. if (!is_nd_pmem(dev))
  345. return 0;
  346. nd_region = to_nd_region(dev);
  347. for (i = 0; i < nd_region->ndr_mappings; i++) {
  348. nd_mapping = &nd_region->mapping[i];
  349. if (nd_mapping->nvdimm == info->nd_mapping->nvdimm)
  350. break;
  351. }
  352. if (i >= nd_region->ndr_mappings)
  353. return 0;
  354. ndd = to_ndd(nd_mapping);
  355. map_end = nd_mapping->start + nd_mapping->size - 1;
  356. blk_start = nd_mapping->start;
  357. /*
  358. * In the allocation case ->res is set to free space that we are
  359. * looking to validate against PMEM aliasing collision rules
  360. * (i.e. BLK is allocated after all aliased PMEM).
  361. */
  362. if (info->res) {
  363. if (info->res->start >= nd_mapping->start
  364. && info->res->start < map_end)
  365. /* pass */;
  366. else
  367. return 0;
  368. }
  369. retry:
  370. /*
  371. * Find the free dpa from the end of the last pmem allocation to
  372. * the end of the interleave-set mapping.
  373. */
  374. for_each_dpa_resource(ndd, res) {
  375. if (strncmp(res->name, "pmem", 4) != 0)
  376. continue;
  377. if ((res->start >= blk_start && res->start < map_end)
  378. || (res->end >= blk_start
  379. && res->end <= map_end)) {
  380. new = max(blk_start, min(map_end + 1, res->end + 1));
  381. if (new != blk_start) {
  382. blk_start = new;
  383. goto retry;
  384. }
  385. }
  386. }
  387. /* update the free space range with the probed blk_start */
  388. if (info->res && blk_start > info->res->start) {
  389. info->res->start = max(info->res->start, blk_start);
  390. if (info->res->start > info->res->end)
  391. info->res->end = info->res->start - 1;
  392. return 1;
  393. }
  394. info->available -= blk_start - nd_mapping->start;
  395. return 0;
  396. }
  397. /**
  398. * nd_blk_available_dpa - account the unused dpa of BLK region
  399. * @nd_mapping: container of dpa-resource-root + labels
  400. *
  401. * Unlike PMEM, BLK namespaces can occupy discontiguous DPA ranges, but
  402. * we arrange for them to never start at an lower dpa than the last
  403. * PMEM allocation in an aliased region.
  404. */
  405. resource_size_t nd_blk_available_dpa(struct nd_region *nd_region)
  406. {
  407. struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev);
  408. struct nd_mapping *nd_mapping = &nd_region->mapping[0];
  409. struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
  410. struct blk_alloc_info info = {
  411. .nd_mapping = nd_mapping,
  412. .available = nd_mapping->size,
  413. .res = NULL,
  414. };
  415. struct resource *res;
  416. if (!ndd)
  417. return 0;
  418. device_for_each_child(&nvdimm_bus->dev, &info, alias_dpa_busy);
  419. /* now account for busy blk allocations in unaliased dpa */
  420. for_each_dpa_resource(ndd, res) {
  421. if (strncmp(res->name, "blk", 3) != 0)
  422. continue;
  423. info.available -= resource_size(res);
  424. }
  425. return info.available;
  426. }
  427. /**
  428. * nd_pmem_available_dpa - for the given dimm+region account unallocated dpa
  429. * @nd_mapping: container of dpa-resource-root + labels
  430. * @nd_region: constrain available space check to this reference region
  431. * @overlap: calculate available space assuming this level of overlap
  432. *
  433. * Validate that a PMEM label, if present, aligns with the start of an
  434. * interleave set and truncate the available size at the lowest BLK
  435. * overlap point.
  436. *
  437. * The expectation is that this routine is called multiple times as it
  438. * probes for the largest BLK encroachment for any single member DIMM of
  439. * the interleave set. Once that value is determined the PMEM-limit for
  440. * the set can be established.
  441. */
  442. resource_size_t nd_pmem_available_dpa(struct nd_region *nd_region,
  443. struct nd_mapping *nd_mapping, resource_size_t *overlap)
  444. {
  445. resource_size_t map_start, map_end, busy = 0, available, blk_start;
  446. struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
  447. struct resource *res;
  448. const char *reason;
  449. if (!ndd)
  450. return 0;
  451. map_start = nd_mapping->start;
  452. map_end = map_start + nd_mapping->size - 1;
  453. blk_start = max(map_start, map_end + 1 - *overlap);
  454. for_each_dpa_resource(ndd, res) {
  455. if (res->start >= map_start && res->start < map_end) {
  456. if (strncmp(res->name, "blk", 3) == 0)
  457. blk_start = min(blk_start,
  458. max(map_start, res->start));
  459. else if (res->end > map_end) {
  460. reason = "misaligned to iset";
  461. goto err;
  462. } else
  463. busy += resource_size(res);
  464. } else if (res->end >= map_start && res->end <= map_end) {
  465. if (strncmp(res->name, "blk", 3) == 0) {
  466. /*
  467. * If a BLK allocation overlaps the start of
  468. * PMEM the entire interleave set may now only
  469. * be used for BLK.
  470. */
  471. blk_start = map_start;
  472. } else
  473. busy += resource_size(res);
  474. } else if (map_start > res->start && map_start < res->end) {
  475. /* total eclipse of the mapping */
  476. busy += nd_mapping->size;
  477. blk_start = map_start;
  478. }
  479. }
  480. *overlap = map_end + 1 - blk_start;
  481. available = blk_start - map_start;
  482. if (busy < available)
  483. return available - busy;
  484. return 0;
  485. err:
  486. nd_dbg_dpa(nd_region, ndd, res, "%s\n", reason);
  487. return 0;
  488. }
  489. void nvdimm_free_dpa(struct nvdimm_drvdata *ndd, struct resource *res)
  490. {
  491. WARN_ON_ONCE(!is_nvdimm_bus_locked(ndd->dev));
  492. kfree(res->name);
  493. __release_region(&ndd->dpa, res->start, resource_size(res));
  494. }
  495. struct resource *nvdimm_allocate_dpa(struct nvdimm_drvdata *ndd,
  496. struct nd_label_id *label_id, resource_size_t start,
  497. resource_size_t n)
  498. {
  499. char *name = kmemdup(label_id, sizeof(*label_id), GFP_KERNEL);
  500. struct resource *res;
  501. if (!name)
  502. return NULL;
  503. WARN_ON_ONCE(!is_nvdimm_bus_locked(ndd->dev));
  504. res = __request_region(&ndd->dpa, start, n, name, 0);
  505. if (!res)
  506. kfree(name);
  507. return res;
  508. }
  509. /**
  510. * nvdimm_allocated_dpa - sum up the dpa currently allocated to this label_id
  511. * @nvdimm: container of dpa-resource-root + labels
  512. * @label_id: dpa resource name of the form {pmem|blk}-<human readable uuid>
  513. */
  514. resource_size_t nvdimm_allocated_dpa(struct nvdimm_drvdata *ndd,
  515. struct nd_label_id *label_id)
  516. {
  517. resource_size_t allocated = 0;
  518. struct resource *res;
  519. for_each_dpa_resource(ndd, res)
  520. if (strcmp(res->name, label_id->id) == 0)
  521. allocated += resource_size(res);
  522. return allocated;
  523. }
  524. static int count_dimms(struct device *dev, void *c)
  525. {
  526. int *count = c;
  527. if (is_nvdimm(dev))
  528. (*count)++;
  529. return 0;
  530. }
  531. int nvdimm_bus_check_dimm_count(struct nvdimm_bus *nvdimm_bus, int dimm_count)
  532. {
  533. int count = 0;
  534. /* Flush any possible dimm registration failures */
  535. nd_synchronize();
  536. device_for_each_child(&nvdimm_bus->dev, &count, count_dimms);
  537. dev_dbg(&nvdimm_bus->dev, "%s: count: %d\n", __func__, count);
  538. if (count != dimm_count)
  539. return -ENXIO;
  540. return 0;
  541. }
  542. EXPORT_SYMBOL_GPL(nvdimm_bus_check_dimm_count);
  543. void __exit nvdimm_devs_exit(void)
  544. {
  545. ida_destroy(&dimm_ida);
  546. }