1. 04 7月, 2017 1 次提交
  2. 17 5月, 2017 2 次提交
    • E
      fw_cfg: Remove user_creatable flag · 731fec79
      Eduardo Habkost 提交于
      fw_cfg won't work with -device, as:
      * fw_cfg_init1() won't get called for the device;
      * The device won't appear at /machine/fw_cfg, and won't work with
        the -fw_cfg command-line option.
      
      Remove the user_creatable flag from the device class.
      
      Cc: Marcel Apfelbaum <marcel@redhat.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Laszlo Ersek <lersek@redhat.com>
      Cc: Gabriel L. Somlo <somlo@cmu.edu>
      Reviewed-by: NLaszlo Ersek <lersek@redhat.com>
      Acked-by: NMarcel Apfelbaum <marcel@redhat.com>
      Signed-off-by: NEduardo Habkost <ehabkost@redhat.com>
      Message-Id: <20170503203604.31462-15-ehabkost@redhat.com>
      Signed-off-by: NEduardo Habkost <ehabkost@redhat.com>
      731fec79
    • E
      sysbus: Set user_creatable=false by default on TYPE_SYS_BUS_DEVICE · e4f4fb1e
      Eduardo Habkost 提交于
      commit 33cd52b5 unset
      cannot_instantiate_with_device_add_yet in TYPE_SYSBUS, making all
      sysbus devices appear on "-device help" and lack the "no-user"
      flag in "info qdm".
      
      To fix this, we can set user_creatable=false by default on
      TYPE_SYS_BUS_DEVICE, but this requires setting
      user_creatable=true explicitly on the sysbus devices that
      actually work with -device.
      
      Fortunately today we have just a few has_dynamic_sysbus=1
      machines: virt, pc-q35-*, ppce500, and spapr.
      
      virt, ppce500, and spapr have extra checks to ensure just a few
      device types can be instantiated:
      
      * virt supports only TYPE_VFIO_CALXEDA_XGMAC, TYPE_VFIO_AMD_XGBE.
      * ppce500 supports only TYPE_ETSEC_COMMON.
      * spapr supports only TYPE_SPAPR_PCI_HOST_BRIDGE.
      
      This patch sets user_creatable=true explicitly on those 4 device
      classes.
      
      Now, the more complex cases:
      
      pc-q35-*: q35 has no sysbus device whitelist yet (which is a
      separate bug). We are in the process of fixing it and building a
      sysbus whitelist on q35, but in the meantime we can fix the
      "-device help" and "info qdm" bugs mentioned above. Also, despite
      not being strictly necessary for fixing the q35 bug, reducing the
      list of user_creatable=true devices will help us be more
      confident when building the q35 whitelist.
      
      xen: We also have a hack at xen_set_dynamic_sysbus(), that sets
      has_dynamic_sysbus=true at runtime when using the Xen
      accelerator. This hack is only used to allow xen-backend devices
      to be dynamically plugged/unplugged.
      
      This means today we can use -device with the following 22 device
      types, that are the ones compiled into the qemu-system-x86_64 and
      qemu-system-i386 binaries:
      
      * allwinner-ahci
      * amd-iommu
      * cfi.pflash01
      * esp
      * fw_cfg_io
      * fw_cfg_mem
      * generic-sdhci
      * hpet
      * intel-iommu
      * ioapic
      * isabus-bridge
      * kvmclock
      * kvm-ioapic
      * kvmvapic
      * SUNW,fdtwo
      * sysbus-ahci
      * sysbus-fdc
      * sysbus-ohci
      * unimplemented-device
      * virtio-mmio
      * xen-backend
      * xen-sysdev
      
      This patch adds user_creatable=true explicitly to those devices,
      temporarily, just to keep 100% compatibility with existing
      behavior of q35. Subsequent patches will remove
      user_creatable=true from the devices that are really not meant to
      user-creatable on any machine, and remove the FIXME comment from
      the ones that are really supposed to be user-creatable. This is
      being done in separate patches because we still don't have an
      obvious list of devices that will be whitelisted by q35, and I
      would like to get each device reviewed individually.
      
      Cc: Alexander Graf <agraf@suse.de>
      Cc: Alex Williamson <alex.williamson@redhat.com>
      Cc: Alistair Francis <alistair.francis@xilinx.com>
      Cc: Beniamino Galvani <b.galvani@gmail.com>
      Cc: Christian Borntraeger <borntraeger@de.ibm.com>
      Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
      Cc: David Gibson <david@gibson.dropbear.id.au>
      Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
      Cc: Eduardo Habkost <ehabkost@redhat.com>
      Cc: Frank Blaschka <frank.blaschka@de.ibm.com>
      Cc: Gabriel L. Somlo <somlo@cmu.edu>
      Cc: Gerd Hoffmann <kraxel@redhat.com>
      Cc: Igor Mammedov <imammedo@redhat.com>
      Cc: Jason Wang <jasowang@redhat.com>
      Cc: John Snow <jsnow@redhat.com>
      Cc: Juergen Gross <jgross@suse.com>
      Cc: Kevin Wolf <kwolf@redhat.com>
      Cc: Laszlo Ersek <lersek@redhat.com>
      Cc: Marcel Apfelbaum <marcel@redhat.com>
      Cc: Markus Armbruster <armbru@redhat.com>
      Cc: Max Reitz <mreitz@redhat.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Peter Maydell <peter.maydell@linaro.org>
      Cc: Pierre Morel <pmorel@linux.vnet.ibm.com>
      Cc: Prasad J Pandit <pjp@fedoraproject.org>
      Cc: qemu-arm@nongnu.org
      Cc: qemu-block@nongnu.org
      Cc: qemu-ppc@nongnu.org
      Cc: Richard Henderson <rth@twiddle.net>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Shannon Zhao <zhaoshenglong@huawei.com>
      Cc: sstabellini@kernel.org
      Cc: Thomas Huth <thuth@redhat.com>
      Cc: Yi Min Zhao <zyimin@linux.vnet.ibm.com>
      Acked-by: NJohn Snow <jsnow@redhat.com>
      Acked-by: NJuergen Gross <jgross@suse.com>
      Acked-by: NMarcel Apfelbaum <marcel@redhat.com>
      Signed-off-by: NEduardo Habkost <ehabkost@redhat.com>
      Message-Id: <20170503203604.31462-3-ehabkost@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      [ehabkost: Small changes at sysbus_device_class_init() comments]
      Signed-off-by: NEduardo Habkost <ehabkost@redhat.com>
      e4f4fb1e
  3. 25 1月, 2017 1 次提交
  4. 19 1月, 2017 3 次提交
    • L
      fw-cfg: bump "x-file-slots" to 0x20 for 2.9+ machine types · a5b3ebfd
      Laszlo Ersek 提交于
      More precisely, the "x-file-slots" count is bumped for all machine types
      that:
      (a) use fw_cfg, and
      (b) are not versioned (hence migration is not expected to work for them
          across QEMU releases anyway), or have version 2.9.
      
      This affects machine types implemented in the following source files:
      
      - "hw/arm/virt.c". The "virt-*" machine type is versioned, and the <= 2.8
        versions already depend on HW_COMPAT_2_8 (see commit e353aac5).
        Therefore adding the "x-file-slots" compat values to HW_COMPAT_2_8
        suffices.
      
      - "hw/i386/pc.c". The "pc-i440fx-*" (including "pc-*") and "pc-q35-*"
        machine types are versioned. Modifying HW_COMPAT_2_8 is sufficient here
        too (see commit "pc: Add 2.9 machine-types"). The "isapc" machtype is
        not versioned. The "xenfv" machine type, which uses fw_cfg for direct
        kernel booting, is also not versioned.
      
      - "hw/ppc/mac_newworld.c". The "mac99" machine type is not versioned.
      
      - "hw/ppc/mac_oldworld.c". The "g3beige" machine type is not versioned.
      
      - "hw/sparc/sun4m.c". None of the 9 machine types defined in this file
        appear versioned.
      
      - "hw/sparc64/sun4u.c". None of the 3 machine types defined in this file
        appear versioned.
      
      Cc: "Gabriel L. Somlo" <somlo@cmu.edu>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Alexander Graf <agraf@suse.de>
      Cc: Anthony Perard <anthony.perard@citrix.com>
      Cc: Artyom Tarasenko <atar4qemu@gmail.com>
      Cc: David Gibson <david@gibson.dropbear.id.au>
      Cc: Eduardo Habkost <ehabkost@redhat.com>
      Cc: Gerd Hoffmann <kraxel@redhat.com>
      Cc: Igor Mammedov <imammedo@redhat.com>
      Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Peter Maydell <peter.maydell@linaro.org>
      Cc: Stefano Stabellini <sstabellini@kernel.org>
      Signed-off-by: NLaszlo Ersek <lersek@redhat.com>
      Acked-by: NGabriel Somlo <somlo@cmu.edu>
      Tested-by: NGabriel Somlo <somlo@cmu.edu>
      Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      Reviewed-by: NEduardo Habkost <ehabkost@redhat.com>
      a5b3ebfd
    • L
      fw-cfg: turn FW_CFG_FILE_SLOTS into a device property · e12f3a13
      Laszlo Ersek 提交于
      We'd like to raise the value of FW_CFG_FILE_SLOTS. Doing it naively could
      lead to problems with backward migration: a more recent QEMU (running an
      older machine type) would allow the guest, in fw_cfg_select(), to select a
      high key value that is unavailable in the same machine type implemented by
      the older (target) QEMU. On the target host, fw_cfg_data_read() for
      example could dereference nonexistent entries.
      
      As first step, size the FWCfgState.entries[*] and FWCfgState.entry_order
      arrays dynamically. All three array sizes will be influenced by the new
      field FWCfgState.file_slots (and matching device property).
      
      Make the following changes:
      
      - Replace the FW_CFG_FILE_SLOTS macro with FW_CFG_FILE_SLOTS_MIN (minimum
        count of fw_cfg file slots) in the header file. The value remains 0x10.
      
      - Replace all uses of FW_CFG_FILE_SLOTS with a helper function called
        fw_cfg_file_slots(), returning the new property.
      
      - Eliminate the macro FW_CFG_MAX_ENTRY, and replace all its uses with a
        helper function called fw_cfg_max_entry().
      
      - In the MMIO- and IO-mapped realize functions both, allocate all three
        arrays dynamically, based on the new property.
      
      - The new property defaults to FW_CFG_FILE_SLOTS_MIN. This is going to be
        customized in the following patches.
      
      Cc: "Gabriel L. Somlo" <somlo@cmu.edu>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Gerd Hoffmann <kraxel@redhat.com>
      Cc: Igor Mammedov <imammedo@redhat.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NLaszlo Ersek <lersek@redhat.com>
      Acked-by: NGabriel Somlo <somlo@cmu.edu>
      Tested-by: NGabriel Somlo <somlo@cmu.edu>
      Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      Reviewed-by: NEduardo Habkost <ehabkost@redhat.com>
      e12f3a13
    • M
      fw-cfg: support writeable blobs · baf2d5bf
      Michael S. Tsirkin 提交于
      Useful to send guest data back to QEMU.
      
      Changes from Laszlo Ersek <lersek@redhat.com>:
      - rebase the patch from Michael Tsirkin's original postings at [1] and [2]
        to the following patches:
        - loader: Allow a custom AddressSpace when loading ROMs
        - loader: Add AddressSpace loading support to uImages
        - loader: fix handling of custom address spaces when adding ROM blobs
      - reject such writes immediately that would exceed the end of the array,
        rather than performing a partial write before setting the error bit: see
        the (len != dma.length) condition
      - document the write interface
      
      [1] http://lists.nongnu.org/archive/html/qemu-devel/2016-02/msg04968.html
      [2] http://lists.nongnu.org/archive/html/qemu-devel/2016-03/msg02735.html
      
      Cc: "Gabriel L. Somlo" <somlo@cmu.edu>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Gerd Hoffmann <kraxel@redhat.com>
      Cc: Igor Mammedov <imammedo@redhat.com>
      Cc: Michael Walle <michael@walle.cc>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Peter Maydell <peter.maydell@linaro.org>
      Cc: Shannon Zhao <zhaoshenglong@huawei.com>
      Cc: qemu-arm@nongnu.org
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: NLaszlo Ersek <lersek@redhat.com>
      Reviewed-by: NMarcel Apfelbaum <marcel@redhat.com>
      Acked-by: NGabriel Somlo <somlo@cmu.edu>
      Tested-by: NGabriel Somlo <somlo@cmu.edu>
      Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      Reviewed-by: NEduardo Habkost <ehabkost@redhat.com>
      baf2d5bf
  5. 16 11月, 2016 1 次提交
  6. 28 10月, 2016 1 次提交
  7. 23 9月, 2016 1 次提交
  8. 15 9月, 2016 1 次提交
  9. 08 8月, 2016 1 次提交
  10. 04 8月, 2016 1 次提交
  11. 14 7月, 2016 1 次提交
  12. 07 6月, 2016 1 次提交
  13. 21 5月, 2016 1 次提交
    • E
      vl: Replace DT_NOGRAPHIC with machine option · cfc58cf3
      Eduardo Habkost 提交于
      All DisplayType values are just UI options that don't affect any
      hardware emulation code, except for DT_NOGRAPHIC. Replace
      DT_NOGRAPHIC with DT_NONE plus a new "-machine graphics=on|off"
      option, so hardware emulation code don't need to use the
      display_type variable.
      
      Cc: Michael Walle <michael@walle.cc>
      Cc: Blue Swirl <blauwirbel@gmail.com>
      Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
      Signed-off-by: NEduardo Habkost <ehabkost@redhat.com>
      cfc58cf3
  14. 08 4月, 2016 1 次提交
    • G
      Sort the fw_cfg file list · bab47d9a
      Gerd Hoffmann 提交于
      Entries are inserted in filename order instead of being
      appended to the end in case sorting is enabled.
      
      This will avoid any future issues of moving the file creation
      around, it doesn't matter what order they are created now,
      the will always be in filename order.
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      
      Added machine type handling for compatibility.  This was
      a fairly complex change, this will preserve the order of fw_cfg
      for older versions no matter what order the firmware files
      actually come in.  A list is kept of the correct legacy order
      and the entries will be inserted based upon their order in
      the list.  Except that some entries are ordered (in a specific
      area of the list) based upon what order they appear on the
      command line.  Special handling is added for those entries.
      Signed-off-by: NCorey Minyard <cminyard@mvista.com>
      Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      bab47d9a
  15. 23 3月, 2016 1 次提交
  16. 08 3月, 2016 1 次提交
  17. 26 2月, 2016 1 次提交
  18. 29 1月, 2016 1 次提交
    • P
      hw: Clean up includes · 0430891c
      Peter Maydell 提交于
      Clean up includes so that osdep.h is included first and headers
      which it implies are not included manually.
      
      This commit was created with scripts/clean-includes.
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      Message-id: 1453832250-766-38-git-send-email-peter.maydell@linaro.org
      0430891c
  19. 15 12月, 2015 5 次提交
    • G
      fw_cfg: replace ioport data read with generic method · 6c8d56a2
      Gabriel L. Somlo 提交于
      IOPort read access is limited to one byte at a time by
      fw_cfg_comb_valid(). As such, fw_cfg_comb_read() may safely
      ignore its size argument (which will always be 1), and simply
      call its fw_cfg_read() helper function once, returning 8 bits
      via the least significant byte of a 64-bit return value.
      
      This patch replaces fw_cfg_comb_read() with the generic method
      fw_cfg_data_read(), and removes the unused fw_cfg_read() helper.
      
      When called with size = 1, fw_cfg_data_read() acts exactly like
      fw_cfg_read(), performing the same set of sanity checks, and
      executing the while loop at most once (subject to the current
      read offset being within range).
      
      Cc: Laszlo Ersek <lersek@redhat.com>
      Cc: Gerd Hoffmann <kraxel@redhat.com>
      Cc: Marc Marí <markmb@redhat.com>
      Signed-off-by: NGabriel Somlo <somlo@cmu.edu>
      Message-id: 1446733972-1602-7-git-send-email-somlo@cmu.edu
      Reviewed-by: NLaszlo Ersek <lersek@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      6c8d56a2
    • G
      fw_cfg: add generic non-DMA read method · 38bf2093
      Gabriel L. Somlo 提交于
      Introduce fw_cfg_data_read(), a generic read method which works
      on all access widths (1 through 8 bytes, inclusive), and can be
      used during both IOPort and MMIO read accesses.
      
      To maintain legibility, only fw_cfg_data_mem_read() (the MMIO
      data read method) is replaced by this patch. The new method
      essentially unwinds the fw_cfg_data_mem_read() + fw_cfg_read()
      combo, but without unnecessarily repeating all the validity
      checks performed by the latter on each byte being read.
      
      This patch also modifies the trace_fw_cfg_read prototype to
      accept a 64-bit value argument, allowing it to work properly
      with the new read method, but also remain backward compatible
      with existing call sites.
      
      Cc: Laszlo Ersek <lersek@redhat.com>
      Cc: Gerd Hoffmann <kraxel@redhat.com>
      Cc: Marc Marí <markmb@redhat.com>
      Signed-off-by: NGabriel Somlo <somlo@cmu.edu>
      Reviewed-by: NLaszlo Ersek <lersek@redhat.com>
      Message-id: 1446733972-1602-6-git-send-email-somlo@cmu.edu
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      38bf2093
    • G
      fw_cfg: avoid calculating invalid current entry pointer · 66f8fd9d
      Gabriel L. Somlo 提交于
      When calculating a pointer to the currently selected fw_cfg item, the
      following is used:
      
        FWCfgEntry *e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
      
      When s->cur_entry is FW_CFG_INVALID, we are calculating the address of
      a non-existent element in s->entries[arch][...], which is undefined.
      
      This patch ensures the resulting entry pointer is set to NULL whenever
      s->cur_entry is FW_CFG_INVALID.
      Reported-by: NLaszlo Ersek <lersek@redhat.com>
      Reviewed-by: NLaszlo Ersek <lersek@redhat.com>
      Signed-off-by: NGabriel Somlo <somlo@cmu.edu>
      Message-id: 1446733972-1602-5-git-send-email-somlo@cmu.edu
      Cc: Marc Marí <markmb@redhat.com>
      Signed-off-by: NGabriel Somlo <somlo@cmu.edu>
      Reviewed-by: NLaszlo Ersek <lersek@redhat.com>
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      66f8fd9d
    • G
      fw_cfg: remove offset argument from callback prototype · 3f8752b4
      Gabriel L. Somlo 提交于
      Read callbacks are now only invoked at item selection, before any
      data is read. As such, the value of the offset argument passed to
      the callback will always be 0. Also, the two callback instances
      currently in use both leave their offset argument unused.
      
      This patch removes the offset argument from the fw_cfg read callback
      prototype, and from the currently available instances. The unused
      (write) callback prototype is also removed (write support was removed
      earlier, in commit 023e3148).
      
      Cc: Laszlo Ersek <lersek@redhat.com>
      Cc: Gerd Hoffmann <kraxel@redhat.com>
      Cc: Marc Marí <markmb@redhat.com>
      Signed-off-by: NGabriel Somlo <somlo@cmu.edu>
      Reviewed-by: NLaszlo Ersek <lersek@redhat.com>
      Message-id: 1446733972-1602-4-git-send-email-somlo@cmu.edu
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      3f8752b4
    • G
      fw_cfg: amend callback behavior spec to once per select · 3bef7e8a
      Gabriel L. Somlo 提交于
      Currently, the fw_cfg internal API specifies that if an item was set up
      with a read callback, the callback must be run each time a byte is read
      from the item. This behavior is both wasteful (most items do not have a
      read callback set), and impractical for bulk transfers (e.g., DMA read).
      
      At the time of this writing, the only items configured with a callback
      are "/etc/table-loader", "/etc/acpi/tables", and "/etc/acpi/rsdp". They
      all share the same callback functions: virt_acpi_build_update() on ARM
      (in hw/arm/virt-acpi-build.c), and acpi_build_update() on i386 (in
      hw/i386/acpi.c). Both of these callbacks are one-shot (i.e. they return
      without doing anything at all after the first time they are invoked with
      a given build_state; since build_state is also shared across all three
      items mentioned above, the callback only ever runs *once*, the first
      time either of the listed items is read).
      
      This patch amends the specification for fw_cfg_add_file_callback() to
      state that any available read callback will only be invoked once each
      time the item is selected. This change has no practical effect on the
      current behavior of QEMU, and it enables us to significantly optimize
      the behavior of fw_cfg reads during guest firmware setup, eliminating
      a large amount of redundant callback checks and invocations.
      
      Cc: Laszlo Ersek <lersek@redhat.com>
      Cc: Gerd Hoffmann <kraxel@redhat.com>
      Cc: Marc Marí <markmb@redhat.com>
      Signed-off-by: NGabriel Somlo <somlo@cmu.edu>
      Reviewed-by: NLaszlo Ersek <lersek@redhat.com>
      Message-id: 1446733972-1602-3-git-send-email-somlo@cmu.edu
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      3bef7e8a
  20. 19 10月, 2015 2 次提交
  21. 11 9月, 2015 1 次提交
  22. 10 6月, 2015 4 次提交
  23. 25 3月, 2015 1 次提交
    • G
      fw_cfg: factor out initialization of FW_CFG_ID (rev. number) · 3a5c76ba
      Gabriel L. Somlo 提交于
      The fw_cfg documentation says this of the revision key (0x0001, FW_CFG_ID):
      
      > A 32-bit little-endian unsigned int, this item is used as an interface
      > revision number, and is currently set to 1 by all QEMU architectures
      > which expose a fw_cfg device.
      
      arm/virt doesn't.  It could be argued that that's an error in
      "hw/arm/virt.c"; on the other hand, all of the other fw_cfg providing
      boards set the interface version to 1 manually, despite the device
      coming from the same, shared implementation. Therefore, instead of
      adding
      
          fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
      
      to arm/virt, consolidate all such existing calls in the fw_cfg
      initialization code.
      Signed-off-by: NGabriel Somlo <somlo@cmu.edu>
      Message-Id: <1426789244-26318-1-git-send-email-somlo@cmu.edu>
      Reviewed-by: NLaszlo Ersek <lersek@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      3a5c76ba
  24. 19 3月, 2015 1 次提交
    • S
      Fix remaining warnings from Sparse (void return) · e7ae771f
      Stefan Weil 提交于
      Sparse report:
      
      hw/display/vga.c:2000:5: warning: returning void-valued expression
      hw/intc/arm_gic.c:707:9: warning: returning void-valued expression
      hw/intc/etraxfs_pic.c:138:9: warning: returning void-valued expression
      hw/nvram/fw_cfg.c:475:5: warning: returning void-valued expression
      hw/timer/a9gtimer.c:124:5: warning: returning void-valued expression
      hw/tpm/tpm_tis.c:794:5: warning: returning void-valued expression
      hw/usb/hcd-musb.c:558:9: warning: returning void-valued expression
      hw/usb/hcd-musb.c:776:13: warning: returning void-valued expression
      hw/usb/hcd-musb.c:867:5: warning: returning void-valued expression
      hw/usb/hcd-musb.c:932:5: warning: returning void-valued expression
      include/qom/cpu.h:584:5: warning: returning void-valued expression
      monitor.c:4686:13: warning: returning void-valued expression
      monitor.c:4690:13: warning: returning void-valued expression
      
      Cc: Edgar E. Iglesias <edgar.iglesias@gmail.com>
      Cc: Gerd Hoffmann <kraxel@redhat.com>
      Cc: Andreas Färber <afaerber@suse.de>
      Cc: Luiz Capitulino <lcapitulino@redhat.com>
      Signed-off-by: NStefan Weil <sw@weilnetz.de>
      Signed-off-by: NMichael Tokarev <mjt@tls.msk.ru>
      e7ae771f
  25. 16 1月, 2015 1 次提交
    • L
      fw_cfg: fix endianness in fw_cfg_data_mem_read() / _write() · 36b62ae6
      Laszlo Ersek 提交于
      (1) Let's contemplate what device endianness means, for a memory mapped
      device register (independently of QEMU -- that is, on physical hardware).
      
      It determines the byte order that the device will put on the data bus when
      the device is producing a *numerical value* for the CPU. This byte order
      may differ from the CPU's own byte order, therefore when software wants to
      consume the *numerical value*, it may have to swap the byte order first.
      
      For example, suppose we have a device that exposes in a 2-byte register
      the number of sheep we have to count before falling asleep. If the value
      is decimal 37 (0x0025), then a big endian register will produce [0x00,
      0x25], while a little endian register will produce [0x25, 0x00].
      
      If the device register is big endian, but the CPU is little endian, the
      numerical value will read as 0x2500 (decimal 9472), which software has to
      byte swap before use.
      
      However... if we ask the device about who stole our herd of sheep, and it
      answers "XY", then the byte representation coming out of the register must
      be [0x58, 0x59], regardless of the device register's endianness for
      numeric values. And, software needs to copy these bytes into a string
      field regardless of the CPU's own endianness.
      
      (2) QEMU's device register accessor functions work with *numerical values*
      exclusively, not strings:
      
      The emulated register's read accessor function returns the numerical value
      (eg. 37 decimal, 0x0025) as a *host-encoded* uint64_t. QEMU translates
      this value for the guest to the endianness of the emulated device register
      (which is recorded in MemoryRegionOps.endianness). Then guest code must
      translate the numerical value from device register to guest CPU
      endianness, before including it in any computation (see (1)).
      
      (3) However, the data register of the fw_cfg device shall transfer strings
      *only* -- that is, opaque blobs. Interpretation of any given blob is
      subject to further agreement -- it can be an integer in an independently
      determined byte order, or a genuine string, or an array of structs of
      integers (in some byte order) and fixed size strings, and so on.
      
      Because register emulation in QEMU is integer-preserving, not
      string-preserving (see (2)), we have to jump through a few hoops.
      
      (3a) We defined the memory mapped fw_cfg data register as
      DEVICE_BIG_ENDIAN.
      
      The particular choice is not really relevant -- we picked BE only for
      consistency with the control register, which *does* transfer integers --
      but our choice affects how we must host-encode values from fw_cfg strings.
      
      (3b) Since we want the fw_cfg string "XY" to appear as the [0x58, 0x59]
      array on the data register, *and* we picked DEVICE_BIG_ENDIAN, we must
      compose the host (== C language) value 0x5859 in the read accessor
      function.
      
      (3c) When the guest performs the read access, the immediate uint16_t value
      will be 0x5958 (in LE guests) and 0x5859 (in BE guests). However, the
      uint16_t value does not matter. The only thing that matters is the byte
      pattern [0x58, 0x59], which the guest code must copy into the target
      string *without* any byte-swapping.
      
      (4) Now I get to explain where I screwed up. :(
      
      When we decided for big endian *integer* representation in the MMIO data
      register -- see (3a) --, I mindlessly added an indiscriminate
      byte-swizzling step to the (little endian) guest firmware.
      
      This was a grave error -- it violates (3c) --, but I didn't realize it. I
      only saw that the code I otherwise intended for fw_cfg_data_mem_read():
      
          value = 0;
          for (i = 0; i < size; ++i) {
              value = (value << 8) | fw_cfg_read(s);
          }
      
      didn't produce the expected result in the guest.
      
      In true facepalm style, instead of blaming my guest code (which violated
      (3c)), I blamed my host code (which was correct). Ultimately, I coded
      ldX_he_p() into fw_cfg_data_mem_read(), because that happened to work.
      
      Obviously (...in retrospect) that was wrong. Only because my host happened
      to be LE, ldX_he_p() composed the (otherwise incorrect) host value 0x5958
      from the fw_cfg string "XY". And that happened to compensate for the bogus
      indiscriminate byte-swizzling in my guest code.
      
      Clearly the current code leaks the host endianness through to the guest,
      which is wrong. Any device should work the same regardless of host
      endianness.
      
      The solution is to compose the host-endian representation (2) of the big
      endian interpretation (3a, 3b) of the fw_cfg string, and to drop the wrong
      byte-swizzling in the guest (3c).
      
      Brown paper bag time for me.
      Signed-off-by: NLaszlo Ersek <lersek@redhat.com>
      Message-id: 1420024880-15416-1-git-send-email-lersek@redhat.com
      Reviewed-by: NPeter Maydell <peter.maydell@linaro.org>
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      36b62ae6
  26. 23 12月, 2014 4 次提交
    • L
      fw_cfg_mem: expose the "data_width" property with fw_cfg_init_mem_wide() · 6c87e3d5
      Laszlo Ersek 提交于
      We rebase fw_cfg_init_mem() to the new function for compatibility with
      current callers.
      
      The behavior of the (big endian) multi-byte data reads is best shown
      with a qtest session.  Here, we are reading the first six bytes of
      the UUID
      
          $ arm-softmmu/qemu-system-arm -M virt -machine accel=qtest \
               -qtest stdio -uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8
      >>> writew 0x9020008 0x0200
      <<< OK
      >>> readl 0x9020000
      <<< OK 0x000000004600cb32
      
      Remember this is big endian.  On big endian machines, it is stored
      directly as 0x46 0x00 0xcb 0x32.
      
      On a little endian machine, we have to first swap it, so that it becomes
      0x32cb0046.  When written to memory, it becomes 0x46 0x00 0xcb 0x32
      again.
      
      Reading byte-by-byte works too, of course:
      
      >>> readb 0x9020000
      <<< OK 0x0000000000000038
      >>> readb 0x9020000
      <<< OK 0x00000000000000ec
      
      Here only a single byte is read at a time, so they are read in order
      similar to the 1-byte data port that is already in PPC and SPARC
      machines.
      Signed-off-by: NLaszlo Ersek <lersek@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-id: 1419250305-31062-8-git-send-email-pbonzini@redhat.com
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      6c87e3d5
    • L
      fw_cfg_mem: introduce the "data_width" property · cfaadf0e
      Laszlo Ersek 提交于
      The "data_width" property is capable of changing the maximum valid access
      size to the MMIO data register, and resizes the memory region similarly,
      at device realization time.
      
      The default value of "data_memwidth" is set so that we don't yet diverge
      from "fw_cfg_data_mem_ops".
      
      Most of the fw_cfg_mem users will stick with the default, and for them we
      should continue using the statically allocated "fw_cfg_data_mem_ops". This
      is beneficial for debugging because gdb can resolve pointers referencing
      static objects to the names of those objects.
      Signed-off-by: NLaszlo Ersek <lersek@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-id: 1419250305-31062-7-git-send-email-pbonzini@redhat.com
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      cfaadf0e
    • L
      fw_cfg_mem: flip ctl_mem_ops and data_mem_ops to DEVICE_BIG_ENDIAN · d789c845
      Laszlo Ersek 提交于
      The standalone selector port (fw_cfg_ctl_mem_ops) is only used by big
      endian guests to date (*), hence this change doesn't regress them. Paolo
      and Alex have suggested / requested an explicit DEVICE_BIG_ENDIAN setting
      here, for clarity.
      
      (*) git grep -l fw_cfg_init_mem
      
          hw/nvram/fw_cfg.c
          hw/ppc/mac_newworld.c
          hw/ppc/mac_oldworld.c
          hw/sparc/sun4m.c
          include/hw/nvram/fw_cfg.h
      
      The standalone data port (fw_cfg_data_mem_ops) has max_access_size 1 (for
      now), hence changing its endianness doesn't change behavior for existing
      guest code.
      Signed-off-by: NLaszlo Ersek <lersek@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-id: 1419250305-31062-5-git-send-email-pbonzini@redhat.com
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      d789c845
    • L
      fw_cfg_mem: max access size and region size are the same for data register · 86099db3
      Laszlo Ersek 提交于
      Make it clear that the maximum access size to the MMIO data register
      determines the full size of the memory region.
      
      Currently the max access size is 1.
      
      This patch doesn't change behavior.
      Signed-off-by: NLaszlo Ersek <lersek@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-id: 1419250305-31062-4-git-send-email-pbonzini@redhat.com
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      86099db3