2 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
23 #ifndef _SYS_PCI_TOOLS_H
24 #define _SYS_PCI_TOOLS_H
26 #pragma ident "@(#)pci_tools.h 1.4 05/09/28 SMI"
28 #include <sys/modctl.h>
35 * Versioning. Have different versions for userland program and drivers, so
36 * they can all stay in sync with each other.
38 #define PCITOOL_USER_VERSION 1
39 #define PCITOOL_DRVR_VERSION 1
41 /* File suffixes for nexus pcitool nodes. */
42 #define PCI_MINOR_REG "reg"
43 #define PCI_MINOR_INTR "intr"
46 * Ioctls for PCI tools.
48 #define PCITOOL_IOC (('P' << 24) | ('C' << 16) | ('T' << 8))
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)
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)
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)
62 /* Return the number of supported interrupts on a PCI bus. */
63 #define PCITOOL_DEVICE_NUM_INTR (PCITOOL_IOC | 7)
67 * This file contains data structures for the pci tool.
69 #define PCITOOL_CONFIG 0
70 #define PCITOOL_BAR0 1
71 #define PCITOOL_BAR1 2
72 #define PCITOOL_BAR2 3
73 #define PCITOOL_BAR3 4
74 #define PCITOOL_BAR4 5
75 #define PCITOOL_BAR5 6
79 * Pass this through barnum to signal to use a base addr instead.
80 * This is for platforms which do not have a way to automatically map
81 * a selected bank to a base addr.
83 #define PCITOOL_BASE 0xFF
86 * BAR corresponding to space desired.
89 config = PCITOOL_CONFIG,
101 * PCITOOL error numbers.
105 PCITOOL_SUCCESS = 0x0,
106 PCITOOL_INVALID_CPUID,
108 PCITOOL_PENDING_INTRTIMEOUT,
109 PCITOOL_REGPROP_NOTWELLFORMED,
110 PCITOOL_INVALID_ADDRESS,
112 PCITOOL_OUT_OF_RANGE,
113 PCITOOL_END_OF_RANGE,
114 PCITOOL_ROM_DISABLED,
122 * PCITOOL_DEVICE_SET_INTR ioctl data structure to re-assign the interrupts.
124 typedef struct pcitool_intr_set {
125 uint16_t user_version; /* Userland program version - to krnl */
126 uint16_t drvr_version; /* Driver version - from kernel */
127 uint32_t ino; /* interrupt to set - to kernel */
128 uint32_t cpu_id; /* to: cpu to set / from: old cpu returned */
129 pcitool_errno_t status; /* from kernel */
130 } pcitool_intr_set_t;
134 * PCITOOL_DEVICE_GET_INTR ioctl data structure to dump out the
135 * ino mapping information.
138 typedef struct pcitool_intr_dev {
139 uint32_t dev_inst; /* device instance - from kernel */
140 char driver_name[MAXMODCONFNAME]; /* from kernel */
141 char path[MAXPATHLEN]; /* device path - from kernel */
142 } pcitool_intr_dev_t;
145 typedef struct pcitool_intr_get {
146 uint16_t user_version; /* Userland program version - to krnl */
147 uint16_t drvr_version; /* Driver version - from kernel */
148 uint32_t ino; /* interrupt number - to kernel */
149 uint8_t num_devs_ret; /* room for this # of devs to be */
150 /* returned - to kernel */
151 /* # devs returned - from kernel */
152 uint8_t num_devs; /* # devs on this ino - from kernel */
153 /* intrs enabled for devs if > 0 */
154 uint8_t ctlr; /* controller number - from kernel */
155 uint32_t cpu_id; /* cpu of interrupt - from kernel */
156 pcitool_errno_t status; /* returned status - from kernel */
157 pcitool_intr_dev_t dev[1]; /* start of variable device list */
159 } pcitool_intr_get_t;
162 * Get the size needed to return the number of devices wanted.
163 * Can't say num_devs - 1 as num_devs may be unsigned.
165 #define PCITOOL_IGET_SIZE(num_devs) \
166 (sizeof (pcitool_intr_get_t) - \
167 sizeof (pcitool_intr_dev_t) + \
168 (num_devs * sizeof (pcitool_intr_dev_t)))
171 * Size and endian fields for acc_attr bitmask.
173 #define PCITOOL_ACC_ATTR_SIZE_MASK 0x3
174 #define PCITOOL_ACC_ATTR_SIZE_1 0x0
175 #define PCITOOL_ACC_ATTR_SIZE_2 0x1
176 #define PCITOOL_ACC_ATTR_SIZE_4 0x2
177 #define PCITOOL_ACC_ATTR_SIZE_8 0x3
178 #define PCITOOL_ACC_ATTR_SIZE(x) (1 << (x & PCITOOL_ACC_ATTR_SIZE_MASK))
180 #define PCITOOL_ACC_ATTR_ENDN_MASK 0x100
181 #define PCITOOL_ACC_ATTR_ENDN_LTL 0x0
182 #define PCITOOL_ACC_ATTR_ENDN_BIG 0x100
183 #define PCITOOL_ACC_IS_BIG_ENDIAN(x) (x & PCITOOL_ACC_ATTR_ENDN_BIG)
186 * Data structure to read and write to pci device registers.
187 * This is the argument to the following ioctls:
188 * PCITOOL_DEVICE_SET/GET_REG
189 * PCITOOL_NEXUS_SET/GET_REG
191 typedef struct pcitool_reg {
192 uint16_t user_version; /* Userland program version - to krnl */
193 uint16_t drvr_version; /* Driver version - from kernel */
194 uint8_t bus_no; /* pci bus - to kernel */
195 uint8_t dev_no; /* pci dev - to kernel */
196 uint8_t func_no; /* pci function - to kernel */
197 uint8_t barnum; /* bank (DEVCTL_NEXUS_SET/GET_REG) or */
198 /* BAR from pcitools_bar_t */
199 /* (DEVCTL_DEVICE_SET/GET_REG) */
201 uint64_t offset; /* to kernel */
202 uint32_t acc_attr; /* access attributes - to kernel */
203 uint32_t padding1; /* 8-byte align next uint64_t for X86 */
204 uint64_t data; /* to/from kernel, 64-bit alignment */
205 uint32_t status; /* from kernel */
206 uint32_t padding2; /* 8-byte align next uint64_t for X86 */
207 uint64_t phys_addr; /* from kernel, 64-bit alignment */
215 #endif /* _SYS_PCI_TOOLS_H */