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: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
parent a32296f9
...@@ -656,7 +656,7 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on) ...@@ -656,7 +656,7 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on)
if (on) if (on)
acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0); acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0);
for (unit = 0; unit < MAX_DRIVES; ++unit) { for (unit = 0; unit < MAX_DRIVES; ++unit) {
ide_drive_t *drive = &hwif->drives[unit]; ide_drive_t *drive = hwif->devices[unit];
if (!drive->acpidata->obj_handle) if (!drive->acpidata->obj_handle)
drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive); drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
...@@ -711,14 +711,14 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif) ...@@ -711,14 +711,14 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
* for both drives, regardless whether they are connected * for both drives, regardless whether they are connected
* or not. * or not.
*/ */
hwif->drives[0].acpidata = &hwif->acpidata->master; hwif->devices[0]->acpidata = &hwif->acpidata->master;
hwif->drives[1].acpidata = &hwif->acpidata->slave; hwif->devices[1]->acpidata = &hwif->acpidata->slave;
/* /*
* Send IDENTIFY for each drive * Send IDENTIFY for each drive
*/ */
for (i = 0; i < MAX_DRIVES; i++) { for (i = 0; i < MAX_DRIVES; i++) {
drive = &hwif->drives[i]; drive = hwif->devices[i];
memset(drive->acpidata, 0, sizeof(*drive->acpidata)); memset(drive->acpidata, 0, sizeof(*drive->acpidata));
...@@ -745,7 +745,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif) ...@@ -745,7 +745,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
ide_acpi_push_timing(hwif); ide_acpi_push_timing(hwif);
for (i = 0; i < MAX_DRIVES; i++) { for (i = 0; i < MAX_DRIVES; i++) {
drive = &hwif->drives[i]; drive = hwif->devices[i];
if (drive->dev_flags & IDE_DFLAG_PRESENT) if (drive->dev_flags & IDE_DFLAG_PRESENT)
/* Execute ACPI startup code */ /* Execute ACPI startup code */
......
...@@ -1111,7 +1111,7 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) ...@@ -1111,7 +1111,7 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE); prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE);
timeout = jiffies; timeout = jiffies;
for (unit = 0; unit < MAX_DRIVES; unit++) { for (unit = 0; unit < MAX_DRIVES; unit++) {
ide_drive_t *tdrive = &hwif->drives[unit]; ide_drive_t *tdrive = hwif->devices[unit];
if (tdrive->dev_flags & IDE_DFLAG_PRESENT && if (tdrive->dev_flags & IDE_DFLAG_PRESENT &&
tdrive->dev_flags & IDE_DFLAG_PARKED && tdrive->dev_flags & IDE_DFLAG_PARKED &&
...@@ -1134,7 +1134,7 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) ...@@ -1134,7 +1134,7 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
* for any of the drives on this interface. * for any of the drives on this interface.
*/ */
for (unit = 0; unit < MAX_DRIVES; ++unit) for (unit = 0; unit < MAX_DRIVES; ++unit)
pre_reset(&hwif->drives[unit]); pre_reset(hwif->devices[unit]);
if (io_ports->ctl_addr == 0) { if (io_ports->ctl_addr == 0) {
spin_unlock_irqrestore(&hwif->lock, flags); spin_unlock_irqrestore(&hwif->lock, flags);
......
...@@ -463,7 +463,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd) ...@@ -463,7 +463,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
if (ide_read_device(drive) != drive->select && present == 0) { if (ide_read_device(drive) != drive->select && present == 0) {
if (drive->dn & 1) { if (drive->dn & 1) {
/* exit with drive0 selected */ /* exit with drive0 selected */
SELECT_DRIVE(&hwif->drives[0]); SELECT_DRIVE(hwif->devices[0]);
/* allow ATA_BUSY to assert & clear */ /* allow ATA_BUSY to assert & clear */
msleep(50); msleep(50);
} }
...@@ -509,7 +509,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd) ...@@ -509,7 +509,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
} }
if (drive->dn & 1) { if (drive->dn & 1) {
/* exit with drive0 selected */ /* exit with drive0 selected */
SELECT_DRIVE(&hwif->drives[0]); SELECT_DRIVE(hwif->devices[0]);
msleep(50); msleep(50);
/* ensure drive irq is clear */ /* ensure drive irq is clear */
(void)tp_ops->read_status(hwif); (void)tp_ops->read_status(hwif);
...@@ -715,7 +715,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif) ...@@ -715,7 +715,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
/* Now make sure both master & slave are ready */ /* Now make sure both master & slave are ready */
for (unit = 0; unit < MAX_DRIVES; unit++) { for (unit = 0; unit < MAX_DRIVES; unit++) {
ide_drive_t *drive = &hwif->drives[unit]; ide_drive_t *drive = hwif->devices[unit];
/* Ignore disks that we will not probe for later. */ /* Ignore disks that we will not probe for later. */
if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 || if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 ||
...@@ -733,7 +733,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif) ...@@ -733,7 +733,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
out: out:
/* Exit function with master reselected (let's be sane) */ /* Exit function with master reselected (let's be sane) */
if (unit) if (unit)
SELECT_DRIVE(&hwif->drives[0]); SELECT_DRIVE(hwif->devices[0]);
return rc; return rc;
} }
...@@ -749,7 +749,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif) ...@@ -749,7 +749,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
void ide_undecoded_slave(ide_drive_t *dev1) void ide_undecoded_slave(ide_drive_t *dev1)
{ {
ide_drive_t *dev0 = &dev1->hwif->drives[0]; ide_drive_t *dev0 = dev1->hwif->devices[0];
if ((dev1->dn & 1) == 0 || (dev0->dev_flags & IDE_DFLAG_PRESENT) == 0) if ((dev1->dn & 1) == 0 || (dev0->dev_flags & IDE_DFLAG_PRESENT) == 0)
return; return;
...@@ -784,8 +784,8 @@ static int ide_probe_port(ide_hwif_t *hwif) ...@@ -784,8 +784,8 @@ static int ide_probe_port(ide_hwif_t *hwif)
BUG_ON(hwif->present); BUG_ON(hwif->present);
if ((hwif->drives[0].dev_flags & IDE_DFLAG_NOPROBE) && if ((hwif->devices[0]->dev_flags & IDE_DFLAG_NOPROBE) &&
(hwif->drives[1].dev_flags & IDE_DFLAG_NOPROBE)) (hwif->devices[1]->dev_flags & IDE_DFLAG_NOPROBE))
return -EACCES; return -EACCES;
/* /*
...@@ -807,7 +807,7 @@ static int ide_probe_port(ide_hwif_t *hwif) ...@@ -807,7 +807,7 @@ static int ide_probe_port(ide_hwif_t *hwif)
* but a lot of cdrom drives are configured as single slaves. * but a lot of cdrom drives are configured as single slaves.
*/ */
for (unit = 0; unit < MAX_DRIVES; ++unit) { for (unit = 0; unit < MAX_DRIVES; ++unit) {
ide_drive_t *drive = &hwif->drives[unit]; ide_drive_t *drive = hwif->devices[unit];
(void) probe_for_drive(drive); (void) probe_for_drive(drive);
if (drive->dev_flags & IDE_DFLAG_PRESENT) if (drive->dev_flags & IDE_DFLAG_PRESENT)
...@@ -832,7 +832,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif) ...@@ -832,7 +832,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
int unit; int unit;
for (unit = 0; unit < MAX_DRIVES; unit++) { for (unit = 0; unit < MAX_DRIVES; unit++) {
ide_drive_t *drive = &hwif->drives[unit]; ide_drive_t *drive = hwif->devices[unit];
if (drive->dev_flags & IDE_DFLAG_PRESENT) { if (drive->dev_flags & IDE_DFLAG_PRESENT) {
if (port_ops && port_ops->quirkproc) if (port_ops && port_ops->quirkproc)
...@@ -841,7 +841,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif) ...@@ -841,7 +841,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
} }
for (unit = 0; unit < MAX_DRIVES; ++unit) { for (unit = 0; unit < MAX_DRIVES; ++unit) {
ide_drive_t *drive = &hwif->drives[unit]; ide_drive_t *drive = hwif->devices[unit];
if (drive->dev_flags & IDE_DFLAG_PRESENT) { if (drive->dev_flags & IDE_DFLAG_PRESENT) {
ide_set_max_pio(drive); ide_set_max_pio(drive);
...@@ -854,7 +854,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif) ...@@ -854,7 +854,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
} }
for (unit = 0; unit < MAX_DRIVES; ++unit) { for (unit = 0; unit < MAX_DRIVES; ++unit) {
ide_drive_t *drive = &hwif->drives[unit]; ide_drive_t *drive = hwif->devices[unit];
if ((hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) || if ((hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) ||
drive->id[ATA_ID_DWORD_IO]) drive->id[ATA_ID_DWORD_IO])
...@@ -931,7 +931,7 @@ static int ide_port_setup_devices(ide_hwif_t *hwif) ...@@ -931,7 +931,7 @@ static int ide_port_setup_devices(ide_hwif_t *hwif)
mutex_lock(&ide_cfg_mtx); mutex_lock(&ide_cfg_mtx);
for (i = 0; i < MAX_DRIVES; i++) { for (i = 0; i < MAX_DRIVES; i++) {
ide_drive_t *drive = &hwif->drives[i]; ide_drive_t *drive = hwif->devices[i];
if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
continue; continue;
...@@ -1017,7 +1017,7 @@ static struct kobject *ata_probe(dev_t dev, int *part, void *data) ...@@ -1017,7 +1017,7 @@ static struct kobject *ata_probe(dev_t dev, int *part, void *data)
{ {
ide_hwif_t *hwif = data; ide_hwif_t *hwif = data;
int unit = *part >> PARTN_BITS; int unit = *part >> PARTN_BITS;
ide_drive_t *drive = &hwif->drives[unit]; ide_drive_t *drive = hwif->devices[unit];
if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
return NULL; return NULL;
...@@ -1164,7 +1164,7 @@ static void hwif_register_devices(ide_hwif_t *hwif) ...@@ -1164,7 +1164,7 @@ static void hwif_register_devices(ide_hwif_t *hwif)
unsigned int i; unsigned int i;
for (i = 0; i < MAX_DRIVES; i++) { for (i = 0; i < MAX_DRIVES; i++) {
ide_drive_t *drive = &hwif->drives[i]; ide_drive_t *drive = hwif->devices[i];
struct device *dev = &drive->gendev; struct device *dev = &drive->gendev;
int ret; int ret;
...@@ -1190,7 +1190,7 @@ static void ide_port_init_devices(ide_hwif_t *hwif) ...@@ -1190,7 +1190,7 @@ static void ide_port_init_devices(ide_hwif_t *hwif)
int i; int i;
for (i = 0; i < MAX_DRIVES; i++) { for (i = 0; i < MAX_DRIVES; i++) {
ide_drive_t *drive = &hwif->drives[i]; ide_drive_t *drive = hwif->devices[i];
drive->dn = i + hwif->channel * 2; drive->dn = i + hwif->channel * 2;
...@@ -1285,7 +1285,7 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif) ...@@ -1285,7 +1285,7 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
int unit; int unit;
for (unit = 0; unit < MAX_DRIVES; ++unit) { for (unit = 0; unit < MAX_DRIVES; ++unit) {
ide_drive_t *drive = &hwif->drives[unit]; ide_drive_t *drive = hwif->devices[unit];
u8 j = (hwif->index * MAX_DRIVES) + unit; u8 j = (hwif->index * MAX_DRIVES) + unit;
memset(drive, 0, sizeof(*drive)); memset(drive, 0, sizeof(*drive));
...@@ -1309,9 +1309,6 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif) ...@@ -1309,9 +1309,6 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
static void ide_init_port_data(ide_hwif_t *hwif, unsigned int index) static void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
{ {
/* bulk initialize hwif & drive info with zeros */
memset(hwif, 0, sizeof(ide_hwif_t));
/* fill in any non-zero initial values */ /* fill in any non-zero initial values */
hwif->index = index; hwif->index = index;
hwif->major = ide_hwif_to_major[index]; hwif->major = ide_hwif_to_major[index];
...@@ -1388,6 +1385,34 @@ static void ide_free_port_slot(int idx) ...@@ -1388,6 +1385,34 @@ static void ide_free_port_slot(int idx)
mutex_unlock(&ide_cfg_mtx); mutex_unlock(&ide_cfg_mtx);
} }
static void ide_port_free_devices(ide_hwif_t *hwif)
{
int i;
for (i = 0; i < MAX_DRIVES; i++)
kfree(hwif->devices[i]);
}
static int ide_port_alloc_devices(ide_hwif_t *hwif, int node)
{
int i;
for (i = 0; i < MAX_DRIVES; i++) {
ide_drive_t *drive;
drive = kzalloc_node(sizeof(*drive), GFP_KERNEL, node);
if (drive == NULL)
goto out_nomem;
hwif->devices[i] = drive;
}
return 0;
out_nomem:
ide_port_free_devices(hwif);
return -ENOMEM;
}
struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws) struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
{ {
struct ide_host *host; 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,6 +1435,11 @@ struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
if (hwif == NULL) if (hwif == NULL)
continue; continue;
if (ide_port_alloc_devices(hwif, node) < 0) {
kfree(hwif);
continue;
}
idx = ide_find_port_slot(d); idx = ide_find_port_slot(d);
if (idx < 0) { if (idx < 0) {
printk(KERN_ERR "%s: no free slot for interface\n", 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,7 +1605,7 @@ static void __ide_port_unregister_devices(ide_hwif_t *hwif)
int i; int i;
for (i = 0; i < MAX_DRIVES; i++) { for (i = 0; i < MAX_DRIVES; i++) {
ide_drive_t *drive = &hwif->drives[i]; ide_drive_t *drive = hwif->devices[i];
if (drive->dev_flags & IDE_DFLAG_PRESENT) { if (drive->dev_flags & IDE_DFLAG_PRESENT) {
device_unregister(&drive->gendev); device_unregister(&drive->gendev);
...@@ -1651,6 +1681,7 @@ void ide_host_free(struct ide_host *host) ...@@ -1651,6 +1681,7 @@ void ide_host_free(struct ide_host *host)
if (hwif == NULL) if (hwif == NULL)
continue; continue;
ide_port_free_devices(hwif);
ide_free_port_slot(hwif->index); ide_free_port_slot(hwif->index);
kfree(hwif); kfree(hwif);
} }
......
...@@ -599,7 +599,7 @@ void ide_proc_port_register_devices(ide_hwif_t *hwif) ...@@ -599,7 +599,7 @@ void ide_proc_port_register_devices(ide_hwif_t *hwif)
char name[64]; char name[64];
for (d = 0; d < MAX_DRIVES; d++) { for (d = 0; d < MAX_DRIVES; d++) {
ide_drive_t *drive = &hwif->drives[d]; ide_drive_t *drive = hwif->devices[d];
if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0 || drive->proc) if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0 || drive->proc)
continue; continue;
......
...@@ -497,7 +497,7 @@ void ide_port_apply_params(ide_hwif_t *hwif) ...@@ -497,7 +497,7 @@ void ide_port_apply_params(ide_hwif_t *hwif)
} }
for (i = 0; i < MAX_DRIVES; i++) for (i = 0; i < MAX_DRIVES; i++)
ide_dev_apply_params(&hwif->drives[i], i); ide_dev_apply_params(hwif->devices[i], i);
} }
/* /*
......
...@@ -259,7 +259,7 @@ static void scc_set_dma_mode(ide_drive_t *drive, const u8 speed) ...@@ -259,7 +259,7 @@ static void scc_set_dma_mode(ide_drive_t *drive, const u8 speed)
unsigned long scrcst_port = ctl_base + 0x014; unsigned long scrcst_port = ctl_base + 0x014;
unsigned long udenvt_port = ctl_base + 0x018; unsigned long udenvt_port = ctl_base + 0x018;
unsigned long tdvhsel_port = ctl_base + 0x020; unsigned long tdvhsel_port = ctl_base + 0x020;
int is_slave = (&hwif->drives[1] == drive); int is_slave = drive->dn & 1;
int offset, idx; int offset, idx;
unsigned long reg; unsigned long reg;
unsigned long jcactsel; unsigned long jcactsel;
...@@ -413,7 +413,8 @@ static int scc_dma_end(ide_drive_t *drive) ...@@ -413,7 +413,8 @@ static int scc_dma_end(ide_drive_t *drive)
if (rq) if (rq)
rq->errors |= ERROR_RESET; rq->errors |= ERROR_RESET;
for (unit = 0; unit < MAX_DRIVES; unit++) { for (unit = 0; unit < MAX_DRIVES; unit++) {
ide_drive_t *drive = &hwif->drives[unit]; ide_drive_t *drive = hwif->devices[unit];
drive->crc_count++; drive->crc_count++;
} }
} }
......
...@@ -753,7 +753,7 @@ typedef struct hwif_s { ...@@ -753,7 +753,7 @@ typedef struct hwif_s {
unsigned long sata_scr[SATA_NR_PORTS]; unsigned long sata_scr[SATA_NR_PORTS];
ide_drive_t drives[MAX_DRIVES]; /* drive info */ ide_drive_t *devices[MAX_DRIVES];
u8 major; /* our major number */ u8 major; /* our major number */
u8 index; /* 0 for ide0; 1 for ide1; ... */ u8 index; /* 0 for ide0; 1 for ide1; ... */
...@@ -1600,7 +1600,7 @@ static inline int hwif_to_node(ide_hwif_t *hwif) ...@@ -1600,7 +1600,7 @@ static inline int hwif_to_node(ide_hwif_t *hwif)
static inline ide_drive_t *ide_get_pair_dev(ide_drive_t *drive) static inline ide_drive_t *ide_get_pair_dev(ide_drive_t *drive)
{ {
ide_drive_t *peer = &drive->hwif->drives[(drive->dn ^ 1) & 1]; ide_drive_t *peer = drive->hwif->devices[(drive->dn ^ 1) & 1];
return (peer->dev_flags & IDE_DFLAG_PRESENT) ? peer : NULL; return (peer->dev_flags & IDE_DFLAG_PRESENT) ? peer : NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment