2000-11-14 21:21:00 +03:00
|
|
|
/* $NetBSD: isadma.c,v 1.46 2000/11/14 18:28:16 thorpej Exp $ */
|
1997-06-07 03:43:45 +04:00
|
|
|
|
|
|
|
/*-
|
2000-02-08 01:07:27 +03:00
|
|
|
* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
|
1997-06-07 03:43:45 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
|
|
|
* NASA Ames Research Center.
|
|
|
|
*
|
|
|
|
* 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 the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``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 FOUNDATION OR CONTRIBUTORS
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device driver for the ISA on-board DMA controller.
|
|
|
|
*/
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1993-10-17 08:34:23 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1996-04-30 00:02:32 +04:00
|
|
|
#include <sys/proc.h>
|
1997-06-07 03:43:45 +04:00
|
|
|
#include <sys/device.h>
|
1998-06-09 04:00:21 +04:00
|
|
|
#include <sys/malloc.h>
|
1994-04-23 02:58:50 +04:00
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
#include <machine/bus.h>
|
1993-10-17 08:34:23 +03:00
|
|
|
|
2000-06-28 20:27:51 +04:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
#include <dev/isa/isareg.h>
|
1997-06-07 03:43:45 +04:00
|
|
|
#include <dev/isa/isavar.h>
|
1995-04-17 16:06:30 +04:00
|
|
|
#include <dev/isa/isadmavar.h>
|
|
|
|
#include <dev/isa/isadmareg.h>
|
1993-10-14 08:22:57 +03:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
struct isa_mem *isa_mem_head;
|
1997-07-27 05:16:32 +04:00
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
/*
|
|
|
|
* High byte of DMA address is stored in this DMAPG register for
|
|
|
|
* the Nth DMA channel.
|
|
|
|
*/
|
1996-04-01 00:51:43 +04:00
|
|
|
static int dmapageport[2][4] = {
|
1997-06-07 03:43:45 +04:00
|
|
|
{0x7, 0x3, 0x1, 0x2},
|
|
|
|
{0xf, 0xb, 0x9, 0xa}
|
1996-03-01 07:08:13 +03:00
|
|
|
};
|
|
|
|
|
1998-06-28 10:59:35 +04:00
|
|
|
static u_int8_t dmamode[] = {
|
|
|
|
/* write to device/read from device */
|
1996-03-01 07:08:13 +03:00
|
|
|
DMA37MD_READ | DMA37MD_SINGLE,
|
1996-03-01 07:35:27 +03:00
|
|
|
DMA37MD_WRITE | DMA37MD_SINGLE,
|
1998-06-28 10:59:35 +04:00
|
|
|
|
1999-02-22 05:32:43 +03:00
|
|
|
/* write to device/read from device */
|
|
|
|
DMA37MD_READ | DMA37MD_DEMAND,
|
|
|
|
DMA37MD_WRITE | DMA37MD_DEMAND,
|
|
|
|
|
1998-06-28 10:59:35 +04:00
|
|
|
/* write to device/read from device - DMAMODE_LOOP */
|
1997-05-30 01:46:07 +04:00
|
|
|
DMA37MD_READ | DMA37MD_SINGLE | DMA37MD_LOOP,
|
1998-06-28 10:59:35 +04:00
|
|
|
DMA37MD_WRITE | DMA37MD_SINGLE | DMA37MD_LOOP,
|
|
|
|
|
|
|
|
/* write to device/read from device - DMAMODE_LOOPDEMAND */
|
|
|
|
DMA37MD_READ | DMA37MD_DEMAND | DMA37MD_LOOP,
|
|
|
|
DMA37MD_WRITE | DMA37MD_DEMAND | DMA37MD_LOOP,
|
1996-03-01 07:08:13 +03:00
|
|
|
};
|
1993-10-14 08:22:57 +03:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
static inline void _isa_dmaunmask __P((struct isa_dma_state *, int));
|
|
|
|
static inline void _isa_dmamask __P((struct isa_dma_state *, int));
|
1996-04-30 00:02:32 +04:00
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
static inline void
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmaunmask(ids, chan)
|
|
|
|
struct isa_dma_state *ids;
|
1997-03-21 05:17:11 +03:00
|
|
|
int chan;
|
|
|
|
{
|
|
|
|
int ochan = chan & 3;
|
|
|
|
|
1998-06-09 05:04:17 +04:00
|
|
|
ISA_DMA_MASK_CLR(ids, chan);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If DMA is frozen, don't unmask it now. It will be
|
|
|
|
* unmasked when DMA is thawed again.
|
|
|
|
*/
|
|
|
|
if (ids->ids_frozen)
|
|
|
|
return;
|
|
|
|
|
1997-03-21 05:17:11 +03:00
|
|
|
/* set dma channel mode, and set dma channel mode */
|
|
|
|
if ((chan & 4) == 0)
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma1h,
|
1997-06-07 03:43:45 +04:00
|
|
|
DMA1_SMSK, ochan | DMA37SM_CLEAR);
|
1997-03-21 05:17:11 +03:00
|
|
|
else
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma2h,
|
1997-06-07 03:43:45 +04:00
|
|
|
DMA2_SMSK, ochan | DMA37SM_CLEAR);
|
1997-03-21 05:17:11 +03:00
|
|
|
}
|
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
static inline void
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamask(ids, chan)
|
|
|
|
struct isa_dma_state *ids;
|
1997-03-21 05:17:11 +03:00
|
|
|
int chan;
|
|
|
|
{
|
|
|
|
int ochan = chan & 3;
|
|
|
|
|
1998-06-09 05:04:17 +04:00
|
|
|
ISA_DMA_MASK_SET(ids, chan);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Should we avoid masking the channel if DMA is
|
|
|
|
* XXX frozen? It seems like what we're doing should
|
|
|
|
* XXX be safe, and we do need to reset FFC...
|
|
|
|
*/
|
|
|
|
|
1997-03-21 05:17:11 +03:00
|
|
|
/* set dma channel mode, and set dma channel mode */
|
|
|
|
if ((chan & 4) == 0) {
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma1h,
|
1997-06-07 03:43:45 +04:00
|
|
|
DMA1_SMSK, ochan | DMA37SM_SET);
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma1h,
|
1997-06-07 03:43:45 +04:00
|
|
|
DMA1_FFC, 0);
|
1997-03-21 05:17:11 +03:00
|
|
|
} else {
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma2h,
|
1997-06-07 03:43:45 +04:00
|
|
|
DMA2_SMSK, ochan | DMA37SM_SET);
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma2h,
|
1997-06-07 03:43:45 +04:00
|
|
|
DMA2_FFC, 0);
|
1997-03-21 05:17:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-10-22 23:24:14 +03:00
|
|
|
/*
|
1998-06-09 04:00:21 +04:00
|
|
|
* _isa_dmainit(): Initialize the isa_dma_state for this chipset.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_isa_dmainit(ids, bst, dmat, dev)
|
|
|
|
struct isa_dma_state *ids;
|
|
|
|
bus_space_tag_t bst;
|
|
|
|
bus_dma_tag_t dmat;
|
|
|
|
struct device *dev;
|
|
|
|
{
|
2000-02-08 01:07:27 +03:00
|
|
|
int chan;
|
1998-06-09 04:00:21 +04:00
|
|
|
|
|
|
|
ids->ids_dev = dev;
|
|
|
|
|
|
|
|
if (ids->ids_initialized) {
|
|
|
|
/*
|
|
|
|
* Some systems may have e.g. `ofisa' (OpenFirmware
|
|
|
|
* configuration of ISA bus) and a regular `isa'.
|
|
|
|
* We allow both to call the initialization function,
|
|
|
|
* and take the device name from the last caller
|
|
|
|
* (assuming it will be the indirect ISA bus). Since
|
|
|
|
* `ofisa' and `isa' are the same bus with different
|
|
|
|
* configuration mechanisms, the space and dma tags
|
|
|
|
* must be the same!
|
|
|
|
*/
|
|
|
|
if (ids->ids_bst != bst || ids->ids_dmat != dmat)
|
|
|
|
panic("_isa_dmainit: inconsistent ISA tags");
|
|
|
|
} else {
|
|
|
|
ids->ids_bst = bst;
|
|
|
|
ids->ids_dmat = dmat;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map the registers used by the ISA DMA controller.
|
|
|
|
*/
|
|
|
|
if (bus_space_map(ids->ids_bst, IO_DMA1, DMA1_IOSIZE, 0,
|
|
|
|
&ids->ids_dma1h))
|
|
|
|
panic("_isa_dmainit: unable to map DMA controller #1");
|
|
|
|
if (bus_space_map(ids->ids_bst, IO_DMA2, DMA2_IOSIZE, 0,
|
|
|
|
&ids->ids_dma2h))
|
|
|
|
panic("_isa_dmainit: unable to map DMA controller #2");
|
|
|
|
if (bus_space_map(ids->ids_bst, IO_DMAPG, 0xf, 0,
|
|
|
|
&ids->ids_dmapgh))
|
|
|
|
panic("_isa_dmainit: unable to map DMA page registers");
|
|
|
|
|
1998-06-09 05:04:17 +04:00
|
|
|
/*
|
|
|
|
* All 8 DMA channels start out "masked".
|
|
|
|
*/
|
|
|
|
ids->ids_masked = 0xff;
|
|
|
|
|
2000-02-08 01:07:27 +03:00
|
|
|
/*
|
|
|
|
* Initialize the max transfer size for each channel, if
|
|
|
|
* it is not initialized already (i.e. by a bus-dependent
|
|
|
|
* front-end).
|
|
|
|
*/
|
|
|
|
for (chan = 0; chan < 8; chan++) {
|
|
|
|
if (ids->ids_maxsize[chan] == 0)
|
|
|
|
ids->ids_maxsize[chan] =
|
|
|
|
ISA_DMA_MAXSIZE_DEFAULT(chan);
|
|
|
|
}
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
ids->ids_initialized = 1;
|
1998-07-08 09:23:23 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DRQ 4 is used to chain the two 8237s together; make
|
|
|
|
* sure it's always cascaded, and that it will be unmasked
|
|
|
|
* when DMA is thawed.
|
|
|
|
*/
|
|
|
|
_isa_dmacascade(ids, 4);
|
1998-06-09 04:00:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _isa_dmacascade(): program 8237 DMA controller channel to accept
|
1993-10-14 08:22:57 +03:00
|
|
|
* external dma control by a board.
|
|
|
|
*/
|
1998-06-25 23:18:05 +04:00
|
|
|
int
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmacascade(ids, chan)
|
|
|
|
struct isa_dma_state *ids;
|
1993-10-22 23:24:14 +03:00
|
|
|
int chan;
|
1993-10-14 08:22:57 +03:00
|
|
|
{
|
1997-03-21 05:17:11 +03:00
|
|
|
int ochan = chan & 3;
|
1993-10-22 23:24:14 +03:00
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
1998-06-25 23:18:05 +04:00
|
|
|
return (EINVAL);
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
if (ISA_DMA_DRQ_ISFREE(ids, chan) == 0) {
|
|
|
|
printf("%s: DRQ %d is not free\n", ids->ids_dev->dv_xname,
|
|
|
|
chan);
|
1998-06-25 23:18:05 +04:00
|
|
|
return (EAGAIN);
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
ISA_DMA_DRQ_ALLOC(ids, chan);
|
1993-10-14 08:22:57 +03:00
|
|
|
|
|
|
|
/* set dma channel mode, and set dma channel mode */
|
1997-03-21 05:17:11 +03:00
|
|
|
if ((chan & 4) == 0)
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma1h,
|
1997-06-07 03:43:45 +04:00
|
|
|
DMA1_MODE, ochan | DMA37MD_CASCADE);
|
|
|
|
else
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma2h,
|
1997-06-07 03:43:45 +04:00
|
|
|
DMA2_MODE, ochan | DMA37MD_CASCADE);
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmaunmask(ids, chan);
|
1998-06-25 23:18:05 +04:00
|
|
|
return (0);
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
|
|
|
|
2000-02-08 01:07:27 +03:00
|
|
|
bus_size_t
|
|
|
|
_isa_dmamaxsize(ids, chan)
|
|
|
|
struct isa_dma_state *ids;
|
|
|
|
int chan;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (chan < 0 || chan > 7) {
|
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ids->ids_maxsize[chan]);
|
|
|
|
}
|
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
int
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamap_create(ids, chan, size, flags)
|
|
|
|
struct isa_dma_state *ids;
|
1997-06-07 03:43:45 +04:00
|
|
|
int chan;
|
|
|
|
bus_size_t size;
|
|
|
|
int flags;
|
|
|
|
{
|
1999-03-22 10:06:09 +03:00
|
|
|
int error;
|
1997-06-07 03:43:45 +04:00
|
|
|
|
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
1998-06-25 23:18:05 +04:00
|
|
|
return (EINVAL);
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
|
|
|
|
2000-02-08 01:07:27 +03:00
|
|
|
if (size > ids->ids_maxsize[chan])
|
1997-06-07 03:43:45 +04:00
|
|
|
return (EINVAL);
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
if (ISA_DMA_DRQ_ISFREE(ids, chan) == 0) {
|
|
|
|
printf("%s: drq %d is not free\n", ids->ids_dev->dv_xname,
|
|
|
|
chan);
|
1998-06-25 23:18:05 +04:00
|
|
|
return (EAGAIN);
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
ISA_DMA_DRQ_ALLOC(ids, chan);
|
1997-06-07 03:43:45 +04:00
|
|
|
|
2000-02-08 01:07:27 +03:00
|
|
|
error = bus_dmamap_create(ids->ids_dmat, size, 1, size,
|
|
|
|
ids->ids_maxsize[chan], flags, &ids->ids_dmamaps[chan]);
|
1999-03-22 10:06:09 +03:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
ISA_DMA_DRQ_FREE(ids, chan);
|
|
|
|
|
|
|
|
return (error);
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamap_destroy(ids, chan)
|
|
|
|
struct isa_dma_state *ids;
|
1997-06-07 03:43:45 +04:00
|
|
|
int chan;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
1997-06-07 03:43:45 +04:00
|
|
|
goto lose;
|
|
|
|
}
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
if (ISA_DMA_DRQ_ISFREE(ids, chan)) {
|
1997-06-07 03:43:45 +04:00
|
|
|
printf("%s: drq %d is already free\n",
|
1998-06-09 04:00:21 +04:00
|
|
|
ids->ids_dev->dv_xname, chan);
|
1997-06-07 03:43:45 +04:00
|
|
|
goto lose;
|
|
|
|
}
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
ISA_DMA_DRQ_FREE(ids, chan);
|
1997-06-07 03:43:45 +04:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_dmamap_destroy(ids->ids_dmat, ids->ids_dmamaps[chan]);
|
1997-06-07 03:43:45 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
lose:
|
1998-06-09 04:00:21 +04:00
|
|
|
panic("_isa_dmamap_destroy");
|
1993-10-14 08:22:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-06-09 04:00:21 +04:00
|
|
|
* _isa_dmastart(): program 8237 DMA controller channel and set it
|
1997-06-07 03:43:45 +04:00
|
|
|
* in motion.
|
1993-10-14 08:22:57 +03:00
|
|
|
*/
|
1997-06-07 03:43:45 +04:00
|
|
|
int
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmastart(ids, chan, addr, nbytes, p, flags, busdmaflags)
|
|
|
|
struct isa_dma_state *ids;
|
1993-10-22 23:24:14 +03:00
|
|
|
int chan;
|
1997-06-07 03:43:45 +04:00
|
|
|
void *addr;
|
|
|
|
bus_size_t nbytes;
|
|
|
|
struct proc *p;
|
|
|
|
int flags;
|
|
|
|
int busdmaflags;
|
1993-10-14 08:22:57 +03:00
|
|
|
{
|
1997-06-07 03:43:45 +04:00
|
|
|
bus_dmamap_t dmam;
|
|
|
|
bus_addr_t dmaaddr;
|
1993-10-14 08:22:57 +03:00
|
|
|
int waport;
|
1997-03-21 05:17:11 +03:00
|
|
|
int ochan = chan & 3;
|
1997-06-07 03:43:45 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
1997-06-07 03:43:45 +04:00
|
|
|
goto lose;
|
|
|
|
}
|
1993-10-14 08:22:57 +03:00
|
|
|
|
1996-02-20 07:17:05 +03:00
|
|
|
#ifdef ISADMA_DEBUG
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("_isa_dmastart: drq %d, addr %p, nbytes 0x%lx, p %p, "
|
1997-06-07 03:43:45 +04:00
|
|
|
"flags 0x%x, dmaflags 0x%x\n",
|
|
|
|
chan, addr, nbytes, p, flags, busdmaflags);
|
1993-10-22 23:24:14 +03:00
|
|
|
#endif
|
1993-10-14 08:22:57 +03:00
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
if (chan & 4) {
|
|
|
|
if (nbytes > (1 << 17) || nbytes & 1 || (u_long)addr & 1) {
|
|
|
|
printf("%s: drq %d, nbytes 0x%lx, addr %p\n",
|
1998-06-09 04:00:21 +04:00
|
|
|
ids->ids_dev->dv_xname, chan, nbytes, addr);
|
1997-06-07 03:43:45 +04:00
|
|
|
goto lose;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (nbytes > (1 << 16)) {
|
|
|
|
printf("%s: drq %d, nbytes 0x%lx\n",
|
1998-06-09 04:00:21 +04:00
|
|
|
ids->ids_dev->dv_xname, chan, nbytes);
|
1997-06-07 03:43:45 +04:00
|
|
|
goto lose;
|
|
|
|
}
|
1993-10-14 08:22:57 +03:00
|
|
|
}
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
dmam = ids->ids_dmamaps[chan];
|
1997-08-30 21:33:49 +04:00
|
|
|
if (dmam == NULL)
|
1998-06-09 04:00:21 +04:00
|
|
|
panic("_isa_dmastart: no DMA map for chan %d\n", chan);
|
1997-05-29 00:02:39 +04:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
error = bus_dmamap_load(ids->ids_dmat, dmam, addr, nbytes,
|
1997-06-07 03:43:45 +04:00
|
|
|
p, busdmaflags);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
1993-10-14 08:22:57 +03:00
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
#ifdef ISADMA_DEBUG
|
|
|
|
__asm(".globl isa_dmastart_afterload ; isa_dmastart_afterload:");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (flags & DMAMODE_READ) {
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_dmamap_sync(ids->ids_dmat, dmam, 0, dmam->dm_mapsize,
|
1998-02-04 08:12:46 +03:00
|
|
|
BUS_DMASYNC_PREREAD);
|
1998-06-09 04:00:21 +04:00
|
|
|
ids->ids_dmareads |= (1 << chan);
|
1997-06-07 03:43:45 +04:00
|
|
|
} else {
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_dmamap_sync(ids->ids_dmat, dmam, 0, dmam->dm_mapsize,
|
1998-02-04 08:12:46 +03:00
|
|
|
BUS_DMASYNC_PREWRITE);
|
1998-06-09 04:00:21 +04:00
|
|
|
ids->ids_dmareads &= ~(1 << chan);
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
dmaaddr = dmam->dm_segs[0].ds_addr;
|
|
|
|
|
|
|
|
#ifdef ISADMA_DEBUG
|
|
|
|
printf(" dmaaddr 0x%lx\n", dmaaddr);
|
|
|
|
|
|
|
|
__asm(".globl isa_dmastart_aftersync ; isa_dmastart_aftersync:");
|
|
|
|
#endif
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
ids->ids_dmalength[chan] = nbytes;
|
1997-06-07 03:43:45 +04:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamask(ids, chan);
|
|
|
|
ids->ids_dmafinished &= ~(1 << chan);
|
1996-02-22 09:21:48 +03:00
|
|
|
|
1993-10-14 08:22:57 +03:00
|
|
|
if ((chan & 4) == 0) {
|
1997-03-21 05:17:11 +03:00
|
|
|
/* set dma channel mode */
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma1h, DMA1_MODE,
|
1997-06-07 03:43:45 +04:00
|
|
|
ochan | dmamode[flags]);
|
1993-10-14 08:22:57 +03:00
|
|
|
|
|
|
|
/* send start address */
|
1997-03-21 05:17:11 +03:00
|
|
|
waport = DMA1_CHN(ochan);
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dmapgh,
|
1997-06-07 03:43:45 +04:00
|
|
|
dmapageport[0][ochan], (dmaaddr >> 16) & 0xff);
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma1h, waport,
|
1997-06-07 03:43:45 +04:00
|
|
|
dmaaddr & 0xff);
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma1h, waport,
|
1997-06-07 03:43:45 +04:00
|
|
|
(dmaaddr >> 8) & 0xff);
|
1993-10-14 08:22:57 +03:00
|
|
|
|
|
|
|
/* send count */
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma1h, waport + 1,
|
1997-06-07 03:43:45 +04:00
|
|
|
(--nbytes) & 0xff);
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma1h, waport + 1,
|
1997-06-07 03:43:45 +04:00
|
|
|
(nbytes >> 8) & 0xff);
|
1993-10-14 08:22:57 +03:00
|
|
|
} else {
|
1997-03-21 05:17:11 +03:00
|
|
|
/* set dma channel mode */
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma2h, DMA2_MODE,
|
1997-06-07 03:43:45 +04:00
|
|
|
ochan | dmamode[flags]);
|
1993-10-14 08:22:57 +03:00
|
|
|
|
|
|
|
/* send start address */
|
1997-03-21 05:17:11 +03:00
|
|
|
waport = DMA2_CHN(ochan);
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dmapgh,
|
1997-06-07 03:43:45 +04:00
|
|
|
dmapageport[1][ochan], (dmaaddr >> 16) & 0xff);
|
|
|
|
dmaaddr >>= 1;
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma2h, waport,
|
1997-06-07 03:43:45 +04:00
|
|
|
dmaaddr & 0xff);
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma2h, waport,
|
1997-06-07 03:43:45 +04:00
|
|
|
(dmaaddr >> 8) & 0xff);
|
1993-10-14 08:22:57 +03:00
|
|
|
|
|
|
|
/* send count */
|
|
|
|
nbytes >>= 1;
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma2h, waport + 2,
|
1997-06-07 03:43:45 +04:00
|
|
|
(--nbytes) & 0xff);
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma2h, waport + 2,
|
1997-06-07 03:43:45 +04:00
|
|
|
(nbytes >> 8) & 0xff);
|
1993-10-14 08:22:57 +03:00
|
|
|
}
|
1997-03-21 05:17:11 +03:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmaunmask(ids, chan);
|
1997-06-07 03:43:45 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
lose:
|
1998-06-09 04:00:21 +04:00
|
|
|
panic("_isa_dmastart");
|
1993-10-14 08:22:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmaabort(ids, chan)
|
|
|
|
struct isa_dma_state *ids;
|
1993-10-22 23:24:14 +03:00
|
|
|
int chan;
|
1993-10-14 08:22:57 +03:00
|
|
|
{
|
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
|
|
|
panic("_isa_dmaabort");
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
1997-03-21 03:00:21 +03:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamask(ids, chan);
|
|
|
|
bus_dmamap_unload(ids->ids_dmat, ids->ids_dmamaps[chan]);
|
|
|
|
ids->ids_dmareads &= ~(1 << chan);
|
1997-03-21 03:00:21 +03:00
|
|
|
}
|
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
bus_size_t
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmacount(ids, chan)
|
|
|
|
struct isa_dma_state *ids;
|
1997-03-21 03:00:21 +03:00
|
|
|
int chan;
|
|
|
|
{
|
|
|
|
int waport;
|
1997-06-07 03:43:45 +04:00
|
|
|
bus_size_t nbytes;
|
1997-03-21 05:17:11 +03:00
|
|
|
int ochan = chan & 3;
|
1997-03-21 03:00:21 +03:00
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
1997-06-07 03:43:45 +04:00
|
|
|
panic("isa_dmacount");
|
|
|
|
}
|
1997-03-21 03:00:21 +03:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamask(ids, chan);
|
1997-03-21 03:00:21 +03:00
|
|
|
|
1997-05-29 00:02:39 +04:00
|
|
|
/*
|
|
|
|
* We have to shift the byte count by 1. If we're in auto-initialize
|
|
|
|
* mode, the count may have wrapped around to the initial value. We
|
|
|
|
* can't use the TC bit to check for this case, so instead we compare
|
|
|
|
* against the original byte count.
|
|
|
|
* If we're not in auto-initialize mode, then the count will wrap to
|
|
|
|
* -1, so we also handle that case.
|
|
|
|
*/
|
|
|
|
if ((chan & 4) == 0) {
|
|
|
|
waport = DMA1_CHN(ochan);
|
1998-06-09 04:00:21 +04:00
|
|
|
nbytes = bus_space_read_1(ids->ids_bst, ids->ids_dma1h,
|
1997-06-07 03:43:45 +04:00
|
|
|
waport + 1) + 1;
|
1998-06-09 04:00:21 +04:00
|
|
|
nbytes += bus_space_read_1(ids->ids_bst, ids->ids_dma1h,
|
1997-06-07 03:43:45 +04:00
|
|
|
waport + 1) << 8;
|
1997-05-29 00:02:39 +04:00
|
|
|
nbytes &= 0xffff;
|
|
|
|
} else {
|
|
|
|
waport = DMA2_CHN(ochan);
|
1998-06-09 04:00:21 +04:00
|
|
|
nbytes = bus_space_read_1(ids->ids_bst, ids->ids_dma2h,
|
1997-06-07 03:43:45 +04:00
|
|
|
waport + 2) + 1;
|
1998-06-09 04:00:21 +04:00
|
|
|
nbytes += bus_space_read_1(ids->ids_bst, ids->ids_dma2h,
|
1997-06-07 03:43:45 +04:00
|
|
|
waport + 2) << 8;
|
1997-05-29 00:02:39 +04:00
|
|
|
nbytes <<= 1;
|
|
|
|
nbytes &= 0x1ffff;
|
|
|
|
}
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
if (nbytes == ids->ids_dmalength[chan])
|
1997-03-21 05:17:11 +03:00
|
|
|
nbytes = 0;
|
1997-03-21 03:00:21 +03:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmaunmask(ids, chan);
|
1997-03-21 03:00:21 +03:00
|
|
|
return (nbytes);
|
1993-10-14 08:22:57 +03:00
|
|
|
}
|
|
|
|
|
1996-02-20 07:17:05 +03:00
|
|
|
int
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmafinished(ids, chan)
|
|
|
|
struct isa_dma_state *ids;
|
1994-04-23 02:58:50 +04:00
|
|
|
int chan;
|
1993-10-14 08:22:57 +03:00
|
|
|
{
|
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
|
|
|
panic("_isa_dmafinished");
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
1993-10-14 08:22:57 +03:00
|
|
|
|
|
|
|
/* check that the terminal count was reached */
|
|
|
|
if ((chan & 4) == 0)
|
1998-06-09 04:00:21 +04:00
|
|
|
ids->ids_dmafinished |= bus_space_read_1(ids->ids_bst,
|
|
|
|
ids->ids_dma1h, DMA1_SR) & 0x0f;
|
1993-10-14 08:22:57 +03:00
|
|
|
else
|
1998-06-09 04:00:21 +04:00
|
|
|
ids->ids_dmafinished |= (bus_space_read_1(ids->ids_bst,
|
|
|
|
ids->ids_dma2h, DMA2_SR) & 0x0f) << 4;
|
1996-02-22 09:21:48 +03:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
return ((ids->ids_dmafinished & (1 << chan)) != 0);
|
1996-02-20 07:17:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmadone(ids, chan)
|
|
|
|
struct isa_dma_state *ids;
|
1996-02-20 07:17:05 +03:00
|
|
|
int chan;
|
|
|
|
{
|
1997-06-07 03:43:45 +04:00
|
|
|
bus_dmamap_t dmam;
|
1996-02-20 07:17:05 +03:00
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
|
|
|
panic("_isa_dmadone");
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
1994-04-23 02:58:50 +04:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
dmam = ids->ids_dmamaps[chan];
|
1997-03-21 05:17:11 +03:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamask(ids, chan);
|
1996-02-22 09:21:48 +03:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
if (_isa_dmafinished(ids, chan) == 0)
|
|
|
|
printf("%s: _isa_dmadone: channel %d not finished\n",
|
|
|
|
ids->ids_dev->dv_xname, chan);
|
1997-06-07 03:43:45 +04:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_dmamap_sync(ids->ids_dmat, dmam, 0, dmam->dm_mapsize,
|
|
|
|
(ids->ids_dmareads & (1 << chan)) ? BUS_DMASYNC_POSTREAD :
|
1997-06-07 03:43:45 +04:00
|
|
|
BUS_DMASYNC_POSTWRITE);
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_dmamap_unload(ids->ids_dmat, dmam);
|
|
|
|
ids->ids_dmareads &= ~(1 << chan);
|
1993-10-14 08:22:57 +03:00
|
|
|
}
|
|
|
|
|
1998-06-09 05:04:17 +04:00
|
|
|
void
|
|
|
|
_isa_dmafreeze(ids)
|
|
|
|
struct isa_dma_state *ids;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
|
|
|
|
if (ids->ids_frozen == 0) {
|
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma1h,
|
|
|
|
DMA1_MASK, 0x0f);
|
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma2h,
|
|
|
|
DMA2_MASK, 0x0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
ids->ids_frozen++;
|
|
|
|
if (ids->ids_frozen < 1)
|
|
|
|
panic("_isa_dmafreeze: overflow");
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_isa_dmathaw(ids)
|
|
|
|
struct isa_dma_state *ids;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
|
|
|
|
ids->ids_frozen--;
|
|
|
|
if (ids->ids_frozen < 0)
|
|
|
|
panic("_isa_dmathaw: underflow");
|
|
|
|
|
|
|
|
if (ids->ids_frozen == 0) {
|
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma1h,
|
|
|
|
DMA1_MASK, ids->ids_masked & 0x0f);
|
|
|
|
bus_space_write_1(ids->ids_bst, ids->ids_dma2h,
|
|
|
|
DMA2_MASK, (ids->ids_masked >> 4) & 0x0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1993-10-14 08:22:57 +03:00
|
|
|
int
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamem_alloc(ids, chan, size, addrp, flags)
|
|
|
|
struct isa_dma_state *ids;
|
1993-10-22 23:24:14 +03:00
|
|
|
int chan;
|
1997-06-07 03:43:45 +04:00
|
|
|
bus_size_t size;
|
|
|
|
bus_addr_t *addrp;
|
|
|
|
int flags;
|
1993-10-14 08:22:57 +03:00
|
|
|
{
|
1997-06-07 03:43:45 +04:00
|
|
|
bus_dma_segment_t seg;
|
|
|
|
int error, boundary, rsegs;
|
|
|
|
|
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
|
|
|
panic("_isa_dmamem_alloc");
|
1993-10-14 08:22:57 +03:00
|
|
|
}
|
1997-06-07 03:43:45 +04:00
|
|
|
|
|
|
|
boundary = (chan & 4) ? (1 << 17) : (1 << 16);
|
|
|
|
|
|
|
|
size = round_page(size);
|
|
|
|
|
2000-11-14 21:21:00 +03:00
|
|
|
error = bus_dmamem_alloc(ids->ids_dmat, size, PAGE_SIZE, boundary,
|
1997-06-07 03:43:45 +04:00
|
|
|
&seg, 1, &rsegs, flags);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
*addrp = seg.ds_addr;
|
|
|
|
return (0);
|
1993-10-14 08:22:57 +03:00
|
|
|
}
|
1994-04-23 02:58:50 +04:00
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
void
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamem_free(ids, chan, addr, size)
|
|
|
|
struct isa_dma_state *ids;
|
1997-06-07 03:43:45 +04:00
|
|
|
int chan;
|
|
|
|
bus_addr_t addr;
|
|
|
|
bus_size_t size;
|
|
|
|
{
|
|
|
|
bus_dma_segment_t seg;
|
1994-04-23 02:58:50 +04:00
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
|
|
|
panic("_isa_dmamem_free");
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
1994-04-23 02:58:50 +04:00
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
seg.ds_addr = addr;
|
|
|
|
seg.ds_len = size;
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_dmamem_free(ids->ids_dmat, &seg, 1);
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamem_map(ids, chan, addr, size, kvap, flags)
|
|
|
|
struct isa_dma_state *ids;
|
1997-06-07 03:43:45 +04:00
|
|
|
int chan;
|
|
|
|
bus_addr_t addr;
|
|
|
|
bus_size_t size;
|
|
|
|
caddr_t *kvap;
|
|
|
|
int flags;
|
1996-04-30 00:02:32 +04:00
|
|
|
{
|
1997-06-07 03:43:45 +04:00
|
|
|
bus_dma_segment_t seg;
|
|
|
|
|
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
|
|
|
panic("_isa_dmamem_map");
|
1994-04-23 02:58:50 +04:00
|
|
|
}
|
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
seg.ds_addr = addr;
|
|
|
|
seg.ds_len = size;
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
return (bus_dmamem_map(ids->ids_dmat, &seg, 1, size, kvap, flags));
|
1994-04-23 02:58:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamem_unmap(ids, chan, kva, size)
|
|
|
|
struct isa_dma_state *ids;
|
1997-06-07 03:43:45 +04:00
|
|
|
int chan;
|
|
|
|
caddr_t kva;
|
|
|
|
size_t size;
|
1996-04-30 00:02:32 +04:00
|
|
|
{
|
1994-04-23 02:58:50 +04:00
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
|
|
|
panic("_isa_dmamem_unmap");
|
1994-04-23 02:58:50 +04:00
|
|
|
}
|
1997-06-07 03:43:45 +04:00
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
bus_dmamem_unmap(ids->ids_dmat, kva, size);
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
|
|
|
|
2000-06-26 08:55:19 +04:00
|
|
|
paddr_t
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamem_mmap(ids, chan, addr, size, off, prot, flags)
|
|
|
|
struct isa_dma_state *ids;
|
1997-06-07 03:43:45 +04:00
|
|
|
int chan;
|
|
|
|
bus_addr_t addr;
|
|
|
|
bus_size_t size;
|
2000-06-26 08:55:19 +04:00
|
|
|
off_t off;
|
|
|
|
int prot, flags;
|
1997-06-07 03:43:45 +04:00
|
|
|
{
|
|
|
|
bus_dma_segment_t seg;
|
|
|
|
|
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
|
|
|
panic("_isa_dmamem_mmap");
|
1997-06-07 03:43:45 +04:00
|
|
|
}
|
|
|
|
|
1998-11-19 18:38:20 +03:00
|
|
|
if (off < 0)
|
|
|
|
return (-1);
|
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
seg.ds_addr = addr;
|
|
|
|
seg.ds_len = size;
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
return (bus_dmamem_mmap(ids->ids_dmat, &seg, 1, off, prot, flags));
|
1994-04-23 02:58:50 +04:00
|
|
|
}
|
1997-07-27 05:16:32 +04:00
|
|
|
|
1997-08-05 02:13:32 +04:00
|
|
|
int
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_drq_isfree(ids, chan)
|
|
|
|
struct isa_dma_state *ids;
|
1997-08-05 02:13:32 +04:00
|
|
|
int chan;
|
|
|
|
{
|
1998-06-09 04:00:21 +04:00
|
|
|
|
1997-08-05 02:13:32 +04:00
|
|
|
if (chan < 0 || chan > 7) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("%s: bogus drq %d\n", ids->ids_dev->dv_xname, chan);
|
|
|
|
panic("_isa_drq_isfree");
|
1997-08-05 02:13:32 +04:00
|
|
|
}
|
1998-06-09 04:00:21 +04:00
|
|
|
|
|
|
|
return ISA_DMA_DRQ_ISFREE(ids, chan);
|
1997-08-05 02:13:32 +04:00
|
|
|
}
|
|
|
|
|
1997-07-27 05:16:32 +04:00
|
|
|
void *
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_malloc(ids, chan, size, pool, flags)
|
|
|
|
struct isa_dma_state *ids;
|
1997-07-27 05:16:32 +04:00
|
|
|
int chan;
|
|
|
|
size_t size;
|
|
|
|
int pool;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
bus_addr_t addr;
|
|
|
|
caddr_t kva;
|
|
|
|
int bflags;
|
|
|
|
struct isa_mem *m;
|
|
|
|
|
|
|
|
bflags = flags & M_WAITOK ? BUS_DMA_WAITOK : BUS_DMA_NOWAIT;
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
if (_isa_dmamem_alloc(ids, chan, size, &addr, bflags))
|
1997-07-27 05:16:32 +04:00
|
|
|
return 0;
|
1998-06-09 04:00:21 +04:00
|
|
|
if (_isa_dmamem_map(ids, chan, addr, size, &kva, bflags)) {
|
|
|
|
_isa_dmamem_free(ids, chan, addr, size);
|
1997-07-27 05:16:32 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
m = malloc(sizeof(*m), pool, flags);
|
|
|
|
if (m == 0) {
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamem_unmap(ids, chan, kva, size);
|
|
|
|
_isa_dmamem_free(ids, chan, addr, size);
|
1997-07-27 05:16:32 +04:00
|
|
|
return 0;
|
|
|
|
}
|
1998-06-09 04:00:21 +04:00
|
|
|
m->ids = ids;
|
1997-07-27 05:16:32 +04:00
|
|
|
m->chan = chan;
|
|
|
|
m->size = size;
|
|
|
|
m->addr = addr;
|
|
|
|
m->kva = kva;
|
|
|
|
m->next = isa_mem_head;
|
|
|
|
isa_mem_head = m;
|
|
|
|
return (void *)kva;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_free(addr, pool)
|
1997-07-27 05:16:32 +04:00
|
|
|
void *addr;
|
|
|
|
int pool;
|
|
|
|
{
|
|
|
|
struct isa_mem **mp, *m;
|
|
|
|
caddr_t kva = (caddr_t)addr;
|
|
|
|
|
1998-06-09 04:00:21 +04:00
|
|
|
for(mp = &isa_mem_head; *mp && (*mp)->kva != kva;
|
|
|
|
mp = &(*mp)->next)
|
1997-07-27 05:16:32 +04:00
|
|
|
;
|
|
|
|
m = *mp;
|
|
|
|
if (!m) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("_isa_free: freeing unallocted memory\n");
|
1997-07-27 05:16:32 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
*mp = m->next;
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_dmamem_unmap(m->ids, m->chan, kva, m->size);
|
|
|
|
_isa_dmamem_free(m->ids, m->chan, m->addr, m->size);
|
1997-07-27 05:16:32 +04:00
|
|
|
free(m, pool);
|
|
|
|
}
|
1997-07-29 00:56:05 +04:00
|
|
|
|
2000-06-26 08:55:19 +04:00
|
|
|
paddr_t
|
1998-06-09 04:00:21 +04:00
|
|
|
_isa_mappage(mem, off, prot)
|
1997-07-29 00:56:05 +04:00
|
|
|
void *mem;
|
2000-06-26 08:55:19 +04:00
|
|
|
off_t off;
|
1997-07-29 00:56:05 +04:00
|
|
|
int prot;
|
|
|
|
{
|
|
|
|
struct isa_mem *m;
|
|
|
|
|
|
|
|
for(m = isa_mem_head; m && m->kva != (caddr_t)mem; m = m->next)
|
|
|
|
;
|
|
|
|
if (!m) {
|
1998-06-09 04:00:21 +04:00
|
|
|
printf("_isa_mappage: mapping unallocted memory\n");
|
1997-07-29 00:56:05 +04:00
|
|
|
return -1;
|
|
|
|
}
|
1998-06-09 04:00:21 +04:00
|
|
|
return _isa_dmamem_mmap(m->ids, m->chan, m->addr,
|
|
|
|
m->size, off, prot, BUS_DMA_WAITOK);
|
1997-07-29 00:56:05 +04:00
|
|
|
}
|