]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/mn10300/kernel/gdb-io-serial.c
MN10300: And Panasonic AM34 subarch and implement SMP
[mirror_ubuntu-artful-kernel.git] / arch / mn10300 / kernel / gdb-io-serial.c
1 /* 16550 serial driver for gdbstub I/O
2 *
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11 #include <linux/string.h>
12 #include <linux/kernel.h>
13 #include <linux/signal.h>
14 #include <linux/sched.h>
15 #include <linux/mm.h>
16 #include <linux/console.h>
17 #include <linux/init.h>
18 #include <linux/nmi.h>
19
20 #include <asm/pgtable.h>
21 #include <asm/system.h>
22 #include <asm/gdb-stub.h>
23 #include <asm/exceptions.h>
24 #include <asm/serial-regs.h>
25 #include <unit/serial.h>
26 #include <asm/smp.h>
27
28 /*
29 * initialise the GDB stub
30 */
31 void gdbstub_io_init(void)
32 {
33 u16 tmp;
34
35 /* set up the serial port */
36 GDBPORT_SERIAL_LCR = UART_LCR_WLEN8; /* 1N8 */
37 GDBPORT_SERIAL_FCR = (UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
38 UART_FCR_CLEAR_XMIT);
39
40 FLOWCTL_CLEAR(DTR);
41 FLOWCTL_SET(RTS);
42
43 gdbstub_io_set_baud(115200);
44
45 /* we want to get serial receive interrupts */
46 XIRQxICR(GDBPORT_SERIAL_IRQ) = 0;
47 tmp = XIRQxICR(GDBPORT_SERIAL_IRQ);
48
49 #if CONFIG_GDBSTUB_IRQ_LEVEL == 0
50 IVAR0 = EXCEP_IRQ_LEVEL0;
51 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 1
52 IVAR1 = EXCEP_IRQ_LEVEL1;
53 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 2
54 IVAR2 = EXCEP_IRQ_LEVEL2;
55 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 3
56 IVAR3 = EXCEP_IRQ_LEVEL3;
57 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 4
58 IVAR4 = EXCEP_IRQ_LEVEL4;
59 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 5
60 IVAR5 = EXCEP_IRQ_LEVEL5;
61 #else
62 #error "Unknown irq level for gdbstub."
63 #endif
64
65 set_intr_stub(NUM2EXCEP_IRQ_LEVEL(CONFIG_GDBSTUB_IRQ_LEVEL),
66 gdbstub_io_rx_handler);
67
68 XIRQxICR(GDBPORT_SERIAL_IRQ) &= ~GxICR_REQUEST;
69 XIRQxICR(GDBPORT_SERIAL_IRQ) =
70 GxICR_ENABLE | NUM2GxICR_LEVEL(CONFIG_GDBSTUB_IRQ_LEVEL);
71 tmp = XIRQxICR(GDBPORT_SERIAL_IRQ);
72
73 GDBPORT_SERIAL_IER = UART_IER_RDI | UART_IER_RLSI;
74
75 /* permit level 0 IRQs to take place */
76 local_change_intr_mask_level(NUM2EPSW_IM(CONFIG_GDBSTUB_IRQ_LEVEL + 1));
77 }
78
79 /*
80 * set up the GDB stub serial port baud rate timers
81 */
82 void gdbstub_io_set_baud(unsigned baud)
83 {
84 unsigned value;
85 u8 lcr;
86
87 value = 18432000 / 16 / baud;
88
89 lcr = GDBPORT_SERIAL_LCR;
90 GDBPORT_SERIAL_LCR |= UART_LCR_DLAB;
91 GDBPORT_SERIAL_DLL = value & 0xff;
92 GDBPORT_SERIAL_DLM = (value >> 8) & 0xff;
93 GDBPORT_SERIAL_LCR = lcr;
94 }
95
96 /*
97 * wait for a character to come from the debugger
98 */
99 int gdbstub_io_rx_char(unsigned char *_ch, int nonblock)
100 {
101 unsigned ix;
102 u8 ch, st;
103 #if defined(CONFIG_MN10300_WD_TIMER)
104 int cpu;
105 #endif
106
107 *_ch = 0xff;
108
109 if (gdbstub_rx_unget) {
110 *_ch = gdbstub_rx_unget;
111 gdbstub_rx_unget = 0;
112 return 0;
113 }
114
115 try_again:
116 /* pull chars out of the buffer */
117 ix = gdbstub_rx_outp;
118 barrier();
119 if (ix == gdbstub_rx_inp) {
120 if (nonblock)
121 return -EAGAIN;
122 #ifdef CONFIG_MN10300_WD_TIMER
123 for (cpu = 0; cpu < NR_CPUS; cpu++)
124 watchdog_alert_counter[cpu] = 0;
125 #endif
126 goto try_again;
127 }
128
129 ch = gdbstub_rx_buffer[ix++];
130 st = gdbstub_rx_buffer[ix++];
131 barrier();
132 gdbstub_rx_outp = ix & 0x00000fff;
133
134 if (st & UART_LSR_BI) {
135 gdbstub_proto("### GDB Rx Break Detected ###\n");
136 return -EINTR;
137 } else if (st & (UART_LSR_FE | UART_LSR_OE | UART_LSR_PE)) {
138 gdbstub_proto("### GDB Rx Error (st=%02x) ###\n", st);
139 return -EIO;
140 } else {
141 gdbstub_proto("### GDB Rx %02x (st=%02x) ###\n", ch, st);
142 *_ch = ch & 0x7f;
143 return 0;
144 }
145 }
146
147 /*
148 * send a character to the debugger
149 */
150 void gdbstub_io_tx_char(unsigned char ch)
151 {
152 FLOWCTL_SET(DTR);
153 LSR_WAIT_FOR(THRE);
154 /* FLOWCTL_WAIT_FOR(CTS); */
155
156 if (ch == 0x0a) {
157 GDBPORT_SERIAL_TX = 0x0d;
158 LSR_WAIT_FOR(THRE);
159 /* FLOWCTL_WAIT_FOR(CTS); */
160 }
161 GDBPORT_SERIAL_TX = ch;
162
163 FLOWCTL_CLEAR(DTR);
164 }
165
166 /*
167 * send a character to the debugger
168 */
169 void gdbstub_io_tx_flush(void)
170 {
171 LSR_WAIT_FOR(TEMT);
172 LSR_WAIT_FOR(THRE);
173 FLOWCTL_CLEAR(DTR);
174 }