19 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/string.h>
22 #include <linux/kernel.h>
27 #include <linux/errno.h>
29 #include <linux/slab.h>
34 #include <linux/pci.h>
37 #include <asm/byteorder.h>
39 #include <asm/uaccess.h>
72 if (ata_id_current_chs_valid(
id)) {
86 static void ide_disk_init_mult_count(
ide_drive_t *drive)
92 if ((max_multsect / 2) > 1)
104 static void ide_classify_ata_dev(
ide_drive_t *drive)
108 int is_cfa = ata_id_is_cfa(
id);
116 if (!ata_id_has_unload(drive->
id))
120 is_cfa ?
"CFA" :
"ATA");
123 static void ide_classify_atapi_dev(
ide_drive_t *drive)
132 if (!
strstr(m,
"CD-ROM")) {
207 ide_dump_identify((
u8 *)
id);
216 if ((m[0] ==
'N' && m[1] ==
'E') ||
217 (m[0] ==
'F' && m[1] ==
'X') ||
218 (m[0] ==
'P' && m[1] ==
'i'))
230 if (
strstr(m,
"E X A B Y T E N E S T"))
255 int use_altstatus = 0,
rc;
279 "instead of ALTSTATUS(0x%02x)\n",
292 memset(&tf, 0,
sizeof(tf));
318 do_identify(drive, cmd,
id);
339 stat = altstatus ? hwif->
tp_ops->read_altstatus(hwif)
340 : hwif->
tp_ops->read_status(hwif);
393 printk(
KERN_INFO "probing for %s: present=%d, media=%d, probetype=%s\n",
405 if (ide_read_device(drive) != drive->
select && present == 0) {
432 "resetting drive\n", drive->
name,
stat);
488 rc = do_probe(drive, cmd);
492 rc = do_probe(drive, cmd);
513 ide_classify_atapi_dev(drive);
515 ide_classify_ata_dev(drive);
529 ide_disk_init_chs(drive);
530 ide_disk_init_mult_count(drive);
536 static void hwif_release_dev(
struct device *
dev)
543 static int ide_register_port(
ide_hwif_t *hwif)
552 hwif->
gendev.release = hwif_release_dev;
597 static int ide_port_wait_ready(
ide_hwif_t *hwif)
698 if (ide_port_wait_ready(hwif) == -
EBUSY)
706 (
void) probe_for_drive(drive);
721 static void ide_port_tune_devices(
ide_hwif_t *hwif)
735 ide_set_max_pio(drive);
751 int max_sectors = 256;
766 q->queuedata = drive;
769 if (hwif->
rqsize < max_sectors)
770 max_sectors = hwif->
rqsize;
784 max_sg_entries >>= 1;
804 static int ide_port_setup_devices(
ide_hwif_t *hwif)
811 if (ide_init_queue(drive)) {
835 hwif->
tp_ops->read_status(hwif);
853 if (irq_handler ==
NULL)
859 #if !defined(__mc68000__)
892 request_module(
"ide-disk");
894 request_module(
"ide-cd");
896 request_module(
"ide-tape");
898 request_module(
"ide-floppy");
903 static struct kobject *exact_match(
dev_t dev,
int *part,
void *data)
905 struct gendisk *
p =
data;
907 return &disk_to_dev(p)->kobj;
910 static int exact_lock(
dev_t dev,
void *data)
912 struct gendisk *
p =
data;
922 disk->minors,
NULL, exact_match, exact_lock, disk);
938 unsigned int unit = drive->
dn & 1;
940 disk->major = hwif->
major;
943 disk->queue = drive->
queue;
948 static void drive_release_dev (
struct device *dev)
999 static void hwif_register_devices(
ide_hwif_t *hwif)
1012 dev->
release = drive_release_dev;
1017 "%d\n", __func__, ret);
1021 static void ide_port_init_devices(
ide_hwif_t *hwif)
1041 if (port_ops && port_ops->
init_dev)
1079 rc = ide_hwif_setup_dma(hwif, d);
1111 static void ide_port_cable_detect(
ide_hwif_t *hwif)
1121 static const u8 ide_hwif_to_major[] =
1125 static void ide_port_init_devices_data(
ide_hwif_t *hwif)
1132 u16 *saved_id = drive->
id;
1134 memset(drive, 0,
sizeof(*drive));
1136 drive->
id = saved_id;
1145 drive->
name[0] =
'h';
1146 drive->
name[1] =
'd';
1147 drive->
name[2] =
'a' +
j;
1150 INIT_LIST_HEAD(&drive->
list);
1161 hwif->
name[0] =
'i';
1162 hwif->
name[1] =
'd';
1163 hwif->
name[2] =
'e';
1176 ide_port_init_devices_data(hwif);
1188 static unsigned int ide_indexes;
1197 static int ide_find_port_slot(
const struct ide_port_info *d)
1215 if ((ide_indexes | i) != (1 <<
MAX_HWIFS) - 1)
1216 idx =
ffz(ide_indexes | i);
1218 if ((ide_indexes | 3) != (1 <<
MAX_HWIFS) - 1)
1219 idx =
ffz(ide_indexes | 3);
1220 else if ((ide_indexes & 3) != 3)
1221 idx =
ffz(ide_indexes);
1224 ide_indexes |= (1 <<
idx);
1230 static void ide_free_port_slot(
int idx)
1233 ide_indexes &= ~(1 <<
idx);
1237 static void ide_port_free_devices(
ide_hwif_t *hwif)
1255 drive = kzalloc_node(
sizeof(*drive),
GFP_KERNEL, node);
1276 ide_port_free_devices(hwif);
1285 int node = dev ? dev_to_node(dev) : -1;
1288 host = kzalloc_node(
sizeof(*host),
GFP_KERNEL, node);
1292 for (i = 0; i < n_ports; i++) {
1299 hwif = kzalloc_node(
sizeof(*hwif),
GFP_KERNEL, node);
1303 if (ide_port_alloc_devices(hwif, node) < 0) {
1308 idx = ide_find_port_slot(d);
1311 d ? d->
name :
"ide");
1312 ide_port_free_devices(hwif);
1317 ide_init_port_data(hwif, idx);
1346 ide_port_free_devices(hwif);
1347 ide_free_port_slot(hwif->
index);
1351 static void ide_disable_port(
ide_hwif_t *hwif)
1359 if (host->
ports[i] == hwif) {
1365 ide_port_free(hwif);
1380 ide_init_port_hw(hwif, hws[i]);
1383 if ((i & 1) && mate) {
1388 mate = (i & 1) ?
NULL : hwif;
1390 ide_init_port(hwif, i & 1, d);
1391 ide_port_cable_detect(hwif);
1395 ide_port_init_devices(hwif);
1402 if (ide_probe_port(hwif) == 0)
1409 if (ide_register_port(hwif)) {
1410 ide_disable_port(hwif);
1416 ide_port_tune_devices(hwif);
1419 ide_host_enable_irqs(host);
1425 if (hwif_init(hwif) == 0) {
1427 "interface\n", hwif->
name);
1429 ide_disable_port(hwif);
1434 if (ide_port_setup_devices(hwif) == 0) {
1456 hwif_register_devices(hwif);
1487 static void __ide_port_unregister_devices(
ide_hwif_t *hwif)
1501 __ide_port_unregister_devices(hwif);
1503 ide_port_init_devices_data(hwif);
1530 __ide_port_unregister_devices(hwif);
1561 ide_port_free(hwif);
1575 ide_unregister(hwif);
1587 ide_port_cable_detect(hwif);
1591 ide_port_init_devices(hwif);
1593 rc = ide_probe_port(hwif);
1602 ide_port_tune_devices(hwif);
1603 ide_port_setup_devices(hwif);
1605 hwif_register_devices(hwif);