From ec150c7e09071bcf51bfaa8071fe23efb6df69f7 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 12 Aug 2019 07:23:31 +0200 Subject: include: Make headers more self-contained Back in 2016, we discussed[1] rules for headers, and these were generally liked: 1. Have a carefully curated header that's included everywhere first. We got that already thanks to Peter: osdep.h. 2. Headers should normally include everything they need beyond osdep.h. If exceptions are needed for some reason, they must be documented in the header. If all that's needed from a header is typedefs, put those into qemu/typedefs.h instead of including the header. 3. Cyclic inclusion is forbidden. This patch gets include/ closer to obeying 2. It's actually extracted from my "[RFC] Baby steps towards saner headers" series[2], which demonstrates a possible path towards checking 2 automatically. It passes the RFC test there. [1] Message-ID: <87h9g8j57d.fsf@blackfin.pond.sub.org> https://lists.nongnu.org/archive/html/qemu-devel/2016-03/msg03345.html [2] Message-Id: <20190711122827.18970-1-armbru@redhat.com> https://lists.nongnu.org/archive/html/qemu-devel/2019-07/msg02715.html Signed-off-by: Markus Armbruster Reviewed-by: Alistair Francis Message-Id: <20190812052359.30071-2-armbru@redhat.com> Tested-by: Philippe Mathieu-Daudé --- include/exec/cputlb.h | 3 +++ include/exec/exec-all.h | 1 + include/exec/ioport.h | 2 ++ include/exec/memory-internal.h | 2 ++ include/exec/ram_addr.h | 1 + include/exec/softmmu-semi.h | 2 ++ include/exec/tb-hash.h | 2 ++ include/exec/user/thunk.h | 2 ++ 8 files changed, 15 insertions(+) (limited to 'include/exec') diff --git a/include/exec/cputlb.h b/include/exec/cputlb.h index 5373188be3..a62cfb28d5 100644 --- a/include/exec/cputlb.h +++ b/include/exec/cputlb.h @@ -16,9 +16,12 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see . */ + #ifndef CPUTLB_H #define CPUTLB_H +#include "exec/cpu-common.h" + #if !defined(CONFIG_USER_ONLY) /* cputlb.c */ void tlb_protect_code(ram_addr_t ram_addr); diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 16034ee651..135aeaab0d 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -20,6 +20,7 @@ #ifndef EXEC_ALL_H #define EXEC_ALL_H +#include "cpu.h" #include "exec/tb-context.h" #include "sysemu/cpus.h" diff --git a/include/exec/ioport.h b/include/exec/ioport.h index a298b89ce1..97feb296d2 100644 --- a/include/exec/ioport.h +++ b/include/exec/ioport.h @@ -24,6 +24,8 @@ #ifndef IOPORT_H #define IOPORT_H +#include "exec/memory.h" + #define MAX_IOPORTS (64 * 1024) #define IOPORTS_MASK (MAX_IOPORTS - 1) diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h index d1a9dd1ec8..ef4fb92371 100644 --- a/include/exec/memory-internal.h +++ b/include/exec/memory-internal.h @@ -20,6 +20,8 @@ #ifndef MEMORY_INTERNAL_H #define MEMORY_INTERNAL_H +#include "cpu.h" + #ifndef CONFIG_USER_ONLY static inline AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv) { diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index b7b2e60ff6..a327a80cfe 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -20,6 +20,7 @@ #define RAM_ADDR_H #ifndef CONFIG_USER_ONLY +#include "cpu.h" #include "hw/xen/xen.h" #include "sysemu/tcg.h" #include "exec/ramlist.h" diff --git a/include/exec/softmmu-semi.h b/include/exec/softmmu-semi.h index 970837992e..fbcae88f4b 100644 --- a/include/exec/softmmu-semi.h +++ b/include/exec/softmmu-semi.h @@ -10,6 +10,8 @@ #ifndef SOFTMMU_SEMI_H #define SOFTMMU_SEMI_H +#include "cpu.h" + static inline uint64_t softmmu_tget64(CPUArchState *env, target_ulong addr) { uint64_t val; diff --git a/include/exec/tb-hash.h b/include/exec/tb-hash.h index 4f3a37d927..805235d321 100644 --- a/include/exec/tb-hash.h +++ b/include/exec/tb-hash.h @@ -20,6 +20,8 @@ #ifndef EXEC_TB_HASH_H #define EXEC_TB_HASH_H +#include "exec/cpu-defs.h" +#include "exec/exec-all.h" #include "qemu/xxhash.h" #ifdef CONFIG_SOFTMMU diff --git a/include/exec/user/thunk.h b/include/exec/user/thunk.h index 8d3af5a3be..eae2c27f99 100644 --- a/include/exec/user/thunk.h +++ b/include/exec/user/thunk.h @@ -16,10 +16,12 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see . */ + #ifndef THUNK_H #define THUNK_H #include "cpu.h" +#include "exec/user/abitypes.h" /* types enums definitions */ -- cgit v1.2.3-55-g7522 From 1b53ecd909bc59bb5f54892a5cbb8721a3467ede Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 12 Aug 2019 07:23:34 +0200 Subject: memory: Fix type of IOMMUMemoryRegionClass member @parent_class TYPE_IOMMU_MEMORY_REGION is a direct subtype of TYPE_MEMORY_REGION. Its instance struct is IOMMUMemoryRegion, and its first member is a MemoryRegion. Correct. Its class struct is IOMMUMemoryRegionClass, and its first member is a DeviceClass. Wrong. Messed up when commit 1221a474676 introduced the QOM type. It even included hw/qdev-core.h just for that. TYPE_MEMORY_REGION doesn't bother to define a class struct. This is fine, it simply defaults to its super-type TYPE_OBJECT's class struct ObjectClass. Changing IOMMUMemoryRegionClass's first member's type to ObjectClass would be a minimal fix, if a bit brittle: if TYPE_MEMORY_REGION ever acquired own class struct, we'd have to update IOMMUMemoryRegionClass to use it. Fix it the clean and robust way instead: give TYPE_MEMORY_REGION its own class struct MemoryRegionClass now, and use it for IOMMUMemoryRegionClass's first member. Revert the include of hw/qdev-core.h, and fix the few files that have come to rely on it. Cc: Paolo Bonzini Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Paolo Bonzini Message-Id: <20190812052359.30071-5-armbru@redhat.com> --- hw/display/vga-isa-mm.c | 1 + hw/net/pcnet.h | 1 + include/exec/memory.h | 10 ++++++++-- memory.c | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) (limited to 'include/exec') diff --git a/hw/display/vga-isa-mm.c b/hw/display/vga-isa-mm.c index 215e649719..a790f69b6d 100644 --- a/hw/display/vga-isa-mm.c +++ b/hw/display/vga-isa-mm.c @@ -22,6 +22,7 @@ * THE SOFTWARE. */ #include "qemu/osdep.h" +#include "qemu/bitops.h" #include "qemu/units.h" #include "hw/hw.h" #include "hw/display/vga.h" diff --git a/hw/net/pcnet.h b/hw/net/pcnet.h index 40831a7845..28d19a5c6f 100644 --- a/hw/net/pcnet.h +++ b/hw/net/pcnet.h @@ -8,6 +8,7 @@ #define PCNET_LOOPTEST_NOCRC 2 #include "exec/memory.h" +#include "hw/irq.h" /* BUS CONFIGURATION REGISTERS */ #define BCR_MSRDA 0 diff --git a/include/exec/memory.h b/include/exec/memory.h index bb0961ddb9..d99eb25d2e 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -20,12 +20,12 @@ #include "exec/hwaddr.h" #include "exec/memattrs.h" #include "exec/ramlist.h" +#include "qemu/bswap.h" #include "qemu/queue.h" #include "qemu/int128.h" #include "qemu/notify.h" #include "qom/object.h" #include "qemu/rcu.h" -#include "hw/qdev-core.h" #define RAM_ADDR_INVALID (~(ram_addr_t)0) @@ -205,6 +205,12 @@ struct MemoryRegionOps { } impl; }; +typedef struct MemoryRegionClass { + /* private */ + ObjectClass parent_class; +} MemoryRegionClass; + + enum IOMMUMemoryRegionAttr { IOMMU_ATTR_SPAPR_TCE_FD }; @@ -237,7 +243,7 @@ enum IOMMUMemoryRegionAttr { */ typedef struct IOMMUMemoryRegionClass { /* private */ - struct DeviceClass parent_class; + MemoryRegionClass parent_class; /* * Return a TLB entry that contains a given address. diff --git a/memory.c b/memory.c index 5d8c9a9234..09d9b254fd 100644 --- a/memory.c +++ b/memory.c @@ -3245,6 +3245,7 @@ void memory_region_init_rom_device(MemoryRegion *mr, static const TypeInfo memory_region_info = { .parent = TYPE_OBJECT, .name = TYPE_MEMORY_REGION, + .class_size = sizeof(MemoryRegionClass), .instance_size = sizeof(MemoryRegion), .instance_init = memory_region_initfn, .instance_finalize = memory_region_finalize, -- cgit v1.2.3-55-g7522 From dc5e9ac716c5c5312ab29fb9f311f8176064fe04 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 12 Aug 2019 07:23:49 +0200 Subject: Include qemu/queue.h slightly less Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Message-Id: <20190812052359.30071-20-armbru@redhat.com> --- hw/scsi/vhost-scsi.c | 1 - hw/vfio/ap.c | 1 - include/exec/cpu-defs.h | 1 - include/hw/xen/xen_common.h | 1 - include/net/can_emu.h | 1 + include/net/filter.h | 1 + include/qemu/range.h | 2 -- include/qom/object.h | 1 - include/sysemu/cryptodev.h | 1 + include/sysemu/rng.h | 1 + include/sysemu/sysemu.h | 1 - linux-user/elfload.c | 1 + linux-user/main.c | 1 + linux-user/qemu.h | 1 - linux-user/syscall.c | 1 + nbd/client.c | 1 + nbd/nbd-internal.h | 1 - nbd/server.c | 1 + qapi/qapi-dealloc-visitor.c | 1 - target/i386/whpx-all.c | 1 - ui/kbd-state.c | 1 - util/vfio-helpers.c | 1 - 22 files changed, 9 insertions(+), 14 deletions(-) (limited to 'include/exec') diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 343ca8be7a..83c9d83459 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -20,7 +20,6 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/module.h" -#include "qemu/queue.h" #include "monitor/monitor.h" #include "migration/blocker.h" #include "hw/virtio/vhost-scsi.h" diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index d1c86abb76..2bfc402037 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -20,7 +20,6 @@ #include "hw/s390x/ap-device.h" #include "qemu/error-report.h" #include "qemu/module.h" -#include "qemu/queue.h" #include "qemu/option.h" #include "qemu/config-file.h" #include "cpu.h" diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h index 9bc713a70b..57a9a4ffd9 100644 --- a/include/exec/cpu-defs.h +++ b/include/exec/cpu-defs.h @@ -25,7 +25,6 @@ #include "qemu/host-utils.h" #include "qemu/thread.h" -#include "qemu/queue.h" #ifdef CONFIG_TCG #include "tcg-target.h" #endif diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 1e3ec4e16e..82e56339dd 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -16,7 +16,6 @@ #include "hw/xen/xen.h" #include "hw/pci/pci.h" -#include "qemu/queue.h" #include "hw/xen/trace.h" extern xc_interface *xen_xc; diff --git a/include/net/can_emu.h b/include/net/can_emu.h index 1da4d01b95..d4fc51b57d 100644 --- a/include/net/can_emu.h +++ b/include/net/can_emu.h @@ -28,6 +28,7 @@ #ifndef NET_CAN_EMU_H #define NET_CAN_EMU_H +#include "qemu/queue.h" #include "qom/object.h" /* NOTE: the following two structures is copied from . */ diff --git a/include/net/filter.h b/include/net/filter.h index 9bc6fa3cc6..e8fb6259db 100644 --- a/include/net/filter.h +++ b/include/net/filter.h @@ -10,6 +10,7 @@ #define QEMU_NET_FILTER_H #include "qapi/qapi-types-net.h" +#include "qemu/queue.h" #include "qom/object.h" #include "net/queue.h" diff --git a/include/qemu/range.h b/include/qemu/range.h index 71b8b215c6..f62b363e0d 100644 --- a/include/qemu/range.h +++ b/include/qemu/range.h @@ -20,8 +20,6 @@ #ifndef QEMU_RANGE_H #define QEMU_RANGE_H -#include "qemu/queue.h" - /* * Operations on 64 bit address ranges. * Notes: diff --git a/include/qom/object.h b/include/qom/object.h index 7bb82a7f56..128d00c77f 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -15,7 +15,6 @@ #define QEMU_OBJECT_H #include "qapi/qapi-builtin-types.h" -#include "qemu/queue.h" #include "qemu/module.h" struct TypeImpl; diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index 92bbb79131..a9afb7e5b5 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -23,6 +23,7 @@ #ifndef CRYPTODEV_H #define CRYPTODEV_H +#include "qemu/queue.h" #include "qom/object.h" /** diff --git a/include/sysemu/rng.h b/include/sysemu/rng.h index 2a02f47771..9b22c156f8 100644 --- a/include/sysemu/rng.h +++ b/include/sysemu/rng.h @@ -13,6 +13,7 @@ #ifndef QEMU_RNG_H #define QEMU_RNG_H +#include "qemu/queue.h" #include "qom/object.h" #define TYPE_RNG_BACKEND "rng-backend" diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 984c439ac9..77f5df59b0 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -3,7 +3,6 @@ /* Misc. things related to the system emulator. */ #include "qapi/qapi-types-run-state.h" -#include "qemu/queue.h" #include "qemu/timer.h" #include "qemu/notify.h" #include "qemu/main-loop.h" diff --git a/linux-user/elfload.c b/linux-user/elfload.c index bd43c4817d..3365e192eb 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -8,6 +8,7 @@ #include "qemu.h" #include "disas/disas.h" #include "qemu/path.h" +#include "qemu/queue.h" #include "qemu/guest-random.h" #ifdef _ARCH_PPC64 diff --git a/linux-user/main.c b/linux-user/main.c index 8ffc525195..47917bbb20 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -28,6 +28,7 @@ #include "qapi/error.h" #include "qemu.h" #include "qemu/path.h" +#include "qemu/queue.h" #include "qemu/config-file.h" #include "qemu/cutils.h" #include "qemu/error-report.h" diff --git a/linux-user/qemu.h b/linux-user/qemu.h index aac0334627..f6f5fe5fbb 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -16,7 +16,6 @@ #include "syscall_defs.h" #include "target_syscall.h" #include "exec/gdbstub.h" -#include "qemu/queue.h" /* This is the size of the host kernel's sigset_t, needed where we make * direct system calls that take a sigset_t pointer and a size. diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 8367cb138d..8b41a03901 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "qemu/cutils.h" #include "qemu/path.h" +#include "qemu/queue.h" #include #include #include diff --git a/nbd/client.c b/nbd/client.c index 4de30630c7..d554ae353d 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qemu/queue.h" #include "trace.h" #include "nbd-internal.h" #include "qemu/cutils.h" diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index 049f83df77..ec3d2e2ebc 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -28,7 +28,6 @@ #endif #include "qemu/bswap.h" -#include "qemu/queue.h" #include "qemu/main-loop.h" /* This is all part of the "official" NBD API. diff --git a/nbd/server.c b/nbd/server.c index 10faedcfc5..dbd2ff8555 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qemu/queue.h" #include "trace.h" #include "nbd-internal.h" #include "qemu/units.h" diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index 89ccd905ec..d192724b13 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -15,7 +15,6 @@ #include "qemu/osdep.h" #include "qapi/dealloc-visitor.h" #include "qapi/qmp/qnull.h" -#include "qemu/queue.h" #include "qapi/visitor-impl.h" struct QapiDeallocVisitor diff --git a/target/i386/whpx-all.c b/target/i386/whpx-all.c index ed95105eae..2cf66f7804 100644 --- a/target/i386/whpx-all.c +++ b/target/i386/whpx-all.c @@ -20,7 +20,6 @@ #include "qemu/main-loop.h" #include "hw/boards.h" #include "qemu/error-report.h" -#include "qemu/queue.h" #include "qapi/error.h" #include "migration/blocker.h" #include "whp-dispatch.h" diff --git a/ui/kbd-state.c b/ui/kbd-state.c index 1668d17dda..62d42a7a22 100644 --- a/ui/kbd-state.c +++ b/ui/kbd-state.c @@ -5,7 +5,6 @@ */ #include "qemu/osdep.h" #include "qemu/bitmap.h" -#include "qemu/queue.h" #include "ui/console.h" #include "ui/input.h" #include "ui/kbd-state.h" diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 2367fe8f7f..26ffd0d6b5 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -17,7 +17,6 @@ #include "exec/ramlist.h" #include "exec/cpu-common.h" #include "trace.h" -#include "qemu/queue.h" #include "qemu/error-report.h" #include "standard-headers/linux/pci_regs.h" #include "qemu/event_notifier.h" -- cgit v1.2.3-55-g7522