GK SDK 源码库: XMIPCLinuxV100R005C00SPC030 (kernel/tools/open_source excluded)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
config FIRMWARE
|
||||
bool "Enable Firmware driver support"
|
||||
|
||||
config SPL_FIRMWARE
|
||||
bool "Enable Firmware driver support in SPL"
|
||||
depends on FIRMWARE
|
||||
|
||||
config SPL_ARM_PSCI_FW
|
||||
bool
|
||||
select SPL_FIRMWARE
|
||||
|
||||
config ARM_PSCI_FW
|
||||
bool
|
||||
select FIRMWARE
|
||||
|
||||
config TI_SCI_PROTOCOL
|
||||
tristate "TI System Control Interface (TISCI) Message Protocol"
|
||||
depends on K3_SEC_PROXY
|
||||
select FIRMWARE
|
||||
select SPL_FIRMWARE if SPL
|
||||
help
|
||||
TI System Control Interface (TISCI) Message Protocol is used to manage
|
||||
compute systems such as ARM, DSP etc with the system controller in
|
||||
complex System on Chip (SoC) such as those found on certain K3
|
||||
generation SoC from TI.
|
||||
|
||||
This protocol library is used by client drivers to use the features
|
||||
provided by the system controller.
|
||||
|
||||
config ZYNQMP_FIRMWARE
|
||||
bool "ZynqMP Firmware interface"
|
||||
select FIRMWARE
|
||||
help
|
||||
Firmware interface driver is used by different
|
||||
drivers to communicate with the firmware for
|
||||
various platform management services.
|
||||
Say yes to enable ZynqMP firmware interface driver.
|
||||
If in doubt, say N.
|
||||
@@ -0,0 +1,5 @@
|
||||
obj-$(CONFIG_FIRMWARE) += firmware-uclass.o
|
||||
obj-$(CONFIG_$(SPL_)ARM_PSCI_FW) += psci.o
|
||||
obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o
|
||||
obj-$(CONFIG_SANDBOX) += firmware-sandbox.o
|
||||
obj-$(CONFIG_ZYNQMP_FIRMWARE) += firmware-zynqmp.o
|
||||
@@ -0,0 +1,20 @@
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* sandbox firmware driver
|
||||
*
|
||||
* Copyright (C) 2018 Xilinx, Inc.
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <dm.h>
|
||||
|
||||
static const struct udevice_id generic_sandbox_firmware_ids[] = {
|
||||
{ .compatible = "sandbox,firmware" },
|
||||
{ }
|
||||
};
|
||||
|
||||
U_BOOT_DRIVER(sandbox_firmware) = {
|
||||
.name = "sandbox_firmware",
|
||||
.id = UCLASS_FIRMWARE,
|
||||
.of_match = generic_sandbox_firmware_ids,
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
|
||||
#include <common.h>
|
||||
#include <dm.h>
|
||||
|
||||
/* Firmware access is platform-dependent. No generic code in uclass */
|
||||
UCLASS_DRIVER(firmware) = {
|
||||
.id = UCLASS_FIRMWARE,
|
||||
.name = "firmware",
|
||||
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
|
||||
.post_bind = dm_scan_fdt_dev,
|
||||
#endif
|
||||
};
|
||||
@@ -0,0 +1,192 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Xilinx Zynq MPSoC Firmware driver
|
||||
*
|
||||
* Copyright (C) 2018-2019 Xilinx, Inc.
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <dm.h>
|
||||
#include <zynqmp_firmware.h>
|
||||
|
||||
#if defined(CONFIG_ZYNQMP_IPI)
|
||||
#include <mailbox.h>
|
||||
#include <asm/arch/sys_proto.h>
|
||||
|
||||
#define PMUFW_PAYLOAD_ARG_CNT 8
|
||||
|
||||
struct zynqmp_power {
|
||||
struct mbox_chan tx_chan;
|
||||
struct mbox_chan rx_chan;
|
||||
} zynqmp_power;
|
||||
|
||||
static int ipi_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
|
||||
{
|
||||
struct zynqmp_ipi_msg msg;
|
||||
int ret;
|
||||
|
||||
if (req_len > PMUFW_PAYLOAD_ARG_CNT ||
|
||||
res_maxlen > PMUFW_PAYLOAD_ARG_CNT)
|
||||
return -EINVAL;
|
||||
|
||||
if (!(zynqmp_power.tx_chan.dev) || !(&zynqmp_power.rx_chan.dev))
|
||||
return -EINVAL;
|
||||
|
||||
msg.buf = (u32 *)req;
|
||||
msg.len = req_len;
|
||||
ret = mbox_send(&zynqmp_power.tx_chan, &msg);
|
||||
if (ret) {
|
||||
debug("%s: Sending message failed\n", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
msg.buf = res;
|
||||
msg.len = res_maxlen;
|
||||
ret = mbox_recv(&zynqmp_power.rx_chan, &msg, 100);
|
||||
if (ret)
|
||||
debug("%s: Receiving message failed\n", __func__);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int send_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_SPL_BUILD))
|
||||
return ipi_req(req, req_len, res, res_maxlen);
|
||||
|
||||
return xilinx_pm_request(req[0], 0, 0, 0, 0, res);
|
||||
}
|
||||
|
||||
unsigned int zynqmp_firmware_version(void)
|
||||
{
|
||||
int ret;
|
||||
u32 ret_payload[PAYLOAD_ARG_CNT];
|
||||
static u32 pm_api_version = ZYNQMP_PM_VERSION_INVALID;
|
||||
|
||||
/*
|
||||
* Get PMU version only once and later
|
||||
* just return stored values instead of
|
||||
* asking PMUFW again.
|
||||
**/
|
||||
if (pm_api_version == ZYNQMP_PM_VERSION_INVALID) {
|
||||
const u32 request[] = { PM_GET_API_VERSION };
|
||||
|
||||
ret = send_req(request, ARRAY_SIZE(request), ret_payload, 2);
|
||||
if (ret)
|
||||
panic("PMUFW is not found - Please load it!\n");
|
||||
|
||||
pm_api_version = ret_payload[1];
|
||||
if (pm_api_version < ZYNQMP_PM_VERSION)
|
||||
panic("PMUFW version error. Expected: v%d.%d\n",
|
||||
ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR);
|
||||
}
|
||||
|
||||
return pm_api_version;
|
||||
};
|
||||
|
||||
/**
|
||||
* Send a configuration object to the PMU firmware.
|
||||
*
|
||||
* @cfg_obj: Pointer to the configuration object
|
||||
* @size: Size of @cfg_obj in bytes
|
||||
*/
|
||||
void zynqmp_pmufw_load_config_object(const void *cfg_obj, size_t size)
|
||||
{
|
||||
const u32 request[] = {
|
||||
PM_SET_CONFIGURATION,
|
||||
(u32)((u64)cfg_obj)
|
||||
};
|
||||
u32 response;
|
||||
int err;
|
||||
|
||||
printf("Loading new PMUFW cfg obj (%ld bytes)\n", size);
|
||||
|
||||
err = send_req(request, ARRAY_SIZE(request), &response, 1);
|
||||
if (err)
|
||||
panic("Cannot load PMUFW configuration object (%d)\n", err);
|
||||
if (response != 0)
|
||||
panic("PMUFW returned 0x%08x status!\n", response);
|
||||
}
|
||||
|
||||
static int zynqmp_power_probe(struct udevice *dev)
|
||||
{
|
||||
int ret;
|
||||
|
||||
debug("%s, (dev=%p)\n", __func__, dev);
|
||||
|
||||
ret = mbox_get_by_name(dev, "tx", &zynqmp_power.tx_chan);
|
||||
if (ret) {
|
||||
debug("%s: Cannot find tx mailbox\n", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = mbox_get_by_name(dev, "rx", &zynqmp_power.rx_chan);
|
||||
if (ret) {
|
||||
debug("%s: Cannot find rx mailbox\n", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = zynqmp_firmware_version();
|
||||
printf("PMUFW:\tv%d.%d\n",
|
||||
ret >> ZYNQMP_PM_VERSION_MAJOR_SHIFT,
|
||||
ret & ZYNQMP_PM_VERSION_MINOR_MASK);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
static const struct udevice_id zynqmp_power_ids[] = {
|
||||
{ .compatible = "xlnx,zynqmp-power" },
|
||||
{ }
|
||||
};
|
||||
|
||||
U_BOOT_DRIVER(zynqmp_power) = {
|
||||
.name = "zynqmp_power",
|
||||
.id = UCLASS_FIRMWARE,
|
||||
.of_match = zynqmp_power_ids,
|
||||
.probe = zynqmp_power_probe,
|
||||
};
|
||||
#endif
|
||||
|
||||
int __maybe_unused xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2,
|
||||
u32 arg3, u32 *ret_payload)
|
||||
{
|
||||
/*
|
||||
* Added SIP service call Function Identifier
|
||||
* Make sure to stay in x0 register
|
||||
*/
|
||||
struct pt_regs regs;
|
||||
|
||||
if (current_el() == 3) {
|
||||
printf("%s: Can't call SMC from EL3 context\n", __func__);
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
regs.regs[0] = PM_SIP_SVC | api_id;
|
||||
regs.regs[1] = ((u64)arg1 << 32) | arg0;
|
||||
regs.regs[2] = ((u64)arg3 << 32) | arg2;
|
||||
|
||||
smc_call(®s);
|
||||
|
||||
if (ret_payload) {
|
||||
ret_payload[0] = (u32)regs.regs[0];
|
||||
ret_payload[1] = upper_32_bits(regs.regs[0]);
|
||||
ret_payload[2] = (u32)regs.regs[1];
|
||||
ret_payload[3] = upper_32_bits(regs.regs[1]);
|
||||
ret_payload[4] = (u32)regs.regs[2];
|
||||
}
|
||||
|
||||
return regs.regs[0];
|
||||
}
|
||||
|
||||
static const struct udevice_id zynqmp_firmware_ids[] = {
|
||||
{ .compatible = "xlnx,zynqmp-firmware" },
|
||||
{ .compatible = "xlnx,versal-firmware"},
|
||||
{ }
|
||||
};
|
||||
|
||||
U_BOOT_DRIVER(zynqmp_firmware) = {
|
||||
.id = UCLASS_FIRMWARE,
|
||||
.name = "zynqmp-firmware",
|
||||
.probe = dm_scan_fdt_dev,
|
||||
.of_match = zynqmp_firmware_ids,
|
||||
};
|
||||
@@ -0,0 +1,163 @@
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* Copyright (C) 2017 Masahiro Yamada <yamada.masahiro@socionext.com>
|
||||
*
|
||||
* Based on drivers/firmware/psci.c from Linux:
|
||||
* Copyright (C) 2015 ARM Limited
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <dm.h>
|
||||
#include <irq_func.h>
|
||||
#include <dm/lists.h>
|
||||
#include <efi_loader.h>
|
||||
#include <linux/libfdt.h>
|
||||
#include <linux/arm-smccc.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/printk.h>
|
||||
#include <linux/psci.h>
|
||||
|
||||
#define DRIVER_NAME "psci"
|
||||
|
||||
#define PSCI_METHOD_HVC 1
|
||||
#define PSCI_METHOD_SMC 2
|
||||
|
||||
int __efi_runtime_data psci_method;
|
||||
|
||||
unsigned long __efi_runtime invoke_psci_fn
|
||||
(unsigned long function_id, unsigned long arg0,
|
||||
unsigned long arg1, unsigned long arg2)
|
||||
{
|
||||
struct arm_smccc_res res;
|
||||
|
||||
/*
|
||||
* In the __efi_runtime we need to avoid the switch statement. In some
|
||||
* cases the compiler creates lookup tables to implement switch. These
|
||||
* tables are not correctly relocated when SetVirtualAddressMap is
|
||||
* called.
|
||||
*/
|
||||
if (psci_method == PSCI_METHOD_SMC)
|
||||
arm_smccc_smc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
|
||||
else if (psci_method == PSCI_METHOD_HVC)
|
||||
arm_smccc_hvc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
|
||||
else
|
||||
res.a0 = PSCI_RET_DISABLED;
|
||||
return res.a0;
|
||||
}
|
||||
|
||||
static int psci_bind(struct udevice *dev)
|
||||
{
|
||||
/* No SYSTEM_RESET support for PSCI 0.1 */
|
||||
if (device_is_compatible(dev, "arm,psci-0.2") ||
|
||||
device_is_compatible(dev, "arm,psci-1.0")) {
|
||||
int ret;
|
||||
|
||||
/* bind psci-sysreset optionally */
|
||||
ret = device_bind_driver(dev, "psci-sysreset", "psci-sysreset",
|
||||
NULL);
|
||||
if (ret)
|
||||
pr_debug("PSCI System Reset was not bound.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int psci_probe(struct udevice *dev)
|
||||
{
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
const char *method;
|
||||
|
||||
method = fdt_stringlist_get(gd->fdt_blob, dev_of_offset(dev), "method",
|
||||
0, NULL);
|
||||
if (!method) {
|
||||
pr_warn("missing \"method\" property\n");
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
if (!strcmp("hvc", method)) {
|
||||
psci_method = PSCI_METHOD_HVC;
|
||||
} else if (!strcmp("smc", method)) {
|
||||
psci_method = PSCI_METHOD_SMC;
|
||||
} else {
|
||||
pr_warn("invalid \"method\" property: %s\n", method);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* void do_psci_probe() - probe PSCI firmware driver
|
||||
*
|
||||
* Ensure that psci_method is initialized.
|
||||
*/
|
||||
static void __maybe_unused do_psci_probe(void)
|
||||
{
|
||||
struct udevice *dev;
|
||||
|
||||
uclass_get_device_by_name(UCLASS_FIRMWARE, DRIVER_NAME, &dev);
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_EFI_LOADER) && IS_ENABLED(CONFIG_PSCI_RESET)
|
||||
efi_status_t efi_reset_system_init(void)
|
||||
{
|
||||
do_psci_probe();
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
void __efi_runtime EFIAPI efi_reset_system(enum efi_reset_type reset_type,
|
||||
efi_status_t reset_status,
|
||||
unsigned long data_size,
|
||||
void *reset_data)
|
||||
{
|
||||
if (reset_type == EFI_RESET_COLD ||
|
||||
reset_type == EFI_RESET_WARM ||
|
||||
reset_type == EFI_RESET_PLATFORM_SPECIFIC) {
|
||||
invoke_psci_fn(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0);
|
||||
} else if (reset_type == EFI_RESET_SHUTDOWN) {
|
||||
invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0);
|
||||
}
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
#endif /* IS_ENABLED(CONFIG_EFI_LOADER) && IS_ENABLED(CONFIG_PSCI_RESET) */
|
||||
|
||||
#ifdef CONFIG_PSCI_RESET
|
||||
void reset_misc(void)
|
||||
{
|
||||
do_psci_probe();
|
||||
invoke_psci_fn(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0);
|
||||
}
|
||||
#endif /* CONFIG_PSCI_RESET */
|
||||
|
||||
#ifdef CONFIG_CMD_POWEROFF
|
||||
int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||
{
|
||||
do_psci_probe();
|
||||
|
||||
puts("poweroff ...\n");
|
||||
udelay(50000); /* wait 50 ms */
|
||||
|
||||
disable_interrupts();
|
||||
invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0);
|
||||
enable_interrupts();
|
||||
|
||||
log_err("Power off not supported on this platform\n");
|
||||
return CMD_RET_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static const struct udevice_id psci_of_match[] = {
|
||||
{ .compatible = "arm,psci" },
|
||||
{ .compatible = "arm,psci-0.2" },
|
||||
{ .compatible = "arm,psci-1.0" },
|
||||
{},
|
||||
};
|
||||
|
||||
U_BOOT_DRIVER(psci) = {
|
||||
.name = DRIVER_NAME,
|
||||
.id = UCLASS_FIRMWARE,
|
||||
.of_match = psci_of_match,
|
||||
.bind = psci_bind,
|
||||
.probe = psci_probe,
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user