Thomas Gleixner | 5b497af | 2019-05-29 07:18:09 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright(c) 2016 Intel Corporation. All rights reserved. |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 4 | */ |
| 5 | #ifndef __DAX_PRIVATE_H__ |
| 6 | #define __DAX_PRIVATE_H__ |
| 7 | |
| 8 | #include <linux/device.h> |
| 9 | #include <linux/cdev.h> |
Dan Williams | 0f3da14 | 2020-10-13 16:50:13 -0700 | [diff] [blame] | 10 | #include <linux/idr.h> |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 11 | |
Dan Williams | 51cf784 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 12 | /* private routines between core files */ |
| 13 | struct dax_device; |
| 14 | struct dax_device *inode_dax(struct inode *inode); |
| 15 | struct inode *dax_inode(struct dax_device *dax_dev); |
Dan Williams | 9567da0 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 16 | int dax_bus_init(void); |
| 17 | void dax_bus_exit(void); |
Dan Williams | 51cf784 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 18 | |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 19 | /** |
| 20 | * struct dax_region - mapping infrastructure for dax devices |
| 21 | * @id: kernel-wide unique region for a memory range |
Dan Williams | 8fc5c73 | 2018-11-09 12:43:07 -0800 | [diff] [blame] | 22 | * @target_node: effective numa node if this memory range is onlined |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 23 | * @kref: to pin while other agents have a need to do lookups |
| 24 | * @dev: parent device backing this region |
| 25 | * @align: allocation and mapping alignment for child dax devices |
Dan Williams | 0f3da14 | 2020-10-13 16:50:13 -0700 | [diff] [blame] | 26 | * @ida: instance id allocator |
Dan Williams | c2f3011 | 2020-10-13 16:50:03 -0700 | [diff] [blame] | 27 | * @res: resource tree to track instance allocations |
Dan Williams | 0f3da14 | 2020-10-13 16:50:13 -0700 | [diff] [blame] | 28 | * @seed: allow userspace to find the first unbound seed device |
| 29 | * @youngest: allow userspace to find the most recently created device |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 30 | */ |
| 31 | struct dax_region { |
| 32 | int id; |
Dan Williams | 8fc5c73 | 2018-11-09 12:43:07 -0800 | [diff] [blame] | 33 | int target_node; |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 34 | struct kref kref; |
| 35 | struct device *dev; |
| 36 | unsigned int align; |
Dan Williams | 0f3da14 | 2020-10-13 16:50:13 -0700 | [diff] [blame] | 37 | struct ida ida; |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 38 | struct resource res; |
Dan Williams | 0f3da14 | 2020-10-13 16:50:13 -0700 | [diff] [blame] | 39 | struct device *seed; |
| 40 | struct device *youngest; |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Dan Williams | 0b07ce8 | 2020-10-13 16:50:45 -0700 | [diff] [blame] | 43 | struct dax_mapping { |
| 44 | struct device dev; |
| 45 | int range_id; |
| 46 | int id; |
| 47 | }; |
| 48 | |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 49 | /** |
Dan Williams | 89ec9f2 | 2018-10-29 15:52:42 -0700 | [diff] [blame] | 50 | * struct dev_dax - instance data for a subdivision of a dax region, and |
| 51 | * data while the device is activated in the driver. |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 52 | * @region - parent region |
Dan Williams | 7361636 | 2017-05-04 23:38:43 -0700 | [diff] [blame] | 53 | * @dax_dev - core dax functionality |
Dan Williams | 8fc5c73 | 2018-11-09 12:43:07 -0800 | [diff] [blame] | 54 | * @target_node: effective numa node if dev_dax memory range is onlined |
Dan Williams | 0f3da14 | 2020-10-13 16:50:13 -0700 | [diff] [blame] | 55 | * @id: ida allocated id |
Dan Williams | 0b07ce8 | 2020-10-13 16:50:45 -0700 | [diff] [blame] | 56 | * @ida: mapping id allocator |
Dan Williams | 7361636 | 2017-05-04 23:38:43 -0700 | [diff] [blame] | 57 | * @dev - device core |
Dan Williams | 89ec9f2 | 2018-10-29 15:52:42 -0700 | [diff] [blame] | 58 | * @pgmap - pgmap for memmap setup / lifetime (driver owned) |
Dan Williams | 60e93dc | 2020-10-13 16:50:39 -0700 | [diff] [blame] | 59 | * @nr_range: size of @ranges |
| 60 | * @ranges: resource-span + pgoff tuples for the instance |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 61 | */ |
Dan Williams | 7361636 | 2017-05-04 23:38:43 -0700 | [diff] [blame] | 62 | struct dev_dax { |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 63 | struct dax_region *region; |
Dan Williams | 7361636 | 2017-05-04 23:38:43 -0700 | [diff] [blame] | 64 | struct dax_device *dax_dev; |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 65 | unsigned int align; |
Dan Williams | 8fc5c73 | 2018-11-09 12:43:07 -0800 | [diff] [blame] | 66 | int target_node; |
Dan Williams | 0f3da14 | 2020-10-13 16:50:13 -0700 | [diff] [blame] | 67 | int id; |
Dan Williams | 0b07ce8 | 2020-10-13 16:50:45 -0700 | [diff] [blame] | 68 | struct ida ida; |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 69 | struct device dev; |
Dan Williams | f5516ec | 2020-10-13 16:49:43 -0700 | [diff] [blame] | 70 | struct dev_pagemap *pgmap; |
Dan Williams | 60e93dc | 2020-10-13 16:50:39 -0700 | [diff] [blame] | 71 | int nr_range; |
| 72 | struct dev_dax_range { |
| 73 | unsigned long pgoff; |
| 74 | struct range range; |
Dan Williams | 0b07ce8 | 2020-10-13 16:50:45 -0700 | [diff] [blame] | 75 | struct dax_mapping *mapping; |
Dan Williams | 60e93dc | 2020-10-13 16:50:39 -0700 | [diff] [blame] | 76 | } *ranges; |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 77 | }; |
Dan Williams | 51cf784 | 2017-07-12 17:58:21 -0700 | [diff] [blame] | 78 | |
| 79 | static inline struct dev_dax *to_dev_dax(struct device *dev) |
| 80 | { |
| 81 | return container_of(dev, struct dev_dax, dev); |
| 82 | } |
Dan Williams | 0b07ce8 | 2020-10-13 16:50:45 -0700 | [diff] [blame] | 83 | |
| 84 | static inline struct dax_mapping *to_dax_mapping(struct device *dev) |
| 85 | { |
| 86 | return container_of(dev, struct dax_mapping, dev); |
| 87 | } |
Joao Martins | 33cf94d | 2020-10-13 16:50:50 -0700 | [diff] [blame] | 88 | |
| 89 | phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, unsigned long size); |
Dan Williams | 6d82120 | 2020-10-13 16:50:55 -0700 | [diff] [blame] | 90 | |
| 91 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 92 | static inline bool dax_align_valid(unsigned long align) |
| 93 | { |
| 94 | if (align == PUD_SIZE && IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)) |
| 95 | return true; |
| 96 | if (align == PMD_SIZE && has_transparent_hugepage()) |
| 97 | return true; |
| 98 | if (align == PAGE_SIZE) |
| 99 | return true; |
| 100 | return false; |
| 101 | } |
| 102 | #else |
| 103 | static inline bool dax_align_valid(unsigned long align) |
| 104 | { |
| 105 | return align == PAGE_SIZE; |
| 106 | } |
| 107 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
Dave Jiang | efebc71 | 2017-04-07 15:33:36 -0700 | [diff] [blame] | 108 | #endif |