Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / scsi / targets / 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.2 00/06/07
43purpose:
44copyright: Copyright 1995-2000 Sun Microsystems, Inc. All Rights Reserved
45
46\ This file contains some words which are useful for both SCSI disk and
47\ SCSI tape device drivers.
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
59
60\ Calls the parent device's "retry-command" method. The parent device is
61\ assumed to be a driver for a SCSI host adapter (device-type = "scsi")
62
63: retry-command ( dma-addr dma-len dma-dir cmd-addr cmd-len #retries -- ... )
64 ( ... -- false ) \ No error
65 ( ... -- true true ) \ Hardware error
66 ( ... -- sensebuf false true ) \ Fatal error with extended status
67 " retry-command" $call-parent
68;
69
70
71\ Simplified command execution routines for common simple command forms
72
73: no-data-command ( cmdbuf -- error? ) " no-data-command" $call-parent ;
74
75: short-data-command ( data-len cmdbuf cmdlen -- true | buffer false )
76 " short-data-command" $call-parent
77;
78
79
80\ Some tools for reading and writing 2, 3, and 4 byte numbers to and from
81\ SCSI command and data buffers. The ones defined below are used both in
82\ the SCSI disk and the SCSI tape packages. Other variations that are
83\ used only by one of the packages are defined in the package where they
84\ are used.
85
86: +c! ( n addr -- addr' ) tuck c! 1+ ;
87: 3c! ( n addr -- ) >r lbsplit drop r> +c! +c! c! ;
88
89: -c@ ( addr -- n addr' ) dup c@ swap 1- ;
90: 3c@ ( addr -- n ) 2 + -c@ -c@ c@ 0 bljoin ;
91: 4c@ ( addr -- n ) 3 + -c@ -c@ -c@ c@ bljoin ;
92
93
94\ "Scratch" command buffer useful for construction of read and write commands
95
96create cmdbuf 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
97: cb! ( byte index -- ) cmdbuf + c! ; \ Write byte to command buffer
98
99
100\ The deblocker converts a block/record-oriented interface to a byte-oriented
101\ interface, using internal buffering. Disk and tape devices are usually
102\ block or record oriented, but the OBP external interface is byte-oriented,
103\ in order to be independent of particular device block sizes.
104
1050 instance value deblocker
106
107\ Fix read records at no larger than 32K.
108headers
109h# 8000 value deblock-defbufsize
110
111headerless
112: init-deblocker ( -- okay? )
113 " " " deblocker" $open-package to deblocker
114 deblocker if
115 true
116 else
117 ." Can't open deblocker package" cr false
118 then
119;
120
121headers