File Index
Files and directories
Sign in
FILE

dax-private.h

File preview with syntax highlighting.

linux-6.19.14/drivers/dax/dax-private.h C
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Copyright(c) 2016 Intel Corporation. All rights reserved.
  4 */
  5#ifndef __DAX_PRIVATE_H__
  6#define __DAX_PRIVATE_H__
  7
  8#include <linux/device.h>
  9#include <linux/cdev.h>
 10#include <linux/idr.h>
 11
 12/* private routines between core files */
 13struct dax_device;
 14struct dax_device *inode_dax(struct inode *inode);
 15struct inode *dax_inode(struct dax_device *dax_dev);
 16int dax_bus_init(void);
 17void dax_bus_exit(void);
 18
 19/**
 20 * struct dax_region - mapping infrastructure for dax devices
 21 * @id: kernel-wide unique region for a memory range
 22 * @target_node: effective numa node if this memory range is onlined
 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
 26 * @ida: instance id allocator
 27 * @res: resource tree to track instance allocations
 28 * @seed: allow userspace to find the first unbound seed device
 29 * @youngest: allow userspace to find the most recently created device
 30 */
 31struct dax_region {
 32	int id;
 33	int target_node;
 34	struct kref kref;
 35	struct device *dev;
 36	unsigned int align;
 37	struct ida ida;
 38	struct resource res;
 39	struct device *seed;
 40	struct device *youngest;
 41};
 42
 43/**
 44 * struct dax_mapping - device to display mapping range attributes
 45 * @dev: device representing this range
 46 * @range_id: index within dev_dax ranges array
 47 * @id: ida of this mapping
 48 */
 49struct dax_mapping {
 50	struct device dev;
 51	int range_id;
 52	int id;
 53};
 54
 55/**
 56 * struct dev_dax_range - tuple represenging a range of memory used by dev_dax
 57 * @pgoff: page offset
 58 * @range: resource-span
 59 * @mapping: reference to the dax_mapping for this range
 60 */
 61struct dev_dax_range {
 62	unsigned long pgoff;
 63	struct range range;
 64	struct dax_mapping *mapping;
 65};
 66
 67/**
 68 * struct dev_dax - instance data for a subdivision of a dax region, and
 69 * data while the device is activated in the driver.
 70 * @region: parent region
 71 * @dax_dev: core dax functionality
 72 * @align: alignment of this instance
 73 * @target_node: effective numa node if dev_dax memory range is onlined
 74 * @dyn_id: is this a dynamic or statically created instance
 75 * @id: ida allocated id when the dax_region is not static
 76 * @ida: mapping id allocator
 77 * @dev: device core
 78 * @pgmap: pgmap for memmap setup / lifetime (driver owned)
 79 * @memmap_on_memory: allow kmem to put the memmap in the memory
 80 * @nr_range: size of @ranges
 81 * @ranges: range tuples of memory used
 82 */
 83struct dev_dax {
 84	struct dax_region *region;
 85	struct dax_device *dax_dev;
 86	unsigned int align;
 87	int target_node;
 88	bool dyn_id;
 89	int id;
 90	struct ida ida;
 91	struct device dev;
 92	struct dev_pagemap *pgmap;
 93	bool memmap_on_memory;
 94	int nr_range;
 95	struct dev_dax_range *ranges;
 96};
 97
 98/*
 99 * While run_dax() is potentially a generic operation that could be
100 * defined in include/linux/dax.h we don't want to grow any users
101 * outside of drivers/dax/
102 */
103void run_dax(struct dax_device *dax_dev);
104
105static inline struct dev_dax *to_dev_dax(struct device *dev)
106{
107	return container_of(dev, struct dev_dax, dev);
108}
109
110static inline struct dax_mapping *to_dax_mapping(struct device *dev)
111{
112	return container_of(dev, struct dax_mapping, dev);
113}
114
115phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, unsigned long size);
116
117#ifdef CONFIG_TRANSPARENT_HUGEPAGE
118static inline bool dax_align_valid(unsigned long align)
119{
120	if (align == PUD_SIZE && IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD))
121		return true;
122	if (align == PMD_SIZE && has_transparent_hugepage())
123		return true;
124	if (align == PAGE_SIZE)
125		return true;
126	return false;
127}
128#else
129static inline bool dax_align_valid(unsigned long align)
130{
131	return align == PAGE_SIZE;
132}
133#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
134#endif
~/ Read-only file preview.