| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |  * QEMU ESCC (Z8030/Z8530/Z85C30/SCC/ESCC) serial port emulation | 
					
						
							| 
									
										
										
										
											2007-09-16 21:08:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |  * Copyright (c) 2003-2005 Fabrice Bellard | 
					
						
							| 
									
										
										
										
											2007-09-16 21:08:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  |  * in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  |  * furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The above copyright notice and this permission notice shall be included in | 
					
						
							|  |  |  |  * all copies or substantial portions of the Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | 
					
						
							|  |  |  |  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
					
						
							|  |  |  |  * THE SOFTWARE. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-07-15 08:51:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 18:17:30 +00:00
										 |  |  | #include "qemu/osdep.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 07:23:42 +02:00
										 |  |  | #include "hw/irq.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 07:23:51 +02:00
										 |  |  | #include "hw/qdev-properties.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-04 15:40:22 +01:00
										 |  |  | #include "hw/sysbus.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 07:23:45 +02:00
										 |  |  | #include "migration/vmstate.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-23 16:35:07 +02:00
										 |  |  | #include "qemu/module.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-05 17:06:20 +01:00
										 |  |  | #include "hw/char/escc.h"
 | 
					
						
							| 
									
										
										
										
											2012-11-28 12:06:30 +01:00
										 |  |  | #include "ui/console.h"
 | 
					
						
							| 
									
										
										
										
											2011-08-07 11:01:05 +00:00
										 |  |  | #include "trace.h"
 | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2009-10-24 16:09:01 +00:00
										 |  |  |  * Chipset docs: | 
					
						
							|  |  |  |  * "Z80C30/Z85C30/Z80230/Z85230/Z85233 SCC/ESCC User Manual", | 
					
						
							|  |  |  |  * http://www.zilog.com/docs/serial/scc_escc_um.pdf
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |  * On Sparc32 this is the serial port, mouse and keyboard part of chip STP2001 | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |  * (Slave I/O), also produced as NCR89C105. See | 
					
						
							|  |  |  |  * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
 | 
					
						
							| 
									
										
										
										
											2007-09-16 21:08:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |  * The serial ports implement full AMD AM8530 or Zilog Z8530 chips, | 
					
						
							|  |  |  |  * mouse and keyboard ports don't implement all functions and they are | 
					
						
							|  |  |  |  * only asynchronous. There is no DMA. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-05-26 00:50:04 +02:00
										 |  |  |  * Z85C30 is also used on PowerMacs and m68k Macs. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * There are some small differences between Sparc version (sunzilog) | 
					
						
							|  |  |  |  * and PowerMac (pmac): | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |  *  Offset between control and data registers | 
					
						
							|  |  |  |  *  There is some kind of lockup bug, but we can ignore it | 
					
						
							|  |  |  |  *  CTS is inverted | 
					
						
							|  |  |  |  *  DMA on pmac using DBDMA chip | 
					
						
							|  |  |  |  *  pmac can do IRDA and faster rates, sunzilog can only do 38400 | 
					
						
							|  |  |  |  *  pmac baud rate generator clock is 3.6864 MHz, sunzilog 4.9152 MHz | 
					
						
							| 
									
										
										
										
											2019-05-26 00:50:04 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Linux driver for m68k Macs is the same as for PowerMac (pmac_zilog), | 
					
						
							|  |  |  |  * but registers are grouped by type and not by channel: | 
					
						
							|  |  |  |  * channel is selected by bit 0 of the address (instead of bit 1) | 
					
						
							|  |  |  |  * and register is selected by bit 1 of the address (instead of bit 0). | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-09 11:35:47 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Modifications: | 
					
						
							|  |  |  |  *  2006-Aug-10  Igor Kovalenko :   Renamed KBDQueue to SERIOQueue, implemented | 
					
						
							|  |  |  |  *                                  serial mouse queue. | 
					
						
							|  |  |  |  *                                  Implemented serial mouse protocol. | 
					
						
							| 
									
										
										
										
											2010-08-15 16:04:41 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  *  2010-May-23  Artyom Tarasenko:  Reworked IUS logic | 
					
						
							| 
									
										
										
										
											2006-09-09 11:35:47 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | #define CHN_C(s) ((s)->chn == escc_chn_b ? 'b' : 'a')
 | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  | #define SERIAL_CTRL 0
 | 
					
						
							|  |  |  | #define SERIAL_DATA 1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define W_CMD     0
 | 
					
						
							|  |  |  | #define CMD_PTR_MASK   0x07
 | 
					
						
							|  |  |  | #define CMD_CMD_MASK   0x38
 | 
					
						
							|  |  |  | #define CMD_HI         0x08
 | 
					
						
							|  |  |  | #define CMD_CLR_TXINT  0x28
 | 
					
						
							|  |  |  | #define CMD_CLR_IUS    0x38
 | 
					
						
							|  |  |  | #define W_INTR    1
 | 
					
						
							|  |  |  | #define INTR_INTALL    0x01
 | 
					
						
							|  |  |  | #define INTR_TXINT     0x02
 | 
					
						
							|  |  |  | #define INTR_RXMODEMSK 0x18
 | 
					
						
							|  |  |  | #define INTR_RXINT1ST  0x08
 | 
					
						
							|  |  |  | #define INTR_RXINTALL  0x10
 | 
					
						
							|  |  |  | #define W_IVEC    2
 | 
					
						
							|  |  |  | #define W_RXCTRL  3
 | 
					
						
							|  |  |  | #define RXCTRL_RXEN    0x01
 | 
					
						
							|  |  |  | #define W_TXCTRL1 4
 | 
					
						
							|  |  |  | #define TXCTRL1_PAREN  0x01
 | 
					
						
							|  |  |  | #define TXCTRL1_PAREV  0x02
 | 
					
						
							|  |  |  | #define TXCTRL1_1STOP  0x04
 | 
					
						
							|  |  |  | #define TXCTRL1_1HSTOP 0x08
 | 
					
						
							|  |  |  | #define TXCTRL1_2STOP  0x0c
 | 
					
						
							|  |  |  | #define TXCTRL1_STPMSK 0x0c
 | 
					
						
							|  |  |  | #define TXCTRL1_CLK1X  0x00
 | 
					
						
							|  |  |  | #define TXCTRL1_CLK16X 0x40
 | 
					
						
							|  |  |  | #define TXCTRL1_CLK32X 0x80
 | 
					
						
							|  |  |  | #define TXCTRL1_CLK64X 0xc0
 | 
					
						
							|  |  |  | #define TXCTRL1_CLKMSK 0xc0
 | 
					
						
							|  |  |  | #define W_TXCTRL2 5
 | 
					
						
							|  |  |  | #define TXCTRL2_TXEN   0x08
 | 
					
						
							|  |  |  | #define TXCTRL2_BITMSK 0x60
 | 
					
						
							|  |  |  | #define TXCTRL2_5BITS  0x00
 | 
					
						
							|  |  |  | #define TXCTRL2_7BITS  0x20
 | 
					
						
							|  |  |  | #define TXCTRL2_6BITS  0x40
 | 
					
						
							|  |  |  | #define TXCTRL2_8BITS  0x60
 | 
					
						
							|  |  |  | #define W_SYNC1   6
 | 
					
						
							|  |  |  | #define W_SYNC2   7
 | 
					
						
							|  |  |  | #define W_TXBUF   8
 | 
					
						
							|  |  |  | #define W_MINTR   9
 | 
					
						
							|  |  |  | #define MINTR_STATUSHI 0x10
 | 
					
						
							|  |  |  | #define MINTR_RST_MASK 0xc0
 | 
					
						
							|  |  |  | #define MINTR_RST_B    0x40
 | 
					
						
							|  |  |  | #define MINTR_RST_A    0x80
 | 
					
						
							|  |  |  | #define MINTR_RST_ALL  0xc0
 | 
					
						
							|  |  |  | #define W_MISC1  10
 | 
					
						
							|  |  |  | #define W_CLOCK  11
 | 
					
						
							|  |  |  | #define CLOCK_TRXC     0x08
 | 
					
						
							|  |  |  | #define W_BRGLO  12
 | 
					
						
							|  |  |  | #define W_BRGHI  13
 | 
					
						
							|  |  |  | #define W_MISC2  14
 | 
					
						
							|  |  |  | #define MISC2_PLLDIS   0x30
 | 
					
						
							|  |  |  | #define W_EXTINT 15
 | 
					
						
							|  |  |  | #define EXTINT_DCD     0x08
 | 
					
						
							|  |  |  | #define EXTINT_SYNCINT 0x10
 | 
					
						
							|  |  |  | #define EXTINT_CTSINT  0x20
 | 
					
						
							|  |  |  | #define EXTINT_TXUNDRN 0x40
 | 
					
						
							|  |  |  | #define EXTINT_BRKINT  0x80
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define R_STATUS  0
 | 
					
						
							|  |  |  | #define STATUS_RXAV    0x01
 | 
					
						
							|  |  |  | #define STATUS_ZERO    0x02
 | 
					
						
							|  |  |  | #define STATUS_TXEMPTY 0x04
 | 
					
						
							|  |  |  | #define STATUS_DCD     0x08
 | 
					
						
							|  |  |  | #define STATUS_SYNC    0x10
 | 
					
						
							|  |  |  | #define STATUS_CTS     0x20
 | 
					
						
							|  |  |  | #define STATUS_TXUNDRN 0x40
 | 
					
						
							|  |  |  | #define STATUS_BRK     0x80
 | 
					
						
							|  |  |  | #define R_SPEC    1
 | 
					
						
							|  |  |  | #define SPEC_ALLSENT   0x01
 | 
					
						
							|  |  |  | #define SPEC_BITS8     0x06
 | 
					
						
							|  |  |  | #define R_IVEC    2
 | 
					
						
							|  |  |  | #define IVEC_TXINTB    0x00
 | 
					
						
							|  |  |  | #define IVEC_LONOINT   0x06
 | 
					
						
							|  |  |  | #define IVEC_LORXINTA  0x0c
 | 
					
						
							|  |  |  | #define IVEC_LORXINTB  0x04
 | 
					
						
							|  |  |  | #define IVEC_LOTXINTA  0x08
 | 
					
						
							|  |  |  | #define IVEC_HINOINT   0x60
 | 
					
						
							|  |  |  | #define IVEC_HIRXINTA  0x30
 | 
					
						
							|  |  |  | #define IVEC_HIRXINTB  0x20
 | 
					
						
							|  |  |  | #define IVEC_HITXINTA  0x10
 | 
					
						
							|  |  |  | #define R_INTR    3
 | 
					
						
							|  |  |  | #define INTR_EXTINTB   0x01
 | 
					
						
							|  |  |  | #define INTR_TXINTB    0x02
 | 
					
						
							|  |  |  | #define INTR_RXINTB    0x04
 | 
					
						
							|  |  |  | #define INTR_EXTINTA   0x08
 | 
					
						
							|  |  |  | #define INTR_TXINTA    0x10
 | 
					
						
							|  |  |  | #define INTR_RXINTA    0x20
 | 
					
						
							|  |  |  | #define R_IPEN    4
 | 
					
						
							|  |  |  | #define R_TXCTRL1 5
 | 
					
						
							|  |  |  | #define R_TXCTRL2 6
 | 
					
						
							|  |  |  | #define R_BC      7
 | 
					
						
							|  |  |  | #define R_RXBUF   8
 | 
					
						
							|  |  |  | #define R_RXCTRL  9
 | 
					
						
							|  |  |  | #define R_MISC   10
 | 
					
						
							|  |  |  | #define R_MISC1  11
 | 
					
						
							|  |  |  | #define R_BRGLO  12
 | 
					
						
							|  |  |  | #define R_BRGHI  13
 | 
					
						
							|  |  |  | #define R_MISC1I 14
 | 
					
						
							|  |  |  | #define R_EXTINT 15
 | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | static void handle_kbd_command(ESCCChannelState *s, int val); | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  | static int serial_can_receive(void *opaque); | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | static void serial_receive_byte(ESCCChannelState *s, int ch); | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-26 00:50:04 +02:00
										 |  |  | static int reg_shift(ESCCState *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return s->bit_swap ? s->it_shift + 1 : s->it_shift; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int chn_shift(ESCCState *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return s->bit_swap ? s->it_shift : s->it_shift + 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-04-18 19:21:38 +00:00
										 |  |  | static void clear_queue(void *opaque) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     ESCCChannelState *s = opaque; | 
					
						
							|  |  |  |     ESCCSERIOQueue *q = &s->queue; | 
					
						
							| 
									
										
										
										
											2007-04-18 19:21:38 +00:00
										 |  |  |     q->rptr = q->wptr = q->count = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  | static void put_queue(void *opaque, int b) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     ESCCChannelState *s = opaque; | 
					
						
							|  |  |  |     ESCCSERIOQueue *q = &s->queue; | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-07 11:01:05 +00:00
										 |  |  |     trace_escc_put_queue(CHN_C(s), b); | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     if (q->count >= ESCC_SERIO_QUEUE_SIZE) { | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |     q->data[q->wptr] = b; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     if (++q->wptr == ESCC_SERIO_QUEUE_SIZE) { | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |         q->wptr = 0; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |     q->count++; | 
					
						
							|  |  |  |     serial_receive_byte(s, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static uint32_t get_queue(void *opaque) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     ESCCChannelState *s = opaque; | 
					
						
							|  |  |  |     ESCCSERIOQueue *q = &s->queue; | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |     int val; | 
					
						
							| 
									
										
										
										
											2007-09-17 08:09:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |     if (q->count == 0) { | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         val = q->data[q->rptr]; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |         if (++q->rptr == ESCC_SERIO_QUEUE_SIZE) { | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |             q->rptr = 0; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |         q->count--; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-08-07 11:01:05 +00:00
										 |  |  |     trace_escc_get_queue(CHN_C(s), val); | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |     if (q->count > 0) | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         serial_receive_byte(s, 0); | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |     return val; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | static int escc_update_irq_chn(ESCCChannelState *s) | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-08-15 16:04:41 +02:00
										 |  |  |     if ((((s->wregs[W_INTR] & INTR_TXINT) && (s->txint == 1)) || | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |          // tx ints enabled, pending
 | 
					
						
							|  |  |  |          ((((s->wregs[W_INTR] & INTR_RXMODEMSK) == INTR_RXINT1ST) || | 
					
						
							|  |  |  |            ((s->wregs[W_INTR] & INTR_RXMODEMSK) == INTR_RXINTALL)) && | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |           s->rxint == 1) || // rx ints enabled, pending
 | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |          ((s->wregs[W_EXTINT] & EXTINT_BRKINT) && | 
					
						
							|  |  |  |           (s->rregs[R_STATUS] & STATUS_BRK)))) { // break int e&p
 | 
					
						
							| 
									
										
										
										
											2006-09-09 11:38:11 +00:00
										 |  |  |         return 1; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-09-09 11:38:11 +00:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | static void escc_update_irq(ESCCChannelState *s) | 
					
						
							| 
									
										
										
										
											2006-09-09 11:38:11 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int irq; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |     irq = escc_update_irq_chn(s); | 
					
						
							|  |  |  |     irq |= escc_update_irq_chn(s->otherchn); | 
					
						
							| 
									
										
										
										
											2006-09-09 11:38:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-07 11:01:05 +00:00
										 |  |  |     trace_escc_update_irq(irq); | 
					
						
							| 
									
										
										
										
											2007-04-07 18:14:41 +00:00
										 |  |  |     qemu_set_irq(s->irq, irq); | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | static void escc_reset_chn(ESCCChannelState *s) | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     s->reg = 0; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     for (i = 0; i < ESCC_SERIAL_REGS; i++) { | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         s->rregs[i] = 0; | 
					
						
							|  |  |  |         s->wregs[i] = 0; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     s->wregs[W_TXCTRL1] = TXCTRL1_1STOP; // 1X divisor, 1 stop bit, no parity
 | 
					
						
							|  |  |  |     s->wregs[W_MINTR] = MINTR_RST_ALL; | 
					
						
							|  |  |  |     s->wregs[W_CLOCK] = CLOCK_TRXC; // Synch mode tx clock = TRxC
 | 
					
						
							|  |  |  |     s->wregs[W_MISC2] = MISC2_PLLDIS; // PLL disabled
 | 
					
						
							|  |  |  |     s->wregs[W_EXTINT] = EXTINT_DCD | EXTINT_SYNCINT | EXTINT_CTSINT | | 
					
						
							|  |  |  |         EXTINT_TXUNDRN | EXTINT_BRKINT; // Enable most interrupts
 | 
					
						
							| 
									
										
										
										
											2007-12-04 20:58:31 +00:00
										 |  |  |     if (s->disabled) | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |         s->rregs[R_STATUS] = STATUS_TXEMPTY | STATUS_DCD | STATUS_SYNC | | 
					
						
							|  |  |  |             STATUS_CTS | STATUS_TXUNDRN; | 
					
						
							| 
									
										
										
										
											2007-12-04 20:58:31 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |         s->rregs[R_STATUS] = STATUS_TXEMPTY | STATUS_TXUNDRN; | 
					
						
							| 
									
										
										
										
											2007-12-27 20:24:15 +00:00
										 |  |  |     s->rregs[R_SPEC] = SPEC_BITS8 | SPEC_ALLSENT; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     s->rx = s->tx = 0; | 
					
						
							|  |  |  |     s->rxint = s->txint = 0; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:38:11 +00:00
										 |  |  |     s->rxint_under_svc = s->txint_under_svc = 0; | 
					
						
							| 
									
										
										
										
											2007-09-23 11:48:47 +00:00
										 |  |  |     s->e0_mode = s->led_mode = s->caps_lock_mode = s->num_lock_mode = 0; | 
					
						
							| 
									
										
										
										
											2007-04-18 19:21:38 +00:00
										 |  |  |     clear_queue(s); | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-24 16:07:10 +00:00
										 |  |  | static void escc_reset(DeviceState *d) | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-24 21:30:40 +02:00
										 |  |  |     ESCCState *s = ESCC(d); | 
					
						
							| 
									
										
										
										
											2009-10-24 16:07:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |     escc_reset_chn(&s->chn[0]); | 
					
						
							|  |  |  |     escc_reset_chn(&s->chn[1]); | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | static inline void set_rxint(ESCCChannelState *s) | 
					
						
							| 
									
										
										
										
											2005-12-05 20:31:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     s->rxint = 1; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     /* XXX: missing daisy chainnig: escc_chn_b rx should have a lower priority
 | 
					
						
							| 
									
										
										
										
											2010-08-15 16:04:41 +02:00
										 |  |  |        than chn_a rx/tx/special_condition service*/ | 
					
						
							|  |  |  |     s->rxint_under_svc = 1; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     if (s->chn == escc_chn_a) { | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |         s->rregs[R_INTR] |= INTR_RXINTA; | 
					
						
							| 
									
										
										
										
											2010-08-15 16:04:41 +02:00
										 |  |  |         if (s->wregs[W_MINTR] & MINTR_STATUSHI) | 
					
						
							|  |  |  |             s->otherchn->rregs[R_IVEC] = IVEC_HIRXINTA; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             s->otherchn->rregs[R_IVEC] = IVEC_LORXINTA; | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |         s->otherchn->rregs[R_INTR] |= INTR_RXINTB; | 
					
						
							| 
									
										
										
										
											2010-08-15 16:04:41 +02:00
										 |  |  |         if (s->wregs[W_MINTR] & MINTR_STATUSHI) | 
					
						
							|  |  |  |             s->rregs[R_IVEC] = IVEC_HIRXINTB; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             s->rregs[R_IVEC] = IVEC_LORXINTB; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |     escc_update_irq(s); | 
					
						
							| 
									
										
										
										
											2005-12-05 20:31:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | static inline void set_txint(ESCCChannelState *s) | 
					
						
							| 
									
										
										
										
											2008-01-17 21:07:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     s->txint = 1; | 
					
						
							|  |  |  |     if (!s->rxint_under_svc) { | 
					
						
							|  |  |  |         s->txint_under_svc = 1; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |         if (s->chn == escc_chn_a) { | 
					
						
							| 
									
										
										
										
											2011-01-27 08:21:35 +01:00
										 |  |  |             if (s->wregs[W_INTR] & INTR_TXINT) { | 
					
						
							|  |  |  |                 s->rregs[R_INTR] |= INTR_TXINTA; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2008-01-17 21:07:04 +00:00
										 |  |  |             if (s->wregs[W_MINTR] & MINTR_STATUSHI) | 
					
						
							|  |  |  |                 s->otherchn->rregs[R_IVEC] = IVEC_HITXINTA; | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 s->otherchn->rregs[R_IVEC] = IVEC_LOTXINTA; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             s->rregs[R_IVEC] = IVEC_TXINTB; | 
					
						
							| 
									
										
										
										
											2011-01-27 08:21:35 +01:00
										 |  |  |             if (s->wregs[W_INTR] & INTR_TXINT) { | 
					
						
							|  |  |  |                 s->otherchn->rregs[R_INTR] |= INTR_TXINTB; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2008-01-17 21:07:04 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |     escc_update_irq(s); | 
					
						
							| 
									
										
										
										
											2010-08-15 16:04:41 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-01-17 21:07:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | static inline void clr_rxint(ESCCChannelState *s) | 
					
						
							| 
									
										
										
										
											2008-01-17 21:07:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     s->rxint = 0; | 
					
						
							|  |  |  |     s->rxint_under_svc = 0; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     if (s->chn == escc_chn_a) { | 
					
						
							| 
									
										
										
										
											2008-01-17 21:07:04 +00:00
										 |  |  |         if (s->wregs[W_MINTR] & MINTR_STATUSHI) | 
					
						
							|  |  |  |             s->otherchn->rregs[R_IVEC] = IVEC_HINOINT; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             s->otherchn->rregs[R_IVEC] = IVEC_LONOINT; | 
					
						
							|  |  |  |         s->rregs[R_INTR] &= ~INTR_RXINTA; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         if (s->wregs[W_MINTR] & MINTR_STATUSHI) | 
					
						
							|  |  |  |             s->rregs[R_IVEC] = IVEC_HINOINT; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             s->rregs[R_IVEC] = IVEC_LONOINT; | 
					
						
							|  |  |  |         s->otherchn->rregs[R_INTR] &= ~INTR_RXINTB; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (s->txint) | 
					
						
							|  |  |  |         set_txint(s); | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |     escc_update_irq(s); | 
					
						
							| 
									
										
										
										
											2008-01-17 21:07:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | static inline void clr_txint(ESCCChannelState *s) | 
					
						
							| 
									
										
										
										
											2005-12-05 20:31:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     s->txint = 0; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:38:11 +00:00
										 |  |  |     s->txint_under_svc = 0; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     if (s->chn == escc_chn_a) { | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |         if (s->wregs[W_MINTR] & MINTR_STATUSHI) | 
					
						
							|  |  |  |             s->otherchn->rregs[R_IVEC] = IVEC_HINOINT; | 
					
						
							| 
									
										
										
										
											2007-04-20 19:35:25 +00:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |             s->otherchn->rregs[R_IVEC] = IVEC_LONOINT; | 
					
						
							|  |  |  |         s->rregs[R_INTR] &= ~INTR_TXINTA; | 
					
						
							| 
									
										
										
										
											2007-04-20 19:35:25 +00:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2010-08-15 16:04:41 +02:00
										 |  |  |         s->otherchn->rregs[R_INTR] &= ~INTR_TXINTB; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |         if (s->wregs[W_MINTR] & MINTR_STATUSHI) | 
					
						
							|  |  |  |             s->rregs[R_IVEC] = IVEC_HINOINT; | 
					
						
							| 
									
										
										
										
											2007-04-20 19:35:25 +00:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |             s->rregs[R_IVEC] = IVEC_LONOINT; | 
					
						
							|  |  |  |         s->otherchn->rregs[R_INTR] &= ~INTR_TXINTB; | 
					
						
							| 
									
										
										
										
											2007-04-20 19:35:25 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-09-09 11:38:11 +00:00
										 |  |  |     if (s->rxint) | 
					
						
							|  |  |  |         set_rxint(s); | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |     escc_update_irq(s); | 
					
						
							| 
									
										
										
										
											2005-12-05 20:31:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | static void escc_update_parameters(ESCCChannelState *s) | 
					
						
							| 
									
										
										
										
											2006-09-09 12:17:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int speed, parity, data_bits, stop_bits; | 
					
						
							|  |  |  |     QEMUSerialSetParams ssp; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     if (!qemu_chr_fe_backend_connected(&s->chr) || s->type != escc_serial) | 
					
						
							| 
									
										
										
										
											2006-09-09 12:17:15 +00:00
										 |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     if (s->wregs[W_TXCTRL1] & TXCTRL1_PAREN) { | 
					
						
							|  |  |  |         if (s->wregs[W_TXCTRL1] & TXCTRL1_PAREV) | 
					
						
							| 
									
										
										
										
											2006-09-09 12:17:15 +00:00
										 |  |  |             parity = 'E'; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             parity = 'O'; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         parity = 'N'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     if ((s->wregs[W_TXCTRL1] & TXCTRL1_STPMSK) == TXCTRL1_2STOP) | 
					
						
							| 
									
										
										
										
											2006-09-09 12:17:15 +00:00
										 |  |  |         stop_bits = 2; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         stop_bits = 1; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     switch (s->wregs[W_TXCTRL2] & TXCTRL2_BITMSK) { | 
					
						
							|  |  |  |     case TXCTRL2_5BITS: | 
					
						
							| 
									
										
										
										
											2006-09-09 12:17:15 +00:00
										 |  |  |         data_bits = 5; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     case TXCTRL2_7BITS: | 
					
						
							| 
									
										
										
										
											2006-09-09 12:17:15 +00:00
										 |  |  |         data_bits = 7; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     case TXCTRL2_6BITS: | 
					
						
							| 
									
										
										
										
											2006-09-09 12:17:15 +00:00
										 |  |  |         data_bits = 6; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     case TXCTRL2_8BITS: | 
					
						
							| 
									
										
										
										
											2006-09-09 12:17:15 +00:00
										 |  |  |         data_bits = 8; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |     speed = s->clock / ((s->wregs[W_BRGLO] | (s->wregs[W_BRGHI] << 8)) + 2); | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     switch (s->wregs[W_TXCTRL1] & TXCTRL1_CLKMSK) { | 
					
						
							|  |  |  |     case TXCTRL1_CLK1X: | 
					
						
							| 
									
										
										
										
											2006-09-09 12:17:15 +00:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     case TXCTRL1_CLK16X: | 
					
						
							| 
									
										
										
										
											2006-09-09 12:17:15 +00:00
										 |  |  |         speed /= 16; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     case TXCTRL1_CLK32X: | 
					
						
							| 
									
										
										
										
											2006-09-09 12:17:15 +00:00
										 |  |  |         speed /= 32; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     case TXCTRL1_CLK64X: | 
					
						
							| 
									
										
										
										
											2006-09-09 12:17:15 +00:00
										 |  |  |         speed /= 64; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ssp.speed = speed; | 
					
						
							|  |  |  |     ssp.parity = parity; | 
					
						
							|  |  |  |     ssp.data_bits = data_bits; | 
					
						
							|  |  |  |     ssp.stop_bits = stop_bits; | 
					
						
							| 
									
										
										
										
											2011-08-07 11:01:05 +00:00
										 |  |  |     trace_escc_update_parameters(CHN_C(s), speed, parity, data_bits, stop_bits); | 
					
						
							| 
									
										
										
										
											2016-10-22 12:52:55 +03:00
										 |  |  |     qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp); | 
					
						
							| 
									
										
										
										
											2006-09-09 12:17:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-23 12:30:10 +02:00
										 |  |  | static void escc_mem_write(void *opaque, hwaddr addr, | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |                            uint64_t val, unsigned size) | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-25 15:02:38 +02:00
										 |  |  |     ESCCState *serial = opaque; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     ESCCChannelState *s; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     uint32_t saddr; | 
					
						
							|  |  |  |     int newreg, channel; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     val &= 0xff; | 
					
						
							| 
									
										
										
										
											2019-05-26 00:50:04 +02:00
										 |  |  |     saddr = (addr >> reg_shift(serial)) & 1; | 
					
						
							|  |  |  |     channel = (addr >> chn_shift(serial)) & 1; | 
					
						
							| 
									
										
										
										
											2007-06-25 19:56:13 +00:00
										 |  |  |     s = &serial->chn[channel]; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     switch (saddr) { | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     case SERIAL_CTRL: | 
					
						
							| 
									
										
										
										
											2011-08-07 11:01:05 +00:00
										 |  |  |         trace_escc_mem_writeb_ctrl(CHN_C(s), s->reg, val & 0xff); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         newreg = 0; | 
					
						
							|  |  |  |         switch (s->reg) { | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |         case W_CMD: | 
					
						
							|  |  |  |             newreg = val & CMD_PTR_MASK; | 
					
						
							|  |  |  |             val &= CMD_CMD_MASK; | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |             switch (val) { | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |             case CMD_HI: | 
					
						
							|  |  |  |                 newreg |= CMD_HI; | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |             case CMD_CLR_TXINT: | 
					
						
							| 
									
										
										
										
											2005-12-05 20:31:52 +00:00
										 |  |  |                 clr_txint(s); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |             case CMD_CLR_IUS: | 
					
						
							| 
									
										
										
										
											2010-08-15 16:04:41 +02:00
										 |  |  |                 if (s->rxint_under_svc) { | 
					
						
							|  |  |  |                     s->rxint_under_svc = 0; | 
					
						
							|  |  |  |                     if (s->txint) { | 
					
						
							|  |  |  |                         set_txint(s); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } else if (s->txint_under_svc) { | 
					
						
							|  |  |  |                     s->txint_under_svc = 0; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 escc_update_irq(s); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |         case W_INTR ... W_RXCTRL: | 
					
						
							|  |  |  |         case W_SYNC1 ... W_TXBUF: | 
					
						
							|  |  |  |         case W_MISC1 ... W_CLOCK: | 
					
						
							|  |  |  |         case W_MISC2 ... W_EXTINT: | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |             s->wregs[s->reg] = val; | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |         case W_TXCTRL1: | 
					
						
							|  |  |  |         case W_TXCTRL2: | 
					
						
							| 
									
										
										
										
											2008-04-12 08:47:27 +00:00
										 |  |  |             s->wregs[s->reg] = val; | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |             escc_update_parameters(s); | 
					
						
							| 
									
										
										
										
											2008-04-12 08:47:27 +00:00
										 |  |  |             break; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |         case W_BRGLO: | 
					
						
							|  |  |  |         case W_BRGHI: | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |             s->wregs[s->reg] = val; | 
					
						
							| 
									
										
										
										
											2008-04-12 08:47:27 +00:00
										 |  |  |             s->rregs[s->reg] = val; | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |             escc_update_parameters(s); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |             break; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |         case W_MINTR: | 
					
						
							|  |  |  |             switch (val & MINTR_RST_MASK) { | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |             case 0: | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |             case MINTR_RST_B: | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |                 escc_reset_chn(&serial->chn[0]); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |                 return; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |             case MINTR_RST_A: | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |                 escc_reset_chn(&serial->chn[1]); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |                 return; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |             case MINTR_RST_ALL: | 
					
						
							| 
									
										
										
										
											2013-07-24 21:30:40 +02:00
										 |  |  |                 escc_reset(DEVICE(serial)); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (s->reg == 0) | 
					
						
							|  |  |  |             s->reg = newreg; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             s->reg = 0; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     case SERIAL_DATA: | 
					
						
							| 
									
										
										
										
											2011-08-07 11:01:05 +00:00
										 |  |  |         trace_escc_mem_writeb_data(CHN_C(s), val); | 
					
						
							| 
									
										
										
										
											2019-04-19 11:40:41 -04:00
										 |  |  |         /*
 | 
					
						
							|  |  |  |          * Lower the irq when data is written to the Tx buffer and no other | 
					
						
							|  |  |  |          * interrupts are currently pending. The irq will be raised again once | 
					
						
							|  |  |  |          * the Tx buffer becomes empty below. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         s->txint = 0; | 
					
						
							|  |  |  |         escc_update_irq(s); | 
					
						
							| 
									
										
										
										
											2007-08-11 07:54:26 +00:00
										 |  |  |         s->tx = val; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |         if (s->wregs[W_TXCTRL2] & TXCTRL2_TXEN) { // tx enabled
 | 
					
						
							| 
									
										
										
										
											2017-07-06 15:08:52 +03:00
										 |  |  |             if (qemu_chr_fe_backend_connected(&s->chr)) { | 
					
						
							| 
									
										
										
										
											2016-09-06 14:56:04 +01:00
										 |  |  |                 /* XXX this blocks entire thread. Rewrite to use
 | 
					
						
							|  |  |  |                  * qemu_chr_fe_write and background I/O callbacks */ | 
					
						
							| 
									
										
										
										
											2016-10-22 12:52:55 +03:00
										 |  |  |                 qemu_chr_fe_write_all(&s->chr, &s->tx, 1); | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |             } else if (s->type == escc_kbd && !s->disabled) { | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |                 handle_kbd_command(s, val); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |         s->rregs[R_STATUS] |= STATUS_TXEMPTY; // Tx buffer empty
 | 
					
						
							|  |  |  |         s->rregs[R_SPEC] |= SPEC_ALLSENT; // All sent
 | 
					
						
							| 
									
										
										
										
											2007-08-11 07:54:26 +00:00
										 |  |  |         set_txint(s); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     default: | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-23 12:30:10 +02:00
										 |  |  | static uint64_t escc_mem_read(void *opaque, hwaddr addr, | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |                               unsigned size) | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-25 15:02:38 +02:00
										 |  |  |     ESCCState *serial = opaque; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     ESCCChannelState *s; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     uint32_t saddr; | 
					
						
							|  |  |  |     uint32_t ret; | 
					
						
							|  |  |  |     int channel; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-26 00:50:04 +02:00
										 |  |  |     saddr = (addr >> reg_shift(serial)) & 1; | 
					
						
							|  |  |  |     channel = (addr >> chn_shift(serial)) & 1; | 
					
						
							| 
									
										
										
										
											2007-06-25 19:56:13 +00:00
										 |  |  |     s = &serial->chn[channel]; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     switch (saddr) { | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     case SERIAL_CTRL: | 
					
						
							| 
									
										
										
										
											2011-08-07 11:01:05 +00:00
										 |  |  |         trace_escc_mem_readb_ctrl(CHN_C(s), s->reg, s->rregs[s->reg]); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         ret = s->rregs[s->reg]; | 
					
						
							|  |  |  |         s->reg = 0; | 
					
						
							|  |  |  |         return ret; | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     case SERIAL_DATA: | 
					
						
							|  |  |  |         s->rregs[R_STATUS] &= ~STATUS_RXAV; | 
					
						
							| 
									
										
										
										
											2005-12-05 20:31:52 +00:00
										 |  |  |         clr_rxint(s); | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |         if (s->type == escc_kbd || s->type == escc_mouse) { | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |             ret = get_queue(s); | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |             ret = s->rx; | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-08-07 11:01:05 +00:00
										 |  |  |         trace_escc_mem_readb_data(CHN_C(s), ret); | 
					
						
							| 
									
										
										
										
											2016-10-22 12:52:59 +03:00
										 |  |  |         qemu_chr_fe_accept_input(&s->chr); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         return ret; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     default: | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  | static const MemoryRegionOps escc_mem_ops = { | 
					
						
							|  |  |  |     .read = escc_mem_read, | 
					
						
							|  |  |  |     .write = escc_mem_write, | 
					
						
							|  |  |  |     .endianness = DEVICE_NATIVE_ENDIAN, | 
					
						
							|  |  |  |     .valid = { | 
					
						
							|  |  |  |         .min_access_size = 1, | 
					
						
							|  |  |  |         .max_access_size = 1, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | static int serial_can_receive(void *opaque) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     ESCCChannelState *s = opaque; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:38:11 +00:00
										 |  |  |     int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     if (((s->wregs[W_RXCTRL] & RXCTRL_RXEN) == 0) // Rx not enabled
 | 
					
						
							|  |  |  |         || ((s->rregs[R_STATUS] & STATUS_RXAV) == STATUS_RXAV)) | 
					
						
							|  |  |  |         // char already available
 | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         ret = 0; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         ret = 1; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:38:11 +00:00
										 |  |  |     return ret; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | static void serial_receive_byte(ESCCChannelState *s, int ch) | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-08-07 11:01:05 +00:00
										 |  |  |     trace_escc_serial_receive_byte(CHN_C(s), ch); | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     s->rregs[R_STATUS] |= STATUS_RXAV; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     s->rx = ch; | 
					
						
							| 
									
										
										
										
											2005-12-05 20:31:52 +00:00
										 |  |  |     set_rxint(s); | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | static void serial_receive_break(ESCCChannelState *s) | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-12-10 20:05:09 +00:00
										 |  |  |     s->rregs[R_STATUS] |= STATUS_BRK; | 
					
						
							| 
									
										
										
										
											2009-01-12 17:38:28 +00:00
										 |  |  |     escc_update_irq(s); | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void serial_receive1(void *opaque, const uint8_t *buf, int size) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     ESCCChannelState *s = opaque; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     serial_receive_byte(s, buf[0]); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void serial_event(void *opaque, int event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     ESCCChannelState *s = opaque; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     if (event == CHR_EVENT_BREAK) | 
					
						
							|  |  |  |         serial_receive_break(s); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-24 16:07:10 +00:00
										 |  |  | static const VMStateDescription vmstate_escc_chn = { | 
					
						
							|  |  |  |     .name ="escc_chn", | 
					
						
							|  |  |  |     .version_id = 2, | 
					
						
							|  |  |  |     .minimum_version_id = 1, | 
					
						
							| 
									
										
										
										
											2014-04-16 15:24:04 +02:00
										 |  |  |     .fields = (VMStateField[]) { | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |         VMSTATE_UINT32(vmstate_dummy, ESCCChannelState), | 
					
						
							|  |  |  |         VMSTATE_UINT32(reg, ESCCChannelState), | 
					
						
							|  |  |  |         VMSTATE_UINT32(rxint, ESCCChannelState), | 
					
						
							|  |  |  |         VMSTATE_UINT32(txint, ESCCChannelState), | 
					
						
							|  |  |  |         VMSTATE_UINT32(rxint_under_svc, ESCCChannelState), | 
					
						
							|  |  |  |         VMSTATE_UINT32(txint_under_svc, ESCCChannelState), | 
					
						
							|  |  |  |         VMSTATE_UINT8(rx, ESCCChannelState), | 
					
						
							|  |  |  |         VMSTATE_UINT8(tx, ESCCChannelState), | 
					
						
							|  |  |  |         VMSTATE_BUFFER(wregs, ESCCChannelState), | 
					
						
							|  |  |  |         VMSTATE_BUFFER(rregs, ESCCChannelState), | 
					
						
							| 
									
										
										
										
											2009-10-24 16:07:10 +00:00
										 |  |  |         VMSTATE_END_OF_LIST() | 
					
						
							| 
									
										
										
										
											2006-09-09 11:38:11 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-10-24 16:07:10 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-24 16:07:10 +00:00
										 |  |  | static const VMStateDescription vmstate_escc = { | 
					
						
							|  |  |  |     .name ="escc", | 
					
						
							|  |  |  |     .version_id = 2, | 
					
						
							|  |  |  |     .minimum_version_id = 1, | 
					
						
							| 
									
										
										
										
											2014-04-16 15:24:04 +02:00
										 |  |  |     .fields = (VMStateField[]) { | 
					
						
							| 
									
										
										
										
											2013-06-25 15:02:38 +02:00
										 |  |  |         VMSTATE_STRUCT_ARRAY(chn, ESCCState, 2, 2, vmstate_escc_chn, | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |                              ESCCChannelState), | 
					
						
							| 
									
										
										
										
											2009-10-24 16:07:10 +00:00
										 |  |  |         VMSTATE_END_OF_LIST() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-25 13:16:21 +01:00
										 |  |  | static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src, | 
					
						
							|  |  |  |                                 InputEvent *evt) | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     ESCCChannelState *s = (ESCCChannelState *)dev; | 
					
						
							| 
									
										
										
										
											2014-03-25 13:16:21 +01:00
										 |  |  |     int qcode, keycode; | 
					
						
							| 
									
										
										
										
											2016-03-03 09:16:49 -07:00
										 |  |  |     InputKeyEvent *key; | 
					
						
							| 
									
										
										
										
											2014-03-25 13:16:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 16:34:58 -06:00
										 |  |  |     assert(evt->type == INPUT_EVENT_KIND_KEY); | 
					
						
							| 
									
										
											  
											
												qapi: Don't special-case simple union wrappers
Simple unions were carrying a special case that hid their 'data'
QMP member from the resulting C struct, via the hack method
QAPISchemaObjectTypeVariant.simple_union_type().  But by using
the work we started by unboxing flat union and alternate
branches, coupled with the ability to visit the members of an
implicit type, we can now expose the simple union's implicit
type in qapi-types.h:
| struct q_obj_ImageInfoSpecificQCow2_wrapper {
|     ImageInfoSpecificQCow2 *data;
| };
|
| struct q_obj_ImageInfoSpecificVmdk_wrapper {
|     ImageInfoSpecificVmdk *data;
| };
...
| struct ImageInfoSpecific {
|     ImageInfoSpecificKind type;
|     union { /* union tag is @type */
|         void *data;
|-        ImageInfoSpecificQCow2 *qcow2;
|-        ImageInfoSpecificVmdk *vmdk;
|+        q_obj_ImageInfoSpecificQCow2_wrapper qcow2;
|+        q_obj_ImageInfoSpecificVmdk_wrapper vmdk;
|     } u;
| };
Doing this removes asymmetry between QAPI's QMP side and its
C side (both sides now expose 'data'), and means that the
treatment of a simple union as sugar for a flat union is now
equivalent in both languages (previously the two approaches used
a different layer of dereferencing, where the simple union could
be converted to a flat union with equivalent C layout but
different {} on the wire, or to an equivalent QMP wire form
but with different C representation).  Using the implicit type
also lets us get rid of the simple_union_type() hack.
Of course, now all clients of simple unions have to adjust from
using su->u.member to using su->u.member.data; while this touches
a number of files in the tree, some earlier cleanup patches
helped minimize the change to the initialization of a temporary
variable rather than every single member access.  The generated
qapi-visit.c code is also affected by the layout change:
|@@ -7393,10 +7393,10 @@ void visit_type_ImageInfoSpecific_member
|     }
|     switch (obj->type) {
|     case IMAGE_INFO_SPECIFIC_KIND_QCOW2:
|-        visit_type_ImageInfoSpecificQCow2(v, "data", &obj->u.qcow2, &err);
|+        visit_type_q_obj_ImageInfoSpecificQCow2_wrapper_members(v, &obj->u.qcow2, &err);
|         break;
|     case IMAGE_INFO_SPECIFIC_KIND_VMDK:
|-        visit_type_ImageInfoSpecificVmdk(v, "data", &obj->u.vmdk, &err);
|+        visit_type_q_obj_ImageInfoSpecificVmdk_wrapper_members(v, &obj->u.vmdk, &err);
|         break;
|     default:
|         abort();
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1458254921-17042-13-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
											
										 
											2016-03-17 16:48:37 -06:00
										 |  |  |     key = evt->u.key.data; | 
					
						
							| 
									
										
										
										
											2016-03-03 09:16:49 -07:00
										 |  |  |     qcode = qemu_input_key_value_to_qcode(key->key); | 
					
						
							| 
									
										
										
										
											2017-08-24 10:46:08 +02:00
										 |  |  |     trace_escc_sunkbd_event_in(qcode, QKeyCode_str(qcode), | 
					
						
							| 
									
										
										
										
											2016-03-03 09:16:49 -07:00
										 |  |  |                                key->down); | 
					
						
							| 
									
										
										
										
											2014-03-25 13:16:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (qcode == Q_KEY_CODE_CAPS_LOCK) { | 
					
						
							| 
									
										
										
										
											2016-03-03 09:16:49 -07:00
										 |  |  |         if (key->down) { | 
					
						
							| 
									
										
										
										
											2014-03-25 13:16:21 +01:00
										 |  |  |             s->caps_lock_mode ^= 1; | 
					
						
							|  |  |  |             if (s->caps_lock_mode == 2) { | 
					
						
							|  |  |  |                 return; /* Drop second press */ | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             s->caps_lock_mode ^= 2; | 
					
						
							|  |  |  |             if (s->caps_lock_mode == 3) { | 
					
						
							|  |  |  |                 return; /* Drop first release */ | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2007-09-21 19:09:35 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-03-25 13:16:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (qcode == Q_KEY_CODE_NUM_LOCK) { | 
					
						
							| 
									
										
										
										
											2016-03-03 09:16:49 -07:00
										 |  |  |         if (key->down) { | 
					
						
							| 
									
										
										
										
											2014-03-25 13:16:21 +01:00
										 |  |  |             s->num_lock_mode ^= 1; | 
					
						
							|  |  |  |             if (s->num_lock_mode == 2) { | 
					
						
							|  |  |  |                 return; /* Drop second press */ | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             s->num_lock_mode ^= 2; | 
					
						
							|  |  |  |             if (s->num_lock_mode == 3) { | 
					
						
							|  |  |  |                 return; /* Drop first release */ | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-17 16:41:16 +00:00
										 |  |  |     if (qcode > qemu_input_map_qcode_to_sun_len) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     keycode = qemu_input_map_qcode_to_sun[qcode]; | 
					
						
							| 
									
										
										
										
											2016-03-03 09:16:49 -07:00
										 |  |  |     if (!key->down) { | 
					
						
							| 
									
										
										
										
											2014-03-25 13:16:21 +01:00
										 |  |  |         keycode |= 0x80; | 
					
						
							| 
									
										
										
										
											2007-09-21 19:09:35 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-03-25 13:16:21 +01:00
										 |  |  |     trace_escc_sunkbd_event_out(keycode); | 
					
						
							|  |  |  |     put_queue(s, keycode); | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-25 13:16:21 +01:00
										 |  |  | static QemuInputHandler sunkbd_handler = { | 
					
						
							|  |  |  |     .name  = "sun keyboard", | 
					
						
							|  |  |  |     .mask  = INPUT_EVENT_MASK_KEY, | 
					
						
							|  |  |  |     .event = sunkbd_handle_event, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  | static void handle_kbd_command(ESCCChannelState *s, int val) | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-08-07 11:01:05 +00:00
										 |  |  |     trace_escc_kbd_command(val); | 
					
						
							| 
									
										
										
										
											2007-09-21 19:09:35 +00:00
										 |  |  |     if (s->led_mode) { // Ignore led byte
 | 
					
						
							|  |  |  |         s->led_mode = 0; | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |     switch (val) { | 
					
						
							|  |  |  |     case 1: // Reset, return type code
 | 
					
						
							| 
									
										
										
										
											2007-04-18 19:21:38 +00:00
										 |  |  |         clear_queue(s); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         put_queue(s, 0xff); | 
					
						
							|  |  |  |         put_queue(s, 4); // Type 4
 | 
					
						
							|  |  |  |         put_queue(s, 0x7f); | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2007-09-21 19:09:35 +00:00
										 |  |  |     case 0xe: // Set leds
 | 
					
						
							|  |  |  |         s->led_mode = 1; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |     case 7: // Query layout
 | 
					
						
							| 
									
										
										
										
											2007-04-18 19:21:38 +00:00
										 |  |  |     case 0xf: | 
					
						
							|  |  |  |         clear_queue(s); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         put_queue(s, 0xfe); | 
					
						
							| 
									
										
										
										
											2014-05-06 14:11:16 +02:00
										 |  |  |         put_queue(s, 0x21); /*  en-us layout */ | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |     default: | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-16 21:08:06 +00:00
										 |  |  | static void sunmouse_event(void *opaque, | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |                                int dx, int dy, int dz, int buttons_state) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     ESCCChannelState *s = opaque; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     int ch; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-07 11:01:05 +00:00
										 |  |  |     trace_escc_sunmouse_event(dx, dy, buttons_state); | 
					
						
							| 
									
										
										
										
											2006-09-09 11:35:47 +00:00
										 |  |  |     ch = 0x80 | 0x7; /* protocol start byte, no buttons pressed */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (buttons_state & MOUSE_EVENT_LBUTTON) | 
					
						
							|  |  |  |         ch ^= 0x4; | 
					
						
							|  |  |  |     if (buttons_state & MOUSE_EVENT_MBUTTON) | 
					
						
							|  |  |  |         ch ^= 0x2; | 
					
						
							|  |  |  |     if (buttons_state & MOUSE_EVENT_RBUTTON) | 
					
						
							|  |  |  |         ch ^= 0x1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     put_queue(s, ch); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ch = dx; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ch > 127) | 
					
						
							| 
									
										
										
										
											2009-09-30 19:43:55 +02:00
										 |  |  |         ch = 127; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:35:47 +00:00
										 |  |  |     else if (ch < -127) | 
					
						
							| 
									
										
										
										
											2009-09-30 19:43:55 +02:00
										 |  |  |         ch = -127; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:35:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     put_queue(s, ch & 0xff); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ch = -dy; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ch > 127) | 
					
						
							| 
									
										
										
										
											2009-09-30 18:56:44 +00:00
										 |  |  |         ch = 127; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:35:47 +00:00
										 |  |  |     else if (ch < -127) | 
					
						
							| 
									
										
										
										
											2009-09-30 18:56:44 +00:00
										 |  |  |         ch = -127; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:35:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     put_queue(s, ch & 0xff); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // MSC protocol specify two extra motion bytes
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     put_queue(s, 0); | 
					
						
							|  |  |  |     put_queue(s, 0); | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-25 14:39:00 +08:00
										 |  |  | static void escc_init1(Object *obj) | 
					
						
							| 
									
										
										
										
											2009-07-15 08:51:32 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-25 14:39:00 +08:00
										 |  |  |     ESCCState *s = ESCC(obj); | 
					
						
							|  |  |  |     SysBusDevice *dev = SYS_BUS_DEVICE(obj); | 
					
						
							| 
									
										
										
										
											2009-07-15 08:51:32 +00:00
										 |  |  |     unsigned int i; | 
					
						
							| 
									
										
										
										
											2009-07-15 13:43:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |     for (i = 0; i < 2; i++) { | 
					
						
							| 
									
										
										
										
											2009-07-15 08:51:32 +00:00
										 |  |  |         sysbus_init_irq(dev, &s->chn[i].irq); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         s->chn[i].chn = 1 - i; | 
					
						
							| 
									
										
										
										
											2005-04-06 20:42:35 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     s->chn[0].otherchn = &s->chn[1]; | 
					
						
							|  |  |  |     s->chn[1].otherchn = &s->chn[0]; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-27 11:38:10 +02:00
										 |  |  |     sysbus_init_mmio(dev, &s->mmio); | 
					
						
							| 
									
										
										
										
											2016-05-25 14:39:00 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void escc_realize(DeviceState *dev, Error **errp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ESCCState *s = ESCC(dev); | 
					
						
							|  |  |  |     unsigned int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 15:58:18 +08:00
										 |  |  |     s->chn[0].disabled = s->disabled; | 
					
						
							|  |  |  |     s->chn[1].disabled = s->disabled; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     memory_region_init_io(&s->mmio, OBJECT(dev), &escc_mem_ops, s, "escc", | 
					
						
							|  |  |  |                           ESCC_SIZE << s->it_shift); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-25 14:39:00 +08:00
										 |  |  |     for (i = 0; i < 2; i++) { | 
					
						
							| 
									
										
										
										
											2017-07-06 15:08:52 +03:00
										 |  |  |         if (qemu_chr_fe_backend_connected(&s->chn[i].chr)) { | 
					
						
							| 
									
										
										
										
											2016-06-01 15:58:18 +08:00
										 |  |  |             s->chn[i].clock = s->frequency / 2; | 
					
						
							| 
									
										
										
										
											2016-10-22 12:52:55 +03:00
										 |  |  |             qemu_chr_fe_set_handlers(&s->chn[i].chr, serial_can_receive, | 
					
						
							| 
									
										
										
										
											2017-07-06 15:08:49 +03:00
										 |  |  |                                      serial_receive1, serial_event, NULL, | 
					
						
							| 
									
										
										
										
											2016-10-22 12:53:03 +03:00
										 |  |  |                                      &s->chn[i], NULL, true); | 
					
						
							| 
									
										
										
										
											2016-05-25 14:39:00 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     if (s->chn[0].type == escc_mouse) { | 
					
						
							| 
									
										
										
										
											2009-07-15 08:51:32 +00:00
										 |  |  |         qemu_add_mouse_event_handler(sunmouse_event, &s->chn[0], 0, | 
					
						
							|  |  |  |                                      "QEMU Sun Mouse"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-02-14 07:35:58 +01:00
										 |  |  |     if (s->chn[1].type == escc_kbd) { | 
					
						
							| 
									
										
										
										
											2014-03-25 13:16:21 +01:00
										 |  |  |         s->chn[1].hs = qemu_input_handler_register((DeviceState *)(&s->chn[1]), | 
					
						
							|  |  |  |                                                    &sunkbd_handler); | 
					
						
							| 
									
										
										
										
											2009-07-15 08:51:32 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-07-15 08:51:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-24 13:12:29 -06:00
										 |  |  | static Property escc_properties[] = { | 
					
						
							| 
									
										
										
										
											2013-06-25 15:02:38 +02:00
										 |  |  |     DEFINE_PROP_UINT32("frequency", ESCCState, frequency,   0), | 
					
						
							|  |  |  |     DEFINE_PROP_UINT32("it_shift",  ESCCState, it_shift,    0), | 
					
						
							| 
									
										
										
										
											2019-05-26 00:50:04 +02:00
										 |  |  |     DEFINE_PROP_BOOL("bit_swap",    ESCCState, bit_swap,    false), | 
					
						
							| 
									
										
										
										
											2013-06-25 15:02:38 +02:00
										 |  |  |     DEFINE_PROP_UINT32("disabled",  ESCCState, disabled,    0), | 
					
						
							|  |  |  |     DEFINE_PROP_UINT32("chnBtype",  ESCCState, chn[0].type, 0), | 
					
						
							|  |  |  |     DEFINE_PROP_UINT32("chnAtype",  ESCCState, chn[1].type, 0), | 
					
						
							|  |  |  |     DEFINE_PROP_CHR("chrB", ESCCState, chn[0].chr), | 
					
						
							|  |  |  |     DEFINE_PROP_CHR("chrA", ESCCState, chn[1].chr), | 
					
						
							| 
									
										
										
										
											2012-01-24 13:12:29 -06:00
										 |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void escc_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-07 21:34:16 -06:00
										 |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2012-01-24 13:12:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-07 21:34:16 -06:00
										 |  |  |     dc->reset = escc_reset; | 
					
						
							| 
									
										
										
										
											2016-05-25 14:39:00 +08:00
										 |  |  |     dc->realize = escc_realize; | 
					
						
							| 
									
										
										
										
											2011-12-07 21:34:16 -06:00
										 |  |  |     dc->vmsd = &vmstate_escc; | 
					
						
							|  |  |  |     dc->props = escc_properties; | 
					
						
							| 
									
										
										
										
											2015-09-26 18:22:05 +02:00
										 |  |  |     set_bit(DEVICE_CATEGORY_INPUT, dc->categories); | 
					
						
							| 
									
										
										
										
											2012-01-24 13:12:29 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-10 16:19:07 +01:00
										 |  |  | static const TypeInfo escc_info = { | 
					
						
							| 
									
										
										
										
											2013-07-24 21:30:40 +02:00
										 |  |  |     .name          = TYPE_ESCC, | 
					
						
							| 
									
										
										
										
											2011-12-07 21:34:16 -06:00
										 |  |  |     .parent        = TYPE_SYS_BUS_DEVICE, | 
					
						
							| 
									
										
										
										
											2013-06-25 15:02:38 +02:00
										 |  |  |     .instance_size = sizeof(ESCCState), | 
					
						
							| 
									
										
										
										
											2016-05-25 14:39:00 +08:00
										 |  |  |     .instance_init = escc_init1, | 
					
						
							| 
									
										
										
										
											2011-12-07 21:34:16 -06:00
										 |  |  |     .class_init    = escc_class_init, | 
					
						
							| 
									
										
										
										
											2009-07-15 08:51:32 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-09 15:20:55 +01:00
										 |  |  | static void escc_register_types(void) | 
					
						
							| 
									
										
										
										
											2009-07-15 08:51:32 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-07 21:34:16 -06:00
										 |  |  |     type_register_static(&escc_info); | 
					
						
							| 
									
										
										
										
											2009-07-15 08:51:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-09 15:20:55 +01:00
										 |  |  | type_init(escc_register_types) |