From nobody Sat Apr 27 14:10:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487258303439179.1612890088062; Thu, 16 Feb 2017 07:18:23 -0800 (PST) Received: from localhost ([::1]:47275 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceNp7-0007Dv-8J for importer@patchew.org; Thu, 16 Feb 2017 10:18:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4u-0002LB-6G for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceN4r-0007RU-0o for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:36 -0500 Received: from greensocs.com ([193.104.36.180]:53103) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4q-0007Nm-L7 for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:32 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id C743240D415; Thu, 16 Feb 2017 15:30:27 +0100 (CET) Received: from greensocs.com ([127.0.0.1]) by localhost (gs-01.greensocs.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id odnDlODC4k1K; Thu, 16 Feb 2017 15:30:27 +0100 (CET) Received: from corsair.home (bd231-7-88-127-3-24.fbx.proxad.net [88.127.3.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: fred.konrad@greensocs.com) by greensocs.com (Postfix) with ESMTPSA id 91ACF40D40E; Thu, 16 Feb 2017 15:30:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255427; bh=18PF8c3PyUfq+tNct/HXy+bj21rBg/co+AD+/XEM+rQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kZebfurAEeTG5A694u++XlWuUyXAwhgeUNGSapmpW5h66ddOsvcgR3P7970pBl8Iq sgSLW09SaOzhxFFXIo77r4CIci/yzcdz9T2FUb2HXW/ylkHZcXg97fkjZBT2cNrnoI 9Ar/NXMHzJL8d2N6PmfDqlmtWACI0UIiZs42V8Dw= X-Virus-Scanned: amavisd-new at greensocs.com Authentication-Results: gs-01.greensocs.com (amavisd-new); dkim=pass (1024-bit key) header.d=greensocs.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255427; bh=18PF8c3PyUfq+tNct/HXy+bj21rBg/co+AD+/XEM+rQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kZebfurAEeTG5A694u++XlWuUyXAwhgeUNGSapmpW5h66ddOsvcgR3P7970pBl8Iq sgSLW09SaOzhxFFXIo77r4CIci/yzcdz9T2FUb2HXW/ylkHZcXg97fkjZBT2cNrnoI 9Ar/NXMHzJL8d2N6PmfDqlmtWACI0UIiZs42V8Dw= From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 15:30:07 +0100 Message-Id: <1487255413-14196-2-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> References: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH V1 1/7] cputlb: cleanup get_page_addr_code to use VICTIM_TLB_HIT X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, mark.burton@greensocs.com, alistair.francis@xilinx.com, clg@kaod.org, pbonzini@redhat.com, fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: KONRAD Frederic This replaces env1 and page_index variables by env and index so we can use VICTIM_TLB_HIT macro later. Signed-off-by: KONRAD Frederic Reviewed-by: Richard Henderson --- cputlb.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cputlb.c b/cputlb.c index 6c39927..665caea 100644 --- a/cputlb.c +++ b/cputlb.c @@ -457,21 +457,21 @@ static void report_bad_exec(CPUState *cpu, target_ulo= ng addr) * is actually a ram_addr_t (in system mode; the user mode emulation * version of this function returns a guest virtual address). */ -tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr) +tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) { - int mmu_idx, page_index, pd; + int mmu_idx, index, pd; void *p; MemoryRegion *mr; - CPUState *cpu =3D ENV_GET_CPU(env1); + CPUState *cpu =3D ENV_GET_CPU(env); CPUIOTLBEntry *iotlbentry; =20 - page_index =3D (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); - mmu_idx =3D cpu_mmu_index(env1, true); - if (unlikely(env1->tlb_table[mmu_idx][page_index].addr_code !=3D + index =3D (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); + mmu_idx =3D cpu_mmu_index(env, true); + if (unlikely(env->tlb_table[mmu_idx][index].addr_code !=3D (addr & TARGET_PAGE_MASK))) { - cpu_ldub_code(env1, addr); + cpu_ldub_code(env, addr); } - iotlbentry =3D &env1->iotlb[mmu_idx][page_index]; + iotlbentry =3D &env->iotlb[mmu_idx][index]; pd =3D iotlbentry->addr & ~TARGET_PAGE_MASK; mr =3D iotlb_to_region(cpu, pd, iotlbentry->attrs); if (memory_region_is_unassigned(mr)) { @@ -484,7 +484,7 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1, t= arget_ulong addr) exit(1); } } - p =3D (void *)((uintptr_t)addr + env1->tlb_table[mmu_idx][page_index].= addend); + p =3D (void *)((uintptr_t)addr + env->tlb_table[mmu_idx][index].addend= ); return qemu_ram_addr_from_host_nofail(p); } =20 --=20 1.8.3.1 From nobody Sat Apr 27 14:10:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487257752027166.06385831350156; Thu, 16 Feb 2017 07:09:12 -0800 (PST) Received: from localhost ([::1]:47228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceNg8-0006Fv-9a for importer@patchew.org; Thu, 16 Feb 2017 10:09:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4u-0002LG-6Y for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceN4q-0007RJ-V7 for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:36 -0500 Received: from greensocs.com ([193.104.36.180]:53197) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4q-0007OM-Ig for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:32 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id B23C440D419; Thu, 16 Feb 2017 15:30:28 +0100 (CET) Received: from greensocs.com ([127.0.0.1]) by localhost (gs-01.greensocs.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jM33VWH7nhKq; Thu, 16 Feb 2017 15:30:27 +0100 (CET) Received: from corsair.home (bd231-7-88-127-3-24.fbx.proxad.net [88.127.3.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: fred.konrad@greensocs.com) by greensocs.com (Postfix) with ESMTPSA id 380BE40D414; Thu, 16 Feb 2017 15:30:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255428; bh=gyIhXgrpIztPCsO6V7u8crpVs4ubKq1AFGiLiyP0GSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=e76z7MKcFwCyWRSh+w47yzyzYM8JQq8gxY9jMbK6YIJkVpNeZJpKcAwW4cfXBIH2l 1LeeR+hWX1ZTKmzAVaR22J8+RTy6Y54bj4V5ZGXqvzSMkUAjQMnAs89CSKpTKZkD04 ff/oomMVvl3U/Zug/TQCAxpX9YsJxI30SvRfCMtI= X-Virus-Scanned: amavisd-new at greensocs.com Authentication-Results: gs-01.greensocs.com (amavisd-new); dkim=pass (1024-bit key) header.d=greensocs.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255427; bh=gyIhXgrpIztPCsO6V7u8crpVs4ubKq1AFGiLiyP0GSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aPYtprcOP8lQM3HTKzqnHhwJSu2yopuFEhkBcD6+DqW5jss8biT68jv1ggZoEg1Rb P0flgzp6iEy8NDCfhMBsOHKMfKkJ5Y7qMeBl2KToaPFnEwzmfmMG+7iKfZjF1TtmlW 7Ur5Dx2CaHMyCgclOwZFYbX7njNe/ma2CZutkG3c= From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 15:30:08 +0100 Message-Id: <1487255413-14196-3-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> References: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH V1 2/7] cputlb: move get_page_addr_code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, mark.burton@greensocs.com, alistair.francis@xilinx.com, clg@kaod.org, pbonzini@redhat.com, fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: KONRAD Frederic This just moves the code before VICTIM_TLB_HIT macro definition so we can use it. Signed-off-by: KONRAD Frederic Reviewed-by: Richard Henderson --- cputlb.c | 72 ++++++++++++++++++++++++++++++++----------------------------= ---- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/cputlb.c b/cputlb.c index 665caea..b3a5f47 100644 --- a/cputlb.c +++ b/cputlb.c @@ -452,42 +452,6 @@ static void report_bad_exec(CPUState *cpu, target_ulon= g addr) log_cpu_state_mask(LOG_GUEST_ERROR, cpu, CPU_DUMP_FPU | CPU_DUMP_CCOP); } =20 -/* NOTE: this function can trigger an exception */ -/* NOTE2: the returned address is not exactly the physical address: it - * is actually a ram_addr_t (in system mode; the user mode emulation - * version of this function returns a guest virtual address). - */ -tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) -{ - int mmu_idx, index, pd; - void *p; - MemoryRegion *mr; - CPUState *cpu =3D ENV_GET_CPU(env); - CPUIOTLBEntry *iotlbentry; - - index =3D (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); - mmu_idx =3D cpu_mmu_index(env, true); - if (unlikely(env->tlb_table[mmu_idx][index].addr_code !=3D - (addr & TARGET_PAGE_MASK))) { - cpu_ldub_code(env, addr); - } - iotlbentry =3D &env->iotlb[mmu_idx][index]; - pd =3D iotlbentry->addr & ~TARGET_PAGE_MASK; - mr =3D iotlb_to_region(cpu, pd, iotlbentry->attrs); - if (memory_region_is_unassigned(mr)) { - CPUClass *cc =3D CPU_GET_CLASS(cpu); - - if (cc->do_unassigned_access) { - cc->do_unassigned_access(cpu, addr, false, true, 0, 4); - } else { - report_bad_exec(cpu, addr); - exit(1); - } - } - p =3D (void *)((uintptr_t)addr + env->tlb_table[mmu_idx][index].addend= ); - return qemu_ram_addr_from_host_nofail(p); -} - static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, target_ulong addr, uintptr_t retaddr, int size) { @@ -554,6 +518,42 @@ static bool victim_tlb_hit(CPUArchState *env, size_t m= mu_idx, size_t index, victim_tlb_hit(env, mmu_idx, index, offsetof(CPUTLBEntry, TY), \ (ADDR) & TARGET_PAGE_MASK) =20 +/* NOTE: this function can trigger an exception */ +/* NOTE2: the returned address is not exactly the physical address: it + * is actually a ram_addr_t (in system mode; the user mode emulation + * version of this function returns a guest virtual address). + */ +tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) +{ + int mmu_idx, index, pd; + void *p; + MemoryRegion *mr; + CPUState *cpu =3D ENV_GET_CPU(env); + CPUIOTLBEntry *iotlbentry; + + index =3D (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); + mmu_idx =3D cpu_mmu_index(env, true); + if (unlikely(env->tlb_table[mmu_idx][index].addr_code !=3D + (addr & TARGET_PAGE_MASK))) { + cpu_ldub_code(env, addr); + } + iotlbentry =3D &env->iotlb[mmu_idx][index]; + pd =3D iotlbentry->addr & ~TARGET_PAGE_MASK; + mr =3D iotlb_to_region(cpu, pd, iotlbentry->attrs); + if (memory_region_is_unassigned(mr)) { + CPUClass *cc =3D CPU_GET_CLASS(cpu); + + if (cc->do_unassigned_access) { + cc->do_unassigned_access(cpu, addr, false, true, 0, 4); + } else { + report_bad_exec(cpu, addr); + exit(1); + } + } + p =3D (void *)((uintptr_t)addr + env->tlb_table[mmu_idx][index].addend= ); + return qemu_ram_addr_from_host_nofail(p); +} + /* Probe for whether the specified guest write access is permitted. * If it is not permitted then an exception will be taken in the same * way as if this were a real write access (and we will not return). --=20 1.8.3.1 From nobody Sat Apr 27 14:10:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487257302843259.59168997061386; Thu, 16 Feb 2017 07:01:42 -0800 (PST) Received: from localhost ([::1]:47184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceNYx-00005x-RS for importer@patchew.org; Thu, 16 Feb 2017 10:01:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4u-0002LF-6Y for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceN4q-0007R2-RX for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:36 -0500 Received: from greensocs.com ([193.104.36.180]:53249) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4q-0007Ov-It for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:32 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 46D8C40D416; Thu, 16 Feb 2017 15:30:29 +0100 (CET) Received: from greensocs.com ([127.0.0.1]) by localhost (gs-01.greensocs.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YHqyxVXCBd9y; Thu, 16 Feb 2017 15:30:28 +0100 (CET) Received: from corsair.home (bd231-7-88-127-3-24.fbx.proxad.net [88.127.3.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: fred.konrad@greensocs.com) by greensocs.com (Postfix) with ESMTPSA id EB3BB40D40A; Thu, 16 Feb 2017 15:30:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255429; bh=vFs4pz0qoNSPRirMExI/nfF83RiQEDUvvMEt6Nfjry4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vIONwvqVKPdWvE/w+GDaTtEAGhWhXC2Rjy9LXRKvU5VVzurR7gPAQuEd/yY69Gzk0 su5wNMhtogDMB2wFdZrHwLeOm+Qn+JByYUQEIBoh4IApvSD3tQAPbBQfiCh2ZjpiLz HvTeYz6T5j5UAfQFSH8yEtz6PAm/fc9zMxhxFV/s= X-Virus-Scanned: amavisd-new at greensocs.com Authentication-Results: gs-01.greensocs.com (amavisd-new); dkim=pass (1024-bit key) header.d=greensocs.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255428; bh=vFs4pz0qoNSPRirMExI/nfF83RiQEDUvvMEt6Nfjry4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kCyo01Hwo/bDWKOmKpN1J1REGo31wi3TuUdGcgtMt5FnXo8Wz4p8HO/7SQqeCeWTe cHPv5WtyJIkzRdJlRIrkFi+0Wofukl3jVMlfaQ8knD2ybxnb21wL4gS8fA18XW3mau f3kYoczIiqdPLwiqnEYIjfj5VEQep9zyTCC2XQYc= From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 15:30:09 +0100 Message-Id: <1487255413-14196-4-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> References: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH V1 3/7] cputlb: fix the way get_page_addr_code fills the tlb X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, mark.burton@greensocs.com, alistair.francis@xilinx.com, clg@kaod.org, pbonzini@redhat.com, fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: KONRAD Frederic get_page_addr_code(..) does a cpu_ldub_code to fill the tlb: This can lead to some side effects if a device is mapped at this address. So this patch replaces the cpu_memory_ld by a tlb_fill. Signed-off-by: KONRAD Frederic Reviewed-by: Richard Henderson --- cputlb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cputlb.c b/cputlb.c index b3a5f47..846341e 100644 --- a/cputlb.c +++ b/cputlb.c @@ -534,8 +534,10 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env, t= arget_ulong addr) index =3D (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); mmu_idx =3D cpu_mmu_index(env, true); if (unlikely(env->tlb_table[mmu_idx][index].addr_code !=3D - (addr & TARGET_PAGE_MASK))) { - cpu_ldub_code(env, addr); + (addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK)))) { + if (!VICTIM_TLB_HIT(addr_read, addr)) { + tlb_fill(ENV_GET_CPU(env), addr, MMU_INST_FETCH, mmu_idx, 0); + } } iotlbentry =3D &env->iotlb[mmu_idx][index]; pd =3D iotlbentry->addr & ~TARGET_PAGE_MASK; --=20 1.8.3.1 From nobody Sat Apr 27 14:10:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487257600672824.449349049985; Thu, 16 Feb 2017 07:06:40 -0800 (PST) Received: from localhost ([::1]:47215 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceNdm-0004Dw-2U for importer@patchew.org; Thu, 16 Feb 2017 10:06:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4u-0002LK-77 for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceN4q-0007RI-VG for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:36 -0500 Received: from greensocs.com ([193.104.36.180]:53400) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4q-0007Pp-Ic for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:32 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 434E240D418; Thu, 16 Feb 2017 15:30:30 +0100 (CET) Received: from greensocs.com ([127.0.0.1]) by localhost (gs-01.greensocs.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rR-zfdAUAJwz; Thu, 16 Feb 2017 15:30:29 +0100 (CET) Received: from corsair.home (bd231-7-88-127-3-24.fbx.proxad.net [88.127.3.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: fred.konrad@greensocs.com) by greensocs.com (Postfix) with ESMTPSA id 96C6740D40E; Thu, 16 Feb 2017 15:30:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255430; bh=XUssQOThNdWcLnnGFJBrWLPlD8QtXwr5ns/ymsu+ygA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jSNO5AW17kIRrbNGhTxB/Uj0w5FCExOG7ROrRQFikNwv55QCL0nnZs1p2Zmbd4sc9 ZkN6KePDMuC3qosHJzZG7IRw0sksdLfpuysyb67u04bAuQj7l5k1ANLEkCOwCSTNS1 2Rrh+udJG2HXrWiTaPFBvYMeNajBaCtq7PW2GR7o= X-Virus-Scanned: amavisd-new at greensocs.com Authentication-Results: gs-01.greensocs.com (amavisd-new); dkim=pass (1024-bit key) header.d=greensocs.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255429; bh=XUssQOThNdWcLnnGFJBrWLPlD8QtXwr5ns/ymsu+ygA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qiSup8l3EZPoARcE5Zh2LCddv27Jk+hdkW7mqw/ZoRdND6x8vithQ+1wey7T+QD0y Gsc4vL7tfm7spbSMtZYucOFeGytjr7y6M0zPA421ZAcSNe91OLeWla62KMS/LiEEyJ 8XXvP8DZCy7nlOahlvaB2AGbLh/nbGh32QDms+Ko= From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 15:30:10 +0100 Message-Id: <1487255413-14196-5-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> References: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH V1 4/7] exec: allow to get a pointer for some mmio memory region X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, mark.burton@greensocs.com, alistair.francis@xilinx.com, clg@kaod.org, pbonzini@redhat.com, fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: KONRAD Frederic This introduces a special callback which allows to run code from some MMIO devices. SysBusDevice with a MemoryRegion which implements the request_ptr callback = will be notified when the guest try to execute code from their offset. Then it w= ill be able to eg: pre-load some code from an SPI device or ask a pointer from = an external simulator, etc.. When the pointer or the data in it are no longer valid the device has to invalidate it. Signed-off-by: KONRAD Frederic RFC -> V1: * Use mmio-interface instead of directly creating the subregion. --- cputlb.c | 7 +++++++ include/exec/memory.h | 35 +++++++++++++++++++++++++++++++ memory.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 99 insertions(+) diff --git a/cputlb.c b/cputlb.c index 846341e..9077247 100644 --- a/cputlb.c +++ b/cputlb.c @@ -545,6 +545,13 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env, t= arget_ulong addr) if (memory_region_is_unassigned(mr)) { CPUClass *cc =3D CPU_GET_CLASS(cpu); =20 + if (memory_region_request_mmio_ptr(mr, addr)) { + /* A MemoryRegion is potentially added so re-run the + * get_page_addr_code. + */ + return get_page_addr_code(env, addr); + } + if (cc->do_unassigned_access) { cc->do_unassigned_access(cpu, addr, false, true, 0, 4); } else { diff --git a/include/exec/memory.h b/include/exec/memory.h index 987f925..36b0eec 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -120,6 +120,15 @@ struct MemoryRegionOps { uint64_t data, unsigned size, MemTxAttrs attrs); + /* Instruction execution pre-callback: + * @addr is the address of the access relative to the @mr. + * @size is the size of the area returned by the callback. + * @offset is the location of the pointer inside @mr. + * + * Returns a pointer to a location which contains guest code. + */ + void *(*request_ptr)(void *opaque, hwaddr addr, unsigned *size, + unsigned *offset); =20 enum device_endian endianness; /* Guest-visible constraints: */ @@ -1253,6 +1262,32 @@ void memory_global_dirty_log_stop(void); void mtree_info(fprintf_function mon_printf, void *f, bool flatview); =20 /** + * memory_region_request_mmio_ptr: request a pointer to an mmio + * MemoryRegion. If it is possible map a RAM MemoryRegion with this pointe= r. + * When the device wants to invalidate the pointer it will call + * memory_region_invalidate_mmio_ptr. + * + * @mr: #MemoryRegion to check + * @addr: address within that region + * + * Returns true on success, false otherwise. + */ +bool memory_region_request_mmio_ptr(MemoryRegion *mr, hwaddr addr); + +/** + * memory_region_invalidate_mmio_ptr: invalidate the pointer to an mmio + * previously requested. + * In the end that means that if something wants to execute from this area= it + * will need to request the pointer again. + * + * @mr: #MemoryRegion associated to the pointer. + * @addr: address within that region + * @size: size of that area. + */ +void memory_region_invalidate_mmio_ptr(MemoryRegion *mr, hwaddr offset, + unsigned size); + +/** * memory_region_dispatch_read: perform a read directly to the specified * MemoryRegion. * diff --git a/memory.c b/memory.c index 6c58373..a605250 100644 --- a/memory.c +++ b/memory.c @@ -30,6 +30,8 @@ #include "exec/ram_addr.h" #include "sysemu/kvm.h" #include "sysemu/sysemu.h" +#include "hw/misc/mmio_interface.h" +#include "hw/qdev-properties.h" =20 //#define DEBUG_UNASSIGNED =20 @@ -2375,6 +2377,61 @@ void memory_listener_unregister(MemoryListener *list= ener) QTAILQ_REMOVE(&listener->address_space->listeners, listener, link_as); } =20 +bool memory_region_request_mmio_ptr(MemoryRegion *mr, hwaddr addr) +{ + void *host; + unsigned size =3D 0; + unsigned offset =3D 0; + Object *new_interface; + + if (!mr || !mr->ops->request_ptr) { + return false; + } + + /* + * Avoid an update if the request_ptr call + * memory_region_invalidate_mmio_ptr which seems to be likely when we = use + * a cache. + */ + memory_region_transaction_begin(); + + host =3D mr->ops->request_ptr(mr->opaque, addr - mr->addr, &size, &off= set); + + if (!host || !size) { + memory_region_transaction_commit(); + return false; + } + + new_interface =3D object_new("mmio_interface"); + qdev_prop_set_uint64(DEVICE(new_interface), "start", offset); + qdev_prop_set_uint64(DEVICE(new_interface), "end", offset + size - 1); + qdev_prop_set_bit(DEVICE(new_interface), "ro", true); + qdev_prop_set_ptr(DEVICE(new_interface), "host_ptr", host); + qdev_prop_set_ptr(DEVICE(new_interface), "subregion", mr); + object_property_set_bool(OBJECT(new_interface), true, "realized", NULL= ); + + memory_region_transaction_commit(); + return true; +} + +void memory_region_invalidate_mmio_ptr(MemoryRegion *mr, hwaddr offset, + unsigned size) +{ + MemoryRegionSection section =3D memory_region_find(mr, offset, size); + + if (section.mr !=3D mr) { + /* memory_region_find add a ref on section.mr */ + memory_region_unref(section.mr); + if (!MMIO_INTERFACE(section.mr->owner)) { + return; + } + /* We found the interface just drop it. */ + object_property_set_bool(section.mr->owner, false, "realized", NUL= L); + object_unref(section.mr->owner); + object_unparent(section.mr->owner); + } +} + void address_space_init(AddressSpace *as, MemoryRegion *root, const char *= name) { memory_region_ref(root); --=20 1.8.3.1 From nobody Sat Apr 27 14:10:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148725751604647.056432368880564; Thu, 16 Feb 2017 07:05:16 -0800 (PST) Received: from localhost ([::1]:47206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceNcP-00030j-ND for importer@patchew.org; Thu, 16 Feb 2017 10:05:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51217) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4u-0002LI-6u for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceN4r-0007Rr-Gv for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:36 -0500 Received: from greensocs.com ([193.104.36.180]:53623) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4r-0007RY-9o for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:33 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 1849440D41C; Thu, 16 Feb 2017 15:30:31 +0100 (CET) Received: from greensocs.com ([127.0.0.1]) by localhost (gs-01.greensocs.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PcELw0yRPoVw; Thu, 16 Feb 2017 15:30:30 +0100 (CET) Received: from corsair.home (bd231-7-88-127-3-24.fbx.proxad.net [88.127.3.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: fred.konrad@greensocs.com) by greensocs.com (Postfix) with ESMTPSA id 73AED40D412; Thu, 16 Feb 2017 15:30:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255431; bh=8gSlVKn+Xw0EjUuMTq78EerDTftjGRBIyLIqvWbzkdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MVBqJ7mfZeJYXOZsd6o1C59/XZ2enk0kAP+oAiifKlXi7FrsIp6+j4wnu7yZpY3yC SCemMzT8XhzaVQSLNLsPy82GIaDQKDeJFlDQ24u/IxHyCvDKe7bsANyjh+Mw+VjUGP TFRQmPgQ7rs+Qa9okY/nBLOfh9/utsp0QNLvaP+s= X-Virus-Scanned: amavisd-new at greensocs.com Authentication-Results: gs-01.greensocs.com (amavisd-new); dkim=pass (1024-bit key) header.d=greensocs.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255430; bh=8gSlVKn+Xw0EjUuMTq78EerDTftjGRBIyLIqvWbzkdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0W+ET4nv4Iv2bWFWEuyosMv6l6/ElF7aG6K5be1hYabhQkhzJwJDaXIMhooXQ2n12 LTgj2JgwOZiCosM4cFkWvCJxKOih6rBfaenhfpE56Hqjl120ibPzB7PnsHScpmxEop avKwPf1jssvgnNcNA8LmyHyw/h9XlNxoG3h64Teo= From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 15:30:11 +0100 Message-Id: <1487255413-14196-6-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> References: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH V1 5/7] qdev: add MemoryRegion property X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, mark.burton@greensocs.com, alistair.francis@xilinx.com, clg@kaod.org, pbonzini@redhat.com, fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: KONRAD Frederic We need to pass a pointer to a MemoryRegion for mmio_interface. So this just adds that. Signed-off-by: KONRAD Frederic --- include/hw/qdev-properties.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 7ac3153..babb258 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -171,6 +171,8 @@ extern PropertyInfo qdev_prop_arraylen; DEFINE_PROP_DEFAULT(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t) #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddre= ss) +#define DEFINE_PROP_MEMORY_REGION(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *) =20 #define DEFINE_PROP_END_OF_LIST() \ {} --=20 1.8.3.1 From nobody Sat Apr 27 14:10:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487257894489846.4189331925259; Thu, 16 Feb 2017 07:11:34 -0800 (PST) Received: from localhost ([::1]:47239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceNiU-0000CM-74 for importer@patchew.org; Thu, 16 Feb 2017 10:11:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4u-0002LJ-76 for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceN4r-0007S9-Ms for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:36 -0500 Received: from greensocs.com ([193.104.36.180]:53622) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4r-0007RZ-9e for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:33 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 52A5440D41A; Thu, 16 Feb 2017 15:30:32 +0100 (CET) Received: from greensocs.com ([127.0.0.1]) by localhost (gs-01.greensocs.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eRIgBc1R3uET; Thu, 16 Feb 2017 15:30:31 +0100 (CET) Received: from corsair.home (bd231-7-88-127-3-24.fbx.proxad.net [88.127.3.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: fred.konrad@greensocs.com) by greensocs.com (Postfix) with ESMTPSA id 72EB040D41B; Thu, 16 Feb 2017 15:30:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255432; bh=a9Yr7jln2nO1DSyoOHLX8z8OZMExGzpjmm2To9aGE1M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=erINF9Typ+GL81YCm/DPYtI/VIGBgNBB1pfR/jJNxFE9dbXCLHAdgFLSt1X2lmqsF 2hEgb4OHYZuRg690T+ltZDWfnqbXtIhrF0nzBtE69HiVZeX/eDz2EDUDjTrL87B0Xv Q0IVsBAT6Y9045ckxEB0kZpn52mRZ5zUJixeg8UE= X-Virus-Scanned: amavisd-new at greensocs.com Authentication-Results: gs-01.greensocs.com (amavisd-new); dkim=pass (1024-bit key) header.d=greensocs.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255430; bh=a9Yr7jln2nO1DSyoOHLX8z8OZMExGzpjmm2To9aGE1M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=uRFCdh78Lt++0bRP5D+YhuVWvgRRLnbwGdsTxX3KNN0jdZdmPSx8PkdPl9ncc8TG1 pKD9EKFqNY/rLUQd6GvxVOMOKYvJGvj6YHeMuowLl3rAaIF8xis4+USfWI8L0dnPtb oEE2KRshAgSfrvKOiH791WKdFWXdmcb94Kq7mw8w= From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 15:30:12 +0100 Message-Id: <1487255413-14196-7-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> References: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH V1 6/7] introduce mmio_interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, mark.burton@greensocs.com, alistair.francis@xilinx.com, clg@kaod.org, pbonzini@redhat.com, fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: KONRAD Frederic This introduces mmio_interface object which contains a MemoryRegion and can be hotplugged/hotunplugged. Signed-off-by: KONRAD Frederic --- hw/misc/Makefile.objs | 1 + hw/misc/mmio_interface.c | 128 +++++++++++++++++++++++++++++++++++= ++++ include/hw/misc/mmio_interface.h | 49 +++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 hw/misc/mmio_interface.c create mode 100644 include/hw/misc/mmio_interface.h diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index 898e4cc..91580a3 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -55,3 +55,4 @@ obj-$(CONFIG_EDU) +=3D edu.o obj-$(CONFIG_HYPERV_TESTDEV) +=3D hyperv_testdev.o obj-$(CONFIG_AUX) +=3D auxbus.o obj-$(CONFIG_ASPEED_SOC) +=3D aspeed_scu.o aspeed_sdmc.o +obj-y +=3D mmio_interface.o \ No newline at end of file diff --git a/hw/misc/mmio_interface.c b/hw/misc/mmio_interface.c new file mode 100644 index 0000000..223b9cf --- /dev/null +++ b/hw/misc/mmio_interface.c @@ -0,0 +1,128 @@ +/* + * mmio_interface.c + * + * Copyright (C) 2017 : GreenSocs + * http://www.greensocs.com/ , email: info@greensocs.com + * + * Developed by : + * Frederic Konrad + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option)any later version. + * + * This program is distributed in the hope that 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 for 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 "trace.h" +#include "hw/qdev-properties.h" +#include "hw/misc/mmio_interface.h" +#include "qapi/error.h" + +#ifndef DEBUG_MMIO_INTERFACE +#define DEBUG_MMIO_INTERFACE 0 +#endif + +static uint64_t mmio_interface_counter; + +#define DPRINTF(fmt, ...) do { = \ + if (DEBUG_MMIO_INTERFACE) { = \ + qemu_log("mmio_interface: 0x%16.16lX: " fmt, s->id, ## __VA_ARGS__= ); \ + } = \ +} while (0); + +static void mmio_interface_init(Object *obj) +{ + MMIOInterface *s =3D MMIO_INTERFACE(obj); + + if (DEBUG_MMIO_INTERFACE) { + s->id =3D mmio_interface_counter++; + } + + DPRINTF("interface created\n"); + s->host_ptr =3D 0; + s->subregion =3D 0; +} + +static void mmio_interface_realize(DeviceState *dev, Error **errp) +{ + MMIOInterface *s =3D MMIO_INTERFACE(dev); + + DPRINTF("realize from 0x%16.16lX to 0x%16.16lX map host pointer" + " %p\n", s->start, s->end, s->host_ptr); + + if (!s->host_ptr) { + error_setg(errp, "host_ptr property must be set"); + } + + if (!s->subregion) { + error_setg(errp, "subregion property must be set"); + } + + memory_region_init_ram_ptr(&s->ram_mem, OBJECT(s), "ram", + s->end - s->start + 1, s->host_ptr); + memory_region_set_readonly(&s->ram_mem, s->ro); + memory_region_add_subregion(s->subregion, s->start, &s->ram_mem); +} + +static void mmio_interface_unrealize(DeviceState *dev, Error **errp) +{ + MMIOInterface *s =3D MMIO_INTERFACE(dev); + + DPRINTF("unrealize from 0x%16.16lX to 0x%16.16lX map host pointer" + " %p\n", s->start, s->end, s->host_ptr); + memory_region_del_subregion(s->subregion, &s->ram_mem); +} + +static void mmio_interface_finalize(Object *obj) +{ + MMIOInterface *s =3D MMIO_INTERFACE(obj); + + DPRINTF("finalize from 0x%16.16lX to 0x%16.16lX map host pointer" + " %p\n", s->start, s->end, s->host_ptr); + object_unparent(OBJECT(&s->ram_mem)); +} + +static Property mmio_interface_properties[] =3D { + DEFINE_PROP_UINT64("start", MMIOInterface, start, 0), + DEFINE_PROP_UINT64("end", MMIOInterface, end, 0), + DEFINE_PROP_PTR("host_ptr", MMIOInterface, host_ptr), + DEFINE_PROP_BOOL("ro", MMIOInterface, ro, false), + DEFINE_PROP_MEMORY_REGION("subregion", MMIOInterface, subregion), + DEFINE_PROP_END_OF_LIST(), +}; + +static void mmio_interface_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + dc->realize =3D mmio_interface_realize; + dc->unrealize =3D mmio_interface_unrealize; + dc->props =3D mmio_interface_properties; +} + +static const TypeInfo mmio_interface_info =3D { + .name =3D TYPE_MMIO_INTERFACE, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(MMIOInterface), + .instance_init =3D mmio_interface_init, + .instance_finalize =3D mmio_interface_finalize, + .class_init =3D mmio_interface_class_init, +}; + +static void mmio_interface_register_types(void) +{ + type_register_static(&mmio_interface_info); +} + +type_init(mmio_interface_register_types) diff --git a/include/hw/misc/mmio_interface.h b/include/hw/misc/mmio_interf= ace.h new file mode 100644 index 0000000..90d34fb --- /dev/null +++ b/include/hw/misc/mmio_interface.h @@ -0,0 +1,49 @@ +/* + * mmio_interface.h + * + * Copyright (C) 2017 : GreenSocs + * http://www.greensocs.com/ , email: info@greensocs.com + * + * Developed by : + * Frederic Konrad + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option)any later version. + * + * This program is distributed in the hope that 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 for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + * + */ + +#ifndef MMIO_INTERFACE_H +#define MMIO_INTERFACE_H + +#include "exec/memory.h" + +#define TYPE_MMIO_INTERFACE "mmio_interface" +#define MMIO_INTERFACE(obj) OBJECT_CHECK(MMIOInterface, (obj), = \ + TYPE_MMIO_INTERFACE) + +typedef struct MMIOInterface { + DeviceState parent_obj; + + MemoryRegion *subregion; + MemoryRegion ram_mem; + uint64_t start; + uint64_t end; + bool ro; + uint64_t id; + void *host_ptr; +} MMIOInterface; + +void mmio_interface_map(MMIOInterface *s); +void mmio_interface_unmap(MMIOInterface *s); + +#endif /* MMIO_INTERFACE_H */ --=20 1.8.3.1 From nobody Sat Apr 27 14:10:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487256693718151.83189858007393; Thu, 16 Feb 2017 06:51:33 -0800 (PST) Received: from localhost ([::1]:47132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceNPA-0008Fm-8P for importer@patchew.org; Thu, 16 Feb 2017 09:51:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4u-0002LE-6U for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceN4r-0007SG-Ny for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:36 -0500 Received: from greensocs.com ([193.104.36.180]:53624) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN4r-0007Rf-Cz for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:30:33 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id AD97240D41B; Thu, 16 Feb 2017 15:30:32 +0100 (CET) Received: from greensocs.com ([127.0.0.1]) by localhost (gs-01.greensocs.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id n7PKy4AhF246; Thu, 16 Feb 2017 15:30:31 +0100 (CET) Received: from corsair.home (bd231-7-88-127-3-24.fbx.proxad.net [88.127.3.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: fred.konrad@greensocs.com) by greensocs.com (Postfix) with ESMTPSA id 2A80340D40E; Thu, 16 Feb 2017 15:30:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255432; bh=WWL0abNXIJMY+OeqbXzF5PHT2OOBAypIao+1S4u5zn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1Mo/1Jkm79cWAG07XNX/0+LHKkh9gAR6odbO/Bu8Ny0zoSU/i/K3wnBLCYNSdG14j GIOSiYIyvwzQSmsygEqaM5N9kvI9xv2Jbfvv8bcPiZJd15qdFyp1/s2KJnN5cylGD+ KgWdLzRXD8cNW0R8jT+eaJtz/Nzi2XiJJ8GOj1vM= X-Virus-Scanned: amavisd-new at greensocs.com Authentication-Results: gs-01.greensocs.com (amavisd-new); dkim=pass (1024-bit key) header.d=greensocs.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1487255431; bh=WWL0abNXIJMY+OeqbXzF5PHT2OOBAypIao+1S4u5zn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mWv/Z1SgCkIIGcs6eHn8mMGiabOjKNoUOBPuNxLy5/aq3W8aCpOVJcse/Qdn7Vdbh JtzShPqRfQOFFzbG11QCg9NqSuq1KwdxFHq6BuHwCNw5m+okEnh6R2s16F/GyLzijM N8PpOQveZICMJdZnKiGQymqEhM+18ajnpB1L7qqA= From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 15:30:13 +0100 Message-Id: <1487255413-14196-8-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> References: <1487255413-14196-1-git-send-email-fred.konrad@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH V1 7/7] xilinx_spips: allow mmio execution X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, mark.burton@greensocs.com, alistair.francis@xilinx.com, clg@kaod.org, pbonzini@redhat.com, fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: KONRAD Frederic This allows to execute from the lqspi area. When the request_ptr is called the device loads 1024bytes from the SPI devi= ce. Then this code can be executed by the guest. Signed-off-by: KONRAD Frederic --- hw/ssi/xilinx_spips.c | 74 ++++++++++++++++++++++++++++++++++++++---------= ---- 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/hw/ssi/xilinx_spips.c b/hw/ssi/xilinx_spips.c index da8adfa..e833028 100644 --- a/hw/ssi/xilinx_spips.c +++ b/hw/ssi/xilinx_spips.c @@ -496,6 +496,18 @@ static const MemoryRegionOps spips_ops =3D { .endianness =3D DEVICE_LITTLE_ENDIAN, }; =20 +static void xilinx_qspips_invalidate_mmio_ptr(XilinxQSPIPS *q) +{ + XilinxSPIPS *s =3D &q->parent_obj; + + if (q->lqspi_cached_addr !=3D ~0ULL) { + /* Invalidate the current mapped mmio */ + memory_region_invalidate_mmio_ptr(&s->mmlqspi, q->lqspi_cached_add= r, + LQSPI_CACHE_SIZE); + q->lqspi_cached_addr =3D ~0ULL; + } +} + static void xilinx_qspips_write(void *opaque, hwaddr addr, uint64_t value, unsigned size) { @@ -505,7 +517,7 @@ static void xilinx_qspips_write(void *opaque, hwaddr ad= dr, addr >>=3D 2; =20 if (addr =3D=3D R_LQSPI_CFG) { - q->lqspi_cached_addr =3D ~0ULL; + xilinx_qspips_invalidate_mmio_ptr(q); } } =20 @@ -517,27 +529,20 @@ static const MemoryRegionOps qspips_ops =3D { =20 #define LQSPI_CACHE_SIZE 1024 =20 -static uint64_t -lqspi_read(void *opaque, hwaddr addr, unsigned int size) +static void lqspi_load_cache(void *opaque, hwaddr addr) { - int i; XilinxQSPIPS *q =3D opaque; XilinxSPIPS *s =3D opaque; - uint32_t ret; - - if (addr >=3D q->lqspi_cached_addr && - addr <=3D q->lqspi_cached_addr + LQSPI_CACHE_SIZE - 4) { - uint8_t *retp =3D &q->lqspi_buf[addr - q->lqspi_cached_addr]; - ret =3D cpu_to_le32(*(uint32_t *)retp); - DB_PRINT_L(1, "addr: %08x, data: %08x\n", (unsigned)addr, - (unsigned)ret); - return ret; - } else { - int flash_addr =3D (addr / num_effective_busses(s)); - int slave =3D flash_addr >> LQSPI_ADDRESS_BITS; - int cache_entry =3D 0; - uint32_t u_page_save =3D s->regs[R_LQSPI_STS] & ~LQSPI_CFG_U_PAGE; - + int i; + int flash_addr =3D ((addr & ~(LQSPI_CACHE_SIZE - 1)) + / num_effective_busses(s)); + int slave =3D flash_addr >> LQSPI_ADDRESS_BITS; + int cache_entry =3D 0; + uint32_t u_page_save =3D s->regs[R_LQSPI_STS] & ~LQSPI_CFG_U_PAGE; + + if (addr < q->lqspi_cached_addr || + addr > q->lqspi_cached_addr + LQSPI_CACHE_SIZE - 4) { + xilinx_qspips_invalidate_mmio_ptr(q); s->regs[R_LQSPI_STS] &=3D ~LQSPI_CFG_U_PAGE; s->regs[R_LQSPI_STS] |=3D slave ? LQSPI_CFG_U_PAGE : 0; =20 @@ -589,12 +594,43 @@ lqspi_read(void *opaque, hwaddr addr, unsigned int si= ze) xilinx_spips_update_cs_lines(s); =20 q->lqspi_cached_addr =3D flash_addr * num_effective_busses(s); + } +} + +static void *lqspi_request_mmio_ptr(void *opaque, hwaddr addr, unsigned *s= ize, + unsigned *offset) +{ + XilinxQSPIPS *q =3D opaque; + hwaddr offset_within_the_region =3D addr & ~(LQSPI_CACHE_SIZE - 1); + + lqspi_load_cache(opaque, offset_within_the_region); + *size =3D LQSPI_CACHE_SIZE; + *offset =3D offset_within_the_region; + return q->lqspi_buf; +} + +static uint64_t +lqspi_read(void *opaque, hwaddr addr, unsigned int size) +{ + XilinxQSPIPS *q =3D opaque; + uint32_t ret; + + if (addr >=3D q->lqspi_cached_addr && + addr <=3D q->lqspi_cached_addr + LQSPI_CACHE_SIZE - 4) { + uint8_t *retp =3D &q->lqspi_buf[addr - q->lqspi_cached_addr]; + ret =3D cpu_to_le32(*(uint32_t *)retp); + DB_PRINT_L(1, "addr: %08x, data: %08x\n", (unsigned)addr, + (unsigned)ret); + return ret; + } else { + lqspi_load_cache(opaque, addr); return lqspi_read(opaque, addr, size); } } =20 static const MemoryRegionOps lqspi_ops =3D { .read =3D lqspi_read, + .request_ptr =3D lqspi_request_mmio_ptr, .endianness =3D DEVICE_NATIVE_ENDIAN, .valid =3D { .min_access_size =3D 1, --=20 1.8.3.1