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 52917a9c9Sschwartz * Common Development and Distribution License (the "License"). 62917a9c9Sschwartz * 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 /* 22*5cd376e8SJimmy Vetayases * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #ifndef _SYS_PCI_TOOLS_H 267c478bd9Sstevel@tonic-gate #define _SYS_PCI_TOOLS_H 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifdef __cplusplus 317c478bd9Sstevel@tonic-gate extern "C" { 327c478bd9Sstevel@tonic-gate #endif 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate /* 352917a9c9Sschwartz * Versioning. 367c478bd9Sstevel@tonic-gate */ 372917a9c9Sschwartz #define PCITOOL_V1 1 382917a9c9Sschwartz #define PCITOOL_V2 2 392917a9c9Sschwartz #define PCITOOL_VERSION PCITOOL_V2 407c478bd9Sstevel@tonic-gate 417851eb82Sschwartz /* File suffixes for nexus pcitool nodes. */ 427851eb82Sschwartz #define PCI_MINOR_REG "reg" 437851eb82Sschwartz #define PCI_MINOR_INTR "intr" 447851eb82Sschwartz 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate * Ioctls for PCI tools. 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate #define PCITOOL_IOC (('P' << 24) | ('C' << 16) | ('T' << 8)) 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* Read/write a device on a PCI bus, in physical space. */ 517c478bd9Sstevel@tonic-gate #define PCITOOL_DEVICE_GET_REG (PCITOOL_IOC | 1) 527c478bd9Sstevel@tonic-gate #define PCITOOL_DEVICE_SET_REG (PCITOOL_IOC | 2) 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* Read/write the PCI nexus bridge, in physical space. */ 557c478bd9Sstevel@tonic-gate #define PCITOOL_NEXUS_GET_REG (PCITOOL_IOC | 3) 567c478bd9Sstevel@tonic-gate #define PCITOOL_NEXUS_SET_REG (PCITOOL_IOC | 4) 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* Get/set interrupt-CPU mapping for PCI devices. */ 597c478bd9Sstevel@tonic-gate #define PCITOOL_DEVICE_GET_INTR (PCITOOL_IOC | 5) 607c478bd9Sstevel@tonic-gate #define PCITOOL_DEVICE_SET_INTR (PCITOOL_IOC | 6) 617c478bd9Sstevel@tonic-gate 622917a9c9Sschwartz /* Get system interrupt information */ 632917a9c9Sschwartz #define PCITOOL_SYSTEM_INTR_INFO (PCITOOL_IOC | 8) 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate /* 667c478bd9Sstevel@tonic-gate * This file contains data structures for the pci tool. 677c478bd9Sstevel@tonic-gate */ 687c478bd9Sstevel@tonic-gate #define PCITOOL_CONFIG 0 697c478bd9Sstevel@tonic-gate #define PCITOOL_BAR0 1 707c478bd9Sstevel@tonic-gate #define PCITOOL_BAR1 2 717c478bd9Sstevel@tonic-gate #define PCITOOL_BAR2 3 727c478bd9Sstevel@tonic-gate #define PCITOOL_BAR3 4 737c478bd9Sstevel@tonic-gate #define PCITOOL_BAR4 5 747c478bd9Sstevel@tonic-gate #define PCITOOL_BAR5 6 757c478bd9Sstevel@tonic-gate #define PCITOOL_ROM 7 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate /* 7869cd775fSschwartz * Pass this through barnum to signal to use a base addr instead. 7969cd775fSschwartz * This is for platforms which do not have a way to automatically map 8069cd775fSschwartz * a selected bank to a base addr. 8169cd775fSschwartz */ 8269cd775fSschwartz #define PCITOOL_BASE 0xFF 8369cd775fSschwartz 8469cd775fSschwartz /* 857c478bd9Sstevel@tonic-gate * BAR corresponding to space desired. 867c478bd9Sstevel@tonic-gate */ 877c478bd9Sstevel@tonic-gate typedef enum { 887c478bd9Sstevel@tonic-gate config = PCITOOL_CONFIG, 897c478bd9Sstevel@tonic-gate bar0 = PCITOOL_BAR0, 907c478bd9Sstevel@tonic-gate bar1 = PCITOOL_BAR1, 917c478bd9Sstevel@tonic-gate bar2 = PCITOOL_BAR2, 927c478bd9Sstevel@tonic-gate bar3 = PCITOOL_BAR3, 937c478bd9Sstevel@tonic-gate bar4 = PCITOOL_BAR4, 947c478bd9Sstevel@tonic-gate bar5 = PCITOOL_BAR5, 957c478bd9Sstevel@tonic-gate rom = PCITOOL_ROM 967c478bd9Sstevel@tonic-gate } pcitool_bars_t; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate /* 1007c478bd9Sstevel@tonic-gate * PCITOOL error numbers. 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate typedef enum { 1047c478bd9Sstevel@tonic-gate PCITOOL_SUCCESS = 0x0, 1057c478bd9Sstevel@tonic-gate PCITOOL_INVALID_CPUID, 1067c478bd9Sstevel@tonic-gate PCITOOL_INVALID_INO, 10709b1eac2SEvan Yan PCITOOL_INVALID_MSI, 1087c478bd9Sstevel@tonic-gate PCITOOL_PENDING_INTRTIMEOUT, 1097c478bd9Sstevel@tonic-gate PCITOOL_REGPROP_NOTWELLFORMED, 1107c478bd9Sstevel@tonic-gate PCITOOL_INVALID_ADDRESS, 1117c478bd9Sstevel@tonic-gate PCITOOL_NOT_ALIGNED, 1127c478bd9Sstevel@tonic-gate PCITOOL_OUT_OF_RANGE, 1137c478bd9Sstevel@tonic-gate PCITOOL_END_OF_RANGE, 1147c478bd9Sstevel@tonic-gate PCITOOL_ROM_DISABLED, 1157c478bd9Sstevel@tonic-gate PCITOOL_ROM_WRITE, 1167c478bd9Sstevel@tonic-gate PCITOOL_IO_ERROR, 1177c478bd9Sstevel@tonic-gate PCITOOL_INVALID_SIZE 1187c478bd9Sstevel@tonic-gate } pcitool_errno_t; 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate /* 1227c478bd9Sstevel@tonic-gate * PCITOOL_DEVICE_SET_INTR ioctl data structure to re-assign the interrupts. 1237c478bd9Sstevel@tonic-gate */ 1247c478bd9Sstevel@tonic-gate typedef struct pcitool_intr_set { 1257c478bd9Sstevel@tonic-gate uint16_t user_version; /* Userland program version - to krnl */ 1267c478bd9Sstevel@tonic-gate uint16_t drvr_version; /* Driver version - from kernel */ 1277c478bd9Sstevel@tonic-gate uint32_t ino; /* interrupt to set - to kernel */ 12809b1eac2SEvan Yan uint32_t msi; /* Specific MSI to set - to kernel */ 1297c478bd9Sstevel@tonic-gate uint32_t cpu_id; /* to: cpu to set / from: old cpu returned */ 1307ff178cdSJimmy Vetayases uint32_t old_cpu; /* to/from kernel: old cpu id */ 1312917a9c9Sschwartz uint32_t flags; /* to kernel */ 13209b1eac2SEvan Yan pcitool_errno_t status; /* from kernel */ 1337c478bd9Sstevel@tonic-gate } pcitool_intr_set_t; 1347c478bd9Sstevel@tonic-gate 1352917a9c9Sschwartz /* 13609b1eac2SEvan Yan * Flags for pcitool_intr_get/set_t/info_t 1372917a9c9Sschwartz */ 13809b1eac2SEvan Yan #define PCITOOL_INTR_FLAG_SET_GROUP 0x1 13909b1eac2SEvan Yan #define PCITOOL_INTR_FLAG_GET_MSI 0x2 14009b1eac2SEvan Yan #define PCITOOL_INTR_FLAG_SET_MSI 0x4 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate /* 1437c478bd9Sstevel@tonic-gate * PCITOOL_DEVICE_GET_INTR ioctl data structure to dump out the 1447c478bd9Sstevel@tonic-gate * ino mapping information. 1457c478bd9Sstevel@tonic-gate */ 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate typedef struct pcitool_intr_dev { 1487c478bd9Sstevel@tonic-gate uint32_t dev_inst; /* device instance - from kernel */ 1497c478bd9Sstevel@tonic-gate char driver_name[MAXMODCONFNAME]; /* from kernel */ 1507c478bd9Sstevel@tonic-gate char path[MAXPATHLEN]; /* device path - from kernel */ 1517c478bd9Sstevel@tonic-gate } pcitool_intr_dev_t; 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate typedef struct pcitool_intr_get { 1547c478bd9Sstevel@tonic-gate uint16_t user_version; /* Userland program version - to krnl */ 1557c478bd9Sstevel@tonic-gate uint16_t drvr_version; /* Driver version - from kernel */ 1567c478bd9Sstevel@tonic-gate uint32_t ino; /* interrupt number - to kernel */ 15709b1eac2SEvan Yan uint32_t msi; /* MSI number - to kernel */ 1587c478bd9Sstevel@tonic-gate uint8_t num_devs_ret; /* room for this # of devs to be */ 1597c478bd9Sstevel@tonic-gate /* returned - to kernel */ 1607c478bd9Sstevel@tonic-gate /* # devs returned - from kernel */ 1617c478bd9Sstevel@tonic-gate uint8_t num_devs; /* # devs on this ino - from kernel */ 1627c478bd9Sstevel@tonic-gate /* intrs enabled for devs if > 0 */ 1637c478bd9Sstevel@tonic-gate uint8_t ctlr; /* controller number - from kernel */ 1647c478bd9Sstevel@tonic-gate uint32_t cpu_id; /* cpu of interrupt - from kernel */ 16509b1eac2SEvan Yan uint32_t flags; /* to kernel */ 1667c478bd9Sstevel@tonic-gate pcitool_errno_t status; /* returned status - from kernel */ 1677c478bd9Sstevel@tonic-gate pcitool_intr_dev_t dev[1]; /* start of variable device list */ 1687c478bd9Sstevel@tonic-gate /* from kernel */ 1697c478bd9Sstevel@tonic-gate } pcitool_intr_get_t; 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate /* 1727c478bd9Sstevel@tonic-gate * Get the size needed to return the number of devices wanted. 1737c478bd9Sstevel@tonic-gate * Can't say num_devs - 1 as num_devs may be unsigned. 1747c478bd9Sstevel@tonic-gate */ 1757c478bd9Sstevel@tonic-gate #define PCITOOL_IGET_SIZE(num_devs) \ 1767c478bd9Sstevel@tonic-gate (sizeof (pcitool_intr_get_t) - \ 1777c478bd9Sstevel@tonic-gate sizeof (pcitool_intr_dev_t) + \ 1787c478bd9Sstevel@tonic-gate (num_devs * sizeof (pcitool_intr_dev_t))) 1797c478bd9Sstevel@tonic-gate 1802917a9c9Sschwartz typedef struct pcitool_intr_info { 1812917a9c9Sschwartz uint16_t user_version; /* Userland program version - to krnl */ 1822917a9c9Sschwartz uint16_t drvr_version; /* Driver version - from kernel */ 18309b1eac2SEvan Yan uint32_t flags; /* to kernel */ 1842917a9c9Sschwartz uint32_t num_intr; /* Number of intrs suppt by nexus */ 1857ff178cdSJimmy Vetayases uint32_t num_cpu; 1862917a9c9Sschwartz uint32_t ctlr_version; /* Intr ctlr HW version - from kernel */ 1872917a9c9Sschwartz uchar_t ctlr_type; /* A PCITOOL_CTLR_TYPE - from kernel */ 1882917a9c9Sschwartz } pcitool_intr_info_t; 1892917a9c9Sschwartz 1902917a9c9Sschwartz /* 1912917a9c9Sschwartz * Interrupt controller types 1922917a9c9Sschwartz */ 1932917a9c9Sschwartz #define PCITOOL_CTLR_TYPE_UNKNOWN 0 1942917a9c9Sschwartz #define PCITOOL_CTLR_TYPE_RISC 1 1952917a9c9Sschwartz #define PCITOOL_CTLR_TYPE_UPPC 2 1962917a9c9Sschwartz #define PCITOOL_CTLR_TYPE_PCPLUSMP 3 1977ff178cdSJimmy Vetayases #define PCITOOL_CTLR_TYPE_APIX 4 1982917a9c9Sschwartz 1997c478bd9Sstevel@tonic-gate /* 2007c478bd9Sstevel@tonic-gate * Size and endian fields for acc_attr bitmask. 2017c478bd9Sstevel@tonic-gate */ 2027c478bd9Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_SIZE_MASK 0x3 2037c478bd9Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_SIZE_1 0x0 2047c478bd9Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_SIZE_2 0x1 2057c478bd9Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_SIZE_4 0x2 2067c478bd9Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_SIZE_8 0x3 2077c478bd9Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_SIZE(x) (1 << (x & PCITOOL_ACC_ATTR_SIZE_MASK)) 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_ENDN_MASK 0x100 2107c478bd9Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_ENDN_LTL 0x0 2117c478bd9Sstevel@tonic-gate #define PCITOOL_ACC_ATTR_ENDN_BIG 0x100 2127c478bd9Sstevel@tonic-gate #define PCITOOL_ACC_IS_BIG_ENDIAN(x) (x & PCITOOL_ACC_ATTR_ENDN_BIG) 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate /* 2157c478bd9Sstevel@tonic-gate * Data stucture to read and write to pci device registers. 2167c478bd9Sstevel@tonic-gate * This is the argument to the following ioctls: 2177c478bd9Sstevel@tonic-gate * PCITOOL_DEVICE_SET/GET_REG 2187c478bd9Sstevel@tonic-gate * PCITOOL_NEXUS_SET/GET_REG 2197c478bd9Sstevel@tonic-gate */ 2207c478bd9Sstevel@tonic-gate typedef struct pcitool_reg { 2217c478bd9Sstevel@tonic-gate uint16_t user_version; /* Userland program version - to krnl */ 2227c478bd9Sstevel@tonic-gate uint16_t drvr_version; /* Driver version - from kernel */ 2237c478bd9Sstevel@tonic-gate uint8_t bus_no; /* pci bus - to kernel */ 2247c478bd9Sstevel@tonic-gate uint8_t dev_no; /* pci dev - to kernel */ 2257c478bd9Sstevel@tonic-gate uint8_t func_no; /* pci function - to kernel */ 2267c478bd9Sstevel@tonic-gate uint8_t barnum; /* bank (DEVCTL_NEXUS_SET/GET_REG) or */ 2277c478bd9Sstevel@tonic-gate /* BAR from pcitools_bar_t */ 2287c478bd9Sstevel@tonic-gate /* (DEVCTL_DEVICE_SET/GET_REG) */ 2297c478bd9Sstevel@tonic-gate /* to kernel */ 2307c478bd9Sstevel@tonic-gate uint64_t offset; /* to kernel */ 2317c478bd9Sstevel@tonic-gate uint32_t acc_attr; /* access attributes - to kernel */ 2327c478bd9Sstevel@tonic-gate uint32_t padding1; /* 8-byte align next uint64_t for X86 */ 2337c478bd9Sstevel@tonic-gate uint64_t data; /* to/from kernel, 64-bit alignment */ 2347c478bd9Sstevel@tonic-gate uint32_t status; /* from kernel */ 2357c478bd9Sstevel@tonic-gate uint32_t padding2; /* 8-byte align next uint64_t for X86 */ 2367c478bd9Sstevel@tonic-gate uint64_t phys_addr; /* from kernel, 64-bit alignment */ 2377c478bd9Sstevel@tonic-gate } pcitool_reg_t; 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2417c478bd9Sstevel@tonic-gate } 2427c478bd9Sstevel@tonic-gate #endif 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate #endif /* _SYS_PCI_TOOLS_H */ 245