Skip to content

Commit

Permalink
ide: make drive->id an union (take 2)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Bartlomiej Zolnierkiewicz committed Oct 10, 2008
1 parent 5b90e99 commit 4dde449
Show file tree
Hide file tree
Showing 28 changed files with 312 additions and 280 deletions.
4 changes: 2 additions & 2 deletions drivers/ide/arm/icside.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ static void icside_set_dma_mode(ide_drive_t *drive, const u8 xfer_mode)
* If we're going to be doing MW_DMA_1 or MW_DMA_2, we should
* take care to note the values in the ID...
*/
if (use_dma_info && drive->id->eide_dma_time > cycle_time)
cycle_time = drive->id->eide_dma_time;
if (use_dma_info && drive->id[ATA_ID_EIDE_DMA_TIME] > cycle_time)
cycle_time = drive->id[ATA_ID_EIDE_DMA_TIME];

drive->drive_data = cycle_time;

Expand Down
3 changes: 2 additions & 1 deletion drivers/ide/arm/palm_bk3710.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ static void palm_bk3710_set_dma_mode(ide_drive_t *drive, u8 xferspeed)
palm_bk3710_setudmamode(base, is_slave,
xferspeed - XFER_UDMA_0);
} else {
palm_bk3710_setdmamode(base, is_slave, drive->id->eide_dma_min,
palm_bk3710_setdmamode(base, is_slave,
drive->id[ATA_ID_EIDE_DMA_MIN],
xferspeed);
}
}
Expand Down
6 changes: 3 additions & 3 deletions drivers/ide/ide-acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ void ide_acpi_get_timing(ide_hwif_t *hwif)
* This function executes the _STM ACPI method for the target channel.
*
* _STM requires Identify Drive data, which has to passed as an argument.
* Unfortunately hd_driveid is a mangled version which we can't readily
* Unfortunately drive->id is a mangled version which we can't readily
* use; hence we'll get the information afresh.
*/
void ide_acpi_push_timing(ide_hwif_t *hwif)
Expand Down Expand Up @@ -614,10 +614,10 @@ void ide_acpi_push_timing(ide_hwif_t *hwif)
in_params[0].buffer.length = sizeof(struct GTM_buffer);
in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm;
in_params[1].type = ACPI_TYPE_BUFFER;
in_params[1].buffer.length = sizeof(struct hd_driveid);
in_params[1].buffer.length = sizeof(ATA_ID_WORDS * 2);
in_params[1].buffer.pointer = (u8 *)&master->idbuff;
in_params[2].type = ACPI_TYPE_BUFFER;
in_params[2].buffer.length = sizeof(struct hd_driveid);
in_params[2].buffer.length = sizeof(ATA_ID_WORDS * 2);
in_params[2].buffer.pointer = (u8 *)&slave->idbuff;
/* Output buffer: _STM has no output */

Expand Down
15 changes: 8 additions & 7 deletions drivers/ide/ide-cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1866,14 +1866,14 @@ static const struct cd_list_entry ide_cd_quirks_list[] = {
{ NULL, NULL, 0 }
};

