xref: /titanic_41/usr/src/uts/i86pc/io/isa.c (revision 450396635f70344c58b6b1e4db38cf17ff34445c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  *	ISA bus nexus driver
28  */
29 
30 #include <sys/types.h>
31 #include <sys/cmn_err.h>
32 #include <sys/conf.h>
33 #include <sys/modctl.h>
34 #include <sys/autoconf.h>
35 #include <sys/errno.h>
36 #include <sys/debug.h>
37 #include <sys/kmem.h>
38 #include <sys/psm.h>
39 #include <sys/ddidmareq.h>
40 #include <sys/ddi_impldefs.h>
41 #include <sys/ddi_subrdefs.h>
42 #include <sys/dma_engine.h>
43 #include <sys/ddi.h>
44 #include <sys/sunddi.h>
45 #include <sys/sunndi.h>
46 #include <sys/acpi/acpi_enum.h>
47 #include <sys/mach_intr.h>
48 #include <sys/pci.h>
49 #include <sys/note.h>
50 #include <sys/boot_console.h>
51 #if defined(__xpv)
52 #include <sys/hypervisor.h>
53 #include <sys/evtchn_impl.h>
54 
55 extern int console_hypervisor_device;
56 #endif
57 
58 extern int pseudo_isa;
59 extern int isa_resource_setup(void);
60 extern int (*psm_intr_ops)(dev_info_t *, ddi_intr_handle_impl_t *,
61     psm_intr_op_t, int *);
62 extern void pci_register_isa_resources(int, uint32_t, uint32_t);
63 static char USED_RESOURCES[] = "used-resources";
64 static void isa_enumerate(int);
65 static void enumerate_BIOS_serial(dev_info_t *);
66 static void adjust_prtsz(dev_info_t *isa_dip);
67 static void isa_create_ranges_prop(dev_info_t *);
68 
69 /*
70  * The following typedef is used to represent an entry in the "ranges"
71  * property of a pci-isa bridge device node.
72  */
73 typedef struct {
74 	uint32_t child_high;
75 	uint32_t child_low;
76 	uint32_t parent_high;
77 	uint32_t parent_mid;
78 	uint32_t parent_low;
79 	uint32_t size;
80 } pib_ranges_t;
81 
82 typedef struct {
83 	uint32_t base;
84 	uint32_t len;
85 } used_ranges_t;
86 
87 #define	USED_CELL_SIZE	2	/* 1 byte addr, 1 byte size */
88 #define	ISA_ADDR_IO	1	/* IO address space */
89 #define	ISA_ADDR_MEM	0	/* memory adress space */
90 #define	BIOS_DATA_AREA	0x400
91 /*
92  * #define ISA_DEBUG 1
93  */
94 
95 /*
96  * For serial ports not enumerated by ACPI, and parallel ports with
97  * illegal size. Typically, a system can have as many as 4 serial
98  * ports and 3 parallel ports.
99  */
100 #define	MAX_EXTRA_RESOURCE	7
101 static struct regspec isa_extra_resource[MAX_EXTRA_RESOURCE];
102 static int isa_extra_count = 0;
103 
104 /*
105  *      Local data
106  */
107 static ddi_dma_lim_t ISA_dma_limits = {
108 	0,		/* address low				*/
109 	0x00ffffff,	/* address high				*/
110 	0,		/* counter max				*/
111 	1,		/* burstsize				*/
112 	DMA_UNIT_8,	/* minimum xfer				*/
113 	0,		/* dma speed				*/
114 	(uint_t)DMALIM_VER0, /* version				*/
115 	0x0000ffff,	/* address register			*/
116 	0x0000ffff,	/* counter register			*/
117 	1,		/* sector size				*/
118 	0x00000001,	/* scatter/gather list length		*/
119 	(uint_t)0xffffffff /* request size			*/
120 };
121 
122 static ddi_dma_attr_t ISA_dma_attr = {
123 	DMA_ATTR_V0,
124 	(unsigned long long)0,
125 	(unsigned long long)0x00ffffff,
126 	0x0000ffff,
127 	1,
128 	1,
129 	1,
130 	(unsigned long long)0xffffffff,
131 	(unsigned long long)0x0000ffff,
132 	1,
133 	1,
134 	0
135 };
136 
137 
138 /*
139  * Config information
140  */
141 
142 static int
143 isa_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
144     off_t offset, off_t len, caddr_t *vaddrp);
145 
146 static int
147 isa_dma_allochdl(dev_info_t *, dev_info_t *, ddi_dma_attr_t *,
148     int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *);
149 
150 static int
151 isa_dma_mctl(dev_info_t *, dev_info_t *, ddi_dma_handle_t, enum ddi_dma_ctlops,
152     off_t *, size_t *, caddr_t *, uint_t);
153 
154 static int
155 isa_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *);
156 
157 static int
158 isa_intr_ops(dev_info_t *pdip, dev_info_t *rdip, ddi_intr_op_t intr_op,
159     ddi_intr_handle_impl_t *hdlp, void *result);
160 
161 struct bus_ops isa_bus_ops = {
162 	BUSO_REV,
163 	isa_bus_map,
164 	NULL,
165 	NULL,
166 	NULL,
167 	i_ddi_map_fault,
168 	ddi_dma_map,
169 	isa_dma_allochdl,
170 	ddi_dma_freehdl,
171 	ddi_dma_bindhdl,
172 	ddi_dma_unbindhdl,
173 	ddi_dma_flush,
174 	ddi_dma_win,
175 	isa_dma_mctl,
176 	isa_ctlops,
177 	ddi_bus_prop_op,
178 	NULL,		/* (*bus_get_eventcookie)();	*/
179 	NULL,		/* (*bus_add_eventcall)();	*/
180 	NULL,		/* (*bus_remove_eventcall)();	*/
181 	NULL,		/* (*bus_post_event)();		*/
182 	NULL,		/* (*bus_intr_ctl)(); */
183 	NULL,		/* (*bus_config)(); */
184 	NULL,		/* (*bus_unconfig)(); */
185 	NULL,		/* (*bus_fm_init)(); */
186 	NULL,		/* (*bus_fm_fini)(); */
187 	NULL,		/* (*bus_fm_access_enter)(); */
188 	NULL,		/* (*bus_fm_access_exit)(); */
189 	NULL,		/* (*bus_power)(); */
190 	isa_intr_ops	/* (*bus_intr_op)(); */
191 };
192 
193 
194 static int isa_attach(dev_info_t *devi, ddi_attach_cmd_t cmd);
195 
196 /*
197  * Internal isa ctlops support routines
198  */
199 static int isa_initchild(dev_info_t *child);
200 
201 struct dev_ops isa_ops = {
202 	DEVO_REV,		/* devo_rev, */
203 	0,			/* refcnt  */
204 	ddi_no_info,		/* info */
205 	nulldev,		/* identify */
206 	nulldev,		/* probe */
207 	isa_attach,		/* attach */
208 	nulldev,		/* detach */
209 	nodev,			/* reset */
210 	(struct cb_ops *)0,	/* driver operations */
211 	&isa_bus_ops,		/* bus operations */
212 	NULL,			/* power */
213 	ddi_quiesce_not_needed,		/* quiesce */
214 };
215 
216 /*
217  * Module linkage information for the kernel.
218  */
219 
220 static struct modldrv modldrv = {
221 	&mod_driverops, /* Type of module.  This is ISA bus driver */
222 	"isa nexus driver for 'ISA'",
223 	&isa_ops,	/* driver ops */
224 };
225 
226 static struct modlinkage modlinkage = {
227 	MODREV_1,
228 	&modldrv,
229 	NULL
230 };
231 
232 int
233 _init(void)
234 {
235 	int	err;
236 
237 	if ((err = mod_install(&modlinkage)) != 0)
238 		return (err);
239 
240 	impl_bus_add_probe(isa_enumerate);
241 	return (0);
242 }
243 
244 int
245 _fini(void)
246 {
247 	int	err;
248 
249 	impl_bus_delete_probe(isa_enumerate);
250 
251 	if ((err = mod_remove(&modlinkage)) != 0)
252 		return (err);
253 
254 	return (0);
255 }
256 
257 int
258 _info(struct modinfo *modinfop)
259 {
260 	return (mod_info(&modlinkage, modinfop));
261 }
262 
263 static int
264 isa_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
265 {
266 	int rval;
267 
268 #if defined(__xpv)
269 	/*
270 	 * don't allow isa to attach in domU. this can happen if someone sets
271 	 * the console wrong, etc. ISA devices assume the H/W is there and
272 	 * will cause the domU to panic.
273 	 */
274 	if (!DOMAIN_IS_INITDOMAIN(xen_info)) {
275 		return (DDI_FAILURE);
276 	}
277 #endif
278 
279 	switch (cmd) {
280 	case DDI_ATTACH:
281 		break;
282 	case DDI_RESUME:
283 		return (DDI_SUCCESS);
284 	default:
285 		return (DDI_FAILURE);
286 	}
287 
288 	if ((rval = i_dmae_init(devi)) == DDI_SUCCESS)
289 		ddi_report_dev(devi);
290 
291 	return (rval);
292 }
293 
294 #define	SET_RNGS(rng_p, used_p, ctyp, ptyp) do {			\
295 		(rng_p)->child_high = (ctyp);				\
296 		(rng_p)->child_low = (rng_p)->parent_low = (used_p)->base; \
297 		(rng_p)->parent_high = (ptyp);				\
298 		(rng_p)->parent_mid = 0;				\
299 		(rng_p)->size = (used_p)->len;				\
300 		_NOTE(CONSTCOND) } while (0)
301 static uint_t
302 isa_used_to_ranges(int ctype, int *array, uint_t size, pib_ranges_t *ranges)
303 {
304 	used_ranges_t *used_p;
305 	pib_ranges_t *rng_p = ranges;
306 	uint_t	i, ptype;
307 
308 	ptype = (ctype == ISA_ADDR_IO) ? PCI_ADDR_IO : PCI_ADDR_MEM32;
309 	ptype |= PCI_REG_REL_M;
310 	size /= USED_CELL_SIZE;
311 	used_p = (used_ranges_t *)array;
312 	SET_RNGS(rng_p, used_p, ctype, ptype);
313 	for (i = 1, used_p++; i < size; i++, used_p++) {
314 		/* merge ranges record if applicable */
315 		if (rng_p->child_low + rng_p->size == used_p->base)
316 			rng_p->size += used_p->len;
317 		else {
318 			rng_p++;
319 			SET_RNGS(rng_p, used_p, ctype, ptype);
320 		}
321 	}
322 	return (rng_p - ranges + 1);
323 }
324 
325 void
326 isa_remove_res_from_pci(int type, int *array, uint_t size)
327 {
328 	int i;
329 	used_ranges_t *used_p;
330 
331 	size /= USED_CELL_SIZE;
332 	used_p = (used_ranges_t *)array;
333 	for (i = 0; i < size; i++, used_p++)
334 		pci_register_isa_resources(type, used_p->base, used_p->len);
335 }
336 
337 static void
338 isa_create_ranges_prop(dev_info_t *dip)
339 {
340 	dev_info_t *used;
341 	int *ioarray, *memarray, status;
342 	uint_t nio = 0, nmem = 0, nrng = 0, n;
343 	pib_ranges_t *ranges;
344 
345 	used = ddi_find_devinfo("used-resources", -1, 0);
346 	if (used == NULL) {
347 		cmn_err(CE_WARN, "Failed to find used-resources <%s>\n",
348 		    ddi_get_name(dip));
349 		return;
350 	}
351 	status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, used,
352 	    DDI_PROP_DONTPASS, "io-space", &ioarray, &nio);
353 	if (status != DDI_PROP_SUCCESS && status != DDI_PROP_NOT_FOUND) {
354 		cmn_err(CE_WARN, "io-space property failure for %s (%x)\n",
355 		    ddi_get_name(used), status);
356 		return;
357 	}
358 	status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, used,
359 	    DDI_PROP_DONTPASS, "device-memory", &memarray, &nmem);
360 	if (status != DDI_PROP_SUCCESS && status != DDI_PROP_NOT_FOUND) {
361 		cmn_err(CE_WARN, "device-memory property failure for %s (%x)\n",
362 		    ddi_get_name(used), status);
363 		return;
364 	}
365 	n = (nio + nmem) / USED_CELL_SIZE;
366 	ranges =  (pib_ranges_t *)kmem_zalloc(sizeof (pib_ranges_t) * n,
367 	    KM_SLEEP);
368 
369 	if (nio != 0) {
370 		nrng = isa_used_to_ranges(ISA_ADDR_IO, ioarray, nio, ranges);
371 		isa_remove_res_from_pci(ISA_ADDR_IO, ioarray, nio);
372 		ddi_prop_free(ioarray);
373 	}
374 	if (nmem != 0) {
375 		nrng += isa_used_to_ranges(ISA_ADDR_MEM, memarray, nmem,
376 		    ranges + nrng);
377 		isa_remove_res_from_pci(ISA_ADDR_MEM, memarray, nmem);
378 		ddi_prop_free(memarray);
379 	}
380 
381 	if (!pseudo_isa)
382 		(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, dip, "ranges",
383 		    (int *)ranges, nrng * sizeof (pib_ranges_t) / sizeof (int));
384 	kmem_free(ranges, sizeof (pib_ranges_t) * n);
385 }
386 
387 /*ARGSUSED*/
388 static int
389 isa_apply_range(dev_info_t *dip, struct regspec *isa_reg_p,
390     pci_regspec_t *pci_reg_p)
391 {
392 	pib_ranges_t *ranges, *rng_p;
393 	int len, i, offset, nrange;
394 
395 	if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
396 	    "ranges", (caddr_t)&ranges, &len) != DDI_SUCCESS) {
397 		cmn_err(CE_WARN, "Can't get %s ranges property",
398 		    ddi_get_name(dip));
399 		return (DDI_ME_REGSPEC_RANGE);
400 	}
401 	nrange = len / sizeof (pib_ranges_t);
402 	rng_p = ranges;
403 	for (i = 0; i < nrange; i++, rng_p++) {
404 		/* Check for correct space */
405 		if (isa_reg_p->regspec_bustype != rng_p->child_high)
406 			continue;
407 
408 		/* Detect whether request entirely fits within a range */
409 		if (isa_reg_p->regspec_addr < rng_p->child_low)
410 			continue;
411 		if ((isa_reg_p->regspec_addr + isa_reg_p->regspec_size - 1) >
412 		    (rng_p->child_low + rng_p->size - 1))
413 			continue;
414 
415 		offset = isa_reg_p->regspec_addr - rng_p->child_low;
416 
417 		pci_reg_p->pci_phys_hi = rng_p->parent_high;
418 		pci_reg_p->pci_phys_mid = 0;
419 		pci_reg_p->pci_phys_low = rng_p->parent_low + offset;
420 		pci_reg_p->pci_size_hi = 0;
421 		pci_reg_p->pci_size_low = isa_reg_p->regspec_size;
422 
423 		break;
424 	}
425 	kmem_free(ranges, len);
426 
427 	if (i < nrange)
428 		return (DDI_SUCCESS);
429 
430 	/*
431 	 * Check extra resource range specially for serial and parallel
432 	 * devices, which are treated differently from all other ISA
433 	 * devices. On some machines, serial ports are not enumerated
434 	 * by ACPI but by BIOS, with io base addresses noted in legacy
435 	 * BIOS data area. Parallel port on some machines comes with
436 	 * illegal size.
437 	 */
438 	if (isa_reg_p->regspec_bustype != ISA_ADDR_IO)
439 		goto out_of_range;
440 
441 	for (i = 0; i < isa_extra_count; i++) {
442 		struct regspec *reg_p = &isa_extra_resource[i];
443 
444 		if (isa_reg_p->regspec_addr < reg_p->regspec_addr)
445 			continue;
446 		if ((isa_reg_p->regspec_addr + isa_reg_p->regspec_size) >
447 		    (reg_p->regspec_addr + reg_p->regspec_size))
448 			continue;
449 
450 		pci_reg_p->pci_phys_hi = PCI_ADDR_IO | PCI_REG_REL_M;
451 		pci_reg_p->pci_phys_mid = 0;
452 		pci_reg_p->pci_phys_low = isa_reg_p->regspec_addr;
453 		pci_reg_p->pci_size_hi = 0;
454 		pci_reg_p->pci_size_low = isa_reg_p->regspec_size;
455 		break;
456 	}
457 	if (i < isa_extra_count)
458 		return (DDI_SUCCESS);
459 
460 out_of_range:
461 	cmn_err(CE_WARN, "isa_apply_range: Out of range base <0x%x>, size <%d>",
462 	    isa_reg_p->regspec_addr, isa_reg_p->regspec_size);
463 	return (DDI_ME_REGSPEC_RANGE);
464 }
465 
466 static int
467 isa_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
468     off_t offset, off_t len, caddr_t *vaddrp)
469 {
470 	struct regspec tmp_reg, *rp;
471 	pci_regspec_t vreg;
472 	ddi_map_req_t mr = *mp;		/* Get private copy of request */
473 	int error;
474 
475 	if (pseudo_isa)
476 		return (i_ddi_bus_map(dip, rdip, mp, offset, len, vaddrp));
477 
478 	mp = &mr;
479 
480 	/*
481 	 * First, if given an rnumber, convert it to a regspec...
482 	 */
483 	if (mp->map_type == DDI_MT_RNUMBER)  {
484 
485 		int rnumber = mp->map_obj.rnumber;
486 
487 		rp = i_ddi_rnumber_to_regspec(rdip, rnumber);
488 		if (rp == (struct regspec *)0)
489 			return (DDI_ME_RNUMBER_RANGE);
490 
491 		/*
492 		 * Convert the given ddi_map_req_t from rnumber to regspec...
493 		 */
494 		mp->map_type = DDI_MT_REGSPEC;
495 		mp->map_obj.rp = rp;
496 	}
497 
498 	/*
499 	 * Adjust offset and length correspnding to called values...
500 	 * XXX: A non-zero length means override the one in the regspec.
501 	 * XXX: (Regardless of what's in the parent's range)
502 	 */
503 
504 	tmp_reg = *(mp->map_obj.rp);		/* Preserve underlying data */
505 	rp = mp->map_obj.rp = &tmp_reg;		/* Use tmp_reg in request */
506 
507 	rp->regspec_addr += (uint_t)offset;
508 	if (len != 0)
509 		rp->regspec_size = (uint_t)len;
510 
511 	if ((error = isa_apply_range(dip, rp, &vreg)) != 0)
512 		return (error);
513 	mp->map_obj.rp = (struct regspec *)&vreg;
514 
515 	/*
516 	 * Call my parents bus_map function with modified values...
517 	 */
518 
519 	return (ddi_map(dip, mp, (off_t)0, (off_t)0, vaddrp));
520 }
521 
522 static int
523 isa_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *dma_attr,
524     int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep)
525 {
526 	ddi_dma_attr_merge(dma_attr, &ISA_dma_attr);
527 	return (ddi_dma_allochdl(dip, rdip, dma_attr, waitfp, arg, handlep));
528 }
529 
530 static int
531 isa_dma_mctl(dev_info_t *dip, dev_info_t *rdip,
532     ddi_dma_handle_t handle, enum ddi_dma_ctlops request,
533     off_t *offp, size_t *lenp, caddr_t *objp, uint_t flags)
534 {
535 	int rval;
536 	ddi_dma_lim_t defalt;
537 	int arg = (int)(uintptr_t)objp;
538 
539 	switch (request) {
540 
541 	case DDI_DMA_E_PROG:
542 		return (i_dmae_prog(rdip, (struct ddi_dmae_req *)offp,
543 		    (ddi_dma_cookie_t *)lenp, arg));
544 
545 	case DDI_DMA_E_ACQUIRE:
546 		return (i_dmae_acquire(rdip, arg, (int(*)(caddr_t))offp,
547 		    (caddr_t)lenp));
548 
549 	case DDI_DMA_E_FREE:
550 		return (i_dmae_free(rdip, arg));
551 
552 	case DDI_DMA_E_STOP:
553 		i_dmae_stop(rdip, arg);
554 		return (DDI_SUCCESS);
555 
556 	case DDI_DMA_E_ENABLE:
557 		i_dmae_enable(rdip, arg);
558 		return (DDI_SUCCESS);
559 
560 	case DDI_DMA_E_DISABLE:
561 		i_dmae_disable(rdip, arg);
562 		return (DDI_SUCCESS);
563 
564 	case DDI_DMA_E_GETCNT:
565 		i_dmae_get_chan_stat(rdip, arg, NULL, (int *)lenp);
566 		return (DDI_SUCCESS);
567 
568 	case DDI_DMA_E_SWSETUP:
569 		return (i_dmae_swsetup(rdip, (struct ddi_dmae_req *)offp,
570 		    (ddi_dma_cookie_t *)lenp, arg));
571 
572 	case DDI_DMA_E_SWSTART:
573 		i_dmae_swstart(rdip, arg);
574 		return (DDI_SUCCESS);
575 
576 	case DDI_DMA_E_GETLIM:
577 		bcopy(&ISA_dma_limits, objp, sizeof (ddi_dma_lim_t));
578 		return (DDI_SUCCESS);
579 
580 	case DDI_DMA_E_GETATTR:
581 		bcopy(&ISA_dma_attr, objp, sizeof (ddi_dma_attr_t));
582 		return (DDI_SUCCESS);
583 
584 	case DDI_DMA_E_1STPTY:
585 		{
586 			struct ddi_dmae_req req1stpty =
587 			    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
588 			if (arg == 0) {
589 				req1stpty.der_command = DMAE_CMD_TRAN;
590 				req1stpty.der_trans = DMAE_TRANS_DMND;
591 			} else {
592 				req1stpty.der_trans = DMAE_TRANS_CSCD;
593 			}
594 			return (i_dmae_prog(rdip, &req1stpty, NULL, arg));
595 		}
596 
597 	case DDI_DMA_IOPB_ALLOC:	/* get contiguous DMA-able memory */
598 	case DDI_DMA_SMEM_ALLOC:
599 		if (!offp) {
600 			defalt = ISA_dma_limits;
601 			offp = (off_t *)&defalt;
602 		}
603 		/*FALLTHROUGH*/
604 	default:
605 		rval = ddi_dma_mctl(dip, rdip, handle, request, offp,
606 		    lenp, objp, flags);
607 	}
608 	return (rval);
609 }
610 
611 /*
612  * Check if driver should be treated as an old pre 2.6 driver
613  */
614 static int
615 old_driver(dev_info_t *dip)
616 {
617 	extern int ignore_hardware_nodes;	/* force flag from ddi_impl.c */
618 
619 	if (ndi_dev_is_persistent_node(dip)) {
620 		if (ignore_hardware_nodes)
621 			return (1);
622 		if (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
623 		    "ignore-hardware-nodes", -1) != -1)
624 			return (1);
625 	}
626 	return (0);
627 }
628 
629 typedef struct {
630 	uint32_t phys_hi;
631 	uint32_t phys_lo;
632 	uint32_t size;
633 } isa_regs_t;
634 
635 /*
636  * Return non-zero if device in tree is a PnP isa device
637  */
638 static int
639 is_pnpisa(dev_info_t *dip)
640 {
641 	isa_regs_t *isa_regs;
642 	int proplen, pnpisa;
643 
644 	if (ndi_dev_is_persistent_node(dip) == 0)
645 		return (0);
646 	if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "reg",
647 	    (caddr_t)&isa_regs, &proplen) != DDI_PROP_SUCCESS) {
648 		return (0);
649 	}
650 	pnpisa = isa_regs[0].phys_hi & 0x80000000;
651 	/*
652 	 * free the memory allocated by ddi_getlongprop().
653 	 */
654 	kmem_free(isa_regs, proplen);
655 	if (pnpisa)
656 		return (1);
657 	else
658 		return (0);
659 }
660 
661 /*ARGSUSED*/
662 static int
663 isa_ctlops(dev_info_t *dip, dev_info_t *rdip,
664 	ddi_ctl_enum_t ctlop, void *arg, void *result)
665 {
666 	int rn;
667 	struct ddi_parent_private_data *pdp;
668 
669 	switch (ctlop) {
670 	case DDI_CTLOPS_REPORTDEV:
671 		if (rdip == (dev_info_t *)0)
672 			return (DDI_FAILURE);
673 		cmn_err(CE_CONT, "?ISA-device: %s%d\n",
674 		    ddi_driver_name(rdip), ddi_get_instance(rdip));
675 		return (DDI_SUCCESS);
676 
677 	case DDI_CTLOPS_INITCHILD:
678 		/*
679 		 * older drivers aren't expecting the "standard" device
680 		 * node format used by the hardware nodes.  these drivers
681 		 * only expect their own properties set in their driver.conf
682 		 * files.  so they tell us not to call them with hardware
683 		 * nodes by setting the property "ignore-hardware-nodes".
684 		 */
685 		if (old_driver((dev_info_t *)arg)) {
686 			return (DDI_NOT_WELL_FORMED);
687 		}
688 
689 		return (isa_initchild((dev_info_t *)arg));
690 
691 	case DDI_CTLOPS_UNINITCHILD:
692 		impl_ddi_sunbus_removechild((dev_info_t *)arg);
693 		return (DDI_SUCCESS);
694 
695 	case DDI_CTLOPS_SIDDEV:
696 		/*
697 		 * All ISA devices need to do confirming probes
698 		 * unless they are PnP ISA.
699 		 */
700 		if (is_pnpisa(dip))
701 			return (DDI_SUCCESS);
702 		else
703 			return (DDI_FAILURE);
704 
705 	case DDI_CTLOPS_REGSIZE:
706 	case DDI_CTLOPS_NREGS:
707 		if (rdip == (dev_info_t *)0)
708 			return (DDI_FAILURE);
709 
710 		if ((pdp = ddi_get_parent_data(rdip)) == NULL)
711 			return (DDI_FAILURE);
712 
713 		if (ctlop == DDI_CTLOPS_NREGS) {
714 			*(int *)result = pdp->par_nreg;
715 		} else {
716 			rn = *(int *)arg;
717 			if (rn >= pdp->par_nreg)
718 				return (DDI_FAILURE);
719 			*(off_t *)result = (off_t)pdp->par_reg[rn].regspec_size;
720 		}
721 		return (DDI_SUCCESS);
722 
723 	case DDI_CTLOPS_ATTACH:
724 	case DDI_CTLOPS_DETACH:
725 	case DDI_CTLOPS_PEEK:
726 	case DDI_CTLOPS_POKE:
727 		return (DDI_FAILURE);
728 
729 	default:
730 		return (ddi_ctlops(dip, rdip, ctlop, arg, result));
731 	}
732 }
733 
734 static struct intrspec *
735 isa_get_ispec(dev_info_t *rdip, int inum)
736 {
737 	struct ddi_parent_private_data *pdp = ddi_get_parent_data(rdip);
738 
739 	/* Validate the interrupt number */
740 	if (inum >= pdp->par_nintr)
741 		return (NULL);
742 
743 	/* Get the interrupt structure pointer and return that */
744 	return ((struct intrspec *)&pdp->par_intr[inum]);
745 }
746 
747 static int
748 isa_intr_ops(dev_info_t *pdip, dev_info_t *rdip, ddi_intr_op_t intr_op,
749     ddi_intr_handle_impl_t *hdlp, void *result)
750 {
751 	struct intrspec *ispec;
752 
753 	if (pseudo_isa)
754 		return (i_ddi_intr_ops(pdip, rdip, intr_op, hdlp, result));
755 
756 
757 	/* Process the interrupt operation */
758 	switch (intr_op) {
759 	case DDI_INTROP_GETCAP:
760 		/* First check with pcplusmp */
761 		if (psm_intr_ops == NULL)
762 			return (DDI_FAILURE);
763 
764 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_GET_CAP, result)) {
765 			*(int *)result = 0;
766 			return (DDI_FAILURE);
767 		}
768 		break;
769 	case DDI_INTROP_SETCAP:
770 		if (psm_intr_ops == NULL)
771 			return (DDI_FAILURE);
772 
773 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_SET_CAP, result))
774 			return (DDI_FAILURE);
775 		break;
776 	case DDI_INTROP_ALLOC:
777 		if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)
778 			return (DDI_FAILURE);
779 		hdlp->ih_pri = ispec->intrspec_pri;
780 		*(int *)result = hdlp->ih_scratch1;
781 		break;
782 	case DDI_INTROP_FREE:
783 		break;
784 	case DDI_INTROP_GETPRI:
785 		if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)
786 			return (DDI_FAILURE);
787 		*(int *)result = ispec->intrspec_pri;
788 		break;
789 	case DDI_INTROP_SETPRI:
790 		/* Validate the interrupt priority passed to us */
791 		if (*(int *)result > LOCK_LEVEL)
792 			return (DDI_FAILURE);
793 
794 		/* Ensure that PSM is all initialized and ispec is ok */
795 		if ((psm_intr_ops == NULL) ||
796 		    ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL))
797 			return (DDI_FAILURE);
798 
799 		/* update the ispec with the new priority */
800 		ispec->intrspec_pri =  *(int *)result;
801 		break;
802 	case DDI_INTROP_ADDISR:
803 		if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)
804 			return (DDI_FAILURE);
805 		ispec->intrspec_func = hdlp->ih_cb_func;
806 		break;
807 	case DDI_INTROP_REMISR:
808 		if (hdlp->ih_type != DDI_INTR_TYPE_FIXED)
809 			return (DDI_FAILURE);
810 		if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)
811 			return (DDI_FAILURE);
812 		ispec->intrspec_func = (uint_t (*)()) 0;
813 		break;
814 	case DDI_INTROP_ENABLE:
815 		if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)
816 			return (DDI_FAILURE);
817 
818 		/* Call psmi to translate irq with the dip */
819 		if (psm_intr_ops == NULL)
820 			return (DDI_FAILURE);
821 
822 #if defined(__xpv)
823 		/*
824 		 * if the hypervisor is using an isa serial port for the
825 		 * console, make sure we don't try to use that interrupt as
826 		 * it will cause us to panic when xen_bind_pirq() fails.
827 		 */
828 		if (((ispec->intrspec_vec == 4) &&
829 		    (console_hypervisor_device == CONS_TTYA)) ||
830 		    ((ispec->intrspec_vec == 3) &&
831 		    (console_hypervisor_device == CONS_TTYB))) {
832 			return (DDI_FAILURE);
833 		}
834 #endif
835 		((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispec;
836 		(void) (*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_XLATE_VECTOR,
837 		    (int *)&hdlp->ih_vector);
838 
839 		/* Add the interrupt handler */
840 		if (!add_avintr((void *)hdlp, ispec->intrspec_pri,
841 		    hdlp->ih_cb_func, DEVI(rdip)->devi_name, hdlp->ih_vector,
842 		    hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, NULL, rdip))
843 			return (DDI_FAILURE);
844 		break;
845 	case DDI_INTROP_DISABLE:
846 		if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)
847 			return (DDI_FAILURE);
848 
849 		/* Call psm_ops() to translate irq with the dip */
850 		if (psm_intr_ops == NULL)
851 			return (DDI_FAILURE);
852 
853 		((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispec;
854 		(void) (*psm_intr_ops)(rdip, hdlp,
855 		    PSM_INTR_OP_XLATE_VECTOR, (int *)&hdlp->ih_vector);
856 
857 		/* Remove the interrupt handler */
858 		rem_avintr((void *)hdlp, ispec->intrspec_pri,
859 		    hdlp->ih_cb_func, hdlp->ih_vector);
860 		break;
861 	case DDI_INTROP_SETMASK:
862 		if (psm_intr_ops == NULL)
863 			return (DDI_FAILURE);
864 
865 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_SET_MASK, NULL))
866 			return (DDI_FAILURE);
867 		break;
868 	case DDI_INTROP_CLRMASK:
869 		if (psm_intr_ops == NULL)
870 			return (DDI_FAILURE);
871 
872 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_CLEAR_MASK, NULL))
873 			return (DDI_FAILURE);
874 		break;
875 	case DDI_INTROP_GETPENDING:
876 		if (psm_intr_ops == NULL)
877 			return (DDI_FAILURE);
878 
879 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_GET_PENDING,
880 		    result)) {
881 			*(int *)result = 0;
882 			return (DDI_FAILURE);
883 		}
884 		break;
885 	case DDI_INTROP_NAVAIL:
886 	case DDI_INTROP_NINTRS:
887 		*(int *)result = i_ddi_get_intx_nintrs(rdip);
888 		if (*(int *)result == 0) {
889 			return (DDI_FAILURE);
890 		}
891 		break;
892 	case DDI_INTROP_SUPPORTED_TYPES:
893 		*(int *)result = DDI_INTR_TYPE_FIXED;	/* Always ... */
894 		break;
895 	default:
896 		return (DDI_FAILURE);
897 	}
898 
899 	return (DDI_SUCCESS);
900 }
901 
902 static void
903 isa_vendor(uint32_t id, char *vendor)
904 {
905 	vendor[0] = '@' + ((id >> 26) & 0x1f);
906 	vendor[1] = '@' + ((id >> 21) & 0x1f);
907 	vendor[2] = '@' + ((id >> 16) & 0x1f);
908 	vendor[3] = 0;
909 }
910 
911 /*
912  * Name a child
913  */
914 static int
915 isa_name_child(dev_info_t *child, char *name, int namelen)
916 {
917 	char vendor[8];
918 	int device;
919 	uint32_t serial;
920 	int func;
921 	int bustype;
922 	uint32_t base;
923 	int proplen;
924 	int pnpisa = 0;
925 	isa_regs_t *isa_regs;
926 
927 	void make_ddi_ppd(dev_info_t *, struct ddi_parent_private_data **);
928 
929 	/*
930 	 * older drivers aren't expecting the "standard" device
931 	 * node format used by the hardware nodes.  these drivers
932 	 * only expect their own properties set in their driver.conf
933 	 * files.  so they tell us not to call them with hardware
934 	 * nodes by setting the property "ignore-hardware-nodes".
935 	 */
936 	if (old_driver(child))
937 		return (DDI_FAILURE);
938 
939 	/*
940 	 * Fill in parent-private data
941 	 */
942 	if (ddi_get_parent_data(child) == NULL) {
943 		struct ddi_parent_private_data *pdptr;
944 		make_ddi_ppd(child, &pdptr);
945 		ddi_set_parent_data(child, pdptr);
946 	}
947 
948 	if (ndi_dev_is_persistent_node(child) == 0) {
949 		/*
950 		 * For .conf nodes, generate name from parent private data
951 		 */
952 		name[0] = '\0';
953 		if (sparc_pd_getnreg(child) > 0) {
954 			(void) snprintf(name, namelen, "%x,%x",
955 			    (uint_t)sparc_pd_getreg(child, 0)->regspec_bustype,
956 			    (uint_t)sparc_pd_getreg(child, 0)->regspec_addr);
957 		}
958 		return (DDI_SUCCESS);
959 	}
960 
961 	/*
962 	 * For hw nodes, look up "reg" property
963 	 */
964 	if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, "reg",
965 	    (caddr_t)&isa_regs, &proplen) != DDI_PROP_SUCCESS) {
966 		return (DDI_FAILURE);
967 	}
968 
969 	/*
970 	 * extract the device identifications
971 	 */
972 	pnpisa = isa_regs[0].phys_hi & 0x80000000;
973 	if (pnpisa) {
974 		isa_vendor(isa_regs[0].phys_hi, vendor);
975 		device = isa_regs[0].phys_hi & 0xffff;
976 		serial = isa_regs[0].phys_lo;
977 		func = (isa_regs[0].size >> 24) & 0xff;
978 		if (func != 0)
979 			(void) snprintf(name, namelen, "pnp%s,%04x,%x,%x",
980 			    vendor, device, serial, func);
981 		else
982 			(void) snprintf(name, namelen, "pnp%s,%04x,%x",
983 			    vendor, device, serial);
984 	} else {
985 		bustype = isa_regs[0].phys_hi;
986 		base = isa_regs[0].phys_lo;
987 		(void) sprintf(name, "%x,%x", bustype, base);
988 	}
989 
990 	/*
991 	 * free the memory allocated by ddi_getlongprop().
992 	 */
993 	kmem_free(isa_regs, proplen);
994 
995 	return (DDI_SUCCESS);
996 }
997 
998 static int
999 isa_initchild(dev_info_t *child)
1000 {
1001 	char name[80];
1002 
1003 	if (isa_name_child(child, name, 80) != DDI_SUCCESS)
1004 		return (DDI_FAILURE);
1005 	ddi_set_name_addr(child, name);
1006 
1007 	if (ndi_dev_is_persistent_node(child) != 0)
1008 		return (DDI_SUCCESS);
1009 
1010 	/*
1011 	 * This is a .conf node, try merge properties onto a
1012 	 * hw node with the same name.
1013 	 */
1014 	if (ndi_merge_node(child, isa_name_child) == DDI_SUCCESS) {
1015 		/*
1016 		 * Return failure to remove node
1017 		 */
1018 		impl_ddi_sunbus_removechild(child);
1019 		return (DDI_FAILURE);
1020 	}
1021 	/*
1022 	 * Cannot merge node, permit pseudo children
1023 	 */
1024 	return (DDI_SUCCESS);
1025 }
1026 
1027 /*
1028  * called when ACPI enumeration is not used
1029  */
1030 static void
1031 add_known_used_resources(void)
1032 {
1033 	/* needs to be in increasing order */
1034 	int intr[] = {0x1, 0x3, 0x4, 0x6, 0x7, 0xc};
1035 	int dma[] = {0x2};
1036 	int io[] = {0x60, 0x1, 0x64, 0x1, 0x2f8, 0x8, 0x378, 0x8, 0x3f0, 0x10,
1037 	    0x778, 0x4};
1038 	dev_info_t *usedrdip;
1039 
1040 	usedrdip = ddi_find_devinfo(USED_RESOURCES, -1, 0);
1041 
1042 	if (usedrdip == NULL) {
1043 		(void) ndi_devi_alloc_sleep(ddi_root_node(), USED_RESOURCES,
1044 		    (pnode_t)DEVI_SID_NODEID, &usedrdip);
1045 	}
1046 
1047 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip,
1048 	    "interrupts", (int *)intr, (int)(sizeof (intr) / sizeof (int)));
1049 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip,
1050 	    "io-space", (int *)io, (int)(sizeof (io) / sizeof (int)));
1051 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip,
1052 	    "dma-channels", (int *)dma, (int)(sizeof (dma) / sizeof (int)));
1053 	(void) ndi_devi_bind_driver(usedrdip, 0);
1054 
1055 }
1056 
1057 static void
1058 isa_enumerate(int reprogram)
1059 {
1060 	int circ, i;
1061 	dev_info_t *xdip;
1062 	dev_info_t *isa_dip = ddi_find_devinfo("isa", -1, 0);
1063 
1064 	/* hard coded isa stuff */
1065 	struct regspec asy_regs[] = {
1066 		{1, 0x3f8, 0x8},
1067 		{1, 0x2f8, 0x8}
1068 	};
1069 	int asy_intrs[] = {0x4, 0x3};
1070 
1071 	struct regspec i8042_regs[] = {
1072 		{1, 0x60, 0x1},
1073 		{1, 0x64, 0x1}
1074 	};
1075 	int i8042_intrs[] = {0x1, 0xc};
1076 	char *acpi_prop;
1077 	int acpi_enum = 1; /* ACPI is default to be on */
1078 
1079 	if (reprogram || !isa_dip)
1080 		return;
1081 
1082 	bzero(isa_extra_resource, MAX_EXTRA_RESOURCE * sizeof (struct regspec));
1083 
1084 	ndi_devi_enter(isa_dip, &circ);
1085 
1086 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(),
1087 	    DDI_PROP_DONTPASS, "acpi-enum", &acpi_prop) == DDI_PROP_SUCCESS) {
1088 		acpi_enum = strcmp("off", acpi_prop);
1089 		ddi_prop_free(acpi_prop);
1090 	}
1091 
1092 	if (acpi_enum) {
1093 		if (acpi_isa_device_enum(isa_dip)) {
1094 			ndi_devi_exit(isa_dip, circ);
1095 			if (isa_resource_setup() != NDI_SUCCESS) {
1096 				cmn_err(CE_WARN, "isa nexus: isa "
1097 				    "resource setup failed");
1098 			}
1099 
1100 			/* serial ports? */
1101 			enumerate_BIOS_serial(isa_dip);
1102 
1103 			/* adjust parallel port size  */
1104 			adjust_prtsz(isa_dip);
1105 
1106 			isa_create_ranges_prop(isa_dip);
1107 			return;
1108 		}
1109 		cmn_err(CE_NOTE, "!Solaris did not detect ACPI BIOS");
1110 	}
1111 	cmn_err(CE_NOTE, "!ACPI is off");
1112 
1113 	/* serial ports */
1114 	for (i = 0; i < 2; i++) {
1115 #if defined(__xpv)
1116 		if ((i == 0 && console_hypervisor_device == CONS_TTYA) ||
1117 		    (i == 1 && console_hypervisor_device == CONS_TTYB)) {
1118 			continue;
1119 		}
1120 #endif
1121 		ndi_devi_alloc_sleep(isa_dip, "asy",
1122 		    (pnode_t)DEVI_SID_NODEID, &xdip);
1123 		(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip,
1124 		    "reg", (int *)&asy_regs[i], 3);
1125 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, xdip,
1126 		    "interrupts", asy_intrs[i]);
1127 		(void) ndi_devi_bind_driver(xdip, 0);
1128 	}
1129 
1130 	/* i8042 node */
1131 	ndi_devi_alloc_sleep(isa_dip, "i8042",
1132 	    (pnode_t)DEVI_SID_NODEID, &xdip);
1133 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip,
1134 	    "reg", (int *)i8042_regs, 6);
1135 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip,
1136 	    "interrupts", (int *)i8042_intrs, 2);
1137 	(void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip,
1138 	    "unit-address", "1,60");
1139 	(void) ndi_devi_bind_driver(xdip, 0);
1140 
1141 	add_known_used_resources();
1142 
1143 	ndi_devi_exit(isa_dip, circ);
1144 
1145 	isa_create_ranges_prop(isa_dip);
1146 }
1147 
1148 /*
1149  * On some machines, serial port 2 isn't listed in the ACPI table.
1150  * This function goes through the BIOS data area and makes sure all
1151  * the serial ports there are in the dev_info tree.  If any are missing,
1152  * this function will add them.
1153  */
1154 
1155 static int num_BIOS_serial = 2;	/* number of BIOS serial ports to look at */
1156 
1157 static void
1158 enumerate_BIOS_serial(dev_info_t *isa_dip)
1159 {
1160 	ushort_t *bios_data;
1161 	int i;
1162 	dev_info_t *xdip;
1163 	int found;
1164 	int ret;
1165 	struct regspec *tmpregs;
1166 	int tmpregs_len;
1167 	static struct regspec tmp_asy_regs[] = {
1168 		{1, 0x3f8, 0x8},
1169 	};
1170 	static int default_asy_intrs[] = { 4, 3, 4, 3 };
1171 	static size_t size = 4;
1172 
1173 	/*
1174 	 * The first four 2-byte quantities of the BIOS data area contain
1175 	 * the base I/O addresses of the first four serial ports.
1176 	 */
1177 	bios_data = (ushort_t *)psm_map_new((paddr_t)BIOS_DATA_AREA, size,
1178 	    PSM_PROT_READ);
1179 	for (i = 0; i < num_BIOS_serial; i++) {
1180 		if (bios_data[i] == 0) {
1181 			/* no COM[i]: port */
1182 			continue;
1183 		}
1184 
1185 		/* Look for it in the dev_info tree */
1186 		found = 0;
1187 		for (xdip = ddi_get_child(isa_dip); xdip != NULL;
1188 		    xdip = ddi_get_next_sibling(xdip)) {
1189 			if (strncmp(ddi_node_name(xdip), "asy", 3) != 0) {
1190 				/* skip non asy */
1191 				continue;
1192 			}
1193 
1194 			/* Match by addr */
1195 			ret = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, xdip,
1196 			    DDI_PROP_DONTPASS, "reg", (int **)&tmpregs,
1197 			    (uint_t *)&tmpregs_len);
1198 			if (ret != DDI_PROP_SUCCESS) {
1199 				/* error */
1200 				continue;
1201 			}
1202 
1203 			if (tmpregs->regspec_addr == bios_data[i])
1204 				found = 1;
1205 			/*
1206 			 * Free the memory allocated by
1207 			 * ddi_prop_lookup_int_array().
1208 			 */
1209 			ddi_prop_free(tmpregs);
1210 
1211 		}
1212 
1213 		/* If not found, then add it */
1214 		if (!found) {
1215 			ndi_devi_alloc_sleep(isa_dip, "asy",
1216 			    (pnode_t)DEVI_SID_NODEID, &xdip);
1217 			(void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip,
1218 			    "compatible", "PNP0500");
1219 			/* This should be gotten from master file: */
1220 			(void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip,
1221 			    "model", "Standard PC COM port");
1222 			tmp_asy_regs[0].regspec_addr = bios_data[i];
1223 			(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip,
1224 			    "reg", (int *)&tmp_asy_regs[0], 3);
1225 			(void) ndi_prop_update_int(DDI_DEV_T_NONE, xdip,
1226 			    "interrupts", default_asy_intrs[i]);
1227 			(void) ndi_devi_bind_driver(xdip, 0);
1228 
1229 			ASSERT(isa_extra_count < MAX_EXTRA_RESOURCE);
1230 			bcopy(tmp_asy_regs,
1231 			    isa_extra_resource + isa_extra_count,
1232 			    sizeof (struct regspec));
1233 			isa_extra_count++;
1234 		}
1235 	}
1236 
1237 	/*
1238 	 * An asy node may have been attached via ACPI enumeration, or
1239 	 * directly from this file.  Check each serial port to see if it
1240 	 * is in use by the hypervisor.  If it is in use, then remove
1241 	 * the node from the device tree.
1242 	 */
1243 #if defined(__xpv)
1244 	i = 0;
1245 
1246 	for (xdip = ddi_get_child(isa_dip); xdip != NULL; ) {
1247 		dev_info_t *curdip;
1248 
1249 		curdip = xdip;
1250 		xdip = ddi_get_next_sibling(xdip);
1251 
1252 		if (strncmp(ddi_node_name(curdip), "asy", 3) != 0)
1253 			continue;
1254 
1255 		if ((i == 0 && console_hypervisor_device == CONS_TTYA) ||
1256 		    (i == 1 && console_hypervisor_device == CONS_TTYB)) {
1257 			ret = ndi_devi_free(curdip);
1258 			if (ret != DDI_SUCCESS) {
1259 				cmn_err(CE_WARN,
1260 				    "could not remove asy%d node", i);
1261 			}
1262 
1263 			cmn_err(CE_NOTE, "!asy%d unavailable, reserved"
1264 			    " to hypervisor", i);
1265 		}
1266 
1267 		i++;
1268 	}
1269 #endif
1270 
1271 	psm_unmap((caddr_t)bios_data, size);
1272 }
1273 
1274 /*
1275  * Some machine comes with an illegal parallel port size of 3
1276  * bytes in ACPI, even parallel port mode is ECP.
1277  */
1278 #define	DEFAULT_PRT_SIZE	8
1279 static void
1280 adjust_prtsz(dev_info_t *isa_dip)
1281 {
1282 	dev_info_t *cdip;
1283 	struct regspec *regs_p, *extreg_p;
1284 	int regs_len, nreg, i;
1285 	char *name;
1286 
1287 	for (cdip = ddi_get_child(isa_dip); cdip != NULL;
1288 	    cdip = ddi_get_next_sibling(cdip)) {
1289 		name = ddi_node_name(cdip);
1290 		if ((strncmp(name, "lp", 2) != 0) || (strnlen(name, 3) != 2))
1291 			continue;	/* skip non parallel */
1292 
1293 		if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, cdip,
1294 		    DDI_PROP_DONTPASS, "reg", (int **)&regs_p,
1295 		    (uint_t *)&regs_len) != DDI_PROP_SUCCESS)
1296 			continue;
1297 
1298 		nreg = regs_len / (sizeof (struct regspec) / sizeof (int));
1299 		for (i = 0; i < nreg; i++) {
1300 			if (regs_p[i].regspec_size == DEFAULT_PRT_SIZE)
1301 				continue;
1302 
1303 			ASSERT(isa_extra_count < MAX_EXTRA_RESOURCE);
1304 			extreg_p = &isa_extra_resource[isa_extra_count++];
1305 			extreg_p->regspec_bustype = ISA_ADDR_IO;
1306 			extreg_p->regspec_addr = regs_p[i].regspec_addr;
1307 			extreg_p->regspec_size = DEFAULT_PRT_SIZE;
1308 		}
1309 
1310 		ddi_prop_free(regs_p);
1311 	}
1312 }
1313