pci_cap.c revision 911fc2e57de04c6f6a4da8afebbafbcc3e3c4ee5
27255037bba8df933008f7bd2112201bef2e2429pjha * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
27255037bba8df933008f7bd2112201bef2e2429pjha * See the License for the specific language governing permissions
27255037bba8df933008f7bd2112201bef2e2429pjha * and limitations under the License.
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 * CDDL HEADER END
27255037bba8df933008f7bd2112201bef2e2429pjha * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27255037bba8df933008f7bd2112201bef2e2429pjha * Use is subject to license terms.
27255037bba8df933008f7bd2112201bef2e2429pjha#pragma ident "%Z%%M% %I% %E% SMI"
27255037bba8df933008f7bd2112201bef2e2429pjha * Generic PCI Capabilites Interface for all pci platforms
27255037bba8df933008f7bd2112201bef2e2429pjha/* Cap Base Macro */
27255037bba8df933008f7bd2112201bef2e2429pjha#define PCI_CAP_BASE(h, id, base_p) (*base_p ? DDI_SUCCESS : \
27255037bba8df933008f7bd2112201bef2e2429pjha * pci_cap_probe: returns the capid and base based upon a given index
27255037bba8df933008f7bd2112201bef2e2429pjha uint32_t id, xcaps_hdr; /* Extended Caps Header Word */
27255037bba8df933008f7bd2112201bef2e2429pjha /* PCIE and PCIX Version 2 contain Extended Config Space */
27255037bba8df933008f7bd2112201bef2e2429pjha for (i = 0, base = pci_config_get8(h, PCI_CONF_CAP_PTR);
27255037bba8df933008f7bd2112201bef2e2429pjha if ((xcaps_hdr = pci_config_get32(h, base)) == 0xffffffff)
27255037bba8df933008f7bd2112201bef2e2429pjha if ((xcaps_hdr = pci_config_get32(h, base)) == 0xffffffff)
27255037bba8df933008f7bd2112201bef2e2429pjha id = ((xcaps_hdr >> PCIE_EXT_CAP_ID_SHIFT) & PCIE_EXT_CAP_ID_MASK) |
27255037bba8df933008f7bd2112201bef2e2429pjha PCI_CAP_DBG("pci_cap_probe: index=%x, id=%x, base=%x\n",
27255037bba8df933008f7bd2112201bef2e2429pjha * pci_lcap_locate: Helper function locates a base in conventional config space.
27255037bba8df933008f7bd2112201bef2e2429pjhapci_lcap_locate(ddi_acc_handle_t h, uint8_t id, uint16_t *base_p)
27255037bba8df933008f7bd2112201bef2e2429pjha for (base = pci_config_get8(h, PCI_CONF_CAP_PTR); base;
27255037bba8df933008f7bd2112201bef2e2429pjha * pci_xcap_locate: Helper function locates a base in extended config space.
27255037bba8df933008f7bd2112201bef2e2429pjhapci_xcap_locate(ddi_acc_handle_t h, uint16_t id, uint16_t *base_p)
27255037bba8df933008f7bd2112201bef2e2429pjha PCIE_EXT_CAP_NEXT_PTR_SHIFT) & PCIE_EXT_CAP_NEXT_PTR_MASK) {
27255037bba8df933008f7bd2112201bef2e2429pjha if ((xcaps_hdr = pci_config_get32(h, base)) == 0xffffffff)
27255037bba8df933008f7bd2112201bef2e2429pjha * pci_cap_get: This function uses the base or capid to get a byte, word,
27255037bba8df933008f7bd2112201bef2e2429pjha * or dword. If access by capid is requested, the function uses the capid to
27255037bba8df933008f7bd2112201bef2e2429pjha * locate the base. Access by a base results in better performance
27255037bba8df933008f7bd2112201bef2e2429pjha * because no cap list traversal is required.
911fc2e57de04c6f6a4da8afebbafbcc3e3c4ee5pjha return (0xffffffff);
911fc2e57de04c6f6a4da8afebbafbcc3e3c4ee5pjha * Each access to a PCI Configuration Space should be checked
911fc2e57de04c6f6a4da8afebbafbcc3e3c4ee5pjha * by the calling function. A returned value of the 2's complement
911fc2e57de04c6f6a4da8afebbafbcc3e3c4ee5pjha * of -1 indicates that either the device is offlined or it does not
27255037bba8df933008f7bd2112201bef2e2429pjha switch (size) {
27255037bba8df933008f7bd2112201bef2e2429pjha PCI_CAP_DBG("pci_cap_get: %p[x%x]=x%x\n", (void *)h, offset, data);
27255037bba8df933008f7bd2112201bef2e2429pjha * pci_cap_put: This function uses the caps ptr or capid to put a byte, word,
27255037bba8df933008f7bd2112201bef2e2429pjha * or dword. If access by capid is requested, the function uses the capid to
27255037bba8df933008f7bd2112201bef2e2429pjha * locate the base. Access by base results in better performance
27255037bba8df933008f7bd2112201bef2e2429pjha * because no cap list traversal is required.
27255037bba8df933008f7bd2112201bef2e2429pjha * use the pci_config_size_t to switch for the appropriate read
27255037bba8df933008f7bd2112201bef2e2429pjha switch (size) {
27255037bba8df933008f7bd2112201bef2e2429pjha * Cache the entire Cap Structure. The caller is required to allocate and free
27255037bba8df933008f7bd2112201bef2e2429pjhapci_cap_read(ddi_acc_handle_t h, uint32_t id, uint16_t base,
27255037bba8df933008f7bd2112201bef2e2429pjha if ((*ptr++ = pci_config_get32(h, base)) == 0xffffffff)