pci_tools.h revision 4f5e7dd7
14f5e7dd7Smrg/*
24f5e7dd7Smrg * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
34f5e7dd7Smrg *
44f5e7dd7Smrg * Permission is hereby granted, free of charge, to any person obtaining a
54f5e7dd7Smrg * copy of this software and associated documentation files (the
64f5e7dd7Smrg * "Software"), to deal in the Software without restriction, including
74f5e7dd7Smrg * without limitation the rights to use, copy, modify, merge, publish,
84f5e7dd7Smrg * distribute, and/or sell copies of the Software, and to permit persons
94f5e7dd7Smrg * to whom the Software is furnished to do so, provided that the above
104f5e7dd7Smrg * copyright notice(s) and this permission notice appear in all copies of
114f5e7dd7Smrg * the Software and that both the above copyright notice(s) and this
124f5e7dd7Smrg * permission notice appear in supporting documentation.
134f5e7dd7Smrg *
144f5e7dd7Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
154f5e7dd7Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
164f5e7dd7Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
174f5e7dd7Smrg * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
184f5e7dd7Smrg * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
194f5e7dd7Smrg * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
204f5e7dd7Smrg * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
214f5e7dd7Smrg * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
224f5e7dd7Smrg * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
234f5e7dd7Smrg *
244f5e7dd7Smrg * Except as contained in this notice, the name of a copyright holder
254f5e7dd7Smrg * shall not be used in advertising or otherwise to promote the sale, use
264f5e7dd7Smrg * or other dealings in this Software without prior written authorization
274f5e7dd7Smrg * of the copyright holder.
284f5e7dd7Smrg */
294f5e7dd7Smrg#ifndef _SYS_PCI_TOOLS_H
304f5e7dd7Smrg#define	_SYS_PCI_TOOLS_H
314f5e7dd7Smrg
324f5e7dd7Smrg#pragma ident	"@(#)pci_tools.h	1.4	05/09/28 SMI"
334f5e7dd7Smrg
344f5e7dd7Smrg#include <sys/modctl.h>
354f5e7dd7Smrg
364f5e7dd7Smrg#ifdef	__cplusplus
374f5e7dd7Smrgextern "C" {
384f5e7dd7Smrg#endif
394f5e7dd7Smrg
404f5e7dd7Smrg/*
414f5e7dd7Smrg * Versioning. Have different versions for userland program and drivers, so
424f5e7dd7Smrg * they can all stay in sync with each other.
434f5e7dd7Smrg */
444f5e7dd7Smrg#define	PCITOOL_USER_VERSION	1
454f5e7dd7Smrg#define	PCITOOL_DRVR_VERSION	1
464f5e7dd7Smrg
474f5e7dd7Smrg/* File suffixes for nexus pcitool nodes. */
484f5e7dd7Smrg#define	PCI_MINOR_REG	"reg"
494f5e7dd7Smrg#define	PCI_MINOR_INTR	"intr"
504f5e7dd7Smrg
514f5e7dd7Smrg/*
524f5e7dd7Smrg * Ioctls for PCI tools.
534f5e7dd7Smrg */
544f5e7dd7Smrg#define	PCITOOL_IOC		(('P' << 24) | ('C' << 16) | ('T' << 8))
554f5e7dd7Smrg
564f5e7dd7Smrg/* Read/write a device on a PCI bus, in physical space. */
574f5e7dd7Smrg#define	PCITOOL_DEVICE_GET_REG	(PCITOOL_IOC | 1)
584f5e7dd7Smrg#define	PCITOOL_DEVICE_SET_REG	(PCITOOL_IOC | 2)
594f5e7dd7Smrg
604f5e7dd7Smrg/* Read/write the PCI nexus bridge, in physical space. */
614f5e7dd7Smrg#define	PCITOOL_NEXUS_GET_REG	(PCITOOL_IOC | 3)
624f5e7dd7Smrg#define	PCITOOL_NEXUS_SET_REG	(PCITOOL_IOC | 4)
634f5e7dd7Smrg
644f5e7dd7Smrg/* Get/set interrupt-CPU mapping for PCI devices. */
654f5e7dd7Smrg#define	PCITOOL_DEVICE_GET_INTR	(PCITOOL_IOC | 5)
664f5e7dd7Smrg#define	PCITOOL_DEVICE_SET_INTR	(PCITOOL_IOC | 6)
674f5e7dd7Smrg
684f5e7dd7Smrg/* Return the number of supported interrupts on a PCI bus. */
694f5e7dd7Smrg#define	PCITOOL_DEVICE_NUM_INTR	(PCITOOL_IOC | 7)
704f5e7dd7Smrg
714f5e7dd7Smrg
724f5e7dd7Smrg/*
734f5e7dd7Smrg * This file contains data structures for the pci tool.
744f5e7dd7Smrg */
754f5e7dd7Smrg#define	PCITOOL_CONFIG	0
764f5e7dd7Smrg#define	PCITOOL_BAR0	1
774f5e7dd7Smrg#define	PCITOOL_BAR1	2
784f5e7dd7Smrg#define	PCITOOL_BAR2	3
794f5e7dd7Smrg#define	PCITOOL_BAR3	4
804f5e7dd7Smrg#define	PCITOOL_BAR4	5
814f5e7dd7Smrg#define	PCITOOL_BAR5	6
824f5e7dd7Smrg#define	PCITOOL_ROM	7
834f5e7dd7Smrg
844f5e7dd7Smrg/*
854f5e7dd7Smrg * Pass this through barnum to signal to use a base addr instead.
864f5e7dd7Smrg * This is for platforms which do not have a way to automatically map
874f5e7dd7Smrg * a selected bank to a base addr.
884f5e7dd7Smrg */
894f5e7dd7Smrg#define	PCITOOL_BASE	0xFF
904f5e7dd7Smrg
914f5e7dd7Smrg/*
924f5e7dd7Smrg * BAR corresponding to space desired.
934f5e7dd7Smrg */
944f5e7dd7Smrgtypedef enum {
954f5e7dd7Smrg    config = PCITOOL_CONFIG,
964f5e7dd7Smrg    bar0 = PCITOOL_BAR0,
974f5e7dd7Smrg    bar1 = PCITOOL_BAR1,
984f5e7dd7Smrg    bar2 = PCITOOL_BAR2,
994f5e7dd7Smrg    bar3 = PCITOOL_BAR3,
1004f5e7dd7Smrg    bar4 = PCITOOL_BAR4,
1014f5e7dd7Smrg    bar5 = PCITOOL_BAR5,
1024f5e7dd7Smrg    rom = PCITOOL_ROM
1034f5e7dd7Smrg} pcitool_bars_t;
1044f5e7dd7Smrg
1054f5e7dd7Smrg
1064f5e7dd7Smrg/*
1074f5e7dd7Smrg * PCITOOL error numbers.
1084f5e7dd7Smrg */
1094f5e7dd7Smrg
1104f5e7dd7Smrgtypedef enum {
1114f5e7dd7Smrg	PCITOOL_SUCCESS = 0x0,
1124f5e7dd7Smrg	PCITOOL_INVALID_CPUID,
1134f5e7dd7Smrg	PCITOOL_INVALID_INO,
1144f5e7dd7Smrg	PCITOOL_PENDING_INTRTIMEOUT,
1154f5e7dd7Smrg	PCITOOL_REGPROP_NOTWELLFORMED,
1164f5e7dd7Smrg	PCITOOL_INVALID_ADDRESS,
1174f5e7dd7Smrg	PCITOOL_NOT_ALIGNED,
1184f5e7dd7Smrg	PCITOOL_OUT_OF_RANGE,
1194f5e7dd7Smrg	PCITOOL_END_OF_RANGE,
1204f5e7dd7Smrg	PCITOOL_ROM_DISABLED,
1214f5e7dd7Smrg	PCITOOL_ROM_WRITE,
1224f5e7dd7Smrg	PCITOOL_IO_ERROR,
1234f5e7dd7Smrg	PCITOOL_INVALID_SIZE
1244f5e7dd7Smrg} pcitool_errno_t;
1254f5e7dd7Smrg
1264f5e7dd7Smrg
1274f5e7dd7Smrg/*
1284f5e7dd7Smrg * PCITOOL_DEVICE_SET_INTR ioctl data structure to re-assign the interrupts.
1294f5e7dd7Smrg */
1304f5e7dd7Smrgtypedef struct pcitool_intr_set {
1314f5e7dd7Smrg	uint16_t user_version;	/* Userland program version - to krnl */
1324f5e7dd7Smrg	uint16_t drvr_version;	/* Driver version - from kernel */
1334f5e7dd7Smrg	uint32_t ino;		/* interrupt to set - to kernel */
1344f5e7dd7Smrg	uint32_t cpu_id;	/* to: cpu to set / from: old cpu returned */
1354f5e7dd7Smrg	pcitool_errno_t status;	/* from kernel */
1364f5e7dd7Smrg} pcitool_intr_set_t;
1374f5e7dd7Smrg
1384f5e7dd7Smrg
1394f5e7dd7Smrg/*
1404f5e7dd7Smrg * PCITOOL_DEVICE_GET_INTR ioctl data structure to dump out the
1414f5e7dd7Smrg * ino mapping information.
1424f5e7dd7Smrg */
1434f5e7dd7Smrg
1444f5e7dd7Smrgtypedef struct pcitool_intr_dev {
1454f5e7dd7Smrg	uint32_t	dev_inst;	/* device instance - from kernel */
1464f5e7dd7Smrg	char		driver_name[MAXMODCONFNAME];	/* from kernel */
1474f5e7dd7Smrg	char		path[MAXPATHLEN]; /* device path - from kernel */
1484f5e7dd7Smrg} pcitool_intr_dev_t;
1494f5e7dd7Smrg
1504f5e7dd7Smrg
1514f5e7dd7Smrgtypedef struct pcitool_intr_get {
1524f5e7dd7Smrg	uint16_t user_version;		/* Userland program version - to krnl */
1534f5e7dd7Smrg	uint16_t drvr_version;		/* Driver version - from kernel */
1544f5e7dd7Smrg	uint32_t	ino;		/* interrupt number - to kernel */
1554f5e7dd7Smrg	uint8_t		num_devs_ret;	/* room for this # of devs to be */
1564f5e7dd7Smrg					/* returned - to kernel */
1574f5e7dd7Smrg					/* # devs returned - from kernel */
1584f5e7dd7Smrg	uint8_t		num_devs;	/* # devs on this ino - from kernel */
1594f5e7dd7Smrg					/* intrs enabled for devs if > 0 */
1604f5e7dd7Smrg	uint8_t		ctlr;		/* controller number - from kernel */
1614f5e7dd7Smrg	uint32_t	cpu_id;		/* cpu of interrupt - from kernel */
1624f5e7dd7Smrg	pcitool_errno_t status;		/* returned status - from kernel */
1634f5e7dd7Smrg	pcitool_intr_dev_t	dev[1];	/* start of variable device list */
1644f5e7dd7Smrg					/* from kernel */
1654f5e7dd7Smrg} pcitool_intr_get_t;
1664f5e7dd7Smrg
1674f5e7dd7Smrg/*
1684f5e7dd7Smrg * Get the size needed to return the number of devices wanted.
1694f5e7dd7Smrg * Can't say num_devs - 1 as num_devs may be unsigned.
1704f5e7dd7Smrg */
1714f5e7dd7Smrg#define	PCITOOL_IGET_SIZE(num_devs) \
1724f5e7dd7Smrg	(sizeof (pcitool_intr_get_t) - \
1734f5e7dd7Smrg	sizeof (pcitool_intr_dev_t) + \
1744f5e7dd7Smrg	(num_devs * sizeof (pcitool_intr_dev_t)))
1754f5e7dd7Smrg
1764f5e7dd7Smrg/*
1774f5e7dd7Smrg * Size and endian fields for acc_attr bitmask.
1784f5e7dd7Smrg */
1794f5e7dd7Smrg#define	PCITOOL_ACC_ATTR_SIZE_MASK	0x3
1804f5e7dd7Smrg#define	PCITOOL_ACC_ATTR_SIZE_1		0x0
1814f5e7dd7Smrg#define	PCITOOL_ACC_ATTR_SIZE_2		0x1
1824f5e7dd7Smrg#define	PCITOOL_ACC_ATTR_SIZE_4		0x2
1834f5e7dd7Smrg#define	PCITOOL_ACC_ATTR_SIZE_8		0x3
1844f5e7dd7Smrg#define	PCITOOL_ACC_ATTR_SIZE(x)	(1 << (x & PCITOOL_ACC_ATTR_SIZE_MASK))
1854f5e7dd7Smrg
1864f5e7dd7Smrg#define	PCITOOL_ACC_ATTR_ENDN_MASK	0x100
1874f5e7dd7Smrg#define	PCITOOL_ACC_ATTR_ENDN_LTL	0x0
1884f5e7dd7Smrg#define	PCITOOL_ACC_ATTR_ENDN_BIG	0x100
1894f5e7dd7Smrg#define	PCITOOL_ACC_IS_BIG_ENDIAN(x)	(x & PCITOOL_ACC_ATTR_ENDN_BIG)
1904f5e7dd7Smrg
1914f5e7dd7Smrg/*
1924f5e7dd7Smrg * Data structure to read and write to pci device registers.
1934f5e7dd7Smrg * This is the argument to the following ioctls:
1944f5e7dd7Smrg *	PCITOOL_DEVICE_SET/GET_REG
1954f5e7dd7Smrg *	PCITOOL_NEXUS_SET/GET_REG
1964f5e7dd7Smrg */
1974f5e7dd7Smrgtypedef struct pcitool_reg {
1984f5e7dd7Smrg	uint16_t	user_version;	/* Userland program version - to krnl */
1994f5e7dd7Smrg	uint16_t	drvr_version;	/* Driver version - from kernel */
2004f5e7dd7Smrg	uint8_t		bus_no;		/* pci bus - to kernel */
2014f5e7dd7Smrg	uint8_t		dev_no;		/* pci dev - to kernel */
2024f5e7dd7Smrg	uint8_t		func_no;	/* pci function - to kernel */
2034f5e7dd7Smrg	uint8_t		barnum;		/* bank (DEVCTL_NEXUS_SET/GET_REG) or */
2044f5e7dd7Smrg					/*   BAR from pcitools_bar_t */
2054f5e7dd7Smrg					/*   (DEVCTL_DEVICE_SET/GET_REG) */
2064f5e7dd7Smrg					/*   to kernel */
2074f5e7dd7Smrg	uint64_t	offset;		/* to kernel */
2084f5e7dd7Smrg	uint32_t	acc_attr;	/* access attributes - to kernel */
2094f5e7dd7Smrg	uint32_t	padding1;	/* 8-byte align next uint64_t for X86 */
2104f5e7dd7Smrg	uint64_t	data;		/* to/from kernel, 64-bit alignment */
2114f5e7dd7Smrg	uint32_t	status;		/* from kernel */
2124f5e7dd7Smrg	uint32_t	padding2;	/* 8-byte align next uint64_t for X86 */
2134f5e7dd7Smrg	uint64_t	phys_addr;	/* from kernel, 64-bit alignment */
2144f5e7dd7Smrg} pcitool_reg_t;
2154f5e7dd7Smrg
2164f5e7dd7Smrg
2174f5e7dd7Smrg#ifdef	__cplusplus
2184f5e7dd7Smrg}
2194f5e7dd7Smrg#endif
2204f5e7dd7Smrg
2214f5e7dd7Smrg#endif	/* _SYS_PCI_TOOLS_H */
222