17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5a3114836SGerry Liu * Common Development and Distribution License (the "License"). 6a3114836SGerry Liu * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22fa9e4066Sahrens * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 2448bbca81SDaniel Hoffman * Copyright (c) 2016 by Delphix. All rights reserved. 25*3ce53722SRobert Mustacchi * Copyright 2020 Oxide Computer Company 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #ifndef _SYS_ESUNDDI_H 297c478bd9Sstevel@tonic-gate #define _SYS_ESUNDDI_H 307c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 317c478bd9Sstevel@tonic-gate #include <sys/proc.h> 327c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 337c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 347c478bd9Sstevel@tonic-gate #include <sys/epm.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifdef __cplusplus 377c478bd9Sstevel@tonic-gate extern "C" { 387c478bd9Sstevel@tonic-gate #endif 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #ifdef _KERNEL 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * esunddi.h: Function prototypes for kernel ddi functions. 447c478bd9Sstevel@tonic-gate * Note that drivers calling these functions are not 457c478bd9Sstevel@tonic-gate * portable. 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate int 497c478bd9Sstevel@tonic-gate e_ddi_prop_create(dev_t dev, dev_info_t *dip, int flag, 50*3ce53722SRobert Mustacchi char *name, caddr_t value, int length); 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate int 537c478bd9Sstevel@tonic-gate e_ddi_prop_modify(dev_t dev, dev_info_t *dip, int flag, 54*3ce53722SRobert Mustacchi char *name, caddr_t value, int length); 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate int 577c478bd9Sstevel@tonic-gate e_ddi_prop_update_int(dev_t match_dev, dev_info_t *dip, 58*3ce53722SRobert Mustacchi char *name, int data); 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate int 617c478bd9Sstevel@tonic-gate e_ddi_prop_update_int64(dev_t match_dev, dev_info_t *dip, 627c478bd9Sstevel@tonic-gate char *name, int64_t data); 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate int 657c478bd9Sstevel@tonic-gate e_ddi_prop_update_int_array(dev_t match_dev, dev_info_t *dip, 667c478bd9Sstevel@tonic-gate char *name, int *data, uint_t nelements); 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate int 697c478bd9Sstevel@tonic-gate e_ddi_prop_update_int64_array(dev_t match_dev, dev_info_t *dip, 707c478bd9Sstevel@tonic-gate char *name, int64_t *data, uint_t nelements); 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate int 737c478bd9Sstevel@tonic-gate e_ddi_prop_update_string(dev_t match_dev, dev_info_t *dip, 74*3ce53722SRobert Mustacchi char *name, char *data); 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate int 777c478bd9Sstevel@tonic-gate e_ddi_prop_update_string_array(dev_t match_dev, dev_info_t *dip, 787c478bd9Sstevel@tonic-gate char *name, char **data, uint_t nelements); 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate int 817c478bd9Sstevel@tonic-gate e_ddi_prop_update_byte_array(dev_t match_dev, dev_info_t *dip, 827c478bd9Sstevel@tonic-gate char *name, uchar_t *data, uint_t nelements); 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate int 857c478bd9Sstevel@tonic-gate e_ddi_prop_remove(dev_t dev, dev_info_t *dip, char *name); 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate void 887c478bd9Sstevel@tonic-gate e_ddi_prop_remove_all(dev_info_t *dip); 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate int 917c478bd9Sstevel@tonic-gate e_ddi_prop_undefine(dev_t dev, dev_info_t *dip, int flag, char *name); 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate int 947c478bd9Sstevel@tonic-gate e_ddi_getprop(dev_t dev, vtype_t type, char *name, int flags, int defaultval); 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate int64_t 977c478bd9Sstevel@tonic-gate e_ddi_getprop_int64(dev_t dev, vtype_t type, char *name, 98*3ce53722SRobert Mustacchi int flags, int64_t defvalue); 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate int 1017c478bd9Sstevel@tonic-gate e_ddi_getproplen(dev_t dev, vtype_t type, char *name, int flags, int *lengthp); 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate int 1047c478bd9Sstevel@tonic-gate e_ddi_getlongprop(dev_t dev, vtype_t type, char *name, int flags, 105*3ce53722SRobert Mustacchi caddr_t valuep, int *lengthp); 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate int 1087c478bd9Sstevel@tonic-gate e_ddi_getlongprop_buf(dev_t dev, vtype_t type, char *name, int flags, 109*3ce53722SRobert Mustacchi caddr_t valuep, int *lengthp); 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate int 1127c478bd9Sstevel@tonic-gate e_ddi_parental_suspend_resume(dev_info_t *dip); 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate int 1157c478bd9Sstevel@tonic-gate e_ddi_resume(dev_info_t *dip, ddi_attach_cmd_t); 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate int 1187c478bd9Sstevel@tonic-gate e_ddi_suspend(dev_info_t *dip, ddi_detach_cmd_t cmd); 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate void 1217c478bd9Sstevel@tonic-gate pm_init(void); 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate void 1247c478bd9Sstevel@tonic-gate e_ddi_prop_list_delete(ddi_prop_t *proplist); 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate int 1277c478bd9Sstevel@tonic-gate e_ddi_copyfromdev(dev_info_t *, off_t, const void *, void *, size_t); 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate int 1307c478bd9Sstevel@tonic-gate e_ddi_copytodev(dev_info_t *, off_t, const void *, void *, size_t); 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate /* 1337c478bd9Sstevel@tonic-gate * return codes for devi_stillreferenced() 1347c478bd9Sstevel@tonic-gate * 1357c478bd9Sstevel@tonic-gate * DEVI_REFERENCED - specfs has open minor device(s) for the devinfo 1367c478bd9Sstevel@tonic-gate * DEVI_NOT_REFERENCED - specfs has no open minor device for the devinfo 1377c478bd9Sstevel@tonic-gate */ 1387c478bd9Sstevel@tonic-gate #define DEVI_REFERENCED 1 1397c478bd9Sstevel@tonic-gate #define DEVI_NOT_REFERENCED 0 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate int 1427c478bd9Sstevel@tonic-gate devi_stillreferenced(dev_info_t *dip); 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate extern int (*pm_platform_power)(power_req_t *); 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate /* 1477c478bd9Sstevel@tonic-gate * A consolidation private function which is essentially equivalent to 1487c478bd9Sstevel@tonic-gate * ddi_umem_lock but with the addition of arguments ops_vector and procp. 1497c478bd9Sstevel@tonic-gate * The procp argument can be eliminated eventually as part of proper 1507c478bd9Sstevel@tonic-gate * dynamic reconfiguration callback implementation. 1517c478bd9Sstevel@tonic-gate * 1527c478bd9Sstevel@tonic-gate * The valid flag values are those used for ddi_umem_lock plus an 1537c478bd9Sstevel@tonic-gate * additional flag (DDI_UMEMLOCK_LONGTERM) which must be set when the 1547c478bd9Sstevel@tonic-gate * locking will be maintained for an indefinitely long period (essentially 1557c478bd9Sstevel@tonic-gate * permanent), rather than for what would be required for a typical I/O 1567c478bd9Sstevel@tonic-gate * completion. When DDI_UMEMLOCK_LONGTERM is set, umem_lockmemory will 1577c478bd9Sstevel@tonic-gate * return EFAULT if the memory pertains to a regular file which is 1587c478bd9Sstevel@tonic-gate * mapped MAP_SHARED. This is to prevent a deadlock in the pvn routines 1597c478bd9Sstevel@tonic-gate * if a file truncation is attempted after the locking is done. 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate int 1627c478bd9Sstevel@tonic-gate umem_lockmemory(caddr_t addr, size_t size, int flags, 163*3ce53722SRobert Mustacchi ddi_umem_cookie_t *cookie, struct umem_callback_ops *ops_vector, 164*3ce53722SRobert Mustacchi proc_t *procp); 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate #define DDI_UMEMLOCK_LONGTERM 0x04 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate /* 1697c478bd9Sstevel@tonic-gate * These are evolving forms of the ddi function ddi_hold_devi_by_instance. 1707c478bd9Sstevel@tonic-gate * Like ddi_hold_devi_by_instance, the hold should be released with 1717c478bd9Sstevel@tonic-gate * ddi_release_devi. 1727c478bd9Sstevel@tonic-gate */ 1737c478bd9Sstevel@tonic-gate dev_info_t * 1747c478bd9Sstevel@tonic-gate e_ddi_hold_devi_by_dev(dev_t dev, int flags); 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate dev_info_t * 1777c478bd9Sstevel@tonic-gate e_ddi_hold_devi_by_path(char *path, int flags); 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate /* {e_}ddi_hold_devi{_by{instance|dev|path}} flags */ 1807c478bd9Sstevel@tonic-gate #define E_DDI_HOLD_DEVI_NOATTACH 0x01 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate void 1837c478bd9Sstevel@tonic-gate e_ddi_hold_devi(dev_info_t *); 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate /* 1867c478bd9Sstevel@tonic-gate * Return the reference count on a devinfo node. The caller can determine, 18748bbca81SDaniel Hoffman * with knowledge of its own holds, if the devinfo node is still in use. 1887c478bd9Sstevel@tonic-gate */ 1897c478bd9Sstevel@tonic-gate int 1907c478bd9Sstevel@tonic-gate e_ddi_devi_holdcnt(dev_info_t *dip); 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate /* 1937c478bd9Sstevel@tonic-gate * Perform path reconstruction given a major and instance. Does not 1947c478bd9Sstevel@tonic-gate * drive attach of the path. 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate int 1977c478bd9Sstevel@tonic-gate e_ddi_majorinstance_to_path(major_t major, int instance, char *name); 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate /* 2007c478bd9Sstevel@tonic-gate * walk all devinfo nodes linked on the driver list 2017c478bd9Sstevel@tonic-gate */ 2027c478bd9Sstevel@tonic-gate void 2037c478bd9Sstevel@tonic-gate e_ddi_walk_driver(char *, int (*f)(dev_info_t *, void *), void *); 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate /* 2067c478bd9Sstevel@tonic-gate * Given the nodeid for a persistent node, find the corresponding 2077c478bd9Sstevel@tonic-gate * devinfo node. 2087c478bd9Sstevel@tonic-gate * NOTE: .conf nodeids are not valid arguments to this function. 2097c478bd9Sstevel@tonic-gate */ 2107c478bd9Sstevel@tonic-gate dev_info_t * 211fa9e4066Sahrens e_ddi_nodeid_to_dip(pnode_t nodeid); 2127c478bd9Sstevel@tonic-gate 213a3114836SGerry Liu /* 214a3114836SGerry Liu * Defines for DR interfaces 215a3114836SGerry Liu */ 216a3114836SGerry Liu #define DEVI_BRANCH_CHILD 0x01 /* Walk immediate children of root */ 217a3114836SGerry Liu #define DEVI_BRANCH_CONFIGURE 0x02 /* Configure branch after create */ 218a3114836SGerry Liu #define DEVI_BRANCH_DESTROY 0x04 /* Destroy branch after unconfigure */ 219a3114836SGerry Liu #define DEVI_BRANCH_EVENT 0x08 /* Post NDI event */ 220a3114836SGerry Liu #define DEVI_BRANCH_PROM 0x10 /* Branches derived from PROM nodes */ 221a3114836SGerry Liu #define DEVI_BRANCH_SID 0x20 /* SID node branches */ 222a3114836SGerry Liu #define DEVI_BRANCH_ROOT 0x40 /* Node is the root of a branch */ 223a3114836SGerry Liu 224a3114836SGerry Liu typedef struct devi_branch { 225a3114836SGerry Liu void *arg; 226a3114836SGerry Liu void (*devi_branch_callback)(dev_info_t *, void *, uint_t); 227a3114836SGerry Liu int type; 228a3114836SGerry Liu union { 229a3114836SGerry Liu int (*prom_branch_select)(pnode_t, void *, uint_t); 230a3114836SGerry Liu int (*sid_branch_create)(dev_info_t *, void *, uint_t); 231a3114836SGerry Liu } create; 232a3114836SGerry Liu } devi_branch_t; 233a3114836SGerry Liu 234a3114836SGerry Liu extern int e_ddi_branch_create(dev_info_t *pdip, devi_branch_t *bp, 235a3114836SGerry Liu dev_info_t **dipp, uint_t flags); 236a3114836SGerry Liu extern int e_ddi_branch_configure(dev_info_t *rdip, dev_info_t **dipp, 237a3114836SGerry Liu uint_t flags); 238a3114836SGerry Liu extern int e_ddi_branch_unconfigure(dev_info_t *rdip, dev_info_t **dipp, 239a3114836SGerry Liu uint_t flags); 240a3114836SGerry Liu extern int e_ddi_branch_destroy(dev_info_t *rdip, dev_info_t **dipp, 241a3114836SGerry Liu uint_t flags); 242a3114836SGerry Liu extern void e_ddi_branch_hold(dev_info_t *rdip); 243a3114836SGerry Liu extern void e_ddi_branch_rele(dev_info_t *rdip); 244a3114836SGerry Liu extern int e_ddi_branch_held(dev_info_t *rdip); 245a3114836SGerry Liu extern int e_ddi_branch_referenced(dev_info_t *rdip, 246a3114836SGerry Liu int (*cb)(dev_info_t *dip, void *, uint_t), void *arg); 247a3114836SGerry Liu 2487c478bd9Sstevel@tonic-gate /* 2497c478bd9Sstevel@tonic-gate * Obsolete interfaces, no longer used, to be removed. 2507c478bd9Sstevel@tonic-gate * Retained only for driver compatibility. 2517c478bd9Sstevel@tonic-gate */ 252*3ce53722SRobert Mustacchi void e_ddi_enter_driver_list(struct devnames *, int *); /* obsolete */ 2537c478bd9Sstevel@tonic-gate 254*3ce53722SRobert Mustacchi int e_ddi_tryenter_driver_list(struct devnames *, int *); /* obsolete */ 2557c478bd9Sstevel@tonic-gate 256*3ce53722SRobert Mustacchi void e_ddi_exit_driver_list(struct devnames *, int); /* obsolete */ 257*3ce53722SRobert Mustacchi 258*3ce53722SRobert Mustacchi typedef struct ddi_unbind_callback { 259*3ce53722SRobert Mustacchi list_node_t ddiub_next; 260*3ce53722SRobert Mustacchi void (*ddiub_cb)(void *, dev_info_t *); 261*3ce53722SRobert Mustacchi void *ddiub_arg; 262*3ce53722SRobert Mustacchi } ddi_unbind_callback_t; 2637c478bd9Sstevel@tonic-gate 264*3ce53722SRobert Mustacchi extern void e_ddi_register_unbind_callback(dev_info_t *, 265*3ce53722SRobert Mustacchi ddi_unbind_callback_t *); 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2707c478bd9Sstevel@tonic-gate } 2717c478bd9Sstevel@tonic-gate #endif 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate #endif /* _SYS_ESUNDDI_H */ 274