Skip to content

Commit a660cdd

Browse files
committed
Merge branch 'acpi-tables' into linux-next
* acpi-tables: ACPI: tables: Improve logging around acpi_initialize_tables() ACPI: VIOT: Remove (explicitly) unused header ACPI: Add documentation for exposing MRRM data ACPI: MRRM: Add /sys files to describe memory ranges ACPI: MRRM: Minimal parse of ACPI MRRM table ACPI: tables: Add __nonstring annotations for unterminated strings
2 parents fca37ec + 8e66be0 commit a660cdd

8 files changed

Lines changed: 224 additions & 3 deletions

File tree

Documentation/ABI/testing/sysfs-firmware-acpi

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,24 @@ Description:
248248
# cat ff_pwr_btn
249249
7 enabled
250250

251+
What: /sys/firmware/acpi/memory_ranges/rangeX
252+
Date: February 2025
253+
Contact: Tony Luck <tony.luck@intel.com>
254+
Description:
255+
On systems with the ACPI MRRM table reports the parameters for
256+
each range.
257+
258+
base: Starting system physical address.
259+
260+
length: Length of this range in bytes.
261+
262+
node: NUMA node that this range belongs to. Negative numbers
263+
indicate that the node number could not be determined (e.g
264+
for an address range that is reserved for future hot add of
265+
memory).
266+
267+
local_region_id: ID associated with access by agents
268+
local to this range of addresses.
269+
270+
remote_region_id: ID associated with access by agents
271+
non-local to this range of addresses.

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ config X86_64
3838
select ARCH_HAS_ELFCORE_COMPAT
3939
select ZONE_DMA32
4040
select EXECMEM if DYNAMIC_FTRACE
41+
select ACPI_MRRM if ACPI
4142

4243
config FORCE_DYNAMIC_FTRACE
4344
def_bool y

drivers/acpi/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ config ACPI_FFH
576576
Enable this feature if you want to set up and install the FFH Address
577577
Space handler to handle FFH OpRegion in the firmware.
578578

579+
config ACPI_MRRM
580+
bool
581+
579582
source "drivers/acpi/pmic/Kconfig"
580583

581584
config ACPI_VIOT

drivers/acpi/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ acpi-$(CONFIG_ACPI_WATCHDOG) += acpi_watchdog.o
6666
acpi-$(CONFIG_ACPI_PRMT) += prmt.o
6767
acpi-$(CONFIG_ACPI_PCC) += acpi_pcc.o
6868
acpi-$(CONFIG_ACPI_FFH) += acpi_ffh.o
69+
acpi-$(CONFIG_ACPI_MRRM) += acpi_mrrm.o
6970

7071
# Address translation
7172
acpi-$(CONFIG_ACPI_ADXL) += acpi_adxl.o

