]> git.saurik.com Git - apple/xnu.git/blame - pexpert/ppc/pe_kprintf.c
xnu-1456.1.26.tar.gz
[apple/xnu.git] / pexpert / ppc / pe_kprintf.c
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * file: pe_kprintf.c
30 * PPC platform expert debugging output initialization.
31 */
32#include <stdarg.h>
33#include <machine/machine_routines.h>
34#include <pexpert/protos.h>
35#include <pexpert/pexpert.h>
36#include <pexpert/ppc/powermac.h>
91447636 37#include <pexpert/device_tree.h>
1c79356b
A
38#include <kern/debug.h>
39#include <kern/simple_lock.h>
0c530ab8 40#include <vm/pmap.h>
1c79356b
A
41
42/* extern references */
2d21ac55
A
43extern void scc_putc(int unit, int line, int c);
44extern long strtol(const char *, char **, int);
1c79356b
A
45
46/* Globals */
2d21ac55 47void (*PE_kputc)(char c);
1c79356b 48
2d21ac55 49unsigned int disable_serial_output = TRUE;
1c79356b 50
55e303ae 51vm_offset_t scc = 0;
1c79356b 52
55e303ae 53struct slock kprintf_lock;
1c79356b 54
2d21ac55 55void PE_init_kprintf(__unused boolean_t vm_initialized)
1c79356b 56{
1c79356b 57 unsigned int boot_arg;
2d21ac55
A
58 int32_t serial_baud = -1;
59 unsigned int size;
91447636
A
60 DTEntry options;
61 char *str, baud[7];
1c79356b
A
62
63 if (PE_state.initialized == FALSE)
64 panic("Platform Expert not initialized");
65
593a1d5f 66 if (PE_parse_boot_argn("debug", &boot_arg, sizeof (boot_arg)))
2d21ac55 67 if(boot_arg & DB_KPRT) disable_serial_output = FALSE;
1c79356b 68
2d21ac55
A
69 if (DTLookupEntry(NULL, "/options", &options) == kSuccess) {
70 if (DTGetProperty(options, "input-device", (void **)&str, &size) == kSuccess) {
91447636
A
71 if ((size > 5) && !strncmp("scca:", str, 5)) {
72 size -= 5;
73 str += 5;
74 if (size <= 6) {
75 strncpy(baud, str, size);
76 baud[size] = '\0';
2d21ac55 77 gPESerialBaud = strtol(baud, NULL, 0);
91447636
A
78 }
79 }
80 }
2d21ac55 81 if (DTGetProperty(options, "output-device", (void **)&str, &size) == kSuccess) {
91447636
A
82 if ((size > 5) && !strncmp("scca:", str, 5)) {
83 size -= 5;
84 str += 5;
85 if (size <= 6) {
86 strncpy(baud, str, size);
87 baud[size] = '\0';
2d21ac55 88 gPESerialBaud = strtol(baud, NULL, 0);
91447636
A
89 }
90 }
91 }
92 }
93
94 /* Check the boot-args for new serial baud. */
593a1d5f 95 if (PE_parse_boot_argn("serialbaud", &serial_baud, sizeof (serial_baud)))
91447636
A
96 if (serial_baud != -1) gPESerialBaud = serial_baud;
97
55e303ae 98 if( (scc = PE_find_scc())) { /* See if we can find the serial port */
0c530ab8 99 scc = io_map_spec(scc, 0x1000, VM_WIMG_IO); /* Map it in */
91447636 100 initialize_serial((void *)scc, gPESerialBaud); /* Start up the serial driver */
1c79356b
A
101 PE_kputc = serial_putc;
102
103 simple_lock_init(&kprintf_lock, 0);
55e303ae
A
104 } else
105 PE_kputc = cnputc;
1c79356b
A
106
107#if 0
108 /*
109 * FUTURE: eventually let the boot command determine where
110 * the debug output will be, serial, video, etc.
111 */
112 switch (PE_state.debug_video.v_display) {
113 case kDebugTypeSerial:
114 PE_kputc = serial_putc;
115 break;
116
117 case kDebugTypeDisplay:
118 init_display_putc( (unsigned char*)PE_state.debug_video.v_baseAddr,
119 PE_state.debug_video.v_rowBytes,
120 PE_state.debug_video.v_height);
121 PE_kputc = display_putc;
122 break;
123
124 default:
125 PE_state.debug_video.v_baseAddr = 0;
126 }
127#endif
128}
129
130void serial_putc(char c)
131{
2d21ac55
A
132 scc_putc(0, 1, c);
133 if (c == '\n')
134 scc_putc(0, 1, '\r');
1c79356b
A
135}
136
137void kprintf(const char *fmt, ...)
138{
139 va_list listp;
140 boolean_t state;
141
142 state = ml_set_interrupts_enabled(FALSE);
143 simple_lock(&kprintf_lock);
144
2d21ac55 145 if (!disable_serial_output) {
1c79356b
A
146 va_start(listp, fmt);
147 _doprnt(fmt, &listp, PE_kputc, 16);
148 va_end(listp);
149 }
150
151 simple_unlock(&kprintf_lock);
152 ml_set_interrupts_enabled(state);
153}
154