用于 ARM 固件特定操作的注册与调用接口

作者:Tomasz Figa <t.figa@samsung.com>

一些开发板运行在 TrustZone 安全世界中的安全固件上,这改变了某些事务的初始化方式。因此,需要为这类平台提供一个接口,以指定可用的固件操作并在需要时调用它们。

可以通过填充 struct firmware_ops 并提供相应的回调函数,然后使用 register_firmware_ops() 函数进行注册,来指定固件操作

void register_firmware_ops(const struct firmware_ops *ops)

ops 指针必须为非空。关于 struct firmware_ops 及其成员的更多信息,可以在 arch/arm/include/asm/firmware.h 头文件中找到。

系统提供了一套默认的空操作集合,因此如果平台不需要固件操作,则无需进行任何设置。

为了调用固件操作,系统提供了一个辅助宏

#define call_firmware_op(op, ...)                               \
        ((firmware_ops->op) ? firmware_ops->op(__VA_ARGS__) : (-ENOSYS))

该宏会检查是否提供了该操作并调用它,否则返回 -ENOSYS 以标示给定的操作不可用(例如,允许回退到旧有操作)。

注册固件操作示例

/* board file */

static int platformX_do_idle(void)
{
        /* tell platformX firmware to enter idle */
        return 0;
}

static int platformX_cpu_boot(int i)
{
        /* tell platformX firmware to boot CPU i */
        return 0;
}

static const struct firmware_ops platformX_firmware_ops = {
        .do_idle        = exynos_do_idle,
        .cpu_boot       = exynos_cpu_boot,
        /* other operations not available on platformX */
};

/* init_early callback of machine descriptor */
static void __init board_init_early(void)
{
        register_firmware_ops(&platformX_firmware_ops);
}

使用固件操作示例

/* some platform code, e.g. SMP initialization */

__raw_writel(__pa_symbol(exynos4_secondary_startup),
        CPU1_BOOT_REG);

/* Call Exynos specific smc call */
if (call_firmware_op(cpu_boot, cpu) == -ENOSYS)
        cpu_boot_legacy(...); /* Try legacy way */

gic_raise_softirq(cpumask_of(cpu), 1);