1. 18 Jul, 2018 2 commits
    • Antonio Nino Diaz's avatar
      Fix types of arch.h definitions · 30399885
      Antonio Nino Diaz authored
      
      
      Define the values as unsigned int or unsigned long long based on the
      actual size of the register. This prevents subtle issues caused by
      having a type that is too small. For example:
      
          #define OPTION_ENABLE 0x3
          #define OPTION_SHIFT  32
      
          uint64_t mask = OPTION_ENABLE << OPTION_SHIFT;
      
      Because OPTION_ENABLE fits in an int, the value is considered an int.
      This means that, after shifting it 32 places to the left, the final
      result is 0. The correct way to define the values is:
      
          #define OPTION_ENABLE ULL(0x3)
          #define OPTION_SHIFT  U(32)
      
      In this case, the compiler is forced to use a 64 bit value from the
      start, so shifting it 32 places to the left results in the expected
      value.
      
      Change-Id: Ieaf2ffc2d8caa48c622db011f2aef549e713e019
      Signed-off-by: default avatarAntonio Nino Diaz <antonio.ninodiaz@arm.com>
      30399885
    • Antonio Nino Diaz's avatar
      Add missing parentheses to macros in arch.h · 0107aa49
      Antonio Nino Diaz authored
      
      
      Change-Id: Ifea46da46d1bfd01b341acfad75df5bcab48a204
      Signed-off-by: default avatarAntonio Nino Diaz <antonio.ninodiaz@arm.com>
      0107aa49
  2. 12 Jul, 2018 1 commit
  3. 11 Jul, 2018 9 commits
  4. 10 Jul, 2018 1 commit
    • Roberto Vargas's avatar
      Fix MISRA rule 8.3 · c96f297f
      Roberto Vargas authored
      
      
      Rule 8.3: All declarations of an object or function shall
                    use the same names and type qualifiers.
      
      Fixed for:
      	make DEBUG=1 PLAT=juno ARCH=aarch32 AARCH32_SP=sp_min RESET_TO_SP_MIN=1 JUNO_AARCH32_EL3_RUNTIME=1 bl32
      
      Change-Id: Ia34f5155e1cdb67161191f69e8d1248cbaa39e1a
      Signed-off-by: default avatarRoberto Vargas <roberto.vargas@arm.com>
      c96f297f
  5. 03 Jul, 2018 3 commits
    • Yann Gautier's avatar
      Add MMC framework · ad71d45e
      Yann Gautier authored
      
      
      This change is largely based on existing eMMC framework by Haojian Zhuang
      (@hzhuang1).
      
      The MMC framework supports both eMMC and SD card devices. It was
      written as a new framework since breaking few eMMC framework APIs.
      
      At card probe and after the reset to idle command (CMD0), a Send
      Interface Condition Command is sent (CMD8) to distinguish between
      eMMC and SD card devices. eMMC devices go through the same
      sequence as in the former eMMC framework. Else the framework
      uses commands dedicated to SD-cards for init or frequency switch.
      
      A structure is created to share info with the driver. It stores:
      - the MMC type (eMMC, SD or SD HC)
      - the device size
      - the max frequency supported by the device
      - the block size: 512 for eMMC and SD-HC and read from CSD
       structure for older SD-cards
      
      Restriction to align buffers on block size has been removed.
      Cache maintenance was removed and is expected to be done in the platform
      or device driver.
      
      The MMC framework includes some MISRA compliance coding style
      maybe not yet ported in the existing eMMC framework.
      
      Fixes ARM-software/tf-issues#597
      Signed-off-by: default avatarYann Gautier <yann.gautier@st.com>
      ad71d45e
    • Sandrine Bailleux's avatar
      Fix incorrect pointer conversion in SMC_UUID_RET() · 43b8fa8e
      Sandrine Bailleux authored
      
      
      Casting a pointer to a struct uuid into a pointer to uint32_t may
      result in a pointer that is not correctly aligned, which constitutes
      an undefined behaviour. In the case of TF, this also generates a data
      abort because alignment fault checking is enabled (through the SCTLR.A
      bit).
      
      This patch modifies the SMC_UUID_RET() macro to read the uuid
      structure without any pointer aliasing. A helper function then
      combines every set of 4 bytes into a 32-bit value suitable to be
      returned through the x0-x3 registers.
      
      This fixes a violation of MISRA rule 11.3.
      
      Change-Id: I53ee73bb4cb332f4d8286055ceceb6f347caa080
      Signed-off-by: default avatarSandrine Bailleux <sandrine.bailleux@arm.com>
      43b8fa8e
    • Antonio Nino Diaz's avatar
      xlat v2: Split code into separate files · fd2299e6
      Antonio Nino Diaz authored
      
      
      Instead of having one big file with all the code, it's better to have
      a few smaller files that are more manageable:
      
      - xlat_tables_core.c: Code related to the core functionality of the
        library (map and unmap regions, initialize xlat context).
      - xlat_tables_context.c: Instantiation of the active image context
        as well as APIs to manipulate it.
      - xlat_tables_utils.c: Helper code that isn't part of the core
        functionality (change attributes, debug print messages).
      
      Change-Id: I3ea956fc1afd7473c0bb5e7c6aab3b2e5d88c711
      Signed-off-by: default avatarAntonio Nino Diaz <antonio.ninodiaz@arm.com>
      fd2299e6
  6. 27 Jun, 2018 1 commit
    • Jeenu Viswambharan's avatar
      xlat v2: Split MMU setup and enable · 0cc7aa89
      Jeenu Viswambharan authored
      
      
      At present, the function provided by the translation library to enable
      MMU constructs appropriate values for translation library, and programs
      them to the right registers. The construction of initial values,
      however, is only required once as both the primary and secondaries
      program the same values.
      
      Additionally, the MMU-enabling function is written in C, which means
      there's an active stack at the time of enabling MMU. On some systems,
      like Arm DynamIQ, having active stack while enabling MMU during warm
      boot might lead to coherency problems.
      
      This patch addresses both the above problems by:
      
        - Splitting the MMU-enabling function into two: one that sets up
          values to be programmed into the registers, and another one that
          takes the pre-computed values and writes to the appropriate
          registers. With this, the primary effectively calls both functions
          to have the MMU enabled, but secondaries only need to call the
          latter.
      
        - Rewriting the function that enables MMU in assembly so that it
          doesn't use stack.
      
      This patch fixes a bunch of MISRA issues on the way.
      
      Change-Id: I0faca97263a970ffe765f0e731a1417e43fbfc45
      Signed-off-by: default avatarJeenu Viswambharan <jeenu.viswambharan@arm.com>
      0cc7aa89
  7. 26 Jun, 2018 1 commit
  8. 23 Jun, 2018 1 commit
  9. 22 Jun, 2018 1 commit
    • Antonio Nino Diaz's avatar
      xlat: Remove mmap_attr_t enum type · 3a1b7b10
      Antonio Nino Diaz authored
      
      
      The values defined in this type are used in logical operations, which
      goes against MISRA Rule 10.1: "Operands shall not be of an inappropriate
      essential type".
      
      Now, `unsigned int` is used instead. This also allows us to move the
      dynamic mapping bit from 30 to 31. It was an undefined behaviour in the
      past because an enum is signed by default, and bit 31 corresponds to the
      sign bit. It is undefined behaviour to modify the sign bit. Now, bit 31
      is free to use as it was originally meant to be.
      
      mmap_attr_t is now defined as an `unsigned int` for backwards
      compatibility.
      
      Change-Id: I6b31218c14b9c7fdabebe432de7fae6e90a97f34
      Signed-off-by: default avatarAntonio Nino Diaz <antonio.ninodiaz@arm.com>
      3a1b7b10
  10. 21 Jun, 2018 4 commits
    • Jeenu Viswambharan's avatar
      SDEI: Make dispatches synchronous · cdb6ac94
      Jeenu Viswambharan authored
      
      
      SDEI event dispatches currently only sets up the Non-secure context
      before returning to the caller. The actual dispatch only happens upon
      exiting EL3 next time.
      
      However, for various error handling scenarios, it's beneficial to have
      the dispatch happen synchronously. I.e. when receiving SDEI interrupt,
      or for a successful sdei_dispatch_event() call, the event handler is
      executed; and upon the event completion, dispatcher execution resumes
      after the point of dispatch. The jump primitives introduced in the
      earlier patch facilitates this feature.
      
      With this patch:
      
        - SDEI interrupts and calls to sdei_dispatch_event prepares the NS
          context for event dispatch, then sets a jump point, and immediately
          exits EL3. This results in the client handler executing in
          Non-secure.
      
        - When the SDEI client completes the dispatched event, the SDEI
          dispatcher does a longjmp to the jump pointer created earlier. For
          the caller of the sdei_dispatch_event() in particular, this would
          appear as if call returned successfully.
      
      The dynamic workaround for CVE_2018_3639 is slightly shifted around as
      part of related minor refactoring. It doesn't affect the workaround
      functionality.
      
      Documentation updated.
      
      NOTE: This breaks the semantics of the explicit dispatch API, and any
      exiting usages should be carefully reviewed.
      
      Change-Id: Ib9c876d27ea2af7fb22de49832e55a0da83da3f9
      Signed-off-by: default avatarJeenu Viswambharan <jeenu.viswambharan@arm.com>
      cdb6ac94
    • Jeenu Viswambharan's avatar
      BL31: Introduce jump primitives · e7b9473e
      Jeenu Viswambharan authored
      
      
      This patch introduces setjmp() and ongjmp() primitives to enable
      standard setjmp/longjmp style execution. Both APIs parameters take a
      pointer to struct jmpbuf type, which hosts CPU registers saved/restored
      during jump.
      
      As per the standard usage:
      
        - setjmp() return 0 when a jump is setup; and a non-zero value when
          returning from jump.
      
        - The caller of setjmp() must not return, or otherwise update stack
          pointer since.
      
      Change-Id: I4af1d32e490cfa547979631b762b4cba188d0551
      Signed-off-by: default avatarJeenu Viswambharan <jeenu.viswambharan@arm.com>
      e7b9473e
    • Jeenu Viswambharan's avatar
      SDEI: Allow platforms to define explicit events · af2c9ecd
      Jeenu Viswambharan authored
      
      
      The current macros only allow to define dynamic and statically-bound
      SDEI events. However, there ought be a mechanism to define SDEI events
      that are explicitly dispatched; i.e., events that are dispatched as a
      result of a previous secure interrupt or other exception
      
      This patch introduces SDEI_EXPLICIT_EVENT() macro to define an explicit
      event. They must be placed under private mappings. Only the priority
      flags are allowed to be additionally specified.
      
      Documentation updated.
      
      Change-Id: I2e12f5571381195d6234c9dfbd5904608ad41db3
      Signed-off-by: default avatarJeenu Viswambharan <jeenu.viswambharan@arm.com>
      af2c9ecd
    • Dimitris Papastamos's avatar
      fvp: Increase BL2 size for TBBR builds · 7ae58827
      Dimitris Papastamos authored
      
      
      Change-Id: I67e64bb79cc984ea3263f069e22738a42321c46d
      Signed-off-by: default avatarDimitris Papastamos <dimitris.papastamos@arm.com>
      7ae58827
  11. 20 Jun, 2018 2 commits
    • Antonio Nino Diaz's avatar
      SPM: Allow entering the SP without needing a SMC · 4d4ceb59
      Antonio Nino Diaz authored
      
      
      It may be needed to enter the Secure Partition through other means than
      an MM_COMMUNICATE SMC. This patch enables this behaviour by extracting
      the necessary code from mm_communicate() and allowing other parts of the
      code to use it.
      
      Change-Id: I59f6638d22d9c9d0baff0984f39d056298a8dc8e
      Signed-off-by: default avatarAntonio Nino Diaz <antonio.ninodiaz@arm.com>
      4d4ceb59
    • Soby Mathew's avatar
      ARM Platforms: Update CNTFRQ register in CNTCTLBase frame · 342d6220
      Soby Mathew authored
      
      
      Currently TF-A doesn't initialise CNTFRQ register in CNTCTLBase
      frame of the system timer. ARM ARM states that "The instance of
      the register in the CNTCTLBase frame must be programmed with this
      value as part of system initialization."
      
      The psci_arch_setup() updates the CNTFRQ system register but
      according to the ARM ARM, this instance of the register is
      independent of the memory mapped instance. This is only an issue
      for Normal world software which relies on the memory mapped
      instance rather than the system register one.
      
      This patch resolves the issue for ARM platforms.
      
      The patch also solves a related issue on Juno, wherein
      CNTBaseN.CNTFRQ can be written and does not reflect the value of
      the register in CNTCTLBase frame. Hence this patch additionally
      updates CNTFRQ register in the Non Secure frame of the CNTBaseN.
      
      Fixes ARM-Software/tf-issues#593
      
      Change-Id: I09cebb6633688b34d5b1bc349fbde4751025b350
      Signed-off-by: default avatarSoby Mathew <soby.mathew@arm.com>
      342d6220
  12. 19 Jun, 2018 1 commit
    • Antonio Nino Diaz's avatar
      plat/arm: Migrate AArch64 port to the multi console driver · 88a0523e
      Antonio Nino Diaz authored
      
      
      The old API is deprecated and will eventually be removed.
      
      Arm platforms now use the multi console driver for boot and runtime
      consoles. However, the crash console uses the direct console API because
      it doesn't need any memory access to work. This makes it more robust
      during crashes.
      
      The AArch32 port of the Trusted Firmware doesn't support this new API
      yet, so it is only enabled in AArch64 builds. Because of this, the
      common code must maintain compatibility with both systems. SP_MIN
      doesn't have to be updated because it's only used in AArch32 builds.
      The TSP is only used in AArch64, so it only needs to support the new
      API without keeping support for the old one.
      
      Special care must be taken because of PSCI_SYSTEM_SUSPEND. In Juno, this
      causes the UARTs to reset (except for the one used by the TSP). This
      means that they must be unregistered when suspending and re-registered
      when resuming. This wasn't a problem with the old driver because it just
      restarted the UART, and there were no problems associated with
      registering and unregistering consoles.
      
      The size reserved for BL2 has been increased.
      
      Change-Id: Icefd117dd1eb9c498921181a21318c2d2435c441
      Signed-off-by: default avatarAntonio Nino Diaz <antonio.ninodiaz@arm.com>
      88a0523e
  13. 18 Jun, 2018 1 commit
  14. 14 Jun, 2018 3 commits
    • Yann Gautier's avatar
      utils: Add BIT_32 and BIT_64 macros · 167c5f80
      Yann Gautier authored
      
      
      When applying some MISRA rules, lots of issues are raised with BIT macro
      on AARCH32, and cast on uint32_t would be required (Rule 10.3).
      The macros BIT_32 and BIT_64 are then created for 32bit and 64bit.
      Then the BIT macro defaults on BIT_64 on AARCH64,
      and on BIT_32 on AARCH32.
      Signed-off-by: default avatarYann Gautier <yann.gautier@st.com>
      167c5f80
    • Yann Gautier's avatar
      Add GENMASK macros · 39676357
      Yann Gautier authored
      
      
      Import GENMASK_32 and GENMASK_64 macros from optee-os (permissive license).
      And default GENMASK is set to GENMASK_32 for AARCH32,
      and to GENMASK_64 for 64bit arch.
      
      fixes arm-software/tf-issues#596
      Signed-off-by: default avatarYann Gautier <yann.gautier@st.com>
      Signed-off-by: default avatarNicolas Le Bayon <nicolas.le.bayon@st.com>
      39676357
    • Roberto Vargas's avatar
      Make TF UUID RFC 4122 compliant · 03364865
      Roberto Vargas authored
      
      
      RFC4122 defines that fields are stored in network order (big endian),
      but TF-A stores them in machine order (little endian by default in TF-A).
      We cannot change the future UUIDs that are already generated, but we can store
      all the bytes using arrays and modify fiptool to generate the UUIDs with
      the correct byte order.
      
      Change-Id: I97be2d3168d91f4dee7ccfafc533ea55ff33e46f
      Signed-off-by: default avatarRoberto Vargas <roberto.vargas@arm.com>
      03364865
  15. 13 Jun, 2018 2 commits
    • Sandrine Bailleux's avatar
      SPM: Treat SP xlat tables the same as others · d801a1d0
      Sandrine Bailleux authored
      The translation tables allocated for the Secure Partition do not need
      to be treated as a special case. They can be put amongst the other
      tables mapping BL31's general purpose memory. They will be mapped with
      the same attributes as them, which is fine.
      
      The explicit alignment constraint in BL31's linker script to pad the
      last page of memory allocated to the Secure Partition's translation
      tables is useless too, as page tables are per se pages, thus their
      end address is naturally aligned on a page-boundary.
      
      In fact, this patch does not change the existing behaviour. Since
      patch 22282bb6
      
       ("SPM: Move all SP-related info to SP context
      struct"), the secure_partition.c file has been renamed into sp_xlat.c
      but the linker script has not been properly updated. As a result, the
      SP translation tables are not specifically put at the start of the
      xlat_table linker section, the __SP_IMAGE_XLAT_TABLES_START__/_END__
      symbols have the same value, the size of the resulting mmap_region
      covering these xlat tables is 0 and so it is ignored.
      
      Change-Id: I4cf0a4cc090298811cca53fc9cee74df0f2b1512
      Signed-off-by: default avatarSandrine Bailleux <sandrine.bailleux@arm.com>
      d801a1d0
    • Antonio Nino Diaz's avatar
      xlat v2: Introduce xlat granule size helpers · a0b9bb79
      Antonio Nino Diaz authored
      
      
      The function xlat_arch_is_granule_size_supported() can be used to check
      if a specific granule size is supported. In Armv8, AArch32 only supports
      4 KiB pages. AArch64 supports 4 KiB, 16 KiB or 64 KiB depending on the
      implementation, which is detected at runtime.
      
      The function xlat_arch_get_max_supported_granule_size() returns the max
      granule size supported by the implementation.
      
      Even though right now they are only used by SPM, they may be useful in
      other places in the future. This patch moves the code currently in SPM
      to the xlat tables lib so that it can be reused.
      
      Change-Id: If54624a5ecf20b9b9b7f38861b56383a03bbc8a4
      Signed-off-by: default avatarAntonio Nino Diaz <antonio.ninodiaz@arm.com>
      a0b9bb79
  16. 12 Jun, 2018 2 commits
    • Daniel Boulby's avatar
      Fix MISRA Rule 5.3 Part 2 · 896a5902
      Daniel Boulby authored
      
      
      Use a _ prefix for Macro arguments to prevent that argument from
      hiding variables of the same name in the outer scope
      
      Rule 5.3: An identifier declared in an inner scope shall not
                hide an identifier declared in an outer scope
      
      Fixed For:
          make LOG_LEVEL=50 PLAT=fvp
      
      Change-Id: I67b6b05cbad4aeca65ce52981b4679b340604708
      Signed-off-by: default avatarDaniel Boulby <daniel.boulby@arm.com>
      896a5902
    • Daniel Boulby's avatar
      Fix MISRA Rule 5.3 Part 1 · d3775d46
      Daniel Boulby authored
      
      
      Conflict with function name and variable name within that function.
      Change the name of the function from image_size to get_image_size
      to remove conflict and make the function fit the normal project
      naming convention.
      
      Rule 5.3:  An identifier declared in an inner scope shall not
                 hide an identifier declared in an outer scope
      
      Fixed For:
          make LOG_LEVEL=50 PLAT=fvp
      
      Change-Id: I1a63d2730113e2741fffa79730459c584b0224d7
      Signed-off-by: default avatarDaniel Boulby <daniel.boulby@arm.com>
      d3775d46
  17. 11 Jun, 2018 2 commits
  18. 08 Jun, 2018 3 commits