types: use int-ll64 for both aarch32 and aarch64
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Fri, 2 Feb 2018 06:09:36 +0000 (15:09 +0900)
committerMasahiro Yamada <yamada.masahiro@socionext.com>
Fri, 27 Apr 2018 09:35:02 +0000 (18:35 +0900)
Since commit 031dbb122472 ("AArch32: Add essential Arch helpers"),
it is difficult to use consistent format strings for printf() family
between aarch32 and aarch64.

For example, uint64_t is defined as 'unsigned long long' for aarch32
and as 'unsigned long' for aarch64.  Likewise, uintptr_t is defined
as 'unsigned int' for aarch32, and as 'unsigned long' for aarch64.

A problem typically arises when you use printf() in common code.

One solution could be, to cast the arguments to a type long enough
for both architectures.  For example, if 'val' is uint64_t type,
like this:

  printf("val = %llx\n", (unsigned long long)val);

Or, somebody may suggest to use a macro provided by <inttypes.h>,
like this:

  printf("val = %" PRIx64 "\n", val);

But, both would make the code ugly.

The solution adopted in Linux kernel is to use the same typedefs for
all architectures.  The fixed integer types in the kernel-space have
been unified into int-ll64, like follows:

    typedef signed char           int8_t;
    typedef unsigned char         uint8_t;

    typedef signed short          int16_t;
    typedef unsigned short        uint16_t;

    typedef signed int            int32_t;
    typedef unsigned int          uint32_t;

    typedef signed long long      int64_t;
    typedef unsigned long long    uint64_t;

[ Linux commit: 0c79a8e29b5fcbcbfd611daf9d500cfad8370fcf ]

This gets along with the codebase shared between 32 bit and 64 bit,
with the data model called ILP32, LP64, respectively.

The width for primitive types is defined as follows:

                   ILP32           LP64
    int            32              32
    long           32              64
    long long      64              64
    pointer        32              64

'long long' is 64 bit for both, so it is used for defining uint64_t.
'long' has the same width as pointer, so for uintptr_t.

We still need an ifdef conditional for (s)size_t.

All 64 bit architectures use "unsigned long" size_t, and most 32 bit
architectures use "unsigned int" size_t.  H8/300, S/390 are known as
exceptions; they use "unsigned long" size_t despite their architecture
is 32 bit.

One idea for simplification might be to define size_t as 'unsigned long'
across architectures, then forbid the use of "%z" string format.
However, this would cause a distortion between size_t and sizeof()
operator.  We have unknowledge about the native type of sizeof(), so
we need a guess of it anyway.  I want the following formula to always
return 1:

  __builtin_types_compatible_p(size_t, typeof(sizeof(int)))

Fortunately, ARM is probably a majority case.  As far as I know, all
32 bit ARM compilers use "unsigned int" size_t.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
bl32/tsp/tsp_interrupt.c
bl32/tsp/tsp_main.c
include/lib/stdlib/machine/_types.h
plat/common/aarch64/plat_common.c
plat/hisilicon/hikey/hikey_bl1_setup.c
plat/nvidia/tegra/soc/t186/drivers/mce/mce.c
plat/rockchip/common/params_setup.c
plat/xilinx/zynqmp/plat_startup.c
services/spd/trusty/trusty.c

index cbfc152595b3845c4da2d0775199426c17f6c140..f501338143ea9550c979941cd1ec8ee16178810a 100644 (file)
@@ -33,7 +33,7 @@ void tsp_update_sync_sel1_intr_stats(uint32_t type, uint64_t elr_el3)
 
 #if LOG_LEVEL >= LOG_LEVEL_VERBOSE
        spin_lock(&console_lock);
