1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * * Neither the name of Cavium Networks nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
23 * This Software, including technical data, may be subject to U.S. export control
24 * laws, including the U.S. Export Administration Act and its associated
25 * regulations, and may be subject to export or import regulations in other
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
41 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
42 #include <linux/module.h>
43 #include <asm/octeon/cvmx.h>
44 #include <asm/octeon/cvmx-debug.h>
45 #include <asm/octeon/cvmx-uart.h>
46 #include <asm/octeon/octeon-boot-info.h>
47 #include <asm/octeon/cvmx-spinlock.h>
49 int cvmx_debug_uart = 1;
53 #include "executive-config.h"
55 #include "cvmx-debug.h"
56 #include "cvmx-uart.h"
57 #include "cvmx-spinlock.h"
59 #ifndef __OCTEON_NEWLIB__
60 #include "../../bootloader/u-boot/include/octeon_mem_map.h"
62 #include "octeon-boot-info.h"
68 #ifdef __OCTEON_NEWLIB__
69 #pragma weak cvmx_uart_enable_intr
70 int cvmx_debug_uart = 1;
74 /* Default to second uart port for backward compatibility. The default (if
75 -debug does not set the uart number) can now be overridden with
76 CVMX_DEBUG_COMM_UART_NUM. */
77 #ifndef CVMX_DEBUG_COMM_UART_NUM
78 # define CVMX_DEBUG_COMM_UART_NUM 1
81 static CVMX_SHARED cvmx_spinlock_t cvmx_debug_uart_lock;
84 * Interrupt handler for debugger Control-C interrupts.
86 * @param irq_number IRQ interrupt number
87 * @param registers CPU registers at the time of the interrupt
88 * @param user_arg Unused user argument
90 void cvmx_debug_uart_process_debug_interrupt(int irq_number, uint64_t registers[32], void *user_arg)
92 cvmx_uart_lsr_t lsrval;
94 /* Check for a Control-C interrupt from the debugger. This loop will eat
95 all input received on the uart */
96 lsrval.u64 = cvmx_read_csr(CVMX_MIO_UARTX_LSR(cvmx_debug_uart));
99 int c = cvmx_read_csr(CVMX_MIO_UARTX_RBR(cvmx_debug_uart));
102 register uint64_t tmp;
103 #ifndef CVMX_BUILD_FOR_LINUX_KERNEL
107 /* Pulse MCD0 signal on Ctrl-C to stop all the cores. Also
108 set the MCD0 to be not masked by this core so we know
109 the signal is received by someone */
112 "ori %0, %0, 0x1110\n"
116 lsrval.u64 = cvmx_read_csr(CVMX_MIO_UARTX_LSR(cvmx_debug_uart));
121 static void cvmx_debug_uart_init(void)
123 if (cvmx_debug_uart == -1)
124 cvmx_debug_uart = CVMX_DEBUG_COMM_UART_NUM;
127 static void cvmx_debug_uart_install_break_handler(void)
129 #ifndef CVMX_BUILD_FOR_LINUX_KERNEL
130 #ifdef __OCTEON_NEWLIB__
131 if (cvmx_uart_enable_intr)
133 cvmx_uart_enable_intr(cvmx_debug_uart, cvmx_debug_uart_process_debug_interrupt);
137 /* Get a packet from the UART, return 0 on failure and 1 on success. */
139 static int cvmx_debug_uart_getpacket(char *buffer, size_t size)
143 unsigned char checksum;
148 ch = cvmx_uart_read_byte_with_timeout(cvmx_debug_uart, &timedout, __SHRT_MAX__);
153 /* if this is not the start character, ignore it. */
161 /* now, read until a # or end of buffer is found */
164 ch = cvmx_uart_read_byte(cvmx_debug_uart);
169 checksum = checksum + ch;
181 csumchars[0] = cvmx_uart_read_byte(cvmx_debug_uart);
182 csumchars[1] = cvmx_uart_read_byte(cvmx_debug_uart);
183 n = sscanf(csumchars, "%2x", &xmitcsum);
187 return checksum == xmitcsum;
193 static int cvmx_debug_uart_putpacket(char *packet)
197 unsigned char *ptr = (unsigned char *) packet;
200 for (csum = 0, i = 0; ptr[i]; i++)
202 sprintf(csumstr, "%02x", csum);
204 cvmx_spinlock_lock(&cvmx_debug_uart_lock);
205 cvmx_uart_write_byte(cvmx_debug_uart, '$');
206 cvmx_uart_write_string(cvmx_debug_uart, packet);
207 cvmx_uart_write_byte(cvmx_debug_uart, '#');
208 cvmx_uart_write_string(cvmx_debug_uart, csumstr);
209 cvmx_spinlock_unlock(&cvmx_debug_uart_lock);
214 static void cvmx_debug_uart_change_core(int oldcore, int newcore)
216 #ifndef CVMX_BUILD_FOR_LINUX_KERNEL
217 cvmx_ciu_intx0_t irq_control;
219 irq_control.u64 = cvmx_read_csr(CVMX_CIU_INTX_EN0(newcore * 2));
220 irq_control.s.uart |= (1<<cvmx_debug_uart);
221 cvmx_write_csr(CVMX_CIU_INTX_EN0(newcore * 2), irq_control.u64);
223 /* Disable interrupts to this core since he is about to die */
224 irq_control.u64 = cvmx_read_csr(CVMX_CIU_INTX_EN0(oldcore * 2));
225 irq_control.s.uart &= ~(1<<cvmx_debug_uart);
226 cvmx_write_csr(CVMX_CIU_INTX_EN0(oldcore* 2), irq_control.u64);
230 cvmx_debug_comm_t cvmx_debug_uart_comm =
232 .init = cvmx_debug_uart_init,
233 .install_break_handler = cvmx_debug_uart_install_break_handler,
235 .getpacket = cvmx_debug_uart_getpacket,
236 .putpacket = cvmx_debug_uart_putpacket,
237 .wait_for_resume = NULL,
238 .change_core = cvmx_debug_uart_change_core,