Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / network / neptune / niu / map.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: map.fth
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: @(#)map.fth 1.2 07/03/13
43purpose:
44copyright: Copyright 2007 Sun Microsystems, Inc. All rights reserved.
45copyright: Use is subject to license terms.
46
47headerless
48
49: map-in ( phys.lo phys.hi size -- vaddr ) " map-in" $call-parent ;
50
51: map-out ( vaddr size -- ) " map-out" $call-parent ;
52
53: make-power-of-2 ( x -- x' ) 1 d# 63 << begin 1 xrshift 2dup and until 1 << nip ;
54
55\ The Hypervisor NIU APIs are defined in FWARC case 2006/524
56h# 142 constant n2niu-rx-lp-set
57h# 144 constant n2niu-tx-lp-set
58
59: log-page-set ( vaddr size -- )
60 swap >physical drop swap ( raddr size )
61 0 0 2swap ( channel register raddr size )
62 2over 2over 4 1 n2niu-rx-lp-set h# 80 htrap ?dup if
63 cmn-fatal[ " RX Logical page setting failed!" ]cmn-end
64 then
65 4 1 n2niu-tx-lp-set h# 80 htrap ?dup if
66 cmn-fatal[ " TX Logical page setting failed!" ]cmn-end
67 then
68;
69
70: dma-alloc ( size -- vaddr ) " dma-alloc" $call-parent ;
71: dma-free ( vaddr size -- ) " dma-free" $call-parent ;
72
73: dma-map-in ( vaddr n cache? -- devaddr )
74 >r 2dup log-page-set
75 r> " dma-map-in" $call-parent
76;
77
78: dma-map-out ( vaddr devaddr n -- ) " dma-map-out" $call-parent ;
79
80: dma-sync ( virt-adr dev-adr size -- )
81 " dma-sync" ['] $call-parent catch if
82 3drop 2drop
83 then
84;
85
860 value cpu-dma-base
870 value io-dma-base
88
89\ Conversion between cpu dma address and io dma address.
90: cpu>io-adr ( cpu-adr -- io-adr ) cpu-dma-base - io-dma-base + ;
91: io>cpu-adr ( io-adr -- cpu-adr ) io-dma-base - cpu-dma-base + ;
92
93#rcds /rcd * h# 2000 align-size
94constant /rcd-ring \ RX completion ring, 8KB aligned
95
96#rmds /rmd * h# 2000 align-size
97constant /rmd-ring \ RX descriptor ring, 8KB aligned
98
99#rbufs /rbuf * constant /rbufs \ RX data buffers, 8KB aligned
100
101#tmds /tmd * h# 800 align-size
102constant /tmd-ring \ TX descriptor ring, 2KB aligned
103
104/tbuf h# 1000 align-size
105constant /tbufs \ TX data buffer(s), 4KB aligned
106
107d# 64 constant /tmbox \ TX Mailbox
108d# 64 constant /rmbox \ RX Mailbox
109
110struct
111 /rcd-ring field >rcd-ring
112 /rmd-ring field >rmd-ring
113 /rbufs field >rbufs
114 /tmd-ring field >tmd-ring
115 /tbufs field >tbufs
116 /tmbox field >tmbox
117 /rmbox field >rmbox
118make-power-of-2 constant /dma-region
119
120: rcd0 ( -- addr ) cpu-dma-base >rcd-ring ;
121: rmd0 ( -- addr ) cpu-dma-base >rmd-ring ;
122: rbuf0 ( -- addr ) cpu-dma-base >rbufs ;
123: tmd0 ( -- addr ) cpu-dma-base >tmd-ring ;
124: tbuf0 ( -- addr ) cpu-dma-base >tbufs ;
125: rmbox ( -- addr ) cpu-dma-base >rmbox ;
126: tmbox ( -- addr ) cpu-dma-base >tmbox ;
127
128: io-rcd0 ( -- addr ) io-dma-base >rcd-ring ;
129: io-rmd0 ( -- addr ) io-dma-base >rmd-ring ;
130: io-rbuf0 ( -- addr ) io-dma-base >rbufs ;
131: io-tmd0 ( -- addr ) io-dma-base >tmd-ring ;
132: io-tbuf0 ( -- addr ) io-dma-base >tbufs ;
133: io-rmbox ( -- addr ) io-dma-base >rmbox ;
134: io-tmbox ( -- addr ) io-dma-base >tmbox ;
135
136: map-buffers ( -- )
137 /dma-region dup dma-alloc dup to cpu-dma-base
138 swap false dma-map-in to io-dma-base
139;
140
141: unmap-buffers ( -- )
142 cpu-dma-base io-dma-base /dma-region dma-map-out
143 cpu-dma-base /dma-region dma-free
144 0 to cpu-dma-base 0 to io-dma-base
145;
146
147: map-regs ( -- )
148 " reg" get-my-property drop ( reg-addr,len )
149 drop-regline
150 map-in-regline ( reg-addr',len' vaddr )
151 nip nip ( vaddr )
152 dup to pio
153 dup h# 80000 + to fzc-pio
154 dup h# 180000 + to xmac0
155 dup h# 182000 + to xpcs0
156 dup h# 184000 + to pcs0
157 dup h# 196000 + to mif
158 dup h# 280000 + to fzc-ipp
159 dup h# 380000 + to fzc-fflp
160 dup h# 580000 + to fzc-zcp
161 dup h# 600000 + to dmc
162 dup h# 680000 + to fzc-dmc
163 dup h# 780000 + to fzc-txc
164 h# 800000 + to pio-ldsv
165;
166
167: unmap-regs ( -- )
168 " reg" get-my-property drop ( reg-addr,len )
169 drop-regline ( reg-addr',len' )
170 regline-size pio swap map-out ( )
171 0 to pio 0 to fzc-pio 0 to xmac0 0 to xpcs0
172 0 to mif 0 to fzc-ipp 0 to fzc-fflp 0 to fzc-zcp
173 0 to dmc 0 to fzc-dmc 0 to fzc-txc 0 to pio-ldsv
174;
175
176: map-resources ( -- )
177 pio 0= if
178 map-regs map-buffers
179 10g-fiber to portmode
180 my-space to port
181 then
182;
183
184: unmap-resources ( -- )
185 pio if
186 unmap-buffers unmap-regs
187 then
188;
189
190headerless