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 54397Sschwartz * Common Development and Distribution License (the "License"). 64397Sschwartz * 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*10053SEvan.Yan@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_TOOLS_H 270Sstevel@tonic-gate #define _SYS_PCI_TOOLS_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/modctl.h> 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifdef __cplusplus 320Sstevel@tonic-gate extern "C" { 330Sstevel@tonic-gate #endif 340Sstevel@tonic-gate 350Sstevel@tonic-gate /* 364397Sschwartz * Versioning. 370Sstevel@tonic-gate */ 384397Sschwartz #define PCITOOL_V1 1 394397Sschwartz #define PCITOOL_V2 2 404397Sschwartz #define PCITOOL_VERSION PCITOOL_V2 410Sstevel@tonic-gate 42117Sschwartz /* File suffixes for nexus pcitool nodes. */ 43117Sschwartz #define PCI_MINOR_REG "reg" 44117Sschwartz #define PCI_MINOR_INTR "intr" 45117Sschwartz 460Sstevel@tonic-gate /* 470Sstevel@tonic-gate * Ioctls for PCI tools. 480Sstevel@tonic-gate */ 490Sstevel@tonic-gate #define PCITOOL_IOC (('P' << 24) | ('C' << 16) | ('T' << 8)) 500Sstevel@tonic-gate 510Sstevel@tonic-gate /* Read/write a device on a PCI bus, in physical space. */ 524397Sschwartz #define PCITOOL_DEVICE_GET_REG (PCITOOL_IOC | 1) 534397Sschwartz #define PCITOOL_DEVICE_SET_REG (PCITOOL_IOC | 2) 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* Read/write the PCI nexus bridge, in physical space. */ 564397Sschwartz #define PCITOOL_NEXUS_GET_REG (PCITOOL_IOC | 3) 574397Sschwartz #define PCITOOL_NEXUS_SET_REG (PCITOOL_IOC | 4) 580Sstevel@tonic-gate 590Sstevel@tonic-gate /* Get/set interrupt-CPU mapping for PCI devices. */ 604397Sschwartz #define PCITOOL_DEVICE_GET_INTR (PCITOOL_IOC | 5) 614397Sschwartz #define PCITOOL_DEVICE_SET_INTR (PCITOOL_IOC | 6) 620Sstevel@tonic-gate 634397Sschwartz /* Get system interrupt information */ 644397Sschwartz #define PCITOOL_SYSTEM_INTR_INFO (PCITOOL_IOC | 8) 650Sstevel@tonic-gate 660Sstevel@tonic-gate /* 670Sstevel@tonic-gate * This file contains data structures for the pci tool. 680Sstevel@tonic-gate */ 690Sstevel@tonic-gate #define PCITOOL_CONFIG 0 700Sstevel@tonic-gate #define PCITOOL_BAR0 1 710Sstevel@tonic-gate #define PCITOOL_BAR1 2 720Sstevel@tonic-gate #define PCITOOL_BAR2 3 730Sstevel@tonic-gate #define PCITOOL_BAR3 4 740Sstevel@tonic-gate #define PCITOOL_BAR4 5 750Sstevel@tonic-gate #define PCITOOL_BAR5 6 760Sstevel@tonic-gate #define PCITOOL_ROM 7 770Sstevel@tonic-gate 780Sstevel@tonic-gate /* 79624Sschwartz * Pass this through barnum to signal to use a base addr instead. 80624Sschwartz * This is for platforms which do not have a way to automatically map 81624Sschwartz * a selected bank to a base addr. 82624Sschwartz */ 83624Sschwartz #define PCITOOL_BASE 0xFF 84624Sschwartz 85624Sschwartz /* 860Sstevel@tonic-gate * BAR corresponding to space desired. 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate typedef enum { 890Sstevel@tonic-gate config = PCITOOL_CONFIG, 900Sstevel@tonic-gate bar0 = PCITOOL_BAR0, 910Sstevel@tonic-gate bar1 = PCITOOL_BAR1, 920Sstevel@tonic-gate bar2 = PCITOOL_BAR2, 930Sstevel@tonic-gate bar3 = PCITOOL_BAR3, 940Sstevel@tonic-gate bar4 = PCITOOL_BAR4, 950Sstevel@tonic-gate bar5 = PCITOOL_BAR5, 960Sstevel@tonic-gate rom = PCITOOL_ROM 970Sstevel@tonic-gate } pcitool_bars_t; 980Sstevel@tonic-gate 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* 1010Sstevel@tonic-gate * PCITOOL error numbers. 1020Sstevel@tonic-gate */ 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate typedef enum { 1050Sstevel@tonic-gate PCITOOL_SUCCESS = 0x0, 1060Sstevel@tonic-gate PCITOOL_INVALID_CPUID, 1070Sstevel@tonic-gate PCITOOL_INVALID_INO, 108*10053SEvan.Yan@Sun.COM PCITOOL_INVALID_MSI, 1090Sstevel@tonic-gate PCITOOL_PENDING_INTRTIMEOUT, 1100Sstevel@tonic-gate PCITOOL_REGPROP_NOTWELLFORMED, 1110Sstevel@tonic-gate PCITOOL_INVALID_ADDRESS, 1120Sstevel@tonic-gate PCITOOL_NOT_ALIGNED, 1130Sstevel@tonic-gate PCITOOL_OUT_OF_RANGE, 1140Sstevel@tonic-gate PCITOOL_END_OF_RANGE, 1150Sstevel@tonic-gate PCITOOL_ROM_DISABLED, 1160Sstevel@tonic-gate PCITOOL_ROM_WRITE, 1170Sstevel@tonic-gate PCITOOL_IO_ERROR, 1180Sstevel@tonic-gate PCITOOL_INVALID_SIZE 1190Sstevel@tonic-gate } pcitool_errno_t; 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* 1230Sstevel@tonic-gate * PCITOOL_DEVICE_SET_INTR ioctl data structure to re-assign the interrupts. 1240Sstevel@tonic-gate */ 1250Sstevel@tonic-gate typedef struct pcitool_intr_set { 1260Sstevel@tonic-gate uint16_t user_version; /* Userland program version - to krnl */ 1270Sstevel@tonic-gate uint16_t drvr_version; /* Driver version - from kernel */ 1280Sstevel@tonic-gate uint32_t ino; /* interrupt to set - to kernel */ 129*10053SEvan.Yan@Sun.COM uint32_t msi; /* Specific MSI to set - to kernel */ 1300Sstevel@tonic-gate uint32_t cpu_id; /* to: cpu to set / from: old cpu returned */ 131*10053SEvan.Yan@Sun.COM uint32_t flags; /* to kernel */ 1320Sstevel@tonic-gate pcitool_errno_t status; /* from kernel */ 1330Sstevel@tonic-gate } pcitool_intr_set_t; 1340Sstevel@tonic-gate 1354397Sschwartz /* 136*10053SEvan.Yan@Sun.COM * Flags for pcitool_intr_get/set_t/info_t 1374397Sschwartz */ 138*10053SEvan.Yan@Sun.COM #define PCITOOL_INTR_FLAG_SET_GROUP 0x1 139*10053SEvan.Yan@Sun.COM #define PCITOOL_INTR_FLAG_GET_MSI 0x2 140*10053SEvan.Yan@Sun.COM #define PCITOOL_INTR_FLAG_SET_MSI 0x4 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate /* 1430Sstevel@tonic-gate * PCITOOL_DEVICE_GET_INTR ioctl data structure to dump out the 1440Sstevel@tonic-gate * ino mapping information. 1450Sstevel@tonic-gate */ 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate typedef struct pcitool_intr_dev { 1480Sstevel@tonic-gate uint32_t dev_inst; /* device instance - from kernel */ 1490Sstevel@tonic-gate char driver_name[MAXMODCONFNAME]; /* from kernel */ 1500Sstevel@tonic-gate char path[MAXPATHLEN]; /* device path - from kernel */ 1510Sstevel@tonic-gate } pcitool_intr_dev_t; 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate typedef struct pcitool_intr_get { 1540Sstevel@tonic-gate uint16_t user_version; /* Userland program version - to krnl */ 1550Sstevel@tonic-gate uint16_t drvr_version; /* Driver version - from kernel */ 1560Sstevel@tonic-gate uint32_t ino; /* interrupt number - to kernel */ 157*10053SEvan.Yan@Sun.COM uint32_t msi; /* MSI number - to kernel */ 1580Sstevel@tonic-gate uint8_t num_devs_ret; /* room for this # of devs to be */ 1590Sstevel@tonic-gate /* returned - to kernel */ 1600Sstevel@tonic-gate /* # devs returned - from kernel */ 1610Sstevel@tonic-gate uint8_t num_devs; /* # devs on this ino - from kernel */ 1620Sstevel@tonic-gate /* intrs enabled for devs if > 0 */ 1630Sstevel@tonic-gate uint8_t ctlr; /* controller number - from kernel */ 1640Sstevel@tonic-gate uint32_t cpu_id; /* cpu of interrupt - from kernel */ 165*10053SEvan.Yan@Sun.COM uint32_t flags; /* to kernel */ 1660Sstevel@tonic-gate pcitool_errno_t status; /* returned status - from kernel */ 1670Sstevel@tonic-gate pcitool_intr_dev_t dev[1]; /* start of variable device list */ 1680Sstevel@tonic-gate /* from kernel */ 1690Sstevel@tonic-gate } pcitool_intr_get_t; 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate /* 1720Sstevel@tonic-gate * Get the size needed to return the number of devices wanted. 1730Sstevel@tonic-gate * Can't say num_devs - 1 as num_devs may be unsigned. 1740Sstevel@tonic-gate */ 1750Sstevel@tonic-gate #define PCITOOL_IGET_SIZE(num_devs) \ 1760Sstevel@tonic-gate (sizeof (pcitool_intr_get_t) - \ 1770Sstevel@tonic-gate sizeof (pcitool_intr_dev_t) + \ 1780Sstevel@tonic-gate (num_devs * sizeof (pcitool_intr_dev_t))) 1790Sstevel@tonic-gate 1804397Sschwartz typedef struct pcitool_intr_info { 1814397Sschwartz uint16_t user_version; /* Userland program version - to krnl */ 1824397Sschwartz uint16_t drvr_version; /* Driver version - from kernel */ 183*10053SEvan.Yan@Sun.COM uint32_t flags; /* to kernel */ 1844397Sschwartz uint32_t num_intr; /* Number of intrs suppt by nexus */ 1854397Sschwartz uint32_t ctlr_version; /* Intr ctlr HW version - from kernel */ 1864397Sschwartz uchar_t ctlr_type; /* A PCITOOL_CTLR_TYPE - from kernel */ 1874397Sschwartz } pcitool_intr_info_t; 1884397Sschwartz 1894397Sschwartz /* 1904397Sschwartz * Interrupt controller types 1914397Sschwartz */ 1924397Sschwartz #define PCITOOL_CTLR_TYPE_UNKNOWN 0 1934397Sschwartz #define PCITOOL_CTLR_TYPE_RISC 1 1944397Sschwartz #define PCITOOL_CTLR_TYPE_UPPC 2 1954397Sschwartz #define PCITOOL_CTLR_TYPE_PCPLUSMP 3 1964397Sschwartz 1970Sstevel@tonic-gate /* 1980Sstevel@tonic-gate * Size and endian fields for acc_attr bitmask. 1990Sstevel@tonic-gate */ 2000Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_SIZE_MASK 0x3 2010Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_SIZE_1 0x0 2020Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_SIZE_2 0x1 2030Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_SIZE_4 0x2 2040Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_SIZE_8 0x3 2050Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_SIZE(x) (1 << (x & PCITOOL_ACC_ATTR_SIZE_MASK)) 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_ENDN_MASK 0x100 2080Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_ENDN_LTL 0x0 2090Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_ENDN_BIG 0x100 2100Sstevel@tonic-gate #define PCITOOL_ACC_IS_BIG_ENDIAN(x) (x & PCITOOL_ACC_ATTR_ENDN_BIG) 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate /* 2130Sstevel@tonic-gate * Data stucture to read and write to pci device registers. 2140Sstevel@tonic-gate * This is the argument to the following ioctls: 2150Sstevel@tonic-gate * PCITOOL_DEVICE_SET/GET_REG 2160Sstevel@tonic-gate * PCITOOL_NEXUS_SET/GET_REG 2170Sstevel@tonic-gate */ 2180Sstevel@tonic-gate typedef struct pcitool_reg { 2190Sstevel@tonic-gate uint16_t user_version; /* Userland program version - to krnl */ 2200Sstevel@tonic-gate uint16_t drvr_version; /* Driver version - from kernel */ 2210Sstevel@tonic-gate uint8_t bus_no; /* pci bus - to kernel */ 2220Sstevel@tonic-gate uint8_t dev_no; /* pci dev - to kernel */ 2230Sstevel@tonic-gate uint8_t func_no; /* pci function - to kernel */ 2240Sstevel@tonic-gate uint8_t barnum; /* bank (DEVCTL_NEXUS_SET/GET_REG) or */ 2250Sstevel@tonic-gate /* BAR from pcitools_bar_t */ 2260Sstevel@tonic-gate /* (DEVCTL_DEVICE_SET/GET_REG) */ 2270Sstevel@tonic-gate /* to kernel */ 2280Sstevel@tonic-gate uint64_t offset; /* to kernel */ 2290Sstevel@tonic-gate uint32_t acc_attr; /* access attributes - to kernel */ 2300Sstevel@tonic-gate uint32_t padding1; /* 8-byte align next uint64_t for X86 */ 2310Sstevel@tonic-gate uint64_t data; /* to/from kernel, 64-bit alignment */ 2320Sstevel@tonic-gate uint32_t status; /* from kernel */ 2330Sstevel@tonic-gate uint32_t padding2; /* 8-byte align next uint64_t for X86 */ 2340Sstevel@tonic-gate uint64_t phys_addr; /* from kernel, 64-bit alignment */ 2350Sstevel@tonic-gate } pcitool_reg_t; 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate #ifdef __cplusplus 2390Sstevel@tonic-gate } 2400Sstevel@tonic-gate #endif 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate #endif /* _SYS_PCI_TOOLS_H */ 243