All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4] igd-passthrough-i440FX: convert to realize()
@ 2015-12-29  8:46 Cao jin
  2015-12-29  9:25 ` Cao jin
  2015-12-29 11:25 ` Michael S. Tsirkin
  0 siblings, 2 replies; 51+ messages in thread
From: Cao jin @ 2015-12-29  8:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefano.stabellini, mst

Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
---
changelog v4:
1. strip the bugfix code, but I guess this patch should be applied after
   that bugfix patch.
2. Other little fix as per previous review

Some explanation to previous review:
1. error_setg_errno() I use in this patch will print the strerror(errno), so I
   guess it will be informative enough? example:

   error_setg_errno(errp, errno, "open %s fail", path); will print:
   "open bluhbluh fail: string_from_strerrer(errno)"

2. snprintf() has tiny tiny chance to fail, I don`t assert here, because this
   device is on-board, it init during machine initialization, in case it fails,
   the errp we set will results in error_report(err) and exit(1), at least can
   let user know why fail. see the call-chain:

   pc_xen_hvm_init_pci->pc_init1->i440fx_init->pci_create_simple-> pci_create_simple_multifunction->qdev_init_nofail

About test:
1. Compiled
2. Did a dirty hack to force create/realize this device in pc_init1(), prove
   that the realizing process is ok, I will reply this mail later to attch the
   screenshot evidence

 hw/pci-host/piix.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index a9cb983..e91570f 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -761,7 +761,7 @@ static const IGDHostInfo igd_host_bridge_infos[] = {
     {0xa8, 4},  /* SNB: base of GTT stolen memory */
 };
 
-static int host_pci_config_read(int pos, int len, uint32_t *val)
+static void host_pci_config_read(int pos, int len, uint32_t *val, Error **errp)
 {
     char path[PATH_MAX];
     int config_fd;
@@ -769,19 +769,19 @@ static int host_pci_config_read(int pos, int len, uint32_t *val)
     /* Access real host bridge. */
     int rc = snprintf(path, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s",
                       0, 0, 0, 0, "config");
-    int ret = 0;
 
     if (rc >= size || rc < 0) {
-        return -ENODEV;
+        error_setg_errno(errp, errno, "snprintf err");
     }
 
     config_fd = open(path, O_RDWR);
     if (config_fd < 0) {
-        return -ENODEV;
+        error_setg_errno(errp, errno, "open %s fail", path);
+        return;
     }
 
     if (lseek(config_fd, pos, SEEK_SET) != pos) {
-        ret = -errno;
+        error_setg_errno(errp, errno, "lseek err");
         goto out;
     }
 
@@ -789,32 +789,32 @@ static int host_pci_config_read(int pos, int len, uint32_t *val)
         rc = read(config_fd, (uint8_t *)val, len);
     } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
     if (rc != len) {
-        ret = -errno;
+        error_setg_errno(errp, errno, "read err");
     }
 
 out:
     close(config_fd);
-    return ret;
 }
 
-static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev)
+static void igd_pt_i440fx_realize(struct PCIDevice *pci_dev, Error **errp)
 {
     uint32_t val = 0;
-    int rc, i, num;
+    int i, num;
     int pos, len;
+    Error *local_err = NULL;
 
     num = ARRAY_SIZE(igd_host_bridge_infos);
     for (i = 0; i < num; i++) {
         pos = igd_host_bridge_infos[i].offset;
         len = igd_host_bridge_infos[i].len;
-        rc = host_pci_config_read(pos, len, &val);
-        if (rc) {
-            return -ENODEV;
+
+        host_pci_config_read(pos, len, &val, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return;
         }
         pci_default_write_config(pci_dev, pos, cpu_to_le32(val), len);
     }
-
-    return 0;
 }
 
 static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data)
@@ -822,7 +822,7 @@ static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = igd_pt_i440fx_initfn;
+    k->realize = igd_pt_i440fx_realize;
     dc->desc = "IGD Passthrough Host bridge";
 }
 
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 51+ messages in thread

end of thread, other threads:[~2016-01-13  7:38 UTC | newest]

Thread overview: 51+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-29  8:46 [Qemu-devel] [PATCH v4] igd-passthrough-i440FX: convert to realize() Cao jin
2015-12-29  9:25 ` Cao jin
2015-12-29 11:25 ` Michael S. Tsirkin
2015-12-29 13:27   ` Cao jin
2016-01-04 14:47     ` Stefano Stabellini
2016-01-04 14:47       ` Stefano Stabellini
2016-01-04 15:33       ` [Qemu-devel] " Lars Kurth
2016-01-04 15:33         ` Lars Kurth
2016-01-04 15:41         ` [Qemu-devel] " Stefano Stabellini
2016-01-04 15:41           ` Stefano Stabellini
2016-01-04 19:49           ` Konrad Rzeszutek Wilk
2016-01-06 10:21           ` [Qemu-devel] [Xen-devel] " Lars Kurth
2016-01-06 10:21             ` Lars Kurth
2016-01-06 12:18             ` [Qemu-devel] [Xen-devel] " Stefano Stabellini
2016-01-06 12:18               ` Stefano Stabellini
2016-01-07  1:32               ` [Qemu-devel] " Hao, Xudong
2016-01-07  1:32                 ` Hao, Xudong
2016-01-08 11:57                 ` [Qemu-devel] [Xen-devel] " Stefano Stabellini
2016-01-08 11:57                   ` Stefano Stabellini
2016-01-11  1:46                   ` [Qemu-devel] " Hao, Xudong
2016-01-11  1:46                     ` Hao, Xudong
2016-01-11  9:53                   ` [Qemu-devel] " Hao, Xudong
2016-01-11  9:53                     ` Hao, Xudong
2016-01-11 10:32                     ` [Qemu-devel] " Gerd Hoffmann
2016-01-11 10:32                       ` Gerd Hoffmann
2016-01-12  8:41                       ` [Qemu-devel] " Hao, Xudong
2016-01-12  8:41                         ` Hao, Xudong
2016-01-12  8:47                         ` [Qemu-devel] " Michael S. Tsirkin
2016-01-12  8:47                           ` Michael S. Tsirkin
2016-01-12  9:50                           ` [Qemu-devel] " Hao, Xudong
2016-01-12  9:50                             ` Hao, Xudong
2016-01-12 10:24                             ` [Qemu-devel] " Gerd Hoffmann
2016-01-12 10:24                               ` Gerd Hoffmann
2016-01-13  1:55                               ` [Qemu-devel] " Hao, Xudong
2016-01-13  1:55                                 ` Hao, Xudong
2016-01-13  7:37                               ` [Qemu-devel] " Hao, Xudong
2016-01-13  7:37                                 ` Hao, Xudong
2016-01-11 10:46                     ` [Qemu-devel] " Stefano Stabellini
2016-01-11 10:46                       ` Stefano Stabellini
2016-01-11 11:01                       ` [Qemu-devel] " Michael S. Tsirkin
2016-01-11 11:01                         ` Michael S. Tsirkin
2016-01-12  9:54                       ` [Qemu-devel] " Hao, Xudong
2016-01-12  9:54                         ` Hao, Xudong
2016-01-12  2:01                     ` [Qemu-devel] " Cao jin
2016-01-12  2:01                       ` Cao jin
2016-01-12  2:24                       ` [Qemu-devel] " Hao, Xudong
2016-01-12  2:24                         ` Hao, Xudong
2016-01-07 13:28   ` [Qemu-devel] " Cao jin
2016-01-07 15:01     ` Stefano Stabellini
2016-01-07 16:21       ` Gerd Hoffmann
2016-01-07 17:42         ` Stefano Stabellini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.