1 /* $NetBSD: dmac3.c,v 1.12 2008/06/13 12:26:35 cegger Exp $ */
4 * Copyright (c) 2000 Tsubai Masanari. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: dmac3.c,v 1.12 2008/06/13 12:26:35 cegger Exp $");
32 #include <sys/param.h>
33 #include <sys/device.h>
34 #include <sys/kernel.h>
35 #include <sys/systm.h>
37 #include <uvm/uvm_extern.h>
39 #include <machine/locore.h>
41 #include <newsmips/apbus/apbusvar.h>
42 #include <newsmips/apbus/dmac3reg.h>
43 #include <newsmips/apbus/dmac3var.h>
45 #include <mips/cache.h>
55 # define APAD_MODE DMAC3_CSR_APAD
59 # define BURST_MODE (DMAC3_CSR_DBURST | DMAC3_CSR_MBURST)
64 int dmac3_match(device_t
, cfdata_t
, void *);
65 void dmac3_attach(device_t
, device_t
, void *);
67 extern paddr_t
kvtophys(vaddr_t
);
69 CFATTACH_DECL_NEW(dmac
, sizeof(struct dmac3_softc
),
70 dmac3_match
, dmac3_attach
, NULL
, NULL
);
73 dmac3_match(device_t parent
, cfdata_t cf
, void *aux
)
75 struct apbus_attach_args
*apa
= aux
;
77 if (strcmp(apa
->apa_name
, "dmac3") == 0)
84 dmac3_attach(device_t parent
, device_t self
, void *aux
)
86 struct dmac3_softc
*sc
= device_private(self
);
87 struct apbus_attach_args
*apa
= aux
;
89 static paddr_t dmamap
= DMAC3_PAGEMAP
;
90 static vaddr_t dmaaddr
= 0;
93 reg
= (void *)apa
->apa_hwbase
;
95 sc
->sc_ctlnum
= apa
->apa_ctlnum
;
96 sc
->sc_dmamap
= (uint32_t *)dmamap
;
97 sc
->sc_dmaaddr
= dmaaddr
;
101 sc
->sc_conf
= DMAC3_CONF_PCEN
| DMAC3_CONF_DCEN
| DMAC3_CONF_FASTACCESS
;
105 aprint_normal(" slot%d addr 0x%lx", apa
->apa_slotno
, apa
->apa_hwbase
);
106 aprint_normal(": ctlnum = %d, map = %p, va = %#"PRIxVADDR
,
107 apa
->apa_ctlnum
, sc
->sc_dmamap
, sc
->sc_dmaaddr
);
112 dmac3_link(int ctlnum
)
114 struct dmac3_softc
*sc
;
117 for (unit
= 0; unit
< dmac_cd
.cd_ndevs
; unit
++) {
118 sc
= device_lookup_private(&dmac_cd
, unit
);
121 if (sc
->sc_ctlnum
== ctlnum
)
128 dmac3_reset(struct dmac3_softc
*sc
)
130 struct dmac3reg
*reg
= sc
->sc_reg
;
132 reg
->csr
= DMAC3_CSR_RESET
;
134 reg
->intr
= DMAC3_INTR_EOPIE
| DMAC3_INTR_INTEN
;
135 reg
->conf
= sc
->sc_conf
;
139 dmac3_start(struct dmac3_softc
*sc
, vaddr_t addr
, int len
, int direction
)
141 struct dmac3reg
*reg
= sc
->sc_reg
;
143 vaddr_t start
, end
, v
;
144 volatile uint32_t *p
;
146 if (reg
->csr
& DMAC3_CSR_ENABLE
)
149 start
= mips_trunc_page(addr
);
150 end
= mips_round_page(addr
+ len
);
152 for (v
= start
; v
< end
; v
+= PAGE_SIZE
) {
154 mips_dcache_wbinv_range(MIPS_PHYS_TO_KSEG0(pa
), PAGE_SIZE
);
156 *p
++ = (pa
>> PGSHIFT
) | 0xc0000000;
162 addr
+= sc
->sc_dmaaddr
;
166 reg
->intr
= DMAC3_INTR_EOPIE
| DMAC3_INTR_INTEN
;
167 reg
->csr
= DMAC3_CSR_ENABLE
| direction
| BURST_MODE
| APAD_MODE
;
173 struct dmac3_softc
*sc
= v
;
174 struct dmac3reg
*reg
= sc
->sc_reg
;
175 int intr
, conf
, rv
= 1;
178 if ((intr
& DMAC3_INTR_INT
) == 0)
181 /* clear interrupt */
186 if (intr
& DMAC3_INTR_PERR
) {
187 printf("%s: intr = 0x%x\n", device_xname(sc
->sc_dev
), intr
);
191 if (conf
& (DMAC3_CONF_IPER
| DMAC3_CONF_MPER
| DMAC3_CONF_DERR
)) {
192 printf("%s: conf = 0x%x\n", device_xname(sc
->sc_dev
), conf
);
193 if (conf
& DMAC3_CONF_DERR
) {
194 printf("DMA address = 0x%x\n", reg
->addr
);
195 printf("resetting DMA...\n");
204 dmac3_misc(struct dmac3_softc
*sc
, int cmd
)
206 struct dmac3reg
*reg
= sc
->sc_reg
;
209 conf
= DMAC3_CONF_PCEN
| DMAC3_CONF_DCEN
| cmd
;