octeontx2-af: Fix mcs stats register address
[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
0b07ce87
DW
43struct dax_mapping {
44 struct device dev;
45 int range_id;
46 int id;
47};
48
efebc711 49/**
89ec9f2c
DW
50 * struct dev_dax - instance data for a subdivision of a dax region, and
51 * data while the device is activated in the driver.
efebc711 52 * @region - parent region
73616367 53 * @dax_dev - core dax functionality
8fc5c735 54 * @target_node: effective numa node if dev_dax memory range is onlined
70aab281
DW
55 * @dyn_id: is this a dynamic or statically created instance
56 * @id: ida allocated id when the dax_region is not static
0b07ce87 57 * @ida: mapping id allocator
73616367 58 * @dev - device core
89ec9f2c 59 * @pgmap - pgmap for memmap setup / lifetime (driver owned)
60e93dc0
DW
60 * @nr_range: size of @ranges
61 * @ranges: resource-span + pgoff tuples for the instance
efebc711 62 */
73616367 63struct dev_dax {
efebc711 64 struct dax_region *region;
73616367 65 struct dax_device *dax_dev;
33cf94d7 66 unsigned int align;
8fc5c735 67 int target_node;
70aab281 68 bool dyn_id;
0f3da14a 69 int id;
0b07ce87 70 struct ida ida;
efebc711 71 struct device dev;
f5516ec5 72 struct dev_pagemap *pgmap;
60e93dc0
DW
73 int nr_range;
74 struct dev_dax_range {
75 unsigned long pgoff;
76 struct range range;
0b07ce87 77 struct dax_mapping *mapping;
60e93dc0 78 } *ranges;
efebc711 79};
51cf784c 80
2d515352
AB
81/*
82 * While run_dax() is potentially a generic operation that could be
83 * defined in include/linux/dax.h we don't want to grow any users
84 * outside of drivers/dax/
85 */
86void run_dax(struct dax_device *dax_dev);
87
51cf784c
DW
88static inline struct dev_dax *to_dev_dax(struct device *dev)
89{
90 return container_of(dev, struct dev_dax, dev);
91}
0b07ce87
DW
92
93static inline struct dax_mapping *to_dax_mapping(struct device *dev)
94{
95 return container_of(dev, struct dax_mapping, dev);
96}
33cf94d7
JM
97
98phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, unsigned long size);
6d82120f
DW
99
100#ifdef CONFIG_TRANSPARENT_HUGEPAGE
101static inline bool dax_align_valid(unsigned long align)
102{
103 if (align == PUD_SIZE && IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD))
104 return true;
105 if (align == PMD_SIZE && has_transparent_hugepage())
106 return true;
107 if (align == PAGE_SIZE)
108 return true;
109 return false;
110}
111#else
112static inline bool dax_align_valid(unsigned long align)
113{
114 return align == PAGE_SIZE;
115}
116#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
efebc711 117#endif