/* 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* @target_node: effective numa node if dev_dax memory range is onlined72* @dyn_id: is this a dynamic or statically created instance73* @id: ida allocated id when the dax_region is not static74* @ida: mapping id allocator75* @dev - device core76* @pgmap - pgmap for memmap setup / lifetime (driver owned)77* @nr_range: size of @ranges78* @ranges: range tuples of memory used79*/80struct dev_dax {81struct dax_region *region;82struct dax_device *dax_dev;83unsigned int align;84int target_node;85bool dyn_id;86int id;87struct ida ida;88struct device dev;89struct dev_pagemap *pgmap;90bool memmap_on_memory;91int nr_range;92struct dev_dax_range *ranges;93};9495/*96* While run_dax() is potentially a generic operation that could be97* defined in include/linux/dax.h we don't want to grow any users98* outside of drivers/dax/99*/100void run_dax(struct dax_device *dax_dev);101102static inline struct dev_dax *to_dev_dax(struct device *dev)103{104return container_of(dev, struct dev_dax, dev);105}106107static inline struct dax_mapping *to_dax_mapping(struct device *dev)108{109return container_of(dev, struct dax_mapping, dev);110}111112phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, unsigned long size);113114#ifdef CONFIG_TRANSPARENT_HUGEPAGE115static inline bool dax_align_valid(unsigned long align)116{117if (align == PUD_SIZE && IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD))118return true;119if (align == PMD_SIZE && has_transparent_hugepage())120return true;121if (align == PAGE_SIZE)122return true;123return false;124}125#else126static inline bool dax_align_valid(unsigned long align)127{128return align == PAGE_SIZE;129}130#endif /* CONFIG_TRANSPARENT_HUGEPAGE */131#endif132133134