1 /**** vi:set ts=8 sts=8 sw=8:************************************************
3 * Copyright (C) 2002 Marcin Dalecki <martin@dalecki.de>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * Code common among all the ATAPI device drivers.
18 * Ideally this should evolve in to a unified driver.
21 #include <linux/module.h>
22 #include <linux/types.h>
23 #include <linux/string.h>
24 #include <linux/kernel.h>
26 #include <linux/ioport.h>
27 #include <linux/blkdev.h>
28 #include <linux/errno.h>
29 #include <linux/slab.h>
30 #include <linux/completion.h>
31 #include <linux/cdrom.h>
32 #include <linux/hdreg.h>
33 #include <linux/ide.h>
34 #include <linux/atapi.h>
36 #include <asm/byteorder.h>
38 #include <asm/bitops.h>
39 #include <asm/uaccess.h>
42 * Initializes a packet command. Used by tape and floppy driver.
44 void atapi_init_pc(struct atapi_packet_command
*pc
)
49 pc
->request_transfer
= 0;
50 pc
->buffer
= pc
->pc_buffer
;
51 pc
->buffer_size
= IDEFLOPPY_PC_BUFFER_SIZE
;
57 * Too bad. The drive wants to send us data which we are not ready to accept.
60 void atapi_discard_data(struct ata_device
*drive
, unsigned int bcount
)
63 IN_BYTE(IDE_DATA_REG
);
66 void atapi_write_zeros(struct ata_device
*drive
, unsigned int bcount
)
69 OUT_BYTE(0, IDE_DATA_REG
);
73 * The following routines are mainly used by the ATAPI drivers.
75 * These routines will round up any request for an odd number of bytes, so if
76 * an odd n is specified, be sure that there's at least one extra byte
77 * allocated for the buffer.
79 void atapi_read(struct ata_device
*drive
, u8
*buf
, unsigned int n
)
81 if (drive
->channel
->atapi_read
) {
82 drive
->channel
->atapi_read(drive
, buf
, n
);
87 #if defined(CONFIG_ATARI) || defined(CONFIG_Q40)
88 if (MACH_IS_ATARI
|| MACH_IS_Q40
) {
89 /* Atari has a byte-swapped IDE interface */
90 insw_swapw(IDE_DATA_REG
, buf
, n
/ 2);
94 ata_read(drive
, buf
, n
/ 4);
96 insw(IDE_DATA_REG
, buf
+ (n
& ~0x03), 1);
99 void atapi_write(struct ata_device
*drive
, u8
*buf
, unsigned int n
)
101 if (drive
->channel
->atapi_write
) {
102 drive
->channel
->atapi_write(drive
, buf
, n
);
107 #if defined(CONFIG_ATARI) || defined(CONFIG_Q40)
108 if (MACH_IS_ATARI
|| MACH_IS_Q40
) {
109 /* Atari has a byte-swapped IDE interface */
110 outsw_swapw(IDE_DATA_REG
, buf
, n
/ 2);
114 ata_write(drive
, buf
, n
/ 4);
116 outsw(IDE_DATA_REG
, buf
+ (n
& ~0x03), 1);
121 * This function issues a special IDE device request onto the request queue.
123 * If action is ide_wait, then the rq is queued at the end of the request
124 * queue, and the function sleeps until it has been processed. This is for use
125 * when invoked from an ioctl handler.
127 * If action is ide_preempt, then the rq is queued at the head of the request
128 * queue, displacing the currently-being-processed request and this function
129 * returns immediately without waiting for the new rq to be completed. This is
130 * VERY DANGEROUS, and is intended for careful use by the ATAPI tape/cdrom
133 * If action is ide_end, then the rq is queued at the end of the request queue,
134 * and the function returns immediately without waiting for the new rq to be
135 * completed. This is again intended for careful use by the ATAPI tape/cdrom
138 int ide_do_drive_cmd(struct ata_device
*drive
, struct request
*rq
, ide_action_t action
)
141 struct ata_channel
*ch
= drive
->channel
;
142 unsigned int major
= ch
->major
;
143 request_queue_t
*q
= &drive
->queue
;
144 struct list_head
*queue_head
= &q
->queue_head
;
145 DECLARE_COMPLETION(wait
);
147 #ifdef CONFIG_BLK_DEV_PDC4030
148 if (ch
->chipset
== ide_pdc4030
&& rq
->buffer
)
149 return -ENOSYS
; /* special drive cmds not supported */
152 rq
->rq_status
= RQ_ACTIVE
;
153 rq
->rq_dev
= mk_kdev(major
, (drive
->select
.b
.unit
) << PARTN_BITS
);
154 if (action
== ide_wait
)
157 spin_lock_irqsave(ch
->lock
, flags
);
159 if (action
== ide_preempt
)
161 else if (!blk_queue_empty(&drive
->queue
))
162 queue_head
= queue_head
->prev
; /* ide_end and ide_wait */
164 __elv_add_request(q
, rq
, queue_head
);
168 spin_unlock_irqrestore(ch
->lock
, flags
);
170 if (action
== ide_wait
) {
171 wait_for_completion(&wait
); /* wait for it to be serviced */
172 return rq
->errors
? -EIO
: 0; /* return -EIO if errors */
178 EXPORT_SYMBOL(ide_do_drive_cmd
);
179 EXPORT_SYMBOL(atapi_discard_data
);
180 EXPORT_SYMBOL(atapi_write_zeros
);
181 EXPORT_SYMBOL(atapi_init_pc
);
183 EXPORT_SYMBOL(atapi_read
);
184 EXPORT_SYMBOL(atapi_write
);
186 MODULE_LICENSE("GPL");