1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/platform_device.h>
3 #include <linux/memregion.h>
4 #include <linux/module.h>
8 void hmem_register_device(int target_nid, struct resource *r)
10 /* define a clean / non-busy resource for the platform device */
11 struct resource res = {
14 .flags = IORESOURCE_MEM,
16 struct platform_device *pdev;
17 struct memregion_info info;
20 rc = region_intersects(res.start, resource_size(&res), IORESOURCE_MEM,
21 IORES_DESC_SOFT_RESERVED);
22 if (rc != REGION_INTERSECTS)
25 id = memregion_alloc(GFP_KERNEL);
27 pr_err("memregion allocation failure for %pr\n", &res);
31 pdev = platform_device_alloc("hmem", id);
33 pr_err("hmem device allocation failure for %pr\n", &res);
37 pdev->dev.numa_node = numa_map_to_online_node(target_nid);
38 info = (struct memregion_info) {
39 .target_node = target_nid,
41 rc = platform_device_add_data(pdev, &info, sizeof(info));
43 pr_err("hmem memregion_info allocation failure for %pr\n", &res);
47 rc = platform_device_add_resources(pdev, &res, 1);
49 pr_err("hmem resource allocation failure for %pr\n", &res);
53 rc = platform_device_add(pdev);
55 dev_err(&pdev->dev, "device add failed for %pr\n", &res);
62 put_device(&pdev->dev);