Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions arch/arm64/kernel/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <linux/suspend.h>
#include <linux/pgtable.h>

#include <acpi/acpi.h>
#include <acpi/ghes.h>
#include <acpi/processor.h>
#include <asm/cputype.h>
Expand Down Expand Up @@ -458,3 +459,11 @@ int acpi_unmap_cpu(int cpu)
}
EXPORT_SYMBOL(acpi_unmap_cpu);
#endif /* CONFIG_ACPI_HOTPLUG_CPU */

int acpi_get_cpu_acpi_id(unsigned int cpu)
{
if (cpu >= nr_cpu_ids || !cpu_possible(cpu))
return -EINVAL;
return get_acpi_id_for_cpu(cpu);
}
EXPORT_SYMBOL_GPL(acpi_get_cpu_acpi_id);
9 changes: 9 additions & 0 deletions arch/loongarch/kernel/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <linux/memblock.h>
#include <linux/of_fdt.h>
#include <linux/serial_core.h>
#include <asm/acpi.h>
#include <asm/io.h>
#include <asm/numa.h>
#include <asm/loongson.h>
Expand Down Expand Up @@ -385,3 +386,11 @@ int acpi_unmap_cpu(int cpu)
EXPORT_SYMBOL(acpi_unmap_cpu);

#endif /* CONFIG_ACPI_HOTPLUG_CPU */

int acpi_get_cpu_acpi_id(unsigned int cpu)
{
if (cpu >= nr_cpu_ids || !cpu_possible(cpu))
return -EINVAL;
return get_acpi_id_for_cpu(cpu);
}
EXPORT_SYMBOL_GPL(acpi_get_cpu_acpi_id);
10 changes: 10 additions & 0 deletions arch/riscv/kernel/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <linux/pci.h>
#include <linux/serial_core.h>

#include <asm/acpi.h>

int acpi_noirq = 1; /* skip ACPI IRQ initialization */
int acpi_disabled = 1;
EXPORT_SYMBOL(acpi_disabled);
Expand Down Expand Up @@ -337,3 +339,11 @@ int raw_pci_write(unsigned int domain, unsigned int bus,
}

#endif /* CONFIG_PCI */

int acpi_get_cpu_acpi_id(unsigned int cpu)
{
if (cpu >= nr_cpu_ids || !cpu_possible(cpu))
return -EINVAL;
return get_acpi_id_for_cpu(cpu);
}
EXPORT_SYMBOL_GPL(acpi_get_cpu_acpi_id);
17 changes: 17 additions & 0 deletions arch/x86/kernel/cpu/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <linux/stackprotector.h>
#include <linux/utsname.h>
#include <linux/efi.h>
#include <linux/acpi.h>

#include <asm/alternative.h>
#include <asm/cmdline.h>
Expand Down Expand Up @@ -57,6 +58,7 @@
#include <asm/asm.h>
#include <asm/bugs.h>
#include <asm/cpu.h>
#include <asm/smp.h>
#include <asm/mce.h>
#include <asm/msr.h>
#include <asm/cacheinfo.h>
Expand Down Expand Up @@ -2643,3 +2645,18 @@ void __init arch_cpu_finalize_init(void)
*/
mem_encrypt_init();
}

int acpi_get_cpu_acpi_id(unsigned int cpu)
{
u32 acpi_id;

if (cpu >= nr_cpu_ids || !cpu_possible(cpu))
return -EINVAL;

acpi_id = cpu_acpi_id(cpu);
if (acpi_id == CPU_ACPIID_INVALID)
return -ENODEV;

return (int)acpi_id;
}
EXPORT_SYMBOL_GPL(acpi_get_cpu_acpi_id);
17 changes: 12 additions & 5 deletions drivers/pci/tph.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,28 @@ static int write_tag_to_st_table(struct pci_dev *pdev, int index, u16 tag)
* with a specific CPU
* @pdev: PCI device
* @mem_type: target memory type (volatile or persistent RAM)
* @cpu_uid: associated CPU id
* @cpu: associated CPU id
* @tag: Steering Tag to be returned
*
* Return the Steering Tag for a target memory that is associated with a
* specific CPU as indicated by cpu_uid.
* specific CPU as indicated by cpu.
*
* Return: 0 if success, otherwise negative value (-errno)
*/
int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,
unsigned int cpu_uid, u16 *tag)
unsigned int cpu, u16 *tag)
{
#ifdef CONFIG_ACPI
unsigned int cpu_uid;
struct pci_dev *rp;
acpi_handle rp_acpi_handle;
union st_info info;
int ret;

ret = acpi_get_cpu_acpi_id(cpu);
if (ret < 0)
return ret;
cpu_uid = (unsigned int)ret;

rp = pcie_find_root_port(pdev);
if (!rp || !rp->bus || !rp->bus->bridge)
Expand All @@ -265,9 +272,9 @@ int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,

*tag = tph_extract_tag(mem_type, pdev->tph_req_type, &info);

pci_dbg(pdev, "get steering tag: mem_type=%s, cpu_uid=%d, tag=%#04x\n",
pci_dbg(pdev, "get steering tag: mem_type=%s, cpu=%d, tag=%#04x\n",
(mem_type == TPH_MEM_TYPE_VM) ? "volatile" : "persistent",
cpu_uid, *tag);
cpu, *tag);

return 0;
#else
Expand Down
10 changes: 10 additions & 0 deletions include/linux/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@ int acpi_unmap_cpu(int cpu);

acpi_handle acpi_get_processor_handle(int cpu);

/*
* acpi_get_cpu_acpi_id() - Get ACPI Processor UID of a specified CPU from MADT table
* @cpu: Logical CPU number (0-based)
*
* Return: ACPI Processor ID of the CPU on success (non-negative);
* -EINVAL if the CPU number is invalid or not possible;
* -ENODEV if the ACPI ID of the CPU is invalid.
*/
int acpi_get_cpu_acpi_id(unsigned int cpu);

#ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
int acpi_get_ioapic_id(acpi_handle handle, u32 gsi_base, u64 *phys_addr);
#endif
Expand Down
4 changes: 2 additions & 2 deletions include/linux/pci-tph.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int pcie_tph_set_st_entry(struct pci_dev *pdev,
unsigned int index, u16 tag);
int pcie_tph_get_cpu_st(struct pci_dev *dev,
enum tph_mem_type mem_type,
unsigned int cpu_uid, u16 *tag);
unsigned int cpu, u16 *tag);
void pcie_disable_tph(struct pci_dev *pdev);
int pcie_enable_tph(struct pci_dev *pdev, int mode);
u16 pcie_tph_get_st_table_size(struct pci_dev *pdev);
Expand All @@ -36,7 +36,7 @@ static inline int pcie_tph_set_st_entry(struct pci_dev *pdev,
{ return -EINVAL; }
static inline int pcie_tph_get_cpu_st(struct pci_dev *dev,
enum tph_mem_type mem_type,
unsigned int cpu_uid, u16 *tag)
unsigned int cpu, u16 *tag)
{ return -EINVAL; }
static inline void pcie_disable_tph(struct pci_dev *pdev) { }
static inline int pcie_enable_tph(struct pci_dev *pdev, int mode)
Expand Down
Loading