/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
/* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1988, 1989 Intel Corp. */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Set features for each architecture. List of features:
* ADDR_32: Address is 32 bits
* COUNT_24: Count is 24 bits
* DMA_4CSCD: DMA channel 4 is used for cascade of channels 0-3)
* DMA_INTR: DMA interrupt is available (always with DMA_BUF_CHAIN)
* DMA_BUF_CHAIN: DMA buffer chaining is available (always with DMA_INTR)
* MEM_TO_MEM: Memory to memory transfers available
* NO_PROG_WIDTH: Channel data width is NOT programmable
* SCATER_GATHER Scatter-gather DMA is available (code not implemented)
* ISA_MODE Standard ISA modes available
* EISA_EXT_MODE: EISA extension modes available
*/
/*
* Address is 24 bits (default) with no carry between lo word and hi byte
* Count is 16 bits (default)
*/
#define DMA_4CSCD
#define NO_PROG_WIDTH
#define ISA_MODE
#include <sys/dma_engine.h>
#include <sys/dma_i8237A.h>
#if defined(DEBUG)
static int i8237debug = 0;
#else
#define dprintf(x)
#endif /* defined(DEBUG) */
extern int EISA_chaining;
/*
* data structures for maintaining the DMACs
*/
DMAE_PATH_8, /* first 4 DMA channels default to 8-bit xfers */
0,
DMAE_PATH_16, /* last 3 DMA channels default to 16-bit xfers */
#ifdef DMA_4CSCD
#else /* !DMA_4CSCD */
#endif /* !DMA_4CSCD */
#ifdef DMA_BUF_CHAIN
{0, 0, 0, 0, 0, 0, 0, 0};
#endif /* DMA_BUF_CHAIN */
#ifdef DMA_INTR
#endif
static int d37A_set_mode(struct ddi_dmae_req *, int);
static int d37A_write_addr(ulong_t, int);
static ulong_t d37A_read_addr(int);
static int d37A_write_count(long, int);
static long d37A_read_count(int);
#ifdef DMA_BUF_CHAIN
#endif
/*
* Routine: d37A_init()
* purpose: initializes the 8237A.
* caller: dma_init()
* calls: d37A macros, d37A_init()
*/
/*ARGSUSED*/
int
{
#ifdef DMA_INTR
int error;
DDI_SUCCESS) {
if (error != DDI_INTR_NOTFOUND)
EISA_chaining = 0;
}
#else /* !DMA_INTR */
#endif /* !DMA_INTR */
return (DDI_SUCCESS);
}
/*
* Routine: d37A_valid()
* purpose: validates the channel to be acquired.
* caller: i_dmae_acquire()
* calls:
*/
int
{
#ifdef DMA_4CSCD
if (chnl == 4)
return (0);
#endif /* DMA_4CSCD */
return (1);
}
/*
* Routine: d37A_release()
* purpose: resets the 8237A mode.
* caller: i_dmae_free()
* calls:
*/
void
{
#ifdef DMA_4CSCD
if (chnl == 4)
return;
#endif /* DMA_4CSCD */
}
/*
* routine: d37A_dma_disable()
* purpose: Prevent the DMAC from responding to external hardware
* requests for DMA service on the given channel
* caller: dma_disable()
* calls: d37A macros
*/
void
{
dprintf(("d37A_dma_disable: chnl=%d mask_reg=0x%x\n",
}
/*
* routine: d37A_dma_enable()
* purpose: Enable to DMAC to respond to hardware requests for DMA
* service on the specified channel.
* caller: dma_enable()
* calls: d37A macros
*/
void
{
dprintf(("d37A_dma_enable: chnl=%d mask_reg=0x%x val=0x%x\n",
/* mutex_enter(&dma_engine_lock); */
/* mutex_exit(&dma_engine_lock); */
}
/*
* routine: d37A_get_best_mode()
* purpose: stub routine - determine optimum transfer method
* caller: dma_get_best_mode().
* calls:
*/
/* ARGSUSED */
{
return (DMAE_CYCLES_2);
}
#ifdef DMA_INTR
/*
* routine: d37A_intr()
* purpose: stub routine
* caller:
* calls: dma_intr().
*/
/*ARGSUSED*/
static uint_t
{
/* channel 4 can't interrupt */
chnl = 0;
do {
if (istate & 1) {
#ifdef DEBUG
if (chnl < 4)
else
if (mask & 1)
#endif /* DEBUG */
}
chnl++;
istate >>= 1;
} while (istate);
chnl = 0;
do {
chnl++;
nstate >>= 1;
} while (nstate);
return (DDI_INTR_CLAIMED);
}
return (DDI_INTR_UNCLAIMED);
}
#endif /* DMA_INTR */
#ifdef DMA_BUF_CHAIN
/*
* routine: dEISA_setchain()
* caller: d37A_intr()
* calls: d37A macros
*/
static void
{
if (cp) {
dprintf(("dEISA_setchain: chnl=%d next_addr=%x count=%lx\n",
} else {
/*
* clear chain enable bit
*/
}
}
#endif /* DMA_BUF_CHAIN */
/*
* routine: d37A_prog_chan()
* purpose: program the Mode registers and the Base registers of a
* DMA channel for a subsequent hardware-initiated transfer.
* caller: dma_prog_chan()
* calls: d37A_write_addr(), d37A_write_count(), d37A macros.
*/
int
{
dprintf(("d37A_prog_chan err: chnl=%d in cascade mode\n",
chnl));
return (DDI_FAILURE);
}
#ifndef MEM_TO_MEM
dprintf(("d37A_prog_chan err: memory to memory mode not supported.\n"));
return (DDI_FAILURE);
}
#endif /* !MEM_TO_MEM */
dprintf(("d37A_prog_chan: chnl=%d dmaereq=%p\n",
if (dmaereqp) {
switch (chnl) {
case DMAE_CH0:
case DMAE_CH1:
case DMAE_CH2:
case DMAE_CH3:
#ifdef NO_PROG_WIDTH
return (DDI_FAILURE);
}
#endif /* NO_PROG_WIDTH */
break;
#ifndef DMA_4CSCD
case DMAE_CH4:
#endif /* !DMA_4CSCD */
case DMAE_CH5:
case DMAE_CH6:
case DMAE_CH7:
#ifdef NO_PROG_WIDTH
return (DDI_FAILURE);
}
#endif /* NO_PROG_WIDTH */
break;
default:
return (DDI_FAILURE);
}
} else
chnl &= 3;
if (dmaereqp)
if (cp) {
#ifdef DMA_BUF_CHAIN
/*
* i/o operation has more than 1 cookie
* so enable dma buffer chaining
*/
drv_usecwait(10);
drv_usecwait(15);
}
#endif /* DMA_BUF_CHAIN */
}
return (DDI_SUCCESS);
}
/*
* routine: d37A_dma_swsetup()
* purpose: program the Mode registers and the Base register for the
* specified channel.
* caller: dma_swsetup()
* calls: d37A_write_addr(), d37A_write_count(), d37A macros.
*/
int
{
dprintf(("d37A_dma_swsetup err: chnl %d not programmed\n",
chnl));
return (DDI_FAILURE);
}
dprintf(("d37A_dma_swsetup: chnl=%d dmaereq=%p.\n",
/* MUST BE IN BLOCK MODE FOR SOFTWARE INITIATED REQUESTS */
switch (chnl) {
case DMAE_CH0:
case DMAE_CH1:
case DMAE_CH2:
case DMAE_CH3:
#ifdef NO_PROG_WIDTH
return (DDI_FAILURE);
}
#endif /* NO_PROG_WIDTH */
break;
#ifndef DMA_4CSCD
case DMAE_CH4:
#endif /* !DMA_4CSCD */
case DMAE_CH5:
case DMAE_CH6:
case DMAE_CH7:
#ifdef NO_PROG_WIDTH
return (DDI_FAILURE);
}
#endif /* NO_PROG_WIDTH */
break;
default:
return (DDI_FAILURE);
};
#ifdef DMA_BUF_CHAIN
/*
* i/o operation has more than 1 cookie
* so enable dma buffer chaining
*/
}
#endif /* DMA_BUF_CHAIN */
return (DDI_SUCCESS);
}
/*
* routine: d37A_dma_swstart()
* purpose: SW start transfer setup on the indicated channel.
* caller: dma_swstart()
* calls: d37A_dma_enable(), d37A macros
*/
void
{
}
/*
* routine: d37A_dma_stop()
* purpose: Stop any activity on the indicated channel.
* caller: dma_stop()
* calls: d37A macros
*/
void
{
}
/*
* routine: d37A_get_chan_stat()
* purpose: retrieve the Current Address and Count registers for the
* specified channel.
* caller: dma_get_chan_stat()
* calls: d37A_read_addr(), d37A_read_count().
*/
void
{
int tcount;
if (addressp)
if (countp)
dprintf(("d37A_get_chan_stat: chnl=%d address=%lx count=%x\n",
}
/*
* routine: d37A_set_mode()
* purpose: program the Mode registers of the
* DMAC for a subsequent hardware-initiated transfer.
* caller: d37A_prog_chan(), d37A_dma_swsetup
* calls:
*/
static int
{
#ifdef ISA_MODE
#if defined(lint)
#endif
switch (dmaereqp->der_command) {
case DMAE_CMD_READ:
mode |= DMAMODE_READ;
break;
case DMAE_CMD_WRITE:
mode |= DMAMODE_WRITE;
break;
case DMAE_CMD_VRFY:
mode |= DMAMODE_VERF;
break;
case DMAE_CMD_TRAN:
break;
default:
return (DDI_FAILURE);
}
mode |= DMAMODE_AUTO;
mode |= DMAMODE_DECR;
case DMAE_TRANS_SNGL:
mode |= DMAMODE_SINGLE;
break;
case DMAE_TRANS_BLCK:
mode |= DMAMODE_BLOCK;
break;
case DMAE_TRANS_DMND:
break;
case DMAE_TRANS_CSCD:
mode |= DMAMODE_CASC;
break;
default:
return (DDI_FAILURE);
}
dprintf(("d37A_set_mode: chnl=%d mode_reg=0x%x mode=0x%x\n",
#endif /* ISA_MODE */
#ifdef EISA_EXT_MODE
case DMAE_PATH_8:
/* emode |= EISA_DMA_8; */
break;
case DMAE_PATH_16:
emode |= EISA_DMA_16;
break;
case DMAE_PATH_32:
emode |= EISA_DMA_32;
break;
case DMAE_PATH_16B:
emode |= EISA_DMA_16B;
break;
default:
switch (chnl) {
case DMAE_CH0:
case DMAE_CH1:
case DMAE_CH2:
case DMAE_CH3:
/* emode |= EISA_DMA_8; */
break;
case DMAE_CH5:
case DMAE_CH6:
case DMAE_CH7:
emode |= EISA_DMA_16;
break;
}
}
dprintf(("d37A_set_mode: chnl=%d em_reg=0x%x emode=0x%x\n",
#endif /* EISA_EXT_MODE */
return (DDI_SUCCESS);
}
/*
* routine: d37A_write_addr()
* purpose: write the 24- or 32-bit physical address into the Base Address
* Register for the indicated channel.
* caller: d37A_prog_chan(), d37A_dma_swsetup().
* calls: d37A macros
*/
static int
{
switch (d37A_chnl_path[chnl]) {
case DMAE_PATH_8:
case DMAE_PATH_16B:
case DMAE_PATH_32:
/*
* program DMA controller with byte address
*/
break;
case DMAE_PATH_16:
/*
* convert byte address to shifted word address
*/
break;
default:
return (DDI_FAILURE);
}
kpreempt_disable(); /* don't preempt thread while using flip-flop */
#ifdef ADDR_32
#endif /* ADDR_32 */
return (DDI_SUCCESS);
}
/*
* routine: d37A_read_addr()
* purpose: read the 24- or 32-bit physical address from the Current Address
* Register for the indicated channel.
* caller: d37A_get_chan_stat().
* calls: d37A macros
*/
static ulong_t
{
kpreempt_disable(); /* don't preempt thread while using flip-flop */
#ifdef ADDR_32
#endif /* ADDR_32 */
switch (d37A_chnl_path[chnl]) {
case DMAE_PATH_8:
case DMAE_PATH_16B:
case DMAE_PATH_32:
/*
* return with byte address
*/
break;
case DMAE_PATH_16:
/*
* convert shifted word address to byte address
*/
break;
default:
return ((ulong_t)DDI_FAILURE);
}
return (paddress);
}
/*
* routine: d37A_write_count()
* purpose: write the 16- or 24-bit count into the Base Count Register for
* the indicated channel.
* caller: d37A_prog_chan(), d37A_dma_swsetup()
* calls: d37A macros
*/
static int
{
switch (d37A_chnl_path[chnl]) {
case DMAE_PATH_16:
/*
* Convert byte count to word count
*/
count >>= 1;
/* FALLTHROUGH */
case DMAE_PATH_8:
case DMAE_PATH_16B:
case DMAE_PATH_32:
--count;
break;
default:
return (DDI_FAILURE);
}
kpreempt_disable(); /* don't preempt thread while using flip-flop */
#ifdef COUNT_24
#endif /* COUNT_24 */
return (DDI_SUCCESS);
}
/*
* routine: d37A_read_count()
* purpose: read the 16- or 24-bit count from the Current Count Register for
* the indicated channel
* caller: d37A_get_chan_stat()
* calls: d37A macros
*/
static long
{
long count = 0;
kpreempt_disable(); /* don't preempt thread while using flip-flop */
#ifdef COUNT_24
#endif /* COUNT_24 */
#ifdef COUNT_24
#else /* !COUNT_24 */
#endif /* !COUNT_24 */
count = -1;
switch (d37A_chnl_path[chnl]) {
case DMAE_PATH_8:
case DMAE_PATH_16B:
case DMAE_PATH_32:
++count;
break;
case DMAE_PATH_16:
/*
* Convert incremented word count to byte count
*/
break;
}
return (count);
}