📄 s3c2450disp.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.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 2007-2008. Samsung Electronics, co. ltd All rights reserved.
Module Name: s3c2450disp.cpp
Abstract: Main Display Driver Implementation. This driver can support directdraw(DDGPE)
Functions: DrvEscape, ...
Notes:
--*/
#include "precomp.h"
#include <nkintr.h>
#include <gxinfo.h>
#define DISPPERF_DECLARE
#include "dispperf.h"
INSTANTIATE_GPE_ZONES(0x3,"MGDI Driver","unused1","unused2") // Start with errors and warnings
DDGPE * gGPE = (DDGPE *)NULL;
// This prototype avoids problems exporting from .lib
BOOL
APIENTRY
GPEEnableDriver(
ULONG engineVersion,
ULONG cj,
DRVENABLEDATA * data,
PENGCALLBACKS engineCallbacks
);
BOOL
APIENTRY
DrvEnableDriver(
ULONG engineVersion,
ULONG cj,
DRVENABLEDATA * data,
PENGCALLBACKS engineCallbacks
)
{
return GPEEnableDriver(engineVersion, cj, data, engineCallbacks);
}
// this routine converts a string into a GUID and returns TRUE if the
// conversion was successful.
BOOL
ConvertStringToGuid (LPCTSTR pszGuid, GUID *pGuid)
{
UINT Data4[8];
int Count;
BOOL fOk = FALSE;
TCHAR *pszGuidFormat = _T("{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}");
DEBUGCHK(pGuid != NULL && pszGuid != NULL);
__try
{
if (_stscanf(pszGuid, pszGuidFormat, &pGuid->Data1,
&pGuid->Data2, &pGuid->Data3, &Data4[0], &Data4[1], &Data4[2], &Data4[3],
&Data4[4], &Data4[5], &Data4[6], &Data4[7]) == 11)
{
for(Count = 0; Count < (sizeof(Data4) / sizeof(Data4[0])); Count++)
{
pGuid->Data4[Count] = (UCHAR) Data4[Count];
}
}
fOk = TRUE;
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
return fOk;
}
// This routine notifies the OS that we support the Power Manager IOCTLs (through
// ExtEscape(), which calls DrvEscape()).
BOOL
AdvertisePowerInterface(HMODULE hInst)
{
BOOL fOk = FALSE;
HKEY hk;
DWORD dwStatus;
TCHAR szTemp[MAX_PATH];
GUID gClass;
// assume we are advertising the default class
fOk = ConvertStringToGuid(PMCLASS_DISPLAY, &gClass);
DEBUGCHK(fOk);
// check for an override in the registry
dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("System\\GDI\\Drivers"), 0, 0, &hk);
if(dwStatus == ERROR_SUCCESS)
{
DWORD dwType, dwSize;
dwSize = sizeof(szTemp);
dwStatus = RegQueryValueEx(hk, _T("DisplayPowerClass"), NULL, &dwType, (LPBYTE) szTemp, &dwSize);
szTemp[MAX_PATH-1] = 0;
if(dwStatus == ERROR_SUCCESS && dwType == REG_SZ)
{
// got a guid string, convert it to a guid
GUID gTemp;
fOk = ConvertStringToGuid(szTemp, &gTemp);
DEBUGCHK(fOk);
if(fOk)
{
gClass = gTemp;
}
}
// release the registry key
RegCloseKey(hk);
}
// figure out what device name to advertise
if(fOk)
{
fOk = GetModuleFileName(hInst, szTemp, sizeof(szTemp) / sizeof(szTemp[0]));
DEBUGCHK(fOk);
}
// now advertise the interface
if(fOk)
{
fOk = AdvertiseInterface(&gClass, szTemp, TRUE);
DEBUGCHK(fOk);
}
return fOk;
}
//
// Main entry point for a GPE-compliant driver
//
GPE *
GetGPE()
{
if (!gGPE)
{
gGPE = new S3C2450DISP();
}
return gGPE;
}
ULONG gBitMasks[] = { 0xf800,0x07e0,0x001f}; //< This is for RGB565 Format Bitmask.
S3C2450DISP::S3C2450DISP()
{
DWORD oldMode;
ULONG fbSize;
ULONG fbOffset;
ULONG offsetX;
ULONG offsetY;
m_InDDraw = FALSE;
DEBUGMSG(GPE_ZONE_INIT,(TEXT("S3C2450DISP::S3C2450DISP\r\n")));
m_pIntrReg = (S3C2450_INTR_REG *)VirtualAlloc(0, sizeof(S3C2450_INTR_REG), MEM_RESERVE, PAGE_NOACCESS);
if (m_pIntrReg == NULL)
{
return;
}
if (!VirtualCopy((PVOID)m_pIntrReg, (PVOID)(S3C2450_BASE_REG_PA_INTR >> 8), sizeof(S3C2450_INTR_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE)) {
return;
}
m_pLCDReg = (S3C2450_LCD_REG *)VirtualAlloc(0, sizeof(S3C2450_LCD_REG), MEM_RESERVE, PAGE_NOACCESS);
if (m_pLCDReg == NULL)
{
return;
}
if (!VirtualCopy((PVOID)m_pLCDReg, (PVOID)(S3C2450_BASE_REG_PA_LCD >> 8), sizeof(S3C2450_LCD_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE)) {
return;
}
// regist LCD Interrupt
m_dwVSYNCIrq = IRQ_LCD_VSYNC;
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &m_dwVSYNCIrq, sizeof(DWORD), &m_dwVSYNCSysIntr, sizeof(DWORD), NULL))
{
m_dwVSYNCSysIntr = SYSINTR_UNDEFINED;
return;
}
m_hVSYNCInterruptEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if(NULL == m_hVSYNCInterruptEvent)
{
return;
}
if (!(InterruptInitialize(m_dwVSYNCSysIntr, m_hVSYNCInterruptEvent, 0, 0)))
{
return;
}
m_pLCDReg->VIDINTCON &= ~((0x3)<<15 | (0x3)<<13 | (0x1) <<12 | (0x1) ); // FRAMESEL0, INTFRMEN Bit clear
m_pLCDReg->VIDINTCON |= ((0x3)<<15 /*| (0x0)<<13 | (0x1)<<12*/ ); /// Video Frame Disalbe
//m_pIntrReg->INTSUBMSK |= 1 << IRQ_SUB_LCD3; // Disable Interrupt
//m_pIntrReg->INTMSK |= 1 << IRQ_LCD; // Disable Interrupt
//DisableInterrupt();
fpVisibleOverlay = 0;
fpOverlayFlipFrom = 0;
InitializeCriticalSection(&m_CS);
InitializeCriticalSection(&m_cs2D);
oldMode = SetKMode(TRUE);
m_RedMaskSize = 5;
m_RedMaskPosition = 11;
m_GreenMaskSize = 6;
m_GreenMaskPosition = 5;
m_BlueMaskSize = 5;
m_BlueMaskPosition = 0;
gBitMasks[0] =((1<<m_RedMaskSize) -1) << m_RedMaskPosition;
gBitMasks[1] =((1<<m_GreenMaskSize)-1) << m_GreenMaskPosition;
gBitMasks[2] =((1<<m_BlueMaskSize) -1) << m_BlueMaskPosition;
m_VesaMode = 0;
m_nScreenWidth = LCD_XSIZE_TFT;
m_nScreenHeight = LCD_YSIZE_TFT;
m_colorDepth = 16;
m_cxPhysicalScreen = LCD_XSIZE_TFT;
m_cyPhysicalScreen = LCD_YSIZE_TFT;
m_pvFlatFrameBuffer = IMAGE_FRAMEBUFFER_DMA_BASE;
m_cbScanLineLength = m_nScreenWidth * 2;
m_FrameBufferSize = m_nScreenHeight * m_cbScanLineLength;
m_VideoPowerState = VideoPowerOn;
m_iRotate = GetRotateModeFromReg();
SetRotateParams();
SetKMode(oldMode);
//< Initialize Display Mode
InitializeDisplayMode();
// compute frame buffer displayable area offset
offsetX = (m_cxPhysicalScreen - m_nScreenWidthSave) / 2;
offsetY = (m_cyPhysicalScreen - m_nScreenHeightSave) / 2;
fbOffset = (offsetY * m_cbScanLineLength) + offsetX;
// compute physical frame buffer size
fbSize = m_cyPhysicalScreen * m_cbScanLineLength;
// for DDraw enabled, make sure we also have some off-screen video memory available for surface allocations
fbSize = IMAGE_FRAMEBUFFER_SIZE;
// Use CreateFileMapping/MapViewOfFile to guarantee the VirtualFrameBuffer
// pointer is allocated in shared memory.
m_hVFBMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, fbSize, NULL);
if (m_hVFBMapping != NULL)
{
m_VirtualFrameBuffer = (DWORD)MapViewOfFile(m_hVFBMapping, FILE_MAP_WRITE, 0, 0, 0);
}
else
{
m_VirtualFrameBuffer = NULL;
}
////// if (m_VesaMode != 0)
////// {
if (VirtualCopy((void *)m_VirtualFrameBuffer, (void *)(m_pvFlatFrameBuffer >> 8), fbSize, PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL))
{
// CeSetMemoryAttributes ((void *)m_VirtualFrameBuffer, (void *)(m_pvFlatFrameBuffer >> 8), fbSize, PAGE_WRITECOMBINE);
if (VirtualSetAttributes((void *)m_VirtualFrameBuffer, fbSize, 0x4, 0xc, NULL) != TRUE)
{
RETAILMSG (1, (_T("Couldn't change framebuffer's page attributes as NCB.")));
RETAILMSG (1, (_T("VirtualSetAttributes failed.")));
}
}
////// }
////// else
////// {
////// if (VirtualCopy((void *)m_VirtualFrameBuffer, (void *)m_pvFlatFrameBuffer, fbSize, PAGE_READWRITE | PAGE_NOCACHE)) {
////// // since we don't know if the physical address under is contiguious or not, we have to settle with
////// // PHYSICAL_ADDRESS_UNKNOWN and hope that the CPU supports it.
////// CeSetMemoryAttributes ((void *)m_VirtualFrameBuffer, PHYSICAL_ADDRESS_UNKNOWN, fbSize, PAGE_WRITECOMBINE);
////// }
////// }
PREFAST_ASSERT(m_VirtualFrameBuffer);
////// {
////// DWORD index;
////// volatile PUSHORT ptr = (PUSHORT)m_VirtualFrameBuffer;
//////
////// for (index = 0; index < 320*240; index++)
////// {
////// if(index < 240*80)
////// {
////// ptr[index] = 0xf800;
////// }
////// else if(index < 240*160)
////// {
////// ptr[index] = 0x07e0;
////// }
////// else if(index < 240*240)
////// {
////// ptr[index] = 0x001f;
////// }
////// else
////// {
////// ptr[index] = 0xffff;
////// }
////// }
//////
////// }
memset ((void*)m_VirtualFrameBuffer, 0x0, fbSize); //< Screen Clear
m_VirtualFrameBuffer += fbOffset;
fbSize -= fbOffset;
m_pVideoMemoryHeap = new SurfaceHeap(fbSize, m_VirtualFrameBuffer, NULL, NULL);
if(!m_pVideoMemoryHeap)
{
RETAILMSG (1, (L"Failed to create surface heap on internal SRAM memory\n"));
return;
}
m_CursorVisible = FALSE;
m_CursorDisabled = TRUE;
m_CursorForcedOff = FALSE;
memset (&m_CursorRect, 0x0, sizeof(m_CursorRect));
#if G2D_ACCELERATE
// Enable Block Power and Clock Source
// DevHWPowerGating(HWPWR_2D_ON);
// DevHWClockGating(HWCLK_2D_ON);
BOOL bResult;
m_oG2D = new FIMGSE2D;
if(m_oG2D == NULL)
{
RETAILMSG(1, (TEXT("--S3C2450DISP() 2D Accelerator Initialization Fail\r\n")));
}
else
{
m_oG2D->Init();
RETAILMSG(1, (TEXT("--S3C2450DISP() 2D Accelerator Initialization Succeed\r\n")));
}
if(m_oG2D)
{
bResult = m_oG2D->InitializeInterrupt();
if(bResult==FALSE)
{
RETAILMSG(1, (TEXT("--S3C2450DISP() 2D Acclerator Interrupt Initialization Failed.\r\n")));
}
else
{
RETAILMSG(1, (TEXT("--S3C2450DISP() 2D Acclerator Interrupt Initialization Succeed.\r\n")));
}
}
else
{
RETAILMSG(1, (TEXT("--S3C2450DISP() 2D Acclerator Object was not created.\r\n")));
}
#endif
AdvertisePowerInterface(g_hmodDisplayDll);
}
S3C2450DISP::~S3C2450DISP()
{
if (m_VirtualFrameBuffer != NULL)
{
UnmapViewOfFile((LPVOID)m_VirtualFrameBuffer);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -