1296177Sjhibbits/* Copyright (c) 2008-2011 Freescale Semiconductor, Inc.
2296177Sjhibbits * All rights reserved.
3296177Sjhibbits *
4296177Sjhibbits * Redistribution and use in source and binary forms, with or without
5296177Sjhibbits * modification, are permitted provided that the following conditions are met:
6296177Sjhibbits *     * Redistributions of source code must retain the above copyright
7296177Sjhibbits *       notice, this list of conditions and the following disclaimer.
8296177Sjhibbits *     * Redistributions in binary form must reproduce the above copyright
9296177Sjhibbits *       notice, this list of conditions and the following disclaimer in the
10296177Sjhibbits *       documentation and/or other materials provided with the distribution.
11296177Sjhibbits *     * Neither the name of Freescale Semiconductor nor the
12296177Sjhibbits *       names of its contributors may be used to endorse or promote products
13296177Sjhibbits *       derived from this software without specific prior written permission.
14296177Sjhibbits *
15296177Sjhibbits *
16296177Sjhibbits * ALTERNATIVELY, this software may be distributed under the terms of the
17296177Sjhibbits * GNU General Public License ("GPL") as published by the Free Software
18296177Sjhibbits * Foundation, either version 2 of that License or (at your option) any
19296177Sjhibbits * later version.
20296177Sjhibbits *
21296177Sjhibbits * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22296177Sjhibbits * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23296177Sjhibbits * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24296177Sjhibbits * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25296177Sjhibbits * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26296177Sjhibbits * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27296177Sjhibbits * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28296177Sjhibbits * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29296177Sjhibbits * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30296177Sjhibbits * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31296177Sjhibbits */
32296177Sjhibbits
33296177Sjhibbits/****************************************************************
34296177Sjhibbits *
35296177Sjhibbits * File:  mm.h
36296177Sjhibbits *
37296177Sjhibbits *
38296177Sjhibbits * Description:
39296177Sjhibbits *  MM (Memory Management) object definitions.
40296177Sjhibbits *  It also includes definitions of the Free Block, Busy Block
41296177Sjhibbits *  and Memory Block structures used by the MM object.
42296177Sjhibbits *
43296177Sjhibbits ****************************************************************/
44296177Sjhibbits
45296177Sjhibbits#ifndef __MM_H
46296177Sjhibbits#define __MM_H
47296177Sjhibbits
48296177Sjhibbits
49296177Sjhibbits#include "mm_ext.h"
50296177Sjhibbits
51296177Sjhibbits#define __ERR_MODULE__  MODULE_MM
52296177Sjhibbits
53296177Sjhibbits
54296177Sjhibbits#define MAKE_ALIGNED(addr, align)    \
55296177Sjhibbits    (((uint64_t)(addr) + ((align) - 1)) & (~(((uint64_t)align) - 1)))
56296177Sjhibbits
57296177Sjhibbits
58296177Sjhibbits/* t_MemBlock data stucutre defines parameters of the Memory Block */
59296177Sjhibbitstypedef struct t_MemBlock
60296177Sjhibbits{
61296177Sjhibbits    struct t_MemBlock *p_Next;      /* Pointer to the next memory block */
62296177Sjhibbits
63296177Sjhibbits    uint64_t  base;                 /* Base address of the memory block */
64296177Sjhibbits    uint64_t  end;                  /* End address of the memory block */
65296177Sjhibbits} t_MemBlock;
66296177Sjhibbits
67296177Sjhibbits
68296177Sjhibbits/* t_FreeBlock data stucutre defines parameters of the Free Block */
69296177Sjhibbitstypedef struct t_FreeBlock
70296177Sjhibbits{
71296177Sjhibbits    struct t_FreeBlock *p_Next;     /* Pointer to the next free block */
72296177Sjhibbits
73296177Sjhibbits    uint64_t  base;                 /* Base address of the block */
74296177Sjhibbits    uint64_t  end;                  /* End address of the block */
75296177Sjhibbits} t_FreeBlock;
76296177Sjhibbits
77296177Sjhibbits
78296177Sjhibbits/* t_BusyBlock data stucutre defines parameters of the Busy Block  */
79296177Sjhibbitstypedef struct t_BusyBlock
80296177Sjhibbits{
81296177Sjhibbits    struct t_BusyBlock *p_Next;         /* Pointer to the next free block */
82296177Sjhibbits
83296177Sjhibbits    uint64_t    base;                   /* Base address of the block */
84296177Sjhibbits    uint64_t    end;                    /* End address of the block */
85296177Sjhibbits    char        name[MM_MAX_NAME_LEN];  /* That block of memory was allocated for
86296177Sjhibbits                                           something specified by the Name */
87296177Sjhibbits} t_BusyBlock;
88296177Sjhibbits
89296177Sjhibbits
90296177Sjhibbits/* t_MM data structure defines parameters of the MM object */
91296177Sjhibbitstypedef struct t_MM
92296177Sjhibbits{
93296177Sjhibbits    t_MemBlock      *memBlocks;     /* List of memory blocks (Memory list) */
94296177Sjhibbits    t_BusyBlock     *busyBlocks;    /* List of busy blocks (Busy list) */
95296177Sjhibbits    t_FreeBlock     *freeBlocks[MM_MAX_ALIGNMENT + 1];
96296177Sjhibbits                                    /* Alignment lists of free blocks (Free lists) */
97296177Sjhibbits    t_Handle        h_Spinlock;
98296177Sjhibbits} t_MM;
99296177Sjhibbits
100296177Sjhibbits
101296177Sjhibbits#endif /* __MM_H */
102