aboutsummaryrefslogtreecommitdiff
path: root/slof/fs/available.fs
blob: fe6f2120c4a9537e3b1a78b546230c47245b977f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
\ *****************************************************************************
\ * Copyright (c) 2004, 2008 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ *     IBM Corporation - initial implementation
\ ****************************************************************************/

VARIABLE chosen-memory-ih 0 chosen-memory-ih !

\ +
\ Maintain "available" property.
\ Sun has a single memory node with "available" property
\ and separate memory controller nodes.
\ We pair memory nodes with their respective memory controllers
\ and use /chosen/memory as default memory node to hold the "available" map
\ NOTE -> /chosen/memory is expected to be initialized before using claim/release
\ +

: (chosen-memory-ph) ( -- phandle )
	chosen-memory-ih @ ?dup 0= IF
		s" memory" get-chosen IF
			decode-int nip nip dup chosen-memory-ih !
			ihandle>phandle
		ELSE 0 THEN
	ELSE ihandle>phandle THEN
;

: (set-available-prop) ( prop plen -- )
	s" available"
	(chosen-memory-ph) ?dup 0<> IF set-property ELSE
		cr ." Can't find chosen memory node - "
		." no available property created" cr
		2dup 2dup
	THEN
;

: update-available-property ( available-ptr -- )
	dup >r available>size@
	0= r@ available AVAILABLE-SIZE /available * + >= or IF
		available r> available - encode-bytes (set-available-prop)
	ELSE
		r> /available + RECURSE
	THEN
;

: update-available-property available update-available-property ;

\ \\\\\\\\\\\\\\ Exported Interface:
\ +
\ IEEE 1275 implementation:
\	claim
\ Claim the region with given start address and size (if align parameter is 0);
\ alternatively claim any region of given alignment
\ +
\ Throw an exception if failed
\ +
: claim ( [ addr ] len align -- base ) claim update-available-property ;

\ +
\ IEEE 1275 implementation:
\	release
\ Free the region with given start address and size
\ +
: release ( addr len -- ) release update-available-property ;

update-available-property