Commit 8759957b authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'libnvdimm-for-4.6' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm

Pull libnvdimm updates from Dan Williams:

 - Asynchronous address range scrub:

     Given the capacities of next generation persistent memory devices a
     scrub operation to find all poison may take 10s of seconds.  We
     want this scrub work to be done asynchronously with the rest of
     system initialization, so we move it out of line from the NFIT
     probing, i.e. acpi_nfit_add().

 - Clear poison:

     ACPI 6.1 introduces the ability to send "clear error" commands to
     the ACPI0012:00 device representing the root of an "nvdimm bus".
     Similar to relocating a bad block on a disk, this support clears
     media errors in response to a write.

 - Persistent memory resource tracking:

     A persistent memory range may be designated as simply "reserved" by
     platform firmware in the efi/e820 memory map.  Later when the NFIT
     driver loads it discovers that the range is "Persistent Memory".

     The NFIT bus driver inserts a resource to advertise that
     "persistent" attribute in the system resource tree for /proc/iomem
     and kernel-internal usages.

 - Miscellaneous cleanups and fixes:

     Workaround section misaligned pmem ranges when allocating a struct
     page memmap, fix handling of the read-only case in the ioctl path,
     and clean up block device major number allocation.

* tag 'libnvdimm-for-4.6' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm: (26 commits)
  libnvdimm, pmem: clear poison on write
  libnvdimm, pmem: fix kmap_atomic() leak in error path
  nvdimm/btt: don't allocate unused major device number
  nvdimm/blk: don't allocate unused major device number
  pmem: don't allocate unused major device number
  ACPI: Change NFIT driver to insert new resource
  resource: Export insert_resource and remove_resource
  resource: Add remove_resource interface
  resource: Change __request_region to inherit from immediate parent
  libnvdimm, pmem: fix ia64 build, use PHYS_PFN
  nfit, libnvdimm: clear poison command support
  libnvdimm, pfn: 'resource'-address and 'size' attributes for pfn devices
  libnvdimm, pmem: adjust for section collisions with 'System RAM'
  libnvdimm, pmem: fix 'pfn' support for section-misaligned namespaces
  libnvdimm: Fix security issue with DSM IOCTL.
  libnvdimm: Clean-up access mode check.
  tools/testing/nvdimm: expand ars unit testing
  nfit: disable userspace initiated ars during scrub
  nfit: scrub and register regions in a workqueue
  nfit, libnvdimm: async region scrub workqueue
  ...
