27255037bba8df933008f7bd2112201bef2e2429pjha/*
27255037bba8df933008f7bd2112201bef2e2429pjha * CDDL HEADER START
27255037bba8df933008f7bd2112201bef2e2429pjha *
27255037bba8df933008f7bd2112201bef2e2429pjha * The contents of this file are subject to the terms of the
27255037bba8df933008f7bd2112201bef2e2429pjha * Common Development and Distribution License (the "License").
27255037bba8df933008f7bd2112201bef2e2429pjha * You may not use this file except in compliance with the License.
27255037bba8df933008f7bd2112201bef2e2429pjha *
27255037bba8df933008f7bd2112201bef2e2429pjha * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
27255037bba8df933008f7bd2112201bef2e2429pjha * or http://www.opensolaris.org/os/licensing.
27255037bba8df933008f7bd2112201bef2e2429pjha * See the License for the specific language governing permissions
27255037bba8df933008f7bd2112201bef2e2429pjha * and limitations under the License.
27255037bba8df933008f7bd2112201bef2e2429pjha *
27255037bba8df933008f7bd2112201bef2e2429pjha * When distributing Covered Code, include this CDDL HEADER in each
27255037bba8df933008f7bd2112201bef2e2429pjha * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
27255037bba8df933008f7bd2112201bef2e2429pjha * If applicable, add the following below this CDDL HEADER, with the
27255037bba8df933008f7bd2112201bef2e2429pjha * fields enclosed by brackets "[]" replaced with your own identifying
27255037bba8df933008f7bd2112201bef2e2429pjha * information: Portions Copyright [yyyy] [name of copyright owner]
27255037bba8df933008f7bd2112201bef2e2429pjha *
27255037bba8df933008f7bd2112201bef2e2429pjha * CDDL HEADER END
27255037bba8df933008f7bd2112201bef2e2429pjha */
27255037bba8df933008f7bd2112201bef2e2429pjha/*
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
27255037bba8df933008f7bd2112201bef2e2429pjha * Use is subject to license terms.
27255037bba8df933008f7bd2112201bef2e2429pjha */
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha#ifndef _SYS_PCI_CAP_H
27255037bba8df933008f7bd2112201bef2e2429pjha#define _SYS_PCI_CAP_H
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha#ifdef __cplusplus
27255037bba8df933008f7bd2112201bef2e2429pjhaextern "C" {
27255037bba8df933008f7bd2112201bef2e2429pjha#endif
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_XCFG_FLAG_SHIFT 31
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_XCFG_FLAG (1u << PCI_CAP_XCFG_FLAG_SHIFT)
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha/* Function Prototypes */
27255037bba8df933008f7bd2112201bef2e2429pjhaint pci_xcap_locate(ddi_acc_handle_t h, uint16_t id, uint16_t *base_p);
27255037bba8df933008f7bd2112201bef2e2429pjhaint pci_lcap_locate(ddi_acc_handle_t h, uint8_t id, uint16_t *base_p);
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayasesint pci_htcap_locate(ddi_acc_handle_t h, uint16_t reg_mask, uint16_t reg_val,
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases uint16_t *base_p);
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha/* Extract the lower 16 bits Extended CFG SPACE */
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_XID_MASK 0xffff
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha/* Extract the lower 8 bits Extended CFG SPACE */
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_ID_MASK 0xff
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_XCFG_SPC(i) ((i) ? (i) | PCI_CAP_XCFG_FLAG : 0)
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha#ifdef DEBUG
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_DBG if (pci_cap_debug) printf
27255037bba8df933008f7bd2112201bef2e2429pjha#else
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_DBG _NOTE(CONSTANTCONDITION) if (0) printf
27255037bba8df933008f7bd2112201bef2e2429pjha#endif /* DEBUG */
27255037bba8df933008f7bd2112201bef2e2429pjha
dc5d169b4bfc1a6993578ef34dae678076fd19fbpjha/* 2's complement of -1, added here to ameliorate testing for invalid data */
dc5d169b4bfc1a6993578ef34dae678076fd19fbpjha#define PCI_CAP_EINVAL8 0xff
dc5d169b4bfc1a6993578ef34dae678076fd19fbpjha#define PCI_CAP_EINVAL16 0xffff
dc5d169b4bfc1a6993578ef34dae678076fd19fbpjha#define PCI_CAP_EINVAL32 0xffffffff
dc5d169b4bfc1a6993578ef34dae678076fd19fbpjha
27255037bba8df933008f7bd2112201bef2e2429pjha/*
27255037bba8df933008f7bd2112201bef2e2429pjha * Supported Config Size Reads/Writes
27255037bba8df933008f7bd2112201bef2e2429pjha */
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjhatypedef enum {
27255037bba8df933008f7bd2112201bef2e2429pjha PCI_CAP_CFGSZ_8 = 0,
27255037bba8df933008f7bd2112201bef2e2429pjha PCI_CAP_CFGSZ_16 = 1,
27255037bba8df933008f7bd2112201bef2e2429pjha PCI_CAP_CFGSZ_32 = 2
3c4226f98775d47a05fa88f9f72479f1a250eaa5pjha} pci_cap_config_size_t;
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha/* Define Macros */
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_LOCATE(h, id, base_p) ((id) & PCI_CAP_XCFG_FLAG ? \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_xcap_locate(h, (uint16_t)((id) & PCI_CAP_XID_MASK), base_p) : \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_lcap_locate(h, (uint8_t)((id) & PCI_CAP_ID_MASK), base_p))
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_GET8(h, i, b, o) ((uint8_t) \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_cap_get(h, PCI_CAP_CFGSZ_8, i, b, o))
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_GET16(h, i, b, o) ((uint16_t) \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_cap_get(h, PCI_CAP_CFGSZ_16, i, b, o))
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_GET32(h, i, b, o) ((uint32_t) \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_cap_get(h, PCI_CAP_CFGSZ_32, i, b, o))
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_PUT8(h, i, b, o, d) ((uint8_t) \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_cap_put(h, PCI_CAP_CFGSZ_8, i, b, o, d))
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_PUT16(h, i, b, o, d) ((uint16_t) \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_cap_put(h, PCI_CAP_CFGSZ_16, i, b, o, d))
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_PUT32(h, i, b, o, d) ((uint32_t) \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_cap_put(h, PCI_CAP_CFGSZ_32, i, b, o, d))
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_XCAP_GET8(h, i, b, o) ((uint8_t) \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_cap_get(h, PCI_CAP_CFGSZ_8, PCI_CAP_XCFG_SPC(i), b, o))
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_XCAP_GET16(h, i, b, o) ((uint16_t) \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_cap_get(h, PCI_CAP_CFGSZ_16, PCI_CAP_XCFG_SPC(i), b, o))
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_XCAP_GET32(h, i, b, o) ((uint32_t) \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_cap_get(h, PCI_CAP_CFGSZ_32, PCI_CAP_XCFG_SPC(i), b, o))
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_XCAP_PUT8(h, i, b, o, d) ((uint8_t) \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_cap_put(h, PCI_CAP_CFGSZ_8, PCI_CAP_XCFG_SPC(i), b, o, d))
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_XCAP_PUT16(h, i, b, o, d) ((uint16_t) \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_cap_put(h, PCI_CAP_CFGSZ_16, PCI_CAP_XCFG_SPC(i), b, o, d))
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_XCAP_PUT32(h, i, b, o, d) ((uint32_t) \
27255037bba8df933008f7bd2112201bef2e2429pjha pci_cap_put(h, PCI_CAP_CFGSZ_32, PCI_CAP_XCFG_SPC(i), b, o, d))
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjhaextern int pci_cap_probe(ddi_acc_handle_t h, uint16_t index,
27255037bba8df933008f7bd2112201bef2e2429pjha uint32_t *id_p, uint16_t *base_p);
27255037bba8df933008f7bd2112201bef2e2429pjha
3c4226f98775d47a05fa88f9f72479f1a250eaa5pjhaextern uint32_t pci_cap_get(ddi_acc_handle_t h, pci_cap_config_size_t size,
27255037bba8df933008f7bd2112201bef2e2429pjha uint32_t id, uint16_t base, uint16_t offset);
27255037bba8df933008f7bd2112201bef2e2429pjha
3c4226f98775d47a05fa88f9f72479f1a250eaa5pjhaextern int pci_cap_put(ddi_acc_handle_t h, pci_cap_config_size_t size,
27255037bba8df933008f7bd2112201bef2e2429pjha uint32_t id, uint16_t base, uint16_t offset, uint32_t data);
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjhaextern int pci_cap_read(ddi_acc_handle_t h, uint32_t id, uint16_t base,
27255037bba8df933008f7bd2112201bef2e2429pjha uint32_t *buf_p, uint32_t nwords);
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha#ifdef __cplusplus
27255037bba8df933008f7bd2112201bef2e2429pjha}
27255037bba8df933008f7bd2112201bef2e2429pjha#endif
27255037bba8df933008f7bd2112201bef2e2429pjha
27255037bba8df933008f7bd2112201bef2e2429pjha#endif /* _SYS_PCI_CAP_H */