From nobody Sun May 5 18:18:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557095022; cv=none; d=zoho.com; s=zohoarc; b=jDSUKFkvhHZsxN7o8XFQPnIVNij+x7nRugT6LW+TSKZhxI2qLryhV2ZV+k8bwOHepckvnVPCoLFHq9+PnxSfiLcwezcsJcBGFUM6d6m5OY/rnw2YiI1ePTx8gbm3D4D/uB3vQwnfX58fmteK4oTbIqja1f3Qriu93sY+RvTQOl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557095022; 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:ARC-Authentication-Results; bh=ue5qBC42ila9OajLm1xy3T7dwtnl3bDCtILDi7x+CWo=; b=PlVMRD0Dk2MFxBRXuV7KXrUqHyM7AkOPhTnIsEG1FEVClYQ2UVHMuj9sF2emPMS0e/LMcCdZfqoyfRbSYlJzGfH/f7ukMDT40AmMgYoUmQ3VNbI/PW/0UefOTo7fPLU9VbVeK3cxlF/Qof3Wc25XWoapr2YGfXbSJaWxQr5wais= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557095022753259.34294004464505; Sun, 5 May 2019 15:23:42 -0700 (PDT) Received: from localhost ([127.0.0.1]:47007 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPXl-0001KT-Hi for importer@patchew.org; Sun, 05 May 2019 18:23:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPQw-0004JL-Tr for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNPQr-0008HG-K7 for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59680) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNPQQ-0007L8-Qa; Sun, 05 May 2019 18:16:03 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E95D37FD45; Sun, 5 May 2019 22:16:00 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 91BB17C386; Sun, 5 May 2019 22:15:55 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stephen Checkoway Date: Mon, 6 May 2019 00:15:32 +0200 Message-Id: <20190505221544.31568-2-philmd@redhat.com> In-Reply-To: <20190505221544.31568-1-philmd@redhat.com> References: <20190505221544.31568-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sun, 05 May 2019 22:16:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 01/13] tests/pflash-cfi02: Add test for supported CFI commands 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Stephen Checkoway Test the AMD command set for parallel flash chips. This test uses an ARM musicpal board with a pflash drive to test the following list of currently-supported commands. - Autoselect - CFI - Sector erase - Chip erase - Program - Unlock bypass - Reset Signed-off-by: Stephen Checkoway Message-Id: <20190426162624.55977-2-stephen.checkoway@oberlin.edu> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 [PMD: reworded the patch subject] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- tests/Makefile.include | 2 + tests/pflash-cfi02-test.c | 225 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 tests/pflash-cfi02-test.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 7c8b9c84b24..b84a308d9a1 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -263,6 +263,7 @@ check-qtest-arm-y +=3D tests/m25p80-test$(EXESUF) check-qtest-arm-y +=3D tests/test-arm-mptimer$(EXESUF) check-qtest-arm-y +=3D tests/boot-serial-test$(EXESUF) check-qtest-arm-y +=3D tests/hexloader-test$(EXESUF) +check-qtest-arm-$(CONFIG_PFLASH_CFI02) +=3D tests/pflash-cfi02-test$(EXESU= F) =20 check-qtest-aarch64-y =3D tests/numa-test$(EXESUF) check-qtest-aarch64-y +=3D tests/boot-serial-test$(EXESUF) @@ -773,6 +774,7 @@ tests/device-introspect-test$(EXESUF): tests/device-int= rospect-test.o tests/rtc-test$(EXESUF): tests/rtc-test.o tests/m48t59-test$(EXESUF): tests/m48t59-test.o tests/hexloader-test$(EXESUF): tests/hexloader-test.o +tests/pflash-cfi02$(EXESUF): tests/pflash-cfi02-test.o tests/endianness-test$(EXESUF): tests/endianness-test.o tests/prom-env-test$(EXESUF): tests/prom-env-test.o $(libqos-obj-y) tests/rtas-test$(EXESUF): tests/rtas-test.o $(libqos-spapr-obj-y) diff --git a/tests/pflash-cfi02-test.c b/tests/pflash-cfi02-test.c new file mode 100644 index 00000000000..40af1bb523e --- /dev/null +++ b/tests/pflash-cfi02-test.c @@ -0,0 +1,225 @@ +/* + * QTest testcase for parallel flash with AMD command set + * + * Copyright (c) 2019 Stephen Checkoway + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "libqtest.h" + +/* + * To test the pflash_cfi02 device, we run QEMU with the musicpal machine = with + * a pflash drive. This enables us to test some flash configurations, but = not + * all. In particular, we're limited to a 16-bit wide flash device. + */ + +#define MP_FLASH_SIZE_MAX (32 * 1024 * 1024) +#define BASE_ADDR (0x100000000ULL - MP_FLASH_SIZE_MAX) + +#define FLASH_WIDTH 2 +#define CFI_ADDR (FLASH_WIDTH * 0x55) +#define UNLOCK0_ADDR (FLASH_WIDTH * 0x5555) +#define UNLOCK1_ADDR (FLASH_WIDTH * 0x2AAA) + +#define CFI_CMD 0x98 +#define UNLOCK0_CMD 0xAA +#define UNLOCK1_CMD 0x55 +#define AUTOSELECT_CMD 0x90 +#define RESET_CMD 0xF0 +#define PROGRAM_CMD 0xA0 +#define SECTOR_ERASE_CMD 0x30 +#define CHIP_ERASE_CMD 0x10 +#define UNLOCK_BYPASS_CMD 0x20 +#define UNLOCK_BYPASS_RESET_CMD 0x00 + +static char image_path[] =3D "/tmp/qtest.XXXXXX"; + +static inline void flash_write(uint64_t byte_addr, uint16_t data) +{ + qtest_writew(global_qtest, BASE_ADDR + byte_addr, data); +} + +static inline uint16_t flash_read(uint64_t byte_addr) +{ + return qtest_readw(global_qtest, BASE_ADDR + byte_addr); +} + +static void unlock(void) +{ + flash_write(UNLOCK0_ADDR, UNLOCK0_CMD); + flash_write(UNLOCK1_ADDR, UNLOCK1_CMD); +} + +static void reset(void) +{ + flash_write(0, RESET_CMD); +} + +static void sector_erase(uint64_t byte_addr) +{ + unlock(); + flash_write(UNLOCK0_ADDR, 0x80); + unlock(); + flash_write(byte_addr, SECTOR_ERASE_CMD); +} + +static void wait_for_completion(uint64_t byte_addr) +{ + /* If DQ6 is toggling, step the clock and ensure the toggle stops. */ + if ((flash_read(byte_addr) & 0x40) ^ (flash_read(byte_addr) & 0x40)) { + /* Wait for erase or program to finish. */ + clock_step_next(); + /* Ensure that DQ6 has stopped toggling. */ + g_assert_cmpint(flash_read(byte_addr), =3D=3D, flash_read(byte_add= r)); + } +} + +static void bypass_program(uint64_t byte_addr, uint16_t data) +{ + flash_write(UNLOCK0_ADDR, PROGRAM_CMD); + flash_write(byte_addr, data); + /* + * Data isn't valid until DQ6 stops toggling. We don't model this as + * writes are immediate, but if this changes in the future, we can wait + * until the program is complete. + */ + wait_for_completion(byte_addr); +} + +static void program(uint64_t byte_addr, uint16_t data) +{ + unlock(); + bypass_program(byte_addr, data); +} + +static void chip_erase(void) +{ + unlock(); + flash_write(UNLOCK0_ADDR, 0x80); + unlock(); + flash_write(UNLOCK0_ADDR, SECTOR_ERASE_CMD); +} + +static void test_flash(void) +{ + global_qtest =3D qtest_initf("-M musicpal,accel=3Dqtest " + "-drive if=3Dpflash,file=3D%s,format=3Draw,= copy-on-read", + image_path); + /* Check the IDs. */ + unlock(); + flash_write(UNLOCK0_ADDR, AUTOSELECT_CMD); + g_assert_cmpint(flash_read(FLASH_WIDTH * 0x0000), =3D=3D, 0x00BF); + g_assert_cmpint(flash_read(FLASH_WIDTH * 0x0001), =3D=3D, 0x236D); + reset(); + + /* Check the erase blocks. */ + flash_write(CFI_ADDR, CFI_CMD); + g_assert_cmpint(flash_read(FLASH_WIDTH * 0x10), =3D=3D, 'Q'); + g_assert_cmpint(flash_read(FLASH_WIDTH * 0x11), =3D=3D, 'R'); + g_assert_cmpint(flash_read(FLASH_WIDTH * 0x12), =3D=3D, 'Y'); + /* Num erase regions. */ + g_assert_cmpint(flash_read(FLASH_WIDTH * 0x2C), >=3D, 1); + uint32_t nb_sectors =3D flash_read(FLASH_WIDTH * 0x2D) + + (flash_read(FLASH_WIDTH * 0x2E) << 8) + 1; + uint32_t sector_len =3D (flash_read(FLASH_WIDTH * 0x2F) << 8) + + (flash_read(FLASH_WIDTH * 0x30) << 16); + reset(); + + /* Erase and program sector. */ + for (uint32_t i =3D 0; i < nb_sectors; ++i) { + uint64_t byte_addr =3D i * sector_len; + sector_erase(byte_addr); + /* Read toggle. */ + uint16_t status0 =3D flash_read(byte_addr); + /* DQ7 is 0 during an erase. */ + g_assert_cmpint(status0 & 0x80, =3D=3D, 0); + uint16_t status1 =3D flash_read(byte_addr); + /* DQ6 toggles during an erase. */ + g_assert_cmpint(status0 & 0x40, !=3D, status1 & 0x40); + /* Wait for erase to complete. */ + clock_step_next(); + /* Ensure DQ6 has stopped toggling. */ + g_assert_cmpint(flash_read(byte_addr), =3D=3D, flash_read(byte_add= r)); + /* Now the data should be valid. */ + g_assert_cmpint(flash_read(byte_addr), =3D=3D, 0xFFFF); + + /* Program a bit pattern. */ + program(byte_addr, 0x5555); + g_assert_cmpint(flash_read(byte_addr), =3D=3D, 0x5555); + program(byte_addr, 0xAA55); + g_assert_cmpint(flash_read(byte_addr), =3D=3D, 0x0055); + } + + /* Erase the chip. */ + chip_erase(); + /* Read toggle. */ + uint16_t status0 =3D flash_read(0); + /* DQ7 is 0 during an erase. */ + g_assert_cmpint(status0 & 0x80, =3D=3D, 0); + uint16_t status1 =3D flash_read(0); + /* DQ6 toggles during an erase. */ + g_assert_cmpint(status0 & 0x40, !=3D, status1 & 0x40); + /* Wait for erase to complete. */ + clock_step_next(); + /* Ensure DQ6 has stopped toggling. */ + g_assert_cmpint(flash_read(0), =3D=3D, flash_read(0)); + /* Now the data should be valid. */ + g_assert_cmpint(flash_read(0), =3D=3D, 0xFFFF); + + /* Unlock bypass */ + unlock(); + flash_write(UNLOCK0_ADDR, UNLOCK_BYPASS_CMD); + bypass_program(0, 0x0123); + bypass_program(2, 0x4567); + bypass_program(4, 0x89AB); + /* + * Test that bypass programming, unlike normal programming can use any + * address for the PROGRAM_CMD. + */ + flash_write(6, PROGRAM_CMD); + flash_write(6, 0xCDEF); + wait_for_completion(6); + flash_write(0, UNLOCK_BYPASS_RESET_CMD); + bypass_program(8, 0x55AA); /* Should fail. */ + g_assert_cmpint(flash_read(0), =3D=3D, 0x0123); + g_assert_cmpint(flash_read(2), =3D=3D, 0x4567); + g_assert_cmpint(flash_read(4), =3D=3D, 0x89AB); + g_assert_cmpint(flash_read(6), =3D=3D, 0xCDEF); + g_assert_cmpint(flash_read(8), =3D=3D, 0xFFFF); + + qtest_quit(global_qtest); +} + +static void cleanup(void *opaque) +{ + unlink(image_path); +} + +int main(int argc, char **argv) +{ + int fd =3D mkstemp(image_path); + if (fd =3D=3D -1) { + g_printerr("Failed to create temporary file %s: %s\n", image_path, + strerror(errno)); + exit(EXIT_FAILURE); + } + if (ftruncate(fd, 8 * 1024 * 1024) < 0) { + int error_code =3D errno; + close(fd); + unlink(image_path); + g_printerr("Failed to truncate file %s to 8 MB: %s\n", image_path, + strerror(error_code)); + exit(EXIT_FAILURE); + } + close(fd); + + qtest_add_abrt_handler(cleanup, NULL); + g_test_init(&argc, &argv, NULL); + qtest_add_func("pflash-cfi02", test_flash); + int result =3D g_test_run(); + cleanup(NULL); + return result; +} --=20 2.20.1 From nobody Sun May 5 18:18:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557094894; cv=none; d=zoho.com; s=zohoarc; b=Ru6xEjGFvCX3rfBfc9QFh62rKFQm/+I7zxj2R47Di7w8yPZX/wuxtUDQOwSZylG4td/OVh49XtdwL/or2WfZcy0bdLOVHYuVjgbNGv7CFCLIrPmeCvkRr6ZClG2x3hJrrqF5j1emQU9CWqHVEqXJz79b1iP43ui5HpgFZ/AiscY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557094894; 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:ARC-Authentication-Results; bh=C2DF5GfGfBKY2uR1N6FvTwEWL71UsbXiIaLyXDddoos=; b=ND16DjTx29goeMf+S79f1GdMFWZu8RsCcmiNuZ5cmNs4FfXMC/W/fPQR6BBflNzqzZqQwk9NAxnQvu2SaAh3ai/3ZTvgkqAyppDFMTKAaieAFipFnFOZOB48r4JIA/anq/o/FLZxyYcZ/kCKb7H3TIgGiRoFFFCBX8dF+DJL3yA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557094894222116.44911592152027; Sun, 5 May 2019 15:21:34 -0700 (PDT) Received: from localhost ([127.0.0.1]:46952 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPVi-00081J-Ih for importer@patchew.org; Sun, 05 May 2019 18:21:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPQv-0004HU-8I for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNPQr-0008Ge-Ci for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44986) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNPQT-0007YP-Hn; Sun, 05 May 2019 18:16:05 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2BF9C05E760; Sun, 5 May 2019 22:16:04 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 620FE7C386; Sun, 5 May 2019 22:16:01 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stephen Checkoway Date: Mon, 6 May 2019 00:15:33 +0200 Message-Id: <20190505221544.31568-3-philmd@redhat.com> In-Reply-To: <20190505221544.31568-1-philmd@redhat.com> References: <20190505221544.31568-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sun, 05 May 2019 22:16:04 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 02/13] tests/pflash-cfi02: Use the GLib API 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- tests/pflash-cfi02-test.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/tests/pflash-cfi02-test.c b/tests/pflash-cfi02-test.c index 40af1bb523e..ff775618c02 100644 --- a/tests/pflash-cfi02-test.c +++ b/tests/pflash-cfi02-test.c @@ -35,8 +35,6 @@ #define UNLOCK_BYPASS_CMD 0x20 #define UNLOCK_BYPASS_RESET_CMD 0x00 =20 -static char image_path[] =3D "/tmp/qtest.XXXXXX"; - static inline void flash_write(uint64_t byte_addr, uint16_t data) { qtest_writew(global_qtest, BASE_ADDR + byte_addr, data); @@ -103,8 +101,9 @@ static void chip_erase(void) flash_write(UNLOCK0_ADDR, SECTOR_ERASE_CMD); } =20 -static void test_flash(void) +static void test_flash(const void *opaque) { + const char *image_path =3D opaque; global_qtest =3D qtest_initf("-M musicpal,accel=3Dqtest " "-drive if=3Dpflash,file=3D%s,format=3Draw,= copy-on-read", image_path); @@ -195,31 +194,30 @@ static void test_flash(void) =20 static void cleanup(void *opaque) { + char *image_path =3D opaque; unlink(image_path); + g_free(image_path); } =20 int main(int argc, char **argv) { - int fd =3D mkstemp(image_path); - if (fd =3D=3D -1) { - g_printerr("Failed to create temporary file %s: %s\n", image_path, - strerror(errno)); - exit(EXIT_FAILURE); - } + GError *error =3D NULL; + char *image_path; + int fd =3D g_file_open_tmp("pflash-cfi02-XXXXXX.raw", &image_path, &er= ror); + g_assert_no_error(error); if (ftruncate(fd, 8 * 1024 * 1024) < 0) { - int error_code =3D errno; + g_printerr("Failed to truncate file %s to 8 MB: %s\n", image_path, + strerror(errno)); close(fd); unlink(image_path); - g_printerr("Failed to truncate file %s to 8 MB: %s\n", image_path, - strerror(error_code)); exit(EXIT_FAILURE); } close(fd); =20 - qtest_add_abrt_handler(cleanup, NULL); + qtest_add_abrt_handler(cleanup, image_path); g_test_init(&argc, &argv, NULL); - qtest_add_func("pflash-cfi02", test_flash); + qtest_add_data_func("pflash-cfi02", image_path, test_flash); int result =3D g_test_run(); - cleanup(NULL); + cleanup(image_path); return result; } --=20 2.20.1 From nobody Sun May 5 18:18:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557094861; cv=none; d=zoho.com; s=zohoarc; b=KEKyChh5Husmt7pyAexesmv479Z4p1xOUtlpz8BJ+sHezCvNujl2dgYFI7EILzkiX9wuY2+sLDSxda+l2wbuwNGoze0d+RCyHvklMf4XPCNiZM07JaZjTT/ErwXD99K3Ytl/zU6O2jBZSLlpj+xYMn8lzY/Mym+1EpSJP/noHY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557094861; 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:ARC-Authentication-Results; bh=KzHDfo0qd5ztEDT8YAsw7XKfwRFMUAt4Y0+yaPNlsqo=; b=LUJl+yLAcxL0epxwrIsanEQJ3DlDG8PoJr8gjUFK5CFepFwualSJuqgKhtr0h+wSvyJ0qNR5+AuUdPS1qn383c46W9sxdhOnyP9/xg4W8YgoMbM9lsr6ZfXgTWkD85+ji+Dwt2RKYzyEoJCbj+jI9KpWhhqNc9LHG59lVJ3ivQA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557094861574681.4567942526132; Sun, 5 May 2019 15:21:01 -0700 (PDT) Received: from localhost ([127.0.0.1]:46950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPV3-0007Q7-0b for importer@patchew.org; Sun, 05 May 2019 18:20:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35972) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPQx-0004JX-4H for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNPQt-0008JP-8Y for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55218) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNPQf-0007iI-Ld; Sun, 05 May 2019 18:16:21 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4FADE30842B5; Sun, 5 May 2019 22:16:09 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 36A6B7C386; Sun, 5 May 2019 22:16:04 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stephen Checkoway Date: Mon, 6 May 2019 00:15:34 +0200 Message-Id: <20190505221544.31568-4-philmd@redhat.com> In-Reply-To: <20190505221544.31568-1-philmd@redhat.com> References: <20190505221544.31568-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sun, 05 May 2019 22:16:09 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 03/13] tests/pflash-cfi02: Use IEC binary prefixes for size constants 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Using IEC binary prefixes in order to make the code more readable. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- tests/pflash-cfi02-test.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/pflash-cfi02-test.c b/tests/pflash-cfi02-test.c index ff775618c02..3c37465499a 100644 --- a/tests/pflash-cfi02-test.c +++ b/tests/pflash-cfi02-test.c @@ -8,6 +8,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/units.h" #include "libqtest.h" =20 /* @@ -16,7 +17,7 @@ * all. In particular, we're limited to a 16-bit wide flash device. */ =20 -#define MP_FLASH_SIZE_MAX (32 * 1024 * 1024) +#define MP_FLASH_SIZE_MAX (32 * MiB) #define BASE_ADDR (0x100000000ULL - MP_FLASH_SIZE_MAX) =20 #define FLASH_WIDTH 2 @@ -205,7 +206,7 @@ int main(int argc, char **argv) char *image_path; int fd =3D g_file_open_tmp("pflash-cfi02-XXXXXX.raw", &image_path, &er= ror); g_assert_no_error(error); - if (ftruncate(fd, 8 * 1024 * 1024) < 0) { + if (ftruncate(fd, 8 * MiB) < 0) { g_printerr("Failed to truncate file %s to 8 MB: %s\n", image_path, strerror(errno)); close(fd); --=20 2.20.1 From nobody Sun May 5 18:18:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557095202; cv=none; d=zoho.com; s=zohoarc; b=WpWTVkr3RxzK7Ay4tq+9wBanOL9btlFqOC3hnkoR3slo2KdtSyqyWLMsrX/zcaLf4RSE2uDPOCTkGmfooCYs/a8ZbibZY/5vKMv/fmT4PZ3vzM8nqIEWm6Z50+FZUROPo1ZdN/PtTggaPXD0r9x4BlKMclf1ZPV90PN43V9W2NI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557095202; 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:ARC-Authentication-Results; bh=iqumbHtmcMi8VVOO2uivLX3gBT9mZ728o6GEhGEgyWQ=; b=HyrdHT14hlE4nAtjrBtqVQ+C3Rx6Jb8j8E7DAW0D8TbdxPWPCP4OK4ixnNYCIQ9KyPJocr1C2b+5fHj8ELFpV5TXghafZEtWYcKTKUfcPNftsCtcvnbl6Zf+rh4Cvebk41IKsnXgcAyoaZusfS+Egq1s1IL7nMVE10ysexyx2rk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 155709520295678.78497483537205; Sun, 5 May 2019 15:26:42 -0700 (PDT) Received: from localhost ([127.0.0.1]:47073 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPaY-00046q-F7 for importer@patchew.org; Sun, 05 May 2019 18:26:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36032) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPR1-0004Nd-4X for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNPQx-0008Or-38 for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41088) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNPQm-0007tZ-VW; Sun, 05 May 2019 18:16:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0FB9F356DB; Sun, 5 May 2019 22:16:16 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C536F5D739; Sun, 5 May 2019 22:16:09 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stephen Checkoway Date: Mon, 6 May 2019 00:15:35 +0200 Message-Id: <20190505221544.31568-5-philmd@redhat.com> In-Reply-To: <20190505221544.31568-1-philmd@redhat.com> References: <20190505221544.31568-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sun, 05 May 2019 22:16:16 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 04/13] hw/block/pflash_cfi02: Fix debug format string 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Always compile the debug code to prevent format string to bitrot. Signed-off-by: Stephen Checkoway Message-Id: <20190426162624.55977-3-stephen.checkoway@oberlin.edu> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 [PMD: Extracted from bigger patch, use PRIx32] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/pflash_cfi02.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index f2c6201f813..f88e09cebaa 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -46,15 +46,13 @@ #include "hw/sysbus.h" #include "trace.h" =20 -//#define PFLASH_DEBUG -#ifdef PFLASH_DEBUG +#define PFLASH_DEBUG false #define DPRINTF(fmt, ...) \ do { \ - fprintf(stderr, "PFLASH: " fmt , ## __VA_ARGS__); \ + if (PFLASH_DEBUG) { \ + fprintf(stderr, "PFLASH: " fmt, ## __VA_ARGS__); \ + } \ } while (0) -#else -#define DPRINTF(fmt, ...) do { } while (0) -#endif =20 #define PFLASH_LAZY_ROMD_THRESHOLD 42 =20 @@ -220,14 +218,14 @@ static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr = offset, default: goto flash_read; } - DPRINTF("%s: ID " TARGET_FMT_plx " %x\n", __func__, boff, ret); + DPRINTF("%s: ID " TARGET_FMT_plx " %" PRIx32 "\n", __func__, boff,= ret); break; case 0xA0: case 0x10: case 0x30: /* Status register read */ ret =3D pfl->status; - DPRINTF("%s: status %x\n", __func__, ret); + DPRINTF("%s: status %" PRIx32 "\n", __func__, ret); /* Toggle bit 6 */ pfl->status ^=3D 0x40; break; @@ -277,7 +275,7 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offse= t, trace_pflash_write(offset, value, width, pfl->wcycle); offset &=3D pfl->chip_len - 1; =20 - DPRINTF("%s: offset " TARGET_FMT_plx " %08x %d\n", __func__, + DPRINTF("%s: offset " TARGET_FMT_plx " %08" PRIx32 " %d\n", __func__, offset, value, width); boff =3D offset & (pfl->sector_len - 1); if (pfl->width =3D=3D 2) --=20 2.20.1 From nobody Sun May 5 18:18:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557095325; cv=none; d=zoho.com; s=zohoarc; b=EIcwvonSHefDoca0UkrIPiIvQMESkQbitPf8EF9SFhNRPg9HNyjiOGdRqKO/kUnIuxhKpqyd64BCVnl4yfgDvrYtKAF+zIlTYtrFSdEPIcQabpsiZ0GvmNtSJAg3P/vq52z19FgqkAt2RG57abPU3cYPLUsDfQdaub/JpwFOmXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557095325; 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:ARC-Authentication-Results; bh=+lglsxPXN/aBNQ2LyJciTi1x4Phpx3l/tzqa3qhEMpQ=; b=VWFZ9VYu+o163wP58KUq0Nhs1GJSa6APK46UySxA1kvpcxdoWq39cXmP9k8KgYsJdEvaar/Gsx6ZrmojUlIObqMhDYU8WK/4t6qsLgv94XDCB0NcOkLhul3LExXz9YIlCO72CT+7iyBrBfCdWB8p1vklFjXt4uED9dBGS29vDJE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557095325568600.1350645298317; Sun, 5 May 2019 15:28:45 -0700 (PDT) Received: from localhost ([127.0.0.1]:47098 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPcg-0007Vn-IQ for importer@patchew.org; Sun, 05 May 2019 18:28:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPR4-0004Rr-Nk for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNPR0-0008UU-VC for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40718) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNPQp-000813-Fy; Sun, 05 May 2019 18:16:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 05CDBC057F59; Sun, 5 May 2019 22:16:21 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 84BB55D739; Sun, 5 May 2019 22:16:16 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stephen Checkoway Date: Mon, 6 May 2019 00:15:36 +0200 Message-Id: <20190505221544.31568-6-philmd@redhat.com> In-Reply-To: <20190505221544.31568-1-philmd@redhat.com> References: <20190505221544.31568-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 05 May 2019 22:16:21 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 05/13] hw/block/pflash_cfi02: Add an enum to define the write cycles 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" No change in functionality is intended with this commit. Signed-off-by: Stephen Checkoway Message-Id: <20190426162624.55977-3-stephen.checkoway@oberlin.edu> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 [PMD: Extracted from bigger patch] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/pflash_cfi02.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index f88e09cebaa..b27796d74d2 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -56,6 +56,11 @@ do { = \ =20 #define PFLASH_LAZY_ROMD_THRESHOLD 42 =20 +/* Special write cycles for CFI queries. */ +enum { + WCYCLE_CFI =3D 7, +}; + struct PFlashCFI02 { /*< private >*/ SysBusDevice parent_obj; @@ -293,7 +298,7 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offse= t, if (boff =3D=3D 0x55 && cmd =3D=3D 0x98) { enter_CFI_mode: /* Enter CFI query mode */ - pfl->wcycle =3D 7; + pfl->wcycle =3D WCYCLE_CFI; pfl->cmd =3D 0x98; return; } @@ -465,7 +470,7 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offse= t, goto reset_flash; } break; - case 7: /* Special value for CFI queries */ + case WCYCLE_CFI: /* Special value for CFI queries */ DPRINTF("%s: invalid write in CFI query mode\n", __func__); goto reset_flash; default: --=20 2.20.1 From nobody Sun May 5 18:18:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557094899; cv=none; d=zoho.com; s=zohoarc; b=hYmYzYgblzs00+A4DWhXUxSfYrLBoQ5qIotv9gWa3tpRsfB8RWhsRO9SkDbpVE2+8mEpOCfIkL6DM1S4x3obORpSKWoeNPm3KqegtGPMmNwlTSvQaKD7pEl9NSwy8pXFVvJnrwVCjnhJrc9pOz5RlslcUZyMfrBYKjXhyHV0Bro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557094899; 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:ARC-Authentication-Results; bh=4NCzsY0OElt+JddhpUt8/VmY+939Mxs+p7913Sfq7t4=; b=N53dx5CMBWucuJ947BKobyIKqXJ3iIIr5YtuB5VRmj9R9nik2JCK/kJn+i89Q14oA5eqBFE3WeOtucvFUHtnWMSznMuJcCBmtzILhGpxOxTE9eLaeLM+TlydlNvTI+3Y5R4WtZhsomQiCMme6QWROKxTVko8NCTjFufUSXPUuRc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557094899845212.3200927984525; Sun, 5 May 2019 15:21:39 -0700 (PDT) Received: from localhost ([127.0.0.1]:46954 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPVl-00083v-NL for importer@patchew.org; Sun, 05 May 2019 18:21:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPR4-0004Rq-Ni for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNPR0-0008Ua-VG for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43822) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNPQp-0008AQ-HO; Sun, 05 May 2019 18:16:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BBDB6307BCB3; Sun, 5 May 2019 22:16:25 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5D7C7C386; Sun, 5 May 2019 22:16:21 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stephen Checkoway Date: Mon, 6 May 2019 00:15:37 +0200 Message-Id: <20190505221544.31568-7-philmd@redhat.com> In-Reply-To: <20190505221544.31568-1-philmd@redhat.com> References: <20190505221544.31568-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sun, 05 May 2019 22:16:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/13] hw/block/pflash_cfi02: Add helpers to manipulate the status bits 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Pull out all of the code to modify the status into simple helper functions. Status handling becomes more complex once multiple chips are interleaved to produce a single device. No change in functionality is intended with this commit. Signed-off-by: Stephen Checkoway Message-Id: <20190426162624.55977-3-stephen.checkoway@oberlin.edu> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 [PMD: Extracted from bigger patch] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/pflash_cfi02.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index b27796d74d2..9673eee969f 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -100,6 +100,31 @@ struct PFlashCFI02 { void *storage; }; =20 +/* + * Toggle status bit DQ7. + */ +static inline void toggle_dq7(PFlashCFI02 *pfl) +{ + pfl->status ^=3D 0x80; +} + +/* + * Set status bit DQ7 to bit 7 of value. + */ +static inline void set_dq7(PFlashCFI02 *pfl, uint8_t value) +{ + pfl->status &=3D 0x7F; + pfl->status |=3D value & 0x80; +} + +/* + * Toggle status bit DQ6. + */ +static inline void toggle_dq6(PFlashCFI02 *pfl) +{ + pfl->status ^=3D 0x40; +} + /* * Set up replicated mappings of the same region. */ @@ -129,7 +154,7 @@ static void pflash_timer (void *opaque) =20 trace_pflash_timer_expired(pfl->cmd); /* Reset flash */ - pfl->status ^=3D 0x80; + toggle_dq7(pfl); if (pfl->bypass) { pfl->wcycle =3D 2; } else { @@ -232,7 +257,7 @@ static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr of= fset, ret =3D pfl->status; DPRINTF("%s: status %" PRIx32 "\n", __func__, ret); /* Toggle bit 6 */ - pfl->status ^=3D 0x40; + toggle_dq6(pfl); break; case 0x98: /* CFI query mode */ @@ -381,7 +406,11 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offs= et, break; } } - pfl->status =3D 0x00 | ~(value & 0x80); + /* + * While programming, status bit DQ7 should hold the opposite + * value from how it was programmed. + */ + set_dq7(pfl, ~value); /* Let's pretend write is immediate */ if (pfl->bypass) goto do_bypass; @@ -429,7 +458,7 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offse= t, memset(pfl->storage, 0xFF, pfl->chip_len); pflash_update(pfl, 0, pfl->chip_len); } - pfl->status =3D 0x00; + set_dq7(pfl, 0x00); /* Let's wait 5 seconds before chip erase is done */ timer_mod(&pfl->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + (NANOSECONDS_PER_SECOND * 5)); @@ -444,7 +473,7 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offse= t, memset(p + offset, 0xFF, pfl->sector_len); pflash_update(pfl, offset, pfl->sector_len); } - pfl->status =3D 0x00; + set_dq7(pfl, 0x00); /* Let's wait 1/2 second before sector erase is done */ timer_mod(&pfl->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + (NANOSECONDS_PER_SECOND / 2)); --=20 2.20.1 From nobody Sun May 5 18:18:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557095401; cv=none; d=zoho.com; s=zohoarc; b=Srg0EruvODL+wMSwkJFvWdtB5MTg6GfMw+un+6TzZqBk2AZ742Nxs/d2tmaDvo/N/Z0VG7mYCFsnaN7Bm++Xo61hbRhMb8mBxVnRhHYy4AKHaN7zumoZtWVEhrI8at4hiMyDiZa73pRg2MNhOJrem3sh5x8OAFZ1tnKLZHnuOhE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557095401; 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:ARC-Authentication-Results; bh=rvkwr3NwtXhSAm39QU6gT/vEi79PyJxtnFMcbf3UOAM=; b=GnLohhtB0WPjTMtlTJca5PE4B+f5b+YAS8ET6MBvMqJ9S1zUeQ0gz6YU3XGmgRL+JPtQCLnfL65dIjKMFsjxPaUKjeFOiwWib2SvFPVXE5HSn0zMHYfSUguSNLIf8pIraPdfDuuwPilLo+SnPIhoDICqm5NjA1uI/HqO9W11/qM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557095401773120.26738978246635; Sun, 5 May 2019 15:30:01 -0700 (PDT) Received: from localhost ([127.0.0.1]:47111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPds-0008K5-QI for importer@patchew.org; Sun, 05 May 2019 18:29:56 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36169) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPR8-0004UP-PA for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNPR7-0000E5-Ul for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38952) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNPQx-0008If-1B; Sun, 05 May 2019 18:16:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 70A6D30820E4; Sun, 5 May 2019 22:16:30 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2EAAE5D739; Sun, 5 May 2019 22:16:25 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stephen Checkoway Date: Mon, 6 May 2019 00:15:38 +0200 Message-Id: <20190505221544.31568-8-philmd@redhat.com> In-Reply-To: <20190505221544.31568-1-philmd@redhat.com> References: <20190505221544.31568-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sun, 05 May 2019 22:16:30 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 07/13] hw/block/pflash_cfi02: Simplify a statement using fall through 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Stephen Checkoway Message-Id: <20190426162624.55977-3-stephen.checkoway@oberlin.edu> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 [PMD: Extracted from bigger patch] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/pflash_cfi02.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 9673eee969f..1e006e7bf3a 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -241,10 +241,10 @@ static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr = offset, case 0x0E: case 0x0F: ret =3D boff & 0x01 ? pfl->ident3 : pfl->ident2; - if (ret =3D=3D (uint8_t)-1) { - goto flash_read; + if (ret !=3D (uint8_t)-1) { + break; } - break; + /* Fall through to data read. */ default: goto flash_read; } --=20 2.20.1 From nobody Sun May 5 18:18:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557095099; cv=none; d=zoho.com; s=zohoarc; b=GS4c/knY9gQdK4rvDdzJGk4GQ+a03O9NDMusq0IHAtOW8z/HWIZLnOyUUfND6uHFFCs0j7br/LX7PeLJFrK2cz90AlqcNyTqnFhIYm1WFxNoM8fp52A6GiIV+NZ3mjlorn0yle/xLnFq/sZNweGDjvX686/P8yuMCyXTEjyKXoc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557095099; 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:ARC-Authentication-Results; bh=h5nUIC9sjb1Yr4lxiKiwpggPRxYGKKTJkgdtITbw1+U=; b=F0teECjDnqn9p+KDQJSf/LhAu6awDRtOLbTBLEprmtuXdN/uK/xHG+VykhNnUVHopg8p2pJpCVO7IrtSg2yc3HsM9kU/WMhCxCgfADZw1Gx6fwGwWaw8zDD/Ju6YlYvoKepf2GymHNnxOgiYJrcuECSGZ4uiNtlecgOUNJq1Ymc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557095099330974.4721362780296; Sun, 5 May 2019 15:24:59 -0700 (PDT) Received: from localhost ([127.0.0.1]:47014 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPZ2-0002Yl-7Y for importer@patchew.org; Sun, 05 May 2019 18:24:56 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPR8-0004UO-P6 for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNPR7-0000Dd-Pz for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53402) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNPR2-0008SH-Qq; Sun, 05 May 2019 18:16:42 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 320733082B71; Sun, 5 May 2019 22:16:37 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DCC4E7C386; Sun, 5 May 2019 22:16:30 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stephen Checkoway Date: Mon, 6 May 2019 00:15:39 +0200 Message-Id: <20190505221544.31568-9-philmd@redhat.com> In-Reply-To: <20190505221544.31568-1-philmd@redhat.com> References: <20190505221544.31568-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sun, 05 May 2019 22:16:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/13] hw/block/pflash_cfi02: Use the ldst API in pflash_write() 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The load/store API eases code review. Signed-off-by: Stephen Checkoway Message-Id: <20190426162624.55977-3-stephen.checkoway@oberlin.edu> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 [PMD: Extracted from bigger patch] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/pflash_cfi02.c | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 1e006e7bf3a..69e0086324e 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -373,38 +373,16 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr off= set, goto check_unlock0; case 0xA0: trace_pflash_data_write(offset, value, width, 0); - p =3D pfl->storage; if (!pfl->ro) { - switch (width) { - case 1: - p[offset] &=3D value; - pflash_update(pfl, offset, 1); - break; - case 2: - if (be) { - p[offset] &=3D value >> 8; - p[offset + 1] &=3D value; - } else { - p[offset] &=3D value; - p[offset + 1] &=3D value >> 8; - } - pflash_update(pfl, offset, 2); - break; - case 4: - if (be) { - p[offset] &=3D value >> 24; - p[offset + 1] &=3D value >> 16; - p[offset + 2] &=3D value >> 8; - p[offset + 3] &=3D value; - } else { - p[offset] &=3D value; - p[offset + 1] &=3D value >> 8; - p[offset + 2] &=3D value >> 16; - p[offset + 3] &=3D value >> 24; - } - pflash_update(pfl, offset, 4); - break; + p =3D (uint8_t *)pfl->storage + offset; + if (pfl->be) { + uint64_t current =3D ldn_be_p(p, width); + stn_be_p(p, width, current & value); + } else { + uint64_t current =3D ldn_le_p(p, width); + stn_le_p(p, width, current & value); } + pflash_update(pfl, offset, width); } /* * While programming, status bit DQ7 should hold the opposite --=20 2.20.1 From nobody Sun May 5 18:18:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557095257; cv=none; d=zoho.com; s=zohoarc; b=QfCKJ2L8dsszzgfOwNp6TB+8o4Kq5zjxluOFM8mltbU+Uv2EH0y2tVFju+dXCi7B3p/c6F4m4XYU4beOMsbQISUad0KlI6Gkk+421VsYwDnx542H1v+cHBIi15e2lkJOJMFgX2ySC4IZMJaikcK2SukQ9RZx8AI+1gf8FRq7RQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557095257; 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:ARC-Authentication-Results; bh=Uy9VQrLZYlK1hEiscI6QHAUzFuq7lDZtOOxlyKKT+UQ=; b=AqP6bN9Zc5VWan+xvP/0zbADS6PT2KDpyglq7xEFh7ai5mh7fkl4UtEJUHU37lKesrEbmMJF2rLHR8lneKQjZc4vT87zAtAnYs/YgRRMfi8smjpS7nuVpA8+AkYKqVp/lcSykRn6xpcUHM9bYFyDJ5h4NNuAlkO29WYOZWLs3ec= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557095257855727.761594627371; Sun, 5 May 2019 15:27:37 -0700 (PDT) Received: from localhost ([127.0.0.1]:47080 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPba-0006Zw-Rd for importer@patchew.org; Sun, 05 May 2019 18:27:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPR8-0004UM-P0 for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNPR7-0000Dr-RL for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51400) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNPR4-000076-O2; Sun, 05 May 2019 18:16:42 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF19A85A07; Sun, 5 May 2019 22:16:40 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0F385D739; Sun, 5 May 2019 22:16:37 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stephen Checkoway Date: Mon, 6 May 2019 00:15:40 +0200 Message-Id: <20190505221544.31568-10-philmd@redhat.com> In-Reply-To: <20190505221544.31568-1-philmd@redhat.com> References: <20190505221544.31568-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 05 May 2019 22:16:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 09/13] hw/block/pflash_cfi02: Use the ldst API in pflash_read() 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The load/store API eases code review. Signed-off-by: Stephen Checkoway Message-Id: <20190426162624.55977-3-stephen.checkoway@oberlin.edu> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 [PMD: Extracted from bigger patch] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/pflash_cfi02.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 69e0086324e..2777167af11 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -196,34 +196,20 @@ static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr = offset, case 0x00: flash_read: /* Flash area read */ - p =3D pfl->storage; + p =3D (uint8_t *)pfl->storage + offset; + if (pfl->be) { + ret =3D ldn_be_p(p, width); + } else { + ret =3D ldn_le_p(p, width); + } switch (width) { case 1: - ret =3D p[offset]; trace_pflash_data_read8(offset, ret); break; case 2: - if (be) { - ret =3D p[offset] << 8; - ret |=3D p[offset + 1]; - } else { - ret =3D p[offset]; - ret |=3D p[offset + 1] << 8; - } trace_pflash_data_read16(offset, ret); break; case 4: - if (be) { - ret =3D p[offset] << 24; - ret |=3D p[offset + 1] << 16; - ret |=3D p[offset + 2] << 8; - ret |=3D p[offset + 3]; - } else { - ret =3D p[offset]; - ret |=3D p[offset + 1] << 8; - ret |=3D p[offset + 2] << 16; - ret |=3D p[offset + 3] << 24; - } trace_pflash_data_read32(offset, ret); break; } --=20 2.20.1 From nobody Sun May 5 18:18:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557095070; cv=none; d=zoho.com; s=zohoarc; b=a7E+wxmZ5kjHtNKEKiSZm0YPXX1iYLyAABjYnlRFnWcgcmKu6ef6BNsUGCg+w/pXOCdvnQe5xeDdONUhOMvKpt5wLGndElwzRt8rfBO1U2piwsBwrm5DXz4NHc7oq2vEeKT6vCvscBNK9ORi9N3mnTp1HAagwniSYhYWWGUG27o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557095070; 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:ARC-Authentication-Results; bh=3CbNyz0PGA34ZvRc5zI/wvGQWVZ3AO6ea2hFUDq/m74=; b=ncf2cyF/JBOyzWeocc2be7zW9O7SPjXL+57bJxruDGmchEjBFAl0dJL1t9Dk7Zh3IaLuJIFq5/z4fnssJbK0yVMLqwHMPm10u5XfelZTsW7T8oVHrzuUa7Vl+0grxhPQvekbi5WsUeUKTv51597qYcPk8sWMqyJrPNMYZwWfBvM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557095070052906.3972633042717; Sun, 5 May 2019 15:24:30 -0700 (PDT) Received: from localhost ([127.0.0.1]:47010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPYX-00022Y-Se for importer@patchew.org; Sun, 05 May 2019 18:24:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPRA-0004XY-Hz for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNPR9-0000Gv-Jx for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51354) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNPR7-0000Bm-6T; Sun, 05 May 2019 18:16:45 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C3E43091740; Sun, 5 May 2019 22:16:44 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7442F7C386; Sun, 5 May 2019 22:16:41 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stephen Checkoway Date: Mon, 6 May 2019 00:15:41 +0200 Message-Id: <20190505221544.31568-11-philmd@redhat.com> In-Reply-To: <20190505221544.31568-1-philmd@redhat.com> References: <20190505221544.31568-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Sun, 05 May 2019 22:16:44 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 10/13] hw/block/pflash_cfi02: Extract the pflash_data_read() function 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Extract the code block in a new function, remove a goto statement. Signed-off-by: Stephen Checkoway Message-Id: <20190426162624.55977-3-stephen.checkoway@oberlin.edu> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 [PMD: Extracted from bigger patch, remove the XXX tracing comment] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/pflash_cfi02.c | 44 ++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 2777167af11..adfa39f9b5e 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -164,12 +164,33 @@ static void pflash_timer (void *opaque) pfl->cmd =3D 0; } =20 +/* + * Read data from flash. + */ +static uint64_t pflash_data_read(PFlashCFI02 *pfl, hwaddr offset, + unsigned int width) +{ + uint8_t *p =3D (uint8_t *)pfl->storage + offset; + uint64_t ret =3D pfl->be ? ldn_be_p(p, width) : ldn_le_p(p, width); + switch (width) { + case 1: + trace_pflash_data_read8(offset, ret); + break; + case 2: + trace_pflash_data_read16(offset, ret); + break; + case 4: + trace_pflash_data_read32(offset, ret); + break; + } + return ret; +} + static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr offset, int width, int be) { hwaddr boff; uint32_t ret; - uint8_t *p; =20 ret =3D -1; trace_pflash_read(offset, pfl->cmd, width, pfl->wcycle); @@ -194,25 +215,8 @@ static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr o= ffset, case 0x80: /* We accept reads during second unlock sequence... */ case 0x00: - flash_read: /* Flash area read */ - p =3D (uint8_t *)pfl->storage + offset; - if (pfl->be) { - ret =3D ldn_be_p(p, width); - } else { - ret =3D ldn_le_p(p, width); - } - switch (width) { - case 1: - trace_pflash_data_read8(offset, ret); - break; - case 2: - trace_pflash_data_read16(offset, ret); - break; - case 4: - trace_pflash_data_read32(offset, ret); - break; - } + ret =3D pflash_data_read(pfl, offset, width); break; case 0x90: /* flash ID read */ @@ -232,7 +236,7 @@ static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr of= fset, } /* Fall through to data read. */ default: - goto flash_read; + ret =3D pflash_data_read(pfl, offset, width); } DPRINTF("%s: ID " TARGET_FMT_plx " %" PRIx32 "\n", __func__, boff,= ret); break; --=20 2.20.1 From nobody Sun May 5 18:18:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557095086; cv=none; d=zoho.com; s=zohoarc; b=J8YMetQIu2rGsNZrys+XxyL39IABNcDbnuzLoOz6sD749ji4kUaUdJEdRWRuYA77HJsJTwzFvmG1La+A+qzk8guud/oIK+uOSHZtxov2lMbYbcrQrkNMn/1MVbCe6fIyvODz/qcf3gyRGNi6V6lagKsTqnu6uT1FnpN10Kx75Cg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557095086; 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:ARC-Authentication-Results; bh=JBHghD8HQ93UKzG2JYXZ2G6M+DgFCslbovJSNUB4EpA=; b=iNK1FreVSZxqiGKa+iASydm5rCBuNUY6iJPb4ZYCSOOi6/VTKVYgxPIZaQgasVWQT2IWlLrBTvhHvWO6uOgXzBroW7ZDJrYwENjudSluiKBDPlIM91ZyhGDMR7xInZUGjx4SSdUcgenvCg7FCL6kHbSDphF1mM7rN0ltlBja3D0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557095086961937.961915542303; Sun, 5 May 2019 15:24:46 -0700 (PDT) Received: from localhost ([127.0.0.1]:47012 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPYn-0002F4-Nz for importer@patchew.org; Sun, 05 May 2019 18:24:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPRE-0004ea-M2 for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNPRD-0000NO-ET for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44722) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNPRA-0000Hh-NV; Sun, 05 May 2019 18:16:48 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 11E68309264B; Sun, 5 May 2019 22:16:48 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E81405D739; Sun, 5 May 2019 22:16:44 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stephen Checkoway Date: Mon, 6 May 2019 00:15:42 +0200 Message-Id: <20190505221544.31568-12-philmd@redhat.com> In-Reply-To: <20190505221544.31568-1-philmd@redhat.com> References: <20190505221544.31568-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Sun, 05 May 2019 22:16:48 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 11/13] hw/block/pflash_cfi02: Unify the MemoryRegionOps 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The pflash_read()/pflash_write() can check the device endianess via the pfl->be variable, so remove the 'int be' argument. Since the big/little MemoryRegionOps are now identical, it is pointless to declare them both. Unify them. Signed-off-by: Stephen Checkoway Message-Id: <20190426162624.55977-3-stephen.checkoway@oberlin.edu> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 [PMD: Extracted from bigger patch to ease review] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/pflash_cfi02.c | 62 +++++++++++------------------------------ 1 file changed, 16 insertions(+), 46 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index adfa39f9b5e..59daade2ee6 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -186,11 +186,11 @@ static uint64_t pflash_data_read(PFlashCFI02 *pfl, hw= addr offset, return ret; } =20 -static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr offset, - int width, int be) +static uint64_t pflash_read(void *opaque, hwaddr offset, unsigned int widt= h) { + PFlashCFI02 *pfl =3D opaque; hwaddr boff; - uint32_t ret; + uint64_t ret; =20 ret =3D -1; trace_pflash_read(offset, pfl->cmd, width, pfl->wcycle); @@ -238,14 +238,14 @@ static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr = offset, default: ret =3D pflash_data_read(pfl, offset, width); } - DPRINTF("%s: ID " TARGET_FMT_plx " %" PRIx32 "\n", __func__, boff,= ret); + DPRINTF("%s: ID " TARGET_FMT_plx " %" PRIx64 "\n", __func__, boff,= ret); break; case 0xA0: case 0x10: case 0x30: /* Status register read */ ret =3D pfl->status; - DPRINTF("%s: status %" PRIx32 "\n", __func__, ret); + DPRINTF("%s: status %" PRIx64 "\n", __func__, ret); /* Toggle bit 6 */ toggle_dq6(pfl); break; @@ -263,8 +263,7 @@ static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr of= fset, } =20 /* update flash content on disk */ -static void pflash_update(PFlashCFI02 *pfl, int offset, - int size) +static void pflash_update(PFlashCFI02 *pfl, int offset, int size) { int offset_end; if (pfl->blk) { @@ -277,9 +276,10 @@ static void pflash_update(PFlashCFI02 *pfl, int offset, } } =20 -static void pflash_write(PFlashCFI02 *pfl, hwaddr offset, - uint32_t value, int width, int be) +static void pflash_write(void *opaque, hwaddr offset, uint64_t value, + unsigned int width) { + PFlashCFI02 *pfl =3D opaque; hwaddr boff; uint8_t *p; uint8_t cmd; @@ -295,7 +295,7 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offse= t, trace_pflash_write(offset, value, width, pfl->wcycle); offset &=3D pfl->chip_len - 1; =20 - DPRINTF("%s: offset " TARGET_FMT_plx " %08" PRIx32 " %d\n", __func__, + DPRINTF("%s: offset " TARGET_FMT_plx " %08" PRIx64 " %d\n", __func__, offset, value, width); boff =3D offset & (pfl->sector_len - 1); if (pfl->width =3D=3D 2) @@ -492,39 +492,9 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offs= et, pfl->cmd =3D 0; } =20 -static uint64_t pflash_be_readfn(void *opaque, hwaddr addr, unsigned size) -{ - return pflash_read(opaque, addr, size, 1); -} - -static void pflash_be_writefn(void *opaque, hwaddr addr, - uint64_t value, unsigned size) -{ - pflash_write(opaque, addr, value, size, 1); -} - -static uint64_t pflash_le_readfn(void *opaque, hwaddr addr, unsigned size) -{ - return pflash_read(opaque, addr, size, 0); -} - -static void pflash_le_writefn(void *opaque, hwaddr addr, - uint64_t value, unsigned size) -{ - pflash_write(opaque, addr, value, size, 0); -} - -static const MemoryRegionOps pflash_cfi02_ops_be =3D { - .read =3D pflash_be_readfn, - .write =3D pflash_be_writefn, - .valid.min_access_size =3D 1, - .valid.max_access_size =3D 4, - .endianness =3D DEVICE_NATIVE_ENDIAN, -}; - -static const MemoryRegionOps pflash_cfi02_ops_le =3D { - .read =3D pflash_le_readfn, - .write =3D pflash_le_writefn, +static const MemoryRegionOps pflash_cfi02_ops =3D { + .read =3D pflash_read, + .write =3D pflash_write, .valid.min_access_size =3D 1, .valid.max_access_size =3D 4, .endianness =3D DEVICE_NATIVE_ENDIAN, @@ -552,9 +522,9 @@ static void pflash_cfi02_realize(DeviceState *dev, Erro= r **errp) =20 chip_len =3D pfl->sector_len * pfl->nb_blocs; =20 - memory_region_init_rom_device(&pfl->orig_mem, OBJECT(pfl), pfl->be ? - &pflash_cfi02_ops_be : &pflash_cfi02_ops= _le, - pfl, pfl->name, chip_len, &local_err); + memory_region_init_rom_device(&pfl->orig_mem, OBJECT(pfl), + &pflash_cfi02_ops, pfl, pfl->name, + chip_len, &local_err); if (local_err) { error_propagate(errp, local_err); return; --=20 2.20.1 From nobody Sun May 5 18:18:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557095473; cv=none; d=zoho.com; s=zohoarc; b=ALbYQ/D6eKJpHJhP23UrN9ona9n4Y/rx/iuBfb9SwNcJDWgp+ifl4AL6NsigcpmEJajUw4rGIgZ0cJNP6/iaFyTsZdgERELCu3NWLqGC+bakI3+FIzlOmBnntQBow6hmmhF3D9z1SyOgxjmafBxuELa/RSfm70Vd4waC6fHKqrk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557095473; 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:ARC-Authentication-Results; bh=sf+zq39torbqnLR9iLS1VDaveQKxBA+ez1e+ohoK8J8=; b=mq84ppY/L50Y/dxDOPHgPwP5TbLbD9X/XgTmI8yTdHqS/hfPKQyYJ7IgHze+4jyDnOXQkZodM2drWv8BUhQEVNxKoGzi96TK7YsWmQSewL4+Oa73WXLpnftsDdaGJ+Yz2wlCgx9uFfb7E9oHHeTb+pTmZUFNtRT5TgjBiXljjDw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557095473457255.38319261594484; Sun, 5 May 2019 15:31:13 -0700 (PDT) Received: from localhost ([127.0.0.1]:47147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPf2-0000so-Gh for importer@patchew.org; Sun, 05 May 2019 18:31:08 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36290) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPRI-0004jd-N1 for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNPRH-0000TL-MI for qemu-devel@nongnu.org; Sun, 05 May 2019 18:16:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38972) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNPRF-0000PQ-8Y; Sun, 05 May 2019 18:16:53 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8CAB230820E4; Sun, 5 May 2019 22:16:52 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C4605D739; Sun, 5 May 2019 22:16:48 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stephen Checkoway Date: Mon, 6 May 2019 00:15:43 +0200 Message-Id: <20190505221544.31568-13-philmd@redhat.com> In-Reply-To: <20190505221544.31568-1-philmd@redhat.com> References: <20190505221544.31568-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sun, 05 May 2019 22:16:52 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 12/13] hw/block/pflash_cfi02: Fix command address comparison 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Stephen Checkoway Most AMD commands only examine 11 bits of the address. This masks the addresses used in the comparison to 11 bits. The exceptions are word or sector addresses which use offset directly rather than the shifted offset, boff. Signed-off-by: Stephen Checkoway Acked-by: Thomas Huth Message-Id: <20190426162624.55977-4-stephen.checkoway@oberlin.edu> [PMD: Prepend 'hw/' in patch subject] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/pflash_cfi02.c | 8 +++++++- tests/pflash-cfi02-test.c | 12 ++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 59daade2ee6..4c17dbf99f4 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -297,11 +297,13 @@ static void pflash_write(void *opaque, hwaddr offset,= uint64_t value, =20 DPRINTF("%s: offset " TARGET_FMT_plx " %08" PRIx64 " %d\n", __func__, offset, value, width); - boff =3D offset & (pfl->sector_len - 1); + boff =3D offset; if (pfl->width =3D=3D 2) boff =3D boff >> 1; else if (pfl->width =3D=3D 4) boff =3D boff >> 2; + /* Only the least-significant 11 bits are used in most cases. */ + boff &=3D 0x7FF; switch (pfl->wcycle) { case 0: /* Set the device in I/O access mode if required */ @@ -520,6 +522,10 @@ static void pflash_cfi02_realize(DeviceState *dev, Err= or **errp) return; } =20 + /* Only 11 bits are used in the comparison. */ + pfl->unlock_addr0 &=3D 0x7FF; + pfl->unlock_addr1 &=3D 0x7FF; + chip_len =3D pfl->sector_len * pfl->nb_blocs; =20 memory_region_init_rom_device(&pfl->orig_mem, OBJECT(pfl), diff --git a/tests/pflash-cfi02-test.c b/tests/pflash-cfi02-test.c index 3c37465499a..1e5d9124b71 100644 --- a/tests/pflash-cfi02-test.c +++ b/tests/pflash-cfi02-test.c @@ -22,8 +22,8 @@ =20 #define FLASH_WIDTH 2 #define CFI_ADDR (FLASH_WIDTH * 0x55) -#define UNLOCK0_ADDR (FLASH_WIDTH * 0x5555) -#define UNLOCK1_ADDR (FLASH_WIDTH * 0x2AAA) +#define UNLOCK0_ADDR (FLASH_WIDTH * 0x555) +#define UNLOCK1_ADDR (FLASH_WIDTH * 0x2AA) =20 #define CFI_CMD 0x98 #define UNLOCK0_CMD 0xAA @@ -190,6 +190,14 @@ static void test_flash(const void *opaque) g_assert_cmpint(flash_read(6), =3D=3D, 0xCDEF); g_assert_cmpint(flash_read(8), =3D=3D, 0xFFFF); =20 + /* Test ignored high order bits of address. */ + flash_write(FLASH_WIDTH * 0x5555, UNLOCK0_CMD); + flash_write(FLASH_WIDTH * 0x2AAA, UNLOCK1_CMD); + flash_write(FLASH_WIDTH * 0x5555, AUTOSELECT_CMD); + g_assert_cmpint(flash_read(FLASH_WIDTH * 0x0000), =3D=3D, 0x00BF); + g_assert_cmpint(flash_read(FLASH_WIDTH * 0x0001), =3D=3D, 0x236D); + reset(); + qtest_quit(global_qtest); } =20 --=20 2.20.1 From nobody Sun May 5 18:18:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557095249; cv=none; d=zoho.com; s=zohoarc; b=mIOMA2U39MTpeUKTw9/9DE+l7xZ+60Rqm4GZNmtoLEVCf32bZJSvxpi/GuYu2efw7lYeTLc9KHf+LrW9rM9Op5OjEryU60KjxxqBdJeLfBDsh89q0uKwNDjaFIsEaLhMThSVuYqj+wglToMJAjbeLDmMZSLc6ItaPstv9Xg7UuI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557095249; 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:ARC-Authentication-Results; bh=UKBlQHT0Na0IXm+5ompJXJoDRlgG/IG+4Gz3+EE9iUA=; b=PXtIBpdFDfmH5AcDw8kY0vLBWRer9hrpQMK0wiDr9/aMsr7xIkHjeWKqF93HEyWmvRhBlMDteLf2ZbUpdcgytE+pxd2Z2+izrMWYm8f05HTILnSd9ON3iCSjTxVF++TGZB/CKNkJrTSfhQH+25N7lmb1s21IIlQN2In6gEbQ4cw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557095249270377.39229391188735; Sun, 5 May 2019 15:27:29 -0700 (PDT) Received: from localhost ([127.0.0.1]:47078 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPbN-0006Pz-8C for importer@patchew.org; Sun, 05 May 2019 18:27:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNPRP-0004rR-JB for qemu-devel@nongnu.org; Sun, 05 May 2019 18:17:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNPRO-0000ci-O2 for qemu-devel@nongnu.org; Sun, 05 May 2019 18:17:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNPRL-0000Xs-FJ; Sun, 05 May 2019 18:16:59 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B062CB0AA6; Sun, 5 May 2019 22:16:58 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-58.brq.redhat.com [10.40.204.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 06A535D739; Sun, 5 May 2019 22:16:52 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stephen Checkoway Date: Mon, 6 May 2019 00:15:44 +0200 Message-Id: <20190505221544.31568-14-philmd@redhat.com> In-Reply-To: <20190505221544.31568-1-philmd@redhat.com> References: <20190505221544.31568-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sun, 05 May 2019 22:16:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 13/13] hw/block/pflash_cfi02: Use the chip erase time specified in the CFI table 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Stephen Checkoway When erasing the chip, use the typical time specified in the CFI table rather than arbitrarily selecting 5 seconds. Since the currently unconfigurable value set in the table is 12, this means a chip erase takes 4096 ms so this isn't a big change in behavior. Signed-off-by: Stephen Checkoway Message-Id: <20190426162624.55977-11-stephen.checkoway@oberlin.edu> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 [PMD: Prepend 'hw/' in patch subject] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/pflash_cfi02.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 4c17dbf99f4..49cd9ed0f91 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -429,9 +429,9 @@ static void pflash_write(void *opaque, hwaddr offset, u= int64_t value, pflash_update(pfl, 0, pfl->chip_len); } set_dq7(pfl, 0x00); - /* Let's wait 5 seconds before chip erase is done */ + /* Wait the time specified at CFI address 0x22. */ timer_mod(&pfl->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + - (NANOSECONDS_PER_SECOND * 5)); + (1ULL << pfl->cfi_table[0x22]) * SCALE_MS); break; case 0x30: /* Sector erase */ --=20 2.20.1