parents 6968e6f8 48901165
...@@ -137,6 +137,11 @@ static inline void arch_clear_pmem(void __pmem *addr, size_t size) ...@@ -137,6 +137,11 @@ static inline void arch_clear_pmem(void __pmem *addr, size_t size)
arch_wb_cache_pmem(addr, size); arch_wb_cache_pmem(addr, size);
} }
static inline void arch_invalidate_pmem(void __pmem *addr, size_t size)
{
clflush_cache_range((void __force *) addr, size);
}
static inline bool __arch_has_wmb_pmem(void) static inline bool __arch_has_wmb_pmem(void)
{ {
/* /*
......
This diff is collapsed.
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#ifndef __NFIT_H__ #ifndef __NFIT_H__
#define __NFIT_H__ #define __NFIT_H__
#include <linux/workqueue.h>
#include <linux/libnvdimm.h> #include <linux/libnvdimm.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/uuid.h> #include <linux/uuid.h>
...@@ -40,15 +41,32 @@ enum nfit_uuids { ...@@ -40,15 +41,32 @@ enum nfit_uuids {
NFIT_UUID_MAX, NFIT_UUID_MAX,
}; };
enum nfit_fic {
NFIT_FIC_BYTE = 0x101, /* byte-addressable energy backed */
NFIT_FIC_BLK = 0x201, /* block-addressable non-energy backed */
NFIT_FIC_BYTEN = 0x301, /* byte-addressable non-energy backed */
};
enum { enum {
ND_BLK_READ_FLUSH = 1, NFIT_BLK_READ_FLUSH = 1,
ND_BLK_DCR_LATCH = 2, NFIT_BLK_DCR_LATCH = 2,
NFIT_ARS_STATUS_DONE = 0,
NFIT_ARS_STATUS_BUSY = 1 << 16,
NFIT_ARS_STATUS_NONE = 2 << 16,
NFIT_ARS_STATUS_INTR = 3 << 16,
NFIT_ARS_START_BUSY = 6,
NFIT_ARS_CAP_NONE = 1,
NFIT_ARS_F_OVERFLOW = 1,
NFIT_ARS_TIMEOUT = 90,
}; };
struct nfit_spa { struct nfit_spa {
struct acpi_nfit_system_address *spa; struct acpi_nfit_system_address *spa;
struct list_head list; struct list_head list;
int is_registered; struct nd_region *nd_region;
unsigned int ars_done:1;
u32 clear_err_unit;
u32 max_ars;
}; };
struct nfit_dcr { struct nfit_dcr {
...@@ -110,6 +128,10 @@ struct acpi_nfit_desc { ...@@ -110,6 +128,10 @@ struct acpi_nfit_desc {
struct list_head idts; struct list_head idts;
struct nvdimm_bus *nvdimm_bus; struct nvdimm_bus *nvdimm_bus;
struct device *dev; struct device *dev;
struct nd_cmd_ars_status *ars_status;
size_t ars_status_size;
struct work_struct work;
unsigned int cancel:1;
unsigned long dimm_dsm_force_en; unsigned long dimm_dsm_force_en;
unsigned long bus_dsm_force_en; unsigned long bus_dsm_force_en;
int (*blk_do_io)(struct nd_blk_region *ndbr, resource_size_t dpa, int (*blk_do_io)(struct nd_blk_region *ndbr, resource_size_t dpa,
...@@ -182,5 +204,5 @@ static inline struct acpi_nfit_desc *to_acpi_desc( ...@@ -182,5 +204,5 @@ static inline struct acpi_nfit_desc *to_acpi_desc(
const u8 *to_nfit_uuid(enum nfit_uuids id); const u8 *to_nfit_uuid(enum nfit_uuids id);
int acpi_nfit_init(struct acpi_nfit_desc *nfit, acpi_size sz); int acpi_nfit_init(struct acpi_nfit_desc *nfit, acpi_size sz);
extern const struct attribute_group *acpi_nfit_attribute_groups[]; void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev);
#endif /* __NFIT_H__ */ #endif /* __NFIT_H__ */
...@@ -31,8 +31,6 @@ struct nd_blk_device { ...@@ -31,8 +31,6 @@ struct nd_blk_device {
u32 internal_lbasize; u32 internal_lbasize;
}; };
static int nd_blk_major;
static u32 nd_blk_meta_size(struct nd_blk_device *blk_dev) static u32 nd_blk_meta_size(struct nd_blk_device *blk_dev)
{ {
return blk_dev->nsblk->lbasize - blk_dev->sector_size; return blk_dev->nsblk->lbasize - blk_dev->sector_size;
...@@ -264,7 +262,6 @@ static int nd_blk_attach_disk(struct nd_namespace_common *ndns, ...@@ -264,7 +262,6 @@ static int nd_blk_attach_disk(struct nd_namespace_common *ndns,
} }
disk->driverfs_dev = &ndns->dev; disk->driverfs_dev = &ndns->dev;
disk->major = nd_blk_major;
disk->first_minor = 0; disk->first_minor = 0;
disk->fops = &nd_blk_fops; disk->fops = &nd_blk_fops;
disk->private_data = blk_dev; disk->private_data = blk_dev;
...@@ -358,25 +355,12 @@ static struct nd_device_driver nd_blk_driver = { ...@@ -358,25 +355,12 @@ static struct nd_device_driver nd_blk_driver = {
static int __init nd_blk_init(void) static int __init nd_blk_init(void)
{ {
int rc; return nd_driver_register(&nd_blk_driver);
rc = register_blkdev(0, "nd_blk");
if (rc < 0)
return rc;
nd_blk_major = rc;
rc = nd_driver_register(&nd_blk_driver);
if (rc < 0)
unregister_blkdev(nd_blk_major, "nd_blk");
return rc;
} }
static void __exit nd_blk_exit(void) static void __exit nd_blk_exit(void)
{ {
driver_unregister(&nd_blk_driver.drv); driver_unregister(&nd_blk_driver.drv);
unregister_blkdev(nd_blk_major, "nd_blk");
} }
MODULE_AUTHOR("Ross Zwisler <ross.zwisler@linux.intel.com>"); MODULE_AUTHOR("Ross Zwisler <ross.zwisler@linux.intel.com>");
......
...@@ -31,8 +31,6 @@ enum log_ent_request { ...@@ -31,8 +31,6 @@ enum log_ent_request {
LOG_OLD_ENT LOG_OLD_ENT
}; };
static int btt_major;
static int arena_read_bytes(struct arena_info *arena, resource_size_t offset, static int arena_read_bytes(struct arena_info *arena, resource_size_t offset,
void *buf, size_t n) void *buf, size_t n)
{ {
...@@ -1246,7 +1244,6 @@ static int btt_blk_init(struct btt *btt) ...@@ -1246,7 +1244,6 @@ static int btt_blk_init(struct btt *btt)
nvdimm_namespace_disk_name(ndns, btt->btt_disk->disk_name); nvdimm_namespace_disk_name(ndns, btt->btt_disk->disk_name);
btt->btt_disk->driverfs_dev = &btt->nd_btt->dev; btt->btt_disk->driverfs_dev = &btt->nd_btt->dev;
btt->btt_disk->major = btt_major;
btt->btt_disk->first_minor = 0; btt->btt_disk->first_minor = 0;
btt->btt_disk->fops = &btt_fops; btt->btt_disk->fops = &btt_fops;
btt->btt_disk->private_data = btt; btt->btt_disk->private_data = btt;
...@@ -1423,22 +1420,11 @@ EXPORT_SYMBOL(nvdimm_namespace_detach_btt); ...@@ -1423,22 +1420,11 @@ EXPORT_SYMBOL(nvdimm_namespace_detach_btt);
static int __init nd_btt_init(void) static int __init nd_btt_init(void)
{ {
int rc; int rc = 0;
btt_major = register_blkdev(0, "btt");
if (btt_major < 0)
return btt_major;
debugfs_root = debugfs_create_dir("btt", NULL); debugfs_root = debugfs_create_dir("btt", NULL);
if (IS_ERR_OR_NULL(debugfs_root)) { if (IS_ERR_OR_NULL(debugfs_root))
rc = -ENXIO; rc = -ENXIO;
goto err_debugfs;
}
return 0;
err_debugfs:
unregister_blkdev(btt_major, "btt");
return rc; return rc;
} }
...@@ -1446,7 +1432,6 @@ static int __init nd_btt_init(void) ...@@ -1446,7 +1432,6 @@ static int __init nd_btt_init(void)
static void __exit nd_btt_exit(void) static void __exit nd_btt_exit(void)
{ {
debugfs_remove_recursive(debugfs_root); debugfs_remove_recursive(debugfs_root);
unregister_blkdev(btt_major, "btt");
} }
MODULE_ALIAS_ND_DEVICE(ND_DEVICE_BTT); MODULE_ALIAS_ND_DEVICE(ND_DEVICE_BTT);
......
...@@ -133,6 +133,78 @@ static int nvdimm_bus_remove(struct device *dev) ...@@ -133,6 +133,78 @@ static int nvdimm_bus_remove(struct device *dev)
return rc; return rc;
} }
void nd_device_notify(struct device *dev, enum nvdimm_event event)
{
device_lock(dev);
if (dev->driver) {
struct nd_device_driver *nd_drv;
nd_drv = to_nd_device_driver(dev->driver);
if (nd_drv->notify)
nd_drv->notify(dev, event);
}
device_unlock(dev);
}
EXPORT_SYMBOL(nd_device_notify);
void nvdimm_region_notify(struct nd_region *nd_region, enum nvdimm_event event)
{
struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev);
if (!nvdimm_bus)
return;
/* caller is responsible for holding a reference on the device */
nd_device_notify(&nd_region->dev, event);
}
EXPORT_SYMBOL_GPL(nvdimm_region_notify);
long nvdimm_clear_poison(struct device *dev, phys_addr_t phys,
unsigned int len)
{
struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
struct nvdimm_bus_descriptor *nd_desc;
struct nd_cmd_clear_error clear_err;
struct nd_cmd_ars_cap ars_cap;
u32 clear_err_unit, mask;
int cmd_rc, rc;
if (!nvdimm_bus)
return -ENXIO;
nd_desc = nvdimm_bus->nd_desc;
if (!nd_desc->ndctl)
return -ENXIO;
memset(&ars_cap, 0, sizeof(ars_cap));
ars_cap.address = phys;
ars_cap.length = len;
rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_CAP, &ars_cap,
sizeof(ars_cap), &cmd_rc);
if (rc < 0)
return rc;
if (cmd_rc < 0)
return cmd_rc;
clear_err_unit = ars_cap.clear_err_unit;
if (!clear_err_unit || !is_power_of_2(clear_err_unit))
return -ENXIO;
mask = clear_err_unit - 1;
if ((phys | len) & mask)
return -ENXIO;
memset(&clear_err, 0, sizeof(clear_err));
clear_err.address = phys;
clear_err.length = len;
rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_CLEAR_ERROR, &clear_err,
sizeof(clear_err), &cmd_rc);
if (rc < 0)
return rc;
if (cmd_rc < 0)
return cmd_rc;
return clear_err.cleared;
}
EXPORT_SYMBOL_GPL(nvdimm_clear_poison);
static struct bus_type nvdimm_bus_type = { static struct bus_type nvdimm_bus_type = {
.name = "nd", .name = "nd",
.uevent = nvdimm_bus_uevent, .uevent = nvdimm_bus_uevent,
...@@ -395,6 +467,12 @@ static const struct nd_cmd_desc __nd_cmd_bus_descs[] = { ...@@ -395,6 +467,12 @@ static const struct nd_cmd_desc __nd_cmd_bus_descs[] = {
.out_num = 3, .out_num = 3,
.out_sizes = { 4, 4, UINT_MAX, }, .out_sizes = { 4, 4, UINT_MAX, },
}, },
[ND_CMD_CLEAR_ERROR] = {
.in_num = 2,
.in_sizes = { 8, 8, },
.out_num = 3,
.out_sizes = { 4, 4, 8, },
},
}; };
const struct nd_cmd_desc *nd_cmd_bus_desc(int cmd) const struct nd_cmd_desc *nd_cmd_bus_desc(int cmd)
...@@ -463,17 +541,37 @@ void wait_nvdimm_bus_probe_idle(struct device *dev) ...@@ -463,17 +541,37 @@ void wait_nvdimm_bus_probe_idle(struct device *dev)
} while (true); } while (true);
} }
static int pmem_active(struct device *dev, void *data)
{
if (is_nd_pmem(dev) && dev->driver)
return -EBUSY;
return 0;
}
/* set_config requires an idle interleave set */ /* set_config requires an idle interleave set */
static int nd_cmd_clear_to_send(struct nvdimm *nvdimm, unsigned int cmd) static int nd_cmd_clear_to_send(struct nvdimm_bus *nvdimm_bus,
struct nvdimm *nvdimm, unsigned int cmd)
{ {
struct nvdimm_bus *nvdimm_bus; struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc;
/* ask the bus provider if it would like to block this request */
if (nd_desc->clear_to_send) {
int rc = nd_desc->clear_to_send(nd_desc, nvdimm, cmd);
if (rc)
return rc;
}
/* require clear error to go through the pmem driver */
if (!nvdimm && cmd == ND_CMD_CLEAR_ERROR)
return device_for_each_child(&nvdimm_bus->dev, NULL,
pmem_active);
if (!nvdimm || cmd != ND_CMD_SET_CONFIG_DATA) if (!nvdimm || cmd != ND_CMD_SET_CONFIG_DATA)
return 0; return 0;
nvdimm_bus = walk_to_nvdimm_bus(&nvdimm->dev); /* prevent label manipulation while the kernel owns label updates */
wait_nvdimm_bus_probe_idle(&nvdimm_bus->dev); wait_nvdimm_bus_probe_idle(&nvdimm_bus->dev);
if (atomic_read(&nvdimm->busy)) if (atomic_read(&nvdimm->busy))
return -EBUSY; return -EBUSY;
return 0; return 0;
...@@ -513,10 +611,11 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, ...@@ -513,10 +611,11 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm,
/* fail write commands (when read-only) */ /* fail write commands (when read-only) */
if (read_only) if (read_only)
switch (ioctl_cmd) { switch (cmd) {
case ND_IOCTL_VENDOR: case ND_CMD_VENDOR:
case ND_IOCTL_SET_CONFIG_DATA: case ND_CMD_SET_CONFIG_DATA:
case ND_IOCTL_ARS_START: case ND_CMD_ARS_START:
case ND_CMD_CLEAR_ERROR:
dev_dbg(&nvdimm_bus->dev, "'%s' command while read-only.\n", dev_dbg(&nvdimm_bus->dev, "'%s' command while read-only.\n",
nvdimm ? nvdimm_cmd_name(cmd) nvdimm ? nvdimm_cmd_name(cmd)
: nvdimm_bus_cmd_name(cmd)); : nvdimm_bus_cmd_name(cmd));
...@@ -583,11 +682,11 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, ...@@ -583,11 +682,11 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm,
} }
nvdimm_bus_lock(&nvdimm_bus->dev); nvdimm_bus_lock(&nvdimm_bus->dev);
rc = nd_cmd_clear_to_send(nvdimm, cmd); rc = nd_cmd_clear_to_send(nvdimm_bus, nvdimm, cmd);
if (rc) if (rc)
goto out_unlock; goto out_unlock;
rc = nd_desc->ndctl(nd_desc, nvdimm, cmd, buf, buf_len); rc = nd_desc->ndctl(nd_desc, nvdimm, cmd, buf, buf_len, NULL);
if (rc < 0) if (rc < 0)
goto out_unlock; goto out_unlock;
if (copy_to_user(p, buf, buf_len)) if (copy_to_user(p, buf, buf_len))
...@@ -602,14 +701,14 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, ...@@ -602,14 +701,14 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm,
static long nd_ioctl(struct file *file, unsigned int cmd, unsigned long arg) static long nd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ {
long id = (long) file->private_data; long id = (long) file->private_data;
int rc = -ENXIO, read_only; int rc = -ENXIO, ro;
struct nvdimm_bus *nvdimm_bus; struct nvdimm_bus *nvdimm_bus;
read_only = (O_RDWR != (file->f_flags & O_ACCMODE)); ro = ((file->f_flags & O_ACCMODE) == O_RDONLY);
mutex_lock(&nvdimm_bus_list_mutex); mutex_lock(&nvdimm_bus_list_mutex);
list_for_each_entry(nvdimm_bus, &nvdimm_bus_list, list) { list_for_each_entry(nvdimm_bus, &nvdimm_bus_list, list) {
if (nvdimm_bus->id == id) { if (nvdimm_bus->id == id) {
rc = __nd_ioctl(nvdimm_bus, NULL, read_only, cmd, arg); rc = __nd_ioctl(nvdimm_bus, NULL, ro, cmd, arg);
break; break;
} }
} }
...@@ -633,10 +732,10 @@ static int match_dimm(struct device *dev, void *data) ...@@ -633,10 +732,10 @@ static int match_dimm(struct device *dev, void *data)
static long nvdimm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) static long nvdimm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ {
int rc = -ENXIO, read_only; int rc = -ENXIO, ro;
struct nvdimm_bus *nvdimm_bus; struct nvdimm_bus *nvdimm_bus;
read_only = (O_RDWR != (file->f_flags & O_ACCMODE)); ro = ((file->f_flags & O_ACCMODE) == O_RDONLY);
mutex_lock(&nvdimm_bus_list_mutex); mutex_lock(&nvdimm_bus_list_mutex);
list_for_each_entry(nvdimm_bus, &nvdimm_bus_list, list) { list_for_each_entry(nvdimm_bus, &nvdimm_bus_list, list) {
struct device *dev = device_find_child(&nvdimm_bus->dev, struct device *dev = device_find_child(&nvdimm_bus->dev,
...@@ -647,7 +746,7 @@ static long nvdimm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -647,7 +746,7 @@ static long nvdimm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
continue; continue;
nvdimm = to_nvdimm(dev); nvdimm = to_nvdimm(dev);
rc = __nd_ioctl(nvdimm_bus, nvdimm, read_only, cmd, arg); rc = __nd_ioctl(nvdimm_bus, nvdimm, ro, cmd, arg);
put_device(dev); put_device(dev);
break; break;
} }
......
...@@ -298,6 +298,15 @@ static int flush_regions_dimms(struct device *dev, void *data) ...@@ -298,6 +298,15 @@ static int flush_regions_dimms(struct device *dev, void *data)
static ssize_t wait_probe_show(struct device *dev, static ssize_t wait_probe_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev);
struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc;
int rc;
if (nd_desc->flush_probe) {
rc = nd_desc->flush_probe(nd_desc);
if (rc)
return rc;
}
nd_synchronize(); nd_synchronize();
device_for_each_child(dev, NULL, flush_regions_dimms); device_for_each_child(dev, NULL, flush_regions_dimms);
return sprintf(buf, "1\n"); return sprintf(buf, "1\n");
...@@ -408,33 +417,11 @@ static void __add_badblock_range(struct badblocks *bb, u64 ns_offset, u64 len) ...@@ -408,33 +417,11 @@ static void __add_badblock_range(struct badblocks *bb, u64 ns_offset, u64 len)
set_badblock(bb, start_sector, num_sectors); set_badblock(bb, start_sector, num_sectors);
} }
/** static void namespace_add_poison(struct list_head *poison_list,
* nvdimm_namespace_add_poison() - Convert a list of poison ranges to badblocks struct badblocks *bb, struct resource *res)
* @ndns: the namespace containing poison ranges
* @bb: badblocks instance to populate
* @offset: offset at the start of the namespace before 'sector 0'
*
* The poison list generated during NFIT initialization may contain multiple,
* possibly overlapping ranges in the SPA (System Physical Address) space.
* Compare each of these ranges to the namespace currently being initialized,
* and add badblocks to the gendisk for all matching sub-ranges
*/
void nvdimm_namespace_add_poison(struct nd_namespace_common *ndns,
struct badblocks *bb, resource_size_t offset)
{ {
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
struct nd_region *nd_region = to_nd_region(ndns->dev.parent);
struct nvdimm_bus *nvdimm_bus;
struct list_head *poison_list;
u64 ns_start, ns_end, ns_size;
struct nd_poison *pl; struct nd_poison *pl;
ns_size = nvdimm_namespace_capacity(ndns) - offset;
ns_start = nsio->res.start + offset;
ns_end = nsio->res.end;
nvdimm_bus = to_nvdimm_bus(nd_region->dev.parent);
poison_list = &nvdimm_bus->poison_list;
if (list_empty(poison_list)) if (list_empty(poison_list))
return; return;
...@@ -442,37 +429,69 @@ void nvdimm_namespace_add_poison(struct nd_namespace_common *ndns, ...@@ -442,37 +429,69 @@ void nvdimm_namespace_add_poison(struct nd_namespace_common *ndns,
u64 pl_end = pl->start + pl->length - 1; u64 pl_end = pl->start + pl->length - 1;
/* Discard intervals with no intersection */ /* Discard intervals with no intersection */
if (pl_end < ns_start) if (pl_end < res->start)
continue; continue;
if (pl->start > ns_end) if (pl->start > res->end)
continue; continue;
/* Deal with any overlap after start of the namespace */ /* Deal with any overlap after start of the namespace */
if (pl->start >= ns_start) { if (pl->start >= res->start) {
u64 start = pl->start; u64 start = pl->start;
u64 len; u64 len;
if (pl_end <= ns_end) if (pl_end <= res->end)
len = pl->length; len = pl->length;
else else
len = ns_start + ns_size - pl->start; len = res->start + resource_size(res)
__add_badblock_range(bb, start - ns_start, len); - pl->start;
__add_badblock_range(bb, start - res->start, len);
continue; continue;
} }
/* Deal with overlap for poison starting before the namespace */ /* Deal with overlap for poison starting before the namespace */
if (pl->start < ns_start) { if (pl->start < res->start) {
u64 len; u64 len;
if (pl_end < ns_end) if (pl_end < res->end)
len = pl->start + pl->length - ns_start; len = pl->start + pl->length - res->start;
else else
len = ns_size; len = resource_size(res);
__add_badblock_range(bb, 0, len); __add_badblock_range(bb, 0, len);
} }
} }
} }
/**
* nvdimm_namespace_add_poison() - Convert a list of poison ranges to badblocks
* @ndns: the namespace containing poison ranges
* @bb: badblocks instance to populate
* @offset: offset at the start of the namespace before 'sector 0'
*
* The poison list generated during NFIT initialization may contain multiple,
* possibly overlapping ranges in the SPA (System Physical Address) space.
* Compare each of these ranges to the namespace currently being initialized,
* and add badblocks to the gendisk for all matching sub-ranges
*/
void nvdimm_namespace_add_poison(struct nd_namespace_common *ndns,
struct badblocks *bb, resource_size_t offset)
{
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
struct nd_region *nd_region = to_nd_region(ndns->dev.parent);
struct nvdimm_bus *nvdimm_bus;
struct list_head *poison_list;
struct resource res = {
.start = nsio->res.start + offset,
.end = nsio->res.end,
};
nvdimm_bus = to_nvdimm_bus(nd_region->dev.parent);
poison_list = &nvdimm_bus->poison_list;
nvdimm_bus_lock(&nvdimm_bus->dev);
namespace_add_poison(poison_list, bb, &res);
nvdimm_bus_unlock(&nvdimm_bus->dev);
}
EXPORT_SYMBOL_GPL(nvdimm_namespace_add_poison); EXPORT_SYMBOL_GPL(nvdimm_namespace_add_poison);
static int __add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length) static int add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length)
{ {
struct nd_poison *pl; struct nd_poison *pl;
...@@ -487,12 +506,12 @@ static int __add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length) ...@@ -487,12 +506,12 @@ static int __add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length)
return 0; return 0;
} }
int nvdimm_bus_add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length) static int bus_add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length)
{ {
struct nd_poison *pl; struct nd_poison *pl;
if (list_empty(&nvdimm_bus->poison_list)) if (list_empty(&nvdimm_bus->poison_list))
return __add_poison(nvdimm_bus, addr, length); return add_poison(nvdimm_bus, addr, length);
/* /*
* There is a chance this is a duplicate, check for those first. * There is a chance this is a duplicate, check for those first.
...@@ -512,7 +531,18 @@ int nvdimm_bus_add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length) ...@@ -512,7 +531,18 @@ int nvdimm_bus_add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length)
* as any overlapping ranges will get resolved when the list is consumed * as any overlapping ranges will get resolved when the list is consumed
* and converted to badblocks * and converted to badblocks
*/ */
return __add_poison(nvdimm_bus, addr, length); return add_poison(nvdimm_bus, addr, length);
}
int nvdimm_bus_add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length)
{
int rc;
nvdimm_bus_lock(&nvdimm_bus->dev);
rc = bus_add_poison(nvdimm_bus, addr, length);
nvdimm_bus_unlock(&nvdimm_bus->dev);
return rc;
} }
EXPORT_SYMBOL_GPL(nvdimm_bus_add_poison); EXPORT_SYMBOL_GPL(nvdimm_bus_add_poison);
...@@ -553,7 +583,11 @@ void nvdimm_bus_unregister(struct nvdimm_bus *nvdimm_bus) ...@@ -553,7 +583,11 @@ void nvdimm_bus_unregister(struct nvdimm_bus *nvdimm_bus)
nd_synchronize(); nd_synchronize();
device_for_each_child(&nvdimm_bus->dev, NULL, child_unregister); device_for_each_child(&nvdimm_bus->dev, NULL, child_unregister);
nvdimm_bus_lock(&nvdimm_bus->dev);
free_poison_list(&nvdimm_bus->poison_list); free_poison_list(&nvdimm_bus->poison_list);
nvdimm_bus_unlock(&nvdimm_bus->dev);
nvdimm_bus_destroy_ndctl(nvdimm_bus); nvdimm_bus_destroy_ndctl(nvdimm_bus);
device_unregister(&nvdimm_bus->dev); device_unregister(&nvdimm_bus->dev);
......
...@@ -75,7 +75,7 @@ int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd) ...@@ -75,7 +75,7 @@ int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd)
memset(cmd, 0, sizeof(*cmd)); memset(cmd, 0, sizeof(*cmd));
nd_desc = nvdimm_bus->nd_desc; nd_desc = nvdimm_bus->nd_desc;
return nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev), return nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev),
ND_CMD_GET_CONFIG_SIZE, cmd, sizeof(*cmd)); ND_CMD_GET_CONFIG_SIZE, cmd, sizeof(*cmd), NULL);
} }
int nvdimm_init_config_data(struct nvdimm_drvdata *ndd) int nvdimm_init_config_data(struct nvdimm_drvdata *ndd)
...@@ -120,7 +120,7 @@ int nvdimm_init_config_data(struct nvdimm_drvdata *ndd) ...@@ -120,7 +120,7 @@ int nvdimm_init_config_data(struct nvdimm_drvdata *ndd)
cmd->in_offset = offset; cmd->in_offset = offset;
rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev), rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev),
ND_CMD_GET_CONFIG_DATA, cmd, ND_CMD_GET_CONFIG_DATA, cmd,
cmd->in_length + sizeof(*cmd)); cmd->in_length + sizeof(*cmd), NULL);
if (rc || cmd->status) { if (rc || cmd->status) {
rc = -ENXIO; rc = -ENXIO;
break; break;
...@@ -171,7 +171,7 @@ int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset, ...@@ -171,7 +171,7 @@ int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset,
status = ((void *) cmd) + cmd_size - sizeof(u32); status = ((void *) cmd) + cmd_size - sizeof(u32);
rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev), rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev),
ND_CMD_SET_CONFIG_DATA, cmd, cmd_size); ND_CMD_SET_CONFIG_DATA, cmd, cmd_size, NULL);
if (rc || *status) { if (rc || *status) {
rc = rc ? rc : -ENXIO; rc = rc ? rc : -ENXIO;
break; break;
......
...@@ -133,6 +133,7 @@ bool nd_is_uuid_unique(struct device *dev, u8 *uuid) ...@@ -133,6 +133,7 @@ bool nd_is_uuid_unique(struct device *dev, u8 *uuid)
bool pmem_should_map_pages(struct device *dev) bool pmem_should_map_pages(struct device *dev)
{ {
struct nd_region *nd_region = to_nd_region(dev->parent); struct nd_region *nd_region = to_nd_region(dev->parent);
struct nd_namespace_io *nsio;
if (!IS_ENABLED(CONFIG_ZONE_DEVICE)) if (!IS_ENABLED(CONFIG_ZONE_DEVICE))
return false; return false;
...@@ -143,6 +144,12 @@ bool pmem_should_map_pages(struct device *dev) ...@@ -143,6 +144,12 @@ bool pmem_should_map_pages(struct device *dev)
if (is_nd_pfn(dev) || is_nd_btt(dev)) if (is_nd_pfn(dev) || is_nd_btt(dev))
return false; return false;
nsio = to_nd_namespace_io(dev);
if (region_intersects(nsio->res.start, resource_size(&nsio->res),
IORESOURCE_SYSTEM_RAM,
IORES_DESC_NONE) == REGION_MIXED)
return false;
#ifdef ARCH_MEMREMAP_PMEM #ifdef ARCH_MEMREMAP_PMEM
return ARCH_MEMREMAP_PMEM == MEMREMAP_WB; return ARCH_MEMREMAP_PMEM == MEMREMAP_WB;
#else #else
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/ndctl.h> #include <linux/ndctl.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/nd.h>
#include "label.h" #include "label.h"
enum { enum {
...@@ -168,6 +169,7 @@ int nd_integrity_init(struct gendisk *disk, unsigned long meta_size); ...@@ -168,6 +169,7 @@ int nd_integrity_init(struct gendisk *disk, unsigned long meta_size);
void wait_nvdimm_bus_probe_idle(struct device *dev); void wait_nvdimm_bus_probe_idle(struct device *dev);
void nd_device_register(struct device *dev); void nd_device_register(struct device *dev);
void nd_device_unregister(struct device *dev, enum nd_async_mode mode); void nd_device_unregister(struct device *dev, enum nd_async_mode mode);
void nd_device_notify(struct device *dev, enum nvdimm_event event);
int nd_uuid_store(struct device *dev, u8 **uuid_out, const char *buf, int nd_uuid_store(struct device *dev, u8 **uuid_out, const char *buf,
size_t len); size_t len);
ssize_t nd_sector_size_show(unsigned long current_lbasize, ssize_t nd_sector_size_show(unsigned long current_lbasize,
...@@ -184,6 +186,8 @@ int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd); ...@@ -184,6 +186,8 @@ int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd);
int nvdimm_init_config_data(struct nvdimm_drvdata *ndd); int nvdimm_init_config_data(struct nvdimm_drvdata *ndd);
int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset, int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset,
void *buf, size_t len); void *buf, size_t len);
long nvdimm_clear_poison(struct device *dev, phys_addr_t phys,
unsigned int len);
struct nd_btt *to_nd_btt(struct device *dev); struct nd_btt *to_nd_btt(struct device *dev);
struct nd_gen_sb { struct nd_gen_sb {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#define __NVDIMM_PFN_H #define __NVDIMM_PFN_H
#include <linux/types.h> #include <linux/types.h>
#include <linux/mmzone.h>
#define PFN_SIG_LEN 16 #define PFN_SIG_LEN 16
#define PFN_SIG "NVDIMM_PFN_INFO\0" #define PFN_SIG "NVDIMM_PFN_INFO\0"
...@@ -26,10 +27,28 @@ struct nd_pfn_sb { ...@@ -26,10 +27,28 @@ struct nd_pfn_sb {
__le32 flags; __le32 flags;
__le16 version_major; __le16 version_major;
__le16 version_minor; __le16 version_minor;
__le64 dataoff; __le64 dataoff; /* relative to namespace_base + start_pad */
__le64 npfns; __le64 npfns;
__le32 mode; __le32 mode;
u8 padding[4012]; /* minor-version-1 additions for section alignment */
__le32 start_pad;
__le32 end_trunc;
u8 padding[4004];
__le64 checksum; __le64 checksum;
}; };
#ifdef CONFIG_SPARSEMEM
#define PFN_SECTION_ALIGN_DOWN(x) SECTION_ALIGN_DOWN(x)
#define PFN_SECTION_ALIGN_UP(x) SECTION_ALIGN_UP(x)
#else
/*
* In this case ZONE_DEVICE=n and we will disable 'pfn' device support,
* but we still want pmem to compile.
*/
#define PFN_SECTION_ALIGN_DOWN(x) (x)
#define PFN_SECTION_ALIGN_UP(x) (x)
#endif
#define PHYS_SECTION_ALIGN_DOWN(x) PFN_PHYS(PFN_SECTION_ALIGN_DOWN(PHYS_PFN(x)))
#define PHYS_SECTION_ALIGN_UP(x) PFN_PHYS(PFN_SECTION_ALIGN_UP(PHYS_PFN(x)))
#endif /* __NVDIMM_PFN_H */ #endif /* __NVDIMM_PFN_H */
...@@ -205,11 +205,67 @@ static ssize_t namespace_store(struct device *dev, ...@@ -205,11 +205,67 @@ static ssize_t namespace_store(struct device *dev,
} }
static DEVICE_ATTR_RW(namespace); static DEVICE_ATTR_RW(namespace);
static ssize_t resource_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct nd_pfn *nd_pfn = to_nd_pfn(dev);
ssize_t rc;
device_lock(dev);
if (dev->driver) {
struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
u64 offset = __le64_to_cpu(pfn_sb->dataoff);
struct nd_namespace_common *ndns = nd_pfn->ndns;
u32 start_pad = __le32_to_cpu(pfn_sb->start_pad);
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
rc = sprintf(buf, "%#llx\n", (unsigned long long) nsio->res.start
+ start_pad + offset);
} else {
/* no address to convey if the pfn instance is disabled */
rc = -ENXIO;
}
device_unlock(dev);
return rc;
}
static DEVICE_ATTR_RO(resource);
static ssize_t size_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct nd_pfn *nd_pfn = to_nd_pfn(dev);
ssize_t rc;
device_lock(dev);
if (dev->driver) {
struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
u64 offset = __le64_to_cpu(pfn_sb->dataoff);
struct nd_namespace_common *ndns = nd_pfn->ndns;
u32 start_pad = __le32_to_cpu(pfn_sb->start_pad);
u32 end_trunc = __le32_to_cpu(pfn_sb->end_trunc);
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
rc = sprintf(buf, "%llu\n", (unsigned long long)
resource_size(&nsio->res) - start_pad
- end_trunc - offset);
} else {
/* no size to convey if the pfn instance is disabled */
rc = -ENXIO;
}
device_unlock(dev);
return rc;
}
static DEVICE_ATTR_RO(size);
static struct attribute *nd_pfn_attributes[] = { static struct attribute *nd_pfn_attributes[] = {
&dev_attr_mode.attr, &dev_attr_mode.attr,
&dev_attr_namespace.attr, &dev_attr_namespace.attr,
&dev_attr_uuid.attr, &dev_attr_uuid.attr,
&dev_attr_align.attr, &dev_attr_align.attr,
&dev_attr_resource.attr,
&dev_attr_size.attr,
NULL, NULL,
}; };
...@@ -299,6 +355,11 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn) ...@@ -299,6 +355,11 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn)
if (memcmp(pfn_sb->parent_uuid, parent_uuid, 16) != 0) if (memcmp(pfn_sb->parent_uuid, parent_uuid, 16) != 0)
return -ENODEV; return -ENODEV;
if (__le16_to_cpu(pfn_sb->version_minor) < 1) {
pfn_sb->start_pad = 0;
pfn_sb->end_trunc = 0;
}
switch (le32_to_cpu(pfn_sb->mode)) { switch (le32_to_cpu(pfn_sb->mode)) {
case PFN_MODE_RAM: case PFN_MODE_RAM:
case PFN_MODE_PMEM: case PFN_MODE_PMEM:
......
This diff is collapsed.
...@@ -93,9 +93,21 @@ static int nd_region_remove(struct device *dev) ...@@ -93,9 +93,21 @@ static int nd_region_remove(struct device *dev)
return 0; return 0;
} }
static int child_notify(struct device *dev, void *data)
{
nd_device_notify(dev, *(enum nvdimm_event *) data);
return 0;
}
static void nd_region_notify(struct device *dev, enum nvdimm_event event)
{
device_for_each_child(dev, &event, child_notify);
}
static struct nd_device_driver nd_region_driver = { static struct nd_device_driver nd_region_driver = {
.probe = nd_region_probe, .probe = nd_region_probe,
.remove = nd_region_remove, .remove = nd_region_remove,
.notify = nd_region_notify,
.drv = { .drv = {
.name = "nd_region", .name = "nd_region",
}, },
......
...@@ -172,6 +172,7 @@ extern void reserve_region_with_split(struct resource *root, ...@@ -172,6 +172,7 @@ extern void reserve_region_with_split(struct resource *root,
extern struct resource *insert_resource_conflict(struct resource *parent, struct resource *new); extern struct resource *insert_resource_conflict(struct resource *parent, struct resource *new);
extern int insert_resource(struct resource *parent, struct resource *new); extern int insert_resource(struct resource *parent, struct resource *new);
extern void insert_resource_expand_to_fit(struct resource *root, struct resource *new); extern void insert_resource_expand_to_fit(struct resource *root, struct resource *new);
extern int remove_resource(struct resource *old);
extern void arch_remove_reservations(struct resource *avail); extern void arch_remove_reservations(struct resource *avail);
extern int allocate_resource(struct resource *root, struct resource *new, extern int allocate_resource(struct resource *root, struct resource *new,
resource_size_t size, resource_size_t min, resource_size_t size, resource_size_t min,
......
...@@ -48,7 +48,7 @@ struct nvdimm; ...@@ -48,7 +48,7 @@ struct nvdimm;
struct nvdimm_bus_descriptor; struct nvdimm_bus_descriptor;
typedef int (*ndctl_fn)(struct nvdimm_bus_descriptor *nd_desc, typedef int (*ndctl_fn)(struct nvdimm_bus_descriptor *nd_desc,
struct nvdimm *nvdimm, unsigned int cmd, void *buf, struct nvdimm *nvdimm, unsigned int cmd, void *buf,
unsigned int buf_len); unsigned int buf_len, int *cmd_rc);
struct nd_namespace_label; struct nd_namespace_label;
struct nvdimm_drvdata; struct nvdimm_drvdata;
...@@ -71,6 +71,9 @@ struct nvdimm_bus_descriptor { ...@@ -71,6 +71,9 @@ struct nvdimm_bus_descriptor {
unsigned long dsm_mask; unsigned long dsm_mask;
char *provider_name; char *provider_name;
ndctl_fn ndctl; ndctl_fn ndctl;
int (*flush_probe)(struct nvdimm_bus_descriptor *nd_desc);
int (*clear_to_send)(struct nvdimm_bus_descriptor *nd_desc,
struct nvdimm *nvdimm, unsigned int cmd);
}; };
struct nd_cmd_desc { struct nd_cmd_desc {
......
...@@ -16,11 +16,16 @@ ...@@ -16,11 +16,16 @@
#include <linux/ndctl.h> #include <linux/ndctl.h>
#include <linux/device.h> #include <linux/device.h>
enum nvdimm_event {
NVDIMM_REVALIDATE_POISON,
};
struct nd_device_driver { struct nd_device_driver {
struct device_driver drv; struct device_driver drv;
unsigned long type; unsigned long type;
int (*probe)(struct device *dev); int (*probe)(struct device *dev);
int (*remove)(struct device *dev); int (*remove)(struct device *dev);
void (*notify)(struct device *dev, enum nvdimm_event event);
}; };
static inline struct nd_device_driver *to_nd_device_driver( static inline struct nd_device_driver *to_nd_device_driver(
...@@ -144,6 +149,8 @@ static inline int nvdimm_write_bytes(struct nd_namespace_common *ndns, ...@@ -144,6 +149,8 @@ static inline int nvdimm_write_bytes(struct nd_namespace_common *ndns,
MODULE_ALIAS("nd:t" __stringify(type) "*") MODULE_ALIAS("nd:t" __stringify(type) "*")
#define ND_DEVICE_MODALIAS_FMT "nd:t%d" #define ND_DEVICE_MODALIAS_FMT "nd:t%d"
struct nd_region;
void nvdimm_region_notify(struct nd_region *nd_region, enum nvdimm_event event);
int __must_check __nd_driver_register(struct nd_device_driver *nd_drv, int __must_check __nd_driver_register(struct nd_device_driver *nd_drv,
struct module *module, const char *mod_name); struct module *module, const char *mod_name);
#define nd_driver_register(driver) \ #define nd_driver_register(driver) \
......
...@@ -58,6 +58,11 @@ static inline void arch_wb_cache_pmem(void __pmem *addr, size_t size) ...@@ -58,6 +58,11 @@ static inline void arch_wb_cache_pmem(void __pmem *addr, size_t size)
{ {
BUG(); BUG();
} }
static inline void arch_invalidate_pmem(void __pmem *addr, size_t size)
{
BUG();
}
#endif #endif
/* /*
...@@ -185,6 +190,20 @@ static inline void clear_pmem(void __pmem *addr, size_t size) ...@@ -185,6 +190,20 @@ static inline void clear_pmem(void __pmem *addr, size_t size)
default_clear_pmem(addr, size); default_clear_pmem(addr, size);
} }
/**
* invalidate_pmem - flush a pmem range from the cache hierarchy
* @addr: virtual start address
* @size: bytes to invalidate (internally aligned to cache line size)
*
* For platforms that support clearing poison this flushes any poisoned
* ranges out of the cache
*/
static inline void invalidate_pmem(void __pmem *addr, size_t size)
{
if (arch_has_pmem_api())
arch_invalidate_pmem(addr, size);
}
/** /**
* wb_cache_pmem - write back processor cache for PMEM memory range * wb_cache_pmem - write back processor cache for PMEM memory range
* @addr: virtual start address * @addr: virtual start address
......
...@@ -98,6 +98,14 @@ struct nd_cmd_ars_status { ...@@ -98,6 +98,14 @@ struct nd_cmd_ars_status {
} __packed records[0]; } __packed records[0];
} __packed; } __packed;
struct nd_cmd_clear_error {
__u64 address;
__u64 length;
__u32 status;
__u8 reserved[4];
__u64 cleared;
} __packed;
enum { enum {
ND_CMD_IMPLEMENTED = 0, ND_CMD_IMPLEMENTED = 0,
...@@ -105,6 +113,7 @@ enum { ...@@ -105,6 +113,7 @@ enum {
ND_CMD_ARS_CAP = 1, ND_CMD_ARS_CAP = 1,
ND_CMD_ARS_START = 2, ND_CMD_ARS_START = 2,
ND_CMD_ARS_STATUS = 3, ND_CMD_ARS_STATUS = 3,
ND_CMD_CLEAR_ERROR = 4,
/* per-dimm commands */ /* per-dimm commands */
ND_CMD_SMART = 1, ND_CMD_SMART = 1,
...@@ -129,6 +138,7 @@ static inline const char *nvdimm_bus_cmd_name(unsigned cmd) ...@@ -129,6 +138,7 @@ static inline const char *nvdimm_bus_cmd_name(unsigned cmd)
[ND_CMD_ARS_CAP] = "ars_cap", [ND_CMD_ARS_CAP] = "ars_cap",
[ND_CMD_ARS_START] = "ars_start", [ND_CMD_ARS_START] = "ars_start",
[ND_CMD_ARS_STATUS] = "ars_status", [ND_CMD_ARS_STATUS] = "ars_status",
[ND_CMD_CLEAR_ERROR] = "clear_error",
}; };
if (cmd < ARRAY_SIZE(names) && names[cmd]) if (cmd < ARRAY_SIZE(names) && names[cmd])
...@@ -187,6 +197,9 @@ static inline const char *nvdimm_cmd_name(unsigned cmd) ...@@ -187,6 +197,9 @@ static inline const char *nvdimm_cmd_name(unsigned cmd)
#define ND_IOCTL_ARS_STATUS _IOWR(ND_IOCTL, ND_CMD_ARS_STATUS,\ #define ND_IOCTL_ARS_STATUS _IOWR(ND_IOCTL, ND_CMD_ARS_STATUS,\
struct nd_cmd_ars_status) struct nd_cmd_ars_status)
#define ND_IOCTL_CLEAR_ERROR _IOWR(ND_IOCTL, ND_CMD_CLEAR_ERROR,\
struct nd_cmd_clear_error)
#define ND_DEVICE_DIMM 1 /* nd_dimm: container for "config data" */ #define ND_DEVICE_DIMM 1 /* nd_dimm: container for "config data" */
#define ND_DEVICE_REGION_PMEM 2 /* nd_region: (parent of PMEM namespaces) */ #define ND_DEVICE_REGION_PMEM 2 /* nd_region: (parent of PMEM namespaces) */
#define ND_DEVICE_REGION_BLK 3 /* nd_region: (parent of BLK namespaces) */ #define ND_DEVICE_REGION_BLK 3 /* nd_region: (parent of BLK namespaces) */
......
...@@ -233,9 +233,9 @@ static struct resource * __request_resource(struct resource *root, struct resour ...@@ -233,9 +233,9 @@ static struct resource * __request_resource(struct resource *root, struct resour
} }
} }
static int __release_resource(struct resource *old) static int __release_resource(struct resource *old, bool release_child)
{ {
struct resource *tmp, **p; struct resource *tmp, **p, *chd;
p = &old->parent->child; p = &old->parent->child;
for (;;) { for (;;) {
...@@ -243,7 +243,17 @@ static int __release_resource(struct resource *old) ...@@ -243,7 +243,17 @@ static int __release_resource(struct resource *old)
if (!tmp) if (!tmp)
break; break;
if (tmp == old) { if (tmp == old) {
*p = tmp->sibling; if (release_child || !(tmp->child)) {
*p = tmp->sibling;
} else {
for (chd = tmp->child;; chd = chd->sibling) {
chd->parent = tmp->parent;
if (!(chd->sibling))
break;
}
*p = tmp->child;
chd->sibling = tmp->sibling;
}
old->parent = NULL; old->parent = NULL;
return 0; return 0;
} }
...@@ -325,7 +335,7 @@ int release_resource(struct resource *old) ...@@ -325,7 +335,7 @@ int release_resource(struct resource *old)
int retval; int retval;
write_lock(&resource_lock); write_lock(&resource_lock);
retval = __release_resource(old); retval = __release_resource(old, true);
write_unlock(&resource_lock); write_unlock(&resource_lock);
return retval; return retval;
} }
...@@ -679,7 +689,7 @@ static int reallocate_resource(struct resource *root, struct resource *old, ...@@ -679,7 +689,7 @@ static int reallocate_resource(struct resource *root, struct resource *old,
old->start = new.start; old->start = new.start;
old->end = new.end; old->end = new.end;
} else { } else {
__release_resource(old); __release_resource(old, true);
*old = new; *old = new;
conflict = __request_resource(root, old); conflict = __request_resource(root, old);
BUG_ON(conflict); BUG_ON(conflict);
...@@ -825,6 +835,9 @@ static struct resource * __insert_resource(struct resource *parent, struct resou ...@@ -825,6 +835,9 @@ static struct resource * __insert_resource(struct resource *parent, struct resou
* entirely fit within the range of the new resource, then the new * entirely fit within the range of the new resource, then the new
* resource is inserted and the conflicting resources become children of * resource is inserted and the conflicting resources become children of
* the new resource. * the new resource.
*
* This function is intended for producers of resources, such as FW modules
* and bus drivers.
*/ */
struct resource *insert_resource_conflict(struct resource *parent, struct resource *new) struct resource *insert_resource_conflict(struct resource *parent, struct resource *new)
{ {
...@@ -842,6 +855,9 @@ struct resource *insert_resource_conflict(struct resource *parent, struct resour ...@@ -842,6 +855,9 @@ struct resource *insert_resource_conflict(struct resource *parent, struct resour
* @new: new resource to insert * @new: new resource to insert
* *
* Returns 0 on success, -EBUSY if the resource can't be inserted. * Returns 0 on success, -EBUSY if the resource can't be inserted.
*
* This function is intended for producers of resources, such as FW modules
* and bus drivers.
*/ */
int insert_resource(struct resource *parent, struct resource *new) int insert_resource(struct resource *parent, struct resource *new)
{ {
...@@ -850,6 +866,7 @@ int insert_resource(struct resource *parent, struct resource *new) ...@@ -850,6 +866,7 @@ int insert_resource(struct resource *parent, struct resource *new)
conflict = insert_resource_conflict(parent, new); conflict = insert_resource_conflict(parent, new);
return conflict ? -EBUSY : 0; return conflict ? -EBUSY : 0;
} }
EXPORT_SYMBOL_GPL(insert_resource);
/** /**
* insert_resource_expand_to_fit - Insert a resource into the resource tree * insert_resource_expand_to_fit - Insert a resource into the resource tree
...@@ -885,6 +902,32 @@ void insert_resource_expand_to_fit(struct resource *root, struct resource *new) ...@@ -885,6 +902,32 @@ void insert_resource_expand_to_fit(struct resource *root, struct resource *new)
write_unlock(&resource_lock); write_unlock(&resource_lock);
} }
/**
* remove_resource - Remove a resource in the resource tree
* @old: resource to remove
*
* Returns 0 on success, -EINVAL if the resource is not valid.
*
* This function removes a resource previously inserted by insert_resource()
* or insert_resource_conflict(), and moves the children (if any) up to
* where they were before. insert_resource() and insert_resource_conflict()
* insert a new resource, and move any conflicting resources down to the
* children of the new resource.
*
* insert_resource(), insert_resource_conflict() and remove_resource() are
* intended for producers of resources, such as FW modules and bus drivers.
*/
int remove_resource(struct resource *old)
{
int retval;
write_lock(&resource_lock);
retval = __release_resource(old, false);
write_unlock(&resource_lock);
return retval;
}
EXPORT_SYMBOL_GPL(remove_resource);
static int __adjust_resource(struct resource *res, resource_size_t start, static int __adjust_resource(struct resource *res, resource_size_t start,
resource_size_t size) resource_size_t size)
{ {
...@@ -1085,15 +1128,16 @@ struct resource * __request_region(struct resource *parent, ...@@ -1085,15 +1128,16 @@ struct resource * __request_region(struct resource *parent,
res->name = name; res->name = name;
res->start = start; res->start = start;
res->end = start + n - 1; res->end = start + n - 1;
res->flags = resource_type(parent) | resource_ext_type(parent);
res->flags |= IORESOURCE_BUSY | flags;
res->desc = IORES_DESC_NONE;
write_lock(&resource_lock); write_lock(&resource_lock);
for (;;) { for (;;) {
struct resource *conflict; struct resource *conflict;
res->flags = resource_type(parent) | resource_ext_type(parent);
res->flags |= IORESOURCE_BUSY | flags;
res->desc = parent->desc;
conflict = __request_resource(parent, res); conflict = __request_resource(parent, res);
if (!conflict) if (!conflict)
break; break;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment