]> git.ipfire.org Git - thirdparty/kernel/linux.git/blame - drivers/nvdimm/nd-core.h
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 295
[thirdparty/kernel/linux.git] / drivers / nvdimm / nd-core.h
CommitLineData
5b497af4 1/* SPDX-License-Identifier: GPL-2.0-only */
b94d5230
DW
2/*
3 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
b94d5230
DW
4 */
5#ifndef __ND_CORE_H__
6#define __ND_CORE_H__
7#include <linux/libnvdimm.h>
8#include <linux/device.h>
eaf96153
DW
9#include <linux/sizes.h>
10#include <linux/mutex.h>
1b40e09a 11#include <linux/nd.h>
b94d5230 12
e6dfb2de
DW
13extern struct list_head nvdimm_bus_list;
14extern struct mutex nvdimm_bus_list_mutex;
62232e45 15extern int nvdimm_major;
7d988097 16extern struct workqueue_struct *nvdimm_wq;
e6dfb2de 17
b94d5230
DW
18struct nvdimm_bus {
19 struct nvdimm_bus_descriptor *nd_desc;
eaf96153 20 wait_queue_head_t probe_wait;
45def22c 21 struct list_head list;
b94d5230 22 struct device dev;
eaf96153 23 int id, probe_active;
29b9aa0a 24 struct list_head mapping_list;
3d88002e 25 struct mutex reconfig_mutex;
aa9ad44a 26 struct badrange badrange;
b94d5230 27};
45def22c 28
e6dfb2de
DW
29struct nvdimm {
30 unsigned long flags;
31 void *provider_data;
e3654eca 32 unsigned long cmd_mask;
e6dfb2de 33 struct device dev;
eaf96153 34 atomic_t busy;
e5ae3b25
DW
35 int id, num_flush;
36 struct resource *flush_wpq;
d6548ae4 37 const char *dimm_id;
f2989396
DJ
38 struct {
39 const struct nvdimm_security_ops *ops;
40 enum nvdimm_security_state state;
89fa9d8e 41 enum nvdimm_security_state ext_state;
7d988097
DJ
42 unsigned int overwrite_tmo;
43 struct kernfs_node *overwrite_state;
f2989396 44 } sec;
7d988097 45 struct delayed_work dwork;
e6dfb2de
DW
46};
47
f2989396 48static inline enum nvdimm_security_state nvdimm_security_state(
faa8bd6e 49 struct nvdimm *nvdimm, enum nvdimm_passphrase_type ptype)
f2989396
DJ
50{
51 if (!nvdimm->sec.ops)
52 return -ENXIO;
53
faa8bd6e 54 return nvdimm->sec.ops->state(nvdimm, ptype);
f2989396 55}
37833fb7 56int nvdimm_security_freeze(struct nvdimm *nvdimm);
03b65b22
DJ
57#if IS_ENABLED(CONFIG_NVDIMM_KEYS)
58int nvdimm_security_disable(struct nvdimm *nvdimm, unsigned int keyid);
d2a4ac73 59int nvdimm_security_update(struct nvdimm *nvdimm, unsigned int keyid,
89fa9d8e
DJ
60 unsigned int new_keyid,
61 enum nvdimm_passphrase_type pass_type);
62int nvdimm_security_erase(struct nvdimm *nvdimm, unsigned int keyid,
63 enum nvdimm_passphrase_type pass_type);
7d988097
DJ
64int nvdimm_security_overwrite(struct nvdimm *nvdimm, unsigned int keyid);
65void nvdimm_security_overwrite_query(struct work_struct *work);
03b65b22
DJ
66#else
67static inline int nvdimm_security_disable(struct nvdimm *nvdimm,
68 unsigned int keyid)
69{
70 return -EOPNOTSUPP;
71}
89fa9d8e
DJ
72static inline int nvdimm_security_update(struct nvdimm *nvdimm,
73 unsigned int keyid,
74 unsigned int new_keyid,
75 enum nvdimm_passphrase_type pass_type)
d2a4ac73
DJ
76{
77 return -EOPNOTSUPP;
78}
89fa9d8e
DJ
79static inline int nvdimm_security_erase(struct nvdimm *nvdimm,
80 unsigned int keyid,
81 enum nvdimm_passphrase_type pass_type)
64e77c8c
DJ
82{
83 return -EOPNOTSUPP;
84}
7d988097
DJ
85static inline int nvdimm_security_overwrite(struct nvdimm *nvdimm,
86 unsigned int keyid)
87{
88 return -EOPNOTSUPP;
89}
90static inline void nvdimm_security_overwrite_query(struct work_struct *work)
91{
92}
03b65b22 93#endif
f2989396 94
762d067d
DW
95/**
96 * struct blk_alloc_info - tracking info for BLK dpa scanning
97 * @nd_mapping: blk region mapping boundaries
98 * @available: decremented in alias_dpa_busy as aliased PMEM is scanned
99 * @busy: decremented in blk_dpa_busy to account for ranges already
100 * handled by alias_dpa_busy
101 * @res: alias_dpa_busy interprets this a free space range that needs to
102 * be truncated to the valid BLK allocation starting DPA, blk_dpa_busy
103 * treats it as a busy range that needs the aliased PMEM ranges
104 * truncated.
105 */
106struct blk_alloc_info {
107 struct nd_mapping *nd_mapping;
108 resource_size_t available, busy;
109 struct resource *res;
110};
111
3d88002e 112bool is_nvdimm(struct device *dev);
3d88002e 113bool is_nd_pmem(struct device *dev);
c9e582aa 114bool is_nd_volatile(struct device *dev);
047fc8a1 115bool is_nd_blk(struct device *dev);
c9e582aa
DW
116static inline bool is_nd_region(struct device *dev)
117{
118 return is_nd_pmem(dev) || is_nd_blk(dev) || is_nd_volatile(dev);
119}
120static inline bool is_memory(struct device *dev)
121{
122 return is_nd_pmem(dev) || is_nd_volatile(dev);
123}
e6dfb2de 124struct nvdimm_bus *walk_to_nvdimm_bus(struct device *nd_dev);
45def22c 125int __init nvdimm_bus_init(void);
4d88a97a 126void nvdimm_bus_exit(void);
b354aba0
DW
127void nvdimm_devs_exit(void);
128void nd_region_devs_exit(void);
eaf96153 129void nd_region_probe_success(struct nvdimm_bus *nvdimm_bus, struct device *dev);
1b40e09a 130struct nd_region;
98a29c39 131void nd_region_create_ns_seed(struct nd_region *nd_region);
8c2f7e86 132void nd_region_create_btt_seed(struct nd_region *nd_region);
2dc43331 133void nd_region_create_pfn_seed(struct nd_region *nd_region);
cd03412a 134void nd_region_create_dax_seed(struct nd_region *nd_region);
eaf96153 135void nd_region_disable(struct nvdimm_bus *nvdimm_bus, struct device *dev);
45def22c
DW
136int nvdimm_bus_create_ndctl(struct nvdimm_bus *nvdimm_bus);
137void nvdimm_bus_destroy_ndctl(struct nvdimm_bus *nvdimm_bus);
4d88a97a 138void nd_synchronize(void);
1f7df6f8
DW
139int nvdimm_bus_register_dimms(struct nvdimm_bus *nvdimm_bus);
140int nvdimm_bus_register_regions(struct nvdimm_bus *nvdimm_bus);
eaf96153 141int nvdimm_bus_init_interleave_sets(struct nvdimm_bus *nvdimm_bus);
8c2f7e86 142void __nd_device_register(struct device *dev);
1f7df6f8 143int nd_match_dimm(struct device *dev, void *data);
bf9bccc1
DW
144struct nd_label_id;
145char *nd_label_gen_id(struct nd_label_id *label_id, u8 *uuid, u32 flags);
146bool nd_is_uuid_unique(struct device *dev, u8 *uuid);
147struct nd_region;
148struct nvdimm_drvdata;
149struct nd_mapping;
ae8219f1 150void nd_mapping_free_labels(struct nd_mapping *nd_mapping);
12e3129e
KB
151
152int __reserve_free_pmem(struct device *dev, void *data);
153void release_free_pmem(struct nvdimm_bus *nvdimm_bus,
154 struct nd_mapping *nd_mapping);
155
156resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region,
157 struct nd_mapping *nd_mapping);
158resource_size_t nd_region_allocatable_dpa(struct nd_region *nd_region);
bf9bccc1
DW
159resource_size_t nd_pmem_available_dpa(struct nd_region *nd_region,
160 struct nd_mapping *nd_mapping, resource_size_t *overlap);
a1f3e4d6 161resource_size_t nd_blk_available_dpa(struct nd_region *nd_region);
bf9bccc1 162resource_size_t nd_region_available_dpa(struct nd_region *nd_region);
ae86cbfe
DW
163int nd_region_conflict(struct nd_region *nd_region, resource_size_t start,
164 resource_size_t size);
bf9bccc1
DW
165resource_size_t nvdimm_allocated_dpa(struct nvdimm_drvdata *ndd,
166 struct nd_label_id *label_id);
762d067d 167int alias_dpa_busy(struct device *dev, void *data);
1b40e09a
DW
168struct resource *nsblk_add_resource(struct nd_region *nd_region,
169 struct nvdimm_drvdata *ndd, struct nd_namespace_blk *nsblk,
170 resource_size_t start);
0ba1c634 171int nvdimm_num_label_slots(struct nvdimm_drvdata *ndd);
bf9bccc1 172void get_ndd(struct nvdimm_drvdata *ndd);
8c2f7e86 173resource_size_t __nvdimm_namespace_capacity(struct nd_namespace_common *ndns);
e1455744
DW
174void nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns);
175void __nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns);
176bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach,
177 struct nd_namespace_common **_ndns);
178bool __nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach,
179 struct nd_namespace_common **_ndns);
180ssize_t nd_namespace_store(struct device *dev,
181 struct nd_namespace_common **_ndns, const char *buf,
182 size_t len);
03dca343 183struct nd_pfn *to_nd_pfn_safe(struct device *dev);
b94d5230 184#endif /* __ND_CORE_H__ */