Skip to content
4 changes: 2 additions & 2 deletions Documentation/PCI/tph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ To retrieve a Steering Tag for a target memory associated with a specific
CPU, use the following function::

int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type type,
unsigned int cpu_uid, u16 *tag);
unsigned int cpu, u16 *tag);

The `type` argument is used to specify the memory type, either volatile
or persistent, of the target memory. The `cpu_uid` argument specifies the
or persistent, of the target memory. The `cpu` argument specifies the
CPU where the memory is associated to.

After the ST value is retrieved, the device driver can use the following
Expand Down
17 changes: 1 addition & 16 deletions arch/arm64/include/asm/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,7 @@ static inline bool acpi_has_cpu_in_madt(void)
}

struct acpi_madt_generic_interrupt *acpi_cpu_get_madt_gicc(int cpu);
static inline u32 get_acpi_id_for_cpu(unsigned int cpu)
{
return acpi_cpu_get_madt_gicc(cpu)->uid;
}

static inline int get_cpu_for_acpi_id(u32 uid)
{
int cpu;

for (cpu = 0; cpu < nr_cpu_ids; cpu++)
if (acpi_cpu_get_madt_gicc(cpu) &&
uid == get_acpi_id_for_cpu(cpu))
return cpu;

return -EINVAL;
}
int get_cpu_for_acpi_id(u32 uid);

static inline void arch_fix_phys_package_id(int num, u32 slot) { }
void __init acpi_init_cpus(void);
Expand Down
30 changes: 30 additions & 0 deletions arch/arm64/kernel/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,33 @@ int acpi_unmap_cpu(int cpu)
}
EXPORT_SYMBOL(acpi_unmap_cpu);
#endif /* CONFIG_ACPI_HOTPLUG_CPU */

int acpi_get_cpu_uid(unsigned int cpu, u32 *uid)
{
struct acpi_madt_generic_interrupt *gicc;

if (cpu >= nr_cpu_ids)
return -EINVAL;

gicc = acpi_cpu_get_madt_gicc(cpu);
if (!gicc)
return -ENODEV;

*uid = gicc->uid;
return 0;
}
EXPORT_SYMBOL_GPL(acpi_get_cpu_uid);

int get_cpu_for_acpi_id(u32 uid)
{
u32 cpu_uid;
int ret;

for (int cpu = 0; cpu < nr_cpu_ids; cpu++) {
ret = acpi_get_cpu_uid(cpu, &cpu_uid);
if (ret == 0 && uid == cpu_uid)
return cpu;
}

return -EINVAL;
}
5 changes: 0 additions & 5 deletions arch/loongarch/include/asm/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ extern struct acpi_madt_core_pic acpi_core_pic[MAX_CORE_PIC];

extern int __init parse_acpi_topology(void);

static inline u32 get_acpi_id_for_cpu(unsigned int cpu)
{
return acpi_core_pic[cpu_logical_map(cpu)].processor_id;
}

#endif /* !CONFIG_ACPI */

#define ACPI_TABLE_UPGRADE_MAX_PHYS ARCH_LOW_ADDRESS_LIMIT
Expand Down
9 changes: 9 additions & 0 deletions arch/loongarch/kernel/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,12 @@ int acpi_unmap_cpu(int cpu)
EXPORT_SYMBOL(acpi_unmap_cpu);

#endif /* CONFIG_ACPI_HOTPLUG_CPU */

int acpi_get_cpu_uid(unsigned int cpu, u32 *uid)
{
if (cpu >= nr_cpu_ids)
return -EINVAL;
*uid = acpi_core_pic[cpu_logical_map(cpu)].processor_id;
return 0;
}
EXPORT_SYMBOL_GPL(acpi_get_cpu_uid);
4 changes: 0 additions & 4 deletions arch/riscv/include/asm/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { }

void acpi_init_rintc_map(void);
struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu);
static inline u32 get_acpi_id_for_cpu(int cpu)
{
return acpi_cpu_get_madt_rintc(cpu)->uid;
}

int acpi_get_riscv_isa(struct acpi_table_header *table,
unsigned int cpu, const char **isa);
Expand Down
16 changes: 16 additions & 0 deletions arch/riscv/kernel/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,19 @@ int raw_pci_write(unsigned int domain, unsigned int bus,
}

#endif /* CONFIG_PCI */

int acpi_get_cpu_uid(unsigned int cpu, u32 *uid)
{
struct acpi_madt_rintc *rintc;

if (cpu >= nr_cpu_ids)
return -EINVAL;

rintc = acpi_cpu_get_madt_rintc(cpu);
if (!rintc)
return -ENODEV;

*uid = rintc->uid;
return 0;
}
EXPORT_SYMBOL_GPL(acpi_get_cpu_uid);
9 changes: 6 additions & 3 deletions arch/riscv/kernel/acpi_numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ static int __init acpi_numa_get_nid(unsigned int cpu)

