2003-07-15 05:19:42 +04:00
|
|
|
/* $NetBSD: dma.c,v 1.16 2003/07/15 01:19:48 lukem Exp $ */
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Leo Weppelman.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Leo Weppelman.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file contains special code dealing with the DMA interface
|
|
|
|
* on the Atari ST.
|
|
|
|
*
|
|
|
|
* The DMA circuitry requires some special treatment for the peripheral
|
|
|
|
* devices which make use of the ST's DMA feature (the hard disk and the
|
|
|
|
* floppy drive).
|
|
|
|
* All devices using DMA need mutually exclusive access and can follow some
|
|
|
|
* standard pattern which will be provided in this file.
|
|
|
|
*
|
|
|
|
* The file contains the following entry points:
|
|
|
|
*
|
1995-04-23 02:18:17 +04:00
|
|
|
* st_dmagrab: ensure exclusive access to the DMA circuitry
|
|
|
|
* st_dmafree: free exclusive access to the DMA circuitry
|
|
|
|
* st_dmawanted: somebody is queued waiting for DMA-access
|
1995-03-26 11:12:03 +04:00
|
|
|
* dmaint: DMA interrupt routine, switches to the current driver
|
1995-05-14 19:46:17 +04:00
|
|
|
* st_dmaaddr_set: specify 24 bit RAM address
|
|
|
|
* st_dmaaddr_get: get address of last DMA-op
|
1995-04-23 02:18:17 +04:00
|
|
|
* st_dmacomm: program DMA, flush FIFO first
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
|
|
|
|
2003-07-15 05:19:42 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__KERNEL_RCSID(0, "$NetBSD: dma.c,v 1.16 2003/07/15 01:19:48 lukem Exp $");
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
1997-01-27 10:54:40 +03:00
|
|
|
#include <sys/proc.h>
|
1995-04-30 16:04:48 +04:00
|
|
|
#include <sys/queue.h>
|
1997-01-02 00:14:47 +03:00
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/iomap.h>
|
|
|
|
#include <machine/dma.h>
|
|
|
|
|
1997-01-02 00:14:47 +03:00
|
|
|
#include <atari/atari/intr.h>
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
#define NDMA_DEV 10 /* Max 2 floppy's, 8 hard-disks */
|
1995-04-30 16:04:48 +04:00
|
|
|
typedef struct dma_entry {
|
|
|
|
TAILQ_ENTRY(dma_entry) entries; /* List pointers */
|
1996-02-22 13:10:44 +03:00
|
|
|
void (*call_func)(void *); /* Call when lock granted */
|
|
|
|
void (*int_func)(void *); /* Call on DMA interrupt */
|
|
|
|
void *softc; /* Arg. to int_func */
|
|
|
|
int *lock_stat; /* status of DMA lock */
|
1995-04-30 16:04:48 +04:00
|
|
|
} DMA_ENTRY;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Preallocated entries. An allocator seem an overkill here.
|
|
|
|
*/
|
|
|
|
static DMA_ENTRY dmatable[NDMA_DEV]; /* preallocated entries */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Heads of free and active lists:
|
|
|
|
*/
|
|
|
|
static TAILQ_HEAD(freehead, dma_entry) dma_free;
|
|
|
|
static TAILQ_HEAD(acthead, dma_entry) dma_active;
|
|
|
|
|
|
|
|
static int must_init = 1; /* Must initialize */
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1997-01-12 18:44:45 +03:00
|
|
|
int cdmaint __P((void *, int));
|
1996-02-22 13:10:44 +03:00
|
|
|
|
1997-01-02 00:14:47 +03:00
|
|
|
static void st_dma_init __P((void));
|
1995-04-30 16:04:48 +04:00
|
|
|
|
1996-02-22 13:10:44 +03:00
|
|
|
static void
|
1997-01-02 00:14:47 +03:00
|
|
|
st_dma_init()
|
1995-04-30 16:04:48 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
TAILQ_INIT(&dma_free);
|
|
|
|
TAILQ_INIT(&dma_active);
|
|
|
|
|
|
|
|
for(i = 0; i < NDMA_DEV; i++)
|
|
|
|
TAILQ_INSERT_HEAD(&dma_free, &dmatable[i], entries);
|
1997-01-02 00:14:47 +03:00
|
|
|
|
1997-01-12 18:44:45 +03:00
|
|
|
if (intr_establish(7, USER_VEC, 0, cdmaint, NULL) == NULL)
|
2002-09-27 19:35:29 +04:00
|
|
|
panic("st_dma_init: Can't establish interrupt");
|
1995-04-30 16:04:48 +04:00
|
|
|
}
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1996-02-22 13:10:44 +03:00
|
|
|
int
|
|
|
|
st_dmagrab(int_func, call_func, softc, lock_stat, rcaller)
|
|
|
|
dma_farg int_func;
|
|
|
|
dma_farg call_func;
|
|
|
|
void *softc;
|
|
|
|
int *lock_stat;
|
|
|
|
int rcaller;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
int sps;
|
1995-04-30 16:04:48 +04:00
|
|
|
DMA_ENTRY *req;
|
|
|
|
|
|
|
|
if(must_init) {
|
1997-01-02 00:14:47 +03:00
|
|
|
st_dma_init();
|
1995-04-30 16:04:48 +04:00
|
|
|
must_init = 0;
|
|
|
|
}
|
|
|
|
*lock_stat = DMA_LOCK_REQ;
|
|
|
|
|
|
|
|
sps = splhigh();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a request...
|
|
|
|
*/
|
|
|
|
if(dma_free.tqh_first == NULL)
|
2002-09-27 19:35:29 +04:00
|
|
|
panic("st_dmagrab: Too many outstanding requests");
|
1995-04-30 16:04:48 +04:00
|
|
|
req = dma_free.tqh_first;
|
|
|
|
TAILQ_REMOVE(&dma_free, dma_free.tqh_first, entries);
|
|
|
|
req->call_func = call_func;
|
|
|
|
req->int_func = int_func;
|
|
|
|
req->softc = softc;
|
|
|
|
req->lock_stat = lock_stat;
|
|
|
|
TAILQ_INSERT_TAIL(&dma_active, req, entries);
|
|
|
|
|
|
|
|
if(dma_active.tqh_first != req) {
|
1997-01-27 10:54:40 +03:00
|
|
|
if (call_func == NULL) {
|
|
|
|
do {
|
|
|
|
tsleep(&dma_active, PRIBIO, "dmalck", 0);
|
|
|
|
} while (*req->lock_stat != DMA_LOCK_GRANT);
|
|
|
|
splx(sps);
|
|
|
|
return(1);
|
|
|
|
}
|
1995-03-26 11:12:03 +04:00
|
|
|
splx(sps);
|
1995-04-23 02:18:17 +04:00
|
|
|
return(0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
1995-04-30 16:04:48 +04:00
|
|
|
splx(sps);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We're at the head of the queue, ergo: we got the lock.
|
|
|
|
*/
|
|
|
|
*lock_stat = DMA_LOCK_GRANT;
|
|
|
|
|
1997-01-27 10:54:40 +03:00
|
|
|
if(rcaller || (call_func == NULL)) {
|
1995-04-23 02:18:17 +04:00
|
|
|
/*
|
|
|
|
* Just return to caller immediately without going
|
|
|
|
* through 'call_func' first.
|
|
|
|
*/
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
(*call_func)(softc); /* Call followup function */
|
1995-04-23 02:18:17 +04:00
|
|
|
return(0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1995-04-23 02:18:17 +04:00
|
|
|
void
|
1995-04-30 16:04:48 +04:00
|
|
|
st_dmafree(softc, lock_stat)
|
|
|
|
void *softc;
|
|
|
|
int *lock_stat;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
int sps;
|
1995-04-30 16:04:48 +04:00
|
|
|
DMA_ENTRY *req;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-04-30 16:04:48 +04:00
|
|
|
sps = splhigh();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some validity checks first.
|
|
|
|
*/
|
|
|
|
if((req = dma_active.tqh_first) == NULL)
|
2002-09-27 19:35:29 +04:00
|
|
|
panic("st_dmafree: empty active queue");
|
1995-04-30 16:04:48 +04:00
|
|
|
if(req->softc != softc)
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("Caller of st_dmafree is not lock-owner!\n");
|
1995-04-30 16:04:48 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear lock status, move request from active to free queue.
|
|
|
|
*/
|
|
|
|
*lock_stat = 0;
|
|
|
|
TAILQ_REMOVE(&dma_active, req, entries);
|
|
|
|
TAILQ_INSERT_HEAD(&dma_free, req, entries);
|
|
|
|
|
|
|
|
if((req = dma_active.tqh_first) != NULL) {
|
|
|
|
*req->lock_stat = DMA_LOCK_GRANT;
|
1997-01-27 10:54:40 +03:00
|
|
|
|
|
|
|
if (req->call_func == NULL)
|
|
|
|
wakeup((caddr_t)&dma_active);
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* Call next request through softint handler. This avoids
|
|
|
|
* spl-conflicts.
|
|
|
|
*/
|
|
|
|
add_sicallback((si_farg)req->call_func, req->softc, 0);
|
|
|
|
}
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
splx(sps);
|
1995-04-30 16:04:48 +04:00
|
|
|
return;
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1995-04-23 02:18:17 +04:00
|
|
|
int
|
|
|
|
st_dmawanted()
|
|
|
|
{
|
1995-04-30 16:04:48 +04:00
|
|
|
return(dma_active.tqh_first->entries.tqe_next != NULL);
|
1995-04-23 02:18:17 +04:00
|
|
|
}
|
|
|
|
|
1997-01-12 18:44:45 +03:00
|
|
|
int
|
1997-01-02 00:14:47 +03:00
|
|
|
cdmaint(unused, sr)
|
|
|
|
void *unused;
|
1996-02-22 13:10:44 +03:00
|
|
|
int sr; /* sr at time of interrupt */
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
1996-02-22 13:10:44 +03:00
|
|
|
dma_farg int_func;
|
|
|
|
void *softc;
|
1995-05-14 19:46:17 +04:00
|
|
|
|
|
|
|
if(dma_active.tqh_first != NULL) {
|
1997-01-12 18:44:45 +03:00
|
|
|
/*
|
|
|
|
* Due to the logic of the ST-DMA chip, it is not possible to
|
|
|
|
* check for stray interrupts here...
|
|
|
|
*/
|
1995-05-14 19:46:17 +04:00
|
|
|
int_func = dma_active.tqh_first->int_func;
|
|
|
|
softc = dma_active.tqh_first->softc;
|
|
|
|
|
1996-06-18 15:10:04 +04:00
|
|
|
if(!BASEPRI(sr))
|
|
|
|
add_sicallback((si_farg)int_func, softc, 0);
|
|
|
|
else {
|
|
|
|
spl1();
|
|
|
|
(*int_func)(softc);
|
1996-07-05 23:22:21 +04:00
|
|
|
spl0();
|
1996-06-18 15:10:04 +04:00
|
|
|
}
|
1997-01-12 18:44:45 +03:00
|
|
|
return 1;
|
1996-06-18 15:10:04 +04:00
|
|
|
}
|
1997-01-12 18:44:45 +03:00
|
|
|
return 0;
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1995-04-23 02:18:17 +04:00
|
|
|
/*
|
|
|
|
* Setup address for DMA-transfer.
|
|
|
|
* Note: The order _is_ important!
|
|
|
|
*/
|
|
|
|
void
|
1995-05-14 19:46:17 +04:00
|
|
|
st_dmaaddr_set(address)
|
1995-03-26 11:12:03 +04:00
|
|
|
caddr_t address;
|
|
|
|
{
|
|
|
|
register u_long ad = (u_long)address;
|
|
|
|
|
|
|
|
DMA->dma_addr[AD_LOW ] = (ad ) & 0xff;
|
|
|
|
DMA->dma_addr[AD_MID ] = (ad >> 8) & 0xff;
|
|
|
|
DMA->dma_addr[AD_HIGH] = (ad >>16) & 0xff;
|
|
|
|
}
|
|
|
|
|
1995-05-14 19:46:17 +04:00
|
|
|
/*
|
|
|
|
* Get address from DMA unit.
|
|
|
|
*/
|
|
|
|
u_long
|
|
|
|
st_dmaaddr_get()
|
|
|
|
{
|
|
|
|
register u_long ad = 0;
|
|
|
|
|
|
|
|
ad = (DMA->dma_addr[AD_LOW ] & 0xff);
|
|
|
|
ad |= (DMA->dma_addr[AD_MID ] & 0xff) << 8;
|
|
|
|
ad |= (DMA->dma_addr[AD_HIGH] & 0xff) <<16;
|
|
|
|
return(ad);
|
|
|
|
}
|
|
|
|
|
1995-04-23 02:18:17 +04:00
|
|
|
/*
|
|
|
|
* Program the DMA-controller to transfer 'nblk' blocks of 512 bytes.
|
|
|
|
* The DMA_WRBIT trick flushes the FIFO before doing DMA.
|
|
|
|
*/
|
|
|
|
void
|
1995-05-14 19:46:17 +04:00
|
|
|
st_dmacomm(mode, nblk)
|
|
|
|
int mode, nblk;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
DMA->dma_mode = mode;
|
1995-04-23 02:18:17 +04:00
|
|
|
DMA->dma_mode = mode ^ DMA_WRBIT;
|
1995-03-26 11:12:03 +04:00
|
|
|
DMA->dma_mode = mode;
|
1995-05-14 19:46:17 +04:00
|
|
|
DMA->dma_data = nblk;
|
1995-11-07 00:13:38 +03:00
|
|
|
delay(2); /* Needed for Falcon */
|
1995-05-14 19:46:17 +04:00
|
|
|
DMA->dma_mode = DMA_SCREG | (mode & DMA_WRBIT);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|