Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: disk.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: @(#)disk.fth 1.12 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 | ||
49 | " disk" name | |
50 | " block" device-type | |
51 | ||
52 | hex | |
53 | 0 instance value offset-low | |
54 | 0 instance value offset-high | |
55 | 0 instance value label-package | |
56 | 0 instance value blocksize | |
57 | ||
58 | : init-label-package ( -- okay? ) | |
59 | 0 is offset-high 0 is offset-low | |
60 | my-args " disk-label" $open-package is label-package | |
61 | label-package if | |
62 | 0 0 " offset" label-package $call-method is offset-high is offset-low | |
63 | true | |
64 | else | |
65 | ." Can't open disk label package" cr false | |
66 | then | |
67 | ; | |
68 | ||
69 | 0 instance value deblocker | |
70 | : init-deblocker ( -- okay? ) | |
71 | " " " deblocker" $open-package is deblocker | |
72 | deblocker if | |
73 | true | |
74 | else | |
75 | ." Can't open deblocker package" cr false | |
76 | then | |
77 | ; | |
78 | ||
79 | /xfer-pkt instance buffer: ata-pkt | |
80 | d# 12 instance buffer: ata-cmd | |
81 | ||
82 | : do-ata ( buffer cdb timeout -- fail? ) | |
83 | ata-pkt set-pkt-data ( pkt ) | |
84 | 0 over >xfer-type l! ( pkt ) | |
85 | " run-command" $call-parent ( fail? ) | |
86 | ; | |
87 | ||
88 | : dataless-cmd ( cmd -- ) 0 swap ata-cmd tuck c! d# 10000 do-ata ; | |
89 | ||
90 | : set-block-size ( n -- ) | |
91 | dup is blocksize | |
92 | " disk-block-size" $call-parent | |
93 | ; | |
94 | ||
95 | external | |
96 | ||
97 | : spin-up ( -- ) h# E1 dataless-cmd drop ; | |
98 | : spin-down ( -- ) h# E0 dataless-cmd drop ; | |
99 | : dma-alloc ( #bytes -- vaddr ) " dma-alloc" $call-parent ; | |
100 | : dma-free ( vaddr #bytes -- ) " dma-free" $call-parent ; | |
101 | ||
102 | : block-size ( -- n ) blocksize ; | |
103 | : max-transfer ( -- n ) blocksize h# 40 * ; | |
104 | ||
105 | headerless | |
106 | \ | |
107 | \ this routine expects to never be called with #blocks > 256 | |
108 | \ (ie zero into the sector count reg) | |
109 | \ | |
110 | ||
111 | : disk-r/w-blocks ( adr block# #blocks read? -- #blocks ) | |
112 | if h# 21 else h# 31 then ( adr block# #blocks cmd ) | |
113 | ata-cmd >cmd-byte c! ( adr block# #blocks ) | |
114 | ata-cmd >#blocks c! ( adr block# ) | |
115 | ata-cmd >block# l! ( adr ) | |
116 | ata-cmd d# 2000 ( adr cdb timeout ) | |
117 | do-ata if false exit then ( -- ) | |
118 | ata-pkt >transfer-bytes l@ ( #bytes ) | |
119 | blocksize / ( #blocks ) | |
120 | ; | |
121 | ||
122 | : .bail? ( flag -- ) 0= if r> drop false then ; | |
123 | ||
124 | external | |
125 | ||
126 | : read-blocks ( adr block# #blocks -- #rd ) true disk-r/w-blocks ; | |
127 | : write-blocks ( adr block# #blocks -- #wr ) false disk-r/w-blocks ; | |
128 | ||
129 | : open ( -- flag ) | |
130 | my-unit ( lun target ) | |
131 | dup 8 >> ?dup if ( lun target port# ) | |
132 | " set-port" $call-parent .bail? ( lun target ) | |
133 | 3 and ( lun target ) | |
134 | then | |
135 | dup rot ( target target lun ) | |
136 | " set-address" $call-parent .bail? ( target ) | |
137 | h# 200 set-block-size ( target ) | |
138 | " device-present?" $call-parent .bail? ( -- ) | |
139 | spin-up ( -- ) | |
140 | init-deblocker .bail? ( -- ) | |
141 | init-label-package .bail? ( -- ) | |
142 | true ( true ) | |
143 | ; | |
144 | ||
145 | : seek ( offset.low offset.high -- okay? ) | |
146 | offset-low offset-high d+ " seek" deblocker $call-method | |
147 | ; | |
148 | : read ( adr len -- actual-len ) " read" deblocker $call-method ; | |
149 | : write ( adr len -- actual-len ) " write" deblocker $call-method ; | |
150 | : load ( adr -- size ) " load" label-package $call-method ; | |
151 | ||
152 | : close ( -- ) | |
153 | label-package close-package 0 is label-package | |
154 | deblocker close-package 0 is deblocker | |
155 | ; | |
156 | ||
157 |