drivers/acpi/acpi_mrrm.c

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2025, Intel Corporation.
4+
*
5+
* Memory Range and Region Mapping (MRRM) structure
6+
*
7+
* Parse and report the platform's MRRM table in /sys.
8+
*/
9+
10+
#define pr_fmt(fmt) "acpi/mrrm: " fmt
11+
12+
#include <linux/acpi.h>
13+
#include <linux/init.h>
14+
#include <linux/string.h>
15+
#include <linux/sysfs.h>
16+
17+
static int max_mem_region = -ENOENT;
18+
19+
/* Access for use by resctrl file system */
20+
int acpi_mrrm_max_mem_region(void)
21+
{
22+
return max_mem_region;
23+
}
24+
25+
struct mrrm_mem_range_entry {
26+
u64 base;
27+
u64 length;
28+
int node;
29+
u8 local_region_id;
30+
u8 remote_region_id;
31+
};
32+
33+
static struct mrrm_mem_range_entry *mrrm_mem_range_entry;
34+
static u32 mrrm_mem_entry_num;
35+
36+
static int get_node_num(struct mrrm_mem_range_entry *e)
37+
{
38+
unsigned int nid;
39+
40+
for_each_online_node(nid) {
41+
for (int z = 0; z < MAX_NR_ZONES; z++) {
42+
struct zone *zone = NODE_DATA(nid)->node_zones + z;
43+
44+
if (!populated_zone(zone))
45+
continue;
46+
if (zone_intersects(zone, PHYS_PFN(e->base), PHYS_PFN(e->length)))
47+
return zone_to_nid(zone);
48+
}
49+
}
50+
51+
return -ENOENT;
52+
}
53+
54+
static __init int acpi_parse_mrrm(struct acpi_table_header *table)
55+
{
56+
struct acpi_mrrm_mem_range_entry *mre_entry;
57+
struct acpi_table_mrrm *mrrm;
58+
void *mre, *mrrm_end;
59+
int mre_count = 0;
60+
61+
mrrm = (struct acpi_table_mrrm *)table;
62+
if (!mrrm)
63+
return -ENODEV;
64+
65+
if (mrrm->flags & ACPI_MRRM_FLAGS_REGION_ASSIGNMENT_OS)
66+
return -EOPNOTSUPP;
67+
68+
mrrm_end = (void *)mrrm + mrrm->header.length - 1;
69+
mre = (void *)mrrm + sizeof(struct acpi_table_mrrm);
70+
while (mre < mrrm_end) {
71+
mre_entry = mre;
72+
mre_count++;
73+
mre += mre_entry->header.length;
74+
}
75+
if (!mre_count) {
76+
pr_info(FW_BUG "No ranges listed in MRRM table\n");
77+
return -EINVAL;
78+
}
79+
80+
mrrm_mem_range_entry = kmalloc_array(mre_count, sizeof(*mrrm_mem_range_entry),
81+
GFP_KERNEL | __GFP_ZERO);
82+
if (!mrrm_mem_range_entry)
83+
return -ENOMEM;
84+
85+
mre = (void *)mrrm + sizeof(struct acpi_table_mrrm);
86+
while (mre < mrrm_end) {
87+
struct mrrm_mem_range_entry *e;
88+
89+
mre_entry = mre;
90+
e = mrrm_mem_range_entry + mrrm_mem_entry_num;
91+
92+
e->base = mre_entry->addr_base;
93+
e->length = mre_entry->addr_len;
94+
e->node = get_node_num(e);
95+
96+
if (mre_entry->region_id_flags & ACPI_MRRM_VALID_REGION_ID_FLAGS_LOCAL)
97+
e->local_region_id = mre_entry->local_region_id;
98+
else
99+
e->local_region_id = -1;
100+
if (mre_entry->region_id_flags & ACPI_MRRM_VALID_REGION_ID_FLAGS_REMOTE)
101+
e->remote_region_id = mre_entry->remote_region_id;
102+
else
103+
e->remote_region_id = -1;
104+
105+
mrrm_mem_entry_num++;
106+
mre += mre_entry->header.length;
107+
}
108+
109+
max_mem_region = mrrm->max_mem_region;
110+
111+
return 0;
112+
}
113+
114+
#define RANGE_ATTR(name, fmt) \
115+
static ssize_t name##_show(struct kobject *kobj, \
116+
struct kobj_attribute *attr, char *buf) \
117+
{ \
118+
struct mrrm_mem_range_entry *mre; \
119+
const char *kname = kobject_name(kobj); \
120+
int n, ret; \
121+
\
122+
ret = kstrtoint(kname + 5, 10, &n); \
123+
if (ret) \
124+
return ret; \
125+
\
126+
mre = mrrm_mem_range_entry + n; \
127+
\
128+
return sysfs_emit(buf, fmt, mre->name); \
129+
} \
130+
static struct kobj_attribute name##_attr = __ATTR_RO(name)
131+
132+
RANGE_ATTR(base, "0x%llx\n");
133+
RANGE_ATTR(length, "0x%llx\n");
134+
RANGE_ATTR(node, "%d\n");
135+
RANGE_ATTR(local_region_id, "%d\n");
136+
RANGE_ATTR(remote_region_id, "%d\n");
137+
138+
static struct attribute *memory_range_attrs[] = {
139+
&base_attr.attr,
140+
&length_attr.attr,
141+
&node_attr.attr,
142+
&local_region_id_attr.attr,
143+
&remote_region_id_attr.attr,
144+
NULL
145+
};
146+
147+
ATTRIBUTE_GROUPS(memory_range);
148+
149+
static __init int add_boot_memory_ranges(void)
150+
{
151+
struct kobject *pkobj, *kobj;
152+
int ret = -EINVAL;
153+
char *name;
154+
155+
pkobj = kobject_create_and_add("memory_ranges", acpi_kobj);
156+
157+
for (int i = 0; i < mrrm_mem_entry_num; i++) {
158+
name = kasprintf(GFP_KERNEL, "range%d", i);
159+
if (!name)
160+
break;
161+
162+
kobj = kobject_create_and_add(name, pkobj);
163+
164+
ret = sysfs_create_groups(kobj, memory_range_groups);
165+
if (ret)
166+
return ret;
167+
}
168+
169+
return ret;
170+
}
171+
172+
static __init int mrrm_init(void)
173+
{
174+
int ret;
175+
176+
ret = acpi_table_parse(ACPI_SIG_MRRM, acpi_parse_mrrm);
177+
if (ret < 0)
178+
return ret;
179+
180+
return add_boot_memory_ranges();
181+
}
182+
device_initcall(mrrm_init);

