xref: /freebsd/sys/dev/ata/ata-all.h (revision 55bfaed1)
18b89ef0aSSøren Schmidt /*-
28b89ef0aSSøren Schmidt  * Copyright (c) 1998,1999 S�ren Schmidt
38b89ef0aSSøren Schmidt  * All rights reserved.
48b89ef0aSSøren Schmidt  *
58b89ef0aSSøren Schmidt  * Redistribution and use in source and binary forms, with or without
68b89ef0aSSøren Schmidt  * modification, are permitted provided that the following conditions
78b89ef0aSSøren Schmidt  * are met:
88b89ef0aSSøren Schmidt  * 1. Redistributions of source code must retain the above copyright
98b89ef0aSSøren Schmidt  *    notice, this list of conditions and the following disclaimer,
108b89ef0aSSøren Schmidt  *    without modification, immediately at the beginning of the file.
118b89ef0aSSøren Schmidt  * 2. Redistributions in binary form must reproduce the above copyright
128b89ef0aSSøren Schmidt  *    notice, this list of conditions and the following disclaimer in the
138b89ef0aSSøren Schmidt  *    documentation and/or other materials provided with the distribution.
148b89ef0aSSøren Schmidt  * 3. The name of the author may not be used to endorse or promote products
158b89ef0aSSøren Schmidt  *    derived from this software without specific prior written permission.
168b89ef0aSSøren Schmidt  *
178b89ef0aSSøren Schmidt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
188b89ef0aSSøren Schmidt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
198b89ef0aSSøren Schmidt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
208b89ef0aSSøren Schmidt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
218b89ef0aSSøren Schmidt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
228b89ef0aSSøren Schmidt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
238b89ef0aSSøren Schmidt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
248b89ef0aSSøren Schmidt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
258b89ef0aSSøren Schmidt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
268b89ef0aSSøren Schmidt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
278b89ef0aSSøren Schmidt  *
2855bfaed1SSøren Schmidt  *	$Id: ata-all.h,v 1.4 1999/03/07 21:49:14 sos Exp $
298b89ef0aSSøren Schmidt  */
308b89ef0aSSøren Schmidt 
318b89ef0aSSøren Schmidt /* ATA register defines */
328b89ef0aSSøren Schmidt #define ATA_DATA			0x00	/* data register */
338b89ef0aSSøren Schmidt #define	ATA_ERROR			0x01	/* (R) error register */
3455bfaed1SSøren Schmidt #define ATA_FEATURE			0x01	/* (W) feature register */
3555bfaed1SSøren Schmidt #define		ATA_F_DMA		0x01	/* enable DMA */
3655bfaed1SSøren Schmidt #define		ATA_F_OVL		0x02	/* enable overlap */
3755bfaed1SSøren Schmidt 
3855bfaed1SSøren Schmidt #define ATA_COUNT			0x02	/* (W) sector count */
3955bfaed1SSøren Schmidt #define ATA_IREASON			0x02	/* (R) interrupt reason */
408b89ef0aSSøren Schmidt #define		ATA_I_CMD		0x01	/* cmd (1) | data (0) */
418b89ef0aSSøren Schmidt #define		ATA_I_IN		0x02	/* read (1) | write (0) */
428b89ef0aSSøren Schmidt #define		ATA_I_RELEASE		0x04	/* released bus (1) */
4355bfaed1SSøren Schmidt #define		ATA_I_TAGMASK		0xf8	/* tag mask */
448b89ef0aSSøren Schmidt 
458b89ef0aSSøren Schmidt #define	ATA_SECTOR			0x03	/* sector # */
468b89ef0aSSøren Schmidt #define	ATA_CYL_LSB			0x04	/* cylinder# LSB */
478b89ef0aSSøren Schmidt #define	ATA_CYL_MSB			0x05	/* cylinder# MSB */
488b89ef0aSSøren Schmidt #define ATA_DRIVE			0x06	/* Sector/Drive/Head register */
4955bfaed1SSøren Schmidt #define		ATA_D_LBA		0x40	/* use LBA adressing */
508b89ef0aSSøren Schmidt #define		ATA_D_IBM		0xa0	/* 512 byte sectors, ECC */
518b89ef0aSSøren Schmidt 
528b89ef0aSSøren Schmidt #define ATA_CMD				0x07	/* command register */
538b89ef0aSSøren Schmidt #define		ATA_C_ATA_IDENTIFY	0xec	/* get ATA params */
548b89ef0aSSøren Schmidt #define		ATA_C_ATAPI_IDENTIFY	0xa1	/* get ATAPI params*/
558b89ef0aSSøren Schmidt #define		ATA_C_READ		0x20	/* read command */
568b89ef0aSSøren Schmidt #define		ATA_C_WRITE		0x30	/* write command */
578b89ef0aSSøren Schmidt #define		ATA_C_READ_MULTI	0xc4	/* read multi command */
588b89ef0aSSøren Schmidt #define		ATA_C_WRITE_MULTI	0xc5	/* write multi command */
598b89ef0aSSøren Schmidt #define		ATA_C_SET_MULTI		0xc6	/* set multi size command */
6055bfaed1SSøren Schmidt #define		ATA_C_READ_DMA		0xc8	/* read w/DMA command */
6155bfaed1SSøren Schmidt #define		ATA_C_WRITE_DMA		0xca	/* write w/DMA command */
6255bfaed1SSøren Schmidt #define		ATA_C_PACKET_CMD	0xa0	/* packet command */
6355bfaed1SSøren Schmidt #define		ATA_C_SETFEATURES	0xef	/* features command */
6455bfaed1SSøren Schmidt #define		    ATA_C_FEA_SETXFER	0x03	/* set transfer mode */
658b89ef0aSSøren Schmidt 
668b89ef0aSSøren Schmidt #define ATA_STATUS			0x07	/* status register */
678b89ef0aSSøren Schmidt #define		ATA_S_ERROR		0x01	/* error */
688b89ef0aSSøren Schmidt #define		ATA_S_INDEX		0x02	/* index */
698b89ef0aSSøren Schmidt #define		ATA_S_CORR		0x04	/* data corrected */
708b89ef0aSSøren Schmidt #define		ATA_S_DRQ		0x08	/* data request */
7155bfaed1SSøren Schmidt #define		ATA_S_DSC		0x10	/* drive seek completed */
7255bfaed1SSøren Schmidt #define		ATA_S_SERV		0x10	/* drive needs service */
738b89ef0aSSøren Schmidt #define		ATA_S_DWF		0x20	/* drive write fault */
7455bfaed1SSøren Schmidt #define		ATA_S_DMRD		0x20	/* DMA ready */
758b89ef0aSSøren Schmidt #define		ATA_S_DRDY		0x40	/* drive ready */
768b89ef0aSSøren Schmidt #define		ATA_S_BSY		0x80	/* busy */
778b89ef0aSSøren Schmidt 
788b89ef0aSSøren Schmidt #define ATA_ALTPORT			0x206	/* alternate Status register */
798b89ef0aSSøren Schmidt #define 	ATA_A_IDS		0x02	/* disable interrupts */
808b89ef0aSSøren Schmidt #define		ATA_A_RESET		0x04	/* RESET controller */
818b89ef0aSSøren Schmidt #define 	ATA_A_4BIT		0x08	/* 4 head bits */
828b89ef0aSSøren Schmidt 
8355bfaed1SSøren Schmidt /* misc defines */
848b89ef0aSSøren Schmidt #define	ATA_MASTER			0x00
858b89ef0aSSøren Schmidt #define	ATA_SLAVE			0x10
868b89ef0aSSøren Schmidt #define	ATA_IOSIZE			0x08
87989fb394SSøren Schmidt #define ATA_OP_FINISHED			0x00
88989fb394SSøren Schmidt #define ATA_OP_CONTINUES		0x01
898b89ef0aSSøren Schmidt 
9055bfaed1SSøren Schmidt /* devices types */
918b89ef0aSSøren Schmidt #define ATA_ATA_MASTER			0x01
928b89ef0aSSøren Schmidt #define ATA_ATA_SLAVE			0x02
938b89ef0aSSøren Schmidt #define ATA_ATAPI_MASTER		0x04
948b89ef0aSSøren Schmidt #define ATA_ATAPI_SLAVE			0x08
958b89ef0aSSøren Schmidt 
9655bfaed1SSøren Schmidt /* busmaster DMA related defines */
9755bfaed1SSøren Schmidt #define ATA_BM_OFFSET1			0x08
9855bfaed1SSøren Schmidt #define ATA_DMA_ENTRIES			256
9955bfaed1SSøren Schmidt #define ATA_DMA_EOT			0x80000000
1008b89ef0aSSøren Schmidt 
10155bfaed1SSøren Schmidt #define ATA_BMCMD_PORT			0x00
10255bfaed1SSøren Schmidt #define ATA_BMCMD_START_STOP		0x01
10355bfaed1SSøren Schmidt #define ATA_BMCMD_WRITE_READ		0x08
10455bfaed1SSøren Schmidt 
10555bfaed1SSøren Schmidt #define ATA_BMSTAT_PORT			0x02
10655bfaed1SSøren Schmidt #define ATA_BMSTAT_MASK			0x07
10755bfaed1SSøren Schmidt #define ATA_BMSTAT_ACTIVE		0x01
10855bfaed1SSøren Schmidt #define ATA_BMSTAT_ERROR		0x02
10955bfaed1SSøren Schmidt #define ATA_BMSTAT_INTERRUPT		0x04
11055bfaed1SSøren Schmidt #define ATA_BMSTAT_DMA_MASTER		0x20
11155bfaed1SSøren Schmidt #define ATA_BMSTAT_DMA_SLAVE		0x40
11255bfaed1SSøren Schmidt 
11355bfaed1SSøren Schmidt #define ATA_BMDTP_PORT			0x04
11455bfaed1SSøren Schmidt 
11555bfaed1SSøren Schmidt #define ATA_WDMA2			0x22
11655bfaed1SSøren Schmidt #define ATA_UDMA2			0x42
11755bfaed1SSøren Schmidt 
11855bfaed1SSøren Schmidt /* structure for holding DMA address data */
11955bfaed1SSøren Schmidt struct ata_dmaentry {
12055bfaed1SSøren Schmidt         u_int32_t base;
12155bfaed1SSøren Schmidt         u_int32_t count;
12255bfaed1SSøren Schmidt };
12355bfaed1SSøren Schmidt 
12455bfaed1SSøren Schmidt /* structure describing an ATA device */
12555bfaed1SSøren Schmidt struct ata_softc {
12655bfaed1SSøren Schmidt     int32_t			unit;		/* unit on this controller */
12755bfaed1SSøren Schmidt     int32_t			lun;		/* logical unit # */
12855bfaed1SSøren Schmidt     pcici_t			tag;		/* PCI tag for this device */
12955bfaed1SSøren Schmidt     int32_t			ioaddr;		/* port addr */
13055bfaed1SSøren Schmidt     int32_t			altioaddr;	/* alternate port addr */
13155bfaed1SSøren Schmidt     int32_t			bmaddr;		/* bus master DMA port */
13255bfaed1SSøren Schmidt     struct ata_dmaentry		*dmatab[2];	/* DMA transfer tables */
13355bfaed1SSøren Schmidt     int32_t			flags;		/* controller flags */
1348b89ef0aSSøren Schmidt     int32_t			devices;	/* what is present */
1358b89ef0aSSøren Schmidt     u_int8_t			status;		/* last controller status */
1368b89ef0aSSøren Schmidt     u_int8_t			error;		/* last controller error */
1378b89ef0aSSøren Schmidt     int32_t			active;		/* active processing request */
1388b89ef0aSSøren Schmidt #define		ATA_IDLE		0x0
1392e526e2aSSøren Schmidt #define		ATA_IMMEDIATE		0x0
1402e526e2aSSøren Schmidt #define		ATA_WAIT_INTR		0x1
1412e526e2aSSøren Schmidt #define		ATA_IGNORE_INTR		0x2
1422e526e2aSSøren Schmidt #define		ATA_ACTIVE_ATA		0x3
1432e526e2aSSøren Schmidt #define		ATA_ACTIVE_ATAPI	0x4
1448b89ef0aSSøren Schmidt 
1458b89ef0aSSøren Schmidt     struct buf_queue_head       ata_queue;      /* head of ATA queue */
1468b89ef0aSSøren Schmidt     TAILQ_HEAD(, atapi_request) atapi_queue;    /* head of ATAPI queue */
1478b89ef0aSSøren Schmidt };
1488b89ef0aSSøren Schmidt 
1498b89ef0aSSøren Schmidt #define MAXATA	8
1508b89ef0aSSøren Schmidt 
1518b89ef0aSSøren Schmidt extern struct ata_softc *atadevices[];
1528b89ef0aSSøren Schmidt 
1538b89ef0aSSøren Schmidt /* public prototypes */
1548b89ef0aSSøren Schmidt void ata_start(struct ata_softc *);
15555bfaed1SSøren Schmidt int32_t ata_wait(struct ata_softc *, int32_t, u_int8_t);
15655bfaed1SSøren Schmidt int32_t ata_command(struct ata_softc *, int32_t, u_int32_t, u_int32_t, u_int32_t, u_int32_t, u_int32_t, u_int32_t, int32_t);
15755bfaed1SSøren Schmidt int32_t ata_dmainit(struct ata_softc *, int32_t, int32_t, int32_t, int32_t);
15855bfaed1SSøren Schmidt int32_t ata_dmasetup(struct ata_softc *, int32_t, int8_t *, int32_t, int32_t);
15955bfaed1SSøren Schmidt void ata_dmastart(struct ata_softc *, int32_t);
16055bfaed1SSøren Schmidt int32_t ata_dmastatus(struct ata_softc *, int32_t);
16155bfaed1SSøren Schmidt int32_t ata_dmadone(struct ata_softc *, int32_t);
1622e526e2aSSøren Schmidt void bswap(int8_t *, int32_t);
1632e526e2aSSøren Schmidt void btrim(int8_t *, int32_t);
1648b89ef0aSSøren Schmidt void bpack(int8_t *, int8_t *, int32_t);
1658b89ef0aSSøren Schmidt 
166