From patchwork Tue Mar 5 19:55:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sven Schnelle X-Patchwork-Id: 1051971 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=stackframe.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=duncanthrax.net header.i=@duncanthrax.net header.b="TXhJp+mr"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44DSMC5G6Rz9s4Y for ; Wed, 6 Mar 2019 06:56:23 +1100 (AEDT) Received: from localhost ([127.0.0.1]:48489 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1GAn-0006NE-LA for incoming@patchwork.ozlabs.org; Tue, 05 Mar 2019 14:56:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1GA3-0006HW-1e for qemu-devel@nongnu.org; Tue, 05 Mar 2019 14:55:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1GA2-0005rB-9l for qemu-devel@nongnu.org; Tue, 05 Mar 2019 14:55:34 -0500 Received: from smtp.duncanthrax.net ([2001:470:70c5:1111::170]:56945) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1GA1-0005kc-Qn for qemu-devel@nongnu.org; Tue, 05 Mar 2019 14:55:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=duncanthrax.net; s=dkim; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=e7FyrcRLh4e7VbGBOCB2JSF1j1+j3xQgs9+D2RzjISU=; b=TXhJp+mrKu/LC9OKhPqUjClfxI x7d30kPW0RYsyBsJfu0Hahm+9/jV9t3Fmfg7qaozoxCGcG+R1Rzs3HbrMGpJxY3MVaHewUnuI42ZW fcTatIXrny422ZWf4+NrpIuWuIX2KAOajgiifP3xGzZwdgGSPAeqXMCyk7n1Ql1FscU0=; Received: from [134.3.47.207] (helo=t470p.stackframe.org) by smtp.eurescom.eu with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1h1G9x-0004To-V4; Tue, 05 Mar 2019 20:55:30 +0100 From: Sven Schnelle To: Paolo Bonzini Date: Tue, 5 Mar 2019 20:55:15 +0100 Message-Id: <20190305195519.24303-2-svens@stackframe.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305195519.24303-1-svens@stackframe.org> References: <20190305195519.24303-1-svens@stackframe.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:470:70c5:1111::170 Subject: [Qemu-devel] [PATCH v2 1/5] lsi: use ldn_le_p()/stn_le_p() 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: Fam Zheng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sven Schnelle , QEMU Developers Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Instead of using the open-coded versions, use the helper already present as this makes the code easier to read and less error-prone. Signed-off-by: Sven Schnelle Reviewed-by: Philippe Mathieu-Daudé --- hw/scsi/lsi53c895a.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c index 5623da8950..5f336606b9 100644 --- a/hw/scsi/lsi53c895a.c +++ b/hw/scsi/lsi53c895a.c @@ -289,8 +289,7 @@ typedef struct { uint8_t sbr; uint32_t adder; - /* Script ram is stored as 32-bit words in host byteorder. */ - uint32_t script_ram[2048]; + uint8_t script_ram[2048 * sizeof(uint32_t)]; } LSIState; #define TYPE_LSI53C810 "lsi53c810" @@ -2079,29 +2078,14 @@ static void lsi_ram_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { LSIState *s = opaque; - uint32_t newval; - uint32_t mask; - int shift; - - newval = s->script_ram[addr >> 2]; - shift = (addr & 3) * 8; - mask = ((uint64_t)1 << (size * 8)) - 1; - newval &= ~(mask << shift); - newval |= val << shift; - s->script_ram[addr >> 2] = newval; + stn_le_p(s->script_ram + addr, size, val); } static uint64_t lsi_ram_read(void *opaque, hwaddr addr, unsigned size) { LSIState *s = opaque; - uint32_t val; - uint32_t mask; - - val = s->script_ram[addr >> 2]; - mask = ((uint64_t)1 << (size * 8)) - 1; - val >>= (addr & 3) * 8; - return val & mask; + return ldn_le_p(s->script_ram + addr, size); } static const MemoryRegionOps lsi_ram_ops = { @@ -2244,7 +2228,7 @@ static const VMStateDescription vmstate_lsi_scsi = { VMSTATE_BUFFER_UNSAFE(scratch, LSIState, 0, 18 * sizeof(uint32_t)), VMSTATE_UINT8(sbr, LSIState), - VMSTATE_BUFFER_UNSAFE(script_ram, LSIState, 0, 2048 * sizeof(uint32_t)), + VMSTATE_BUFFER_UNSAFE(script_ram, LSIState, 0, 8192), VMSTATE_END_OF_LIST() } };