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 (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2018 Nexenta Systems, Inc.
  25  */
  26 
  27 #ifndef _SYS_SUNNDI_H
  28 #define _SYS_SUNNDI_H
  29 
  30 /*
  31  * Sun Specific NDI definitions
  32  */
  33 
  34 #include <sys/esunddi.h>
  35 #include <sys/sunddi.h>
  36 #include <sys/obpdefs.h>
  37 
  38 #ifdef  __cplusplus
  39 extern "C" {
  40 #endif
  41 
  42 #ifdef _KERNEL
  43 
  44 #define NDI_SUCCESS     DDI_SUCCESS     /* successful return */
  45 #define NDI_FAILURE     DDI_FAILURE     /* unsuccessful return */
  46 #define NDI_NOMEM       -2              /* failed to allocate resources */
  47 #define NDI_BADHANDLE   -3              /* bad handle passed to in function */
  48 #define NDI_FAULT       -4              /* fault during copyin/copyout */
  49 #define NDI_BUSY        -5              /* device busy - could not offline */
  50 #define NDI_UNBOUND     -6              /* device not bound to a driver */
  51 #define NDI_EINVAL      -7              /* invalid request or arguments */
  52 #define NDI_ENOTSUP     -8              /* operation or event not supported */
  53 #define NDI_CLAIMED     NDI_SUCCESS     /* event is claimed */
  54 #define NDI_UNCLAIMED   -9              /* event is not claimed */
  55 
  56 /*
  57  * Property functions:   See also, ddipropdefs.h.
  58  *                      In general, the underlying driver MUST be held
  59  *                      to call it's property functions.
  60  */
  61 
  62 /*
  63  * Used to create boolean properties
  64  */
  65 int
  66 ndi_prop_create_boolean(dev_t match_dev, dev_info_t *dip, char *name);
  67 
  68 /*
  69  * Used to create, modify, and lookup integer properties
  70  */
  71 int
  72 ndi_prop_update_int(dev_t match_dev, dev_info_t *dip, char *name, int data);
  73 
  74 int
  75 ndi_prop_update_int_array(dev_t match_dev, dev_info_t *dip, char *name,
  76     int *data, uint_t nelements);
  77 
  78 int
  79 ndi_prop_update_int64(dev_t match_dev, dev_info_t *dip, char *name,
  80     int64_t data);
  81 
  82 int
  83 ndi_prop_update_int64_array(dev_t match_dev, dev_info_t *dip, char *name,
  84     int64_t *data, uint_t nelements);
  85 
  86 /*
  87  * Used to create, modify, and lookup string properties
  88  */
  89 int
  90 ndi_prop_update_string(dev_t match_dev, dev_info_t *dip, char *name,
  91     char *data);
  92 
  93 int
  94 ndi_prop_update_string_array(dev_t match_dev, dev_info_t *dip,
  95     char *name, char **data, uint_t nelements);
  96 
  97 /*
  98  * Used to create, modify, and lookup byte properties
  99  */
 100 int
 101 ndi_prop_update_byte_array(dev_t match_dev, dev_info_t *dip,
 102     char *name, uchar_t *data, uint_t nelements);
 103 
 104 /*
 105  * Used to remove properties
 106  */
 107 int
 108 ndi_prop_remove(dev_t dev, dev_info_t *dip, char *name);
 109 
 110 void
 111 ndi_prop_remove_all(dev_info_t *dip);
 112 
 113 /*
 114  * Nexus Driver Functions
 115  */
 116 /*
 117  * Allocate and initialize a new dev_info structure.
 118  * This routine will often be called at interrupt time by a nexus in
 119  * response to a hotplug event, therefore memory allocations are
 120  * not allowed to sleep.
 121  */
 122 int
 123 ndi_devi_alloc(dev_info_t *parent, char *node_name, pnode_t nodeid,
 124     dev_info_t **ret_dip);
 125 
 126 void
 127 ndi_devi_alloc_sleep(dev_info_t *parent, char *node_name, pnode_t nodeid,
 128     dev_info_t **ret_dip);
 129 
 130 /*
 131  * Remove an initialized (but not yet attached) dev_info
 132  * node from it's parent.
 133  */
 134 int
 135 ndi_devi_free(dev_info_t *dip);
 136 
 137 /* devinfo locking: use DEVI_BUSY_OWNED in ASSERTs to verify */
 138 void ndi_devi_enter(dev_info_t *dip, int *circ);
 139 void ndi_devi_exit(dev_info_t *dip, int circ);
 140 int ndi_devi_tryenter(dev_info_t *dip, int *circ);
 141 
 142 /* devinfo ref counting */
 143 void ndi_hold_devi(dev_info_t *dip);
 144 void ndi_rele_devi(dev_info_t *dip);
 145 
 146 /* driver ref counting */
 147 struct dev_ops *ndi_hold_driver(dev_info_t *dip);
 148 void ndi_rele_driver(dev_info_t *dip);
 149 
 150 /*
 151  * Change the node name
 152  */
 153 int
 154 ndi_devi_set_nodename(dev_info_t *dip, char *name, int flags);
 155 
 156 /*
 157  * Place the devinfo in the DS_BOUND state,
 158  * binding a driver to the device
 159  *
 160  * Flags:
 161  *      all flags are ignored.
 162  */
 163 int
 164 ndi_devi_bind_driver(dev_info_t *dip, uint_t flags);
 165 
 166 /*
 167  * Asynchronous version of ndi_devi_bind_driver, callable from
 168  * interrupt context. The dip must be a persistent node.
 169  */
 170 int
 171 ndi_devi_bind_driver_async(dev_info_t *dip, uint_t flags);
 172 
 173 /*
 174  * Return devctl state of the child addressed by "name@addr".
 175  * For use by a driver's DEVCTL_DEVICE_GETSTATE handler.
 176  */
 177 int
 178 ndi_devctl_device_getstate(dev_info_t *parent, struct devctl_iocdata *dcp,
 179         uint_t *state);
 180 
 181 /*
 182  * Transition the child addressed by "name@addr" to the online state.
 183  * For use by a driver's DEVCTL_DEVICE_ONLINE handler.
 184  */
 185 int
 186 ndi_devctl_device_online(dev_info_t *dip, struct devctl_iocdata *dcp,
 187         uint_t flags);
 188 
 189 /*
 190  * Transition the child addressed by "name@addr" to the offline state.
 191  * For use by a driver's DEVCTL_DEVICE_OFFLINE handler.
 192  */
 193 int
 194 ndi_devctl_device_offline(dev_info_t *dip, struct devctl_iocdata *dcp,
 195         uint_t flags);
 196 
 197 /*
 198  * Remove the child addressed by name@addr.
 199  * For use by a driver's DEVCTL_DEVICE_REMOVE handler.
 200  */
 201 int
 202 ndi_devctl_device_remove(dev_info_t *dip, struct devctl_iocdata *dcp,
 203         uint_t flags);
 204 
 205 /*
 206  * Bus get state
 207  * For use by a driver's DEVCTL_BUS_GETSTATE handler.
 208  */
 209 int
 210 ndi_devctl_bus_getstate(dev_info_t *dip, struct devctl_iocdata *dcp,
 211         uint_t *state);
 212 
 213 /*
 214  * Place the devinfo in the ONLINE state
 215  */
 216 int
 217 ndi_devi_online(dev_info_t *dip, uint_t flags);
 218 
 219 /*
 220  * Generic devctl ioctl handler
 221  */
 222 int
 223 ndi_devctl_ioctl(dev_info_t *dip, int cmd, intptr_t arg, int mode,
 224         uint_t flags);
 225 
 226 /*
 227  * Asynchronous version of ndi_devi_online, callable from interrupt
 228  * context. The dip must be a persistent node.
 229  */
 230 int
 231 ndi_devi_online_async(dev_info_t *dip, uint_t flags);
 232 
 233 
 234 /*
 235  * Configure children of a nexus node.
 236  *
 237  * Flags:
 238  *      NDI_ONLINE_ATTACH - Attach driver to devinfo node when placing
 239  *                          the device Online.
 240  *      NDI_CONFIG - Recursively configure children if child is nexus node
 241  */
 242 int
 243 ndi_devi_config(dev_info_t *dip, int flags);
 244 
 245 int
 246 ndi_devi_config_driver(dev_info_t *dip, int flags, major_t major);
 247 
 248 int
 249 ndi_devi_config_one(dev_info_t *dip, char *devnm, dev_info_t **dipp, int flags);
 250 
 251 /*
 252  * Unconfigure children of a nexus node.
 253  *
 254  * Flags:
 255  *      NDI_DEVI_REMOVE - Remove child devinfo nodes
 256  *
 257  *      NDI_UNCONFIG - Put child devinfo nodes to uninitialized state,
 258  *                      release resources held by child nodes.
 259  */
 260 int
 261 ndi_devi_unconfig(dev_info_t *dip, int flags);
 262 
 263 int
 264 e_ddi_devi_unconfig(dev_info_t *dip, dev_info_t **dipp, int flags);
 265 
 266 int
 267 ndi_devi_unconfig_one(dev_info_t *dip, char *devnm, dev_info_t **dipp,
 268     int flags);
 269 
 270 int
 271 ndi_devi_unconfig_driver(dev_info_t *dip, int flags, major_t major);
 272 
 273 void
 274 ndi_set_bus_private(dev_info_t *dip, boolean_t up, uint32_t port_type,
 275     void *data);
 276 
 277 void *
 278 ndi_get_bus_private(dev_info_t *dip, boolean_t up);
 279 
 280 boolean_t
 281 ndi_port_type(dev_info_t *dip, boolean_t up, uint32_t port_type);
 282 
 283 /*
 284  * Interrupt Resource Management (IRM) Pools.
 285  */
 286 int
 287 ndi_irm_create(dev_info_t *dip, ddi_irm_params_t *paramsp,
 288     ddi_irm_pool_t **pool_retp);
 289 
 290 int
 291 ndi_irm_destroy(ddi_irm_pool_t *poolp);
 292 
 293 int
 294 ndi_irm_resize_pool(ddi_irm_pool_t *poolp, uint_t newsize);
 295 
 296 /*
 297  * Take a device node "Offline".
 298  *
 299  * Offline means to detach the device instance from the bound
 300  * driver and setting the devinfo state to prevent deferred attach
 301  * from re-attaching the device instance.
 302  *
 303  * Flags:
 304  *      NDI_DEVI_REMOVE - Remove the node from the devinfo tree after
 305  *                        first taking it Offline.
 306  */
 307 
 308 #define NDI_DEVI_REMOVE         0x00000001 /* remove after unconfig */
 309 #define NDI_ONLINE_ATTACH       0x00000002 /* online/attach after config */
 310 #define NDI_MDI_FALLBACK        0x00000004 /* Leadville to fallback to phci */
 311 #define NDI_CONFIG              0x00000008 /* recursively config descendants */
 312 #define NDI_UNCONFIG            0x00000010 /* unconfig to uninitialized state */
 313 #define NDI_DEVI_BIND           0x00000020 /* transition to DS_BOUND state */
 314 #define NDI_DEVI_PERSIST        0x00000040 /* do not config offlined nodes */
 315 #define NDI_PROMNAME            0x00000080 /* name comes from prom */
 316 #define NDI_DEVFS_CLEAN         0x00001000 /* clean dv_nodes only, no detach */
 317 #define NDI_AUTODETACH          0x00002000 /* moduninstall daemon */
 318 #define NDI_NO_EVENT            0x00004000 /* don't devfs add/remove events */
 319 #define NDI_DEVI_DEBUG          0x00008000 /* turn on observability */
 320 #define NDI_CONFIG_REPROBE      0x00010000 /* force reprobe (deferred attach) */
 321 #define NDI_DEVI_ONLINE         0x00020000 /* force offlined device to online */
 322 #define NDI_DEVI_OFFLINE        0x00040000 /* set detached device to offline */
 323 #define NDI_POST_EVENT          0x00080000 /* Post NDI events before remove */
 324 #define NDI_BRANCH_EVENT_OP     0x01000000 /* branch op needs branch event */
 325 #define NDI_NO_EVENT_STATE_CHNG 0x02000000 /* don't change the event state */
 326 #define NDI_DRV_CONF_REPROBE    0x04000000 /* reprobe conf-enum'd nodes only */
 327 #define NDI_DETACH_DRIVER       0x08000000 /* performing driver_detach */
 328 #define NDI_MTC_OFF             0x10000000 /* disable multi-threading */
 329 #define NDI_USER_REQ            0x20000000 /* user requested operation */
 330 #define NDI_DEVI_GONE           0x40000000 /* device is gone */
 331 
 332 /* ndi interface flag values */
 333 #define NDI_SLEEP               0x000000
 334 #define NDI_NOSLEEP             0x100000
 335 #define NDI_EVENT_NOPASS        0x200000 /* do not pass event req up the tree */
 336 
 337 int
 338 ndi_devi_offline(dev_info_t *dip, uint_t flags);
 339 
 340 /*
 341  * Find the child dev_info node of parent nexus 'p' whose name
 342  * matches "cname"@"caddr".  Use ndi_devi_findchild() instead.
 343  */
 344 dev_info_t *
 345 ndi_devi_find(dev_info_t *p, char *cname, char *caddr);
 346 
 347 /*
 348  * Find the child dev_info node of parent nexus 'p' whose name
 349  * matches device name "name"@"addr".
 350  */
 351 dev_info_t *
 352 ndi_devi_findchild(dev_info_t *p, char *devname);
 353 
 354 /*
 355  * Find the child dev_info node of parent nexus 'p' whose name
 356  * matches "dname"@"ua". If a child doesn't have a "ua"
 357  * value, it calls the function "make_ua" to create it.
 358  */
 359 dev_info_t *
 360 ndi_devi_findchild_by_callback(dev_info_t *p, char *dname, char *ua,
 361     int (*make_ua)(dev_info_t *, char *, int));
 362 
 363 /*
 364  * Maintain DEVI_DEVICE_REMOVED hotplug devi_state for remove/reinsert hotplug
 365  * of open devices.
 366  */
 367 int
 368 ndi_devi_device_isremoved(dev_info_t *dip);
 369 int
 370 ndi_devi_device_remove(dev_info_t *dip);
 371 int
 372 ndi_devi_device_insert(dev_info_t *dip);
 373 
 374 /*
 375  * generate debug msg via NDI_DEVI_DEBUG flag
 376  */
 377 #define NDI_DEBUG(flags, args)  \
 378         if (flags & NDI_DEVI_DEBUG) cmn_err args
 379 
 380 /*
 381  * Copy in the devctl IOCTL data structure and the strings referenced
 382  * by the structure.
 383  *
 384  * Convenience functions for use by nexus drivers as part of the
 385  * implementation of devctl IOCTL handling.
 386  */
 387 int
 388 ndi_dc_allochdl(void *iocarg, struct devctl_iocdata **rdcp);
 389 
 390 void
 391 ndi_dc_freehdl(struct devctl_iocdata *dcp);
 392 
 393 char *
 394 ndi_dc_getpath(struct devctl_iocdata *dcp);
 395 
 396 char *
 397 ndi_dc_getname(struct devctl_iocdata *dcp);
 398 
 399 char *
 400 ndi_dc_getaddr(struct devctl_iocdata *dcp);
 401 
 402 nvlist_t *
 403 ndi_dc_get_ap_data(struct devctl_iocdata *dcp);
 404 
 405 char *
 406 ndi_dc_getminorname(struct devctl_iocdata *dcp);
 407 
 408 int
 409 ndi_dc_return_dev_state(dev_info_t *dip, struct devctl_iocdata *dcp);
 410 
 411 int
 412 ndi_dc_return_ap_state(devctl_ap_state_t *ap, struct devctl_iocdata *dcp);
 413 
 414 int
 415 ndi_dc_return_bus_state(dev_info_t *dip, struct devctl_iocdata *dcp);
 416 
 417 int
 418 ndi_dc_devi_create(struct devctl_iocdata *dcp, dev_info_t *pdip, int flags,
 419     dev_info_t **rdip);
 420 
 421 int
 422 ndi_get_bus_state(dev_info_t *dip, uint_t *rstate);
 423 
 424 int
 425 ndi_set_bus_state(dev_info_t *dip, uint_t state);
 426 
 427 /*
 428  * Post an event notification up the device tree hierarchy to the
 429  * parent nexus, until claimed by a bus nexus driver or the top
 430  * of the dev_info tree is reached.
 431  */
 432 int
 433 ndi_post_event(dev_info_t *dip, dev_info_t *rdip, ddi_eventcookie_t eventhdl,
 434     void *impl_data);
 435 
 436 /*
 437  * Called by the NDI Event Framework to deliver a registration request to the
 438  * appropriate bus nexus driver.
 439  */
 440 int
 441 ndi_busop_add_eventcall(dev_info_t *dip, dev_info_t *rdip,
 442     ddi_eventcookie_t eventhdl, void (*callback)(), void *arg,
 443     ddi_callback_id_t *cb_id);
 444 
 445 /*
 446  * Called by the NDI Event Framework to deliver an unregister request to the
 447  * appropriate bus nexus driver.
 448  */
 449 int
 450 ndi_busop_remove_eventcall(dev_info_t *ddip, ddi_callback_id_t id);
 451 
 452 /*
 453  * Called by the NDI Event Framework and/or a bus nexus driver's
 454  * implementation of the (*bus_get_eventcookie)() interface up the device tree
 455  * hierarchy, until claimed by a bus nexus driver or the top of the dev_info
 456  * tree is reached.  The NDI Event Framework will skip nexus drivers which are
 457  * not configured to handle NDI events.
 458  */
 459 int
 460 ndi_busop_get_eventcookie(dev_info_t *dip, dev_info_t *rdip, char *name,
 461     ddi_eventcookie_t *event_cookiep);
 462 
 463 /*
 464  * ndi event callback support routines:
 465  *
 466  * these functions require an opaque ndi event handle
 467  */
 468 typedef struct ndi_event_hdl *ndi_event_hdl_t;
 469 
 470 /*
 471  * structure for maintaining each registered callback
 472  */
 473 typedef struct ndi_event_callbacks {
 474         struct ndi_event_callbacks *ndi_evtcb_next;
 475         struct ndi_event_callbacks *ndi_evtcb_prev;
 476         dev_info_t      *ndi_evtcb_dip;
 477         char            *devname; /* name of device defining this callback */
 478         void            (*ndi_evtcb_callback)();
 479         void            *ndi_evtcb_arg;
 480         ddi_eventcookie_t       ndi_evtcb_cookie;
 481 } ndi_event_callbacks_t;
 482 
 483 /*
 484  * a nexus driver defines events that it can support using the
 485  * following structure
 486  */
 487 typedef struct ndi_event_definition {
 488         int                     ndi_event_tag;
 489         char                    *ndi_event_name;
 490         ddi_plevel_t            ndi_event_plevel;
 491         uint_t                  ndi_event_attributes;
 492 } ndi_event_definition_t;
 493 
 494 typedef struct ndi_event_cookie {
 495         ndi_event_definition_t  *definition;    /* Event Description */
 496         dev_info_t              *ddip;          /* Devi defining this event */
 497         ndi_event_callbacks_t   *callback_list; /* Cb's reg'd to w/ this evt */
 498         struct ndi_event_cookie *next_cookie;   /* Next cookie def'd in hdl */
 499 } ndi_event_cookie_t;
 500 
 501 
 502 #define NDI_EVENT(cookie) ((struct ndi_event_cookie *)(void *)(cookie))
 503 #define NDI_EVENT_NAME(cookie) (NDI_EVENT(cookie)->definition->ndi_event_name)
 504 #define NDI_EVENT_TAG(cookie) (NDI_EVENT(cookie)->definition->ndi_event_tag)
 505 #define NDI_EVENT_ATTRIBUTES(cookie) \
 506         (NDI_EVENT(cookie)->definition->ndi_event_attributes)
 507 #define NDI_EVENT_PLEVEL(cookie) \
 508         (NDI_EVENT(cookie)->definition->ndi_event_plevel)
 509 #define NDI_EVENT_DDIP(cookie) (NDI_EVENT(cookie)->ddip)
 510 
 511 /* ndi_event_attributes */
 512 #define NDI_EVENT_POST_TO_ALL   0x0 /* broadcast: post to all handlers */
 513 #define NDI_EVENT_POST_TO_TGT   0x1 /* call only specific child's hdlr */
 514 
 515 typedef struct ndi_event_set {
 516         ushort_t                ndi_events_version;
 517         ushort_t                ndi_n_events;
 518         ndi_event_definition_t  *ndi_event_defs;
 519 } ndi_event_set_t;
 520 
 521 
 522 #define NDI_EVENTS_REV0                 0
 523 #define NDI_EVENTS_REV1                 1
 524 
 525 /*
 526  * allocate an ndi event handle
 527  */
 528 int
 529 ndi_event_alloc_hdl(dev_info_t *dip, ddi_iblock_cookie_t cookie,
 530         ndi_event_hdl_t *ndi_event_hdl, uint_t flag);
 531 
 532 /*
 533  * free the ndi event handle
 534  */
 535 int
 536 ndi_event_free_hdl(ndi_event_hdl_t handle);
 537 
 538 /*
 539  * bind or unbind a set of events to/from the event handle
 540  */
 541 int
 542 ndi_event_bind_set(ndi_event_hdl_t      handle,
 543         ndi_event_set_t         *ndi_event_set,
 544         uint_t                  flag);
 545 
 546 int
 547 ndi_event_unbind_set(ndi_event_hdl_t    handle,
 548         ndi_event_set_t         *ndi_event_set,
 549         uint_t                  flag);
 550 
 551 /*
 552  * get an event cookie
 553  */
 554 int
 555 ndi_event_retrieve_cookie(ndi_event_hdl_t       handle,
 556         dev_info_t              *child_dip,
 557         char                    *eventname,
 558         ddi_eventcookie_t       *cookiep,
 559         uint_t                  flag);
 560 
 561 /*
 562  * add an event callback info to the ndi event handle
 563  */
 564 int
 565 ndi_event_add_callback(ndi_event_hdl_t  handle,
 566         dev_info_t              *child_dip,
 567         ddi_eventcookie_t       cookie,
 568         void                    (*event_callback)
 569                                         (dev_info_t *,
 570                                         ddi_eventcookie_t,
 571                                         void *arg,
 572                                         void *impldata),
 573         void                    *arg,
 574         uint_t                  flag,
 575         ddi_callback_id_t *cb_id);
 576 
 577 /*
 578  * remove an event callback registration from the ndi event handle
 579  */
 580 int
 581 ndi_event_remove_callback(ndi_event_hdl_t handle, ddi_callback_id_t id);
 582 
 583 /*
 584  * perform callbacks for a specified cookie
 585  */
 586 int
 587 ndi_event_run_callbacks(ndi_event_hdl_t handle, dev_info_t *child_dip,
 588     ddi_eventcookie_t cookie, void *bus_impldata);
 589 
 590 /*
 591  * do callback for just one child_dip, regardless of attributes
 592  */
 593 int ndi_event_do_callback(ndi_event_hdl_t handle, dev_info_t *child_dip,
 594         ddi_eventcookie_t cookie, void *bus_impldata);
 595 
 596 /*
 597  * ndi_event_tag_to_cookie: utility function to find an event cookie
 598  * given an event tag
 599  */
 600 ddi_eventcookie_t
 601 ndi_event_tag_to_cookie(ndi_event_hdl_t handle, int event_tag);
 602 
 603 /*
 604  * ndi_event_cookie_to_tag: utility function to find an event tag
 605  * given an event_cookie
 606  */
 607 int
 608 ndi_event_cookie_to_tag(ndi_event_hdl_t handle,
 609         ddi_eventcookie_t cookie);
 610 
 611 /*
 612  * ndi_event_cookie_to_name: utility function to find an event
 613  * name given an event_cookie
 614  */
 615 char *
 616 ndi_event_cookie_to_name(ndi_event_hdl_t handle,
 617         ddi_eventcookie_t cookie);
 618 
 619 /*
 620  * ndi_event_tag_to_name: utility function to find an event
 621  * name given an event_tag
 622  */
 623 char *
 624 ndi_event_tag_to_name(ndi_event_hdl_t   handle, int event_tag);
 625 
 626 dev_info_t *
 627 ndi_devi_config_vhci(char *, int);
 628 
 629 #ifdef DEBUG
 630 /*
 631  * ndi_event_dump_hdl: debug functionality used to display event handle
 632  */
 633 void
 634 ndi_event_dump_hdl(struct ndi_event_hdl *hdl, char *location);
 635 #endif
 636 
 637 /*
 638  * Default busop bus_config helper functions
 639  */
 640 int
 641 ndi_busop_bus_config(dev_info_t *pdip, uint_t flags, ddi_bus_config_op_t op,
 642     void *arg, dev_info_t **child, clock_t reset_delay);
 643 
 644 int
 645 ndi_busop_bus_unconfig(dev_info_t *dip, uint_t flags, ddi_bus_config_op_t op,
 646     void *arg);
 647 
 648 /*
 649  * Called by the Nexus/HPC drivers to register, unregister and interact
 650  * with the hotplug framework for the specified hotplug connection.
 651  */
 652 int
 653 ndi_hp_register(dev_info_t *dip, ddi_hp_cn_info_t *info_p);
 654 
 655 int
 656 ndi_hp_unregister(dev_info_t *dip, char *cn_name);
 657 
 658 int
 659 ndi_hp_state_change_req(dev_info_t *dip, char *cn_name,
 660     ddi_hp_cn_state_t state, uint_t flag);
 661 
 662 void
 663 ndi_hp_walk_cn(dev_info_t *dip, int (*f)(ddi_hp_cn_info_t *, void *),
 664     void *arg);
 665 
 666 /*
 667  * Bus Resource allocation structures and function prototypes exported
 668  * by busra module
 669  */
 670 
 671 /* structure for specifying a request */
 672 typedef struct ndi_ra_request {
 673         uint_t          ra_flags;       /* General flags                */
 674                                         /* see bit definitions below    */
 675 
 676         uint64_t        ra_len;         /* Requested allocation length  */
 677 
 678         uint64_t        ra_addr;        /* Specific base address requested */
 679 
 680         uint64_t        ra_boundbase;   /* Base address of the area for */
 681                                         /* the allocated resource to be */
 682                                         /* restricted to                */
 683 
 684         uint64_t        ra_boundlen;    /* Length of the area, starting */
 685                                         /* from ra_boundbase, for the   */
 686                                         /* allocated resource to be     */
 687                                         /* restricted to.               */
 688 
 689         uint64_t        ra_align_mask;  /* Alignment mask used for      */
 690                                         /* allocated base address       */
 691 } ndi_ra_request_t;
 692 
 693 
 694 /* ra_flags bit definitions */
 695 #define NDI_RA_ALIGN_SIZE       0x0001  /* Set the alignment of the     */
 696                                         /* allocated resource address   */
 697                                         /* according to the ra_len      */
 698                                         /* value (alignment mask will   */
 699                                         /* be (ra_len - 1)). Value of   */
 700                                         /* ra_len has to be power of 2. */
 701                                         /* If this flag is set, value of */
 702                                         /* ra_align_mask will be ignored. */
 703 
 704 
 705 #define NDI_RA_ALLOC_BOUNDED    0x0002  /* Indicates that the resource  */
 706                                         /* should be restricted to the  */
 707                                         /* area specified by ra_boundbase */
 708                                         /* and ra_boundlen */
 709 
 710 #define NDI_RA_ALLOC_SPECIFIED  0x0004  /* Indicates that a specific    */
 711                                         /* address (ra_addr value) is   */
 712                                         /* requested.                   */
 713 
 714 #define NDI_RA_ALLOC_PARTIAL_OK 0x0008  /* Indicates if requested size  */
 715                                         /* (ra_len) chunk is not available */
 716                                         /* then allocate as big chunk as */
 717                                         /* possible which is less than or */
 718                                         /* equal to ra_len size. */
 719 
 720 
 721 /* return values specific to bus resource allocator */
 722 #define NDI_RA_PARTIAL_REQ              -7
 723 
 724 
 725 
 726 
 727 /* Predefined types for generic type of resources */
 728 #define NDI_RA_TYPE_MEM                 "memory"
 729 #define NDI_RA_TYPE_IO                  "io"
 730 #define NDI_RA_TYPE_PCI_BUSNUM          "pci_bus_number"
 731 #define NDI_RA_TYPE_PCI_PREFETCH_MEM    "pci_prefetchable_memory"
 732 #define NDI_RA_TYPE_INTR                "interrupt"
 733 
 734 /* flag bit definition */
 735 #define NDI_RA_PASS     0x0001          /* pass request up the dev tree */
 736 
 737 /*
 738  * Prototype definitions for functions exported
 739  */
 740 
 741 int
 742 ndi_ra_map_setup(dev_info_t *dip, char *type);
 743 
 744 int
 745 ndi_ra_map_destroy(dev_info_t *dip, char *type);
 746 
 747 int
 748 ndi_ra_alloc(dev_info_t *dip, ndi_ra_request_t *req, uint64_t *basep,
 749         uint64_t *lenp, char *type, uint_t flag);
 750 
 751 int
 752 ndi_ra_free(dev_info_t *dip, uint64_t base, uint64_t len, char *type,
 753         uint_t flag);
 754 
 755 /*
 756  * ndi_dev_is_prom_node: Return non-zero if the node is a prom node
 757  */
 758 int ndi_dev_is_prom_node(dev_info_t *);
 759 
 760 /*
 761  * ndi_dev_is_pseudo_node: Return non-zero if the node is a pseudo node.
 762  * NB: all non-prom nodes are pseudo nodes.
 763  * c.f. ndi_dev_is_persistent_node
 764  */
 765 int ndi_dev_is_pseudo_node(dev_info_t *);
 766 
 767 /*
 768  * ndi_dev_is_persistent_node: Return non-zero if the node has the
 769  * property of persistence.
 770  */
 771 int ndi_dev_is_persistent_node(dev_info_t *);
 772 
 773 /*
 774  * ndi_dev_is_hotplug_node: Return non-zero if the node was created by hotplug.
 775  */
 776 int ndi_dev_is_hotplug_node(dev_info_t *);
 777 
 778 /*
 779  * ndi_dev_is_hidden_node: Return non-zero if the node is hidden.
 780  */
 781 int ndi_dev_is_hidden_node(dev_info_t *);
 782 
 783 /*
 784  * ndi_devi_set_hidden: mark a node as hidden
 785  * ndi_devi_clr_hidden: mark a node as visible
 786  */
 787 void ndi_devi_set_hidden(dev_info_t *);
 788 void ndi_devi_clr_hidden(dev_info_t *);
 789 
 790 /*
 791  * Event posted when a fault is reported
 792  */
 793 #define DDI_DEVI_FAULT_EVENT    "DDI:DEVI_FAULT"
 794 
 795 struct ddi_fault_event_data {
 796         dev_info_t              *f_dip;
 797         ddi_fault_impact_t      f_impact;
 798         ddi_fault_location_t    f_location;
 799         const char              *f_message;
 800         ddi_devstate_t          f_oldstate;
 801 };
 802 
 803 /*
 804  * Access handle/DMA handle fault flag setting/clearing functions for nexi
 805  */
 806 void ndi_set_acc_fault(ddi_acc_handle_t ah);
 807 void ndi_clr_acc_fault(ddi_acc_handle_t ah);
 808 void ndi_set_dma_fault(ddi_dma_handle_t dh);
 809 void ndi_clr_dma_fault(ddi_dma_handle_t dh);
 810 
 811 /* Driver.conf property merging */
 812 int     ndi_merge_node(dev_info_t *, int (*)(dev_info_t *, char *, int));
 813 void    ndi_merge_wildcard_node(dev_info_t *);
 814 
 815 /*
 816  * Ndi 'flavor' support: These interfaces are to support a nexus driver
 817  * with multiple 'flavors' of children (devi_flavor of child), coupled
 818  * with a child flavor-specifc private data mechanism (via devi_flavor_v
 819  * of parent). This is provided as an extension to ddi_[sg]et_driver_private,
 820  * where the vanilla 'flavor' is what is stored or retrieved via
 821  * ddi_[sg]et_driver_private.
 822  *
 823  * Flavors are indexed with a small integer. The first flavor, flavor
 824  * zero, is always present and reserved as the 'vanilla' flavor.
 825  * Space for extra flavors can be allocated and private pointers
 826  * with respect to each flavor set and retrieved.
 827  *
 828  * NOTE:For a nexus driver, if the need to support multiple flavors of
 829  *      children is understood from the begining, then a private 'flavor'
 830  *      mechanism can be implemented via ddi_[sg]et_driver_private.
 831  *
 832  *      With SCSA, the need to support multiple flavors of children was not
 833  *      anticipated, and ddi_get_driver_private(9F) of an initiator port
 834  *      devinfo node was publicly defined in the DDI to return a
 835  *      scsi_device(9S) child-flavor specific value: a pointer to
 836  *      scsi_hba_tran(9S).  Over the years, each time the need to support
 837  *      a new flavor of child has occurred, a new form of overload/kludge
 838  *      has been devised. The ndi 'flavors' interfaces provide a simple way
 839  *      to address this issue that can be used by both SCSA nexus support,
 840  *      and by other nexus drivers.
 841  */
 842 
 843 /*
 844  * Interfaces to maintain flavor-specific private data for children of self
 845  */
 846 #define NDI_FLAVOR_VANILLA      0
 847 
 848 void    ndi_flavorv_alloc(dev_info_t *self, int nflavors);
 849 void    ndi_flavorv_set(dev_info_t *self, ndi_flavor_t child_flavor, void *);
 850 void    *ndi_flavorv_get(dev_info_t *self, ndi_flavor_t child_flavor);
 851 
 852 /* Interfaces for 'self' nexus driver to get/set flavor of child */
 853 void            ndi_flavor_set(dev_info_t *child, ndi_flavor_t child_flavor);
 854 ndi_flavor_t    ndi_flavor_get(dev_info_t *child);
 855 
 856 #endif  /* _KERNEL */
 857 
 858 #ifdef  __cplusplus
 859 }
 860 #endif
 861 
 862 #endif  /* _SYS_SUNNDI_H */