block, arm: Fix buffered flash writes on VExpress
v2 cover block, arm: Fix buffered flash writes on VExpress
Here is my updated patch to fix buffered flash writes on the VExpress platform. Buffered writes should now work properly on platforms whose flash interface width is different from the device width. The default is for the device-width to be set to the interface width, so platforms that can benefit from this change will need to be updated. This patchset updates the configuration for the VExpress platform which requires it. UEFI firmware uses buffered writes for persistent variable storage, and this patchset enables this usage on QEMU.
Changes from v1:
* Add device-width property and use this to mask write length instead of devices mas write length
* Update vexpress init code to set device-width to proper value.
Roy Franz (2):
Add device-width property to pflash_cfi01
Set proper device-width for vexpress flash
hw/arm/vexpress.c | 38 ++++++++++++++++++++++++++++++++++++-- hw/block/pflash_cfi01.c | 21 +++++++++++++-------- 2 files changed, 49 insertions(+), 10 deletions(-)
Signature · 1 line
1.7.10.4
PATCH v2 1/2 Add device-width property to pflash_cfi01
The width of the devices that make up the flash interface is required to mask certain commands, in particular the write length for buffered writes. This length will be presented to each device on the interface by the program writing the flash, and the flash emulation code needs to be able to determine the length of the write as recieved by each flash device. The device-width defaults to the bank width which should maintain existing behavior for platforms that don't need this change.
This change is required to support buffered writes on the vexpress platform that has a 32 bit flash interface with 2 16 bit devices on it.
--- hw/block/pflash_cfi01.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
hw/block/pflash_cfi01.c +13 -8
@@ -71,7 +71,8 @@ struct pflash_t {BlockDriverState *bs;uint32_t nb_blocs;uint64_t sector_len; -uint8_t width; +uint8_t bank_width; +uint8_t device_width;uint8_t be;uint8_t wcycle;/* if 0, the flash is read normally */ int ro;
@@ -126,9 +127,9 @@ static uint32_t pflash_read (pflash_t *pfl, hwaddr offset, ret =-1 ; boff = offset &0xFF ;/* why this here ?? */ -if (pfl->width ==2 ) +if (pfl->bank_width ==2 ) boff = boff >>1 ; -else if (pfl->width ==4 ) +else if (pfl->bank_width ==4 ) boff = boff >>2 ;#if 0
@@ -378,6 +379,8 @@ static void pflash_write(pflash_t *pfl, hwaddr offset,break ;case 0xe8 : +/* Mask writeblock size based on device width */ + value &= (1ULL << (pfl->device_width *8 )) -1 ;DPRINTF ("%s: block write of %x bytes\n" , __func__, value); pfl->counter = value; pfl->wcycle++;
@@ -665,7 +668,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->cfi_table[0x28 ] =0x02 ; pfl->cfi_table[0x29 ] =0x00 ;/* Max number of bytes in multi-bytes write */ -if (pfl->width ==1 ) { +if (pfl->bank_width ==1 ) { pfl->cfi_table[0x2A ] =0x08 ; }else { pfl->cfi_table[0x2A ] =0x0B ;
@@ -706,7 +709,8 @@ static Property pflash_cfi01_properties[] = { DEFINE_PROP_DRIVE("drive", struct pflash_t, bs), DEFINE_PROP_UINT32("num-blocks", struct pflash_t, nb_blocs, 0), DEFINE_PROP_UINT64("sector-length", struct pflash_t, sector_len, 0), - DEFINE_PROP_UINT8("width", struct pflash_t, width, 0), + DEFINE_PROP_UINT8("width", struct pflash_t, bank_width, 0), + DEFINE_PROP_UINT8("device-width", struct pflash_t, device_width, 0), DEFINE_PROP_UINT8("big-endian", struct pflash_t, be, 0), DEFINE_PROP_UINT16("id0", struct pflash_t, ident0, 0), DEFINE_PROP_UINT16("id1", struct pflash_t, ident1, 0),
@@ -745,8 +749,8 @@ pflash_t *pflash_cfi01_register(hwaddr base, DeviceState *qdev, const char *name, hwaddr size, BlockDriverState *bs, - uint32_t sector_len, int nb_blocs, int width, - uint16_t id0, uint16_t id1, + uint32_t sector_len, int nb_blocs, + int bank_width, uint16_t id0, uint16_t id1, uint16_t id2, uint16_t id3, int be) { DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
@@ -756,7 +760,8 @@ pflash_t *pflash_cfi01_register(hwaddr base, }qdev_prop_set_uint32 (dev,"num-blocks" , nb_blocs);qdev_prop_set_uint64 (dev,"sector-length" , sector_len); -qdev_prop_set_uint8 (dev,"width" , width); +qdev_prop_set_uint8 (dev,"width" , bank_width); +qdev_prop_set_uint8 (dev,"device-width" , bank_width);qdev_prop_set_uint8 (dev,"big-endian" , !!be);qdev_prop_set_uint16 (dev,"id0" , id0);qdev_prop_set_uint16 (dev,"id1" , id1);
Signature · 1 line
1.7.10.4
PATCH v2 2/2 Set proper device-width for vexpress flash
In reply to Roy FranzCreate vexpress specific pflash registration function which properly configures the device-width of 16 bits (2 bytes) for the NOR flash on the vexpress platform. This change is required for buffered flash writes to work properly.
--- hw/arm/vexpress.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
hw/arm/vexpress.c +36 -2
@@ -480,6 +480,39 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt) } } + +/* Open code a private version of plfash registration since we +* need to set non-default device width for Vexpress platform. +*/ +static pflash_t *ve_pflash_cfi01_register (hwaddr base, +DeviceState *qdev,const char *name, +hwaddr size, +BlockDriverState *bs, +uint32_t sector_len,int nb_blocs, +int bank_width,uint16_t id0,uint16_t id1, +uint16_t id2,uint16_t id3,int be) +{ +DeviceState *dev =qdev_create (NULL ,"cfi.pflash01" ); + +if (bs &&qdev_prop_set_drive (dev,"drive" , bs)) { +abort (); + } +qdev_prop_set_uint32 (dev,"num-blocks" , nb_blocs); +qdev_prop_set_uint64 (dev,"sector-length" , sector_len); +qdev_prop_set_uint8 (dev,"width" , bank_width); +qdev_prop_set_uint8 (dev,"device-width" ,2 ); +qdev_prop_set_uint8 (dev,"big-endian" , !!be); +qdev_prop_set_uint16 (dev,"id0" , id0); +qdev_prop_set_uint16 (dev,"id1" , id1); +qdev_prop_set_uint16 (dev,"id2" , id2); +qdev_prop_set_uint16 (dev,"id3" , id3); +qdev_prop_set_string (dev,"name" , name); +qdev_init_nofail (dev); + +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , base); +return OBJECT_CHECK (pflash_t, (dev),"cfi.pflash01" ); +} +static void vexpress_common_init (VEDBoardInfo *daughterboard,QEMUMachineInitArgs *args) {
@@ -561,7 +594,8 @@ static void vexpress_common_init(VEDBoardInfo *daughterboard,sysbus_create_simple ("pl111" , map[VE_CLCD ], pic[14 ]); dinfo =drive_get_next (IF_PFLASH ); - pflash0 = pflash_cfi01_register(map[VE_NORFLASH0], NULL, "vexpress.flash0", + pflash0 = ve_pflash_cfi01_register(map[VE_NORFLASH0], NULL, + "vexpress.flash0", VEXPRESS_FLASH_SIZE, dinfo ? dinfo->bdrv : NULL, VEXPRESS_FLASH_SECT_SIZE, VEXPRESS_FLASH_SIZE / VEXPRESS_FLASH_SECT_SIZE, 4,
@@ -580,7 +614,7 @@ static void vexpress_common_init(VEDBoardInfo *daughterboard, } dinfo =drive_get_next (IF_PFLASH ); - if (!pflash_cfi01_register(map[VE_NORFLASH1], NULL, "vexpress.flash1", + if (!ve_pflash_cfi01_register(map[VE_NORFLASH1], NULL, "vexpress.flash1", VEXPRESS_FLASH_SIZE, dinfo ? dinfo->bdrv : NULL, VEXPRESS_FLASH_SECT_SIZE, VEXPRESS_FLASH_SIZE / VEXPRESS_FLASH_SECT_SIZE, 4,
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 2/2 v2] Set proper device-width for vexpress flash
Quoted 7 lines · Roy Franz
Create vexpress specific pflash registration function which properly configures the device-width of 16 bits (2 bytes) for the NOR flash on the vexpress platform. This change is required for buffered flash writes to work properly.
+/* Open code a private version of plfash registration since we
"pflash"
Quoted 45 lines
+ * need to set non-default device width for Vexpress platform.
+ */hw/arm/vexpress.c +31
-1+static pflash_t *ve_pflash_cfi01_register (hwaddr base, +DeviceState *qdev,const char *name, +hwaddr size, +BlockDriverState *bs, +uint32_t sector_len,int nb_blocs, +int bank_width,uint16_t id0,uint16_t id1, +uint16_t id2,uint16_t id3,int be) +{ +DeviceState *dev =qdev_create (NULL ,"cfi.pflash01" ); + +if (bs &&qdev_prop_set_drive (dev,"drive" , bs)) { +abort (); + } +qdev_prop_set_uint32 (dev,"num-blocks" , nb_blocs); +qdev_prop_set_uint64 (dev,"sector-length" , sector_len); +qdev_prop_set_uint8 (dev,"width" , bank_width); +qdev_prop_set_uint8 (dev,"device-width" ,2 ); +qdev_prop_set_uint8 (dev,"big-endian" , !!be); +qdev_prop_set_uint16 (dev,"id0" , id0); +qdev_prop_set_uint16 (dev,"id1" , id1); +qdev_prop_set_uint16 (dev,"id2" , id2); +qdev_prop_set_uint16 (dev,"id3" , id3); +qdev_prop_set_string (dev,"name" , name); +qdev_init_nofail (dev); + +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , base); +return OBJECT_CHECK (pflash_t, (dev),"cfi.pflash01" ); +} +static void vexpress_common_init (VEDBoardInfo *daughterboard,QEMUMachineInitArgs *args) {@@ -561,7 +594,8 @@ static void vexpress_common_init(VEDBoardInfo *daughterboard,sysbus_create_simple ("pl111" , map[VE_CLCD ], pic[14 ]); dinfo =drive_get_next (IF_PFLASH ); - pflash0 = pflash_cfi01_register(map[VE_NORFLASH0], NULL, "vexpress.flash0", + pflash0 = ve_pflash_cfi01_register(map[VE_NORFLASH0], NULL, + "vexpress.flash0", VEXPRESS_FLASH_SIZE, dinfo ? dinfo->bdrv : NULL, VEXPRESS_FLASH_SECT_SIZE, VEXPRESS_FLASH_SIZE / VEXPRESS_FLASH_SECT_SIZE, 4,
hw/arm/vexpress.c static void vexpress_common_init(VEDBoardInfo *daughterboard, · line 620
Quoted 8 lines
hw/arm/vexpress.c +1
-1@@ -580,7 +614,7 @@ static void vexpress_common_init(VEDBoardInfo *daughterboard, } dinfo =drive_get_next (IF_PFLASH ); - if (!pflash_cfi01_register(map[VE_NORFLASH1], NULL, "vexpress.flash1", + if (!ve_pflash_cfi01_register(map[VE_NORFLASH1], NULL, "vexpress.flash1", VEXPRESS_FLASH_SIZE, dinfo ? dinfo->bdrv : NULL, VEXPRESS_FLASH_SECT_SIZE, VEXPRESS_FLASH_SIZE / VEXPRESS_FLASH_SECT_SIZE, 4,
Almost all the parameters you're passing here are the same for both calls, so it would be better to hard code them in the utility function.
-- PMM
v3 cover block, arm: Fix buffered flash writes on VExpress
Here is my updated patch to fix buffered flash writes on the VExpress platform. Buffered writes should now work properly on platforms whose flash interface width is different from the device width. The default is for the device-width to be set to the interface width, so platforms that can benefit from this change will need to be updated. This patchset updates the configuration for the VExpress platform which requires it. UEFI firmware uses buffered writes for persistent variable storage, and this patchset enables this usage on QEMU.
Changes from v2:
(All changes in patch 2/2, 1/1 unchanged.)
* Set flash invariant properties directly in VExpress specific flash init routine rather than passing long argument list.
* Fix typo in comment.
Changes from v1:
* Add device-width property and use this to mask write length instead of devices mas write length
* Update vexpress init code to set device-width to proper value.
Roy Franz (2):
Add device-width property to pflash_cfi01
Set proper device-width for vexpress flash
hw/arm/vexpress.c | 43 +++++++++++++++++++++++++++++++++---------- hw/block/pflash_cfi01.c | 21 +++++++++++++-------- 2 files changed, 46 insertions(+), 18 deletions(-)
Signature · 1 line
1.7.10.4
PATCH v3 1/2 block: Add device-width property to pflash_cfi01
The width of the devices that make up the flash interface is required to mask certain commands, in particular the write length for buffered writes. This length will be presented to each device on the interface by the program writing the flash, and the flash emulation code needs to be able to determine the length of the write as recieved by each flash device. The device-width defaults to the bank width which should maintain existing behavior for platforms that don't need this change.
This change is required to support buffered writes on the vexpress platform that has a 32 bit flash interface with 2 16 bit devices on it.
--- hw/block/pflash_cfi01.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
hw/block/pflash_cfi01.c +13 -8
@@ -71,7 +71,8 @@ struct pflash_t {BlockDriverState *bs;uint32_t nb_blocs;uint64_t sector_len; -uint8_t width; +uint8_t bank_width; +uint8_t device_width;uint8_t be;uint8_t wcycle;/* if 0, the flash is read normally */ int ro;
@@ -126,9 +127,9 @@ static uint32_t pflash_read (pflash_t *pfl, hwaddr offset, ret =-1 ; boff = offset &0xFF ;/* why this here ?? */ -if (pfl->width ==2 ) +if (pfl->bank_width ==2 ) boff = boff >>1 ; -else if (pfl->width ==4 ) +else if (pfl->bank_width ==4 ) boff = boff >>2 ;#if 0
@@ -378,6 +379,8 @@ static void pflash_write(pflash_t *pfl, hwaddr offset,break ;case 0xe8 : +/* Mask writeblock size based on device width */ + value &= (1ULL << (pfl->device_width *8 )) -1 ;DPRINTF ("%s: block write of %x bytes\n" , __func__, value); pfl->counter = value; pfl->wcycle++;
@@ -665,7 +668,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->cfi_table[0x28 ] =0x02 ; pfl->cfi_table[0x29 ] =0x00 ;/* Max number of bytes in multi-bytes write */ -if (pfl->width ==1 ) { +if (pfl->bank_width ==1 ) { pfl->cfi_table[0x2A ] =0x08 ; }else { pfl->cfi_table[0x2A ] =0x0B ;
@@ -706,7 +709,8 @@ static Property pflash_cfi01_properties[] = { DEFINE_PROP_DRIVE("drive", struct pflash_t, bs), DEFINE_PROP_UINT32("num-blocks", struct pflash_t, nb_blocs, 0), DEFINE_PROP_UINT64("sector-length", struct pflash_t, sector_len, 0), - DEFINE_PROP_UINT8("width", struct pflash_t, width, 0), + DEFINE_PROP_UINT8("width", struct pflash_t, bank_width, 0), + DEFINE_PROP_UINT8("device-width", struct pflash_t, device_width, 0), DEFINE_PROP_UINT8("big-endian", struct pflash_t, be, 0), DEFINE_PROP_UINT16("id0", struct pflash_t, ident0, 0), DEFINE_PROP_UINT16("id1", struct pflash_t, ident1, 0),
@@ -745,8 +749,8 @@ pflash_t *pflash_cfi01_register(hwaddr base, DeviceState *qdev, const char *name, hwaddr size, BlockDriverState *bs, - uint32_t sector_len, int nb_blocs, int width, - uint16_t id0, uint16_t id1, + uint32_t sector_len, int nb_blocs, + int bank_width, uint16_t id0, uint16_t id1, uint16_t id2, uint16_t id3, int be) { DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
@@ -756,7 +760,8 @@ pflash_t *pflash_cfi01_register(hwaddr base, }qdev_prop_set_uint32 (dev,"num-blocks" , nb_blocs);qdev_prop_set_uint64 (dev,"sector-length" , sector_len); -qdev_prop_set_uint8 (dev,"width" , width); +qdev_prop_set_uint8 (dev,"width" , bank_width); +qdev_prop_set_uint8 (dev,"device-width" , bank_width);qdev_prop_set_uint8 (dev,"big-endian" , !!be);qdev_prop_set_uint16 (dev,"id0" , id0);qdev_prop_set_uint16 (dev,"id1" , id1);
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 1/2 v3] block: Add device-width property to pflash_cfi01
Quoted 23 lines · Roy Franz
The width of the devices that make up the flash interface is required to mask certain commands, in particular the write length for buffered writes. This length will be presented to each device on the interface by the program writing the flash, and the flash emulation code needs to be able to determine the length of the write as recieved by each flash device. The device-width defaults to the bank width which should maintain existing behavior for platforms that don't need this change.
This change is required to support buffered writes on the vexpress platform that has a 32 bit flash interface with 2 16 bit devices on it.Signed-off-by Roy Franz <[email protected]>--- hw/block/pflash_cfi01.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)hw/block/pflash_cfi01.c +0
-0
hw/block/pflash_cfi01.c struct pflash_t { · line 74
Quoted 5 lines
hw/block/pflash_cfi01.c +1
-1@@ -71,7 +71,8 @@ struct pflash_t {BlockDriverState *bs;uint32_t nb_blocs;uint64_t sector_len; -uint8_t width; +uint8_t bank_width;
If you want to rename this struct field can you put that in its own patch, please? Otherwise it's hard to see the actual functional changes.
Quoted 17 lines
hw/block/pflash_cfi01.c +3
-2+uint8_t device_width;uint8_t be;uint8_t wcycle;/* if 0, the flash is read normally */ int ro;@@ -126,9 +127,9 @@ static uint32_t pflash_read (pflash_t *pfl, hwaddr offset, ret =-1 ; boff = offset &0xFF ;/* why this here ?? */ -if (pfl->width ==2 ) +if (pfl->bank_width ==2 ) boff = boff >>1 ; -else if (pfl->width ==4 ) +else if (pfl->bank_width ==4 ) boff = boff >>2 ;#if 0
hw/block/pflash_cfi01.c static void pflash_write(pflash_t *pfl, hwaddr offset, · line 383
Quoted 5 lines
hw/block/pflash_cfi01.c +2
-0@@ -378,6 +379,8 @@ static void pflash_write(pflash_t *pfl, hwaddr offset,break ;case 0xe8 : +/* Mask writeblock size based on device width */ + value &= (1ULL << (pfl->device_width *8 )) -1 ;
Is this really the only guest visible difference for banked flash devices?
hw/block/pflash_cfi01.c static void pflash_write(pflash_t *pfl, hwaddr offset, · line 386
Quoted 3 lines
hw/block/pflash_cfi01.c +0
-0DPRINTF ("%s: block write of %x bytes\n" , __func__, value); pfl->counter = value; pfl->wcycle++;
thanks
-- PMM
PATCH v3 2/2 block, arm: Set proper device-width for vexpress flash
In reply to Roy FranzCreate vexpress specific pflash registration function which properly configures the device-width of 16 bits (2 bytes) for the NOR flash on the vexpress platform. This change is required for buffered flash writes to work properly.
--- hw/arm/vexpress.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-)
hw/arm/vexpress.c +33 -10
@@ -480,6 +480,35 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt) } } + +/* Open code a private version of pflash registration since we +* need to set non-default device width for VExpress platform. +*/ +static pflash_t *ve_pflash_cfi01_register (hwaddr base,const char *name, +BlockDriverState *bs) +{ +DeviceState *dev =qdev_create (NULL ,"cfi.pflash01" ); + +if (bs &&qdev_prop_set_drive (dev,"drive" , bs)) { +abort (); + } + +qdev_prop_set_uint32 (dev,"num-blocks" ,VEXPRESS_FLASH_SIZE /VEXPRESS_FLASH_SECT_SIZE ); +qdev_prop_set_uint64 (dev,"sector-length" ,VEXPRESS_FLASH_SECT_SIZE ); +qdev_prop_set_uint8 (dev,"width" ,4 ); +qdev_prop_set_uint8 (dev,"device-width" ,2 ); +qdev_prop_set_uint8 (dev,"big-endian" ,0 ); +qdev_prop_set_uint16 (dev,"id0" ,0x00 ); +qdev_prop_set_uint16 (dev,"id1" ,0x89 ); +qdev_prop_set_uint16 (dev,"id2" ,0x00 ); +qdev_prop_set_uint16 (dev,"id3" ,0x18 ); +qdev_prop_set_string (dev,"name" , name); +qdev_init_nofail (dev); + +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , base); +return OBJECT_CHECK (pflash_t, (dev),"cfi.pflash01" ); +} +static void vexpress_common_init (VEDBoardInfo *daughterboard,QEMUMachineInitArgs *args) {
@@ -561,11 +590,8 @@ static void vexpress_common_init(VEDBoardInfo *daughterboard,sysbus_create_simple ("pl111" , map[VE_CLCD ], pic[14 ]); dinfo =drive_get_next (IF_PFLASH ); - pflash0 =pflash_cfi01_register (map[VE_NORFLASH0 ],NULL ,"vexpress.flash0" , -VEXPRESS_FLASH_SIZE , dinfo ? dinfo->bdrv :NULL , -VEXPRESS_FLASH_SECT_SIZE , -VEXPRESS_FLASH_SIZE /VEXPRESS_FLASH_SECT_SIZE ,4 , -0x00 ,0x89 ,0x00 ,0x18 ,0 ); + pflash0 =ve_pflash_cfi01_register (map[VE_NORFLASH0 ],"vexpress.flash0" , + dinfo ? dinfo->bdrv :NULL );if (!pflash0) {fprintf (stderr,"vexpress: error registering flash 0.\n" );exit (1 );
@@ -580,11 +606,8 @@ static void vexpress_common_init(VEDBoardInfo *daughterboard, } dinfo =drive_get_next (IF_PFLASH ); -if (!pflash_cfi01_register (map[VE_NORFLASH1 ],NULL ,"vexpress.flash1" , -VEXPRESS_FLASH_SIZE , dinfo ? dinfo->bdrv :NULL , -VEXPRESS_FLASH_SECT_SIZE , -VEXPRESS_FLASH_SIZE /VEXPRESS_FLASH_SECT_SIZE ,4 , -0x00 ,0x89 ,0x00 ,0x18 ,0 )) { +if (!ve_pflash_cfi01_register (map[VE_NORFLASH1 ],"vexpress.flash1" , + dinfo ? dinfo->bdrv :NULL )) {fprintf (stderr,"vexpress: error registering flash 1.\n" );exit (1 ); }
Signature · 1 line
1.7.10.4