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