From patchwork Tue Mar 13 22:46:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 10281203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 010C260231 for ; Tue, 13 Mar 2018 23:25:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5600205F6 for ; Tue, 13 Mar 2018 23:25:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8DFF285C9; Tue, 13 Mar 2018 23:25:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1B306205F6 for ; Tue, 13 Mar 2018 23:25:17 +0000 (UTC) Received: from localhost ([::1]:43422 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evt8D-0002QS-Ji for patchwork-qemu-devel@patchwork.kernel.org; Tue, 13 Mar 2018 19:14:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evsiJ-0005wk-DR for qemu-devel@nongnu.org; Tue, 13 Mar 2018 18:48:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evsiH-0003gr-AU for qemu-devel@nongnu.org; Tue, 13 Mar 2018 18:48:11 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:36935) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evsiH-0003fX-09 for qemu-devel@nongnu.org; Tue, 13 Mar 2018 18:48:09 -0400 Received: by mail-wr0-x241.google.com with SMTP id z12so2563187wrg.4 for ; Tue, 13 Mar 2018 15:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/T9mimLrUSUK+UmgRdL/HPXuwI5QRhyhlbLL+RoEasQ=; b=ltkx5QjcTJ+QJAKsGYhGShp7Idc63GnxeJmMieMXpLNIQ9G5IwbZpBx7XMXkTJ1UqR esfKSkjswUIxxOOTBC0dw3vvBkJOAwSy/JRArNFobnUW6hxQ0u6FBT4HEU4zBEPZg0vw j7VGNB6MKJ7fA19NSbmyJiJXzxDXBvl6W63KqYiU2TVC8Ef69Rp6dCQsFjh/NThzYIrI a6xXqKwBjC7riBdA2KluNt/wp/MuE9JnGltQO31boIbwtrFyVEgSvnE/iSUYOq0Gav59 PpMM9sn51bwDGa3NdusI+Ch8o+DXw95gYYnBHOTWR3Ch0G7n6goFJaqYdzVyUBCaAZlG Rs0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=/T9mimLrUSUK+UmgRdL/HPXuwI5QRhyhlbLL+RoEasQ=; b=sgqZ+OjJQrXrqgJ9WTjVj79G1gLr8TOqFOZdI/otkQhfG4Js+A3yt2z8ljIVqDjxqi 0Pj2+MCLjOtZ5udASEpepU+OgF0iuZlwGTXr44McmALKDywoxg6vdMpWetqJNI6/lVrw hnaI//cPYQnVRjTHHdxVDWT8FkXK0dI+SCPk9GANAcKbHGhCAUExH+CpPLMLzyL0cTDw Cml0Ahjpa+S0yLajTXJBU2FmL0JUtL7DCmTKeftycbBIxxkLuvvYSWbY3KWXPVkMB9Xe Tbm5kNzT60q963vbZhAf45aSHPoeXQDJMvU2Ic1l6lOYjzKIpO7+wM3hF9hLTfaCtn/w MYjw== X-Gm-Message-State: AElRT7FVXHNL9vnuHpf/xzI6p4NsZauTfE4RNwPYaXL1IUp42pdLBQV/ LzXwBRuHflDUXTMLNgUgw/VBUvyz X-Google-Smtp-Source: AG47ELuoPvwWxXX7JcMGpFDTI+/uNyxxZgMr4DzD74ZYEKKkZ4/E3IsWA55xv8AhgDtXcqehAVRwNQ== X-Received: by 10.223.148.37 with SMTP id 34mr1938378wrq.243.1520981287507; Tue, 13 Mar 2018 15:48:07 -0700 (PDT) Received: from donizetti.lan (94-36-191-219.adsl-ull.clienti.tiscali.it. [94.36.191.219]) by smtp.gmail.com with ESMTPSA id x107sm1557951wrb.97.2018.03.13.15.48.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Mar 2018 15:48:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 23:46:47 +0100 Message-Id: <20180313224719.4954-38-pbonzini@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180313224719.4954-1-pbonzini@redhat.com> References: <20180313224719.4954-1-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PULL 37/69] hw/isa/superio: Factor out the serial code from pc87312.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20180308223946.26784-12-f4bug@amsat.org> Signed-off-by: Paolo Bonzini --- hw/isa/isa-superio.c | 41 +++++++++++++++++++++++++++++++++++++++++ hw/isa/pc87312.c | 43 ++++++++++++------------------------------- hw/isa/trace-events | 2 +- include/hw/isa/pc87312.h | 4 ---- include/hw/isa/superio.h | 2 ++ 5 files changed, 56 insertions(+), 36 deletions(-) diff --git a/hw/isa/isa-superio.c b/hw/isa/isa-superio.c index eb263fcc3a..6962421aad 100644 --- a/hw/isa/isa-superio.c +++ b/hw/isa/isa-superio.c @@ -14,6 +14,7 @@ #include "sysemu/sysemu.h" #include "chardev/char.h" #include "hw/isa/superio.h" +#include "hw/char/serial.h" #include "trace.h" static void isa_superio_realize(DeviceState *dev, Error **errp) @@ -66,6 +67,46 @@ static void isa_superio_realize(DeviceState *dev, Error **errp) g_free(name); } } + + /* Serial */ + for (i = 0; i < k->serial.count; i++) { + if (i >= ARRAY_SIZE(sio->serial)) { + warn_report("superio: ignoring %td serial controllers", + k->serial.count - ARRAY_SIZE(sio->serial)); + break; + } + if (!k->serial.is_enabled || k->serial.is_enabled(sio, i)) { + /* FIXME use a qdev chardev prop instead of serial_hds[] */ + chr = serial_hds[i]; + if (chr == NULL || chr->be) { + name = g_strdup_printf("discarding-serial%d", i); + chr = qemu_chr_new(name, "null"); + } else { + name = g_strdup_printf("serial%d", i); + } + isa = isa_create(bus, TYPE_ISA_SERIAL); + d = DEVICE(isa); + qdev_prop_set_uint32(d, "index", i); + if (k->serial.get_iobase) { + qdev_prop_set_uint32(d, "iobase", + k->serial.get_iobase(sio, i)); + } + if (k->serial.get_irq) { + qdev_prop_set_uint32(d, "irq", k->serial.get_irq(sio, i)); + } + qdev_prop_set_chr(d, "chardev", chr); + qdev_init_nofail(d); + sio->serial[i] = isa; + trace_superio_create_serial(i, + k->serial.get_iobase ? + k->serial.get_iobase(sio, i) : -1, + k->serial.get_irq ? + k->serial.get_irq(sio, i) : -1); + object_property_add_child(OBJECT(dev), name, + OBJECT(sio->serial[0]), NULL); + g_free(name); + } + } } static void isa_superio_class_init(ObjectClass *oc, void *data) diff --git a/hw/isa/pc87312.c b/hw/isa/pc87312.c index 1c15715c69..c2837bca43 100644 --- a/hw/isa/pc87312.c +++ b/hw/isa/pc87312.c @@ -29,8 +29,6 @@ #include "qemu/error-report.h" #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" -#include "sysemu/sysemu.h" -#include "chardev/char.h" #include "trace.h" @@ -100,8 +98,9 @@ static const uint16_t uart_base[2][4] = { { 0x2e8, 0x238, 0x2e0, 0x228 } }; -static inline uint16_t get_uart_iobase(PC87312State *s, int i) +static uint16_t get_uart_iobase(ISASuperIODevice *sio, uint8_t i) { + PC87312State *s = PC87312(sio); int idx; idx = (s->regs[REG_FAR] >> (2 * i + 2)) & 0x3; if (idx == 0) { @@ -113,15 +112,17 @@ static inline uint16_t get_uart_iobase(PC87312State *s, int i) } } -static inline unsigned int get_uart_irq(PC87312State *s, int i) +static unsigned int get_uart_irq(ISASuperIODevice *sio, uint8_t i) { + PC87312State *s = PC87312(sio); int idx; idx = (s->regs[REG_FAR] >> (2 * i + 2)) & 0x3; return (idx & 1) ? 3 : 4; } -static inline bool is_uart_enabled(PC87312State *s, int i) +static bool is_uart_enabled(ISASuperIODevice *sio, uint8_t i) { + PC87312State *s = PC87312(sio); return s->regs[REG_FER] & (FER_UART1_EN << i); } @@ -271,11 +272,8 @@ static void pc87312_realize(DeviceState *dev, Error **errp) DeviceState *d; ISADevice *isa; ISABus *bus; - Chardev *chr; DriveInfo *drive; Error *local_err = NULL; - char name[5]; - int i; s = PC87312(dev); isa = ISA_DEVICE(dev); @@ -289,27 +287,6 @@ static void pc87312_realize(DeviceState *dev, Error **errp) return; } - for (i = 0; i < 2; i++) { - if (is_uart_enabled(s, i)) { - /* FIXME use a qdev chardev prop instead of serial_hds[] */ - chr = serial_hds[i]; - if (chr == NULL) { - snprintf(name, sizeof(name), "ser%d", i); - chr = qemu_chr_new(name, "null"); - } - isa = isa_create(bus, "isa-serial"); - d = DEVICE(isa); - qdev_prop_set_uint32(d, "index", i); - qdev_prop_set_uint32(d, "iobase", get_uart_iobase(s, i)); - qdev_prop_set_uint32(d, "irq", get_uart_irq(s, i)); - qdev_prop_set_chr(d, "chardev", chr); - qdev_init_nofail(d); - s->uart[i].dev = isa; - trace_pc87312_info_serial(i, get_uart_iobase(s, i), - get_uart_irq(s, i)); - } - } - if (is_fdc_enabled(s)) { isa = isa_create(bus, "isa-fdc"); d = DEVICE(isa); @@ -380,8 +357,6 @@ static void pc87312_class_init(ObjectClass *klass, void *data) dc->reset = pc87312_reset; dc->vmsd = &vmstate_pc87312; dc->props = pc87312_properties; - /* Reason: Uses serial_hds[0] in realize(), so it can't be used twice */ - dc->user_creatable = false; sc->parallel = (ISASuperIOFuncs){ .count = 1, @@ -389,6 +364,12 @@ static void pc87312_class_init(ObjectClass *klass, void *data) .get_iobase = get_parallel_iobase, .get_irq = get_parallel_irq, }; + sc->serial = (ISASuperIOFuncs){ + .count = 2, + .is_enabled = is_uart_enabled, + .get_iobase = get_uart_iobase, + .get_irq = get_uart_irq, + }; } static const TypeInfo pc87312_type_info = { diff --git a/hw/isa/trace-events b/hw/isa/trace-events index 97b1949981..c78dd6c353 100644 --- a/hw/isa/trace-events +++ b/hw/isa/trace-events @@ -2,10 +2,10 @@ # hw/isa/isa-superio.c superio_create_parallel(int id, uint16_t base, unsigned int irq) "id=%d, base 0x%03x, irq %u" +superio_create_serial(int id, uint16_t base, unsigned int irq) "id=%d, base 0x%03x, irq %u" # hw/isa/pc87312.c pc87312_io_read(uint32_t addr, uint32_t val) "read addr=0x%x val=0x%x" pc87312_io_write(uint32_t addr, uint32_t val) "write addr=0x%x val=0x%x" pc87312_info_floppy(uint32_t base) "base 0x%x" pc87312_info_ide(uint32_t base) "base 0x%x" -pc87312_info_serial(int n, uint32_t base, uint32_t irq) "id=%d, base 0x%x, irq %u" diff --git a/include/hw/isa/pc87312.h b/include/hw/isa/pc87312.h index bcc4578479..1480615a2c 100644 --- a/include/hw/isa/pc87312.h +++ b/include/hw/isa/pc87312.h @@ -39,10 +39,6 @@ typedef struct PC87312State { uint16_t iobase; uint8_t config; /* initial configuration */ - struct { - ISADevice *dev; - } uart[2]; - struct { ISADevice *dev; } fdc; diff --git a/include/hw/isa/superio.h b/include/hw/isa/superio.h index e9879cfde1..0b516721c3 100644 --- a/include/hw/isa/superio.h +++ b/include/hw/isa/superio.h @@ -28,6 +28,7 @@ typedef struct ISASuperIODevice { /*< public >*/ ISADevice *parallel[MAX_PARALLEL_PORTS]; + ISADevice *serial[MAX_SERIAL_PORTS]; } ISASuperIODevice; typedef struct ISASuperIOFuncs { @@ -45,6 +46,7 @@ typedef struct ISASuperIOClass { DeviceRealize parent_realize; ISASuperIOFuncs parallel; + ISASuperIOFuncs serial; } ISASuperIOClass; #endif /* HW_ISA_SUPERIO_H */