arch/powerpc/platforms/powernv/opal-power.c

Source file repositories/reference/linux-study-clean/arch/powerpc/platforms/powernv/opal-power.c

File Facts

System
Linux kernel
Corpus path
arch/powerpc/platforms/powernv/opal-power.c
Extension
.c
Size
4058 bytes
Lines
175
Domain
Architecture Layer
Bucket
arch/powerpc
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

if (detect_epow()) {
			pr_info("EPOW msg received. Powering off system\n");
			orderly_poweroff(true);
		}
		break;
	case OPAL_MSG_DPO:
		pr_info("DPO msg received. Powering off system\n");
		orderly_poweroff(true);
		break;
	case OPAL_MSG_SHUTDOWN:
		type = be64_to_cpu(((struct opal_msg *)msg)->params[0]);
		switch (type) {
		case SOFT_REBOOT:
			pr_info("Reboot requested\n");
			orderly_reboot();
			break;
		case SOFT_OFF:
			pr_info("Poweroff requested\n");
			orderly_poweroff(true);
			break;
		default:
			pr_err("Unknown power-control type %llu\n", type);
		}
		break;
	default:
		pr_err("Unknown OPAL message type %lu\n", msg_type);
	}

	return 0;
}

/* OPAL EPOW event notifier block */
static struct notifier_block opal_epow_nb = {
	.notifier_call	= opal_power_control_event,
	.next		= NULL,
	.priority	= 0,
};

/* OPAL DPO event notifier block */
static struct notifier_block opal_dpo_nb = {
	.notifier_call	= opal_power_control_event,
	.next		= NULL,
	.priority	= 0,
};

/* OPAL power-control event notifier block */
static struct notifier_block opal_power_control_nb = {
	.notifier_call	= opal_power_control_event,
	.next		= NULL,
	.priority	= 0,
};

int __init opal_power_control_init(void)
{
	int ret, supported = 0;
	struct device_node *np;

	/* Register OPAL power-control events notifier */
	ret = opal_message_notifier_register(OPAL_MSG_SHUTDOWN,
						&opal_power_control_nb);
	if (ret)
		pr_err("Failed to register SHUTDOWN notifier, ret = %d\n", ret);

	/* Determine OPAL EPOW, DPO support */
	np = of_find_node_by_path("/ibm,opal/epow");
	if (np) {
		supported = of_device_is_compatible(np, "ibm,opal-v3-epow");
		of_node_put(np);
	}

	if (!supported)
		return 0;
	pr_info("OPAL EPOW, DPO support detected.\n");

	/* Register EPOW event notifier */
	ret = opal_message_notifier_register(OPAL_MSG_EPOW, &opal_epow_nb);
	if (ret)
		pr_err("Failed to register EPOW notifier, ret = %d\n", ret);

	/* Register DPO event notifier */
	ret = opal_message_notifier_register(OPAL_MSG_DPO, &opal_dpo_nb);
	if (ret)
		pr_err("Failed to register DPO notifier, ret = %d\n", ret);

	/* Check for any pending EPOW or DPO events. */
	if (poweroff_pending())
		orderly_poweroff(true);

	return 0;
}

Annotation

Implementation Notes