Skip to content

Commit 4dde449

Browse files
committed
ide: make drive->id an union (take 2)
Make drive->id an unnamed union so id can be accessed either by using 'u16 *id' or 'struct hd_driveid *driveid'. Then convert all existing drive->id users accordingly (using 'u16 *id' when possible). This is an intermediate step to make ide 'struct hd_driveid'-free. While at it: - Add missing KERN_CONTs in it821x.c. - Use ATA_ID_WORDS and ATA_ID_*_LEN defines. - Remove unnecessary checks for drive->id. - s/drive_table/table/ in ide_in_drive_list(). - Cleanup ide_config_drive_speed() a bit. - s/drive1/dev1/ & s/drive0/dev0/ in ide_undecoded_slave(). v2: Fix typo in drivers/ide/ppc/pmac.c. (From Stephen Rothwell) There should be no functional changes caused by this patch. Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
1 parent 5b90e99 commit 4dde449

28 files changed

Lines changed: 312 additions & 280 deletions

‎drivers/ide/arm/icside.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ static void icside_set_dma_mode(ide_drive_t *drive, const u8 xfer_mode)
265265
* If we're going to be doing MW_DMA_1 or MW_DMA_2, we should
266266
* take care to note the values in the ID...
267267
*/
268-
if (use_dma_info && drive->id->eide_dma_time > cycle_time)
269-
cycle_time = drive->id->eide_dma_time;
268+
if (use_dma_info && drive->id[ATA_ID_EIDE_DMA_TIME] > cycle_time)
269+
cycle_time = drive->id[ATA_ID_EIDE_DMA_TIME];
270270

271271
drive->drive_data = cycle_time;
272272

‎drivers/ide/arm/palm_bk3710.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ static void palm_bk3710_set_dma_mode(ide_drive_t *drive, u8 xferspeed)
213213
palm_bk3710_setudmamode(base, is_slave,
214214
xferspeed - XFER_UDMA_0);
215215
} else {
216-
palm_bk3710_setdmamode(base, is_slave, drive->id->eide_dma_min,
216+
palm_bk3710_setdmamode(base, is_slave,
217+
drive->id[ATA_ID_EIDE_DMA_MIN],
217218
xferspeed);
218219
}
219220
}

‎drivers/ide/ide-acpi.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ void ide_acpi_get_timing(ide_hwif_t *hwif)
584584
* This function executes the _STM ACPI method for the target channel.
585585
*
586586
* _STM requires Identify Drive data, which has to passed as an argument.
587-
* Unfortunately hd_driveid is a mangled version which we can't readily
587+
* Unfortunately drive->id is a mangled version which we can't readily
588588
* use; hence we'll get the information afresh.
589589
*/
590590
void ide_acpi_push_timing(ide_hwif_t *hwif)
@@ -614,10 +614,10 @@ void ide_acpi_push_timing(ide_hwif_t *hwif)
614614
in_params[0].buffer.length = sizeof(struct GTM_buffer);
615615
in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm;
616616
in_params[1].type = ACPI_TYPE_BUFFER;
617-
in_params[1].buffer.length = sizeof(struct hd_driveid);
617+
in_params[1].buffer.length = sizeof(ATA_ID_WORDS * 2);
618618
in_params[1].buffer.pointer = (u8 *)&master->idbuff;
619619
in_params[2].type = ACPI_TYPE_BUFFER;
620-
in_params[2].buffer.length = sizeof(struct hd_driveid);
620+
in_params[2].buffer.length = sizeof(ATA_ID_WORDS * 2);
621621
in_params[2].buffer.pointer = (u8 *)&slave->idbuff;
622622
/* Output buffer: _STM has no output */
623623

‎drivers/ide/ide-cd.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,14 +1866,14 @@ static const struct cd_list_entry ide_cd_quirks_list[] = {
18661866
{ NULL, NULL, 0 }
18671867
};
18681868

