avmem.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:6k
源码类别:

DVD

开发平台:

C/C++

  1. /*****************************************************************************
  2. File name   : avmem.c
  3. Description : AVMEM functions
  4. COPYRIGHT (C) 2004 STMicroelectronics
  5. *****************************************************************************/
  6. /* Includes --------------------------------------------------------------- */
  7. #include <string.h>
  8. #include "stdevice.h"
  9. #include "sttbx.h"
  10. #include "section.h"   /* memory partitions */
  11. #include "errors.h"
  12. #include "boot.h"
  13. #include "avmem.h"
  14. #include "fdma.h"
  15. /* Private Types ------------------------------------------------------ */
  16. /* Private Constants -------------------------------------------------- */
  17. #define AVMEM_MAX_BLOCKS    100
  18. #define AVMEM_FORB_RANGES   2
  19. /* Private Variables -------------------------------------------------- */
  20. void *Forbidden_Borders_p[KB_AVMEM_FORB_BORDERS] = {
  21. #if 0 //def MALY3
  22.     (void*)0xC0800000,
  23.     (void*)0xC0900000,
  24.     (void*)0xC0A00000,
  25.     (void*)0xC0B00000,
  26.     (void*)0xC0C00000,
  27.     (void*)0xC0D00000
  28. #else
  29.     (void*)0xC0800000,
  30.     (void*)0xC0900000,
  31.     (void*)0xC0A00000,
  32.     (void*)0xC0B00000,
  33.     (void*)0xC0C00000,
  34.     (void*)0xC0D00000,
  35.     (void*)0xC0E00000,
  36.     (void*)0xC0F00000,
  37.     (void*)0xC1A00000,
  38.     (void*)0xC1B00000
  39. #endif
  40.     };
  41. /* Private Macros ----------------------------------------------------- */
  42. #ifndef BM_BASE_ADDRESS
  43.   #define BM_BASE_ADDRESS 0
  44. #endif
  45. /* Private Function prototypes ---------------------------------------- */
  46. /* Functions ---------------------------------------------------------- */
  47. /* Global ----------------------------------------------------------------- */
  48. ST_DeviceName_t           AVMEM_DeviceName = "AVMEM";
  49. STAVMEM_PartitionHandle_t g_KBAvmemPartitionHandle[KB_AVMEM_MAX_PARTITIONS];
  50. /* Functions -------------------------------------------------------------- */
  51. /*
  52.   1 bits buffer   (Video)
  53.   4 frame buffers (Video)
  54.   2 dest buffer   (Video tests)
  55.   1 bits buffer   (Audio)
  56.  ---
  57.   8 (MaxBlocks rounded to 10) */
  58. /*-------------------------------------------------------------------------
  59.  * Function : KB_AVMEMSetup
  60.  * Input    : None
  61.  * Output   :
  62.  * Return   : Error Code
  63.  * ----------------------------------------------------------------------*/
  64. ST_ErrorCode_t KB_AVMEMSetup(void)
  65. {
  66.     ST_ErrorCode_t                       ST_ErrorCode;
  67.     U32 instance;
  68.     STAVMEM_InitParams_t                 STAVMEM_InitParams;
  69.     STAVMEM_SharedMemoryVirtualMapping_t VirtualMapping;
  70.     STAVMEM_MemoryRange_t                PartitionMapTable[KB_AVMEM_MAX_PARTITIONS];
  71.     STAVMEM_CreatePartitionParams_t      STAVMEM_CreatePartitionParams = { 0 }; /* dummy parameter */
  72.     PartitionMapTable[0].StartAddr_p = (void *) (AVMEM_BASE_ADDRESS);
  73.     PartitionMapTable[0].StopAddr_p  = (void *) (AVMEM_BASE_ADDRESS + AVMEM_SIZE -1);
  74.     #if (KB_AVMEM_MAX_PARTITIONS - 1)
  75.         PartitionMapTable[1].StartAddr_p = (void *) (NCACHE_BASE_ADDRESS);
  76.         PartitionMapTable[1].StopAddr_p  = (void *) (NCACHE_BASE_ADDRESS + NCACHE_SIZE -1);
  77.     #endif
  78.     if (KB_AVMEM_DEVICE_TYPE == STAVMEM_DEVICE_TYPE_VIRTUAL)
  79.     {
  80.         VirtualMapping.PhysicalAddressSeenFromCPU_p     = (void *)AVMEM_BASE_ADDRESS;
  81.         VirtualMapping.PhysicalAddressSeenFromDevice_p  = (void *)AVMEM_BASE_ADDRESS;
  82.         VirtualMapping.PhysicalAddressSeenFromDevice2_p = (void *)AVMEM_BASE_ADDRESS;
  83.         VirtualMapping.VirtualBaseAddress_p             = (void *)AVMEM_BASE_ADDRESS;
  84.         VirtualMapping.VirtualSize                      = AVMEM_SIZE;
  85.         VirtualMapping.VirtualWindowOffset              = 0;
  86.         VirtualMapping.VirtualWindowSize                = AVMEM_SIZE;
  87.     }
  88.     STAVMEM_InitParams.DeviceType                   = KB_AVMEM_DEVICE_TYPE;
  89.     STAVMEM_InitParams.MaxPartitions                = KB_AVMEM_MAX_PARTITIONS;
  90.     STAVMEM_InitParams.MaxNumberOfMemoryMapRanges   = KB_AVMEM_MAX_PARTITIONS;
  91.     /* because each partition has a single range here */
  92.     STAVMEM_InitParams.SharedMemoryVirtualMapping_p = &VirtualMapping;
  93.     STTBX_Print(("KB_AVMEMSetup(GENERIC,"));
  94.     STAVMEM_InitParams.CPUPartition_p               = SystemPartition;
  95.     STAVMEM_InitParams.NCachePartition_p            = NcachePartition;
  96.     STAVMEM_InitParams.MaxBlocks                    = AVMEM_MAX_BLOCKS;
  97.     STAVMEM_InitParams.MaxForbiddenRanges           = AVMEM_FORB_RANGES;
  98.     STAVMEM_InitParams.MaxForbiddenBorders          = KB_AVMEM_FORB_BORDERS;
  99.     STAVMEM_InitParams.OptimisedMemAccessStrategy_p = NULL;
  100.     STAVMEM_InitParams.BlockMoveDmaBaseAddr_p       = (void *)BM_BASE_ADDRESS;
  101.     STAVMEM_InitParams.VideoBaseAddr_p              = (void *)VIDEO_BASE_ADDRESS;
  102.     STAVMEM_InitParams.CacheBaseAddr_p              = (void *)CACHE_BASE_ADDRESS;
  103.     STAVMEM_InitParams.NumberOfDCachedRanges        = (sizeof( g_KBBOOTDCacheMap ) / sizeof(STBOOT_DCache_Area_t)) - 1;
  104.     STAVMEM_InitParams.DCachedRanges_p              = (STAVMEM_MemoryRange_t *)(g_KBBOOTDCacheMap);
  105.     STAVMEM_InitParams.SDRAMBaseAddr_p              = (void *)AVMEM_BASE_ADDRESS;
  106.     STAVMEM_InitParams.SDRAMSize                    = AVMEM_SIZE;
  107.     memset(STAVMEM_InitParams.GpdmaName, 0, sizeof(STAVMEM_InitParams.GpdmaName));
  108.     STTBX_Print(("%s)=", AVMEM_DeviceName ));
  109.     ST_ErrorCode = STAVMEM_Init(AVMEM_DeviceName, &STAVMEM_InitParams);
  110.     if (ST_ErrorCode != ST_NO_ERROR)
  111.     {
  112.         STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode) ));
  113.         return( ST_ErrorCode );
  114.     }
  115.     STTBX_Print(("%sn", STAVMEM_GetRevision() ));
  116.     for (instance=0; (instance < KB_AVMEM_MAX_PARTITIONS); instance++)
  117.     {
  118.         STAVMEM_CreatePartitionParams.NumberOfPartitionRanges=(sizeof(PartitionMapTable[instance])/sizeof(STAVMEM_MemoryRange_t));
  119.         STAVMEM_CreatePartitionParams.PartitionRanges_p       = &PartitionMapTable[instance];
  120.         ST_ErrorCode = STAVMEM_CreatePartition(AVMEM_DeviceName, &STAVMEM_CreatePartitionParams, &g_KBAvmemPartitionHandle[instance]);
  121.         STTBX_Print(("AVMEM_CreatePartition() #%d %sn", instance, KB_ErrorGetText(ST_ErrorCode)));
  122.     }
  123.     return( ST_ErrorCode );
  124. }
  125. /* EOF --------------------------------------------------------------------- */