dax: enable dax in the presence of known media errors (badblocks)
[deliverable/linux.git] / drivers / nvdimm / pmem.c
1 /*
2 * Persistent Memory Driver
3 *
4 * Copyright (c) 2014-2015, Intel Corporation.
5 * Copyright (c) 2015, Christoph Hellwig <hch@lst.de>.
6 * Copyright (c) 2015, Boaz Harrosh <boaz@plexistor.com>.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 */
17
18 #include <asm/cacheflush.h>
19 #include <linux/blkdev.h>
20 #include <linux/hdreg.h>
21 #include <linux/init.h>
22 #include <linux/platform_device.h>
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/badblocks.h>
26 #include <linux/memremap.h>
27 #include <linux/vmalloc.h>
28 #include <linux/pfn_t.h>
29 #include <linux/slab.h>
30 #include <linux/pmem.h>
31 #include <linux/nd.h>
32 #include "pfn.h"
33 #include "nd.h"
34
35 struct pmem_device {
36 struct request_queue *pmem_queue;
37 struct gendisk *pmem_disk;
38 struct nd_namespace_common *ndns;
39
40 /* One contiguous memory region per device */
41 phys_addr_t phys_addr;
42 /* when non-zero this device is hosting a 'pfn' instance */
43 phys_addr_t data_offset;
44 u64 pfn_flags;
45 void __pmem *virt_addr;
46 /* immutable base size of the namespace */
47 size_t size;
48 /* trim size when namespace capacity has been section aligned */
49 u32 pfn_pad;
50 struct badblocks bb;
51 };
52
53 static bool is_bad_pmem(struct badblocks *bb, sector_t sector, unsigned int len)
54 {
55 if (bb->count) {
56 sector_t first_bad;
57 int num_bad;
58
59 return !!badblocks_check(bb, sector, len / 512, &first_bad,
60 &num_bad);
61 }
62
63 return false;
64 }
65
66 static void pmem_clear_poison(struct pmem_device *pmem, phys_addr_t offset,
67 unsigned int len)
68 {
69 struct device *dev = disk_to_dev(pmem->pmem_disk);
70 sector_t sector;
71 long cleared;
72
73 sector = (offset - pmem->data_offset) / 512;
74 cleared = nvdimm_clear_poison(dev, pmem->phys_addr + offset, len);
75
76 if (cleared > 0 && cleared / 512) {
77 dev_dbg(dev, "%s: %llx clear %ld sector%s\n",
78 __func__, (unsigned long long) sector,
79 cleared / 512, cleared / 512 > 1 ? "s" : "");
80 badblocks_clear(&pmem->bb, sector, cleared / 512);
81 }
82 invalidate_pmem(pmem->virt_addr + offset, len);
83 }
84
85 static int pmem_do_bvec(struct pmem_device *pmem, struct page *page,
86 unsigned int len, unsigned int off, int rw,
87 sector_t sector)
88 {
89 int rc = 0;
90 bool bad_pmem = false;
91 void *mem = kmap_atomic(page);
92 phys_addr_t pmem_off = sector * 512 + pmem->data_offset;
93 void __pmem *pmem_addr = pmem->virt_addr + pmem_off;
94
95 if (unlikely(is_bad_pmem(&pmem->bb, sector, len)))
96 bad_pmem = true;
97
98 if (rw == READ) {
99 if (unlikely(bad_pmem))
100 rc = -EIO;
101 else {
102 rc = memcpy_from_pmem(mem + off, pmem_addr, len);
103 flush_dcache_page(page);
104 }
105 } else {
106 /*
107 * Note that we write the data both before and after
108 * clearing poison. The write before clear poison
109 * handles situations where the latest written data is
110 * preserved and the clear poison operation simply marks
111 * the address range as valid without changing the data.
112 * In this case application software can assume that an
113 * interrupted write will either return the new good
114 * data or an error.
115 *
116 * However, if pmem_clear_poison() leaves the data in an
117 * indeterminate state we need to perform the write
118 * after clear poison.
119 */
120 flush_dcache_page(page);
121 memcpy_to_pmem(pmem_addr, mem + off, len);
122 if (unlikely(bad_pmem)) {
123 pmem_clear_poison(pmem, pmem_off, len);
124 memcpy_to_pmem(pmem_addr, mem + off, len);
125 }
126 }
127
128 kunmap_atomic(mem);
129 return rc;
130 }
131
132 static blk_qc_t pmem_make_request(struct request_queue *q, struct bio *bio)
133 {
134 int rc = 0;
135 bool do_acct;
136 unsigned long start;
137 struct bio_vec bvec;
138 struct bvec_iter iter;
139 struct block_device *bdev = bio->bi_bdev;
140 struct pmem_device *pmem = bdev->bd_disk->private_data;
141
142 do_acct = nd_iostat_start(bio, &start);
143 bio_for_each_segment(bvec, bio, iter) {
144 rc = pmem_do_bvec(pmem, bvec.bv_page, bvec.bv_len,
145 bvec.bv_offset, bio_data_dir(bio),
146 iter.bi_sector);
147 if (rc) {
148 bio->bi_error = rc;
149 break;
150 }
151 }
152 if (do_acct)
153 nd_iostat_end(bio, start);
154
155 if (bio_data_dir(bio))
156 wmb_pmem();
157
158 bio_endio(bio);
159 return BLK_QC_T_NONE;
160 }
161
162 static int pmem_rw_page(struct block_device *bdev, sector_t sector,
163 struct page *page, int rw)
164 {
165 struct pmem_device *pmem = bdev->bd_disk->private_data;
166 int rc;
167
168 rc = pmem_do_bvec(pmem, page, PAGE_SIZE, 0, rw, sector);
169 if (rw & WRITE)
170 wmb_pmem();
171
172 /*
173 * The ->rw_page interface is subtle and tricky. The core
174 * retries on any error, so we can only invoke page_endio() in
175 * the successful completion case. Otherwise, we'll see crashes
176 * caused by double completion.
177 */
178 if (rc == 0)
179 page_endio(page, rw & WRITE, 0);
180
181 return rc;
182 }
183
184 static long pmem_direct_access(struct block_device *bdev, sector_t sector,
185 void __pmem **kaddr, pfn_t *pfn, long size)
186 {
187 struct pmem_device *pmem = bdev->bd_disk->private_data;
188 resource_size_t offset = sector * 512 + pmem->data_offset;
189
190 if (unlikely(is_bad_pmem(&pmem->bb, sector, size)))
191 return -EIO;
192 *kaddr = pmem->virt_addr + offset;
193 *pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags);
194
195 /*
196 * If badblocks are present, limit known good range to the
197 * requested range.
198 */
199 if (unlikely(pmem->bb.count))
200 return size;
201 return pmem->size - pmem->pfn_pad - offset;
202 }
203
204 static const struct block_device_operations pmem_fops = {
205 .owner = THIS_MODULE,
206 .rw_page = pmem_rw_page,
207 .direct_access = pmem_direct_access,
208 .revalidate_disk = nvdimm_revalidate_disk,
209 };
210
211 static struct pmem_device *pmem_alloc(struct device *dev,
212 struct resource *res, int id)
213 {
214 struct pmem_device *pmem;
215 struct request_queue *q;
216
217 pmem = devm_kzalloc(dev, sizeof(*pmem), GFP_KERNEL);
218 if (!pmem)
219 return ERR_PTR(-ENOMEM);
220
221 pmem->phys_addr = res->start;
222 pmem->size = resource_size(res);
223 if (!arch_has_wmb_pmem())
224 dev_warn(dev, "unable to guarantee persistence of writes\n");
225
226 if (!devm_request_mem_region(dev, pmem->phys_addr, pmem->size,
227 dev_name(dev))) {
228 dev_warn(dev, "could not reserve region [0x%pa:0x%zx]\n",
229 &pmem->phys_addr, pmem->size);
230 return ERR_PTR(-EBUSY);
231 }
232
233 q = blk_alloc_queue_node(GFP_KERNEL, dev_to_node(dev));
234 if (!q)
235 return ERR_PTR(-ENOMEM);
236
237 pmem->pfn_flags = PFN_DEV;
238 if (pmem_should_map_pages(dev)) {
239 pmem->virt_addr = (void __pmem *) devm_memremap_pages(dev, res,
240 &q->q_usage_counter, NULL);
241 pmem->pfn_flags |= PFN_MAP;
242 } else
243 pmem->virt_addr = (void __pmem *) devm_memremap(dev,
244 pmem->phys_addr, pmem->size,
245 ARCH_MEMREMAP_PMEM);
246
247 if (IS_ERR(pmem->virt_addr)) {
248 blk_cleanup_queue(q);
249 return (void __force *) pmem->virt_addr;
250 }
251
252 pmem->pmem_queue = q;
253 return pmem;
254 }
255
256 static void pmem_detach_disk(struct pmem_device *pmem)
257 {
258 if (!pmem->pmem_disk)
259 return;
260
261 del_gendisk(pmem->pmem_disk);
262 put_disk(pmem->pmem_disk);
263 blk_cleanup_queue(pmem->pmem_queue);
264 }
265
266 static int pmem_attach_disk(struct device *dev,
267 struct nd_namespace_common *ndns, struct pmem_device *pmem)
268 {
269 struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
270 int nid = dev_to_node(dev);
271 struct resource bb_res;
272 struct gendisk *disk;
273
274 blk_queue_make_request(pmem->pmem_queue, pmem_make_request);
275 blk_queue_physical_block_size(pmem->pmem_queue, PAGE_SIZE);
276 blk_queue_max_hw_sectors(pmem->pmem_queue, UINT_MAX);
277 blk_queue_bounce_limit(pmem->pmem_queue, BLK_BOUNCE_ANY);
278 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, pmem->pmem_queue);
279
280 disk = alloc_disk_node(0, nid);
281 if (!disk) {
282 blk_cleanup_queue(pmem->pmem_queue);
283 return -ENOMEM;
284 }
285
286 disk->fops = &pmem_fops;
287 disk->private_data = pmem;
288 disk->queue = pmem->pmem_queue;
289 disk->flags = GENHD_FL_EXT_DEVT;
290 nvdimm_namespace_disk_name(ndns, disk->disk_name);
291 disk->driverfs_dev = dev;
292 set_capacity(disk, (pmem->size - pmem->pfn_pad - pmem->data_offset)
293 / 512);
294 pmem->pmem_disk = disk;
295 devm_exit_badblocks(dev, &pmem->bb);
296 if (devm_init_badblocks(dev, &pmem->bb))
297 return -ENOMEM;
298 bb_res.start = nsio->res.start + pmem->data_offset;
299 bb_res.end = nsio->res.end;
300 if (is_nd_pfn(dev)) {
301 struct nd_pfn *nd_pfn = to_nd_pfn(dev);
302 struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
303
304 bb_res.start += __le32_to_cpu(pfn_sb->start_pad);
305 bb_res.end -= __le32_to_cpu(pfn_sb->end_trunc);
306 }
307 nvdimm_badblocks_populate(to_nd_region(dev->parent), &pmem->bb,
308 &bb_res);
309 disk->bb = &pmem->bb;
310 add_disk(disk);
311 revalidate_disk(disk);
312
313 return 0;
314 }
315
316 static int pmem_rw_bytes(struct nd_namespace_common *ndns,
317 resource_size_t offset, void *buf, size_t size, int rw)
318 {
319 struct pmem_device *pmem = dev_get_drvdata(ndns->claim);
320
321 if (unlikely(offset + size > pmem->size)) {
322 dev_WARN_ONCE(&ndns->dev, 1, "request out of range\n");
323 return -EFAULT;
324 }
325
326 if (rw == READ) {
327 unsigned int sz_align = ALIGN(size + (offset & (512 - 1)), 512);
328
329 if (unlikely(is_bad_pmem(&pmem->bb, offset / 512, sz_align)))
330 return -EIO;
331 return memcpy_from_pmem(buf, pmem->virt_addr + offset, size);
332 } else {
333 memcpy_to_pmem(pmem->virt_addr + offset, buf, size);
334 wmb_pmem();
335 }
336
337 return 0;
338 }
339
340 static int nd_pfn_init(struct nd_pfn *nd_pfn)
341 {
342 struct nd_pfn_sb *pfn_sb = kzalloc(sizeof(*pfn_sb), GFP_KERNEL);
343 struct pmem_device *pmem = dev_get_drvdata(&nd_pfn->dev);
344 struct nd_namespace_common *ndns = nd_pfn->ndns;
345 u32 start_pad = 0, end_trunc = 0;
346 resource_size_t start, size;
347 struct nd_namespace_io *nsio;
348 struct nd_region *nd_region;
349 unsigned long npfns;
350 phys_addr_t offset;
351 u64 checksum;
352 int rc;
353
354 if (!pfn_sb)
355 return -ENOMEM;
356
357 nd_pfn->pfn_sb = pfn_sb;
358 rc = nd_pfn_validate(nd_pfn);
359 if (rc == -ENODEV)
360 /* no info block, do init */;
361 else
362 return rc;
363
364 nd_region = to_nd_region(nd_pfn->dev.parent);
365 if (nd_region->ro) {
366 dev_info(&nd_pfn->dev,
367 "%s is read-only, unable to init metadata\n",
368 dev_name(&nd_region->dev));
369 goto err;
370 }
371
372 memset(pfn_sb, 0, sizeof(*pfn_sb));
373
374 /*
375 * Check if pmem collides with 'System RAM' when section aligned and
376 * trim it accordingly
377 */
378 nsio = to_nd_namespace_io(&ndns->dev);
379 start = PHYS_SECTION_ALIGN_DOWN(nsio->res.start);
380 size = resource_size(&nsio->res);
381 if (region_intersects(start, size, IORESOURCE_SYSTEM_RAM,
382 IORES_DESC_NONE) == REGION_MIXED) {
383
384 start = nsio->res.start;
385 start_pad = PHYS_SECTION_ALIGN_UP(start) - start;
386 }
387
388 start = nsio->res.start;
389 size = PHYS_SECTION_ALIGN_UP(start + size) - start;
390 if (region_intersects(start, size, IORESOURCE_SYSTEM_RAM,
391 IORES_DESC_NONE) == REGION_MIXED) {
392 size = resource_size(&nsio->res);
393 end_trunc = start + size - PHYS_SECTION_ALIGN_DOWN(start + size);
394 }
395
396 if (start_pad + end_trunc)
397 dev_info(&nd_pfn->dev, "%s section collision, truncate %d bytes\n",
398 dev_name(&ndns->dev), start_pad + end_trunc);
399
400 /*
401 * Note, we use 64 here for the standard size of struct page,
402 * debugging options may cause it to be larger in which case the
403 * implementation will limit the pfns advertised through
404 * ->direct_access() to those that are included in the memmap.
405 */
406 start += start_pad;
407 npfns = (pmem->size - start_pad - end_trunc - SZ_8K) / SZ_4K;
408 if (nd_pfn->mode == PFN_MODE_PMEM)
409 offset = ALIGN(start + SZ_8K + 64 * npfns, nd_pfn->align)
410 - start;
411 else if (nd_pfn->mode == PFN_MODE_RAM)
412 offset = ALIGN(start + SZ_8K, nd_pfn->align) - start;
413 else
414 goto err;
415
416 if (offset + start_pad + end_trunc >= pmem->size) {
417 dev_err(&nd_pfn->dev, "%s unable to satisfy requested alignment\n",
418 dev_name(&ndns->dev));
419 goto err;
420 }
421
422 npfns = (pmem->size - offset - start_pad - end_trunc) / SZ_4K;
423 pfn_sb->mode = cpu_to_le32(nd_pfn->mode);
424 pfn_sb->dataoff = cpu_to_le64(offset);
425 pfn_sb->npfns = cpu_to_le64(npfns);
426 memcpy(pfn_sb->signature, PFN_SIG, PFN_SIG_LEN);
427 memcpy(pfn_sb->uuid, nd_pfn->uuid, 16);
428 memcpy(pfn_sb->parent_uuid, nd_dev_to_uuid(&ndns->dev), 16);
429 pfn_sb->version_major = cpu_to_le16(1);
430 pfn_sb->version_minor = cpu_to_le16(1);
431 pfn_sb->start_pad = cpu_to_le32(start_pad);
432 pfn_sb->end_trunc = cpu_to_le32(end_trunc);
433 checksum = nd_sb_checksum((struct nd_gen_sb *) pfn_sb);
434 pfn_sb->checksum = cpu_to_le64(checksum);
435
436 rc = nvdimm_write_bytes(ndns, SZ_4K, pfn_sb, sizeof(*pfn_sb));
437 if (rc)
438 goto err;
439
440 return 0;
441 err:
442 nd_pfn->pfn_sb = NULL;
443 kfree(pfn_sb);
444 return -ENXIO;
445 }
446
447 static int nvdimm_namespace_detach_pfn(struct nd_namespace_common *ndns)
448 {
449 struct nd_pfn *nd_pfn = to_nd_pfn(ndns->claim);
450 struct pmem_device *pmem;
451
452 /* free pmem disk */
453 pmem = dev_get_drvdata(&nd_pfn->dev);
454 pmem_detach_disk(pmem);
455
456 /* release nd_pfn resources */
457 kfree(nd_pfn->pfn_sb);
458 nd_pfn->pfn_sb = NULL;
459
460 return 0;
461 }
462
463 /*
464 * We hotplug memory at section granularity, pad the reserved area from
465 * the previous section base to the namespace base address.
466 */
467 static unsigned long init_altmap_base(resource_size_t base)
468 {
469 unsigned long base_pfn = PHYS_PFN(base);
470
471 return PFN_SECTION_ALIGN_DOWN(base_pfn);
472 }
473
474 static unsigned long init_altmap_reserve(resource_size_t base)
475 {
476 unsigned long reserve = PHYS_PFN(SZ_8K);
477 unsigned long base_pfn = PHYS_PFN(base);
478
479 reserve += base_pfn - PFN_SECTION_ALIGN_DOWN(base_pfn);
480 return reserve;
481 }
482
483 static int __nvdimm_namespace_attach_pfn(struct nd_pfn *nd_pfn)
484 {
485 int rc;
486 struct resource res;
487 struct request_queue *q;
488 struct pmem_device *pmem;
489 struct vmem_altmap *altmap;
490 struct device *dev = &nd_pfn->dev;
491 struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
492 struct nd_namespace_common *ndns = nd_pfn->ndns;
493 u32 start_pad = __le32_to_cpu(pfn_sb->start_pad);
494 u32 end_trunc = __le32_to_cpu(pfn_sb->end_trunc);
495 struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
496 resource_size_t base = nsio->res.start + start_pad;
497 struct vmem_altmap __altmap = {
498 .base_pfn = init_altmap_base(base),
499 .reserve = init_altmap_reserve(base),
500 };
501
502 pmem = dev_get_drvdata(dev);
503 pmem->data_offset = le64_to_cpu(pfn_sb->dataoff);
504 pmem->pfn_pad = start_pad + end_trunc;
505 nd_pfn->mode = le32_to_cpu(nd_pfn->pfn_sb->mode);
506 if (nd_pfn->mode == PFN_MODE_RAM) {
507 if (pmem->data_offset < SZ_8K)
508 return -EINVAL;
509 nd_pfn->npfns = le64_to_cpu(pfn_sb->npfns);
510 altmap = NULL;
511 } else if (nd_pfn->mode == PFN_MODE_PMEM) {
512 nd_pfn->npfns = (pmem->size - pmem->pfn_pad - pmem->data_offset)
513 / PAGE_SIZE;
514 if (le64_to_cpu(nd_pfn->pfn_sb->npfns) > nd_pfn->npfns)
515 dev_info(&nd_pfn->dev,
516 "number of pfns truncated from %lld to %ld\n",
517 le64_to_cpu(nd_pfn->pfn_sb->npfns),
518 nd_pfn->npfns);
519 altmap = & __altmap;
520 altmap->free = PHYS_PFN(pmem->data_offset - SZ_8K);
521 altmap->alloc = 0;
522 } else {
523 rc = -ENXIO;
524 goto err;
525 }
526
527 /* establish pfn range for lookup, and switch to direct map */
528 q = pmem->pmem_queue;
529 memcpy(&res, &nsio->res, sizeof(res));
530 res.start += start_pad;
531 res.end -= end_trunc;
532 devm_memunmap(dev, (void __force *) pmem->virt_addr);
533 pmem->virt_addr = (void __pmem *) devm_memremap_pages(dev, &res,
534 &q->q_usage_counter, altmap);
535 pmem->pfn_flags |= PFN_MAP;
536 if (IS_ERR(pmem->virt_addr)) {
537 rc = PTR_ERR(pmem->virt_addr);
538 goto err;
539 }
540
541 /* attach pmem disk in "pfn-mode" */
542 rc = pmem_attach_disk(dev, ndns, pmem);
543 if (rc)
544 goto err;
545
546 return rc;
547 err:
548 nvdimm_namespace_detach_pfn(ndns);
549 return rc;
550
551 }
552
553 static int nvdimm_namespace_attach_pfn(struct nd_namespace_common *ndns)
554 {
555 struct nd_pfn *nd_pfn = to_nd_pfn(ndns->claim);
556 int rc;
557
558 if (!nd_pfn->uuid || !nd_pfn->ndns)
559 return -ENODEV;
560
561 rc = nd_pfn_init(nd_pfn);
562 if (rc)
563 return rc;
564 /* we need a valid pfn_sb before we can init a vmem_altmap */
565 return __nvdimm_namespace_attach_pfn(nd_pfn);
566 }
567
568 static int nd_pmem_probe(struct device *dev)
569 {
570 struct nd_region *nd_region = to_nd_region(dev->parent);
571 struct nd_namespace_common *ndns;
572 struct nd_namespace_io *nsio;
573 struct pmem_device *pmem;
574
575 ndns = nvdimm_namespace_common_probe(dev);
576 if (IS_ERR(ndns))
577 return PTR_ERR(ndns);
578
579 nsio = to_nd_namespace_io(&ndns->dev);
580 pmem = pmem_alloc(dev, &nsio->res, nd_region->id);
581 if (IS_ERR(pmem))
582 return PTR_ERR(pmem);
583
584 pmem->ndns = ndns;
585 dev_set_drvdata(dev, pmem);
586 ndns->rw_bytes = pmem_rw_bytes;
587 if (devm_init_badblocks(dev, &pmem->bb))
588 return -ENOMEM;
589 nvdimm_badblocks_populate(nd_region, &pmem->bb, &nsio->res);
590
591 if (is_nd_btt(dev)) {
592 /* btt allocates its own request_queue */
593 blk_cleanup_queue(pmem->pmem_queue);
594 pmem->pmem_queue = NULL;
595 return nvdimm_namespace_attach_btt(ndns);
596 }
597
598 if (is_nd_pfn(dev))
599 return nvdimm_namespace_attach_pfn(ndns);
600
601 if (nd_btt_probe(ndns, pmem) == 0 || nd_pfn_probe(ndns, pmem) == 0) {
602 /*
603 * We'll come back as either btt-pmem, or pfn-pmem, so
604 * drop the queue allocation for now.
605 */
606 blk_cleanup_queue(pmem->pmem_queue);
607 return -ENXIO;
608 }
609
610 return pmem_attach_disk(dev, ndns, pmem);
611 }
612
613 static int nd_pmem_remove(struct device *dev)
614 {
615 struct pmem_device *pmem = dev_get_drvdata(dev);
616
617 if (is_nd_btt(dev))
618 nvdimm_namespace_detach_btt(pmem->ndns);
619 else if (is_nd_pfn(dev))
620 nvdimm_namespace_detach_pfn(pmem->ndns);
621 else
622 pmem_detach_disk(pmem);
623
624 return 0;
625 }
626
627 static void nd_pmem_notify(struct device *dev, enum nvdimm_event event)
628 {
629 struct pmem_device *pmem = dev_get_drvdata(dev);
630 struct nd_namespace_common *ndns = pmem->ndns;
631 struct nd_region *nd_region = to_nd_region(dev->parent);
632 struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
633 struct resource res = {
634 .start = nsio->res.start + pmem->data_offset,
635 .end = nsio->res.end,
636 };
637
638 if (event != NVDIMM_REVALIDATE_POISON)
639 return;
640
641 if (is_nd_pfn(dev)) {
642 struct nd_pfn *nd_pfn = to_nd_pfn(dev);
643 struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
644
645 res.start += __le32_to_cpu(pfn_sb->start_pad);
646 res.end -= __le32_to_cpu(pfn_sb->end_trunc);
647 }
648
649 nvdimm_badblocks_populate(nd_region, &pmem->bb, &res);
650 }
651
652 MODULE_ALIAS("pmem");
653 MODULE_ALIAS_ND_DEVICE(ND_DEVICE_NAMESPACE_IO);
654 MODULE_ALIAS_ND_DEVICE(ND_DEVICE_NAMESPACE_PMEM);
655 static struct nd_device_driver nd_pmem_driver = {
656 .probe = nd_pmem_probe,
657 .remove = nd_pmem_remove,
658 .notify = nd_pmem_notify,
659 .drv = {
660 .name = "nd_pmem",
661 },
662 .type = ND_DRIVER_NAMESPACE_IO | ND_DRIVER_NAMESPACE_PMEM,
663 };
664
665 static int __init pmem_init(void)
666 {
667 return nd_driver_register(&nd_pmem_driver);
668 }
669 module_init(pmem_init);
670
671 static void pmem_exit(void)
672 {
673 driver_unregister(&nd_pmem_driver.drv);
674 }
675 module_exit(pmem_exit);
676
677 MODULE_AUTHOR("Ross Zwisler <ross.zwisler@linux.intel.com>");
678 MODULE_LICENSE("GPL v2");
This page took 0.05123 seconds and 6 git commands to generate.