xref: /openbsd/sys/dev/pci/pciidereg.h (revision 61e87b28)
1*61e87b28Sderaadt /*	$OpenBSD: pciidereg.h,v 1.10 2013/11/26 20:33:17 deraadt Exp $	*/
231d29a7cScsapuntz /*	$NetBSD: pciidereg.h,v 1.6 2000/11/14 18:42:58 thorpej Exp $	*/
34ca53b7aSangelos 
44ca53b7aSangelos /*
54ca53b7aSangelos  * Copyright (c) 1998 Christopher G. Demetriou.  All rights reserved.
64ca53b7aSangelos  *
74ca53b7aSangelos  * Redistribution and use in source and binary forms, with or without
84ca53b7aSangelos  * modification, are permitted provided that the following conditions
94ca53b7aSangelos  * are met:
104ca53b7aSangelos  * 1. Redistributions of source code must retain the above copyright
114ca53b7aSangelos  *    notice, this list of conditions and the following disclaimer.
124ca53b7aSangelos  * 2. Redistributions in binary form must reproduce the above copyright
134ca53b7aSangelos  *    notice, this list of conditions and the following disclaimer in the
144ca53b7aSangelos  *    documentation and/or other materials provided with the distribution.
154ca53b7aSangelos  * 3. All advertising materials mentioning features or use of this software
164ca53b7aSangelos  *    must display the following acknowledgement:
174ca53b7aSangelos  *      This product includes software developed by Christopher G. Demetriou
184ca53b7aSangelos  *	for the NetBSD Project.
194ca53b7aSangelos  * 4. The name of the author may not be used to endorse or promote products
204ca53b7aSangelos  *    derived from this software without specific prior written permission
214ca53b7aSangelos  *
224ca53b7aSangelos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
234ca53b7aSangelos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
244ca53b7aSangelos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
254ca53b7aSangelos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
264ca53b7aSangelos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
274ca53b7aSangelos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
284ca53b7aSangelos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
294ca53b7aSangelos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
304ca53b7aSangelos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
314ca53b7aSangelos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
324ca53b7aSangelos  */
334ca53b7aSangelos 
3453a3e126Sgrange #ifndef _DEV_PCI_PCIIDEREG_H_
3553a3e126Sgrange #define _DEV_PCI_PCIIDEREG_H_
3653a3e126Sgrange 
374ca53b7aSangelos /*
384ca53b7aSangelos  * PCI IDE controller register definitions.
394ca53b7aSangelos  *
404ca53b7aSangelos  * Author: Christopher G. Demetriou, March 2, 1998.
414ca53b7aSangelos  *
424ca53b7aSangelos  * See "PCI IDE Controller Specification, Revision 1.0 3/4/94" and
434ca53b7aSangelos  * "Programming Interface for Bus Master IDE Controller, Revision 1.0
444ca53b7aSangelos  * 5/16/94" from the PCI SIG.
454ca53b7aSangelos  */
464ca53b7aSangelos 
474ca53b7aSangelos /*
484ca53b7aSangelos  * Number of channels per chip.  MUST NOT CHANGE (macros in pciide.c and
494ca53b7aSangelos  * this file depend on its value).
504ca53b7aSangelos  */
514ca53b7aSangelos #define	PCIIDE_NUM_CHANNELS		2
524ca53b7aSangelos 
534ca53b7aSangelos /*
544ca53b7aSangelos  * PCI base address register locations (some are per-channel).
554ca53b7aSangelos  */
564ca53b7aSangelos #define	PCIIDE_REG_CMD_BASE(chan)	(0x10 + (8 * (chan)))
574ca53b7aSangelos #define	PCIIDE_REG_CTL_BASE(chan)	(0x14 + (8 * (chan)))
584ca53b7aSangelos #define	PCIIDE_REG_BUS_MASTER_DMA	0x20
594ca53b7aSangelos 
604ca53b7aSangelos /*
614ca53b7aSangelos  * Bits in the PCI Programming Interface register (some are per-channel).
627481efa2Scsapuntz  * Bits 6-4 are defined as read-only in PCI 2.1 specification.
6331d29a7cScsapuntz  * Microsoft proposed to use these bits for independent channels
647481efa2Scsapuntz  * enable/disable. This feature is enabled based on the value of bit 6.
654ca53b7aSangelos  */
667481efa2Scsapuntz #define PCIIDE_CHANSTATUS_EN		0x40
677481efa2Scsapuntz #define PCIIDE_CHAN_EN(chan)		(0x20 >> (chan))
684ca53b7aSangelos #define	PCIIDE_INTERFACE_PCI(chan)	(0x01 << (2 * (chan)))
694ca53b7aSangelos #define	PCIIDE_INTERFACE_SETTABLE(chan)	(0x02 << (2 * (chan)))
704ca53b7aSangelos #define	PCIIDE_INTERFACE_BUS_MASTER_DMA	0x80
714ca53b7aSangelos 
724ca53b7aSangelos /*
734ca53b7aSangelos  * Compatibility address/IRQ definitions (some are per-channel).
744ca53b7aSangelos  */
754ca53b7aSangelos #define	PCIIDE_COMPAT_CMD_BASE(chan)	((chan) == 0 ? 0x1f0 : 0x170)
764ca53b7aSangelos #define	PCIIDE_COMPAT_CMD_SIZE		8
774ca53b7aSangelos #define	PCIIDE_COMPAT_CTL_BASE(chan)	((chan) == 0 ? 0x3f6 : 0x376)
784ca53b7aSangelos #define	PCIIDE_COMPAT_CTL_SIZE		1
794ca53b7aSangelos #define	PCIIDE_COMPAT_IRQ(chan)		((chan) == 0 ? 14 : 15)
807481efa2Scsapuntz 
8131d29a7cScsapuntz #define	PCIIDE_CHANNEL_NAME(chan)	((chan) == 0 ? "channel 0" : "channel 1")
8231d29a7cScsapuntz 
837481efa2Scsapuntz /*
847481efa2Scsapuntz  * definitions for IDE DMA
857481efa2Scsapuntz  * XXX maybe this should go elsewhere
867481efa2Scsapuntz  */
877481efa2Scsapuntz 
887481efa2Scsapuntz /* secondary channel registers offset */
897481efa2Scsapuntz #define IDEDMA_SCH_OFFSET 0x08
90a5043c9bSgrange #define IDEDMA_NREGS 8
917481efa2Scsapuntz 
923da708ceSgrange /* Bus master command register (per channel) */
933da708ceSgrange #define IDEDMA_CMD(chan) (0x00 + IDEDMA_SCH_OFFSET * (chan))
947481efa2Scsapuntz #define IDEDMA_CMD_WRITE 0x08
957481efa2Scsapuntz #define IDEDMA_CMD_START 0x01
967481efa2Scsapuntz 
973da708ceSgrange /* Bus master status register (per channel) */
983da708ceSgrange #define IDEDMA_CTL(chan) (0x02 + IDEDMA_SCH_OFFSET * (chan))
997481efa2Scsapuntz #define IDEDMA_CTL_DRV_DMA(d)	(0x20 << (d))
1007481efa2Scsapuntz #define IDEDMA_CTL_INTR		0x04
1017481efa2Scsapuntz #define IDEDMA_CTL_ERR		0x02
1027481efa2Scsapuntz #define IDEDMA_CTL_ACT		0x01
1037481efa2Scsapuntz 
1043da708ceSgrange /* Bus master table pointer register (per channel) */
1053da708ceSgrange #define IDEDMA_TBL(chan) (0x04 + IDEDMA_SCH_OFFSET * (chan))
1067481efa2Scsapuntz #define IDEDMA_TBL_MASK 0xfffffffc
1077481efa2Scsapuntz #define IDEDMA_TBL_ALIGN 0x00010000
1087481efa2Scsapuntz 
1097481efa2Scsapuntz /* bus master table descriptor */
1107481efa2Scsapuntz struct idedma_table {
1117481efa2Scsapuntz 	u_int32_t base_addr; /* physical base addr of memory region */
1127481efa2Scsapuntz 	u_int32_t byte_count; /* memory region length */
1137481efa2Scsapuntz #define IDEDMA_BYTE_COUNT_MASK 0x0000FFFF
1147481efa2Scsapuntz #define IDEDMA_BYTE_COUNT_EOT  0x80000000
1157481efa2Scsapuntz };
1167481efa2Scsapuntz 
1177481efa2Scsapuntz #define IDEDMA_BYTE_COUNT_MAX 0x00010000 /* Max I/O per table */
1187481efa2Scsapuntz #define IDEDMA_BYTE_COUNT_ALIGN 0x00010000
1197481efa2Scsapuntz 
1207481efa2Scsapuntz /* Number of idedma table needed */
12131d29a7cScsapuntz #define NIDEDMA_TABLES (MAXPHYS/PAGE_SIZE + 1)
12253a3e126Sgrange 
123b1caa2a2Sjsg /* Intel SCH */
124b1caa2a2Sjsg #define SCH_D0TIM	0x80
125b1caa2a2Sjsg #define SCH_D1TIM	0x84
126031afe8aSjsg #define SCH_TIM_UDMA	0x70000
127b1caa2a2Sjsg #define SCH_TIM_MDMA	0x00300
128b1caa2a2Sjsg #define SCH_TIM_PIO	0x00007
129*61e87b28Sderaadt #define SCH_TIM_SYNCDMA	(1U << 31)
130b1caa2a2Sjsg 
131b1caa2a2Sjsg #define SCH_TIM_MASK	(SCH_TIM_UDMA | SCH_TIM_MDMA | SCH_TIM_PIO)
132b1caa2a2Sjsg 
13353a3e126Sgrange #endif	/* !_DEV_PCI_PCIIDEREG_H_ */
134