用于注册和调用 ARM 的固件特定操作的接口¶
由 Tomasz Figa <t.figa@samsung.com> 编写
有些板子运行着在 TrustZone 安全世界中运行的安全固件,这改变了一些事情的初始化方式。 这使得需要为这些平台提供一个接口来指定可用的固件操作,并在需要时调用它们。
可以通过填写一个带有适当回调的 struct firmware_ops 结构体,然后使用 register_firmware_ops() 函数注册它来指定固件操作。
void register_firmware_ops(const struct firmware_ops *ops)
ops 指针必须是非 NULL 的。 有关 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);