Skip to content

Commit

Permalink
hw/ide: Extract bmdma_status_writeb()
Browse files Browse the repository at this point in the history
Every TYPE_PCI_IDE device performs the same not-so-trivial bit manipulation by
copy'n'paste code. Extract this into bmdma_status_writeb(), mirroring
bmdma_cmd_writeb().

Signed-off-by: Bernhard Beschow <shentey@gmail.com>
Reviewed-by: BALATON Zoltan <balaton@eik.bme.hu>
Message-Id: <20230531211043.41724-6-shentey@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
  • Loading branch information
shentok authored and philmd committed Jul 10, 2023
1 parent bf0576e commit 5fe2421
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion hw/ide/cmd646.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static void bmdma_write(void *opaque, hwaddr addr,
cmd646_update_irq(pci_dev);
break;
case 2:
bm->status = (val & 0x60) | (bm->status & 1) | (bm->status & ~val & 0x06);
bmdma_status_writeb(bm, val);
break;
case 3:
if (bm == &bm->pci_dev->bmdma[0]) {
Expand Down
5 changes: 5 additions & 0 deletions hw/ide/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ void bmdma_cmd_writeb(BMDMAState *bm, uint32_t val)
bm->cmd = val & 0x09;
}

void bmdma_status_writeb(BMDMAState *bm, uint32_t val)
{
bm->status = (val & 0x60) | (bm->status & 1) | (bm->status & ~val & 0x06);
}

static uint64_t bmdma_addr_read(void *opaque, hwaddr addr,
unsigned width)
{
Expand Down
2 changes: 1 addition & 1 deletion hw/ide/piix.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void bmdma_write(void *opaque, hwaddr addr,
bmdma_cmd_writeb(bm, val);
break;
case 2:
bm->status = (val & 0x60) | (bm->status & 1) | (bm->status & ~val & 0x06);
bmdma_status_writeb(bm, val);
break;
}
}
Expand Down
6 changes: 2 additions & 4 deletions hw/ide/sii3112.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ static void sii3112_reg_write(void *opaque, hwaddr addr,
break;
case 0x02:
case 0x12:
d->i.bmdma[0].status = (val & 0x60) | (d->i.bmdma[0].status & 1) |
(d->i.bmdma[0].status & ~val & 6);
bmdma_status_writeb(&d->i.bmdma[0], val);
break;
case 0x04 ... 0x07:
bmdma_addr_ioport_ops.write(&d->i.bmdma[0], addr - 4, val, size);
Expand All @@ -165,8 +164,7 @@ static void sii3112_reg_write(void *opaque, hwaddr addr,
break;
case 0x0a:
case 0x1a:
d->i.bmdma[1].status = (val & 0x60) | (d->i.bmdma[1].status & 1) |
(d->i.bmdma[1].status & ~val & 6);
bmdma_status_writeb(&d->i.bmdma[1], val);
break;
case 0x0c ... 0x0f:
bmdma_addr_ioport_ops.write(&d->i.bmdma[1], addr - 12, val, size);
Expand Down
2 changes: 1 addition & 1 deletion hw/ide/via.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void bmdma_write(void *opaque, hwaddr addr,
bmdma_cmd_writeb(bm, val);
break;
case 2:
bm->status = (val & 0x60) | (bm->status & 1) | (bm->status & ~val & 0x06);
bmdma_status_writeb(bm, val);
break;
default:;
}
Expand Down
1 change: 1 addition & 0 deletions include/hw/ide/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct PCIIDEState {

void bmdma_init(IDEBus *bus, BMDMAState *bm, PCIIDEState *d);
void bmdma_cmd_writeb(BMDMAState *bm, uint32_t val);
void bmdma_status_writeb(BMDMAState *bm, uint32_t val);
extern MemoryRegionOps bmdma_addr_ioport_ops;
void pci_ide_create_devs(PCIDevice *dev);

Expand Down

0 comments on commit 5fe2421

Please sign in to comment.