hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/dax/dax-private.h
....@@ -1,57 +1,110 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Copyright(c) 2016 Intel Corporation. All rights reserved.
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of version 2 of the GNU General Public License as
6
- * published by the Free Software Foundation.
7
- *
8
- * This program is distributed in the hope that it will be useful, but
9
- * WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
- * General Public License for more details.
124 */
135 #ifndef __DAX_PRIVATE_H__
146 #define __DAX_PRIVATE_H__
157
168 #include <linux/device.h>
179 #include <linux/cdev.h>
10
+#include <linux/idr.h>
11
+
12
+/* private routines between core files */
13
+struct dax_device;
14
+struct dax_device *inode_dax(struct inode *inode);
15
+struct inode *dax_inode(struct dax_device *dax_dev);
16
+int dax_bus_init(void);
17
+void dax_bus_exit(void);
1818
1919 /**
2020 * struct dax_region - mapping infrastructure for dax devices
2121 * @id: kernel-wide unique region for a memory range
22
- * @base: linear address corresponding to @res
22
+ * @target_node: effective numa node if this memory range is onlined
2323 * @kref: to pin while other agents have a need to do lookups
2424 * @dev: parent device backing this region
2525 * @align: allocation and mapping alignment for child dax devices
26
- * @res: physical address range of the region
27
- * @pfn_flags: identify whether the pfns are paged back or not
26
+ * @ida: instance id allocator
27
+ * @res: resource tree to track instance allocations
28
+ * @seed: allow userspace to find the first unbound seed device
29
+ * @youngest: allow userspace to find the most recently created device
2830 */
2931 struct dax_region {
3032 int id;
31
- struct ida ida;
32
- void *base;
33
+ int target_node;
3334 struct kref kref;
3435 struct device *dev;
3536 unsigned int align;
37
+ struct ida ida;
3638 struct resource res;
37
- unsigned long pfn_flags;
39
+ struct device *seed;
40
+ struct device *youngest;
41
+};
42
+
43
+struct dax_mapping {
44
+ struct device dev;
45
+ int range_id;
46
+ int id;
3847 };
3948
4049 /**
41
- * struct dev_dax - instance data for a subdivision of a dax region
50
+ * struct dev_dax - instance data for a subdivision of a dax region, and
51
+ * data while the device is activated in the driver.
4252 * @region - parent region
4353 * @dax_dev - core dax functionality
54
+ * @target_node: effective numa node if dev_dax memory range is onlined
55
+ * @dyn_id: is this a dynamic or statically created instance
56
+ * @id: ida allocated id when the dax_region is not static
57
+ * @ida: mapping id allocator
4458 * @dev - device core
45
- * @id - child id in the region
46
- * @num_resources - number of physical address extents in this device
47
- * @res - array of physical address ranges
59
+ * @pgmap - pgmap for memmap setup / lifetime (driver owned)
60
+ * @nr_range: size of @ranges
61
+ * @ranges: resource-span + pgoff tuples for the instance
4862 */
4963 struct dev_dax {
5064 struct dax_region *region;
5165 struct dax_device *dax_dev;
52
- struct device dev;
66
+ unsigned int align;
67
+ int target_node;
68
+ bool dyn_id;
5369 int id;
54
- int num_resources;
55
- struct resource res[0];
70
+ struct ida ida;
71
+ struct device dev;
72
+ struct dev_pagemap *pgmap;
73
+ int nr_range;
74
+ struct dev_dax_range {
75
+ unsigned long pgoff;
76
+ struct range range;
77
+ struct dax_mapping *mapping;
78
+ } *ranges;
5679 };
80
+
81
+static inline struct dev_dax *to_dev_dax(struct device *dev)
82
+{
83
+ return container_of(dev, struct dev_dax, dev);
84
+}
85
+
86
+static inline struct dax_mapping *to_dax_mapping(struct device *dev)
87
+{
88
+ return container_of(dev, struct dax_mapping, dev);
89
+}
90
+
91
+phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, unsigned long size);
92
+
93
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
94
+static inline bool dax_align_valid(unsigned long align)
95
+{
96
+ if (align == PUD_SIZE && IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD))
97
+ return true;
98
+ if (align == PMD_SIZE && has_transparent_hugepage())
99
+ return true;
100
+ if (align == PAGE_SIZE)
101
+ return true;
102
+ return false;
103
+}
104
+#else
105
+static inline bool dax_align_valid(unsigned long align)
106
+{
107
+ return align == PAGE_SIZE;
108
+}
109
+#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
57110 #endif