2015-05-31 21:41:48 +03:00
|
|
|
/*
|
|
|
|
* Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*/
|
|
|
|
#ifndef __LINUX_ND_H__
|
|
|
|
#define __LINUX_ND_H__
|
2015-06-25 11:20:04 +03:00
|
|
|
#include <linux/fs.h>
|
2015-05-31 21:41:48 +03:00
|
|
|
#include <linux/ndctl.h>
|
|
|
|
#include <linux/device.h>
|
2016-03-22 10:22:16 +03:00
|
|
|
#include <linux/badblocks.h>
|
2015-05-31 21:41:48 +03:00
|
|
|
|
2016-02-18 21:29:49 +03:00
|
|
|
enum nvdimm_event {
|
|
|
|
NVDIMM_REVALIDATE_POISON,
|
|
|
|
};
|
|
|
|
|
2015-05-31 21:41:48 +03:00
|
|
|
struct nd_device_driver {
|
|
|
|
struct device_driver drv;
|
|
|
|
unsigned long type;
|
|
|
|
int (*probe)(struct device *dev);
|
|
|
|
int (*remove)(struct device *dev);
|
2016-07-09 10:12:52 +03:00
|
|
|
void (*shutdown)(struct device *dev);
|
2016-02-18 21:29:49 +03:00
|
|
|
void (*notify)(struct device *dev, enum nvdimm_event event);
|
2015-05-31 21:41:48 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct nd_device_driver *to_nd_device_driver(
|
|
|
|
struct device_driver *drv)
|
|
|
|
{
|
|
|
|
return container_of(drv, struct nd_device_driver, drv);
|
2015-05-31 22:02:11 +03:00
|
|
|
};
|
|
|
|
|
2015-06-25 11:20:04 +03:00
|
|
|
/**
|
|
|
|
* struct nd_namespace_common - core infrastructure of a namespace
|
|
|
|
* @force_raw: ignore other personalities for the namespace (e.g. btt)
|
|
|
|
* @dev: device model node
|
|
|
|
* @claim: when set a another personality has taken ownership of the namespace
|
|
|
|
* @rw_bytes: access the raw namespace capacity with byte-aligned transfers
|
|
|
|
*/
|
|
|
|
struct nd_namespace_common {
|
|
|
|
int force_raw;
|
|
|
|
struct device dev;
|
|
|
|
struct device *claim;
|
|
|
|
int (*rw_bytes)(struct nd_namespace_common *, resource_size_t offset,
|
|
|
|
void *buf, size_t size, int rw);
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct nd_namespace_common *to_ndns(struct device *dev)
|
|
|
|
{
|
|
|
|
return container_of(dev, struct nd_namespace_common, dev);
|
|
|
|
}
|
|
|
|
|
2015-06-18 00:14:46 +03:00
|
|
|
/**
|
2016-03-22 10:22:16 +03:00
|
|
|
* struct nd_namespace_io - device representation of a persistent memory range
|
2015-06-18 00:14:46 +03:00
|
|
|
* @dev: namespace device created by the nd region driver
|
|
|
|
* @res: struct resource conversion of a NFIT SPA table
|
2016-03-22 10:22:16 +03:00
|
|
|
* @size: cached resource_size(@res) for fast path size checks
|
|
|
|
* @addr: virtual address to access the namespace range
|
|
|
|
* @bb: badblocks list for the namespace range
|
2015-06-18 00:14:46 +03:00
|
|
|
*/
|
2015-05-31 22:02:11 +03:00
|
|
|
struct nd_namespace_io {
|
2015-06-25 11:20:04 +03:00
|
|
|
struct nd_namespace_common common;
|
2015-05-31 22:02:11 +03:00
|
|
|
struct resource res;
|
2016-03-22 10:22:16 +03:00
|
|
|
resource_size_t size;
|
2016-06-04 04:06:47 +03:00
|
|
|
void *addr;
|
2016-03-22 10:22:16 +03:00
|
|
|
struct badblocks bb;
|
2015-05-31 22:02:11 +03:00
|
|
|
};
|
|
|
|
|
2015-06-18 00:14:46 +03:00
|
|
|
/**
|
|
|
|
* struct nd_namespace_pmem - namespace device for dimm-backed interleaved memory
|
|
|
|
* @nsio: device and system physical address range to drive
|
|
|
|
* @alt_name: namespace name supplied in the dimm label
|
|
|
|
* @uuid: namespace name supplied in the dimm label
|
|
|
|
*/
|
|
|
|
struct nd_namespace_pmem {
|
|
|
|
struct nd_namespace_io nsio;
|
|
|
|
char *alt_name;
|
|
|
|
u8 *uuid;
|
|
|
|
};
|
|
|
|
|
2015-05-01 20:34:01 +03:00
|
|
|
/**
|
|
|
|
* struct nd_namespace_blk - namespace for dimm-bounded persistent memory
|
|
|
|
* @alt_name: namespace name supplied in the dimm label
|
|
|
|
* @uuid: namespace name supplied in the dimm label
|
|
|
|
* @id: ida allocated id
|
|
|
|
* @lbasize: blk namespaces have a native sector size when btt not present
|
2016-03-18 21:27:36 +03:00
|
|
|
* @size: sum of all the resource ranges allocated to this namespace
|
2015-05-01 20:34:01 +03:00
|
|
|
* @num_resources: number of dpa extents to claim
|
|
|
|
* @res: discontiguous dpa extents for given dimm
|
|
|
|
*/
|
|
|
|
struct nd_namespace_blk {
|
2015-06-25 11:20:04 +03:00
|
|
|
struct nd_namespace_common common;
|
2015-05-01 20:34:01 +03:00
|
|
|
char *alt_name;
|
|
|
|
u8 *uuid;
|
|
|
|
int id;
|
|
|
|
unsigned long lbasize;
|
2016-03-18 21:27:36 +03:00
|
|
|
resource_size_t size;
|
2015-05-01 20:34:01 +03:00
|
|
|
int num_resources;
|
|
|
|
struct resource **res;
|
|
|
|
};
|
|
|
|
|
2015-05-31 22:02:11 +03:00
|
|
|
static inline struct nd_namespace_io *to_nd_namespace_io(struct device *dev)
|
|
|
|
{
|
2015-06-25 11:20:04 +03:00
|
|
|
return container_of(dev, struct nd_namespace_io, common.dev);
|
2015-05-31 21:41:48 +03:00
|
|
|
}
|
|
|
|
|
2015-06-18 00:14:46 +03:00
|
|
|
static inline struct nd_namespace_pmem *to_nd_namespace_pmem(struct device *dev)
|
|
|
|
{
|
|
|
|
struct nd_namespace_io *nsio = to_nd_namespace_io(dev);
|
|
|
|
|
|
|
|
return container_of(nsio, struct nd_namespace_pmem, nsio);
|
|
|
|
}
|
|
|
|
|
2015-05-01 20:34:01 +03:00
|
|
|
static inline struct nd_namespace_blk *to_nd_namespace_blk(struct device *dev)
|
|
|
|
{
|
2015-06-25 11:20:04 +03:00
|
|
|
return container_of(dev, struct nd_namespace_blk, common.dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nvdimm_read_bytes() - synchronously read bytes from an nvdimm namespace
|
|
|
|
* @ndns: device to read
|
|
|
|
* @offset: namespace-relative starting offset
|
|
|
|
* @buf: buffer to fill
|
|
|
|
* @size: transfer length
|
|
|
|
*
|
|
|
|
* @buf is up-to-date upon return from this routine.
|
|
|
|
*/
|
|
|
|
static inline int nvdimm_read_bytes(struct nd_namespace_common *ndns,
|
|
|
|
resource_size_t offset, void *buf, size_t size)
|
|
|
|
{
|
|
|
|
return ndns->rw_bytes(ndns, offset, buf, size, READ);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nvdimm_write_bytes() - synchronously write bytes to an nvdimm namespace
|
|
|
|
* @ndns: device to read
|
|
|
|
* @offset: namespace-relative starting offset
|
|
|
|
* @buf: buffer to drain
|
|
|
|
* @size: transfer length
|
|
|
|
*
|
|
|
|
* NVDIMM Namepaces disks do not implement sectors internally. Depending on
|
|
|
|
* the @ndns, the contents of @buf may be in cpu cache, platform buffers,
|
|
|
|
* or on backing memory media upon return from this routine. Flushing
|
|
|
|
* to media is handled internal to the @ndns driver, if at all.
|
|
|
|
*/
|
|
|
|
static inline int nvdimm_write_bytes(struct nd_namespace_common *ndns,
|
|
|
|
resource_size_t offset, void *buf, size_t size)
|
|
|
|
{
|
|
|
|
return ndns->rw_bytes(ndns, offset, buf, size, WRITE);
|
2015-05-01 20:34:01 +03:00
|
|
|
}
|
|
|
|
|
2015-05-31 21:41:48 +03:00
|
|
|
#define MODULE_ALIAS_ND_DEVICE(type) \
|
|
|
|
MODULE_ALIAS("nd:t" __stringify(type) "*")
|
|
|
|
#define ND_DEVICE_MODALIAS_FMT "nd:t%d"
|
|
|
|
|
2016-02-18 21:29:49 +03:00
|
|
|
struct nd_region;
|
|
|
|
void nvdimm_region_notify(struct nd_region *nd_region, enum nvdimm_event event);
|
2015-05-31 21:41:48 +03:00
|
|
|
int __must_check __nd_driver_register(struct nd_device_driver *nd_drv,
|
|
|
|
struct module *module, const char *mod_name);
|
|
|
|
#define nd_driver_register(driver) \
|
|
|
|
__nd_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
|
|
|
|
#endif /* __LINUX_ND_H__ */
|