xref: /openbmc/linux/tools/testing/nvdimm/dax-dev.c (revision cbdf59ad)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2016, Intel Corporation.
4  */
5 #include "test/nfit_test.h"
6 #include <linux/mm.h>
7 #include "../../../drivers/dax/dax-private.h"
8 
9 phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff,
10 		unsigned long size)
11 {
12 	struct resource *res = &dev_dax->region->res;
13 	phys_addr_t addr;
14 
15 	addr = pgoff * PAGE_SIZE + res->start;
16 	if (addr >= res->start && addr <= res->end) {
17 		if (addr + size - 1 <= res->end) {
18 			if (get_nfit_res(addr)) {
19 				struct page *page;
20 
21 				if (dev_dax->region->align > PAGE_SIZE)
22 					return -1;
23 
24 				page = vmalloc_to_page((void *)addr);
25 				return PFN_PHYS(page_to_pfn(page));
26 			} else
27 				return addr;
28 		}
29 	}
30 	return -1;
31 }
32