Commit | Line | Data |
---|---|---|
1f7df6f8 DW |
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 | */ | |
eaf96153 DW |
13 | #include <linux/scatterlist.h> |
14 | #include <linux/sched.h> | |
1f7df6f8 | 15 | #include <linux/slab.h> |
eaf96153 | 16 | #include <linux/sort.h> |
1f7df6f8 | 17 | #include <linux/io.h> |
bf9bccc1 | 18 | #include <linux/nd.h> |
1f7df6f8 DW |
19 | #include "nd-core.h" |
20 | #include "nd.h" | |
21 | ||
22 | static DEFINE_IDA(region_ida); | |
23 | ||
24 | static void nd_region_release(struct device *dev) | |
25 | { | |
26 | struct nd_region *nd_region = to_nd_region(dev); | |
27 | u16 i; | |
28 | ||
29 | for (i = 0; i < nd_region->ndr_mappings; i++) { | |
30 | struct nd_mapping *nd_mapping = &nd_region->mapping[i]; | |
31 | struct nvdimm *nvdimm = nd_mapping->nvdimm; | |
32 | ||
33 | put_device(&nvdimm->dev); | |
34 | } | |
35 | ida_simple_remove(®ion_ida, nd_region->id); | |
36 | kfree(nd_region); | |
37 | } | |
38 | ||
39 | static struct device_type nd_blk_device_type = { | |
40 | .name = "nd_blk", | |
41 | .release = nd_region_release, | |
42 | }; | |
43 | ||
44 | static struct device_type nd_pmem_device_type = { | |
45 | .name = "nd_pmem", | |
46 | .release = nd_region_release, | |
47 | }; | |
48 | ||
49 | static struct device_type nd_volatile_device_type = { | |
50 | .name = "nd_volatile", | |
51 | .release = nd_region_release, | |
52 | }; | |
53 | ||
3d88002e | 54 | bool is_nd_pmem(struct device *dev) |
1f7df6f8 DW |
55 | { |
56 | return dev ? dev->type == &nd_pmem_device_type : false; | |
57 | } | |
58 | ||
3d88002e DW |
59 | bool is_nd_blk(struct device *dev) |
60 | { | |
61 | return dev ? dev->type == &nd_blk_device_type : false; | |
62 | } | |
63 | ||
1f7df6f8 DW |
64 | struct nd_region *to_nd_region(struct device *dev) |
65 | { | |
66 | struct nd_region *nd_region = container_of(dev, struct nd_region, dev); | |
67 | ||
68 | WARN_ON(dev->type->release != nd_region_release); | |
69 | return nd_region; | |
70 | } | |
71 | EXPORT_SYMBOL_GPL(to_nd_region); | |
72 | ||
3d88002e DW |
73 | /** |
74 | * nd_region_to_nstype() - region to an integer namespace type | |
75 | * @nd_region: region-device to interrogate | |
76 | * | |
77 | * This is the 'nstype' attribute of a region as well, an input to the | |
78 | * MODALIAS for namespace devices, and bit number for a nvdimm_bus to match | |
79 | * namespace devices with namespace drivers. | |
80 | */ | |
81 | int nd_region_to_nstype(struct nd_region *nd_region) | |
82 | { | |
83 | if (is_nd_pmem(&nd_region->dev)) { | |
84 | u16 i, alias; | |
85 | ||
86 | for (i = 0, alias = 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 | ||
90 | if (nvdimm->flags & NDD_ALIASING) | |
91 | alias++; | |
92 | } | |
93 | if (alias) | |
94 | return ND_DEVICE_NAMESPACE_PMEM; | |
95 | else | |
96 | return ND_DEVICE_NAMESPACE_IO; | |
97 | } else if (is_nd_blk(&nd_region->dev)) { | |
98 | return ND_DEVICE_NAMESPACE_BLK; | |
99 | } | |
100 | ||
101 | return 0; | |
102 | } | |
bf9bccc1 DW |
103 | EXPORT_SYMBOL(nd_region_to_nstype); |
104 | ||
105 | static int is_uuid_busy(struct device *dev, void *data) | |
106 | { | |
107 | struct nd_region *nd_region = to_nd_region(dev->parent); | |
108 | u8 *uuid = data; | |
109 | ||
110 | switch (nd_region_to_nstype(nd_region)) { | |
111 | case ND_DEVICE_NAMESPACE_PMEM: { | |
112 | struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev); | |
113 | ||
114 | if (!nspm->uuid) | |
115 | break; | |
116 | if (memcmp(uuid, nspm->uuid, NSLABEL_UUID_LEN) == 0) | |
117 | return -EBUSY; | |
118 | break; | |
119 | } | |
120 | case ND_DEVICE_NAMESPACE_BLK: { | |
1b40e09a DW |
121 | struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev); |
122 | ||
123 | if (!nsblk->uuid) | |
124 | break; | |
125 | if (memcmp(uuid, nsblk->uuid, NSLABEL_UUID_LEN) == 0) | |
126 | return -EBUSY; | |
bf9bccc1 DW |
127 | break; |
128 | } | |
129 | default: | |
130 | break; | |
131 | } | |
132 | ||
133 | return 0; | |
134 | } | |
135 | ||
136 | static int is_namespace_uuid_busy(struct device *dev, void *data) | |
137 | { | |
138 | if (is_nd_pmem(dev) || is_nd_blk(dev)) | |
139 | return device_for_each_child(dev, data, is_uuid_busy); | |
140 | return 0; | |
141 | } | |
142 | ||
143 | /** | |
144 | * nd_is_uuid_unique - verify that no other namespace has @uuid | |
145 | * @dev: any device on a nvdimm_bus | |
146 | * @uuid: uuid to check | |
147 | */ | |
148 | bool nd_is_uuid_unique(struct device *dev, u8 *uuid) | |
149 | { | |
150 | struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); | |
151 | ||
152 | if (!nvdimm_bus) | |
153 | return false; | |
154 | WARN_ON_ONCE(!is_nvdimm_bus_locked(&nvdimm_bus->dev)); | |
155 | if (device_for_each_child(&nvdimm_bus->dev, uuid, | |
156 | is_namespace_uuid_busy) != 0) | |
157 | return false; | |
158 | return true; | |
159 | } | |
3d88002e | 160 | |
1f7df6f8 DW |
161 | static ssize_t size_show(struct device *dev, |
162 | struct device_attribute *attr, char *buf) | |
163 | { | |
164 | struct nd_region *nd_region = to_nd_region(dev); | |
165 | unsigned long long size = 0; | |
166 | ||
167 | if (is_nd_pmem(dev)) { | |
168 | size = nd_region->ndr_size; | |
169 | } else if (nd_region->ndr_mappings == 1) { | |
170 | struct nd_mapping *nd_mapping = &nd_region->mapping[0]; | |
171 | ||
172 | size = nd_mapping->size; | |
173 | } | |
174 | ||
175 | return sprintf(buf, "%llu\n", size); | |
176 | } | |
177 | static DEVICE_ATTR_RO(size); | |
178 | ||
179 | static ssize_t mappings_show(struct device *dev, | |
180 | struct device_attribute *attr, char *buf) | |
181 | { | |
182 | struct nd_region *nd_region = to_nd_region(dev); | |
183 | ||
184 | return sprintf(buf, "%d\n", nd_region->ndr_mappings); | |
185 | } | |
186 | static DEVICE_ATTR_RO(mappings); | |
187 | ||
3d88002e DW |
188 | static ssize_t nstype_show(struct device *dev, |
189 | struct device_attribute *attr, char *buf) | |
190 | { | |
191 | struct nd_region *nd_region = to_nd_region(dev); | |
192 | ||
193 | return sprintf(buf, "%d\n", nd_region_to_nstype(nd_region)); | |
194 | } | |
195 | static DEVICE_ATTR_RO(nstype); | |
196 | ||
eaf96153 DW |
197 | static ssize_t set_cookie_show(struct device *dev, |
198 | struct device_attribute *attr, char *buf) | |
199 | { | |
200 | struct nd_region *nd_region = to_nd_region(dev); | |
201 | struct nd_interleave_set *nd_set = nd_region->nd_set; | |
202 | ||
203 | if (is_nd_pmem(dev) && nd_set) | |
204 | /* pass, should be precluded by region_visible */; | |
205 | else | |
206 | return -ENXIO; | |
207 | ||
208 | return sprintf(buf, "%#llx\n", nd_set->cookie); | |
209 | } | |
210 | static DEVICE_ATTR_RO(set_cookie); | |
211 | ||
bf9bccc1 DW |
212 | resource_size_t nd_region_available_dpa(struct nd_region *nd_region) |
213 | { | |
214 | resource_size_t blk_max_overlap = 0, available, overlap; | |
215 | int i; | |
216 | ||
217 | WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); | |
218 | ||
219 | retry: | |
220 | available = 0; | |
221 | overlap = blk_max_overlap; | |
222 | for (i = 0; i < nd_region->ndr_mappings; i++) { | |
223 | struct nd_mapping *nd_mapping = &nd_region->mapping[i]; | |
224 | struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); | |
225 | ||
226 | /* if a dimm is disabled the available capacity is zero */ | |
227 | if (!ndd) | |
228 | return 0; | |
229 | ||
230 | if (is_nd_pmem(&nd_region->dev)) { | |
231 | available += nd_pmem_available_dpa(nd_region, | |
232 | nd_mapping, &overlap); | |
233 | if (overlap > blk_max_overlap) { | |
234 | blk_max_overlap = overlap; | |
235 | goto retry; | |
236 | } | |
237 | } else if (is_nd_blk(&nd_region->dev)) { | |
1b40e09a | 238 | available += nd_blk_available_dpa(nd_mapping); |
bf9bccc1 DW |
239 | } |
240 | } | |
241 | ||
242 | return available; | |
243 | } | |
244 | ||
245 | static ssize_t available_size_show(struct device *dev, | |
246 | struct device_attribute *attr, char *buf) | |
247 | { | |
248 | struct nd_region *nd_region = to_nd_region(dev); | |
249 | unsigned long long available = 0; | |
250 | ||
251 | /* | |
252 | * Flush in-flight updates and grab a snapshot of the available | |
253 | * size. Of course, this value is potentially invalidated the | |
254 | * memory nvdimm_bus_lock() is dropped, but that's userspace's | |
255 | * problem to not race itself. | |
256 | */ | |
257 | nvdimm_bus_lock(dev); | |
258 | wait_nvdimm_bus_probe_idle(dev); | |
259 | available = nd_region_available_dpa(nd_region); | |
260 | nvdimm_bus_unlock(dev); | |
261 | ||
262 | return sprintf(buf, "%llu\n", available); | |
263 | } | |
264 | static DEVICE_ATTR_RO(available_size); | |
265 | ||
3d88002e DW |
266 | static ssize_t init_namespaces_show(struct device *dev, |
267 | struct device_attribute *attr, char *buf) | |
268 | { | |
269 | struct nd_region_namespaces *num_ns = dev_get_drvdata(dev); | |
270 | ssize_t rc; | |
271 | ||
272 | nvdimm_bus_lock(dev); | |
273 | if (num_ns) | |
274 | rc = sprintf(buf, "%d/%d\n", num_ns->active, num_ns->count); | |
275 | else | |
276 | rc = -ENXIO; | |
277 | nvdimm_bus_unlock(dev); | |
278 | ||
279 | return rc; | |
280 | } | |
281 | static DEVICE_ATTR_RO(init_namespaces); | |
282 | ||
bf9bccc1 DW |
283 | static ssize_t namespace_seed_show(struct device *dev, |
284 | struct device_attribute *attr, char *buf) | |
285 | { | |
286 | struct nd_region *nd_region = to_nd_region(dev); | |
287 | ssize_t rc; | |
288 | ||
289 | nvdimm_bus_lock(dev); | |
290 | if (nd_region->ns_seed) | |
291 | rc = sprintf(buf, "%s\n", dev_name(nd_region->ns_seed)); | |
292 | else | |
293 | rc = sprintf(buf, "\n"); | |
294 | nvdimm_bus_unlock(dev); | |
295 | return rc; | |
296 | } | |
297 | static DEVICE_ATTR_RO(namespace_seed); | |
298 | ||
1f7df6f8 DW |
299 | static struct attribute *nd_region_attributes[] = { |
300 | &dev_attr_size.attr, | |
3d88002e | 301 | &dev_attr_nstype.attr, |
1f7df6f8 | 302 | &dev_attr_mappings.attr, |
eaf96153 | 303 | &dev_attr_set_cookie.attr, |
bf9bccc1 DW |
304 | &dev_attr_available_size.attr, |
305 | &dev_attr_namespace_seed.attr, | |
3d88002e | 306 | &dev_attr_init_namespaces.attr, |
1f7df6f8 DW |
307 | NULL, |
308 | }; | |
309 | ||
eaf96153 DW |
310 | static umode_t region_visible(struct kobject *kobj, struct attribute *a, int n) |
311 | { | |
312 | struct device *dev = container_of(kobj, typeof(*dev), kobj); | |
313 | struct nd_region *nd_region = to_nd_region(dev); | |
314 | struct nd_interleave_set *nd_set = nd_region->nd_set; | |
bf9bccc1 | 315 | int type = nd_region_to_nstype(nd_region); |
eaf96153 | 316 | |
bf9bccc1 DW |
317 | if (a != &dev_attr_set_cookie.attr |
318 | && a != &dev_attr_available_size.attr) | |
eaf96153 DW |
319 | return a->mode; |
320 | ||
bf9bccc1 DW |
321 | if ((type == ND_DEVICE_NAMESPACE_PMEM |
322 | || type == ND_DEVICE_NAMESPACE_BLK) | |
323 | && a == &dev_attr_available_size.attr) | |
324 | return a->mode; | |
325 | else if (is_nd_pmem(dev) && nd_set) | |
326 | return a->mode; | |
eaf96153 DW |
327 | |
328 | return 0; | |
329 | } | |
330 | ||
1f7df6f8 DW |
331 | struct attribute_group nd_region_attribute_group = { |
332 | .attrs = nd_region_attributes, | |
eaf96153 | 333 | .is_visible = region_visible, |
1f7df6f8 DW |
334 | }; |
335 | EXPORT_SYMBOL_GPL(nd_region_attribute_group); | |
336 | ||
bf9bccc1 DW |
337 | u64 nd_region_interleave_set_cookie(struct nd_region *nd_region) |
338 | { | |
339 | struct nd_interleave_set *nd_set = nd_region->nd_set; | |
340 | ||
341 | if (nd_set) | |
342 | return nd_set->cookie; | |
343 | return 0; | |
344 | } | |
345 | ||
eaf96153 DW |
346 | /* |
347 | * Upon successful probe/remove, take/release a reference on the | |
348 | * associated interleave set (if present) | |
349 | */ | |
350 | static void nd_region_notify_driver_action(struct nvdimm_bus *nvdimm_bus, | |
351 | struct device *dev, bool probe) | |
352 | { | |
bf9bccc1 | 353 | if (!probe && (is_nd_pmem(dev) || is_nd_blk(dev))) { |
eaf96153 DW |
354 | struct nd_region *nd_region = to_nd_region(dev); |
355 | int i; | |
356 | ||
357 | for (i = 0; i < nd_region->ndr_mappings; i++) { | |
358 | struct nd_mapping *nd_mapping = &nd_region->mapping[i]; | |
bf9bccc1 | 359 | struct nvdimm_drvdata *ndd = nd_mapping->ndd; |
eaf96153 DW |
360 | struct nvdimm *nvdimm = nd_mapping->nvdimm; |
361 | ||
bf9bccc1 DW |
362 | kfree(nd_mapping->labels); |
363 | nd_mapping->labels = NULL; | |
364 | put_ndd(ndd); | |
365 | nd_mapping->ndd = NULL; | |
366 | atomic_dec(&nvdimm->busy); | |
eaf96153 | 367 | } |
1b40e09a DW |
368 | } else if (dev->parent && is_nd_blk(dev->parent) && probe) { |
369 | struct nd_region *nd_region = to_nd_region(dev->parent); | |
370 | ||
371 | nvdimm_bus_lock(dev); | |
372 | if (nd_region->ns_seed == dev) | |
373 | nd_region_create_blk_seed(nd_region); | |
374 | nvdimm_bus_unlock(dev); | |
eaf96153 DW |
375 | } |
376 | } | |
377 | ||
378 | void nd_region_probe_success(struct nvdimm_bus *nvdimm_bus, struct device *dev) | |
379 | { | |
380 | nd_region_notify_driver_action(nvdimm_bus, dev, true); | |
381 | } | |
382 | ||
383 | void nd_region_disable(struct nvdimm_bus *nvdimm_bus, struct device *dev) | |
384 | { | |
385 | nd_region_notify_driver_action(nvdimm_bus, dev, false); | |
386 | } | |
387 | ||
1f7df6f8 DW |
388 | static ssize_t mappingN(struct device *dev, char *buf, int n) |
389 | { | |
390 | struct nd_region *nd_region = to_nd_region(dev); | |
391 | struct nd_mapping *nd_mapping; | |
392 | struct nvdimm *nvdimm; | |
393 | ||
394 | if (n >= nd_region->ndr_mappings) | |
395 | return -ENXIO; | |
396 | nd_mapping = &nd_region->mapping[n]; | |
397 | nvdimm = nd_mapping->nvdimm; | |
398 | ||
399 | return sprintf(buf, "%s,%llu,%llu\n", dev_name(&nvdimm->dev), | |
400 | nd_mapping->start, nd_mapping->size); | |
401 | } | |
402 | ||
403 | #define REGION_MAPPING(idx) \ | |
404 | static ssize_t mapping##idx##_show(struct device *dev, \ | |
405 | struct device_attribute *attr, char *buf) \ | |
406 | { \ | |
407 | return mappingN(dev, buf, idx); \ | |
408 | } \ | |
409 | static DEVICE_ATTR_RO(mapping##idx) | |
410 | ||
411 | /* | |
412 | * 32 should be enough for a while, even in the presence of socket | |
413 | * interleave a 32-way interleave set is a degenerate case. | |
414 | */ | |
415 | REGION_MAPPING(0); | |
416 | REGION_MAPPING(1); | |
417 | REGION_MAPPING(2); | |
418 | REGION_MAPPING(3); | |
419 | REGION_MAPPING(4); | |
420 | REGION_MAPPING(5); | |
421 | REGION_MAPPING(6); | |
422 | REGION_MAPPING(7); | |
423 | REGION_MAPPING(8); | |
424 | REGION_MAPPING(9); | |
425 | REGION_MAPPING(10); | |
426 | REGION_MAPPING(11); | |
427 | REGION_MAPPING(12); | |
428 | REGION_MAPPING(13); | |
429 | REGION_MAPPING(14); | |
430 | REGION_MAPPING(15); | |
431 | REGION_MAPPING(16); | |
432 | REGION_MAPPING(17); | |
433 | REGION_MAPPING(18); | |
434 | REGION_MAPPING(19); | |
435 | REGION_MAPPING(20); | |
436 | REGION_MAPPING(21); | |
437 | REGION_MAPPING(22); | |
438 | REGION_MAPPING(23); | |
439 | REGION_MAPPING(24); | |
440 | REGION_MAPPING(25); | |
441 | REGION_MAPPING(26); | |
442 | REGION_MAPPING(27); | |
443 | REGION_MAPPING(28); | |
444 | REGION_MAPPING(29); | |
445 | REGION_MAPPING(30); | |
446 | REGION_MAPPING(31); | |
447 | ||
448 | static umode_t mapping_visible(struct kobject *kobj, struct attribute *a, int n) | |
449 | { | |
450 | struct device *dev = container_of(kobj, struct device, kobj); | |
451 | struct nd_region *nd_region = to_nd_region(dev); | |
452 | ||
453 | if (n < nd_region->ndr_mappings) | |
454 | return a->mode; | |
455 | return 0; | |
456 | } | |
457 | ||
458 | static struct attribute *mapping_attributes[] = { | |
459 | &dev_attr_mapping0.attr, | |
460 | &dev_attr_mapping1.attr, | |
461 | &dev_attr_mapping2.attr, | |
462 | &dev_attr_mapping3.attr, | |
463 | &dev_attr_mapping4.attr, | |
464 | &dev_attr_mapping5.attr, | |
465 | &dev_attr_mapping6.attr, | |
466 | &dev_attr_mapping7.attr, | |
467 | &dev_attr_mapping8.attr, | |
468 | &dev_attr_mapping9.attr, | |
469 | &dev_attr_mapping10.attr, | |
470 | &dev_attr_mapping11.attr, | |
471 | &dev_attr_mapping12.attr, | |
472 | &dev_attr_mapping13.attr, | |
473 | &dev_attr_mapping14.attr, | |
474 | &dev_attr_mapping15.attr, | |
475 | &dev_attr_mapping16.attr, | |
476 | &dev_attr_mapping17.attr, | |
477 | &dev_attr_mapping18.attr, | |
478 | &dev_attr_mapping19.attr, | |
479 | &dev_attr_mapping20.attr, | |
480 | &dev_attr_mapping21.attr, | |
481 | &dev_attr_mapping22.attr, | |
482 | &dev_attr_mapping23.attr, | |
483 | &dev_attr_mapping24.attr, | |
484 | &dev_attr_mapping25.attr, | |
485 | &dev_attr_mapping26.attr, | |
486 | &dev_attr_mapping27.attr, | |
487 | &dev_attr_mapping28.attr, | |
488 | &dev_attr_mapping29.attr, | |
489 | &dev_attr_mapping30.attr, | |
490 | &dev_attr_mapping31.attr, | |
491 | NULL, | |
492 | }; | |
493 | ||
494 | struct attribute_group nd_mapping_attribute_group = { | |
495 | .is_visible = mapping_visible, | |
496 | .attrs = mapping_attributes, | |
497 | }; | |
498 | EXPORT_SYMBOL_GPL(nd_mapping_attribute_group); | |
499 | ||
500 | void *nd_region_provider_data(struct nd_region *nd_region) | |
501 | { | |
502 | return nd_region->provider_data; | |
503 | } | |
504 | EXPORT_SYMBOL_GPL(nd_region_provider_data); | |
505 | ||
506 | static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus, | |
507 | struct nd_region_desc *ndr_desc, struct device_type *dev_type, | |
508 | const char *caller) | |
509 | { | |
510 | struct nd_region *nd_region; | |
511 | struct device *dev; | |
512 | u16 i; | |
513 | ||
514 | for (i = 0; i < ndr_desc->num_mappings; i++) { | |
515 | struct nd_mapping *nd_mapping = &ndr_desc->nd_mapping[i]; | |
516 | struct nvdimm *nvdimm = nd_mapping->nvdimm; | |
517 | ||
518 | if ((nd_mapping->start | nd_mapping->size) % SZ_4K) { | |
519 | dev_err(&nvdimm_bus->dev, "%s: %s mapping%d is not 4K aligned\n", | |
520 | caller, dev_name(&nvdimm->dev), i); | |
521 | ||
522 | return NULL; | |
523 | } | |
524 | } | |
525 | ||
526 | nd_region = kzalloc(sizeof(struct nd_region) | |
527 | + sizeof(struct nd_mapping) * ndr_desc->num_mappings, | |
528 | GFP_KERNEL); | |
529 | if (!nd_region) | |
530 | return NULL; | |
531 | nd_region->id = ida_simple_get(®ion_ida, 0, 0, GFP_KERNEL); | |
532 | if (nd_region->id < 0) { | |
533 | kfree(nd_region); | |
534 | return NULL; | |
535 | } | |
536 | ||
537 | memcpy(nd_region->mapping, ndr_desc->nd_mapping, | |
538 | sizeof(struct nd_mapping) * ndr_desc->num_mappings); | |
539 | for (i = 0; i < ndr_desc->num_mappings; i++) { | |
540 | struct nd_mapping *nd_mapping = &ndr_desc->nd_mapping[i]; | |
541 | struct nvdimm *nvdimm = nd_mapping->nvdimm; | |
542 | ||
543 | get_device(&nvdimm->dev); | |
544 | } | |
545 | nd_region->ndr_mappings = ndr_desc->num_mappings; | |
546 | nd_region->provider_data = ndr_desc->provider_data; | |
eaf96153 | 547 | nd_region->nd_set = ndr_desc->nd_set; |
1b40e09a | 548 | ida_init(&nd_region->ns_ida); |
1f7df6f8 DW |
549 | dev = &nd_region->dev; |
550 | dev_set_name(dev, "region%d", nd_region->id); | |
551 | dev->parent = &nvdimm_bus->dev; | |
552 | dev->type = dev_type; | |
553 | dev->groups = ndr_desc->attr_groups; | |
554 | nd_region->ndr_size = resource_size(ndr_desc->res); | |
555 | nd_region->ndr_start = ndr_desc->res->start; | |
556 | nd_device_register(dev); | |
557 | ||
558 | return nd_region; | |
559 | } | |
560 | ||
561 | struct nd_region *nvdimm_pmem_region_create(struct nvdimm_bus *nvdimm_bus, | |
562 | struct nd_region_desc *ndr_desc) | |
563 | { | |
564 | return nd_region_create(nvdimm_bus, ndr_desc, &nd_pmem_device_type, | |
565 | __func__); | |
566 | } | |
567 | EXPORT_SYMBOL_GPL(nvdimm_pmem_region_create); | |
568 | ||
569 | struct nd_region *nvdimm_blk_region_create(struct nvdimm_bus *nvdimm_bus, | |
570 | struct nd_region_desc *ndr_desc) | |
571 | { | |
572 | if (ndr_desc->num_mappings > 1) | |
573 | return NULL; | |
574 | return nd_region_create(nvdimm_bus, ndr_desc, &nd_blk_device_type, | |
575 | __func__); | |
576 | } | |
577 | EXPORT_SYMBOL_GPL(nvdimm_blk_region_create); | |
578 | ||
579 | struct nd_region *nvdimm_volatile_region_create(struct nvdimm_bus *nvdimm_bus, | |
580 | struct nd_region_desc *ndr_desc) | |
581 | { | |
582 | return nd_region_create(nvdimm_bus, ndr_desc, &nd_volatile_device_type, | |
583 | __func__); | |
584 | } | |
585 | EXPORT_SYMBOL_GPL(nvdimm_volatile_region_create); |