qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@kaod.org>
To: Peter Maydell <peter.maydell@linaro.org>,
	Peter Crosthwaite <crosthwaite.peter@gmail.com>
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, kwolf@redhat.com,
	armbru@redhat.com, "Andrew Jeffery" <andrew@aj.id.au>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Cédric Le Goater" <clg@kaod.org>
Subject: [Qemu-devel] [PATCH v5 4/9] m25p80: change cur_addr to 32 bit integer
Date: Tue, 28 Jun 2016 20:24:25 +0200	[thread overview]
Message-ID: <1467138270-32481-5-git-send-email-clg@kaod.org> (raw)
In-Reply-To: <1467138270-32481-1-git-send-email-clg@kaod.org>

From: Paolo Bonzini <pbonzini@redhat.com>

The maximum amount of storage that can be addressed by the m25p80 command
set is 4 GiB.  However, cur_addr is currently a 64-bit integer.  To avoid
further problems related to sign extension of signed 32-bit integer
expressions, change cur_addr to a 32 bit integer.  Preserve migration
format by adding a dummy 4-byte field in place of the (big-endian)
high four bytes in the formerly 64-bit cur_addr field.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 hw/block/m25p80.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index 4836b4eb9666..80e60c23e009 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -390,7 +390,7 @@ typedef struct Flash {
     uint32_t pos;
     uint8_t needed_bytes;
     uint8_t cmd_in_progress;
-    uint64_t cur_addr;
+    uint32_t cur_addr;
     uint32_t nonvolatile_cfg;
     /* Configuration register for Macronix */
     uint32_t volatile_cfg;
@@ -536,9 +536,9 @@ static inline void flash_sync_dirty(Flash *s, int64_t newpage)
 }
 
 static inline
-void flash_write8(Flash *s, uint64_t addr, uint8_t data)
+void flash_write8(Flash *s, uint32_t addr, uint8_t data)
 {
-    int64_t page = addr / s->pi->page_size;
+    uint32_t page = addr / s->pi->page_size;
     uint8_t prev = s->storage[s->cur_addr];
 
     if (!s->write_enable) {
@@ -546,7 +546,7 @@ void flash_write8(Flash *s, uint64_t addr, uint8_t data)
     }
 
     if ((prev ^ data) & data) {
-        DB_PRINT_L(1, "programming zero to one! addr=%" PRIx64 "  %" PRIx8
+        DB_PRINT_L(1, "programming zero to one! addr=%" PRIx32 "  %" PRIx8
                    " -> %" PRIx8 "\n", addr, prev, data);
     }
 
@@ -1095,7 +1095,7 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx)
     switch (s->state) {
 
     case STATE_PAGE_PROGRAM:
-        DB_PRINT_L(1, "page program cur_addr=%#" PRIx64 " data=%" PRIx8 "\n",
+        DB_PRINT_L(1, "page program cur_addr=%#" PRIx32 " data=%" PRIx8 "\n",
                    s->cur_addr, (uint8_t)tx);
         flash_write8(s, s->cur_addr, (uint8_t)tx);
         s->cur_addr = (s->cur_addr + 1) & (s->size - 1);
@@ -1103,7 +1103,7 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx)
 
     case STATE_READ:
         r = s->storage[s->cur_addr];
-        DB_PRINT_L(1, "READ 0x%" PRIx64 "=%" PRIx8 "\n", s->cur_addr,
+        DB_PRINT_L(1, "READ 0x%" PRIx32 "=%" PRIx8 "\n", s->cur_addr,
                    (uint8_t)r);
         s->cur_addr = (s->cur_addr + 1) & (s->size - 1);
         break;
@@ -1202,7 +1202,8 @@ static const VMStateDescription vmstate_m25p80 = {
         VMSTATE_UINT32(pos, Flash),
         VMSTATE_UINT8(needed_bytes, Flash),
         VMSTATE_UINT8(cmd_in_progress, Flash),
-        VMSTATE_UINT64(cur_addr, Flash),
+        VMSTATE_UNUSED(4),
+        VMSTATE_UINT32(cur_addr, Flash),
         VMSTATE_BOOL(write_enable, Flash),
         VMSTATE_BOOL_V(reset_enable, Flash, 2),
         VMSTATE_UINT8_V(ear, Flash, 2),
-- 
2.1.4

  parent reply	other threads:[~2016-06-28 18:25 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-28 18:24 [Qemu-devel] [PATCH v5 0/9] ast2400: SMC controllers Cédric Le Goater
2016-06-28 18:24 ` [Qemu-devel] [PATCH v5 1/9] ssi: change ssi_slave_init to be a realize ops Cédric Le Goater
2016-07-01 15:16   ` Peter Maydell
2016-06-28 18:24 ` [Qemu-devel] [PATCH v5 2/9] m25p80: do not put iovec on the stack Cédric Le Goater
2016-06-28 18:24 ` [Qemu-devel] [PATCH v5 3/9] m25p80: avoid out of bounds accesses Cédric Le Goater
2016-06-28 18:24 ` Cédric Le Goater [this message]
2016-06-28 18:24 ` [Qemu-devel] [PATCH v5 5/9] m25p80: qdev-ify drive property Cédric Le Goater
2016-06-28 18:24 ` [Qemu-devel] [PATCH v5 6/9] ast2400: add SMC controllers (FMC and SPI) Cédric Le Goater
2016-06-29  7:58   ` Cédric Le Goater
2016-07-02 17:00     ` mar.krzeminski
2016-07-04  6:58       ` Cédric Le Goater
2016-07-04  7:12         ` Marcin Krzemiński
2016-06-28 18:24 ` [Qemu-devel] [PATCH v5 7/9] ast2400: add SPI flash slaves Cédric Le Goater
2016-07-01 16:24   ` Peter Maydell
2016-07-01 16:44     ` Cédric Le Goater
2016-07-01 17:00       ` Peter Maydell
2016-07-02 17:08   ` mar.krzeminski
2016-07-02 17:51     ` mar.krzeminski
2016-06-28 18:24 ` [Qemu-devel] [PATCH v5 8/9] ast2400: create " Cédric Le Goater
2016-07-01 15:19   ` Peter Maydell
2016-06-28 18:24 ` [Qemu-devel] [PATCH v5 9/9] tests: add a m25p80 test Cédric Le Goater
2016-07-01 17:18   ` Peter Maydell
2016-07-01 17:22     ` Peter Maydell
2016-07-01 17:30     ` Cédric Le Goater
2016-07-01 21:46       ` Greg Kurz
2016-07-02 18:05   ` mar.krzeminski
2016-07-04  9:15     ` Cédric Le Goater
2016-07-04  9:50       ` Cédric Le Goater
2016-07-04 11:14       ` Peter Maydell
2016-07-04 12:01         ` Cédric Le Goater
2016-07-04 12:11           ` Peter Maydell
2016-07-04 12:32             ` Cédric Le Goater
2016-07-01 16:25 ` [Qemu-devel] [PATCH v5 0/9] ast2400: SMC controllers Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467138270-32481-5-git-send-email-clg@kaod.org \
    --to=clg@kaod.org \
    --cc=andrew@aj.id.au \
    --cc=armbru@redhat.com \
    --cc=crosthwaite.peter@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).