11624Spjha /* 21624Spjha * CDDL HEADER START 31624Spjha * 41624Spjha * The contents of this file are subject to the terms of the 51624Spjha * Common Development and Distribution License (the "License"). 61624Spjha * You may not use this file except in compliance with the License. 71624Spjha * 81624Spjha * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91624Spjha * or http://www.opensolaris.org/os/licensing. 101624Spjha * See the License for the specific language governing permissions 111624Spjha * and limitations under the License. 121624Spjha * 131624Spjha * When distributing Covered Code, include this CDDL HEADER in each 141624Spjha * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151624Spjha * If applicable, add the following below this CDDL HEADER, with the 161624Spjha * fields enclosed by brackets "[]" replaced with your own identifying 171624Spjha * information: Portions Copyright [yyyy] [name of copyright owner] 181624Spjha * 191624Spjha * CDDL HEADER END 201624Spjha */ 211624Spjha /* 22*9970SJimmy.Vetayases@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 231624Spjha * Use is subject to license terms. 241624Spjha */ 251624Spjha 261624Spjha #ifndef _SYS_PCI_CAP_H 271624Spjha #define _SYS_PCI_CAP_H 281624Spjha 291624Spjha #ifdef __cplusplus 301624Spjha extern "C" { 311624Spjha #endif 321624Spjha 331624Spjha #define PCI_CAP_XCFG_FLAG_SHIFT 31 341624Spjha #define PCI_CAP_XCFG_FLAG (1u << PCI_CAP_XCFG_FLAG_SHIFT) 351624Spjha 361624Spjha /* Function Prototypes */ 371624Spjha int pci_xcap_locate(ddi_acc_handle_t h, uint16_t id, uint16_t *base_p); 381624Spjha int pci_lcap_locate(ddi_acc_handle_t h, uint8_t id, uint16_t *base_p); 39*9970SJimmy.Vetayases@Sun.COM int pci_htcap_locate(ddi_acc_handle_t h, uint16_t reg_mask, uint16_t reg_val, 40*9970SJimmy.Vetayases@Sun.COM uint16_t *base_p); 411624Spjha 421624Spjha 431624Spjha /* Extract the lower 16 bits Extended CFG SPACE */ 441624Spjha #define PCI_CAP_XID_MASK 0xffff 451624Spjha 461624Spjha /* Extract the lower 8 bits Extended CFG SPACE */ 471624Spjha #define PCI_CAP_ID_MASK 0xff 481624Spjha 491624Spjha #define PCI_CAP_XCFG_SPC(i) ((i) ? (i) | PCI_CAP_XCFG_FLAG : 0) 501624Spjha 511624Spjha #ifdef DEBUG 521624Spjha #define PCI_CAP_DBG if (pci_cap_debug) printf 531624Spjha #else 541624Spjha #define PCI_CAP_DBG _NOTE(CONSTANTCONDITION) if (0) printf 551624Spjha #endif /* DEBUG */ 561624Spjha 571774Spjha /* 2's complement of -1, added here to ameliorate testing for invalid data */ 581774Spjha #define PCI_CAP_EINVAL8 0xff 591774Spjha #define PCI_CAP_EINVAL16 0xffff 601774Spjha #define PCI_CAP_EINVAL32 0xffffffff 611774Spjha 621624Spjha /* 631624Spjha * Supported Config Size Reads/Writes 641624Spjha */ 651624Spjha 661624Spjha typedef enum { 671624Spjha PCI_CAP_CFGSZ_8 = 0, 681624Spjha PCI_CAP_CFGSZ_16 = 1, 691624Spjha PCI_CAP_CFGSZ_32 = 2 702587Spjha } pci_cap_config_size_t; 711624Spjha 721624Spjha /* Define Macros */ 731624Spjha 741624Spjha #define PCI_CAP_LOCATE(h, id, base_p) ((id) & PCI_CAP_XCFG_FLAG ? \ 751624Spjha pci_xcap_locate(h, (uint16_t)((id) & PCI_CAP_XID_MASK), base_p) : \ 761624Spjha pci_lcap_locate(h, (uint8_t)((id) & PCI_CAP_ID_MASK), base_p)) 771624Spjha 781624Spjha #define PCI_CAP_GET8(h, i, b, o) ((uint8_t) \ 791624Spjha pci_cap_get(h, PCI_CAP_CFGSZ_8, i, b, o)) 801624Spjha #define PCI_CAP_GET16(h, i, b, o) ((uint16_t) \ 811624Spjha pci_cap_get(h, PCI_CAP_CFGSZ_16, i, b, o)) 821624Spjha #define PCI_CAP_GET32(h, i, b, o) ((uint32_t) \ 831624Spjha pci_cap_get(h, PCI_CAP_CFGSZ_32, i, b, o)) 841624Spjha 851624Spjha #define PCI_CAP_PUT8(h, i, b, o, d) ((uint8_t) \ 861624Spjha pci_cap_put(h, PCI_CAP_CFGSZ_8, i, b, o, d)) 871624Spjha #define PCI_CAP_PUT16(h, i, b, o, d) ((uint16_t) \ 881624Spjha pci_cap_put(h, PCI_CAP_CFGSZ_16, i, b, o, d)) 891624Spjha #define PCI_CAP_PUT32(h, i, b, o, d) ((uint32_t) \ 901624Spjha pci_cap_put(h, PCI_CAP_CFGSZ_32, i, b, o, d)) 911624Spjha 921624Spjha #define PCI_XCAP_GET8(h, i, b, o) ((uint8_t) \ 931624Spjha pci_cap_get(h, PCI_CAP_CFGSZ_8, PCI_CAP_XCFG_SPC(i), b, o)) 941624Spjha #define PCI_XCAP_GET16(h, i, b, o) ((uint16_t) \ 951624Spjha pci_cap_get(h, PCI_CAP_CFGSZ_16, PCI_CAP_XCFG_SPC(i), b, o)) 961624Spjha #define PCI_XCAP_GET32(h, i, b, o) ((uint32_t) \ 971624Spjha pci_cap_get(h, PCI_CAP_CFGSZ_32, PCI_CAP_XCFG_SPC(i), b, o)) 981624Spjha 991624Spjha #define PCI_XCAP_PUT8(h, i, b, o, d) ((uint8_t) \ 1001624Spjha pci_cap_put(h, PCI_CAP_CFGSZ_8, PCI_CAP_XCFG_SPC(i), b, o, d)) 1011624Spjha #define PCI_XCAP_PUT16(h, i, b, o, d) ((uint16_t) \ 1021624Spjha pci_cap_put(h, PCI_CAP_CFGSZ_16, PCI_CAP_XCFG_SPC(i), b, o, d)) 1031624Spjha #define PCI_XCAP_PUT32(h, i, b, o, d) ((uint32_t) \ 1041624Spjha pci_cap_put(h, PCI_CAP_CFGSZ_32, PCI_CAP_XCFG_SPC(i), b, o, d)) 1051624Spjha 1061624Spjha 1071624Spjha extern int pci_cap_probe(ddi_acc_handle_t h, uint16_t index, 1081624Spjha uint32_t *id_p, uint16_t *base_p); 1091624Spjha 1102587Spjha extern uint32_t pci_cap_get(ddi_acc_handle_t h, pci_cap_config_size_t size, 1111624Spjha uint32_t id, uint16_t base, uint16_t offset); 1121624Spjha 1132587Spjha extern int pci_cap_put(ddi_acc_handle_t h, pci_cap_config_size_t size, 1141624Spjha uint32_t id, uint16_t base, uint16_t offset, uint32_t data); 1151624Spjha 1161624Spjha extern int pci_cap_read(ddi_acc_handle_t h, uint32_t id, uint16_t base, 1171624Spjha uint32_t *buf_p, uint32_t nwords); 1181624Spjha 1191624Spjha #ifdef __cplusplus 1201624Spjha } 1211624Spjha #endif 1221624Spjha 1231624Spjha #endif /* _SYS_PCI_CAP_H */ 124