1 /* $NetBSD: pci_consinit.c,v 1.1 2025/03/09 01:06:42 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include "opt_kgdb.h"
31
32 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
33
34 __KERNEL_RCSID(0, "$NetBSD: pci_consinit.c,v 1.1 2025/03/09 01:06:42 thorpej Exp $");
35
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/termios.h>
39 #include <sys/time.h>
40 #include <sys/bus.h>
41
42 #include <machine/rpb.h>
43 #include <machine/autoconf.h>
44
45 #include <dev/ic/comreg.h>
46 #include <dev/ic/comvar.h>
47
48 #include <dev/ic/i8042reg.h>
49 #include <dev/ic/pckbcvar.h>
50
51 #include <dev/isa/isareg.h>
52 #include <dev/isa/isavar.h>
53
54 #include <dev/pci/pcireg.h>
55 #include <dev/pci/pcivar.h>
56
57 #include "pckbd.h"
58
59 #ifndef CONSPEED
60 #define CONSPEED TTYDEF_SPEED
61 #endif
62 static int comcnrate = CONSPEED;
63
64 #ifdef KGDB
65 #include <machine/db_machdep.h>
66
67 static const char *kgdb_devlist[] = {
68 "com",
69 NULL,
70 };
71 #endif /* KGDB */
72
73 void
pci_consinit(pci_chipset_tag_t disp_pc,bus_space_tag_t disp_iot,bus_space_tag_t disp_memt,bus_space_tag_t isa_iot,bus_space_tag_t isa_memt)74 pci_consinit(pci_chipset_tag_t disp_pc,
75 bus_space_tag_t disp_iot, bus_space_tag_t disp_memt,
76 bus_space_tag_t isa_iot, bus_space_tag_t isa_memt)
77 {
78 const struct ctb *ctb;
79
80 ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off);
81
82 switch (ctb->ctb_term_type) {
83 case CTB_PRINTERPORT:
84 /* serial console ... */
85 /* XXX */
86 /*
87 * Delay to allow PROM putchars to complete.
88 * FIFO depth * character time,
89 * character time = (1000000 / (defaultrate / 10))
90 */
91 DELAY(160000000 / comcnrate);
92
93 if (comcnattach(isa_iot, 0x3f8, comcnrate, COM_FREQ,
94 COM_TYPE_NORMAL,
95 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) {
96 panic("can't init serial console");
97 }
98 break;
99
100 case CTB_GRAPHICS:
101 #if NPCKBD > 0
102 /* display console ... */
103 /* XXX */
104 (void) pckbc_cnattach(isa_iot, IO_KBD, KBCMDP,
105 PCKBC_KBD_SLOT, 0);
106
107 switch (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot)) {
108 case CTB_TURBOSLOT_TYPE_ISA:
109 case CTB_TURBOSLOT_TYPE_EISA:
110 isa_display_console(isa_iot, isa_memt);
111 break;
112
113 case CTB_TURBOSLOT_TYPE_PCI:
114 default:
115 pci_display_console(disp_iot, disp_memt, disp_pc,
116 CTB_TURBOSLOT_BUS(ctb->ctb_turboslot),
117 CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0);
118 break;
119 }
120 #else
121 panic("not configured to use display && keyboard console");
122 #endif
123 break;
124
125 default:
126 printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type);
127 printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot);
128
129 panic("%s: unknown console type %ld", __func__,
130 ctb->ctb_term_type);
131 }
132 #ifdef KGDB
133 /* Attach the KGDB device. */
134 alpha_kgdb_init(kgdb_devlist, isa_iot);
135 #endif /* KGDB */
136 }
137