^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) ==========================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) Interface for registering and calling firmware-specific operations for ARM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) ==========================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) Written by Tomasz Figa <t.figa@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) Some boards are running with secure firmware running in TrustZone secure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) world, which changes the way some things have to be initialized. This makes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) a need to provide an interface for such platforms to specify available firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) operations and call them when needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) Firmware operations can be specified by filling in a struct firmware_ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) with appropriate callbacks and then registering it with register_firmware_ops()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) function::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) void register_firmware_ops(const struct firmware_ops *ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) The ops pointer must be non-NULL. More information about struct firmware_ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) and its members can be found in arch/arm/include/asm/firmware.h header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) There is a default, empty set of operations provided, so there is no need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) set anything if platform does not require firmware operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) To call a firmware operation, a helper macro is provided::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define call_firmware_op(op, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) ((firmware_ops->op) ? firmware_ops->op(__VA_ARGS__) : (-ENOSYS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) the macro checks if the operation is provided and calls it or otherwise returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) -ENOSYS to signal that given operation is not available (for example, to allow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) fallback to legacy operation).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) Example of registering firmware operations::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* board file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static int platformX_do_idle(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* tell platformX firmware to enter idle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static int platformX_cpu_boot(int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* tell platformX firmware to boot CPU i */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static const struct firmware_ops platformX_firmware_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .do_idle = exynos_do_idle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .cpu_boot = exynos_cpu_boot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* other operations not available on platformX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* init_early callback of machine descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static void __init board_init_early(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) register_firmware_ops(&platformX_firmware_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) Example of using a firmware operation::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* some platform code, e.g. SMP initialization */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) __raw_writel(__pa_symbol(exynos4_secondary_startup),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) CPU1_BOOT_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* Call Exynos specific smc call */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (call_firmware_op(cpu_boot, cpu) == -ENOSYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) cpu_boot_legacy(...); /* Try legacy way */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) gic_raise_softirq(cpumask_of(cpu), 1);