VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / arch / ppc64 / kernel / udbg.c
index 9f54b0a..da21791 100644 (file)
@@ -3,12 +3,6 @@
  *
  * c 2001 PPC 64 Team, IBM Corp
  *
- * NOTE: I am trying to make this code avoid any static data references to
- *  simplify debugging early boot.  We'll see how that goes...
- *
- * To use this call udbg_init() first.  It will init the uart to 9600 8N1.
- * You may need to update the COM1 define if your uart is at a different addr.
- *
  *      This program is free software; you can redistribute it and/or
  *      modify it under the terms of the GNU General Public License
  *      as published by the Free Software Foundation; either version
@@ -53,10 +47,9 @@ struct NS16550 {
 #define LSR_TEMT 0x40  /* Xmitter empty */
 #define LSR_ERR  0x80  /* Error */
 
-volatile struct NS16550 *udbg_comport;
+static volatile struct NS16550 *udbg_comport;
 
-void
-udbg_init_uart(void *comport)
+void udbg_init_uart(void *comport)
 {
        if (comport) {
                udbg_comport = (struct NS16550 *)comport;
@@ -89,8 +82,7 @@ static unsigned char scc_inittab[] = {
     3,  0xc1,          /* rx enable, 8 bits */
 };
 
-void
-udbg_init_scc(struct device_node *np)
+void udbg_init_scc(struct device_node *np)
 {
        unsigned long addr;
        int i, x;
@@ -127,10 +119,9 @@ udbg_init_scc(struct device_node *np)
 
 #endif /* CONFIG_PPC_PMAC */
 
-void
-udbg_putc(unsigned char c)
+void udbg_putc(unsigned char c)
 {
-       if ( udbg_comport ) {
+       if (udbg_comport) {
                while ((udbg_comport->lsr & LSR_THRE) == 0)
                        /* wait for idle */;
                udbg_comport->thr = c; eieio();
@@ -173,10 +164,9 @@ int udbg_getc_poll(void)
        return -1;
 }
 
-unsigned char
-udbg_getc(void)
+unsigned char udbg_getc(void)
 {
-       if ( udbg_comport ) {
+       if (udbg_comport) {
                while ((udbg_comport->lsr & LSR_DR) == 0)
                        /* wait for char */;
                return udbg_comport->rbr;
@@ -192,8 +182,7 @@ udbg_getc(void)
        return 0;
 }
 
-void
-udbg_puts(const char *s)
+void udbg_puts(const char *s)
 {
        if (ppc_md.udbg_putc) {
                char c;
@@ -207,8 +196,7 @@ udbg_puts(const char *s)
        }
 }
 
-int
-udbg_write(const char *s, int n)
+int udbg_write(const char *s, int n)
 {
        int remain = n;
        char c;
@@ -216,20 +204,23 @@ udbg_write(const char *s, int n)
        if (!ppc_md.udbg_putc)
                return 0;
 
-       if ( s && *s != '\0' ) {
-               while ( (( c = *s++ ) != '\0') && (remain-- > 0)) {
+       if (s && *s != '\0') {
+               while (((c = *s++) != '\0') && (remain-- > 0)) {
                        ppc_md.udbg_putc(c);
                }
        }
+
        return n - remain;
 }
 
-int
-udbg_read(char *buf, int buflen) {
+int udbg_read(char *buf, int buflen)
+{
        char c, *p = buf;
        int i;
+
        if (!ppc_md.udbg_putc)
-               for (;;);       /* stop here for cpuctl */
+               return 0;
+
        for (i = 0; i < buflen; ++i) {
                do {
                        c = ppc_md.udbg_getc();
@@ -238,68 +229,38 @@ udbg_read(char *buf, int buflen) {
                        break;
                *p++ = c;
        }
+
        return i;
 }
 
-void
-udbg_console_write(struct console *con, const char *s, unsigned int n)
+void udbg_console_write(struct console *con, const char *s, unsigned int n)
 {
        udbg_write(s, n);
 }
 
-void
-udbg_puthex(unsigned long val)
-{
-       int i, nibbles = sizeof(val)*2;
-       unsigned char buf[sizeof(val)*2+1];
-       for (i = nibbles-1;  i >= 0;  i--) {
-               buf[i] = (val & 0xf) + '0';
-               if (buf[i] > '9')
-                   buf[i] += ('a'-'0'-10);
-               val >>= 4;
-       }
-       buf[nibbles] = '\0';
-       udbg_puts(buf);
-}
-
-void
-udbg_printSP(const char *s)
-{
-       if (systemcfg->platform == PLATFORM_PSERIES) {
-               unsigned long sp;
-               asm("mr %0,1" : "=r" (sp) :);
-               if (s)
-                       udbg_puts(s);
-               udbg_puthex(sp);
-       }
-}
-
-void
-udbg_printf(const char *fmt, ...)
+#define UDBG_BUFSIZE 256
+void udbg_printf(const char *fmt, ...)
 {
-       unsigned char buf[256];
-
+       unsigned char buf[UDBG_BUFSIZE];
        va_list args;
-       va_start(args, fmt);
 
-       vsprintf(buf, fmt, args);
+       va_start(args, fmt);
+       vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
        udbg_puts(buf);
-
        va_end(args);
 }
 
 /* Special print used by PPCDBG() macro */
-void
-udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...)
+void udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...)
 {
        unsigned long active_debugs = debug_flags & naca->debug_switch;
 
-       if ( active_debugs ) {
+       if (active_debugs) {
                va_list ap;
-               unsigned char buf[256];
+               unsigned char buf[UDBG_BUFSIZE];
                unsigned long i, len = 0;
 
-               for(i=0; i < PPCDBG_NUM_FLAGS ;i++) {
+               for (i=0; i < PPCDBG_NUM_FLAGS; i++) {
                        if (((1U << i) & active_debugs) && 
                            trace_names[i]) {
                                len += strlen(trace_names[i]); 
@@ -307,25 +268,24 @@ udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...)
                                break;
                        }
                }
-               sprintf(buf, " [%s]: ", current->comm);
+
+               snprintf(buf, UDBG_BUFSIZE, " [%s]: ", current->comm);
                len += strlen(buf); 
                udbg_puts(buf);
 
-               while(len < 18) {
+               while (len < 18) {
                        udbg_puts(" ");
                        len++;
                }
 
                va_start(ap, fmt);
-               vsprintf(buf, fmt, ap);
+               vsnprintf(buf, UDBG_BUFSIZE, fmt, ap);
                udbg_puts(buf);
-               
                va_end(ap);
        }
 }
 
-unsigned long
-udbg_ifdebug(unsigned long flags)
+unsigned long udbg_ifdebug(unsigned long flags)
 {
        return (flags & naca->debug_switch);
 }