Skip to content

Commit aff2caf

Browse files
committed
Merge remote-tracking branch 'remotes/kraxel/tags/modules-20200707-pull-request' into staging
qom: add support for qom objects in modules. build some devices (qxl, virtio-gpu, ccid, usb-redir) as modules. build braille chardev as module. v2: more verbose comment for "build: fix device module builds" patch. note: qemu doesn't rebuild objects on cflags changes (specifically -fPIC being added when code is switched from builtin to module). Workaround for resulting build errors: "make clean", rebuild. # gpg: Signature made Tue 07 Jul 2020 14:42:16 BST # gpg: using RSA key 4CB6D8EED3E87138 # gpg: Good signature from "Gerd Hoffmann (work) <[email protected]>" [full] # gpg: aka "Gerd Hoffmann <[email protected]>" [full] # gpg: aka "Gerd Hoffmann (private) <[email protected]>" [full] # Primary key fingerprint: A032 8CFF B93A 17A7 9901 FE7D 4CB6 D8EE D3E8 7138 * remotes/kraxel/tags/modules-20200707-pull-request: chardev: enable modules, use for braille vga: build virtio-gpu as module vga: build virtio-gpu only once vga: build qxl as module usb: build usb-redir as module ccid: build smartcard as module build: fix device module builds qdev: device module support object: qom module support module: qom module support Signed-off-by: Peter Maydell <[email protected]>
2 parents 3d7cad3 + ef138c7 commit aff2caf

File tree

15 files changed

+156
-25
lines changed

15 files changed

+156
-25
lines changed

Makefile.objs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ common-obj-y += migration/
5959
common-obj-y += audio/
6060
common-obj-m += audio/
6161
common-obj-y += hw/
62+
common-obj-m += hw/
6263

6364
common-obj-y += replay/
6465

@@ -70,6 +71,7 @@ common-obj-$(CONFIG_TPM) += tpm.o
7071

7172
common-obj-y += backends/
7273
common-obj-y += chardev/
74+
common-obj-m += chardev/
7375

7476
common-obj-$(CONFIG_SECCOMP) += qemu-seccomp.o
7577
qemu-seccomp.o-cflags := $(SECCOMP_CFLAGS)

Makefile.target

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,20 @@ endif # CONFIG_SOFTMMU
179179
dummy := $(call unnest-vars,,obj-y)
180180
all-obj-y := $(obj-y)
181181

