Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Jul 1997 15:32:17 +0200 (MET DST)
From:      Luigi Rizzo <luigi@labinfo.iet.unipi.it>
To:        hackers@freebsd.org, multimedia@freebsd.org
Subject:   polling the status of a dma channel
Message-ID:  <199707221332.PAA22798@labinfo.iet.unipi.it>

next in thread | raw e-mail | index | archive | help
Recently I and others had a need to poll the status of a dma channel
to determine if a transfer was proceeding or not.

I came out with the following function which I placed in
/sys/i386/isa/isa.c -- the place I believe it belongs to.

Maybe we should consider adding this function to isa.c ? It would be
useful for the sound driver and probably other drivers as well.

	Cheers
	Luigi

-------------


/* 
 * isa_dmapoll returns the number of pending bytes for a dma transfer
 * on the given channel. 
 */   
 
int
isa_dmapoll(int chan)
{
    u_long phy = 0 ;
    u_long cnt = 0 ;
    u_long flags ;
    int waport;
  
    if (dma_inuse & (1 << chan) == 0) {
        printf("chan %d not acquired\n", chan);
        return -1 ;
    }
    if (dma_busy & (1 << chan) == 0) {
        printf("chan %d not busy\n", chan);
        return -2 ;
    }
    flags = splhigh();
    if ((chan & 4) == 0) { /* 8-bit channel */
        outb(DMA1_FFC, 0);
        waport =  DMA1_CHN(chan);
        phy= inb(waport) + (inb(waport) <<8) + (inb(dmapageport[chan]) <<16 );
        cnt = inb(waport+1) + (inb(waport+1)<<8) +1;
	cnt &= 0xffff ;
    } else {
        outb(DMA2_FFC, 0);
        waport = DMA2_CHN(chan - 4);
        phy= inb(waport) + (inb(waport) <<8) + (inb(dmapageport[chan]) <<16 );
        cnt = inb(waport+1) + (inb(waport+1)<<8) + 1;
        phy <<= 1;
        cnt <<= 1;
	cnt &= 0x1ffff ;
    }
    splx(flags);
    return cnt ;
}   

	Cheers
	Luigi
-----------------------------+--------------------------------------
Luigi Rizzo                  |  Dip. di Ingegneria dell'Informazione
email: luigi@iet.unipi.it    |  Universita' di Pisa
tel: +39-50-568533           |  via Diotisalvi 2, 56126 PISA (Italy)
fax: +39-50-568522           |  http://www.iet.unipi.it/~luigi/
_____________________________|______________________________________



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199707221332.PAA22798>