xref: /titanic_44/usr/src/uts/i86pc/io/isa.c (revision 3f7d54a6b84904c8f4d8daa4c7b577bede7df8b9)
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 2010 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 (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "reg",
645 	    (caddr_t)&isa_regs, &proplen) != DDI_PROP_SUCCESS) {
646 		return (0);
647 	}
648 	pnpisa = isa_regs[0].phys_hi & 0x80000000;
649 	/*
650 	 * free the memory allocated by ddi_getlongprop().
651 	 */
652 	kmem_free(isa_regs, proplen);
653 	if (pnpisa)
654 		return (1);
655 	else
656 		return (0);
657 }
658 
659 /*ARGSUSED*/
660 static int
661 isa_ctlops(dev_info_t *dip, dev_info_t *rdip,
662 	ddi_ctl_enum_t ctlop, void *arg, void *result)
663 {
664 	int rn;
665 	struct ddi_parent_private_data *pdp;
666 
667 	switch (ctlop) {
668 	case DDI_CTLOPS_REPORTDEV:
669 		if (rdip == (dev_info_t *)0)
670 			return (DDI_FAILURE);
671 		cmn_err(CE_CONT, "?ISA-device: %s%d\n",
672 		    ddi_driver_name(rdip), ddi_get_instance(rdip));
673 		return (DDI_SUCCESS);
674 
675 	case DDI_CTLOPS_INITCHILD:
676 		/*
677 		 * older drivers aren't expecting the "standard" device
678 		 * node format used by the hardware nodes.  these drivers
679 		 * only expect their own properties set in their driver.conf
680 		 * files.  so they tell us not to call them with hardware
681 		 * nodes by setting the property "ignore-hardware-nodes".
682 		 */
683 		if (old_driver((dev_info_t *)arg)) {
684 			return (DDI_NOT_WELL_FORMED);
685 		}
686 
687 		return (isa_initchild((dev_info_t *)arg));
688 
689 	case DDI_CTLOPS_UNINITCHILD:
690 		impl_ddi_sunbus_removechild((dev_info_t *)arg);
691 		return (DDI_SUCCESS);
692 
693 	case DDI_CTLOPS_SIDDEV:
694 		if (ndi_dev_is_persistent_node(rdip))
695 			return (DDI_SUCCESS);
696 		/*
697 		 * All ISA devices need to do confirming probes
698 		 * unless they are PnP ISA.
699 		 */
700 		if (is_pnpisa(rdip))
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 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_XLATE_VECTOR,
837 		    (int *)&hdlp->ih_vector) == PSM_FAILURE)
838 			return (DDI_FAILURE);
839 
840 		/* Add the interrupt handler */
841 		if (!add_avintr((void *)hdlp, ispec->intrspec_pri,
842 		    hdlp->ih_cb_func, DEVI(rdip)->devi_name, hdlp->ih_vector,
843 		    hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, NULL, rdip))
844 			return (DDI_FAILURE);
845 		break;
846 	case DDI_INTROP_DISABLE:
847 		if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)
848 			return (DDI_FAILURE);
849 
850 		/* Call psm_ops() to translate irq with the dip */
851 		if (psm_intr_ops == NULL)
852 			return (DDI_FAILURE);
853 
854 		((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispec;
855 		(void) (*psm_intr_ops)(rdip, hdlp,
856 		    PSM_INTR_OP_XLATE_VECTOR, (int *)&hdlp->ih_vector);
857 
858 		/* Remove the interrupt handler */
859 		rem_avintr((void *)hdlp, ispec->intrspec_pri,
860 		    hdlp->ih_cb_func, hdlp->ih_vector);
861 		break;
862 	case DDI_INTROP_SETMASK:
863 		if (psm_intr_ops == NULL)
864 			return (DDI_FAILURE);
865 
866 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_SET_MASK, NULL))
867 			return (DDI_FAILURE);
868 		break;
869 	case DDI_INTROP_CLRMASK:
870 		if (psm_intr_ops == NULL)
871 			return (DDI_FAILURE);
872 
873 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_CLEAR_MASK, NULL))
874 			return (DDI_FAILURE);
875 		break;
876 	case DDI_INTROP_GETPENDING:
877 		if (psm_intr_ops == NULL)
878 			return (DDI_FAILURE);
879 
880 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_GET_PENDING,
881 		    result)) {
882 			*(int *)result = 0;
883 			return (DDI_FAILURE);
884 		}
885 		break;
886 	case DDI_INTROP_NAVAIL:
887 	case DDI_INTROP_NINTRS:
888 		*(int *)result = i_ddi_get_intx_nintrs(rdip);
889 		if (*(int *)result == 0) {
890 			return (DDI_FAILURE);
891 		}
892 		break;
893 	case DDI_INTROP_SUPPORTED_TYPES:
894 		*(int *)result = DDI_INTR_TYPE_FIXED;	/* Always ... */
895 		break;
896 	default:
897 		return (DDI_FAILURE);
898 	}
899 
900 	return (DDI_SUCCESS);
901 }
902 
903 static void
904 isa_vendor(uint32_t id, char *vendor)
905 {
906 	vendor[0] = '@' + ((id >> 26) & 0x1f);
907 	vendor[1] = '@' + ((id >> 21) & 0x1f);
908 	vendor[2] = '@' + ((id >> 16) & 0x1f);
909 	vendor[3] = 0;
910 }
911 
912 /*
913  * Name a child
914  */
915 static int
916 isa_name_child(dev_info_t *child, char *name, int namelen)
917 {
918 	char vendor[8];
919 	int device;
920 	uint32_t serial;
921 	int func;
922 	int bustype;
923 	uint32_t base;
924 	int proplen;
925 	int pnpisa = 0;
926 	isa_regs_t *isa_regs;
927 
928 	void make_ddi_ppd(dev_info_t *, struct ddi_parent_private_data **);
929 
930 	/*
931 	 * older drivers aren't expecting the "standard" device
932 	 * node format used by the hardware nodes.  these drivers
933 	 * only expect their own properties set in their driver.conf
934 	 * files.  so they tell us not to call them with hardware
935 	 * nodes by setting the property "ignore-hardware-nodes".
936 	 */
937 	if (old_driver(child))
938 		return (DDI_FAILURE);
939 
940 	/*
941 	 * Fill in parent-private data
942 	 */
943 	if (ddi_get_parent_data(child) == NULL) {
944 		struct ddi_parent_private_data *pdptr;
945 		make_ddi_ppd(child, &pdptr);
946 		ddi_set_parent_data(child, pdptr);
947 	}
948 
949 	if (ndi_dev_is_persistent_node(child) == 0) {
950 		/*
951 		 * For .conf nodes, generate name from parent private data
952 		 */
953 		name[0] = '\0';
954 		if (sparc_pd_getnreg(child) > 0) {
955 			(void) snprintf(name, namelen, "%x,%x",
956 			    (uint_t)sparc_pd_getreg(child, 0)->regspec_bustype,
957 			    (uint_t)sparc_pd_getreg(child, 0)->regspec_addr);
958 		}
959 		return (DDI_SUCCESS);
960 	}
961 
962 	/*
963 	 * For hw nodes, look up "reg" property
964 	 */
965 	if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, "reg",
966 	    (caddr_t)&isa_regs, &proplen) != DDI_PROP_SUCCESS) {
967 		return (DDI_FAILURE);
968 	}
969 
970 	/*
971 	 * extract the device identifications
972 	 */
973 	pnpisa = isa_regs[0].phys_hi & 0x80000000;
974 	if (pnpisa) {
975 		isa_vendor(isa_regs[0].phys_hi, vendor);
976 		device = isa_regs[0].phys_hi & 0xffff;
977 		serial = isa_regs[0].phys_lo;
978 		func = (isa_regs[0].size >> 24) & 0xff;
979 		if (func != 0)
980 			(void) snprintf(name, namelen, "pnp%s,%04x,%x,%x",
981 			    vendor, device, serial, func);
982 		else
983 			(void) snprintf(name, namelen, "pnp%s,%04x,%x",
984 			    vendor, device, serial);
985 	} else {
986 		bustype = isa_regs[0].phys_hi;
987 		base = isa_regs[0].phys_lo;
988 		(void) sprintf(name, "%x,%x", bustype, base);
989 	}
990 
991 	/*
992 	 * free the memory allocated by ddi_getlongprop().
993 	 */
994 	kmem_free(isa_regs, proplen);
995 
996 	return (DDI_SUCCESS);
997 }
998 
999 static int
1000 isa_initchild(dev_info_t *child)
1001 {
1002 	char name[80];
1003 
1004 	if (isa_name_child(child, name, 80) != DDI_SUCCESS)
1005 		return (DDI_FAILURE);
1006 	ddi_set_name_addr(child, name);
1007 
1008 	if (ndi_dev_is_persistent_node(child) != 0)
1009 		return (DDI_SUCCESS);
1010 
1011 	/*
1012 	 * This is a .conf node, try merge properties onto a
1013 	 * hw node with the same name.
1014 	 */
1015 	if (ndi_merge_node(child, isa_name_child) == DDI_SUCCESS) {
1016 		/*
1017 		 * Return failure to remove node
1018 		 */
1019 		impl_ddi_sunbus_removechild(child);
1020 		return (DDI_FAILURE);
1021 	}
1022 	/*
1023 	 * Cannot merge node, permit pseudo children
1024 	 */
1025 	return (DDI_SUCCESS);
1026 }
1027 
1028 /*
1029  * called when ACPI enumeration is not used
1030  */
1031 static void
1032 add_known_used_resources(void)
1033 {
1034 	/* needs to be in increasing order */
1035 	int intr[] = {0x1, 0x3, 0x4, 0x6, 0x7, 0xc};
1036 	int dma[] = {0x2};
1037 	int io[] = {0x60, 0x1, 0x64, 0x1, 0x2f8, 0x8, 0x378, 0x8, 0x3f0, 0x10,
1038 	    0x778, 0x4};
1039 	dev_info_t *usedrdip;
1040 
1041 	usedrdip = ddi_find_devinfo(USED_RESOURCES, -1, 0);
1042 
1043 	if (usedrdip == NULL) {
1044 		(void) ndi_devi_alloc_sleep(ddi_root_node(), USED_RESOURCES,
1045 		    (pnode_t)DEVI_SID_NODEID, &usedrdip);
1046 	}
1047 
1048 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip,
1049 	    "interrupts", (int *)intr, (int)(sizeof (intr) / sizeof (int)));
1050 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip,
1051 	    "io-space", (int *)io, (int)(sizeof (io) / sizeof (int)));
1052 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip,
1053 	    "dma-channels", (int *)dma, (int)(sizeof (dma) / sizeof (int)));
1054 	(void) ndi_devi_bind_driver(usedrdip, 0);
1055 
1056 }
1057 
1058 static void
1059 isa_enumerate(int reprogram)
1060 {
1061 	int circ, i;
1062 	dev_info_t *xdip;
1063 	dev_info_t *isa_dip = ddi_find_devinfo("isa", -1, 0);
1064 
1065 	/* hard coded isa stuff */
1066 	struct regspec asy_regs[] = {
1067 		{1, 0x3f8, 0x8},
1068 		{1, 0x2f8, 0x8}
1069 	};
1070 	int asy_intrs[] = {0x4, 0x3};
1071 
1072 	struct regspec i8042_regs[] = {
1073 		{1, 0x60, 0x1},
1074 		{1, 0x64, 0x1}
1075 	};
1076 	int i8042_intrs[] = {0x1, 0xc};
1077 	char *acpi_prop;
1078 	int acpi_enum = 1; /* ACPI is default to be on */
1079 
1080 	if (reprogram || !isa_dip)
1081 		return;
1082 
1083 	bzero(isa_extra_resource, MAX_EXTRA_RESOURCE * sizeof (struct regspec));
1084 
1085 	ndi_devi_enter(isa_dip, &circ);
1086 
1087 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(),
1088 	    DDI_PROP_DONTPASS, "acpi-enum", &acpi_prop) == DDI_PROP_SUCCESS) {
1089 		acpi_enum = strcmp("off", acpi_prop);
1090 		ddi_prop_free(acpi_prop);
1091 	}
1092 
1093 	if (acpi_enum) {
1094 		if (acpi_isa_device_enum(isa_dip)) {
1095 			ndi_devi_exit(isa_dip, circ);
1096 			if (isa_resource_setup() != NDI_SUCCESS) {
1097 				cmn_err(CE_WARN, "isa nexus: isa "
1098 				    "resource setup failed");
1099 			}
1100 
1101 			/* serial ports? */
1102 			enumerate_BIOS_serial(isa_dip);
1103 
1104 			/* adjust parallel port size  */
1105 			adjust_prtsz(isa_dip);
1106 
1107 			isa_create_ranges_prop(isa_dip);
1108 			return;
1109 		}
1110 		cmn_err(CE_NOTE, "!Solaris did not detect ACPI BIOS");
1111 	}
1112 	cmn_err(CE_NOTE, "!ACPI is off");
1113 
1114 	/* serial ports */
1115 	for (i = 0; i < 2; i++) {
1116 #if defined(__xpv)
1117 		if ((i == 0 && console_hypervisor_device == CONS_TTYA) ||
1118 		    (i == 1 && console_hypervisor_device == CONS_TTYB)) {
1119 			continue;
1120 		}
1121 #endif
1122 		ndi_devi_alloc_sleep(isa_dip, "asy",
1123 		    (pnode_t)DEVI_SID_NODEID, &xdip);
1124 		(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip,
1125 		    "reg", (int *)&asy_regs[i], 3);
1126 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, xdip,
1127 		    "interrupts", asy_intrs[i]);
1128 		(void) ndi_devi_bind_driver(xdip, 0);
1129 	}
1130 
1131 	/* i8042 node */
1132 	ndi_devi_alloc_sleep(isa_dip, "i8042",
1133 	    (pnode_t)DEVI_SID_NODEID, &xdip);
1134 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip,
1135 	    "reg", (int *)i8042_regs, 6);
1136 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip,
1137 	    "interrupts", (int *)i8042_intrs, 2);
1138 	(void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip,
1139 	    "unit-address", "1,60");
1140 	(void) ndi_devi_bind_driver(xdip, 0);
1141 
1142 	add_known_used_resources();
1143 
1144 	ndi_devi_exit(isa_dip, circ);
1145 
1146 	isa_create_ranges_prop(isa_dip);
1147 }
1148 
1149 /*
1150  * On some machines, serial port 2 isn't listed in the ACPI table.
1151  * This function goes through the BIOS data area and makes sure all
1152  * the serial ports there are in the dev_info tree.  If any are missing,
1153  * this function will add them.
1154  */
1155 
1156 static int num_BIOS_serial = 2;	/* number of BIOS serial ports to look at */
1157 
1158 static void
1159 enumerate_BIOS_serial(dev_info_t *isa_dip)
1160 {
1161 	ushort_t *bios_data;
1162 	int i;
1163 	dev_info_t *xdip;
1164 	int found;
1165 	int ret;
1166 	struct regspec *tmpregs;
1167 	int tmpregs_len;
1168 	static struct regspec tmp_asy_regs[] = {
1169 		{1, 0x3f8, 0x8},
1170 	};
1171 	static int default_asy_intrs[] = { 4, 3, 4, 3 };
1172 	static size_t size = 4;
1173 
1174 	/*
1175 	 * The first four 2-byte quantities of the BIOS data area contain
1176 	 * the base I/O addresses of the first four serial ports.
1177 	 */
1178 	bios_data = (ushort_t *)psm_map_new((paddr_t)BIOS_DATA_AREA, size,
1179 	    PSM_PROT_READ);
1180 	for (i = 0; i < num_BIOS_serial; i++) {
1181 		if (bios_data[i] == 0) {
1182 			/* no COM[i]: port */
1183 			continue;
1184 		}
1185 
1186 		/* Look for it in the dev_info tree */
1187 		found = 0;
1188 		for (xdip = ddi_get_child(isa_dip); xdip != NULL;
1189 		    xdip = ddi_get_next_sibling(xdip)) {
1190 			if (strncmp(ddi_node_name(xdip), "asy", 3) != 0) {
1191 				/* skip non asy */
1192 				continue;
1193 			}
1194 
1195 			/* Match by addr */
1196 			ret = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, xdip,
1197 			    DDI_PROP_DONTPASS, "reg", (int **)&tmpregs,
1198 			    (uint_t *)&tmpregs_len);
1199 			if (ret != DDI_PROP_SUCCESS) {
1200 				/* error */
1201 				continue;
1202 			}
1203 
1204 			if (tmpregs->regspec_addr == bios_data[i])
1205 				found = 1;
1206 			/*
1207 			 * Free the memory allocated by
1208 			 * ddi_prop_lookup_int_array().
1209 			 */
1210 			ddi_prop_free(tmpregs);
1211 
1212 		}
1213 
1214 		/* If not found, then add it */
1215 		if (!found) {
1216 			ndi_devi_alloc_sleep(isa_dip, "asy",
1217 			    (pnode_t)DEVI_SID_NODEID, &xdip);
1218 			(void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip,
1219 			    "compatible", "PNP0500");
1220 			/* This should be gotten from master file: */
1221 			(void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip,
1222 			    "model", "Standard PC COM port");
1223 			tmp_asy_regs[0].regspec_addr = bios_data[i];
1224 			(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip,
1225 			    "reg", (int *)&tmp_asy_regs[0], 3);
1226 			(void) ndi_prop_update_int(DDI_DEV_T_NONE, xdip,
1227 			    "interrupts", default_asy_intrs[i]);
1228 			(void) ndi_devi_bind_driver(xdip, 0);
1229 
1230 			ASSERT(isa_extra_count < MAX_EXTRA_RESOURCE);
1231 			bcopy(tmp_asy_regs,
1232 			    isa_extra_resource + isa_extra_count,
1233 			    sizeof (struct regspec));
1234 			isa_extra_count++;
1235 		}
1236 	}
1237 
1238 	/*
1239 	 * An asy node may have been attached via ACPI enumeration, or
1240 	 * directly from this file.  Check each serial port to see if it
1241 	 * is in use by the hypervisor.  If it is in use, then remove
1242 	 * the node from the device tree.
1243 	 */
1244 #if defined(__xpv)
1245 	i = 0;
1246 
1247 	for (xdip = ddi_get_child(isa_dip); xdip != NULL; ) {
1248 		dev_info_t *curdip;
1249 
1250 		curdip = xdip;
1251 		xdip = ddi_get_next_sibling(xdip);
1252 
1253 		if (strncmp(ddi_node_name(curdip), "asy", 3) != 0)
1254 			continue;
1255 
1256 		if ((i == 0 && console_hypervisor_device == CONS_TTYA) ||
1257 		    (i == 1 && console_hypervisor_device == CONS_TTYB)) {
1258 			ret = ndi_devi_free(curdip);
1259 			if (ret != DDI_SUCCESS) {
1260 				cmn_err(CE_WARN,
1261 				    "could not remove asy%d node", i);
1262 			}
1263 
1264 			cmn_err(CE_NOTE, "!asy%d unavailable, reserved"
1265 			    " to hypervisor", i);
1266 		}
1267 
1268 		i++;
1269 	}
1270 #endif
1271 
1272 	psm_unmap((caddr_t)bios_data, size);
1273 }
1274 
1275 /*
1276  * Some machine comes with an illegal parallel port size of 3
1277  * bytes in ACPI, even parallel port mode is ECP.
1278  */
1279 #define	DEFAULT_PRT_SIZE	8
1280 static void
1281 adjust_prtsz(dev_info_t *isa_dip)
1282 {
1283 	dev_info_t *cdip;
1284 	struct regspec *regs_p, *extreg_p;
1285 	int regs_len, nreg, i;
1286 	char *name;
1287 
1288 	for (cdip = ddi_get_child(isa_dip); cdip != NULL;
1289 	    cdip = ddi_get_next_sibling(cdip)) {
1290 		name = ddi_node_name(cdip);
1291 		if ((strncmp(name, "lp", 2) != 0) || (strnlen(name, 3) != 2))
1292 			continue;	/* skip non parallel */
1293 
1294 		if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, cdip,
1295 		    DDI_PROP_DONTPASS, "reg", (int **)&regs_p,
1296 		    (uint_t *)&regs_len) != DDI_PROP_SUCCESS)
1297 			continue;
1298 
1299 		nreg = regs_len / (sizeof (struct regspec) / sizeof (int));
1300 		for (i = 0; i < nreg; i++) {
1301 			if (regs_p[i].regspec_size == DEFAULT_PRT_SIZE)
1302 				continue;
1303 
1304 			ASSERT(isa_extra_count < MAX_EXTRA_RESOURCE);
1305 			extreg_p = &isa_extra_resource[isa_extra_count++];
1306 			extreg_p->regspec_bustype = ISA_ADDR_IO;
1307 			extreg_p->regspec_addr = regs_p[i].regspec_addr;
1308 			extreg_p->regspec_size = DEFAULT_PRT_SIZE;
1309 		}
1310 
1311 		ddi_prop_free(regs_p);
1312 	}
1313 }
1314