1. 25 Sep, 2019 10 commits
    • Andre Przywara's avatar
      rpi4: Add GIC maintenance interrupt to GIC DT node · 3903a8cd
      Andre Przywara authored
      
      
      For being able to use the virtualisation support the GIC offers, we need
      to know the interrupt number of the maintenance interrupt. This
      information is missing from the official RPi4 device tree.
      
      Use libfdt to add the "interrupts" property to the GIC node, which
      allows hypervisors like KVM or Xen to be able to use the GIC's help on
      virtualising interrupts.
      
      Change-Id: Iab84f0885a5bf29fb84ca8f385e8a39d27700c75
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      3903a8cd
    • Andre Przywara's avatar
      rpi4: Cleanup memory regions, move pens to first page · 882c0ff6
      Andre Przywara authored
      
      
      Now that we have the SMP pens in the first page of DRAM, we can get rid
      of all the fancy RPi3 memory regions that our RPi4 port does not really
      need. This avoids using up memory all over the place, restricting ATF
      to just run in the first 512KB of DRAM.
      
      Remove the now unused regions. This also moves the SMP pens into our
      first memory page (holding the firmware magic), where the original
      firmware put them, but where there is also enough space for them.
      
      Since the pens will require code execution privileges, we amend the
      memory attributes used for that page to include write and execution
      rights.
      
      Change-Id: I131633abeb4a4d7b9057e737b9b0d163b73e47c6
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      882c0ff6
    • Andre Przywara's avatar
      rpi4: Reserve resident BL31 region from non-secure world · 2b19e2f3
      Andre Przywara authored
      
      
      The GPU firmware loads the armstub8.bin (BL31) image at address 0, the
      beginning of DRAM. As this holds the resident PSCI code and the SMP
      pens, the non-secure world should better know about this, to avoid
      accessing memory owned by TF-A. This is particularly criticial as the
      Raspberry Pi 4 does not feature a secure memory controller, so
      overwriting code is a very real danger.
      
      Use the newly introduced function to add a node into reserved-memory
      node, where non-secure world can check for regions to be excluded from
      its mappings.
      
      Reserve the first 512KB of memory for now. We can refine this later if
      need be.
      
      Change-Id: I00e55e70c5c02615320d79ff35bc32b805d30770
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      2b19e2f3
    • Andre Przywara's avatar
      rpi4: Amend DTB to advertise PSCI · f67fa69c
      Andre Przywara authored
      
      
      The device tree provided by the official Raspberry Pi firmware uses
      spin tables for SMP bringup.
      
      One of the benefit of having TF-A is that it provides PSCI services, so
      let's rewrite the DTB to advertise PSCI instead of spin tables.
      This uses the (newly exported) routine from the QEMU platform port.
      
      Change-Id: Ifddcb14041ca253a333f8c2d5e97a42db152470c
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      f67fa69c
    • Andre Przywara's avatar
      rpi4: Determine BL33 entry point at runtime · 448fb352
      Andre Przywara authored
      
      
      Now that we have the armstub magic value in place, the GPU firmware will
      write the kernel load address (and DTB address) into our special page,
      so we can always easily access the actual location without hardcoding
      any addresses into the BL31 image.
      
      Make the compile-time defined PRELOADED_BL33_BASE macro optional, and
      read the BL33 entry point from the magic location, if the macro was not
      defined. We do the same for the DTB address.
      
      This also splits the currently "common" definition of
      plat_get_ns_image_entrypoint() to be separate between RPi3 and RPi4.
      
      Change-Id: I6f26c0adc6fce2df47786b271c490928b4529abb
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      448fb352
    • Andre Przywara's avatar
      rpi4: Accommodate "armstub8.bin" header at the beginning of BL31 image · c4597e13
      Andre Przywara authored
      
      
      The Raspberry Pi GPU firmware checks for a magic value at offset 240
      (0xf0) of the armstub8.bin image it loads. If that value matches,
      it writes the kernel load address and the DTB address into subsequent
      memory locations.
      We can use these addresses to avoid hardcoding these values into the BL31
      image, to make it more flexible and a drop-in replacement for the
      official armstub8.bin.
      
      Reserving just 16 bytes at offset 240 of the final image file is not easily
      possible, though, as this location is in the middle of the generic BL31
      entry point code.
      However we can prepend an extra section before the actual BL31 image, to
      contain the magic and addresses. This needs to be 4KB, because the
      actual BL31 entry point needs to be page aligned.
      
      Use the platform linker script hook that the generic code provides, to
      add an almost empty 4KB code block before the entry point code. The very
      first word contains a branch instruction to jump over this page, into
      the actual entry code.
      This also gives us plenty of room for the SMP pens later.
      
      Change-Id: I38caa5e7195fa39cbef8600933a03d86f09263d6
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      c4597e13
    • Andre Przywara's avatar
      Add basic support for Raspberry Pi 4 · f5cb15b0
      Andre Przywara authored
      
      
      The Raspberry Pi 4 is a single board computer with four Cortex-A72
      cores. From a TF-A perspective it is quite similar to the Raspberry Pi
      3, although it comes with more memory (up to 4GB) and has a GIC.
      
      This initial port though differs quite a lot from the existing rpi3
      platform port, mainly due to taking a much simpler and more robust
      approach to loading the non-secure payload:
      The GPU firmware of the SoC, which is responsible for initial platform
      setup (including DRAM initialisation), already loads the kernel, device
      tree and the "armstub" into DRAM. We take advantage of this, by placing
      just a BL31 component into the armstub8.bin component, which will be
      executed first, in AArch64 EL3.
      The non-secure payload can be a kernel or a boot loader (U-Boot or
      EDK-2), disguised as the "kernel" image and loaded by the GPU firmware.
      
      So this is just a BL31-only port, which directly drops into EL2
      and executes whatever has been loaded as the "kernel" image, handing
      over the DTB address in x0.
      
      Change-Id: I636f4d1f661821566ad9e341d69ba36f6bbfb546
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      f5cb15b0
    • Andre Przywara's avatar
      rpi3: Allow runtime determination of UART base clock rate · 7c0a1877
      Andre Przywara authored
      
      
      At the moment the UART input clock rate is hard coded at compile time.
      This works as long as the GPU firmware always sets up the same rate,
      which does not seem to be true for the Raspberry Pi 4.
      
      In preparation for being able to change this at runtime, add a base
      clock parameter to the console setup function. This is still hardcoded
      for the Raspberry Pi 3.
      
      Change-Id: I398bc2f1e9b46f7af9a84cb0b33cbe8e78f2d900
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      7c0a1877
    • 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
  2. 18 Sep, 2019 6 commits
  3. 17 Sep, 2019 1 commit
  4. 16 Sep, 2019 10 commits
  5. 13 Sep, 2019 13 commits
    • Deepika Bhavnani's avatar
      Unsigned long should not be used as per coding guidelines · ee006a79
      Deepika Bhavnani authored
      
      
      We should either change them to `unsigned int` or `unsigned long long`
      when the size of the variable is the same in AArch64 and AArch32 or
      to `u_register_t` if it is supposed to be 32 bit wide in AArch32
      and 64 bit wide in AArch64.
      Signed-off-by: default avatarDeepika Bhavnani <deepika.bhavnani@arm.com>
      Change-Id: I80e2a6edb33248ee88be395829abbd4c36c89abe
      ee006a79
    • Deepika Bhavnani's avatar
      SCTLR and ACTLR are 32-bit for AArch32 and 64-bit for AArch64 · eeb5a7b5
      Deepika Bhavnani authored
      
      
      AArch64 System register SCTLR_EL1[31:0] is architecturally mapped
      to AArch32 System register SCTLR[31:0]
      AArch64 System register ACTLR_EL1[31:0] is architecturally mapped
      to AArch32 System register ACTLR[31:0].
      
      `u_register_t` should be used when it's important to store the
      contents of a register in its native size
      Signed-off-by: default avatarDeepika Bhavnani <deepika.bhavnani@arm.com>
      Change-Id: I0055422f8cc0454405e011f53c1c4ddcaceb5779
      eeb5a7b5
    • Andre Przywara's avatar
      rpi3: Do prescaler and control setup in C · dcf6d4f8
      Andre Przywara authored
      
      
      To initialise the arch timer configuration and some clock prescaler, we
      need to do two MMIO access *once*, early during boot.
      
      As tempting as it may sound, plat_reset_handler() is not the right place
      to do this, as it will be called on every CPU coming up, both for
      secondary cores as well as during warmboots. So this access will be done
      multiple times, and even during a rich OS' runtime. Whether doing so anyway
      is actually harmful is hard to say, but we should definitely avoid this if
      possible.
      
      Move the initialisation of these registers to C code in
      bl1_early_platform_setup(), where it will still be executed early enough
      (before enabling the console), but only once during the whole boot
      process.
      
      Change-Id: I081c41a5476d424411411488ff8f633e87d3bcc5
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      dcf6d4f8
    • 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
      rpi3: Move rng driver to drivers · 990ab78e
      Andre Przywara authored
      
      
      To allow sharing the driver between the RPi3 and RPi4, move the random
      number generator driver into the generic driver directory.
      
      Change-Id: Iae94d7cb22c6bce3af9bff709d76d4caf87b14d1
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      990ab78e
    • Andre Przywara's avatar
      rpi3: Add "rpi" platform directory · ab13addd
      Andre Przywara authored
      
      
      With the incoming support for the Raspberry Pi 4 boards, one directory
      to serve both versions will not end up well.
      
      Create an additional layer by inserting a "rpi" directory betweeen /plat
      and rpi3, so that we can more easily share or separate files between the
      two later.
      
      Change-Id: I75adbb054fe7902f34db0fd5e579a55612dd8a5f
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      ab13addd
    • Andre Przywara's avatar
      rpi3: Prepare for supporting a GIC (in RPi4) · e6fd00ab
      Andre Przywara authored
      
      
      As the PSCI "power" management functions for the Raspberry Pi 3 port
      will be shared with the upcoming RPi4 support, we need to prepare them
      for dealing with the GIC interrupt controller.
      Splitting this code just for those simple calls to the generic GIC
      routines does not seem worthwhile, so just use a #define the protect the
      GIC code from being included by the existing RPi3 code.
      
      Change-Id: Iaca6b0214563852b28ad4a088ec45348ae8be40d
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      e6fd00ab
    • 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
    • Andre Przywara's avatar
      rpi3: Move VC mailbox driver into generic drivers directory · c0031189
      Andre Przywara authored
      
      
      To allow sharing the driver between the RPi3 and RPi4, move the mailbox
      driver into the generic driver directory.
      
      Change-Id: I463e49acf82b02bf004f3d56482b7791f3020bc0
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      c0031189
    • Andre Przywara's avatar
      rpi3: Make SHARED_RAM optional · a95e6415
      Andre Przywara authored
      
      
      The existing Raspberry Pi 3 port sports a number of memory regions,
      which are used for several purposes. The upcoming RPi4 port will not use
      all of those, so make the SHARED_RAM region optional, by only mapping it
      if it has actually been defined. This helps to get a cleaner RPi4 port.
      
      Change-Id: Id69677b7fb6ed48d9f238854b610896785db8cab
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      a95e6415
    • Andre Przywara's avatar
      rpi3: Move rpi3_hw.h header file to include/rpi_hw.h · 4666d046
      Andre Przywara authored
      
      
      With the advent of Raspberry Pi 4 support, we need to separate some
      board specific headers between the RPi3 and RPi4.
      Rename and move the "rpi3_hw.h" header, so that .c files just include
      rpi_hw.h, and automatically get the correct version.
      
      Change-Id: I03b39063028d2bee1429bffccde71dddfe2dcde8
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      4666d046
    • Andre Przywara's avatar
      rpi3: Rename RPI3_IO_BASE to RPI_IO_BASE · 110fd1fe
      Andre Przywara authored
      
      
      The location of the MMIO window is different between a Raspberry Pi 3
      and 4: the former has it just below 1GB, the latter below 4GB.
      The relative location of the peripherals is mostly compatible though.
      
      To allow sharing code between the two models, let's rename the symbol
      used for the MMIO base to the more generic RPI_IO_BASE name.
      
      Change-Id: I3c2762fb30fd56cca743348e79d72ef8c60ddb03
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      110fd1fe
    • Andre Przywara's avatar
      rpi3: Move shared rpi3 files into common directory · 4f2b9848
      Andre Przywara authored
      
      
      To be able to share code more easily between the existing Raspberry Pi 3
      and the upcoming Raspberry Pi 4 platform, move some code which is not
      board specific into a "common" directory.
      
      Change-Id: I9211ab2d754b040128fac13c2f0a30a5cc8c7f2c
      Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
      4f2b9848