1869-
static unsigned int ide_cd_flags(struct hd_driveid *id)
1869+
static unsigned int ide_cd_flags(u16 *id)
18701870
{
18711871
const struct cd_list_entry *cle = ide_cd_quirks_list;
18721872

18731873
while (cle->id_model) {
1874-
if (strcmp(cle->id_model, id->model) == 0 &&
1874+
if (strcmp(cle->id_model, (char *)&id[ATA_ID_PROD]) == 0 &&
18751875
(cle->id_firmware == NULL ||
1876-
strstr(id->fw_rev, cle->id_firmware)))
1876+
strstr((char *)&id[ATA_ID_FW_REV], cle->id_firmware)))
18771877
return cle->cd_flags;
18781878
cle++;
18791879
}
@@ -1885,7 +1885,8 @@ static int ide_cdrom_setup(ide_drive_t *drive)
18851885
{
18861886
struct cdrom_info *cd = drive->driver_data;
18871887
struct cdrom_device_info *cdi = &cd->devinfo;
1888-
struct hd_driveid *id = drive->id;
1888+
u16 *id = drive->id;
1889+
char *fw_rev = (char *)&id[ATA_ID_FW_REV];
18891890
int nslots;
18901891

18911892
blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn);
@@ -1900,15 +1901,15 @@ static int ide_cdrom_setup(ide_drive_t *drive)
19001901
drive->atapi_flags = IDE_AFLAG_MEDIA_CHANGED | IDE_AFLAG_NO_EJECT |
19011902
ide_cd_flags(id);
19021903

1903-
if ((id->config & 0x0060) == 0x20)
1904+
if ((id[ATA_ID_CONFIG] & 0x0060) == 0x20)
19041905
drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
19051906

19061907
if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) &&
1907-
id->fw_rev[4] == '1' && id->fw_rev[6] <= '2')
1908+
fw_rev[4] == '1' && fw_rev[6] <= '2')
19081909
drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD |
19091910
IDE_AFLAG_TOCADDR_AS_BCD);
19101911
else if ((drive->atapi_flags & IDE_AFLAG_VERTOS_600_ESD) &&
1911-
id->fw_rev[4] == '1' && id->fw_rev[6] <= '2')
1912+
fw_rev[4] == '1' && fw_rev[6] <= '2')
19121913
drive->atapi_flags |= IDE_AFLAG_TOCTRACKS_AS_BCD;
19131914
else if (drive->atapi_flags & IDE_AFLAG_SANYO_3CD)
19141915
/* 3 => use CD in slot 0 */

