1 .\" $NetBSD: wdc.9,v 1.15 2005/12/26 19:48:13 perry Exp $
3 .\" Copyright (c) 1998 Manuel Bouyer.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 .\" INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 .Nd machine-independent IDE/ATAPI driver
34 .In sys/dev/ic/wdcvar.h
36 .Fn wdcprobe "struct channel_softc * chp"
38 .Fn wdcattach "struct channel_softc * chp"
42 driver provides the machine independent core functions for driving IDE
44 IDE devices-specific drivers
50 will use services provided by
53 The machine-dependent bus front-end provides informations to
60 The first one defines global controller properties, and the second contains
61 per-channel informations.
63 returns informations about the attached devices in the
67 struct wdc_softc { /* Per controller state */
70 #define WDC_CAPABILITY_DATA16 0x0001
71 #define WDC_CAPABILITY_DATA32 0x0002
72 #define WDC_CAPABILITY_MODE 0x0004
73 #define WDC_CAPABILITY_DMA 0x0008
74 #define WDC_CAPABILITY_UDMA 0x0010
75 #define WDC_CAPABILITY_HWLOCK 0x0020
76 #define WDC_CAPABILITY_ATA_NOSTREAM 0x0040
77 #define WDC_CAPABILITY_ATAPI_NOSTREAM 0x0080
78 #define WDC_CAPABILITY_NO_EXTRA_RESETS 0x0100
79 #define WDC_CAPABILITY_PREATA 0x0200
80 #define WDC_CAPABILITY_IRQACK 0x0400
81 #define WDC_CAPABILITY_SINGLE_DRIVE 0x0800
82 #define WDC_CAPABILITY_NOIRQ 0x1000
83 #define WDC_CAPABILITY_SELECT 0x2000
87 struct channel_softc *channels;
90 int (*dma_init)(void *, int, int, void *, size_t, int);
91 void (*dma_start)(void *, int, int, int);
92 int (*dma_finish)(void *, int, int, int);
93 #define WDC_DMA_READ 0x01
94 #define WDC_DMA_POLL 0x02
96 int (*claim_hw)(void *, int);
97 void (*free_hw)(void *);
100 struct channel_softc { /* Per channel data */
102 struct wdc_softc *wdc;
103 bus_space_tag_t cmd_iot;
104 bus_space_handle_t cmd_ioh;
105 bus_space_tag_t ctl_iot;
106 bus_space_handle_t ctl_ioh;
107 bus_space_tag_t data32iot;
108 bus_space_handle_t data32ioh;
110 #define WDCF_ACTIVE 0x01
111 #define WDCF_IRQ_WAIT 0x10
114 struct ata_drive_datas ch_drive[2];
115 struct channel_queue *ch_queue;
118 struct ata_drive_datas {
121 #define DRIVE_ATA 0x01
122 #define DRIVE_ATAPI 0x02
123 #define DRIVE (DRIVE_ATA|DRIVE_ATAPI)
124 #define DRIVE_CAP32 0x04
125 #define DRIVE_DMA 0x08
126 #define DRIVE_UDMA 0x10
127 #define DRIVE_MODE 0x20
133 struct device *drv_softc;
138 The bus front-end needs to fill in the following elements of
140 .Bl -tag -compact -width "dma_finish" -offset "xxxx"
142 supports one or more of the WDC_CAPABILITY flags
144 number of channels supported by this controller
147 .Va struct channel_softc
152 The following elements are optional:
153 .Bl -tag -compact -width "dma_finish" -offset "xxxx"
165 .Va WDC_CAPABILITY_DATA16
167 .Va WDC_CAPABILITY_DATA32
170 whether the controller supports 16- or 32-bit I/O accesses on the data port.
171 If both are set, a test will be done for each drive using the ATA or
172 ATAPI IDENTIFY command, to automatically select the working mode.
175 .Va WDC_CAPABILITY_DMA
177 .Va WDC_CAPABILITY_UDMA
178 flags are set for controllers supporting the DMA and Ultra-DMA modes.
179 The bus front-end needs to provide the
186 is called just before issuing a DMA command to the IDE device.
187 The arguments are, respectively:
189 the channel number, the drive number on this channel,
190 the virtual address of the DMA buffer, the size of the transfer, and the
194 is called just after issuing a DMA command to the IDE device.
195 The arguments are, respectively:
197 the channel number, the drive number on this channel, and the
201 is called once the transfer is complete.
202 The arguments are, respectively:
204 the channel number, the drive number on this channel, and the
208 indicates the direction of the data transfer, and
210 indicates if the transfer will use (or used) interrupts.
213 .Va WDC_CAPABILITY_MODE
214 flag means that the bus front-end can program the PIO and DMA modes, so
216 needs to provide back the supported modes for each drive, and set the drives
222 needs to be set to the highest PIO and DMA mode supported.
224 .Va WDC_CAPABILITY_UDMA
227 must be set to the highest Ultra-DMA mode supported.
229 .Va WDC_CAPABILITY_MODE
232 will not attempt to change the current drive's settings, assuming the host's
233 firmware has done it right.
236 .Va WDC_CAPABILITY_HWLOCK
237 flag is set for controllers needing hardware looking before accessing the
239 If this flag is set, the bus front-end needs to provide the
245 will be called when the driver wants to access the controller ports.
246 The second parameter is set to 1 when it is possible to sleep waiting
247 for the lock, 0 otherwise.
248 It should return 1 when access has been granted, 0 otherwise.
249 When access has not been granted and sleep is not allowed, the bus
252 with the first argument passed to
255 This arguments will also be the one passed to
257 This function is called once the transfer is complete, so that the lock can
260 Accesses to the data port are done by using the bus_space stream functions,
262 .Va WDC_CAPABILITY_ATA_NOSTREAM
264 .Va WDC_CAPABILITY_ATAPI_NOSTREAM
266 This should not be used, unless the data bus is not wired properly (which
267 seems common on big-endian systems), and byte-order needs to be preserved
268 for compatibility with the host's firmware.
269 Also note that the IDE bus is a little-endian bus, so the bus_space
270 functions used for the bus_space tag passed in the
272 have to do the appropriate byte-swapping for big-endian systems.
274 .Va WDC_CAPABILITY_NO_EXTRA_RESETS
275 avoid the controller reset at the end of the disks probe.
276 This reset is needed for some controllers, but causes problems with some
279 .Va WDC_CAPABILITY_NOIRQ
280 tells the driver that this controller doesn't have its interrupt lines
281 wired up usefully, so it should always use polled transfers.
283 The bus front-end needs to fill in the following
286 .Bl -tag -compact -width "dma_finish" -offset "xxxx"
288 The channel number on the controller
290 A pointer to the controller's wdc_softc
292 Bus-space tag and handle for access to the command block registers (which
293 includes the 16-bit data port)
295 Bus-space tag and handle for access to the control block registers
298 .Va struct channel_queue .
299 This will hold the queues of outstanding commands for this controller.
301 The following elements are optional:
302 .Bl -tag -compact -width "dma_finish" -offset "xxxx"
303 .It data32iot, data32ioh
304 Bus-space tag and handle for 32-bit data accesses.
306 .Va WDC_CAPABILITY_DATA32
307 is set in the controller's
312 can point to a common
313 .Va struct channel_queue
314 if the controller doesn't support concurrent access to its different channels.
315 If all channels are independent, it is recommended that each channel has
318 (for better performance).
320 The bus-specific front-end can use the
322 function, with a properly initialised
323 .Va struct channel_softc
329 to be easily used in bus front-end probe functions).
330 This function will return an integer where bit 0 will be set if the master
331 device has been found, and 1 if the slave device has been found.
333 The bus-specific attach function has to call
335 for each channel, with a pointer to a properly initialised
338 This will probe devices attached to the IDE channel and attach them.
339 Once this function returns, the
343 will contain the drive's capabilities.
344 This can be used to properly initialise the controller's mode, or disable a
345 channel without drives.
347 The elements of interest in
349 for a bus front-end are:
350 .Bl -tag -compact -width "dma_finish" -offset "xxxx"
354 Flags indicating the drive capabilities.
357 indicate either that no drive is here, or that no driver was
358 found for this device.
359 .It PIO_mode, DMA_mode, UDMA_mode
360 the highest supported modes for this drive compatible with the controller's
362 Needs to be reset to the mode to use by the drive, if known.
364 A pointer to the drive's softc.
365 Can be used to print the drive's name.
369 handles the following flags:
370 .Bl -tag -compact -width "dma_finish" -offset "xxxx"
371 .It DRIVE_ATA, DRIVE_ATAPI
372 Gives the drive type, if any.
373 The shortcut DRIVE can be used to just test the presence/absence of a drive.
375 This drive works with 32-bit data I/O.
377 This drive supports DMA.
379 This drive supports Ultra-DMA.
381 This drive properly reported its PIO and DMA mode.
384 Once the controller has been initialised, it has to reset the
388 as well as the values of
393 if the modes to be used are not highest ones supported by the drive.
398 The wdc core functions are implemented in
399 .Pa sys/dev/ic/wdc.c .
400 Low-level ATA and ATAPI support is provided by
401 .Pa sys/dev/ata_wdc.c
403 .Pa sys/dev/scsipi/atapi_wdc.c
406 An example of a simple bus front-end can be found in
407 .Pa sys/dev/isapnp/wdc_isapnp.c .
408 A more complex one, with multiple channels and bus-master DMA support is
409 .Pa sys/dev/pci/pciide.c .
410 .Pa sys/arch/atari/dev/wdc_mb.c
411 makes use of hardware locking, and also provides an example of bus-front
412 end for a big-endian system, which needs byte-swapping bus_space functions.