hw/ide: factor out the IDENTIFY DEVICE current geometry words
Words 54 to 58 of IDENTIFY DEVICE describe the CHS translation in effect and the capacity it addresses. Both ide_identify() and ide_cfata_identify() fill them the same way while building their cached data. Move them into ide_identify_chs(), so that the next change can refresh them in place once the translation changes, the way ide_identify_size() does for the capacity words. No functional change. Cc: John Snow <jsnow@redhat.com> Cc: Peter Maydell <peter.maydell@linaro.org> Cc: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Signed-off-by: Denis V. Lunev <den@openvz.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Denis V. Lunev committed
Aug 14, 2026 at 17:43 UTC
747679ca5981f1d591dc53e076df8a39d3428061
1 file changed
+14
-15
hw/ide/core.c
+14
-15
@@ -110,6 +110,18 @@ static void put_le16(uint16_t *p, unsigned int v)
110
*p = cpu_to_le16(v);
111
}
112
113
+static void ide_identify_chs(IDEState *s)
114
+{
115
+ uint16_t *p = (uint16_t *)s->identify_data;
116
+ unsigned int cur_sec = s->cylinders * s->heads * s->sectors;
117
+
118
+ put_le16(p + 54, s->cylinders);
119
+ put_le16(p + 55, s->heads);
120
+ put_le16(p + 56, s->sectors);
121
+ put_le16(p + 57, cur_sec);
122
+ put_le16(p + 58, cur_sec >> 16);
123
+}
124
+
125
static void ide_identify_size(IDEState *s)
126
{
127
uint16_t *p = (uint16_t *)s->identify_data;
@@ -128,7 +140,6 @@ static void ide_identify_size(IDEState *s)
140
static void ide_identify(IDEState *s)
141
{
142
uint16_t *p;
131
- unsigned int oldsize;
143
IDEDevice *dev = s->unit ? s->bus->slave : s->bus->master;
144
145
p = (uint16_t *)s->identify_data;
@@ -158,12 +169,7 @@ static void ide_identify(IDEState *s)
169
put_le16(p + 51, 0x200); /* PIO transfer cycle */
170
put_le16(p + 52, 0x200); /* DMA transfer cycle */
171
put_le16(p + 53, 1 | (1 << 1) | (1 << 2)); /* words 54-58,64-70,88 are valid */
161
- put_le16(p + 54, s->cylinders);
162
- put_le16(p + 55, s->heads);
163
- put_le16(p + 56, s->sectors);
164
- oldsize = s->cylinders * s->heads * s->sectors;
165
- put_le16(p + 57, oldsize);
166
- put_le16(p + 58, oldsize >> 16);
172
+ ide_identify_chs(s);
173
if (s->mult_sectors)
174
put_le16(p + 59, 0x100 | s->mult_sectors);
175
/* *(p + 60) := nb_sectors -- see ide_identify_size */
@@ -321,7 +327,6 @@ static void ide_cfata_identify_size(IDEState *s)
327
static void ide_cfata_identify(IDEState *s)
328
{
329
uint16_t *p;
324
- uint32_t cur_sec;
330
331
p = (uint16_t *)s->identify_data;
332
if (s->identify_set) {
@@ -329,8 +334,6 @@ static void ide_cfata_identify(IDEState *s)
334
}
335
memset(p, 0, sizeof(s->identify_data));
336
332
- cur_sec = s->cylinders * s->heads * s->sectors;
333
-
337
put_le16(p + 0, 0x848a); /* CF Storage Card signature */
338
put_le16(p + 1, s->cylinders); /* Default cylinders */
339
put_le16(p + 3, s->drive_heads); /* Default heads */
@@ -350,11 +353,7 @@ static void ide_cfata_identify(IDEState *s)
353
put_le16(p + 51, 0x0002); /* PIO cycle timing mode */
354
put_le16(p + 52, 0x0001); /* DMA cycle timing mode */
355
put_le16(p + 53, 0x0003); /* Translation params valid */
353
- put_le16(p + 54, s->cylinders); /* Current cylinders */
354
- put_le16(p + 55, s->heads); /* Current heads */
355
- put_le16(p + 56, s->sectors); /* Current sectors */
356
- put_le16(p + 57, cur_sec); /* Current capacity */
357
- put_le16(p + 58, cur_sec >> 16); /* Current capacity */
356
+ ide_identify_chs(s); /* Current C/H/S and capacity */
357
if (s->mult_sectors) /* Multiple sector setting */
358
put_le16(p + 59, 0x100 | s->mult_sectors);
359
/* *(p + 60) := nb_sectors -- see ide_cfata_identify_size */