acpi-ext.c 2.8 KB

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