static inline int get_cpu_for_acpi_id(u32 uid)
{
int cpu;
u32 cpu_uid;
int ret;

for (cpu = 0; cpu < nr_cpu_ids; cpu++)
if (uid == get_acpi_id_for_cpu(cpu))
for (int cpu = 0; cpu < nr_cpu_ids; cpu++) {
ret = acpi_get_cpu_uid(cpu, &cpu_uid);
if (ret == 0 && uid == cpu_uid)
return cpu;
}

return -EINVAL;
}
Expand Down
1 change: 0 additions & 1 deletion arch/x86/include/asm/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#ifndef CONFIG_SMP
#define cpu_physical_id(cpu) boot_cpu_physical_apicid
#define cpu_acpi_id(cpu) 0
#endif /* CONFIG_SMP */

#ifdef CONFIG_HOTPLUG_CPU
Expand Down
1 change: 0 additions & 1 deletion arch/x86/include/asm/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ __visible void smp_call_function_interrupt(struct pt_regs *regs);
__visible void smp_call_function_single_interrupt(struct pt_regs *r);

#define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
#define cpu_acpi_id(cpu) per_cpu(x86_cpu_to_acpiid, cpu)

/*
* This function is needed by all SMP systems. It must _always_ be valid
Expand Down
20 changes: 20 additions & 0 deletions arch/x86/kernel/acpi/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1848,3 +1848,23 @@ void __iomem * (*acpi_os_ioremap)(acpi_physical_address phys, acpi_size size) =
x86_acpi_os_ioremap;
EXPORT_SYMBOL_GPL(acpi_os_ioremap);
#endif

int acpi_get_cpu_uid(unsigned int cpu, u32 *uid)
{
u32 acpi_id;

if (cpu >= nr_cpu_ids)
return -EINVAL;

#ifdef CONFIG_SMP
acpi_id = per_cpu(x86_cpu_to_acpiid, cpu);
if (acpi_id == CPU_ACPIID_INVALID)
return -ENODEV;
#else
acpi_id = 0;
#endif

*uid = acpi_id;
return 0;
}
EXPORT_SYMBOL_GPL(acpi_get_cpu_uid);
5 changes: 3 additions & 2 deletions arch/x86/xen/enlighten_hvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ static void xen_hvm_crash_shutdown(struct pt_regs *regs)

static int xen_cpu_up_prepare_hvm(unsigned int cpu)
{
u32 cpu_uid;
int rc = 0;

/*
Expand All @@ -161,8 +162,8 @@ static int xen_cpu_up_prepare_hvm(unsigned int cpu)
*/
xen_uninit_lock_cpu(cpu);

