Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / sun4v-devices / niu-nexus / niu-nexus.tok
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: niu-nexus.tok
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)niu-nexus.tok 1.1 07/01/23
43purpose:
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47fcode-version3
48
49headerless
50
51fload ${BP}/dev/utilities/misc.fth
52fload ${BP}/dev/utilities/shifter.fth
53fload ${BP}/dev/utilities/cif.fth
54fload ${BP}/dev/sun4v-devices/utilities/property-access.fth
55
56h# 2000 value pagesize
57alias mmu-pagesize pagesize
58
59\ Where we find the bootprom driver resources.
60: builtin-drivers " SUNW,builtin-drivers" ;
61
62defer claim 0 " claim" do-cif is claim
63defer release 0 " release" do-cif is release
64
65external
66
67: dma-alloc ( size -- vaddr ) mmu-pagesize over max swap 0 claim ;
68: dma-free ( vaddr size -- ) swap release ;
69: dma-sync ( virt-addr dev-addr size -- ) 3drop ;
70: dma-map-in ( virt size cache? -- dma-virt ) 2drop >physical drop ;
71: dma-map-out ( virt dma-virt size -- ) 3drop ;
72
73: map-in ( phys.lo phys.hi len -- vaddr )
74 \ The following code assumes that there are only
75 \ two entries in the 'ranges' property: one for
76 \ port 0 with a register base of 0x81.0000.0000
77 \ and one for port 1 with a register base of
78 \ 0x81.0200.0000. If the 'ranges' property
79 \ ever changes, this code will have to be updated
80 >r if h# 2000000 + then h# 80000081 0 lxjoin r>
81 " map-in" $call-parent
82;
83
84: map-out ( vaddr len -- ) " map-out" $call-parent ;
85
86" niu" encode-string " name" property
87
88external
89
902 encode-int " #address-cells" property
912 encode-int " #size-cells" property
92" compatible" make-prop drop
93" device-type" required-prop drop encode-string " device_type" property
94
95: enx+ ( xdr,len x -- xdr,len ) xlsplit swap >r en+ r> en+ ;
96
97: parse-int ( adr len -- pa.hi ) parse-2int nip ;
98
99: encode-unit ( pa.lo pa.hi -- adr,len )
100 nip
101 push-hex
102 <# u#s u#>
103 pop-base
104;
105
106: decode-unit ( adr len -- pa.lo pa.hi )
107 parse-int 0 swap
108;
109
110: open true ;
111: close ;
112
1130 0 encode-bytes
1140 my-space lxjoin enx+ 0 enx+ \ cfg-handle
115" reg" property
116
117\ 'ranges' property has two entries, one for each port:
118\ 00000000 00000000 80000081 00000000 00000000 05008000
119\ 00000001 00000000 80000081 02000000 00000000 05008000
1200 encode-int 0 en+ h# 80000081 en+ 0 en+ 0 en+ h# 5008000 en+
1211 en+ 0 en+ h# 80000081 en+ h# 2000000 en+ 0 en+ h# 5008000 en+
122" ranges" property
123
124: builtin-drivers ( -- str$ )
125 " /packages/SUNW,builtin-drivers"
126;
127
128: builtin-phandle@ ( -- phandle true | false )
129 builtin-drivers find-package
130;
131
132: start-port-node ( port -- ) 0 swap encode-unit 0 0 2swap new-device set-args ;
133
134: probe-network-nodes ( -- )
135 my-node ( node )
136 begin ( node )
137 " network" md-find-node ?dup ( node true | false )
138 while ( node )
139 dup " port" ascii v md-find-prop ( node prop )
140 md-decode-prop drop ( node port )
141 start-port-node ( node )
142 dup " compatible" -1 md-find-prop ( node prop )
143 md-decode-prop drop decode-string 2swap 2drop builtin-phandle@ drop find-method if ( node acf| )
144 catch if ( node )
145 cmn-warn[ " Problem attaching siu child driver" ]cmn-end
146 then ( node )
147 then ( node )
148 finish-device ( node )
149 repeat ( node )
150;
151
152probe-network-nodes
153
154end0