vdi.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. #include "mm.h"
  28. #include "vpuconfig.h"
  29. #include "vputypes.h"
  30. /************************************************************************/
  31. /* COMMON REGISTERS */
  32. /************************************************************************/
  33. #define VPU_PRODUCT_NAME_REGISTER 0x1040
  34. #define VPU_PRODUCT_CODE_REGISTER 0x1044
  35. #define SUPPORT_MULTI_CORE_IN_ONE_DRIVER
  36. #define MAX_VPU_CORE_NUM MAX_NUM_VPU_CORE
  37. #define MAX_VPU_BUFFER_POOL 1000
  38. #define VpuWriteReg( CORE, ADDR, DATA ) vdi_write_register( CORE, ADDR, DATA ) // system register write
  39. #define VpuReadReg( CORE, ADDR ) vdi_read_register( CORE, ADDR ) // system register read
  40. #define VpuWriteMem( CORE, ADDR, DATA, LEN, ENDIAN ) vdi_write_memory( CORE, ADDR, DATA, LEN, ENDIAN ) // system memory write
  41. #define VpuReadMem( CORE, ADDR, DATA, LEN, ENDIAN ) vdi_read_memory( CORE, ADDR, DATA, LEN, ENDIAN ) // system memory read
  42. typedef struct vpu_buffer_t {
  43. Uint32 size;
  44. PhysicalAddress phys_addr;
  45. unsigned long base;
  46. unsigned long virt_addr;
  47. } vpu_buffer_t;
  48. typedef enum {
  49. VDI_LITTLE_ENDIAN = 0, /* 64bit LE */
  50. VDI_BIG_ENDIAN, /* 64bit BE */
  51. VDI_32BIT_LITTLE_ENDIAN,
  52. VDI_32BIT_BIG_ENDIAN,
  53. /* WAVE PRODUCTS */
  54. VDI_128BIT_LITTLE_ENDIAN = 16,
  55. VDI_128BIT_LE_BYTE_SWAP,
  56. VDI_128BIT_LE_WORD_SWAP,
  57. VDI_128BIT_LE_WORD_BYTE_SWAP,
  58. VDI_128BIT_LE_DWORD_SWAP,
  59. VDI_128BIT_LE_DWORD_BYTE_SWAP,
  60. VDI_128BIT_LE_DWORD_WORD_SWAP,
  61. VDI_128BIT_LE_DWORD_WORD_BYTE_SWAP,
  62. VDI_128BIT_BE_DWORD_WORD_BYTE_SWAP,
  63. VDI_128BIT_BE_DWORD_WORD_SWAP,
  64. VDI_128BIT_BE_DWORD_BYTE_SWAP,
  65. VDI_128BIT_BE_DWORD_SWAP,
  66. VDI_128BIT_BE_WORD_BYTE_SWAP,
  67. VDI_128BIT_BE_WORD_SWAP,
  68. VDI_128BIT_BE_BYTE_SWAP,
  69. VDI_128BIT_BIG_ENDIAN = 31,
  70. VDI_ENDIAN_MAX
  71. } EndianMode;
  72. #define VDI_128BIT_ENDIAN_MASK 0xf
  73. typedef struct vpu_instance_pool_t {
  74. 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.
  75. vpu_buffer_t vpu_common_buffer;
  76. int vpu_instance_num;
  77. int instance_pool_inited;
  78. void* pendingInst;
  79. int pendingInstIdxPlus1;
  80. Uint32 lastPerformanceCycles;
  81. video_mm_t vmem;
  82. } vpu_instance_pool_t;
  83. #if defined (__cplusplus)
  84. extern "C" {
  85. #endif
  86. int vdi_probe(unsigned long core_idx);
  87. int vdi_init(unsigned long core_idx);
  88. int vdi_release(unsigned long core_idx); //this function may be called only at system off.
  89. vpu_instance_pool_t * vdi_get_instance_pool(unsigned long core_idx);
  90. int vdi_allocate_common_memory(unsigned long core_idx);
  91. int vdi_get_common_memory(unsigned long core_idx, vpu_buffer_t *vb);
  92. int vdi_allocate_dma_memory(unsigned long core_idx, vpu_buffer_t *vb, int memTypes, int instIndex);
  93. int vdi_attach_dma_memory(unsigned long core_idx, vpu_buffer_t *vb);
  94. void vdi_free_dma_memory(unsigned long core_idx, vpu_buffer_t *vb, int memTypes, int instIndex);
  95. int vdi_get_sram_memory(unsigned long core_idx, vpu_buffer_t *vb);
  96. int vdi_dettach_dma_memory(unsigned long core_idx, vpu_buffer_t *vb);
  97. #ifdef SUPPORT_MULTI_INST_INTR
  98. int vdi_wait_interrupt(unsigned long coreIdx, unsigned int instIdx, int timeout);
  99. #else
  100. int vdi_wait_interrupt(unsigned long core_idx, int timeout);
  101. #endif
  102. int vdi_wait_vpu_busy(unsigned long core_idx, int timeout, unsigned int addr_bit_busy_flag);
  103. int vdi_wait_vcpu_bus_busy(unsigned long core_idx, int timeout, unsigned int addr_bit_busy_flag);
  104. int vdi_wait_bus_busy(unsigned long core_idx, int timeout, unsigned int gdi_busy_flag);
  105. int vdi_hw_reset(unsigned long core_idx);
  106. int vdi_set_clock_gate(unsigned long core_idx, int enable);
  107. int vdi_get_clock_gate(unsigned long core_idx);
  108. /**
  109. * @brief make clock stable before changing clock frequency
  110. * @detail Before inoking vdi_set_clock_freg() caller MUST invoke vdi_ready_change_clock() function.
  111. * after changing clock frequency caller also invoke vdi_done_change_clock() function.
  112. * @return 0 failure
  113. * 1 success
  114. */
  115. int vdi_ready_change_clock(unsigned long core_idx);
  116. int vdi_set_change_clock(unsigned long core_idx, unsigned long clock_mask);
  117. int vdi_done_change_clock(unsigned long core_idx);
  118. int vdi_get_instance_num(unsigned long core_idx);
  119. void vdi_write_register(unsigned long core_idx, unsigned int addr, unsigned int data);
  120. unsigned int vdi_read_register(unsigned long core_idx, unsigned int addr);
  121. void vdi_fio_write_register(unsigned long core_idx, unsigned int addr, unsigned int data);
  122. unsigned int vdi_fio_read_register(unsigned long core_idx, unsigned int addr);
  123. int vdi_clear_memory(unsigned long core_idx, PhysicalAddress addr, int len, int endian);
  124. int vdi_write_memory(unsigned long core_idx, PhysicalAddress addr, unsigned char *data, int len, int endian);
  125. int vdi_read_memory(unsigned long core_idx, PhysicalAddress addr, unsigned char *data, int len, int endian);
  126. int vdi_virt_to_phys(unsigned long core_idx, vpu_buffer_t *vb);
  127. int vdi_lock(unsigned long core_idx);
  128. void vdi_unlock(unsigned long core_idx);
  129. int vdi_disp_lock(unsigned long core_idx);
  130. void vdi_disp_unlock(unsigned long core_idx);
  131. int vdi_open_instance(unsigned long core_idx, unsigned long inst_idx);
  132. int vdi_close_instance(unsigned long core_idx, unsigned long inst_idx);
  133. int vdi_set_bit_firmware_to_pm(unsigned long core_idx, const unsigned short *code);
  134. int vdi_get_system_endian(unsigned long core_idx);
  135. int vdi_convert_endian(unsigned long core_idx, unsigned int endian);
  136. void vdi_flush_ddr(unsigned long core_idx,unsigned long start,unsigned long size,unsigned char flag);
  137. #if defined(SUPPORT_SW_UART) || defined(SUPPORT_SW_UART_V2)
  138. int vdi_get_task_num(unsigned long core_idx);
  139. #endif
  140. #if defined (__cplusplus)
  141. }
  142. #endif
  143. #endif //#ifndef _VDI_H_