aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-probe.c
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2009-01-06 11:20:56 -0500
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2009-01-06 11:20:56 -0500
commit5e7f3a46690f7f6c9f2781c700ab4370874aa0e8 (patch)
treebe5a50962416bbbc323c24d997ceb3472e3d44b9 /drivers/ide/ide-probe.c
parenta32296f93821497d794ab8e1312d677717479777 (diff)
ide: dynamic allocation of device structures
Allocate device structures dynamically instead of having them embedded in ide_hwif_t: * Remove needless zeroing of port structure from ide_init_port_data(). * Add ide_hwif_t.devices[MAX_DRIVES] (table of pointers to the devices). * Add ide_port_{alloc,free}_devices() helpers and use them respectively in ide_{host,free}_alloc(). * Convert all users of ->drives[] to use ->devices[] instead. While at it: * Use drive->dn for the slave device check in scc_pata.c. As a nice side-effect this patch cuts ~1kB (x86-32) from the resulting code size: text data bss dec hex filename 53963 1244 237 55444 d894 drivers/ide/ide-core.o.before 52981 1244 237 54462 d4be drivers/ide/ide-core.o.after Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/ide-probe.c')
-rw-r--r--drivers/ide/ide-probe.c71
1 files changed, 51 insertions, 20 deletions
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 00c7e5a67bd1..006e601cafb8 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -463,7 +463,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
463 if (ide_read_device(drive) != drive->select && present == 0) { 463 if (ide_read_device(drive) != drive->select && present == 0) {
464 if (drive->dn & 1) { 464 if (drive->dn & 1) {
465 /* exit with drive0 selected */ 465 /* exit with drive0 selected */
466 SELECT_DRIVE(&hwif->drives[0]); 466 SELECT_DRIVE(hwif->devices[0]);
467 /* allow ATA_BUSY to assert & clear */ 467 /* allow ATA_BUSY to assert & clear */
468 msleep(50); 468 msleep(50);
469 } 469 }
@@ -509,7 +509,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
509 } 509 }
510 if (drive->dn & 1) { 510 if (drive->dn & 1) {
511 /* exit with drive0 selected */ 511 /* exit with drive0 selected */
512 SELECT_DRIVE(&hwif->drives[0]); 512 SELECT_DRIVE(hwif->devices[0]);
513 msleep(50); 513 msleep(50);
514 /* ensure drive irq is clear */ 514 /* ensure drive irq is clear */
515 (void)tp_ops->read_status(hwif); 515 (void)tp_ops->read_status(hwif);
@@ -715,7 +715,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
715 715
716 /* Now make sure both master & slave are ready */ 716 /* Now make sure both master & slave are ready */
717 for (unit = 0; unit < MAX_DRIVES; unit++) { 717 for (unit = 0; unit < MAX_DRIVES; unit++) {
718 ide_drive_t *drive = &hwif->drives[unit]; 718 ide_drive_t *drive = hwif->devices[unit];
719 719
720 /* Ignore disks that we will not probe for later. */ 720 /* Ignore disks that we will not probe for later. */
721 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 || 721 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 ||
@@ -733,7 +733,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
733out: 733out:
734 /* Exit function with master reselected (let's be sane) */ 734 /* Exit function with master reselected (let's be sane) */
735 if (unit) 735 if (unit)
736 SELECT_DRIVE(&hwif->drives[0]); 736 SELECT_DRIVE(hwif->devices[0]);
737 737
738 return rc; 738 return rc;
739} 739}
@@ -749,7 +749,7 @@ out:
749 749
750void ide_undecoded_slave(ide_drive_t *dev1) 750void ide_undecoded_slave(ide_drive_t *dev1)
751{ 751{
752 ide_drive_t *dev0 = &dev1->hwif->drives[0]; 752 ide_drive_t *dev0 = dev1->hwif->devices[0];
753 753
754 if ((dev1->dn & 1) == 0 || (dev0->dev_flags & IDE_DFLAG_PRESENT) == 0) 754 if ((dev1->dn & 1) == 0 || (dev0->dev_flags & IDE_DFLAG_PRESENT) == 0)
755 return; 755 return;
@@ -784,8 +784,8 @@ static int ide_probe_port(ide_hwif_t *hwif)
784 784
785 BUG_ON(hwif->present); 785 BUG_ON(hwif->present);
786 786
787 if ((hwif->drives[0].dev_flags & IDE_DFLAG_NOPROBE) && 787 if ((hwif->devices[0]->dev_flags & IDE_DFLAG_NOPROBE) &&
788 (hwif->drives[1].dev_flags & IDE_DFLAG_NOPROBE)) 788 (hwif->devices[1]->dev_flags & IDE_DFLAG_NOPROBE))
789 return -EACCES; 789 return -EACCES;
790 790
791 /* 791 /*
@@ -807,7 +807,7 @@ static int ide_probe_port(ide_hwif_t *hwif)
807 * but a lot of cdrom drives are configured as single slaves. 807 * but a lot of cdrom drives are configured as single slaves.
808 */ 808 */
809 for (unit = 0; unit < MAX_DRIVES; ++unit) { 809 for (unit = 0; unit < MAX_DRIVES; ++unit) {
810 ide_drive_t *drive = &hwif->drives[unit]; 810 ide_drive_t *drive = hwif->devices[unit];
811 811
812 (void) probe_for_drive(drive); 812 (void) probe_for_drive(drive);
813 if (drive->dev_flags & IDE_DFLAG_PRESENT) 813 if (drive->dev_flags & IDE_DFLAG_PRESENT)
@@ -832,7 +832,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
832 int unit; 832 int unit;
833 833
834 for (unit = 0; unit < MAX_DRIVES; unit++) { 834 for (unit = 0; unit < MAX_DRIVES; unit++) {
835 ide_drive_t *drive = &hwif->drives[unit]; 835 ide_drive_t *drive = hwif->devices[unit];
836 836
837 if (drive->dev_flags & IDE_DFLAG_PRESENT) { 837 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
838 if (port_ops && port_ops->quirkproc) 838 if (port_ops && port_ops->quirkproc)
@@ -841,7 +841,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
841 } 841 }
842 842
843 for (unit = 0; unit < MAX_DRIVES; ++unit) { 843 for (unit = 0; unit < MAX_DRIVES; ++unit) {
844 ide_drive_t *drive = &hwif->drives[unit]; 844 ide_drive_t *drive = hwif->devices[unit];
845 845
846 if (drive->dev_flags & IDE_DFLAG_PRESENT) { 846 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
847 ide_set_max_pio(drive); 847 ide_set_max_pio(drive);
@@ -854,7 +854,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
854 } 854 }
855 855
856 for (unit = 0; unit < MAX_DRIVES; ++unit) { 856 for (unit = 0; unit < MAX_DRIVES; ++unit) {
857 ide_drive_t *drive = &hwif->drives[unit]; 857 ide_drive_t *drive = hwif->devices[unit];
858 858
859 if ((hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) || 859 if ((hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) ||
860 drive->id[ATA_ID_DWORD_IO]) 860 drive->id[ATA_ID_DWORD_IO])
@@ -931,7 +931,7 @@ static int ide_port_setup_devices(ide_hwif_t *hwif)
931 931
932 mutex_lock(&ide_cfg_mtx); 932 mutex_lock(&ide_cfg_mtx);
933 for (i = 0; i < MAX_DRIVES; i++) { 933 for (i = 0; i < MAX_DRIVES; i++) {
934 ide_drive_t *drive = &hwif->drives[i]; 934 ide_drive_t *drive = hwif->devices[i];
935 935
936 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) 936 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
937 continue; 937 continue;
@@ -1017,7 +1017,7 @@ static struct kobject *ata_probe(dev_t dev, int *part, void *data)
1017{ 1017{
1018 ide_hwif_t *hwif = data; 1018 ide_hwif_t *hwif = data;
1019 int unit = *part >> PARTN_BITS; 1019 int unit = *part >> PARTN_BITS;
1020 ide_drive_t *drive = &hwif->drives[unit]; 1020 ide_drive_t *drive = hwif->devices[unit];
1021 1021
1022 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) 1022 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
1023 return NULL; 1023 return NULL;
@@ -1164,7 +1164,7 @@ static void hwif_register_devices(ide_hwif_t *hwif)
1164 unsigned int i; 1164 unsigned int i;
1165 1165
1166 for (i = 0; i < MAX_DRIVES; i++) { 1166 for (i = 0; i < MAX_DRIVES; i++) {
1167 ide_drive_t *drive = &hwif->drives[i]; 1167 ide_drive_t *drive = hwif->devices[i];
1168 struct device *dev = &drive->gendev; 1168 struct device *dev = &drive->gendev;
1169 int ret; 1169 int ret;
1170 1170
@@ -1190,7 +1190,7 @@ static void ide_port_init_devices(ide_hwif_t *hwif)
1190 int i; 1190 int i;
1191 1191
1192 for (i = 0; i < MAX_DRIVES; i++) { 1192 for (i = 0; i < MAX_DRIVES; i++) {
1193 ide_drive_t *drive = &hwif->drives[i]; 1193 ide_drive_t *drive = hwif->devices[i];
1194 1194
1195 drive->dn = i + hwif->channel * 2; 1195 drive->dn = i + hwif->channel * 2;
1196 1196
@@ -1285,7 +1285,7 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
1285 int unit; 1285 int unit;
1286 1286
1287 for (unit = 0; unit < MAX_DRIVES; ++unit) { 1287 for (unit = 0; unit < MAX_DRIVES; ++unit) {
1288 ide_drive_t *drive = &hwif->drives[unit]; 1288 ide_drive_t *drive = hwif->devices[unit];
1289 u8 j = (hwif->index * MAX_DRIVES) + unit; 1289 u8 j = (hwif->index * MAX_DRIVES) + unit;
1290 1290
1291 memset(drive, 0, sizeof(*drive)); 1291 memset(drive, 0, sizeof(*drive));
@@ -1309,9 +1309,6 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
1309 1309
1310static void ide_init_port_data(ide_hwif_t *hwif, unsigned int index) 1310static void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
1311{ 1311{
1312 /* bulk initialize hwif & drive info with zeros */
1313 memset(hwif, 0, sizeof(ide_hwif_t));
1314
1315 /* fill in any non-zero initial values */ 1312 /* fill in any non-zero initial values */
1316 hwif->index = index; 1313 hwif->index = index;
1317 hwif->major = ide_hwif_to_major[index]; 1314 hwif->major = ide_hwif_to_major[index];
@@ -1388,6 +1385,34 @@ static void ide_free_port_slot(int idx)
1388 mutex_unlock(&ide_cfg_mtx); 1385 mutex_unlock(&ide_cfg_mtx);
1389} 1386}
1390 1387
1388static void ide_port_free_devices(ide_hwif_t *hwif)
1389{
1390 int i;
1391
1392 for (i = 0; i < MAX_DRIVES; i++)
1393 kfree(hwif->devices[i]);
1394}
1395
1396static int ide_port_alloc_devices(ide_hwif_t *hwif, int node)
1397{
1398 int i;
1399
1400 for (i = 0; i < MAX_DRIVES; i++) {
1401 ide_drive_t *drive;
1402
1403 drive = kzalloc_node(sizeof(*drive), GFP_KERNEL, node);
1404 if (drive == NULL)
1405 goto out_nomem;
1406
1407 hwif->devices[i] = drive;
1408 }
1409 return 0;
1410
1411out_nomem:
1412 ide_port_free_devices(hwif);
1413 return -ENOMEM;
1414}
1415
1391struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws) 1416struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1392{ 1417{
1393 struct ide_host *host; 1418 struct ide_host *host;
@@ -1410,6 +1435,11 @@ struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1410 if (hwif == NULL) 1435 if (hwif == NULL)
1411 continue; 1436 continue;
1412 1437
1438 if (ide_port_alloc_devices(hwif, node) < 0) {
1439 kfree(hwif);
1440 continue;
1441 }
1442
1413 idx = ide_find_port_slot(d); 1443 idx = ide_find_port_slot(d);
1414 if (idx < 0) { 1444 if (idx < 0) {
1415 printk(KERN_ERR "%s: no free slot for interface\n", 1445 printk(KERN_ERR "%s: no free slot for interface\n",
@@ -1575,7 +1605,7 @@ static void __ide_port_unregister_devices(ide_hwif_t *hwif)
1575 int i; 1605 int i;
1576 1606
1577 for (i = 0; i < MAX_DRIVES; i++) { 1607 for (i = 0; i < MAX_DRIVES; i++) {
1578 ide_drive_t *drive = &hwif->drives[i]; 1608 ide_drive_t *drive = hwif->devices[i];
1579 1609
1580 if (drive->dev_flags & IDE_DFLAG_PRESENT) { 1610 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
1581 device_unregister(&drive->gendev); 1611 device_unregister(&drive->gendev);
@@ -1651,6 +1681,7 @@ void ide_host_free(struct ide_host *host)
1651 if (hwif == NULL) 1681 if (hwif == NULL)
1652 continue; 1682 continue;
1653 1683
1684 ide_port_free_devices(hwif);
1654 ide_free_port_slot(hwif->index); 1685 ide_free_port_slot(hwif->index);
1655 kfree(hwif); 1686 kfree(hwif);
1656 } 1687 }