18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2016, Intel Corporation. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci#include "test/nfit_test.h" 68c2ecf20Sopenharmony_ci#include <linux/mm.h> 78c2ecf20Sopenharmony_ci#include "../../../drivers/dax/dax-private.h" 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciphys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, 108c2ecf20Sopenharmony_ci unsigned long size) 118c2ecf20Sopenharmony_ci{ 128c2ecf20Sopenharmony_ci int i; 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci for (i = 0; i < dev_dax->nr_range; i++) { 158c2ecf20Sopenharmony_ci struct dev_dax_range *dax_range = &dev_dax->ranges[i]; 168c2ecf20Sopenharmony_ci struct range *range = &dax_range->range; 178c2ecf20Sopenharmony_ci unsigned long long pgoff_end; 188c2ecf20Sopenharmony_ci phys_addr_t addr; 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci pgoff_end = dax_range->pgoff + PHYS_PFN(range_len(range)) - 1; 218c2ecf20Sopenharmony_ci if (pgoff < dax_range->pgoff || pgoff > pgoff_end) 228c2ecf20Sopenharmony_ci continue; 238c2ecf20Sopenharmony_ci addr = PFN_PHYS(pgoff - dax_range->pgoff) + range->start; 248c2ecf20Sopenharmony_ci if (addr + size - 1 <= range->end) { 258c2ecf20Sopenharmony_ci if (get_nfit_res(addr)) { 268c2ecf20Sopenharmony_ci struct page *page; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci if (dev_dax->region->align > PAGE_SIZE) 298c2ecf20Sopenharmony_ci return -1; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci page = vmalloc_to_page((void *)addr); 328c2ecf20Sopenharmony_ci return PFN_PHYS(page_to_pfn(page)); 338c2ecf20Sopenharmony_ci } 348c2ecf20Sopenharmony_ci return addr; 358c2ecf20Sopenharmony_ci } 368c2ecf20Sopenharmony_ci break; 378c2ecf20Sopenharmony_ci } 388c2ecf20Sopenharmony_ci return -1; 398c2ecf20Sopenharmony_ci} 40