diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2016-12-07 18:39:10 +0300 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2017-01-27 18:08:00 +0100 |
commit | 777357d758d937c9dd83082c39aff9f1e53e9ba3 (patch) | |
tree | 20b236bf5acc7dfc20b4358bb8072dfe983c0e2d /hw/bt | |
parent | 5bf5adaeb7245d7037f29429fb231b4b602d5b50 (diff) |
chardev: qom-ify
Turn Chardev into Object.
qemu_chr_alloc() is replaced by the qemu_chardev_new() constructor. It
will call qemu_char_open() to open/intialize the chardev with the
ChardevCommon *backend settings.
The CharDriver::create() callback is turned into a ChardevClass::open()
which is called from the newly introduced qemu_chardev_open().
"chardev-gdb" and "chardev-hci" are internal chardev and aren't
creatable directly with -chardev. Use a new internal flag to disable
them. We may want to use TYPE_USER_CREATABLE interface instead, or
perhaps allow -chardev usage.
Although in general we keep typename and macros private, unless the type
is being used by some other file, in this patch, all types and common
helper macros for qemu-char.c are in char.h. This is to help transition
now (some types must be declared early, while some aren't shared) and
when splitting in several units. This is to be improved later.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'hw/bt')
-rw-r--r-- | hw/bt/hci-csr.c | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/hw/bt/hci-csr.c b/hw/bt/hci-csr.c index 153ed2f1ba..3c193848fc 100644 --- a/hw/bt/hci-csr.c +++ b/hw/bt/hci-csr.c @@ -55,6 +55,9 @@ struct csrhci_s { struct HCIInfo *hci; }; +#define TYPE_CHARDEV_HCI "chardev-hci" +#define HCI_CHARDEV(obj) OBJECT_CHECK(struct csrhci_s, (obj), TYPE_CHARDEV_HCI) + /* H4+ packet types */ enum { H4_CMD_PKT = 1, @@ -462,23 +465,12 @@ qemu_irq *csrhci_pins_get(Chardev *chr) return s->pins; } -Chardev *uart_hci_init(void) +static void csrhci_open(Chardev *chr, + ChardevBackend *backend, + bool *be_opened, + Error **errp) { - static const CharDriver hci_driver = { - .instance_size = sizeof(struct csrhci_s), - .kind = -1, - .chr_write = csrhci_write, - .chr_ioctl = csrhci_ioctl, - }; - Error *err = NULL; - ChardevCommon common = { 0, }; - Chardev *chr = qemu_chr_alloc(&hci_driver, &common, &err); - struct csrhci_s *s = (struct csrhci_s *)chr; - - if (err) { - error_report_err(err); - return NULL; - } + struct csrhci_s *s = HCI_CHARDEV(chr); s->hci = qemu_next_hci(); s->hci->opaque = s; @@ -488,6 +480,35 @@ Chardev *uart_hci_init(void) s->out_tm = timer_new_ns(QEMU_CLOCK_VIRTUAL, csrhci_out_tick, s); s->pins = qemu_allocate_irqs(csrhci_pins, s, __csrhci_pins); csrhci_reset(s); + *be_opened = false; +} + +static void char_hci_class_init(ObjectClass *oc, void *data) +{ + ChardevClass *cc = CHARDEV_CLASS(oc); + + cc->internal = true; + cc->open = csrhci_open; + cc->chr_write = csrhci_write; + cc->chr_ioctl = csrhci_ioctl; +} + +static const TypeInfo char_hci_type_info = { + .name = TYPE_CHARDEV_HCI, + .parent = TYPE_CHARDEV, + .instance_size = sizeof(struct csrhci_s), + .class_init = char_hci_class_init, +}; - return chr; +Chardev *uart_hci_init(void) +{ + return qemu_chardev_new(NULL, TYPE_CHARDEV_HCI, + NULL, &error_abort); } + +static void register_types(void) +{ + type_register_static(&char_hci_type_info); +} + +type_init(register_types); |