xref: /illumos-gate/usr/src/uts/i86pc/io/isa.c (revision 37d6e2456ee4a15f47fa97a2a2eae60a9b22bd87)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5dcd3dacaSszhou  * Common Development and Distribution License (the "License").
6dcd3dacaSszhou  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2278323854SJudy Chen  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  *	ISA bus nexus driver
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
327c478bd9Sstevel@tonic-gate #include <sys/conf.h>
337c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
347c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
357c478bd9Sstevel@tonic-gate #include <sys/errno.h>
367c478bd9Sstevel@tonic-gate #include <sys/debug.h>
377c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
38dffe9ac5Sml #include <sys/psm.h>
397c478bd9Sstevel@tonic-gate #include <sys/ddidmareq.h>
407c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
41*37d6e245Slipeng sang - Sun Microsystems - Beijing China #include <sys/ddi_subrdefs.h>
427c478bd9Sstevel@tonic-gate #include <sys/dma_engine.h>
437c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
447c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
457c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
467c478bd9Sstevel@tonic-gate #include <sys/acpi/acpi_enum.h>
4778323854SJudy Chen #include <sys/mach_intr.h>
4878323854SJudy Chen #include <sys/pci.h>
4978323854SJudy Chen #include <sys/note.h>
50843e1988Sjohnlev #if defined(__xpv)
51843e1988Sjohnlev #include <sys/hypervisor.h>
52843e1988Sjohnlev #include <sys/evtchn_impl.h>
53843e1988Sjohnlev #endif
54843e1988Sjohnlev 
5578323854SJudy Chen extern int pseudo_isa;
567c478bd9Sstevel@tonic-gate extern int isa_resource_setup(void);
5778323854SJudy Chen extern int (*psm_intr_ops)(dev_info_t *, ddi_intr_handle_impl_t *,
5878323854SJudy Chen     psm_intr_op_t, int *);
591d6b7b34SJudy Chen extern void pci_register_isa_resources(int, uint32_t, uint32_t);
607c478bd9Sstevel@tonic-gate static char USED_RESOURCES[] = "used-resources";
61*37d6e245Slipeng sang - Sun Microsystems - Beijing China static void isa_enumerate(int);
62dffe9ac5Sml static void enumerate_BIOS_serial(dev_info_t *);
631d6b7b34SJudy Chen static void adjust_prtsz(dev_info_t *isa_dip);
64*37d6e245Slipeng sang - Sun Microsystems - Beijing China static void isa_create_ranges_prop(dev_info_t *);
65dffe9ac5Sml 
6678323854SJudy Chen /*
6778323854SJudy Chen  * The following typedef is used to represent an entry in the "ranges"
6878323854SJudy Chen  * property of a pci-isa bridge device node.
6978323854SJudy Chen  */
7078323854SJudy Chen typedef struct {
7178323854SJudy Chen 	uint32_t child_high;
7278323854SJudy Chen 	uint32_t child_low;
7378323854SJudy Chen 	uint32_t parent_high;
7478323854SJudy Chen 	uint32_t parent_mid;
7578323854SJudy Chen 	uint32_t parent_low;
7678323854SJudy Chen 	uint32_t size;
7778323854SJudy Chen } pib_ranges_t;
7878323854SJudy Chen 
7978323854SJudy Chen typedef struct {
8078323854SJudy Chen 	uint32_t base;
8178323854SJudy Chen 	uint32_t len;
8278323854SJudy Chen } used_ranges_t;
8378323854SJudy Chen 
8478323854SJudy Chen #define	USED_CELL_SIZE	2	/* 1 byte addr, 1 byte size */
8578323854SJudy Chen #define	ISA_ADDR_IO	1	/* IO address space */
8678323854SJudy Chen #define	ISA_ADDR_MEM	0	/* memory adress space */
87dffe9ac5Sml #define	BIOS_DATA_AREA	0x400
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * #define ISA_DEBUG 1
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate 
921d6b7b34SJudy Chen /*
931d6b7b34SJudy Chen  * For serial ports not enumerated by ACPI, and parallel ports with
941d6b7b34SJudy Chen  * illegal size. Typically, a system can have as many as 4 serial
951d6b7b34SJudy Chen  * ports and 3 parallel ports.
961d6b7b34SJudy Chen  */
971d6b7b34SJudy Chen #define	MAX_EXTRA_RESOURCE	7
981d6b7b34SJudy Chen static struct regspec isa_extra_resource[MAX_EXTRA_RESOURCE];
991d6b7b34SJudy Chen static int isa_extra_count = 0;
1001d6b7b34SJudy Chen 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  *      Local data
1037c478bd9Sstevel@tonic-gate  */
1047c478bd9Sstevel@tonic-gate static ddi_dma_lim_t ISA_dma_limits = {
1057c478bd9Sstevel@tonic-gate 	0,		/* address low				*/
1067c478bd9Sstevel@tonic-gate 	0x00ffffff,	/* address high				*/
1077c478bd9Sstevel@tonic-gate 	0,		/* counter max				*/
1087c478bd9Sstevel@tonic-gate 	1,		/* burstsize				*/
1097c478bd9Sstevel@tonic-gate 	DMA_UNIT_8,	/* minimum xfer				*/
1107c478bd9Sstevel@tonic-gate 	0,		/* dma speed				*/
1117c478bd9Sstevel@tonic-gate 	(uint_t)DMALIM_VER0, /* version				*/
1127c478bd9Sstevel@tonic-gate 	0x0000ffff,	/* address register			*/
1137c478bd9Sstevel@tonic-gate 	0x0000ffff,	/* counter register			*/
1147c478bd9Sstevel@tonic-gate 	1,		/* sector size				*/
1157c478bd9Sstevel@tonic-gate 	0x00000001,	/* scatter/gather list length		*/
1167c478bd9Sstevel@tonic-gate 	(uint_t)0xffffffff /* request size			*/
1177c478bd9Sstevel@tonic-gate };
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate static ddi_dma_attr_t ISA_dma_attr = {
1207c478bd9Sstevel@tonic-gate 	DMA_ATTR_V0,
1217c478bd9Sstevel@tonic-gate 	(unsigned long long)0,
1227c478bd9Sstevel@tonic-gate 	(unsigned long long)0x00ffffff,
1237c478bd9Sstevel@tonic-gate 	0x0000ffff,
1247c478bd9Sstevel@tonic-gate 	1,
1257c478bd9Sstevel@tonic-gate 	1,
1267c478bd9Sstevel@tonic-gate 	1,
1277c478bd9Sstevel@tonic-gate 	(unsigned long long)0xffffffff,
1287c478bd9Sstevel@tonic-gate 	(unsigned long long)0x0000ffff,
1297c478bd9Sstevel@tonic-gate 	1,
1307c478bd9Sstevel@tonic-gate 	1,
1317c478bd9Sstevel@tonic-gate 	0
1327c478bd9Sstevel@tonic-gate };
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate /*
1367c478bd9Sstevel@tonic-gate  * Config information
1377c478bd9Sstevel@tonic-gate  */
1387c478bd9Sstevel@tonic-gate 
13978323854SJudy Chen static int
14078323854SJudy Chen isa_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
14178323854SJudy Chen     off_t offset, off_t len, caddr_t *vaddrp);
14278323854SJudy Chen 
1437c478bd9Sstevel@tonic-gate static int
1447c478bd9Sstevel@tonic-gate isa_dma_allochdl(dev_info_t *, dev_info_t *, ddi_dma_attr_t *,
1457c478bd9Sstevel@tonic-gate     int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *);
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate static int
1487c478bd9Sstevel@tonic-gate isa_dma_mctl(dev_info_t *, dev_info_t *, ddi_dma_handle_t, enum ddi_dma_ctlops,
1497c478bd9Sstevel@tonic-gate     off_t *, size_t *, caddr_t *, uint_t);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate static int
1527c478bd9Sstevel@tonic-gate isa_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *);
1537c478bd9Sstevel@tonic-gate 
15478323854SJudy Chen static int
15578323854SJudy Chen isa_intr_ops(dev_info_t *pdip, dev_info_t *rdip, ddi_intr_op_t intr_op,
15678323854SJudy Chen     ddi_intr_handle_impl_t *hdlp, void *result);
15778323854SJudy Chen 
1587c478bd9Sstevel@tonic-gate struct bus_ops isa_bus_ops = {
1597c478bd9Sstevel@tonic-gate 	BUSO_REV,
16078323854SJudy Chen 	isa_bus_map,
1617c478bd9Sstevel@tonic-gate 	NULL,
1627c478bd9Sstevel@tonic-gate 	NULL,
1637c478bd9Sstevel@tonic-gate 	NULL,
1647c478bd9Sstevel@tonic-gate 	i_ddi_map_fault,
1657c478bd9Sstevel@tonic-gate 	ddi_dma_map,
1667c478bd9Sstevel@tonic-gate 	isa_dma_allochdl,
1677c478bd9Sstevel@tonic-gate 	ddi_dma_freehdl,
1687c478bd9Sstevel@tonic-gate 	ddi_dma_bindhdl,
1697c478bd9Sstevel@tonic-gate 	ddi_dma_unbindhdl,
1707c478bd9Sstevel@tonic-gate 	ddi_dma_flush,
1717c478bd9Sstevel@tonic-gate 	ddi_dma_win,
1727c478bd9Sstevel@tonic-gate 	isa_dma_mctl,
1737c478bd9Sstevel@tonic-gate 	isa_ctlops,
1747c478bd9Sstevel@tonic-gate 	ddi_bus_prop_op,
1757c478bd9Sstevel@tonic-gate 	NULL,		/* (*bus_get_eventcookie)();	*/
1767c478bd9Sstevel@tonic-gate 	NULL,		/* (*bus_add_eventcall)();	*/
1777c478bd9Sstevel@tonic-gate 	NULL,		/* (*bus_remove_eventcall)();	*/
1787c478bd9Sstevel@tonic-gate 	NULL,		/* (*bus_post_event)();		*/
1797c478bd9Sstevel@tonic-gate 	NULL,		/* (*bus_intr_ctl)(); */
1807c478bd9Sstevel@tonic-gate 	NULL,		/* (*bus_config)(); */
1817c478bd9Sstevel@tonic-gate 	NULL,		/* (*bus_unconfig)(); */
1827c478bd9Sstevel@tonic-gate 	NULL,		/* (*bus_fm_init)(); */
1837c478bd9Sstevel@tonic-gate 	NULL,		/* (*bus_fm_fini)(); */
1847c478bd9Sstevel@tonic-gate 	NULL,		/* (*bus_fm_access_enter)(); */
1857c478bd9Sstevel@tonic-gate 	NULL,		/* (*bus_fm_access_exit)(); */
1867c478bd9Sstevel@tonic-gate 	NULL,		/* (*bus_power)(); */
18778323854SJudy Chen 	isa_intr_ops	/* (*bus_intr_op)(); */
1887c478bd9Sstevel@tonic-gate };
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate static int isa_attach(dev_info_t *devi, ddi_attach_cmd_t cmd);
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate  * Internal isa ctlops support routines
1957c478bd9Sstevel@tonic-gate  */
1967c478bd9Sstevel@tonic-gate static int isa_initchild(dev_info_t *child);
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate struct dev_ops isa_ops = {
1997c478bd9Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev, */
2007c478bd9Sstevel@tonic-gate 	0,			/* refcnt  */
2017c478bd9Sstevel@tonic-gate 	ddi_no_info,		/* info */
2027c478bd9Sstevel@tonic-gate 	nulldev,		/* identify */
2037c478bd9Sstevel@tonic-gate 	nulldev,		/* probe */
2047c478bd9Sstevel@tonic-gate 	isa_attach,		/* attach */
20578323854SJudy Chen 	nulldev,		/* detach */
2067c478bd9Sstevel@tonic-gate 	nodev,			/* reset */
2077c478bd9Sstevel@tonic-gate 	(struct cb_ops *)0,	/* driver operations */
20819397407SSherry Moore 	&isa_bus_ops,		/* bus operations */
20919397407SSherry Moore 	NULL,			/* power */
21019397407SSherry Moore 	ddi_quiesce_not_needed,		/* quiesce */
2117c478bd9Sstevel@tonic-gate };
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate /*
2147c478bd9Sstevel@tonic-gate  * Module linkage information for the kernel.
2157c478bd9Sstevel@tonic-gate  */
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
2187c478bd9Sstevel@tonic-gate 	&mod_driverops, /* Type of module.  This is ISA bus driver */
219613b2871SRichard Bean 	"isa nexus driver for 'ISA'",
2207c478bd9Sstevel@tonic-gate 	&isa_ops,	/* driver ops */
2217c478bd9Sstevel@tonic-gate };
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
2247c478bd9Sstevel@tonic-gate 	MODREV_1,
2257c478bd9Sstevel@tonic-gate 	&modldrv,
2267c478bd9Sstevel@tonic-gate 	NULL
2277c478bd9Sstevel@tonic-gate };
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate int
2307c478bd9Sstevel@tonic-gate _init(void)
2317c478bd9Sstevel@tonic-gate {
232*37d6e245Slipeng sang - Sun Microsystems - Beijing China 	int	err;
233*37d6e245Slipeng sang - Sun Microsystems - Beijing China 
234*37d6e245Slipeng sang - Sun Microsystems - Beijing China 	if ((err = mod_install(&modlinkage)) != 0)
235*37d6e245Slipeng sang - Sun Microsystems - Beijing China 		return (err);
236*37d6e245Slipeng sang - Sun Microsystems - Beijing China 
237*37d6e245Slipeng sang - Sun Microsystems - Beijing China 	impl_bus_add_probe(isa_enumerate);
238*37d6e245Slipeng sang - Sun Microsystems - Beijing China 	return (0);
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate int
2427c478bd9Sstevel@tonic-gate _fini(void)
2437c478bd9Sstevel@tonic-gate {
244*37d6e245Slipeng sang - Sun Microsystems - Beijing China 	int	err;
245*37d6e245Slipeng sang - Sun Microsystems - Beijing China 
246*37d6e245Slipeng sang - Sun Microsystems - Beijing China 	impl_bus_delete_probe(isa_enumerate);
247*37d6e245Slipeng sang - Sun Microsystems - Beijing China 
248*37d6e245Slipeng sang - Sun Microsystems - Beijing China 	if ((err = mod_remove(&modlinkage)) != 0)
249*37d6e245Slipeng sang - Sun Microsystems - Beijing China 		return (err);
250*37d6e245Slipeng sang - Sun Microsystems - Beijing China 
251*37d6e245Slipeng sang - Sun Microsystems - Beijing China 	return (0);
2527c478bd9Sstevel@tonic-gate }
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate int
2557c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
2567c478bd9Sstevel@tonic-gate {
2577c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
2587c478bd9Sstevel@tonic-gate }
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate static int
2617c478bd9Sstevel@tonic-gate isa_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
2627c478bd9Sstevel@tonic-gate {
2637c478bd9Sstevel@tonic-gate 	int rval;
2647c478bd9Sstevel@tonic-gate 
265843e1988Sjohnlev #if defined(__xpv)
266843e1988Sjohnlev 	/*
267843e1988Sjohnlev 	 * don't allow isa to attach in domU. this can happen if someone sets
268843e1988Sjohnlev 	 * the console wrong, etc. ISA devices assume the H/W is there and
269843e1988Sjohnlev 	 * will cause the domU to panic.
270843e1988Sjohnlev 	 */
271843e1988Sjohnlev 	if (!DOMAIN_IS_INITDOMAIN(xen_info)) {
272843e1988Sjohnlev 		return (DDI_FAILURE);
273843e1988Sjohnlev 	}
274843e1988Sjohnlev #endif
275843e1988Sjohnlev 
27678323854SJudy Chen 	switch (cmd) {
27778323854SJudy Chen 	case DDI_ATTACH:
27878323854SJudy Chen 		break;
27978323854SJudy Chen 	case DDI_RESUME:
28078323854SJudy Chen 		return (DDI_SUCCESS);
28178323854SJudy Chen 	default:
2827c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
28378323854SJudy Chen 	}
2847c478bd9Sstevel@tonic-gate 
285*37d6e245Slipeng sang - Sun Microsystems - Beijing China 	if ((rval = i_dmae_init(devi)) == DDI_SUCCESS)
2867c478bd9Sstevel@tonic-gate 		ddi_report_dev(devi);
28778323854SJudy Chen 
2887c478bd9Sstevel@tonic-gate 	return (rval);
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate 
29178323854SJudy Chen #define	SET_RNGS(rng_p, used_p, ctyp, ptyp) do {			\
29278323854SJudy Chen 		(rng_p)->child_high = (ctyp);				\
29378323854SJudy Chen 		(rng_p)->child_low = (rng_p)->parent_low = (used_p)->base; \
29478323854SJudy Chen 		(rng_p)->parent_high = (ptyp);				\
29578323854SJudy Chen 		(rng_p)->parent_mid = 0;				\
29678323854SJudy Chen 		(rng_p)->size = (used_p)->len;				\
29778323854SJudy Chen 		_NOTE(CONSTCOND) } while (0)
29878323854SJudy Chen static uint_t
29978323854SJudy Chen isa_used_to_ranges(int ctype, int *array, uint_t size, pib_ranges_t *ranges)
30078323854SJudy Chen {
30178323854SJudy Chen 	used_ranges_t *used_p;
30278323854SJudy Chen 	pib_ranges_t *rng_p = ranges;
30378323854SJudy Chen 	uint_t	i, ptype;
30478323854SJudy Chen 
30578323854SJudy Chen 	ptype = (ctype == ISA_ADDR_IO) ? PCI_ADDR_IO : PCI_ADDR_MEM32;
30678323854SJudy Chen 	ptype |= PCI_REG_REL_M;
30778323854SJudy Chen 	size /= USED_CELL_SIZE;
30878323854SJudy Chen 	used_p = (used_ranges_t *)array;
30978323854SJudy Chen 	SET_RNGS(rng_p, used_p, ctype, ptype);
31078323854SJudy Chen 	for (i = 1, used_p++; i < size; i++, used_p++) {
31178323854SJudy Chen 		/* merge ranges record if applicable */
31278323854SJudy Chen 		if (rng_p->child_low + rng_p->size == used_p->base)
31378323854SJudy Chen 			rng_p->size += used_p->len;
31478323854SJudy Chen 		else {
31578323854SJudy Chen 			rng_p++;
31678323854SJudy Chen 			SET_RNGS(rng_p, used_p, ctype, ptype);
31778323854SJudy Chen 		}
31878323854SJudy Chen 	}
31978323854SJudy Chen 	return (rng_p - ranges + 1);
32078323854SJudy Chen }
32178323854SJudy Chen 
32278323854SJudy Chen void
32378323854SJudy Chen isa_remove_res_from_pci(int type, int *array, uint_t size)
32478323854SJudy Chen {
32578323854SJudy Chen 	int i;
32678323854SJudy Chen 	used_ranges_t *used_p;
32778323854SJudy Chen 
32878323854SJudy Chen 	size /= USED_CELL_SIZE;
32978323854SJudy Chen 	used_p = (used_ranges_t *)array;
33078323854SJudy Chen 	for (i = 0; i < size; i++, used_p++)
3311d6b7b34SJudy Chen 		pci_register_isa_resources(type, used_p->base, used_p->len);
33278323854SJudy Chen }
33378323854SJudy Chen 
33478323854SJudy Chen static void
335*37d6e245Slipeng sang - Sun Microsystems - Beijing China isa_create_ranges_prop(dev_info_t *dip)
33678323854SJudy Chen {
33778323854SJudy Chen 	dev_info_t *used;
33878323854SJudy Chen 	int *ioarray, *memarray, status;
33978323854SJudy Chen 	uint_t nio = 0, nmem = 0, nrng = 0, n;
34078323854SJudy Chen 	pib_ranges_t *ranges;
34178323854SJudy Chen 
34278323854SJudy Chen 	used = ddi_find_devinfo("used-resources", -1, 0);
34378323854SJudy Chen 	if (used == NULL) {
34478323854SJudy Chen 		cmn_err(CE_WARN, "Failed to find used-resources <%s>\n",
34578323854SJudy Chen 		    ddi_get_name(dip));
34678323854SJudy Chen 		return;
34778323854SJudy Chen 	}
34878323854SJudy Chen 	status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, used,
34978323854SJudy Chen 	    DDI_PROP_DONTPASS, "io-space", &ioarray, &nio);
35078323854SJudy Chen 	if (status != DDI_PROP_SUCCESS && status != DDI_PROP_NOT_FOUND) {
35178323854SJudy Chen 		cmn_err(CE_WARN, "io-space property failure for %s (%x)\n",
35278323854SJudy Chen 		    ddi_get_name(used), status);
35378323854SJudy Chen 		return;
35478323854SJudy Chen 	}
35578323854SJudy Chen 	status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, used,
35678323854SJudy Chen 	    DDI_PROP_DONTPASS, "device-memory", &memarray, &nmem);
35778323854SJudy Chen 	if (status != DDI_PROP_SUCCESS && status != DDI_PROP_NOT_FOUND) {
35878323854SJudy Chen 		cmn_err(CE_WARN, "device-memory property failure for %s (%x)\n",
35978323854SJudy Chen 		    ddi_get_name(used), status);
36078323854SJudy Chen 		return;
36178323854SJudy Chen 	}
36278323854SJudy Chen 	n = (nio + nmem) / USED_CELL_SIZE;
36378323854SJudy Chen 	ranges =  (pib_ranges_t *)kmem_zalloc(sizeof (pib_ranges_t) * n,
36478323854SJudy Chen 	    KM_SLEEP);
36578323854SJudy Chen 
36678323854SJudy Chen 	if (nio != 0) {
36778323854SJudy Chen 		nrng = isa_used_to_ranges(ISA_ADDR_IO, ioarray, nio, ranges);
36878323854SJudy Chen 		isa_remove_res_from_pci(ISA_ADDR_IO, ioarray, nio);
36978323854SJudy Chen 		ddi_prop_free(ioarray);
37078323854SJudy Chen 	}
37178323854SJudy Chen 	if (nmem != 0) {
37278323854SJudy Chen 		nrng += isa_used_to_ranges(ISA_ADDR_MEM, memarray, nmem,
37378323854SJudy Chen 		    ranges + nrng);
37478323854SJudy Chen 		isa_remove_res_from_pci(ISA_ADDR_MEM, memarray, nmem);
37578323854SJudy Chen 		ddi_prop_free(memarray);
37678323854SJudy Chen 	}
37778323854SJudy Chen 
3781d6b7b34SJudy Chen 	if (!pseudo_isa)
3791d6b7b34SJudy Chen 		(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, dip, "ranges",
3801d6b7b34SJudy Chen 		    (int *)ranges, nrng * sizeof (pib_ranges_t) / sizeof (int));
38178323854SJudy Chen 	kmem_free(ranges, sizeof (pib_ranges_t) * n);
38278323854SJudy Chen }
38378323854SJudy Chen 
38478323854SJudy Chen /*ARGSUSED*/
38578323854SJudy Chen static int
38678323854SJudy Chen isa_apply_range(dev_info_t *dip, struct regspec *isa_reg_p,
38778323854SJudy Chen     pci_regspec_t *pci_reg_p)
38878323854SJudy Chen {
38978323854SJudy Chen 	pib_ranges_t *ranges, *rng_p;
39078323854SJudy Chen 	int len, i, offset, nrange;
39178323854SJudy Chen 
39278323854SJudy Chen 	if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
39378323854SJudy Chen 	    "ranges", (caddr_t)&ranges, &len) != DDI_SUCCESS) {
39478323854SJudy Chen 		cmn_err(CE_WARN, "Can't get %s ranges property",
39578323854SJudy Chen 		    ddi_get_name(dip));
39678323854SJudy Chen 		return (DDI_ME_REGSPEC_RANGE);
39778323854SJudy Chen 	}
39878323854SJudy Chen 	nrange = len / sizeof (pib_ranges_t);
39978323854SJudy Chen 	rng_p = ranges;
40078323854SJudy Chen 	for (i = 0; i < nrange; i++, rng_p++) {
40178323854SJudy Chen 		/* Check for correct space */
40278323854SJudy Chen 		if (isa_reg_p->regspec_bustype != rng_p->child_high)
40378323854SJudy Chen 			continue;
40478323854SJudy Chen 
40578323854SJudy Chen 		/* Detect whether request entirely fits within a range */
40678323854SJudy Chen 		if (isa_reg_p->regspec_addr < rng_p->child_low)
40778323854SJudy Chen 			continue;
4082273e7c7SJudy Chen 		if ((isa_reg_p->regspec_addr + isa_reg_p->regspec_size - 1) >
4092273e7c7SJudy Chen 		    (rng_p->child_low + rng_p->size - 1))
41078323854SJudy Chen 			continue;
41178323854SJudy Chen 
41278323854SJudy Chen 		offset = isa_reg_p->regspec_addr - rng_p->child_low;
41378323854SJudy Chen 
41478323854SJudy Chen 		pci_reg_p->pci_phys_hi = rng_p->parent_high;
41578323854SJudy Chen 		pci_reg_p->pci_phys_mid = 0;
41678323854SJudy Chen 		pci_reg_p->pci_phys_low = rng_p->parent_low + offset;
41778323854SJudy Chen 		pci_reg_p->pci_size_hi = 0;
41878323854SJudy Chen 		pci_reg_p->pci_size_low = isa_reg_p->regspec_size;
41978323854SJudy Chen 
42078323854SJudy Chen 		break;
42178323854SJudy Chen 	}
42278323854SJudy Chen 	kmem_free(ranges, len);
4231d6b7b34SJudy Chen 
4241d6b7b34SJudy Chen 	if (i < nrange)
4251d6b7b34SJudy Chen 		return (DDI_SUCCESS);
4261d6b7b34SJudy Chen 
4271d6b7b34SJudy Chen 	/*
4281d6b7b34SJudy Chen 	 * Check extra resource range specially for serial and parallel
4291d6b7b34SJudy Chen 	 * devices, which are treated differently from all other ISA
4301d6b7b34SJudy Chen 	 * devices. On some machines, serial ports are not enumerated
4311d6b7b34SJudy Chen 	 * by ACPI but by BIOS, with io base addresses noted in legacy
4321d6b7b34SJudy Chen 	 * BIOS data area. Parallel port on some machines comes with
4331d6b7b34SJudy Chen 	 * illegal size.
4341d6b7b34SJudy Chen 	 */
4351d6b7b34SJudy Chen 	if (isa_reg_p->regspec_bustype != ISA_ADDR_IO)
4361d6b7b34SJudy Chen 		goto out_of_range;
4371d6b7b34SJudy Chen 
4381d6b7b34SJudy Chen 	for (i = 0; i < isa_extra_count; i++) {
4391d6b7b34SJudy Chen 		struct regspec *reg_p = &isa_extra_resource[i];
4401d6b7b34SJudy Chen 
4411d6b7b34SJudy Chen 		if (isa_reg_p->regspec_addr < reg_p->regspec_addr)
4421d6b7b34SJudy Chen 			continue;
4431d6b7b34SJudy Chen 		if ((isa_reg_p->regspec_addr + isa_reg_p->regspec_size) >
4441d6b7b34SJudy Chen 		    (reg_p->regspec_addr + reg_p->regspec_size))
4451d6b7b34SJudy Chen 			continue;
4461d6b7b34SJudy Chen 
4471d6b7b34SJudy Chen 		pci_reg_p->pci_phys_hi = PCI_ADDR_IO | PCI_REG_REL_M;
4481d6b7b34SJudy Chen 		pci_reg_p->pci_phys_mid = 0;
4491d6b7b34SJudy Chen 		pci_reg_p->pci_phys_low = isa_reg_p->regspec_addr;
4501d6b7b34SJudy Chen 		pci_reg_p->pci_size_hi = 0;
4511d6b7b34SJudy Chen 		pci_reg_p->pci_size_low = isa_reg_p->regspec_size;
4521d6b7b34SJudy Chen 		break;
45378323854SJudy Chen 	}
4541d6b7b34SJudy Chen 	if (i < isa_extra_count)
4551d6b7b34SJudy Chen 		return (DDI_SUCCESS);
45678323854SJudy Chen 
4571d6b7b34SJudy Chen out_of_range:
4581d6b7b34SJudy Chen 	cmn_err(CE_WARN, "isa_apply_range: Out of range base <0x%x>, size <%d>",
4591d6b7b34SJudy Chen 	    isa_reg_p->regspec_addr, isa_reg_p->regspec_size);
4601d6b7b34SJudy Chen 	return (DDI_ME_REGSPEC_RANGE);
46178323854SJudy Chen }
46278323854SJudy Chen 
46378323854SJudy Chen static int
46478323854SJudy Chen isa_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
46578323854SJudy Chen     off_t offset, off_t len, caddr_t *vaddrp)
46678323854SJudy Chen {
46778323854SJudy Chen 	struct regspec tmp_reg, *rp;
46878323854SJudy Chen 	pci_regspec_t vreg;
46978323854SJudy Chen 	ddi_map_req_t mr = *mp;		/* Get private copy of request */
47078323854SJudy Chen 	int error;
47178323854SJudy Chen 
47278323854SJudy Chen 	if (pseudo_isa)
47378323854SJudy Chen 		return (i_ddi_bus_map(dip, rdip, mp, offset, len, vaddrp));
47478323854SJudy Chen 
47578323854SJudy Chen 	mp = &mr;
47678323854SJudy Chen 
47778323854SJudy Chen 	/*
47878323854SJudy Chen 	 * First, if given an rnumber, convert it to a regspec...
47978323854SJudy Chen 	 */
48078323854SJudy Chen 	if (mp->map_type == DDI_MT_RNUMBER)  {
48178323854SJudy Chen 
48278323854SJudy Chen 		int rnumber = mp->map_obj.rnumber;
48378323854SJudy Chen 
48478323854SJudy Chen 		rp = i_ddi_rnumber_to_regspec(rdip, rnumber);
48578323854SJudy Chen 		if (rp == (struct regspec *)0)
48678323854SJudy Chen 			return (DDI_ME_RNUMBER_RANGE);
48778323854SJudy Chen 
48878323854SJudy Chen 		/*
48978323854SJudy Chen 		 * Convert the given ddi_map_req_t from rnumber to regspec...
49078323854SJudy Chen 		 */
49178323854SJudy Chen 		mp->map_type = DDI_MT_REGSPEC;
49278323854SJudy Chen 		mp->map_obj.rp = rp;
49378323854SJudy Chen 	}
49478323854SJudy Chen 
49578323854SJudy Chen 	/*
49678323854SJudy Chen 	 * Adjust offset and length correspnding to called values...
49778323854SJudy Chen 	 * XXX: A non-zero length means override the one in the regspec.
49878323854SJudy Chen 	 * XXX: (Regardless of what's in the parent's range)
49978323854SJudy Chen 	 */
50078323854SJudy Chen 
50178323854SJudy Chen 	tmp_reg = *(mp->map_obj.rp);		/* Preserve underlying data */
50278323854SJudy Chen 	rp = mp->map_obj.rp = &tmp_reg;		/* Use tmp_reg in request */
50378323854SJudy Chen 
50478323854SJudy Chen 	rp->regspec_addr += (uint_t)offset;
50578323854SJudy Chen 	if (len != 0)
50678323854SJudy Chen 		rp->regspec_size = (uint_t)len;
50778323854SJudy Chen 
50878323854SJudy Chen 	if ((error = isa_apply_range(dip, rp, &vreg)) != 0)
50978323854SJudy Chen 		return (error);
51078323854SJudy Chen 	mp->map_obj.rp = (struct regspec *)&vreg;
51178323854SJudy Chen 
51278323854SJudy Chen 	/*
51378323854SJudy Chen 	 * Call my parents bus_map function with modified values...
51478323854SJudy Chen 	 */
51578323854SJudy Chen 
51678323854SJudy Chen 	return (ddi_map(dip, mp, (off_t)0, (off_t)0, vaddrp));
51778323854SJudy Chen }
51878323854SJudy Chen 
5197c478bd9Sstevel@tonic-gate static int
5207c478bd9Sstevel@tonic-gate isa_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *dma_attr,
5217c478bd9Sstevel@tonic-gate     int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep)
5227c478bd9Sstevel@tonic-gate {
5237c478bd9Sstevel@tonic-gate 	ddi_dma_attr_merge(dma_attr, &ISA_dma_attr);
5247c478bd9Sstevel@tonic-gate 	return (ddi_dma_allochdl(dip, rdip, dma_attr, waitfp, arg, handlep));
5257c478bd9Sstevel@tonic-gate }
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate static int
5287c478bd9Sstevel@tonic-gate isa_dma_mctl(dev_info_t *dip, dev_info_t *rdip,
5297c478bd9Sstevel@tonic-gate     ddi_dma_handle_t handle, enum ddi_dma_ctlops request,
5307c478bd9Sstevel@tonic-gate     off_t *offp, size_t *lenp, caddr_t *objp, uint_t flags)
5317c478bd9Sstevel@tonic-gate {
5327c478bd9Sstevel@tonic-gate 	int rval;
5337c478bd9Sstevel@tonic-gate 	ddi_dma_lim_t defalt;
5347c478bd9Sstevel@tonic-gate 	int arg = (int)(uintptr_t)objp;
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 	switch (request) {
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate 	case DDI_DMA_E_PROG:
5397c478bd9Sstevel@tonic-gate 		return (i_dmae_prog(rdip, (struct ddi_dmae_req *)offp,
5407c478bd9Sstevel@tonic-gate 		    (ddi_dma_cookie_t *)lenp, arg));
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 	case DDI_DMA_E_ACQUIRE:
5437c478bd9Sstevel@tonic-gate 		return (i_dmae_acquire(rdip, arg, (int(*)(caddr_t))offp,
5447c478bd9Sstevel@tonic-gate 		    (caddr_t)lenp));
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate 	case DDI_DMA_E_FREE:
5477c478bd9Sstevel@tonic-gate 		return (i_dmae_free(rdip, arg));
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 	case DDI_DMA_E_STOP:
5507c478bd9Sstevel@tonic-gate 		i_dmae_stop(rdip, arg);
5517c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate 	case DDI_DMA_E_ENABLE:
5547c478bd9Sstevel@tonic-gate 		i_dmae_enable(rdip, arg);
5557c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
5567c478bd9Sstevel@tonic-gate 
5577c478bd9Sstevel@tonic-gate 	case DDI_DMA_E_DISABLE:
5587c478bd9Sstevel@tonic-gate 		i_dmae_disable(rdip, arg);
5597c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate 	case DDI_DMA_E_GETCNT:
5627c478bd9Sstevel@tonic-gate 		i_dmae_get_chan_stat(rdip, arg, NULL, (int *)lenp);
5637c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 	case DDI_DMA_E_SWSETUP:
5667c478bd9Sstevel@tonic-gate 		return (i_dmae_swsetup(rdip, (struct ddi_dmae_req *)offp,
5677c478bd9Sstevel@tonic-gate 		    (ddi_dma_cookie_t *)lenp, arg));
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate 	case DDI_DMA_E_SWSTART:
5707c478bd9Sstevel@tonic-gate 		i_dmae_swstart(rdip, arg);
5717c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate 	case DDI_DMA_E_GETLIM:
5747c478bd9Sstevel@tonic-gate 		bcopy(&ISA_dma_limits, objp, sizeof (ddi_dma_lim_t));
5757c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 	case DDI_DMA_E_GETATTR:
5787c478bd9Sstevel@tonic-gate 		bcopy(&ISA_dma_attr, objp, sizeof (ddi_dma_attr_t));
5797c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate 	case DDI_DMA_E_1STPTY:
5827c478bd9Sstevel@tonic-gate 		{
5837c478bd9Sstevel@tonic-gate 			struct ddi_dmae_req req1stpty =
5847c478bd9Sstevel@tonic-gate 			    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
5857c478bd9Sstevel@tonic-gate 			if (arg == 0) {
5867c478bd9Sstevel@tonic-gate 				req1stpty.der_command = DMAE_CMD_TRAN;
5877c478bd9Sstevel@tonic-gate 				req1stpty.der_trans = DMAE_TRANS_DMND;
5887c478bd9Sstevel@tonic-gate 			} else {
5897c478bd9Sstevel@tonic-gate 				req1stpty.der_trans = DMAE_TRANS_CSCD;
5907c478bd9Sstevel@tonic-gate 			}
5917c478bd9Sstevel@tonic-gate 			return (i_dmae_prog(rdip, &req1stpty, NULL, arg));
5927c478bd9Sstevel@tonic-gate 		}
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 	case DDI_DMA_IOPB_ALLOC:	/* get contiguous DMA-able memory */
5957c478bd9Sstevel@tonic-gate 	case DDI_DMA_SMEM_ALLOC:
5967c478bd9Sstevel@tonic-gate 		if (!offp) {
5977c478bd9Sstevel@tonic-gate 			defalt = ISA_dma_limits;
5987c478bd9Sstevel@tonic-gate 			offp = (off_t *)&defalt;
5997c478bd9Sstevel@tonic-gate 		}
6007c478bd9Sstevel@tonic-gate 		/*FALLTHROUGH*/
6017c478bd9Sstevel@tonic-gate 	default:
6027c478bd9Sstevel@tonic-gate 		rval = ddi_dma_mctl(dip, rdip, handle, request, offp,
6037c478bd9Sstevel@tonic-gate 		    lenp, objp, flags);
6047c478bd9Sstevel@tonic-gate 	}
6057c478bd9Sstevel@tonic-gate 	return (rval);
6067c478bd9Sstevel@tonic-gate }
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate /*
6097c478bd9Sstevel@tonic-gate  * Check if driver should be treated as an old pre 2.6 driver
6107c478bd9Sstevel@tonic-gate  */
6117c478bd9Sstevel@tonic-gate static int
6127c478bd9Sstevel@tonic-gate old_driver(dev_info_t *dip)
6137c478bd9Sstevel@tonic-gate {
6147c478bd9Sstevel@tonic-gate 	extern int ignore_hardware_nodes;	/* force flag from ddi_impl.c */
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate 	if (ndi_dev_is_persistent_node(dip)) {
6177c478bd9Sstevel@tonic-gate 		if (ignore_hardware_nodes)
6187c478bd9Sstevel@tonic-gate 			return (1);
6197c478bd9Sstevel@tonic-gate 		if (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
6207c478bd9Sstevel@tonic-gate 		    "ignore-hardware-nodes", -1) != -1)
6217c478bd9Sstevel@tonic-gate 			return (1);
6227c478bd9Sstevel@tonic-gate 	}
6237c478bd9Sstevel@tonic-gate 	return (0);
6247c478bd9Sstevel@tonic-gate }
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate typedef struct {
6277c478bd9Sstevel@tonic-gate 	uint32_t phys_hi;
6287c478bd9Sstevel@tonic-gate 	uint32_t phys_lo;
6297c478bd9Sstevel@tonic-gate 	uint32_t size;
6307c478bd9Sstevel@tonic-gate } isa_regs_t;
6317c478bd9Sstevel@tonic-gate 
6327c478bd9Sstevel@tonic-gate /*
6337c478bd9Sstevel@tonic-gate  * Return non-zero if device in tree is a PnP isa device
6347c478bd9Sstevel@tonic-gate  */
6357c478bd9Sstevel@tonic-gate static int
6367c478bd9Sstevel@tonic-gate is_pnpisa(dev_info_t *dip)
6377c478bd9Sstevel@tonic-gate {
6387c478bd9Sstevel@tonic-gate 	isa_regs_t *isa_regs;
6397c478bd9Sstevel@tonic-gate 	int proplen, pnpisa;
6407c478bd9Sstevel@tonic-gate 
6417c478bd9Sstevel@tonic-gate 	if (ndi_dev_is_persistent_node(dip) == 0)
6427c478bd9Sstevel@tonic-gate 		return (0);
6437c478bd9Sstevel@tonic-gate 	if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "reg",
644843e1988Sjohnlev 	    (caddr_t)&isa_regs, &proplen) != DDI_PROP_SUCCESS) {
6457c478bd9Sstevel@tonic-gate 		return (0);
6467c478bd9Sstevel@tonic-gate 	}
6477c478bd9Sstevel@tonic-gate 	pnpisa = isa_regs[0].phys_hi & 0x80000000;
6487c478bd9Sstevel@tonic-gate 	/*
6497c478bd9Sstevel@tonic-gate 	 * free the memory allocated by ddi_getlongprop().
6507c478bd9Sstevel@tonic-gate 	 */
6517c478bd9Sstevel@tonic-gate 	kmem_free(isa_regs, proplen);
6527c478bd9Sstevel@tonic-gate 	if (pnpisa)
6537c478bd9Sstevel@tonic-gate 		return (1);
6547c478bd9Sstevel@tonic-gate 	else
6557c478bd9Sstevel@tonic-gate 		return (0);
6567c478bd9Sstevel@tonic-gate }
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6597c478bd9Sstevel@tonic-gate static int
6607c478bd9Sstevel@tonic-gate isa_ctlops(dev_info_t *dip, dev_info_t *rdip,
6617c478bd9Sstevel@tonic-gate 	ddi_ctl_enum_t ctlop, void *arg, void *result)
6627c478bd9Sstevel@tonic-gate {
66378323854SJudy Chen 	int rn;
66478323854SJudy Chen 	struct ddi_parent_private_data *pdp;
66578323854SJudy Chen 
6667c478bd9Sstevel@tonic-gate 	switch (ctlop) {
6677c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTDEV:
6687c478bd9Sstevel@tonic-gate 		if (rdip == (dev_info_t *)0)
6697c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
6707c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "?ISA-device: %s%d\n",
6717c478bd9Sstevel@tonic-gate 		    ddi_driver_name(rdip), ddi_get_instance(rdip));
6727c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_INITCHILD:
6757c478bd9Sstevel@tonic-gate 		/*
6767c478bd9Sstevel@tonic-gate 		 * older drivers aren't expecting the "standard" device
6777c478bd9Sstevel@tonic-gate 		 * node format used by the hardware nodes.  these drivers
6787c478bd9Sstevel@tonic-gate 		 * only expect their own properties set in their driver.conf
6797c478bd9Sstevel@tonic-gate 		 * files.  so they tell us not to call them with hardware
6807c478bd9Sstevel@tonic-gate 		 * nodes by setting the property "ignore-hardware-nodes".
6817c478bd9Sstevel@tonic-gate 		 */
6827c478bd9Sstevel@tonic-gate 		if (old_driver((dev_info_t *)arg)) {
6837c478bd9Sstevel@tonic-gate 			return (DDI_NOT_WELL_FORMED);
6847c478bd9Sstevel@tonic-gate 		}
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 		return (isa_initchild((dev_info_t *)arg));
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_UNINITCHILD:
6897c478bd9Sstevel@tonic-gate 		impl_ddi_sunbus_removechild((dev_info_t *)arg);
6907c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_SIDDEV:
6937c478bd9Sstevel@tonic-gate 		/*
6947c478bd9Sstevel@tonic-gate 		 * All ISA devices need to do confirming probes
6957c478bd9Sstevel@tonic-gate 		 * unless they are PnP ISA.
6967c478bd9Sstevel@tonic-gate 		 */
6977c478bd9Sstevel@tonic-gate 		if (is_pnpisa(dip))
6987c478bd9Sstevel@tonic-gate 			return (DDI_SUCCESS);
6997c478bd9Sstevel@tonic-gate 		else
7007c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
7017c478bd9Sstevel@tonic-gate 
70278323854SJudy Chen 	case DDI_CTLOPS_REGSIZE:
70378323854SJudy Chen 	case DDI_CTLOPS_NREGS:
70478323854SJudy Chen 		if (rdip == (dev_info_t *)0)
70578323854SJudy Chen 			return (DDI_FAILURE);
70678323854SJudy Chen 
70778323854SJudy Chen 		if ((pdp = ddi_get_parent_data(rdip)) == NULL)
70878323854SJudy Chen 			return (DDI_FAILURE);
70978323854SJudy Chen 
71078323854SJudy Chen 		if (ctlop == DDI_CTLOPS_NREGS) {
71178323854SJudy Chen 			*(int *)result = pdp->par_nreg;
71278323854SJudy Chen 		} else {
71378323854SJudy Chen 			rn = *(int *)arg;
71478323854SJudy Chen 			if (rn >= pdp->par_nreg)
71578323854SJudy Chen 				return (DDI_FAILURE);
71678323854SJudy Chen 			*(off_t *)result = (off_t)pdp->par_reg[rn].regspec_size;
71778323854SJudy Chen 		}
71878323854SJudy Chen 		return (DDI_SUCCESS);
71978323854SJudy Chen 
72078323854SJudy Chen 	case DDI_CTLOPS_ATTACH:
72178323854SJudy Chen 	case DDI_CTLOPS_DETACH:
72278323854SJudy Chen 	case DDI_CTLOPS_PEEK:
72378323854SJudy Chen 	case DDI_CTLOPS_POKE:
72478323854SJudy Chen 		return (DDI_FAILURE);
72578323854SJudy Chen 
7267c478bd9Sstevel@tonic-gate 	default:
7277c478bd9Sstevel@tonic-gate 		return (ddi_ctlops(dip, rdip, ctlop, arg, result));
7287c478bd9Sstevel@tonic-gate 	}
7297c478bd9Sstevel@tonic-gate }
7307c478bd9Sstevel@tonic-gate 
73178323854SJudy Chen static struct intrspec *
73278323854SJudy Chen isa_get_ispec(dev_info_t *rdip, int inum)
73378323854SJudy Chen {
73478323854SJudy Chen 	struct ddi_parent_private_data *pdp = ddi_get_parent_data(rdip);
73578323854SJudy Chen 
73678323854SJudy Chen 	/* Validate the interrupt number */
73778323854SJudy Chen 	if (inum >= pdp->par_nintr)
73878323854SJudy Chen 		return (NULL);
73978323854SJudy Chen 
74078323854SJudy Chen 	/* Get the interrupt structure pointer and return that */
74178323854SJudy Chen 	return ((struct intrspec *)&pdp->par_intr[inum]);
74278323854SJudy Chen }
74378323854SJudy Chen 
74478323854SJudy Chen static int
74578323854SJudy Chen isa_intr_ops(dev_info_t *pdip, dev_info_t *rdip, ddi_intr_op_t intr_op,
74678323854SJudy Chen     ddi_intr_handle_impl_t *hdlp, void *result)
74778323854SJudy Chen {
74878323854SJudy Chen 	struct intrspec *ispec;
74978323854SJudy Chen 
75078323854SJudy Chen 	if (pseudo_isa)
75178323854SJudy Chen 		return (i_ddi_intr_ops(pdip, rdip, intr_op, hdlp, result));
75278323854SJudy Chen 
75378323854SJudy Chen 
75478323854SJudy Chen 	/* Process the interrupt operation */
75578323854SJudy Chen 	switch (intr_op) {
75678323854SJudy Chen 	case DDI_INTROP_GETCAP:
75778323854SJudy Chen 		/* First check with pcplusmp */
75878323854SJudy Chen 		if (psm_intr_ops == NULL)
75978323854SJudy Chen 			return (DDI_FAILURE);
76078323854SJudy Chen 
76178323854SJudy Chen 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_GET_CAP, result)) {
76278323854SJudy Chen 			*(int *)result = 0;
76378323854SJudy Chen 			return (DDI_FAILURE);
76478323854SJudy Chen 		}
76578323854SJudy Chen 		break;
76678323854SJudy Chen 	case DDI_INTROP_SETCAP:
76778323854SJudy Chen 		if (psm_intr_ops == NULL)
76878323854SJudy Chen 			return (DDI_FAILURE);
76978323854SJudy Chen 
77078323854SJudy Chen 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_SET_CAP, result))
77178323854SJudy Chen 			return (DDI_FAILURE);
77278323854SJudy Chen 		break;
77378323854SJudy Chen 	case DDI_INTROP_ALLOC:
77478323854SJudy Chen 		if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)
77578323854SJudy Chen 			return (DDI_FAILURE);
77678323854SJudy Chen 		hdlp->ih_pri = ispec->intrspec_pri;
77778323854SJudy Chen 		*(int *)result = hdlp->ih_scratch1;
77878323854SJudy Chen 		break;
77978323854SJudy Chen 	case DDI_INTROP_FREE:
78078323854SJudy Chen 		break;
78178323854SJudy Chen 	case DDI_INTROP_GETPRI:
78278323854SJudy Chen 		if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)
78378323854SJudy Chen 			return (DDI_FAILURE);
78478323854SJudy Chen 		*(int *)result = ispec->intrspec_pri;
78578323854SJudy Chen 		break;
78678323854SJudy Chen 	case DDI_INTROP_SETPRI:
78778323854SJudy Chen 		/* Validate the interrupt priority passed to us */
78878323854SJudy Chen 		if (*(int *)result > LOCK_LEVEL)
78978323854SJudy Chen 			return (DDI_FAILURE);
79078323854SJudy Chen 
79178323854SJudy Chen 		/* Ensure that PSM is all initialized and ispec is ok */
79278323854SJudy Chen 		if ((psm_intr_ops == NULL) ||
79378323854SJudy Chen 		    ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL))
79478323854SJudy Chen 			return (DDI_FAILURE);
79578323854SJudy Chen 
79678323854SJudy Chen 		/* update the ispec with the new priority */
79778323854SJudy Chen 		ispec->intrspec_pri =  *(int *)result;
79878323854SJudy Chen 		break;
79978323854SJudy Chen 	case DDI_INTROP_ADDISR:
80078323854SJudy Chen 		if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)
80178323854SJudy Chen 			return (DDI_FAILURE);
80278323854SJudy Chen 		ispec->intrspec_func = hdlp->ih_cb_func;
80378323854SJudy Chen 		break;
80478323854SJudy Chen 	case DDI_INTROP_REMISR:
80578323854SJudy Chen 		if (hdlp->ih_type != DDI_INTR_TYPE_FIXED)
80678323854SJudy Chen 			return (DDI_FAILURE);
80778323854SJudy Chen 		if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)
80878323854SJudy Chen 			return (DDI_FAILURE);
80978323854SJudy Chen 		ispec->intrspec_func = (uint_t (*)()) 0;
81078323854SJudy Chen 		break;
81178323854SJudy Chen 	case DDI_INTROP_ENABLE:
81278323854SJudy Chen 		if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)
81378323854SJudy Chen 			return (DDI_FAILURE);
81478323854SJudy Chen 
81578323854SJudy Chen 		/* Call psmi to translate irq with the dip */
81678323854SJudy Chen 		if (psm_intr_ops == NULL)
81778323854SJudy Chen 			return (DDI_FAILURE);
81878323854SJudy Chen 
81978323854SJudy Chen 		((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispec;
82078323854SJudy Chen 		(void) (*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_XLATE_VECTOR,
82178323854SJudy Chen 		    (int *)&hdlp->ih_vector);
82278323854SJudy Chen 
82378323854SJudy Chen 		/* Add the interrupt handler */
82478323854SJudy Chen 		if (!add_avintr((void *)hdlp, ispec->intrspec_pri,
82578323854SJudy Chen 		    hdlp->ih_cb_func, DEVI(rdip)->devi_name, hdlp->ih_vector,
82678323854SJudy Chen 		    hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, NULL, rdip))
82778323854SJudy Chen 			return (DDI_FAILURE);
82878323854SJudy Chen 		break;
82978323854SJudy Chen 	case DDI_INTROP_DISABLE:
83078323854SJudy Chen 		if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)
83178323854SJudy Chen 			return (DDI_FAILURE);
83278323854SJudy Chen 
83378323854SJudy Chen 		/* Call psm_ops() to translate irq with the dip */
83478323854SJudy Chen 		if (psm_intr_ops == NULL)
83578323854SJudy Chen 			return (DDI_FAILURE);
83678323854SJudy Chen 
83778323854SJudy Chen 		((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispec;
83878323854SJudy Chen 		(void) (*psm_intr_ops)(rdip, hdlp,
83978323854SJudy Chen 		    PSM_INTR_OP_XLATE_VECTOR, (int *)&hdlp->ih_vector);
84078323854SJudy Chen 
84178323854SJudy Chen 		/* Remove the interrupt handler */
84278323854SJudy Chen 		rem_avintr((void *)hdlp, ispec->intrspec_pri,
84378323854SJudy Chen 		    hdlp->ih_cb_func, hdlp->ih_vector);
84478323854SJudy Chen 		break;
84578323854SJudy Chen 	case DDI_INTROP_SETMASK:
84678323854SJudy Chen 		if (psm_intr_ops == NULL)
84778323854SJudy Chen 			return (DDI_FAILURE);
84878323854SJudy Chen 
84978323854SJudy Chen 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_SET_MASK, NULL))
85078323854SJudy Chen 			return (DDI_FAILURE);
85178323854SJudy Chen 		break;
85278323854SJudy Chen 	case DDI_INTROP_CLRMASK:
85378323854SJudy Chen 		if (psm_intr_ops == NULL)
85478323854SJudy Chen 			return (DDI_FAILURE);
85578323854SJudy Chen 
85678323854SJudy Chen 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_CLEAR_MASK, NULL))
85778323854SJudy Chen 			return (DDI_FAILURE);
85878323854SJudy Chen 		break;
85978323854SJudy Chen 	case DDI_INTROP_GETPENDING:
86078323854SJudy Chen 		if (psm_intr_ops == NULL)
86178323854SJudy Chen 			return (DDI_FAILURE);
86278323854SJudy Chen 
86378323854SJudy Chen 		if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_GET_PENDING,
86478323854SJudy Chen 		    result)) {
86578323854SJudy Chen 			*(int *)result = 0;
86678323854SJudy Chen 			return (DDI_FAILURE);
86778323854SJudy Chen 		}
86878323854SJudy Chen 		break;
86978323854SJudy Chen 	case DDI_INTROP_NAVAIL:
87078323854SJudy Chen 	case DDI_INTROP_NINTRS:
87178323854SJudy Chen 		*(int *)result = i_ddi_get_intx_nintrs(rdip);
87278323854SJudy Chen 		if (*(int *)result == 0) {
87378323854SJudy Chen 			return (DDI_FAILURE);
87478323854SJudy Chen 		}
87578323854SJudy Chen 		break;
87678323854SJudy Chen 	case DDI_INTROP_SUPPORTED_TYPES:
87778323854SJudy Chen 		*(int *)result = DDI_INTR_TYPE_FIXED;	/* Always ... */
87878323854SJudy Chen 		break;
87978323854SJudy Chen 	default:
88078323854SJudy Chen 		return (DDI_FAILURE);
88178323854SJudy Chen 	}
88278323854SJudy Chen 
88378323854SJudy Chen 	return (DDI_SUCCESS);
88478323854SJudy Chen }
88578323854SJudy Chen 
8867c478bd9Sstevel@tonic-gate static void
8877c478bd9Sstevel@tonic-gate isa_vendor(uint32_t id, char *vendor)
8887c478bd9Sstevel@tonic-gate {
8897c478bd9Sstevel@tonic-gate 	vendor[0] = '@' + ((id >> 26) & 0x1f);
8907c478bd9Sstevel@tonic-gate 	vendor[1] = '@' + ((id >> 21) & 0x1f);
8917c478bd9Sstevel@tonic-gate 	vendor[2] = '@' + ((id >> 16) & 0x1f);
8927c478bd9Sstevel@tonic-gate 	vendor[3] = 0;
8937c478bd9Sstevel@tonic-gate }
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate /*
8967c478bd9Sstevel@tonic-gate  * Name a child
8977c478bd9Sstevel@tonic-gate  */
8987c478bd9Sstevel@tonic-gate static int
8997c478bd9Sstevel@tonic-gate isa_name_child(dev_info_t *child, char *name, int namelen)
9007c478bd9Sstevel@tonic-gate {
9017c478bd9Sstevel@tonic-gate 	char vendor[8];
9027c478bd9Sstevel@tonic-gate 	int device;
9037c478bd9Sstevel@tonic-gate 	uint32_t serial;
9047c478bd9Sstevel@tonic-gate 	int func;
9057c478bd9Sstevel@tonic-gate 	int bustype;
9067c478bd9Sstevel@tonic-gate 	uint32_t base;
9077c478bd9Sstevel@tonic-gate 	int proplen;
9087c478bd9Sstevel@tonic-gate 	int pnpisa = 0;
9097c478bd9Sstevel@tonic-gate 	isa_regs_t *isa_regs;
9107c478bd9Sstevel@tonic-gate 
9117c478bd9Sstevel@tonic-gate 	void make_ddi_ppd(dev_info_t *, struct ddi_parent_private_data **);
9127c478bd9Sstevel@tonic-gate 
9137c478bd9Sstevel@tonic-gate 	/*
9147c478bd9Sstevel@tonic-gate 	 * older drivers aren't expecting the "standard" device
9157c478bd9Sstevel@tonic-gate 	 * node format used by the hardware nodes.  these drivers
9167c478bd9Sstevel@tonic-gate 	 * only expect their own properties set in their driver.conf
9177c478bd9Sstevel@tonic-gate 	 * files.  so they tell us not to call them with hardware
9187c478bd9Sstevel@tonic-gate 	 * nodes by setting the property "ignore-hardware-nodes".
9197c478bd9Sstevel@tonic-gate 	 */
9207c478bd9Sstevel@tonic-gate 	if (old_driver(child))
9217c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
9227c478bd9Sstevel@tonic-gate 
9237c478bd9Sstevel@tonic-gate 	/*
9247c478bd9Sstevel@tonic-gate 	 * Fill in parent-private data
9257c478bd9Sstevel@tonic-gate 	 */
9267c478bd9Sstevel@tonic-gate 	if (ddi_get_parent_data(child) == NULL) {
9277c478bd9Sstevel@tonic-gate 		struct ddi_parent_private_data *pdptr;
9287c478bd9Sstevel@tonic-gate 		make_ddi_ppd(child, &pdptr);
9297c478bd9Sstevel@tonic-gate 		ddi_set_parent_data(child, pdptr);
9307c478bd9Sstevel@tonic-gate 	}
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate 	if (ndi_dev_is_persistent_node(child) == 0) {
9337c478bd9Sstevel@tonic-gate 		/*
9347c478bd9Sstevel@tonic-gate 		 * For .conf nodes, generate name from parent private data
9357c478bd9Sstevel@tonic-gate 		 */
9367c478bd9Sstevel@tonic-gate 		name[0] = '\0';
9377c478bd9Sstevel@tonic-gate 		if (sparc_pd_getnreg(child) > 0) {
9387c478bd9Sstevel@tonic-gate 			(void) snprintf(name, namelen, "%x,%x",
9397c478bd9Sstevel@tonic-gate 			    (uint_t)sparc_pd_getreg(child, 0)->regspec_bustype,
9407c478bd9Sstevel@tonic-gate 			    (uint_t)sparc_pd_getreg(child, 0)->regspec_addr);
9417c478bd9Sstevel@tonic-gate 		}
9427c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
9437c478bd9Sstevel@tonic-gate 	}
9447c478bd9Sstevel@tonic-gate 
9457c478bd9Sstevel@tonic-gate 	/*
9467c478bd9Sstevel@tonic-gate 	 * For hw nodes, look up "reg" property
9477c478bd9Sstevel@tonic-gate 	 */
9487c478bd9Sstevel@tonic-gate 	if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, "reg",
9497c478bd9Sstevel@tonic-gate 	    (caddr_t)&isa_regs, &proplen) != DDI_PROP_SUCCESS) {
9507c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
9517c478bd9Sstevel@tonic-gate 	}
9527c478bd9Sstevel@tonic-gate 
9537c478bd9Sstevel@tonic-gate 	/*
9547c478bd9Sstevel@tonic-gate 	 * extract the device identifications
9557c478bd9Sstevel@tonic-gate 	 */
9567c478bd9Sstevel@tonic-gate 	pnpisa = isa_regs[0].phys_hi & 0x80000000;
9577c478bd9Sstevel@tonic-gate 	if (pnpisa) {
9587c478bd9Sstevel@tonic-gate 		isa_vendor(isa_regs[0].phys_hi, vendor);
9597c478bd9Sstevel@tonic-gate 		device = isa_regs[0].phys_hi & 0xffff;
9607c478bd9Sstevel@tonic-gate 		serial = isa_regs[0].phys_lo;
9617c478bd9Sstevel@tonic-gate 		func = (isa_regs[0].size >> 24) & 0xff;
9627c478bd9Sstevel@tonic-gate 		if (func != 0)
9637c478bd9Sstevel@tonic-gate 			(void) snprintf(name, namelen, "pnp%s,%04x,%x,%x",
9647c478bd9Sstevel@tonic-gate 			    vendor, device, serial, func);
9657c478bd9Sstevel@tonic-gate 		else
9667c478bd9Sstevel@tonic-gate 			(void) snprintf(name, namelen, "pnp%s,%04x,%x",
9677c478bd9Sstevel@tonic-gate 			    vendor, device, serial);
9687c478bd9Sstevel@tonic-gate 	} else {
9697c478bd9Sstevel@tonic-gate 		bustype = isa_regs[0].phys_hi;
9707c478bd9Sstevel@tonic-gate 		base = isa_regs[0].phys_lo;
9717c478bd9Sstevel@tonic-gate 		(void) sprintf(name, "%x,%x", bustype, base);
9727c478bd9Sstevel@tonic-gate 	}
9737c478bd9Sstevel@tonic-gate 
9747c478bd9Sstevel@tonic-gate 	/*
9757c478bd9Sstevel@tonic-gate 	 * free the memory allocated by ddi_getlongprop().
9767c478bd9Sstevel@tonic-gate 	 */
9777c478bd9Sstevel@tonic-gate 	kmem_free(isa_regs, proplen);
9787c478bd9Sstevel@tonic-gate 
9797c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
9807c478bd9Sstevel@tonic-gate }
9817c478bd9Sstevel@tonic-gate 
9827c478bd9Sstevel@tonic-gate static int
9837c478bd9Sstevel@tonic-gate isa_initchild(dev_info_t *child)
9847c478bd9Sstevel@tonic-gate {
9857c478bd9Sstevel@tonic-gate 	char name[80];
9867c478bd9Sstevel@tonic-gate 
9877c478bd9Sstevel@tonic-gate 	if (isa_name_child(child, name, 80) != DDI_SUCCESS)
9887c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
9897c478bd9Sstevel@tonic-gate 	ddi_set_name_addr(child, name);
9907c478bd9Sstevel@tonic-gate 
9917c478bd9Sstevel@tonic-gate 	if (ndi_dev_is_persistent_node(child) != 0)
9927c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
9937c478bd9Sstevel@tonic-gate 
9947c478bd9Sstevel@tonic-gate 	/*
9957c478bd9Sstevel@tonic-gate 	 * This is a .conf node, try merge properties onto a
9967c478bd9Sstevel@tonic-gate 	 * hw node with the same name.
9977c478bd9Sstevel@tonic-gate 	 */
9987c478bd9Sstevel@tonic-gate 	if (ndi_merge_node(child, isa_name_child) == DDI_SUCCESS) {
9997c478bd9Sstevel@tonic-gate 		/*
10007c478bd9Sstevel@tonic-gate 		 * Return failure to remove node
10017c478bd9Sstevel@tonic-gate 		 */
10027c478bd9Sstevel@tonic-gate 		impl_ddi_sunbus_removechild(child);
10037c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
10047c478bd9Sstevel@tonic-gate 	}
10057c478bd9Sstevel@tonic-gate 	/*
10067c478bd9Sstevel@tonic-gate 	 * Cannot merge node, permit pseudo children
10077c478bd9Sstevel@tonic-gate 	 */
10087c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
10097c478bd9Sstevel@tonic-gate }
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate /*
10127c478bd9Sstevel@tonic-gate  * called when ACPI enumeration is not used
10137c478bd9Sstevel@tonic-gate  */
10147c478bd9Sstevel@tonic-gate static void
10157c478bd9Sstevel@tonic-gate add_known_used_resources(void)
10167c478bd9Sstevel@tonic-gate {
10177c478bd9Sstevel@tonic-gate 	/* needs to be in increasing order */
10187c478bd9Sstevel@tonic-gate 	int intr[] = {0x1, 0x3, 0x4, 0x6, 0x7, 0xc};
10197c478bd9Sstevel@tonic-gate 	int dma[] = {0x2};
10207c478bd9Sstevel@tonic-gate 	int io[] = {0x60, 0x1, 0x64, 0x1, 0x2f8, 0x8, 0x378, 0x8, 0x3f0, 0x10,
10217c478bd9Sstevel@tonic-gate 	    0x778, 0x4};
10227c478bd9Sstevel@tonic-gate 	dev_info_t *usedrdip;
10237c478bd9Sstevel@tonic-gate 
10247c478bd9Sstevel@tonic-gate 	usedrdip = ddi_find_devinfo(USED_RESOURCES, -1, 0);
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate 	if (usedrdip == NULL) {
10277c478bd9Sstevel@tonic-gate 		(void) ndi_devi_alloc_sleep(ddi_root_node(), USED_RESOURCES,
1028fa9e4066Sahrens 		    (pnode_t)DEVI_SID_NODEID, &usedrdip);
10297c478bd9Sstevel@tonic-gate 	}
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip,
10327c478bd9Sstevel@tonic-gate 	    "interrupts", (int *)intr, (int)(sizeof (intr) / sizeof (int)));
10337c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip,
10347c478bd9Sstevel@tonic-gate 	    "io-space", (int *)io, (int)(sizeof (io) / sizeof (int)));
10357c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip,
10367c478bd9Sstevel@tonic-gate 	    "dma-channels", (int *)dma, (int)(sizeof (dma) / sizeof (int)));
10377c478bd9Sstevel@tonic-gate 	(void) ndi_devi_bind_driver(usedrdip, 0);
10387c478bd9Sstevel@tonic-gate 
10397c478bd9Sstevel@tonic-gate }
10407c478bd9Sstevel@tonic-gate 
10417c478bd9Sstevel@tonic-gate static void
1042*37d6e245Slipeng sang - Sun Microsystems - Beijing China isa_enumerate(int reprogram)
10437c478bd9Sstevel@tonic-gate {
10447c478bd9Sstevel@tonic-gate 	int circ, i;
10457c478bd9Sstevel@tonic-gate 	dev_info_t *xdip;
1046*37d6e245Slipeng sang - Sun Microsystems - Beijing China 	dev_info_t *isa_dip = ddi_find_devinfo("isa", -1, 0);
10477c478bd9Sstevel@tonic-gate 
10487c478bd9Sstevel@tonic-gate 	/* hard coded isa stuff */
10497c478bd9Sstevel@tonic-gate 	struct regspec asy_regs[] = {
10507c478bd9Sstevel@tonic-gate 		{1, 0x3f8, 0x8},
10517c478bd9Sstevel@tonic-gate 		{1, 0x2f8, 0x8}
10527c478bd9Sstevel@tonic-gate 	};
10537c478bd9Sstevel@tonic-gate 	int asy_intrs[] = {0x4, 0x3};
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate 	struct regspec i8042_regs[] = {
10567c478bd9Sstevel@tonic-gate 		{1, 0x60, 0x1},
10577c478bd9Sstevel@tonic-gate 		{1, 0x64, 0x1}
10587c478bd9Sstevel@tonic-gate 	};
10597c478bd9Sstevel@tonic-gate 	int i8042_intrs[] = {0x1, 0xc};
10607c478bd9Sstevel@tonic-gate 	char *acpi_prop;
10617c478bd9Sstevel@tonic-gate 	int acpi_enum = 1; /* ACPI is default to be on */
10627c478bd9Sstevel@tonic-gate 
1063*37d6e245Slipeng sang - Sun Microsystems - Beijing China 	if (reprogram || !isa_dip)
10647c478bd9Sstevel@tonic-gate 		return;
10657c478bd9Sstevel@tonic-gate 
1066*37d6e245Slipeng sang - Sun Microsystems - Beijing China 	bzero(isa_extra_resource, MAX_EXTRA_RESOURCE * sizeof (struct regspec));
1067*37d6e245Slipeng sang - Sun Microsystems - Beijing China 
10687c478bd9Sstevel@tonic-gate 	ndi_devi_enter(isa_dip, &circ);
10697c478bd9Sstevel@tonic-gate 
10707c478bd9Sstevel@tonic-gate 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(),
10717c478bd9Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, "acpi-enum", &acpi_prop) == DDI_PROP_SUCCESS) {
10727c478bd9Sstevel@tonic-gate 		acpi_enum = strcmp("off", acpi_prop);
10737c478bd9Sstevel@tonic-gate 		ddi_prop_free(acpi_prop);
10747c478bd9Sstevel@tonic-gate 	}
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate 	if (acpi_enum) {
10777c478bd9Sstevel@tonic-gate 		if (acpi_isa_device_enum(isa_dip)) {
10787c478bd9Sstevel@tonic-gate 			ndi_devi_exit(isa_dip, circ);
10797c478bd9Sstevel@tonic-gate 			if (isa_resource_setup() != NDI_SUCCESS) {
10807c478bd9Sstevel@tonic-gate 				cmn_err(CE_WARN, "isa nexus: isa "
10817c478bd9Sstevel@tonic-gate 				    "resource setup failed");
10827c478bd9Sstevel@tonic-gate 			}
1083dffe9ac5Sml 
1084dffe9ac5Sml 			/* serial ports? */
1085dffe9ac5Sml 			enumerate_BIOS_serial(isa_dip);
10861d6b7b34SJudy Chen 
10871d6b7b34SJudy Chen 			/* adjust parallel port size  */
10881d6b7b34SJudy Chen 			adjust_prtsz(isa_dip);
1089*37d6e245Slipeng sang - Sun Microsystems - Beijing China 
1090*37d6e245Slipeng sang - Sun Microsystems - Beijing China 			isa_create_ranges_prop(isa_dip);
10917c478bd9Sstevel@tonic-gate 			return;
10927c478bd9Sstevel@tonic-gate 		}
10937c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!Solaris did not detect ACPI BIOS");
10947c478bd9Sstevel@tonic-gate 	}
10957c478bd9Sstevel@tonic-gate 	cmn_err(CE_NOTE, "!ACPI is off");
10967c478bd9Sstevel@tonic-gate 
10977c478bd9Sstevel@tonic-gate 	/* serial ports */
10987c478bd9Sstevel@tonic-gate 	for (i = 0; i < 2; i++) {
1099843e1988Sjohnlev #if defined(__xpv)
1100843e1988Sjohnlev 		/*
1101843e1988Sjohnlev 		 * the hypervisor may be reserving the serial ports for console
1102843e1988Sjohnlev 		 * and/or debug use.  Probe the irqs to see if they are
1103843e1988Sjohnlev 		 * available.
1104843e1988Sjohnlev 		 */
1105843e1988Sjohnlev 		if (ec_probe_pirq(asy_intrs[i]) == 0)
1106843e1988Sjohnlev 			continue; /* in use */
1107843e1988Sjohnlev #endif
11087c478bd9Sstevel@tonic-gate 		ndi_devi_alloc_sleep(isa_dip, "asy",
1109fa9e4066Sahrens 		    (pnode_t)DEVI_SID_NODEID, &xdip);
11107c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip,
11117c478bd9Sstevel@tonic-gate 		    "reg", (int *)&asy_regs[i], 3);
11127c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, xdip,
11137c478bd9Sstevel@tonic-gate 		    "interrupts", asy_intrs[i]);
11147c478bd9Sstevel@tonic-gate 		(void) ndi_devi_bind_driver(xdip, 0);
11157c478bd9Sstevel@tonic-gate 	}
11167c478bd9Sstevel@tonic-gate 
11177c478bd9Sstevel@tonic-gate 	/* i8042 node */
11187c478bd9Sstevel@tonic-gate 	ndi_devi_alloc_sleep(isa_dip, "i8042",
1119fa9e4066Sahrens 	    (pnode_t)DEVI_SID_NODEID, &xdip);
11207c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip,
11217c478bd9Sstevel@tonic-gate 	    "reg", (int *)i8042_regs, 6);
11227c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip,
11237c478bd9Sstevel@tonic-gate 	    "interrupts", (int *)i8042_intrs, 2);
11247c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip,
11257c478bd9Sstevel@tonic-gate 	    "unit-address", "1,60");
11267c478bd9Sstevel@tonic-gate 	(void) ndi_devi_bind_driver(xdip, 0);
11277c478bd9Sstevel@tonic-gate 
11287c478bd9Sstevel@tonic-gate 	add_known_used_resources();
11297c478bd9Sstevel@tonic-gate 
11307c478bd9Sstevel@tonic-gate 	ndi_devi_exit(isa_dip, circ);
11317c478bd9Sstevel@tonic-gate 
1132*37d6e245Slipeng sang - Sun Microsystems - Beijing China 	isa_create_ranges_prop(isa_dip);
11337c478bd9Sstevel@tonic-gate }
1134dffe9ac5Sml 
1135dffe9ac5Sml /*
1136dffe9ac5Sml  * On some machines, serial port 2 isn't listed in the ACPI table.
1137dffe9ac5Sml  * This function goes through the BIOS data area and makes sure all
1138dffe9ac5Sml  * the serial ports there are in the dev_info tree.  If any are missing,
1139dffe9ac5Sml  * this function will add them.
1140dffe9ac5Sml  */
1141dffe9ac5Sml 
1142dffe9ac5Sml static int num_BIOS_serial = 2;	/* number of BIOS serial ports to look at */
1143dffe9ac5Sml 
1144dffe9ac5Sml static void
1145dffe9ac5Sml enumerate_BIOS_serial(dev_info_t *isa_dip)
1146dffe9ac5Sml {
1147dffe9ac5Sml 	ushort_t *bios_data;
1148dffe9ac5Sml 	int i;
1149dffe9ac5Sml 	dev_info_t *xdip;
1150dffe9ac5Sml 	int found;
1151dffe9ac5Sml 	int ret;
1152dffe9ac5Sml 	struct regspec *tmpregs;
1153dffe9ac5Sml 	int tmpregs_len;
1154dffe9ac5Sml 	static struct regspec tmp_asy_regs[] = {
1155dffe9ac5Sml 		{1, 0x3f8, 0x8},
1156dffe9ac5Sml 	};
1157dffe9ac5Sml 	static int default_asy_intrs[] = { 4, 3, 4, 3 };
1158dffe9ac5Sml 	static size_t size = 4;
1159dffe9ac5Sml 
1160dffe9ac5Sml 	/*
1161dffe9ac5Sml 	 * The first four 2-byte quantities of the BIOS data area contain
1162dffe9ac5Sml 	 * the base I/O addresses of the first four serial ports.
1163dffe9ac5Sml 	 */
1164dffe9ac5Sml 	bios_data = (ushort_t *)psm_map_new((paddr_t)BIOS_DATA_AREA, size,
1165843e1988Sjohnlev 	    PSM_PROT_READ);
1166dffe9ac5Sml 	for (i = 0; i < num_BIOS_serial; i++) {
1167dffe9ac5Sml 		if (bios_data[i] == 0) {
1168dffe9ac5Sml 			/* no COM[i]: port */
1169dffe9ac5Sml 			continue;
1170dffe9ac5Sml 		}
1171dffe9ac5Sml 
1172dffe9ac5Sml 		/* Look for it in the dev_info tree */
1173dffe9ac5Sml 		found = 0;
1174dffe9ac5Sml 		for (xdip = ddi_get_child(isa_dip); xdip != NULL;
1175dffe9ac5Sml 		    xdip = ddi_get_next_sibling(xdip)) {
1176dffe9ac5Sml 			if (strncmp(ddi_node_name(xdip), "asy", 3) != 0) {
1177dffe9ac5Sml 				/* skip non asy */
1178dffe9ac5Sml 				continue;
1179dffe9ac5Sml 			}
1180dffe9ac5Sml 
1181dffe9ac5Sml 			/* Match by addr */
1182dffe9ac5Sml 			ret = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, xdip,
1183843e1988Sjohnlev 			    DDI_PROP_DONTPASS, "reg", (int **)&tmpregs,
1184843e1988Sjohnlev 			    (uint_t *)&tmpregs_len);
1185dffe9ac5Sml 			if (ret != DDI_PROP_SUCCESS) {
1186dffe9ac5Sml 				/* error */
1187dffe9ac5Sml 				continue;
1188dffe9ac5Sml 			}
1189dffe9ac5Sml 
1190dffe9ac5Sml 			if (tmpregs->regspec_addr == bios_data[i])
1191dffe9ac5Sml 				found = 1;
1192dffe9ac5Sml 			/*
1193dffe9ac5Sml 			 * Free the memory allocated by
1194dffe9ac5Sml 			 * ddi_prop_lookup_int_array().
1195dffe9ac5Sml 			 */
1196dffe9ac5Sml 			ddi_prop_free(tmpregs);
1197843e1988Sjohnlev 
1198dffe9ac5Sml 		}
1199dffe9ac5Sml 
1200dffe9ac5Sml 		/* If not found, then add it */
1201dffe9ac5Sml 		if (!found) {
1202dffe9ac5Sml 			ndi_devi_alloc_sleep(isa_dip, "asy",
1203dffe9ac5Sml 			    (pnode_t)DEVI_SID_NODEID, &xdip);
1204dffe9ac5Sml 			(void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip,
1205dffe9ac5Sml 			    "compatible", "PNP0500");
1206dffe9ac5Sml 			/* This should be gotten from master file: */
1207dffe9ac5Sml 			(void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip,
1208dffe9ac5Sml 			    "model", "Standard PC COM port");
1209dffe9ac5Sml 			tmp_asy_regs[0].regspec_addr = bios_data[i];
1210dffe9ac5Sml 			(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip,
1211dffe9ac5Sml 			    "reg", (int *)&tmp_asy_regs[0], 3);
1212dffe9ac5Sml 			(void) ndi_prop_update_int(DDI_DEV_T_NONE, xdip,
1213dffe9ac5Sml 			    "interrupts", default_asy_intrs[i]);
1214dffe9ac5Sml 			(void) ndi_devi_bind_driver(xdip, 0);
12151d6b7b34SJudy Chen 
12161d6b7b34SJudy Chen 			ASSERT(isa_extra_count < MAX_EXTRA_RESOURCE);
12171d6b7b34SJudy Chen 			bcopy(tmp_asy_regs,
12181d6b7b34SJudy Chen 			    isa_extra_resource + isa_extra_count,
12191d6b7b34SJudy Chen 			    sizeof (struct regspec));
12201d6b7b34SJudy Chen 			isa_extra_count++;
1221dffe9ac5Sml 		}
1222dffe9ac5Sml 	}
1223843e1988Sjohnlev #if defined(__xpv)
1224843e1988Sjohnlev 	/*
1225843e1988Sjohnlev 	 * Check each serial port to see if it is in use by the hypervisor.
1226843e1988Sjohnlev 	 * If it is in use, then remove the node from the device tree.
1227843e1988Sjohnlev 	 */
1228843e1988Sjohnlev 	i = 0;
1229843e1988Sjohnlev 	for (xdip = ddi_get_child(isa_dip); xdip != NULL; ) {
1230843e1988Sjohnlev 		int asy_intr;
1231843e1988Sjohnlev 		dev_info_t *curdip;
1232843e1988Sjohnlev 
1233843e1988Sjohnlev 		curdip = xdip;
1234843e1988Sjohnlev 		xdip = ddi_get_next_sibling(xdip);
1235843e1988Sjohnlev 		if (strncmp(ddi_node_name(curdip), "asy", 3) != 0) {
1236843e1988Sjohnlev 			/* skip non asy */
1237843e1988Sjohnlev 			continue;
1238843e1988Sjohnlev 		}
1239843e1988Sjohnlev 		/*
1240843e1988Sjohnlev 		 * Check if the hypervisor is using the serial port by probing
1241843e1988Sjohnlev 		 * the irq and if it is using it remove the node
1242843e1988Sjohnlev 		 * from the device tree
1243843e1988Sjohnlev 		 */
1244843e1988Sjohnlev 		asy_intr = ddi_prop_get_int(DDI_DEV_T_ANY, curdip,
1245843e1988Sjohnlev 		    DDI_PROP_DONTPASS, "interrupts", -1);
1246843e1988Sjohnlev 		if (asy_intr == -1) {
1247843e1988Sjohnlev 			/* error */
1248843e1988Sjohnlev 			continue;
1249843e1988Sjohnlev 		}
1250843e1988Sjohnlev 
1251843e1988Sjohnlev 		if (ec_probe_pirq(asy_intr)) {
1252843e1988Sjohnlev 			continue;
1253843e1988Sjohnlev 		}
1254843e1988Sjohnlev 		ret = ndi_devi_free(curdip);
1255843e1988Sjohnlev 		if (ret != DDI_SUCCESS)
1256843e1988Sjohnlev 			cmn_err(CE_WARN,
1257843e1988Sjohnlev 			    "could not remove asy%d node", i);
1258843e1988Sjohnlev 		else
1259843e1988Sjohnlev 			cmn_err(CE_NOTE, "!asy%d unavailable, reserved"
1260843e1988Sjohnlev 			    " to hypervisor", i);
1261843e1988Sjohnlev 		i++;
1262843e1988Sjohnlev 	}
1263843e1988Sjohnlev #endif	/* __xpv */
1264dffe9ac5Sml 
1265dffe9ac5Sml 	psm_unmap((caddr_t)bios_data, size);
1266dffe9ac5Sml }
12671d6b7b34SJudy Chen 
12681d6b7b34SJudy Chen /*
12691d6b7b34SJudy Chen  * Some machine comes with an illegal parallel port size of 3
12701d6b7b34SJudy Chen  * bytes in ACPI, even parallel port mode is ECP.
12711d6b7b34SJudy Chen  */
12721d6b7b34SJudy Chen #define	DEFAULT_PRT_SIZE	8
12731d6b7b34SJudy Chen static void
12741d6b7b34SJudy Chen adjust_prtsz(dev_info_t *isa_dip)
12751d6b7b34SJudy Chen {
12761d6b7b34SJudy Chen 	dev_info_t *cdip;
12771d6b7b34SJudy Chen 	struct regspec *regs_p, *extreg_p;
12781d6b7b34SJudy Chen 	int regs_len, nreg, i;
12791d6b7b34SJudy Chen 	char *name;
12801d6b7b34SJudy Chen 
12811d6b7b34SJudy Chen 	for (cdip = ddi_get_child(isa_dip); cdip != NULL;
12821d6b7b34SJudy Chen 	    cdip = ddi_get_next_sibling(cdip)) {
12831d6b7b34SJudy Chen 		name = ddi_node_name(cdip);
12841d6b7b34SJudy Chen 		if ((strncmp(name, "lp", 2) != 0) || (strnlen(name, 3) != 2))
12851d6b7b34SJudy Chen 			continue;	/* skip non parallel */
12861d6b7b34SJudy Chen 
12871d6b7b34SJudy Chen 		if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, cdip,
12881d6b7b34SJudy Chen 		    DDI_PROP_DONTPASS, "reg", (int **)&regs_p,
12891d6b7b34SJudy Chen 		    (uint_t *)&regs_len) != DDI_PROP_SUCCESS)
12901d6b7b34SJudy Chen 			continue;
12911d6b7b34SJudy Chen 
12921d6b7b34SJudy Chen 		nreg = regs_len / (sizeof (struct regspec) / sizeof (int));
12931d6b7b34SJudy Chen 		for (i = 0; i < nreg; i++) {
12941d6b7b34SJudy Chen 			if (regs_p[i].regspec_size == DEFAULT_PRT_SIZE)
12951d6b7b34SJudy Chen 				continue;
12961d6b7b34SJudy Chen 
12971d6b7b34SJudy Chen 			ASSERT(isa_extra_count < MAX_EXTRA_RESOURCE);
12981d6b7b34SJudy Chen 			extreg_p = &isa_extra_resource[isa_extra_count++];
12991d6b7b34SJudy Chen 			extreg_p->regspec_bustype = ISA_ADDR_IO;
13001d6b7b34SJudy Chen 			extreg_p->regspec_addr = regs_p[i].regspec_addr;
13011d6b7b34SJudy Chen 			extreg_p->regspec_size = DEFAULT_PRT_SIZE;
13021d6b7b34SJudy Chen 		}
13031d6b7b34SJudy Chen 
13041d6b7b34SJudy Chen 		ddi_prop_free(regs_p);
13051d6b7b34SJudy Chen 	}
13061d6b7b34SJudy Chen }
1307