Re: [PATCH] qom/object: enable setter for uint types

2019-11-25 Thread Felipe Franciosi


> On Nov 19, 2019, at 10:06 AM, Stefan Hajnoczi  wrote:
> 
> On Sun, Nov 17, 2019 at 03:50:32PM +, Felipe Franciosi wrote:
>> Traditionally, the uint-specific property helpers only offer getters.
>> When adding object (or class) uint types, one must therefore use the
>> generic property helper if a setter is needed.
>> 
>> This enhances the uint-specific property helper APIs by adding a
>> 'readonly' field and modifying all users of that API to set this
>> parameter to true. If 'readonly' is false, though, the helper will add
>> an automatic setter for the value.
>> 
>> Signed-off-by: Felipe Franciosi 
>> ---
>> hw/acpi/ich9.c   |   4 +-
>> hw/acpi/pcihp.c  |   6 +--
>> hw/acpi/piix4.c  |  12 +++---
>> hw/isa/lpc_ich9.c|   4 +-
>> hw/ppc/spapr_drc.c   |   2 +-
>> include/qom/object.h |  28 
>> qom/object.c | 100 ---
>> ui/console.c |   3 +-
>> 8 files changed, 111 insertions(+), 48 deletions(-)
> 
> Reviewed-by: Stefan Hajnoczi 

While cleaning up more code to use these helpers, I realised that some
setters included a check to ensure values were not overflowing. I
therefore decided to improve on this setter and send other related
changes together in the following patchset:

https://lists.gnu.org/archive/html/qemu-devel/2019-11/msg04136.html

Please don't merge this patch and look at the patchset instead.

F.



Re: [PATCH] qom/object: enable setter for uint types

2019-11-19 Thread Stefan Hajnoczi
On Sun, Nov 17, 2019 at 03:50:32PM +, Felipe Franciosi wrote:
> Traditionally, the uint-specific property helpers only offer getters.
> When adding object (or class) uint types, one must therefore use the
> generic property helper if a setter is needed.
> 
> This enhances the uint-specific property helper APIs by adding a
> 'readonly' field and modifying all users of that API to set this
> parameter to true. If 'readonly' is false, though, the helper will add
> an automatic setter for the value.
> 
> Signed-off-by: Felipe Franciosi 
> ---
>  hw/acpi/ich9.c   |   4 +-
>  hw/acpi/pcihp.c  |   6 +--
>  hw/acpi/piix4.c  |  12 +++---
>  hw/isa/lpc_ich9.c|   4 +-
>  hw/ppc/spapr_drc.c   |   2 +-
>  include/qom/object.h |  28 
>  qom/object.c | 100 ---
>  ui/console.c |   3 +-
>  8 files changed, 111 insertions(+), 48 deletions(-)

Reviewed-by: Stefan Hajnoczi 


signature.asc
Description: PGP signature


[PATCH] qom/object: enable setter for uint types

2019-11-17 Thread Felipe Franciosi
Traditionally, the uint-specific property helpers only offer getters.
When adding object (or class) uint types, one must therefore use the
generic property helper if a setter is needed.

This enhances the uint-specific property helper APIs by adding a
'readonly' field and modifying all users of that API to set this
parameter to true. If 'readonly' is false, though, the helper will add
an automatic setter for the value.

Signed-off-by: Felipe Franciosi 
---
 hw/acpi/ich9.c   |   4 +-
 hw/acpi/pcihp.c  |   6 +--
 hw/acpi/piix4.c  |  12 +++---
 hw/isa/lpc_ich9.c|   4 +-
 hw/ppc/spapr_drc.c   |   2 +-
 include/qom/object.h |  28 
 qom/object.c | 100 ---
 ui/console.c |   3 +-
 8 files changed, 111 insertions(+), 48 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 2034dd749e..94dc5147ce 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -454,12 +454,12 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs 
*pm, Error **errp)
 pm->s4_val = 2;
 
 object_property_add_uint32_ptr(obj, ACPI_PM_PROP_PM_IO_BASE,
-   >pm_io_base, errp);
+   >pm_io_base, true, errp);
 object_property_add(obj, ACPI_PM_PROP_GPE0_BLK, "uint32",
 ich9_pm_get_gpe0_blk,
 NULL, NULL, pm, NULL);
 object_property_add_uint32_ptr(obj, ACPI_PM_PROP_GPE0_BLK_LEN,
-   _len, errp);
+   _len, true, errp);
 object_property_add_bool(obj, "memory-hotplug-support",
  ich9_pm_get_memory_hotplug_support,
  ich9_pm_set_memory_hotplug_support,
diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 8413348a33..70bc1408e6 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -80,7 +80,7 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque)
 
 *bus_bsel = (*bsel_alloc)++;
 object_property_add_uint32_ptr(OBJECT(bus), ACPI_PCIHP_PROP_BSEL,
-   bus_bsel, _abort);
+   bus_bsel, true, _abort);
 }
 
 return bsel_alloc;
@@ -373,9 +373,9 @@ void acpi_pcihp_init(Object *owner, AcpiPciHpState *s, 
PCIBus *root_bus,
 memory_region_add_subregion(address_space_io, s->io_base, >io);
 
 object_property_add_uint16_ptr(owner, ACPI_PCIHP_IO_BASE_PROP, >io_base,
-   _abort);
+   true, _abort);
 object_property_add_uint16_ptr(owner, ACPI_PCIHP_IO_LEN_PROP, >io_len,
-   _abort);
+   true, _abort);
 }
 
 const VMStateDescription vmstate_acpi_pcihp_pci_status = {
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 93aec2dd2c..032ba11e62 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -443,17 +443,17 @@ static void piix4_pm_add_propeties(PIIX4PMState *s)
 static const uint16_t sci_int = 9;
 
 object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_ENABLE_CMD,
-  _enable_cmd, NULL);
+  _enable_cmd, true, NULL);
 object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_DISABLE_CMD,
-  _disable_cmd, NULL);
+  _disable_cmd, true, NULL);
 object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK,
-  _blk, NULL);
+  _blk, true, NULL);
 object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK_LEN,
-  _blk_len, NULL);
+  _blk_len, true, NULL);
 object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT,
-  _int, NULL);
+  _int, true, NULL);
 object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_PM_IO_BASE,
-  >io_base, NULL);
+  >io_base, true, NULL);
 }
 
 static void piix4_pm_realize(PCIDevice *dev, Error **errp)
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 17c292e306..ce3342 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -645,9 +645,9 @@ static void ich9_lpc_add_properties(ICH9LPCState *lpc)
 ich9_lpc_get_sci_int,
 NULL, NULL, NULL, NULL);
 object_property_add_uint8_ptr(OBJECT(lpc), ACPI_PM_PROP_ACPI_ENABLE_CMD,
-  _enable_cmd, NULL);
+  _enable_cmd, true, NULL);
 object_property_add_uint8_ptr(OBJECT(lpc), ACPI_PM_PROP_ACPI_DISABLE_CMD,
-  _disable_cmd, NULL);
+  _disable_cmd, true, NULL);
 
 ich9_pm_add_properties(OBJECT(lpc), >pm, NULL);
 }
diff --git