Skip to content
Snippets Groups Projects
  1. Jan 12, 2022
  2. Jan 04, 2022
    • Daniel Henrique Barboza's avatar
      pnv_phb4.c: do not set 'root-bus' as bus name · 9747d061
      Daniel Henrique Barboza authored
      
      This change has the same motivation as the one done for pnv-phb3-root-bus
      buses previously. Defaulting every bus to 'root-bus' makes it impossible to attach
      root ports to specific buses and it doesn't allow for custom bus
      naming because we're ignoring the 'id' value when registering the root
      bus.
      
      After this patch, creating pnv-phb4 devices with 'id' being set will
      result in the following qtree:
      
      qemu-system-ppc64 -m 4G -machine powernv9,accel=tcg \
         -device pnv-phb4,chip-id=0,index=0,id=pcie.0 \
         -device pnv-phb4,chip-id=1,index=4,id=pcie.1
      
      bus: main-system-bus
        type System
        dev: pnv-phb4, id "pcie.1"
          index = 4 (0x4)
          chip-id = 1 (0x1)
          version = 704374636546 (0xa400000002)
          device-id = 1217 (0x4c1)
          x-config-reg-migration-enabled = true
          bypass-iommu = false
          bus: pcie.1
            type pnv-phb4-root-bus
        dev: pnv-phb4, id "pcie.0"
          index = 0 (0x0)
          chip-id = 0 (0x0)
          version = 704374636546 (0xa400000002)
          device-id = 1217 (0x4c1)
          x-config-reg-migration-enabled = true
          bypass-iommu = false
          bus: pcie.0
            type pnv-phb4-root-bus
      
      And without setting any ids:
      
      qemu-system-ppc64 -m 4G -machine powernv9,accel=tcg \
         -device pnv-phb4,chip-id=0,index=0,id=pcie.0 \
         -device pnv-phb4,chip-id=1,index=4,id=pcie.1
      
      bus: main-system-bus
        type System
        dev: pnv-phb4, id ""
          index = 4 (0x4)
          chip-id = 1 (0x1)
          version = 704374636546 (0xa400000002)
          device-id = 1217 (0x4c1)
          x-config-reg-migration-enabled = true
          bypass-iommu = false
          bus: pnv-phb4-root-bus.1
            type pnv-phb4-root-bus
        dev: pnv-phb4, id ""
          index = 0 (0x0)
          chip-id = 0 (0x0)
          version = 704374636546 (0xa400000002)
          device-id = 1217 (0x4c1)
          x-config-reg-migration-enabled = true
          bypass-iommu = false
          bus: pnv-phb4-root-bus.0
            type pnv-phb4-root-bus
      
      Signed-off-by: default avatarDaniel Henrique Barboza <danielhb413@gmail.com>
      Reviewed-by: default avatarCédric Le Goater <clg@kaod.org>
      Message-Id: <20211228193806.1198496-17-danielhb413@gmail.com>
      Signed-off-by: default avatarCédric Le Goater <clg@kaod.org>
      9747d061
    • Cédric Le Goater's avatar
      ppc/pnv: Remove the PHB4 "device-id" property · c42b9c8b
      Cédric Le Goater authored
      
      It's unused.
      
      Signed-off-by: default avatarCédric Le Goater <clg@kaod.org>
      Reviewed-by: default avatarDaniel Henrique Barboza <danielhb413@gmail.com>
      Message-Id: <20211222063817.1541058-4-clg@kaod.org>
      Signed-off-by: default avatarCédric Le Goater <clg@kaod.org>
      c42b9c8b
    • Cédric Le Goater's avatar
      ppc/pnv: Remove PHB4 reset handler · 81fbb57b
      Cédric Le Goater authored
      
      The PHB4 reset handler was preparing ground for PHB5 to set
      appropriately the device id. We don't need it for the PHB4 since the
      device id is already set in the root port complex. PH5 will introduce
      its own.
      
      "device-id" property is now useless. It should be removed.
      
      Signed-off-by: default avatarCédric Le Goater <clg@kaod.org>
      Reviewed-by: default avatarDaniel Henrique Barboza <danielhb413@gmail.com>
      Message-Id: <20211222063817.1541058-3-clg@kaod.org>
      Signed-off-by: default avatarCédric Le Goater <clg@kaod.org>
      81fbb57b
  3. Dec 30, 2021
  4. Dec 17, 2021
  5. Jul 26, 2021
  6. Feb 09, 2021
  7. Jan 04, 2021
  8. Sep 09, 2020
  9. Jul 10, 2020
    • Markus Armbruster's avatar
      error: Eliminate error_propagate() with Coccinelle, part 1 · 668f62ec
      Markus Armbruster authored
      
      When all we do with an Error we receive into a local variable is
      propagating to somewhere else, we can just as well receive it there
      right away.  Convert
      
          if (!foo(..., &err)) {
              ...
              error_propagate(errp, err);
              ...
              return ...
          }
      
      to
      
          if (!foo(..., errp)) {
              ...
              ...
              return ...
          }
      
      where nothing else needs @err.  Coccinelle script:
      
          @rule1 forall@
          identifier fun, err, errp, lbl;
          expression list args, args2;
          binary operator op;
          constant c1, c2;
          symbol false;
          @@
               if (
          (
          -        fun(args, &err, args2)
          +        fun(args, errp, args2)
          |
          -        !fun(args, &err, args2)
          +        !fun(args, errp, args2)
          |
          -        fun(args, &err, args2) op c1
          +        fun(args, errp, args2) op c1
          )
                  )
               {
                   ... when != err
                       when != lbl:
                       when strict
          -        error_propagate(errp, err);
                   ... when != err
          (
                   return;
          |
                   return c2;
          |
                   return false;
          )
               }
      
          @rule2 forall@
          identifier fun, err, errp, lbl;
          expression list args, args2;
          expression var;
          binary operator op;
          constant c1, c2;
          symbol false;
          @@
          -    var = fun(args, &err, args2);
          +    var = fun(args, errp, args2);
               ... when != err
               if (
          (
                   var
          |
                   !var
          |
                   var op c1
          )
                  )
               {
                   ... when != err
                       when != lbl:
                       when strict
          -        error_propagate(errp, err);
                   ... when != err
          (
                   return;
          |
                   return c2;
          |
                   return false;
          |
                   return var;
          )
               }
      
          @depends on rule1 || rule2@
          identifier err;
          @@
          -    Error *err = NULL;
               ... when != err
      
      Not exactly elegant, I'm afraid.
      
      The "when != lbl:" is necessary to avoid transforming
      
               if (fun(args, &err)) {
                   goto out
               }
               ...
           out:
               error_propagate(errp, err);
      
      even though other paths to label out still need the error_propagate().
      For an actual example, see sclp_realize().
      
      Without the "when strict", Coccinelle transforms vfio_msix_setup(),
      incorrectly.  I don't know what exactly "when strict" does, only that
      it helps here.
      
      The match of return is narrower than what I want, but I can't figure
      out how to express "return where the operand doesn't use @err".  For
      an example where it's too narrow, see vfio_intx_enable().
      
      Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
      confused by ARMSSE being used both as typedef and function-like macro
      there.  Converted manually.
      
      Line breaks tidied up manually.  One nested declaration of @local_err
      deleted manually.  Preexisting unwanted blank line dropped in
      hw/riscv/sifive_e.c.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-35-armbru@redhat.com>
      668f62ec
    • Markus Armbruster's avatar
      qom: Put name parameter before value / visitor parameter · 5325cc34
      Markus Armbruster authored
      
      The object_property_set_FOO() setters take property name and value in
      an unusual order:
      
          void object_property_set_FOO(Object *obj, FOO_TYPE value,
                                       const char *name, Error **errp)
      
      Having to pass value before name feels grating.  Swap them.
      
      Same for object_property_set(), object_property_get(), and
      object_property_parse().
      
      Convert callers with this Coccinelle script:
      
          @@
          identifier fun = {
              object_property_get, object_property_parse, object_property_set_str,
              object_property_set_link, object_property_set_bool,
              object_property_set_int, object_property_set_uint, object_property_set,
              object_property_set_qobject
          };
          expression obj, v, name, errp;
          @@
          -    fun(obj, v, name, errp)
          +    fun(obj, name, v, errp)
      
      Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
      message "no position information".  Convert that one manually.
      
      Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
      ARMSSE being used both as typedef and function-like macro there.
      Convert manually.
      
      Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
      by RXCPU being used both as typedef and function-like macro there.
      Convert manually.  The other files using RXCPU that way don't need
      conversion.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-27-armbru@redhat.com>
      [Straightforwad conflict with commit 2336172d "audio: set default
      value for pcspk.iobase property" resolved]
      5325cc34
    • Markus Armbruster's avatar
      qdev: Use returned bool to check for qdev_realize() etc. failure · 118bfd76
      Markus Armbruster authored
      
      Convert
      
          foo(..., &err);
          if (err) {
              ...
          }
      
      to
      
          if (!foo(..., &err)) {
              ...
          }
      
      for qdev_realize(), qdev_realize_and_unref(), qbus_realize() and their
      wrappers isa_realize_and_unref(), pci_realize_and_unref(),
      sysbus_realize(), sysbus_realize_and_unref(), usb_realize_and_unref().
      Coccinelle script:
      
          @@
          identifier fun = {
              isa_realize_and_unref, pci_realize_and_unref, qbus_realize,
              qdev_realize, qdev_realize_and_unref, sysbus_realize,
              sysbus_realize_and_unref, usb_realize_and_unref
          };
          expression list args, args2;
          typedef Error;
          Error *err;
          @@
          -    fun(args, &err, args2);
          -    if (err)
          +    if (!fun(args, &err, args2))
               {
                   ...
               }
      
      Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
      message "no position information".  Nothing to convert there; skipped.
      
      Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
      ARMSSE being used both as typedef and function-like macro there.
      Converted manually.
      
      A few line breaks tidied up manually.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Reviewed-by: default avatarGreg Kurz <groug@kaod.org>
      Message-Id: <20200707160613.848843-5-armbru@redhat.com>
      118bfd76
  10. Jun 15, 2020
    • Markus Armbruster's avatar
      qdev: Convert bus-less devices to qdev_realize() with Coccinelle · ce189ab2
      Markus Armbruster authored
      
      All remaining conversions to qdev_realize() are for bus-less devices.
      Coccinelle script:
      
          // only correct for bus-less @dev!
      
          @@
          expression errp;
          expression dev;
          @@
          -    qdev_init_nofail(dev);
          +    qdev_realize(dev, NULL, &error_fatal);
      
          @ depends on !(file in "hw/core/qdev.c") && !(file in "hw/core/bus.c")@
          expression errp;
          expression dev;
          symbol true;
          @@
          -    object_property_set_bool(OBJECT(dev), true, "realized", errp);
          +    qdev_realize(DEVICE(dev), NULL, errp);
      
          @ depends on !(file in "hw/core/qdev.c") && !(file in "hw/core/bus.c")@
          expression errp;
          expression dev;
          symbol true;
          @@
          -    object_property_set_bool(dev, true, "realized", errp);
          +    qdev_realize(DEVICE(dev), NULL, errp);
      
      Note that Coccinelle chokes on ARMSSE typedef vs. macro in
      hw/arm/armsse.c.  Worked around by temporarily renaming the macro for
      the spatch run.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Acked-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <20200610053247.1583243-57-armbru@redhat.com>
      ce189ab2
    • Markus Armbruster's avatar
      qom: Less verbose object_initialize_child() · 9fc7fc4d
      Markus Armbruster authored
      
      All users of object_initialize_child() pass the obvious child size
      argument.  Almost all pass &error_abort and no properties.  Tiresome.
      
      Rename object_initialize_child() to
      object_initialize_child_with_props() to free the name.  New
      convenience wrapper object_initialize_child() automates the size
      argument, and passes &error_abort and no properties.
      
      Rename object_initialize_childv() to
      object_initialize_child_with_propsv() for consistency.
      
      Convert callers with this Coccinelle script:
      
          @@
          expression parent, propname, type;
          expression child, size;
          symbol error_abort;
          @@
          -    object_initialize_child(parent, propname, OBJECT(child), size, type, &error_abort, NULL)
          +    object_initialize_child(parent, propname, child, size, type, &error_abort, NULL)
      
          @@
          expression parent, propname, type;
          expression child;
          symbol error_abort;
          @@
          -    object_initialize_child(parent, propname, child, sizeof(*child), type, &error_abort, NULL)
          +    object_initialize_child(parent, propname, child, type)
      
          @@
          expression parent, propname, type;
          expression child;
          symbol error_abort;
          @@
          -    object_initialize_child(parent, propname, &child, sizeof(child), type, &error_abort, NULL)
          +    object_initialize_child(parent, propname, &child, type)
      
          @@
          expression parent, propname, type;
          expression child, size, err;
          expression list props;
          @@
          -    object_initialize_child(parent, propname, child, size, type, err, props)
          +    object_initialize_child_with_props(parent, propname, child, size, type, err, props)
      
      Note that Coccinelle chokes on ARMSSE typedef vs. macro in
      hw/arm/armsse.c.  Worked around by temporarily renaming the macro for
      the spatch run.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Acked-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      [Rebased: machine opentitan is new (commit fe0fe473)]
      Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <20200610053247.1583243-37-armbru@redhat.com>
      9fc7fc4d
    • Markus Armbruster's avatar
      qom: Tidy up a few object_initialize_child() calls · 19dc7e97
      Markus Armbruster authored
      
      The callers of object_initialize_child() commonly  pass either
      &child, sizeof(child), or pchild, sizeof(*pchild).  Tidy up the few
      that don't, mostly to keep the next commit simpler.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <20200610053247.1583243-36-armbru@redhat.com>
      19dc7e97
    • Markus Armbruster's avatar
      qdev: Convert uses of qdev_set_parent_bus() with Coccinelle · 99ba777e
      Markus Armbruster authored
      
      In addition to the qdev_create() patterns converted so far, we have a
      qdev_set_parent_bus() pattern.  Mostly when we embed a device in a
      parent device rather than allocating it on the heap.
      
      This pattern also puts devices in the dangerous "no QOM parent, but
      plugged into bus" state I explained in recent commit "qdev: New
      qdev_new(), qdev_realize(), etc."
      
      Apply same solution: convert to qdev_realize().  Coccinelle script:
      
          @@
          expression dev, bus, errp;
          symbol true;
          @@
          -    qdev_set_parent_bus(DEVICE(dev), bus);
               ...
          -    object_property_set_bool(OBJECT(dev), true, "realized", errp);
          +    qdev_realize(DEVICE(dev), bus, errp);
      
          @ depends on !(file in "qdev-monitor.c") && !(file in "hw/core/qdev.c")@
          expression dev, bus, errp;
          symbol true;
          @@
          -    qdev_set_parent_bus(dev, bus);
               ...
          -    object_property_set_bool(OBJECT(dev), true, "realized", errp);
          +    qdev_realize(dev, bus, errp);
      
          @@
          expression dev, bus;
          symbol true;
          @@
          -    qdev_set_parent_bus(DEVICE(dev), bus);
               ...
          -    qdev_init_nofail(DEVICE(dev));
          +    qdev_realize(DEVICE(dev), bus, &error_fatal);
      
      Unconverted uses of qdev_set_parent_bus() remain.  They'll be
      converted later in this series.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <20200610053247.1583243-12-armbru@redhat.com>
      [Also convert new hw/virtio/vhost-user-vsock-pci.c]
      99ba777e
  11. Feb 02, 2020
    • Cédric Le Goater's avatar
      ppc/pnv: change the PowerNV machine devices to be non user creatable · 23a782eb
      Cédric Le Goater authored
      
      The PowerNV machine emulates an OpenPOWER system and the PowerNV chip
      devices are models of the internal logic of the POWER processor. They
      can not be instantiated by the user on the QEMU command line.
      
      The PHB3/PHB4 devices could be an exception in the future after some
      rework on how the device tree is built. For the moment, exclude them
      also.
      
      Signed-off-by: default avatarCédric Le Goater <clg@kaod.org>
      Message-Id: <20200129113720.7404-1-clg@kaod.org>
      Tested-by: default avatarThomas Huth <thuth@redhat.com>
      Reviewed-by: default avatarGreg Kurz <groug@kaod.org>
      Signed-off-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
      23a782eb
    • Benjamin Herrenschmidt's avatar
      ppc/pnv: Add models for POWER9 PHB4 PCIe Host bridge · 4f9924c4
      Benjamin Herrenschmidt authored
      
      These changes introduces models for the PCIe Host Bridge (PHB4) of the
      POWER9 processor. It includes the PowerBus logic interface (PBCQ),
      IOMMU support, a single PCIe Gen.4 Root Complex, and support for MSI
      and LSI interrupt sources as found on a POWER9 system using the XIVE
      interrupt controller.
      
      POWER9 processor comes with 3 PHB4 PEC (PCI Express Controller) and
      each PEC can have several PHBs. By default,
      
        * PEC0 provides 1 PHB  (PHB0)
        * PEC1 provides 2 PHBs (PHB1 and PHB2)
        * PEC2 provides 3 PHBs (PHB3, PHB4 and PHB5)
      
      Each PEC has a set  "global" registers and some "per-stack" (per-PHB)
      registers. Those are organized in two XSCOM ranges, the "Nest" range
      and the "PCI" range, each range contains both some "PEC" registers and
      some "per-stack" registers.
      
      No default device layout is provided and PCI devices can be added on
      any of the available PCIe Root Port (pcie.0 .. 2 of a Power9 chip)
      with address 0x0 as the firwware (skiboot) only accepts a single
      device per root port. To run a simple system with a network and a
      storage adapters, use a command line options such as :
      
        -device e1000e,netdev=net0,mac=C0:FF:EE:00:00:02,bus=pcie.0,addr=0x0
        -netdev bridge,id=net0,helper=/usr/libexec/qemu-bridge-helper,br=virbr0,id=hostnet0
      
        -device megasas,id=scsi0,bus=pcie.1,addr=0x0
        -drive file=$disk,if=none,id=drive-scsi0-0-0-0,format=qcow2,cache=none
        -device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0-0-0-0,id=scsi0-0-0-0,bootindex=2
      
      If more are needed, include a bridge.
      
      Multi chip is supported, each chip adding its set of PHB4 controllers
      and its PCI busses. The model doesn't emulate the EEH error handling.
      
      This model is not ready for hotplug yet.
      
      Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
      [ clg: - numerous cleanups
             - commit log
             - fix for broken LSI support
             - PHB pic printinfo
             - large QOM rework ]
      Signed-off-by: default avatarCédric Le Goater <clg@kaod.org>
      Message-Id: <20200127144506.11132-2-clg@kaod.org>
      [dwg: Use device_class_set_props()]
      Signed-off-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
      4f9924c4
Loading