Skip to contentSkip to conversation

hw/i2c/core.c: add the id property of i2c_slaver when created in the QEMUMachine's initialization

PATCH In review Zhou Yuan 2 participants 2 messages Nov 15, 2013

lore
Share & tools
lore

Zhou Yuan

author
#0 lore raw

PATCH 1/1 hw/i2c/core.c: add the id property of i2c_slaver when created in the QEMUMachine's initialization

From: zhouy <[email protected]>
Date: Fri, 15 Nov 2013 15:50:52 -0500
Subject: [PATCH] add the id property of i2c_slaver when created in the
QEMUMachine's initialization

---
 qemu-master/hw/i2c/core.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
qemu-master/hw/i2c/core.c +7 -1
index c97e7f7..ea3e59d 100644
@@ -213,10 +213,16 @@ static int i2c_slave_qdev_init(DeviceState *dev)
 DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr)
 {
     DeviceState *dev;
-
+    static unsigned int seq_num;
+    char *id = g_malloc0(20);
+    snprintf(id, 20, "%s-%d", name, seq_num);
     dev = qdev_create(&bus->qbus, name);
     qdev_prop_set_uint8(dev, "address", addr);
+    dev->id = id;
+    object_property_add_child(container_get(qdev_get_machine(), "/peripheral"),
+                              dev->id, OBJECT(dev), NULL);
     qdev_init_nofail(dev);
+    seq_num++;
     return dev;
 }
 
Signature · 20 lines
1.7.6

以上、よろしくお願いいたします。    
--------------
A new email address of FJWAN is launched from Apr.1 2007.
The updated address is: [email protected] 
--------------------------------------------------
Zhou Yuan
Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST)
No. 6 Wenzhu Road, Nanjing, 210012, China
TEL:+86+25-86630566-9555
FUJITSU INTERNAL:7998-9555
FAX:+86+25-83317685
EMail:[email protected]
--------------------------------------------------
This communication is for use by the intended recipient(s) only and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If you are not an intended recipient of this communication, you are hereby notified that any dissemination, distribution or copying hereof is strictly prohibited.  If you have received this communication in error, please notify me by reply e-mail, permanently delete this communication from your system, and destroy any hard copies you may have printed.
 
[email protected]
16:54:53
qemu-devel
#1 lore raw
Quoted 21 lines · Zhou Yuan

From: zhouy <[email protected]>
Date: Fri, 15 Nov 2013 15:50:52 -0500
Subject: [PATCH] add the id property of i2c_slaver when created in the
QEMUMachine's initialization

---
 qemu-master/hw/i2c/core.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
qemu-master/hw/i2c/core.c +2 -1
index c97e7f7..ea3e59d 100644
@@ -213,10 +213,16 @@ static int i2c_slave_qdev_init(DeviceState *dev)
 DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr)
 {
     DeviceState *dev;
-
+    static unsigned int seq_num;
+    char *id = g_malloc0(20);

qemu-master/hw/i2c/core.c static int i2c_slave_qdev_init(DeviceState *dev) · line 227

Quoted 10 lines
qemu-master/hw/i2c/core.c +5 -0
+    snprintf(id, 20, "%s-%d", name, seq_num);
     dev = qdev_create(&bus->qbus, name);
     qdev_prop_set_uint8(dev, "address", addr);
+    dev->id = id;
+    object_property_add_child(container_get(qdev_get_machine(), "/peripheral"),
+                              dev->id, OBJECT(dev), NULL);
     qdev_init_nofail(dev);
+    seq_num++;
     return dev;
 }

Why is this needed?

In general, property "id" / DeviceState member id is strictly for the user, and should never be set automatically. Exceptions exist in convenience options, mostly for historical reasons.