1. 23 Mar, 2021 1 commit
    • Andre Przywara's avatar
      fdt: Use proper #address-cells and #size-cells for reserved-memory · 81146c46
      Andre Przywara authored
      
      
      The devicetree binding document[1] for the /reserved-memory node demands
      that the number of address and size-cells in the reserved-memory node
      must match those values in the root node. So far we were forcing a
      64-bit address along with a 32-bit size.
      
      Adjust the code to query the cells values from the root node, and
      populate the newly created /reserved-memory node accordingly.
      
      This fixes the fdt_add_reserved_memory() function when called on a
      devicetree which does not use the 2/1 pair. Linux is picky about this
      and will bail out the parsing routine, effectively ignoring the
      reserved-memory node:
      [    0.000000] OF: fdt: Reserved memory: unsupported node format, ignoring
      
      [1] Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt
          in the Linux kernel source tree
      
      Change-Id: Ie126ebab4f3fedd48e12c9ed4bd8fa123acc86d3
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      81146c46
  2. 07 Oct, 2020 1 commit
    • Andre Przywara's avatar
      fdt: Fix coverity complaint about 32-bit multiplication · 4276cfe2
      Andre Przywara authored
      
      
      Coverity raised an eyebrow over our GICR frame size calculation:
      ========
          CID 362942:  Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
      Potentially overflowing expression "nr_cores * gicr_frame_size" with type
      "unsigned int" (32 bits, unsigned) is evaluated using 32-bit arithmetic,
      and then used in a context that expects an expression of type "uint64_t"
      (64 bits, unsigned).
      ========
      
      Even with a GICv4 (256KB frame size) we need 16384 cores to overflow
      32-bit, so it's not a practical issue.
      
      But it's also easy to fix, so let's just do that: cast gicr_frame_size
      to an unsigned 64-bit integer, so that the multiplication is done in the
      64-bit realm.
      
      Change-Id: Iad10e19b9e58d5fbf9d13205fbcef0aac5ae48af
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      4276cfe2
  3. 29 Sep, 2020 1 commit
    • Andre Przywara's avatar
      fdt: Add function to adjust GICv3 redistributor size · 9f7bab42
      Andre Przywara authored
      
      
      We now have code to detect the CPU topology at runtime, and can also
      populate the CPU nodes in a devicetree accordingly. This is used by the
      ARM FPGA port, for instance.
      But also a GICv3 compatible interrupt controller provides MMIO frames
      per core, so the size of this region needs to be adjusted in the DT,
      to match the number of cores as well.
      
      Provide a generic function to find the GICv3 interrupt controller in
      the DT, then adjust the "reg" entry to match the number of detected
      cores. Since the size of the GICR frame per cores differs between
      GICv4 and GICv3, this size is supplied as a parameter to the function.
      The caller should determine the applicable value by either hardcoding
      it or by observing GICR_TYPER.VLPIS.
      
      Change-Id: Ic2a6445c2c5381a36bf24263f52fcbefad378c05
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      9f7bab42
  4. 01 Sep, 2020 1 commit
  5. 22 Jan, 2020 1 commit
  6. 25 Sep, 2019 2 commits
    • Andre Przywara's avatar
      FDT helper functions: Respect architecture in PSCI function IDs · 66799507
      Andre Przywara authored
      
      
      PSCI uses different function IDs for CPU_SUSPEND and CPU_ON, depending on
      the architecture used (AArch64 or AArch32).
      For recent PSCI versions the client will determine the right version,
      but for PSCI v0.1 we need to put some ID in the DT node. At the moment
      we always add the 64-bit IDs, which is not correct if TF-A is built for
      AArch32.
      
      Use the function IDs matching the TF-A build architecture, for the two
      IDs where this differs. This only affects legacy OSes using PSCI v0.1.
      
      On the way remove the sys_poweroff and sys_reset properties, which were
      never described in the official PSCI DT binding.
      
      Change-Id: If77bc6daec215faeb2dc67112e765aacafd17f33
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      66799507
    • Andre Przywara's avatar
      FDT helper functions: Add function documentation · 6eaf928d
      Andre Przywara authored
      
      
      Since we moved some functions that amend a DT blob in memory to common
      code, let's add proper function documentation.
      This covers the three exported functions in common/fdt_fixup.c.
      
      Change-Id: I67d7d27344e62172c789d308662f78d54903cf57
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      6eaf928d
  7. 13 Sep, 2019 2 commits
    • Andre Przywara's avatar
      Add fdt_add_reserved_memory() helper function · 3ef45dda
      Andre Przywara authored
      
      
      If a firmware component like TF-A reserves special memory regions for
      its own or secure payload services, it should announce the location and
      size of those regions to the non-secure world. This will avoid
      disappointment when some rich OS tries to acccess this memory, which
      will likely end in a crash.
      
      The traditional way of advertising reserved memory using device tree is
      using the special memreserve feature of the device tree blob (DTB).
      However by definition those regions mentioned there do not prevent the
      rich OS to map this memory, which may lead to speculative accesses to
      this memory and hence spurious bus errors.
      
      A safer way of carving out memory is to use the /reserved-memory node as
      part of the normal DT structure. Besides being easier to setup, this
      also defines an explicit "no-map" property to signify the secure-only
      nature of certain memory regions, which avoids the rich OS to
      accidentally step on it.
      
      Add a helper function to allow platform ports to easily add a region.
      
      Change-Id: I2b92676cf48fd3bdacda05b5c6b1c7952ebed68c
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      3ef45dda
    • Andre Przywara's avatar
      qemu: Move and generalise FDT PSCI fixup · f240728b
      Andre Przywara authored
      
      
      The QEMU platform port scans its device tree to advertise PSCI as the
      CPU enable method. It does this by scanning *every* node in the DT and
      check whether its compatible string starts with "arm,cortex-a". Then it
      sets the enable-method to PSCI, if it doesn't already have one.
      
      Other platforms might want to use this functionality as well, so let's
      move it out of the QEMU platform directory and make it more robust by
      fixing some shortcomings:
      - A compatible string starting with a certain prefix is not a good way
      to find the CPU nodes. For instance a "arm,cortex-a72-pmu" node will
      match as well and is in turn favoured with an enable-method.
      - If the DT already has an enable-method, we won't change this to PSCI.
      
      Those two issues will for instance fail on the Raspberry Pi 4 DT.
      To fix those problems, we adjust the scanning method:
      The DT spec says that all CPU nodes are subnodes of the mandatory
      /cpus node, which is a subnode of the root node. Also each CPU node has
      to have a device_type = "cpu" property. So we find the /cpus node, then
      scan for a subnode with the proper device_type, forcing the
      enable-method to "psci".
      We have to restart this search after a property has been patched, as the
      node offsets might have changed meanwhile.
      
      This allows this routine to be reused for the Raspberry Pi 4 later.
      
      Change-Id: I00cae16cc923d9f8bb96a9b2a2933b9a79b06139
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      f240728b