コード例 #1
0
int __noinstrument kfi_read_proc(char *buf, char **start, off_t fpos,
				 int length, int *eof, void *data)
{
	int len = kfi_dump_log(buf);
	
	if (fpos >= len) {
		*start = buf;
		*eof = 1;
		return 0;
	}
	*start = buf + fpos;
	if ((len -= fpos) > length)
		return length;
	*eof = 1;
	return len;
}
コード例 #2
0
ファイル: sys.c プロジェクト: muromec/linux-ezxdev
/*
 * Reboot system call: for obvious reasons only root may call it,
 * and even root needs to set up some magic numbers in the registers
 * so that some mistake won't make this reboot the whole machine.
 * You can also set the meaning of the ctrl-alt-del-key here.
 *
 * reboot doesn't sync: do that yourself before calling this.
 */
asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void * arg)
{
	char buffer[256];

	/* We only trust the superuser with rebooting the system. */
	if (!capable(CAP_SYS_BOOT))
		return -EPERM;

	/* For safety, we require "magic" arguments. */
	if (magic1 != LINUX_REBOOT_MAGIC1 ||
	    (magic2 != LINUX_REBOOT_MAGIC2 && magic2 != LINUX_REBOOT_MAGIC2A &&
			magic2 != LINUX_REBOOT_MAGIC2B))
		return -EINVAL;

#ifdef CONFIG_ARCH_EZXBASE

/* must be sync with include/linux/moto_accy.h */
#define ACCS_REBOOT (1 << MOTO_ACCY_TYPE_CHARGER_MID | \
                     1 << MOTO_ACCY_TYPE_CHARGER_MID_MPX | \
                     1 << MOTO_ACCY_TYPE_CHARGER_FAST | \
                     1 << MOTO_ACCY_TYPE_CHARGER_FAST_MPX | \
                     1 << MOTO_ACCY_TYPE_CHARGER_FAST_3G | \
		     1 << MOTO_ACCY_TYPE_CARKIT_MID | \
		     1 << MOTO_ACCY_TYPE_CARKIT_FAST | \
		     1 << MOTO_ACCY_TYPE_CARKIT_SMART)

#define FACTORY_REBOOT (1 << MOTO_ACCY_TYPE_CABLE_FACTORY)

        MOTO_ACCY_MASK_T mask = (MOTO_ACCY_MASK_T)moto_accy_get_all_devices();
        if (LINUX_REBOOT_CMD_RESTART == cmd) {
		if (mask & FACTORY_REBOOT) {
	                *(unsigned long *)(phys_to_virt(FLAG_ADDR)) = FACTORY_REBOOT_FLAG;
		} else {
	                *(unsigned long *)(phys_to_virt(FLAG_ADDR)) = APP_REBOOT_FLAG;
		}
        }
                                                                                                                             
        if (LINUX_REBOOT_CMD_POWER_OFF == cmd) {
            if (mask & ACCS_REBOOT) {
                *(unsigned long *)(phys_to_virt(FLAG_ADDR)) = CHARGE_FLAG;
                cmd = LINUX_REBOOT_CMD_RESTART;
                printk(KERN_EMERG "Change to reboot mode.\n");
            }
        }
#endif

	lock_kernel();
	switch (cmd) {
	case LINUX_REBOOT_CMD_RESTART:
		notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL);
#ifdef CONFIG_KFI
		kfi_dump_log(NULL);
#endif
		printk(KERN_EMERG "Restarting system.\n");
		machine_restart(NULL);
		break;

	case LINUX_REBOOT_CMD_CAD_ON:
		C_A_D = 1;
		break;

	case LINUX_REBOOT_CMD_CAD_OFF:
		C_A_D = 0;
		break;

	case LINUX_REBOOT_CMD_HALT:
		notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL);
#ifdef CONFIG_KFI
		kfi_dump_log(NULL);
#endif
		printk(KERN_EMERG "System halted.\n");
		machine_halt();
		do_exit(0);
		break;

	case LINUX_REBOOT_CMD_POWER_OFF:
		notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL);
#ifdef CONFIG_KFI
		kfi_dump_log(NULL);
#endif
		printk(KERN_EMERG "Power down.\n");
		machine_power_off();
		do_exit(0);
		break;

	case LINUX_REBOOT_CMD_RESTART2:
		if (strncpy_from_user(&buffer[0], (char *)arg, sizeof(buffer) - 1) < 0) {
			unlock_kernel();
			return -EFAULT;
		}
		buffer[sizeof(buffer) - 1] = '\0';

		notifier_call_chain(&reboot_notifier_list, SYS_RESTART, buffer);
		printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer);
#ifdef CONFIG_KFI
		kfi_dump_log(NULL);
#endif
		machine_restart(buffer);
		break;

	default:
		unlock_kernel();
		return -EINVAL;
	}
	unlock_kernel();
	return 0;
}
コード例 #3
0
/*
 * Reboot system call: for obvious reasons only root may call it,
 * and even root needs to set up some magic numbers in the registers
 * so that some mistake won't make this reboot the whole machine.
 * You can also set the meaning of the ctrl-alt-del-key here.
 *
 * reboot doesn't sync: do that yourself before calling this.
 */
asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void * arg)
{
	char buffer[256];

	/* We only trust the superuser with rebooting the system. */
	if (!capable(CAP_SYS_BOOT))
		return -EPERM;

	/* For safety, we require "magic" arguments. */
	if (magic1 != LINUX_REBOOT_MAGIC1 ||
	    (magic2 != LINUX_REBOOT_MAGIC2 && magic2 != LINUX_REBOOT_MAGIC2A &&
			magic2 != LINUX_REBOOT_MAGIC2B))
		return -EINVAL;

	lock_kernel();
	switch (cmd) {
	case LINUX_REBOOT_CMD_RESTART:
		notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL);
#ifdef CONFIG_KFI
		kfi_dump_log(NULL);
#endif
		printk(KERN_EMERG "Restarting system.\n");
		machine_restart(NULL);
		break;

	case LINUX_REBOOT_CMD_CAD_ON:
		C_A_D = 1;
		break;

	case LINUX_REBOOT_CMD_CAD_OFF:
		C_A_D = 0;
		break;

	case LINUX_REBOOT_CMD_HALT:
		notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL);
#ifdef CONFIG_KFI
		kfi_dump_log(NULL);
#endif
		printk(KERN_EMERG "System halted.\n");
		machine_halt();
		do_exit(0);
		break;

	case LINUX_REBOOT_CMD_POWER_OFF:
		notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL);
#ifdef CONFIG_KFI
		kfi_dump_log(NULL);
#endif
		printk(KERN_EMERG "Power down.\n");
		machine_power_off();
		do_exit(0);
		break;

	case LINUX_REBOOT_CMD_RESTART2:
		if (strncpy_from_user(&buffer[0], (char *)arg, sizeof(buffer) - 1) < 0) {
			unlock_kernel();
			return -EFAULT;
		}
		buffer[sizeof(buffer) - 1] = '\0';

		notifier_call_chain(&reboot_notifier_list, SYS_RESTART, buffer);
		printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer);
#ifdef CONFIG_KFI
		kfi_dump_log(NULL);
#endif
		machine_restart(buffer);
		break;

	default:
		unlock_kernel();
		return -EINVAL;
	}
	unlock_kernel();
	return 0;
}