📄 ipu_base.cpp
字号:
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2005, Motorola Inc. All Rights Reserved
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2005, Freescale Semiconductor, Inc. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// Freescale Semiconductor, Inc.
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include <ceddk.h>
#include <cmnintrin.h>
#include <NKIntr.h>
#include "mxarm11.h"
#include "Ipu.h"
//------------------------------------------------------------------------------
// External Functions
extern "C" DWORD IPUGetIRQ();
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
// Defines
// Macros for generating 64-bit IRQ masks
#define IPU_INTMASK(intr) (((ULONG) 1) << intr)
// Masks for IPU submodule interrupt groups
#define PRP_ENC_DMA_CHA_MASK IPU_INTMASK(IPU_INT_DMAIC_0)
#define PRP_VF_DMA_CHA_MASK IPU_INTMASK(IPU_INT_DMAIC_1) | IPU_INTMASK(IPU_INT_DMAIC_3)
#define PRP_ENC_ROT_DMA_CHA_MASK IPU_INTMASK(IPU_INT_DMAIC_8) | IPU_INTMASK(IPU_INT_DMAIC_10)
#define PRP_VF_ROT_DMA_CHA_MASK IPU_INTMASK(IPU_INT_DMAIC_9) | IPU_INTMASK(IPU_INT_DMAIC_11)
#define PP_DMA_CHA_MASK IPU_INTMASK(IPU_INT_DMAIC_2) | IPU_INTMASK(IPU_INT_DMAIC_4) | \
IPU_INTMASK(IPU_INT_DMAIC_5)
#define PP_ROT_DMA_CHA_MASK IPU_INTMASK(IPU_INT_DMAIC_12) | IPU_INTMASK(IPU_INT_DMAIC_13)
#define SDC_BG_DMA_CHA_MASK IPU_INTMASK(IPU_INT_DMASDC_0)
#define SDC_FG_DMA_CHA_MASK IPU_INTMASK(IPU_INT_DMASDC_1)
#define ADC_DMA_CHA_MASK IPU_INTMASK(IPU_INT_DMAADC_2) | IPU_INTMASK(IPU_INT_DMAADC_3) | \
IPU_INTMASK(IPU_INT_DMAADC_4) | IPU_INTMASK(IPU_INT_DMAADC_5) | \
IPU_INTMASK(IPU_INT_DMAADC_6) | IPU_INTMASK(IPU_INT_DMAADC_7)
#define PF_DMA_CHA_MASK IPU_INTMASK(IPU_INT_DMAPF_0) | IPU_INTMASK(IPU_INT_DMAPF_1) | \
IPU_INTMASK(IPU_INT_DMAPF_2) | IPU_INTMASK(IPU_INT_DMAPF_3) | \
IPU_INTMASK(IPU_INT_DMAPF_4) | IPU_INTMASK(IPU_INT_DMAPF_5) | \
IPU_INTMASK(IPU_INT_DMAPF_6) | IPU_INTMASK(IPU_INT_DMAPF_7)
#define IPU_FUNCTION_ENTRY() \
DEBUGMSG(ZONE_FUNCTION, (TEXT("++%s\r\n"), __WFUNCTION__))
#define IPU_FUNCTION_EXIT() \
DEBUGMSG(ZONE_FUNCTION, (TEXT("--%s\r\n"), __WFUNCTION__))
#ifdef DEBUG
// Debug zone bit positions
#define ZONEID_ERROR 0
#define ZONEID_WARN 1
#define ZONEID_INIT 2
#define ZONEID_FUNCTION 3
#define ZONEID_INFO 4
// Debug zone masks
#define ZONEMASK_ERROR (1 << ZONEID_ERROR)
#define ZONEMASK_WARN (1 << ZONEID_WARN)
#define ZONEMASK_INIT (1 << ZONEID_INIT)
#define ZONEMASK_FUNCTION (1 << ZONEID_FUNCTION)
#define ZONEMASK_INFO (1 << ZONEID_INFO)
// Debug zone args to DEBUGMSG
#define ZONE_ERROR DEBUGZONE(ZONEID_ERROR)
#define ZONE_WARN DEBUGZONE(ZONEID_WARN)
#define ZONE_INIT DEBUGZONE(ZONEID_INIT)
#define ZONE_FUNCTION DEBUGZONE(ZONEID_FUNCTION)
#define ZONE_INFO DEBUGZONE(ZONEID_INFO)
DBGPARAM dpCurSettings = {
_T("IPU"),
{
TEXT("Errors"), TEXT("Warnings"), TEXT("Init"), TEXT("Func"),
TEXT("Info"), TEXT(""), TEXT(""), TEXT(""),
TEXT(""),TEXT(""),TEXT(""),TEXT(""),
TEXT(""),TEXT(""),TEXT(""),TEXT("")
},
ZONEMASK_ERROR | ZONEMASK_WARN // ulZoneMask
};
#endif // DEBUG
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
PCSP_IPU_REGS g_pIPU;
HANDLE g_hIpuIntrEvent;
HANDLE g_hPrpIntrEvent;
HANDLE g_hPpIntrEvent;
HANDLE g_hPfIntrEvent;
HANDLE g_hSDCBGIntrEvent;
HANDLE g_hSDCFGIntrEvent;
HANDLE g_hADCIntrEvent;
DWORD g_ipuIntr;
HANDLE g_hIpuISRThread;
static HANDLE g_phIntrHdlr[IPU_INT_MAX_ID];
static DWORD g_pIntrGroupMask[IPU_INT_MAX_ID];
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
// Local Functions
static BOOL InitIPU(void);
static void DeinitIPU(void);
static BOOL IpuAlloc(void);
static void IpuDealloc(void);
static BOOL IpuIntrInit(void);
static void IpuIntrThread(LPVOID);
static void IpuISRLoop(UINT32);
//-----------------------------------------------------------------------------
//
// Function: DllEntry
//
// This is the entry and exit point for the IPU common module. This
// function is called when processed and threads attach and detach from this
// module.
//
// Parameters:
// hInstDll
// [in] The handle to this module.
//
// dwReason
// [in] Specifies a flag indicating why the DLL entry-point function
// is being called.
//
// lpvReserved
// [in] Specifies further aspects of DLL initialization and cleanup.
//
// Returns:
// TRUE if the PMIC is initialized; FALSE if an error occurred during
// initialization.
//
//-----------------------------------------------------------------------------
BOOL WINAPI IPU_Base_DllEntry(HANDLE hInstDll, DWORD dwReason, LPVOID lpvReserved)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
DEBUGREGISTER((HMODULE)hInstDll);
DEBUGMSG(ZONE_INIT, (_T("***** DLL PROCESS ATTACH TO PMIC DLL *****\r\n")));
DisableThreadLibraryCalls((HMODULE) hInstDll);
break;
case DLL_PROCESS_DETACH:
break;
}
// return TRUE for success
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: Init
//
// This function initializes the IPU Base common component. Called by the
// Device Manager to initialize a device.
//
// Parameters:
// None.
//
// Returns:
// Returns TRUE if successful, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL Init(void)
{
BOOL rc = FALSE;
if (!InitIPU())
{
DEBUGMSG(ZONE_INIT, (_T("InitIPU failed!")));
goto cleanUp;
}
rc = TRUE;
cleanUp:
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: Deinit
//
// This function deinitializes the IPU Base common component. Called by the
// Device Manager to de-initialize a device.
//
// Parameters:
// None.
//
// Returns:
// Returns TRUE.
//
//-----------------------------------------------------------------------------
BOOL Deinit(void)
{
DeinitIPU();
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: InitIPU
//
// This function initializes common IPU components.
//
// Parameters:
// none.
//
// Returns:
// none.
//------------------------------------------------------------------------------
static BOOL InitIPU(void)
{
IPU_FUNCTION_ENTRY();
// Allocate IPU driver data structures.
if (!IpuAlloc())
{
DEBUGMSG(ZONE_ERROR, (_T("IPU common Init: Allocation failed!\r\n")));
}
// Initialize IPU interrupt, sub-module events, and interrupt masks
if (!IpuIntrInit())
{
DEBUGMSG(ZONE_ERROR,(TEXT("%s: Interrupt initialization failed!\r\n"), __WFUNCTION__));
goto Error;
}
// Initialize thread for IPU Interrupt Handling ISR
// pThreadAttributes = NULL (must be NULL)
// dwStackSize = 0 => default stack size determined by linker
// lpStartAddress = CspiProcessQueue => thread entry point
// lpParameter = NULL => point to thread parameter
// dwCreationFlags = 0 => no flags
// lpThreadId = NULL => thread ID is not returned
g_hIpuISRThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)IpuIntrThread, NULL, 0, NULL);
if (g_hIpuISRThread == NULL)
{
DEBUGMSG(ZONE_ERROR,(TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
goto Error;
}
else
{
DEBUGMSG(ZONE_INIT, (TEXT("%s: create IPU ISR thread success\r\n"), __WFUNCTION__));
CeSetThreadPriority(g_hIpuISRThread, 100);//THREAD_PRIORITY_TIME_CRITICAL);
}
// Initialize IMA_ADDR to 0, so that IPU submodule drivers can
// access the IMA registers.
OUTREG32(&g_pIPU->IPU_IMA_ADDR, 0);
return TRUE;
Error:
DeinitIPU();
return FALSE;
}
//------------------------------------------------------------------------------
//
// Function: DeinitIPU
//
// This function deinitializes PMIC subsystems.
//
// Parameters:
// none.
// Returns:
// none.
//------------------------------------------------------------------------------
static void DeinitIPU(void)
{
IPU_FUNCTION_ENTRY();
// Unmap IPU register pointer
IpuDealloc();
if (g_hIpuIntrEvent != NULL)
{
CloseHandle(g_hIpuIntrEvent);
g_hIpuIntrEvent = NULL;
}
CloseHandle(g_hPrpIntrEvent);
g_hPrpIntrEvent = NULL;
CloseHandle(g_hPpIntrEvent);
g_hPpIntrEvent = NULL;
if (g_hIpuISRThread)
{
TerminateThread(g_hIpuISRThread, 0);
CloseHandle(g_hIpuISRThread);
g_hIpuISRThread = NULL;
}
IPU_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: IpuAlloc
//
// This function allocates the data structures required for interaction
// with the IPU hardware.
//
// Parameters:
// None.
//
// Returns:
// Returns TRUE if successful, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
static BOOL IpuAlloc(void)
{
BOOL rc = FALSE;
PHYSICAL_ADDRESS phyAddr;
IPU_FUNCTION_ENTRY();
if (g_pIPU == NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -