#include <linux/memremap.h>
#include <linux/blkdev.h>
#include <linux/device.h>
static void nd_pfn_release(struct device *dev)
struct nd_region *nd_region = to_nd_region(dev->parent);
struct nd_pfn *nd_pfn = to_nd_pfn(dev);
nd_detach_ndns(&nd_pfn->dev, &nd_pfn->ndns);
ida_simple_remove(&nd_region->pfn_ida, nd_pfn->id);
static struct device_type nd_pfn_device_type = {
.release = nd_pfn_release,
bool is_nd_pfn(struct device *dev)
return dev ? dev->type == &nd_pfn_device_type : false;
EXPORT_SYMBOL(is_nd_pfn);
struct nd_pfn *to_nd_pfn(struct device *dev)
struct nd_pfn *nd_pfn = container_of(dev, struct nd_pfn, dev);
WARN_ON(!is_nd_pfn(dev));
EXPORT_SYMBOL(to_nd_pfn);
static ssize_t mode_show(struct device *dev,
struct device_attribute *attr, char *buf)
struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev);
return sprintf(buf, "ram\n");
return sprintf(buf, "pmem\n");
return sprintf(buf, "none\n");
static ssize_t mode_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev);
if (strncmp(buf, "pmem\n", n) == 0
|| strncmp(buf, "pmem", n) == 0) {
nd_pfn->mode = PFN_MODE_PMEM;
} else if (strncmp(buf, "ram\n", n) == 0
|| strncmp(buf, "ram", n) == 0)
nd_pfn->mode = PFN_MODE_RAM;
else if (strncmp(buf, "none\n", n) == 0
|| strncmp(buf, "none", n) == 0)