Home | History | Annotate | Line # | Download | only in ic
wdcvar.h revision 1.95
      1  1.95    bouyer /*	$NetBSD: wdcvar.h,v 1.95 2012/07/31 15:50:35 bouyer Exp $	*/
      2   1.1       cgd 
      3   1.3   mycroft /*-
      4  1.82   mycroft  * Copyright (c) 1998, 2003, 2004 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  *
     19   1.3   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.3   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.3   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.3   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.3   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.3   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.3   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.3   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.3   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.3   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.3   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1       cgd  */
     31   1.1       cgd 
     32  1.50   thorpej #ifndef _DEV_IC_WDCVAR_H_
     33  1.50   thorpej #define	_DEV_IC_WDCVAR_H_
     34  1.50   thorpej 
     35  1.57   thorpej #include <sys/callout.h>
     36  1.57   thorpej 
     37  1.85     itohy #include <dev/ata/ataconf.h>
     38  1.57   thorpej #include <dev/ic/wdcreg.h>
     39  1.22   thorpej 
     40   1.6    bouyer #define	WAITTIME    (10 * hz)    /* time to wait for a completion */
     41   1.6    bouyer 	/* this is a lot for hard drives, but not for cdroms */
     42   1.5      mark 
     43  1.45    bouyer #define WDC_NREG	8 /* number of command registers */
     44  1.57   thorpej #define	WDC_NSHADOWREG	2 /* number of command "shadow" registers */
     45   1.6    bouyer 
     46  1.95    bouyer #define WDC_MAXDRIVES	2 /* absolute max number of drives per channel */
     47  1.95    bouyer 
     48  1.75   thorpej struct wdc_regs {
     49   1.6    bouyer 	/* Our registers */
     50   1.6    bouyer 	bus_space_tag_t       cmd_iot;
     51  1.44      fvdl 	bus_space_handle_t    cmd_baseioh;
     52  1.91  jakllsch 	bus_size_t            cmd_ios;
     53  1.57   thorpej 	bus_space_handle_t    cmd_iohs[WDC_NREG+WDC_NSHADOWREG];
     54   1.6    bouyer 	bus_space_tag_t       ctl_iot;
     55   1.6    bouyer 	bus_space_handle_t    ctl_ioh;
     56  1.91  jakllsch 	bus_size_t            ctl_ios;
     57  1.75   thorpej 
     58  1.75   thorpej 	/* data32{iot,ioh} are only used for 32-bit data xfers */
     59  1.63   mycroft 	bus_space_tag_t       data32iot;
     60  1.63   mycroft 	bus_space_handle_t    data32ioh;
     61  1.87    bouyer 
     62  1.87    bouyer 	/* SATA native registers */
     63  1.87    bouyer 	bus_space_tag_t       sata_iot;
     64  1.87    bouyer 	bus_space_handle_t    sata_baseioh;
     65  1.87    bouyer 	bus_space_handle_t    sata_control;
     66  1.87    bouyer 	bus_space_handle_t    sata_status;
     67  1.87    bouyer 	bus_space_handle_t    sata_error;
     68  1.87    bouyer 
     69  1.41    bouyer };
     70  1.41    bouyer 
     71  1.53   thorpej /*
     72  1.53   thorpej  * Per-controller data
     73  1.53   thorpej  */
     74  1.53   thorpej struct wdc_softc {
     75  1.77   thorpej 	struct atac_softc sc_atac;	/* generic ATA controller info */
     76  1.53   thorpej 
     77  1.75   thorpej 	struct wdc_regs *regs;		/* register array (per-channel) */
     78  1.75   thorpej 
     79  1.95    bouyer 	int		wdc_maxdrives;	/* max number of drives per channel */
     80  1.95    bouyer 
     81  1.95    bouyer 	int		cap;		/* controller capabilities */
     82   1.6    bouyer #define WDC_CAPABILITY_NO_EXTRA_RESETS 0x0100 /* only reset once */
     83  1.63   mycroft #define WDC_CAPABILITY_PREATA	0x0200	/* ctrl can be a pre-ata one */
     84  1.80  rearnsha #define WDC_CAPABILITY_WIDEREGS 0x0400  /* Ctrl has wide (16bit) registers  */
     85  1.48   thorpej 
     86  1.86     itohy #if NATA_DMA || NATA_PIOBM
     87   1.1       cgd 	/* if WDC_CAPABILITY_DMA set in 'cap' */
     88   1.6    bouyer 	void            *dma_arg;
     89  1.50   thorpej 	int            (*dma_init)(void *, int, int, void *, size_t, int);
     90  1.50   thorpej 	void           (*dma_start)(void *, int, int);
     91  1.50   thorpej 	int            (*dma_finish)(void *, int, int, int);
     92  1.85     itohy #if NATA_PIOBM
     93  1.85     itohy 	void           (*piobm_start)(void *, int, int, int, int, int);
     94  1.85     itohy 	void           (*piobm_done)(void *, int, int);
     95  1.85     itohy #endif
     96  1.24    bouyer /* flags passed to dma_init */
     97  1.85     itohy #define WDC_DMA_READ		0x01
     98  1.85     itohy #define WDC_DMA_IRQW		0x02
     99  1.85     itohy #define WDC_DMA_LBA48		0x04
    100  1.85     itohy #define WDC_DMA_PIOBM_ATA	0x08
    101  1.85     itohy #define WDC_DMA_PIOBM_ATAPI	0x10
    102  1.85     itohy #if NATA_PIOBM
    103  1.85     itohy /* flags passed to piobm_start */
    104  1.85     itohy #define WDC_PIOBM_XFER_IRQ	0x01
    105  1.85     itohy #endif
    106  1.50   thorpej 
    107  1.60    bouyer /* values passed to dma_finish */
    108  1.60    bouyer #define WDC_DMAEND_END	0	/* check for proper end of a DMA xfer */
    109  1.60    bouyer #define WDC_DMAEND_ABRT 1	/* abort a DMA xfer, verbose */
    110  1.60    bouyer #define WDC_DMAEND_ABRT_QUIET 2	/* abort a DMA xfer, quiet */
    111  1.60    bouyer 
    112  1.24    bouyer 	int		dma_status; /* status returned from dma_finish() */
    113  1.24    bouyer #define WDC_DMAST_NOIRQ	0x01	/* missing IRQ */
    114  1.24    bouyer #define WDC_DMAST_ERR	0x02	/* DMA error */
    115  1.24    bouyer #define WDC_DMAST_UNDER	0x04	/* DMA underrun */
    116  1.86     itohy #endif	/* NATA_DMA || NATA_PIOBM */
    117   1.2       leo 
    118  1.74   thorpej 	/* Optional callback to select drive. */
    119  1.75   thorpej 	void		(*select)(struct ata_channel *,int);
    120  1.25    bouyer 
    121  1.74   thorpej 	/* Optional callback to ack IRQ. */
    122  1.75   thorpej 	void		(*irqack)(struct ata_channel *);
    123  1.64   mycroft 
    124  1.83    bouyer 	/* Optional callback to perform a bus reset */
    125  1.83    bouyer 	void		(*reset)(struct ata_channel *, int);
    126  1.83    bouyer 
    127  1.64   mycroft 	/* overridden if the backend has a different data transfer method */
    128  1.75   thorpej 	void	(*datain_pio)(struct ata_channel *, int, void *, size_t);
    129  1.75   thorpej 	void	(*dataout_pio)(struct ata_channel *, int, void *, size_t);
    130   1.1       cgd };
    131   1.1       cgd 
    132  1.76   thorpej /* Given an ata_channel, get the wdc_softc. */
    133  1.77   thorpej #define	CHAN_TO_WDC(chp)	((struct wdc_softc *)(chp)->ch_atac)
    134  1.76   thorpej 
    135  1.76   thorpej /* Given an ata_channel, get the wdc_regs. */
    136  1.76   thorpej #define	CHAN_TO_WDC_REGS(chp)	(&CHAN_TO_WDC(chp)->regs[(chp)->ch_channel])
    137  1.76   thorpej 
    138   1.6    bouyer /*
    139   1.6    bouyer  * Public functions which can be called by ATA or ATAPI specific parts,
    140   1.6    bouyer  * or bus-specific backends.
    141   1.6    bouyer  */
    142   1.1       cgd 
    143  1.75   thorpej void	wdc_allocate_regs(struct wdc_softc *);
    144  1.75   thorpej void	wdc_init_shadow_regs(struct ata_channel *);
    145  1.57   thorpej 
    146  1.75   thorpej int	wdcprobe(struct ata_channel *);
    147  1.75   thorpej void	wdcattach(struct ata_channel *);
    148  1.88    dyoung int	wdcdetach(device_t, int);
    149  1.88    dyoung void	wdc_childdetached(device_t, device_t);
    150  1.50   thorpej int	wdcintr(void *);
    151  1.50   thorpej 
    152  1.87    bouyer void	wdc_sataprobe(struct ata_channel *);
    153  1.87    bouyer void	wdc_drvprobe(struct ata_channel *);
    154  1.87    bouyer 
    155  1.50   thorpej void	wdcrestart(void*);
    156  1.50   thorpej 
    157  1.75   thorpej int	wdcwait(struct ata_channel *, int, int, int, int);
    158  1.41    bouyer #define WDCWAIT_OK	0  /* we have what we asked */
    159  1.41    bouyer #define WDCWAIT_TOUT	-1 /* timed out */
    160  1.41    bouyer #define WDCWAIT_THR	1  /* return, the kernel thread has been awakened */
    161  1.50   thorpej 
    162  1.75   thorpej void	wdcbit_bucket(struct ata_channel *, int);
    163  1.63   mycroft 
    164  1.75   thorpej int	wdc_dmawait(struct ata_channel *, struct ata_xfer *, int);
    165  1.75   thorpej void	wdccommand(struct ata_channel *, u_int8_t, u_int8_t, u_int16_t,
    166  1.50   thorpej 		   u_int8_t, u_int8_t, u_int8_t, u_int8_t);
    167  1.75   thorpej void	wdccommandext(struct ata_channel *, u_int8_t, u_int8_t, u_int64_t,
    168  1.92  jakllsch 		      u_int16_t, u_int16_t);
    169  1.75   thorpej void	wdccommandshort(struct ata_channel *, int, int);
    170  1.50   thorpej void	wdctimeout(void *arg);
    171  1.95    bouyer void	wdc_reset_drive(struct ata_drive_datas *, int, uint32_t *);
    172  1.75   thorpej void	wdc_reset_channel(struct ata_channel *, int);
    173  1.83    bouyer void	wdc_do_reset(struct ata_channel *, int);
    174  1.50   thorpej 
    175  1.65   thorpej int	wdc_exec_command(struct ata_drive_datas *, struct ata_command*);
    176   1.9   thorpej 
    177  1.81     perry /*
    178   1.6    bouyer  * ST506 spec says that if READY or SEEKCMPLT go off, then the read or write
    179   1.6    bouyer  * command is aborted.
    180  1.81     perry  */
    181  1.51   thorpej #define wdc_wait_for_drq(chp, timeout, flags) \
    182  1.41    bouyer 		wdcwait((chp), WDCS_DRQ, WDCS_DRQ, (timeout), (flags))
    183  1.51   thorpej #define wdc_wait_for_unbusy(chp, timeout, flags) \
    184  1.41    bouyer 		wdcwait((chp), 0, 0, (timeout), (flags))
    185  1.51   thorpej #define wdc_wait_for_ready(chp, timeout, flags) \
    186  1.41    bouyer 		wdcwait((chp), WDCS_DRDY, WDCS_DRDY, (timeout), (flags))
    187  1.50   thorpej 
    188   1.6    bouyer /* ATA/ATAPI specs says a device can take 31s to reset */
    189   1.6    bouyer #define WDC_RESET_WAIT 31000
    190   1.1       cgd 
    191  1.50   thorpej void	wdc_atapibus_attach(struct atabus_softc *);
    192  1.47   thorpej 
    193  1.50   thorpej #endif /* _DEV_IC_WDCVAR_H_ */
    194