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 DAXDRV_FSDEV_TYPE, 37 }; 38 39 struct dax_device_driver { 40 struct device_driver drv; 41 struct list_head ids; 42 enum dax_driver_type type; 43 int (*probe)(struct dev_dax *dev); 44 void (*remove)(struct dev_dax *dev); 45 }; 46 47 #define to_dax_drv(__drv) container_of_const(__drv, struct dax_device_driver, drv) 48 49 int __dax_driver_register(struct dax_device_driver *dax_drv, 50 struct module *module, const char *mod_name); 51 #define dax_driver_register(driver) \ 52 __dax_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) 53 void dax_driver_unregister(struct dax_device_driver *dax_drv); 54 void kill_dev_dax(struct dev_dax *dev_dax); 55 bool static_dev_dax(struct dev_dax *dev_dax); 56 57 struct hmem_platform_device { 58 struct platform_device pdev; 59 struct work_struct work; 60 bool did_probe; 61 }; 62 63 static inline struct hmem_platform_device * 64 to_hmem_platform_device(struct platform_device *pdev) 65 { 66 return container_of(pdev, struct hmem_platform_device, pdev); 67 } 68 69 #if IS_ENABLED(CONFIG_DEV_DAX_HMEM) 70 void dax_hmem_flush_work(void); 71 #else 72 static inline void dax_hmem_flush_work(void) { } 73 #endif 74 75 #define MODULE_ALIAS_DAX_DEVICE(type) \ 76 MODULE_ALIAS("dax:t" __stringify(type) "*") 77 #define DAX_DEVICE_MODALIAS_FMT "dax:t%d" 78 79 #endif /* __DAX_BUS_H__ */ 80