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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  PS3 virtual uart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *  Copyright (C) 2006 Sony Computer Entertainment Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *  Copyright 2006 Sony Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <asm/ps3.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <asm/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <asm/lv1call.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include "vuart.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) MODULE_AUTHOR("Sony Corporation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) MODULE_DESCRIPTION("PS3 vuart");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  * vuart - An inter-partition data link service.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *  port 0: PS3 AV Settings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  *  port 2: PS3 System Manager.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  * The vuart provides a bi-directional byte stream data link between logical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  * partitions.  Its primary role is as a communications link between the guest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  * OS and the system policy module.  The current HV does not support any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  * connections other than those listed.
^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) enum {PORT_COUNT = 3,};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) enum vuart_param {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	PARAM_TX_TRIGGER = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	PARAM_RX_TRIGGER = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	PARAM_INTERRUPT_MASK = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	PARAM_RX_BUF_SIZE = 3, /* read only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	PARAM_RX_BYTES = 4, /* read only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	PARAM_TX_BUF_SIZE = 5, /* read only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	PARAM_TX_BYTES = 6, /* read only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	PARAM_INTERRUPT_STATUS = 7, /* read only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) enum vuart_interrupt_bit {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	INTERRUPT_BIT_TX = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	INTERRUPT_BIT_RX = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	INTERRUPT_BIT_DISCONNECT = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) enum vuart_interrupt_mask {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	INTERRUPT_MASK_TX = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	INTERRUPT_MASK_RX = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	INTERRUPT_MASK_DISCONNECT = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63)  * struct ps3_vuart_port_priv - private vuart device data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) struct ps3_vuart_port_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	u64 interrupt_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 		spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 		struct list_head head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	} tx_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 		struct ps3_vuart_work work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 		unsigned long bytes_held;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 		spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 		struct list_head head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	} rx_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	struct ps3_vuart_stats stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) static struct ps3_vuart_port_priv *to_port_priv(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	BUG_ON(!dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	BUG_ON(!dev->driver_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	return (struct ps3_vuart_port_priv *)dev->driver_priv;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  * struct ports_bmp - bitmap indicating ports needing service.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  * A 256 bit read only bitmap indicating ports needing service.  Do not write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94)  * to these bits.  Must not cross a page boundary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) struct ports_bmp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	u64 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	u64 unused[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) } __attribute__((aligned(32)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) #define dump_ports_bmp(_b) _dump_ports_bmp(_b, __func__, __LINE__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) static void __maybe_unused _dump_ports_bmp(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	const struct ports_bmp *bmp, const char *func, int line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	pr_debug("%s:%d: ports_bmp: %016llxh\n", func, line, bmp->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) #define dump_port_params(_b) _dump_port_params(_b, __func__, __LINE__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) static void __maybe_unused _dump_port_params(unsigned int port_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	const char *func, int line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) #if defined(DEBUG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	static const char *strings[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 		"tx_trigger      ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 		"rx_trigger      ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 		"interrupt_mask  ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 		"rx_buf_size     ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 		"rx_bytes        ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 		"tx_buf_size     ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 		"tx_bytes        ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 		"interrupt_status",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	u64 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	for (i = 0; i < ARRAY_SIZE(strings); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 		result = lv1_get_virtual_uart_param(port_number, i, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 		if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 			pr_debug("%s:%d: port_%u: %s failed: %s\n", func, line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 				port_number, strings[i], ps3_result(result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 		pr_debug("%s:%d: port_%u: %s = %lxh\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 			func, line, port_number, strings[i], value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) int ps3_vuart_get_triggers(struct ps3_system_bus_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	struct vuart_triggers *trig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	u64 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	u64 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	u64 tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	result = lv1_get_virtual_uart_param(dev->port_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 		PARAM_TX_TRIGGER, &tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	trig->tx = tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 		dev_dbg(&dev->core, "%s:%d: tx_trigger failed: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 			__func__, __LINE__, ps3_result(result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	result = lv1_get_virtual_uart_param(dev->port_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 		PARAM_RX_BUF_SIZE, &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 		dev_dbg(&dev->core, "%s:%d: tx_buf_size failed: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 			__func__, __LINE__, ps3_result(result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	result = lv1_get_virtual_uart_param(dev->port_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 		PARAM_RX_TRIGGER, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		dev_dbg(&dev->core, "%s:%d: rx_trigger failed: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 			__func__, __LINE__, ps3_result(result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	trig->rx = size - val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	dev_dbg(&dev->core, "%s:%d: tx %lxh, rx %lxh\n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		trig->tx, trig->rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) int ps3_vuart_set_triggers(struct ps3_system_bus_device *dev, unsigned int tx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	unsigned int rx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	u64 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	result = lv1_set_virtual_uart_param(dev->port_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 		PARAM_TX_TRIGGER, tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		dev_dbg(&dev->core, "%s:%d: tx_trigger failed: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 			__func__, __LINE__, ps3_result(result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	result = lv1_get_virtual_uart_param(dev->port_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 		PARAM_RX_BUF_SIZE, &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		dev_dbg(&dev->core, "%s:%d: tx_buf_size failed: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 			__func__, __LINE__, ps3_result(result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	result = lv1_set_virtual_uart_param(dev->port_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 		PARAM_RX_TRIGGER, size - rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 		dev_dbg(&dev->core, "%s:%d: rx_trigger failed: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 			__func__, __LINE__, ps3_result(result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	dev_dbg(&dev->core, "%s:%d: tx %xh, rx %xh\n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 		tx, rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) static int ps3_vuart_get_rx_bytes_waiting(struct ps3_system_bus_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	u64 *bytes_waiting)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	result = lv1_get_virtual_uart_param(dev->port_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		PARAM_RX_BYTES, bytes_waiting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		dev_dbg(&dev->core, "%s:%d: rx_bytes failed: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 			__func__, __LINE__, ps3_result(result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	dev_dbg(&dev->core, "%s:%d: %llxh\n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		*bytes_waiting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243)  * ps3_vuart_set_interrupt_mask - Enable/disable the port interrupt sources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244)  * @dev: The struct ps3_system_bus_device instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245)  * @bmp: Logical OR of enum vuart_interrupt_mask values. A zero bit disables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) static int ps3_vuart_set_interrupt_mask(struct ps3_system_bus_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	unsigned long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	dev_dbg(&dev->core, "%s:%d: %lxh\n", __func__, __LINE__, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	priv->interrupt_mask = mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	result = lv1_set_virtual_uart_param(dev->port_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		PARAM_INTERRUPT_MASK, priv->interrupt_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 		dev_dbg(&dev->core, "%s:%d: interrupt_mask failed: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 			__func__, __LINE__, ps3_result(result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) static int ps3_vuart_get_interrupt_status(struct ps3_system_bus_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	unsigned long *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	u64 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	result = lv1_get_virtual_uart_param(dev->port_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		PARAM_INTERRUPT_STATUS, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 		dev_dbg(&dev->core, "%s:%d: interrupt_status failed: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 			__func__, __LINE__, ps3_result(result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	*status = tmp & priv->interrupt_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	dev_dbg(&dev->core, "%s:%d: m %llxh, s %llxh, m&s %lxh\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		__func__, __LINE__, priv->interrupt_mask, tmp, *status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) int ps3_vuart_enable_interrupt_tx(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	return (priv->interrupt_mask & INTERRUPT_MASK_TX) ? 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		: ps3_vuart_set_interrupt_mask(dev, priv->interrupt_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		| INTERRUPT_MASK_TX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) int ps3_vuart_enable_interrupt_rx(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	return (priv->interrupt_mask & INTERRUPT_MASK_RX) ? 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		: ps3_vuart_set_interrupt_mask(dev, priv->interrupt_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		| INTERRUPT_MASK_RX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) int ps3_vuart_enable_interrupt_disconnect(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	return (priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT) ? 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		: ps3_vuart_set_interrupt_mask(dev, priv->interrupt_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		| INTERRUPT_MASK_DISCONNECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) int ps3_vuart_disable_interrupt_tx(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	return (priv->interrupt_mask & INTERRUPT_MASK_TX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		? ps3_vuart_set_interrupt_mask(dev, priv->interrupt_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		& ~INTERRUPT_MASK_TX) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) int ps3_vuart_disable_interrupt_rx(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	return (priv->interrupt_mask & INTERRUPT_MASK_RX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		? ps3_vuart_set_interrupt_mask(dev, priv->interrupt_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		& ~INTERRUPT_MASK_RX) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) int ps3_vuart_disable_interrupt_disconnect(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	return (priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		? ps3_vuart_set_interrupt_mask(dev, priv->interrupt_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		& ~INTERRUPT_MASK_DISCONNECT) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345)  * ps3_vuart_raw_write - Low level write helper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346)  * @dev: The struct ps3_system_bus_device instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348)  * Do not call ps3_vuart_raw_write directly, use ps3_vuart_write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) static int ps3_vuart_raw_write(struct ps3_system_bus_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	const void *buf, unsigned int bytes, u64 *bytes_written)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	result = lv1_write_virtual_uart(dev->port_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		dev_dbg(&dev->core, "%s:%d: lv1_write_virtual_uart failed: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 			"%s\n", __func__, __LINE__, ps3_result(result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	priv->stats.bytes_written += *bytes_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	dev_dbg(&dev->core, "%s:%d: wrote %llxh/%xh=>%lxh\n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		*bytes_written, bytes, priv->stats.bytes_written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375)  * ps3_vuart_raw_read - Low level read helper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376)  * @dev: The struct ps3_system_bus_device instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378)  * Do not call ps3_vuart_raw_read directly, use ps3_vuart_read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) static int ps3_vuart_raw_read(struct ps3_system_bus_device *dev, void *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	unsigned int bytes, u64 *bytes_read)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	result = lv1_read_virtual_uart(dev->port_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		dev_dbg(&dev->core, "%s:%d: lv1_read_virtual_uart failed: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 			__func__, __LINE__, ps3_result(result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	priv->stats.bytes_read += *bytes_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	dev_dbg(&dev->core, "%s:%d: read %llxh/%xh=>%lxh\n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		*bytes_read, bytes, priv->stats.bytes_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407)  * ps3_vuart_clear_rx_bytes - Discard bytes received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408)  * @dev: The struct ps3_system_bus_device instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409)  * @bytes: Max byte count to discard, zero = all pending.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411)  * Used to clear pending rx interrupt source.  Will not block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) void ps3_vuart_clear_rx_bytes(struct ps3_system_bus_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	unsigned int bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	u64 bytes_waiting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	void *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes_waiting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	BUG_ON(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	bytes = bytes ? min(bytes, (unsigned int)bytes_waiting) : bytes_waiting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	dev_dbg(&dev->core, "%s:%d: %u\n", __func__, __LINE__, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	if (!bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	/* Add some extra space for recently arrived data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	bytes += 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	tmp = kmalloc(bytes, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	if (!tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	ps3_vuart_raw_read(dev, tmp, bytes, &bytes_waiting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	kfree(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	/* Don't include these bytes in the stats. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	priv->stats.bytes_read -= bytes_waiting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) EXPORT_SYMBOL_GPL(ps3_vuart_clear_rx_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453)  * struct list_buffer - An element for a port device fifo buffer list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) struct list_buffer {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	struct list_head link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	const unsigned char *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	const unsigned char *tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	unsigned long dbg_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	unsigned char data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465)  * ps3_vuart_write - the entry point for writing data to a port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466)  * @dev: The struct ps3_system_bus_device instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468)  * If the port is idle on entry as much of the incoming data is written to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469)  * the port as the port will accept.  Otherwise a list buffer is created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470)  * and any remaning incoming data is copied to that buffer.  The buffer is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471)  * then enqueued for transmision via the transmit interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) int ps3_vuart_write(struct ps3_system_bus_device *dev, const void *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	unsigned int bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	static unsigned long dbg_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	struct list_buffer *lb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		bytes, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	spin_lock_irqsave(&priv->tx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	if (list_empty(&priv->tx_list.head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		u64 bytes_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		result = ps3_vuart_raw_write(dev, buf, bytes, &bytes_written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		spin_unlock_irqrestore(&priv->tx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 			dev_dbg(&dev->core,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 				"%s:%d: ps3_vuart_raw_write failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 				__func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 			return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		if (bytes_written == bytes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 			dev_dbg(&dev->core, "%s:%d: wrote %xh bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 				__func__, __LINE__, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		bytes -= bytes_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		buf += bytes_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		spin_unlock_irqrestore(&priv->tx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	if (!lb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	memcpy(lb->data, buf, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	lb->head = lb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	lb->tail = lb->data + bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	lb->dbg_number = ++dbg_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	spin_lock_irqsave(&priv->tx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	list_add_tail(&lb->link, &priv->tx_list.head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	ps3_vuart_enable_interrupt_tx(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	spin_unlock_irqrestore(&priv->tx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %xh bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		__func__, __LINE__, lb->dbg_number, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) EXPORT_SYMBOL_GPL(ps3_vuart_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536)  * ps3_vuart_queue_rx_bytes - Queue waiting bytes into the buffer list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537)  * @dev: The struct ps3_system_bus_device instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538)  * @bytes_queued: Number of bytes queued to the buffer list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540)  * Must be called with priv->rx_list.lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) static int ps3_vuart_queue_rx_bytes(struct ps3_system_bus_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	u64 *bytes_queued)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	static unsigned long dbg_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	struct list_buffer *lb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	u64 bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	*bytes_queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	BUG_ON(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	if (!bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	/* Add some extra space for recently arrived data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	bytes += 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	if (!lb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	ps3_vuart_raw_read(dev, lb->data, bytes, &bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	lb->head = lb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	lb->tail = lb->data + bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	lb->dbg_number = ++dbg_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	list_add_tail(&lb->link, &priv->rx_list.head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	priv->rx_list.bytes_held += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	dev_dbg(&dev->core, "%s:%d: buf_%lu: queued %llxh bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		__func__, __LINE__, lb->dbg_number, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	*bytes_queued = bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590)  * ps3_vuart_read - The entry point for reading data from a port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592)  * Queue data waiting at the port, and if enough bytes to satisfy the request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593)  * are held in the buffer list those bytes are dequeued and copied to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594)  * caller's buffer.  Emptied list buffers are retiered.  If the request cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595)  * be statified by bytes held in the list buffers -EAGAIN is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) int ps3_vuart_read(struct ps3_system_bus_device *dev, void *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	unsigned int bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	struct list_buffer *lb, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	unsigned long bytes_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		bytes, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	spin_lock_irqsave(&priv->rx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	/* Queue rx bytes here for polled reads. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	while (priv->rx_list.bytes_held < bytes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		u64 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 		result = ps3_vuart_queue_rx_bytes(dev, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		if (result || !tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 			dev_dbg(&dev->core, "%s:%d: starved for %lxh bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 				__func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 				bytes - priv->rx_list.bytes_held);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 			spin_unlock_irqrestore(&priv->rx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 			return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	list_for_each_entry_safe(lb, n, &priv->rx_list.head, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		bytes_read = min((unsigned int)(lb->tail - lb->head), bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		memcpy(buf, lb->head, bytes_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		buf += bytes_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		bytes -= bytes_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		priv->rx_list.bytes_held -= bytes_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		if (bytes_read < lb->tail - lb->head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 			lb->head += bytes_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 			dev_dbg(&dev->core, "%s:%d: buf_%lu: dequeued %lxh "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 				"bytes\n", __func__, __LINE__, lb->dbg_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 				bytes_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 			spin_unlock_irqrestore(&priv->rx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		dev_dbg(&dev->core, "%s:%d: buf_%lu: free, dequeued %lxh "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 			"bytes\n", __func__, __LINE__, lb->dbg_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 			bytes_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		list_del(&lb->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		kfree(lb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	spin_unlock_irqrestore(&priv->rx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) EXPORT_SYMBOL_GPL(ps3_vuart_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658)  * ps3_vuart_work - Asynchronous read handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) static void ps3_vuart_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	struct ps3_system_bus_device *dev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		ps3_vuart_work_to_system_bus_dev(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	struct ps3_vuart_port_driver *drv =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		ps3_system_bus_dev_to_vuart_drv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	BUG_ON(!drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	drv->work(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) int ps3_vuart_read_async(struct ps3_system_bus_device *dev, unsigned int bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	if (priv->rx_list.work.trigger) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		dev_dbg(&dev->core, "%s:%d: warning, multiple calls\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 			__func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	BUG_ON(!bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	spin_lock_irqsave(&priv->rx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	if (priv->rx_list.bytes_held >= bytes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		dev_dbg(&dev->core, "%s:%d: schedule_work %xh bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 			__func__, __LINE__, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		schedule_work(&priv->rx_list.work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		spin_unlock_irqrestore(&priv->rx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	priv->rx_list.work.trigger = bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	spin_unlock_irqrestore(&priv->rx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	dev_dbg(&dev->core, "%s:%d: waiting for %u(%xh) bytes\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		__LINE__, bytes, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) EXPORT_SYMBOL_GPL(ps3_vuart_read_async);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) void ps3_vuart_cancel_async(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	to_port_priv(dev)->rx_list.work.trigger = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) EXPORT_SYMBOL_GPL(ps3_vuart_cancel_async);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711)  * ps3_vuart_handle_interrupt_tx - third stage transmit interrupt handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713)  * Services the transmit interrupt for the port.  Writes as much data from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714)  * buffer list as the port will accept.  Retires any emptied list buffers and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715)  * adjusts the final list buffer state for a partial write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) static int ps3_vuart_handle_interrupt_tx(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	struct list_buffer *lb, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	unsigned long bytes_total = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	spin_lock_irqsave(&priv->tx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	list_for_each_entry_safe(lb, n, &priv->tx_list.head, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		u64 bytes_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		result = ps3_vuart_raw_write(dev, lb->head, lb->tail - lb->head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 			&bytes_written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 			dev_dbg(&dev->core,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 				"%s:%d: ps3_vuart_raw_write failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 				__func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		bytes_total += bytes_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		if (bytes_written < lb->tail - lb->head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 			lb->head += bytes_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 			dev_dbg(&dev->core,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 				"%s:%d cleared buf_%lu, %llxh bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 				__func__, __LINE__, lb->dbg_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 				bytes_written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 			goto port_full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		dev_dbg(&dev->core, "%s:%d free buf_%lu\n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 			lb->dbg_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		list_del(&lb->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		kfree(lb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	ps3_vuart_disable_interrupt_tx(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) port_full:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	spin_unlock_irqrestore(&priv->tx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	dev_dbg(&dev->core, "%s:%d wrote %lxh bytes total\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		__func__, __LINE__, bytes_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771)  * ps3_vuart_handle_interrupt_rx - third stage receive interrupt handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773)  * Services the receive interrupt for the port.  Creates a list buffer and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774)  * copies all waiting port data to that buffer and enqueues the buffer in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775)  * buffer list.  Buffer list data is dequeued via ps3_vuart_read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) static int ps3_vuart_handle_interrupt_rx(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	u64 bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	spin_lock_irqsave(&priv->rx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	result = ps3_vuart_queue_rx_bytes(dev, &bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		spin_unlock_irqrestore(&priv->rx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	if (priv->rx_list.work.trigger && priv->rx_list.bytes_held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		>= priv->rx_list.work.trigger) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		dev_dbg(&dev->core, "%s:%d: schedule_work %lxh bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 			__func__, __LINE__, priv->rx_list.work.trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		priv->rx_list.work.trigger = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 		schedule_work(&priv->rx_list.work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	spin_unlock_irqrestore(&priv->rx_list.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) static int ps3_vuart_handle_interrupt_disconnect(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	BUG_ON("no support");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816)  * ps3_vuart_handle_port_interrupt - second stage interrupt handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818)  * Services any pending interrupt types for the port.  Passes control to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819)  * third stage type specific interrupt handler.  Returns control to the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820)  * stage handler after one iteration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) static int ps3_vuart_handle_port_interrupt(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	unsigned long status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	result = ps3_vuart_get_interrupt_status(dev, &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	dev_dbg(&dev->core, "%s:%d: status: %lxh\n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	if (status & INTERRUPT_MASK_DISCONNECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		priv->stats.disconnect_interrupts++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		result = ps3_vuart_handle_interrupt_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 			ps3_vuart_disable_interrupt_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	if (status & INTERRUPT_MASK_TX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		priv->stats.tx_interrupts++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 		result = ps3_vuart_handle_interrupt_tx(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 			ps3_vuart_disable_interrupt_tx(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	if (status & INTERRUPT_MASK_RX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		priv->stats.rx_interrupts++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		result = ps3_vuart_handle_interrupt_rx(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 			ps3_vuart_disable_interrupt_rx(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) static struct vuart_bus_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	struct ports_bmp *bmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	unsigned int virq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	struct mutex probe_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	int use_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	struct ps3_system_bus_device *devices[PORT_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) } vuart_bus_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870)  * ps3_vuart_irq_handler - first stage interrupt handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872)  * Loops finding any interrupting port and its associated instance data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873)  * Passes control to the second stage port specific interrupt handler.  Loops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874)  * until all outstanding interrupts are serviced.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) static irqreturn_t ps3_vuart_irq_handler(int irq, void *_private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	struct vuart_bus_priv *bus_priv = _private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	BUG_ON(!bus_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		unsigned int port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		dump_ports_bmp(bus_priv->bmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		port = (BITS_PER_LONG - 1) - __ilog2(bus_priv->bmp->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		if (port == BITS_PER_LONG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		BUG_ON(port >= PORT_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		BUG_ON(!bus_priv->devices[port]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		ps3_vuart_handle_port_interrupt(bus_priv->devices[port]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) static int ps3_vuart_bus_interrupt_get(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	pr_debug(" -> %s:%d\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	vuart_bus_priv.use_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	BUG_ON(vuart_bus_priv.use_count > 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	if (vuart_bus_priv.use_count != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	BUG_ON(vuart_bus_priv.bmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	vuart_bus_priv.bmp = kzalloc(sizeof(struct ports_bmp), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	if (!vuart_bus_priv.bmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		result = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		goto fail_bmp_malloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	result = ps3_vuart_irq_setup(PS3_BINDING_CPU_ANY, vuart_bus_priv.bmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		&vuart_bus_priv.virq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		pr_debug("%s:%d: ps3_vuart_irq_setup failed (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 			__func__, __LINE__, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		result = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		goto fail_alloc_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	result = request_irq(vuart_bus_priv.virq, ps3_vuart_irq_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		0, "vuart", &vuart_bus_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		pr_debug("%s:%d: request_irq failed (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 			__func__, __LINE__, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		goto fail_request_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	pr_debug(" <- %s:%d: ok\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) fail_request_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	ps3_vuart_irq_destroy(vuart_bus_priv.virq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	vuart_bus_priv.virq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) fail_alloc_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	kfree(vuart_bus_priv.bmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	vuart_bus_priv.bmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) fail_bmp_malloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	vuart_bus_priv.use_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	pr_debug(" <- %s:%d: failed\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) static int ps3_vuart_bus_interrupt_put(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	pr_debug(" -> %s:%d\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	vuart_bus_priv.use_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	BUG_ON(vuart_bus_priv.use_count < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	if (vuart_bus_priv.use_count != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	free_irq(vuart_bus_priv.virq, &vuart_bus_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	ps3_vuart_irq_destroy(vuart_bus_priv.virq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	vuart_bus_priv.virq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	kfree(vuart_bus_priv.bmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	vuart_bus_priv.bmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	pr_debug(" <- %s:%d\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) static int ps3_vuart_probe(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	struct ps3_vuart_port_driver *drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	struct ps3_vuart_port_priv *priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	drv = ps3_system_bus_dev_to_vuart_drv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	BUG_ON(!drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	dev_dbg(&dev->core, "%s:%d: (%s)\n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		drv->core.core.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	if (dev->port_number >= PORT_COUNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	mutex_lock(&vuart_bus_priv.probe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	result = ps3_vuart_bus_interrupt_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		goto fail_setup_interrupt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	if (vuart_bus_priv.devices[dev->port_number]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		dev_dbg(&dev->core, "%s:%d: port busy (%d)\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 			__LINE__, dev->port_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 		result = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		goto fail_busy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	vuart_bus_priv.devices[dev->port_number] = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	/* Setup dev->driver_priv. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	dev->driver_priv = kzalloc(sizeof(struct ps3_vuart_port_priv),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	if (!dev->driver_priv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		result = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		goto fail_dev_malloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	INIT_LIST_HEAD(&priv->tx_list.head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	spin_lock_init(&priv->tx_list.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	INIT_LIST_HEAD(&priv->rx_list.head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	spin_lock_init(&priv->rx_list.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	INIT_WORK(&priv->rx_list.work.work, ps3_vuart_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	priv->rx_list.work.trigger = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	priv->rx_list.work.dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	/* clear stale pending interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	ps3_vuart_clear_rx_bytes(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	ps3_vuart_set_interrupt_mask(dev, INTERRUPT_MASK_RX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	ps3_vuart_set_triggers(dev, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	if (drv->probe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		result = drv->probe(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 		dev_info(&dev->core, "%s:%d: no probe method\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 			__LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		dev_dbg(&dev->core, "%s:%d: drv->probe failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 			__func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		goto fail_probe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	mutex_unlock(&vuart_bus_priv.probe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) fail_probe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	ps3_vuart_set_interrupt_mask(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	kfree(dev->driver_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	dev->driver_priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) fail_dev_malloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	vuart_bus_priv.devices[dev->port_number] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) fail_busy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	ps3_vuart_bus_interrupt_put();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) fail_setup_interrupt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	mutex_unlock(&vuart_bus_priv.probe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	dev_dbg(&dev->core, "%s:%d: failed\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)  * ps3_vuart_cleanup - common cleanup helper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)  * @dev: The struct ps3_system_bus_device instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)  * Cleans interrupts and HV resources.  Must be called with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)  * vuart_bus_priv.probe_mutex held.  Used by ps3_vuart_remove and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)  * ps3_vuart_shutdown.  After this call, polled reading will still work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) static int ps3_vuart_cleanup(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	ps3_vuart_cancel_async(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	ps3_vuart_set_interrupt_mask(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	ps3_vuart_bus_interrupt_put();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)  * ps3_vuart_remove - Completely clean the device instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)  * @dev: The struct ps3_system_bus_device instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)  * Cleans all memory, interrupts and HV resources.  After this call the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)  * device can no longer be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) static int ps3_vuart_remove(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	struct ps3_vuart_port_priv *priv = to_port_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	struct ps3_vuart_port_driver *drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	BUG_ON(!dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	mutex_lock(&vuart_bus_priv.probe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	dev_dbg(&dev->core, " -> %s:%d: match_id %d\n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 		dev->match_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	if (!dev->core.driver) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		dev_dbg(&dev->core, "%s:%d: no driver bound\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 			__LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		mutex_unlock(&vuart_bus_priv.probe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	drv = ps3_system_bus_dev_to_vuart_drv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	BUG_ON(!drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	if (drv->remove) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 		drv->remove(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		dev_dbg(&dev->core, "%s:%d: no remove method\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		__LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	ps3_vuart_cleanup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	vuart_bus_priv.devices[dev->port_number] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	kfree(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	mutex_unlock(&vuart_bus_priv.probe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)  * ps3_vuart_shutdown - Cleans interrupts and HV resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)  * @dev: The struct ps3_system_bus_device instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)  * Cleans interrupts and HV resources.  After this call the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)  * device can still be used in polling mode.  This behavior required
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)  * by sys-manager to be able to complete the device power operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)  * sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) static int ps3_vuart_shutdown(struct ps3_system_bus_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	struct ps3_vuart_port_driver *drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	BUG_ON(!dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	mutex_lock(&vuart_bus_priv.probe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	dev_dbg(&dev->core, " -> %s:%d: match_id %d\n", __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 		dev->match_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	if (!dev->core.driver) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 		dev_dbg(&dev->core, "%s:%d: no driver bound\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 			__LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		mutex_unlock(&vuart_bus_priv.probe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	drv = ps3_system_bus_dev_to_vuart_drv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	BUG_ON(!drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	if (drv->shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 		drv->shutdown(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	else if (drv->remove) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 		dev_dbg(&dev->core, "%s:%d: no shutdown, calling remove\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 			__func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 		drv->remove(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 		dev_dbg(&dev->core, "%s:%d: no shutdown method\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 			__LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	ps3_vuart_cleanup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	mutex_unlock(&vuart_bus_priv.probe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) static int __init ps3_vuart_bus_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	pr_debug("%s:%d:\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	mutex_init(&vuart_bus_priv.probe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) static void __exit ps3_vuart_bus_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	pr_debug("%s:%d:\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) core_initcall(ps3_vuart_bus_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) module_exit(ps3_vuart_bus_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)  * ps3_vuart_port_driver_register - Add a vuart port device driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.core.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	BUG_ON(!drv->core.match_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	BUG_ON(!drv->core.core.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	drv->core.probe = ps3_vuart_probe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	drv->core.remove = ps3_vuart_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	drv->core.shutdown = ps3_vuart_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	result = ps3_system_bus_driver_register(&drv->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) EXPORT_SYMBOL_GPL(ps3_vuart_port_driver_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)  * ps3_vuart_port_driver_unregister - Remove a vuart port device driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.core.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	ps3_system_bus_driver_unregister(&drv->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) EXPORT_SYMBOL_GPL(ps3_vuart_port_driver_unregister);