1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2016 - 2018 Intel Corporation. All rights reserved. */
3 #include <linux/memremap.h>
4 #include <linux/module.h>
5 #include <linux/pfn_t.h>
6 #include "../../nvdimm/pfn.h"
7 #include "../../nvdimm/nd.h"
10 struct dev_dax
*__dax_pmem_probe(struct device
*dev
, enum dev_dax_subsys subsys
)
13 int rc
, id
, region_id
;
14 resource_size_t offset
;
15 struct nd_pfn_sb
*pfn_sb
;
16 struct dev_dax
*dev_dax
;
17 struct dev_dax_data data
;
18 struct nd_namespace_io
*nsio
;
19 struct dax_region
*dax_region
;
20 struct dev_pagemap pgmap
= { };
21 struct nd_namespace_common
*ndns
;
22 struct nd_dax
*nd_dax
= to_nd_dax(dev
);
23 struct nd_pfn
*nd_pfn
= &nd_dax
->nd_pfn
;
24 struct nd_region
*nd_region
= to_nd_region(dev
->parent
);
26 ndns
= nvdimm_namespace_common_probe(dev
);
28 return ERR_CAST(ndns
);
30 /* parse the 'pfn' info block via ->rw_bytes */
31 rc
= devm_namespace_enable(dev
, ndns
, nd_info_block_reserve());
34 rc
= nvdimm_setup_pfn(nd_pfn
, &pgmap
);
37 devm_namespace_disable(dev
, ndns
);
39 /* reserve the metadata area, device-dax will reserve the data */
40 pfn_sb
= nd_pfn
->pfn_sb
;
41 offset
= le64_to_cpu(pfn_sb
->dataoff
);
42 nsio
= to_nd_namespace_io(&ndns
->dev
);
43 if (!devm_request_mem_region(dev
, nsio
->res
.start
, offset
,
44 dev_name(&ndns
->dev
))) {
45 dev_warn(dev
, "could not reserve metadata\n");
46 return ERR_PTR(-EBUSY
);
49 rc
= sscanf(dev_name(&ndns
->dev
), "namespace%d.%d", ®ion_id
, &id
);
51 return ERR_PTR(-EINVAL
);
53 /* adjust the dax_region range to the start of data */
55 range
.start
+= offset
;
56 dax_region
= alloc_dax_region(dev
, region_id
, &range
,
57 nd_region
->target_node
, le32_to_cpu(pfn_sb
->align
),
58 IORESOURCE_DAX_STATIC
);
60 return ERR_PTR(-ENOMEM
);
62 data
= (struct dev_dax_data
) {
63 .dax_region
= dax_region
,
67 .size
= range_len(&range
),
69 dev_dax
= devm_create_dev_dax(&data
);
71 /* child dev_dax instances now own the lifetime of the dax_region */
72 dax_region_put(dax_region
);
76 EXPORT_SYMBOL_GPL(__dax_pmem_probe
);
78 MODULE_LICENSE("GPL v2");
79 MODULE_AUTHOR("Intel Corporation");