Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright(c) 2016 Intel Corporation. All rights reserved.
0004  */
0005 #ifndef __DAX_PRIVATE_H__
0006 #define __DAX_PRIVATE_H__
0007 
0008 #include <linux/device.h>
0009 #include <linux/cdev.h>
0010 #include <linux/idr.h>
0011 
0012 /* private routines between core files */
0013 struct dax_device;
0014 struct dax_device *inode_dax(struct inode *inode);
0015 struct inode *dax_inode(struct dax_device *dax_dev);
0016 int dax_bus_init(void);
0017 void dax_bus_exit(void);
0018 
0019 /**
0020  * struct dax_region - mapping infrastructure for dax devices
0021  * @id: kernel-wide unique region for a memory range
0022  * @target_node: effective numa node if this memory range is onlined
0023  * @kref: to pin while other agents have a need to do lookups
0024  * @dev: parent device backing this region
0025  * @align: allocation and mapping alignment for child dax devices
0026  * @ida: instance id allocator
0027  * @res: resource tree to track instance allocations
0028  * @seed: allow userspace to find the first unbound seed device
0029  * @youngest: allow userspace to find the most recently created device
0030  */
0031 struct dax_region {
0032     int id;
0033     int target_node;
0034     struct kref kref;
0035     struct device *dev;
0036     unsigned int align;
0037     struct ida ida;
0038     struct resource res;
0039     struct device *seed;
0040     struct device *youngest;
0041 };
0042 
0043 struct dax_mapping {
0044     struct device dev;
0045     int range_id;
0046     int id;
0047 };
0048 
0049 /**
0050  * struct dev_dax - instance data for a subdivision of a dax region, and
0051  * data while the device is activated in the driver.
0052  * @region - parent region
0053  * @dax_dev - core dax functionality
0054  * @target_node: effective numa node if dev_dax memory range is onlined
0055  * @id: ida allocated id
0056  * @ida: mapping id allocator
0057  * @dev - device core
0058  * @pgmap - pgmap for memmap setup / lifetime (driver owned)
0059  * @nr_range: size of @ranges
0060  * @ranges: resource-span + pgoff tuples for the instance
0061  */
0062 struct dev_dax {
0063     struct dax_region *region;
0064     struct dax_device *dax_dev;
0065     unsigned int align;
0066     int target_node;
0067     int id;
0068     struct ida ida;
0069     struct device dev;
0070     struct dev_pagemap *pgmap;
0071     int nr_range;
0072     struct dev_dax_range {
0073         unsigned long pgoff;
0074         struct range range;
0075         struct dax_mapping *mapping;
0076     } *ranges;
0077 };
0078 
0079 static inline struct dev_dax *to_dev_dax(struct device *dev)
0080 {
0081     return container_of(dev, struct dev_dax, dev);
0082 }
0083 
0084 static inline struct dax_mapping *to_dax_mapping(struct device *dev)
0085 {
0086     return container_of(dev, struct dax_mapping, dev);
0087 }
0088 
0089 phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, unsigned long size);
0090 
0091 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
0092 static inline bool dax_align_valid(unsigned long align)
0093 {
0094     if (align == PUD_SIZE && IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD))
0095         return true;
0096     if (align == PMD_SIZE && has_transparent_hugepage())
0097         return true;
0098     if (align == PAGE_SIZE)
0099         return true;
0100     return false;
0101 }
0102 #else
0103 static inline bool dax_align_valid(unsigned long align)
0104 {
0105     return align == PAGE_SIZE;
0106 }
0107 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
0108 #endif