Skip to content

Commit fe09857

Browse files
committed
dax/hmem: Convey the dax range via memregion_info()
In preparation for hmem platform devices to be unregistered, stop using platform_device_add_resources() to convey the address range. The platform_device_add_resources() API causes an existing "Soft Reserved" iomem resource to be re-parented under an inserted platform device resource. When that platform device is deleted it removes the platform device resource and all children. Instead, it is sufficient to convey just the address range and let request_mem_region() insert resources to indicate the devices active in the range. This allows the "Soft Reserved" resource to be re-enumerated upon the next probe event. Reviewed-by: Jonathan Cameron <[email protected]> Tested-by: Fan Ni <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Link: https://lore.kernel.org/r/167602002217.1924368.7036275892522551624.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent 84fe17f commit fe09857

File tree

3 files changed

+19
-34
lines changed

3 files changed

+19
-34
lines changed

drivers/dax/hmem/device.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,71 +15,62 @@ static struct resource hmem_active = {
1515
.flags = IORESOURCE_MEM,
1616
};
1717

18-
void hmem_register_device(int target_nid, struct resource *r)
18+
void hmem_register_device(int target_nid, struct resource *res)
1919
{
20-
/* define a clean / non-busy resource for the platform device */
21-
struct resource res = {
22-
.start = r->start,
23-
.end = r->end,
24-
.flags = IORESOURCE_MEM,
25-
.desc = IORES_DESC_SOFT_RESERVED,
26-
};
2720
struct platform_device *pdev;
2821
struct memregion_info info;
2922
int rc, id;
3023

3124
if (nohmem)
3225
return;
3326

34-
rc = region_intersects(res.start, resource_size(&res), IORESOURCE_MEM,
35-
IORES_DESC_SOFT_RESERVED);
27+
rc = region_intersects(res->start, resource_size(res), IORESOURCE_MEM,
28+
IORES_DESC_SOFT_RESERVED);
3629
if (rc != REGION_INTERSECTS)
3730
return;
3831

3932
id = memregion_alloc(GFP_KERNEL);
4033
if (id < 0) {
41-
pr_err("memregion allocation failure for %pr\n", &res);
34+
pr_err("memregion allocation failure for %pr\n", res);
4235
return;
4336
}
4437

4538
pdev = platform_device_alloc("hmem", id);
4639
if (!pdev) {
47-
pr_err("hmem device allocation failure for %pr\n", &res);
40+
pr_err("hmem device allocation failure for %pr\n", res);
4841
goto out_pdev;
4942
}
5043

51-
if (!__request_region(&hmem_active, res.start, resource_size(&res),
44+
if (!__request_region(&hmem_active, res->start, resource_size(res),
5245
dev_name(&pdev->dev), 0)) {
53-
dev_dbg(&pdev->dev, "hmem range %pr already active\n", &res);
46+
dev_dbg(&pdev->dev, "hmem range %pr already active\n", res);
5447
goto out_active;
5548
}
5649

5750
pdev->dev.numa_node = numa_map_to_online_node(target_nid);
5851
info = (struct memregion_info) {
5952
.target_node = target_nid,
53+
.range = {
54+
.start = res->start,
55+
.end = res->end,
56+
},
6057
};
6158
rc = platform_device_add_data(pdev, &info, sizeof(info));
6259
if (rc < 0) {
63-
pr_err("hmem memregion_info allocation failure for %pr\n", &res);
64-
goto out_resource;
65-
}
66-
67-
rc = platform_device_add_resources(pdev, &res, 1);
68-
if (rc < 0) {
69-
pr_err("hmem resource allocation failure for %pr\n", &res);
60+
pr_err("hmem memregion_info allocation failure for %pr\n", res);
7061
goto out_resource;
7162
}
7263

7364
rc = platform_device_add(pdev);
7465
if (rc < 0) {
75-
dev_err(&pdev->dev, "device add failed for %pr\n", &res);
66+
dev_err(&pdev->dev, "device add failed for %pr\n", res);
7667
goto out_resource;
7768
}
7869

7970
return;
8071

8172
out_resource:
82-
__release_region(&hmem_active, res.start, resource_size(&res));
73+
__release_region(&hmem_active, res->start, resource_size(res));
8374
out_active:
8475
platform_device_put(pdev);
8576
out_pdev:

drivers/dax/hmem/hmem.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,17 @@ static int dax_hmem_probe(struct platform_device *pdev)
1515
struct memregion_info *mri;
1616
struct dev_dax_data data;
1717
struct dev_dax *dev_dax;
18-
struct resource *res;
19-
struct range range;
20-
21-
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
22-
if (!res)
23-
return -ENOMEM;
2418

2519
mri = dev->platform_data;
26-
range.start = res->start;
27-
range.end = res->end;
28-
dax_region = alloc_dax_region(dev, pdev->id, &range, mri->target_node,
29-
PMD_SIZE, 0);
20+
dax_region = alloc_dax_region(dev, pdev->id, &mri->range,
21+
mri->target_node, PMD_SIZE, 0);
3022
if (!dax_region)
3123
return -ENOMEM;
3224

3325
data = (struct dev_dax_data) {
3426
.dax_region = dax_region,
3527
.id = -1,
36-
.size = region_idle ? 0 : resource_size(res),
28+
.size = region_idle ? 0 : range_len(&mri->range),
3729
};
3830
dev_dax = devm_create_dev_dax(&data);
3931
if (IS_ERR(dev_dax))

include/linux/memregion.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
#define _MEMREGION_H_
44
#include <linux/types.h>
55
#include <linux/errno.h>
6+
#include <linux/range.h>
67
#include <linux/bug.h>
78

89
struct memregion_info {
910
int target_node;
11+
struct range range;
1012
};
1113

1214
#ifdef CONFIG_MEMREGION

0 commit comments

Comments
 (0)