hw: allow write_enable latch get/set
cover hw: allow write_enable latch get/set
Hey everyone,
My patch adds the get/set property for the write_enable latch. Currently, it is not an exposed property but this change adds QOM visibility and makes this property modifiable.
Acceptance tests have also been added to verify the value in the status register (after the value is set).
Thanks,
Iris
Iris Chen (1):
hw: allow write_enable latch get/set
hw/block/m25p80.c | 30 ++++++++++++++++++++++++++++++ tests/qtest/aspeed_smc-test.c | 20 ++++++++++++++++++++ 2 files changed, 50 insertions(+)
Signature · 1 line
2.30.2
PATCH 1/1 hw: allow write_enable latch get/set
--- hw/block/m25p80.c | 30 ++++++++++++++++++++++++++++++ tests/qtest/aspeed_smc-test.c | 20 ++++++++++++++++++++ 2 files changed, 50 insertions(+)
hw/block/m25p80.c +30 -0
@@ -35,6 +35,7 @@#include "qapi/error.h" #include "trace.h" #include "qom/object.h" +#include "qapi/visitor.h" /* Fields for FlashPartInfo->flags */
@@ -1646,6 +1647,31 @@ static const VMStateDescription vmstate_m25p80 = { } }; +static void m25p80_get_wel (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +Flash *s =M25P80 (obj); + +assert (strcmp (name,"WEL" ) ==0 ); + +visit_type_bool (v, name, &s->write_enable, errp); +} + +static void m25p80_set_wel (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +Flash *s =M25P80 (obj); +bool value; + +assert (strcmp (name,"WEL" ) ==0 ); + +if (!visit_type_bool (v, name, &value, errp)) { +return ; + } + + s->write_enable = value; +} +static void m25p80_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -1660,6 +1686,10 @@ static void m25p80_class_init(ObjectClass *klass, void *data)device_class_set_props (dc, m25p80_properties); dc->reset = m25p80_reset; mc->pi = data; + +object_class_property_add (klass,"WEL" ,"bool" , + m25p80_get_wel, + m25p80_set_wel,NULL ,NULL ); }static const TypeInfo m25p80_info = {
tests/qtest/aspeed_smc-test.c +20 -0
@@ -49,6 +49,7 @@*/ enum {JEDEC_READ =0x9f , +RDSR =0x5 ,BULK_ERASE =0xc7 ,READ =0x03 ,PP =0x02 ,
@@ -348,6 +349,24 @@ static void test_write_page_mem(void)flash_reset (); } +static void test_read_status_reg (void ) +{ +uint8_t r; + +qmp ("{ 'execute': 'qom-set', 'arguments': " +"{'path': '/machine/soc/fmc/ssi.0/child[0]', 'property': 'WEL', 'value': true}}" ); + +spi_conf (CONF_ENABLE_W0 ); +spi_ctrl_start_user (); +writeb (ASPEED_FLASH_BASE ,RDSR ); + r =readb (ASPEED_FLASH_BASE ); +spi_ctrl_stop_user (); + + g_assert_cmphex(r, ==, 0x2); + +flash_reset (); +} +static char tmp_path[] ="/tmp/qtest.m25p80.XXXXXX" ;int main (int argc,char **argv)
@@ -373,6 +392,7 @@ int main(int argc, char **argv)qtest_add_func ("/ast2400/smc/write_page" , test_write_page);qtest_add_func ("/ast2400/smc/read_page_mem" , test_read_page_mem);qtest_add_func ("/ast2400/smc/write_page_mem" , test_write_page_mem); +qtest_add_func ("/ast2400/smc/read_status_reg" , test_read_status_reg); ret =g_test_run ();
Signature · 1 line
2.30.2
Quoted 54 lines · Iris Chen via
---
hw/block/m25p80.c| 30 ++++++++++++++++++++++++++++++tests/qtest/aspeed_smc-test.c| 20 ++++++++++++++++++++2 files changed, 50 insertions(+)hw/block/m25p80.c +26
-0@@ -35,6 +35,7 @@#include "qapi/error.h" #include "trace.h" #include "qom/object.h" +#include "qapi/visitor.h" /* Fields for FlashPartInfo->flags */ @@ -1646,6 +1647,31 @@ static const VMStateDescription vmstate_m25p80 = { } }; +static void m25p80_get_wel (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +Flash *s =M25P80 (obj); + +assert (strcmp (name,"WEL" ) ==0 ); + +visit_type_bool (v, name, &s->write_enable, errp); +} + +static void m25p80_set_wel (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +Flash *s =M25P80 (obj); +bool value; + +assert (strcmp (name,"WEL" ) ==0 ); + +if (!visit_type_bool (v, name, &value, errp)) { +return ; + } + + s->write_enable = value; +} +static void m25p80_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
hw/block/m25p80.c static void m25p80_class_init(ObjectClass *klass, void *data) · line 1692
Quoted 7 lines
hw/block/m25p80.c +4
-0@@ -1660,6 +1686,10 @@ static void m25p80_class_init(ObjectClass *klass, void *data)device_class_set_props (dc, m25p80_properties); dc->reset = m25p80_reset; mc->pi = data; + +object_class_property_add (klass,"WEL" ,"bool" , + m25p80_get_wel, + m25p80_set_wel,NULL ,NULL );
I think the spacing here might be slightly off, try making the 2nd and 3rd lines align with “klass” in the first line.
Quoted 16 lines
hw/block/m25p80.c +0
-0}static const TypeInfo m25p80_info = {tests/qtest/aspeed_smc-test.c +1
-0@@ -49,6 +49,7 @@*/ enum {JEDEC_READ =0x9f , +RDSR =0x5 ,BULK_ERASE =0xc7 ,READ =0x03 ,PP =0x02 ,
tests/qtest/aspeed_smc-test.c static void test_write_page_mem(void) · line 357
Quoted 9 lines
tests/qtest/aspeed_smc-test.c +6
-0@@ -348,6 +349,24 @@ static void test_write_page_mem(void)flash_reset (); } +static void test_read_status_reg (void ) +{ +uint8_t r; + +qmp ("{ 'execute': 'qom-set', 'arguments': " +"{'path': '/machine/soc/fmc/ssi.0/child[0]', 'property': 'WEL', 'value': true}}" );
Spacing is off here, make sure the indentation is set to 4 spaces.
tests/qtest/aspeed_smc-test.c static void test_write_page_mem(void) · line 363
Quoted 6 lines
tests/qtest/aspeed_smc-test.c +6
-0+ +spi_conf (CONF_ENABLE_W0 ); +spi_ctrl_start_user (); +writeb (ASPEED_FLASH_BASE ,RDSR ); + r =readb (ASPEED_FLASH_BASE ); +spi_ctrl_stop_user ();
Spacing is off here too.
tests/qtest/aspeed_smc-test.c static void test_write_page_mem(void) · line 365
Quoted 2 lines
tests/qtest/aspeed_smc-test.c +2
-0+ + g_assert_cmphex(r, ==, 0x2);
Maybe consider using a constant instead of 0x2, like:
...
#include “qemu/bitops.h"
...
#define SR_WEL BIT(1)
…g_assert_cmphex(r, ==, SR_WEL);
Additionally, since we only care about testing the write enable latch state (and not the other bits in the status register), it could be:
g_assert_cmphex(r & SR_WEL, ==, SR_WEL);
Quoted 20 lines
tests/qtest/aspeed_smc-test.c +5
-0+ +flash_reset (); +} +static char tmp_path[] ="/tmp/qtest.m25p80.XXXXXX" ;int main (int argc,char **argv)@@ -373,6 +392,7 @@ int main(int argc, char **argv)qtest_add_func ("/ast2400/smc/write_page" , test_write_page);qtest_add_func ("/ast2400/smc/read_page_mem" , test_read_page_mem);qtest_add_func ("/ast2400/smc/write_page_mem" , test_write_page_mem); +qtest_add_func ("/ast2400/smc/read_status_reg" , test_read_status_reg); ret =g_test_run ();Signature · 1 line
2.30.2
Hello Iris,
You need to add a description to the patch, may be use what you wrote in the cover letter to start with, and a Signed-off-by tag.
Before sending, please run :
$ ./scripts/checkpatch.pl <patch>
and
$ ./scripts/get_maintainer.pl <patch>
to know who to send to.
The long story is here :
https://qemu.readthedocs.io/en/latest/devel/submitting-a-patch.html
Quoted 18 lines · Iris Chen via
--- hw/block/m25p80.c | 30 ++++++++++++++++++++++++++++++ tests/qtest/aspeed_smc-test.c | 20 ++++++++++++++++++++ 2 files changed, 50 insertions(+)hw/block/m25p80.c +1
-0@@ -35,6 +35,7 @@#include "qapi/error.h" #include "trace.h" #include "qom/object.h" +#include "qapi/visitor.h" /* Fields for FlashPartInfo->flags */
hw/block/m25p80.c static const VMStateDescription vmstate_m25p80 = { · line 1655
Quoted 9 lines
hw/block/m25p80.c +6
-0@@ -1646,6 +1647,31 @@ static const VMStateDescription vmstate_m25p80 = { } }; +static void m25p80_get_wel (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +Flash *s =M25P80 (obj); + +assert (strcmp (name,"WEL" ) ==0 );
That's not necessary.
Quoted 23 lines
hw/block/m25p80.c +19
-0+ +visit_type_bool (v, name, &s->write_enable, errp); +} + +static void m25p80_set_wel (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +Flash *s =M25P80 (obj); +bool value; + +assert (strcmp (name,"WEL" ) ==0 ); + +if (!visit_type_bool (v, name, &value, errp)) { +return ; + } + + s->write_enable = value; +} +static void m25p80_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
hw/block/m25p80.c static void m25p80_class_init(ObjectClass *klass, void *data) · line 1692
Quoted 7 lines
hw/block/m25p80.c +4
-0@@ -1660,6 +1686,10 @@ static void m25p80_class_init(ObjectClass *klass, void *data)device_class_set_props (dc, m25p80_properties); dc->reset = m25p80_reset; mc->pi = data; + +object_class_property_add (klass,"WEL" ,"bool" , + m25p80_get_wel, + m25p80_set_wel,NULL ,NULL );
Instead, you could add a :
DEFINE_PROP_BOOL("write-enable", Flash, write_enable, false);under m25p80_properties.
Thanks,
C.
Quoted 48 lines
hw/block/m25p80.c +0
-0}static const TypeInfo m25p80_info = {tests/qtest/aspeed_smc-test.c +20
-0@@ -49,6 +49,7 @@*/ enum {JEDEC_READ =0x9f , +RDSR =0x5 ,BULK_ERASE =0xc7 ,READ =0x03 ,PP =0x02 ,@@ -348,6 +349,24 @@ static void test_write_page_mem(void)flash_reset (); } +static void test_read_status_reg (void ) +{ +uint8_t r; + +qmp ("{ 'execute': 'qom-set', 'arguments': " +"{'path': '/machine/soc/fmc/ssi.0/child[0]', 'property': 'WEL', 'value': true}}" ); + +spi_conf (CONF_ENABLE_W0 ); +spi_ctrl_start_user (); +writeb (ASPEED_FLASH_BASE ,RDSR ); + r =readb (ASPEED_FLASH_BASE ); +spi_ctrl_stop_user (); + + g_assert_cmphex(r, ==, 0x2); + +flash_reset (); +} +static char tmp_path[] ="/tmp/qtest.m25p80.XXXXXX" ;int main (int argc,char **argv)@@ -373,6 +392,7 @@ int main(int argc, char **argv)qtest_add_func ("/ast2400/smc/write_page" , test_write_page);qtest_add_func ("/ast2400/smc/read_page_mem" , test_read_page_mem);qtest_add_func ("/ast2400/smc/write_page_mem" , test_write_page_mem); +qtest_add_func ("/ast2400/smc/read_status_reg" , test_read_status_reg); ret =g_test_run ();