17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 544961713Sgirish * Common Development and Distribution License (the "License"). 644961713Sgirish * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22ffa17327SGuoli Shu * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 24b5cf5bc2SHans Rosenfeld * Copyright 2018 Joyent, Inc. 25*60bb5373SAndy Fiddaman * Copyright 2023 Oxide Computer Company 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #ifndef _SYS_PCI_IMPL_H 297c478bd9Sstevel@tonic-gate #define _SYS_PCI_IMPL_H 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/dditypes.h> 327c478bd9Sstevel@tonic-gate #include <sys/memlist.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 357c478bd9Sstevel@tonic-gate extern "C" { 367c478bd9Sstevel@tonic-gate #endif 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64) 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * There are two ways to access the PCI configuration space on X86 427c478bd9Sstevel@tonic-gate * Access method 2 is the older method 437c478bd9Sstevel@tonic-gate * Access method 1 is the newer method and is preferred because 447c478bd9Sstevel@tonic-gate * of the problems in trying to lock the configuration space 457c478bd9Sstevel@tonic-gate * for MP machines using method 2. See PCI Local BUS Specification 467c478bd9Sstevel@tonic-gate * Revision 2.0 section 3.6.4.1 for more details. 477c478bd9Sstevel@tonic-gate * 487c478bd9Sstevel@tonic-gate * In addition, on IBM Sandalfoot and a few related machines there's 497c478bd9Sstevel@tonic-gate * still another mechanism. See PReP 1.1 section 6.1.7. 507c478bd9Sstevel@tonic-gate */ 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #define PCI_MECHANISM_UNKNOWN -1 537c478bd9Sstevel@tonic-gate #define PCI_MECHANISM_NONE 0 54c2e7b48dSkalai #if defined(__i386) || defined(__amd64) 557c478bd9Sstevel@tonic-gate #define PCI_MECHANISM_1 1 567c478bd9Sstevel@tonic-gate #define PCI_MECHANISM_2 2 577c478bd9Sstevel@tonic-gate #else 587c478bd9Sstevel@tonic-gate #error "Unknown processor type" 597c478bd9Sstevel@tonic-gate #endif 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate #ifndef FALSE 637c478bd9Sstevel@tonic-gate #define FALSE 0 647c478bd9Sstevel@tonic-gate #endif 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate #ifndef TRUE 677c478bd9Sstevel@tonic-gate #define TRUE 1 687c478bd9Sstevel@tonic-gate #endif 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate #define PCI_FUNC_MASK 0x07 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* these macros apply to Configuration Mechanism #1 */ 737c478bd9Sstevel@tonic-gate #define PCI_CONFADD 0xcf8 747c478bd9Sstevel@tonic-gate #define PCI_PMC 0xcfb 757c478bd9Sstevel@tonic-gate #define PCI_CONFDATA 0xcfc 767c478bd9Sstevel@tonic-gate #define PCI_CONE 0x80000000 777c478bd9Sstevel@tonic-gate #define PCI_CADDR1(bus, device, function, reg) \ 787c478bd9Sstevel@tonic-gate (PCI_CONE | (((bus) & 0xff) << 16) | (((device & 0x1f)) << 11) \ 797c478bd9Sstevel@tonic-gate | (((function) & 0x7) << 8) | ((reg) & 0xfc)) 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate /* these macros apply to Configuration Mechanism #2 */ 827c478bd9Sstevel@tonic-gate #define PCI_CSE_PORT 0xcf8 837c478bd9Sstevel@tonic-gate #define PCI_FORW_PORT 0xcfa 847c478bd9Sstevel@tonic-gate #define PCI_CADDR2(device, indx) \ 857c478bd9Sstevel@tonic-gate (0xc000 | (((device) & 0xf) << 8) | (indx)) 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate typedef struct pci_acc_cfblk { 887c478bd9Sstevel@tonic-gate uchar_t c_busnum; /* bus number */ 897c478bd9Sstevel@tonic-gate uchar_t c_devnum; /* device number */ 907c478bd9Sstevel@tonic-gate uchar_t c_funcnum; /* function number */ 917c478bd9Sstevel@tonic-gate uchar_t c_fill; /* reserve field */ 927c478bd9Sstevel@tonic-gate } pci_acc_cfblk_t; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate struct pci_bus_resource { 952f283da5SDan Mick struct memlist *io_avail; /* available free io res */ 962f283da5SDan Mick struct memlist *io_used; /* used io res */ 972f283da5SDan Mick struct memlist *mem_avail; /* available free mem res */ 982f283da5SDan Mick struct memlist *mem_used; /* used mem res */ 992f283da5SDan Mick struct memlist *pmem_avail; /* available free prefetchable mem res */ 1002f283da5SDan Mick struct memlist *pmem_used; /* used prefetchable mem res */ 1012f283da5SDan Mick struct memlist *bus_avail; /* available free bus res */ 10205f867c3Sgs150176 /* bus_space_used not needed; can read from regs */ 1037c478bd9Sstevel@tonic-gate dev_info_t *dip; /* devinfo node */ 1047c478bd9Sstevel@tonic-gate void *privdata; /* private data for configuration */ 1057c478bd9Sstevel@tonic-gate uchar_t par_bus; /* parent bus number */ 1067c478bd9Sstevel@tonic-gate uchar_t sub_bus; /* highest bus number beyond this bridge */ 1077c478bd9Sstevel@tonic-gate uchar_t root_addr; /* legacy peer bus address assignment */ 10805f867c3Sgs150176 uchar_t num_cbb; /* # of CardBus Bridges on the bus */ 109*60bb5373SAndy Fiddaman uchar_t num_bridge; /* number of bridges under this bus */ 11005f867c3Sgs150176 boolean_t io_reprogram; /* need io reprog on this bus */ 11105f867c3Sgs150176 boolean_t mem_reprogram; /* need mem reprog on this bus */ 11205f867c3Sgs150176 boolean_t subtractive; /* subtractive PPB */ 113b5cf5bc2SHans Rosenfeld uint64_t mem_size; /* existing children required MEM space size */ 114*60bb5373SAndy Fiddaman uint64_t pmem_size; /* existing children required PMEM space size */ 115*60bb5373SAndy Fiddaman uint64_t mem_buffer; /* memory available for proactively */ 116*60bb5373SAndy Fiddaman /* allocating to bridges for hotplug */ 117ffa17327SGuoli Shu uint_t io_size; /* existing children required I/O space size */ 1187c478bd9Sstevel@tonic-gate }; 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate extern struct pci_bus_resource *pci_bus_res; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* 1237c478bd9Sstevel@tonic-gate * For now, x86-only to avoid conflicts with <sys/memlist_impl.h> 1247c478bd9Sstevel@tonic-gate */ 125a3114836SGerry Liu #define memlist_find memlist_find_pci 126a3114836SGerry Liu #define memlist_insert memlist_insert_pci 127a3114836SGerry Liu 1287c478bd9Sstevel@tonic-gate extern struct memlist *memlist_alloc(void); 1297c478bd9Sstevel@tonic-gate extern void memlist_free(struct memlist *); 13005f867c3Sgs150176 extern void memlist_free_all(struct memlist **); 1317c478bd9Sstevel@tonic-gate extern void memlist_insert(struct memlist **, uint64_t, uint64_t); 1327c478bd9Sstevel@tonic-gate extern int memlist_remove(struct memlist **, uint64_t, uint64_t); 1337c478bd9Sstevel@tonic-gate extern uint64_t memlist_find(struct memlist **, uint64_t, int); 13405f867c3Sgs150176 extern uint64_t memlist_find_with_startaddr(struct memlist **, uint64_t, 13505f867c3Sgs150176 uint64_t, int); 1367c478bd9Sstevel@tonic-gate extern void memlist_dump(struct memlist *); 1372f283da5SDan Mick extern void memlist_subsume(struct memlist **, struct memlist **); 13805f867c3Sgs150176 extern void memlist_merge(struct memlist **, struct memlist **); 1397c478bd9Sstevel@tonic-gate extern struct memlist *memlist_dup(struct memlist *); 1407c478bd9Sstevel@tonic-gate extern int memlist_count(struct memlist *); 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate #endif /* __i386 || __amd64 */ 1437c478bd9Sstevel@tonic-gate 14426947304SEvan Yan /* Definitions for minor numbers */ 14526947304SEvan Yan #define PCI_MINOR_NUM(x, y) (((uint_t)(x) << 8) | ((y) & 0xFF)) 14626947304SEvan Yan #define PCI_MINOR_NUM_TO_PCI_DEVNUM(x) ((x) & 0xFF) 14726947304SEvan Yan #define PCI_MINOR_NUM_TO_INSTANCE(x) ((x) >> 8) 14826947304SEvan Yan #define PCI_DEVCTL_MINOR 0xFF 14926947304SEvan Yan 15026947304SEvan Yan /* 15126947304SEvan Yan * Minor numbers for dedicated pcitool nodes. 15226947304SEvan Yan * Note that FF and FE minor numbers are used for other minor nodes. 15326947304SEvan Yan */ 15426947304SEvan Yan #define PCI_TOOL_REG_MINOR_NUM 0xFD 15526947304SEvan Yan #define PCI_TOOL_INTR_MINOR_NUM 0xFC 15626947304SEvan Yan 15726947304SEvan Yan /* pci devctl soft state flag */ 15826947304SEvan Yan #define PCI_SOFT_STATE_CLOSED 0x0 15926947304SEvan Yan #define PCI_SOFT_STATE_OPEN 0x1 16026947304SEvan Yan #define PCI_SOFT_STATE_OPEN_EXCL 0x2 16126947304SEvan Yan 1627c478bd9Sstevel@tonic-gate /* 1637c478bd9Sstevel@tonic-gate * PCI capability related definitions. 1647c478bd9Sstevel@tonic-gate */ 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate /* 1677c478bd9Sstevel@tonic-gate * Minimum number of dwords to be saved. 1687c478bd9Sstevel@tonic-gate */ 1697c478bd9Sstevel@tonic-gate #define PCI_MSI_MIN_WORDS 3 1707c478bd9Sstevel@tonic-gate #define PCI_PCIX_MIN_WORDS 2 1717c478bd9Sstevel@tonic-gate #define PCI_PCIE_MIN_WORDS 5 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate /* 1747c478bd9Sstevel@tonic-gate * Total number of dwords to be saved. 1757c478bd9Sstevel@tonic-gate */ 1767c478bd9Sstevel@tonic-gate #define PCI_PMCAP_NDWORDS 2 1777c478bd9Sstevel@tonic-gate #define PCI_AGP_NDWORDS 3 1787c478bd9Sstevel@tonic-gate #define PCI_SLOTID_NDWORDS 1 1797c478bd9Sstevel@tonic-gate #define PCI_MSIX_NDWORDS 3 1807c478bd9Sstevel@tonic-gate #define PCI_CAP_SZUNKNOWN 0 1817c478bd9Sstevel@tonic-gate 182cb7ea99dSJimmy Vetayases #define PCI_HTCAP_SLPRI_NDWORDS 7 183cb7ea99dSJimmy Vetayases #define PCI_HTCAP_HOSTSEC_NDWORDS 6 184cb7ea99dSJimmy Vetayases #define PCI_HTCAP_INTCONF_NDWORDS 2 185cb7ea99dSJimmy Vetayases #define PCI_HTCAP_REVID_NDWORDS 1 186cb7ea99dSJimmy Vetayases #define PCI_HTCAP_UNITID_CLUMP_NDWORDS 3 187cb7ea99dSJimmy Vetayases #define PCI_HTCAP_ECFG_NDWORDS 3 188cb7ea99dSJimmy Vetayases #define PCI_HTCAP_ADDRMAP_NDWORDS PCI_CAP_SZUNKNOWN /* variable */ 189cb7ea99dSJimmy Vetayases #define PCI_HTCAP_MSIMAP_NDWORDS 3 190cb7ea99dSJimmy Vetayases #define PCI_HTCAP_DIRROUTE_NDWORDS 3 191cb7ea99dSJimmy Vetayases #define PCI_HTCAP_VCSET_NDWORDS 3 192cb7ea99dSJimmy Vetayases #define PCI_HTCAP_RETRYMODE_NDWORDS 3 193cb7ea99dSJimmy Vetayases #define PCI_HTCAP_GEN3_NDWORDS 10 194cb7ea99dSJimmy Vetayases #define PCI_HTCAP_FUNCEXT_NDWORDS PCI_CAP_SZUNKNOWN /* variable */ 195cb7ea99dSJimmy Vetayases #define PCI_HTCAP_PM_NDWORDS 2 196cb7ea99dSJimmy Vetayases 197cb7ea99dSJimmy Vetayases 1987c478bd9Sstevel@tonic-gate #define CAP_ID(confhdl, cap_ptr, xspace) \ 1997c478bd9Sstevel@tonic-gate ((xspace) ? 0 : pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_ID)) 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate #define NEXT_CAP(confhdl, cap_ptr, xspace) \ 2027c478bd9Sstevel@tonic-gate ((xspace) ? 0 : \ 2037c478bd9Sstevel@tonic-gate pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_NEXT_PTR)) 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate extern int pci_resource_setup(dev_info_t *); 2067c478bd9Sstevel@tonic-gate extern void pci_resource_destroy(dev_info_t *); 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate #endif 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate #endif /* _SYS_PCI_IMPL_H */ 213