Home | History | Annotate | Line # | Download | only in ata
atavar.h revision 1.2
      1  1.2  bouyer /*	$NetBSD: atavar.h,v 1.2 1998/10/12 16:09:15 bouyer Exp $	*/
      2  1.2  bouyer 
      3  1.2  bouyer /*
      4  1.2  bouyer  * Copyright (c) 1998 Manuel Bouyer.
      5  1.2  bouyer  *
      6  1.2  bouyer  * Redistribution and use in source and binary forms, with or without
      7  1.2  bouyer  * modification, are permitted provided that the following conditions
      8  1.2  bouyer  * are met:
      9  1.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     10  1.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     11  1.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     13  1.2  bouyer  *    documentation and/or other materials provided with the distribution.
     14  1.2  bouyer  * 3. All advertising materials mentioning features or use of this software
     15  1.2  bouyer  *    must display the following acknowledgement:
     16  1.2  bouyer  *	This product includes software developed by the University of
     17  1.2  bouyer  *	California, Berkeley and its contributors.
     18  1.2  bouyer  * 4. Neither the name of the University nor the names of its contributors
     19  1.2  bouyer  *    may be used to endorse or promote products derived from this software
     20  1.2  bouyer  *    without specific prior written permission.
     21  1.2  bouyer  *
     22  1.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.2  bouyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.2  bouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.2  bouyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.2  bouyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.2  bouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.2  bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.2  bouyer  * SUCH DAMAGE.
     33  1.2  bouyer  *
     34  1.2  bouyer  */
     35  1.2  bouyer 
     36  1.2  bouyer /* Hight-level functions and structures used by both ATA and ATAPI devices */
     37  1.2  bouyer 
     38  1.2  bouyer /* Datas common to drives and controller drivers */
     39  1.2  bouyer struct ata_drive_datas {
     40  1.2  bouyer     u_int8_t drive; /* drive number */
     41  1.2  bouyer     u_int8_t drive_flags; /* bitmask for drives present/absent and cap */
     42  1.2  bouyer #define DRIVE_ATA   0x01
     43  1.2  bouyer #define DRIVE_ATAPI 0x02
     44  1.2  bouyer #define DRIVE (DRIVE_ATA|DRIVE_ATAPI)
     45  1.2  bouyer #define DRIVE_CAP32 0x04
     46  1.2  bouyer #define DRIVE_DMA   0x08
     47  1.2  bouyer #define DRIVE_UDMA  0x10
     48  1.2  bouyer     /*
     49  1.2  bouyer      * Current setting of drive's PIO, DMA and UDMA modes.
     50  1.2  bouyer      * Is initialised by the disks drivers at attach time, and may be
     51  1.2  bouyer      * changed later by the controller's code if needed
     52  1.2  bouyer      */
     53  1.2  bouyer     u_int8_t PIO_mode; /* Current setting of drive's PIO mode */
     54  1.2  bouyer     u_int8_t DMA_mode; /* Current setting of drive's DMA mode */
     55  1.2  bouyer     u_int8_t UDMA_mode; /* Current setting of drive's UDMA mode */
     56  1.2  bouyer     /*
     57  1.2  bouyer      * Drive state. This is drive-type (ATA or ATAPI) dependant
     58  1.2  bouyer      * This is reset to 0 after a channel reset.
     59  1.2  bouyer      */
     60  1.2  bouyer     u_int8_t state;
     61  1.2  bouyer 
     62  1.2  bouyer     struct device *drv_softc; /* ATA drives softc, if any */
     63  1.2  bouyer     void* chnl_softc; /* channel softc */
     64  1.2  bouyer };
     65  1.2  bouyer 
     66  1.2  bouyer /* ATA/ATAPI common attachement datas */
     67  1.2  bouyer struct ata_atapi_attach {
     68  1.2  bouyer     u_int8_t aa_type; /* Type of device */
     69  1.2  bouyer #define T_ATA 0
     70  1.2  bouyer #define T_ATAPI 1
     71  1.2  bouyer     u_int8_t aa_channel; /* controller's channel */
     72  1.2  bouyer     u_int8_t aa_openings; /* Number of simultaneous commands possible */
     73  1.2  bouyer     struct ata_drive_datas *aa_drv_data;
     74  1.2  bouyer     void *aa_bus_private; /* infos specifics to this bus */
     75  1.2  bouyer };
     76  1.2  bouyer 
     77  1.2  bouyer 
     78  1.2  bouyer 
     79  1.2  bouyer 
     80  1.2  bouyer /*
     81  1.2  bouyer  * ATA/ATAPI commands description
     82  1.2  bouyer  *
     83  1.2  bouyer  * This structure defines the interface between the ATA/ATAPI device driver
     84  1.2  bouyer  * and the controller for short commands. It contains the command's parameter,
     85  1.2  bouyer  * the len of data's to read/write (if any), and a function to call upon
     86  1.2  bouyer  * completion.
     87  1.2  bouyer  * If no sleep is allowed, the driver can poll for command completion.
     88  1.2  bouyer  * Once the command completed, if the error registed is valid, the flag
     89  1.2  bouyer  * AT_ERROR is set and the error register value is copied to r_error .
     90  1.2  bouyer  * A separate interface is needed for read/write or ATAPI packet commands
     91  1.2  bouyer  * (which need multiple interrupts per commands).
     92  1.2  bouyer  */
     93  1.2  bouyer struct wdc_command {
     94  1.2  bouyer     u_int8_t r_command;  /* Parameters to upload to registers */
     95  1.2  bouyer     u_int8_t r_head;
     96  1.2  bouyer     u_int16_t r_cyl;
     97  1.2  bouyer     u_int8_t r_sector;
     98  1.2  bouyer     u_int8_t r_count;
     99  1.2  bouyer     u_int8_t r_precomp;
    100  1.2  bouyer     u_int8_t r_st_bmask; /* status register mask to wait for before command */
    101  1.2  bouyer     u_int8_t r_st_pmask; /* status register mask to wait for after command */
    102  1.2  bouyer     u_int8_t r_error;    /* error register after command done */
    103  1.2  bouyer     volatile u_int16_t flags;
    104  1.2  bouyer #define AT_READ     0x0001 /* There is data to read */
    105  1.2  bouyer #define AT_WRITE    0x0002 /* There is data to write (excl. with AT_READ) */
    106  1.2  bouyer #define AT_WAIT     0x0008 /* wait in controller code for command completion */
    107  1.2  bouyer #define AT_POLL     0x0010 /* poll for command completion (no interrupts) */
    108  1.2  bouyer #define AT_DONE     0x0020 /* command is done */
    109  1.2  bouyer #define AT_ERROR    0x0040 /* command is done with error */
    110  1.2  bouyer #define AT_TIMEOU   0x0040 /* command timed out */
    111  1.2  bouyer #define AT_DF       0x0080 /* Drive fault */
    112  1.2  bouyer     int timeout;	 /* timeout (in ms) */
    113  1.2  bouyer     void *data;          /* Data buffer address */
    114  1.2  bouyer     int bcount;           /* number of bytes to transfer */
    115  1.2  bouyer     void (*callback) __P((void*)); /* command to call once command completed */
    116  1.2  bouyer     void *callback_arg;  /* argument passed to *callback() */
    117  1.2  bouyer };
    118  1.2  bouyer 
    119  1.2  bouyer int wdc_exec_command __P((struct ata_drive_datas *, struct wdc_command*));
    120  1.2  bouyer #define WDC_COMPLETE 0x01
    121  1.2  bouyer #define WDC_QUEUED   0x02
    122  1.2  bouyer #define WDC_TRY_AGAIN 0x03
    123  1.2  bouyer 
    124  1.2  bouyer void wdc_probe_caps __P((struct ata_drive_datas*));
    125  1.2  bouyer 
    126  1.2  bouyer void wdc_reset_channel __P((struct ata_drive_datas *));
    127  1.2  bouyer 
    128  1.2  bouyer struct ataparams;
    129  1.2  bouyer int ata_get_params __P((struct ata_drive_datas*, u_int8_t,
    130  1.2  bouyer 	 struct ataparams *));
    131  1.2  bouyer int ata_set_mode __P((struct ata_drive_datas*, u_int8_t, u_int8_t));
    132  1.2  bouyer /* return code for these cmds */
    133  1.2  bouyer #define CMD_OK    0
    134  1.2  bouyer #define CMD_ERR   1
    135  1.2  bouyer #define CMD_AGAIN 2
    136