From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Claudio Fontana" <cfontana@suse.de>,
"Laurent Vivier" <laurent@vivier.eu>
Subject: [PATCH 07/11] exec: Extract CPU I/O instructions to "cpu-io.h"
Date: Mon, 17 May 2021 13:11:07 +0200 [thread overview]
Message-ID: <20210517111111.1068153-8-f4bug@amsat.org> (raw)
In-Reply-To: <20210517111111.1068153-1-f4bug@amsat.org>
Not all architectures use an I/O bus. Extract the CPU I/O
instruction helpers into a specific unit named cpu-io.c
(and its equivalent "cpu-io.h" header).
Since what is left in ioport.c is no more target specific,
build the file with the other softmmu objects by moving the
file to the softmmu_ss Meson source set.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/exec/cpu-io.h | 30 +++++++++++
include/exec/ioport.h | 7 ---
hw/i386/xen/xen-hvm.c | 1 +
monitor/misc.c | 2 +-
softmmu/cpu-io.c | 88 +++++++++++++++++++++++++++++++
softmmu/ioport.c | 60 ---------------------
softmmu/qtest.c | 1 +
tests/qtest/fuzz/qtest_wrappers.c | 3 +-
softmmu/meson.build | 3 +-
9 files changed, 125 insertions(+), 70 deletions(-)
create mode 100644 include/exec/cpu-io.h
create mode 100644 softmmu/cpu-io.c
diff --git a/include/exec/cpu-io.h b/include/exec/cpu-io.h
new file mode 100644
index 00000000000..6538c451177
--- /dev/null
+++ b/include/exec/cpu-io.h
@@ -0,0 +1,30 @@
+/*
+ * QEMU CPU I/O instructions
+ *
+ * Copyright (c) 2003 Fabrice Bellard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CPU_IO_H
+#define CPU_IO_H
+
+void cpu_outb(uint32_t addr, uint8_t val);
+void cpu_outw(uint32_t addr, uint16_t val);
+void cpu_outl(uint32_t addr, uint32_t val);
+uint8_t cpu_inb(uint32_t addr);
+uint16_t cpu_inw(uint32_t addr);
+uint32_t cpu_inl(uint32_t addr);
+
+#endif /* CPU_IO_H */
diff --git a/include/exec/ioport.h b/include/exec/ioport.h
index d5ca8abff76..f94f71b19f0 100644
--- a/include/exec/ioport.h
+++ b/include/exec/ioport.h
@@ -44,13 +44,6 @@ typedef struct MemoryRegionPortio {
extern const MemoryRegionOps unassigned_io_ops;
#endif
-void cpu_outb(uint32_t addr, uint8_t val);
-void cpu_outw(uint32_t addr, uint16_t val);
-void cpu_outl(uint32_t addr, uint32_t val);
-uint8_t cpu_inb(uint32_t addr);
-uint16_t cpu_inw(uint32_t addr);
-uint32_t cpu_inl(uint32_t addr);
-
typedef struct PortioList {
const struct MemoryRegionPortio *ports;
Object *owner;
diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
index 9b432773f02..c8de325a809 100644
--- a/hw/i386/xen/xen-hvm.c
+++ b/hw/i386/xen/xen-hvm.c
@@ -33,6 +33,7 @@
#include "sysemu/xen.h"
#include "sysemu/xen-mapcache.h"
#include "trace.h"
+#include "exec/cpu-io.h"
#include <xen/hvm/ioreq.h>
#include <xen/hvm/e820.h>
diff --git a/monitor/misc.c b/monitor/misc.c
index c1fcd995805..60ee9c91a9f 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -76,7 +76,7 @@
#include "qapi/qmp-event.h"
#include "sysemu/cpus.h"
#include "qemu/cutils.h"
-
+#include "exec/cpu-io.h"
#if defined(TARGET_S390X)
#include "hw/s390x/storage-keys.h"
#include "hw/s390x/storage-attributes.h"
diff --git a/softmmu/cpu-io.c b/softmmu/cpu-io.c
new file mode 100644
index 00000000000..98da9d693f9
--- /dev/null
+++ b/softmmu/cpu-io.c
@@ -0,0 +1,88 @@
+/*
+ * QEMU CPU I/O instructions
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "exec/sysemu/address-spaces.h"
+#include "exec/cpu-io.h"
+#include "cpu.h"
+#include "trace.h"
+
+void cpu_outb(uint32_t addr, uint8_t val)
+{
+ trace_cpu_out(addr, 'b', val);
+ address_space_write(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
+ &val, 1);
+}
+
+void cpu_outw(uint32_t addr, uint16_t val)
+{
+ uint8_t buf[2];
+
+ trace_cpu_out(addr, 'w', val);
+ stw_p(buf, val);
+ address_space_write(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
+ buf, 2);
+}
+
+void cpu_outl(uint32_t addr, uint32_t val)
+{
+ uint8_t buf[4];
+
+ trace_cpu_out(addr, 'l', val);
+ stl_p(buf, val);
+ address_space_write(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
+ buf, 4);
+}
+
+uint8_t cpu_inb(uint32_t addr)
+{
+ uint8_t val;
+
+ address_space_read(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
+ &val, 1);
+ trace_cpu_in(addr, 'b', val);
+ return val;
+}
+
+uint16_t cpu_inw(uint32_t addr)
+{
+ uint8_t buf[2];
+ uint16_t val;
+
+ address_space_read(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED, buf, 2);
+ val = lduw_p(buf);
+ trace_cpu_in(addr, 'w', val);
+ return val;
+}
+
+uint32_t cpu_inl(uint32_t addr)
+{
+ uint8_t buf[4];
+ uint32_t val;
+
+ address_space_read(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED, buf, 4);
+ val = ldl_p(buf);
+ trace_cpu_in(addr, 'l', val);
+ return val;
+}
diff --git a/softmmu/ioport.c b/softmmu/ioport.c
index 6ace5ec966a..6f297027cfe 100644
--- a/softmmu/ioport.c
+++ b/softmmu/ioport.c
@@ -26,7 +26,6 @@
*/
#include "qemu/osdep.h"
-#include "cpu.h"
#include "exec/ioport.h"
#include "exec/sysemu/memory.h"
#include "exec/sysemu/address-spaces.h"
@@ -54,65 +53,6 @@ const MemoryRegionOps unassigned_io_ops = {
.endianness = DEVICE_NATIVE_ENDIAN,
};
-void cpu_outb(uint32_t addr, uint8_t val)
-{
- trace_cpu_out(addr, 'b', val);
- address_space_write(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
- &val, 1);
-}
-
-void cpu_outw(uint32_t addr, uint16_t val)
-{
- uint8_t buf[2];
-
- trace_cpu_out(addr, 'w', val);
- stw_p(buf, val);
- address_space_write(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
- buf, 2);
-}
-
-void cpu_outl(uint32_t addr, uint32_t val)
-{
- uint8_t buf[4];
-
- trace_cpu_out(addr, 'l', val);
- stl_p(buf, val);
- address_space_write(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
- buf, 4);
-}
-
-uint8_t cpu_inb(uint32_t addr)
-{
- uint8_t val;
-
- address_space_read(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
- &val, 1);
- trace_cpu_in(addr, 'b', val);
- return val;
-}
-
-uint16_t cpu_inw(uint32_t addr)
-{
- uint8_t buf[2];
- uint16_t val;
-
- address_space_read(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED, buf, 2);
- val = lduw_p(buf);
- trace_cpu_in(addr, 'w', val);
- return val;
-}
-
-uint32_t cpu_inl(uint32_t addr)
-{
- uint8_t buf[4];
- uint32_t val;
-
- address_space_read(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED, buf, 4);
- val = ldl_p(buf);
- trace_cpu_in(addr, 'l', val);
- return val;
-}
-
void portio_list_init(PortioList *piolist,
Object *owner,
const MemoryRegionPortio *callbacks,
diff --git a/softmmu/qtest.c b/softmmu/qtest.c
index f1ee4fbc369..2551296c727 100644
--- a/softmmu/qtest.c
+++ b/softmmu/qtest.c
@@ -31,6 +31,7 @@
#ifdef CONFIG_PSERIES
#include "hw/ppc/spapr_rtas.h"
#endif
+#include "exec/cpu-io.h"
#define MAX_IRQ 256
diff --git a/tests/qtest/fuzz/qtest_wrappers.c b/tests/qtest/fuzz/qtest_wrappers.c
index 0580f8df860..25cf1b72705 100644
--- a/tests/qtest/fuzz/qtest_wrappers.c
+++ b/tests/qtest/fuzz/qtest_wrappers.c
@@ -12,8 +12,9 @@
*/
#include "qemu/osdep.h"
+#include "exec/sysemu/address-spaces.h"
+#include "exec/cpu-io.h"
#include "hw/core/cpu.h"
-#include "exec/ioport.h"
#include "fuzz.h"
diff --git a/softmmu/meson.build b/softmmu/meson.build
index d8e03018abf..ebf063b8990 100644
--- a/softmmu/meson.build
+++ b/softmmu/meson.build
@@ -2,11 +2,11 @@
'arch_init.c',
'balloon.c',
'cpus.c',
+ 'cpu-io.c',
'cpu-throttle.c',
'datadir.c',
'globals.c',
'physmem.c',
- 'ioport.c',
'rtc.c',
'runstate.c',
'memory.c',
@@ -24,6 +24,7 @@
softmmu_ss.add(files(
'bootdevice.c',
'dma-helpers.c',
+ 'ioport.c',
'qdev-monitor.c',
), sdl, libpmem, libdaxctl)
--
2.26.3
next prev parent reply other threads:[~2021-05-17 11:45 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-17 11:11 [PATCH 00/11] exec: Restrict various system emulation specific headers (to sysemu) Philippe Mathieu-Daudé
2021-05-17 11:11 ` [PATCH 01/11] NOTFORMERGE target/arm: Restrict KVM files to softmmu Philippe Mathieu-Daudé
2021-05-17 11:11 ` [PATCH 02/11] exec: Restrict hwaddr.h to sysemu/ Philippe Mathieu-Daudé
2021-05-26 18:15 ` Richard Henderson
2022-12-06 14:32 ` Philippe Mathieu-Daudé
2022-12-06 14:40 ` Philippe Mathieu-Daudé
2022-12-06 14:53 ` Claudio Fontana
2022-12-06 15:38 ` Claudio Fontana
2022-12-06 17:09 ` Philippe Mathieu-Daudé
2022-12-06 17:17 ` Richard Henderson
2022-12-07 10:09 ` Claudio Fontana
2022-12-06 15:01 ` Peter Maydell
2021-05-17 11:11 ` [PATCH 03/11] exec: Restrict cputlb.h " Philippe Mathieu-Daudé
2021-05-17 11:11 ` [PATCH 04/11] exec: Restrict memory.h " Philippe Mathieu-Daudé
2021-05-17 11:11 ` [PATCH 05/11] exec: Restrict memory-internal.h " Philippe Mathieu-Daudé
2021-05-17 11:11 ` [PATCH 06/11] exec: Restrict address-spaces.h " Philippe Mathieu-Daudé
2021-05-17 11:11 ` Philippe Mathieu-Daudé [this message]
2021-05-17 11:11 ` [PATCH 08/11] exec: Restrict ioport.h " Philippe Mathieu-Daudé
2021-05-17 11:11 ` [PATCH 09/11] exec: Restrict ram_addr.h " Philippe Mathieu-Daudé
2021-05-17 11:11 ` [PATCH 10/11] exec: Restrict ramblock.h " Philippe Mathieu-Daudé
2021-05-17 11:11 ` [PATCH 11/11] exec: Restrict confidential-guest-support.h " Philippe Mathieu-Daudé
2021-05-25 14:13 ` [PATCH 00/11] exec: Restrict various system emulation specific headers (to sysemu) Philippe Mathieu-Daudé
2021-11-06 14:58 ` Philippe Mathieu-Daudé
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=20210517111111.1068153-8-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=cfontana@suse.de \
--cc=laurent@vivier.eu \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).