Home | History | Annotate | Line # | Download | only in ic
wdcvar.h revision 1.36.2.4
      1  1.36.2.4     skrll /*	$NetBSD: wdcvar.h,v 1.36.2.4 2004/09/18 14:46:01 skrll Exp $	*/
      2       1.1       cgd 
      3       1.3   mycroft /*-
      4  1.36.2.1     skrll  * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
      5       1.3   mycroft  * All rights reserved.
      6       1.1       cgd  *
      7       1.3   mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8       1.3   mycroft  * by Charles M. Hannum, by Onno van der Linden and by Manuel Bouyer.
      9       1.1       cgd  *
     10       1.1       cgd  * Redistribution and use in source and binary forms, with or without
     11       1.1       cgd  * modification, are permitted provided that the following conditions
     12       1.1       cgd  * are met:
     13       1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     14       1.6    bouyer  *	notice, this list of conditions and the following disclaimer.
     15       1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.6    bouyer  *	notice, this list of conditions and the following disclaimer in the
     17       1.6    bouyer  *	documentation and/or other materials provided with the distribution.
     18       1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     19       1.1       cgd  *    must display the following acknowledgement:
     20       1.3   mycroft  *        This product includes software developed by the NetBSD
     21       1.3   mycroft  *        Foundation, Inc. and its contributors.
     22       1.3   mycroft  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.3   mycroft  *    contributors may be used to endorse or promote products derived
     24       1.3   mycroft  *    from this software without specific prior written permission.
     25       1.1       cgd  *
     26       1.3   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.3   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.3   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.3   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.3   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.3   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.3   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.3   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.3   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.3   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.3   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1       cgd  */
     38       1.1       cgd 
     39  1.36.2.1     skrll #ifndef _DEV_IC_WDCVAR_H_
     40  1.36.2.1     skrll #define	_DEV_IC_WDCVAR_H_
     41  1.36.2.1     skrll 
     42  1.36.2.1     skrll #include <sys/callout.h>
     43  1.36.2.1     skrll 
     44  1.36.2.1     skrll #include <dev/ic/wdcreg.h>
     45      1.22   thorpej 
     46       1.6    bouyer #define	WAITTIME    (10 * hz)    /* time to wait for a completion */
     47       1.6    bouyer 	/* this is a lot for hard drives, but not for cdroms */
     48       1.5      mark 
     49  1.36.2.1     skrll #define WDC_NREG	8 /* number of command registers */
     50  1.36.2.1     skrll #define	WDC_NSHADOWREG	2 /* number of command "shadow" registers */
     51  1.36.2.1     skrll 
     52  1.36.2.3     skrll struct wdc_regs {
     53       1.6    bouyer 	/* Our registers */
     54       1.6    bouyer 	bus_space_tag_t       cmd_iot;
     55  1.36.2.1     skrll 	bus_space_handle_t    cmd_baseioh;
     56  1.36.2.1     skrll 	bus_space_handle_t    cmd_iohs[WDC_NREG+WDC_NSHADOWREG];
     57       1.6    bouyer 	bus_space_tag_t       ctl_iot;
     58       1.6    bouyer 	bus_space_handle_t    ctl_ioh;
     59  1.36.2.3     skrll 
     60  1.36.2.3     skrll 	/* data32{iot,ioh} are only used for 32-bit data xfers */
     61  1.36.2.2     skrll 	bus_space_tag_t       data32iot;
     62  1.36.2.2     skrll 	bus_space_handle_t    data32ioh;
     63       1.6    bouyer };
     64       1.6    bouyer 
     65  1.36.2.1     skrll /*
     66  1.36.2.1     skrll  * Per-controller data
     67  1.36.2.1     skrll  */
     68  1.36.2.1     skrll struct wdc_softc {
     69  1.36.2.3     skrll 	struct atac_softc sc_atac;	/* generic ATA controller info */
     70  1.36.2.3     skrll 
     71  1.36.2.3     skrll 	struct wdc_regs *regs;		/* register array (per-channel) */
     72  1.36.2.1     skrll 
     73  1.36.2.1     skrll 	int           cap;		/* controller capabilities */
     74       1.6    bouyer #define WDC_CAPABILITY_NO_EXTRA_RESETS 0x0100 /* only reset once */
     75  1.36.2.2     skrll #define WDC_CAPABILITY_PREATA	0x0200	/* ctrl can be a pre-ata one */
     76  1.36.2.1     skrll 
     77       1.1       cgd 	/* if WDC_CAPABILITY_DMA set in 'cap' */
     78       1.6    bouyer 	void            *dma_arg;
     79  1.36.2.1     skrll 	int            (*dma_init)(void *, int, int, void *, size_t, int);
     80  1.36.2.1     skrll 	void           (*dma_start)(void *, int, int);
     81  1.36.2.1     skrll 	int            (*dma_finish)(void *, int, int, int);
     82      1.24    bouyer /* flags passed to dma_init */
     83      1.36  nakayama #define WDC_DMA_READ	0x01
     84      1.36  nakayama #define WDC_DMA_IRQW	0x02
     85      1.36  nakayama #define WDC_DMA_LBA48	0x04
     86  1.36.2.1     skrll 
     87  1.36.2.1     skrll /* values passed to dma_finish */
     88  1.36.2.1     skrll #define WDC_DMAEND_END	0	/* check for proper end of a DMA xfer */
     89  1.36.2.1     skrll #define WDC_DMAEND_ABRT 1	/* abort a DMA xfer, verbose */
     90  1.36.2.1     skrll #define WDC_DMAEND_ABRT_QUIET 2	/* abort a DMA xfer, quiet */
     91  1.36.2.1     skrll 
     92      1.24    bouyer 	int		dma_status; /* status returned from dma_finish() */
     93      1.24    bouyer #define WDC_DMAST_NOIRQ	0x01	/* missing IRQ */
     94      1.24    bouyer #define WDC_DMAST_ERR	0x02	/* DMA error */
     95      1.24    bouyer #define WDC_DMAST_UNDER	0x04	/* DMA underrun */
     96       1.2       leo 
     97  1.36.2.3     skrll 	/* Optional callback to select drive. */
     98  1.36.2.3     skrll 	void		(*select)(struct ata_channel *,int);
     99      1.14    bouyer 
    100  1.36.2.3     skrll 	/* Optional callback to ack IRQ. */
    101  1.36.2.3     skrll 	void		(*irqack)(struct ata_channel *);
    102  1.36.2.2     skrll 
    103  1.36.2.2     skrll 	/* overridden if the backend has a different data transfer method */
    104  1.36.2.3     skrll 	void	(*datain_pio)(struct ata_channel *, int, void *, size_t);
    105  1.36.2.3     skrll 	void	(*dataout_pio)(struct ata_channel *, int, void *, size_t);
    106       1.6    bouyer };
    107       1.4      kenh 
    108  1.36.2.3     skrll /* Given an ata_channel, get the wdc_softc. */
    109  1.36.2.3     skrll #define	CHAN_TO_WDC(chp)	((struct wdc_softc *)(chp)->ch_atac)
    110  1.36.2.3     skrll 
    111  1.36.2.3     skrll /* Given an ata_channel, get the wdc_regs. */
    112  1.36.2.3     skrll #define	CHAN_TO_WDC_REGS(chp)	(&CHAN_TO_WDC(chp)->regs[(chp)->ch_channel])
    113  1.36.2.3     skrll 
    114       1.6    bouyer /*
    115       1.6    bouyer  * Public functions which can be called by ATA or ATAPI specific parts,
    116       1.6    bouyer  * or bus-specific backends.
    117       1.6    bouyer  */
    118       1.1       cgd 
    119  1.36.2.3     skrll void	wdc_allocate_regs(struct wdc_softc *);
    120  1.36.2.3     skrll void	wdc_init_shadow_regs(struct ata_channel *);
    121  1.36.2.1     skrll 
    122  1.36.2.3     skrll int	wdcprobe(struct ata_channel *);
    123  1.36.2.3     skrll void	wdcattach(struct ata_channel *);
    124  1.36.2.1     skrll int	wdcdetach(struct device *, int);
    125  1.36.2.1     skrll int	wdcactivate(struct device *, enum devact);
    126  1.36.2.1     skrll int	wdcintr(void *);
    127  1.36.2.1     skrll 
    128  1.36.2.1     skrll void	wdcrestart(void*);
    129  1.36.2.1     skrll 
    130  1.36.2.3     skrll int	wdcwait(struct ata_channel *, int, int, int, int);
    131  1.36.2.1     skrll #define WDCWAIT_OK	0  /* we have what we asked */
    132  1.36.2.1     skrll #define WDCWAIT_TOUT	-1 /* timed out */
    133  1.36.2.1     skrll #define WDCWAIT_THR	1  /* return, the kernel thread has been awakened */
    134  1.36.2.1     skrll 
    135  1.36.2.3     skrll void	wdcbit_bucket(struct ata_channel *, int);
    136  1.36.2.2     skrll 
    137  1.36.2.3     skrll int	wdc_dmawait(struct ata_channel *, struct ata_xfer *, int);
    138  1.36.2.3     skrll void	wdccommand(struct ata_channel *, u_int8_t, u_int8_t, u_int16_t,
    139  1.36.2.1     skrll 		   u_int8_t, u_int8_t, u_int8_t, u_int8_t);
    140  1.36.2.3     skrll void	wdccommandext(struct ata_channel *, u_int8_t, u_int8_t, u_int64_t,
    141  1.36.2.1     skrll 		      u_int16_t);
    142  1.36.2.3     skrll void	wdccommandshort(struct ata_channel *, int, int);
    143  1.36.2.1     skrll void	wdctimeout(void *arg);
    144  1.36.2.1     skrll void	wdc_reset_drive(struct ata_drive_datas *, int);
    145  1.36.2.3     skrll void	wdc_reset_channel(struct ata_channel *, int);
    146  1.36.2.1     skrll 
    147  1.36.2.2     skrll int	wdc_exec_command(struct ata_drive_datas *, struct ata_command*);
    148       1.9   thorpej 
    149       1.6    bouyer /*
    150       1.6    bouyer  * ST506 spec says that if READY or SEEKCMPLT go off, then the read or write
    151       1.6    bouyer  * command is aborted.
    152       1.6    bouyer  */
    153  1.36.2.1     skrll #define wdc_wait_for_drq(chp, timeout, flags) \
    154  1.36.2.1     skrll 		wdcwait((chp), WDCS_DRQ, WDCS_DRQ, (timeout), (flags))
    155  1.36.2.1     skrll #define wdc_wait_for_unbusy(chp, timeout, flags) \
    156  1.36.2.1     skrll 		wdcwait((chp), 0, 0, (timeout), (flags))
    157  1.36.2.1     skrll #define wdc_wait_for_ready(chp, timeout, flags) \
    158  1.36.2.1     skrll 		wdcwait((chp), WDCS_DRDY, WDCS_DRDY, (timeout), (flags))
    159  1.36.2.1     skrll 
    160       1.6    bouyer /* ATA/ATAPI specs says a device can take 31s to reset */
    161       1.6    bouyer #define WDC_RESET_WAIT 31000
    162       1.1       cgd 
    163  1.36.2.1     skrll void	wdc_atapibus_attach(struct atabus_softc *);
    164  1.36.2.1     skrll 
    165  1.36.2.1     skrll #endif /* _DEV_IC_WDCVAR_H_ */
    166