1*0aeed3e9SJustin Hibbits /* Copyright (c) 2008-2011 Freescale Semiconductor, Inc. 2*0aeed3e9SJustin Hibbits * All rights reserved. 3*0aeed3e9SJustin Hibbits * 4*0aeed3e9SJustin Hibbits * Redistribution and use in source and binary forms, with or without 5*0aeed3e9SJustin Hibbits * modification, are permitted provided that the following conditions are met: 6*0aeed3e9SJustin Hibbits * * Redistributions of source code must retain the above copyright 7*0aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer. 8*0aeed3e9SJustin Hibbits * * Redistributions in binary form must reproduce the above copyright 9*0aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer in the 10*0aeed3e9SJustin Hibbits * documentation and/or other materials provided with the distribution. 11*0aeed3e9SJustin Hibbits * * Neither the name of Freescale Semiconductor nor the 12*0aeed3e9SJustin Hibbits * names of its contributors may be used to endorse or promote products 13*0aeed3e9SJustin Hibbits * derived from this software without specific prior written permission. 14*0aeed3e9SJustin Hibbits * 15*0aeed3e9SJustin Hibbits * 16*0aeed3e9SJustin Hibbits * ALTERNATIVELY, this software may be distributed under the terms of the 17*0aeed3e9SJustin Hibbits * GNU General Public License ("GPL") as published by the Free Software 18*0aeed3e9SJustin Hibbits * Foundation, either version 2 of that License or (at your option) any 19*0aeed3e9SJustin Hibbits * later version. 20*0aeed3e9SJustin Hibbits * 21*0aeed3e9SJustin Hibbits * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY 22*0aeed3e9SJustin Hibbits * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23*0aeed3e9SJustin Hibbits * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24*0aeed3e9SJustin Hibbits * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY 25*0aeed3e9SJustin Hibbits * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26*0aeed3e9SJustin Hibbits * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27*0aeed3e9SJustin Hibbits * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28*0aeed3e9SJustin Hibbits * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29*0aeed3e9SJustin Hibbits * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30*0aeed3e9SJustin Hibbits * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31*0aeed3e9SJustin Hibbits */ 32*0aeed3e9SJustin Hibbits 33*0aeed3e9SJustin Hibbits /****************************************************************************** 34*0aeed3e9SJustin Hibbits @File FM_muram.c 35*0aeed3e9SJustin Hibbits 36*0aeed3e9SJustin Hibbits @Description FM MURAM ... 37*0aeed3e9SJustin Hibbits *//***************************************************************************/ 38*0aeed3e9SJustin Hibbits #include "error_ext.h" 39*0aeed3e9SJustin Hibbits #include "std_ext.h" 40*0aeed3e9SJustin Hibbits #include "mm_ext.h" 41*0aeed3e9SJustin Hibbits #include "string_ext.h" 42*0aeed3e9SJustin Hibbits #include "sprint_ext.h" 43*0aeed3e9SJustin Hibbits #include "fm_muram_ext.h" 44*0aeed3e9SJustin Hibbits #include "fm_common.h" 45*0aeed3e9SJustin Hibbits 46*0aeed3e9SJustin Hibbits 47*0aeed3e9SJustin Hibbits #define __ERR_MODULE__ MODULE_FM_MURAM 48*0aeed3e9SJustin Hibbits 49*0aeed3e9SJustin Hibbits 50*0aeed3e9SJustin Hibbits typedef struct 51*0aeed3e9SJustin Hibbits { 52*0aeed3e9SJustin Hibbits t_Handle h_Mem; 53*0aeed3e9SJustin Hibbits uintptr_t baseAddr; 54*0aeed3e9SJustin Hibbits uint32_t size; 55*0aeed3e9SJustin Hibbits } t_FmMuram; 56*0aeed3e9SJustin Hibbits 57*0aeed3e9SJustin Hibbits 58*0aeed3e9SJustin Hibbits void FmMuramClear(t_Handle h_FmMuram) 59*0aeed3e9SJustin Hibbits { 60*0aeed3e9SJustin Hibbits t_FmMuram *p_FmMuram = ( t_FmMuram *)h_FmMuram; 61*0aeed3e9SJustin Hibbits 62*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN(h_FmMuram, E_INVALID_HANDLE); 63*0aeed3e9SJustin Hibbits IOMemSet32(UINT_TO_PTR(p_FmMuram->baseAddr), 0, p_FmMuram->size); 64*0aeed3e9SJustin Hibbits } 65*0aeed3e9SJustin Hibbits 66*0aeed3e9SJustin Hibbits 67*0aeed3e9SJustin Hibbits t_Handle FM_MURAM_ConfigAndInit(uintptr_t baseAddress, uint32_t size) 68*0aeed3e9SJustin Hibbits { 69*0aeed3e9SJustin Hibbits t_Handle h_Mem; 70*0aeed3e9SJustin Hibbits t_FmMuram *p_FmMuram; 71*0aeed3e9SJustin Hibbits 72*0aeed3e9SJustin Hibbits if (!baseAddress) 73*0aeed3e9SJustin Hibbits { 74*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("baseAddress 0 is not supported")); 75*0aeed3e9SJustin Hibbits return NULL; 76*0aeed3e9SJustin Hibbits } 77*0aeed3e9SJustin Hibbits 78*0aeed3e9SJustin Hibbits if (baseAddress%4) 79*0aeed3e9SJustin Hibbits { 80*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("baseAddress not 4 bytes aligned!")); 81*0aeed3e9SJustin Hibbits return NULL; 82*0aeed3e9SJustin Hibbits } 83*0aeed3e9SJustin Hibbits 84*0aeed3e9SJustin Hibbits /* Allocate FM MURAM structure */ 85*0aeed3e9SJustin Hibbits p_FmMuram = (t_FmMuram *) XX_Malloc(sizeof(t_FmMuram)); 86*0aeed3e9SJustin Hibbits if (!p_FmMuram) 87*0aeed3e9SJustin Hibbits { 88*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_NO_MEMORY, ("FM MURAM driver structure")); 89*0aeed3e9SJustin Hibbits return NULL; 90*0aeed3e9SJustin Hibbits } 91*0aeed3e9SJustin Hibbits memset(p_FmMuram, 0, sizeof(t_FmMuram)); 92*0aeed3e9SJustin Hibbits 93*0aeed3e9SJustin Hibbits 94*0aeed3e9SJustin Hibbits if ((MM_Init(&h_Mem, baseAddress, size) != E_OK) || (!h_Mem)) 95*0aeed3e9SJustin Hibbits { 96*0aeed3e9SJustin Hibbits XX_Free(p_FmMuram); 97*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_INVALID_HANDLE, ("FM-MURAM partition!!!")); 98*0aeed3e9SJustin Hibbits return NULL; 99*0aeed3e9SJustin Hibbits } 100*0aeed3e9SJustin Hibbits 101*0aeed3e9SJustin Hibbits /* Initialize FM MURAM parameters which will be kept by the driver */ 102*0aeed3e9SJustin Hibbits p_FmMuram->baseAddr = baseAddress; 103*0aeed3e9SJustin Hibbits p_FmMuram->size = size; 104*0aeed3e9SJustin Hibbits p_FmMuram->h_Mem = h_Mem; 105*0aeed3e9SJustin Hibbits 106*0aeed3e9SJustin Hibbits return p_FmMuram; 107*0aeed3e9SJustin Hibbits } 108*0aeed3e9SJustin Hibbits 109*0aeed3e9SJustin Hibbits t_Error FM_MURAM_Free(t_Handle h_FmMuram) 110*0aeed3e9SJustin Hibbits { 111*0aeed3e9SJustin Hibbits t_FmMuram *p_FmMuram = ( t_FmMuram *)h_FmMuram; 112*0aeed3e9SJustin Hibbits 113*0aeed3e9SJustin Hibbits if (p_FmMuram->h_Mem) 114*0aeed3e9SJustin Hibbits MM_Free(p_FmMuram->h_Mem); 115*0aeed3e9SJustin Hibbits 116*0aeed3e9SJustin Hibbits XX_Free(h_FmMuram); 117*0aeed3e9SJustin Hibbits 118*0aeed3e9SJustin Hibbits return E_OK; 119*0aeed3e9SJustin Hibbits } 120*0aeed3e9SJustin Hibbits 121*0aeed3e9SJustin Hibbits void * FM_MURAM_AllocMem(t_Handle h_FmMuram, uint32_t size, uint32_t align) 122*0aeed3e9SJustin Hibbits { 123*0aeed3e9SJustin Hibbits t_FmMuram *p_FmMuram = ( t_FmMuram *)h_FmMuram; 124*0aeed3e9SJustin Hibbits uintptr_t addr; 125*0aeed3e9SJustin Hibbits 126*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(h_FmMuram, E_INVALID_HANDLE, NULL); 127*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_FmMuram->h_Mem, E_INVALID_HANDLE, NULL); 128*0aeed3e9SJustin Hibbits 129*0aeed3e9SJustin Hibbits addr = (uintptr_t)MM_Get(p_FmMuram->h_Mem, size, align ,"FM MURAM"); 130*0aeed3e9SJustin Hibbits 131*0aeed3e9SJustin Hibbits if (addr == ILLEGAL_BASE) 132*0aeed3e9SJustin Hibbits return NULL; 133*0aeed3e9SJustin Hibbits 134*0aeed3e9SJustin Hibbits return UINT_TO_PTR(addr); 135*0aeed3e9SJustin Hibbits } 136*0aeed3e9SJustin Hibbits 137*0aeed3e9SJustin Hibbits void * FM_MURAM_AllocMemForce(t_Handle h_FmMuram, uint64_t base, uint32_t size) 138*0aeed3e9SJustin Hibbits { 139*0aeed3e9SJustin Hibbits t_FmMuram *p_FmMuram = ( t_FmMuram *)h_FmMuram; 140*0aeed3e9SJustin Hibbits uintptr_t addr; 141*0aeed3e9SJustin Hibbits 142*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(h_FmMuram, E_INVALID_HANDLE, NULL); 143*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_FmMuram->h_Mem, E_INVALID_HANDLE, NULL); 144*0aeed3e9SJustin Hibbits 145*0aeed3e9SJustin Hibbits addr = (uintptr_t)MM_GetForce(p_FmMuram->h_Mem, base, size, "FM MURAM"); 146*0aeed3e9SJustin Hibbits 147*0aeed3e9SJustin Hibbits if (addr == ILLEGAL_BASE) 148*0aeed3e9SJustin Hibbits return NULL; 149*0aeed3e9SJustin Hibbits 150*0aeed3e9SJustin Hibbits return UINT_TO_PTR(addr); 151*0aeed3e9SJustin Hibbits } 152*0aeed3e9SJustin Hibbits 153*0aeed3e9SJustin Hibbits t_Error FM_MURAM_FreeMem(t_Handle h_FmMuram, void *ptr) 154*0aeed3e9SJustin Hibbits { 155*0aeed3e9SJustin Hibbits t_FmMuram *p_FmMuram = ( t_FmMuram *)h_FmMuram; 156*0aeed3e9SJustin Hibbits 157*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(h_FmMuram, E_INVALID_HANDLE); 158*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_FmMuram->h_Mem, E_INVALID_HANDLE); 159*0aeed3e9SJustin Hibbits 160*0aeed3e9SJustin Hibbits if (MM_Put(p_FmMuram->h_Mem, PTR_TO_UINT(ptr)) == 0) 161*0aeed3e9SJustin Hibbits RETURN_ERROR(MINOR, E_INVALID_HANDLE, ("memory pointer!!!")); 162*0aeed3e9SJustin Hibbits 163*0aeed3e9SJustin Hibbits return E_OK; 164*0aeed3e9SJustin Hibbits } 165