1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
/* $NetBSD: atppc_isa.c,v 1.17 2022/09/25 17:09:36 thorpej Exp $ */
/*-
* Copyright (c) 2001 Alcove - Nicolas Souchu
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* FreeBSD: src/sys/isa/ppc.c,v 1.26.2.5 2001/10/02 05:21:45 nsouch Exp
*
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: atppc_isa.c,v 1.17 2022/09/25 17:09:36 thorpej Exp $");
#include "opt_atppc.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/intr.h>
#include <sys/bus.h>
#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>
#include <dev/isa/isadmavar.h>
#include <dev/ic/atppcreg.h>
#include <dev/ic/atppcvar.h>
#include <dev/isa/atppc_isadma.h>
/*
* ISA bus attach code for atppc driver.
* Note on capabilities: capabilities may exist in the chipset but may not
* necessarily be useable. I.e. you may specify an IRQ in the autoconfig, but
* will the port actually have an IRQ assigned to it at the hardware level?
* How can you test if the capabilities can be used? For interrupts, see if a
* handler exists (sc_intr != NULL). For DMA, see if the sc_dma_start() and
* sc_dma_finish() function pointers are not NULL.
*/
/* Configuration data for atppc on isa bus. */
struct atppc_isa_softc {
/* Machine independent device data */
struct atppc_softc sc_atppc;
/* IRQ/DRQ/IO Port assignments on ISA bus */
int sc_irq;
int sc_drq;
int sc_iobase;
/* ISA chipset tag */
isa_chipset_tag_t sc_ic;
};
/* Probe and attach functions for a atppc device on the ISA bus. */
static int atppc_isa_probe(device_t, cfdata_t, void *);
static void atppc_isa_attach(device_t, device_t, void *);
static int atppc_isa_dma_start(struct atppc_softc *, void *, u_int,
u_int8_t);
static int atppc_isa_dma_finish(struct atppc_softc *);
static int atppc_isa_dma_abort(struct atppc_softc *);
static int atppc_isa_dma_malloc(device_t, void **, bus_addr_t *,
bus_size_t);
static void atppc_isa_dma_free(device_t, void **, bus_addr_t *,
bus_size_t);
CFATTACH_DECL_NEW(atppc_isa, sizeof(struct atppc_isa_softc), atppc_isa_probe,
atppc_isa_attach, NULL, NULL);
/*
* Probe function: find parallel port controller on isa bus. Combined from
* lpt_isa_probe() in lpt.c and atppc_detect_port() from FreeBSD's ppc.c.
*/
static int
atppc_isa_probe(device_t parent, cfdata_t cf, void *aux)
{
bus_space_handle_t ioh;
struct isa_attach_args *ia = aux;
bus_space_tag_t iot = ia->ia_iot;
int rval = 0;
if (ia->ia_nio < 1)
return (0);
/* Disallow wildcarded i/o address */
if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
return (0);
if (bus_space_map(iot, ia->ia_io[0].ir_addr, IO_LPTSIZE, 0, &ioh))
return (0);
if (atppc_detect_port(iot, ioh) == 0)
rval = 1;
bus_space_unmap(iot, ioh, IO_LPTSIZE);
if (rval) {
ia->ia_nio = 1;
ia->ia_io[0].ir_size = IO_LPTSIZE;
ia->ia_nirq = 1;
ia->ia_ndrq = 1;
ia->ia_niomem = 0;
}
return (rval);
}
/* Attach function: attach and configure parallel port controller on isa bus. */
static void
atppc_isa_attach(device_t parent, device_t self, void *aux)
{
struct atppc_isa_softc *sc = device_private(self);
struct atppc_softc *lsc = &sc->sc_atppc;
struct isa_attach_args *ia = aux;
printf(": AT Parallel Port\n");
lsc->sc_iot = ia->ia_iot;
lsc->sc_dmat = ia->ia_dmat;
lsc->sc_has = 0;
sc->sc_ic = ia->ia_ic;
sc->sc_iobase = ia->ia_io->ir_addr;
if (bus_space_map(lsc->sc_iot, sc->sc_iobase, IO_LPTSIZE, 0,
&lsc->sc_ioh) != 0) {
aprint_error_dev(self, "attempt to map bus space failed, device not "
"properly attached.\n");
lsc->sc_dev_ok = ATPPC_NOATTACH;
return;
}
lsc->sc_dev = self;
lsc->sc_dev_ok = ATPPC_ATTACHED;
/* Assign interrupt handler */
if (!(device_cfdata(self)->cf_flags & ATPPC_FLAG_DISABLE_INTR)
&& ia->ia_irq->ir_irq != ISA_UNKNOWN_IRQ
&& ia->ia_nirq >= 1) {
sc->sc_irq = ia->ia_irq[0].ir_irq;
} else
sc->sc_irq = -1;
if (sc->sc_irq > 0) {
/* Establish interrupt handler. */
lsc->sc_ieh = isa_intr_establish(sc->sc_ic, sc->sc_irq,
IST_EDGE, IPL_TTY, atppcintr, lsc->sc_dev);
lsc->sc_has |= ATPPC_HAS_INTR;
}
/* Configure DMA */
if (!(device_cfdata(self)->cf_flags & ATPPC_FLAG_DISABLE_DMA)
&& ia->ia_drq->ir_drq != ISA_UNKNOWN_DRQ
&& ia->ia_ndrq >= 1)
sc->sc_drq = ia->ia_drq[0].ir_drq;
else
sc->sc_drq = -1;
if (sc->sc_drq != -1
&& atppc_isadma_setup(lsc, sc->sc_ic, sc->sc_drq) == 0) {
lsc->sc_has |= ATPPC_HAS_DMA;
/* setup DMA hooks */
lsc->sc_dma_start = atppc_isa_dma_start;
lsc->sc_dma_finish = atppc_isa_dma_finish;
lsc->sc_dma_abort = atppc_isa_dma_abort;
lsc->sc_dma_malloc = atppc_isa_dma_malloc;
lsc->sc_dma_free = atppc_isa_dma_free;
}
/* Run soft configuration attach */
atppc_sc_attach(lsc);
return;
}
/* Start DMA operation over ISA bus */
static int
atppc_isa_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
u_int8_t mode)
{
struct atppc_isa_softc *sc = (struct atppc_isa_softc *) lsc;
return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode);
}
/* Stop DMA operation over ISA bus */
static int
atppc_isa_dma_finish(struct atppc_softc *lsc)
{
struct atppc_isa_softc *sc = (struct atppc_isa_softc *) lsc;
return atppc_isadma_finish(sc->sc_ic, sc->sc_drq);
}
/* Abort DMA operation over ISA bus */
static int
atppc_isa_dma_abort(struct atppc_softc *lsc)
{
struct atppc_isa_softc *sc = (struct atppc_isa_softc *) lsc;
return atppc_isadma_abort(sc->sc_ic, sc->sc_drq);
}
/* Allocate memory for DMA over ISA bus */
static int
atppc_isa_dma_malloc(device_t dev, void **buf, bus_addr_t *bus_addr,
bus_size_t size)
{
struct atppc_isa_softc *sc = device_private(dev);
return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
}
/* Free memory allocated by atppc_isa_dma_malloc() */
static void
atppc_isa_dma_free(device_t dev, void **buf, bus_addr_t *bus_addr,
bus_size_t size)
{
struct atppc_isa_softc *sc = device_private(dev);
return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
}
|