xref: /openbmc/linux/drivers/nvdimm/nd.h (revision d34cb808402898e53b9a9bcbbedd01667a78723b)
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;
4502881768SDan Williams 	int 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;
137401c0a19SDan Williams 	int position;
138ae8219f1SDan Williams 	struct list_head labels;
139ae8219f1SDan Williams 	struct mutex lock;
14044c462ebSDan Williams 	/*
14144c462ebSDan Williams 	 * @ndd is for private use at region enable / disable time for
14244c462ebSDan Williams 	 * get_ndd() + put_ndd(), all other nd_mapping to ndd
14344c462ebSDan Williams 	 * conversions use to_ndd() which respects enabled state of the
14444c462ebSDan Williams 	 * nvdimm.
14544c462ebSDan Williams 	 */
14644c462ebSDan Williams 	struct nvdimm_drvdata *ndd;
14744c462ebSDan Williams };
14844c462ebSDan Williams 
1491f7df6f8SDan Williams struct nd_region {
1501f7df6f8SDan Williams 	struct device dev;
1511b40e09aSDan Williams 	struct ida ns_ida;
1528c2f7e86SDan Williams 	struct ida btt_ida;
153e1455744SDan Williams 	struct ida pfn_ida;
154cd03412aSDan Williams 	struct ida dax_ida;
155004f1afbSDan Williams 	unsigned long flags;
156bf9bccc1SDan Williams 	struct device *ns_seed;
1578c2f7e86SDan Williams 	struct device *btt_seed;
158e1455744SDan Williams 	struct device *pfn_seed;
159cd03412aSDan Williams 	struct device *dax_seed;
1601f7df6f8SDan Williams 	u16 ndr_mappings;
1611f7df6f8SDan Williams 	u64 ndr_size;
1621f7df6f8SDan Williams 	u64 ndr_start;
16341d7a6d6SToshi Kani 	int id, num_lanes, ro, numa_node;
1641f7df6f8SDan Williams 	void *provider_data;
165975750a9SToshi Kani 	struct kernfs_node *bb_state;
1666a6bef90SDave Jiang 	struct badblocks bb;
167eaf96153SDan Williams 	struct nd_interleave_set *nd_set;
1685212e11fSVishal Verma 	struct nd_percpu_lane __percpu *lane;
1691f7df6f8SDan Williams 	struct nd_mapping mapping[0];
1701f7df6f8SDan Williams };
1711f7df6f8SDan Williams 
172047fc8a1SRoss Zwisler struct nd_blk_region {
173047fc8a1SRoss Zwisler 	int (*enable)(struct nvdimm_bus *nvdimm_bus, struct device *dev);
174047fc8a1SRoss Zwisler 	int (*do_io)(struct nd_blk_region *ndbr, resource_size_t dpa,
175047fc8a1SRoss Zwisler 			void *iobuf, u64 len, int rw);
176047fc8a1SRoss Zwisler 	void *blk_provider_data;
177047fc8a1SRoss Zwisler 	struct nd_region nd_region;
178047fc8a1SRoss Zwisler };
179047fc8a1SRoss Zwisler 
1804a826c83SDan Williams /*
1814a826c83SDan Williams  * Lookup next in the repeating sequence of 01, 10, and 11.
1824a826c83SDan Williams  */
1834a826c83SDan Williams static inline unsigned nd_inc_seq(unsigned seq)
1844a826c83SDan Williams {
1854a826c83SDan Williams 	static const unsigned next[] = { 0, 2, 3, 1 };
1864a826c83SDan Williams 
1874a826c83SDan Williams 	return next[seq & 3];
1884a826c83SDan Williams }
189f524bf27SDan Williams 
1905212e11fSVishal Verma struct btt;
1918c2f7e86SDan Williams struct nd_btt {
1928c2f7e86SDan Williams 	struct device dev;
1938c2f7e86SDan Williams 	struct nd_namespace_common *ndns;
1945212e11fSVishal Verma 	struct btt *btt;
1958c2f7e86SDan Williams 	unsigned long lbasize;
196abe8b4e3SVishal Verma 	u64 size;
1978c2f7e86SDan Williams 	u8 *uuid;
1988c2f7e86SDan Williams 	int id;
19914e49454SVishal Verma 	int initial_offset;
20014e49454SVishal Verma 	u16 version_major;
20114e49454SVishal Verma 	u16 version_minor;
2028c2f7e86SDan Williams };
2038c2f7e86SDan Williams 
204e1455744SDan Williams enum nd_pfn_mode {
205e1455744SDan Williams 	PFN_MODE_NONE,
206e1455744SDan Williams 	PFN_MODE_RAM,
207e1455744SDan Williams 	PFN_MODE_PMEM,
208e1455744SDan Williams };
209e1455744SDan Williams 
210e1455744SDan Williams struct nd_pfn {
211e1455744SDan Williams 	int id;
212e1455744SDan Williams 	u8 *uuid;
213e1455744SDan Williams 	struct device dev;
214315c5625SDan Williams 	unsigned long align;
215e1455744SDan Williams 	unsigned long npfns;
216e1455744SDan Williams 	enum nd_pfn_mode mode;
217e1455744SDan Williams 	struct nd_pfn_sb *pfn_sb;
218e1455744SDan Williams 	struct nd_namespace_common *ndns;
219e1455744SDan Williams };
220e1455744SDan Williams 
221cd03412aSDan Williams struct nd_dax {
222cd03412aSDan Williams 	struct nd_pfn nd_pfn;
223cd03412aSDan Williams };
224cd03412aSDan Williams 
2254d88a97aSDan Williams enum nd_async_mode {
2264d88a97aSDan Williams 	ND_SYNC,
2274d88a97aSDan Williams 	ND_ASYNC,
2284d88a97aSDan Williams };
2294d88a97aSDan Williams 
23041cd8b70SVishal Verma int nd_integrity_init(struct gendisk *disk, unsigned long meta_size);
231bf9bccc1SDan Williams void wait_nvdimm_bus_probe_idle(struct device *dev);
2324d88a97aSDan Williams void nd_device_register(struct device *dev);
2334d88a97aSDan Williams void nd_device_unregister(struct device *dev, enum nd_async_mode mode);
23471999466SDan Williams void nd_device_notify(struct device *dev, enum nvdimm_event event);
235bf9bccc1SDan Williams int nd_uuid_store(struct device *dev, u8 **uuid_out, const char *buf,
236bf9bccc1SDan Williams 		size_t len);
237b2c48f9fSDan Williams ssize_t nd_size_select_show(unsigned long current_size,
2381b40e09aSDan Williams 		const unsigned long *supported, char *buf);
239b2c48f9fSDan Williams ssize_t nd_size_select_store(struct device *dev, const char *buf,
240b2c48f9fSDan Williams 		unsigned long *current_size, const unsigned long *supported);
2414d88a97aSDan Williams int __init nvdimm_init(void);
2423d88002eSDan Williams int __init nd_region_init(void);
243b3fde74eSDan Williams int __init nd_label_init(void);
2444d88a97aSDan Williams void nvdimm_exit(void);
2453d88002eSDan Williams void nd_region_exit(void);
246bf9bccc1SDan Williams struct nvdimm;
247bf9bccc1SDan Williams struct nvdimm_drvdata *to_ndd(struct nd_mapping *nd_mapping);
248aee65987SToshi Kani int nvdimm_check_config_data(struct device *dev);
2494d88a97aSDan Williams int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd);
2504d88a97aSDan Williams int nvdimm_init_config_data(struct nvdimm_drvdata *ndd);
251f524bf27SDan Williams int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset,
252f524bf27SDan Williams 		void *buf, size_t len);
25359e64739SDan Williams long nvdimm_clear_poison(struct device *dev, phys_addr_t phys,
25459e64739SDan Williams 		unsigned int len);
25542237e39SDan Williams void nvdimm_set_aliasing(struct device *dev);
2568f078b38SDan Williams void nvdimm_set_locked(struct device *dev);
257*d34cb808SDan Williams void nvdimm_clear_locked(struct device *dev);
2588c2f7e86SDan Williams struct nd_btt *to_nd_btt(struct device *dev);
259e1455744SDan Williams 
260e1455744SDan Williams struct nd_gen_sb {
261e1455744SDan Williams 	char reserved[SZ_4K - 8];
262e1455744SDan Williams 	__le64 checksum;
263e1455744SDan Williams };
264e1455744SDan Williams 
265e1455744SDan Williams u64 nd_sb_checksum(struct nd_gen_sb *sb);
2668c2f7e86SDan Williams #if IS_ENABLED(CONFIG_BTT)
267200c79daSDan Williams int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns);
2688c2f7e86SDan Williams bool is_nd_btt(struct device *dev);
2698c2f7e86SDan Williams struct device *nd_btt_create(struct nd_region *nd_region);
2708c2f7e86SDan Williams #else
271e32bc729SDan Williams static inline int nd_btt_probe(struct device *dev,
272200c79daSDan Williams 		struct nd_namespace_common *ndns)
2738c2f7e86SDan Williams {
2748c2f7e86SDan Williams 	return -ENODEV;
2758c2f7e86SDan Williams }
2768c2f7e86SDan Williams 
2778c2f7e86SDan Williams static inline bool is_nd_btt(struct device *dev)
2788c2f7e86SDan Williams {
2798c2f7e86SDan Williams 	return false;
2808c2f7e86SDan Williams }
2818c2f7e86SDan Williams 
2828c2f7e86SDan Williams static inline struct device *nd_btt_create(struct nd_region *nd_region)
2838c2f7e86SDan Williams {
2848c2f7e86SDan Williams 	return NULL;
2858c2f7e86SDan Williams }
2868c2f7e86SDan Williams #endif
287e1455744SDan Williams 
288e1455744SDan Williams struct nd_pfn *to_nd_pfn(struct device *dev);
289e1455744SDan Williams #if IS_ENABLED(CONFIG_NVDIMM_PFN)
2900dd69643SOliver O'Halloran 
2910dd69643SOliver O'Halloran #ifdef CONFIG_TRANSPARENT_HUGEPAGE
2920dd69643SOliver O'Halloran #define PFN_DEFAULT_ALIGNMENT HPAGE_PMD_SIZE
2930dd69643SOliver O'Halloran #else
2940dd69643SOliver O'Halloran #define PFN_DEFAULT_ALIGNMENT PAGE_SIZE
2950dd69643SOliver O'Halloran #endif
2960dd69643SOliver O'Halloran 
297200c79daSDan Williams int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns);
298e1455744SDan Williams bool is_nd_pfn(struct device *dev);
299e1455744SDan Williams struct device *nd_pfn_create(struct nd_region *nd_region);
300cd03412aSDan Williams struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn,
301cd03412aSDan Williams 		struct nd_namespace_common *ndns);
302c5ed9268SDan Williams int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig);
303cd03412aSDan Williams extern struct attribute_group nd_pfn_attribute_group;
304e1455744SDan Williams #else
305200c79daSDan Williams static inline int nd_pfn_probe(struct device *dev,
306200c79daSDan Williams 		struct nd_namespace_common *ndns)
307e1455744SDan Williams {
308e1455744SDan Williams 	return -ENODEV;
309e1455744SDan Williams }
310e1455744SDan Williams 
311e1455744SDan Williams static inline bool is_nd_pfn(struct device *dev)
312e1455744SDan Williams {
313e1455744SDan Williams 	return false;
314e1455744SDan Williams }
315e1455744SDan Williams 
316e1455744SDan Williams static inline struct device *nd_pfn_create(struct nd_region *nd_region)
317e1455744SDan Williams {
318e1455744SDan Williams 	return NULL;
319e1455744SDan Williams }
32032ab0a3fSDan Williams 
321c5ed9268SDan Williams static inline int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
32232ab0a3fSDan Williams {
32332ab0a3fSDan Williams 	return -ENODEV;
32432ab0a3fSDan Williams }
325e1455744SDan Williams #endif
326e1455744SDan Williams 
327cd03412aSDan Williams struct nd_dax *to_nd_dax(struct device *dev);
328cd03412aSDan Williams #if IS_ENABLED(CONFIG_NVDIMM_DAX)
329c5ed9268SDan Williams int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns);
330cd03412aSDan Williams bool is_nd_dax(struct device *dev);
331cd03412aSDan Williams struct device *nd_dax_create(struct nd_region *nd_region);
332cd03412aSDan Williams #else
333c5ed9268SDan Williams static inline int nd_dax_probe(struct device *dev,
334c5ed9268SDan Williams 		struct nd_namespace_common *ndns)
335c5ed9268SDan Williams {
336c5ed9268SDan Williams 	return -ENODEV;
337c5ed9268SDan Williams }
338c5ed9268SDan Williams 
339cd03412aSDan Williams static inline bool is_nd_dax(struct device *dev)
340cd03412aSDan Williams {
341cd03412aSDan Williams 	return false;
342cd03412aSDan Williams }
343cd03412aSDan Williams 
344cd03412aSDan Williams static inline struct device *nd_dax_create(struct nd_region *nd_region)
345cd03412aSDan Williams {
346cd03412aSDan Williams 	return NULL;
347cd03412aSDan Williams }
348cd03412aSDan Williams #endif
349cd03412aSDan Williams 
3503d88002eSDan Williams struct nd_region *to_nd_region(struct device *dev);
3513d88002eSDan Williams int nd_region_to_nstype(struct nd_region *nd_region);
3523d88002eSDan Williams int nd_region_register_namespaces(struct nd_region *nd_region, int *err);
353c12c48ceSDan Williams u64 nd_region_interleave_set_cookie(struct nd_region *nd_region,
354c12c48ceSDan Williams 		struct nd_namespace_index *nsindex);
35586ef58a4SDan Williams u64 nd_region_interleave_set_altcookie(struct nd_region *nd_region);
3563d88002eSDan Williams void nvdimm_bus_lock(struct device *dev);
3573d88002eSDan Williams void nvdimm_bus_unlock(struct device *dev);
3583d88002eSDan Williams bool is_nvdimm_bus_locked(struct device *dev);
35958138820SDan Williams int nvdimm_revalidate_disk(struct gendisk *disk);
360bf9bccc1SDan Williams void nvdimm_drvdata_release(struct kref *kref);
361bf9bccc1SDan Williams void put_ndd(struct nvdimm_drvdata *ndd);
3624a826c83SDan Williams int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd);
3634a826c83SDan Williams void nvdimm_free_dpa(struct nvdimm_drvdata *ndd, struct resource *res);
3644a826c83SDan Williams struct resource *nvdimm_allocate_dpa(struct nvdimm_drvdata *ndd,
3654a826c83SDan Williams 		struct nd_label_id *label_id, resource_size_t start,
3664a826c83SDan Williams 		resource_size_t n);
3678c2f7e86SDan Williams resource_size_t nvdimm_namespace_capacity(struct nd_namespace_common *ndns);
3688c2f7e86SDan Williams struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev);
3695212e11fSVishal Verma int nvdimm_namespace_attach_btt(struct nd_namespace_common *ndns);
370298f2bc5SDan Williams int nvdimm_namespace_detach_btt(struct nd_btt *nd_btt);
3715212e11fSVishal Verma const char *nvdimm_namespace_disk_name(struct nd_namespace_common *ndns,
3725212e11fSVishal Verma 		char *name);
373f979b13cSDan Williams unsigned int pmem_sector_size(struct nd_namespace_common *ndns);
374a3901802SDan Williams void nvdimm_badblocks_populate(struct nd_region *nd_region,
375a3901802SDan Williams 		struct badblocks *bb, const struct resource *res);
376200c79daSDan Williams #if IS_ENABLED(CONFIG_ND_CLAIM)
377ac515c08SDan Williams struct vmem_altmap *nvdimm_setup_pfn(struct nd_pfn *nd_pfn,
378ac515c08SDan Williams 		struct resource *res, struct vmem_altmap *altmap);
379200c79daSDan Williams int devm_nsio_enable(struct device *dev, struct nd_namespace_io *nsio);
380200c79daSDan Williams void devm_nsio_disable(struct device *dev, struct nd_namespace_io *nsio);
381200c79daSDan Williams #else
382ac515c08SDan Williams static inline struct vmem_altmap *nvdimm_setup_pfn(struct nd_pfn *nd_pfn,
383ac515c08SDan Williams 		struct resource *res, struct vmem_altmap *altmap)
384ac515c08SDan Williams {
385ac515c08SDan Williams 	return ERR_PTR(-ENXIO);
386ac515c08SDan Williams }
387200c79daSDan Williams static inline int devm_nsio_enable(struct device *dev,
388200c79daSDan Williams 		struct nd_namespace_io *nsio)
389200c79daSDan Williams {
390200c79daSDan Williams 	return -ENXIO;
391200c79daSDan Williams }
392200c79daSDan Williams static inline void devm_nsio_disable(struct device *dev,
393200c79daSDan Williams 		struct nd_namespace_io *nsio)
394200c79daSDan Williams {
395200c79daSDan Williams }
396200c79daSDan Williams #endif
397047fc8a1SRoss Zwisler int nd_blk_region_init(struct nd_region *nd_region);
398e5ae3b25SDan Williams int nd_region_activate(struct nd_region *nd_region);
399f0dc089cSDan Williams void __nd_iostat_start(struct bio *bio, unsigned long *start);
400f0dc089cSDan Williams static inline bool nd_iostat_start(struct bio *bio, unsigned long *start)
401f0dc089cSDan Williams {
40274d46992SChristoph Hellwig 	struct gendisk *disk = bio->bi_disk;
403f0dc089cSDan Williams 
404f0dc089cSDan Williams 	if (!blk_queue_io_stat(disk->queue))
405f0dc089cSDan Williams 		return false;
406f0dc089cSDan Williams 
4078d7c22acSToshi Kani 	*start = jiffies;
408d62e26b3SJens Axboe 	generic_start_io_acct(disk->queue, bio_data_dir(bio),
4098d7c22acSToshi Kani 			      bio_sectors(bio), &disk->part0);
410f0dc089cSDan Williams 	return true;
411f0dc089cSDan Williams }
4128d7c22acSToshi Kani static inline void nd_iostat_end(struct bio *bio, unsigned long start)
4138d7c22acSToshi Kani {
41474d46992SChristoph Hellwig 	struct gendisk *disk = bio->bi_disk;
4158d7c22acSToshi Kani 
416d62e26b3SJens Axboe 	generic_end_io_acct(disk->queue, bio_data_dir(bio), &disk->part0,
417d62e26b3SJens Axboe 				start);
4188d7c22acSToshi Kani }
419200c79daSDan Williams static inline bool is_bad_pmem(struct badblocks *bb, sector_t sector,
420200c79daSDan Williams 		unsigned int len)
421200c79daSDan Williams {
422200c79daSDan Williams 	if (bb->count) {
423200c79daSDan Williams 		sector_t first_bad;
424200c79daSDan Williams 		int num_bad;
425200c79daSDan Williams 
426200c79daSDan Williams 		return !!badblocks_check(bb, sector, len / 512, &first_bad,
427200c79daSDan Williams 				&num_bad);
428200c79daSDan Williams 	}
429200c79daSDan Williams 
430200c79daSDan Williams 	return false;
431200c79daSDan Williams }
432047fc8a1SRoss Zwisler resource_size_t nd_namespace_blk_validate(struct nd_namespace_blk *nsblk);
4336ec68954SVishal Verma const u8 *nd_dev_to_uuid(struct device *dev);
434004f1afbSDan Williams bool pmem_should_map_pages(struct device *dev);
4354d88a97aSDan Williams #endif /* __ND_H__ */
436