1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __RAMALLOC_H__ |
|
17 #define __RAMALLOC_H__ |
|
18 #include <kernel/klib.h> |
|
19 |
|
20 // RAM information block passed from bootstrap to kernel. |
|
21 // Consists of two consecutive lists of SRamBank structures, each terminated by |
|
22 // a bank with iSize=0. |
|
23 // The first list specifies all available blocks of RAM in the system. |
|
24 // The second list specifies any blocks of RAM which are reserved and not |
|
25 // available for general allocation. This should not include RAM mapped by the |
|
26 // bootstrap - this will be discovered when the initial page mappings are |
|
27 // analysed. |
|
28 struct SRamInfo |
|
29 { |
|
30 SRamBank iBanks[1]; // extend for multiple banks |
|
31 // SRamBank iReservedBlocks[1]; |
|
32 }; |
|
33 |
|
34 const TPhysAddr NULL_PAGE=0xffffffffu; |
|
35 class DRamAllocatorBase : public DBase |
|
36 { |
|
37 public: |
|
38 static DRamAllocatorBase* New(const SRamInfo& aInfo, TInt aPageShift, const SRamBank* aPowerBanks=NULL); |
|
39 static void Panic(TInt aPanic); |
|
40 FORCE_INLINE TInt FreeRamInPages() |
|
41 {return iTotalFreeRamPages;} |
|
42 FORCE_INLINE TInt ClaimPhysicalRam(TPhysAddr aBase, TInt aSize) |
|
43 {return SetPhysicalRamState(aBase,aSize,EFalse);} |
|
44 FORCE_INLINE TInt FreePhysicalRam(TPhysAddr aBase, TInt aSize) |
|
45 {return SetPhysicalRamState(aBase,aSize,ETrue);} |
|
46 public: |
|
47 virtual TInt Create(const SRamInfo& aInfo, const SRamBank* aPowerBanks)=0; |
|
48 virtual TInt MarkPageAllocated(TPhysAddr aAddr)=0; |
|
49 virtual TInt FreeRamPage(TPhysAddr aAddr)=0; |
|
50 virtual void FreeRamPages(TPhysAddr* aPageList, TInt aNumPages)=0; |
|
51 virtual TInt AllocRamPages(TPhysAddr* aPageList, TInt aNumPages)=0; |
|
52 virtual TInt AllocContiguousRam(TInt aSize, TPhysAddr& aPhysAddr, TInt aAlign=0)=0; |
|
53 virtual TInt SetPhysicalRamState(TPhysAddr aBase, TInt aSize, TBool aState)=0; |
|
54 virtual TUint TotalPhysicalRamPages()=0; |
|
55 protected: |
|
56 static DRamAllocatorBase* New(); |
|
57 protected: |
|
58 TInt iPageSize; |
|
59 TInt iPageShift; |
|
60 TInt iTotalFreeRamPages; |
|
61 TInt iNumPowerBlocks; |
|
62 TInt* iPowerBlockPages; // number of pages used in each power block |
|
63 TUint32 iPowerState; // mask of currently used power blocks |
|
64 }; |
|
65 |
|
66 #endif |
|
67 |
|