Tue Jul 7 02:10:21 2020 UTC ()
Fix boot failure for PowerMac11,2 when ``auto-boot?'' is true.

For some machines like PowerMac11,2, Open Firmware does not correctly
initialize console-related variables, like font-adr and line#, when
``auto-boot?'' is true; -1 is returned instead of correct values.

Fall back to wsfont embedded in kernel in this case. Also, do not use
line# if it is negative.


(rin)
diff -r1.14 -r1.15 src/sys/arch/powerpc/oea/ofw_rascons.c

cvs diff -r1.14 -r1.15 src/sys/arch/powerpc/oea/ofw_rascons.c (expand / switch to unified diff)

--- src/sys/arch/powerpc/oea/ofw_rascons.c 2020/03/16 22:02:37 1.14
+++ src/sys/arch/powerpc/oea/ofw_rascons.c 2020/07/07 02:10:20 1.15
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ofw_rascons.c,v 1.14 2020/03/16 22:02:37 macallan Exp $ */ 1/* $NetBSD: ofw_rascons.c,v 1.15 2020/07/07 02:10:20 rin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Author: Chris G. Demetriou 7 * Author: Chris G. Demetriou
8 * 8 *
9 * Permission to use, copy, modify and distribute this software and 9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright 10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the 11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions 12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation. 13 * thereof, and that both notices appear in supporting documentation.
14 * 14 *
@@ -18,27 +18,27 @@ @@ -18,27 +18,27 @@
18 * 18 *
19 * Carnegie Mellon requests users of this software to return to 19 * Carnegie Mellon requests users of this software to return to
20 * 20 *
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science 22 * School of Computer Science
23 * Carnegie Mellon University 23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890 24 * Pittsburgh PA 15213-3890
25 * 25 *
26 * any improvements or extensions that they make and grant Carnegie the 26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes. 27 * rights to redistribute these changes.
28 */ 28 */
29 29
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31__KERNEL_RCSID(0, "$NetBSD: ofw_rascons.c,v 1.14 2020/03/16 22:02:37 macallan Exp $"); 31__KERNEL_RCSID(0, "$NetBSD: ofw_rascons.c,v 1.15 2020/07/07 02:10:20 rin Exp $");
32 32
33#include "wsdisplay.h" 33#include "wsdisplay.h"
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/buf.h> 36#include <sys/buf.h>
37#include <sys/bus.h> 37#include <sys/bus.h>
38#include <sys/conf.h> 38#include <sys/conf.h>
39#include <sys/device.h> 39#include <sys/device.h>
40#include <sys/ioctl.h> 40#include <sys/ioctl.h>
41#include <sys/kernel.h> 41#include <sys/kernel.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43 43
44#include <dev/ofw/openfirm.h> 44#include <dev/ofw/openfirm.h>
@@ -77,26 +77,28 @@ struct wsscreen_descr rascons_stdscreen  @@ -77,26 +77,28 @@ struct wsscreen_descr rascons_stdscreen
77 0, 0, 77 0, 0,
78 WSSCREEN_REVERSE 78 WSSCREEN_REVERSE
79}; 79};
80 80
81int 81int
82rascons_cnattach(void) 82rascons_cnattach(void)
83{ 83{
84 struct rasops_info *ri = &rascons_console_screen.scr_ri; 84 struct rasops_info *ri = &rascons_console_screen.scr_ri;
85 long defattr; 85 long defattr;
86 int crow = 0; 86 int crow = 0;
87 87
88 /* get current cursor position */ 88 /* get current cursor position */
89 OF_interpret("line#", 0, 1, &crow); 89 OF_interpret("line#", 0, 1, &crow);
 90 if (crow < 0)
 91 crow = 0;
90 92
91 /* move (rom monitor) cursor to the lowest line - 1 */ 93 /* move (rom monitor) cursor to the lowest line - 1 */
92 /* XXXX - Why? */ 94 /* XXXX - Why? */
93#if 0 95#if 0
94 OF_interpret("#lines 2 - to line#", 0, 0); 96 OF_interpret("#lines 2 - to line#", 0, 0);
95#endif 97#endif
96 wsfont_init(); 98 wsfont_init();
97 if (copy_rom_font() == 0) { 99 if (copy_rom_font() == 0) {
98#if !defined(OFWOEA_WSCONS_NO_ROM_FONT) 100#if !defined(OFWOEA_WSCONS_NO_ROM_FONT)
99 romfont_loaded = 1; 101 romfont_loaded = 1;
100#endif /* !OFWOEA_WSCONS_NO_ROM_FONT */ 102#endif /* !OFWOEA_WSCONS_NO_ROM_FONT */
101 } 103 }
102 104
@@ -155,43 +157,54 @@ rascons_add_rom_font(void) @@ -155,43 +157,54 @@ rascons_add_rom_font(void)
155 } 157 }
156} 158}
157 159
158void 160void
159rascons_finalize(void) 161rascons_finalize(void)
160{ 162{
161 struct rasops_info *ri = &rascons_console_screen.scr_ri; 163 struct rasops_info *ri = &rascons_console_screen.scr_ri;
162 long defattr; 164 long defattr;
163 int crow = 0; 165 int crow = 0;
164 166
165 if (needs_finalize == 0) return; 167 if (needs_finalize == 0) return;
166 168
167 /* get current cursor position */ 169 /* get current cursor position */
168 if (romfont_loaded) OF_interpret("line#", 0, 1, &crow); 170 if (romfont_loaded) {
 171 OF_interpret("line#", 0, 1, &crow);
 172 if (crow < 0)
 173 crow = 0;
 174 }
169 175
170 ri->ri_ops.allocattr(ri, 0, 0, 0, &defattr); 176 ri->ri_ops.allocattr(ri, 0, 0, 0, &defattr);
171 wsdisplay_preattach(&rascons_stdscreen, ri, 0, uimax(0, 177 wsdisplay_preattach(&rascons_stdscreen, ri, 0, uimax(0,
172 uimin(crow, ri->ri_rows - 1)), defattr); 178 uimin(crow, ri->ri_rows - 1)), defattr);
173} 179}
174 180
175static int 181static int
176copy_rom_font(void) 182copy_rom_font(void)
177{ 183{
178 u_char *romfont; 184 u_char *romfont;
179 int char_width, char_height, stride; 185 int char_width, char_height, stride;
180 int chosen, mmu, m, e, size; 186 int chosen, mmu, m, e, size;
181 187
182 /* Get ROM FONT address. */ 188 /*
 189 * Get ROM FONT address.
 190 *
 191 * For some machines like ``PowerMac11,2'', Open Firmware does not
 192 * initialize console-related variables when auto-boot? is true;
 193 * -1 is returned instead of correct value. Fall back to wsfont
 194 * embedded in kernel in this case.
 195 */
183 OF_interpret("font-adr", 0, 1, &romfont); 196 OF_interpret("font-adr", 0, 1, &romfont);
184 if (romfont == NULL) 197 if (romfont == NULL || romfont == (u_char *)-1)
185 return -1; 198 return -1;
186 199
187 chosen = OF_finddevice("/chosen"); 200 chosen = OF_finddevice("/chosen");
188 OF_getprop(chosen, "mmu", &mmu, 4); 201 OF_getprop(chosen, "mmu", &mmu, 4);
189 202
190 /* 203 /*
191 * Convert to physcal address. We cannot access to Open Firmware's 204 * Convert to physcal address. We cannot access to Open Firmware's
192 * virtual address space. 205 * virtual address space.
193 */ 206 */
194 OF_call_method("translate", mmu, 1, 3, romfont, &romfont, &m, &e); 207 OF_call_method("translate", mmu, 1, 3, romfont, &romfont, &m, &e);
195 208
196 /* Get character size */ 209 /* Get character size */
197 OF_interpret("char-width", 0, 1, &char_width); 210 OF_interpret("char-width", 0, 1, &char_width);