[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/7] hw/ide/core: Replace magic '512' value by BDRV_SECTOR_SIZE
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 3/7] hw/ide/core: Replace magic '512' value by BDRV_SECTOR_SIZE |
Date: |
Fri, 14 Aug 2020 10:28:37 +0200 |
Use self-explicit definitions instead of magic '512' value.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/ide/core.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index f76f7e5234..bcb2aa85fc 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -121,7 +121,7 @@ static void ide_identify(IDEState *s)
put_le16(p + 0, 0x0040);
put_le16(p + 1, s->cylinders);
put_le16(p + 3, s->heads);
- put_le16(p + 4, 512 * s->sectors); /* XXX: retired, remove ? */
+ put_le16(p + 4, BDRV_SECTOR_SIZE * s->sectors); /* XXX: retired, remove ?
*/
put_le16(p + 5, 512); /* XXX: retired, remove ? */
put_le16(p + 6, s->sectors);
padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */
@@ -864,7 +864,7 @@ static void ide_dma_cb(void *opaque, int ret)
}
}
- if (s->io_buffer_size > s->nsector * 512) {
+ if (s->io_buffer_size > s->nsector * BDRV_SECTOR_SIZE) {
/*
* The PRDs were longer than needed for this request.
* The Active bit must remain set after the request completes.
@@ -877,7 +877,7 @@ static void ide_dma_cb(void *opaque, int ret)
sector_num = ide_get_sector(s);
if (n > 0) {
- assert(n * 512 == s->sg.size);
+ assert(n * BDRV_SECTOR_SIZE == s->sg.size);
dma_buf_commit(s, s->sg.size);
sector_num += n;
ide_set_sector(s, sector_num);
@@ -894,17 +894,17 @@ static void ide_dma_cb(void *opaque, int ret)
/* launch next transfer */
n = s->nsector;
s->io_buffer_index = 0;
- s->io_buffer_size = n * 512;
+ s->io_buffer_size = n * BDRV_SECTOR_SIZE;
prep_size = s->bus->dma->ops->prepare_buf(s->bus->dma, s->io_buffer_size);
/* prepare_buf() must succeed and respect the limit */
- assert(prep_size >= 0 && prep_size <= n * 512);
+ assert(prep_size >= 0 && prep_size <= n * BDRV_SECTOR_SIZE);
/*
* Now prep_size stores the number of bytes in the sglist, and
* s->io_buffer_size stores the number of bytes described by the PRDs.
*/
- if (prep_size < n * 512) {
+ if (prep_size < n * BDRV_SECTOR_SIZE) {
/*
* The PRDs are too short for this request. Error condition!
* Reset the Active bit and don't raise the interrupt.
@@ -1412,7 +1412,8 @@ static bool cmd_identify(IDEState *s, uint8_t cmd)
ide_cfata_identify(s);
}
s->status = READY_STAT | SEEK_STAT;
- ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop);
+ ide_transfer_start(s, s->io_buffer, BDRV_SECTOR_SIZE,
+ ide_transfer_stop);
ide_set_irq(s->bus);
return false;
} else {
@@ -1482,7 +1483,7 @@ static bool cmd_write_multiple(IDEState *s, uint8_t cmd)
n = MIN(s->nsector, s->req_nb_sectors);
s->status = SEEK_STAT | READY_STAT;
- ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_write);
+ ide_transfer_start(s, s->io_buffer, BDRV_SECTOR_SIZE * n,
ide_sector_write);
s->media_changed = 1;
@@ -1524,7 +1525,7 @@ static bool cmd_write_pio(IDEState *s, uint8_t cmd)
s->req_nb_sectors = 1;
s->status = SEEK_STAT | READY_STAT;
- ide_transfer_start(s, s->io_buffer, 512, ide_sector_write);
+ ide_transfer_start(s, s->io_buffer, BDRV_SECTOR_SIZE, ide_sector_write);
s->media_changed = 1;
@@ -1678,7 +1679,7 @@ static bool cmd_identify_packet(IDEState *s, uint8_t cmd)
{
ide_atapi_identify(s);
s->status = READY_STAT | SEEK_STAT;
- ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop);
+ ide_transfer_start(s, s->io_buffer, BDRV_SECTOR_SIZE, ide_transfer_stop);
ide_set_irq(s->bus);
return false;
}
@@ -2559,7 +2560,7 @@ static void ide_init1(IDEBus *bus, int unit)
s->unit = unit;
s->drive_serial = drive_serial++;
/* we need at least 2k alignment for accessing CDROMs using O_DIRECT */
- s->io_buffer_total_len = IDE_DMA_BUF_SECTORS*512 + 4;
+ s->io_buffer_total_len = IDE_DMA_BUF_SECTORS * BDRV_SECTOR_SIZE + 4;
s->io_buffer = qemu_memalign(2048, s->io_buffer_total_len);
memset(s->io_buffer, 0, s->io_buffer_total_len);
--
2.21.3
- [PATCH 0/7] block: Use definitions instead of magic values, Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 1/7] block/null: Make more explicit the driver default size is 1GiB, Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 2/7] hw/ide/core: Trivial typo fix, Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 3/7] hw/ide/core: Replace magic '512' value by BDRV_SECTOR_SIZE,
Philippe Mathieu-Daudé <=
- [PATCH 4/7] hw/ide/ahci: Replace magic '512' value by BDRV_SECTOR_SIZE, Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 5/7] hw/ide/atapi: Replace magic '512' value by BDRV_SECTOR_SIZE, Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 6/7] hw/ide/pci: Replace magic '512' value by BDRV_SECTOR_SIZE, Philippe Mathieu-Daudé, 2020/08/14