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