xref: /openbmc/linux/drivers/nvdimm/nd.h (revision f979b13c3cc51584882bffa32965f34e5afa3b9b)
14d88a97aSDan Williams /*
24d88a97aSDan Williams  * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
34d88a97aSDan Williams  *
44d88a97aSDan Williams  * This program is free software; you can redistribute it and/or modify
54d88a97aSDan Williams  * it under the terms of version 2 of the GNU General Public License as
64d88a97aSDan Williams  * published by the Free Software Foundation.
74d88a97aSDan Williams  *
84d88a97aSDan Williams  * This program is distributed in the hope that it will be useful, but
94d88a97aSDan Williams  * WITHOUT ANY WARRANTY; without even the implied warranty of
104d88a97aSDan Williams  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
114d88a97aSDan Williams  * General Public License for more details.
124d88a97aSDan Williams  */
134d88a97aSDan Williams #ifndef __ND_H__
144d88a97aSDan Williams #define __ND_H__
151f7df6f8SDan Williams #include <linux/libnvdimm.h>
16200c79daSDan Williams #include <linux/badblocks.h>
17f0dc089cSDan Williams #include <linux/blkdev.h>
184d88a97aSDan Williams #include <linux/device.h>
194d88a97aSDan Williams #include <linux/mutex.h>
204d88a97aSDan Williams #include <linux/ndctl.h>
21bf9bccc1SDan Williams #include <linux/types.h>
2271999466SDan Williams #include <linux/nd.h>
234a826c83SDan Williams #include "label.h"
244d88a97aSDan Williams 
258c2f7e86SDan Williams enum {
265212e11fSVishal Verma 	/*
275212e11fSVishal Verma 	 * Limits the maximum number of block apertures a dimm can
285212e11fSVishal Verma 	 * support and is an input to the geometry/on-disk-format of a
295212e11fSVishal Verma 	 * BTT instance
305212e11fSVishal Verma 	 */
315212e11fSVishal Verma 	ND_MAX_LANES = 256,
328c2f7e86SDan Williams 	SECTOR_SHIFT = 9,
33fcae6957SVishal Verma 	INT_LBASIZE_ALIGNMENT = 64,
343ae3d67bSVishal Verma 	NVDIMM_IO_ATOMIC = 1,
358c2f7e86SDan Williams };
368c2f7e86SDan Williams 
370caeef63SVishal Verma struct nd_poison {
380caeef63SVishal Verma 	u64 start;
390caeef63SVishal Verma 	u64 length;
400caeef63SVishal Verma 	struct list_head list;
410caeef63SVishal Verma };
420caeef63SVishal Verma 
434d88a97aSDan Williams struct nvdimm_drvdata {
444d88a97aSDan Williams 	struct device *dev;
45564e871aSDan Williams 	int nsindex_size, nslabel_size;
464d88a97aSDan Williams 	struct nd_cmd_get_config_size nsarea;
474d88a97aSDan Williams 	void *data;
484a826c83SDan Williams 	int ns_current, ns_next;
494a826c83SDan Williams 	struct resource dpa;
50bf9bccc1SDan Williams 	struct kref kref;
514d88a97aSDan Williams };
524d88a97aSDan Williams 
53e5ae3b25SDan Williams struct nd_region_data {
54e5ae3b25SDan Williams 	int ns_count;
55e5ae3b25SDan Williams 	int ns_active;
56595c7307SDan Williams 	unsigned int hints_shift;
57595c7307SDan Williams 	void __iomem *flush_wpq[0];
583d88002eSDan Williams };
593d88002eSDan Williams 
60595c7307SDan Williams static inline void __iomem *ndrd_get_flush_wpq(struct nd_region_data *ndrd,
61595c7307SDan Williams 		int dimm, int hint)
62595c7307SDan Williams {
63595c7307SDan Williams 	unsigned int num = 1 << ndrd->hints_shift;
64595c7307SDan Williams 	unsigned int mask = num - 1;
65595c7307SDan Williams 
66595c7307SDan Williams 	return ndrd->flush_wpq[dimm * num + (hint & mask)];
67595c7307SDan Williams }
68595c7307SDan Williams 
69595c7307SDan Williams static inline void ndrd_set_flush_wpq(struct nd_region_data *ndrd, int dimm,
70595c7307SDan Williams 		int hint, void __iomem *flush)
71595c7307SDan Williams {
72595c7307SDan Williams 	unsigned int num = 1 << ndrd->hints_shift;
73595c7307SDan Williams 	unsigned int mask = num - 1;
74595c7307SDan Williams 
75595c7307SDan Williams 	ndrd->flush_wpq[dimm * num + (hint & mask)] = flush;
76595c7307SDan Williams }
77595c7307SDan Williams 
784a826c83SDan Williams static inline struct nd_namespace_index *to_namespace_index(
794a826c83SDan Williams 		struct nvdimm_drvdata *ndd, int i)
804a826c83SDan Williams {
814a826c83SDan Williams 	if (i < 0)
824a826c83SDan Williams 		return NULL;
834a826c83SDan Williams 
844a826c83SDan Williams 	return ndd->data + sizeof_namespace_index(ndd) * i;
854a826c83SDan Williams }
864a826c83SDan Williams 
874a826c83SDan Williams static inline struct nd_namespace_index *to_current_namespace_index(
884a826c83SDan Williams 		struct nvdimm_drvdata *ndd)
894a826c83SDan Williams {
904a826c83SDan Williams 	return to_namespace_index(ndd, ndd->ns_current);
914a826c83SDan Williams }
924a826c83SDan Williams 
934a826c83SDan Williams static inline struct nd_namespace_index *to_next_namespace_index(
944a826c83SDan Williams 		struct nvdimm_drvdata *ndd)
954a826c83SDan Williams {
964a826c83SDan Williams 	return to_namespace_index(ndd, ndd->ns_next);
974a826c83SDan Williams }
984a826c83SDan Williams 
99564e871aSDan Williams unsigned sizeof_namespace_label(struct nvdimm_drvdata *ndd);
100564e871aSDan Williams 
101564e871aSDan Williams #define namespace_label_has(ndd, field) \
102564e871aSDan Williams 	(offsetof(struct nd_namespace_label, field) \
103564e871aSDan Williams 		< sizeof_namespace_label(ndd))
104564e871aSDan Williams 
1054a826c83SDan Williams #define nd_dbg_dpa(r, d, res, fmt, arg...) \
1064a826c83SDan Williams 	dev_dbg((r) ? &(r)->dev : (d)->dev, "%s: %.13s: %#llx @ %#llx " fmt, \
1074a826c83SDan Williams 		(r) ? dev_name((d)->dev) : "", res ? res->name : "null", \
1084a826c83SDan Williams 		(unsigned long long) (res ? resource_size(res) : 0), \
1094a826c83SDan Williams 		(unsigned long long) (res ? res->start : 0), ##arg)
1104a826c83SDan Williams 
111bf9bccc1SDan Williams #define for_each_dpa_resource(ndd, res) \
112bf9bccc1SDan Williams 	for (res = (ndd)->dpa.child; res; res = res->sibling)
113bf9bccc1SDan Williams 
1144a826c83SDan Williams #define for_each_dpa_resource_safe(ndd, res, next) \
1154a826c83SDan Williams 	for (res = (ndd)->dpa.child, next = res ? res->sibling : NULL; \
1164a826c83SDan Williams 			res; res = next, next = next ? next->sibling : NULL)
1174a826c83SDan Williams 
1185212e11fSVishal Verma struct nd_percpu_lane {
1195212e11fSVishal Verma 	int count;
1205212e11fSVishal Verma 	spinlock_t lock;
1215212e11fSVishal Verma };
1225212e11fSVishal Verma 
123ae8219f1SDan Williams struct nd_label_ent {
124ae8219f1SDan Williams 	struct list_head list;
125ae8219f1SDan Williams 	struct nd_namespace_label *label;
126ae8219f1SDan Williams };
127ae8219f1SDan Williams 
128ae8219f1SDan Williams enum nd_mapping_lock_class {
129ae8219f1SDan Williams 	ND_MAPPING_CLASS0,
130ae8219f1SDan Williams 	ND_MAPPING_UUID_SCAN,
131ae8219f1SDan Williams };
132ae8219f1SDan Williams 
13344c462ebSDan Williams struct nd_mapping {
13444c462ebSDan Williams 	struct nvdimm *nvdimm;
13544c462ebSDan Williams 	u64 start;
13644c462ebSDan Williams 	u64 size;
137ae8219f1SDan Williams 	struct list_head labels;
138ae8219f1SDan Williams 	struct mutex lock;
13944c462ebSDan Williams 	/*
14044c462ebSDan Williams 	 * @ndd is for private use at region enable / disable time for
14144c462ebSDan Williams 	 * get_ndd() + put_ndd(), all other nd_mapping to ndd
14244c462ebSDan Williams 	 * conversions use to_ndd() which respects enabled state of the
14344c462ebSDan Williams 	 * nvdimm.
14444c462ebSDan Williams 	 */
14544c462ebSDan Williams 	struct nvdimm_drvdata *ndd;
14644c462ebSDan Williams };
14744c462ebSDan Williams 
1481f7df6f8SDan Williams struct nd_region {
1491f7df6f8SDan Williams 	struct device dev;
1501b40e09aSDan Williams 	struct ida ns_ida;
1518c2f7e86SDan Williams 	struct ida btt_ida;
152e1455744SDan Williams 	struct ida pfn_ida;
153cd03412aSDan Williams 	struct ida dax_ida;
154004f1afbSDan Williams 	unsigned long flags;
155bf9bccc1SDan Williams 	struct device *ns_seed;
1568c2f7e86SDan Williams 	struct device *btt_seed;
157e1455744SDan Williams 	struct device *pfn_seed;
158cd03412aSDan Williams 	struct device *dax_seed;
1591f7df6f8SDan Williams 	u16 ndr_mappings;
1601f7df6f8SDan Williams 	u64 ndr_size;
1611f7df6f8SDan Williams 	u64 ndr_start;
16241d7a6d6SToshi Kani 	int id, num_lanes, ro, numa_node;
1631f7df6f8SDan Williams 	void *provider_data;
1646a6bef90SDave Jiang 	struct badblocks bb;
165eaf96153SDan Williams 	struct nd_interleave_set *nd_set;
1665212e11fSVishal Verma 	struct nd_percpu_lane __percpu *lane;
1671f7df6f8SDan Williams 	struct nd_mapping mapping[0];
1681f7df6f8SDan Williams };
1691f7df6f8SDan Williams 
170047fc8a1SRoss Zwisler struct nd_blk_region {
171047fc8a1SRoss Zwisler 	int (*enable)(struct nvdimm_bus *nvdimm_bus, struct device *dev);
172047fc8a1SRoss Zwisler 	int (*do_io)(struct nd_blk_region *ndbr, resource_size_t dpa,
173047fc8a1SRoss Zwisler 			void *iobuf, u64 len, int rw);
174047fc8a1SRoss Zwisler 	void *blk_provider_data;
175047fc8a1SRoss Zwisler 	struct nd_region nd_region;
176047fc8a1SRoss Zwisler };
177047fc8a1SRoss Zwisler 
1784a826c83SDan Williams /*
1794a826c83SDan Williams  * Lookup next in the repeating sequence of 01, 10, and 11.
1804a826c83SDan Williams  */
1814a826c83SDan Williams static inline unsigned nd_inc_seq(unsigned seq)
1824a826c83SDan Williams {
1834a826c83SDan Williams 	static const unsigned next[] = { 0, 2, 3, 1 };
1844a826c83SDan Williams 
1854a826c83SDan Williams 	return next[seq & 3];
1864a826c83SDan Williams }
187f524bf27SDan Williams 
1885212e11fSVishal Verma struct btt;
1898c2f7e86SDan Williams struct nd_btt {
1908c2f7e86SDan Williams 	struct device dev;
1918c2f7e86SDan Williams 	struct nd_namespace_common *ndns;
1925212e11fSVishal Verma 	struct btt *btt;
1938c2f7e86SDan Williams 	unsigned long lbasize;
194abe8b4e3SVishal Verma 	u64 size;
1958c2f7e86SDan Williams 	u8 *uuid;
1968c2f7e86SDan Williams 	int id;
1978c2f7e86SDan Williams };
1988c2f7e86SDan Williams 
199e1455744SDan Williams enum nd_pfn_mode {
200e1455744SDan Williams 	PFN_MODE_NONE,
201e1455744SDan Williams 	PFN_MODE_RAM,
202e1455744SDan Williams 	PFN_MODE_PMEM,
203e1455744SDan Williams };
204e1455744SDan Williams 
205e1455744SDan Williams struct nd_pfn {
206e1455744SDan Williams 	int id;
207e1455744SDan Williams 	u8 *uuid;
208e1455744SDan Williams 	struct device dev;
209315c5625SDan Williams 	unsigned long align;
210e1455744SDan Williams 	unsigned long npfns;
211e1455744SDan Williams 	enum nd_pfn_mode mode;
212e1455744SDan Williams 	struct nd_pfn_sb *pfn_sb;
213e1455744SDan Williams 	struct nd_namespace_common *ndns;
214e1455744SDan Williams };
215e1455744SDan Williams 
216cd03412aSDan Williams struct nd_dax {
217cd03412aSDan Williams 	struct nd_pfn nd_pfn;
218cd03412aSDan Williams };
219cd03412aSDan Williams 
2204d88a97aSDan Williams enum nd_async_mode {
2214d88a97aSDan Williams 	ND_SYNC,
2224d88a97aSDan Williams 	ND_ASYNC,
2234d88a97aSDan Williams };
2244d88a97aSDan Williams 
22541cd8b70SVishal Verma int nd_integrity_init(struct gendisk *disk, unsigned long meta_size);
226bf9bccc1SDan Williams void wait_nvdimm_bus_probe_idle(struct device *dev);
2274d88a97aSDan Williams void nd_device_register(struct device *dev);
2284d88a97aSDan Williams void nd_device_unregister(struct device *dev, enum nd_async_mode mode);
22971999466SDan Williams void nd_device_notify(struct device *dev, enum nvdimm_event event);
230bf9bccc1SDan Williams int nd_uuid_store(struct device *dev, u8 **uuid_out, const char *buf,
231bf9bccc1SDan Williams 		size_t len);
2321b40e09aSDan Williams ssize_t nd_sector_size_show(unsigned long current_lbasize,
2331b40e09aSDan Williams 		const unsigned long *supported, char *buf);
2341b40e09aSDan Williams ssize_t nd_sector_size_store(struct device *dev, const char *buf,
2351b40e09aSDan Williams 		unsigned long *current_lbasize, const unsigned long *supported);
2364d88a97aSDan Williams int __init nvdimm_init(void);
2373d88002eSDan Williams int __init nd_region_init(void);
2384d88a97aSDan Williams void nvdimm_exit(void);
2393d88002eSDan Williams void nd_region_exit(void);
240bf9bccc1SDan Williams struct nvdimm;
241bf9bccc1SDan Williams struct nvdimm_drvdata *to_ndd(struct nd_mapping *nd_mapping);
242aee65987SToshi Kani int nvdimm_check_config_data(struct device *dev);
2434d88a97aSDan Williams int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd);
2444d88a97aSDan Williams int nvdimm_init_config_data(struct nvdimm_drvdata *ndd);
245f524bf27SDan Williams int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset,
246f524bf27SDan Williams 		void *buf, size_t len);
24759e64739SDan Williams long nvdimm_clear_poison(struct device *dev, phys_addr_t phys,
24859e64739SDan Williams 		unsigned int len);
24942237e39SDan Williams void nvdimm_set_aliasing(struct device *dev);
2508f078b38SDan Williams void nvdimm_set_locked(struct device *dev);
2518c2f7e86SDan Williams struct nd_btt *to_nd_btt(struct device *dev);
252e1455744SDan Williams 
253e1455744SDan Williams struct nd_gen_sb {
254e1455744SDan Williams 	char reserved[SZ_4K - 8];
255e1455744SDan Williams 	__le64 checksum;
256e1455744SDan Williams };
257e1455744SDan Williams 
258e1455744SDan Williams u64 nd_sb_checksum(struct nd_gen_sb *sb);
2598c2f7e86SDan Williams #if IS_ENABLED(CONFIG_BTT)
260200c79daSDan Williams int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns);
2618c2f7e86SDan Williams bool is_nd_btt(struct device *dev);
2628c2f7e86SDan Williams struct device *nd_btt_create(struct nd_region *nd_region);
2638c2f7e86SDan Williams #else
264e32bc729SDan Williams static inline int nd_btt_probe(struct device *dev,
265200c79daSDan Williams 		struct nd_namespace_common *ndns)
2668c2f7e86SDan Williams {
2678c2f7e86SDan Williams 	return -ENODEV;
2688c2f7e86SDan Williams }
2698c2f7e86SDan Williams 
2708c2f7e86SDan Williams static inline bool is_nd_btt(struct device *dev)
2718c2f7e86SDan Williams {
2728c2f7e86SDan Williams 	return false;
2738c2f7e86SDan Williams }
2748c2f7e86SDan Williams 
2758c2f7e86SDan Williams static inline struct device *nd_btt_create(struct nd_region *nd_region)
2768c2f7e86SDan Williams {
2778c2f7e86SDan Williams 	return NULL;
2788c2f7e86SDan Williams }
2798c2f7e86SDan Williams #endif
280e1455744SDan Williams 
281e1455744SDan Williams struct nd_pfn *to_nd_pfn(struct device *dev);
282e1455744SDan Williams #if IS_ENABLED(CONFIG_NVDIMM_PFN)
283200c79daSDan Williams int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns);
284e1455744SDan Williams bool is_nd_pfn(struct device *dev);
285e1455744SDan Williams struct device *nd_pfn_create(struct nd_region *nd_region);
286cd03412aSDan Williams struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn,
287cd03412aSDan Williams 		struct nd_namespace_common *ndns);
288c5ed9268SDan Williams int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig);
289cd03412aSDan Williams extern struct attribute_group nd_pfn_attribute_group;
290e1455744SDan Williams #else
291200c79daSDan Williams static inline int nd_pfn_probe(struct device *dev,
292200c79daSDan Williams 		struct nd_namespace_common *ndns)
293e1455744SDan Williams {
294e1455744SDan Williams 	return -ENODEV;
295e1455744SDan Williams }
296e1455744SDan Williams 
297e1455744SDan Williams static inline bool is_nd_pfn(struct device *dev)
298e1455744SDan Williams {
299e1455744SDan Williams 	return false;
300e1455744SDan Williams }
301e1455744SDan Williams 
302e1455744SDan Williams static inline struct device *nd_pfn_create(struct nd_region *nd_region)
303e1455744SDan Williams {
304e1455744SDan Williams 	return NULL;
305e1455744SDan Williams }
30632ab0a3fSDan Williams 
307c5ed9268SDan Williams static inline int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
30832ab0a3fSDan Williams {
30932ab0a3fSDan Williams 	return -ENODEV;
31032ab0a3fSDan Williams }
311e1455744SDan Williams #endif
312e1455744SDan Williams 
313cd03412aSDan Williams struct nd_dax *to_nd_dax(struct device *dev);
314cd03412aSDan Williams #if IS_ENABLED(CONFIG_NVDIMM_DAX)
315c5ed9268SDan Williams int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns);
316cd03412aSDan Williams bool is_nd_dax(struct device *dev);
317cd03412aSDan Williams struct device *nd_dax_create(struct nd_region *nd_region);
318cd03412aSDan Williams #else
319c5ed9268SDan Williams static inline int nd_dax_probe(struct device *dev,
320c5ed9268SDan Williams 		struct nd_namespace_common *ndns)
321c5ed9268SDan Williams {
322c5ed9268SDan Williams 	return -ENODEV;
323c5ed9268SDan Williams }
324c5ed9268SDan Williams 
325cd03412aSDan Williams static inline bool is_nd_dax(struct device *dev)
326cd03412aSDan Williams {
327cd03412aSDan Williams 	return false;
328cd03412aSDan Williams }
329cd03412aSDan Williams 
330cd03412aSDan Williams static inline struct device *nd_dax_create(struct nd_region *nd_region)
331cd03412aSDan Williams {
332cd03412aSDan Williams 	return NULL;
333cd03412aSDan Williams }
334cd03412aSDan Williams #endif
335cd03412aSDan Williams 
3363d88002eSDan Williams struct nd_region *to_nd_region(struct device *dev);
3373d88002eSDan Williams int nd_region_to_nstype(struct nd_region *nd_region);
3383d88002eSDan Williams int nd_region_register_namespaces(struct nd_region *nd_region, int *err);
339c12c48ceSDan Williams u64 nd_region_interleave_set_cookie(struct nd_region *nd_region,
340c12c48ceSDan Williams 		struct nd_namespace_index *nsindex);
34186ef58a4SDan Williams u64 nd_region_interleave_set_altcookie(struct nd_region *nd_region);
3423d88002eSDan Williams void nvdimm_bus_lock(struct device *dev);
3433d88002eSDan Williams void nvdimm_bus_unlock(struct device *dev);
3443d88002eSDan Williams bool is_nvdimm_bus_locked(struct device *dev);
34558138820SDan Williams int nvdimm_revalidate_disk(struct gendisk *disk);
346bf9bccc1SDan Williams void nvdimm_drvdata_release(struct kref *kref);
347bf9bccc1SDan Williams void put_ndd(struct nvdimm_drvdata *ndd);
3484a826c83SDan Williams int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd);
3494a826c83SDan Williams void nvdimm_free_dpa(struct nvdimm_drvdata *ndd, struct resource *res);
3504a826c83SDan Williams struct resource *nvdimm_allocate_dpa(struct nvdimm_drvdata *ndd,
3514a826c83SDan Williams 		struct nd_label_id *label_id, resource_size_t start,
3524a826c83SDan Williams 		resource_size_t n);
3538c2f7e86SDan Williams resource_size_t nvdimm_namespace_capacity(struct nd_namespace_common *ndns);
3548c2f7e86SDan Williams struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev);
3555212e11fSVishal Verma int nvdimm_namespace_attach_btt(struct nd_namespace_common *ndns);
356298f2bc5SDan Williams int nvdimm_namespace_detach_btt(struct nd_btt *nd_btt);
3575212e11fSVishal Verma const char *nvdimm_namespace_disk_name(struct nd_namespace_common *ndns,
3585212e11fSVishal Verma 		char *name);
359*f979b13cSDan Williams unsigned int pmem_sector_size(struct nd_namespace_common *ndns);
360a3901802SDan Williams void nvdimm_badblocks_populate(struct nd_region *nd_region,
361a3901802SDan Williams 		struct badblocks *bb, const struct resource *res);
362200c79daSDan Williams #if IS_ENABLED(CONFIG_ND_CLAIM)
363ac515c08SDan Williams struct vmem_altmap *nvdimm_setup_pfn(struct nd_pfn *nd_pfn,
364ac515c08SDan Williams 		struct resource *res, struct vmem_altmap *altmap);
365200c79daSDan Williams int devm_nsio_enable(struct device *dev, struct nd_namespace_io *nsio);
366200c79daSDan Williams void devm_nsio_disable(struct device *dev, struct nd_namespace_io *nsio);
367200c79daSDan Williams #else
368ac515c08SDan Williams static inline struct vmem_altmap *nvdimm_setup_pfn(struct nd_pfn *nd_pfn,
369ac515c08SDan Williams 		struct resource *res, struct vmem_altmap *altmap)
370ac515c08SDan Williams {
371ac515c08SDan Williams 	return ERR_PTR(-ENXIO);
372ac515c08SDan Williams }
373200c79daSDan Williams static inline int devm_nsio_enable(struct device *dev,
374200c79daSDan Williams 		struct nd_namespace_io *nsio)
375200c79daSDan Williams {
376200c79daSDan Williams 	return -ENXIO;
377200c79daSDan Williams }
378200c79daSDan Williams static inline void devm_nsio_disable(struct device *dev,
379200c79daSDan Williams 		struct nd_namespace_io *nsio)
380200c79daSDan Williams {
381200c79daSDan Williams }
382200c79daSDan Williams #endif
383047fc8a1SRoss Zwisler int nd_blk_region_init(struct nd_region *nd_region);
384e5ae3b25SDan Williams int nd_region_activate(struct nd_region *nd_region);
385f0dc089cSDan Williams void __nd_iostat_start(struct bio *bio, unsigned long *start);
386f0dc089cSDan Williams static inline bool nd_iostat_start(struct bio *bio, unsigned long *start)
387f0dc089cSDan Williams {
388f0dc089cSDan Williams 	struct gendisk *disk = bio->bi_bdev->bd_disk;
389f0dc089cSDan Williams 
390f0dc089cSDan Williams 	if (!blk_queue_io_stat(disk->queue))
391f0dc089cSDan Williams 		return false;
392f0dc089cSDan Williams 
3938d7c22acSToshi Kani 	*start = jiffies;
3948d7c22acSToshi Kani 	generic_start_io_acct(bio_data_dir(bio),
3958d7c22acSToshi Kani 			      bio_sectors(bio), &disk->part0);
396f0dc089cSDan Williams 	return true;
397f0dc089cSDan Williams }
3988d7c22acSToshi Kani static inline void nd_iostat_end(struct bio *bio, unsigned long start)
3998d7c22acSToshi Kani {
4008d7c22acSToshi Kani 	struct gendisk *disk = bio->bi_bdev->bd_disk;
4018d7c22acSToshi Kani 
4028d7c22acSToshi Kani 	generic_end_io_acct(bio_data_dir(bio), &disk->part0, start);
4038d7c22acSToshi Kani }
404200c79daSDan Williams static inline bool is_bad_pmem(struct badblocks *bb, sector_t sector,
405200c79daSDan Williams 		unsigned int len)
406200c79daSDan Williams {
407200c79daSDan Williams 	if (bb->count) {
408200c79daSDan Williams 		sector_t first_bad;
409200c79daSDan Williams 		int num_bad;
410200c79daSDan Williams 
411200c79daSDan Williams 		return !!badblocks_check(bb, sector, len / 512, &first_bad,
412200c79daSDan Williams 				&num_bad);
413200c79daSDan Williams 	}
414200c79daSDan Williams 
415200c79daSDan Williams 	return false;
416200c79daSDan Williams }
417047fc8a1SRoss Zwisler resource_size_t nd_namespace_blk_validate(struct nd_namespace_blk *nsblk);
4186ec68954SVishal Verma const u8 *nd_dev_to_uuid(struct device *dev);
419004f1afbSDan Williams bool pmem_should_map_pages(struct device *dev);
4204d88a97aSDan Williams #endif /* __ND_H__ */
421