LCOV - code coverage report
Current view: top level - arch/arm/kernel - reboot.c (source / functions) Hit Total Coverage
Test: Real Lines: 0 34 0.0 %
Date: 2020-10-17 15:46:43 Functions: 0 7 0.0 %
Legend: Neither, QEMU, Real, Both Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: GPL-2.0-only
       2                 :            : /*
       3                 :            :  *  Copyright (C) 1996-2000 Russell King - Converted to ARM.
       4                 :            :  *  Original Copyright (C) 1995  Linus Torvalds
       5                 :            :  */
       6                 :            : #include <linux/cpu.h>
       7                 :            : #include <linux/delay.h>
       8                 :            : #include <linux/reboot.h>
       9                 :            : 
      10                 :            : #include <asm/cacheflush.h>
      11                 :            : #include <asm/idmap.h>
      12                 :            : #include <asm/virt.h>
      13                 :            : 
      14                 :            : #include "reboot.h"
      15                 :            : 
      16                 :            : typedef void (*phys_reset_t)(unsigned long, bool);
      17                 :            : 
      18                 :            : /*
      19                 :            :  * Function pointers to optional machine specific functions
      20                 :            :  */
      21                 :            : void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
      22                 :            : void (*pm_power_off)(void);
      23                 :            : EXPORT_SYMBOL(pm_power_off);
      24                 :            : 
      25                 :            : /*
      26                 :            :  * A temporary stack to use for CPU reset. This is static so that we
      27                 :            :  * don't clobber it with the identity mapping. When running with this
      28                 :            :  * stack, any references to the current task *will not work* so you
      29                 :            :  * should really do as little as possible before jumping to your reset
      30                 :            :  * code.
      31                 :            :  */
      32                 :            : static u64 soft_restart_stack[16];
      33                 :            : 
      34                 :          0 : static void __soft_restart(void *addr)
      35                 :            : {
      36                 :            :         phys_reset_t phys_reset;
      37                 :            : 
      38                 :            :         /* Take out a flat memory mapping. */
      39                 :          0 :         setup_mm_for_reboot();
      40                 :            : 
      41                 :            :         /* Clean and invalidate caches */
      42                 :          0 :         flush_cache_all();
      43                 :            : 
      44                 :            :         /* Turn off caching */
      45                 :          0 :         cpu_proc_fin();
      46                 :            : 
      47                 :            :         /* Push out any further dirty data, and ensure cache is empty */
      48                 :          0 :         flush_cache_all();
      49                 :            : 
      50                 :            :         /* Switch to the identity mapping. */
      51                 :          0 :         phys_reset = (phys_reset_t)virt_to_idmap(cpu_reset);
      52                 :            : 
      53                 :            :         /* original stub should be restored by kvm */
      54                 :          0 :         phys_reset((unsigned long)addr, is_hyp_mode_available());
      55                 :            : 
      56                 :            :         /* Should never get here. */
      57                 :          0 :         BUG();
      58                 :            : }
      59                 :            : 
      60                 :          0 : void _soft_restart(unsigned long addr, bool disable_l2)
      61                 :            : {
      62                 :            :         u64 *stack = soft_restart_stack + ARRAY_SIZE(soft_restart_stack);
      63                 :            : 
      64                 :            :         /* Disable interrupts first */
      65                 :            :         raw_local_irq_disable();
      66                 :          0 :         local_fiq_disable();
      67                 :            : 
      68                 :            :         /* Disable the L2 if we're the last man standing. */
      69                 :            :         if (disable_l2)
      70                 :            :                 outer_disable();
      71                 :            : 
      72                 :            :         /* Change to the new stack and continue with the reset. */
      73                 :          0 :         call_with_stack(__soft_restart, (void *)addr, (void *)stack);
      74                 :            : 
      75                 :            :         /* Should never get here. */
      76                 :          0 :         BUG();
      77                 :            : }
      78                 :            : 
      79                 :          0 : void soft_restart(unsigned long addr)
      80                 :            : {
      81                 :          0 :         _soft_restart(addr, num_online_cpus() == 1);
      82                 :            : }
      83                 :            : 
      84                 :            : /*
      85                 :            :  * Called by kexec, immediately prior to machine_kexec().
      86                 :            :  *
      87                 :            :  * This must completely disable all secondary CPUs; simply causing those CPUs
      88                 :            :  * to execute e.g. a RAM-based pin loop is not sufficient. This allows the
      89                 :            :  * kexec'd kernel to use any and all RAM as it sees fit, without having to
      90                 :            :  * avoid any code or data used by any SW CPU pin loop. The CPU hotplug
      91                 :            :  * functionality embodied in disable_nonboot_cpus() to achieve this.
      92                 :            :  */
      93                 :          0 : void machine_shutdown(void)
      94                 :            : {
      95                 :            :         disable_nonboot_cpus();
      96                 :          0 : }
      97                 :            : 
      98                 :            : /*
      99                 :            :  * Halting simply requires that the secondary CPUs stop performing any
     100                 :            :  * activity (executing tasks, handling interrupts). smp_send_stop()
     101                 :            :  * achieves this.
     102                 :            :  */
     103                 :          0 : void machine_halt(void)
     104                 :            : {
     105                 :          0 :         machine_power_off();
     106                 :          0 : }
     107                 :            : 
     108                 :            : /*
     109                 :            :  * Power-off simply requires that the secondary CPUs stop performing any
     110                 :            :  * activity (executing tasks, handling interrupts). smp_send_stop()
     111                 :            :  * achieves this. When the system power is turned off, it will take all CPUs
     112                 :            :  * with it.
     113                 :            :  */
     114                 :          0 : void machine_power_off(void)
     115                 :            : {
     116                 :          0 :         local_irq_disable();
     117                 :          0 :         smp_send_stop();
     118                 :            : 
     119                 :          0 :         if (pm_power_off)
     120                 :          0 :                 pm_power_off();
     121                 :          0 : }
     122                 :            : 
     123                 :            : /*
     124                 :            :  * Restart requires that the secondary CPUs stop performing any activity
     125                 :            :  * while the primary CPU resets the system. Systems with a single CPU can
     126                 :            :  * use soft_restart() as their machine descriptor's .restart hook, since that
     127                 :            :  * will cause the only available CPU to reset. Systems with multiple CPUs must
     128                 :            :  * provide a HW restart implementation, to ensure that all CPUs reset at once.
     129                 :            :  * This is required so that any code running after reset on the primary CPU
     130                 :            :  * doesn't have to co-ordinate with other CPUs to ensure they aren't still
     131                 :            :  * executing pre-reset code, and using RAM that the primary CPU's code wishes
     132                 :            :  * to use. Implementing such co-ordination would be essentially impossible.
     133                 :            :  */
     134                 :          0 : void machine_restart(char *cmd)
     135                 :            : {
     136                 :          0 :         local_irq_disable();
     137                 :          0 :         smp_send_stop();
     138                 :            : 
     139                 :          0 :         if (arm_pm_restart)
     140                 :          0 :                 arm_pm_restart(reboot_mode, cmd);
     141                 :            :         else
     142                 :          0 :                 do_kernel_restart(cmd);
     143                 :            : 
     144                 :            :         /* Give a grace period for failure to restart of 1s */
     145                 :          0 :         mdelay(1000);
     146                 :            : 
     147                 :            :         /* Whoops - the platform was unable to reboot. Tell the user! */
     148                 :          0 :         printk("Reboot failed -- System halted\n");
     149                 :          0 :         while (1);
     150                 :            : }
    

Generated by: LCOV version 1.14