10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*3156Sgirish * Common Development and Distribution License (the "License"). 6*3156Sgirish * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*3156Sgirish * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_PCI_IMPL_H 270Sstevel@tonic-gate #define _SYS_PCI_IMPL_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #include <sys/dditypes.h> 320Sstevel@tonic-gate #include <sys/memlist.h> 330Sstevel@tonic-gate 340Sstevel@tonic-gate #ifdef __cplusplus 350Sstevel@tonic-gate extern "C" { 360Sstevel@tonic-gate #endif 370Sstevel@tonic-gate 380Sstevel@tonic-gate #if defined(__i386) || defined(__amd64) 390Sstevel@tonic-gate 400Sstevel@tonic-gate /* 410Sstevel@tonic-gate * There are two ways to access the PCI configuration space on X86 420Sstevel@tonic-gate * Access method 2 is the older method 430Sstevel@tonic-gate * Access method 1 is the newer method and is preferred because 440Sstevel@tonic-gate * of the problems in trying to lock the configuration space 450Sstevel@tonic-gate * for MP machines using method 2. See PCI Local BUS Specification 460Sstevel@tonic-gate * Revision 2.0 section 3.6.4.1 for more details. 470Sstevel@tonic-gate * 480Sstevel@tonic-gate * In addition, on IBM Sandalfoot and a few related machines there's 490Sstevel@tonic-gate * still another mechanism. See PReP 1.1 section 6.1.7. 500Sstevel@tonic-gate */ 510Sstevel@tonic-gate 520Sstevel@tonic-gate #define PCI_MECHANISM_UNKNOWN -1 530Sstevel@tonic-gate #define PCI_MECHANISM_NONE 0 54641Skalai #if defined(__i386) || defined(__amd64) 550Sstevel@tonic-gate #define PCI_MECHANISM_1 1 560Sstevel@tonic-gate #define PCI_MECHANISM_2 2 570Sstevel@tonic-gate #else 580Sstevel@tonic-gate #error "Unknown processor type" 590Sstevel@tonic-gate #endif 600Sstevel@tonic-gate 610Sstevel@tonic-gate 620Sstevel@tonic-gate #ifndef FALSE 630Sstevel@tonic-gate #define FALSE 0 640Sstevel@tonic-gate #endif 650Sstevel@tonic-gate 660Sstevel@tonic-gate #ifndef TRUE 670Sstevel@tonic-gate #define TRUE 1 680Sstevel@tonic-gate #endif 690Sstevel@tonic-gate 700Sstevel@tonic-gate #define PCI_FUNC_MASK 0x07 710Sstevel@tonic-gate 720Sstevel@tonic-gate /* these macros apply to Configuration Mechanism #1 */ 730Sstevel@tonic-gate #define PCI_CONFADD 0xcf8 740Sstevel@tonic-gate #define PCI_PMC 0xcfb 750Sstevel@tonic-gate #define PCI_CONFDATA 0xcfc 760Sstevel@tonic-gate #define PCI_CONE 0x80000000 770Sstevel@tonic-gate #define PCI_CADDR1(bus, device, function, reg) \ 780Sstevel@tonic-gate (PCI_CONE | (((bus) & 0xff) << 16) | (((device & 0x1f)) << 11) \ 790Sstevel@tonic-gate | (((function) & 0x7) << 8) | ((reg) & 0xfc)) 800Sstevel@tonic-gate 810Sstevel@tonic-gate /* these macros apply to Configuration Mechanism #2 */ 820Sstevel@tonic-gate #define PCI_CSE_PORT 0xcf8 830Sstevel@tonic-gate #define PCI_FORW_PORT 0xcfa 840Sstevel@tonic-gate #define PCI_CADDR2(device, indx) \ 850Sstevel@tonic-gate (0xc000 | (((device) & 0xf) << 8) | (indx)) 860Sstevel@tonic-gate 870Sstevel@tonic-gate typedef struct pci_acc_cfblk { 880Sstevel@tonic-gate uchar_t c_busnum; /* bus number */ 890Sstevel@tonic-gate uchar_t c_devnum; /* device number */ 900Sstevel@tonic-gate uchar_t c_funcnum; /* function number */ 910Sstevel@tonic-gate uchar_t c_fill; /* reserve field */ 920Sstevel@tonic-gate } pci_acc_cfblk_t; 930Sstevel@tonic-gate 940Sstevel@tonic-gate struct pci_bus_resource { 950Sstevel@tonic-gate struct memlist *io_ports; 960Sstevel@tonic-gate struct memlist *mem_space; 970Sstevel@tonic-gate struct memlist *pmem_space; 980Sstevel@tonic-gate dev_info_t *dip; /* devinfo node */ 990Sstevel@tonic-gate void *privdata; /* private data for configuration */ 1000Sstevel@tonic-gate uchar_t par_bus; /* parent bus number */ 1010Sstevel@tonic-gate uchar_t sub_bus; /* highest bus number beyond this bridge */ 1020Sstevel@tonic-gate uchar_t root_addr; /* legacy peer bus address assignment */ 1030Sstevel@tonic-gate uchar_t padding1; 1040Sstevel@tonic-gate #ifdef _LP64 1050Sstevel@tonic-gate uint32_t padding2; 1060Sstevel@tonic-gate #endif 1070Sstevel@tonic-gate }; 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate extern struct pci_bus_resource *pci_bus_res; 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate /* 1120Sstevel@tonic-gate * For now, x86-only to avoid conflicts with <sys/memlist_impl.h> 1130Sstevel@tonic-gate */ 1140Sstevel@tonic-gate extern struct memlist *memlist_alloc(void); 1150Sstevel@tonic-gate extern void memlist_free(struct memlist *); 1160Sstevel@tonic-gate extern void memlist_insert(struct memlist **, uint64_t, uint64_t); 1170Sstevel@tonic-gate extern int memlist_remove(struct memlist **, uint64_t, uint64_t); 1180Sstevel@tonic-gate extern uint64_t memlist_find(struct memlist **, uint64_t, int); 1190Sstevel@tonic-gate extern void memlist_dump(struct memlist *); 1200Sstevel@tonic-gate extern struct memlist *memlist_dup(struct memlist *); 1210Sstevel@tonic-gate extern int memlist_count(struct memlist *); 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate #endif /* __i386 || __amd64 */ 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate /* 126*3156Sgirish * Parent private data structure for PCI/PCI-X/PCIe devices. 127*3156Sgirish */ 128*3156Sgirish typedef struct pci_parent_data { 129*3156Sgirish uint32_t pci_bdf; /* BDF for pci/pci-x/pcie */ 130*3156Sgirish uint8_t pci_sec_bus; /* PCIE2PCI bridge's secondary bus */ 131*3156Sgirish uint8_t pci_phfun; /* Phantom funs for pci-x/pcie */ 132*3156Sgirish } pci_parent_data_t; 133*3156Sgirish 134*3156Sgirish #define PCI_GET_BDF(dip) \ 135*3156Sgirish ((pci_parent_data_t *)DEVI((dip))->devi_parent_data)->pci_bdf 136*3156Sgirish #define PCI_GET_SEC_BUS(dip) \ 137*3156Sgirish ((pci_parent_data_t *)DEVI((dip))->devi_parent_data)->pci_sec_bus 138*3156Sgirish #define PCI_GET_PHFUN(dip) \ 139*3156Sgirish ((pci_parent_data_t *)DEVI((dip))->devi_parent_data)->pci_phfun 140*3156Sgirish 141*3156Sgirish /* 1420Sstevel@tonic-gate * PCI capability related definitions. 1430Sstevel@tonic-gate */ 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate /* 1460Sstevel@tonic-gate * Minimum number of dwords to be saved. 1470Sstevel@tonic-gate */ 1480Sstevel@tonic-gate #define PCI_MSI_MIN_WORDS 3 1490Sstevel@tonic-gate #define PCI_PCIX_MIN_WORDS 2 1500Sstevel@tonic-gate #define PCI_PCIE_MIN_WORDS 5 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate /* 1530Sstevel@tonic-gate * Total number of dwords to be saved. 1540Sstevel@tonic-gate */ 1550Sstevel@tonic-gate #define PCI_PMCAP_NDWORDS 2 1560Sstevel@tonic-gate #define PCI_AGP_NDWORDS 3 1570Sstevel@tonic-gate #define PCI_SLOTID_NDWORDS 1 1580Sstevel@tonic-gate #define PCI_MSIX_NDWORDS 3 1590Sstevel@tonic-gate #define PCI_CAP_SZUNKNOWN 0 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate #define CAP_ID(confhdl, cap_ptr, xspace) \ 1620Sstevel@tonic-gate ((xspace) ? 0 : pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_ID)) 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate #define NEXT_CAP(confhdl, cap_ptr, xspace) \ 1650Sstevel@tonic-gate ((xspace) ? 0 : \ 1660Sstevel@tonic-gate pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_NEXT_PTR)) 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate extern int pci_resource_setup(dev_info_t *); 1690Sstevel@tonic-gate extern void pci_resource_destroy(dev_info_t *); 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate #ifdef __cplusplus 1720Sstevel@tonic-gate } 1730Sstevel@tonic-gate #endif 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate #endif /* _SYS_PCI_IMPL_H */ 176