xref: /onnv-gate/usr/src/uts/sun4/sys/fcode.h (revision 762)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*762Sdhain  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_SYS_FCODE_H
280Sstevel@tonic-gate #define	_SYS_FCODE_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/sysmacros.h>
330Sstevel@tonic-gate #include <sys/ddi.h>
340Sstevel@tonic-gate #include <sys/sunddi.h>
350Sstevel@tonic-gate #include <sys/fc_plat.h>
360Sstevel@tonic-gate #include <sys/pci.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifdef	__cplusplus
390Sstevel@tonic-gate extern "C" {
400Sstevel@tonic-gate #endif
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  * The FCode driver presents a private interface to the fcode
440Sstevel@tonic-gate  * user level interpreter.  This interface is subject to change
450Sstevel@tonic-gate  * at any time and is only provided for use by the fcode interpreter.
460Sstevel@tonic-gate  *
470Sstevel@tonic-gate  * The user program opens the device, causing a new instance of
480Sstevel@tonic-gate  * the driver to be cloned.  This instance is specific to a specific
490Sstevel@tonic-gate  * instance of a new device managed by the kernel and driver framework.
500Sstevel@tonic-gate  *
510Sstevel@tonic-gate  * The interpreter does an FC_GET_PARAMETERS ioctl to get the fcode
520Sstevel@tonic-gate  * length, which can be mmap-ed (at offset 0) to provide access to a copy
530Sstevel@tonic-gate  * of the device's fcode.
540Sstevel@tonic-gate  *
550Sstevel@tonic-gate  * The interpreter uses the FC_RUN_PRIV ioctl to request privileged
560Sstevel@tonic-gate  * operations to be run by the driver.
570Sstevel@tonic-gate  *
580Sstevel@tonic-gate  * The interpreter sends an FC_VALIDATE ioctl to notify the
590Sstevel@tonic-gate  * driver that it's done interpreting FCode to signify a normal
600Sstevel@tonic-gate  * ending sequence when the interpreter later closes the device.
610Sstevel@tonic-gate  * This way the driver can easily distinguish between the user
620Sstevel@tonic-gate  * level interpreter failing and finishing normally, thus validating
630Sstevel@tonic-gate  * the interpreters actions and the state it downloads to the driver.
640Sstevel@tonic-gate  * The 'arg' value in the FC_VALIDATE ioctl is ignored, there
650Sstevel@tonic-gate  * are no arguments to this ioctl.
660Sstevel@tonic-gate  */
670Sstevel@tonic-gate 
680Sstevel@tonic-gate #define	FCIOC			(0xfc<<8)
690Sstevel@tonic-gate #define	FC_GET_PARAMETERS	(FCIOC | 1)
700Sstevel@tonic-gate #define	FC_RUN_PRIV		(FCIOC | 2)
710Sstevel@tonic-gate #define	FC_VALIDATE		(FCIOC | 3)
720Sstevel@tonic-gate #define	FC_GET_MY_ARGS		(FCIOC | 4)
730Sstevel@tonic-gate #define	FC_GET_FCODE_DATA	(FCIOC | 5)
74*762Sdhain #define	FC_SET_FCODE_ERROR	(FCIOC | 6)
750Sstevel@tonic-gate 
760Sstevel@tonic-gate #define	FC_GET_MY_ARGS_BUFLEN	256	/* Max my-args length */
770Sstevel@tonic-gate 
780Sstevel@tonic-gate /*
790Sstevel@tonic-gate  * FC_GET_PARAMETERS: Expected as the first ioctl after a successful
800Sstevel@tonic-gate  * open and blocking read (the read returns 0 when there's something
810Sstevel@tonic-gate  * to interpret).  The ioctl arg is a pointer to an fc_parameters
820Sstevel@tonic-gate  * data structure which is filled in by the driver with the fcode
830Sstevel@tonic-gate  * len (if any) and unit address of the new device.
840Sstevel@tonic-gate  * Offset 0 .. fcode len may be used as the offset to an mmap call to
850Sstevel@tonic-gate  * provide access to a copy of the device fcode. The unit address is
860Sstevel@tonic-gate  * returned as a NULL terminated string.
870Sstevel@tonic-gate  */
880Sstevel@tonic-gate 
890Sstevel@tonic-gate struct fc_parameters {
900Sstevel@tonic-gate 	int32_t	fcode_size;
910Sstevel@tonic-gate 	char	unit_address[OBP_MAXPATHLEN];
920Sstevel@tonic-gate 	int	config_address;
930Sstevel@tonic-gate };
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 
970Sstevel@tonic-gate /*
980Sstevel@tonic-gate  * FC_RUN_PRIV: The ioctl 'arg' is a pointer to an array of fc_cell_t's
990Sstevel@tonic-gate  * in the following format:
1000Sstevel@tonic-gate  *
1010Sstevel@tonic-gate  * fc_cell_t[0]: Pointer to a NULL terminated string: service name
1020Sstevel@tonic-gate  * fc_cell_t[1]: Number of input arguments (Call this value 'A')
1030Sstevel@tonic-gate  * fc_cell_t[2]: Number of output result cells allocated (Call this val 'R')
1040Sstevel@tonic-gate  * fc_cell_t[3]: Error Cell (See below)
1050Sstevel@tonic-gate  * fc_cell_t[4]: Priv Violation Cell (non-zero if priv. violation)
1060Sstevel@tonic-gate  * fc_cell_t[5]: Argument cell[0] (Possibly none)
1070Sstevel@tonic-gate  * fc_cell_t[5 + 'A']: Result cell[0] (Possibly none)
1080Sstevel@tonic-gate  *
1090Sstevel@tonic-gate  * The array is variable sized, and must contain a minimum of 5 fc_cell_t's.
1100Sstevel@tonic-gate  * The size (in fc_cell_t's) is 5 + 'A' + 'R'.
1110Sstevel@tonic-gate  *
1120Sstevel@tonic-gate  * The argument cells are filled in by the caller.  The result cells
1130Sstevel@tonic-gate  * (if any) and error cell are returned to the caller by the driver.
1140Sstevel@tonic-gate  * The error cell and priv violation cell are filled in and returned
1150Sstevel@tonic-gate  * to the caller by the driver.
1160Sstevel@tonic-gate  *
1170Sstevel@tonic-gate  * Error Cell Values:
1180Sstevel@tonic-gate  *
1190Sstevel@tonic-gate  *	-1:	The call itself failed (the service name was unknown).
1200Sstevel@tonic-gate  *
1210Sstevel@tonic-gate  *	0:	No error (though the result cells may indicate results
1220Sstevel@tonic-gate  *		that signify an error consistent with the service request.)
1230Sstevel@tonic-gate  *
1240Sstevel@tonic-gate  * Priv Violation Cell Values:
1250Sstevel@tonic-gate  *
1260Sstevel@tonic-gate  *	0:	No priv violation
1270Sstevel@tonic-gate  *
1280Sstevel@tonic-gate  *	-1:	Executing the request caused a priv. violation.
1290Sstevel@tonic-gate  *		For example, an rl@ from an address not mapped in
1300Sstevel@tonic-gate  *		by the interpreter.
1310Sstevel@tonic-gate  */
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate #define	FC_ERR_NONE	fc_int2cell(0)
1340Sstevel@tonic-gate #define	FC_ERR_SVC_NAME	fc_int2cell(-1)
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate #define	FC_PRIV_OK	fc_intcell(0)
1370Sstevel@tonic-gate #define	FC_PRIV_ERROR	fc_int2cell(-1)
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate /*
1400Sstevel@tonic-gate  * Client interface template:
1410Sstevel@tonic-gate  * The actual number of arguments is nargs.
1420Sstevel@tonic-gate  * The actual number of results is nresults.
1430Sstevel@tonic-gate  * The variable array 'v' contains 'nargs + nresults' elements
1440Sstevel@tonic-gate  */
1450Sstevel@tonic-gate struct fc_client_interface {
1460Sstevel@tonic-gate 	fc_cell_t	svc_name;
1470Sstevel@tonic-gate 	fc_cell_t	nargs;
1480Sstevel@tonic-gate 	fc_cell_t	nresults;
1490Sstevel@tonic-gate 	fc_cell_t	error;
1500Sstevel@tonic-gate 	fc_cell_t	priv_error;
1510Sstevel@tonic-gate 	fc_cell_t	v[1];	/* variable array of args and results */
1520Sstevel@tonic-gate };
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate typedef	struct fc_client_interface fc_ci_t;
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate #define	fc_arg(cp, i)		(cp->v[(i)])
1570Sstevel@tonic-gate #define	fc_result(cp, i)	(cp->v[fc_cell2int(cp->nargs) + (i)])
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate #define	FCC_FIXED_CELLS			5
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate /*
1620Sstevel@tonic-gate  * FC_GET_FCODE_DATA: This ioctl allows userland portion of the fcode
1630Sstevel@tonic-gate  * interpreter to get the fcode into a local buffer without having
1640Sstevel@tonic-gate  * to use mmap() interface (which calls hat_getkpfnum() routine).
1650Sstevel@tonic-gate  * This allows DR kernel cage memory to be relocated while this
1660Sstevel@tonic-gate  * fcode buffer is allocated.
1670Sstevel@tonic-gate  *
1680Sstevel@tonic-gate  * The ioctl arg is a pointer to an fc_fcode_info structure which
1690Sstevel@tonic-gate  * has the fcode_size field set with the expected fcode length.
1700Sstevel@tonic-gate  * The driver uses this field to validate correct size before using
1710Sstevel@tonic-gate  * copyout() to fill in the fcode_ptr buffer with fcode data.
1720Sstevel@tonic-gate  */
1730Sstevel@tonic-gate typedef struct fc_fcode_info {
1740Sstevel@tonic-gate 	int32_t	fcode_size;
1750Sstevel@tonic-gate 	char	*fcode_ptr;
1760Sstevel@tonic-gate } fc_fcode_info_t;
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate /*
1790Sstevel@tonic-gate  * The service name len (max) is limited by the size of a method name
1800Sstevel@tonic-gate  */
1810Sstevel@tonic-gate #define	FC_SVC_NAME_LEN		OBP_MAXPROPNAME
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate /*
1840Sstevel@tonic-gate  * "Internally" generated service names ...
1850Sstevel@tonic-gate  */
1860Sstevel@tonic-gate #define	FC_SVC_VALIDATE		"sunos,validate"
1870Sstevel@tonic-gate #define	FC_SVC_INVALIDATE	"sunos,invalidate"
1880Sstevel@tonic-gate #define	FC_SVC_EXIT		"sunos,exit"
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate #define	FC_OPEN_METHOD		"open"
1910Sstevel@tonic-gate #define	FC_CLOSE_METHOD		"close"
1920Sstevel@tonic-gate #define	FC_FIND_FCODE		"$find"
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate /*
1950Sstevel@tonic-gate  * Property related group:
1960Sstevel@tonic-gate  *
1970Sstevel@tonic-gate  * sunos,get*proplen ( propname-cstr phandle -- proplen )
1980Sstevel@tonic-gate  * sunos,get*prop ( propname-cstr buf phandle -- proplen )
1990Sstevel@tonic-gate  *
2000Sstevel@tonic-gate  * sunos,property ( propname-cstr buf len phandle -- )
2010Sstevel@tonic-gate  */
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate #define	FC_GET_MY_PROPLEN	"sunos,get-my-proplen"
2040Sstevel@tonic-gate #define	FC_GET_MY_PROP		"sunos,get-my-prop"
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate #define	FC_GET_IN_PROPLEN	"sunos,get-inherited-proplen"
2070Sstevel@tonic-gate #define	FC_GET_IN_PROP		"sunos,get-inherited-prop"
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate #define	FC_GET_PKG_PROPLEN	"sunos,get-package-proplen"
2100Sstevel@tonic-gate #define	FC_GET_PKG_PROP		"sunos,get-package-prop"
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate #define	FC_CREATE_PROPERTY	"sunos,property"
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate /*
2150Sstevel@tonic-gate  * Register access and dma ... same as 1275
2160Sstevel@tonic-gate  *
2170Sstevel@tonic-gate  * dma-map-in maps in a suitable aligned user address.
2180Sstevel@tonic-gate  */
2190Sstevel@tonic-gate #define	FC_RL_FETCH		"rl@"
2200Sstevel@tonic-gate #define	FC_RW_FETCH		"rw@"
2210Sstevel@tonic-gate #define	FC_RB_FETCH		"rb@"
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate #define	FC_RL_STORE		"rl!"
2240Sstevel@tonic-gate #define	FC_RW_STORE		"rw!"
2250Sstevel@tonic-gate #define	FC_RB_STORE		"rb!"
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate #define	FC_MAP_IN		"map-in"
2280Sstevel@tonic-gate #define	FC_MAP_OUT		"map-out"
2290Sstevel@tonic-gate #define	FC_DMA_MAP_IN		"dma-map-in"
2300Sstevel@tonic-gate #define	FC_DMA_MAP_OUT		"dma-map-out"
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate /*
2330Sstevel@tonic-gate  * PCI configuration space access methods ... same as pci binding
2340Sstevel@tonic-gate  */
2350Sstevel@tonic-gate #define	FC_PCI_CFG_L_FETCH	"config-l@"
2360Sstevel@tonic-gate #define	FC_PCI_CFG_W_FETCH	"config-w@"
2370Sstevel@tonic-gate #define	FC_PCI_CFG_B_FETCH	"config-b@"
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate #define	FC_PCI_CFG_L_STORE	"config-l!"
2400Sstevel@tonic-gate #define	FC_PCI_CFG_W_STORE	"config-w!"
2410Sstevel@tonic-gate #define	FC_PCI_CFG_B_STORE	"config-b!"
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate /*
2440Sstevel@tonic-gate  * Device node creation ...
2450Sstevel@tonic-gate  *
2460Sstevel@tonic-gate  * Create a new device with the given name, unit-address, parent.phandle
2470Sstevel@tonic-gate  * with a phandle that must have been previously allocated using
2480Sstevel@tonic-gate  * sunos,alloc-phandle.  finish-device marks the device creation and
2490Sstevel@tonic-gate  * the creation of its properties as complete. (It's a signal to the
2500Sstevel@tonic-gate  * the OS that the node is now reasonably complete.)
2510Sstevel@tonic-gate  *
2520Sstevel@tonic-gate  * sunos,new-device ( name-cstr unit-addr-cstr parent.phandle phandle -- )
2530Sstevel@tonic-gate  * finish-device ( phandle  -- )
2540Sstevel@tonic-gate  */
2550Sstevel@tonic-gate #define	FC_NEW_DEVICE		"sunos,new-device"
2560Sstevel@tonic-gate #define	FC_FINISH_DEVICE	"sunos,finish-device"
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate /*
2590Sstevel@tonic-gate  * Navigation and configuration:
2600Sstevel@tonic-gate  *
2610Sstevel@tonic-gate  * sunos,probe-address ( -- phys.lo ... )
2620Sstevel@tonic-gate  * sunos,probe-space ( -- phys.hi )
2630Sstevel@tonic-gate  *
2640Sstevel@tonic-gate  * sunos,ap-phandle ( -- ap.phandle )
2650Sstevel@tonic-gate  *	Return attachment point phandle
2660Sstevel@tonic-gate  *
2670Sstevel@tonic-gate  * sunos,parent ( child.phandle -- parent.phandle )
2680Sstevel@tonic-gate  *
2690Sstevel@tonic-gate  * child ( parent.phandle -- child.phandle )
2700Sstevel@tonic-gate  * peer ( phandle -- phandle.sibling )
2710Sstevel@tonic-gate  *
2720Sstevel@tonic-gate  * sunos,alloc-phandle ( -- phandle )
2730Sstevel@tonic-gate  * Allocates a unique phandle, not associated with the device tree
2740Sstevel@tonic-gate  *
2750Sstevel@tonic-gate  * sunos,config-child ( -- child.phandle )
2760Sstevel@tonic-gate  * Return the phandle of the child being configured.
2770Sstevel@tonic-gate  */
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate #define	FC_PROBE_ADDRESS	"sunos,probe-address"
2800Sstevel@tonic-gate #define	FC_PROBE_SPACE		"sunos,probe-space"
2810Sstevel@tonic-gate #define	FC_AP_PHANDLE		"sunos,ap-phandle"
2820Sstevel@tonic-gate #define	FC_PARENT		"sunos,parent"
2830Sstevel@tonic-gate #define	FC_CHILD_FCODE		"child"
2840Sstevel@tonic-gate #define	FC_PEER_FCODE		"peer"
2850Sstevel@tonic-gate #define	FC_ALLOC_PHANDLE	"sunos,alloc-phandle"
2860Sstevel@tonic-gate #define	FC_CONFIG_CHILD		"sunos,config-child"
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate /*
2890Sstevel@tonic-gate  * Fcode Drop In Routines:
2900Sstevel@tonic-gate  * sunos,get_fcode_size ( cstr -- len )
2910Sstevel@tonic-gate  * Returns the size in bytes of the Fcode for a given drop in.
2920Sstevel@tonic-gate  * sunos,get_fcode (cstr buf len -- status? )
2930Sstevel@tonic-gate  * Returns the Fcode image for a given drop in.
2940Sstevel@tonic-gate  */
2950Sstevel@tonic-gate #define	FC_GET_FCODE_SIZE	"sunos,get-fcode-size"
2960Sstevel@tonic-gate #define	FC_GET_FCODE		"sunos,get-fcode"
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate /*
299*762Sdhain  * Values for fc_request 'error'. This has been moved from the _KERNEL
300*762Sdhain  * area to allow the FC_SET_FCODE_ERROR ioctl to use these values to
301*762Sdhain  * signal the kernel as to the disposition of the userland interpreter.
302*762Sdhain  * NOTE: Positive values are used to indicate a kernel error,
303*762Sdhain  * negative values are used to identify userland interpreter errors.
304*762Sdhain  */
305*762Sdhain #define	FC_SUCCESS	0		/* FCode interpreted successfully */
306*762Sdhain #define	FC_TIMEOUT	1		/* Timer expired */
307*762Sdhain #define	FC_ERROR	-1		/* Interpreter error */
308*762Sdhain #define	FC_EXEC_FAILED	-2		/* Interpreter failed to exec */
309*762Sdhain #define	FC_NO_FCODE	-3		/* Interpreter couldn't find fcode */
310*762Sdhain #define	FC_FCODE_ABORT	-4		/* Interpreter called exit(1) */
311*762Sdhain #define	FC_ERROR_VALID(s) ((s) >= FC_FCODE_ABORT) && ((s) <= FC_TIMEOUT)
312*762Sdhain 
313*762Sdhain /*
3140Sstevel@tonic-gate  * kernel internal data structures and interfaces
3150Sstevel@tonic-gate  * for the fcode interpreter.
3160Sstevel@tonic-gate  */
3170Sstevel@tonic-gate #if defined(_KERNEL)
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate /*
3200Sstevel@tonic-gate  * PCI bus-specific arguments.
3210Sstevel@tonic-gate  *
3220Sstevel@tonic-gate  * We can't get the physical config address of the child from the
3230Sstevel@tonic-gate  * unit address, so we supply it here, along with the child's dip
3240Sstevel@tonic-gate  * as the bus specific argument to pci_ops_alloc_handle.
3250Sstevel@tonic-gate  */
3260Sstevel@tonic-gate 
3270Sstevel@tonic-gate struct pci_ops_bus_args {
3280Sstevel@tonic-gate 	int32_t config_address;		/* phys.hi config addr component */
3290Sstevel@tonic-gate };
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate /*
3320Sstevel@tonic-gate  * Define data structures for resource lists and handle management
3330Sstevel@tonic-gate  *
3340Sstevel@tonic-gate  * 'untyped' resources are managed by the provider.
3350Sstevel@tonic-gate  */
3360Sstevel@tonic-gate struct fc_dma_resource {
3370Sstevel@tonic-gate 	void *virt;
3380Sstevel@tonic-gate 	size_t len;
3390Sstevel@tonic-gate 	ddi_dma_handle_t h;
3400Sstevel@tonic-gate 	uint32_t devaddr;
3410Sstevel@tonic-gate 	struct buf *bp;
3420Sstevel@tonic-gate };
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate struct fc_map_resource {
3450Sstevel@tonic-gate 	void *virt;
3460Sstevel@tonic-gate 	size_t len;
3470Sstevel@tonic-gate 	ddi_acc_handle_t h;
3480Sstevel@tonic-gate 	void *regspec;
3490Sstevel@tonic-gate };
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate struct fc_nodeid_resource {
3520Sstevel@tonic-gate 	int nodeid;		/* An allocated nodeid */
3530Sstevel@tonic-gate };
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate struct fc_contigious_resource {
3560Sstevel@tonic-gate 	void *virt;
3570Sstevel@tonic-gate 	size_t len;
3580Sstevel@tonic-gate };
3590Sstevel@tonic-gate struct fc_untyped_resource {
3600Sstevel@tonic-gate 	int utype;		/* providers private type field */
3610Sstevel@tonic-gate 	void (*free)(void *);	/* function to free the resource */
3620Sstevel@tonic-gate 	void *resource;		/* Pointer to the resource */
3630Sstevel@tonic-gate };
3640Sstevel@tonic-gate 
3650Sstevel@tonic-gate typedef enum {
3660Sstevel@tonic-gate 	RT_DMA = 0,
3670Sstevel@tonic-gate 	RT_MAP,
3680Sstevel@tonic-gate 	RT_NODEID,
3690Sstevel@tonic-gate 	RT_CONTIGIOUS,
3700Sstevel@tonic-gate 	RT_UNTYPED
3710Sstevel@tonic-gate } fc_resource_type_t;
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate struct fc_resource {
3740Sstevel@tonic-gate 	struct fc_resource *next;
3750Sstevel@tonic-gate 	fc_resource_type_t type;
3760Sstevel@tonic-gate 	union {
3770Sstevel@tonic-gate 		struct fc_dma_resource d;
3780Sstevel@tonic-gate 		struct fc_map_resource m;
3790Sstevel@tonic-gate 		struct fc_nodeid_resource n;
3800Sstevel@tonic-gate 		struct fc_contigious_resource c;
3810Sstevel@tonic-gate 		struct fc_untyped_resource r;
3820Sstevel@tonic-gate 	} un;
3830Sstevel@tonic-gate };
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate #define	fc_dma_virt	un.d.virt
3860Sstevel@tonic-gate #define	fc_dma_len	un.d.len
3870Sstevel@tonic-gate #define	fc_dma_handle	un.d.h
3880Sstevel@tonic-gate #define	fc_dma_devaddr	un.d.devaddr
3890Sstevel@tonic-gate #define	fc_dma_bp	un.d.bp
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate #define	fc_map_virt	un.m.virt
3920Sstevel@tonic-gate #define	fc_map_len	un.m.len
3930Sstevel@tonic-gate #define	fc_map_handle	un.m.h
3940Sstevel@tonic-gate #define	fc_regspec	un.m.regspec
3950Sstevel@tonic-gate 
3960Sstevel@tonic-gate #define	fc_nodeid_r	un.n.nodeid
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate #define	fc_contig_virt	un.c.virt
3990Sstevel@tonic-gate #define	fc_contig_len	un.c.len
4000Sstevel@tonic-gate 
4010Sstevel@tonic-gate #define	fc_untyped_type	un.r.utype
4020Sstevel@tonic-gate #define	fc_untyped_free	un.r.free
4030Sstevel@tonic-gate #define	fc_untyped_r	un.r.resource
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate struct fc_phandle_entry {
4060Sstevel@tonic-gate 	struct fc_phandle_entry *next;
4070Sstevel@tonic-gate 	dev_info_t	*dip;
4080Sstevel@tonic-gate 	fc_phandle_t	h;
4090Sstevel@tonic-gate };
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate extern void fc_phandle_table_alloc(struct fc_phandle_entry **);
4120Sstevel@tonic-gate extern void fc_phandle_table_free(struct fc_phandle_entry **);
4130Sstevel@tonic-gate extern dev_info_t *fc_phandle_to_dip(struct fc_phandle_entry **, fc_phandle_t);
4140Sstevel@tonic-gate extern fc_phandle_t fc_dip_to_phandle(struct fc_phandle_entry **, dev_info_t *);
4150Sstevel@tonic-gate extern void fc_add_dip_to_phandle(struct fc_phandle_entry **, dev_info_t *,
4160Sstevel@tonic-gate     fc_phandle_t);
4170Sstevel@tonic-gate 
4180Sstevel@tonic-gate /*
4190Sstevel@tonic-gate  * Structures and functions for managing our own subtree rooted
4200Sstevel@tonic-gate  * at the attachment point. The parent linkage is established
4210Sstevel@tonic-gate  * at node creation time.  The 'downwards' linkage isn't established
4220Sstevel@tonic-gate  * until the node is bound.
4230Sstevel@tonic-gate  */
4240Sstevel@tonic-gate struct fc_device_tree {
4250Sstevel@tonic-gate 	dev_info_t *dip;
4260Sstevel@tonic-gate 	struct fc_device_tree *child;
4270Sstevel@tonic-gate 	struct fc_device_tree *peer;
4280Sstevel@tonic-gate };
4290Sstevel@tonic-gate 
4300Sstevel@tonic-gate void fc_add_child(dev_info_t *child, dev_info_t *parent,
4310Sstevel@tonic-gate     struct fc_device_tree *head);
4320Sstevel@tonic-gate 
4330Sstevel@tonic-gate void fc_remove_child(dev_info_t *child, struct fc_device_tree *head);
4340Sstevel@tonic-gate 
4350Sstevel@tonic-gate dev_info_t *fc_child_node(dev_info_t *parent, struct fc_device_tree *head);
4360Sstevel@tonic-gate dev_info_t *fc_peer_node(dev_info_t *devi, struct fc_device_tree *head);
4370Sstevel@tonic-gate struct fc_device_tree *fc_find_node(dev_info_t *, struct fc_device_tree *);
4380Sstevel@tonic-gate 
4390Sstevel@tonic-gate void fc_create_device_tree(dev_info_t *ap, struct fc_device_tree **head);
4400Sstevel@tonic-gate void fc_remove_device_tree(struct fc_device_tree **head);
4410Sstevel@tonic-gate 
4420Sstevel@tonic-gate /*
4430Sstevel@tonic-gate  * Our handles represent a list of resources associated with an
4440Sstevel@tonic-gate  * attachment point.  The handles chain, just as the ops functions
4450Sstevel@tonic-gate  * do, with the ops caller responsible for remembering the handle
4460Sstevel@tonic-gate  * of the ops function below it. NB: Externally, this data structure
4470Sstevel@tonic-gate  * is opaque. (Not all members may be present in each chained cookie.)
4480Sstevel@tonic-gate  * For example, the dtree head is valid in only a single instance
4490Sstevel@tonic-gate  * of a set of chained cookies, so use the access function to find it.)
4500Sstevel@tonic-gate  */
4510Sstevel@tonic-gate struct fc_resource_list {
4520Sstevel@tonic-gate 	struct fc_resource *head;
4530Sstevel@tonic-gate 	void *next_handle;		/* next handle in chain */
4540Sstevel@tonic-gate 	dev_info_t *ap;			/* Attachment point dip */
4550Sstevel@tonic-gate 	dev_info_t *child;		/* Child being configured, if any */
4560Sstevel@tonic-gate 	dev_info_t *cdip;		/* Current node, if any */
4570Sstevel@tonic-gate 	int cdip_state;			/* node creation state - see below */
4580Sstevel@tonic-gate 	void *fcode;			/* fcode kernel address */
4590Sstevel@tonic-gate 	size_t fcode_size;		/* fcode size or zero */
4600Sstevel@tonic-gate 	char *unit_address;		/* childs unit address */
4610Sstevel@tonic-gate 	char *my_args;			/* initial setting for my-args */
4620Sstevel@tonic-gate 	void *bus_args;			/* bus dependent arguments */
4630Sstevel@tonic-gate 	struct fc_phandle_entry *ptable; /* devinfo/phandle table */
4640Sstevel@tonic-gate 	struct fc_device_tree *dtree;	/* Our subtree (leaf cookie only) */
4650Sstevel@tonic-gate };
4660Sstevel@tonic-gate 
4670Sstevel@tonic-gate typedef struct fc_resource_list *fco_handle_t;
4680Sstevel@tonic-gate 
4690Sstevel@tonic-gate /*
4700Sstevel@tonic-gate  * Values for cdip_state:
4710Sstevel@tonic-gate  */
4720Sstevel@tonic-gate #define	FC_CDIP_NOSTATE		0x00	/* No state - no nodes created */
4730Sstevel@tonic-gate #define	FC_CDIP_STARTED		0x01	/* Node started - dip in cdip */
4740Sstevel@tonic-gate #define	FC_CDIP_DONE		0x02	/* Node finished - last dip in cdip */
4750Sstevel@tonic-gate #define	FC_CDIP_CONFIG		0x10	/* subtree configured */
4760Sstevel@tonic-gate 
4770Sstevel@tonic-gate /*
4780Sstevel@tonic-gate  * Functions to allocate handles for the fcode_interpreter.
4790Sstevel@tonic-gate  *
4800Sstevel@tonic-gate  * This function allocates a handle, used to store resources
4810Sstevel@tonic-gate  * associated with this fcode request including the address of
4820Sstevel@tonic-gate  * the mapped in and copied in fcode and it's size or NULL, 0
4830Sstevel@tonic-gate  * if there is no fcode (the interpreter may look for a drop-in
4840Sstevel@tonic-gate  * driver if there is no fcode), the unit address of child and
4850Sstevel@tonic-gate  * bus specific arguments.  For PCI, the bus specific arguments
4860Sstevel@tonic-gate  * include the child's prototype dip and the config address of
4870Sstevel@tonic-gate  * the child, which can't be derived from the unit address.
4880Sstevel@tonic-gate  *
4890Sstevel@tonic-gate  * The 'handle' returned also contains resource information
4900Sstevel@tonic-gate  * about any allocations of kernel resources that the fcode
4910Sstevel@tonic-gate  * may have created.  Thus, the handle's life is the life
4920Sstevel@tonic-gate  * of the plug-in card and can't be released until the card
4930Sstevel@tonic-gate  * is removed.  Upon release, the resources are released.
4940Sstevel@tonic-gate  */
4950Sstevel@tonic-gate extern fco_handle_t
4960Sstevel@tonic-gate fc_ops_alloc_handle(dev_info_t *ap, dev_info_t *config_child,
4970Sstevel@tonic-gate     void *fcode, size_t fcode_size, char *unit_address, void *bus_args);
4980Sstevel@tonic-gate 
4990Sstevel@tonic-gate extern fco_handle_t
5000Sstevel@tonic-gate pci_fc_ops_alloc_handle(dev_info_t *ap, dev_info_t *config_child,
5010Sstevel@tonic-gate     void *fcode, size_t fcode_size, char *unit_address,
5020Sstevel@tonic-gate     struct pci_ops_bus_args *bus_args);
5030Sstevel@tonic-gate 
5040Sstevel@tonic-gate extern fco_handle_t
5050Sstevel@tonic-gate gp2_fc_ops_alloc_handle(dev_info_t *ap, dev_info_t *config_child,
5060Sstevel@tonic-gate     void *fcode, size_t fcode_size, char *unit_address,
5070Sstevel@tonic-gate     char *my_args);
5080Sstevel@tonic-gate 
5090Sstevel@tonic-gate extern void pci_fc_ops_free_handle(fco_handle_t handle);
5100Sstevel@tonic-gate extern void gp2_fc_ops_free_handle(fco_handle_t handle);
5110Sstevel@tonic-gate extern void fc_ops_free_handle(fco_handle_t handle);
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate extern struct fc_phandle_entry **fc_handle_to_phandle_head(fco_handle_t rp);
5140Sstevel@tonic-gate 
5150Sstevel@tonic-gate struct fc_device_tree **fc_handle_to_dtree_head(fco_handle_t);
5160Sstevel@tonic-gate struct fc_device_tree *fc_handle_to_dtree(fco_handle_t);
5170Sstevel@tonic-gate 
5180Sstevel@tonic-gate /*
5190Sstevel@tonic-gate  * fc_ops_t is the main glue back to the framework and attachment point driver
5200Sstevel@tonic-gate  * for privileged driver operations.  The framework/driver provides a pointer
5210Sstevel@tonic-gate  * to the fc_ops function to handle the request given in the args.  The dip
5220Sstevel@tonic-gate  * and handle are passed back to the framework/driver to distinguish
5230Sstevel@tonic-gate  * requests, if necessary.  The argument array is an array of fc_cell_t's
5240Sstevel@tonic-gate  * and is defined in fcode.h
5250Sstevel@tonic-gate  *
5260Sstevel@tonic-gate  * The ops function should return -1 to indicate that the service name is
5270Sstevel@tonic-gate  * unknown and return the value 0 to indicate that the service name was known
5280Sstevel@tonic-gate  * and processed (even if it failed).  ops functions may chain, using the
5290Sstevel@tonic-gate  * return code to communicate if the current function handled the service
5300Sstevel@tonic-gate  * request. Using this technique, the driver can provide certain ops functions
5310Sstevel@tonic-gate  * and allow a framework ops function to handle standardized ops functions,
5320Sstevel@tonic-gate  * or work hand in hand with a framework function so both can handle an op.
5330Sstevel@tonic-gate  * If an ops function is not handled, thus returning -1 to the driver, the
5340Sstevel@tonic-gate  * driver will log an error noting the name of the service and return the
5350Sstevel@tonic-gate  * error to the caller.
5360Sstevel@tonic-gate  */
5370Sstevel@tonic-gate typedef int (fc_ops_t)(dev_info_t *, fco_handle_t, fc_ci_t *);
5380Sstevel@tonic-gate 
5390Sstevel@tonic-gate extern fc_ops_t fc_ops;
5400Sstevel@tonic-gate extern fc_ops_t pci_fc_ops;
5410Sstevel@tonic-gate extern fc_ops_t gp2_fc_ops;
5420Sstevel@tonic-gate 
5430Sstevel@tonic-gate /*
5440Sstevel@tonic-gate  * Internal structure used to enque an fcode request
5450Sstevel@tonic-gate  * The 'next' and 'busy' fields are protected by a mutex.
5460Sstevel@tonic-gate  * Thread synchronization is accomplished via use of the 'busy' field.
5470Sstevel@tonic-gate  */
5480Sstevel@tonic-gate struct fc_request {
5490Sstevel@tonic-gate 	struct fc_request *next;	/* Next in chain (private) */
5500Sstevel@tonic-gate 	int		busy;		/* Waiters flag (private; see below) */
5510Sstevel@tonic-gate 	int		error;		/* Interpreter return code (private) */
5520Sstevel@tonic-gate 	dev_info_t	*ap_dip;	/* Attachment point. ie: pci nexus */
5530Sstevel@tonic-gate 	fc_ops_t	*ap_ops;	/* driver's fcode ops function */
5540Sstevel@tonic-gate 	fco_handle_t	handle;		/* Caller's private identifier */
5550Sstevel@tonic-gate 	timeout_id_t	timeout;	/* Timeout identifier */
5560Sstevel@tonic-gate };
5570Sstevel@tonic-gate 
5580Sstevel@tonic-gate /*
5590Sstevel@tonic-gate  * Values for 'busy'.  The requester initializes the field to FC_R_INIT (0),
5600Sstevel@tonic-gate  * then waits for it be set to FC_R_DONE.  The framework sets it to
5610Sstevel@tonic-gate  * FC_R_BUSY while working on the request so it can distinguish between
5620Sstevel@tonic-gate  * an inactive and an active request.
5630Sstevel@tonic-gate  */
5640Sstevel@tonic-gate #define	FC_R_INIT	0		/* initialized, on queue */
5650Sstevel@tonic-gate #define	FC_R_BUSY	1		/* request is active, busy */
5660Sstevel@tonic-gate #define	FC_R_DONE	2		/* request is done and may be deq'd */
5670Sstevel@tonic-gate 
5680Sstevel@tonic-gate /*
5690Sstevel@tonic-gate  * Function to call to invoke the fcode interpreter.
5700Sstevel@tonic-gate  *
5710Sstevel@tonic-gate  * This function will wait and return when the interpreter either
5720Sstevel@tonic-gate  * completes successfully or fails, returning pass/fail status as
5730Sstevel@tonic-gate  * the return code.  Interim calls to the driver's ops function will
5740Sstevel@tonic-gate  * be made for both priv. ops and to create device nodes and properties.
5750Sstevel@tonic-gate  *
5760Sstevel@tonic-gate  * Calling this function will log a message to userland to request the
5770Sstevel@tonic-gate  * eventd to start the userland fcode interpreter process. The interpreter
5780Sstevel@tonic-gate  * opens /dev/fcode, which clones an instance of the driver, and then
5790Sstevel@tonic-gate  * waits in a 'read' until there's an active request.
5800Sstevel@tonic-gate  * XXX: For the prototype, we can start it manually or use an init.d script.
5810Sstevel@tonic-gate  *
5820Sstevel@tonic-gate  * 'ap' is the attachment point dip: that is, the driving parent's dev_info_t
5830Sstevel@tonic-gate  * ie: for pci devices, this will be the dip of the pci nexus.
5840Sstevel@tonic-gate  *
5850Sstevel@tonic-gate  * The 'handle' is provided for the caller, and can be used to
5860Sstevel@tonic-gate  * identify the request along with the attachment point dip, both
5870Sstevel@tonic-gate  * of which will be passed back to the driver's ops function.
5880Sstevel@tonic-gate  * The handle is allocated first by calling a bus-specific
5890Sstevel@tonic-gate  * <bus>_ops_handle_alloc function.
5900Sstevel@tonic-gate  *
5910Sstevel@tonic-gate  * ops functions may chain; an ops function should return -1 if
5920Sstevel@tonic-gate  * the call was not recognized, or 0 if the call was recognized.
5930Sstevel@tonic-gate  */
5940Sstevel@tonic-gate extern int fcode_interpreter(dev_info_t *, fc_ops_t *, fco_handle_t);
5950Sstevel@tonic-gate 
5960Sstevel@tonic-gate /*
5970Sstevel@tonic-gate  * The fcode implementation uses this function to wait for and 'de-queue'
5980Sstevel@tonic-gate  * an fcode request.  It's triggered by a 'read' request from the
5990Sstevel@tonic-gate  * userland interpreter. It uses a 'sig' form of waiting (cv_wait_sig),
6000Sstevel@tonic-gate  * so the interpreter can interrupt the read.
6010Sstevel@tonic-gate  */
6020Sstevel@tonic-gate extern struct fc_request *fc_get_request(void);
6030Sstevel@tonic-gate 
6040Sstevel@tonic-gate /*
6050Sstevel@tonic-gate  * When the fcode implementation is finished servicing a request, it calls this
6060Sstevel@tonic-gate  * function to mark the request as done and to signal the originating thread
6070Sstevel@tonic-gate  * (now waiting in fcode_interpreter) that the request is done.
6080Sstevel@tonic-gate  */
6090Sstevel@tonic-gate extern void fc_finish_request(struct fc_request *);
6100Sstevel@tonic-gate 
6110Sstevel@tonic-gate /*
6120Sstevel@tonic-gate  * The fcode implementation uses these functions to manage
6130Sstevel@tonic-gate  * resource items and resource lists ...
6140Sstevel@tonic-gate  */
6150Sstevel@tonic-gate extern void fc_add_resource(fco_handle_t, struct fc_resource *);
6160Sstevel@tonic-gate extern void fc_rem_resource(fco_handle_t, struct fc_resource *);
6170Sstevel@tonic-gate extern void fc_lock_resource_list(fco_handle_t);
6180Sstevel@tonic-gate extern void fc_unlock_resource_list(fco_handle_t);
6190Sstevel@tonic-gate 
6200Sstevel@tonic-gate /*
6210Sstevel@tonic-gate  * ops common and helper functions
6220Sstevel@tonic-gate  */
6230Sstevel@tonic-gate extern int fc_fail_op(dev_info_t *, fco_handle_t, fc_ci_t *);
6240Sstevel@tonic-gate extern int fc_success_op(dev_info_t *, fco_handle_t, fc_ci_t *);
6250Sstevel@tonic-gate 
6260Sstevel@tonic-gate extern int fc_syntax_error(fc_ci_t *, char *);
6270Sstevel@tonic-gate extern int fc_priv_error(fc_ci_t *, char *);
6280Sstevel@tonic-gate 
6290Sstevel@tonic-gate /*
6300Sstevel@tonic-gate  * Recharacterized ddi functions we need to define ...
6310Sstevel@tonic-gate  *
6320Sstevel@tonic-gate  * The only difference is we call through the attachment point driver,
6330Sstevel@tonic-gate  * as a proxy for the child that isn't yet attached. The ddi functions
6340Sstevel@tonic-gate  * optimize these functions by not necessarily calling through the
6350Sstevel@tonic-gate  * attachment point driver.
6360Sstevel@tonic-gate  */
6370Sstevel@tonic-gate int fc_ddi_dma_htoc(dev_info_t *, ddi_dma_handle_t, off_t, ddi_dma_cookie_t *);
6380Sstevel@tonic-gate int fc_ddi_dma_free(dev_info_t *ap, ddi_dma_handle_t h);
6390Sstevel@tonic-gate int fc_ddi_dma_sync(ddi_dma_handle_t h, off_t o, size_t l, uint_t whom);
6400Sstevel@tonic-gate 
6410Sstevel@tonic-gate /*
6420Sstevel@tonic-gate  * The ndi prop functions aren't appropriate for the interpreter.
6430Sstevel@tonic-gate  * We create byte-array, untyped properties.
6440Sstevel@tonic-gate  */
6450Sstevel@tonic-gate 
6460Sstevel@tonic-gate int fc_ndi_prop_update(dev_t, dev_info_t *, char *, uchar_t *, uint_t);
6470Sstevel@tonic-gate 
6480Sstevel@tonic-gate /*
6490Sstevel@tonic-gate  * The setup and teardown parts of physio()
6500Sstevel@tonic-gate  */
6510Sstevel@tonic-gate int fc_physio_setup(struct buf **bpp, void *io_base, size_t io_len);
6520Sstevel@tonic-gate void fc_physio_free(struct buf **bpp, void *io_base, size_t io_len);
6530Sstevel@tonic-gate 
6540Sstevel@tonic-gate /*
6550Sstevel@tonic-gate  * debugging macros
6560Sstevel@tonic-gate  */
6570Sstevel@tonic-gate extern int fcode_debug;
6580Sstevel@tonic-gate #define	dcmn_err(level, args) if (fcode_debug >= level) cmn_err args
6590Sstevel@tonic-gate 
6600Sstevel@tonic-gate #ifdef DEBUG
6610Sstevel@tonic-gate 
6620Sstevel@tonic-gate void fc_debug(char *, uintptr_t, uintptr_t,
6630Sstevel@tonic-gate     uintptr_t, uintptr_t, uintptr_t);
6640Sstevel@tonic-gate 
6650Sstevel@tonic-gate #define	FC_DEBUG0(level, flag, s) if (fcode_debug >= level) \
6660Sstevel@tonic-gate     fc_debug(s, 0, 0, 0, 0, 0)
6670Sstevel@tonic-gate #define	FC_DEBUG1(level, flag, fmt, a1) if (fcode_debug >= level) \
6680Sstevel@tonic-gate     fc_debug(fmt, (uintptr_t)(a1), 0, 0, 0, 0);
6690Sstevel@tonic-gate #define	FC_DEBUG2(level, flag, fmt, a1, a2) if (fcode_debug >= level) \
6700Sstevel@tonic-gate     fc_debug(fmt, (uintptr_t)(a1), (uintptr_t)(a2), 0, 0, 0);
6710Sstevel@tonic-gate #define	FC_DEBUG3(level, flag, fmt, a1, a2, a3) \
6720Sstevel@tonic-gate     if (fcode_debug >= level) \
6730Sstevel@tonic-gate     fc_debug(fmt, (uintptr_t)(a1), (uintptr_t)(a2), (uintptr_t)(a3), 0, 0);
6740Sstevel@tonic-gate #else
6750Sstevel@tonic-gate #define	FC_DEBUG0(level, flag, s)
6760Sstevel@tonic-gate #define	FC_DEBUG1(level, flag, fmt, a1)
6770Sstevel@tonic-gate #define	FC_DEBUG2(level, flag, fmt, a1, a2)
6780Sstevel@tonic-gate #define	FC_DEBUG3(level, flag, fmt, a1, a2, a3)
6790Sstevel@tonic-gate #endif
6800Sstevel@tonic-gate 
6810Sstevel@tonic-gate 
6820Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
6830Sstevel@tonic-gate 
6840Sstevel@tonic-gate #ifdef	__cplusplus
6850Sstevel@tonic-gate }
6860Sstevel@tonic-gate #endif
6870Sstevel@tonic-gate 
6880Sstevel@tonic-gate #endif	/* _SYS_FCODE_H */
689