]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/nd.h
acpi, nfit: constify *_attribute_group
[mirror_ubuntu-bionic-kernel.git] / include / linux / nd.h
CommitLineData
4d88a97a
DW
1/*
2 * Copyright(c) 2013-2015 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 __LINUX_ND_H__
14#define __LINUX_ND_H__
8c2f7e86 15#include <linux/fs.h>
4d88a97a
DW
16#include <linux/ndctl.h>
17#include <linux/device.h>
200c79da 18#include <linux/badblocks.h>
4d88a97a 19
71999466
DW
20enum nvdimm_event {
21 NVDIMM_REVALIDATE_POISON,
22};
23
b3fde74e
DW
24enum nvdimm_claim_class {
25 NVDIMM_CCLASS_NONE,
26 NVDIMM_CCLASS_BTT,
27 NVDIMM_CCLASS_PFN,
28 NVDIMM_CCLASS_DAX,
29 NVDIMM_CCLASS_UNKNOWN,
30};
31
4d88a97a
DW
32struct nd_device_driver {
33 struct device_driver drv;
34 unsigned long type;
35 int (*probe)(struct device *dev);
36 int (*remove)(struct device *dev);
476f848a 37 void (*shutdown)(struct device *dev);
71999466 38 void (*notify)(struct device *dev, enum nvdimm_event event);
4d88a97a
DW
39};
40
41static inline struct nd_device_driver *to_nd_device_driver(
42 struct device_driver *drv)
43{
44 return container_of(drv, struct nd_device_driver, drv);
3d88002e
DW
45};
46
8c2f7e86
DW
47/**
48 * struct nd_namespace_common - core infrastructure of a namespace
49 * @force_raw: ignore other personalities for the namespace (e.g. btt)
50 * @dev: device model node
51 * @claim: when set a another personality has taken ownership of the namespace
b3fde74e 52 * @claim_class: restrict claim type to a given class
8c2f7e86
DW
53 * @rw_bytes: access the raw namespace capacity with byte-aligned transfers
54 */
55struct nd_namespace_common {
56 int force_raw;
57 struct device dev;
58 struct device *claim;
b3fde74e 59 enum nvdimm_claim_class claim_class;
8c2f7e86 60 int (*rw_bytes)(struct nd_namespace_common *, resource_size_t offset,
3ae3d67b 61 void *buf, size_t size, int rw, unsigned long flags);
8c2f7e86
DW
62};
63
64static inline struct nd_namespace_common *to_ndns(struct device *dev)
65{
66 return container_of(dev, struct nd_namespace_common, dev);
67}
68
bf9bccc1 69/**
200c79da 70 * struct nd_namespace_io - device representation of a persistent memory range
bf9bccc1
DW
71 * @dev: namespace device created by the nd region driver
72 * @res: struct resource conversion of a NFIT SPA table
200c79da
DW
73 * @size: cached resource_size(@res) for fast path size checks
74 * @addr: virtual address to access the namespace range
75 * @bb: badblocks list for the namespace range
bf9bccc1 76 */
3d88002e 77struct nd_namespace_io {
8c2f7e86 78 struct nd_namespace_common common;
3d88002e 79 struct resource res;
200c79da 80 resource_size_t size;
7a9eb206 81 void *addr;
200c79da 82 struct badblocks bb;
3d88002e
DW
83};
84
bf9bccc1
DW
85/**
86 * struct nd_namespace_pmem - namespace device for dimm-backed interleaved memory
87 * @nsio: device and system physical address range to drive
f979b13c 88 * @lbasize: logical sector size for the namespace in block-device-mode
bf9bccc1
DW
89 * @alt_name: namespace name supplied in the dimm label
90 * @uuid: namespace name supplied in the dimm label
0e3b0d12 91 * @id: ida allocated id
bf9bccc1
DW
92 */
93struct nd_namespace_pmem {
94 struct nd_namespace_io nsio;
f979b13c 95 unsigned long lbasize;
bf9bccc1
DW
96 char *alt_name;
97 u8 *uuid;
0e3b0d12 98 int id;
bf9bccc1
DW
99};
100
1b40e09a
DW
101/**
102 * struct nd_namespace_blk - namespace for dimm-bounded persistent memory
1b40e09a
DW
103 * @alt_name: namespace name supplied in the dimm label
104 * @uuid: namespace name supplied in the dimm label
105 * @id: ida allocated id
106 * @lbasize: blk namespaces have a native sector size when btt not present
9d90725d 107 * @size: sum of all the resource ranges allocated to this namespace
1b40e09a
DW
108 * @num_resources: number of dpa extents to claim
109 * @res: discontiguous dpa extents for given dimm
110 */
111struct nd_namespace_blk {
8c2f7e86 112 struct nd_namespace_common common;
1b40e09a
DW
113 char *alt_name;
114 u8 *uuid;
115 int id;
116 unsigned long lbasize;
9d90725d 117 resource_size_t size;
1b40e09a
DW
118 int num_resources;
119 struct resource **res;
120};
121
6ff3e912 122static inline struct nd_namespace_io *to_nd_namespace_io(const struct device *dev)
3d88002e 123{
8c2f7e86 124 return container_of(dev, struct nd_namespace_io, common.dev);
4d88a97a
DW
125}
126
6ff3e912 127static inline struct nd_namespace_pmem *to_nd_namespace_pmem(const struct device *dev)
bf9bccc1
DW
128{
129 struct nd_namespace_io *nsio = to_nd_namespace_io(dev);
130
131 return container_of(nsio, struct nd_namespace_pmem, nsio);
132}
133
6ff3e912 134static inline struct nd_namespace_blk *to_nd_namespace_blk(const struct device *dev)
1b40e09a 135{
8c2f7e86
DW
136 return container_of(dev, struct nd_namespace_blk, common.dev);
137}
138
139/**
140 * nvdimm_read_bytes() - synchronously read bytes from an nvdimm namespace
141 * @ndns: device to read
142 * @offset: namespace-relative starting offset
143 * @buf: buffer to fill
144 * @size: transfer length
145 *
146 * @buf is up-to-date upon return from this routine.
147 */
148static inline int nvdimm_read_bytes(struct nd_namespace_common *ndns,
3ae3d67b
VV
149 resource_size_t offset, void *buf, size_t size,
150 unsigned long flags)
8c2f7e86 151{
3ae3d67b 152 return ndns->rw_bytes(ndns, offset, buf, size, READ, flags);
8c2f7e86
DW
153}
154
155/**
156 * nvdimm_write_bytes() - synchronously write bytes to an nvdimm namespace
157 * @ndns: device to read
158 * @offset: namespace-relative starting offset
159 * @buf: buffer to drain
160 * @size: transfer length
161 *
162 * NVDIMM Namepaces disks do not implement sectors internally. Depending on
163 * the @ndns, the contents of @buf may be in cpu cache, platform buffers,
164 * or on backing memory media upon return from this routine. Flushing
165 * to media is handled internal to the @ndns driver, if at all.
166 */
167static inline int nvdimm_write_bytes(struct nd_namespace_common *ndns,
3ae3d67b
VV
168 resource_size_t offset, void *buf, size_t size,
169 unsigned long flags)
8c2f7e86 170{
3ae3d67b 171 return ndns->rw_bytes(ndns, offset, buf, size, WRITE, flags);
1b40e09a
DW
172}
173
4d88a97a
DW
174#define MODULE_ALIAS_ND_DEVICE(type) \
175 MODULE_ALIAS("nd:t" __stringify(type) "*")
176#define ND_DEVICE_MODALIAS_FMT "nd:t%d"
177
71999466
DW
178struct nd_region;
179void nvdimm_region_notify(struct nd_region *nd_region, enum nvdimm_event event);
4d88a97a
DW
180int __must_check __nd_driver_register(struct nd_device_driver *nd_drv,
181 struct module *module, const char *mod_name);
182#define nd_driver_register(driver) \
183 __nd_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
184#endif /* __LINUX_ND_H__ */