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