xref: /titanic_41/usr/src/uts/sun4/sys/fcode.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
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 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_FCODE_H
28 #define	_SYS_FCODE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/sysmacros.h>
33 #include <sys/ddi.h>
34 #include <sys/sunddi.h>
35 #include <sys/fc_plat.h>
36 #include <sys/pci.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * The FCode driver presents a private interface to the fcode
44  * user level interpreter.  This interface is subject to change
45  * at any time and is only provided for use by the fcode interpreter.
46  *
47  * The user program opens the device, causing a new instance of
48  * the driver to be cloned.  This instance is specific to a specific
49  * instance of a new device managed by the kernel and driver framework.
50  *
51  * The interpreter does an FC_GET_PARAMETERS ioctl to get the fcode
52  * length, which can be mmap-ed (at offset 0) to provide access to a copy
53  * of the device's fcode.
54  *
55  * The interpreter uses the FC_RUN_PRIV ioctl to request privileged
56  * operations to be run by the driver.
57  *
58  * The interpreter sends an FC_VALIDATE ioctl to notify the
59  * driver that it's done interpreting FCode to signify a normal
60  * ending sequence when the interpreter later closes the device.
61  * This way the driver can easily distinguish between the user
62  * level interpreter failing and finishing normally, thus validating
63  * the interpreters actions and the state it downloads to the driver.
64  * The 'arg' value in the FC_VALIDATE ioctl is ignored, there
65  * are no arguments to this ioctl.
66  */
67 
68 #define	FCIOC			(0xfc<<8)
69 #define	FC_GET_PARAMETERS	(FCIOC | 1)
70 #define	FC_RUN_PRIV		(FCIOC | 2)
71 #define	FC_VALIDATE		(FCIOC | 3)
72 #define	FC_GET_MY_ARGS		(FCIOC | 4)
73 #define	FC_GET_FCODE_DATA	(FCIOC | 5)
74 
75 #define	FC_GET_MY_ARGS_BUFLEN	256	/* Max my-args length */
76 
77 /*
78  * FC_GET_PARAMETERS: Expected as the first ioctl after a successful
79  * open and blocking read (the read returns 0 when there's something
80  * to interpret).  The ioctl arg is a pointer to an fc_parameters
81  * data structure which is filled in by the driver with the fcode
82  * len (if any) and unit address of the new device.
83  * Offset 0 .. fcode len may be used as the offset to an mmap call to
84  * provide access to a copy of the device fcode. The unit address is
85  * returned as a NULL terminated string.
86  */
87 
88 struct fc_parameters {
89 	int32_t	fcode_size;
90 	char	unit_address[OBP_MAXPATHLEN];
91 	int	config_address;
92 };
93 
94 
95 
96 /*
97  * FC_RUN_PRIV: The ioctl 'arg' is a pointer to an array of fc_cell_t's
98  * in the following format:
99  *
100  * fc_cell_t[0]: Pointer to a NULL terminated string: service name
101  * fc_cell_t[1]: Number of input arguments (Call this value 'A')
102  * fc_cell_t[2]: Number of output result cells allocated (Call this val 'R')
103  * fc_cell_t[3]: Error Cell (See below)
104  * fc_cell_t[4]: Priv Violation Cell (non-zero if priv. violation)
105  * fc_cell_t[5]: Argument cell[0] (Possibly none)
106  * fc_cell_t[5 + 'A']: Result cell[0] (Possibly none)
107  *
108  * The array is variable sized, and must contain a minimum of 5 fc_cell_t's.
109  * The size (in fc_cell_t's) is 5 + 'A' + 'R'.
110  *
111  * The argument cells are filled in by the caller.  The result cells
112  * (if any) and error cell are returned to the caller by the driver.
113  * The error cell and priv violation cell are filled in and returned
114  * to the caller by the driver.
115  *
116  * Error Cell Values:
117  *
118  *	-1:	The call itself failed (the service name was unknown).
119  *
120  *	0:	No error (though the result cells may indicate results
121  *		that signify an error consistent with the service request.)
122  *
123  * Priv Violation Cell Values:
124  *
125  *	0:	No priv violation
126  *
127  *	-1:	Executing the request caused a priv. violation.
128  *		For example, an rl@ from an address not mapped in
129  *		by the interpreter.
130  */
131 
132 #define	FC_ERR_NONE	fc_int2cell(0)
133 #define	FC_ERR_SVC_NAME	fc_int2cell(-1)
134 
135 #define	FC_PRIV_OK	fc_intcell(0)
136 #define	FC_PRIV_ERROR	fc_int2cell(-1)
137 
138 /*
139  * Client interface template:
140  * The actual number of arguments is nargs.
141  * The actual number of results is nresults.
142  * The variable array 'v' contains 'nargs + nresults' elements
143  */
144 struct fc_client_interface {
145 	fc_cell_t	svc_name;
146 	fc_cell_t	nargs;
147 	fc_cell_t	nresults;
148 	fc_cell_t	error;
149 	fc_cell_t	priv_error;
150 	fc_cell_t	v[1];	/* variable array of args and results */
151 };
152 
153 typedef	struct fc_client_interface fc_ci_t;
154 
155 #define	fc_arg(cp, i)		(cp->v[(i)])
156 #define	fc_result(cp, i)	(cp->v[fc_cell2int(cp->nargs) + (i)])
157 
158 #define	FCC_FIXED_CELLS			5
159 
160 /*
161  * FC_GET_FCODE_DATA: This ioctl allows userland portion of the fcode
162  * interpreter to get the fcode into a local buffer without having
163  * to use mmap() interface (which calls hat_getkpfnum() routine).
164  * This allows DR kernel cage memory to be relocated while this
165  * fcode buffer is allocated.
166  *
167  * The ioctl arg is a pointer to an fc_fcode_info structure which
168  * has the fcode_size field set with the expected fcode length.
169  * The driver uses this field to validate correct size before using
170  * copyout() to fill in the fcode_ptr buffer with fcode data.
171  */
172 typedef struct fc_fcode_info {
173 	int32_t	fcode_size;
174 	char	*fcode_ptr;
175 } fc_fcode_info_t;
176 
177 /*
178  * The service name len (max) is limited by the size of a method name
179  */
180 #define	FC_SVC_NAME_LEN		OBP_MAXPROPNAME
181 
182 /*
183  * "Internally" generated service names ...
184  */
185 #define	FC_SVC_VALIDATE		"sunos,validate"
186 #define	FC_SVC_INVALIDATE	"sunos,invalidate"
187 #define	FC_SVC_EXIT		"sunos,exit"
188 
189 #define	FC_OPEN_METHOD		"open"
190 #define	FC_CLOSE_METHOD		"close"
191 #define	FC_FIND_FCODE		"$find"
192 
193 /*
194  * Property related group:
195  *
196  * sunos,get*proplen ( propname-cstr phandle -- proplen )
197  * sunos,get*prop ( propname-cstr buf phandle -- proplen )
198  *
199  * sunos,property ( propname-cstr buf len phandle -- )
200  */
201 
202 #define	FC_GET_MY_PROPLEN	"sunos,get-my-proplen"
203 #define	FC_GET_MY_PROP		"sunos,get-my-prop"
204 
205 #define	FC_GET_IN_PROPLEN	"sunos,get-inherited-proplen"
206 #define	FC_GET_IN_PROP		"sunos,get-inherited-prop"
207 
208 #define	FC_GET_PKG_PROPLEN	"sunos,get-package-proplen"
209 #define	FC_GET_PKG_PROP		"sunos,get-package-prop"
210 
211 #define	FC_CREATE_PROPERTY	"sunos,property"
212 
213 /*
214  * Register access and dma ... same as 1275
215  *
216  * dma-map-in maps in a suitable aligned user address.
217  */
218 #define	FC_RL_FETCH		"rl@"
219 #define	FC_RW_FETCH		"rw@"
220 #define	FC_RB_FETCH		"rb@"
221 
222 #define	FC_RL_STORE		"rl!"
223 #define	FC_RW_STORE		"rw!"
224 #define	FC_RB_STORE		"rb!"
225 
226 #define	FC_MAP_IN		"map-in"
227 #define	FC_MAP_OUT		"map-out"
228 #define	FC_DMA_MAP_IN		"dma-map-in"
229 #define	FC_DMA_MAP_OUT		"dma-map-out"
230 
231 /*
232  * PCI configuration space access methods ... same as pci binding
233  */
234 #define	FC_PCI_CFG_L_FETCH	"config-l@"
235 #define	FC_PCI_CFG_W_FETCH	"config-w@"
236 #define	FC_PCI_CFG_B_FETCH	"config-b@"
237 
238 #define	FC_PCI_CFG_L_STORE	"config-l!"
239 #define	FC_PCI_CFG_W_STORE	"config-w!"
240 #define	FC_PCI_CFG_B_STORE	"config-b!"
241 
242 /*
243  * Device node creation ...
244  *
245  * Create a new device with the given name, unit-address, parent.phandle
246  * with a phandle that must have been previously allocated using
247  * sunos,alloc-phandle.  finish-device marks the device creation and
248  * the creation of its properties as complete. (It's a signal to the
249  * the OS that the node is now reasonably complete.)
250  *
251  * sunos,new-device ( name-cstr unit-addr-cstr parent.phandle phandle -- )
252  * finish-device ( phandle  -- )
253  */
254 #define	FC_NEW_DEVICE		"sunos,new-device"
255 #define	FC_FINISH_DEVICE	"sunos,finish-device"
256 
257 /*
258  * Navigation and configuration:
259  *
260  * sunos,probe-address ( -- phys.lo ... )
261  * sunos,probe-space ( -- phys.hi )
262  *
263  * sunos,ap-phandle ( -- ap.phandle )
264  *	Return attachment point phandle
265  *
266  * sunos,parent ( child.phandle -- parent.phandle )
267  *
268  * child ( parent.phandle -- child.phandle )
269  * peer ( phandle -- phandle.sibling )
270  *
271  * sunos,alloc-phandle ( -- phandle )
272  * Allocates a unique phandle, not associated with the device tree
273  *
274  * sunos,config-child ( -- child.phandle )
275  * Return the phandle of the child being configured.
276  */
277 
278 #define	FC_PROBE_ADDRESS	"sunos,probe-address"
279 #define	FC_PROBE_SPACE		"sunos,probe-space"
280 #define	FC_AP_PHANDLE		"sunos,ap-phandle"
281 #define	FC_PARENT		"sunos,parent"
282 #define	FC_CHILD_FCODE		"child"
283 #define	FC_PEER_FCODE		"peer"
284 #define	FC_ALLOC_PHANDLE	"sunos,alloc-phandle"
285 #define	FC_CONFIG_CHILD		"sunos,config-child"
286 
287 /*
288  * Fcode Drop In Routines:
289  * sunos,get_fcode_size ( cstr -- len )
290  * Returns the size in bytes of the Fcode for a given drop in.
291  * sunos,get_fcode (cstr buf len -- status? )
292  * Returns the Fcode image for a given drop in.
293  */
294 #define	FC_GET_FCODE_SIZE	"sunos,get-fcode-size"
295 #define	FC_GET_FCODE		"sunos,get-fcode"
296 
297 /*
298  * kernel internal data structures and interfaces
299  * for the fcode interpreter.
300  */
301 #if defined(_KERNEL)
302 
303 /*
304  * PCI bus-specific arguments.
305  *
306  * We can't get the physical config address of the child from the
307  * unit address, so we supply it here, along with the child's dip
308  * as the bus specific argument to pci_ops_alloc_handle.
309  */
310 
311 struct pci_ops_bus_args {
312 	int32_t config_address;		/* phys.hi config addr component */
313 };
314 
315 /*
316  * Define data structures for resource lists and handle management
317  *
318  * 'untyped' resources are managed by the provider.
319  */
320 struct fc_dma_resource {
321 	void *virt;
322 	size_t len;
323 	ddi_dma_handle_t h;
324 	uint32_t devaddr;
325 	struct buf *bp;
326 };
327 
328 struct fc_map_resource {
329 	void *virt;
330 	size_t len;
331 	ddi_acc_handle_t h;
332 	void *regspec;
333 };
334 
335 struct fc_nodeid_resource {
336 	int nodeid;		/* An allocated nodeid */
337 };
338 
339 struct fc_contigious_resource {
340 	void *virt;
341 	size_t len;
342 };
343 struct fc_untyped_resource {
344 	int utype;		/* providers private type field */
345 	void (*free)(void *);	/* function to free the resource */
346 	void *resource;		/* Pointer to the resource */
347 };
348 
349 typedef enum {
350 	RT_DMA = 0,
351 	RT_MAP,
352 	RT_NODEID,
353 	RT_CONTIGIOUS,
354 	RT_UNTYPED
355 } fc_resource_type_t;
356 
357 struct fc_resource {
358 	struct fc_resource *next;
359 	fc_resource_type_t type;
360 	union {
361 		struct fc_dma_resource d;
362 		struct fc_map_resource m;
363 		struct fc_nodeid_resource n;
364 		struct fc_contigious_resource c;
365 		struct fc_untyped_resource r;
366 	} un;
367 };
368 
369 #define	fc_dma_virt	un.d.virt
370 #define	fc_dma_len	un.d.len
371 #define	fc_dma_handle	un.d.h
372 #define	fc_dma_devaddr	un.d.devaddr
373 #define	fc_dma_bp	un.d.bp
374 
375 #define	fc_map_virt	un.m.virt
376 #define	fc_map_len	un.m.len
377 #define	fc_map_handle	un.m.h
378 #define	fc_regspec	un.m.regspec
379 
380 #define	fc_nodeid_r	un.n.nodeid
381 
382 #define	fc_contig_virt	un.c.virt
383 #define	fc_contig_len	un.c.len
384 
385 #define	fc_untyped_type	un.r.utype
386 #define	fc_untyped_free	un.r.free
387 #define	fc_untyped_r	un.r.resource
388 
389 struct fc_phandle_entry {
390 	struct fc_phandle_entry *next;
391 	dev_info_t	*dip;
392 	fc_phandle_t	h;
393 };
394 
395 extern void fc_phandle_table_alloc(struct fc_phandle_entry **);
396 extern void fc_phandle_table_free(struct fc_phandle_entry **);
397 extern dev_info_t *fc_phandle_to_dip(struct fc_phandle_entry **, fc_phandle_t);
398 extern fc_phandle_t fc_dip_to_phandle(struct fc_phandle_entry **, dev_info_t *);
399 extern void fc_add_dip_to_phandle(struct fc_phandle_entry **, dev_info_t *,
400     fc_phandle_t);
401 
402 /*
403  * Structures and functions for managing our own subtree rooted
404  * at the attachment point. The parent linkage is established
405  * at node creation time.  The 'downwards' linkage isn't established
406  * until the node is bound.
407  */
408 struct fc_device_tree {
409 	dev_info_t *dip;
410 	struct fc_device_tree *child;
411 	struct fc_device_tree *peer;
412 };
413 
414 void fc_add_child(dev_info_t *child, dev_info_t *parent,
415     struct fc_device_tree *head);
416 
417 void fc_remove_child(dev_info_t *child, struct fc_device_tree *head);
418 
419 dev_info_t *fc_child_node(dev_info_t *parent, struct fc_device_tree *head);
420 dev_info_t *fc_peer_node(dev_info_t *devi, struct fc_device_tree *head);
421 struct fc_device_tree *fc_find_node(dev_info_t *, struct fc_device_tree *);
422 
423 void fc_create_device_tree(dev_info_t *ap, struct fc_device_tree **head);
424 void fc_remove_device_tree(struct fc_device_tree **head);
425 
426 /*
427  * Our handles represent a list of resources associated with an
428  * attachment point.  The handles chain, just as the ops functions
429  * do, with the ops caller responsible for remembering the handle
430  * of the ops function below it. NB: Externally, this data structure
431  * is opaque. (Not all members may be present in each chained cookie.)
432  * For example, the dtree head is valid in only a single instance
433  * of a set of chained cookies, so use the access function to find it.)
434  */
435 struct fc_resource_list {
436 	struct fc_resource *head;
437 	void *next_handle;		/* next handle in chain */
438 	dev_info_t *ap;			/* Attachment point dip */
439 	dev_info_t *child;		/* Child being configured, if any */
440 	dev_info_t *cdip;		/* Current node, if any */
441 	int cdip_state;			/* node creation state - see below */
442 	void *fcode;			/* fcode kernel address */
443 	size_t fcode_size;		/* fcode size or zero */
444 	char *unit_address;		/* childs unit address */
445 	char *my_args;			/* initial setting for my-args */
446 	void *bus_args;			/* bus dependent arguments */
447 	struct fc_phandle_entry *ptable; /* devinfo/phandle table */
448 	struct fc_device_tree *dtree;	/* Our subtree (leaf cookie only) */
449 };
450 
451 typedef struct fc_resource_list *fco_handle_t;
452 
453 /*
454  * Values for cdip_state:
455  */
456 #define	FC_CDIP_NOSTATE		0x00	/* No state - no nodes created */
457 #define	FC_CDIP_STARTED		0x01	/* Node started - dip in cdip */
458 #define	FC_CDIP_DONE		0x02	/* Node finished - last dip in cdip */
459 #define	FC_CDIP_CONFIG		0x10	/* subtree configured */
460 
461 /*
462  * Functions to allocate handles for the fcode_interpreter.
463  *
464  * This function allocates a handle, used to store resources
465  * associated with this fcode request including the address of
466  * the mapped in and copied in fcode and it's size or NULL, 0
467  * if there is no fcode (the interpreter may look for a drop-in
468  * driver if there is no fcode), the unit address of child and
469  * bus specific arguments.  For PCI, the bus specific arguments
470  * include the child's prototype dip and the config address of
471  * the child, which can't be derived from the unit address.
472  *
473  * The 'handle' returned also contains resource information
474  * about any allocations of kernel resources that the fcode
475  * may have created.  Thus, the handle's life is the life
476  * of the plug-in card and can't be released until the card
477  * is removed.  Upon release, the resources are released.
478  */
479 extern fco_handle_t
480 fc_ops_alloc_handle(dev_info_t *ap, dev_info_t *config_child,
481     void *fcode, size_t fcode_size, char *unit_address, void *bus_args);
482 
483 extern fco_handle_t
484 pci_fc_ops_alloc_handle(dev_info_t *ap, dev_info_t *config_child,
485     void *fcode, size_t fcode_size, char *unit_address,
486     struct pci_ops_bus_args *bus_args);
487 
488 extern fco_handle_t
489 gp2_fc_ops_alloc_handle(dev_info_t *ap, dev_info_t *config_child,
490     void *fcode, size_t fcode_size, char *unit_address,
491     char *my_args);
492 
493 extern void pci_fc_ops_free_handle(fco_handle_t handle);
494 extern void gp2_fc_ops_free_handle(fco_handle_t handle);
495 extern void fc_ops_free_handle(fco_handle_t handle);
496 
497 extern struct fc_phandle_entry **fc_handle_to_phandle_head(fco_handle_t rp);
498 
499 struct fc_device_tree **fc_handle_to_dtree_head(fco_handle_t);
500 struct fc_device_tree *fc_handle_to_dtree(fco_handle_t);
501 
502 /*
503  * fc_ops_t is the main glue back to the framework and attachment point driver
504  * for privileged driver operations.  The framework/driver provides a pointer
505  * to the fc_ops function to handle the request given in the args.  The dip
506  * and handle are passed back to the framework/driver to distinguish
507  * requests, if necessary.  The argument array is an array of fc_cell_t's
508  * and is defined in fcode.h
509  *
510  * The ops function should return -1 to indicate that the service name is
511  * unknown and return the value 0 to indicate that the service name was known
512  * and processed (even if it failed).  ops functions may chain, using the
513  * return code to communicate if the current function handled the service
514  * request. Using this technique, the driver can provide certain ops functions
515  * and allow a framework ops function to handle standardized ops functions,
516  * or work hand in hand with a framework function so both can handle an op.
517  * If an ops function is not handled, thus returning -1 to the driver, the
518  * driver will log an error noting the name of the service and return the
519  * error to the caller.
520  */
521 typedef int (fc_ops_t)(dev_info_t *, fco_handle_t, fc_ci_t *);
522 
523 extern fc_ops_t fc_ops;
524 extern fc_ops_t pci_fc_ops;
525 extern fc_ops_t gp2_fc_ops;
526 
527 /*
528  * Internal structure used to enque an fcode request
529  * The 'next' and 'busy' fields are protected by a mutex.
530  * Thread synchronization is accomplished via use of the 'busy' field.
531  */
532 struct fc_request {
533 	struct fc_request *next;	/* Next in chain (private) */
534 	int		busy;		/* Waiters flag (private; see below) */
535 	int		error;		/* Interpreter return code (private) */
536 	dev_info_t	*ap_dip;	/* Attachment point. ie: pci nexus */
537 	fc_ops_t	*ap_ops;	/* driver's fcode ops function */
538 	fco_handle_t	handle;		/* Caller's private identifier */
539 	timeout_id_t	timeout;	/* Timeout identifier */
540 };
541 
542 /*
543  * Values for 'busy'.  The requester initializes the field to FC_R_INIT (0),
544  * then waits for it be set to FC_R_DONE.  The framework sets it to
545  * FC_R_BUSY while working on the request so it can distinguish between
546  * an inactive and an active request.
547  */
548 #define	FC_R_INIT	0		/* initialized, on queue */
549 #define	FC_R_BUSY	1		/* request is active, busy */
550 #define	FC_R_DONE	2		/* request is done and may be deq'd */
551 
552 /*
553  * Values for 'error'.
554  */
555 #define	FC_SUCCESS	0		/* FCode interpreted successfully */
556 #define	FC_TIMEOUT	1		/* Timer expired */
557 #define	FC_ERROR	-1		/* Interpreter error */
558 
559 /*
560  * Function to call to invoke the fcode interpreter.
561  *
562  * This function will wait and return when the interpreter either
563  * completes successfully or fails, returning pass/fail status as
564  * the return code.  Interim calls to the driver's ops function will
565  * be made for both priv. ops and to create device nodes and properties.
566  *
567  * Calling this function will log a message to userland to request the
568  * eventd to start the userland fcode interpreter process. The interpreter
569  * opens /dev/fcode, which clones an instance of the driver, and then
570  * waits in a 'read' until there's an active request.
571  * XXX: For the prototype, we can start it manually or use an init.d script.
572  *
573  * 'ap' is the attachment point dip: that is, the driving parent's dev_info_t
574  * ie: for pci devices, this will be the dip of the pci nexus.
575  *
576  * The 'handle' is provided for the caller, and can be used to
577  * identify the request along with the attachment point dip, both
578  * of which will be passed back to the driver's ops function.
579  * The handle is allocated first by calling a bus-specific
580  * <bus>_ops_handle_alloc function.
581  *
582  * ops functions may chain; an ops function should return -1 if
583  * the call was not recognized, or 0 if the call was recognized.
584  */
585 extern int fcode_interpreter(dev_info_t *, fc_ops_t *, fco_handle_t);
586 
587 /*
588  * The fcode implementation uses this function to wait for and 'de-queue'
589  * an fcode request.  It's triggered by a 'read' request from the
590  * userland interpreter. It uses a 'sig' form of waiting (cv_wait_sig),
591  * so the interpreter can interrupt the read.
592  */
593 extern struct fc_request *fc_get_request(void);
594 
595 /*
596  * When the fcode implementation is finished servicing a request, it calls this
597  * function to mark the request as done and to signal the originating thread
598  * (now waiting in fcode_interpreter) that the request is done.
599  */
600 extern void fc_finish_request(struct fc_request *);
601 
602 /*
603  * The fcode implementation uses these functions to manage
604  * resource items and resource lists ...
605  */
606 extern void fc_add_resource(fco_handle_t, struct fc_resource *);
607 extern void fc_rem_resource(fco_handle_t, struct fc_resource *);
608 extern void fc_lock_resource_list(fco_handle_t);
609 extern void fc_unlock_resource_list(fco_handle_t);
610 
611 /*
612  * ops common and helper functions
613  */
614 extern int fc_fail_op(dev_info_t *, fco_handle_t, fc_ci_t *);
615 extern int fc_success_op(dev_info_t *, fco_handle_t, fc_ci_t *);
616 
617 extern int fc_syntax_error(fc_ci_t *, char *);
618 extern int fc_priv_error(fc_ci_t *, char *);
619 
620 /*
621  * Recharacterized ddi functions we need to define ...
622  *
623  * The only difference is we call through the attachment point driver,
624  * as a proxy for the child that isn't yet attached. The ddi functions
625  * optimize these functions by not necessarily calling through the
626  * attachment point driver.
627  */
628 int fc_ddi_dma_htoc(dev_info_t *, ddi_dma_handle_t, off_t, ddi_dma_cookie_t *);
629 int fc_ddi_dma_free(dev_info_t *ap, ddi_dma_handle_t h);
630 int fc_ddi_dma_sync(ddi_dma_handle_t h, off_t o, size_t l, uint_t whom);
631 
632 /*
633  * The ndi prop functions aren't appropriate for the interpreter.
634  * We create byte-array, untyped properties.
635  */
636 
637 int fc_ndi_prop_update(dev_t, dev_info_t *, char *, uchar_t *, uint_t);
638 
639 /*
640  * The setup and teardown parts of physio()
641  */
642 int fc_physio_setup(struct buf **bpp, void *io_base, size_t io_len);
643 void fc_physio_free(struct buf **bpp, void *io_base, size_t io_len);
644 
645 /*
646  * debugging macros
647  */
648 extern int fcode_debug;
649 #define	dcmn_err(level, args) if (fcode_debug >= level) cmn_err args
650 
651 #ifdef DEBUG
652 
653 void fc_debug(char *, uintptr_t, uintptr_t,
654     uintptr_t, uintptr_t, uintptr_t);
655 
656 #define	FC_DEBUG0(level, flag, s) if (fcode_debug >= level) \
657     fc_debug(s, 0, 0, 0, 0, 0)
658 #define	FC_DEBUG1(level, flag, fmt, a1) if (fcode_debug >= level) \
659     fc_debug(fmt, (uintptr_t)(a1), 0, 0, 0, 0);
660 #define	FC_DEBUG2(level, flag, fmt, a1, a2) if (fcode_debug >= level) \
661     fc_debug(fmt, (uintptr_t)(a1), (uintptr_t)(a2), 0, 0, 0);
662 #define	FC_DEBUG3(level, flag, fmt, a1, a2, a3) \
663     if (fcode_debug >= level) \
664     fc_debug(fmt, (uintptr_t)(a1), (uintptr_t)(a2), (uintptr_t)(a3), 0, 0);
665 #else
666 #define	FC_DEBUG0(level, flag, s)
667 #define	FC_DEBUG1(level, flag, fmt, a1)
668 #define	FC_DEBUG2(level, flag, fmt, a1, a2)
669 #define	FC_DEBUG3(level, flag, fmt, a1, a2, a3)
670 #endif
671 
672 
673 #endif	/* defined(_KERNEL) */
674 
675 #ifdef	__cplusplus
676 }
677 #endif
678 
679 #endif	/* _SYS_FCODE_H */
680