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