Blame view
include/linux/nd.h
5.52 KB
5b497af42 treewide: Replace... |
1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
4d88a97aa libnvdimm, nvdimm... |
2 3 |
/* * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. |
4d88a97aa libnvdimm, nvdimm... |
4 5 6 |
*/ #ifndef __LINUX_ND_H__ #define __LINUX_ND_H__ |
8c2f7e865 libnvdimm: infras... |
7 |
#include <linux/fs.h> |
4d88a97aa libnvdimm, nvdimm... |
8 9 |
#include <linux/ndctl.h> #include <linux/device.h> |
200c79da8 libnvdimm, pmem, ... |
10 |
#include <linux/badblocks.h> |
4d88a97aa libnvdimm, nvdimm... |
11 |
|
719994660 libnvdimm: async ... |
12 13 14 |
enum nvdimm_event { NVDIMM_REVALIDATE_POISON, }; |
b3fde74ea libnvdimm, label:... |
15 16 17 |
enum nvdimm_claim_class { NVDIMM_CCLASS_NONE, NVDIMM_CCLASS_BTT, |
14e494542 libnvdimm, btt: B... |
18 |
NVDIMM_CCLASS_BTT2, |
b3fde74ea libnvdimm, label:... |
19 20 21 22 |
NVDIMM_CCLASS_PFN, NVDIMM_CCLASS_DAX, NVDIMM_CCLASS_UNKNOWN, }; |
4d88a97aa libnvdimm, nvdimm... |
23 24 25 26 27 |
struct nd_device_driver { struct device_driver drv; unsigned long type; int (*probe)(struct device *dev); int (*remove)(struct device *dev); |
476f848aa libnvdimm, pmem: ... |
28 |
void (*shutdown)(struct device *dev); |
719994660 libnvdimm: async ... |
29 |
void (*notify)(struct device *dev, enum nvdimm_event event); |
4d88a97aa libnvdimm, nvdimm... |
30 31 32 33 34 35 |
}; static inline struct nd_device_driver *to_nd_device_driver( struct device_driver *drv) { return container_of(drv, struct nd_device_driver, drv); |
3d88002e4 libnvdimm: suppor... |
36 |
}; |
bf9bccc14 libnvdimm: pmem l... |
37 |
/** |
8c2f7e865 libnvdimm: infras... |
38 39 40 41 |
* struct nd_namespace_common - core infrastructure of a namespace * @force_raw: ignore other personalities for the namespace (e.g. btt) * @dev: device model node * @claim: when set a another personality has taken ownership of the namespace |
b3fde74ea libnvdimm, label:... |
42 |
* @claim_class: restrict claim type to a given class |
8c2f7e865 libnvdimm: infras... |
43 44 45 46 47 48 |
* @rw_bytes: access the raw namespace capacity with byte-aligned transfers */ struct nd_namespace_common { int force_raw; struct device dev; struct device *claim; |
b3fde74ea libnvdimm, label:... |
49 |
enum nvdimm_claim_class claim_class; |
8c2f7e865 libnvdimm: infras... |
50 |
int (*rw_bytes)(struct nd_namespace_common *, resource_size_t offset, |
3ae3d67ba libnvdimm: add an... |
51 |
void *buf, size_t size, int rw, unsigned long flags); |
8c2f7e865 libnvdimm: infras... |
52 53 54 55 56 57 58 59 |
}; static inline struct nd_namespace_common *to_ndns(struct device *dev) { return container_of(dev, struct nd_namespace_common, dev); } /** |
200c79da8 libnvdimm, pmem, ... |
60 |
* struct nd_namespace_io - device representation of a persistent memory range |
bf9bccc14 libnvdimm: pmem l... |
61 62 |
* @dev: namespace device created by the nd region driver * @res: struct resource conversion of a NFIT SPA table |
200c79da8 libnvdimm, pmem, ... |
63 64 65 |
* @size: cached resource_size(@res) for fast path size checks * @addr: virtual address to access the namespace range * @bb: badblocks list for the namespace range |
bf9bccc14 libnvdimm: pmem l... |
66 |
*/ |
3d88002e4 libnvdimm: suppor... |
67 |
struct nd_namespace_io { |
8c2f7e865 libnvdimm: infras... |
68 |
struct nd_namespace_common common; |
3d88002e4 libnvdimm: suppor... |
69 |
struct resource res; |
200c79da8 libnvdimm, pmem, ... |
70 |
resource_size_t size; |
7a9eb2066 pmem: kill __pmem... |
71 |
void *addr; |
200c79da8 libnvdimm, pmem, ... |
72 |
struct badblocks bb; |
3d88002e4 libnvdimm: suppor... |
73 |
}; |
bf9bccc14 libnvdimm: pmem l... |
74 75 76 |
/** * struct nd_namespace_pmem - namespace device for dimm-backed interleaved memory * @nsio: device and system physical address range to drive |
f979b13c3 libnvdimm, label:... |
77 |
* @lbasize: logical sector size for the namespace in block-device-mode |
bf9bccc14 libnvdimm: pmem l... |
78 79 |
* @alt_name: namespace name supplied in the dimm label * @uuid: namespace name supplied in the dimm label |
0e3b0d123 libnvdimm, namesp... |
80 |
* @id: ida allocated id |
bf9bccc14 libnvdimm: pmem l... |
81 82 83 |
*/ struct nd_namespace_pmem { struct nd_namespace_io nsio; |
f979b13c3 libnvdimm, label:... |
84 |
unsigned long lbasize; |
bf9bccc14 libnvdimm: pmem l... |
85 86 |
char *alt_name; u8 *uuid; |
0e3b0d123 libnvdimm, namesp... |
87 |
int id; |
bf9bccc14 libnvdimm: pmem l... |
88 |
}; |
1b40e09a1 libnvdimm: blk la... |
89 90 |
/** * struct nd_namespace_blk - namespace for dimm-bounded persistent memory |
1b40e09a1 libnvdimm: blk la... |
91 92 93 94 |
* @alt_name: namespace name supplied in the dimm label * @uuid: namespace name supplied in the dimm label * @id: ida allocated id * @lbasize: blk namespaces have a native sector size when btt not present |
9d90725dd libnvdimm, blk: m... |
95 |
* @size: sum of all the resource ranges allocated to this namespace |
1b40e09a1 libnvdimm: blk la... |
96 97 98 99 |
* @num_resources: number of dpa extents to claim * @res: discontiguous dpa extents for given dimm */ struct nd_namespace_blk { |
8c2f7e865 libnvdimm: infras... |
100 |
struct nd_namespace_common common; |
1b40e09a1 libnvdimm: blk la... |
101 102 103 104 |
char *alt_name; u8 *uuid; int id; unsigned long lbasize; |
9d90725dd libnvdimm, blk: m... |
105 |
resource_size_t size; |
1b40e09a1 libnvdimm: blk la... |
106 107 108 |
int num_resources; struct resource **res; }; |
6ff3e912d libnvdimm, namesp... |
109 |
static inline struct nd_namespace_io *to_nd_namespace_io(const struct device *dev) |
3d88002e4 libnvdimm: suppor... |
110 |
{ |
8c2f7e865 libnvdimm: infras... |
111 |
return container_of(dev, struct nd_namespace_io, common.dev); |
4d88a97aa libnvdimm, nvdimm... |
112 |
} |
6ff3e912d libnvdimm, namesp... |
113 |
static inline struct nd_namespace_pmem *to_nd_namespace_pmem(const struct device *dev) |
bf9bccc14 libnvdimm: pmem l... |
114 115 116 117 118 |
{ struct nd_namespace_io *nsio = to_nd_namespace_io(dev); return container_of(nsio, struct nd_namespace_pmem, nsio); } |
6ff3e912d libnvdimm, namesp... |
119 |
static inline struct nd_namespace_blk *to_nd_namespace_blk(const struct device *dev) |
1b40e09a1 libnvdimm: blk la... |
120 |
{ |
8c2f7e865 libnvdimm: infras... |
121 122 123 124 125 126 127 128 129 130 131 132 133 |
return container_of(dev, struct nd_namespace_blk, common.dev); } /** * nvdimm_read_bytes() - synchronously read bytes from an nvdimm namespace * @ndns: device to read * @offset: namespace-relative starting offset * @buf: buffer to fill * @size: transfer length * * @buf is up-to-date upon return from this routine. */ static inline int nvdimm_read_bytes(struct nd_namespace_common *ndns, |
3ae3d67ba libnvdimm: add an... |
134 135 |
resource_size_t offset, void *buf, size_t size, unsigned long flags) |
8c2f7e865 libnvdimm: infras... |
136 |
{ |
3ae3d67ba libnvdimm: add an... |
137 |
return ndns->rw_bytes(ndns, offset, buf, size, READ, flags); |
8c2f7e865 libnvdimm: infras... |
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
} /** * nvdimm_write_bytes() - synchronously write bytes to an nvdimm namespace * @ndns: device to read * @offset: namespace-relative starting offset * @buf: buffer to drain * @size: transfer length * * NVDIMM Namepaces disks do not implement sectors internally. Depending on * the @ndns, the contents of @buf may be in cpu cache, platform buffers, * or on backing memory media upon return from this routine. Flushing * to media is handled internal to the @ndns driver, if at all. */ static inline int nvdimm_write_bytes(struct nd_namespace_common *ndns, |
3ae3d67ba libnvdimm: add an... |
153 154 |
resource_size_t offset, void *buf, size_t size, unsigned long flags) |
8c2f7e865 libnvdimm: infras... |
155 |
{ |
3ae3d67ba libnvdimm: add an... |
156 |
return ndns->rw_bytes(ndns, offset, buf, size, WRITE, flags); |
1b40e09a1 libnvdimm: blk la... |
157 |
} |
4d88a97aa libnvdimm, nvdimm... |
158 159 160 |
#define MODULE_ALIAS_ND_DEVICE(type) \ MODULE_ALIAS("nd:t" __stringify(type) "*") #define ND_DEVICE_MODALIAS_FMT "nd:t%d" |
719994660 libnvdimm: async ... |
161 162 |
struct nd_region; void nvdimm_region_notify(struct nd_region *nd_region, enum nvdimm_event event); |
4d88a97aa libnvdimm, nvdimm... |
163 164 |
int __must_check __nd_driver_register(struct nd_device_driver *nd_drv, struct module *module, const char *mod_name); |
71cfdd0ba libnvdimm: provid... |
165 166 167 168 |
static inline void nd_driver_unregister(struct nd_device_driver *drv) { driver_unregister(&drv->drv); } |
4d88a97aa libnvdimm, nvdimm... |
169 170 |
#define nd_driver_register(driver) \ __nd_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) |
71cfdd0ba libnvdimm: provid... |
171 172 |
#define module_nd_driver(driver) \ module_driver(driver, nd_driver_register, nd_driver_unregister) |
4d88a97aa libnvdimm, nvdimm... |
173 |
#endif /* __LINUX_ND_H__ */ |