Commit 3153c26b54230d025c6d536e8d3015def4524906
Committed by
Bartlomiej Zolnierkiewicz
1 parent
c9ff9e7b64
Exists in
master
and in
39 other branches
ide: refactor tf_read() method
Simplify tf_read() method, making it deal only with 'struct ide_taskfile' and the validity flags that the upper layer passes, and factoring out the code that deals with the high order bytes into ide_tf_readback() to be called from the only two functions interested, ide_complete_cmd() and ide_dump_sector(). This should stop the needless code duplication in this method and so make it about twice smaller than it was; along with simplifying the setup for the method call, this should save both time and space... Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Showing 10 changed files with 40 additions and 101 deletions Side-by-side Diff
drivers/ide/ide-atapi.c
... | ... | @@ -254,15 +254,13 @@ |
254 | 254 | |
255 | 255 | void ide_read_bcount_and_ireason(ide_drive_t *drive, u16 *bcount, u8 *ireason) |
256 | 256 | { |
257 | - struct ide_cmd cmd; | |
257 | + struct ide_taskfile tf; | |
258 | 258 | |
259 | - memset(&cmd, 0, sizeof(cmd)); | |
260 | - cmd.valid.in.tf = IDE_VALID_LBAH | IDE_VALID_LBAM | IDE_VALID_NSECT; | |
259 | + drive->hwif->tp_ops->tf_read(drive, &tf, IDE_VALID_NSECT | | |
260 | + IDE_VALID_LBAM | IDE_VALID_LBAH); | |
261 | 261 | |
262 | - drive->hwif->tp_ops->tf_read(drive, &cmd); | |
263 | - | |
264 | - *bcount = (cmd.tf.lbah << 8) | cmd.tf.lbam; | |
265 | - *ireason = cmd.tf.nsect & 3; | |
262 | + *bcount = (tf.lbah << 8) | tf.lbam; | |
263 | + *ireason = tf.nsect & 3; | |
266 | 264 | } |
267 | 265 | EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason); |
268 | 266 | |
269 | 267 | |
270 | 268 | |
... | ... | @@ -452,14 +450,11 @@ |
452 | 450 | |
453 | 451 | static u8 ide_read_ireason(ide_drive_t *drive) |
454 | 452 | { |
455 | - struct ide_cmd cmd; | |
453 | + struct ide_taskfile tf; | |
456 | 454 | |
457 | - memset(&cmd, 0, sizeof(cmd)); | |
458 | - cmd.valid.in.tf = IDE_VALID_NSECT; | |
455 | + drive->hwif->tp_ops->tf_read(drive, &tf, IDE_VALID_NSECT); | |
459 | 456 | |
460 | - drive->hwif->tp_ops->tf_read(drive, &cmd); | |
461 | - | |
462 | - return cmd.tf.nsect & 3; | |
457 | + return tf.nsect & 3; | |
463 | 458 | } |
464 | 459 | |
465 | 460 | static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason) |
drivers/ide/ide-io-std.c
... | ... | @@ -112,13 +112,11 @@ |
112 | 112 | } |
113 | 113 | EXPORT_SYMBOL_GPL(ide_tf_load); |
114 | 114 | |
115 | -void ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd) | |
115 | +void ide_tf_read(ide_drive_t *drive, struct ide_taskfile *tf, u8 valid) | |
116 | 116 | { |
117 | 117 | ide_hwif_t *hwif = drive->hwif; |
118 | 118 | struct ide_io_ports *io_ports = &hwif->io_ports; |
119 | - struct ide_taskfile *tf = &cmd->tf; | |
120 | 119 | u8 (*tf_inb)(unsigned long port); |
121 | - u8 valid = cmd->valid.in.tf; | |
122 | 120 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; |
123 | 121 | |
124 | 122 | if (mmio) |
... | ... | @@ -126,9 +124,6 @@ |
126 | 124 | else |
127 | 125 | tf_inb = ide_inb; |
128 | 126 | |
129 | - /* be sure we're looking at the low order bits */ | |
130 | - hwif->tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS); | |
131 | - | |
132 | 127 | if (valid & IDE_VALID_ERROR) |
133 | 128 | tf->error = tf_inb(io_ports->feature_addr); |
134 | 129 | if (valid & IDE_VALID_NSECT) |
... | ... | @@ -141,24 +136,6 @@ |
141 | 136 | tf->lbah = tf_inb(io_ports->lbah_addr); |
142 | 137 | if (valid & IDE_VALID_DEVICE) |
143 | 138 | tf->device = tf_inb(io_ports->device_addr); |
144 | - | |
145 | - if (cmd->tf_flags & IDE_TFLAG_LBA48) { | |
146 | - hwif->tp_ops->write_devctl(hwif, ATA_HOB | ATA_DEVCTL_OBS); | |
147 | - | |
148 | - tf = &cmd->hob; | |
149 | - valid = cmd->valid.in.hob; | |
150 | - | |
151 | - if (valid & IDE_VALID_ERROR) | |
152 | - tf->error = tf_inb(io_ports->feature_addr); | |
153 | - if (valid & IDE_VALID_NSECT) | |
154 | - tf->nsect = tf_inb(io_ports->nsect_addr); | |
155 | - if (valid & IDE_VALID_LBAL) | |
156 | - tf->lbal = tf_inb(io_ports->lbal_addr); | |
157 | - if (valid & IDE_VALID_LBAM) | |
158 | - tf->lbam = tf_inb(io_ports->lbam_addr); | |
159 | - if (valid & IDE_VALID_LBAH) | |
160 | - tf->lbah = tf_inb(io_ports->lbah_addr); | |
161 | - } | |
162 | 139 | } |
163 | 140 | EXPORT_SYMBOL_GPL(ide_tf_read); |
164 | 141 |
drivers/ide/ide-io.c
drivers/ide/ide-iops.c
... | ... | @@ -37,14 +37,11 @@ |
37 | 37 | |
38 | 38 | u8 ide_read_error(ide_drive_t *drive) |
39 | 39 | { |
40 | - struct ide_cmd cmd; | |
40 | + struct ide_taskfile tf; | |
41 | 41 | |
42 | - memset(&cmd, 0, sizeof(cmd)); | |
43 | - cmd.valid.in.tf = IDE_VALID_ERROR; | |
42 | + drive->hwif->tp_ops->tf_read(drive, &tf, IDE_VALID_ERROR); | |
44 | 43 | |
45 | - drive->hwif->tp_ops->tf_read(drive, &cmd); | |
46 | - | |
47 | - return cmd.tf.error; | |
44 | + return tf.error; | |
48 | 45 | } |
49 | 46 | EXPORT_SYMBOL_GPL(ide_read_error); |
50 | 47 |
drivers/ide/ide-lib.c
drivers/ide/ide-probe.c
... | ... | @@ -335,14 +335,11 @@ |
335 | 335 | |
336 | 336 | static u8 ide_read_device(ide_drive_t *drive) |
337 | 337 | { |
338 | - struct ide_cmd cmd; | |
338 | + struct ide_taskfile tf; | |
339 | 339 | |
340 | - memset(&cmd, 0, sizeof(cmd)); | |
341 | - cmd.valid.in.tf = IDE_VALID_DEVICE; | |
340 | + drive->hwif->tp_ops->tf_read(drive, &tf, IDE_VALID_DEVICE); | |
342 | 341 | |
343 | - drive->hwif->tp_ops->tf_read(drive, &cmd); | |
344 | - | |
345 | - return cmd.tf.device; | |
342 | + return tf.device; | |
346 | 343 | } |
347 | 344 | |
348 | 345 | /** |
drivers/ide/ide-taskfile.c
... | ... | @@ -23,6 +23,23 @@ |
23 | 23 | #include <asm/uaccess.h> |
24 | 24 | #include <asm/io.h> |
25 | 25 | |
26 | +void ide_tf_readback(ide_drive_t *drive, struct ide_cmd *cmd) | |
27 | +{ | |
28 | + ide_hwif_t *hwif = drive->hwif; | |
29 | + const struct ide_tp_ops *tp_ops = hwif->tp_ops; | |
30 | + | |
31 | + /* Be sure we're looking at the low order bytes */ | |
32 | + tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS); | |
33 | + | |
34 | + tp_ops->tf_read(drive, &cmd->tf, cmd->valid.in.tf); | |
35 | + | |
36 | + if (cmd->tf_flags & IDE_TFLAG_LBA48) { | |
37 | + tp_ops->write_devctl(hwif, ATA_HOB | ATA_DEVCTL_OBS); | |
38 | + | |
39 | + tp_ops->tf_read(drive, &cmd->hob, cmd->valid.in.hob); | |
40 | + } | |
41 | +} | |
42 | + | |
26 | 43 | void ide_tf_dump(const char *s, struct ide_cmd *cmd) |
27 | 44 | { |
28 | 45 | #ifdef DEBUG |
drivers/ide/ns87415.c
... | ... | @@ -61,15 +61,11 @@ |
61 | 61 | return superio_ide_inb(hwif->dma_base + ATA_DMA_STATUS); |
62 | 62 | } |
63 | 63 | |
64 | -static void superio_tf_read(ide_drive_t *drive, struct ide_cmd *cmd) | |
64 | +static void superio_tf_read(ide_drive_t *drive, struct ide_taskfile *tf, | |
65 | + u8 valid) | |
65 | 66 | { |
66 | 67 | struct ide_io_ports *io_ports = &drive->hwif->io_ports; |
67 | - struct ide_taskfile *tf = &cmd->tf; | |
68 | - u8 valid = cmd->valid.in.tf; | |
69 | 68 | |
70 | - /* be sure we're looking at the low order bits */ | |
71 | - ide_write_devctl(hwif, ATA_DEVCTL_OBS); | |
72 | - | |
73 | 69 | if (valid & IDE_VALID_ERROR) |
74 | 70 | tf->error = inb(io_ports->feature_addr); |
75 | 71 | if (valid & IDE_VALID_NSECT) |
... | ... | @@ -82,24 +78,6 @@ |
82 | 78 | tf->lbah = inb(io_ports->lbah_addr); |
83 | 79 | if (valid & IDE_VALID_DEVICE) |
84 | 80 | tf->device = superio_ide_inb(io_ports->device_addr); |
85 | - | |
86 | - if (cmd->tf_flags & IDE_TFLAG_LBA48) { | |
87 | - ide_write_devctl(hwif, ATA_HOB | ATA_DEVCTL_OBS); | |
88 | - | |
89 | - tf = &cmd->hob; | |
90 | - valid = cmd->valid.in.hob; | |
91 | - | |
92 | - if (valid & IDE_VALID_ERROR) | |
93 | - tf->error = inb(io_ports->feature_addr); | |
94 | - if (valid & IDE_VALID_NSECT) | |
95 | - tf->nsect = inb(io_ports->nsect_addr); | |
96 | - if (valid & IDE_VALID_LBAL) | |
97 | - tf->lbal = inb(io_ports->lbal_addr); | |
98 | - if (valid & IDE_VALID_LBAM) | |
99 | - tf->lbam = inb(io_ports->lbam_addr); | |
100 | - if (valid & IDE_VALID_LBAH) | |
101 | - tf->lbah = inb(io_ports->lbah_addr); | |
102 | - } | |
103 | 81 | } |
104 | 82 | |
105 | 83 | static void ns87415_dev_select(ide_drive_t *drive); |
drivers/ide/scc_pata.c
... | ... | @@ -663,15 +663,10 @@ |
663 | 663 | scc_ide_outb(tf->device, io_ports->device_addr); |
664 | 664 | } |
665 | 665 | |
666 | -static void scc_tf_read(ide_drive_t *drive, struct ide_cmd *cmd) | |
666 | +static void scc_tf_read(ide_drive_t *drive, struct ide_taskfile *tf, u8 valid) | |
667 | 667 | { |
668 | 668 | struct ide_io_ports *io_ports = &drive->hwif->io_ports; |
669 | - struct ide_taskfile *tf = &cmd->tf; | |
670 | - u8 valid = cmd->valid.in.tf; | |
671 | 669 | |
672 | - /* be sure we're looking at the low order bits */ | |
673 | - scc_write_devctl(hwif, ATA_DEVCTL_OBS); | |
674 | - | |
675 | 670 | if (valid & IDE_VALID_ERROR) |
676 | 671 | tf->error = scc_ide_inb(io_ports->feature_addr); |
677 | 672 | if (valid & IDE_VALID_NSECT) |
... | ... | @@ -684,24 +679,6 @@ |
684 | 679 | tf->lbah = scc_ide_inb(io_ports->lbah_addr); |
685 | 680 | if (valid & IDE_VALID_DEVICE) |
686 | 681 | tf->device = scc_ide_inb(io_ports->device_addr); |
687 | - | |
688 | - if (cmd->tf_flags & IDE_TFLAG_LBA48) { | |
689 | - scc_write_devctl(hwif, ATA_HOB | ATA_DEVCTL_OBS); | |
690 | - | |
691 | - tf = &cmd->hob; | |
692 | - valid = cmd->valid.in.hob; | |
693 | - | |
694 | - if (valid & IDE_VALID_ERROR) | |
695 | - tf->error = scc_ide_inb(io_ports->feature_addr); | |
696 | - if (valid & IDE_VALID_NSECT) | |
697 | - tf->nsect = scc_ide_inb(io_ports->nsect_addr); | |
698 | - if (valid & IDE_VALID_LBAL) | |
699 | - tf->lbal = scc_ide_inb(io_ports->lbal_addr); | |
700 | - if (valid & IDE_VALID_LBAM) | |
701 | - tf->lbam = scc_ide_inb(io_ports->lbam_addr); | |
702 | - if (valid & IDE_VALID_LBAH) | |
703 | - tf->lbah = scc_ide_inb(io_ports->lbah_addr); | |
704 | - } | |
705 | 682 | } |
706 | 683 | |
707 | 684 | static void scc_input_data(ide_drive_t *drive, struct ide_cmd *cmd, |
include/linux/ide.h
... | ... | @@ -625,7 +625,7 @@ |
625 | 625 | |
626 | 626 | void (*dev_select)(ide_drive_t *); |
627 | 627 | void (*tf_load)(ide_drive_t *, struct ide_taskfile *, u8); |
628 | - void (*tf_read)(ide_drive_t *, struct ide_cmd *); | |
628 | + void (*tf_read)(ide_drive_t *, struct ide_taskfile *, u8); | |
629 | 629 | |
630 | 630 | void (*input_data)(ide_drive_t *, struct ide_cmd *, |
631 | 631 | void *, unsigned int); |
... | ... | @@ -1124,6 +1124,7 @@ |
1124 | 1124 | void ide_complete_cmd(ide_drive_t *, struct ide_cmd *, u8, u8); |
1125 | 1125 | int ide_complete_rq(ide_drive_t *, int, unsigned int); |
1126 | 1126 | |
1127 | +void ide_tf_readback(ide_drive_t *drive, struct ide_cmd *cmd); | |
1127 | 1128 | void ide_tf_dump(const char *, struct ide_cmd *); |
1128 | 1129 | |
1129 | 1130 | void ide_exec_command(ide_hwif_t *, u8); |
... | ... | @@ -1133,7 +1134,7 @@ |
1133 | 1134 | |
1134 | 1135 | void ide_dev_select(ide_drive_t *); |
1135 | 1136 | void ide_tf_load(ide_drive_t *, struct ide_taskfile *, u8); |
1136 | -void ide_tf_read(ide_drive_t *, struct ide_cmd *); | |
1137 | +void ide_tf_read(ide_drive_t *, struct ide_taskfile *, u8); | |
1137 | 1138 | |
1138 | 1139 | void ide_input_data(ide_drive_t *, struct ide_cmd *, void *, unsigned int); |
1139 | 1140 | void ide_output_data(ide_drive_t *, struct ide_cmd *, void *, unsigned int); |