From nobody Tue Feb 10 20:49:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=neuroblade.ai) ARC-Seal: i=2; a=rsa-sha256; t=1645712703; cv=pass; d=zohomail.com; s=zohoarc; b=J7mPrMypCHIz1C3h0Z8DWtucVRk9OBxP3iKWs9Qb7XKY3MaoDdcCD87lOp40iH4EIIEp68m1JZirbe+um1OIHAIgeSth3Z5gnJfTgxL30fF8tDztqv+cNHWq9W8I5HtZSLuiBbKBUXTRxebOA2uqO3ZijmZf8AsBlrVv1orHQwY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645712703; 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=U+LTtdmSQTzcbU1knKt9/bt3i0YzY9uULhTAlCwOrv8=; b=ntmpM+CtdfD71XEHM35ZSffUUZxyQ37Ud8zHk8G/TSbqce3tfjTBmlb2r9WwZbHwCSO12EXyDKVz/0tl1B608XVR0zzv27CT9qyROAUXY/xrB8jAN2UraPe4VtYilIAMgnMt5EX7sIhYO0vGdm0y6bPJV/hbtj3+xl219Sy9pKo= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=neuroblade.ai) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164571270352454.207177791182744; Thu, 24 Feb 2022 06:25:03 -0800 (PST) Received: from localhost ([::1]:36534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNF3F-00064P-P6 for importer@patchew.org; Thu, 24 Feb 2022 09:25:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNF1D-0004Z7-Uk for qemu-devel@nongnu.org; Thu, 24 Feb 2022 09:22:55 -0500 Received: from [2a01:111:f400:fe0d::71a] (port=60166 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNF1A-000296-Ep for qemu-devel@nongnu.org; Thu, 24 Feb 2022 09:22:55 -0500 Received: from AS9PR06CA0037.eurprd06.prod.outlook.com (2603:10a6:20b:463::21) by DB8PR09MB3834.eurprd09.prod.outlook.com (2603:10a6:10:f8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Thu, 24 Feb 2022 13:49:50 +0000 Received: from VE1EUR02FT030.eop-EUR02.prod.protection.outlook.com (2603:10a6:20b:463:cafe::b5) by AS9PR06CA0037.outlook.office365.com (2603:10a6:20b:463::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21 via Frontend Transport; Thu, 24 Feb 2022 13:49:50 +0000 Received: from nb-o365.localdomain (192.116.190.34) by VE1EUR02FT030.mail.protection.outlook.com (10.152.12.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23 via Frontend Transport; Thu, 24 Feb 2022 13:49:49 +0000 Received: from amirgonnen-vm.neuroblade.corp (amirgonnen-vm.neuroblade.corp [192.168.3.87]) by nb-o365.localdomain (Postfix) with ESMTP id 2AA991F6C1; Thu, 24 Feb 2022 15:49:28 +0200 (IST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LeYPEk5I3dN6/HUh4Foz6wWPw4XA5XICxV6uMsukCk9EojKrDcdu/YDrekY947iu/K6lT4NzLZ5DOtImGKEcsvaqKEivL908dRddYcRQuz1OFUGroA2xATozNuKlESKwjzqjC1GCFbyEAFFWod+FFAbLwr8bRTe0o2yAOLp0gSkUuYp71bbIpgLqWMn1M5+jg7CK9TIuVHDrhpXdDvrtKndfc4/nqkE49y3vugzGFIAEGW5mnsUZcf4jTgpev5poefFvE06PDToHY6joZJsXhh4I6k6cdjRaGN6nnufE4Rw8KJFYOkvHpdqFtZNhIuyIkpq5rR32ALtUwxYelNrBtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=U+LTtdmSQTzcbU1knKt9/bt3i0YzY9uULhTAlCwOrv8=; b=nAObiv/Gqzxqv8PTOhSpdKoGzDZUhbx6F2rBLWr15q8OV3uUAIn6qg9BktuAb/smtiupKOYnLJWcos99yuVGyl5DHQo4nDwPDsRy84lE03XhXQHk8zElF5QakLvGRA0SicH8NV1gOkgNdeDv3taLDH42s1l/++ITTIQLQ0YbMxasPlG7O+wYNR+a1hdNyBjJYSMYD0r+Tfc/YWATKLzPgBJzItveXA/i9uj7yEt1Ru9MUY30XPcB3WoVYX78lM2T0yadsVhmLuIe5l0+RzpeBtwzFV6VN4PY/ea5aPsauoQqLG9KBFnYUHOmUTtc0a3TwWWD1OVyhu6m5o34IdiVMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 192.116.190.34) smtp.rcpttodomain=denx.de smtp.mailfrom=neuroblade.ai; dmarc=none action=none header.from=neuroblade.ai; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NeuroBlade.onmicrosoft.com; s=selector2-NeuroBlade-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U+LTtdmSQTzcbU1knKt9/bt3i0YzY9uULhTAlCwOrv8=; b=e5LApPRoUGBldDGxmom+TnXzwMkA3YfiYH8YbFrL3NcYeXnU5tZ6LLGGtgNZXmZMiIvEFxduUYs9DXWnblfjV+t8O6hwyRBzMdfSjXV+ihbkjY085ZCrPtT6DSMrLDcI0ZSqLlULm8juupThxfHw2qZIPNxq10ck6d7OytQQBGY= X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 192.116.190.34) smtp.mailfrom=neuroblade.ai; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=neuroblade.ai; 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: Fail (protection.outlook.com: domain of neuroblade.ai does not designate 192.116.190.34 as permitted sender) receiver=protection.outlook.com; client-ip=192.116.190.34; helo=nb-o365.localdomain; From: Amir Gonnen To: qemu-devel@nongnu.org, Peter Maydell , Chris Wulff , Marek Vasut Subject: [PATCH v2 1/4] target/nios2: Shadow register set Date: Thu, 24 Feb 2022 15:48:58 +0200 Message-Id: <20220224134901.500007-2-amir.gonnen@neuroblade.ai> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224134901.500007-1-amir.gonnen@neuroblade.ai> References: <20220224134901.500007-1-amir.gonnen@neuroblade.ai> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4b4c3926-7165-4ad0-2fd7-08d9f79c86f7 X-MS-TrafficTypeDiagnostic: DB8PR09MB3834:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EdUIQ9a+Y3jh8QPdtZTLiFn6uC8ChykIhknNNlY9oL0HWOYX+u0EYsE2sx5oOE7qhYXWYYjAIL3/48AM1HS4p1XJTdg+/SklbDd7IyYJmmd4imVtERoC1IUWSd3d3GyoEnwqRdkK570LlAokoKHtCke/+Nhr9JA0xvp7p+8J8GvqBHNtTXnXexU3861po0PmgnQPXNWqDD8BC+EwcFEFeRR1MDA8Ou9G7/g4ov4KdTUS+douy8ZTD4uSBSjJQ7YSpdX0MphhJoEOOuJoAXXdvDL1T/FiY9bLz2sa/3HgzNK9UndVhaw9CzMkgVRI6JnlH9jud8TfdyqtieuSht47TacYBz3/Ip25K4ArTod5hDLC2fp45j29KZ9gOZZTOH3tVUh4GxIfN/n94SrzbLLw5L+m87eHvGPHzkweObm9ApIlrT/EU6Sha8GJQGAMVKeBIAoINFKM+qcULzDtfY/HQRNfkXG781ICtXNotSJ52wQRGPobkGzGFS8mQWBowX+92UkCCIpLy+oaTgtwvA/EC7ay8CDAnPtUtL+WWfvIAJdaG/ih0RAbCe4KFBsD7ufCRhQfjOARxxB49MixdhsfGNPPCc3/ymR+9V7/BnGk3i1wPTFS0msuuj7sZXk2QUbtvxnL3vFdLfnkLWxv24sq3JDj81G0ESuz4fAMjqDYbWmCsV94TG8nxSTp+Y31b02gCbfMZiSDYVZoJjp/UOd0q6qEntUSnm/llO2OtjziBG4FuVnr+dv1L/znIold9HTmTWzh3WAG6MEhHgysFxwL4Vv09Defhzh9+67LHxLHk/3efWSlWFf6tRn7wOEIHY35 X-Forefront-Antispam-Report: CIP:192.116.190.34; CTRY:IL; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:nb-o365.localdomain; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(136003)(376002)(34036004)(346002)(39840400004)(396003)(36840700001)(46966006)(36860700001)(316002)(86362001)(1076003)(2906002)(83380400001)(508600001)(110136005)(82310400004)(6666004)(5660300002)(186003)(70206006)(70586007)(44832011)(40480700001)(36756003)(107886003)(47076005)(26005)(336012)(6266002)(356005)(81166007)(8936002)(4326008)(8676002)(2616005)(36900700001)(27056005); DIR:OUT; SFP:1102; X-OriginatorOrg: neuroblade.ai X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 13:49:49.9691 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b4c3926-7165-4ad0-2fd7-08d9f79c86f7 X-MS-Exchange-CrossTenant-Id: 63c61203-65af-4cf8-98e5-d12f35edaefa X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=63c61203-65af-4cf8-98e5-d12f35edaefa; Ip=[192.116.190.34]; Helo=[nb-o365.localdomain] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR02FT030.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR09MB3834 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:fe0d::71a (failed) Received-SPF: pass client-ip=2a01:111:f400:fe0d::71a; envelope-from=amir.gonnen@neuroblade.ai; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amir Gonnen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @NeuroBlade.onmicrosoft.com) X-ZM-MESSAGEID: 1645712705307100001 Content-Type: text/plain; charset="utf-8" Implement shadow register set and related instructions rdprs, wrprs. Fix eret to update either status or sstatus according to current register set. eret also changes register set when needed. Signed-off-by: Amir Gonnen --- target/nios2/cpu.c | 1 + target/nios2/cpu.h | 47 ++++++++++++++++++++++++++++++++++++++-- target/nios2/helper.h | 3 +++ target/nios2/op_helper.c | 24 ++++++++++++++++++++ target/nios2/translate.c | 32 ++++++++++++++++++++++----- 5 files changed, 100 insertions(+), 7 deletions(-) diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c index 4cade61e93..0886705818 100644 --- a/target/nios2/cpu.c +++ b/target/nios2/cpu.c @@ -54,6 +54,7 @@ static void nios2_cpu_reset(DeviceState *dev) ncc->parent_reset(dev); memset(env->regs, 0, sizeof(uint32_t) * NUM_CORE_REGS); + memset(env->shadow_regs, 0, sizeof(uint32_t) * NUM_REG_SETS * NUM_GP_R= EGS); env->regs[R_PC] =3D cpu->reset_addr; #if defined(CONFIG_USER_ONLY) diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h index d2ba0c5bbd..1d3503825b 100644 --- a/target/nios2/cpu.h +++ b/target/nios2/cpu.h @@ -57,9 +57,14 @@ struct Nios2CPUClass { #define EXCEPTION_ADDRESS 0x00000004 #define FAST_TLB_MISS_ADDRESS 0x00000008 +#define NUM_GP_REGS 32 +#define NUM_CR_REGS 32 /* GP regs + CR regs + PC */ -#define NUM_CORE_REGS (32 + 32 + 1) +#define NUM_CORE_REGS (NUM_GP_REGS + NUM_CR_REGS + 1) + +/* 63 shadow register sets. 0 is the primary set */ +#define NUM_REG_SETS 64 /* General purpose register aliases */ #define R_ZERO 0 @@ -80,7 +85,7 @@ struct Nios2CPUClass { #define R_RA 31 /* Control register aliases */ -#define CR_BASE 32 +#define CR_BASE NUM_GP_REGS #define CR_STATUS (CR_BASE + 0) #define CR_STATUS_PIE (1 << 0) #define CR_STATUS_U (1 << 1) @@ -88,7 +93,9 @@ struct Nios2CPUClass { #define CR_STATUS_IH (1 << 3) #define CR_STATUS_IL (63 << 4) #define CR_STATUS_CRS (63 << 10) +#define CR_STATUS_CRS_OFFSET 10 #define CR_STATUS_PRS (63 << 16) +#define CR_STATUS_PRS_OFFSET 16 #define CR_STATUS_NMI (1 << 22) #define CR_STATUS_RSIE (1 << 23) #define CR_ESTATUS (CR_BASE + 1) @@ -131,6 +138,7 @@ struct Nios2CPUClass { /* Other registers */ #define R_PC 64 +#define R_SSTATUS 30 /* Exceptions */ #define EXCP_BREAK 0x1000 @@ -157,6 +165,7 @@ struct Nios2CPUClass { struct CPUNios2State { uint32_t regs[NUM_CORE_REGS]; + uint32_t shadow_regs[NUM_REG_SETS][NUM_GP_REGS]; #if !defined(CONFIG_USER_ONLY) Nios2MMU mmu; @@ -246,4 +255,38 @@ static inline void cpu_get_tb_cpu_state(CPUNios2State = *env, target_ulong *pc, *flags =3D (env->regs[CR_STATUS] & (CR_STATUS_EH | CR_STATUS_U)); } +static inline uint32_t cpu_get_crs(const CPUNios2State *env) +{ + return (env->regs[CR_STATUS] & CR_STATUS_CRS) + >> CR_STATUS_CRS_OFFSET; +} + +static inline uint32_t cpu_get_prs(const CPUNios2State *env) +{ + return (env->regs[CR_STATUS] & CR_STATUS_PRS) + >> CR_STATUS_PRS_OFFSET; +} + +static inline void cpu_change_reg_set(CPUNios2State *env, uint32_t prev_se= t, + uint32_t new_set) +{ + if (new_set =3D=3D prev_set) { + return; + } + memcpy(env->shadow_regs[prev_set], env->regs, + sizeof(uint32_t) * NUM_GP_REGS); + memcpy(env->regs, env->shadow_regs[new_set], + sizeof(uint32_t) * NUM_GP_REGS); + env->regs[CR_STATUS] =3D (env->regs[CR_STATUS] & (~CR_STATUS_PRS)) + | ((prev_set << CR_STATUS_PRS_OFFSET) & CR_STATUS_P= RS); + env->regs[CR_STATUS] =3D (env->regs[CR_STATUS] & (~CR_STATUS_CRS)) + | ((new_set << CR_STATUS_CRS_OFFSET) & CR_STATUS_CR= S); +} + +static inline void cpu_set_crs(CPUNios2State *env, uint32_t value) +{ + uint32_t crs =3D cpu_get_crs(env); + cpu_change_reg_set(env, crs, value); +} + #endif /* NIOS2_CPU_H */ diff --git a/target/nios2/helper.h b/target/nios2/helper.h index 6c8f0b5b35..3e5c016e9c 100644 --- a/target/nios2/helper.h +++ b/target/nios2/helper.h @@ -18,6 +18,9 @@ * */ +DEF_HELPER_2(eret, void, env, i32) +DEF_HELPER_3(wrprs, void, env, i32, i32) +DEF_HELPER_2(rdprs, i32, env, i32) DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, i32) #if !defined(CONFIG_USER_ONLY) diff --git a/target/nios2/op_helper.c b/target/nios2/op_helper.c index a59003855a..5e4f7a47ae 100644 --- a/target/nios2/op_helper.c +++ b/target/nios2/op_helper.c @@ -59,3 +59,27 @@ void helper_raise_exception(CPUNios2State *env, uint32_t= index) cs->exception_index =3D index; cpu_loop_exit(cs); } + +void helper_wrprs(CPUNios2State *env, uint32_t reg_index, uint32_t value) +{ + uint32_t prs =3D cpu_get_prs(env); + env->shadow_regs[prs][reg_index] =3D value; +} + +uint32_t helper_rdprs(CPUNios2State *env, uint32_t reg_index) +{ + uint32_t prs =3D cpu_get_prs(env); + return env->shadow_regs[prs][reg_index]; +} + +void helper_eret(CPUNios2State *env, uint32_t new_pc) +{ + uint32_t crs =3D cpu_get_crs(env); + if (crs =3D=3D 0) { + env->regs[CR_STATUS] =3D env->regs[CR_ESTATUS]; + } else { + env->regs[CR_STATUS] =3D env->regs[R_SSTATUS]; + } + cpu_change_reg_set(env, crs, cpu_get_crs(env)); + env->regs[R_PC] =3D new_pc; +} diff --git a/target/nios2/translate.c b/target/nios2/translate.c index f9abc2fdd2..e22ab1996a 100644 --- a/target/nios2/translate.c +++ b/target/nios2/translate.c @@ -205,6 +205,19 @@ static void call(DisasContext *dc, uint32_t code, uint= 32_t flags) /* * I-Type instructions */ + +/* + * rB <- prs.rA + sigma(IMM16) + */ +static void rdprs(DisasContext *dc, uint32_t code, uint32_t flags) +{ + I_TYPE(instr, code); + TCGv t =3D tcg_temp_new(); + gen_helper_rdprs(t, cpu_env, tcg_const_i32(instr.a)); + tcg_gen_addi_tl(cpu_R[instr.b], t, instr.imm16.s); + tcg_temp_free(t); +} + /* Load instructions */ static void gen_ldx(DisasContext *dc, uint32_t code, uint32_t flags) { @@ -365,7 +378,7 @@ static const Nios2Instruction i_type_instructions[] =3D= { INSTRUCTION_FLG(gen_stx, MO_SL), /* stwio */ INSTRUCTION_FLG(gen_bxx, TCG_COND_LTU), /* bltu */ INSTRUCTION_FLG(gen_ldx, MO_UL), /* ldwio */ - INSTRUCTION_UNIMPLEMENTED(), /* rdprs */ + INSTRUCTION(rdprs), /* rdprs */ INSTRUCTION_ILLEGAL(), INSTRUCTION_FLG(handle_r_type_instr, 0), /* R-Type */ INSTRUCTION_NOP(), /* flushd */ @@ -378,14 +391,23 @@ static const Nios2Instruction i_type_instructions[] = =3D { /* * R-Type instructions */ + +/* + * prs.rC <- rA + */ +static void wrprs(DisasContext *dc, uint32_t code, uint32_t flags) +{ + R_TYPE(instr, code); + gen_helper_wrprs(cpu_env, tcg_const_i32(instr.c), cpu_R[instr.a]); +} + /* - * status <- estatus + * status <- CRS =3D=3D 0? estatus: sstatus * PC <- ea */ static void eret(DisasContext *dc, uint32_t code, uint32_t flags) { - tcg_gen_mov_tl(cpu_R[CR_STATUS], cpu_R[CR_ESTATUS]); - tcg_gen_mov_tl(cpu_R[R_PC], cpu_R[R_EA]); + gen_helper_eret(cpu_env, cpu_R[R_EA]); dc->base.is_jmp =3D DISAS_JUMP; } @@ -672,7 +694,7 @@ static const Nios2Instruction r_type_instructions[] =3D= { INSTRUCTION_ILLEGAL(), INSTRUCTION(slli), /* slli */ INSTRUCTION(sll), /* sll */ - INSTRUCTION_UNIMPLEMENTED(), /* wrprs */ + INSTRUCTION(wrprs), /* wrprs */ INSTRUCTION_ILLEGAL(), INSTRUCTION(or), /* or */ INSTRUCTION(mulxsu), /* mulxsu */ -- 2.25.1 The contents of this email message and any attachments are intended solely = for the addressee(s) and may contain confidential and/or privileged informa= tion and may be legally protected from disclosure. If you are not the inten= ded recipient of this message or their agent, or if this message has been a= ddressed to you in error, please immediately alert the sender by reply emai= l and then delete this message and any attachments. If you are not the inte= nded recipient, you are hereby notified that any use, dissemination, copyin= g, or storage of this message or its attachments is strictly prohibited. From nobody Tue Feb 10 20:49:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=neuroblade.ai) ARC-Seal: i=2; a=rsa-sha256; t=1645712653; cv=pass; d=zohomail.com; s=zohoarc; b=UZluiJ46qS8rDm07InpBrWoIQhLQUDL91jsg1kDKJ9cIkfBaYADc7rfup65otOM+Bd0Ayu4bfnMwbQwqtPeAcfdTnO1wc9zVHCp7aHhBl5lYbTb4dieh7YdRkTmtXtZHBNWdLVybPlK+DI46CY9XkvP8iI9+5CGCkQWDZnNQvfE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645712653; 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=byptLtzyopgwHv9aXHp0sYgBZ6k5E5boMrKXpeMNiJw=; b=ZsgXAdW5WB73YqdU/0OhcmEfNLCslPlz579z4cjulDGDGIXk1YqXfwcMnevDu69vf4z0oVBZunl6Fh0hz8WtHb0CPxLITklMkHXSLSd5xiWwDEWVxGrUdlpYMG1QPGXxhkf8iP9/nCkvni/dxUVhrIAl9bZZUWKOe9wDPouWb0o= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=neuroblade.ai) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645712653188345.171064339718; Thu, 24 Feb 2022 06:24:13 -0800 (PST) Received: from localhost ([::1]:34808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNF2R-0004ni-9i for importer@patchew.org; Thu, 24 Feb 2022 09:24:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNF0R-0003b4-MH for qemu-devel@nongnu.org; Thu, 24 Feb 2022 09:22:07 -0500 Received: from [2a01:111:f400:fe0e::725] (port=58848 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNF0O-0001xB-Mn for qemu-devel@nongnu.org; Thu, 24 Feb 2022 09:22:07 -0500 Received: from AM5PR1001CA0039.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:206:15::16) by AM8PR09MB5365.eurprd09.prod.outlook.com (2603:10a6:20b:324::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24; Thu, 24 Feb 2022 13:49:53 +0000 Received: from VE1EUR02FT045.eop-EUR02.prod.protection.outlook.com (2603:10a6:206:15:cafe::1a) by AM5PR1001CA0039.outlook.office365.com (2603:10a6:206:15::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21 via Frontend Transport; Thu, 24 Feb 2022 13:49:52 +0000 Received: from nb-o365.localdomain (192.116.190.34) by VE1EUR02FT045.mail.protection.outlook.com (10.152.12.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23 via Frontend Transport; Thu, 24 Feb 2022 13:49:51 +0000 Received: from amirgonnen-vm.neuroblade.corp (amirgonnen-vm.neuroblade.corp [192.168.3.87]) by nb-o365.localdomain (Postfix) with ESMTP id 09B381F6C1; Thu, 24 Feb 2022 15:49:30 +0200 (IST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DZZ5mj/vwP1UJVOaxozL99rqafxtFHkycRaUOBjRKl9ZtP5h6aGN7j4sGgIaSmi4AjZ3/FUYtcTsY7u7KHUaJ1O60scQ21sMZGrsHHYgYD/WACrYJr77ee6WjYXSJnC0j1SGo6CQuWTwyKvRBVcH8yPXPvDoogAARObW9ZFzjAvjM3dLVK9LtW5PqBr6L6NqXdRkzEePEtm3rBo2eji5pMzkAeXx6xxtuwqyhpiOeNVWwnQ9qb3AFfqvRtmotCCll4tNfBhJjxILzvo+2LyQgOIZq563eQtqwIpNPxNdphzNTuRd7nLSzEibo7b0Nj6AZ3CS0e6FtYZDbypKYhAgtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=byptLtzyopgwHv9aXHp0sYgBZ6k5E5boMrKXpeMNiJw=; b=lQgN2Z8kF+Oy8V8d6wSsXmw3IW4/UwPpSG4rAmVbHhzbi1rKg8HVyQ5L6eGNogU4QYRxlSVtlyMtVSrNtz7YIpyn/sWIlWcnF/vJoJNKdpquHceVzdAVcepyhI7wOdTprvER8no5K+si/p1TnPvXEm4rhr9l++5anvVFUicfHTvA0TA1kikQYusPYVb5mQ0a2f84T2M/goJ2VPOZkLXs5e36QnEZH33lSVQEWUTzmerKERx1xIQHSD8zd4aH9BieKCLX1bhiXeRImXNBXJsbdiQEceszFPEetaMs/Rp1iVxp4hTdW7teEd4HeT7ToiWs35lqQIyqG2rladQOBiz96Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 192.116.190.34) smtp.rcpttodomain=denx.de smtp.mailfrom=neuroblade.ai; dmarc=none action=none header.from=neuroblade.ai; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NeuroBlade.onmicrosoft.com; s=selector2-NeuroBlade-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=byptLtzyopgwHv9aXHp0sYgBZ6k5E5boMrKXpeMNiJw=; b=EE5BXQXoYs+GliXCxWEdNT7NQIjb/yXU9A6zdFTxn2R057s3j8uJrggar+rf7D5mSxsecbTEdjUj3AbuWLNGd46/FXK4RyxWavKr5rLyB0CHrxEzxs074efJ88/zDR81/Dvw2pSQHyRfNNBpkadssAVXxnuwGRIx/XjOZpeJ0h8= X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 192.116.190.34) smtp.mailfrom=neuroblade.ai; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=neuroblade.ai; 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: Fail (protection.outlook.com: domain of neuroblade.ai does not designate 192.116.190.34 as permitted sender) receiver=protection.outlook.com; client-ip=192.116.190.34; helo=nb-o365.localdomain; From: Amir Gonnen To: qemu-devel@nongnu.org, Peter Maydell , Chris Wulff , Marek Vasut Subject: [PATCH v2 2/4] target/nios2: Exteral Interrupt Controller (EIC) Date: Thu, 24 Feb 2022 15:48:59 +0200 Message-Id: <20220224134901.500007-3-amir.gonnen@neuroblade.ai> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224134901.500007-1-amir.gonnen@neuroblade.ai> References: <20220224134901.500007-1-amir.gonnen@neuroblade.ai> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c326506a-ea7e-499e-0cbb-08d9f79c8814 X-MS-TrafficTypeDiagnostic: AM8PR09MB5365:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zAGay09UQef/mtyXP88cKJO8P7hrG62rR66mDTMi15lGX4yehuoM072kSvaLMwupraRA9pQ3qgu4VsFoBvQ93E+4HKATpF8jReID68FUQf9IFLrPRPjXEMgLxEwVu+w6uGYc06gQxt1sTmuj3fvhULwoxcOU1uIO5kV6FRFMC4FNrjzflLB8qi/9cnXAtIKMdIa0WhLR2J+fqkf9mrAueLHSYUPOUYo5kSQHiobKGrImP4FT8WHyqbvau2rmSnlbvSM80S4zoqc+6u3QK+jvyPaQ1+3O6BiFaenKquRF9d6tdP91DS9Jf8/lGtciIVJZMsj3BJZpvh1X1hyUD5qMcznOF9boESUEga17Htx8PfcZ36myYASLOWbVxyG+AhUNks0ZiLSMFkzzq29lia5o1PFPYBT6EPI3L6XKil0N23urqtQY4RC/y3wRVYQ0rVZdYu9He2bxwNkQITWEiT+rSqaewzk4X5wK0frQl7rCxJ6Nvu2D7sSJqWLCgYipmVNeM+fOYwPJaxTgIYGyYo/S9EFadYuBdRjnG9rtoJ8HjXSQRPL1cJPaF5VIxbj6B5Hd+vieCwr/kW4sOduu//ChJRaOTEKime9IwkOpK0jTBOtJdiUhetX0o/1dKVJEfJs7O8Y5Ip8aRMDjEIFiqdGevy3A+8IzaxhqpwOAZODblrp+JR4IGGb6WM8Q6j+igZFReewtzUdFM+H1yOJEEdybzJGY2bwrBP7pSXePTlMqjjk= X-Forefront-Antispam-Report: CIP:192.116.190.34; CTRY:IL; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:nb-o365.localdomain; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(39840400004)(396003)(136003)(346002)(34036004)(376002)(46966006)(36840700001)(40480700001)(186003)(82310400004)(508600001)(6666004)(6266002)(44832011)(26005)(1076003)(336012)(36860700001)(81166007)(70206006)(5660300002)(107886003)(356005)(316002)(36756003)(47076005)(8676002)(83380400001)(4326008)(110136005)(2906002)(2616005)(8936002)(86362001)(70586007)(27056005)(36900700001); DIR:OUT; SFP:1102; X-OriginatorOrg: neuroblade.ai X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 13:49:51.8203 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c326506a-ea7e-499e-0cbb-08d9f79c8814 X-MS-Exchange-CrossTenant-Id: 63c61203-65af-4cf8-98e5-d12f35edaefa X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=63c61203-65af-4cf8-98e5-d12f35edaefa; Ip=[192.116.190.34]; Helo=[nb-o365.localdomain] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR02FT045.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR09MB5365 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:fe0e::725 (failed) Received-SPF: pass client-ip=2a01:111:f400:fe0e::725; envelope-from=amir.gonnen@neuroblade.ai; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amir Gonnen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @NeuroBlade.onmicrosoft.com) X-ZM-MESSAGEID: 1645712655621100001 Content-Type: text/plain; charset="utf-8" Implement Exteral Interrupt Controller interface (EIC). Added intc_present property, true by default. When set to false, nios2 uses the EIC interface when handling IRQ. When set to true (default) it uses the internal interrupt controller. When nios2 recieves irq, it first checks intc_present to decide whether to use the internal interrupt controller or the EIC. The EIC is triggered by IRQ gpio but also recieves additional data from the external interrupt controller (such as VIC): rha, ril, rrs and rnmi. The interrupt controller is expected to raise IRQ after setting these fields on Nios2CPU. rha, ril, rrs and rnmi are used when EIC handles external interrupt, in order to decide if to take the interrupt now, which shadow register set to use, which PC to jump to, whether to set NMI flag, etc. Signed-off-by: Amir Gonnen --- target/nios2/cpu.c | 58 +++++++++++++++++++++++++++++++++------- target/nios2/cpu.h | 22 +++++++++++++++ target/nios2/helper.c | 33 ++++++++++++++++++++--- target/nios2/op_helper.c | 7 +++-- 4 files changed, 105 insertions(+), 15 deletions(-) diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c index 0886705818..9bd8a6301a 100644 --- a/target/nios2/cpu.c +++ b/target/nios2/cpu.c @@ -55,6 +55,7 @@ static void nios2_cpu_reset(DeviceState *dev) memset(env->regs, 0, sizeof(uint32_t) * NUM_CORE_REGS); memset(env->shadow_regs, 0, sizeof(uint32_t) * NUM_REG_SETS * NUM_GP_R= EGS); + env->regs[CR_STATUS] |=3D CR_STATUS_RSIE; env->regs[R_PC] =3D cpu->reset_addr; #if defined(CONFIG_USER_ONLY) @@ -65,10 +66,28 @@ static void nios2_cpu_reset(DeviceState *dev) #endif } +bool nios2_take_eic_irq(const Nios2CPU *cpu) +{ + const CPUNios2State *env =3D &cpu->env; + + if (cpu->rnmi) { + return !(env->regs[CR_STATUS] & CR_STATUS_NMI); + } + + if (((env->regs[CR_STATUS] & CR_STATUS_PIE) =3D=3D 0) || + (cpu->ril <=3D cpu_get_il(env)) || + (cpu->rrs =3D=3D cpu_get_crs(env) && + !(env->regs[CR_STATUS] & CR_STATUS_RSIE))) { + + return false; + } + + return true; +} + #ifndef CONFIG_USER_ONLY -static void nios2_cpu_set_irq(void *opaque, int irq, int level) +static void nios2_cpu_set_intc_irq(Nios2CPU *cpu, int irq, int level) { - Nios2CPU *cpu =3D opaque; CPUNios2State *env =3D &cpu->env; CPUState *cs =3D CPU(cpu); @@ -83,6 +102,32 @@ static void nios2_cpu_set_irq(void *opaque, int irq, in= t level) cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); } } + +static void nios2_cpu_set_eic_irq(Nios2CPU *cpu, int level) +{ + CPUNios2State *env =3D &cpu->env; + CPUState *cs =3D CPU(cpu); + + env->irq_pending =3D level; + + if (env->irq_pending && nios2_take_eic_irq(cpu)) { + env->irq_pending =3D 0; + cpu_interrupt(cs, CPU_INTERRUPT_HARD); + } else if (!env->irq_pending) { + cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); + } +} + +static void nios2_cpu_set_irq(void *opaque, int irq, int level) +{ + Nios2CPU *cpu =3D opaque; + + if (cpu->intc_present) { + nios2_cpu_set_intc_irq(cpu, irq, level); + } else { + nios2_cpu_set_eic_irq(cpu, level); + } +} #endif static void nios2_cpu_initfn(Object *obj) @@ -94,13 +139,6 @@ static void nios2_cpu_initfn(Object *obj) #if !defined(CONFIG_USER_ONLY) mmu_init(&cpu->env); - /* - * These interrupt lines model the IIC (internal interrupt - * controller). QEMU does not currently support the EIC - * (external interrupt controller) -- if we did it would be - * a separate device in hw/intc with a custom interface to - * the CPU, and boards using it would not wire up these IRQ lines. - */ qdev_init_gpio_in_named(DEVICE(cpu), nios2_cpu_set_irq, "IRQ", 32); #endif } @@ -202,6 +240,8 @@ static Property nios2_properties[] =3D { DEFINE_PROP_UINT32("mmu_tlb_num_ways", Nios2CPU, tlb_num_ways, 16), /* ALTR,tlb-num-entries */ DEFINE_PROP_UINT32("mmu_pid_num_entries", Nios2CPU, tlb_num_entries, 2= 56), + /* interrupt-controller (internal) */ + DEFINE_PROP_BOOL("intc_present", Nios2CPU, intc_present, true), DEFINE_PROP_END_OF_LIST(), }; diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h index 1d3503825b..1b3d0ed25e 100644 --- a/target/nios2/cpu.h +++ b/target/nios2/cpu.h @@ -92,12 +92,14 @@ struct Nios2CPUClass { #define CR_STATUS_EH (1 << 2) #define CR_STATUS_IH (1 << 3) #define CR_STATUS_IL (63 << 4) +#define CR_STATUS_IL_OFFSET 6 #define CR_STATUS_CRS (63 << 10) #define CR_STATUS_CRS_OFFSET 10 #define CR_STATUS_PRS (63 << 16) #define CR_STATUS_PRS_OFFSET 16 #define CR_STATUS_NMI (1 << 22) #define CR_STATUS_RSIE (1 << 23) +#define CR_STATUS_SRS (1 << 31) #define CR_ESTATUS (CR_BASE + 1) #define CR_BSTATUS (CR_BASE + 2) #define CR_IENABLE (CR_BASE + 3) @@ -189,6 +191,7 @@ struct Nios2CPU { CPUNios2State env; bool mmu_present; + bool intc_present; uint32_t pid_num_bits; uint32_t tlb_num_ways; uint32_t tlb_num_entries; @@ -197,10 +200,17 @@ struct Nios2CPU { uint32_t reset_addr; uint32_t exception_addr; uint32_t fast_tlb_miss_addr; + + /* External Interrupt Controller Interface */ + uint32_t rha; /* Requested handler address */ + uint32_t ril; /* Requested interrupt level */ + uint32_t rrs; /* Requested register set */ + uint32_t rnmi; /* Requested nonmaskable interrupt */ }; void nios2_tcg_init(void); +bool nios2_take_eic_irq(const Nios2CPU *cpu); void nios2_cpu_do_interrupt(CPUState *cs); void dump_mmu(CPUNios2State *env); void nios2_cpu_dump_state(CPUState *cpu, FILE *f, int flags); @@ -255,6 +265,18 @@ static inline void cpu_get_tb_cpu_state(CPUNios2State = *env, target_ulong *pc, *flags =3D (env->regs[CR_STATUS] & (CR_STATUS_EH | CR_STATUS_U)); } +static inline uint32_t cpu_get_il(const CPUNios2State *env) +{ + return (env->regs[CR_STATUS] & CR_STATUS_IL) + >> CR_STATUS_IL_OFFSET; +} + +static inline void cpu_set_il(CPUNios2State *env, uint32_t value) +{ + env->regs[CR_STATUS] =3D (env->regs[CR_STATUS] & ~CR_STATUS_IL) + | ((value << CR_STATUS_IL_OFFSET) & CR_STATUS_IL); +} + static inline uint32_t cpu_get_crs(const CPUNios2State *env) { return (env->regs[CR_STATUS] & CR_STATUS_CRS) diff --git a/target/nios2/helper.c b/target/nios2/helper.c index e5c98650e1..bc022e969d 100644 --- a/target/nios2/helper.c +++ b/target/nios2/helper.c @@ -54,21 +54,46 @@ void nios2_cpu_do_interrupt(CPUState *cs) Nios2CPU *cpu =3D NIOS2_CPU(cs); CPUNios2State *env =3D &cpu->env; + if (cs->exception_index !=3D EXCP_IRQ) { + cpu_set_crs(env, 0); + } + switch (cs->exception_index) { case EXCP_IRQ: assert(env->regs[CR_STATUS] & CR_STATUS_PIE); qemu_log_mask(CPU_LOG_INT, "interrupt at pc=3D%x\n", env->regs[R_P= C]); - env->regs[CR_ESTATUS] =3D env->regs[CR_STATUS]; - env->regs[CR_STATUS] |=3D CR_STATUS_IH; + uint32_t last_status =3D env->regs[CR_STATUS]; env->regs[CR_STATUS] &=3D ~(CR_STATUS_PIE | CR_STATUS_U); env->regs[CR_EXCEPTION] &=3D ~(0x1F << 2); env->regs[CR_EXCEPTION] |=3D (cs->exception_index & 0x1F) << 2; - env->regs[R_EA] =3D env->regs[R_PC] + 4; - env->regs[R_PC] =3D cpu->exception_addr; + if (!cpu->intc_present) { + cpu_set_crs(env, cpu->rrs); + cpu_set_il(env, cpu->ril); + if (cpu->rnmi) { + env->regs[CR_STATUS] |=3D CR_STATUS_NMI; + } else { + env->regs[CR_STATUS] &=3D ~CR_STATUS_NMI; + } + if (cpu->rrs =3D=3D 0) { + env->regs[CR_ESTATUS] =3D last_status; + } else { + env->regs[R_SSTATUS] =3D last_status; + env->regs[R_SSTATUS] |=3D CR_STATUS_SRS; + } + env->regs[CR_STATUS] |=3D CR_STATUS_IH; + env->regs[R_EA] =3D env->regs[R_PC] + 4; + env->regs[R_PC] =3D cpu->rha; + + } else { + env->regs[CR_ESTATUS] =3D last_status; + env->regs[R_EA] =3D env->regs[R_PC] + 4; + env->regs[R_PC] =3D cpu->exception_addr; + } + break; case EXCP_TLBD: diff --git a/target/nios2/op_helper.c b/target/nios2/op_helper.c index 5e4f7a47ae..1de823a067 100644 --- a/target/nios2/op_helper.c +++ b/target/nios2/op_helper.c @@ -40,8 +40,11 @@ static void nios2_check_interrupts(CPUNios2State *env) { if (env->irq_pending && (env->regs[CR_STATUS] & CR_STATUS_PIE)) { - env->irq_pending =3D 0; - cpu_interrupt(env_cpu(env), CPU_INTERRUPT_HARD); + Nios2CPU *cpu =3D (Nios2CPU *)env_cpu(env); + if (cpu->intc_present || nios2_take_eic_irq(cpu)) { + env->irq_pending =3D 0; + cpu_interrupt(env_cpu(env), CPU_INTERRUPT_HARD); + } } } -- 2.25.1 The contents of this email message and any attachments are intended solely = for the addressee(s) and may contain confidential and/or privileged informa= tion and may be legally protected from disclosure. If you are not the inten= ded recipient of this message or their agent, or if this message has been a= ddressed to you in error, please immediately alert the sender by reply emai= l and then delete this message and any attachments. If you are not the inte= nded recipient, you are hereby notified that any use, dissemination, copyin= g, or storage of this message or its attachments is strictly prohibited. From nobody Tue Feb 10 20:49:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=neuroblade.ai) ARC-Seal: i=2; a=rsa-sha256; t=1645711721; cv=pass; d=zohomail.com; s=zohoarc; b=c+jc3Fk6o6Ct2EuPDdCEVH8dYJqorq2lMPfH9eGznFllkMs61E35n1RZlcsO56G6EvZ0Pm5pYwcksHiylryDZCXvsMx8RA4FyYaYuazG721JZJ+uGViaQ/CkR9wN6c87UWofH3YjH8FwoU8K2kD3m8pj+NNNxffSO1Ddc//pnQ8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645711721; 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=WmqTrYcqDvR+nrfpW9EBstqpHKq06ktFSlg2tFHjHpk=; b=RK0fIxHJap3FO2k2dfxXivJVCCpuuQA2gu8ipAkTRrz++F1DPJRfr8Viaj1wRssOBSnv2cO+GEcfhGf2cBFpDThj87reBnp4rqwsEeRHNio4Lt2stlJOuuJ6HzNZQDp4LXVR87IIWrfuOV9pt8aGoHJyoH3IZVl27Cw2VEVpM5w= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=neuroblade.ai) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645711721788840.7048198214292; Thu, 24 Feb 2022 06:08:41 -0800 (PST) Received: from localhost ([::1]:39022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNEnQ-0004kg-Gj for importer@patchew.org; Thu, 24 Feb 2022 09:08:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNEkL-0008VP-Ul for qemu-devel@nongnu.org; Thu, 24 Feb 2022 09:05:30 -0500 Received: from [2a01:111:f400:fe06::722] (port=12454 helo=EUR02-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNEkB-0006fn-RZ for qemu-devel@nongnu.org; Thu, 24 Feb 2022 09:05:29 -0500 Received: from AM0PR06CA0075.eurprd06.prod.outlook.com (2603:10a6:208:fa::16) by AM8PR09MB5228.eurprd09.prod.outlook.com (2603:10a6:20b:3db::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Thu, 24 Feb 2022 13:49:54 +0000 Received: from VE1EUR02FT058.eop-EUR02.prod.protection.outlook.com (2603:10a6:208:fa:cafe::15) by AM0PR06CA0075.outlook.office365.com (2603:10a6:208:fa::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23 via Frontend Transport; Thu, 24 Feb 2022 13:49:54 +0000 Received: from nb-o365.localdomain (192.116.190.34) by VE1EUR02FT058.mail.protection.outlook.com (10.152.13.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23 via Frontend Transport; Thu, 24 Feb 2022 13:49:53 +0000 Received: from amirgonnen-vm.neuroblade.corp (amirgonnen-vm.neuroblade.corp [192.168.3.87]) by nb-o365.localdomain (Postfix) with ESMTP id BECDD211BB; Thu, 24 Feb 2022 15:49:31 +0200 (IST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WHCMK/FTYJhnRN36kmZOozOggFLTY3a+6ueON/khKkewe7I59rm/T+bII36phJxxw/PO97OGwVLS+kiYxRZrWqt5fJsOuk6ADloP57SpFR0RdeUSj3spRvCY4ImTwfM319judjP4dt4i8PCO1JwZXZNlCVhOX8KpA3DQ+at0vdJLiu8reIjwlBs3APQ3/eZ98JoB5Mu8y0VIOHxC8U07kIsBJ1e5EFGJtGHkztG5qpjkSplV6BGvDgvfxCC2N0FtOM7MeHqNW4ZjTqow0ggjZIf33lG5/tLFACQ3TmniW2peVdigeTJkkjF4f+5G6KvPPKSPtccd7CkTTL+sOnUBNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WmqTrYcqDvR+nrfpW9EBstqpHKq06ktFSlg2tFHjHpk=; b=LysKSD1tfSS1OKE9n0YuBg1hVcSkk475rDBr/s60BbY+vqsvmHrlktec5gJL+q2JYbDPhubAED85MiLbN8An3yYvQwGXJaAsIH7d9hMjzd5CRwzxwY7G54AFxWJ2xJCoCcxJdubBW9jWq8Zlgo3NyD9qGlDNOI1ux5A5fp1nl4zh1MF4hmfkzBAK0jHLSnA2EzXixXB4iWDADwcxAmwO1Z+wfYhhWioIT0Bh3SuPaxt166cQMTPvcJIz5Eg0kKzbx1tOXnhieYRUbRe3F/AVNr4VC1x5DW2y5d43PWUBT4jeX60bEsBbBorH/jM5Trdf1LEExav1eN7XC8pahIbyvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 192.116.190.34) smtp.rcpttodomain=denx.de smtp.mailfrom=neuroblade.ai; dmarc=none action=none header.from=neuroblade.ai; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NeuroBlade.onmicrosoft.com; s=selector2-NeuroBlade-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WmqTrYcqDvR+nrfpW9EBstqpHKq06ktFSlg2tFHjHpk=; b=l5Rx8+aAiuZCOMDJ4Nks/Bj/MhFIpGiWTDD3S3r/YsJQES3NGw9DwFTyvBl24O7OGDa5OSU5pKnkTN9SKH4iidXYd//EOG7g+cjeQGVfRvlcDU3vkh7oCdjoO4wARZE+Vt2xMOYfHdbdPcCqOE3hOmRPKgNoOxpsaNL+DEHi6HU= X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 192.116.190.34) smtp.mailfrom=neuroblade.ai; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=neuroblade.ai; 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: Fail (protection.outlook.com: domain of neuroblade.ai does not designate 192.116.190.34 as permitted sender) receiver=protection.outlook.com; client-ip=192.116.190.34; helo=nb-o365.localdomain; From: Amir Gonnen To: qemu-devel@nongnu.org, Peter Maydell , Chris Wulff , Marek Vasut Subject: [PATCH v2 3/4] hw/intc: Vectored Interrupt Controller (VIC) Date: Thu, 24 Feb 2022 15:49:00 +0200 Message-Id: <20220224134901.500007-4-amir.gonnen@neuroblade.ai> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224134901.500007-1-amir.gonnen@neuroblade.ai> References: <20220224134901.500007-1-amir.gonnen@neuroblade.ai> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c02b2a7f-b9ad-4df9-35b5-08d9f79c8926 X-MS-TrafficTypeDiagnostic: AM8PR09MB5228:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Qs3sg0wGuEIipXkoInHrV18qx8dASsyxD5lnHD61/32TLyM2Y68h46Cpi3Xpt0kmuL/JBNF7hZtfefUVTF8Y43BiGvfHDQl1XuHyKLN7lFvyY4VJ7zBaCzJyd4aoiPhhsOsGxBEJ2Gi1o7pm7qIptwTvVa4SgyfO82svOSxislzZTPh+KjPxc/t3qHcGWNutIuvbuWqrG7O7FVum0aYV4WS9fZXZCqtIZ1f8QOCD5Rpk+ml5E3OyYUXXTa1WA/8mt1KNsjFVKppmMwqkBo9wQCQ4bjVhntq8rqdCGIlpCe0fsrIgqge5rnlMs1x+K24MxNbdasY57O/gzCbLlFYSBZzwg9zLhAfTYcv6rALKEdmlms20S1118DOKhkIVvygQf5G1sb3uNojZrxCsybS8ar+a/QIagUDXGuLk9HSRWtCi6DCVvGch5SYrbSNT40TP1T0bVOEjALdD8+crDIW5F9g/7sYS2WsCuLpaVaPGw3wi8YPqoGyCtSZJrR5xSHIxjaA6QXSYbAB2fE11+RWV/nEzUO86io5V7YeVwhqb/nmgE1kfM7C1REfqMIlvzQo20MMturVjtcHA0T+S264u5BcOirACqh5gg6zkQ+DvKyq0/beci7oZqqjR2Qyb2e6vC+695hJdYeoE6u70prIY761tcoRyVxaPf3nCiUjsDSMIBpFrjdLsVExqCSDW4sKd1KA2oG2BXceo49WvdpotqUosqgXoLPkbIIxlmZtw+N4= X-Forefront-Antispam-Report: CIP:192.116.190.34; CTRY:IL; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:nb-o365.localdomain; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(346002)(376002)(39840400004)(396003)(136003)(34036004)(36840700001)(46966006)(2906002)(4326008)(30864003)(508600001)(8676002)(86362001)(316002)(70206006)(70586007)(5660300002)(110136005)(8936002)(40480700001)(44832011)(81166007)(356005)(82310400004)(107886003)(1076003)(36860700001)(6666004)(36756003)(2616005)(83380400001)(336012)(6266002)(47076005)(26005)(186003)(36900700001)(27056005); DIR:OUT; SFP:1102; X-OriginatorOrg: neuroblade.ai X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 13:49:53.6171 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c02b2a7f-b9ad-4df9-35b5-08d9f79c8926 X-MS-Exchange-CrossTenant-Id: 63c61203-65af-4cf8-98e5-d12f35edaefa X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=63c61203-65af-4cf8-98e5-d12f35edaefa; Ip=[192.116.190.34]; Helo=[nb-o365.localdomain] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR02FT058.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR09MB5228 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:fe06::722 (failed) Received-SPF: pass client-ip=2a01:111:f400:fe06::722; envelope-from=amir.gonnen@neuroblade.ai; helo=EUR02-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amir Gonnen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @NeuroBlade.onmicrosoft.com) X-ZM-MESSAGEID: 1645711724155100001 Content-Type: text/plain; charset="utf-8" Implement nios2 Vectored Interrupt Controller (VIC). VIC is connected to EIC. It needs to update rha, ril, rrs and rnmi fields on Nios2CPU before raising an IRQ. For that purpose, VIC has a "cpu" property which should refer to the nios2 cpu and set by the board that connects VIC. Signed-off-by: Amir Gonnen --- hw/intc/Kconfig | 4 + hw/intc/meson.build | 1 + hw/intc/nios2_vic.c | 327 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 332 insertions(+) create mode 100644 hw/intc/nios2_vic.c diff --git a/hw/intc/Kconfig b/hw/intc/Kconfig index 528e77b4a6..8000241428 100644 --- a/hw/intc/Kconfig +++ b/hw/intc/Kconfig @@ -81,3 +81,7 @@ config GOLDFISH_PIC config M68K_IRQC bool + +config NIOS2_VIC + default y + depends on NIOS2 && TCG diff --git a/hw/intc/meson.build b/hw/intc/meson.build index 7466024402..547e16eb2d 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -61,3 +61,4 @@ specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_XIVE'], if_true: files('spapr_xive_kvm.c')) specific_ss.add(when: 'CONFIG_GOLDFISH_PIC', if_true: files('goldfish_pic.= c')) specific_ss.add(when: 'CONFIG_M68K_IRQC', if_true: files('m68k_irqc.c')) +specific_ss.add(when: 'CONFIG_NIOS2_VIC', if_true: files('nios2_vic.c')) diff --git a/hw/intc/nios2_vic.c b/hw/intc/nios2_vic.c new file mode 100644 index 0000000000..a9c9b3e7ac --- /dev/null +++ b/hw/intc/nios2_vic.c @@ -0,0 +1,327 @@ +/* + * Vectored Interrupt Controller for nios2 processor + * + * Copyright (c) 2022 Neuroblade + * + * Interface: + * QOM property "cpu": link to the Nios2 CPU (must be set) + * Unnamed GPIO inputs 0..NIOS2_VIC_MAX_IRQ-1: input IRQ lines + * IRQ should be connected to nios2 IRQ0. + * + * Reference: "Embedded Peripherals IP User Guide + * for Intel=C2=AE Quartus=C2=AE Prime Design Suite: 21.4" + * Chapter 38 "Vectored Interrupt Controller Core" + * + * 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/irq.h" +#include "hw/qdev-properties.h" +#include "hw/sysbus.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qemu/bitops.h" +#include "qemu/log.h" +#include "qom/object.h" +#include "cpu.h" + +#define LOG_VIC(...) qemu_log_mask(CPU_LOG_INT, ##__VA_ARGS__) + +#define TYPE_NIOS2_VIC "nios2-vic" + +OBJECT_DECLARE_SIMPLE_TYPE(Nios2Vic, NIOS2_VIC) + +#define NIOS2_VIC_MAX_IRQ 32 + +enum { + INT_CONFIG0 =3D 0, + INT_CONFIG31 =3D 31, + INT_ENABLE =3D 32, + INT_ENABLE_SET =3D 33, + INT_ENABLE_CLR =3D 34, + INT_PENDING =3D 35, + INT_RAW_STATUS =3D 36, + SW_INTERRUPT =3D 37, + SW_INTERRUPT_SET =3D 38, + SW_INTERRUPT_CLR =3D 39, + VIC_CONFIG =3D 40, + VIC_STATUS =3D 41, + VEC_TBL_BASE =3D 42, + VEC_TBL_ADDR =3D 43, + CSR_COUNT /* Last! */ +}; + +struct Nios2Vic { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + qemu_irq output_int; + + /* properties */ + CPUState *cpu; + MemoryRegion csr; + + uint32_t int_config[32]; + uint32_t vic_config; + uint32_t int_raw_status; + uint32_t int_enable; + uint32_t sw_int; + uint32_t vic_status; + uint32_t vec_tbl_base; + uint32_t vec_tbl_addr; +}; + +/* Requested interrupt level (INT_CONFIG[0:5]) */ +static inline uint32_t vic_int_config_ril(const Nios2Vic *vic, int irq_num) +{ + return extract32(vic->int_config[irq_num], 0, 6); +} + +/* Requested NMI (INT_CONFIG[6]) */ +static inline uint32_t vic_int_config_rnmi(const Nios2Vic *vic, int irq_nu= m) +{ + return extract32(vic->int_config[irq_num], 6, 1); +} + +/* Requested register set (INT_CONFIG[7:12]) */ +static inline uint32_t vic_int_config_rrs(const Nios2Vic *vic, int irq_num) +{ + return extract32(vic->int_config[irq_num], 7, 6); +} + +static inline uint32_t vic_config_vec_size(const Nios2Vic *vic) +{ + return 1 << (2 + extract32(vic->vic_config, 0, 3)); +} + +static inline uint32_t vic_int_pending(const Nios2Vic *vic) +{ + return (vic->int_raw_status | vic->sw_int) & vic->int_enable; +} + +static void vic_update_irq(Nios2Vic *vic) +{ + Nios2CPU *cpu =3D NIOS2_CPU(vic->cpu); + uint32_t pending =3D vic_int_pending(vic); + int irq =3D -1; + int max_ril =3D 0; + + vic->vec_tbl_addr =3D 0; + vic->vic_status =3D 0; + + if (pending =3D=3D 0) { + qemu_irq_lower(vic->output_int); + return; + } + + for (int i =3D 0; i < NIOS2_VIC_MAX_IRQ; i++) { + if (pending & BIT(i)) { + int ril =3D vic_int_config_ril(vic, i); + if (ril > max_ril) { + irq =3D i; + max_ril =3D ril; + } + } + } + + if (irq < 0) { + qemu_irq_lower(vic->output_int); + return; + } + + vic->vec_tbl_addr =3D irq * vic_config_vec_size(vic) + vic->vec_tbl_ba= se; + vic->vic_status =3D deposit32(vic->vic_status, 0, 6, irq) | BIT(31); + + cpu->rha =3D vic->vec_tbl_addr; + cpu->ril =3D max_ril; + cpu->rrs =3D vic_int_config_rrs(vic, irq); + cpu->rnmi =3D vic_int_config_rnmi(vic, irq); + + qemu_irq_raise(vic->output_int); +} + +static void vic_set_irq(void *opaque, int irq_num, int level) +{ + Nios2Vic *vic =3D opaque; + LOG_VIC("%s: irq %d level %d", __func__, irq_num, level); + + if (level) { + vic->int_raw_status |=3D BIT(irq_num); + } else { + vic->int_raw_status &=3D ~BIT(irq_num); + } + + vic_update_irq(vic); +} + +static void nios2_vic_reset(DeviceState *dev) +{ + Nios2Vic *vic =3D NIOS2_VIC(dev); + memset(&vic->int_config, 0, sizeof(vic->int_config)); + vic->vic_config =3D 0; + vic->int_raw_status =3D 0; + vic->int_enable =3D 0; + vic->sw_int =3D 0; + vic->vic_status =3D 0; + vic->vec_tbl_base =3D 0; + vic->vec_tbl_addr =3D 0; +} + +static uint64_t nios2_vic_csr_read(void *opaque, hwaddr offset, unsigned s= ize) +{ + Nios2Vic *vic =3D opaque; + int index =3D offset / 4; + + switch (index) { + case INT_CONFIG0 ... INT_CONFIG31: + return vic->int_config[index - INT_CONFIG0]; + case INT_ENABLE: + return vic->int_enable; + case INT_PENDING: + return vic_int_pending(vic); + case INT_RAW_STATUS: + return vic->int_raw_status; + case SW_INTERRUPT: + return vic->sw_int; + case VIC_CONFIG: + return vic->vic_config; + case VIC_STATUS: + return vic->vic_status; + case VEC_TBL_BASE: + return vic->vec_tbl_base; + case VEC_TBL_ADDR: + return vic->vec_tbl_addr; + default: + return 0; + } +} + +static void nios2_vic_csr_write(void *opaque, hwaddr offset, uint64_t valu= e, + unsigned size) +{ + Nios2Vic *vic =3D opaque; + int index =3D offset / 4; + + switch (index) { + case INT_CONFIG0 ... INT_CONFIG31: + vic->int_config[index - INT_CONFIG0] =3D value; + break; + case INT_ENABLE: + vic->int_enable =3D value; + break; + case INT_ENABLE_SET: + vic->int_enable |=3D value; + break; + case INT_ENABLE_CLR: + vic->int_enable &=3D ~value; + break; + case SW_INTERRUPT: + vic->sw_int =3D value; + break; + case SW_INTERRUPT_SET: + vic->sw_int |=3D value; + break; + case SW_INTERRUPT_CLR: + vic->sw_int &=3D ~value; + break; + case VIC_CONFIG: + vic->vic_config =3D value; + break; + case VEC_TBL_BASE: + vic->vec_tbl_base =3D value; + break; + default: + ; + } + + vic_update_irq(vic); +} + +static const MemoryRegionOps nios2_vic_csr_ops =3D { + .read =3D nios2_vic_csr_read, + .write =3D nios2_vic_csr_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { .min_access_size =3D 4, .max_access_size =3D 4 } +}; + +static void nios2_vic_realize(DeviceState *dev, Error **errp) +{ + Nios2Vic *vic =3D NIOS2_VIC(dev); + + if (!vic->cpu) { + /* This is a programming error in the code using this device */ + error_setg(errp, "nios2-vic 'cpu' link property was not set"); + return; + } + + sysbus_init_irq(SYS_BUS_DEVICE(dev), &vic->output_int); + qdev_init_gpio_in(dev, vic_set_irq, NIOS2_VIC_MAX_IRQ); + + memory_region_init_io(&vic->csr, OBJECT(dev), &nios2_vic_csr_ops, vic, + "nios2.vic.csr", CSR_COUNT * sizeof(uint32_t)); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &vic->csr); +} + +static Property nios2_vic_properties[] =3D { + DEFINE_PROP_LINK("cpu", Nios2Vic, cpu, TYPE_CPU, CPUState *), + DEFINE_PROP_END_OF_LIST() +}; + +static const VMStateDescription nios2_vic_vmstate =3D { + .name =3D "nios2-vic", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]){ VMSTATE_UINT32_ARRAY(int_config, Nios2Vi= c, 32), + VMSTATE_UINT32(vic_config, Nios2Vic), + VMSTATE_UINT32(int_raw_status, Nios2Vic), + VMSTATE_UINT32(int_enable, Nios2Vic), + VMSTATE_UINT32(sw_int, Nios2Vic), + VMSTATE_UINT32(vic_status, Nios2Vic), + VMSTATE_UINT32(vec_tbl_base, Nios2Vic), + VMSTATE_UINT32(vec_tbl_addr, Nios2Vic), + VMSTATE_END_OF_LIST() }, +}; + + +static void nios2_vic_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->reset =3D nios2_vic_reset; + dc->realize =3D nios2_vic_realize; + dc->vmsd =3D &nios2_vic_vmstate; + device_class_set_props(dc, nios2_vic_properties); +} + +static const TypeInfo nios2_vic_info =3D { + .name =3D TYPE_NIOS2_VIC, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(Nios2Vic), + .class_init =3D nios2_vic_class_init, +}; + +static void nios2_vic_register_types(void) +{ + type_register_static(&nios2_vic_info); +} + +type_init(nios2_vic_register_types); -- 2.25.1 The contents of this email message and any attachments are intended solely = for the addressee(s) and may contain confidential and/or privileged informa= tion and may be legally protected from disclosure. If you are not the inten= ded recipient of this message or their agent, or if this message has been a= ddressed to you in error, please immediately alert the sender by reply emai= l and then delete this message and any attachments. If you are not the inte= nded recipient, you are hereby notified that any use, dissemination, copyin= g, or storage of this message or its attachments is strictly prohibited. From nobody Tue Feb 10 20:49:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=neuroblade.ai) ARC-Seal: i=2; a=rsa-sha256; t=1645710980; cv=pass; d=zohomail.com; s=zohoarc; b=Zj/XKqcMirHO01MjZ610tiTy5iRX3dqFcqbZh39sZ+SQAmMn1pJhgssDEHVFFvGY4PIFe4btT+XOF+Xnm4TtmNXwEmzioNoZdhe8uXcVqfXfqD5LldDrZyferJO7qZBmBnQMSINWi+nIceS2i1s1SOMo9tP2rcBW497bUyoRr0E= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645710980; 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=6qtFOmNqZy7r5i6a8zPmwmAhgZ6arJVgK60AdqilnN4=; b=Olcme2XVaKKbEsRQM+zkXozrq+jpF9kZinn8lgjcilA8KjOLhoQeZ81eLbzEk93X78ZAVD+ZmaDu/1QFHRv7EhEPy9q7LrzkOFNvslxvCNFov9jUivzt/u1KdWnfMSVt50KYt5HOdeTQ8EaTALmrH/Zw0IObSFvrf0HPLBNwgX4= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=neuroblade.ai) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645710980205777.7162038339243; Thu, 24 Feb 2022 05:56:20 -0800 (PST) Received: from localhost ([::1]:47926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNEbS-0006yO-Vz for importer@patchew.org; Thu, 24 Feb 2022 08:56:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNEaI-0006Fz-EC for qemu-devel@nongnu.org; Thu, 24 Feb 2022 08:55:07 -0500 Received: from mail-eopbgr00126.outbound.protection.outlook.com ([40.107.0.126]:2295 helo=EUR02-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNEaF-0004No-4x for qemu-devel@nongnu.org; Thu, 24 Feb 2022 08:55:05 -0500 Received: from AS9PR0301CA0047.eurprd03.prod.outlook.com (2603:10a6:20b:469::27) by VI1PR09MB2670.eurprd09.prod.outlook.com (2603:10a6:803:8a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.18; Thu, 24 Feb 2022 13:49:56 +0000 Received: from VE1EUR02FT029.eop-EUR02.prod.protection.outlook.com (2603:10a6:20b:469:cafe::67) by AS9PR0301CA0047.outlook.office365.com (2603:10a6:20b:469::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19 via Frontend Transport; Thu, 24 Feb 2022 13:49:56 +0000 Received: from nb-o365.localdomain (192.116.190.34) by VE1EUR02FT029.mail.protection.outlook.com (10.152.12.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23 via Frontend Transport; Thu, 24 Feb 2022 13:49:55 +0000 Received: from amirgonnen-vm.neuroblade.corp (amirgonnen-vm.neuroblade.corp [192.168.3.87]) by nb-o365.localdomain (Postfix) with ESMTP id EDD491F6C1; Thu, 24 Feb 2022 15:49:33 +0200 (IST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LgvZiFpMO8X0I+Xi7hDdfdkPqqOpd72eYMnCOgvuTr0Xv3dixewjFr1IWpDhlqL6EcUDJ8ODDc5NvOx2UgrggXKMB3aEWkqoUjUiFgtuww8GCox+Y2N26QqGN3nC0Bf33K+hKshlYWQBmk99kDsqq2O7cghXvVeozwkgkSfaH/MzHjXyeSuy3lX2vQf/dLjKpyJzqn3XP7l7TAejV1cxLhu6QJjZ86CqQ+W65xIQMZ0YCGmGfV4uiXXjhx8Q8AyJ97qtv/3HjQeUjDBngGGNxNYB3V8kuxFuaIs8ZXxFPMe9MpvWHIZz+AgeREpuE5geAK9UQd+dcvRBCgelV+S+gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6qtFOmNqZy7r5i6a8zPmwmAhgZ6arJVgK60AdqilnN4=; b=WR+nO5MYJf4c6YKZjdR3rZcvOZvYL3DzuUs0GXPe55hgnSqFFVJ/Efv72blW3VgWcOnd4V4gdUmsl92b9CfG7q889hbH2pkDsCrX8xql12awhRwse7Nlv2ZEnwcnntbQPvGe/PBkCEkxfVtEAH0wXwymZtZMD89RbmLuaSZcN/7dCrJ9z7Hvru/UWZW0iVo3WO4toFuxlCeEnYjJasxdqzYwlWlAd3fVRhFFanXTDzMYdRCAZ9HrIJtabN40xMpZUqK7PHOXpBBWnrxW01sQ0iI84dEsjOC2bd12MumArUkXFd8+IpU3rfF+uBViH0FWq8HKH7n9CAAmxzpxb5iF7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 192.116.190.34) smtp.rcpttodomain=denx.de smtp.mailfrom=neuroblade.ai; dmarc=none action=none header.from=neuroblade.ai; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NeuroBlade.onmicrosoft.com; s=selector2-NeuroBlade-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6qtFOmNqZy7r5i6a8zPmwmAhgZ6arJVgK60AdqilnN4=; b=Ft4IeTy70WRZRkpQRXDiTLfTkaL0xmDWM9tjaAuGRasVrD1N6OFAvHk7i8eQHdSTWUhBA10rcfLKztu+uHRdSXhGNuVM+oQ+WhZoPWc5DfvZEsYVmozfr20JuWI7bbmtBVF4vVWX9MI9BaLwbM7hDO3ZbM97O8yh24KP74ss0fA= X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 192.116.190.34) smtp.mailfrom=neuroblade.ai; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=neuroblade.ai; 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: Fail (protection.outlook.com: domain of neuroblade.ai does not designate 192.116.190.34 as permitted sender) receiver=protection.outlook.com; client-ip=192.116.190.34; helo=nb-o365.localdomain; From: Amir Gonnen To: qemu-devel@nongnu.org, Peter Maydell , Chris Wulff , Marek Vasut Subject: [PATCH v2 4/4] hw/nios2: Machine with a Vectored Interrupt Controller Date: Thu, 24 Feb 2022 15:49:01 +0200 Message-Id: <20220224134901.500007-5-amir.gonnen@neuroblade.ai> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224134901.500007-1-amir.gonnen@neuroblade.ai> References: <20220224134901.500007-1-amir.gonnen@neuroblade.ai> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bbc507c1-b205-4b7e-56bf-08d9f79c8a6c X-MS-TrafficTypeDiagnostic: VI1PR09MB2670:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: geJbfG/0tCRqRJQGNCKp0bVGtFBHH6KgqrjKFVkv8ICx1tAZ9c4rPAgR38OXvP3DRuH0ZG4zjZsXzrEcaIC20OTVcAnEu+NItgWzh0B1BH3OHKOcUcBqf2F5MGtdPFMAzUjSg5K+ku/9qZUwH5g8m7SX2PGnUC0tuoAE9VrRsrrdKuUSXBHbUmmoMl0zLoWdVvIHvBbiLpG/ZJYUjzgioPuXLDP/CX0AaPhhDKJcYOXqRPtX49O61oKAWWyJa572En2k4ZmyElh5NPydyFa2hSLivG32ytaVhzRxSS519avoVUiAyj533WsctPVH94mCD53fTJm0pG2wBHDvzY7kz8/DulEOkKNByKnH0G42G2oe4SlYwUYVM6a/I3EJP+r2vx0nIhoCpetyVHTOJ13BVVwr7dIPrj3hC9ciBgeEkpKPphikGuDnl4wk8FGlZKrwxhpyNxIU3Tff1+EK/eeRROIcawZc3iQ2bGqI17GfNR9qrD5lmLMPTQFiFHaLX9j3C90v2NxcYuqbJyERkPoo3aZzMad1jRSTarsetalCN5IgaKkfen78nIdp9VraQurnOyBvnDvlfkR6Ip4p/FLcK3cy8QilJKoPDqGpAFiHSxcLNEQ9+KmMrDF4ShTuANkqsP0ksjjKTUSq8YpQw5COmrKhiuG4VAwEIrJ3EyIrucyTdWAoR+6b/N/jk/BkKMgNYSnNqY37dXCxlGmcsur6qyTtcX8hAXR1wbIe0svcvnk= X-Forefront-Antispam-Report: CIP:192.116.190.34; CTRY:IL; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:nb-o365.localdomain; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(376002)(39840400004)(136003)(346002)(34036004)(396003)(36840700001)(46966006)(110136005)(36860700001)(356005)(82310400004)(44832011)(86362001)(4326008)(508600001)(70206006)(70586007)(8676002)(81166007)(8936002)(6666004)(186003)(316002)(6266002)(2906002)(40480700001)(36756003)(1076003)(5660300002)(83380400001)(26005)(336012)(2616005)(47076005)(107886003)(36900700001)(27056005); DIR:OUT; SFP:1102; X-OriginatorOrg: neuroblade.ai X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 13:49:55.7544 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bbc507c1-b205-4b7e-56bf-08d9f79c8a6c X-MS-Exchange-CrossTenant-Id: 63c61203-65af-4cf8-98e5-d12f35edaefa X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=63c61203-65af-4cf8-98e5-d12f35edaefa; Ip=[192.116.190.34]; Helo=[nb-o365.localdomain] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR02FT029.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR09MB2670 Received-SPF: pass client-ip=40.107.0.126; envelope-from=amir.gonnen@neuroblade.ai; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amir Gonnen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @NeuroBlade.onmicrosoft.com) X-ZM-MESSAGEID: 1645710982345100001 Content-Type: text/plain; charset="utf-8" Demonstrate how to use nios2 VIC on a machine. Introduce a new machine "10m50-ghrd-vic" which is based on "10m50-ghrd" with a VIC attached and internal interrupt controller removed. When VIC is present, irq0 connects the VIC to the cpu, intc_present is set to false to disable the internal interrupt controller, and the devices on the machine are attached to the VIC (and not directly to cpu). To allow VIC update EIC fields, we set the "cpu" property of the VIC with a reference to the nios2 cpu. Signed-off-by: Amir Gonnen --- hw/nios2/10m50_devboard.c | 64 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c index 3d1205b8bd..9f62a2993f 100644 --- a/hw/nios2/10m50_devboard.c +++ b/hw/nios2/10m50_devboard.c @@ -36,10 +36,23 @@ #include "boot.h" +#define TYPE_NIOS2_MACHINE MACHINE_TYPE_NAME("10m50-ghrd") +typedef struct Nios2MachineClass Nios2MachineClass; +DECLARE_OBJ_CHECKERS(MachineState, Nios2MachineClass, + NIOS2_MACHINE, TYPE_NIOS2_MACHINE) + #define BINARY_DEVICE_TREE_FILE "10m50-devboard.dtb" +struct Nios2MachineClass { + MachineClass parent_obj; + + bool vic; +}; + static void nios2_10m50_ghrd_init(MachineState *machine) { + Nios2MachineClass *nmc =3D NIOS2_MACHINE_GET_CLASS(machine); + Nios2CPU *cpu; DeviceState *dev; MemoryRegion *address_space_mem =3D get_system_memory(); @@ -74,8 +87,24 @@ static void nios2_10m50_ghrd_init(MachineState *machine) /* Create CPU -- FIXME */ cpu =3D NIOS2_CPU(cpu_create(TYPE_NIOS2_CPU)); - for (i =3D 0; i < 32; i++) { - irq[i] =3D qdev_get_gpio_in_named(DEVICE(cpu), "IRQ", i); + + if (nmc->vic) { + DeviceState *dev =3D qdev_new("nios2-vic"); + + object_property_set_link(OBJECT(dev), "cpu", OBJECT(cpu), &error_f= atal); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + cpu->intc_present =3D false; + qemu_irq cpu_irq =3D qdev_get_gpio_in_named(DEVICE(cpu), "IRQ", 0); + sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, cpu_irq); + for (int i =3D 0; i < 32; i++) { + irq[i] =3D qdev_get_gpio_in(dev, i); + } + MemoryRegion *dev_mr =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev= ), 0); + memory_region_add_subregion(address_space_mem, 0x18002000, dev_mr); + } else { + for (i =3D 0; i < 32; i++) { + irq[i] =3D qdev_get_gpio_in_named(DEVICE(cpu), "IRQ", i); + } } /* Register: Altera 16550 UART */ @@ -105,11 +134,38 @@ static void nios2_10m50_ghrd_init(MachineState *machi= ne) BINARY_DEVICE_TREE_FILE, NULL); } -static void nios2_10m50_ghrd_machine_init(struct MachineClass *mc) +static void nios2_10m50_ghrd_machine_class_init(ObjectClass *oc, void *dat= a) { + MachineClass *mc =3D MACHINE_CLASS(oc); + Nios2MachineClass *nmc =3D NIOS2_MACHINE_CLASS(oc); mc->desc =3D "Altera 10M50 GHRD Nios II design"; mc->init =3D nios2_10m50_ghrd_init; mc->is_default =3D true; + nmc->vic =3D false; } -DEFINE_MACHINE("10m50-ghrd", nios2_10m50_ghrd_machine_init); +static void nios2_10m50_ghrd_vic_machine_class_init(ObjectClass *oc, void = *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + Nios2MachineClass *nmc =3D NIOS2_MACHINE_CLASS(oc); + mc->desc =3D "Altera 10M50 GHRD Nios II design with VIC"; + mc->init =3D nios2_10m50_ghrd_init; + mc->is_default =3D false; + nmc->vic =3D true; +} + +static const TypeInfo nios_machine_types[] =3D { + { + .name =3D MACHINE_TYPE_NAME("10m50-ghrd"), + .parent =3D TYPE_MACHINE, + .class_size =3D sizeof(Nios2MachineClass), + .class_init =3D nios2_10m50_ghrd_machine_class_init, + }, { + .name =3D MACHINE_TYPE_NAME("10m50-ghrd-vic"), + .parent =3D TYPE_MACHINE, + .class_size =3D sizeof(Nios2MachineClass), + .class_init =3D nios2_10m50_ghrd_vic_machine_class_init, + } +}; + +DEFINE_TYPES(nios_machine_types) -- 2.25.1 The contents of this email message and any attachments are intended solely = for the addressee(s) and may contain confidential and/or privileged informa= tion and may be legally protected from disclosure. If you are not the inten= ded recipient of this message or their agent, or if this message has been a= ddressed to you in error, please immediately alert the sender by reply emai= l and then delete this message and any attachments. If you are not the inte= nded recipient, you are hereby notified that any use, dissemination, copyin= g, or storage of this message or its attachments is strictly prohibited.