1. 24 Jan, 2021 7 commits
    • Samuel Holland's avatar
      allwinner: Split native and SCPI-based PSCI implementations · fe753c97
      Samuel Holland authored
      
      
      In order to keep SCP firmware as optional, the original, limited native
      PSCI implementation was kept around as a fallback. This turned out to be
      a good decision, as some newer SoCs omit the ARISC, and thus cannot run
      SCP firmware.
      
      However, keeping the two implementations in one file makes things
      unnecessarily messy. First, it is difficult to compile out the
      SCPI-based implementation where it is not applicable. Second the check
      is done in each callback, while scpi_available is only updated at boot.
      This makes the individual callbacks unnecessarily complicated.
      
      It is cleaner to provide two entirely separate implementations in two
      separate files. The native implementation does not support any kind of
      CPU suspend, so its callbacks are greatly simplified. One function,
      sunxi_validate_ns_entrypoint, is shared between the two implementations.
      
      Finally, the logic for choosing between implementations is kept in a
      third file, to provide for platforms where only one implementation is
      applicable and the other is compiled out.
      
      Change-Id: I4914f07d8e693dbce218e0e2394bef15c42945f8
      Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
      fe753c97
    • Samuel Holland's avatar
      allwinner: psci: Improve system shutdown/reset sequence · dae98b3a
      Samuel Holland authored
      
      
      - When the SCPI shutdown/reset command returns success, the SCP is
        still waiting for the CPU to enter WFI. Do that.
      - Peform board-level poweroff before CPU poweroff. If there is a PMIC
        available, it will turn everything off including the CPUs, so doing
        CPU poweroff first is a waste of cycles.
      - During poweroff, attempt to turn off the local CPU using the ARISC.
        This should use slightly less power than just an infinite WFI.
      - Drop the WFI in the reset failure path. The panic will hang anyway.
      
      Change-Id: I897efecb3fe4e77a56041b97dd273156ec51ef8e
      Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
      dae98b3a
    • Samuel Holland's avatar
      allwinner: psci: Drop .pwr_domain_pwr_down_wfi callback · 975d076d
      Samuel Holland authored
      
      
      When operating on the local cpu, sunxi_cpu_power_off_self() only "arms"
      the ARISC to perform the power-off process; the SCP waits for the CPU to
      enter WFI before acutally powering it off. Since this matches the
      expected split between .pwr_domain_off and .pwr_domain_pwr_down_wfi, we
      can move the sunxi_cpu_power_off_self() call to sunxi_pwr_domain_off().
      Since that change makes sunxi_pwr_down_wfi() equivalent to the default
      implementation, the callback is no longer needed.
      
      Change-Id: I7d65f66c550d1c69fa5e9945affd7a25b3d3ef42
      Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
      975d076d
    • Samuel Holland's avatar
      allwinner: Separate code to power off self and other CPUs · a1d349be
      Samuel Holland authored
      
      
      Currently, sunxi_cpu_off() has two separate code paths: one for the
      local CPU, and one for other CPUs. Let's split them in to two functions.
      This actually simplifies things, because all callers either operate on
      the local CPU only (sunxi_pwr_down_wfi()) or other CPUs only
      (sunxi_cpu_power_off_others()). This avoids needing a second MPIDR read
      to choose the appropriate code path.
      
      Change-Id: I55de85025235cc95466bfa106831fc4c2368f527
      Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
      a1d349be
    • Samuel Holland's avatar
      allwinner: psci: Invert check in .validate_ns_entrypoint · 814dce8f
      Samuel Holland authored
      
      
      Checking the exceptional case and letting the success case fall through
      is not only more idiomatic, but it also allows adding more exceptional
      cases in the future, such as a check for overlapping secure DRAM.
      
      Change-Id: I720441a6a8853fd7f211ebe851f14d921a6db03d
      Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
      814dce8f
    • Samuel Holland's avatar
      allwinner: psci: Drop MPIDR check from .pwr_domain_on · 772ef7e7
      Samuel Holland authored
      
      
      This duplicated the logic in psci_validate_mpidr() which was already
      called from psci_cpu_on().
      
      Change-Id: I96ee92f1ce3e9cc2985b4e229ba86ebd27b79915
      Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
      772ef7e7
    • Samuel Holland's avatar
      allwinner: psci: Drop .get_node_hw_state callback · a1473c99
      Samuel Holland authored
      
      
      This optional PSCI function was only implemented when SCPI was
      available. However, the underlying SCPI function is not able to fulfill
      the necessary contract. First, the SCPI protocol has no way to represent
      HW_STANDBY at the CPU power level. Second, the SCPI implementation
      maintains its own logical view of power states, and its implementation
      of SCPI_CMD_GET_CSS_POWER_STATE does not actually query the hardware.
      Thus it cannot provide "the physical view of power state", as required
      for this function by the PSCI specification.
      
      Since the function is optional, drop it.
      
      Change-Id: I5f3a0810ac19ddeb3c0c5d35aeb09f09a0b80c1d
      Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
      a1473c99
  2. 13 Feb, 2020 1 commit
    • Samuel Holland's avatar
      allwinner: Implement PSCI system suspend using SCPI · e382c88e
      Samuel Holland authored
      
      
      If an SCP firmware is present and able to communicate via SCPI, then use
      that to implement CPU and system power state transitions, including CPU
      hotplug and system suspend. Otherwise, fall back to the existing CPU
      power control implementation.
      
      The last 16 KiB of SRAM A2 are reserved for the SCP firmware, and the
      SCPI shared memory is at the very end of this region (and therefore the
      end of SRAM A2). BL31 continues to start at the beginning of SRAM A2
      (not counting the ARISC exception vector area) and fills up to the
      beginning of the SCP firmware.
      
      Because the SCP firmware is not loaded adjacent to the ARISC exception
      vector area, the jump instructions used for exception handling cannot be
      included in the SCP firmware image, and must be initialized here before
      turning on the SCP.
      Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
      Change-Id: I37b9b9636f94d4125230423726f3ac5e9cdb551c
      e382c88e
  3. 14 Dec, 2019 1 commit
  4. 10 Apr, 2019 1 commit
  5. 18 Feb, 2019 1 commit
  6. 04 Jan, 2019 1 commit
    • Antonio Nino Diaz's avatar
      Sanitise includes across codebase · 09d40e0e
      Antonio Nino Diaz authored
      Enforce full include path for includes. Deprecate old paths.
      
      The following folders inside include/lib have been left unchanged:
      
      - include/lib/cpus/${ARCH}
      - include/lib/el3_runtime/${ARCH}
      
      The reason for this change is that having a global namespace for
      includes isn't a good idea. It defeats one of the advantages of having
      folders and it introduces problems that are sometimes subtle (because
      you may not know the header you are actually including if there are two
      of them).
      
      For example, this patch had to be created because two headers were
      called the same way: e0ea0928 ("Fix gpio includes of mt8173 platform
      to avoid collision."). More recently, this patch has had similar
      problems: 46f9b2c3 ("drivers: add tzc380 support").
      
      This problem was introduced in commit 4ecca339
      
       ("Move include and
      source files to logical locations"). At that time, there weren't too
      many headers so it wasn't a real issue. However, time has shown that
      this creates problems.
      
      Platforms that want to preserve the way they include headers may add the
      removed paths to PLAT_INCLUDES, but this is discouraged.
      
      Change-Id: I39dc53ed98f9e297a5966e723d1936d6ccf2fc8f
      Signed-off-by: default avatarAntonio Nino Diaz <antonio.ninodiaz@arm.com>
      09d40e0e
  7. 20 Oct, 2018 2 commits
    • Andre Przywara's avatar
      allwinner: Use the arisc to turn off ARM cores · 7db0c960
      Andre Przywara authored
      
      
      PSCI requires a core to turn itself off, which we can't do properly by
      just executing an algorithm on that very core. As a consequence we just
      put a core into WFI on CPU_OFF right now.
      To fix this let's task the "arisc" management processor (an OpenRISC
      core) with that task of asserting reset and turning off the core's power
      domain. We use a handcrafted sequence of OpenRISC instructions to
      achieve this, and hand this data over to the new sunxi_execute_arisc_code()
      routine.
      The commented source code for this routine is provided in a separate file,
      but the ATF code contains the already encoded instructions as data.
      The H6 uses the same algorithm, but differs in the MMIO addresses, so
      provide a SoC (family) specific copy of that code.
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      7db0c960
    • Andre Przywara's avatar
      allwinner: Export sunxi_private.h · 4ec1a239
      Andre Przywara authored
      
      
      So far we have a sunxi_private.h header file in the common code directory.
      This holds the prototypes of various functions we share in *common*
      code. However we will need some of those in the platform specific code
      parts as well, and want to introduce new functions shared across the
      whole platform port.
      
      So move the sunxi_private.h file into the common/include directory, so
      that it becomes visible to all parts of the platform code.
      Fix up the existing #includes and add missing ones, also add the
      sunxi_read_soc_id() prototype here.
      
      This will be used in follow up patches.
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      4ec1a239
  8. 07 Sep, 2018 1 commit
  9. 28 Jun, 2018 1 commit
  10. 15 Jun, 2018 3 commits
    • Samuel Holland's avatar
      allwinner: Add platform PSCI functions required for SMP · 560581ec
      Samuel Holland authored
      
      
      The reset vector entry point is preserved across CPU resets, so it only
      needs to be set once at boot.
      
      Hotplugged CPUs are not actually powered down, but are put in a wfi with
      the GIC disconnected.
      
      With this commit, Linux is able to enable, hotplug and use all four CPUs.
      Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      560581ec
    • Samuel Holland's avatar
      allwinner: Add functions to control CPU power/reset · 333d66cf
      Samuel Holland authored
      
      
      sun50i_cpu_on will be used by the PSCI implementation to initialize
      secondary cores for SMP. Unfortunately, sun50i_cpu_off is not usable by
      PSCI directly, because it is not possible for a CPU to use this function
      to power itself down. Power cannot be shut off until the outputs are
      clamped, and MMIO does not work once the outputs are clamped.
      
      But at least CPU0 can shutdown the other cores early in the BL31 boot
      process and before shutting down the system.
      Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      333d66cf
    • Samuel Holland's avatar
      allwinner: Introduce basic platform support · 58032586
      Samuel Holland authored
      
      
      This platform supports Allwinner's SoCs with ARMv8 cores. So far they
      all sport a single cluster of Cortex-A53 cores.
      
      "sunxi" is the original code name used for this platform, and since it
      appears in the Linux kernel and in U-Boot as well, we use it here as a
      short file name prefix and for identifiers.
      
      This port includes BL31 support only. U-Boot's SPL takes the role of the
      primary loader, also doing the DRAM initialization. It then loads the
      rest of the firmware, namely ATF and U-Boot (BL33), then hands execution
      over to ATF.
      
      This commit includes the basic platform code shared across all SoCs.
      There is no platform.mk yet.
      
      [Andre: moved files into proper directories, supported RESET_TO_BL31,
      	various clean ups and simplifications ]
      Signed-off-by: default avatarSamuel Holland <samuel@sholland.org>
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      58032586