/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Copyright(c) 2016 Intel Corporation. All rights reserved.3*/4#ifndef __DAX_PRIVATE_H__5#define __DAX_PRIVATE_H__67#include <linux/device.h>8#include <linux/cdev.h>9#include <linux/idr.h>1011/* private routines between core files */12struct dax_device;13struct dax_device *inode_dax(struct inode *inode);14struct inode *dax_inode(struct dax_device *dax_dev);15int dax_bus_init(void);16void dax_bus_exit(void);1718/**19* struct dax_region - mapping infrastructure for dax devices20* @id: kernel-wide unique region for a memory range21* @target_node: effective numa node if this memory range is onlined22* @kref: to pin while other agents have a need to do lookups23* @dev: parent device backing this region24* @align: allocation and mapping alignment for child dax devices25* @ida: instance id allocator26* @res: resource tree to track instance allocations27* @seed: allow userspace to find the first unbound seed device28* @youngest: allow userspace to find the most recently created device29*/30struct dax_region {31int id;32int target_node;33struct kref kref;34struct device *dev;35unsigned int align;36struct ida ida;37struct resource res;38struct device *seed;39struct device *youngest;40};4142/**43* struct dax_mapping - device to display mapping range attributes44* @dev: device representing this range45* @range_id: index within dev_dax ranges array46* @id: ida of this mapping47*/48struct dax_mapping {49struct device dev;50int range_id;51int id;52};5354/**55* struct dev_dax_range - tuple represenging a range of memory used by dev_dax56* @pgoff: page offset57* @range: resource-span58* @mapping: reference to the dax_mapping for this range59*/60struct dev_dax_range {61unsigned long pgoff;62struct range range;63struct dax_mapping *mapping;64};6566/**67* struct dev_dax - instance data for a subdivision of a dax region, and68* data while the device is activated in the driver.69* @region: parent region70* @dax_dev: core dax functionality71* @align: alignment of this instance72* @target_node: effective numa node if dev_dax memory range is onlined73* @dyn_id: is this a dynamic or statically created instance74* @id: ida allocated id when the dax_region is not static75* @ida: mapping id allocator76* @dev: device core77* @pgmap: pgmap for memmap setup / lifetime (driver owned)78* @memmap_on_memory: allow kmem to put the memmap in the memory79* @nr_range: size of @ranges80* @ranges: range tuples of memory used81*/82struct dev_dax {83struct dax_region *region;84struct dax_device *dax_dev;85unsigned int align;86int target_node;87bool dyn_id;88int id;89struct ida ida;90struct device dev;91struct dev_pagemap *pgmap;92bool memmap_on_memory;93int nr_range;94struct dev_dax_range *ranges;95};9697/*98* While run_dax() is potentially a generic operation that could be99* defined in include/linux/dax.h we don't want to grow any users100* outside of drivers/dax/101*/102void run_dax(struct dax_device *dax_dev);103104static inline struct dev_dax *to_dev_dax(struct device *dev)105{106return container_of(dev, struct dev_dax, dev);107}108109static inline struct dax_mapping *to_dax_mapping(struct device *dev)110{111return container_of(dev, struct dax_mapping, dev);112}113114phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, unsigned long size);115116#ifdef CONFIG_TRANSPARENT_HUGEPAGE117static inline bool dax_align_valid(unsigned long align)118{119if (align == PUD_SIZE && IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD))120return true;121if (align == PMD_SIZE && has_transparent_hugepage())122return true;123if (align == PAGE_SIZE)124return true;125return false;126}127#else128static inline bool dax_align_valid(unsigned long align)129{130return align == PAGE_SIZE;131}132#endif /* CONFIG_TRANSPARENT_HUGEPAGE */133#endif134135136