Thu Jun 7 19:39:54 2018 UTC ()
Pull up following revision(s) (requested by jdolecek in ticket #841):

	sys/dev/isa/isadmareg.h: revision 1.9
	sys/dev/isa/isareg.h: revision 1.10
	sys/dev/isa/isadma.c: revision 1.67

fix off-by-one in the mapping of the ISA DMA page registers, they actually
start at 0x81; the code used bus_space_map() starting from 0x80 but
used +1 offset for actual I/O, now it maps starting 0x81 and does I/O
without offset

the reads and writes work exactly the same as before, but this frees
0x80 for being mapped independantly
patch provided in PR kern/52468 by Jonathan Chapman; checked against the spec
and also FreeBSD sys/x86/isa/isa_dma.c


(martin)
diff -r1.66 -r1.66.52.1 src/sys/dev/isa/isadma.c
diff -r1.8 -r1.8.80.1 src/sys/dev/isa/isadmareg.h
diff -r1.9 -r1.9.156.1 src/sys/dev/isa/isareg.h

cvs diff -r1.66 -r1.66.52.1 src/sys/dev/isa/isadma.c (expand / switch to unified diff)

--- src/sys/dev/isa/isadma.c 2010/11/13 13:52:03 1.66
+++ src/sys/dev/isa/isadma.c 2018/06/07 19:39:54 1.66.52.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: isadma.c,v 1.66 2010/11/13 13:52:03 uebayasi Exp $ */ 1/* $NetBSD: isadma.c,v 1.66.52.1 2018/06/07 19:39:54 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -25,53 +25,57 @@ @@ -25,53 +25,57 @@
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * Device driver for the ISA on-board DMA controller. 34 * Device driver for the ISA on-board DMA controller.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: isadma.c,v 1.66 2010/11/13 13:52:03 uebayasi Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: isadma.c,v 1.66.52.1 2018/06/07 19:39:54 martin Exp $");
39 39
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/systm.h> 41#include <sys/systm.h>
42#include <sys/proc.h> 42#include <sys/proc.h>
43#include <sys/device.h> 43#include <sys/device.h>
44#include <sys/malloc.h> 44#include <sys/malloc.h>
45 45
46#include <sys/bus.h> 46#include <sys/bus.h>
47 47
48#include <dev/isa/isareg.h> 48#include <dev/isa/isareg.h>
49#include <dev/isa/isavar.h> 49#include <dev/isa/isavar.h>
50#include <dev/isa/isadmavar.h> 50#include <dev/isa/isadmavar.h>
51#include <dev/isa/isadmareg.h> 51#include <dev/isa/isadmareg.h>
52 52
53struct isa_mem *isa_mem_head; 53struct isa_mem *isa_mem_head;
54 54
55/* 55/*
56 * High byte of DMA address is stored in this DMAPG register for 56 * DMA Channel to Address Page Register offset mapping
57 * the Nth DMA channel. 57 *
 58 * Offset from IO_DMAPG is stored in this 2D array -- first dimension is
 59 * the DMA controller, second dimension is the DMA channel.
 60 *
 61 * e.g. dmapageport[0][1] gives us the offset for DMA ch 1 on DMA1
58 */ 62 */
59static int dmapageport[2][4] = { 63static const int dmapageport[2][4] = {
60 {0x7, 0x3, 0x1, 0x2}, 64 {0x6, 0x2, 0x0, 0x1},
61 {0xf, 0xb, 0x9, 0xa} 65 {0xe, 0xa, 0x8, 0x9}
62}; 66};
63 67
64static u_int8_t dmamode[] = { 68static const u_int8_t dmamode[] = {
65 /* write to device/read from device */ 69 /* write to device/read from device */
66 DMA37MD_READ | DMA37MD_SINGLE, 70 DMA37MD_READ | DMA37MD_SINGLE,
67 DMA37MD_WRITE | DMA37MD_SINGLE, 71 DMA37MD_WRITE | DMA37MD_SINGLE,
68 72
69 /* write to device/read from device */ 73 /* write to device/read from device */
70 DMA37MD_READ | DMA37MD_DEMAND, 74 DMA37MD_READ | DMA37MD_DEMAND,
71 DMA37MD_WRITE | DMA37MD_DEMAND, 75 DMA37MD_WRITE | DMA37MD_DEMAND,
72 76
73 /* write to device/read from device - DMAMODE_LOOP */ 77 /* write to device/read from device - DMAMODE_LOOP */
74 DMA37MD_READ | DMA37MD_SINGLE | DMA37MD_LOOP, 78 DMA37MD_READ | DMA37MD_SINGLE | DMA37MD_LOOP,
75 DMA37MD_WRITE | DMA37MD_SINGLE | DMA37MD_LOOP, 79 DMA37MD_WRITE | DMA37MD_SINGLE | DMA37MD_LOOP,
76 80
77 /* write to device/read from device - DMAMODE_LOOPDEMAND */ 81 /* write to device/read from device - DMAMODE_LOOPDEMAND */
@@ -159,27 +163,27 @@ _isa_dmainit(struct isa_dma_state *ids,  @@ -159,27 +163,27 @@ _isa_dmainit(struct isa_dma_state *ids,
159 } else { 163 } else {
160 ids->ids_bst = bst; 164 ids->ids_bst = bst;
161 ids->ids_dmat = dmat; 165 ids->ids_dmat = dmat;
162 166
163 /* 167 /*
164 * Map the registers used by the ISA DMA controller. 168 * Map the registers used by the ISA DMA controller.
165 */ 169 */
166 if (bus_space_map(ids->ids_bst, IO_DMA1, DMA1_IOSIZE, 0, 170 if (bus_space_map(ids->ids_bst, IO_DMA1, DMA1_IOSIZE, 0,
167 &ids->ids_dma1h)) 171 &ids->ids_dma1h))
168 panic("_isa_dmainit: unable to map DMA controller #1"); 172 panic("_isa_dmainit: unable to map DMA controller #1");
169 if (bus_space_map(ids->ids_bst, IO_DMA2, DMA2_IOSIZE, 0, 173 if (bus_space_map(ids->ids_bst, IO_DMA2, DMA2_IOSIZE, 0,
170 &ids->ids_dma2h)) 174 &ids->ids_dma2h))
171 panic("_isa_dmainit: unable to map DMA controller #2"); 175 panic("_isa_dmainit: unable to map DMA controller #2");
172 if (bus_space_map(ids->ids_bst, IO_DMAPG, 0xf, 0, 176 if (bus_space_map(ids->ids_bst, IO_DMAPG, DMAPG_IOSIZE, 0,
173 &ids->ids_dmapgh)) 177 &ids->ids_dmapgh))
174 panic("_isa_dmainit: unable to map DMA page registers"); 178 panic("_isa_dmainit: unable to map DMA page registers");
175 179
176 /* 180 /*
177 * All 8 DMA channels start out "masked". 181 * All 8 DMA channels start out "masked".
178 */ 182 */
179 ids->ids_masked = 0xff; 183 ids->ids_masked = 0xff;
180 184
181 /* 185 /*
182 * Initialize the max transfer size for each channel, if 186 * Initialize the max transfer size for each channel, if
183 * it is not initialized already (i.e. by a bus-dependent 187 * it is not initialized already (i.e. by a bus-dependent
184 * front-end). 188 * front-end).
185 */ 189 */
@@ -201,27 +205,27 @@ _isa_dmainit(struct isa_dma_state *ids,  @@ -201,27 +205,27 @@ _isa_dmainit(struct isa_dma_state *ids,
201} 205}
202 206
203void 207void
204_isa_dmadestroy(struct isa_dma_state *ids) 208_isa_dmadestroy(struct isa_dma_state *ids)
205{ 209{
206 if (!ids->ids_initialized) 210 if (!ids->ids_initialized)
207 return; 211 return;
208 212
209 _isa_dmacascade_stop(ids, 4); 213 _isa_dmacascade_stop(ids, 4);
210 214
211 /* 215 /*
212 * Unmap the registers used by the ISA DMA controller. 216 * Unmap the registers used by the ISA DMA controller.
213 */ 217 */
214 bus_space_unmap(ids->ids_bst, ids->ids_dmapgh, 0xf); 218 bus_space_unmap(ids->ids_bst, ids->ids_dmapgh, DMAPG_IOSIZE);
215 bus_space_unmap(ids->ids_bst, ids->ids_dma2h, DMA2_IOSIZE); 219 bus_space_unmap(ids->ids_bst, ids->ids_dma2h, DMA2_IOSIZE);
216 bus_space_unmap(ids->ids_bst, ids->ids_dma1h, DMA1_IOSIZE); 220 bus_space_unmap(ids->ids_bst, ids->ids_dma1h, DMA1_IOSIZE);
217 221
218 ids->ids_initialized = 0; 222 ids->ids_initialized = 0;
219} 223}
220 224
221/* 225/*
222 * _isa_dmacascade(): program 8237 DMA controller channel to accept 226 * _isa_dmacascade(): program 8237 DMA controller channel to accept
223 * external dma control by a board. 227 * external dma control by a board.
224 */ 228 */
225int 229int
226_isa_dmacascade(struct isa_dma_state *ids, int chan) 230_isa_dmacascade(struct isa_dma_state *ids, int chan)
227{ 231{

cvs diff -r1.8 -r1.8.80.1 src/sys/dev/isa/isadmareg.h (expand / switch to unified diff)

--- src/sys/dev/isa/isadmareg.h 2008/04/28 20:23:52 1.8
+++ src/sys/dev/isa/isadmareg.h 2018/06/07 19:39:54 1.8.80.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: isadmareg.h,v 1.8 2008/04/28 20:23:52 martin Exp $ */ 1/* $NetBSD: isadmareg.h,v 1.8.80.1 2018/06/07 19:39:54 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -37,26 +37,29 @@ @@ -37,26 +37,29 @@
37 37
38/* 38/*
39 * By default, ISA DMA controllers can do 64k or 128k transfers, depending 39 * By default, ISA DMA controllers can do 64k or 128k transfers, depending
40 * on the width of the channel being used. However, this may be modified 40 * on the width of the channel being used. However, this may be modified
41 * by our parent based on bus constraints, etc. Clients of ISA DMA should 41 * by our parent based on bus constraints, etc. Clients of ISA DMA should
42 * query the ISA DMA to determine the maximum transfer size allowed. 42 * query the ISA DMA to determine the maximum transfer size allowed.
43 */ 43 */
44#define ISA_DMA_MAXSIZE_8BIT (64 * 1024) 44#define ISA_DMA_MAXSIZE_8BIT (64 * 1024)
45#define ISA_DMA_MAXSIZE_16BIT (ISA_DMA_MAXSIZE_8BIT * 2) 45#define ISA_DMA_MAXSIZE_16BIT (ISA_DMA_MAXSIZE_8BIT * 2)
46 46
47#define ISA_DMA_MAXSIZE_DEFAULT(chan) \ 47#define ISA_DMA_MAXSIZE_DEFAULT(chan) \
48 (((chan) & 4) ? ISA_DMA_MAXSIZE_16BIT : ISA_DMA_MAXSIZE_8BIT) 48 (((chan) & 4) ? ISA_DMA_MAXSIZE_16BIT : ISA_DMA_MAXSIZE_8BIT)
49 49
 50/* DMA Page Address Registers size */
 51#define DMAPG_IOSIZE (1*15)
 52
50/* 53/*
51 * Register definitions for DMA controller 1 (channels 0..3): 54 * Register definitions for DMA controller 1 (channels 0..3):
52 */ 55 */
53#define DMA1_CHN(c) (1*(2*(c))) /* addr reg for channel c */ 56#define DMA1_CHN(c) (1*(2*(c))) /* addr reg for channel c */
54#define DMA1_SR (1*8) /* status register */ 57#define DMA1_SR (1*8) /* status register */
55#define DMA1_SMSK (1*10) /* single mask register */ 58#define DMA1_SMSK (1*10) /* single mask register */
56#define DMA1_MODE (1*11) /* mode register */ 59#define DMA1_MODE (1*11) /* mode register */
57#define DMA1_FFC (1*12) /* clear first/last FF */ 60#define DMA1_FFC (1*12) /* clear first/last FF */
58#define DMA1_MASK (1*15) /* mask register */ 61#define DMA1_MASK (1*15) /* mask register */
59 62
60#define DMA1_IOSIZE (1*16) 63#define DMA1_IOSIZE (1*16)
61 64
62/* 65/*

cvs diff -r1.9 -r1.9.156.1 src/sys/dev/isa/isareg.h (expand / switch to unified diff)

--- src/sys/dev/isa/isareg.h 2005/12/11 12:22:02 1.9
+++ src/sys/dev/isa/isareg.h 2018/06/07 19:39:54 1.9.156.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: isareg.h,v 1.9 2005/12/11 12:22:02 christos Exp $ */ 1/* $NetBSD: isareg.h,v 1.9.156.1 2018/06/07 19:39:54 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1990 The Regents of the University of California. 4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * William Jolitz. 8 * William Jolitz.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -45,27 +45,27 @@ @@ -45,27 +45,27 @@
45#ifndef IO_ISABEGIN 45#ifndef IO_ISABEGIN
46#define IO_ISABEGIN 0x000 /* 0x000 - Beginning of I/O Registers */ 46#define IO_ISABEGIN 0x000 /* 0x000 - Beginning of I/O Registers */
47 47
48 /* CPU Board */ 48 /* CPU Board */
49#define IO_DMA1 0x000 /* 8237A DMA Controller #1 */ 49#define IO_DMA1 0x000 /* 8237A DMA Controller #1 */
50#define IO_ICU1 0x020 /* 8259A Interrupt Controller #1 */ 50#define IO_ICU1 0x020 /* 8259A Interrupt Controller #1 */
51#define IO_PMP1 0x026 /* 82347 Power Management Peripheral */ 51#define IO_PMP1 0x026 /* 82347 Power Management Peripheral */
52#define IO_TIMER1 0x040 /* 8253 Timer #1 */ 52#define IO_TIMER1 0x040 /* 8253 Timer #1 */
53#define IO_TIMER2 0x048 /* 8253 Timer #2 (EISA only) */ 53#define IO_TIMER2 0x048 /* 8253 Timer #2 (EISA only) */
54#define IO_KBD 0x060 /* 8042 Keyboard */ 54#define IO_KBD 0x060 /* 8042 Keyboard */
55#define IO_PPI 0x061 /* Programmable Peripheral Interface */ 55#define IO_PPI 0x061 /* Programmable Peripheral Interface */
56#define IO_RTC 0x070 /* RTC */ 56#define IO_RTC 0x070 /* RTC */
57#define IO_NMI IO_RTC /* NMI Control */ 57#define IO_NMI IO_RTC /* NMI Control */
58#define IO_DMAPG 0x080 /* DMA Page Registers */ 58#define IO_DMAPG 0x081 /* DMA Page Registers */
59#define IO_ICU2 0x0A0 /* 8259A Interrupt Controller #2 */ 59#define IO_ICU2 0x0A0 /* 8259A Interrupt Controller #2 */
60#define IO_DMA2 0x0C0 /* 8237A DMA Controller #2 */ 60#define IO_DMA2 0x0C0 /* 8237A DMA Controller #2 */
61#define IO_NPX 0x0F0 /* Numeric Coprocessor */ 61#define IO_NPX 0x0F0 /* Numeric Coprocessor */
62 62
63 /* Cards */ 63 /* Cards */
64 /* 0x100 - 0x16F Open */ 64 /* 0x100 - 0x16F Open */
65 65
66#define IO_WD2 0x170 /* Secondary Fixed Disk Controller */ 66#define IO_WD2 0x170 /* Secondary Fixed Disk Controller */
67#define IO_PMP2 0x178 /* 82347 Power Management Peripheral */ 67#define IO_PMP2 0x178 /* 82347 Power Management Peripheral */
68 68
69 /* 0x17A - 0x1EF Open */ 69 /* 0x17A - 0x1EF Open */
70 70
71#define IO_WD1 0x1f0 /* Primary Fixed Disk Controller */ 71#define IO_WD1 0x1f0 /* Primary Fixed Disk Controller */