1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23 */ 24 25 #ifndef _SYS_PCI_TOOLS_H 26 #define _SYS_PCI_TOOLS_H 27 28 #include <sys/modctl.h> 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 /* 35 * Versioning. 36 */ 37 #define PCITOOL_V1 1 38 #define PCITOOL_V2 2 39 #define PCITOOL_VERSION PCITOOL_V2 40 41 /* File suffixes for nexus pcitool nodes. */ 42 #define PCI_MINOR_REG "reg" 43 #define PCI_MINOR_INTR "intr" 44 45 /* 46 * Ioctls for PCI tools. 47 */ 48 #define PCITOOL_IOC (('P' << 24) | ('C' << 16) | ('T' << 8)) 49 50 /* Read/write a device on a PCI bus, in physical space. */ 51 #define PCITOOL_DEVICE_GET_REG (PCITOOL_IOC | 1) 52 #define PCITOOL_DEVICE_SET_REG (PCITOOL_IOC | 2) 53 54 /* Read/write the PCI nexus bridge, in physical space. */ 55 #define PCITOOL_NEXUS_GET_REG (PCITOOL_IOC | 3) 56 #define PCITOOL_NEXUS_SET_REG (PCITOOL_IOC | 4) 57 58 /* Get/set interrupt-CPU mapping for PCI devices. */ 59 #define PCITOOL_DEVICE_GET_INTR (PCITOOL_IOC | 5) 60 #define PCITOOL_DEVICE_SET_INTR (PCITOOL_IOC | 6) 61 62 /* Get system interrupt information */ 63 #define PCITOOL_SYSTEM_INTR_INFO (PCITOOL_IOC | 8) 64 65 /* 66 * This file contains data structures for the pci tool. 67 */ 68 #define PCITOOL_CONFIG 0 69 #define PCITOOL_BAR0 1 70 #define PCITOOL_BAR1 2 71 #define PCITOOL_BAR2 3 72 #define PCITOOL_BAR3 4 73 #define PCITOOL_BAR4 5 74 #define PCITOOL_BAR5 6 75 #define PCITOOL_ROM 7 76 77 /* 78 * Pass this through barnum to signal to use a base addr instead. 79 * This is for platforms which do not have a way to automatically map 80 * a selected bank to a base addr. 81 */ 82 #define PCITOOL_BASE 0xFF 83 84 /* 85 * BAR corresponding to space desired. 86 */ 87 typedef enum { 88 config = PCITOOL_CONFIG, 89 bar0 = PCITOOL_BAR0, 90 bar1 = PCITOOL_BAR1, 91 bar2 = PCITOOL_BAR2, 92 bar3 = PCITOOL_BAR3, 93 bar4 = PCITOOL_BAR4, 94 bar5 = PCITOOL_BAR5, 95 rom = PCITOOL_ROM 96 } pcitool_bars_t; 97 98 99 /* 100 * PCITOOL error numbers. 101 */ 102 103 typedef enum { 104 PCITOOL_SUCCESS = 0x0, 105 PCITOOL_INVALID_CPUID, 106 PCITOOL_INVALID_INO, 107 PCITOOL_INVALID_MSI, 108 PCITOOL_PENDING_INTRTIMEOUT, 109 PCITOOL_REGPROP_NOTWELLFORMED, 110 PCITOOL_INVALID_ADDRESS, 111 PCITOOL_NOT_ALIGNED, 112 PCITOOL_OUT_OF_RANGE, 113 PCITOOL_END_OF_RANGE, 114 PCITOOL_ROM_DISABLED, 115 PCITOOL_ROM_WRITE, 116 PCITOOL_IO_ERROR, 117 PCITOOL_INVALID_SIZE, 118 PCITOOL_UNKNOWN_HEADER_TYPE, 119 PCITOOL_INVALID_REGOFF 120 } pcitool_errno_t; 121 122 123 /* 124 * PCITOOL_DEVICE_SET_INTR ioctl data structure to re-assign the interrupts. 125 */ 126 typedef struct pcitool_intr_set { 127 uint16_t user_version; /* Userland program version - to krnl */ 128 uint16_t drvr_version; /* Driver version - from kernel */ 129 uint32_t ino; /* interrupt to set - to kernel */ 130 uint32_t msi; /* Specific MSI to set - to kernel */ 131 uint32_t cpu_id; /* to: cpu to set / from: old cpu returned */ 132 uint32_t old_cpu; /* to/from kernel: old cpu id */ 133 uint32_t flags; /* to kernel */ 134 pcitool_errno_t status; /* from kernel */ 135 } pcitool_intr_set_t; 136 137 /* 138 * Flags for pcitool_intr_get/set_t/info_t 139 */ 140 #define PCITOOL_INTR_FLAG_SET_GROUP 0x1 141 #define PCITOOL_INTR_FLAG_GET_MSI 0x2 142 #define PCITOOL_INTR_FLAG_SET_MSI 0x4 143 144 /* 145 * PCITOOL_DEVICE_GET_INTR ioctl data structure to dump out the 146 * ino mapping information. 147 */ 148 149 typedef struct pcitool_intr_dev { 150 uint32_t dev_inst; /* device instance - from kernel */ 151 char driver_name[MAXMODCONFNAME]; /* from kernel */ 152 char path[MAXPATHLEN]; /* device path - from kernel */ 153 } pcitool_intr_dev_t; 154 155 typedef struct pcitool_intr_get { 156 uint16_t user_version; /* Userland program version - to krnl */ 157 uint16_t drvr_version; /* Driver version - from kernel */ 158 uint32_t ino; /* interrupt number - to kernel */ 159 uint32_t msi; /* MSI number - to kernel */ 160 uint8_t num_devs_ret; /* room for this # of devs to be */ 161 /* returned - to kernel */ 162 /* # devs returned - from kernel */ 163 uint8_t num_devs; /* # devs on this ino - from kernel */ 164 /* intrs enabled for devs if > 0 */ 165 uint8_t ctlr; /* controller number - from kernel */ 166 uint32_t cpu_id; /* cpu of interrupt - from kernel */ 167 uint32_t flags; /* to kernel */ 168 pcitool_errno_t status; /* returned status - from kernel */ 169 pcitool_intr_dev_t dev[1]; /* start of variable device list */ 170 /* from kernel */ 171 } pcitool_intr_get_t; 172 173 /* 174 * Get the size needed to return the number of devices wanted. 175 * Can't say num_devs - 1 as num_devs may be unsigned. 176 */ 177 #define PCITOOL_IGET_SIZE(num_devs) \ 178 (sizeof (pcitool_intr_get_t) - \ 179 sizeof (pcitool_intr_dev_t) + \ 180 (num_devs * sizeof (pcitool_intr_dev_t))) 181 182 typedef struct pcitool_intr_info { 183 uint16_t user_version; /* Userland program version - to krnl */ 184 uint16_t drvr_version; /* Driver version - from kernel */ 185 uint32_t flags; /* to kernel */ 186 uint32_t num_intr; /* Number of intrs suppt by nexus */ 187 uint32_t num_cpu; 188 uint32_t ctlr_version; /* Intr ctlr HW version - from kernel */ 189 uchar_t ctlr_type; /* A PCITOOL_CTLR_TYPE - from kernel */ 190 } pcitool_intr_info_t; 191 192 /* 193 * Interrupt controller types 194 */ 195 #define PCITOOL_CTLR_TYPE_UNKNOWN 0 196 #define PCITOOL_CTLR_TYPE_RISC 1 197 #define PCITOOL_CTLR_TYPE_UPPC 2 198 #define PCITOOL_CTLR_TYPE_PCPLUSMP 3 199 #define PCITOOL_CTLR_TYPE_APIX 4 200 201 /* 202 * Size and endian fields for acc_attr bitmask. 203 */ 204 #define PCITOOL_ACC_ATTR_SIZE_MASK 0x3 205 #define PCITOOL_ACC_ATTR_SIZE_1 0x0 206 #define PCITOOL_ACC_ATTR_SIZE_2 0x1 207 #define PCITOOL_ACC_ATTR_SIZE_4 0x2 208 #define PCITOOL_ACC_ATTR_SIZE_8 0x3 209 #define PCITOOL_ACC_ATTR_SIZE(x) (1 << (x & PCITOOL_ACC_ATTR_SIZE_MASK)) 210 211 #define PCITOOL_ACC_ATTR_ENDN_MASK 0x100 212 #define PCITOOL_ACC_ATTR_ENDN_LTL 0x0 213 #define PCITOOL_ACC_ATTR_ENDN_BIG 0x100 214 #define PCITOOL_ACC_IS_BIG_ENDIAN(x) (x & PCITOOL_ACC_ATTR_ENDN_BIG) 215 216 /* 217 * Data stucture to read and write to pci device registers. 218 * This is the argument to the following ioctls: 219 * PCITOOL_DEVICE_SET/GET_REG 220 * PCITOOL_NEXUS_SET/GET_REG 221 */ 222 typedef struct pcitool_reg { 223 uint16_t user_version; /* Userland program version - to krnl */ 224 uint16_t drvr_version; /* Driver version - from kernel */ 225 uint8_t bus_no; /* pci bus - to kernel */ 226 uint8_t dev_no; /* pci dev - to kernel */ 227 uint8_t func_no; /* pci function - to kernel */ 228 uint8_t barnum; /* bank (DEVCTL_NEXUS_SET/GET_REG) or */ 229 /* BAR from pcitools_bar_t */ 230 /* (DEVCTL_DEVICE_SET/GET_REG) */ 231 /* to kernel */ 232 uint64_t offset; /* to kernel */ 233 uint32_t acc_attr; /* access attributes - to kernel */ 234 uint32_t padding1; /* 8-byte align next uint64_t for X86 */ 235 uint64_t data; /* to/from kernel, 64-bit alignment */ 236 uint32_t status; /* from kernel */ 237 uint32_t padding2; /* 8-byte align next uint64_t for X86 */ 238 uint64_t phys_addr; /* from kernel, 64-bit alignment */ 239 } pcitool_reg_t; 240 241 242 #ifdef __cplusplus 243 } 244 #endif 245 246 #endif /* _SYS_PCI_TOOLS_H */ 247