drm: mm: fix range restricted allocations
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / mn10300 / kernel / gdb-io-serial.c
blobae663dc717e94ab807fbeb3169955e8fbaebd04b
1 /* 16550 serial driver for gdbstub I/O
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
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>
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>
28 * initialise the GDB stub
30 void gdbstub_io_init(void)
32 u16 tmp;
34 /* set up the serial port */
35 GDBPORT_SERIAL_LCR = UART_LCR_WLEN8; /* 1N8 */
36 GDBPORT_SERIAL_FCR = (UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
37 UART_FCR_CLEAR_XMIT);
39 FLOWCTL_CLEAR(DTR);
40 FLOWCTL_SET(RTS);
42 gdbstub_io_set_baud(115200);
44 /* we want to get serial receive interrupts */
45 XIRQxICR(GDBPORT_SERIAL_IRQ) = 0;
46 tmp = XIRQxICR(GDBPORT_SERIAL_IRQ);
48 IVAR0 = EXCEP_IRQ_LEVEL0;
49 set_intr_stub(EXCEP_IRQ_LEVEL0, gdbstub_io_rx_handler);
51 XIRQxICR(GDBPORT_SERIAL_IRQ) &= ~GxICR_REQUEST;
52 XIRQxICR(GDBPORT_SERIAL_IRQ) = GxICR_ENABLE | GxICR_LEVEL_0;
53 tmp = XIRQxICR(GDBPORT_SERIAL_IRQ);
55 GDBPORT_SERIAL_IER = UART_IER_RDI | UART_IER_RLSI;
57 /* permit level 0 IRQs to take place */
58 asm volatile(
59 " and %0,epsw \n"
60 " or %1,epsw \n"
62 : "i"(~EPSW_IM), "i"(EPSW_IE | EPSW_IM_1)
67 * set up the GDB stub serial port baud rate timers
69 void gdbstub_io_set_baud(unsigned baud)
71 unsigned value;
72 u8 lcr;
74 value = 18432000 / 16 / baud;
76 lcr = GDBPORT_SERIAL_LCR;
77 GDBPORT_SERIAL_LCR |= UART_LCR_DLAB;
78 GDBPORT_SERIAL_DLL = value & 0xff;
79 GDBPORT_SERIAL_DLM = (value >> 8) & 0xff;
80 GDBPORT_SERIAL_LCR = lcr;
84 * wait for a character to come from the debugger
86 int gdbstub_io_rx_char(unsigned char *_ch, int nonblock)
88 unsigned ix;
89 u8 ch, st;
91 *_ch = 0xff;
93 if (gdbstub_rx_unget) {
94 *_ch = gdbstub_rx_unget;
95 gdbstub_rx_unget = 0;
96 return 0;
99 try_again:
100 /* pull chars out of the buffer */
101 ix = gdbstub_rx_outp;
102 barrier();
103 if (ix == gdbstub_rx_inp) {
104 if (nonblock)
105 return -EAGAIN;
106 #ifdef CONFIG_MN10300_WD_TIMER
107 watchdog_alert_counter = 0;
108 #endif /* CONFIG_MN10300_WD_TIMER */
109 goto try_again;
112 ch = gdbstub_rx_buffer[ix++];
113 st = gdbstub_rx_buffer[ix++];
114 barrier();
115 gdbstub_rx_outp = ix & 0x00000fff;
117 if (st & UART_LSR_BI) {
118 gdbstub_proto("### GDB Rx Break Detected ###\n");
119 return -EINTR;
120 } else if (st & (UART_LSR_FE | UART_LSR_OE | UART_LSR_PE)) {
121 gdbstub_proto("### GDB Rx Error (st=%02x) ###\n", st);
122 return -EIO;
123 } else {
124 gdbstub_proto("### GDB Rx %02x (st=%02x) ###\n", ch, st);
125 *_ch = ch & 0x7f;
126 return 0;
131 * send a character to the debugger
133 void gdbstub_io_tx_char(unsigned char ch)
135 FLOWCTL_SET(DTR);
136 LSR_WAIT_FOR(THRE);
137 /* FLOWCTL_WAIT_FOR(CTS); */
139 if (ch == 0x0a) {
140 GDBPORT_SERIAL_TX = 0x0d;
141 LSR_WAIT_FOR(THRE);
142 /* FLOWCTL_WAIT_FOR(CTS); */
144 GDBPORT_SERIAL_TX = ch;
146 FLOWCTL_CLEAR(DTR);
150 * send a character to the debugger
152 void gdbstub_io_tx_flush(void)
154 LSR_WAIT_FOR(TEMT);
155 LSR_WAIT_FOR(THRE);
156 FLOWCTL_CLEAR(DTR);