tools/testing/cxl: Add a physical_node link
authorDan Williams <dan.j.williams@intel.com>
Mon, 24 Jan 2022 00:32:12 +0000 (16:32 -0800)
committerDan Williams <dan.j.williams@intel.com>
Wed, 9 Feb 2022 06:57:33 +0000 (22:57 -0800)
Emulate what ACPI does to link a host bridge platform firmware device to
device node on the PCI bus. In this case it's just self referencing
link, but it otherwise lets the tooling test out its lookup code.

Link: https://lore.kernel.org/r/164298433209.3018233.18101085948127163720.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
tools/testing/cxl/test/cxl.c

index 1b36e67dcd7ec77a552a0c36330f9aded80b66d7..431f2bddf6c834652d6cf5f75f12886cd1c6b986 100644 (file)
@@ -641,7 +641,12 @@ static __init int cxl_test_init(void)
                        platform_device_put(pdev);
                        goto err_bridge;
                }
+
                cxl_host_bridge[i] = pdev;
+               rc = sysfs_create_link(&pdev->dev.kobj, &pdev->dev.kobj,
+                                      "physical_node");
+               if (rc)
+                       goto err_bridge;
        }
 
        for (i = 0; i < ARRAY_SIZE(cxl_root_port); i++) {
@@ -745,8 +750,14 @@ err_port:
        for (i = ARRAY_SIZE(cxl_root_port) - 1; i >= 0; i--)
                platform_device_unregister(cxl_root_port[i]);
 err_bridge:
-       for (i = ARRAY_SIZE(cxl_host_bridge) - 1; i >= 0; i--)
+       for (i = ARRAY_SIZE(cxl_host_bridge) - 1; i >= 0; i--) {
+               struct platform_device *pdev = cxl_host_bridge[i];
+
+               if (!pdev)
+                       continue;
+               sysfs_remove_link(&pdev->dev.kobj, "physical_node");
                platform_device_unregister(cxl_host_bridge[i]);
+       }
 err_populate:
        depopulate_all_mock_resources();
 err_gen_pool_add:
@@ -769,8 +780,14 @@ static __exit void cxl_test_exit(void)
                platform_device_unregister(cxl_switch_uport[i]);
        for (i = ARRAY_SIZE(cxl_root_port) - 1; i >= 0; i--)
                platform_device_unregister(cxl_root_port[i]);
-       for (i = ARRAY_SIZE(cxl_host_bridge) - 1; i >= 0; i--)
+       for (i = ARRAY_SIZE(cxl_host_bridge) - 1; i >= 0; i--) {
+               struct platform_device *pdev = cxl_host_bridge[i];
+
+               if (!pdev)
+                       continue;
+               sysfs_remove_link(&pdev->dev.kobj, "physical_node");
                platform_device_unregister(cxl_host_bridge[i]);
+       }
        depopulate_all_mock_resources();
        gen_pool_destroy(cxl_mock_pool);
        unregister_cxl_mock_ops(&cxl_mock_ops);