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