kfd_device_queue_manager_cik.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright 2014 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 "kfd_device_queue_manager.h"
  24. #include "cik_regs.h"
  25. #include "oss/oss_2_4_sh_mask.h"
  26. static bool set_cache_memory_policy_cik(struct device_queue_manager *dqm,
  27. struct qcm_process_device *qpd,
  28. enum cache_policy default_policy,
  29. enum cache_policy alternate_policy,
  30. void __user *alternate_aperture_base,
  31. uint64_t alternate_aperture_size);
  32. static int register_process_cik(struct device_queue_manager *dqm,
  33. struct qcm_process_device *qpd);
  34. static int initialize_cpsch_cik(struct device_queue_manager *dqm);
  35. static void init_sdma_vm(struct device_queue_manager *dqm, struct queue *q,
  36. struct qcm_process_device *qpd);
  37. void device_queue_manager_init_cik(struct device_queue_manager_asic_ops *ops)
  38. {
  39. ops->set_cache_memory_policy = set_cache_memory_policy_cik;
  40. ops->register_process = register_process_cik;
  41. ops->initialize = initialize_cpsch_cik;
  42. ops->init_sdma_vm = init_sdma_vm;
  43. }
  44. static uint32_t compute_sh_mem_bases_64bit(unsigned int top_address_nybble)
  45. {
  46. /* In 64-bit mode, we can only control the top 3 bits of the LDS,
  47. * scratch and GPUVM apertures.
  48. * The hardware fills in the remaining 59 bits according to the
  49. * following pattern:
  50. * LDS: X0000000'00000000 - X0000001'00000000 (4GB)
  51. * Scratch: X0000001'00000000 - X0000002'00000000 (4GB)
  52. * GPUVM: Y0010000'00000000 - Y0020000'00000000 (1TB)
  53. *
  54. * (where X/Y is the configurable nybble with the low-bit 0)
  55. *
  56. * LDS and scratch will have the same top nybble programmed in the
  57. * top 3 bits of SH_MEM_BASES.PRIVATE_BASE.
  58. * GPUVM can have a different top nybble programmed in the
  59. * top 3 bits of SH_MEM_BASES.SHARED_BASE.
  60. * We don't bother to support different top nybbles
  61. * for LDS/Scratch and GPUVM.
  62. */
  63. BUG_ON((top_address_nybble & 1) || top_address_nybble > 0xE ||
  64. top_address_nybble == 0);
  65. return PRIVATE_BASE(top_address_nybble << 12) |
  66. SHARED_BASE(top_address_nybble << 12);
  67. }
  68. static bool set_cache_memory_policy_cik(struct device_queue_manager *dqm,
  69. struct qcm_process_device *qpd,
  70. enum cache_policy default_policy,
  71. enum cache_policy alternate_policy,
  72. void __user *alternate_aperture_base,
  73. uint64_t alternate_aperture_size)
  74. {
  75. uint32_t default_mtype;
  76. uint32_t ape1_mtype;
  77. default_mtype = (default_policy == cache_policy_coherent) ?
  78. MTYPE_NONCACHED :
  79. MTYPE_CACHED;
  80. ape1_mtype = (alternate_policy == cache_policy_coherent) ?
  81. MTYPE_NONCACHED :
  82. MTYPE_CACHED;
  83. qpd->sh_mem_config = (qpd->sh_mem_config & PTR32)
  84. | ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED)
  85. | DEFAULT_MTYPE(default_mtype)
  86. | APE1_MTYPE(ape1_mtype);
  87. return true;
  88. }
  89. static int register_process_cik(struct device_queue_manager *dqm,
  90. struct qcm_process_device *qpd)
  91. {
  92. struct kfd_process_device *pdd;
  93. unsigned int temp;
  94. BUG_ON(!dqm || !qpd);
  95. pdd = qpd_to_pdd(qpd);
  96. /* check if sh_mem_config register already configured */
  97. if (qpd->sh_mem_config == 0) {
  98. qpd->sh_mem_config =
  99. ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED) |
  100. DEFAULT_MTYPE(MTYPE_NONCACHED) |
  101. APE1_MTYPE(MTYPE_NONCACHED);
  102. qpd->sh_mem_ape1_limit = 0;
  103. qpd->sh_mem_ape1_base = 0;
  104. }
  105. if (qpd->pqm->process->is_32bit_user_mode) {
  106. temp = get_sh_mem_bases_32(pdd);
  107. qpd->sh_mem_bases = SHARED_BASE(temp);
  108. qpd->sh_mem_config |= PTR32;
  109. } else {
  110. temp = get_sh_mem_bases_nybble_64(pdd);
  111. qpd->sh_mem_bases = compute_sh_mem_bases_64bit(temp);
  112. }
  113. pr_debug("kfd: is32bit process: %d sh_mem_bases nybble: 0x%X and register 0x%X\n",
  114. qpd->pqm->process->is_32bit_user_mode, temp, qpd->sh_mem_bases);
  115. return 0;
  116. }
  117. static void init_sdma_vm(struct device_queue_manager *dqm, struct queue *q,
  118. struct qcm_process_device *qpd)
  119. {
  120. uint32_t value = (1 << SDMA0_RLC0_VIRTUAL_ADDR__ATC__SHIFT);
  121. if (q->process->is_32bit_user_mode)
  122. value |= (1 << SDMA0_RLC0_VIRTUAL_ADDR__PTR32__SHIFT) |
  123. get_sh_mem_bases_32(qpd_to_pdd(qpd));
  124. else
  125. value |= ((get_sh_mem_bases_nybble_64(qpd_to_pdd(qpd))) <<
  126. SDMA0_RLC0_VIRTUAL_ADDR__SHARED_BASE__SHIFT) &
  127. SDMA0_RLC0_VIRTUAL_ADDR__SHARED_BASE_MASK;
  128. q->properties.sdma_vm_addr = value;
  129. }
  130. static int initialize_cpsch_cik(struct device_queue_manager *dqm)
  131. {
  132. return init_pipelines(dqm, get_pipes_num(dqm), get_first_pipe(dqm));
  133. }