Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: methods.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 ============================================ | |
42 | id: @(#)methods.fth 1.6 06/07/14 | |
43 | purpose: | |
44 | copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | headerless | |
48 | \ Encode-unit/decode-unit for IDE need to be defined to handle: | |
49 | \ [dev][,LUN] | |
50 | : (decode-unit) ( adr len -- lo hi ) decode-2int ; | |
51 | ||
52 | : $hxnumber ( adr,len -- n false | true ) | |
53 | dup if | |
54 | base @ >r hex $number r> base ! | |
55 | else | |
56 | 2drop 0 false | |
57 | then | |
58 | ; | |
59 | ||
60 | \ Encode-unit/decode-unit for SATA need to be defined to handle: | |
61 | \ [dev][,pPORT][,LUN] | |
62 | : (decode-sata-unit) ( adr len -- lo hi ) | |
63 | ascii , left-parse-string ( after-str before-str ) | |
64 | $hxnumber throw >r ( after-str ) | |
65 | ?dup 0= if drop 0 r> exit then | |
66 | over c@ ascii p = if | |
67 | swap 1+ swap 1- ( after-str' ) \ 1 /string | |
68 | ascii , left-parse-string ( after-str'' before-str'' ) | |
69 | $hxnumber throw ( after-str port ) | |
70 | 8 << r> or >r ( after-str ) | |
71 | then | |
72 | $hxnumber throw r> ( lo hi ) | |
73 | ; | |
74 | ||
75 | ||
76 | external | |
77 | defer decode-unit ' (decode-unit) to decode-unit | |
78 | : encode-unit ( l h -- adr,len ) | |
79 | swap ( h l ) | |
80 | <# u#s drop ascii , hold ( h ) | |
81 | dup 8 >> ?dup if | |
82 | \ We have a port#! | |
83 | u#s drop ascii p hold ascii , hold | |
84 | then | |
85 | h# 3 and u#s u#> | |
86 | ; | |
87 | ||
88 | : dma-alloc ( n -- v ) " dma-alloc" $call-parent ; | |
89 | : dma-free ( vaddr bytes -- ) " dma-free" $call-parent ; | |
90 | : dma-map-in ( vaddr n cache? -- devaddr ) " dma-map-in" $call-parent ; | |
91 | : dma-map-out ( vaddr devaddr n -- ) " dma-map-out" $call-parent ; | |
92 | ||
93 | : disk-block-size ( bytes -- ) is blocksize ; | |
94 | ||
95 | : run-command ( pkt -- error? ) | |
96 | dup >xfer-type l@ case | |
97 | 0 of run-ata endof | |
98 | 1 of run-atapi endof | |
99 | ( pkttype ) >r drop true r> | |
100 | endcase | |
101 | timeout? if false (reset) drop then | |
102 | ; | |
103 | ||
104 | : identify ( target lun -- ) | |
105 | set-address if | |
106 | h# EC id-cmd c! ( -- ) | |
107 | id-buf id-cmd d# 2000 id-pkt ( buffer cmd timeout pkt ) | |
108 | set-pkt-data run-ata if ( -- ) | |
109 | id-pkt >status l@ h# 1 and if ( -- ) | |
110 | false (reset) drop ( -- ) | |
111 | h# A1 id-cmd c! ( -- ) | |
112 | id-buf id-cmd d# 2000 id-pkt ( buffer cmd timeout pkt ) | |
113 | set-pkt-data run-ata if ( -- ) | |
114 | .not-present ( false ) | |
115 | else ( -- ) | |
116 | true ( true ) | |
117 | then ( data? ) | |
118 | else ( -- ) | |
119 | .not-present ( -- false ) | |
120 | then ( data? ) | |
121 | else ( -- ) | |
122 | true ( true ) | |
123 | then ( data? ) | |
124 | if ( -- ) | |
125 | id-buf w@ dup 4 spaces | |
126 | h# 80 bitset? if ." Removable" then space | |
127 | ." ATA" h# 8000 bitset? if ." PI" then space | |
128 | Model-# | |
129 | then | |
130 | then cr | |
131 | ; | |
132 | ||
133 | : device-present? ( target -- present? ) | |
134 | present 1 rot << and | |
135 | ; | |
136 | ||
137 | : reset&check ( -- ) | |
138 | secondary? if 4 else 2 then 0 do | |
139 | i 0 set-address if | |
140 | true (reset) if | |
141 | reset-bsy-timeout wait-!busy? if | |
142 | present h# 10 and 0= if | |
143 | present 3 i << or is present | |
144 | then | |
145 | then | |
146 | then | |
147 | then | |
148 | 2 +loop | |
149 | present h# 10 and 0= if present h# 10 or is present then | |
150 | ||
151 | ; | |
152 | ||
153 | : reset ( -- ) | |
154 | map-regs | |
155 | secondary? if 4 else 2 then 0 do | |
156 | i 0 set-address if false (reset) drop then | |
157 | 2 +loop | |
158 | unmap-regs | |
159 | ; | |
160 | ||
161 | : open ( -- flag ) | |
162 | map-regs reset&check \ reset primary | |
163 | true | |
164 | ; | |
165 | ||
166 | : close ( -- ) | |
167 | unmap-regs | |
168 | ; | |
169 | ||
170 | : show-children ( -- ) | |
171 | open 0= if exit then | |
172 | secondary? if 4 else 2 then 0 do | |
173 | ." Device " i . | |
174 | i 1 and i 1 >> | |
175 | ." ( " if .secondary else .primary then | |
176 | if .slave else .master then ." ) " cr | |
177 | 5 spaces | |
178 | present 1 i << and if | |
179 | i 0 identify | |
180 | else | |
181 | .not-present cr drop | |
182 | then cr | |
183 | loop | |
184 | close | |
185 | ; | |
186 | ||
187 | reset |