irq_service.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright 2012-15 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. * Authors: AMD
  23. *
  24. */
  25. #include "dm_services.h"
  26. #include "include/irq_service_interface.h"
  27. #include "include/logger_interface.h"
  28. #include "dce110/irq_service_dce110.h"
  29. #include "dce80/irq_service_dce80.h"
  30. #include "dce120/irq_service_dce120.h"
  31. #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
  32. #include "dcn10/irq_service_dcn10.h"
  33. #endif
  34. #include "reg_helper.h"
  35. #include "irq_service.h"
  36. #define CTX \
  37. irq_service->ctx
  38. void dal_irq_service_construct(
  39. struct irq_service *irq_service,
  40. struct irq_service_init_data *init_data)
  41. {
  42. if (!init_data || !init_data->ctx) {
  43. BREAK_TO_DEBUGGER();
  44. return;
  45. }
  46. irq_service->ctx = init_data->ctx;
  47. }
  48. void dal_irq_service_destroy(struct irq_service **irq_service)
  49. {
  50. if (!irq_service || !*irq_service) {
  51. BREAK_TO_DEBUGGER();
  52. return;
  53. }
  54. kfree(*irq_service);
  55. *irq_service = NULL;
  56. }
  57. const struct irq_source_info *find_irq_source_info(
  58. struct irq_service *irq_service,
  59. enum dc_irq_source source)
  60. {
  61. if (source > DAL_IRQ_SOURCES_NUMBER || source < DC_IRQ_SOURCE_INVALID)
  62. return NULL;
  63. return &irq_service->info[source];
  64. }
  65. void dal_irq_service_set_generic(
  66. struct irq_service *irq_service,
  67. const struct irq_source_info *info,
  68. bool enable)
  69. {
  70. uint32_t addr = info->enable_reg;
  71. uint32_t value = dm_read_reg(irq_service->ctx, addr);
  72. value = (value & ~info->enable_mask) |
  73. (info->enable_value[enable ? 0 : 1] & info->enable_mask);
  74. dm_write_reg(irq_service->ctx, addr, value);
  75. }
  76. bool dal_irq_service_set(
  77. struct irq_service *irq_service,
  78. enum dc_irq_source source,
  79. bool enable)
  80. {
  81. const struct irq_source_info *info =
  82. find_irq_source_info(irq_service, source);
  83. if (!info) {
  84. dm_logger_write(
  85. irq_service->ctx->logger, LOG_ERROR,
  86. "%s: cannot find irq info table entry for %d\n",
  87. __func__,
  88. source);
  89. return false;
  90. }
  91. dal_irq_service_ack(irq_service, source);
  92. if (info->funcs->set)
  93. return info->funcs->set(irq_service, info, enable);
  94. dal_irq_service_set_generic(irq_service, info, enable);
  95. return true;
  96. }
  97. void dal_irq_service_ack_generic(
  98. struct irq_service *irq_service,
  99. const struct irq_source_info *info)
  100. {
  101. uint32_t addr = info->ack_reg;
  102. uint32_t value = dm_read_reg(irq_service->ctx, addr);
  103. value = (value & ~info->ack_mask) |
  104. (info->ack_value & info->ack_mask);
  105. dm_write_reg(irq_service->ctx, addr, value);
  106. }
  107. bool dal_irq_service_ack(
  108. struct irq_service *irq_service,
  109. enum dc_irq_source source)
  110. {
  111. const struct irq_source_info *info =
  112. find_irq_source_info(irq_service, source);
  113. if (!info) {
  114. dm_logger_write(
  115. irq_service->ctx->logger, LOG_ERROR,
  116. "%s: cannot find irq info table entry for %d\n",
  117. __func__,
  118. source);
  119. return false;
  120. }
  121. if (info->funcs->ack)
  122. return info->funcs->ack(irq_service, info);
  123. dal_irq_service_ack_generic(irq_service, info);
  124. return true;
  125. }
  126. enum dc_irq_source dal_irq_service_to_irq_source(
  127. struct irq_service *irq_service,
  128. uint32_t src_id,
  129. uint32_t ext_id)
  130. {
  131. return irq_service->funcs->to_dal_irq_source(
  132. irq_service,
  133. src_id,
  134. ext_id);
  135. }