From patchwork Sat Apr 4 12:27:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 11474235 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A0309913 for ; Sat, 4 Apr 2020 12:27:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 762BC206E9 for ; Sat, 4 Apr 2020 12:27:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="t9y1c2U9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 762BC206E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:38444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKhtK-0006Jl-KF for patchwork-qemu-devel@patchwork.kernel.org; Sat, 04 Apr 2020 08:27:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54589) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKhsK-0004yT-Me for qemu-devel@nongnu.org; Sat, 04 Apr 2020 08:26:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jKhsJ-00074Q-J4 for qemu-devel@nongnu.org; Sat, 04 Apr 2020 08:26:12 -0400 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]:46288) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jKhsJ-00073b-AV; Sat, 04 Apr 2020 08:26:11 -0400 Received: by mail-lj1-x244.google.com with SMTP id r7so9667738ljg.13; Sat, 04 Apr 2020 05:26:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/mVbxU5HIlyJ3CPwMR0UvPTLcyJH/YT6yvZCH4lqhNk=; b=t9y1c2U94OSeGNtvpnNyR4+ma+fLYxtmBXI25c/bBBIAX5Kc94BYu/MRlYO0iqlkyT RJT/hkkURtERPM8GO/4jhVv1CJO88MXLuUWiH19/S2mLVJL+axwnBvb4xn1SWufoOcIr vDwiZ/7K//wlrf5ygOWVdBKKic063CaEFhvAxoSuJpE9xuoBFl4sKd50LALtASvLlEyO z2sKGndFBWAnccBgdaN1G9Fg4uWMyTehF8lGZEmEk+MBylQ/rb0EikGniu+qupoEEPMV 0gncU1uyHv1734Pw+yy33erhrw+qvo2NyqDoK+vWjB73C/7KcuUs26YZqlbfsAMJLvaq pmhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/mVbxU5HIlyJ3CPwMR0UvPTLcyJH/YT6yvZCH4lqhNk=; b=qeYBLZppy1nnrnUWAOKW6ZDXnQpiKaioDX3PZd9wSHgwXck9Tb7otp1xZScgX0Qo0a l13jnEVMUDXOwwGkTLDKfa/3RhLUeueFIK/DtjRPiHIxQb6S58wTWigwJ/I/2h2pls5v qAnTJfH53WACV4/t8boIlNtznJyq2FgRIo8fO/mnNGy1P+8DoiIBgzHNadTtDzfmDeNG LNKNSUUeahqxuXAMoSnM3iyqZ8OWkkQNXMX1h2Nzin6GXwtzf6V+KA3g2y1kSflXKpwy mwixSzNPMvidK5Y84xkbg9waYRWiyYBbInw0RYsfqPpFeev1/nTjc3wvhuNEXTfDTkw4 izGQ== X-Gm-Message-State: AGi0PubGNijsv1xfdrVZBhh2tdikBce1PqACbDAl0weeeDc26nAbogCC 78/pS8KIR1fYP79IrQfO4nkhY29HemF0YA== X-Google-Smtp-Source: APiQypIRbcQhscanCFiX8xJXTdHWHtvSNwL8c5NTvwo30Q1SIMNgXIskEpmxpSixg5iBEV/EGZ4DQA== X-Received: by 2002:a2e:b24c:: with SMTP id n12mr7838498ljm.7.1586003169880; Sat, 04 Apr 2020 05:26:09 -0700 (PDT) Received: from localhost (81-231-232-130-no39.tbcn.telia.com. [81.231.232.130]) by smtp.gmail.com with ESMTPSA id z9sm4359591lfd.9.2020.04.04.05.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 05:26:09 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Subject: [PATCH v1 1/2] dma/xlnx-zdma: Fix descriptor loading (MEM) wrt endianness Date: Sat, 4 Apr 2020 14:27:17 +0200 Message-Id: <20200404122718.25111-2-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200404122718.25111-1-edgar.iglesias@gmail.com> References: <20200404122718.25111-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::244 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: figlesia@xilinx.com, peter.maydell@linaro.org, sstabellini@kernel.org, edgar.iglesias@xilinx.com, sai.pavan.boddu@xilinx.com, frasse.iglesias@gmail.com, alistair@alistair23.me, richard.henderson@linaro.org, frederic.konrad@adacore.com, qemu-arm@nongnu.org, philmd@redhat.com, luc.michel@greensocs.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: "Edgar E. Iglesias" Fix descriptor loading from memory wrt host endianness. Reported-by: Peter Maydell Signed-off-by: Edgar E. Iglesias Reviewed-by: Francisco Iglesias Reviewed-by: Philippe Mathieu-Daudé --- hw/dma/xlnx-zdma.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/dma/xlnx-zdma.c b/hw/dma/xlnx-zdma.c index 1c45367f3c..5f4775f663 100644 --- a/hw/dma/xlnx-zdma.c +++ b/hw/dma/xlnx-zdma.c @@ -299,19 +299,22 @@ static void zdma_put_regaddr64(XlnxZDMA *s, unsigned int basereg, uint64_t addr) s->regs[basereg + 1] = addr >> 32; } -static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr, void *buf) +static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr, + XlnxZDMADescr *descr) { /* ZDMA descriptors must be aligned to their own size. */ if (addr % sizeof(XlnxZDMADescr)) { qemu_log_mask(LOG_GUEST_ERROR, "zdma: unaligned descriptor at %" PRIx64, addr); - memset(buf, 0x0, sizeof(XlnxZDMADescr)); + memset(descr, 0x0, sizeof(XlnxZDMADescr)); s->error = true; return false; } - address_space_read(s->dma_as, addr, s->attr, buf, sizeof(XlnxZDMADescr)); + descr->addr = address_space_ldq_le(s->dma_as, addr, s->attr, NULL); + descr->size = address_space_ldl_le(s->dma_as, addr + 8, s->attr, NULL); + descr->attr = address_space_ldl_le(s->dma_as, addr + 12, s->attr, NULL); return true; } @@ -344,7 +347,7 @@ static void zdma_update_descr_addr(XlnxZDMA *s, bool type, } else { addr = zdma_get_regaddr64(s, basereg); addr += sizeof(s->dsc_dst); - address_space_read(s->dma_as, addr, s->attr, (void *) &next, 8); + next = address_space_ldq_le(s->dma_as, addr, s->attr, NULL); } zdma_put_regaddr64(s, basereg, next); From patchwork Sat Apr 4 12:27:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 11474237 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3ADA913 for ; Sat, 4 Apr 2020 12:28:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 89147206E9 for ; Sat, 4 Apr 2020 12:28:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OH2pxAlx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 89147206E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:38472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKhud-0000fw-OQ for patchwork-qemu-devel@patchwork.kernel.org; Sat, 04 Apr 2020 08:28:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54609) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKhsL-0004z6-K4 for qemu-devel@nongnu.org; Sat, 04 Apr 2020 08:26:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jKhsK-00075I-Ly for qemu-devel@nongnu.org; Sat, 04 Apr 2020 08:26:13 -0400 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]:45952) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jKhsK-00074W-Db; Sat, 04 Apr 2020 08:26:12 -0400 Received: by mail-lf1-x141.google.com with SMTP id f8so6658719lfe.12; Sat, 04 Apr 2020 05:26:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UIdgNnpIM7op2ww8CQDxqYn3C3b56loAVAluCHlbtpI=; b=OH2pxAlxJKC37T2qOgXtzCvuH7Zh5kcqZ4uz0l26jz0i59u2lzJ/cJsT+nsghk8QiE oeNiwEdtEbF0+F1GpjC79x1OxiKVAOI1/P4fVrtFG3/M+7BAnyDMMeJ9ZEUMd+rdjwi5 aB9OSociNgxHXeENMTDiM50HzWnqQRDkhu5ir7Nw1rKYkjA8pQDf8rxYztP29BK6sz+a Yea9j/KMTkY9oI9oL1auGYWhL0E7xbBPmLUXasc+sy/h+ccRrx6ir6uN7AE4SArpIH08 tDNUPgGAxQkSSjjZ+p3XMAxiFeK5SpkhsN1S/mcf2Ax3sKYkCCzrLY4KIw7dC4CI7vY3 TXEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UIdgNnpIM7op2ww8CQDxqYn3C3b56loAVAluCHlbtpI=; b=eoYHrgINX9NtWkEVDakmFAx8Lt+Mzp/ZW3ydZS2CfW/x8aZYJYDHT6h7NxPg1WoeNj IB7UJ8IepEPnjMSrbXtakG/ip+jWmf/91bRne9sP73sA33PT6qKWJKw2etEV1m1MxThE cEyNCywowf9Y74eGxIMSlOMeLZuUiT6c2bMWyER6FunddNJnAl6pJ4g6Kjg5Dq+1c1ux uIpTNKADsyJqhgdp8Egmj3Yil1F5yMvc/ohQFP80JU/8zJi9WOgK2OpuXnoBYoopQMzn rRxDvXK0POASUAqHy2gVstDKaVQuAx4Dd4aMBK6Tp3K+cKjNkKROF6KKAfpGiYph46ZG PbTg== X-Gm-Message-State: AGi0PuaZmkB/3wz5SeN+YSxU/It3jb8ySuz07DVRebcEG+LocjQFuFjf 59S1hrMoZtdivxFkh8jFoFhIpWDaAaB8Mg== X-Google-Smtp-Source: APiQypJxgmGM9DAB4gVNwGv9G3DJJFgTp35z7KiJXRSk08KftWfFe84jV6/NvTeD2/a44rc4KAVijQ== X-Received: by 2002:a19:430b:: with SMTP id q11mr1103901lfa.142.1586003171052; Sat, 04 Apr 2020 05:26:11 -0700 (PDT) Received: from localhost (81-231-232-130-no39.tbcn.telia.com. [81.231.232.130]) by smtp.gmail.com with ESMTPSA id i4sm7877776lfl.57.2020.04.04.05.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 05:26:10 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Subject: [PATCH v1 2/2] dma/xlnx-zdma: Fix descriptor loading (REG) wrt endianness Date: Sat, 4 Apr 2020 14:27:18 +0200 Message-Id: <20200404122718.25111-3-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200404122718.25111-1-edgar.iglesias@gmail.com> References: <20200404122718.25111-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::141 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: figlesia@xilinx.com, peter.maydell@linaro.org, sstabellini@kernel.org, edgar.iglesias@xilinx.com, sai.pavan.boddu@xilinx.com, frasse.iglesias@gmail.com, alistair@alistair23.me, richard.henderson@linaro.org, frederic.konrad@adacore.com, qemu-arm@nongnu.org, philmd@redhat.com, luc.michel@greensocs.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: "Edgar E. Iglesias" Fix descriptor loading from registers wrt host endianness. Reported-by: Peter Maydell Signed-off-by: Edgar E. Iglesias Reviewed-by: Francisco Iglesias --- hw/dma/xlnx-zdma.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hw/dma/xlnx-zdma.c b/hw/dma/xlnx-zdma.c index 5f4775f663..4121a1b489 100644 --- a/hw/dma/xlnx-zdma.c +++ b/hw/dma/xlnx-zdma.c @@ -299,6 +299,14 @@ static void zdma_put_regaddr64(XlnxZDMA *s, unsigned int basereg, uint64_t addr) s->regs[basereg + 1] = addr >> 32; } +static void zdma_load_descriptor_reg(XlnxZDMA *s, unsigned int reg, + XlnxZDMADescr *descr) +{ + descr->addr = zdma_get_regaddr64(s, reg); + descr->size = s->regs[reg + 2]; + descr->attr = s->regs[reg + 3]; +} + static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr, XlnxZDMADescr *descr) { @@ -324,8 +332,7 @@ static void zdma_load_src_descriptor(XlnxZDMA *s) unsigned int ptype = ARRAY_FIELD_EX32(s->regs, ZDMA_CH_CTRL0, POINT_TYPE); if (ptype == PT_REG) { - memcpy(&s->dsc_src, &s->regs[R_ZDMA_CH_SRC_DSCR_WORD0], - sizeof(s->dsc_src)); + zdma_load_descriptor_reg(s, R_ZDMA_CH_SRC_DSCR_WORD0, &s->dsc_src); return; } @@ -360,8 +367,7 @@ static void zdma_load_dst_descriptor(XlnxZDMA *s) bool dst_type; if (ptype == PT_REG) { - memcpy(&s->dsc_dst, &s->regs[R_ZDMA_CH_DST_DSCR_WORD0], - sizeof(s->dsc_dst)); + zdma_load_descriptor_reg(s, R_ZDMA_CH_DST_DSCR_WORD0, &s->dsc_dst); return; }