vdi.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* SPDX-License-Identifier: LGPL-2.1 OR BSD-3-Clause */
  2. /*
  3. * Copyright (c) 2019, Chips&Media
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef _VDI_H_
  27. #define _VDI_H_
  28. #ifdef USE_FEEDING_METHOD_BUFFER
  29. #include "wave511/vdi/mm.h"
  30. #include "wave511/vpuapi/vpuconfig.h"
  31. #include "wave511/vpuapi/vputypes.h"
  32. #else
  33. #include "mm.h"
  34. #include "vpuconfig.h"
  35. #include "vputypes.h"
  36. #endif
  37. /************************************************************************/
  38. /* COMMON REGISTERS */
  39. /************************************************************************/
  40. #define VPU_PRODUCT_NAME_REGISTER 0x1040
  41. #define VPU_PRODUCT_CODE_REGISTER 0x1044
  42. #define SUPPORT_MULTI_CORE_IN_ONE_DRIVER
  43. #define MAX_VPU_CORE_NUM MAX_NUM_VPU_CORE
  44. #define MAX_VPU_BUFFER_POOL 1000
  45. #define VpuWriteReg( CORE, ADDR, DATA ) vdi_write_register( CORE, ADDR, DATA ) // system register write
  46. #define VpuReadReg( CORE, ADDR ) vdi_read_register( CORE, ADDR ) // system register read
  47. #define VpuWriteMem( CORE, ADDR, DATA, LEN, ENDIAN ) vdi_write_memory( CORE, ADDR, DATA, LEN, ENDIAN ) // system memory write
  48. #define VpuReadMem( CORE, ADDR, DATA, LEN, ENDIAN ) vdi_read_memory( CORE, ADDR, DATA, LEN, ENDIAN ) // system memory read
  49. typedef struct vpu_buffer_t {
  50. Uint32 size;
  51. PhysicalAddress phys_addr;
  52. unsigned long base;
  53. unsigned long virt_addr;
  54. } vpu_buffer_t;
  55. typedef enum {
  56. VDI_LITTLE_ENDIAN = 0, /* 64bit LE */
  57. VDI_BIG_ENDIAN, /* 64bit BE */
  58. VDI_32BIT_LITTLE_ENDIAN,
  59. VDI_32BIT_BIG_ENDIAN,
  60. /* WAVE PRODUCTS */
  61. VDI_128BIT_LITTLE_ENDIAN = 16,
  62. VDI_128BIT_LE_BYTE_SWAP,
  63. VDI_128BIT_LE_WORD_SWAP,
  64. VDI_128BIT_LE_WORD_BYTE_SWAP,
  65. VDI_128BIT_LE_DWORD_SWAP,
  66. VDI_128BIT_LE_DWORD_BYTE_SWAP,
  67. VDI_128BIT_LE_DWORD_WORD_SWAP,
  68. VDI_128BIT_LE_DWORD_WORD_BYTE_SWAP,
  69. VDI_128BIT_BE_DWORD_WORD_BYTE_SWAP,
  70. VDI_128BIT_BE_DWORD_WORD_SWAP,
  71. VDI_128BIT_BE_DWORD_BYTE_SWAP,
  72. VDI_128BIT_BE_DWORD_SWAP,
  73. VDI_128BIT_BE_WORD_BYTE_SWAP,
  74. VDI_128BIT_BE_WORD_SWAP,
  75. VDI_128BIT_BE_BYTE_SWAP,
  76. VDI_128BIT_BIG_ENDIAN = 31,
  77. VDI_ENDIAN_MAX
  78. } EndianMode;
  79. #define VDI_128BIT_ENDIAN_MASK 0xf
  80. typedef struct vpu_instance_pool_t {
  81. unsigned char codecInstPool[MAX_NUM_INSTANCE][MAX_INST_HANDLE_SIZE]; // Since VDI don't know the size of CodecInst structure, VDI should have the enough space not to overflow.
  82. vpu_buffer_t vpu_common_buffer;
  83. int vpu_instance_num;
  84. int instance_pool_inited;
  85. void* pendingInst;
  86. int pendingInstIdxPlus1;
  87. Uint32 lastPerformanceCycles;
  88. video_mm_t vmem;
  89. } vpu_instance_pool_t;
  90. #if defined (__cplusplus)
  91. extern "C" {
  92. #endif
  93. int vdi_probe(unsigned long core_idx);
  94. int vdi_init(unsigned long core_idx);
  95. int vdi_release(unsigned long core_idx); //this function may be called only at system off.
  96. vpu_instance_pool_t * vdi_get_instance_pool(unsigned long core_idx);
  97. int vdi_allocate_common_memory(unsigned long core_idx);
  98. int vdi_get_common_memory(unsigned long core_idx, vpu_buffer_t *vb);
  99. int vdi_allocate_dma_memory(unsigned long core_idx, vpu_buffer_t *vb, int memTypes, int instIndex);
  100. int vdi_attach_dma_memory(unsigned long core_idx, vpu_buffer_t *vb);
  101. void vdi_free_dma_memory(unsigned long core_idx, vpu_buffer_t *vb, int memTypes, int instIndex);
  102. int vdi_get_sram_memory(unsigned long core_idx, vpu_buffer_t *vb);
  103. int vdi_dettach_dma_memory(unsigned long core_idx, vpu_buffer_t *vb);
  104. void* vdi_map_virt2(unsigned long core_idx, int size, PhysicalAddress bufY);
  105. int vdi_virt_to_phys(unsigned long core_idx, vpu_buffer_t *vb);
  106. void* vdi_remap_vaddr(unsigned long coreIndex, unsigned long virtAddress, unsigned int size);
  107. #ifdef SUPPORT_MULTI_INST_INTR
  108. int vdi_wait_interrupt(unsigned long coreIdx, unsigned int instIdx, int timeout);
  109. #else
  110. int vdi_wait_interrupt(unsigned long core_idx, int timeout);
  111. #endif
  112. int vdi_wait_vpu_busy(unsigned long core_idx, int timeout, unsigned int addr_bit_busy_flag);
  113. int vdi_wait_vcpu_bus_busy(unsigned long core_idx, int timeout, unsigned int addr_bit_busy_flag);
  114. int vdi_wait_bus_busy(unsigned long core_idx, int timeout, unsigned int gdi_busy_flag);
  115. int vdi_hw_reset(unsigned long core_idx);
  116. int vdi_set_clock_gate(unsigned long core_idx, int enable);
  117. int vdi_get_clock_gate(unsigned long core_idx);
  118. /**
  119. * @brief make clock stable before changing clock frequency
  120. * @detail Before inoking vdi_set_clock_freg() caller MUST invoke vdi_ready_change_clock() function.
  121. * after changing clock frequency caller also invoke vdi_done_change_clock() function.
  122. * @return 0 failure
  123. * 1 success
  124. */
  125. int vdi_ready_change_clock(unsigned long core_idx);
  126. int vdi_set_change_clock(unsigned long core_idx, unsigned long clock_mask);
  127. int vdi_done_change_clock(unsigned long core_idx);
  128. int vdi_get_instance_num(unsigned long core_idx);
  129. void vdi_write_register(unsigned long core_idx, unsigned int addr, unsigned int data);
  130. unsigned int vdi_read_register(unsigned long core_idx, unsigned int addr);
  131. void vdi_fio_write_register(unsigned long core_idx, unsigned int addr, unsigned int data);
  132. unsigned int vdi_fio_read_register(unsigned long core_idx, unsigned int addr);
  133. int vdi_clear_memory(unsigned long core_idx, PhysicalAddress addr, int len, int endian);
  134. int vdi_write_memory(unsigned long core_idx, PhysicalAddress addr, unsigned char *data, int len, int endian);
  135. int vdi_read_memory(unsigned long core_idx, PhysicalAddress addr, unsigned char *data, int len, int endian);
  136. int vdi_read_memory2(unsigned long core_idx, PhysicalAddress addr, unsigned char **ppdata, int len, int endian);
  137. int vdi_lock(unsigned long core_idx);
  138. void vdi_unlock(unsigned long core_idx);
  139. int vdi_disp_lock(unsigned long core_idx);
  140. void vdi_disp_unlock(unsigned long core_idx);
  141. int vdi_open_instance(unsigned long core_idx, unsigned long inst_idx);
  142. int vdi_close_instance(unsigned long core_idx, unsigned long inst_idx);
  143. int vdi_set_bit_firmware_to_pm(unsigned long core_idx, const unsigned short *code);
  144. int vdi_get_system_endian(unsigned long core_idx);
  145. int vdi_convert_endian(unsigned long core_idx, unsigned int endian);
  146. void vdi_flush_ddr(unsigned long core_idx,unsigned long start,unsigned long size,unsigned char flag);
  147. #if defined(SUPPORT_SW_UART) || defined(SUPPORT_SW_UART_V2)
  148. int vdi_get_task_num(unsigned long core_idx);
  149. #endif
  150. void set_cpu_freq_fixed(void);
  151. void realese_cpu_freq_fixed(void);
  152. #if defined (__cplusplus)
  153. }
  154. #endif
  155. #endif //#ifndef _VDI_H_