device-dax: introduce 'seed' devices
[sfrench/cifs-2.6.git] / drivers / dax / dax-private.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright(c) 2016 Intel Corporation. All rights reserved.
4  */
5 #ifndef __DAX_PRIVATE_H__
6 #define __DAX_PRIVATE_H__
7
8 #include <linux/device.h>
9 #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);
18
19 /**
20  * struct dax_region - mapping infrastructure for dax devices
21  * @id: kernel-wide unique region for a memory range
22  * @target_node: effective numa node if this memory range is onlined
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
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
30  */
31 struct dax_region {
32         int id;
33         int target_node;
34         struct kref kref;
35         struct device *dev;
36         unsigned int align;
37         struct ida ida;
38         struct resource res;
39         struct device *seed;
40         struct device *youngest;
41 };
42
43 /**
44  * struct dev_dax - instance data for a subdivision of a dax region, and
45  * data while the device is activated in the driver.
46  * @region - parent region
47  * @dax_dev - core dax functionality
48  * @target_node: effective numa node if dev_dax memory range is onlined
49  * @id: ida allocated id
50  * @dev - device core
51  * @pgmap - pgmap for memmap setup / lifetime (driver owned)
52  * @range: resource range for the instance
53  */
54 struct dev_dax {
55         struct dax_region *region;
56         struct dax_device *dax_dev;
57         int target_node;
58         int id;
59         struct device dev;
60         struct dev_pagemap *pgmap;
61         struct range range;
62 };
63
64 static inline u64 range_len(struct range *range)
65 {
66         return range->end - range->start + 1;
67 }
68
69 static inline struct dev_dax *to_dev_dax(struct device *dev)
70 {
71         return container_of(dev, struct dev_dax, dev);
72 }
73 #endif