1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/platform_device.h>
3 #include <linux/memregion.h>
4 #include <linux/module.h>
9 module_param_named(disable
, nohmem
, bool, 0444);
11 static bool platform_initialized
;
12 static DEFINE_MUTEX(hmem_resource_lock
);
13 static struct resource hmem_active
= {
14 .name
= "HMEM devices",
17 .flags
= IORESOURCE_MEM
,
20 int walk_hmem_resources(struct device
*host
, walk_hmem_fn fn
)
25 mutex_lock(&hmem_resource_lock
);
26 for (res
= hmem_active
.child
; res
; res
= res
->sibling
) {
27 rc
= fn(host
, (int) res
->desc
, res
);
31 mutex_unlock(&hmem_resource_lock
);
34 EXPORT_SYMBOL_GPL(walk_hmem_resources
);
36 static void __hmem_register_resource(int target_nid
, struct resource
*res
)
38 struct platform_device
*pdev
;
42 new = __request_region(&hmem_active
, res
->start
, resource_size(res
), "",
45 pr_debug("hmem range %pr already active\n", res
);
49 new->desc
= target_nid
;
51 if (platform_initialized
)
54 pdev
= platform_device_alloc("hmem_platform", 0);
56 pr_err_once("failed to register device-dax hmem_platform device\n");
60 rc
= platform_device_add(pdev
);
62 platform_device_put(pdev
);
64 platform_initialized
= true;
67 void hmem_register_resource(int target_nid
, struct resource
*res
)
72 mutex_lock(&hmem_resource_lock
);
73 __hmem_register_resource(target_nid
, res
);
74 mutex_unlock(&hmem_resource_lock
);
77 static __init
int hmem_register_one(struct resource
*res
, void *data
)
79 hmem_register_resource(phys_to_target_node(res
->start
), res
);
84 static __init
int hmem_init(void)
86 walk_iomem_res_desc(IORES_DESC_SOFT_RESERVED
,
87 IORESOURCE_MEM
, 0, -1, NULL
, hmem_register_one
);
92 * As this is a fallback for address ranges unclaimed by the ACPI HMAT
93 * parsing it must be at an initcall level greater than hmat_init().
95 device_initcall(hmem_init
);