xref: /titanic_54/usr/src/uts/sun4/sys/ebus.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_EBUS_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_EBUS_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
33*7c478bd9Sstevel@tonic-gate extern "C" {
34*7c478bd9Sstevel@tonic-gate #endif
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate /*
37*7c478bd9Sstevel@tonic-gate  * driver state type:
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate typedef enum { NEW = 0, ATTACHED, RESUMED, DETACHED,
40*7c478bd9Sstevel@tonic-gate 		SUSPENDED, PM_SUSPENDED } driver_state_t;
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  * The i86pc specific code fragments are to support the debug of "honeynut"
44*7c478bd9Sstevel@tonic-gate  * and "multigrain" prototypes on i86pc platform.  Most of the fragments
45*7c478bd9Sstevel@tonic-gate  * deal with differences in the interrupt dispatching between the prototypes
46*7c478bd9Sstevel@tonic-gate  * and the cheerio ebus.  On the prototype boards, all interrupt lines are
47*7c478bd9Sstevel@tonic-gate  * tied together.  For this case, the nexus driver uses a common interrupt
48*7c478bd9Sstevel@tonic-gate  * handler to poll all of its children.
49*7c478bd9Sstevel@tonic-gate  */
50*7c478bd9Sstevel@tonic-gate #if defined(i86pc)
51*7c478bd9Sstevel@tonic-gate #define	MAX_EBUS_DEVS	6
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate /*
54*7c478bd9Sstevel@tonic-gate  * ebus device interrupt info;
55*7c478bd9Sstevel@tonic-gate  */
56*7c478bd9Sstevel@tonic-gate typedef struct {
57*7c478bd9Sstevel@tonic-gate 	char *name;
58*7c478bd9Sstevel@tonic-gate 	uint_t inuse;
59*7c478bd9Sstevel@tonic-gate 	uint_t (*handler)();
60*7c478bd9Sstevel@tonic-gate 	caddr_t arg;
61*7c478bd9Sstevel@tonic-gate } ebus_intr_slot_t;
62*7c478bd9Sstevel@tonic-gate #endif
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate struct ebus_intr_map {
65*7c478bd9Sstevel@tonic-gate 	uint32_t ebus_phys_hi;
66*7c478bd9Sstevel@tonic-gate 	uint32_t ebus_phys_low;
67*7c478bd9Sstevel@tonic-gate 	uint32_t ebus_intr;
68*7c478bd9Sstevel@tonic-gate 	uint32_t intr_ctlr_nodeid;
69*7c478bd9Sstevel@tonic-gate 	uint32_t ino;
70*7c478bd9Sstevel@tonic-gate };
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate struct ebus_intr_map_mask {
73*7c478bd9Sstevel@tonic-gate 	uint32_t ebus_phys_hi;
74*7c478bd9Sstevel@tonic-gate 	uint32_t ebus_phys_low;
75*7c478bd9Sstevel@tonic-gate 	uint32_t ebus_intr;
76*7c478bd9Sstevel@tonic-gate };
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate /*
79*7c478bd9Sstevel@tonic-gate  * driver soft state structure:
80*7c478bd9Sstevel@tonic-gate  */
81*7c478bd9Sstevel@tonic-gate typedef struct {
82*7c478bd9Sstevel@tonic-gate 	dev_info_t *dip;
83*7c478bd9Sstevel@tonic-gate 	driver_state_t state;
84*7c478bd9Sstevel@tonic-gate 	pci_regspec_t *reg;
85*7c478bd9Sstevel@tonic-gate 	int nreg;
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate 	union {
88*7c478bd9Sstevel@tonic-gate 		struct ebus_pci_rangespec *rangep;
89*7c478bd9Sstevel@tonic-gate 		struct febus_rangespec    *ferangep;
90*7c478bd9Sstevel@tonic-gate 	} rangespec;
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 	int range_cnt;
93*7c478bd9Sstevel@tonic-gate 	kmutex_t ebus_mutex;
94*7c478bd9Sstevel@tonic-gate 	uint_t ebus_soft_state;
95*7c478bd9Sstevel@tonic-gate #define	EBUS_SOFT_STATE_CLOSED		0x00
96*7c478bd9Sstevel@tonic-gate #define	EBUS_SOFT_STATE_OPEN		0x01
97*7c478bd9Sstevel@tonic-gate #define	EBUS_SOFT_STATE_OPEN_EXCL	0x02
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate #if defined(i86pc)
100*7c478bd9Sstevel@tonic-gate 	ddi_iblock_cookie_t iblock;
101*7c478bd9Sstevel@tonic-gate 	ddi_idevice_cookie_t idevice;
102*7c478bd9Sstevel@tonic-gate 	ebus_intr_slot_t intr_slot[MAX_EBUS_DEVS];
103*7c478bd9Sstevel@tonic-gate #endif
104*7c478bd9Sstevel@tonic-gate #if defined(__sparc)
105*7c478bd9Sstevel@tonic-gate 	/* Interrupt support */
106*7c478bd9Sstevel@tonic-gate 	int intr_map_size;
107*7c478bd9Sstevel@tonic-gate 	struct ebus_intr_map *intr_map;
108*7c478bd9Sstevel@tonic-gate 	struct ebus_intr_map_mask *intr_map_mask;
109*7c478bd9Sstevel@tonic-gate #endif
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 	uint_t type;
112*7c478bd9Sstevel@tonic-gate #define	EBUS_TYPE			0x00
113*7c478bd9Sstevel@tonic-gate #define	FEBUS_TYPE			0x01
114*7c478bd9Sstevel@tonic-gate } ebus_devstate_t;
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate /*
117*7c478bd9Sstevel@tonic-gate  * definition of ebus reg spec entry:
118*7c478bd9Sstevel@tonic-gate  */
119*7c478bd9Sstevel@tonic-gate typedef struct {
120*7c478bd9Sstevel@tonic-gate 	uint32_t addr_hi;
121*7c478bd9Sstevel@tonic-gate 	uint32_t addr_low;
122*7c478bd9Sstevel@tonic-gate 	uint32_t size;
123*7c478bd9Sstevel@tonic-gate } ebus_regspec_t;
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate /* EBUS range entry */
126*7c478bd9Sstevel@tonic-gate struct ebus_pci_rangespec {
127*7c478bd9Sstevel@tonic-gate 	uint32_t ebus_phys_hi;			/* Child hi range address */
128*7c478bd9Sstevel@tonic-gate 	uint32_t ebus_phys_low;			/* Child low range address */
129*7c478bd9Sstevel@tonic-gate 	uint32_t pci_phys_hi;			/* Parent hi rng addr */
130*7c478bd9Sstevel@tonic-gate 	uint32_t pci_phys_mid;			/* Parent mid rng addr */
131*7c478bd9Sstevel@tonic-gate 	uint32_t pci_phys_low;			/* Parent low rng addr */
132*7c478bd9Sstevel@tonic-gate 	uint32_t rng_size;			/* Range size */
133*7c478bd9Sstevel@tonic-gate };
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate /* FEBUS range entry */
136*7c478bd9Sstevel@tonic-gate struct febus_rangespec {
137*7c478bd9Sstevel@tonic-gate 	uint32_t febus_phys_hi;			/* Child hi range address */
138*7c478bd9Sstevel@tonic-gate 	uint32_t febus_phys_low;		/* Child low range address */
139*7c478bd9Sstevel@tonic-gate 	uint32_t parent_phys_hi;		/* Parent hi rng addr */
140*7c478bd9Sstevel@tonic-gate 	uint32_t parent_phys_low;		/* Parent low rng addr */
141*7c478bd9Sstevel@tonic-gate 	uint32_t rng_size;			/* Range size */
142*7c478bd9Sstevel@tonic-gate };
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate /*
145*7c478bd9Sstevel@tonic-gate  * use macros for soft state and driver properties:
146*7c478bd9Sstevel@tonic-gate  */
147*7c478bd9Sstevel@tonic-gate #define	get_ebus_soft_state(i)	\
148*7c478bd9Sstevel@tonic-gate 	((ebus_devstate_t *)ddi_get_soft_state(per_ebus_state, (i)))
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate #define	alloc_ebus_soft_state(i)	\
151*7c478bd9Sstevel@tonic-gate 	ddi_soft_state_zalloc(per_ebus_state, (i))
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate #define	free_ebus_soft_state(i)	\
154*7c478bd9Sstevel@tonic-gate 	ddi_soft_state_free(per_ebus_state, (i))
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate #define	getprop(dip, name, addr, intp)		\
158*7c478bd9Sstevel@tonic-gate 		ddi_getlongprop(DDI_DEV_T_NONE, (dip), DDI_PROP_DONTPASS, \
159*7c478bd9Sstevel@tonic-gate 				(name), (caddr_t)(addr), (intp))
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate #define	IS_RIO(dip) \
162*7c478bd9Sstevel@tonic-gate 		((ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, \
163*7c478bd9Sstevel@tonic-gate 		"device-id", -1) == 0x1100) && \
164*7c478bd9Sstevel@tonic-gate 		(ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, \
165*7c478bd9Sstevel@tonic-gate 		"vendor-id", -1) == 0x108e))
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate #define	EBUS_4MHZ	4000
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate /*
170*7c478bd9Sstevel@tonic-gate  * register offsets and lengths:
171*7c478bd9Sstevel@tonic-gate  */
172*7c478bd9Sstevel@tonic-gate #define	TCR_OFFSET	0x710000
173*7c478bd9Sstevel@tonic-gate #define	TCR_LENGTH	12
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate /*
176*7c478bd9Sstevel@tonic-gate  * timing control register settings:
177*7c478bd9Sstevel@tonic-gate  */
178*7c478bd9Sstevel@tonic-gate #define	TCR1		0x08101008
179*7c478bd9Sstevel@tonic-gate #define	TCR2		0x08100020
180*7c478bd9Sstevel@tonic-gate #define	TCR3		0x00000020
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate #if defined(DEBUG)
183*7c478bd9Sstevel@tonic-gate #define	D_IDENTIFY	0x00000001
184*7c478bd9Sstevel@tonic-gate #define	D_ATTACH	0x00000002
185*7c478bd9Sstevel@tonic-gate #define	D_DETACH	0x00000004
186*7c478bd9Sstevel@tonic-gate #define	D_MAP		0x00000008
187*7c478bd9Sstevel@tonic-gate #define	D_CTLOPS	0x00000010
188*7c478bd9Sstevel@tonic-gate #define	D_INTR		0x00000100
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate #define	DBG(flag, psp, fmt)	\
191*7c478bd9Sstevel@tonic-gate 	ebus_debug(flag, psp, fmt, 0, 0, 0, 0, 0);
192*7c478bd9Sstevel@tonic-gate #define	DBG1(flag, psp, fmt, a1)	\
193*7c478bd9Sstevel@tonic-gate 	ebus_debug(flag, psp, fmt, (uintptr_t)(a1), 0, 0, 0, 0);
194*7c478bd9Sstevel@tonic-gate #define	DBG2(flag, psp, fmt, a1, a2)	\
195*7c478bd9Sstevel@tonic-gate 	ebus_debug(flag, psp, fmt, (uintptr_t)(a1), (uintptr_t)(a2), 0, 0, 0);
196*7c478bd9Sstevel@tonic-gate #define	DBG3(flag, psp, fmt, a1, a2, a3)	\
197*7c478bd9Sstevel@tonic-gate 	ebus_debug(flag, psp, fmt, (uintptr_t)(a1), (uintptr_t)(a2), \
198*7c478bd9Sstevel@tonic-gate 	    (uintptr_t)(a3), 0, 0);
199*7c478bd9Sstevel@tonic-gate #define	DBG4(flag, psp, fmt, a1, a2, a3, a4)	\
200*7c478bd9Sstevel@tonic-gate 	ebus_debug(flag, psp, fmt, (uintptr_t)(a1), (uintptr_t)(a2), \
201*7c478bd9Sstevel@tonic-gate 	    (uintptr_t)(a3), \
202*7c478bd9Sstevel@tonic-gate 		(uintptr_t)(a4), 0);
203*7c478bd9Sstevel@tonic-gate #define	DBG5(flag, psp, fmt, a1, a2, a3, a4, a5)	\
204*7c478bd9Sstevel@tonic-gate 	ebus_debug(flag, psp, fmt, (uintptr_t)(a1), (uintptr_t)(a2), \
205*7c478bd9Sstevel@tonic-gate 	    (uintptr_t)(a3), \
206*7c478bd9Sstevel@tonic-gate 		(uintptr_t)(a4), (uintptr_t)(a5));
207*7c478bd9Sstevel@tonic-gate static void
208*7c478bd9Sstevel@tonic-gate ebus_debug(uint_t, ebus_devstate_t *, char *, uintptr_t, uintptr_t, uintptr_t,
209*7c478bd9Sstevel@tonic-gate     uintptr_t, uintptr_t);
210*7c478bd9Sstevel@tonic-gate #else
211*7c478bd9Sstevel@tonic-gate #define	DBG(flag, psp, fmt)
212*7c478bd9Sstevel@tonic-gate #define	DBG1(flag, psp, fmt, a1)
213*7c478bd9Sstevel@tonic-gate #define	DBG2(flag, psp, fmt, a1, a2)
214*7c478bd9Sstevel@tonic-gate #define	DBG3(flag, psp, fmt, a1, a2, a3)
215*7c478bd9Sstevel@tonic-gate #define	DBG4(flag, psp, fmt, a1, a2, a3, a4)
216*7c478bd9Sstevel@tonic-gate #define	DBG5(flag, psp, fmt, a1, a2, a3, a4, a5)
217*7c478bd9Sstevel@tonic-gate #endif
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
220*7c478bd9Sstevel@tonic-gate }
221*7c478bd9Sstevel@tonic-gate #endif
222*7c478bd9Sstevel@tonic-gate 
223*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_EBUS_H */
224