From: Liav Albani <liavalb@gmail.com>
To: qemu-devel@nongnu.org
Cc: jsnow@redhat.com, Liav Albani <liavalb@gmail.com>, qemu-block@nongnu.org
Subject: [PATCH 1/1] hw/ide: share bmdma read and write functions between piix.c and via.c
Date: Sat, 19 Feb 2022 10:08:18 +0200 [thread overview]
Message-ID: <20220219080818.327683-2-liavalb@gmail.com> (raw)
In-Reply-To: <20220219080818.327683-1-liavalb@gmail.com>
Instead of letting each implementation to duplicate this code, we can
share these functions between IDE PIIX3/4 and VIA implementations.
Signed-off-by: Liav Albani <liavalb@gmail.com>
---
hw/ide/pci.c | 47 ++++++++++++++++++++++++++++++++++++++++
hw/ide/piix.c | 50 ++-----------------------------------------
hw/ide/via.c | 51 ++------------------------------------------
include/hw/ide/pci.h | 4 ++++
4 files changed, 55 insertions(+), 97 deletions(-)
diff --git a/hw/ide/pci.c b/hw/ide/pci.c
index 84ba733548..c8b867659a 100644
--- a/hw/ide/pci.c
+++ b/hw/ide/pci.c
@@ -502,6 +502,53 @@ static const struct IDEDMAOps bmdma_ops = {
.reset = bmdma_reset,
};
+uint64_t bmdma_default_read(void *opaque, hwaddr addr,
+ unsigned size)
+{
+ BMDMAState *bm = opaque;
+ uint32_t val;
+
+ if (size != 1) {
+ return ((uint64_t)1 << (size * 8)) - 1;
+ }
+
+ switch (addr & 3) {
+ case 0:
+ val = bm->cmd;
+ break;
+ case 2:
+ val = bm->status;
+ break;
+ default:
+ val = 0xff;
+ break;
+ }
+
+ trace_bmdma_read_via(addr, val);
+ return val;
+}
+
+void bmdma_default_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+ BMDMAState *bm = opaque;
+
+ if (size != 1) {
+ return;
+ }
+
+ trace_bmdma_write_via(addr, val);
+ switch (addr & 3) {
+ case 0:
+ bmdma_cmd_writeb(bm, val);
+ break;
+ case 2:
+ bm->status = (val & 0x60) | (bm->status & 1) | (bm->status & ~val & 0x06);
+ break;
+ default:;
+ }
+}
+
void bmdma_init(IDEBus *bus, BMDMAState *bm, PCIIDEState *d)
{
if (bus->dma == &bm->dma) {
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index ce89fd0aa3..fdf3a04cb1 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -35,55 +35,9 @@
#include "hw/ide/pci.h"
#include "trace.h"
-static uint64_t bmdma_read(void *opaque, hwaddr addr, unsigned size)
-{
- BMDMAState *bm = opaque;
- uint32_t val;
-
- if (size != 1) {
- return ((uint64_t)1 << (size * 8)) - 1;
- }
-
- switch(addr & 3) {
- case 0:
- val = bm->cmd;
- break;
- case 2:
- val = bm->status;
- break;
- default:
- val = 0xff;
- break;
- }
-
- trace_bmdma_read(addr, val);
- return val;
-}
-
-static void bmdma_write(void *opaque, hwaddr addr,
- uint64_t val, unsigned size)
-{
- BMDMAState *bm = opaque;
-
- if (size != 1) {
- return;
- }
-
- trace_bmdma_write(addr, val);
-
- switch(addr & 3) {
- case 0:
- bmdma_cmd_writeb(bm, val);
- break;
- case 2:
- bm->status = (val & 0x60) | (bm->status & 1) | (bm->status & ~val & 0x06);
- break;
- }
-}
-
static const MemoryRegionOps piix_bmdma_ops = {
- .read = bmdma_read,
- .write = bmdma_write,
+ .read = bmdma_default_read,
+ .write = bmdma_default_write,
};
static void bmdma_setup_bar(PCIIDEState *d)
diff --git a/hw/ide/via.c b/hw/ide/via.c
index 82def819c4..13f27c9514 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -33,56 +33,9 @@
#include "hw/ide/pci.h"
#include "trace.h"
-static uint64_t bmdma_read(void *opaque, hwaddr addr,
- unsigned size)
-{
- BMDMAState *bm = opaque;
- uint32_t val;
-
- if (size != 1) {
- return ((uint64_t)1 << (size * 8)) - 1;
- }
-
- switch (addr & 3) {
- case 0:
- val = bm->cmd;
- break;
- case 2:
- val = bm->status;
- break;
- default:
- val = 0xff;
- break;
- }
-
- trace_bmdma_read_via(addr, val);
- return val;
-}
-
-static void bmdma_write(void *opaque, hwaddr addr,
- uint64_t val, unsigned size)
-{
- BMDMAState *bm = opaque;
-
- if (size != 1) {
- return;
- }
-
- trace_bmdma_write_via(addr, val);
- switch (addr & 3) {
- case 0:
- bmdma_cmd_writeb(bm, val);
- break;
- case 2:
- bm->status = (val & 0x60) | (bm->status & 1) | (bm->status & ~val & 0x06);
- break;
- default:;
- }
-}
-
static const MemoryRegionOps via_bmdma_ops = {
- .read = bmdma_read,
- .write = bmdma_write,
+ .read = bmdma_default_read,
+ .write = bmdma_default_write,
};
static void bmdma_setup_bar(PCIIDEState *d)
diff --git a/include/hw/ide/pci.h b/include/hw/ide/pci.h
index d8384e1c42..159136f055 100644
--- a/include/hw/ide/pci.h
+++ b/include/hw/ide/pci.h
@@ -62,6 +62,10 @@ static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
}
void bmdma_init(IDEBus *bus, BMDMAState *bm, PCIIDEState *d);
+uint64_t bmdma_default_read(void *opaque, hwaddr addr,
+ unsigned size);
+void bmdma_default_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size);
void bmdma_cmd_writeb(BMDMAState *bm, uint32_t val);
extern MemoryRegionOps bmdma_addr_ioport_ops;
void pci_ide_create_devs(PCIDevice *dev);
--
2.35.1
next prev parent reply other threads:[~2022-02-19 8:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-19 8:08 [PATCH 0/1] hw/ide: share bmdma read and write functions Liav Albani
2022-02-19 8:08 ` Liav Albani [this message]
2022-02-19 11:19 ` [PATCH 1/1] hw/ide: share bmdma read and write functions between piix.c and via.c BALATON Zoltan
2022-02-19 13:05 ` Liav Albani
2022-02-19 14:32 ` BALATON Zoltan
2022-02-19 15:57 ` BALATON Zoltan
2022-02-19 17:11 ` Liav Albani
2022-02-19 18:10 ` BALATON Zoltan
2022-09-06 14:26 ` [PATCH 0/1] hw/ide: share bmdma read and write functions Bernhard Beschow
2023-01-09 19:24 ` John Snow
2023-01-10 23:07 ` Bernhard Beschow
[not found] ` <7e7bf877-0300-7a2e-e0a4-f8db6eeae88b@gmail.com>
2023-01-16 20:29 ` John Snow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220219080818.327683-2-liavalb@gmail.com \
--to=liavalb@gmail.com \
--cc=jsnow@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).