1
2
3
4
5#ifndef __LINUX_ND_H__
6#define __LINUX_ND_H__
7#include <linux/fs.h>
8#include <linux/ndctl.h>
9#include <linux/device.h>
10#include <linux/badblocks.h>
11
12enum nvdimm_event {
13 NVDIMM_REVALIDATE_POISON,
14 NVDIMM_REVALIDATE_REGION,
15};
16
17enum nvdimm_claim_class {
18 NVDIMM_CCLASS_NONE,
19 NVDIMM_CCLASS_BTT,
20 NVDIMM_CCLASS_BTT2,
21 NVDIMM_CCLASS_PFN,
22 NVDIMM_CCLASS_DAX,
23 NVDIMM_CCLASS_UNKNOWN,
24};
25
26struct nd_device_driver {
27 struct device_driver drv;
28 unsigned long type;
29 int (*probe)(struct device *dev);
30 void (*remove)(struct device *dev);
31 void (*shutdown)(struct device *dev);
32 void (*notify)(struct device *dev, enum nvdimm_event event);
33};
34
35static inline struct nd_device_driver *to_nd_device_driver(
36 struct device_driver *drv)
37{
38 return container_of(drv, struct nd_device_driver, drv);
39};
40
41
42
43
44
45
46
47
48
49struct nd_namespace_common {
50 int force_raw;
51 struct device dev;
52 struct device *claim;
53 enum nvdimm_claim_class claim_class;
54 int (*rw_bytes)(struct nd_namespace_common *, resource_size_t offset,
55 void *buf, size_t size, int rw, unsigned long flags);
56};
57
58static inline struct nd_namespace_common *to_ndns(struct device *dev)
59{
60 return container_of(dev, struct nd_namespace_common, dev);
61}
62
63
64
65
66
67
68
69
70
71struct nd_namespace_io {
72 struct nd_namespace_common common;
73 struct resource res;
74 resource_size_t size;
75 void *addr;
76 struct badblocks bb;
77};
78
79
80
81
82
83
84
85
86
87struct nd_namespace_pmem {
88 struct nd_namespace_io nsio;
89 unsigned long lbasize;
90 char *alt_name;
91 u8 *uuid;
92 int id;
93};
94
95
96
97
98
99
100
101
102
103
104
105struct nd_namespace_blk {
106 struct nd_namespace_common common;
107 char *alt_name;
108 u8 *uuid;
109 int id;
110 unsigned long lbasize;
111 resource_size_t size;
112 int num_resources;
113 struct resource **res;
114};
115
116static inline struct nd_namespace_io *to_nd_namespace_io(const struct device *dev)
117{
118 return container_of(dev, struct nd_namespace_io, common.dev);
119}
120
121static inline struct nd_namespace_pmem *to_nd_namespace_pmem(const struct device *dev)
122{
123 struct nd_namespace_io *nsio = to_nd_namespace_io(dev);
124
125 return container_of(nsio, struct nd_namespace_pmem, nsio);
126}
127
128static inline struct nd_namespace_blk *to_nd_namespace_blk(const struct device *dev)
129{
130 return container_of(dev, struct nd_namespace_blk, common.dev);
131}
132
133
134
135
136
137
138
139
140
141
142static inline int nvdimm_read_bytes(struct nd_namespace_common *ndns,
143 resource_size_t offset, void *buf, size_t size,
144 unsigned long flags)
145{
146 return ndns->rw_bytes(ndns, offset, buf, size, READ, flags);
147}
148
149
150
151
152
153
154
155
156
157
158
159
160
161static inline int nvdimm_write_bytes(struct nd_namespace_common *ndns,
162 resource_size_t offset, void *buf, size_t size,
163 unsigned long flags)
164{
165 return ndns->rw_bytes(ndns, offset, buf, size, WRITE, flags);
166}
167
168#define MODULE_ALIAS_ND_DEVICE(type) \
169 MODULE_ALIAS("nd:t" __stringify(type) "*")
170#define ND_DEVICE_MODALIAS_FMT "nd:t%d"
171
172struct nd_region;
173void nvdimm_region_notify(struct nd_region *nd_region, enum nvdimm_event event);
174int __must_check __nd_driver_register(struct nd_device_driver *nd_drv,
175 struct module *module, const char *mod_name);
176static inline void nd_driver_unregister(struct nd_device_driver *drv)
177{
178 driver_unregister(&drv->drv);
179}
180#define nd_driver_register(driver) \
181 __nd_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
182#define module_nd_driver(driver) \
183 module_driver(driver, nd_driver_register, nd_driver_unregister)
184#endif
185