📄 ps3-sys-manager.c
字号:
/* * PS3 System Manager. * * Copyright (C) 2007 Sony Computer Entertainment Inc. * Copyright 2007 Sony Corp. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <linux/kernel.h>#include <linux/module.h>#include <linux/workqueue.h>#include <linux/reboot.h>#include <asm/firmware.h>#include <asm/ps3.h>#include "vuart.h"MODULE_AUTHOR("Sony Corporation");MODULE_LICENSE("GPL v2");MODULE_DESCRIPTION("PS3 System Manager");/** * ps3_sys_manager - PS3 system manager driver. * * The system manager provides an asynchronous system event notification * mechanism for reporting events like thermal alert and button presses to * guests. It also provides support to control system shutdown and startup. * * The actual system manager is implemented as an application running in the * system policy module in lpar_1. Guests communicate with the system manager * through port 2 of the vuart using a simple packet message protocol. * Messages are comprised of a fixed field header followed by a message * specific payload. *//** * struct ps3_sys_manager_header - System manager message header. * @version: Header version, currently 1. * @size: Header size in bytes, curently 16. * @payload_size: Message payload size in bytes. * @service_id: Message type, one of enum ps3_sys_manager_service_id. * @request_tag: Unique number to identify reply. */struct ps3_sys_manager_header { /* version 1 */ u8 version; u8 size; u16 reserved_1; u32 payload_size; u16 service_id; u16 reserved_2; u32 request_tag;};#define dump_sm_header(_h) _dump_sm_header(_h, __func__, __LINE__)static void __maybe_unused _dump_sm_header( const struct ps3_sys_manager_header *h, const char *func, int line){ pr_debug("%s:%d: version: %xh\n", func, line, h->version); pr_debug("%s:%d: size: %xh\n", func, line, h->size); pr_debug("%s:%d: payload_size: %xh\n", func, line, h->payload_size); pr_debug("%s:%d: service_id: %xh\n", func, line, h->service_id); pr_debug("%s:%d: request_tag: %xh\n", func, line, h->request_tag);}/** * @PS3_SM_RX_MSG_LEN_MIN - Shortest received message length. * @PS3_SM_RX_MSG_LEN_MAX - Longest received message length. * * Currently all messages received from the system manager are either * (16 bytes header + 8 bytes payload = 24 bytes) or (16 bytes header * + 16 bytes payload = 32 bytes). This knowlege is used to simplify * the logic. */enum { PS3_SM_RX_MSG_LEN_MIN = 24, PS3_SM_RX_MSG_LEN_MAX = 32,};/** * enum ps3_sys_manager_service_id - Message header service_id. * @PS3_SM_SERVICE_ID_REQUEST: guest --> sys_manager. * @PS3_SM_SERVICE_ID_REQUEST_ERROR: guest <-- sys_manager. * @PS3_SM_SERVICE_ID_COMMAND: guest <-- sys_manager. * @PS3_SM_SERVICE_ID_RESPONSE: guest --> sys_manager. * @PS3_SM_SERVICE_ID_SET_ATTR: guest --> sys_manager. * @PS3_SM_SERVICE_ID_EXTERN_EVENT: guest <-- sys_manager. * @PS3_SM_SERVICE_ID_SET_NEXT_OP: guest --> sys_manager. * * PS3_SM_SERVICE_ID_REQUEST_ERROR is returned for invalid data values in a * a PS3_SM_SERVICE_ID_REQUEST message. It also seems to be returned when * a REQUEST message is sent at the wrong time. */enum ps3_sys_manager_service_id { /* version 1 */ PS3_SM_SERVICE_ID_REQUEST = 1, PS3_SM_SERVICE_ID_RESPONSE = 2, PS3_SM_SERVICE_ID_COMMAND = 3, PS3_SM_SERVICE_ID_EXTERN_EVENT = 4, PS3_SM_SERVICE_ID_SET_NEXT_OP = 5, PS3_SM_SERVICE_ID_REQUEST_ERROR = 6, PS3_SM_SERVICE_ID_SET_ATTR = 8,};/** * enum ps3_sys_manager_attr - Notification attribute (bit position mask). * @PS3_SM_ATTR_POWER: Power button. * @PS3_SM_ATTR_RESET: Reset button, not available on retail console. * @PS3_SM_ATTR_THERMAL: Sytem thermal alert. * @PS3_SM_ATTR_CONTROLLER: Remote controller event. * @PS3_SM_ATTR_ALL: Logical OR of all. * * The guest tells the system manager which events it is interested in receiving * notice of by sending the system manager a logical OR of notification * attributes via the ps3_sys_manager_send_attr() routine. */enum ps3_sys_manager_attr { /* version 1 */ PS3_SM_ATTR_POWER = 1, PS3_SM_ATTR_RESET = 2, PS3_SM_ATTR_THERMAL = 4, PS3_SM_ATTR_CONTROLLER = 8, /* bogus? */ PS3_SM_ATTR_ALL = 0x0f,};/** * enum ps3_sys_manager_event - External event type, reported by system manager. * @PS3_SM_EVENT_POWER_PRESSED: payload.value not used. * @PS3_SM_EVENT_POWER_RELEASED: payload.value = time pressed in millisec. * @PS3_SM_EVENT_RESET_PRESSED: payload.value not used. * @PS3_SM_EVENT_RESET_RELEASED: payload.value = time pressed in millisec. * @PS3_SM_EVENT_THERMAL_ALERT: payload.value = thermal zone id. * @PS3_SM_EVENT_THERMAL_CLEARED: payload.value = thermal zone id. */enum ps3_sys_manager_event { /* version 1 */ PS3_SM_EVENT_POWER_PRESSED = 3, PS3_SM_EVENT_POWER_RELEASED = 4, PS3_SM_EVENT_RESET_PRESSED = 5, PS3_SM_EVENT_RESET_RELEASED = 6, PS3_SM_EVENT_THERMAL_ALERT = 7, PS3_SM_EVENT_THERMAL_CLEARED = 8, /* no info on controller events */};/** * enum ps3_sys_manager_next_op - Operation to perform after lpar is destroyed. */enum ps3_sys_manager_next_op { /* version 3 */ PS3_SM_NEXT_OP_SYS_SHUTDOWN = 1, PS3_SM_NEXT_OP_SYS_REBOOT = 2, PS3_SM_NEXT_OP_LPAR_REBOOT = 0x82,};/** * enum ps3_sys_manager_wake_source - Next-op wakeup source (bit position mask). * @PS3_SM_WAKE_DEFAULT: Disk insert, power button, eject button, IR * controller, and bluetooth controller. * @PS3_SM_WAKE_RTC: * @PS3_SM_WAKE_RTC_ERROR: * @PS3_SM_WAKE_P_O_R: Power on reset. * * Additional wakeup sources when specifying PS3_SM_NEXT_OP_SYS_SHUTDOWN. * System will always wake from the PS3_SM_WAKE_DEFAULT sources. */enum ps3_sys_manager_wake_source { /* version 3 */ PS3_SM_WAKE_DEFAULT = 0, PS3_SM_WAKE_RTC = 0x00000040, PS3_SM_WAKE_RTC_ERROR = 0x00000080, PS3_SM_WAKE_P_O_R = 0x10000000,};/** * enum ps3_sys_manager_cmd - Command from system manager to guest. * * The guest completes the actions needed, then acks or naks the command via * ps3_sys_manager_send_response(). In the case of @PS3_SM_CMD_SHUTDOWN, * the guest must be fully prepared for a system poweroff prior to acking the * command. */enum ps3_sys_manager_cmd { /* version 1 */ PS3_SM_CMD_SHUTDOWN = 1, /* shutdown guest OS */};/** * ps3_sm_force_power_off - Poweroff helper. * * A global variable used to force a poweroff when the power button has * been pressed irrespective of how init handles the ctrl_alt_del signal. * */static unsigned int ps3_sm_force_power_off;/** * ps3_sys_manager_write - Helper to write a two part message to the vuart. * */static int ps3_sys_manager_write(struct ps3_system_bus_device *dev, const struct ps3_sys_manager_header *header, const void *payload){ int result; BUG_ON(header->version != 1); BUG_ON(header->size != 16); BUG_ON(header->payload_size != 8 && header->payload_size != 16); BUG_ON(header->service_id > 8); result = ps3_vuart_write(dev, header, sizeof(struct ps3_sys_manager_header)); if (!result) result = ps3_vuart_write(dev, payload, header->payload_size); return result;}/** * ps3_sys_manager_send_attr - Send a 'set attribute' to the system manager. * */static int ps3_sys_manager_send_attr(struct ps3_system_bus_device *dev, enum ps3_sys_manager_attr attr){ struct ps3_sys_manager_header header; struct { u8 version; u8 reserved_1[3]; u32 attribute; } payload; BUILD_BUG_ON(sizeof(payload) != 8); dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, attr); memset(&header, 0, sizeof(header)); header.version = 1; header.size = 16; header.payload_size = 16; header.service_id = PS3_SM_SERVICE_ID_SET_ATTR; memset(&payload, 0, sizeof(payload)); payload.version = 1; payload.attribute = attr; return ps3_sys_manager_write(dev, &header, &payload);}/** * ps3_sys_manager_send_next_op - Send a 'set next op' to the system manager. * * Tell the system manager what to do after this lpar is destroyed. */static int ps3_sys_manager_send_next_op(struct ps3_system_bus_device *dev, enum ps3_sys_manager_next_op op, enum ps3_sys_manager_wake_source wake_source){ struct ps3_sys_manager_header header; struct { u8 version; u8 type; u8 gos_id; u8 reserved_1; u32 wake_source; u8 reserved_2[8]; } payload; BUILD_BUG_ON(sizeof(payload) != 16); dev_dbg(&dev->core, "%s:%d: (%xh)\n", __func__, __LINE__, op); memset(&header, 0, sizeof(header)); header.version = 1; header.size = 16; header.payload_size = 16; header.service_id = PS3_SM_SERVICE_ID_SET_NEXT_OP; memset(&payload, 0, sizeof(payload)); payload.version = 3; payload.type = op; payload.gos_id = 3; /* other os */ payload.wake_source = wake_source; return ps3_sys_manager_write(dev, &header, &payload);}/** * ps3_sys_manager_send_request_shutdown - Send 'request' to the system manager. * * The guest sends this message to request an operation or action of the system * manager. The reply is a command message from the system manager. In the * command handler the guest performs the requested operation. The result of * the command is then communicated back to the system manager with a response * message. * * Currently, the only supported request is the 'shutdown self' request. */static int ps3_sys_manager_send_request_shutdown( struct ps3_system_bus_device *dev){ struct ps3_sys_manager_header header; struct { u8 version; u8 type; u8 gos_id; u8 reserved_1[13]; } payload; BUILD_BUG_ON(sizeof(payload) != 16); dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__); memset(&header, 0, sizeof(header)); header.version = 1; header.size = 16; header.payload_size = 16; header.service_id = PS3_SM_SERVICE_ID_REQUEST; memset(&payload, 0, sizeof(payload)); payload.version = 1; payload.type = 1; /* shutdown */ payload.gos_id = 0; /* self */ return ps3_sys_manager_write(dev, &header, &payload);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -