Skip to content

Commit c01044c

Browse files
djbwtorvalds
authored andcommitted
ACPI: HMAT: refactor hmat_register_target_device to hmem_register_device
In preparation for exposing "Soft Reserved" memory ranges without an HMAT, move the hmem device registration to its own compilation unit and make the implementation generic. The generic implementation drops usage acpi_map_pxm_to_online_node() that was translating ACPI proximity domain values and instead relies on numa_map_to_online_node() to determine the numa node for the device. [[email protected]: CONFIG_DEV_DAX_HMEM_DEVICES should depend on CONFIG_DAX=y] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]> Signed-off-by: Joao Martins <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Ben Skeggs <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brice Goglin <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Daniel Vetter <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Dave Jiang <[email protected]> Cc: David Airlie <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Ira Weiny <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Jeff Moyer <[email protected]> Cc: Jia He <[email protected]> Cc: Joao Martins <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Pavel Tatashin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Rafael J. Wysocki <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Tom Lendacky <[email protected]> Cc: Vishal Verma <[email protected]> Cc: Wei Yang <[email protected]> Cc: Will Deacon <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Bjorn Helgaas <[email protected]> Cc: Boris Ostrovsky <[email protected]> Cc: Hulk Robot <[email protected]> Cc: Jason Yan <[email protected]> Cc: "Jérôme Glisse" <[email protected]> Cc: Juergen Gross <[email protected]> Cc: kernel test robot <[email protected]> Cc: Randy Dunlap <[email protected]> Cc: Stefano Stabellini <[email protected]> Cc: Vivek Goyal <[email protected]> Link: https://lkml.kernel.org/r/159643096584.4062302.5035370788475153738.stgit@dwillia2-desk3.amr.corp.intel.com Link: https://lore.kernel.org/r/158318761484.2216124.2049322072599482736.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Linus Torvalds <[email protected]>
1 parent 88e9a5b commit c01044c

File tree

7 files changed

+90
-65
lines changed

7 files changed

+90
-65
lines changed

drivers/acpi/numa/hmat.c

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/mutex.h>
2525
#include <linux/node.h>
2626
#include <linux/sysfs.h>
27+
#include <linux/dax.h>
2728

2829
static u8 hmat_revision;
2930
static int hmat_disable __initdata;
@@ -640,66 +641,6 @@ static void hmat_register_target_perf(struct memory_target *target)
640641
node_set_perf_attrs(mem_nid, &target->hmem_attrs, 0);
641642
}
642643

643-
static void hmat_register_target_device(struct memory_target *target,
644-
struct resource *r)
645-
{
646-
/* define a clean / non-busy resource for the platform device */
647-
struct resource res = {
648-
.start = r->start,
649-
.end = r->end,
650-
.flags = IORESOURCE_MEM,
651-
};
652-
struct platform_device *pdev;
653-
struct memregion_info info;
654-
int rc, id;
655-
656-
rc = region_intersects(res.start, resource_size(&res), IORESOURCE_MEM,
657-
IORES_DESC_SOFT_RESERVED);
658-
if (rc != REGION_INTERSECTS)
659-
return;
660-
661-
id = memregion_alloc(GFP_KERNEL);
662-
if (id < 0) {
663-
pr_err("memregion allocation failure for %pr\n", &res);
664-
return;
665-
}
666-
667-
pdev = platform_device_alloc("hmem", id);
668-
if (!pdev) {
669-
pr_err("hmem device allocation failure for %pr\n", &res);
670-
goto out_pdev;
671-
}
672-
673-
pdev->dev.numa_node = acpi_map_pxm_to_online_node(target->memory_pxm);
674-
info = (struct memregion_info) {
675-
.target_node = acpi_map_pxm_to_node(target->memory_pxm),
676-
};
677-
rc = platform_device_add_data(pdev, &info, sizeof(info));
678-
if (rc < 0) {
679-
pr_err("hmem memregion_info allocation failure for %pr\n", &res);
680-
goto out_pdev;
681-
}
682-
683-
rc = platform_device_add_resources(pdev, &res, 1);
684-
if (rc < 0) {
685-
pr_err("hmem resource allocation failure for %pr\n", &res);
686-
goto out_resource;
687-
}
688-
689-
rc = platform_device_add(pdev);
690-
if (rc < 0) {
691-
dev_err(&pdev->dev, "device add failed for %pr\n", &res);
692-
goto out_resource;
693-
}
694-
695-
return;
696-
697-
out_resource:
698-
put_device(&pdev->dev);
699-
out_pdev:
700-
memregion_free(id);
701-
}
702-
703644
static void hmat_register_target_devices(struct memory_target *target)
704645
{
705646
struct resource *res;
@@ -711,8 +652,11 @@ static void hmat_register_target_devices(struct memory_target *target)
711652
if (!IS_ENABLED(CONFIG_DEV_DAX_HMEM))
712653
return;
713654

714-
for (res = target->memregions.child; res; res = res->sibling)
715-
hmat_register_target_device(target, res);
655+
for (res = target->memregions.child; res; res = res->sibling) {
656+
int target_nid = acpi_map_pxm_to_node(target->memory_pxm);
657+
658+
hmem_register_device(target_nid, res);
659+
}
716660
}
717661

