aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-02-01 17:58:02 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-02-01 17:58:02 -0500
commitf3191248bf1bf6627c04c5624904df45e0a979ed (patch)
treead7a49bf947f849740999702204373c3c12caea7
parentcbb51afa6d69be003cc827a89e023906885f241e (diff)
parenta14dc57495899175a0827673fe23ed17b5653896 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6: (100 commits) ide: move hwif_register() call out of ide_probe_port() ide: factor out code for tuning devices from ide_probe_port() ide: move handling of I/O resources out of ide_probe_port() ide: make probe_hwif() return an error value ide: use ide_remove_port_from_hwgroup in init_irq() ide: prepare init_irq() for using ide_remove_port_from_hwgroup() ide: factor out code removing port from hwgroup from ide_unregister() ide: I/O resources are released too early in ide_unregister() ide: cleanup ide_system_bus_speed() ide: remove needless zeroing of hwgroup fields from init_irq() ide: remove unused ide_hwgroup_t fields ide_platform: remove struct hwif_prop ide: remove hwif->present manipulations from hwif_init() ide: move wait_hwif_ready() documentation in the right place ide: fix handling of busy I/O resources in probe_hwif() <linux/hdsmart.h> is not used by kernel code ide: don't include <linux/hdsmart.h> ide-floppy: cleanup header ide: update/add my Copyrights ide: delete filenames/versions from comments ...
-rw-r--r--Documentation/ide/ChangeLog.ide-cd.1994-2004268
-rw-r--r--Documentation/ide/ChangeLog.ide-floppy.1996-200263
-rw-r--r--drivers/cdrom/cdrom.c6
-rw-r--r--drivers/ide/Kconfig55
-rw-r--r--drivers/ide/Makefile4
-rw-r--r--drivers/ide/arm/bast-ide.c3
-rw-r--r--drivers/ide/arm/icside.c50
-rw-r--r--drivers/ide/arm/rapide.c6
-rw-r--r--drivers/ide/cris/ide-cris.c3
-rw-r--r--drivers/ide/h8300/ide-h8300.c1
-rw-r--r--drivers/ide/ide-acpi.c1
-rw-r--r--drivers/ide/ide-cd.c2333
-rw-r--r--drivers/ide/ide-cd.h706
-rw-r--r--drivers/ide/ide-cd_ioctl.c475
-rw-r--r--drivers/ide/ide-cd_verbose.c359
-rw-r--r--drivers/ide/ide-disk.c11
-rw-r--r--drivers/ide/ide-dma.c110
-rw-r--r--drivers/ide/ide-floppy.c122
-rw-r--r--drivers/ide/ide-io.c2
-rw-r--r--drivers/ide/ide-iops.c4
-rw-r--r--drivers/ide/ide-lib.c6
-rw-r--r--drivers/ide/ide-pnp.c2
-rw-r--r--drivers/ide/ide-probe.c190
-rw-r--r--drivers/ide/ide-proc.c2
-rw-r--r--drivers/ide/ide-scan-pci.c9
-rw-r--r--drivers/ide/ide-tape.c80
-rw-r--r--drivers/ide/ide-taskfile.c12
-rw-r--r--drivers/ide/ide-timing.h2
-rw-r--r--drivers/ide/ide.c116
-rw-r--r--drivers/ide/legacy/ali14xx.c2
-rw-r--r--drivers/ide/legacy/buddha.c2
-rw-r--r--drivers/ide/legacy/dtc2278.c2
-rw-r--r--drivers/ide/legacy/falconide.c3
-rw-r--r--drivers/ide/legacy/gayle.c2
-rw-r--r--drivers/ide/legacy/ht6560b.c2
-rw-r--r--drivers/ide/legacy/ide-cs.c2
-rw-r--r--drivers/ide/legacy/ide_platform.c34
-rw-r--r--drivers/ide/legacy/macide.c2
-rw-r--r--drivers/ide/legacy/q40ide.c2
-rw-r--r--drivers/ide/legacy/qd65xx.c2
-rw-r--r--drivers/ide/legacy/qd65xx.h2
-rw-r--r--drivers/ide/legacy/umc8672.c2
-rw-r--r--drivers/ide/mips/au1xxx-ide.c43
-rw-r--r--drivers/ide/pci/aec62xx.c11
-rw-r--r--drivers/ide/pci/alim15x3.c20
-rw-r--r--drivers/ide/pci/amd74xx.c281
-rw-r--r--drivers/ide/pci/atiixp.c11
-rw-r--r--drivers/ide/pci/cmd640.c2
-rw-r--r--drivers/ide/pci/cmd64x.c20
-rw-r--r--drivers/ide/pci/cs5520.c2
-rw-r--r--drivers/ide/pci/cs5530.c2
-rw-r--r--drivers/ide/pci/cs5535.c6
-rw-r--r--drivers/ide/pci/cy82c693.c7
-rw-r--r--drivers/ide/pci/delkin_cb.c4
-rw-r--r--drivers/ide/pci/generic.c5
-rw-r--r--drivers/ide/pci/hpt34x.c6
-rw-r--r--drivers/ide/pci/hpt366.c33
-rw-r--r--drivers/ide/pci/it8213.c7
-rw-r--r--drivers/ide/pci/it821x.c50
-rw-r--r--drivers/ide/pci/jmicron.c2
-rw-r--r--drivers/ide/pci/ns87415.c20
-rw-r--r--drivers/ide/pci/opti621.c2
-rw-r--r--drivers/ide/pci/pdc202xx_new.c6
-rw-r--r--drivers/ide/pci/pdc202xx_old.c17
-rw-r--r--drivers/ide/pci/piix.c55
-rw-r--r--drivers/ide/pci/rz1000.c4
-rw-r--r--drivers/ide/pci/sc1200.c14
-rw-r--r--drivers/ide/pci/scc_pata.c13
-rw-r--r--drivers/ide/pci/serverworks.c24
-rw-r--r--drivers/ide/pci/sgiioc4.c19
-rw-r--r--drivers/ide/pci/siimage.c53
-rw-r--r--drivers/ide/pci/sis5513.c24
-rw-r--r--drivers/ide/pci/sl82c105.c19
-rw-r--r--drivers/ide/pci/slc90e66.c9
-rw-r--r--drivers/ide/pci/tc86c001.c5
-rw-r--r--drivers/ide/pci/triflex.c4
-rw-r--r--drivers/ide/pci/trm290.c65
-rw-r--r--drivers/ide/pci/via82cxxx.c15
-rw-r--r--drivers/ide/ppc/mpc8xx.c2
-rw-r--r--drivers/ide/ppc/pmac.c39
-rw-r--r--drivers/ide/setup-pci.c94
-rw-r--r--drivers/scsi/ide-scsi.c5
-rw-r--r--include/asm-mips/mach-au1x00/au1xxx_ide.h1
-rw-r--r--include/linux/cdrom.h14
-rw-r--r--include/linux/hdsmart.h2
-rw-r--r--include/linux/ide.h40
86 files changed, 2549 insertions, 3588 deletions
diff --git a/Documentation/ide/ChangeLog.ide-cd.1994-2004 b/Documentation/ide/ChangeLog.ide-cd.1994-2004
new file mode 100644
index 00000000000..190d17bfff6
--- /dev/null
+++ b/Documentation/ide/ChangeLog.ide-cd.1994-2004
@@ -0,0 +1,268 @@
1/*
2 * 1.00 Oct 31, 1994 -- Initial version.
3 * 1.01 Nov 2, 1994 -- Fixed problem with starting request in
4 * cdrom_check_status.
5 * 1.03 Nov 25, 1994 -- leaving unmask_intr[] as a user-setting (as for disks)
6 * (from mlord) -- minor changes to cdrom_setup()
7 * -- renamed ide_dev_s to ide_drive_t, enable irq on command
8 * 2.00 Nov 27, 1994 -- Generalize packet command interface;
9 * add audio ioctls.
10 * 2.01 Dec 3, 1994 -- Rework packet command interface to handle devices
11 * which send an interrupt when ready for a command.
12 * 2.02 Dec 11, 1994 -- Cache the TOC in the driver.
13 * Don't use SCMD_PLAYAUDIO_TI; it's not included
14 * in the current version of ATAPI.
15 * Try to use LBA instead of track or MSF addressing
16 * when possible.
17 * Don't wait for READY_STAT.
18 * 2.03 Jan 10, 1995 -- Rewrite block read routines to handle block sizes
19 * other than 2k and to move multiple sectors in a
20 * single transaction.
21 * 2.04 Apr 21, 1995 -- Add work-around for Creative Labs CD220E drives.
22 * Thanks to Nick Saw <cwsaw@pts7.pts.mot.com> for
23 * help in figuring this out. Ditto for Acer and
24 * Aztech drives, which seem to have the same problem.
25 * 2.04b May 30, 1995 -- Fix to match changes in ide.c version 3.16 -ml
26 * 2.05 Jun 8, 1995 -- Don't attempt to retry after an illegal request
27 * or data protect error.
28 * Use HWIF and DEV_HWIF macros as in ide.c.
29 * Always try to do a request_sense after
30 * a failed command.
31 * Include an option to give textual descriptions
32 * of ATAPI errors.
33 * Fix a bug in handling the sector cache which
34 * showed up if the drive returned data in 512 byte
35 * blocks (like Pioneer drives). Thanks to
36 * Richard Hirst <srh@gpt.co.uk> for diagnosing this.
37 * Properly supply the page number field in the
38 * MODE_SELECT command.
39 * PLAYAUDIO12 is broken on the Aztech; work around it.
40 * 2.05x Aug 11, 1995 -- lots of data structure renaming/restructuring in ide.c
41 * (my apologies to Scott, but now ide-cd.c is independent)
42 * 3.00 Aug 22, 1995 -- Implement CDROMMULTISESSION ioctl.
43 * Implement CDROMREADAUDIO ioctl (UNTESTED).
44 * Use input_ide_data() and output_ide_data().
45 * Add door locking.
46 * Fix usage count leak in cdrom_open, which happened
47 * when a read-write mount was attempted.
48 * Try to load the disk on open.
49 * Implement CDROMEJECT_SW ioctl (off by default).
50 * Read total cdrom capacity during open.
51 * Rearrange logic in cdrom_decode_status. Issue
52 * request sense commands for failed packet commands
53 * from here instead of from cdrom_queue_packet_command.
54 * Fix a race condition in retrieving error information.
55 * Suppress printing normal unit attention errors and
56 * some drive not ready errors.
57 * Implement CDROMVOLREAD ioctl.
58 * Implement CDROMREADMODE1/2 ioctls.
59 * Fix race condition in setting up interrupt handlers
60 * when the `serialize' option is used.
61 * 3.01 Sep 2, 1995 -- Fix ordering of reenabling interrupts in
62 * cdrom_queue_request.
63 * Another try at using ide_[input,output]_data.
64 * 3.02 Sep 16, 1995 -- Stick total disk capacity in partition table as well.
65 * Make VERBOSE_IDE_CD_ERRORS dump failed command again.
66 * Dump out more information for ILLEGAL REQUEST errs.
67 * Fix handling of errors occurring before the
68 * packet command is transferred.
69 * Fix transfers with odd bytelengths.
70 * 3.03 Oct 27, 1995 -- Some Creative drives have an id of just `CD'.
71 * `DCI-2S10' drives are broken too.
72 * 3.04 Nov 20, 1995 -- So are Vertos drives.
73 * 3.05 Dec 1, 1995 -- Changes to go with overhaul of ide.c and ide-tape.c
74 * 3.06 Dec 16, 1995 -- Add support needed for partitions.
75 * More workarounds for Vertos bugs (based on patches
76 * from Holger Dietze <dietze@aix520.informatik.uni-leipzig.de>).
77 * Try to eliminate byteorder assumptions.
78 * Use atapi_cdrom_subchnl struct definition.
79 * Add STANDARD_ATAPI compilation option.
80 * 3.07 Jan 29, 1996 -- More twiddling for broken drives: Sony 55D,
81 * Vertos 300.
82 * Add NO_DOOR_LOCKING configuration option.
83 * Handle drive_cmd requests w/NULL args (for hdparm -t).
84 * Work around sporadic Sony55e audio play problem.
85 * 3.07a Feb 11, 1996 -- check drive->id for NULL before dereferencing, to fix
86 * problem with "hde=cdrom" with no drive present. -ml
87 * 3.08 Mar 6, 1996 -- More Vertos workarounds.
88 * 3.09 Apr 5, 1996 -- Add CDROMCLOSETRAY ioctl.
89 * Switch to using MSF addressing for audio commands.
90 * Reformat to match kernel tabbing style.
91 * Add CDROM_GET_UPC ioctl.
92 * 3.10 Apr 10, 1996 -- Fix compilation error with STANDARD_ATAPI.
93 * 3.11 Apr 29, 1996 -- Patch from Heiko Eißfeldt <heiko@colossus.escape.de>
94 * to remove redundant verify_area calls.
95 * 3.12 May 7, 1996 -- Rudimentary changer support. Based on patches
96 * from Gerhard Zuber <zuber@berlin.snafu.de>.
97 * Let open succeed even if there's no loaded disc.
98 * 3.13 May 19, 1996 -- Fixes for changer code.
99 * 3.14 May 29, 1996 -- Add work-around for Vertos 600.
100 * (From Hennus Bergman <hennus@sky.ow.nl>.)
101 * 3.15 July 2, 1996 -- Added support for Sanyo 3 CD changers
102 * from Ben Galliart <bgallia@luc.edu> with
103 * special help from Jeff Lightfoot
104 * <jeffml@pobox.com>
105 * 3.15a July 9, 1996 -- Improved Sanyo 3 CD changer identification
106 * 3.16 Jul 28, 1996 -- Fix from Gadi to reduce kernel stack usage for ioctl.
107 * 3.17 Sep 17, 1996 -- Tweak audio reads for some drives.
108 * Start changing CDROMLOADFROMSLOT to CDROM_SELECT_DISC.
109 * 3.18 Oct 31, 1996 -- Added module and DMA support.
110 *
111 * 4.00 Nov 5, 1996 -- New ide-cd maintainer,
112 * Erik B. Andersen <andersee@debian.org>
113 * -- Newer Creative drives don't always set the error
114 * register correctly. Make sure we see media changes
115 * regardless.
116 * -- Integrate with generic cdrom driver.
117 * -- CDROMGETSPINDOWN and CDROMSETSPINDOWN ioctls, based on
118 * a patch from Ciro Cattuto <>.
119 * -- Call set_device_ro.
120 * -- Implement CDROMMECHANISMSTATUS and CDROMSLOTTABLE
121 * ioctls, based on patch by Erik Andersen
122 * -- Add some probes of drive capability during setup.
123 *
124 * 4.01 Nov 11, 1996 -- Split into ide-cd.c and ide-cd.h
125 * -- Removed CDROMMECHANISMSTATUS and CDROMSLOTTABLE
126 * ioctls in favor of a generalized approach
127 * using the generic cdrom driver.
128 * -- Fully integrated with the 2.1.X kernel.
129 * -- Other stuff that I forgot (lots of changes)
130 *
131 * 4.02 Dec 01, 1996 -- Applied patch from Gadi Oxman <gadio@netvision.net.il>
132 * to fix the drive door locking problems.
133 *
134 * 4.03 Dec 04, 1996 -- Added DSC overlap support.
135 * 4.04 Dec 29, 1996 -- Added CDROMREADRAW ioclt based on patch
136 * by Ales Makarov (xmakarov@sun.felk.cvut.cz)
137 *
138 * 4.05 Nov 20, 1997 -- Modified to print more drive info on init
139 * Minor other changes
140 * Fix errors on CDROMSTOP (If you have a "Dolphin",
141 * you must define IHAVEADOLPHIN)
142 * Added identifier so new Sanyo CD-changer works
143 * Better detection if door locking isn't supported
144 *
145 * 4.06 Dec 17, 1997 -- fixed endless "tray open" messages -ml
146 * 4.07 Dec 17, 1997 -- fallback to set pc->stat on "tray open"
147 * 4.08 Dec 18, 1997 -- spew less noise when tray is empty
148 * -- fix speed display for ACER 24X, 18X
149 * 4.09 Jan 04, 1998 -- fix handling of the last block so we return
150 * an end of file instead of an I/O error (Gadi)
151 * 4.10 Jan 24, 1998 -- fixed a bug so now changers can change to a new
152 * slot when there is no disc in the current slot.
153 * -- Fixed a memory leak where info->changer_info was
154 * malloc'ed but never free'd when closing the device.
155 * -- Cleaned up the global namespace a bit by making more
156 * functions static that should already have been.
157 * 4.11 Mar 12, 1998 -- Added support for the CDROM_SELECT_SPEED ioctl
158 * based on a patch for 2.0.33 by Jelle Foks
159 * <jelle@scintilla.utwente.nl>, a patch for 2.0.33
160 * by Toni Giorgino <toni@pcape2.pi.infn.it>, the SCSI
161 * version, and my own efforts. -erik
162 * -- Fixed a stupid bug which egcs was kind enough to
163 * inform me of where "Illegal mode for this track"
164 * was never returned due to a comparison on data
165 * types of limited range.
166 * 4.12 Mar 29, 1998 -- Fixed bug in CDROM_SELECT_SPEED so write speed is
167 * now set ionly for CD-R and CD-RW drives. I had
168 * removed this support because it produced errors.
169 * It produced errors _only_ for non-writers. duh.
170 * 4.13 May 05, 1998 -- Suppress useless "in progress of becoming ready"
171 * messages, since this is not an error.
172 * -- Change error messages to be const
173 * -- Remove a "\t" which looks ugly in the syslogs
174 * 4.14 July 17, 1998 -- Change to pointing to .ps version of ATAPI spec
175 * since the .pdf version doesn't seem to work...
176 * -- Updated the TODO list to something more current.
177 *
178 * 4.15 Aug 25, 1998 -- Updated ide-cd.h to respect mechine endianess,
179 * patch thanks to "Eddie C. Dost" <ecd@skynet.be>
180 *
181 * 4.50 Oct 19, 1998 -- New maintainers!
182 * Jens Axboe <axboe@image.dk>
183 * Chris Zwilling <chris@cloudnet.com>
184 *
185 * 4.51 Dec 23, 1998 -- Jens Axboe <axboe@image.dk>
186 * - ide_cdrom_reset enabled since the ide subsystem
187 * handles resets fine now. <axboe@image.dk>
188 * - Transfer size fix for Samsung CD-ROMs, thanks to
189 * "Ville Hallik" <ville.hallik@mail.ee>.
190 * - other minor stuff.
191 *
192 * 4.52 Jan 19, 1999 -- Jens Axboe <axboe@image.dk>
193 * - Detect DVD-ROM/RAM drives
194 *
195 * 4.53 Feb 22, 1999 - Include other model Samsung and one Goldstar
196 * drive in transfer size limit.
197 * - Fix the I/O error when doing eject without a medium
198 * loaded on some drives.
199 * - CDROMREADMODE2 is now implemented through
200 * CDROMREADRAW, since many drives don't support
201 * MODE2 (even though ATAPI 2.6 says they must).
202 * - Added ignore parameter to ide-cd (as a module), eg
203 * insmod ide-cd ignore='hda hdb'
204 * Useful when using ide-cd in conjunction with
205 * ide-scsi. TODO: non-modular way of doing the
206 * same.
207 *
208 * 4.54 Aug 5, 1999 - Support for MMC2 class commands through the generic
209 * packet interface to cdrom.c.
210 * - Unified audio ioctl support, most of it.
211 * - cleaned up various deprecated verify_area().
212 * - Added ide_cdrom_packet() as the interface for
213 * the Uniform generic_packet().
214 * - bunch of other stuff, will fill in logs later.
215 * - report 1 slot for non-changers, like the other
216 * cd-rom drivers. don't report select disc for
217 * non-changers as well.
218 * - mask out audio playing, if the device can't do it.
219 *
220 * 4.55 Sep 1, 1999 - Eliminated the rest of the audio ioctls, except
221 * for CDROMREADTOC[ENTRY|HEADER]. Some of the drivers
222 * use this independently of the actual audio handling.
223 * They will disappear later when I get the time to
224 * do it cleanly.
225 * - Minimize the TOC reading - only do it when we
226 * know a media change has occurred.
227 * - Moved all the CDROMREADx ioctls to the Uniform layer.
228 * - Heiko Eißfeldt <heiko@colossus.escape.de> supplied
229 * some fixes for CDI.
230 * - CD-ROM leaving door locked fix from Andries
231 * Brouwer <Andries.Brouwer@cwi.nl>
232 * - Erik Andersen <andersen@xmission.com> unified
233 * commands across the various drivers and how
234 * sense errors are handled.
235 *
236 * 4.56 Sep 12, 1999 - Removed changer support - it is now in the
237 * Uniform layer.
238 * - Added partition based multisession handling.
239 * - Mode sense and mode select moved to the
240 * Uniform layer.
241 * - Fixed a problem with WPI CDS-32X drive - it
242 * failed the capabilities
243 *
244 * 4.57 Apr 7, 2000 - Fixed sense reporting.
245 * - Fixed possible oops in ide_cdrom_get_last_session()
246 * - Fix locking mania and make ide_cdrom_reset relock
247 * - Stop spewing errors to log when magicdev polls with
248 * TEST_UNIT_READY on some drives.
249 * - Various fixes from Tobias Ringstrom:
250 * tray if it was locked prior to the reset.
251 * - cdrom_read_capacity returns one frame too little.
252 * - Fix real capacity reporting.
253 *
254 * 4.58 May 1, 2000 - Clean up ACER50 stuff.
255 * - Fix small problem with ide_cdrom_capacity
256 *
257 * 4.59 Aug 11, 2000 - Fix changer problem in cdrom_read_toc, we weren't
258 * correctly sensing a disc change.
259 * - Rearranged some code
260 * - Use extended sense on drives that support it for
261 * correctly reporting tray status -- from
262 * Michael D Johnson <johnsom@orst.edu>
263 * 4.60 Dec 17, 2003 - Add mt rainier support
264 * - Bump timeout for packet commands, matches sr
265 * - Odd stuff
266 * 4.61 Jan 22, 2004 - support hardware sector sizes other than 2kB,
267 * Pascal Schmidt <der.eremit@email.de>
268 */
diff --git a/Documentation/ide/ChangeLog.ide-floppy.1996-2002 b/Documentation/ide/ChangeLog.ide-floppy.1996-2002
new file mode 100644
index 00000000000..46c19ef32a9
--- /dev/null
+++ b/Documentation/ide/ChangeLog.ide-floppy.1996-2002
@@ -0,0 +1,63 @@
1/*
2 * Many thanks to Lode Leroy <Lode.Leroy@www.ibase.be>, who tested so many
3 * ALPHA patches to this driver on an EASYSTOR LS-120 ATAPI floppy drive.
4 *
5 * Ver 0.1 Oct 17 96 Initial test version, mostly based on ide-tape.c.
6 * Ver 0.2 Oct 31 96 Minor changes.
7 * Ver 0.3 Dec 2 96 Fixed error recovery bug.
8 * Ver 0.4 Jan 26 97 Add support for the HDIO_GETGEO ioctl.
9 * Ver 0.5 Feb 21 97 Add partitions support.
10 * Use the minimum of the LBA and CHS capacities.
11 * Avoid hwgroup->rq == NULL on the last irq.
12 * Fix potential null dereferencing with DEBUG_LOG.
13 * Ver 0.8 Dec 7 97 Increase irq timeout from 10 to 50 seconds.
14 * Add media write-protect detection.
15 * Issue START command only if TEST UNIT READY fails.
16 * Add work-around for IOMEGA ZIP revision 21.D.
17 * Remove idefloppy_get_capabilities().
18 * Ver 0.9 Jul 4 99 Fix a bug which might have caused the number of
19 * bytes requested on each interrupt to be zero.
20 * Thanks to <shanos@es.co.nz> for pointing this out.
21 * Ver 0.9.sv Jan 6 01 Sam Varshavchik <mrsam@courier-mta.com>
22 * Implement low level formatting. Reimplemented
23 * IDEFLOPPY_CAPABILITIES_PAGE, since we need the srfp
24 * bit. My LS-120 drive barfs on
25 * IDEFLOPPY_CAPABILITIES_PAGE, but maybe it's just me.
26 * Compromise by not reporting a failure to get this
27 * mode page. Implemented four IOCTLs in order to
28 * implement formatting. IOCTls begin with 0x4600,
29 * 0x46 is 'F' as in Format.
30 * Jan 9 01 Userland option to select format verify.
31 * Added PC_SUPPRESS_ERROR flag - some idefloppy drives
32 * do not implement IDEFLOPPY_CAPABILITIES_PAGE, and
33 * return a sense error. Suppress error reporting in
34 * this particular case in order to avoid spurious
35 * errors in syslog. The culprit is
36 * idefloppy_get_capability_page(), so move it to
37 * idefloppy_begin_format() so that it's not used
38 * unless absolutely necessary.
39 * If drive does not support format progress indication
40 * monitor the dsc bit in the status register.
41 * Also, O_NDELAY on open will allow the device to be
42 * opened without a disk available. This can be used to
43 * open an unformatted disk, or get the device capacity.
44 * Ver 0.91 Dec 11 99 Added IOMEGA Clik! drive support by
45 * <paul@paulbristow.net>
46 * Ver 0.92 Oct 22 00 Paul Bristow became official maintainer for this
47 * driver. Included Powerbook internal zip kludge.
48 * Ver 0.93 Oct 24 00 Fixed bugs for Clik! drive
49 * no disk on insert and disk change now works
50 * Ver 0.94 Oct 27 00 Tidied up to remove strstr(Clik) everywhere
51 * Ver 0.95 Nov 7 00 Brought across to kernel 2.4
52 * Ver 0.96 Jan 7 01 Actually in line with release version of 2.4.0
53 * including set_bit patch from Rusty Russell
54 * Ver 0.97 Jul 22 01 Merge 0.91-0.96 onto 0.9.sv for ac series
55 * Ver 0.97.sv Aug 3 01 Backported from 2.4.7-ac3
56 * Ver 0.98 Oct 26 01 Split idefloppy_transfer_pc into two pieces to
57 * fix a lost interrupt problem. It appears the busy
58 * bit was being deasserted by my IOMEGA ATAPI ZIP 100
59 * drive before the drive was actually ready.
60 * Ver 0.98a Oct 29 01 Expose delay value so we can play.
61 * Ver 0.99 Feb 24 02 Remove duplicate code, modify clik! detection code
62 * to support new PocketZip drives
63 */
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index af056105316..47e5b40510c 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -2787,12 +2787,6 @@ int cdrom_ioctl(struct file * file, struct cdrom_device_info *cdi,
2787 return -ENOSYS; 2787 return -ENOSYS;
2788} 2788}
2789 2789
2790static inline
2791int msf_to_lba(char m, char s, char f)
2792{
2793 return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
2794}
2795
2796/* 2790/*
2797 * Required when we need to use READ_10 to issue other than 2048 block 2791 * Required when we need to use READ_10 to issue other than 2048 block
2798 * reads 2792 * reads
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 64df55e20ab..e42a465f571 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -206,6 +206,15 @@ config BLK_DEV_IDECD
206 To compile this driver as a module, choose M here: the 206 To compile this driver as a module, choose M here: the
207 module will be called ide-cd. 207 module will be called ide-cd.
208 208
209config BLK_DEV_IDECD_VERBOSE_ERRORS
210 bool "Verbose error logging for IDE/ATAPI CDROM driver" if EMBEDDED
211 depends on BLK_DEV_IDECD
212 default y
213 help
214 Turn this on to have the driver print out the meanings of the
215 ATAPI error codes. This will use up additional 8kB of kernel-space
216 memory, though.
217
209config BLK_DEV_IDETAPE 218config BLK_DEV_IDETAPE
210 tristate "Include IDE/ATAPI TAPE support (EXPERIMENTAL)" 219 tristate "Include IDE/ATAPI TAPE support (EXPERIMENTAL)"
211 depends on EXPERIMENTAL 220 depends on EXPERIMENTAL
@@ -617,8 +626,8 @@ config BLK_DEV_SC1200
617 tristate "National SCx200 chipset support" 626 tristate "National SCx200 chipset support"
618 select BLK_DEV_IDEDMA_PCI 627 select BLK_DEV_IDEDMA_PCI
619 help 628 help
620 This driver adds support for the built in IDE on the National 629 This driver adds support for the on-board IDE controller on the
621 SCx200 series of embedded x86 "Geode" systems 630 National SCx200 series of embedded x86 "Geode" systems.
622 631
623config BLK_DEV_PIIX 632config BLK_DEV_PIIX
624 tristate "Intel PIIXn chipsets support" 633 tristate "Intel PIIXn chipsets support"
@@ -793,22 +802,22 @@ config BLK_DEV_CELLEB
793 depends on PPC_CELLEB 802 depends on PPC_CELLEB
794 select BLK_DEV_IDEDMA_PCI 803 select BLK_DEV_IDEDMA_PCI
795 help 804 help
796 This driver provides support for the built-in IDE controller on 805 This driver provides support for the on-board IDE controller on
797 Toshiba Cell Reference Board. 806 Toshiba Cell Reference Board.
798 If unsure, say Y. 807 If unsure, say Y.
799 808
800endif 809endif
801 810
802config BLK_DEV_IDE_PMAC 811config BLK_DEV_IDE_PMAC
803 tristate "Builtin PowerMac IDE support" 812 tristate "PowerMac on-board IDE support"
804 depends on PPC_PMAC && IDE=y && BLK_DEV_IDE=y 813 depends on PPC_PMAC && IDE=y && BLK_DEV_IDE=y
805 help 814 help
806 This driver provides support for the built-in IDE controller on 815 This driver provides support for the on-board IDE controller on
807 most of the recent Apple Power Macintoshes and PowerBooks. 816 most of the recent Apple Power Macintoshes and PowerBooks.
808 If unsure, say Y. 817 If unsure, say Y.
809 818
810config BLK_DEV_IDE_PMAC_ATA100FIRST 819config BLK_DEV_IDE_PMAC_ATA100FIRST
811 bool "Probe internal ATA/100 (Kauai) first" 820 bool "Probe on-board ATA/100 (Kauai) first"
812 depends on BLK_DEV_IDE_PMAC 821 depends on BLK_DEV_IDE_PMAC
813 help 822 help
814 This option will cause the ATA/100 controller found in UniNorth2 823 This option will cause the ATA/100 controller found in UniNorth2
@@ -823,7 +832,7 @@ config BLK_DEV_IDEDMA_PMAC
823 depends on BLK_DEV_IDE_PMAC 832 depends on BLK_DEV_IDE_PMAC
824 select BLK_DEV_IDEDMA_PCI 833 select BLK_DEV_IDEDMA_PCI
825 help 834 help
826 This option allows the driver for the built-in IDE controller on 835 This option allows the driver for the on-board IDE controller on
827 Power Macintoshes and PowerBooks to use DMA (direct memory access) 836 Power Macintoshes and PowerBooks to use DMA (direct memory access)
828 to transfer data to and from memory. Saying Y is safe and improves 837 to transfer data to and from memory. Saying Y is safe and improves
829 performance. 838 performance.
@@ -934,7 +943,7 @@ config BLK_DEV_GAYLE
934 help 943 help
935 This is the IDE driver for the Amiga Gayle IDE interface. It supports 944 This is the IDE driver for the Amiga Gayle IDE interface. It supports
936 both the `A1200 style' and `A4000 style' of the Gayle IDE interface, 945 both the `A1200 style' and `A4000 style' of the Gayle IDE interface,
937 This includes builtin IDE interfaces on some Amiga models (A600, 946 This includes on-board IDE interfaces on some Amiga models (A600,
938 A1200, A4000, and A4000T), and IDE interfaces on the Zorro expansion 947 A1200, A4000, and A4000T), and IDE interfaces on the Zorro expansion
939 bus (M-Tech E-Matrix 530 expansion card). 948 bus (M-Tech E-Matrix 530 expansion card).
940 Say Y if you have an Amiga with a Gayle IDE interface and want to use 949 Say Y if you have an Amiga with a Gayle IDE interface and want to use
@@ -948,10 +957,10 @@ config BLK_DEV_IDEDOUBLER
948 depends on BLK_DEV_GAYLE && EXPERIMENTAL 957 depends on BLK_DEV_GAYLE && EXPERIMENTAL
949 ---help--- 958 ---help---
950 This driver provides support for the so-called `IDE doublers' (made 959 This driver provides support for the so-called `IDE doublers' (made
951 by various manufacturers, e.g. Eyetech) that can be connected to the 960 by various manufacturers, e.g. Eyetech) that can be connected to
952 builtin IDE interface of some Amiga models. Using such an IDE 961 the on-board IDE interface of some Amiga models. Using such an IDE
953 doubler, you can connect up to four instead of two IDE devices on 962 doubler, you can connect up to four instead of two IDE devices to
954 the Amiga's builtin IDE interface. 963 the Amiga's on-board IDE interface.
955 964
956 Note that the normal Amiga Gayle IDE driver may not work correctly 965 Note that the normal Amiga Gayle IDE driver may not work correctly
957 if you have an IDE doubler and don't enable this driver! 966 if you have an IDE doubler and don't enable this driver!
@@ -963,9 +972,9 @@ config BLK_DEV_BUDDHA
963 tristate "Buddha/Catweasel/X-Surf IDE interface support (EXPERIMENTAL)" 972 tristate "Buddha/Catweasel/X-Surf IDE interface support (EXPERIMENTAL)"
964 depends on ZORRO && EXPERIMENTAL 973 depends on ZORRO && EXPERIMENTAL
965 help 974 help
966 This is the IDE driver for the IDE interfaces on the Buddha, 975 This is the IDE driver for the IDE interfaces on the Buddha, Catweasel
967 Catweasel and X-Surf expansion boards. It supports up to two interfaces 976 and X-Surf expansion boards. It supports up to two interfaces on the
968 on the Buddha, three on the Catweasel and two on the X-Surf. 977 Buddha, three on the Catweasel and two on the X-Surf.
969 978
970 Say Y if you have a Buddha or Catweasel expansion board and want to 979 Say Y if you have a Buddha or Catweasel expansion board and want to
971 use IDE devices (hard disks, CD-ROM drives, etc.) that are connected 980 use IDE devices (hard disks, CD-ROM drives, etc.) that are connected
@@ -975,23 +984,23 @@ config BLK_DEV_FALCON_IDE
975 tristate "Falcon IDE interface support" 984 tristate "Falcon IDE interface support"
976 depends on ATARI 985 depends on ATARI
977 help 986 help
978 This is the IDE driver for the builtin IDE interface on the Atari 987 This is the IDE driver for the on-board IDE interface on the Atari
979 Falcon. Say Y if you have a Falcon and want to use IDE devices (hard 988 Falcon. Say Y if you have a Falcon and want to use IDE devices (hard
980 disks, CD-ROM drives, etc.) that are connected to the builtin IDE 989 disks, CD-ROM drives, etc.) that are connected to the on-board IDE
981 interface. 990 interface.
982 991
983config BLK_DEV_MAC_IDE 992config BLK_DEV_MAC_IDE
984 tristate "Macintosh Quadra/Powerbook IDE interface support" 993 tristate "Macintosh Quadra/Powerbook IDE interface support"
985 depends on MAC 994 depends on MAC
986 help 995 help
987 This is the IDE driver for the builtin IDE interface on some m68k 996 This is the IDE driver for the on-board IDE interface on some m68k
988 Macintosh models. It supports both the `Quadra style' (used in 997 Macintosh models. It supports both the `Quadra style' (used in
989 Quadra/ Centris 630 and Performa 588 models) and `Powerbook style' 998 Quadra/ Centris 630 and Performa 588 models) and `Powerbook style'
990 (used in the Powerbook 150 and 190 models) IDE interface. 999 (used in the Powerbook 150 and 190 models) IDE interface.
991 1000
992 Say Y if you have such an Macintosh model and want to use IDE 1001 Say Y if you have such an Macintosh model and want to use IDE
993 devices (hard disks, CD-ROM drives, etc.) that are connected to the 1002 devices (hard disks, CD-ROM drives, etc.) that are connected to the
994 builtin IDE interface. 1003 on-board IDE interface.
995 1004
996config BLK_DEV_Q40IDE 1005config BLK_DEV_Q40IDE
997 tristate "Q40/Q60 IDE interface support" 1006 tristate "Q40/Q60 IDE interface support"
@@ -1062,8 +1071,8 @@ config BLK_DEV_ALI14XX
1062 boot parameter. It enables support for the secondary IDE interface 1071 boot parameter. It enables support for the secondary IDE interface
1063 of the ALI M1439/1443/1445/1487/1489 chipsets, and permits faster 1072 of the ALI M1439/1443/1445/1487/1489 chipsets, and permits faster
1064 I/O speeds to be set as well. See the files 1073 I/O speeds to be set as well. See the files
1065 <file:Documentation/ide.txt> and <file:drivers/ide/legacy/ali14xx.c> for 1074 <file:Documentation/ide.txt> and <file:drivers/ide/legacy/ali14xx.c>
1066 more info. 1075 for more info.
1067 1076
1068config BLK_DEV_DTC2278 1077config BLK_DEV_DTC2278
1069 tristate "DTC-2278 support" 1078 tristate "DTC-2278 support"
@@ -1088,8 +1097,8 @@ config BLK_DEV_QD65XX
1088 help 1097 help
1089 This driver is enabled at runtime using the "qd65xx.probe" kernel 1098 This driver is enabled at runtime using the "qd65xx.probe" kernel
1090 boot parameter. It permits faster I/O speeds to be set. See the 1099 boot parameter. It permits faster I/O speeds to be set. See the
1091 <file:Documentation/ide.txt> and <file:drivers/ide/legacy/qd65xx.c> for 1100 <file:Documentation/ide.txt> and <file:drivers/ide/legacy/qd65xx.c>
1092 more info. 1101 for more info.
1093 1102
1094config BLK_DEV_UMC8672 1103config BLK_DEV_UMC8672
1095 tristate "UMC-8672 support" 1104 tristate "UMC-8672 support"
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index 0d2da89d15c..a4a4323be91 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -40,8 +40,10 @@ obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o
40obj-$(CONFIG_IDE_H8300) += h8300/ 40obj-$(CONFIG_IDE_H8300) += h8300/
41obj-$(CONFIG_IDE_GENERIC) += ide-generic.o 41obj-$(CONFIG_IDE_GENERIC) += ide-generic.o
42 42
43ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o
44
43obj-$(CONFIG_BLK_DEV_IDEDISK) += ide-disk.o 45obj-$(CONFIG_BLK_DEV_IDEDISK) += ide-disk.o
44obj-$(CONFIG_BLK_DEV_IDECD) += ide-cd.o 46obj-$(CONFIG_BLK_DEV_IDECD) += ide-cd_mod.o
45obj-$(CONFIG_BLK_DEV_IDETAPE) += ide-tape.o 47obj-$(CONFIG_BLK_DEV_IDETAPE) += ide-tape.o
46obj-$(CONFIG_BLK_DEV_IDEFLOPPY) += ide-floppy.o 48obj-$(CONFIG_BLK_DEV_IDEFLOPPY) += ide-floppy.o
47 49
diff --git a/drivers/ide/arm/bast-ide.c b/drivers/ide/arm/bast-ide.c
index 45bf9c825f2..037300fa284 100644
--- a/drivers/ide/arm/bast-ide.c
+++ b/drivers/ide/arm/bast-ide.c
@@ -1,5 +1,4 @@
1/* linux/drivers/ide/arm/bast-ide.c 1/*
2 *
3 * Copyright (c) 2003-2004 Simtec Electronics 2 * Copyright (c) 2003-2004 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk> 3 * Ben Dooks <ben@simtec.co.uk>
5 * 4 *
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c
index 8a5c7205b77..8d2cc47a362 100644
--- a/drivers/ide/arm/icside.c
+++ b/drivers/ide/arm/icside.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/arm/icside.c
3 *
4 * Copyright (c) 1996-2004 Russell King. 2 * Copyright (c) 1996-2004 Russell King.
5 * 3 *
6 * Please note that this platform does not support 32-bit IDE IO. 4 * Please note that this platform does not support 32-bit IDE IO.
@@ -71,8 +69,6 @@ struct icside_state {
71 void __iomem *irq_port; 69 void __iomem *irq_port;
72 void __iomem *ioc_base; 70 void __iomem *ioc_base;
73 unsigned int type; 71 unsigned int type;
74 /* parent device... until the IDE core gets one of its own */
75 struct device *dev;
76 ide_hwif_t *hwif[2]; 72 ide_hwif_t *hwif[2];
77}; 73};
78 74
@@ -206,23 +202,6 @@ static void icside_maskproc(ide_drive_t *drive, int mask)
206 * interfaces use the same IRQ, which should guarantee this. 202 * interfaces use the same IRQ, which should guarantee this.
207 */ 203 */
208 204
209static void icside_build_sglist(ide_drive_t *drive, struct request *rq)
210{
211 ide_hwif_t *hwif = drive->hwif;
212 struct icside_state *state = hwif->hwif_data;
213 struct scatterlist *sg = hwif->sg_table;
214
215 ide_map_sg(drive, rq);
216
217 if (rq_data_dir(rq) == READ)
218 hwif->sg_dma_direction = DMA_FROM_DEVICE;
219 else
220 hwif->sg_dma_direction = DMA_TO_DEVICE;
221
222 hwif->sg_nents = dma_map_sg(state->dev, sg, hwif->sg_nents,
223 hwif->sg_dma_direction);
224}
225
226/* 205/*
227 * Configure the IOMD to give the appropriate timings for the transfer 206 * Configure the IOMD to give the appropriate timings for the transfer
228 * mode being requested. We take the advice of the ATA standards, and 207 * mode being requested. We take the advice of the ATA standards, and
@@ -294,33 +273,32 @@ static void icside_dma_host_set(ide_drive_t *drive, int on)
294static int icside_dma_end(ide_drive_t *drive) 273static int icside_dma_end(ide_drive_t *drive)
295{ 274{
296 ide_hwif_t *hwif = HWIF(drive); 275 ide_hwif_t *hwif = HWIF(drive);
297 struct icside_state *state = hwif->hwif_data; 276 struct expansion_card *ec = ECARD_DEV(hwif->dev);
298 277
299 drive->waiting_for_dma = 0; 278 drive->waiting_for_dma = 0;
300 279
301 disable_dma(ECARD_DEV(state->dev)->dma); 280 disable_dma(ec->dma);
302 281
303 /* Teardown mappings after DMA has completed. */ 282 /* Teardown mappings after DMA has completed. */
304 dma_unmap_sg(state->dev, hwif->sg_table, hwif->sg_nents, 283 ide_destroy_dmatable(drive);
305 hwif->sg_dma_direction);
306 284
307 return get_dma_residue(ECARD_DEV(state->dev)->dma) != 0; 285 return get_dma_residue(ec->dma) != 0;
308} 286}
309 287
310static void icside_dma_start(ide_drive_t *drive) 288static void icside_dma_start(ide_drive_t *drive)
311{ 289{
312 ide_hwif_t *hwif = HWIF(drive); 290 ide_hwif_t *hwif = HWIF(drive);
313 struct icside_state *state = hwif->hwif_data; 291 struct expansion_card *ec = ECARD_DEV(hwif->dev);
314 292
315 /* We can not enable DMA on both channels simultaneously. */ 293 /* We can not enable DMA on both channels simultaneously. */
316 BUG_ON(dma_channel_active(ECARD_DEV(state->dev)->dma)); 294 BUG_ON(dma_channel_active(ec->dma));
317 enable_dma(ECARD_DEV(state->dev)->dma); 295 enable_dma(ec->dma);
318} 296}
319 297
320static int icside_dma_setup(ide_drive_t *drive) 298static int icside_dma_setup(ide_drive_t *drive)
321{ 299{
322 ide_hwif_t *hwif = HWIF(drive); 300 ide_hwif_t *hwif = HWIF(drive);
323 struct icside_state *state = hwif->hwif_data; 301 struct expansion_card *ec = ECARD_DEV(hwif->dev);
324 struct request *rq = hwif->hwgroup->rq; 302 struct request *rq = hwif->hwgroup->rq;
325 unsigned int dma_mode; 303 unsigned int dma_mode;
326 304
@@ -332,9 +310,9 @@ static int icside_dma_setup(ide_drive_t *drive)
332 /* 310 /*
333 * We can not enable DMA on both channels. 311 * We can not enable DMA on both channels.
334 */ 312 */
335 BUG_ON(dma_channel_active(ECARD_DEV(state->dev)->dma)); 313 BUG_ON(dma_channel_active(ec->dma));
336 314
337 icside_build_sglist(drive, rq); 315 hwif->sg_nents = ide_build_sglist(drive, rq);
338 316
339 /* 317 /*
340 * Ensure that we have the right interrupt routed. 318 * Ensure that we have the right interrupt routed.
@@ -349,14 +327,14 @@ static int icside_dma_setup(ide_drive_t *drive)
349 /* 327 /*
350 * Select the correct timing for this drive. 328 * Select the correct timing for this drive.
351 */ 329 */
352 set_dma_speed(ECARD_DEV(state->dev)->dma, drive->drive_data); 330 set_dma_speed(ec->dma, drive->drive_data);
353 331
354 /* 332 /*
355 * Tell the DMA engine about the SG table and 333 * Tell the DMA engine about the SG table and
356 * data direction. 334 * data direction.
357 */ 335 */
358 set_dma_sg(ECARD_DEV(state->dev)->dma, hwif->sg_table, hwif->sg_nents); 336 set_dma_sg(ec->dma, hwif->sg_table, hwif->sg_nents);
359 set_dma_mode(ECARD_DEV(state->dev)->dma, dma_mode); 337 set_dma_mode(ec->dma, dma_mode);
360 338
361 drive->waiting_for_dma = 1; 339 drive->waiting_for_dma = 1;
362 340
@@ -444,6 +422,7 @@ icside_setup(void __iomem *base, struct cardinfo *info, struct expansion_card *e
444 hwif->noprobe = 0; 422 hwif->noprobe = 0;
445 hwif->chipset = ide_acorn; 423 hwif->chipset = ide_acorn;
446 hwif->gendev.parent = &ec->dev; 424 hwif->gendev.parent = &ec->dev;
425 hwif->dev = &ec->dev;
447 } 426 }
448 427
449 return hwif; 428 return hwif;
@@ -591,7 +570,6 @@ icside_probe(struct expansion_card *ec, const struct ecard_id *id)
591 } 570 }
592 571
593 state->type = ICS_TYPE_NOTYPE; 572 state->type = ICS_TYPE_NOTYPE;
594 state->dev = &ec->dev;
595 573
596 idmem = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); 574 idmem = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
597 if (idmem) { 575 if (idmem) {
diff --git a/drivers/ide/arm/rapide.c b/drivers/ide/arm/rapide.c
index e6b56d1d48f..c8b6581e624 100644
--- a/drivers/ide/arm/rapide.c
+++ b/drivers/ide/arm/rapide.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/arm/rapide.c
3 *
4 * Copyright (c) 1996-2002 Russell King. 2 * Copyright (c) 1996-2002 Russell King.
5 */ 3 */
6 4
@@ -78,8 +76,8 @@ static void __devexit rapide_remove(struct expansion_card *ec)
78 76
79 ecard_set_drvdata(ec, NULL); 77 ecard_set_drvdata(ec, NULL);
80 78
81 /* there must be a better way */ 79 ide_unregister(hwif->index);
82 ide_unregister(hwif - ide_hwifs); 80
83 ecard_release_resources(ec); 81 ecard_release_resources(ec);
84} 82}
85 83
diff --git a/drivers/ide/cris/ide-cris.c b/drivers/ide/cris/ide-cris.c
index 8c3294c4d23..0640a38ff12 100644
--- a/drivers/ide/cris/ide-cris.c
+++ b/drivers/ide/cris/ide-cris.c
@@ -1,5 +1,4 @@
1/* $Id: cris-ide-driver.patch,v 1.1 2005/06/29 21:39:07 akpm Exp $ 1/*
2 *
3 * Etrax specific IDE functions, like init and PIO-mode setting etc. 2 * Etrax specific IDE functions, like init and PIO-mode setting etc.
4 * Almost the entire ide.c is used for the rest of the Etrax ATA driver. 3 * Almost the entire ide.c is used for the rest of the Etrax ATA driver.
5 * Copyright (c) 2000-2005 Axis Communications AB 4 * Copyright (c) 2000-2005 Axis Communications AB
diff --git a/drivers/ide/h8300/ide-h8300.c b/drivers/ide/h8300/ide-h8300.c
index 4f6d0191cf6..02432958dfe 100644
--- a/drivers/ide/h8300/ide-h8300.c
+++ b/drivers/ide/h8300/ide-h8300.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * drivers/ide/h8300/ide-h8300.c
3 * H8/300 generic IDE interface 2 * H8/300 generic IDE interface
4 */ 3 */
5 4
diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index e888fc35b27..68bc6184478 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * ide-acpi.c
3 * Provides ACPI support for IDE drives. 2 * Provides ACPI support for IDE drives.
4 * 3 *
5 * Copyright (C) 2005 Intel Corp. 4 * Copyright (C) 2005 Intel Corp.
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index bee05a3f52a..23074e84472 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -1,14 +1,14 @@
1/* 1/*
2 * linux/drivers/ide/ide-cd.c 2 * ATAPI CD-ROM driver.
3 * 3 *
4 * Copyright (C) 1994, 1995, 1996 scott snyder <snyder@fnald0.fnal.gov> 4 * Copyright (C) 1994-1996 Scott Snyder <snyder@fnald0.fnal.gov>
5 * Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org> 5 * Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org>
6 * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de> 6 * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de>
7 * Copyright (C) 2005, 2007 Bartlomiej Zolnierkiewicz
7 * 8 *
8 * May be copied or modified under the terms of the GNU General Public 9 * May be copied or modified under the terms of the GNU General Public
9 * License. See linux/COPYING for more information. 10 * License. See linux/COPYING for more information.
10 * 11 *
11 * ATAPI CD-ROM driver. To be used with ide.c.
12 * See Documentation/cdrom/ide-cd for usage information. 12 * See Documentation/cdrom/ide-cd for usage information.
13 * 13 *
14 * Suggestions are welcome. Patches that work are more welcome though. ;-) 14 * Suggestions are welcome. Patches that work are more welcome though. ;-)
@@ -19,287 +19,11 @@
19 * ftp://fission.dt.wdc.com/pub/standards/SFF_atapi/spec/SFF8020-r2.6/PS/8020r26.ps 19 * ftp://fission.dt.wdc.com/pub/standards/SFF_atapi/spec/SFF8020-r2.6/PS/8020r26.ps
20 * ftp://ftp.avc-pioneer.com/Mtfuji4/Spec/Fuji4r10.pdf 20 * ftp://ftp.avc-pioneer.com/Mtfuji4/Spec/Fuji4r10.pdf
21 * 21 *
22 * Drives that deviate from these standards will be accommodated as much 22 * For historical changelog please see:
23 * as possible via compile time or command-line options. Since I only have 23 * Documentation/ide/ChangeLog.ide-cd.1994-2004
24 * a few drives, you generally need to send me patches... 24 */
25 * 25
26 * ---------------------------------- 26#define IDECD_VERSION "5.00"
27 * TO DO LIST:
28 * -Make it so that Pioneer CD DR-A24X and friends don't get screwed up on
29 * boot
30 *
31 * ----------------------------------
32 * 1.00 Oct 31, 1994 -- Initial version.
33 * 1.01 Nov 2, 1994 -- Fixed problem with starting request in
34 * cdrom_check_status.
35 * 1.03 Nov 25, 1994 -- leaving unmask_intr[] as a user-setting (as for disks)
36 * (from mlord) -- minor changes to cdrom_setup()
37 * -- renamed ide_dev_s to ide_drive_t, enable irq on command
38 * 2.00 Nov 27, 1994 -- Generalize packet command interface;
39 * add audio ioctls.
40 * 2.01 Dec 3, 1994 -- Rework packet command interface to handle devices
41 * which send an interrupt when ready for a command.
42 * 2.02 Dec 11, 1994 -- Cache the TOC in the driver.
43 * Don't use SCMD_PLAYAUDIO_TI; it's not included
44 * in the current version of ATAPI.
45 * Try to use LBA instead of track or MSF addressing
46 * when possible.
47 * Don't wait for READY_STAT.
48 * 2.03 Jan 10, 1995 -- Rewrite block read routines to handle block sizes
49 * other than 2k and to move multiple sectors in a
50 * single transaction.
51 * 2.04 Apr 21, 1995 -- Add work-around for Creative Labs CD220E drives.
52 * Thanks to Nick Saw <cwsaw@pts7.pts.mot.com> for
53 * help in figuring this out. Ditto for Acer and
54 * Aztech drives, which seem to have the same problem.
55 * 2.04b May 30, 1995 -- Fix to match changes in ide.c version 3.16 -ml
56 * 2.05 Jun 8, 1995 -- Don't attempt to retry after an illegal request
57 * or data protect error.
58 * Use HWIF and DEV_HWIF macros as in ide.c.
59 * Always try to do a request_sense after
60 * a failed command.
61 * Include an option to give textual descriptions
62 * of ATAPI errors.
63 * Fix a bug in handling the sector cache which
64 * showed up if the drive returned data in 512 byte
65 * blocks (like Pioneer drives). Thanks to
66 * Richard Hirst <srh@gpt.co.uk> for diagnosing this.
67 * Properly supply the page number field in the
68 * MODE_SELECT command.
69 * PLAYAUDIO12 is broken on the Aztech; work around it.
70 * 2.05x Aug 11, 1995 -- lots of data structure renaming/restructuring in ide.c
71 * (my apologies to Scott, but now ide-cd.c is independent)
72 * 3.00 Aug 22, 1995 -- Implement CDROMMULTISESSION ioctl.
73 * Implement CDROMREADAUDIO ioctl (UNTESTED).
74 * Use input_ide_data() and output_ide_data().
75 * Add door locking.
76 * Fix usage count leak in cdrom_open, which happened
77 * when a read-write mount was attempted.
78 * Try to load the disk on open.
79 * Implement CDROMEJECT_SW ioctl (off by default).
80 * Read total cdrom capacity during open.
81 * Rearrange logic in cdrom_decode_status. Issue
82 * request sense commands for failed packet commands
83 * from here instead of from cdrom_queue_packet_command.
84 * Fix a race condition in retrieving error information.
85 * Suppress printing normal unit attention errors and
86 * some drive not ready errors.
87 * Implement CDROMVOLREAD ioctl.
88 * Implement CDROMREADMODE1/2 ioctls.
89 * Fix race condition in setting up interrupt handlers
90 * when the `serialize' option is used.
91 * 3.01 Sep 2, 1995 -- Fix ordering of reenabling interrupts in
92 * cdrom_queue_request.
93 * Another try at using ide_[input,output]_data.
94 * 3.02 Sep 16, 1995 -- Stick total disk capacity in partition table as well.
95 * Make VERBOSE_IDE_CD_ERRORS dump failed command again.
96 * Dump out more information for ILLEGAL REQUEST errs.
97 * Fix handling of errors occurring before the
98 * packet command is transferred.
99 * Fix transfers with odd bytelengths.
100 * 3.03 Oct 27, 1995 -- Some Creative drives have an id of just `CD'.
101 * `DCI-2S10' drives are broken too.
102 * 3.04 Nov 20, 1995 -- So are Vertos drives.
103 * 3.05 Dec 1, 1995 -- Changes to go with overhaul of ide.c and ide-tape.c
104 * 3.06 Dec 16, 1995 -- Add support needed for partitions.
105 * More workarounds for Vertos bugs (based on patches
106 * from Holger Dietze <dietze@aix520.informatik.uni-leipzig.de>).
107 * Try to eliminate byteorder assumptions.
108 * Use atapi_cdrom_subchnl struct definition.
109 * Add STANDARD_ATAPI compilation option.
110 * 3.07 Jan 29, 1996 -- More twiddling for broken drives: Sony 55D,
111 * Vertos 300.
112 * Add NO_DOOR_LOCKING configuration option.
113 * Handle drive_cmd requests w/NULL args (for hdparm -t).
114 * Work around sporadic Sony55e audio play problem.
115 * 3.07a Feb 11, 1996 -- check drive->id for NULL before dereferencing, to fix
116 * problem with "hde=cdrom" with no drive present. -ml
117 * 3.08 Mar 6, 1996 -- More Vertos workarounds.
118 * 3.09 Apr 5, 1996 -- Add CDROMCLOSETRAY ioctl.
119 * Switch to using MSF addressing for audio commands.
120 * Reformat to match kernel tabbing style.
121 * Add CDROM_GET_UPC ioctl.
122 * 3.10 Apr 10, 1996 -- Fix compilation error with STANDARD_ATAPI.
123 * 3.11 Apr 29, 1996 -- Patch from Heiko Eißfeldt <heiko@colossus.escape.de>
124 * to remove redundant verify_area calls.
125 * 3.12 May 7, 1996 -- Rudimentary changer support. Based on patches
126 * from Gerhard Zuber <zuber@berlin.snafu.de>.
127 * Let open succeed even if there's no loaded disc.
128 * 3.13 May 19, 1996 -- Fixes for changer code.
129 * 3.14 May 29, 1996 -- Add work-around for Vertos 600.
130 * (From Hennus Bergman <hennus@sky.ow.nl>.)
131 * 3.15 July 2, 1996 -- Added support for Sanyo 3 CD changers
132 * from Ben Galliart <bgallia@luc.edu> with
133 * special help from Jeff Lightfoot
134 * <jeffml@pobox.com>
135 * 3.15a July 9, 1996 -- Improved Sanyo 3 CD changer identification
136 * 3.16 Jul 28, 1996 -- Fix from Gadi to reduce kernel stack usage for ioctl.
137 * 3.17 Sep 17, 1996 -- Tweak audio reads for some drives.
138 * Start changing CDROMLOADFROMSLOT to CDROM_SELECT_DISC.
139 * 3.18 Oct 31, 1996 -- Added module and DMA support.
140 *
141 *
142 * 4.00 Nov 5, 1996 -- New ide-cd maintainer,
143 * Erik B. Andersen <andersee@debian.org>
144 * -- Newer Creative drives don't always set the error
145 * register correctly. Make sure we see media changes
146 * regardless.
147 * -- Integrate with generic cdrom driver.
148 * -- CDROMGETSPINDOWN and CDROMSETSPINDOWN ioctls, based on
149 * a patch from Ciro Cattuto <>.
150 * -- Call set_device_ro.
151 * -- Implement CDROMMECHANISMSTATUS and CDROMSLOTTABLE
152 * ioctls, based on patch by Erik Andersen
153 * -- Add some probes of drive capability during setup.
154 *
155 * 4.01 Nov 11, 1996 -- Split into ide-cd.c and ide-cd.h
156 * -- Removed CDROMMECHANISMSTATUS and CDROMSLOTTABLE
157 * ioctls in favor of a generalized approach
158 * using the generic cdrom driver.
159 * -- Fully integrated with the 2.1.X kernel.
160 * -- Other stuff that I forgot (lots of changes)
161 *
162 * 4.02 Dec 01, 1996 -- Applied patch from Gadi Oxman <gadio@netvision.net.il>
163 * to fix the drive door locking problems.
164 *
165 * 4.03 Dec 04, 1996 -- Added DSC overlap support.
166 * 4.04 Dec 29, 1996 -- Added CDROMREADRAW ioclt based on patch
167 * by Ales Makarov (xmakarov@sun.felk.cvut.cz)
168 *
169 * 4.05 Nov 20, 1997 -- Modified to print more drive info on init
170 * Minor other changes
171 * Fix errors on CDROMSTOP (If you have a "Dolphin",
172 * you must define IHAVEADOLPHIN)
173 * Added identifier so new Sanyo CD-changer works
174 * Better detection if door locking isn't supported
175 *
176 * 4.06 Dec 17, 1997 -- fixed endless "tray open" messages -ml
177 * 4.07 Dec 17, 1997 -- fallback to set pc->stat on "tray open"
178 * 4.08 Dec 18, 1997 -- spew less noise when tray is empty
179 * -- fix speed display for ACER 24X, 18X
180 * 4.09 Jan 04, 1998 -- fix handling of the last block so we return
181 * an end of file instead of an I/O error (Gadi)
182 * 4.10 Jan 24, 1998 -- fixed a bug so now changers can change to a new
183 * slot when there is no disc in the current slot.
184 * -- Fixed a memory leak where info->changer_info was
185 * malloc'ed but never free'd when closing the device.
186 * -- Cleaned up the global namespace a bit by making more
187 * functions static that should already have been.
188 * 4.11 Mar 12, 1998 -- Added support for the CDROM_SELECT_SPEED ioctl
189 * based on a patch for 2.0.33 by Jelle Foks
190 * <jelle@scintilla.utwente.nl>, a patch for 2.0.33
191 * by Toni Giorgino <toni@pcape2.pi.infn.it>, the SCSI
192 * version, and my own efforts. -erik
193 * -- Fixed a stupid bug which egcs was kind enough to
194 * inform me of where "Illegal mode for this track"
195 * was never returned due to a comparison on data
196 * types of limited range.
197 * 4.12 Mar 29, 1998 -- Fixed bug in CDROM_SELECT_SPEED so write speed is
198 * now set ionly for CD-R and CD-RW drives. I had
199 * removed this support because it produced errors.
200 * It produced errors _only_ for non-writers. duh.
201 * 4.13 May 05, 1998 -- Suppress useless "in progress of becoming ready"
202 * messages, since this is not an error.
203 * -- Change error messages to be const
204 * -- Remove a "\t" which looks ugly in the syslogs
205 * 4.14 July 17, 1998 -- Change to pointing to .ps version of ATAPI spec
206 * since the .pdf version doesn't seem to work...
207 * -- Updated the TODO list to something more current.
208 *
209 * 4.15 Aug 25, 1998 -- Updated ide-cd.h to respect mechine endianess,
210 * patch thanks to "Eddie C. Dost" <ecd@skynet.be>
211 *
212 * 4.50 Oct 19, 1998 -- New maintainers!
213 * Jens Axboe <axboe@image.dk>
214 * Chris Zwilling <chris@cloudnet.com>
215 *
216 * 4.51 Dec 23, 1998 -- Jens Axboe <axboe@image.dk>
217 * - ide_cdrom_reset enabled since the ide subsystem
218 * handles resets fine now. <axboe@image.dk>
219 * - Transfer size fix for Samsung CD-ROMs, thanks to
220 * "Ville Hallik" <ville.hallik@mail.ee>.
221 * - other minor stuff.
222 *
223 * 4.52 Jan 19, 1999 -- Jens Axboe <axboe@image.dk>
224 * - Detect DVD-ROM/RAM drives
225 *
226 * 4.53 Feb 22, 1999 - Include other model Samsung and one Goldstar
227 * drive in transfer size limit.
228 * - Fix the I/O error when doing eject without a medium
229 * loaded on some drives.
230 * - CDROMREADMODE2 is now implemented through
231 * CDROMREADRAW, since many drives don't support
232 * MODE2 (even though ATAPI 2.6 says they must).
233 * - Added ignore parameter to ide-cd (as a module), eg
234 * insmod ide-cd ignore='hda hdb'
235 * Useful when using ide-cd in conjunction with
236 * ide-scsi. TODO: non-modular way of doing the
237 * same.
238 *
239 * 4.54 Aug 5, 1999 - Support for MMC2 class commands through the generic
240 * packet interface to cdrom.c.
241 * - Unified audio ioctl support, most of it.
242 * - cleaned up various deprecated verify_area().
243 * - Added ide_cdrom_packet() as the interface for
244 * the Uniform generic_packet().
245 * - bunch of other stuff, will fill in logs later.
246 * - report 1 slot for non-changers, like the other
247 * cd-rom drivers. don't report select disc for
248 * non-changers as well.
249 * - mask out audio playing, if the device can't do it.
250 *
251 * 4.55 Sep 1, 1999 - Eliminated the rest of the audio ioctls, except
252 * for CDROMREADTOC[ENTRY|HEADER]. Some of the drivers
253 * use this independently of the actual audio handling.
254 * They will disappear later when I get the time to
255 * do it cleanly.
256 * - Minimize the TOC reading - only do it when we
257 * know a media change has occurred.
258 * - Moved all the CDROMREADx ioctls to the Uniform layer.
259 * - Heiko Eißfeldt <heiko@colossus.escape.de> supplied
260 * some fixes for CDI.
261 * - CD-ROM leaving door locked fix from Andries
262 * Brouwer <Andries.Brouwer@cwi.nl>
263 * - Erik Andersen <andersen@xmission.com> unified
264 * commands across the various drivers and how
265 * sense errors are handled.
266 *
267 * 4.56 Sep 12, 1999 - Removed changer support - it is now in the
268 * Uniform layer.
269 * - Added partition based multisession handling.
270 * - Mode sense and mode select moved to the
271 * Uniform layer.
272 * - Fixed a problem with WPI CDS-32X drive - it
273 * failed the capabilities
274 *
275 * 4.57 Apr 7, 2000 - Fixed sense reporting.
276 * - Fixed possible oops in ide_cdrom_get_last_session()
277 * - Fix locking mania and make ide_cdrom_reset relock
278 * - Stop spewing errors to log when magicdev polls with
279 * TEST_UNIT_READY on some drives.
280 * - Various fixes from Tobias Ringstrom:
281 * tray if it was locked prior to the reset.
282 * - cdrom_read_capacity returns one frame too little.
283 * - Fix real capacity reporting.
284 *
285 * 4.58 May 1, 2000 - Clean up ACER50 stuff.
286 * - Fix small problem with ide_cdrom_capacity
287 *
288 * 4.59 Aug 11, 2000 - Fix changer problem in cdrom_read_toc, we weren't
289 * correctly sensing a disc change.
290 * - Rearranged some code
291 * - Use extended sense on drives that support it for
292 * correctly reporting tray status -- from
293 * Michael D Johnson <johnsom@orst.edu>
294 * 4.60 Dec 17, 2003 - Add mt rainier support
295 * - Bump timeout for packet commands, matches sr
296 * - Odd stuff
297 * 4.61 Jan 22, 2004 - support hardware sector sizes other than 2kB,
298 * Pascal Schmidt <der.eremit@email.de>
299 *
300 *************************************************************************/
301
302#define IDECD_VERSION "4.61"
303 27
304#include <linux/module.h> 28#include <linux/module.h>
305#include <linux/types.h> 29#include <linux/types.h>
@@ -313,6 +37,7 @@
313#include <linux/ide.h> 37#include <linux/ide.h>
314#include <linux/completion.h> 38#include <linux/completion.h>
315#include <linux/mutex.h> 39#include <linux/mutex.h>
40#include <linux/bcd.h>
316 41
317#include <scsi/scsi.h> /* For SCSI -> ATAPI command conversion */ 42#include <scsi/scsi.h> /* For SCSI -> ATAPI command conversion */
318 43
@@ -360,11 +85,11 @@ static void ide_cd_put(struct cdrom_info *cd)
360 buffers. */ 85 buffers. */
361static void cdrom_saw_media_change (ide_drive_t *drive) 86static void cdrom_saw_media_change (ide_drive_t *drive)
362{ 87{
363 struct cdrom_info *info = drive->driver_data; 88 struct cdrom_info *cd = drive->driver_data;
364 89
365 CDROM_STATE_FLAGS (drive)->media_changed = 1; 90 cd->cd_flags |= IDE_CD_FLAG_MEDIA_CHANGED;
366 CDROM_STATE_FLAGS (drive)->toc_valid = 0; 91 cd->cd_flags &= ~IDE_CD_FLAG_TOC_VALID;
367 info->nsectors_buffered = 0; 92 cd->nsectors_buffered = 0;
368} 93}
369 94
370static int cdrom_log_sense(ide_drive_t *drive, struct request *rq, 95static int cdrom_log_sense(ide_drive_t *drive, struct request *rq,
@@ -465,134 +190,14 @@ void cdrom_analyze_sense_data(ide_drive_t *drive,
465 } 190 }
466 } 191 }
467 } 192 }
468#if VERBOSE_IDE_CD_ERRORS
469 {
470 int i;
471 const char *s = "bad sense key!";
472 char buf[80];
473
474 printk ("ATAPI device %s:\n", drive->name);
475 if (sense->error_code==0x70)
476 printk(" Error: ");
477 else if (sense->error_code==0x71)
478 printk(" Deferred Error: ");
479 else if (sense->error_code == 0x7f)
480 printk(" Vendor-specific Error: ");
481 else
482 printk(" Unknown Error Type: ");
483
484 if (sense->sense_key < ARRAY_SIZE(sense_key_texts))
485 s = sense_key_texts[sense->sense_key];
486
487 printk("%s -- (Sense key=0x%02x)\n", s, sense->sense_key);
488
489 if (sense->asc == 0x40) {
490 sprintf(buf, "Diagnostic failure on component 0x%02x",
491 sense->ascq);
492 s = buf;
493 } else {
494 int lo = 0, mid, hi = ARRAY_SIZE(sense_data_texts);
495 unsigned long key = (sense->sense_key << 16);
496 key |= (sense->asc << 8);
497 if (!(sense->ascq >= 0x80 && sense->ascq <= 0xdd))
498 key |= sense->ascq;
499 s = NULL;
500
501 while (hi > lo) {
502 mid = (lo + hi) / 2;
503 if (sense_data_texts[mid].asc_ascq == key ||
504 sense_data_texts[mid].asc_ascq == (0xff0000|key)) {
505 s = sense_data_texts[mid].text;
506 break;
507 }
508 else if (sense_data_texts[mid].asc_ascq > key)
509 hi = mid;
510 else
511 lo = mid+1;
512 }
513 }
514
515 if (s == NULL) {
516 if (sense->asc > 0x80)
517 s = "(vendor-specific error)";
518 else
519 s = "(reserved error code)";
520 }
521
522 printk(KERN_ERR " %s -- (asc=0x%02x, ascq=0x%02x)\n",
523 s, sense->asc, sense->ascq);
524
525 if (failed_command != NULL) {
526
527 int lo=0, mid, hi= ARRAY_SIZE(packet_command_texts);
528 s = NULL;
529
530 while (hi > lo) {
531 mid = (lo + hi) / 2;
532 if (packet_command_texts[mid].packet_command ==
533 failed_command->cmd[0]) {
534 s = packet_command_texts[mid].text;
535 break;
536 }
537 if (packet_command_texts[mid].packet_command >
538 failed_command->cmd[0])
539 hi = mid;
540 else
541 lo = mid+1;
542 }
543
544 printk (KERN_ERR " The failed \"%s\" packet command was: \n \"", s);
545 for (i=0; i<sizeof (failed_command->cmd); i++)
546 printk ("%02x ", failed_command->cmd[i]);
547 printk ("\"\n");
548 }
549
550 /* The SKSV bit specifies validity of the sense_key_specific
551 * in the next two commands. It is bit 7 of the first byte.
552 * In the case of NOT_READY, if SKSV is set the drive can
553 * give us nice ETA readings.
554 */
555 if (sense->sense_key == NOT_READY && (sense->sks[0] & 0x80)) {
556 int progress = (sense->sks[1] << 8 | sense->sks[2]) * 100;
557 printk(KERN_ERR " Command is %02d%% complete\n", progress / 0xffff);
558
559 }
560
561 if (sense->sense_key == ILLEGAL_REQUEST &&
562 (sense->sks[0] & 0x80) != 0) {
563 printk(KERN_ERR " Error in %s byte %d",
564 (sense->sks[0] & 0x40) != 0 ?
565 "command packet" : "command data",
566 (sense->sks[1] << 8) + sense->sks[2]);
567
568 if ((sense->sks[0] & 0x40) != 0)
569 printk (" bit %d", sense->sks[0] & 0x07);
570 193
571 printk ("\n"); 194 ide_cd_log_error(drive->name, failed_command, sense);
572 }
573 }
574
575#else /* not VERBOSE_IDE_CD_ERRORS */
576
577 /* Suppress printing unit attention and `in progress of becoming ready'
578 errors when we're not being verbose. */
579
580 if (sense->sense_key == UNIT_ATTENTION ||
581 (sense->sense_key == NOT_READY && (sense->asc == 4 ||
582 sense->asc == 0x3a)))
583 return;
584
585 printk(KERN_ERR "%s: error code: 0x%02x sense_key: 0x%02x asc: 0x%02x ascq: 0x%02x\n",
586 drive->name,
587 sense->error_code, sense->sense_key,
588 sense->asc, sense->ascq);
589#endif /* not VERBOSE_IDE_CD_ERRORS */
590} 195}
591 196
592/* 197/*
593 * Initialize a ide-cd packet command request 198 * Initialize a ide-cd packet command request
594 */ 199 */
595static void cdrom_prepare_request(ide_drive_t *drive, struct request *rq) 200void ide_cd_init_rq(ide_drive_t *drive, struct request *rq)
596{ 201{
597 struct cdrom_info *cd = drive->driver_data; 202 struct cdrom_info *cd = drive->driver_data;
598 203
@@ -611,7 +216,7 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
611 sense = &info->sense_data; 216 sense = &info->sense_data;
612 217
613 /* stuff the sense request in front of our current request */ 218 /* stuff the sense request in front of our current request */
614 cdrom_prepare_request(drive, rq); 219 ide_cd_init_rq(drive, rq);
615 220
616 rq->data = sense; 221 rq->data = sense;
617 rq->cmd[0] = GPCMD_REQUEST_SENSE; 222 rq->cmd[0] = GPCMD_REQUEST_SENSE;
@@ -718,7 +323,6 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
718 323
719 } else if (blk_pc_request(rq) || rq->cmd_type == REQ_TYPE_ATA_PC) { 324 } else if (blk_pc_request(rq) || rq->cmd_type == REQ_TYPE_ATA_PC) {
720 /* All other functions, except for READ. */ 325 /* All other functions, except for READ. */
721 unsigned long flags;
722 326
723 /* 327 /*
724 * if we have an error, pass back CHECK_CONDITION as the 328 * if we have an error, pass back CHECK_CONDITION as the
@@ -756,15 +360,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
756 * remove failed request completely and end it when the 360 * remove failed request completely and end it when the
757 * request sense has completed 361 * request sense has completed
758 */ 362 */
759 if (stat & ERR_STAT) { 363 goto end_request;
760 spin_lock_irqsave(&ide_lock, flags);
761 blkdev_dequeue_request(rq);
762 HWGROUP(drive)->rq = NULL;
763 spin_unlock_irqrestore(&ide_lock, flags);
764
765 cdrom_queue_request_sense(drive, rq->sense, rq);
766 } else
767 cdrom_end_request(drive, 0);
768 364
769 } else if (blk_fs_request(rq)) { 365 } else if (blk_fs_request(rq)) {
770 int do_end_request = 0; 366 int do_end_request = 0;
@@ -844,23 +440,15 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
844 sense data. We need this in order to perform end of media 440 sense data. We need this in order to perform end of media
845 processing */ 441 processing */
846 442
847 if (do_end_request) { 443 if (do_end_request)
848 if (stat & ERR_STAT) { 444 goto end_request;
849 unsigned long flags;
850 spin_lock_irqsave(&ide_lock, flags);
851 blkdev_dequeue_request(rq);
852 HWGROUP(drive)->rq = NULL;
853 spin_unlock_irqrestore(&ide_lock, flags);
854 445
855 cdrom_queue_request_sense(drive, rq->sense, rq); 446 /*
856 } else 447 * If we got a CHECK_CONDITION status,
857 cdrom_end_request(drive, 0); 448 * queue a request sense command.
858 } else { 449 */
859 /* If we got a CHECK_CONDITION status, 450 if (stat & ERR_STAT)
860 queue a request sense command. */ 451 cdrom_queue_request_sense(drive, NULL, NULL);
861 if (stat & ERR_STAT)
862 cdrom_queue_request_sense(drive, NULL, NULL);
863 }
864 } else { 452 } else {
865 blk_dump_rq_flags(rq, "ide-cd: bad rq"); 453 blk_dump_rq_flags(rq, "ide-cd: bad rq");
866 cdrom_end_request(drive, 0); 454 cdrom_end_request(drive, 0);
@@ -868,6 +456,21 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
868 456
869 /* Retry, or handle the next request. */ 457 /* Retry, or handle the next request. */
870 return 1; 458 return 1;
459
460end_request:
461 if (stat & ERR_STAT) {
462 unsigned long flags;
463
464 spin_lock_irqsave(&ide_lock, flags);
465 blkdev_dequeue_request(rq);
466 HWGROUP(drive)->rq = NULL;
467 spin_unlock_irqrestore(&ide_lock, flags);
468
469 cdrom_queue_request_sense(drive, rq->sense, rq);
470 } else
471 cdrom_end_request(drive, 0);
472
473 return 1;
871} 474}
872 475
873static int cdrom_timer_expiry(ide_drive_t *drive) 476static int cdrom_timer_expiry(ide_drive_t *drive)
@@ -924,8 +527,8 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
924 /* Set up the controller registers. */ 527 /* Set up the controller registers. */
925 ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL | 528 ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL |
926 IDE_TFLAG_NO_SELECT_MASK, xferlen, info->dma); 529 IDE_TFLAG_NO_SELECT_MASK, xferlen, info->dma);
927 530
928 if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt) { 531 if (info->cd_flags & IDE_CD_FLAG_DRQ_INTERRUPT) {
929 /* waiting for CDB interrupt, not DMA yet. */ 532 /* waiting for CDB interrupt, not DMA yet. */
930 if (info->dma) 533 if (info->dma)
931 drive->waiting_for_dma = 0; 534 drive->waiting_for_dma = 0;
@@ -951,10 +554,6 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
951 by cdrom_start_packet_command. 554 by cdrom_start_packet_command.
952 HANDLER is the interrupt handler to call when the command completes 555 HANDLER is the interrupt handler to call when the command completes
953 or there's data ready. */ 556 or there's data ready. */
954/*
955 * changed 5 parameters to 3 for dvd-ram
956 * struct packet_command *pc; now packet_command_t *pc;
957 */
958#define ATAPI_MIN_CDB_BYTES 12 557#define ATAPI_MIN_CDB_BYTES 12
959static ide_startstop_t cdrom_transfer_packet_command (ide_drive_t *drive, 558static ide_startstop_t cdrom_transfer_packet_command (ide_drive_t *drive,
960 struct request *rq, 559 struct request *rq,
@@ -965,7 +564,7 @@ static ide_startstop_t cdrom_transfer_packet_command (ide_drive_t *drive,
965 struct cdrom_info *info = drive->driver_data; 564 struct cdrom_info *info = drive->driver_data;
966 ide_startstop_t startstop; 565 ide_startstop_t startstop;
967 566
968 if (CDROM_CONFIG_FLAGS(drive)->drq_interrupt) { 567 if (info->cd_flags & IDE_CD_FLAG_DRQ_INTERRUPT) {
969 /* Here we should have been called after receiving an interrupt 568 /* Here we should have been called after receiving an interrupt
970 from the device. DRQ should how be set. */ 569 from the device. DRQ should how be set. */
971 570
@@ -1005,6 +604,27 @@ static ide_startstop_t cdrom_transfer_packet_command (ide_drive_t *drive,
1005 * Block read functions. 604 * Block read functions.
1006 */ 605 */
1007 606
607typedef void (xfer_func_t)(ide_drive_t *, void *, u32);
608
609static void ide_cd_pad_transfer(ide_drive_t *drive, xfer_func_t *xf, int len)
610{
611 while (len > 0) {
612 int dum = 0;
613 xf(drive, &dum, sizeof(dum));
614 len -= sizeof(dum);
615 }
616}
617
618static void ide_cd_drain_data(ide_drive_t *drive, int nsects)
619{
620 while (nsects > 0) {
621 static char dum[SECTOR_SIZE];
622
623 drive->hwif->atapi_input_bytes(drive, dum, sizeof(dum));
624 nsects--;
625 }
626}
627
1008/* 628/*
1009 * Buffer up to SECTORS_TO_TRANSFER sectors from the drive in our sector 629 * Buffer up to SECTORS_TO_TRANSFER sectors from the drive in our sector
1010 * buffer. Once the first sector is added, any subsequent sectors are 630 * buffer. Once the first sector is added, any subsequent sectors are
@@ -1043,11 +663,7 @@ static void cdrom_buffer_sectors (ide_drive_t *drive, unsigned long sector,
1043 } 663 }
1044 664
1045 /* Throw away any remaining data. */ 665 /* Throw away any remaining data. */
1046 while (sectors_to_transfer > 0) { 666 ide_cd_drain_data(drive, sectors_to_transfer);
1047 static char dum[SECTOR_SIZE];
1048 HWIF(drive)->atapi_input_bytes(drive, dum, sizeof (dum));
1049 --sectors_to_transfer;
1050 }
1051} 667}
1052 668
1053/* 669/*
@@ -1056,23 +672,25 @@ static void cdrom_buffer_sectors (ide_drive_t *drive, unsigned long sector,
1056 * ok; nonzero if the request has been terminated. 672 * ok; nonzero if the request has been terminated.
1057 */ 673 */
1058static 674static
1059int cdrom_read_check_ireason (ide_drive_t *drive, int len, int ireason) 675int ide_cd_check_ireason(ide_drive_t *drive, int len, int ireason, int rw)
1060{ 676{
1061 if (ireason == 2) 677 /*
678 * ireason == 0: the drive wants to receive data from us
679 * ireason == 2: the drive is expecting to transfer data to us
680 */
681 if (ireason == (!rw << 1))
1062 return 0; 682 return 0;
1063 else if (ireason == 0) { 683 else if (ireason == (rw << 1)) {
1064 /* Whoops... The drive is expecting to receive data from us! */ 684 ide_hwif_t *hwif = drive->hwif;
685 xfer_func_t *xf;
686
687 /* Whoops... */
1065 printk(KERN_ERR "%s: %s: wrong transfer direction!\n", 688 printk(KERN_ERR "%s: %s: wrong transfer direction!\n",
1066 drive->name, __FUNCTION__); 689 drive->name, __FUNCTION__);
1067 690
1068 /* Throw some data at the drive so it doesn't hang 691 xf = rw ? hwif->atapi_output_bytes : hwif->atapi_input_bytes;
1069 and quit this request. */ 692 ide_cd_pad_transfer(drive, xf, len);
1070 while (len > 0) { 693 } else if (rw == 0 && ireason == 1) {
1071 int dum = 0;
1072 HWIF(drive)->atapi_output_bytes(drive, &dum, sizeof (dum));
1073 len -= sizeof (dum);
1074 }
1075 } else if (ireason == 1) {
1076 /* Some drives (ASUS) seem to tell us that status 694 /* Some drives (ASUS) seem to tell us that status
1077 * info is available. just get it and ignore. 695 * info is available. just get it and ignore.
1078 */ 696 */
@@ -1089,137 +707,28 @@ int cdrom_read_check_ireason (ide_drive_t *drive, int len, int ireason)
1089} 707}
1090 708
1091/* 709/*
1092 * Interrupt routine. Called when a read request has completed. 710 * Assume that the drive will always provide data in multiples of at least
711 * SECTOR_SIZE, as it gets hairy to keep track of the transfers otherwise.
1093 */ 712 */
1094static ide_startstop_t cdrom_read_intr (ide_drive_t *drive) 713static int ide_cd_check_transfer_size(ide_drive_t *drive, int len)
1095{ 714{
1096 int stat; 715 struct cdrom_info *cd = drive->driver_data;
1097 int ireason, len, sectors_to_transfer, nskip;
1098 struct cdrom_info *info = drive->driver_data;
1099 u8 lowcyl = 0, highcyl = 0;
1100 int dma = info->dma, dma_error = 0;
1101
1102 struct request *rq = HWGROUP(drive)->rq;
1103
1104 /*
1105 * handle dma case
1106 */
1107 if (dma) {
1108 info->dma = 0;
1109 dma_error = HWIF(drive)->ide_dma_end(drive);
1110 if (dma_error) {
1111 printk(KERN_ERR "%s: DMA read error\n", drive->name);
1112 ide_dma_off(drive);
1113 }
1114 }
1115
1116 if (cdrom_decode_status(drive, 0, &stat))
1117 return ide_stopped;
1118
1119 if (dma) {
1120 if (!dma_error) {
1121 ide_end_request(drive, 1, rq->nr_sectors);
1122 return ide_stopped;
1123 } else
1124 return ide_error(drive, "dma error", stat);
1125 }
1126
1127 /* Read the interrupt reason and the transfer length. */
1128 ireason = HWIF(drive)->INB(IDE_IREASON_REG) & 0x3;
1129 lowcyl = HWIF(drive)->INB(IDE_BCOUNTL_REG);
1130 highcyl = HWIF(drive)->INB(IDE_BCOUNTH_REG);
1131
1132 len = lowcyl + (256 * highcyl);
1133
1134 /* If DRQ is clear, the command has completed. */
1135 if ((stat & DRQ_STAT) == 0) {
1136 /* If we're not done filling the current buffer, complain.
1137 Otherwise, complete the command normally. */
1138 if (rq->current_nr_sectors > 0) {
1139 printk (KERN_ERR "%s: cdrom_read_intr: data underrun (%d blocks)\n",
1140 drive->name, rq->current_nr_sectors);
1141 rq->cmd_flags |= REQ_FAILED;
1142 cdrom_end_request(drive, 0);
1143 } else
1144 cdrom_end_request(drive, 1);
1145 return ide_stopped;
1146 }
1147
1148 /* Check that the drive is expecting to do the same thing we are. */
1149 if (cdrom_read_check_ireason (drive, len, ireason))
1150 return ide_stopped;
1151
1152 /* Assume that the drive will always provide data in multiples
1153 of at least SECTOR_SIZE, as it gets hairy to keep track
1154 of the transfers otherwise. */
1155 if ((len % SECTOR_SIZE) != 0) {
1156 printk (KERN_ERR "%s: cdrom_read_intr: Bad transfer size %d\n",
1157 drive->name, len);
1158 if (CDROM_CONFIG_FLAGS(drive)->limit_nframes)
1159 printk (KERN_ERR " This drive is not supported by this version of the driver\n");
1160 else {
1161 printk (KERN_ERR " Trying to limit transfer sizes\n");
1162 CDROM_CONFIG_FLAGS(drive)->limit_nframes = 1;
1163 }
1164 cdrom_end_request(drive, 0);
1165 return ide_stopped;
1166 }
1167
1168 /* The number of sectors we need to read from the drive. */
1169 sectors_to_transfer = len / SECTOR_SIZE;
1170
1171 /* First, figure out if we need to bit-bucket
1172 any of the leading sectors. */
1173 nskip = min_t(int, rq->current_nr_sectors - bio_cur_sectors(rq->bio), sectors_to_transfer);
1174
1175 while (nskip > 0) {
1176 /* We need to throw away a sector. */
1177 static char dum[SECTOR_SIZE];
1178 HWIF(drive)->atapi_input_bytes(drive, dum, sizeof (dum));
1179
1180 --rq->current_nr_sectors;
1181 --nskip;
1182 --sectors_to_transfer;
1183 }
1184 716
1185 /* Now loop while we still have data to read from the drive. */ 717 if ((len % SECTOR_SIZE) == 0)
1186 while (sectors_to_transfer > 0) { 718 return 0;
1187 int this_transfer;
1188 719
1189 /* If we've filled the present buffer but there's another 720 printk(KERN_ERR "%s: %s: Bad transfer size %d\n",
1190 chained buffer after it, move on. */ 721 drive->name, __FUNCTION__, len);
1191 if (rq->current_nr_sectors == 0 && rq->nr_sectors)
1192 cdrom_end_request(drive, 1);
1193 722
1194 /* If the buffers are full, cache the rest of the data in our 723 if (cd->cd_flags & IDE_CD_FLAG_LIMIT_NFRAMES)
1195 internal buffer. */ 724 printk(KERN_ERR " This drive is not supported by "
1196 if (rq->current_nr_sectors == 0) { 725 "this version of the driver\n");
1197 cdrom_buffer_sectors(drive, rq->sector, sectors_to_transfer); 726 else {
1198 sectors_to_transfer = 0; 727 printk(KERN_ERR " Trying to limit transfer sizes\n");
1199 } else { 728 cd->cd_flags |= IDE_CD_FLAG_LIMIT_NFRAMES;
1200 /* Transfer data to the buffers.
1201 Figure out how many sectors we can transfer
1202 to the current buffer. */
1203 this_transfer = min_t(int, sectors_to_transfer,
1204 rq->current_nr_sectors);
1205
1206 /* Read this_transfer sectors
1207 into the current buffer. */
1208 while (this_transfer > 0) {
1209 HWIF(drive)->atapi_input_bytes(drive, rq->buffer, SECTOR_SIZE);
1210 rq->buffer += SECTOR_SIZE;
1211 --rq->nr_sectors;
1212 --rq->current_nr_sectors;
1213 ++rq->sector;
1214 --this_transfer;
1215 --sectors_to_transfer;
1216 }
1217 }
1218 } 729 }
1219 730
1220 /* Done moving data! Wait for another interrupt. */ 731 return 1;
1221 ide_set_handler(drive, &cdrom_read_intr, ATAPI_WAIT_PC, NULL);
1222 return ide_started;
1223} 732}
1224 733
1225/* 734/*
@@ -1281,48 +790,58 @@ static int cdrom_read_from_buffer (ide_drive_t *drive)
1281 return 0; 790 return 0;
1282} 791}
1283 792
793static ide_startstop_t cdrom_newpc_intr(ide_drive_t *);
794
1284/* 795/*
1285 * Routine to send a read packet command to the drive. 796 * Routine to send a read/write packet command to the drive.
1286 * This is usually called directly from cdrom_start_read. 797 * This is usually called directly from cdrom_start_{read,write}().
1287 * However, for drq_interrupt devices, it is called from an interrupt 798 * However, for drq_interrupt devices, it is called from an interrupt
1288 * when the drive is ready to accept the command. 799 * when the drive is ready to accept the command.
1289 */ 800 */
1290static ide_startstop_t cdrom_start_read_continuation (ide_drive_t *drive) 801static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive)
1291{ 802{
1292 struct request *rq = HWGROUP(drive)->rq; 803 struct request *rq = HWGROUP(drive)->rq;
1293 unsigned short sectors_per_frame;
1294 int nskip;
1295 804
1296 sectors_per_frame = queue_hardsect_size(drive->queue) >> SECTOR_BITS; 805 if (rq_data_dir(rq) == READ) {
806 unsigned short sectors_per_frame =
807 queue_hardsect_size(drive->queue) >> SECTOR_BITS;
808 int nskip = rq->sector & (sectors_per_frame - 1);
1297 809
1298 /* If the requested sector doesn't start on a cdrom block boundary, 810 /*
1299 we must adjust the start of the transfer so that it does, 811 * If the requested sector doesn't start on a frame boundary,
1300 and remember to skip the first few sectors. 812 * we must adjust the start of the transfer so that it does,
1301 If the CURRENT_NR_SECTORS field is larger than the size 813 * and remember to skip the first few sectors.
1302 of the buffer, it will mean that we're to skip a number 814 *
1303 of sectors equal to the amount by which CURRENT_NR_SECTORS 815 * If the rq->current_nr_sectors field is larger than the size
1304 is larger than the buffer size. */ 816 * of the buffer, it will mean that we're to skip a number of
1305 nskip = rq->sector & (sectors_per_frame - 1); 817 * sectors equal to the amount by which rq->current_nr_sectors
1306 if (nskip > 0) { 818 * is larger than the buffer size.
1307 /* Sanity check... */ 819 */
1308 if (rq->current_nr_sectors != bio_cur_sectors(rq->bio) && 820 if (nskip > 0) {
1309 (rq->sector & (sectors_per_frame - 1))) { 821 /* Sanity check... */
1310 printk(KERN_ERR "%s: cdrom_start_read_continuation: buffer botch (%u)\n", 822 if (rq->current_nr_sectors !=
1311 drive->name, rq->current_nr_sectors); 823 bio_cur_sectors(rq->bio)) {
1312 cdrom_end_request(drive, 0); 824 printk(KERN_ERR "%s: %s: buffer botch (%u)\n",
1313 return ide_stopped; 825 drive->name, __FUNCTION__,
826 rq->current_nr_sectors);
827 cdrom_end_request(drive, 0);
828 return ide_stopped;
829 }
830 rq->current_nr_sectors += nskip;
1314 } 831 }
1315 rq->current_nr_sectors += nskip;
1316 } 832 }
1317 833#if 0
834 else
835 /* the immediate bit */
836 rq->cmd[1] = 1 << 3;
837#endif
1318 /* Set up the command */ 838 /* Set up the command */
1319 rq->timeout = ATAPI_WAIT_PC; 839 rq->timeout = ATAPI_WAIT_PC;
1320 840
1321 /* Send the command to the drive and return. */ 841 /* Send the command to the drive and return. */
1322 return cdrom_transfer_packet_command(drive, rq, &cdrom_read_intr); 842 return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr);
1323} 843}
1324 844
1325
1326#define IDECD_SEEK_THRESHOLD (1000) /* 1000 blocks */ 845#define IDECD_SEEK_THRESHOLD (1000) /* 1000 blocks */
1327#define IDECD_SEEK_TIMER (5 * WAIT_MIN_SLEEP) /* 100 ms */ 846#define IDECD_SEEK_TIMER (5 * WAIT_MIN_SLEEP) /* 100 ms */
1328#define IDECD_SEEK_TIMEOUT (2 * WAIT_CMD) /* 20 sec */ 847#define IDECD_SEEK_TIMEOUT (2 * WAIT_CMD) /* 20 sec */
@@ -1335,7 +854,8 @@ static ide_startstop_t cdrom_seek_intr (ide_drive_t *drive)
1335 854
1336 if (cdrom_decode_status(drive, 0, &stat)) 855 if (cdrom_decode_status(drive, 0, &stat))
1337 return ide_stopped; 856 return ide_stopped;
1338 CDROM_CONFIG_FLAGS(drive)->seeking = 1; 857
858 info->cd_flags |= IDE_CD_FLAG_SEEKING;
1339 859
1340 if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) { 860 if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) {
1341 if (--retry == 0) { 861 if (--retry == 0) {
@@ -1391,184 +911,25 @@ static void restore_request (struct request *rq)
1391 rq->q->prep_rq_fn(rq->q, rq); 911 rq->q->prep_rq_fn(rq->q, rq);
1392} 912}
1393 913
1394/*
1395 * Start a read request from the CD-ROM.
1396 */
1397static ide_startstop_t cdrom_start_read (ide_drive_t *drive, unsigned int block)
1398{
1399 struct cdrom_info *info = drive->driver_data;
1400 struct request *rq = HWGROUP(drive)->rq;
1401 unsigned short sectors_per_frame;
1402
1403 sectors_per_frame = queue_hardsect_size(drive->queue) >> SECTOR_BITS;
1404
1405 /* We may be retrying this request after an error. Fix up
1406 any weirdness which might be present in the request packet. */
1407 restore_request(rq);
1408
1409 /* Satisfy whatever we can of this request from our cached sector. */
1410 if (cdrom_read_from_buffer(drive))
1411 return ide_stopped;
1412
1413 /* Clear the local sector buffer. */
1414 info->nsectors_buffered = 0;
1415
1416 /* use dma, if possible. */
1417 info->dma = drive->using_dma;
1418 if ((rq->sector & (sectors_per_frame - 1)) ||
1419 (rq->nr_sectors & (sectors_per_frame - 1)))
1420 info->dma = 0;
1421
1422 /* Start sending the read request to the drive. */
1423 return cdrom_start_packet_command(drive, 32768, cdrom_start_read_continuation);
1424}
1425
1426/**************************************************************************** 914/****************************************************************************
1427 * Execute all other packet commands. 915 * Execute all other packet commands.
1428 */ 916 */
1429 917
1430/* Interrupt routine for packet command completion. */ 918static void ide_cd_request_sense_fixup(struct request *rq)
1431static ide_startstop_t cdrom_pc_intr (ide_drive_t *drive)
1432{ 919{
1433 int ireason, len, thislen; 920 /*
1434 struct request *rq = HWGROUP(drive)->rq; 921 * Some of the trailing request sense fields are optional,
1435 u8 lowcyl = 0, highcyl = 0; 922 * and some drives don't send them. Sigh.
1436 int stat; 923 */
1437 924 if (rq->cmd[0] == GPCMD_REQUEST_SENSE &&
1438 /* Check for errors. */ 925 rq->data_len > 0 && rq->data_len <= 5)
1439 if (cdrom_decode_status(drive, 0, &stat)) 926 while (rq->data_len > 0) {
1440 return ide_stopped; 927 *(u8 *)rq->data++ = 0;
1441 928 --rq->data_len;
1442 /* Read the interrupt reason and the transfer length. */
1443 ireason = HWIF(drive)->INB(IDE_IREASON_REG) & 0x3;
1444 lowcyl = HWIF(drive)->INB(IDE_BCOUNTL_REG);
1445 highcyl = HWIF(drive)->INB(IDE_BCOUNTH_REG);
1446
1447 len = lowcyl + (256 * highcyl);
1448
1449 /* If DRQ is clear, the command has completed.
1450 Complain if we still have data left to transfer. */
1451 if ((stat & DRQ_STAT) == 0) {
1452 /* Some of the trailing request sense fields are optional, and
1453 some drives don't send them. Sigh. */
1454 if (rq->cmd[0] == GPCMD_REQUEST_SENSE &&
1455 rq->data_len > 0 &&
1456 rq->data_len <= 5) {
1457 while (rq->data_len > 0) {
1458 *(unsigned char *)rq->data++ = 0;
1459 --rq->data_len;
1460 }
1461 }
1462
1463 if (rq->data_len == 0)
1464 cdrom_end_request(drive, 1);
1465 else {
1466 /* Comment this out, because this always happens
1467 right after a reset occurs, and it is annoying to
1468 always print expected stuff. */
1469 /*
1470 printk ("%s: cdrom_pc_intr: data underrun %d\n",
1471 drive->name, pc->buflen);
1472 */
1473 rq->cmd_flags |= REQ_FAILED;
1474 cdrom_end_request(drive, 0);
1475 }
1476 return ide_stopped;
1477 }
1478
1479 /* Figure out how much data to transfer. */
1480 thislen = rq->data_len;
1481 if (thislen > len) thislen = len;
1482
1483 /* The drive wants to be written to. */
1484 if (ireason == 0) {
1485 if (!rq->data) {
1486 blk_dump_rq_flags(rq, "cdrom_pc_intr, write");
1487 goto confused;
1488 }
1489 /* Transfer the data. */
1490 HWIF(drive)->atapi_output_bytes(drive, rq->data, thislen);
1491
1492 /* If we haven't moved enough data to satisfy the drive,
1493 add some padding. */
1494 while (len > thislen) {
1495 int dum = 0;
1496 HWIF(drive)->atapi_output_bytes(drive, &dum, sizeof(dum));
1497 len -= sizeof(dum);
1498 }
1499
1500 /* Keep count of how much data we've moved. */
1501 rq->data += thislen;
1502 rq->data_len -= thislen;
1503 }
1504
1505 /* Same drill for reading. */
1506 else if (ireason == 2) {
1507 if (!rq->data) {
1508 blk_dump_rq_flags(rq, "cdrom_pc_intr, read");
1509 goto confused;
1510 }
1511 /* Transfer the data. */
1512 HWIF(drive)->atapi_input_bytes(drive, rq->data, thislen);
1513
1514 /* If we haven't moved enough data to satisfy the drive,
1515 add some padding. */
1516 while (len > thislen) {
1517 int dum = 0;
1518 HWIF(drive)->atapi_input_bytes(drive, &dum, sizeof(dum));
1519 len -= sizeof(dum);
1520 } 929 }
1521
1522 /* Keep count of how much data we've moved. */
1523 rq->data += thislen;
1524 rq->data_len -= thislen;
1525
1526 if (blk_sense_request(rq))
1527 rq->sense_len += thislen;
1528 } else {
1529confused:
1530 printk (KERN_ERR "%s: cdrom_pc_intr: The drive "
1531 "appears confused (ireason = 0x%02x). "
1532 "Trying to recover by ending request.\n",
1533 drive->name, ireason);
1534 rq->cmd_flags |= REQ_FAILED;
1535 cdrom_end_request(drive, 0);
1536 return ide_stopped;
1537 }
1538
1539 /* Now we wait for another interrupt. */
1540 ide_set_handler(drive, &cdrom_pc_intr, ATAPI_WAIT_PC, cdrom_timer_expiry);
1541 return ide_started;
1542} 930}
1543 931
1544static ide_startstop_t cdrom_do_pc_continuation (ide_drive_t *drive) 932int ide_cd_queue_pc(ide_drive_t *drive, struct request *rq)
1545{
1546 struct request *rq = HWGROUP(drive)->rq;
1547
1548 if (!rq->timeout)
1549 rq->timeout = ATAPI_WAIT_PC;
1550
1551 /* Send the command to the drive and return. */
1552 return cdrom_transfer_packet_command(drive, rq, &cdrom_pc_intr);
1553}
1554
1555
1556static ide_startstop_t cdrom_do_packet_command (ide_drive_t *drive)
1557{
1558 int len;
1559 struct request *rq = HWGROUP(drive)->rq;
1560 struct cdrom_info *info = drive->driver_data;
1561
1562 info->dma = 0;
1563 rq->cmd_flags &= ~REQ_FAILED;
1564 len = rq->data_len;
1565
1566 /* Start sending the command to the drive. */
1567 return cdrom_start_packet_command(drive, len, cdrom_do_pc_continuation);
1568}
1569
1570
1571static int cdrom_queue_packet_command(ide_drive_t *drive, struct request *rq)
1572{ 933{
1573 struct request_sense sense; 934 struct request_sense sense;
1574 int retries = 10; 935 int retries = 10;
@@ -1617,37 +978,6 @@ static int cdrom_queue_packet_command(ide_drive_t *drive, struct request *rq)
1617} 978}
1618 979
1619/* 980/*
1620 * Write handling
1621 */
1622static int cdrom_write_check_ireason(ide_drive_t *drive, int len, int ireason)
1623{
1624 /* Two notes about IDE interrupt reason here - 0 means that
1625 * the drive wants to receive data from us, 2 means that
1626 * the drive is expecting to transfer data to us.
1627 */
1628 if (ireason == 0)
1629 return 0;
1630 else if (ireason == 2) {
1631 /* Whoops... The drive wants to send data. */
1632 printk(KERN_ERR "%s: %s: wrong transfer direction!\n",
1633 drive->name, __FUNCTION__);
1634
1635 while (len > 0) {
1636 int dum = 0;
1637 HWIF(drive)->atapi_input_bytes(drive, &dum, sizeof(dum));
1638 len -= sizeof(dum);
1639 }
1640 } else {
1641 /* Drive wants a command packet, or invalid ireason... */
1642 printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n",
1643 drive->name, __FUNCTION__, ireason);
1644 }
1645
1646 cdrom_end_request(drive, 0);
1647 return 1;
1648}
1649
1650/*
1651 * Called from blk_end_request_callback() after the data of the request 981 * Called from blk_end_request_callback() after the data of the request
1652 * is completed and before the request is completed. 982 * is completed and before the request is completed.
1653 * By returning value '1', blk_end_request_callback() returns immediately 983 * By returning value '1', blk_end_request_callback() returns immediately
@@ -1658,29 +988,27 @@ static int cdrom_newpc_intr_dummy_cb(struct request *rq)
1658 return 1; 988 return 1;
1659} 989}
1660 990
1661typedef void (xfer_func_t)(ide_drive_t *, void *, u32);
1662
1663/*
1664 * best way to deal with dma that is not sector aligned right now... note
1665 * that in this path we are not using ->data or ->buffer at all. this irs
1666 * can replace cdrom_pc_intr, cdrom_read_intr, and cdrom_write_intr in the
1667 * future.
1668 */
1669static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) 991static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1670{ 992{
1671 struct cdrom_info *info = drive->driver_data; 993 struct cdrom_info *info = drive->driver_data;
1672 struct request *rq = HWGROUP(drive)->rq; 994 struct request *rq = HWGROUP(drive)->rq;
1673 int dma_error, dma, stat, ireason, len, thislen;
1674 u8 lowcyl, highcyl;
1675 xfer_func_t *xferfunc; 995 xfer_func_t *xferfunc;
1676 unsigned long flags; 996 ide_expiry_t *expiry = NULL;
997 int dma_error = 0, dma, stat, ireason, len, thislen, uptodate = 0;
998 int write = (rq_data_dir(rq) == WRITE) ? 1 : 0;
999 unsigned int timeout;
1000 u8 lowcyl, highcyl;
1677 1001
1678 /* Check for errors. */ 1002 /* Check for errors. */
1679 dma_error = 0;
1680 dma = info->dma; 1003 dma = info->dma;
1681 if (dma) { 1004 if (dma) {
1682 info->dma = 0; 1005 info->dma = 0;
1683 dma_error = HWIF(drive)->ide_dma_end(drive); 1006 dma_error = HWIF(drive)->ide_dma_end(drive);
1007 if (dma_error) {
1008 printk(KERN_ERR "%s: DMA %s error\n", drive->name,
1009 write ? "write" : "read");
1010 ide_dma_off(drive);
1011 }
1684 } 1012 }
1685 1013
1686 if (cdrom_decode_status(drive, 0, &stat)) 1014 if (cdrom_decode_status(drive, 0, &stat))
@@ -1690,19 +1018,13 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1690 * using dma, transfer is complete now 1018 * using dma, transfer is complete now
1691 */ 1019 */
1692 if (dma) { 1020 if (dma) {
1693 if (dma_error) { 1021 if (dma_error)
1694 printk(KERN_ERR "ide-cd: dma error\n");
1695 ide_dma_off(drive);
1696 return ide_error(drive, "dma error", stat); 1022 return ide_error(drive, "dma error", stat);
1023 if (blk_fs_request(rq)) {
1024 ide_end_request(drive, 1, rq->nr_sectors);
1025 return ide_stopped;
1697 } 1026 }
1698 1027 goto end_request;
1699 spin_lock_irqsave(&ide_lock, flags);
1700 if (__blk_end_request(rq, 0, rq->data_len))
1701 BUG();
1702 HWGROUP(drive)->rq = NULL;
1703 spin_unlock_irqrestore(&ide_lock, flags);
1704
1705 return ide_stopped;
1706 } 1028 }
1707 1029
1708 /* 1030 /*
@@ -1713,7 +1035,8 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1713 highcyl = HWIF(drive)->INB(IDE_BCOUNTH_REG); 1035 highcyl = HWIF(drive)->INB(IDE_BCOUNTH_REG);
1714 1036
1715 len = lowcyl + (256 * highcyl); 1037 len = lowcyl + (256 * highcyl);
1716 thislen = rq->data_len; 1038
1039 thislen = blk_fs_request(rq) ? len : rq->data_len;
1717 if (thislen > len) 1040 if (thislen > len)
1718 thislen = len; 1041 thislen = len;
1719 1042
@@ -1721,53 +1044,111 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1721 * If DRQ is clear, the command has completed. 1044 * If DRQ is clear, the command has completed.
1722 */ 1045 */
1723 if ((stat & DRQ_STAT) == 0) { 1046 if ((stat & DRQ_STAT) == 0) {
1724 spin_lock_irqsave(&ide_lock, flags); 1047 if (blk_fs_request(rq)) {
1725 if (__blk_end_request(rq, 0, rq->data_len)) 1048 /*
1726 BUG(); 1049 * If we're not done reading/writing, complain.
1727 HWGROUP(drive)->rq = NULL; 1050 * Otherwise, complete the command normally.
1728 spin_unlock_irqrestore(&ide_lock, flags); 1051 */
1729 1052 uptodate = 1;
1730 return ide_stopped; 1053 if (rq->current_nr_sectors > 0) {
1054 printk(KERN_ERR "%s: %s: data underrun "
1055 "(%d blocks)\n",
1056 drive->name, __FUNCTION__,
1057 rq->current_nr_sectors);
1058 if (!write)
1059 rq->cmd_flags |= REQ_FAILED;
1060 uptodate = 0;
1061 }
1062 cdrom_end_request(drive, uptodate);
1063 return ide_stopped;
1064 } else if (!blk_pc_request(rq)) {
1065 ide_cd_request_sense_fixup(rq);
1066 /* Complain if we still have data left to transfer. */
1067 uptodate = rq->data_len ? 0 : 1;
1068 }
1069 goto end_request;
1731 } 1070 }
1732 1071
1733 /* 1072 /*
1734 * check which way to transfer data 1073 * check which way to transfer data
1735 */ 1074 */
1736 if (rq_data_dir(rq) == WRITE) { 1075 if (blk_fs_request(rq) || blk_pc_request(rq)) {
1737 /* 1076 if (ide_cd_check_ireason(drive, len, ireason, write))
1738 * write to drive
1739 */
1740 if (cdrom_write_check_ireason(drive, len, ireason))
1741 return ide_stopped; 1077 return ide_stopped;
1742 1078
1743 xferfunc = HWIF(drive)->atapi_output_bytes; 1079 if (blk_fs_request(rq) && write == 0) {
1744 } else { 1080 int nskip;
1745 /*
1746 * read from drive
1747 */
1748 if (cdrom_read_check_ireason(drive, len, ireason))
1749 return ide_stopped;
1750 1081
1082 if (ide_cd_check_transfer_size(drive, len)) {
1083 cdrom_end_request(drive, 0);
1084 return ide_stopped;
1085 }
1086
1087 /*
1088 * First, figure out if we need to bit-bucket
1089 * any of the leading sectors.
1090 */
1091 nskip = min_t(int, rq->current_nr_sectors
1092 - bio_cur_sectors(rq->bio),
1093 thislen >> 9);
1094 if (nskip > 0) {
1095 ide_cd_drain_data(drive, nskip);
1096 rq->current_nr_sectors -= nskip;
1097 thislen -= (nskip << 9);
1098 }
1099 }
1100 }
1101
1102 if (ireason == 0) {
1103 write = 1;
1104 xferfunc = HWIF(drive)->atapi_output_bytes;
1105 } else if (ireason == 2 || (ireason == 1 &&
1106 (blk_fs_request(rq) || blk_pc_request(rq)))) {
1107 write = 0;
1751 xferfunc = HWIF(drive)->atapi_input_bytes; 1108 xferfunc = HWIF(drive)->atapi_input_bytes;
1109 } else {
1110 printk(KERN_ERR "%s: %s: The drive "
1111 "appears confused (ireason = 0x%02x). "
1112 "Trying to recover by ending request.\n",
1113 drive->name, __FUNCTION__, ireason);
1114 goto end_request;
1752 } 1115 }
1753 1116
1754 /* 1117 /*
1755 * transfer data 1118 * transfer data
1756 */ 1119 */
1757 while (thislen > 0) { 1120 while (thislen > 0) {
1758 int blen = blen = rq->data_len; 1121 u8 *ptr = blk_fs_request(rq) ? NULL : rq->data;
1759 char *ptr = rq->data; 1122 int blen = rq->data_len;
1760 1123
1761 /* 1124 /*
1762 * bio backed? 1125 * bio backed?
1763 */ 1126 */
1764 if (rq->bio) { 1127 if (rq->bio) {
1765 ptr = bio_data(rq->bio); 1128 if (blk_fs_request(rq)) {
1766 blen = bio_iovec(rq->bio)->bv_len; 1129 ptr = rq->buffer;
1130 blen = rq->current_nr_sectors << 9;
1131 } else {
1132 ptr = bio_data(rq->bio);
1133 blen = bio_iovec(rq->bio)->bv_len;
1134 }
1767 } 1135 }
1768 1136
1769 if (!ptr) { 1137 if (!ptr) {
1770 printk(KERN_ERR "%s: confused, missing data\n", drive->name); 1138 if (blk_fs_request(rq) && !write)
1139 /*
1140 * If the buffers are full, cache the rest
1141 * of the data in our internal buffer.
1142 */
1143 cdrom_buffer_sectors(drive, rq->sector,
1144 thislen >> 9);
1145 else {
1146 printk(KERN_ERR "%s: confused, missing data\n",
1147 drive->name);
1148 blk_dump_rq_flags(rq, rq_data_dir(rq)
1149 ? "cdrom_newpc_intr, write"
1150 : "cdrom_newpc_intr, read");
1151 }
1771 break; 1152 break;
1772 } 1153 }
1773 1154
@@ -1778,185 +1159,117 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1778 1159
1779 thislen -= blen; 1160 thislen -= blen;
1780 len -= blen; 1161 len -= blen;
1781 rq->data_len -= blen;
1782 1162
1783 if (rq->bio) 1163 if (blk_fs_request(rq)) {
1164 rq->buffer += blen;
1165 rq->nr_sectors -= (blen >> 9);
1166 rq->current_nr_sectors -= (blen >> 9);
1167 rq->sector += (blen >> 9);
1168
1169 if (rq->current_nr_sectors == 0 && rq->nr_sectors)
1170 cdrom_end_request(drive, 1);
1171 } else {
1172 rq->data_len -= blen;
1173
1784 /* 1174 /*
1785 * The request can't be completed until DRQ is cleared. 1175 * The request can't be completed until DRQ is cleared.
1786 * So complete the data, but don't complete the request 1176 * So complete the data, but don't complete the request
1787 * using the dummy function for the callback feature 1177 * using the dummy function for the callback feature
1788 * of blk_end_request_callback(). 1178 * of blk_end_request_callback().
1789 */ 1179 */
1790 blk_end_request_callback(rq, 0, blen, 1180 if (rq->bio)
1181 blk_end_request_callback(rq, 0, blen,
1791 cdrom_newpc_intr_dummy_cb); 1182 cdrom_newpc_intr_dummy_cb);
1792 else 1183 else
1793 rq->data += blen; 1184 rq->data += blen;
1794 }
1795
1796 /*
1797 * pad, if necessary
1798 */
1799 if (len > 0) {
1800 while (len > 0) {
1801 int pad = 0;
1802
1803 xferfunc(drive, &pad, sizeof(pad));
1804 len -= sizeof(pad);
1805 }
1806 }
1807
1808 BUG_ON(HWGROUP(drive)->handler != NULL);
1809
1810 ide_set_handler(drive, cdrom_newpc_intr, rq->timeout, NULL);
1811 return ide_started;
1812}
1813
1814static ide_startstop_t cdrom_write_intr(ide_drive_t *drive)
1815{
1816 int stat, ireason, len, sectors_to_transfer, uptodate;
1817 struct cdrom_info *info = drive->driver_data;
1818 int dma_error = 0, dma = info->dma;
1819 u8 lowcyl = 0, highcyl = 0;
1820
1821 struct request *rq = HWGROUP(drive)->rq;
1822
1823 /* Check for errors. */
1824 if (dma) {
1825 info->dma = 0;
1826 dma_error = HWIF(drive)->ide_dma_end(drive);
1827 if (dma_error) {
1828 printk(KERN_ERR "%s: DMA write error\n", drive->name);
1829 ide_dma_off(drive);
1830 } 1185 }
1831 } 1186 }
1832 1187
1833 if (cdrom_decode_status(drive, 0, &stat)) 1188 if (write && blk_sense_request(rq))
1834 return ide_stopped; 1189 rq->sense_len += thislen;
1835 1190
1836 /* 1191 /*
1837 * using dma, transfer is complete now 1192 * pad, if necessary
1838 */ 1193 */
1839 if (dma) { 1194 if (!blk_fs_request(rq) && len > 0)
1840 if (dma_error) 1195 ide_cd_pad_transfer(drive, xferfunc, len);
1841 return ide_error(drive, "dma error", stat);
1842 1196
1843 ide_end_request(drive, 1, rq->nr_sectors); 1197 if (blk_pc_request(rq)) {
1844 return ide_stopped; 1198 timeout = rq->timeout;
1199 } else {
1200 timeout = ATAPI_WAIT_PC;
1201 if (!blk_fs_request(rq))
1202 expiry = cdrom_timer_expiry;
1845 } 1203 }
1846 1204
1847 /* Read the interrupt reason and the transfer length. */ 1205 ide_set_handler(drive, cdrom_newpc_intr, timeout, expiry);
1848 ireason = HWIF(drive)->INB(IDE_IREASON_REG) & 0x3; 1206 return ide_started;
1849 lowcyl = HWIF(drive)->INB(IDE_BCOUNTL_REG);
1850 highcyl = HWIF(drive)->INB(IDE_BCOUNTH_REG);
1851 1207
1852 len = lowcyl + (256 * highcyl); 1208end_request:
1209 if (blk_pc_request(rq)) {
1210 unsigned long flags;
1853 1211
1854 /* If DRQ is clear, the command has completed. */ 1212 spin_lock_irqsave(&ide_lock, flags);
1855 if ((stat & DRQ_STAT) == 0) { 1213 if (__blk_end_request(rq, 0, rq->data_len))
1856 /* If we're not done writing, complain. 1214 BUG();
1857 * Otherwise, complete the command normally. 1215 HWGROUP(drive)->rq = NULL;
1858 */ 1216 spin_unlock_irqrestore(&ide_lock, flags);
1859 uptodate = 1; 1217 } else {
1860 if (rq->current_nr_sectors > 0) { 1218 if (!uptodate)
1861 printk(KERN_ERR "%s: %s: data underrun (%d blocks)\n", 1219 rq->cmd_flags |= REQ_FAILED;
1862 drive->name, __FUNCTION__,
1863 rq->current_nr_sectors);
1864 uptodate = 0;
1865 }
1866 cdrom_end_request(drive, uptodate); 1220 cdrom_end_request(drive, uptodate);
1867 return ide_stopped;
1868 } 1221 }
1222 return ide_stopped;
1223}
1869 1224
1870 /* Check that the drive is expecting to do the same thing we are. */ 1225static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1871 if (cdrom_write_check_ireason(drive, len, ireason)) 1226{
1872 return ide_stopped; 1227 struct cdrom_info *cd = drive->driver_data;
1873 1228 int write = rq_data_dir(rq) == WRITE;
1874 sectors_to_transfer = len / SECTOR_SIZE; 1229 unsigned short sectors_per_frame =
1875 1230 queue_hardsect_size(drive->queue) >> SECTOR_BITS;
1876 /*
1877 * now loop and write out the data
1878 */
1879 while (sectors_to_transfer > 0) {
1880 int this_transfer;
1881
1882 if (!rq->current_nr_sectors) {
1883 printk(KERN_ERR "%s: %s: confused, missing data\n",
1884 drive->name, __FUNCTION__);
1885 break;
1886 }
1887 1231
1232 if (write) {
1888 /* 1233 /*
1889 * Figure out how many sectors we can transfer 1234 * disk has become write protected
1890 */ 1235 */
1891 this_transfer = min_t(int, sectors_to_transfer, rq->current_nr_sectors); 1236 if (cd->disk->policy) {
1892 1237 cdrom_end_request(drive, 0);
1893 while (this_transfer > 0) { 1238 return ide_stopped;
1894 HWIF(drive)->atapi_output_bytes(drive, rq->buffer, SECTOR_SIZE);
1895 rq->buffer += SECTOR_SIZE;
1896 --rq->nr_sectors;
1897 --rq->current_nr_sectors;
1898 ++rq->sector;
1899 --this_transfer;
1900 --sectors_to_transfer;
1901 } 1239 }
1902 1240 } else {
1903 /* 1241 /*
1904 * current buffer complete, move on 1242 * We may be retrying this request after an error. Fix up any
1243 * weirdness which might be present in the request packet.
1905 */ 1244 */
1906 if (rq->current_nr_sectors == 0 && rq->nr_sectors) 1245 restore_request(rq);
1907 cdrom_end_request(drive, 1);
1908 }
1909
1910 /* re-arm handler */
1911 ide_set_handler(drive, &cdrom_write_intr, ATAPI_WAIT_PC, NULL);
1912 return ide_started;
1913}
1914
1915static ide_startstop_t cdrom_start_write_cont(ide_drive_t *drive)
1916{
1917 struct request *rq = HWGROUP(drive)->rq;
1918 1246
1919#if 0 /* the immediate bit */ 1247 /* Satisfy whatever we can of this request from our cache. */
1920 rq->cmd[1] = 1 << 3; 1248 if (cdrom_read_from_buffer(drive))
1921#endif 1249 return ide_stopped;
1922 rq->timeout = ATAPI_WAIT_PC; 1250 }
1923
1924 return cdrom_transfer_packet_command(drive, rq, cdrom_write_intr);
1925}
1926
1927static ide_startstop_t cdrom_start_write(ide_drive_t *drive, struct request *rq)
1928{
1929 struct cdrom_info *info = drive->driver_data;
1930 struct gendisk *g = info->disk;
1931 unsigned short sectors_per_frame = queue_hardsect_size(drive->queue) >> SECTOR_BITS;
1932 1251
1933 /* 1252 /*
1934 * writes *must* be hardware frame aligned 1253 * use DMA, if possible / writes *must* be hardware frame aligned
1935 */ 1254 */
1936 if ((rq->nr_sectors & (sectors_per_frame - 1)) || 1255 if ((rq->nr_sectors & (sectors_per_frame - 1)) ||
1937 (rq->sector & (sectors_per_frame - 1))) { 1256 (rq->sector & (sectors_per_frame - 1))) {
1938 cdrom_end_request(drive, 0); 1257 if (write) {
1939 return ide_stopped; 1258 cdrom_end_request(drive, 0);
1940 } 1259 return ide_stopped;
1941 1260 }
1942 /* 1261 cd->dma = 0;
1943 * disk has become write protected 1262 } else
1944 */ 1263 cd->dma = drive->using_dma;
1945 if (g->policy) {
1946 cdrom_end_request(drive, 0);
1947 return ide_stopped;
1948 }
1949
1950 info->nsectors_buffered = 0;
1951 1264
1952 /* use dma, if possible. we don't need to check more, since we 1265 /* Clear the local sector buffer. */
1953 * know that the transfer is always (at least!) frame aligned */ 1266 cd->nsectors_buffered = 0;
1954 info->dma = drive->using_dma ? 1 : 0;
1955 1267
1956 info->devinfo.media_written = 1; 1268 if (write)
1269 cd->devinfo.media_written = 1;
1957 1270
1958 /* Start sending the write request to the drive. */ 1271 /* Start sending the read/write request to the drive. */
1959 return cdrom_start_packet_command(drive, 32768, cdrom_start_write_cont); 1272 return cdrom_start_packet_command(drive, 32768, cdrom_start_rw_cont);
1960} 1273}
1961 1274
1962static ide_startstop_t cdrom_do_newpc_cont(ide_drive_t *drive) 1275static ide_startstop_t cdrom_do_newpc_cont(ide_drive_t *drive)
@@ -1973,7 +1286,10 @@ static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1973{ 1286{
1974 struct cdrom_info *info = drive->driver_data; 1287 struct cdrom_info *info = drive->driver_data;
1975 1288
1976 rq->cmd_flags |= REQ_QUIET; 1289 if (blk_pc_request(rq))
1290 rq->cmd_flags |= REQ_QUIET;
1291 else
1292 rq->cmd_flags &= ~REQ_FAILED;
1977 1293
1978 info->dma = 0; 1294 info->dma = 0;
1979 1295
@@ -2010,7 +1326,7 @@ ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block)
2010 struct cdrom_info *info = drive->driver_data; 1326 struct cdrom_info *info = drive->driver_data;
2011 1327
2012 if (blk_fs_request(rq)) { 1328 if (blk_fs_request(rq)) {
2013 if (CDROM_CONFIG_FLAGS(drive)->seeking) { 1329 if (info->cd_flags & IDE_CD_FLAG_SEEKING) {
2014 unsigned long elapsed = jiffies - info->start_seek; 1330 unsigned long elapsed = jiffies - info->start_seek;
2015 int stat = HWIF(drive)->INB(IDE_STATUS_REG); 1331 int stat = HWIF(drive)->INB(IDE_STATUS_REG);
2016 1332
@@ -2021,22 +1337,16 @@ ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block)
2021 } 1337 }
2022 printk (KERN_ERR "%s: DSC timeout\n", drive->name); 1338 printk (KERN_ERR "%s: DSC timeout\n", drive->name);
2023 } 1339 }
2024 CDROM_CONFIG_FLAGS(drive)->seeking = 0; 1340 info->cd_flags &= ~IDE_CD_FLAG_SEEKING;
2025 } 1341 }
2026 if ((rq_data_dir(rq) == READ) && IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap) { 1342 if ((rq_data_dir(rq) == READ) && IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap) {
2027 action = cdrom_start_seek(drive, block); 1343 action = cdrom_start_seek(drive, block);
2028 } else { 1344 } else
2029 if (rq_data_dir(rq) == READ) 1345 action = cdrom_start_rw(drive, rq);
2030 action = cdrom_start_read(drive, block);
2031 else
2032 action = cdrom_start_write(drive, rq);
2033 }
2034 info->last_block = block; 1346 info->last_block = block;
2035 return action; 1347 return action;
2036 } else if (rq->cmd_type == REQ_TYPE_SENSE || 1348 } else if (blk_sense_request(rq) || blk_pc_request(rq) ||
2037 rq->cmd_type == REQ_TYPE_ATA_PC) { 1349 rq->cmd_type == REQ_TYPE_ATA_PC) {
2038 return cdrom_do_packet_command(drive);
2039 } else if (blk_pc_request(rq)) {
2040 return cdrom_do_block_pc(drive, rq); 1350 return cdrom_do_block_pc(drive, rq);
2041 } else if (blk_special_request(rq)) { 1351 } else if (blk_special_request(rq)) {
2042 /* 1352 /*
@@ -2063,141 +1373,33 @@ ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block)
2063 * can also be NULL, in which case no sense information is returned. 1373 * can also be NULL, in which case no sense information is returned.
2064 */ 1374 */
2065 1375
2066#if ! STANDARD_ATAPI
2067static inline
2068int bin2bcd (int x)
2069{
2070 return (x%10) | ((x/10) << 4);
2071}
2072
2073
2074static inline
2075int bcd2bin (int x)
2076{
2077 return (x >> 4) * 10 + (x & 0x0f);
2078}
2079
2080static 1376static
2081void msf_from_bcd (struct atapi_msf *msf) 1377void msf_from_bcd (struct atapi_msf *msf)
2082{ 1378{
2083 msf->minute = bcd2bin (msf->minute); 1379 msf->minute = BCD2BIN(msf->minute);
2084 msf->second = bcd2bin (msf->second); 1380 msf->second = BCD2BIN(msf->second);
2085 msf->frame = bcd2bin (msf->frame); 1381 msf->frame = BCD2BIN(msf->frame);
2086}
2087
2088#endif /* not STANDARD_ATAPI */
2089
2090
2091static inline
2092void lba_to_msf (int lba, byte *m, byte *s, byte *f)
2093{
2094 lba += CD_MSF_OFFSET;
2095 lba &= 0xffffff; /* negative lbas use only 24 bits */
2096 *m = lba / (CD_SECS * CD_FRAMES);
2097 lba %= (CD_SECS * CD_FRAMES);
2098 *s = lba / CD_FRAMES;
2099 *f = lba % CD_FRAMES;
2100}
2101
2102
2103static inline
2104int msf_to_lba (byte m, byte s, byte f)
2105{
2106 return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
2107} 1382}
2108 1383
2109static int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense) 1384int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense)
2110{ 1385{
2111 struct request req; 1386 struct request req;
2112 struct cdrom_info *info = drive->driver_data; 1387 struct cdrom_info *info = drive->driver_data;
2113 struct cdrom_device_info *cdi = &info->devinfo; 1388 struct cdrom_device_info *cdi = &info->devinfo;
2114 1389
2115 cdrom_prepare_request(drive, &req); 1390 ide_cd_init_rq(drive, &req);
2116 1391
2117 req.sense = sense; 1392 req.sense = sense;
2118 req.cmd[0] = GPCMD_TEST_UNIT_READY; 1393 req.cmd[0] = GPCMD_TEST_UNIT_READY;
2119 req.cmd_flags |= REQ_QUIET; 1394 req.cmd_flags |= REQ_QUIET;
2120 1395
2121#if ! STANDARD_ATAPI 1396 /*
2122 /* the Sanyo 3 CD changer uses byte 7 of TEST_UNIT_READY to 1397 * Sanyo 3 CD changer uses byte 7 of TEST_UNIT_READY to
2123 switch CDs instead of supporting the LOAD_UNLOAD opcode */ 1398 * switch CDs instead of supporting the LOAD_UNLOAD opcode.
2124 1399 */
2125 req.cmd[7] = cdi->sanyo_slot % 3; 1400 req.cmd[7] = cdi->sanyo_slot % 3;
2126#endif /* not STANDARD_ATAPI */
2127
2128 return cdrom_queue_packet_command(drive, &req);
2129}
2130
2131
2132/* Lock the door if LOCKFLAG is nonzero; unlock it otherwise. */
2133static int
2134cdrom_lockdoor(ide_drive_t *drive, int lockflag, struct request_sense *sense)
2135{
2136 struct request_sense my_sense;
2137 struct request req;
2138 int stat;
2139
2140 if (sense == NULL)
2141 sense = &my_sense;
2142
2143 /* If the drive cannot lock the door, just pretend. */
2144 if (CDROM_CONFIG_FLAGS(drive)->no_doorlock) {
2145 stat = 0;
2146 } else {
2147 cdrom_prepare_request(drive, &req);
2148 req.sense = sense;
2149 req.cmd[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
2150 req.cmd[4] = lockflag ? 1 : 0;
2151 stat = cdrom_queue_packet_command(drive, &req);
2152 }
2153
2154 /* If we got an illegal field error, the drive
2155 probably cannot lock the door. */
2156 if (stat != 0 &&
2157 sense->sense_key == ILLEGAL_REQUEST &&
2158 (sense->asc == 0x24 || sense->asc == 0x20)) {
2159 printk (KERN_ERR "%s: door locking not supported\n",
2160 drive->name);
2161 CDROM_CONFIG_FLAGS(drive)->no_doorlock = 1;
2162 stat = 0;
2163 }
2164
2165 /* no medium, that's alright. */
2166 if (stat != 0 && sense->sense_key == NOT_READY && sense->asc == 0x3a)
2167 stat = 0;
2168
2169 if (stat == 0)
2170 CDROM_STATE_FLAGS(drive)->door_locked = lockflag;
2171
2172 return stat;
2173}
2174 1401
2175 1402 return ide_cd_queue_pc(drive, &req);
2176/* Eject the disk if EJECTFLAG is 0.
2177 If EJECTFLAG is 1, try to reload the disk. */
2178static int cdrom_eject(ide_drive_t *drive, int ejectflag,
2179 struct request_sense *sense)
2180{
2181 struct request req;
2182 char loej = 0x02;
2183
2184 if (CDROM_CONFIG_FLAGS(drive)->no_eject && !ejectflag)
2185 return -EDRIVE_CANT_DO_THIS;
2186
2187 /* reload fails on some drives, if the tray is locked */
2188 if (CDROM_STATE_FLAGS(drive)->door_locked && ejectflag)
2189 return 0;
2190
2191 cdrom_prepare_request(drive, &req);
2192
2193 /* only tell drive to close tray if open, if it can do that */
2194 if (ejectflag && !CDROM_CONFIG_FLAGS(drive)->close_tray)
2195 loej = 0;
2196
2197 req.sense = sense;
2198 req.cmd[0] = GPCMD_START_STOP_UNIT;
2199 req.cmd[4] = loej | (ejectflag != 0);
2200 return cdrom_queue_packet_command(drive, &req);
2201} 1403}
2202 1404
2203static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity, 1405static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
@@ -2212,7 +1414,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
2212 int stat; 1414 int stat;
2213 struct request req; 1415 struct request req;
2214 1416
2215 cdrom_prepare_request(drive, &req); 1417 ide_cd_init_rq(drive, &req);
2216 1418
2217 req.sense = sense; 1419 req.sense = sense;
2218 req.cmd[0] = GPCMD_READ_CDVD_CAPACITY; 1420 req.cmd[0] = GPCMD_READ_CDVD_CAPACITY;
@@ -2220,7 +1422,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
2220 req.data_len = sizeof(capbuf); 1422 req.data_len = sizeof(capbuf);
2221 req.cmd_flags |= REQ_QUIET; 1423 req.cmd_flags |= REQ_QUIET;
2222 1424
2223 stat = cdrom_queue_packet_command(drive, &req); 1425 stat = ide_cd_queue_pc(drive, &req);
2224 if (stat == 0) { 1426 if (stat == 0) {
2225 *capacity = 1 + be32_to_cpu(capbuf.lba); 1427 *capacity = 1 + be32_to_cpu(capbuf.lba);
2226 *sectors_per_frame = 1428 *sectors_per_frame =
@@ -2236,7 +1438,7 @@ static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag,
2236{ 1438{
2237 struct request req; 1439 struct request req;
2238 1440
2239 cdrom_prepare_request(drive, &req); 1441 ide_cd_init_rq(drive, &req);
2240 1442
2241 req.sense = sense; 1443 req.sense = sense;
2242 req.data = buf; 1444 req.data = buf;
@@ -2251,12 +1453,11 @@ static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag,
2251 if (msf_flag) 1453 if (msf_flag)
2252 req.cmd[1] = 2; 1454 req.cmd[1] = 2;
2253 1455
2254 return cdrom_queue_packet_command(drive, &req); 1456 return ide_cd_queue_pc(drive, &req);
2255} 1457}
2256 1458
2257
2258/* Try to read the entire TOC for the disk into our internal buffer. */ 1459/* Try to read the entire TOC for the disk into our internal buffer. */
2259static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense) 1460int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
2260{ 1461{
2261 int stat, ntracks, i; 1462 int stat, ntracks, i;
2262 struct cdrom_info *info = drive->driver_data; 1463 struct cdrom_info *info = drive->driver_data;
@@ -2283,7 +1484,7 @@ static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense)
2283 If it is, just return. */ 1484 If it is, just return. */
2284 (void) cdrom_check_status(drive, sense); 1485 (void) cdrom_check_status(drive, sense);
2285 1486
2286 if (CDROM_STATE_FLAGS(drive)->toc_valid) 1487 if (info->cd_flags & IDE_CD_FLAG_TOC_VALID)
2287 return 0; 1488 return 0;
2288 1489
2289 /* Try to get the total cdrom capacity and sector size. */ 1490 /* Try to get the total cdrom capacity and sector size. */
@@ -2305,12 +1506,10 @@ static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense)
2305 if (stat) 1506 if (stat)
2306 return stat; 1507 return stat;
2307 1508
2308#if ! STANDARD_ATAPI 1509 if (info->cd_flags & IDE_CD_FLAG_TOCTRACKS_AS_BCD) {
2309 if (CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd) { 1510 toc->hdr.first_track = BCD2BIN(toc->hdr.first_track);
2310 toc->hdr.first_track = bcd2bin(toc->hdr.first_track); 1511 toc->hdr.last_track = BCD2BIN(toc->hdr.last_track);
2311 toc->hdr.last_track = bcd2bin(toc->hdr.last_track);
2312 } 1512 }
2313#endif /* not STANDARD_ATAPI */
2314 1513
2315 ntracks = toc->hdr.last_track - toc->hdr.first_track + 1; 1514 ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
2316 if (ntracks <= 0) 1515 if (ntracks <= 0)
@@ -2342,16 +1541,13 @@ static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense)
2342 (ntracks + 1) * 1541 (ntracks + 1) *
2343 sizeof(struct atapi_toc_entry), 1542 sizeof(struct atapi_toc_entry),
2344 sense); 1543 sense);
2345 if (stat) { 1544 if (stat)
2346 return stat; 1545 return stat;
2347 } 1546
2348#if ! STANDARD_ATAPI 1547 if (info->cd_flags & IDE_CD_FLAG_TOCTRACKS_AS_BCD) {
2349 if (CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd) { 1548 toc->hdr.first_track = (u8)BIN2BCD(CDROM_LEADOUT);
2350 toc->hdr.first_track = bin2bcd(CDROM_LEADOUT); 1549 toc->hdr.last_track = (u8)BIN2BCD(CDROM_LEADOUT);
2351 toc->hdr.last_track = bin2bcd(CDROM_LEADOUT); 1550 } else {
2352 } else
2353#endif /* not STANDARD_ATAPI */
2354 {
2355 toc->hdr.first_track = CDROM_LEADOUT; 1551 toc->hdr.first_track = CDROM_LEADOUT;
2356 toc->hdr.last_track = CDROM_LEADOUT; 1552 toc->hdr.last_track = CDROM_LEADOUT;
2357 } 1553 }
@@ -2362,21 +1558,17 @@ static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense)
2362 1558
2363 toc->hdr.toc_length = ntohs (toc->hdr.toc_length); 1559 toc->hdr.toc_length = ntohs (toc->hdr.toc_length);
2364 1560
2365#if ! STANDARD_ATAPI 1561 if (info->cd_flags & IDE_CD_FLAG_TOCTRACKS_AS_BCD) {
2366 if (CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd) { 1562 toc->hdr.first_track = BCD2BIN(toc->hdr.first_track);
2367 toc->hdr.first_track = bcd2bin(toc->hdr.first_track); 1563 toc->hdr.last_track = BCD2BIN(toc->hdr.last_track);
2368 toc->hdr.last_track = bcd2bin(toc->hdr.last_track);
2369 } 1564 }
2370#endif /* not STANDARD_ATAPI */
2371 1565
2372 for (i=0; i<=ntracks; i++) { 1566 for (i = 0; i <= ntracks; i++) {
2373#if ! STANDARD_ATAPI 1567 if (info->cd_flags & IDE_CD_FLAG_TOCADDR_AS_BCD) {
2374 if (CDROM_CONFIG_FLAGS(drive)->tocaddr_as_bcd) { 1568 if (info->cd_flags & IDE_CD_FLAG_TOCTRACKS_AS_BCD)
2375 if (CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd) 1569 toc->ent[i].track = BCD2BIN(toc->ent[i].track);
2376 toc->ent[i].track = bcd2bin(toc->ent[i].track);
2377 msf_from_bcd(&toc->ent[i].addr.msf); 1570 msf_from_bcd(&toc->ent[i].addr.msf);
2378 } 1571 }
2379#endif /* not STANDARD_ATAPI */
2380 toc->ent[i].addr.lba = msf_to_lba (toc->ent[i].addr.msf.minute, 1572 toc->ent[i].addr.lba = msf_to_lba (toc->ent[i].addr.msf.minute,
2381 toc->ent[i].addr.msf.second, 1573 toc->ent[i].addr.msf.second,
2382 toc->ent[i].addr.msf.frame); 1574 toc->ent[i].addr.msf.frame);
@@ -2396,8 +1588,7 @@ static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense)
2396 toc->last_session_lba = msf_to_lba(0, 2, 0); /* 0m 2s 0f */ 1588 toc->last_session_lba = msf_to_lba(0, 2, 0); /* 0m 2s 0f */
2397 } 1589 }
2398 1590
2399#if ! STANDARD_ATAPI 1591 if (info->cd_flags & IDE_CD_FLAG_TOCADDR_AS_BCD) {
2400 if (CDROM_CONFIG_FLAGS(drive)->tocaddr_as_bcd) {
2401 /* Re-read multisession information using MSF format */ 1592 /* Re-read multisession information using MSF format */
2402 stat = cdrom_read_tocentry(drive, 0, 1, 1, (char *)&ms_tmp, 1593 stat = cdrom_read_tocentry(drive, 0, 1, 1, (char *)&ms_tmp,
2403 sizeof(ms_tmp), sense); 1594 sizeof(ms_tmp), sense);
@@ -2409,7 +1600,6 @@ static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense)
2409 ms_tmp.ent.addr.msf.second, 1600 ms_tmp.ent.addr.msf.second,
2410 ms_tmp.ent.addr.msf.frame); 1601 ms_tmp.ent.addr.msf.frame);
2411 } 1602 }
2412#endif /* not STANDARD_ATAPI */
2413 1603
2414 toc->xa_flag = (ms_tmp.hdr.first_track != ms_tmp.hdr.last_track); 1604 toc->xa_flag = (ms_tmp.hdr.first_track != ms_tmp.hdr.last_track);
2415 1605
@@ -2422,278 +1612,22 @@ static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense)
2422 } 1612 }
2423 1613
2424 /* Remember that we've read this stuff. */ 1614 /* Remember that we've read this stuff. */
2425 CDROM_STATE_FLAGS(drive)->toc_valid = 1; 1615 info->cd_flags |= IDE_CD_FLAG_TOC_VALID;
2426 1616
2427 return 0; 1617 return 0;
2428} 1618}
2429 1619
2430 1620int ide_cdrom_get_capabilities(ide_drive_t *drive, u8 *buf)
2431static int cdrom_read_subchannel(ide_drive_t *drive, int format, char *buf,
2432 int buflen, struct request_sense *sense)
2433{
2434 struct request req;
2435
2436 cdrom_prepare_request(drive, &req);
2437
2438 req.sense = sense;
2439 req.data = buf;
2440 req.data_len = buflen;
2441 req.cmd[0] = GPCMD_READ_SUBCHANNEL;
2442 req.cmd[1] = 2; /* MSF addressing */
2443 req.cmd[2] = 0x40; /* request subQ data */
2444 req.cmd[3] = format;
2445 req.cmd[7] = (buflen >> 8);
2446 req.cmd[8] = (buflen & 0xff);
2447 return cdrom_queue_packet_command(drive, &req);
2448}
2449
2450/* ATAPI cdrom drives are free to select the speed you request or any slower
2451 rate :-( Requesting too fast a speed will _not_ produce an error. */
2452static int cdrom_select_speed(ide_drive_t *drive, int speed,
2453 struct request_sense *sense)
2454{
2455 struct request req;
2456 cdrom_prepare_request(drive, &req);
2457
2458 req.sense = sense;
2459 if (speed == 0)
2460 speed = 0xffff; /* set to max */
2461 else
2462 speed *= 177; /* Nx to kbytes/s */
2463
2464 req.cmd[0] = GPCMD_SET_SPEED;
2465 /* Read Drive speed in kbytes/second MSB */
2466 req.cmd[2] = (speed >> 8) & 0xff;
2467 /* Read Drive speed in kbytes/second LSB */
2468 req.cmd[3] = speed & 0xff;
2469 if (CDROM_CONFIG_FLAGS(drive)->cd_r ||
2470 CDROM_CONFIG_FLAGS(drive)->cd_rw ||
2471 CDROM_CONFIG_FLAGS(drive)->dvd_r) {
2472 /* Write Drive speed in kbytes/second MSB */
2473 req.cmd[4] = (speed >> 8) & 0xff;
2474 /* Write Drive speed in kbytes/second LSB */
2475 req.cmd[5] = speed & 0xff;
2476 }
2477
2478 return cdrom_queue_packet_command(drive, &req);
2479}
2480
2481static int cdrom_play_audio(ide_drive_t *drive, int lba_start, int lba_end)
2482{
2483 struct request_sense sense;
2484 struct request req;
2485
2486 cdrom_prepare_request(drive, &req);
2487
2488 req.sense = &sense;
2489 req.cmd[0] = GPCMD_PLAY_AUDIO_MSF;
2490 lba_to_msf(lba_start, &req.cmd[3], &req.cmd[4], &req.cmd[5]);
2491 lba_to_msf(lba_end-1, &req.cmd[6], &req.cmd[7], &req.cmd[8]);
2492
2493 return cdrom_queue_packet_command(drive, &req);
2494}
2495
2496static int cdrom_get_toc_entry(ide_drive_t *drive, int track,
2497 struct atapi_toc_entry **ent)
2498{
2499 struct cdrom_info *info = drive->driver_data;
2500 struct atapi_toc *toc = info->toc;
2501 int ntracks;
2502
2503 /*
2504 * don't serve cached data, if the toc isn't valid
2505 */
2506 if (!CDROM_STATE_FLAGS(drive)->toc_valid)
2507 return -EINVAL;
2508
2509 /* Check validity of requested track number. */
2510 ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
2511 if (toc->hdr.first_track == CDROM_LEADOUT) ntracks = 0;
2512 if (track == CDROM_LEADOUT)
2513 *ent = &toc->ent[ntracks];
2514 else if (track < toc->hdr.first_track ||
2515 track > toc->hdr.last_track)
2516 return -EINVAL;
2517 else
2518 *ent = &toc->ent[track - toc->hdr.first_track];
2519
2520 return 0;
2521}
2522
2523/* the generic packet interface to cdrom.c */
2524static int ide_cdrom_packet(struct cdrom_device_info *cdi,
2525 struct packet_command *cgc)
2526{
2527 struct request req;
2528 ide_drive_t *drive = cdi->handle;
2529
2530 if (cgc->timeout <= 0)
2531 cgc->timeout = ATAPI_WAIT_PC;
2532
2533 /* here we queue the commands from the uniform CD-ROM
2534 layer. the packet must be complete, as we do not
2535 touch it at all. */
2536 cdrom_prepare_request(drive, &req);
2537 memcpy(req.cmd, cgc->cmd, CDROM_PACKET_SIZE);
2538 if (cgc->sense)
2539 memset(cgc->sense, 0, sizeof(struct request_sense));
2540 req.data = cgc->buffer;
2541 req.data_len = cgc->buflen;
2542 req.timeout = cgc->timeout;
2543
2544 if (cgc->quiet)
2545 req.cmd_flags |= REQ_QUIET;
2546
2547 req.sense = cgc->sense;
2548 cgc->stat = cdrom_queue_packet_command(drive, &req);
2549 if (!cgc->stat)
2550 cgc->buflen -= req.data_len;
2551 return cgc->stat;
2552}
2553
2554static
2555int ide_cdrom_audio_ioctl (struct cdrom_device_info *cdi,
2556 unsigned int cmd, void *arg)
2557
2558{
2559 ide_drive_t *drive = cdi->handle;
2560 struct cdrom_info *info = drive->driver_data;
2561 int stat;
2562
2563 switch (cmd) {
2564 /*
2565 * emulate PLAY_AUDIO_TI command with PLAY_AUDIO_10, since
2566 * atapi doesn't support it
2567 */
2568 case CDROMPLAYTRKIND: {
2569 unsigned long lba_start, lba_end;
2570 struct cdrom_ti *ti = arg;
2571 struct atapi_toc_entry *first_toc, *last_toc;
2572
2573 stat = cdrom_get_toc_entry(drive, ti->cdti_trk0, &first_toc);
2574 if (stat)
2575 return stat;
2576
2577 stat = cdrom_get_toc_entry(drive, ti->cdti_trk1, &last_toc);
2578 if (stat)
2579 return stat;
2580
2581 if (ti->cdti_trk1 != CDROM_LEADOUT)
2582 ++last_toc;
2583 lba_start = first_toc->addr.lba;
2584 lba_end = last_toc->addr.lba;
2585
2586 if (lba_end <= lba_start)
2587 return -EINVAL;
2588
2589 return cdrom_play_audio(drive, lba_start, lba_end);
2590 }
2591
2592 case CDROMREADTOCHDR: {
2593 struct cdrom_tochdr *tochdr = arg;
2594 struct atapi_toc *toc;
2595
2596 /* Make sure our saved TOC is valid. */
2597 stat = cdrom_read_toc(drive, NULL);
2598 if (stat)
2599 return stat;
2600
2601 toc = info->toc;
2602 tochdr->cdth_trk0 = toc->hdr.first_track;
2603 tochdr->cdth_trk1 = toc->hdr.last_track;
2604
2605 return 0;
2606 }
2607
2608 case CDROMREADTOCENTRY: {
2609 struct cdrom_tocentry *tocentry = arg;
2610 struct atapi_toc_entry *toce;
2611
2612 stat = cdrom_get_toc_entry(drive, tocentry->cdte_track, &toce);
2613 if (stat)
2614 return stat;
2615
2616 tocentry->cdte_ctrl = toce->control;
2617 tocentry->cdte_adr = toce->adr;
2618 if (tocentry->cdte_format == CDROM_MSF) {
2619 lba_to_msf (toce->addr.lba,
2620 &tocentry->cdte_addr.msf.minute,
2621 &tocentry->cdte_addr.msf.second,
2622 &tocentry->cdte_addr.msf.frame);
2623 } else
2624 tocentry->cdte_addr.lba = toce->addr.lba;
2625
2626 return 0;
2627 }
2628
2629 default:
2630 return -EINVAL;
2631 }
2632}
2633
2634static
2635int ide_cdrom_reset (struct cdrom_device_info *cdi)
2636{
2637 ide_drive_t *drive = cdi->handle;
2638 struct request_sense sense;
2639 struct request req;
2640 int ret;
2641
2642 cdrom_prepare_request(drive, &req);
2643 req.cmd_type = REQ_TYPE_SPECIAL;
2644 req.cmd_flags = REQ_QUIET;
2645 ret = ide_do_drive_cmd(drive, &req, ide_wait);
2646
2647 /*
2648 * A reset will unlock the door. If it was previously locked,
2649 * lock it again.
2650 */
2651 if (CDROM_STATE_FLAGS(drive)->door_locked)
2652 (void) cdrom_lockdoor(drive, 1, &sense);
2653
2654 return ret;
2655}
2656
2657
2658static
2659int ide_cdrom_tray_move (struct cdrom_device_info *cdi, int position)
2660{
2661 ide_drive_t *drive = cdi->handle;
2662 struct request_sense sense;
2663
2664 if (position) {
2665 int stat = cdrom_lockdoor(drive, 0, &sense);
2666 if (stat)
2667 return stat;
2668 }
2669
2670 return cdrom_eject(drive, !position, &sense);
2671}
2672
2673static
2674int ide_cdrom_lock_door (struct cdrom_device_info *cdi, int lock)
2675{
2676 ide_drive_t *drive = cdi->handle;
2677 return cdrom_lockdoor(drive, lock, NULL);
2678}
2679
2680static
2681int ide_cdrom_get_capabilities(ide_drive_t *drive, struct atapi_capabilities_page *cap)
2682{ 1621{
2683 struct cdrom_info *info = drive->driver_data; 1622 struct cdrom_info *info = drive->driver_data;
2684 struct cdrom_device_info *cdi = &info->devinfo; 1623 struct cdrom_device_info *cdi = &info->devinfo;
2685 struct packet_command cgc; 1624 struct packet_command cgc;
2686 int stat, attempts = 3, size = sizeof(*cap); 1625 int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE;
2687 1626
2688 /* 1627 if ((info->cd_flags & IDE_CD_FLAG_FULL_CAPS_PAGE) == 0)
2689 * ACER50 (and others?) require the full spec length mode sense 1628 size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE;
2690 * page capabilities size, but older drives break.
2691 */
2692 if (!(!strcmp(drive->id->model, "ATAPI CD ROM DRIVE 50X MAX") ||
2693 !strcmp(drive->id->model, "WPI CDS-32X")))
2694 size -= sizeof(cap->pad);
2695 1629
2696 init_cdrom_command(&cgc, cap, size, CGC_DATA_UNKNOWN); 1630 init_cdrom_command(&cgc, buf, size, CGC_DATA_UNKNOWN);
2697 do { /* we seem to get stat=0x01,err=0x00 the first time (??) */ 1631 do { /* we seem to get stat=0x01,err=0x00 the first time (??) */
2698 stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CAPABILITIES_PAGE, 0); 1632 stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CAPABILITIES_PAGE, 0);
2699 if (!stat) 1633 if (!stat)
@@ -2702,177 +1636,33 @@ int ide_cdrom_get_capabilities(ide_drive_t *drive, struct atapi_capabilities_pag
2702 return stat; 1636 return stat;
2703} 1637}
2704 1638
2705static 1639void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf)
2706void ide_cdrom_update_speed (ide_drive_t *drive, struct atapi_capabilities_page *cap)
2707{
2708 /* The ACER/AOpen 24X cdrom has the speed fields byte-swapped */
2709 if (!drive->id->model[0] &&
2710 !strncmp(drive->id->fw_rev, "241N", 4)) {
2711 CDROM_STATE_FLAGS(drive)->current_speed =
2712 (le16_to_cpu(cap->curspeed) + (176/2)) / 176;
2713 CDROM_CONFIG_FLAGS(drive)->max_speed =
2714 (le16_to_cpu(cap->maxspeed) + (176/2)) / 176;
2715 } else {
2716 CDROM_STATE_FLAGS(drive)->current_speed =
2717 (be16_to_cpu(cap->curspeed) + (176/2)) / 176;
2718 CDROM_CONFIG_FLAGS(drive)->max_speed =
2719 (be16_to_cpu(cap->maxspeed) + (176/2)) / 176;
2720 }
2721}
2722
2723static
2724int ide_cdrom_select_speed (struct cdrom_device_info *cdi, int speed)
2725{
2726 ide_drive_t *drive = cdi->handle;
2727 struct request_sense sense;
2728 struct atapi_capabilities_page cap;
2729 int stat;
2730
2731 if ((stat = cdrom_select_speed(drive, speed, &sense)) < 0)
2732 return stat;
2733
2734 if (!ide_cdrom_get_capabilities(drive, &cap)) {
2735 ide_cdrom_update_speed(drive, &cap);
2736 cdi->speed = CDROM_STATE_FLAGS(drive)->current_speed;
2737 }
2738 return 0;
2739}
2740
2741/*
2742 * add logic to try GET_EVENT command first to check for media and tray
2743 * status. this should be supported by newer cd-r/w and all DVD etc
2744 * drives
2745 */
2746static
2747int ide_cdrom_drive_status (struct cdrom_device_info *cdi, int slot_nr)
2748{
2749 ide_drive_t *drive = cdi->handle;
2750 struct media_event_desc med;
2751 struct request_sense sense;
2752 int stat;
2753
2754 if (slot_nr != CDSL_CURRENT)
2755 return -EINVAL;
2756
2757 stat = cdrom_check_status(drive, &sense);
2758 if (!stat || sense.sense_key == UNIT_ATTENTION)
2759 return CDS_DISC_OK;
2760
2761 if (!cdrom_get_media_event(cdi, &med)) {
2762 if (med.media_present)
2763 return CDS_DISC_OK;
2764 else if (med.door_open)
2765 return CDS_TRAY_OPEN;
2766 else
2767 return CDS_NO_DISC;
2768 }
2769
2770 if (sense.sense_key == NOT_READY && sense.asc == 0x04 && sense.ascq == 0x04)
2771 return CDS_DISC_OK;
2772
2773 /*
2774 * If not using Mt Fuji extended media tray reports,
2775 * just return TRAY_OPEN since ATAPI doesn't provide
2776 * any other way to detect this...
2777 */
2778 if (sense.sense_key == NOT_READY) {
2779 if (sense.asc == 0x3a && sense.ascq == 1)
2780 return CDS_NO_DISC;
2781 else
2782 return CDS_TRAY_OPEN;
2783 }
2784 return CDS_DRIVE_NOT_READY;
2785}
2786
2787static
2788int ide_cdrom_get_last_session (struct cdrom_device_info *cdi,
2789 struct cdrom_multisession *ms_info)
2790{ 1640{
2791 struct atapi_toc *toc; 1641 struct cdrom_info *cd = drive->driver_data;
2792 ide_drive_t *drive = cdi->handle; 1642 u16 curspeed, maxspeed;
2793 struct cdrom_info *info = drive->driver_data;
2794 struct request_sense sense;
2795 int ret;
2796
2797 if (!CDROM_STATE_FLAGS(drive)->toc_valid || info->toc == NULL)
2798 if ((ret = cdrom_read_toc(drive, &sense)))
2799 return ret;
2800
2801 toc = info->toc;
2802 ms_info->addr.lba = toc->last_session_lba;
2803 ms_info->xa_flag = toc->xa_flag;
2804
2805 return 0;
2806}
2807
2808static
2809int ide_cdrom_get_mcn (struct cdrom_device_info *cdi,
2810 struct cdrom_mcn *mcn_info)
2811{
2812 int stat;
2813 char mcnbuf[24];
2814 ide_drive_t *drive = cdi->handle;
2815
2816/* get MCN */
2817 if ((stat = cdrom_read_subchannel(drive, 2, mcnbuf, sizeof (mcnbuf), NULL)))
2818 return stat;
2819
2820 memcpy (mcn_info->medium_catalog_number, mcnbuf+9,
2821 sizeof (mcn_info->medium_catalog_number)-1);
2822 mcn_info->medium_catalog_number[sizeof (mcn_info->medium_catalog_number)-1]
2823 = '\0';
2824
2825 return 0;
2826}
2827
2828
2829 1643
2830/**************************************************************************** 1644 curspeed = *(u16 *)&buf[8 + 14];
2831 * Other driver requests (open, close, check media change). 1645 maxspeed = *(u16 *)&buf[8 + 8];
2832 */
2833 1646
2834static 1647 if (cd->cd_flags & IDE_CD_FLAG_LE_SPEED_FIELDS) {
2835int ide_cdrom_check_media_change_real (struct cdrom_device_info *cdi, 1648 curspeed = le16_to_cpu(curspeed);
2836 int slot_nr) 1649 maxspeed = le16_to_cpu(maxspeed);
2837{
2838 ide_drive_t *drive = cdi->handle;
2839 int retval;
2840
2841 if (slot_nr == CDSL_CURRENT) {
2842 (void) cdrom_check_status(drive, NULL);
2843 retval = CDROM_STATE_FLAGS(drive)->media_changed;
2844 CDROM_STATE_FLAGS(drive)->media_changed = 0;
2845 return retval;
2846 } else { 1650 } else {
2847 return -EINVAL; 1651 curspeed = be16_to_cpu(curspeed);
1652 maxspeed = be16_to_cpu(maxspeed);
2848 } 1653 }
2849}
2850
2851 1654
2852static 1655 cd->current_speed = (curspeed + (176/2)) / 176;
2853int ide_cdrom_open_real (struct cdrom_device_info *cdi, int purpose) 1656 cd->max_speed = (maxspeed + (176/2)) / 176;
2854{
2855 return 0;
2856} 1657}
2857 1658
2858/* 1659#define IDE_CD_CAPABILITIES \
2859 * Close down the device. Invalidate all cached blocks. 1660 (CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | CDC_SELECT_SPEED | \
2860 */ 1661 CDC_SELECT_DISC | CDC_MULTI_SESSION | CDC_MCN | CDC_MEDIA_CHANGED | \
2861 1662 CDC_PLAY_AUDIO | CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R | \
2862static 1663 CDC_CD_RW | CDC_DVD | CDC_DVD_R | CDC_DVD_RAM | CDC_GENERIC_PACKET | \
2863void ide_cdrom_release_real (struct cdrom_device_info *cdi) 1664 CDC_MO_DRIVE | CDC_MRW | CDC_MRW_W | CDC_RAM)
2864{
2865 ide_drive_t *drive = cdi->handle;
2866
2867 if (!cdi->use_count)
2868 CDROM_STATE_FLAGS(drive)->toc_valid = 0;
2869}
2870 1665
2871
2872
2873/****************************************************************************
2874 * Device initialization.
2875 */
2876static struct cdrom_device_ops ide_cdrom_dops = { 1666static struct cdrom_device_ops ide_cdrom_dops = {
2877 .open = ide_cdrom_open_real, 1667 .open = ide_cdrom_open_real,
2878 .release = ide_cdrom_release_real, 1668 .release = ide_cdrom_release_real,
@@ -2885,14 +1675,7 @@ static struct cdrom_device_ops ide_cdrom_dops = {
2885 .get_mcn = ide_cdrom_get_mcn, 1675 .get_mcn = ide_cdrom_get_mcn,
2886 .reset = ide_cdrom_reset, 1676 .reset = ide_cdrom_reset,
2887 .audio_ioctl = ide_cdrom_audio_ioctl, 1677 .audio_ioctl = ide_cdrom_audio_ioctl,
2888 .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | 1678 .capability = IDE_CD_CAPABILITIES,
2889 CDC_SELECT_SPEED | CDC_SELECT_DISC |
2890 CDC_MULTI_SESSION | CDC_MCN |
2891 CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO | CDC_RESET |
2892 CDC_DRIVE_STATUS | CDC_CD_R |
2893 CDC_CD_RW | CDC_DVD | CDC_DVD_R| CDC_DVD_RAM |
2894 CDC_GENERIC_PACKET | CDC_MO_DRIVE | CDC_MRW |
2895 CDC_MRW_W | CDC_RAM,
2896 .generic_packet = ide_cdrom_packet, 1679 .generic_packet = ide_cdrom_packet,
2897}; 1680};
2898 1681
@@ -2902,35 +1685,12 @@ static int ide_cdrom_register (ide_drive_t *drive, int nslots)
2902 struct cdrom_device_info *devinfo = &info->devinfo; 1685 struct cdrom_device_info *devinfo = &info->devinfo;
2903 1686
2904 devinfo->ops = &ide_cdrom_dops; 1687 devinfo->ops = &ide_cdrom_dops;
2905 devinfo->mask = 0; 1688 devinfo->speed = info->current_speed;
2906 devinfo->speed = CDROM_STATE_FLAGS(drive)->current_speed;
2907 devinfo->capacity = nslots; 1689 devinfo->capacity = nslots;
2908 devinfo->handle = drive; 1690 devinfo->handle = drive;
2909 strcpy(devinfo->name, drive->name); 1691 strcpy(devinfo->name, drive->name);
2910 1692
2911 /* set capability mask to match the probe. */ 1693 if (info->cd_flags & IDE_CD_FLAG_NO_SPEED_SELECT)
2912 if (!CDROM_CONFIG_FLAGS(drive)->cd_r)
2913 devinfo->mask |= CDC_CD_R;
2914 if (!CDROM_CONFIG_FLAGS(drive)->cd_rw)
2915 devinfo->mask |= CDC_CD_RW;
2916 if (!CDROM_CONFIG_FLAGS(drive)->dvd)
2917 devinfo->mask |= CDC_DVD;
2918 if (!CDROM_CONFIG_FLAGS(drive)->dvd_r)
2919 devinfo->mask |= CDC_DVD_R;
2920 if (!CDROM_CONFIG_FLAGS(drive)->dvd_ram)
2921 devinfo->mask |= CDC_DVD_RAM;
2922 if (!CDROM_CONFIG_FLAGS(drive)->is_changer)
2923 devinfo->mask |= CDC_SELECT_DISC;
2924 if (!CDROM_CONFIG_FLAGS(drive)->audio_play)
2925 devinfo->mask |= CDC_PLAY_AUDIO;
2926 if (!CDROM_CONFIG_FLAGS(drive)->close_tray)
2927 devinfo->mask |= CDC_CLOSE_TRAY;
2928 if (!CDROM_CONFIG_FLAGS(drive)->mo_drive)
2929 devinfo->mask |= CDC_MO_DRIVE;
2930 if (!CDROM_CONFIG_FLAGS(drive)->ram)
2931 devinfo->mask |= CDC_RAM;
2932
2933 if (CDROM_CONFIG_FLAGS(drive)->no_speed_select)
2934 devinfo->mask |= CDC_SELECT_SPEED; 1694 devinfo->mask |= CDC_SELECT_SPEED;
2935 1695
2936 devinfo->disk = info->disk; 1696 devinfo->disk = info->disk;
@@ -2940,22 +1700,25 @@ static int ide_cdrom_register (ide_drive_t *drive, int nslots)
2940static 1700static
2941int ide_cdrom_probe_capabilities (ide_drive_t *drive) 1701int ide_cdrom_probe_capabilities (ide_drive_t *drive)
2942{ 1702{
2943 struct cdrom_info *info = drive->driver_data; 1703 struct cdrom_info *cd = drive->driver_data;
2944 struct cdrom_device_info *cdi = &info->devinfo; 1704 struct cdrom_device_info *cdi = &cd->devinfo;
2945 struct atapi_capabilities_page cap; 1705 u8 buf[ATAPI_CAPABILITIES_PAGE_SIZE];
1706 mechtype_t mechtype;
2946 int nslots = 1; 1707 int nslots = 1;
2947 1708
1709 cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R |
1710 CDC_DVD_RAM | CDC_SELECT_DISC | CDC_PLAY_AUDIO |
1711 CDC_MO_DRIVE | CDC_RAM);
1712
2948 if (drive->media == ide_optical) { 1713 if (drive->media == ide_optical) {
2949 CDROM_CONFIG_FLAGS(drive)->mo_drive = 1; 1714 cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM);
2950 CDROM_CONFIG_FLAGS(drive)->ram = 1;
2951 printk(KERN_ERR "%s: ATAPI magneto-optical drive\n", drive->name); 1715 printk(KERN_ERR "%s: ATAPI magneto-optical drive\n", drive->name);
2952 return nslots; 1716 return nslots;
2953 } 1717 }
2954 1718
2955 if (CDROM_CONFIG_FLAGS(drive)->nec260 || 1719 if (cd->cd_flags & IDE_CD_FLAG_PRE_ATAPI12) {
2956 !strcmp(drive->id->model,"STINGRAY 8422 IDE 8X CD-ROM 7-27-95")) { 1720 cd->cd_flags &= ~IDE_CD_FLAG_NO_EJECT;
2957 CDROM_CONFIG_FLAGS(drive)->no_eject = 0; 1721 cdi->mask &= ~CDC_PLAY_AUDIO;
2958 CDROM_CONFIG_FLAGS(drive)->audio_play = 1;
2959 return nslots; 1722 return nslots;
2960 } 1723 }
2961 1724
@@ -2969,83 +1732,66 @@ int ide_cdrom_probe_capabilities (ide_drive_t *drive)
2969 cdi->handle = drive; 1732 cdi->handle = drive;
2970 cdi->ops = &ide_cdrom_dops; 1733 cdi->ops = &ide_cdrom_dops;
2971 1734
2972 if (ide_cdrom_get_capabilities(drive, &cap)) 1735 if (ide_cdrom_get_capabilities(drive, buf))
2973 return 0; 1736 return 0;
2974 1737
2975 if (cap.lock == 0) 1738 if ((buf[8 + 6] & 0x01) == 0)
2976 CDROM_CONFIG_FLAGS(drive)->no_doorlock = 1; 1739 cd->cd_flags |= IDE_CD_FLAG_NO_DOORLOCK;
2977 if (cap.eject) 1740 if (buf[8 + 6] & 0x08)
2978 CDROM_CONFIG_FLAGS(drive)->no_eject = 0; 1741 cd->cd_flags &= ~IDE_CD_FLAG_NO_EJECT;
2979 if (cap.cd_r_write) 1742 if (buf[8 + 3] & 0x01)
2980 CDROM_CONFIG_FLAGS(drive)->cd_r = 1; 1743 cdi->mask &= ~CDC_CD_R;
2981 if (cap.cd_rw_write) { 1744 if (buf[8 + 3] & 0x02)
2982 CDROM_CONFIG_FLAGS(drive)->cd_rw = 1; 1745 cdi->mask &= ~(CDC_CD_RW | CDC_RAM);
2983 CDROM_CONFIG_FLAGS(drive)->ram = 1; 1746 if (buf[8 + 2] & 0x38)
2984 } 1747 cdi->mask &= ~CDC_DVD;
2985 if (cap.test_write) 1748 if (buf[8 + 3] & 0x20)
2986 CDROM_CONFIG_FLAGS(drive)->test_write = 1; 1749 cdi->mask &= ~(CDC_DVD_RAM | CDC_RAM);
2987 if (cap.dvd_ram_read || cap.dvd_r_read || cap.dvd_rom) 1750 if (buf[8 + 3] & 0x10)
2988 CDROM_CONFIG_FLAGS(drive)->dvd = 1; 1751 cdi->mask &= ~CDC_DVD_R;
2989 if (cap.dvd_ram_write) { 1752 if ((buf[8 + 4] & 0x01) || (cd->cd_flags & IDE_CD_FLAG_PLAY_AUDIO_OK))
2990 CDROM_CONFIG_FLAGS(drive)->dvd_ram = 1; 1753 cdi->mask &= ~CDC_PLAY_AUDIO;
2991 CDROM_CONFIG_FLAGS(drive)->ram = 1; 1754
2992 } 1755 mechtype = buf[8 + 6] >> 5;
2993 if (cap.dvd_r_write) 1756 if (mechtype == mechtype_caddy || mechtype == mechtype_popup)
2994 CDROM_CONFIG_FLAGS(drive)->dvd_r = 1; 1757 cdi->mask |= CDC_CLOSE_TRAY;
2995 if (cap.audio_play)
2996 CDROM_CONFIG_FLAGS(drive)->audio_play = 1;
2997 if (cap.mechtype == mechtype_caddy || cap.mechtype == mechtype_popup)
2998 CDROM_CONFIG_FLAGS(drive)->close_tray = 0;
2999
3000 /* Some drives used by Apple don't advertise audio play
3001 * but they do support reading TOC & audio datas
3002 */
3003 if (strcmp(drive->id->model, "MATSHITADVD-ROM SR-8187") == 0 ||
3004 strcmp(drive->id->model, "MATSHITADVD-ROM SR-8186") == 0 ||
3005 strcmp(drive->id->model, "MATSHITADVD-ROM SR-8176") == 0 ||
3006 strcmp(drive->id->model, "MATSHITADVD-ROM SR-8174") == 0)
3007 CDROM_CONFIG_FLAGS(drive)->audio_play = 1;
3008 1758
3009#if ! STANDARD_ATAPI
3010 if (cdi->sanyo_slot > 0) { 1759 if (cdi->sanyo_slot > 0) {
3011 CDROM_CONFIG_FLAGS(drive)->is_changer = 1; 1760 cdi->mask &= ~CDC_SELECT_DISC;
3012 nslots = 3; 1761 nslots = 3;
1762 } else if (mechtype == mechtype_individual_changer ||
1763 mechtype == mechtype_cartridge_changer) {
1764 nslots = cdrom_number_of_slots(cdi);
1765 if (nslots > 1)
1766 cdi->mask &= ~CDC_SELECT_DISC;
3013 } 1767 }
3014 1768
3015 else 1769 ide_cdrom_update_speed(drive, buf);
3016#endif /* not STANDARD_ATAPI */
3017 if (cap.mechtype == mechtype_individual_changer ||
3018 cap.mechtype == mechtype_cartridge_changer) {
3019 if ((nslots = cdrom_number_of_slots(cdi)) > 1) {
3020 CDROM_CONFIG_FLAGS(drive)->is_changer = 1;
3021 CDROM_CONFIG_FLAGS(drive)->supp_disc_present = 1;
3022 }
3023 }
3024 1770
3025 ide_cdrom_update_speed(drive, &cap);
3026 /* don't print speed if the drive reported 0.
3027 */
3028 printk(KERN_INFO "%s: ATAPI", drive->name); 1771 printk(KERN_INFO "%s: ATAPI", drive->name);
3029 if (CDROM_CONFIG_FLAGS(drive)->max_speed)
3030 printk(" %dX", CDROM_CONFIG_FLAGS(drive)->max_speed);
3031 printk(" %s", CDROM_CONFIG_FLAGS(drive)->dvd ? "DVD-ROM" : "CD-ROM");
3032 1772
3033 if (CDROM_CONFIG_FLAGS(drive)->dvd_r|CDROM_CONFIG_FLAGS(drive)->dvd_ram) 1773 /* don't print speed if the drive reported 0 */
3034 printk(" DVD%s%s", 1774 if (cd->max_speed)
3035 (CDROM_CONFIG_FLAGS(drive)->dvd_r)? "-R" : "", 1775 printk(KERN_CONT " %dX", cd->max_speed);
3036 (CDROM_CONFIG_FLAGS(drive)->dvd_ram)? "-RAM" : "");
3037 1776
3038 if (CDROM_CONFIG_FLAGS(drive)->cd_r|CDROM_CONFIG_FLAGS(drive)->cd_rw) 1777 printk(KERN_CONT " %s", (cdi->mask & CDC_DVD) ? "CD-ROM" : "DVD-ROM");
3039 printk(" CD%s%s",
3040 (CDROM_CONFIG_FLAGS(drive)->cd_r)? "-R" : "",
3041 (CDROM_CONFIG_FLAGS(drive)->cd_rw)? "/RW" : "");
3042 1778
3043 if (CDROM_CONFIG_FLAGS(drive)->is_changer) 1779 if ((cdi->mask & CDC_DVD_R) == 0 || (cdi->mask & CDC_DVD_RAM) == 0)
3044 printk(" changer w/%d slots", nslots); 1780 printk(KERN_CONT " DVD%s%s",
3045 else 1781 (cdi->mask & CDC_DVD_R) ? "" : "-R",
3046 printk(" drive"); 1782 (cdi->mask & CDC_DVD_RAM) ? "" : "-RAM");
3047 1783
3048 printk(KERN_CONT ", %dkB Cache\n", be16_to_cpu(cap.buffer_size)); 1784 if ((cdi->mask & CDC_CD_R) == 0 || (cdi->mask & CDC_CD_RW) == 0)
1785 printk(KERN_CONT " CD%s%s",
1786 (cdi->mask & CDC_CD_R) ? "" : "-R",
1787 (cdi->mask & CDC_CD_RW) ? "" : "/RW");
1788
1789 if ((cdi->mask & CDC_SELECT_DISC) == 0)
1790 printk(KERN_CONT " changer w/%d slots", nslots);
1791 else
1792 printk(KERN_CONT " drive");
1793
1794 printk(KERN_CONT ", %dkB Cache\n", be16_to_cpu(*(u16 *)&buf[8 + 12]));
3049 1795
3050 return nslots; 1796 return nslots;
3051} 1797}
@@ -3138,11 +1884,74 @@ static int ide_cdrom_prep_fn(struct request_queue *q, struct request *rq)
3138 return 0; 1884 return 0;
3139} 1885}
3140 1886
1887struct cd_list_entry {
1888 const char *id_model;
1889 const char *id_firmware;
1890 unsigned int cd_flags;
1891};
1892
1893static const struct cd_list_entry ide_cd_quirks_list[] = {
1894 /* Limit transfer size per interrupt. */
1895 { "SAMSUNG CD-ROM SCR-2430", NULL, IDE_CD_FLAG_LIMIT_NFRAMES },
1896 { "SAMSUNG CD-ROM SCR-2432", NULL, IDE_CD_FLAG_LIMIT_NFRAMES },
1897 /* SCR-3231 doesn't support the SET_CD_SPEED command. */
1898 { "SAMSUNG CD-ROM SCR-3231", NULL, IDE_CD_FLAG_NO_SPEED_SELECT },
1899 /* Old NEC260 (not R) was released before ATAPI 1.2 spec. */
1900 { "NEC CD-ROM DRIVE:260", "1.01", IDE_CD_FLAG_TOCADDR_AS_BCD |
1901 IDE_CD_FLAG_PRE_ATAPI12, },
1902 /* Vertos 300, some versions of this drive like to talk BCD. */
1903 { "V003S0DS", NULL, IDE_CD_FLAG_VERTOS_300_SSD, },
1904 /* Vertos 600 ESD. */
1905 { "V006E0DS", NULL, IDE_CD_FLAG_VERTOS_600_ESD, },
1906 /*
1907 * Sanyo 3 CD changer uses a non-standard command for CD changing
1908 * (by default standard ATAPI support for CD changers is used).
1909 */
1910 { "CD-ROM CDR-C3 G", NULL, IDE_CD_FLAG_SANYO_3CD },
1911 { "CD-ROM CDR-C3G", NULL, IDE_CD_FLAG_SANYO_3CD },
1912 { "CD-ROM CDR_C36", NULL, IDE_CD_FLAG_SANYO_3CD },
1913 /* Stingray 8X CD-ROM. */
1914 { "STINGRAY 8422 IDE 8X CD-ROM 7-27-95", NULL, IDE_CD_FLAG_PRE_ATAPI12},
1915 /*
1916 * ACER 50X CD-ROM and WPI 32X CD-ROM require the full spec length
1917 * mode sense page capabilities size, but older drives break.
1918 */
1919 { "ATAPI CD ROM DRIVE 50X MAX", NULL, IDE_CD_FLAG_FULL_CAPS_PAGE },
1920 { "WPI CDS-32X", NULL, IDE_CD_FLAG_FULL_CAPS_PAGE },
1921 /* ACER/AOpen 24X CD-ROM has the speed fields byte-swapped. */
1922 { "", "241N", IDE_CD_FLAG_LE_SPEED_FIELDS },
1923 /*
1924 * Some drives used by Apple don't advertise audio play
1925 * but they do support reading TOC & audio datas.
1926 */
1927 { "MATSHITADVD-ROM SR-8187", NULL, IDE_CD_FLAG_PLAY_AUDIO_OK },
1928 { "MATSHITADVD-ROM SR-8186", NULL, IDE_CD_FLAG_PLAY_AUDIO_OK },
1929 { "MATSHITADVD-ROM SR-8176", NULL, IDE_CD_FLAG_PLAY_AUDIO_OK },
1930 { "MATSHITADVD-ROM SR-8174", NULL, IDE_CD_FLAG_PLAY_AUDIO_OK },
1931 { NULL, NULL, 0 }
1932};
1933
1934static unsigned int ide_cd_flags(struct hd_driveid *id)
1935{
1936 const struct cd_list_entry *cle = ide_cd_quirks_list;
1937
1938 while (cle->id_model) {
1939 if (strcmp(cle->id_model, id->model) == 0 &&
1940 (cle->id_firmware == NULL ||
1941 strstr(id->fw_rev, cle->id_firmware)))
1942 return cle->cd_flags;
1943 cle++;
1944 }
1945
1946 return 0;
1947}
1948
3141static 1949static
3142int ide_cdrom_setup (ide_drive_t *drive) 1950int ide_cdrom_setup (ide_drive_t *drive)
3143{ 1951{
3144 struct cdrom_info *info = drive->driver_data; 1952 struct cdrom_info *cd = drive->driver_data;
3145 struct cdrom_device_info *cdi = &info->devinfo; 1953 struct cdrom_device_info *cdi = &cd->devinfo;
1954 struct hd_driveid *id = drive->id;
3146 int nslots; 1955 int nslots;
3147 1956
3148 blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn); 1957 blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn);
@@ -3153,101 +1962,21 @@ int ide_cdrom_setup (ide_drive_t *drive)
3153 1962
3154 drive->special.all = 0; 1963 drive->special.all = 0;
3155 1964
3156 CDROM_STATE_FLAGS(drive)->media_changed = 1; 1965 cd->cd_flags = IDE_CD_FLAG_MEDIA_CHANGED | IDE_CD_FLAG_NO_EJECT |
3157 CDROM_STATE_FLAGS(drive)->toc_valid = 0; 1966 ide_cd_flags(id);
3158 CDROM_STATE_FLAGS(drive)->door_locked = 0;
3159 1967
3160#if NO_DOOR_LOCKING 1968 if ((id->config & 0x0060) == 0x20)
3161 CDROM_CONFIG_FLAGS(drive)->no_doorlock = 1; 1969 cd->cd_flags |= IDE_CD_FLAG_DRQ_INTERRUPT;
3162#else
3163 CDROM_CONFIG_FLAGS(drive)->no_doorlock = 0;
3164#endif
3165 1970
3166 CDROM_CONFIG_FLAGS(drive)->drq_interrupt = ((drive->id->config & 0x0060) == 0x20); 1971 if ((cd->cd_flags & IDE_CD_FLAG_VERTOS_300_SSD) &&
3167 CDROM_CONFIG_FLAGS(drive)->is_changer = 0; 1972 id->fw_rev[4] == '1' && id->fw_rev[6] <= '2')
3168 CDROM_CONFIG_FLAGS(drive)->cd_r = 0; 1973 cd->cd_flags |= (IDE_CD_FLAG_TOCTRACKS_AS_BCD |
3169 CDROM_CONFIG_FLAGS(drive)->cd_rw = 0; 1974 IDE_CD_FLAG_TOCADDR_AS_BCD);
3170 CDROM_CONFIG_FLAGS(drive)->test_write = 0; 1975 else if ((cd->cd_flags & IDE_CD_FLAG_VERTOS_600_ESD) &&
3171 CDROM_CONFIG_FLAGS(drive)->dvd = 0; 1976 id->fw_rev[4] == '1' && id->fw_rev[6] <= '2')
3172 CDROM_CONFIG_FLAGS(drive)->dvd_r = 0; 1977 cd->cd_flags |= IDE_CD_FLAG_TOCTRACKS_AS_BCD;
3173 CDROM_CONFIG_FLAGS(drive)->dvd_ram = 0; 1978 else if (cd->cd_flags & IDE_CD_FLAG_SANYO_3CD)
3174 CDROM_CONFIG_FLAGS(drive)->no_eject = 1; 1979 cdi->sanyo_slot = 3; /* 3 => use CD in slot 0 */
3175 CDROM_CONFIG_FLAGS(drive)->supp_disc_present = 0;
3176 CDROM_CONFIG_FLAGS(drive)->audio_play = 0;
3177 CDROM_CONFIG_FLAGS(drive)->close_tray = 1;
3178
3179 /* limit transfer size per interrupt. */
3180 CDROM_CONFIG_FLAGS(drive)->limit_nframes = 0;
3181 /* a testament to the nice quality of Samsung drives... */
3182 if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-2430"))
3183 CDROM_CONFIG_FLAGS(drive)->limit_nframes = 1;
3184 else if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-2432"))
3185 CDROM_CONFIG_FLAGS(drive)->limit_nframes = 1;
3186 /* the 3231 model does not support the SET_CD_SPEED command */
3187 else if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-3231"))
3188 CDROM_CONFIG_FLAGS(drive)->no_speed_select = 1;
3189
3190#if ! STANDARD_ATAPI
3191 /* by default Sanyo 3 CD changer support is turned off and
3192 ATAPI Rev 2.2+ standard support for CD changers is used */
3193 cdi->sanyo_slot = 0;
3194
3195 CDROM_CONFIG_FLAGS(drive)->nec260 = 0;
3196 CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd = 0;
3197 CDROM_CONFIG_FLAGS(drive)->tocaddr_as_bcd = 0;
3198 CDROM_CONFIG_FLAGS(drive)->playmsf_as_bcd = 0;
3199 CDROM_CONFIG_FLAGS(drive)->subchan_as_bcd = 0;
3200
3201 if (strcmp (drive->id->model, "V003S0DS") == 0 &&
3202 drive->id->fw_rev[4] == '1' &&
3203 drive->id->fw_rev[6] <= '2') {
3204 /* Vertos 300.
3205 Some versions of this drive like to talk BCD. */
3206 CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd = 1;
3207 CDROM_CONFIG_FLAGS(drive)->tocaddr_as_bcd = 1;
3208 CDROM_CONFIG_FLAGS(drive)->playmsf_as_bcd = 1;
3209 CDROM_CONFIG_FLAGS(drive)->subchan_as_bcd = 1;
3210 }
3211
3212 else if (strcmp (drive->id->model, "V006E0DS") == 0 &&
3213 drive->id->fw_rev[4] == '1' &&
3214 drive->id->fw_rev[6] <= '2') {
3215 /* Vertos 600 ESD. */
3216 CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd = 1;
3217 }
3218 else if (strcmp(drive->id->model, "NEC CD-ROM DRIVE:260") == 0 &&
3219 strncmp(drive->id->fw_rev, "1.01", 4) == 0) { /* FIXME */
3220 /* Old NEC260 (not R).
3221 This drive was released before the 1.2 version
3222 of the spec. */
3223 CDROM_CONFIG_FLAGS(drive)->tocaddr_as_bcd = 1;
3224 CDROM_CONFIG_FLAGS(drive)->playmsf_as_bcd = 1;
3225 CDROM_CONFIG_FLAGS(drive)->subchan_as_bcd = 1;
3226 CDROM_CONFIG_FLAGS(drive)->nec260 = 1;
3227 }
3228 else if (strcmp(drive->id->model, "WEARNES CDD-120") == 0 &&
3229 strncmp(drive->id->fw_rev, "A1.1", 4) == 0) { /* FIXME */
3230 /* Wearnes */
3231 CDROM_CONFIG_FLAGS(drive)->playmsf_as_bcd = 1;
3232 CDROM_CONFIG_FLAGS(drive)->subchan_as_bcd = 1;
3233 }
3234 /* Sanyo 3 CD changer uses a non-standard command
3235 for CD changing */
3236 else if ((strcmp(drive->id->model, "CD-ROM CDR-C3 G") == 0) ||
3237 (strcmp(drive->id->model, "CD-ROM CDR-C3G") == 0) ||
3238 (strcmp(drive->id->model, "CD-ROM CDR_C36") == 0)) {
3239 /* uses CD in slot 0 when value is set to 3 */
3240 cdi->sanyo_slot = 3;
3241 }
3242#endif /* not STANDARD_ATAPI */
3243
3244 info->toc = NULL;
3245 info->buffer = NULL;
3246 info->sector_buffered = 0;
3247 info->nsectors_buffered = 0;
3248 info->changer_info = NULL;
3249 info->last_block = 0;
3250 info->start_seek = 0;
3251 1980
3252 nslots = ide_cdrom_probe_capabilities (drive); 1981 nslots = ide_cdrom_probe_capabilities (drive);
3253 1982
@@ -3262,7 +1991,7 @@ int ide_cdrom_setup (ide_drive_t *drive)
3262 1991
3263 if (ide_cdrom_register(drive, nslots)) { 1992 if (ide_cdrom_register(drive, nslots)) {
3264 printk (KERN_ERR "%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name); 1993 printk (KERN_ERR "%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name);
3265 info->devinfo.handle = NULL; 1994 cd->devinfo.handle = NULL;
3266 return 1; 1995 return 1;
3267 } 1996 }
3268 ide_cdrom_add_settings(drive); 1997 ide_cdrom_add_settings(drive);
@@ -3302,7 +2031,6 @@ static void ide_cd_release(struct kref *kref)
3302 2031
3303 kfree(info->buffer); 2032 kfree(info->buffer);
3304 kfree(info->toc); 2033 kfree(info->toc);
3305 kfree(info->changer_info);
3306 if (devinfo->handle == drive && unregister_cdrom(devinfo)) 2034 if (devinfo->handle == drive && unregister_cdrom(devinfo))
3307 printk(KERN_ERR "%s: %s failed to unregister device from the cdrom " 2035 printk(KERN_ERR "%s: %s failed to unregister device from the cdrom "
3308 "driver.\n", __FUNCTION__, drive->name); 2036 "driver.\n", __FUNCTION__, drive->name);
@@ -3458,7 +2186,9 @@ static int idecd_revalidate_disk(struct gendisk *disk)
3458{ 2186{
3459 struct cdrom_info *info = ide_cd_g(disk); 2187 struct cdrom_info *info = ide_cd_g(disk);
3460 struct request_sense sense; 2188 struct request_sense sense;
3461 cdrom_read_toc(info->drive, &sense); 2189
2190 ide_cd_read_toc(info->drive, &sense);
2191
3462 return 0; 2192 return 0;
3463} 2193}
3464 2194
@@ -3533,7 +2263,7 @@ static int ide_cd_probe(ide_drive_t *drive)
3533 goto failed; 2263 goto failed;
3534 } 2264 }
3535 2265
3536 cdrom_read_toc(drive, &sense); 2266 ide_cd_read_toc(drive, &sense);
3537 g->fops = &idecd_ops; 2267 g->fops = &idecd_ops;
3538 g->flags |= GENHD_FL_REMOVABLE; 2268 g->flags |= GENHD_FL_REMOVABLE;
3539 add_disk(g); 2269 add_disk(g);
@@ -3556,6 +2286,7 @@ static int __init ide_cdrom_init(void)
3556} 2286}
3557 2287
3558MODULE_ALIAS("ide:*m-cdrom*"); 2288MODULE_ALIAS("ide:*m-cdrom*");
2289MODULE_ALIAS("ide-cd");
3559module_init(ide_cdrom_init); 2290module_init(ide_cdrom_init);
3560module_exit(ide_cdrom_exit); 2291module_exit(ide_cdrom_exit);
3561MODULE_LICENSE("GPL"); 2292MODULE_LICENSE("GPL");
diff --git a/drivers/ide/ide-cd.h b/drivers/ide/ide-cd.h
index 1b302fe2724..22e3751a681 100644
--- a/drivers/ide/ide-cd.h
+++ b/drivers/ide/ide-cd.h
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/ide_cd.h
3 *
4 * Copyright (C) 1996-98 Erik Andersen 2 * Copyright (C) 1996-98 Erik Andersen
5 * Copyright (C) 1998-2000 Jens Axboe 3 * Copyright (C) 1998-2000 Jens Axboe
6 */ 4 */
@@ -10,31 +8,6 @@
10#include <linux/cdrom.h> 8#include <linux/cdrom.h>
11#include <asm/byteorder.h> 9#include <asm/byteorder.h>
12 10
13/* Turn this on to have the driver print out the meanings of the
14 ATAPI error codes. This will use up additional kernel-space
15 memory, though. */
16
17#ifndef VERBOSE_IDE_CD_ERRORS
18#define VERBOSE_IDE_CD_ERRORS 1
19#endif
20
21
22/* Turning this on will remove code to work around various nonstandard
23 ATAPI implementations. If you know your drive follows the standard,
24 this will give you a slightly smaller kernel. */
25
26#ifndef STANDARD_ATAPI
27#define STANDARD_ATAPI 0
28#endif
29
30
31/* Turning this on will disable the door-locking functionality.
32 This is apparently needed for supermount. */
33
34#ifndef NO_DOOR_LOCKING
35#define NO_DOOR_LOCKING 0
36#endif
37
38/* 11/*
39 * typical timeout for packet command 12 * typical timeout for packet command
40 */ 13 */
@@ -49,68 +22,47 @@
49#endif 22#endif
50#define SECTORS_PER_FRAME (CD_FRAMESIZE >> SECTOR_BITS) 23#define SECTORS_PER_FRAME (CD_FRAMESIZE >> SECTOR_BITS)
51#define SECTOR_BUFFER_SIZE (CD_FRAMESIZE * 32) 24#define SECTOR_BUFFER_SIZE (CD_FRAMESIZE * 32)
52#define SECTORS_BUFFER (SECTOR_BUFFER_SIZE >> SECTOR_BITS)
53#define SECTORS_MAX (131072 >> SECTOR_BITS)
54
55#define BLOCKS_PER_FRAME (CD_FRAMESIZE / BLOCK_SIZE)
56
57/* special command codes for strategy routine. */
58#define PACKET_COMMAND 4315
59#define REQUEST_SENSE_COMMAND 4316
60#define RESET_DRIVE_COMMAND 4317
61
62
63/* Configuration flags. These describe the capabilities of the drive.
64 They generally do not change after initialization, unless we learn
65 more about the drive from stuff failing. */
66struct ide_cd_config_flags {
67 __u8 drq_interrupt : 1; /* Device sends an interrupt when ready
68 for a packet command. */
69 __u8 no_doorlock : 1; /* Drive cannot lock the door. */
70 __u8 no_eject : 1; /* Drive cannot eject the disc. */
71 __u8 nec260 : 1; /* Drive is a pre-1.2 NEC 260 drive. */
72 __u8 playmsf_as_bcd : 1; /* PLAYMSF command takes BCD args. */
73 __u8 tocaddr_as_bcd : 1; /* TOC addresses are in BCD. */
74 __u8 toctracks_as_bcd : 1; /* TOC track numbers are in BCD. */
75 __u8 subchan_as_bcd : 1; /* Subchannel info is in BCD. */
76 __u8 is_changer : 1; /* Drive is a changer. */
77 __u8 cd_r : 1; /* Drive can write to CD-R media . */
78 __u8 cd_rw : 1; /* Drive can write to CD-R/W media . */
79 __u8 dvd : 1; /* Drive is a DVD-ROM */
80 __u8 dvd_r : 1; /* Drive can write DVD-R */
81 __u8 dvd_ram : 1; /* Drive can write DVD-RAM */
82 __u8 ram : 1; /* generic WRITE (dvd-ram/mrw) */
83 __u8 test_write : 1; /* Drive can fake writes */
84 __u8 supp_disc_present : 1; /* Changer can report exact contents
85 of slots. */
86 __u8 limit_nframes : 1; /* Drive does not provide data in
87 multiples of SECTOR_SIZE when more
88 than one interrupt is needed. */
89 __u8 seeking : 1; /* Seeking in progress */
90 __u8 audio_play : 1; /* can do audio related commands */
91 __u8 close_tray : 1; /* can close the tray */
92 __u8 writing : 1; /* pseudo write in progress */
93 __u8 mo_drive : 1; /* drive is an MO device */
94 __u8 no_speed_select : 1; /* SET_CD_SPEED command is unsupported. */
95 __u8 reserved : 1;
96 byte max_speed; /* Max speed of the drive */
97};
98#define CDROM_CONFIG_FLAGS(drive) (&(((struct cdrom_info *)(drive->driver_data))->config_flags))
99 25
100 26/* Capabilities Page size including 8 bytes of Mode Page Header */
101/* State flags. These give information about the current state of the 27#define ATAPI_CAPABILITIES_PAGE_SIZE (8 + 20)
102 drive, and will change during normal operation. */ 28#define ATAPI_CAPABILITIES_PAGE_PAD_SIZE 4
103struct ide_cd_state_flags { 29
104 __u8 media_changed : 1; /* Driver has noticed a media change. */ 30enum {
105 __u8 toc_valid : 1; /* Saved TOC information is current. */ 31 /* Device sends an interrupt when ready for a packet command. */
106 __u8 door_locked : 1; /* We think that the drive door is locked. */ 32 IDE_CD_FLAG_DRQ_INTERRUPT = (1 << 0),
107 __u8 writing : 1; /* the drive is currently writing */ 33 /* Drive cannot lock the door. */
108 __u8 reserved : 4; 34 IDE_CD_FLAG_NO_DOORLOCK = (1 << 1),
109 byte current_speed; /* Current speed of the drive */ 35 /* Drive cannot eject the disc. */
36 IDE_CD_FLAG_NO_EJECT = (1 << 2),
37 /* Drive is a pre ATAPI 1.2 drive. */
38 IDE_CD_FLAG_PRE_ATAPI12 = (1 << 3),
39 /* TOC addresses are in BCD. */
40 IDE_CD_FLAG_TOCADDR_AS_BCD = (1 << 4),
41 /* TOC track numbers are in BCD. */
42 IDE_CD_FLAG_TOCTRACKS_AS_BCD = (1 << 5),
43 /*
44 * Drive does not provide data in multiples of SECTOR_SIZE
45 * when more than one interrupt is needed.
46 */
47 IDE_CD_FLAG_LIMIT_NFRAMES = (1 << 6),
48 /* Seeking in progress. */
49 IDE_CD_FLAG_SEEKING = (1 << 7),
50 /* Driver has noticed a media change. */
51 IDE_CD_FLAG_MEDIA_CHANGED = (1 << 8),
52 /* Saved TOC information is current. */
53 IDE_CD_FLAG_TOC_VALID = (1 << 9),
54 /* We think that the drive door is locked. */
55 IDE_CD_FLAG_DOOR_LOCKED = (1 << 10),
56 /* SET_CD_SPEED command is unsupported. */
57 IDE_CD_FLAG_NO_SPEED_SELECT = (1 << 11),
58 IDE_CD_FLAG_VERTOS_300_SSD = (1 << 12),
59 IDE_CD_FLAG_VERTOS_600_ESD = (1 << 13),
60 IDE_CD_FLAG_SANYO_3CD = (1 << 14),
61 IDE_CD_FLAG_FULL_CAPS_PAGE = (1 << 15),
62 IDE_CD_FLAG_PLAY_AUDIO_OK = (1 << 16),
63 IDE_CD_FLAG_LE_SPEED_FIELDS = (1 << 17),
110}; 64};
111 65
112#define CDROM_STATE_FLAGS(drive) (&(((struct cdrom_info *)(drive->driver_data))->state_flags))
113
114/* Structure of a MSF cdrom address. */ 66/* Structure of a MSF cdrom address. */
115struct atapi_msf { 67struct atapi_msf {
116 byte reserved; 68 byte reserved;
@@ -155,310 +107,6 @@ struct atapi_toc {
155 /* One extra for the leadout. */ 107 /* One extra for the leadout. */
156}; 108};
157 109
158
159/* This structure is annoyingly close to, but not identical with,
160 the cdrom_subchnl structure from cdrom.h. */
161struct atapi_cdrom_subchnl {
162 u_char acdsc_reserved;
163 u_char acdsc_audiostatus;
164 u_short acdsc_length;
165 u_char acdsc_format;
166
167#if defined(__BIG_ENDIAN_BITFIELD)
168 u_char acdsc_ctrl: 4;
169 u_char acdsc_adr: 4;
170#elif defined(__LITTLE_ENDIAN_BITFIELD)
171 u_char acdsc_adr: 4;
172 u_char acdsc_ctrl: 4;
173#else
174#error "Please fix <asm/byteorder.h>"
175#endif
176 u_char acdsc_trk;
177 u_char acdsc_ind;
178 union {
179 struct atapi_msf msf;
180 int lba;
181 } acdsc_absaddr;
182 union {
183 struct atapi_msf msf;
184 int lba;
185 } acdsc_reladdr;
186};
187
188
189
190/* This should probably go into cdrom.h along with the other
191 * generic stuff now in the Mt. Fuji spec.
192 */
193struct atapi_capabilities_page {
194 struct mode_page_header header;
195#if defined(__BIG_ENDIAN_BITFIELD)
196 __u8 parameters_saveable : 1;
197 __u8 reserved1 : 1;
198 __u8 page_code : 6;
199#elif defined(__LITTLE_ENDIAN_BITFIELD)
200 __u8 page_code : 6;
201 __u8 reserved1 : 1;
202 __u8 parameters_saveable : 1;
203#else
204#error "Please fix <asm/byteorder.h>"
205#endif
206
207 byte page_length;
208
209#if defined(__BIG_ENDIAN_BITFIELD)
210 __u8 reserved2 : 2;
211 /* Drive supports reading of DVD-RAM discs */
212 __u8 dvd_ram_read : 1;
213 /* Drive supports reading of DVD-R discs */
214 __u8 dvd_r_read : 1;
215 /* Drive supports reading of DVD-ROM discs */
216 __u8 dvd_rom : 1;
217 /* Drive supports reading CD-R discs with addressing method 2 */
218 __u8 method2 : 1; /* reserved in 1.2 */
219 /* Drive can read from CD-R/W (CD-E) discs (orange book, part III) */
220 __u8 cd_rw_read : 1; /* reserved in 1.2 */
221 /* Drive supports read from CD-R discs (orange book, part II) */
222 __u8 cd_r_read : 1; /* reserved in 1.2 */
223#elif defined(__LITTLE_ENDIAN_BITFIELD)
224 /* Drive supports read from CD-R discs (orange book, part II) */
225 __u8 cd_r_read : 1; /* reserved in 1.2 */
226 /* Drive can read from CD-R/W (CD-E) discs (orange book, part III) */
227 __u8 cd_rw_read : 1; /* reserved in 1.2 */
228 /* Drive supports reading CD-R discs with addressing method 2 */
229 __u8 method2 : 1;
230 /* Drive supports reading of DVD-ROM discs */
231 __u8 dvd_rom : 1;
232 /* Drive supports reading of DVD-R discs */
233 __u8 dvd_r_read : 1;
234 /* Drive supports reading of DVD-RAM discs */
235 __u8 dvd_ram_read : 1;
236 __u8 reserved2 : 2;
237#else
238#error "Please fix <asm/byteorder.h>"
239#endif
240
241#if defined(__BIG_ENDIAN_BITFIELD)
242 __u8 reserved3 : 2;
243 /* Drive can write DVD-RAM discs */
244 __u8 dvd_ram_write : 1;
245 /* Drive can write DVD-R discs */
246 __u8 dvd_r_write : 1;
247 __u8 reserved3a : 1;
248 /* Drive can fake writes */
249 __u8 test_write : 1;
250 /* Drive can write to CD-R/W (CD-E) discs (orange book, part III) */
251 __u8 cd_rw_write : 1; /* reserved in 1.2 */
252 /* Drive supports write to CD-R discs (orange book, part II) */
253 __u8 cd_r_write : 1; /* reserved in 1.2 */
254#elif defined(__LITTLE_ENDIAN_BITFIELD)
255 /* Drive can write to CD-R discs (orange book, part II) */
256 __u8 cd_r_write : 1; /* reserved in 1.2 */
257 /* Drive can write to CD-R/W (CD-E) discs (orange book, part III) */
258 __u8 cd_rw_write : 1; /* reserved in 1.2 */
259 /* Drive can fake writes */
260 __u8 test_write : 1;
261 __u8 reserved3a : 1;
262 /* Drive can write DVD-R discs */
263 __u8 dvd_r_write : 1;
264 /* Drive can write DVD-RAM discs */
265 __u8 dvd_ram_write : 1;
266 __u8 reserved3 : 2;
267#else
268#error "Please fix <asm/byteorder.h>"
269#endif
270
271#if defined(__BIG_ENDIAN_BITFIELD)
272 __u8 reserved4 : 1;
273 /* Drive can read multisession discs. */
274 __u8 multisession : 1;
275 /* Drive can read mode 2, form 2 data. */
276 __u8 mode2_form2 : 1;
277 /* Drive can read mode 2, form 1 (XA) data. */
278 __u8 mode2_form1 : 1;
279 /* Drive supports digital output on port 2. */
280 __u8 digport2 : 1;
281 /* Drive supports digital output on port 1. */
282 __u8 digport1 : 1;
283 /* Drive can deliver a composite audio/video data stream. */
284 __u8 composite : 1;
285 /* Drive supports audio play operations. */
286 __u8 audio_play : 1;
287#elif defined(__LITTLE_ENDIAN_BITFIELD)
288 /* Drive supports audio play operations. */
289 __u8 audio_play : 1;
290 /* Drive can deliver a composite audio/video data stream. */
291 __u8 composite : 1;
292 /* Drive supports digital output on port 1. */
293 __u8 digport1 : 1;
294 /* Drive supports digital output on port 2. */
295 __u8 digport2 : 1;
296 /* Drive can read mode 2, form 1 (XA) data. */
297 __u8 mode2_form1 : 1;
298 /* Drive can read mode 2, form 2 data. */
299 __u8 mode2_form2 : 1;
300 /* Drive can read multisession discs. */
301 __u8 multisession : 1;
302 __u8 reserved4 : 1;
303#else
304#error "Please fix <asm/byteorder.h>"
305#endif
306
307#if defined(__BIG_ENDIAN_BITFIELD)
308 __u8 reserved5 : 1;
309 /* Drive can return Media Catalog Number (UPC) info. */
310 __u8 upc : 1;
311 /* Drive can return International Standard Recording Code info. */
312 __u8 isrc : 1;
313 /* Drive supports C2 error pointers. */
314 __u8 c2_pointers : 1;
315 /* R-W data will be returned deinterleaved and error corrected. */
316 __u8 rw_corr : 1;
317 /* Subchannel reads can return combined R-W information. */
318 __u8 rw_supported : 1;
319 /* Drive can continue a read cdda operation from a loss of streaming.*/
320 __u8 cdda_accurate : 1;
321 /* Drive can read Red Book audio data. */
322 __u8 cdda : 1;
323#elif defined(__LITTLE_ENDIAN_BITFIELD)
324 /* Drive can read Red Book audio data. */
325 __u8 cdda : 1;
326 /* Drive can continue a read cdda operation from a loss of streaming.*/
327 __u8 cdda_accurate : 1;
328 /* Subchannel reads can return combined R-W information. */
329 __u8 rw_supported : 1;
330 /* R-W data will be returned deinterleaved and error corrected. */
331 __u8 rw_corr : 1;
332 /* Drive supports C2 error pointers. */
333 __u8 c2_pointers : 1;
334 /* Drive can return International Standard Recording Code info. */
335 __u8 isrc : 1;
336 /* Drive can return Media Catalog Number (UPC) info. */
337 __u8 upc : 1;
338 __u8 reserved5 : 1;
339#else
340#error "Please fix <asm/byteorder.h>"
341#endif
342
343#if defined(__BIG_ENDIAN_BITFIELD)
344 /* Drive mechanism types. */
345 mechtype_t mechtype : 3;
346 __u8 reserved6 : 1;
347 /* Drive can eject a disc or changer cartridge. */
348 __u8 eject : 1;
349 /* State of prevent/allow jumper. */
350 __u8 prevent_jumper : 1;
351 /* Present state of door lock. */
352 __u8 lock_state : 1;
353 /* Drive can lock the door. */
354 __u8 lock : 1;
355#elif defined(__LITTLE_ENDIAN_BITFIELD)
356
357 /* Drive can lock the door. */
358 __u8 lock : 1;
359 /* Present state of door lock. */
360 __u8 lock_state : 1;
361 /* State of prevent/allow jumper. */
362 __u8 prevent_jumper : 1;
363 /* Drive can eject a disc or changer cartridge. */
364 __u8 eject : 1;
365 __u8 reserved6 : 1;
366 /* Drive mechanism types. */
367 mechtype_t mechtype : 3;
368#else
369#error "Please fix <asm/byteorder.h>"
370#endif
371
372#if defined(__BIG_ENDIAN_BITFIELD)
373 __u8 reserved7 : 4;
374 /* Drive supports software slot selection. */
375 __u8 sss : 1; /* reserved in 1.2 */
376 /* Changer can report exact contents of slots. */
377 __u8 disc_present : 1; /* reserved in 1.2 */
378 /* Audio for each channel can be muted independently. */
379 __u8 separate_mute : 1;
380 /* Audio level for each channel can be controlled independently. */
381 __u8 separate_volume : 1;
382#elif defined(__LITTLE_ENDIAN_BITFIELD)
383
384 /* Audio level for each channel can be controlled independently. */
385 __u8 separate_volume : 1;
386 /* Audio for each channel can be muted independently. */
387 __u8 separate_mute : 1;
388 /* Changer can report exact contents of slots. */
389 __u8 disc_present : 1; /* reserved in 1.2 */
390 /* Drive supports software slot selection. */
391 __u8 sss : 1; /* reserved in 1.2 */
392 __u8 reserved7 : 4;
393#else
394#error "Please fix <asm/byteorder.h>"
395#endif
396
397 /* Note: the following four fields are returned in big-endian form. */
398 /* Maximum speed (in kB/s). */
399 unsigned short maxspeed;
400 /* Number of discrete volume levels. */
401 unsigned short n_vol_levels;
402 /* Size of cache in drive, in kB. */
403 unsigned short buffer_size;
404 /* Current speed (in kB/s). */
405 unsigned short curspeed;
406 char pad[4];
407};
408
409
410struct atapi_mechstat_header {
411#if defined(__BIG_ENDIAN_BITFIELD)
412 __u8 fault : 1;
413 __u8 changer_state : 2;
414 __u8 curslot : 5;
415#elif defined(__LITTLE_ENDIAN_BITFIELD)
416 __u8 curslot : 5;
417 __u8 changer_state : 2;
418 __u8 fault : 1;
419#else
420#error "Please fix <asm/byteorder.h>"
421#endif
422
423#if defined(__BIG_ENDIAN_BITFIELD)
424 __u8 mech_state : 3;
425 __u8 door_open : 1;
426 __u8 reserved1 : 4;
427#elif defined(__LITTLE_ENDIAN_BITFIELD)
428 __u8 reserved1 : 4;
429 __u8 door_open : 1;
430 __u8 mech_state : 3;
431#else
432#error "Please fix <asm/byteorder.h>"
433#endif
434
435 byte curlba[3];
436 byte nslots;
437 __u16 slot_tablelen;
438};
439
440
441struct atapi_slot {
442#if defined(__BIG_ENDIAN_BITFIELD)
443 __u8 disc_present : 1;
444 __u8 reserved1 : 6;
445 __u8 change : 1;
446#elif defined(__LITTLE_ENDIAN_BITFIELD)
447 __u8 change : 1;
448 __u8 reserved1 : 6;
449 __u8 disc_present : 1;
450#else
451#error "Please fix <asm/byteorder.h>"
452#endif
453
454 byte reserved2[3];
455};
456
457struct atapi_changer_info {
458 struct atapi_mechstat_header hdr;
459 struct atapi_slot slots[0];
460};
461
462/* Extra per-device info for cdrom drives. */ 110/* Extra per-device info for cdrom drives. */
463struct cdrom_info { 111struct cdrom_info {
464 ide_drive_t *drive; 112 ide_drive_t *drive;
@@ -483,11 +131,11 @@ struct cdrom_info {
483 int dma; 131 int dma;
484 unsigned long last_block; 132 unsigned long last_block;
485 unsigned long start_seek; 133 unsigned long start_seek;
486 /* Buffer to hold mechanism status and changer slot table. */
487 struct atapi_changer_info *changer_info;
488 134
489 struct ide_cd_config_flags config_flags; 135 unsigned int cd_flags;
490 struct ide_cd_state_flags state_flags; 136
137 u8 max_speed; /* Max speed of the drive. */
138 u8 current_speed; /* Current speed of the drive. */
491 139
492 /* Per-device info needed by cdrom.c generic driver. */ 140 /* Per-device info needed by cdrom.c generic driver. */
493 struct cdrom_device_info devinfo; 141 struct cdrom_device_info devinfo;
@@ -495,250 +143,30 @@ struct cdrom_info {
495 unsigned long write_timeout; 143 unsigned long write_timeout;
496}; 144};
497 145
498/**************************************************************************** 146/* ide-cd_verbose.c */
499 * Descriptions of ATAPI error codes. 147void ide_cd_log_error(const char *, struct request *, struct request_sense *);
500 */ 148
501 149/* ide-cd.c functions used by ide-cd_ioctl.c */
502/* This stuff should be in cdrom.h, since it is now generic... */ 150void ide_cd_init_rq(ide_drive_t *, struct request *);
503 151int ide_cd_queue_pc(ide_drive_t *, struct request *);
504/* ATAPI sense keys (from table 140 of ATAPI 2.6) */ 152int ide_cd_read_toc(ide_drive_t *, struct request_sense *);
505#define NO_SENSE 0x00 153int ide_cdrom_get_capabilities(ide_drive_t *, u8 *);
506#define RECOVERED_ERROR 0x01 154void ide_cdrom_update_speed(ide_drive_t *, u8 *);
507#define NOT_READY 0x02 155int cdrom_check_status(ide_drive_t *, struct request_sense *);
508#define MEDIUM_ERROR 0x03 156
509#define HARDWARE_ERROR 0x04 157/* ide-cd_ioctl.c */
510#define ILLEGAL_REQUEST 0x05 158int ide_cdrom_open_real(struct cdrom_device_info *, int);
511#define UNIT_ATTENTION 0x06 159void ide_cdrom_release_real(struct cdrom_device_info *);
512#define DATA_PROTECT 0x07 160int ide_cdrom_drive_status(struct cdrom_device_info *, int);
513#define BLANK_CHECK 0x08 161int ide_cdrom_check_media_change_real(struct cdrom_device_info *, int);
514#define ABORTED_COMMAND 0x0b 162int ide_cdrom_tray_move(struct cdrom_device_info *, int);
515#define MISCOMPARE 0x0e 163int ide_cdrom_lock_door(struct cdrom_device_info *, int);
516 164int ide_cdrom_select_speed(struct cdrom_device_info *, int);
517 165int ide_cdrom_get_last_session(struct cdrom_device_info *,
518 166 struct cdrom_multisession *);
519/* This stuff should be in cdrom.h, since it is now generic... */ 167int ide_cdrom_get_mcn(struct cdrom_device_info *, struct cdrom_mcn *);
520#if VERBOSE_IDE_CD_ERRORS 168int ide_cdrom_reset(struct cdrom_device_info *cdi);
521 169int ide_cdrom_audio_ioctl(struct cdrom_device_info *, unsigned int, void *);
522 /* The generic packet command opcodes for CD/DVD Logical Units, 170int ide_cdrom_packet(struct cdrom_device_info *, struct packet_command *);
523 * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
524static const struct {
525 unsigned short packet_command;
526 const char * const text;
527} packet_command_texts[] = {
528 { GPCMD_TEST_UNIT_READY, "Test Unit Ready" },
529 { GPCMD_REQUEST_SENSE, "Request Sense" },
530 { GPCMD_FORMAT_UNIT, "Format Unit" },
531 { GPCMD_INQUIRY, "Inquiry" },
532 { GPCMD_START_STOP_UNIT, "Start/Stop Unit" },
533 { GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL, "Prevent/Allow Medium Removal" },
534 { GPCMD_READ_FORMAT_CAPACITIES, "Read Format Capacities" },
535 { GPCMD_READ_CDVD_CAPACITY, "Read Cd/Dvd Capacity" },
536 { GPCMD_READ_10, "Read 10" },
537 { GPCMD_WRITE_10, "Write 10" },
538 { GPCMD_SEEK, "Seek" },
539 { GPCMD_WRITE_AND_VERIFY_10, "Write and Verify 10" },
540 { GPCMD_VERIFY_10, "Verify 10" },
541 { GPCMD_FLUSH_CACHE, "Flush Cache" },
542 { GPCMD_READ_SUBCHANNEL, "Read Subchannel" },
543 { GPCMD_READ_TOC_PMA_ATIP, "Read Table of Contents" },
544 { GPCMD_READ_HEADER, "Read Header" },
545 { GPCMD_PLAY_AUDIO_10, "Play Audio 10" },
546 { GPCMD_GET_CONFIGURATION, "Get Configuration" },
547 { GPCMD_PLAY_AUDIO_MSF, "Play Audio MSF" },
548 { GPCMD_PLAYAUDIO_TI, "Play Audio TrackIndex" },
549 { GPCMD_GET_EVENT_STATUS_NOTIFICATION, "Get Event Status Notification" },
550 { GPCMD_PAUSE_RESUME, "Pause/Resume" },
551 { GPCMD_STOP_PLAY_SCAN, "Stop Play/Scan" },
552 { GPCMD_READ_DISC_INFO, "Read Disc Info" },
553 { GPCMD_READ_TRACK_RZONE_INFO, "Read Track Rzone Info" },
554 { GPCMD_RESERVE_RZONE_TRACK, "Reserve Rzone Track" },
555 { GPCMD_SEND_OPC, "Send OPC" },
556 { GPCMD_MODE_SELECT_10, "Mode Select 10" },
557 { GPCMD_REPAIR_RZONE_TRACK, "Repair Rzone Track" },
558 { GPCMD_MODE_SENSE_10, "Mode Sense 10" },
559 { GPCMD_CLOSE_TRACK, "Close Track" },
560 { GPCMD_BLANK, "Blank" },
561 { GPCMD_SEND_EVENT, "Send Event" },
562 { GPCMD_SEND_KEY, "Send Key" },
563 { GPCMD_REPORT_KEY, "Report Key" },
564 { GPCMD_LOAD_UNLOAD, "Load/Unload" },
565 { GPCMD_SET_READ_AHEAD, "Set Read-ahead" },
566 { GPCMD_READ_12, "Read 12" },
567 { GPCMD_GET_PERFORMANCE, "Get Performance" },
568 { GPCMD_SEND_DVD_STRUCTURE, "Send DVD Structure" },
569 { GPCMD_READ_DVD_STRUCTURE, "Read DVD Structure" },
570 { GPCMD_SET_STREAMING, "Set Streaming" },
571 { GPCMD_READ_CD_MSF, "Read CD MSF" },
572 { GPCMD_SCAN, "Scan" },
573 { GPCMD_SET_SPEED, "Set Speed" },
574 { GPCMD_PLAY_CD, "Play CD" },
575 { GPCMD_MECHANISM_STATUS, "Mechanism Status" },
576 { GPCMD_READ_CD, "Read CD" },
577};
578
579
580
581/* From Table 303 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
582static const char * const sense_key_texts[16] = {
583 "No sense data",
584 "Recovered error",
585 "Not ready",
586 "Medium error",
587 "Hardware error",
588 "Illegal request",
589 "Unit attention",
590 "Data protect",
591 "Blank check",
592 "(reserved)",
593 "(reserved)",
594 "Aborted command",
595 "(reserved)",
596 "(reserved)",
597 "Miscompare",
598 "(reserved)",
599};
600
601/* From Table 304 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
602static const struct {
603 unsigned long asc_ascq;
604 const char * const text;
605} sense_data_texts[] = {
606 { 0x000000, "No additional sense information" },
607 { 0x000011, "Play operation in progress" },
608 { 0x000012, "Play operation paused" },
609 { 0x000013, "Play operation successfully completed" },
610 { 0x000014, "Play operation stopped due to error" },
611 { 0x000015, "No current audio status to return" },
612 { 0x010c0a, "Write error - padding blocks added" },
613 { 0x011700, "Recovered data with no error correction applied" },
614 { 0x011701, "Recovered data with retries" },
615 { 0x011702, "Recovered data with positive head offset" },
616 { 0x011703, "Recovered data with negative head offset" },
617 { 0x011704, "Recovered data with retries and/or CIRC applied" },
618 { 0x011705, "Recovered data using previous sector ID" },
619 { 0x011800, "Recovered data with error correction applied" },
620 { 0x011801, "Recovered data with error correction and retries applied"},
621 { 0x011802, "Recovered data - the data was auto-reallocated" },
622 { 0x011803, "Recovered data with CIRC" },
623 { 0x011804, "Recovered data with L-EC" },
624 { 0x015d00,
625 "Failure prediction threshold exceeded - Predicted logical unit failure" },
626 { 0x015d01,
627 "Failure prediction threshold exceeded - Predicted media failure" },
628 { 0x015dff, "Failure prediction threshold exceeded - False" },
629 { 0x017301, "Power calibration area almost full" },
630 { 0x020400, "Logical unit not ready - cause not reportable" },
631 /* Following is misspelled in ATAPI 2.6, _and_ in Mt. Fuji */
632 { 0x020401,
633 "Logical unit not ready - in progress [sic] of becoming ready" },
634 { 0x020402, "Logical unit not ready - initializing command required" },
635 { 0x020403, "Logical unit not ready - manual intervention required" },
636 { 0x020404, "Logical unit not ready - format in progress" },
637 { 0x020407, "Logical unit not ready - operation in progress" },
638 { 0x020408, "Logical unit not ready - long write in progress" },
639 { 0x020600, "No reference position found (media may be upside down)" },
640 { 0x023000, "Incompatible medium installed" },
641 { 0x023a00, "Medium not present" },
642 { 0x025300, "Media load or eject failed" },
643 { 0x025700, "Unable to recover table of contents" },
644 { 0x030300, "Peripheral device write fault" },
645 { 0x030301, "No write current" },
646 { 0x030302, "Excessive write errors" },
647 { 0x030c00, "Write error" },
648 { 0x030c01, "Write error - Recovered with auto reallocation" },
649 { 0x030c02, "Write error - auto reallocation failed" },
650 { 0x030c03, "Write error - recommend reassignment" },
651 { 0x030c04, "Compression check miscompare error" },
652 { 0x030c05, "Data expansion occurred during compress" },
653 { 0x030c06, "Block not compressible" },
654 { 0x030c07, "Write error - recovery needed" },
655 { 0x030c08, "Write error - recovery failed" },
656 { 0x030c09, "Write error - loss of streaming" },
657 { 0x031100, "Unrecovered read error" },
658 { 0x031106, "CIRC unrecovered error" },
659 { 0x033101, "Format command failed" },
660 { 0x033200, "No defect spare location available" },
661 { 0x033201, "Defect list update failure" },
662 { 0x035100, "Erase failure" },
663 { 0x037200, "Session fixation error" },
664 { 0x037201, "Session fixation error writin lead-in" },
665 { 0x037202, "Session fixation error writin lead-out" },
666 { 0x037300, "CD control error" },
667 { 0x037302, "Power calibration area is full" },
668 { 0x037303, "Power calibration area error" },
669 { 0x037304, "Program memory area / RMA update failure" },
670 { 0x037305, "Program memory area / RMA is full" },
671 { 0x037306, "Program memory area / RMA is (almost) full" },
672
673 { 0x040200, "No seek complete" },
674 { 0x040300, "Write fault" },
675 { 0x040900, "Track following error" },
676 { 0x040901, "Tracking servo failure" },
677 { 0x040902, "Focus servo failure" },
678 { 0x040903, "Spindle servo failure" },
679 { 0x041500, "Random positioning error" },
680 { 0x041501, "Mechanical positioning or changer error" },
681 { 0x041502, "Positioning error detected by read of medium" },
682 { 0x043c00, "Mechanical positioning or changer error" },
683 { 0x044000, "Diagnostic failure on component (ASCQ)" },
684 { 0x044400, "Internal CD/DVD logical unit failure" },
685 { 0x04b600, "Media load mechanism failed" },
686 { 0x051a00, "Parameter list length error" },
687 { 0x052000, "Invalid command operation code" },
688 { 0x052100, "Logical block address out of range" },
689 { 0x052102, "Invalid address for write" },
690 { 0x052400, "Invalid field in command packet" },
691 { 0x052600, "Invalid field in parameter list" },
692 { 0x052601, "Parameter not supported" },
693 { 0x052602, "Parameter value invalid" },
694 { 0x052700, "Write protected media" },
695 { 0x052c00, "Command sequence error" },
696 { 0x052c03, "Current program area is not empty" },
697 { 0x052c04, "Current program area is empty" },
698 { 0x053001, "Cannot read medium - unknown format" },
699 { 0x053002, "Cannot read medium - incompatible format" },
700 { 0x053900, "Saving parameters not supported" },
701 { 0x054e00, "Overlapped commands attempted" },
702 { 0x055302, "Medium removal prevented" },
703 { 0x055500, "System resource failure" },
704 { 0x056300, "End of user area encountered on this track" },
705 { 0x056400, "Illegal mode for this track or incompatible medium" },
706 { 0x056f00, "Copy protection key exchange failure - Authentication failure" },
707 { 0x056f01, "Copy protection key exchange failure - Key not present" },
708 { 0x056f02, "Copy protection key exchange failure - Key not established" },
709 { 0x056f03, "Read of scrambled sector without authentication" },
710 { 0x056f04, "Media region code is mismatched to logical unit" },
711 { 0x056f05, "Drive region must be permanent / region reset count error" },
712 { 0x057203, "Session fixation error - incomplete track in session" },
713 { 0x057204, "Empty or partially written reserved track" },
714 { 0x057205, "No more RZONE reservations are allowed" },
715 { 0x05bf00, "Loss of streaming" },
716 { 0x062800, "Not ready to ready transition, medium may have changed" },
717 { 0x062900, "Power on, reset or hardware reset occurred" },
718 { 0x062a00, "Parameters changed" },
719 { 0x062a01, "Mode parameters changed" },
720 { 0x062e00, "Insufficient time for operation" },
721 { 0x063f00, "Logical unit operating conditions have changed" },
722 { 0x063f01, "Microcode has been changed" },
723 { 0x065a00, "Operator request or state change input (unspecified)" },
724 { 0x065a01, "Operator medium removal request" },
725 { 0x0bb900, "Play operation aborted" },
726
727 /* Here we use 0xff for the key (not a valid key) to signify
728 * that these can have _any_ key value associated with them... */
729 { 0xff0401, "Logical unit is in process of becoming ready" },
730 { 0xff0400, "Logical unit not ready, cause not reportable" },
731 { 0xff0402, "Logical unit not ready, initializing command required" },
732 { 0xff0403, "Logical unit not ready, manual intervention required" },
733 { 0xff0500, "Logical unit does not respond to selection" },
734 { 0xff0800, "Logical unit communication failure" },
735 { 0xff0802, "Logical unit communication parity error" },
736 { 0xff0801, "Logical unit communication time-out" },
737 { 0xff2500, "Logical unit not supported" },
738 { 0xff4c00, "Logical unit failed self-configuration" },
739 { 0xff3e00, "Logical unit has not self-configured yet" },
740};
741#endif
742
743 171
744#endif /* _IDE_CD_H */ 172#endif /* _IDE_CD_H */
diff --git a/drivers/ide/ide-cd_ioctl.c b/drivers/ide/ide-cd_ioctl.c
new file mode 100644
index 00000000000..b68284de4e8
--- /dev/null
+++ b/drivers/ide/ide-cd_ioctl.c
@@ -0,0 +1,475 @@
1/*
2 * cdrom.c IOCTLs handling for ide-cd driver.
3 *
4 * Copyright (C) 1994-1996 Scott Snyder <snyder@fnald0.fnal.gov>
5 * Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org>
6 * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de>
7 */
8
9#include <linux/kernel.h>
10#include <linux/cdrom.h>
11#include <linux/ide.h>
12#include <scsi/scsi.h>
13
14#include "ide-cd.h"
15
16/****************************************************************************
17 * Other driver requests (open, close, check media change).
18 */
19int ide_cdrom_open_real(struct cdrom_device_info *cdi, int purpose)
20{
21 return 0;
22}
23
24/*
25 * Close down the device. Invalidate all cached blocks.
26 */
27void ide_cdrom_release_real(struct cdrom_device_info *cdi)
28{
29 ide_drive_t *drive = cdi->handle;
30 struct cdrom_info *cd = drive->driver_data;
31
32 if (!cdi->use_count)
33 cd->cd_flags &= ~IDE_CD_FLAG_TOC_VALID;
34}
35
36/*
37 * add logic to try GET_EVENT command first to check for media and tray
38 * status. this should be supported by newer cd-r/w and all DVD etc
39 * drives
40 */
41int ide_cdrom_drive_status(struct cdrom_device_info *cdi, int slot_nr)
42{
43 ide_drive_t *drive = cdi->handle;
44 struct media_event_desc med;
45 struct request_sense sense;
46 int stat;
47
48 if (slot_nr != CDSL_CURRENT)
49 return -EINVAL;
50
51 stat = cdrom_check_status(drive, &sense);
52 if (!stat || sense.sense_key == UNIT_ATTENTION)
53 return CDS_DISC_OK;
54
55 if (!cdrom_get_media_event(cdi, &med)) {
56 if (med.media_present)
57 return CDS_DISC_OK;
58 else if (med.door_open)
59 return CDS_TRAY_OPEN;
60 else
61 return CDS_NO_DISC;
62 }
63
64 if (sense.sense_key == NOT_READY && sense.asc == 0x04
65 && sense.ascq == 0x04)
66 return CDS_DISC_OK;
67
68 /*
69 * If not using Mt Fuji extended media tray reports,
70 * just return TRAY_OPEN since ATAPI doesn't provide
71 * any other way to detect this...
72 */
73 if (sense.sense_key == NOT_READY) {
74 if (sense.asc == 0x3a && sense.ascq == 1)
75 return CDS_NO_DISC;
76 else
77 return CDS_TRAY_OPEN;
78 }
79 return CDS_DRIVE_NOT_READY;
80}
81
82int ide_cdrom_check_media_change_real(struct cdrom_device_info *cdi,
83 int slot_nr)
84{
85 ide_drive_t *drive = cdi->handle;
86 struct cdrom_info *cd = drive->driver_data;
87 int retval;
88
89 if (slot_nr == CDSL_CURRENT) {
90 (void) cdrom_check_status(drive, NULL);
91 retval = (cd->cd_flags & IDE_CD_FLAG_MEDIA_CHANGED) ? 1 : 0;
92 cd->cd_flags &= ~IDE_CD_FLAG_MEDIA_CHANGED;
93 return retval;
94 } else {
95 return -EINVAL;
96 }
97}
98
99/* Eject the disk if EJECTFLAG is 0.
100 If EJECTFLAG is 1, try to reload the disk. */
101static
102int cdrom_eject(ide_drive_t *drive, int ejectflag,
103 struct request_sense *sense)
104{
105 struct cdrom_info *cd = drive->driver_data;
106 struct cdrom_device_info *cdi = &cd->devinfo;
107 struct request req;
108 char loej = 0x02;
109
110 if ((cd->cd_flags & IDE_CD_FLAG_NO_EJECT) && !ejectflag)
111 return -EDRIVE_CANT_DO_THIS;
112
113 /* reload fails on some drives, if the tray is locked */
114 if ((cd->cd_flags & IDE_CD_FLAG_DOOR_LOCKED) && ejectflag)
115 return 0;
116
117 ide_cd_init_rq(drive, &req);
118
119 /* only tell drive to close tray if open, if it can do that */
120 if (ejectflag && (cdi->mask & CDC_CLOSE_TRAY))
121 loej = 0;
122
123 req.sense = sense;
124 req.cmd[0] = GPCMD_START_STOP_UNIT;
125 req.cmd[4] = loej | (ejectflag != 0);
126
127 return ide_cd_queue_pc(drive, &req);
128}
129
130/* Lock the door if LOCKFLAG is nonzero; unlock it otherwise. */
131static
132int ide_cd_lockdoor(ide_drive_t *drive, int lockflag,
133 struct request_sense *sense)
134{
135 struct cdrom_info *cd = drive->driver_data;
136 struct request_sense my_sense;
137 struct request req;
138 int stat;
139
140 if (sense == NULL)
141 sense = &my_sense;
142
143 /* If the drive cannot lock the door, just pretend. */
144 if (cd->cd_flags & IDE_CD_FLAG_NO_DOORLOCK) {
145 stat = 0;
146 } else {
147 ide_cd_init_rq(drive, &req);
148 req.sense = sense;
149 req.cmd[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
150 req.cmd[4] = lockflag ? 1 : 0;
151 stat = ide_cd_queue_pc(drive, &req);
152 }
153
154 /* If we got an illegal field error, the drive
155 probably cannot lock the door. */
156 if (stat != 0 &&
157 sense->sense_key == ILLEGAL_REQUEST &&
158 (sense->asc == 0x24 || sense->asc == 0x20)) {
159 printk(KERN_ERR "%s: door locking not supported\n",
160 drive->name);
161 cd->cd_flags |= IDE_CD_FLAG_NO_DOORLOCK;
162 stat = 0;
163 }
164
165 /* no medium, that's alright. */
166 if (stat != 0 && sense->sense_key == NOT_READY && sense->asc == 0x3a)
167 stat = 0;
168
169 if (stat == 0) {
170 if (lockflag)
171 cd->cd_flags |= IDE_CD_FLAG_DOOR_LOCKED;
172 else
173 cd->cd_flags &= ~IDE_CD_FLAG_DOOR_LOCKED;
174 }
175
176 return stat;
177}
178
179int ide_cdrom_tray_move(struct cdrom_device_info *cdi, int position)
180{
181 ide_drive_t *drive = cdi->handle;
182 struct request_sense sense;
183
184 if (position) {
185 int stat = ide_cd_lockdoor(drive, 0, &sense);
186
187 if (stat)
188 return stat;
189 }
190
191 return cdrom_eject(drive, !position, &sense);
192}
193
194int ide_cdrom_lock_door(struct cdrom_device_info *cdi, int lock)
195{
196 ide_drive_t *drive = cdi->handle;
197
198 return ide_cd_lockdoor(drive, lock, NULL);
199}
200
201/*
202 * ATAPI devices are free to select the speed you request or any slower
203 * rate. :-( Requesting too fast a speed will _not_ produce an error.
204 */
205int ide_cdrom_select_speed(struct cdrom_device_info *cdi, int speed)
206{
207 ide_drive_t *drive = cdi->handle;
208 struct cdrom_info *cd = drive->driver_data;
209 struct request rq;
210 struct request_sense sense;
211 u8 buf[ATAPI_CAPABILITIES_PAGE_SIZE];
212 int stat;
213
214 ide_cd_init_rq(drive, &rq);
215
216 rq.sense = &sense;
217
218 if (speed == 0)
219 speed = 0xffff; /* set to max */
220 else
221 speed *= 177; /* Nx to kbytes/s */
222
223 rq.cmd[0] = GPCMD_SET_SPEED;
224 /* Read Drive speed in kbytes/second MSB/LSB */
225 rq.cmd[2] = (speed >> 8) & 0xff;
226 rq.cmd[3] = speed & 0xff;
227 if ((cdi->mask & (CDC_CD_R | CDC_CD_RW | CDC_DVD_R)) !=
228 (CDC_CD_R | CDC_CD_RW | CDC_DVD_R)) {
229 /* Write Drive speed in kbytes/second MSB/LSB */
230 rq.cmd[4] = (speed >> 8) & 0xff;
231 rq.cmd[5] = speed & 0xff;
232 }
233
234 stat = ide_cd_queue_pc(drive, &rq);
235
236 if (!ide_cdrom_get_capabilities(drive, buf)) {
237 ide_cdrom_update_speed(drive, buf);
238 cdi->speed = cd->current_speed;
239 }
240
241 return 0;
242}
243
244int ide_cdrom_get_last_session(struct cdrom_device_info *cdi,
245 struct cdrom_multisession *ms_info)
246{
247 struct atapi_toc *toc;
248 ide_drive_t *drive = cdi->handle;
249 struct cdrom_info *info = drive->driver_data;
250 struct request_sense sense;
251 int ret;
252
253 if ((info->cd_flags & IDE_CD_FLAG_TOC_VALID) == 0 || !info->toc) {
254 ret = ide_cd_read_toc(drive, &sense);
255 if (ret)
256 return ret;
257 }
258
259 toc = info->toc;
260 ms_info->addr.lba = toc->last_session_lba;
261 ms_info->xa_flag = toc->xa_flag;
262
263 return 0;
264}
265
266int ide_cdrom_get_mcn(struct cdrom_device_info *cdi,
267 struct cdrom_mcn *mcn_info)
268{
269 ide_drive_t *drive = cdi->handle;
270 int stat, mcnlen;
271 struct request rq;
272 char buf[24];
273
274 ide_cd_init_rq(drive, &rq);
275
276 rq.data = buf;
277 rq.data_len = sizeof(buf);
278
279 rq.cmd[0] = GPCMD_READ_SUBCHANNEL;
280 rq.cmd[1] = 2; /* MSF addressing */
281 rq.cmd[2] = 0x40; /* request subQ data */
282 rq.cmd[3] = 2; /* format */
283 rq.cmd[8] = sizeof(buf);
284
285 stat = ide_cd_queue_pc(drive, &rq);
286 if (stat)
287 return stat;
288
289 mcnlen = sizeof(mcn_info->medium_catalog_number) - 1;
290 memcpy(mcn_info->medium_catalog_number, buf + 9, mcnlen);
291 mcn_info->medium_catalog_number[mcnlen] = '\0';
292
293 return 0;
294}
295
296int ide_cdrom_reset(struct cdrom_device_info *cdi)
297{
298 ide_drive_t *drive = cdi->handle;
299 struct cdrom_info *cd = drive->driver_data;
300 struct request_sense sense;
301 struct request req;
302 int ret;
303
304 ide_cd_init_rq(drive, &req);
305 req.cmd_type = REQ_TYPE_SPECIAL;
306 req.cmd_flags = REQ_QUIET;
307 ret = ide_do_drive_cmd(drive, &req, ide_wait);
308
309 /*
310 * A reset will unlock the door. If it was previously locked,
311 * lock it again.
312 */
313 if (cd->cd_flags & IDE_CD_FLAG_DOOR_LOCKED)
314 (void)ide_cd_lockdoor(drive, 1, &sense);
315
316 return ret;
317}
318
319static int ide_cd_get_toc_entry(ide_drive_t *drive, int track,
320 struct atapi_toc_entry **ent)
321{
322 struct cdrom_info *info = drive->driver_data;
323 struct atapi_toc *toc = info->toc;
324 int ntracks;
325
326 /*
327 * don't serve cached data, if the toc isn't valid
328 */
329 if ((info->cd_flags & IDE_CD_FLAG_TOC_VALID) == 0)
330 return -EINVAL;
331
332 /* Check validity of requested track number. */
333 ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
334
335 if (toc->hdr.first_track == CDROM_LEADOUT)
336 ntracks = 0;
337
338 if (track == CDROM_LEADOUT)
339 *ent = &toc->ent[ntracks];
340 else if (track < toc->hdr.first_track || track > toc->hdr.last_track)
341 return -EINVAL;
342 else
343 *ent = &toc->ent[track - toc->hdr.first_track];
344
345 return 0;
346}
347
348static int ide_cd_fake_play_trkind(ide_drive_t *drive, void *arg)
349{
350 struct cdrom_ti *ti = arg;
351 struct atapi_toc_entry *first_toc, *last_toc;
352 unsigned long lba_start, lba_end;
353 int stat;
354 struct request rq;
355 struct request_sense sense;
356
357 stat = ide_cd_get_toc_entry(drive, ti->cdti_trk0, &first_toc);
358 if (stat)
359 return stat;
360
361 stat = ide_cd_get_toc_entry(drive, ti->cdti_trk1, &last_toc);
362 if (stat)
363 return stat;
364
365 if (ti->cdti_trk1 != CDROM_LEADOUT)
366 ++last_toc;
367 lba_start = first_toc->addr.lba;
368 lba_end = last_toc->addr.lba;
369
370 if (lba_end <= lba_start)
371 return -EINVAL;
372
373 ide_cd_init_rq(drive, &rq);
374
375 rq.sense = &sense;
376 rq.cmd[0] = GPCMD_PLAY_AUDIO_MSF;
377 lba_to_msf(lba_start, &rq.cmd[3], &rq.cmd[4], &rq.cmd[5]);
378 lba_to_msf(lba_end - 1, &rq.cmd[6], &rq.cmd[7], &rq.cmd[8]);
379
380 return ide_cd_queue_pc(drive, &rq);
381}
382
383static int ide_cd_read_tochdr(ide_drive_t *drive, void *arg)
384{
385 struct cdrom_info *cd = drive->driver_data;
386 struct cdrom_tochdr *tochdr = arg;
387 struct atapi_toc *toc;
388 int stat;
389
390 /* Make sure our saved TOC is valid. */
391 stat = ide_cd_read_toc(drive, NULL);
392 if (stat)
393 return stat;
394
395 toc = cd->toc;
396 tochdr->cdth_trk0 = toc->hdr.first_track;
397 tochdr->cdth_trk1 = toc->hdr.last_track;
398
399 return 0;
400}
401
402static int ide_cd_read_tocentry(ide_drive_t *drive, void *arg)
403{
404 struct cdrom_tocentry *tocentry = arg;
405 struct atapi_toc_entry *toce;
406 int stat;
407
408 stat = ide_cd_get_toc_entry(drive, tocentry->cdte_track, &toce);
409 if (stat)
410 return stat;
411
412 tocentry->cdte_ctrl = toce->control;
413 tocentry->cdte_adr = toce->adr;
414 if (tocentry->cdte_format == CDROM_MSF) {
415 lba_to_msf(toce->addr.lba,
416 &tocentry->cdte_addr.msf.minute,
417 &tocentry->cdte_addr.msf.second,
418 &tocentry->cdte_addr.msf.frame);
419 } else
420 tocentry->cdte_addr.lba = toce->addr.lba;
421
422 return 0;
423}
424
425int ide_cdrom_audio_ioctl(struct cdrom_device_info *cdi,
426 unsigned int cmd, void *arg)
427{
428 ide_drive_t *drive = cdi->handle;
429
430 switch (cmd) {
431 /*
432 * emulate PLAY_AUDIO_TI command with PLAY_AUDIO_10, since
433 * atapi doesn't support it
434 */
435 case CDROMPLAYTRKIND:
436 return ide_cd_fake_play_trkind(drive, arg);
437 case CDROMREADTOCHDR:
438 return ide_cd_read_tochdr(drive, arg);
439 case CDROMREADTOCENTRY:
440 return ide_cd_read_tocentry(drive, arg);
441 default:
442 return -EINVAL;
443 }
444}
445
446/* the generic packet interface to cdrom.c */
447int ide_cdrom_packet(struct cdrom_device_info *cdi,
448 struct packet_command *cgc)
449{
450 struct request req;
451 ide_drive_t *drive = cdi->handle;
452
453 if (cgc->timeout <= 0)
454 cgc->timeout = ATAPI_WAIT_PC;
455
456 /* here we queue the commands from the uniform CD-ROM
457 layer. the packet must be complete, as we do not
458 touch it at all. */
459 ide_cd_init_rq(drive, &req);
460 memcpy(req.cmd, cgc->cmd, CDROM_PACKET_SIZE);
461 if (cgc->sense)
462 memset(cgc->sense, 0, sizeof(struct request_sense));
463 req.data = cgc->buffer;
464 req.data_len = cgc->buflen;
465 req.timeout = cgc->timeout;
466
467 if (cgc->quiet)
468 req.cmd_flags |= REQ_QUIET;
469
470 req.sense = cgc->sense;
471 cgc->stat = ide_cd_queue_pc(drive, &req);
472 if (!cgc->stat)
473 cgc->buflen -= req.data_len;
474 return cgc->stat;
475}
diff --git a/drivers/ide/ide-cd_verbose.c b/drivers/ide/ide-cd_verbose.c
new file mode 100644
index 00000000000..6ed7ca07133
--- /dev/null
+++ b/drivers/ide/ide-cd_verbose.c
@@ -0,0 +1,359 @@
1/*
2 * Verbose error logging for ATAPI CD/DVD devices.
3 *
4 * Copyright (C) 1994-1996 Scott Snyder <snyder@fnald0.fnal.gov>
5 * Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org>
6 * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de>
7 */
8
9#include <linux/kernel.h>
10#include <linux/blkdev.h>
11#include <linux/cdrom.h>
12#include <scsi/scsi.h>
13
14#ifndef CONFIG_BLK_DEV_IDECD_VERBOSE_ERRORS
15void ide_cd_log_error(const char *name, struct request *failed_command,
16 struct request_sense *sense)
17{
18 /* Suppress printing unit attention and `in progress of becoming ready'
19 errors when we're not being verbose. */
20 if (sense->sense_key == UNIT_ATTENTION ||
21 (sense->sense_key == NOT_READY && (sense->asc == 4 ||
22 sense->asc == 0x3a)))
23 return;
24
25 printk(KERN_ERR "%s: error code: 0x%02x sense_key: 0x%02x "
26 "asc: 0x%02x ascq: 0x%02x\n",
27 name, sense->error_code, sense->sense_key,
28 sense->asc, sense->ascq);
29}
30#else
31/* The generic packet command opcodes for CD/DVD Logical Units,
32 * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
33static const struct {
34 unsigned short packet_command;
35 const char * const text;
36} packet_command_texts[] = {
37 { GPCMD_TEST_UNIT_READY, "Test Unit Ready" },
38 { GPCMD_REQUEST_SENSE, "Request Sense" },
39 { GPCMD_FORMAT_UNIT, "Format Unit" },
40 { GPCMD_INQUIRY, "Inquiry" },
41 { GPCMD_START_STOP_UNIT, "Start/Stop Unit" },
42 { GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL, "Prevent/Allow Medium Removal" },
43 { GPCMD_READ_FORMAT_CAPACITIES, "Read Format Capacities" },
44 { GPCMD_READ_CDVD_CAPACITY, "Read Cd/Dvd Capacity" },
45 { GPCMD_READ_10, "Read 10" },
46 { GPCMD_WRITE_10, "Write 10" },
47 { GPCMD_SEEK, "Seek" },
48 { GPCMD_WRITE_AND_VERIFY_10, "Write and Verify 10" },
49 { GPCMD_VERIFY_10, "Verify 10" },
50 { GPCMD_FLUSH_CACHE, "Flush Cache" },
51 { GPCMD_READ_SUBCHANNEL, "Read Subchannel" },
52 { GPCMD_READ_TOC_PMA_ATIP, "Read Table of Contents" },
53 { GPCMD_READ_HEADER, "Read Header" },
54 { GPCMD_PLAY_AUDIO_10, "Play Audio 10" },
55 { GPCMD_GET_CONFIGURATION, "Get Configuration" },
56 { GPCMD_PLAY_AUDIO_MSF, "Play Audio MSF" },
57 { GPCMD_PLAYAUDIO_TI, "Play Audio TrackIndex" },
58 { GPCMD_GET_EVENT_STATUS_NOTIFICATION,
59 "Get Event Status Notification" },
60 { GPCMD_PAUSE_RESUME, "Pause/Resume" },
61 { GPCMD_STOP_PLAY_SCAN, "Stop Play/Scan" },
62 { GPCMD_READ_DISC_INFO, "Read Disc Info" },
63 { GPCMD_READ_TRACK_RZONE_INFO, "Read Track Rzone Info" },
64 { GPCMD_RESERVE_RZONE_TRACK, "Reserve Rzone Track" },
65 { GPCMD_SEND_OPC, "Send OPC" },
66 { GPCMD_MODE_SELECT_10, "Mode Select 10" },
67 { GPCMD_REPAIR_RZONE_TRACK, "Repair Rzone Track" },
68 { GPCMD_MODE_SENSE_10, "Mode Sense 10" },
69 { GPCMD_CLOSE_TRACK, "Close Track" },
70 { GPCMD_BLANK, "Blank" },
71 { GPCMD_SEND_EVENT, "Send Event" },
72 { GPCMD_SEND_KEY, "Send Key" },
73 { GPCMD_REPORT_KEY, "Report Key" },
74 { GPCMD_LOAD_UNLOAD, "Load/Unload" },
75 { GPCMD_SET_READ_AHEAD, "Set Read-ahead" },
76 { GPCMD_READ_12, "Read 12" },
77 { GPCMD_GET_PERFORMANCE, "Get Performance" },
78 { GPCMD_SEND_DVD_STRUCTURE, "Send DVD Structure" },
79 { GPCMD_READ_DVD_STRUCTURE, "Read DVD Structure" },
80 { GPCMD_SET_STREAMING, "Set Streaming" },
81 { GPCMD_READ_CD_MSF, "Read CD MSF" },
82 { GPCMD_SCAN, "Scan" },
83 { GPCMD_SET_SPEED, "Set Speed" },
84 { GPCMD_PLAY_CD, "Play CD" },
85 { GPCMD_MECHANISM_STATUS, "Mechanism Status" },
86 { GPCMD_READ_CD, "Read CD" },
87};
88
89/* From Table 303 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
90static const char * const sense_key_texts[16] = {
91 "No sense data",
92 "Recovered error",
93 "Not ready",
94 "Medium error",
95 "Hardware error",
96 "Illegal request",
97 "Unit attention",
98 "Data protect",
99 "Blank check",
100 "(reserved)",
101 "(reserved)",
102 "Aborted command",
103 "(reserved)",
104 "(reserved)",
105 "Miscompare",
106 "(reserved)",
107};
108
109/* From Table 304 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
110static const struct {
111 unsigned long asc_ascq;
112 const char * const text;
113} sense_data_texts[] = {
114 { 0x000000, "No additional sense information" },
115 { 0x000011, "Play operation in progress" },
116 { 0x000012, "Play operation paused" },
117 { 0x000013, "Play operation successfully completed" },
118 { 0x000014, "Play operation stopped due to error" },
119 { 0x000015, "No current audio status to return" },
120 { 0x010c0a, "Write error - padding blocks added" },
121 { 0x011700, "Recovered data with no error correction applied" },
122 { 0x011701, "Recovered data with retries" },
123 { 0x011702, "Recovered data with positive head offset" },
124 { 0x011703, "Recovered data with negative head offset" },
125 { 0x011704, "Recovered data with retries and/or CIRC applied" },
126 { 0x011705, "Recovered data using previous sector ID" },
127 { 0x011800, "Recovered data with error correction applied" },
128 { 0x011801, "Recovered data with error correction and retries applied"},
129 { 0x011802, "Recovered data - the data was auto-reallocated" },
130 { 0x011803, "Recovered data with CIRC" },
131 { 0x011804, "Recovered data with L-EC" },
132 { 0x015d00, "Failure prediction threshold exceeded"
133 " - Predicted logical unit failure" },
134 { 0x015d01, "Failure prediction threshold exceeded"
135 " - Predicted media failure" },
136 { 0x015dff, "Failure prediction threshold exceeded - False" },
137 { 0x017301, "Power calibration area almost full" },
138 { 0x020400, "Logical unit not ready - cause not reportable" },
139 /* Following is misspelled in ATAPI 2.6, _and_ in Mt. Fuji */
140 { 0x020401, "Logical unit not ready"
141 " - in progress [sic] of becoming ready" },
142 { 0x020402, "Logical unit not ready - initializing command required" },
143 { 0x020403, "Logical unit not ready - manual intervention required" },
144 { 0x020404, "Logical unit not ready - format in progress" },
145 { 0x020407, "Logical unit not ready - operation in progress" },
146 { 0x020408, "Logical unit not ready - long write in progress" },
147 { 0x020600, "No reference position found (media may be upside down)" },
148 { 0x023000, "Incompatible medium installed" },
149 { 0x023a00, "Medium not present" },
150 { 0x025300, "Media load or eject failed" },
151 { 0x025700, "Unable to recover table of contents" },
152 { 0x030300, "Peripheral device write fault" },
153 { 0x030301, "No write current" },
154 { 0x030302, "Excessive write errors" },
155 { 0x030c00, "Write error" },
156 { 0x030c01, "Write error - Recovered with auto reallocation" },
157 { 0x030c02, "Write error - auto reallocation failed" },
158 { 0x030c03, "Write error - recommend reassignment" },
159 { 0x030c04, "Compression check miscompare error" },
160 { 0x030c05, "Data expansion occurred during compress" },
161 { 0x030c06, "Block not compressible" },
162 { 0x030c07, "Write error - recovery needed" },
163 { 0x030c08, "Write error - recovery failed" },
164 { 0x030c09, "Write error - loss of streaming" },
165 { 0x031100, "Unrecovered read error" },
166 { 0x031106, "CIRC unrecovered error" },
167 { 0x033101, "Format command failed" },
168 { 0x033200, "No defect spare location available" },
169 { 0x033201, "Defect list update failure" },
170 { 0x035100, "Erase failure" },
171 { 0x037200, "Session fixation error" },
172 { 0x037201, "Session fixation error writin lead-in" },
173 { 0x037202, "Session fixation error writin lead-out" },
174 { 0x037300, "CD control error" },
175 { 0x037302, "Power calibration area is full" },
176 { 0x037303, "Power calibration area error" },
177 { 0x037304, "Program memory area / RMA update failure" },
178 { 0x037305, "Program memory area / RMA is full" },
179 { 0x037306, "Program memory area / RMA is (almost) full" },
180 { 0x040200, "No seek complete" },
181 { 0x040300, "Write fault" },
182 { 0x040900, "Track following error" },
183 { 0x040901, "Tracking servo failure" },
184 { 0x040902, "Focus servo failure" },
185 { 0x040903, "Spindle servo failure" },
186 { 0x041500, "Random positioning error" },
187 { 0x041501, "Mechanical positioning or changer error" },
188 { 0x041502, "Positioning error detected by read of medium" },
189 { 0x043c00, "Mechanical positioning or changer error" },
190 { 0x044000, "Diagnostic failure on component (ASCQ)" },
191 { 0x044400, "Internal CD/DVD logical unit failure" },
192 { 0x04b600, "Media load mechanism failed" },
193 { 0x051a00, "Parameter list length error" },
194 { 0x052000, "Invalid command operation code" },
195 { 0x052100, "Logical block address out of range" },
196 { 0x052102, "Invalid address for write" },
197 { 0x052400, "Invalid field in command packet" },
198 { 0x052600, "Invalid field in parameter list" },
199 { 0x052601, "Parameter not supported" },
200 { 0x052602, "Parameter value invalid" },
201 { 0x052700, "Write protected media" },
202 { 0x052c00, "Command sequence error" },
203 { 0x052c03, "Current program area is not empty" },
204 { 0x052c04, "Current program area is empty" },
205 { 0x053001, "Cannot read medium - unknown format" },
206 { 0x053002, "Cannot read medium - incompatible format" },
207 { 0x053900, "Saving parameters not supported" },
208 { 0x054e00, "Overlapped commands attempted" },
209 { 0x055302, "Medium removal prevented" },
210 { 0x055500, "System resource failure" },
211 { 0x056300, "End of user area encountered on this track" },
212 { 0x056400, "Illegal mode for this track or incompatible medium" },
213 { 0x056f00, "Copy protection key exchange failure"
214 " - Authentication failure" },
215 { 0x056f01, "Copy protection key exchange failure - Key not present" },
216 { 0x056f02, "Copy protection key exchange failure"
217 " - Key not established" },
218 { 0x056f03, "Read of scrambled sector without authentication" },
219 { 0x056f04, "Media region code is mismatched to logical unit" },
220 { 0x056f05, "Drive region must be permanent"
221 " / region reset count error" },
222 { 0x057203, "Session fixation error - incomplete track in session" },
223 { 0x057204, "Empty or partially written reserved track" },
224 { 0x057205, "No more RZONE reservations are allowed" },
225 { 0x05bf00, "Loss of streaming" },
226 { 0x062800, "Not ready to ready transition, medium may have changed" },
227 { 0x062900, "Power on, reset or hardware reset occurred" },
228 { 0x062a00, "Parameters changed" },
229 { 0x062a01, "Mode parameters changed" },
230 { 0x062e00, "Insufficient time for operation" },
231 { 0x063f00, "Logical unit operating conditions have changed" },
232 { 0x063f01, "Microcode has been changed" },
233 { 0x065a00, "Operator request or state change input (unspecified)" },
234 { 0x065a01, "Operator medium removal request" },
235 { 0x0bb900, "Play operation aborted" },
236 /* Here we use 0xff for the key (not a valid key) to signify
237 * that these can have _any_ key value associated with them... */
238 { 0xff0401, "Logical unit is in process of becoming ready" },
239 { 0xff0400, "Logical unit not ready, cause not reportable" },
240 { 0xff0402, "Logical unit not ready, initializing command required" },
241 { 0xff0403, "Logical unit not ready, manual intervention required" },
242 { 0xff0500, "Logical unit does not respond to selection" },
243 { 0xff0800, "Logical unit communication failure" },
244 { 0xff0802, "Logical unit communication parity error" },
245 { 0xff0801, "Logical unit communication time-out" },
246 { 0xff2500, "Logical unit not supported" },
247 { 0xff4c00, "Logical unit failed self-configuration" },
248 { 0xff3e00, "Logical unit has not self-configured yet" },
249};
250
251void ide_cd_log_error(const char *name, struct request *failed_command,
252 struct request_sense *sense)
253{
254 int i;
255 const char *s = "bad sense key!";
256 char buf[80];
257
258 printk(KERN_ERR "ATAPI device %s:\n", name);
259 if (sense->error_code == 0x70)
260 printk(KERN_CONT " Error: ");
261 else if (sense->error_code == 0x71)
262 printk(" Deferred Error: ");
263 else if (sense->error_code == 0x7f)
264 printk(KERN_CONT " Vendor-specific Error: ");
265 else
266 printk(KERN_CONT " Unknown Error Type: ");
267
268 if (sense->sense_key < ARRAY_SIZE(sense_key_texts))
269 s = sense_key_texts[sense->sense_key];
270
271 printk(KERN_CONT "%s -- (Sense key=0x%02x)\n", s, sense->sense_key);
272
273 if (sense->asc == 0x40) {
274 sprintf(buf, "Diagnostic failure on component 0x%02x",
275 sense->ascq);
276 s = buf;
277 } else {
278 int lo = 0, mid, hi = ARRAY_SIZE(sense_data_texts);
279 unsigned long key = (sense->sense_key << 16);
280
281 key |= (sense->asc << 8);
282 if (!(sense->ascq >= 0x80 && sense->ascq <= 0xdd))
283 key |= sense->ascq;
284 s = NULL;
285
286 while (hi > lo) {
287 mid = (lo + hi) / 2;
288 if (sense_data_texts[mid].asc_ascq == key ||
289 sense_data_texts[mid].asc_ascq == (0xff0000|key)) {
290 s = sense_data_texts[mid].text;
291 break;
292 } else if (sense_data_texts[mid].asc_ascq > key)
293 hi = mid;
294 else
295 lo = mid + 1;
296 }
297 }
298
299 if (s == NULL) {
300 if (sense->asc > 0x80)
301 s = "(vendor-specific error)";
302 else
303 s = "(reserved error code)";
304 }
305
306 printk(KERN_ERR " %s -- (asc=0x%02x, ascq=0x%02x)\n",
307 s, sense->asc, sense->ascq);
308
309 if (failed_command != NULL) {
310 int lo = 0, mid, hi = ARRAY_SIZE(packet_command_texts);
311 s = NULL;
312
313 while (hi > lo) {
314 mid = (lo + hi) / 2;
315 if (packet_command_texts[mid].packet_command ==
316 failed_command->cmd[0]) {
317 s = packet_command_texts[mid].text;
318 break;
319 }
320 if (packet_command_texts[mid].packet_command >
321 failed_command->cmd[0])
322 hi = mid;
323 else
324 lo = mid + 1;
325 }
326
327 printk(KERN_ERR " The failed \"%s\" packet command "
328 "was: \n \"", s);
329 for (i = 0; i < sizeof(failed_command->cmd); i++)
330 printk(KERN_CONT "%02x ", failed_command->cmd[i]);
331 printk(KERN_CONT "\"\n");
332 }
333
334 /* The SKSV bit specifies validity of the sense_key_specific
335 * in the next two commands. It is bit 7 of the first byte.
336 * In the case of NOT_READY, if SKSV is set the drive can
337 * give us nice ETA readings.
338 */
339 if (sense->sense_key == NOT_READY && (sense->sks[0] & 0x80)) {
340 int progress = (sense->sks[1] << 8 | sense->sks[2]) * 100;
341
342 printk(KERN_ERR " Command is %02d%% complete\n",
343 progress / 0xffff);
344 }
345
346 if (sense->sense_key == ILLEGAL_REQUEST &&
347 (sense->sks[0] & 0x80) != 0) {
348 printk(KERN_ERR " Error in %s byte %d",
349 (sense->sks[0] & 0x40) != 0 ?
350 "command packet" : "command data",
351 (sense->sks[1] << 8) + sense->sks[2]);
352
353 if ((sense->sks[0] & 0x40) != 0)
354 printk(KERN_CONT " bit %d", sense->sks[0] & 0x07);
355
356 printk(KERN_CONT "\n");
357 }
358}
359#endif
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 717e114ced5..3c69822507e 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -1,10 +1,9 @@
1/* 1/*
2 * linux/drivers/ide/ide-disk.c Version 1.18 Mar 05, 2003 2 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
3 * 3 * Copyright (C) 1998-2002 Linux ATA Development
4 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below) 4 * Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 1998-2002 Linux ATA Development 5 * Copyright (C) 2003 Red Hat <alan@redhat.com>
6 * Andre Hedrick <andre@linux-ide.org> 6 * Copyright (C) 2003-2005, 2007 Bartlomiej Zolnierkiewicz
7 * Copyright (C) 2003 Red Hat <alan@redhat.com>
8 */ 7 */
9 8
10/* 9/*
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 5bf32038dc4..7beaf1e9be1 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -1,15 +1,13 @@
1/* 1/*
2 * linux/drivers/ide/ide-dma.c Version 4.10 June 9, 2000 2 * Copyright (C) 1995-1998 Mark Lord
3 * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org>
4 * Copyright (C) 2004, 2007 Bartlomiej Zolnierkiewicz
3 * 5 *
4 * Copyright (c) 1999-2000 Andre Hedrick <andre@linux-ide.org>
5 * May be copied or modified under the terms of the GNU General Public License 6 * May be copied or modified under the terms of the GNU General Public License
6 */ 7 */
7 8
8/* 9/*
9 * Special Thanks to Mark for his Six years of work. 10 * Special Thanks to Mark for his Six years of work.
10 *
11 * Copyright (c) 1995-1998 Mark Lord
12 * May be copied or modified under the terms of the GNU General Public License
13 */ 11 */
14 12
15/* 13/*
@@ -85,6 +83,7 @@
85#include <linux/ide.h> 83#include <linux/ide.h>
86#include <linux/delay.h> 84#include <linux/delay.h>
87#include <linux/scatterlist.h> 85#include <linux/scatterlist.h>
86#include <linux/dma-mapping.h>
88 87
89#include <asm/io.h> 88#include <asm/io.h>
90#include <asm/irq.h> 89#include <asm/irq.h>
@@ -169,16 +168,15 @@ static int ide_dma_good_drive(ide_drive_t *drive)
169 return ide_in_drive_list(drive->id, drive_whitelist); 168 return ide_in_drive_list(drive->id, drive_whitelist);
170} 169}
171 170
172#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
173/** 171/**
174 * ide_build_sglist - map IDE scatter gather for DMA I/O 172 * ide_build_sglist - map IDE scatter gather for DMA I/O
175 * @drive: the drive to build the DMA table for 173 * @drive: the drive to build the DMA table for
176 * @rq: the request holding the sg list 174 * @rq: the request holding the sg list
177 * 175 *
178 * Perform the PCI mapping magic necessary to access the source or 176 * Perform the DMA mapping magic necessary to access the source or
179 * target buffers of a request via PCI DMA. The lower layers of the 177 * target buffers of a request via DMA. The lower layers of the
180 * kernel provide the necessary cache management so that we can 178 * kernel provide the necessary cache management so that we can
181 * operate in a portable fashion 179 * operate in a portable fashion.
182 */ 180 */
183 181
184int ide_build_sglist(ide_drive_t *drive, struct request *rq) 182int ide_build_sglist(ide_drive_t *drive, struct request *rq)
@@ -186,20 +184,20 @@ int ide_build_sglist(ide_drive_t *drive, struct request *rq)
186 ide_hwif_t *hwif = HWIF(drive); 184 ide_hwif_t *hwif = HWIF(drive);
187 struct scatterlist *sg = hwif->sg_table; 185 struct scatterlist *sg = hwif->sg_table;
188 186
189 BUG_ON((rq->cmd_type == REQ_TYPE_ATA_TASKFILE) && rq->nr_sectors > 256);
190
191 ide_map_sg(drive, rq); 187 ide_map_sg(drive, rq);
192 188
193 if (rq_data_dir(rq) == READ) 189 if (rq_data_dir(rq) == READ)
194 hwif->sg_dma_direction = PCI_DMA_FROMDEVICE; 190 hwif->sg_dma_direction = DMA_FROM_DEVICE;
195 else 191 else
196 hwif->sg_dma_direction = PCI_DMA_TODEVICE; 192 hwif->sg_dma_direction = DMA_TO_DEVICE;
197 193
198 return pci_map_sg(hwif->pci_dev, sg, hwif->sg_nents, hwif->sg_dma_direction); 194 return dma_map_sg(hwif->dev, sg, hwif->sg_nents,
195 hwif->sg_dma_direction);
199} 196}
200 197
201EXPORT_SYMBOL_GPL(ide_build_sglist); 198EXPORT_SYMBOL_GPL(ide_build_sglist);
202 199
200#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
203/** 201/**
204 * ide_build_dmatable - build IDE DMA table 202 * ide_build_dmatable - build IDE DMA table
205 * 203 *
@@ -284,16 +282,17 @@ int ide_build_dmatable (ide_drive_t *drive, struct request *rq)
284 *--table |= cpu_to_le32(0x80000000); 282 *--table |= cpu_to_le32(0x80000000);
285 return count; 283 return count;
286 } 284 }
285
287 printk(KERN_ERR "%s: empty DMA table?\n", drive->name); 286 printk(KERN_ERR "%s: empty DMA table?\n", drive->name);
287
288use_pio_instead: 288use_pio_instead:
289 pci_unmap_sg(hwif->pci_dev, 289 ide_destroy_dmatable(drive);
290 hwif->sg_table, 290
291 hwif->sg_nents,
292 hwif->sg_dma_direction);
293 return 0; /* revert to PIO for this request */ 291 return 0; /* revert to PIO for this request */
294} 292}
295 293
296EXPORT_SYMBOL_GPL(ide_build_dmatable); 294EXPORT_SYMBOL_GPL(ide_build_dmatable);
295#endif
297 296
298/** 297/**
299 * ide_destroy_dmatable - clean up DMA mapping 298 * ide_destroy_dmatable - clean up DMA mapping
@@ -308,15 +307,15 @@ EXPORT_SYMBOL_GPL(ide_build_dmatable);
308 307
309void ide_destroy_dmatable (ide_drive_t *drive) 308void ide_destroy_dmatable (ide_drive_t *drive)
310{ 309{
311 struct pci_dev *dev = HWIF(drive)->pci_dev; 310 ide_hwif_t *hwif = drive->hwif;
312 struct scatterlist *sg = HWIF(drive)->sg_table;
313 int nents = HWIF(drive)->sg_nents;
314 311
315 pci_unmap_sg(dev, sg, nents, HWIF(drive)->sg_dma_direction); 312 dma_unmap_sg(hwif->dev, hwif->sg_table, hwif->sg_nents,
313 hwif->sg_dma_direction);
316} 314}
317 315
318EXPORT_SYMBOL_GPL(ide_destroy_dmatable); 316EXPORT_SYMBOL_GPL(ide_destroy_dmatable);
319 317
318#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
320/** 319/**
321 * config_drive_for_dma - attempt to activate IDE DMA 320 * config_drive_for_dma - attempt to activate IDE DMA
322 * @drive: the drive to place in DMA mode 321 * @drive: the drive to place in DMA mode
@@ -474,8 +473,6 @@ void ide_dma_on(ide_drive_t *drive)
474 drive->hwif->dma_host_set(drive, 1); 473 drive->hwif->dma_host_set(drive, 1);
475} 474}
476 475
477EXPORT_SYMBOL(ide_dma_on);
478
479#ifdef CONFIG_BLK_DEV_IDEDMA_PCI 476#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
480/** 477/**
481 * ide_dma_setup - begin a DMA phase 478 * ide_dma_setup - begin a DMA phase
@@ -847,10 +844,10 @@ EXPORT_SYMBOL(ide_dma_timeout);
847static void ide_release_dma_engine(ide_hwif_t *hwif) 844static void ide_release_dma_engine(ide_hwif_t *hwif)
848{ 845{
849 if (hwif->dmatable_cpu) { 846 if (hwif->dmatable_cpu) {
850 pci_free_consistent(hwif->pci_dev, 847 struct pci_dev *pdev = to_pci_dev(hwif->dev);
851 PRD_ENTRIES * PRD_BYTES, 848
852 hwif->dmatable_cpu, 849 pci_free_consistent(pdev, PRD_ENTRIES * PRD_BYTES,
853 hwif->dmatable_dma); 850 hwif->dmatable_cpu, hwif->dmatable_dma);
854 hwif->dmatable_cpu = NULL; 851 hwif->dmatable_cpu = NULL;
855 } 852 }
856} 853}
@@ -878,7 +875,9 @@ int ide_release_dma(ide_hwif_t *hwif)
878 875
879static int ide_allocate_dma_engine(ide_hwif_t *hwif) 876static int ide_allocate_dma_engine(ide_hwif_t *hwif)
880{ 877{
881 hwif->dmatable_cpu = pci_alloc_consistent(hwif->pci_dev, 878 struct pci_dev *pdev = to_pci_dev(hwif->dev);
879
880 hwif->dmatable_cpu = pci_alloc_consistent(pdev,
882 PRD_ENTRIES * PRD_BYTES, 881 PRD_ENTRIES * PRD_BYTES,
883 &hwif->dmatable_dma); 882 &hwif->dmatable_dma);
884 883
@@ -891,19 +890,19 @@ static int ide_allocate_dma_engine(ide_hwif_t *hwif)
891 return 1; 890 return 1;
892} 891}
893 892
894static int ide_mapped_mmio_dma(ide_hwif_t *hwif, unsigned long base, unsigned int ports) 893static int ide_mapped_mmio_dma(ide_hwif_t *hwif, unsigned long base)
895{ 894{
896 printk(KERN_INFO " %s: MMIO-DMA ", hwif->name); 895 printk(KERN_INFO " %s: MMIO-DMA ", hwif->name);
897 896
898 return 0; 897 return 0;
899} 898}
900 899
901static int ide_iomio_dma(ide_hwif_t *hwif, unsigned long base, unsigned int ports) 900static int ide_iomio_dma(ide_hwif_t *hwif, unsigned long base)
902{ 901{
903 printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx", 902 printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx",
904 hwif->name, base, base + ports - 1); 903 hwif->name, base, base + 7);
905 904
906 if (!request_region(base, ports, hwif->name)) { 905 if (!request_region(base, 8, hwif->name)) {
907 printk(" -- Error, ports in use.\n"); 906 printk(" -- Error, ports in use.\n");
908 return 1; 907 return 1;
909 } 908 }
@@ -915,7 +914,7 @@ static int ide_iomio_dma(ide_hwif_t *hwif, unsigned long base, unsigned int port
915 if (!request_region(hwif->extra_base, 914 if (!request_region(hwif->extra_base,
916 hwif->cds->extra, hwif->cds->name)) { 915 hwif->cds->extra, hwif->cds->name)) {
917 printk(" -- Error, extra ports in use.\n"); 916 printk(" -- Error, extra ports in use.\n");
918 release_region(base, ports); 917 release_region(base, 8);
919 return 1; 918 return 1;
920 } 919 }
921 hwif->extra_ports = hwif->cds->extra; 920 hwif->extra_ports = hwif->cds->extra;
@@ -925,17 +924,19 @@ static int ide_iomio_dma(ide_hwif_t *hwif, unsigned long base, unsigned int port
925 return 0; 924 return 0;
926} 925}
927 926
928static int ide_dma_iobase(ide_hwif_t *hwif, unsigned long base, unsigned int ports) 927static int ide_dma_iobase(ide_hwif_t *hwif, unsigned long base)
929{ 928{
930 if (hwif->mmio) 929 if (hwif->mmio)
931 return ide_mapped_mmio_dma(hwif, base,ports); 930 return ide_mapped_mmio_dma(hwif, base);
932 931
933 return ide_iomio_dma(hwif, base, ports); 932 return ide_iomio_dma(hwif, base);
934} 933}
935 934
936void ide_setup_dma(ide_hwif_t *hwif, unsigned long base, unsigned num_ports) 935void ide_setup_dma(ide_hwif_t *hwif, unsigned long base)
937{ 936{
938 if (ide_dma_iobase(hwif, base, num_ports)) 937 u8 dma_stat;
938
939 if (ide_dma_iobase(hwif, base))
939 return; 940 return;
940 941
941 if (ide_allocate_dma_engine(hwif)) { 942 if (ide_allocate_dma_engine(hwif)) {
@@ -945,16 +946,16 @@ void ide_setup_dma(ide_hwif_t *hwif, unsigned long base, unsigned num_ports)
945 946
946 hwif->dma_base = base; 947 hwif->dma_base = base;
947 948
948 if (!(hwif->dma_command)) 949 if (!hwif->dma_command)
949 hwif->dma_command = hwif->dma_base; 950 hwif->dma_command = hwif->dma_base + 0;
950 if (!(hwif->dma_vendor1)) 951 if (!hwif->dma_vendor1)
951 hwif->dma_vendor1 = (hwif->dma_base + 1); 952 hwif->dma_vendor1 = hwif->dma_base + 1;
952 if (!(hwif->dma_status)) 953 if (!hwif->dma_status)
953 hwif->dma_status = (hwif->dma_base + 2); 954 hwif->dma_status = hwif->dma_base + 2;
954 if (!(hwif->dma_vendor3)) 955 if (!hwif->dma_vendor3)
955 hwif->dma_vendor3 = (hwif->dma_base + 3); 956 hwif->dma_vendor3 = hwif->dma_base + 3;
956 if (!(hwif->dma_prdtable)) 957 if (!hwif->dma_prdtable)
957 hwif->dma_prdtable = (hwif->dma_base + 4); 958 hwif->dma_prdtable = hwif->dma_base + 4;
958 959
959 if (!hwif->dma_host_set) 960 if (!hwif->dma_host_set)
960 hwif->dma_host_set = &ide_dma_host_set; 961 hwif->dma_host_set = &ide_dma_host_set;
@@ -973,13 +974,10 @@ void ide_setup_dma(ide_hwif_t *hwif, unsigned long base, unsigned num_ports)
973 if (!hwif->dma_lost_irq) 974 if (!hwif->dma_lost_irq)
974 hwif->dma_lost_irq = &ide_dma_lost_irq; 975 hwif->dma_lost_irq = &ide_dma_lost_irq;
975 976
976 if (hwif->chipset != ide_trm290) { 977 dma_stat = hwif->INB(hwif->dma_status);
977 u8 dma_stat = hwif->INB(hwif->dma_status); 978 printk(KERN_CONT ", BIOS settings: %s:%s, %s:%s\n",
978 printk(", BIOS settings: %s:%s, %s:%s", 979 hwif->drives[0].name, (dma_stat & 0x20) ? "DMA" : "PIO",
979 hwif->drives[0].name, (dma_stat & 0x20) ? "DMA" : "pio", 980 hwif->drives[1].name, (dma_stat & 0x40) ? "DMA" : "PIO");
980 hwif->drives[1].name, (dma_stat & 0x40) ? "DMA" : "pio");
981 }
982 printk("\n");
983} 981}
984 982
985EXPORT_SYMBOL_GPL(ide_setup_dma); 983EXPORT_SYMBOL_GPL(ide_setup_dma);
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index ff8232ef965..3512637ae8d 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -1,13 +1,12 @@
1/* 1/*
2 * linux/drivers/ide/ide-floppy.c Version 0.99 Feb 24 2002 2 * IDE ATAPI floppy driver.
3 * 3 *
4 * Copyright (C) 1996 - 1999 Gadi Oxman <gadio@netvision.net.il> 4 * Copyright (C) 1996-1999 Gadi Oxman <gadio@netvision.net.il>
5 * Copyright (C) 2000 - 2002 Paul Bristow <paul@paulbristow.net> 5 * Copyright (C) 2000-2002 Paul Bristow <paul@paulbristow.net>
6 * Copyright (C) 2005 Bartlomiej Zolnierkiewicz
6 */ 7 */
7 8
8/* 9/*
9 * IDE ATAPI floppy driver.
10 *
11 * The driver currently doesn't have any fancy features, just the bare 10 * The driver currently doesn't have any fancy features, just the bare
12 * minimum read/write support. 11 * minimum read/write support.
13 * 12 *
@@ -17,67 +16,8 @@
17 * Iomega Zip 100/250 16 * Iomega Zip 100/250
18 * Iomega PC Card Clik!/PocketZip 17 * Iomega PC Card Clik!/PocketZip
19 * 18 *
20 * Many thanks to Lode Leroy <Lode.Leroy@www.ibase.be>, who tested so many 19 * For a historical changelog see
21 * ALPHA patches to this driver on an EASYSTOR LS-120 ATAPI floppy drive. 20 * Documentation/ide/ChangeLog.ide-floppy.1996-2002
22 *
23 * Ver 0.1 Oct 17 96 Initial test version, mostly based on ide-tape.c.
24 * Ver 0.2 Oct 31 96 Minor changes.
25 * Ver 0.3 Dec 2 96 Fixed error recovery bug.
26 * Ver 0.4 Jan 26 97 Add support for the HDIO_GETGEO ioctl.
27 * Ver 0.5 Feb 21 97 Add partitions support.
28 * Use the minimum of the LBA and CHS capacities.
29 * Avoid hwgroup->rq == NULL on the last irq.
30 * Fix potential null dereferencing with DEBUG_LOG.
31 * Ver 0.8 Dec 7 97 Increase irq timeout from 10 to 50 seconds.
32 * Add media write-protect detection.
33 * Issue START command only if TEST UNIT READY fails.
34 * Add work-around for IOMEGA ZIP revision 21.D.
35 * Remove idefloppy_get_capabilities().
36 * Ver 0.9 Jul 4 99 Fix a bug which might have caused the number of
37 * bytes requested on each interrupt to be zero.
38 * Thanks to <shanos@es.co.nz> for pointing this out.
39 * Ver 0.9.sv Jan 6 01 Sam Varshavchik <mrsam@courier-mta.com>
40 * Implement low level formatting. Reimplemented
41 * IDEFLOPPY_CAPABILITIES_PAGE, since we need the srfp
42 * bit. My LS-120 drive barfs on
43 * IDEFLOPPY_CAPABILITIES_PAGE, but maybe it's just me.
44 * Compromise by not reporting a failure to get this
45 * mode page. Implemented four IOCTLs in order to
46 * implement formatting. IOCTls begin with 0x4600,
47 * 0x46 is 'F' as in Format.
48 * Jan 9 01 Userland option to select format verify.
49 * Added PC_SUPPRESS_ERROR flag - some idefloppy drives
50 * do not implement IDEFLOPPY_CAPABILITIES_PAGE, and
51 * return a sense error. Suppress error reporting in
52 * this particular case in order to avoid spurious
53 * errors in syslog. The culprit is
54 * idefloppy_get_capability_page(), so move it to
55 * idefloppy_begin_format() so that it's not used
56 * unless absolutely necessary.
57 * If drive does not support format progress indication
58 * monitor the dsc bit in the status register.
59 * Also, O_NDELAY on open will allow the device to be
60 * opened without a disk available. This can be used to
61 * open an unformatted disk, or get the device capacity.
62 * Ver 0.91 Dec 11 99 Added IOMEGA Clik! drive support by
63 * <paul@paulbristow.net>
64 * Ver 0.92 Oct 22 00 Paul Bristow became official maintainer for this
65 * driver. Included Powerbook internal zip kludge.
66 * Ver 0.93 Oct 24 00 Fixed bugs for Clik! drive
67 * no disk on insert and disk change now works
68 * Ver 0.94 Oct 27 00 Tidied up to remove strstr(Clik) everywhere
69 * Ver 0.95 Nov 7 00 Brought across to kernel 2.4
70 * Ver 0.96 Jan 7 01 Actually in line with release version of 2.4.0
71 * including set_bit patch from Rusty Russell
72 * Ver 0.97 Jul 22 01 Merge 0.91-0.96 onto 0.9.sv for ac series
73 * Ver 0.97.sv Aug 3 01 Backported from 2.4.7-ac3
74 * Ver 0.98 Oct 26 01 Split idefloppy_transfer_pc into two pieces to
75 * fix a lost interrupt problem. It appears the busy
76 * bit was being deasserted by my IOMEGA ATAPI ZIP 100
77 * drive before the drive was actually ready.
78 * Ver 0.98a Oct 29 01 Expose delay value so we can play.
79 * Ver 0.99 Feb 24 02 Remove duplicate code, modify clik! detection code
80 * to support new PocketZip drives
81 */ 21 */
82 22
83#define IDEFLOPPY_VERSION "0.99.newide" 23#define IDEFLOPPY_VERSION "0.99.newide"
@@ -1658,7 +1598,6 @@ static int idefloppy_identify_device (ide_drive_t *drive,struct hd_driveid *id)
1658{ 1598{
1659 struct idefloppy_id_gcw gcw; 1599 struct idefloppy_id_gcw gcw;
1660#if IDEFLOPPY_DEBUG_INFO 1600#if IDEFLOPPY_DEBUG_INFO
1661 u16 mask,i;
1662 char buffer[80]; 1601 char buffer[80];
1663#endif /* IDEFLOPPY_DEBUG_INFO */ 1602#endif /* IDEFLOPPY_DEBUG_INFO */
1664 1603
@@ -1705,55 +1644,6 @@ static int idefloppy_identify_device (ide_drive_t *drive,struct hd_driveid *id)
1705 default: sprintf(buffer, "Reserved");break; 1644 default: sprintf(buffer, "Reserved");break;
1706 } 1645 }
1707 printk(KERN_INFO "Command Packet Size: %s\n", buffer); 1646 printk(KERN_INFO "Command Packet Size: %s\n", buffer);
1708 printk(KERN_INFO "Model: %.40s\n",id->model);
1709 printk(KERN_INFO "Firmware Revision: %.8s\n",id->fw_rev);
1710 printk(KERN_INFO "Serial Number: %.20s\n",id->serial_no);
1711 printk(KERN_INFO "Write buffer size(?): %d bytes\n",id->buf_size*512);
1712 printk(KERN_INFO "DMA: %s",id->capability & 0x01 ? "Yes\n":"No\n");
1713 printk(KERN_INFO "LBA: %s",id->capability & 0x02 ? "Yes\n":"No\n");
1714 printk(KERN_INFO "IORDY can be disabled: %s",id->capability & 0x04 ? "Yes\n":"No\n");
1715 printk(KERN_INFO "IORDY supported: %s",id->capability & 0x08 ? "Yes\n":"Unknown\n");
1716 printk(KERN_INFO "ATAPI overlap supported: %s",id->capability & 0x20 ? "Yes\n":"No\n");
1717 printk(KERN_INFO "PIO Cycle Timing Category: %d\n",id->tPIO);
1718 printk(KERN_INFO "DMA Cycle Timing Category: %d\n",id->tDMA);
1719 printk(KERN_INFO "Single Word DMA supported modes:\n");
1720 for (i=0,mask=1;i<8;i++,mask=mask << 1) {
1721 if (id->dma_1word & mask)
1722 printk(KERN_INFO " Mode %d%s\n", i,
1723 (id->dma_1word & (mask << 8)) ? " (active)" : "");
1724 }
1725 printk(KERN_INFO "Multi Word DMA supported modes:\n");
1726 for (i=0,mask=1;i<8;i++,mask=mask << 1) {
1727 if (id->dma_mword & mask)
1728 printk(KERN_INFO " Mode %d%s\n", i,
1729 (id->dma_mword & (mask << 8)) ? " (active)" : "");
1730 }
1731 if (id->field_valid & 0x0002) {
1732 printk(KERN_INFO "Enhanced PIO Modes: %s\n",
1733 id->eide_pio_modes & 1 ? "Mode 3":"None");
1734 if (id->eide_dma_min == 0)
1735 sprintf(buffer, "Not supported");
1736 else
1737 sprintf(buffer, "%d ns",id->eide_dma_min);
1738 printk(KERN_INFO "Minimum Multi-word DMA cycle per word: %s\n", buffer);
1739 if (id->eide_dma_time == 0)
1740 sprintf(buffer, "Not supported");
1741 else
1742 sprintf(buffer, "%d ns",id->eide_dma_time);
1743 printk(KERN_INFO "Manufacturer\'s Recommended Multi-word cycle: %s\n", buffer);
1744 if (id->eide_pio == 0)
1745 sprintf(buffer, "Not supported");
1746 else
1747 sprintf(buffer, "%d ns",id->eide_pio);
1748 printk(KERN_INFO "Minimum PIO cycle without IORDY: %s\n",
1749 buffer);
1750 if (id->eide_pio_iordy == 0)
1751 sprintf(buffer, "Not supported");
1752 else
1753 sprintf(buffer, "%d ns",id->eide_pio_iordy);
1754 printk(KERN_INFO "Minimum PIO cycle with IORDY: %s\n", buffer);
1755 } else
1756 printk(KERN_INFO "According to the device, fields 64-70 are not valid.\n");
1757#endif /* IDEFLOPPY_DEBUG_INFO */ 1647#endif /* IDEFLOPPY_DEBUG_INFO */
1758 1648
1759 if (gcw.protocol != 2) 1649 if (gcw.protocol != 2)
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index e6bb9cf24e3..4bddef0c0b9 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -1487,7 +1487,7 @@ irqreturn_t ide_intr (int irq, void *dev_id)
1487 * remove all the ifdef PCI crap 1487 * remove all the ifdef PCI crap
1488 */ 1488 */
1489#ifdef CONFIG_BLK_DEV_IDEPCI 1489#ifdef CONFIG_BLK_DEV_IDEPCI
1490 if (hwif->pci_dev && !hwif->pci_dev->vendor) 1490 if (hwif->chipset != ide_pci)
1491#endif /* CONFIG_BLK_DEV_IDEPCI */ 1491#endif /* CONFIG_BLK_DEV_IDEPCI */
1492 { 1492 {
1493 /* 1493 /*
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index e2a7e95e163..16b1f6e1278 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/ide-iops.c Version 0.37 Mar 05, 2003
3 *
4 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2003 Red Hat <alan@redhat.com> 3 * Copyright (C) 2003 Red Hat <alan@redhat.com>
6 * 4 *
@@ -1168,7 +1166,7 @@ EXPORT_SYMBOL(ide_do_reset);
1168 1166
1169/* 1167/*
1170 * ide_wait_not_busy() waits for the currently selected device on the hwif 1168 * ide_wait_not_busy() waits for the currently selected device on the hwif
1171 * to report a non-busy status, see comments in probe_hwif(). 1169 * to report a non-busy status, see comments in ide_probe_port().
1172 */ 1170 */
1173int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout) 1171int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout)
1174{ 1172{
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 9b44fbdfe41..b42940d8bf7 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -358,8 +358,10 @@ void ide_toggle_bounce(ide_drive_t *drive, int on)
358 if (!PCI_DMA_BUS_IS_PHYS) { 358 if (!PCI_DMA_BUS_IS_PHYS) {
359 addr = BLK_BOUNCE_ANY; 359 addr = BLK_BOUNCE_ANY;
360 } else if (on && drive->media == ide_disk) { 360 } else if (on && drive->media == ide_disk) {
361 if (HWIF(drive)->pci_dev) 361 struct device *dev = drive->hwif->dev;
362 addr = HWIF(drive)->pci_dev->dma_mask; 362
363 if (dev && dev->dma_mask)
364 addr = *dev->dma_mask;
363 } 365 }
364 366
365 if (drive->queue) 367 if (drive->queue)
diff --git a/drivers/ide/ide-pnp.c b/drivers/ide/ide-pnp.c
index cbbb0f75be9..4bda5cf2be3 100644
--- a/drivers/ide/ide-pnp.c
+++ b/drivers/ide/ide-pnp.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/ide-pnp.c
3 *
4 * This file provides autodetection for ISA PnP IDE interfaces. 2 * This file provides autodetection for ISA PnP IDE interfaces.
5 * It was tested with "ESS ES1868 Plug and Play AudioDrive" IDE interface. 3 * It was tested with "ESS ES1868 Plug and Play AudioDrive" IDE interface.
6 * 4 *
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index edf650b20c6..98a8af44bf6 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1,7 +1,6 @@
1/* 1/*
2 * linux/drivers/ide/ide-probe.c Version 1.11 Mar 05, 2003 2 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
3 * 3 * Copyright (C) 2005, 2007 Bartlomiej Zolnierkiewicz
4 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
5 */ 4 */
6 5
7/* 6/*
@@ -129,6 +128,10 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
129 128
130 drive->id_read = 1; 129 drive->id_read = 1;
131 local_irq_enable(); 130 local_irq_enable();
131#ifdef DEBUG
132 printk(KERN_INFO "%s: dumping identify data\n", drive->name);
133 ide_dump_identify((u8 *)id);
134#endif
132 ide_fix_driveid(id); 135 ide_fix_driveid(id);
133 136
134#if defined (CONFIG_SCSI_EATA_PIO) || defined (CONFIG_SCSI_EATA) 137#if defined (CONFIG_SCSI_EATA_PIO) || defined (CONFIG_SCSI_EATA)
@@ -610,7 +613,7 @@ static void hwif_release_dev (struct device *dev)
610 complete(&hwif->gendev_rel_comp); 613 complete(&hwif->gendev_rel_comp);
611} 614}
612 615
613static void hwif_register (ide_hwif_t *hwif) 616static void ide_register_port(ide_hwif_t *hwif)
614{ 617{
615 int ret; 618 int ret;
616 619
@@ -618,8 +621,8 @@ static void hwif_register (ide_hwif_t *hwif)
618 strlcpy(hwif->gendev.bus_id,hwif->name,BUS_ID_SIZE); 621 strlcpy(hwif->gendev.bus_id,hwif->name,BUS_ID_SIZE);
619 hwif->gendev.driver_data = hwif; 622 hwif->gendev.driver_data = hwif;
620 if (hwif->gendev.parent == NULL) { 623 if (hwif->gendev.parent == NULL) {
621 if (hwif->pci_dev) 624 if (hwif->dev)
622 hwif->gendev.parent = &hwif->pci_dev->dev; 625 hwif->gendev.parent = hwif->dev;
623 else 626 else
624 /* Would like to do = &device_legacy */ 627 /* Would like to do = &device_legacy */
625 hwif->gendev.parent = NULL; 628 hwif->gendev.parent = NULL;
@@ -631,7 +634,33 @@ static void hwif_register (ide_hwif_t *hwif)
631 __FUNCTION__, ret); 634 __FUNCTION__, ret);
632} 635}
633 636
634static int wait_hwif_ready(ide_hwif_t *hwif) 637/**
638 * ide_port_wait_ready - wait for port to become ready
639 * @hwif: IDE port
640 *
641 * This is needed on some PPCs and a bunch of BIOS-less embedded
642 * platforms. Typical cases are:
643 *
644 * - The firmware hard reset the disk before booting the kernel,
645 * the drive is still doing it's poweron-reset sequence, that
646 * can take up to 30 seconds.
647 *
648 * - The firmware does nothing (or no firmware), the device is
649 * still in POST state (same as above actually).
650 *
651 * - Some CD/DVD/Writer combo drives tend to drive the bus during
652 * their reset sequence even when they are non-selected slave
653 * devices, thus preventing discovery of the main HD.
654 *
655 * Doing this wait-for-non-busy should not harm any existing
656 * configuration and fix some issues like the above.
657 *
658 * BenH.
659 *
660 * Returns 0 on success, error code (< 0) otherwise.
661 */
662
663static int ide_port_wait_ready(ide_hwif_t *hwif)
635{ 664{
636 int unit, rc; 665 int unit, rc;
637 666
@@ -709,36 +738,16 @@ void ide_undecoded_slave(ide_drive_t *drive1)
709 738
710EXPORT_SYMBOL_GPL(ide_undecoded_slave); 739EXPORT_SYMBOL_GPL(ide_undecoded_slave);
711 740
712/* 741static int ide_probe_port(ide_hwif_t *hwif)
713 * This routine only knows how to look for drive units 0 and 1
714 * on an interface, so any setting of MAX_DRIVES > 2 won't work here.
715 */
716static void probe_hwif(ide_hwif_t *hwif)
717{ 742{
718 unsigned long flags; 743 unsigned long flags;
719 unsigned int irqd; 744 unsigned int irqd;
720 int unit; 745 int unit, rc = -ENODEV;
721 746
722 if (hwif->noprobe) 747 BUG_ON(hwif->present);
723 return;
724 748
725 if ((hwif->chipset != ide_4drives || !hwif->mate || !hwif->mate->present) && 749 if (hwif->noprobe)
726 (ide_hwif_request_regions(hwif))) { 750 return -EACCES;
727 u16 msgout = 0;
728 for (unit = 0; unit < MAX_DRIVES; ++unit) {
729 ide_drive_t *drive = &hwif->drives[unit];
730 if (drive->present) {
731 drive->present = 0;
732 printk(KERN_ERR "%s: ERROR, PORTS ALREADY IN USE\n",
733 drive->name);
734 msgout = 1;
735 }
736 }
737 if (!msgout)
738 printk(KERN_ERR "%s: ports already in use, skipping probe\n",
739 hwif->name);
740 return;
741 }
742 751
743 /* 752 /*
744 * We must always disable IRQ, as probe_for_drive will assert IRQ, but 753 * We must always disable IRQ, as probe_for_drive will assert IRQ, but
@@ -750,26 +759,7 @@ static void probe_hwif(ide_hwif_t *hwif)
750 759
751 local_irq_set(flags); 760 local_irq_set(flags);
752 761
753 /* This is needed on some PPCs and a bunch of BIOS-less embedded 762 if (ide_port_wait_ready(hwif) == -EBUSY)
754 * platforms. Typical cases are:
755 *
756 * - The firmware hard reset the disk before booting the kernel,
757 * the drive is still doing it's poweron-reset sequence, that
758 * can take up to 30 seconds
759 * - The firmware does nothing (or no firmware), the device is
760 * still in POST state (same as above actually).
761 * - Some CD/DVD/Writer combo drives tend to drive the bus during
762 * their reset sequence even when they are non-selected slave
763 * devices, thus preventing discovery of the main HD
764 *
765 * Doing this wait-for-busy should not harm any existing configuration
766 * (at least things won't be worse than what current code does, that
767 * is blindly go & talk to the drive) and fix some issues like the
768 * above.
769 *
770 * BenH.
771 */
772 if (wait_hwif_ready(hwif) == -EBUSY)
773 printk(KERN_DEBUG "%s: Wait for ready failed before probe !\n", hwif->name); 763 printk(KERN_DEBUG "%s: Wait for ready failed before probe !\n", hwif->name);
774 764
775 /* 765 /*
@@ -779,14 +769,8 @@ static void probe_hwif(ide_hwif_t *hwif)
779 ide_drive_t *drive = &hwif->drives[unit]; 769 ide_drive_t *drive = &hwif->drives[unit];
780 drive->dn = (hwif->channel ? 2 : 0) + unit; 770 drive->dn = (hwif->channel ? 2 : 0) + unit;
781 (void) probe_for_drive(drive); 771 (void) probe_for_drive(drive);
782 if (drive->present && !hwif->present) { 772 if (drive->present)
783 hwif->present = 1; 773 rc = 0;
784 if (hwif->chipset != ide_4drives ||
785 !hwif->mate ||
786 !hwif->mate->present) {
787 hwif_register(hwif);
788 }
789 }
790 } 774 }
791 if (hwif->io_ports[IDE_CONTROL_OFFSET] && hwif->reset) { 775 if (hwif->io_ports[IDE_CONTROL_OFFSET] && hwif->reset) {
792 printk(KERN_WARNING "%s: reset\n", hwif->name); 776 printk(KERN_WARNING "%s: reset\n", hwif->name);
@@ -803,10 +787,12 @@ static void probe_hwif(ide_hwif_t *hwif)
803 if (irqd) 787 if (irqd)
804 enable_irq(irqd); 788 enable_irq(irqd);
805 789
806 if (!hwif->present) { 790 return rc;
807 ide_hwif_release_regions(hwif); 791}
808 return; 792
809 } 793static void ide_port_tune_devices(ide_hwif_t *hwif)
794{
795 int unit;
810 796
811 for (unit = 0; unit < MAX_DRIVES; unit++) { 797 for (unit = 0; unit < MAX_DRIVES; unit++) {
812 ide_drive_t *drive = &hwif->drives[unit]; 798 ide_drive_t *drive = &hwif->drives[unit];
@@ -997,21 +983,17 @@ static int init_irq (ide_hwif_t *hwif)
997 spin_lock_irq(&ide_lock); 983 spin_lock_irq(&ide_lock);
998 hwif->next = hwgroup->hwif->next; 984 hwif->next = hwgroup->hwif->next;
999 hwgroup->hwif->next = hwif; 985 hwgroup->hwif->next = hwif;
986 BUG_ON(hwif->next == hwif);
1000 spin_unlock_irq(&ide_lock); 987 spin_unlock_irq(&ide_lock);
1001 } else { 988 } else {
1002 hwgroup = kmalloc_node(sizeof(ide_hwgroup_t), 989 hwgroup = kmalloc_node(sizeof(*hwgroup), GFP_KERNEL|__GFP_ZERO,
1003 GFP_KERNEL | __GFP_ZERO, 990 hwif_to_node(hwif));
1004 hwif_to_node(hwif->drives[0].hwif)); 991 if (hwgroup == NULL)
1005 if (!hwgroup) 992 goto out_up;
1006 goto out_up;
1007 993
1008 hwif->hwgroup = hwgroup; 994 hwif->hwgroup = hwgroup;
995 hwgroup->hwif = hwif->next = hwif;
1009 996
1010 hwgroup->hwif = hwif->next = hwif;
1011 hwgroup->rq = NULL;
1012 hwgroup->handler = NULL;
1013 hwgroup->drive = NULL;
1014 hwgroup->busy = 0;
1015 init_timer(&hwgroup->timer); 997 init_timer(&hwgroup->timer);
1016 hwgroup->timer.function = &ide_timer_expiry; 998 hwgroup->timer.function = &ide_timer_expiry;
1017 hwgroup->timer.data = (unsigned long) hwgroup; 999 hwgroup->timer.data = (unsigned long) hwgroup;
@@ -1079,25 +1061,7 @@ static int init_irq (ide_hwif_t *hwif)
1079 mutex_unlock(&ide_cfg_mtx); 1061 mutex_unlock(&ide_cfg_mtx);
1080 return 0; 1062 return 0;
1081out_unlink: 1063out_unlink:
1082 spin_lock_irq(&ide_lock); 1064 ide_remove_port_from_hwgroup(hwif);
1083 if (hwif->next == hwif) {
1084 BUG_ON(match);
1085 BUG_ON(hwgroup->hwif != hwif);
1086 kfree(hwgroup);
1087 } else {
1088 ide_hwif_t *g;
1089 g = hwgroup->hwif;
1090 while (g->next != hwif)
1091 g = g->next;
1092 g->next = hwif->next;
1093 if (hwgroup->hwif == hwif) {
1094 /* Impossible. */
1095 printk(KERN_ERR "Duh. Uninitialized hwif listed as active hwif.\n");
1096 hwgroup->hwif = g;
1097 }
1098 BUG_ON(hwgroup->hwif == hwif);
1099 }
1100 spin_unlock_irq(&ide_lock);
1101out_up: 1065out_up:
1102 mutex_unlock(&ide_cfg_mtx); 1066 mutex_unlock(&ide_cfg_mtx);
1103 return 1; 1067 return 1;
@@ -1246,28 +1210,21 @@ static int hwif_init(ide_hwif_t *hwif)
1246{ 1210{
1247 int old_irq; 1211 int old_irq;
1248 1212
1249 /* Return success if no device is connected */
1250 if (!hwif->present)
1251 return 1;
1252
1253 if (!hwif->irq) { 1213 if (!hwif->irq) {
1254 if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET]))) 1214 if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET])))
1255 { 1215 {
1256 printk("%s: DISABLED, NO IRQ\n", hwif->name); 1216 printk("%s: DISABLED, NO IRQ\n", hwif->name);
1257 return (hwif->present = 0); 1217 return 0;
1258 } 1218 }
1259 } 1219 }
1260#ifdef CONFIG_BLK_DEV_HD 1220#ifdef CONFIG_BLK_DEV_HD
1261 if (hwif->irq == HD_IRQ && hwif->io_ports[IDE_DATA_OFFSET] != HD_DATA) { 1221 if (hwif->irq == HD_IRQ && hwif->io_ports[IDE_DATA_OFFSET] != HD_DATA) {
1262 printk("%s: CANNOT SHARE IRQ WITH OLD " 1222 printk("%s: CANNOT SHARE IRQ WITH OLD "
1263 "HARDDISK DRIVER (hd.c)\n", hwif->name); 1223 "HARDDISK DRIVER (hd.c)\n", hwif->name);
1264 return (hwif->present = 0); 1224 return 0;
1265 } 1225 }
1266#endif /* CONFIG_BLK_DEV_HD */ 1226#endif /* CONFIG_BLK_DEV_HD */
1267 1227
1268 /* we set it back to 1 if all is ok below */
1269 hwif->present = 0;
1270
1271 if (register_blkdev(hwif->major, hwif->name)) 1228 if (register_blkdev(hwif->major, hwif->name))
1272 return 0; 1229 return 0;
1273 1230
@@ -1306,10 +1263,7 @@ static int hwif_init(ide_hwif_t *hwif)
1306 1263
1307done: 1264done:
1308 init_gendisk(hwif); 1265 init_gendisk(hwif);
1309
1310 ide_acpi_init(hwif); 1266 ide_acpi_init(hwif);
1311
1312 hwif->present = 1; /* success */
1313 return 1; 1267 return 1;
1314 1268
1315out: 1269out:
@@ -1344,7 +1298,27 @@ int ide_device_add_all(u8 *idx)
1344 if (idx[i] == 0xff) 1298 if (idx[i] == 0xff)
1345 continue; 1299 continue;
1346 1300
1347 probe_hwif(&ide_hwifs[idx[i]]); 1301 hwif = &ide_hwifs[idx[i]];
1302
1303 if ((hwif->chipset != ide_4drives || !hwif->mate ||
1304 !hwif->mate->present) && ide_hwif_request_regions(hwif)) {
1305 printk(KERN_ERR "%s: ports already in use, "
1306 "skipping probe\n", hwif->name);
1307 continue;
1308 }
1309
1310 if (ide_probe_port(hwif) < 0) {
1311 ide_hwif_release_regions(hwif);
1312 continue;
1313 }
1314
1315 hwif->present = 1;
1316
1317 if (hwif->chipset != ide_4drives || !hwif->mate ||
1318 !hwif->mate->present)
1319 ide_register_port(hwif);
1320
1321 ide_port_tune_devices(hwif);
1348 } 1322 }
1349 1323
1350 for (i = 0; i < MAX_HWIFS; i++) { 1324 for (i = 0; i < MAX_HWIFS; i++) {
@@ -1353,9 +1327,13 @@ int ide_device_add_all(u8 *idx)
1353 1327
1354 hwif = &ide_hwifs[idx[i]]; 1328 hwif = &ide_hwifs[idx[i]];
1355 1329
1330 if (!hwif->present)
1331 continue;
1332
1356 if (hwif_init(hwif) == 0) { 1333 if (hwif_init(hwif) == 0) {
1357 printk(KERN_INFO "%s: failed to initialize IDE " 1334 printk(KERN_INFO "%s: failed to initialize IDE "
1358 "interface\n", hwif->name); 1335 "interface\n", hwif->name);
1336 hwif->present = 0;
1359 rc = -1; 1337 rc = -1;
1360 continue; 1338 continue;
1361 } 1339 }
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index aa663e7f46f..00c249cba23 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/ide-proc.c Version 1.05 Mar 05, 2003
3 *
4 * Copyright (C) 1997-1998 Mark Lord 2 * Copyright (C) 1997-1998 Mark Lord
5 * Copyright (C) 2003 Red Hat <alan@redhat.com> 3 * Copyright (C) 2003 Red Hat <alan@redhat.com>
6 * 4 *
diff --git a/drivers/ide/ide-scan-pci.c b/drivers/ide/ide-scan-pci.c
index 7ffa332d77c..93d2e41be85 100644
--- a/drivers/ide/ide-scan-pci.c
+++ b/drivers/ide/ide-scan-pci.c
@@ -81,7 +81,7 @@ static int __init ide_scan_pcidev(struct pci_dev *dev)
81 * module ordering not traditionally ordered. 81 * module ordering not traditionally ordered.
82 */ 82 */
83 83
84int __init ide_scan_pcibus(void) 84static int __init ide_scan_pcibus(void)
85{ 85{
86 struct pci_dev *dev = NULL; 86 struct pci_dev *dev = NULL;
87 struct pci_driver *d; 87 struct pci_driver *d;
@@ -113,9 +113,4 @@ int __init ide_scan_pcibus(void)
113 return 0; 113 return 0;
114} 114}
115 115
116static int __init ide_scan_pci(void) 116module_init(ide_scan_pcibus);
117{
118 return ide_scan_pcibus();
119}
120
121module_init(ide_scan_pci);
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index d71a584f076..5aef63acf1e 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -1,7 +1,6 @@
1/* 1/*
2 * linux/drivers/ide/ide-tape.c Version 1.19 Nov, 2003 2 * Copyright (C) 1995-1999 Gadi Oxman <gadio@netvision.net.il>
3 * 3 * Copyright (C) 2003-2005 Bartlomiej Zolnierkiewicz
4 * Copyright (C) 1995 - 1999 Gadi Oxman <gadio@netvision.net.il>
5 * 4 *
6 * $Header$ 5 * $Header$
7 * 6 *
@@ -4291,9 +4290,6 @@ static int idetape_identify_device (ide_drive_t *drive)
4291{ 4290{
4292 struct idetape_id_gcw gcw; 4291 struct idetape_id_gcw gcw;
4293 struct hd_driveid *id = drive->id; 4292 struct hd_driveid *id = drive->id;
4294#if IDETAPE_DEBUG_INFO
4295 unsigned short mask,i;
4296#endif /* IDETAPE_DEBUG_INFO */
4297 4293
4298 if (drive->id_read == 0) 4294 if (drive->id_read == 0)
4299 return 1; 4295 return 1;
@@ -4333,62 +4329,6 @@ static int idetape_identify_device (ide_drive_t *drive)
4333 case 1: printk("16 bytes\n");break; 4329 case 1: printk("16 bytes\n");break;
4334 default: printk("Reserved\n");break; 4330 default: printk("Reserved\n");break;
4335 } 4331 }
4336 printk(KERN_INFO "ide-tape: Model: %.40s\n",id->model);
4337 printk(KERN_INFO "ide-tape: Firmware Revision: %.8s\n",id->fw_rev);
4338 printk(KERN_INFO "ide-tape: Serial Number: %.20s\n",id->serial_no);
4339 printk(KERN_INFO "ide-tape: Write buffer size: %d bytes\n",id->buf_size*512);
4340 printk(KERN_INFO "ide-tape: DMA: %s",id->capability & 0x01 ? "Yes\n":"No\n");
4341 printk(KERN_INFO "ide-tape: LBA: %s",id->capability & 0x02 ? "Yes\n":"No\n");
4342 printk(KERN_INFO "ide-tape: IORDY can be disabled: %s",id->capability & 0x04 ? "Yes\n":"No\n");
4343 printk(KERN_INFO "ide-tape: IORDY supported: %s",id->capability & 0x08 ? "Yes\n":"Unknown\n");
4344 printk(KERN_INFO "ide-tape: ATAPI overlap supported: %s",id->capability & 0x20 ? "Yes\n":"No\n");
4345 printk(KERN_INFO "ide-tape: PIO Cycle Timing Category: %d\n",id->tPIO);
4346 printk(KERN_INFO "ide-tape: DMA Cycle Timing Category: %d\n",id->tDMA);
4347 printk(KERN_INFO "ide-tape: Single Word DMA supported modes: ");
4348 for (i=0,mask=1;i<8;i++,mask=mask << 1) {
4349 if (id->dma_1word & mask)
4350 printk("%d ",i);
4351 if (id->dma_1word & (mask << 8))
4352 printk("(active) ");
4353 }
4354 printk("\n");
4355 printk(KERN_INFO "ide-tape: Multi Word DMA supported modes: ");
4356 for (i=0,mask=1;i<8;i++,mask=mask << 1) {
4357 if (id->dma_mword & mask)
4358 printk("%d ",i);
4359 if (id->dma_mword & (mask << 8))
4360 printk("(active) ");
4361 }
4362 printk("\n");
4363 if (id->field_valid & 0x0002) {
4364 printk(KERN_INFO "ide-tape: Enhanced PIO Modes: %s\n",
4365 id->eide_pio_modes & 1 ? "Mode 3":"None");
4366 printk(KERN_INFO "ide-tape: Minimum Multi-word DMA cycle per word: ");
4367 if (id->eide_dma_min == 0)
4368 printk("Not supported\n");
4369 else
4370 printk("%d ns\n",id->eide_dma_min);
4371
4372 printk(KERN_INFO "ide-tape: Manufacturer\'s Recommended Multi-word cycle: ");
4373 if (id->eide_dma_time == 0)
4374 printk("Not supported\n");
4375 else
4376 printk("%d ns\n",id->eide_dma_time);
4377
4378 printk(KERN_INFO "ide-tape: Minimum PIO cycle without IORDY: ");
4379 if (id->eide_pio == 0)
4380 printk("Not supported\n");
4381 else
4382 printk("%d ns\n",id->eide_pio);
4383
4384 printk(KERN_INFO "ide-tape: Minimum PIO cycle with IORDY: ");
4385 if (id->eide_pio_iordy == 0)
4386 printk("Not supported\n");
4387 else
4388 printk("%d ns\n",id->eide_pio_iordy);
4389
4390 } else
4391 printk(KERN_INFO "ide-tape: According to the device, fields 64-70 are not valid.\n");
4392#endif /* IDETAPE_DEBUG_INFO */ 4332#endif /* IDETAPE_DEBUG_INFO */
4393 4333
4394 /* Check that we can support this device */ 4334 /* Check that we can support this device */
@@ -4591,19 +4531,11 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
4591 4531
4592 spin_lock_init(&tape->spinlock); 4532 spin_lock_init(&tape->spinlock);
4593 drive->dsc_overlap = 1; 4533 drive->dsc_overlap = 1;
4594#ifdef CONFIG_BLK_DEV_IDEPCI 4534 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) {
4595 if (HWIF(drive)->pci_dev != NULL) { 4535 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n",
4596 /* 4536 tape->name);
4597 * These two ide-pci host adapters appear to need DSC overlap disabled. 4537 drive->dsc_overlap = 0;
4598 * This probably needs further analysis.
4599 */
4600 if ((HWIF(drive)->pci_dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) ||
4601 (HWIF(drive)->pci_dev->device == PCI_DEVICE_ID_TTI_HPT343)) {
4602 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n", tape->name);
4603 drive->dsc_overlap = 0;
4604 }
4605 } 4538 }
4606#endif /* CONFIG_BLK_DEV_IDEPCI */
4607 /* Seagate Travan drives do not support DSC overlap. */ 4539 /* Seagate Travan drives do not support DSC overlap. */
4608 if (strstr(drive->id->model, "Seagate STT3401")) 4540 if (strstr(drive->id->model, "Seagate STT3401"))
4609 drive->dsc_overlap = 0; 4541 drive->dsc_overlap = 0;
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 5eb6fa15dc4..16a9a581d08 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -1,11 +1,9 @@
1/* 1/*
2 * linux/drivers/ide/ide-taskfile.c Version 0.38 March 05, 2003 2 * Copyright (C) 2000-2002 Michael Cornwell <cornwell@acm.org>
3 * 3 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
4 * Copyright (C) 2000-2002 Michael Cornwell <cornwell@acm.org> 4 * Copyright (C) 2001-2002 Klaus Smolin
5 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
6 * Copyright (C) 2001-2002 Klaus Smolin
7 * IBM Storage Technology Division 5 * IBM Storage Technology Division
8 * Copyright (C) 2003-2004 Bartlomiej Zolnierkiewicz 6 * Copyright (C) 2003-2004, 2007 Bartlomiej Zolnierkiewicz
9 * 7 *
10 * The big the bad and the ugly. 8 * The big the bad and the ugly.
11 */ 9 */
@@ -260,7 +258,7 @@ static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
260 return ide_stopped; 258 return ide_stopped;
261} 259}
262 260
263u8 wait_drive_not_busy(ide_drive_t *drive) 261static u8 wait_drive_not_busy(ide_drive_t *drive)
264{ 262{
265 ide_hwif_t *hwif = HWIF(drive); 263 ide_hwif_t *hwif = HWIF(drive);
266 int retries; 264 int retries;
diff --git a/drivers/ide/ide-timing.h b/drivers/ide/ide-timing.h
index daffbb9797e..adeda762652 100644
--- a/drivers/ide/ide-timing.h
+++ b/drivers/ide/ide-timing.h
@@ -2,8 +2,6 @@
2#define _IDE_TIMING_H 2#define _IDE_TIMING_H
3 3
4/* 4/*
5 * $Id: ide-timing.h,v 1.6 2001/12/23 22:47:56 vojtech Exp $
6 *
7 * Copyright (c) 1999-2001 Vojtech Pavlik 5 * Copyright (c) 1999-2001 Vojtech Pavlik
8 */ 6 */
9 7
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 97894abd9eb..ab9ca2b5b66 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -1,7 +1,6 @@
1/* 1/*
2 * linux/drivers/ide/ide.c Version 7.00beta2 Mar 05 2003 2 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
3 * 3 * Copyrifht (C) 2003-2005, 2007 Bartlomiej Zolnierkiewicz
4 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
5 */ 4 */
6 5
7/* 6/*
@@ -46,7 +45,6 @@
46 */ 45 */
47 46
48#define REVISION "Revision: 7.00alpha2" 47#define REVISION "Revision: 7.00alpha2"
49#define VERSION "Id: ide.c 7.00a2 20020906"
50 48
51#define _IDE_C /* Tell ide.h it's really us */ 49#define _IDE_C /* Tell ide.h it's really us */
52 50
@@ -242,22 +240,12 @@ static int ide_system_bus_speed(void)
242#define pci_default 0 240#define pci_default 0
243#endif /* CONFIG_PCI */ 241#endif /* CONFIG_PCI */
244 242
245 if (!system_bus_speed) { 243 /* user supplied value */
246 if (idebus_parameter) { 244 if (idebus_parameter)
247 /* user supplied value */ 245 return idebus_parameter;
248 system_bus_speed = idebus_parameter; 246
249 } else if (pci_dev_present(pci_default)) { 247 /* safe default value for PCI or VESA and PCI*/
250 /* safe default value for PCI */ 248 return pci_dev_present(pci_default) ? 33 : 50;
251 system_bus_speed = 33;
252 } else {
253 /* safe default value for VESA and PCI */
254 system_bus_speed = 50;
255 }
256 printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
257 "for PIO modes%s\n", system_bus_speed,
258 idebus_parameter ? "" : "; override with idebus=xx");
259 }
260 return system_bus_speed;
261} 249}
262 250
263ide_hwif_t * ide_find_port(unsigned long base) 251ide_hwif_t * ide_find_port(unsigned long base)
@@ -405,8 +393,9 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
405 hwif->chipset = tmp_hwif->chipset; 393 hwif->chipset = tmp_hwif->chipset;
406 hwif->hold = tmp_hwif->hold; 394 hwif->hold = tmp_hwif->hold;
407 395
396 hwif->dev = tmp_hwif->dev;
397
408#ifdef CONFIG_BLK_DEV_IDEPCI 398#ifdef CONFIG_BLK_DEV_IDEPCI
409 hwif->pci_dev = tmp_hwif->pci_dev;
410 hwif->cds = tmp_hwif->cds; 399 hwif->cds = tmp_hwif->cds;
411#endif 400#endif
412 401
@@ -472,6 +461,41 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
472 hwif->hwif_data = tmp_hwif->hwif_data; 461 hwif->hwif_data = tmp_hwif->hwif_data;
473} 462}
474 463
464void ide_remove_port_from_hwgroup(ide_hwif_t *hwif)
465{
466 ide_hwgroup_t *hwgroup = hwif->hwgroup;
467
468 spin_lock_irq(&ide_lock);
469 /*
470 * Remove us from the hwgroup, and free
471 * the hwgroup if we were the only member
472 */
473 if (hwif->next == hwif) {
474 BUG_ON(hwgroup->hwif != hwif);
475 kfree(hwgroup);
476 } else {
477 /* There is another interface in hwgroup.
478 * Unlink us, and set hwgroup->drive and ->hwif to
479 * something sane.
480 */
481 ide_hwif_t *g = hwgroup->hwif;
482
483 while (g->next != hwif)
484 g = g->next;
485 g->next = hwif->next;
486 if (hwgroup->hwif == hwif) {
487 /* Chose a random hwif for hwgroup->hwif.
488 * It's guaranteed that there are no drives
489 * left in the hwgroup.
490 */
491 BUG_ON(hwgroup->drive != NULL);
492 hwgroup->hwif = g;
493 }
494 BUG_ON(hwgroup->hwif == hwif);
495 }
496 spin_unlock_irq(&ide_lock);
497}
498
475/** 499/**
476 * ide_unregister - free an IDE interface 500 * ide_unregister - free an IDE interface
477 * @index: index of interface (will change soon to a pointer) 501 * @index: index of interface (will change soon to a pointer)
@@ -539,43 +563,8 @@ void ide_unregister(unsigned int index)
539 if (irq_count == 1) 563 if (irq_count == 1)
540 free_irq(hwif->irq, hwgroup); 564 free_irq(hwif->irq, hwgroup);
541 565
542 spin_lock_irq(&ide_lock); 566 ide_remove_port_from_hwgroup(hwif);
543 /*
544 * Note that we only release the standard ports,
545 * and do not even try to handle any extra ports
546 * allocated for weird IDE interface chipsets.
547 */
548 ide_hwif_release_regions(hwif);
549
550 /*
551 * Remove us from the hwgroup, and free
552 * the hwgroup if we were the only member
553 */
554 if (hwif->next == hwif) {
555 BUG_ON(hwgroup->hwif != hwif);
556 kfree(hwgroup);
557 } else {
558 /* There is another interface in hwgroup.
559 * Unlink us, and set hwgroup->drive and ->hwif to
560 * something sane.
561 */
562 g = hwgroup->hwif;
563 while (g->next != hwif)
564 g = g->next;
565 g->next = hwif->next;
566 if (hwgroup->hwif == hwif) {
567 /* Chose a random hwif for hwgroup->hwif.
568 * It's guaranteed that there are no drives
569 * left in the hwgroup.
570 */
571 BUG_ON(hwgroup->drive != NULL);
572 hwgroup->hwif = g;
573 }
574 BUG_ON(hwgroup->hwif == hwif);
575 }
576 567
577 /* More messed up locking ... */
578 spin_unlock_irq(&ide_lock);
579 device_unregister(&hwif->gendev); 568 device_unregister(&hwif->gendev);
580 wait_for_completion(&hwif->gendev_rel_comp); 569 wait_for_completion(&hwif->gendev_rel_comp);
581 570
@@ -601,6 +590,13 @@ void ide_unregister(unsigned int index)
601 hwif->extra_ports = 0; 590 hwif->extra_ports = 0;
602 } 591 }
603 592
593 /*
594 * Note that we only release the standard ports,
595 * and do not even try to handle any extra ports
596 * allocated for weird IDE interface chipsets.
597 */
598 ide_hwif_release_regions(hwif);
599
604 /* copy original settings */ 600 /* copy original settings */
605 tmp_hwif = *hwif; 601 tmp_hwif = *hwif;
606 602
@@ -913,7 +909,7 @@ static int set_unmaskirq(ide_drive_t *drive, int arg)
913 909
914int system_bus_clock (void) 910int system_bus_clock (void)
915{ 911{
916 return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed )); 912 return system_bus_speed;
917} 913}
918 914
919EXPORT_SYMBOL(system_bus_clock); 915EXPORT_SYMBOL(system_bus_clock);
@@ -1668,6 +1664,10 @@ static int __init ide_init(void)
1668 printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n"); 1664 printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n");
1669 system_bus_speed = ide_system_bus_speed(); 1665 system_bus_speed = ide_system_bus_speed();
1670 1666
1667 printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
1668 "for PIO modes%s\n", system_bus_speed,
1669 idebus_parameter ? "" : "; override with idebus=xx");
1670
1671 ret = bus_register(&ide_bus_type); 1671 ret = bus_register(&ide_bus_type);
1672 if (ret < 0) { 1672 if (ret < 0) {
1673 printk(KERN_WARNING "IDE: bus_register error: %d\n", ret); 1673 printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/legacy/ali14xx.c
index 5ec0be4cbad..e3ea2096804 100644
--- a/drivers/ide/legacy/ali14xx.c
+++ b/drivers/ide/legacy/ali14xx.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/legacy/ali14xx.c Version 0.03 Feb 09, 1996
3 *
4 * Copyright (C) 1996 Linus Torvalds & author (see below) 2 * Copyright (C) 1996 Linus Torvalds & author (see below)
5 */ 3 */
6 4
diff --git a/drivers/ide/legacy/buddha.c b/drivers/ide/legacy/buddha.c
index 74d28e058f5..dd3d198ade4 100644
--- a/drivers/ide/legacy/buddha.c
+++ b/drivers/ide/legacy/buddha.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/ide/legacy/buddha.c -- Amiga Buddha, Catweasel and X-Surf IDE Driver 2 * Amiga Buddha, Catweasel and X-Surf IDE Driver
3 * 3 *
4 * Copyright (C) 1997, 2001 by Geert Uytterhoeven and others 4 * Copyright (C) 1997, 2001 by Geert Uytterhoeven and others
5 * 5 *
diff --git a/drivers/ide/legacy/dtc2278.c b/drivers/ide/legacy/dtc2278.c
index 13eee6da280..611c9705a3a 100644
--- a/drivers/ide/legacy/dtc2278.c
+++ b/drivers/ide/legacy/dtc2278.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/legacy/dtc2278.c Version 0.02 Feb 10, 1996
3 *
4 * Copyright (C) 1996 Linus Torvalds & author (see below) 2 * Copyright (C) 1996 Linus Torvalds & author (see below)
5 */ 3 */
6 4
diff --git a/drivers/ide/legacy/falconide.c b/drivers/ide/legacy/falconide.c
index 2860956bdcb..c9bd6bfb1f3 100644
--- a/drivers/ide/legacy/falconide.c
+++ b/drivers/ide/legacy/falconide.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/ide/legacy/falconide.c -- Atari Falcon IDE Driver 2 * Atari Falcon IDE Driver
3 * 3 *
4 * Created 12 Jul 1997 by Geert Uytterhoeven 4 * Created 12 Jul 1997 by Geert Uytterhoeven
5 * 5 *
@@ -66,6 +66,7 @@ static int __init falconide_init(void)
66{ 66{
67 if (MACH_IS_ATARI && ATARIHW_PRESENT(IDE)) { 67 if (MACH_IS_ATARI && ATARIHW_PRESENT(IDE)) {
68 hw_regs_t hw; 68 hw_regs_t hw;
69 ide_hwif_t *hwif;
69 70
70 printk(KERN_INFO "ide: Falcon IDE controller\n"); 71 printk(KERN_INFO "ide: Falcon IDE controller\n");
71 72
diff --git a/drivers/ide/legacy/gayle.c b/drivers/ide/legacy/gayle.c
index 492fa047efc..f67c51a2c84 100644
--- a/drivers/ide/legacy/gayle.c
+++ b/drivers/ide/legacy/gayle.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/ide/legacy/gayle.c -- Amiga Gayle IDE Driver 2 * Amiga Gayle IDE Driver
3 * 3 *
4 * Created 9 Jul 1997 by Geert Uytterhoeven 4 * Created 9 Jul 1997 by Geert Uytterhoeven
5 * 5 *
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c
index 8da5031a6d0..57bc15cddca 100644
--- a/drivers/ide/legacy/ht6560b.c
+++ b/drivers/ide/legacy/ht6560b.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/legacy/ht6560b.c Version 0.07 Feb 1, 2000
3 *
4 * Copyright (C) 1995-2000 Linus Torvalds & author (see below) 2 * Copyright (C) 1995-2000 Linus Torvalds & author (see below)
5 */ 3 */
6 4
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index f4ea15b3296..3bd29676ef6 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -2,8 +2,6 @@
2 2
3 A driver for PCMCIA IDE/ATA disk cards 3 A driver for PCMCIA IDE/ATA disk cards
4 4
5 ide-cs.c 1.3 2002/10/26 05:45:31
6
7 The contents of this file are subject to the Mozilla Public 5 The contents of this file are subject to the Mozilla Public
8 License Version 1.1 (the "License"); you may not use this file 6 License Version 1.1 (the "License"); you may not use this file
9 except in compliance with the License. You may obtain a copy of 7 except in compliance with the License. You may obtain a copy of
diff --git a/drivers/ide/legacy/ide_platform.c b/drivers/ide/legacy/ide_platform.c
index 69a0fb0e564..7c3231a21d1 100644
--- a/drivers/ide/legacy/ide_platform.c
+++ b/drivers/ide/legacy/ide_platform.c
@@ -21,13 +21,6 @@
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/io.h> 22#include <linux/io.h>
23 23
24static struct {
25 void __iomem *plat_ide_mapbase;
26 void __iomem *plat_ide_alt_mapbase;
27 ide_hwif_t *hwif;
28 int index;
29} hwif_prop;
30
31static void __devinit plat_ide_setup_ports(hw_regs_t *hw, 24static void __devinit plat_ide_setup_ports(hw_regs_t *hw,
32 void __iomem *base, 25 void __iomem *base,
33 void __iomem *ctrl, 26 void __iomem *ctrl,
@@ -54,6 +47,7 @@ static void __devinit plat_ide_setup_ports(hw_regs_t *hw,
54static int __devinit plat_ide_probe(struct platform_device *pdev) 47static int __devinit plat_ide_probe(struct platform_device *pdev)
55{ 48{
56 struct resource *res_base, *res_alt, *res_irq; 49 struct resource *res_base, *res_alt, *res_irq;
50 void __iomem *base, *alt_base;
57 ide_hwif_t *hwif; 51 ide_hwif_t *hwif;
58 struct pata_platform_info *pdata; 52 struct pata_platform_info *pdata;
59 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; 53 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
@@ -84,27 +78,25 @@ static int __devinit plat_ide_probe(struct platform_device *pdev)
84 } 78 }
85 79
86 if (mmio) { 80 if (mmio) {
87 hwif_prop.plat_ide_mapbase = devm_ioremap(&pdev->dev, 81 base = devm_ioremap(&pdev->dev,
88 res_base->start, res_base->end - res_base->start + 1); 82 res_base->start, res_base->end - res_base->start + 1);
89 hwif_prop.plat_ide_alt_mapbase = devm_ioremap(&pdev->dev, 83 alt_base = devm_ioremap(&pdev->dev,
90 res_alt->start, res_alt->end - res_alt->start + 1); 84 res_alt->start, res_alt->end - res_alt->start + 1);
91 } else { 85 } else {
92 hwif_prop.plat_ide_mapbase = devm_ioport_map(&pdev->dev, 86 base = devm_ioport_map(&pdev->dev,
93 res_base->start, res_base->end - res_base->start + 1); 87 res_base->start, res_base->end - res_base->start + 1);
94 hwif_prop.plat_ide_alt_mapbase = devm_ioport_map(&pdev->dev, 88 alt_base = devm_ioport_map(&pdev->dev,
95 res_alt->start, res_alt->end - res_alt->start + 1); 89 res_alt->start, res_alt->end - res_alt->start + 1);
96 } 90 }
97 91
98 hwif = ide_find_port((unsigned long)hwif_prop.plat_ide_mapbase); 92 hwif = ide_find_port((unsigned long)base);
99 if (!hwif) { 93 if (!hwif) {
100 ret = -ENODEV; 94 ret = -ENODEV;
101 goto out; 95 goto out;
102 } 96 }
103 97
104 memset(&hw, 0, sizeof(hw)); 98 memset(&hw, 0, sizeof(hw));
105 plat_ide_setup_ports(&hw, hwif_prop.plat_ide_mapbase, 99 plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start);
106 hwif_prop.plat_ide_alt_mapbase,
107 pdata, res_irq->start);
108 hw.dev = &pdev->dev; 100 hw.dev = &pdev->dev;
109 101
110 ide_init_port_hw(hwif, &hw); 102 ide_init_port_hw(hwif, &hw);
@@ -114,9 +106,6 @@ static int __devinit plat_ide_probe(struct platform_device *pdev)
114 default_hwif_mmiops(hwif); 106 default_hwif_mmiops(hwif);
115 } 107 }
116 108
117 hwif_prop.hwif = hwif;
118 hwif_prop.index = hwif->index;
119
120 idx[0] = hwif->index; 109 idx[0] = hwif->index;
121 110
122 ide_device_add(idx); 111 ide_device_add(idx);
@@ -133,14 +122,7 @@ static int __devexit plat_ide_remove(struct platform_device *pdev)
133{ 122{
134 ide_hwif_t *hwif = pdev->dev.driver_data; 123 ide_hwif_t *hwif = pdev->dev.driver_data;
135 124
136 if (hwif != hwif_prop.hwif) { 125 ide_unregister(hwif->index);
137 dev_printk(KERN_DEBUG, &pdev->dev, "%s: hwif value error",
138 pdev->name);
139 } else {
140 ide_unregister(hwif_prop.index);
141 hwif_prop.index = 0;
142 hwif_prop.hwif = NULL;
143 }
144 126
145 return 0; 127 return 0;
146} 128}
diff --git a/drivers/ide/legacy/macide.c b/drivers/ide/legacy/macide.c
index 782d4c76c0e..c54d07ff64f 100644
--- a/drivers/ide/legacy/macide.c
+++ b/drivers/ide/legacy/macide.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/ide/legacy/macide.c -- Macintosh IDE Driver 2 * Macintosh IDE Driver
3 * 3 *
4 * Copyright (C) 1998 by Michael Schmitz 4 * Copyright (C) 1998 by Michael Schmitz
5 * 5 *
diff --git a/drivers/ide/legacy/q40ide.c b/drivers/ide/legacy/q40ide.c
index f5329730df9..a9c6b0609c5 100644
--- a/drivers/ide/legacy/q40ide.c
+++ b/drivers/ide/legacy/q40ide.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/ide/legacy/q40ide.c -- Q40 I/O port IDE Driver 2 * Q40 I/O port IDE Driver
3 * 3 *
4 * (c) Richard Zidlicky 4 * (c) Richard Zidlicky
5 * 5 *
diff --git a/drivers/ide/legacy/qd65xx.c b/drivers/ide/legacy/qd65xx.c
index 2bac4c1a653..37534bb483a 100644
--- a/drivers/ide/legacy/qd65xx.c
+++ b/drivers/ide/legacy/qd65xx.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/legacy/qd65xx.c Version 0.07 Sep 30, 2001
3 *
4 * Copyright (C) 1996-2001 Linus Torvalds & author (see below) 2 * Copyright (C) 1996-2001 Linus Torvalds & author (see below)
5 */ 3 */
6 4
diff --git a/drivers/ide/legacy/qd65xx.h b/drivers/ide/legacy/qd65xx.h
index 633a42456ef..28dd50a15d5 100644
--- a/drivers/ide/legacy/qd65xx.h
+++ b/drivers/ide/legacy/qd65xx.h
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/legacy/qd65xx.h
3 *
4 * Copyright (c) 2000 Linus Torvalds & authors 2 * Copyright (c) 2000 Linus Torvalds & authors
5 */ 3 */
6 4
diff --git a/drivers/ide/legacy/umc8672.c b/drivers/ide/legacy/umc8672.c
index a1ae1ae6699..26f38ce5877 100644
--- a/drivers/ide/legacy/umc8672.c
+++ b/drivers/ide/legacy/umc8672.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/legacy/umc8672.c Version 0.05 Jul 31, 1996
3 *
4 * Copyright (C) 1995-1996 Linus Torvalds & author (see below) 2 * Copyright (C) 1995-1996 Linus Torvalds & author (see below)
5 */ 3 */
6 4
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
index 2d3e5115b83..cd42b30a7a3 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/mips/au1xxx-ide.c version 01.30.00 Aug. 02 2005
3 *
4 * BRIEF MODULE DESCRIPTION 2 * BRIEF MODULE DESCRIPTION
5 * AMD Alchemy Au1xxx IDE interface routines over the Static Bus 3 * AMD Alchemy Au1xxx IDE interface routines over the Static Bus
6 * 4 *
@@ -50,7 +48,6 @@
50#include <asm/mach-au1x00/au1xxx_ide.h> 48#include <asm/mach-au1x00/au1xxx_ide.h>
51 49
52#define DRV_NAME "au1200-ide" 50#define DRV_NAME "au1200-ide"
53#define DRV_VERSION "1.0"
54#define DRV_AUTHOR "Enrico Walther <enrico.walther@amd.com> / Pete Popov <ppopov@embeddedalley.com>" 51#define DRV_AUTHOR "Enrico Walther <enrico.walther@amd.com> / Pete Popov <ppopov@embeddedalley.com>"
55 52
56/* enable the burstmode in the dbdma */ 53/* enable the burstmode in the dbdma */
@@ -209,24 +206,6 @@ static void auide_set_dma_mode(ide_drive_t *drive, const u8 speed)
209 */ 206 */
210 207
211#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 208#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
212
213static int auide_build_sglist(ide_drive_t *drive, struct request *rq)
214{
215 ide_hwif_t *hwif = drive->hwif;
216 _auide_hwif *ahwif = (_auide_hwif*)hwif->hwif_data;
217 struct scatterlist *sg = hwif->sg_table;
218
219 ide_map_sg(drive, rq);
220
221 if (rq_data_dir(rq) == READ)
222 hwif->sg_dma_direction = DMA_FROM_DEVICE;
223 else
224 hwif->sg_dma_direction = DMA_TO_DEVICE;
225
226 return dma_map_sg(ahwif->dev, sg, hwif->sg_nents,
227 hwif->sg_dma_direction);
228}
229
230static int auide_build_dmatable(ide_drive_t *drive) 209static int auide_build_dmatable(ide_drive_t *drive)
231{ 210{
232 int i, iswrite, count = 0; 211 int i, iswrite, count = 0;
@@ -241,8 +220,7 @@ static int auide_build_dmatable(ide_drive_t *drive)
241 /* Save for interrupt context */ 220 /* Save for interrupt context */
242 ahwif->drive = drive; 221 ahwif->drive = drive;
243 222
244 /* Build sglist */ 223 hwif->sg_nents = i = ide_build_sglist(drive, rq);
245 hwif->sg_nents = i = auide_build_sglist(drive, rq);
246 224
247 if (!i) 225 if (!i)
248 return 0; 226 return 0;
@@ -300,10 +278,7 @@ static int auide_build_dmatable(ide_drive_t *drive)
300 return 1; 278 return 1;
301 279
302 use_pio_instead: 280 use_pio_instead:
303 dma_unmap_sg(ahwif->dev, 281 ide_destroy_dmatable(drive);
304 hwif->sg_table,
305 hwif->sg_nents,
306 hwif->sg_dma_direction);
307 282
308 return 0; /* revert to PIO for this request */ 283 return 0; /* revert to PIO for this request */
309} 284}
@@ -311,11 +286,9 @@ static int auide_build_dmatable(ide_drive_t *drive)
311static int auide_dma_end(ide_drive_t *drive) 286static int auide_dma_end(ide_drive_t *drive)
312{ 287{
313 ide_hwif_t *hwif = HWIF(drive); 288 ide_hwif_t *hwif = HWIF(drive);
314 _auide_hwif *ahwif = (_auide_hwif*)hwif->hwif_data;
315 289
316 if (hwif->sg_nents) { 290 if (hwif->sg_nents) {
317 dma_unmap_sg(ahwif->dev, hwif->sg_table, hwif->sg_nents, 291 ide_destroy_dmatable(drive);
318 hwif->sg_dma_direction);
319 hwif->sg_nents = 0; 292 hwif->sg_nents = 0;
320 } 293 }
321 294
@@ -504,7 +477,7 @@ static int auide_ddma_init(_auide_hwif *auide) {
504 auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan, 477 auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan,
505 NUM_DESCRIPTORS); 478 NUM_DESCRIPTORS);
506 479
507 hwif->dmatable_cpu = dma_alloc_coherent(auide->dev, 480 hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev,
508 PRD_ENTRIES * PRD_BYTES, /* 1 Page */ 481 PRD_ENTRIES * PRD_BYTES, /* 1 Page */
509 &hwif->dmatable_dma, GFP_KERNEL); 482 &hwif->dmatable_dma, GFP_KERNEL);
510 483
@@ -592,9 +565,6 @@ static int au_ide_probe(struct device *dev)
592#endif 565#endif
593 566
594 memset(&auide_hwif, 0, sizeof(_auide_hwif)); 567 memset(&auide_hwif, 0, sizeof(_auide_hwif));
595 auide_hwif.dev = 0;
596
597 ahwif->dev = dev;
598 ahwif->irq = platform_get_irq(pdev, 0); 568 ahwif->irq = platform_get_irq(pdev, 0);
599 569
600 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 570 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -629,10 +599,13 @@ static int au_ide_probe(struct device *dev)
629 memset(&hw, 0, sizeof(hw)); 599 memset(&hw, 0, sizeof(hw));
630 auide_setup_ports(&hw, ahwif); 600 auide_setup_ports(&hw, ahwif);
631 hw.irq = ahwif->irq; 601 hw.irq = ahwif->irq;
602 hw.dev = dev;
632 hw.chipset = ide_au1xxx; 603 hw.chipset = ide_au1xxx;
633 604
634 ide_init_port_hw(hwif, &hw); 605 ide_init_port_hw(hwif, &hw);
635 606
607 hwif->dev = dev;
608
636 hwif->ultra_mask = 0x0; /* Disable Ultra DMA */ 609 hwif->ultra_mask = 0x0; /* Disable Ultra DMA */
637#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 610#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
638 hwif->mwdma_mask = 0x07; /* Multimode-2 DMA */ 611 hwif->mwdma_mask = 0x07; /* Multimode-2 DMA */
@@ -715,7 +688,7 @@ static int au_ide_remove(struct device *dev)
715 ide_hwif_t *hwif = dev_get_drvdata(dev); 688 ide_hwif_t *hwif = dev_get_drvdata(dev);
716 _auide_hwif *ahwif = &auide_hwif; 689 _auide_hwif *ahwif = &auide_hwif;
717 690
718 ide_unregister(hwif - ide_hwifs); 691 ide_unregister(hwif->index);
719 692
720 iounmap((void *)ahwif->regbase); 693 iounmap((void *)ahwif->regbase);
721 694
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index 7f4d1857d55..824df78c701 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/aec62xx.c Version 0.27 Sep 16, 2007
3 *
4 * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2007 MontaVista Software, Inc. <source@mvista.com> 3 * Copyright (C) 2007 MontaVista Software, Inc. <source@mvista.com>
6 * 4 *
@@ -90,7 +88,7 @@ static u8 pci_bus_clock_list_ultra (u8 speed, struct chipset_bus_clock_list_entr
90static void aec6210_set_mode(ide_drive_t *drive, const u8 speed) 88static void aec6210_set_mode(ide_drive_t *drive, const u8 speed)
91{ 89{
92 ide_hwif_t *hwif = HWIF(drive); 90 ide_hwif_t *hwif = HWIF(drive);
93 struct pci_dev *dev = hwif->pci_dev; 91 struct pci_dev *dev = to_pci_dev(hwif->dev);
94 u16 d_conf = 0; 92 u16 d_conf = 0;
95 u8 ultra = 0, ultra_conf = 0; 93 u8 ultra = 0, ultra_conf = 0;
96 u8 tmp0 = 0, tmp1 = 0, tmp2 = 0; 94 u8 tmp0 = 0, tmp1 = 0, tmp2 = 0;
@@ -116,7 +114,7 @@ static void aec6210_set_mode(ide_drive_t *drive, const u8 speed)
116static void aec6260_set_mode(ide_drive_t *drive, const u8 speed) 114static void aec6260_set_mode(ide_drive_t *drive, const u8 speed)
117{ 115{
118 ide_hwif_t *hwif = HWIF(drive); 116 ide_hwif_t *hwif = HWIF(drive);
119 struct pci_dev *dev = hwif->pci_dev; 117 struct pci_dev *dev = to_pci_dev(hwif->dev);
120 u8 unit = (drive->select.b.unit & 0x01); 118 u8 unit = (drive->select.b.unit & 0x01);
121 u8 tmp1 = 0, tmp2 = 0; 119 u8 tmp1 = 0, tmp2 = 0;
122 u8 ultra = 0, drive_conf = 0, ultra_conf = 0; 120 u8 ultra = 0, drive_conf = 0, ultra_conf = 0;
@@ -170,7 +168,7 @@ static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev, const ch
170 168
171static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif) 169static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif)
172{ 170{
173 struct pci_dev *dev = hwif->pci_dev; 171 struct pci_dev *dev = to_pci_dev(hwif->dev);
174 172
175 hwif->set_pio_mode = &aec_set_pio_mode; 173 hwif->set_pio_mode = &aec_set_pio_mode;
176 174
@@ -188,7 +186,7 @@ static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif)
188 if (hwif->cbl != ATA_CBL_PATA40_SHORT) { 186 if (hwif->cbl != ATA_CBL_PATA40_SHORT) {
189 u8 ata66 = 0, mask = hwif->channel ? 0x02 : 0x01; 187 u8 ata66 = 0, mask = hwif->channel ? 0x02 : 0x01;
190 188
191 pci_read_config_byte(hwif->pci_dev, 0x49, &ata66); 189 pci_read_config_byte(dev, 0x49, &ata66);
192 190
193 hwif->cbl = (ata66 & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80; 191 hwif->cbl = (ata66 & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
194 } 192 }
@@ -202,6 +200,7 @@ static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
202 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, 200 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
203 .host_flags = IDE_HFLAG_SERIALIZE | 201 .host_flags = IDE_HFLAG_SERIALIZE |
204 IDE_HFLAG_NO_ATAPI_DMA | 202 IDE_HFLAG_NO_ATAPI_DMA |
203 IDE_HFLAG_NO_DSC |
205 IDE_HFLAG_ABUSE_SET_DMA_MODE | 204 IDE_HFLAG_ABUSE_SET_DMA_MODE |
206 IDE_HFLAG_OFF_BOARD, 205 IDE_HFLAG_OFF_BOARD,
207 .pio_mask = ATA_PIO4, 206 .pio_mask = ATA_PIO4,
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 49aa82e412b..130cc6e784e 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/alim15x3.c Version 0.29 Sep 16 2007
3 *
4 * Copyright (C) 1998-2000 Michel Aubry, Maintainer 2 * Copyright (C) 1998-2000 Michel Aubry, Maintainer
5 * Copyright (C) 1998-2000 Andrzej Krzysztofowicz, Maintainer 3 * Copyright (C) 1998-2000 Andrzej Krzysztofowicz, Maintainer
6 * Copyright (C) 1999-2000 CJ, cjtsai@ali.com.tw, Maintainer 4 * Copyright (C) 1999-2000 CJ, cjtsai@ali.com.tw, Maintainer
@@ -293,7 +291,7 @@ static int ali_get_info (char *buffer, char **addr, off_t offset, int count)
293static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio) 291static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio)
294{ 292{
295 ide_hwif_t *hwif = HWIF(drive); 293 ide_hwif_t *hwif = HWIF(drive);
296 struct pci_dev *dev = hwif->pci_dev; 294 struct pci_dev *dev = to_pci_dev(hwif->dev);
297 int s_time, a_time, c_time; 295 int s_time, a_time, c_time;
298 u8 s_clc, a_clc, r_clc; 296 u8 s_clc, a_clc, r_clc;
299 unsigned long flags; 297 unsigned long flags;
@@ -396,7 +394,7 @@ static u8 ali_udma_filter(ide_drive_t *drive)
396static void ali_set_dma_mode(ide_drive_t *drive, const u8 speed) 394static void ali_set_dma_mode(ide_drive_t *drive, const u8 speed)
397{ 395{
398 ide_hwif_t *hwif = HWIF(drive); 396 ide_hwif_t *hwif = HWIF(drive);
399 struct pci_dev *dev = hwif->pci_dev; 397 struct pci_dev *dev = to_pci_dev(hwif->dev);
400 u8 speed1 = speed; 398 u8 speed1 = speed;
401 u8 unit = (drive->select.b.unit & 0x01); 399 u8 unit = (drive->select.b.unit & 0x01);
402 u8 tmpbyte = 0x00; 400 u8 tmpbyte = 0x00;
@@ -625,7 +623,7 @@ static int ali_cable_override(struct pci_dev *pdev)
625 623
626static u8 __devinit ata66_ali15x3(ide_hwif_t *hwif) 624static u8 __devinit ata66_ali15x3(ide_hwif_t *hwif)
627{ 625{
628 struct pci_dev *dev = hwif->pci_dev; 626 struct pci_dev *dev = to_pci_dev(hwif->dev);
629 unsigned long flags; 627 unsigned long flags;
630 u8 cbl = ATA_CBL_PATA40, tmpbyte; 628 u8 cbl = ATA_CBL_PATA40, tmpbyte;
631 629
@@ -688,12 +686,13 @@ static void __devinit init_hwif_common_ali15x3 (ide_hwif_t *hwif)
688 686
689static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif) 687static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif)
690{ 688{
689 struct pci_dev *dev = to_pci_dev(hwif->dev);
691 u8 ideic, inmir; 690 u8 ideic, inmir;
692 s8 irq_routing_table[] = { -1, 9, 3, 10, 4, 5, 7, 6, 691 s8 irq_routing_table[] = { -1, 9, 3, 10, 4, 5, 7, 6,
693 1, 11, 0, 12, 0, 14, 0, 15 }; 692 1, 11, 0, 12, 0, 14, 0, 15 };
694 int irq = -1; 693 int irq = -1;
695 694
696 if (hwif->pci_dev->device == PCI_DEVICE_ID_AL_M5229) 695 if (dev->device == PCI_DEVICE_ID_AL_M5229)
697 hwif->irq = hwif->channel ? 15 : 14; 696 hwif->irq = hwif->channel ? 15 : 14;
698 697
699 if (isa_dev) { 698 if (isa_dev) {
@@ -745,7 +744,7 @@ static void __devinit init_dma_ali15x3 (ide_hwif_t *hwif, unsigned long dmabase)
745 return; 744 return;
746 if (!hwif->channel) 745 if (!hwif->channel)
747 outb(inb(dmabase + 2) & 0x60, dmabase + 2); 746 outb(inb(dmabase + 2) & 0x60, dmabase + 2);
748 ide_setup_dma(hwif, dmabase, 8); 747 ide_setup_dma(hwif, dmabase);
749} 748}
750 749
751static const struct ide_port_info ali15x3_chipset __devinitdata = { 750static const struct ide_port_info ali15x3_chipset __devinitdata = {
@@ -775,7 +774,7 @@ static int __devinit alim15x3_init_one(struct pci_dev *dev, const struct pci_dev
775 }; 774 };
776 775
777 struct ide_port_info d = ali15x3_chipset; 776 struct ide_port_info d = ali15x3_chipset;
778 u8 rev = dev->revision; 777 u8 rev = dev->revision, idx = id->driver_data;
779 778
780 if (pci_dev_present(ati_rs100)) 779 if (pci_dev_present(ati_rs100))
781 printk(KERN_WARNING "alim15x3: ATI Radeon IGP Northbridge is not yet fully tested.\n"); 780 printk(KERN_WARNING "alim15x3: ATI Radeon IGP Northbridge is not yet fully tested.\n");
@@ -798,6 +797,9 @@ static int __devinit alim15x3_init_one(struct pci_dev *dev, const struct pci_dev
798 d.udma_mask = ATA_UDMA6; 797 d.udma_mask = ATA_UDMA6;
799 } 798 }
800 799
800 if (idx == 0)
801 d.host_flags |= IDE_HFLAG_CLEAR_SIMPLEX;
802
801#if defined(CONFIG_SPARC64) 803#if defined(CONFIG_SPARC64)
802 d.init_hwif = init_hwif_common_ali15x3; 804 d.init_hwif = init_hwif_common_ali15x3;
803#endif /* CONFIG_SPARC64 */ 805#endif /* CONFIG_SPARC64 */
@@ -807,7 +809,7 @@ static int __devinit alim15x3_init_one(struct pci_dev *dev, const struct pci_dev
807 809
808static const struct pci_device_id alim15x3_pci_tbl[] = { 810static const struct pci_device_id alim15x3_pci_tbl[] = {
809 { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5229), 0 }, 811 { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5229), 0 },
810 { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5228), 0 }, 812 { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5228), 1 },
811 { 0, }, 813 { 0, },
812}; 814};
813MODULE_DEVICE_TABLE(pci, alim15x3_pci_tbl); 815MODULE_DEVICE_TABLE(pci, alim15x3_pci_tbl);
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index cee51fdafcf..8c52bc9eaa5 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * Version 2.24
3 *
4 * AMD 755/756/766/8111 and nVidia nForce/2/2s/3/3s/CK804/MCP04 2 * AMD 755/756/766/8111 and nVidia nForce/2/2s/3/3s/CK804/MCP04
5 * IDE driver for Linux. 3 * IDE driver for Linux.
6 * 4 *
@@ -28,81 +26,46 @@
28 26
29#include "ide-timing.h" 27#include "ide-timing.h"
30 28
31#define AMD_IDE_CONFIG (0x01 + amd_config->base) 29enum {
32#define AMD_CABLE_DETECT (0x02 + amd_config->base) 30 AMD_IDE_CONFIG = 0x41,
33#define AMD_DRIVE_TIMING (0x08 + amd_config->base) 31 AMD_CABLE_DETECT = 0x42,
34#define AMD_8BIT_TIMING (0x0e + amd_config->base) 32 AMD_DRIVE_TIMING = 0x48,
35#define AMD_ADDRESS_SETUP (0x0c + amd_config->base) 33 AMD_8BIT_TIMING = 0x4e,
36#define AMD_UDMA_TIMING (0x10 + amd_config->base) 34 AMD_ADDRESS_SETUP = 0x4c,
37 35 AMD_UDMA_TIMING = 0x50,
38#define AMD_CHECK_SWDMA 0x08
39#define AMD_BAD_SWDMA 0x10
40#define AMD_BAD_FIFO 0x20
41#define AMD_CHECK_SERENADE 0x40
42
43/*
44 * AMD SouthBridge chips.
45 */
46
47static struct amd_ide_chip {
48 unsigned short id;
49 u8 base;
50 u8 udma_mask;
51 u8 flags;
52} amd_ide_chips[] = {
53 { PCI_DEVICE_ID_AMD_COBRA_7401, 0x40, ATA_UDMA2, AMD_BAD_SWDMA },
54 { PCI_DEVICE_ID_AMD_VIPER_7409, 0x40, ATA_UDMA4, AMD_CHECK_SWDMA },
55 { PCI_DEVICE_ID_AMD_VIPER_7411, 0x40, ATA_UDMA5, AMD_BAD_FIFO },
56 { PCI_DEVICE_ID_AMD_OPUS_7441, 0x40, ATA_UDMA5, },
57 { PCI_DEVICE_ID_AMD_8111_IDE, 0x40, ATA_UDMA6, AMD_CHECK_SERENADE },
58 { PCI_DEVICE_ID_NVIDIA_NFORCE_IDE, 0x50, ATA_UDMA5, },
59 { PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE, 0x50, ATA_UDMA6, },
60 { PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE, 0x50, ATA_UDMA6, },
61 { PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA, 0x50, ATA_UDMA6, },
62 { PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE, 0x50, ATA_UDMA6, },
63 { PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE, 0x50, ATA_UDMA6, },
64 { PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA, 0x50, ATA_UDMA6, },
65 { PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2, 0x50, ATA_UDMA6, },
66 { PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE, 0x50, ATA_UDMA6, },
67 { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE, 0x50, ATA_UDMA6, },
68 { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE, 0x50, ATA_UDMA6, },
69 { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE, 0x50, ATA_UDMA6, },
70 { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE, 0x50, ATA_UDMA6, },
71 { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE, 0x50, ATA_UDMA6, },
72 { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE, 0x50, ATA_UDMA6, },
73 { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP73_IDE, 0x50, ATA_UDMA6, },
74 { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP77_IDE, 0x50, ATA_UDMA6, },
75 { PCI_DEVICE_ID_AMD_CS5536_IDE, 0x40, ATA_UDMA5, },
76 { 0 }
77}; 36};
78 37
79static struct amd_ide_chip *amd_config;
80static const struct ide_port_info *amd_chipset;
81static unsigned int amd_80w; 38static unsigned int amd_80w;
82static unsigned int amd_clock; 39static unsigned int amd_clock;
83 40
84static char *amd_dma[] = { "16", "25", "33", "44", "66", "100", "133" }; 41static char *amd_dma[] = { "16", "25", "33", "44", "66", "100", "133" };
85static unsigned char amd_cyc2udma[] = { 6, 6, 5, 4, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 7 }; 42static unsigned char amd_cyc2udma[] = { 6, 6, 5, 4, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 7 };
86 43
44static inline u8 amd_offset(struct pci_dev *dev)
45{
46 return (dev->vendor == PCI_VENDOR_ID_NVIDIA) ? 0x10 : 0;
47}
48
87/* 49/*
88 * amd_set_speed() writes timing values to the chipset registers 50 * amd_set_speed() writes timing values to the chipset registers
89 */ 51 */
90 52
91static void amd_set_speed(struct pci_dev *dev, unsigned char dn, struct ide_timing *timing) 53static void amd_set_speed(struct pci_dev *dev, u8 dn, u8 udma_mask,
54 struct ide_timing *timing)
92{ 55{
93 unsigned char t; 56 u8 t = 0, offset = amd_offset(dev);
94 57
95 pci_read_config_byte(dev, AMD_ADDRESS_SETUP, &t); 58 pci_read_config_byte(dev, AMD_ADDRESS_SETUP + offset, &t);
96 t = (t & ~(3 << ((3 - dn) << 1))) | ((FIT(timing->setup, 1, 4) - 1) << ((3 - dn) << 1)); 59 t = (t & ~(3 << ((3 - dn) << 1))) | ((FIT(timing->setup, 1, 4) - 1) << ((3 - dn) << 1));
97 pci_write_config_byte(dev, AMD_ADDRESS_SETUP, t); 60 pci_write_config_byte(dev, AMD_ADDRESS_SETUP + offset, t);
98 61
99 pci_write_config_byte(dev, AMD_8BIT_TIMING + (1 - (dn >> 1)), 62 pci_write_config_byte(dev, AMD_8BIT_TIMING + offset + (1 - (dn >> 1)),
100 ((FIT(timing->act8b, 1, 16) - 1) << 4) | (FIT(timing->rec8b, 1, 16) - 1)); 63 ((FIT(timing->act8b, 1, 16) - 1) << 4) | (FIT(timing->rec8b, 1, 16) - 1));
101 64
102 pci_write_config_byte(dev, AMD_DRIVE_TIMING + (3 - dn), 65 pci_write_config_byte(dev, AMD_DRIVE_TIMING + offset + (3 - dn),
103 ((FIT(timing->active, 1, 16) - 1) << 4) | (FIT(timing->recover, 1, 16) - 1)); 66 ((FIT(timing->active, 1, 16) - 1) << 4) | (FIT(timing->recover, 1, 16) - 1));
104 67
105 switch (amd_config->udma_mask) { 68 switch (udma_mask) {
106 case ATA_UDMA2: t = timing->udma ? (0xc0 | (FIT(timing->udma, 2, 5) - 2)) : 0x03; break; 69 case ATA_UDMA2: t = timing->udma ? (0xc0 | (FIT(timing->udma, 2, 5) - 2)) : 0x03; break;
107 case ATA_UDMA4: t = timing->udma ? (0xc0 | amd_cyc2udma[FIT(timing->udma, 2, 10)]) : 0x03; break; 70 case ATA_UDMA4: t = timing->udma ? (0xc0 | amd_cyc2udma[FIT(timing->udma, 2, 10)]) : 0x03; break;
108 case ATA_UDMA5: t = timing->udma ? (0xc0 | amd_cyc2udma[FIT(timing->udma, 1, 10)]) : 0x03; break; 71 case ATA_UDMA5: t = timing->udma ? (0xc0 | amd_cyc2udma[FIT(timing->udma, 1, 10)]) : 0x03; break;
@@ -110,7 +73,7 @@ static void amd_set_speed(struct pci_dev *dev, unsigned char dn, struct ide_timi
110 default: return; 73 default: return;
111 } 74 }
112 75
113 pci_write_config_byte(dev, AMD_UDMA_TIMING + (3 - dn), t); 76 pci_write_config_byte(dev, AMD_UDMA_TIMING + offset + (3 - dn), t);
114} 77}
115 78
116/* 79/*
@@ -120,12 +83,15 @@ static void amd_set_speed(struct pci_dev *dev, unsigned char dn, struct ide_timi
120 83
121static void amd_set_drive(ide_drive_t *drive, const u8 speed) 84static void amd_set_drive(ide_drive_t *drive, const u8 speed)
122{ 85{
123 ide_drive_t *peer = HWIF(drive)->drives + (~drive->dn & 1); 86 ide_hwif_t *hwif = drive->hwif;
87 struct pci_dev *dev = to_pci_dev(hwif->dev);
88 ide_drive_t *peer = hwif->drives + (~drive->dn & 1);
124 struct ide_timing t, p; 89 struct ide_timing t, p;
125 int T, UT; 90 int T, UT;
91 u8 udma_mask = hwif->ultra_mask;
126 92
127 T = 1000000000 / amd_clock; 93 T = 1000000000 / amd_clock;
128 UT = (amd_config->udma_mask == ATA_UDMA2) ? T : (T / 2); 94 UT = (udma_mask == ATA_UDMA2) ? T : (T / 2);
129 95
130 ide_timing_compute(drive, speed, &t, T, UT); 96 ide_timing_compute(drive, speed, &t, T, UT);
131 97
@@ -137,7 +103,7 @@ static void amd_set_drive(ide_drive_t *drive, const u8 speed)
137 if (speed == XFER_UDMA_5 && amd_clock <= 33333) t.udma = 1; 103 if (speed == XFER_UDMA_5 && amd_clock <= 33333) t.udma = 1;
138 if (speed == XFER_UDMA_6 && amd_clock <= 33333) t.udma = 15; 104 if (speed == XFER_UDMA_6 && amd_clock <= 33333) t.udma = 15;
139 105
140 amd_set_speed(HWIF(drive)->pci_dev, drive->dn, &t); 106 amd_set_speed(dev, drive->dn, udma_mask, &t);
141} 107}
142 108
143/* 109/*
@@ -149,67 +115,68 @@ static void amd_set_pio_mode(ide_drive_t *drive, const u8 pio)
149 amd_set_drive(drive, XFER_PIO_0 + pio); 115 amd_set_drive(drive, XFER_PIO_0 + pio);
150} 116}
151 117
152/* 118static void __devinit amd7409_cable_detect(struct pci_dev *dev,
153 * The initialization callback. Here we determine the IDE chip type 119 const char *name)
154 * and initialize its drive independent registers. 120{
155 */ 121 /* no host side cable detection */
122 amd_80w = 0x03;
123}
156 124
157static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev, const char *name) 125static void __devinit amd7411_cable_detect(struct pci_dev *dev,
126 const char *name)
158{ 127{
159 unsigned char t;
160 unsigned int u;
161 int i; 128 int i;
129 u32 u = 0;
130 u8 t = 0, offset = amd_offset(dev);
131
132 pci_read_config_byte(dev, AMD_CABLE_DETECT + offset, &t);
133 pci_read_config_dword(dev, AMD_UDMA_TIMING + offset, &u);
134 amd_80w = ((t & 0x3) ? 1 : 0) | ((t & 0xc) ? 2 : 0);
135 for (i = 24; i >= 0; i -= 8)
136 if (((u >> i) & 4) && !(amd_80w & (1 << (1 - (i >> 4))))) {
137 printk(KERN_WARNING "%s: BIOS didn't set cable bits "
138 "correctly. Enabling workaround.\n",
139 name);
140 amd_80w |= (1 << (1 - (i >> 4)));
141 }
142}
162 143
163/* 144/*
164 * Check for bad SWDMA. 145 * The initialization callback. Initialize drive independent registers.
165 */ 146 */
166 147
167 if (amd_config->flags & AMD_CHECK_SWDMA) { 148static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev,
168 if (dev->revision <= 7) 149 const char *name)
169 amd_config->flags |= AMD_BAD_SWDMA; 150{
170 } 151 u8 t = 0, offset = amd_offset(dev);
171 152
172/* 153/*
173 * Check 80-wire cable presence. 154 * Check 80-wire cable presence.
174 */ 155 */
175 156
176 switch (amd_config->udma_mask) { 157 if (dev->vendor == PCI_VENDOR_ID_AMD &&
177 158 dev->device == PCI_DEVICE_ID_AMD_COBRA_7401)
178 case ATA_UDMA6: 159 ; /* no UDMA > 2 */
179 case ATA_UDMA5: 160 else if (dev->vendor == PCI_VENDOR_ID_AMD &&
180 pci_read_config_byte(dev, AMD_CABLE_DETECT, &t); 161 dev->device == PCI_DEVICE_ID_AMD_VIPER_7409)
181 pci_read_config_dword(dev, AMD_UDMA_TIMING, &u); 162 amd7409_cable_detect(dev, name);
182 amd_80w = ((t & 0x3) ? 1 : 0) | ((t & 0xc) ? 2 : 0); 163 else
183 for (i = 24; i >= 0; i -= 8) 164 amd7411_cable_detect(dev, name);
184 if (((u >> i) & 4) && !(amd_80w & (1 << (1 - (i >> 4))))) {
185 printk(KERN_WARNING "%s: BIOS didn't set cable bits correctly. Enabling workaround.\n",
186 amd_chipset->name);
187 amd_80w |= (1 << (1 - (i >> 4)));
188 }
189 break;
190
191 case ATA_UDMA4:
192 /* no host side cable detection */
193 amd_80w = 0x03;
194 break;
195 }
196 165
197/* 166/*
198 * Take care of prefetch & postwrite. 167 * Take care of prefetch & postwrite.
199 */ 168 */
200 169
201 pci_read_config_byte(dev, AMD_IDE_CONFIG, &t); 170 pci_read_config_byte(dev, AMD_IDE_CONFIG + offset, &t);
202 pci_write_config_byte(dev, AMD_IDE_CONFIG, 171 /*
203 (amd_config->flags & AMD_BAD_FIFO) ? (t & 0x0f) : (t | 0xf0)); 172 * Check for broken FIFO support.
204 173 */
205/* 174 if (dev->vendor == PCI_VENDOR_ID_AMD &&
206 * Take care of incorrectly wired Serenade mainboards. 175 dev->vendor == PCI_DEVICE_ID_AMD_VIPER_7411)
207 */ 176 t &= 0x0f;
208 177 else
209 if ((amd_config->flags & AMD_CHECK_SERENADE) && 178 t |= 0xf0;
210 dev->subsystem_vendor == PCI_VENDOR_ID_AMD && 179 pci_write_config_byte(dev, AMD_IDE_CONFIG + offset, t);
211 dev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE)
212 amd_config->udma_mask = ATA_UDMA5;
213 180
214/* 181/*
215 * Determine the system bus clock. 182 * Determine the system bus clock.
@@ -225,25 +192,19 @@ static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev, const ch
225 192
226 if (amd_clock < 20000 || amd_clock > 50000) { 193 if (amd_clock < 20000 || amd_clock > 50000) {
227 printk(KERN_WARNING "%s: User given PCI clock speed impossible (%d), using 33 MHz instead.\n", 194 printk(KERN_WARNING "%s: User given PCI clock speed impossible (%d), using 33 MHz instead.\n",
228 amd_chipset->name, amd_clock); 195 name, amd_clock);
229 amd_clock = 33333; 196 amd_clock = 33333;
230 } 197 }
231 198
232/*
233 * Print the boot message.
234 */
235
236 printk(KERN_INFO "%s: %s (rev %02x) UDMA%s controller\n",
237 amd_chipset->name, pci_name(dev), dev->revision,
238 amd_dma[fls(amd_config->udma_mask) - 1]);
239
240 return dev->irq; 199 return dev->irq;
241} 200}
242 201
243static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif) 202static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
244{ 203{
204 struct pci_dev *dev = to_pci_dev(hwif->dev);
205
245 if (hwif->irq == 0) /* 0 is bogus but will do for now */ 206 if (hwif->irq == 0) /* 0 is bogus but will do for now */
246 hwif->irq = pci_get_legacy_ide_irq(hwif->pci_dev, hwif->channel); 207 hwif->irq = pci_get_legacy_ide_irq(dev, hwif->channel);
247 208
248 hwif->set_pio_mode = &amd_set_pio_mode; 209 hwif->set_pio_mode = &amd_set_pio_mode;
249 hwif->set_dma_mode = &amd_set_drive; 210 hwif->set_dma_mode = &amd_set_drive;
@@ -251,10 +212,6 @@ static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
251 if (!hwif->dma_base) 212 if (!hwif->dma_base)
252 return; 213 return;
253 214
254 hwif->ultra_mask = amd_config->udma_mask;
255 if (amd_config->flags & AMD_BAD_SWDMA)
256 hwif->swdma_mask = 0x00;
257
258 if (hwif->cbl != ATA_CBL_PATA40_SHORT) { 215 if (hwif->cbl != ATA_CBL_PATA40_SHORT) {
259 if ((amd_80w >> hwif->channel) & 1) 216 if ((amd_80w >> hwif->channel) & 1)
260 hwif->cbl = ATA_CBL_PATA80; 217 hwif->cbl = ATA_CBL_PATA80;
@@ -272,7 +229,7 @@ static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
272 IDE_HFLAG_UNMASK_IRQS | \ 229 IDE_HFLAG_UNMASK_IRQS | \
273 IDE_HFLAG_BOOTABLE) 230 IDE_HFLAG_BOOTABLE)
274 231
275#define DECLARE_AMD_DEV(name_str) \ 232#define DECLARE_AMD_DEV(name_str, swdma, udma) \
276 { \ 233 { \
277 .name = name_str, \ 234 .name = name_str, \
278 .init_chipset = init_chipset_amd74xx, \ 235 .init_chipset = init_chipset_amd74xx, \
@@ -280,11 +237,12 @@ static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
280 .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, \ 237 .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, \
281 .host_flags = IDE_HFLAGS_AMD, \ 238 .host_flags = IDE_HFLAGS_AMD, \
282 .pio_mask = ATA_PIO5, \ 239 .pio_mask = ATA_PIO5, \
283 .swdma_mask = ATA_SWDMA2, \ 240 .swdma_mask = swdma, \
284 .mwdma_mask = ATA_MWDMA2, \ 241 .mwdma_mask = ATA_MWDMA2, \
242 .udma_mask = udma, \
285 } 243 }
286 244
287#define DECLARE_NV_DEV(name_str) \ 245#define DECLARE_NV_DEV(name_str, udma) \
288 { \ 246 { \
289 .name = name_str, \ 247 .name = name_str, \
290 .init_chipset = init_chipset_amd74xx, \ 248 .init_chipset = init_chipset_amd74xx, \
@@ -294,45 +252,62 @@ static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
294 .pio_mask = ATA_PIO5, \ 252 .pio_mask = ATA_PIO5, \
295 .swdma_mask = ATA_SWDMA2, \ 253 .swdma_mask = ATA_SWDMA2, \
296 .mwdma_mask = ATA_MWDMA2, \ 254 .mwdma_mask = ATA_MWDMA2, \
255 .udma_mask = udma, \
297 } 256 }
298 257
299static const struct ide_port_info amd74xx_chipsets[] __devinitdata = { 258static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
300 /* 0 */ DECLARE_AMD_DEV("AMD7401"), 259 /* 0 */ DECLARE_AMD_DEV("AMD7401", 0x00, ATA_UDMA2),
301 /* 1 */ DECLARE_AMD_DEV("AMD7409"), 260 /* 1 */ DECLARE_AMD_DEV("AMD7409", ATA_SWDMA2, ATA_UDMA4),
302 /* 2 */ DECLARE_AMD_DEV("AMD7411"), 261 /* 2 */ DECLARE_AMD_DEV("AMD7411", ATA_SWDMA2, ATA_UDMA5),
303 /* 3 */ DECLARE_AMD_DEV("AMD7441"), 262 /* 3 */ DECLARE_AMD_DEV("AMD7441", ATA_SWDMA2, ATA_UDMA5),
304 /* 4 */ DECLARE_AMD_DEV("AMD8111"), 263 /* 4 */ DECLARE_AMD_DEV("AMD8111", ATA_SWDMA2, ATA_UDMA6),
305 264
306 /* 5 */ DECLARE_NV_DEV("NFORCE"), 265 /* 5 */ DECLARE_NV_DEV("NFORCE", ATA_UDMA5),
307 /* 6 */ DECLARE_NV_DEV("NFORCE2"), 266 /* 6 */ DECLARE_NV_DEV("NFORCE2", ATA_UDMA6),
308 /* 7 */ DECLARE_NV_DEV("NFORCE2-U400R"), 267 /* 7 */ DECLARE_NV_DEV("NFORCE2-U400R", ATA_UDMA6),
309 /* 8 */ DECLARE_NV_DEV("NFORCE2-U400R-SATA"), 268 /* 8 */ DECLARE_NV_DEV("NFORCE2-U400R-SATA", ATA_UDMA6),
310 /* 9 */ DECLARE_NV_DEV("NFORCE3-150"), 269 /* 9 */ DECLARE_NV_DEV("NFORCE3-150", ATA_UDMA6),
311 /* 10 */ DECLARE_NV_DEV("NFORCE3-250"), 270 /* 10 */ DECLARE_NV_DEV("NFORCE3-250", ATA_UDMA6),
312 /* 11 */ DECLARE_NV_DEV("NFORCE3-250-SATA"), 271 /* 11 */ DECLARE_NV_DEV("NFORCE3-250-SATA", ATA_UDMA6),
313 /* 12 */ DECLARE_NV_DEV("NFORCE3-250-SATA2"), 272 /* 12 */ DECLARE_NV_DEV("NFORCE3-250-SATA2", ATA_UDMA6),
314 /* 13 */ DECLARE_NV_DEV("NFORCE-CK804"), 273 /* 13 */ DECLARE_NV_DEV("NFORCE-CK804", ATA_UDMA6),
315 /* 14 */ DECLARE_NV_DEV("NFORCE-MCP04"), 274 /* 14 */ DECLARE_NV_DEV("NFORCE-MCP04", ATA_UDMA6),
316 /* 15 */ DECLARE_NV_DEV("NFORCE-MCP51"), 275 /* 15 */ DECLARE_NV_DEV("NFORCE-MCP51", ATA_UDMA6),
317 /* 16 */ DECLARE_NV_DEV("NFORCE-MCP55"), 276 /* 16 */ DECLARE_NV_DEV("NFORCE-MCP55", ATA_UDMA6),
318 /* 17 */ DECLARE_NV_DEV("NFORCE-MCP61"), 277 /* 17 */ DECLARE_NV_DEV("NFORCE-MCP61", ATA_UDMA6),
319 /* 18 */ DECLARE_NV_DEV("NFORCE-MCP65"), 278 /* 18 */ DECLARE_NV_DEV("NFORCE-MCP65", ATA_UDMA6),
320 /* 19 */ DECLARE_NV_DEV("NFORCE-MCP67"), 279 /* 19 */ DECLARE_NV_DEV("NFORCE-MCP67", ATA_UDMA6),
321 /* 20 */ DECLARE_NV_DEV("NFORCE-MCP73"), 280 /* 20 */ DECLARE_NV_DEV("NFORCE-MCP73", ATA_UDMA6),
322 /* 21 */ DECLARE_NV_DEV("NFORCE-MCP77"), 281 /* 21 */ DECLARE_NV_DEV("NFORCE-MCP77", ATA_UDMA6),
323 /* 22 */ DECLARE_AMD_DEV("AMD5536"), 282
283 /* 22 */ DECLARE_AMD_DEV("AMD5536", ATA_SWDMA2, ATA_UDMA5),
324}; 284};
325 285
326static int __devinit amd74xx_probe(struct pci_dev *dev, const struct pci_device_id *id) 286static int __devinit amd74xx_probe(struct pci_dev *dev, const struct pci_device_id *id)
327{ 287{
328 amd_chipset = amd74xx_chipsets + id->driver_data; 288 struct ide_port_info d;
329 amd_config = amd_ide_chips + id->driver_data; 289 u8 idx = id->driver_data;
330 if (dev->device != amd_config->id) { 290
331 printk(KERN_ERR "%s: assertion 0x%02x == 0x%02x failed !\n", 291 d = amd74xx_chipsets[idx];
332 pci_name(dev), dev->device, amd_config->id); 292
333 return -ENODEV; 293 /*
294 * Check for bad SWDMA and incorrectly wired Serenade mainboards.
295 */
296 if (idx == 1) {
297 if (dev->revision <= 7)
298 d.swdma_mask = 0;
299 d.host_flags |= IDE_HFLAG_CLEAR_SIMPLEX;
300 } else if (idx == 4) {
301 if (dev->subsystem_vendor == PCI_VENDOR_ID_AMD &&
302 dev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE)
303 d.udma_mask = ATA_UDMA5;
334 } 304 }
335 return ide_setup_pci_device(dev, amd_chipset); 305
306 printk(KERN_INFO "%s: %s (rev %02x) UDMA%s controller\n",
307 d.name, pci_name(dev), dev->revision,
308 amd_dma[fls(d.udma_mask) - 1]);
309
310 return ide_setup_pci_device(dev, &d);
336} 311}
337 312
338static const struct pci_device_id amd74xx_pci_tbl[] = { 313static const struct pci_device_id amd74xx_pci_tbl[] = {
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index 491871984aa..b56274af178 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/atiixp.c Version 0.05 Nov 9 2007
3 *
4 * Copyright (C) 2003 ATI Inc. <hyu@ati.com> 2 * Copyright (C) 2003 ATI Inc. <hyu@ati.com>
5 * Copyright (C) 2004,2007 Bartlomiej Zolnierkiewicz 3 * Copyright (C) 2004,2007 Bartlomiej Zolnierkiewicz
6 */ 4 */
@@ -55,7 +53,7 @@ static DEFINE_SPINLOCK(atiixp_lock);
55 53
56static void atiixp_set_pio_mode(ide_drive_t *drive, const u8 pio) 54static void atiixp_set_pio_mode(ide_drive_t *drive, const u8 pio)
57{ 55{
58 struct pci_dev *dev = drive->hwif->pci_dev; 56 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
59 unsigned long flags; 57 unsigned long flags;
60 int timing_shift = (drive->dn & 2) ? 16 : 0 + (drive->dn & 1) ? 0 : 8; 58 int timing_shift = (drive->dn & 2) ? 16 : 0 + (drive->dn & 1) ? 0 : 8;
61 u32 pio_timing_data; 59 u32 pio_timing_data;
@@ -88,7 +86,7 @@ static void atiixp_set_pio_mode(ide_drive_t *drive, const u8 pio)
88 86
89static void atiixp_set_dma_mode(ide_drive_t *drive, const u8 speed) 87static void atiixp_set_dma_mode(ide_drive_t *drive, const u8 speed)
90{ 88{
91 struct pci_dev *dev = drive->hwif->pci_dev; 89 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
92 unsigned long flags; 90 unsigned long flags;
93 int timing_shift = (drive->dn & 2) ? 16 : 0 + (drive->dn & 1) ? 0 : 8; 91 int timing_shift = (drive->dn & 2) ? 16 : 0 + (drive->dn & 1) ? 0 : 8;
94 u32 tmp32; 92 u32 tmp32;
@@ -133,9 +131,8 @@ static void atiixp_set_dma_mode(ide_drive_t *drive, const u8 speed)
133 131
134static void __devinit init_hwif_atiixp(ide_hwif_t *hwif) 132static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
135{ 133{
136 u8 udma_mode = 0; 134 struct pci_dev *pdev = to_pci_dev(hwif->dev);
137 u8 ch = hwif->channel; 135 u8 udma_mode = 0, ch = hwif->channel;
138 struct pci_dev *pdev = hwif->pci_dev;
139 136
140 hwif->set_pio_mode = &atiixp_set_pio_mode; 137 hwif->set_pio_mode = &atiixp_set_pio_mode;
141 hwif->set_dma_mode = &atiixp_set_dma_mode; 138 hwif->set_dma_mode = &atiixp_set_dma_mode;
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c
index da3565e0071..7240c20b959 100644
--- a/drivers/ide/pci/cmd640.c
+++ b/drivers/ide/pci/cmd640.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/cmd640.c Version 1.02 Sep 01, 1996
3 *
4 * Copyright (C) 1995-1996 Linus Torvalds & authors (see below) 2 * Copyright (C) 1995-1996 Linus Torvalds & authors (see below)
5 */ 3 */
6 4
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index cd4eb9def15..04aa9e59670 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/cmd64x.c Version 1.53 Dec 24, 2007
3 *
4 * cmd64x.c: Enable interrupts at initialization time on Ultra/PCI machines. 2 * cmd64x.c: Enable interrupts at initialization time on Ultra/PCI machines.
5 * Due to massive hardware bugs, UltraDMA is only supported 3 * Due to massive hardware bugs, UltraDMA is only supported
6 * on the 646U2 and not on the 646U. 4 * on the 646U2 and not on the 646U.
@@ -71,7 +69,7 @@ static u8 quantize_timing(int timing, int quant)
71 */ 69 */
72static void program_cycle_times (ide_drive_t *drive, int cycle_time, int active_time) 70static void program_cycle_times (ide_drive_t *drive, int cycle_time, int active_time)
73{ 71{
74 struct pci_dev *dev = HWIF(drive)->pci_dev; 72 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
75 int clock_time = 1000 / system_bus_clock(); 73 int clock_time = 1000 / system_bus_clock();
76 u8 cycle_count, active_count, recovery_count, drwtim; 74 u8 cycle_count, active_count, recovery_count, drwtim;
77 static const u8 recovery_values[] = 75 static const u8 recovery_values[] =
@@ -118,7 +116,7 @@ static void program_cycle_times (ide_drive_t *drive, int cycle_time, int active_
118static void cmd64x_tune_pio(ide_drive_t *drive, const u8 pio) 116static void cmd64x_tune_pio(ide_drive_t *drive, const u8 pio)
119{ 117{
120 ide_hwif_t *hwif = HWIF(drive); 118 ide_hwif_t *hwif = HWIF(drive);
121 struct pci_dev *dev = hwif->pci_dev; 119 struct pci_dev *dev = to_pci_dev(hwif->dev);
122 unsigned int cycle_time; 120 unsigned int cycle_time;
123 u8 setup_count, arttim = 0; 121 u8 setup_count, arttim = 0;
124 122
@@ -183,7 +181,7 @@ static void cmd64x_set_pio_mode(ide_drive_t *drive, const u8 pio)
183static void cmd64x_set_dma_mode(ide_drive_t *drive, const u8 speed) 181static void cmd64x_set_dma_mode(ide_drive_t *drive, const u8 speed)
184{ 182{
185 ide_hwif_t *hwif = HWIF(drive); 183 ide_hwif_t *hwif = HWIF(drive);
186 struct pci_dev *dev = hwif->pci_dev; 184 struct pci_dev *dev = to_pci_dev(hwif->dev);
187 u8 unit = drive->dn & 0x01; 185 u8 unit = drive->dn & 0x01;
188 u8 regU = 0, pciU = hwif->channel ? UDIDETCR1 : UDIDETCR0; 186 u8 regU = 0, pciU = hwif->channel ? UDIDETCR1 : UDIDETCR0;
189 187
@@ -245,7 +243,7 @@ static int cmd648_ide_dma_end (ide_drive_t *drive)
245static int cmd64x_ide_dma_end (ide_drive_t *drive) 243static int cmd64x_ide_dma_end (ide_drive_t *drive)
246{ 244{
247 ide_hwif_t *hwif = HWIF(drive); 245 ide_hwif_t *hwif = HWIF(drive);
248 struct pci_dev *dev = hwif->pci_dev; 246 struct pci_dev *dev = to_pci_dev(hwif->dev);
249 int irq_reg = hwif->channel ? ARTTIM23 : CFR; 247 int irq_reg = hwif->channel ? ARTTIM23 : CFR;
250 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 : 248 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 :
251 CFR_INTR_CH0; 249 CFR_INTR_CH0;
@@ -285,7 +283,7 @@ static int cmd648_ide_dma_test_irq (ide_drive_t *drive)
285static int cmd64x_ide_dma_test_irq (ide_drive_t *drive) 283static int cmd64x_ide_dma_test_irq (ide_drive_t *drive)
286{ 284{
287 ide_hwif_t *hwif = HWIF(drive); 285 ide_hwif_t *hwif = HWIF(drive);
288 struct pci_dev *dev = hwif->pci_dev; 286 struct pci_dev *dev = to_pci_dev(hwif->dev);
289 int irq_reg = hwif->channel ? ARTTIM23 : CFR; 287 int irq_reg = hwif->channel ? ARTTIM23 : CFR;
290 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 : 288 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 :
291 CFR_INTR_CH0; 289 CFR_INTR_CH0;
@@ -375,7 +373,7 @@ static unsigned int __devinit init_chipset_cmd64x(struct pci_dev *dev, const cha
375 373
376static u8 __devinit ata66_cmd64x(ide_hwif_t *hwif) 374static u8 __devinit ata66_cmd64x(ide_hwif_t *hwif)
377{ 375{
378 struct pci_dev *dev = hwif->pci_dev; 376 struct pci_dev *dev = to_pci_dev(hwif->dev);
379 u8 bmidecsr = 0, mask = hwif->channel ? 0x02 : 0x01; 377 u8 bmidecsr = 0, mask = hwif->channel ? 0x02 : 0x01;
380 378
381 switch (dev->device) { 379 switch (dev->device) {
@@ -390,7 +388,7 @@ static u8 __devinit ata66_cmd64x(ide_hwif_t *hwif)
390 388
391static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif) 389static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif)
392{ 390{
393 struct pci_dev *dev = hwif->pci_dev; 391 struct pci_dev *dev = to_pci_dev(hwif->dev);
394 392
395 hwif->set_pio_mode = &cmd64x_set_pio_mode; 393 hwif->set_pio_mode = &cmd64x_set_pio_mode;
396 hwif->set_dma_mode = &cmd64x_set_dma_mode; 394 hwif->set_dma_mode = &cmd64x_set_dma_mode;
@@ -443,7 +441,9 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
443 .init_chipset = init_chipset_cmd64x, 441 .init_chipset = init_chipset_cmd64x,
444 .init_hwif = init_hwif_cmd64x, 442 .init_hwif = init_hwif_cmd64x,
445 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}}, 443 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}},
446 .host_flags = IDE_HFLAG_ABUSE_PREFETCH | IDE_HFLAG_BOOTABLE, 444 .host_flags = IDE_HFLAG_CLEAR_SIMPLEX |
445 IDE_HFLAG_ABUSE_PREFETCH |
446 IDE_HFLAG_BOOTABLE,
447 .pio_mask = ATA_PIO5, 447 .pio_mask = ATA_PIO5,
448 .mwdma_mask = ATA_MWDMA2, 448 .mwdma_mask = ATA_MWDMA2,
449 .udma_mask = 0x00, /* no udma */ 449 .udma_mask = 0x00, /* no udma */
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index 6ec00b8d7ec..9e01c6dc758 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/cs5520.c
@@ -69,7 +69,7 @@ static struct pio_clocks cs5520_pio_clocks[]={
69static void cs5520_set_pio_mode(ide_drive_t *drive, const u8 pio) 69static void cs5520_set_pio_mode(ide_drive_t *drive, const u8 pio)
70{ 70{
71 ide_hwif_t *hwif = HWIF(drive); 71 ide_hwif_t *hwif = HWIF(drive);
72 struct pci_dev *pdev = hwif->pci_dev; 72 struct pci_dev *pdev = to_pci_dev(hwif->dev);
73 int controller = drive->dn > 1 ? 1 : 0; 73 int controller = drive->dn > 1 ? 1 : 0;
74 74
75 /* FIXME: if DMA = 1 do we need to set the DMA bit here ? */ 75 /* FIXME: if DMA = 1 do we need to set the DMA bit here ? */
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index df5966b3346..765aac397ce 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/cs5530.c Version 0.77 Sep 24 2007
3 *
4 * Copyright (C) 2000 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 2000 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2000 Mark Lord <mlord@pobox.com> 3 * Copyright (C) 2000 Mark Lord <mlord@pobox.com>
6 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz 4 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index 50b3d7791f5..66433aa53f5 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/cs5535.c
3 *
4 * Copyright (C) 2004-2005 Advanced Micro Devices, Inc. 2 * Copyright (C) 2004-2005 Advanced Micro Devices, Inc.
5 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz 3 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
6 * 4 *
@@ -177,13 +175,15 @@ static u8 __devinit cs5535_cable_detect(struct pci_dev *dev)
177 */ 175 */
178static void __devinit init_hwif_cs5535(ide_hwif_t *hwif) 176static void __devinit init_hwif_cs5535(ide_hwif_t *hwif)
179{ 177{
178 struct pci_dev *dev = to_pci_dev(hwif->dev);
179
180 hwif->set_pio_mode = &cs5535_set_pio_mode; 180 hwif->set_pio_mode = &cs5535_set_pio_mode;
181 hwif->set_dma_mode = &cs5535_set_dma_mode; 181 hwif->set_dma_mode = &cs5535_set_dma_mode;
182 182
183 if (hwif->dma_base == 0) 183 if (hwif->dma_base == 0)
184 return; 184 return;
185 185
186 hwif->cbl = cs5535_cable_detect(hwif->pci_dev); 186 hwif->cbl = cs5535_cable_detect(dev);
187} 187}
188 188
189static const struct ide_port_info cs5535_chipset __devinitdata = { 189static const struct ide_port_info cs5535_chipset __devinitdata = {
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index 3ec4c659a37..50100ac8770 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/cy82c693.c Version 0.44 Nov 8, 2007
3 *
4 * Copyright (C) 1998-2000 Andreas S. Krebs (akrebs@altavista.net), Maintainer 2 * Copyright (C) 1998-2000 Andreas S. Krebs (akrebs@altavista.net), Maintainer
5 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>, Integrator 3 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>, Integrator
6 * 4 *
@@ -228,7 +226,7 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
228static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio) 226static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
229{ 227{
230 ide_hwif_t *hwif = HWIF(drive); 228 ide_hwif_t *hwif = HWIF(drive);
231 struct pci_dev *dev = hwif->pci_dev; 229 struct pci_dev *dev = to_pci_dev(hwif->dev);
232 pio_clocks_t pclk; 230 pio_clocks_t pclk;
233 unsigned int addrCtrl; 231 unsigned int addrCtrl;
234 232
@@ -397,8 +395,9 @@ static void __devinit init_hwif_cy82c693(ide_hwif_t *hwif)
397static void __devinit init_iops_cy82c693(ide_hwif_t *hwif) 395static void __devinit init_iops_cy82c693(ide_hwif_t *hwif)
398{ 396{
399 static ide_hwif_t *primary; 397 static ide_hwif_t *primary;
398 struct pci_dev *dev = to_pci_dev(hwif->dev);
400 399
401 if (PCI_FUNC(hwif->pci_dev->devfn) == 1) 400 if (PCI_FUNC(dev->devfn) == 1)
402 primary = hwif; 401 primary = hwif;
403 else { 402 else {
404 hwif->mate = primary; 403 hwif->mate = primary;
diff --git a/drivers/ide/pci/delkin_cb.c b/drivers/ide/pci/delkin_cb.c
index 26aa492071b..27e47fc9710 100644
--- a/drivers/ide/pci/delkin_cb.c
+++ b/drivers/ide/pci/delkin_cb.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/delkin_cb.c
3 *
4 * Created 20 Oct 2004 by Mark Lord 2 * Created 20 Oct 2004 by Mark Lord
5 * 3 *
6 * Basic support for Delkin/ASKA/Workbit Cardbus CompactFlash adapter 4 * Basic support for Delkin/ASKA/Workbit Cardbus CompactFlash adapter
@@ -87,7 +85,7 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
87 return -ENODEV; 85 return -ENODEV;
88 } 86 }
89 pci_set_drvdata(dev, hwif); 87 pci_set_drvdata(dev, hwif);
90 hwif->pci_dev = dev; 88 hwif->dev = &dev->dev;
91 drive = &hwif->drives[0]; 89 drive = &hwif->drives[0];
92 if (drive->present) { 90 if (drive->present) {
93 drive->io_32bit = 1; 91 drive->io_32bit = 1;
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index 06885697ed7..59ebe84f105 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/generic.c Version 0.11 December 30, 2002
3 *
4 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
5 * Portions (C) Copyright 2002 Red Hat Inc <alan@redhat.com> 3 * Portions (C) Copyright 2002 Red Hat Inc <alan@redhat.com>
6 * 4 *
@@ -104,7 +102,8 @@ static const struct ide_port_info generic_chipsets[] __devinitdata = {
104 102
105 { /* 14 */ 103 { /* 14 */
106 .name = "Revolution", 104 .name = "Revolution",
107 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA | 105 .host_flags = IDE_HFLAG_CLEAR_SIMPLEX |
106 IDE_HFLAG_TRUST_BIOS_FOR_DMA |
108 IDE_HFLAG_OFF_BOARD, 107 IDE_HFLAG_OFF_BOARD,
109 .swdma_mask = ATA_SWDMA2, 108 .swdma_mask = ATA_SWDMA2,
110 .mwdma_mask = ATA_MWDMA2, 109 .mwdma_mask = ATA_MWDMA2,
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index dfba0d13fcd..25dbb814822 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -1,7 +1,6 @@
1/* 1/*
2 * linux/drivers/ide/pci/hpt34x.c Version 0.40 Sept 10, 2002
3 *
4 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
3 *
5 * May be copied or modified under the terms of the GNU General Public License 4 * May be copied or modified under the terms of the GNU General Public License
6 * 5 *
7 * 6 *
@@ -45,7 +44,7 @@
45 44
46static void hpt34x_set_mode(ide_drive_t *drive, const u8 speed) 45static void hpt34x_set_mode(ide_drive_t *drive, const u8 speed)
47{ 46{
48 struct pci_dev *dev = HWIF(drive)->pci_dev; 47 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
49 u32 reg1= 0, tmp1 = 0, reg2 = 0, tmp2 = 0; 48 u32 reg1= 0, tmp1 = 0, reg2 = 0, tmp2 = 0;
50 u8 hi_speed, lo_speed; 49 u8 hi_speed, lo_speed;
51 50
@@ -131,6 +130,7 @@ static void __devinit init_hwif_hpt34x(ide_hwif_t *hwif)
131 130
132#define IDE_HFLAGS_HPT34X \ 131#define IDE_HFLAGS_HPT34X \
133 (IDE_HFLAG_NO_ATAPI_DMA | \ 132 (IDE_HFLAG_NO_ATAPI_DMA | \
133 IDE_HFLAG_NO_DSC | \
134 IDE_HFLAG_ABUSE_SET_DMA_MODE | \ 134 IDE_HFLAG_ABUSE_SET_DMA_MODE | \
135 IDE_HFLAG_NO_AUTODMA) 135 IDE_HFLAG_NO_AUTODMA)
136 136
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 12685939a81..5623cad569d 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/hpt366.c Version 1.30 Dec 12, 2007
3 *
4 * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org>
5 * Portions Copyright (C) 2001 Sun Microsystems, Inc. 3 * Portions Copyright (C) 2001 Sun Microsystems, Inc.
6 * Portions Copyright (C) 2003 Red Hat Inc 4 * Portions Copyright (C) 2003 Red Hat Inc
@@ -626,7 +624,8 @@ static int check_in_drive_list(ide_drive_t *drive, const char **list)
626static u8 hpt3xx_udma_filter(ide_drive_t *drive) 624static u8 hpt3xx_udma_filter(ide_drive_t *drive)
627{ 625{
628 ide_hwif_t *hwif = HWIF(drive); 626 ide_hwif_t *hwif = HWIF(drive);
629 struct hpt_info *info = pci_get_drvdata(hwif->pci_dev); 627 struct pci_dev *dev = to_pci_dev(hwif->dev);
628 struct hpt_info *info = pci_get_drvdata(dev);
630 u8 mask = hwif->ultra_mask; 629 u8 mask = hwif->ultra_mask;
631 630
632 switch (info->chip_type) { 631 switch (info->chip_type) {
@@ -665,7 +664,8 @@ static u8 hpt3xx_udma_filter(ide_drive_t *drive)
665static u8 hpt3xx_mdma_filter(ide_drive_t *drive) 664static u8 hpt3xx_mdma_filter(ide_drive_t *drive)
666{ 665{
667 ide_hwif_t *hwif = HWIF(drive); 666 ide_hwif_t *hwif = HWIF(drive);
668 struct hpt_info *info = pci_get_drvdata(hwif->pci_dev); 667 struct pci_dev *dev = to_pci_dev(hwif->dev);
668 struct hpt_info *info = pci_get_drvdata(dev);
669 669
670 switch (info->chip_type) { 670 switch (info->chip_type) {
671 case HPT372 : 671 case HPT372 :
@@ -699,7 +699,7 @@ static u32 get_speed_setting(u8 speed, struct hpt_info *info)
699 699
700static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed) 700static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed)
701{ 701{
702 struct pci_dev *dev = HWIF(drive)->pci_dev; 702 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
703 struct hpt_info *info = pci_get_drvdata(dev); 703 struct hpt_info *info = pci_get_drvdata(dev);
704 struct hpt_timings *t = info->timings; 704 struct hpt_timings *t = info->timings;
705 u8 itr_addr = 0x40 + (drive->dn * 4); 705 u8 itr_addr = 0x40 + (drive->dn * 4);
@@ -742,7 +742,7 @@ static void hpt3xx_quirkproc(ide_drive_t *drive)
742static void hpt3xx_maskproc(ide_drive_t *drive, int mask) 742static void hpt3xx_maskproc(ide_drive_t *drive, int mask)
743{ 743{
744 ide_hwif_t *hwif = HWIF(drive); 744 ide_hwif_t *hwif = HWIF(drive);
745 struct pci_dev *dev = hwif->pci_dev; 745 struct pci_dev *dev = to_pci_dev(hwif->dev);
746 struct hpt_info *info = pci_get_drvdata(dev); 746 struct hpt_info *info = pci_get_drvdata(dev);
747 747
748 if (drive->quirk_list) { 748 if (drive->quirk_list) {
@@ -774,7 +774,7 @@ static void hpt3xx_maskproc(ide_drive_t *drive, int mask)
774 */ 774 */
775static void hpt366_dma_lost_irq(ide_drive_t *drive) 775static void hpt366_dma_lost_irq(ide_drive_t *drive)
776{ 776{
777 struct pci_dev *dev = HWIF(drive)->pci_dev; 777 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
778 u8 mcr1 = 0, mcr3 = 0, scr1 = 0; 778 u8 mcr1 = 0, mcr3 = 0, scr1 = 0;
779 779
780 pci_read_config_byte(dev, 0x50, &mcr1); 780 pci_read_config_byte(dev, 0x50, &mcr1);
@@ -790,18 +790,20 @@ static void hpt366_dma_lost_irq(ide_drive_t *drive)
790static void hpt370_clear_engine(ide_drive_t *drive) 790static void hpt370_clear_engine(ide_drive_t *drive)
791{ 791{
792 ide_hwif_t *hwif = HWIF(drive); 792 ide_hwif_t *hwif = HWIF(drive);
793 struct pci_dev *dev = to_pci_dev(hwif->dev);
793 794
794 pci_write_config_byte(hwif->pci_dev, hwif->select_data, 0x37); 795 pci_write_config_byte(dev, hwif->select_data, 0x37);
795 udelay(10); 796 udelay(10);
796} 797}
797 798
798static void hpt370_irq_timeout(ide_drive_t *drive) 799static void hpt370_irq_timeout(ide_drive_t *drive)
799{ 800{
800 ide_hwif_t *hwif = HWIF(drive); 801 ide_hwif_t *hwif = HWIF(drive);
802 struct pci_dev *dev = to_pci_dev(hwif->dev);
801 u16 bfifo = 0; 803 u16 bfifo = 0;
802 u8 dma_cmd; 804 u8 dma_cmd;
803 805
804 pci_read_config_word(hwif->pci_dev, hwif->select_data + 2, &bfifo); 806 pci_read_config_word(dev, hwif->select_data + 2, &bfifo);
805 printk(KERN_DEBUG "%s: %d bytes in FIFO\n", drive->name, bfifo & 0x1ff); 807 printk(KERN_DEBUG "%s: %d bytes in FIFO\n", drive->name, bfifo & 0x1ff);
806 808
807 /* get DMA command mode */ 809 /* get DMA command mode */
@@ -844,10 +846,11 @@ static void hpt370_dma_timeout(ide_drive_t *drive)
844static int hpt374_ide_dma_test_irq(ide_drive_t *drive) 846static int hpt374_ide_dma_test_irq(ide_drive_t *drive)
845{ 847{
846 ide_hwif_t *hwif = HWIF(drive); 848 ide_hwif_t *hwif = HWIF(drive);
849 struct pci_dev *dev = to_pci_dev(hwif->dev);
847 u16 bfifo = 0; 850 u16 bfifo = 0;
848 u8 dma_stat; 851 u8 dma_stat;
849 852
850 pci_read_config_word(hwif->pci_dev, hwif->select_data + 2, &bfifo); 853 pci_read_config_word(dev, hwif->select_data + 2, &bfifo);
851 if (bfifo & 0x1FF) { 854 if (bfifo & 0x1FF) {
852// printk("%s: %d bytes in FIFO\n", drive->name, bfifo); 855// printk("%s: %d bytes in FIFO\n", drive->name, bfifo);
853 return 0; 856 return 0;
@@ -867,7 +870,7 @@ static int hpt374_ide_dma_test_irq(ide_drive_t *drive)
867static int hpt374_ide_dma_end(ide_drive_t *drive) 870static int hpt374_ide_dma_end(ide_drive_t *drive)
868{ 871{
869 ide_hwif_t *hwif = HWIF(drive); 872 ide_hwif_t *hwif = HWIF(drive);
870 struct pci_dev *dev = hwif->pci_dev; 873 struct pci_dev *dev = to_pci_dev(hwif->dev);
871 u8 mcr = 0, mcr_addr = hwif->select_data; 874 u8 mcr = 0, mcr_addr = hwif->select_data;
872 u8 bwsr = 0, mask = hwif->channel ? 0x02 : 0x01; 875 u8 bwsr = 0, mask = hwif->channel ? 0x02 : 0x01;
873 876
@@ -942,7 +945,7 @@ static void hpt3xxn_rw_disk(ide_drive_t *drive, struct request *rq)
942static int hpt3xx_busproc(ide_drive_t *drive, int state) 945static int hpt3xx_busproc(ide_drive_t *drive, int state)
943{ 946{
944 ide_hwif_t *hwif = HWIF(drive); 947 ide_hwif_t *hwif = HWIF(drive);
945 struct pci_dev *dev = hwif->pci_dev; 948 struct pci_dev *dev = to_pci_dev(hwif->dev);
946 u8 mcr_addr = hwif->select_data + 2; 949 u8 mcr_addr = hwif->select_data + 2;
947 u8 resetmask = hwif->channel ? 0x80 : 0x40; 950 u8 resetmask = hwif->channel ? 0x80 : 0x40;
948 u8 bsr2 = 0; 951 u8 bsr2 = 0;
@@ -1278,7 +1281,7 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1278 1281
1279static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) 1282static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1280{ 1283{
1281 struct pci_dev *dev = hwif->pci_dev; 1284 struct pci_dev *dev = to_pci_dev(hwif->dev);
1282 struct hpt_info *info = pci_get_drvdata(dev); 1285 struct hpt_info *info = pci_get_drvdata(dev);
1283 int serialize = HPT_SERIALIZE_IO; 1286 int serialize = HPT_SERIALIZE_IO;
1284 u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02; 1287 u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02;
@@ -1393,7 +1396,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1393 1396
1394static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase) 1397static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
1395{ 1398{
1396 struct pci_dev *dev = hwif->pci_dev; 1399 struct pci_dev *dev = to_pci_dev(hwif->dev);
1397 u8 masterdma = 0, slavedma = 0; 1400 u8 masterdma = 0, slavedma = 0;
1398 u8 dma_new = 0, dma_old = 0; 1401 u8 dma_new = 0, dma_old = 0;
1399 unsigned long flags; 1402 unsigned long flags;
@@ -1413,7 +1416,7 @@ static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
1413 1416
1414 local_irq_restore(flags); 1417 local_irq_restore(flags);
1415 1418
1416 ide_setup_dma(hwif, dmabase, 8); 1419 ide_setup_dma(hwif, dmabase);
1417} 1420}
1418 1421
1419static void __devinit hpt374_init(struct pci_dev *dev, struct pci_dev *dev2) 1422static void __devinit hpt374_init(struct pci_dev *dev, struct pci_dev *dev2)
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index 2a0f45c4f4c..df74e588a53 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/it8213.c
@@ -28,7 +28,7 @@
28static void it8213_set_pio_mode(ide_drive_t *drive, const u8 pio) 28static void it8213_set_pio_mode(ide_drive_t *drive, const u8 pio)
29{ 29{
30 ide_hwif_t *hwif = HWIF(drive); 30 ide_hwif_t *hwif = HWIF(drive);
31 struct pci_dev *dev = hwif->pci_dev; 31 struct pci_dev *dev = to_pci_dev(hwif->dev);
32 int is_slave = drive->dn & 1; 32 int is_slave = drive->dn & 1;
33 int master_port = 0x40; 33 int master_port = 0x40;
34 int slave_port = 0x44; 34 int slave_port = 0x44;
@@ -85,7 +85,7 @@ static void it8213_set_pio_mode(ide_drive_t *drive, const u8 pio)
85static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed) 85static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed)
86{ 86{
87 ide_hwif_t *hwif = HWIF(drive); 87 ide_hwif_t *hwif = HWIF(drive);
88 struct pci_dev *dev = hwif->pci_dev; 88 struct pci_dev *dev = to_pci_dev(hwif->dev);
89 u8 maslave = 0x40; 89 u8 maslave = 0x40;
90 int a_speed = 3 << (drive->dn * 4); 90 int a_speed = 3 << (drive->dn * 4);
91 int u_flag = 1 << drive->dn; 91 int u_flag = 1 << drive->dn;
@@ -152,6 +152,7 @@ static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed)
152 152
153static void __devinit init_hwif_it8213(ide_hwif_t *hwif) 153static void __devinit init_hwif_it8213(ide_hwif_t *hwif)
154{ 154{
155 struct pci_dev *dev = to_pci_dev(hwif->dev);
155 u8 reg42h = 0; 156 u8 reg42h = 0;
156 157
157 hwif->set_dma_mode = &it8213_set_dma_mode; 158 hwif->set_dma_mode = &it8213_set_dma_mode;
@@ -160,7 +161,7 @@ static void __devinit init_hwif_it8213(ide_hwif_t *hwif)
160 if (!hwif->dma_base) 161 if (!hwif->dma_base)
161 return; 162 return;
162 163
163 pci_read_config_byte(hwif->pci_dev, 0x42, &reg42h); 164 pci_read_config_byte(dev, 0x42, &reg42h);
164 165
165 if (hwif->cbl != ATA_CBL_PATA40_SHORT) 166 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
166 hwif->cbl = (reg42h & 0x02) ? ATA_CBL_PATA40 : ATA_CBL_PATA80; 167 hwif->cbl = (reg42h & 0x02) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index e610a5340fd..938d35f35c8 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -1,7 +1,4 @@
1
2/* 1/*
3 * linux/drivers/ide/pci/it821x.c Version 0.16 Jul 3 2007
4 *
5 * Copyright (C) 2004 Red Hat <alan@redhat.com> 2 * Copyright (C) 2004 Red Hat <alan@redhat.com>
6 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz 3 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
7 * 4 *
@@ -113,7 +110,8 @@ static int it8212_noraid;
113 110
114static void it821x_program(ide_drive_t *drive, u16 timing) 111static void it821x_program(ide_drive_t *drive, u16 timing)
115{ 112{
116 ide_hwif_t *hwif = drive->hwif; 113 ide_hwif_t *hwif = drive->hwif;
114 struct pci_dev *dev = to_pci_dev(hwif->dev);
117 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 115 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
118 int channel = hwif->channel; 116 int channel = hwif->channel;
119 u8 conf; 117 u8 conf;
@@ -123,7 +121,8 @@ static void it821x_program(ide_drive_t *drive, u16 timing)
123 conf = timing >> 8; 121 conf = timing >> 8;
124 else 122 else
125 conf = timing & 0xFF; 123 conf = timing & 0xFF;
126 pci_write_config_byte(hwif->pci_dev, 0x54 + 4 * channel, conf); 124
125 pci_write_config_byte(dev, 0x54 + 4 * channel, conf);
127} 126}
128 127
129/** 128/**
@@ -137,7 +136,8 @@ static void it821x_program(ide_drive_t *drive, u16 timing)
137 136
138static void it821x_program_udma(ide_drive_t *drive, u16 timing) 137static void it821x_program_udma(ide_drive_t *drive, u16 timing)
139{ 138{
140 ide_hwif_t *hwif = drive->hwif; 139 ide_hwif_t *hwif = drive->hwif;
140 struct pci_dev *dev = to_pci_dev(hwif->dev);
141 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 141 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
142 int channel = hwif->channel; 142 int channel = hwif->channel;
143 int unit = drive->select.b.unit; 143 int unit = drive->select.b.unit;
@@ -148,11 +148,12 @@ static void it821x_program_udma(ide_drive_t *drive, u16 timing)
148 conf = timing >> 8; 148 conf = timing >> 8;
149 else 149 else
150 conf = timing & 0xFF; 150 conf = timing & 0xFF;
151 if(itdev->timing10 == 0) 151
152 pci_write_config_byte(hwif->pci_dev, 0x56 + 4 * channel + unit, conf); 152 if (itdev->timing10 == 0)
153 pci_write_config_byte(dev, 0x56 + 4 * channel + unit, conf);
153 else { 154 else {
154 pci_write_config_byte(hwif->pci_dev, 0x56 + 4 * channel, conf); 155 pci_write_config_byte(dev, 0x56 + 4 * channel, conf);
155 pci_write_config_byte(hwif->pci_dev, 0x56 + 4 * channel + 1, conf); 156 pci_write_config_byte(dev, 0x56 + 4 * channel + 1, conf);
156 } 157 }
157} 158}
158 159
@@ -167,6 +168,7 @@ static void it821x_program_udma(ide_drive_t *drive, u16 timing)
167static void it821x_clock_strategy(ide_drive_t *drive) 168static void it821x_clock_strategy(ide_drive_t *drive)
168{ 169{
169 ide_hwif_t *hwif = drive->hwif; 170 ide_hwif_t *hwif = drive->hwif;
171 struct pci_dev *dev = to_pci_dev(hwif->dev);
170 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 172 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
171 173
172 u8 unit = drive->select.b.unit; 174 u8 unit = drive->select.b.unit;
@@ -205,10 +207,11 @@ static void it821x_clock_strategy(ide_drive_t *drive)
205 itdev->clock_mode = ATA_50; 207 itdev->clock_mode = ATA_50;
206 sel = 1; 208 sel = 1;
207 } 209 }
208 pci_read_config_byte(hwif->pci_dev, 0x50, &v); 210
211 pci_read_config_byte(dev, 0x50, &v);
209 v &= ~(1 << (1 + hwif->channel)); 212 v &= ~(1 << (1 + hwif->channel));
210 v |= sel << (1 + hwif->channel); 213 v |= sel << (1 + hwif->channel);
211 pci_write_config_byte(hwif->pci_dev, 0x50, v); 214 pci_write_config_byte(dev, 0x50, v);
212 215
213 /* 216 /*
214 * Reprogram the UDMA/PIO of the pair drive for the switch 217 * Reprogram the UDMA/PIO of the pair drive for the switch
@@ -282,7 +285,8 @@ static void it821x_set_pio_mode(ide_drive_t *drive, const u8 pio)
282 285
283static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted) 286static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
284{ 287{
285 ide_hwif_t *hwif = drive->hwif; 288 ide_hwif_t *hwif = drive->hwif;
289 struct pci_dev *dev = to_pci_dev(hwif->dev);
286 struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif); 290 struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif);
287 int unit = drive->select.b.unit; 291 int unit = drive->select.b.unit;
288 int channel = hwif->channel; 292 int channel = hwif->channel;
@@ -297,12 +301,12 @@ static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
297 itdev->udma[unit] = UDMA_OFF; 301 itdev->udma[unit] = UDMA_OFF;
298 302
299 /* UDMA bits off - Revision 0x10 do them in pairs */ 303 /* UDMA bits off - Revision 0x10 do them in pairs */
300 pci_read_config_byte(hwif->pci_dev, 0x50, &conf); 304 pci_read_config_byte(dev, 0x50, &conf);
301 if(itdev->timing10) 305 if (itdev->timing10)
302 conf |= channel ? 0x60: 0x18; 306 conf |= channel ? 0x60: 0x18;
303 else 307 else
304 conf |= 1 << (3 + 2 * channel + unit); 308 conf |= 1 << (3 + 2 * channel + unit);
305 pci_write_config_byte(hwif->pci_dev, 0x50, conf); 309 pci_write_config_byte(dev, 0x50, conf);
306 310
307 it821x_clock_strategy(drive); 311 it821x_clock_strategy(drive);
308 /* FIXME: do we need to program this ? */ 312 /* FIXME: do we need to program this ? */
@@ -320,7 +324,8 @@ static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
320 324
321static void it821x_tune_udma (ide_drive_t *drive, byte mode_wanted) 325static void it821x_tune_udma (ide_drive_t *drive, byte mode_wanted)
322{ 326{
323 ide_hwif_t *hwif = drive->hwif; 327 ide_hwif_t *hwif = drive->hwif;
328 struct pci_dev *dev = to_pci_dev(hwif->dev);
324 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 329 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
325 int unit = drive->select.b.unit; 330 int unit = drive->select.b.unit;
326 int channel = hwif->channel; 331 int channel = hwif->channel;
@@ -337,12 +342,12 @@ static void it821x_tune_udma (ide_drive_t *drive, byte mode_wanted)
337 itdev->udma[unit] |= 0x8080; /* UDMA 5/6 select on */ 342 itdev->udma[unit] |= 0x8080; /* UDMA 5/6 select on */
338 343
339 /* UDMA on. Again revision 0x10 must do the pair */ 344 /* UDMA on. Again revision 0x10 must do the pair */
340 pci_read_config_byte(hwif->pci_dev, 0x50, &conf); 345 pci_read_config_byte(dev, 0x50, &conf);
341 if(itdev->timing10) 346 if (itdev->timing10)
342 conf &= channel ? 0x9F: 0xE7; 347 conf &= channel ? 0x9F: 0xE7;
343 else 348 else
344 conf &= ~ (1 << (3 + 2 * channel + unit)); 349 conf &= ~ (1 << (3 + 2 * channel + unit));
345 pci_write_config_byte(hwif->pci_dev, 0x50, conf); 350 pci_write_config_byte(dev, 0x50, conf);
346 351
347 it821x_clock_strategy(drive); 352 it821x_clock_strategy(drive);
348 it821x_program_udma(drive, itdev->udma[unit]); 353 it821x_program_udma(drive, itdev->udma[unit]);
@@ -520,6 +525,7 @@ static void __devinit it821x_quirkproc(ide_drive_t *drive)
520 525
521static void __devinit init_hwif_it821x(ide_hwif_t *hwif) 526static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
522{ 527{
528 struct pci_dev *dev = to_pci_dev(hwif->dev);
523 struct it821x_dev *idev = kzalloc(sizeof(struct it821x_dev), GFP_KERNEL); 529 struct it821x_dev *idev = kzalloc(sizeof(struct it821x_dev), GFP_KERNEL);
524 u8 conf; 530 u8 conf;
525 531
@@ -532,7 +538,7 @@ static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
532 538
533 ide_set_hwifdata(hwif, idev); 539 ide_set_hwifdata(hwif, idev);
534 540
535 pci_read_config_byte(hwif->pci_dev, 0x50, &conf); 541 pci_read_config_byte(dev, 0x50, &conf);
536 if (conf & 1) { 542 if (conf & 1) {
537 idev->smart = 1; 543 idev->smart = 1;
538 hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA; 544 hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
@@ -555,7 +561,7 @@ static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
555 * this is necessary. 561 * this is necessary.
556 */ 562 */
557 563
558 pci_read_config_byte(hwif->pci_dev, 0x08, &conf); 564 pci_read_config_byte(dev, 0x08, &conf);
559 if (conf == 0x10) { 565 if (conf == 0x10) {
560 idev->timing10 = 1; 566 idev->timing10 = 1;
561 hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA; 567 hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index 0083eaf89c7..8b40f6479c5 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -30,7 +30,7 @@ typedef enum {
30 30
31static u8 __devinit ata66_jmicron(ide_hwif_t *hwif) 31static u8 __devinit ata66_jmicron(ide_hwif_t *hwif)
32{ 32{
33 struct pci_dev *pdev = hwif->pci_dev; 33 struct pci_dev *pdev = to_pci_dev(hwif->dev);
34 34
35 u32 control; 35 u32 control;
36 u32 control5; 36 u32 control5;
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c
index d4df4642dbb..fc9eee9ccac 100644
--- a/drivers/ide/pci/ns87415.c
+++ b/drivers/ide/pci/ns87415.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/ns87415.c Version 2.00 Sep. 10, 2002
3 *
4 * Copyright (C) 1997-1998 Mark Lord <mlord@pobox.com> 2 * Copyright (C) 1997-1998 Mark Lord <mlord@pobox.com>
5 * Copyright (C) 1998 Eddie C. Dost <ecd@skynet.be> 3 * Copyright (C) 1998 Eddie C. Dost <ecd@skynet.be>
6 * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org>
@@ -71,10 +69,9 @@ static u8 superio_ide_inb (unsigned long port)
71 69
72static void __devinit superio_ide_init_iops (struct hwif_s *hwif) 70static void __devinit superio_ide_init_iops (struct hwif_s *hwif)
73{ 71{
72 struct pci_dev *pdev = to_pci_dev(hwif->dev);
74 u32 base, dmabase; 73 u32 base, dmabase;
75 u8 tmp; 74 u8 port = hwif->channel, tmp;
76 struct pci_dev *pdev = hwif->pci_dev;
77 u8 port = hwif->channel;
78 75
79 base = pci_resource_start(pdev, port * 2) & ~3; 76 base = pci_resource_start(pdev, port * 2) & ~3;
80 dmabase = pci_resource_start(pdev, 4) & ~3; 77 dmabase = pci_resource_start(pdev, 4) & ~3;
@@ -93,10 +90,11 @@ static void __devinit superio_ide_init_iops (struct hwif_s *hwif)
93 90
94static void __devinit init_iops_ns87415(ide_hwif_t *hwif) 91static void __devinit init_iops_ns87415(ide_hwif_t *hwif)
95{ 92{
96 if (PCI_SLOT(hwif->pci_dev->devfn) == 0xE) { 93 struct pci_dev *dev = to_pci_dev(hwif->dev);
94
95 if (PCI_SLOT(dev->devfn) == 0xE)
97 /* Built-in - assume it's under superio. */ 96 /* Built-in - assume it's under superio. */
98 superio_ide_init_iops(hwif); 97 superio_ide_init_iops(hwif);
99 }
100} 98}
101#endif 99#endif
102 100
@@ -110,8 +108,8 @@ static unsigned int ns87415_count = 0, ns87415_control[MAX_HWIFS] = { 0 };
110static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma) 108static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
111{ 109{
112 ide_hwif_t *hwif = HWIF(drive); 110 ide_hwif_t *hwif = HWIF(drive);
111 struct pci_dev *dev = to_pci_dev(hwif->dev);
113 unsigned int bit, other, new, *old = (unsigned int *) hwif->select_data; 112 unsigned int bit, other, new, *old = (unsigned int *) hwif->select_data;
114 struct pci_dev *dev = hwif->pci_dev;
115 unsigned long flags; 113 unsigned long flags;
116 114
117 local_irq_save(flags); 115 local_irq_save(flags);
@@ -189,7 +187,7 @@ static int ns87415_ide_dma_setup(ide_drive_t *drive)
189 187
190static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif) 188static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
191{ 189{
192 struct pci_dev *dev = hwif->pci_dev; 190 struct pci_dev *dev = to_pci_dev(hwif->dev);
193 unsigned int ctrl, using_inta; 191 unsigned int ctrl, using_inta;
194 u8 progif; 192 u8 progif;
195#ifdef __sparc_v9__ 193#ifdef __sparc_v9__
@@ -231,8 +229,8 @@ static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
231 229
232#ifdef __sparc_v9__ 230#ifdef __sparc_v9__
233 /* 231 /*
234 * XXX: Reset the device, if we don't it will not respond 232 * XXX: Reset the device, if we don't it will not respond to
235 * to SELECT_DRIVE() properly during first probe_hwif(). 233 * SELECT_DRIVE() properly during first ide_probe_port().
236 */ 234 */
237 timeout = 10000; 235 timeout = 10000;
238 outb(12, hwif->io_ports[IDE_CONTROL_OFFSET]); 236 outb(12, hwif->io_ports[IDE_CONTROL_OFFSET]);
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c
index 8953d9c3926..0ce92d32303 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/pci/opti621.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/opti621.c Version 0.9 Sep 24, 2007
3 *
4 * Copyright (C) 1996-1998 Linus Torvalds & authors (see below) 2 * Copyright (C) 1996-1998 Linus Torvalds & authors (see below)
5 */ 3 */
6 4
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 89d2363a1eb..bb29db03540 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -149,6 +149,7 @@ static struct udma_timing {
149static void pdcnew_set_dma_mode(ide_drive_t *drive, const u8 speed) 149static void pdcnew_set_dma_mode(ide_drive_t *drive, const u8 speed)
150{ 150{
151 ide_hwif_t *hwif = HWIF(drive); 151 ide_hwif_t *hwif = HWIF(drive);
152 struct pci_dev *dev = to_pci_dev(hwif->dev);
152 u8 adj = (drive->dn & 1) ? 0x08 : 0x00; 153 u8 adj = (drive->dn & 1) ? 0x08 : 0x00;
153 154
154 /* 155 /*
@@ -159,7 +160,7 @@ static void pdcnew_set_dma_mode(ide_drive_t *drive, const u8 speed)
159 * As we set up the PLL to output 133 MHz for UltraDMA/133 capable 160 * As we set up the PLL to output 133 MHz for UltraDMA/133 capable
160 * chips, we must override the default register settings... 161 * chips, we must override the default register settings...
161 */ 162 */
162 if (max_dma_rate(hwif->pci_dev) == 4) { 163 if (max_dma_rate(dev) == 4) {
163 u8 mode = speed & 0x07; 164 u8 mode = speed & 0x07;
164 165
165 if (speed >= XFER_UDMA_0) { 166 if (speed >= XFER_UDMA_0) {
@@ -186,9 +187,10 @@ static void pdcnew_set_dma_mode(ide_drive_t *drive, const u8 speed)
186static void pdcnew_set_pio_mode(ide_drive_t *drive, const u8 pio) 187static void pdcnew_set_pio_mode(ide_drive_t *drive, const u8 pio)
187{ 188{
188 ide_hwif_t *hwif = drive->hwif; 189 ide_hwif_t *hwif = drive->hwif;
190 struct pci_dev *dev = to_pci_dev(hwif->dev);
189 u8 adj = (drive->dn & 1) ? 0x08 : 0x00; 191 u8 adj = (drive->dn & 1) ? 0x08 : 0x00;
190 192
191 if (max_dma_rate(hwif->pci_dev) == 4) { 193 if (max_dma_rate(dev) == 4) {
192 set_indexed_reg(hwif, 0x0c + adj, pio_timings[pio].reg0c); 194 set_indexed_reg(hwif, 0x0c + adj, pio_timings[pio].reg0c);
193 set_indexed_reg(hwif, 0x0d + adj, pio_timings[pio].reg0d); 195 set_indexed_reg(hwif, 0x0d + adj, pio_timings[pio].reg0d);
194 set_indexed_reg(hwif, 0x13 + adj, pio_timings[pio].reg13); 196 set_indexed_reg(hwif, 0x13 + adj, pio_timings[pio].reg13);
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index 3a1e081fe39..31a1308414a 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/pdc202xx_old.c Version 0.52 Aug 27, 2007
3 *
4 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2006-2007 MontaVista Software, Inc. 3 * Copyright (C) 2006-2007 MontaVista Software, Inc.
6 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz 4 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
@@ -66,7 +64,7 @@ static void pdc_old_disable_66MHz_clock(ide_hwif_t *);
66static void pdc202xx_set_mode(ide_drive_t *drive, const u8 speed) 64static void pdc202xx_set_mode(ide_drive_t *drive, const u8 speed)
67{ 65{
68 ide_hwif_t *hwif = HWIF(drive); 66 ide_hwif_t *hwif = HWIF(drive);
69 struct pci_dev *dev = hwif->pci_dev; 67 struct pci_dev *dev = to_pci_dev(hwif->dev);
70 u8 drive_pci = 0x60 + (drive->dn << 2); 68 u8 drive_pci = 0x60 + (drive->dn << 2);
71 69
72 u8 AP = 0, BP = 0, CP = 0; 70 u8 AP = 0, BP = 0, CP = 0;
@@ -144,9 +142,10 @@ static void pdc202xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
144 142
145static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif) 143static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif)
146{ 144{
145 struct pci_dev *dev = to_pci_dev(hwif->dev);
147 u16 CIS = 0, mask = (hwif->channel) ? (1<<11) : (1<<10); 146 u16 CIS = 0, mask = (hwif->channel) ? (1<<11) : (1<<10);
148 147
149 pci_read_config_word(hwif->pci_dev, 0x50, &CIS); 148 pci_read_config_word(dev, 0x50, &CIS);
150 149
151 return (CIS & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80; 150 return (CIS & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
152} 151}
@@ -305,12 +304,14 @@ static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev,
305 304
306static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif) 305static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
307{ 306{
307 struct pci_dev *dev = to_pci_dev(hwif->dev);
308
308 hwif->set_pio_mode = &pdc202xx_set_pio_mode; 309 hwif->set_pio_mode = &pdc202xx_set_pio_mode;
309 hwif->set_dma_mode = &pdc202xx_set_mode; 310 hwif->set_dma_mode = &pdc202xx_set_mode;
310 311
311 hwif->quirkproc = &pdc202xx_quirkproc; 312 hwif->quirkproc = &pdc202xx_quirkproc;
312 313
313 if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246) 314 if (dev->device != PCI_DEVICE_ID_PROMISE_20246)
314 hwif->resetproc = &pdc202xx_reset; 315 hwif->resetproc = &pdc202xx_reset;
315 316
316 if (hwif->dma_base == 0) 317 if (hwif->dma_base == 0)
@@ -319,7 +320,7 @@ static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
319 hwif->dma_lost_irq = &pdc202xx_dma_lost_irq; 320 hwif->dma_lost_irq = &pdc202xx_dma_lost_irq;
320 hwif->dma_timeout = &pdc202xx_dma_timeout; 321 hwif->dma_timeout = &pdc202xx_dma_timeout;
321 322
322 if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246) { 323 if (dev->device != PCI_DEVICE_ID_PROMISE_20246) {
323 if (hwif->cbl != ATA_CBL_PATA40_SHORT) 324 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
324 hwif->cbl = pdc202xx_old_cable_detect(hwif); 325 hwif->cbl = pdc202xx_old_cable_detect(hwif);
325 326
@@ -334,7 +335,7 @@ static void __devinit init_dma_pdc202xx(ide_hwif_t *hwif, unsigned long dmabase)
334 u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0; 335 u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0;
335 336
336 if (hwif->channel) { 337 if (hwif->channel) {
337 ide_setup_dma(hwif, dmabase, 8); 338 ide_setup_dma(hwif, dmabase);
338 return; 339 return;
339 } 340 }
340 341
@@ -358,7 +359,7 @@ static void __devinit init_dma_pdc202xx(ide_hwif_t *hwif, unsigned long dmabase)
358 } 359 }
359#endif /* CONFIG_PDC202XX_BURST */ 360#endif /* CONFIG_PDC202XX_BURST */
360 361
361 ide_setup_dma(hwif, dmabase, 8); 362 ide_setup_dma(hwif, dmabase);
362} 363}
363 364
364static void __devinit pdc202ata4_fixup_irq(struct pci_dev *dev, 365static void __devinit pdc202ata4_fixup_irq(struct pci_dev *dev,
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index bd6d3f77d30..c1a6b68337d 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/piix.c Version 0.54 Sep 5, 2007
3 *
4 * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer 2 * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer
5 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> 3 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
6 * Copyright (C) 2003 Red Hat Inc <alan@redhat.com> 4 * Copyright (C) 2003 Red Hat Inc <alan@redhat.com>
@@ -8,53 +6,8 @@
8 * 6 *
9 * May be copied or modified under the terms of the GNU General Public License 7 * May be copied or modified under the terms of the GNU General Public License
10 * 8 *
11 * PIO mode setting function for Intel chipsets. 9 * Documentation:
12 * For use instead of BIOS settings.
13 *
14 * 40-41
15 * 42-43
16 *
17 * 41
18 * 43
19 *
20 * | PIO 0 | c0 | 80 | 0 |
21 * | PIO 2 | SW2 | d0 | 90 | 4 |
22 * | PIO 3 | MW1 | e1 | a1 | 9 |
23 * | PIO 4 | MW2 | e3 | a3 | b |
24 *
25 * sitre = word40 & 0x4000; primary
26 * sitre = word42 & 0x4000; secondary
27 *
28 * 44 8421|8421 hdd|hdb
29 *
30 * 48 8421 hdd|hdc|hdb|hda udma enabled
31 *
32 * 0001 hda
33 * 0010 hdb
34 * 0100 hdc
35 * 1000 hdd
36 *
37 * 4a 84|21 hdb|hda
38 * 4b 84|21 hdd|hdc
39 *
40 * ata-33/82371AB
41 * ata-33/82371EB
42 * ata-33/82801AB ata-66/82801AA
43 * 00|00 udma 0 00|00 reserved
44 * 01|01 udma 1 01|01 udma 3
45 * 10|10 udma 2 10|10 udma 4
46 * 11|11 reserved 11|11 reserved
47 *
48 * 54 8421|8421 ata66 drive|ata66 enable
49 *
50 * pci_read_config_word(HWIF(drive)->pci_dev, 0x40, &reg40);
51 * pci_read_config_word(HWIF(drive)->pci_dev, 0x42, &reg42);
52 * pci_read_config_word(HWIF(drive)->pci_dev, 0x44, &reg44);
53 * pci_read_config_byte(HWIF(drive)->pci_dev, 0x48, &reg48);
54 * pci_read_config_word(HWIF(drive)->pci_dev, 0x4a, &reg4a);
55 * pci_read_config_byte(HWIF(drive)->pci_dev, 0x54, &reg54);
56 * 10 *
57 * Documentation
58 * Publically available from Intel web site. Errata documentation 11 * Publically available from Intel web site. Errata documentation
59 * is also publically available. As an aide to anyone hacking on this 12 * is also publically available. As an aide to anyone hacking on this
60 * driver the list of errata that are relevant is below.going back to 13 * driver the list of errata that are relevant is below.going back to
@@ -116,7 +69,7 @@ static int no_piix_dma;
116static void piix_set_pio_mode(ide_drive_t *drive, const u8 pio) 69static void piix_set_pio_mode(ide_drive_t *drive, const u8 pio)
117{ 70{
118 ide_hwif_t *hwif = HWIF(drive); 71 ide_hwif_t *hwif = HWIF(drive);
119 struct pci_dev *dev = hwif->pci_dev; 72 struct pci_dev *dev = to_pci_dev(hwif->dev);
120 int is_slave = drive->dn & 1; 73 int is_slave = drive->dn & 1;
121 int master_port = hwif->channel ? 0x42 : 0x40; 74 int master_port = hwif->channel ? 0x42 : 0x40;
122 int slave_port = 0x44; 75 int slave_port = 0x44;
@@ -185,7 +138,7 @@ static void piix_set_pio_mode(ide_drive_t *drive, const u8 pio)
185static void piix_set_dma_mode(ide_drive_t *drive, const u8 speed) 138static void piix_set_dma_mode(ide_drive_t *drive, const u8 speed)
186{ 139{
187 ide_hwif_t *hwif = HWIF(drive); 140 ide_hwif_t *hwif = HWIF(drive);
188 struct pci_dev *dev = hwif->pci_dev; 141 struct pci_dev *dev = to_pci_dev(hwif->dev);
189 u8 maslave = hwif->channel ? 0x42 : 0x40; 142 u8 maslave = hwif->channel ? 0x42 : 0x40;
190 int a_speed = 3 << (drive->dn * 4); 143 int a_speed = 3 << (drive->dn * 4);
191 int u_flag = 1 << drive->dn; 144 int u_flag = 1 << drive->dn;
@@ -305,7 +258,7 @@ static const struct ich_laptop ich_laptop[] = {
305 258
306static u8 __devinit piix_cable_detect(ide_hwif_t *hwif) 259static u8 __devinit piix_cable_detect(ide_hwif_t *hwif)
307{ 260{
308 struct pci_dev *pdev = hwif->pci_dev; 261 struct pci_dev *pdev = to_pci_dev(hwif->dev);
309 const struct ich_laptop *lap = &ich_laptop[0]; 262 const struct ich_laptop *lap = &ich_laptop[0];
310 u8 reg54h = 0, mask = hwif->channel ? 0xc0 : 0x30; 263 u8 reg54h = 0, mask = hwif->channel ? 0xc0 : 0x30;
311 264
diff --git a/drivers/ide/pci/rz1000.c b/drivers/ide/pci/rz1000.c
index 6b10ae260fa..7ed6625819d 100644
--- a/drivers/ide/pci/rz1000.c
+++ b/drivers/ide/pci/rz1000.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/rz1000.c Version 0.06 January 12, 2003
3 *
4 * Copyright (C) 1995-1998 Linus Torvalds & author (see below) 2 * Copyright (C) 1995-1998 Linus Torvalds & author (see below)
5 */ 3 */
6 4
@@ -32,8 +30,8 @@
32 30
33static void __devinit init_hwif_rz1000 (ide_hwif_t *hwif) 31static void __devinit init_hwif_rz1000 (ide_hwif_t *hwif)
34{ 32{
33 struct pci_dev *dev = to_pci_dev(hwif->dev);
35 u16 reg; 34 u16 reg;
36 struct pci_dev *dev = hwif->pci_dev;
37 35
38 if (!pci_read_config_word (dev, 0x40, &reg) && 36 if (!pci_read_config_word (dev, 0x40, &reg) &&
39 !pci_write_config_word(dev, 0x40, reg & 0xdfff)) { 37 !pci_write_config_word(dev, 0x40, reg & 0xdfff)) {
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index 32fdf53379f..af499a60eb3 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/sc1200.c Version 0.97 Aug 3 2007
3 *
4 * Copyright (C) 2000-2002 Mark Lord <mlord@pobox.com> 2 * Copyright (C) 2000-2002 Mark Lord <mlord@pobox.com>
5 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz 3 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
6 * 4 *
@@ -87,7 +85,7 @@ static const unsigned int sc1200_pio_timings[4][5] =
87static void sc1200_tunepio(ide_drive_t *drive, u8 pio) 85static void sc1200_tunepio(ide_drive_t *drive, u8 pio)
88{ 86{
89 ide_hwif_t *hwif = drive->hwif; 87 ide_hwif_t *hwif = drive->hwif;
90 struct pci_dev *pdev = hwif->pci_dev; 88 struct pci_dev *pdev = to_pci_dev(hwif->dev);
91 unsigned int basereg = hwif->channel ? 0x50 : 0x40, format = 0; 89 unsigned int basereg = hwif->channel ? 0x50 : 0x40, format = 0;
92 90
93 pci_read_config_dword(pdev, basereg + 4, &format); 91 pci_read_config_dword(pdev, basereg + 4, &format);
@@ -130,6 +128,7 @@ out:
130static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode) 128static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode)
131{ 129{
132 ide_hwif_t *hwif = HWIF(drive); 130 ide_hwif_t *hwif = HWIF(drive);
131 struct pci_dev *dev = to_pci_dev(hwif->dev);
133 int unit = drive->select.b.unit; 132 int unit = drive->select.b.unit;
134 unsigned int reg, timings; 133 unsigned int reg, timings;
135 unsigned short pci_clock; 134 unsigned short pci_clock;
@@ -160,12 +159,11 @@ static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode)
160 timings = mwdma_timing[pci_clock][mode - XFER_MW_DMA_0]; 159 timings = mwdma_timing[pci_clock][mode - XFER_MW_DMA_0];
161 160
162 if (unit == 0) { /* are we configuring drive0? */ 161 if (unit == 0) { /* are we configuring drive0? */
163 pci_read_config_dword(hwif->pci_dev, basereg+4, &reg); 162 pci_read_config_dword(dev, basereg + 4, &reg);
164 timings |= reg & 0x80000000; /* preserve PIO format bit */ 163 timings |= reg & 0x80000000; /* preserve PIO format bit */
165 pci_write_config_dword(hwif->pci_dev, basereg+4, timings); 164 pci_write_config_dword(dev, basereg + 4, timings);
166 } else { 165 } else
167 pci_write_config_dword(hwif->pci_dev, basereg+12, timings); 166 pci_write_config_dword(dev, basereg + 12, timings);
168 }
169} 167}
170 168
171/* Replacement for the standard ide_dma_end action in 169/* Replacement for the standard ide_dma_end action in
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c
index 24a85bbcd2a..7694969b02c 100644
--- a/drivers/ide/pci/scc_pata.c
+++ b/drivers/ide/pci/scc_pata.c
@@ -594,7 +594,7 @@ static int __devinit init_setup_scc(struct pci_dev *dev,
594 594
595static void __devinit init_mmio_iops_scc(ide_hwif_t *hwif) 595static void __devinit init_mmio_iops_scc(ide_hwif_t *hwif)
596{ 596{
597 struct pci_dev *dev = hwif->pci_dev; 597 struct pci_dev *dev = to_pci_dev(hwif->dev);
598 struct scc_ports *ports = pci_get_drvdata(dev); 598 struct scc_ports *ports = pci_get_drvdata(dev);
599 unsigned long dma_base = ports->dma; 599 unsigned long dma_base = ports->dma;
600 600
@@ -620,7 +620,7 @@ static void __devinit init_mmio_iops_scc(ide_hwif_t *hwif)
620 hwif->io_ports[IDE_STATUS_OFFSET] = dma_base + 0x3c; 620 hwif->io_ports[IDE_STATUS_OFFSET] = dma_base + 0x3c;
621 hwif->io_ports[IDE_CONTROL_OFFSET] = dma_base + 0x40; 621 hwif->io_ports[IDE_CONTROL_OFFSET] = dma_base + 0x40;
622 622
623 hwif->irq = hwif->pci_dev->irq; 623 hwif->irq = dev->irq;
624 hwif->dma_base = dma_base; 624 hwif->dma_base = dma_base;
625 hwif->config_data = ports->ctl; 625 hwif->config_data = ports->ctl;
626 hwif->mmio = 1; 626 hwif->mmio = 1;
@@ -636,7 +636,8 @@ static void __devinit init_mmio_iops_scc(ide_hwif_t *hwif)
636 636
637static void __devinit init_iops_scc(ide_hwif_t *hwif) 637static void __devinit init_iops_scc(ide_hwif_t *hwif)
638{ 638{
639 struct pci_dev *dev = hwif->pci_dev; 639 struct pci_dev *dev = to_pci_dev(hwif->dev);
640
640 hwif->hwif_data = NULL; 641 hwif->hwif_data = NULL;
641 if (pci_get_drvdata(dev) == NULL) 642 if (pci_get_drvdata(dev) == NULL)
642 return; 643 return;
@@ -726,10 +727,8 @@ static void __devexit scc_remove(struct pci_dev *dev)
726 unsigned long dma_size = pci_resource_len(dev, 1); 727 unsigned long dma_size = pci_resource_len(dev, 1);
727 728
728 if (hwif->dmatable_cpu) { 729 if (hwif->dmatable_cpu) {
729 pci_free_consistent(hwif->pci_dev, 730 pci_free_consistent(dev, PRD_ENTRIES * PRD_BYTES,
730 PRD_ENTRIES * PRD_BYTES, 731 hwif->dmatable_cpu, hwif->dmatable_dma);
731 hwif->dmatable_cpu,
732 hwif->dmatable_dma);
733 hwif->dmatable_cpu = NULL; 732 hwif->dmatable_cpu = NULL;
734 } 733 }
735 734
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index 877c09bf482..f495253b7d4 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/serverworks.c Version 0.22 Jun 27 2007
3 *
4 * Copyright (C) 1998-2000 Michel Aubry 2 * Copyright (C) 1998-2000 Michel Aubry
5 * Copyright (C) 1998-2000 Andrzej Krzysztofowicz 3 * Copyright (C) 1998-2000 Andrzej Krzysztofowicz
6 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
@@ -67,7 +65,7 @@ static int check_in_drive_lists (ide_drive_t *drive, const char **list)
67 65
68static u8 svwks_udma_filter(ide_drive_t *drive) 66static u8 svwks_udma_filter(ide_drive_t *drive)
69{ 67{
70 struct pci_dev *dev = HWIF(drive)->pci_dev; 68 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
71 u8 mask = 0; 69 u8 mask = 0;
72 70
73 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE) 71 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE)
@@ -130,7 +128,7 @@ static void svwks_set_pio_mode(ide_drive_t *drive, const u8 pio)
130 static const u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 }; 128 static const u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 };
131 static const u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 }; 129 static const u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 };
132 130
133 struct pci_dev *dev = drive->hwif->pci_dev; 131 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
134 132
135 pci_write_config_byte(dev, drive_pci[drive->dn], pio_modes[pio]); 133 pci_write_config_byte(dev, drive_pci[drive->dn], pio_modes[pio]);
136 134
@@ -153,7 +151,7 @@ static void svwks_set_dma_mode(ide_drive_t *drive, const u8 speed)
153 static const u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 }; 151 static const u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 };
154 152
155 ide_hwif_t *hwif = HWIF(drive); 153 ide_hwif_t *hwif = HWIF(drive);
156 struct pci_dev *dev = hwif->pci_dev; 154 struct pci_dev *dev = to_pci_dev(hwif->dev);
157 u8 unit = (drive->select.b.unit & 0x01); 155 u8 unit = (drive->select.b.unit & 0x01);
158 156
159 u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0; 157 u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0;
@@ -287,7 +285,8 @@ static u8 __devinit ata66_svwks_svwks(ide_hwif_t *hwif)
287 */ 285 */
288static u8 __devinit ata66_svwks_dell(ide_hwif_t *hwif) 286static u8 __devinit ata66_svwks_dell(ide_hwif_t *hwif)
289{ 287{
290 struct pci_dev *dev = hwif->pci_dev; 288 struct pci_dev *dev = to_pci_dev(hwif->dev);
289
291 if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL && 290 if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
292 dev->vendor == PCI_VENDOR_ID_SERVERWORKS && 291 dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
293 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE || 292 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE ||
@@ -305,7 +304,8 @@ static u8 __devinit ata66_svwks_dell(ide_hwif_t *hwif)
305 */ 304 */
306static u8 __devinit ata66_svwks_cobalt(ide_hwif_t *hwif) 305static u8 __devinit ata66_svwks_cobalt(ide_hwif_t *hwif)
307{ 306{
308 struct pci_dev *dev = hwif->pci_dev; 307 struct pci_dev *dev = to_pci_dev(hwif->dev);
308
309 if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN && 309 if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN &&
310 dev->vendor == PCI_VENDOR_ID_SERVERWORKS && 310 dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
311 dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) 311 dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE)
@@ -316,7 +316,7 @@ static u8 __devinit ata66_svwks_cobalt(ide_hwif_t *hwif)
316 316
317static u8 __devinit ata66_svwks(ide_hwif_t *hwif) 317static u8 __devinit ata66_svwks(ide_hwif_t *hwif)
318{ 318{
319 struct pci_dev *dev = hwif->pci_dev; 319 struct pci_dev *dev = to_pci_dev(hwif->dev);
320 320
321 /* Server Works */ 321 /* Server Works */
322 if (dev->subsystem_vendor == PCI_VENDOR_ID_SERVERWORKS) 322 if (dev->subsystem_vendor == PCI_VENDOR_ID_SERVERWORKS)
@@ -340,6 +340,8 @@ static u8 __devinit ata66_svwks(ide_hwif_t *hwif)
340 340
341static void __devinit init_hwif_svwks (ide_hwif_t *hwif) 341static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
342{ 342{
343 struct pci_dev *dev = to_pci_dev(hwif->dev);
344
343 hwif->set_pio_mode = &svwks_set_pio_mode; 345 hwif->set_pio_mode = &svwks_set_pio_mode;
344 hwif->set_dma_mode = &svwks_set_dma_mode; 346 hwif->set_dma_mode = &svwks_set_dma_mode;
345 hwif->udma_filter = &svwks_udma_filter; 347 hwif->udma_filter = &svwks_udma_filter;
@@ -347,7 +349,7 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
347 if (!hwif->dma_base) 349 if (!hwif->dma_base)
348 return; 350 return;
349 351
350 if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) { 352 if (dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
351 if (hwif->cbl != ATA_CBL_PATA40_SHORT) 353 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
352 hwif->cbl = ata66_svwks(hwif); 354 hwif->cbl = ata66_svwks(hwif);
353 } 355 }
@@ -418,7 +420,9 @@ static int __devinit svwks_init_one(struct pci_dev *dev, const struct pci_device
418 420
419 d = serverworks_chipsets[idx]; 421 d = serverworks_chipsets[idx];
420 422
421 if (idx == 2 || idx == 3) { 423 if (idx == 1)
424 d.host_flags |= IDE_HFLAG_CLEAR_SIMPLEX;
425 else if (idx == 2 || idx == 3) {
422 if ((PCI_FUNC(dev->devfn) & 1) == 0) { 426 if ((PCI_FUNC(dev->devfn) & 1) == 0) {
423 if (pci_resource_start(dev, 0) != 0x01f1) 427 if (pci_resource_start(dev, 0) != 0x01f1)
424 d.host_flags &= ~IDE_HFLAG_BOOTABLE; 428 d.host_flags &= ~IDE_HFLAG_BOOTABLE;
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index 9e0be7d5498..85902074b1f 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -159,6 +159,7 @@ sgiioc4_clearirq(ide_drive_t * drive)
159 } 159 }
160 160
161 if (intr_reg & 0x02) { 161 if (intr_reg & 0x02) {
162 struct pci_dev *dev = to_pci_dev(hwif->dev);
162 /* Error when transferring DMA data on PCI bus */ 163 /* Error when transferring DMA data on PCI bus */
163 u32 pci_err_addr_low, pci_err_addr_high, 164 u32 pci_err_addr_low, pci_err_addr_high,
164 pci_stat_cmd_reg; 165 pci_stat_cmd_reg;
@@ -167,7 +168,7 @@ sgiioc4_clearirq(ide_drive_t * drive)
167 readl((void __iomem *)hwif->io_ports[IDE_IRQ_OFFSET]); 168 readl((void __iomem *)hwif->io_ports[IDE_IRQ_OFFSET]);
168 pci_err_addr_high = 169 pci_err_addr_high =
169 readl((void __iomem *)(hwif->io_ports[IDE_IRQ_OFFSET] + 4)); 170 readl((void __iomem *)(hwif->io_ports[IDE_IRQ_OFFSET] + 4));
170 pci_read_config_dword(hwif->pci_dev, PCI_COMMAND, 171 pci_read_config_dword(dev, PCI_COMMAND,
171 &pci_stat_cmd_reg); 172 &pci_stat_cmd_reg);
172 printk(KERN_ERR 173 printk(KERN_ERR
173 "%s(%s) : PCI Bus Error when doing DMA:" 174 "%s(%s) : PCI Bus Error when doing DMA:"
@@ -178,8 +179,7 @@ sgiioc4_clearirq(ide_drive_t * drive)
178 __FUNCTION__, drive->name, 179 __FUNCTION__, drive->name,
179 pci_err_addr_high, pci_err_addr_low); 180 pci_err_addr_high, pci_err_addr_low);
180 /* Clear the PCI Error indicator */ 181 /* Clear the PCI Error indicator */
181 pci_write_config_dword(hwif->pci_dev, PCI_COMMAND, 182 pci_write_config_dword(dev, PCI_COMMAND, 0x00000146);
182 0x00000146);
183 } 183 }
184 184
185 /* Clear the Interrupt, Error bits on the IOC4 */ 185 /* Clear the Interrupt, Error bits on the IOC4 */
@@ -334,6 +334,7 @@ sgiioc4_INB(unsigned long port)
334static int __devinit 334static int __devinit
335ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base) 335ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base)
336{ 336{
337 struct pci_dev *dev = to_pci_dev(hwif->dev);
337 void __iomem *virt_dma_base; 338 void __iomem *virt_dma_base;
338 int num_ports = sizeof (ioc4_dma_regs_t); 339 int num_ports = sizeof (ioc4_dma_regs_t);
339 void *pad; 340 void *pad;
@@ -359,7 +360,7 @@ ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base)
359 } 360 }
360 hwif->dma_base = (unsigned long) virt_dma_base; 361 hwif->dma_base = (unsigned long) virt_dma_base;
361 362
362 hwif->dmatable_cpu = pci_alloc_consistent(hwif->pci_dev, 363 hwif->dmatable_cpu = pci_alloc_consistent(dev,
363 IOC4_PRD_ENTRIES * IOC4_PRD_BYTES, 364 IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
364 &hwif->dmatable_dma); 365 &hwif->dmatable_dma);
365 366
@@ -368,7 +369,7 @@ ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base)
368 369
369 hwif->sg_max_nents = IOC4_PRD_ENTRIES; 370 hwif->sg_max_nents = IOC4_PRD_ENTRIES;
370 371
371 pad = pci_alloc_consistent(hwif->pci_dev, IOC4_IDE_CACHELINE_SIZE, 372 pad = pci_alloc_consistent(dev, IOC4_IDE_CACHELINE_SIZE,
372 (dma_addr_t *) &(hwif->dma_status)); 373 (dma_addr_t *) &(hwif->dma_status));
373 374
374 if (pad) { 375 if (pad) {
@@ -376,8 +377,7 @@ ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base)
376 return 0; 377 return 0;
377 } 378 }
378 379
379 pci_free_consistent(hwif->pci_dev, 380 pci_free_consistent(dev, IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
380 IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
381 hwif->dmatable_cpu, hwif->dmatable_dma); 381 hwif->dmatable_cpu, hwif->dmatable_dma);
382 printk(KERN_INFO 382 printk(KERN_INFO
383 "%s() -- Error! Unable to allocate DMA Maps for drive %s\n", 383 "%s() -- Error! Unable to allocate DMA Maps for drive %s\n",
@@ -517,8 +517,7 @@ sgiioc4_build_dma_table(ide_drive_t * drive, struct request *rq, int ddir)
517 } 517 }
518 518
519use_pio_instead: 519use_pio_instead:
520 pci_unmap_sg(hwif->pci_dev, hwif->sg_table, hwif->sg_nents, 520 ide_destroy_dmatable(drive);
521 hwif->sg_dma_direction);
522 521
523 return 0; /* revert to PIO for this request */ 522 return 0; /* revert to PIO for this request */
524} 523}
@@ -641,7 +640,7 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
641 hw.dev = &dev->dev; 640 hw.dev = &dev->dev;
642 ide_init_port_hw(hwif, &hw); 641 ide_init_port_hw(hwif, &hw);
643 642
644 hwif->pci_dev = dev; 643 hwif->dev = &dev->dev;
645 hwif->channel = 0; /* Single Channel chip */ 644 hwif->channel = 0; /* Single Channel chip */
646 645
647 /* The IOC4 uses MMIO rather than Port IO. */ 646 /* The IOC4 uses MMIO rather than Port IO. */
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 908f37b4e0e..4877bc8cd59 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/siimage.c Version 1.19 Nov 16 2007
3 *
4 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2003 Red Hat <alan@redhat.com> 3 * Copyright (C) 2003 Red Hat <alan@redhat.com>
6 * Copyright (C) 2007 MontaVista Software, Inc. 4 * Copyright (C) 2007 MontaVista Software, Inc.
@@ -79,7 +77,7 @@ static int pdev_is_sata(struct pci_dev *pdev)
79 77
80static inline int is_sata(ide_hwif_t *hwif) 78static inline int is_sata(ide_hwif_t *hwif)
81{ 79{
82 return pdev_is_sata(hwif->pci_dev); 80 return pdev_is_sata(to_pci_dev(hwif->dev));
83} 81}
84 82
85/** 83/**
@@ -140,13 +138,14 @@ static inline unsigned long siimage_seldev(ide_drive_t *drive, int r)
140static u8 sil_pata_udma_filter(ide_drive_t *drive) 138static u8 sil_pata_udma_filter(ide_drive_t *drive)
141{ 139{
142 ide_hwif_t *hwif = drive->hwif; 140 ide_hwif_t *hwif = drive->hwif;
141 struct pci_dev *dev = to_pci_dev(hwif->dev);
143 unsigned long base = (unsigned long) hwif->hwif_data; 142 unsigned long base = (unsigned long) hwif->hwif_data;
144 u8 mask = 0, scsc = 0; 143 u8 mask = 0, scsc = 0;
145 144
146 if (hwif->mmio) 145 if (hwif->mmio)
147 scsc = hwif->INB(base + 0x4A); 146 scsc = hwif->INB(base + 0x4A);
148 else 147 else
149 pci_read_config_byte(hwif->pci_dev, 0x8A, &scsc); 148 pci_read_config_byte(dev, 0x8A, &scsc);
150 149
151 if ((scsc & 0x30) == 0x10) /* 133 */ 150 if ((scsc & 0x30) == 0x10) /* 133 */
152 mask = ATA_UDMA6; 151 mask = ATA_UDMA6;
@@ -219,19 +218,21 @@ static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
219 mode |= (unit ? 0x10 : 0x01); 218 mode |= (unit ? 0x10 : 0x01);
220 hwif->OUTB(mode, base + addr_mask); 219 hwif->OUTB(mode, base + addr_mask);
221 } else { 220 } else {
222 pci_write_config_word(hwif->pci_dev, addr, speedp); 221 struct pci_dev *dev = to_pci_dev(hwif->dev);
223 pci_write_config_word(hwif->pci_dev, tfaddr, speedt); 222
224 pci_read_config_word(hwif->pci_dev, tfaddr-2, &speedp); 223 pci_write_config_word(dev, addr, speedp);
224 pci_write_config_word(dev, tfaddr, speedt);
225 pci_read_config_word(dev, tfaddr - 2, &speedp);
225 speedp &= ~0x200; 226 speedp &= ~0x200;
226 /* Set IORDY for mode 3 or 4 */ 227 /* Set IORDY for mode 3 or 4 */
227 if (pio > 2) 228 if (pio > 2)
228 speedp |= 0x200; 229 speedp |= 0x200;
229 pci_write_config_word(hwif->pci_dev, tfaddr-2, speedp); 230 pci_write_config_word(dev, tfaddr - 2, speedp);
230 231
231 pci_read_config_byte(hwif->pci_dev, addr_mask, &mode); 232 pci_read_config_byte(dev, addr_mask, &mode);
232 mode &= ~(unit ? 0x30 : 0x03); 233 mode &= ~(unit ? 0x30 : 0x03);
233 mode |= (unit ? 0x10 : 0x01); 234 mode |= (unit ? 0x10 : 0x01);
234 pci_write_config_byte(hwif->pci_dev, addr_mask, mode); 235 pci_write_config_byte(dev, addr_mask, mode);
235 } 236 }
236} 237}
237 238
@@ -250,6 +251,7 @@ static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed)
250 u16 dma[] = { 0x2208, 0x10C2, 0x10C1 }; 251 u16 dma[] = { 0x2208, 0x10C2, 0x10C1 };
251 252
252 ide_hwif_t *hwif = HWIF(drive); 253 ide_hwif_t *hwif = HWIF(drive);
254 struct pci_dev *dev = to_pci_dev(hwif->dev);
253 u16 ultra = 0, multi = 0; 255 u16 ultra = 0, multi = 0;
254 u8 mode = 0, unit = drive->select.b.unit; 256 u8 mode = 0, unit = drive->select.b.unit;
255 unsigned long base = (unsigned long)hwif->hwif_data; 257 unsigned long base = (unsigned long)hwif->hwif_data;
@@ -266,10 +268,10 @@ static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed)
266 multi = hwif->INW(ma); 268 multi = hwif->INW(ma);
267 ultra = hwif->INW(ua); 269 ultra = hwif->INW(ua);
268 } else { 270 } else {
269 pci_read_config_byte(hwif->pci_dev, 0x8A, &scsc); 271 pci_read_config_byte(dev, 0x8A, &scsc);
270 pci_read_config_byte(hwif->pci_dev, addr_mask, &mode); 272 pci_read_config_byte(dev, addr_mask, &mode);
271 pci_read_config_word(hwif->pci_dev, ma, &multi); 273 pci_read_config_word(dev, ma, &multi);
272 pci_read_config_word(hwif->pci_dev, ua, &ultra); 274 pci_read_config_word(dev, ua, &ultra);
273 } 275 }
274 276
275 mode &= ~((unit) ? 0x30 : 0x03); 277 mode &= ~((unit) ? 0x30 : 0x03);
@@ -293,9 +295,9 @@ static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed)
293 hwif->OUTW(multi, ma); 295 hwif->OUTW(multi, ma);
294 hwif->OUTW(ultra, ua); 296 hwif->OUTW(ultra, ua);
295 } else { 297 } else {
296 pci_write_config_byte(hwif->pci_dev, addr_mask, mode); 298 pci_write_config_byte(dev, addr_mask, mode);
297 pci_write_config_word(hwif->pci_dev, ma, multi); 299 pci_write_config_word(dev, ma, multi);
298 pci_write_config_word(hwif->pci_dev, ua, ultra); 300 pci_write_config_word(dev, ua, ultra);
299 } 301 }
300} 302}
301 303
@@ -303,6 +305,7 @@ static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed)
303static int siimage_io_ide_dma_test_irq (ide_drive_t *drive) 305static int siimage_io_ide_dma_test_irq (ide_drive_t *drive)
304{ 306{
305 ide_hwif_t *hwif = HWIF(drive); 307 ide_hwif_t *hwif = HWIF(drive);
308 struct pci_dev *dev = to_pci_dev(hwif->dev);
306 u8 dma_altstat = 0; 309 u8 dma_altstat = 0;
307 unsigned long addr = siimage_selreg(hwif, 1); 310 unsigned long addr = siimage_selreg(hwif, 1);
308 311
@@ -311,7 +314,7 @@ static int siimage_io_ide_dma_test_irq (ide_drive_t *drive)
311 return 1; 314 return 1;
312 315
313 /* return 1 if Device INTR asserted */ 316 /* return 1 if Device INTR asserted */
314 pci_read_config_byte(hwif->pci_dev, addr, &dma_altstat); 317 pci_read_config_byte(dev, addr, &dma_altstat);
315 if (dma_altstat & 8) 318 if (dma_altstat & 8)
316 return 0; //return 1; 319 return 0; //return 1;
317 return 0; 320 return 0;
@@ -377,13 +380,14 @@ static int siimage_mmio_ide_dma_test_irq (ide_drive_t *drive)
377static int sil_sata_busproc(ide_drive_t * drive, int state) 380static int sil_sata_busproc(ide_drive_t * drive, int state)
378{ 381{
379 ide_hwif_t *hwif = HWIF(drive); 382 ide_hwif_t *hwif = HWIF(drive);
383 struct pci_dev *dev = to_pci_dev(hwif->dev);
380 u32 stat_config = 0; 384 u32 stat_config = 0;
381 unsigned long addr = siimage_selreg(hwif, 0); 385 unsigned long addr = siimage_selreg(hwif, 0);
382 386
383 if (hwif->mmio) 387 if (hwif->mmio)
384 stat_config = readl((void __iomem *)addr); 388 stat_config = readl((void __iomem *)addr);
385 else 389 else
386 pci_read_config_dword(hwif->pci_dev, addr, &stat_config); 390 pci_read_config_dword(dev, addr, &stat_config);
387 391
388 switch (state) { 392 switch (state) {
389 case BUSSTATE_ON: 393 case BUSSTATE_ON:
@@ -643,7 +647,7 @@ static unsigned int __devinit init_chipset_siimage(struct pci_dev *dev, const ch
643 647
644static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif) 648static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
645{ 649{
646 struct pci_dev *dev = hwif->pci_dev; 650 struct pci_dev *dev = to_pci_dev(hwif->dev);
647 void *addr = pci_get_drvdata(dev); 651 void *addr = pci_get_drvdata(dev);
648 u8 ch = hwif->channel; 652 u8 ch = hwif->channel;
649 hw_regs_t hw; 653 hw_regs_t hw;
@@ -756,12 +760,14 @@ static void __devinit sil_quirkproc(ide_drive_t *drive)
756 760
757static void __devinit init_iops_siimage(ide_hwif_t *hwif) 761static void __devinit init_iops_siimage(ide_hwif_t *hwif)
758{ 762{
763 struct pci_dev *dev = to_pci_dev(hwif->dev);
764
759 hwif->hwif_data = NULL; 765 hwif->hwif_data = NULL;
760 766
761 /* Pessimal until we finish probing */ 767 /* Pessimal until we finish probing */
762 hwif->rqsize = 15; 768 hwif->rqsize = 15;
763 769
764 if (pci_get_drvdata(hwif->pci_dev) == NULL) 770 if (pci_get_drvdata(dev) == NULL)
765 return; 771 return;
766 772
767 init_mmio_iops_siimage(hwif); 773 init_mmio_iops_siimage(hwif);
@@ -777,11 +783,12 @@ static void __devinit init_iops_siimage(ide_hwif_t *hwif)
777 783
778static u8 __devinit ata66_siimage(ide_hwif_t *hwif) 784static u8 __devinit ata66_siimage(ide_hwif_t *hwif)
779{ 785{
786 struct pci_dev *dev = to_pci_dev(hwif->dev);
780 unsigned long addr = siimage_selreg(hwif, 0); 787 unsigned long addr = siimage_selreg(hwif, 0);
781 u8 ata66 = 0; 788 u8 ata66 = 0;
782 789
783 if (pci_get_drvdata(hwif->pci_dev) == NULL) 790 if (pci_get_drvdata(dev) == NULL)
784 pci_read_config_byte(hwif->pci_dev, addr, &ata66); 791 pci_read_config_byte(dev, addr, &ata66);
785 else 792 else
786 ata66 = hwif->INB(addr); 793 ata66 = hwif->INB(addr);
787 794
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 85d36996e6a..2a461de22aa 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/sis5513.c Version 0.31 Aug 9, 2007
3 *
4 * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2002 Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer 3 * Copyright (C) 2002 Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer
6 * Copyright (C) 2003 Vojtech Pavlik <vojtech@suse.cz> 4 * Copyright (C) 2003 Vojtech Pavlik <vojtech@suse.cz>
@@ -197,7 +195,7 @@ static char* chipset_capability[] = {
197 195
198static u8 sis_ata133_get_base(ide_drive_t *drive) 196static u8 sis_ata133_get_base(ide_drive_t *drive)
199{ 197{
200 struct pci_dev *dev = drive->hwif->pci_dev; 198 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
201 u32 reg54 = 0; 199 u32 reg54 = 0;
202 200
203 pci_read_config_dword(dev, 0x54, &reg54); 201 pci_read_config_dword(dev, 0x54, &reg54);
@@ -207,7 +205,7 @@ static u8 sis_ata133_get_base(ide_drive_t *drive)
207 205
208static void sis_ata16_program_timings(ide_drive_t *drive, const u8 mode) 206static void sis_ata16_program_timings(ide_drive_t *drive, const u8 mode)
209{ 207{
210 struct pci_dev *dev = drive->hwif->pci_dev; 208 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
211 u16 t1 = 0; 209 u16 t1 = 0;
212 u8 drive_pci = 0x40 + drive->dn * 2; 210 u8 drive_pci = 0x40 + drive->dn * 2;
213 211
@@ -230,7 +228,7 @@ static void sis_ata16_program_timings(ide_drive_t *drive, const u8 mode)
230 228
231static void sis_ata100_program_timings(ide_drive_t *drive, const u8 mode) 229static void sis_ata100_program_timings(ide_drive_t *drive, const u8 mode)
232{ 230{
233 struct pci_dev *dev = drive->hwif->pci_dev; 231 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
234 u8 t1, drive_pci = 0x40 + drive->dn * 2; 232 u8 t1, drive_pci = 0x40 + drive->dn * 2;
235 233
236 /* timing bits: 7:4 active 3:0 recovery */ 234 /* timing bits: 7:4 active 3:0 recovery */
@@ -253,7 +251,7 @@ static void sis_ata100_program_timings(ide_drive_t *drive, const u8 mode)
253 251
254static void sis_ata133_program_timings(ide_drive_t *drive, const u8 mode) 252static void sis_ata133_program_timings(ide_drive_t *drive, const u8 mode)
255{ 253{
256 struct pci_dev *dev = drive->hwif->pci_dev; 254 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
257 u32 t1 = 0; 255 u32 t1 = 0;
258 u8 drive_pci = sis_ata133_get_base(drive), clk, idx; 256 u8 drive_pci = sis_ata133_get_base(drive), clk, idx;
259 257
@@ -286,7 +284,7 @@ static void sis_program_timings(ide_drive_t *drive, const u8 mode)
286static void config_drive_art_rwp (ide_drive_t *drive) 284static void config_drive_art_rwp (ide_drive_t *drive)
287{ 285{
288 ide_hwif_t *hwif = HWIF(drive); 286 ide_hwif_t *hwif = HWIF(drive);
289 struct pci_dev *dev = hwif->pci_dev; 287 struct pci_dev *dev = to_pci_dev(hwif->dev);
290 u8 reg4bh = 0; 288 u8 reg4bh = 0;
291 u8 rw_prefetch = 0; 289 u8 rw_prefetch = 0;
292 290
@@ -307,7 +305,7 @@ static void sis_set_pio_mode(ide_drive_t *drive, const u8 pio)
307 305
308static void sis_ata133_program_udma_timings(ide_drive_t *drive, const u8 mode) 306static void sis_ata133_program_udma_timings(ide_drive_t *drive, const u8 mode)
309{ 307{
310 struct pci_dev *dev = drive->hwif->pci_dev; 308 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
311 u32 regdw = 0; 309 u32 regdw = 0;
312 u8 drive_pci = sis_ata133_get_base(drive), clk, idx; 310 u8 drive_pci = sis_ata133_get_base(drive), clk, idx;
313 311
@@ -326,7 +324,7 @@ static void sis_ata133_program_udma_timings(ide_drive_t *drive, const u8 mode)
326 324
327static void sis_ata33_program_udma_timings(ide_drive_t *drive, const u8 mode) 325static void sis_ata33_program_udma_timings(ide_drive_t *drive, const u8 mode)
328{ 326{
329 struct pci_dev *dev = drive->hwif->pci_dev; 327 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
330 u8 drive_pci = 0x40 + drive->dn * 2, reg = 0, i = chipset_family; 328 u8 drive_pci = 0x40 + drive->dn * 2, reg = 0, i = chipset_family;
331 329
332 pci_read_config_byte(dev, drive_pci + 1, &reg); 330 pci_read_config_byte(dev, drive_pci + 1, &reg);
@@ -359,7 +357,7 @@ static void sis_set_dma_mode(ide_drive_t *drive, const u8 speed)
359 357
360static u8 sis5513_ata133_udma_filter(ide_drive_t *drive) 358static u8 sis5513_ata133_udma_filter(ide_drive_t *drive)
361{ 359{
362 struct pci_dev *dev = drive->hwif->pci_dev; 360 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
363 u32 regdw = 0; 361 u32 regdw = 0;
364 u8 drive_pci = sis_ata133_get_base(drive); 362 u8 drive_pci = sis_ata133_get_base(drive);
365 363
@@ -530,7 +528,7 @@ static const struct sis_laptop sis_laptop[] = {
530 528
531static u8 __devinit ata66_sis5513(ide_hwif_t *hwif) 529static u8 __devinit ata66_sis5513(ide_hwif_t *hwif)
532{ 530{
533 struct pci_dev *pdev = hwif->pci_dev; 531 struct pci_dev *pdev = to_pci_dev(hwif->dev);
534 const struct sis_laptop *lap = &sis_laptop[0]; 532 const struct sis_laptop *lap = &sis_laptop[0];
535 u8 ata66 = 0; 533 u8 ata66 = 0;
536 534
@@ -545,12 +543,12 @@ static u8 __devinit ata66_sis5513(ide_hwif_t *hwif)
545 if (chipset_family >= ATA_133) { 543 if (chipset_family >= ATA_133) {
546 u16 regw = 0; 544 u16 regw = 0;
547 u16 reg_addr = hwif->channel ? 0x52: 0x50; 545 u16 reg_addr = hwif->channel ? 0x52: 0x50;
548 pci_read_config_word(hwif->pci_dev, reg_addr, &regw); 546 pci_read_config_word(pdev, reg_addr, &regw);
549 ata66 = (regw & 0x8000) ? 0 : 1; 547 ata66 = (regw & 0x8000) ? 0 : 1;
550 } else if (chipset_family >= ATA_66) { 548 } else if (chipset_family >= ATA_66) {
551 u8 reg48h = 0; 549 u8 reg48h = 0;
552 u8 mask = hwif->channel ? 0x20 : 0x10; 550 u8 mask = hwif->channel ? 0x20 : 0x10;
553 pci_read_config_byte(hwif->pci_dev, 0x48, &reg48h); 551 pci_read_config_byte(pdev, 0x48, &reg48h);
554 ata66 = (reg48h & mask) ? 0 : 1; 552 ata66 = (reg48h & mask) ? 0 : 1;
555 } 553 }
556 554
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index c7a125b66c2..da13a1298ad 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/sl82c105.c
3 *
4 * SL82C105/Winbond 553 IDE driver 2 * SL82C105/Winbond 553 IDE driver
5 * 3 *
6 * Maintainer unknown. 4 * Maintainer unknown.
@@ -78,7 +76,7 @@ static unsigned int get_pio_timings(ide_drive_t *drive, u8 pio)
78 */ 76 */
79static void sl82c105_set_pio_mode(ide_drive_t *drive, const u8 pio) 77static void sl82c105_set_pio_mode(ide_drive_t *drive, const u8 pio)
80{ 78{
81 struct pci_dev *dev = HWIF(drive)->pci_dev; 79 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
82 int reg = 0x44 + drive->dn * 4; 80 int reg = 0x44 + drive->dn * 4;
83 u16 drv_ctrl; 81 u16 drv_ctrl;
84 82
@@ -147,7 +145,7 @@ static inline void sl82c105_reset_host(struct pci_dev *dev)
147static void sl82c105_dma_lost_irq(ide_drive_t *drive) 145static void sl82c105_dma_lost_irq(ide_drive_t *drive)
148{ 146{
149 ide_hwif_t *hwif = HWIF(drive); 147 ide_hwif_t *hwif = HWIF(drive);
150 struct pci_dev *dev = hwif->pci_dev; 148 struct pci_dev *dev = to_pci_dev(hwif->dev);
151 u32 val, mask = hwif->channel ? CTRL_IDE_IRQB : CTRL_IDE_IRQA; 149 u32 val, mask = hwif->channel ? CTRL_IDE_IRQB : CTRL_IDE_IRQA;
152 u8 dma_cmd; 150 u8 dma_cmd;
153 151
@@ -184,7 +182,7 @@ static void sl82c105_dma_lost_irq(ide_drive_t *drive)
184static void sl82c105_dma_start(ide_drive_t *drive) 182static void sl82c105_dma_start(ide_drive_t *drive)
185{ 183{
186 ide_hwif_t *hwif = HWIF(drive); 184 ide_hwif_t *hwif = HWIF(drive);
187 struct pci_dev *dev = hwif->pci_dev; 185 struct pci_dev *dev = to_pci_dev(hwif->dev);
188 int reg = 0x44 + drive->dn * 4; 186 int reg = 0x44 + drive->dn * 4;
189 187
190 DBG(("%s(drive:%s)\n", __FUNCTION__, drive->name)); 188 DBG(("%s(drive:%s)\n", __FUNCTION__, drive->name));
@@ -197,15 +195,17 @@ static void sl82c105_dma_start(ide_drive_t *drive)
197 195
198static void sl82c105_dma_timeout(ide_drive_t *drive) 196static void sl82c105_dma_timeout(ide_drive_t *drive)
199{ 197{
198 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
199
200 DBG(("sl82c105_dma_timeout(drive:%s)\n", drive->name)); 200 DBG(("sl82c105_dma_timeout(drive:%s)\n", drive->name));
201 201
202 sl82c105_reset_host(HWIF(drive)->pci_dev); 202 sl82c105_reset_host(dev);
203 ide_dma_timeout(drive); 203 ide_dma_timeout(drive);
204} 204}
205 205
206static int sl82c105_dma_end(ide_drive_t *drive) 206static int sl82c105_dma_end(ide_drive_t *drive)
207{ 207{
208 struct pci_dev *dev = HWIF(drive)->pci_dev; 208 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
209 int reg = 0x44 + drive->dn * 4; 209 int reg = 0x44 + drive->dn * 4;
210 int ret; 210 int ret;
211 211
@@ -224,7 +224,7 @@ static int sl82c105_dma_end(ide_drive_t *drive)
224 */ 224 */
225static void sl82c105_resetproc(ide_drive_t *drive) 225static void sl82c105_resetproc(ide_drive_t *drive)
226{ 226{
227 struct pci_dev *dev = HWIF(drive)->pci_dev; 227 struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
228 u32 val; 228 u32 val;
229 229
230 DBG(("sl82c105_resetproc(drive:%s)\n", drive->name)); 230 DBG(("sl82c105_resetproc(drive:%s)\n", drive->name));
@@ -293,6 +293,7 @@ static unsigned int __devinit init_chipset_sl82c105(struct pci_dev *dev, const c
293 */ 293 */
294static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif) 294static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
295{ 295{
296 struct pci_dev *dev = to_pci_dev(hwif->dev);
296 unsigned int rev; 297 unsigned int rev;
297 298
298 DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index)); 299 DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index));
@@ -304,7 +305,7 @@ static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
304 if (!hwif->dma_base) 305 if (!hwif->dma_base)
305 return; 306 return;
306 307
307 rev = sl82c105_bridge_revision(hwif->pci_dev); 308 rev = sl82c105_bridge_revision(dev);
308 if (rev <= 5) { 309 if (rev <= 5) {
309 /* 310 /*
310 * Never ever EVER under any circumstances enable 311 * Never ever EVER under any circumstances enable
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index dbbb46819a2..a6cf810c469 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/pci/slc90e66.c Version 0.19 Sep 24, 2007
3 *
4 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2006-2007 MontaVista Software, Inc. <source@mvista.com> 3 * Copyright (C) 2006-2007 MontaVista Software, Inc. <source@mvista.com>
6 * 4 *
@@ -26,7 +24,7 @@ static DEFINE_SPINLOCK(slc90e66_lock);
26static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio) 24static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio)
27{ 25{
28 ide_hwif_t *hwif = HWIF(drive); 26 ide_hwif_t *hwif = HWIF(drive);
29 struct pci_dev *dev = hwif->pci_dev; 27 struct pci_dev *dev = to_pci_dev(hwif->dev);
30 int is_slave = drive->dn & 1; 28 int is_slave = drive->dn & 1;
31 int master_port = hwif->channel ? 0x42 : 0x40; 29 int master_port = hwif->channel ? 0x42 : 0x40;
32 int slave_port = 0x44; 30 int slave_port = 0x44;
@@ -79,7 +77,7 @@ static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio)
79static void slc90e66_set_dma_mode(ide_drive_t *drive, const u8 speed) 77static void slc90e66_set_dma_mode(ide_drive_t *drive, const u8 speed)
80{ 78{
81 ide_hwif_t *hwif = HWIF(drive); 79 ide_hwif_t *hwif = HWIF(drive);
82 struct pci_dev *dev = hwif->pci_dev; 80 struct pci_dev *dev = to_pci_dev(hwif->dev);
83 u8 maslave = hwif->channel ? 0x42 : 0x40; 81 u8 maslave = hwif->channel ? 0x42 : 0x40;
84 int sitre = 0, a_speed = 7 << (drive->dn * 4); 82 int sitre = 0, a_speed = 7 << (drive->dn * 4);
85 int u_speed = 0, u_flag = 1 << drive->dn; 83 int u_speed = 0, u_flag = 1 << drive->dn;
@@ -122,13 +120,14 @@ static void slc90e66_set_dma_mode(ide_drive_t *drive, const u8 speed)
122 120
123static void __devinit init_hwif_slc90e66 (ide_hwif_t *hwif) 121static void __devinit init_hwif_slc90e66 (ide_hwif_t *hwif)
124{ 122{
123 struct pci_dev *dev = to_pci_dev(hwif->dev);
125 u8 reg47 = 0; 124 u8 reg47 = 0;
126 u8 mask = hwif->channel ? 0x01 : 0x02; /* bit0:Primary */ 125 u8 mask = hwif->channel ? 0x01 : 0x02; /* bit0:Primary */
127 126
128 hwif->set_pio_mode = &slc90e66_set_pio_mode; 127 hwif->set_pio_mode = &slc90e66_set_pio_mode;
129 hwif->set_dma_mode = &slc90e66_set_dma_mode; 128 hwif->set_dma_mode = &slc90e66_set_dma_mode;
130 129
131 pci_read_config_byte(hwif->pci_dev, 0x47, &reg47); 130 pci_read_config_byte(dev, 0x47, &reg47);
132 131
133 if (hwif->dma_base == 0) 132 if (hwif->dma_base == 0)
134 return; 133 return;
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c
index e1faf6c2fe1..9fbbb4f2dd5 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/pci/tc86c001.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * drivers/ide/pci/tc86c001.c Version 1.01 Sep 5, 2007
3 *
4 * Copyright (C) 2002 Toshiba Corporation 2 * Copyright (C) 2002 Toshiba Corporation
5 * Copyright (C) 2005-2006 MontaVista Software, Inc. <source@mvista.com> 3 * Copyright (C) 2005-2006 MontaVista Software, Inc. <source@mvista.com>
6 * 4 *
@@ -164,7 +162,8 @@ static int tc86c001_busproc(ide_drive_t *drive, int state)
164 162
165static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif) 163static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
166{ 164{
167 unsigned long sc_base = pci_resource_start(hwif->pci_dev, 5); 165 struct pci_dev *dev = to_pci_dev(hwif->dev);
166 unsigned long sc_base = pci_resource_start(dev, 5);
168 u16 scr1 = inw(sc_base + 0x00); 167 u16 scr1 = inw(sc_base + 0x00);
169 168
170 /* System Control 1 Register bit 15 (Soft Reset) set */ 169 /* System Control 1 Register bit 15 (Soft Reset) set */
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index ae52a96a1cf..852b7269373 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * triflex.c
3 *
4 * IDE Chipset driver for the Compaq TriFlex IDE controller. 2 * IDE Chipset driver for the Compaq TriFlex IDE controller.
5 * 3 *
6 * Known to work with the Compaq Workstation 5x00 series. 4 * Known to work with the Compaq Workstation 5x00 series.
@@ -43,7 +41,7 @@
43static void triflex_set_mode(ide_drive_t *drive, const u8 speed) 41static void triflex_set_mode(ide_drive_t *drive, const u8 speed)
44{ 42{
45 ide_hwif_t *hwif = HWIF(drive); 43 ide_hwif_t *hwif = HWIF(drive);
46 struct pci_dev *dev = hwif->pci_dev; 44 struct pci_dev *dev = to_pci_dev(hwif->dev);
47 u8 channel_offset = hwif->channel ? 0x74 : 0x70; 45 u8 channel_offset = hwif->channel ? 0x74 : 0x70;
48 u16 timing = 0; 46 u16 timing = 0;
49 u32 triflex_timings = 0; 47 u32 triflex_timings = 0;
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c
index 04cd893e1ab..d9ebb698953 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/pci/trm290.c
@@ -1,8 +1,7 @@
1/* 1/*
2 * linux/drivers/ide/pci/trm290.c Version 1.05 Dec. 26, 2007
3 *
4 * Copyright (c) 1997-1998 Mark Lord 2 * Copyright (c) 1997-1998 Mark Lord
5 * Copyright (c) 2007 MontaVista Software, Inc. <source@mvista.com> 3 * Copyright (c) 2007 MontaVista Software, Inc. <source@mvista.com>
4 *
6 * May be copied or modified under the terms of the GNU General Public License 5 * May be copied or modified under the terms of the GNU General Public License
7 * 6 *
8 * June 22, 2004 - get rid of check_region 7 * June 22, 2004 - get rid of check_region
@@ -209,10 +208,10 @@ static int trm290_dma_setup(ide_drive_t *drive)
209 } 208 }
210 /* select DMA xfer */ 209 /* select DMA xfer */
211 trm290_prepare_drive(drive, 1); 210 trm290_prepare_drive(drive, 1);
212 outl(hwif->dmatable_dma | rw, hwif->dma_command); 211 outl(hwif->dmatable_dma | rw, hwif->dma_base);
213 drive->waiting_for_dma = 1; 212 drive->waiting_for_dma = 1;
214 /* start DMA */ 213 /* start DMA */
215 outw((count * 2) - 1, hwif->dma_status); 214 outw(count * 2 - 1, hwif->dma_base + 2);
216 return 0; 215 return 0;
217} 216}
218 217
@@ -222,23 +221,21 @@ static void trm290_dma_start(ide_drive_t *drive)
222 221
223static int trm290_ide_dma_end (ide_drive_t *drive) 222static int trm290_ide_dma_end (ide_drive_t *drive)
224{ 223{
225 ide_hwif_t *hwif = HWIF(drive); 224 u16 status;
226 u16 status = 0;
227 225
228 drive->waiting_for_dma = 0; 226 drive->waiting_for_dma = 0;
229 /* purge DMA mappings */ 227 /* purge DMA mappings */
230 ide_destroy_dmatable(drive); 228 ide_destroy_dmatable(drive);
231 status = inw(hwif->dma_status); 229 status = inw(HWIF(drive)->dma_base + 2);
232 return (status != 0x00ff); 230 return status != 0x00ff;
233} 231}
234 232
235static int trm290_ide_dma_test_irq (ide_drive_t *drive) 233static int trm290_ide_dma_test_irq (ide_drive_t *drive)
236{ 234{
237 ide_hwif_t *hwif = HWIF(drive); 235 u16 status;
238 u16 status = 0;
239 236
240 status = inw(hwif->dma_status); 237 status = inw(HWIF(drive)->dma_base + 2);
241 return (status == 0x00ff); 238 return status == 0x00ff;
242} 239}
243 240
244static void trm290_dma_host_set(ide_drive_t *drive, int on) 241static void trm290_dma_host_set(ide_drive_t *drive, int on)
@@ -247,21 +244,37 @@ static void trm290_dma_host_set(ide_drive_t *drive, int on)
247 244
248static void __devinit init_hwif_trm290(ide_hwif_t *hwif) 245static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
249{ 246{
250 unsigned int cfgbase = 0; 247 struct pci_dev *dev = to_pci_dev(hwif->dev);
248 unsigned int cfg_base = pci_resource_start(dev, 4);
251 unsigned long flags; 249 unsigned long flags;
252 u8 reg = 0; 250 u8 reg = 0;
253 struct pci_dev *dev = hwif->pci_dev; 251
254 252 if ((dev->class & 5) && cfg_base)
255 cfgbase = pci_resource_start(dev, 4); 253 printk(KERN_INFO "TRM290: chip");
256 if ((dev->class & 5) && cfgbase) { 254 else {
257 hwif->config_data = cfgbase; 255 cfg_base = 0x3df0;
258 printk(KERN_INFO "TRM290: chip config base at 0x%04lx\n", 256 printk(KERN_INFO "TRM290: using default");
259 hwif->config_data);
260 } else {
261 hwif->config_data = 0x3df0;
262 printk(KERN_INFO "TRM290: using default config base at 0x%04lx\n",
263 hwif->config_data);
264 } 257 }
258 printk(KERN_CONT " config base at 0x%04x\n", cfg_base);
259 hwif->config_data = cfg_base;
260 hwif->dma_base = (cfg_base + 4) ^ (hwif->channel ? 0x80 : 0);
261
262 printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx",
263 hwif->name, hwif->dma_base, hwif->dma_base + 3);
264
265 if (!request_region(hwif->dma_base, 4, hwif->name)) {
266 printk(KERN_CONT " -- Error, ports in use.\n");
267 return;
268 }
269
270 hwif->dmatable_cpu = pci_alloc_consistent(dev, PRD_ENTRIES * PRD_BYTES,
271 &hwif->dmatable_dma);
272 if (!hwif->dmatable_cpu) {
273 printk(KERN_CONT " -- Error, unable to allocate DMA table.\n");
274 release_region(hwif->dma_base, 4);
275 return;
276 }
277 printk(KERN_CONT "\n");
265 278
266 local_irq_save(flags); 279 local_irq_save(flags);
267 /* put config reg into first byte of hwif->select_data */ 280 /* put config reg into first byte of hwif->select_data */
@@ -276,15 +289,13 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
276 outb(reg, hwif->config_data + 3); 289 outb(reg, hwif->config_data + 3);
277 local_irq_restore(flags); 290 local_irq_restore(flags);
278 291
279 if ((reg & 0x10)) 292 if (reg & 0x10)
280 /* legacy mode */ 293 /* legacy mode */
281 hwif->irq = hwif->channel ? 15 : 14; 294 hwif->irq = hwif->channel ? 15 : 14;
282 else if (!hwif->irq && hwif->mate && hwif->mate->irq) 295 else if (!hwif->irq && hwif->mate && hwif->mate->irq)
283 /* sharing IRQ with mate */ 296 /* sharing IRQ with mate */
284 hwif->irq = hwif->mate->irq; 297 hwif->irq = hwif->mate->irq;
285 298
286 ide_setup_dma(hwif, (hwif->config_data + 4) ^ (hwif->channel ? 0x0080 : 0x0000), 3);
287
288 hwif->dma_host_set = &trm290_dma_host_set; 299 hwif->dma_host_set = &trm290_dma_host_set;
289 hwif->dma_setup = &trm290_dma_setup; 300 hwif->dma_setup = &trm290_dma_setup;
290 hwif->dma_exec_cmd = &trm290_dma_exec_cmd; 301 hwif->dma_exec_cmd = &trm290_dma_exec_cmd;
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index 4b32c90f489..24cb9047fb4 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -1,7 +1,4 @@
1/* 1/*
2 *
3 * Version 3.50
4 *
5 * VIA IDE driver for Linux. Supported southbridges: 2 * VIA IDE driver for Linux. Supported southbridges:
6 * 3 *
7 * vt82c576, vt82c586, vt82c586a, vt82c586b, vt82c596a, vt82c596b, 4 * vt82c576, vt82c586, vt82c586a, vt82c586b, vt82c596a, vt82c596b,
@@ -121,8 +118,8 @@ struct via82cxxx_dev
121 118
122static void via_set_speed(ide_hwif_t *hwif, u8 dn, struct ide_timing *timing) 119static void via_set_speed(ide_hwif_t *hwif, u8 dn, struct ide_timing *timing)
123{ 120{
124 struct pci_dev *dev = hwif->pci_dev; 121 struct pci_dev *dev = to_pci_dev(hwif->dev);
125 struct via82cxxx_dev *vdev = pci_get_drvdata(hwif->pci_dev); 122 struct via82cxxx_dev *vdev = pci_get_drvdata(dev);
126 u8 t; 123 u8 t;
127 124
128 if (~vdev->via_config->flags & VIA_BAD_AST) { 125 if (~vdev->via_config->flags & VIA_BAD_AST) {
@@ -159,8 +156,10 @@ static void via_set_speed(ide_hwif_t *hwif, u8 dn, struct ide_timing *timing)
159 156
160static void via_set_drive(ide_drive_t *drive, const u8 speed) 157static void via_set_drive(ide_drive_t *drive, const u8 speed)
161{ 158{
162 ide_drive_t *peer = HWIF(drive)->drives + (~drive->dn & 1); 159 ide_hwif_t *hwif = drive->hwif;
163 struct via82cxxx_dev *vdev = pci_get_drvdata(drive->hwif->pci_dev); 160 ide_drive_t *peer = hwif->drives + (~drive->dn & 1);
161 struct pci_dev *dev = to_pci_dev(hwif->dev);
162 struct via82cxxx_dev *vdev = pci_get_drvdata(dev);
164 struct ide_timing t, p; 163 struct ide_timing t, p;
165 unsigned int T, UT; 164 unsigned int T, UT;
166 165
@@ -408,7 +407,7 @@ static int via_cable_override(struct pci_dev *pdev)
408 407
409static u8 __devinit via82cxxx_cable_detect(ide_hwif_t *hwif) 408static u8 __devinit via82cxxx_cable_detect(ide_hwif_t *hwif)
410{ 409{
411 struct pci_dev *pdev = hwif->pci_dev; 410 struct pci_dev *pdev = to_pci_dev(hwif->dev);
412 struct via82cxxx_dev *vdev = pci_get_drvdata(pdev); 411 struct via82cxxx_dev *vdev = pci_get_drvdata(pdev);
413 412
414 if (via_cable_override(pdev)) 413 if (via_cable_override(pdev))
diff --git a/drivers/ide/ppc/mpc8xx.c b/drivers/ide/ppc/mpc8xx.c
index 3fd5d45b5e0..45c1d55e60d 100644
--- a/drivers/ide/ppc/mpc8xx.c
+++ b/drivers/ide/ppc/mpc8xx.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/drivers/ide/ppc/ide-m8xx.c
3 *
4 * Copyright (C) 2000, 2001 Wolfgang Denk, wd@denx.de 2 * Copyright (C) 2000, 2001 Wolfgang Denk, wd@denx.de
5 * Modified for direct IDE interface 3 * Modified for direct IDE interface
6 * by Thomas Lange, thomas@corelatus.com 4 * by Thomas Lange, thomas@corelatus.com
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index 736d12c8e68..23112ef68f6 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -1,7 +1,6 @@
1/* 1/*
2 * linux/drivers/ide/ppc/pmac.c
3 *
4 * Support for IDE interfaces on PowerMacs. 2 * Support for IDE interfaces on PowerMacs.
3 *
5 * These IDE interfaces are memory-mapped and have a DBDMA channel 4 * These IDE interfaces are memory-mapped and have a DBDMA channel
6 * for doing DMA. 5 * for doing DMA.
7 * 6 *
@@ -1011,7 +1010,7 @@ pmac_ide_do_resume(ide_hwif_t *hwif)
1011 * (it is kept in 2.4). This introduce an interface numbering change on some 1010 * (it is kept in 2.4). This introduce an interface numbering change on some
1012 * rare machines unfortunately, but it's better this way. 1011 * rare machines unfortunately, but it's better this way.
1013 */ 1012 */
1014static int 1013static int __devinit
1015pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif, hw_regs_t *hw) 1014pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif, hw_regs_t *hw)
1016{ 1015{
1017 struct device_node *np = pmif->node; 1016 struct device_node *np = pmif->node;
@@ -1200,7 +1199,7 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
1200 base = ioremap(macio_resource_start(mdev, 0), 0x400); 1199 base = ioremap(macio_resource_start(mdev, 0), 0x400);
1201 regbase = (unsigned long) base; 1200 regbase = (unsigned long) base;
1202 1201
1203 hwif->pci_dev = mdev->bus->pdev; 1202 hwif->dev = &mdev->bus->pdev->dev;
1204 1203
1205 pmif->mdev = mdev; 1204 pmif->mdev = mdev;
1206 pmif->node = mdev->ofdev.node; 1205 pmif->node = mdev->ofdev.node;
@@ -1228,12 +1227,12 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
1228 /* The inteface is released to the common IDE layer */ 1227 /* The inteface is released to the common IDE layer */
1229 dev_set_drvdata(&mdev->ofdev.dev, NULL); 1228 dev_set_drvdata(&mdev->ofdev.dev, NULL);
1230 iounmap(base); 1229 iounmap(base);
1231 if (pmif->dma_regs) 1230 if (pmif->dma_regs) {
1232 iounmap(pmif->dma_regs); 1231 iounmap(pmif->dma_regs);
1232 macio_release_resource(mdev, 1);
1233 }
1233 memset(pmif, 0, sizeof(*pmif)); 1234 memset(pmif, 0, sizeof(*pmif));
1234 macio_release_resource(mdev, 0); 1235 macio_release_resource(mdev, 0);
1235 if (pmif->dma_regs)
1236 macio_release_resource(mdev, 1);
1237 } 1236 }
1238 1237
1239 return rc; 1238 return rc;
@@ -1315,7 +1314,7 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1315 return -ENXIO; 1314 return -ENXIO;
1316 } 1315 }
1317 1316
1318 hwif->pci_dev = pdev; 1317 hwif->dev = &pdev->dev;
1319 pmif->mdev = NULL; 1318 pmif->mdev = NULL;
1320 pmif->node = np; 1319 pmif->node = np;
1321 1320
@@ -1535,11 +1534,10 @@ pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq)
1535 } 1534 }
1536 1535
1537 printk(KERN_DEBUG "%s: empty DMA table?\n", drive->name); 1536 printk(KERN_DEBUG "%s: empty DMA table?\n", drive->name);
1538 use_pio_instead: 1537
1539 pci_unmap_sg(hwif->pci_dev, 1538use_pio_instead:
1540 hwif->sg_table, 1539 ide_destroy_dmatable(drive);
1541 hwif->sg_nents, 1540
1542 hwif->sg_dma_direction);
1543 return 0; /* revert to PIO for this request */ 1541 return 0; /* revert to PIO for this request */
1544} 1542}
1545 1543
@@ -1548,12 +1546,9 @@ static void
1548pmac_ide_destroy_dmatable (ide_drive_t *drive) 1546pmac_ide_destroy_dmatable (ide_drive_t *drive)
1549{ 1547{
1550 ide_hwif_t *hwif = drive->hwif; 1548 ide_hwif_t *hwif = drive->hwif;
1551 struct pci_dev *dev = HWIF(drive)->pci_dev;
1552 struct scatterlist *sg = hwif->sg_table;
1553 int nents = hwif->sg_nents;
1554 1549
1555 if (nents) { 1550 if (hwif->sg_nents) {
1556 pci_unmap_sg(dev, sg, nents, hwif->sg_dma_direction); 1551 ide_destroy_dmatable(drive);
1557 hwif->sg_nents = 0; 1552 hwif->sg_nents = 0;
1558 } 1553 }
1559} 1554}
@@ -1726,13 +1721,15 @@ pmac_ide_dma_lost_irq (ide_drive_t *drive)
1726 * Allocate the data structures needed for using DMA with an interface 1721 * Allocate the data structures needed for using DMA with an interface
1727 * and fill the proper list of functions pointers 1722 * and fill the proper list of functions pointers
1728 */ 1723 */
1729static void __init 1724static void __devinit
1730pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif) 1725pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1731{ 1726{
1727 struct pci_dev *dev = to_pci_dev(hwif->dev);
1728
1732 /* We won't need pci_dev if we switch to generic consistent 1729 /* We won't need pci_dev if we switch to generic consistent
1733 * DMA routines ... 1730 * DMA routines ...
1734 */ 1731 */
1735 if (hwif->pci_dev == NULL) 1732 if (dev == NULL)
1736 return; 1733 return;
1737 /* 1734 /*
1738 * Allocate space for the DBDMA commands. 1735 * Allocate space for the DBDMA commands.
@@ -1740,7 +1737,7 @@ pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1740 * aligning the start address to a multiple of 16 bytes. 1737 * aligning the start address to a multiple of 16 bytes.
1741 */ 1738 */
1742 pmif->dma_table_cpu = (struct dbdma_cmd*)pci_alloc_consistent( 1739 pmif->dma_table_cpu = (struct dbdma_cmd*)pci_alloc_consistent(
1743 hwif->pci_dev, 1740 dev,
1744 (MAX_DCMDS + 2) * sizeof(struct dbdma_cmd), 1741 (MAX_DCMDS + 2) * sizeof(struct dbdma_cmd),
1745 &hwif->dmatable_dma); 1742 &hwif->dmatable_dma);
1746 if (pmif->dma_table_cpu == NULL) { 1743 if (pmif->dma_table_cpu == NULL) {
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index 676c66e7288..8ff5a0ef10a 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -1,9 +1,8 @@
1/* 1/*
2 * linux/drivers/ide/setup-pci.c Version 1.10 2002/08/19 2 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
3 * Copyright (C) 1995-1998 Mark Lord
4 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
3 * 5 *
4 * Copyright (c) 1998-2000 Andre Hedrick <andre@linux-ide.org>
5 *
6 * Copyright (c) 1995-1998 Mark Lord
7 * May be copied or modified under the terms of the GNU General Public License 6 * May be copied or modified under the terms of the GNU General Public License
8 */ 7 */
9 8
@@ -140,6 +139,16 @@ static int ide_setup_pci_baseregs (struct pci_dev *dev, const char *name)
140} 139}
141 140
142#ifdef CONFIG_BLK_DEV_IDEDMA_PCI 141#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
142static void ide_pci_clear_simplex(unsigned long dma_base, const char *name)
143{
144 u8 dma_stat = inb(dma_base + 2);
145
146 outb(dma_stat & 0x60, dma_base + 2);
147 dma_stat = inb(dma_base + 2);
148 if (dma_stat & 0x80)
149 printk(KERN_INFO "%s: simplex device: DMA forced\n", name);
150}
151
143/** 152/**
144 * ide_get_or_set_dma_base - setup BMIBA 153 * ide_get_or_set_dma_base - setup BMIBA
145 * @d: IDE port info 154 * @d: IDE port info
@@ -152,8 +161,9 @@ static int ide_setup_pci_baseregs (struct pci_dev *dev, const char *name)
152 161
153static unsigned long ide_get_or_set_dma_base(const struct ide_port_info *d, ide_hwif_t *hwif) 162static unsigned long ide_get_or_set_dma_base(const struct ide_port_info *d, ide_hwif_t *hwif)
154{ 163{
155 unsigned long dma_base = 0; 164 struct pci_dev *dev = to_pci_dev(hwif->dev);
156 struct pci_dev *dev = hwif->pci_dev; 165 unsigned long dma_base = 0;
166 u8 dma_stat = 0;
157 167
158 if (hwif->mmio) 168 if (hwif->mmio)
159 return hwif->dma_base; 169 return hwif->dma_base;
@@ -174,52 +184,30 @@ static unsigned long ide_get_or_set_dma_base(const struct ide_port_info *d, ide_
174 if (hwif->channel) 184 if (hwif->channel)
175 dma_base += 8; 185 dma_base += 8;
176 186
177 if ((d->host_flags & IDE_HFLAG_CS5520) == 0) { 187 if (d->host_flags & IDE_HFLAG_CS5520)
178 u8 simplex_stat = 0; 188 goto out;
179 189
180 switch(dev->device) { 190 if (d->host_flags & IDE_HFLAG_CLEAR_SIMPLEX) {
181 case PCI_DEVICE_ID_AL_M5219: 191 ide_pci_clear_simplex(dma_base, d->name);
182 case PCI_DEVICE_ID_AL_M5229: 192 goto out;
183 case PCI_DEVICE_ID_AMD_VIPER_7409: 193 }
184 case PCI_DEVICE_ID_CMD_643: 194
185 case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE: 195 /*
186 case PCI_DEVICE_ID_REVOLUTION: 196 * If the device claims "simplex" DMA, this means that only one of
187 simplex_stat = inb(dma_base + 2); 197 * the two interfaces can be trusted with DMA at any point in time
188 outb(simplex_stat & 0x60, dma_base + 2); 198 * (so we should enable DMA only on one of the two interfaces).
189 simplex_stat = inb(dma_base + 2); 199 *
190 if (simplex_stat & 0x80) { 200 * FIXME: At this point we haven't probed the drives so we can't make
191 printk(KERN_INFO "%s: simplex device: " 201 * the appropriate decision. Really we should defer this problem until
192 "DMA forced\n", 202 * we tune the drive then try to grab DMA ownership if we want to be
193 d->name); 203 * the DMA end. This has to be become dynamic to handle hot-plug.
194 } 204 */
195 break; 205 dma_stat = hwif->INB(dma_base + 2);
196 default: 206 if ((dma_stat & 0x80) && hwif->mate && hwif->mate->dma_base) {
197 /* 207 printk(KERN_INFO "%s: simplex device: DMA disabled\n", d->name);
198 * If the device claims "simplex" DMA, 208 dma_base = 0;
199 * this means only one of the two interfaces
200 * can be trusted with DMA at any point in time.
201 * So we should enable DMA only on one of the
202 * two interfaces.
203 */
204 simplex_stat = hwif->INB(dma_base + 2);
205 if (simplex_stat & 0x80) {
206 /* simplex device? */
207/*
208 * At this point we haven't probed the drives so we can't make the
209 * appropriate decision. Really we should defer this problem
210 * until we tune the drive then try to grab DMA ownership if we want
211 * to be the DMA end. This has to be become dynamic to handle hot
212 * plug.
213 */
214 if (hwif->mate && hwif->mate->dma_base) {
215 printk(KERN_INFO "%s: simplex device: "
216 "DMA disabled\n",
217 d->name);
218 dma_base = 0;
219 }
220 }
221 }
222 } 209 }
210out:
223 return dma_base; 211 return dma_base;
224} 212}
225#endif /* CONFIG_BLK_DEV_IDEDMA_PCI */ 213#endif /* CONFIG_BLK_DEV_IDEDMA_PCI */
@@ -402,7 +390,7 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, const struct ide_port
402 390
403 hwif->noprobe = oldnoprobe; 391 hwif->noprobe = oldnoprobe;
404 392
405 hwif->pci_dev = dev; 393 hwif->dev = &dev->dev;
406 hwif->cds = d; 394 hwif->cds = d;
407 hwif->channel = port; 395 hwif->channel = port;
408 396
@@ -451,7 +439,7 @@ static void ide_hwif_setup_dma(struct pci_dev *dev, const struct ide_port_info *
451 if (d->init_dma) { 439 if (d->init_dma) {
452 d->init_dma(hwif, dma_base); 440 d->init_dma(hwif, dma_base);
453 } else { 441 } else {
454 ide_setup_dma(hwif, dma_base, 8); 442 ide_setup_dma(hwif, dma_base);
455 } 443 }
456 } else { 444 } else {
457 printk(KERN_INFO "%s: %s Bus-Master DMA disabled " 445 printk(KERN_INFO "%s: %s Bus-Master DMA disabled "
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index db8bc20539e..5ed00069846 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -1,7 +1,6 @@
1/* 1/*
2 * linux/drivers/scsi/ide-scsi.c Version 0.9 Jul 4, 1999 2 * Copyright (C) 1996-1999 Gadi Oxman <gadio@netvision.net.il>
3 * 3 * Copyright (C) 2004-2005 Bartlomiej Zolnierkiewicz
4 * Copyright (C) 1996 - 1999 Gadi Oxman <gadio@netvision.net.il>
5 */ 4 */
6 5
7/* 6/*
diff --git a/include/asm-mips/mach-au1x00/au1xxx_ide.h b/include/asm-mips/mach-au1x00/au1xxx_ide.h
index aef0edbfe4c..e4fe26c160b 100644
--- a/include/asm-mips/mach-au1x00/au1xxx_ide.h
+++ b/include/asm-mips/mach-au1x00/au1xxx_ide.h
@@ -74,7 +74,6 @@ typedef struct
74 struct dbdma_cmd *dma_table_cpu; 74 struct dbdma_cmd *dma_table_cpu;
75 dma_addr_t dma_table_dma; 75 dma_addr_t dma_table_dma;
76#endif 76#endif
77 struct device *dev;
78 int irq; 77 int irq;
79 u32 regbase; 78 u32 regbase;
80#ifdef CONFIG_PM 79#ifdef CONFIG_PM
diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
index fcdc11b9609..a5cd2047624 100644
--- a/include/linux/cdrom.h
+++ b/include/linux/cdrom.h
@@ -1187,6 +1187,20 @@ struct media_event_desc {
1187 1187
1188extern int cdrom_get_media_event(struct cdrom_device_info *cdi, struct media_event_desc *med); 1188extern int cdrom_get_media_event(struct cdrom_device_info *cdi, struct media_event_desc *med);
1189 1189
1190static inline void lba_to_msf(int lba, u8 *m, u8 *s, u8 *f)
1191{
1192 lba += CD_MSF_OFFSET;
1193 lba &= 0xffffff; /* negative lbas use only 24 bits */
1194 *m = lba / (CD_SECS * CD_FRAMES);
1195 lba %= (CD_SECS * CD_FRAMES);
1196 *s = lba / CD_FRAMES;
1197 *f = lba % CD_FRAMES;
1198}
1199
1200static inline int msf_to_lba(u8 m, u8 s, u8 f)
1201{
1202 return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
1203}
1190#endif /* End of kernel only stuff */ 1204#endif /* End of kernel only stuff */
1191 1205
1192#endif /* _LINUX_CDROM_H */ 1206#endif /* _LINUX_CDROM_H */
diff --git a/include/linux/hdsmart.h b/include/linux/hdsmart.h
index 7974a47fe58..e69192159d4 100644
--- a/include/linux/hdsmart.h
+++ b/include/linux/hdsmart.h
@@ -17,6 +17,7 @@
17#ifndef _LINUX_HDSMART_H 17#ifndef _LINUX_HDSMART_H
18#define _LINUX_HDSMART_H 18#define _LINUX_HDSMART_H
19 19
20#ifndef __KERNEL
20#define OFFLINE_FULL_SCAN 0 21#define OFFLINE_FULL_SCAN 0
21#define SHORT_SELF_TEST 1 22#define SHORT_SELF_TEST 1
22#define EXTEND_SELF_TEST 2 23#define EXTEND_SELF_TEST 2
@@ -120,5 +121,6 @@ typedef struct ata_smart_selftestlog_s {
120 unsigned char resevered[2]; 121 unsigned char resevered[2];
121 unsigned char chksum; 122 unsigned char chksum;
122} __attribute__ ((packed)) ata_smart_selftestlog_t; 123} __attribute__ ((packed)) ata_smart_selftestlog_t;
124#endif /* __KERNEL__ *
123 125
124#endif /* _LINUX_HDSMART_H */ 126#endif /* _LINUX_HDSMART_H */
diff --git a/include/linux/ide.h b/include/linux/ide.h
index 27cb39de2ae..ec10b2a3bb6 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -9,7 +9,6 @@
9#include <linux/init.h> 9#include <linux/init.h>
10#include <linux/ioport.h> 10#include <linux/ioport.h>
11#include <linux/hdreg.h> 11#include <linux/hdreg.h>
12#include <linux/hdsmart.h>
13#include <linux/blkdev.h> 12#include <linux/blkdev.h>
14#include <linux/proc_fs.h> 13#include <linux/proc_fs.h>
15#include <linux/interrupt.h> 14#include <linux/interrupt.h>
@@ -503,7 +502,8 @@ typedef struct hwif_s {
503 502
504 hwif_chipset_t chipset; /* sub-module for tuning.. */ 503 hwif_chipset_t chipset; /* sub-module for tuning.. */
505 504
506 struct pci_dev *pci_dev; /* for pci chipsets */ 505 struct device *dev;
506
507 const struct ide_port_info *cds; /* chipset device struct */ 507 const struct ide_port_info *cds; /* chipset device struct */
508 508
509 ide_ack_intr_t *ack_intr; 509 ide_ack_intr_t *ack_intr;
@@ -628,8 +628,7 @@ typedef int (ide_expiry_t)(ide_drive_t *);
628typedef struct hwgroup_s { 628typedef struct hwgroup_s {
629 /* irq handler, if active */ 629 /* irq handler, if active */
630 ide_startstop_t (*handler)(ide_drive_t *); 630 ide_startstop_t (*handler)(ide_drive_t *);
631 /* irq handler, suspended if active */ 631
632 ide_startstop_t (*handler_save)(ide_drive_t *);
633 /* BOOL: protects all fields below */ 632 /* BOOL: protects all fields below */
634 volatile int busy; 633 volatile int busy;
635 /* BOOL: wake us up on timer expiry */ 634 /* BOOL: wake us up on timer expiry */
@@ -644,25 +643,18 @@ typedef struct hwgroup_s {
644 /* ptr to current hwif in linked-list */ 643 /* ptr to current hwif in linked-list */
645 ide_hwif_t *hwif; 644 ide_hwif_t *hwif;
646 645
647 /* for pci chipsets */
648 struct pci_dev *pci_dev;
649
650 /* current request */ 646 /* current request */
651 struct request *rq; 647 struct request *rq;
648
652 /* failsafe timer */ 649 /* failsafe timer */
653 struct timer_list timer; 650 struct timer_list timer;
654 /* local copy of current write rq */
655 struct request wrq;
656 /* timeout value during long polls */ 651 /* timeout value during long polls */
657 unsigned long poll_timeout; 652 unsigned long poll_timeout;
658 /* queried upon timeouts */ 653 /* queried upon timeouts */
659 int (*expiry)(ide_drive_t *); 654 int (*expiry)(ide_drive_t *);
660 /* ide_system_bus_speed */ 655
661 int pio_clock;
662 int req_gen; 656 int req_gen;
663 int req_gen_timer; 657 int req_gen_timer;
664
665 unsigned char cmd_buf[4];
666} ide_hwgroup_t; 658} ide_hwgroup_t;
667 659
668typedef struct ide_driver_s ide_driver_t; 660typedef struct ide_driver_s ide_driver_t;
@@ -986,8 +978,6 @@ ide_startstop_t do_rw_taskfile(ide_drive_t *, ide_task_t *);
986 978
987void task_end_request(ide_drive_t *, struct request *, u8); 979void task_end_request(ide_drive_t *, struct request *, u8);
988 980
989u8 wait_drive_not_busy(ide_drive_t *);
990
991int ide_raw_taskfile(ide_drive_t *, ide_task_t *, u8 *, u16); 981int ide_raw_taskfile(ide_drive_t *, ide_task_t *, u8 *, u16);
992int ide_no_data_taskfile(ide_drive_t *, ide_task_t *); 982int ide_no_data_taskfile(ide_drive_t *, ide_task_t *);
993 983
@@ -1017,7 +1007,6 @@ void ide_init_disk(struct gendisk *, ide_drive_t *);
1017 1007
1018#ifdef CONFIG_IDEPCI_PCIBUS_ORDER 1008#ifdef CONFIG_IDEPCI_PCIBUS_ORDER
1019extern int ide_scan_direction; 1009extern int ide_scan_direction;
1020int __init ide_scan_pcibus(void);
1021extern int __ide_pci_register_driver(struct pci_driver *driver, struct module *owner, const char *mod_name); 1010extern int __ide_pci_register_driver(struct pci_driver *driver, struct module *owner, const char *mod_name);
1022#define ide_pci_register_driver(d) __ide_pci_register_driver(d, THIS_MODULE, KBUILD_MODNAME) 1011#define ide_pci_register_driver(d) __ide_pci_register_driver(d, THIS_MODULE, KBUILD_MODNAME)
1023#else 1012#else
@@ -1096,6 +1085,10 @@ enum {
1096 IDE_HFLAG_ABUSE_SET_DMA_MODE = (1 << 26), 1085 IDE_HFLAG_ABUSE_SET_DMA_MODE = (1 << 26),
1097 /* host is CY82C693 */ 1086 /* host is CY82C693 */
1098 IDE_HFLAG_CY82C693 = (1 << 27), 1087 IDE_HFLAG_CY82C693 = (1 << 27),
1088 /* force host out of "simplex" mode */
1089 IDE_HFLAG_CLEAR_SIMPLEX = (1 << 28),
1090 /* DSC overlap is unsupported */
1091 IDE_HFLAG_NO_DSC = (1 << 29),
1099}; 1092};
1100 1093
1101#ifdef CONFIG_BLK_DEV_OFFBOARD 1094#ifdef CONFIG_BLK_DEV_OFFBOARD
@@ -1153,12 +1146,13 @@ void ide_dma_on(ide_drive_t *);
1153int ide_set_dma(ide_drive_t *); 1146int ide_set_dma(ide_drive_t *);
1154ide_startstop_t ide_dma_intr(ide_drive_t *); 1147ide_startstop_t ide_dma_intr(ide_drive_t *);
1155 1148
1149int ide_build_sglist(ide_drive_t *, struct request *);
1150void ide_destroy_dmatable(ide_drive_t *);
1151
1156#ifdef CONFIG_BLK_DEV_IDEDMA_PCI 1152#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
1157extern int ide_build_sglist(ide_drive_t *, struct request *);
1158extern int ide_build_dmatable(ide_drive_t *, struct request *); 1153extern int ide_build_dmatable(ide_drive_t *, struct request *);
1159extern void ide_destroy_dmatable(ide_drive_t *);
1160extern int ide_release_dma(ide_hwif_t *); 1154extern int ide_release_dma(ide_hwif_t *);
1161extern void ide_setup_dma(ide_hwif_t *, unsigned long, unsigned int); 1155extern void ide_setup_dma(ide_hwif_t *, unsigned long);
1162 1156
1163void ide_dma_host_set(ide_drive_t *, int); 1157void ide_dma_host_set(ide_drive_t *, int);
1164extern int ide_dma_setup(ide_drive_t *); 1158extern int ide_dma_setup(ide_drive_t *);
@@ -1197,6 +1191,7 @@ static inline void ide_acpi_init(ide_hwif_t *hwif) { ; }
1197static inline void ide_acpi_set_state(ide_hwif_t *hwif, int on) {} 1191static inline void ide_acpi_set_state(ide_hwif_t *hwif, int on) {}
1198#endif 1192#endif
1199 1193
1194void ide_remove_port_from_hwgroup(ide_hwif_t *);
1200extern int ide_hwif_request_regions(ide_hwif_t *hwif); 1195extern int ide_hwif_request_regions(ide_hwif_t *hwif);
1201extern void ide_hwif_release_regions(ide_hwif_t* hwif); 1196extern void ide_hwif_release_regions(ide_hwif_t* hwif);
1202extern void ide_unregister (unsigned int index); 1197extern void ide_unregister (unsigned int index);
@@ -1291,9 +1286,14 @@ extern struct bus_type ide_bus_type;
1291#define ide_id_has_flush_cache_ext(id) \ 1286#define ide_id_has_flush_cache_ext(id) \
1292 (((id)->cfs_enable_2 & 0x2400) == 0x2400) 1287 (((id)->cfs_enable_2 & 0x2400) == 0x2400)
1293 1288
1289static inline void ide_dump_identify(u8 *id)
1290{
1291 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 2, id, 512, 0);
1292}
1293
1294static inline int hwif_to_node(ide_hwif_t *hwif) 1294static inline int hwif_to_node(ide_hwif_t *hwif)
1295{ 1295{
1296 struct pci_dev *dev = hwif->pci_dev; 1296 struct pci_dev *dev = to_pci_dev(hwif->dev);
1297 return dev ? pcibus_to_node(dev->bus) : -1; 1297 return dev ? pcibus_to_node(dev->bus) : -1;
1298} 1298}
1299 1299