]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - arch/ppc64/kernel/udbg.c
[PATCH] ppc64: Remove old includes
[mirror_ubuntu-jammy-kernel.git] / arch / ppc64 / kernel / udbg.c
CommitLineData
1da177e4 1/*
7f853352 2 * polling mode stateless debugging stuff, originally for NS16550 Serial Ports
1da177e4
LT
3 *
4 * c 2001 PPC 64 Team, IBM Corp
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <stdarg.h>
13#define WANT_PPCDBG_TAB /* Only defined here */
14#include <linux/config.h>
15#include <linux/types.h>
188d2ce7 16#include <linux/sched.h>
1da177e4
LT
17#include <asm/ppcdebug.h>
18#include <asm/processor.h>
1da177e4 19
c8f1c8be
MM
20void (*udbg_putc)(unsigned char c);
21unsigned char (*udbg_getc)(void);
22int (*udbg_getc_poll)(void);
23
1da177e4
LT
24void udbg_puts(const char *s)
25{
c8f1c8be 26 if (udbg_putc) {
1da177e4
LT
27 char c;
28
29 if (s && *s != '\0') {
30 while ((c = *s++) != '\0')
c8f1c8be 31 udbg_putc(c);
1da177e4
LT
32 }
33 }
34#if 0
35 else {
36 printk("%s", s);
37 }
38#endif
39}
40
41int udbg_write(const char *s, int n)
42{
43 int remain = n;
44 char c;
45
c8f1c8be 46 if (!udbg_putc)
1da177e4
LT
47 return 0;
48
49 if (s && *s != '\0') {
50 while (((c = *s++) != '\0') && (remain-- > 0)) {
c8f1c8be 51 udbg_putc(c);
1da177e4
LT
52 }
53 }
54
55 return n - remain;
56}
57
58int udbg_read(char *buf, int buflen)
59{
60 char c, *p = buf;
61 int i;
62
c8f1c8be 63 if (!udbg_getc)
1da177e4
LT
64 return 0;
65
66 for (i = 0; i < buflen; ++i) {
67 do {
c8f1c8be 68 c = udbg_getc();
1da177e4
LT
69 } while (c == 0x11 || c == 0x13);
70 if (c == 0)
71 break;
72 *p++ = c;
73 }
74
75 return i;
76}
77
78void udbg_console_write(struct console *con, const char *s, unsigned int n)
79{
80 udbg_write(s, n);
81}
82
83#define UDBG_BUFSIZE 256
84void udbg_printf(const char *fmt, ...)
85{
86 unsigned char buf[UDBG_BUFSIZE];
87 va_list args;
88
89 va_start(args, fmt);
90 vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
91 udbg_puts(buf);
92 va_end(args);
93}
94
95/* Special print used by PPCDBG() macro */
96void udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...)
97{
98 unsigned long active_debugs = debug_flags & ppc64_debug_switch;
99
100 if (active_debugs) {
101 va_list ap;
102 unsigned char buf[UDBG_BUFSIZE];
103 unsigned long i, len = 0;
104
105 for (i=0; i < PPCDBG_NUM_FLAGS; i++) {
106 if (((1U << i) & active_debugs) &&
107 trace_names[i]) {
108 len += strlen(trace_names[i]);
109 udbg_puts(trace_names[i]);
110 break;
111 }
112 }
113
114 snprintf(buf, UDBG_BUFSIZE, " [%s]: ", current->comm);
115 len += strlen(buf);
116 udbg_puts(buf);
117
118 while (len < 18) {
119 udbg_puts(" ");
120 len++;
121 }
122
123 va_start(ap, fmt);
124 vsnprintf(buf, UDBG_BUFSIZE, fmt, ap);
125 udbg_puts(buf);
126 va_end(ap);
127 }
128}
129
130unsigned long udbg_ifdebug(unsigned long flags)
131{
132 return (flags & ppc64_debug_switch);
133}