mock_acpi.c 829 B

1234567891011121314151617181920212223242526272829303132333435
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright(c) 2021 Intel Corporation. All rights reserved. */
  3. #include <linux/platform_device.h>
  4. #include <linux/device.h>
  5. #include <linux/acpi.h>
  6. #include <cxl.h>
  7. #include "test/mock.h"
  8. struct acpi_device *to_cxl_host_bridge(struct device *host, struct device *dev)
  9. {
  10. int index;
  11. struct acpi_device *adev, *found = NULL;
  12. struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
  13. if (ops && ops->is_mock_bridge(dev)) {
  14. found = ACPI_COMPANION(dev);
  15. goto out;
  16. }
  17. if (dev->bus == &platform_bus_type)
  18. goto out;
  19. adev = to_acpi_device(dev);
  20. if (!acpi_pci_find_root(adev->handle))
  21. goto out;
  22. if (strcmp(acpi_device_hid(adev), "ACPI0016") == 0) {
  23. found = adev;
  24. dev_dbg(host, "found host bridge %s\n", dev_name(&adev->dev));
  25. }
  26. out:
  27. put_cxl_mock_ops(index);
  28. return found;
  29. }