irq_service.c 3.9 KB

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