182+
#
183+
# common-obj-m has some crap here, probably as side effect from
184+
# unnest-vars recursing into target directories to fill obj-y and not
185+
# properly handling the -m case.
186+
#
187+
# Clear common-obj-m as workaround. Fixes suspious dependency errors
188+
# when building devices as modules. A bit hackish, but should be ok
189+
# as long as we do not have any target-specific modules.
190+
#
191+
# The meson-based build system currently in development doesn't need
192+
# unnest-vars and will obsolete this workaround.
193+
#
194+
common-obj-m :=
195+
182196
include $(SRC_PATH)/Makefile.objs
183197
dummy := $(call unnest-vars,.., \
184198
authz-obj-y \

chardev/Makefile.objs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ chardev-obj-$(CONFIG_WIN32) += char-win.o
1818
chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
1919

2020
common-obj-y += msmouse.o wctablet.o testdev.o
21-
common-obj-$(CONFIG_BRLAPI) += baum.o
21+
22+
ifeq ($(CONFIG_BRLAPI),y)
23+
common-obj-m += baum.o
2224
baum.o-cflags := $(SDL_CFLAGS)
2325
baum.o-libs := $(BRLAPI_LIBS)
26+
endif
2427

2528
common-obj-$(CONFIG_SPICE) += spice.o

chardev/char.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static const ChardevClass *char_get_class(const char *driver, Error **errp)
527527
const ChardevClass *cc;
528528
char *typename = g_strdup_printf("chardev-%s", driver);
529529

530-
oc = object_class_by_name(typename);
530+
oc = module_object_class_by_name(typename);
531531
g_free(typename);
532532

533533
if (!object_class_dynamic_cast(oc, TYPE_CHARDEV)) {

hw/Makefile.objs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ devices-dirs-y += smbios/
4343
endif
4444

4545
common-obj-y += $(devices-dirs-y)
46+
common-obj-m += display/
47+
common-obj-m += usb/
4648
obj-y += $(devices-dirs-y)

hw/core/qdev.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
137137
*/
138138
DeviceState *qdev_new(const char *name)
139139
{
140+
if (!object_class_by_name(name)) {
141+
module_load_qom_one(name);
142+
}
140143
return DEVICE(object_new(name));
141144
}
142145

@@ -147,10 +150,9 @@ DeviceState *qdev_new(const char *name)
147150
*/
148151
DeviceState *qdev_try_new(const char *name)
149152
{
150-
if (!object_class_by_name(name)) {
153+
if (!module_object_class_by_name(name)) {
151154
return NULL;
152155
}
153-
154156
return DEVICE(object_new(name));
155157
}
156158

hw/display/Makefile.objs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,24 @@ common-obj-$(CONFIG_ARTIST) += artist.o
4444

4545
obj-$(CONFIG_VGA) += vga.o
4646

47-
common-obj-$(CONFIG_QXL) += qxl.o qxl-logger.o qxl-render.o
48-
49-
obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu-base.o virtio-gpu.o virtio-gpu-3d.o
50-
obj-$(CONFIG_VHOST_USER_GPU) += vhost-user-gpu.o
51-
obj-$(call land,$(CONFIG_VIRTIO_GPU),$(CONFIG_VIRTIO_PCI)) += virtio-gpu-pci.o
52-
obj-$(call land,$(CONFIG_VHOST_USER_GPU),$(CONFIG_VIRTIO_PCI)) += vhost-user-gpu-pci.o
53-
obj-$(CONFIG_VIRTIO_VGA) += virtio-vga.o
54-
obj-$(CONFIG_VHOST_USER_VGA) += vhost-user-vga.o
55-
virtio-gpu.o-cflags := $(VIRGL_CFLAGS)
56-
virtio-gpu.o-libs += $(VIRGL_LIBS)
57-
virtio-gpu-3d.o-cflags := $(VIRGL_CFLAGS)
58-
virtio-gpu-3d.o-libs += $(VIRGL_LIBS)
47+
ifeq ($(CONFIG_QXL),y)
48+
common-obj-m += qxl.mo
49+
qxl.mo-objs = qxl.o qxl-logger.o qxl-render.o
50+
endif
51+
52+
ifeq ($(CONFIG_VIRTIO_GPU),y)
53+
common-obj-m += virtio-gpu.mo
54+
virtio-gpu-obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu-base.o virtio-gpu.o virtio-gpu-3d.o
55+
virtio-gpu-obj-$(CONFIG_VHOST_USER_GPU) += vhost-user-gpu.o
56+
virtio-gpu-obj-$(call land,$(CONFIG_VIRTIO_GPU),$(CONFIG_VIRTIO_PCI)) += virtio-gpu-pci.o
57+
virtio-gpu-obj-$(call land,$(CONFIG_VHOST_USER_GPU),$(CONFIG_VIRTIO_PCI)) += vhost-user-gpu-pci.o
58+
virtio-gpu-obj-$(CONFIG_VIRTIO_VGA) += virtio-vga.o
59+
virtio-gpu-obj-$(CONFIG_VHOST_USER_VGA) += vhost-user-vga.o
60+
virtio-gpu.mo-objs := $(virtio-gpu-obj-y)
61+
virtio-gpu.mo-cflags := $(VIRGL_CFLAGS)
62+
virtio-gpu.mo-libs := $(VIRGL_LIBS)
63+
endif
64+
5965
common-obj-$(CONFIG_DPCD) += dpcd.o
6066
common-obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx_dp.o
6167

hw/usb/Makefile.objs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,26 @@ common-obj-$(CONFIG_USB_NETWORK) += dev-network.o
2929

3030
ifeq ($(CONFIG_USB_SMARTCARD),y)
3131
common-obj-y += dev-smartcard-reader.o
32-
common-obj-$(CONFIG_SMARTCARD) += smartcard.mo
32+
ifeq ($(CONFIG_SMARTCARD),y)
33+
common-obj-m += smartcard.mo
3334
smartcard.mo-objs := ccid-card-passthru.o ccid-card-emulated.o
3435
smartcard.mo-cflags := $(SMARTCARD_CFLAGS)
3536
smartcard.mo-libs := $(SMARTCARD_LIBS)
3637
endif
38+
endif
3739

3840
ifeq ($(CONFIG_POSIX),y)
3941
common-obj-$(CONFIG_USB_STORAGE_MTP) += dev-mtp.o
4042
endif
4143

4244
# usb redirection
4345
ifeq ($(CONFIG_USB),y)
44-
common-obj-$(CONFIG_USB_REDIR) += redirect.o quirks.o
45-
redirect.o-cflags = $(USB_REDIR_CFLAGS)
46-
redirect.o-libs = $(USB_REDIR_LIBS)
46+
ifeq ($(CONFIG_USB_REDIR),y)
47+
common-obj-m += redirect.mo
48+
redirect.mo-objs = redirect.o quirks.o
49+
redirect.mo-cflags = $(USB_REDIR_CFLAGS)
50+
redirect.mo-libs = $(USB_REDIR_LIBS)
51+
endif
4752
endif
4853

4954
# usb pass-through

include/qemu/module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,7 @@ void register_dso_module_init(void (*fn)(void), module_init_type type);
7070

7171
void module_call_init(module_init_type type);
7272
bool module_load_one(const char *prefix, const char *lib_name);
73+
void module_load_qom_one(const char *type);
74+
void module_load_qom_all(void);
7375

7476
#endif

include/qom/object.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,18 @@ bool object_class_is_abstract(ObjectClass *klass);
994994
*/
995995
ObjectClass *object_class_by_name(const char *typename);
996996

997+
/**
998+
* module_object_class_by_name:
999+
* @typename: The QOM typename to obtain the class for.
1000+
*
1001+
* For objects which might be provided by a module. Behaves like
1002+
* object_class_by_name, but additionally tries to load the module
1003+
* needed in case the class is not available.
1004+
*
1005+
* Returns: The class for @typename or %NULL if not found.
1006+
*/
1007+
ObjectClass *module_object_class_by_name(const char *typename);
1008+
9971009
void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
9981010
const char *implements_type, bool include_abstract,
9991011
void *opaque);

0 commit comments

Comments
 (0)