1855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi/*
2855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi * Copyright (C) 2011 The Android Open Source Project
3855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi *
4855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi * Licensed under the Apache License, Version 2.0 (the "License");
5855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi * you may not use this file except in compliance with the License.
6855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi * You may obtain a copy of the License at
7855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi *
8855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi *      http://www.apache.org/licenses/LICENSE-2.0
9855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi *
10855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi * Unless required by applicable law or agreed to in writing, software
11855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi * distributed under the License is distributed on an "AS IS" BASIS,
12855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi * See the License for the specific language governing permissions and
14855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi * limitations under the License.
15855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi */
16855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi/**
17855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi*************************************************************************
18855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi * @file   M4PSW_MemoryInterface.c
19855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi * @brief  Memory Interface
20855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi * @note   Implementation of the osal memory functions
21855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi *************************************************************************
22855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi*/
23855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi
24855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi#include <stdlib.h>
25855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi#include <memory.h>
26855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi
27855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi#include <time.h>
28855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi#include "M4OSA_Memory.h"
29855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi#ifndef M4VPS_ADVANCED_MEMORY_MANAGER
30855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi/**
31855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi ************************************************************************
32694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu * @fn         M4OSA_MemAddr32 M4OSA_32bitAlignedMalloc(M4OSA_UInt32 size,
33694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu *                                          M4OSA_CoreID coreID,
34694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu *                                          M4OSA_Char* string)
35694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu * @brief      this function allocates a memory block (at least 32 bits aligned)
36694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu * @note
37694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu * @param      size (IN): size of allocated block in bytes
38694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu * @param      coreID (IN): identification of the caller component
39694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu * @param      string (IN): description of the allocated block (null terminated)
40694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu * @return     address of the allocated block, M4OSA_NULL if no memory available
41694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu ************************************************************************
42694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu*/
43694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu
44694816d7291f17364502ac5d3319684a0b180860Shyam PallapothuM4OSA_MemAddr32 M4OSA_32bitAlignedMalloc(M4OSA_UInt32 size,
45694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu                             M4OSA_CoreID coreID,
46694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu                             M4OSA_Char* string)
47694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu{
48694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu    M4OSA_MemAddr32 Address = M4OSA_NULL;
49694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu
50694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu    /**
51694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu     * If size is 0, malloc on WIN OS allocates a zero-length item in
52694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu     * the heap and returns a valid pointer to that item.
53694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu     * On other platforms, malloc could returns an invalid pointer
54694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu     * So, DON'T allocate memory of 0 byte */
55694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu    if (size == 0)
56694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu    {
57694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu        return Address;
58694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu    }
59694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu
60694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu    if (size%4 != 0)
61694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu    {
62694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu        size = size + 4 - (size%4);
63694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu    }
64694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu
65694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu    Address = (M4OSA_MemAddr32) malloc(size);
66694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu
67694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu    return Address;
68694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu}
69694816d7291f17364502ac5d3319684a0b180860Shyam Pallapothu
70855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi#endif
71855ec7c4be7ad642721909d5837a8d25a117c22fDharmaray Kundargi
72