2019-05-29 07:18:09 -07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2015-05-19 22:54:31 -04:00
|
|
|
/*
|
|
|
|
|
* libnvdimm - Non-volatile-memory Devices Subsystem
|
|
|
|
|
*
|
|
|
|
|
* Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef __LIBNVDIMM_H__
|
|
|
|
|
#define __LIBNVDIMM_H__
|
2015-06-25 04:21:02 -04:00
|
|
|
#include <linux/kernel.h>
|
2015-06-08 14:27:06 -04:00
|
|
|
#include <linux/sizes.h>
|
|
|
|
|
#include <linux/types.h>
|
2017-06-06 11:10:51 -07:00
|
|
|
#include <linux/uuid.h>
|
2017-08-23 12:48:26 -07:00
|
|
|
#include <linux/spinlock.h>
|
2019-07-05 19:33:22 +05:30
|
|
|
#include <linux/bio.h>
|
2017-08-23 12:48:26 -07:00
|
|
|
|
|
|
|
|
struct badrange_entry {
|
|
|
|
|
u64 start;
|
|
|
|
|
u64 length;
|
|
|
|
|
struct list_head list;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct badrange {
|
|
|
|
|
struct list_head list;
|
|
|
|
|
spinlock_t lock;
|
|
|
|
|
};
|
2015-04-25 03:56:17 -04:00
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
/* when a dimm supports both PMEM and BLK access a label is required */
|
2017-05-04 14:01:24 -07:00
|
|
|
NDD_ALIASING = 0,
|
2015-06-23 20:08:34 -04:00
|
|
|
/* unarmed memory devices may not persist writes */
|
2017-05-04 14:01:24 -07:00
|
|
|
NDD_UNARMED = 1,
|
|
|
|
|
/* locked memory devices should not be accessed */
|
|
|
|
|
NDD_LOCKED = 2,
|
2018-12-13 15:36:18 -07:00
|
|
|
/* memory under security wipes should not be accessed */
|
|
|
|
|
NDD_SECURITY_OVERWRITE = 3,
|
|
|
|
|
/* tracking whether or not there is a pending device reference */
|
|
|
|
|
NDD_WORK_PENDING = 4,
|
2019-02-02 16:35:26 -08:00
|
|
|
/* ignore / filter NSLABEL_FLAG_LOCAL for this DIMM, i.e. no aliasing */
|
|
|
|
|
NDD_NOBLK = 5,
|
2015-06-08 14:27:06 -04:00
|
|
|
|
|
|
|
|
/* need to set a limit somewhere, but yes, this is likely overkill */
|
|
|
|
|
ND_IOCTL_MAX_BUFLEN = SZ_4M,
|
2016-02-17 13:08:58 -08:00
|
|
|
ND_CMD_MAX_ELEM = 5,
|
2016-04-11 15:02:28 -07:00
|
|
|
ND_CMD_MAX_ENVELOPE = 256,
|
2015-06-09 20:13:14 -04:00
|
|
|
ND_MAX_MAPPINGS = 32,
|
2015-05-01 13:34:01 -04:00
|
|
|
|
2015-08-24 19:20:23 -04:00
|
|
|
/* region flag indicating to direct-map persistent memory by default */
|
|
|
|
|
ND_REGION_PAGEMAP = 0,
|
2018-01-31 12:45:38 -07:00
|
|
|
/*
|
|
|
|
|
* Platform ensures entire CPU store data path is flushed to pmem on
|
|
|
|
|
* system power loss.
|
|
|
|
|
*/
|
|
|
|
|
ND_REGION_PERSIST_CACHE = 1,
|
2018-01-31 12:45:43 -07:00
|
|
|
/*
|
|
|
|
|
* Platform provides mechanisms to automatically flush outstanding
|
|
|
|
|
* write data from memory controler to pmem on system power loss.
|
|
|
|
|
* (ADR)
|
|
|
|
|
*/
|
|
|
|
|
ND_REGION_PERSIST_MEMCTRL = 2,
|
2015-08-24 19:20:23 -04:00
|
|
|
|
2019-07-05 19:33:22 +05:30
|
|
|
/* Platform provides asynchronous flush mechanism */
|
|
|
|
|
ND_REGION_ASYNC = 3,
|
|
|
|
|
|
2015-05-01 13:34:01 -04:00
|
|
|
/* mark newly adjusted resources as requiring a label update */
|
|
|
|
|
DPA_RESOURCE_ADJUSTED = 1 << 0,
|
2015-04-25 03:56:17 -04:00
|
|
|
};
|
|
|
|
|
|
2015-04-26 19:26:48 -04:00
|
|
|
extern struct attribute_group nvdimm_bus_attribute_group;
|
2015-06-08 14:27:06 -04:00
|
|
|
extern struct attribute_group nvdimm_attribute_group;
|
2015-05-31 14:41:48 -04:00
|
|
|
extern struct attribute_group nd_device_attribute_group;
|
2015-06-19 12:18:34 -06:00
|
|
|
extern struct attribute_group nd_numa_attribute_group;
|
2015-06-09 20:13:14 -04:00
|
|
|
extern struct attribute_group nd_region_attribute_group;
|
|
|
|
|
extern struct attribute_group nd_mapping_attribute_group;
|
2015-04-26 19:26:48 -04:00
|
|
|
|
2015-05-19 22:54:31 -04:00
|
|
|
struct nvdimm;
|
|
|
|
|
struct nvdimm_bus_descriptor;
|
|
|
|
|
typedef int (*ndctl_fn)(struct nvdimm_bus_descriptor *nd_desc,
|
|
|
|
|
struct nvdimm *nvdimm, unsigned int cmd, void *buf,
|
2016-02-12 17:01:11 -08:00
|
|
|
unsigned int buf_len, int *cmd_rc);
|
2015-05-19 22:54:31 -04:00
|
|
|
|
2018-04-06 15:21:13 +10:00
|
|
|
struct device_node;
|
2015-05-19 22:54:31 -04:00
|
|
|
struct nvdimm_bus_descriptor {
|
2015-04-26 19:26:48 -04:00
|
|
|
const struct attribute_group **attr_groups;
|
2017-06-30 20:53:24 -07:00
|
|
|
unsigned long bus_dsm_mask;
|
2016-04-28 16:17:07 -07:00
|
|
|
unsigned long cmd_mask;
|
2016-07-21 20:03:19 -07:00
|
|
|
struct module *module;
|
2015-05-19 22:54:31 -04:00
|
|
|
char *provider_name;
|
2018-04-06 15:21:13 +10:00
|
|
|
struct device_node *of_node;
|
2015-05-19 22:54:31 -04:00
|
|
|
ndctl_fn ndctl;
|
2016-02-19 12:16:34 -08:00
|
|
|
int (*flush_probe)(struct nvdimm_bus_descriptor *nd_desc);
|
2016-02-22 21:50:31 -08:00
|
|
|
int (*clear_to_send)(struct nvdimm_bus_descriptor *nd_desc,
|
2018-12-04 10:31:11 -08:00
|
|
|
struct nvdimm *nvdimm, unsigned int cmd, void *data);
|
2015-05-19 22:54:31 -04:00
|
|
|
};
|
|
|
|
|
|
2015-06-08 14:27:06 -04:00
|
|
|
struct nd_cmd_desc {
|
|
|
|
|
int in_num;
|
|
|
|
|
int out_num;
|
|
|
|
|
u32 in_sizes[ND_CMD_MAX_ELEM];
|
|
|
|
|
int out_sizes[ND_CMD_MAX_ELEM];
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-01 13:11:27 -04:00
|
|
|
struct nd_interleave_set {
|
2017-06-04 10:59:15 +09:00
|
|
|
/* v1.1 definition of the interleave-set-cookie algorithm */
|
|
|
|
|
u64 cookie1;
|
|
|
|
|
/* v1.2 definition of the interleave-set-cookie algorithm */
|
|
|
|
|
u64 cookie2;
|
2017-02-28 18:32:48 -08:00
|
|
|
/* compatibility with initial buggy Linux implementation */
|
|
|
|
|
u64 altcookie;
|
2017-06-06 11:10:51 -07:00
|
|
|
|
|
|
|
|
guid_t type_guid;
|
2015-05-01 13:11:27 -04:00
|
|
|
};
|
|
|
|
|
|
2016-09-19 16:38:50 -07:00
|
|
|
struct nd_mapping_desc {
|
|
|
|
|
struct nvdimm *nvdimm;
|
|
|
|
|
u64 start;
|
|
|
|
|
u64 size;
|
2017-08-04 17:20:16 -07:00
|
|
|
int position;
|
2016-09-19 16:38:50 -07:00
|
|
|
};
|
|
|
|
|
|
2019-07-05 19:33:22 +05:30
|
|
|
struct nd_region;
|
2015-06-09 20:13:14 -04:00
|
|
|
struct nd_region_desc {
|
|
|
|
|
struct resource *res;
|
2016-09-19 16:38:50 -07:00
|
|
|
struct nd_mapping_desc *mapping;
|
2015-06-09 20:13:14 -04:00
|
|
|
u16 num_mappings;
|
|
|
|
|
const struct attribute_group **attr_groups;
|
2015-05-01 13:11:27 -04:00
|
|
|
struct nd_interleave_set *nd_set;
|
2015-06-09 20:13:14 -04:00
|
|
|
void *provider_data;
|
2015-06-25 04:20:32 -04:00
|
|
|
int num_lanes;
|
2015-06-19 12:18:33 -06:00
|
|
|
int numa_node;
|
2018-11-09 12:43:07 -08:00
|
|
|
int target_node;
|
2015-08-24 19:20:23 -04:00
|
|
|
unsigned long flags;
|
2018-04-06 15:21:13 +10:00
|
|
|
struct device_node *of_node;
|
2019-07-05 19:33:22 +05:30
|
|
|
int (*flush)(struct nd_region *nd_region, struct bio *bio);
|
2015-06-09 20:13:14 -04:00
|
|
|
};
|
|
|
|
|
|
2016-06-06 17:42:38 -07:00
|
|
|
struct device;
|
|
|
|
|
void *devm_nvdimm_memremap(struct device *dev, resource_size_t offset,
|
|
|
|
|
size_t size, unsigned long flags);
|
|
|
|
|
static inline void __iomem *devm_nvdimm_ioremap(struct device *dev,
|
|
|
|
|
resource_size_t offset, size_t size)
|
|
|
|
|
{
|
|
|
|
|
return (void __iomem *) devm_nvdimm_memremap(dev, offset, size, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 14:27:06 -04:00
|
|
|
struct nvdimm_bus;
|
2015-05-31 15:02:11 -04:00
|
|
|
struct module;
|
2015-06-25 04:21:02 -04:00
|
|
|
struct device;
|
|
|
|
|
struct nd_blk_region;
|
|
|
|
|
struct nd_blk_region_desc {
|
|
|
|
|
int (*enable)(struct nvdimm_bus *nvdimm_bus, struct device *dev);
|
|
|
|
|
int (*do_io)(struct nd_blk_region *ndbr, resource_size_t dpa,
|
|
|
|
|
void *iobuf, u64 len, int rw);
|
|
|
|
|
struct nd_region_desc ndr_desc;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static inline struct nd_blk_region_desc *to_blk_region_desc(
|
|
|
|
|
struct nd_region_desc *ndr_desc)
|
|
|
|
|
{
|
|
|
|
|
return container_of(ndr_desc, struct nd_blk_region_desc, ndr_desc);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-05 23:39:29 -08:00
|
|
|
enum nvdimm_security_state {
|
2019-01-08 15:34:52 -08:00
|
|
|
NVDIMM_SECURITY_ERROR = -1,
|
2018-12-05 23:39:29 -08:00
|
|
|
NVDIMM_SECURITY_DISABLED,
|
|
|
|
|
NVDIMM_SECURITY_UNLOCKED,
|
|
|
|
|
NVDIMM_SECURITY_LOCKED,
|
|
|
|
|
NVDIMM_SECURITY_FROZEN,
|
|
|
|
|
NVDIMM_SECURITY_OVERWRITE,
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-06 12:40:01 -08:00
|
|
|
#define NVDIMM_PASSPHRASE_LEN 32
|
|
|
|
|
#define NVDIMM_KEY_DESC_LEN 22
|
|
|
|
|
|
|
|
|
|
struct nvdimm_key_data {
|
|
|
|
|
u8 data[NVDIMM_PASSPHRASE_LEN];
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-10 10:53:22 -07:00
|
|
|
enum nvdimm_passphrase_type {
|
|
|
|
|
NVDIMM_USER,
|
|
|
|
|
NVDIMM_MASTER,
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-05 23:39:29 -08:00
|
|
|
struct nvdimm_security_ops {
|
2018-12-10 10:53:22 -07:00
|
|
|
enum nvdimm_security_state (*state)(struct nvdimm *nvdimm,
|
|
|
|
|
enum nvdimm_passphrase_type pass_type);
|
2018-12-06 09:14:08 -08:00
|
|
|
int (*freeze)(struct nvdimm *nvdimm);
|
2018-12-06 12:40:01 -08:00
|
|
|
int (*change_key)(struct nvdimm *nvdimm,
|
|
|
|
|
const struct nvdimm_key_data *old_data,
|
2018-12-10 10:53:22 -07:00
|
|
|
const struct nvdimm_key_data *new_data,
|
|
|
|
|
enum nvdimm_passphrase_type pass_type);
|
2018-12-06 12:40:01 -08:00
|
|
|
int (*unlock)(struct nvdimm *nvdimm,
|
|
|
|
|
const struct nvdimm_key_data *key_data);
|
2018-12-07 10:33:30 -07:00
|
|
|
int (*disable)(struct nvdimm *nvdimm,
|
|
|
|
|
const struct nvdimm_key_data *key_data);
|
2018-12-07 14:02:12 -07:00
|
|
|
int (*erase)(struct nvdimm *nvdimm,
|
2018-12-10 10:53:22 -07:00
|
|
|
const struct nvdimm_key_data *key_data,
|
|
|
|
|
enum nvdimm_passphrase_type pass_type);
|
2018-12-13 15:36:18 -07:00
|
|
|
int (*overwrite)(struct nvdimm *nvdimm,
|
|
|
|
|
const struct nvdimm_key_data *key_data);
|
|
|
|
|
int (*query_overwrite)(struct nvdimm *nvdimm);
|
2018-12-05 23:39:29 -08:00
|
|
|
};
|
|
|
|
|
|
2017-08-23 12:48:26 -07:00
|
|
|
void badrange_init(struct badrange *badrange);
|
|
|
|
|
int badrange_add(struct badrange *badrange, u64 addr, u64 length);
|
|
|
|
|
void badrange_forget(struct badrange *badrange, phys_addr_t start,
|
|
|
|
|
unsigned int len);
|
|
|
|
|
int nvdimm_bus_add_badrange(struct nvdimm_bus *nvdimm_bus, u64 addr,
|
|
|
|
|
u64 length);
|
2016-07-21 20:03:19 -07:00
|
|
|
struct nvdimm_bus *nvdimm_bus_register(struct device *parent,
|
|
|
|
|
struct nvdimm_bus_descriptor *nfit_desc);
|
2015-05-19 22:54:31 -04:00
|
|
|
void nvdimm_bus_unregister(struct nvdimm_bus *nvdimm_bus);
|
2015-04-26 19:26:48 -04:00
|
|
|
struct nvdimm_bus *to_nvdimm_bus(struct device *dev);
|
2018-12-05 23:39:29 -08:00
|
|
|
struct nvdimm_bus *nvdimm_to_bus(struct nvdimm *nvdimm);
|
2015-04-25 03:56:17 -04:00
|
|
|
struct nvdimm *to_nvdimm(struct device *dev);
|
2015-06-09 20:13:14 -04:00
|
|
|
struct nd_region *to_nd_region(struct device *dev);
|
2018-04-02 13:14:25 -07:00
|
|
|
struct device *nd_region_dev(struct nd_region *nd_region);
|
2015-06-25 04:21:02 -04:00
|
|
|
struct nd_blk_region *to_nd_blk_region(struct device *dev);
|
2015-04-26 19:26:48 -04:00
|
|
|
struct nvdimm_bus_descriptor *to_nd_desc(struct nvdimm_bus *nvdimm_bus);
|
2016-07-23 21:51:42 -07:00
|
|
|
struct device *to_nvdimm_bus_dev(struct nvdimm_bus *nvdimm_bus);
|
2015-04-25 03:56:17 -04:00
|
|
|
const char *nvdimm_name(struct nvdimm *nvdimm);
|
2016-08-22 19:28:37 -07:00
|
|
|
struct kobject *nvdimm_kobj(struct nvdimm *nvdimm);
|
2016-04-28 16:17:07 -07:00
|
|
|
unsigned long nvdimm_cmd_mask(struct nvdimm *nvdimm);
|
2015-04-25 03:56:17 -04:00
|
|
|
void *nvdimm_provider_data(struct nvdimm *nvdimm);
|
2018-12-04 10:31:20 -08:00
|
|
|
struct nvdimm *__nvdimm_create(struct nvdimm_bus *nvdimm_bus,
|
|
|
|
|
void *provider_data, const struct attribute_group **groups,
|
|
|
|
|
unsigned long flags, unsigned long cmd_mask, int num_flush,
|
2018-12-05 23:39:29 -08:00
|
|
|
struct resource *flush_wpq, const char *dimm_id,
|
|
|
|
|
const struct nvdimm_security_ops *sec_ops);
|
2018-12-04 10:31:20 -08:00
|
|
|
static inline struct nvdimm *nvdimm_create(struct nvdimm_bus *nvdimm_bus,
|
|
|
|
|
void *provider_data, const struct attribute_group **groups,
|
|
|
|
|
unsigned long flags, unsigned long cmd_mask, int num_flush,
|
|
|
|
|
struct resource *flush_wpq)
|
|
|
|
|
{
|
|
|
|
|
return __nvdimm_create(nvdimm_bus, provider_data, groups, flags,
|
2018-12-05 23:39:29 -08:00
|
|
|
cmd_mask, num_flush, flush_wpq, NULL, NULL);
|
2018-12-04 10:31:20 -08:00
|
|
|
}
|
|
|
|
|
|
2015-06-08 14:27:06 -04:00
|
|
|
const struct nd_cmd_desc *nd_cmd_dimm_desc(int cmd);
|
|
|
|
|
const struct nd_cmd_desc *nd_cmd_bus_desc(int cmd);
|
|
|
|
|
u32 nd_cmd_in_size(struct nvdimm *nvdimm, int cmd,
|
|
|
|
|
const struct nd_cmd_desc *desc, int idx, void *buf);
|
|
|
|
|
u32 nd_cmd_out_size(struct nvdimm *nvdimm, int cmd,
|
|
|
|
|
const struct nd_cmd_desc *desc, int idx, const u32 *in_field,
|
2016-12-06 09:10:12 -08:00
|
|
|
const u32 *out_field, unsigned long remainder);
|
2015-05-31 14:41:48 -04:00
|
|
|
int nvdimm_bus_check_dimm_count(struct nvdimm_bus *nvdimm_bus, int dimm_count);
|
2015-06-09 20:13:14 -04:00
|
|
|
struct nd_region *nvdimm_pmem_region_create(struct nvdimm_bus *nvdimm_bus,
|
|
|
|
|
struct nd_region_desc *ndr_desc);
|
|
|
|
|
struct nd_region *nvdimm_blk_region_create(struct nvdimm_bus *nvdimm_bus,
|
|
|
|
|
struct nd_region_desc *ndr_desc);
|
|
|
|
|
struct nd_region *nvdimm_volatile_region_create(struct nvdimm_bus *nvdimm_bus,
|
|
|
|
|
struct nd_region_desc *ndr_desc);
|
2015-06-25 04:21:02 -04:00
|
|
|
void *nd_region_provider_data(struct nd_region *nd_region);
|
|
|
|
|
void *nd_blk_region_provider_data(struct nd_blk_region *ndbr);
|
|
|
|
|
void nd_blk_region_set_provider_data(struct nd_blk_region *ndbr, void *data);
|
|
|
|
|
struct nvdimm *nd_blk_region_to_dimm(struct nd_blk_region *ndbr);
|
2017-01-13 20:36:58 -08:00
|
|
|
unsigned long nd_blk_memremap_flags(struct nd_blk_region *ndbr);
|
2015-06-25 04:21:02 -04:00
|
|
|
unsigned int nd_region_acquire_lane(struct nd_region *nd_region);
|
|
|
|
|
void nd_region_release_lane(struct nd_region *nd_region, unsigned int lane);
|
2015-05-01 13:11:27 -04:00
|
|
|
u64 nd_fletcher64(void *addr, size_t len, bool le);
|
2019-07-05 19:33:22 +05:30
|
|
|
int nvdimm_flush(struct nd_region *nd_region, struct bio *bio);
|
|
|
|
|
int generic_nvdimm_flush(struct nd_region *nd_region);
|
2016-07-07 19:44:50 -07:00
|
|
|
int nvdimm_has_flush(struct nd_region *nd_region);
|
2017-06-09 09:46:50 -07:00
|
|
|
int nvdimm_has_cache(struct nd_region *nd_region);
|
2018-12-13 15:36:18 -07:00
|
|
|
int nvdimm_in_overwrite(struct nvdimm *nvdimm);
|
2017-08-31 12:27:09 +01:00
|
|
|
|
2018-12-05 23:39:29 -08:00
|
|
|
static inline int nvdimm_ctl(struct nvdimm *nvdimm, unsigned int cmd, void *buf,
|
|
|
|
|
unsigned int buf_len, int *cmd_rc)
|
|
|
|
|
{
|
|
|
|
|
struct nvdimm_bus *nvdimm_bus = nvdimm_to_bus(nvdimm);
|
|
|
|
|
struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
|
|
|
|
|
|
|
|
|
|
return nd_desc->ndctl(nd_desc, nvdimm, cmd, buf, buf_len, cmd_rc);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-31 12:27:09 +01:00
|
|
|
#ifdef CONFIG_ARCH_HAS_PMEM_API
|
|
|
|
|
#define ARCH_MEMREMAP_PMEM MEMREMAP_WB
|
|
|
|
|
void arch_wb_cache_pmem(void *addr, size_t size);
|
|
|
|
|
void arch_invalidate_pmem(void *addr, size_t size);
|
|
|
|
|
#else
|
|
|
|
|
#define ARCH_MEMREMAP_PMEM MEMREMAP_WT
|
|
|
|
|
static inline void arch_wb_cache_pmem(void *addr, size_t size)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
static inline void arch_invalidate_pmem(void *addr, size_t size)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-05-19 22:54:31 -04:00
|
|
|
#endif /* __LIBNVDIMM_H__ */
|