xref: /illumos-gate/usr/src/uts/common/sys/pci_tools.h (revision 69cd775f)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _SYS_PCI_TOOLS_H
287c478bd9Sstevel@tonic-gate #define	_SYS_PCI_TOOLS_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
357c478bd9Sstevel@tonic-gate extern "C" {
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * Versioning. Have different versions for userland program and drivers, so
407c478bd9Sstevel@tonic-gate  * they can all stay in sync with each other.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate #define	PCITOOL_USER_VERSION	1
437c478bd9Sstevel@tonic-gate #define	PCITOOL_DRVR_VERSION	1
447c478bd9Sstevel@tonic-gate 
457851eb82Sschwartz /* File suffixes for nexus pcitool nodes. */
467851eb82Sschwartz #define	PCI_MINOR_REG	"reg"
477851eb82Sschwartz #define	PCI_MINOR_INTR	"intr"
487851eb82Sschwartz 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * Ioctls for PCI tools.
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate #define	PCITOOL_IOC		(('P' << 24) | ('C' << 16) | ('T' << 8))
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /* Read/write a device on a PCI bus, in physical space. */
557c478bd9Sstevel@tonic-gate #define	PCITOOL_DEVICE_GET_REG	(PCITOOL_IOC | 1)
567c478bd9Sstevel@tonic-gate #define	PCITOOL_DEVICE_SET_REG	(PCITOOL_IOC | 2)
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /* Read/write the PCI nexus bridge, in physical space. */
597c478bd9Sstevel@tonic-gate #define	PCITOOL_NEXUS_GET_REG	(PCITOOL_IOC | 3)
607c478bd9Sstevel@tonic-gate #define	PCITOOL_NEXUS_SET_REG	(PCITOOL_IOC | 4)
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /* Get/set interrupt-CPU mapping for PCI devices. */
637c478bd9Sstevel@tonic-gate #define	PCITOOL_DEVICE_GET_INTR	(PCITOOL_IOC | 5)
647c478bd9Sstevel@tonic-gate #define	PCITOOL_DEVICE_SET_INTR	(PCITOOL_IOC | 6)
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /* Return the number of supported interrupts on a PCI bus. */
677c478bd9Sstevel@tonic-gate #define	PCITOOL_DEVICE_NUM_INTR	(PCITOOL_IOC | 7)
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * This file contains data structures for the pci tool.
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate #define	PCITOOL_CONFIG	0
747c478bd9Sstevel@tonic-gate #define	PCITOOL_BAR0	1
757c478bd9Sstevel@tonic-gate #define	PCITOOL_BAR1	2
767c478bd9Sstevel@tonic-gate #define	PCITOOL_BAR2	3
777c478bd9Sstevel@tonic-gate #define	PCITOOL_BAR3	4
787c478bd9Sstevel@tonic-gate #define	PCITOOL_BAR4	5
797c478bd9Sstevel@tonic-gate #define	PCITOOL_BAR5	6
807c478bd9Sstevel@tonic-gate #define	PCITOOL_ROM	7
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
83*69cd775fSschwartz  * Pass this through barnum to signal to use a base addr instead.
84*69cd775fSschwartz  * This is for platforms which do not have a way to automatically map
85*69cd775fSschwartz  * a selected bank to a base addr.
86*69cd775fSschwartz  */
87*69cd775fSschwartz #define	PCITOOL_BASE	0xFF
88*69cd775fSschwartz 
89*69cd775fSschwartz /*
907c478bd9Sstevel@tonic-gate  * BAR corresponding to space desired.
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate typedef enum {
937c478bd9Sstevel@tonic-gate     config = PCITOOL_CONFIG,
947c478bd9Sstevel@tonic-gate     bar0 = PCITOOL_BAR0,
957c478bd9Sstevel@tonic-gate     bar1 = PCITOOL_BAR1,
967c478bd9Sstevel@tonic-gate     bar2 = PCITOOL_BAR2,
977c478bd9Sstevel@tonic-gate     bar3 = PCITOOL_BAR3,
987c478bd9Sstevel@tonic-gate     bar4 = PCITOOL_BAR4,
997c478bd9Sstevel@tonic-gate     bar5 = PCITOOL_BAR5,
1007c478bd9Sstevel@tonic-gate     rom = PCITOOL_ROM
1017c478bd9Sstevel@tonic-gate } pcitool_bars_t;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * PCITOOL error numbers.
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate typedef enum {
1097c478bd9Sstevel@tonic-gate 	PCITOOL_SUCCESS = 0x0,
1107c478bd9Sstevel@tonic-gate 	PCITOOL_INVALID_CPUID,
1117c478bd9Sstevel@tonic-gate 	PCITOOL_INVALID_INO,
1127c478bd9Sstevel@tonic-gate 	PCITOOL_PENDING_INTRTIMEOUT,
1137c478bd9Sstevel@tonic-gate 	PCITOOL_REGPROP_NOTWELLFORMED,
1147c478bd9Sstevel@tonic-gate 	PCITOOL_INVALID_ADDRESS,
1157c478bd9Sstevel@tonic-gate 	PCITOOL_NOT_ALIGNED,
1167c478bd9Sstevel@tonic-gate 	PCITOOL_OUT_OF_RANGE,
1177c478bd9Sstevel@tonic-gate 	PCITOOL_END_OF_RANGE,
1187c478bd9Sstevel@tonic-gate 	PCITOOL_ROM_DISABLED,
1197c478bd9Sstevel@tonic-gate 	PCITOOL_ROM_WRITE,
1207c478bd9Sstevel@tonic-gate 	PCITOOL_IO_ERROR,
1217c478bd9Sstevel@tonic-gate 	PCITOOL_INVALID_SIZE
1227c478bd9Sstevel@tonic-gate } pcitool_errno_t;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /*
1267c478bd9Sstevel@tonic-gate  * PCITOOL_DEVICE_SET_INTR ioctl data structure to re-assign the interrupts.
1277c478bd9Sstevel@tonic-gate  */
1287c478bd9Sstevel@tonic-gate typedef struct pcitool_intr_set {
1297c478bd9Sstevel@tonic-gate 	uint16_t user_version;	/* Userland program version - to krnl */
1307c478bd9Sstevel@tonic-gate 	uint16_t drvr_version;	/* Driver version - from kernel */
1317c478bd9Sstevel@tonic-gate 	uint32_t ino;		/* interrupt to set - to kernel */
1327c478bd9Sstevel@tonic-gate 	uint32_t cpu_id;	/* to: cpu to set / from: old cpu returned */
1337c478bd9Sstevel@tonic-gate 	pcitool_errno_t status;	/* from kernel */
1347c478bd9Sstevel@tonic-gate } pcitool_intr_set_t;
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /*
1387c478bd9Sstevel@tonic-gate  * PCITOOL_DEVICE_GET_INTR ioctl data structure to dump out the
1397c478bd9Sstevel@tonic-gate  * ino mapping information.
1407c478bd9Sstevel@tonic-gate  */
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate typedef struct pcitool_intr_dev {
1437c478bd9Sstevel@tonic-gate 	uint32_t	dev_inst;	/* device instance - from kernel */
1447c478bd9Sstevel@tonic-gate 	char		driver_name[MAXMODCONFNAME];	/* from kernel */
1457c478bd9Sstevel@tonic-gate 	char		path[MAXPATHLEN]; /* device path - from kernel */
1467c478bd9Sstevel@tonic-gate } pcitool_intr_dev_t;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate typedef struct pcitool_intr_get {
1507c478bd9Sstevel@tonic-gate 	uint16_t user_version;		/* Userland program version - to krnl */
1517c478bd9Sstevel@tonic-gate 	uint16_t drvr_version;		/* Driver version - from kernel */
1527c478bd9Sstevel@tonic-gate 	uint32_t	ino;		/* interrupt number - to kernel */
1537c478bd9Sstevel@tonic-gate 	uint8_t		num_devs_ret;	/* room for this # of devs to be */
1547c478bd9Sstevel@tonic-gate 					/* returned - to kernel */
1557c478bd9Sstevel@tonic-gate 					/* # devs returned - from kernel */
1567c478bd9Sstevel@tonic-gate 	uint8_t		num_devs;	/* # devs on this ino - from kernel */
1577c478bd9Sstevel@tonic-gate 					/* intrs enabled for devs if > 0 */
1587c478bd9Sstevel@tonic-gate 	uint8_t		ctlr;		/* controller number - from kernel */
1597c478bd9Sstevel@tonic-gate 	uint32_t	cpu_id;		/* cpu of interrupt - from kernel */
1607c478bd9Sstevel@tonic-gate 	pcitool_errno_t status;		/* returned status - from kernel */
1617c478bd9Sstevel@tonic-gate 	pcitool_intr_dev_t	dev[1];	/* start of variable device list */
1627c478bd9Sstevel@tonic-gate 					/* from kernel */
1637c478bd9Sstevel@tonic-gate } pcitool_intr_get_t;
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate /*
1667c478bd9Sstevel@tonic-gate  * Get the size needed to return the number of devices wanted.
1677c478bd9Sstevel@tonic-gate  * Can't say num_devs - 1 as num_devs may be unsigned.
1687c478bd9Sstevel@tonic-gate  */
1697c478bd9Sstevel@tonic-gate #define	PCITOOL_IGET_SIZE(num_devs) \
1707c478bd9Sstevel@tonic-gate 	(sizeof (pcitool_intr_get_t) - \
1717c478bd9Sstevel@tonic-gate 	sizeof (pcitool_intr_dev_t) + \
1727c478bd9Sstevel@tonic-gate 	(num_devs * sizeof (pcitool_intr_dev_t)))
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate /*
1757c478bd9Sstevel@tonic-gate  * Size and endian fields for acc_attr bitmask.
1767c478bd9Sstevel@tonic-gate  */
1777c478bd9Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_SIZE_MASK	0x3
1787c478bd9Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_SIZE_1		0x0
1797c478bd9Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_SIZE_2		0x1
1807c478bd9Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_SIZE_4		0x2
1817c478bd9Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_SIZE_8		0x3
1827c478bd9Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_SIZE(x)	(1 << (x & PCITOOL_ACC_ATTR_SIZE_MASK))
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_ENDN_MASK	0x100
1857c478bd9Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_ENDN_LTL	0x0
1867c478bd9Sstevel@tonic-gate #define	PCITOOL_ACC_ATTR_ENDN_BIG	0x100
1877c478bd9Sstevel@tonic-gate #define	PCITOOL_ACC_IS_BIG_ENDIAN(x)	(x & PCITOOL_ACC_ATTR_ENDN_BIG)
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate /*
1907c478bd9Sstevel@tonic-gate  * Data stucture to read and write to pci device registers.
1917c478bd9Sstevel@tonic-gate  * This is the argument to the following ioctls:
1927c478bd9Sstevel@tonic-gate  *	PCITOOL_DEVICE_SET/GET_REG
1937c478bd9Sstevel@tonic-gate  *	PCITOOL_NEXUS_SET/GET_REG
1947c478bd9Sstevel@tonic-gate  */
1957c478bd9Sstevel@tonic-gate typedef struct pcitool_reg {
1967c478bd9Sstevel@tonic-gate 	uint16_t	user_version;	/* Userland program version - to krnl */
1977c478bd9Sstevel@tonic-gate 	uint16_t	drvr_version;	/* Driver version - from kernel */
1987c478bd9Sstevel@tonic-gate 	uint8_t		bus_no;		/* pci bus - to kernel */
1997c478bd9Sstevel@tonic-gate 	uint8_t		dev_no;		/* pci dev - to kernel */
2007c478bd9Sstevel@tonic-gate 	uint8_t		func_no;	/* pci function - to kernel */
2017c478bd9Sstevel@tonic-gate 	uint8_t		barnum;		/* bank (DEVCTL_NEXUS_SET/GET_REG) or */
2027c478bd9Sstevel@tonic-gate 					/*   BAR from pcitools_bar_t */
2037c478bd9Sstevel@tonic-gate 					/*   (DEVCTL_DEVICE_SET/GET_REG) */
2047c478bd9Sstevel@tonic-gate 					/*   to kernel */
2057c478bd9Sstevel@tonic-gate 	uint64_t	offset;		/* to kernel */
2067c478bd9Sstevel@tonic-gate 	uint32_t	acc_attr;	/* access attributes - to kernel */
2077c478bd9Sstevel@tonic-gate 	uint32_t	padding1;	/* 8-byte align next uint64_t for X86 */
2087c478bd9Sstevel@tonic-gate 	uint64_t	data;		/* to/from kernel, 64-bit alignment */
2097c478bd9Sstevel@tonic-gate 	uint32_t	status;		/* from kernel */
2107c478bd9Sstevel@tonic-gate 	uint32_t	padding2;	/* 8-byte align next uint64_t for X86 */
2117c478bd9Sstevel@tonic-gate 	uint64_t	phys_addr;	/* from kernel, 64-bit alignment */
2127c478bd9Sstevel@tonic-gate } pcitool_reg_t;
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2167c478bd9Sstevel@tonic-gate }
2177c478bd9Sstevel@tonic-gate #endif
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate #endif	/* _SYS_PCI_TOOLS_H */
220