Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* sstate.c: System soft state support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/hypervisor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/spitfire.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/oplib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "kernel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static int hv_supports_soft_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static void do_set_sstate(unsigned long state, const char *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	unsigned long err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	if (!hv_supports_soft_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	err = sun4v_mach_set_soft_state(state, kimage_addr_to_ra(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		printk(KERN_WARNING "SSTATE: Failed to set soft-state to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		       "state[%lx] msg[%s], err=%lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		       state, msg, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static const char booting_msg[32] __attribute__((aligned(32))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	"Linux booting";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static const char running_msg[32] __attribute__((aligned(32))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	"Linux running";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static const char halting_msg[32] __attribute__((aligned(32))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	"Linux halting";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static const char poweroff_msg[32] __attribute__((aligned(32))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	"Linux powering off";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static const char rebooting_msg[32] __attribute__((aligned(32))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	"Linux rebooting";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static const char panicking_msg[32] __attribute__((aligned(32))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	"Linux panicking";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static int sstate_reboot_call(struct notifier_block *np, unsigned long type, void *_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	const char *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	case SYS_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		msg = rebooting_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	case SYS_HALT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		msg = halting_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	case SYS_POWER_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		msg = poweroff_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	do_set_sstate(HV_SOFT_STATE_TRANSITION, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static struct notifier_block sstate_reboot_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.notifier_call = sstate_reboot_call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static int sstate_panic_event(struct notifier_block *n, unsigned long event, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	do_set_sstate(HV_SOFT_STATE_TRANSITION, panicking_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static struct notifier_block sstate_panic_block = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	.notifier_call	=	sstate_panic_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	.priority	=	INT_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static int __init sstate_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	unsigned long major, minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (tlb_type != hypervisor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	major = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	minor = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (sun4v_hvapi_register(HV_GRP_SOFT_STATE, major, &minor))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	hv_supports_soft_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	prom_sun4v_guest_soft_state();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	do_set_sstate(HV_SOFT_STATE_TRANSITION, booting_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	atomic_notifier_chain_register(&panic_notifier_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 				       &sstate_panic_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	register_reboot_notifier(&sstate_reboot_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) core_initcall(sstate_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static int __init sstate_running(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	do_set_sstate(HV_SOFT_STATE_NORMAL, running_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) late_initcall(sstate_running);