From owner-freebsd-hackers Tue Jul 22 07:45:55 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id HAA02418 for hackers-outgoing; Tue, 22 Jul 1997 07:45:55 -0700 (PDT) Received: from labinfo.iet.unipi.it (labinfo.iet.unipi.it [131.114.9.5]) by hub.freebsd.org (8.8.5/8.8.5) with SMTP id HAA01892; Tue, 22 Jul 1997 07:38:14 -0700 (PDT) Received: from localhost (luigi@localhost) by labinfo.iet.unipi.it (8.6.5/8.6.5) id PAA22798; Tue, 22 Jul 1997 15:32:17 +0200 From: Luigi Rizzo Message-Id: <199707221332.PAA22798@labinfo.iet.unipi.it> Subject: polling the status of a dma channel To: hackers@freebsd.org, multimedia@freebsd.org Date: Tue, 22 Jul 1997 15:32:17 +0200 (MET DST) X-Mailer: ELM [version 2.4 PL23] Content-Type: text Sender: owner-freebsd-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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/ _____________________________|______________________________________