Home | History | Annotate | Line # | Download | only in ata
satafis_subr.c revision 1.3
      1 /* $NetBSD: satafis_subr.c,v 1.3 2009/07/04 20:57:15 jakllsch Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2009 Jonathan A. Kollasch.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 /*
     29  * Copyright (c) 2006 Manuel Bouyer.
     30  *
     31  * Redistribution and use in source and binary forms, with or without
     32  * modification, are permitted provided that the following conditions
     33  * are met:
     34  * 1. Redistributions of source code must retain the above copyright
     35  *    notice, this list of conditions and the following disclaimer.
     36  * 2. Redistributions in binary form must reproduce the above copyright
     37  *    notice, this list of conditions and the following disclaimer in the
     38  *    documentation and/or other materials provided with the distribution.
     39  * 3. All advertising materials mentioning features or use of this software
     40  *    must display the following acknowledgement:
     41  *	This product includes software developed by Manuel Bouyer.
     42  * 4. The name of the author may not be used to endorse or promote products
     43  *    derived from this software without specific prior written permission.
     44  *
     45  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     46  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     47  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     48  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     49  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     50  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     51  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     52  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     53  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     54  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     55  *
     56  */
     57 
     58 #include <sys/cdefs.h>
     59 __KERNEL_RCSID(0, "$NetBSD: satafis_subr.c,v 1.3 2009/07/04 20:57:15 jakllsch Exp $");
     60 
     61 #include <sys/param.h>
     62 #include <sys/systm.h>
     63 
     64 #include <sys/disklabel.h>
     65 
     66 #include <dev/ata/atareg.h>
     67 #include <dev/ata/atavar.h>
     68 
     69 #include <dev/ata/satafisreg.h>
     70 #include <dev/ata/satafisvar.h>
     71 
     72 #include <dev/ic/wdcreg.h> /* for WDCTL_4BIT */
     73 
     74 #include "atapibus.h"
     75 
     76 void
     77 satafis_rhd_construct_cmd(struct ata_command *ata_c, uint8_t *fis)
     78 {
     79 	memset(fis, 0, RHD_FISLEN);
     80 
     81 	fis[fis_type] = RHD_FISTYPE;
     82 	fis[rhd_cdpmp] = 0x80; /* xxx magic */
     83 	fis[rhd_command] = ata_c->r_command;
     84 	fis[rhd_features] = ata_c->r_features;
     85 	fis[rhd_sector] = ata_c->r_sector;
     86 	fis[rhd_cyl_lo] = ata_c->r_cyl & 0xff;
     87 	fis[rhd_cyl_hi] = (ata_c->r_cyl >> 8) & 0xff;
     88 	fis[rhd_dh] = ata_c->r_head & 0x0f;
     89 	fis[rhd_seccnt] = ata_c->r_count;
     90 	fis[rhd_control] = WDCTL_4BIT;
     91 
     92 	return;
     93 }
     94 
     95 void
     96 satafis_rhd_construct_bio(struct ata_xfer *xfer, uint8_t *fis)
     97 {
     98 	struct ata_bio *ata_bio = xfer->c_cmd;
     99 	int nblks;
    100 
    101 	nblks = xfer->c_bcount / ata_bio->lp->d_secsize;
    102 
    103 	memset(fis, 0, RHD_FISLEN);
    104 
    105 	fis[fis_type] = RHD_FISTYPE;
    106 	fis[rhd_cdpmp] = 0x80; /* xxx magic */
    107 	if (ata_bio->flags & ATA_LBA48) {
    108 		fis[rhd_command] = (ata_bio->flags & ATA_READ) ?
    109 		    WDCC_READDMA_EXT : WDCC_WRITEDMA_EXT;
    110 	} else {
    111 		fis[rhd_command] =
    112 		    (ata_bio->flags & ATA_READ) ? WDCC_READDMA : WDCC_WRITEDMA;
    113 	}
    114 	fis[rhd_sector] = ata_bio->blkno & 0xff;
    115 	fis[rhd_cyl_lo] = (ata_bio->blkno >> 8) & 0xff;
    116 	fis[rhd_cyl_hi] = (ata_bio->blkno >> 16) & 0xff;
    117 	if (ata_bio->flags & ATA_LBA48) {
    118 		fis[rhd_dh] = WDSD_LBA;
    119 		fis[rhd_sector_exp] = (ata_bio->blkno >> 24) & 0xff;
    120 		fis[rhd_cyl_lo_exp] = (ata_bio->blkno >> 32) & 0xff;
    121 		fis[rhd_cyl_hi_exp] = (ata_bio->blkno >> 40) & 0xff;
    122 	} else {
    123 		fis[rhd_dh] = ((ata_bio->blkno >> 24) & 0x0f) | WDSD_LBA;
    124 	}
    125 	fis[rhd_seccnt] = nblks & 0xff;
    126 	fis[rhd_seccnt_exp] = (ata_bio->flags & ATA_LBA48) ?
    127 	    ((nblks >> 8) & 0xff) : 0;
    128 	fis[rhd_control] = WDCTL_4BIT;
    129 	return;
    130 }
    131 
    132 #if NATAPIBUS > 0
    133 void
    134 satafis_rhd_construct_atapi(struct ata_xfer *xfer, uint8_t *fis)
    135 {
    136 	memset(fis, 0, RHD_FISLEN);
    137 
    138 	fis[fis_type] = RHD_FISTYPE;
    139 	fis[rhd_cdpmp] = 0x80; /* xxx magic */
    140 	fis[rhd_command] = ATAPI_PKT_CMD;
    141 	fis[rhd_features] = (xfer->c_flags & C_DMA) ?
    142 	    ATAPI_PKT_CMD_FTRE_DMA : 0;
    143 	fis[rhd_dh] = WDSD_IBM; /* XXX or WDSD_LBA? */
    144 	fis[rhd_control] = WDCTL_4BIT;
    145 
    146 	return;
    147 }
    148 #endif /* NATAPIBUS */
    149 
    150 void
    151 satafis_rdh_parse(struct ata_channel *chp, uint8_t *fis)
    152 {
    153 #if 0
    154 	/* siisata doesn't do enough for this to work */
    155 	KASSERT(fis[fis_type] == RDH_FISTYPE);
    156 #endif
    157 	chp->ch_status = fis[rdh_status];
    158 	chp->ch_error = fis[rdh_error];
    159 
    160 	return;
    161 }
    162