Skip to content
Snippets Groups Projects
  1. Feb 11, 2022
  2. Feb 08, 2022
    • Peter Maydell's avatar
      Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20220208' into staging · 0a301624
      Peter Maydell authored
      
      target-arm queue:
       * Fix handling of SVE ZCR_LEN when using VHE
       * xlnx-zynqmp: 'Or' the QSPI / QSPI DMA IRQs
       * Don't ever enable PSCI when booting guest in EL3
       * Adhere to SMCCC 1.3 section 5.2
       * highbank: Fix issues with booting SMP
       * midway: Fix issues booting at all
       * boot: Drop existing dtb /psci node rather than retaining it
       * versal-virt: Always call arm_load_kernel()
       * force flag recalculation when messing with DAIF
       * hw/timer/armv7m_systick: Update clock source before enabling timer
       * hw/arm/smmuv3: Fix device reset
       * hw/intc/arm_gicv3_its: refactorings and minor bug fixes
       * hw/sensor: Add lsm303dlhc magnetometer device
      
      # gpg: Signature made Tue 08 Feb 2022 11:39:15 GMT
      # gpg:                using RSA key E1A5C593CD419DE28E8315CF3C2525ED14360CDE
      # gpg:                issuer "peter.maydell@linaro.org"
      # gpg: Good signature from "Peter Maydell <peter.maydell@linaro.org>" [ultimate]
      # gpg:                 aka "Peter Maydell <pmaydell@gmail.com>" [ultimate]
      # gpg:                 aka "Peter Maydell <pmaydell@chiark.greenend.org.uk>" [ultimate]
      # Primary key fingerprint: E1A5 C593 CD41 9DE2 8E83  15CF 3C25 25ED 1436 0CDE
      
      * remotes/pmaydell/tags/pull-target-arm-20220208: (39 commits)
        hw/sensor: Add lsm303dlhc magnetometer device
        hw/intc/arm_gicv3_its: Split error checks
        hw/intc/arm_gicv3_its: Don't allow intid 1023 in MAPI/MAPTI
        hw/intc/arm_gicv3_its: In MAPC with V=0, don't check rdbase field
        hw/intc/arm_gicv3_its: Drop TableDesc and CmdQDesc valid fields
        hw/intc/arm_gicv3_its: Make update_ite() use ITEntry
        hw/intc/arm_gicv3_its: Pass ITE values back from get_ite() via a struct
        hw/intc/arm_gicv3_its: Avoid nested ifs in get_ite()
        hw/intc/arm_gicv3_its: Fix address calculation in get_ite() and update_ite()
        hw/intc/arm_gicv3_its: Pass CTEntry to update_cte()
        hw/intc/arm_gicv3_its: Keep CTEs as a struct, not a raw uint64_t
        hw/intc/arm_gicv3_its: Pass DTEntry to update_dte()
        hw/intc/arm_gicv3_its: Keep DTEs as a struct, not a raw uint64_t
        hw/intc/arm_gicv3_its: Use address_space_map() to access command queue packets
        hw/arm/smmuv3: Fix device reset
        hw/timer/armv7m_systick: Update clock source before enabling timer
        arm: force flag recalculation when messing with DAIF
        hw/arm: versal-virt: Always call arm_load_kernel()
        hw/arm/boot: Drop existing dtb /psci node rather than retaining it
        hw/arm/boot: Drop nb_cpus field from arm_boot_info
        ...
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      0a301624
    • Kevin Townsend's avatar
      hw/sensor: Add lsm303dlhc magnetometer device · 4fd1ebb1
      Kevin Townsend authored
      
      This commit adds emulation of the magnetometer on the LSM303DLHC.
      It allows the magnetometer's X, Y and Z outputs to be set via the
      mag-x, mag-y and mag-z properties, as well as the 12-bit
      temperature output via the temperature property. Sensor can be
      enabled with 'CONFIG_LSM303DLHC_MAG=y'.
      
      Signed-off-by: default avatarKevin Townsend <kevin.townsend@linaro.org>
      Message-id: 20220130095032.35392-1-kevin.townsend@linaro.org
      Reviewed-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      4fd1ebb1
    • Peter Maydell's avatar
      hw/intc/arm_gicv3_its: Split error checks · d7d359c4
      Peter Maydell authored
      
      In most of the ITS command processing, we check different error
      possibilities one at a time and log them appropriately. In
      process_mapti() and process_mapd() we have code which checks
      multiple error cases at once, which means the logging is less
      specific than it could be. Split those cases up.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220201193207.2771604-14-peter.maydell@linaro.org
      d7d359c4
    • Peter Maydell's avatar
      hw/intc/arm_gicv3_its: Don't allow intid 1023 in MAPI/MAPTI · 33302414
      Peter Maydell authored
      
      When handling MAPI/MAPTI, we allow the supplied interrupt ID to be
      either 1023 or something in the valid LPI range.  This is a mistake:
      only a real valid LPI is allowed.  (The general behaviour of the ITS
      is that most interrupt ID fields require a value in the LPI range;
      the exception is that fields specifying a doorbell value, which are
      all in GICv4 commands, allow also 1023 to mean "no doorbell".)
      Remove the condition that incorrectly allows 1023 here.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220201193207.2771604-13-peter.maydell@linaro.org
      33302414
    • Peter Maydell's avatar
      hw/intc/arm_gicv3_its: In MAPC with V=0, don't check rdbase field · 84d43d2e
      Peter Maydell authored
      
      In the MAPC command, if V=0 this is a request to delete a collection
      table entry and the rdbase field of the command packet will not be
      used.  In particular, the specification says that the "UNPREDICTABLE
      if rdbase is not valid" only applies for V=1.
      
      We were doing a check-and-log-guest-error on rdbase regardless of
      whether the V bit was set, and also (harmlessly but confusingly)
      storing the contents of the rdbase field into the updated collection
      table entry.  Update the code so that if V=0 we don't check or use
      the rdbase field value.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220201193207.2771604-12-peter.maydell@linaro.org
      84d43d2e
    • Peter Maydell's avatar
      hw/intc/arm_gicv3_its: Drop TableDesc and CmdQDesc valid fields · da4680ce
      Peter Maydell authored
      
      Currently we track in the TableDesc and CmdQDesc structs the state of
      the GITS_BASER<n> and GITS_CBASER Valid bits.  However we aren't very
      consistent abut checking the valid field: we test it in update_cte()
      and update_dte(), but not anywhere else we look things up in tables.
      
      The GIC specification says that it is UNPREDICTABLE if a guest fails
      to set any of these Valid bits before enabling the ITS via
      GITS_CTLR.Enabled.  So we can choose to handle Valid == 0 as
      equivalent to a zero-length table.  This is in fact how we're already
      catching this case in most of the table-access paths: when Valid is 0
      we leave the num_entries fields in TableDesc or CmdQDesc set to zero,
      and then the out-of-bounds check "index >= num_entries" that we have
      to do anyway before doing any of these table lookups will always be
      true, catching the no-valid-table case without any extra code.
      
      So we can remove the checks on the valid field from update_cte()
      and update_dte(): since these happen after the bounds check there
      was never any case when the test could fail. That means the valid
      fields would be entirely unused, so just remove them.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220201193207.2771604-11-peter.maydell@linaro.org
      da4680ce
    • Peter Maydell's avatar
      hw/intc/arm_gicv3_its: Make update_ite() use ITEntry · 7eb54267
      Peter Maydell authored
      
      Make the update_ite() struct use the new ITEntry struct, so that
      callers don't need to assemble the in-memory ITE data themselves, and
      only get_ite() and update_ite() need to care about that in-memory
      layout.  We can then drop the no-longer-used IteEntry struct
      definition.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220201193207.2771604-10-peter.maydell@linaro.org
      7eb54267
    • Peter Maydell's avatar
      hw/intc/arm_gicv3_its: Pass ITE values back from get_ite() via a struct · 244194fe
      Peter Maydell authored
      
      In get_ite() we currently return the caller some of the fields of an
      Interrupt Table Entry via a set of pointer arguments, and validate
      some of them internally (interrupt type and valid bit) to return a
      simple true/false 'valid' indication. Define a new ITEntry struct
      which has all the fields that the in-memory ITE has, and bring the
      get_ite() function in to line with get_dte() and get_cte().
      
      This paves the way for handling virtual interrupts, which will want
      a different subset of the fields in the ITE. Handling them under
      the old "lots of pointer arguments" scheme would have meant a
      confusingly large set of arguments for this function.
      
      The new struct ITEntry is obviously confusably similar to the
      existing IteEntry struct, whose fields are the raw 12 bytes
      of the in-memory ITE. In the next commit we will make update_ite()
      use ITEntry instead of IteEntry, which will allow us to delete
      the IteEntry struct and remove the confusion.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220201193207.2771604-9-peter.maydell@linaro.org
      244194fe
    • Peter Maydell's avatar
      hw/intc/arm_gicv3_its: Avoid nested ifs in get_ite() · 2954b93f
      Peter Maydell authored
      
      The get_ite() code has some awkward nested if statements; clean
      them up by returning early if the memory accesses fail.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220201193207.2771604-8-peter.maydell@linaro.org
      2954b93f
    • Peter Maydell's avatar
      hw/intc/arm_gicv3_its: Fix address calculation in get_ite() and update_ite() · a1ce993d
      Peter Maydell authored
      
      In get_ite() and update_ite() we work with a 12-byte in-guest-memory
      table entry, which we intend to handle as an 8-byte value followed by
      a 4-byte value.  Unfortunately the calculation of the address of the
      4-byte value is wrong, because we write it as:
      
       table_base_address + (index * entrysize) + 4
      (obfuscated by the way the expression has been written)
      
      when it should be + 8.  This bug meant that we overwrote the top
      bytes of the 8-byte value with the 4-byte value.  There are no
      guest-visible effects because the top half of the 8-byte value
      contains only the doorbell interrupt field, which is used only in
      GICv4, and the two bugs in the "write ITE" and "read ITE" codepaths
      cancel each other out.
      
      We can't simply change the calculation, because this would break
      migration of a (TCG) guest from the old version of QEMU which had
      in-guest-memory interrupt tables written using the buggy version of
      update_ite().  We must also at the same time change the layout of the
      fields within the ITE_L and ITE_H values so that the in-memory
      locations of the fields we care about (VALID, INTTYPE, INTID and
      ICID) stay the same.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220201193207.2771604-7-peter.maydell@linaro.org
      a1ce993d
    • Peter Maydell's avatar
      hw/intc/arm_gicv3_its: Pass CTEntry to update_cte() · 06985cc3
      Peter Maydell authored
      
      Make update_cte() take a CTEntry struct rather than all the fields
      of the new CTE as separate arguments.
      
      This brings it into line with the update_dte() API.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220201193207.2771604-6-peter.maydell@linaro.org
      06985cc3
    • Peter Maydell's avatar
      hw/intc/arm_gicv3_its: Keep CTEs as a struct, not a raw uint64_t · d37cf49b
      Peter Maydell authored
      
      In the ITS, a CTE is an entry in the collection table, which contains
      multiple fields. Currently the function get_cte() which reads one
      entry from the device table returns a success/failure boolean and
      passes back the raw 64-bit integer CTE value via a pointer argument.
      We then extract fields from the CTE as we need them.
      
      Create a real C struct with the same fields as the CTE, and
      populate it in get_cte(), so that that function and update_cte()
      are the only ones which need to care about the in-guest-memory
      format of the CTE.
      
      This brings get_cte()'s API into line with get_dte().
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220201193207.2771604-5-peter.maydell@linaro.org
      d37cf49b
    • Peter Maydell's avatar
      hw/intc/arm_gicv3_its: Pass DTEntry to update_dte() · 22d62b08
      Peter Maydell authored
      
      Make update_dte() take a DTEntry struct rather than all the fields of
      the new DTE as separate arguments.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220201193207.2771604-4-peter.maydell@linaro.org
      22d62b08
    • Peter Maydell's avatar
      hw/intc/arm_gicv3_its: Keep DTEs as a struct, not a raw uint64_t · 4acf93e1
      Peter Maydell authored
      
      In the ITS, a DTE is an entry in the device table, which contains
      multiple fields. Currently the function get_dte() which reads one
      entry from the device table returns it as a raw 64-bit integer,
      which we then pass around in that form, only extracting fields
      from it as we need them.
      
      Create a real C struct with the same fields as the DTE, and
      populate it in get_dte(), so that that function and update_dte()
      are the only ones that need to care about the in-guest-memory
      format of the DTE.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220201193207.2771604-3-peter.maydell@linaro.org
      4acf93e1
    • Peter Maydell's avatar
      hw/intc/arm_gicv3_its: Use address_space_map() to access command queue packets · b6f96009
      Peter Maydell authored
      
      Currently the ITS accesses each 8-byte doubleword in a 4-doubleword
      command packet with a separate address_space_ldq_le() call.  This is
      awkward because the individual command processing functions have
      ended up with code to handle "load more doublewords out of the
      packet", which is both unwieldy and also a potential source of bugs
      because it's not obvious when looking at a line that pulls a field
      out of the 'value' variable which of the 4 doublewords that variable
      currently holds.
      
      Switch to using address_space_map() to map the whole command packet
      at once and fish the four doublewords out of it.  Then each process_*
      function can start with a few lines of code that extract the fields
      it cares about.
      
      This requires us to split out the guts of process_its_cmd() into a
      new do_process_its_cmd(), because we were previously overloading the
      value and offset arguments as a backdoor way to directly pass the
      devid and eventid from a write to GITS_TRANSLATER.  The new
      do_process_its_cmd() takes those arguments directly, and
      process_its_cmd() is just a wrapper that does the "read fields from
      command packet" part.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220201193207.2771604-2-peter.maydell@linaro.org
      b6f96009
    • Eric Auger's avatar
      hw/arm/smmuv3: Fix device reset · 43530095
      Eric Auger authored
      
      We currently miss a bunch of register resets in the device reset
      function. This sometimes prevents the guest from rebooting after
      a system_reset (with virtio-blk-pci). For instance, we may get
      the following errors:
      
      invalid STE
      smmuv3-iommu-memory-region-0-0 translation failed for iova=0x13a9d2000(SMMU_EVT_C_BAD_STE)
      Invalid read at addr 0x13A9D2000, size 2, region '(null)', reason: rejected
      invalid STE
      smmuv3-iommu-memory-region-0-0 translation failed for iova=0x13a9d2000(SMMU_EVT_C_BAD_STE)
      Invalid write at addr 0x13A9D2000, size 2, region '(null)', reason: rejected
      invalid STE
      
      Signed-off-by: default avatarEric Auger <eric.auger@redhat.com>
      Message-id: 20220202111602.627429-1-eric.auger@redhat.com
      Fixes: 10a83cb9 ("hw/arm/smmuv3: Skeleton")
      Reviewed-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      43530095
    • Richard Petri's avatar
      hw/timer/armv7m_systick: Update clock source before enabling timer · 77cd9971
      Richard Petri authored
      
      Starting the SysTick timer and changing the clock source a the same time
      will result in an error, if the previous clock period was zero. For exmaple,
      on the mps2-tz platforms, no refclk is present. Right after reset, the
      configured ptimer period is zero, and trying to enabling it will turn it off
      right away. E.g., code running on the platform setting
      
          SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
      
      should change the clock source and enable the timer on real hardware, but
      resulted in an error in qemu.
      
      Signed-off-by: default avatarRichard Petri <git@rpls.de>
      Reviewed-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Message-id: 20220201192650.289584-1-git@rpls.de
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      77cd9971
    • Alex Bennée's avatar
      arm: force flag recalculation when messing with DAIF · c737d868
      Alex Bennée authored
      
      The recently introduced debug tests in kvm-unit-tests exposed an error
      in our handling of singlestep cause by stale hflags. This is caught by
      --enable-debug-tcg when running the tests.
      
      Signed-off-by: default avatarAlex Bennée <alex.bennee@linaro.org>
      Reported-by: default avatarAndrew Jones <drjones@redhat.com>
      Tested-by: default avatarAndrew Jones <drjones@redhat.com>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220202122353.457084-1-alex.bennee@linaro.org
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      c737d868
    • Edgar E. Iglesias's avatar
      hw/arm: versal-virt: Always call arm_load_kernel() · 40874a38
      Edgar E. Iglesias authored
      
      Always call arm_load_kernel() regardless of kernel_filename being
      set. This is needed because arm_load_kernel() sets up reset for
      the CPUs.
      
      Fixes: 6f16da53 (hw/arm: versal: Add a virtual Xilinx Versal board)
      Reported-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Signed-off-by: default avatarEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Message-id: 20220130110313.4045351-2-edgar.iglesias@gmail.com
      Reviewed-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      40874a38
    • Peter Maydell's avatar
      hw/arm/boot: Drop existing dtb /psci node rather than retaining it · e4b0bb80
      Peter Maydell authored
      
      If we're using PSCI emulation, we add a /psci node to the device tree
      we pass to the guest.  At the moment, if the dtb already has a /psci
      node in it, we retain it, rather than replacing it. (This behaviour
      was added in commit c39770cd in 2018.)
      
      This is a problem if the existing node doesn't match our PSCI
      emulation.  In particular, it might specify the wrong method (HVC vs
      SMC), or wrong function IDs for cpu_suspend/cpu_off/etc, in which
      case the guest will not get the behaviour it wants when it makes PSCI
      calls.
      
      An example of this is trying to boot the highbank or midway board
      models using the device tree supplied in the kernel sources: this
      device tree includes a /psci node that specifies function IDs that
      don't match the (PSCI 0.2 compliant) IDs that QEMU uses.  The dtb
      cpu_suspend function ID happens to match the PSCI 0.2 cpu_off ID, so
      the guest hangs after booting when the kernel tries to idle the CPU
      and instead it gets turned off.
      
      Instead of retaining an existing /psci node, delete it entirely
      and replace it with a node whose properties match QEMU's PSCI
      emulation behaviour. This matches the way we handle /memory nodes,
      where we also delete any existing nodes and write in ones that
      match the way QEMU is going to behave.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Tested-by: default avatarEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Tested-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Message-id: 20220127154639.2090164-17-peter.maydell@linaro.org
      e4b0bb80
    • Peter Maydell's avatar
      hw/arm/boot: Drop nb_cpus field from arm_boot_info · d6dc926e
      Peter Maydell authored
      
      We use the arm_boot_info::nb_cpus field in only one place, and that
      place can easily get the number of CPUs locally rather than relying
      on the board code to have set the field correctly.  (At least one
      board, xlnx-versal-virt, does not set the field despite having more
      than one CPU.)
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Tested-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Message-id: 20220127154639.2090164-16-peter.maydell@linaro.org
      d6dc926e
    • Peter Maydell's avatar
      hw/arm/highbank: Drop unused secondary boot stub code · 45dd668f
      Peter Maydell authored
      
      The highbank and midway board code includes boot-stub code for
      handling secondary CPU boot which keeps the secondaries in a pen
      until the primary writes to a known location with the address they
      should jump to.
      
      This code is never used, because the boards enable QEMU's PSCI
      emulation, so secondary CPUs are kept powered off until the PSCI call
      which turns them on, and then start execution from the address given
      by the guest in that PSCI call.  Delete the unreachable code.
      
      (The code was wrong for midway in any case -- on the Cortex-A15 the
      GIC CPU interface registers are at a different offset from PERIPHBASE
      compared to the Cortex-A9, and the code baked-in the offsets for
      highbank's A9.)
      
      Note that this commit implicitly depends on the preceding "Don't
      write secondary boot stub if using PSCI" commit -- the default
      secondary-boot stub code overlaps with one of the highbank-specific
      bootcode rom blobs, so we must suppress the secondary-boot
      stub code entirely, not merely replace the highbank-specific
      version with the default.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Tested-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Message-id: 20220127154639.2090164-15-peter.maydell@linaro.org
      45dd668f
    • Peter Maydell's avatar
      hw/arm/boot: Don't write secondary boot stub if using PSCI · d4a29ed6
      Peter Maydell authored
      
      If we're using PSCI emulation to start secondary CPUs, there is no
      point in writing the "secondary boot" stub code, because it will
      never be used -- secondary CPUs start powered-off, and when powered
      on are set to begin execution at the address specified by the guest's
      power-on PSCI call, not at the stub.
      
      Move the call to the hook that writes the secondary boot stub code so
      that we can do it only if we're starting a Linux kernel and not using
      PSCI.
      
      (None of the users of the hook care about the ordering of its call
      relative to anything else: they only use it to write a rom blob to
      guest memory.)
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Tested-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Message-id: 20220127154639.2090164-14-peter.maydell@linaro.org
      d4a29ed6
    • Peter Maydell's avatar
      hw/arm/boot: Prevent setting both psci_conduit and secure_board_setup · dc888dd4
      Peter Maydell authored
      
      Now that we have dealt with the one special case (highbank) that needed
      to set both psci_conduit and secure_board_setup, we don't need to
      allow that combination any more. It doesn't make sense in general,
      so use an assertion to ensure we don't add new boards that do it
      by accident without thinking through the consequences.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Tested-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Message-id: 20220127154639.2090164-13-peter.maydell@linaro.org
      dc888dd4
    • Peter Maydell's avatar
      hw/arm/highbank: Drop use of secure_board_setup · 61b82973
      Peter Maydell authored
      
      Guest code on highbank may make non-PSCI SMC calls in order to
      enable/disable the L2x0 cache controller (see the Linux kernel's
      arch/arm/mach-highbank/highbank.c highbank_l2c310_write_sec()
      function).  The ABI for this is documented in kernel commit
      8e56130dcb as being borrowed from the OMAP44xx ROM.  The OMAP44xx TRM
      documents this function ID as having no return value and potentially
      trashing all guest registers except SP and PC. For QEMU's purposes
      (where our L2x0 model is a stub and enabling or disabling it doesn't
      affect the guest behaviour) a simple "do nothing" SMC is fine.
      
      We currently implement this NOP behaviour using a little bit of
      Secure code we run before jumping to the guest kernel, which is
      written by arm_write_secure_board_setup_dummy_smc().  The code sets
      up a set of Secure vectors where the SMC entry point returns without
      doing anything.
      
      Now that the PSCI SMC emulation handles all SMC calls (setting r0 to
      an error code if the input r0 function identifier is not recognized),
      we can use that default behaviour as sufficient for the highbank
      cache controller call.  (Because the guest code assumes r0 has no
      interesting value on exit it doesn't matter that we set it to the
      error code).  We can therefore delete the highbank board code that
      sets secure_board_setup to true and writes the secure-code bootstub.
      
      (Note that because the OMAP44xx ABI puts function-identifiers in
      r12 and PSCI uses r0, we only avoid a clash because Linux's code
      happens to put the function-identifier in both registers. But this
      is true also when the kernel is running on real firmware that
      implements both ABIs as far as I can see.)
      
      This change fixes in passing booting on the 'midway' board model,
      which has been completely broken since we added support for Hyp
      mode to the Cortex-A15 CPU. When we did that boot.c was made to
      start running the guest code in Hyp mode; this includes the
      board_setup hook, which instantly UNDEFs because the NSACR is
      not accessible from Hyp. (Put another way, we never made the
      secure_board_setup hook support cope with Hyp mode.)
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Tested-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Message-id: 20220127154639.2090164-12-peter.maydell@linaro.org
      61b82973
    • Peter Maydell's avatar
      arm: tcg: Adhere to SMCCC 1.3 section 5.2 · 3f37979b
      Peter Maydell authored
      
      The SMCCC 1.3 spec section 5.2 says
      
        The Unknown SMC Function Identifier is a sign-extended value of (-1)
        that is returned in the R0, W0 or X0 registers. An implementation must
        return this error code when it receives:
      
          * An SMC or HVC call with an unknown Function Identifier
          * An SMC or HVC call for a removed Function Identifier
          * An SMC64/HVC64 call from AArch32 state
      
      To comply with these statements, let's always return -1 when we encounter
      an unknown HVC or SMC call.
      
      [PMM:
       This is a reinstatement of commit 9fcd15b9, previously
       reverted in commit 4825eaae; we can do this now that we
       have arranged for all the affected board models to not enable the
       PSCI emulation if they are running guest code at EL3. This avoids
       the regressions that caused us to revert the change for 7.0.]
      
      Signed-off-by: default avatarAlexander Graf <agraf@csgraf.de>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Tested-by: default avatarEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Tested-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Reviewed-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      3f37979b
    • Peter Maydell's avatar
      hw/arm: highbank: For EL3 guests, don't enable PSCI, start all cores · 33284d48
      Peter Maydell authored
      Change the highbank/midway boards to use the new boot.c functionality
      to allow us to enable psci-conduit only if the guest is being booted
      in EL1 or EL2, so that if the user runs guest EL3 firmware code our
      PSCI emulation doesn't get in its way.
      
      To do this we stop setting the psci-conduit and start-powered-off
      properties on the CPU objects in the board code, and instead set the
      psci_conduit field in the arm_boot_info struct to tell the common
      boot loader code that we'd like PSCI if the guest is starting at an
      EL that it makes sense with (in which case it will set these
      properties).
      
      This means that when running guest code at EL3, all the cores
      will start execution at once on poweron. This matches the
      real hardware behaviour. (A brief description of the hardware
      boot process is in the u-boot documentation for these boards:
      https://u-boot.readthedocs.io/en/latest/board/highbank/highbank.html#boot-process
      
      
       -- in theory one might run the 'a9boot'/'a15boot' secure monitor
      code in QEMU, though we probably don't emulate enough for that.)
      
      This affects the highbank and midway boards.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Tested-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Message-id: 20220127154639.2090164-10-peter.maydell@linaro.org
      33284d48
    • Peter Maydell's avatar
      hw/arm/virt: Let boot.c handle PSCI enablement · 52c235ad
      Peter Maydell authored
      
      Instead of setting the CPU psci-conduit and start-powered-off
      properties in the virt board code, set the arm_boot_info psci_conduit
      field so that the boot.c code can do it.
      
      This will fix a corner case where we were incorrectly enabling PSCI
      emulation when booting guest code into EL3 because it was an ELF file
      passed to -kernel or to the generic loader.  (EL3 guest code started
      via -bios or -pflash was already being run with PSCI emulation
      disabled.)
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Tested-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Message-id: 20220127154639.2090164-9-peter.maydell@linaro.org
      52c235ad
    • Peter Maydell's avatar
      hw/arm/versal: Let boot.c handle PSCI enablement · 9437a76e
      Peter Maydell authored
      
      Instead of setting the CPU psci-conduit and start-powered-off
      properties in the xlnx-versal-virt board code, set the arm_boot_info
      psci_conduit field so that the boot.c code can do it.
      
      This will fix a corner case where we were incorrectly enabling PSCI
      emulation when booting guest code into EL3 because it was an ELF file
      passed to -kernel.  (EL3 guest code started via -bios, -pflash, or
      the generic loader was already being run with PSCI emulation
      disabled.)
      
      Note that EL3 guest code has no way to turn on the secondary CPUs
      because there's no emulated power controller, but this was already
      true for EL3 guest code run via -bios, -pflash, or the generic
      loader.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Tested-by: default avatarEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Tested-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Message-id: 20220127154639.2090164-8-peter.maydell@linaro.org
      9437a76e
    • Peter Maydell's avatar
      hw/arm/xlnx-zcu102: Don't enable PSCI conduit when booting guest in EL3 · 50c785f2
      Peter Maydell authored
      
      Change the Xilinx ZynqMP-based board xlnx-zcu102 to use the new
      boot.c functionality to allow us to enable psci-conduit only if
      the guest is being booted in EL1 or EL2, so that if the user runs
      guest EL3 firmware code our PSCI emulation doesn't get in its
      way.
      
      To do this we stop setting the psci-conduit property on the CPU
      objects in the SoC code, and instead set the psci_conduit field in
      the arm_boot_info struct to tell the common boot loader code that
      we'd like PSCI if the guest is starting at an EL that it makes
      sense with.
      
      Note that this means that EL3 guest code will have no way
      to power on secondary cores, because we don't model any
      kind of power controller that does that on this SoC.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Tested-by: default avatarEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Tested-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Acked-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220127154639.2090164-7-peter.maydell@linaro.org
      50c785f2
    • Peter Maydell's avatar
      hw/arm: allwinner: Don't enable PSCI conduit when booting guest in EL3 · 49865b90
      Peter Maydell authored
      
      Change the allwinner-h3 based board to use the new boot.c
      functionality to allow us to enable psci-conduit only if the guest is
      being booted in EL1 or EL2, so that if the user runs guest EL3
      firmware code our PSCI emulation doesn't get in its way.
      
      To do this we stop setting the psci-conduit property on the CPU
      objects in the SoC code, and instead set the psci_conduit field in
      the arm_boot_info struct to tell the common boot loader code that
      we'd like PSCI if the guest is starting at an EL that it makes sense
      with.
      
      This affects the orangepi-pc board.
      
      This commit leaves the secondary CPUs in the powered-down state if
      the guest is booting at EL3, which is the same behaviour as before
      this commit.  The secondaries can no longer be started by that EL3
      code making a PSCI call but can still be started via the CPU
      Configuration Module registers (which we model in
      hw/misc/allwinner-cpucfg.c).
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Tested-by: default avatarNiek Linnenbank <nieklinnenbank@gmail.com>
      Message-id: 20220127154639.2090164-6-peter.maydell@linaro.org
      49865b90
    • Peter Maydell's avatar
      hw/arm: imx: Don't enable PSCI conduit when booting guest in EL3 · ae2474f1
      Peter Maydell authored
      
      Change the iMX-SoC based boards to use the new boot.c functionality
      to allow us to enable psci-conduit only if the guest is being booted
      in EL1 or EL2, so that if the user runs guest EL3 firmware code our
      PSCI emulation doesn't get in its way.
      
      To do this we stop setting the psci-conduit property on the CPU
      objects in the SoC code, and instead set the psci_conduit field in
      the arm_boot_info struct to tell the common boot loader code that
      we'd like PSCI if the guest is starting at an EL that it makes
      sense with.
      
      This affects the mcimx6ul-evk and mcimx7d-sabre boards.
      
      Note that for the mcimx7d board, this means that when running guest
      code at EL3 there is currently no way to power on the secondary CPUs,
      because we do not currently have a model of the system reset
      controller module which should be used to do that for the imx7 SoC,
      only for the imx6 SoC.  (Previously EL3 code which knew it was
      running on QEMU could use a PSCI call to do this.) This doesn't
      affect the imx6ul-evk board because it is uniprocessor.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Tested-by: default avatarEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Acked-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Message-id: 20220127154639.2090164-5-peter.maydell@linaro.org
      ae2474f1
    • Peter Maydell's avatar
      hw/arm/boot: Support setting psci-conduit based on guest EL · 817e2db8
      Peter Maydell authored
      
      Currently we expect board code to set the psci-conduit property on
      CPUs and ensure that secondary CPUs are created with the
      start-powered-off property set to false, if the board wishes to use
      QEMU's builtin PSCI emulation.  This worked OK for the virt board
      where we first wanted to use it, because the virt board directly
      creates its CPUs and is in a reasonable position to set those
      properties.  For other boards which model real hardware and use a
      separate SoC object, however, it is more awkward.  Most PSCI-using
      boards just set the psci-conduit board unconditionally.
      
      This was never strictly speaking correct (because you would not be
      able to run EL3 guest firmware that itself provided the PSCI
      interface, as the QEMU implementation would overrule it), but mostly
      worked in practice because for non-PSCI SMC calls QEMU would emulate
      the SMC instruction as normal (by trapping to guest EL3).  However,
      we would like to make our PSCI emulation follow the part of the SMCC
      specification that mandates that SMC calls with unknown function
      identifiers return a failure code, which means that all SMC calls
      will be handled by the PSCI code and the "emulate as normal" path
      will no longer be taken.
      
      We tried to implement that in commit 9fcd15b9
      ("arm: tcg: Adhere to SMCCC 1.3 section 5.2"), but this
      regressed attempts to run EL3 guest code on the affected boards:
       * mcimx6ul-evk, mcimx7d-sabre, orangepi, xlnx-zcu102
       * for the case only of EL3 code loaded via -kernel (and
         not via -bios or -pflash), virt and xlnx-versal-virt
      so for the 7.0 release we reverted it (in commit 4825eaae).
      
      This commit provides a mechanism that boards can use to arrange that
      psci-conduit is set if running guest code at a low enough EL but not
      if it would be running at the same EL that the conduit implies that
      the QEMU PSCI implementation is using.  (Later commits will convert
      individual board models to use this mechanism.)
      
      We do this by moving the setting of the psci-conduit and
      start-powered-off properties to arm_load_kernel().  Boards which want
      to potentially use emulated PSCI must set a psci_conduit field in the
      arm_boot_info struct to the type of conduit they want to use (SMC or
      HVC); arm_load_kernel() will then set the CPUs up accordingly if it
      is not going to start the guest code at the same or higher EL as the
      fake QEMU firmware would be at.
      
      Board/SoC code which uses this mechanism should no longer set the CPU
      psci-conduit property directly.  It should only set the
      start-powered-off property for secondaries if EL3 guest firmware
      running bare metal expects that rather than the alternative "all CPUs
      start executing the firmware at once".
      
      Note that when calculating whether we are going to run guest
      code at EL3, we ignore the setting of arm_boot_info::secure_board_setup,
      which might cause us to run a stub bit of guest code at EL3 which
      does some board-specific setup before dropping to EL2 or EL1 to
      run the guest kernel. This is OK because only one board that
      enables PSCI sets secure_board_setup (the highbank board), and
      the stub code it writes will behave the same way whether the
      one SMC call it makes is handled by "emulate the SMC" or by
      "PSCI default returns an error code". So we can leave that stub
      code in place until after we've changed the PSCI default behaviour;
      at that point we will remove it.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Tested-by: default avatarEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Message-id: 20220127154639.2090164-4-peter.maydell@linaro.org
      817e2db8
    • Peter Maydell's avatar
      cpu.c: Make start-powered-off settable after realize · 0c3c25fc
      Peter Maydell authored
      
      The CPU object's start-powered-off property is currently only
      settable before the CPU object is realized.  For arm machines this is
      awkward, because we would like to decide whether the CPU should be
      powered-off based on how we are booting the guest code, which is
      something done in the machine model code and in common code called by
      the machine model, which runs much later and in completely different
      parts of the codebase from the SoC object code that is responsible
      for creating and realizing the CPU objects.
      
      Allow start-powered-off to be set after realize.  Since this isn't
      something that's supported by the DEFINE_PROP_* macros, we have to
      switch the property definition to use the
      object_class_property_add_bool() function.
      
      Note that it doesn't conceptually make sense to change the setting of
      the property after the machine has been completely initialized,
      beacuse this would mean that the behaviour of the machine when first
      started would differ from its behaviour when the system is
      subsequently reset.  (It would also require the underlying state to
      be migrated, which we don't do.)
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Tested-by: default avatarEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Message-id: 20220127154639.2090164-3-peter.maydell@linaro.org
      0c3c25fc
    • Peter Maydell's avatar
      target/arm: make psci-conduit settable after realize · bddd892e
      Peter Maydell authored
      
      We want to allow the psci-conduit property to be set after realize,
      because the parts of the code which are best placed to decide if it's
      OK to enable QEMU's builtin PSCI emulation (the board code and the
      arm_load_kernel() function are distant from the code which creates
      and realizes CPUs (typically inside an SoC object's init and realize
      method) and run afterwards.
      
      Since the DEFINE_PROP_* macros don't have support for creating
      properties which can be changed after realize, change the property to
      be created with object_property_add_uint32_ptr(), which is what we
      already use in this function for creating settable-after-realize
      properties like init-svtor and init-nsvtor.
      
      Note that it doesn't conceptually make sense to change the setting of
      the property after the machine has been completely initialized,
      beacuse this would mean that the behaviour of the machine when first
      started would differ from its behaviour when the system is
      subsequently reset.  (It would also require the underlying state to
      be migrated, which we don't do.)
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Tested-by: default avatarEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Message-id: 20220127154639.2090164-2-peter.maydell@linaro.org
      bddd892e
    • Francisco Iglesias's avatar
      hw/arm/xlnx-zynqmp: 'Or' the QSPI / QSPI DMA IRQs · c74ccb5d
      Francisco Iglesias authored
      
      'Or' the IRQs coming from the QSPI and QSPI DMA models. This is done for
      avoiding the situation where one of the models incorrectly deasserts an
      interrupt asserted from the other model (which will result in that the IRQ
      is lost and will not reach guest SW).
      
      Signed-off-by: default avatarFrancisco Iglesias <francisco.iglesias@xilinx.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <f4bug@amsat.org>
      Reviewed-by: default avatarLuc Michel <luc@lmichel.fr>
      Message-id: 20220203151742.1457-1-francisco.iglesias@xilinx.com
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      c74ccb5d
    • Richard Henderson's avatar
      target/arm: Use CPTR_TFP with CPTR_EL3 in fp_exception_el · a7b66ada
      Richard Henderson authored
      
      Use the named bit rather than a bare extract32.
      
      Signed-off-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarZenghui Yu <yuzenghui@huawei.com>
      Message-id: 20220127063428.30212-5-richard.henderson@linaro.org
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      a7b66ada
    • Richard Henderson's avatar
      target/arm: Fix {fp, sve}_exception_el for VHE mode running · d5a6fa2d
      Richard Henderson authored
      
      When HCR_EL2.E2H is set, the format of CPTR_EL2 changes to
      look more like CPACR_EL1, with ZEN and FPEN fields instead
      of TZ and TFP fields.
      
      Reported-by: default avatarZenghui Yu <yuzenghui@huawei.com>
      Signed-off-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Message-id: 20220127063428.30212-4-richard.henderson@linaro.org
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      d5a6fa2d
    • Richard Henderson's avatar
      target/arm: Tidy sve_exception_el for CPACR_EL1 access · 7701cee5
      Richard Henderson authored
      
      Extract entire fields for ZEN and FPEN, rather than testing specific bits.
      This makes it easier to follow the code versus the ARM spec.
      
      Signed-off-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarZenghui Yu <yuzenghui@huawei.com>
      Message-id: 20220127063428.30212-3-richard.henderson@linaro.org
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      7701cee5
Loading