qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: marcin.krzeminski@nokia.com
To: qemu-devel@nongnu.org
Cc: pawel.lenkow@nokia.com, peter.crosthwaite@xilinx.com,
	marcin.krzeminski@nokia.com
Subject: [Qemu-devel] [PATCH 09/12] Support for 6Bytes jdec.
Date: Wed, 16 Dec 2015 13:57:12 +0100	[thread overview]
Message-ID: <1450270635-27080-10-git-send-email-marcin.krzeminski@nokia.com> (raw)
In-Reply-To: <1450270635-27080-1-git-send-email-marcin.krzeminski@nokia.com>

From: Marcin Krzeminski <marcin.krzeminski@nokia.com>

Signed-off-by: Pawel Lenkow <pawel.lenkow@nokia.com>
---
 hw/block/m25p80.c | 61 +++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 41 insertions(+), 20 deletions(-)

diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index a41c2f1..6fc55a3 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -50,12 +50,17 @@
 /* 16 MiB max in 3 byte address mode */
 #define MAX_3BYTES_SIZE 0x1000000
 
+#define SPI_NOR_MAX_ID_LEN    6
+
 typedef struct FlashPartInfo {
     const char *part_name;
-    /* jedec code. (jedec >> 16) & 0xff is the 1st byte, >> 8 the 2nd etc */
-    uint32_t jedec;
-    /* extended jedec code */
-    uint16_t ext_jedec;
+    /*
+     * This array stores the ID bytes.
+     * The first three bytes are the JEDIC ID.
+     * JEDEC ID zero means "no ID" (mostly older chips).
+     */
+    uint8_t id[SPI_NOR_MAX_ID_LEN];
+    uint8_t id_len;
     /* there is confusion between manufacturers as to what a sector is. In this
      * device model, a "sector" is the size that is erased by the ERASE_SECTOR
      * command (opcode 0xd8).
@@ -67,11 +72,33 @@ typedef struct FlashPartInfo {
 } FlashPartInfo;
 
 /* adapted from linux */
-
-#define INFO(_part_name, _jedec, _ext_jedec, _sector_size, _n_sectors, _flags)\
-    .part_name = (_part_name),\
-    .jedec = (_jedec),\
-    .ext_jedec = (_ext_jedec),\
+/* Used when the "_ext_id" is two bytes at most */
+#define INFO(_part_name, _jedec_id, _ext_id, _sector_size, _n_sectors, _flags)\
+    .part_name = _part_name,\
+    .id = {\
+        ((_jedec_id) >> 16) & 0xff,\
+        ((_jedec_id) >> 8) & 0xff,\
+        (_jedec_id) & 0xff,\
+        ((_ext_id) >> 8) & 0xff,\
+        (_ext_id) & 0xff,\
+          },\
+    .id_len = (!(_jedec_id) ? 0 : (3 + ((_ext_id) ? 2 : 0))),\
+    .sector_size = (_sector_size),\
+    .n_sectors = (_n_sectors),\
+    .page_size = 256,\
+    .flags = (_flags),
+
+#define INFO6(_part_name, _jedec_id, _ext_id, _sector_size, _n_sectors, _flags)\
+    .part_name = _part_name,\
+    .id = {\
+        ((_jedec_id) >> 16) & 0xff,\
+        ((_jedec_id) >> 8) & 0xff,\
+        (_jedec_id) & 0xff,\
+        ((_ext_id) >> 16) & 0xff,\
+        ((_ext_id) >> 8) & 0xff,\
+        (_ext_id) & 0xff,\
+          },\
+    .id_len = 6,\
     .sector_size = (_sector_size),\
     .n_sectors = (_n_sectors),\
     .page_size = 256,\
@@ -519,7 +546,7 @@ static void decode_new_cmd(Flash *s, uint32_t value)
         break;
 
     case DIOR:
-        switch ((s->pi->jedec >> 16) & 0xFF) {
+        switch (s->pi->id[0]) {
         case JEDEC_WINBOND:
         case JEDEC_SPANSION:
             s->needed_bytes = 4;
@@ -534,7 +561,7 @@ static void decode_new_cmd(Flash *s, uint32_t value)
         break;
 
     case QIOR:
-        switch ((s->pi->jedec >> 16) & 0xFF) {
+        switch (s->pi->id[0]) {
         case JEDEC_WINBOND:
         case JEDEC_SPANSION:
             s->needed_bytes = 6;
@@ -573,16 +600,10 @@ static void decode_new_cmd(Flash *s, uint32_t value)
 
     case JEDEC_READ:
         DB_PRINT_L(0, "populated jedec code\n");
-        s->data[0] = (s->pi->jedec >> 16) & 0xff;
-        s->data[1] = (s->pi->jedec >> 8) & 0xff;
-        s->data[2] = s->pi->jedec & 0xff;
-        if (s->pi->ext_jedec) {
-            s->data[3] = (s->pi->ext_jedec >> 8) & 0xff;
-            s->data[4] = s->pi->ext_jedec & 0xff;
-            s->len = 5;
-        } else {
-            s->len = 3;
+        for (i = 0; i < s->pi->id_len; i++) {
+            s->data[i] = s->pi->id[i];
         }
+        s->len = s->pi->id_len;
         s->pos = 0;
         s->state = STATE_READING_DATA;
         break;
-- 
2.5.0

  parent reply	other threads:[~2015-12-16 12:57 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-16 12:57 [Qemu-devel] [PATCH 00/12] Support for new flash devices/4bytes commands marcin.krzeminski
2015-12-16 12:57 ` [Qemu-devel] [PATCH 01/12] Removed unused variable marcin.krzeminski
2015-12-21 10:20   ` Peter Crosthwaite
2015-12-16 12:57 ` [Qemu-devel] [PATCH 02/12] Added reset-pin emulation in model marcin.krzeminski
2015-12-21 11:04   ` Peter Crosthwaite
2015-12-21 13:39     ` [Qemu-devel] ODP: " Krzeminski, Marcin (Nokia - PL/Wroclaw)
2016-02-01 18:29       ` [Qemu-devel] " Peter Crosthwaite
2016-02-02  7:15         ` Krzeminski, Marcin (Nokia - PL/Wroclaw)
2015-12-16 12:57 ` [Qemu-devel] [PATCH 03/12] Reset enable and reset memory commands support marcin.krzeminski
2015-12-21 11:18   ` Peter Crosthwaite
2015-12-21 13:42     ` [Qemu-devel] ODP: " Krzeminski, Marcin (Nokia - PL/Wroclaw)
2015-12-16 12:57 ` [Qemu-devel] [PATCH 04/12] Changed variable type to allow serial eeprom emulation (changing 0->1) marcin.krzeminski
2015-12-21 11:23   ` Peter Crosthwaite
2015-12-21 13:46     ` [Qemu-devel] ODP: " Krzeminski, Marcin (Nokia - PL/Wroclaw)
2015-12-16 12:57 ` [Qemu-devel] [PATCH 05/12] Added support for serial eeproms - AT25128A/AT25256A marcin.krzeminski
2015-12-21 11:28   ` Peter Crosthwaite
2015-12-21 13:49     ` [Qemu-devel] ODP: " Krzeminski, Marcin (Nokia - PL/Wroclaw)
2015-12-16 12:57 ` [Qemu-devel] [PATCH 06/12] 4byte address mode support added marcin.krzeminski
2015-12-21 11:35   ` Peter Crosthwaite
     [not found]     ` <CA0E6F9BA6AED7458C23277BD87075E51017D30D@DEMUMBX005.nsn-intra.net>
2015-12-21 13:53       ` [Qemu-devel] ODP: " Krzeminski, Marcin (Nokia - PL/Wroclaw)
2015-12-22 18:41   ` [Qemu-devel] " Cédric Le Goater
2015-12-22 21:28     ` Peter Crosthwaite
2016-02-04 11:58       ` Krzeminski, Marcin (Nokia - PL/Wroclaw)
2015-12-16 12:57 ` [Qemu-devel] [PATCH 07/12] Added support for extend address mode commands marcin.krzeminski
2015-12-21 11:41   ` Peter Crosthwaite
2015-12-21 13:56     ` [Qemu-devel] ODP: " Krzeminski, Marcin (Nokia - PL/Wroclaw)
2015-12-16 12:57 ` [Qemu-devel] [PATCH 08/12] Support for N25Q256A/N25Q512A marcin.krzeminski
2015-12-21 10:29   ` Peter Crosthwaite
2015-12-21 13:57     ` [Qemu-devel] ODP: " Krzeminski, Marcin (Nokia - PL/Wroclaw)
2015-12-16 12:57 ` marcin.krzeminski [this message]
2015-12-21 10:47   ` [Qemu-devel] [PATCH 09/12] Support for 6Bytes jdec Peter Crosthwaite
2015-12-21 14:10     ` [Qemu-devel] ODP: " Krzeminski, Marcin (Nokia - PL/Wroclaw)
2015-12-16 12:57 ` [Qemu-devel] [PATCH 10/12] Support for quad commands marcin.krzeminski
2015-12-21 11:52   ` Peter Crosthwaite
2015-12-21 14:29     ` [Qemu-devel] ODP: " Krzeminski, Marcin (Nokia - PL/Wroclaw)
2015-12-22 21:40   ` [Qemu-devel] " Peter Crosthwaite
2015-12-23  2:25     ` Peter Crosthwaite
2015-12-29 14:21       ` Lenkow, Pawel (Nokia - PL/Wroclaw)
2015-12-16 12:57 ` [Qemu-devel] [PATCH 11/12] Support for mx66u51235 and s25fl512s marcin.krzeminski
2015-12-16 12:57 ` [Qemu-devel] [PATCH 12/12] Read flag status register command support added marcin.krzeminski
2015-12-21 11:54   ` Peter Crosthwaite
2015-12-21 14:36     ` [Qemu-devel] ODP: " Krzeminski, Marcin (Nokia - PL/Wroclaw)
2015-12-16 13:01 ` [Qemu-devel] [PATCH 00/12] Support for new flash devices/4bytes commands Krzeminski, Marcin (Nokia - PL/Wroclaw)

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=1450270635-27080-10-git-send-email-marcin.krzeminski@nokia.com \
    --to=marcin.krzeminski@nokia.com \
    --cc=pawel.lenkow@nokia.com \
    --cc=peter.crosthwaite@xilinx.com \
    --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).