vdi.h 7.9 KB

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