18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci * 38c2ecf20Sopenharmony_ci * Copyright 2016-2019 HabanaLabs, Ltd. 48c2ecf20Sopenharmony_ci * All Rights Reserved. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef GOYAP_H_ 98c2ecf20Sopenharmony_ci#define GOYAP_H_ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <uapi/misc/habanalabs.h> 128c2ecf20Sopenharmony_ci#include "../common/habanalabs.h" 138c2ecf20Sopenharmony_ci#include "../include/common/hl_boot_if.h" 148c2ecf20Sopenharmony_ci#include "../include/goya/goya_packets.h" 158c2ecf20Sopenharmony_ci#include "../include/goya/goya.h" 168c2ecf20Sopenharmony_ci#include "../include/goya/goya_async_events.h" 178c2ecf20Sopenharmony_ci#include "../include/goya/goya_fw_if.h" 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define NUMBER_OF_CMPLT_QUEUES 5 208c2ecf20Sopenharmony_ci#define NUMBER_OF_EXT_HW_QUEUES 5 218c2ecf20Sopenharmony_ci#define NUMBER_OF_CPU_HW_QUEUES 1 228c2ecf20Sopenharmony_ci#define NUMBER_OF_INT_HW_QUEUES 9 238c2ecf20Sopenharmony_ci#define NUMBER_OF_HW_QUEUES (NUMBER_OF_EXT_HW_QUEUES + \ 248c2ecf20Sopenharmony_ci NUMBER_OF_CPU_HW_QUEUES + \ 258c2ecf20Sopenharmony_ci NUMBER_OF_INT_HW_QUEUES) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* 288c2ecf20Sopenharmony_ci * Number of MSIX interrupts IDS: 298c2ecf20Sopenharmony_ci * Each completion queue has 1 ID 308c2ecf20Sopenharmony_ci * The event queue has 1 ID 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci#define NUMBER_OF_INTERRUPTS (NUMBER_OF_CMPLT_QUEUES + 1) 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#if (NUMBER_OF_INTERRUPTS > GOYA_MSIX_ENTRIES) 358c2ecf20Sopenharmony_ci#error "Number of MSIX interrupts must be smaller or equal to GOYA_MSIX_ENTRIES" 368c2ecf20Sopenharmony_ci#endif 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define QMAN_FENCE_TIMEOUT_USEC 10000 /* 10 ms */ 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#define QMAN_STOP_TIMEOUT_USEC 100000 /* 100 ms */ 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define CORESIGHT_TIMEOUT_USEC 100000 /* 100 ms */ 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define GOYA_CPU_TIMEOUT_USEC 15000000 /* 15s */ 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define TPC_ENABLED_MASK 0xFF 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define PLL_HIGH_DEFAULT 1575000000 /* 1.575 GHz */ 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define MAX_POWER_DEFAULT 200000 /* 200W */ 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define DRAM_PHYS_DEFAULT_SIZE 0x100000000ull /* 4GB */ 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#define GOYA_DEFAULT_CARD_NAME "HL1000" 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define GOYA_MAX_PENDING_CS 64 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#if !IS_MAX_PENDING_CS_VALID(GOYA_MAX_PENDING_CS) 598c2ecf20Sopenharmony_ci#error "GOYA_MAX_PENDING_CS must be power of 2 and greater than 1" 608c2ecf20Sopenharmony_ci#endif 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/* DRAM Memory Map */ 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#define CPU_FW_IMAGE_SIZE 0x10000000 /* 256MB */ 658c2ecf20Sopenharmony_ci#define MMU_PAGE_TABLES_SIZE 0x0FC00000 /* 252MB */ 668c2ecf20Sopenharmony_ci#define MMU_DRAM_DEFAULT_PAGE_SIZE 0x00200000 /* 2MB */ 678c2ecf20Sopenharmony_ci#define MMU_CACHE_MNG_SIZE 0x00001000 /* 4KB */ 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#define CPU_FW_IMAGE_ADDR DRAM_PHYS_BASE 708c2ecf20Sopenharmony_ci#define MMU_PAGE_TABLES_ADDR (CPU_FW_IMAGE_ADDR + CPU_FW_IMAGE_SIZE) 718c2ecf20Sopenharmony_ci#define MMU_DRAM_DEFAULT_PAGE_ADDR (MMU_PAGE_TABLES_ADDR + \ 728c2ecf20Sopenharmony_ci MMU_PAGE_TABLES_SIZE) 738c2ecf20Sopenharmony_ci#define MMU_CACHE_MNG_ADDR (MMU_DRAM_DEFAULT_PAGE_ADDR + \ 748c2ecf20Sopenharmony_ci MMU_DRAM_DEFAULT_PAGE_SIZE) 758c2ecf20Sopenharmony_ci#define DRAM_DRIVER_END_ADDR (MMU_CACHE_MNG_ADDR + \ 768c2ecf20Sopenharmony_ci MMU_CACHE_MNG_SIZE) 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#define DRAM_BASE_ADDR_USER 0x20000000 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci#if (DRAM_DRIVER_END_ADDR > DRAM_BASE_ADDR_USER) 818c2ecf20Sopenharmony_ci#error "Driver must reserve no more than 512MB" 828c2ecf20Sopenharmony_ci#endif 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci/* 858c2ecf20Sopenharmony_ci * SRAM Memory Map for Driver 868c2ecf20Sopenharmony_ci * 878c2ecf20Sopenharmony_ci * Driver occupies DRIVER_SRAM_SIZE bytes from the start of SRAM. It is used for 888c2ecf20Sopenharmony_ci * MME/TPC QMANs 898c2ecf20Sopenharmony_ci * 908c2ecf20Sopenharmony_ci */ 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci#define MME_QMAN_BASE_OFFSET 0x000000 /* Must be 0 */ 938c2ecf20Sopenharmony_ci#define MME_QMAN_LENGTH 64 948c2ecf20Sopenharmony_ci#define TPC_QMAN_LENGTH 64 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci#define TPC0_QMAN_BASE_OFFSET (MME_QMAN_BASE_OFFSET + \ 978c2ecf20Sopenharmony_ci (MME_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) 988c2ecf20Sopenharmony_ci#define TPC1_QMAN_BASE_OFFSET (TPC0_QMAN_BASE_OFFSET + \ 998c2ecf20Sopenharmony_ci (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) 1008c2ecf20Sopenharmony_ci#define TPC2_QMAN_BASE_OFFSET (TPC1_QMAN_BASE_OFFSET + \ 1018c2ecf20Sopenharmony_ci (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) 1028c2ecf20Sopenharmony_ci#define TPC3_QMAN_BASE_OFFSET (TPC2_QMAN_BASE_OFFSET + \ 1038c2ecf20Sopenharmony_ci (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) 1048c2ecf20Sopenharmony_ci#define TPC4_QMAN_BASE_OFFSET (TPC3_QMAN_BASE_OFFSET + \ 1058c2ecf20Sopenharmony_ci (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) 1068c2ecf20Sopenharmony_ci#define TPC5_QMAN_BASE_OFFSET (TPC4_QMAN_BASE_OFFSET + \ 1078c2ecf20Sopenharmony_ci (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) 1088c2ecf20Sopenharmony_ci#define TPC6_QMAN_BASE_OFFSET (TPC5_QMAN_BASE_OFFSET + \ 1098c2ecf20Sopenharmony_ci (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) 1108c2ecf20Sopenharmony_ci#define TPC7_QMAN_BASE_OFFSET (TPC6_QMAN_BASE_OFFSET + \ 1118c2ecf20Sopenharmony_ci (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci#define SRAM_DRIVER_RES_OFFSET (TPC7_QMAN_BASE_OFFSET + \ 1148c2ecf20Sopenharmony_ci (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci#if (SRAM_DRIVER_RES_OFFSET >= GOYA_KMD_SRAM_RESERVED_SIZE_FROM_START) 1178c2ecf20Sopenharmony_ci#error "MME/TPC QMANs SRAM space exceeds limit" 1188c2ecf20Sopenharmony_ci#endif 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci#define SRAM_USER_BASE_OFFSET GOYA_KMD_SRAM_RESERVED_SIZE_FROM_START 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/* Virtual address space */ 1238c2ecf20Sopenharmony_ci#define VA_HOST_SPACE_START 0x1000000000000ull /* 256TB */ 1248c2ecf20Sopenharmony_ci#define VA_HOST_SPACE_END 0x3FF8000000000ull /* 1PB - 1TB */ 1258c2ecf20Sopenharmony_ci#define VA_HOST_SPACE_SIZE (VA_HOST_SPACE_END - \ 1268c2ecf20Sopenharmony_ci VA_HOST_SPACE_START) /* 767TB */ 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#define VA_DDR_SPACE_START 0x800000000ull /* 32GB */ 1298c2ecf20Sopenharmony_ci#define VA_DDR_SPACE_END 0x2000000000ull /* 128GB */ 1308c2ecf20Sopenharmony_ci#define VA_DDR_SPACE_SIZE (VA_DDR_SPACE_END - \ 1318c2ecf20Sopenharmony_ci VA_DDR_SPACE_START) /* 128GB */ 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#if (HL_CPU_ACCESSIBLE_MEM_SIZE != SZ_2M) 1348c2ecf20Sopenharmony_ci#error "HL_CPU_ACCESSIBLE_MEM_SIZE must be exactly 2MB to enable MMU mapping" 1358c2ecf20Sopenharmony_ci#endif 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci#define VA_CPU_ACCESSIBLE_MEM_ADDR 0x8000000000ull 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci#define DMA_MAX_TRANSFER_SIZE U32_MAX 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci#define HW_CAP_PLL 0x00000001 1428c2ecf20Sopenharmony_ci#define HW_CAP_DDR_0 0x00000002 1438c2ecf20Sopenharmony_ci#define HW_CAP_DDR_1 0x00000004 1448c2ecf20Sopenharmony_ci#define HW_CAP_MME 0x00000008 1458c2ecf20Sopenharmony_ci#define HW_CAP_CPU 0x00000010 1468c2ecf20Sopenharmony_ci#define HW_CAP_DMA 0x00000020 1478c2ecf20Sopenharmony_ci#define HW_CAP_MSIX 0x00000040 1488c2ecf20Sopenharmony_ci#define HW_CAP_CPU_Q 0x00000080 1498c2ecf20Sopenharmony_ci#define HW_CAP_MMU 0x00000100 1508c2ecf20Sopenharmony_ci#define HW_CAP_TPC_MBIST 0x00000200 1518c2ecf20Sopenharmony_ci#define HW_CAP_GOLDEN 0x00000400 1528c2ecf20Sopenharmony_ci#define HW_CAP_TPC 0x00000800 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistruct goya_device { 1558c2ecf20Sopenharmony_ci /* TODO: remove hw_queues_lock after moving to scheduler code */ 1568c2ecf20Sopenharmony_ci spinlock_t hw_queues_lock; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci u64 mme_clk; 1598c2ecf20Sopenharmony_ci u64 tpc_clk; 1608c2ecf20Sopenharmony_ci u64 ic_clk; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci u64 ddr_bar_cur_addr; 1638c2ecf20Sopenharmony_ci u32 events_stat[GOYA_ASYNC_EVENT_ID_SIZE]; 1648c2ecf20Sopenharmony_ci u32 events_stat_aggregate[GOYA_ASYNC_EVENT_ID_SIZE]; 1658c2ecf20Sopenharmony_ci u32 hw_cap_initialized; 1668c2ecf20Sopenharmony_ci u8 device_cpu_mmu_mappings_done; 1678c2ecf20Sopenharmony_ci}; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ciint goya_get_fixed_properties(struct hl_device *hdev); 1708c2ecf20Sopenharmony_ciint goya_mmu_init(struct hl_device *hdev); 1718c2ecf20Sopenharmony_civoid goya_init_dma_qmans(struct hl_device *hdev); 1728c2ecf20Sopenharmony_civoid goya_init_mme_qmans(struct hl_device *hdev); 1738c2ecf20Sopenharmony_civoid goya_init_tpc_qmans(struct hl_device *hdev); 1748c2ecf20Sopenharmony_ciint goya_init_cpu_queues(struct hl_device *hdev); 1758c2ecf20Sopenharmony_civoid goya_init_security(struct hl_device *hdev); 1768c2ecf20Sopenharmony_ciint goya_late_init(struct hl_device *hdev); 1778c2ecf20Sopenharmony_civoid goya_late_fini(struct hl_device *hdev); 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_civoid goya_ring_doorbell(struct hl_device *hdev, u32 hw_queue_id, u32 pi); 1808c2ecf20Sopenharmony_civoid goya_pqe_write(struct hl_device *hdev, __le64 *pqe, struct hl_bd *bd); 1818c2ecf20Sopenharmony_civoid goya_update_eq_ci(struct hl_device *hdev, u32 val); 1828c2ecf20Sopenharmony_civoid goya_restore_phase_topology(struct hl_device *hdev); 1838c2ecf20Sopenharmony_ciint goya_context_switch(struct hl_device *hdev, u32 asid); 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ciint goya_debugfs_i2c_read(struct hl_device *hdev, u8 i2c_bus, 1868c2ecf20Sopenharmony_ci u8 i2c_addr, u8 i2c_reg, u32 *val); 1878c2ecf20Sopenharmony_ciint goya_debugfs_i2c_write(struct hl_device *hdev, u8 i2c_bus, 1888c2ecf20Sopenharmony_ci u8 i2c_addr, u8 i2c_reg, u32 val); 1898c2ecf20Sopenharmony_civoid goya_debugfs_led_set(struct hl_device *hdev, u8 led, u8 state); 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ciint goya_test_queue(struct hl_device *hdev, u32 hw_queue_id); 1928c2ecf20Sopenharmony_ciint goya_test_queues(struct hl_device *hdev); 1938c2ecf20Sopenharmony_ciint goya_test_cpu_queue(struct hl_device *hdev); 1948c2ecf20Sopenharmony_ciint goya_send_cpu_message(struct hl_device *hdev, u32 *msg, u16 len, 1958c2ecf20Sopenharmony_ci u32 timeout, long *result); 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_cilong goya_get_temperature(struct hl_device *hdev, int sensor_index, u32 attr); 1988c2ecf20Sopenharmony_cilong goya_get_voltage(struct hl_device *hdev, int sensor_index, u32 attr); 1998c2ecf20Sopenharmony_cilong goya_get_current(struct hl_device *hdev, int sensor_index, u32 attr); 2008c2ecf20Sopenharmony_cilong goya_get_fan_speed(struct hl_device *hdev, int sensor_index, u32 attr); 2018c2ecf20Sopenharmony_cilong goya_get_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr); 2028c2ecf20Sopenharmony_civoid goya_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, 2038c2ecf20Sopenharmony_ci long value); 2048c2ecf20Sopenharmony_ciu64 goya_get_max_power(struct hl_device *hdev); 2058c2ecf20Sopenharmony_civoid goya_set_max_power(struct hl_device *hdev, u64 value); 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_civoid goya_set_pll_profile(struct hl_device *hdev, enum hl_pll_frequency freq); 2088c2ecf20Sopenharmony_civoid goya_add_device_attr(struct hl_device *hdev, 2098c2ecf20Sopenharmony_ci struct attribute_group *dev_attr_grp); 2108c2ecf20Sopenharmony_ciint goya_cpucp_info_get(struct hl_device *hdev); 2118c2ecf20Sopenharmony_ciint goya_debug_coresight(struct hl_device *hdev, void *data); 2128c2ecf20Sopenharmony_civoid goya_halt_coresight(struct hl_device *hdev); 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ciint goya_suspend(struct hl_device *hdev); 2158c2ecf20Sopenharmony_ciint goya_resume(struct hl_device *hdev); 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_civoid goya_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entry); 2188c2ecf20Sopenharmony_civoid *goya_get_events_stat(struct hl_device *hdev, bool aggregate, u32 *size); 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_civoid goya_add_end_of_cb_packets(struct hl_device *hdev, void *kernel_address, 2218c2ecf20Sopenharmony_ci u32 len, u64 cq_addr, u32 cq_val, u32 msix_vec, 2228c2ecf20Sopenharmony_ci bool eb); 2238c2ecf20Sopenharmony_ciint goya_cs_parser(struct hl_device *hdev, struct hl_cs_parser *parser); 2248c2ecf20Sopenharmony_civoid *goya_get_int_queue_base(struct hl_device *hdev, u32 queue_id, 2258c2ecf20Sopenharmony_ci dma_addr_t *dma_handle, u16 *queue_len); 2268c2ecf20Sopenharmony_ciu32 goya_get_dma_desc_list_size(struct hl_device *hdev, struct sg_table *sgt); 2278c2ecf20Sopenharmony_ciint goya_send_heartbeat(struct hl_device *hdev); 2288c2ecf20Sopenharmony_civoid *goya_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size, 2298c2ecf20Sopenharmony_ci dma_addr_t *dma_handle); 2308c2ecf20Sopenharmony_civoid goya_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size, 2318c2ecf20Sopenharmony_ci void *vaddr); 2328c2ecf20Sopenharmony_civoid goya_mmu_remove_device_cpu_mappings(struct hl_device *hdev); 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ciint goya_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk); 2358c2ecf20Sopenharmony_ciu32 goya_get_queue_id_for_cq(struct hl_device *hdev, u32 cq_idx); 2368c2ecf20Sopenharmony_ciu64 goya_get_device_time(struct hl_device *hdev); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci#endif /* GOYAP_H_ */ 239