static unsigned int ide_cd_flags(struct hd_driveid *id)
static unsigned int ide_cd_flags(u16 *id)
{
const struct cd_list_entry *cle = ide_cd_quirks_list;

while (cle->id_model) {
if (strcmp(cle->id_model, id->model) == 0 &&
if (strcmp(cle->id_model, (char *)&id[ATA_ID_PROD]) == 0 &&
(cle->id_firmware == NULL ||
strstr(id->fw_rev, cle->id_firmware)))
strstr((char *)&id[ATA_ID_FW_REV], cle->id_firmware)))
return cle->cd_flags;
cle++;
}
Expand All @@ -1885,7 +1885,8 @@ static int ide_cdrom_setup(ide_drive_t *drive)
{
struct cdrom_info *cd = drive->driver_data;
struct cdrom_device_info *cdi = &cd->devinfo;
struct hd_driveid *id = drive->id;
u16 *id = drive->id;
char *fw_rev = (char *)&id[ATA_ID_FW_REV];
int nslots;

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

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

if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) &&
id->fw_rev[4] == '1' && id->fw_rev[6] <= '2')
fw_rev[4] == '1' && fw_rev[6] <= '2')
drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD |
IDE_AFLAG_TOCADDR_AS_BCD);
else if ((drive->atapi_flags & IDE_AFLAG_VERTOS_600_ESD) &&
id->fw_rev[4] == '1' && id->fw_rev[6] <= '2')
fw_rev[4] == '1' && fw_rev[6] <= '2')
drive->atapi_flags |= IDE_AFLAG_TOCTRACKS_AS_BCD;
else if (drive->atapi_flags & IDE_AFLAG_SANYO_3CD)
/* 3 => use CD in slot 0 */
Expand Down
63 changes: 33 additions & 30 deletions drivers/ide/ide-disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ static void ide_disk_put(struct ide_disk_obj *idkp)
*
* It is called only once for each drive.
*/
static int lba_capacity_is_ok(struct hd_driveid *id)
static int lba_capacity_is_ok(u16 *id)
{
struct hd_driveid *driveid = (struct hd_driveid *)id;
unsigned long lba_sects, chs_sects, head, tail;

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

/*
Expand All @@ -113,15 +114,15 @@ static int lba_capacity_is_ok(struct hd_driveid *id)
* Some drives can be jumpered to use 15 heads instead of 16.
* Some drives can be jumpered to use 4092 cyls instead of 16383.
*/
if ((id->cyls == 16383
|| (id->cyls == 4092 && id->cur_cyls == 16383)) &&
id->sectors == 63 &&
(id->heads == 15 || id->heads == 16) &&
(id->lba_capacity >= 16383*63*id->heads))
if ((id[ATA_ID_CYLS] == 16383 ||
(id[ATA_ID_CYLS] == 4092 && id[ATA_ID_CUR_CYLS] == 16383)) &&
id[ATA_ID_SECTORS] == 63 &&
(id[ATA_ID_HEADS] == 15 || id[ATA_ID_HEADS] == 16) &&
(driveid->lba_capacity >= 16383 * 63 * id[ATA_ID_HEADS]))
return 1;

lba_sects = id->lba_capacity;
chs_sects = id->cyls * id->heads * id->sectors;
lba_sects = driveid->lba_capacity;
chs_sects = id[ATA_ID_CYLS] * id[ATA_ID_HEADS] * id[ATA_ID_SECTORS];

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

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

/*
* The same here.
*/
static inline int idedisk_supports_lba48(const struct hd_driveid *id)
static inline int idedisk_supports_lba48(const u16 *id)
{
return (id->command_set_2 & 0x0400) && (id->cfs_enable_2 & 0x0400)
&& id->lba_capacity_2;
return (id[ATA_ID_COMMAND_SET_2] & 0x0400) &&
(id[ATA_ID_CFS_ENABLE_2] & 0x0400) &&
((struct hd_driveid *)id)->lba_capacity_2;
}

/*
Expand Down Expand Up @@ -453,7 +456,8 @@ static void idedisk_check_hpa(ide_drive_t *drive)

static void init_idedisk_capacity(ide_drive_t *drive)
{
struct hd_driveid *id = drive->id;
struct hd_driveid *driveid = drive->driveid;
u16 *id = drive->id;
/*
* If this drive supports the Host Protected Area feature set,
* then we may need to change our opinion about the drive's capacity.
Expand All @@ -463,13 +467,13 @@ static void init_idedisk_capacity(ide_drive_t *drive)
if (idedisk_supports_lba48(id)) {
/* drive speaks 48-bit LBA */
drive->select.b.lba = 1;
drive->capacity64 = id->lba_capacity_2;
drive->capacity64 = driveid->lba_capacity_2;
if (hpa)
idedisk_check_hpa(drive);
} else if ((id->capability & 2) && lba_capacity_is_ok(id)) {
} else if ((driveid->capability & 2) && lba_capacity_is_ok(id)) {
/* drive speaks 28-bit LBA */
drive->select.b.lba = 1;
drive->capacity64 = id->lba_capacity;
drive->capacity64 = driveid->lba_capacity;
if (hpa)
idedisk_check_hpa(drive);
} else {
Expand Down Expand Up @@ -523,7 +527,7 @@ static int proc_idedisk_read_cache
int len;

if (drive->id_read)
len = sprintf(out, "%i\n", drive->id->buf_size / 2);
len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
else
len = sprintf(out, "(none)\n");

Expand Down Expand Up @@ -618,7 +622,7 @@ static int set_multcount(ide_drive_t *drive, int arg)
struct request *rq;
int error;

if (arg < 0 || arg > drive->id->max_multsect)
if (arg < 0 || arg > drive->driveid->max_multsect)
return -EINVAL;

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

static void update_ordered(ide_drive_t *drive)
{
struct hd_driveid *id = drive->id;
u16 *id = drive->id;
unsigned ordered = QUEUE_ORDERED_NONE;
prepare_flush_fn *prep_fn = NULL;

Expand Down Expand Up @@ -762,8 +766,6 @@ static int set_lba_addressing(ide_drive_t *drive, int arg)
#ifdef CONFIG_IDE_PROC_FS
static void idedisk_add_settings(ide_drive_t *drive)
{
struct hd_driveid *id = drive->id;

ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 65535, 1, 1,
&drive->bios_cyl, NULL);
ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1,
Expand All @@ -773,7 +775,7 @@ static void idedisk_add_settings(ide_drive_t *drive)
ide_add_setting(drive, "address", SETTING_RW, TYPE_BYTE, 0, 2, 1, 1,
&drive->addressing, set_lba_addressing);
ide_add_setting(drive, "multcount", SETTING_RW, TYPE_BYTE, 0,
id->max_multsect, 1, 1, &drive->mult_count,
drive->driveid->max_multsect, 1, 1, &drive->mult_count,
set_multcount);
ide_add_setting(drive, "nowerr", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1,
&drive->nowerr, set_nowerr);
Expand All @@ -795,7 +797,8 @@ static inline void idedisk_add_settings(ide_drive_t *drive) { ; }
static void idedisk_setup(ide_drive_t *drive)
{
ide_hwif_t *hwif = drive->hwif;
struct hd_driveid *id = drive->id;
u16 *id = drive->id;
char *m = (char *)&id[ATA_ID_PROD];
unsigned long long capacity;

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

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

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

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

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

write_cache(drive, 1);
Expand Down
Loading

0 comments on commit 4dde449

Please sign in to comment.