xref: /netbsd/sys/arch/alpha/alpha/dec_axppci_33.c (revision bf9ec67e)
1 /* $NetBSD: dec_axppci_33.c,v 1.50 2001/06/05 04:53:11 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.50 2001/06/05 04:53:11 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 <dev/cons.h>
44 
45 #include <uvm/uvm_extern.h>
46 
47 #include <machine/rpb.h>
48 #include <machine/alpha.h>
49 #include <machine/autoconf.h>
50 #include <machine/conf.h>
51 
52 #include <dev/ic/comreg.h>
53 #include <dev/ic/comvar.h>
54 
55 #include <dev/isa/isareg.h>
56 #include <dev/isa/isavar.h>
57 #include <dev/ic/i8042reg.h>
58 #include <dev/ic/pckbcvar.h>
59 #include <dev/pci/pcireg.h>
60 #include <dev/pci/pcivar.h>
61 
62 #include <alpha/pci/lcareg.h>
63 #include <alpha/pci/lcavar.h>
64 
65 #include <dev/scsipi/scsi_all.h>
66 #include <dev/scsipi/scsipi_all.h>
67 #include <dev/scsipi/scsiconf.h>
68 
69 #include "pckbd.h"
70 
71 #ifndef CONSPEED
72 #define CONSPEED TTYDEF_SPEED
73 #endif
74 static int comcnrate = CONSPEED;
75 
76 void dec_axppci_33_init __P((void));
77 static void dec_axppci_33_cons_init __P((void));
78 static void dec_axppci_33_device_register __P((struct device *, void *));
79 
80 #ifdef KGDB
81 #include <machine/db_machdep.h>
82 
83 static const char *kgdb_devlist[] = {
84 	"com",
85 	NULL,
86 };
87 #endif /* KGDB */
88 
89 const struct alpha_variation_table dec_axppci_33_variations[] = {
90 	{ 0, "Alpha PC AXPpci33 (\"NoName\")" },
91 	{ 0, NULL },
92 };
93 
94 static struct lca_config *lca_preinit __P((void));
95 
96 static struct lca_config *
97 lca_preinit()
98 {
99 	extern struct lca_config lca_configuration;
100 
101 	lca_init(&lca_configuration, 0);
102 	return &lca_configuration;
103 }
104 
105 #define	NSIO_PORT  0x26e	/* Hardware enabled option: 0x398 */
106 #define	NSIO_BASE  0
107 #define	NSIO_INDEX NSIO_BASE
108 #define	NSIO_DATA  1
109 #define	NSIO_SIZE  2
110 #define	NSIO_CFG0  0
111 #define	NSIO_CFG1  1
112 #define	NSIO_CFG2  2
113 #define	NSIO_IDE_ENABLE 0x40
114 
115 void
116 dec_axppci_33_init()
117 {
118 	int cfg0val;
119 	u_int64_t variation;
120 	bus_space_tag_t iot;
121 	struct lca_config *lcp;
122 	bus_space_handle_t nsio;
123 #define	A33_NSIOBARRIER(type) bus_space_barrier(iot, nsio,\
124 				NSIO_BASE, NSIO_SIZE, (type))
125 
126 	platform.family = "DEC AXPpci";
127 
128 	if ((platform.model = alpha_dsr_sysname()) == NULL) {
129 		variation = hwrpb->rpb_variation & SV_ST_MASK;
130 		if ((platform.model = alpha_variation_name(variation,
131 		    dec_axppci_33_variations)) == NULL)
132 			platform.model = alpha_unknown_sysname();
133 	}
134 
135 	platform.iobus = "lca";
136 	platform.cons_init = dec_axppci_33_cons_init;
137 	platform.device_register = dec_axppci_33_device_register;
138 
139 	lcp = lca_preinit();
140 	iot = &lcp->lc_iot;
141 	if (bus_space_map(iot, NSIO_PORT, NSIO_SIZE, 0, &nsio))
142 		return;
143 
144 	bus_space_write_1(iot, nsio, NSIO_INDEX, NSIO_CFG0);
145 	A33_NSIOBARRIER(BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);
146 	cfg0val = bus_space_read_1(iot, nsio, NSIO_DATA);
147 
148 	cfg0val |= NSIO_IDE_ENABLE;
149 
150 	bus_space_write_1(iot, nsio, NSIO_INDEX, NSIO_CFG0);
151 	A33_NSIOBARRIER(BUS_SPACE_BARRIER_WRITE);
152 	bus_space_write_1(iot, nsio, NSIO_DATA, cfg0val);
153 	A33_NSIOBARRIER(BUS_SPACE_BARRIER_WRITE);
154 	bus_space_write_1(iot, nsio, NSIO_DATA, cfg0val);
155 
156 	/* Leave nsio mapped to catch any accidental port space collisions  */
157 
158 	/*
159 	 * AXPpci33 systems have either 0, 256K, or 1M secondary
160 	 * caches.  Default to middle-of-the-road.
161 	 *
162 	 * XXX Dynamically size it!
163 	 */
164 	uvmexp.ncolors = atop(256 * 1024);
165 }
166 
167 static void
168 dec_axppci_33_cons_init()
169 {
170 	struct ctb *ctb;
171 	struct lca_config *lcp;
172 
173 	lcp = lca_preinit();
174 
175 	ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
176 
177 	switch (ctb->ctb_term_type) {
178 	case CTB_PRINTERPORT:
179 		/* serial console ... */
180 		/* XXX */
181 		{
182 			/*
183 			 * Delay to allow PROM putchars to complete.
184 			 * FIFO depth * character time,
185 			 * character time = (1000000 / (defaultrate / 10))
186 			 */
187 			DELAY(160000000 / comcnrate);
188 
189 			if(comcnattach(&lcp->lc_iot, 0x3f8, comcnrate,
190 			    COM_FREQ,
191 			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
192 				panic("can't init serial console");
193 
194 			break;
195 		}
196 
197 	case CTB_GRAPHICS:
198 #if NPCKBD > 0
199 		/* display console ... */
200 		/* XXX */
201 		(void) pckbc_cnattach(&lcp->lc_iot, IO_KBD, KBCMDP,
202 		    PCKBC_KBD_SLOT);
203 
204 		if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) ==
205 		    CTB_TURBOSLOT_TYPE_ISA)
206 			isa_display_console(&lcp->lc_iot, &lcp->lc_memt);
207 		else
208 			pci_display_console(&lcp->lc_iot, &lcp->lc_memt,
209 			    &lcp->lc_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot),
210 			    CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0);
211 #else
212 		panic("not configured to use display && keyboard console");
213 #endif
214 		break;
215 
216 	default:
217 		printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type);
218 		printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot);
219 
220 		panic("consinit: unknown console type %ld\n",
221 		    ctb->ctb_term_type);
222 	}
223 #ifdef KGDB
224 	/* Attach the KGDB device. */
225 	alpha_kgdb_init(kgdb_devlist, &lcp->lc_iot);
226 #endif /* KGDB */
227 }
228 
229 static void
230 dec_axppci_33_device_register(dev, aux)
231 	struct device *dev;
232 	void *aux;
233 {
234 	static int found, initted, scsiboot, netboot;
235 	static struct device *pcidev, *scsidev;
236 	struct bootdev_data *b = bootdev_data;
237 	struct device *parent = dev->dv_parent;
238 	struct cfdata *cf = dev->dv_cfdata;
239 	struct cfdriver *cd = cf->cf_driver;
240 
241 	if (found)
242 		return;
243 
244 	if (!initted) {
245 		scsiboot = (strcmp(b->protocol, "SCSI") == 0);
246 		netboot = (strcmp(b->protocol, "BOOTP") == 0) ||
247 		    (strcmp(b->protocol, "MOP") == 0);
248 #if 0
249 		printf("scsiboot = %d, netboot = %d\n", scsiboot, netboot);
250 #endif
251 		initted =1;
252 	}
253 
254 	if (pcidev == NULL) {
255 		if (strcmp(cd->cd_name, "pci"))
256 			return;
257 		else {
258 			struct pcibus_attach_args *pba = aux;
259 
260 			if ((b->slot / 1000) != pba->pba_bus)
261 				return;
262 
263 			pcidev = dev;
264 #if 0
265 			printf("\npcidev = %s\n", pcidev->dv_xname);
266 #endif
267 			return;
268 		}
269 	}
270 
271 	if (scsiboot && (scsidev == NULL)) {
272 		if (parent != pcidev)
273 			return;
274 		else {
275 			struct pci_attach_args *pa = aux;
276 
277 			if ((b->slot % 1000) != pa->pa_device)
278 				return;
279 
280 			/* XXX function? */
281 
282 			scsidev = dev;
283 #if 0
284 			printf("\nscsidev = %s\n", scsidev->dv_xname);
285 #endif
286 			return;
287 		}
288 	}
289 
290 	if (scsiboot &&
291 	    (!strcmp(cd->cd_name, "sd") ||
292 	     !strcmp(cd->cd_name, "st") ||
293 	     !strcmp(cd->cd_name, "cd"))) {
294 		struct scsipibus_attach_args *sa = aux;
295 
296 		if (parent->dv_parent != scsidev)
297 			return;
298 
299 		if (b->unit / 100 != sa->sa_periph->periph_target)
300 			return;
301 
302 		/* XXX LUN! */
303 
304 		switch (b->boot_dev_type) {
305 		case 0:
306 			if (strcmp(cd->cd_name, "sd") &&
307 			    strcmp(cd->cd_name, "cd"))
308 				return;
309 			break;
310 		case 1:
311 			if (strcmp(cd->cd_name, "st"))
312 				return;
313 			break;
314 		default:
315 			return;
316 		}
317 
318 		/* we've found it! */
319 		booted_device = dev;
320 #if 0
321 		printf("\nbooted_device = %s\n", booted_device->dv_xname);
322 #endif
323 		found = 1;
324 	}
325 
326 	if (netboot) {
327 		if (parent != pcidev)
328 			return;
329 		else {
330 			struct pci_attach_args *pa = aux;
331 
332 			if ((b->slot % 1000) != pa->pa_device)
333 				return;
334 
335 			/* XXX function? */
336 
337 			booted_device = dev;
338 #if 0
339 			printf("\nbooted_device = %s\n", booted_device->dv_xname);
340 #endif
341 			found = 1;
342 			return;
343 		}
344 	}
345 }
346