acpi-ext.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * (c) Copyright 2003, 2006 Hewlett-Packard Development Company, L.P.
  4. * Alex Williamson <[email protected]>
  5. * Bjorn Helgaas <[email protected]>
  6. */
  7. #include <linux/module.h>
  8. #include <linux/types.h>
  9. #include <linux/slab.h>
  10. #include <linux/acpi.h>
  11. #include <asm/acpi-ext.h>
  12. /*
  13. * Device CSRs that do not appear in PCI config space should be described
  14. * via ACPI. This would normally be done with Address Space Descriptors
  15. * marked as "consumer-only," but old versions of Windows and Linux ignore
  16. * the producer/consumer flag, so HP invented a vendor-defined resource to
  17. * describe the location and size of CSR space.
  18. */
  19. struct acpi_vendor_uuid hp_ccsr_uuid = {
  20. .subtype = 2,
  21. .data = { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a,
  22. 0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad },
  23. };
  24. static acpi_status hp_ccsr_locate(acpi_handle obj, u64 *base, u64 *length)
  25. {
  26. acpi_status status;
  27. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  28. struct acpi_resource *resource;
  29. struct acpi_resource_vendor_typed *vendor;
  30. status = acpi_get_vendor_resource(obj, METHOD_NAME__CRS, &hp_ccsr_uuid,
  31. &buffer);
  32. resource = buffer.pointer;
  33. vendor = &resource->data.vendor_typed;
  34. if (ACPI_FAILURE(status) || vendor->byte_length < 16) {
  35. status = AE_NOT_FOUND;
  36. goto exit;
  37. }
  38. memcpy(base, vendor->byte_data, sizeof(*base));
  39. memcpy(length, vendor->byte_data + 8, sizeof(*length));
  40. exit:
  41. kfree(buffer.pointer);
  42. return status;
  43. }
  44. struct csr_space {
  45. u64 base;
  46. u64 length;
  47. };
  48. static acpi_status find_csr_space(struct acpi_resource *resource, void *data)
  49. {
  50. struct csr_space *space = data;
  51. struct acpi_resource_address64 addr;
  52. acpi_status status;
  53. status = acpi_resource_to_address64(resource, &addr);
  54. if (ACPI_SUCCESS(status) &&
  55. addr.resource_type == ACPI_MEMORY_RANGE &&
  56. addr.address.address_length &&
  57. addr.producer_consumer == ACPI_CONSUMER) {
  58. space->base = addr.address.minimum;
  59. space->length = addr.address.address_length;
  60. return AE_CTRL_TERMINATE;
  61. }
  62. return AE_OK; /* keep looking */
  63. }
  64. static acpi_status hp_crs_locate(acpi_handle obj, u64 *base, u64 *length)
  65. {
  66. struct csr_space space = { 0, 0 };
  67. acpi_walk_resources(obj, METHOD_NAME__CRS, find_csr_space, &space);
  68. if (!space.length)
  69. return AE_NOT_FOUND;
  70. *base = space.base;
  71. *length = space.length;
  72. return AE_OK;
  73. }
  74. acpi_status hp_acpi_csr_space(acpi_handle obj, u64 *csr_base, u64 *csr_length)
  75. {
  76. acpi_status status;
  77. status = hp_ccsr_locate(obj, csr_base, csr_length);
  78. if (ACPI_SUCCESS(status))
  79. return status;
  80. return hp_crs_locate(obj, csr_base, csr_length);
  81. }
  82. EXPORT_SYMBOL(hp_acpi_csr_space);