xref: /linux/drivers/dax/dax-private.h (revision f5516ec5efb9fe0f426a46eeef25d389d3c2f988)
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 
11 /* private routines between core files */
12 struct dax_device;
13 struct dax_device *inode_dax(struct inode *inode);
14 struct inode *dax_inode(struct dax_device *dax_dev);
15 int dax_bus_init(void);
16 void dax_bus_exit(void);
17 
18 /**
19  * struct dax_region - mapping infrastructure for dax devices
20  * @id: kernel-wide unique region for a memory range
21  * @target_node: effective numa node if this memory range is onlined
22  * @kref: to pin while other agents have a need to do lookups
23  * @dev: parent device backing this region
24  * @align: allocation and mapping alignment for child dax devices
25  * @res: physical address range of the region
26  */
27 struct dax_region {
28 	int id;
29 	int target_node;
30 	struct kref kref;
31 	struct device *dev;
32 	unsigned int align;
33 	struct resource res;
34 };
35 
36 /**
37  * struct dev_dax - instance data for a subdivision of a dax region, and
38  * data while the device is activated in the driver.
39  * @region - parent region
40  * @dax_dev - core dax functionality
41  * @target_node: effective numa node if dev_dax memory range is onlined
42  * @dev - device core
43  * @pgmap - pgmap for memmap setup / lifetime (driver owned)
44  * @range: resource range for the instance
45  * @dax_mem_res: physical address range of hotadded DAX memory
46  * @dax_mem_name: name for hotadded DAX memory via add_memory_driver_managed()
47  */
48 struct dev_dax {
49 	struct dax_region *region;
50 	struct dax_device *dax_dev;
51 	int target_node;
52 	struct device dev;
53 	struct dev_pagemap *pgmap;
54 	struct range range;
55 	struct resource *dax_kmem_res;
56 };
57 
58 static inline u64 range_len(struct range *range)
59 {
60 	return range->end - range->start + 1;
61 }
62 
63 static inline struct dev_dax *to_dev_dax(struct device *dev)
64 {
65 	return container_of(dev, struct dev_dax, dev);
66 }
67 #endif
68