Home | History | Annotate | Line # | Download | only in isa
atppc_isadma.c revision 1.1
      1 /* $NetBSD: atppc_isadma.c,v 1.1 2004/01/25 11:35:46 jdolecek Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2001 Alcove - Nicolas Souchu
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  *
     28  * FreeBSD: src/sys/isa/ppc.c,v 1.26.2.5 2001/10/02 05:21:45 nsouch Exp
     29  *
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: atppc_isadma.c,v 1.1 2004/01/25 11:35:46 jdolecek Exp $");
     34 
     35 #include "opt_atppc.h"
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/kernel.h>
     40 #include <sys/malloc.h>
     41 #include <sys/device.h>
     42 
     43 #include <machine/intr.h>
     44 #include <machine/bus.h>
     45 
     46 #include <dev/ic/atppcreg.h>
     47 #include <dev/ic/atppcvar.h>
     48 
     49 #include <dev/isa/isadmavar.h>
     50 #include <dev/isa/isareg.h>
     51 #include <dev/isa/isavar.h>
     52 
     53 #include <dev/isa/atppc_isadma.h>
     54 
     55 /* Enable DMA */
     56 int
     57 atppc_isadma_setup(struct atppc_softc * lsc, isa_chipset_tag_t ic, int drq)
     58 {
     59 	int error = 1;
     60 
     61 	/* Reserve DRQ */
     62 	if (isa_drq_alloc(ic, drq)) {
     63 		ATPPC_DPRINTF(("%s(%s): cannot reserve DRQ line.\n", __func__,
     64 			lsc->sc_dev.dv_xname));
     65 		return error;
     66 	}
     67 
     68 	/* Get maximum DMA size for isa bus */
     69 	lsc->sc_dma_maxsize = isa_dmamaxsize(ic, drq);
     70 
     71 	/* Create dma mapping */
     72 	error = isa_dmamap_create(ic, drq, lsc->sc_dma_maxsize,
     73 		BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW);
     74 
     75 	return error;
     76 }
     77 
     78 /* Start DMA operation over ISA bus */
     79 int
     80 atppc_isadma_start(isa_chipset_tag_t ic, int drq, void * buf, u_int nbytes,
     81 	u_int8_t mode)
     82 {
     83 	return (isa_dmastart(ic, drq, buf, nbytes, NULL,
     84 		((mode == ATPPC_DMA_MODE_WRITE) ? DMAMODE_WRITE :
     85 		DMAMODE_READ) | DMAMODE_DEMAND, ((mode == ATPPC_DMA_MODE_WRITE)
     86 		? BUS_DMA_WRITE : BUS_DMA_READ) | BUS_DMA_NOWAIT));
     87 }
     88 
     89 /* Stop DMA operation over ISA bus */
     90 int
     91 atppc_isadma_finish(isa_chipset_tag_t ic, int drq)
     92 {
     93 	isa_dmadone(ic, drq);
     94 	return 0;
     95 }
     96 
     97 /* Abort DMA operation over ISA bus */
     98 int
     99 atppc_isadma_abort(isa_chipset_tag_t ic, int drq)
    100 {
    101 	isa_dmaabort(ic, drq);
    102 	return 0;
    103 }
    104 
    105 /* Allocate memory for DMA over ISA bus */
    106 int
    107 atppc_isadma_malloc(isa_chipset_tag_t ic, int drq, caddr_t *buf, bus_addr_t *bus_addr, bus_size_t size)
    108 {
    109 	int error;
    110 
    111 	error = isa_dmamem_alloc(ic, drq, size, bus_addr, BUS_DMA_WAITOK);
    112 	if (error)
    113 		return error;
    114 
    115 	error = isa_dmamem_map(ic, drq, *bus_addr, size, buf, BUS_DMA_WAITOK);
    116 	if (error)
    117 		isa_dmamem_free(ic, drq, *bus_addr, size);
    118 
    119 	return error;
    120 }
    121 
    122 /* Free memory allocated by atppc_isadma_malloc() */
    123 void
    124 atppc_isadma_free(isa_chipset_tag_t ic, int drq, caddr_t * buf, bus_addr_t * bus_addr, bus_size_t size)
    125 {
    126 	isa_dmamem_unmap(ic, drq, *buf, size);
    127 	isa_dmamem_free(ic, drq, *bus_addr, size);
    128 }
    129