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