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