📄 mfcmemory.c
字号:
/*
* Project Name MFC DRIVER
* Copyright 2007 Samsung Electronics Co, Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information
* of Samsung Electronics ("Confidential Information").
* you shall not disclose such Confidential Information and shall use
* it only in accordance with the terms of the license agreement
* you entered into with Samsung Electronics
*
* This source file is for setting physical memory.
*
* @name MFC DRIVER MODULE Module (MfcMemory.c)
* @author Jiun, Yu(jiun.yu@samsung.com)
* @date 03-28-07
*/
#include <windows.h>
#include <DrvLib.h>
#include "LogMsg.h"
void *Phy2Vir_AddrMapping(unsigned int phy_addr, int mem_size)
{
#if 1
void *mappedAddr = NULL;
mappedAddr = DrvLib_MapIoSpace(phy_addr, mem_size, FALSE);
if (mappedAddr == NULL)
{
RETAILMSG(1, (L"[MFC:ERR] Phy2Vir_AddrMapping() : Mapping Failed [PA:0x%08x]\n\r", phy_addr));
}
return mappedAddr;
#else
BOOL b;
void *reserved_mem;
reserved_mem = (void *)VirtualAlloc(NULL, mem_size, MEM_RESERVE, PAGE_NOACCESS);
if (reserved_mem == NULL) {
ERRORMSG(1,(TEXT("For IOPreg: VirtualAlloc failed!\r\n")));
return 0;
}
b = VirtualCopy(reserved_mem,
(void *)(phy_addr >> 8),
mem_size,
PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE);
if (b == FALSE) {
VirtualFree(reserved_mem, 0, MEM_RELEASE);
return NULL;
}
return reserved_mem;
#endif
}
void *Mem_Alloc(unsigned int size)
{
void *alloc_mem;
alloc_mem = (void *) malloc(size);
if (alloc_mem == NULL) {
LOG_MSG(LOG_ERROR, "Mem_Alloc", "memory allocation failed!\r\n");
return NULL;
}
return alloc_mem;
}
void Mem_Free(void *addr)
{
free(addr);
}
void *Mem_Cpy(void *dst, const void *src, int size)
{
return memcpy(dst, src, size);
}
int Mem_Set(void *dst, int value, int size)
{
memset(dst, value, size);
return value;
}
int Copy_From_User(void *to, const void *from, unsigned long n)
{
return (int)memcpy(to, from, n);
}
int Copy_To_User(void *to, const void *from, unsigned long n)
{
return (int)memcpy(to, from, n);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -