xref: /onnv-gate/usr/src/uts/common/sys/pci_tools.h (revision 12825:e35468461453)
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*12825SJimmy.Vetayases@oracle.com  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #ifndef _SYS_PCI_TOOLS_H
260Sstevel@tonic-gate #define	_SYS_PCI_TOOLS_H
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/modctl.h>
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifdef	__cplusplus
310Sstevel@tonic-gate extern "C" {
320Sstevel@tonic-gate #endif
330Sstevel@tonic-gate 
340Sstevel@tonic-gate /*
354397Sschwartz  * Versioning.
360Sstevel@tonic-gate  */
374397Sschwartz #define	PCITOOL_V1	1
384397Sschwartz #define	PCITOOL_V2	2
394397Sschwartz #define	PCITOOL_VERSION	PCITOOL_V2
400Sstevel@tonic-gate 
41117Sschwartz /* File suffixes for nexus pcitool nodes. */
42117Sschwartz #define	PCI_MINOR_REG	"reg"
43117Sschwartz #define	PCI_MINOR_INTR	"intr"
44117Sschwartz 
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate  * Ioctls for PCI tools.
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate #define	PCITOOL_IOC		(('P' << 24) | ('C' << 16) | ('T' << 8))
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /* Read/write a device on a PCI bus, in physical space. */
514397Sschwartz #define	PCITOOL_DEVICE_GET_REG		(PCITOOL_IOC | 1)
524397Sschwartz #define	PCITOOL_DEVICE_SET_REG		(PCITOOL_IOC | 2)
530Sstevel@tonic-gate 
540Sstevel@tonic-gate /* Read/write the PCI nexus bridge, in physical space. */
554397Sschwartz #define	PCITOOL_NEXUS_GET_REG		(PCITOOL_IOC | 3)
564397Sschwartz #define	PCITOOL_NEXUS_SET_REG		(PCITOOL_IOC | 4)
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /* Get/set interrupt-CPU mapping for PCI devices. */
594397Sschwartz #define	PCITOOL_DEVICE_GET_INTR		(PCITOOL_IOC | 5)
604397Sschwartz #define	PCITOOL_DEVICE_SET_INTR		(PCITOOL_IOC | 6)
610Sstevel@tonic-gate 
624397Sschwartz /* Get system interrupt information */
634397Sschwartz #define	PCITOOL_SYSTEM_INTR_INFO	(PCITOOL_IOC | 8)
640Sstevel@tonic-gate 
650Sstevel@tonic-gate /*
660Sstevel@tonic-gate  * This file contains data structures for the pci tool.
670Sstevel@tonic-gate  */
680Sstevel@tonic-gate #define	PCITOOL_CONFIG	0
690Sstevel@tonic-gate #define	PCITOOL_BAR0	1
700Sstevel@tonic-gate #define	PCITOOL_BAR1	2
710Sstevel@tonic-gate #define	PCITOOL_BAR2	3
720Sstevel@tonic-gate #define	PCITOOL_BAR3	4
730Sstevel@tonic-gate #define	PCITOOL_BAR4	5
740Sstevel@tonic-gate #define	PCITOOL_BAR5	6
750Sstevel@tonic-gate #define	PCITOOL_ROM	7
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /*
78624Sschwartz  * Pass this through barnum to signal to use a base addr instead.
79624Sschwartz  * This is for platforms which do not have a way to automatically map
80624Sschwartz  * a selected bank to a base addr.
81624Sschwartz  */
82624Sschwartz #define	PCITOOL_BASE	0xFF
83624Sschwartz 
84624Sschwartz /*
850Sstevel@tonic-gate  * BAR corresponding to space desired.
860Sstevel@tonic-gate  */
870Sstevel@tonic-gate typedef enum {
880Sstevel@tonic-gate     config = PCITOOL_CONFIG,
890Sstevel@tonic-gate     bar0 = PCITOOL_BAR0,
900Sstevel@tonic-gate     bar1 = PCITOOL_BAR1,
910Sstevel@tonic-gate     bar2 = PCITOOL_BAR2,
920Sstevel@tonic-gate     bar3 = PCITOOL_BAR3,
930Sstevel@tonic-gate     bar4 = PCITOOL_BAR4,
940Sstevel@tonic-gate     bar5 = PCITOOL_BAR5,
950Sstevel@tonic-gate     rom = PCITOOL_ROM
960Sstevel@tonic-gate } pcitool_bars_t;
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 
990Sstevel@tonic-gate /*
1000Sstevel@tonic-gate  * PCITOOL error numbers.
1010Sstevel@tonic-gate  */
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate typedef enum {
1040Sstevel@tonic-gate 	PCITOOL_SUCCESS = 0x0,
1050Sstevel@tonic-gate 	PCITOOL_INVALID_CPUID,
1060Sstevel@tonic-gate 	PCITOOL_INVALID_INO,
10710053SEvan.Yan@Sun.COM 	PCITOOL_INVALID_MSI,
1080Sstevel@tonic-gate 	PCITOOL_PENDING_INTRTIMEOUT,
1090Sstevel@tonic-gate 	PCITOOL_REGPROP_NOTWELLFORMED,
1100Sstevel@tonic-gate 	PCITOOL_INVALID_ADDRESS,
1110Sstevel@tonic-gate 	PCITOOL_NOT_ALIGNED,
1120Sstevel@tonic-gate 	PCITOOL_OUT_OF_RANGE,
1130Sstevel@tonic-gate 	PCITOOL_END_OF_RANGE,
1140Sstevel@tonic-gate 	PCITOOL_ROM_DISABLED,
1150Sstevel@tonic-gate 	PCITOOL_ROM_WRITE,
1160Sstevel@tonic-gate 	PCITOOL_IO_ERROR,
1170Sstevel@tonic-gate 	PCITOOL_INVALID_SIZE
1180Sstevel@tonic-gate } pcitool_errno_t;
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate /*
1220Sstevel@tonic-gate  * PCITOOL_DEVICE_SET_INTR ioctl data structure to re-assign the interrupts.
1230Sstevel@tonic-gate  */
1240Sstevel@tonic-gate typedef struct pcitool_intr_set {
1250Sstevel@tonic-gate 	uint16_t user_version;	/* Userland program version - to krnl */
1260Sstevel@tonic-gate 	uint16_t drvr_version;	/* Driver version - from kernel */
1270Sstevel@tonic-gate 	uint32_t ino;		/* interrupt to set - to kernel */
12810053SEvan.Yan@Sun.COM 	uint32_t msi;		/* Specific MSI to set - to kernel */
1290Sstevel@tonic-gate 	uint32_t cpu_id;	/* to: cpu to set / from: old cpu returned */
13012683SJimmy.Vetayases@oracle.com 	uint32_t old_cpu;	/* to/from kernel: old cpu id */
13110053SEvan.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 /*
13610053SEvan.Yan@Sun.COM  * Flags for pcitool_intr_get/set_t/info_t
1374397Sschwartz  */
13810053SEvan.Yan@Sun.COM #define	PCITOOL_INTR_FLAG_SET_GROUP	0x1
13910053SEvan.Yan@Sun.COM #define	PCITOOL_INTR_FLAG_GET_MSI	0x2
14010053SEvan.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 */
15710053SEvan.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 */
16510053SEvan.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 */
18310053SEvan.Yan@Sun.COM 	uint32_t flags;			/* to kernel */
1844397Sschwartz 	uint32_t num_intr;		/* Number of intrs suppt by nexus */
18512683SJimmy.Vetayases@oracle.com 	uint32_t num_cpu;
1864397Sschwartz 	uint32_t ctlr_version;		/* Intr ctlr HW version - from kernel */
1874397Sschwartz 	uchar_t	ctlr_type;		/* A PCITOOL_CTLR_TYPE - from kernel */
1884397Sschwartz } pcitool_intr_info_t;
1894397Sschwartz 
1904397Sschwartz /*
1914397Sschwartz  * Interrupt controller types
1924397Sschwartz  */
1934397Sschwartz #define	PCITOOL_CTLR_TYPE_UNKNOWN	0
1944397Sschwartz #define	PCITOOL_CTLR_TYPE_RISC		1
1954397Sschwartz #define	PCITOOL_CTLR_TYPE_UPPC		2
1964397Sschwartz #define	PCITOOL_CTLR_TYPE_PCPLUSMP	3
19712683SJimmy.Vetayases@oracle.com #define	PCITOOL_CTLR_TYPE_APIX		4
1984397Sschwartz 
1990Sstevel@tonic-gate /*
2000Sstevel@tonic-gate  * Size and endian fields for acc_attr bitmask.
2010Sstevel@tonic-gate  */
2020Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_SIZE_MASK	0x3
2030Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_SIZE_1		0x0
2040Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_SIZE_2		0x1
2050Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_SIZE_4		0x2
2060Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_SIZE_8		0x3
2070Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_SIZE(x)	(1 << (x & PCITOOL_ACC_ATTR_SIZE_MASK))
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_ENDN_MASK	0x100
2100Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_ENDN_LTL	0x0
2110Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_ENDN_BIG	0x100
2120Sstevel@tonic-gate #define	PCITOOL_ACC_IS_BIG_ENDIAN(x)	(x & PCITOOL_ACC_ATTR_ENDN_BIG)
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate /*
2150Sstevel@tonic-gate  * Data stucture to read and write to pci device registers.
2160Sstevel@tonic-gate  * This is the argument to the following ioctls:
2170Sstevel@tonic-gate  *	PCITOOL_DEVICE_SET/GET_REG
2180Sstevel@tonic-gate  *	PCITOOL_NEXUS_SET/GET_REG
2190Sstevel@tonic-gate  */
2200Sstevel@tonic-gate typedef struct pcitool_reg {
2210Sstevel@tonic-gate 	uint16_t	user_version;	/* Userland program version - to krnl */
2220Sstevel@tonic-gate 	uint16_t	drvr_version;	/* Driver version - from kernel */
2230Sstevel@tonic-gate 	uint8_t		bus_no;		/* pci bus - to kernel */
2240Sstevel@tonic-gate 	uint8_t		dev_no;		/* pci dev - to kernel */
2250Sstevel@tonic-gate 	uint8_t		func_no;	/* pci function - to kernel */
2260Sstevel@tonic-gate 	uint8_t		barnum;		/* bank (DEVCTL_NEXUS_SET/GET_REG) or */
2270Sstevel@tonic-gate 					/*   BAR from pcitools_bar_t */
2280Sstevel@tonic-gate 					/*   (DEVCTL_DEVICE_SET/GET_REG) */
2290Sstevel@tonic-gate 					/*   to kernel */
2300Sstevel@tonic-gate 	uint64_t	offset;		/* to kernel */
2310Sstevel@tonic-gate 	uint32_t	acc_attr;	/* access attributes - to kernel */
2320Sstevel@tonic-gate 	uint32_t	padding1;	/* 8-byte align next uint64_t for X86 */
2330Sstevel@tonic-gate 	uint64_t	data;		/* to/from kernel, 64-bit alignment */
2340Sstevel@tonic-gate 	uint32_t	status;		/* from kernel */
2350Sstevel@tonic-gate 	uint32_t	padding2;	/* 8-byte align next uint64_t for X86 */
2360Sstevel@tonic-gate 	uint64_t	phys_addr;	/* from kernel, 64-bit alignment */
2370Sstevel@tonic-gate } pcitool_reg_t;
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate #ifdef	__cplusplus
2410Sstevel@tonic-gate }
2420Sstevel@tonic-gate #endif
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate #endif	/* _SYS_PCI_TOOLS_H */
245