xref: /titanic_52/usr/src/uts/sun4u/sys/sbdpriv.h (revision ac88567a7a5bb7f01cf22cf366bc9d6203e24d7a)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_SBDPRIV_H
28 #define	_SYS_SBDPRIV_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/processor.h>
37 #include <sys/obpdefs.h>
38 #include <sys/memlist.h>
39 #include <sys/sbd_ioctl.h>
40 #include <sys/mem_config.h>
41 #include <sys/sbd.h>
42 #ifdef DEBUG
43 #include <sys/promif.h>
44 #endif
45 
46 
47 /*
48  * This structure passes the information when the caller requests to
49  * reserve a portion of unconfigured memory. It is also used to release
50  * previously reserved memory
51  */
52 struct sbd_mres {
53 	uint64_t	new_base_pa;	/* new base addr for physintalled */
54 	uint64_t	reserved_pa;	/* addr of the reserved mem */
55 	uint64_t	size;		/* size of the reserved chunk. */
56 };
57 
58 int sbd_memory_reserve(dev_info_t *, uint64_t, struct sbd_mres *);
59 int sbd_memory_release(dev_info_t *, uint64_t, struct sbd_mres *);
60 
61 /*	This error type is used inside sbd only */
62 typedef struct {
63 	int	e_errno;
64 	int	e_code;
65 	char	e_rsc[MAXPATHLEN];
66 } sbderror_t;
67 
68 #include <sys/sbd.h>
69 #include <sys/sbd_error.h>
70 
71 typedef enum {
72 	SBD_STATE_EMPTY = 0,
73 	SBD_STATE_OCCUPIED,
74 	SBD_STATE_CONNECTED,
75 	SBD_STATE_UNCONFIGURED,
76 	SBD_STATE_PARTIAL,
77 	SBD_STATE_CONFIGURED,
78 	SBD_STATE_RELEASE,
79 	SBD_STATE_UNREFERENCED,
80 	SBD_STATE_FATAL,
81 	SBD_STATE_MAX
82 } sbd_istate_t;
83 
84 typedef struct {
85 	sbderror_t	*errp;
86 	sbd_flags_t	flags;
87 } sbd_treeinfo_t;
88 
89 /*
90  * generic flags (sbd_handle.h_flags)
91  */
92 #define	SBD_FLAG_DEVI_FORCE	0x00000001
93 
94 /* mirror of SBD_FLAG_FORCE from sbd_ioctl.h */
95 #define	SBD_IOCTL_FLAG_FORCE	0x00000004
96 
97 #define	SBD_USER_FLAG_MASK	0x0000ffff
98 
99 #define	SBD_KERN_FLAG_MASK	0xffff0000	/* no flags in use */
100 
101 /*
102  * Translation macros for sbd->sbdp flags
103  */
104 #define	SBD_2_SBDP_FLAGS(f) (((f) & SBD_IOCTL_FLAG_FORCE) ? \
105 				SBDP_IOCTL_FLAG_FORCE : 0)
106 
107 typedef struct sbd_handle {
108 	void 		*h_sbd;
109 	sbderror_t	*h_err;
110 	dev_t		h_dev;		/* dev_t of opened device */
111 	int		h_cmd;		/* ioctl argument */
112 	int		h_mode;		/* device open mode */
113 	sbd_flags_t	h_flags;
114 	sbd_ioctl_arg_t	*h_iap;		/* points to kernel copy of ioargs */
115 	sbdp_opts_t	h_opts;		/* points to the platform options */
116 } sbd_handle_t;
117 
118 #define	SBD_HD2ERR(hd)		((hd)->h_err)
119 #define	SBD_GET_ERR(ep)		((ep)->e_code)
120 #define	SBD_SET_ERR(ep, ec)	((ep)->e_code = (ec))
121 #define	SBD_GET_ERRNO(ep)	((ep)->e_errno)
122 #define	SBD_SET_ERRNO(ep, en)	((ep)->e_errno = (en))
123 #define	SBD_GET_ERRSTR(ep)	((ep)->e_rsc)
124 
125 #define	SBD_SET_ERRSTR(ep, es)	\
126 { \
127 	if ((es) && (*(es) != '\0')) \
128 		(void) strncpy((ep)->e_rsc, (es), MAXPATHLEN); \
129 }
130 
131 #define	SBD_SET_IOCTL_ERR(ierr, code, rsc) \
132 { \
133 	(ierr)->e_code = (int)(code); \
134 	if ((rsc) && (*(rsc) != '\0')) \
135 		bcopy((caddr_t)(rsc), \
136 			(caddr_t)(ierr)->e_rsc, \
137 			sizeof ((ierr)->e_rsc)); \
138 }
139 
140 #define	SBD_FREE_ERR(ep) \
141 	((ep)->e_rsc[0] = '\0')
142 
143 #define	SBD_GET_PERR(spe, ep) \
144 	(ep)->e_errno = EIO; \
145 	(ep)->e_code = (spe)->e_code; \
146 	if (*((spe)->e_rsc) != '\0') \
147 		bcopy((caddr_t)((spe)->e_rsc), \
148 			(caddr_t)((ep))->e_rsc, \
149 			sizeof (((ep))->e_rsc));
150 
151 /*
152  * dev_t is shared by PIM and PSM layers.
153  *
154  * Format = 31......16,15.......0
155  *	    |   PIM   |   PSM   |
156  */
157 #define	_SBD_DEVPIM_SHIFT	16
158 #define	_SBD_DEVPIM_MASK		0xffff
159 #define	_SBD_DEVPSM_MASK		0xffff
160 
161 #define	SBD_GET_MINOR2INST(d)	(((d) >> _SBD_DEVPIM_SHIFT) & _SBD_DEVPIM_MASK)
162 #define	SBD_MAKE_MINOR(i, m) \
163 			((((i) & _SBD_DEVPIM_MASK) << _SBD_DEVPIM_SHIFT) | \
164 			((m) & _SBD_DEVPSM_MASK))
165 
166 #define	GETSTRUCT(t, n) \
167 		((t *)kmem_zalloc((size_t)(n) * sizeof (t), KM_SLEEP))
168 #define	FREESTRUCT(p, t, n) \
169 		(kmem_free((caddr_t)(p), sizeof (t) * (size_t)(n)))
170 
171 #define	GET_SOFTC(i)		ddi_get_soft_state(sbd_g.softsp, (i))
172 #define	ALLOC_SOFTC(i)		ddi_soft_state_zalloc(sbd_g.softsp, (i))
173 #define	FREE_SOFTC(i)		ddi_soft_state_free(sbd_g.softsp, (i))
174 
175 /*
176  * Per instance soft-state structure.
177  */
178 typedef struct sbd_softstate {
179 	void		*sbd_boardlist;
180 	int		max_boards;
181 	int		wnode;
182 } sbd_softstate_t;
183 
184 /*
185  * dr Global data elements
186  */
187 typedef struct {
188 	sbd_softstate_t	*softsp;	/* pointer to initialize soft state */
189 } sbd_global;
190 
191 typedef struct {
192 	sbderror_t	dv_error;
193 	dev_info_t	*dv_dip;
194 } sbd_devlist_t;
195 
196 extern int	plat_max_io_units_per_board();
197 extern int	plat_max_cmp_units_per_board();
198 extern int	plat_max_cpu_units_per_board();
199 extern int	plat_max_mem_units_per_board();
200 #define	MAX_IO_UNITS_PER_BOARD		plat_max_io_units_per_board()
201 #define	MAX_CMP_UNITS_PER_BOARD		plat_max_cmp_units_per_board()
202 #define	MAX_CPU_UNITS_PER_BOARD		plat_max_cpu_units_per_board()
203 #define	MAX_MEM_UNITS_PER_BOARD		plat_max_mem_units_per_board()
204 #define	SBD_MAX_UNITS_PER_BOARD		8
205 /* If any of the max units exceeds 5, this must be adjusted	*/
206 
207 #define	SBD_MAX_INSTANCES		16
208 
209 #define	SBD_NUM_STATES		((int)SBD_STATE_MAX)
210 
211 #ifdef DEBUG
212 #define	SBD_DEVICE_TRANSITION(sb, nt, un, st) \
213 { \
214 	int	_ostate, _nstate; \
215 	_ostate = (int)((sb)->sb_dev[NIX(nt)][un].u_common.sbdev_state); \
216 	_nstate = (int)(st); \
217 	PR_STATE("BOARD %d (%s.%d) STATE: %s(%d) -> %s(%d)\n", \
218 		(sb)->sb_num, \
219 		sbd_ct_str[nt], (un), \
220 		sbd_state_str[_ostate], _ostate, \
221 		sbd_state_str[_nstate], _nstate); \
222 	(void) drv_getparm(TIME, \
223 	(void *)&(sb)->sb_dev[NIX(nt)][un].u_common.sbdev_time); \
224 	(sb)->sb_dev[NIX(nt)][un].u_common.sbdev_state = (st); \
225 	(sb)->sb_dev[NIX(nt)][un].u_common.sbdev_ostate = ostate_cvt(st); \
226 	send_event = 1; \
227 }
228 #define	SBD_BOARD_TRANSITION(sb, st) \
229 { \
230 	PR_STATE("BOARD %d STATE: %s(%d) -> %s(%d)\n", \
231 		(sb)->sb_num, \
232 		sbd_state_str[(int)(sb)->sb_state], (int)(sb)->sb_state, \
233 		sbd_state_str[(int)(st)], (int)(st)); \
234 	(sb)->sb_pstate = (sb)->sb_state; \
235 	(sb)->sb_state = (st); \
236 	send_event = 1; \
237 }
238 #else /* DEBUG */
239 #define	SBD_DEVICE_TRANSITION(sb, nt, un, st) \
240 { \
241 	(sb)->sb_dev[NIX(nt)][un].u_common.sbdev_state = (st); \
242 	(sb)->sb_dev[NIX(nt)][un].u_common.sbdev_ostate = ostate_cvt(st); \
243 	(void) drv_getparm(TIME, \
244 		(void *)&(sb)->sb_dev[NIX(nt)][un].u_common.sbdev_time); \
245 	send_event = 1; \
246 }
247 #define	SBD_BOARD_TRANSITION(sb, st) \
248 		((sb)->sb_pstate = (sb)->sb_state, (sb)->sb_state = (st),  \
249 		send_event = 1)
250 #endif /* DEBUG */
251 
252 #define	SBD_DEVICE_STATE(sb, nt, un) \
253 		((sb)->sb_dev[NIX(nt)][un].u_common.sbdev_state)
254 #define	SBD_BOARD_STATE(sb) \
255 		((sb)->sb_state)
256 #define	SBD_BOARD_PSTATE(sb) \
257 		((sb)->sb_pstate)
258 
259 typedef uint32_t sbd_devset_t;
260 
261 /*
262  * sbd_priv_handle_t MUST appear first.
263  */
264 typedef struct sbd_priv_handle {
265 	sbd_handle_t		sh_handle;
266 	void			*sh_arg;	/* raw ioctl arg */
267 	sbd_devset_t		sh_devset;	/* based on h_dev */
268 	sbd_devset_t		sh_orig_devset;	/* what client requested */
269 	sbderror_t		sh_err;
270 	struct sbd_priv_handle	*sh_next;
271 } sbd_priv_handle_t;
272 
273 #define	SBD_MAXNUM_NT		3
274 #define	NIX(t)			(((t) == SBD_COMP_CPU) ? 0 : \
275 				((t) == SBD_COMP_MEM) ? 1 : \
276 				((t) == SBD_COMP_IO) ? 2 : \
277 				((t) == SBD_COMP_CMP) ? 0 : SBD_MAXNUM_NT)
278 
279 #define	SBD_NUM_MC_PER_BOARD	4
280 
281 
282 typedef struct sbd_common_unit {
283 	sbd_istate_t		sbdev_state;
284 	sbd_cond_t		sbdev_cond;
285 	sbd_state_t		sbdev_ostate;
286 	time_t			sbdev_time;
287 	int			sbdev_busy;
288 	void			*sbdev_sbp;
289 	int			sbdev_unum;
290 	sbd_comp_type_t		sbdev_type;
291 	dev_info_t		*sbdev_dip;
292 } sbd_common_unit_t;
293 
294 typedef struct sbd_mem_unit {
295 	sbd_common_unit_t	sbm_cm;
296 	sbd_istate_t		sbm_state;	/* mem-unit state */
297 	uint_t			sbm_flags;
298 	pfn_t			sbm_basepfn;
299 	pgcnt_t			sbm_npages;
300 	pgcnt_t			sbm_pageslost;
301 	/*
302 	 * The following fields are used during
303 	 * the memory detach process only. sbm_mlist
304 	 * will be used to store the board memlist
305 	 * following a detach. The memlist will be
306 	 * used to re-attach the board when configuring
307 	 * the unit directly after an unconfigure.
308 	 */
309 	struct sbd_mem_unit	*sbm_peer;
310 	struct memlist		*sbm_mlist;
311 	struct memlist		*sbm_del_mlist;
312 	memhandle_t		sbm_memhandle;
313 	pfn_t			sbm_alignment_mask;
314 	pfn_t			sbm_slice_offset;
315 	/*
316 	 * The following field is used to support the
317 	 * representation of all memory controllers on
318 	 * a board with one sbd_mem_unit_t.
319 	 */
320 	dev_info_t		*sbm_dip[SBD_NUM_MC_PER_BOARD];
321 	/*
322 	 * The following field determines if the memory on this board
323 	 * is part of an interleave across boards
324 	 */
325 	int			sbm_interleave;
326 } sbd_mem_unit_t;
327 
328 /*
329  * Currently only maintain state information for individual
330  * components.
331  */
332 typedef struct sbd_cpu_unit {
333 	sbd_common_unit_t	sbc_cm;		/* cpu-unit state */
334 	processorid_t		sbc_cpu_id;
335 	cpu_flag_t		sbc_cpu_flags;
336 	ushort_t		sbc_pad1;
337 	int			sbc_cpu_impl;
338 	int			sbc_speed;
339 	int			sbc_ecache;
340 } sbd_cpu_unit_t;
341 
342 typedef struct sbd_io_unit {
343 	sbd_common_unit_t	sbi_cm;		/* io-unit state */
344 } sbd_io_unit_t;
345 
346 typedef union {
347 	sbd_common_unit_t	u_common;
348 	sbd_mem_unit_t		_mu;
349 	sbd_cpu_unit_t		_cu;
350 	sbd_io_unit_t		_iu;
351 } sbd_dev_unit_t;
352 
353 typedef struct {
354 	sbd_priv_handle_t	*sb_handle;
355 	int			sb_ref;		/* # of handle references */
356 	int			sb_num;		/* board number */
357 	void			*sb_softsp;	/* pointer to soft state */
358 	dev_info_t		*sb_topdip;	/* top devinfo of instance */
359 	sbd_istate_t		sb_state;	/* (current) board state */
360 	sbd_istate_t		sb_pstate;	/* previous board state */
361 	sbd_cond_t		sb_cond;	/* condition		*/
362 	sbd_state_t		sb_rstate;	/* receptacle state	*/
363 	sbd_state_t		sb_ostate;	/* occupant state	*/
364 		/*
365 		 * 0=CPU, 1=MEM, 2=IO, 3=NULL
366 		 */
367 	dev_info_t		**sb_devlist[SBD_MAXNUM_NT + 1];
368 
369 	sbd_devset_t	sb_dev_present;		/* present mask */
370 	sbd_devset_t	sb_dev_attached;	/* attached mask */
371 	sbd_devset_t	sb_dev_released;	/* released mask */
372 	sbd_devset_t	sb_dev_unreferenced;	/* unreferenced mask */
373 	sbd_dev_unit_t	*sb_dev[SBD_MAXNUM_NT];
374 
375 	char		*sb_cpupath[SBD_MAX_UNITS_PER_BOARD];
376 	char		*sb_mempath[SBD_MAX_UNITS_PER_BOARD];
377 	char		*sb_iopath[SBD_MAX_UNITS_PER_BOARD];
378 
379 	int		sb_ndev;		/* number of devs */
380 	int		sb_errno;		/* store errno */
381 	int		sb_busy;		/* drain in progress */
382 	int		sb_assigned;
383 	int		sb_flags;
384 	kmutex_t	sb_flags_mutex;		/* mutex to protect flags */
385 	int		sb_wnode;
386 	int		sb_memaccess_ok;
387 	sbd_stat_t	sb_stat;		/* cached board status */
388 	processorid_t	sb_cpuid;		/* for starfire connect */
389 	time_t		sb_time;		/* time of last board op */
390 	kmutex_t	sb_mutex;
391 	kmutex_t	sb_slock;		/* status - unconfig, discon */
392 } sbd_board_t;
393 
394 /* definitions for sb_flags */
395 #define	SBD_BOARD_STATUS_CACHED	1
396 
397 #define	SBD_GET_BOARD_MEMUNIT(sb, un) \
398 			(&((sb)->sb_dev[NIX(SBD_COMP_MEM)][un]._mu))
399 #define	SBD_GET_BOARD_CPUUNIT(sb, un) \
400 			(&((sb)->sb_dev[NIX(SBD_COMP_CPU)][un]._cu))
401 #define	SBD_GET_BOARD_IOUNIT(sb, un) \
402 			(&((sb)->sb_dev[NIX(SBD_COMP_IO)][un]._iu))
403 
404 typedef ushort_t	boardset_t;	/* assumes 16 boards max */
405 
406 #define	BOARDSET(b)		((boardset_t)(1 << (b)))
407 #define	BOARD_IN_SET(bs, b)	(((bs) & BOARDSET(b)) != 0)
408 #define	BOARD_ADD(bs, b)	((bs) |= BOARDSET(b))
409 #define	BOARD_DEL(bs, b)	((bs) &= ~BOARDSET(b))
410 
411 /*
412  * Format of sbd_devset_t bit masks:
413  *
414  *	32		   16        8    4    0
415  *	|....|....|...I|IIII|....|...M|CCCC|CCCC|
416  * 1 = indicates respective component present/attached.
417  * I = I/O, M = Memory, C = CPU.
418  */
419 #define	DEVSET_ANYUNIT		(-1)
420 #define	_NT2DEVPOS(t, u)	((NIX(t) << 3) + (u))
421 #define	_DEVSET_MASK		0x001f01ff
422 #define	_CMP_DEVSET_MASK	0x11
423 #define	DEVSET(t, u) \
424 	(((u) == DEVSET_ANYUNIT) ? \
425 	    (sbd_devset_t)((0xff << _NT2DEVPOS((t), 0)) & _DEVSET_MASK) : \
426 	(((t) == SBD_COMP_CMP) ? \
427 	    (sbd_devset_t)(_CMP_DEVSET_MASK << _NT2DEVPOS((t), (u))) : \
428 	(sbd_devset_t)(1 << _NT2DEVPOS((t), (u)))))
429 
430 #define	DEVSET_IN_SET(ds, t, u)	(((ds) & DEVSET((t), (u))) != 0)
431 #define	DEVSET_ADD(ds, t, u)	((ds) |= DEVSET((t), (u)))
432 #define	DEVSET_DEL(ds, t, u)	((ds) &= ~DEVSET((t), (u)))
433 #define	DEVSET_GET_UNITSET(ds, t) \
434 	(((ds) & DEVSET((t), DEVSET_ANYUNIT)) >> _NT2DEVPOS((t), 0))
435 /*
436  * Ops for sbd_board_t.sb_dev_present
437  */
438 #define	SBD_DEV_IS_PRESENT(bp, nt, un) \
439 			DEVSET_IN_SET((bp)->sb_dev_present, (nt), (un))
440 #define	SBD_DEV_SET_PRESENT(bp, nt, un) \
441 			DEVSET_ADD((bp)->sb_dev_present, (nt), (un))
442 #define	SBD_DEV_CLR_PRESENT(bp, nt, un) \
443 			DEVSET_DEL((bp)->sb_dev_present, (nt), (un))
444 /*
445  * Ops for sbd_board_t.sb_dev_attached
446  */
447 #define	SBD_DEV_IS_ATTACHED(bp, nt, un) \
448 			DEVSET_IN_SET((bp)->sb_dev_attached, (nt), (un))
449 #define	SBD_DEV_SET_ATTACHED(bp, nt, un) \
450 			DEVSET_ADD((bp)->sb_dev_attached, (nt), (un))
451 #define	SBD_DEV_CLR_ATTACHED(bp, nt, un) \
452 			DEVSET_DEL((bp)->sb_dev_attached, (nt), (un))
453 /*
454  * Ops for sbd_board_t.sb_dev_released
455  */
456 #define	SBD_DEV_IS_RELEASED(bp, nt, un) \
457 			DEVSET_IN_SET((bp)->sb_dev_released, (nt), (un))
458 #define	SBD_DEV_SET_RELEASED(bp, nt, un) \
459 			DEVSET_ADD((bp)->sb_dev_released, (nt), (un))
460 #define	SBD_DEV_CLR_RELEASED(bp, nt, un) \
461 			DEVSET_DEL((bp)->sb_dev_released, (nt), (un))
462 /*
463  * Ops for sbd_board_t.sb_dev_unreferenced
464  */
465 #define	SBD_DEV_IS_UNREFERENCED(bp, nt, un) \
466 			DEVSET_IN_SET((bp)->sb_dev_unreferenced, (nt), (un))
467 #define	SBD_DEV_SET_UNREFERENCED(bp, nt, un) \
468 			DEVSET_ADD((bp)->sb_dev_unreferenced, (nt), (un))
469 #define	SBD_DEV_CLR_UNREFERENCED(bp, nt, un) \
470 			DEVSET_DEL((bp)->sb_dev_unreferenced, (nt), (un))
471 
472 #define	SBD_DEVS_PRESENT(bp) \
473 			((bp)->sb_dev_present)
474 #define	SBD_DEVS_ATTACHED(bp) \
475 			((bp)->sb_dev_attached)
476 #define	SBD_DEVS_RELEASED(bp) \
477 			((bp)->sb_dev_released)
478 #define	SBD_DEVS_UNREFERENCED(bp) \
479 			((bp)->sb_dev_unreferenced)
480 #define	SBD_DEVS_UNATTACHED(bp) \
481 			((bp)->sb_dev_present & ~(bp)->sb_dev_attached)
482 #define	SBD_DEVS_CONFIGURE(bp, devs) \
483 			((bp)->sb_dev_attached = (devs))
484 #define	SBD_DEVS_DISCONNECT(bp, devs) \
485 			((bp)->sb_dev_present &= ~(devs))
486 #define	SBD_DEVS_CANCEL(bp, devs) \
487 			((bp)->sb_dev_released &= ~(devs), \
488 			(bp)->sb_dev_unreferenced &= ~(devs))
489 
490 /*
491  * return values from sbd_cancel_cpu
492  */
493 #define	SBD_CPUERR_NONE		0
494 #define	SBD_CPUERR_RECOVERABLE	-1
495 #define	SBD_CPUERR_FATAL	-2
496 
497 /*
498  * sbd_board_t.sbmem[].sbm_flags
499  */
500 #define	SBD_MFLAG_RESERVED	0x01	/* mem unit reserved for delete */
501 #define	SBD_MFLAG_SOURCE	0x02	/* source brd of copy/rename op */
502 #define	SBD_MFLAG_TARGET	0x04	/* board selected as target */
503 #define	SBD_MFLAG_MEMUPSIZE	0x08	/* move from big to small board */
504 #define	SBD_MFLAG_MEMDOWNSIZE	0x10	/* move from small to big board */
505 #define	SBD_MFLAG_MEMRESIZE	0x18	/* move to different size board */
506 #define	SBD_MFLAG_RELOWNER	0x20	/* memory release (delete) owner */
507 #define	SBD_MFLAG_RELDONE	0x40
508 
509 typedef struct {
510 	int	sfio_cmd;
511 	void	*sfio_arg;
512 } sbd_ioctl_t;
513 
514 /*
515  * 32bit support for sbd_ioctl_t.
516  */
517 typedef struct {
518 	int32_t		sfio_cmd;
519 	uint32_t	sfio_arg;
520 } sbd_ioctl32_t;
521 
522 /*
523  * PSM-DR layers are only allowed to use lower 16 bits of dev_t.
524  * B    - bottom 4 bits are for the slot number.
525  * D    - device type chosen (0 = indicates all devices in slot).
526  * U	- unit number if specific device type chosen.
527  * X    - not used.
528  *
529  * Upper      Lower
530  * XXXXUUUUDDDDBBBB
531  *
532  * Note that this format only allows attachment points to
533  * either represent all the units on a board or one particular
534  * unit.  A more general specification would permit any combination
535  * of specific units and types to be represented by individual
536  * attachment points.
537  */
538 #define	SBD_DEV_SLOTMASK	0x000f
539 /*
540  * These device level definitions are primarily for unit testing.
541  */
542 #define	SBD_DEV_UNITMASK	0x0f00
543 #define	SBD_DEV_UNITSHIFT	8
544 #define	SBD_DEV_CPU		0x0010
545 #define	SBD_DEV_MEM		0x0020
546 #define	SBD_DEV_IO		0x0040
547 #define	SBD_DEV_TYPEMASK	(SBD_DEV_CPU | SBD_DEV_MEM | SBD_DEV_IO)
548 #define	SBD_DEV_TYPESHIFT	4
549 
550 /*
551  * Slot, Instance, and Minor number Macro definitions
552  */
553 #define	SLOT2DEV(s)		((s) & SBD_DEV_SLOTMASK)
554 #define	SBDGETSLOT(unit)	((unit) & SBD_DEV_SLOTMASK)
555 /*
556  * The following is primarily for unit testing.
557  */
558 #define	ALLCPU2DEV(s)		(SBD_DEV_CPU | SLOT2DEV(s))
559 #define	ALLMEM2DEV(s)		(SBD_DEV_MEM | SLOT2DEV(s))
560 #define	ALLIO2DEV(s)		(SBD_DEV_IO | SLOT2DEV(s))
561 #define	_UNIT2DEV(u)		(((u) << SBD_DEV_UNITSHIFT) & \
562 					SBD_DEV_UNITMASK)
563 #define	CPUUNIT2DEV(s, c)	(_UNIT2DEV(c) | ALLCPU2DEV(s))
564 #define	MEMUNIT2DEV(s, m)	(_UNIT2DEV(m) | ALLMEM2DEV(s))
565 #define	IOUNIT2DEV(s, i)	(_UNIT2DEV(i) | ALLIO2DEV(s))
566 
567 #define	DEV_IS_ALLUNIT(d)	(((d) & SBD_DEV_UNITMASK) == 0)
568 #define	_DEV_IS_ALLTYPE(d)	(((d) & SBD_DEV_TYPEMASK) == 0)
569 #define	DEV_IS_ALLBOARD(d)	(DEV_IS_ALLUNIT(d) && _DEV_IS_ALLTYPE(d))
570 #define	DEV_IS_CPU(d)		((d) & SBD_DEV_CPU)
571 #define	DEV_IS_MEM(d)		((d) & SBD_DEV_MEM)
572 #define	DEV_IS_IO(d)		((d) & SBD_DEV_IO)
573 #define	DEV_IS_ALLCPU(d)	(DEV_IS_ALLUNIT(d) && DEV_IS_CPU(d))
574 #define	DEV_IS_ALLMEM(d)	(DEV_IS_ALLUNIT(d) && DEV_IS_MEM(d))
575 #define	DEV_IS_ALLIO(d)		(DEV_IS_ALLUNIT(d) && DEV_IS_IO(d))
576 #define	DEV2UNIT(d) \
577 		((((d) & SBD_DEV_UNITMASK) >> SBD_DEV_UNITSHIFT) - 1)
578 #define	DEV2NT(d) \
579 		(DEV_IS_MEM(d) ? SBD_COMP_MEM : \
580 		DEV_IS_CPU(d) ? SBD_COMP_CPU : \
581 		DEV_IS_IO(d) ? SBD_COMP_IO : SBD_COMP_UNKNOWN)
582 
583 /*
584  * Macros to cast between PIM and PSM layers of the following
585  * structures:
586  *	board_t		<-> sbd_board_t
587  *	sbd_handle_t	<-> sbd_priv_handle_t
588  *	sbderror_t	<-> sbderror_t
589  *	slot		-> board_t
590  *	slot		-> sbd_board_t
591  *	sbd_board_t	-> sbd_handle_t
592  *	sbd_handle	-> sbderror_t
593  */
594 #define	SBDH2BD(bd)		((sbd_board_t *)(bd))
595 
596 #define	HD2MACHHD(hd)		((sbd_priv_handle_t *)(hd))
597 #define	MACHHD2HD(mhd)		((sbd_handle_t *)&((mhd)->sh_handle))
598 
599 #define	ERR2MACHERR(err)	((sbderror_t *)(err))
600 #define	MACHERR2ERR(merr)	((sbderror_t *)(merr))
601 
602 #define	BSLOT2MACHBD(b)		(&(sbd_boardlist[b]))
603 #define	BSLOT2BD(slot)		MACHBD2BD(BSLOT2MACHBD(slot))
604 
605 #define	MACHBD2HD(sbp)		MACHHD2HD((sbp)->sb_handle)
606 
607 #define	HD2MACHERR(hd)		ERR2MACHERR(SBD_HD2ERR(hd))
608 
609 #define	MACHSRHD2HD(srh)	((srh)->sr_dr_handlep)
610 
611 /*
612  * CMP Specific Helpers
613  */
614 #define	MAX_CORES_PER_CMP		2
615 #define	SBD_CMP_CORE_UNUM(cmp, core)	((cmp + (core * 512))
616 #define	SBD_CMP_NUM(unum)		(unum & 0x3)
617 
618 /*
619  * Some stuff to assist in debug.
620  */
621 #ifdef DEBUG
622 #define	SBD_DBG_STATE	0x00000001
623 #define	SBD_DBG_QR	0x00000002
624 #define	SBD_DBG_CPU	0x00000004
625 #define	SBD_DBG_MEM	0x00000008
626 #define	SBD_DBG_IO	0x00000010
627 #define	SBD_DBG_HW	0x00000020
628 #define	SBD_DBG_BYP	0x00000040
629 
630 #define	PR_ALL		if (sbd_debug)			printf
631 #define	PR_STATE	if (sbd_debug & SBD_DBG_STATE)	printf
632 #define	PR_QR		if (sbd_debug & SBD_DBG_QR)	prom_printf
633 #define	PR_CPU		if (sbd_debug & SBD_DBG_CPU)	printf
634 #define	PR_MEM		if (sbd_debug & SBD_DBG_MEM)	printf
635 #define	PR_IO		if (sbd_debug & SBD_DBG_IO)	printf
636 #define	PR_HW		if (sbd_debug & SBD_DBG_HW)	printf
637 #define	PR_BYP		if (sbd_debug & SBD_DBG_BYP)	prom_printf
638 
639 #define	SBD_MEMLIST_DUMP(ml)	memlist_dump(ml)
640 
641 extern uint_t	sbd_debug;
642 #else /* DEBUG */
643 #define	PR_ALL		if (0) printf
644 #define	PR_STATE	PR_ALL
645 #define	PR_QR		PR_ALL
646 #define	PR_CPU		PR_ALL
647 #define	PR_MEM		PR_ALL
648 #define	PR_IO		PR_ALL
649 #define	PR_HW		PR_ALL
650 #define	PR_BYP		PR_ALL
651 
652 #define	SBD_MEMLIST_DUMP(ml)
653 #endif /* DEBUG */
654 extern char	*sbd_state_str[];
655 extern char	*sbd_ct_str[];
656 
657 /*
658  * event flag
659  */
660 extern char send_event;
661 
662 /*
663  * IMPORTANT:
664  * The following two defines are also coded into OBP, so if they
665  * need to change here, don't forget to change OBP also.
666  */
667 #define	SBD_OBP_PROBE_GOOD	0
668 #define	SBD_OBP_PROBE_BAD	1
669 
670 extern int		sbd_setup_instance(int, dev_info_t *, int, int,
671 				caddr_t);
672 extern int		sbd_teardown_instance(int, caddr_t);
673 extern int		sbd_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
674 				char *event);
675 
676 extern sbd_comp_type_t	sbd_cm_type(char *name);
677 extern sbd_state_t	ostate_cvt(sbd_istate_t state);
678 extern void		sbd_cpu_set_prop(sbd_cpu_unit_t *cp, dev_info_t *dip);
679 extern int		sbd_cpu_flags(sbd_handle_t *hp, sbd_devset_t devset,
680 				sbd_dev_stat_t *dsp);
681 extern int		sbd_disconnect_cpu(sbd_handle_t *hp, int unit);
682 extern int		sbd_connect_cpu(sbd_board_t *sbp, int unit);
683 extern int		sbd_disconnect_mem(sbd_handle_t *hp, int unit);
684 
685 extern int		sbd_pre_detach_mem(sbd_handle_t *hp,
686 				sbd_devlist_t *devlist, int devnum);
687 extern int		sbd_post_attach_mem(sbd_handle_t *,
688 				sbd_devlist_t *, int);
689 extern int		sbd_post_detach_mem(sbd_handle_t *,
690 				sbd_devlist_t *, int);
691 extern int		sbd_post_attach_cpu(sbd_handle_t *hp,
692 					sbd_devlist_t *devlist, int devnum);
693 extern int		sbd_pre_release_cpu(sbd_handle_t *hp,
694 					sbd_devlist_t *devlist, int devnum);
695 extern int		sbd_pre_detach_cpu(sbd_handle_t *hp,
696 					sbd_devlist_t *devlist, int devnum);
697 extern int		sbd_post_detach_cpu(sbd_handle_t *hp,
698 					sbd_devlist_t *devlist, int devnum);
699 extern int		sbd_pre_attach_mem(sbd_handle_t *hp,
700 					sbd_devlist_t *devlist, int devnum);
701 extern int		sbd_pre_release_mem(sbd_handle_t *hp,
702 					sbd_devlist_t *devlist, int devnum);
703 extern int		sbd_disconnect_io(sbd_handle_t *hp, int unit);
704 extern void		sbd_check_devices(dev_info_t *dip, int *refcount,
705 					sbd_handle_t *handle);
706 extern struct memlist	*sbd_get_memlist(sbd_mem_unit_t *mp, sbderror_t *ep);
707 extern void		sbd_init_mem_unit(sbd_board_t *sbp, int unit,
708 					sbderror_t *ep);
709 extern void		sbd_release_mem_done(sbd_handle_t *hp, int unit);
710 extern void		sbd_release_cleanup(sbd_handle_t *hp);
711 extern int		sbd_cancel_cpu(sbd_handle_t *hp, int unit);
712 extern void		sbd_init_err(sbderror_t *ep);
713 extern int		sbd_cancel_mem(sbd_handle_t *hp, int unit);
714 extern sbd_comp_type_t	sbd_get_devtype(sbd_handle_t *hp, dev_info_t *dip);
715 extern int		sbd_get_board(dev_info_t *dip);
716 extern int		sfhw_get_base_physaddr(dev_info_t *dip,
717 					uint64_t *basepa);
718 extern int		sbd_pre_attach_cpu(sbd_handle_t *hp,
719 					sbd_devlist_t *devlist, int devnum);
720 extern int		sbd_move_memory(sbd_handle_t *hp, sbd_board_t
721 				*s_bp, sbd_board_t *t_bp);
722 extern void		memlist_delete(struct memlist *mlist);
723 extern struct memlist	*memlist_dup(struct memlist *mlist);
724 extern void		memlist_dump(struct memlist *mlist);
725 extern int		memlist_intersect(struct memlist *alist,
726 					struct memlist *blist);
727 extern int		sbd_juggle_bootproc(sbd_handle_t *hp,
728 					processorid_t cpuid);
729 
730 extern sbd_cond_t	sbd_get_comp_cond(dev_info_t *);
731 void			sbd_attach_mem(sbd_handle_t *hp, sbderror_t *ep);
732 int			sbd_release_mem(sbd_handle_t *hp, dev_info_t *dip,
733 					int unit);
734 
735 int			sbd_get_memhandle(sbd_handle_t *hp, dev_info_t *dip,
736 					memhandle_t *mhp);
737 int			sbd_detach_memory(sbd_handle_t *hp, sbderror_t *ep,
738 					sbd_mem_unit_t *s_mp, int unit);
739 void			sbd_release_memory_done(void *arg, int error);
740 int			sbd_set_err_in_hdl(sbd_handle_t *hp, sbderror_t *ep);
741 sbdp_handle_t		*sbd_get_sbdp_handle(sbd_board_t *sbp,
742 					sbd_handle_t *hp);
743 void			sbd_release_sbdp_handle(sbdp_handle_t *hp);
744 void			sbd_reset_error_sbdph(sbdp_handle_t *hp);
745 extern int		sbd_is_cmp_child(dev_info_t *dip);
746 
747 typedef const char *const fn_t;
748 
749 #ifdef	__cplusplus
750 }
751 #endif
752 
753 #endif /* _SYS_SBDPRIV_H */
754