pci_cap.c revision cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0
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
fb66942fa6213bb169b433e06b0ed5dcced34b0dCasper H.S. Dik * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
27255037bba8df933008f7bd2112201bef2e2429pjha * Use is subject to license terms.
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 */
dc5d169b4bfc1a6993578ef34dae678076fd19fbpjha if (status == PCI_CAP_EINVAL16 || !(status & PCI_STAT_CAP))
27255037bba8df933008f7bd2112201bef2e2429pjha /* PCIE and PCIX Version 2 contain Extended Config Space */
27255037bba8df933008f7bd2112201bef2e2429pjha for (i = 0, base = pci_config_get8(h, PCI_CONF_CAP_PTR);
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases base && i < index; base = pci_config_get8(h, base
dc5d169b4bfc1a6993578ef34dae678076fd19fbpjha if ((xcaps_hdr = pci_config_get32(h, base)) == PCI_CAP_EINVAL32)
dc5d169b4bfc1a6993578ef34dae678076fd19fbpjha if ((xcaps_hdr = pci_config_get32(h, base)) == PCI_CAP_EINVAL32)
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)
dc5d169b4bfc1a6993578ef34dae678076fd19fbpjha if (status == PCI_CAP_EINVAL16 || !(status & PCI_STAT_CAP))
fb66942fa6213bb169b433e06b0ed5dcced34b0dCasper H.S. Dik header = pci_config_get8(h, PCI_CONF_HEADER);
fb66942fa6213bb169b433e06b0ed5dcced34b0dCasper H.S. Dik cmn_err(CE_WARN, "%s: unexpected pci header type:%x",
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases base = pci_config_get8(h, base + PCI_CAP_NEXT_PTR)) {
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)
dc5d169b4bfc1a6993578ef34dae678076fd19fbpjha if (status == PCI_CAP_EINVAL16 || !(status & PCI_STAT_CAP))
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases PCIE_EXT_CAP_NEXT_PTR_SHIFT) & PCIE_EXT_CAP_NEXT_PTR_MASK) {
dc5d169b4bfc1a6993578ef34dae678076fd19fbpjha if ((xcaps_hdr = pci_config_get32(h, base)) == PCI_CAP_EINVAL32)
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * There can be multiple pci caps with a Hypertransport technology cap ID
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * Each is distiguished by a type register in the upper half of the cap
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * header (the "command" register part).
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * This returns the location of a hypertransport capability whose upper
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * 16-bits of the cap header matches <reg_val> after masking the value
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * with <reg_mask>; if both <reg_mask> and <reg_val> are 0, it will return
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * the first HT cap found
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayasespci_htcap_locate(ddi_acc_handle_t h, uint16_t reg_mask, uint16_t reg_val,
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases status = pci_config_get16(h, PCI_CONF_STAT);
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases if (status == PCI_CAP_EINVAL16 || !(status & PCI_STAT_CAP))
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases header = pci_config_get8(h, PCI_CONF_HEADER);
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases cmn_err(CE_WARN, "%s: unexpected pci header type:%x",
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases base = pci_config_get8(h, base + PCI_CAP_NEXT_PTR)) {
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases if (pci_config_get8(h, base) == PCI_CAP_ID_HT &&
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases (pci_config_get16(h, base + PCI_CAP_ID_REGS_OFF) &
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.
3c4226f98775d47a05fa88f9f72479f1a250eaa5pjhapci_cap_get(ddi_acc_handle_t h, pci_cap_config_size_t size,
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.
3c4226f98775d47a05fa88f9f72479f1a250eaa5pjhapci_cap_put(ddi_acc_handle_t h, pci_cap_config_size_t size,
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,
dc5d169b4bfc1a6993578ef34dae678076fd19fbpjha if ((*ptr++ = pci_config_get32(h, base)) == PCI_CAP_EINVAL32)