15b497af4SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2efebc711SDave Jiang /* 3efebc711SDave Jiang * Copyright(c) 2016 Intel Corporation. All rights reserved. 4efebc711SDave Jiang */ 5efebc711SDave Jiang #ifndef __DAX_PRIVATE_H__ 6efebc711SDave Jiang #define __DAX_PRIVATE_H__ 7efebc711SDave Jiang 8efebc711SDave Jiang #include <linux/device.h> 9efebc711SDave Jiang #include <linux/cdev.h> 100f3da14aSDan Williams #include <linux/idr.h> 11efebc711SDave Jiang 1251cf784cSDan Williams /* private routines between core files */ 1351cf784cSDan Williams struct dax_device; 1451cf784cSDan Williams struct dax_device *inode_dax(struct inode *inode); 1551cf784cSDan Williams struct inode *dax_inode(struct dax_device *dax_dev); 169567da0bSDan Williams int dax_bus_init(void); 179567da0bSDan Williams void dax_bus_exit(void); 1851cf784cSDan Williams 19efebc711SDave Jiang /** 20efebc711SDave Jiang * struct dax_region - mapping infrastructure for dax devices 21efebc711SDave Jiang * @id: kernel-wide unique region for a memory range 228fc5c735SDan Williams * @target_node: effective numa node if this memory range is onlined 23efebc711SDave Jiang * @kref: to pin while other agents have a need to do lookups 24efebc711SDave Jiang * @dev: parent device backing this region 25efebc711SDave Jiang * @align: allocation and mapping alignment for child dax devices 260f3da14aSDan Williams * @ida: instance id allocator 27c2f3011eSDan Williams * @res: resource tree to track instance allocations 280f3da14aSDan Williams * @seed: allow userspace to find the first unbound seed device 290f3da14aSDan Williams * @youngest: allow userspace to find the most recently created device 30efebc711SDave Jiang */ 31efebc711SDave Jiang struct dax_region { 32efebc711SDave Jiang int id; 338fc5c735SDan Williams int target_node; 34efebc711SDave Jiang struct kref kref; 35efebc711SDave Jiang struct device *dev; 36efebc711SDave Jiang unsigned int align; 370f3da14aSDan Williams struct ida ida; 38efebc711SDave Jiang struct resource res; 390f3da14aSDan Williams struct device *seed; 400f3da14aSDan Williams struct device *youngest; 41efebc711SDave Jiang }; 42efebc711SDave Jiang 430b07ce87SDan Williams struct dax_mapping { 440b07ce87SDan Williams struct device dev; 450b07ce87SDan Williams int range_id; 460b07ce87SDan Williams int id; 470b07ce87SDan Williams }; 480b07ce87SDan Williams 49efebc711SDave Jiang /** 5089ec9f2cSDan Williams * struct dev_dax - instance data for a subdivision of a dax region, and 5189ec9f2cSDan Williams * data while the device is activated in the driver. 52efebc711SDave Jiang * @region - parent region 5373616367SDan Williams * @dax_dev - core dax functionality 548fc5c735SDan Williams * @target_node: effective numa node if dev_dax memory range is onlined 55*70aab281SDan Williams * @dyn_id: is this a dynamic or statically created instance 56*70aab281SDan Williams * @id: ida allocated id when the dax_region is not static 570b07ce87SDan Williams * @ida: mapping id allocator 5873616367SDan Williams * @dev - device core 5989ec9f2cSDan Williams * @pgmap - pgmap for memmap setup / lifetime (driver owned) 6060e93dc0SDan Williams * @nr_range: size of @ranges 6160e93dc0SDan Williams * @ranges: resource-span + pgoff tuples for the instance 62efebc711SDave Jiang */ 6373616367SDan Williams struct dev_dax { 64efebc711SDave Jiang struct dax_region *region; 6573616367SDan Williams struct dax_device *dax_dev; 6633cf94d7SJoao Martins unsigned int align; 678fc5c735SDan Williams int target_node; 68*70aab281SDan Williams bool dyn_id; 690f3da14aSDan Williams int id; 700b07ce87SDan Williams struct ida ida; 71efebc711SDave Jiang struct device dev; 72f5516ec5SDan Williams struct dev_pagemap *pgmap; 7360e93dc0SDan Williams int nr_range; 7460e93dc0SDan Williams struct dev_dax_range { 7560e93dc0SDan Williams unsigned long pgoff; 76f5516ec5SDan Williams struct range range; 770b07ce87SDan Williams struct dax_mapping *mapping; 7860e93dc0SDan Williams } *ranges; 79efebc711SDave Jiang }; 8051cf784cSDan Williams 812d515352SArnd Bergmann /* 822d515352SArnd Bergmann * While run_dax() is potentially a generic operation that could be 832d515352SArnd Bergmann * defined in include/linux/dax.h we don't want to grow any users 842d515352SArnd Bergmann * outside of drivers/dax/ 852d515352SArnd Bergmann */ 862d515352SArnd Bergmann void run_dax(struct dax_device *dax_dev); 872d515352SArnd Bergmann to_dev_dax(struct device * dev)8851cf784cSDan Williamsstatic inline struct dev_dax *to_dev_dax(struct device *dev) 8951cf784cSDan Williams { 9051cf784cSDan Williams return container_of(dev, struct dev_dax, dev); 9151cf784cSDan Williams } 920b07ce87SDan Williams to_dax_mapping(struct device * dev)930b07ce87SDan Williamsstatic inline struct dax_mapping *to_dax_mapping(struct device *dev) 940b07ce87SDan Williams { 950b07ce87SDan Williams return container_of(dev, struct dax_mapping, dev); 960b07ce87SDan Williams } 9733cf94d7SJoao Martins 9833cf94d7SJoao Martins phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, unsigned long size); 996d82120fSDan Williams 1006d82120fSDan Williams #ifdef CONFIG_TRANSPARENT_HUGEPAGE dax_align_valid(unsigned long align)1016d82120fSDan Williamsstatic inline bool dax_align_valid(unsigned long align) 1026d82120fSDan Williams { 1036d82120fSDan Williams if (align == PUD_SIZE && IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)) 1046d82120fSDan Williams return true; 1056d82120fSDan Williams if (align == PMD_SIZE && has_transparent_hugepage()) 1066d82120fSDan Williams return true; 1076d82120fSDan Williams if (align == PAGE_SIZE) 1086d82120fSDan Williams return true; 1096d82120fSDan Williams return false; 1106d82120fSDan Williams } 1116d82120fSDan Williams #else dax_align_valid(unsigned long align)1126d82120fSDan Williamsstatic inline bool dax_align_valid(unsigned long align) 1136d82120fSDan Williams { 1146d82120fSDan Williams return align == PAGE_SIZE; 1156d82120fSDan Williams } 1166d82120fSDan Williams #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 117efebc711SDave Jiang #endif 118