From patchwork Tue May 3 19:48:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568985 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9791644map; Tue, 3 May 2022 13:22:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwn12TwMtq426ug1B1I1EgqVj9HBm6cnxqAVHPMBAOC0heK+v8aa6aM4ViNsPmP0FRsCySR X-Received: by 2002:a37:62ce:0:b0:69f:b99b:ef0b with SMTP id w197-20020a3762ce000000b0069fb99bef0bmr13531532qkb.725.1651609372619; Tue, 03 May 2022 13:22:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609372; cv=none; d=google.com; s=arc-20160816; b=zV80aLnlhPFlZLb4SSVtBRS8Nl9GKVUi9cEF1eJIQk2pSFqUky73lobfTcDqSyIgYh akO5mSGhqj+bM63uTkD2bAE1bawXzsC838EGPa1S5i1QE1MUDoZT5ko/r8hWOpbw/zqB HB530HmW/QPaZlMPkjg+D9Xwf7kKRaQYPkvR94dGLb8Xj/PSjnnJreQ28L1pGBLEU7cC TJjAnbB41fcqwzxkJTb0n6JRKRyP5ekAQONqLpJCcfTl3yWTfD0OxkNzmqJRdpFEJhYL pfQETCU7/3tILNhJN02xj9xCTUNshvwyWADulV+E3kxg150204tf+pW2F70ZiJdkemxn cNng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=WMI7bqILJjX6/FSY73MwMD4JpfCZEnEL2iLuRqOe/O0=; b=NaHfQR0n2RQ3yACWa3R17POEQPOafrrYRmzOIpwGmwPb6uw95ZPjQEwdNGLvrpGjHT eruznyCWZvmPVPe2kTcrf+g7fF07eJr58SQKVhe99KYBG5fwrymqyot+iGQOmFv0/i1p dqNAEoe/G53B2mQ//9JMhsaSbP3SdJhzf8eArlKXS1FWZX6urfEMkKk+zMzoZ6khT/R5 sg4xGYjHuXaud8PVpkbwtFqE2dX1CPiqIT4L/NI5IH9x1bxfsb8EUJPcSIcVK47fvDkT wXAFUej63uSdDnifl1WsyoIEdjI0IVVmspKOkaYF6fiW7UAmz8gN4npYxhQQ/OAdmYH3 EZdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cRIJieso; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u68-20020a376047000000b0069fb7937fc6si5689769qkb.476.2022.05.03.13.22.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:22:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cRIJieso; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlz2p-0003dC-Ot for patch@linaro.org; Tue, 03 May 2022 16:22:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWW-0002Hw-MT for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:29 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]:45898) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWS-0003d6-VL for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:27 -0400 Received: by mail-pf1-x433.google.com with SMTP id h1so15551034pfv.12 for ; Tue, 03 May 2022 12:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=WMI7bqILJjX6/FSY73MwMD4JpfCZEnEL2iLuRqOe/O0=; b=cRIJieso6ZCk/SZfaRT0o8vM9qNf8jMBzxUCuz33hkH6vWSIMT/CfgxUmmLYHJku/b AWLEJ98ebT5zbAMO/G944cTP0SUpWR0ii5K7rRi+egr45Qt8OX3lVWlVvkODIalzdyw6 GREjfIHSswZzMjGdbrfF00pmTSrYwXfuk3d9FTb4+MDwxhin01L3mYfZSAsooKzIyUHA K8cP1ZKCCOBIVw30kRV9fESE44sXBgT8kw21IUYKpepqYRgfiQBO4W2SVhcTRkar605i 8XMq4mmFIG8IqKpRPe3rKgnAM6wMHQpWcEmSLLUN7WHSOfMHpvNOmzXtsfVEfXnfDb3z HGaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WMI7bqILJjX6/FSY73MwMD4JpfCZEnEL2iLuRqOe/O0=; b=aeuuc9J2z6/CRNAfzvZIoyEl/paznojBQu4wEvAOnPwv2NVifdiSABCSYMFm5iujd3 LEOrZwic0rt6gDfpbfDDqFmp6ZZ/V86fLM3KJN1hCM6htMfMO0A5YPg297i6sV4eHXR9 b5Y5Wq2YiomX5xoIoxK1UNXcgVaNorq1OjLleOCTqu4lXaZeLv/iULfiGmd/Iit6GUV7 CYALqkA1qnIIQHAnYw6UgkH2r8b4dJCTNV2E1NYp7UQng7YmfkEwnDEyvTwAlUOOVBED J9233WtSrPcJGAWlQwxe24PNi+8yo5PFJKK9e3L77J4kghkPbfhCDBibaYNbRSQuSOHx dj+A== X-Gm-Message-State: AOAM533aI051HCGtSMiMxqelNuWcwuCPcG9j2MlaEbP2a7cvVN9QR6r2 0ic/BgBacs2P08FJrwGS+YOTW5mXSrW2MQ== X-Received: by 2002:a63:6682:0:b0:3c2:2f7c:cc76 with SMTP id a124-20020a636682000000b003c22f7ccc76mr8544328pgc.253.1651607363262; Tue, 03 May 2022 12:49:23 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 38/74] semihosting: Cleanup chardev init Date: Tue, 3 May 2022 12:48:07 -0700 Message-Id: <20220503194843.1379101-39-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220503194843.1379101-1-richard.henderson@linaro.org> References: <20220503194843.1379101-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rename qemu_semihosting_connect_chardevs to qemu_semihosting_chardev_init; pass the result directly to qemu_semihosting_console_init. Store the chardev in SemihostingConsole instead of SemihostingConfig, which lets us drop semihosting_get_chardev. Signed-off-by: Richard Henderson --- include/semihosting/semihost.h | 13 ++----------- semihosting/config.c | 17 +++++++---------- semihosting/console.c | 31 +++++++++++++++---------------- softmmu/vl.c | 3 +-- stubs/semihost.c | 6 +----- 5 files changed, 26 insertions(+), 44 deletions(-) diff --git a/include/semihosting/semihost.h b/include/semihosting/semihost.h index 0c55ade3ac..5b36a76f08 100644 --- a/include/semihosting/semihost.h +++ b/include/semihosting/semihost.h @@ -51,14 +51,6 @@ static inline const char *semihosting_get_cmdline(void) { return NULL; } - -static inline Chardev *semihosting_get_chardev(void) -{ - return NULL; -} -static inline void qemu_semihosting_console_init(void) -{ -} #else /* !CONFIG_USER_ONLY */ bool semihosting_enabled(void); SemihostingTarget semihosting_get_target(void); @@ -66,12 +58,11 @@ const char *semihosting_get_arg(int i); int semihosting_get_argc(void); const char *semihosting_get_cmdline(void); void semihosting_arg_fallback(const char *file, const char *cmd); -Chardev *semihosting_get_chardev(void); /* for vl.c hooks */ void qemu_semihosting_enable(void); int qemu_semihosting_config_options(const char *opt); -void qemu_semihosting_connect_chardevs(void); -void qemu_semihosting_console_init(void); +void qemu_semihosting_chardev_init(void); +void qemu_semihosting_console_init(Chardev *); #endif /* CONFIG_USER_ONLY */ #endif /* SEMIHOST_H */ diff --git a/semihosting/config.c b/semihosting/config.c index 50d82108e6..4bca769fad 100644 --- a/semihosting/config.c +++ b/semihosting/config.c @@ -50,7 +50,6 @@ QemuOptsList qemu_semihosting_config_opts = { typedef struct SemihostingConfig { bool enabled; SemihostingTarget target; - Chardev *chardev; char **argv; int argc; const char *cmdline; /* concatenated argv */ @@ -121,11 +120,6 @@ void semihosting_arg_fallback(const char *file, const char *cmd) } } -Chardev *semihosting_get_chardev(void) -{ - return semihosting.chardev; -} - void qemu_semihosting_enable(void) { semihosting.enabled = true; @@ -171,16 +165,19 @@ int qemu_semihosting_config_options(const char *optarg) return 0; } -void qemu_semihosting_connect_chardevs(void) +/* We had to defer this until chardevs were created */ +void qemu_semihosting_chardev_init(void) { - /* We had to defer this until chardevs were created */ + Chardev *chr = NULL; + if (semihost_chardev) { - Chardev *chr = qemu_chr_find(semihost_chardev); + chr = qemu_chr_find(semihost_chardev); if (chr == NULL) { error_report("semihosting chardev '%s' not found", semihost_chardev); exit(1); } - semihosting.chardev = chr; } + + qemu_semihosting_console_init(chr); } diff --git a/semihosting/console.c b/semihosting/console.c index df618a28a4..4088192842 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -27,11 +27,21 @@ #include "qapi/error.h" #include "qemu/fifo8.h" +/* Access to this structure is protected by the BQL */ +typedef struct SemihostingConsole { + CharBackend backend; + Chardev *chr; + GSList *sleeping_cpus; + bool got; + Fifo8 fifo; +} SemihostingConsole; + +static SemihostingConsole console; + int qemu_semihosting_log_out(const char *s, int len) { - Chardev *chardev = semihosting_get_chardev(); - if (chardev) { - return qemu_chr_write_all(chardev, (uint8_t *) s, len); + if (console.chr) { + return qemu_chr_write_all(console.chr, (uint8_t *) s, len); } else { return write(STDERR_FILENO, s, len); } @@ -106,16 +116,6 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr) #define FIFO_SIZE 1024 -/* Access to this structure is protected by the BQL */ -typedef struct SemihostingConsole { - CharBackend backend; - GSList *sleeping_cpus; - bool got; - Fifo8 fifo; -} SemihostingConsole; - -static SemihostingConsole console; - static int console_can_read(void *opaque) { SemihostingConsole *c = opaque; @@ -169,10 +169,9 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) return ret; } -void qemu_semihosting_console_init(void) +void qemu_semihosting_console_init(Chardev *chr) { - Chardev *chr = semihosting_get_chardev(); - + console.chr = chr; if (chr) { fifo8_create(&console.fifo, FIFO_SIZE); qemu_chr_fe_init(&console.backend, chr, &error_abort); diff --git a/softmmu/vl.c b/softmmu/vl.c index c2919579fd..009b660588 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2019,8 +2019,7 @@ static void qemu_create_late_backends(void) exit(1); /* now chardevs have been created we may have semihosting to connect */ - qemu_semihosting_connect_chardevs(); - qemu_semihosting_console_init(); + qemu_semihosting_chardev_init(); } static bool have_custom_ram_size(void) diff --git a/stubs/semihost.c b/stubs/semihost.c index 4bf2cf71b9..f486651afb 100644 --- a/stubs/semihost.c +++ b/stubs/semihost.c @@ -65,10 +65,6 @@ void semihosting_arg_fallback(const char *file, const char *cmd) { } -void qemu_semihosting_connect_chardevs(void) -{ -} - -void qemu_semihosting_console_init(void) +void qemu_semihosting_chardev_init(void) { }