From nobody Thu May 16 07:12:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1591827914; cv=none; d=zohomail.com; s=zohoarc; b=TdKwHaPl3xDYc1cDGb18cXx4UuA/0CNIFwcxGj7X9rWSoccN86uDgcPrTrnK8bzBQO05K0NPKXFBp23wiNNoyaKQmDcjH2UE3TvHq1+/0RnplJtOZiiHuG0FPgTJ+NvswObV4S6BKurF1AjmJ8wlt6CISaIUC5qlPHrA3aOWyCA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591827914; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=44BYYKR8sjEgBTnS+htAFcCV9q3MmgOzDKTxlt9CX9o=; b=Xszigmf4nbYBsvx2OsWzD+dk/2hwEOCZLnIfxKm51ttZTfdVxI5GxTBa5jjxQeEQo+6/Cwvj2at9VEDQvZDSauDkGB3fGUwmkrRJF5P1d5g0TgyQrYbU6pwk/xmgWMb4rleZ+LX3/mVOLoDKqDvi4Pepl8lV53zt5nFhw4P7rbs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591827914249320.60166311884143; Wed, 10 Jun 2020 15:25:14 -0700 (PDT) Received: from localhost ([::1]:46442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj99k-0002Pk-W9 for importer@patchew.org; Wed, 10 Jun 2020 18:25:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj95u-0004LP-Ge; Wed, 10 Jun 2020 18:21:14 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:59139) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj95t-00023G-5A; Wed, 10 Jun 2020 18:21:14 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Jun 2020 06:21:08 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 15:10:34 -0700 Received: from us4qd5p12.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.58.34]) by uls-op-cesaip02.wdc.com with ESMTP; 10 Jun 2020 15:21:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591827672; x=1623363672; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VXvPydcV3oG3Eb03rcTetmZt+5SiUVZX+S5uCVjMvU0=; b=UhHufcQbVm8/D5MwY1t+JOVatkOacwUZv+YQfdNK1jdF2setAhSybomj Kgxx/gZrHYssZ3PmgLOYw04KwDbrmfNnFBM/IkZxK/7NbogBgzUVP0c7z hdkVqdpPk7l1BGeGxemQE6fd7ensv2j31qOkrozpBdfGC8fvGBzMmPtDL fMsPO60IuWe4Sdv3Fou+ISF0BrmbDCHinB0cyHFsl8Usy9kuSdwMs+DBf mfdYZnm9p81Lqm8twG+otb+d8Q8zKBcv9C8H1Nh2IiTWIV/oEG5OKtVZB CDtMU33Dl4XRsdODKu8xpMyX0aq9oQDZMtpmNzzkMT+w/m9lQLEMm2fqS w==; IronPort-SDR: EATAsk3piwtgSUlEms79f5+neN7EeeYUVqu0mdkIwdDvPCZso7/eg2S21/IU4sttX3nOJJmPTo QGgPht37UIFOybIZ7utfSNpOx1xCcL38/Do3Li+Ag6vQGZponKcZXqQz+bSIJRa1Rp0hzU5PXd XBqmoC+SEB6tSjaRBGrBz5QAXb3pJT9xfSOhj8MwdlPpjRmChTl1J6ANNKslap5+mK7WcXSFEr fuC4/QeOG9hM8AkHtdHjDB6xY4Sk+pkvybLBEROFNbEUJe0TktE9TnPrGm1VFSP/wBiwxWLBB9 GqE= X-IronPort-AV: E=Sophos;i="5.73,497,1583164800"; d="scan'208";a="248819307" IronPort-SDR: em4gQod2I33wuftNjaByBDw6F0otLSJ83K1BHjnxKG5Eako8NldvC1RhvCbX1v3VmooQmmJDxs hkO5ZPmYwg80NLqLjMEL90vov1OdhoCkc= IronPort-SDR: P6gAm0pnUqwEmpqtCZdhD5DJ+E2EhUL0nCJzbWwK6vFzlwehSZeEr1DwJ4s/ocsFMQbyarnxUA c4fgxITEzR9w== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v6 1/6] riscv/opentitan: Fix the ROM size Date: Wed, 10 Jun 2020 15:12:11 -0700 Message-Id: <6cb4f31c9b72af4fb81848c233e1be77d1e0e83c.1591827110.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=4234ccaf3=alistair.francis@wdc.com; helo=esa1.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/10 18:21:06 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Alistair Francis Reported-by: Damien Hedde --- hw/riscv/opentitan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c index b4fb836466..6c7359c190 100644 --- a/hw/riscv/opentitan.c +++ b/hw/riscv/opentitan.c @@ -30,7 +30,7 @@ static const struct MemmapEntry { hwaddr base; hwaddr size; } ibex_memmap[] =3D { - [IBEX_ROM] =3D { 0x00008000, 0xc000 }, + [IBEX_ROM] =3D { 0x00008000, 16 * KiB }, [IBEX_RAM] =3D { 0x10000000, 0x10000 }, [IBEX_FLASH] =3D { 0x20000000, 0x80000 }, [IBEX_UART] =3D { 0x40000000, 0x10000 }, --=20 2.26.2 From nobody Thu May 16 07:12:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1591827768; cv=none; d=zohomail.com; s=zohoarc; b=QPMBVC16u33mo0Mc3Z/f19OKMLMdIzQX0N2/UHc7VZBx6AkoaCkdF+0yx8fCzDt+370vFMIAp/HK37a3+9hDNB0zB76qQc6DWZ2DFK2SFUZ5Y2px8SpNhrWtKEvNRej1y7EoYyPA6sUuoczetIXR0fj1L+kgeMV9N8scsdqCvmE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591827768; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ppJHgAVloTwbouI8UWqj/SCwOXhWP6/na85J+6TAVFQ=; b=OD265pwnfZYa/RJLsdhkZLp2A2bIccQMOev/vJQzZvBQsQdEoMSqnsthm9Q+j2e+6BSN91cDRmDrdFhKW8fPnJLOlsUwaZcB13VQuVEFIL/OosAdxeNYMmQQ+Z5zkqz68GljmoFY+PgD22FcY+6b81DVb29hJoya7KNBvcfleWU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591827768705365.2030826067604; Wed, 10 Jun 2020 15:22:48 -0700 (PDT) Received: from localhost ([::1]:37056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj97P-00064c-CU for importer@patchew.org; Wed, 10 Jun 2020 18:22:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42562) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj95w-0004OJ-PG; Wed, 10 Jun 2020 18:21:16 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:59124) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj95u-000237-K5; Wed, 10 Jun 2020 18:21:16 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Jun 2020 06:21:10 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 15:10:37 -0700 Received: from us4qd5p12.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.58.34]) by uls-op-cesaip02.wdc.com with ESMTP; 10 Jun 2020 15:21:10 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591827674; x=1623363674; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vBsO6nahuh+XIaOaytIjtvKtxuylrNHjpzkwuKlaxDU=; b=cSdjNNy/yJVBK3pmU+qyYzPA9IQEr30r3I9lv/Ed2H/MxsV2pmowHj52 PHWIJ5aV9d11jQlKTzi6jFNvRoKnVKWui3eIlIvgfWsptPHs20plM83PD aBb89yCFiEe+mikPbMdQmNFkE8tb6cwZUjmGlwGz60ZpjyiZADIQICafF ohyw3ARsm9feqhfoyj0QEE1MD4Azlmt5diAm5Q0QjZjptaldmI+Z5DqNJ PsQrKtzg5VK98P1uxEG61TF9Izct+Gfay64SGG5ZIfA+rik26/U8xKUE4 0ZV+xVlT+yZD+QLSd4GBbHlvrt+EczUTNJIJY1j+QQuwgYbkm90iM5FRJ A==; IronPort-SDR: NkdQstFPe5vnI2kip3vQS+RE5hzGj72vBiFb2NkDh9g9pr5PsnG2HB+CNp/9wEme1kc18Dkq/H e9vNVp86J8jw9bkbASHqLusX2lnFyAezLe1JtUTKi4SQ7cf0M9CYxIfMqnajH2W8kBHmr8pOBT MNAnwN01GrtIf9nl5sFs6YDJTIGUOf1LfcS9nxYC+psEgalk/eJE+Ov1OXaMEFG1DRuoymXCiX 13Kch8n8gfQB5Q2EQZtgoxLVMhfW6dVvCczadQF16kmPPPq7aIr6NE3R/rbRnYD2yEbaXe1zvs UYU= X-IronPort-AV: E=Sophos;i="5.73,497,1583164800"; d="scan'208";a="248819312" IronPort-SDR: FgKaNjU/q7IEjnXtbwSDUV/oxamnggduCtJZQSuwIEm3AZIZ1As7FWES8CsPhPjvUaK0c/Inki 5mMHw7UQ05ufoOSFKL9yCZR6jSS9dAH/8= IronPort-SDR: MnHhkaLxzscbwuRI3LdQQI3gzfJVKsGHEhqzBEiEXzxLvHpDKwmtBWTEHQWEw+S2v/pVUcBg2M RnLSVmitUmZA== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v6 2/6] hw/char: Initial commit of Ibex UART Date: Wed, 10 Jun 2020 15:12:14 -0700 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=4234ccaf3=alistair.francis@wdc.com; helo=esa1.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/10 18:21:06 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is the initial commit of the Ibex UART device. Serial TX is working, while RX has been implemeneted but untested. This is based on the documentation from: https://docs.opentitan.org/hw/ip/uart/doc/ Signed-off-by: Alistair Francis Reviewed-by: LIU Zhiwei --- include/hw/char/ibex_uart.h | 110 ++++++++ hw/char/ibex_uart.c | 492 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + hw/char/Makefile.objs | 1 + hw/riscv/Kconfig | 4 + 5 files changed, 609 insertions(+) create mode 100644 include/hw/char/ibex_uart.h create mode 100644 hw/char/ibex_uart.c diff --git a/include/hw/char/ibex_uart.h b/include/hw/char/ibex_uart.h new file mode 100644 index 0000000000..2bec772615 --- /dev/null +++ b/include/hw/char/ibex_uart.h @@ -0,0 +1,110 @@ +/* + * QEMU lowRISC Ibex UART device + * + * Copyright (c) 2020 Western Digital + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef HW_IBEX_UART_H +#define HW_IBEX_UART_H + +#include "hw/sysbus.h" +#include "chardev/char-fe.h" +#include "qemu/timer.h" + +#define IBEX_UART_INTR_STATE 0x00 + #define INTR_STATE_TX_WATERMARK (1 << 0) + #define INTR_STATE_RX_WATERMARK (1 << 1) + #define INTR_STATE_TX_EMPTY (1 << 2) + #define INTR_STATE_RX_OVERFLOW (1 << 3) +#define IBEX_UART_INTR_ENABLE 0x04 +#define IBEX_UART_INTR_TEST 0x08 + +#define IBEX_UART_CTRL 0x0c + #define UART_CTRL_TX_ENABLE (1 << 0) + #define UART_CTRL_RX_ENABLE (1 << 1) + #define UART_CTRL_NF (1 << 2) + #define UART_CTRL_SLPBK (1 << 4) + #define UART_CTRL_LLPBK (1 << 5) + #define UART_CTRL_PARITY_EN (1 << 6) + #define UART_CTRL_PARITY_ODD (1 << 7) + #define UART_CTRL_RXBLVL (3 << 8) + #define UART_CTRL_NCO (0xFFFF << 16) + +#define IBEX_UART_STATUS 0x10 + #define UART_STATUS_TXFULL (1 << 0) + #define UART_STATUS_RXFULL (1 << 1) + #define UART_STATUS_TXEMPTY (1 << 2) + #define UART_STATUS_RXIDLE (1 << 4) + #define UART_STATUS_RXEMPTY (1 << 5) + +#define IBEX_UART_RDATA 0x14 +#define IBEX_UART_WDATA 0x18 + +#define IBEX_UART_FIFO_CTRL 0x1c + #define FIFO_CTRL_RXRST (1 << 0) + #define FIFO_CTRL_TXRST (1 << 1) + #define FIFO_CTRL_RXILVL (7 << 2) + #define FIFO_CTRL_RXILVL_SHIFT (2) + #define FIFO_CTRL_TXILVL (3 << 5) + #define FIFO_CTRL_TXILVL_SHIFT (5) + +#define IBEX_UART_FIFO_STATUS 0x20 +#define IBEX_UART_OVRD 0x24 +#define IBEX_UART_VAL 0x28 +#define IBEX_UART_TIMEOUT_CTRL 0x2c + +#define IBEX_UART_TX_FIFO_SIZE 16 + +#define TYPE_IBEX_UART "ibex-uart" +#define IBEX_UART(obj) \ + OBJECT_CHECK(IbexUartState, (obj), TYPE_IBEX_UART) + +typedef struct { + /* */ + SysBusDevice parent_obj; + + /* */ + MemoryRegion mmio; + + uint8_t tx_fifo[IBEX_UART_TX_FIFO_SIZE]; + uint32_t tx_level; + + QEMUTimer *fifo_trigger_handle; + uint64_t char_tx_time; + + uint32_t uart_intr_state; + uint32_t uart_intr_enable; + uint32_t uart_ctrl; + uint32_t uart_status; + uint32_t uart_rdata; + uint32_t uart_fifo_ctrl; + uint32_t uart_fifo_status; + uint32_t uart_ovrd; + uint32_t uart_val; + uint32_t uart_timeout_ctrl; + + CharBackend chr; + qemu_irq tx_watermark; + qemu_irq rx_watermark; + qemu_irq tx_empty; + qemu_irq rx_overflow; +} IbexUartState; +#endif /* HW_IBEX_UART_H */ diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c new file mode 100644 index 0000000000..3e0dd9968e --- /dev/null +++ b/hw/char/ibex_uart.c @@ -0,0 +1,492 @@ +/* + * QEMU lowRISC Ibex UART device + * + * Copyright (c) 2020 Western Digital + * + * For details check the documentation here: + * https://docs.opentitan.org/hw/ip/uart/doc/ + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/char/ibex_uart.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "migration/vmstate.h" +#include "qemu/log.h" +#include "qemu/module.h" + +static void ibex_uart_update_irqs(IbexUartState *s) +{ + if (s->uart_intr_state & s->uart_intr_enable & INTR_STATE_TX_WATERMARK= ) { + qemu_set_irq(s->tx_watermark, 1); + } else { + qemu_set_irq(s->tx_watermark, 0); + } + + if (s->uart_intr_state & s->uart_intr_enable & INTR_STATE_RX_WATERMARK= ) { + qemu_set_irq(s->rx_watermark, 1); + } else { + qemu_set_irq(s->rx_watermark, 0); + } + + if (s->uart_intr_state & s->uart_intr_enable & INTR_STATE_TX_EMPTY) { + qemu_set_irq(s->tx_empty, 1); + } else { + qemu_set_irq(s->tx_empty, 0); + } + + if (s->uart_intr_state & s->uart_intr_enable & INTR_STATE_RX_OVERFLOW)= { + qemu_set_irq(s->rx_overflow, 1); + } else { + qemu_set_irq(s->rx_overflow, 0); + } +} + +static int ibex_uart_can_receive(void *opaque) +{ + IbexUartState *s =3D opaque; + + if (s->uart_ctrl & UART_CTRL_RX_ENABLE) { + return 1; + } + + return 0; +} + +static void ibex_uart_receive(void *opaque, const uint8_t *buf, int size) +{ + IbexUartState *s =3D opaque; + uint8_t rx_fifo_level =3D (s->uart_fifo_ctrl & FIFO_CTRL_RXILVL) + >> FIFO_CTRL_RXILVL_SHIFT; + + s->uart_rdata =3D *buf; + + s->uart_status &=3D ~UART_STATUS_RXIDLE; + s->uart_status &=3D ~UART_STATUS_RXEMPTY; + + if (size > rx_fifo_level) { + s->uart_intr_state |=3D INTR_STATE_RX_WATERMARK; + } + + ibex_uart_update_irqs(s); +} + +static gboolean ibex_uart_xmit(GIOChannel *chan, GIOCondition cond, + void *opaque) +{ + IbexUartState *s =3D opaque; + uint8_t tx_fifo_level =3D (s->uart_fifo_ctrl & FIFO_CTRL_TXILVL) + >> FIFO_CTRL_TXILVL_SHIFT; + int ret; + + /* instant drain the fifo when there's no back-end */ + if (!qemu_chr_fe_backend_connected(&s->chr)) { + s->tx_level =3D 0; + return FALSE; + } + + if (!s->tx_level) { + s->uart_status &=3D ~UART_STATUS_TXFULL; + s->uart_status |=3D UART_STATUS_TXEMPTY; + s->uart_intr_state |=3D INTR_STATE_TX_EMPTY; + s->uart_intr_state &=3D ~INTR_STATE_TX_WATERMARK; + ibex_uart_update_irqs(s); + return FALSE; + } + + ret =3D qemu_chr_fe_write(&s->chr, s->tx_fifo, s->tx_level); + + if (ret >=3D 0) { + s->tx_level -=3D ret; + memmove(s->tx_fifo, s->tx_fifo + ret, s->tx_level); + } + + if (s->tx_level) { + guint r =3D qemu_chr_fe_add_watch(&s->chr, G_IO_OUT | G_IO_HUP, + ibex_uart_xmit, s); + if (!r) { + s->tx_level =3D 0; + return FALSE; + } + } + + /* Clear the TX Full bit */ + if (s->tx_level !=3D IBEX_UART_TX_FIFO_SIZE) { + s->uart_status &=3D ~UART_STATUS_TXFULL; + } + + /* Disable the TX_WATERMARK IRQ */ + if (s->tx_level < tx_fifo_level) { + s->uart_intr_state &=3D ~INTR_STATE_TX_WATERMARK; + } + + /* Set TX empty */ + if (s->tx_level =3D=3D 0) { + s->uart_status |=3D UART_STATUS_TXEMPTY; + s->uart_intr_state |=3D INTR_STATE_TX_EMPTY; + } + + ibex_uart_update_irqs(s); + return FALSE; +} + +static void uart_write_tx_fifo(IbexUartState *s, const uint8_t *buf, + int size) +{ + uint64_t current_time =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + uint8_t tx_fifo_level =3D (s->uart_fifo_ctrl & FIFO_CTRL_TXILVL) + >> FIFO_CTRL_TXILVL_SHIFT; + + if (size > IBEX_UART_TX_FIFO_SIZE - s->tx_level) { + size =3D IBEX_UART_TX_FIFO_SIZE - s->tx_level; + qemu_log_mask(LOG_GUEST_ERROR, "ibex_uart: TX FIFO overflow"); + } + + memcpy(s->tx_fifo + s->tx_level, buf, size); + s->tx_level +=3D size; + + if (s->tx_level > 0) { + s->uart_status &=3D ~UART_STATUS_TXEMPTY; + } + + if (s->tx_level >=3D tx_fifo_level) { + s->uart_intr_state |=3D INTR_STATE_TX_WATERMARK; + ibex_uart_update_irqs(s); + } + + if (s->tx_level =3D=3D IBEX_UART_TX_FIFO_SIZE) { + s->uart_status |=3D UART_STATUS_TXFULL; + } + + timer_mod(s->fifo_trigger_handle, current_time + + (s->char_tx_time * 4)); +} + +static void ibex_uart_reset(DeviceState *dev) +{ + IbexUartState *s =3D IBEX_UART(dev); + + s->uart_intr_state =3D 0x00000000; + s->uart_intr_state =3D 0x00000000; + s->uart_intr_enable =3D 0x00000000; + s->uart_ctrl =3D 0x00000000; + s->uart_status =3D 0x0000003c; + s->uart_rdata =3D 0x00000000; + s->uart_fifo_ctrl =3D 0x00000000; + s->uart_fifo_status =3D 0x00000000; + s->uart_ovrd =3D 0x00000000; + s->uart_val =3D 0x00000000; + s->uart_timeout_ctrl =3D 0x00000000; + + s->tx_level =3D 0; + + s->char_tx_time =3D (NANOSECONDS_PER_SECOND / 230400) * 10; + + ibex_uart_update_irqs(s); +} + +static uint64_t ibex_uart_read(void *opaque, hwaddr addr, + unsigned int size) +{ + IbexUartState *s =3D opaque; + uint64_t retvalue =3D 0; + + switch (addr) { + case IBEX_UART_INTR_STATE: + retvalue =3D s->uart_intr_state; + break; + case IBEX_UART_INTR_ENABLE: + retvalue =3D s->uart_intr_enable; + break; + case IBEX_UART_INTR_TEST: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: wdata is write only\n", __func__); + break; + + case IBEX_UART_CTRL: + retvalue =3D s->uart_ctrl; + break; + case IBEX_UART_STATUS: + retvalue =3D s->uart_status; + break; + + case IBEX_UART_RDATA: + retvalue =3D s->uart_rdata; + if (s->uart_ctrl & UART_CTRL_RX_ENABLE) { + qemu_chr_fe_accept_input(&s->chr); + + s->uart_status |=3D UART_STATUS_RXIDLE; + s->uart_status |=3D UART_STATUS_RXEMPTY; + } + break; + case IBEX_UART_WDATA: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: wdata is write only\n", __func__); + break; + + case IBEX_UART_FIFO_CTRL: + retvalue =3D s->uart_fifo_ctrl; + break; + case IBEX_UART_FIFO_STATUS: + retvalue =3D s->uart_fifo_status; + + retvalue |=3D s->tx_level & 0x1F; + + qemu_log_mask(LOG_UNIMP, + "%s: RX fifos are not supported\n", __func__); + break; + + case IBEX_UART_OVRD: + retvalue =3D s->uart_ovrd; + qemu_log_mask(LOG_UNIMP, + "%s: ovrd is not supported\n", __func__); + break; + case IBEX_UART_VAL: + retvalue =3D s->uart_val; + qemu_log_mask(LOG_UNIMP, + "%s: val is not supported\n", __func__); + break; + case IBEX_UART_TIMEOUT_CTRL: + retvalue =3D s->uart_timeout_ctrl; + qemu_log_mask(LOG_UNIMP, + "%s: timeout_ctrl is not supported\n", __func__); + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr); + return 0; + } + + return retvalue; +} + +static void ibex_uart_write(void *opaque, hwaddr addr, + uint64_t val64, unsigned int size) +{ + IbexUartState *s =3D opaque; + uint32_t value =3D val64; + + switch (addr) { + case IBEX_UART_INTR_STATE: + /* Write 1 clear */ + s->uart_intr_state &=3D ~value; + ibex_uart_update_irqs(s); + break; + case IBEX_UART_INTR_ENABLE: + s->uart_intr_enable =3D value; + ibex_uart_update_irqs(s); + break; + case IBEX_UART_INTR_TEST: + s->uart_intr_state |=3D value; + ibex_uart_update_irqs(s); + break; + + case IBEX_UART_CTRL: + s->uart_ctrl =3D value; + + if (value & UART_CTRL_NF) { + qemu_log_mask(LOG_UNIMP, + "%s: UART_CTRL_NF is not supported\n", __func__); + } + if (value & UART_CTRL_SLPBK) { + qemu_log_mask(LOG_UNIMP, + "%s: UART_CTRL_SLPBK is not supported\n", __func= __); + } + if (value & UART_CTRL_LLPBK) { + qemu_log_mask(LOG_UNIMP, + "%s: UART_CTRL_LLPBK is not supported\n", __func= __); + } + if (value & UART_CTRL_PARITY_EN) { + qemu_log_mask(LOG_UNIMP, + "%s: UART_CTRL_PARITY_EN is not supported\n", + __func__); + } + if (value & UART_CTRL_PARITY_ODD) { + qemu_log_mask(LOG_UNIMP, + "%s: UART_CTRL_PARITY_ODD is not supported\n", + __func__); + } + if (value & UART_CTRL_RXBLVL) { + qemu_log_mask(LOG_UNIMP, + "%s: UART_CTRL_RXBLVL is not supported\n", __fun= c__); + } + if (value & UART_CTRL_NCO) { + uint64_t baud =3D ((value & UART_CTRL_NCO) >> 16); + baud *=3D 1000; + baud /=3D 2 ^ 20; + + s->char_tx_time =3D (NANOSECONDS_PER_SECOND / baud) * 10; + } + break; + case IBEX_UART_STATUS: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: status is read only\n", __func__); + break; + + case IBEX_UART_RDATA: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: rdata is read only\n", __func__); + break; + case IBEX_UART_WDATA: + uart_write_tx_fifo(s, (uint8_t *) &value, 1); + break; + + case IBEX_UART_FIFO_CTRL: + s->uart_fifo_ctrl =3D value; + + if (value & FIFO_CTRL_RXRST) { + qemu_log_mask(LOG_UNIMP, + "%s: RX fifos are not supported\n", __func__); + } + if (value & FIFO_CTRL_TXRST) { + s->tx_level =3D 0; + } + break; + case IBEX_UART_FIFO_STATUS: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: fifo_status is read only\n", __func__); + break; + + case IBEX_UART_OVRD: + s->uart_ovrd =3D value; + qemu_log_mask(LOG_UNIMP, + "%s: ovrd is not supported\n", __func__); + break; + case IBEX_UART_VAL: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: val is read only\n", __func__); + break; + case IBEX_UART_TIMEOUT_CTRL: + s->uart_timeout_ctrl =3D value; + qemu_log_mask(LOG_UNIMP, + "%s: timeout_ctrl is not supported\n", __func__); + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr); + } +} + +static void fifo_trigger_update(void *opaque) +{ + IbexUartState *s =3D opaque; + + if (s->uart_ctrl & UART_CTRL_TX_ENABLE) { + ibex_uart_xmit(NULL, G_IO_OUT, s); + } +} + +static const MemoryRegionOps ibex_uart_ops =3D { + .read =3D ibex_uart_read, + .write =3D ibex_uart_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl.min_access_size =3D 4, + .impl.max_access_size =3D 4, +}; + +static int ibex_uart_post_load(void *opaque, int version_id) +{ + IbexUartState *s =3D opaque; + + ibex_uart_update_irqs(s); + return 0; +} + +static const VMStateDescription vmstate_ibex_uart =3D { + .name =3D TYPE_IBEX_UART, + .version_id =3D 1, + .minimum_version_id =3D 1, + .post_load =3D ibex_uart_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8_ARRAY(tx_fifo, IbexUartState, + IBEX_UART_TX_FIFO_SIZE), + VMSTATE_UINT32(tx_level, IbexUartState), + VMSTATE_UINT64(char_tx_time, IbexUartState), + VMSTATE_TIMER_PTR(fifo_trigger_handle, IbexUartState), + VMSTATE_UINT32(uart_intr_state, IbexUartState), + VMSTATE_UINT32(uart_intr_enable, IbexUartState), + VMSTATE_UINT32(uart_ctrl, IbexUartState), + VMSTATE_UINT32(uart_status, IbexUartState), + VMSTATE_UINT32(uart_rdata, IbexUartState), + VMSTATE_UINT32(uart_fifo_ctrl, IbexUartState), + VMSTATE_UINT32(uart_fifo_status, IbexUartState), + VMSTATE_UINT32(uart_ovrd, IbexUartState), + VMSTATE_UINT32(uart_val, IbexUartState), + VMSTATE_UINT32(uart_timeout_ctrl, IbexUartState), + VMSTATE_END_OF_LIST() + } +}; + +static Property ibex_uart_properties[] =3D { + DEFINE_PROP_CHR("chardev", IbexUartState, chr), + DEFINE_PROP_END_OF_LIST(), +}; + +static void ibex_uart_init(Object *obj) +{ + IbexUartState *s =3D IBEX_UART(obj); + + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->tx_watermark); + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->rx_watermark); + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->tx_empty); + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->rx_overflow); + + memory_region_init_io(&s->mmio, obj, &ibex_uart_ops, s, + TYPE_IBEX_UART, 0x400); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); +} + +static void ibex_uart_realize(DeviceState *dev, Error **errp) +{ + IbexUartState *s =3D IBEX_UART(dev); + + s->fifo_trigger_handle =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, + fifo_trigger_update, s); + + qemu_chr_fe_set_handlers(&s->chr, ibex_uart_can_receive, + ibex_uart_receive, NULL, NULL, + s, NULL, true); +} + +static void ibex_uart_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->reset =3D ibex_uart_reset; + dc->realize =3D ibex_uart_realize; + dc->vmsd =3D &vmstate_ibex_uart; + device_class_set_props(dc, ibex_uart_properties); +} + +static const TypeInfo ibex_uart_info =3D { + .name =3D TYPE_IBEX_UART, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(IbexUartState), + .instance_init =3D ibex_uart_init, + .class_init =3D ibex_uart_class_init, +}; + +static void ibex_uart_register_types(void) +{ + type_register_static(&ibex_uart_info); +} + +type_init(ibex_uart_register_types) diff --git a/MAINTAINERS b/MAINTAINERS index 3abe3faa4e..08fc4cae8e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1246,7 +1246,9 @@ M: Alistair Francis L: qemu-riscv@nongnu.org S: Supported F: hw/riscv/opentitan.c +F: hw/char/ibex_uart.c F: include/hw/riscv/opentitan.h +F: include/hw/char/ibex_uart.h =20 SH4 Machines ------------ diff --git a/hw/char/Makefile.objs b/hw/char/Makefile.objs index 9e9a6c1aff..633996be5b 100644 --- a/hw/char/Makefile.objs +++ b/hw/char/Makefile.objs @@ -12,6 +12,7 @@ common-obj-$(CONFIG_VIRTIO_SERIAL) +=3D virtio-console.o common-obj-$(CONFIG_XILINX) +=3D xilinx_uartlite.o common-obj-$(CONFIG_XEN) +=3D xen_console.o common-obj-$(CONFIG_CADENCE) +=3D cadence_uart.o +common-obj-$(CONFIG_IBEX) +=3D ibex_uart.o =20 common-obj-$(CONFIG_EXYNOS4) +=3D exynos4210_uart.o common-obj-$(CONFIG_COLDFIRE) +=3D mcf_uart.o diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index 94d19571f7..28947ef3e0 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -4,6 +4,9 @@ config HTIF config HART bool =20 +config IBEX + bool + config SIFIVE bool select MSI_NONBROKEN @@ -29,6 +32,7 @@ config SPIKE =20 config OPENTITAN bool + select IBEX select HART select UNIMP =20 --=20 2.26.2 From nobody Thu May 16 07:12:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1591827754; cv=none; d=zohomail.com; s=zohoarc; b=D9qgJ+EMQBRHJizGSWDdxNFh0qSprBFjUo7xqwuRFBDunzllRrj4rFQv0yl9+9jNSdu6feyLRxG6Iw97Z5ARNS3tBRFzI+DXTXrwFCm8XP9LA8Be75de6Ww9tc5NZOEEq0SEqrcZ2aROWiTmRfTdLm3LGAOZ+go2guqknZJqWkU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591827754; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+w5dGWj33ObF/YrJ5jvMdTkBp4yR1AnLidxXGgeMrkk=; b=kXsstnpMi/GJCU5qS/6NREZ0x7FsjXKsCryVkm39hwlmfUpotnmCPI9nY2/SUszlWPdqUuQVb6RM9nxDDMgNBgclflTxgsFwqAWCPHz4yzel53aUeMIefd2aMraMLekqhqgaEybJsLO549QmIn59SEgXzTQU99s3y1Tkj1OvaFw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591827754366625.1070321646104; Wed, 10 Jun 2020 15:22:34 -0700 (PDT) Received: from localhost ([::1]:36488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj97B-0005qY-09 for importer@patchew.org; Wed, 10 Jun 2020 18:22:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj95x-0004On-3J; Wed, 10 Jun 2020 18:21:17 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:59139) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj95v-00023G-Dz; Wed, 10 Jun 2020 18:21:16 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Jun 2020 06:21:13 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 15:10:39 -0700 Received: from us4qd5p12.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.58.34]) by uls-op-cesaip02.wdc.com with ESMTP; 10 Jun 2020 15:21:13 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591827675; x=1623363675; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rfV2J0CN9UPh6faD3IgzwZvnGje5W4oWV7+wZycjHvU=; b=D7VjevuKVu13u3f0EJaz4xqKMea0kc0Wql8PFQIoiFq8khZ8Iqa9c616 ZXWR+qRoIxl860inrzQsgmZLTjvUW1CiIft+Q4v71e8o/Q6iPYOKc6po+ 0c5CoURL37rxSmct76CAByTPHLg5oDNp898Wds0tGEV26iWSGO4iJTG+q CLS/OKYitnAdpxpuH50P1Upic8owMjeYgRWaNgemvoNRuBKU9fLwMmD3J 935qczYKLayA4T+mgQB/gJFhkl7m0mQpXOd6bZScoIva3NeqrZfcFpp0G VXdv/KFktwLvlpItFzFBDgxBcof7IJljd7xu4HlezjikEp0fp9QkC39z/ w==; IronPort-SDR: hv8KcTEMYfLTrPqpofyTAGV4pmol9mvot+x1sEm0rapP2IPA1PYabxBHITOj/fvROaMbXHA1gP gHJVFYvGchiEQJclUUoiJwSLDzmjfPYsUugq8a3KxPugFj8fQXj4uwfTII425yXBBMPKV8uCMl hCI7trKTfLu8yiojSMu8lU3XvPgQBaWyhEk7o7X4MJRlqIOonn2sXo0HfCTl3TooSa4lI8s+B7 zv/f4EkSA04pod4p89e9FHVuOH8/nRbwGBn/t0N3RhCLeGhR28Y00l/tVOgRDjz015xFV6W05I fe4= X-IronPort-AV: E=Sophos;i="5.73,497,1583164800"; d="scan'208";a="248819315" IronPort-SDR: eplSfCLXZ7W5hNo69tbffXpOqFN36yJDe8QVEf22woDTNYqqN+2YFpkNJMkT9bDmJErdYorVD9 g+0X647+rSjvLODCX4H8Aj3rwOaLchDmw= IronPort-SDR: BKPIvbZAMPMRSiKNnDXfSuFbKlsCXdpvPp94KxKglr33CBHQ41T5pM+DJh8rScauqr8JXTW2l0 85JF8E20/EMw== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v6 3/6] hw/intc: Initial commit of lowRISC Ibex PLIC Date: Wed, 10 Jun 2020 15:12:17 -0700 Message-Id: <69841756800201d4e5edbe04a59441455fcfc541.1591827110.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=4234ccaf3=alistair.francis@wdc.com; helo=esa1.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/10 18:21:06 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The Ibex core contains a PLIC that although similar to the RISC-V spec is not RISC-V spec compliant. This patch implements a Ibex PLIC in a somewhat generic way. As the current RISC-V PLIC needs tidying up, my hope is that as the Ibex PLIC move towards spec compliance this PLIC implementation can be updated until it can replace the current PLIC. Signed-off-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/intc/ibex_plic.h | 63 +++++++++ hw/intc/ibex_plic.c | 261 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + hw/intc/Makefile.objs | 1 + 4 files changed, 327 insertions(+) create mode 100644 include/hw/intc/ibex_plic.h create mode 100644 hw/intc/ibex_plic.c diff --git a/include/hw/intc/ibex_plic.h b/include/hw/intc/ibex_plic.h new file mode 100644 index 0000000000..ddc7909903 --- /dev/null +++ b/include/hw/intc/ibex_plic.h @@ -0,0 +1,63 @@ +/* + * QEMU RISC-V lowRISC Ibex PLIC + * + * Copyright (c) 2020 Western Digital + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#ifndef HW_IBEX_PLIC_H +#define HW_IBEX_PLIC_H + +#include "hw/sysbus.h" + +#define TYPE_IBEX_PLIC "ibex-plic" +#define IBEX_PLIC(obj) \ + OBJECT_CHECK(IbexPlicState, (obj), TYPE_IBEX_PLIC) + +typedef struct IbexPlicState { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + MemoryRegion mmio; + + uint32_t *pending; + uint32_t *source; + uint32_t *priority; + uint32_t *enable; + uint32_t threshold; + uint32_t claim; + + /* config */ + uint32_t num_cpus; + uint32_t num_sources; + + uint32_t pending_base; + uint32_t pending_num; + + uint32_t source_base; + uint32_t source_num; + + uint32_t priority_base; + uint32_t priority_num; + + uint32_t enable_base; + uint32_t enable_num; + + uint32_t threshold_base; + + uint32_t claim_base; +} IbexPlicState; + +#endif /* HW_IBEX_PLIC_H */ diff --git a/hw/intc/ibex_plic.c b/hw/intc/ibex_plic.c new file mode 100644 index 0000000000..41079518c6 --- /dev/null +++ b/hw/intc/ibex_plic.c @@ -0,0 +1,261 @@ +/* + * QEMU RISC-V lowRISC Ibex PLIC + * + * Copyright (c) 2020 Western Digital + * + * Documentation avaliable: https://docs.opentitan.org/hw/ip/rv_plic/doc/ + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/qdev-properties.h" +#include "hw/core/cpu.h" +#include "hw/boards.h" +#include "hw/pci/msi.h" +#include "target/riscv/cpu_bits.h" +#include "target/riscv/cpu.h" +#include "hw/intc/ibex_plic.h" + +static bool addr_between(uint32_t addr, uint32_t base, uint32_t num) +{ + uint32_t end =3D base + (num * 0x04); + + if (addr >=3D base && addr < end) { + return true; + } + + return false; +} + +static void ibex_plic_irqs_set_pending(IbexPlicState *s, int irq, bool lev= el) +{ + int pending_num =3D irq / 32; + + s->pending[pending_num] |=3D level << (irq % 32); +} + +static bool ibex_plic_irqs_pending(IbexPlicState *s, uint32_t context) +{ + int i; + + for (i =3D 0; i < s->pending_num; i++) { + uint32_t irq_num =3D ctz64(s->pending[i]) + (i * 32); + + if (!(s->pending[i] & s->enable[i])) { + /* No pending and enabled IRQ */ + continue; + } + + if (s->priority[irq_num] > s->threshold) { + if (!s->claim) { + s->claim =3D irq_num; + } + return true; + } + } + + return false; +} + +static void ibex_plic_update(IbexPlicState *s) +{ + CPUState *cpu; + int level, i; + + for (i =3D 0; i < s->num_cpus; i++) { + cpu =3D qemu_get_cpu(i); + + if (!cpu) { + continue; + } + + level =3D ibex_plic_irqs_pending(s, 0); + + riscv_cpu_update_mip(RISCV_CPU(cpu), MIP_MEIP, BOOL_TO_MASK(level)= ); + } +} + +static void ibex_plic_reset(DeviceState *dev) +{ + IbexPlicState *s =3D IBEX_PLIC(dev); + + s->threshold =3D 0x00000000; + s->claim =3D 0x00000000; +} + +static uint64_t ibex_plic_read(void *opaque, hwaddr addr, + unsigned int size) +{ + IbexPlicState *s =3D opaque; + int offset; + uint32_t ret =3D 0; + + if (addr_between(addr, s->pending_base, s->pending_num)) { + offset =3D (addr - s->pending_base) / 4; + ret =3D s->pending[offset]; + } else if (addr_between(addr, s->source_base, s->source_num)) { + qemu_log_mask(LOG_UNIMP, + "%s: Interrupt source mode not supported\n", __func_= _); + } else if (addr_between(addr, s->priority_base, s->priority_num)) { + offset =3D (addr - s->priority_base) / 4; + ret =3D s->priority[offset]; + } else if (addr_between(addr, s->enable_base, s->enable_num)) { + offset =3D (addr - s->enable_base) / 4; + ret =3D s->enable[offset]; + } else if (addr_between(addr, s->threshold_base, 1)) { + ret =3D s->threshold; + } else if (addr_between(addr, s->claim_base, 1)) { + int pending_num =3D s->claim / 32; + s->pending[pending_num] &=3D ~(1 << (s->claim % 32)); + + ret =3D s->claim; + } + + return ret; +} + +static void ibex_plic_write(void *opaque, hwaddr addr, + uint64_t value, unsigned int size) +{ + IbexPlicState *s =3D opaque; + + if (addr_between(addr, s->pending_base, s->pending_num)) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Pending registers are read only\n", __func__); + } else if (addr_between(addr, s->source_base, s->source_num)) { + qemu_log_mask(LOG_UNIMP, + "%s: Interrupt source mode not supported\n", __func_= _); + } else if (addr_between(addr, s->priority_base, s->priority_num)) { + uint32_t irq =3D ((addr - s->priority_base) >> 2) + 1; + s->priority[irq] =3D value & 7; + } else if (addr_between(addr, s->enable_base, s->enable_num)) { + uint32_t enable_reg =3D (addr - s->enable_base) / 4; + + s->enable[enable_reg] =3D value; + } else if (addr_between(addr, s->threshold_base, 1)) { + s->threshold =3D value & 3; + } else if (addr_between(addr, s->claim_base, 1)) { + if (s->claim =3D=3D value) { + /* Interrupt was completed */ + s->claim =3D 0; + } + } + + ibex_plic_update(s); +} + +static const MemoryRegionOps ibex_plic_ops =3D { + .read =3D ibex_plic_read, + .write =3D ibex_plic_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4 + } +}; + +static void ibex_plic_irq_request(void *opaque, int irq, int level) +{ + IbexPlicState *s =3D opaque; + + ibex_plic_irqs_set_pending(s, irq, level > 0); + ibex_plic_update(s); +} + +static Property ibex_plic_properties[] =3D { + DEFINE_PROP_UINT32("num-cpus", IbexPlicState, num_cpus, 1), + DEFINE_PROP_UINT32("num-sources", IbexPlicState, num_sources, 80), + + DEFINE_PROP_UINT32("pending-base", IbexPlicState, pending_base, 0), + DEFINE_PROP_UINT32("pending-num", IbexPlicState, pending_num, 3), + + DEFINE_PROP_UINT32("source-base", IbexPlicState, source_base, 0x0c), + DEFINE_PROP_UINT32("source-num", IbexPlicState, source_num, 3), + + DEFINE_PROP_UINT32("priority-base", IbexPlicState, priority_base, 0x18= ), + DEFINE_PROP_UINT32("priority-num", IbexPlicState, priority_num, 80), + + DEFINE_PROP_UINT32("enable-base", IbexPlicState, enable_base, 0x200), + DEFINE_PROP_UINT32("enable-num", IbexPlicState, enable_num, 3), + + DEFINE_PROP_UINT32("threshold-base", IbexPlicState, threshold_base, 0x= 20c), + + DEFINE_PROP_UINT32("claim-base", IbexPlicState, claim_base, 0x210), + DEFINE_PROP_END_OF_LIST(), +}; + +static void ibex_plic_init(Object *obj) +{ + IbexPlicState *s =3D IBEX_PLIC(obj); + + memory_region_init_io(&s->mmio, obj, &ibex_plic_ops, s, + TYPE_IBEX_PLIC, 0x400); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); +} + +static void ibex_plic_realize(DeviceState *dev, Error **errp) +{ + IbexPlicState *s =3D IBEX_PLIC(dev); + int i; + + s->pending =3D g_new0(uint32_t, s->pending_num); + s->source =3D g_new0(uint32_t, s->source_num); + s->priority =3D g_new0(uint32_t, s->priority_num); + s->enable =3D g_new0(uint32_t, s->enable_num); + + qdev_init_gpio_in(dev, ibex_plic_irq_request, s->num_sources); + + /* + * We can't allow the supervisor to control SEIP as this would allow t= he + * supervisor to clear a pending external interrupt which will result = in + * a lost interrupt in the case a PLIC is attached. The SEIP bit must = be + * hardware controlled when a PLIC is attached. + */ + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int smp_cpus =3D ms->smp.cpus; + for (i =3D 0; i < smp_cpus; i++) { + RISCVCPU *cpu =3D RISCV_CPU(qemu_get_cpu(i)); + if (riscv_cpu_claim_interrupts(cpu, MIP_SEIP) < 0) { + error_report("SEIP already claimed"); + exit(1); + } + } + + msi_nonbroken =3D true; +} + +static void ibex_plic_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->reset =3D ibex_plic_reset; + device_class_set_props(dc, ibex_plic_properties); + dc->realize =3D ibex_plic_realize; +} + +static const TypeInfo ibex_plic_info =3D { + .name =3D TYPE_IBEX_PLIC, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(IbexPlicState), + .instance_init =3D ibex_plic_init, + .class_init =3D ibex_plic_class_init, +}; + +static void ibex_plic_register_types(void) +{ + type_register_static(&ibex_plic_info); +} + +type_init(ibex_plic_register_types) diff --git a/MAINTAINERS b/MAINTAINERS index 08fc4cae8e..51a3f96d7d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1247,8 +1247,10 @@ L: qemu-riscv@nongnu.org S: Supported F: hw/riscv/opentitan.c F: hw/char/ibex_uart.c +F: hw/intc/ibex_plic.c F: include/hw/riscv/opentitan.h F: include/hw/char/ibex_uart.h +F: include/hw/intc/ibex_plic.h =20 SH4 Machines ------------ diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs index f726d87532..a61e6728fe 100644 --- a/hw/intc/Makefile.objs +++ b/hw/intc/Makefile.objs @@ -49,3 +49,4 @@ obj-$(CONFIG_ARM_GIC) +=3D arm_gicv3_cpuif.o obj-$(CONFIG_MIPS_CPS) +=3D mips_gic.o obj-$(CONFIG_NIOS2) +=3D nios2_iic.o obj-$(CONFIG_OMPIC) +=3D ompic.o +obj-$(CONFIG_IBEX) +=3D ibex_plic.o --=20 2.26.2 From nobody Thu May 16 07:12:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1591827997; cv=none; d=zohomail.com; s=zohoarc; b=Hzp9E+769FiAJMjjKv5P7m3ATa182FsDhJUlTK2Y3Uiv5cDO9NeQf2WOZ+gCLO5Kx1fu+QphAY2cpO/MoLiZjZoBMBANBuTQIag+E84F1tDxMBZZazEAmNPBwUORcCld0BT8K75vPEBdOLyax6nkMdGGmkxxaXmtRSCm/I00zxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591827997; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FXtlzyhg2uufLvBkG6krPfyVZl1t9Juw91jJcAWONfE=; b=N3Um/SEXCaubQkT3+lx76L4g/W3lQWnOTzU0nwHe+Q6n5Heg9pJE83sXOKhkG7wmzBJzuYerdgG+A0QWTrWmn7rx9j+41SS7/WMe8VxlE0A3xplP/zGdB1aOem0IF9JWx2BvfH/Gfm8y5atbYEJqu+nDtwpUUOE6g/9TwowYixw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159182799724110.925218363372096; Wed, 10 Jun 2020 15:26:37 -0700 (PDT) Received: from localhost ([::1]:49746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj9B5-0003py-SW for importer@patchew.org; Wed, 10 Jun 2020 18:26:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj95y-0004RQ-Ug; Wed, 10 Jun 2020 18:21:18 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:59124) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj95x-000237-Oj; Wed, 10 Jun 2020 18:21:18 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Jun 2020 06:21:16 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 15:10:42 -0700 Received: from us4qd5p12.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.58.34]) by uls-op-cesaip02.wdc.com with ESMTP; 10 Jun 2020 15:21:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591827677; x=1623363677; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EO1X9I2FgpPwqH4kt9DMGmIX+WXzCoYTwWl4+hNNrUg=; b=oY3RLjBIV+x0CfjuV9BnOZEmP1AH+jXoVzeX1tWO3pHiYlN+KhkyZipM gVkn0CWTNOtw1Wk6Nx5ghiXYvgOOOpiifQGexjdeLIsWEyGuOvnS2OKsm 176mcWLgcQVIJXyi9fTrL6b5yF7h18xIKw1Vvpf6xBtZmHBCfZdfo0SSm NuQeWDO3uonuqXI0nXk+WJFdF8Rog/FxuFJI3pOWTAoRu358rORaF8fX3 YkNkAfEr2q5PEwyqLRvvDOapfV0Qv80j4D4ZgtG1dPhfJw3JAhtuAZNdo foDjsdFJXDP2uSfaTrQXCU73kAdG/Oun3ZPAZGZUK/c2g1lY+f5NIDt06 A==; IronPort-SDR: STjDqGq4EIAFSXfkQ5ao5IVFwdGkf2aDiyAMvjd9kBcRJJ0DurQqL9TkDa8jGYQGEqay00o1Sc 8Q831LgOcVhIef3lRpTKCR4K6dcPIXr/DJkSuriFVAZ3elihcQULUJaCVDKd7exW4sKAlaeGmq tAHitkQzy744kd1gSTPyplNefZCzZ2ctjldoI4YtXmNvp2MCwxNniZkFilaC3cdn5dpjoEhPLR aDYlQoELaKaS2jJhkiwCORczSh3UZVxnbl56V7WXS1rlq+xaQh0z0n1VzEs7NlPM9HSa3HZJhw 5Lg= X-IronPort-AV: E=Sophos;i="5.73,497,1583164800"; d="scan'208";a="248819317" IronPort-SDR: 9x2K08P/RTTKJxf5iS5S4YQQVcGXLXle4/hYNt+ShvCtgV9pleRp84IUq/gNSCOh+oAeGJxQeL eGzSL70UGF4zTINRpuBZnInGY7pfFwcGo= IronPort-SDR: ZmzPkIVFnUna+2xr3Mvqrv74FMrHnjV3RInjwIPo9CC/yuuYK0n50YqFtTri72A9/3jhmWwBfb oDqPlyTAGgnw== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v6 4/6] riscv/opentitan: Connect the PLIC device Date: Wed, 10 Jun 2020 15:12:19 -0700 Message-Id: <176fecca64adb8977ec573153576c3e6f5e381f2.1591827110.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=4234ccaf3=alistair.francis@wdc.com; helo=esa1.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/10 18:21:06 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/riscv/opentitan.h | 3 +++ hw/riscv/opentitan.c | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/hw/riscv/opentitan.h b/include/hw/riscv/opentitan.h index a4b6499444..76f72905a8 100644 --- a/include/hw/riscv/opentitan.h +++ b/include/hw/riscv/opentitan.h @@ -20,6 +20,7 @@ #define HW_OPENTITAN_H =20 #include "hw/riscv/riscv_hart.h" +#include "hw/intc/ibex_plic.h" =20 #define TYPE_RISCV_IBEX_SOC "riscv.lowrisc.ibex.soc" #define RISCV_IBEX_SOC(obj) \ @@ -31,6 +32,8 @@ typedef struct LowRISCIbexSoCState { =20 /*< public >*/ RISCVHartArrayState cpus; + IbexPlicState plic; + MemoryRegion flash_mem; MemoryRegion rom; } LowRISCIbexSoCState; diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c index 6c7359c190..1fc0327cb5 100644 --- a/hw/riscv/opentitan.c +++ b/hw/riscv/opentitan.c @@ -25,6 +25,7 @@ #include "hw/misc/unimp.h" #include "hw/riscv/boot.h" #include "exec/address-spaces.h" +#include "sysemu/sysemu.h" =20 static const struct MemmapEntry { hwaddr base; @@ -97,6 +98,9 @@ static void riscv_lowrisc_ibex_soc_init(Object *obj) object_initialize_child(obj, "cpus", &s->cpus, sizeof(s->cpus), TYPE_RISCV_HART_ARRAY, &error_abort, NULL); + + sysbus_init_child_obj(obj, "plic", &s->plic, + sizeof(s->plic), TYPE_IBEX_PLIC); } =20 static void riscv_lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **e= rrp) @@ -105,6 +109,9 @@ static void riscv_lowrisc_ibex_soc_realize(DeviceState = *dev_soc, Error **errp) MachineState *ms =3D MACHINE(qdev_get_machine()); LowRISCIbexSoCState *s =3D RISCV_IBEX_SOC(dev_soc); MemoryRegion *sys_mem =3D get_system_memory(); + DeviceState *dev; + SysBusDevice *busdev; + Error *err =3D NULL; =20 object_property_set_str(OBJECT(&s->cpus), ms->cpu_type, "cpu-type", &error_abort); @@ -125,6 +132,16 @@ static void riscv_lowrisc_ibex_soc_realize(DeviceState= *dev_soc, Error **errp) memory_region_add_subregion(sys_mem, memmap[IBEX_FLASH].base, &s->flash_mem); =20 + /* PLIC */ + dev =3D DEVICE(&s->plic); + object_property_set_bool(OBJECT(&s->plic), true, "realized", &err); + if (err !=3D NULL) { + error_propagate(errp, err); + return; + } + busdev =3D SYS_BUS_DEVICE(dev); + sysbus_mmio_map(busdev, 0, memmap[IBEX_PLIC].base); + create_unimplemented_device("riscv.lowrisc.ibex.uart", memmap[IBEX_UART].base, memmap[IBEX_UART].size); create_unimplemented_device("riscv.lowrisc.ibex.gpio", @@ -145,8 +162,6 @@ static void riscv_lowrisc_ibex_soc_realize(DeviceState = *dev_soc, Error **errp) memmap[IBEX_AES].base, memmap[IBEX_AES].size); create_unimplemented_device("riscv.lowrisc.ibex.hmac", memmap[IBEX_HMAC].base, memmap[IBEX_HMAC].size); - create_unimplemented_device("riscv.lowrisc.ibex.plic", - memmap[IBEX_PLIC].base, memmap[IBEX_PLIC].size); create_unimplemented_device("riscv.lowrisc.ibex.pinmux", memmap[IBEX_PINMUX].base, memmap[IBEX_PINMUX].size); create_unimplemented_device("riscv.lowrisc.ibex.alert_handler", --=20 2.26.2 From nobody Thu May 16 07:12:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1591827856; cv=none; d=zohomail.com; s=zohoarc; b=mCXJzLJfIyjoyqUu5BPbbvyxpmtrj+jpINRCg7+sgeIFgbAvbJzWojvn2yrWOwD74o/GtlMIKFtxRGSFMDHZLLVJVJaTHI6RfYEqNL+pwBgX9DvPmDm6H3/+dnuY1K+SeJEXnQX4i0yfz6KnznerzBLuvC+tmYX/1YhEbGjyRd8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591827856; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yXO9+zMl1Yt/7p4dHbLbGjO9cfj0rthp4L1synRDrmo=; b=ZPcPjOTbD/+C2/kps430icXerJmQl69dIkiIWRfvXb9WqO1wL6YCYMueLioQfCUAxlKOXYRXYAQX8nV7WVCp2IrIIDqEQX0CQqIaBF87kaS7EtmizBXS32eqiea5vZeJjnfRsGfOgFDjPbgvPEAauweK8HHv02MV52uWCHO1noI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591827856548428.7824016314503; Wed, 10 Jun 2020 15:24:16 -0700 (PDT) Received: from localhost ([::1]:42844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj98p-0000C6-9s for importer@patchew.org; Wed, 10 Jun 2020 18:24:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj962-0004Xi-Ag; Wed, 10 Jun 2020 18:21:22 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:59148) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj961-00024C-6G; Wed, 10 Jun 2020 18:21:21 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Jun 2020 06:21:19 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 15:10:45 -0700 Received: from us4qd5p12.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.58.34]) by uls-op-cesaip02.wdc.com with ESMTP; 10 Jun 2020 15:21:19 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591827680; x=1623363680; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4DL/dtShyfrUriwfPCj9ft4we7CjJK0RVJvz0+UA9EQ=; b=ODdaP6BkhophXcJAtqiFc0iDD5fNyt4psZUZAyadpyqgJI1tuFagJb4O RXhOw0lsKHIwfzUNQJ+rYfSgkHxmi3SdNVf/fqhHnS9XIrE5OeRqwwmRg hX1WKQodOoRWW1ia+qsyCTsEZAG0Sw4uZ6ee823WY/eDX3+I90R/BFNiZ S35xHP70gKZMOYsitNyZAem+ImcpDN7bNmc817YCgJsM+MifB8ik+f9bB 4sPDZY7OaMLkAus9P/FqJwLgg5ooOfIF5kmUH2AMRLM9l4WWoea9WHckl DfTKW1JJipQtFZRgUd0e36hy8ABZpS4fHkIn4HX0/zIKYcZJEpmXjsQiI g==; IronPort-SDR: Mm1LmeXMnTsipEAFwJPBnddmltgIqCWxSKhKWcqdkmndVRTxTXlMVm2QeSP2DzYBUOyoDkbAOe 7NRJ06HSJyeC3z1kMeUIw/MJKGRRin9ewyknIxVgjt926K1OeNJjh/7KjB4HMAsNtiPNINi0OX 7MNPo4+2FeFSpIKmmxCX97AS/OdS9E6ORaNkNKOtaOc2Ckg/iwiOziffHiT/UI2A6mcJPEz7HU J4D8EwPC6mZfXosjKO7qorx52ixsNptzQD3x7oWA0Ia+/1l8TYt4YeIYxwkYu7ZnvjZsitzY/I HDI= X-IronPort-AV: E=Sophos;i="5.73,497,1583164800"; d="scan'208";a="248819321" IronPort-SDR: KeFmZPLzyuPqW88tWnF9KGdbI7+BGX8LlzcLmn/1ZJgiGKJJd38U7EAl3VxacSEBmb2B+GHHwS XElIHxxqZAOzKc9tkwYr7uWuiSzwcOKbU= IronPort-SDR: Pgpx9fkR//rP7B77n1ZW3Rz5iW0bnT+g4eK4dEtrhIUs/QnJj01pTFBwloYmIncKTYVtikbrtl ewXa/XLZrloQ== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v6 5/6] riscv/opentitan: Connect the UART device Date: Wed, 10 Jun 2020 15:12:22 -0700 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=4234ccaf3=alistair.francis@wdc.com; helo=esa1.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/10 18:21:06 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/riscv/opentitan.h | 13 +++++++++++++ hw/riscv/opentitan.c | 24 ++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/hw/riscv/opentitan.h b/include/hw/riscv/opentitan.h index 76f72905a8..8f29b9cbbf 100644 --- a/include/hw/riscv/opentitan.h +++ b/include/hw/riscv/opentitan.h @@ -21,6 +21,7 @@ =20 #include "hw/riscv/riscv_hart.h" #include "hw/intc/ibex_plic.h" +#include "hw/char/ibex_uart.h" =20 #define TYPE_RISCV_IBEX_SOC "riscv.lowrisc.ibex.soc" #define RISCV_IBEX_SOC(obj) \ @@ -33,6 +34,7 @@ typedef struct LowRISCIbexSoCState { /*< public >*/ RISCVHartArrayState cpus; IbexPlicState plic; + IbexUartState uart; =20 MemoryRegion flash_mem; MemoryRegion rom; @@ -68,4 +70,15 @@ enum { IBEX_PADCTRL, }; =20 +enum { + IBEX_UART_RX_PARITY_ERR_IRQ =3D 0x28, + IBEX_UART_RX_TIMEOUT_IRQ =3D 0x27, + IBEX_UART_RX_BREAK_ERR_IRQ =3D 0x26, + IBEX_UART_RX_FRAME_ERR_IRQ =3D 0x25, + IBEX_UART_RX_OVERFLOW_IRQ =3D 0x24, + IBEX_UART_TX_EMPTY_IRQ =3D 0x23, + IBEX_UART_RX_WATERMARK_IRQ =3D 0x22, + IBEX_UART_TX_WATERMARK_IRQ =3D 0x21, +}; + #endif diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c index 1fc0327cb5..c8b6d2e7df 100644 --- a/hw/riscv/opentitan.c +++ b/hw/riscv/opentitan.c @@ -101,6 +101,9 @@ static void riscv_lowrisc_ibex_soc_init(Object *obj) =20 sysbus_init_child_obj(obj, "plic", &s->plic, sizeof(s->plic), TYPE_IBEX_PLIC); + + sysbus_init_child_obj(obj, "uart", &s->uart, + sizeof(s->uart), TYPE_IBEX_UART); } =20 static void riscv_lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **e= rrp) @@ -142,8 +145,25 @@ static void riscv_lowrisc_ibex_soc_realize(DeviceState= *dev_soc, Error **errp) busdev =3D SYS_BUS_DEVICE(dev); sysbus_mmio_map(busdev, 0, memmap[IBEX_PLIC].base); =20 - create_unimplemented_device("riscv.lowrisc.ibex.uart", - memmap[IBEX_UART].base, memmap[IBEX_UART].size); + /* UART */ + dev =3D DEVICE(&(s->uart)); + qdev_prop_set_chr(dev, "chardev", serial_hd(0)); + object_property_set_bool(OBJECT(&s->uart), true, "realized", &err); + if (err !=3D NULL) { + error_propagate(errp, err); + return; + } + busdev =3D SYS_BUS_DEVICE(dev); + sysbus_mmio_map(busdev, 0, memmap[IBEX_UART].base); + sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(DEVICE(&s->plic), + IBEX_UART_TX_WATERMARK_IRQ)); + sysbus_connect_irq(busdev, 1, qdev_get_gpio_in(DEVICE(&s->plic), + IBEX_UART_RX_WATERMARK_IRQ)); + sysbus_connect_irq(busdev, 2, qdev_get_gpio_in(DEVICE(&s->plic), + IBEX_UART_TX_EMPTY_IRQ)); + sysbus_connect_irq(busdev, 3, qdev_get_gpio_in(DEVICE(&s->plic), + IBEX_UART_RX_OVERFLOW_IRQ)); + create_unimplemented_device("riscv.lowrisc.ibex.gpio", memmap[IBEX_GPIO].base, memmap[IBEX_GPIO].size); create_unimplemented_device("riscv.lowrisc.ibex.spi", --=20 2.26.2 From nobody Thu May 16 07:12:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1591827868; cv=none; d=zohomail.com; s=zohoarc; b=gW4Mi7vMOU04H48SZGGKOI1cbhRyvN+ok3YO4uyYhHCLftLZWXf4oA4oPAhhLvm3f3vpf846hGM1qXFjGsy/msJ67H0dDCV/qvTpkE+NtRARzH/D3vLDZr8Ye6ey3b3+WQg6n5uvEGjtb0rIo9G0PuwOkqHYOU8UYHx5W7PbMQU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591827868; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rhWBHK5003Udi37cw2EI+fP2MKeIgFWQr9pnE8gh7sc=; b=Na8biLBzyaWcSXjR5zm6G8yDi8xvlHMZv2FVN/Gi+5FzcC5MmRxwinBY5gZnamRJRDK4X45CCGkHIMgWk1dXpvgcKSxUAY9T+f359SUjEYLmppPzEfCn+VplhhumKX5z9Zyy3yjaav6a26m2k2VXwjL5YIZQ56XWbm8tP9cyPSM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591827868256550.6034179373208; Wed, 10 Jun 2020 15:24:28 -0700 (PDT) Received: from localhost ([::1]:43662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj990-0000d0-Tf for importer@patchew.org; Wed, 10 Jun 2020 18:24:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj964-0004aq-5f; Wed, 10 Jun 2020 18:21:24 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:59148) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj963-00024C-6O; Wed, 10 Jun 2020 18:21:23 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Jun 2020 06:21:21 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 15:10:48 -0700 Received: from us4qd5p12.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.58.34]) by uls-op-cesaip02.wdc.com with ESMTP; 10 Jun 2020 15:21:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591827683; x=1623363683; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6FATJBjY3MEsYgFLnJ2w8QG6m7aF0O7YWGLLllI2F4A=; b=oFQ/ZviNFRjYX9JYfXkHpz9pqk46dCpVNeUc1O21RrWUwM2LT5O2ZHNr VuJMfXoZEFhyKTWUCGJXFGKmOmmzo3nC4IgAbfjWkgOAMDZbZWezQ6j5D EcgBxGspIAHNJlzbNLKjwo9fYvo3j6To+z5n47yhbMUnnPYFJ/JE9hhdu 4qmNChfxQAnHId/oiEIs4rXj9faRm3V7iJ2pxrzMx1unAStqBqzwDahJW 0fVb3/cUkogr/Gxw2+zX8Qd/lPlavSz/yokaRpon+40FWj1QqhQlU14ES XIAGm84MF+Y478ymSR137JIE2RXIpFYbQ8m076iE56rHrnBYUgN3lKA6d w==; IronPort-SDR: Dx/UHrjUbuwzP/P9ftiP8mv7iRg48fhVC7Ma+PNh0fiUcvXXGSzPI2djQJE77X3aSS2QfglYdz SC1X+y01kAP+1vvx7WAIEKJMoAIDgr6qvaWwqv4qu1/pj5wNKRz8+JJrGThgVKIvgZLXMqIWo1 yVd8iGRVxGxPMnCvDTrgpvMKfnLz/nmCinX5SYl/GQcfFBqmxMjJ57ZssGY/4w9iiPSxdTdB5G ho3Nf5B1RwpSbcalAz0MehmaV8CqQ0NjuQf6n+pRIsSjRfAUVNmzoEe9OyWebA+ULMbdj4bXiF NyU= X-IronPort-AV: E=Sophos;i="5.73,497,1583164800"; d="scan'208";a="248819324" IronPort-SDR: AnBQIcO39xAKUJDqokY6DScpXWgo/3XeA8wyZxIcEtvysyERBiSAT/NluIWzSVUOsLG81uf27y 4LTVZ60Z/o8FNE1DJrVJMtkuNnvzxgp6U= IronPort-SDR: yHkgDLrwQGKDM/lc3pqkFTZ7oQStdCzRA00Flc6E8aYPIYWGooBbhE4K+bxA99Tz47hY1V2ejC aFKlHypwbylA== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v6 6/6] target/riscv: Use a smaller guess size for no-MMU PMP Date: Wed, 10 Jun 2020 15:12:25 -0700 Message-Id: <563998aa064518eea5ae5495a6639f16d881844f.1591827110.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=4234ccaf3=alistair.francis@wdc.com; helo=esa1.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/10 18:21:06 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Alistair Francis Reviewed-by: Bin Meng --- target/riscv/pmp.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 0e6b640fbd..9418660f1b 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -233,12 +233,16 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ul= ong addr, return true; } =20 - /* - * if size is unknown (0), assume that all bytes - * from addr to the end of the page will be accessed. - */ if (size =3D=3D 0) { - pmp_size =3D -(addr | TARGET_PAGE_MASK); + if (riscv_feature(env, RISCV_FEATURE_MMU)) { + /* + * If size is unknown (0), assume that all bytes + * from addr to the end of the page will be accessed. + */ + pmp_size =3D -(addr | TARGET_PAGE_MASK); + } else { + pmp_size =3D sizeof(target_ulong); + } } else { pmp_size =3D size; } --=20 2.26.2