Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / usb2 / device / storage / scsicom.fth
\ ========== Copyright Header Begin ==========================================
\
\ Hypervisor Software File: scsicom.fth
\
\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
\
\ - Do no alter or remove copyright notices
\
\ - Redistribution and use of this software in source and binary forms, with
\ or without modification, are permitted provided that the following
\ conditions are met:
\
\ - Redistribution of source code must retain the above copyright notice,
\ this list of conditions and the following disclaimer.
\
\ - Redistribution in binary form must reproduce the above copyright notice,
\ this list of conditions and the following disclaimer in the
\ documentation and/or other materials provided with the distribution.
\
\ Neither the name of Sun Microsystems, Inc. or the names of contributors
\ may be used to endorse or promote products derived from this software
\ without specific prior written permission.
\
\ This software is provided "AS IS," without a warranty of any kind.
\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
\
\ You acknowledge that this software is not designed, licensed or
\ intended for use in the design, construction, operation or maintenance of
\ any nuclear facility.
\
\ ========== Copyright Header End ============================================
id: @(#)scsicom.fth 1.1 07/01/04
purpose: words which are useful for both SCSI disk and SCSI tape device drivers.
copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
\ See license at end of file
hex
\ The SCSI disk and SCSI tape packages need to export dma-alloc and dma-free
\ methods so the deblocker can allocate DMA-capable buffer memory.
external
: dma-alloc ( n -- vaddr ) " dma-alloc" $call-parent ;
: dma-free ( vaddr n -- ) " dma-free" $call-parent ;
headers
: parent-max-transfer ( -- n ) " max-transfer" $call-parent ;
: parent-set-address ( target lun -- ) " set-address" $call-parent ;
\ Calls the parent device's "retry-command" method. The parent device is
\ assumed to be a driver for a SCSI host adapter (device-type = "scsi")
: retry-command ( dma-addr dma-len dma-dir cmd-addr cmd-len #retries -- ... )
( ... -- false ) \ No error
( ... -- true true ) \ Hardware error
( ... -- sensebuf false true ) \ Fatal error with extended status
" retry-command" $call-parent
;
\ Simplified command execution routines for common simple command forms
: no-data-command ( cmdbuf -- error? ) " no-data-command" $call-parent ;
: short-data-command ( data-len cmdbuf cmdlen -- true | buffer false )
" short-data-command" $call-parent
;
\ Some tools for reading and writing 2, 3, and 4 byte numbers to and from
\ SCSI command and data buffers. The ones defined below are used both in
\ the SCSI disk and the SCSI tape packages. Other variations that are
\ used only by one of the packages are defined in the package where they
\ are used.
: +c! ( n addr -- addr' ) tuck c! 1+ ;
: 3c! ( n addr -- ) >r lbsplit drop r> +c! +c! c! ;
: -c@ ( addr -- n addr' ) dup c@ swap 1- ;
: 3c@ ( addr -- n ) 2 + -c@ -c@ c@ 0 bljoin ;
: 4c@ ( addr -- n ) 3 + -c@ -c@ -c@ c@ bljoin ;
\ "Scratch" command buffer useful for construction of read and write commands
d# 10 constant /cmdbuf
create cmdbuf 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
: cb! ( byte index -- ) cmdbuf + c! ; \ Write byte to command buffer
create eject-cmd h# 1b c, 1 c, 0 c, 0 c, 2 c, 0 c,
external
: device-present? ( lun -- present? )
0 parent-set-address
" inquiry" $call-parent invert
;
: eject ( -- )
my-unit device-present? if
eject-cmd no-data-command drop
then
;
headers
\ The deblocker converts a block/record-oriented interface to a byte-oriented
\ interface, using internal buffering. Disk and tape devices are usually
\ block or record oriented, but the OBP external interface is byte-oriented,
\ in order to be independent of particular device block sizes.
0 instance value deblocker
: init-deblocker ( -- okay? )
" " " deblocker" $open-package to deblocker
deblocker if
true
else
." Can't open deblocker package" cr false
then
;
\ headerless
\ : selftest ( -- )
\ my-unit " set-address" $call-parent
\ " diagnose" $call-parent
\ ;
headers
\ LICENSE_BEGIN
\ Copyright (c) 2006 FirmWorks
\
\ Permission is hereby granted, free of charge, to any person obtaining
\ a copy of this software and associated documentation files (the
\ "Software"), to deal in the Software without restriction, including
\ without limitation the rights to use, copy, modify, merge, publish,
\ distribute, sublicense, and/or sell copies of the Software, and to
\ permit persons to whom the Software is furnished to do so, subject to
\ the following conditions:
\
\ The above copyright notice and this permission notice shall be
\ included in all copies or substantial portions of the Software.
\
\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\
\ LICENSE_END