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 53156Sgirish * Common Development and Distribution License (the "License"). 63156Sgirish * 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 /* 229588SKerry.Shu@Sun.COM * Copyright 2009 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 #include <sys/dditypes.h> 300Sstevel@tonic-gate #include <sys/memlist.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate #ifdef __cplusplus 330Sstevel@tonic-gate extern "C" { 340Sstevel@tonic-gate #endif 350Sstevel@tonic-gate 360Sstevel@tonic-gate #if defined(__i386) || defined(__amd64) 370Sstevel@tonic-gate 380Sstevel@tonic-gate /* 390Sstevel@tonic-gate * There are two ways to access the PCI configuration space on X86 400Sstevel@tonic-gate * Access method 2 is the older method 410Sstevel@tonic-gate * Access method 1 is the newer method and is preferred because 420Sstevel@tonic-gate * of the problems in trying to lock the configuration space 430Sstevel@tonic-gate * for MP machines using method 2. See PCI Local BUS Specification 440Sstevel@tonic-gate * Revision 2.0 section 3.6.4.1 for more details. 450Sstevel@tonic-gate * 460Sstevel@tonic-gate * In addition, on IBM Sandalfoot and a few related machines there's 470Sstevel@tonic-gate * still another mechanism. See PReP 1.1 section 6.1.7. 480Sstevel@tonic-gate */ 490Sstevel@tonic-gate 500Sstevel@tonic-gate #define PCI_MECHANISM_UNKNOWN -1 510Sstevel@tonic-gate #define PCI_MECHANISM_NONE 0 52641Skalai #if defined(__i386) || defined(__amd64) 530Sstevel@tonic-gate #define PCI_MECHANISM_1 1 540Sstevel@tonic-gate #define PCI_MECHANISM_2 2 550Sstevel@tonic-gate #else 560Sstevel@tonic-gate #error "Unknown processor type" 570Sstevel@tonic-gate #endif 580Sstevel@tonic-gate 590Sstevel@tonic-gate 600Sstevel@tonic-gate #ifndef FALSE 610Sstevel@tonic-gate #define FALSE 0 620Sstevel@tonic-gate #endif 630Sstevel@tonic-gate 640Sstevel@tonic-gate #ifndef TRUE 650Sstevel@tonic-gate #define TRUE 1 660Sstevel@tonic-gate #endif 670Sstevel@tonic-gate 680Sstevel@tonic-gate #define PCI_FUNC_MASK 0x07 690Sstevel@tonic-gate 700Sstevel@tonic-gate /* these macros apply to Configuration Mechanism #1 */ 710Sstevel@tonic-gate #define PCI_CONFADD 0xcf8 720Sstevel@tonic-gate #define PCI_PMC 0xcfb 730Sstevel@tonic-gate #define PCI_CONFDATA 0xcfc 740Sstevel@tonic-gate #define PCI_CONE 0x80000000 750Sstevel@tonic-gate #define PCI_CADDR1(bus, device, function, reg) \ 760Sstevel@tonic-gate (PCI_CONE | (((bus) & 0xff) << 16) | (((device & 0x1f)) << 11) \ 770Sstevel@tonic-gate | (((function) & 0x7) << 8) | ((reg) & 0xfc)) 780Sstevel@tonic-gate 790Sstevel@tonic-gate /* these macros apply to Configuration Mechanism #2 */ 800Sstevel@tonic-gate #define PCI_CSE_PORT 0xcf8 810Sstevel@tonic-gate #define PCI_FORW_PORT 0xcfa 820Sstevel@tonic-gate #define PCI_CADDR2(device, indx) \ 830Sstevel@tonic-gate (0xc000 | (((device) & 0xf) << 8) | (indx)) 840Sstevel@tonic-gate 850Sstevel@tonic-gate typedef struct pci_acc_cfblk { 860Sstevel@tonic-gate uchar_t c_busnum; /* bus number */ 870Sstevel@tonic-gate uchar_t c_devnum; /* device number */ 880Sstevel@tonic-gate uchar_t c_funcnum; /* function number */ 890Sstevel@tonic-gate uchar_t c_fill; /* reserve field */ 900Sstevel@tonic-gate } pci_acc_cfblk_t; 910Sstevel@tonic-gate 920Sstevel@tonic-gate struct pci_bus_resource { 9310251SDan.Mick@Sun.COM struct memlist *io_avail; /* available free io res */ 9410251SDan.Mick@Sun.COM struct memlist *io_used; /* used io res */ 9510251SDan.Mick@Sun.COM struct memlist *mem_avail; /* available free mem res */ 9610251SDan.Mick@Sun.COM struct memlist *mem_used; /* used mem res */ 9710251SDan.Mick@Sun.COM struct memlist *pmem_avail; /* available free prefetchable mem res */ 9810251SDan.Mick@Sun.COM struct memlist *pmem_used; /* used prefetchable mem res */ 9910251SDan.Mick@Sun.COM struct memlist *bus_avail; /* available free bus res */ 1006095Sgs150176 /* bus_space_used not needed; can read from regs */ 1010Sstevel@tonic-gate dev_info_t *dip; /* devinfo node */ 1020Sstevel@tonic-gate void *privdata; /* private data for configuration */ 1030Sstevel@tonic-gate uchar_t par_bus; /* parent bus number */ 1040Sstevel@tonic-gate uchar_t sub_bus; /* highest bus number beyond this bridge */ 1050Sstevel@tonic-gate uchar_t root_addr; /* legacy peer bus address assignment */ 1066095Sgs150176 uchar_t num_cbb; /* # of CardBus Bridges on the bus */ 1076095Sgs150176 boolean_t io_reprogram; /* need io reprog on this bus */ 1086095Sgs150176 boolean_t mem_reprogram; /* need mem reprog on this bus */ 1096095Sgs150176 boolean_t subtractive; /* subtractive PPB */ 1109588SKerry.Shu@Sun.COM uint_t mem_size; /* existing children required MEM space size */ 1119588SKerry.Shu@Sun.COM uint_t io_size; /* existing children required I/O space size */ 1120Sstevel@tonic-gate }; 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate extern struct pci_bus_resource *pci_bus_res; 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* 1170Sstevel@tonic-gate * For now, x86-only to avoid conflicts with <sys/memlist_impl.h> 1180Sstevel@tonic-gate */ 1190Sstevel@tonic-gate extern struct memlist *memlist_alloc(void); 1200Sstevel@tonic-gate extern void memlist_free(struct memlist *); 1216095Sgs150176 extern void memlist_free_all(struct memlist **); 1220Sstevel@tonic-gate extern void memlist_insert(struct memlist **, uint64_t, uint64_t); 1230Sstevel@tonic-gate extern int memlist_remove(struct memlist **, uint64_t, uint64_t); 1240Sstevel@tonic-gate extern uint64_t memlist_find(struct memlist **, uint64_t, int); 1256095Sgs150176 extern uint64_t memlist_find_with_startaddr(struct memlist **, uint64_t, 1266095Sgs150176 uint64_t, int); 1270Sstevel@tonic-gate extern void memlist_dump(struct memlist *); 12810251SDan.Mick@Sun.COM extern void memlist_subsume(struct memlist **, struct memlist **); 1296095Sgs150176 extern void memlist_merge(struct memlist **, struct memlist **); 1300Sstevel@tonic-gate extern struct memlist *memlist_dup(struct memlist *); 1310Sstevel@tonic-gate extern int memlist_count(struct memlist *); 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate #endif /* __i386 || __amd64 */ 1340Sstevel@tonic-gate 135*10923SEvan.Yan@Sun.COM /* Definitions for minor numbers */ 136*10923SEvan.Yan@Sun.COM #define PCI_MINOR_NUM(x, y) (((uint_t)(x) << 8) | ((y) & 0xFF)) 137*10923SEvan.Yan@Sun.COM #define PCI_MINOR_NUM_TO_PCI_DEVNUM(x) ((x) & 0xFF) 138*10923SEvan.Yan@Sun.COM #define PCI_MINOR_NUM_TO_INSTANCE(x) ((x) >> 8) 139*10923SEvan.Yan@Sun.COM #define PCI_DEVCTL_MINOR 0xFF 140*10923SEvan.Yan@Sun.COM 141*10923SEvan.Yan@Sun.COM /* 142*10923SEvan.Yan@Sun.COM * Minor numbers for dedicated pcitool nodes. 143*10923SEvan.Yan@Sun.COM * Note that FF and FE minor numbers are used for other minor nodes. 144*10923SEvan.Yan@Sun.COM */ 145*10923SEvan.Yan@Sun.COM #define PCI_TOOL_REG_MINOR_NUM 0xFD 146*10923SEvan.Yan@Sun.COM #define PCI_TOOL_INTR_MINOR_NUM 0xFC 147*10923SEvan.Yan@Sun.COM 148*10923SEvan.Yan@Sun.COM /* pci devctl soft state flag */ 149*10923SEvan.Yan@Sun.COM #define PCI_SOFT_STATE_CLOSED 0x0 150*10923SEvan.Yan@Sun.COM #define PCI_SOFT_STATE_OPEN 0x1 151*10923SEvan.Yan@Sun.COM #define PCI_SOFT_STATE_OPEN_EXCL 0x2 152*10923SEvan.Yan@Sun.COM 1530Sstevel@tonic-gate /* 1540Sstevel@tonic-gate * PCI capability related definitions. 1550Sstevel@tonic-gate */ 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate /* 1580Sstevel@tonic-gate * Minimum number of dwords to be saved. 1590Sstevel@tonic-gate */ 1600Sstevel@tonic-gate #define PCI_MSI_MIN_WORDS 3 1610Sstevel@tonic-gate #define PCI_PCIX_MIN_WORDS 2 1620Sstevel@tonic-gate #define PCI_PCIE_MIN_WORDS 5 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate /* 1650Sstevel@tonic-gate * Total number of dwords to be saved. 1660Sstevel@tonic-gate */ 1670Sstevel@tonic-gate #define PCI_PMCAP_NDWORDS 2 1680Sstevel@tonic-gate #define PCI_AGP_NDWORDS 3 1690Sstevel@tonic-gate #define PCI_SLOTID_NDWORDS 1 1700Sstevel@tonic-gate #define PCI_MSIX_NDWORDS 3 1710Sstevel@tonic-gate #define PCI_CAP_SZUNKNOWN 0 1720Sstevel@tonic-gate 1739970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_SLPRI_NDWORDS 7 1749970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_HOSTSEC_NDWORDS 6 1759970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_INTCONF_NDWORDS 2 1769970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_REVID_NDWORDS 1 1779970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_UNITID_CLUMP_NDWORDS 3 1789970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_ECFG_NDWORDS 3 1799970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_ADDRMAP_NDWORDS PCI_CAP_SZUNKNOWN /* variable */ 1809970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_MSIMAP_NDWORDS 3 1819970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_DIRROUTE_NDWORDS 3 1829970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_VCSET_NDWORDS 3 1839970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_RETRYMODE_NDWORDS 3 1849970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_GEN3_NDWORDS 10 1859970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_FUNCEXT_NDWORDS PCI_CAP_SZUNKNOWN /* variable */ 1869970SJimmy.Vetayases@Sun.COM #define PCI_HTCAP_PM_NDWORDS 2 1879970SJimmy.Vetayases@Sun.COM 1889970SJimmy.Vetayases@Sun.COM 1890Sstevel@tonic-gate #define CAP_ID(confhdl, cap_ptr, xspace) \ 1900Sstevel@tonic-gate ((xspace) ? 0 : pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_ID)) 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate #define NEXT_CAP(confhdl, cap_ptr, xspace) \ 1930Sstevel@tonic-gate ((xspace) ? 0 : \ 1940Sstevel@tonic-gate pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_NEXT_PTR)) 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate extern int pci_resource_setup(dev_info_t *); 1970Sstevel@tonic-gate extern void pci_resource_destroy(dev_info_t *); 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate #ifdef __cplusplus 2000Sstevel@tonic-gate } 2010Sstevel@tonic-gate #endif 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate #endif /* _SYS_PCI_IMPL_H */ 204