region_devs.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  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. #include <linux/scatterlist.h>
  14. #include <linux/highmem.h>
  15. #include <linux/sched.h>
  16. #include <linux/slab.h>
  17. #include <linux/hash.h>
  18. #include <linux/sort.h>
  19. #include <linux/io.h>
  20. #include <linux/nd.h>
  21. #include "nd-core.h"
  22. #include "nd.h"
  23. /*
  24. * For readq() and writeq() on 32-bit builds, the hi-lo, lo-hi order is
  25. * irrelevant.
  26. */
  27. #include <linux/io-64-nonatomic-hi-lo.h>
  28. static DEFINE_IDA(region_ida);
  29. static DEFINE_PER_CPU(int, flush_idx);
  30. static int nvdimm_map_flush(struct device *dev, struct nvdimm *nvdimm, int dimm,
  31. struct nd_region_data *ndrd)
  32. {
  33. int i, j;
  34. dev_dbg(dev, "%s: map %d flush address%s\n", nvdimm_name(nvdimm),
  35. nvdimm->num_flush, nvdimm->num_flush == 1 ? "" : "es");
  36. for (i = 0; i < (1 << ndrd->hints_shift); i++) {
  37. struct resource *res = &nvdimm->flush_wpq[i];
  38. unsigned long pfn = PHYS_PFN(res->start);
  39. void __iomem *flush_page;
  40. /* check if flush hints share a page */
  41. for (j = 0; j < i; j++) {
  42. struct resource *res_j = &nvdimm->flush_wpq[j];
  43. unsigned long pfn_j = PHYS_PFN(res_j->start);
  44. if (pfn == pfn_j)
  45. break;
  46. }
  47. if (j < i)
  48. flush_page = (void __iomem *) ((unsigned long)
  49. ndrd_get_flush_wpq(ndrd, dimm, j)
  50. & PAGE_MASK);
  51. else
  52. flush_page = devm_nvdimm_ioremap(dev,
  53. PFN_PHYS(pfn), PAGE_SIZE);
  54. if (!flush_page)
  55. return -ENXIO;
  56. ndrd_set_flush_wpq(ndrd, dimm, i, flush_page
  57. + (res->start & ~PAGE_MASK));
  58. }
  59. return 0;
  60. }
  61. int nd_region_activate(struct nd_region *nd_region)
  62. {
  63. int i, j, num_flush = 0;
  64. struct nd_region_data *ndrd;
  65. struct device *dev = &nd_region->dev;
  66. size_t flush_data_size = sizeof(void *);
  67. nvdimm_bus_lock(&nd_region->dev);
  68. for (i = 0; i < nd_region->ndr_mappings; i++) {
  69. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  70. struct nvdimm *nvdimm = nd_mapping->nvdimm;
  71. /* at least one null hint slot per-dimm for the "no-hint" case */
  72. flush_data_size += sizeof(void *);
  73. num_flush = min_not_zero(num_flush, nvdimm->num_flush);
  74. if (!nvdimm->num_flush)
  75. continue;
  76. flush_data_size += nvdimm->num_flush * sizeof(void *);
  77. }
  78. nvdimm_bus_unlock(&nd_region->dev);
  79. ndrd = devm_kzalloc(dev, sizeof(*ndrd) + flush_data_size, GFP_KERNEL);
  80. if (!ndrd)
  81. return -ENOMEM;
  82. dev_set_drvdata(dev, ndrd);
  83. if (!num_flush)
  84. return 0;
  85. ndrd->hints_shift = ilog2(num_flush);
  86. for (i = 0; i < nd_region->ndr_mappings; i++) {
  87. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  88. struct nvdimm *nvdimm = nd_mapping->nvdimm;
  89. int rc = nvdimm_map_flush(&nd_region->dev, nvdimm, i, ndrd);
  90. if (rc)
  91. return rc;
  92. }
  93. /*
  94. * Clear out entries that are duplicates. This should prevent the
  95. * extra flushings.
  96. */
  97. for (i = 0; i < nd_region->ndr_mappings - 1; i++) {
  98. /* ignore if NULL already */
  99. if (!ndrd_get_flush_wpq(ndrd, i, 0))
  100. continue;
  101. for (j = i + 1; j < nd_region->ndr_mappings; j++)
  102. if (ndrd_get_flush_wpq(ndrd, i, 0) ==
  103. ndrd_get_flush_wpq(ndrd, j, 0))
  104. ndrd_set_flush_wpq(ndrd, j, 0, NULL);
  105. }
  106. return 0;
  107. }
  108. static void nd_region_release(struct device *dev)
  109. {
  110. struct nd_region *nd_region = to_nd_region(dev);
  111. u16 i;
  112. for (i = 0; i < nd_region->ndr_mappings; i++) {
  113. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  114. struct nvdimm *nvdimm = nd_mapping->nvdimm;
  115. put_device(&nvdimm->dev);
  116. }
  117. free_percpu(nd_region->lane);
  118. ida_simple_remove(&region_ida, nd_region->id);
  119. if (is_nd_blk(dev))
  120. kfree(to_nd_blk_region(dev));
  121. else
  122. kfree(nd_region);
  123. }
  124. static struct device_type nd_blk_device_type = {
  125. .name = "nd_blk",
  126. .release = nd_region_release,
  127. };
  128. static struct device_type nd_pmem_device_type = {
  129. .name = "nd_pmem",
  130. .release = nd_region_release,
  131. };
  132. static struct device_type nd_volatile_device_type = {
  133. .name = "nd_volatile",
  134. .release = nd_region_release,
  135. };
  136. bool is_nd_pmem(struct device *dev)
  137. {
  138. return dev ? dev->type == &nd_pmem_device_type : false;
  139. }
  140. bool is_nd_blk(struct device *dev)
  141. {
  142. return dev ? dev->type == &nd_blk_device_type : false;
  143. }
  144. bool is_nd_volatile(struct device *dev)
  145. {
  146. return dev ? dev->type == &nd_volatile_device_type : false;
  147. }
  148. struct nd_region *to_nd_region(struct device *dev)
  149. {
  150. struct nd_region *nd_region = container_of(dev, struct nd_region, dev);
  151. WARN_ON(dev->type->release != nd_region_release);
  152. return nd_region;
  153. }
  154. EXPORT_SYMBOL_GPL(to_nd_region);
  155. struct device *nd_region_dev(struct nd_region *nd_region)
  156. {
  157. if (!nd_region)
  158. return NULL;
  159. return &nd_region->dev;
  160. }
  161. EXPORT_SYMBOL_GPL(nd_region_dev);
  162. struct nd_blk_region *to_nd_blk_region(struct device *dev)
  163. {
  164. struct nd_region *nd_region = to_nd_region(dev);
  165. WARN_ON(!is_nd_blk(dev));
  166. return container_of(nd_region, struct nd_blk_region, nd_region);
  167. }
  168. EXPORT_SYMBOL_GPL(to_nd_blk_region);
  169. void *nd_region_provider_data(struct nd_region *nd_region)
  170. {
  171. return nd_region->provider_data;
  172. }
  173. EXPORT_SYMBOL_GPL(nd_region_provider_data);
  174. void *nd_blk_region_provider_data(struct nd_blk_region *ndbr)
  175. {
  176. return ndbr->blk_provider_data;
  177. }
  178. EXPORT_SYMBOL_GPL(nd_blk_region_provider_data);
  179. void nd_blk_region_set_provider_data(struct nd_blk_region *ndbr, void *data)
  180. {
  181. ndbr->blk_provider_data = data;
  182. }
  183. EXPORT_SYMBOL_GPL(nd_blk_region_set_provider_data);
  184. /**
  185. * nd_region_to_nstype() - region to an integer namespace type
  186. * @nd_region: region-device to interrogate
  187. *
  188. * This is the 'nstype' attribute of a region as well, an input to the
  189. * MODALIAS for namespace devices, and bit number for a nvdimm_bus to match
  190. * namespace devices with namespace drivers.
  191. */
  192. int nd_region_to_nstype(struct nd_region *nd_region)
  193. {
  194. if (is_memory(&nd_region->dev)) {
  195. u16 i, alias;
  196. for (i = 0, alias = 0; i < nd_region->ndr_mappings; i++) {
  197. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  198. struct nvdimm *nvdimm = nd_mapping->nvdimm;
  199. if (test_bit(NDD_ALIASING, &nvdimm->flags))
  200. alias++;
  201. }
  202. if (alias)
  203. return ND_DEVICE_NAMESPACE_PMEM;
  204. else
  205. return ND_DEVICE_NAMESPACE_IO;
  206. } else if (is_nd_blk(&nd_region->dev)) {
  207. return ND_DEVICE_NAMESPACE_BLK;
  208. }
  209. return 0;
  210. }
  211. EXPORT_SYMBOL(nd_region_to_nstype);
  212. static ssize_t size_show(struct device *dev,
  213. struct device_attribute *attr, char *buf)
  214. {
  215. struct nd_region *nd_region = to_nd_region(dev);
  216. unsigned long long size = 0;
  217. if (is_memory(dev)) {
  218. size = nd_region->ndr_size;
  219. } else if (nd_region->ndr_mappings == 1) {
  220. struct nd_mapping *nd_mapping = &nd_region->mapping[0];
  221. size = nd_mapping->size;
  222. }
  223. return sprintf(buf, "%llu\n", size);
  224. }
  225. static DEVICE_ATTR_RO(size);
  226. static ssize_t deep_flush_show(struct device *dev,
  227. struct device_attribute *attr, char *buf)
  228. {
  229. struct nd_region *nd_region = to_nd_region(dev);
  230. /*
  231. * NOTE: in the nvdimm_has_flush() error case this attribute is
  232. * not visible.
  233. */
  234. return sprintf(buf, "%d\n", nvdimm_has_flush(nd_region));
  235. }
  236. static ssize_t deep_flush_store(struct device *dev, struct device_attribute *attr,
  237. const char *buf, size_t len)
  238. {
  239. bool flush;
  240. int rc = strtobool(buf, &flush);
  241. struct nd_region *nd_region = to_nd_region(dev);
  242. if (rc)
  243. return rc;
  244. if (!flush)
  245. return -EINVAL;
  246. nvdimm_flush(nd_region);
  247. return len;
  248. }
  249. static DEVICE_ATTR_RW(deep_flush);
  250. static ssize_t mappings_show(struct device *dev,
  251. struct device_attribute *attr, char *buf)
  252. {
  253. struct nd_region *nd_region = to_nd_region(dev);
  254. return sprintf(buf, "%d\n", nd_region->ndr_mappings);
  255. }
  256. static DEVICE_ATTR_RO(mappings);
  257. static ssize_t nstype_show(struct device *dev,
  258. struct device_attribute *attr, char *buf)
  259. {
  260. struct nd_region *nd_region = to_nd_region(dev);
  261. return sprintf(buf, "%d\n", nd_region_to_nstype(nd_region));
  262. }
  263. static DEVICE_ATTR_RO(nstype);
  264. static ssize_t set_cookie_show(struct device *dev,
  265. struct device_attribute *attr, char *buf)
  266. {
  267. struct nd_region *nd_region = to_nd_region(dev);
  268. struct nd_interleave_set *nd_set = nd_region->nd_set;
  269. ssize_t rc = 0;
  270. if (is_memory(dev) && nd_set)
  271. /* pass, should be precluded by region_visible */;
  272. else
  273. return -ENXIO;
  274. /*
  275. * The cookie to show depends on which specification of the
  276. * labels we are using. If there are not labels then default to
  277. * the v1.1 namespace label cookie definition. To read all this
  278. * data we need to wait for probing to settle.
  279. */
  280. device_lock(dev);
  281. nvdimm_bus_lock(dev);
  282. wait_nvdimm_bus_probe_idle(dev);
  283. if (nd_region->ndr_mappings) {
  284. struct nd_mapping *nd_mapping = &nd_region->mapping[0];
  285. struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
  286. if (ndd) {
  287. struct nd_namespace_index *nsindex;
  288. nsindex = to_namespace_index(ndd, ndd->ns_current);
  289. rc = sprintf(buf, "%#llx\n",
  290. nd_region_interleave_set_cookie(nd_region,
  291. nsindex));
  292. }
  293. }
  294. nvdimm_bus_unlock(dev);
  295. device_unlock(dev);
  296. if (rc)
  297. return rc;
  298. return sprintf(buf, "%#llx\n", nd_set->cookie1);
  299. }
  300. static DEVICE_ATTR_RO(set_cookie);
  301. resource_size_t nd_region_available_dpa(struct nd_region *nd_region)
  302. {
  303. resource_size_t blk_max_overlap = 0, available, overlap;
  304. int i;
  305. WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev));
  306. retry:
  307. available = 0;
  308. overlap = blk_max_overlap;
  309. for (i = 0; i < nd_region->ndr_mappings; i++) {
  310. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  311. struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
  312. /* if a dimm is disabled the available capacity is zero */
  313. if (!ndd)
  314. return 0;
  315. if (is_memory(&nd_region->dev)) {
  316. available += nd_pmem_available_dpa(nd_region,
  317. nd_mapping, &overlap);
  318. if (overlap > blk_max_overlap) {
  319. blk_max_overlap = overlap;
  320. goto retry;
  321. }
  322. } else if (is_nd_blk(&nd_region->dev))
  323. available += nd_blk_available_dpa(nd_region);
  324. }
  325. return available;
  326. }
  327. resource_size_t nd_region_allocatable_dpa(struct nd_region *nd_region)
  328. {
  329. resource_size_t available = 0;
  330. int i;
  331. if (is_memory(&nd_region->dev))
  332. available = PHYS_ADDR_MAX;
  333. WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev));
  334. for (i = 0; i < nd_region->ndr_mappings; i++) {
  335. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  336. if (is_memory(&nd_region->dev))
  337. available = min(available,
  338. nd_pmem_max_contiguous_dpa(nd_region,
  339. nd_mapping));
  340. else if (is_nd_blk(&nd_region->dev))
  341. available += nd_blk_available_dpa(nd_region);
  342. }
  343. if (is_memory(&nd_region->dev))
  344. return available * nd_region->ndr_mappings;
  345. return available;
  346. }
  347. static ssize_t available_size_show(struct device *dev,
  348. struct device_attribute *attr, char *buf)
  349. {
  350. struct nd_region *nd_region = to_nd_region(dev);
  351. unsigned long long available = 0;
  352. /*
  353. * Flush in-flight updates and grab a snapshot of the available
  354. * size. Of course, this value is potentially invalidated the
  355. * memory nvdimm_bus_lock() is dropped, but that's userspace's
  356. * problem to not race itself.
  357. */
  358. device_lock(dev);
  359. nvdimm_bus_lock(dev);
  360. wait_nvdimm_bus_probe_idle(dev);
  361. available = nd_region_available_dpa(nd_region);
  362. nvdimm_bus_unlock(dev);
  363. device_unlock(dev);
  364. return sprintf(buf, "%llu\n", available);
  365. }
  366. static DEVICE_ATTR_RO(available_size);
  367. static ssize_t max_available_extent_show(struct device *dev,
  368. struct device_attribute *attr, char *buf)
  369. {
  370. struct nd_region *nd_region = to_nd_region(dev);
  371. unsigned long long available = 0;
  372. device_lock(dev);
  373. nvdimm_bus_lock(dev);
  374. wait_nvdimm_bus_probe_idle(dev);
  375. available = nd_region_allocatable_dpa(nd_region);
  376. nvdimm_bus_unlock(dev);
  377. device_unlock(dev);
  378. return sprintf(buf, "%llu\n", available);
  379. }
  380. static DEVICE_ATTR_RO(max_available_extent);
  381. static ssize_t init_namespaces_show(struct device *dev,
  382. struct device_attribute *attr, char *buf)
  383. {
  384. struct nd_region_data *ndrd = dev_get_drvdata(dev);
  385. ssize_t rc;
  386. nvdimm_bus_lock(dev);
  387. if (ndrd)
  388. rc = sprintf(buf, "%d/%d\n", ndrd->ns_active, ndrd->ns_count);
  389. else
  390. rc = -ENXIO;
  391. nvdimm_bus_unlock(dev);
  392. return rc;
  393. }
  394. static DEVICE_ATTR_RO(init_namespaces);
  395. static ssize_t namespace_seed_show(struct device *dev,
  396. struct device_attribute *attr, char *buf)
  397. {
  398. struct nd_region *nd_region = to_nd_region(dev);
  399. ssize_t rc;
  400. nvdimm_bus_lock(dev);
  401. if (nd_region->ns_seed)
  402. rc = sprintf(buf, "%s\n", dev_name(nd_region->ns_seed));
  403. else
  404. rc = sprintf(buf, "\n");
  405. nvdimm_bus_unlock(dev);
  406. return rc;
  407. }
  408. static DEVICE_ATTR_RO(namespace_seed);
  409. static ssize_t btt_seed_show(struct device *dev,
  410. struct device_attribute *attr, char *buf)
  411. {
  412. struct nd_region *nd_region = to_nd_region(dev);
  413. ssize_t rc;
  414. nvdimm_bus_lock(dev);
  415. if (nd_region->btt_seed)
  416. rc = sprintf(buf, "%s\n", dev_name(nd_region->btt_seed));
  417. else
  418. rc = sprintf(buf, "\n");
  419. nvdimm_bus_unlock(dev);
  420. return rc;
  421. }
  422. static DEVICE_ATTR_RO(btt_seed);
  423. static ssize_t pfn_seed_show(struct device *dev,
  424. struct device_attribute *attr, char *buf)
  425. {
  426. struct nd_region *nd_region = to_nd_region(dev);
  427. ssize_t rc;
  428. nvdimm_bus_lock(dev);
  429. if (nd_region->pfn_seed)
  430. rc = sprintf(buf, "%s\n", dev_name(nd_region->pfn_seed));
  431. else
  432. rc = sprintf(buf, "\n");
  433. nvdimm_bus_unlock(dev);
  434. return rc;
  435. }
  436. static DEVICE_ATTR_RO(pfn_seed);
  437. static ssize_t dax_seed_show(struct device *dev,
  438. struct device_attribute *attr, char *buf)
  439. {
  440. struct nd_region *nd_region = to_nd_region(dev);
  441. ssize_t rc;
  442. nvdimm_bus_lock(dev);
  443. if (nd_region->dax_seed)
  444. rc = sprintf(buf, "%s\n", dev_name(nd_region->dax_seed));
  445. else
  446. rc = sprintf(buf, "\n");
  447. nvdimm_bus_unlock(dev);
  448. return rc;
  449. }
  450. static DEVICE_ATTR_RO(dax_seed);
  451. static ssize_t read_only_show(struct device *dev,
  452. struct device_attribute *attr, char *buf)
  453. {
  454. struct nd_region *nd_region = to_nd_region(dev);
  455. return sprintf(buf, "%d\n", nd_region->ro);
  456. }
  457. static ssize_t read_only_store(struct device *dev,
  458. struct device_attribute *attr, const char *buf, size_t len)
  459. {
  460. bool ro;
  461. int rc = strtobool(buf, &ro);
  462. struct nd_region *nd_region = to_nd_region(dev);
  463. if (rc)
  464. return rc;
  465. nd_region->ro = ro;
  466. return len;
  467. }
  468. static DEVICE_ATTR_RW(read_only);
  469. static ssize_t region_badblocks_show(struct device *dev,
  470. struct device_attribute *attr, char *buf)
  471. {
  472. struct nd_region *nd_region = to_nd_region(dev);
  473. ssize_t rc;
  474. device_lock(dev);
  475. if (dev->driver)
  476. rc = badblocks_show(&nd_region->bb, buf, 0);
  477. else
  478. rc = -ENXIO;
  479. device_unlock(dev);
  480. return rc;
  481. }
  482. static DEVICE_ATTR(badblocks, 0444, region_badblocks_show, NULL);
  483. static ssize_t resource_show(struct device *dev,
  484. struct device_attribute *attr, char *buf)
  485. {
  486. struct nd_region *nd_region = to_nd_region(dev);
  487. return sprintf(buf, "%#llx\n", nd_region->ndr_start);
  488. }
  489. static DEVICE_ATTR_RO(resource);
  490. static ssize_t persistence_domain_show(struct device *dev,
  491. struct device_attribute *attr, char *buf)
  492. {
  493. struct nd_region *nd_region = to_nd_region(dev);
  494. if (test_bit(ND_REGION_PERSIST_CACHE, &nd_region->flags))
  495. return sprintf(buf, "cpu_cache\n");
  496. else if (test_bit(ND_REGION_PERSIST_MEMCTRL, &nd_region->flags))
  497. return sprintf(buf, "memory_controller\n");
  498. else
  499. return sprintf(buf, "\n");
  500. }
  501. static DEVICE_ATTR_RO(persistence_domain);
  502. static struct attribute *nd_region_attributes[] = {
  503. &dev_attr_size.attr,
  504. &dev_attr_nstype.attr,
  505. &dev_attr_mappings.attr,
  506. &dev_attr_btt_seed.attr,
  507. &dev_attr_pfn_seed.attr,
  508. &dev_attr_dax_seed.attr,
  509. &dev_attr_deep_flush.attr,
  510. &dev_attr_read_only.attr,
  511. &dev_attr_set_cookie.attr,
  512. &dev_attr_available_size.attr,
  513. &dev_attr_max_available_extent.attr,
  514. &dev_attr_namespace_seed.attr,
  515. &dev_attr_init_namespaces.attr,
  516. &dev_attr_badblocks.attr,
  517. &dev_attr_resource.attr,
  518. &dev_attr_persistence_domain.attr,
  519. NULL,
  520. };
  521. static umode_t region_visible(struct kobject *kobj, struct attribute *a, int n)
  522. {
  523. struct device *dev = container_of(kobj, typeof(*dev), kobj);
  524. struct nd_region *nd_region = to_nd_region(dev);
  525. struct nd_interleave_set *nd_set = nd_region->nd_set;
  526. int type = nd_region_to_nstype(nd_region);
  527. if (!is_memory(dev) && a == &dev_attr_pfn_seed.attr)
  528. return 0;
  529. if (!is_memory(dev) && a == &dev_attr_dax_seed.attr)
  530. return 0;
  531. if (!is_memory(dev) && a == &dev_attr_badblocks.attr)
  532. return 0;
  533. if (a == &dev_attr_resource.attr) {
  534. if (is_memory(dev))
  535. return 0400;
  536. else
  537. return 0;
  538. }
  539. if (a == &dev_attr_deep_flush.attr) {
  540. int has_flush = nvdimm_has_flush(nd_region);
  541. if (has_flush == 1)
  542. return a->mode;
  543. else if (has_flush == 0)
  544. return 0444;
  545. else
  546. return 0;
  547. }
  548. if (a == &dev_attr_persistence_domain.attr) {
  549. if ((nd_region->flags & (BIT(ND_REGION_PERSIST_CACHE)
  550. | BIT(ND_REGION_PERSIST_MEMCTRL))) == 0)
  551. return 0;
  552. return a->mode;
  553. }
  554. if (a != &dev_attr_set_cookie.attr
  555. && a != &dev_attr_available_size.attr)
  556. return a->mode;
  557. if ((type == ND_DEVICE_NAMESPACE_PMEM
  558. || type == ND_DEVICE_NAMESPACE_BLK)
  559. && a == &dev_attr_available_size.attr)
  560. return a->mode;
  561. else if (is_memory(dev) && nd_set)
  562. return a->mode;
  563. return 0;
  564. }
  565. struct attribute_group nd_region_attribute_group = {
  566. .attrs = nd_region_attributes,
  567. .is_visible = region_visible,
  568. };
  569. EXPORT_SYMBOL_GPL(nd_region_attribute_group);
  570. u64 nd_region_interleave_set_cookie(struct nd_region *nd_region,
  571. struct nd_namespace_index *nsindex)
  572. {
  573. struct nd_interleave_set *nd_set = nd_region->nd_set;
  574. if (!nd_set)
  575. return 0;
  576. if (nsindex && __le16_to_cpu(nsindex->major) == 1
  577. && __le16_to_cpu(nsindex->minor) == 1)
  578. return nd_set->cookie1;
  579. return nd_set->cookie2;
  580. }
  581. u64 nd_region_interleave_set_altcookie(struct nd_region *nd_region)
  582. {
  583. struct nd_interleave_set *nd_set = nd_region->nd_set;
  584. if (nd_set)
  585. return nd_set->altcookie;
  586. return 0;
  587. }
  588. void nd_mapping_free_labels(struct nd_mapping *nd_mapping)
  589. {
  590. struct nd_label_ent *label_ent, *e;
  591. lockdep_assert_held(&nd_mapping->lock);
  592. list_for_each_entry_safe(label_ent, e, &nd_mapping->labels, list) {
  593. list_del(&label_ent->list);
  594. kfree(label_ent);
  595. }
  596. }
  597. /*
  598. * Upon successful probe/remove, take/release a reference on the
  599. * associated interleave set (if present), and plant new btt + namespace
  600. * seeds. Also, on the removal of a BLK region, notify the provider to
  601. * disable the region.
  602. */
  603. static void nd_region_notify_driver_action(struct nvdimm_bus *nvdimm_bus,
  604. struct device *dev, bool probe)
  605. {
  606. struct nd_region *nd_region;
  607. if (!probe && is_nd_region(dev)) {
  608. int i;
  609. nd_region = to_nd_region(dev);
  610. for (i = 0; i < nd_region->ndr_mappings; i++) {
  611. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  612. struct nvdimm_drvdata *ndd = nd_mapping->ndd;
  613. struct nvdimm *nvdimm = nd_mapping->nvdimm;
  614. mutex_lock(&nd_mapping->lock);
  615. nd_mapping_free_labels(nd_mapping);
  616. mutex_unlock(&nd_mapping->lock);
  617. put_ndd(ndd);
  618. nd_mapping->ndd = NULL;
  619. if (ndd)
  620. atomic_dec(&nvdimm->busy);
  621. }
  622. }
  623. if (dev->parent && is_nd_region(dev->parent) && probe) {
  624. nd_region = to_nd_region(dev->parent);
  625. nvdimm_bus_lock(dev);
  626. if (nd_region->ns_seed == dev)
  627. nd_region_create_ns_seed(nd_region);
  628. nvdimm_bus_unlock(dev);
  629. }
  630. if (is_nd_btt(dev) && probe) {
  631. struct nd_btt *nd_btt = to_nd_btt(dev);
  632. nd_region = to_nd_region(dev->parent);
  633. nvdimm_bus_lock(dev);
  634. if (nd_region->btt_seed == dev)
  635. nd_region_create_btt_seed(nd_region);
  636. if (nd_region->ns_seed == &nd_btt->ndns->dev)
  637. nd_region_create_ns_seed(nd_region);
  638. nvdimm_bus_unlock(dev);
  639. }
  640. if (is_nd_pfn(dev) && probe) {
  641. struct nd_pfn *nd_pfn = to_nd_pfn(dev);
  642. nd_region = to_nd_region(dev->parent);
  643. nvdimm_bus_lock(dev);
  644. if (nd_region->pfn_seed == dev)
  645. nd_region_create_pfn_seed(nd_region);
  646. if (nd_region->ns_seed == &nd_pfn->ndns->dev)
  647. nd_region_create_ns_seed(nd_region);
  648. nvdimm_bus_unlock(dev);
  649. }
  650. if (is_nd_dax(dev) && probe) {
  651. struct nd_dax *nd_dax = to_nd_dax(dev);
  652. nd_region = to_nd_region(dev->parent);
  653. nvdimm_bus_lock(dev);
  654. if (nd_region->dax_seed == dev)
  655. nd_region_create_dax_seed(nd_region);
  656. if (nd_region->ns_seed == &nd_dax->nd_pfn.ndns->dev)
  657. nd_region_create_ns_seed(nd_region);
  658. nvdimm_bus_unlock(dev);
  659. }
  660. }
  661. void nd_region_probe_success(struct nvdimm_bus *nvdimm_bus, struct device *dev)
  662. {
  663. nd_region_notify_driver_action(nvdimm_bus, dev, true);
  664. }
  665. void nd_region_disable(struct nvdimm_bus *nvdimm_bus, struct device *dev)
  666. {
  667. nd_region_notify_driver_action(nvdimm_bus, dev, false);
  668. }
  669. static ssize_t mappingN(struct device *dev, char *buf, int n)
  670. {
  671. struct nd_region *nd_region = to_nd_region(dev);
  672. struct nd_mapping *nd_mapping;
  673. struct nvdimm *nvdimm;
  674. if (n >= nd_region->ndr_mappings)
  675. return -ENXIO;
  676. nd_mapping = &nd_region->mapping[n];
  677. nvdimm = nd_mapping->nvdimm;
  678. return sprintf(buf, "%s,%llu,%llu,%d\n", dev_name(&nvdimm->dev),
  679. nd_mapping->start, nd_mapping->size,
  680. nd_mapping->position);
  681. }
  682. #define REGION_MAPPING(idx) \
  683. static ssize_t mapping##idx##_show(struct device *dev, \
  684. struct device_attribute *attr, char *buf) \
  685. { \
  686. return mappingN(dev, buf, idx); \
  687. } \
  688. static DEVICE_ATTR_RO(mapping##idx)
  689. /*
  690. * 32 should be enough for a while, even in the presence of socket
  691. * interleave a 32-way interleave set is a degenerate case.
  692. */
  693. REGION_MAPPING(0);
  694. REGION_MAPPING(1);
  695. REGION_MAPPING(2);
  696. REGION_MAPPING(3);
  697. REGION_MAPPING(4);
  698. REGION_MAPPING(5);
  699. REGION_MAPPING(6);
  700. REGION_MAPPING(7);
  701. REGION_MAPPING(8);
  702. REGION_MAPPING(9);
  703. REGION_MAPPING(10);
  704. REGION_MAPPING(11);
  705. REGION_MAPPING(12);
  706. REGION_MAPPING(13);
  707. REGION_MAPPING(14);
  708. REGION_MAPPING(15);
  709. REGION_MAPPING(16);
  710. REGION_MAPPING(17);
  711. REGION_MAPPING(18);
  712. REGION_MAPPING(19);
  713. REGION_MAPPING(20);
  714. REGION_MAPPING(21);
  715. REGION_MAPPING(22);
  716. REGION_MAPPING(23);
  717. REGION_MAPPING(24);
  718. REGION_MAPPING(25);
  719. REGION_MAPPING(26);
  720. REGION_MAPPING(27);
  721. REGION_MAPPING(28);
  722. REGION_MAPPING(29);
  723. REGION_MAPPING(30);
  724. REGION_MAPPING(31);
  725. static umode_t mapping_visible(struct kobject *kobj, struct attribute *a, int n)
  726. {
  727. struct device *dev = container_of(kobj, struct device, kobj);
  728. struct nd_region *nd_region = to_nd_region(dev);
  729. if (n < nd_region->ndr_mappings)
  730. return a->mode;
  731. return 0;
  732. }
  733. static struct attribute *mapping_attributes[] = {
  734. &dev_attr_mapping0.attr,
  735. &dev_attr_mapping1.attr,
  736. &dev_attr_mapping2.attr,
  737. &dev_attr_mapping3.attr,
  738. &dev_attr_mapping4.attr,
  739. &dev_attr_mapping5.attr,
  740. &dev_attr_mapping6.attr,
  741. &dev_attr_mapping7.attr,
  742. &dev_attr_mapping8.attr,
  743. &dev_attr_mapping9.attr,
  744. &dev_attr_mapping10.attr,
  745. &dev_attr_mapping11.attr,
  746. &dev_attr_mapping12.attr,
  747. &dev_attr_mapping13.attr,
  748. &dev_attr_mapping14.attr,
  749. &dev_attr_mapping15.attr,
  750. &dev_attr_mapping16.attr,
  751. &dev_attr_mapping17.attr,
  752. &dev_attr_mapping18.attr,
  753. &dev_attr_mapping19.attr,
  754. &dev_attr_mapping20.attr,
  755. &dev_attr_mapping21.attr,
  756. &dev_attr_mapping22.attr,
  757. &dev_attr_mapping23.attr,
  758. &dev_attr_mapping24.attr,
  759. &dev_attr_mapping25.attr,
  760. &dev_attr_mapping26.attr,
  761. &dev_attr_mapping27.attr,
  762. &dev_attr_mapping28.attr,
  763. &dev_attr_mapping29.attr,
  764. &dev_attr_mapping30.attr,
  765. &dev_attr_mapping31.attr,
  766. NULL,
  767. };
  768. struct attribute_group nd_mapping_attribute_group = {
  769. .is_visible = mapping_visible,
  770. .attrs = mapping_attributes,
  771. };
  772. EXPORT_SYMBOL_GPL(nd_mapping_attribute_group);
  773. int nd_blk_region_init(struct nd_region *nd_region)
  774. {
  775. struct device *dev = &nd_region->dev;
  776. struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
  777. if (!is_nd_blk(dev))
  778. return 0;
  779. if (nd_region->ndr_mappings < 1) {
  780. dev_dbg(dev, "invalid BLK region\n");
  781. return -ENXIO;
  782. }
  783. return to_nd_blk_region(dev)->enable(nvdimm_bus, dev);
  784. }
  785. /**
  786. * nd_region_acquire_lane - allocate and lock a lane
  787. * @nd_region: region id and number of lanes possible
  788. *
  789. * A lane correlates to a BLK-data-window and/or a log slot in the BTT.
  790. * We optimize for the common case where there are 256 lanes, one
  791. * per-cpu. For larger systems we need to lock to share lanes. For now
  792. * this implementation assumes the cost of maintaining an allocator for
  793. * free lanes is on the order of the lock hold time, so it implements a
  794. * static lane = cpu % num_lanes mapping.
  795. *
  796. * In the case of a BTT instance on top of a BLK namespace a lane may be
  797. * acquired recursively. We lock on the first instance.
  798. *
  799. * In the case of a BTT instance on top of PMEM, we only acquire a lane
  800. * for the BTT metadata updates.
  801. */
  802. unsigned int nd_region_acquire_lane(struct nd_region *nd_region)
  803. {
  804. unsigned int cpu, lane;
  805. cpu = get_cpu();
  806. if (nd_region->num_lanes < nr_cpu_ids) {
  807. struct nd_percpu_lane *ndl_lock, *ndl_count;
  808. lane = cpu % nd_region->num_lanes;
  809. ndl_count = per_cpu_ptr(nd_region->lane, cpu);
  810. ndl_lock = per_cpu_ptr(nd_region->lane, lane);
  811. if (ndl_count->count++ == 0)
  812. spin_lock(&ndl_lock->lock);
  813. } else
  814. lane = cpu;
  815. return lane;
  816. }
  817. EXPORT_SYMBOL(nd_region_acquire_lane);
  818. void nd_region_release_lane(struct nd_region *nd_region, unsigned int lane)
  819. {
  820. if (nd_region->num_lanes < nr_cpu_ids) {
  821. unsigned int cpu = get_cpu();
  822. struct nd_percpu_lane *ndl_lock, *ndl_count;
  823. ndl_count = per_cpu_ptr(nd_region->lane, cpu);
  824. ndl_lock = per_cpu_ptr(nd_region->lane, lane);
  825. if (--ndl_count->count == 0)
  826. spin_unlock(&ndl_lock->lock);
  827. put_cpu();
  828. }
  829. put_cpu();
  830. }
  831. EXPORT_SYMBOL(nd_region_release_lane);
  832. static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
  833. struct nd_region_desc *ndr_desc, struct device_type *dev_type,
  834. const char *caller)
  835. {
  836. struct nd_region *nd_region;
  837. struct device *dev;
  838. void *region_buf;
  839. unsigned int i;
  840. int ro = 0;
  841. for (i = 0; i < ndr_desc->num_mappings; i++) {
  842. struct nd_mapping_desc *mapping = &ndr_desc->mapping[i];
  843. struct nvdimm *nvdimm = mapping->nvdimm;
  844. if ((mapping->start | mapping->size) % SZ_4K) {
  845. dev_err(&nvdimm_bus->dev, "%s: %s mapping%d is not 4K aligned\n",
  846. caller, dev_name(&nvdimm->dev), i);
  847. return NULL;
  848. }
  849. if (test_bit(NDD_UNARMED, &nvdimm->flags))
  850. ro = 1;
  851. }
  852. if (dev_type == &nd_blk_device_type) {
  853. struct nd_blk_region_desc *ndbr_desc;
  854. struct nd_blk_region *ndbr;
  855. ndbr_desc = to_blk_region_desc(ndr_desc);
  856. ndbr = kzalloc(sizeof(*ndbr) + sizeof(struct nd_mapping)
  857. * ndr_desc->num_mappings,
  858. GFP_KERNEL);
  859. if (ndbr) {
  860. nd_region = &ndbr->nd_region;
  861. ndbr->enable = ndbr_desc->enable;
  862. ndbr->do_io = ndbr_desc->do_io;
  863. }
  864. region_buf = ndbr;
  865. } else {
  866. nd_region = kzalloc(sizeof(struct nd_region)
  867. + sizeof(struct nd_mapping)
  868. * ndr_desc->num_mappings,
  869. GFP_KERNEL);
  870. region_buf = nd_region;
  871. }
  872. if (!region_buf)
  873. return NULL;
  874. nd_region->id = ida_simple_get(&region_ida, 0, 0, GFP_KERNEL);
  875. if (nd_region->id < 0)
  876. goto err_id;
  877. nd_region->lane = alloc_percpu(struct nd_percpu_lane);
  878. if (!nd_region->lane)
  879. goto err_percpu;
  880. for (i = 0; i < nr_cpu_ids; i++) {
  881. struct nd_percpu_lane *ndl;
  882. ndl = per_cpu_ptr(nd_region->lane, i);
  883. spin_lock_init(&ndl->lock);
  884. ndl->count = 0;
  885. }
  886. for (i = 0; i < ndr_desc->num_mappings; i++) {
  887. struct nd_mapping_desc *mapping = &ndr_desc->mapping[i];
  888. struct nvdimm *nvdimm = mapping->nvdimm;
  889. nd_region->mapping[i].nvdimm = nvdimm;
  890. nd_region->mapping[i].start = mapping->start;
  891. nd_region->mapping[i].size = mapping->size;
  892. nd_region->mapping[i].position = mapping->position;
  893. INIT_LIST_HEAD(&nd_region->mapping[i].labels);
  894. mutex_init(&nd_region->mapping[i].lock);
  895. get_device(&nvdimm->dev);
  896. }
  897. nd_region->ndr_mappings = ndr_desc->num_mappings;
  898. nd_region->provider_data = ndr_desc->provider_data;
  899. nd_region->nd_set = ndr_desc->nd_set;
  900. nd_region->num_lanes = ndr_desc->num_lanes;
  901. nd_region->flags = ndr_desc->flags;
  902. nd_region->ro = ro;
  903. nd_region->numa_node = ndr_desc->numa_node;
  904. ida_init(&nd_region->ns_ida);
  905. ida_init(&nd_region->btt_ida);
  906. ida_init(&nd_region->pfn_ida);
  907. ida_init(&nd_region->dax_ida);
  908. dev = &nd_region->dev;
  909. dev_set_name(dev, "region%d", nd_region->id);
  910. dev->parent = &nvdimm_bus->dev;
  911. dev->type = dev_type;
  912. dev->groups = ndr_desc->attr_groups;
  913. dev->of_node = ndr_desc->of_node;
  914. nd_region->ndr_size = resource_size(ndr_desc->res);
  915. nd_region->ndr_start = ndr_desc->res->start;
  916. nd_device_register(dev);
  917. return nd_region;
  918. err_percpu:
  919. ida_simple_remove(&region_ida, nd_region->id);
  920. err_id:
  921. kfree(region_buf);
  922. return NULL;
  923. }
  924. struct nd_region *nvdimm_pmem_region_create(struct nvdimm_bus *nvdimm_bus,
  925. struct nd_region_desc *ndr_desc)
  926. {
  927. ndr_desc->num_lanes = ND_MAX_LANES;
  928. return nd_region_create(nvdimm_bus, ndr_desc, &nd_pmem_device_type,
  929. __func__);
  930. }
  931. EXPORT_SYMBOL_GPL(nvdimm_pmem_region_create);
  932. struct nd_region *nvdimm_blk_region_create(struct nvdimm_bus *nvdimm_bus,
  933. struct nd_region_desc *ndr_desc)
  934. {
  935. if (ndr_desc->num_mappings > 1)
  936. return NULL;
  937. ndr_desc->num_lanes = min(ndr_desc->num_lanes, ND_MAX_LANES);
  938. return nd_region_create(nvdimm_bus, ndr_desc, &nd_blk_device_type,
  939. __func__);
  940. }
  941. EXPORT_SYMBOL_GPL(nvdimm_blk_region_create);
  942. struct nd_region *nvdimm_volatile_region_create(struct nvdimm_bus *nvdimm_bus,
  943. struct nd_region_desc *ndr_desc)
  944. {
  945. ndr_desc->num_lanes = ND_MAX_LANES;
  946. return nd_region_create(nvdimm_bus, ndr_desc, &nd_volatile_device_type,
  947. __func__);
  948. }
  949. EXPORT_SYMBOL_GPL(nvdimm_volatile_region_create);
  950. /**
  951. * nvdimm_flush - flush any posted write queues between the cpu and pmem media
  952. * @nd_region: blk or interleaved pmem region
  953. */
  954. void nvdimm_flush(struct nd_region *nd_region)
  955. {
  956. struct nd_region_data *ndrd = dev_get_drvdata(&nd_region->dev);
  957. int i, idx;
  958. /*
  959. * Try to encourage some diversity in flush hint addresses
  960. * across cpus assuming a limited number of flush hints.
  961. */
  962. idx = this_cpu_read(flush_idx);
  963. idx = this_cpu_add_return(flush_idx, hash_32(current->pid + idx, 8));
  964. /*
  965. * The first wmb() is needed to 'sfence' all previous writes
  966. * such that they are architecturally visible for the platform
  967. * buffer flush. Note that we've already arranged for pmem
  968. * writes to avoid the cache via memcpy_flushcache(). The final
  969. * wmb() ensures ordering for the NVDIMM flush write.
  970. */
  971. wmb();
  972. for (i = 0; i < nd_region->ndr_mappings; i++)
  973. if (ndrd_get_flush_wpq(ndrd, i, 0))
  974. writeq(1, ndrd_get_flush_wpq(ndrd, i, idx));
  975. wmb();
  976. }
  977. EXPORT_SYMBOL_GPL(nvdimm_flush);
  978. /**
  979. * nvdimm_has_flush - determine write flushing requirements
  980. * @nd_region: blk or interleaved pmem region
  981. *
  982. * Returns 1 if writes require flushing
  983. * Returns 0 if writes do not require flushing
  984. * Returns -ENXIO if flushing capability can not be determined
  985. */
  986. int nvdimm_has_flush(struct nd_region *nd_region)
  987. {
  988. int i;
  989. /* no nvdimm or pmem api == flushing capability unknown */
  990. if (nd_region->ndr_mappings == 0
  991. || !IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API))
  992. return -ENXIO;
  993. for (i = 0; i < nd_region->ndr_mappings; i++) {
  994. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  995. struct nvdimm *nvdimm = nd_mapping->nvdimm;
  996. /* flush hints present / available */
  997. if (nvdimm->num_flush)
  998. return 1;
  999. }
  1000. /*
  1001. * The platform defines dimm devices without hints, assume
  1002. * platform persistence mechanism like ADR
  1003. */
  1004. return 0;
  1005. }
  1006. EXPORT_SYMBOL_GPL(nvdimm_has_flush);
  1007. int nvdimm_has_cache(struct nd_region *nd_region)
  1008. {
  1009. return is_nd_pmem(&nd_region->dev) &&
  1010. !test_bit(ND_REGION_PERSIST_CACHE, &nd_region->flags);
  1011. }
  1012. EXPORT_SYMBOL_GPL(nvdimm_has_cache);
  1013. struct conflict_context {
  1014. struct nd_region *nd_region;
  1015. resource_size_t start, size;
  1016. };
  1017. static int region_conflict(struct device *dev, void *data)
  1018. {
  1019. struct nd_region *nd_region;
  1020. struct conflict_context *ctx = data;
  1021. resource_size_t res_end, region_end, region_start;
  1022. if (!is_memory(dev))
  1023. return 0;
  1024. nd_region = to_nd_region(dev);
  1025. if (nd_region == ctx->nd_region)
  1026. return 0;
  1027. res_end = ctx->start + ctx->size;
  1028. region_start = nd_region->ndr_start;
  1029. region_end = region_start + nd_region->ndr_size;
  1030. if (ctx->start >= region_start && ctx->start < region_end)
  1031. return -EBUSY;
  1032. if (res_end > region_start && res_end <= region_end)
  1033. return -EBUSY;
  1034. return 0;
  1035. }
  1036. int nd_region_conflict(struct nd_region *nd_region, resource_size_t start,
  1037. resource_size_t size)
  1038. {
  1039. struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev);
  1040. struct conflict_context ctx = {
  1041. .nd_region = nd_region,
  1042. .start = start,
  1043. .size = size,
  1044. };
  1045. return device_for_each_child(&nvdimm_bus->dev, &ctx, region_conflict);
  1046. }
  1047. void __exit nd_region_devs_exit(void)
  1048. {
  1049. ida_destroy(&region_ida);
  1050. }