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