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