From patchwork Thu Apr 22 11:20:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1469171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=GHDsk07u; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=J/D3AaS0; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=HkV2d+2F; dkim=neutral header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=SlIa6tjM; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FQw3c6tlSz9sTD for ; Thu, 22 Apr 2021 21:21:32 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=w3iTC5LVkEQi2BMBjmyu9TarKuYL88Bocc0Df6LR/Ws=; b=GHDsk07uUJBrmdEjiI9LsRbuP na3sozaGY8DZgxOfyzVBDPPKUFnxChTiUfuGiqvUUdelYeZMt8jrPh3yNq2RinBEl144dcevRxQ3K iYdiVAJvNIz9MM7GkNOwXuQcr3AyxEGGfZ6pf77/3FE9pFtAB/0H2s2TZdCAn20rQ5WJ529SpCwqn /4ODr1Gna8qwdQykmU8M3aqJYkmQolY70BVTvI+EHWpOFbjAwH77nOF6aOA6W/v1FAygAXXshtAhJ eXkLlwkHqmAF68qk5V9Knq4DYrcNv3JjFzoPtf6nXHeksAlP+aSC1zs/1Lgrd0XlQy3PBuSvX08Fe JWss0y+bQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZXOi-00GZv2-Ge; Thu, 22 Apr 2021 11:21:28 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZXOg-00GZtG-JJ for opensbi@desiato.infradead.org; Thu, 22 Apr 2021 11:21:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=MqEKRSr5aOLFQv3k0TLRtn7rDYG1Jma32pqZzkZneSE=; b=J/D3AaS0HfF8TYhtdbwKuhf4JH 6fd0/hsP7dCFAGCFeRvJUcaYR84KWZdvVvqH+siZWAuO6c7eLu+ND2anzLWDCEkUCUZK6JI/88m7g AdkFdtd0+jv86mimVt02zVf3MuhQZIgsSaXVsrCvjokDazGcAoZ5V8P9ZA321uRRxctRbkNFMUe6S qAGHs56Sfa+iG78N314daN6dEyXMUp7rE/Pq2tWWVtFnUDhCq5E+3+c3gaoh+kliBYmJ8cRAP8lXj 6K+Bydzx75B/vWsdnaN+Xvq2+oEMd3KrqiFxrXKn1ZH0bjh0e95ndOHIbQnDX/d63jxdpXzf6usSx xTkO5bYA==; Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZXOc-00Dc1b-PW for opensbi@lists.infradead.org; Thu, 22 Apr 2021 11:21:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1619090481; x=1650626481; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=8WGOC/L25zKBUxRwjj5GVvGX1xarHUeNXw4XMIOYlUo=; b=HkV2d+2FDhAYYYzksPVZaBafw7L7JnWGQRn4bmRrOcw/Dw4mMN1RzT+v 9b+N8l851xtI561/CXSg8lgfmRf2QkVG6VPpONs0RaJL6Iq6Fsc8yjrgX +L94fBn5qApAL8diKjxutvlRm+2/p7XEnrW2M/pEy9PumWU6DgvlsBRA/ RjZTtxiKEQO0vmr3bm+MckXbSIEXAov89QOO4MFQvTvFIHssL3DojzjBK BGAvM6ZN01twkBhmzcbcoTlFlIo4qXZw0NVF99oYaTbLxf5/X+iURqPFX JowAt59ospr6F6N2y9oKEjLSFtYaN6P4NUBtCS6jgsovOHgrk/SrLbtx/ g==; IronPort-SDR: Zt0hnXEi9zVgpQvzUt3HuLIfy+9cQ9iVISyk0Cp4Jsau+tQXEgEEuPb5xJY+WCNqfQBFEZu/jn K7NgVdfu4kSC8GLsZ5uSM5PtCtS+8IpGEXrsasfZivOK86KTrwEqnJvHY2OKpZDg2KqPCin02h /cnNK5CNS5Rkpiv+fiI61KRMzhRIp1zFI8T/5sgT/4gd+Lxch+5UTi2Uu/Y+2YQeRirG80O5Zb 3AVxxNpygbA0Nxy+jKwmLmT3bE30wFUz2piQapUSGqVpM9s4B9JJuHevlZ2+lVyRjCYthbcJSX Vow= X-IronPort-AV: E=Sophos;i="5.82,242,1613404800"; d="scan'208";a="165856912" Received: from mail-bn8nam11lp2177.outbound.protection.outlook.com (HELO NAM11-BN8-obe.outbound.protection.outlook.com) ([104.47.58.177]) by ob1.hgst.iphmx.com with ESMTP; 22 Apr 2021 19:20:59 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EuRexoVgZf/79TtwfTmFpihaEimQOagl8DkBlZUeZfuA1HiGAZv8eACNTxOSLFV4ExPXTfycJwyGkTjO1SBs3323vDT1yhfksdHb+G37qwF13Z9EFuC0YvwkwK0THjHgS0tmSuR+QGxJDyZTABN9hs7En0dKqRz6LoESIRRXHnxcKpbD4AruWzkZFce7QkIt1hr2Pow/bCfDjur4vVnRF/TSxTCel6fv5RMZdeXYMKpbo6odMXLmelkJ7JQJudCf6YhxL3baGMdq+cwfWA9KxpEDIToTBauagUbns53nt9PIXPozUxzBSvq2/ZqgEVqp5Xqj4UgkImY6KcOFFH6wpQ== 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-SenderADCheck; bh=MqEKRSr5aOLFQv3k0TLRtn7rDYG1Jma32pqZzkZneSE=; b=Ez3AlZs5VKiZACN/WRGBU8h1SzpuYty/EyKrYPDJU2Am2kCgrFj2cYcOSGZ06+m1yWBFEONB3MLK/eKqsMlzobABu3dVFgrk+8T6w/eiYwME5JVTEuQsThISGyutrKWlvrALeQGIc4CViTZ4+Qb092EgYP7D1JZEQJB5pRhH2iy+piKxhNy0BOe5zMPqL69tx1pg5JwpaHmwnYEgf6IwZoLXv/cVqwzi3EEgrtVVY/0QvbMCbo0KxX14IST5k/tERpBjYh6BXyc6QQxi2QFH69Fz4upMmNftCDQbkc78tbuHUOhpD1hWCzOhWjjssqJjWkxhGVP9OcM1S8lHcackQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MqEKRSr5aOLFQv3k0TLRtn7rDYG1Jma32pqZzkZneSE=; b=SlIa6tjMq0XC1feDOebThAkdhtFjj/IkqpmwIThMcVXSF8ovn+tlKPM+1IPaShvdAqnUFi3kmsNGSiBTVAl/I8CNmEl/S53LGwV/+x05DNnbkbkGMKGPFmxBZGtg7AmFuhqw6lw3AUjd16t0LZXnhdpLLIrtmszI+kZbedRNBM0= Authentication-Results: wdc.com; dkim=none (message not signed) header.d=none;wdc.com; dmarc=none action=none header.from=wdc.com; Received: from DM6PR04MB6201.namprd04.prod.outlook.com (2603:10b6:5:127::32) by DM6PR04MB5755.namprd04.prod.outlook.com (2603:10b6:5:162::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 11:20:58 +0000 Received: from DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::8159:3e4e:d870:bd18]) by DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::8159:3e4e:d870:bd18%3]) with mapi id 15.20.4042.024; Thu, 22 Apr 2021 11:20:58 +0000 From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 2/7] lib: sbi: Simplify console platform operations Date: Thu, 22 Apr 2021 16:50:18 +0530 Message-Id: <20210422112023.670521-3-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210422112023.670521-1-anup.patel@wdc.com> References: <20210422112023.670521-1-anup.patel@wdc.com> X-Originating-IP: [122.171.42.203] X-ClientProxiedBy: MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) To DM6PR04MB6201.namprd04.prod.outlook.com (2603:10b6:5:127::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.171.42.203) by MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.22 via Frontend Transport; Thu, 22 Apr 2021 11:20:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8297f309-2f54-468a-5b2a-08d90580b390 X-MS-TrafficTypeDiagnostic: DM6PR04MB5755: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OuS/fQmQC9iXEZ4g/XvTCbtogfLLEDXOvIxUcgUrz7y3npG204YT9WlXl4ZMz3TdZzCQ8L3n8S3Rw+OsmegZ9YdZk72pSF14tmbGP4aFzJEvp8cT3XLNi10W3TgcUBlUh2IXUHQ/KbhYHUV7XcwABfqjJlTgeiEQHvST/0JsQC0kCf8MsDHXoT0fPn3zpn3RW0WmxD9HvTfKOcR7dNi2j1YHew6MVtn88xOH1Wu9aWJ5HRK7RHSdpCqgnecUfyNeMRSkNP7fHq4x77Y+NSMT2Mf4wdcIfIXxYWwCuN66MNV0wS5XsZWOZrApIzeR0sJt4VEJ1ZJoDLCkNmtU9gK1MqlynGNFM8iwfkGK9TZlvhK8ZMj/P/+M+qAfpHJnca0/DnoyPB8WKmaFvXV4o7oVSsGf0p4ztH42OzqngJqlpjuGXdvmvaKDY+QBTTwiQqYMJXjAs2ErzfcMMdgN00bMkG7mRYFt2pQJZrs3qY/0HIiUAQXQQVyFt1wGEiFXCH6EiQsDtJBU5Vui+Yfc4JA0romuWSnzfCpE3mRUQGRD7lziY6F+CEyatTO5E/5Uw1VyxhLOY32EptDq7WU2njjliw/CrhQ9B0lvjiNaPu6UGzR3cMKGpIv4pWkur6qOeP8t3y7Nua0NfKkNuMqZezjSPzoxsKmmZFIsvyZQD658JnE= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR04MB6201.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(366004)(396003)(39860400002)(376002)(136003)(55016002)(4326008)(110136005)(86362001)(478600001)(66946007)(6636002)(5660300002)(66556008)(66476007)(38350700002)(1076003)(2906002)(6666004)(26005)(44832011)(8886007)(956004)(30864003)(38100700002)(83380400001)(186003)(2616005)(16526019)(36756003)(52116002)(7696005)(8676002)(54906003)(8936002)(316002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: aqO5wE7zmXZjWSeZcIThMo5VyYT9VELnAfDuycKVlxs54rz0n1PWbDpvea8x9UPZQbNc8doC0K4utzO/9I3BzbR+ohJj0t/WREC0k/X/yohp5vhQfOlC4wvT2LH/wk7QhVvZafJJN2KeobGhmTM+vbHV1fN/ZJaJaGnc1ssm3o3iap3dcAe77sxM8wF9dKQ5/arHsP2+LW877EM9bcOCs0zKNyDD4/zYNJx+4swYtXBKSIC5Ec+jM7FRWXiguIvhyh06T8cKm+4UIvcvRRDE58Az8z3f4WWQT6KTO666oz2mde1hzm1e4g55N1HTGw+vLONtEd3ZjGZLeAOw6LE23AgDRPLK5rCtjaNNMRvc3FDT/4e+rSTWy76OlxuDJanIUuDGUrXmbnlwn6oW5YjnGeap0isHZSng6vzPHfBCGY3M0il/Hj4QNJRVoTMGXskjMswZD7vm7XyMfx6pKzVUbcSGOv/LehBrleikEF69t9id3OfRjGRepSDv/jpW2BWwfWYyS1edNNWjb+TUgIucIAuGEDENmZykoRocMEYui5I3lSeV+8jpJfuDgkttrkRQ8vB/0E/tLuLJt8DEehleNyUxpkO71gJReDdkQUutjOipxoCs8o9oRC9kXmvSvT0Ihor1uHgRhG7or5wLKzDlqu8CvUghd5VYkl18IxyxEJItWSQbfTM1vpYG0bPsnYyG1hSPq5C2k+2hnTW57nyiEQ/xplm6gVhQ5JMNfipPxRNGx4hQskUTX44WV79NzxwoQ85uQT2zD97eBhYi1eiaDDLRVym4ddyHKe87JkOIqghTROKdOYPOz+R7X8z4i9nZ5+pGQ0QbvrB/CTuR3bxJ1EAb+C/TKQV8hUovrg0YpcRnX4hrhsp/+QAaKlWb0XyZq9hUYX2qfyOoJq1V30odDcczfoTWmQ0dTIVcy9ojSBefV9rStbxXq9Sc5g3KUIe6K1v8TEM+Y55sSd+rP7JvmHi64Xj/OJUhNAiB496e+k1CLSCeI44T3zSJiCi9S14XvVzcUv9QWcZl5Y22myCiZ+/cwr6arIO/XVYO/J3zVj3NwjmKavjfQWhrqiXkg8IS8+xzHB4ee/k88eu5IpaWlr1wvvdUxJKaGxyRZawh1CWaT0BI7zTX6Nk3HXNgnj65VGHy1WSrGaZZVO21DAK7ozEyGOuPXMFN1iifahRqOUdnZHzxZjgoLMj/eqyVoEVUjdHJwaJFDQBBRypTLTbsGoGY1RCx1OD7WUCvG5XfeCA3OOmBs3WbO5EE2zId1V1GZNGtFb/rnZMBouUeqlFBriWuUYCfjdbIYW485D/CLKoRESmNUaiTCcXerqC5ubtk X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8297f309-2f54-468a-5b2a-08d90580b390 X-MS-Exchange-CrossTenant-AuthSource: DM6PR04MB6201.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 11:20:58.2576 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cagZLGvY/gcYujWnvBdUiHXtKARarROankrjK8VhEHI9zVpWC5xjaWbE4jhbh0lguhLt4vOkgWz+/rsFzkSmug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB5755 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210422_042122_882758_2A3CB521 X-CRM114-Status: GOOD ( 19.69 ) X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Instead of having console_putc() and console_getc() callbacks in platform operations, it will be much simpler for console driver to directly register these operations as device to the sbi_console impl [...] Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [216.71.153.144 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Instead of having console_putc() and console_getc() callbacks in platform operations, it will be much simpler for console driver to directly register these operations as device to the sbi_console implementation. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis Reviewed-by: Xiang W --- include/sbi/sbi_console.h | 15 +++++++++++++ include/sbi/sbi_platform.h | 31 -------------------------- include/sbi_utils/serial/fdt_serial.h | 6 ----- include/sbi_utils/serial/shakti-uart.h | 4 ---- include/sbi_utils/serial/sifive-uart.h | 4 ---- include/sbi_utils/serial/uart8250.h | 4 ---- include/sbi_utils/sys/htif.h | 4 +--- lib/sbi/sbi_console.c | 31 +++++++++++++++++++------- lib/utils/serial/fdt_serial.c | 21 ----------------- lib/utils/serial/fdt_serial_htif.c | 10 ++++++--- lib/utils/serial/fdt_serial_shakti.c | 4 +--- lib/utils/serial/fdt_serial_sifive.c | 4 +--- lib/utils/serial/fdt_serial_uart8250.c | 2 -- lib/utils/serial/shakti-uart.c | 12 ++++++++-- lib/utils/serial/sifive-uart.c | 12 ++++++++-- lib/utils/serial/uart8250.c | 13 +++++++++-- lib/utils/sys/htif.c | 20 ++++++++++++++--- platform/andes/ae350/platform.c | 2 -- platform/fpga/ariane/platform.c | 2 -- platform/fpga/openpiton/platform.c | 2 -- platform/generic/platform.c | 2 -- platform/kendryte/k210/platform.c | 2 -- platform/nuclei/ux600/platform.c | 2 -- platform/sifive/fu540/platform.c | 2 -- platform/template/platform.c | 19 ---------------- 25 files changed, 96 insertions(+), 134 deletions(-) diff --git a/include/sbi/sbi_console.h b/include/sbi/sbi_console.h index 7d648f0..e24ba5f 100644 --- a/include/sbi/sbi_console.h +++ b/include/sbi/sbi_console.h @@ -12,6 +12,17 @@ #include +struct sbi_console_device { + /** Name of the console device */ + char name[32]; + + /** Write a character to the console output */ + void (*console_putc)(char ch); + + /** Read a character from the console input */ + int (*console_getc)(void); +}; + #define __printf(a, b) __attribute__((format(printf, a, b))) bool sbi_isprintable(char ch); @@ -32,6 +43,10 @@ int __printf(1, 2) sbi_printf(const char *format, ...); int __printf(1, 2) sbi_dprintf(const char *format, ...); +const struct sbi_console_device *sbi_console_get_device(void); + +void sbi_console_set_device(const struct sbi_console_device *dev); + struct sbi_scratch; int sbi_console_init(struct sbi_scratch *scratch); diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 6736169..0d18ef2 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -95,10 +95,6 @@ struct sbi_platform_operations { /** Initialize (or populate) domains for the platform */ int (*domains_init)(void); - /** Write a character to the platform console output */ - void (*console_putc)(char ch); - /** Read a character from the platform console input */ - int (*console_getc)(void); /** Initialize the platform console */ int (*console_init)(void); @@ -496,33 +492,6 @@ static inline int sbi_platform_domains_init(const struct sbi_platform *plat) return 0; } -/** - * Write a character to the platform console output - * - * @param plat pointer to struct sbi_platform - * @param ch character to write - */ -static inline void sbi_platform_console_putc(const struct sbi_platform *plat, - char ch) -{ - if (plat && sbi_platform_ops(plat)->console_putc) - sbi_platform_ops(plat)->console_putc(ch); -} - -/** - * Read a character from the platform console input - * - * @param plat pointer to struct sbi_platform - * - * @return character read from console input - */ -static inline int sbi_platform_console_getc(const struct sbi_platform *plat) -{ - if (plat && sbi_platform_ops(plat)->console_getc) - return sbi_platform_ops(plat)->console_getc(); - return -1; -} - /** * Initialize the platform console * diff --git a/include/sbi_utils/serial/fdt_serial.h b/include/sbi_utils/serial/fdt_serial.h index 08f9799..6451c23 100644 --- a/include/sbi_utils/serial/fdt_serial.h +++ b/include/sbi_utils/serial/fdt_serial.h @@ -15,14 +15,8 @@ struct fdt_serial { const struct fdt_match *match_table; int (*init)(void *fdt, int nodeoff, const struct fdt_match *match); - void (*putc)(char ch); - int (*getc)(void); }; -void fdt_serial_putc(char ch); - -int fdt_serial_getc(void); - int fdt_serial_init(void); #endif diff --git a/include/sbi_utils/serial/shakti-uart.h b/include/sbi_utils/serial/shakti-uart.h index 08043be..bcb019e 100644 --- a/include/sbi_utils/serial/shakti-uart.h +++ b/include/sbi_utils/serial/shakti-uart.h @@ -9,10 +9,6 @@ #include -void shakti_uart_putc(char ch); - -int shakti_uart_getc(void); - int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate); #endif diff --git a/include/sbi_utils/serial/sifive-uart.h b/include/sbi_utils/serial/sifive-uart.h index f323392..9c465ec 100644 --- a/include/sbi_utils/serial/sifive-uart.h +++ b/include/sbi_utils/serial/sifive-uart.h @@ -12,10 +12,6 @@ #include -void sifive_uart_putc(char ch); - -int sifive_uart_getc(void); - int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate); #endif diff --git a/include/sbi_utils/serial/uart8250.h b/include/sbi_utils/serial/uart8250.h index 0a1b5d3..6b9b48b 100644 --- a/include/sbi_utils/serial/uart8250.h +++ b/include/sbi_utils/serial/uart8250.h @@ -12,10 +12,6 @@ #include -void uart8250_putc(char ch); - -int uart8250_getc(void); - int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift, u32 reg_width); diff --git a/include/sbi_utils/sys/htif.h b/include/sbi_utils/sys/htif.h index a431723..8073a44 100644 --- a/include/sbi_utils/sys/htif.h +++ b/include/sbi_utils/sys/htif.h @@ -10,9 +10,7 @@ #include -void htif_putc(char ch); - -int htif_getc(void); +int htif_serial_init(void); int htif_system_reset_check(u32 type, u32 reason); diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 7189b9b..b54f7a2 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -12,7 +12,7 @@ #include #include -static const struct sbi_platform *console_plat = NULL; +static const struct sbi_console_device *console_dev = NULL; static spinlock_t console_out_lock = SPIN_LOCK_INITIALIZER; bool sbi_isprintable(char c) @@ -26,14 +26,18 @@ bool sbi_isprintable(char c) int sbi_getc(void) { - return sbi_platform_console_getc(console_plat); + if (console_dev && console_dev->console_getc) + return console_dev->console_getc(); + return -1; } void sbi_putc(char ch) { - if (ch == '\n') - sbi_platform_console_putc(console_plat, '\r'); - sbi_platform_console_putc(console_plat, ch); + if (console_dev && console_dev->console_putc) { + if (ch == '\n') + console_dev->console_putc('\r'); + console_dev->console_putc(ch); + } } void sbi_puts(const char *str) @@ -390,9 +394,20 @@ int sbi_dprintf(const char *format, ...) return retval; } -int sbi_console_init(struct sbi_scratch *scratch) +const struct sbi_console_device *sbi_console_get_device(void) +{ + return console_dev; +} + +void sbi_console_set_device(const struct sbi_console_device *dev) { - console_plat = sbi_platform_ptr(scratch); + if (!dev || console_dev) + return; - return sbi_platform_console_init(console_plat); + console_dev = dev; +} + +int sbi_console_init(struct sbi_scratch *scratch) +{ + return sbi_platform_console_init(sbi_platform_ptr(scratch)); } diff --git a/lib/utils/serial/fdt_serial.c b/lib/utils/serial/fdt_serial.c index b9ce67e..43c55e8 100644 --- a/lib/utils/serial/fdt_serial.c +++ b/lib/utils/serial/fdt_serial.c @@ -24,34 +24,13 @@ static struct fdt_serial *serial_drivers[] = { &fdt_serial_shakti, }; -static void dummy_putc(char ch) -{ -} - -static int dummy_getc(void) -{ - return -1; -} - static struct fdt_serial dummy = { .match_table = NULL, .init = NULL, - .putc = dummy_putc, - .getc = dummy_getc, }; static struct fdt_serial *current_driver = &dummy; -void fdt_serial_putc(char ch) -{ - current_driver->putc(ch); -} - -int fdt_serial_getc(void) -{ - return current_driver->getc(); -} - int fdt_serial_init(void) { const void *prop; diff --git a/lib/utils/serial/fdt_serial_htif.c b/lib/utils/serial/fdt_serial_htif.c index 32d6953..fae55b8 100644 --- a/lib/utils/serial/fdt_serial_htif.c +++ b/lib/utils/serial/fdt_serial_htif.c @@ -16,9 +16,13 @@ static const struct fdt_match serial_htif_match[] = { { }, }; +static int serial_htif_init(void *fdt, int nodeoff, + const struct fdt_match *match) +{ + return htif_serial_init(); +} + struct fdt_serial fdt_serial_htif = { .match_table = serial_htif_match, - .init = NULL, - .getc = htif_getc, - .putc = htif_putc + .init = serial_htif_init }; diff --git a/lib/utils/serial/fdt_serial_shakti.c b/lib/utils/serial/fdt_serial_shakti.c index c6385a5..4f91419 100644 --- a/lib/utils/serial/fdt_serial_shakti.c +++ b/lib/utils/serial/fdt_serial_shakti.c @@ -29,7 +29,5 @@ static const struct fdt_match serial_shakti_match[] = { struct fdt_serial fdt_serial_shakti = { .match_table = serial_shakti_match, - .init = serial_shakti_init, - .getc = shakti_uart_getc, - .putc = shakti_uart_putc + .init = serial_shakti_init }; diff --git a/lib/utils/serial/fdt_serial_sifive.c b/lib/utils/serial/fdt_serial_sifive.c index 9e487a2..f4c833c 100644 --- a/lib/utils/serial/fdt_serial_sifive.c +++ b/lib/utils/serial/fdt_serial_sifive.c @@ -32,7 +32,5 @@ static const struct fdt_match serial_sifive_match[] = { struct fdt_serial fdt_serial_sifive = { .match_table = serial_sifive_match, - .init = serial_sifive_init, - .getc = sifive_uart_getc, - .putc = sifive_uart_putc + .init = serial_sifive_init }; diff --git a/lib/utils/serial/fdt_serial_uart8250.c b/lib/utils/serial/fdt_serial_uart8250.c index 5030b82..918193a 100644 --- a/lib/utils/serial/fdt_serial_uart8250.c +++ b/lib/utils/serial/fdt_serial_uart8250.c @@ -34,6 +34,4 @@ static const struct fdt_match serial_uart8250_match[] = { struct fdt_serial fdt_serial_uart8250 = { .match_table = serial_uart8250_match, .init = serial_uart8250_init, - .getc = uart8250_getc, - .putc = uart8250_putc }; diff --git a/lib/utils/serial/shakti-uart.c b/lib/utils/serial/shakti-uart.c index 7c1148e..e77a985 100644 --- a/lib/utils/serial/shakti-uart.c +++ b/lib/utils/serial/shakti-uart.c @@ -23,14 +23,14 @@ static volatile void *uart_base; -void shakti_uart_putc(char ch) +static void shakti_uart_putc(char ch) { while((readw(uart_base + REG_STATUS) & UART_TX_FULL)) ; writeb(ch, uart_base + REG_TX); } -int shakti_uart_getc(void) +static int shakti_uart_getc(void) { u16 status = readw(uart_base + REG_STATUS); if (status & UART_RX_FULL) @@ -38,11 +38,19 @@ int shakti_uart_getc(void) return -1; } +static struct sbi_console_device shakti_console = { + .name = "shakti_uart", + .console_putc = shakti_uart_putc, + .console_getc = shakti_uart_getc +}; + int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate) { uart_base = (volatile void *)base; u16 baud = (u16)(in_freq/(16 * baudrate)); writew(baud, uart_base + REG_BAUD); + sbi_console_set_device(&shakti_console); + return 0; } diff --git a/lib/utils/serial/sifive-uart.c b/lib/utils/serial/sifive-uart.c index 72c8a62..57d80fa 100644 --- a/lib/utils/serial/sifive-uart.c +++ b/lib/utils/serial/sifive-uart.c @@ -66,7 +66,7 @@ static void set_reg(u32 num, u32 val) writel(val, uart_base + (num * 0x4)); } -void sifive_uart_putc(char ch) +static void sifive_uart_putc(char ch) { while (get_reg(UART_REG_TXFIFO) & UART_TXFIFO_FULL) ; @@ -74,7 +74,7 @@ void sifive_uart_putc(char ch) set_reg(UART_REG_TXFIFO, ch); } -int sifive_uart_getc(void) +static int sifive_uart_getc(void) { u32 ret = get_reg(UART_REG_RXFIFO); if (!(ret & UART_RXFIFO_EMPTY)) @@ -82,6 +82,12 @@ int sifive_uart_getc(void) return -1; } +static struct sbi_console_device sifive_console = { + .name = "sifive_uart", + .console_putc = sifive_uart_putc, + .console_getc = sifive_uart_getc +}; + int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate) { uart_base = (volatile void *)base; @@ -98,5 +104,7 @@ int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate) /* Enable Rx */ set_reg(UART_REG_RXCTRL, UART_RXCTRL_RXEN); + sbi_console_set_device(&sifive_console); + return 0; } diff --git a/lib/utils/serial/uart8250.c b/lib/utils/serial/uart8250.c index 9635ba8..1cf6624 100644 --- a/lib/utils/serial/uart8250.c +++ b/lib/utils/serial/uart8250.c @@ -8,6 +8,7 @@ */ #include +#include #include /* clang-format off */ @@ -68,7 +69,7 @@ static void set_reg(u32 num, u32 val) writel(val, uart8250_base + offset); } -void uart8250_putc(char ch) +static void uart8250_putc(char ch) { while ((get_reg(UART_LSR_OFFSET) & UART_LSR_THRE) == 0) ; @@ -76,13 +77,19 @@ void uart8250_putc(char ch) set_reg(UART_THR_OFFSET, ch); } -int uart8250_getc(void) +static int uart8250_getc(void) { if (get_reg(UART_LSR_OFFSET) & UART_LSR_DR) return get_reg(UART_RBR_OFFSET); return -1; } +static struct sbi_console_device uart8250_console = { + .name = "uart8250", + .console_putc = uart8250_putc, + .console_getc = uart8250_getc +}; + int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift, u32 reg_width) { @@ -121,5 +128,7 @@ int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift, /* Set scratchpad */ set_reg(UART_SCR_OFFSET, 0x00); + sbi_console_set_device(&uart8250_console); + return 0; } diff --git a/lib/utils/sys/htif.c b/lib/utils/sys/htif.c index fd70fb9..2fd38a7 100644 --- a/lib/utils/sys/htif.c +++ b/lib/utils/sys/htif.c @@ -6,6 +6,7 @@ */ #include +#include #include #define HTIF_DATA_BITS 48 @@ -98,7 +99,7 @@ static void do_tohost_fromhost(uint64_t dev, uint64_t cmd, uint64_t data) spin_unlock(&htif_lock); } -void htif_putc(char ch) +static void htif_putc(char ch) { /* HTIF devices are not supported on RV32, so do a proxy write call */ volatile uint64_t magic_mem[8]; @@ -109,7 +110,7 @@ void htif_putc(char ch) do_tohost_fromhost(HTIF_DEV_SYSTEM, 0, (uint64_t)(uintptr_t)magic_mem); } #else -void htif_putc(char ch) +static void htif_putc(char ch) { spin_lock(&htif_lock); __set_tohost(HTIF_DEV_CONSOLE, HTIF_CONSOLE_CMD_PUTC, ch); @@ -117,7 +118,7 @@ void htif_putc(char ch) } #endif -int htif_getc(void) +static int htif_getc(void) { int ch; @@ -140,6 +141,19 @@ int htif_getc(void) return ch - 1; } +static struct sbi_console_device htif_console = { + .name = "htif", + .console_putc = htif_putc, + .console_getc = htif_getc +}; + +int htif_serial_init(void) +{ + sbi_console_set_device(&htif_console); + + return 0; +} + int htif_system_reset_check(u32 type, u32 reason) { return 1; diff --git a/platform/andes/ae350/platform.c b/platform/andes/ae350/platform.c index aec91cd..338159d 100644 --- a/platform/andes/ae350/platform.c +++ b/platform/andes/ae350/platform.c @@ -164,8 +164,6 @@ const struct sbi_platform_operations platform_ops = { .final_init = ae350_final_init, .console_init = ae350_console_init, - .console_putc = uart8250_putc, - .console_getc = uart8250_getc, .irqchip_init = ae350_irqchip_init, diff --git a/platform/fpga/ariane/platform.c b/platform/fpga/ariane/platform.c index ea179e5..4f32c42 100644 --- a/platform/fpga/ariane/platform.c +++ b/platform/fpga/ariane/platform.c @@ -154,8 +154,6 @@ const struct sbi_platform_operations platform_ops = { .early_init = ariane_early_init, .final_init = ariane_final_init, .console_init = ariane_console_init, - .console_putc = uart8250_putc, - .console_getc = uart8250_getc, .irqchip_init = ariane_irqchip_init, .ipi_init = ariane_ipi_init, .ipi_send = clint_ipi_send, diff --git a/platform/fpga/openpiton/platform.c b/platform/fpga/openpiton/platform.c index 5eae477..77403c9 100644 --- a/platform/fpga/openpiton/platform.c +++ b/platform/fpga/openpiton/platform.c @@ -180,8 +180,6 @@ const struct sbi_platform_operations platform_ops = { .early_init = openpiton_early_init, .final_init = openpiton_final_init, .console_init = openpiton_console_init, - .console_putc = uart8250_putc, - .console_getc = uart8250_getc, .irqchip_init = openpiton_irqchip_init, .ipi_init = openpiton_ipi_init, .ipi_send = clint_ipi_send, diff --git a/platform/generic/platform.c b/platform/generic/platform.c index 8c1e06f..445cbcf 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -210,8 +210,6 @@ const struct sbi_platform_operations platform_ops = { .early_exit = generic_early_exit, .final_exit = generic_final_exit, .domains_init = generic_domains_init, - .console_putc = fdt_serial_putc, - .console_getc = fdt_serial_getc, .console_init = fdt_serial_init, .irqchip_init = fdt_irqchip_init, .irqchip_exit = fdt_irqchip_exit, diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 0c50af5..495d214 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -149,8 +149,6 @@ const struct sbi_platform_operations platform_ops = { .final_init = k210_final_init, .console_init = k210_console_init, - .console_putc = sifive_uart_putc, - .console_getc = sifive_uart_getc, .irqchip_init = k210_irqchip_init, diff --git a/platform/nuclei/ux600/platform.c b/platform/nuclei/ux600/platform.c index d0a45a2..4f4f884 100644 --- a/platform/nuclei/ux600/platform.c +++ b/platform/nuclei/ux600/platform.c @@ -202,8 +202,6 @@ static void ux600_system_reset(u32 type, u32 reason) const struct sbi_platform_operations platform_ops = { .early_init = ux600_early_init, .final_init = ux600_final_init, - .console_putc = sifive_uart_putc, - .console_getc = sifive_uart_getc, .console_init = ux600_console_init, .irqchip_init = ux600_irqchip_init, .ipi_send = clint_ipi_send, diff --git a/platform/sifive/fu540/platform.c b/platform/sifive/fu540/platform.c index cdd8293..82f6f75 100644 --- a/platform/sifive/fu540/platform.c +++ b/platform/sifive/fu540/platform.c @@ -156,8 +156,6 @@ static u32 fu540_hart_index2id[FU540_HART_COUNT - 1] = { const struct sbi_platform_operations platform_ops = { .final_init = fu540_final_init, - .console_putc = sifive_uart_putc, - .console_getc = sifive_uart_getc, .console_init = fu540_console_init, .irqchip_init = fu540_irqchip_init, .ipi_send = clint_ipi_send, diff --git a/platform/template/platform.c b/platform/template/platform.c index 5bdb186..fbbac30 100644 --- a/platform/template/platform.c +++ b/platform/template/platform.c @@ -63,23 +63,6 @@ static int platform_console_init(void) PLATFORM_UART_BAUDRATE, 0, 1); } -/* - * Write a character to the platform console output. - */ -static void platform_console_putc(char ch) -{ - /* Example if the generic UART8250 driver is used */ - uart8250_putc(ch); -} - -/* - * Read a character from the platform console input. - */ -static int platform_console_getc(void) -{ - return uart8250_getc(); -} - /* * Initialize the platform interrupt controller for current HART. */ @@ -198,8 +181,6 @@ static void platform_system_reset(u32 type, u32 reason) const struct sbi_platform_operations platform_ops = { .early_init = platform_early_init, .final_init = platform_final_init, - .console_putc = platform_console_putc, - .console_getc = platform_console_getc, .console_init = platform_console_init, .irqchip_init = platform_irqchip_init, .ipi_send = platform_ipi_send,