radeon_acpi.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2012 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. */
  23. #include <linux/pci.h>
  24. #include <linux/acpi.h>
  25. #include <linux/slab.h>
  26. #include <acpi/acpi_drivers.h>
  27. #include <acpi/acpi_bus.h>
  28. #include "drmP.h"
  29. #include "drm.h"
  30. #include "drm_sarea.h"
  31. #include "drm_crtc_helper.h"
  32. #include "radeon.h"
  33. #include "radeon_acpi.h"
  34. #include <linux/vga_switcheroo.h>
  35. /* Call the ATIF method
  36. */
  37. static union acpi_object *radeon_atif_call(acpi_handle handle, int function,
  38. struct acpi_buffer *params)
  39. {
  40. acpi_status status;
  41. union acpi_object atif_arg_elements[2];
  42. struct acpi_object_list atif_arg;
  43. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  44. atif_arg.count = 2;
  45. atif_arg.pointer = &atif_arg_elements[0];
  46. atif_arg_elements[0].type = ACPI_TYPE_INTEGER;
  47. atif_arg_elements[0].integer.value = function;
  48. if (params) {
  49. atif_arg_elements[1].type = ACPI_TYPE_BUFFER;
  50. atif_arg_elements[1].buffer.length = params->length;
  51. atif_arg_elements[1].buffer.pointer = params->pointer;
  52. } else {
  53. /* We need a second fake parameter */
  54. atif_arg_elements[1].type = ACPI_TYPE_INTEGER;
  55. atif_arg_elements[1].integer.value = 0;
  56. }
  57. status = acpi_evaluate_object(handle, "ATIF", &atif_arg, &buffer);
  58. /* Fail only if calling the method fails and ATIF is supported */
  59. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  60. DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
  61. acpi_format_exception(status));
  62. kfree(buffer.pointer);
  63. return NULL;
  64. }
  65. return buffer.pointer;
  66. }
  67. /* Call all ACPI methods here */
  68. int radeon_acpi_init(struct radeon_device *rdev)
  69. {
  70. acpi_handle handle;
  71. union acpi_object *info;
  72. int ret = 0;
  73. /* Get the device handle */
  74. handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev);
  75. /* No need to proceed if we're sure that ATIF is not supported */
  76. if (!ASIC_IS_AVIVO(rdev) || !rdev->bios || !handle)
  77. return 0;
  78. /* Call the ATIF method */
  79. info = radeon_atif_call(handle, ATIF_FUNCTION_VERIFY_INTERFACE, NULL);
  80. if (!info)
  81. ret = -EIO;
  82. kfree(info);
  83. return ret;
  84. }