ATF BL1 UFS初始化分析
- 1 ATF的下载链接
- 2 ATF BL1 UFS 初始化简易流程图
- 3 ATF BL1 ufs初始化简单过程分析
- 3.1 调用过程
- 3.2 hikey960_ufs_init
- 3.3 dw_ufs_init
- 3.3 ufs_init
以海思hikey960为例来介绍,简单介绍在ATF BL1阶段的初始化处理。
1 ATF的下载链接
https://github.com/ARM-software/arm-trusted-firmware
可以通过下面的命令来下载ATF的代码,或者通过打包下载的方式也可以。
git clone git@github.com:ARM-software/arm-trusted-firmware.git
2 ATF BL1 UFS 初始化简易流程图
3 ATF BL1 ufs初始化简单过程分析
3.1 调用过程
以以海思hikey960为例来介绍ATF BL1 ufs 初始化的调用关系
| -- bl1_main -------- bl1_main.c| - bl1_platform_setup -------- plat/hisilicon/hikey960/hikey960_bl1_setup.c| - hikey960_ufs_init -------- plat/hisilicon/hikey960/hikey960_bl1_setup.c| - hikey960_ufs_reset -------- plat/hisilicon/hikey960/hikey960_bl1_setup.c| - dw_ufs_init -------- drivers/synopsys/ufs/dw_ufs.c| - ufs_init -------- drivers/synopsys/ufs/dw_ufs.c
3.2 hikey960_ufs_init
UFS_REG_BASE
表示UFS 配置空间的基地址HIKEY960_UFS_DESC_BASE
表示ufs 描述符的基地址HIKEY960_UFS_DESC_SIZE
表示ufs描述符的大小(ufs_params.flags & UFS_FLAGS_SKIPINIT) == 0
当前ufs驱动的flag如果是skipinit则先去做复位操作,对于hikey960来说是不会参与该处理流程的。dw_ufs_init(&ufs_params);
dw ufs的初始化处理
static void hikey960_ufs_init(void)
{dw_ufs_params_t ufs_params;memset(&ufs_params, 0, sizeof(ufs_params));ufs_params.reg_base = UFS_REG_BASE;ufs_params.desc_base = HIKEY960_UFS_DESC_BASE; ufs_params.desc_size = HIKEY960_UFS_DESC_SIZE;if ((ufs_params.flags & UFS_FLAGS_SKIPINIT) == 0)hikey960_ufs_reset();dw_ufs_init(&ufs_params);
}
3.3 dw_ufs_init
.phy_init
ufs phy初始化的处理.phy_set_pwr_mode
ufs phy 电源模式设置ufs_init(&dw_ufs_ops, &ufs_params);
dw ufs以dw_ufs_ops
作为初始化ops以及ufs_params
配置参数去做对应的dw ufs初始化操作。
static const ufs_ops_t dw_ufs_ops = {.phy_init = dwufs_phy_init,.phy_set_pwr_mode = dwufs_phy_set_pwr_mode,
};int dw_ufs_init(dw_ufs_params_t *params)
{ ufs_params_t ufs_params;memset(&ufs_params, 0, sizeof(ufs_params));ufs_params.reg_base = params->reg_base;ufs_params.desc_base = params->desc_base;ufs_params.desc_size = params->desc_size;ufs_params.flags = params->flags; ufs_init(&dw_ufs_ops, &ufs_params);return 0;
}
3.3 ufs_init
nutrs = (mmio_read_32(ufs_params.reg_base + CAP) & CAP_NUTRS_MASK) + 1;
读取CAP寄存器去获取UTP传输请求槽数量Number of UTP Transfer Request Slots (NUTRS)
。当前在BL1阶段采用的是Legacy Single Doorbell mode
。
Number of UTP Transfer Request Slots (NUTRS): For Legacy Single Doorbell mode, this indicates the number of slots provided by the UTP Transfer Request List. A minimum of 1 and maximum of 32 slots may be supported.
UTP传输请求槽数 (NUTRS): 对于传统单门铃模式,它表示UTP 传输请求列表提供的槽数量。可支持最少 1 个、最多 32 个插槽。
For MCQ mode, this field specifies how many active transfer tasks the Host HW controller is capable of managing in parallel. The minimum of 1 and maximum of 256 slots may be supported.
对于 MCQ 模式,该字段指定主机硬件控制器能够并行管理的活动传输任务数量。最少可支持 1 个插槽,最多可支持 256 个插槽。
ufshc_reset(ufs_params.reg_base);
ufs 复位操作ops->phy_init(&ufs_params);
ufs phy初始化,这个会调用在dw_ufs_init注册的ops的phy_init接口,即dwufs_phy_init
ufshc_link_startup(ufs_params.reg_base);
执行linkstartupufs_get_device_info(&card);
获取当前UFS设备的设备描述符ops->phy_set_pwr_mode(&ufs_params);
设置当前ufs的工作电源模式,会调用到dw_ufs_init注册的opsphy_set_pwr_mode接口,即dwufs_phy_set_pwr_mode
函数
int ufs_init(const ufs_ops_t *ops, ufs_params_t *params)
{int result;unsigned int data;uic_cmd_t cmd;struct ufs_dev_desc card = {0};assert((params != NULL) &&(params->reg_base != 0) &&(params->desc_base != 0) &&(params->desc_size >= UFS_DESC_SIZE));memcpy(&ufs_params, params, sizeof(ufs_params_t));/* 0 means 1 slot */nutrs = (mmio_read_32(ufs_params.reg_base + CAP) & CAP_NUTRS_MASK) + 1;if (nutrs > (ufs_params.desc_size / UFS_DESC_SIZE)) {nutrs = ufs_params.desc_size / UFS_DESC_SIZE;}if (ufs_params.flags & UFS_FLAGS_SKIPINIT) {mmio_write_32(ufs_params.reg_base + UTRLBA,ufs_params.desc_base & UINT32_MAX);mmio_write_32(ufs_params.reg_base + UTRLBAU,(ufs_params.desc_base >> 32) & UINT32_MAX);result = ufshc_dme_get(0x1571, 0, &data);assert(result == 0);result = ufshc_dme_get(0x41, 0, &data);assert(result == 0);if (data == 1) {/* prepare to exit hibernate mode */memset(&cmd, 0, sizeof(uic_cmd_t));cmd.op = DME_HIBERNATE_EXIT; result = ufshc_send_uic_cmd(ufs_params.reg_base,&cmd);assert(result == 0);data = mmio_read_32(ufs_params.reg_base + UCMDARG2);assert(data == 0);do {data = mmio_read_32(ufs_params.reg_base + IS);} while ((data & UFS_INT_UHXS) == 0);mmio_write_32(ufs_params.reg_base + IS, UFS_INT_UHXS);data = mmio_read_32(ufs_params.reg_base + HCS);assert((data & HCS_UPMCRS_MASK) == HCS_PWR_LOCAL);}result = ufshc_dme_get(0x1568, 0, &data);assert(result == 0);assert((data > 0) && (data <= 3));} else {assert((ops != NULL) && (ops->phy_init != NULL) &&(ops->phy_set_pwr_mode != NULL));result = ufshc_reset(ufs_params.reg_base);assert(result == 0);ops->phy_init(&ufs_params);result = ufshc_link_startup(ufs_params.reg_base);assert(result == 0);/* enable all interrupts */data = UFS_INT_UCCS | UFS_INT_UHES | UFS_INT_UHXS | UFS_INT_UPMS;data |= UFS_INT_UTRCS | UFS_INT_ERR;mmio_write_32(ufs_params.reg_base + IE, data);ufs_enum();ufs_get_device_info(&card);if (card.wmanufacturerid == UFS_VENDOR_SKHYNIX) {ufs_params.flags |= UFS_FLAGS_VENDOR_SKHYNIX;}ops->phy_set_pwr_mode(&ufs_params);}(void)result;return 0;
}