xref: /netbsd/share/man/man9/isa.9 (revision bf9ec67e)
1.\"     $NetBSD: isa.9,v 1.6 2002/02/13 08:18:42 ross Exp $
2.\"
3.\" Copyright (c) 2001 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Gregory McGarry.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd June 19, 2001
38.Dt ISA 9
39.Os
40.Sh NAME
41.Nm ISA ,
42.Nm isa_intr_alloc ,
43.Nm isa_intr_establish ,
44.Nm isa_intr_disestablish ,
45.Nm isa_intr_evcnt ,
46.Nm isa_dmamap_create ,
47.Nm isa_dmamap_destroy ,
48.Nm isa_dmamem_alloc ,
49.Nm isa_dmamem_free ,
50.Nm isa_dmamem_map ,
51.Nm isa_dmamem_unmap ,
52.Nm isa_malloc ,
53.Nm isa_free ,
54.Nm isa_dmastart ,
55.Nm isa_dmaabort ,
56.Nm isa_dmacount ,
57.Nm isa_dmadone ,
58.Nm isa_dmamaxsize ,
59.Nm isa_drq_isfree ,
60.Nm isa_dmacascade ,
61.Nm isa_mappage
62.Nd Industry-standard Architecture
63.Sh SYNOPSIS
64.Fd #include \*[Lt]machine/bus.h\*[Gt]
65.Fd #include \*[Lt]dev/isa/isareg.h\*[Gt]
66.Fd #include \*[Lt]dev/isa/isavar.h\*[Gt]
67.Ft int
68.Fn isa_intr_alloc "isa_chipset_tag_t ic" "int mask" "int type" \
69"int *irq"
70.Ft const struct evcnt *
71.Fn isa_intr_evcnt "isa_chipset_tag_t ic" "int irq"
72.Ft void *
73.Fn isa_intr_establish "isa_chipset_tag_t ic" "int irq" "int type" \
74"int level" "int (*handler)(void *)" "void *arg"
75.Ft void
76.Fn isa_intr_disestablish "isa_chipset_tag_t ic" "void *ih"
77.Fd #include \*[Lt]dev/isa/isadmareg.h\*[Gt]
78.Fd #include \*[Lt]dev/isa/isadmavar.h\*[Gt]
79.Ft int
80.Fn isa_dmamap_create "isa_chipset_tag_t ic" "int chan" "bus_size_t size" \
81"int flags"
82.Ft void
83.Fn isa_dmamap_destroy "isa_chipset_tag_t ic" "int chan"
84.Ft int
85.Fn isa_dmamem_alloc "isa_chipset_tag_t ic" "int chan" "bus_size_t size" \
86"bus_addr_t *addrp" "int flags"
87.Ft void
88.Fn isa_dmamem_free "isa_chipset_tag_t ic" "int chan" "bus_addr_t addr" \
89"bus_size_t size"
90.Ft int
91.Fn isa_dmamem_map "isa_chipset_tag_t ic" "int chan" "bus_addr_t addr" \
92"bus_size_t size" "caddr_t *kvap" "int flags"
93.Ft void
94.Fn isa_dmamem_unmap "isa_chipset_tag_t ic" "int chan" "caddr_t kva" \
95"size_t size"
96.Ft void *
97.Fn isa_malloc "isa_chipset_tag_t ic" "int chan" "size_t size" \
98"int pool" "int flags"
99.Ft void
100.Fn isa_free "void *addrp" "int pool"
101.Ft int
102.Fn isa_dmastart "isa_chipset_tag_t ic" "int chan" "bus_addr_t addr" \
103"bus_size_t size" "struct proc *proc" "int flags" "int bf"
104.Ft void
105.Fn isa_dmaabort "isa_chipset_tag_t ic" "int chan"
106.Ft bus_size_t
107.Fn isa_dmacount "isa_chipset_tag_t ic" "int chan"
108.Ft void
109.Fn isa_dmadone "isa_chipset_tag_t ic" "int chan"
110.Ft bus_size_t
111.Fn isa_dmamaxsize "isa_chipset_tag_t ic" "int chan"
112.Ft int
113.Fn isa_drq_isfree "isa_chipset_tag_t ic" "int chan"
114.Ft int
115.Fn isa_dmacascade "isa_chipset_tag_t ic" "int chan"
116.Ft paddr_t
117.Fn isa_mappage "void *mem" "off_t offset" "int prot"
118.Sh DESCRIPTION
119The machine-independent
120.Nm
121subsystem provides support for the ISA bus.
122.Pp
123The ISA bus was introduced on the IBM PC/AT.  It is an extension to
124the original bus found on the original IBM PC.  The ISA bus is
125essentially the host bus of the Intel 80286 processor, however the
126widespread acceptance of the bus as a defacto standard has seen it
127appear on systems without Intel processors.
128.Pp
129The ISA bus has a 16-bit data bus, a 24-bit memory address bus, a
13016-bit I/O address bus, and operates at 8MHz.  It provides 15
131interrupt lines and 8 DMA channels supporting DMA transfers of 64KB or
132128KB transfers depending on the width of the channel being
133used. Historically, some devices only decoded the 10 lowest bits of
134the I/O address bus, preventing use of the full 16-bit address space.
135.Pp
136On newer machines, the ISA bus is no longer connected directly to the
137host bus, and is usually connected via a PCI-ISA bridge.  Either way,
138the bus looks the same to the device driver.
139.Sh DATA TYPES
140Drivers for devices attached to the
141.Nm
142bus will make use of the following data types:
143.Bl -tag -width compact
144.It Fa isa_chipset_tag_t
145Chipset tag for the ISA bus.
146.It Fa struct isa_attach_args
147Location hints for devices are recorded in this structure.  It
148contains the following members:
149.Bd -literal
150	bus_space_tag_t ia_iot;		/* isa i/o space tag */
151	bus_space_tag_t ia_memt;	/* isa mem space tag */
152	bus_dma_tag_t ia_dmat;		/* DMA tag */
153	isa_chipset_tag_t ia_ic;
154	int ia_iobase;			/* base i/o address */
155	int ia_iosize;			/* span of ports used */
156	int ia_maddr;			/* physical mem addr */
157	u_int ia_msize;			/* size of memory */
158	int ia_irq;			/* interrupt request */
159	int ia_drq;			/* DMA request */
160	int ia_drq2;			/* second DMA request */
161	void *ia_aux;			/* driver specific */
162.Ed
163.El
164.Sh FUNCTIONS
165.Bl -tag -width compact
166.It Fn isa_intr_alloc "ic" "mask" "type" "irq"
167This function is generally not required by device drivers.  It is used
168by bridges attaching other busses to the ISA bus.
169.It Fn isa_intr_evcnt "ic" "irq"
170Returns the event counter associated with interrupt line
171.Fa irq .
172.It Fn isa_intr_establish "ic" "irq" "type" "level" "handler" "arg"
173To establish an ISA interrupt handler, a driver calls
174.Fn isa_intr_establish
175with the interrupt number
176.Fa irq ,
177type
178.Fa type ,
179and level
180.Fa level .
181When the interrupt occurs the function
182.Fa handler
183is called with argument
184.Fa arg .
185Valid values for
186.Fa type
187are:
188.Bl -tag -width compact
189.It IST_NONE
190Reserve interrupt, but don't actually establish.
191.It IST_EDGE
192Edge-triggered interrupt.
193.It IST_LEVEL
194Level-triggered interrupt.
195.It IST_PULSE
196Pulse-triggered interrupt.
197.El
198.sp
199.Fn isa_intr_establish
200returns an opaque handle to an event descriptor if it succeeds, and
201returns NULL on failure.
202.Pp
203.It Fn isa_intr_disestablish "ic" "ih"
204Dis-establish the interrupt handler with handle
205.Fa ih .
206The handle was returned from
207.Fn isa_intr_establish .
208.It Fn isa_dmamap_create "ic" "chan" "size" "flags"
209Creates a DMA map for channel
210.Fa chan .
211It is initialised to accept maximum DMA transfers of size
212.Fa size .
213Valid values for the
214.Fa flags
215argument are the same as for
216.Fn bus_dmamap_create
217(see
218.Xr bus_dma 9 ) .
219This function returns zero on success or an error value on failure.
220.It Fn isa_dmamap_destroy "ic" "chan"
221Destroy the DMA map for DMA channel
222.Fa chan .
223.It Fn isa_dmamem_alloc "ic" "chan" "size" "addrp" "flags"
224Allocate DMA-safe memory of size
225.Fa size
226for channel
227.Fa chan .
228Valid values for the
229.Fa flags
230argument are the same as for
231.Fn bus_dmamem_alloc
232(see
233.Xr bus_dma 9 ) .
234The bus-address of the memory is returned in
235.Fa addrp .
236This function returns zero on success or an error value on failure.
237.It Fn isa_dmamem_free "ic" "chan" "addr" "size"
238Frees memory previously allocated by
239.Fn isa_dmamem_alloc
240for channel
241.Fa chan .
242The bus-address and size of the memory are specified by
243.Fa addr
244and
245.Fa size
246respectively.
247.It Fn isa_dmamem_map "ic" "chan" "addr" "size" "kvap" "flags"
248Maps DMA-safe memory (allocated with
249.Fn isa_dmamem_alloc )
250specified by bus-address
251.Fa addr
252and of size
253.Fa size
254into kernel virtual address space for DMA channel
255.Fa chan .
256Valid values for the
257.Fa flags
258argument are the same as for
259.Fn bus_dmamem_map
260(see
261.Xr bus_dma 9 ) .
262The kernel virtual address is returned in
263.Fa kvap .
264This function returns zero on success or an error value on failure.
265.It Fn isa_dmamem_unmap "ic" "chan" "kva" "size"
266Unmaps memory (previously mapped with
267.Fn isa_dmamem_map )
268of size
269.Fa size
270for channel
271.Fa chan .
272The kernel virtual address space used by the mapping is freed.
273.It Fn isa_malloc "ic" "chan" "size" "pool" "flags"
274This function is a shortcut for allocating and mapping DMA-safe memory
275in a single step.  The arguments correspond with the arguments to
276.Fn isa_dmamem_alloc
277and
278.Fn isa_dmamem_map .
279The argument
280.Fa pool
281is a pool to record the memory allocation.  This function returns
282a pointer to the DMA-safe memory.
283.It Fn isa_free "addrp" "pool"
284This function is a shortcut for unmapping and deallocating DMA-safe
285memory in a single step.  It replaces
286.Fn isa_dmamem_unmap
287and
288.Fn isa_dmamem_free .
289The argument
290.Fa addrp
291is the pointer to the DMA-safe memory returned by
292.Fn isa_malloc .
293The argument
294.Fa pool
295is the same as the value passed to
296.Fn isa_malloc .
297.It Fn isa_dmastart "ic" "chan" "addr" "size" "proc" "flags" "bf"
298Load DMA memory specified by address
299.Fa addr
300of size
301.Fa size
302into the DMA controller at channel
303.Fa chan
304and set it in motion.
305The argument
306.Fa proc
307is used to indicate the address space in which the buffer is located.
308If NULL, the buffer is assumed to be in kernel space.  Otherwise, the
309buffer is assumed to be in process
310.Fa proc 's
311address space.
312The argument
313.Fa flags
314describes the type of ISA DMA.  Valid values are:
315.Bl -tag -width compact
316.It DMAMODE_WRITE
317DMA transfer from host to device.
318.It DMAMODE_READ
319DMA transfer to host from device.
320.It DMAMODE_SINGLE
321Transfer buffer once and stop.
322.It DMAMODE_DEMAND
323Demand mode.
324.It DMAMODE_LOOP
325Transfer buffer continuously in loop until notified to stop.
326.It DMAMODE_LOOPDEMAND
327Transfer buffer continuously in loop and demand mode.
328.El
329.sp
330The argument
331.Fa bf
332is the bus-space flags.  Valid values are the same as for
333.Fn bus_dmamap_load
334(see
335.Xr bus_dma 9 ) .
336.It Fn isa_dmaabort "ic" "chan"
337Abort a DMA transfer on channel
338.Fa chan .
339.It Fn isa_dmacount "ic" "chan"
340Returns the offset in the DMA memory of the current DMA transfer on
341channel
342.Fa chan .
343.It Fn isa_dmadone "ic" "chan"
344Unloads the DMA memory
345on channel
346.Fa chan
347after a DMA transfer has completed.
348.It Fn isa_dmamaxsize "ic" "chan"
349Returns the maximum allowable DMA transfer size for channel
350.Fa chan .
351.It Fn isa_drq_isfree "ic" "chan"
352If the
353.Fa ia_drq
354or
355.Fa ia_drq2
356members of
357.Fa struct isa_attach_args
358are wildcarded, then the driver is expected to probe the hardware for
359valid DMA channels.  In this case, the driver can check to see if the
360hardware-supported DMA channel
361.Fa chan
362is available for use.
363.It Fn isa_dmacascade "ic" "chan"
364Programs the 8237 DMA controller channel
365.Fa chan
366to accept external DMA control by the device hardware.
367.It Fn isa_mappage "mem" "offset" "prot"
368Provides support for user
369.Xr mmap 2 'ing
370of DMA-safe memory.
371.El
372.Sh AUTOCONFIGURATION
373The ISA bus is an indirect-connection bus.  During autoconfiguration
374each driver is required to probe the bus for the presence of a device.
375An ISA driver will receive a pointer to
376.Fa struct isa_attach_args
377hinting at "locations" on the ISA bus where the device may be located.
378They should use the
379.Em ia_iobase ,
380.Em ia_iosize ,
381.Em ia_maddr ,
382and
383.Em ia_msize
384members.  Not all of these hints will be necessary; locators may
385be wildcarded with IOBASEUNK and MADDRUNK for
386.Em ia_iobase
387and
388.Em ia_maddr
389respectively.  If a driver can probe the device for configuration
390information at default locations, it may update the members of
391.Fa struct isa_attach_args .
392The IRQ and DMA locators can also be wildcarded with IRQUNK and DRQUNK
393respectively.
394.Pp
395During the driver attach step, the I/O and memory address spaces
396should be mapped (see
397.Xr bus_space 9 ) .
398.Sh DMA SUPPORT
399Extensive DMA facilities are provided for the ISA bus.  A driver can
400use up to two DMA channels simultaneously.  The DMA channels allocated
401during autoconfiguration are passed to the driver during the driver
402attach using the
403.Fa ia_drq
404and
405.Fa ia_drq2
406members of
407.Fa struct isa_attach_args .
408.Pp
409Before allocating resources for DMA transfers on the ISA bus, a driver
410should check the maximum allowable DMA transfer size for the DMA
411channel using
412.Fn isa_dmamaxsize .
413.Pp
414A DMA map should be created first using
415.Fn isa_dmamap_create .
416A DMA map describes how DMA memory is loaded into the DMA controllers.
417Only DMA-safe memory can be used for DMA transfers.  DMA-safe memory
418is allocated using
419.Fn isa_dmamem_alloc .
420The memory allocated by
421.Fn isa_dmamem_alloc
422must now be mapped into kernel virtual address space by
423.Fn isa_dmamem_map
424so that it can be accessed by the driver.
425.Pp
426For a DMA transfer from the host to the device, the driver will fill
427the DMA memory with the data to be transferred.  The DMA-transfer of
428the memory is started using
429.Fn isa_dmastart
430with
431.Fa flags
432containing DMAMODE_WRITE.
433When the DMA transfer is completed, a call to
434.Fn isa_dmadone
435cleans up the DMA transfer by unloading the memory from the
436controller.
437.Pp
438For a DMA transfer from the device to the host, the DMA-transfer is
439started using
440.Fn isa_dmastart
441with
442.Fa flags
443containing DMAMODE_READ.
444When the DMA transfer is completed, a call to
445.Fn isa_dmadone
446cleans up the DMA transfer by unloading the memory from the
447controller.  The memory can now be access by the driver.
448.Pp
449When the DMA resources are no longer required they should be released
450using
451.Fn isa_dmamem_unmap ,
452.Fn isa_dmamem_free
453and
454.Fn isa_dmamap_destroy .
455.Sh CODE REFERENCES
456This section describes places within the
457.Nx
458source tree where actual code implementing or utilising the
459machine-independent ISA subsystem can be found.  All pathnames are
460relative to
461.Pa /usr/src .
462.Pp
463The ISA subsystem itself is implemented within the files
464.Pa sys/dev/isa/isa.c
465and
466.Pa sys/dev/isa/isadma.c .
467.Sh SEE ALSO
468.Xr isa 4 ,
469.Xr autoconf 9 ,
470.Xr bus_dma 9 ,
471.Xr bus_space 9 ,
472.Xr driver 9 ,
473.Xr isapnp 9
474.Sh HISTORY
475The machine-independent
476.Nm
477subsystem appeared in
478.Nx 1.2 .
479.Sh BUGS
480The previous behaviour of
481.Fn isa_intr_establish
482was to invoke
483.Fn panic
484on failure.
485.Fn isa_intr_establish
486now returns NULL on failure.  Some old drivers written for the former
487behaviour discard the return value.
488