pmem-dax.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2014-2016, Intel Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. */
  13. #include "test/nfit_test.h"
  14. #include <linux/blkdev.h>
  15. #include <pmem.h>
  16. #include <nd.h>
  17. long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,
  18. long nr_pages, void **kaddr, pfn_t *pfn)
  19. {
  20. resource_size_t offset = PFN_PHYS(pgoff) + pmem->data_offset;
  21. if (unlikely(is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512,
  22. PFN_PHYS(nr_pages))))
  23. return -EIO;
  24. /*
  25. * Limit dax to a single page at a time given vmalloc()-backed
  26. * in the nfit_test case.
  27. */
  28. if (get_nfit_res(pmem->phys_addr + offset)) {
  29. struct page *page;
  30. if (kaddr)
  31. *kaddr = pmem->virt_addr + offset;
  32. page = vmalloc_to_page(pmem->virt_addr + offset);
  33. if (pfn)
  34. *pfn = page_to_pfn_t(page);
  35. pr_debug_ratelimited("%s: pmem: %p pgoff: %#lx pfn: %#lx\n",
  36. __func__, pmem, pgoff, page_to_pfn(page));
  37. return 1;
  38. }
  39. if (kaddr)
  40. *kaddr = pmem->virt_addr + offset;
  41. if (pfn)
  42. *pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags);
  43. /*
  44. * If badblocks are present, limit known good range to the
  45. * requested range.
  46. */
  47. if (unlikely(pmem->bb.count))
  48. return nr_pages;
  49. return PHYS_PFN(pmem->size - pmem->pfn_pad - offset);
  50. }