]>
Commit | Line | Data |
---|---|---|
4d88a97a DW |
1 | /* |
2 | * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of version 2 of the GNU General Public License as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, but | |
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
11 | * General Public License for more details. | |
12 | */ | |
13 | #ifndef __LINUX_ND_H__ | |
14 | #define __LINUX_ND_H__ | |
8c2f7e86 | 15 | #include <linux/fs.h> |
4d88a97a DW |
16 | #include <linux/ndctl.h> |
17 | #include <linux/device.h> | |
200c79da | 18 | #include <linux/badblocks.h> |
4d88a97a | 19 | |
71999466 DW |
20 | enum nvdimm_event { |
21 | NVDIMM_REVALIDATE_POISON, | |
22 | }; | |
23 | ||
4d88a97a DW |
24 | struct nd_device_driver { |
25 | struct device_driver drv; | |
26 | unsigned long type; | |
27 | int (*probe)(struct device *dev); | |
28 | int (*remove)(struct device *dev); | |
476f848a | 29 | void (*shutdown)(struct device *dev); |
71999466 | 30 | void (*notify)(struct device *dev, enum nvdimm_event event); |
4d88a97a DW |
31 | }; |
32 | ||
33 | static 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); | |
3d88002e DW |
37 | }; |
38 | ||
8c2f7e86 DW |
39 | /** |
40 | * struct nd_namespace_common - core infrastructure of a namespace | |
41 | * @force_raw: ignore other personalities for the namespace (e.g. btt) | |
42 | * @dev: device model node | |
43 | * @claim: when set a another personality has taken ownership of the namespace | |
44 | * @rw_bytes: access the raw namespace capacity with byte-aligned transfers | |
45 | */ | |
46 | struct 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 | ||
54 | static inline struct nd_namespace_common *to_ndns(struct device *dev) | |
55 | { | |
56 | return container_of(dev, struct nd_namespace_common, dev); | |
57 | } | |
58 | ||
bf9bccc1 | 59 | /** |
200c79da | 60 | * struct nd_namespace_io - device representation of a persistent memory range |
bf9bccc1 DW |
61 | * @dev: namespace device created by the nd region driver |
62 | * @res: struct resource conversion of a NFIT SPA table | |
200c79da DW |
63 | * @size: cached resource_size(@res) for fast path size checks |
64 | * @addr: virtual address to access the namespace range | |
65 | * @bb: badblocks list for the namespace range | |
bf9bccc1 | 66 | */ |
3d88002e | 67 | struct nd_namespace_io { |
8c2f7e86 | 68 | struct nd_namespace_common common; |
3d88002e | 69 | struct resource res; |
200c79da | 70 | resource_size_t size; |
7a9eb206 | 71 | void *addr; |
200c79da | 72 | struct badblocks bb; |
3d88002e DW |
73 | }; |
74 | ||
bf9bccc1 DW |
75 | /** |
76 | * struct nd_namespace_pmem - namespace device for dimm-backed interleaved memory | |
77 | * @nsio: device and system physical address range to drive | |
78 | * @alt_name: namespace name supplied in the dimm label | |
79 | * @uuid: namespace name supplied in the dimm label | |
0e3b0d12 | 80 | * @id: ida allocated id |
bf9bccc1 DW |
81 | */ |
82 | struct nd_namespace_pmem { | |
83 | struct nd_namespace_io nsio; | |
84 | char *alt_name; | |
85 | u8 *uuid; | |
0e3b0d12 | 86 | int id; |
bf9bccc1 DW |
87 | }; |
88 | ||
1b40e09a DW |
89 | /** |
90 | * struct nd_namespace_blk - namespace for dimm-bounded persistent memory | |
1b40e09a DW |
91 | * @alt_name: namespace name supplied in the dimm label |
92 | * @uuid: namespace name supplied in the dimm label | |
93 | * @id: ida allocated id | |
94 | * @lbasize: blk namespaces have a native sector size when btt not present | |
9d90725d | 95 | * @size: sum of all the resource ranges allocated to this namespace |
1b40e09a DW |
96 | * @num_resources: number of dpa extents to claim |
97 | * @res: discontiguous dpa extents for given dimm | |
98 | */ | |
99 | struct nd_namespace_blk { | |
8c2f7e86 | 100 | struct nd_namespace_common common; |
1b40e09a DW |
101 | char *alt_name; |
102 | u8 *uuid; | |
103 | int id; | |
104 | unsigned long lbasize; | |
9d90725d | 105 | resource_size_t size; |
1b40e09a DW |
106 | int num_resources; |
107 | struct resource **res; | |
108 | }; | |
109 | ||
6ff3e912 | 110 | static inline struct nd_namespace_io *to_nd_namespace_io(const struct device *dev) |
3d88002e | 111 | { |
8c2f7e86 | 112 | return container_of(dev, struct nd_namespace_io, common.dev); |
4d88a97a DW |
113 | } |
114 | ||
6ff3e912 | 115 | static inline struct nd_namespace_pmem *to_nd_namespace_pmem(const struct device *dev) |
bf9bccc1 DW |
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 | ||
6ff3e912 | 122 | static inline struct nd_namespace_blk *to_nd_namespace_blk(const struct device *dev) |
1b40e09a | 123 | { |
8c2f7e86 DW |
124 | return container_of(dev, struct nd_namespace_blk, common.dev); |
125 | } | |
126 | ||
127 | /** | |
128 | * nvdimm_read_bytes() - synchronously read bytes from an nvdimm namespace | |
129 | * @ndns: device to read | |
130 | * @offset: namespace-relative starting offset | |
131 | * @buf: buffer to fill | |
132 | * @size: transfer length | |
133 | * | |
134 | * @buf is up-to-date upon return from this routine. | |
135 | */ | |
136 | static 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 | * nvdimm_write_bytes() - synchronously write bytes to an nvdimm namespace | |
144 | * @ndns: device to read | |
145 | * @offset: namespace-relative starting offset | |
146 | * @buf: buffer to drain | |
147 | * @size: transfer length | |
148 | * | |
149 | * NVDIMM Namepaces disks do not implement sectors internally. Depending on | |
150 | * the @ndns, the contents of @buf may be in cpu cache, platform buffers, | |
151 | * or on backing memory media upon return from this routine. Flushing | |
152 | * to media is handled internal to the @ndns driver, if at all. | |
153 | */ | |
154 | static 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); | |
1b40e09a DW |
158 | } |
159 | ||
4d88a97a DW |
160 | #define MODULE_ALIAS_ND_DEVICE(type) \ |
161 | MODULE_ALIAS("nd:t" __stringify(type) "*") | |
162 | #define ND_DEVICE_MODALIAS_FMT "nd:t%d" | |
163 | ||
71999466 DW |
164 | struct nd_region; |
165 | void nvdimm_region_notify(struct nd_region *nd_region, enum nvdimm_event event); | |
4d88a97a DW |
166 | int __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 /* __LINUX_ND_H__ */ |