1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef __ND_CORE_H__
14#define __ND_CORE_H__
15#include <linux/libnvdimm.h>
16#include <linux/device.h>
17#include <linux/sizes.h>
18#include <linux/mutex.h>
19#include <linux/nd.h>
20
21extern struct list_head nvdimm_bus_list;
22extern struct mutex nvdimm_bus_list_mutex;
23extern int nvdimm_major;
24extern struct workqueue_struct *nvdimm_wq;
25
26struct nvdimm_bus {
27 struct nvdimm_bus_descriptor *nd_desc;
28 wait_queue_head_t wait;
29 struct list_head list;
30 struct device dev;
31 int id, probe_active;
32 atomic_t ioctl_active;
33 struct list_head mapping_list;
34 struct mutex reconfig_mutex;
35 struct badrange badrange;
36};
37
38struct nvdimm {
39 unsigned long flags;
40 void *provider_data;
41 unsigned long cmd_mask;
42 struct device dev;
43 atomic_t busy;
44 int id, num_flush;
45 struct resource *flush_wpq;
46 const char *dimm_id;
47 struct {
48 const struct nvdimm_security_ops *ops;
49 unsigned long flags;
50 unsigned long ext_flags;
51 unsigned int overwrite_tmo;
52 struct kernfs_node *overwrite_state;
53 } sec;
54 struct delayed_work dwork;
55};
56
57static inline unsigned long nvdimm_security_flags(
58 struct nvdimm *nvdimm, enum nvdimm_passphrase_type ptype)
59{
60 u64 flags;
61 const u64 state_flags = 1UL << NVDIMM_SECURITY_DISABLED
62 | 1UL << NVDIMM_SECURITY_LOCKED
63 | 1UL << NVDIMM_SECURITY_UNLOCKED
64 | 1UL << NVDIMM_SECURITY_OVERWRITE;
65
66 if (!nvdimm->sec.ops)
67 return 0;
68
69 flags = nvdimm->sec.ops->get_flags(nvdimm, ptype);
70
71 dev_WARN_ONCE(&nvdimm->dev, hweight64(flags & state_flags) > 1,
72 "reported invalid security state: %#llx\n",
73 (unsigned long long) flags);
74 return flags;
75}
76int nvdimm_security_freeze(struct nvdimm *nvdimm);
77#if IS_ENABLED(CONFIG_NVDIMM_KEYS)
78ssize_t nvdimm_security_store(struct device *dev, const char *buf, size_t len);
79void nvdimm_security_overwrite_query(struct work_struct *work);
80#else
81static inline ssize_t nvdimm_security_store(struct device *dev,
82 const char *buf, size_t len)
83{
84 return -EOPNOTSUPP;
85}
86static inline void nvdimm_security_overwrite_query(struct work_struct *work)
87{
88}
89#endif
90
91
92
93
94
95
96
97
98
99
100
101
102struct blk_alloc_info {
103 struct nd_mapping *nd_mapping;
104 resource_size_t available, busy;
105 struct resource *res;
106};
107
108bool is_nvdimm(struct device *dev);
109bool is_nd_pmem(struct device *dev);
110bool is_nd_volatile(struct device *dev);
111bool is_nd_blk(struct device *dev);
112static inline bool is_nd_region(struct device *dev)
113{
114 return is_nd_pmem(dev) || is_nd_blk(dev) || is_nd_volatile(dev);
115}
116static inline bool is_memory(struct device *dev)
117{
118 return is_nd_pmem(dev) || is_nd_volatile(dev);
119}
120struct nvdimm_bus *walk_to_nvdimm_bus(struct device *nd_dev);
121int __init nvdimm_bus_init(void);
122void nvdimm_bus_exit(void);
123void nvdimm_devs_exit(void);
124struct nd_region;
125void nd_region_advance_seeds(struct nd_region *nd_region, struct device *dev);
126void nd_region_create_ns_seed(struct nd_region *nd_region);
127void nd_region_create_btt_seed(struct nd_region *nd_region);
128void nd_region_create_pfn_seed(struct nd_region *nd_region);
129void nd_region_create_dax_seed(struct nd_region *nd_region);
130int nvdimm_bus_create_ndctl(struct nvdimm_bus *nvdimm_bus);
131void nvdimm_bus_destroy_ndctl(struct nvdimm_bus *nvdimm_bus);
132void nd_synchronize(void);
133int nvdimm_bus_register_dimms(struct nvdimm_bus *nvdimm_bus);
134int nvdimm_bus_register_regions(struct nvdimm_bus *nvdimm_bus);
135int nvdimm_bus_init_interleave_sets(struct nvdimm_bus *nvdimm_bus);
136void __nd_device_register(struct device *dev);
137int nd_match_dimm(struct device *dev, void *data);
138struct nd_label_id;
139char *nd_label_gen_id(struct nd_label_id *label_id, u8 *uuid, u32 flags);
140bool nd_is_uuid_unique(struct device *dev, u8 *uuid);
141struct nd_region;
142struct nvdimm_drvdata;
143struct nd_mapping;
144void nd_mapping_free_labels(struct nd_mapping *nd_mapping);
145
146int __reserve_free_pmem(struct device *dev, void *data);
147void release_free_pmem(struct nvdimm_bus *nvdimm_bus,
148 struct nd_mapping *nd_mapping);
149
150resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region,
151 struct nd_mapping *nd_mapping);
152resource_size_t nd_region_allocatable_dpa(struct nd_region *nd_region);
153resource_size_t nd_pmem_available_dpa(struct nd_region *nd_region,
154 struct nd_mapping *nd_mapping, resource_size_t *overlap);
155resource_size_t nd_blk_available_dpa(struct nd_region *nd_region);
156resource_size_t nd_region_available_dpa(struct nd_region *nd_region);
157int nd_region_conflict(struct nd_region *nd_region, resource_size_t start,
158 resource_size_t size);
159resource_size_t nvdimm_allocated_dpa(struct nvdimm_drvdata *ndd,
160 struct nd_label_id *label_id);
161int alias_dpa_busy(struct device *dev, void *data);
162struct resource *nsblk_add_resource(struct nd_region *nd_region,
163 struct nvdimm_drvdata *ndd, struct nd_namespace_blk *nsblk,
164 resource_size_t start);
165int nvdimm_num_label_slots(struct nvdimm_drvdata *ndd);
166void get_ndd(struct nvdimm_drvdata *ndd);
167resource_size_t __nvdimm_namespace_capacity(struct nd_namespace_common *ndns);
168void nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns);
169void __nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns);
170bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach,
171 struct nd_namespace_common **_ndns);
172bool __nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach,
173 struct nd_namespace_common **_ndns);
174ssize_t nd_namespace_store(struct device *dev,
175 struct nd_namespace_common **_ndns, const char *buf,
176 size_t len);
177struct nd_pfn *to_nd_pfn_safe(struct device *dev);
178#endif
179