From patchwork Thu Mar 10 20:50:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1604151 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=seco.com header.i=@seco.com header.a=rsa-sha256 header.s=selector1 header.b=FRnmSrkd; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KF1ZM0v2lz9sGB for ; Fri, 11 Mar 2022 07:56:27 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2ABCC83C0F; Thu, 10 Mar 2022 21:54:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=seco.com header.i=@seco.com header.b="FRnmSrkd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3FCFF83B30; Thu, 10 Mar 2022 21:52:29 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on061d.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0d::61d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1241983B24 for ; Thu, 10 Mar 2022 21:51:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sean.anderson@seco.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ARX+3SAGZLwMR0XLuixAWujrYqbEAYOBkVbx3AcvzB03rLOG74s0LBfaBQ+t4HQ2Cv5I6/ChKp0IIbx4ymj8PhWwfVGqHlPiG4mig4kyOmDlDjUWOrZLHA+6TbtdGCYSUWhKgToAXH/Hn/lKwT/oh7OLUiF/skiANNi/+gPBG5uAq8bFuXNw5L4SiIyLv1rFqCZKpUXxQeLndlVLb7H2/PmkBEWYT4ggkyooyD7oxZ9VxivKHNN4ICqkTe0LWqPXlQZxWG6DMRPMjOjzaF2ESu+pmGwvqpnfYfzeiYLF8VItofeSEcP+HjnEjwnKdYRup/zJASNhrZhSCHE1/yOVig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=25PGlZavxfPglGWbkuCMXp+KFFQECXolQhfo/jBOvtI=; b=oC+1kH3NCIkRFvdlYOx1GfLdWfujjN2WujNW0eb8gG08jIAqVadfvHR3LuOUTflw2F9BDPufR09WeFT+4gmICZcafJhjRxZWyYmsJ5QriWA2x6UzasSJFBeXw8GzItdsgTrUuHM1KQ1oZeiyC/ZqowB5RzAVWwVNvR5/OFNRS7uW7uBwfI/eURkbJGgO27rqij6AAu5KHrRg6jSOWLf06DIXpc24u9p8wJ0OG9s4rk1I/NIi3o7GDBXm3L+FSRmil2M8Ckz9hy+c4ZSEVlnQidjUubfXdMX8lPfbLW3HI0fAKWRIs2i/ByLM5SizpeFkKO+YmJa3eF3YF0lWJg1TLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=25PGlZavxfPglGWbkuCMXp+KFFQECXolQhfo/jBOvtI=; b=FRnmSrkdhpyJ2usXhnBvnmnODYprI9cWf+rahplRl6GjK+shJZmSFJGuUJJA1yHWGlq5RttRR34NfqHnSNICm9evR0qneaSw/2vyVjwgBPx37jXze9ng9IZ6CN42Sv5M8SQybIj9gnYvKOJoSu0+WsPQ+DYsX4eKDsjyTsiVp2jZgmtcJnU5fx9IS0MJRATn+iRfwZh5/f8rZQwBKDnAi+Y8zkfQG8ek8FwsmoZ2v2eVh+mzOClCcoUCAB4qt8qdE5rhfUdAJQpibp+9JyJzMhQZtGWijbTXvydKfVwcbyCKyT9d7asiKjiI8FoLep0MaXiWNtEBTGk3pPJFTwi2VA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) by DB6PR0301MB2439.eurprd03.prod.outlook.com (2603:10a6:4:5b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Thu, 10 Mar 2022 20:51:51 +0000 Received: from DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::9860:b15b:f166:5896]) by DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::9860:b15b:f166:5896%3]) with mapi id 15.20.5061.022; Thu, 10 Mar 2022 20:51:51 +0000 From: Sean Anderson To: Tom Rini Cc: Liviu Dudau , u-boot@lists.denx.de, Simon Glass , Linus Walleij , Andre Przywara , Sean Anderson Subject: [PATCH v2 26/28] serial: dm: Add support for puts Date: Thu, 10 Mar 2022 15:50:56 -0500 Message-Id: <20220310205059.499269-27-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220310205059.499269-1-sean.anderson@seco.com> References: <20220310205059.499269-1-sean.anderson@seco.com> X-ClientProxiedBy: BL1PR13CA0433.namprd13.prod.outlook.com (2603:10b6:208:2c3::18) To DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0b402ed8-baed-4b02-9ff9-08da02d7cd88 X-MS-TrafficTypeDiagnostic: DB6PR0301MB2439:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VCd6oGBeR9ncJbblshtB7rKjPpK6xbfVSwNOg4X3HjP2HpL9mGnG0yCjG/uAc6AByITyGeW7mK/YUvxWK2wnhWefye1evoLRZ/kZqfmQaJwAoUAYVAobT6K5d6GPZeEMNuYjttqe8bmijLzUybdTB3Vqv1u7/sY7TD4Z85DJoBentMyF09UWK/MEvByJOaJIMf5YJcqAlDw+3Ehy84kvzlau+yRlHivirlUtp3CbDBF+ZkS0RD28oggpFfpPWR8TAzDhx9OgsYF7FdlS8QV0IWObaJA1BGEItvbMbPToGuQLNczcgrd2uoAhmMhgWrSYo2nMk+PvhjBvNZnmIzBoRve868ElpLEXS9u+SRy6dxzh9ZAdgvIYEliAQpAAvlGBWmoqWETc3jI3sAMVb8h9orsK5SnDPty4O7A0Wi+n326Evh6B67/3o4tDeO03DA8hI0WqVpcbS6QZQEivIAubsgqe+UAVIg8Npads8fyoYR90B9DW8bL24czKO6nyG7gfgHBasY9i9B/xTgPKPWna4Xmfpq9oPQhAUQ5IGm1aCRyj1f4rXDV8QgSocyZe1XscT3PN3odt5UBfL2Lk7ZfCKDm3lolcntIoflvzfZXSeCfRSyTT6F+WZIHmJ339jZAfbk2qQOK3rQXcespS8CxfCKv/JgrdDprxqhDmvKlxPPlarokvOEAt9mVOTR9P4858h1wXJJRy/H2rqY9AnWAqZA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4523.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(54906003)(66476007)(316002)(4326008)(66556008)(6916009)(8676002)(66946007)(44832011)(36756003)(86362001)(2906002)(38350700002)(38100700002)(5660300002)(8936002)(6512007)(52116002)(6486002)(6506007)(508600001)(186003)(26005)(2616005)(107886003)(1076003)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: D2AQ4CCTsjTfitv6WXF1653mPc71vU/WHuu2mTIEu7E+duVN2XL2OWzlzjHsqmr6MHj00PY//Dk4Zqmw/R/GjfuLWmOUkHBWWlO5Bsk/2kS0fGIl7Djsbx1vuz4ZuS759QS/d+rObbjUQ1gc5UaGLAv+rz29rRfennH6l5d9ZBuW0gYDVs3Ow0Tn0afVqds84Drsp0e+xoZLqPpTH7tBuGEWKoZw489HVHpOburipswZSkn7pVpLvkNqZac1VZdvcIz+E1ajZ8U4mlMXSHAmKnE26T02i5i1QBwZ9uftj4ag5Oh48IHXgkq/VUIcvFyILzuRANrgoMhroZZOuU/M79wrpF5CuzuQyr7Aae58n3ZnaqlxE/VqLo31ai2QE+/FEaNrWy21UWJu2MrtMzE8n4j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YAFoI/bUIijXoZkKpfPfIdAYbYubmiTt6MdLvngw705ggfAKfy2uhoWEkGfBS7L8i6HsrZq92vw7rkwxB2oe1R7b36ZI8vNxjbLsJz4WTrbM5h0EWUhg8vFBMayWYcpn/6ORIsVPj81aOwlplzEgyzgra4Q= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b402ed8-baed-4b02-9ff9-08da02d7cd88 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4523.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 20:51:51.6478 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Rs61QPMBV0/RsD4YEofx4/JD6BjZteNv8HK87DHd9+KuMWJR635TxbpxQUhSEcgaR7dMyOVSAeXEyNIzk1gAbA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0301MB2439 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Some serial drivers can be vastly more efficient when printing multiple characters at once. Non-DM serial has had a puts option for these sorts of drivers; implement it for DM serial as well. Because we have to add carriage returns, we can't just pass the whole string directly to the serial driver. Instead, we print up to the newline, then print a carriage return, and then continue on. This is less efficient, but it is better than printing each character individually. It also avoids having to allocate memory just to add a few characters. Drivers may perform short writes (such as filling a FIFO) and return the number of characters written in len. We loop over them in the same way that _serial_putc loops over putc. This results in around 148 bytes of bloat for all boards with DM_SERIAL enabled: vexpress_aemv8a_juno: all +148 rodata +8 text +140 u-boot: add: 2/0, grow: 0/-2 bytes: 232/-92 (140) function old new delta _serial_puts - 200 +200 strchrnul - 32 +32 serial_puts 68 24 -44 serial_stub_puts 56 8 -48 Signed-off-by: Sean Anderson --- Changes in v2: - New drivers/serial/serial-uclass.c | 27 +++++++++++++++++++++++++-- include/serial.h | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index 362cedd955..352ad986f7 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -199,8 +199,31 @@ static void _serial_putc(struct udevice *dev, char ch) static void _serial_puts(struct udevice *dev, const char *str) { - while (*str) - _serial_putc(dev, *str++); + struct dm_serial_ops *ops = serial_get_ops(dev); + + if (!ops->puts) { + while (*str) + _serial_putc(dev, *str++); + } + + do { + const char *newline = strchrnul(str, '\n'); + size_t len = newline - str + !!*newline; + + do { + int err; + size_t written = len; + + err = ops->puts(dev, str, &written); + if (err && err != -EAGAIN) + return; + str += written; + len -= written; + } while (len); + + if (*newline) + _serial_putc(dev, '\r'); + } while (*str); } static int __serial_getc(struct udevice *dev) diff --git a/include/serial.h b/include/serial.h index 2681d26c82..ea96d904d8 100644 --- a/include/serial.h +++ b/include/serial.h @@ -195,6 +195,24 @@ struct dm_serial_ops { * @return 0 if OK, -ve on error */ int (*putc)(struct udevice *dev, const char ch); + /** + * puts() - Write a string + * + * This writes a string. This function should be implemented only if + * writing multiple characters at once is more performant than just + * calling putc() in a loop. + * + * If the whole string cannot be written at once, then @len should be + * set to the number of characters written, and this function should + * return -EAGAIN. + * + * @dev: Device pointer + * @s: The string to write + * @len: The length of the string to write. This should be set to the + * number of characters actually written on return. + * @return 0 if OK, -ve on error + */ + int (*puts)(struct udevice *dev, const char *s, size_t *len); /** * pending() - Check if input/output characters are waiting *