‎drivers/ide/ide-disk.c‎

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,13 @@ static void ide_disk_put(struct ide_disk_obj *idkp)
9999
*
100100
* It is called only once for each drive.
101101
*/
102-
static int lba_capacity_is_ok(struct hd_driveid *id)
102+
static int lba_capacity_is_ok(u16 *id)
103103
{
104+
struct hd_driveid *driveid = (struct hd_driveid *)id;
104105
unsigned long lba_sects, chs_sects, head, tail;
105106

106107
/* No non-LBA info .. so valid! */
107-
if (id->cyls == 0)
108+
if (id[ATA_ID_CYLS] == 0)
108109
return 1;
109110

110111
/*
@@ -113,15 +114,15 @@ static int lba_capacity_is_ok(struct hd_driveid *id)
113114
* Some drives can be jumpered to use 15 heads instead of 16.
114115
* Some drives can be jumpered to use 4092 cyls instead of 16383.
115116
*/
116-
if ((id->cyls == 16383
117-
|| (id->cyls == 4092 && id->cur_cyls == 16383)) &&
118-
id->sectors == 63 &&
119-
(id->heads == 15 || id->heads == 16) &&
120-
(id->lba_capacity >= 16383*63*id->heads))
117+
if ((id[ATA_ID_CYLS] == 16383 ||
118+
(id[ATA_ID_CYLS] == 4092 && id[ATA_ID_CUR_CYLS] == 16383)) &&
119+
id[ATA_ID_SECTORS] == 63 &&
120+
(id[ATA_ID_HEADS] == 15 || id[ATA_ID_HEADS] == 16) &&
121+
(driveid->lba_capacity >= 16383 * 63 * id[ATA_ID_HEADS]))
121122
return 1;
122123

123-
lba_sects = id->lba_capacity;
124-
chs_sects = id->cyls * id->heads * id->sectors;
124+
lba_sects = driveid->lba_capacity;
125+
chs_sects = id[ATA_ID_CYLS] * id[ATA_ID_HEADS] * id[ATA_ID_SECTORS];
125126

126127
/* perform a rough sanity check on lba_sects: within 10% is OK */
127128
if ((lba_sects - chs_sects) < chs_sects/10)
@@ -132,7 +133,7 @@ static int lba_capacity_is_ok(struct hd_driveid *id)
132133
tail = (lba_sects & 0xffff);
133134
lba_sects = (head | (tail << 16));
134135
if ((lba_sects - chs_sects) < chs_sects/10) {
135-
id->lba_capacity = lba_sects;
136+
driveid->lba_capacity = lba_sects;
136137
return 1; /* lba_capacity is (now) good */
137138
}
138139

@@ -389,18 +390,20 @@ static unsigned long long sectors_to_MB(unsigned long long n)
389390
* so on non-buggy drives we need test only one.
390391
* However, we should also check whether these fields are valid.
391392
*/
392-
static inline int idedisk_supports_hpa(const struct hd_driveid *id)
393+
static inline int idedisk_supports_hpa(const u16 *id)
393394
{
394-
return (id->command_set_1 & 0x0400) && (id->cfs_enable_1 & 0x0400);
395+
return (id[ATA_ID_COMMAND_SET_1] & 0x0400) &&
396+
(id[ATA_ID_CFS_ENABLE_1] & 0x0400);
395397
}
396398

397399
/*
398400
* The same here.
399401
*/
400-
static inline int idedisk_supports_lba48(const struct hd_driveid *id)
402+
static inline int idedisk_supports_lba48(const u16 *id)
401403
{
402-
return (id->command_set_2 & 0x0400) && (id->cfs_enable_2 & 0x0400)
403-
&& id->lba_capacity_2;
404+
return (id[ATA_ID_COMMAND_SET_2] & 0x0400) &&
405+
(id[ATA_ID_CFS_ENABLE_2] & 0x0400) &&
406+
((struct hd_driveid *)id)->lba_capacity_2;
404407
}
405408

406409
/*
@@ -453,7 +456,8 @@ static void idedisk_check_hpa(ide_drive_t *drive)
453456

454457
static void init_idedisk_capacity(ide_drive_t *drive)
455458
{
456-
struct hd_driveid *id = drive->id;
459+
struct hd_driveid *driveid = drive->driveid;
460+
u16 *id = drive->id;
457461
/*
458462
* If this drive supports the Host Protected Area feature set,
459463
* then we may need to change our opinion about the drive's capacity.
@@ -463,13 +467,13 @@ static void init_idedisk_capacity(ide_drive_t *drive)
463467
if (idedisk_supports_lba48(id)) {
464468
/* drive speaks 48-bit LBA */
465469
drive->select.b.lba = 1;
466-
drive->capacity64 = id->lba_capacity_2;
470+
drive->capacity64 = driveid->lba_capacity_2;
467471
if (hpa)
468472
idedisk_check_hpa(drive);
469-
} else if ((id->capability & 2) && lba_capacity_is_ok(id)) {
473+
} else if ((driveid->capability & 2) && lba_capacity_is_ok(id)) {
470474
/* drive speaks 28-bit LBA */
471475
drive->select.b.lba = 1;
472-
drive->capacity64 = id->lba_capacity;
476+
drive->capacity64 = driveid->lba_capacity;
473477
if (hpa)
474478
idedisk_check_hpa(drive);
475479
} else {
@@ -523,7 +527,7 @@ static int proc_idedisk_read_cache
523527
int len;
524528

525529
if (drive->id_read)
526-
len = sprintf(out, "%i\n", drive->id->buf_size / 2);
530+
len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
527531
else
528532
len = sprintf(out, "(none)\n");
529533

@@ -618,7 +622,7 @@ static int set_multcount(ide_drive_t *drive, int arg)
618622
struct request *rq;
619623
int error;
620624

621-
if (arg < 0 || arg > drive->id->max_multsect)
625+
if (arg < 0 || arg > drive->driveid->max_multsect)
622626
return -EINVAL;
623627

624628
if (drive->special.b.set_multmode)
@@ -650,7 +654,7 @@ static int set_nowerr(ide_drive_t *drive, int arg)
650654

651655
static void update_ordered(ide_drive_t *drive)
652656
{
653-
struct hd_driveid *id = drive->id;
657+
u16 *id = drive->id;
654658
unsigned ordered = QUEUE_ORDERED_NONE;
655659
prepare_flush_fn *prep_fn = NULL;
656660

@@ -762,8 +766,6 @@ static int set_lba_addressing(ide_drive_t *drive, int arg)
762766
#ifdef CONFIG_IDE_PROC_FS
763767
static void idedisk_add_settings(ide_drive_t *drive)
764768
{
765-
struct hd_driveid *id = drive->id;
766-
767769
ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 65535, 1, 1,
768770
&drive->bios_cyl, NULL);
769771
ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1,
@@ -773,7 +775,7 @@ static void idedisk_add_settings(ide_drive_t *drive)
773775
ide_add_setting(drive, "address", SETTING_RW, TYPE_BYTE, 0, 2, 1, 1,
774776
&drive->addressing, set_lba_addressing);
775777
ide_add_setting(drive, "multcount", SETTING_RW, TYPE_BYTE, 0,
776-
id->max_multsect, 1, 1, &drive->mult_count,
778+
drive->driveid->max_multsect, 1, 1, &drive->mult_count,
777779
set_multcount);
778780
ide_add_setting(drive, "nowerr", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1,
779781
&drive->nowerr, set_nowerr);
@@ -795,7 +797,8 @@ static inline void idedisk_add_settings(ide_drive_t *drive) { ; }
795797
static void idedisk_setup(ide_drive_t *drive)
796798
{
797799
ide_hwif_t *hwif = drive->hwif;
798-
struct hd_driveid *id = drive->id;
800+
u16 *id = drive->id;
801+
char *m = (char *)&id[ATA_ID_PROD];
799802
unsigned long long capacity;
800803

801804
idedisk_add_settings(drive);
@@ -807,7 +810,7 @@ static void idedisk_setup(ide_drive_t *drive)
807810
/*
808811
* Removable disks (eg. SYQUEST); ignore 'WD' drives
809812
*/
810-
if (id->model[0] != 'W' || id->model[1] != 'D')
813+
if (m[0] != 'W' || m[1] != 'D')
811814
drive->doorlocking = 1;
812815
}
813816

@@ -880,14 +883,14 @@ static void idedisk_setup(ide_drive_t *drive)
880883
drive->name, capacity, sectors_to_MB(capacity));
881884

882885
/* Only print cache size when it was specified */
883-
if (id->buf_size)
884-
printk(KERN_CONT " w/%dKiB Cache", id->buf_size / 2);
886+
if (id[ATA_ID_BUF_SIZE])
887+
printk(KERN_CONT " w/%dKiB Cache", id[ATA_ID_BUF_SIZE] / 2);
885888

886889
printk(KERN_CONT ", CHS=%d/%d/%d\n",
887890
drive->bios_cyl, drive->bios_head, drive->bios_sect);
888891

889892
/* write cache enabled? */
890-
if ((id->csfo & 1) || (id->cfs_enable_1 & (1 << 5)))
893+
if ((id[ATA_ID_CSFO] & 1) || (id[ATA_ID_CFS_ENABLE_1] & (1 << 5)))
891894
drive->wcache = 1;
892895

893896
write_cache(drive, 1);

0 commit comments

Comments
 (0)