if (cpu_acpi_id(cpu) != CPU_ACPIID_INVALID)
per_cpu(xen_vcpu_id, cpu) = cpu_acpi_id(cpu);
if (acpi_get_cpu_uid(cpu, &cpu_uid) == 0)
per_cpu(xen_vcpu_id, cpu) = cpu_uid;
else
per_cpu(xen_vcpu_id, cpu) = cpu;
xen_vcpu_setup(cpu);
Expand Down
50 changes: 37 additions & 13 deletions drivers/acpi/pptt.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,14 @@ static void cache_setup_acpi_cpu(struct acpi_table_header *table,
{
struct acpi_pptt_cache *found_cache;
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
u32 acpi_cpu_id;
struct cacheinfo *this_leaf;
unsigned int index = 0;
struct acpi_pptt_processor *cpu_node = NULL;

if (acpi_get_cpu_uid(cpu, &acpi_cpu_id) != 0)
return;

while (index < get_cpu_cacheinfo(cpu)->num_leaves) {
this_leaf = this_cpu_ci->info_list + index;
found_cache = acpi_find_cache_node(table, acpi_cpu_id,
Expand Down Expand Up @@ -546,7 +549,10 @@ static int topology_get_acpi_cpu_tag(struct acpi_table_header *table,
unsigned int cpu, int level, int flag)
{
struct acpi_pptt_processor *cpu_node;
u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
u32 acpi_cpu_id;

if (acpi_get_cpu_uid(cpu, &acpi_cpu_id) != 0)
return -ENOENT;

cpu_node = acpi_find_processor_node(table, acpi_cpu_id);
if (cpu_node) {
Expand Down Expand Up @@ -614,18 +620,22 @@ static int find_acpi_cpu_topology_tag(unsigned int cpu, int level, int flag)
*
* Check the node representing a CPU for a given flag.
*
* Return: -ENOENT if the PPTT doesn't exist, the CPU cannot be found or
* the table revision isn't new enough.
* Return: -ENOENT if can't get CPU's ACPI Processor UID, the PPTT doesn't
* exist, the CPU cannot be found or the table revision isn't new
* enough.
* 1, any passed flag set
* 0, flag unset
*/
static int check_acpi_cpu_flag(unsigned int cpu, int rev, u32 flag)
{
struct acpi_table_header *table;
u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
u32 acpi_cpu_id;
struct acpi_pptt_processor *cpu_node = NULL;
int ret = -ENOENT;

if (acpi_get_cpu_uid(cpu, &acpi_cpu_id) != 0)
return -ENOENT;

table = acpi_get_pptt();
if (!table)
return -ENOENT;
Expand All @@ -651,7 +661,8 @@ static int check_acpi_cpu_flag(unsigned int cpu, int rev, u32 flag)
* in the PPTT. Errors caused by lack of a PPTT table, or otherwise, return 0
* indicating we didn't find any cache levels.
*
* Return: -ENOENT if no PPTT table or no PPTT processor struct found.
* Return: -ENOENT if no PPTT table, can't get CPU's ACPI Process UID or no PPTT
* processor struct found.
* 0 on success.
*/
int acpi_get_cache_info(unsigned int cpu, unsigned int *levels,
Expand All @@ -671,7 +682,9 @@ int acpi_get_cache_info(unsigned int cpu, unsigned int *levels,

pr_debug("Cache Setup: find cache levels for CPU=%d\n", cpu);

acpi_cpu_id = get_acpi_id_for_cpu(cpu);
if (acpi_get_cpu_uid(cpu, &acpi_cpu_id))
return -ENOENT;

cpu_node = acpi_find_processor_node(table, acpi_cpu_id);
if (!cpu_node)
return -ENOENT;
Expand Down Expand Up @@ -780,8 +793,9 @@ int find_acpi_cpu_topology_package(unsigned int cpu)
* It may not exist in single CPU systems. In simple multi-CPU systems,
* it may be equal to the package topology level.
*
* Return: -ENOENT if the PPTT doesn't exist, the CPU cannot be found
* or there is no toplogy level above the CPU..
* Return: -ENOENT if the PPTT doesn't exist, can't get CPU's ACPI
* Processor UID, the CPU cannot be found or there is no toplogy level
* above the CPU.
* Otherwise returns a value which represents the package for this CPU.
*/

Expand All @@ -797,7 +811,9 @@ int find_acpi_cpu_topology_cluster(unsigned int cpu)
if (!table)
return -ENOENT;

acpi_cpu_id = get_acpi_id_for_cpu(cpu);
if (acpi_get_cpu_uid(cpu, &acpi_cpu_id) != 0)
return -ENOENT;

cpu_node = acpi_find_processor_node(table, acpi_cpu_id);
if (!cpu_node || !cpu_node->parent)
return -ENOENT;
Expand Down Expand Up @@ -872,7 +888,9 @@ static void acpi_pptt_get_child_cpus(struct acpi_table_header *table_hdr,
cpumask_clear(cpus);

for_each_possible_cpu(cpu) {
acpi_id = get_acpi_id_for_cpu(cpu);
if (acpi_get_cpu_uid(cpu, &acpi_id) != 0)
continue;

cpu_node = acpi_find_processor_node(table_hdr, acpi_id);

while (cpu_node) {
Expand Down Expand Up @@ -966,10 +984,13 @@ int find_acpi_cache_level_from_id(u32 cache_id)
for_each_possible_cpu(cpu) {
bool empty;
int level = 1;
u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
u32 acpi_cpu_id;
struct acpi_pptt_cache *cache;
struct acpi_pptt_processor *cpu_node;

if (acpi_get_cpu_uid(cpu, &acpi_cpu_id) != 0)
continue;

cpu_node = acpi_find_processor_node(table, acpi_cpu_id);
if (!cpu_node)
continue;
Expand Down Expand Up @@ -1030,10 +1051,13 @@ int acpi_pptt_get_cpumask_from_cache_id(u32 cache_id, cpumask_t *cpus)
for_each_possible_cpu(cpu) {
bool empty;
int level = 1;
u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
u32 acpi_cpu_id;
struct acpi_pptt_cache *cache;
struct acpi_pptt_processor *cpu_node;

if (acpi_get_cpu_uid(cpu, &acpi_cpu_id) != 0)
continue;

cpu_node = acpi_find_processor_node(table, acpi_cpu_id);
if (!cpu_node)
continue;
Expand Down
7 changes: 6 additions & 1 deletion drivers/acpi/riscv/rhct.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ int acpi_get_riscv_isa(struct acpi_table_header *table, unsigned int cpu, const
struct acpi_rhct_isa_string *isa_node;
struct acpi_table_rhct *rhct;
u32 *hart_info_node_offset;
u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
u32 acpi_cpu_id;
int ret;

BUG_ON(acpi_disabled);

ret = acpi_get_cpu_uid(cpu, &acpi_cpu_id);
if (ret != 0)
return ret;

if (!table) {
rhct = acpi_get_rhct();
if (!rhct)
Expand Down
Loading
Loading