Home | History | Annotate | Line # | Download | only in ic
wdcvar.h revision 1.36.2.2
      1  1.36.2.2     skrll /*	$NetBSD: wdcvar.h,v 1.36.2.2 2004/08/12 11:41:27 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.29    bouyer /* XXX For scsipi_adapter and scsipi_channel. */
     45       1.8   thorpej #include <dev/scsipi/scsipi_all.h>
     46      1.24    bouyer #include <dev/scsipi/atapiconf.h>
     47       1.8   thorpej 
     48  1.36.2.1     skrll #include <dev/ic/wdcreg.h>
     49      1.22   thorpej 
     50       1.6    bouyer #define	WAITTIME    (10 * hz)    /* time to wait for a completion */
     51       1.6    bouyer 	/* this is a lot for hard drives, but not for cdroms */
     52       1.5      mark 
     53  1.36.2.1     skrll #define WDC_NREG	8 /* number of command registers */
     54  1.36.2.1     skrll #define	WDC_NSHADOWREG	2 /* number of command "shadow" registers */
     55  1.36.2.1     skrll 
     56  1.36.2.1     skrll /*
     57  1.36.2.1     skrll  * Per-channel data
     58  1.36.2.1     skrll  */
     59  1.36.2.1     skrll struct wdc_channel {
     60  1.36.2.1     skrll 	struct callout ch_callout;	/* callout handle */
     61  1.36.2.1     skrll 	int ch_channel;			/* location */
     62  1.36.2.1     skrll 	struct wdc_softc *ch_wdc;	/* controller's softc */
     63       1.6    bouyer 
     64       1.6    bouyer 	/* Our registers */
     65       1.6    bouyer 	bus_space_tag_t       cmd_iot;
     66  1.36.2.1     skrll 	bus_space_handle_t    cmd_baseioh;
     67  1.36.2.1     skrll 	bus_space_handle_t    cmd_iohs[WDC_NREG+WDC_NSHADOWREG];
     68       1.6    bouyer 	bus_space_tag_t       ctl_iot;
     69       1.6    bouyer 	bus_space_handle_t    ctl_ioh;
     70  1.36.2.2     skrll 	bus_space_tag_t       data32iot;
     71  1.36.2.2     skrll 	bus_space_handle_t    data32ioh;
     72  1.36.2.1     skrll 
     73       1.6    bouyer 	/* Our state */
     74  1.36.2.1     skrll 	volatile int ch_flags;
     75  1.36.2.1     skrll #define WDCF_SHUTDOWN 0x02	/* channel is shutting down */
     76       1.6    bouyer #define WDCF_IRQ_WAIT 0x10	/* controller is waiting for irq */
     77      1.24    bouyer #define WDCF_DMA_WAIT 0x20	/* controller is waiting for DMA */
     78  1.36.2.1     skrll #define	WDCF_DISABLED 0x80	/* channel is disabled */
     79  1.36.2.1     skrll #define WDCF_TH_RUN   0x100	/* the kenrel thread is working */
     80  1.36.2.1     skrll #define WDCF_TH_RESET 0x200	/* someone ask the thread to reset */
     81  1.36.2.1     skrll 	u_int8_t ch_status;	/* copy of status register */
     82  1.36.2.1     skrll 	u_int8_t ch_error;	/* copy of error register */
     83  1.36.2.1     skrll 
     84  1.36.2.1     skrll 	/* for the reset callback */
     85  1.36.2.1     skrll 	int ch_reset_flags;
     86  1.36.2.1     skrll 
     87  1.36.2.1     skrll 	/* per-drive info */
     88       1.6    bouyer 	struct ata_drive_datas ch_drive[2];
     89       1.6    bouyer 
     90  1.36.2.1     skrll 	struct device *atabus;	/* self */
     91  1.36.2.1     skrll 
     92  1.36.2.1     skrll 	/* ATAPI children */
     93      1.19     enami 	struct device *atapibus;
     94      1.29    bouyer 	struct scsipi_channel ch_atapi_channel;
     95      1.19     enami 
     96  1.36.2.1     skrll 	/* ATA children */
     97      1.35   thorpej 	struct device *ata_drives[2];
     98      1.35   thorpej 
     99       1.6    bouyer 	/*
    100  1.36.2.1     skrll 	 * Channel queues.  May be the same for all channels, if hw
    101  1.36.2.1     skrll 	 * channels are not independent.
    102       1.6    bouyer 	 */
    103  1.36.2.1     skrll 	struct ata_queue *ch_queue;
    104  1.36.2.1     skrll 
    105  1.36.2.1     skrll 	/* The channel kernel thread */
    106  1.36.2.1     skrll 	struct proc *ch_thread;
    107       1.6    bouyer };
    108       1.6    bouyer 
    109  1.36.2.1     skrll /*
    110  1.36.2.1     skrll  * Per-controller data
    111  1.36.2.1     skrll  */
    112  1.36.2.1     skrll struct wdc_softc {
    113  1.36.2.1     skrll 	struct device sc_dev;		/* generic device info */
    114  1.36.2.1     skrll 
    115  1.36.2.1     skrll 	int           cap;		/* controller capabilities */
    116  1.36.2.2     skrll #define	WDC_CAPABILITY_DATA16	0x0001	/* can do 16-bit data access */
    117  1.36.2.2     skrll #define	WDC_CAPABILITY_DATA32	0x0002	/* can do 32-bit data access */
    118  1.36.2.2     skrll #define WDC_CAPABILITY_MODE	0x0004	/* controller knows its PIO/DMA modes */
    119  1.36.2.2     skrll #define	WDC_CAPABILITY_DMA	0x0008	/* DMA */
    120  1.36.2.2     skrll #define	WDC_CAPABILITY_UDMA	0x0010	/* Ultra-DMA/33 */
    121  1.36.2.2     skrll #define	WDC_CAPABILITY_HWLOCK	0x0020	/* Needs to lock HW */
    122       1.6    bouyer #define	WDC_CAPABILITY_ATA_NOSTREAM 0x0040 /* Don't use stream funcs on ATA */
    123       1.6    bouyer #define	WDC_CAPABILITY_ATAPI_NOSTREAM 0x0080 /* Don't use stream f on ATAPI */
    124       1.6    bouyer #define WDC_CAPABILITY_NO_EXTRA_RESETS 0x0100 /* only reset once */
    125  1.36.2.2     skrll #define WDC_CAPABILITY_PREATA	0x0200	/* ctrl can be a pre-ata one */
    126  1.36.2.2     skrll #define WDC_CAPABILITY_IRQACK	0x0400	/* callback to ack interrupt */
    127  1.36.2.2     skrll #define WDC_CAPABILITY_NOIRQ	0x1000	/* Controller never interrupts */
    128  1.36.2.2     skrll #define WDC_CAPABILITY_SELECT	0x2000	/* Controller selects target */
    129  1.36.2.2     skrll #define	WDC_CAPABILITY_RAID	0x4000	/* Controller "supports" RAID */
    130  1.36.2.1     skrll 	u_int8_t      PIO_cap;		/* highest PIO mode supported */
    131  1.36.2.1     skrll 	u_int8_t      DMA_cap;		/* highest DMA mode supported */
    132  1.36.2.1     skrll 	u_int8_t      UDMA_cap;		/* highest UDMA mode supported */
    133  1.36.2.1     skrll 	int nchannels;			/* # channels on this controller */
    134  1.36.2.1     skrll 	struct wdc_channel **channels;  /* channel-specific data (array) */
    135       1.8   thorpej 
    136       1.8   thorpej 	/*
    137       1.8   thorpej 	 * The reference count here is used for both IDE and ATAPI devices.
    138       1.8   thorpej 	 */
    139      1.24    bouyer 	struct atapi_adapter sc_atapi_adapter;
    140       1.1       cgd 
    141  1.36.2.1     skrll 	/* Function used to probe for drives. */
    142  1.36.2.1     skrll 	void		(*drv_probe)(struct wdc_channel *);
    143  1.36.2.1     skrll 
    144       1.1       cgd 	/* if WDC_CAPABILITY_DMA set in 'cap' */
    145       1.6    bouyer 	void            *dma_arg;
    146  1.36.2.1     skrll 	int            (*dma_init)(void *, int, int, void *, size_t, int);
    147  1.36.2.1     skrll 	void           (*dma_start)(void *, int, int);
    148  1.36.2.1     skrll 	int            (*dma_finish)(void *, int, int, int);
    149      1.24    bouyer /* flags passed to dma_init */
    150      1.36  nakayama #define WDC_DMA_READ	0x01
    151      1.36  nakayama #define WDC_DMA_IRQW	0x02
    152      1.36  nakayama #define WDC_DMA_LBA48	0x04
    153  1.36.2.1     skrll 
    154  1.36.2.1     skrll /* values passed to dma_finish */
    155  1.36.2.1     skrll #define WDC_DMAEND_END	0	/* check for proper end of a DMA xfer */
    156  1.36.2.1     skrll #define WDC_DMAEND_ABRT 1	/* abort a DMA xfer, verbose */
    157  1.36.2.1     skrll #define WDC_DMAEND_ABRT_QUIET 2	/* abort a DMA xfer, quiet */
    158  1.36.2.1     skrll 
    159      1.24    bouyer 	int		dma_status; /* status returned from dma_finish() */
    160      1.24    bouyer #define WDC_DMAST_NOIRQ	0x01	/* missing IRQ */
    161      1.24    bouyer #define WDC_DMAST_ERR	0x02	/* DMA error */
    162      1.24    bouyer #define WDC_DMAST_UNDER	0x04	/* DMA underrun */
    163       1.2       leo 
    164       1.2       leo 	/* if WDC_CAPABILITY_HWLOCK set in 'cap' */
    165  1.36.2.1     skrll 	int            (*claim_hw)(void *, int);
    166  1.36.2.1     skrll 	void            (*free_hw)(void *);
    167      1.14    bouyer 
    168      1.14    bouyer 	/* if WDC_CAPABILITY_MODE set in 'cap' */
    169  1.36.2.1     skrll 	void 		(*set_modes)(struct wdc_channel *);
    170      1.33       dbj 
    171      1.33       dbj 	/* if WDC_CAPABILITY_SELECT set in 'cap' */
    172  1.36.2.1     skrll 	void		(*select)(struct wdc_channel *,int);
    173      1.25    bouyer 
    174      1.25    bouyer 	/* if WDC_CAPABILITY_IRQACK set in 'cap' */
    175  1.36.2.1     skrll 	void		(*irqack)(struct wdc_channel *);
    176  1.36.2.2     skrll 
    177  1.36.2.2     skrll 	/* overridden if the backend has a different data transfer method */
    178  1.36.2.2     skrll 	void	(*datain_pio)(struct wdc_channel *, int, void *, size_t);
    179  1.36.2.2     skrll 	void	(*dataout_pio)(struct wdc_channel *, int, void *, size_t);
    180       1.6    bouyer };
    181       1.4      kenh 
    182       1.6    bouyer /*
    183       1.6    bouyer  * Public functions which can be called by ATA or ATAPI specific parts,
    184       1.6    bouyer  * or bus-specific backends.
    185       1.6    bouyer  */
    186       1.1       cgd 
    187  1.36.2.1     skrll void	wdc_init_shadow_regs(struct wdc_channel *);
    188  1.36.2.1     skrll 
    189  1.36.2.1     skrll int	wdcprobe(struct wdc_channel *);
    190  1.36.2.1     skrll void	wdcattach(struct wdc_channel *);
    191  1.36.2.1     skrll int	wdcdetach(struct device *, int);
    192  1.36.2.1     skrll int	wdcactivate(struct device *, enum devact);
    193  1.36.2.1     skrll int	wdcintr(void *);
    194  1.36.2.1     skrll void	wdc_exec_xfer(struct wdc_channel *, struct ata_xfer *);
    195  1.36.2.1     skrll 
    196  1.36.2.1     skrll struct ata_xfer *wdc_get_xfer(int); /* int = WDC_NOSLEEP/CANSLEEP */
    197       1.6    bouyer #define WDC_CANSLEEP 0x00
    198       1.6    bouyer #define WDC_NOSLEEP 0x01
    199  1.36.2.1     skrll 
    200  1.36.2.1     skrll void	wdc_free_xfer (struct wdc_channel *, struct ata_xfer *);
    201  1.36.2.1     skrll void	wdcstart(struct wdc_channel *);
    202  1.36.2.1     skrll void	wdcrestart(void*);
    203  1.36.2.1     skrll 
    204  1.36.2.1     skrll int	wdcreset(struct wdc_channel *, int);
    205  1.36.2.1     skrll #define RESET_POLL 1
    206  1.36.2.1     skrll #define RESET_SLEEP 0 /* wdcreset will use tsleep() */
    207  1.36.2.1     skrll 
    208  1.36.2.1     skrll int	wdcwait(struct wdc_channel *, int, int, int, int);
    209  1.36.2.1     skrll #define WDCWAIT_OK	0  /* we have what we asked */
    210  1.36.2.1     skrll #define WDCWAIT_TOUT	-1 /* timed out */
    211  1.36.2.1     skrll #define WDCWAIT_THR	1  /* return, the kernel thread has been awakened */
    212  1.36.2.1     skrll 
    213  1.36.2.2     skrll void	wdc_datain_pio(struct wdc_channel *, int, void *, size_t);
    214  1.36.2.2     skrll void	wdc_dataout_pio(struct wdc_channel *, int, void *, size_t);
    215  1.36.2.2     skrll void	wdcbit_bucket(struct wdc_channel *, int);
    216  1.36.2.2     skrll 
    217  1.36.2.1     skrll int	wdc_dmawait(struct wdc_channel *, struct ata_xfer *, int);
    218  1.36.2.1     skrll void	wdccommand(struct wdc_channel *, u_int8_t, u_int8_t, u_int16_t,
    219  1.36.2.1     skrll 		   u_int8_t, u_int8_t, u_int8_t, u_int8_t);
    220  1.36.2.1     skrll void	wdccommandext(struct wdc_channel *, u_int8_t, u_int8_t, u_int64_t,
    221  1.36.2.1     skrll 		      u_int16_t);
    222  1.36.2.1     skrll void	wdccommandshort(struct wdc_channel *, int, int);
    223  1.36.2.1     skrll void	wdctimeout(void *arg);
    224  1.36.2.1     skrll void	wdc_reset_drive(struct ata_drive_datas *, int);
    225  1.36.2.1     skrll void	wdc_reset_channel(struct wdc_channel *, int);
    226  1.36.2.1     skrll 
    227  1.36.2.2     skrll int	wdc_exec_command(struct ata_drive_datas *, struct ata_command*);
    228       1.9   thorpej 
    229  1.36.2.1     skrll int	wdc_addref(struct wdc_channel *);
    230  1.36.2.1     skrll void	wdc_delref(struct wdc_channel *);
    231  1.36.2.2     skrll void	wdc_kill_pending(struct ata_drive_datas *);
    232      1.26  wrstuden 
    233  1.36.2.1     skrll void	wdc_print_modes (struct wdc_channel *);
    234  1.36.2.1     skrll void	wdc_probe_caps(struct ata_drive_datas*);
    235       1.6    bouyer 
    236       1.6    bouyer /*
    237       1.6    bouyer  * ST506 spec says that if READY or SEEKCMPLT go off, then the read or write
    238       1.6    bouyer  * command is aborted.
    239       1.6    bouyer  */
    240  1.36.2.1     skrll #define wdc_wait_for_drq(chp, timeout, flags) \
    241  1.36.2.1     skrll 		wdcwait((chp), WDCS_DRQ, WDCS_DRQ, (timeout), (flags))
    242  1.36.2.1     skrll #define wdc_wait_for_unbusy(chp, timeout, flags) \
    243  1.36.2.1     skrll 		wdcwait((chp), 0, 0, (timeout), (flags))
    244  1.36.2.1     skrll #define wdc_wait_for_ready(chp, timeout, flags) \
    245  1.36.2.1     skrll 		wdcwait((chp), WDCS_DRDY, WDCS_DRDY, (timeout), (flags))
    246  1.36.2.1     skrll 
    247       1.6    bouyer /* ATA/ATAPI specs says a device can take 31s to reset */
    248       1.6    bouyer #define WDC_RESET_WAIT 31000
    249       1.1       cgd 
    250  1.36.2.1     skrll void	wdc_atapibus_attach(struct atabus_softc *);
    251  1.36.2.1     skrll 
    252  1.36.2.1     skrll /* XXX */
    253  1.36.2.1     skrll struct atabus_softc;
    254  1.36.2.1     skrll void	atabusconfig(struct atabus_softc *);
    255  1.36.2.1     skrll 
    256  1.36.2.1     skrll #endif /* _DEV_IC_WDCVAR_H_ */
    257