aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds2007-02-19 13:05:14 -0800
committerLinus Torvalds2007-02-19 13:05:14 -0800
commit5c56f466835d20fc4f7119063a8c029f7170a317 (patch)
treecfa8afcea4defb59de32c501245bae16d0fdc5d0 /drivers
parentdd397a6d1ae125686d97a20f983778c331093206 (diff)
parentc2944612cf30aece4526f23e96e1d234a1870ed6 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
* git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc: (34 commits) [POWERPC] 86xx: Cleaned up platform dts files [POWERPC] 85xx: Renamed MPC8568 MDS board code to match other boards [POWERPC] 85xx: Cleaning up machine probing [POWERPC] QE: clean up ucc_slow.c and ucc_fast.c [POWERPC] 85xx: Cleaned up platform dts files [POWERPC] 83xx: Renamed MPC8323 MDS dts and defconfig to match other boards [POWERPC] 83xx: Updated and renamed MPC8360PB to MPC836x MDS [POWERPC] 83xx: Use of_platform_bus_probe to setup QE devices [POWERPC] 83xx: use default value of loops_per_jiffy [POWERPC] 83xx: Remove obsolete setting of ROOT_DEV. [POWERPC] 83xx: Cleaning up machine probing and board initcalls [POWERPC] Dispose irq mapping when done in mpc52xx_serial.c [POWERPC] 86xx: Add missing of_node_put() in mpc86xx_hpcn_init_irq(). [POWERPC] 8[56]xx: Remove obsolete setting of ROOT_DEV for 85xx and 86xx platforms. [POWERPC] pseries: Enabling auto poweron after power is restored. [POWERPC] use winbond libata instead of ide driver for pseries CD drives [POWERPC] powerpc: remove references to the obsolete linux,platform property [POWERPC] add of_get_mac_address and update fsl_soc.c to use it [POWERPC] 83xx: Cleaned up 83xx platform dts files [POWERPC] Fix bug with early ioremap and 64k pages ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ps3/Makefile1
-rw-r--r--drivers/ps3/sys-manager.c604
-rw-r--r--drivers/ps3/vuart.c398
-rw-r--r--drivers/ps3/vuart.h59
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm2.c2
-rw-r--r--drivers/serial/mpc52xx_uart.c4
6 files changed, 931 insertions, 137 deletions
diff --git a/drivers/ps3/Makefile b/drivers/ps3/Makefile
index 96958c03cf61..e251d1c1171c 100644
--- a/drivers/ps3/Makefile
+++ b/drivers/ps3/Makefile
@@ -1,2 +1,3 @@
obj-$(CONFIG_PS3_VUART) += vuart.o
obj-$(CONFIG_PS3_PS3AV) += ps3av.o ps3av_cmd.o
+obj-$(CONFIG_PS3_SYS_MANAGER) += sys-manager.o
diff --git a/drivers/ps3/sys-manager.c b/drivers/ps3/sys-manager.c
new file mode 100644
index 000000000000..0fc30be8b81e
--- /dev/null
+++ b/drivers/ps3/sys-manager.c
@@ -0,0 +1,604 @@
+/*
+ * 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/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 asyncronous 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.
+ */
+
+struct ps3_sys_manager_header {
+ /* version 1 */
+ u8 version;
+ u8 size;
+ u16 reserved_1;
+ u32 payload_size;
+ u16 service_id;
+ u16 reserved_2[3];
+};
+
+/**
+ * @PS3_SM_RX_MSG_LEN - System manager received message length.
+ *
+ * Currently all messages received from the system manager are the same length
+ * (16 bytes header + 16 bytes payload = 32 bytes). This knowlege is used to
+ * simplify the logic.
+ */
+
+enum {
+ PS3_SM_RX_MSG_LEN = 32,
+};
+
+/**
+ * enum ps3_sys_manager_service_id - Message header service_id.
+ * @PS3_SM_SERVICE_ID_REQUEST: 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.
+ */
+
+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_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_sys_manager_write - Helper to write a two part message to the vuart.
+ *
+ */
+
+static int ps3_sys_manager_write(struct ps3_vuart_port_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_vuart_port_device *dev,
+ enum ps3_sys_manager_attr attr)
+{
+ static const struct ps3_sys_manager_header header = {
+ .version = 1,
+ .size = 16,
+ .payload_size = 16,
+ .service_id = PS3_SM_SERVICE_ID_SET_ATTR,
+ };
+ 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(&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_vuart_port_device *dev,
+ enum ps3_sys_manager_next_op op,
+ enum ps3_sys_manager_wake_source wake_source)
+{
+ static const struct ps3_sys_manager_header header = {
+ .version = 1,
+ .size = 16,
+ .payload_size = 16,
+ .service_id = PS3_SM_SERVICE_ID_SET_NEXT_OP,
+ };
+ 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(&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 it the 'shutdown self' request.
+ */
+
+static int ps3_sys_manager_send_request_shutdown(struct ps3_vuart_port_device *dev)
+{
+ static const struct ps3_sys_manager_header header = {
+ .version = 1,
+ .size = 16,
+ .payload_size = 16,
+ .service_id = PS3_SM_SERVICE_ID_REQUEST,
+ };
+ struct {
+ u8 version;
+ u8 type;
+ u8 gos_id;
+ u8 reserved_1[13];
+ } static const payload = {
+ .version = 1,
+ .type = 1, /* shutdown */
+ .gos_id = 0, /* self */
+ };
+
+ BUILD_BUG_ON(sizeof(payload) != 16);
+
+ dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
+
+ return ps3_sys_manager_write(dev, &header, &payload);
+}
+
+/**
+ * ps3_sys_manager_send_response - Send a 'response' to the system manager.
+ * @status: zero = success, others fail.
+ *
+ * The guest sends this message to the system manager to acnowledge success or
+ * failure of a command sent by the system manager.
+ */
+
+static int ps3_sys_manager_send_response(struct ps3_vuart_port_device *dev,
+ u64 status)
+{
+ static const struct ps3_sys_manager_header header = {
+ .version = 1,
+ .size = 16,
+ .payload_size = 16,
+ .service_id = PS3_SM_SERVICE_ID_RESPONSE,
+ };
+ struct {
+ u8 version;
+ u8 reserved_1[3];
+ u8 status;
+ u8 reserved_2[11];
+ } payload;
+
+ BUILD_BUG_ON(sizeof(payload) != 16);
+
+ dev_dbg(&dev->core, "%s:%d: (%s)\n", __func__, __LINE__,
+ (status ? "nak" : "ack"));
+
+ memset(&payload, 0, sizeof(payload));
+ payload.version = 1;
+ payload.status = status;
+
+ return ps3_sys_manager_write(dev, &header, &payload);
+}
+
+/**
+ * ps3_sys_manager_handle_event - Second stage event msg handler.
+ *
+ */
+
+static int ps3_sys_manager_handle_event(struct ps3_vuart_port_device *dev)
+{
+ int result;
+ struct {
+ u8 version;
+ u8 type;
+ u8 reserved_1[2];
+ u32 value;
+ u8 reserved_2[8];
+ } event;
+
+ BUILD_BUG_ON(sizeof(event) != 16);
+
+ result = ps3_vuart_read(dev, &event, sizeof(event));
+ BUG_ON(result);
+
+ if (event.version != 1) {
+ dev_dbg(&dev->core, "%s:%d: unsupported event version (%u)\n",
+ __func__, __LINE__, event.version);
+ return -EIO;
+ }
+
+ switch (event.type) {
+ case PS3_SM_EVENT_POWER_PRESSED:
+ dev_dbg(&dev->core, "%s:%d: POWER_PRESSED\n",
+ __func__, __LINE__);
+ break;
+ case PS3_SM_EVENT_POWER_RELEASED:
+ dev_dbg(&dev->core, "%s:%d: POWER_RELEASED (%u ms)\n",
+ __func__, __LINE__, event.value);
+ kill_cad_pid(SIGINT, 1);
+ break;
+ case PS3_SM_EVENT_THERMAL_ALERT:
+ dev_dbg(&dev->core, "%s:%d: THERMAL_ALERT (zone %u)\n",
+ __func__, __LINE__, event.value);
+ printk(KERN_INFO "PS3 Thermal Alert Zone %u\n", event.value);
+ break;
+ case PS3_SM_EVENT_THERMAL_CLEARED:
+ dev_dbg(&dev->core, "%s:%d: THERMAL_CLEARED (zone %u)\n",
+ __func__, __LINE__, event.value);
+ break;
+ default:
+ dev_dbg(&dev->core, "%s:%d: unknown event (%u)\n",
+ __func__, __LINE__, event.type);
+ return -EIO;
+ }
+
+ return 0;
+}
+/**
+ * ps3_sys_manager_handle_cmd - Second stage command msg handler.
+ *
+ * The system manager sends this in reply to a 'request' message from the guest.
+ */
+
+static int ps3_sys_manager_handle_cmd(struct ps3_vuart_port_device *dev)
+{
+ int result;
+ struct {
+ u8 version;
+ u8 type;
+ u8 reserved_1[14];
+ } cmd;
+
+ BUILD_BUG_ON(sizeof(cmd) != 16);
+
+ dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
+
+ result = ps3_vuart_read(dev, &cmd, sizeof(cmd));
+
+ if(result)
+ return result;
+
+ if (cmd.version != 1) {
+ dev_dbg(&dev->core, "%s:%d: unsupported cmd version (%u)\n",
+ __func__, __LINE__, cmd.version);
+ return -EIO;
+ }
+
+ if (cmd.type != PS3_SM_CMD_SHUTDOWN) {
+ dev_dbg(&dev->core, "%s:%d: unknown cmd (%u)\n",
+ __func__, __LINE__, cmd.type);
+ return -EIO;
+ }
+
+ ps3_sys_manager_send_response(dev, 0);
+ return 0;
+}
+
+/**
+ * ps3_sys_manager_handle_msg - First stage msg handler.
+ *
+ */
+
+static int ps3_sys_manager_handle_msg(struct ps3_vuart_port_device *dev)
+{
+ int result;
+ struct ps3_sys_manager_header header;
+
+ result = ps3_vuart_read(dev, &header,
+ sizeof(struct ps3_sys_manager_header));
+
+ if(result)
+ return result;
+
+ if (header.version != 1) {
+ dev_dbg(&dev->core, "%s:%d: unsupported header version (%u)\n",
+ __func__, __LINE__, header.version);
+ goto fail_header;
+ }
+
+ BUILD_BUG_ON(sizeof(header) != 16);
+ BUG_ON(header.size != 16);
+ BUG_ON(header.payload_size != 16);
+
+ switch (header.service_id) {
+ case PS3_SM_SERVICE_ID_EXTERN_EVENT:
+ dev_dbg(&dev->core, "%s:%d: EVENT\n", __func__, __LINE__);
+ return ps3_sys_manager_handle_event(dev);
+ case PS3_SM_SERVICE_ID_COMMAND:
+ dev_dbg(&dev->core, "%s:%d: COMMAND\n", __func__, __LINE__);
+ return ps3_sys_manager_handle_cmd(dev);
+ default:
+ dev_dbg(&dev->core, "%s:%d: unknown service_id (%u)\n",
+ __func__, __LINE__, header.service_id);
+ break;
+ }
+ goto fail_id;
+
+fail_header:
+ ps3_vuart_clear_rx_bytes(dev, 0);
+ return -EIO;
+fail_id:
+ ps3_vuart_clear_rx_bytes(dev, header.payload_size);
+ return -EIO;
+}
+
+/**
+ * ps3_sys_manager_work - Asyncronous read handler.
+ *
+ * Signaled when a complete message arrives at the vuart port.
+ */
+
+static void ps3_sys_manager_work(struct work_struct *work)
+{
+ struct ps3_vuart_port_device *dev = ps3_vuart_work_to_port_device(work);
+
+ ps3_sys_manager_handle_msg(dev);
+ ps3_vuart_read_async(dev, ps3_sys_manager_work, PS3_SM_RX_MSG_LEN);
+}
+
+struct {
+ struct ps3_vuart_port_device *dev;
+} static drv_priv;
+
+/**
+ * ps3_sys_manager_restart - The final platform machine_restart routine.
+ *
+ * This routine never returns. The routine disables asyncronous vuart reads
+ * then spins calling ps3_sys_manager_handle_msg() to receive and acknowledge
+ * the shutdown command sent from the system manager. Soon after the
+ * acknowledgement is sent the lpar is destroyed by the HV. This routine
+ * should only be called from ps3_restart().
+ */
+
+void ps3_sys_manager_restart(void)
+{
+ struct ps3_vuart_port_device *dev = drv_priv.dev;
+
+ BUG_ON(!drv_priv.dev);
+
+ dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
+
+ ps3_vuart_cancel_async(dev);
+
+ ps3_sys_manager_send_attr(dev, 0);
+ ps3_sys_manager_send_next_op(dev, PS3_SM_NEXT_OP_LPAR_REBOOT,
+ PS3_SM_WAKE_DEFAULT);
+ ps3_sys_manager_send_request_shutdown(dev);
+
+ printk(KERN_EMERG "System Halted, OK to turn off power\n");
+
+ while(1)
+ ps3_sys_manager_handle_msg(dev);
+}
+
+/**
+ * ps3_sys_manager_power_off - The final platform machine_power_off routine.
+ *
+ * This routine never returns. The routine disables asyncronous vuart reads
+ * then spins calling ps3_sys_manager_handle_msg() to receive and acknowledge
+ * the shutdown command sent from the system manager. Soon after the
+ * acknowledgement is sent the lpar is destroyed by the HV. This routine
+ * should only be called from ps3_power_off().
+ */
+
+void ps3_sys_manager_power_off(void)
+{
+ struct ps3_vuart_port_device *dev = drv_priv.dev;
+
+ BUG_ON(!drv_priv.dev);
+
+ dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
+
+ ps3_vuart_cancel_async(dev);
+
+ ps3_sys_manager_send_next_op(dev, PS3_SM_NEXT_OP_SYS_SHUTDOWN,
+ PS3_SM_WAKE_DEFAULT);
+ ps3_sys_manager_send_request_shutdown(dev);
+
+ printk(KERN_EMERG "System Halted, OK to turn off power\n");
+
+ while(1)
+ ps3_sys_manager_handle_msg(dev);
+}
+
+static int ps3_sys_manager_probe(struct ps3_vuart_port_device *dev)
+{
+ int result;
+
+ dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
+
+ BUG_ON(drv_priv.dev);
+ drv_priv.dev = dev;
+
+ result = ps3_sys_manager_send_attr(dev, PS3_SM_ATTR_ALL);
+ BUG_ON(result);
+
+ result = ps3_vuart_read_async(dev, ps3_sys_manager_work,
+ PS3_SM_RX_MSG_LEN);
+ BUG_ON(result);
+
+ return result;
+}
+
+static struct ps3_vuart_port_driver ps3_sys_manager = {
+ .match_id = PS3_MATCH_ID_SYSTEM_MANAGER,
+ .core = {
+ .name = "ps3_sys_manager",
+ },
+ .probe = ps3_sys_manager_probe,
+};
+
+static int __init ps3_sys_manager_init(void)
+{
+ return ps3_vuart_port_driver_register(&ps3_sys_manager);
+}
+
+module_init(ps3_sys_manager_init);
diff --git a/drivers/ps3/vuart.c b/drivers/ps3/vuart.c
index ef8fd4c30875..746298107d6f 100644
--- a/drivers/ps3/vuart.c
+++ b/drivers/ps3/vuart.c
@@ -21,8 +21,10 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/interrupt.h>
+#include <linux/workqueue.h>
#include <asm/ps3.h>
+#include <asm/firmware.h>
#include <asm/lv1call.h>
#include <asm/bitops.h>
@@ -30,7 +32,7 @@
MODULE_AUTHOR("Sony Corporation");
MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("ps3 vuart");
+MODULE_DESCRIPTION("PS3 vuart");
/**
* vuart - An inter-partition data link service.
@@ -157,7 +159,7 @@ int ps3_vuart_get_triggers(struct ps3_vuart_port_device *dev,
unsigned long size;
unsigned long val;
- result = lv1_get_virtual_uart_param(dev->port_number,
+ result = lv1_get_virtual_uart_param(dev->priv->port_number,
PARAM_TX_TRIGGER, &trig->tx);
if (result) {
@@ -166,7 +168,7 @@ int ps3_vuart_get_triggers(struct ps3_vuart_port_device *dev,
return result;
}
- result = lv1_get_virtual_uart_param(dev->port_number,
+ result = lv1_get_virtual_uart_param(dev->priv->port_number,
PARAM_RX_BUF_SIZE, &size);
if (result) {
@@ -175,7 +177,7 @@ int ps3_vuart_get_triggers(struct ps3_vuart_port_device *dev,
return result;
}
- result = lv1_get_virtual_uart_param(dev->port_number,
+ result = lv1_get_virtual_uart_param(dev->priv->port_number,
PARAM_RX_TRIGGER, &val);
if (result) {
@@ -198,7 +200,7 @@ int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
int result;
unsigned long size;
- result = lv1_set_virtual_uart_param(dev->port_number,
+ result = lv1_set_virtual_uart_param(dev->priv->port_number,
PARAM_TX_TRIGGER, tx);
if (result) {
@@ -207,7 +209,7 @@ int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
return result;
}
- result = lv1_get_virtual_uart_param(dev->port_number,
+ result = lv1_get_virtual_uart_param(dev->priv->port_number,
PARAM_RX_BUF_SIZE, &size);
if (result) {
@@ -216,7 +218,7 @@ int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
return result;
}
- result = lv1_set_virtual_uart_param(dev->port_number,
+ result = lv1_set_virtual_uart_param(dev->priv->port_number,
PARAM_RX_TRIGGER, size - rx);
if (result) {
@@ -232,9 +234,9 @@ int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
}
static int ps3_vuart_get_rx_bytes_waiting(struct ps3_vuart_port_device *dev,
- unsigned long *bytes_waiting)
+ u64 *bytes_waiting)
{
- int result = lv1_get_virtual_uart_param(dev->port_number,
+ int result = lv1_get_virtual_uart_param(dev->priv->port_number,
PARAM_RX_BYTES, bytes_waiting);
if (result)
@@ -253,10 +255,10 @@ static int ps3_vuart_set_interrupt_mask(struct ps3_vuart_port_device *dev,
dev_dbg(&dev->core, "%s:%d: %lxh\n", __func__, __LINE__, mask);
- dev->interrupt_mask = mask;
+ dev->priv->interrupt_mask = mask;
- result = lv1_set_virtual_uart_param(dev->port_number,
- PARAM_INTERRUPT_MASK, dev->interrupt_mask);
+ result = lv1_set_virtual_uart_param(dev->priv->port_number,
+ PARAM_INTERRUPT_MASK, dev->priv->interrupt_mask);
if (result)
dev_dbg(&dev->core, "%s:%d: interrupt_mask failed: %s\n",
@@ -265,62 +267,64 @@ static int ps3_vuart_set_interrupt_mask(struct ps3_vuart_port_device *dev,
return result;
}
-static int ps3_vuart_get_interrupt_mask(struct ps3_vuart_port_device *dev,
+static int ps3_vuart_get_interrupt_status(struct ps3_vuart_port_device *dev,
unsigned long *status)
{
- int result = lv1_get_virtual_uart_param(dev->port_number,
- PARAM_INTERRUPT_STATUS, status);
+ u64 tmp;
+ int result = lv1_get_virtual_uart_param(dev->priv->port_number,
+ PARAM_INTERRUPT_STATUS, &tmp);
if (result)
dev_dbg(&dev->core, "%s:%d: interrupt_status failed: %s\n",
__func__, __LINE__, ps3_result(result));
+ *status = tmp & dev->priv->interrupt_mask;
+
dev_dbg(&dev->core, "%s:%d: m %lxh, s %lxh, m&s %lxh\n",
- __func__, __LINE__, dev->interrupt_mask, *status,
- dev->interrupt_mask & *status);
+ __func__, __LINE__, dev->priv->interrupt_mask, tmp, *status);
return result;
}
int ps3_vuart_enable_interrupt_tx(struct ps3_vuart_port_device *dev)
{
- return (dev->interrupt_mask & INTERRUPT_MASK_TX) ? 0
- : ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask
+ return (dev->priv->interrupt_mask & INTERRUPT_MASK_TX) ? 0
+ : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
| INTERRUPT_MASK_TX);
}
int ps3_vuart_enable_interrupt_rx(struct ps3_vuart_port_device *dev)
{
- return (dev->interrupt_mask & INTERRUPT_MASK_RX) ? 0
- : ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask
+ return (dev->priv->interrupt_mask & INTERRUPT_MASK_RX) ? 0
+ : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
| INTERRUPT_MASK_RX);
}
int ps3_vuart_enable_interrupt_disconnect(struct ps3_vuart_port_device *dev)
{
- return (dev->interrupt_mask & INTERRUPT_MASK_DISCONNECT) ? 0
- : ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask
+ return (dev->priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT) ? 0
+ : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
| INTERRUPT_MASK_DISCONNECT);
}
int ps3_vuart_disable_interrupt_tx(struct ps3_vuart_port_device *dev)
{
- return (dev->interrupt_mask & INTERRUPT_MASK_TX)
- ? ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask
+ return (dev->priv->interrupt_mask & INTERRUPT_MASK_TX)
+ ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
& ~INTERRUPT_MASK_TX) : 0;
}
int ps3_vuart_disable_interrupt_rx(struct ps3_vuart_port_device *dev)
{
- return (dev->interrupt_mask & INTERRUPT_MASK_RX)
- ? ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask
+ return (dev->priv->interrupt_mask & INTERRUPT_MASK_RX)
+ ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
& ~INTERRUPT_MASK_RX) : 0;
}
int ps3_vuart_disable_interrupt_disconnect(struct ps3_vuart_port_device *dev)
{
- return (dev->interrupt_mask & INTERRUPT_MASK_DISCONNECT)
- ? ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask
+ return (dev->priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT)
+ ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
& ~INTERRUPT_MASK_DISCONNECT) : 0;
}
@@ -335,9 +339,7 @@ static int ps3_vuart_raw_write(struct ps3_vuart_port_device *dev,
{
int result;
- dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes);
-
- result = lv1_write_virtual_uart(dev->port_number,
+ result = lv1_write_virtual_uart(dev->priv->port_number,
ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_written);
if (result) {
@@ -346,10 +348,10 @@ static int ps3_vuart_raw_write(struct ps3_vuart_port_device *dev,
return result;
}
- dev->stats.bytes_written += *bytes_written;
+ dev->priv->stats.bytes_written += *bytes_written;
- dev_dbg(&dev->core, "%s:%d: wrote %lxh/%xh=>%lxh\n", __func__,
- __LINE__, *bytes_written, bytes, dev->stats.bytes_written);
+ dev_dbg(&dev->core, "%s:%d: wrote %lxh/%xh=>%lxh\n", __func__, __LINE__,
+ *bytes_written, bytes, dev->priv->stats.bytes_written);
return result;
}
@@ -367,7 +369,7 @@ static int ps3_vuart_raw_read(struct ps3_vuart_port_device *dev, void* buf,
dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes);
- result = lv1_read_virtual_uart(dev->port_number,
+ result = lv1_read_virtual_uart(dev->priv->port_number,
ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_read);
if (result) {
@@ -376,15 +378,58 @@ static int ps3_vuart_raw_read(struct ps3_vuart_port_device *dev, void* buf,
return result;
}
- dev->stats.bytes_read += *bytes_read;
+ dev->priv->stats.bytes_read += *bytes_read;
dev_dbg(&dev->core, "%s:%d: read %lxh/%xh=>%lxh\n", __func__, __LINE__,
- *bytes_read, bytes, dev->stats.bytes_read);
+ *bytes_read, bytes, dev->priv->stats.bytes_read);
return result;
}
/**
+ * ps3_vuart_clear_rx_bytes - Discard bytes received.
+ * @bytes: Max byte count to discard, zero = all pending.
+ *
+ * Used to clear pending rx interrupt source. Will not block.
+ */
+
+void ps3_vuart_clear_rx_bytes(struct ps3_vuart_port_device *dev,
+ unsigned int bytes)
+{
+ int result;
+ u64 bytes_waiting;
+ void* tmp;
+
+ result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes_waiting);
+
+ BUG_ON(result);
+
+ bytes = bytes ? min(bytes, (unsigned int)bytes_waiting) : bytes_waiting;
+
+ dev_dbg(&dev->core, "%s:%d: %u\n", __func__, __LINE__, bytes);
+
+ if (!bytes)
+ return;
+
+ /* Add some extra space for recently arrived data. */
+
+ bytes += 128;
+
+ tmp = kmalloc(bytes, GFP_KERNEL);
+
+ if (!tmp)
+ return;
+
+ ps3_vuart_raw_read(dev, tmp, bytes, &bytes_waiting);
+
+ kfree(tmp);
+
+ /* Don't include these bytes in the stats. */
+
+ dev->priv->stats.bytes_read -= bytes_waiting;
+}
+
+/**
* struct list_buffer - An element for a port device fifo buffer list.
*/
@@ -416,14 +461,14 @@ int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
bytes, bytes);
- spin_lock_irqsave(&dev->tx_list.lock, flags);
+ spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
- if (list_empty(&dev->tx_list.head)) {
+ if (list_empty(&dev->priv->tx_list.head)) {
unsigned long bytes_written;
result = ps3_vuart_raw_write(dev, buf, bytes, &bytes_written);
- spin_unlock_irqrestore(&dev->tx_list.lock, flags);
+ spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
if (result) {
dev_dbg(&dev->core,
@@ -441,7 +486,7 @@ int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
bytes -= bytes_written;
buf += bytes_written;
} else
- spin_unlock_irqrestore(&dev->tx_list.lock, flags);
+ spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_KERNEL);
@@ -454,10 +499,10 @@ int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
lb->tail = lb->data + bytes;
lb->dbg_number = ++dbg_number;
- spin_lock_irqsave(&dev->tx_list.lock, flags);
- list_add_tail(&lb->link, &dev->tx_list.head);
+ spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
+ list_add_tail(&lb->link, &dev->priv->tx_list.head);
ps3_vuart_enable_interrupt_tx(dev);
- spin_unlock_irqrestore(&dev->tx_list.lock, flags);
+ spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %xh bytes\n",
__func__, __LINE__, lb->dbg_number, bytes);
@@ -484,47 +529,83 @@ int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
bytes, bytes);
- spin_lock_irqsave(&dev->rx_list.lock, flags);
+ spin_lock_irqsave(&dev->priv->rx_list.lock, flags);
- if (dev->rx_list.bytes_held < bytes) {
- spin_unlock_irqrestore(&dev->rx_list.lock, flags);
+ if (dev->priv->rx_list.bytes_held < bytes) {
+ spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
dev_dbg(&dev->core, "%s:%d: starved for %lxh bytes\n",
- __func__, __LINE__, bytes - dev->rx_list.bytes_held);
+ __func__, __LINE__,
+ bytes - dev->priv->rx_list.bytes_held);
return -EAGAIN;
}
- list_for_each_entry_safe(lb, n, &dev->rx_list.head, link) {
+ list_for_each_entry_safe(lb, n, &dev->priv->rx_list.head, link) {
bytes_read = min((unsigned int)(lb->tail - lb->head), bytes);
memcpy(buf, lb->head, bytes_read);
buf += bytes_read;
bytes -= bytes_read;
- dev->rx_list.bytes_held -= bytes_read;
+ dev->priv->rx_list.bytes_held -= bytes_read;
if (bytes_read < lb->tail - lb->head) {
lb->head += bytes_read;
- spin_unlock_irqrestore(&dev->rx_list.lock, flags);
-
- dev_dbg(&dev->core,
- "%s:%d: dequeued buf_%lu, %lxh bytes\n",
- __func__, __LINE__, lb->dbg_number, bytes_read);
+ dev_dbg(&dev->core, "%s:%d: buf_%lu: dequeued %lxh "
+ "bytes\n", __func__, __LINE__, lb->dbg_number,
+ bytes_read);
+ spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
return 0;
}
- dev_dbg(&dev->core, "%s:%d free buf_%lu\n", __func__, __LINE__,
- lb->dbg_number);
+ dev_dbg(&dev->core, "%s:%d: buf_%lu: free, dequeued %lxh "
+ "bytes\n", __func__, __LINE__, lb->dbg_number,
+ bytes_read);
list_del(&lb->link);
kfree(lb);
}
- spin_unlock_irqrestore(&dev->rx_list.lock, flags);
- dev_dbg(&dev->core, "%s:%d: dequeued buf_%lu, %xh bytes\n",
- __func__, __LINE__, lb->dbg_number, bytes);
+ spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
+ return 0;
+}
+
+int ps3_vuart_read_async(struct ps3_vuart_port_device *dev, work_func_t func,
+ unsigned int bytes)
+{
+ unsigned long flags;
+
+ if(dev->priv->work.trigger) {
+ dev_dbg(&dev->core, "%s:%d: warning, multiple calls\n",
+ __func__, __LINE__);
+ return -EAGAIN;
+ }
+
+ BUG_ON(!bytes);
+
+ PREPARE_WORK(&dev->priv->work.work, func);
+
+ spin_lock_irqsave(&dev->priv->work.lock, flags);
+ if(dev->priv->rx_list.bytes_held >= bytes) {
+ dev_dbg(&dev->core, "%s:%d: schedule_work %xh bytes\n",
+ __func__, __LINE__, bytes);
+ schedule_work(&dev->priv->work.work);
+ spin_unlock_irqrestore(&dev->priv->work.lock, flags);
+ return 0;
+ }
+
+ dev->priv->work.trigger = bytes;
+ spin_unlock_irqrestore(&dev->priv->work.lock, flags);
+
+ dev_dbg(&dev->core, "%s:%d: waiting for %u(%xh) bytes\n", __func__,
+ __LINE__, bytes, bytes);
return 0;
}
+void ps3_vuart_cancel_async(struct ps3_vuart_port_device *dev)
+{
+ dev->priv->work.trigger = 0;
+}
+
/**
* ps3_vuart_handle_interrupt_tx - third stage transmit interrupt handler
*
@@ -542,9 +623,9 @@ static int ps3_vuart_handle_interrupt_tx(struct ps3_vuart_port_device *dev)
dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
- spin_lock_irqsave(&dev->tx_list.lock, flags);
+ spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
- list_for_each_entry_safe(lb, n, &dev->tx_list.head, link) {
+ list_for_each_entry_safe(lb, n, &dev->priv->tx_list.head, link) {
unsigned long bytes_written;
@@ -578,7 +659,7 @@ static int ps3_vuart_handle_interrupt_tx(struct ps3_vuart_port_device *dev)
ps3_vuart_disable_interrupt_tx(dev);
port_full:
- spin_unlock_irqrestore(&dev->tx_list.lock, flags);
+ spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
dev_dbg(&dev->core, "%s:%d wrote %lxh bytes total\n",
__func__, __LINE__, bytes_total);
return result;
@@ -609,7 +690,7 @@ static int ps3_vuart_handle_interrupt_rx(struct ps3_vuart_port_device *dev)
BUG_ON(!bytes);
- /* add some extra space for recently arrived data */
+ /* Add some extra space for recently arrived data. */
bytes += 128;
@@ -624,14 +705,23 @@ static int ps3_vuart_handle_interrupt_rx(struct ps3_vuart_port_device *dev)
lb->tail = lb->data + bytes;
lb->dbg_number = ++dbg_number;
- spin_lock_irqsave(&dev->rx_list.lock, flags);
- list_add_tail(&lb->link, &dev->rx_list.head);
- dev->rx_list.bytes_held += bytes;
- spin_unlock_irqrestore(&dev->rx_list.lock, flags);
+ spin_lock_irqsave(&dev->priv->rx_list.lock, flags);
+ list_add_tail(&lb->link, &dev->priv->rx_list.head);
+ dev->priv->rx_list.bytes_held += bytes;
+ spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
- dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %lxh bytes\n",
+ dev_dbg(&dev->core, "%s:%d: buf_%lu: queued %lxh bytes\n",
__func__, __LINE__, lb->dbg_number, bytes);
+ spin_lock_irqsave(&dev->priv->work.lock, flags);
+ if(dev->priv->work.trigger
+ && dev->priv->rx_list.bytes_held >= dev->priv->work.trigger) {
+ dev_dbg(&dev->core, "%s:%d: schedule_work %lxh bytes\n",
+ __func__, __LINE__, dev->priv->work.trigger);
+ dev->priv->work.trigger = 0;
+ schedule_work(&dev->priv->work.work);
+ }
+ spin_unlock_irqrestore(&dev->priv->work.lock, flags);
return 0;
}
@@ -656,7 +746,7 @@ static int ps3_vuart_handle_port_interrupt(struct ps3_vuart_port_device *dev)
int result;
unsigned long status;
- result = ps3_vuart_get_interrupt_mask(dev, &status);
+ result = ps3_vuart_get_interrupt_status(dev, &status);
if (result)
return result;
@@ -665,21 +755,21 @@ static int ps3_vuart_handle_port_interrupt(struct ps3_vuart_port_device *dev)
status);
if (status & INTERRUPT_MASK_DISCONNECT) {
- dev->stats.disconnect_interrupts++;
+ dev->priv->stats.disconnect_interrupts++;
result = ps3_vuart_handle_interrupt_disconnect(dev);
if (result)
ps3_vuart_disable_interrupt_disconnect(dev);
}
if (status & INTERRUPT_MASK_TX) {
- dev->stats.tx_interrupts++;
+ dev->priv->stats.tx_interrupts++;
result = ps3_vuart_handle_interrupt_tx(dev);
if (result)
ps3_vuart_disable_interrupt_tx(dev);
}
if (status & INTERRUPT_MASK_RX) {
- dev->stats.rx_interrupts++;
+ dev->priv->stats.rx_interrupts++;
result = ps3_vuart_handle_interrupt_rx(dev);
if (result)
ps3_vuart_disable_interrupt_rx(dev);
@@ -688,12 +778,13 @@ static int ps3_vuart_handle_port_interrupt(struct ps3_vuart_port_device *dev)
return 0;
}
-struct vuart_private {
- unsigned int in_use;
+struct vuart_bus_priv {
+ const struct ports_bmp bmp;
unsigned int virq;
+ struct semaphore probe_mutex;
+ int use_count;
struct ps3_vuart_port_device *devices[PORT_COUNT];
- const struct ports_bmp bmp;
-};
+} static vuart_bus_priv;
/**
* ps3_vuart_irq_handler - first stage interrupt handler
@@ -705,25 +796,25 @@ struct vuart_private {
static irqreturn_t ps3_vuart_irq_handler(int irq, void *_private)
{
- struct vuart_private *private;
+ struct vuart_bus_priv *bus_priv;
BUG_ON(!_private);
- private = (struct vuart_private *)_private;
+ bus_priv = (struct vuart_bus_priv *)_private;
while (1) {
unsigned int port;
- dump_ports_bmp(&private->bmp);
+ dump_ports_bmp(&bus_priv->bmp);
- port = (BITS_PER_LONG - 1) - __ilog2(private->bmp.status);
+ port = (BITS_PER_LONG - 1) - __ilog2(bus_priv->bmp.status);
if (port == BITS_PER_LONG)
break;
BUG_ON(port >= PORT_COUNT);
- BUG_ON(!private->devices[port]);
+ BUG_ON(!bus_priv->devices[port]);
- ps3_vuart_handle_port_interrupt(private->devices[port]);
+ ps3_vuart_handle_port_interrupt(bus_priv->devices[port]);
}
return IRQ_HANDLED;
@@ -744,12 +835,10 @@ static int ps3_vuart_match(struct device *_dev, struct device_driver *_drv)
return result;
}
-static struct vuart_private vuart_private;
-
static int ps3_vuart_probe(struct device *_dev)
{
int result;
- unsigned long tmp;
+ unsigned int port_number;
struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
struct ps3_vuart_port_driver *drv =
to_ps3_vuart_port_driver(_dev->driver);
@@ -758,7 +847,12 @@ static int ps3_vuart_probe(struct device *_dev)
BUG_ON(!drv);
- result = ps3_vuart_match_id_to_port(dev->match_id, &dev->port_number);
+ down(&vuart_bus_priv.probe_mutex);
+
+ /* Setup vuart_bus_priv.devices[]. */
+
+ result = ps3_vuart_match_id_to_port(dev->match_id,
+ &port_number);
if (result) {
dev_dbg(&dev->core, "%s:%d: unknown match_id (%d)\n",
@@ -767,24 +861,41 @@ static int ps3_vuart_probe(struct device *_dev)
goto fail_match;
}
- if (vuart_private.devices[dev->port_number]) {
+ if (vuart_bus_priv.devices[port_number]) {
dev_dbg(&dev->core, "%s:%d: port busy (%d)\n", __func__,
- __LINE__, dev->port_number);
+ __LINE__, port_number);
result = -EBUSY;
goto fail_match;
}
- vuart_private.devices[dev->port_number] = dev;
+ vuart_bus_priv.devices[port_number] = dev;
+
+ /* Setup dev->priv. */
+
+ dev->priv = kzalloc(sizeof(struct ps3_vuart_port_priv), GFP_KERNEL);
+
+ if (!dev->priv) {
+ result = -ENOMEM;
+ goto fail_alloc;
+ }
- INIT_LIST_HEAD(&dev->tx_list.head);
- spin_lock_init(&dev->tx_list.lock);
- INIT_LIST_HEAD(&dev->rx_list.head);
- spin_lock_init(&dev->rx_list.lock);
+ dev->priv->port_number = port_number;
+
+ INIT_LIST_HEAD(&dev->priv->tx_list.head);
+ spin_lock_init(&dev->priv->tx_list.lock);
+
+ INIT_LIST_HEAD(&dev->priv->rx_list.head);
+ spin_lock_init(&dev->priv->rx_list.lock);
+
+ INIT_WORK(&dev->priv->work.work, NULL);
+ spin_lock_init(&dev->priv->work.lock);
+ dev->priv->work.trigger = 0;
+ dev->priv->work.dev = dev;
+
+ if (++vuart_bus_priv.use_count == 1) {
- vuart_private.in_use++;
- if (vuart_private.in_use == 1) {
result = ps3_alloc_vuart_irq(PS3_BINDING_CPU_ANY,
- (void*)&vuart_private.bmp.status, &vuart_private.virq);
+ (void*)&vuart_bus_priv.bmp.status, &vuart_bus_priv.virq);
if (result) {
dev_dbg(&dev->core,
@@ -794,8 +905,8 @@ static int ps3_vuart_probe(struct device *_dev)
goto fail_alloc_irq;
}
- result = request_irq(vuart_private.virq, ps3_vuart_irq_handler,
- IRQF_DISABLED, "vuart", &vuart_private);
+ result = request_irq(vuart_bus_priv.virq, ps3_vuart_irq_handler,
+ IRQF_DISABLED, "vuart", &vuart_bus_priv);
if (result) {
dev_info(&dev->core, "%s:%d: request_irq failed (%d)\n",
@@ -804,10 +915,11 @@ static int ps3_vuart_probe(struct device *_dev)
}
}
- ps3_vuart_set_interrupt_mask(dev, INTERRUPT_MASK_RX);
-
/* clear stale pending interrupts */
- ps3_vuart_get_interrupt_mask(dev, &tmp);
+
+ ps3_vuart_clear_rx_bytes(dev, 0);
+
+ ps3_vuart_set_interrupt_mask(dev, INTERRUPT_MASK_RX);
ps3_vuart_set_triggers(dev, 1, 1);
@@ -822,20 +934,27 @@ static int ps3_vuart_probe(struct device *_dev)
if (result) {
dev_dbg(&dev->core, "%s:%d: drv->probe failed\n",
__func__, __LINE__);
+ down(&vuart_bus_priv.probe_mutex);
goto fail_probe;
}
+ up(&vuart_bus_priv.probe_mutex);
+
return result;
fail_probe:
+ ps3_vuart_set_interrupt_mask(dev, 0);
fail_request_irq:
- vuart_private.in_use--;
- if (!vuart_private.in_use) {
- ps3_free_vuart_irq(vuart_private.virq);
- vuart_private.virq = NO_IRQ;
- }
+ ps3_free_vuart_irq(vuart_bus_priv.virq);
+ vuart_bus_priv.virq = NO_IRQ;
fail_alloc_irq:
+ --vuart_bus_priv.use_count;
+ kfree(dev->priv);
+ dev->priv = NULL;
+fail_alloc:
+ vuart_bus_priv.devices[port_number] = 0;
fail_match:
+ up(&vuart_bus_priv.probe_mutex);
dev_dbg(&dev->core, "%s:%d failed\n", __func__, __LINE__);
return result;
}
@@ -846,10 +965,12 @@ static int ps3_vuart_remove(struct device *_dev)
struct ps3_vuart_port_driver *drv =
to_ps3_vuart_port_driver(_dev->driver);
+ down(&vuart_bus_priv.probe_mutex);
+
dev_dbg(&dev->core, "%s:%d: %s\n", __func__, __LINE__,
dev->core.bus_id);
- BUG_ON(vuart_private.in_use < 1);
+ BUG_ON(vuart_bus_priv.use_count < 1);
if (drv->remove)
drv->remove(dev);
@@ -857,13 +978,19 @@ static int ps3_vuart_remove(struct device *_dev)
dev_dbg(&dev->core, "%s:%d: %s no remove method\n", __func__,
__LINE__, dev->core.bus_id);
- vuart_private.in_use--;
+ vuart_bus_priv.devices[dev->priv->port_number] = 0;
- if (!vuart_private.in_use) {
- free_irq(vuart_private.virq, &vuart_private);
- ps3_free_vuart_irq(vuart_private.virq);
- vuart_private.virq = NO_IRQ;
+ if (--vuart_bus_priv.use_count == 0) {
+ BUG();
+ free_irq(vuart_bus_priv.virq, &vuart_bus_priv);
+ ps3_free_vuart_irq(vuart_bus_priv.virq);
+ vuart_bus_priv.virq = NO_IRQ;
}
+
+ kfree(dev->priv);
+ dev->priv = NULL;
+
+ up(&vuart_bus_priv.probe_mutex);
return 0;
}
@@ -884,12 +1011,12 @@ static void ps3_vuart_shutdown(struct device *_dev)
}
/**
- * ps3_vuart - The vuart instance.
+ * ps3_vuart_bus - The vuart bus instance.
*
* The vuart is managed as a bus that port devices connect to.
*/
-struct bus_type ps3_vuart = {
+struct bus_type ps3_vuart_bus = {
.name = "ps3_vuart",
.match = ps3_vuart_match,
.probe = ps3_vuart_probe,
@@ -897,24 +1024,30 @@ struct bus_type ps3_vuart = {
.shutdown = ps3_vuart_shutdown,
};
-int __init ps3_vuart_init(void)
+int __init ps3_vuart_bus_init(void)
{
int result;
pr_debug("%s:%d:\n", __func__, __LINE__);
- result = bus_register(&ps3_vuart);
+
+ if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
+ return 0;
+
+ init_MUTEX(&vuart_bus_priv.probe_mutex);
+ result = bus_register(&ps3_vuart_bus);
BUG_ON(result);
+
return result;
}
-void __exit ps3_vuart_exit(void)
+void __exit ps3_vuart_bus_exit(void)
{
pr_debug("%s:%d:\n", __func__, __LINE__);
- bus_unregister(&ps3_vuart);
+ bus_unregister(&ps3_vuart_bus);
}
-core_initcall(ps3_vuart_init);
-module_exit(ps3_vuart_exit);
+core_initcall(ps3_vuart_bus_init);
+module_exit(ps3_vuart_bus_exit);
/**
* ps3_vuart_port_release_device - Remove a vuart port device.
@@ -922,11 +1055,14 @@ module_exit(ps3_vuart_exit);
static void ps3_vuart_port_release_device(struct device *_dev)
{
- struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
#if defined(DEBUG)
- memset(dev, 0xad, sizeof(struct ps3_vuart_port_device));
+ struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
+
+ dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
+
+ BUG_ON(dev->priv && "forgot to free");
+ memset(&dev->core, 0, sizeof(dev->core));
#endif
- kfree(dev);
}
/**
@@ -935,11 +1071,12 @@ static void ps3_vuart_port_release_device(struct device *_dev)
int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev)
{
- int result;
static unsigned int dev_count = 1;
+ BUG_ON(dev->priv && "forgot to free");
+
dev->core.parent = NULL;
- dev->core.bus = &ps3_vuart;
+ dev->core.bus = &ps3_vuart_bus;
dev->core.release = ps3_vuart_port_release_device;
snprintf(dev->core.bus_id, sizeof(dev->core.bus_id), "vuart_%02x",
@@ -947,9 +1084,7 @@ int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev)
dev_dbg(&dev->core, "%s:%d register\n", __func__, __LINE__);
- result = device_register(&dev->core);
-
- return result;
+ return device_register(&dev->core);
}
EXPORT_SYMBOL_GPL(ps3_vuart_port_device_register);
@@ -963,7 +1098,7 @@ int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv)
int result;
pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.name);
- drv->core.bus = &ps3_vuart;
+ drv->core.bus = &ps3_vuart_bus;
result = driver_register(&drv->core);
return result;
}
@@ -976,6 +1111,7 @@ EXPORT_SYMBOL_GPL(ps3_vuart_port_driver_register);
void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv)
{
+ pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.name);
driver_unregister(&drv->core);
}
diff --git a/drivers/ps3/vuart.h b/drivers/ps3/vuart.h
index 2cbf728a3a0b..1be992d568c8 100644
--- a/drivers/ps3/vuart.h
+++ b/drivers/ps3/vuart.h
@@ -21,6 +21,44 @@
#if !defined(_PS3_VUART_H)
#define _PS3_VUART_H
+#include <asm/ps3.h>
+
+struct ps3_vuart_stats {
+ unsigned long bytes_written;
+ unsigned long bytes_read;
+ unsigned long tx_interrupts;
+ unsigned long rx_interrupts;
+ unsigned long disconnect_interrupts;
+};
+
+struct ps3_vuart_work {
+ struct work_struct work;
+ unsigned long trigger;
+ spinlock_t lock;
+ struct ps3_vuart_port_device* dev; /* to convert work to device */
+};
+
+/**
+ * struct ps3_vuart_port_priv - private vuart device data.
+ */
+
+struct ps3_vuart_port_priv {
+ unsigned int port_number;
+ u64 interrupt_mask;
+
+ struct {
+ spinlock_t lock;
+ struct list_head head;
+ } tx_list;
+ struct {
+ unsigned long bytes_held;
+ spinlock_t lock;
+ struct list_head head;
+ } rx_list;
+ struct ps3_vuart_stats stats;
+ struct ps3_vuart_work work;
+};
+
/**
* struct ps3_vuart_port_driver - a driver for a device on a vuart port
*/
@@ -41,10 +79,6 @@ struct ps3_vuart_port_driver {
int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv);
void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv);
-int ps3_vuart_write(struct ps3_vuart_port_device *dev,
- const void* buf, unsigned int bytes);
-int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
- unsigned int bytes);
static inline struct ps3_vuart_port_driver *to_ps3_vuart_port_driver(
struct device_driver *_drv)
{
@@ -55,5 +89,22 @@ static inline struct ps3_vuart_port_device *to_ps3_vuart_port_device(
{
return container_of(_dev, struct ps3_vuart_port_device, core);
}
+static inline struct ps3_vuart_port_device *ps3_vuart_work_to_port_device(
+ struct work_struct *_work)
+{
+ struct ps3_vuart_work *vw = container_of(_work, struct ps3_vuart_work,
+ work);
+ return vw->dev;
+}
+
+int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
+ unsigned int bytes);
+int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
+ unsigned int bytes);
+int ps3_vuart_read_async(struct ps3_vuart_port_device *dev, work_func_t func,
+ unsigned int bytes);
+void ps3_vuart_cancel_async(struct ps3_vuart_port_device *dev);
+void ps3_vuart_clear_rx_bytes(struct ps3_vuart_port_device *dev,
+ unsigned int bytes);
#endif
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm2.c b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
index 787a8f134677..fa455996ad8f 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm2.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
@@ -285,7 +285,7 @@ void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
int __init cpm_uart_init_portdesc(void)
{
#if defined(CONFIG_SERIAL_CPM_SMC1) || defined(CONFIG_SERIAL_CPM_SMC2)
- u32 addr;
+ u16 *addr;
#endif
pr_debug("CPM uart[-]:init portdesc\n");
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 955bbd653e22..8d24cd521056 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -995,8 +995,10 @@ mpc52xx_uart_of_remove(struct of_device *op)
struct uart_port *port = dev_get_drvdata(&op->dev);
dev_set_drvdata(&op->dev, NULL);
- if (port)
+ if (port) {
uart_remove_one_port(&mpc52xx_uart_driver, port);
+ irq_dispose_mapping(port->irq);
+ }
return 0;
}