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 #define DAX_KMEM_UNPLUGGED (-1) /* Do not create memory blocks */ 20 21 struct dax_region *alloc_dax_region(struct device *parent, int region_id, 22 struct range *range, int target_node, unsigned int align, 23 unsigned long flags); 24 25 struct dev_dax_data { 26 struct dax_region *dax_region; 27 struct dev_pagemap *pgmap; 28 resource_size_t size; 29 int id; 30 bool memmap_on_memory; 31 }; 32 33 struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data); 34 35 enum dax_driver_type { 36 DAXDRV_KMEM_TYPE, 37 DAXDRV_DEVICE_TYPE, 38 DAXDRV_FSDEV_TYPE, 39 }; 40 41 struct dax_device_driver { 42 struct device_driver drv; 43 struct list_head ids; 44 enum dax_driver_type type; 45 int (*probe)(struct dev_dax *dev); 46 void (*remove)(struct dev_dax *dev); 47 }; 48 49 #define to_dax_drv(__drv) container_of_const(__drv, struct dax_device_driver, drv) 50 51 int __dax_driver_register(struct dax_device_driver *dax_drv, 52 struct module *module, const char *mod_name); 53 #define dax_driver_register(driver) \ 54 __dax_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) 55 void dax_driver_unregister(struct dax_device_driver *dax_drv); 56 void kill_dev_dax(struct dev_dax *dev_dax); 57 bool static_dev_dax(struct dev_dax *dev_dax); 58 59 struct hmem_platform_device { 60 struct platform_device pdev; 61 struct work_struct work; 62 bool did_probe; 63 }; 64 65 static inline struct hmem_platform_device * 66 to_hmem_platform_device(struct platform_device *pdev) 67 { 68 return container_of(pdev, struct hmem_platform_device, pdev); 69 } 70 71 #if IS_ENABLED(CONFIG_DEV_DAX_HMEM) 72 void dax_hmem_flush_work(void); 73 #else 74 static inline void dax_hmem_flush_work(void) { } 75 #endif 76 77 #define MODULE_ALIAS_DAX_DEVICE(type) \ 78 MODULE_ALIAS("dax:t" __stringify(type) "*") 79 #define DAX_DEVICE_MODALIAS_FMT "dax:t%d" 80 81 #endif /* __DAX_BUS_H__ */ 82