linux/arch/arm/firmware/trusted_foundations.c
<<
>>
Prefs
   1/*
   2 * Trusted Foundations support for ARM CPUs
   3 *
   4 * Copyright (c) 2013, NVIDIA Corporation.
   5 *
   6 * This program is free software; you can redistribute it and/or modify
   7 * it under the terms of the GNU General Public License as published by
   8 * the Free Software Foundation; either version 2 of the License, or
   9 * (at your option) any later version.
  10 *
  11 * This program is distributed in the hope that it will be useful, but WITHOUT
  12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  14 * more details.
  15 */
  16
  17#include <linux/kernel.h>
  18#include <linux/init.h>
  19#include <linux/of.h>
  20#include <asm/firmware.h>
  21#include <asm/trusted_foundations.h>
  22
  23#define TF_SET_CPU_BOOT_ADDR_SMC 0xfffff200
  24
  25#define TF_CPU_PM               0xfffffffc
  26#define TF_CPU_PM_S3            0xffffffe3
  27#define TF_CPU_PM_S2            0xffffffe6
  28#define TF_CPU_PM_S2_NO_MC_CLK  0xffffffe5
  29#define TF_CPU_PM_S1            0xffffffe4
  30#define TF_CPU_PM_S1_NOFLUSH_L2 0xffffffe7
  31
  32static unsigned long cpu_boot_addr;
  33
  34static void __naked tf_generic_smc(u32 type, u32 arg1, u32 arg2)
  35{
  36        asm volatile(
  37                ".arch_extension        sec\n\t"
  38                "stmfd  sp!, {r4 - r11, lr}\n\t"
  39                __asmeq("%0", "r0")
  40                __asmeq("%1", "r1")
  41                __asmeq("%2", "r2")
  42                "mov    r3, #0\n\t"
  43                "mov    r4, #0\n\t"
  44                "smc    #0\n\t"
  45                "ldmfd  sp!, {r4 - r11, pc}"
  46                :
  47                : "r" (type), "r" (arg1), "r" (arg2)
  48                : "memory");
  49}
  50
  51static int tf_set_cpu_boot_addr(int cpu, unsigned long boot_addr)
  52{
  53        cpu_boot_addr = boot_addr;
  54        tf_generic_smc(TF_SET_CPU_BOOT_ADDR_SMC, cpu_boot_addr, 0);
  55
  56        return 0;
  57}
  58
  59static int tf_prepare_idle(void)
  60{
  61        tf_generic_smc(TF_CPU_PM, TF_CPU_PM_S1_NOFLUSH_L2, cpu_boot_addr);
  62
  63        return 0;
  64}
  65
  66static const struct firmware_ops trusted_foundations_ops = {
  67        .set_cpu_boot_addr = tf_set_cpu_boot_addr,
  68        .prepare_idle = tf_prepare_idle,
  69};
  70
  71void register_trusted_foundations(struct trusted_foundations_platform_data *pd)
  72{
  73        /*
  74         * we are not using version information for now since currently
  75         * supported SMCs are compatible with all TF releases
  76         */
  77        register_firmware_ops(&trusted_foundations_ops);
  78}
  79
  80void of_register_trusted_foundations(void)
  81{
  82        struct device_node *node;
  83        struct trusted_foundations_platform_data pdata;
  84        int err;
  85
  86        node = of_find_compatible_node(NULL, NULL, "tlm,trusted-foundations");
  87        if (!node)
  88                return;
  89
  90        err = of_property_read_u32(node, "tlm,version-major",
  91                                   &pdata.version_major);
  92        if (err != 0)
  93                panic("Trusted Foundation: missing version-major property\n");
  94        err = of_property_read_u32(node, "tlm,version-minor",
  95                                   &pdata.version_minor);
  96        if (err != 0)
  97                panic("Trusted Foundation: missing version-minor property\n");
  98        register_trusted_foundations(&pdata);
  99}
 100