drivers/acpi/tables.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static u8 __init acpi_table_checksum(u8 *buffer, u32 length)
396396
}
397397

398398
/* All but ACPI_SIG_RSDP and ACPI_SIG_FACS: */
399-
static const char table_sigs[][ACPI_NAMESEG_SIZE] __initconst = {
399+
static const char table_sigs[][ACPI_NAMESEG_SIZE] __nonstring_array __initconst = {
400400
ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
401401
ACPI_SIG_EINJ, ACPI_SIG_ERST, ACPI_SIG_HEST, ACPI_SIG_MADT,
402402
ACPI_SIG_MSCT, ACPI_SIG_SBST, ACPI_SIG_SLIT, ACPI_SIG_SRAT,
@@ -719,8 +719,12 @@ int __init acpi_locate_initial_tables(void)
719719
}
720720

721721
status = acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
722-
if (ACPI_FAILURE(status))
722+
if (ACPI_FAILURE(status)) {
723+
const char *msg = acpi_format_exception(status);
724+
725+
pr_warn("Failed to initialize tables, status=0x%x (%s)", status, msg);
723726
return -EINVAL;
727+
}
724728

725729
return 0;
726730
}

drivers/acpi/viot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#define pr_fmt(fmt) "ACPI: VIOT: " fmt
2020

2121
#include <linux/acpi_viot.h>
22-
#include <linux/fwnode.h>
2322
#include <linux/iommu.h>
2423
#include <linux/list.h>
2524
#include <linux/pci.h>
2625
#include <linux/platform_device.h>
26+
#include <linux/property.h>
2727

2828
struct viot_iommu {
2929
/* Node offset within the table */

include/linux/acpi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,10 @@ int acpi_get_local_u64_address(acpi_handle handle, u64 *addr);
772772
int acpi_get_local_address(acpi_handle handle, u32 *addr);
773773
const char *acpi_get_subsystem_id(acpi_handle handle);
774774

775+
#ifdef CONFIG_ACPI_MRRM
776+
int acpi_mrrm_max_mem_region(void);
777+
#endif
778+
775779
#else /* !CONFIG_ACPI */
776780

777781
#define acpi_disabled 1
@@ -1092,6 +1096,11 @@ static inline acpi_handle acpi_get_processor_handle(int cpu)
10921096
return NULL;
10931097
}
10941098

1099+
static inline int acpi_mrrm_max_mem_region(void)
1100+
{
1101+
return -ENOENT;
1102+
}
1103+
10951104
#endif /* !CONFIG_ACPI */
10961105

10971106
#ifdef CONFIG_ACPI_HMAT

0 commit comments

Comments
 (0)