Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / usb2 / device / storage / scsicom.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: scsicom.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: @(#)scsicom.fth 1.1 07/01/04
43purpose: words which are useful for both SCSI disk and SCSI tape device drivers.
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
45\ See license at end of file
46
47hex
48
49\ The SCSI disk and SCSI tape packages need to export dma-alloc and dma-free
50\ methods so the deblocker can allocate DMA-capable buffer memory.
51
52external
53: dma-alloc ( n -- vaddr ) " dma-alloc" $call-parent ;
54: dma-free ( vaddr n -- ) " dma-free" $call-parent ;
55headers
56
57: parent-max-transfer ( -- n ) " max-transfer" $call-parent ;
58: parent-set-address ( target lun -- ) " set-address" $call-parent ;
59
60
61\ Calls the parent device's "retry-command" method. The parent device is
62\ assumed to be a driver for a SCSI host adapter (device-type = "scsi")
63
64: retry-command ( dma-addr dma-len dma-dir cmd-addr cmd-len #retries -- ... )
65 ( ... -- false ) \ No error
66 ( ... -- true true ) \ Hardware error
67 ( ... -- sensebuf false true ) \ Fatal error with extended status
68 " retry-command" $call-parent
69;
70
71
72\ Simplified command execution routines for common simple command forms
73
74: no-data-command ( cmdbuf -- error? ) " no-data-command" $call-parent ;
75
76: short-data-command ( data-len cmdbuf cmdlen -- true | buffer false )
77 " short-data-command" $call-parent
78;
79
80
81\ Some tools for reading and writing 2, 3, and 4 byte numbers to and from
82\ SCSI command and data buffers. The ones defined below are used both in
83\ the SCSI disk and the SCSI tape packages. Other variations that are
84\ used only by one of the packages are defined in the package where they
85\ are used.
86
87: +c! ( n addr -- addr' ) tuck c! 1+ ;
88: 3c! ( n addr -- ) >r lbsplit drop r> +c! +c! c! ;
89
90: -c@ ( addr -- n addr' ) dup c@ swap 1- ;
91: 3c@ ( addr -- n ) 2 + -c@ -c@ c@ 0 bljoin ;
92: 4c@ ( addr -- n ) 3 + -c@ -c@ -c@ c@ bljoin ;
93
94
95\ "Scratch" command buffer useful for construction of read and write commands
96
97d# 10 constant /cmdbuf
98create cmdbuf 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
99: cb! ( byte index -- ) cmdbuf + c! ; \ Write byte to command buffer
100
101create eject-cmd h# 1b c, 1 c, 0 c, 0 c, 2 c, 0 c,
102
103external
104: device-present? ( lun -- present? )
105 0 parent-set-address
106 " inquiry" $call-parent invert
107;
108
109: eject ( -- )
110 my-unit device-present? if
111 eject-cmd no-data-command drop
112 then
113;
114
115headers
116
117\ The deblocker converts a block/record-oriented interface to a byte-oriented
118\ interface, using internal buffering. Disk and tape devices are usually
119\ block or record oriented, but the OBP external interface is byte-oriented,
120\ in order to be independent of particular device block sizes.
121
1220 instance value deblocker
123: init-deblocker ( -- okay? )
124 " " " deblocker" $open-package to deblocker
125 deblocker if
126 true
127 else
128 ." Can't open deblocker package" cr false
129 then
130;
131
132\ headerless
133\ : selftest ( -- )
134\ my-unit " set-address" $call-parent
135\ " diagnose" $call-parent
136\ ;
137headers
138
139\ LICENSE_BEGIN
140\ Copyright (c) 2006 FirmWorks
141\
142\ Permission is hereby granted, free of charge, to any person obtaining
143\ a copy of this software and associated documentation files (the
144\ "Software"), to deal in the Software without restriction, including
145\ without limitation the rights to use, copy, modify, merge, publish,
146\ distribute, sublicense, and/or sell copies of the Software, and to
147\ permit persons to whom the Software is furnished to do so, subject to
148\ the following conditions:
149\
150\ The above copyright notice and this permission notice shall be
151\ included in all copies or substantial portions of the Software.
152\
153\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
154\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
155\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
156\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
157\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
158\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
159\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
160\
161\ LICENSE_END