qemu/hw/block
Peter Maydell feb0b1aa11 pflash_cfi01: fix per-device sector length in CFI table
For configurations of the pflash_cfi01 device which set it up with a
device-width not equal to the width (ie where we are emulating
multiple narrow flash devices wired up in parallel), we were giving
incorrect values in the CFI data table:

(1) the sector length entry should specify the sector length for a
    single device, not the length for the overall collection of
    devices
(2) the number of blocks per device must not be divided by the
    number of devices because the resulting device size would not
    match the overall size
(3) this then means that the overall write block size must be
    modified depending on the number of devices because the entry is
    per device and when the guest writes into the flash it
    calculates the write size by using the CFI entry (write size
    per device) multiplied by the number of chips.
    (It would alternatively be possible to modify the write
    block size in the CFI table (currently hardcoded at 2048) and
    leave the overall write block size alone.)

This commit corrects these bugs, and adds a hw-compat property
to retain the old behaviour on 2.8 and earlier versions. (The
only board we have which uses this sort of flash config and
has machine versioning is the "virt" board -- the PC uses a
single flash device and so behaviour is unaffected whether
using old-multiple-chip-handling or not.)

Here is a configuration example from the vexpress board:

VEXPRESS_FLASH_SIZE = 64M
VEXPRESS_FLASH_SECT_SIZE 256K
num-blocks = VEXPRESS_FLASH_SIZE / VEXPRESS_FLASH_SECT_SIZE = 256
sector-length = 256K
width = 4
device-width = 2

The code will fill the CFI entry with the following entries:
  num-blocks = 256
  sector-length = 128K
  writeblock_size = 2048

This results in two chips, each with 256 * 128K = 32M device size and
a write block size of 2048.

A sector erase will be sent to both chips, thus 256K must be erased.
When the guest sends a block write command, it will write 4096 bytes
data at once (2048 per device).

Signed-off-by: David Engraf <david.engraf@sysgo.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[PMM: cleaned up and expanded commit message]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2017-01-27 15:20:22 +00:00
..
dataplane virtio: set ISR on dataplane notifications 2016-11-18 17:29:25 +02:00
block.c block/qdev: Allow configuring rerror/werror with qdev properties 2016-07-13 13:32:27 +02:00
cdrom.c block: Clean up includes 2016-01-20 13:36:23 +01:00
ecc.c block: Clean up includes 2016-01-20 13:36:23 +01:00
fdc.c fdc: Move qdev properties to FloppyDrive 2016-10-27 16:29:13 -04:00
hd-geometry.c qemu-common: stop including qemu/bswap.h from qemu-common.h 2016-05-19 16:42:28 +02:00
m25p80.c hw/block/m25p80: Fix typo in local macro name 2017-01-24 23:26:52 +03:00
Makefile.objs block: Always compile virtio-blk dataplane 2014-09-22 11:39:51 +01:00
nand.c nand: Switch to byte-based block access 2016-05-12 15:22:09 +02:00
nvme.c hw/block/nvme: Simplify if-statements a little bit 2016-10-28 18:17:23 +03:00
nvme.h util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
onenand.c onenand: Switch to byte-based block access 2016-05-12 15:22:09 +02:00
pflash_cfi01.c pflash_cfi01: fix per-device sector length in CFI table 2017-01-27 15:20:22 +00:00
pflash_cfi02.c hw/block/pflash_cfi*.c: fix confusing assert fail message 2016-12-22 16:00:26 +01:00
tc58128.c block: Use DIV_ROUND_UP 2016-06-07 18:19:24 +03:00
trace-events trace-events: fix first line comment in trace-events 2016-08-12 10:36:01 +01:00
virtio-blk.c virtio: convert to use DMA api 2017-01-10 05:56:58 +02:00
xen_blkif.h Clean up ill-advised or unusual header guards 2016-07-12 16:20:46 +02:00
xen_disk.c xen_disk: split discard input to match internal representation 2016-11-23 10:47:48 -08:00