blob: a45612148ca021e96ff3c8cf60eab9b4071fb858 [file] [log] [blame]
Dave Jiangefebc712017-04-07 15:33:36 -07001/*
2 * Copyright(c) 2016 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13#ifndef __DAX_PRIVATE_H__
14#define __DAX_PRIVATE_H__
15
16#include <linux/device.h>
17#include <linux/cdev.h>
18
Dan Williams51cf7842017-07-12 17:58:21 -070019/* private routines between core files */
20struct dax_device;
21struct dax_device *inode_dax(struct inode *inode);
22struct inode *dax_inode(struct dax_device *dax_dev);
Dan Williams9567da02017-07-12 17:58:21 -070023int dax_bus_init(void);
24void dax_bus_exit(void);
Dan Williams51cf7842017-07-12 17:58:21 -070025
Dave Jiangefebc712017-04-07 15:33:36 -070026/**
27 * struct dax_region - mapping infrastructure for dax devices
28 * @id: kernel-wide unique region for a memory range
Dan Williams8fc5c732018-11-09 12:43:07 -080029 * @target_node: effective numa node if this memory range is onlined
Dave Jiangefebc712017-04-07 15:33:36 -070030 * @kref: to pin while other agents have a need to do lookups
31 * @dev: parent device backing this region
32 * @align: allocation and mapping alignment for child dax devices
33 * @res: physical address range of the region
34 * @pfn_flags: identify whether the pfns are paged back or not
35 */
36struct dax_region {
37 int id;
Dan Williams8fc5c732018-11-09 12:43:07 -080038 int target_node;
Dave Jiangefebc712017-04-07 15:33:36 -070039 struct kref kref;
40 struct device *dev;
41 unsigned int align;
42 struct resource res;
43 unsigned long pfn_flags;
44};
45
46/**
Dan Williams89ec9f22018-10-29 15:52:42 -070047 * struct dev_dax - instance data for a subdivision of a dax region, and
48 * data while the device is activated in the driver.
Dave Jiangefebc712017-04-07 15:33:36 -070049 * @region - parent region
Dan Williams73616362017-05-04 23:38:43 -070050 * @dax_dev - core dax functionality
Dan Williams8fc5c732018-11-09 12:43:07 -080051 * @target_node: effective numa node if dev_dax memory range is onlined
Dan Williams73616362017-05-04 23:38:43 -070052 * @dev - device core
Dan Williams89ec9f22018-10-29 15:52:42 -070053 * @pgmap - pgmap for memmap setup / lifetime (driver owned)
54 * @ref: pgmap reference count (driver owned)
55 * @cmp: @ref final put completion (driver owned)
Dave Jiangefebc712017-04-07 15:33:36 -070056 */
Dan Williams73616362017-05-04 23:38:43 -070057struct dev_dax {
Dave Jiangefebc712017-04-07 15:33:36 -070058 struct dax_region *region;
Dan Williams73616362017-05-04 23:38:43 -070059 struct dax_device *dax_dev;
Dan Williams8fc5c732018-11-09 12:43:07 -080060 int target_node;
Dave Jiangefebc712017-04-07 15:33:36 -070061 struct device dev;
Dan Williams89ec9f22018-10-29 15:52:42 -070062 struct dev_pagemap pgmap;
63 struct percpu_ref ref;
64 struct completion cmp;
Dave Jiangefebc712017-04-07 15:33:36 -070065};
Dan Williams51cf7842017-07-12 17:58:21 -070066
67static inline struct dev_dax *to_dev_dax(struct device *dev)
68{
69 return container_of(dev, struct dev_dax, dev);
70}
Dave Jiangefebc712017-04-07 15:33:36 -070071#endif