|
1 // Copyright (c) 2006-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 "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Syborg Virtual Hardware Memory implementation |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalTechnology |
|
19 @prototype |
|
20 */ |
|
21 |
|
22 #include "syborgvirtualhwmemory.h" |
|
23 |
|
24 DVirtualHWMemoryManager::DVirtualHWMemoryManager(TUint32 aBase, TInt aMaxSize): |
|
25 iRoot(0, aBase), |
|
26 iLast(0, aBase + aMaxSize) |
|
27 { |
|
28 iRoot.iNext = &iLast; |
|
29 } |
|
30 |
|
31 TUint32 DVirtualHWMemoryManager::Allocate(TInt aSize) |
|
32 { |
|
33 TUint32 address(NULL); |
|
34 TAllocatedCell* current(&iRoot); |
|
35 TAllocatedCell* next(iRoot.iNext); |
|
36 while (next) |
|
37 { |
|
38 const TInt freeBetweenCells = next->iBase - (current->iBase + current->iSize); |
|
39 if (freeBetweenCells >= aSize ) |
|
40 { |
|
41 //Mark area as allocated |
|
42 address = current->iBase + current->iSize; |
|
43 TAllocatedCell* newCell = new TAllocatedCell(aSize, address); |
|
44 if (!newCell) |
|
45 { |
|
46 return NULL; |
|
47 } |
|
48 newCell->iNext = next; |
|
49 current->iNext = newCell; |
|
50 break; |
|
51 } |
|
52 else |
|
53 { |
|
54 current = next; |
|
55 next = next->iNext; |
|
56 } |
|
57 } |
|
58 return address; |
|
59 } |
|
60 |
|
61 void DVirtualHWMemoryManager::Deallocate(const TUint32 aPhysicalAddress) |
|
62 { |
|
63 TAllocatedCell* prev(&iRoot); |
|
64 TAllocatedCell* next(iRoot.iNext); |
|
65 while (next) |
|
66 { |
|
67 if (next->iBase == aPhysicalAddress) |
|
68 { |
|
69 prev->iNext = next->iNext; |
|
70 delete next; |
|
71 next = NULL; |
|
72 } |
|
73 else |
|
74 { |
|
75 prev = next; |
|
76 next = next->iNext; |
|
77 } |
|
78 } |
|
79 } |
|
80 |
|
81 DVirtualHWMemoryManager::~DVirtualHWMemoryManager() |
|
82 { |
|
83 TAllocatedCell* next(iRoot.iNext); |
|
84 while (next) |
|
85 { |
|
86 TAllocatedCell* deletethis = next; |
|
87 next = next->iNext; |
|
88 if (deletethis != &iLast) |
|
89 { |
|
90 delete deletethis; |
|
91 } |
|
92 } |
|
93 } |