From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56CC5C433FE for ; Thu, 10 Dec 2020 19:29:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0994722EBE for ; Thu, 10 Dec 2020 19:29:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390301AbgLJT3K (ORCPT ); Thu, 10 Dec 2020 14:29:10 -0500 Received: from foss.arm.com ([217.140.110.172]:44788 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390264AbgLJOaK (ORCPT ); Thu, 10 Dec 2020 09:30:10 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 928F71396; Thu, 10 Dec 2020 06:29:24 -0800 (PST) Received: from donnerap.arm.com (donnerap.cambridge.arm.com [10.1.195.35]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 772623F718; Thu, 10 Dec 2020 06:29:23 -0800 (PST) From: Andre Przywara To: Will Deacon , Julien Thierry Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Alexandru Elisei , Marc Zyngier Subject: [PATCH kvmtool 02/21] hw/serial: Use device abstraction for FDT generator function Date: Thu, 10 Dec 2020 14:28:49 +0000 Message-Id: <20201210142908.169597-3-andre.przywara@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201210142908.169597-1-andre.przywara@arm.com> References: <20201210142908.169597-1-andre.przywara@arm.com> Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org At the moment we use the .generate_fdt_node member of the ioport ops structure to store the function pointer for the FDT node generator function. ioport__register() will then put a wrapper and this pointer into the device header. The serial device is the only device making use of this special ioport feature, so let's move this over to using the device header directly. This will allow us to get rid of this .generate_fdt_node member in the ops and simplify the code. Signed-off-by: Andre Przywara --- hw/serial.c | 49 +++++++++++++++++++++++++++++++++++++---------- include/kvm/kvm.h | 2 ++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/hw/serial.c b/hw/serial.c index 13c4663e..b0465d99 100644 --- a/hw/serial.c +++ b/hw/serial.c @@ -23,6 +23,7 @@ #define UART_IIR_TYPE_BITS 0xc0 struct serial8250_device { + struct device_header dev_hdr; struct mutex mutex; u8 id; @@ -53,9 +54,20 @@ struct serial8250_device { .msr = UART_MSR_DCD | UART_MSR_DSR | UART_MSR_CTS, \ .mcr = UART_MCR_OUT2, +#ifdef CONFIG_HAS_LIBFDT +static +void serial8250_generate_fdt_node(void *fdt, struct device_header *dev_hdr, + fdt_irq_fn irq_fn); +#else +#define serial8250_generate_fdt_node NULL +#endif static struct serial8250_device devices[] = { /* ttyS0 */ [0] = { + .dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = serial8250_generate_fdt_node, + }, .mutex = MUTEX_INITIALIZER, .id = 0, @@ -66,6 +78,10 @@ static struct serial8250_device devices[] = { }, /* ttyS1 */ [1] = { + .dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = serial8250_generate_fdt_node, + }, .mutex = MUTEX_INITIALIZER, .id = 1, @@ -76,6 +92,10 @@ static struct serial8250_device devices[] = { }, /* ttyS2 */ [2] = { + .dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = serial8250_generate_fdt_node, + }, .mutex = MUTEX_INITIALIZER, .id = 2, @@ -86,6 +106,10 @@ static struct serial8250_device devices[] = { }, /* ttyS3 */ [3] = { + .dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = serial8250_generate_fdt_node, + }, .mutex = MUTEX_INITIALIZER, .id = 3, @@ -371,13 +395,14 @@ char *fdt_stdout_path = NULL; #define DEVICE_NAME_MAX_LEN 32 static -void serial8250_generate_fdt_node(struct ioport *ioport, void *fdt, - void (*generate_irq_prop)(void *fdt, - u8 irq, - enum irq_type)) +void serial8250_generate_fdt_node(void *fdt, struct device_header *dev_hdr, + fdt_irq_fn irq_fn) { char dev_name[DEVICE_NAME_MAX_LEN]; - struct serial8250_device *dev = ioport->priv; + struct serial8250_device *dev = container_of(dev_hdr, + struct serial8250_device, + dev_hdr); + u64 addr = KVM_IOPORT_AREA + dev->iobase; u64 reg_prop[] = { cpu_to_fdt64(addr), @@ -395,24 +420,26 @@ void serial8250_generate_fdt_node(struct ioport *ioport, void *fdt, _FDT(fdt_begin_node(fdt, dev_name)); _FDT(fdt_property_string(fdt, "compatible", "ns16550a")); _FDT(fdt_property(fdt, "reg", reg_prop, sizeof(reg_prop))); - generate_irq_prop(fdt, dev->irq, IRQ_TYPE_LEVEL_HIGH); + irq_fn(fdt, dev->irq, IRQ_TYPE_LEVEL_HIGH); _FDT(fdt_property_cell(fdt, "clock-frequency", 1843200)); _FDT(fdt_end_node(fdt)); } -#else -#define serial8250_generate_fdt_node NULL #endif static struct ioport_operations serial8250_ops = { .io_in = serial8250_in, .io_out = serial8250_out, - .generate_fdt_node = serial8250_generate_fdt_node, }; -static int serial8250__device_init(struct kvm *kvm, struct serial8250_device *dev) +static int serial8250__device_init(struct kvm *kvm, + struct serial8250_device *dev) { int r; + r = device__register(&dev->dev_hdr); + if (r < 0) + return r; + ioport__map_irq(&dev->irq); r = ioport__register(kvm, dev->iobase, &serial8250_ops, 8, dev); @@ -438,6 +465,7 @@ cleanup: struct serial8250_device *dev = &devices[j]; ioport__unregister(kvm, dev->iobase); + device__unregister(&dev->dev_hdr); } return r; @@ -455,6 +483,7 @@ int serial8250__exit(struct kvm *kvm) r = ioport__unregister(kvm, dev->iobase); if (r < 0) return r; + device__unregister(&dev->dev_hdr); } return 0; diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h index 53373b08..ee99c28e 100644 --- a/include/kvm/kvm.h +++ b/include/kvm/kvm.h @@ -31,6 +31,8 @@ .name = #ext, \ .code = ext +typedef void (*fdt_irq_fn)(void *fdt, u8 irq, enum irq_type); + enum { KVM_VMSTATE_RUNNING, KVM_VMSTATE_PAUSED, -- 2.17.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0718C4361B for ; Thu, 10 Dec 2020 14:29:29 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 31BC023E22 for ; Thu, 10 Dec 2020 14:29:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31BC023E22 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id A68F24B1B3; Thu, 10 Dec 2020 09:29:28 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1uxopAuAXdiO; Thu, 10 Dec 2020 09:29:27 -0500 (EST) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 383FA4B1DA; Thu, 10 Dec 2020 09:29:27 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 5E51B4B1B3 for ; Thu, 10 Dec 2020 09:29:26 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x3To7a5+Nl2k for ; Thu, 10 Dec 2020 09:29:25 -0500 (EST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mm01.cs.columbia.edu (Postfix) with ESMTP id E86234B1A6 for ; Thu, 10 Dec 2020 09:29:24 -0500 (EST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 928F71396; Thu, 10 Dec 2020 06:29:24 -0800 (PST) Received: from donnerap.arm.com (donnerap.cambridge.arm.com [10.1.195.35]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 772623F718; Thu, 10 Dec 2020 06:29:23 -0800 (PST) From: Andre Przywara To: Will Deacon , Julien Thierry Subject: [PATCH kvmtool 02/21] hw/serial: Use device abstraction for FDT generator function Date: Thu, 10 Dec 2020 14:28:49 +0000 Message-Id: <20201210142908.169597-3-andre.przywara@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201210142908.169597-1-andre.przywara@arm.com> References: <20201210142908.169597-1-andre.przywara@arm.com> Cc: linux-arm-kernel@lists.infradead.org, Marc Zyngier , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu At the moment we use the .generate_fdt_node member of the ioport ops structure to store the function pointer for the FDT node generator function. ioport__register() will then put a wrapper and this pointer into the device header. The serial device is the only device making use of this special ioport feature, so let's move this over to using the device header directly. This will allow us to get rid of this .generate_fdt_node member in the ops and simplify the code. Signed-off-by: Andre Przywara --- hw/serial.c | 49 +++++++++++++++++++++++++++++++++++++---------- include/kvm/kvm.h | 2 ++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/hw/serial.c b/hw/serial.c index 13c4663e..b0465d99 100644 --- a/hw/serial.c +++ b/hw/serial.c @@ -23,6 +23,7 @@ #define UART_IIR_TYPE_BITS 0xc0 struct serial8250_device { + struct device_header dev_hdr; struct mutex mutex; u8 id; @@ -53,9 +54,20 @@ struct serial8250_device { .msr = UART_MSR_DCD | UART_MSR_DSR | UART_MSR_CTS, \ .mcr = UART_MCR_OUT2, +#ifdef CONFIG_HAS_LIBFDT +static +void serial8250_generate_fdt_node(void *fdt, struct device_header *dev_hdr, + fdt_irq_fn irq_fn); +#else +#define serial8250_generate_fdt_node NULL +#endif static struct serial8250_device devices[] = { /* ttyS0 */ [0] = { + .dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = serial8250_generate_fdt_node, + }, .mutex = MUTEX_INITIALIZER, .id = 0, @@ -66,6 +78,10 @@ static struct serial8250_device devices[] = { }, /* ttyS1 */ [1] = { + .dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = serial8250_generate_fdt_node, + }, .mutex = MUTEX_INITIALIZER, .id = 1, @@ -76,6 +92,10 @@ static struct serial8250_device devices[] = { }, /* ttyS2 */ [2] = { + .dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = serial8250_generate_fdt_node, + }, .mutex = MUTEX_INITIALIZER, .id = 2, @@ -86,6 +106,10 @@ static struct serial8250_device devices[] = { }, /* ttyS3 */ [3] = { + .dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = serial8250_generate_fdt_node, + }, .mutex = MUTEX_INITIALIZER, .id = 3, @@ -371,13 +395,14 @@ char *fdt_stdout_path = NULL; #define DEVICE_NAME_MAX_LEN 32 static -void serial8250_generate_fdt_node(struct ioport *ioport, void *fdt, - void (*generate_irq_prop)(void *fdt, - u8 irq, - enum irq_type)) +void serial8250_generate_fdt_node(void *fdt, struct device_header *dev_hdr, + fdt_irq_fn irq_fn) { char dev_name[DEVICE_NAME_MAX_LEN]; - struct serial8250_device *dev = ioport->priv; + struct serial8250_device *dev = container_of(dev_hdr, + struct serial8250_device, + dev_hdr); + u64 addr = KVM_IOPORT_AREA + dev->iobase; u64 reg_prop[] = { cpu_to_fdt64(addr), @@ -395,24 +420,26 @@ void serial8250_generate_fdt_node(struct ioport *ioport, void *fdt, _FDT(fdt_begin_node(fdt, dev_name)); _FDT(fdt_property_string(fdt, "compatible", "ns16550a")); _FDT(fdt_property(fdt, "reg", reg_prop, sizeof(reg_prop))); - generate_irq_prop(fdt, dev->irq, IRQ_TYPE_LEVEL_HIGH); + irq_fn(fdt, dev->irq, IRQ_TYPE_LEVEL_HIGH); _FDT(fdt_property_cell(fdt, "clock-frequency", 1843200)); _FDT(fdt_end_node(fdt)); } -#else -#define serial8250_generate_fdt_node NULL #endif static struct ioport_operations serial8250_ops = { .io_in = serial8250_in, .io_out = serial8250_out, - .generate_fdt_node = serial8250_generate_fdt_node, }; -static int serial8250__device_init(struct kvm *kvm, struct serial8250_device *dev) +static int serial8250__device_init(struct kvm *kvm, + struct serial8250_device *dev) { int r; + r = device__register(&dev->dev_hdr); + if (r < 0) + return r; + ioport__map_irq(&dev->irq); r = ioport__register(kvm, dev->iobase, &serial8250_ops, 8, dev); @@ -438,6 +465,7 @@ cleanup: struct serial8250_device *dev = &devices[j]; ioport__unregister(kvm, dev->iobase); + device__unregister(&dev->dev_hdr); } return r; @@ -455,6 +483,7 @@ int serial8250__exit(struct kvm *kvm) r = ioport__unregister(kvm, dev->iobase); if (r < 0) return r; + device__unregister(&dev->dev_hdr); } return 0; diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h index 53373b08..ee99c28e 100644 --- a/include/kvm/kvm.h +++ b/include/kvm/kvm.h @@ -31,6 +31,8 @@ .name = #ext, \ .code = ext +typedef void (*fdt_irq_fn)(void *fdt, u8 irq, enum irq_type); + enum { KVM_VMSTATE_RUNNING, KVM_VMSTATE_PAUSED, -- 2.17.1 _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43737C433FE for ; Thu, 10 Dec 2020 14:56:36 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8D9E3206D5 for ; Thu, 10 Dec 2020 14:56:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D9E3206D5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jeVnvCaq2u6WdxXPQt9zYv7OdsiJEH0QEOECl9J2t8s=; b=uuQkyrlnmw58+PWF61bjkOhMUu Ky2tSuMDME/6964pTZ/5zZMpoYYcA3B0MohfNoZzu3HRwARo7ZvQqgv1lKrmjHdBMaB7rzBfP3+fv 8ycJacNbRa9DDY5CSz7Q+FQmmCO+ctjsBws7N1q5IO4rmBGwvbbEP2lOOMjpnhxsYyc9HSR0MJ7nk Pr1YFqL9qJgf/k0PrSgGQPHLswp0Dz4BHAOGV2Fq4yepOCREk5fxK0zhHTN80Nm63zxrBRErowQ7u KVTV0H/poER2D/6vHMqvVSIY0774vk1PkC2vx+iwEbNQ56+QoMtWYAH/5mhGoY8+mB7aaBjC08QsU P4GRm/tQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knNLG-00067I-4u; Thu, 10 Dec 2020 14:54:50 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knNIo-0004ot-HO for linux-arm-kernel@merlin.infradead.org; Thu, 10 Dec 2020 14:52:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=k7JssGJET19sI0ZlV5O6N1Jnqw1g6z3NqHHJm/3eiy8=; b=vvzHO96PKR9G5Onc4aVpsPZgwk fekO66D1L6YrqpnnNBX5OAkVXy1TNvstP3v3d7L49lA3LHSgT4sg/7vN2U/m4MBJxXxUQjPCyvpe7 GMHuajn17/pIHRR+OomiAEpBM1eq12CuvdrVscYAjeWphi78G1p/1/y09kSLTLeO/TP10MRUe9zBF TW2V08GaZTcT3b+IY8agiX3fdod2SaZVlo/3o7bwMwy9Y/smdQKTwrxXcBCwDK2s49IgUPZqXCZ3y SL9RyrOXZFjkB+6XO/O/sW+WzH/oCqVOdDBGqgd/zQjbIc3gUOySAd38jR5PHX3EkeDE+FEdA02QP XUe6OzVw==; Received: from foss.arm.com ([217.140.110.172]) by casper.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knMwf-0002P2-E4 for linux-arm-kernel@lists.infradead.org; Thu, 10 Dec 2020 14:29:31 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 928F71396; Thu, 10 Dec 2020 06:29:24 -0800 (PST) Received: from donnerap.arm.com (donnerap.cambridge.arm.com [10.1.195.35]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 772623F718; Thu, 10 Dec 2020 06:29:23 -0800 (PST) From: Andre Przywara To: Will Deacon , Julien Thierry Subject: [PATCH kvmtool 02/21] hw/serial: Use device abstraction for FDT generator function Date: Thu, 10 Dec 2020 14:28:49 +0000 Message-Id: <20201210142908.169597-3-andre.przywara@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201210142908.169597-1-andre.przywara@arm.com> References: <20201210142908.169597-1-andre.przywara@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201210_142925_998770_3CE6899D X-CRM114-Status: GOOD ( 15.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marc Zyngier , Alexandru Elisei , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org At the moment we use the .generate_fdt_node member of the ioport ops structure to store the function pointer for the FDT node generator function. ioport__register() will then put a wrapper and this pointer into the device header. The serial device is the only device making use of this special ioport feature, so let's move this over to using the device header directly. This will allow us to get rid of this .generate_fdt_node member in the ops and simplify the code. Signed-off-by: Andre Przywara --- hw/serial.c | 49 +++++++++++++++++++++++++++++++++++++---------- include/kvm/kvm.h | 2 ++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/hw/serial.c b/hw/serial.c index 13c4663e..b0465d99 100644 --- a/hw/serial.c +++ b/hw/serial.c @@ -23,6 +23,7 @@ #define UART_IIR_TYPE_BITS 0xc0 struct serial8250_device { + struct device_header dev_hdr; struct mutex mutex; u8 id; @@ -53,9 +54,20 @@ struct serial8250_device { .msr = UART_MSR_DCD | UART_MSR_DSR | UART_MSR_CTS, \ .mcr = UART_MCR_OUT2, +#ifdef CONFIG_HAS_LIBFDT +static +void serial8250_generate_fdt_node(void *fdt, struct device_header *dev_hdr, + fdt_irq_fn irq_fn); +#else +#define serial8250_generate_fdt_node NULL +#endif static struct serial8250_device devices[] = { /* ttyS0 */ [0] = { + .dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = serial8250_generate_fdt_node, + }, .mutex = MUTEX_INITIALIZER, .id = 0, @@ -66,6 +78,10 @@ static struct serial8250_device devices[] = { }, /* ttyS1 */ [1] = { + .dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = serial8250_generate_fdt_node, + }, .mutex = MUTEX_INITIALIZER, .id = 1, @@ -76,6 +92,10 @@ static struct serial8250_device devices[] = { }, /* ttyS2 */ [2] = { + .dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = serial8250_generate_fdt_node, + }, .mutex = MUTEX_INITIALIZER, .id = 2, @@ -86,6 +106,10 @@ static struct serial8250_device devices[] = { }, /* ttyS3 */ [3] = { + .dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = serial8250_generate_fdt_node, + }, .mutex = MUTEX_INITIALIZER, .id = 3, @@ -371,13 +395,14 @@ char *fdt_stdout_path = NULL; #define DEVICE_NAME_MAX_LEN 32 static -void serial8250_generate_fdt_node(struct ioport *ioport, void *fdt, - void (*generate_irq_prop)(void *fdt, - u8 irq, - enum irq_type)) +void serial8250_generate_fdt_node(void *fdt, struct device_header *dev_hdr, + fdt_irq_fn irq_fn) { char dev_name[DEVICE_NAME_MAX_LEN]; - struct serial8250_device *dev = ioport->priv; + struct serial8250_device *dev = container_of(dev_hdr, + struct serial8250_device, + dev_hdr); + u64 addr = KVM_IOPORT_AREA + dev->iobase; u64 reg_prop[] = { cpu_to_fdt64(addr), @@ -395,24 +420,26 @@ void serial8250_generate_fdt_node(struct ioport *ioport, void *fdt, _FDT(fdt_begin_node(fdt, dev_name)); _FDT(fdt_property_string(fdt, "compatible", "ns16550a")); _FDT(fdt_property(fdt, "reg", reg_prop, sizeof(reg_prop))); - generate_irq_prop(fdt, dev->irq, IRQ_TYPE_LEVEL_HIGH); + irq_fn(fdt, dev->irq, IRQ_TYPE_LEVEL_HIGH); _FDT(fdt_property_cell(fdt, "clock-frequency", 1843200)); _FDT(fdt_end_node(fdt)); } -#else -#define serial8250_generate_fdt_node NULL #endif static struct ioport_operations serial8250_ops = { .io_in = serial8250_in, .io_out = serial8250_out, - .generate_fdt_node = serial8250_generate_fdt_node, }; -static int serial8250__device_init(struct kvm *kvm, struct serial8250_device *dev) +static int serial8250__device_init(struct kvm *kvm, + struct serial8250_device *dev) { int r; + r = device__register(&dev->dev_hdr); + if (r < 0) + return r; + ioport__map_irq(&dev->irq); r = ioport__register(kvm, dev->iobase, &serial8250_ops, 8, dev); @@ -438,6 +465,7 @@ cleanup: struct serial8250_device *dev = &devices[j]; ioport__unregister(kvm, dev->iobase); + device__unregister(&dev->dev_hdr); } return r; @@ -455,6 +483,7 @@ int serial8250__exit(struct kvm *kvm) r = ioport__unregister(kvm, dev->iobase); if (r < 0) return r; + device__unregister(&dev->dev_hdr); } return 0; diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h index 53373b08..ee99c28e 100644 --- a/include/kvm/kvm.h +++ b/include/kvm/kvm.h @@ -31,6 +31,8 @@ .name = #ext, \ .code = ext +typedef void (*fdt_irq_fn)(void *fdt, u8 irq, enum irq_type); + enum { KVM_VMSTATE_RUNNING, KVM_VMSTATE_PAUSED, -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel