Merge tag 'pci-v6.16-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci
[linux-2.6-block.git] / drivers / dax / dax-private.h
CommitLineData
5b497af4 1/* SPDX-License-Identifier: GPL-2.0-only */
efebc711
DJ
2/*
3 * Copyright(c) 2016 Intel Corporation. All rights reserved.
efebc711
DJ
4 */
5#ifndef __DAX_PRIVATE_H__
6#define __DAX_PRIVATE_H__
7
8#include <linux/device.h>
9#include <linux/cdev.h>
0f3da14a 10#include <linux/idr.h>
efebc711 11
51cf784c
DW
12/* private routines between core files */
13struct dax_device;
14struct dax_device *inode_dax(struct inode *inode);
15struct inode *dax_inode(struct dax_device *dax_dev);
9567da0b
DW
16int dax_bus_init(void);
17void dax_bus_exit(void);
51cf784c 18
efebc711
DJ
19/**
20 * struct dax_region - mapping infrastructure for dax devices
21 * @id: kernel-wide unique region for a memory range
8fc5c735 22 * @target_node: effective numa node if this memory range is onlined
efebc711
DJ
23 * @kref: to pin while other agents have a need to do lookups
24 * @dev: parent device backing this region
25 * @align: allocation and mapping alignment for child dax devices
0f3da14a 26 * @ida: instance id allocator
c2f3011e 27 * @res: resource tree to track instance allocations
0f3da14a
DW
28 * @seed: allow userspace to find the first unbound seed device
29 * @youngest: allow userspace to find the most recently created device
efebc711
DJ
30 */
31struct dax_region {
32 int id;
8fc5c735 33 int target_node;
efebc711
DJ
34 struct kref kref;
35 struct device *dev;
36 unsigned int align;
0f3da14a 37 struct ida ida;
efebc711 38 struct resource res;
0f3da14a
DW
39 struct device *seed;
40 struct device *youngest;
efebc711
DJ
41};
42
f88b3ecc
IW
43/**
44 * struct dax_mapping - device to display mapping range attributes
45 * @dev: device representing this range
46 * @range_id: index within dev_dax ranges array
47 * @id: ida of this mapping
48 */
0b07ce87
DW
49struct dax_mapping {
50 struct device dev;
51 int range_id;
52 int id;
53};
54
f88b3ecc
IW
55/**
56 * struct dev_dax_range - tuple represenging a range of memory used by dev_dax
57 * @pgoff: page offset
58 * @range: resource-span
59 * @mapping: reference to the dax_mapping for this range
60 */
61struct dev_dax_range {
62 unsigned long pgoff;
63 struct range range;
64 struct dax_mapping *mapping;
65};
66
efebc711 67/**
89ec9f2c
DW
68 * struct dev_dax - instance data for a subdivision of a dax region, and
69 * data while the device is activated in the driver.
efebc711 70 * @region - parent region
73616367 71 * @dax_dev - core dax functionality
8fc5c735 72 * @target_node: effective numa node if dev_dax memory range is onlined
70aab281
DW
73 * @dyn_id: is this a dynamic or statically created instance
74 * @id: ida allocated id when the dax_region is not static
0b07ce87 75 * @ida: mapping id allocator
73616367 76 * @dev - device core
89ec9f2c 77 * @pgmap - pgmap for memmap setup / lifetime (driver owned)
60e93dc0 78 * @nr_range: size of @ranges
f88b3ecc 79 * @ranges: range tuples of memory used
efebc711 80 */
73616367 81struct dev_dax {
efebc711 82 struct dax_region *region;
73616367 83 struct dax_device *dax_dev;
33cf94d7 84 unsigned int align;
8fc5c735 85 int target_node;
70aab281 86 bool dyn_id;
0f3da14a 87 int id;
0b07ce87 88 struct ida ida;
efebc711 89 struct device dev;
f5516ec5 90 struct dev_pagemap *pgmap;
4eca0ef4 91 bool memmap_on_memory;
60e93dc0 92 int nr_range;
f88b3ecc 93 struct dev_dax_range *ranges;
efebc711 94};
51cf784c 95
2d515352
AB
96/*
97 * While run_dax() is potentially a generic operation that could be
98 * defined in include/linux/dax.h we don't want to grow any users
99 * outside of drivers/dax/
100 */
101void run_dax(struct dax_device *dax_dev);
102
51cf784c
DW
103static inline struct dev_dax *to_dev_dax(struct device *dev)
104{
105 return container_of(dev, struct dev_dax, dev);
106}
0b07ce87
DW
107
108static inline struct dax_mapping *to_dax_mapping(struct device *dev)
109{
110 return container_of(dev, struct dax_mapping, dev);
111}
33cf94d7
JM
112
113phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, unsigned long size);
6d82120f
DW
114
115#ifdef CONFIG_TRANSPARENT_HUGEPAGE
116static inline bool dax_align_valid(unsigned long align)
117{
118 if (align == PUD_SIZE && IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD))
119 return true;
120 if (align == PMD_SIZE && has_transparent_hugepage())
121 return true;
122 if (align == PAGE_SIZE)
123 return true;
124 return false;
125}
126#else
127static inline bool dax_align_valid(unsigned long align)
128{
129 return align == PAGE_SIZE;
130}
131#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
efebc711 132#endif