linux suspend/wake - up在mach-omap2上的工作原理



我正试图找出如何为mach-omap2实现暂停/唤醒,特别是在针对TI OMAP3530/DM3730的Linux 2.6.37中。

下面是一些相关代码:

http://lxr.free-electrons.com/source/arch/arm/mach-omap2/pm34xx.c?v=2.6.37

static int omap3_pm_suspend(void)
{
    struct power_state *pwrst;
    int state, ret = 0;
    if (wakeup_timer_seconds || wakeup_timer_milliseconds)
        omap2_pm_wakeup_on_timer(wakeup_timer_seconds,
                     wakeup_timer_milliseconds);
    /* Read current next_pwrsts */
    list_for_each_entry(pwrst, &pwrst_list, node)
        pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
    /* Set ones wanted by suspend */
    list_for_each_entry(pwrst, &pwrst_list, node) {
        if (omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state))
            goto restore;
        if (pwrdm_clear_all_prev_pwrst(pwrst->pwrdm))
            goto restore;
    }
    omap_uart_prepare_suspend();
    omap3_intc_suspend();
    omap_sram_idle();
restore:
    /* Restore next_pwrsts */
    list_for_each_entry(pwrst, &pwrst_list, node) {
        state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
        if (state > pwrst->next_state) {
            printk(KERN_INFO "Powerdomain (%s) didn't enter "
                   "target state %dn",
                   pwrst->pwrdm->name, pwrst->next_state);
            ret = -1;
        }
        omap_set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
    }
    if (ret)
        printk(KERN_ERR "Could not enter target state in pm_suspendn");
    else
        printk(KERN_INFO "Successfully put all powerdomains "
               "to target staten");
    return ret;
}

我真的很难理解它是如何工作的。

看起来,当挂起过程运行到omap_sram_idle();之后,系统已经处于挂起模式,在这个函数的上下文中,一切都冻结了。当它醒来时,它只是从restore:继续并恢复一切。这是正确的吗?

omap_sram_idle() 中间正在发生系统挂起。omap_sram_idle()的第二部分实际上是恢复代码。更确切地说,实际的休眠是由omap34xx_cpu_suspend()汇编函数中的wfi ARM指令完成的。

<标题>暂停路径
  • 查看omap_sram_idle()函数的实现
  • 你可以看到(从注释中判断)系统进入睡眠前的最后一行是_omap_sram_idle() call(这里)
  • _omap_sram_idle()指向omap34xx_cpu_suspend()汇编函数,该汇编函数先前复制到SRAM(因此在RAM断电时不会丢失);看看下面的代码行:

    1. _omap_sram_idle()赋值(注意传递给它的第一个参数是omap34xx_cpu_suspend函数地址)
    2. omap_sram_push()的实现;注意memcpy()调用:omap_sram_ceil是SRAM内存的起始地址,startomap34xx_cpu_suspend() function
    3. 的地址
    4. omap34xx_cpu_suspend()的实现;它是在这一行执行的实际函数(而不是_omap_sram_idle())。看一下函数上面的注释:

      /*
       * Forces OMAP into idle state
       *
       * omap34xx_suspend() - This bit of code just executes the WFI
       * for normal idles.
       *
       * Note: This code get's copied to internal SRAM at boot. When the OMAP
       *       wakes up it continues execution at the point it went to sleep.
       */
      
  • 实际睡眠发生在wfi (Wait For Interrupt) ARM指令(在omap34xx_cpu_suspend()函数中);

  • omap34xx_cpu_suspend()中有两个地方可以执行wfi:
    • 如果不需要上下文保存:此处
    • 如果需要保存上下文:此处
<标题>恢复路径

一旦出现唤醒信号,CPU将继续执行wfi指令之后的指令(这些指令一开始就使CPU进入休眠状态)。因此,您的系统在omap34xx_cpu_suspend()汇编函数中唤醒(从wait_sdrk_ok:标签开始),然后返回到omap_sram_idle()(到这一行),然后返回到omap3_pm_suspend(),到restore:标签。

相关内容

  • 没有找到相关文章

最新更新