acpi: numa: Add helper function to retrieve the performance attributes
authorDave Jiang <dave.jiang@intel.com>
Thu, 21 Dec 2023 22:03:07 +0000 (15:03 -0700)
committerDan Williams <dan.j.williams@intel.com>
Fri, 22 Dec 2023 22:33:10 +0000 (14:33 -0800)
Add helper to retrieve the performance attributes based on the device
handle.  The helper function is exported so the CXL driver can use that
to acquire the performance data between the CPU and the CXL host bridge.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/170319618721.2212653.5552947472849081786.stgit@djiang5-mobl3
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/acpi/numa/hmat.c
include/linux/acpi.h

index 8a1802e078f3c2263720794f89c54528c58c3a10..d6b85f0f6082f72421168b26fec4b2fff09b4e13 100644 (file)
@@ -108,6 +108,47 @@ static struct memory_target *find_mem_target(unsigned int mem_pxm)
        return NULL;
 }
 
+static struct memory_target *acpi_find_genport_target(u32 uid)
+{
+       struct memory_target *target;
+       u32 target_uid;
+       u8 *uid_ptr;
+
+       list_for_each_entry(target, &targets, node) {
+               uid_ptr = target->gen_port_device_handle + 8;
+               target_uid = *(u32 *)uid_ptr;
+               if (uid == target_uid)
+                       return target;
+       }
+
+       return NULL;
+}
+
+/**
+ * acpi_get_genport_coordinates - Retrieve the access coordinates for a generic port
+ * @uid: ACPI unique id
+ * @coord: The access coordinates written back out for the generic port
+ *
+ * Return: 0 on success. Errno on failure.
+ *
+ * Only supports device handles that are ACPI. Assume ACPI0016 HID for CXL.
+ */
+int acpi_get_genport_coordinates(u32 uid,
+                                struct access_coordinate *coord)
+{
+       struct memory_target *target;
+
+       guard(mutex)(&target_lock);
+       target = acpi_find_genport_target(uid);
+       if (!target)
+               return -ENOENT;
+
+       *coord = target->coord[NODE_ACCESS_CLASS_GENPORT_SINK];
+
+       return 0;
+}
+EXPORT_SYMBOL_NS_GPL(acpi_get_genport_coordinates, CXL);
+
 static __init void alloc_memory_initiator(unsigned int cpu_pxm)
 {
        struct memory_initiator *initiator;
index 4db54e928b36d0d9646d78dfcb78cea6e15c4684..8b0761c682f992a518812e0734b2eddc884c502e 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/mod_devicetable.h>
 #include <linux/property.h>
 #include <linux/uuid.h>
+#include <linux/node.h>
 
 struct irq_domain;
 struct irq_domain_ops;
@@ -424,6 +425,16 @@ extern int acpi_blacklisted(void);
 extern void acpi_osi_setup(char *str);
 extern bool acpi_osi_is_win8(void);
 
+#ifdef CONFIG_ACPI_HMAT
+int acpi_get_genport_coordinates(u32 uid, struct access_coordinate *coord);
+#else
+static inline int acpi_get_genport_coordinates(u32 uid,
+                                              struct access_coordinate *coord)
+{
+       return -EOPNOTSUPP;
+}
+#endif
+
 #ifdef CONFIG_ACPI_NUMA
 int acpi_map_pxm_to_node(int pxm);
 int acpi_get_node(acpi_handle handle);