xref: /netbsd-src/sys/arch/alpha/alpha/dec_axppci_33.c (revision 296121ed992a66fda2c79e843285616269b1d6d1)
1 /* $NetBSD: dec_axppci_33.c,v 1.70 2024/03/31 19:06:30 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  * Additional Copyright (c) 1997 by Matthew Jacob for NASA/Ames Research Center
31  */
32 
33 #include "opt_kgdb.h"
34 
35 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
36 
37 __KERNEL_RCSID(0, "$NetBSD: dec_axppci_33.c,v 1.70 2024/03/31 19:06:30 thorpej Exp $");
38 
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/termios.h>
43 #include <sys/conf.h>
44 #include <dev/cons.h>
45 
46 #include <machine/rpb.h>
47 #include <machine/alpha.h>
48 #include <machine/autoconf.h>
49 #include <machine/cpuconf.h>
50 
51 #include <dev/ic/comreg.h>
52 #include <dev/ic/comvar.h>
53 
54 #include <dev/isa/isareg.h>
55 #include <dev/isa/isavar.h>
56 #include <dev/ic/i8042reg.h>
57 #include <dev/ic/pckbcvar.h>
58 #include <dev/pci/pcireg.h>
59 #include <dev/pci/pcivar.h>
60 
61 #include <alpha/pci/lcareg.h>
62 #include <alpha/pci/lcavar.h>
63 
64 #include <dev/scsipi/scsi_all.h>
65 #include <dev/scsipi/scsipi_all.h>
66 #include <dev/scsipi/scsiconf.h>
67 
68 #include "pckbd.h"
69 
70 #ifndef CONSPEED
71 #define CONSPEED TTYDEF_SPEED
72 #endif
73 static int comcnrate = CONSPEED;
74 
75 void dec_axppci_33_init(void);
76 static void dec_axppci_33_cons_init(void);
77 static void dec_axppci_33_device_register(device_t, void *);
78 
79 #ifdef KGDB
80 #include <machine/db_machdep.h>
81 
82 static const char *kgdb_devlist[] = {
83 	"com",
84 	NULL,
85 };
86 #endif /* KGDB */
87 
88 const struct alpha_variation_table dec_axppci_33_variations[] = {
89 	{ 0, "Alpha PC AXPpci33 (\"NoName\")" },
90 	{ 0, NULL },
91 };
92 
93 static struct lca_config *lca_preinit(void);
94 
95 static struct lca_config *
lca_preinit(void)96 lca_preinit(void)
97 {
98 	extern struct lca_config lca_configuration;
99 
100 	lca_init(&lca_configuration);
101 	return &lca_configuration;
102 }
103 
104 #define	NSIO_PORT  0x26e	/* Hardware enabled option: 0x398 */
105 #define	NSIO_BASE  0
106 #define	NSIO_INDEX NSIO_BASE
107 #define	NSIO_DATA  1
108 #define	NSIO_SIZE  2
109 #define	NSIO_CFG0  0
110 #define	NSIO_CFG1  1
111 #define	NSIO_CFG2  2
112 #define	NSIO_IDE_ENABLE 0x40
113 
114 void
dec_axppci_33_init(void)115 dec_axppci_33_init(void)
116 {
117 	int cfg0val;
118 	uint64_t variation;
119 	bus_space_tag_t iot;
120 	struct lca_config *lcp;
121 	bus_space_handle_t nsio;
122 #define	A33_NSIOBARRIER(type) bus_space_barrier(iot, nsio,\
123 				NSIO_BASE, NSIO_SIZE, (type))
124 
125 	platform.family = "DEC AXPpci";
126 
127 	if ((platform.model = alpha_dsr_sysname()) == NULL) {
128 		variation = hwrpb->rpb_variation & SV_ST_MASK;
129 		if ((platform.model = alpha_variation_name(variation,
130 		    dec_axppci_33_variations)) == NULL)
131 			platform.model = alpha_unknown_sysname();
132 	}
133 
134 	platform.iobus = "lca";
135 	platform.cons_init = dec_axppci_33_cons_init;
136 	platform.device_register = dec_axppci_33_device_register;
137 
138 	lcp = lca_preinit();
139 	iot = &lcp->lc_iot;
140 	if (bus_space_map(iot, NSIO_PORT, NSIO_SIZE, 0, &nsio))
141 		return;
142 
143 	bus_space_write_1(iot, nsio, NSIO_INDEX, NSIO_CFG0);
144 	A33_NSIOBARRIER(BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);
145 	cfg0val = bus_space_read_1(iot, nsio, NSIO_DATA);
146 
147 	cfg0val |= NSIO_IDE_ENABLE;
148 
149 	bus_space_write_1(iot, nsio, NSIO_INDEX, NSIO_CFG0);
150 	A33_NSIOBARRIER(BUS_SPACE_BARRIER_WRITE);
151 	bus_space_write_1(iot, nsio, NSIO_DATA, cfg0val);
152 	A33_NSIOBARRIER(BUS_SPACE_BARRIER_WRITE);
153 	bus_space_write_1(iot, nsio, NSIO_DATA, cfg0val);
154 
155 	/* Leave nsio mapped to catch any accidental port space collisions  */
156 
157 	lca_probe_bcache();
158 }
159 
160 static void
dec_axppci_33_cons_init(void)161 dec_axppci_33_cons_init(void)
162 {
163 	struct ctb *ctb;
164 	struct lca_config *lcp;
165 
166 	lcp = lca_preinit();
167 
168 	ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off);
169 
170 	switch (ctb->ctb_term_type) {
171 	case CTB_PRINTERPORT:
172 		/* serial console ... */
173 		/* XXX */
174 		{
175 			/*
176 			 * Delay to allow PROM putchars to complete.
177 			 * FIFO depth * character time,
178 			 * character time = (1000000 / (defaultrate / 10))
179 			 */
180 			DELAY(160000000 / comcnrate);
181 
182 			if(comcnattach(&lcp->lc_iot, 0x3f8, comcnrate,
183 			    COM_FREQ, COM_TYPE_NORMAL,
184 			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
185 				panic("can't init serial console");
186 
187 			break;
188 		}
189 
190 	case CTB_GRAPHICS:
191 #if NPCKBD > 0
192 		/* display console ... */
193 		/* XXX */
194 		(void) pckbc_cnattach(&lcp->lc_iot, IO_KBD, KBCMDP,
195 		    PCKBC_KBD_SLOT, 0);
196 
197 		if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) ==
198 		    CTB_TURBOSLOT_TYPE_ISA)
199 			isa_display_console(&lcp->lc_iot, &lcp->lc_memt);
200 		else
201 			pci_display_console(&lcp->lc_iot, &lcp->lc_memt,
202 			    &lcp->lc_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot),
203 			    CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0);
204 #else
205 		panic("not configured to use display && keyboard console");
206 #endif
207 		break;
208 
209 	default:
210 		printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type);
211 		printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot);
212 
213 		panic("consinit: unknown console type %ld",
214 		    ctb->ctb_term_type);
215 	}
216 #ifdef KGDB
217 	/* Attach the KGDB device. */
218 	alpha_kgdb_init(kgdb_devlist, &lcp->lc_iot);
219 #endif /* KGDB */
220 }
221 
222 static void
dec_axppci_33_device_register(device_t dev,void * aux)223 dec_axppci_33_device_register(device_t dev, void *aux)
224 {
225 	static int found, initted, diskboot, netboot;
226 	static device_t pcidev, ctrlrdev;
227 	struct bootdev_data *b = bootdev_data;
228 	device_t parent = device_parent(dev);
229 
230 	if (b == NULL || found)
231 		return;
232 
233 	if (!initted) {
234 		diskboot = (strcasecmp(b->protocol, "SCSI") == 0);
235 		netboot = (strcasecmp(b->protocol, "BOOTP") == 0) ||
236 		    (strcasecmp(b->protocol, "MOP") == 0);
237 #if 0
238 		printf("diskboot = %d, netboot = %d\n", diskboot, netboot);
239 #endif
240 		initted =1;
241 	}
242 
243 	if (pcidev == NULL) {
244 		if (!device_is_a(dev, "pci"))
245 			return;
246 		else {
247 			struct pcibus_attach_args *pba = aux;
248 
249 			if ((b->slot / 1000) != pba->pba_bus)
250 				return;
251 
252 			pcidev = dev;
253 #if 0
254 			printf("\npcidev = %s\n", device_xname(dev));
255 #endif
256 			return;
257 		}
258 	}
259 
260 	if (ctrlrdev == NULL) {
261 		if (parent != pcidev)
262 			return;
263 		else {
264 			struct pci_attach_args *pa = aux;
265 			int slot;
266 
267 			slot = pa->pa_bus * 1000 + pa->pa_function * 100 +
268 			    pa->pa_device;
269 			if (b->slot != slot)
270 				return;
271 
272 			if (netboot) {
273 				booted_device = dev;
274 #if 0
275 				printf("\nbooted_device = %s\n", device_xname(dev));
276 #endif
277 				found = 1;
278 			} else {
279 				ctrlrdev = dev;
280 #if 0
281 				printf("\nctrlrdev = %s\n", device_xname(dev));
282 #endif
283 			}
284 			return;
285 		}
286 	}
287 
288 	if (!diskboot)
289 		return;
290 
291 	if (device_is_a(dev, "sd") ||
292 	    device_is_a(dev, "st") ||
293 	    device_is_a(dev, "cd")) {
294 		struct scsipibus_attach_args *sa = aux;
295 		struct scsipi_periph *periph = sa->sa_periph;
296 		int unit;
297 
298 		if (device_parent(parent) != ctrlrdev)
299 			return;
300 
301 		unit = periph->periph_target * 100 + periph->periph_lun;
302 		if (b->unit != unit)
303 			return;
304 		if (b->channel != periph->periph_channel->chan_channel)
305 			return;
306 
307 		/* we've found it! */
308 		booted_device = dev;
309 #if 0
310 		printf("\nbooted_device = %s\n", device_xname(dev));
311 #endif
312 		found = 1;
313 	}
314 }
315