718662
static void hmat_register_target(struct memory_target *target)

drivers/dax/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ config DEV_DAX_HMEM
4848

4949
Say M if unsure.
5050

51+
config DEV_DAX_HMEM_DEVICES
52+
depends on DEV_DAX_HMEM && DAX=y
53+
def_bool y
54+
5155
config DEV_DAX_KMEM
5256
tristate "KMEM DAX: volatile-use of persistent memory"
5357
default DEV_DAX

drivers/dax/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
obj-$(CONFIG_DAX) += dax.o
33
obj-$(CONFIG_DEV_DAX) += device_dax.o
44
obj-$(CONFIG_DEV_DAX_KMEM) += kmem.o
5-
obj-$(CONFIG_DEV_DAX_HMEM) += dax_hmem.o
65

76
dax-y := super.o
87
dax-y += bus.o
98
device_dax-y := device.o
10-
dax_hmem-y := hmem.o
119

1210
obj-y += pmem/
11+
obj-y += hmem/

drivers/dax/hmem/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
obj-$(CONFIG_DEV_DAX_HMEM) += dax_hmem.o
3+
obj-$(CONFIG_DEV_DAX_HMEM_DEVICES) += device.o
4+
5+
dax_hmem-y := hmem.o

drivers/dax/hmem/device.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <linux/platform_device.h>
3+
#include <linux/memregion.h>
4+
#include <linux/module.h>
5+
#include <linux/dax.h>
6+
#include <linux/mm.h>
7+
8+
void hmem_register_device(int target_nid, struct resource *r)
9+
{
10+
/* define a clean / non-busy resource for the platform device */
11+
struct resource res = {
12+
.start = r->start,
13+
.end = r->end,
14+
.flags = IORESOURCE_MEM,
15+
};
16+
struct platform_device *pdev;
17+
struct memregion_info info;
18+
int rc, id;
19+
20+
rc = region_intersects(res.start, resource_size(&res), IORESOURCE_MEM,
21+
IORES_DESC_SOFT_RESERVED);
22+
if (rc != REGION_INTERSECTS)
23+
return;
24+
25+
id = memregion_alloc(GFP_KERNEL);
26+
if (id < 0) {
27+
pr_err("memregion allocation failure for %pr\n", &res);
28+
return;
29+
}
30+
31+
pdev = platform_device_alloc("hmem", id);
32+
if (!pdev) {
33+
pr_err("hmem device allocation failure for %pr\n", &res);
34+
goto out_pdev;
35+
}
36+
37+
pdev->dev.numa_node = numa_map_to_online_node(target_nid);
38+
info = (struct memregion_info) {
39+
.target_node = target_nid,
40+
};
41+
rc = platform_device_add_data(pdev, &info, sizeof(info));
42+
if (rc < 0) {
43+
pr_err("hmem memregion_info allocation failure for %pr\n", &res);
44+
goto out_pdev;
45+
}
46+
47+
rc = platform_device_add_resources(pdev, &res, 1);
48+
if (rc < 0) {
49+
pr_err("hmem resource allocation failure for %pr\n", &res);
50+
goto out_resource;
51+
}
52+
53+
rc = platform_device_add(pdev);
54+
if (rc < 0) {
55+
dev_err(&pdev->dev, "device add failed for %pr\n", &res);
56+
goto out_resource;
57+
}
58+
59+
return;
60+
61+
out_resource:
62+
put_device(&pdev->dev);
63+
out_pdev:
64+
memregion_free(id);
65+
}

drivers/dax/hmem.c renamed to drivers/dax/hmem/hmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <linux/memregion.h>
44
#include <linux/module.h>
55
#include <linux/pfn_t.h>
6-
#include "bus.h"
6+
#include "../bus.h"
77

88
static int dax_hmem_probe(struct platform_device *pdev)
99
{

include/linux/dax.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,12 @@ static inline bool dax_mapping(struct address_space *mapping)
238238
return mapping->host && IS_DAX(mapping->host);
239239
}
240240

241+
#ifdef CONFIG_DEV_DAX_HMEM_DEVICES
242+
void hmem_register_device(int target_nid, struct resource *r);
243+
#else
244+
static inline void hmem_register_device(int target_nid, struct resource *r)
245+
{
246+
}
247+
#endif
248+
241249
#endif

0 commit comments

Comments
 (0)