PR port-macppc/56091: on G5 macs we currently can not easily make

early serial console work, so keep the OF based "failsafe" console
but note that we would like to switch over.
Once zs attaches, use the new device mapping and do a belated init
of the zs console globals, and then switch over to real zs based
serial console.
This commit is contained in:
martin 2022-02-13 12:24:24 +00:00
parent bcceabb713
commit 8cefc40753
3 changed files with 72 additions and 23 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: zs.c,v 1.54 2021/09/11 20:28:04 andvar Exp $ */
/* $NetBSD: zs.c,v 1.55 2022/02/13 12:24:24 martin Exp $ */
/*
* Copyright (c) 1996, 1998 Bill Studenmund
@ -49,7 +49,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.54 2021/09/11 20:28:04 andvar Exp $");
__KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.55 2022/02/13 12:24:24 martin Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@ -73,6 +73,7 @@ __KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.54 2021/09/11 20:28:04 andvar Exp $");
#include <dev/cons.h>
#include <dev/ofw/openfirm.h>
#include <powerpc/ofw_cons.h>
#include <dev/ic/z8530reg.h>
#include <machine/z8530var.h>
@ -115,11 +116,28 @@ int zs_cons_canabort = 1;
#else
int zs_cons_canabort = 0;
#endif /* ZS_CONSOLE_ABORT*/
#if PMAC_G5
static void zscn_delayed_init(struct zsdevice *zsd);
#endif
/* device to which the console is attached--if serial. */
/* Mac stuff */
static int zs_get_speed(struct zs_chanstate *);
void zscnprobe(struct consdev *cp);
void zscninit(struct consdev *cp);
int zscngetc(dev_t dev);
void zscnputc(dev_t dev, int c);
#define zscnpollc nullcnpollc
cons_decl(zs);
struct consdev consdev_zs = {
zscnprobe,
zscninit,
zscngetc,
zscnputc,
zscnpollc,
};
/*
* Even though zsparam will set up the clock multiples, etc., we
@ -251,6 +269,12 @@ zsc_attach(device_t parent, device_t self, void *aux)
aprint_normal(" irq %d,%d\n", intr[0][0], intr[1][0]);
#if PMAC_G5
extern struct consdev failsafe_cons;
if (ofwoea_use_serial_console && cn_tab == &failsafe_cons)
zscn_delayed_init(zsd);
#endif
/*
* Initialize software state for each channel.
*/
@ -827,9 +851,6 @@ zs_write_data(struct zs_chanstate *cs, uint8_t val)
* XXX - Well :-P :-) -wrs
****************************************************************/
#define zscnpollc nullcnpollc
cons_decl(zs);
static int stdin, stdout;
/*
@ -968,17 +989,6 @@ zs_abort(struct zs_chanstate *cs)
#endif
}
extern int ofccngetc(dev_t);
extern void ofccnputc(dev_t, int);
struct consdev consdev_zs = {
zscnprobe,
zscninit,
zscngetc,
zscnputc,
zscnpollc,
};
void
zscnprobe(struct consdev *cp)
{
@ -1037,3 +1047,40 @@ zscninit(struct consdev *cp)
return;
zs_conschan = (void *)(reg[2] + zs_offset);
}
#if PMAC_G5
/*
* Do a delayed (now that the device is properly mapped) init of the
* global zs console state, basically the equivalent of calling
* zscnprobe(&consdev_zs); zscninit(&consdev_zs);
* but with the mapped address of the device passed in as zsd.
*/
static void
zscn_delayed_init(struct zsdevice *zsd)
{
int chosen, escc_ch;
char name[16];
if ((chosen = OF_finddevice("/chosen")) == -1)
return;
if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin)) == -1)
return;
if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
return;
if ((escc_ch = OF_instance_to_package(stdin)) == -1)
return;
memset(name, 0, sizeof(name));
if (OF_getprop(escc_ch, "name", name, sizeof(name)) == -1)
return;
zs_conschannel = strcmp(name, "ch-b") == 0;
zs_conschan = (zs_conschannel == 0) ?
&zsd->zs_chan_a :
&zsd->zs_chan_b;
cn_tab = &consdev_zs;
}
#endif

View File

@ -1,8 +1,9 @@
/* $NetBSD: ofw_cons.h,v 1.3 2021/03/05 18:10:06 thorpej Exp $ */
/* $NetBSD: ofw_cons.h,v 1.4 2022/02/13 12:24:24 martin Exp $ */
#ifndef _POWERPC_OFW_CONS_H_
#define _POWERPC_OFW_CONS_H_
extern bool ofwoea_use_serial_console;
void ofwoea_cnprobe(void);
void ofwoea_consinit(void);
int ofkbd_cngetc(dev_t dev);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ofw_consinit.c,v 1.24 2021/03/05 18:10:06 thorpej Exp $ */
/* $NetBSD: ofw_consinit.c,v 1.25 2022/02/13 12:24:24 martin Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.24 2021/03/05 18:10:06 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.25 2022/02/13 12:24:24 martin Exp $");
#include "adb.h"
#include "adbkbd.h"
@ -117,7 +117,7 @@ void ofprint(const char *blah, ...)
#define OFPRINTF while(0) printf
#endif
static bool use_serial_console;
bool ofwoea_use_serial_console;
static struct consdev *selected_serial_consdev;
static int (*selected_keyboard)(void);
@ -149,12 +149,13 @@ ofwoea_cnprobe(void)
OFPRINTF("console type: %s\n", name);
if (strcmp(name, "serial") == 0) {
use_serial_console = true;
ofwoea_use_serial_console = true;
#ifdef PMAC_G5
/* The MMU hasn't been initialized yet, use failsafe for now */
extern struct consdev failsafe_cons;
selected_serial_consdev = &failsafe_cons;
aprint_verbose("Early G5 console selected\n");
aprint_verbose("Early G5 console selected "
"(keeping OF console for now)\n");
return;
#endif /* PMAC_G5 */
@ -388,7 +389,7 @@ ofkbd_cngetc(dev_t dev)
void
cninit(void)
{
if (use_serial_console) {
if (ofwoea_use_serial_console) {
if (selected_serial_consdev != NULL) {
cn_tab = selected_serial_consdev;
(*cn_tab->cn_probe)(cn_tab);