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 5144dfaa9Scth * Common Development and Distribution License (the "License"). 6144dfaa9Scth * 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 /* 22eae2e508Skrishnae * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_DDI_IMPLDEFS_H 277c478bd9Sstevel@tonic-gate #define _SYS_DDI_IMPLDEFS_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <sys/param.h> 317c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 327c478bd9Sstevel@tonic-gate #include <sys/ddipropdefs.h> 337c478bd9Sstevel@tonic-gate #include <sys/devops.h> 347c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 357c478bd9Sstevel@tonic-gate #include <sys/mutex.h> 367c478bd9Sstevel@tonic-gate #include <vm/page.h> 377c478bd9Sstevel@tonic-gate #include <sys/dacf_impl.h> 387c478bd9Sstevel@tonic-gate #include <sys/ndifm.h> 397c478bd9Sstevel@tonic-gate #include <sys/epm.h> 407c478bd9Sstevel@tonic-gate #include <sys/ddidmareq.h> 417c478bd9Sstevel@tonic-gate #include <sys/ddi_intr.h> 427c478bd9Sstevel@tonic-gate #include <sys/ddi_isa.h> 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #ifdef __cplusplus 457c478bd9Sstevel@tonic-gate extern "C" { 467c478bd9Sstevel@tonic-gate #endif 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate /* 497c478bd9Sstevel@tonic-gate * The device id implementation has been switched to be based on properties. 507c478bd9Sstevel@tonic-gate * For compatibility with di_devid libdevinfo interface the following 517c478bd9Sstevel@tonic-gate * must be defined: 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate #define DEVID_COMPATIBILITY ((ddi_devid_t)-1) 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * Definitions for node class. 577c478bd9Sstevel@tonic-gate * DDI_NC_PROM: a node with a nodeid that may be used in a promif call. 587c478bd9Sstevel@tonic-gate * DDI_NC_PSEUDO: a software created node with a software assigned nodeid. 597c478bd9Sstevel@tonic-gate */ 607c478bd9Sstevel@tonic-gate typedef enum { 617c478bd9Sstevel@tonic-gate DDI_NC_PROM = 0, 627c478bd9Sstevel@tonic-gate DDI_NC_PSEUDO 637c478bd9Sstevel@tonic-gate } ddi_node_class_t; 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate /* 667c478bd9Sstevel@tonic-gate * dev_info: The main device information structure this is intended to be 677c478bd9Sstevel@tonic-gate * opaque to drivers and drivers should use ddi functions to 687c478bd9Sstevel@tonic-gate * access *all* driver accessible fields. 697c478bd9Sstevel@tonic-gate * 707c478bd9Sstevel@tonic-gate * devi_parent_data includes property lists (interrupts, registers, etc.) 717c478bd9Sstevel@tonic-gate * devi_driver_data includes whatever the driver wants to place there. 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate struct devinfo_audit; 747c478bd9Sstevel@tonic-gate 75eae2e508Skrishnae typedef struct devi_port { 76eae2e508Skrishnae union { 77eae2e508Skrishnae struct { 78eae2e508Skrishnae uint32_t type; 79eae2e508Skrishnae uint32_t pad; 80eae2e508Skrishnae } port; 81eae2e508Skrishnae uint64_t type64; 82eae2e508Skrishnae } info; 83eae2e508Skrishnae void *priv_p; 84eae2e508Skrishnae } devi_port_t; 85eae2e508Skrishnae 86eae2e508Skrishnae typedef struct devi_bus_priv { 87eae2e508Skrishnae devi_port_t port_up; 88eae2e508Skrishnae devi_port_t port_down; 89eae2e508Skrishnae } devi_bus_priv_t; 90eae2e508Skrishnae 91*20906b23SVikram Hegde struct iommulib_unit; 92*20906b23SVikram Hegde typedef struct iommulib_unit *iommulib_handle_t; 93*20906b23SVikram Hegde 947c478bd9Sstevel@tonic-gate struct dev_info { 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate struct dev_info *devi_parent; /* my parent node in tree */ 977c478bd9Sstevel@tonic-gate struct dev_info *devi_child; /* my child list head */ 987c478bd9Sstevel@tonic-gate struct dev_info *devi_sibling; /* next element on my level */ 997c478bd9Sstevel@tonic-gate 100f4da9be0Scth char *devi_binding_name; /* name used to bind driver: */ 101f4da9be0Scth /* shared storage, points to */ 102f4da9be0Scth /* devi_node_name, devi_compat_names */ 103f4da9be0Scth /* or devi_rebinding_name */ 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate char *devi_addr; /* address part of name */ 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate int devi_nodeid; /* device nodeid */ 1087c478bd9Sstevel@tonic-gate int devi_instance; /* device instance number */ 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate struct dev_ops *devi_ops; /* driver operations */ 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate void *devi_parent_data; /* parent private data */ 1137c478bd9Sstevel@tonic-gate void *devi_driver_data; /* driver private data */ 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate ddi_prop_t *devi_drv_prop_ptr; /* head of driver prop list */ 1167c478bd9Sstevel@tonic-gate ddi_prop_t *devi_sys_prop_ptr; /* head of system prop list */ 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate struct ddi_minor_data *devi_minor; /* head of minor list */ 1197c478bd9Sstevel@tonic-gate struct dev_info *devi_next; /* Next instance of this device */ 1207c478bd9Sstevel@tonic-gate kmutex_t devi_lock; /* Protects per-devinfo data */ 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* logical parents for busop primitives */ 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate struct dev_info *devi_bus_map_fault; /* bus_map_fault parent */ 1257c478bd9Sstevel@tonic-gate struct dev_info *devi_bus_dma_map; /* bus_dma_map parent */ 1267c478bd9Sstevel@tonic-gate struct dev_info *devi_bus_dma_allochdl; /* bus_dma_newhdl parent */ 1277c478bd9Sstevel@tonic-gate struct dev_info *devi_bus_dma_freehdl; /* bus_dma_freehdl parent */ 1287c478bd9Sstevel@tonic-gate struct dev_info *devi_bus_dma_bindhdl; /* bus_dma_bindhdl parent */ 1297c478bd9Sstevel@tonic-gate struct dev_info *devi_bus_dma_unbindhdl; /* bus_dma_unbindhdl parent */ 1307c478bd9Sstevel@tonic-gate struct dev_info *devi_bus_dma_flush; /* bus_dma_flush parent */ 1317c478bd9Sstevel@tonic-gate struct dev_info *devi_bus_dma_win; /* bus_dma_win parent */ 1327c478bd9Sstevel@tonic-gate struct dev_info *devi_bus_dma_ctl; /* bus_dma_ctl parent */ 1337c478bd9Sstevel@tonic-gate struct dev_info *devi_bus_ctl; /* bus_ctl parent */ 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate ddi_prop_t *devi_hw_prop_ptr; /* head of hw prop list */ 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate char *devi_node_name; /* The 'name' of the node */ 1387c478bd9Sstevel@tonic-gate char *devi_compat_names; /* A list of driver names */ 1397c478bd9Sstevel@tonic-gate size_t devi_compat_length; /* Size of compat_names */ 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate int (*devi_bus_dma_bindfunc)(dev_info_t *, dev_info_t *, 1427c478bd9Sstevel@tonic-gate ddi_dma_handle_t, struct ddi_dma_req *, ddi_dma_cookie_t *, 1437c478bd9Sstevel@tonic-gate uint_t *); 1447c478bd9Sstevel@tonic-gate int (*devi_bus_dma_unbindfunc)(dev_info_t *, dev_info_t *, 1457c478bd9Sstevel@tonic-gate ddi_dma_handle_t); 1467c478bd9Sstevel@tonic-gate 147602ca9eaScth char *devi_devid_str; /* registered device id */ 148602ca9eaScth 1497c478bd9Sstevel@tonic-gate /* 1507c478bd9Sstevel@tonic-gate * power management entries 1517c478bd9Sstevel@tonic-gate * components exist even if the device is not currently power managed 1527c478bd9Sstevel@tonic-gate */ 1537c478bd9Sstevel@tonic-gate struct pm_info *devi_pm_info; /* 0 => dev not power managed */ 1547c478bd9Sstevel@tonic-gate uint_t devi_pm_flags; /* pm flags */ 1557c478bd9Sstevel@tonic-gate int devi_pm_num_components; /* number of components */ 1567c478bd9Sstevel@tonic-gate size_t devi_pm_comp_size; /* size of devi_components */ 1577c478bd9Sstevel@tonic-gate struct pm_component *devi_pm_components; /* array of pm components */ 1587c478bd9Sstevel@tonic-gate struct dev_info *devi_pm_ppm; /* ppm attached to this one */ 1597c478bd9Sstevel@tonic-gate void *devi_pm_ppm_private; /* for use by ppm driver */ 1607c478bd9Sstevel@tonic-gate int devi_pm_dev_thresh; /* "device" threshold */ 161f13856c4Scth uint_t devi_pm_kidsupcnt; /* # of kids powered up */ 1627c478bd9Sstevel@tonic-gate struct pm_scan *devi_pm_scan; /* pm scan info */ 1637c478bd9Sstevel@tonic-gate uint_t devi_pm_noinvolpm; /* # of descendents no-invol */ 1647c478bd9Sstevel@tonic-gate uint_t devi_pm_volpmd; /* # of voluntarily pm'ed */ 1657c478bd9Sstevel@tonic-gate kmutex_t devi_pm_lock; /* pm lock for state */ 1667c478bd9Sstevel@tonic-gate kmutex_t devi_pm_busy_lock; /* for component busy count */ 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate uint_t devi_state; /* device/bus state flags */ 1697c478bd9Sstevel@tonic-gate /* see below for definitions */ 1707c478bd9Sstevel@tonic-gate kcondvar_t devi_cv; /* cv */ 1717c478bd9Sstevel@tonic-gate int devi_ref; /* reference count */ 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate dacf_rsrvlist_t *devi_dacf_tasks; /* dacf reservation queue */ 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate ddi_node_class_t devi_node_class; /* Node class */ 1767c478bd9Sstevel@tonic-gate int devi_node_attributes; /* Node attributes: See below */ 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate char *devi_device_class; 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate /* 1817c478bd9Sstevel@tonic-gate * New mpxio kernel hooks entries 1827c478bd9Sstevel@tonic-gate */ 1837c478bd9Sstevel@tonic-gate int devi_mdi_component; /* mpxio component type */ 1847c478bd9Sstevel@tonic-gate void *devi_mdi_client; /* mpxio client information */ 1857c478bd9Sstevel@tonic-gate void *devi_mdi_xhci; /* vhci/phci info */ 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate ddi_prop_list_t *devi_global_prop_list; /* driver global properties */ 1887c478bd9Sstevel@tonic-gate major_t devi_major; /* driver major number */ 1897c478bd9Sstevel@tonic-gate ddi_node_state_t devi_node_state; /* state of node */ 1907c478bd9Sstevel@tonic-gate uint_t devi_flags; /* configuration flags */ 1917c478bd9Sstevel@tonic-gate int devi_circular; /* for recursive operations */ 1927c478bd9Sstevel@tonic-gate void *devi_busy_thread; /* thread operating on node */ 1937c478bd9Sstevel@tonic-gate void *devi_taskq; /* hotplug taskq */ 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate /* device driver statistical and audit info */ 1967c478bd9Sstevel@tonic-gate struct devinfo_audit *devi_audit; /* last state change */ 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate /* 1997c478bd9Sstevel@tonic-gate * FMA support for resource caches and error handlers 2007c478bd9Sstevel@tonic-gate */ 2017c478bd9Sstevel@tonic-gate struct i_ddi_fmhdl *devi_fmhdl; 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate uint_t devi_cpr_flags; 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate /* For interrupt support */ 2067c478bd9Sstevel@tonic-gate devinfo_intr_t *devi_intr_p; 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate void *devi_nex_pm; /* nexus PM private */ 209fe9fe9fbScth 210fe9fe9fbScth char *devi_addr_buf; /* buffer for devi_addr */ 211f4da9be0Scth 212f4da9be0Scth char *devi_rebinding_name; /* binding_name of rebind */ 213602ca9eaScth 21425e8c5aaSvikram /* For device contracts that have this dip's minor node as resource */ 21525e8c5aaSvikram kmutex_t devi_ct_lock; /* contract lock */ 21625e8c5aaSvikram kcondvar_t devi_ct_cv; /* contract cv */ 21725e8c5aaSvikram int devi_ct_count; /* # of outstanding responses */ 21825e8c5aaSvikram int devi_ct_neg; /* neg. occurred on dip */ 21925e8c5aaSvikram list_t devi_ct; 220eae2e508Skrishnae 221eae2e508Skrishnae /* owned by bus framework */ 222eae2e508Skrishnae devi_bus_priv_t devi_bus; /* bus private data */ 223b9ccdc5aScth 224b9ccdc5aScth /* Declarations of the pure dynamic properties to snapshot */ 225b9ccdc5aScth struct i_ddi_prop_dyn *devi_prop_dyn_driver; /* prop_op */ 226b9ccdc5aScth struct i_ddi_prop_dyn *devi_prop_dyn_parent; /* bus_prop_op */ 22786c1f4dcSVikram Hegde 22886c1f4dcSVikram Hegde /* For intel iommu support */ 22986c1f4dcSVikram Hegde void *devi_iommu_private; 230*20906b23SVikram Hegde 231*20906b23SVikram Hegde /* IOMMU handle */ 232*20906b23SVikram Hegde iommulib_handle_t devi_iommulib_handle; 2337c478bd9Sstevel@tonic-gate }; 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate #define DEVI(dev_info_type) ((struct dev_info *)(dev_info_type)) 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate /* 2387c478bd9Sstevel@tonic-gate * NB: The 'name' field, for compatibility with old code (both existing 2397c478bd9Sstevel@tonic-gate * device drivers and userland code), is now defined as the name used 2407c478bd9Sstevel@tonic-gate * to bind the node to a device driver, and not the device node name. 2417c478bd9Sstevel@tonic-gate * If the device node name does not define a binding to a device driver, 2427c478bd9Sstevel@tonic-gate * and the framework uses a different algorithm to create the binding to 2437c478bd9Sstevel@tonic-gate * the driver, the node name and binding name will be different. 2447c478bd9Sstevel@tonic-gate * 2457c478bd9Sstevel@tonic-gate * Note that this implies that the node name plus instance number does 2467c478bd9Sstevel@tonic-gate * NOT create a unique driver id; only the binding name plus instance 2477c478bd9Sstevel@tonic-gate * number creates a unique driver id. 2487c478bd9Sstevel@tonic-gate * 2497c478bd9Sstevel@tonic-gate * New code should not use 'devi_name'; use 'devi_binding_name' or 2507c478bd9Sstevel@tonic-gate * 'devi_node_name' and/or the routines that access those fields. 2517c478bd9Sstevel@tonic-gate */ 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate #define devi_name devi_binding_name 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate /* 2567c478bd9Sstevel@tonic-gate * DDI_CF1, DDI_CF2 and DDI_DRV_UNLOADED are obsolete. They are kept 2577c478bd9Sstevel@tonic-gate * around to allow legacy drivers to to compile. 2587c478bd9Sstevel@tonic-gate */ 2597c478bd9Sstevel@tonic-gate #define DDI_CF1(devi) (DEVI(devi)->devi_addr != NULL) 2607c478bd9Sstevel@tonic-gate #define DDI_CF2(devi) (DEVI(devi)->devi_ops != NULL) 2617c478bd9Sstevel@tonic-gate #define DDI_DRV_UNLOADED(devi) (DEVI(devi)->devi_ops == &mod_nodev_ops) 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate /* 26416747f41Scth * The device state flags (devi_state) contains information regarding 2657c478bd9Sstevel@tonic-gate * the state of the device (Online/Offline/Down). For bus nexus 2667c478bd9Sstevel@tonic-gate * devices, the device state also contains state information regarding 2677c478bd9Sstevel@tonic-gate * the state of the bus represented by this nexus node. 2687c478bd9Sstevel@tonic-gate * 2697c478bd9Sstevel@tonic-gate * Device state information is stored in bits [0-7], bus state in bits 2707c478bd9Sstevel@tonic-gate * [8-15]. 2717c478bd9Sstevel@tonic-gate * 272b9ccdc5aScth * NOTE: all devi_state updates should be protected by devi_lock. 2737c478bd9Sstevel@tonic-gate */ 2747c478bd9Sstevel@tonic-gate #define DEVI_DEVICE_OFFLINE 0x00000001 2757c478bd9Sstevel@tonic-gate #define DEVI_DEVICE_DOWN 0x00000002 2767c478bd9Sstevel@tonic-gate #define DEVI_DEVICE_DEGRADED 0x00000004 2777c478bd9Sstevel@tonic-gate #define DEVI_DEVICE_REMOVED 0x00000008 /* hardware removed */ 27816747f41Scth 2797c478bd9Sstevel@tonic-gate #define DEVI_BUS_QUIESCED 0x00000100 2807c478bd9Sstevel@tonic-gate #define DEVI_BUS_DOWN 0x00000200 2817c478bd9Sstevel@tonic-gate #define DEVI_NDI_CONFIG 0x00000400 /* perform config when attaching */ 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate #define DEVI_S_ATTACHING 0x00010000 2847c478bd9Sstevel@tonic-gate #define DEVI_S_DETACHING 0x00020000 2857c478bd9Sstevel@tonic-gate #define DEVI_S_ONLINING 0x00040000 2867c478bd9Sstevel@tonic-gate #define DEVI_S_OFFLINING 0x00080000 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate #define DEVI_S_INVOKING_DACF 0x00100000 /* busy invoking a dacf task */ 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate #define DEVI_S_UNBOUND 0x00200000 2917c478bd9Sstevel@tonic-gate #define DEVI_S_REPORT 0x08000000 /* report status change */ 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate #define DEVI_S_EVADD 0x10000000 /* state of devfs event */ 2947c478bd9Sstevel@tonic-gate #define DEVI_S_EVREMOVE 0x20000000 /* state of devfs event */ 2957c478bd9Sstevel@tonic-gate #define DEVI_S_NEED_RESET 0x40000000 /* devo_reset should be called */ 2967c478bd9Sstevel@tonic-gate 29716747f41Scth /* 29816747f41Scth * Device state macros. 29916747f41Scth * o All SET/CLR/DONE users must protect context with devi_lock. 30016747f41Scth * o DEVI_SET_DEVICE_ONLINE users must do his own DEVI_SET_REPORT. 30116747f41Scth * o DEVI_SET_DEVICE_{DOWN|DEGRADED|UP} should only be used when !OFFLINE. 30216747f41Scth * o DEVI_SET_DEVICE_UP clears DOWN and DEGRADED. 30316747f41Scth */ 3047c478bd9Sstevel@tonic-gate #define DEVI_IS_DEVICE_OFFLINE(dip) \ 30516747f41Scth ((DEVI(dip)->devi_state & DEVI_DEVICE_OFFLINE) == DEVI_DEVICE_OFFLINE) 3067c478bd9Sstevel@tonic-gate 30716747f41Scth #define DEVI_SET_DEVICE_ONLINE(dip) { \ 30816747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 30925e8c5aaSvikram if (DEVI(dip)->devi_state & DEVI_DEVICE_DEGRADED) { \ 31025e8c5aaSvikram mutex_exit(&DEVI(dip)->devi_lock); \ 31125e8c5aaSvikram e_ddi_undegrade_finalize(dip); \ 31225e8c5aaSvikram mutex_enter(&DEVI(dip)->devi_lock); \ 31325e8c5aaSvikram } \ 31416747f41Scth /* setting ONLINE clears DOWN, DEGRADED, OFFLINE */ \ 31516747f41Scth DEVI(dip)->devi_state &= ~(DEVI_DEVICE_DOWN | \ 31616747f41Scth DEVI_DEVICE_DEGRADED | DEVI_DEVICE_OFFLINE); \ 31716747f41Scth } 3187c478bd9Sstevel@tonic-gate 31916747f41Scth #define DEVI_SET_DEVICE_OFFLINE(dip) { \ 32016747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 32116747f41Scth DEVI(dip)->devi_state |= (DEVI_DEVICE_OFFLINE | DEVI_S_REPORT); \ 32216747f41Scth } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate #define DEVI_IS_DEVICE_DOWN(dip) \ 32516747f41Scth ((DEVI(dip)->devi_state & DEVI_DEVICE_DOWN) == DEVI_DEVICE_DOWN) 3267c478bd9Sstevel@tonic-gate 32716747f41Scth #define DEVI_SET_DEVICE_DOWN(dip) { \ 32816747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 32916747f41Scth ASSERT(!DEVI_IS_DEVICE_OFFLINE(dip)); \ 33016747f41Scth DEVI(dip)->devi_state |= (DEVI_DEVICE_DOWN | DEVI_S_REPORT); \ 33116747f41Scth } 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate #define DEVI_IS_DEVICE_DEGRADED(dip) \ 33416747f41Scth ((DEVI(dip)->devi_state & \ 33516747f41Scth (DEVI_DEVICE_DEGRADED|DEVI_DEVICE_DOWN)) == DEVI_DEVICE_DEGRADED) 3367c478bd9Sstevel@tonic-gate 33716747f41Scth #define DEVI_SET_DEVICE_DEGRADED(dip) { \ 33816747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 33916747f41Scth ASSERT(!DEVI_IS_DEVICE_OFFLINE(dip)); \ 34025e8c5aaSvikram mutex_exit(&DEVI(dip)->devi_lock); \ 34125e8c5aaSvikram e_ddi_degrade_finalize(dip); \ 34225e8c5aaSvikram mutex_enter(&DEVI(dip)->devi_lock); \ 34316747f41Scth DEVI(dip)->devi_state |= (DEVI_DEVICE_DEGRADED | DEVI_S_REPORT); \ 34416747f41Scth } 3457c478bd9Sstevel@tonic-gate 34616747f41Scth #define DEVI_SET_DEVICE_UP(dip) { \ 34716747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 34816747f41Scth ASSERT(!DEVI_IS_DEVICE_OFFLINE(dip)); \ 34925e8c5aaSvikram if (DEVI(dip)->devi_state & DEVI_DEVICE_DEGRADED) { \ 35025e8c5aaSvikram mutex_exit(&DEVI(dip)->devi_lock); \ 35125e8c5aaSvikram e_ddi_undegrade_finalize(dip); \ 35225e8c5aaSvikram mutex_enter(&DEVI(dip)->devi_lock); \ 35325e8c5aaSvikram } \ 35416747f41Scth DEVI(dip)->devi_state &= ~(DEVI_DEVICE_DEGRADED | DEVI_DEVICE_DOWN); \ 35516747f41Scth DEVI(dip)->devi_state |= DEVI_S_REPORT; \ 35616747f41Scth } 3577c478bd9Sstevel@tonic-gate 35816747f41Scth /* Device removal and insertion */ 3597c478bd9Sstevel@tonic-gate #define DEVI_IS_DEVICE_REMOVED(dip) \ 36016747f41Scth ((DEVI(dip)->devi_state & DEVI_DEVICE_REMOVED) == DEVI_DEVICE_REMOVED) 3617c478bd9Sstevel@tonic-gate 36216747f41Scth #define DEVI_SET_DEVICE_REMOVED(dip) { \ 36316747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 36416747f41Scth DEVI(dip)->devi_state |= DEVI_DEVICE_REMOVED; \ 36516747f41Scth } 3667c478bd9Sstevel@tonic-gate 36716747f41Scth #define DEVI_SET_DEVICE_REINSERTED(dip) { \ 36816747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 36916747f41Scth DEVI(dip)->devi_state &= ~DEVI_DEVICE_REMOVED; \ 37016747f41Scth } 3717c478bd9Sstevel@tonic-gate 37216747f41Scth /* Bus state change macros */ 3737c478bd9Sstevel@tonic-gate #define DEVI_IS_BUS_QUIESCED(dip) \ 37416747f41Scth ((DEVI(dip)->devi_state & DEVI_BUS_QUIESCED) == DEVI_BUS_QUIESCED) 3757c478bd9Sstevel@tonic-gate 37616747f41Scth #define DEVI_SET_BUS_ACTIVE(dip) { \ 37716747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 37816747f41Scth DEVI(dip)->devi_state &= ~DEVI_BUS_QUIESCED; \ 37916747f41Scth DEVI(dip)->devi_state |= DEVI_S_REPORT; \ 38016747f41Scth } 3817c478bd9Sstevel@tonic-gate 38216747f41Scth #define DEVI_SET_BUS_QUIESCE(dip) { \ 38316747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 38416747f41Scth DEVI(dip)->devi_state |= (DEVI_BUS_QUIESCED | DEVI_S_REPORT); \ 38516747f41Scth } 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate #define DEVI_IS_BUS_DOWN(dip) \ 38816747f41Scth ((DEVI(dip)->devi_state & DEVI_BUS_DOWN) == DEVI_BUS_DOWN) 3897c478bd9Sstevel@tonic-gate 39016747f41Scth #define DEVI_SET_BUS_UP(dip) { \ 39116747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 39216747f41Scth DEVI(dip)->devi_state &= ~DEVI_BUS_DOWN; \ 39316747f41Scth DEVI(dip)->devi_state |= DEVI_S_REPORT; \ 39416747f41Scth } 3957c478bd9Sstevel@tonic-gate 39616747f41Scth #define DEVI_SET_BUS_DOWN(dip) { \ 39716747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 39816747f41Scth DEVI(dip)->devi_state |= (DEVI_BUS_DOWN | DEVI_S_REPORT); \ 39916747f41Scth } 4007c478bd9Sstevel@tonic-gate 40116747f41Scth /* Status change report needed */ 4027c478bd9Sstevel@tonic-gate #define DEVI_NEED_REPORT(dip) \ 40316747f41Scth ((DEVI(dip)->devi_state & DEVI_S_REPORT) == DEVI_S_REPORT) 4047c478bd9Sstevel@tonic-gate 40516747f41Scth #define DEVI_SET_REPORT(dip) { \ 40616747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 40716747f41Scth DEVI(dip)->devi_state |= DEVI_S_REPORT; \ 40816747f41Scth } 4097c478bd9Sstevel@tonic-gate 41016747f41Scth #define DEVI_REPORT_DONE(dip) { \ 41116747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 41216747f41Scth DEVI(dip)->devi_state &= ~DEVI_S_REPORT; \ 41316747f41Scth } 41416747f41Scth 41516747f41Scth /* Do an NDI_CONFIG for its children */ 4167c478bd9Sstevel@tonic-gate #define DEVI_NEED_NDI_CONFIG(dip) \ 41716747f41Scth ((DEVI(dip)->devi_state & DEVI_NDI_CONFIG) == DEVI_NDI_CONFIG) 4187c478bd9Sstevel@tonic-gate 41916747f41Scth #define DEVI_SET_NDI_CONFIG(dip) { \ 42016747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 42116747f41Scth DEVI(dip)->devi_state |= DEVI_NDI_CONFIG; \ 42216747f41Scth } 4237c478bd9Sstevel@tonic-gate 42416747f41Scth #define DEVI_CLR_NDI_CONFIG(dip) { \ 42516747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 42616747f41Scth DEVI(dip)->devi_state &= ~DEVI_NDI_CONFIG; \ 42716747f41Scth } 4287c478bd9Sstevel@tonic-gate 42916747f41Scth /* Attaching or detaching state */ 4307c478bd9Sstevel@tonic-gate #define DEVI_IS_ATTACHING(dip) \ 43116747f41Scth ((DEVI(dip)->devi_state & DEVI_S_ATTACHING) == DEVI_S_ATTACHING) 4327c478bd9Sstevel@tonic-gate 43316747f41Scth #define DEVI_SET_ATTACHING(dip) { \ 43416747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 43516747f41Scth DEVI(dip)->devi_state |= DEVI_S_ATTACHING; \ 43616747f41Scth } 4377c478bd9Sstevel@tonic-gate 43816747f41Scth #define DEVI_CLR_ATTACHING(dip) { \ 43916747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 44016747f41Scth DEVI(dip)->devi_state &= ~DEVI_S_ATTACHING; \ 44116747f41Scth } 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate #define DEVI_IS_DETACHING(dip) \ 44416747f41Scth ((DEVI(dip)->devi_state & DEVI_S_DETACHING) == DEVI_S_DETACHING) 4457c478bd9Sstevel@tonic-gate 44616747f41Scth #define DEVI_SET_DETACHING(dip) { \ 44716747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 44816747f41Scth DEVI(dip)->devi_state |= DEVI_S_DETACHING; \ 44916747f41Scth } 4507c478bd9Sstevel@tonic-gate 45116747f41Scth #define DEVI_CLR_DETACHING(dip) { \ 45216747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 45316747f41Scth DEVI(dip)->devi_state &= ~DEVI_S_DETACHING; \ 45416747f41Scth } 4557c478bd9Sstevel@tonic-gate 45616747f41Scth /* Onlining or offlining state */ 4577c478bd9Sstevel@tonic-gate #define DEVI_IS_ONLINING(dip) \ 45816747f41Scth ((DEVI(dip)->devi_state & DEVI_S_ONLINING) == DEVI_S_ONLINING) 4597c478bd9Sstevel@tonic-gate 46016747f41Scth #define DEVI_SET_ONLINING(dip) { \ 46116747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 46216747f41Scth DEVI(dip)->devi_state |= DEVI_S_ONLINING; \ 46316747f41Scth } 4647c478bd9Sstevel@tonic-gate 46516747f41Scth #define DEVI_CLR_ONLINING(dip) { \ 46616747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 46716747f41Scth DEVI(dip)->devi_state &= ~DEVI_S_ONLINING; \ 46816747f41Scth } 4697c478bd9Sstevel@tonic-gate 4707c478bd9Sstevel@tonic-gate #define DEVI_IS_OFFLINING(dip) \ 47116747f41Scth ((DEVI(dip)->devi_state & DEVI_S_OFFLINING) == DEVI_S_OFFLINING) 47216747f41Scth 47316747f41Scth #define DEVI_SET_OFFLINING(dip) { \ 47416747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 47516747f41Scth DEVI(dip)->devi_state |= DEVI_S_OFFLINING; \ 47616747f41Scth } 47716747f41Scth 47816747f41Scth #define DEVI_CLR_OFFLINING(dip) { \ 47916747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 48016747f41Scth DEVI(dip)->devi_state &= ~DEVI_S_OFFLINING; \ 48116747f41Scth } 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate #define DEVI_IS_IN_RECONFIG(dip) \ 48416747f41Scth (DEVI(dip)->devi_state & (DEVI_S_OFFLINING | DEVI_S_ONLINING)) 4857c478bd9Sstevel@tonic-gate 48616747f41Scth /* Busy invoking a dacf task against this node */ 4877c478bd9Sstevel@tonic-gate #define DEVI_IS_INVOKING_DACF(dip) \ 48816747f41Scth ((DEVI(dip)->devi_state & DEVI_S_INVOKING_DACF) == DEVI_S_INVOKING_DACF) 4897c478bd9Sstevel@tonic-gate 49016747f41Scth #define DEVI_SET_INVOKING_DACF(dip) { \ 49116747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 49216747f41Scth DEVI(dip)->devi_state |= DEVI_S_INVOKING_DACF; \ 49316747f41Scth } 4947c478bd9Sstevel@tonic-gate 49516747f41Scth #define DEVI_CLR_INVOKING_DACF(dip) { \ 49616747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 49716747f41Scth DEVI(dip)->devi_state &= ~DEVI_S_INVOKING_DACF; \ 49816747f41Scth } 4997c478bd9Sstevel@tonic-gate 50016747f41Scth /* Events for add/remove */ 5017c478bd9Sstevel@tonic-gate #define DEVI_EVADD(dip) \ 50216747f41Scth ((DEVI(dip)->devi_state & DEVI_S_EVADD) == DEVI_S_EVADD) 50316747f41Scth 50416747f41Scth #define DEVI_SET_EVADD(dip) { \ 50516747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 50616747f41Scth DEVI(dip)->devi_state &= ~DEVI_S_EVREMOVE; \ 50716747f41Scth DEVI(dip)->devi_state |= DEVI_S_EVADD; \ 50816747f41Scth } 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate #define DEVI_EVREMOVE(dip) \ 51116747f41Scth ((DEVI(dip)->devi_state & DEVI_S_EVREMOVE) == DEVI_S_EVREMOVE) 5127c478bd9Sstevel@tonic-gate 51316747f41Scth #define DEVI_SET_EVREMOVE(dip) { \ 51416747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 51516747f41Scth DEVI(dip)->devi_state &= ~DEVI_S_EVADD; \ 51616747f41Scth DEVI(dip)->devi_state |= DEVI_S_EVREMOVE; \ 51716747f41Scth } 51816747f41Scth 51916747f41Scth #define DEVI_SET_EVUNINIT(dip) { \ 52016747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 52116747f41Scth DEVI(dip)->devi_state &= ~(DEVI_S_EVADD | DEVI_S_EVREMOVE); \ 52216747f41Scth } 52316747f41Scth 52416747f41Scth /* Need to call the devo_reset entry point for this device at shutdown */ 5257c478bd9Sstevel@tonic-gate #define DEVI_NEED_RESET(dip) \ 52616747f41Scth ((DEVI(dip)->devi_state & DEVI_S_NEED_RESET) == DEVI_S_NEED_RESET) 5277c478bd9Sstevel@tonic-gate 52816747f41Scth #define DEVI_SET_NEED_RESET(dip) { \ 52916747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 53016747f41Scth DEVI(dip)->devi_state |= DEVI_S_NEED_RESET; \ 53116747f41Scth } 5327c478bd9Sstevel@tonic-gate 53316747f41Scth #define DEVI_CLR_NEED_RESET(dip) { \ 53416747f41Scth ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \ 53516747f41Scth DEVI(dip)->devi_state &= ~DEVI_S_NEED_RESET; \ 53616747f41Scth } 5377c478bd9Sstevel@tonic-gate 53816747f41Scth /* 53916747f41Scth * devi_flags bits 54016747f41Scth * 541b9ccdc5aScth * NOTE: all devi_state updates should be protected by devi_lock. 54216747f41Scth */ 54316747f41Scth #define DEVI_BUSY 0x00000001 /* busy configuring children */ 54416747f41Scth #define DEVI_MADE_CHILDREN 0x00000002 /* children made from specs */ 54516747f41Scth #define DEVI_ATTACHED_CHILDREN 0x00000004 /* attached all existing children */ 54616747f41Scth #define DEVI_BRANCH_HELD 0x00000008 /* branch rooted at this dip held */ 54716747f41Scth #define DEVI_NO_BIND 0x00000010 /* prevent driver binding */ 54816747f41Scth #define DEVI_REGISTERED_DEVID 0x00000020 /* device registered a devid */ 5495e3986cbScth #define DEVI_PHCI_SIGNALS_VHCI 0x00000040 /* pHCI ndi_devi_exit signals vHCI */ 550f4da9be0Scth #define DEVI_REBIND 0x00000080 /* post initchild driver rebind */ 55125e8c5aaSvikram #define DEVI_RETIRED 0x00000100 /* device is retired */ 55225e8c5aaSvikram #define DEVI_RETIRING 0x00000200 /* being evaluated for retire */ 55325e8c5aaSvikram #define DEVI_R_CONSTRAINT 0x00000400 /* constraints have been applied */ 55425e8c5aaSvikram #define DEVI_R_BLOCKED 0x00000800 /* constraints block retire */ 55525e8c5aaSvikram #define DEVI_CT_NOP 0x00001000 /* NOP contract event occurred */ 55616747f41Scth 55716747f41Scth #define DEVI_BUSY_CHANGING(dip) (DEVI(dip)->devi_flags & DEVI_BUSY) 55816747f41Scth #define DEVI_BUSY_OWNED(dip) (DEVI_BUSY_CHANGING(dip) && \ 55916747f41Scth ((DEVI(dip))->devi_busy_thread == curthread)) 56016747f41Scth 5617c478bd9Sstevel@tonic-gate char *i_ddi_devi_class(dev_info_t *); 5627c478bd9Sstevel@tonic-gate int i_ddi_set_devi_class(dev_info_t *, char *, int); 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate /* 5657c478bd9Sstevel@tonic-gate * This structure represents one piece of bus space occupied by a given 5667c478bd9Sstevel@tonic-gate * device. It is used in an array for devices with multiple address windows. 5677c478bd9Sstevel@tonic-gate */ 5687c478bd9Sstevel@tonic-gate struct regspec { 5697c478bd9Sstevel@tonic-gate uint_t regspec_bustype; /* cookie for bus type it's on */ 5707c478bd9Sstevel@tonic-gate uint_t regspec_addr; /* address of reg relative to bus */ 5717c478bd9Sstevel@tonic-gate uint_t regspec_size; /* size of this register set */ 5727c478bd9Sstevel@tonic-gate }; 5737c478bd9Sstevel@tonic-gate 5747c478bd9Sstevel@tonic-gate /* 5757c478bd9Sstevel@tonic-gate * This structure represents one piece of nexus bus space. 5767c478bd9Sstevel@tonic-gate * It is used in an array for nexi with multiple bus spaces 5777c478bd9Sstevel@tonic-gate * to define the childs offsets in the parents bus space. 5787c478bd9Sstevel@tonic-gate */ 5797c478bd9Sstevel@tonic-gate struct rangespec { 5807c478bd9Sstevel@tonic-gate uint_t rng_cbustype; /* Child's address, hi order */ 5817c478bd9Sstevel@tonic-gate uint_t rng_coffset; /* Child's address, lo order */ 5827c478bd9Sstevel@tonic-gate uint_t rng_bustype; /* Parent's address, hi order */ 5837c478bd9Sstevel@tonic-gate uint_t rng_offset; /* Parent's address, lo order */ 5847c478bd9Sstevel@tonic-gate uint_t rng_size; /* size of space for this entry */ 5857c478bd9Sstevel@tonic-gate }; 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate #ifdef _KERNEL 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate typedef enum { 5907c478bd9Sstevel@tonic-gate DDI_PRE = 0, 5917c478bd9Sstevel@tonic-gate DDI_POST = 1 5927c478bd9Sstevel@tonic-gate } ddi_pre_post_t; 5937c478bd9Sstevel@tonic-gate 5947c478bd9Sstevel@tonic-gate /* 5957c478bd9Sstevel@tonic-gate * This structure represents notification of a child attach event 5967c478bd9Sstevel@tonic-gate * These could both be the same if attach/detach commands were in the 5977c478bd9Sstevel@tonic-gate * same name space. 5987c478bd9Sstevel@tonic-gate * Note that the target dip is passed as an arg already. 5997c478bd9Sstevel@tonic-gate */ 6007c478bd9Sstevel@tonic-gate struct attachspec { 6017c478bd9Sstevel@tonic-gate ddi_attach_cmd_t cmd; /* type of event */ 6027c478bd9Sstevel@tonic-gate ddi_pre_post_t when; /* one of DDI_PRE or DDI_POST */ 6037c478bd9Sstevel@tonic-gate dev_info_t *pdip; /* parent of attaching node */ 6047c478bd9Sstevel@tonic-gate int result; /* result of attach op (post command only) */ 6057c478bd9Sstevel@tonic-gate }; 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate /* 6087c478bd9Sstevel@tonic-gate * This structure represents notification of a child detach event 6097c478bd9Sstevel@tonic-gate * Note that the target dip is passed as an arg already. 6107c478bd9Sstevel@tonic-gate */ 6117c478bd9Sstevel@tonic-gate struct detachspec { 6127c478bd9Sstevel@tonic-gate ddi_detach_cmd_t cmd; /* type of event */ 6137c478bd9Sstevel@tonic-gate ddi_pre_post_t when; /* one of DDI_PRE or DDI_POST */ 6147c478bd9Sstevel@tonic-gate dev_info_t *pdip; /* parent of detaching node */ 6157c478bd9Sstevel@tonic-gate int result; /* result of detach op (post command only) */ 6167c478bd9Sstevel@tonic-gate }; 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate typedef enum { 6217c478bd9Sstevel@tonic-gate DDM_MINOR = 0, 6227c478bd9Sstevel@tonic-gate DDM_ALIAS, 6237c478bd9Sstevel@tonic-gate DDM_DEFAULT, 6247c478bd9Sstevel@tonic-gate DDM_INTERNAL_PATH 6257c478bd9Sstevel@tonic-gate } ddi_minor_type; 6267c478bd9Sstevel@tonic-gate 6277c478bd9Sstevel@tonic-gate /* implementation flags for driver specified device access control */ 6287c478bd9Sstevel@tonic-gate #define DM_NO_FSPERM 0x1 6297c478bd9Sstevel@tonic-gate 6307c478bd9Sstevel@tonic-gate struct devplcy; 6317c478bd9Sstevel@tonic-gate 6327c478bd9Sstevel@tonic-gate struct ddi_minor { 6337c478bd9Sstevel@tonic-gate char *name; /* name of node */ 6347c478bd9Sstevel@tonic-gate dev_t dev; /* device number */ 6357c478bd9Sstevel@tonic-gate int spec_type; /* block or char */ 6367c478bd9Sstevel@tonic-gate int flags; /* access flags */ 6377c478bd9Sstevel@tonic-gate char *node_type; /* block, byte, serial, network */ 6387c478bd9Sstevel@tonic-gate struct devplcy *node_priv; /* privilege for this minor */ 6397c478bd9Sstevel@tonic-gate mode_t priv_mode; /* default apparent privilege mode */ 6407c478bd9Sstevel@tonic-gate }; 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate /* 6437c478bd9Sstevel@tonic-gate * devi_node_attributes contains node attributes private to the 6447c478bd9Sstevel@tonic-gate * ddi implementation. As a consumer, do not use these bit definitions 6457c478bd9Sstevel@tonic-gate * directly, use the ndi functions that check for the existence of the 6467c478bd9Sstevel@tonic-gate * specific node attributes. 6477c478bd9Sstevel@tonic-gate * 6487c478bd9Sstevel@tonic-gate * DDI_PERSISTENT indicates a 'persistent' node; one that is not 6497c478bd9Sstevel@tonic-gate * automatically freed by the framework if the driver is unloaded 6507c478bd9Sstevel@tonic-gate * or the driver fails to attach to this node. 6517c478bd9Sstevel@tonic-gate * 6527c478bd9Sstevel@tonic-gate * DDI_AUTO_ASSIGNED_NODEID indicates that the nodeid was auto-assigned 6537c478bd9Sstevel@tonic-gate * by the framework and should be auto-freed if the node is removed. 6547c478bd9Sstevel@tonic-gate * 6557c478bd9Sstevel@tonic-gate * DDI_VHCI_NODE indicates that the node type is VHCI. This flag 6567c478bd9Sstevel@tonic-gate * must be set by ndi_devi_config_vhci() routine only. 6577c478bd9Sstevel@tonic-gate */ 6587c478bd9Sstevel@tonic-gate #define DDI_PERSISTENT 0x01 6597c478bd9Sstevel@tonic-gate #define DDI_AUTO_ASSIGNED_NODEID 0x02 6607c478bd9Sstevel@tonic-gate #define DDI_VHCI_NODE 0x04 6617c478bd9Sstevel@tonic-gate 66216747f41Scth #define DEVI_VHCI_NODE(dip) \ 66316747f41Scth (DEVI(dip)->devi_node_attributes & DDI_VHCI_NODE) 66416747f41Scth 6657c478bd9Sstevel@tonic-gate /* 6667c478bd9Sstevel@tonic-gate * The ddi_minor_data structure gets filled in by ddi_create_minor_node. 6677c478bd9Sstevel@tonic-gate * It then gets attached to the devinfo node as a property. 6687c478bd9Sstevel@tonic-gate */ 6697c478bd9Sstevel@tonic-gate struct ddi_minor_data { 6707c478bd9Sstevel@tonic-gate struct ddi_minor_data *next; /* next one in the chain */ 6717c478bd9Sstevel@tonic-gate dev_info_t *dip; /* pointer to devinfo node */ 6727c478bd9Sstevel@tonic-gate ddi_minor_type type; /* Following data type */ 6737c478bd9Sstevel@tonic-gate struct ddi_minor d_minor; /* Actual minor node data */ 6747c478bd9Sstevel@tonic-gate }; 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate #define ddm_name d_minor.name 6777c478bd9Sstevel@tonic-gate #define ddm_dev d_minor.dev 6787c478bd9Sstevel@tonic-gate #define ddm_flags d_minor.flags 6797c478bd9Sstevel@tonic-gate #define ddm_spec_type d_minor.spec_type 6807c478bd9Sstevel@tonic-gate #define ddm_node_type d_minor.node_type 6817c478bd9Sstevel@tonic-gate #define ddm_node_priv d_minor.node_priv 6827c478bd9Sstevel@tonic-gate #define ddm_priv_mode d_minor.priv_mode 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate /* 6857c478bd9Sstevel@tonic-gate * parent private data structure contains register, interrupt, property 6867c478bd9Sstevel@tonic-gate * and range information. 6877c478bd9Sstevel@tonic-gate */ 6887c478bd9Sstevel@tonic-gate struct ddi_parent_private_data { 6897c478bd9Sstevel@tonic-gate int par_nreg; /* number of regs */ 6907c478bd9Sstevel@tonic-gate struct regspec *par_reg; /* array of regs */ 6917c478bd9Sstevel@tonic-gate int par_nintr; /* number of interrupts */ 6927c478bd9Sstevel@tonic-gate struct intrspec *par_intr; /* array of possible interrupts */ 6937c478bd9Sstevel@tonic-gate int par_nrng; /* number of ranges */ 6947c478bd9Sstevel@tonic-gate struct rangespec *par_rng; /* array of ranges */ 6957c478bd9Sstevel@tonic-gate }; 6967c478bd9Sstevel@tonic-gate #define DEVI_PD(d) \ 6977c478bd9Sstevel@tonic-gate ((struct ddi_parent_private_data *)DEVI((d))->devi_parent_data) 6987c478bd9Sstevel@tonic-gate 6997c478bd9Sstevel@tonic-gate #define sparc_pd_getnreg(dev) (DEVI_PD(dev)->par_nreg) 7007c478bd9Sstevel@tonic-gate #define sparc_pd_getnintr(dev) (DEVI_PD(dev)->par_nintr) 7017c478bd9Sstevel@tonic-gate #define sparc_pd_getnrng(dev) (DEVI_PD(dev)->par_nrng) 7027c478bd9Sstevel@tonic-gate #define sparc_pd_getreg(dev, n) (&DEVI_PD(dev)->par_reg[(n)]) 7037c478bd9Sstevel@tonic-gate #define sparc_pd_getintr(dev, n) (&DEVI_PD(dev)->par_intr[(n)]) 7047c478bd9Sstevel@tonic-gate #define sparc_pd_getrng(dev, n) (&DEVI_PD(dev)->par_rng[(n)]) 7057c478bd9Sstevel@tonic-gate 7067c478bd9Sstevel@tonic-gate /* 7077c478bd9Sstevel@tonic-gate * This data structure is entirely private to the soft state allocator. 7087c478bd9Sstevel@tonic-gate */ 7097c478bd9Sstevel@tonic-gate struct i_ddi_soft_state { 7107c478bd9Sstevel@tonic-gate void **array; /* the array of pointers */ 7117c478bd9Sstevel@tonic-gate kmutex_t lock; /* serialize access to this struct */ 7127c478bd9Sstevel@tonic-gate size_t size; /* how many bytes per state struct */ 7137c478bd9Sstevel@tonic-gate size_t n_items; /* how many structs herein */ 7147c478bd9Sstevel@tonic-gate struct i_ddi_soft_state *next; /* 'dirty' elements */ 7157c478bd9Sstevel@tonic-gate }; 7167c478bd9Sstevel@tonic-gate 7177c478bd9Sstevel@tonic-gate /* 7187c478bd9Sstevel@tonic-gate * Solaris DDI DMA implementation structure and function definitions. 7197c478bd9Sstevel@tonic-gate * 7207c478bd9Sstevel@tonic-gate * Note: no callers of DDI functions must depend upon data structures 7217c478bd9Sstevel@tonic-gate * declared below. They are not guaranteed to remain constant. 7227c478bd9Sstevel@tonic-gate */ 7237c478bd9Sstevel@tonic-gate 7247c478bd9Sstevel@tonic-gate /* 7257c478bd9Sstevel@tonic-gate * Implementation DMA mapping structure. 7267c478bd9Sstevel@tonic-gate * 7277c478bd9Sstevel@tonic-gate * The publicly visible ddi_dma_req structure is filled 7287c478bd9Sstevel@tonic-gate * in by a caller that wishes to map a memory object 7297c478bd9Sstevel@tonic-gate * for DMA. Internal to this implementation of the public 7307c478bd9Sstevel@tonic-gate * DDI DMA functions this request structure is put together 7317c478bd9Sstevel@tonic-gate * with bus nexus specific functions that have additional 7327c478bd9Sstevel@tonic-gate * information and constraints as to how to go about doing 7337c478bd9Sstevel@tonic-gate * the requested mapping function 7347c478bd9Sstevel@tonic-gate * 7357c478bd9Sstevel@tonic-gate * In this implementation, some of the information from the 7367c478bd9Sstevel@tonic-gate * original requester is retained throughout the lifetime 7377c478bd9Sstevel@tonic-gate * of the I/O mapping being active. 7387c478bd9Sstevel@tonic-gate */ 7397c478bd9Sstevel@tonic-gate 7407c478bd9Sstevel@tonic-gate /* 7417c478bd9Sstevel@tonic-gate * This is the implementation specific description 7427c478bd9Sstevel@tonic-gate * of how we've mapped an object for DMA. 7437c478bd9Sstevel@tonic-gate */ 7447c478bd9Sstevel@tonic-gate #if defined(__sparc) 7457c478bd9Sstevel@tonic-gate typedef struct ddi_dma_impl { 7467c478bd9Sstevel@tonic-gate /* 7477c478bd9Sstevel@tonic-gate * DMA mapping information 7487c478bd9Sstevel@tonic-gate */ 7497c478bd9Sstevel@tonic-gate ulong_t dmai_mapping; /* mapping cookie */ 7507c478bd9Sstevel@tonic-gate 7517c478bd9Sstevel@tonic-gate /* 7527c478bd9Sstevel@tonic-gate * Size of the current mapping, in bytes. 7537c478bd9Sstevel@tonic-gate * 7547c478bd9Sstevel@tonic-gate * Note that this is distinct from the size of the object being mapped 7557c478bd9Sstevel@tonic-gate * for DVMA. We might have only a portion of the object mapped at any 7567c478bd9Sstevel@tonic-gate * given point in time. 7577c478bd9Sstevel@tonic-gate */ 7587c478bd9Sstevel@tonic-gate uint_t dmai_size; 7597c478bd9Sstevel@tonic-gate 7607c478bd9Sstevel@tonic-gate /* 7617c478bd9Sstevel@tonic-gate * Offset, in bytes, into object that is currently mapped. 7627c478bd9Sstevel@tonic-gate */ 7637c478bd9Sstevel@tonic-gate off_t dmai_offset; 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate /* 7667c478bd9Sstevel@tonic-gate * Information gathered from the original DMA mapping 7677c478bd9Sstevel@tonic-gate * request and saved for the lifetime of the mapping. 7687c478bd9Sstevel@tonic-gate */ 7697c478bd9Sstevel@tonic-gate uint_t dmai_minxfer; 7707c478bd9Sstevel@tonic-gate uint_t dmai_burstsizes; 7717c478bd9Sstevel@tonic-gate uint_t dmai_ndvmapages; 7727c478bd9Sstevel@tonic-gate uint_t dmai_pool; /* cached DVMA space */ 7737c478bd9Sstevel@tonic-gate uint_t dmai_rflags; /* requester's flags + ours */ 7747c478bd9Sstevel@tonic-gate uint_t dmai_inuse; /* active handle? */ 7757c478bd9Sstevel@tonic-gate uint_t dmai_nwin; 7767c478bd9Sstevel@tonic-gate uint_t dmai_winsize; 7777c478bd9Sstevel@tonic-gate caddr_t dmai_nexus_private; 7787c478bd9Sstevel@tonic-gate void *dmai_iopte; 7797c478bd9Sstevel@tonic-gate uint_t *dmai_sbi; 7807c478bd9Sstevel@tonic-gate void *dmai_minfo; /* random mapping information */ 7817c478bd9Sstevel@tonic-gate dev_info_t *dmai_rdip; /* original requester's dev_info_t */ 7827c478bd9Sstevel@tonic-gate ddi_dma_obj_t dmai_object; /* requester's object */ 7837c478bd9Sstevel@tonic-gate ddi_dma_attr_t dmai_attr; /* DMA attributes */ 7847c478bd9Sstevel@tonic-gate ddi_dma_cookie_t *dmai_cookie; /* pointer to first DMA cookie */ 7857c478bd9Sstevel@tonic-gate 7867c478bd9Sstevel@tonic-gate int (*dmai_fault_check)(struct ddi_dma_impl *handle); 7877c478bd9Sstevel@tonic-gate void (*dmai_fault_notify)(struct ddi_dma_impl *handle); 7887c478bd9Sstevel@tonic-gate int dmai_fault; 7897c478bd9Sstevel@tonic-gate ndi_err_t dmai_error; 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate } ddi_dma_impl_t; 7927c478bd9Sstevel@tonic-gate 7937c478bd9Sstevel@tonic-gate #elif defined(__x86) 7947c478bd9Sstevel@tonic-gate 79512f080e7Smrj /* 79612f080e7Smrj * ddi_dma_impl portion that genunix (sunddi.c) depends on. x86 rootnex 79712f080e7Smrj * implementation specific state is in dmai_private. 79812f080e7Smrj */ 7997c478bd9Sstevel@tonic-gate typedef struct ddi_dma_impl { 80012f080e7Smrj ddi_dma_cookie_t *dmai_cookie; /* array of DMA cookies */ 80112f080e7Smrj void *dmai_private; 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate /* 8047c478bd9Sstevel@tonic-gate * Information gathered from the original dma mapping 8057c478bd9Sstevel@tonic-gate * request and saved for the lifetime of the mapping. 8067c478bd9Sstevel@tonic-gate */ 8077c478bd9Sstevel@tonic-gate uint_t dmai_minxfer; 8087c478bd9Sstevel@tonic-gate uint_t dmai_burstsizes; 8097c478bd9Sstevel@tonic-gate uint_t dmai_rflags; /* requester's flags + ours */ 8107c478bd9Sstevel@tonic-gate int dmai_nwin; 8117c478bd9Sstevel@tonic-gate dev_info_t *dmai_rdip; /* original requester's dev_info_t */ 8127c478bd9Sstevel@tonic-gate 8137c478bd9Sstevel@tonic-gate ddi_dma_attr_t dmai_attr; /* DMA attributes */ 8147c478bd9Sstevel@tonic-gate 8157c478bd9Sstevel@tonic-gate int (*dmai_fault_check)(struct ddi_dma_impl *handle); 8167c478bd9Sstevel@tonic-gate void (*dmai_fault_notify)(struct ddi_dma_impl *handle); 8177c478bd9Sstevel@tonic-gate int dmai_fault; 8187c478bd9Sstevel@tonic-gate ndi_err_t dmai_error; 8197c478bd9Sstevel@tonic-gate } ddi_dma_impl_t; 8207c478bd9Sstevel@tonic-gate 8217c478bd9Sstevel@tonic-gate #else 8227c478bd9Sstevel@tonic-gate #error "struct ddi_dma_impl not defined for this architecture" 8237c478bd9Sstevel@tonic-gate #endif /* defined(__sparc) */ 8247c478bd9Sstevel@tonic-gate 8257c478bd9Sstevel@tonic-gate /* 8267c478bd9Sstevel@tonic-gate * For now DMA segments share state with the DMA handle 8277c478bd9Sstevel@tonic-gate */ 8287c478bd9Sstevel@tonic-gate typedef ddi_dma_impl_t ddi_dma_seg_impl_t; 8297c478bd9Sstevel@tonic-gate 8307c478bd9Sstevel@tonic-gate /* 8317c478bd9Sstevel@tonic-gate * These flags use reserved bits from the dma request flags. 8327c478bd9Sstevel@tonic-gate * 8337c478bd9Sstevel@tonic-gate * A note about the DMP_NOSYNC flags: the root nexus will 8347c478bd9Sstevel@tonic-gate * set these as it sees best. If an intermediate nexus 8357c478bd9Sstevel@tonic-gate * actually needs these operations, then during the unwind 8367c478bd9Sstevel@tonic-gate * from the call to ddi_dma_bind, the nexus driver *must* 8377c478bd9Sstevel@tonic-gate * clear the appropriate flag(s). This is because, as an 8387c478bd9Sstevel@tonic-gate * optimization, ddi_dma_sync(9F) looks at these flags before 8397c478bd9Sstevel@tonic-gate * deciding to spend the time going back up the tree. 8407c478bd9Sstevel@tonic-gate */ 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate #define _DMCM1 DDI_DMA_RDWR|DDI_DMA_REDZONE|DDI_DMA_PARTIAL 8437c478bd9Sstevel@tonic-gate #define _DMCM2 DDI_DMA_CONSISTENT|DMP_VMEREQ 8447c478bd9Sstevel@tonic-gate #define DMP_DDIFLAGS (_DMCM1|_DMCM2) 8457c478bd9Sstevel@tonic-gate #define DMP_SHADOW 0x20 8467c478bd9Sstevel@tonic-gate #define DMP_LKIOPB 0x40 8477c478bd9Sstevel@tonic-gate #define DMP_LKSYSV 0x80 8487c478bd9Sstevel@tonic-gate #define DMP_IOCACHE 0x100 8497c478bd9Sstevel@tonic-gate #define DMP_USEHAT 0x200 8507c478bd9Sstevel@tonic-gate #define DMP_PHYSADDR 0x400 8517c478bd9Sstevel@tonic-gate #define DMP_INVALID 0x800 8527c478bd9Sstevel@tonic-gate #define DMP_NOLIMIT 0x1000 8537c478bd9Sstevel@tonic-gate #define DMP_VMEREQ 0x10000000 8547c478bd9Sstevel@tonic-gate #define DMP_BYPASSNEXUS 0x20000000 8557c478bd9Sstevel@tonic-gate #define DMP_NODEVSYNC 0x40000000 8567c478bd9Sstevel@tonic-gate #define DMP_NOCPUSYNC 0x80000000 8577c478bd9Sstevel@tonic-gate #define DMP_NOSYNC (DMP_NODEVSYNC|DMP_NOCPUSYNC) 8587c478bd9Sstevel@tonic-gate 8597c478bd9Sstevel@tonic-gate /* 8607c478bd9Sstevel@tonic-gate * In order to complete a device to device mapping that 8617c478bd9Sstevel@tonic-gate * has percolated as high as an IU nexus (gone that high 8627c478bd9Sstevel@tonic-gate * because the DMA request is a VADDR type), we define 8637c478bd9Sstevel@tonic-gate * structure to use with the DDI_CTLOPS_DMAPMAPC request 8647c478bd9Sstevel@tonic-gate * that re-traverses the request tree to finish the 8657c478bd9Sstevel@tonic-gate * DMA 'mapping' for a device. 8667c478bd9Sstevel@tonic-gate */ 8677c478bd9Sstevel@tonic-gate struct dma_phys_mapc { 8687c478bd9Sstevel@tonic-gate struct ddi_dma_req *dma_req; /* original request */ 8697c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp; /* current handle, or none */ 8707c478bd9Sstevel@tonic-gate int nptes; /* number of ptes */ 8717c478bd9Sstevel@tonic-gate void *ptes; /* ptes already read */ 8727c478bd9Sstevel@tonic-gate }; 8737c478bd9Sstevel@tonic-gate 8747c478bd9Sstevel@tonic-gate #define MAXCALLBACK 20 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate /* 8777c478bd9Sstevel@tonic-gate * Callback definitions 8787c478bd9Sstevel@tonic-gate */ 8797c478bd9Sstevel@tonic-gate struct ddi_callback { 8807c478bd9Sstevel@tonic-gate struct ddi_callback *c_nfree; 8817c478bd9Sstevel@tonic-gate struct ddi_callback *c_nlist; 8827c478bd9Sstevel@tonic-gate int (*c_call)(); 8837c478bd9Sstevel@tonic-gate int c_count; 8847c478bd9Sstevel@tonic-gate caddr_t c_arg; 8857c478bd9Sstevel@tonic-gate size_t c_size; 8867c478bd9Sstevel@tonic-gate }; 8877c478bd9Sstevel@tonic-gate 888b9ccdc5aScth /* 889b9ccdc5aScth * Pure dynamic property declaration. A pure dynamic property is a property 890b9ccdc5aScth * for which a driver's prop_op(9E) implementation will return a value on 891b9ccdc5aScth * demand, but the property name does not exist on a property list (global, 892b9ccdc5aScth * driver, system, or hardware) - the person asking for the value must know 893b9ccdc5aScth * the name and type information. 894b9ccdc5aScth * 895b9ccdc5aScth * For a pure dynamic property to show up in a di_init() devinfo shapshot, the 896b9ccdc5aScth * devinfo driver must know name and type. The i_ddi_prop_dyn_t mechanism 897b9ccdc5aScth * allows a driver to define an array of the name/type information of its 898b9ccdc5aScth * dynamic properties. When a driver declares its dynamic properties in a 899b9ccdc5aScth * i_ddi_prop_dyn_t array, and registers that array using 900b9ccdc5aScth * i_ddi_prop_dyn_driver_set() the devinfo driver has sufficient information 901b9ccdc5aScth * to represent the properties in a snapshot - calling the driver's 902b9ccdc5aScth * prop_op(9E) to obtain values. 903b9ccdc5aScth * 904b9ccdc5aScth * The last element of a i_ddi_prop_dyn_t is detected via a NULL dp_name value. 905b9ccdc5aScth * 906b9ccdc5aScth * A pure dynamic property name associated with a minor_node/dev_t should be 907b9ccdc5aScth * defined with a dp_spec_type of S_IFCHR or S_IFBLK, as appropriate. The 908b9ccdc5aScth * driver's prop_op(9E) entry point will be called for all 909b9ccdc5aScth * ddi_create_minor_node(9F) nodes of the specified spec_type. For a driver 910b9ccdc5aScth * where not all minor_node/dev_t combinations support the same named 911b9ccdc5aScth * properties, it is the responsibility of the prop_op(9E) implementation to 912b9ccdc5aScth * sort out what combinations are appropriate. 913b9ccdc5aScth * 914b9ccdc5aScth * A pure dynamic property of a devinfo node should be defined with a 915b9ccdc5aScth * dp_spec_type of 0. 916b9ccdc5aScth * 917b9ccdc5aScth * NB: Public DDI property interfaces no longer support pure dynamic 918b9ccdc5aScth * properties, but they are still still used. A prime example is the cmlb 919b9ccdc5aScth * implementation of size(9P) properties. Using pure dynamic properties 920b9ccdc5aScth * reduces the space required to maintain per-partition information. Since 921b9ccdc5aScth * there are no public interfaces to create pure dynamic properties, 922b9ccdc5aScth * the i_ddi_prop_dyn_t mechanism should remain private. 923b9ccdc5aScth */ 924b9ccdc5aScth typedef struct i_ddi_prop_dyn { 925b9ccdc5aScth char *dp_name; /* name of dynamic property */ 926b9ccdc5aScth int dp_type; /* DDI_PROP_TYPE_ of property */ 927b9ccdc5aScth int dp_spec_type; /* 0, S_IFCHR, S_IFBLK */ 928b9ccdc5aScth } i_ddi_prop_dyn_t; 929b9ccdc5aScth void i_ddi_prop_dyn_driver_set(dev_info_t *, 930b9ccdc5aScth i_ddi_prop_dyn_t *); 931b9ccdc5aScth i_ddi_prop_dyn_t *i_ddi_prop_dyn_driver_get(dev_info_t *); 932b9ccdc5aScth void i_ddi_prop_dyn_parent_set(dev_info_t *, 933b9ccdc5aScth i_ddi_prop_dyn_t *); 934b9ccdc5aScth i_ddi_prop_dyn_t *i_ddi_prop_dyn_parent_get(dev_info_t *); 935b9ccdc5aScth void i_ddi_prop_dyn_cache_invalidate(dev_info_t *, 936b9ccdc5aScth i_ddi_prop_dyn_t *); 9377c478bd9Sstevel@tonic-gate 9387c478bd9Sstevel@tonic-gate /* 9397c478bd9Sstevel@tonic-gate * Device id - Internal definition. 9407c478bd9Sstevel@tonic-gate */ 9417c478bd9Sstevel@tonic-gate #define DEVID_MAGIC_MSB 0x69 9427c478bd9Sstevel@tonic-gate #define DEVID_MAGIC_LSB 0x64 9437c478bd9Sstevel@tonic-gate #define DEVID_REV_MSB 0x00 9447c478bd9Sstevel@tonic-gate #define DEVID_REV_LSB 0x01 9457c478bd9Sstevel@tonic-gate #define DEVID_HINT_SIZE 4 9467c478bd9Sstevel@tonic-gate 9477c478bd9Sstevel@tonic-gate typedef struct impl_devid { 9487c478bd9Sstevel@tonic-gate uchar_t did_magic_hi; /* device id magic # (msb) */ 9497c478bd9Sstevel@tonic-gate uchar_t did_magic_lo; /* device id magic # (lsb) */ 9507c478bd9Sstevel@tonic-gate uchar_t did_rev_hi; /* device id revision # (msb) */ 9517c478bd9Sstevel@tonic-gate uchar_t did_rev_lo; /* device id revision # (lsb) */ 9527c478bd9Sstevel@tonic-gate uchar_t did_type_hi; /* device id type (msb) */ 9537c478bd9Sstevel@tonic-gate uchar_t did_type_lo; /* device id type (lsb) */ 9547c478bd9Sstevel@tonic-gate uchar_t did_len_hi; /* length of devid data (msb) */ 9557c478bd9Sstevel@tonic-gate uchar_t did_len_lo; /* length of devid data (lsb) */ 9567c478bd9Sstevel@tonic-gate char did_driver[DEVID_HINT_SIZE]; /* driver name - HINT */ 9577c478bd9Sstevel@tonic-gate char did_id[1]; /* start of device id data */ 9587c478bd9Sstevel@tonic-gate } impl_devid_t; 9597c478bd9Sstevel@tonic-gate 9607c478bd9Sstevel@tonic-gate #define DEVID_GETTYPE(devid) ((ushort_t) \ 9617c478bd9Sstevel@tonic-gate (((devid)->did_type_hi << NBBY) + \ 9627c478bd9Sstevel@tonic-gate (devid)->did_type_lo)) 9637c478bd9Sstevel@tonic-gate 9647c478bd9Sstevel@tonic-gate #define DEVID_FORMTYPE(devid, type) (devid)->did_type_hi = hibyte((type)); \ 9657c478bd9Sstevel@tonic-gate (devid)->did_type_lo = lobyte((type)); 9667c478bd9Sstevel@tonic-gate 9677c478bd9Sstevel@tonic-gate #define DEVID_GETLEN(devid) ((ushort_t) \ 9687c478bd9Sstevel@tonic-gate (((devid)->did_len_hi << NBBY) + \ 9697c478bd9Sstevel@tonic-gate (devid)->did_len_lo)) 9707c478bd9Sstevel@tonic-gate 9717c478bd9Sstevel@tonic-gate #define DEVID_FORMLEN(devid, len) (devid)->did_len_hi = hibyte((len)); \ 9727c478bd9Sstevel@tonic-gate (devid)->did_len_lo = lobyte((len)); 9737c478bd9Sstevel@tonic-gate 9747c478bd9Sstevel@tonic-gate /* 9757c478bd9Sstevel@tonic-gate * Per PSARC/1995/352, a binary devid contains fields for <magic number>, 9767c478bd9Sstevel@tonic-gate * <revision>, <driver_hint>, <type>, <id_length>, and the <id> itself. 9777c478bd9Sstevel@tonic-gate * This proposal would encode the binary devid into a string consisting 9787c478bd9Sstevel@tonic-gate * of "<magic><revision>,<driver_hint>@<type><id>" as indicated below 9797c478bd9Sstevel@tonic-gate * (<id_length> is rederived from the length of the string 9807c478bd9Sstevel@tonic-gate * representation of the <id>): 9817c478bd9Sstevel@tonic-gate * 9827c478bd9Sstevel@tonic-gate * <magic> ->"id" 9837c478bd9Sstevel@tonic-gate * 9847c478bd9Sstevel@tonic-gate * <rev> ->"%d" // "0" -> type of DEVID_NONE "id0" 9857c478bd9Sstevel@tonic-gate * // NOTE: PSARC/1995/352 <revision> is "1". 9867c478bd9Sstevel@tonic-gate * // NOTE: support limited to 10 revisions 9877c478bd9Sstevel@tonic-gate * // in current implementation 9887c478bd9Sstevel@tonic-gate * 9897c478bd9Sstevel@tonic-gate * <driver_hint> ->"%s" // "sd"/"ssd" 9907c478bd9Sstevel@tonic-gate * // NOTE: driver names limited to 4 9917c478bd9Sstevel@tonic-gate * // characters for <revision> "1" 9927c478bd9Sstevel@tonic-gate * 9937c478bd9Sstevel@tonic-gate * <type> ->'w' | // DEVID_SCSI3_WWN <hex_id> 9947c478bd9Sstevel@tonic-gate * 'W' | // DEVID_SCSI3_WWN <ascii_id> 9957c478bd9Sstevel@tonic-gate * 't' | // DEVID_SCSI3_VPD_T10 <hex_id> 9967c478bd9Sstevel@tonic-gate * 'T' | // DEVID_SCSI3_VPD_T10 <ascii_id> 9977c478bd9Sstevel@tonic-gate * 'x' | // DEVID_SCSI3_VPD_EUI <hex_id> 9987c478bd9Sstevel@tonic-gate * 'X' | // DEVID_SCSI3_VPD_EUI <ascii_id> 9997c478bd9Sstevel@tonic-gate * 'n' | // DEVID_SCSI3_VPD_NAA <hex_id> 10007c478bd9Sstevel@tonic-gate * 'N' | // DEVID_SCSI3_VPD_NAA <ascii_id> 10017c478bd9Sstevel@tonic-gate * 's' | // DEVID_SCSI_SERIAL <hex_id> 10027c478bd9Sstevel@tonic-gate * 'S' | // DEVID_SCSI_SERIAL <ascii_id> 10037c478bd9Sstevel@tonic-gate * 'f' | // DEVID_FAB <hex_id> 10047c478bd9Sstevel@tonic-gate * 'F' | // DEVID_FAB <ascii_id> 10057c478bd9Sstevel@tonic-gate * 'e' | // DEVID_ENCAP <hex_id> 10067c478bd9Sstevel@tonic-gate * 'E' | // DEVID_ENCAP <ascii_id> 10077c478bd9Sstevel@tonic-gate * 'a' | // DEVID_ATA_SERIAL <hex_id> 10087c478bd9Sstevel@tonic-gate * 'A' | // DEVID_ATA_SERIAL <ascii_id> 10097c478bd9Sstevel@tonic-gate * 'u' | // unknown <hex_id> 10107c478bd9Sstevel@tonic-gate * 'U' // unknown <ascii_id> 10117c478bd9Sstevel@tonic-gate * // NOTE: lower case -> <hex_id> 10127c478bd9Sstevel@tonic-gate * // upper case -> <ascii_id> 10137c478bd9Sstevel@tonic-gate * // NOTE: this covers all types currently 10147c478bd9Sstevel@tonic-gate * // defined for <revision> 1. 10157c478bd9Sstevel@tonic-gate * // NOTE: a <type> can be added 10167c478bd9Sstevel@tonic-gate * // without changing the <revision>. 10177c478bd9Sstevel@tonic-gate * 10187c478bd9Sstevel@tonic-gate * <id> -> <ascii_id> | // <type> is upper case 10197c478bd9Sstevel@tonic-gate * <hex_id> // <type> is lower case 10207c478bd9Sstevel@tonic-gate * 10217c478bd9Sstevel@tonic-gate * <ascii_id> // only if all bytes of binary <id> field 10227c478bd9Sstevel@tonic-gate * // are in the set: 10237c478bd9Sstevel@tonic-gate * // [A-Z][a-z][0-9]+-.= and space and 0x00 10247c478bd9Sstevel@tonic-gate * // the encoded form is: 10257c478bd9Sstevel@tonic-gate * // [A-Z][a-z][0-9]+-.= and _ and ~ 10267c478bd9Sstevel@tonic-gate * // NOTE: ' ' <=> '_', 0x00 <=> '~' 10277c478bd9Sstevel@tonic-gate * // these sets are chosen to avoid shell 10287c478bd9Sstevel@tonic-gate * // and conflicts with DDI node names. 10297c478bd9Sstevel@tonic-gate * 10307c478bd9Sstevel@tonic-gate * <hex_id> // if not <ascii_id>; each byte of binary 10317c478bd9Sstevel@tonic-gate * // <id> maps a to 2 digit ascii hex 10327c478bd9Sstevel@tonic-gate * // representation in the string. 10337c478bd9Sstevel@tonic-gate * 10347c478bd9Sstevel@tonic-gate * This encoding provides a meaningful correlation between the /devices 10357c478bd9Sstevel@tonic-gate * path and the devid string where possible. 10367c478bd9Sstevel@tonic-gate * 10377c478bd9Sstevel@tonic-gate * Fibre: 10387c478bd9Sstevel@tonic-gate * sbus@6,0/SUNW,socal@d,10000/sf@1,0/ssd@w21000020370bb488,0:c,raw 10397c478bd9Sstevel@tonic-gate * id1,ssd@w20000020370bb488:c,raw 10407c478bd9Sstevel@tonic-gate * 10417c478bd9Sstevel@tonic-gate * Copper: 10427c478bd9Sstevel@tonic-gate * sbus@7,0/SUNW,fas@3,8800000/sd@a,0:c 10437c478bd9Sstevel@tonic-gate * id1,sd@SIBM_____1XY210__________:c 10447c478bd9Sstevel@tonic-gate */ 10457c478bd9Sstevel@tonic-gate /* determine if a byte of an id meets ASCII representation requirements */ 10467c478bd9Sstevel@tonic-gate #define DEVID_IDBYTE_ISASCII(b) ( \ 10477c478bd9Sstevel@tonic-gate (((b) >= 'a') && ((b) <= 'z')) || \ 10487c478bd9Sstevel@tonic-gate (((b) >= 'A') && ((b) <= 'Z')) || \ 10497c478bd9Sstevel@tonic-gate (((b) >= '0') && ((b) <= '9')) || \ 10507c478bd9Sstevel@tonic-gate (b == '+') || (b == '-') || (b == '.') || (b == '=') || \ 10517c478bd9Sstevel@tonic-gate (b == ' ') || (b == 0x00)) 10527c478bd9Sstevel@tonic-gate 10537c478bd9Sstevel@tonic-gate /* set type to lower case to indicate that the did_id field is ascii */ 10547c478bd9Sstevel@tonic-gate #define DEVID_TYPE_SETASCII(c) (c - 0x20) /* 'a' -> 'A' */ 10557c478bd9Sstevel@tonic-gate 10567c478bd9Sstevel@tonic-gate /* determine from type if did_id field is binary or ascii */ 10577c478bd9Sstevel@tonic-gate #define DEVID_TYPE_ISASCII(c) (((c) >= 'A') && ((c) <= 'Z')) 10587c478bd9Sstevel@tonic-gate 10597c478bd9Sstevel@tonic-gate /* convert type field from binary to ascii */ 10607c478bd9Sstevel@tonic-gate #define DEVID_TYPE_BINTOASCII(b) ( \ 10617c478bd9Sstevel@tonic-gate ((b) == DEVID_SCSI3_WWN) ? 'w' : \ 10627c478bd9Sstevel@tonic-gate ((b) == DEVID_SCSI3_VPD_T10) ? 't' : \ 10637c478bd9Sstevel@tonic-gate ((b) == DEVID_SCSI3_VPD_EUI) ? 'x' : \ 10647c478bd9Sstevel@tonic-gate ((b) == DEVID_SCSI3_VPD_NAA) ? 'n' : \ 10657c478bd9Sstevel@tonic-gate ((b) == DEVID_SCSI_SERIAL) ? 's' : \ 10667c478bd9Sstevel@tonic-gate ((b) == DEVID_FAB) ? 'f' : \ 10677c478bd9Sstevel@tonic-gate ((b) == DEVID_ENCAP) ? 'e' : \ 10687c478bd9Sstevel@tonic-gate ((b) == DEVID_ATA_SERIAL) ? 'a' : \ 10697c478bd9Sstevel@tonic-gate 'u') /* unknown */ 10707c478bd9Sstevel@tonic-gate 10717c478bd9Sstevel@tonic-gate /* convert type field from ascii to binary */ 10727c478bd9Sstevel@tonic-gate #define DEVID_TYPE_ASCIITOBIN(c) ( \ 10737c478bd9Sstevel@tonic-gate (((c) == 'w') || ((c) == 'W')) ? DEVID_SCSI3_WWN : \ 10747c478bd9Sstevel@tonic-gate (((c) == 't') || ((c) == 'T')) ? DEVID_SCSI3_VPD_T10 : \ 10757c478bd9Sstevel@tonic-gate (((c) == 'x') || ((c) == 'X')) ? DEVID_SCSI3_VPD_EUI : \ 10767c478bd9Sstevel@tonic-gate (((c) == 'n') || ((c) == 'N')) ? DEVID_SCSI3_VPD_NAA : \ 10777c478bd9Sstevel@tonic-gate (((c) == 's') || ((c) == 'S')) ? DEVID_SCSI_SERIAL : \ 10787c478bd9Sstevel@tonic-gate (((c) == 'f') || ((c) == 'F')) ? DEVID_FAB : \ 10797c478bd9Sstevel@tonic-gate (((c) == 'e') || ((c) == 'E')) ? DEVID_ENCAP : \ 10807c478bd9Sstevel@tonic-gate (((c) == 'a') || ((c) == 'A')) ? DEVID_ATA_SERIAL : \ 10817c478bd9Sstevel@tonic-gate DEVID_MAXTYPE +1) /* unknown */ 10827c478bd9Sstevel@tonic-gate 10837c478bd9Sstevel@tonic-gate /* determine if the type should be forced to hex encoding (non-ascii) */ 10847c478bd9Sstevel@tonic-gate #define DEVID_TYPE_BIN_FORCEHEX(b) ( \ 10857c478bd9Sstevel@tonic-gate ((b) == DEVID_SCSI3_WWN) || \ 10867c478bd9Sstevel@tonic-gate ((b) == DEVID_SCSI3_VPD_EUI) || \ 10877c478bd9Sstevel@tonic-gate ((b) == DEVID_SCSI3_VPD_NAA) || \ 10887c478bd9Sstevel@tonic-gate ((b) == DEVID_FAB)) 10897c478bd9Sstevel@tonic-gate 10907c478bd9Sstevel@tonic-gate /* determine if the type is from a scsi3 vpd */ 10917c478bd9Sstevel@tonic-gate #define IS_DEVID_SCSI3_VPD_TYPE(b) ( \ 10927c478bd9Sstevel@tonic-gate ((b) == DEVID_SCSI3_VPD_T10) || \ 10937c478bd9Sstevel@tonic-gate ((b) == DEVID_SCSI3_VPD_EUI) || \ 10947c478bd9Sstevel@tonic-gate ((b) == DEVID_SCSI3_VPD_NAA)) 10957c478bd9Sstevel@tonic-gate 10967c478bd9Sstevel@tonic-gate /* convert rev field from binary to ascii (only supports 10 revs) */ 10977c478bd9Sstevel@tonic-gate #define DEVID_REV_BINTOASCII(b) (b + '0') 10987c478bd9Sstevel@tonic-gate 10997c478bd9Sstevel@tonic-gate /* convert rev field from ascii to binary (only supports 10 revs) */ 11007c478bd9Sstevel@tonic-gate #define DEVID_REV_ASCIITOBIN(c) (c - '0') 11017c478bd9Sstevel@tonic-gate 11027c478bd9Sstevel@tonic-gate /* name of devid property */ 11037c478bd9Sstevel@tonic-gate #define DEVID_PROP_NAME "devid" 11047c478bd9Sstevel@tonic-gate 11057c478bd9Sstevel@tonic-gate /* 11067c478bd9Sstevel@tonic-gate * prop_name used by pci_{save,restore}_config_regs() 11077c478bd9Sstevel@tonic-gate */ 11087c478bd9Sstevel@tonic-gate #define SAVED_CONFIG_REGS "pci-config-regs" 11097c478bd9Sstevel@tonic-gate #define SAVED_CONFIG_REGS_MASK "pcie-config-regs-mask" 11107c478bd9Sstevel@tonic-gate #define SAVED_CONFIG_REGS_CAPINFO "pci-cap-info" 11117c478bd9Sstevel@tonic-gate 11127c478bd9Sstevel@tonic-gate typedef struct pci_config_header_state { 11137c478bd9Sstevel@tonic-gate uint16_t chs_command; 11147c478bd9Sstevel@tonic-gate uint8_t chs_cache_line_size; 11157c478bd9Sstevel@tonic-gate uint8_t chs_latency_timer; 11167c478bd9Sstevel@tonic-gate uint8_t chs_header_type; 11177c478bd9Sstevel@tonic-gate uint8_t chs_sec_latency_timer; 11187c478bd9Sstevel@tonic-gate uint8_t chs_bridge_control; 11197c478bd9Sstevel@tonic-gate uint32_t chs_base0; 11207c478bd9Sstevel@tonic-gate uint32_t chs_base1; 11217c478bd9Sstevel@tonic-gate uint32_t chs_base2; 11227c478bd9Sstevel@tonic-gate uint32_t chs_base3; 11237c478bd9Sstevel@tonic-gate uint32_t chs_base4; 11247c478bd9Sstevel@tonic-gate uint32_t chs_base5; 11257c478bd9Sstevel@tonic-gate } pci_config_header_state_t; 11267c478bd9Sstevel@tonic-gate 11277c478bd9Sstevel@tonic-gate #ifdef _KERNEL 11287c478bd9Sstevel@tonic-gate 11297c478bd9Sstevel@tonic-gate typedef struct pci_cap_save_desc { 11307c478bd9Sstevel@tonic-gate uint16_t cap_offset; 11317c478bd9Sstevel@tonic-gate uint16_t cap_id; 11327c478bd9Sstevel@tonic-gate uint32_t cap_nregs; 11337c478bd9Sstevel@tonic-gate } pci_cap_save_desc_t; 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate typedef struct pci_cap_entry { 11367c478bd9Sstevel@tonic-gate uint16_t cap_id; 11377c478bd9Sstevel@tonic-gate uint32_t cap_ndwords; 11387c478bd9Sstevel@tonic-gate uint32_t (*cap_save_func)(ddi_acc_handle_t confhdl, uint16_t cap_ptr, 11397c478bd9Sstevel@tonic-gate uint32_t *regbuf, uint32_t ndwords); 11407c478bd9Sstevel@tonic-gate } pci_cap_entry_t; 11417c478bd9Sstevel@tonic-gate 11427c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 11437c478bd9Sstevel@tonic-gate 11447c478bd9Sstevel@tonic-gate #ifdef __cplusplus 11457c478bd9Sstevel@tonic-gate } 11467c478bd9Sstevel@tonic-gate #endif 11477c478bd9Sstevel@tonic-gate 11487c478bd9Sstevel@tonic-gate #endif /* _SYS_DDI_IMPLDEFS_H */ 1149