pci_tools.h revision 4f5e7dd7
1/* 2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the 6 * "Software"), to deal in the Software without restriction, including 7 * without limitation the rights to use, copy, modify, merge, publish, 8 * distribute, and/or sell copies of the Software, and to permit persons 9 * to whom the Software is furnished to do so, provided that the above 10 * copyright notice(s) and this permission notice appear in all copies of 11 * the Software and that both the above copyright notice(s) and this 12 * permission notice appear in supporting documentation. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 17 * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 18 * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL 19 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING 20 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 21 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 22 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 23 * 24 * Except as contained in this notice, the name of a copyright holder 25 * shall not be used in advertising or otherwise to promote the sale, use 26 * or other dealings in this Software without prior written authorization 27 * of the copyright holder. 28 */ 29#ifndef _SYS_PCI_TOOLS_H 30#define _SYS_PCI_TOOLS_H 31 32#pragma ident "@(#)pci_tools.h 1.4 05/09/28 SMI" 33 34#include <sys/modctl.h> 35 36#ifdef __cplusplus 37extern "C" { 38#endif 39 40/* 41 * Versioning. Have different versions for userland program and drivers, so 42 * they can all stay in sync with each other. 43 */ 44#define PCITOOL_USER_VERSION 1 45#define PCITOOL_DRVR_VERSION 1 46 47/* File suffixes for nexus pcitool nodes. */ 48#define PCI_MINOR_REG "reg" 49#define PCI_MINOR_INTR "intr" 50 51/* 52 * Ioctls for PCI tools. 53 */ 54#define PCITOOL_IOC (('P' << 24) | ('C' << 16) | ('T' << 8)) 55 56/* Read/write a device on a PCI bus, in physical space. */ 57#define PCITOOL_DEVICE_GET_REG (PCITOOL_IOC | 1) 58#define PCITOOL_DEVICE_SET_REG (PCITOOL_IOC | 2) 59 60/* Read/write the PCI nexus bridge, in physical space. */ 61#define PCITOOL_NEXUS_GET_REG (PCITOOL_IOC | 3) 62#define PCITOOL_NEXUS_SET_REG (PCITOOL_IOC | 4) 63 64/* Get/set interrupt-CPU mapping for PCI devices. */ 65#define PCITOOL_DEVICE_GET_INTR (PCITOOL_IOC | 5) 66#define PCITOOL_DEVICE_SET_INTR (PCITOOL_IOC | 6) 67 68/* Return the number of supported interrupts on a PCI bus. */ 69#define PCITOOL_DEVICE_NUM_INTR (PCITOOL_IOC | 7) 70 71 72/* 73 * This file contains data structures for the pci tool. 74 */ 75#define PCITOOL_CONFIG 0 76#define PCITOOL_BAR0 1 77#define PCITOOL_BAR1 2 78#define PCITOOL_BAR2 3 79#define PCITOOL_BAR3 4 80#define PCITOOL_BAR4 5 81#define PCITOOL_BAR5 6 82#define PCITOOL_ROM 7 83 84/* 85 * Pass this through barnum to signal to use a base addr instead. 86 * This is for platforms which do not have a way to automatically map 87 * a selected bank to a base addr. 88 */ 89#define PCITOOL_BASE 0xFF 90 91/* 92 * BAR corresponding to space desired. 93 */ 94typedef enum { 95 config = PCITOOL_CONFIG, 96 bar0 = PCITOOL_BAR0, 97 bar1 = PCITOOL_BAR1, 98 bar2 = PCITOOL_BAR2, 99 bar3 = PCITOOL_BAR3, 100 bar4 = PCITOOL_BAR4, 101 bar5 = PCITOOL_BAR5, 102 rom = PCITOOL_ROM 103} pcitool_bars_t; 104 105 106/* 107 * PCITOOL error numbers. 108 */ 109 110typedef enum { 111 PCITOOL_SUCCESS = 0x0, 112 PCITOOL_INVALID_CPUID, 113 PCITOOL_INVALID_INO, 114 PCITOOL_PENDING_INTRTIMEOUT, 115 PCITOOL_REGPROP_NOTWELLFORMED, 116 PCITOOL_INVALID_ADDRESS, 117 PCITOOL_NOT_ALIGNED, 118 PCITOOL_OUT_OF_RANGE, 119 PCITOOL_END_OF_RANGE, 120 PCITOOL_ROM_DISABLED, 121 PCITOOL_ROM_WRITE, 122 PCITOOL_IO_ERROR, 123 PCITOOL_INVALID_SIZE 124} pcitool_errno_t; 125 126 127/* 128 * PCITOOL_DEVICE_SET_INTR ioctl data structure to re-assign the interrupts. 129 */ 130typedef struct pcitool_intr_set { 131 uint16_t user_version; /* Userland program version - to krnl */ 132 uint16_t drvr_version; /* Driver version - from kernel */ 133 uint32_t ino; /* interrupt to set - to kernel */ 134 uint32_t cpu_id; /* to: cpu to set / from: old cpu returned */ 135 pcitool_errno_t status; /* from kernel */ 136} pcitool_intr_set_t; 137 138 139/* 140 * PCITOOL_DEVICE_GET_INTR ioctl data structure to dump out the 141 * ino mapping information. 142 */ 143 144typedef struct pcitool_intr_dev { 145 uint32_t dev_inst; /* device instance - from kernel */ 146 char driver_name[MAXMODCONFNAME]; /* from kernel */ 147 char path[MAXPATHLEN]; /* device path - from kernel */ 148} pcitool_intr_dev_t; 149 150 151typedef struct pcitool_intr_get { 152 uint16_t user_version; /* Userland program version - to krnl */ 153 uint16_t drvr_version; /* Driver version - from kernel */ 154 uint32_t ino; /* interrupt number - to kernel */ 155 uint8_t num_devs_ret; /* room for this # of devs to be */ 156 /* returned - to kernel */ 157 /* # devs returned - from kernel */ 158 uint8_t num_devs; /* # devs on this ino - from kernel */ 159 /* intrs enabled for devs if > 0 */ 160 uint8_t ctlr; /* controller number - from kernel */ 161 uint32_t cpu_id; /* cpu of interrupt - from kernel */ 162 pcitool_errno_t status; /* returned status - from kernel */ 163 pcitool_intr_dev_t dev[1]; /* start of variable device list */ 164 /* from kernel */ 165} pcitool_intr_get_t; 166 167/* 168 * Get the size needed to return the number of devices wanted. 169 * Can't say num_devs - 1 as num_devs may be unsigned. 170 */ 171#define PCITOOL_IGET_SIZE(num_devs) \ 172 (sizeof (pcitool_intr_get_t) - \ 173 sizeof (pcitool_intr_dev_t) + \ 174 (num_devs * sizeof (pcitool_intr_dev_t))) 175 176/* 177 * Size and endian fields for acc_attr bitmask. 178 */ 179#define PCITOOL_ACC_ATTR_SIZE_MASK 0x3 180#define PCITOOL_ACC_ATTR_SIZE_1 0x0 181#define PCITOOL_ACC_ATTR_SIZE_2 0x1 182#define PCITOOL_ACC_ATTR_SIZE_4 0x2 183#define PCITOOL_ACC_ATTR_SIZE_8 0x3 184#define PCITOOL_ACC_ATTR_SIZE(x) (1 << (x & PCITOOL_ACC_ATTR_SIZE_MASK)) 185 186#define PCITOOL_ACC_ATTR_ENDN_MASK 0x100 187#define PCITOOL_ACC_ATTR_ENDN_LTL 0x0 188#define PCITOOL_ACC_ATTR_ENDN_BIG 0x100 189#define PCITOOL_ACC_IS_BIG_ENDIAN(x) (x & PCITOOL_ACC_ATTR_ENDN_BIG) 190 191/* 192 * Data structure to read and write to pci device registers. 193 * This is the argument to the following ioctls: 194 * PCITOOL_DEVICE_SET/GET_REG 195 * PCITOOL_NEXUS_SET/GET_REG 196 */ 197typedef struct pcitool_reg { 198 uint16_t user_version; /* Userland program version - to krnl */ 199 uint16_t drvr_version; /* Driver version - from kernel */ 200 uint8_t bus_no; /* pci bus - to kernel */ 201 uint8_t dev_no; /* pci dev - to kernel */ 202 uint8_t func_no; /* pci function - to kernel */ 203 uint8_t barnum; /* bank (DEVCTL_NEXUS_SET/GET_REG) or */ 204 /* BAR from pcitools_bar_t */ 205 /* (DEVCTL_DEVICE_SET/GET_REG) */ 206 /* to kernel */ 207 uint64_t offset; /* to kernel */ 208 uint32_t acc_attr; /* access attributes - to kernel */ 209 uint32_t padding1; /* 8-byte align next uint64_t for X86 */ 210 uint64_t data; /* to/from kernel, 64-bit alignment */ 211 uint32_t status; /* from kernel */ 212 uint32_t padding2; /* 8-byte align next uint64_t for X86 */ 213 uint64_t phys_addr; /* from kernel, 64-bit alignment */ 214} pcitool_reg_t; 215 216 217#ifdef __cplusplus 218} 219#endif 220 221#endif /* _SYS_PCI_TOOLS_H */ 222