memremap: change devm_memremap_pages interface to use struct dev_pagemap
This new interface is similar to how struct device (and many others) work. The caller initializes a 'struct dev_pagemap' as required and calls 'devm_memremap_pages'. This allows the pagemap structure to be embedded in another structure and thus container_of can be used. In this way application specific members can be stored in a containing struct. This will be used by the P2P infrastructure and HMM could probably be cleaned up to use it as well (instead of having it's own, similar 'hmm_devmem_pages_create' function). Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
This commit is contained in:

committed by
Dan Williams

parent
e7744aa25c
commit
e8d5134833
@@ -298,34 +298,34 @@ static int pmem_attach_disk(struct device *dev,
|
||||
{
|
||||
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
|
||||
struct nd_region *nd_region = to_nd_region(dev->parent);
|
||||
struct vmem_altmap __altmap, *altmap = NULL;
|
||||
int nid = dev_to_node(dev), fua, wbc;
|
||||
struct resource *res = &nsio->res;
|
||||
struct resource bb_res;
|
||||
struct nd_pfn *nd_pfn = NULL;
|
||||
struct dax_device *dax_dev;
|
||||
struct nd_pfn_sb *pfn_sb;
|
||||
struct pmem_device *pmem;
|
||||
struct resource pfn_res;
|
||||
struct request_queue *q;
|
||||
struct device *gendev;
|
||||
struct gendisk *disk;
|
||||
void *addr;
|
||||
|
||||
/* while nsio_rw_bytes is active, parse a pfn info block if present */
|
||||
if (is_nd_pfn(dev)) {
|
||||
nd_pfn = to_nd_pfn(dev);
|
||||
altmap = nvdimm_setup_pfn(nd_pfn, &pfn_res, &__altmap);
|
||||
if (IS_ERR(altmap))
|
||||
return PTR_ERR(altmap);
|
||||
}
|
||||
|
||||
/* we're attaching a block device, disable raw namespace access */
|
||||
devm_nsio_disable(dev, nsio);
|
||||
int rc;
|
||||
|
||||
pmem = devm_kzalloc(dev, sizeof(*pmem), GFP_KERNEL);
|
||||
if (!pmem)
|
||||
return -ENOMEM;
|
||||
|
||||
/* while nsio_rw_bytes is active, parse a pfn info block if present */
|
||||
if (is_nd_pfn(dev)) {
|
||||
nd_pfn = to_nd_pfn(dev);
|
||||
rc = nvdimm_setup_pfn(nd_pfn, &pmem->pgmap);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* we're attaching a block device, disable raw namespace access */
|
||||
devm_nsio_disable(dev, nsio);
|
||||
|
||||
dev_set_drvdata(dev, pmem);
|
||||
pmem->phys_addr = res->start;
|
||||
pmem->size = resource_size(res);
|
||||
@@ -350,19 +350,22 @@ static int pmem_attach_disk(struct device *dev,
|
||||
return -ENOMEM;
|
||||
|
||||
pmem->pfn_flags = PFN_DEV;
|
||||
pmem->pgmap.ref = &q->q_usage_counter;
|
||||
if (is_nd_pfn(dev)) {
|
||||
addr = devm_memremap_pages(dev, &pfn_res, &q->q_usage_counter,
|
||||
altmap);
|
||||
addr = devm_memremap_pages(dev, &pmem->pgmap);
|
||||
pfn_sb = nd_pfn->pfn_sb;
|
||||
pmem->data_offset = le64_to_cpu(pfn_sb->dataoff);
|
||||
pmem->pfn_pad = resource_size(res) - resource_size(&pfn_res);
|
||||
pmem->pfn_pad = resource_size(res) -
|
||||
resource_size(&pmem->pgmap.res);
|
||||
pmem->pfn_flags |= PFN_MAP;
|
||||
res = &pfn_res; /* for badblocks populate */
|
||||
res->start += pmem->data_offset;
|
||||
memcpy(&bb_res, &pmem->pgmap.res, sizeof(bb_res));
|
||||
bb_res.start += pmem->data_offset;
|
||||
} else if (pmem_should_map_pages(dev)) {
|
||||
addr = devm_memremap_pages(dev, &nsio->res,
|
||||
&q->q_usage_counter, NULL);
|
||||
memcpy(&pmem->pgmap.res, &nsio->res, sizeof(pmem->pgmap.res));
|
||||
pmem->pgmap.altmap_valid = false;
|
||||
addr = devm_memremap_pages(dev, &pmem->pgmap);
|
||||
pmem->pfn_flags |= PFN_MAP;
|
||||
memcpy(&bb_res, &pmem->pgmap.res, sizeof(bb_res));
|
||||
} else
|
||||
addr = devm_memremap(dev, pmem->phys_addr,
|
||||
pmem->size, ARCH_MEMREMAP_PMEM);
|
||||
@@ -401,7 +404,7 @@ static int pmem_attach_disk(struct device *dev,
|
||||
/ 512);
|
||||
if (devm_init_badblocks(dev, &pmem->bb))
|
||||
return -ENOMEM;
|
||||
nvdimm_badblocks_populate(nd_region, &pmem->bb, res);
|
||||
nvdimm_badblocks_populate(nd_region, &pmem->bb, &bb_res);
|
||||
disk->bb = &pmem->bb;
|
||||
|
||||
dax_dev = alloc_dax(pmem, disk->disk_name, &pmem_dax_ops);
|
||||
|
Reference in New Issue
Block a user