acpi-ext.c 2.7 KB

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