2012-03-26 16:10:59 +04:00
|
|
|
/*
|
|
|
|
* ST M25P80 emulator. Emulate all SPI flash devices based on the m25p80 command
|
|
|
|
* set. Known devices table current as of Jun/2012 and taken from linux.
|
|
|
|
* See drivers/mtd/devices/m25p80.c.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
|
|
|
* Copyright (C) 2012 Peter A. G. Crosthwaite <peter.crosthwaite@petalogix.com>
|
|
|
|
* Copyright (C) 2012 PetaLogix
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 or
|
|
|
|
* (at your option) a later version of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-18 21:01:42 +03:00
|
|
|
#include "qemu/osdep.h"
|
2018-06-25 15:42:05 +03:00
|
|
|
#include "qemu/units.h"
|
2014-10-07 15:59:13 +04:00
|
|
|
#include "sysemu/block-backend.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2020-12-12 01:05:12 +03:00
|
|
|
#include "hw/qdev-properties-system.h"
|
2016-01-21 17:15:03 +03:00
|
|
|
#include "hw/ssi/ssi.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2016-03-30 19:27:23 +03:00
|
|
|
#include "qemu/bitops.h"
|
2015-12-15 15:16:16 +03:00
|
|
|
#include "qemu/log.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2017-01-09 14:40:23 +03:00
|
|
|
#include "qemu/error-report.h"
|
2016-07-04 15:06:37 +03:00
|
|
|
#include "qapi/error.h"
|
2020-03-16 18:52:23 +03:00
|
|
|
#include "trace.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2013-04-16 04:34:11 +04:00
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
/* Fields for FlashPartInfo->flags */
|
|
|
|
|
|
|
|
/* erase capabilities */
|
|
|
|
#define ER_4K 1
|
|
|
|
#define ER_32K 2
|
|
|
|
/* set to allow the page program command to write 0s back to 1. Useful for
|
|
|
|
* modelling EEPROM with SPI flash command set
|
|
|
|
*/
|
2016-03-30 19:27:24 +03:00
|
|
|
#define EEPROM 0x100
|
2012-03-26 16:10:59 +04:00
|
|
|
|
2016-03-30 19:27:23 +03:00
|
|
|
/* 16 MiB max in 3 byte address mode */
|
|
|
|
#define MAX_3BYTES_SIZE 0x1000000
|
|
|
|
|
2016-06-27 17:37:33 +03:00
|
|
|
#define SPI_NOR_MAX_ID_LEN 6
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
typedef struct FlashPartInfo {
|
|
|
|
const char *part_name;
|
2016-06-27 17:37:33 +03:00
|
|
|
/*
|
|
|
|
* 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;
|
2012-03-26 16:10:59 +04:00
|
|
|
/* 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).
|
|
|
|
*/
|
|
|
|
uint32_t sector_size;
|
|
|
|
uint32_t n_sectors;
|
|
|
|
uint32_t page_size;
|
2016-03-30 19:27:22 +03:00
|
|
|
uint16_t flags;
|
2017-01-20 14:15:06 +03:00
|
|
|
/*
|
|
|
|
* Big sized spi nor are often stacked devices, thus sometime
|
|
|
|
* replace chip erase with die erase.
|
|
|
|
* This field inform how many die is in the chip.
|
|
|
|
*/
|
|
|
|
uint8_t die_cnt;
|
2012-03-26 16:10:59 +04:00
|
|
|
} FlashPartInfo;
|
|
|
|
|
|
|
|
/* adapted from linux */
|
2016-06-27 17:37:33 +03:00
|
|
|
/* 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,\
|
2017-01-20 14:15:06 +03:00
|
|
|
.flags = (_flags),\
|
|
|
|
.die_cnt = 0
|
2016-06-27 17:37:33 +03:00
|
|
|
|
|
|
|
#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,\
|
2012-03-26 16:10:59 +04:00
|
|
|
.sector_size = (_sector_size),\
|
|
|
|
.n_sectors = (_n_sectors),\
|
|
|
|
.page_size = 256,\
|
|
|
|
.flags = (_flags),\
|
2017-01-20 14:15:06 +03:00
|
|
|
.die_cnt = 0
|
|
|
|
|
|
|
|
#define INFO_STACKED(_part_name, _jedec_id, _ext_id, _sector_size, _n_sectors,\
|
|
|
|
_flags, _die_cnt)\
|
|
|
|
.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),\
|
|
|
|
.die_cnt = _die_cnt
|
2012-03-26 16:10:59 +04:00
|
|
|
|
2012-10-15 08:34:37 +04:00
|
|
|
#define JEDEC_NUMONYX 0x20
|
|
|
|
#define JEDEC_WINBOND 0xEF
|
|
|
|
#define JEDEC_SPANSION 0x01
|
|
|
|
|
2016-03-30 19:27:23 +03:00
|
|
|
/* Numonyx (Micron) Configuration register macros */
|
|
|
|
#define VCFG_DUMMY 0x1
|
|
|
|
#define VCFG_WRAP_SEQUENTIAL 0x2
|
|
|
|
#define NVCFG_XIP_MODE_DISABLED (7 << 9)
|
|
|
|
#define NVCFG_XIP_MODE_MASK (7 << 9)
|
2020-11-17 02:11:01 +03:00
|
|
|
#define VCFG_XIP_MODE_DISABLED (1 << 3)
|
2016-03-30 19:27:23 +03:00
|
|
|
#define CFG_DUMMY_CLK_LEN 4
|
|
|
|
#define NVCFG_DUMMY_CLK_POS 12
|
|
|
|
#define VCFG_DUMMY_CLK_POS 4
|
2016-11-01 20:03:02 +03:00
|
|
|
#define EVCFG_OUT_DRIVER_STRENGTH_DEF 7
|
2016-03-30 19:27:23 +03:00
|
|
|
#define EVCFG_VPP_ACCELERATOR (1 << 3)
|
|
|
|
#define EVCFG_RESET_HOLD_ENABLED (1 << 4)
|
|
|
|
#define NVCFG_DUAL_IO_MASK (1 << 2)
|
2020-11-17 02:11:01 +03:00
|
|
|
#define EVCFG_DUAL_IO_DISABLED (1 << 6)
|
2016-03-30 19:27:23 +03:00
|
|
|
#define NVCFG_QUAD_IO_MASK (1 << 3)
|
2020-11-17 02:11:01 +03:00
|
|
|
#define EVCFG_QUAD_IO_DISABLED (1 << 7)
|
2016-03-30 19:27:23 +03:00
|
|
|
#define NVCFG_4BYTE_ADDR_MASK (1 << 0)
|
|
|
|
#define NVCFG_LOWER_SEGMENT_MASK (1 << 1)
|
|
|
|
|
2016-03-30 19:27:23 +03:00
|
|
|
/* Numonyx (Micron) Flag Status Register macros */
|
|
|
|
#define FSR_4BYTE_ADDR_MODE_ENABLED 0x1
|
|
|
|
#define FSR_FLASH_READY (1 << 7)
|
|
|
|
|
2016-06-27 17:37:34 +03:00
|
|
|
/* Spansion configuration registers macros. */
|
|
|
|
#define SPANSION_QUAD_CFG_POS 0
|
|
|
|
#define SPANSION_QUAD_CFG_LEN 1
|
|
|
|
#define SPANSION_DUMMY_CLK_POS 0
|
|
|
|
#define SPANSION_DUMMY_CLK_LEN 4
|
|
|
|
#define SPANSION_ADDR_LEN_POS 7
|
|
|
|
#define SPANSION_ADDR_LEN_LEN 1
|
|
|
|
|
2016-06-27 17:37:34 +03:00
|
|
|
/*
|
|
|
|
* Spansion read mode command length in bytes,
|
|
|
|
* the mode is currently not supported.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SPANSION_CONTINUOUS_READ_MODE_CMD_LEN 1
|
2016-07-14 18:51:38 +03:00
|
|
|
#define WINBOND_CONTINUOUS_READ_MODE_CMD_LEN 1
|
2016-06-27 17:37:34 +03:00
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
static const FlashPartInfo known_devices[] = {
|
|
|
|
/* Atmel -- some are (confusingly) marketed as "DataFlash" */
|
|
|
|
{ INFO("at25fs010", 0x1f6601, 0, 32 << 10, 4, ER_4K) },
|
|
|
|
{ INFO("at25fs040", 0x1f6604, 0, 64 << 10, 8, ER_4K) },
|
|
|
|
|
|
|
|
{ INFO("at25df041a", 0x1f4401, 0, 64 << 10, 8, ER_4K) },
|
|
|
|
{ INFO("at25df321a", 0x1f4701, 0, 64 << 10, 64, ER_4K) },
|
|
|
|
{ INFO("at25df641", 0x1f4800, 0, 64 << 10, 128, ER_4K) },
|
|
|
|
|
|
|
|
{ INFO("at26f004", 0x1f0400, 0, 64 << 10, 8, ER_4K) },
|
|
|
|
{ INFO("at26df081a", 0x1f4501, 0, 64 << 10, 16, ER_4K) },
|
|
|
|
{ INFO("at26df161a", 0x1f4601, 0, 64 << 10, 32, ER_4K) },
|
|
|
|
{ INFO("at26df321", 0x1f4700, 0, 64 << 10, 64, ER_4K) },
|
|
|
|
|
2013-05-01 18:40:53 +04:00
|
|
|
{ INFO("at45db081d", 0x1f2500, 0, 64 << 10, 16, ER_4K) },
|
|
|
|
|
2016-03-30 19:27:24 +03:00
|
|
|
/* Atmel EEPROMS - it is assumed, that don't care bit in command
|
|
|
|
* is set to 0. Block protection is not supported.
|
|
|
|
*/
|
|
|
|
{ INFO("at25128a-nonjedec", 0x0, 0, 1, 131072, EEPROM) },
|
|
|
|
{ INFO("at25256a-nonjedec", 0x0, 0, 1, 262144, EEPROM) },
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
/* EON -- en25xxx */
|
|
|
|
{ INFO("en25f32", 0x1c3116, 0, 64 << 10, 64, ER_4K) },
|
|
|
|
{ INFO("en25p32", 0x1c2016, 0, 64 << 10, 64, 0) },
|
|
|
|
{ INFO("en25q32b", 0x1c3016, 0, 64 << 10, 64, 0) },
|
|
|
|
{ INFO("en25p64", 0x1c2017, 0, 64 << 10, 128, 0) },
|
2013-05-01 18:40:53 +04:00
|
|
|
{ INFO("en25q64", 0x1c3017, 0, 64 << 10, 128, ER_4K) },
|
|
|
|
|
|
|
|
/* GigaDevice */
|
|
|
|
{ INFO("gd25q32", 0xc84016, 0, 64 << 10, 64, ER_4K) },
|
|
|
|
{ INFO("gd25q64", 0xc84017, 0, 64 << 10, 128, ER_4K) },
|
2012-03-26 16:10:59 +04:00
|
|
|
|
|
|
|
/* Intel/Numonyx -- xxxs33b */
|
|
|
|
{ INFO("160s33b", 0x898911, 0, 64 << 10, 32, 0) },
|
|
|
|
{ INFO("320s33b", 0x898912, 0, 64 << 10, 64, 0) },
|
|
|
|
{ INFO("640s33b", 0x898913, 0, 64 << 10, 128, 0) },
|
2013-05-01 18:40:53 +04:00
|
|
|
{ INFO("n25q064", 0x20ba17, 0, 64 << 10, 128, 0) },
|
2012-03-26 16:10:59 +04:00
|
|
|
|
2021-01-26 09:00:00 +03:00
|
|
|
/* ISSI */
|
|
|
|
{ INFO("is25lq040b", 0x9d4013, 0, 64 << 10, 8, ER_4K) },
|
|
|
|
{ INFO("is25lp080d", 0x9d6014, 0, 64 << 10, 16, ER_4K) },
|
|
|
|
{ INFO("is25lp016d", 0x9d6015, 0, 64 << 10, 32, ER_4K) },
|
|
|
|
{ INFO("is25lp032", 0x9d6016, 0, 64 << 10, 64, ER_4K) },
|
|
|
|
{ INFO("is25lp064", 0x9d6017, 0, 64 << 10, 128, ER_4K) },
|
|
|
|
{ INFO("is25lp128", 0x9d6018, 0, 64 << 10, 256, ER_4K) },
|
|
|
|
{ INFO("is25lp256", 0x9d6019, 0, 64 << 10, 512, ER_4K) },
|
|
|
|
{ INFO("is25wp032", 0x9d7016, 0, 64 << 10, 64, ER_4K) },
|
|
|
|
{ INFO("is25wp064", 0x9d7017, 0, 64 << 10, 128, ER_4K) },
|
|
|
|
{ INFO("is25wp128", 0x9d7018, 0, 64 << 10, 256, ER_4K) },
|
|
|
|
{ INFO("is25wp256", 0x9d7019, 0, 64 << 10, 512, ER_4K) },
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
/* Macronix */
|
2013-05-01 18:40:53 +04:00
|
|
|
{ INFO("mx25l2005a", 0xc22012, 0, 64 << 10, 4, ER_4K) },
|
2012-03-26 16:10:59 +04:00
|
|
|
{ INFO("mx25l4005a", 0xc22013, 0, 64 << 10, 8, ER_4K) },
|
|
|
|
{ INFO("mx25l8005", 0xc22014, 0, 64 << 10, 16, 0) },
|
|
|
|
{ INFO("mx25l1606e", 0xc22015, 0, 64 << 10, 32, ER_4K) },
|
|
|
|
{ INFO("mx25l3205d", 0xc22016, 0, 64 << 10, 64, 0) },
|
|
|
|
{ INFO("mx25l6405d", 0xc22017, 0, 64 << 10, 128, 0) },
|
|
|
|
{ INFO("mx25l12805d", 0xc22018, 0, 64 << 10, 256, 0) },
|
|
|
|
{ INFO("mx25l12855e", 0xc22618, 0, 64 << 10, 256, 0) },
|
2020-09-01 15:21:50 +03:00
|
|
|
{ INFO6("mx25l25635e", 0xc22019, 0xc22019, 64 << 10, 512, 0) },
|
2012-03-26 16:10:59 +04:00
|
|
|
{ INFO("mx25l25655e", 0xc22619, 0, 64 << 10, 512, 0) },
|
2020-09-01 15:21:51 +03:00
|
|
|
{ INFO("mx66l51235f", 0xc2201a, 0, 64 << 10, 1024, ER_4K | ER_32K) },
|
2016-06-27 17:37:34 +03:00
|
|
|
{ INFO("mx66u51235f", 0xc2253a, 0, 64 << 10, 1024, ER_4K | ER_32K) },
|
|
|
|
{ INFO("mx66u1g45g", 0xc2253b, 0, 64 << 10, 2048, ER_4K | ER_32K) },
|
2016-12-27 17:59:26 +03:00
|
|
|
{ INFO("mx66l1g45g", 0xc2201b, 0, 64 << 10, 2048, ER_4K | ER_32K) },
|
2012-03-26 16:10:59 +04:00
|
|
|
|
2013-05-01 18:40:53 +04:00
|
|
|
/* Micron */
|
2013-06-04 19:59:14 +04:00
|
|
|
{ INFO("n25q032a11", 0x20bb16, 0, 64 << 10, 64, ER_4K) },
|
|
|
|
{ INFO("n25q032a13", 0x20ba16, 0, 64 << 10, 64, ER_4K) },
|
|
|
|
{ INFO("n25q064a11", 0x20bb17, 0, 64 << 10, 128, ER_4K) },
|
|
|
|
{ INFO("n25q064a13", 0x20ba17, 0, 64 << 10, 128, ER_4K) },
|
|
|
|
{ INFO("n25q128a11", 0x20bb18, 0, 64 << 10, 256, ER_4K) },
|
|
|
|
{ INFO("n25q128a13", 0x20ba18, 0, 64 << 10, 256, ER_4K) },
|
|
|
|
{ INFO("n25q256a11", 0x20bb19, 0, 64 << 10, 512, ER_4K) },
|
|
|
|
{ INFO("n25q256a13", 0x20ba19, 0, 64 << 10, 512, ER_4K) },
|
2017-12-13 20:59:21 +03:00
|
|
|
{ INFO("n25q512a11", 0x20bb20, 0, 64 << 10, 1024, ER_4K) },
|
|
|
|
{ INFO("n25q512a13", 0x20ba20, 0, 64 << 10, 1024, ER_4K) },
|
2016-06-27 17:37:34 +03:00
|
|
|
{ INFO("n25q128", 0x20ba18, 0, 64 << 10, 256, 0) },
|
|
|
|
{ INFO("n25q256a", 0x20ba19, 0, 64 << 10, 512, ER_4K) },
|
|
|
|
{ INFO("n25q512a", 0x20ba20, 0, 64 << 10, 1024, ER_4K) },
|
2020-09-01 15:21:50 +03:00
|
|
|
{ INFO("n25q512ax3", 0x20ba20, 0x1000, 64 << 10, 1024, ER_4K) },
|
2020-09-01 15:21:51 +03:00
|
|
|
{ INFO("mt25ql512ab", 0x20ba20, 0x1044, 64 << 10, 1024, ER_4K | ER_32K) },
|
2017-01-20 14:15:07 +03:00
|
|
|
{ INFO_STACKED("n25q00", 0x20ba21, 0x1000, 64 << 10, 2048, ER_4K, 4) },
|
|
|
|
{ INFO_STACKED("n25q00a", 0x20bb21, 0x1000, 64 << 10, 2048, ER_4K, 4) },
|
|
|
|
{ INFO_STACKED("mt25ql01g", 0x20ba21, 0x1040, 64 << 10, 2048, ER_4K, 2) },
|
|
|
|
{ INFO_STACKED("mt25qu01g", 0x20bb21, 0x1040, 64 << 10, 2048, ER_4K, 2) },
|
2013-05-01 18:40:53 +04:00
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
/* Spansion -- single (large) sector size only, at least
|
|
|
|
* for the chips listed here (without boot sectors).
|
|
|
|
*/
|
|
|
|
{ INFO("s25sl032p", 0x010215, 0x4d00, 64 << 10, 64, ER_4K) },
|
2013-05-01 18:40:53 +04:00
|
|
|
{ INFO("s25sl064p", 0x010216, 0x4d00, 64 << 10, 128, ER_4K) },
|
2012-03-26 16:10:59 +04:00
|
|
|
{ INFO("s25fl256s0", 0x010219, 0x4d00, 256 << 10, 128, 0) },
|
|
|
|
{ INFO("s25fl256s1", 0x010219, 0x4d01, 64 << 10, 512, 0) },
|
2016-06-27 17:37:34 +03:00
|
|
|
{ INFO6("s25fl512s", 0x010220, 0x4d0080, 256 << 10, 256, 0) },
|
|
|
|
{ INFO6("s70fl01gs", 0x010221, 0x4d0080, 256 << 10, 512, 0) },
|
2012-03-26 16:10:59 +04:00
|
|
|
{ INFO("s25sl12800", 0x012018, 0x0300, 256 << 10, 64, 0) },
|
|
|
|
{ INFO("s25sl12801", 0x012018, 0x0301, 64 << 10, 256, 0) },
|
|
|
|
{ INFO("s25fl129p0", 0x012018, 0x4d00, 256 << 10, 64, 0) },
|
|
|
|
{ INFO("s25fl129p1", 0x012018, 0x4d01, 64 << 10, 256, 0) },
|
2013-05-01 18:40:53 +04:00
|
|
|
{ INFO("s25sl004a", 0x010212, 0, 64 << 10, 8, 0) },
|
|
|
|
{ INFO("s25sl008a", 0x010213, 0, 64 << 10, 16, 0) },
|
|
|
|
{ INFO("s25sl016a", 0x010214, 0, 64 << 10, 32, 0) },
|
|
|
|
{ INFO("s25sl032a", 0x010215, 0, 64 << 10, 64, 0) },
|
|
|
|
{ INFO("s25sl064a", 0x010216, 0, 64 << 10, 128, 0) },
|
2012-03-26 16:10:59 +04:00
|
|
|
{ INFO("s25fl016k", 0xef4015, 0, 64 << 10, 32, ER_4K | ER_32K) },
|
|
|
|
{ INFO("s25fl064k", 0xef4017, 0, 64 << 10, 128, ER_4K | ER_32K) },
|
|
|
|
|
2016-06-27 17:37:34 +03:00
|
|
|
/* Spansion -- boot sectors support */
|
|
|
|
{ INFO6("s25fs512s", 0x010220, 0x4d0081, 256 << 10, 256, 0) },
|
|
|
|
{ INFO6("s70fs01gs", 0x010221, 0x4d0081, 256 << 10, 512, 0) },
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
/* SST -- large erase sizes are "overlays", "sectors" are 4<< 10 */
|
|
|
|
{ INFO("sst25vf040b", 0xbf258d, 0, 64 << 10, 8, ER_4K) },
|
|
|
|
{ INFO("sst25vf080b", 0xbf258e, 0, 64 << 10, 16, ER_4K) },
|
|
|
|
{ INFO("sst25vf016b", 0xbf2541, 0, 64 << 10, 32, ER_4K) },
|
|
|
|
{ INFO("sst25vf032b", 0xbf254a, 0, 64 << 10, 64, ER_4K) },
|
|
|
|
{ INFO("sst25wf512", 0xbf2501, 0, 64 << 10, 1, ER_4K) },
|
|
|
|
{ INFO("sst25wf010", 0xbf2502, 0, 64 << 10, 2, ER_4K) },
|
|
|
|
{ INFO("sst25wf020", 0xbf2503, 0, 64 << 10, 4, ER_4K) },
|
|
|
|
{ INFO("sst25wf040", 0xbf2504, 0, 64 << 10, 8, ER_4K) },
|
2016-01-21 17:15:03 +03:00
|
|
|
{ INFO("sst25wf080", 0xbf2505, 0, 64 << 10, 16, ER_4K) },
|
2012-03-26 16:10:59 +04:00
|
|
|
|
|
|
|
/* ST Microelectronics -- newer production may have feature updates */
|
|
|
|
{ INFO("m25p05", 0x202010, 0, 32 << 10, 2, 0) },
|
|
|
|
{ INFO("m25p10", 0x202011, 0, 32 << 10, 4, 0) },
|
|
|
|
{ INFO("m25p20", 0x202012, 0, 64 << 10, 4, 0) },
|
|
|
|
{ INFO("m25p40", 0x202013, 0, 64 << 10, 8, 0) },
|
|
|
|
{ INFO("m25p80", 0x202014, 0, 64 << 10, 16, 0) },
|
|
|
|
{ INFO("m25p16", 0x202015, 0, 64 << 10, 32, 0) },
|
|
|
|
{ INFO("m25p32", 0x202016, 0, 64 << 10, 64, 0) },
|
|
|
|
{ INFO("m25p64", 0x202017, 0, 64 << 10, 128, 0) },
|
|
|
|
{ INFO("m25p128", 0x202018, 0, 256 << 10, 64, 0) },
|
2013-05-01 18:40:53 +04:00
|
|
|
{ INFO("n25q032", 0x20ba16, 0, 64 << 10, 64, 0) },
|
2012-03-26 16:10:59 +04:00
|
|
|
|
|
|
|
{ INFO("m45pe10", 0x204011, 0, 64 << 10, 2, 0) },
|
|
|
|
{ INFO("m45pe80", 0x204014, 0, 64 << 10, 16, 0) },
|
|
|
|
{ INFO("m45pe16", 0x204015, 0, 64 << 10, 32, 0) },
|
|
|
|
|
2013-05-01 18:40:53 +04:00
|
|
|
{ INFO("m25pe20", 0x208012, 0, 64 << 10, 4, 0) },
|
2012-03-26 16:10:59 +04:00
|
|
|
{ INFO("m25pe80", 0x208014, 0, 64 << 10, 16, 0) },
|
|
|
|
{ INFO("m25pe16", 0x208015, 0, 64 << 10, 32, ER_4K) },
|
|
|
|
|
|
|
|
{ INFO("m25px32", 0x207116, 0, 64 << 10, 64, ER_4K) },
|
|
|
|
{ INFO("m25px32-s0", 0x207316, 0, 64 << 10, 64, ER_4K) },
|
|
|
|
{ INFO("m25px32-s1", 0x206316, 0, 64 << 10, 64, ER_4K) },
|
|
|
|
{ INFO("m25px64", 0x207117, 0, 64 << 10, 128, 0) },
|
|
|
|
|
|
|
|
/* Winbond -- w25x "blocks" are 64k, "sectors" are 4KiB */
|
|
|
|
{ INFO("w25x10", 0xef3011, 0, 64 << 10, 2, ER_4K) },
|
|
|
|
{ INFO("w25x20", 0xef3012, 0, 64 << 10, 4, ER_4K) },
|
|
|
|
{ INFO("w25x40", 0xef3013, 0, 64 << 10, 8, ER_4K) },
|
|
|
|
{ INFO("w25x80", 0xef3014, 0, 64 << 10, 16, ER_4K) },
|
|
|
|
{ INFO("w25x16", 0xef3015, 0, 64 << 10, 32, ER_4K) },
|
|
|
|
{ INFO("w25x32", 0xef3016, 0, 64 << 10, 64, ER_4K) },
|
|
|
|
{ INFO("w25q32", 0xef4016, 0, 64 << 10, 64, ER_4K) },
|
2013-05-01 18:40:53 +04:00
|
|
|
{ INFO("w25q32dw", 0xef6016, 0, 64 << 10, 64, ER_4K) },
|
2012-03-26 16:10:59 +04:00
|
|
|
{ INFO("w25x64", 0xef3017, 0, 64 << 10, 128, ER_4K) },
|
|
|
|
{ INFO("w25q64", 0xef4017, 0, 64 << 10, 128, ER_4K) },
|
2013-05-01 18:40:53 +04:00
|
|
|
{ INFO("w25q80", 0xef5014, 0, 64 << 10, 16, ER_4K) },
|
|
|
|
{ INFO("w25q80bl", 0xef4014, 0, 64 << 10, 16, ER_4K) },
|
|
|
|
{ INFO("w25q256", 0xef4019, 0, 64 << 10, 512, ER_4K) },
|
2019-09-25 17:32:44 +03:00
|
|
|
{ INFO("w25q512jv", 0xef4020, 0, 64 << 10, 1024, ER_4K) },
|
2012-03-26 16:10:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
NOP = 0,
|
2013-02-04 13:56:25 +04:00
|
|
|
WRSR = 0x1,
|
2012-03-26 16:10:59 +04:00
|
|
|
WRDI = 0x4,
|
|
|
|
RDSR = 0x5,
|
|
|
|
WREN = 0x6,
|
2017-12-13 20:59:21 +03:00
|
|
|
BRRD = 0x16,
|
|
|
|
BRWR = 0x17,
|
2012-10-15 08:34:37 +04:00
|
|
|
JEDEC_READ = 0x9f,
|
2017-12-13 20:59:21 +03:00
|
|
|
BULK_ERASE_60 = 0x60,
|
2012-10-15 08:34:37 +04:00
|
|
|
BULK_ERASE = 0xc7,
|
2016-03-30 19:27:23 +03:00
|
|
|
READ_FSR = 0x70,
|
2016-06-27 17:37:34 +03:00
|
|
|
RDCR = 0x15,
|
2012-10-15 08:34:37 +04:00
|
|
|
|
2016-03-30 19:27:23 +03:00
|
|
|
READ = 0x03,
|
|
|
|
READ4 = 0x13,
|
|
|
|
FAST_READ = 0x0b,
|
|
|
|
FAST_READ4 = 0x0c,
|
2012-10-15 08:34:37 +04:00
|
|
|
DOR = 0x3b,
|
2016-03-30 19:27:23 +03:00
|
|
|
DOR4 = 0x3c,
|
2012-10-15 08:34:37 +04:00
|
|
|
QOR = 0x6b,
|
2016-03-30 19:27:23 +03:00
|
|
|
QOR4 = 0x6c,
|
2012-10-15 08:34:37 +04:00
|
|
|
DIOR = 0xbb,
|
2016-03-30 19:27:23 +03:00
|
|
|
DIOR4 = 0xbc,
|
2012-10-15 08:34:37 +04:00
|
|
|
QIOR = 0xeb,
|
2016-03-30 19:27:23 +03:00
|
|
|
QIOR4 = 0xec,
|
2012-10-15 08:34:37 +04:00
|
|
|
|
2016-03-30 19:27:23 +03:00
|
|
|
PP = 0x02,
|
|
|
|
PP4 = 0x12,
|
2016-06-27 17:37:33 +03:00
|
|
|
PP4_4 = 0x3e,
|
2012-10-15 08:34:37 +04:00
|
|
|
DPP = 0xa2,
|
|
|
|
QPP = 0x32,
|
2017-01-20 14:15:06 +03:00
|
|
|
QPP_4 = 0x34,
|
2017-12-13 20:59:21 +03:00
|
|
|
RDID_90 = 0x90,
|
|
|
|
RDID_AB = 0xab,
|
2020-12-23 05:00:25 +03:00
|
|
|
AAI_WP = 0xad,
|
2012-10-15 08:34:37 +04:00
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
ERASE_4K = 0x20,
|
2016-03-30 19:27:23 +03:00
|
|
|
ERASE4_4K = 0x21,
|
2012-03-26 16:10:59 +04:00
|
|
|
ERASE_32K = 0x52,
|
2016-06-27 17:37:33 +03:00
|
|
|
ERASE4_32K = 0x5c,
|
2012-03-26 16:10:59 +04:00
|
|
|
ERASE_SECTOR = 0xd8,
|
2016-03-30 19:27:23 +03:00
|
|
|
ERASE4_SECTOR = 0xdc,
|
2016-03-30 19:27:22 +03:00
|
|
|
|
2016-03-30 19:27:23 +03:00
|
|
|
EN_4BYTE_ADDR = 0xB7,
|
|
|
|
EX_4BYTE_ADDR = 0xE9,
|
|
|
|
|
2016-03-30 19:27:23 +03:00
|
|
|
EXTEND_ADDR_READ = 0xC8,
|
|
|
|
EXTEND_ADDR_WRITE = 0xC5,
|
|
|
|
|
2016-03-30 19:27:22 +03:00
|
|
|
RESET_ENABLE = 0x66,
|
|
|
|
RESET_MEMORY = 0x99,
|
2016-03-30 19:27:23 +03:00
|
|
|
|
2016-06-27 17:37:34 +03:00
|
|
|
/*
|
|
|
|
* Micron: 0x35 - enable QPI
|
|
|
|
* Spansion: 0x35 - read control register
|
|
|
|
*/
|
|
|
|
RDCR_EQIO = 0x35,
|
|
|
|
RSTQIO = 0xf5,
|
|
|
|
|
2016-03-30 19:27:23 +03:00
|
|
|
RNVCR = 0xB5,
|
|
|
|
WNVCR = 0xB1,
|
|
|
|
|
|
|
|
RVCR = 0x85,
|
|
|
|
WVCR = 0x81,
|
|
|
|
|
|
|
|
REVCR = 0x65,
|
|
|
|
WEVCR = 0x61,
|
2017-01-20 14:15:06 +03:00
|
|
|
|
|
|
|
DIE_ERASE = 0xC4,
|
2012-03-26 16:10:59 +04:00
|
|
|
} FlashCMD;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
STATE_IDLE,
|
|
|
|
STATE_PAGE_PROGRAM,
|
|
|
|
STATE_READ,
|
|
|
|
STATE_COLLECTING_DATA,
|
2016-06-27 17:37:33 +03:00
|
|
|
STATE_COLLECTING_VAR_LEN_DATA,
|
2012-03-26 16:10:59 +04:00
|
|
|
STATE_READING_DATA,
|
|
|
|
} CMDState;
|
|
|
|
|
2016-06-27 17:37:33 +03:00
|
|
|
typedef enum {
|
|
|
|
MAN_SPANSION,
|
|
|
|
MAN_MACRONIX,
|
|
|
|
MAN_NUMONYX,
|
|
|
|
MAN_WINBOND,
|
2017-12-13 20:59:21 +03:00
|
|
|
MAN_SST,
|
2021-01-26 08:59:59 +03:00
|
|
|
MAN_ISSI,
|
2016-06-27 17:37:33 +03:00
|
|
|
MAN_GENERIC,
|
|
|
|
} Manufacturer;
|
|
|
|
|
2020-11-17 02:11:03 +03:00
|
|
|
typedef enum {
|
|
|
|
MODE_STD = 0,
|
|
|
|
MODE_DIO = 1,
|
|
|
|
MODE_QIO = 2
|
|
|
|
} SPIMode;
|
|
|
|
|
2017-01-09 14:40:23 +03:00
|
|
|
#define M25P80_INTERNAL_DATA_BUFFER_SZ 16
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct Flash {
|
2020-10-12 15:49:55 +03:00
|
|
|
SSIPeripheral parent_obj;
|
2014-02-12 04:30:45 +04:00
|
|
|
|
2014-10-07 15:59:18 +04:00
|
|
|
BlockBackend *blk;
|
2012-03-26 16:10:59 +04:00
|
|
|
|
|
|
|
uint8_t *storage;
|
|
|
|
uint32_t size;
|
|
|
|
int page_size;
|
|
|
|
|
|
|
|
uint8_t state;
|
2017-01-09 14:40:23 +03:00
|
|
|
uint8_t data[M25P80_INTERNAL_DATA_BUFFER_SZ];
|
2012-03-26 16:10:59 +04:00
|
|
|
uint32_t len;
|
|
|
|
uint32_t pos;
|
2017-12-13 20:59:20 +03:00
|
|
|
bool data_read_loop;
|
2012-03-26 16:10:59 +04:00
|
|
|
uint8_t needed_bytes;
|
|
|
|
uint8_t cmd_in_progress;
|
2016-07-04 15:06:37 +03:00
|
|
|
uint32_t cur_addr;
|
2016-03-30 19:27:23 +03:00
|
|
|
uint32_t nonvolatile_cfg;
|
2016-06-27 17:37:34 +03:00
|
|
|
/* Configuration register for Macronix */
|
2016-03-30 19:27:23 +03:00
|
|
|
uint32_t volatile_cfg;
|
|
|
|
uint32_t enh_volatile_cfg;
|
2016-06-27 17:37:34 +03:00
|
|
|
/* Spansion cfg registers. */
|
|
|
|
uint8_t spansion_cr1nv;
|
|
|
|
uint8_t spansion_cr2nv;
|
|
|
|
uint8_t spansion_cr3nv;
|
|
|
|
uint8_t spansion_cr4nv;
|
|
|
|
uint8_t spansion_cr1v;
|
|
|
|
uint8_t spansion_cr2v;
|
|
|
|
uint8_t spansion_cr3v;
|
|
|
|
uint8_t spansion_cr4v;
|
2012-03-26 16:10:59 +04:00
|
|
|
bool write_enable;
|
2016-03-30 19:27:23 +03:00
|
|
|
bool four_bytes_address_mode;
|
2016-03-30 19:27:22 +03:00
|
|
|
bool reset_enable;
|
2016-06-27 17:37:34 +03:00
|
|
|
bool quad_enable;
|
2020-12-23 05:00:25 +03:00
|
|
|
bool aai_enable;
|
2016-03-30 19:27:23 +03:00
|
|
|
uint8_t ear;
|
2012-03-26 16:10:59 +04:00
|
|
|
|
|
|
|
int64_t dirty_page;
|
|
|
|
|
|
|
|
const FlashPartInfo *pi;
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2012-03-26 16:10:59 +04:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct M25P80Class {
|
2020-10-12 15:49:55 +03:00
|
|
|
SSIPeripheralClass parent_class;
|
2013-02-28 22:23:15 +04:00
|
|
|
FlashPartInfo *pi;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2013-02-28 22:23:15 +04:00
|
|
|
|
|
|
|
#define TYPE_M25P80 "m25p80-generic"
|
2020-09-16 21:25:18 +03:00
|
|
|
OBJECT_DECLARE_TYPE(Flash, M25P80Class, M25P80)
|
2013-02-28 22:23:15 +04:00
|
|
|
|
2016-06-27 17:37:33 +03:00
|
|
|
static inline Manufacturer get_man(Flash *s)
|
|
|
|
{
|
2016-06-27 17:37:33 +03:00
|
|
|
switch (s->pi->id[0]) {
|
2016-06-27 17:37:33 +03:00
|
|
|
case 0x20:
|
|
|
|
return MAN_NUMONYX;
|
|
|
|
case 0xEF:
|
|
|
|
return MAN_WINBOND;
|
|
|
|
case 0x01:
|
|
|
|
return MAN_SPANSION;
|
|
|
|
case 0xC2:
|
|
|
|
return MAN_MACRONIX;
|
2017-12-13 20:59:21 +03:00
|
|
|
case 0xBF:
|
|
|
|
return MAN_SST;
|
2021-01-26 08:59:59 +03:00
|
|
|
case 0x9D:
|
|
|
|
return MAN_ISSI;
|
2016-06-27 17:37:33 +03:00
|
|
|
default:
|
|
|
|
return MAN_GENERIC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-07 15:59:18 +04:00
|
|
|
static void blk_sync_complete(void *opaque, int ret)
|
2012-03-26 16:10:59 +04:00
|
|
|
{
|
2016-07-04 15:06:37 +03:00
|
|
|
QEMUIOVector *iov = opaque;
|
|
|
|
|
|
|
|
qemu_iovec_destroy(iov);
|
|
|
|
g_free(iov);
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
/* do nothing. Masters do not directly interact with the backing store,
|
|
|
|
* only the working copy so no mutexing required.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flash_sync_page(Flash *s, int page)
|
|
|
|
{
|
2016-07-07 15:47:01 +03:00
|
|
|
QEMUIOVector *iov;
|
2014-06-19 05:36:03 +04:00
|
|
|
|
2021-01-18 15:34:47 +03:00
|
|
|
if (!s->blk || !blk_is_writable(s->blk)) {
|
2014-06-19 05:36:03 +04:00
|
|
|
return;
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
2014-06-19 05:36:03 +04:00
|
|
|
|
2016-07-07 15:47:01 +03:00
|
|
|
iov = g_new(QEMUIOVector, 1);
|
2016-07-04 15:06:37 +03:00
|
|
|
qemu_iovec_init(iov, 1);
|
|
|
|
qemu_iovec_add(iov, s->storage + page * s->pi->page_size,
|
2016-05-06 19:26:40 +03:00
|
|
|
s->pi->page_size);
|
2016-07-04 15:06:37 +03:00
|
|
|
blk_aio_pwritev(s->blk, page * s->pi->page_size, iov, 0,
|
|
|
|
blk_sync_complete, iov);
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void flash_sync_area(Flash *s, int64_t off, int64_t len)
|
|
|
|
{
|
2016-07-07 15:47:01 +03:00
|
|
|
QEMUIOVector *iov;
|
2012-03-26 16:10:59 +04:00
|
|
|
|
2021-01-18 15:34:47 +03:00
|
|
|
if (!s->blk || !blk_is_writable(s->blk)) {
|
2012-03-26 16:10:59 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(!(len % BDRV_SECTOR_SIZE));
|
2016-07-07 15:47:01 +03:00
|
|
|
iov = g_new(QEMUIOVector, 1);
|
2016-07-04 15:06:37 +03:00
|
|
|
qemu_iovec_init(iov, 1);
|
|
|
|
qemu_iovec_add(iov, s->storage + off, len);
|
|
|
|
blk_aio_pwritev(s->blk, off, iov, 0, blk_sync_complete, iov);
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void flash_erase(Flash *s, int offset, FlashCMD cmd)
|
|
|
|
{
|
|
|
|
uint32_t len;
|
|
|
|
uint8_t capa_to_assert = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case ERASE_4K:
|
2016-03-30 19:27:23 +03:00
|
|
|
case ERASE4_4K:
|
2018-06-25 15:42:05 +03:00
|
|
|
len = 4 * KiB;
|
2012-03-26 16:10:59 +04:00
|
|
|
capa_to_assert = ER_4K;
|
|
|
|
break;
|
|
|
|
case ERASE_32K:
|
2016-06-27 17:37:33 +03:00
|
|
|
case ERASE4_32K:
|
2018-06-25 15:42:05 +03:00
|
|
|
len = 32 * KiB;
|
2012-03-26 16:10:59 +04:00
|
|
|
capa_to_assert = ER_32K;
|
|
|
|
break;
|
|
|
|
case ERASE_SECTOR:
|
2016-03-30 19:27:23 +03:00
|
|
|
case ERASE4_SECTOR:
|
2012-03-26 16:10:59 +04:00
|
|
|
len = s->pi->sector_size;
|
|
|
|
break;
|
|
|
|
case BULK_ERASE:
|
|
|
|
len = s->size;
|
|
|
|
break;
|
2017-01-20 14:15:06 +03:00
|
|
|
case DIE_ERASE:
|
|
|
|
if (s->pi->die_cnt) {
|
|
|
|
len = s->size / s->pi->die_cnt;
|
|
|
|
offset = offset & (~(len - 1));
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: die erase is not supported"
|
|
|
|
" by device\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2012-03-26 16:10:59 +04:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2020-03-16 18:52:23 +03:00
|
|
|
trace_m25p80_flash_erase(s, offset, len);
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
if ((s->pi->flags & capa_to_assert) != capa_to_assert) {
|
2013-04-16 04:33:32 +04:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: %d erase size not supported by"
|
|
|
|
" device\n", len);
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!s->write_enable) {
|
2013-04-16 04:33:32 +04:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: erase with write protect!\n");
|
2012-03-26 16:10:59 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
memset(s->storage + offset, 0xff, len);
|
|
|
|
flash_sync_area(s, offset, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void flash_sync_dirty(Flash *s, int64_t newpage)
|
|
|
|
{
|
|
|
|
if (s->dirty_page >= 0 && s->dirty_page != newpage) {
|
|
|
|
flash_sync_page(s, s->dirty_page);
|
|
|
|
s->dirty_page = newpage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
2016-07-04 15:06:37 +03:00
|
|
|
void flash_write8(Flash *s, uint32_t addr, uint8_t data)
|
2012-03-26 16:10:59 +04:00
|
|
|
{
|
2016-07-04 15:06:37 +03:00
|
|
|
uint32_t page = addr / s->pi->page_size;
|
2012-03-26 16:10:59 +04:00
|
|
|
uint8_t prev = s->storage[s->cur_addr];
|
|
|
|
|
|
|
|
if (!s->write_enable) {
|
2013-04-16 04:33:32 +04:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: write with write protect!\n");
|
2020-12-23 05:00:24 +03:00
|
|
|
return;
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((prev ^ data) & data) {
|
2020-03-16 18:52:23 +03:00
|
|
|
trace_m25p80_programming_zero_to_one(s, addr, prev, data);
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
|
|
|
|
2016-03-30 19:27:24 +03:00
|
|
|
if (s->pi->flags & EEPROM) {
|
2012-03-26 16:10:59 +04:00
|
|
|
s->storage[s->cur_addr] = data;
|
|
|
|
} else {
|
|
|
|
s->storage[s->cur_addr] &= data;
|
|
|
|
}
|
|
|
|
|
|
|
|
flash_sync_dirty(s, page);
|
|
|
|
s->dirty_page = page;
|
|
|
|
}
|
|
|
|
|
2016-03-30 19:27:23 +03:00
|
|
|
static inline int get_addr_length(Flash *s)
|
|
|
|
{
|
2016-03-30 19:27:24 +03:00
|
|
|
/* check if eeprom is in use */
|
|
|
|
if (s->pi->flags == EEPROM) {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2016-03-30 19:27:23 +03:00
|
|
|
switch (s->cmd_in_progress) {
|
|
|
|
case PP4:
|
2016-06-27 17:37:33 +03:00
|
|
|
case PP4_4:
|
2017-01-20 14:15:06 +03:00
|
|
|
case QPP_4:
|
2016-03-30 19:27:23 +03:00
|
|
|
case READ4:
|
|
|
|
case QIOR4:
|
|
|
|
case ERASE4_4K:
|
2016-06-27 17:37:33 +03:00
|
|
|
case ERASE4_32K:
|
2016-03-30 19:27:23 +03:00
|
|
|
case ERASE4_SECTOR:
|
|
|
|
case FAST_READ4:
|
|
|
|
case DOR4:
|
|
|
|
case QOR4:
|
|
|
|
case DIOR4:
|
|
|
|
return 4;
|
|
|
|
default:
|
|
|
|
return s->four_bytes_address_mode ? 4 : 3;
|
|
|
|
}
|
2016-03-30 19:27:23 +03:00
|
|
|
}
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
static void complete_collecting_data(Flash *s)
|
|
|
|
{
|
2016-07-04 15:06:37 +03:00
|
|
|
int i, n;
|
2016-03-30 19:27:23 +03:00
|
|
|
|
2016-07-04 15:06:37 +03:00
|
|
|
n = get_addr_length(s);
|
|
|
|
s->cur_addr = (n == 3 ? s->ear : 0);
|
|
|
|
for (i = 0; i < n; ++i) {
|
2016-03-30 19:27:23 +03:00
|
|
|
s->cur_addr <<= 8;
|
|
|
|
s->cur_addr |= s->data[i];
|
|
|
|
}
|
|
|
|
|
2016-07-04 15:06:37 +03:00
|
|
|
s->cur_addr &= s->size - 1;
|
2012-03-26 16:10:59 +04:00
|
|
|
|
2013-01-26 05:58:38 +04:00
|
|
|
s->state = STATE_IDLE;
|
|
|
|
|
2020-03-16 18:52:23 +03:00
|
|
|
trace_m25p80_complete_collecting(s, s->cmd_in_progress, n, s->ear,
|
|
|
|
s->cur_addr);
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
switch (s->cmd_in_progress) {
|
2012-10-15 08:34:37 +04:00
|
|
|
case DPP:
|
|
|
|
case QPP:
|
2017-01-20 14:15:06 +03:00
|
|
|
case QPP_4:
|
2012-03-26 16:10:59 +04:00
|
|
|
case PP:
|
2016-03-30 19:27:23 +03:00
|
|
|
case PP4:
|
2016-06-27 17:37:33 +03:00
|
|
|
case PP4_4:
|
2012-03-26 16:10:59 +04:00
|
|
|
s->state = STATE_PAGE_PROGRAM;
|
|
|
|
break;
|
2020-12-23 05:00:25 +03:00
|
|
|
case AAI_WP:
|
|
|
|
/* AAI programming starts from the even address */
|
|
|
|
s->cur_addr &= ~BIT(0);
|
|
|
|
s->state = STATE_PAGE_PROGRAM;
|
|
|
|
break;
|
2012-03-26 16:10:59 +04:00
|
|
|
case READ:
|
2016-03-30 19:27:23 +03:00
|
|
|
case READ4:
|
2012-03-26 16:10:59 +04:00
|
|
|
case FAST_READ:
|
2016-03-30 19:27:23 +03:00
|
|
|
case FAST_READ4:
|
2012-10-15 08:34:37 +04:00
|
|
|
case DOR:
|
2016-03-30 19:27:23 +03:00
|
|
|
case DOR4:
|
2012-10-15 08:34:37 +04:00
|
|
|
case QOR:
|
2016-03-30 19:27:23 +03:00
|
|
|
case QOR4:
|
2012-10-15 08:34:37 +04:00
|
|
|
case DIOR:
|
2016-03-30 19:27:23 +03:00
|
|
|
case DIOR4:
|
2012-10-15 08:34:37 +04:00
|
|
|
case QIOR:
|
2016-03-30 19:27:23 +03:00
|
|
|
case QIOR4:
|
2012-03-26 16:10:59 +04:00
|
|
|
s->state = STATE_READ;
|
|
|
|
break;
|
|
|
|
case ERASE_4K:
|
2016-03-30 19:27:23 +03:00
|
|
|
case ERASE4_4K:
|
2012-03-26 16:10:59 +04:00
|
|
|
case ERASE_32K:
|
2016-06-27 17:37:33 +03:00
|
|
|
case ERASE4_32K:
|
2012-03-26 16:10:59 +04:00
|
|
|
case ERASE_SECTOR:
|
2016-03-30 19:27:23 +03:00
|
|
|
case ERASE4_SECTOR:
|
2017-01-20 14:15:06 +03:00
|
|
|
case DIE_ERASE:
|
2012-03-26 16:10:59 +04:00
|
|
|
flash_erase(s, s->cur_addr, s->cmd_in_progress);
|
|
|
|
break;
|
2013-02-04 13:56:25 +04:00
|
|
|
case WRSR:
|
2016-06-27 17:37:34 +03:00
|
|
|
switch (get_man(s)) {
|
|
|
|
case MAN_SPANSION:
|
|
|
|
s->quad_enable = !!(s->data[1] & 0x02);
|
|
|
|
break;
|
2021-01-26 08:59:59 +03:00
|
|
|
case MAN_ISSI:
|
|
|
|
s->quad_enable = extract32(s->data[0], 6, 1);
|
|
|
|
break;
|
2016-06-27 17:37:34 +03:00
|
|
|
case MAN_MACRONIX:
|
|
|
|
s->quad_enable = extract32(s->data[0], 6, 1);
|
2016-06-27 17:37:34 +03:00
|
|
|
if (s->len > 1) {
|
2018-06-15 16:57:15 +03:00
|
|
|
s->volatile_cfg = s->data[1];
|
2016-06-27 17:37:34 +03:00
|
|
|
s->four_bytes_address_mode = extract32(s->data[1], 5, 1);
|
|
|
|
}
|
2016-06-27 17:37:34 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-02-04 13:56:25 +04:00
|
|
|
if (s->write_enable) {
|
|
|
|
s->write_enable = false;
|
|
|
|
}
|
|
|
|
break;
|
2017-12-13 20:59:21 +03:00
|
|
|
case BRWR:
|
2016-03-30 19:27:23 +03:00
|
|
|
case EXTEND_ADDR_WRITE:
|
|
|
|
s->ear = s->data[0];
|
|
|
|
break;
|
2016-03-30 19:27:23 +03:00
|
|
|
case WNVCR:
|
|
|
|
s->nonvolatile_cfg = s->data[0] | (s->data[1] << 8);
|
|
|
|
break;
|
|
|
|
case WVCR:
|
|
|
|
s->volatile_cfg = s->data[0];
|
|
|
|
break;
|
|
|
|
case WEVCR:
|
|
|
|
s->enh_volatile_cfg = s->data[0];
|
|
|
|
break;
|
2017-12-13 20:59:21 +03:00
|
|
|
case RDID_90:
|
|
|
|
case RDID_AB:
|
|
|
|
if (get_man(s) == MAN_SST) {
|
|
|
|
if (s->cur_addr <= 1) {
|
|
|
|
if (s->cur_addr) {
|
|
|
|
s->data[0] = s->pi->id[2];
|
|
|
|
s->data[1] = s->pi->id[0];
|
|
|
|
} else {
|
|
|
|
s->data[0] = s->pi->id[0];
|
|
|
|
s->data[1] = s->pi->id[2];
|
|
|
|
}
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 2;
|
|
|
|
s->data_read_loop = true;
|
|
|
|
s->state = STATE_READING_DATA;
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"M25P80: Invalid read id address\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"M25P80: Read id (command 0x90/0xAB) is not supported"
|
|
|
|
" by device\n");
|
|
|
|
}
|
|
|
|
break;
|
2012-03-26 16:10:59 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-30 19:27:22 +03:00
|
|
|
static void reset_memory(Flash *s)
|
|
|
|
{
|
|
|
|
s->cmd_in_progress = NOP;
|
|
|
|
s->cur_addr = 0;
|
2016-03-30 19:27:23 +03:00
|
|
|
s->ear = 0;
|
2016-03-30 19:27:23 +03:00
|
|
|
s->four_bytes_address_mode = false;
|
2016-03-30 19:27:22 +03:00
|
|
|
s->len = 0;
|
|
|
|
s->needed_bytes = 0;
|
|
|
|
s->pos = 0;
|
|
|
|
s->state = STATE_IDLE;
|
|
|
|
s->write_enable = false;
|
|
|
|
s->reset_enable = false;
|
2016-06-27 17:37:34 +03:00
|
|
|
s->quad_enable = false;
|
2020-12-23 05:00:25 +03:00
|
|
|
s->aai_enable = false;
|
2016-03-30 19:27:22 +03:00
|
|
|
|
2016-06-27 17:37:33 +03:00
|
|
|
switch (get_man(s)) {
|
|
|
|
case MAN_NUMONYX:
|
2016-03-30 19:27:23 +03:00
|
|
|
s->volatile_cfg = 0;
|
|
|
|
s->volatile_cfg |= VCFG_DUMMY;
|
|
|
|
s->volatile_cfg |= VCFG_WRAP_SEQUENTIAL;
|
|
|
|
if ((s->nonvolatile_cfg & NVCFG_XIP_MODE_MASK)
|
2020-11-17 02:11:02 +03:00
|
|
|
== NVCFG_XIP_MODE_DISABLED) {
|
2020-11-17 02:11:01 +03:00
|
|
|
s->volatile_cfg |= VCFG_XIP_MODE_DISABLED;
|
2016-03-30 19:27:23 +03:00
|
|
|
}
|
|
|
|
s->volatile_cfg |= deposit32(s->volatile_cfg,
|
|
|
|
VCFG_DUMMY_CLK_POS,
|
|
|
|
CFG_DUMMY_CLK_LEN,
|
|
|
|
extract32(s->nonvolatile_cfg,
|
|
|
|
NVCFG_DUMMY_CLK_POS,
|
|
|
|
CFG_DUMMY_CLK_LEN)
|
|
|
|
);
|
|
|
|
|
|
|
|
s->enh_volatile_cfg = 0;
|
2016-11-01 20:03:02 +03:00
|
|
|
s->enh_volatile_cfg |= EVCFG_OUT_DRIVER_STRENGTH_DEF;
|
2016-03-30 19:27:23 +03:00
|
|
|
s->enh_volatile_cfg |= EVCFG_VPP_ACCELERATOR;
|
|
|
|
s->enh_volatile_cfg |= EVCFG_RESET_HOLD_ENABLED;
|
|
|
|
if (s->nonvolatile_cfg & NVCFG_DUAL_IO_MASK) {
|
2020-11-17 02:11:01 +03:00
|
|
|
s->enh_volatile_cfg |= EVCFG_DUAL_IO_DISABLED;
|
2016-03-30 19:27:23 +03:00
|
|
|
}
|
|
|
|
if (s->nonvolatile_cfg & NVCFG_QUAD_IO_MASK) {
|
2020-11-17 02:11:01 +03:00
|
|
|
s->enh_volatile_cfg |= EVCFG_QUAD_IO_DISABLED;
|
2016-03-30 19:27:23 +03:00
|
|
|
}
|
|
|
|
if (!(s->nonvolatile_cfg & NVCFG_4BYTE_ADDR_MASK)) {
|
|
|
|
s->four_bytes_address_mode = true;
|
|
|
|
}
|
|
|
|
if (!(s->nonvolatile_cfg & NVCFG_LOWER_SEGMENT_MASK)) {
|
2016-06-27 17:37:33 +03:00
|
|
|
s->ear = s->size / MAX_3BYTES_SIZE - 1;
|
2016-03-30 19:27:23 +03:00
|
|
|
}
|
2016-06-27 17:37:33 +03:00
|
|
|
break;
|
2016-06-27 17:37:34 +03:00
|
|
|
case MAN_MACRONIX:
|
|
|
|
s->volatile_cfg = 0x7;
|
|
|
|
break;
|
|
|
|
case MAN_SPANSION:
|
|
|
|
s->spansion_cr1v = s->spansion_cr1nv;
|
|
|
|
s->spansion_cr2v = s->spansion_cr2nv;
|
|
|
|
s->spansion_cr3v = s->spansion_cr3nv;
|
|
|
|
s->spansion_cr4v = s->spansion_cr4nv;
|
|
|
|
s->quad_enable = extract32(s->spansion_cr1v,
|
|
|
|
SPANSION_QUAD_CFG_POS,
|
|
|
|
SPANSION_QUAD_CFG_LEN
|
|
|
|
);
|
|
|
|
s->four_bytes_address_mode = extract32(s->spansion_cr2v,
|
|
|
|
SPANSION_ADDR_LEN_POS,
|
|
|
|
SPANSION_ADDR_LEN_LEN
|
|
|
|
);
|
|
|
|
break;
|
2016-06-27 17:37:33 +03:00
|
|
|
default:
|
|
|
|
break;
|
2016-03-30 19:27:23 +03:00
|
|
|
}
|
|
|
|
|
2020-03-16 18:52:23 +03:00
|
|
|
trace_m25p80_reset_done(s);
|
2016-03-30 19:27:22 +03:00
|
|
|
}
|
|
|
|
|
2020-11-17 02:11:03 +03:00
|
|
|
static uint8_t numonyx_mode(Flash *s)
|
|
|
|
{
|
|
|
|
if (!(s->enh_volatile_cfg & EVCFG_QUAD_IO_DISABLED)) {
|
|
|
|
return MODE_QIO;
|
|
|
|
} else if (!(s->enh_volatile_cfg & EVCFG_DUAL_IO_DISABLED)) {
|
|
|
|
return MODE_DIO;
|
|
|
|
} else {
|
|
|
|
return MODE_STD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 02:11:04 +03:00
|
|
|
static uint8_t numonyx_extract_cfg_num_dummies(Flash *s)
|
|
|
|
{
|
|
|
|
uint8_t num_dummies;
|
|
|
|
uint8_t mode;
|
|
|
|
assert(get_man(s) == MAN_NUMONYX);
|
|
|
|
|
|
|
|
mode = numonyx_mode(s);
|
|
|
|
num_dummies = extract32(s->volatile_cfg, 4, 4);
|
|
|
|
|
|
|
|
if (num_dummies == 0x0 || num_dummies == 0xf) {
|
|
|
|
switch (s->cmd_in_progress) {
|
|
|
|
case QIOR:
|
|
|
|
case QIOR4:
|
|
|
|
num_dummies = 10;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
num_dummies = (mode == MODE_QIO) ? 10 : 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_dummies;
|
|
|
|
}
|
|
|
|
|
2016-06-27 17:37:34 +03:00
|
|
|
static void decode_fast_read_cmd(Flash *s)
|
|
|
|
{
|
|
|
|
s->needed_bytes = get_addr_length(s);
|
|
|
|
switch (get_man(s)) {
|
|
|
|
/* Dummy cycles - modeled with bytes writes instead of bits */
|
2016-06-27 17:37:34 +03:00
|
|
|
case MAN_WINBOND:
|
|
|
|
s->needed_bytes += 8;
|
|
|
|
break;
|
2016-06-27 17:37:34 +03:00
|
|
|
case MAN_NUMONYX:
|
2020-11-17 02:11:04 +03:00
|
|
|
s->needed_bytes += numonyx_extract_cfg_num_dummies(s);
|
2016-06-27 17:37:34 +03:00
|
|
|
break;
|
|
|
|
case MAN_MACRONIX:
|
|
|
|
if (extract32(s->volatile_cfg, 6, 2) == 1) {
|
|
|
|
s->needed_bytes += 6;
|
|
|
|
} else {
|
|
|
|
s->needed_bytes += 8;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MAN_SPANSION:
|
|
|
|
s->needed_bytes += extract32(s->spansion_cr2v,
|
|
|
|
SPANSION_DUMMY_CLK_POS,
|
|
|
|
SPANSION_DUMMY_CLK_LEN
|
|
|
|
);
|
|
|
|
break;
|
2021-01-26 08:59:59 +03:00
|
|
|
case MAN_ISSI:
|
|
|
|
/*
|
|
|
|
* The Fast Read instruction code is followed by address bytes and
|
|
|
|
* dummy cycles, transmitted via the SI line.
|
|
|
|
*
|
|
|
|
* The number of dummy cycles is configurable but this is currently
|
|
|
|
* unmodeled, hence the default value 8 is used.
|
|
|
|
*
|
|
|
|
* QPI (Quad Peripheral Interface) mode has different default value
|
|
|
|
* of dummy cycles, but this is unsupported at the time being.
|
|
|
|
*/
|
|
|
|
s->needed_bytes += 1;
|
|
|
|
break;
|
2016-06-27 17:37:34 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 0;
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void decode_dio_read_cmd(Flash *s)
|
|
|
|
{
|
|
|
|
s->needed_bytes = get_addr_length(s);
|
|
|
|
/* Dummy cycles modeled with bytes writes instead of bits */
|
|
|
|
switch (get_man(s)) {
|
|
|
|
case MAN_WINBOND:
|
2016-07-14 18:51:38 +03:00
|
|
|
s->needed_bytes += WINBOND_CONTINUOUS_READ_MODE_CMD_LEN;
|
2016-06-27 17:37:34 +03:00
|
|
|
break;
|
|
|
|
case MAN_SPANSION:
|
|
|
|
s->needed_bytes += SPANSION_CONTINUOUS_READ_MODE_CMD_LEN;
|
|
|
|
s->needed_bytes += extract32(s->spansion_cr2v,
|
|
|
|
SPANSION_DUMMY_CLK_POS,
|
|
|
|
SPANSION_DUMMY_CLK_LEN
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case MAN_NUMONYX:
|
2020-11-17 02:11:04 +03:00
|
|
|
s->needed_bytes += numonyx_extract_cfg_num_dummies(s);
|
2016-06-27 17:37:34 +03:00
|
|
|
break;
|
|
|
|
case MAN_MACRONIX:
|
|
|
|
switch (extract32(s->volatile_cfg, 6, 2)) {
|
|
|
|
case 1:
|
|
|
|
s->needed_bytes += 6;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
s->needed_bytes += 8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
s->needed_bytes += 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2021-01-26 08:59:59 +03:00
|
|
|
case MAN_ISSI:
|
|
|
|
/*
|
|
|
|
* The Fast Read Dual I/O instruction code is followed by address bytes
|
|
|
|
* and dummy cycles, transmitted via the IO1 and IO0 line.
|
|
|
|
*
|
|
|
|
* The number of dummy cycles is configurable but this is currently
|
|
|
|
* unmodeled, hence the default value 4 is used.
|
|
|
|
*/
|
|
|
|
s->needed_bytes += 1;
|
|
|
|
break;
|
2016-06-27 17:37:34 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 0;
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void decode_qio_read_cmd(Flash *s)
|
|
|
|
{
|
|
|
|
s->needed_bytes = get_addr_length(s);
|
|
|
|
/* Dummy cycles modeled with bytes writes instead of bits */
|
|
|
|
switch (get_man(s)) {
|
|
|
|
case MAN_WINBOND:
|
2016-07-14 18:51:38 +03:00
|
|
|
s->needed_bytes += WINBOND_CONTINUOUS_READ_MODE_CMD_LEN;
|
|
|
|
s->needed_bytes += 4;
|
2016-06-27 17:37:34 +03:00
|
|
|
break;
|
|
|
|
case MAN_SPANSION:
|
|
|
|
s->needed_bytes += SPANSION_CONTINUOUS_READ_MODE_CMD_LEN;
|
|
|
|
s->needed_bytes += extract32(s->spansion_cr2v,
|
|
|
|
SPANSION_DUMMY_CLK_POS,
|
|
|
|
SPANSION_DUMMY_CLK_LEN
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case MAN_NUMONYX:
|
2020-11-17 02:11:04 +03:00
|
|
|
s->needed_bytes += numonyx_extract_cfg_num_dummies(s);
|
2016-06-27 17:37:34 +03:00
|
|
|
break;
|
|
|
|
case MAN_MACRONIX:
|
|
|
|
switch (extract32(s->volatile_cfg, 6, 2)) {
|
|
|
|
case 1:
|
|
|
|
s->needed_bytes += 4;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
s->needed_bytes += 8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
s->needed_bytes += 6;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2021-01-26 08:59:59 +03:00
|
|
|
case MAN_ISSI:
|
|
|
|
/*
|
|
|
|
* The Fast Read Quad I/O instruction code is followed by address bytes
|
|
|
|
* and dummy cycles, transmitted via the IO3, IO2, IO1 and IO0 line.
|
|
|
|
*
|
|
|
|
* The number of dummy cycles is configurable but this is currently
|
|
|
|
* unmodeled, hence the default value 6 is used.
|
|
|
|
*
|
|
|
|
* QPI (Quad Peripheral Interface) mode has different default value
|
|
|
|
* of dummy cycles, but this is unsupported at the time being.
|
|
|
|
*/
|
|
|
|
s->needed_bytes += 3;
|
|
|
|
break;
|
2016-06-27 17:37:34 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 0;
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
}
|
|
|
|
|
2020-12-23 05:00:25 +03:00
|
|
|
static bool is_valid_aai_cmd(uint32_t cmd)
|
|
|
|
{
|
|
|
|
return cmd == AAI_WP || cmd == WRDI || cmd == RDSR;
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
static void decode_new_cmd(Flash *s, uint32_t value)
|
|
|
|
{
|
2016-06-27 17:37:33 +03:00
|
|
|
int i;
|
2020-03-16 18:52:23 +03:00
|
|
|
|
|
|
|
s->cmd_in_progress = value;
|
|
|
|
trace_m25p80_command_decoded(s, value);
|
2012-03-26 16:10:59 +04:00
|
|
|
|
2016-03-30 19:27:22 +03:00
|
|
|
if (value != RESET_MEMORY) {
|
|
|
|
s->reset_enable = false;
|
|
|
|
}
|
|
|
|
|
2020-12-23 05:00:25 +03:00
|
|
|
if (get_man(s) == MAN_SST && s->aai_enable && !is_valid_aai_cmd(value)) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"M25P80: Invalid cmd within AAI programming sequence");
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
switch (value) {
|
|
|
|
|
|
|
|
case ERASE_4K:
|
2016-03-30 19:27:23 +03:00
|
|
|
case ERASE4_4K:
|
2012-03-26 16:10:59 +04:00
|
|
|
case ERASE_32K:
|
2016-06-27 17:37:33 +03:00
|
|
|
case ERASE4_32K:
|
2012-03-26 16:10:59 +04:00
|
|
|
case ERASE_SECTOR:
|
2016-03-30 19:27:23 +03:00
|
|
|
case ERASE4_SECTOR:
|
2012-03-26 16:10:59 +04:00
|
|
|
case PP:
|
2016-03-30 19:27:23 +03:00
|
|
|
case PP4:
|
2017-01-20 14:15:06 +03:00
|
|
|
case DIE_ERASE:
|
2017-12-13 20:59:21 +03:00
|
|
|
case RDID_90:
|
|
|
|
case RDID_AB:
|
2016-03-30 19:27:23 +03:00
|
|
|
s->needed_bytes = get_addr_length(s);
|
2012-03-26 16:10:59 +04:00
|
|
|
s->pos = 0;
|
|
|
|
s->len = 0;
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
break;
|
2020-11-17 02:11:03 +03:00
|
|
|
case READ:
|
|
|
|
case READ4:
|
|
|
|
if (get_man(s) != MAN_NUMONYX || numonyx_mode(s) == MODE_STD) {
|
|
|
|
s->needed_bytes = get_addr_length(s);
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 0;
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Cannot execute cmd %x in "
|
|
|
|
"DIO or QIO mode\n", s->cmd_in_progress);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DPP:
|
|
|
|
if (get_man(s) != MAN_NUMONYX || numonyx_mode(s) != MODE_QIO) {
|
|
|
|
s->needed_bytes = get_addr_length(s);
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 0;
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Cannot execute cmd %x in "
|
|
|
|
"QIO mode\n", s->cmd_in_progress);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case QPP:
|
|
|
|
case QPP_4:
|
|
|
|
case PP4_4:
|
|
|
|
if (get_man(s) != MAN_NUMONYX || numonyx_mode(s) != MODE_DIO) {
|
|
|
|
s->needed_bytes = get_addr_length(s);
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 0;
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Cannot execute cmd %x in "
|
|
|
|
"DIO mode\n", s->cmd_in_progress);
|
|
|
|
}
|
|
|
|
break;
|
2012-03-26 16:10:59 +04:00
|
|
|
|
|
|
|
case FAST_READ:
|
2016-03-30 19:27:23 +03:00
|
|
|
case FAST_READ4:
|
2020-11-17 02:11:03 +03:00
|
|
|
decode_fast_read_cmd(s);
|
|
|
|
break;
|
2012-10-15 08:34:37 +04:00
|
|
|
case DOR:
|
2016-03-30 19:27:23 +03:00
|
|
|
case DOR4:
|
2020-11-17 02:11:03 +03:00
|
|
|
if (get_man(s) != MAN_NUMONYX || numonyx_mode(s) != MODE_QIO) {
|
|
|
|
decode_fast_read_cmd(s);
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Cannot execute cmd %x in "
|
|
|
|
"QIO mode\n", s->cmd_in_progress);
|
|
|
|
}
|
|
|
|
break;
|
2012-10-15 08:34:37 +04:00
|
|
|
case QOR:
|
2016-03-30 19:27:23 +03:00
|
|
|
case QOR4:
|
2020-11-17 02:11:03 +03:00
|
|
|
if (get_man(s) != MAN_NUMONYX || numonyx_mode(s) != MODE_DIO) {
|
|
|
|
decode_fast_read_cmd(s);
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Cannot execute cmd %x in "
|
|
|
|
"DIO mode\n", s->cmd_in_progress);
|
|
|
|
}
|
2012-03-26 16:10:59 +04:00
|
|
|
break;
|
|
|
|
|
2012-10-15 08:34:37 +04:00
|
|
|
case DIOR:
|
2016-03-30 19:27:23 +03:00
|
|
|
case DIOR4:
|
2020-11-17 02:11:03 +03:00
|
|
|
if (get_man(s) != MAN_NUMONYX || numonyx_mode(s) != MODE_QIO) {
|
|
|
|
decode_dio_read_cmd(s);
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Cannot execute cmd %x in "
|
|
|
|
"QIO mode\n", s->cmd_in_progress);
|
|
|
|
}
|
2012-10-15 08:34:37 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QIOR:
|
2016-03-30 19:27:23 +03:00
|
|
|
case QIOR4:
|
2020-11-17 02:11:03 +03:00
|
|
|
if (get_man(s) != MAN_NUMONYX || numonyx_mode(s) != MODE_DIO) {
|
|
|
|
decode_qio_read_cmd(s);
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Cannot execute cmd %x in "
|
|
|
|
"DIO mode\n", s->cmd_in_progress);
|
|
|
|
}
|
2012-10-15 08:34:37 +04:00
|
|
|
break;
|
|
|
|
|
2013-02-04 13:56:25 +04:00
|
|
|
case WRSR:
|
|
|
|
if (s->write_enable) {
|
2016-06-27 17:37:34 +03:00
|
|
|
switch (get_man(s)) {
|
|
|
|
case MAN_SPANSION:
|
|
|
|
s->needed_bytes = 2;
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
break;
|
|
|
|
case MAN_MACRONIX:
|
|
|
|
s->needed_bytes = 2;
|
|
|
|
s->state = STATE_COLLECTING_VAR_LEN_DATA;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
s->needed_bytes = 1;
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
}
|
2013-02-04 13:56:25 +04:00
|
|
|
s->pos = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
case WRDI:
|
|
|
|
s->write_enable = false;
|
2020-12-23 05:00:25 +03:00
|
|
|
if (get_man(s) == MAN_SST) {
|
|
|
|
s->aai_enable = false;
|
|
|
|
}
|
2012-03-26 16:10:59 +04:00
|
|
|
break;
|
|
|
|
case WREN:
|
|
|
|
s->write_enable = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDSR:
|
|
|
|
s->data[0] = (!!s->write_enable) << 1;
|
2021-01-26 08:59:59 +03:00
|
|
|
if (get_man(s) == MAN_MACRONIX || get_man(s) == MAN_ISSI) {
|
2016-06-27 17:37:34 +03:00
|
|
|
s->data[0] |= (!!s->quad_enable) << 6;
|
|
|
|
}
|
2020-12-23 05:00:25 +03:00
|
|
|
if (get_man(s) == MAN_SST) {
|
|
|
|
s->data[0] |= (!!s->aai_enable) << 6;
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
s->pos = 0;
|
|
|
|
s->len = 1;
|
2017-12-13 20:59:20 +03:00
|
|
|
s->data_read_loop = true;
|
2012-03-26 16:10:59 +04:00
|
|
|
s->state = STATE_READING_DATA;
|
|
|
|
break;
|
|
|
|
|
2016-03-30 19:27:23 +03:00
|
|
|
case READ_FSR:
|
|
|
|
s->data[0] = FSR_FLASH_READY;
|
|
|
|
if (s->four_bytes_address_mode) {
|
|
|
|
s->data[0] |= FSR_4BYTE_ADDR_MODE_ENABLED;
|
|
|
|
}
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 1;
|
2017-12-13 20:59:20 +03:00
|
|
|
s->data_read_loop = true;
|
2016-03-30 19:27:23 +03:00
|
|
|
s->state = STATE_READING_DATA;
|
|
|
|
break;
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
case JEDEC_READ:
|
2020-11-17 02:11:03 +03:00
|
|
|
if (get_man(s) != MAN_NUMONYX || numonyx_mode(s) == MODE_STD) {
|
|
|
|
trace_m25p80_populated_jedec(s);
|
|
|
|
for (i = 0; i < s->pi->id_len; i++) {
|
|
|
|
s->data[i] = s->pi->id[i];
|
|
|
|
}
|
|
|
|
for (; i < SPI_NOR_MAX_ID_LEN; i++) {
|
|
|
|
s->data[i] = 0;
|
|
|
|
}
|
2016-06-27 17:37:33 +03:00
|
|
|
|
2020-11-17 02:11:03 +03:00
|
|
|
s->len = SPI_NOR_MAX_ID_LEN;
|
|
|
|
s->pos = 0;
|
|
|
|
s->state = STATE_READING_DATA;
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Cannot execute JEDEC read "
|
|
|
|
"in DIO or QIO mode\n");
|
|
|
|
}
|
2012-03-26 16:10:59 +04:00
|
|
|
break;
|
|
|
|
|
2016-06-27 17:37:34 +03:00
|
|
|
case RDCR:
|
|
|
|
s->data[0] = s->volatile_cfg & 0xFF;
|
|
|
|
s->data[0] |= (!!s->four_bytes_address_mode) << 5;
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 1;
|
|
|
|
s->state = STATE_READING_DATA;
|
|
|
|
break;
|
|
|
|
|
2017-12-13 20:59:21 +03:00
|
|
|
case BULK_ERASE_60:
|
2012-03-26 16:10:59 +04:00
|
|
|
case BULK_ERASE:
|
|
|
|
if (s->write_enable) {
|
2020-03-16 18:52:23 +03:00
|
|
|
trace_m25p80_chip_erase(s);
|
2012-03-26 16:10:59 +04:00
|
|
|
flash_erase(s, 0, BULK_ERASE);
|
|
|
|
} else {
|
2013-04-16 04:33:32 +04:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: chip erase with write "
|
|
|
|
"protect!\n");
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NOP:
|
|
|
|
break;
|
2016-03-30 19:27:23 +03:00
|
|
|
case EN_4BYTE_ADDR:
|
|
|
|
s->four_bytes_address_mode = true;
|
|
|
|
break;
|
|
|
|
case EX_4BYTE_ADDR:
|
|
|
|
s->four_bytes_address_mode = false;
|
|
|
|
break;
|
2017-12-13 20:59:21 +03:00
|
|
|
case BRRD:
|
2016-03-30 19:27:23 +03:00
|
|
|
case EXTEND_ADDR_READ:
|
|
|
|
s->data[0] = s->ear;
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 1;
|
|
|
|
s->state = STATE_READING_DATA;
|
|
|
|
break;
|
2017-12-13 20:59:21 +03:00
|
|
|
case BRWR:
|
2016-03-30 19:27:23 +03:00
|
|
|
case EXTEND_ADDR_WRITE:
|
|
|
|
if (s->write_enable) {
|
|
|
|
s->needed_bytes = 1;
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 0;
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
}
|
|
|
|
break;
|
2016-03-30 19:27:23 +03:00
|
|
|
case RNVCR:
|
|
|
|
s->data[0] = s->nonvolatile_cfg & 0xFF;
|
|
|
|
s->data[1] = (s->nonvolatile_cfg >> 8) & 0xFF;
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 2;
|
|
|
|
s->state = STATE_READING_DATA;
|
|
|
|
break;
|
|
|
|
case WNVCR:
|
2016-06-27 17:37:34 +03:00
|
|
|
if (s->write_enable && get_man(s) == MAN_NUMONYX) {
|
2016-03-30 19:27:23 +03:00
|
|
|
s->needed_bytes = 2;
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 0;
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RVCR:
|
|
|
|
s->data[0] = s->volatile_cfg & 0xFF;
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 1;
|
|
|
|
s->state = STATE_READING_DATA;
|
|
|
|
break;
|
|
|
|
case WVCR:
|
|
|
|
if (s->write_enable) {
|
|
|
|
s->needed_bytes = 1;
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 0;
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case REVCR:
|
|
|
|
s->data[0] = s->enh_volatile_cfg & 0xFF;
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 1;
|
|
|
|
s->state = STATE_READING_DATA;
|
|
|
|
break;
|
|
|
|
case WEVCR:
|
|
|
|
if (s->write_enable) {
|
|
|
|
s->needed_bytes = 1;
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 0;
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
}
|
|
|
|
break;
|
2016-03-30 19:27:22 +03:00
|
|
|
case RESET_ENABLE:
|
|
|
|
s->reset_enable = true;
|
|
|
|
break;
|
|
|
|
case RESET_MEMORY:
|
|
|
|
if (s->reset_enable) {
|
|
|
|
reset_memory(s);
|
|
|
|
}
|
|
|
|
break;
|
2016-06-27 17:37:34 +03:00
|
|
|
case RDCR_EQIO:
|
|
|
|
switch (get_man(s)) {
|
|
|
|
case MAN_SPANSION:
|
|
|
|
s->data[0] = (!!s->quad_enable) << 1;
|
|
|
|
s->pos = 0;
|
|
|
|
s->len = 1;
|
|
|
|
s->state = STATE_READING_DATA;
|
|
|
|
break;
|
|
|
|
case MAN_MACRONIX:
|
|
|
|
s->quad_enable = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RSTQIO:
|
|
|
|
s->quad_enable = false;
|
|
|
|
break;
|
2020-12-23 05:00:25 +03:00
|
|
|
case AAI_WP:
|
|
|
|
if (get_man(s) == MAN_SST) {
|
|
|
|
if (s->write_enable) {
|
|
|
|
if (s->aai_enable) {
|
|
|
|
s->state = STATE_PAGE_PROGRAM;
|
|
|
|
} else {
|
|
|
|
s->aai_enable = true;
|
|
|
|
s->needed_bytes = get_addr_length(s);
|
|
|
|
s->state = STATE_COLLECTING_DATA;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"M25P80: AAI_WP with write protect\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Unknown cmd %x\n", value);
|
|
|
|
}
|
|
|
|
break;
|
2012-03-26 16:10:59 +04:00
|
|
|
default:
|
2020-03-16 18:52:24 +03:00
|
|
|
s->pos = 0;
|
|
|
|
s->len = 1;
|
|
|
|
s->state = STATE_READING_DATA;
|
|
|
|
s->data_read_loop = true;
|
|
|
|
s->data[0] = 0;
|
2013-04-16 04:33:32 +04:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Unknown cmd %x\n", value);
|
2012-03-26 16:10:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-12 15:49:55 +03:00
|
|
|
static int m25p80_cs(SSIPeripheral *ss, bool select)
|
2012-03-26 16:10:59 +04:00
|
|
|
{
|
2014-02-12 04:30:45 +04:00
|
|
|
Flash *s = M25P80(ss);
|
2012-03-26 16:10:59 +04:00
|
|
|
|
|
|
|
if (select) {
|
2016-06-27 17:37:33 +03:00
|
|
|
if (s->state == STATE_COLLECTING_VAR_LEN_DATA) {
|
|
|
|
complete_collecting_data(s);
|
|
|
|
}
|
2012-03-26 16:10:59 +04:00
|
|
|
s->len = 0;
|
|
|
|
s->pos = 0;
|
|
|
|
s->state = STATE_IDLE;
|
|
|
|
flash_sync_dirty(s, -1);
|
2017-12-13 20:59:20 +03:00
|
|
|
s->data_read_loop = false;
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
|
|
|
|
2020-03-16 18:52:23 +03:00
|
|
|
trace_m25p80_select(s, select ? "de" : "");
|
2012-03-26 16:10:59 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-12 15:49:55 +03:00
|
|
|
static uint32_t m25p80_transfer8(SSIPeripheral *ss, uint32_t tx)
|
2012-03-26 16:10:59 +04:00
|
|
|
{
|
2014-02-12 04:30:45 +04:00
|
|
|
Flash *s = M25P80(ss);
|
2012-03-26 16:10:59 +04:00
|
|
|
uint32_t r = 0;
|
|
|
|
|
2020-03-16 18:52:23 +03:00
|
|
|
trace_m25p80_transfer(s, s->state, s->len, s->needed_bytes, s->pos,
|
|
|
|
s->cur_addr, (uint8_t)tx);
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
switch (s->state) {
|
|
|
|
|
|
|
|
case STATE_PAGE_PROGRAM:
|
2020-03-16 18:52:23 +03:00
|
|
|
trace_m25p80_page_program(s, s->cur_addr, (uint8_t)tx);
|
2012-03-26 16:10:59 +04:00
|
|
|
flash_write8(s, s->cur_addr, (uint8_t)tx);
|
2016-07-04 15:06:37 +03:00
|
|
|
s->cur_addr = (s->cur_addr + 1) & (s->size - 1);
|
2020-12-23 05:00:25 +03:00
|
|
|
|
|
|
|
if (get_man(s) == MAN_SST && s->aai_enable && s->cur_addr == 0) {
|
|
|
|
/*
|
|
|
|
* There is no wrap mode during AAI programming once the highest
|
|
|
|
* unprotected memory address is reached. The Write-Enable-Latch
|
|
|
|
* bit is automatically reset, and AAI programming mode aborts.
|
|
|
|
*/
|
|
|
|
s->write_enable = false;
|
|
|
|
s->aai_enable = false;
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_READ:
|
|
|
|
r = s->storage[s->cur_addr];
|
2020-03-16 18:52:23 +03:00
|
|
|
trace_m25p80_read_byte(s, s->cur_addr, (uint8_t)r);
|
2016-07-04 15:06:37 +03:00
|
|
|
s->cur_addr = (s->cur_addr + 1) & (s->size - 1);
|
2012-03-26 16:10:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_COLLECTING_DATA:
|
2016-06-27 17:37:33 +03:00
|
|
|
case STATE_COLLECTING_VAR_LEN_DATA:
|
2017-01-09 14:40:23 +03:00
|
|
|
|
|
|
|
if (s->len >= M25P80_INTERNAL_DATA_BUFFER_SZ) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"M25P80: Write overrun internal data buffer. "
|
|
|
|
"SPI controller (QEMU emulator or guest driver) "
|
|
|
|
"is misbehaving\n");
|
|
|
|
s->len = s->pos = 0;
|
|
|
|
s->state = STATE_IDLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
s->data[s->len] = (uint8_t)tx;
|
|
|
|
s->len++;
|
|
|
|
|
|
|
|
if (s->len == s->needed_bytes) {
|
|
|
|
complete_collecting_data(s);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_READING_DATA:
|
2017-01-09 14:40:23 +03:00
|
|
|
|
|
|
|
if (s->pos >= M25P80_INTERNAL_DATA_BUFFER_SZ) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"M25P80: Read overrun internal data buffer. "
|
|
|
|
"SPI controller (QEMU emulator or guest driver) "
|
|
|
|
"is misbehaving\n");
|
|
|
|
s->len = s->pos = 0;
|
|
|
|
s->state = STATE_IDLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
r = s->data[s->pos];
|
2020-03-16 18:52:23 +03:00
|
|
|
trace_m25p80_read_data(s, s->pos, (uint8_t)r);
|
2012-03-26 16:10:59 +04:00
|
|
|
s->pos++;
|
|
|
|
if (s->pos == s->len) {
|
|
|
|
s->pos = 0;
|
2017-12-13 20:59:20 +03:00
|
|
|
if (!s->data_read_loop) {
|
|
|
|
s->state = STATE_IDLE;
|
|
|
|
}
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case STATE_IDLE:
|
|
|
|
decode_new_cmd(s, (uint8_t)tx);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2020-10-12 15:49:55 +03:00
|
|
|
static void m25p80_realize(SSIPeripheral *ss, Error **errp)
|
2012-03-26 16:10:59 +04:00
|
|
|
{
|
2014-02-12 04:30:45 +04:00
|
|
|
Flash *s = M25P80(ss);
|
2013-02-28 22:23:15 +04:00
|
|
|
M25P80Class *mc = M25P80_GET_CLASS(s);
|
2017-01-24 15:43:31 +03:00
|
|
|
int ret;
|
2012-03-26 16:10:59 +04:00
|
|
|
|
2013-02-28 22:23:15 +04:00
|
|
|
s->pi = mc->pi;
|
2012-03-26 16:10:59 +04:00
|
|
|
|
|
|
|
s->size = s->pi->sector_size * s->pi->n_sectors;
|
|
|
|
s->dirty_page = -1;
|
|
|
|
|
2016-07-04 15:06:37 +03:00
|
|
|
if (s->blk) {
|
2017-01-24 15:43:31 +03:00
|
|
|
uint64_t perm = BLK_PERM_CONSISTENT_READ |
|
2021-01-18 15:34:47 +03:00
|
|
|
(blk_supports_write_perm(s->blk) ? BLK_PERM_WRITE : 0);
|
2017-01-24 15:43:31 +03:00
|
|
|
ret = blk_set_perm(s->blk, perm, BLK_PERM_ALL, errp);
|
|
|
|
if (ret < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-16 18:52:23 +03:00
|
|
|
trace_m25p80_binding(s);
|
2015-04-15 12:43:44 +03:00
|
|
|
s->storage = blk_blockalign(s->blk, s->size);
|
|
|
|
|
2016-05-31 14:36:05 +03:00
|
|
|
if (blk_pread(s->blk, 0, s->storage, s->size) != s->size) {
|
2016-07-04 15:06:37 +03:00
|
|
|
error_setg(errp, "failed to read the initial flash content");
|
|
|
|
return;
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-16 18:52:23 +03:00
|
|
|
trace_m25p80_binding_no_bdrv(s);
|
2015-04-15 12:43:44 +03:00
|
|
|
s->storage = blk_blockalign(NULL, s->size);
|
2012-03-26 16:10:59 +04:00
|
|
|
memset(s->storage, 0xFF, s->size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-30 19:27:22 +03:00
|
|
|
static void m25p80_reset(DeviceState *d)
|
|
|
|
{
|
|
|
|
Flash *s = M25P80(d);
|
|
|
|
|
|
|
|
reset_memory(s);
|
|
|
|
}
|
|
|
|
|
2017-09-25 14:29:12 +03:00
|
|
|
static int m25p80_pre_save(void *opaque)
|
2012-03-26 16:10:59 +04:00
|
|
|
{
|
|
|
|
flash_sync_dirty((Flash *)opaque, -1);
|
2017-09-25 14:29:12 +03:00
|
|
|
|
|
|
|
return 0;
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
|
|
|
|
2016-03-30 19:27:23 +03:00
|
|
|
static Property m25p80_properties[] = {
|
2016-06-27 17:37:34 +03:00
|
|
|
/* This is default value for Micron flash */
|
2016-03-30 19:27:23 +03:00
|
|
|
DEFINE_PROP_UINT32("nonvolatile-cfg", Flash, nonvolatile_cfg, 0x8FFF),
|
2016-06-27 17:37:34 +03:00
|
|
|
DEFINE_PROP_UINT8("spansion-cr1nv", Flash, spansion_cr1nv, 0x0),
|
|
|
|
DEFINE_PROP_UINT8("spansion-cr2nv", Flash, spansion_cr2nv, 0x8),
|
|
|
|
DEFINE_PROP_UINT8("spansion-cr3nv", Flash, spansion_cr3nv, 0x2),
|
|
|
|
DEFINE_PROP_UINT8("spansion-cr4nv", Flash, spansion_cr4nv, 0x10),
|
2016-07-04 15:06:37 +03:00
|
|
|
DEFINE_PROP_DRIVE("drive", Flash, blk),
|
2016-03-30 19:27:23 +03:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2017-12-13 20:59:20 +03:00
|
|
|
static int m25p80_pre_load(void *opaque)
|
|
|
|
{
|
|
|
|
Flash *s = (Flash *)opaque;
|
|
|
|
|
|
|
|
s->data_read_loop = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool m25p80_data_read_loop_needed(void *opaque)
|
|
|
|
{
|
|
|
|
Flash *s = (Flash *)opaque;
|
|
|
|
|
|
|
|
return s->data_read_loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_m25p80_data_read_loop = {
|
|
|
|
.name = "m25p80/data_read_loop",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = m25p80_data_read_loop_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_BOOL(data_read_loop, Flash),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-23 05:00:25 +03:00
|
|
|
static bool m25p80_aai_enable_needed(void *opaque)
|
|
|
|
{
|
|
|
|
Flash *s = (Flash *)opaque;
|
|
|
|
|
|
|
|
return s->aai_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_m25p80_aai_enable = {
|
|
|
|
.name = "m25p80/aai_enable",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = m25p80_aai_enable_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_BOOL(aai_enable, Flash),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
static const VMStateDescription vmstate_m25p80 = {
|
2016-09-06 21:52:18 +03:00
|
|
|
.name = "m25p80",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
2012-03-26 16:10:59 +04:00
|
|
|
.pre_save = m25p80_pre_save,
|
2017-12-13 20:59:20 +03:00
|
|
|
.pre_load = m25p80_pre_load,
|
2012-03-26 16:10:59 +04:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT8(state, Flash),
|
2017-01-09 14:40:23 +03:00
|
|
|
VMSTATE_UINT8_ARRAY(data, Flash, M25P80_INTERNAL_DATA_BUFFER_SZ),
|
2012-03-26 16:10:59 +04:00
|
|
|
VMSTATE_UINT32(len, Flash),
|
|
|
|
VMSTATE_UINT32(pos, Flash),
|
|
|
|
VMSTATE_UINT8(needed_bytes, Flash),
|
|
|
|
VMSTATE_UINT8(cmd_in_progress, Flash),
|
2016-07-04 15:06:37 +03:00
|
|
|
VMSTATE_UINT32(cur_addr, Flash),
|
2012-03-26 16:10:59 +04:00
|
|
|
VMSTATE_BOOL(write_enable, Flash),
|
2016-09-06 21:52:18 +03:00
|
|
|
VMSTATE_BOOL(reset_enable, Flash),
|
|
|
|
VMSTATE_UINT8(ear, Flash),
|
|
|
|
VMSTATE_BOOL(four_bytes_address_mode, Flash),
|
|
|
|
VMSTATE_UINT32(nonvolatile_cfg, Flash),
|
|
|
|
VMSTATE_UINT32(volatile_cfg, Flash),
|
|
|
|
VMSTATE_UINT32(enh_volatile_cfg, Flash),
|
|
|
|
VMSTATE_BOOL(quad_enable, Flash),
|
|
|
|
VMSTATE_UINT8(spansion_cr1nv, Flash),
|
|
|
|
VMSTATE_UINT8(spansion_cr2nv, Flash),
|
|
|
|
VMSTATE_UINT8(spansion_cr3nv, Flash),
|
|
|
|
VMSTATE_UINT8(spansion_cr4nv, Flash),
|
2012-03-26 16:10:59 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
2017-12-13 20:59:20 +03:00
|
|
|
},
|
|
|
|
.subsections = (const VMStateDescription * []) {
|
|
|
|
&vmstate_m25p80_data_read_loop,
|
2020-12-23 05:00:25 +03:00
|
|
|
&vmstate_m25p80_aai_enable,
|
2017-12-13 20:59:20 +03:00
|
|
|
NULL
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void m25p80_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2020-10-12 15:49:55 +03:00
|
|
|
SSIPeripheralClass *k = SSI_PERIPHERAL_CLASS(klass);
|
2013-02-28 22:23:15 +04:00
|
|
|
M25P80Class *mc = M25P80_CLASS(klass);
|
2012-03-26 16:10:59 +04:00
|
|
|
|
2016-07-04 15:06:37 +03:00
|
|
|
k->realize = m25p80_realize;
|
2012-03-26 16:10:59 +04:00
|
|
|
k->transfer = m25p80_transfer8;
|
|
|
|
k->set_cs = m25p80_cs;
|
|
|
|
k->cs_polarity = SSI_CS_LOW;
|
|
|
|
dc->vmsd = &vmstate_m25p80;
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, m25p80_properties);
|
2016-03-30 19:27:22 +03:00
|
|
|
dc->reset = m25p80_reset;
|
2013-02-28 22:23:15 +04:00
|
|
|
mc->pi = data;
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo m25p80_info = {
|
2013-02-28 22:23:15 +04:00
|
|
|
.name = TYPE_M25P80,
|
2020-10-12 15:49:55 +03:00
|
|
|
.parent = TYPE_SSI_PERIPHERAL,
|
2012-03-26 16:10:59 +04:00
|
|
|
.instance_size = sizeof(Flash),
|
2013-02-28 22:23:15 +04:00
|
|
|
.class_size = sizeof(M25P80Class),
|
|
|
|
.abstract = true,
|
2012-03-26 16:10:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void m25p80_register_types(void)
|
|
|
|
{
|
2013-02-28 22:23:15 +04:00
|
|
|
int i;
|
|
|
|
|
2012-03-26 16:10:59 +04:00
|
|
|
type_register_static(&m25p80_info);
|
2013-02-28 22:23:15 +04:00
|
|
|
for (i = 0; i < ARRAY_SIZE(known_devices); ++i) {
|
|
|
|
TypeInfo ti = {
|
|
|
|
.name = known_devices[i].part_name,
|
|
|
|
.parent = TYPE_M25P80,
|
|
|
|
.class_init = m25p80_class_init,
|
|
|
|
.class_data = (void *)&known_devices[i],
|
|
|
|
};
|
|
|
|
type_register(&ti);
|
|
|
|
}
|
2012-03-26 16:10:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(m25p80_register_types)
|