m25p80: Add basic support for the SFDP command

JEDEC STANDARD JESD216 for Serial Flash Discovery Parameters (SFDP)
provides a mean to describe the features of a serial flash device
using a set of internal parameter tables.

This is the initial framework for the RDSFDP command giving access to
a private SFDP area under the flash. This area now needs to be
populated with the flash device characteristics, using a new
'sfdp_read' handler under FlashPartInfo.

Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com>
Message-Id: <20220722063602.128144-2-clg@kaod.org>
Message-Id: <20221013161241.2805140-2-clg@kaod.org>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
This commit is contained in:
Cédric Le Goater 2022-10-24 11:20:15 +02:00
parent 104bdaffd7
commit 2389bcc259
4 changed files with 47 additions and 1 deletions

View file

@ -35,6 +35,7 @@
#include "qapi/error.h"
#include "trace.h"
#include "qom/object.h"
#include "m25p80_sfdp.h"
/* 16 MiB max in 3 byte address mode */
#define MAX_3BYTES_SIZE 0x1000000
@ -72,6 +73,7 @@ typedef struct FlashPartInfo {
* This field inform how many die is in the chip.
*/
uint8_t die_cnt;
uint8_t (*sfdp_read)(uint32_t sfdp_addr);
} FlashPartInfo;
/* adapted from linux */
@ -355,6 +357,7 @@ typedef enum {
BULK_ERASE = 0xc7,
READ_FSR = 0x70,
RDCR = 0x15,
RDSFDP = 0x5a,
READ = 0x03,
READ4 = 0x13,
@ -421,6 +424,7 @@ typedef enum {
STATE_COLLECTING_DATA,
STATE_COLLECTING_VAR_LEN_DATA,
STATE_READING_DATA,
STATE_READING_SFDP,
} CMDState;
typedef enum {
@ -679,6 +683,8 @@ static inline int get_addr_length(Flash *s)
}
switch (s->cmd_in_progress) {
case RDSFDP:
return 3;
case PP4:
case PP4_4:
case QPP_4:
@ -823,6 +829,11 @@ static void complete_collecting_data(Flash *s)
" by device\n");
}
break;
case RDSFDP:
s->state = STATE_READING_SFDP;
break;
default:
break;
}
@ -1431,6 +1442,16 @@ static void decode_new_cmd(Flash *s, uint32_t value)
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Unknown cmd %x\n", value);
}
break;
case RDSFDP:
if (s->pi->sfdp_read) {
s->needed_bytes = get_addr_length(s) + 1; /* SFDP addr + dummy */
s->pos = 0;
s->len = 0;
s->state = STATE_COLLECTING_DATA;
break;
}
/* Fallthrough */
default:
s->pos = 0;
s->len = 1;
@ -1538,6 +1559,12 @@ static uint32_t m25p80_transfer8(SSIPeripheral *ss, uint32_t tx)
}
}
break;
case STATE_READING_SFDP:
assert(s->pi->sfdp_read);
r = s->pi->sfdp_read(s->cur_addr);
trace_m25p80_read_sfdp(s, s->cur_addr, (uint8_t)r);
s->cur_addr = (s->cur_addr + 1) & (M25P80_SFDP_MAX_SIZE - 1);
break;
default:
case STATE_IDLE: