Skip to content

Commit 825314c

Browse files
atahd: clean up READ_MULTIPLE/WRITE_MULTIPLE.
1 parent 8d9bc66 commit 825314c

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

devices/common/ata/atahd.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ int AtaHardDisk::perform_command() {
105105
uint64_t offset = this->get_lba() * ATA_HD_SEC_SIZE;
106106
uint32_t ints_size = ATA_HD_SEC_SIZE;
107107
if (this->r_command == READ_MULTIPLE) {
108-
if (this->sec_per_block == 0) {
109-
LOG_F(ERROR, "%s: cannot do a READ_MULTIPLE with unset sec_per_block", this->name.c_str());
108+
if (!this->sectors_per_int) {
109+
LOG_F(ERROR, "%s: READ_MULTIPLE disabled", this->name.c_str());
110110
this->r_status |= ERR;
111111
this->r_status &= ~BSY;
112112
break;
113113
}
114-
ints_size *= this->sec_per_block;
114+
ints_size *= this->sectors_per_int;
115115
}
116116
hdd_img.read(buffer, offset, xfer_size);
117117
this->data_ptr = (uint16_t *)this->buffer;
@@ -130,13 +130,13 @@ int AtaHardDisk::perform_command() {
130130
uint32_t xfer_size = sec_count * ATA_HD_SEC_SIZE;
131131
uint32_t ints_size = ATA_HD_SEC_SIZE;
132132
if (this->r_command == WRITE_MULTIPLE) {
133-
if (this->sec_per_block == 0) {
134-
LOG_F(ERROR, "%s: cannot do a WRITE_MULTIPLE with unset sec_per_block", this->name.c_str());
133+
if (!this->sectors_per_int) {
134+
LOG_F(ERROR, "%s: WRITE_MULTIPLE disabled", this->name.c_str());
135135
this->r_status |= ERR;
136136
this->r_status &= ~BSY;
137137
break;
138138
}
139-
ints_size *= this->sec_per_block;
139+
ints_size *= this->sectors_per_int;
140140
}
141141
this->prepare_xfer(xfer_size, ints_size);
142142
this->post_xfer_action = [this]() {
@@ -154,8 +154,7 @@ int AtaHardDisk::perform_command() {
154154
this->r_status &= ~BSY;
155155
this->update_intrq(1);
156156
break;
157-
case READ_VERIFY:
158-
// verify sectors are readable, just no-op
157+
case READ_VERIFY: // verify sectors are readable, just no-op
159158
this->r_status &= ~BSY;
160159
this->update_intrq(1);
161160
break;
@@ -167,16 +166,16 @@ int AtaHardDisk::perform_command() {
167166
this->update_intrq(1);
168167
break;
169168
case SET_MULTIPLE_MODE: // this command is mandatory for ATA devices
170-
if (!this->r_sect_count || this->r_sect_count > 128 ||
169+
if (!this->r_sect_count || this->r_sect_count > SECTORS_PER_INT ||
171170
std::bitset<8>(this->r_sect_count).count() != 1) { // power of two?
172-
LOG_F(ERROR, "%s: SET_MULTIPLE_MODE not suported, invalid r_sect_count (%d)", this->name.c_str(), this->r_sect_count);
173-
this->multiple_enabled = false;
171+
LOG_F(ERROR, "%s: invalid parameter %d for SET_MULTIPLE_MODE",
172+
this->name.c_str(), this->r_sect_count);
174173
this->r_error |= ABRT;
175174
this->r_status |= ERR;
176175
} else {
177-
LOG_F(INFO, "%s: SET_MULTIPLE_MODE, r_sect_count=%d", this->name.c_str(), this->r_sect_count);
178-
this->sec_per_block = this->r_sect_count;
179-
this->multiple_enabled = true;
176+
LOG_F(9, "%s: SET_MULTIPLE_MODE, r_sect_count=%d", this->name.c_str(),
177+
this->r_sect_count);
178+
this->sectors_per_int = this->r_sect_count;
180179
}
181180
this->r_status &= ~BSY;
182181
this->update_intrq(1);
@@ -242,16 +241,13 @@ void AtaHardDisk::prepare_identify_info() {
242241

243242
// Maximum number of logical sectors per data block that the device supports
244243
// for READ_MULTIPLE/WRITE_MULTIPLE commands.
245-
const int max_sec_per_block = 8;
246-
if (max_sec_per_block > 1) {
247-
buf_ptr[47] = 0x8000 | max_sec_per_block;
248-
}
244+
buf_ptr[47] = 0x8000 | SECTORS_PER_INT;
245+
249246
// If bit 8 of word 59 is set to one, then bits 7:0 indicate the number of
250247
// logical sectors that shall be transferred per data block for
251248
// READ_MULTIPLE/WRITE_MULTIPLE commands.
252-
if (this->sec_per_block) {
253-
buf_ptr[59] = 0x100 | this->sec_per_block;
254-
}
249+
if (this->sectors_per_int)
250+
buf_ptr[59] = 0x100 | this->sectors_per_int;
255251

256252
buf_ptr[ 1] = this->cylinders;
257253
buf_ptr[ 3] = this->heads;

devices/common/ata/atahd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
3030
#include <string>
3131

3232
#define ATA_HD_SEC_SIZE 512
33+
#define SECTORS_PER_INT 16
3334

3435
// C:16383 x H:16 x S:63 = C:1032 x H:254 x S:63 = 8063.5078125 MiB = 8.46 GB
3536
#define ATA_BIOS_LIMIT 16514064
@@ -69,8 +70,7 @@ class AtaHardDisk : public AtaBaseDevice
6970
uint8_t heads;
7071
uint8_t sectors;
7172

72-
uint8_t sec_per_block = 0; // sectors per block for READ_MULTIPLE/WRITE_MULTIPLE
73-
bool multiple_enabled = false; // READ_MULTIPLE/WRITE_MULTIPLE enabled
73+
uint8_t sectors_per_int = 0; // sectors per interrupt for READ_MULTIPLE/WRITE_MULTIPLE
7474

7575
char * buffer = new char[1 <<17];
7676
};

0 commit comments

Comments
 (0)