-       VERBOSE("TSP: cpu 0x%lx sync s-el1 interrupt request from 0x%lx\n",
+       VERBOSE("TSP: cpu 0x%lx sync s-el1 interrupt request from 0x%llx\n",
                read_mpidr(), elr_el3);
        VERBOSE("TSP: cpu 0x%lx: %d sync s-el1 interrupt requests,"
                " %d sync s-el1 interrupt returns\n",
index 0de0ca8564f5a8e5fde79dd5247ae3e1cd058579..e41b51ebc7220be7d81f0a935219d2fadd4ab14e 100644 (file)
@@ -247,7 +247,7 @@ tsp_args_t *tsp_cpu_resume_main(uint64_t max_off_pwrlvl,
 
 #if LOG_LEVEL >= LOG_LEVEL_INFO
        spin_lock(&console_lock);
-       INFO("TSP: cpu 0x%lx resumed. maximum off power level %ld\n",
+       INFO("TSP: cpu 0x%lx resumed. maximum off power level %lld\n",
             read_mpidr(), max_off_pwrlvl);
        INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu suspend requests\n",
                read_mpidr(),
@@ -347,7 +347,7 @@ tsp_args_t *tsp_smc_handler(uint64_t func,
        tsp_stats[linear_id].smc_count++;
        tsp_stats[linear_id].eret_count++;
 
-       INFO("TSP: cpu 0x%lx received %s smc 0x%lx\n", read_mpidr(),
+       INFO("TSP: cpu 0x%lx received %s smc 0x%llx\n", read_mpidr(),
                ((func >> 31) & 1) == 1 ? "fast" : "yielding",
                func);
        INFO("TSP: cpu 0x%lx: %d smcs, %d erets\n", read_mpidr(),
index fb1083b74f49f9ec51ae07fc84b7013053ccf025..037fdf2f3aa139882fa33d42938e83ef94fef314 100644 (file)
@@ -52,56 +52,19 @@ typedef     short                   __int16_t;
 typedef        unsigned short          __uint16_t;
 typedef        int                     __int32_t;
 typedef        unsigned int            __uint32_t;
-
-
-/*
- * Standard type definitions which are different in AArch64 and AArch32
- */
-#ifdef AARCH32
 typedef        long long               __int64_t;
 typedef        unsigned long long      __uint64_t;
-typedef        __int32_t       __critical_t;
-typedef        __int32_t       __intfptr_t;
-typedef        __int32_t       __intptr_t;
-typedef        __int32_t       __ptrdiff_t;            /* ptr1 - ptr2 */
-typedef        __int32_t       __register_t;
-typedef        __int32_t       __segsz_t;              /* segment size (in pages) */
-typedef        __uint32_t      __size_t;               /* sizeof() */
-typedef        __int32_t       __ssize_t;              /* byte count or error */
-typedef        __uint32_t      __uintfptr_t;
-typedef        __uint32_t      __uintptr_t;
-typedef        __uint32_t      __u_register_t;
-typedef        __uint32_t      __vm_offset_t;
-typedef        __uint32_t      __vm_paddr_t;
-typedef        __uint32_t      __vm_size_t;
-#elif defined AARCH64
-typedef        long                    __int64_t;
-typedef        unsigned long           __uint64_t;
-typedef        __int64_t       __critical_t;
-typedef        __int64_t       __intfptr_t;
-typedef        __int64_t       __intptr_t;
-typedef        __int64_t       __ptrdiff_t;            /* ptr1 - ptr2 */
-typedef        __int64_t       __register_t;
-typedef        __int64_t       __segsz_t;              /* segment size (in pages) */
-typedef        __uint64_t      __size_t;               /* sizeof() */
-typedef        __int64_t       __ssize_t;              /* byte count or error */
-typedef        __uint64_t      __uintfptr_t;
-typedef        __uint64_t      __uintptr_t;
-typedef        __uint64_t      __u_register_t;
-typedef        __uint64_t      __vm_offset_t;
-typedef        __uint64_t      __vm_paddr_t;
-typedef        __uint64_t      __vm_size_t;
-#else
-#error "Only AArch32 or AArch64 supported"
-#endif /* AARCH32 */
 
 /*
  * Standard type definitions.
  */
 typedef        __int32_t       __clock_t;              /* clock()... */
+typedef        long            __critical_t;
 typedef        double          __double_t;
 typedef        float           __float_t;
+typedef        long            __intfptr_t;
 typedef        __int64_t       __intmax_t;
+typedef        long            __intptr_t;
 typedef        __int32_t       __int_fast8_t;
 typedef        __int32_t       __int_fast16_t;
 typedef        __int32_t       __int_fast32_t;
@@ -110,8 +73,22 @@ typedef     __int8_t        __int_least8_t;
 typedef        __int16_t       __int_least16_t;
 typedef        __int32_t       __int_least32_t;
 typedef        __int64_t       __int_least64_t;
+typedef        long            __ptrdiff_t;            /* ptr1 - ptr2 */
+typedef        long            __register_t;
+typedef        long            __segsz_t;              /* segment size (in pages) */
+#ifdef AARCH32
+typedef        unsigned int    __size_t;               /* sizeof() */
+typedef        int             __ssize_t;              /* byte count or error */
+#elif defined AARCH64
+typedef        unsigned long   __size_t;               /* sizeof() */
+typedef        long            __ssize_t;              /* byte count or error */
+#else
+#error "Only AArch32 or AArch64 supported"
+#endif /* AARCH32 */
 typedef        __int64_t       __time_t;               /* time()... */
+typedef        unsigned long   __uintfptr_t;
 typedef        __uint64_t      __uintmax_t;
+typedef        unsigned long   __uintptr_t;
 typedef        __uint32_t      __uint_fast8_t;
 typedef        __uint32_t      __uint_fast16_t;
 typedef        __uint32_t      __uint_fast32_t;
@@ -120,8 +97,12 @@ typedef     __uint8_t       __uint_least8_t;
 typedef        __uint16_t      __uint_least16_t;
 typedef        __uint32_t      __uint_least32_t;
 typedef        __uint64_t      __uint_least64_t;
+typedef        unsigned long   __u_register_t;
+typedef        unsigned long   __vm_offset_t;
 typedef        __int64_t       __vm_ooffset_t;
+typedef        unsigned long   __vm_paddr_t;
 typedef        __uint64_t      __vm_pindex_t;
+typedef        unsigned long   __vm_size_t;
 
 /*
  * Unusual type definitions.
index ddd29f29be97e8e5fe5d62ad6762ec200a9985ae..7a2f38cb0365441a13e7ac32d65de84e4599c509 100644 (file)
@@ -93,7 +93,7 @@ void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  */
 void plat_sdei_handle_masked_trigger(uint64_t mpidr, unsigned int intr)
 {
-       WARN("Spurious SDEI interrupt %u on masked PE %lx\n", intr, mpidr);
+       WARN("Spurious SDEI interrupt %u on masked PE %llx\n", intr, mpidr);
 }
 
 /*
index 28ad9df224057544f8a61dbcebc6d8222f909f9d..da6f6a51949f2428b36e94d51aa6fb90368c29de 100644 (file)
@@ -172,7 +172,7 @@ void bl1_plat_set_ep_info(unsigned int image_id,
                __asm__ volatile ("msr  cpacr_el1, %0" : : "r"(data));
                __asm__ volatile ("mrs  %0, cpacr_el1" : "=r"(data));
        } while ((data & (3 << 20)) != (3 << 20));
-       INFO("cpacr_el1:0x%lx\n", data);
+       INFO("cpacr_el1:0x%llx\n", data);
 
        ep_info->args.arg0 = 0xffff & read_mpidr();
        ep_info->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX,
index 5435ce6e9e1672b064e5d7d0367a3591dac7a150..1353b6ab5a9bb63f50cc70dafa77e07f81cd3152 100644 (file)
@@ -382,7 +382,7 @@ int32_t mce_command_handler(uint64_t cmd, uint64_t arg0, uint64_t arg1,
                break;
 
        default:
-               ERROR("unknown MCE command (%lu)\n", cmd);
+               ERROR("unknown MCE command (%llu)\n", cmd);
                ret = EINVAL;
                break;
        }
index 65afe87696ffd5a03c257fe39eba036fa9f09e38..3dac01328c956a60d48e21361d41f23db8ab5489 100644 (file)
@@ -92,7 +92,7 @@ void params_early_setup(void *plat_param_from_bl2)
                        break;
 #endif
                default:
-                       ERROR("not expected type found %ld\n",
+                       ERROR("not expected type found %lld\n",
                              bl2_param->type);
                        break;
                }
index 3ec492e7a0bdf435ea70aec45460333213022958..18d150c91433b666883b3ebc0ff3359c57e4861d 100644 (file)
@@ -166,12 +166,12 @@ void fsbl_atf_handover(entry_point_info_t *bl32, entry_point_info_t *bl33)
            (ATFHandoffParams->magic[1] != 'L') ||
            (ATFHandoffParams->magic[2] != 'N') ||
            (ATFHandoffParams->magic[3] != 'X')) {
-               ERROR("BL31: invalid ATF handoff structure at %lx\n",
+               ERROR("BL31: invalid ATF handoff structure at %llx\n",
                      atf_handoff_addr);
                panic();
        }
 
-       VERBOSE("BL31: ATF handoff params at:0x%lx, entries:%u\n",
+       VERBOSE("BL31: ATF handoff params at:0x%llx, entries:%u\n",
                atf_handoff_addr, ATFHandoffParams->num_entries);
        if (ATFHandoffParams->num_entries > FSBL_MAX_PARTITIONS) {
                ERROR("BL31: ATF handoff params: too many partitions (%u/%u)\n",
@@ -189,7 +189,7 @@ void fsbl_atf_handover(entry_point_info_t *bl32, entry_point_info_t *bl33)
                int target_estate, target_secure;
                int target_cpu, target_endianness, target_el;
 
-               VERBOSE("BL31: %zd: entry:0x%lx, flags:0x%lx\n", i,
+               VERBOSE("BL31: %zd: entry:0x%llx, flags:0x%llx\n", i,
                        ATFHandoffParams->partition[i].entry_point,
                        ATFHandoffParams->partition[i].flags);
 
@@ -250,7 +250,7 @@ void fsbl_atf_handover(entry_point_info_t *bl32, entry_point_info_t *bl33)
                        }
                }
 
-               VERBOSE("Setting up %s entry point to:%lx, el:%x\n",
+               VERBOSE("Setting up %s entry point to:%llx, el:%x\n",
                        target_secure == FSBL_FLAGS_SECURE ? "BL32" : "BL33",
                        ATFHandoffParams->partition[i].entry_point,
                        target_el);
index 48a2611bd5d3131915c1b6af86116ad7f3dd0849..cc808e2b0b59b37040968b8807909b3d9f96d0d9 100644 (file)
@@ -159,7 +159,7 @@ static uint64_t trusty_set_fiq_handler(void *handle, uint64_t cpu,
        struct trusty_cpu_ctx *ctx;
 
        if (cpu >= PLATFORM_CORE_COUNT) {
-               ERROR("%s: cpu %ld >= %d\n", __func__, cpu, PLATFORM_CORE_COUNT);
+               ERROR("%s: cpu %lld >= %d\n", __func__, cpu, PLATFORM_CORE_COUNT);
                return SM_ERR_INVALID_PARAMETERS;
        }
 
@@ -191,7 +191,7 @@ static uint64_t trusty_fiq_exit(void *handle, uint64_t x1, uint64_t x2, uint64_t
 
        ret = trusty_context_switch(NON_SECURE, SMC_FC_FIQ_EXIT, 0, 0, 0);
        if (ret.r0 != 1) {
-               INFO("%s(%p) SMC_FC_FIQ_EXIT returned unexpected value, %ld\n",
+               INFO("%s(%p) SMC_FC_FIQ_EXIT returned unexpected value, %lld\n",
                       __func__, handle, ret.r0);
        }
 
@@ -331,7 +331,7 @@ static void trusty_cpu_suspend(uint32_t off)
 
        ret = trusty_context_switch(NON_SECURE, SMC_FC_CPU_SUSPEND, off, 0, 0);
        if (ret.r0 != 0) {
-               INFO("%s: cpu %d, SMC_FC_CPU_SUSPEND returned unexpected value, %ld\n",
+               INFO("%s: cpu %d, SMC_FC_CPU_SUSPEND returned unexpected value, %lld\n",
                     __func__, plat_my_core_pos(), ret.r0);
        }
 }
@@ -342,7 +342,7 @@ static void trusty_cpu_resume(uint32_t on)
 
        ret = trusty_context_switch(NON_SECURE, SMC_FC_CPU_RESUME, on, 0, 0);
        if (ret.r0 != 0) {
-               INFO("%s: cpu %d, SMC_FC_CPU_RESUME returned unexpected value, %ld\n",
+               INFO("%s: cpu %d, SMC_FC_CPU_RESUME returned unexpected value, %lld\n",
                     __func__, plat_my_core_pos(), ret.r0);
        }
 }