Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / slof / fs / available.fs
1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2008 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
8 \ *
9 \ * Contributors:
10 \ *     IBM Corporation - initial implementation
11 \ ****************************************************************************/
12
13 VARIABLE chosen-memory-ih 0 chosen-memory-ih !
14
15 \ +
16 \ Maintain "available" property.
17 \ Sun has a single memory node with "available" property
18 \ and separate memory controller nodes.
19 \ We corespond memory nodes with their respective memory controllers
20 \ and use /chosen/memory as default memory node to hold the "available" map
21 \ NOTE -> /chosen/memory is expected 2B initialized before using claim/release
22 \ +
23
24 : (chosen-memory-ph) ( -- phandle )
25         chosen-memory-ih @ ?dup 0= IF
26                 s" memory" get-chosen IF
27                         decode-int nip nip dup chosen-memory-ih !
28                         ihandle>phandle
29                 ELSE 0 THEN
30         ELSE ihandle>phandle THEN
31 ;
32
33 : (set-available-prop) ( prop plen -- )
34         s" available"
35         (chosen-memory-ph) ?dup 0<> IF set-property ELSE
36                 cr ." Can't find chosen memory node - "
37                 ." no available property created" cr
38                 2dup 2dup
39         THEN
40 ;
41
42 : update-available-property ( available-ptr -- )
43         dup >r available>size@
44         0= r@ available AVAILABLE-SIZE /available * + >= or IF
45                 available r> available - encode-bytes (set-available-prop)
46         ELSE
47                 r> /available + RECURSE
48         THEN
49 ;
50
51 : update-available-property available update-available-property ;
52
53 \ \\\\\\\\\\\\\\ Exported Interface:
54 \ +
55 \ IEEE 1275 implementation:
56 \       claim
57 \ Claim the region with given start address and size (if align parameter is 0);
58 \ alternatively claim any region of given alignment
59 \ +
60 \ Throw an exception if failed
61 \ +
62 : claim ( [ addr ] len align -- base ) claim update-available-property ;
63
64 \ +
65 \ IEEE 1275 implementation:
66 \       release
67 \ Free the region with given start address and size
68 \ +
69 : release ( addr len -- ) release update-available-property ;
70
71 update-available-property
72