amdgpu_gmc.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright 2018 Advanced Micro Devices, Inc.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sub license, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  16. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  17. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  18. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  19. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. *
  21. * The above copyright notice and this permission notice (including the
  22. * next paragraph) shall be included in all copies or substantial portions
  23. * of the Software.
  24. *
  25. */
  26. #ifndef __AMDGPU_GMC_H__
  27. #define __AMDGPU_GMC_H__
  28. #include <linux/types.h>
  29. #include "amdgpu_irq.h"
  30. struct firmware;
  31. /*
  32. * VMHUB structures, functions & helpers
  33. */
  34. struct amdgpu_vmhub {
  35. uint32_t ctx0_ptb_addr_lo32;
  36. uint32_t ctx0_ptb_addr_hi32;
  37. uint32_t vm_inv_eng0_req;
  38. uint32_t vm_inv_eng0_ack;
  39. uint32_t vm_context0_cntl;
  40. uint32_t vm_l2_pro_fault_status;
  41. uint32_t vm_l2_pro_fault_cntl;
  42. };
  43. /*
  44. * GPU MC structures, functions & helpers
  45. */
  46. struct amdgpu_gmc_funcs {
  47. /* flush the vm tlb via mmio */
  48. void (*flush_gpu_tlb)(struct amdgpu_device *adev,
  49. uint32_t vmid);
  50. /* flush the vm tlb via ring */
  51. uint64_t (*emit_flush_gpu_tlb)(struct amdgpu_ring *ring, unsigned vmid,
  52. uint64_t pd_addr);
  53. /* Change the VMID -> PASID mapping */
  54. void (*emit_pasid_mapping)(struct amdgpu_ring *ring, unsigned vmid,
  55. unsigned pasid);
  56. /* write pte/pde updates using the cpu */
  57. int (*set_pte_pde)(struct amdgpu_device *adev,
  58. void *cpu_pt_addr, /* cpu addr of page table */
  59. uint32_t gpu_page_idx, /* pte/pde to update */
  60. uint64_t addr, /* addr to write into pte/pde */
  61. uint64_t flags); /* access flags */
  62. /* enable/disable PRT support */
  63. void (*set_prt)(struct amdgpu_device *adev, bool enable);
  64. /* set pte flags based per asic */
  65. uint64_t (*get_vm_pte_flags)(struct amdgpu_device *adev,
  66. uint32_t flags);
  67. /* get the pde for a given mc addr */
  68. void (*get_vm_pde)(struct amdgpu_device *adev, int level,
  69. u64 *dst, u64 *flags);
  70. };
  71. struct amdgpu_gmc {
  72. resource_size_t aper_size;
  73. resource_size_t aper_base;
  74. /* for some chips with <= 32MB we need to lie
  75. * about vram size near mc fb location */
  76. u64 mc_vram_size;
  77. u64 visible_vram_size;
  78. u64 gart_size;
  79. u64 gart_start;
  80. u64 gart_end;
  81. u64 vram_start;
  82. u64 vram_end;
  83. unsigned vram_width;
  84. u64 real_vram_size;
  85. int vram_mtrr;
  86. u64 mc_mask;
  87. const struct firmware *fw; /* MC firmware */
  88. uint32_t fw_version;
  89. struct amdgpu_irq_src vm_fault;
  90. uint32_t vram_type;
  91. uint32_t srbm_soft_reset;
  92. bool prt_warning;
  93. uint64_t stolen_size;
  94. uint32_t sdpif_register;
  95. /* apertures */
  96. u64 shared_aperture_start;
  97. u64 shared_aperture_end;
  98. u64 private_aperture_start;
  99. u64 private_aperture_end;
  100. /* protects concurrent invalidation */
  101. spinlock_t invalidate_lock;
  102. bool translate_further;
  103. struct kfd_vm_fault_info *vm_fault_info;
  104. atomic_t vm_fault_info_updated;
  105. const struct amdgpu_gmc_funcs *gmc_funcs;
  106. };
  107. /**
  108. * amdgpu_gmc_vram_full_visible - Check if full VRAM is visible through the BAR
  109. *
  110. * @adev: amdgpu_device pointer
  111. *
  112. * Returns:
  113. * True if full VRAM is visible through the BAR
  114. */
  115. static inline bool amdgpu_gmc_vram_full_visible(struct amdgpu_gmc *gmc)
  116. {
  117. WARN_ON(gmc->real_vram_size < gmc->visible_vram_size);
  118. return (gmc->real_vram_size == gmc->visible_vram_size);
  119. }
  120. #endif