goyaP.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * Copyright 2016-2022 HabanaLabs, Ltd.
  4. * All Rights Reserved.
  5. *
  6. */
  7. #ifndef GOYAP_H_
  8. #define GOYAP_H_
  9. #include <uapi/misc/habanalabs.h>
  10. #include "../common/habanalabs.h"
  11. #include "../include/common/hl_boot_if.h"
  12. #include "../include/goya/goya_packets.h"
  13. #include "../include/goya/goya.h"
  14. #include "../include/goya/goya_async_events.h"
  15. #include "../include/goya/goya_fw_if.h"
  16. #define NUMBER_OF_CMPLT_QUEUES 5
  17. #define NUMBER_OF_EXT_HW_QUEUES 5
  18. #define NUMBER_OF_CPU_HW_QUEUES 1
  19. #define NUMBER_OF_INT_HW_QUEUES 9
  20. #define NUMBER_OF_HW_QUEUES (NUMBER_OF_EXT_HW_QUEUES + \
  21. NUMBER_OF_CPU_HW_QUEUES + \
  22. NUMBER_OF_INT_HW_QUEUES)
  23. /*
  24. * Number of MSIX interrupts IDS:
  25. * Each completion queue has 1 ID
  26. * The event queue has 1 ID
  27. */
  28. #define NUMBER_OF_INTERRUPTS (NUMBER_OF_CMPLT_QUEUES + 1)
  29. #if (NUMBER_OF_INTERRUPTS > GOYA_MSIX_ENTRIES)
  30. #error "Number of MSIX interrupts must be smaller or equal to GOYA_MSIX_ENTRIES"
  31. #endif
  32. #define QMAN_FENCE_TIMEOUT_USEC 10000 /* 10 ms */
  33. #define QMAN_STOP_TIMEOUT_USEC 100000 /* 100 ms */
  34. #define CORESIGHT_TIMEOUT_USEC 100000 /* 100 ms */
  35. #define GOYA_CPU_TIMEOUT_USEC 15000000 /* 15s */
  36. #define TPC_ENABLED_MASK 0xFF
  37. #define PLL_HIGH_DEFAULT 1575000000 /* 1.575 GHz */
  38. #define MAX_POWER_DEFAULT 200000 /* 200W */
  39. #define DC_POWER_DEFAULT 20000 /* 20W */
  40. #define DRAM_PHYS_DEFAULT_SIZE 0x100000000ull /* 4GB */
  41. #define GOYA_DEFAULT_CARD_NAME "HL1000"
  42. #define GOYA_MAX_PENDING_CS 64
  43. #if !IS_MAX_PENDING_CS_VALID(GOYA_MAX_PENDING_CS)
  44. #error "GOYA_MAX_PENDING_CS must be power of 2 and greater than 1"
  45. #endif
  46. /* DRAM Memory Map */
  47. #define CPU_FW_IMAGE_SIZE 0x10000000 /* 256MB */
  48. #define MMU_PAGE_TABLES_SIZE 0x0FC00000 /* 252MB */
  49. #define MMU_DRAM_DEFAULT_PAGE_SIZE 0x00200000 /* 2MB */
  50. #define MMU_CACHE_MNG_SIZE 0x00001000 /* 4KB */
  51. #define CPU_FW_IMAGE_ADDR DRAM_PHYS_BASE
  52. #define MMU_PAGE_TABLES_ADDR (CPU_FW_IMAGE_ADDR + CPU_FW_IMAGE_SIZE)
  53. #define MMU_DRAM_DEFAULT_PAGE_ADDR (MMU_PAGE_TABLES_ADDR + \
  54. MMU_PAGE_TABLES_SIZE)
  55. #define MMU_CACHE_MNG_ADDR (MMU_DRAM_DEFAULT_PAGE_ADDR + \
  56. MMU_DRAM_DEFAULT_PAGE_SIZE)
  57. #define DRAM_DRIVER_END_ADDR (MMU_CACHE_MNG_ADDR + \
  58. MMU_CACHE_MNG_SIZE)
  59. #define DRAM_BASE_ADDR_USER 0x20000000
  60. #if (DRAM_DRIVER_END_ADDR > DRAM_BASE_ADDR_USER)
  61. #error "Driver must reserve no more than 512MB"
  62. #endif
  63. /*
  64. * SRAM Memory Map for Driver
  65. *
  66. * Driver occupies DRIVER_SRAM_SIZE bytes from the start of SRAM. It is used for
  67. * MME/TPC QMANs
  68. *
  69. */
  70. #define MME_QMAN_BASE_OFFSET 0x000000 /* Must be 0 */
  71. #define MME_QMAN_LENGTH 64
  72. #define TPC_QMAN_LENGTH 64
  73. #define TPC0_QMAN_BASE_OFFSET (MME_QMAN_BASE_OFFSET + \
  74. (MME_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE))
  75. #define TPC1_QMAN_BASE_OFFSET (TPC0_QMAN_BASE_OFFSET + \
  76. (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE))
  77. #define TPC2_QMAN_BASE_OFFSET (TPC1_QMAN_BASE_OFFSET + \
  78. (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE))
  79. #define TPC3_QMAN_BASE_OFFSET (TPC2_QMAN_BASE_OFFSET + \
  80. (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE))
  81. #define TPC4_QMAN_BASE_OFFSET (TPC3_QMAN_BASE_OFFSET + \
  82. (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE))
  83. #define TPC5_QMAN_BASE_OFFSET (TPC4_QMAN_BASE_OFFSET + \
  84. (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE))
  85. #define TPC6_QMAN_BASE_OFFSET (TPC5_QMAN_BASE_OFFSET + \
  86. (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE))
  87. #define TPC7_QMAN_BASE_OFFSET (TPC6_QMAN_BASE_OFFSET + \
  88. (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE))
  89. #define SRAM_DRIVER_RES_OFFSET (TPC7_QMAN_BASE_OFFSET + \
  90. (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE))
  91. #if (SRAM_DRIVER_RES_OFFSET >= GOYA_KMD_SRAM_RESERVED_SIZE_FROM_START)
  92. #error "MME/TPC QMANs SRAM space exceeds limit"
  93. #endif
  94. #define SRAM_USER_BASE_OFFSET GOYA_KMD_SRAM_RESERVED_SIZE_FROM_START
  95. /* Virtual address space */
  96. #define VA_HOST_SPACE_START 0x1000000000000ull /* 256TB */
  97. #define VA_HOST_SPACE_END 0x3FF8000000000ull /* 1PB - 1TB */
  98. #define VA_HOST_SPACE_SIZE (VA_HOST_SPACE_END - \
  99. VA_HOST_SPACE_START) /* 767TB */
  100. #define VA_DDR_SPACE_START 0x800000000ull /* 32GB */
  101. #define VA_DDR_SPACE_END 0x2000000000ull /* 128GB */
  102. #define VA_DDR_SPACE_SIZE (VA_DDR_SPACE_END - \
  103. VA_DDR_SPACE_START) /* 128GB */
  104. #if (HL_CPU_ACCESSIBLE_MEM_SIZE != SZ_2M)
  105. #error "HL_CPU_ACCESSIBLE_MEM_SIZE must be exactly 2MB to enable MMU mapping"
  106. #endif
  107. #define VA_CPU_ACCESSIBLE_MEM_ADDR 0x8000000000ull
  108. #define DMA_MAX_TRANSFER_SIZE U32_MAX
  109. #define HW_CAP_PLL 0x00000001
  110. #define HW_CAP_DDR_0 0x00000002
  111. #define HW_CAP_DDR_1 0x00000004
  112. #define HW_CAP_MME 0x00000008
  113. #define HW_CAP_CPU 0x00000010
  114. #define HW_CAP_DMA 0x00000020
  115. #define HW_CAP_MSIX 0x00000040
  116. #define HW_CAP_CPU_Q 0x00000080
  117. #define HW_CAP_MMU 0x00000100
  118. #define HW_CAP_TPC_MBIST 0x00000200
  119. #define HW_CAP_GOLDEN 0x00000400
  120. #define HW_CAP_TPC 0x00000800
  121. struct goya_work_freq {
  122. struct hl_device *hdev;
  123. struct delayed_work work_freq;
  124. };
  125. struct goya_device {
  126. /* TODO: remove hw_queues_lock after moving to scheduler code */
  127. spinlock_t hw_queues_lock;
  128. struct goya_work_freq *goya_work;
  129. u64 mme_clk;
  130. u64 tpc_clk;
  131. u64 ic_clk;
  132. u64 ddr_bar_cur_addr;
  133. u32 events_stat[GOYA_ASYNC_EVENT_ID_SIZE];
  134. u32 events_stat_aggregate[GOYA_ASYNC_EVENT_ID_SIZE];
  135. u32 hw_cap_initialized;
  136. u8 device_cpu_mmu_mappings_done;
  137. enum hl_pll_frequency curr_pll_profile;
  138. enum hl_pm_mng_profile pm_mng_profile;
  139. };
  140. int goya_set_fixed_properties(struct hl_device *hdev);
  141. int goya_mmu_init(struct hl_device *hdev);
  142. void goya_init_dma_qmans(struct hl_device *hdev);
  143. void goya_init_mme_qmans(struct hl_device *hdev);
  144. void goya_init_tpc_qmans(struct hl_device *hdev);
  145. int goya_init_cpu_queues(struct hl_device *hdev);
  146. void goya_init_security(struct hl_device *hdev);
  147. void goya_ack_protection_bits_errors(struct hl_device *hdev);
  148. int goya_late_init(struct hl_device *hdev);
  149. void goya_late_fini(struct hl_device *hdev);
  150. void goya_ring_doorbell(struct hl_device *hdev, u32 hw_queue_id, u32 pi);
  151. void goya_pqe_write(struct hl_device *hdev, __le64 *pqe, struct hl_bd *bd);
  152. void goya_update_eq_ci(struct hl_device *hdev, u32 val);
  153. void goya_restore_phase_topology(struct hl_device *hdev);
  154. int goya_context_switch(struct hl_device *hdev, u32 asid);
  155. int goya_debugfs_i2c_read(struct hl_device *hdev, u8 i2c_bus,
  156. u8 i2c_addr, u8 i2c_reg, u32 *val);
  157. int goya_debugfs_i2c_write(struct hl_device *hdev, u8 i2c_bus,
  158. u8 i2c_addr, u8 i2c_reg, u32 val);
  159. void goya_debugfs_led_set(struct hl_device *hdev, u8 led, u8 state);
  160. int goya_test_queue(struct hl_device *hdev, u32 hw_queue_id);
  161. int goya_test_queues(struct hl_device *hdev);
  162. int goya_test_cpu_queue(struct hl_device *hdev);
  163. int goya_send_cpu_message(struct hl_device *hdev, u32 *msg, u16 len,
  164. u32 timeout, u64 *result);
  165. long goya_get_temperature(struct hl_device *hdev, int sensor_index, u32 attr);
  166. long goya_get_voltage(struct hl_device *hdev, int sensor_index, u32 attr);
  167. long goya_get_current(struct hl_device *hdev, int sensor_index, u32 attr);
  168. long goya_get_fan_speed(struct hl_device *hdev, int sensor_index, u32 attr);
  169. long goya_get_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr);
  170. void goya_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr,
  171. long value);
  172. u64 goya_get_max_power(struct hl_device *hdev);
  173. void goya_set_max_power(struct hl_device *hdev, u64 value);
  174. void goya_set_pll_profile(struct hl_device *hdev, enum hl_pll_frequency freq);
  175. void goya_add_device_attr(struct hl_device *hdev, struct attribute_group *dev_clk_attr_grp,
  176. struct attribute_group *dev_vrm_attr_grp);
  177. int goya_cpucp_info_get(struct hl_device *hdev);
  178. int goya_debug_coresight(struct hl_device *hdev, struct hl_ctx *ctx, void *data);
  179. void goya_halt_coresight(struct hl_device *hdev, struct hl_ctx *ctx);
  180. int goya_suspend(struct hl_device *hdev);
  181. int goya_resume(struct hl_device *hdev);
  182. void goya_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entry);
  183. void *goya_get_events_stat(struct hl_device *hdev, bool aggregate, u32 *size);
  184. void goya_add_end_of_cb_packets(struct hl_device *hdev, void *kernel_address,
  185. u32 len, u32 original_len, u64 cq_addr, u32 cq_val,
  186. u32 msix_vec, bool eb);
  187. int goya_cs_parser(struct hl_device *hdev, struct hl_cs_parser *parser);
  188. int goya_scrub_device_mem(struct hl_device *hdev);
  189. void *goya_get_int_queue_base(struct hl_device *hdev, u32 queue_id,
  190. dma_addr_t *dma_handle, u16 *queue_len);
  191. u32 goya_get_dma_desc_list_size(struct hl_device *hdev, struct sg_table *sgt);
  192. int goya_send_heartbeat(struct hl_device *hdev);
  193. void *goya_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size,
  194. dma_addr_t *dma_handle);
  195. void goya_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
  196. void *vaddr);
  197. void goya_mmu_remove_device_cpu_mappings(struct hl_device *hdev);
  198. u32 goya_get_queue_id_for_cq(struct hl_device *hdev, u32 cq_idx);
  199. u64 goya_get_device_time(struct hl_device *hdev);
  200. int goya_set_frequency(struct hl_device *hdev, enum hl_pll_frequency freq);
  201. #endif /* GOYAP_H_ */