xref: /linux/drivers/dax/bus.h (revision 5ea5880764cbb164afb17a62e76ca75dc371409d)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2016 - 2018 Intel Corporation. All rights reserved. */
3 #ifndef __DAX_BUS_H__
4 #define __DAX_BUS_H__
5 #include <linux/device.h>
6 #include <linux/platform_device.h>
7 #include <linux/range.h>
8 #include <linux/workqueue.h>
9 
10 struct dev_dax;
11 struct resource;
12 struct dax_device;
13 struct dax_region;
14 
15 /* dax bus specific ioresource flags */
16 #define IORESOURCE_DAX_STATIC BIT(0)
17 #define IORESOURCE_DAX_KMEM BIT(1)
18 
19 struct dax_region *alloc_dax_region(struct device *parent, int region_id,
20 		struct range *range, int target_node, unsigned int align,
21 		unsigned long flags);
22 
23 struct dev_dax_data {
24 	struct dax_region *dax_region;
25 	struct dev_pagemap *pgmap;
26 	resource_size_t size;
27 	int id;
28 	bool memmap_on_memory;
29 };
30 
31 struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data);
32 
33 enum dax_driver_type {
34 	DAXDRV_KMEM_TYPE,
35 	DAXDRV_DEVICE_TYPE,
36 };
37 
38 struct dax_device_driver {
39 	struct device_driver drv;
40 	struct list_head ids;
41 	enum dax_driver_type type;
42 	int (*probe)(struct dev_dax *dev);
43 	void (*remove)(struct dev_dax *dev);
44 };
45 
46 int __dax_driver_register(struct dax_device_driver *dax_drv,
47 		struct module *module, const char *mod_name);
48 #define dax_driver_register(driver) \
49 	__dax_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
50 void dax_driver_unregister(struct dax_device_driver *dax_drv);
51 void kill_dev_dax(struct dev_dax *dev_dax);
52 bool static_dev_dax(struct dev_dax *dev_dax);
53 
54 struct hmem_platform_device {
55 	struct platform_device pdev;
56 	struct work_struct work;
57 	bool did_probe;
58 };
59 
60 static inline struct hmem_platform_device *
61 to_hmem_platform_device(struct platform_device *pdev)
62 {
63 	return container_of(pdev, struct hmem_platform_device, pdev);
64 }
65 
66 #if IS_ENABLED(CONFIG_DEV_DAX_HMEM)
67 void dax_hmem_flush_work(void);
68 #else
69 static inline void dax_hmem_flush_work(void) { }
70 #endif
71 
72 #define MODULE_ALIAS_DAX_DEVICE(type) \
73 	MODULE_ALIAS("dax:t" __stringify(type) "*")
74 #define DAX_DEVICE_MODALIAS_FMT "dax:t%d"
75 
76 #endif /* __DAX_BUS_H__ */
77