Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / network / ophir / 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.1 06/02/16
43purpose: Intel Ophir/82571 map routines
44copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47headerless
48
49\ Instance values
500 instance value reg-base
510 instance value cpu-dma-base \ cpu mapped dma base
520 instance value io-dma-base \ device mapped dma base
530 instance value /dma-blk \ Total amount to map.
54
55\ Constants
56h# 20.000 constant map-size \ Amount to map for registers.
57
58: map-in ( phys.lo .. phys.hi size -- vaddr ) " map-in" $call-parent ;
59: map-out ( vaddr size -- ) " map-out" $call-parent ;
60
61: dma-alloc ( size -- vaddr ) " dma-alloc" $call-parent ;
62: dma-free ( vaddr size -- ) " dma-free" $call-parent ;
63
64: dma-map-in ( vaddr n cache? -- devaddr ) " dma-map-in" $call-parent ;
65: dma-map-out ( vaddr devaddr n -- ) " dma-map-out" $call-parent ;
66
67: dma-sync ( virt-adr dev-adr size -- )
68 " dma-sync" ['] $call-parent catch if
69 3drop 2drop
70 then
71;
72
73: enable-mem-space ( -- )
74 \ PCI Command Register Settings
75 \ h# 100 = SERR# Enable
76 \ h# 40 = Parity Error Enable
77 \ h# 4 = Mastering Enable
78 \ h# 2 = Memory Access Enable
79 4 my-w@ h# 146 or 4 my-w!
80;
81
82: disable-mem-space ( -- )
83 4 my-w@ h# 2 invert and 4 my-w!
84;
85
86\
87\ "Local" access to hardware data structures held in
88\ local memory.
89\ These are functionally equivalent to "rw@" etc except
90\ they access local memory. Since the chip is little-endian
91\ we have to do the flip explicitly ("rw@" etc fcodes
92\ are set up to do it for us, but not "w@" etc).
93\
94
95: local-c@ ( offset -- data ) c@ ;
96: local-c! ( data offset -- ) c! ;
97: local-w! ( data offset -- ) swap wbflip swap w! ;
98: local-w@ ( offset -- data ) w@ wbflip ;
99: local! ( data offset -- ) swap lbflip swap l! ;
100: local@ ( offset -- data ) l@ lbflip ;
101: local-x! ( data offset -- ) swap xbflip swap x! ;
102: local-x@ ( offset -- data ) x@ xbflip ;
103
104: reg@ ( offset -- data ) reg-base + rl@ ;
105: reg! ( data offset -- ) reg-base + rl! ;
106: regx@ ( offset -- data ) reg-base + rx@ ;
107: regx! ( data offset -- ) reg-base + rx! ;
108
109: reg-bset ( data offset -- ) dup reg@ rot or swap reg! ;
110: reg-bclear ( data offset -- ) dup reg@ rot invert and swap reg! ;
111
112\ Conversion between cpu dma address and io dma address.
113: cpu>io-adr ( cpu-adr -- io-adr ) cpu-dma-base - io-dma-base + ;
114: io>cpu-adr ( io-adr -- cpu-adr ) io-dma-base - cpu-dma-base + ;
115
116: map-buffers ( -- )
117 /dma-blk dma-alloc to cpu-dma-base
118 cpu-dma-base /dma-blk false dma-map-in to io-dma-base
119;
120
121: unmap-buffers ( -- )
122 cpu-dma-base io-dma-base /dma-blk dma-map-out
123 cpu-dma-base /dma-blk dma-free
124 0 to cpu-dma-base 0 to io-dma-base
125;
126
127: map-regs ( -- )
128 my-address my-space h# 300.0010 or map-size map-in
129 to reg-base
130 enable-mem-space
131;
132
133: unmap-regs ( -- )
134 reg-base map-size map-out
135 0 to reg-base
136 disable-mem-space
137;
138
139headers
140
141: map-resources ( -- )
142 reg-base 0= if map-regs map-buffers then
143;
144
145: unmap-resources ( -- )
146 reg-base if unmap-buffers unmap-regs then
147;
148
149headerless