1*27255037Spjha /* 2*27255037Spjha * CDDL HEADER START 3*27255037Spjha * 4*27255037Spjha * The contents of this file are subject to the terms of the 5*27255037Spjha * Common Development and Distribution License (the "License"). 6*27255037Spjha * You may not use this file except in compliance with the License. 7*27255037Spjha * 8*27255037Spjha * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*27255037Spjha * or http://www.opensolaris.org/os/licensing. 10*27255037Spjha * See the License for the specific language governing permissions 11*27255037Spjha * and limitations under the License. 12*27255037Spjha * 13*27255037Spjha * When distributing Covered Code, include this CDDL HEADER in each 14*27255037Spjha * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*27255037Spjha * If applicable, add the following below this CDDL HEADER, with the 16*27255037Spjha * fields enclosed by brackets "[]" replaced with your own identifying 17*27255037Spjha * information: Portions Copyright [yyyy] [name of copyright owner] 18*27255037Spjha * 19*27255037Spjha * CDDL HEADER END 20*27255037Spjha */ 21*27255037Spjha /* 22*27255037Spjha * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*27255037Spjha * Use is subject to license terms. 24*27255037Spjha */ 25*27255037Spjha 26*27255037Spjha #ifndef _SYS_PCI_CAP_H 27*27255037Spjha #define _SYS_PCI_CAP_H 28*27255037Spjha 29*27255037Spjha #pragma ident "%Z%%M% %I% %E% SMI" 30*27255037Spjha 31*27255037Spjha #ifdef __cplusplus 32*27255037Spjha extern "C" { 33*27255037Spjha #endif 34*27255037Spjha 35*27255037Spjha #define PCI_CAP_XCFG_FLAG_SHIFT 31 36*27255037Spjha #define PCI_CAP_XCFG_FLAG (1u << PCI_CAP_XCFG_FLAG_SHIFT) 37*27255037Spjha 38*27255037Spjha /* Function Prototypes */ 39*27255037Spjha int pci_xcap_locate(ddi_acc_handle_t h, uint16_t id, uint16_t *base_p); 40*27255037Spjha int pci_lcap_locate(ddi_acc_handle_t h, uint8_t id, uint16_t *base_p); 41*27255037Spjha 42*27255037Spjha 43*27255037Spjha /* Extract the lower 16 bits Extended CFG SPACE */ 44*27255037Spjha #define PCI_CAP_XID_MASK 0xffff 45*27255037Spjha 46*27255037Spjha /* Extract the lower 8 bits Extended CFG SPACE */ 47*27255037Spjha #define PCI_CAP_ID_MASK 0xff 48*27255037Spjha 49*27255037Spjha #define PCI_CAP_XCFG_SPC(i) ((i) ? (i) | PCI_CAP_XCFG_FLAG : 0) 50*27255037Spjha 51*27255037Spjha #ifdef DEBUG 52*27255037Spjha #define PCI_CAP_DBG if (pci_cap_debug) printf 53*27255037Spjha #else 54*27255037Spjha #define PCI_CAP_DBG _NOTE(CONSTANTCONDITION) if (0) printf 55*27255037Spjha #endif /* DEBUG */ 56*27255037Spjha 57*27255037Spjha /* 58*27255037Spjha * Supported Config Size Reads/Writes 59*27255037Spjha */ 60*27255037Spjha 61*27255037Spjha typedef enum { 62*27255037Spjha PCI_CAP_CFGSZ_8 = 0, 63*27255037Spjha PCI_CAP_CFGSZ_16 = 1, 64*27255037Spjha PCI_CAP_CFGSZ_32 = 2 65*27255037Spjha } pci_config_size_t; 66*27255037Spjha 67*27255037Spjha /* Define Macros */ 68*27255037Spjha 69*27255037Spjha #define PCI_CAP_LOCATE(h, id, base_p) ((id) & PCI_CAP_XCFG_FLAG ? \ 70*27255037Spjha pci_xcap_locate(h, (uint16_t)((id) & PCI_CAP_XID_MASK), base_p) : \ 71*27255037Spjha pci_lcap_locate(h, (uint8_t)((id) & PCI_CAP_ID_MASK), base_p)) 72*27255037Spjha 73*27255037Spjha #define PCI_CAP_GET8(h, i, b, o) ((uint8_t) \ 74*27255037Spjha pci_cap_get(h, PCI_CAP_CFGSZ_8, i, b, o)) 75*27255037Spjha #define PCI_CAP_GET16(h, i, b, o) ((uint16_t) \ 76*27255037Spjha pci_cap_get(h, PCI_CAP_CFGSZ_16, i, b, o)) 77*27255037Spjha #define PCI_CAP_GET32(h, i, b, o) ((uint32_t) \ 78*27255037Spjha pci_cap_get(h, PCI_CAP_CFGSZ_32, i, b, o)) 79*27255037Spjha 80*27255037Spjha #define PCI_CAP_PUT8(h, i, b, o, d) ((uint8_t) \ 81*27255037Spjha pci_cap_put(h, PCI_CAP_CFGSZ_8, i, b, o, d)) 82*27255037Spjha #define PCI_CAP_PUT16(h, i, b, o, d) ((uint16_t) \ 83*27255037Spjha pci_cap_put(h, PCI_CAP_CFGSZ_16, i, b, o, d)) 84*27255037Spjha #define PCI_CAP_PUT32(h, i, b, o, d) ((uint32_t) \ 85*27255037Spjha pci_cap_put(h, PCI_CAP_CFGSZ_32, i, b, o, d)) 86*27255037Spjha 87*27255037Spjha #define PCI_XCAP_GET8(h, i, b, o) ((uint8_t) \ 88*27255037Spjha pci_cap_get(h, PCI_CAP_CFGSZ_8, PCI_CAP_XCFG_SPC(i), b, o)) 89*27255037Spjha #define PCI_XCAP_GET16(h, i, b, o) ((uint16_t) \ 90*27255037Spjha pci_cap_get(h, PCI_CAP_CFGSZ_16, PCI_CAP_XCFG_SPC(i), b, o)) 91*27255037Spjha #define PCI_XCAP_GET32(h, i, b, o) ((uint32_t) \ 92*27255037Spjha pci_cap_get(h, PCI_CAP_CFGSZ_32, PCI_CAP_XCFG_SPC(i), b, o)) 93*27255037Spjha 94*27255037Spjha #define PCI_XCAP_PUT8(h, i, b, o, d) ((uint8_t) \ 95*27255037Spjha pci_cap_put(h, PCI_CAP_CFGSZ_8, PCI_CAP_XCFG_SPC(i), b, o, d)) 96*27255037Spjha #define PCI_XCAP_PUT16(h, i, b, o, d) ((uint16_t) \ 97*27255037Spjha pci_cap_put(h, PCI_CAP_CFGSZ_16, PCI_CAP_XCFG_SPC(i), b, o, d)) 98*27255037Spjha #define PCI_XCAP_PUT32(h, i, b, o, d) ((uint32_t) \ 99*27255037Spjha pci_cap_put(h, PCI_CAP_CFGSZ_32, PCI_CAP_XCFG_SPC(i), b, o, d)) 100*27255037Spjha 101*27255037Spjha 102*27255037Spjha extern int pci_cap_probe(ddi_acc_handle_t h, uint16_t index, 103*27255037Spjha uint32_t *id_p, uint16_t *base_p); 104*27255037Spjha 105*27255037Spjha extern uint32_t pci_cap_get(ddi_acc_handle_t h, pci_config_size_t size, 106*27255037Spjha uint32_t id, uint16_t base, uint16_t offset); 107*27255037Spjha 108*27255037Spjha extern int pci_cap_put(ddi_acc_handle_t h, pci_config_size_t size, 109*27255037Spjha uint32_t id, uint16_t base, uint16_t offset, uint32_t data); 110*27255037Spjha 111*27255037Spjha extern int pci_cap_read(ddi_acc_handle_t h, uint32_t id, uint16_t base, 112*27255037Spjha uint32_t *buf_p, uint32_t nwords); 113*27255037Spjha 114*27255037Spjha extern int pci_cap_count(ddi_acc_handle_t h); 115*27255037Spjha 116*27255037Spjha extern void pci_cap_print(ddi_acc_handle_t h); 117*27255037Spjha 118*27255037Spjha extern void pci_cap_dump(uint32_t *buf_p, uint32_t nwords); 119*27255037Spjha 120*27255037Spjha #ifdef __cplusplus 121*27255037Spjha } 122*27255037Spjha #endif 123*27255037Spjha 124*27255037Spjha #endif /* _SYS_PCI_CAP_H */ 125