xref: /illumos-gate/usr/src/uts/sun4/io/px/px_ioapi.h (revision c0da6274)
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
525cf1a30Sjl  * Common Development and Distribution License (the "License").
625cf1a30Sjl  * 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 /*
22ef2504f2SDaniel Ice  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_PX_IOAPI_H
277c478bd9Sstevel@tonic-gate #define	_SYS_PX_IOAPI_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifndef _ASM
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * SUN4V IO Data Definitions
377c478bd9Sstevel@tonic-gate  *
387c478bd9Sstevel@tonic-gate  * cpuid - A unique opaque value which represents a target cpu.
397c478bd9Sstevel@tonic-gate  *
407c478bd9Sstevel@tonic-gate  * devhandle -	Device handle. The device handle uniquely
417c478bd9Sstevel@tonic-gate  *		identifies a SUN4V device. It consists of the
427c478bd9Sstevel@tonic-gate  *		the lower 28-bits of the hi-cell of the first
437c478bd9Sstevel@tonic-gate  *		entry of the SUN4V device's "reg" property as defined
447c478bd9Sstevel@tonic-gate  *		by the SUN4V Bus Binding to Open Firmware.
457c478bd9Sstevel@tonic-gate  *
467c478bd9Sstevel@tonic-gate  * devino -	Device Interrupt Number. An unsigned integer representing
477c478bd9Sstevel@tonic-gate  *		an interrupt within a specific device.
487c478bd9Sstevel@tonic-gate  *
497c478bd9Sstevel@tonic-gate  * sysino -	System Interrupt Number. A 64-bit unsigned integer
507c478bd9Sstevel@tonic-gate  *		representing a unique interrupt within a "system".
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * intr_state - A flag representing the interrupt state for a
537c478bd9Sstevel@tonic-gate  *		a given sysino. The state values are defined as:
547c478bd9Sstevel@tonic-gate  *
557c478bd9Sstevel@tonic-gate  *		INTR_IDLE		0
567c478bd9Sstevel@tonic-gate  *		INTR_RECEIVED		1
577c478bd9Sstevel@tonic-gate  *		INTR_DELIVERED		2
587c478bd9Sstevel@tonic-gate  *
597c478bd9Sstevel@tonic-gate  * intr_valid_state - A flag representing the 'valid' state for
607c478bd9Sstevel@tonic-gate  *		a given sysino. The state values are defined as:
617c478bd9Sstevel@tonic-gate  *
627c478bd9Sstevel@tonic-gate  *		INTR_NOTVALID		0  sysino not enabled
637c478bd9Sstevel@tonic-gate  *		INTR_VALID		1  sysino enabled
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate typedef uint64_t devhandle_t;
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate typedef uint32_t cpuid_t;
697c478bd9Sstevel@tonic-gate typedef uint32_t devino_t;
707c478bd9Sstevel@tonic-gate typedef	uint64_t sysino_t;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate typedef enum intr_state {
737c478bd9Sstevel@tonic-gate 	INTR_IDLE_STATE 	= (uint32_t)0,
747c478bd9Sstevel@tonic-gate 	INTR_RECEIVED_STATE	= (uint32_t)1,
757c478bd9Sstevel@tonic-gate 	INTR_DELIVERED_STATE	= (uint32_t)2
767c478bd9Sstevel@tonic-gate } intr_state_t;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate typedef enum intr_valid_state {
797c478bd9Sstevel@tonic-gate 	INTR_NOTVALID		= (uint32_t)0,
807c478bd9Sstevel@tonic-gate 	INTR_VALID		= (uint32_t)1
817c478bd9Sstevel@tonic-gate } intr_valid_state_t;
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * PCI IO Data Definitions
857c478bd9Sstevel@tonic-gate  *
867c478bd9Sstevel@tonic-gate  * tsbnum -	TSB Number. Identifies which io-tsb is used.
877c478bd9Sstevel@tonic-gate  *		For this version of the spec, tsbnum must be zero.
887c478bd9Sstevel@tonic-gate  *
897c478bd9Sstevel@tonic-gate  * tsbindex -	TSB Index. Identifies which entry in the tsb is
907c478bd9Sstevel@tonic-gate  *		is used. The first entry is zero.
917c478bd9Sstevel@tonic-gate  *
927c478bd9Sstevel@tonic-gate  * tsbid -	A 64-bit aligned data structure which contains
937c478bd9Sstevel@tonic-gate  *		a tsbnum and a tsbindex.
947c478bd9Sstevel@tonic-gate  *		bits 63:32 contain the tsbnum.
957c478bd9Sstevel@tonic-gate  *		bits 31:00 contain the tsbindex.
967c478bd9Sstevel@tonic-gate  *
977c478bd9Sstevel@tonic-gate  * io_attributes - IO Attributes for iommu mappings.
987c478bd9Sstevel@tonic-gate  *		Attributes for iommu mappings. One or more of the
997c478bd9Sstevel@tonic-gate  *		following attribute bits stored in a 64-bit unsigned int.
1007c478bd9Sstevel@tonic-gate  *
10144961713Sgirish  *	6				    3				      0
10244961713Sgirish  *	3				    1				      0
10344961713Sgirish  *	00000000 00000000 00000000 00000000 BBBBBBBB DDDDDFFF 00000000 00PP0LWR
10444961713Sgirish  *
10544961713Sgirish  *		R: DMA data is transferred from main memory to device.
10644961713Sgirish  *		W: DMA data is transferred from device to main memory.
10744961713Sgirish  *		L: Requested DMA transaction can be relaxed ordered within RC.
10844961713Sgirish  *		P: Value of PCI Express and PCI-X phantom function
10944961713Sgirish  *		   configuration. Its encoding is identical to the
11044961713Sgirish  *		   "Phantom Function Supported" field of the
11144961713Sgirish  *		   "Device Capabilities Register (offset 0x4)"
11244961713Sgirish  *		   in the "PCI Express Capability Structure".
11344961713Sgirish  *		   The structure is part of a device's config space.
11444961713Sgirish  *	      BDF: Bus, device and function number of the device
11544961713Sgirish  *		   that is going to issue DMA transactions.
11644961713Sgirish  *		   The BDF values are used to guarantee the mapping
11744961713Sgirish  *		   only be accessed by the specified device.
11844961713Sgirish  *		   If the BDF is set to all 0, RID based protection
11944961713Sgirish  *		   will be turned off.
12044961713Sgirish  *
12144961713Sgirish  *		Relaxed Ordering (L) is advisory. Not all hardware implements a
12244961713Sgirish  *		relaxed ordering attribute. If L attribute is not implemented in
12344961713Sgirish  *		hardware, the implementation is permitted to ignore the L bit.
12444961713Sgirish  *
12544961713Sgirish  *		Bits 3, 15:6 and 63:32 are unused and must be set to zero for
12644961713Sgirish  *		this version of the specification.
1277c478bd9Sstevel@tonic-gate  *
1287c478bd9Sstevel@tonic-gate  *		Note: For compatibility with future versions of this
12944961713Sgirish  *		specification, the caller must set bits 3, 15:6 and 63:32 to
13044961713Sgirish  *		zero. The implementation shall ignore these bits.
1317c478bd9Sstevel@tonic-gate  *
1327c478bd9Sstevel@tonic-gate  * r_addr -	64-bit Real Address.
1337c478bd9Sstevel@tonic-gate  *
1347c478bd9Sstevel@tonic-gate  * io_addr -	64-bit IO Address.
1357c478bd9Sstevel@tonic-gate  *
1367c478bd9Sstevel@tonic-gate  * pci_device - PCI device address. A PCI device address
1377c478bd9Sstevel@tonic-gate  *		identifies a specific device on a specific PCI
1387c478bd9Sstevel@tonic-gate  *		bus segment. A PCI device address is a 32-bit unsigned
1397c478bd9Sstevel@tonic-gate  *		integer with the following format:
1407c478bd9Sstevel@tonic-gate  *
1417c478bd9Sstevel@tonic-gate  *			00000000.bbbbbbbb.dddddfff.00000000
1427c478bd9Sstevel@tonic-gate  *
1437c478bd9Sstevel@tonic-gate  *		Where:
1447c478bd9Sstevel@tonic-gate  *
1457c478bd9Sstevel@tonic-gate  *			bbbbbbbb is the 8-bit pci bus number
1467c478bd9Sstevel@tonic-gate  *			ddddd is the 5-bit pci device number
1477c478bd9Sstevel@tonic-gate  *			fff is the 3-bit pci function number
1487c478bd9Sstevel@tonic-gate  *
1497c478bd9Sstevel@tonic-gate  *			00000000 is the 8-bit literal zero.
1507c478bd9Sstevel@tonic-gate  *
1517c478bd9Sstevel@tonic-gate  * pci_config_offset -	PCI Configuration Space offset.
1527c478bd9Sstevel@tonic-gate  *
1537c478bd9Sstevel@tonic-gate  *		For conventional PCI, an unsigned integer in the range
1547c478bd9Sstevel@tonic-gate  *		0 .. 255 representing the offset of the field in pci config
1557c478bd9Sstevel@tonic-gate  *		space.
1567c478bd9Sstevel@tonic-gate  *
1577c478bd9Sstevel@tonic-gate  *		For PCI implementations with extended configuration space,
1587c478bd9Sstevel@tonic-gate  *		an unsigned integer in the range 0 .. 4095, representing
1597c478bd9Sstevel@tonic-gate  *		the offset of the field in configuration space. Conventional
1607c478bd9Sstevel@tonic-gate  *		PCI config space is offset 0 .. 255. Extended config space
1617c478bd9Sstevel@tonic-gate  *		is offset 256 .. 4095
1627c478bd9Sstevel@tonic-gate  *
1637c478bd9Sstevel@tonic-gate  *		Note: For pci config space accesses, the offset must be 'size'
1647c478bd9Sstevel@tonic-gate  *		aligned.
1657c478bd9Sstevel@tonic-gate  *
1667c478bd9Sstevel@tonic-gate  * error_flag -	Error flag
1677c478bd9Sstevel@tonic-gate  *
1687c478bd9Sstevel@tonic-gate  *		A return value specifies if the action succeeded
1697c478bd9Sstevel@tonic-gate  *		or failed, where:
1707c478bd9Sstevel@tonic-gate  *
1717c478bd9Sstevel@tonic-gate  *			0 - No error occurred while performing the service.
1727c478bd9Sstevel@tonic-gate  *			non-zero - Error occurred while performing the service.
1737c478bd9Sstevel@tonic-gate  *
1747c478bd9Sstevel@tonic-gate  * io_sync_direction - "direction" definition for pci_dma_sync
1757c478bd9Sstevel@tonic-gate  *
1767c478bd9Sstevel@tonic-gate  *		A value specifying the direction for a memory/io sync
1777c478bd9Sstevel@tonic-gate  *		operation, The direction value is a flag, one or both
1787c478bd9Sstevel@tonic-gate  *		directions may be specified by the caller.
1797c478bd9Sstevel@tonic-gate  *
1807c478bd9Sstevel@tonic-gate  *			0x01 - For device (device read from memory)
1817c478bd9Sstevel@tonic-gate  *			0x02 - For cpu (device write to memory)
1827c478bd9Sstevel@tonic-gate  *
1837c478bd9Sstevel@tonic-gate  * io_page_list - A list of io_page_addresses. An io_page_address
1847c478bd9Sstevel@tonic-gate  *		is an r_addr.
1857c478bd9Sstevel@tonic-gate  *
1867c478bd9Sstevel@tonic-gate  * io_page_list_p - A pointer to an io_page_list.
1877c478bd9Sstevel@tonic-gate  */
1887c478bd9Sstevel@tonic-gate typedef uint32_t tsbnum_t;
1897c478bd9Sstevel@tonic-gate typedef uint32_t tsbindex_t;
1907c478bd9Sstevel@tonic-gate typedef uint64_t tsbid_t;
1917c478bd9Sstevel@tonic-gate typedef uint64_t r_addr_t;
1927c478bd9Sstevel@tonic-gate typedef uint64_t io_addr_t;
1937c478bd9Sstevel@tonic-gate typedef uint64_t io_page_list_t;
1947c478bd9Sstevel@tonic-gate typedef uint32_t pages_t;
1957c478bd9Sstevel@tonic-gate typedef uint32_t error_flag_t;
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate typedef uint32_t pci_config_offset_t;
1987c478bd9Sstevel@tonic-gate typedef uint64_t pci_device_t;
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate #define	PCI_TSB_INDEX		0
2017c478bd9Sstevel@tonic-gate #define	PCI_TSB_INDEX_MASK	0xFFFFFFFF
2027c478bd9Sstevel@tonic-gate #define	PCI_TSB_NUM		32
2037c478bd9Sstevel@tonic-gate #define	PCI_TSB_NUM_MASK	0xFFFFFFFF
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate #define	PCI_TSBID(tsbnum, tsbindex) \
2067c478bd9Sstevel@tonic-gate 	((((tsbid_t)tsbnum & PCI_TSB_NUM_MASK) << PCI_TSB_NUM) | \
2077c478bd9Sstevel@tonic-gate 	(((tsbid_t)tsbindex & PCI_TSB_INDEX_MASK) << PCI_TSB_INDEX))
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate #define	PCI_TSBID_TO_TSBNUM(tsbid) \
2107c478bd9Sstevel@tonic-gate 	((tsbid >> PCI_TSB_NUM) & PCI_TSB_NUM_MASK)
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate #define	PCI_TSBID_TO_TSBINDEX(tsbid) \
2137c478bd9Sstevel@tonic-gate 	((tsbid >> PCI_TSB_INDEX) & PCI_TSB_INDEX_MASK)
2147c478bd9Sstevel@tonic-gate 
215ef2504f2SDaniel Ice typedef	uint64_t io_attributes_t;
216ef2504f2SDaniel Ice 
217ef2504f2SDaniel Ice #define	PCI_MAP_ATTR_READ	0x1ull
218ef2504f2SDaniel Ice #define	PCI_MAP_ATTR_WRITE	0x2ull
219ef2504f2SDaniel Ice #define	PCI_MAP_ATTR_RO		0x4ull
2207c478bd9Sstevel@tonic-gate 
22144961713Sgirish #define	PCI_MAP_ATTR_PHFUN	4
22244961713Sgirish #define	PCI_MAP_ATTR_BDF	16
22344961713Sgirish 
224ef2504f2SDaniel Ice #define	PCI_MAP_ATTR_PHFUN_MASK	0x30
225ef2504f2SDaniel Ice #define	PCI_MAP_ATTR_BDF_MASK	0xffff0000
226ef2504f2SDaniel Ice 
22744961713Sgirish #define	PX_ADD_ATTR_EXTNS(attr, bdf) \
228*c85864d8SKrishna Elango 	(attr | (PCIE_CHECK_VALID_BDF(bdf) ? (bdf << PCI_MAP_ATTR_BDF) : 0))
22944961713Sgirish 
2307c478bd9Sstevel@tonic-gate typedef enum io_sync_direction {
2317c478bd9Sstevel@tonic-gate 	IO_SYNC_DEVICE		= (uint32_t)0x01,
2327c478bd9Sstevel@tonic-gate 	IO_SYNC_CPU		= (uint32_t)0x02
2337c478bd9Sstevel@tonic-gate } io_sync_direction_t;
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate  *	MSI Definitions
2377c478bd9Sstevel@tonic-gate  *
2387c478bd9Sstevel@tonic-gate  *	MSI - Message Signaled Interrupt
2397c478bd9Sstevel@tonic-gate  *
2407c478bd9Sstevel@tonic-gate  *	  Message Signaled Interrupt as defined in the PCI Local Bus
2417c478bd9Sstevel@tonic-gate  *	  Specification and the PCI Express Base Specification.
2427c478bd9Sstevel@tonic-gate  *	  A device signals an interrupt via MSI using a posted
2437c478bd9Sstevel@tonic-gate  *	  write cycle to an address specified by system software
2447c478bd9Sstevel@tonic-gate  *	  using a data value specified by system software.
2457c478bd9Sstevel@tonic-gate  *	  The MSI capability data structure contains fields for
2467c478bd9Sstevel@tonic-gate  *	  the PCI address and data values the device uses when
2477c478bd9Sstevel@tonic-gate  *	  sending an MSI message on the bus. MSI-X is an extended
2487c478bd9Sstevel@tonic-gate  *	  form of MSI, but uses the same mechanism for signaling
2497c478bd9Sstevel@tonic-gate  *	  the interrupt as MSI. For the purposes of this document,
2507c478bd9Sstevel@tonic-gate  *	  the term "MSI" refers to MSI or MSI-X.
2517c478bd9Sstevel@tonic-gate  *
2527c478bd9Sstevel@tonic-gate  *	  Root complexes that support MSI define an address range
2537c478bd9Sstevel@tonic-gate  *	  and set of data values that can be used to signal MSIs.
2547c478bd9Sstevel@tonic-gate  *
2557c478bd9Sstevel@tonic-gate  *	  SUN4V/pci requirements for MSI:
2567c478bd9Sstevel@tonic-gate  *
2577c478bd9Sstevel@tonic-gate  *		The root complex defines two address ranges. One in
2587c478bd9Sstevel@tonic-gate  *		the 32-bit pci memory space and one in the 64-bit
2597c478bd9Sstevel@tonic-gate  *		pci memory address space used as the target of a posted
2607c478bd9Sstevel@tonic-gate  *		write to signal an MSI.
2617c478bd9Sstevel@tonic-gate  *
2627c478bd9Sstevel@tonic-gate  *		The root complex treats any write to these address
2637c478bd9Sstevel@tonic-gate  *		ranges as signaling an MSI, however, only the data
2647c478bd9Sstevel@tonic-gate  *		value used in the posted write signals the MSI.
2657c478bd9Sstevel@tonic-gate  *
2667c478bd9Sstevel@tonic-gate  *
2677c478bd9Sstevel@tonic-gate  *	MSI EQ - MSI Event Queue
2687c478bd9Sstevel@tonic-gate  *
2697c478bd9Sstevel@tonic-gate  *	  The MSI Event Queue is a page-aligned main memory data
2707c478bd9Sstevel@tonic-gate  *	  structure used to store MSI data records.
2717c478bd9Sstevel@tonic-gate  *
2727c478bd9Sstevel@tonic-gate  *	  Each root port supports several MSI EQs, and each EQ has a
2737c478bd9Sstevel@tonic-gate  *	  system interrupt associated with it, and can be targeted
2747c478bd9Sstevel@tonic-gate  *	  (individually) to any cpu. The number of MSI EQs supported
2757c478bd9Sstevel@tonic-gate  *	  by a root complex is described by a property defined in [3].
2767c478bd9Sstevel@tonic-gate  *	  Each MSI EQ must be large enough to contain all possible MSI
2777c478bd9Sstevel@tonic-gate  *	  data records generated by any one PCI root port. The number
2787c478bd9Sstevel@tonic-gate  *	  of entries in each MSI EQ is described by a property defined
2797c478bd9Sstevel@tonic-gate  *	  in [3].
2807c478bd9Sstevel@tonic-gate  *
2817c478bd9Sstevel@tonic-gate  *	  Each MSI EQ is compliant with the definition of interrupt
2827c478bd9Sstevel@tonic-gate  *	  queues described in [5], however, instead of accessing the
2837c478bd9Sstevel@tonic-gate  *	  queue head/tail registers via ASI-based registers, an API
2847c478bd9Sstevel@tonic-gate  *	  is provided to access the head/tail registers.
2857c478bd9Sstevel@tonic-gate  *
2867c478bd9Sstevel@tonic-gate  *	  The SUN4V/pci compliant root complex has the ability to
2877c478bd9Sstevel@tonic-gate  *	  generate a system interrupt when the MSI EQ is non-empty.
2887c478bd9Sstevel@tonic-gate  *
2897c478bd9Sstevel@tonic-gate  *	MSI/Message/INTx Data Record format
2907c478bd9Sstevel@tonic-gate  *
2917c478bd9Sstevel@tonic-gate  *	  Each data record consists of 64 bytes of data, aligned
2927c478bd9Sstevel@tonic-gate  *	  on a 64-byte boundary.
2937c478bd9Sstevel@tonic-gate  *
2947c478bd9Sstevel@tonic-gate  *	  The data record is defined as follows:
2957c478bd9Sstevel@tonic-gate  *
2967c478bd9Sstevel@tonic-gate  *
2977c478bd9Sstevel@tonic-gate  *	6666555555555544444444443333333333222222222211111111110000000000
2987c478bd9Sstevel@tonic-gate  *	3210987654321098765432109876543210987654321098765432109876543210
2997c478bd9Sstevel@tonic-gate  *
3007c478bd9Sstevel@tonic-gate  *	0x00:	VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVxxxxxxxxxxxxxxxxxxxxxxxxTTTTTTTT
3017c478bd9Sstevel@tonic-gate  *	0x08:	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
3027c478bd9Sstevel@tonic-gate  *	0x10:	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
3037c478bd9Sstevel@tonic-gate  *	0x18:	SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
3047c478bd9Sstevel@tonic-gate  *	0x20:	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxRRRRRRRRRRRRRRRR
3057c478bd9Sstevel@tonic-gate  *	0x28:	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
3067c478bd9Sstevel@tonic-gate  *	0x30:	DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
3077c478bd9Sstevel@tonic-gate  *	0x38:	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
3087c478bd9Sstevel@tonic-gate  *
3097c478bd9Sstevel@tonic-gate  *	Where,
3107c478bd9Sstevel@tonic-gate  *
3117c478bd9Sstevel@tonic-gate  *	  xx..xx are unused bits and must be ignored by sw.
3127c478bd9Sstevel@tonic-gate  *
3137c478bd9Sstevel@tonic-gate  *	  VV..VV is the version number of this data record
3147c478bd9Sstevel@tonic-gate  *
3157c478bd9Sstevel@tonic-gate  *		For this release of the spec, the version number
3167c478bd9Sstevel@tonic-gate  *		field must be zero.
3177c478bd9Sstevel@tonic-gate  *
3187c478bd9Sstevel@tonic-gate  *	  TTTTTTTT is the data record type:
3197c478bd9Sstevel@tonic-gate  *
3207c478bd9Sstevel@tonic-gate  *		Upper 4 bits are reserved, and must be zero
3217c478bd9Sstevel@tonic-gate  *
3227c478bd9Sstevel@tonic-gate  *		0000 - Not an MSI data record - reserved for sw use.
3237c478bd9Sstevel@tonic-gate  *		0001 - MSG
3247c478bd9Sstevel@tonic-gate  *		0010 - MSI32
3257c478bd9Sstevel@tonic-gate  *		0011 - MSI64
3267c478bd9Sstevel@tonic-gate  *		0010 - Reserved
3277c478bd9Sstevel@tonic-gate  *		...
3287c478bd9Sstevel@tonic-gate  *		0111 - Reserved
3297c478bd9Sstevel@tonic-gate  *		1000 - INTx
3307c478bd9Sstevel@tonic-gate  *		1001 - Reserved
3317c478bd9Sstevel@tonic-gate  *		...
3327c478bd9Sstevel@tonic-gate  *		1110 - Reserved
3337c478bd9Sstevel@tonic-gate  *		1111 - Not an MSI data record - reserved for sw use.
3347c478bd9Sstevel@tonic-gate  *
3357c478bd9Sstevel@tonic-gate  *		All other encodings are reserved.
3367c478bd9Sstevel@tonic-gate  *
3377c478bd9Sstevel@tonic-gate  *	  II..II is the sysino for INTx (sw defined value),
3387c478bd9Sstevel@tonic-gate  *		otherwise zero.
3397c478bd9Sstevel@tonic-gate  *
3407c478bd9Sstevel@tonic-gate  *	  SS..SS is the message timestamp if available.
3417c478bd9Sstevel@tonic-gate  *		If supported by the implementation, a non-zero
3427c478bd9Sstevel@tonic-gate  *		value in this field is a copy of the %stick register
3437c478bd9Sstevel@tonic-gate  *		at the time the message is created.
3447c478bd9Sstevel@tonic-gate  *
3457c478bd9Sstevel@tonic-gate  *		If unsupported, this field will contain zero.
3467c478bd9Sstevel@tonic-gate  *
3477c478bd9Sstevel@tonic-gate  *	  RR..RR is the requester ID of the device that initiated the MSI/MSG
3487c478bd9Sstevel@tonic-gate  *	  and has the following format:
3497c478bd9Sstevel@tonic-gate  *
3507c478bd9Sstevel@tonic-gate  *		bbbbbbbb.dddddfff
3517c478bd9Sstevel@tonic-gate  *
3527c478bd9Sstevel@tonic-gate  *		Where bb..bb is the bus number,
3537c478bd9Sstevel@tonic-gate  *		dd..dd is the device number
3547c478bd9Sstevel@tonic-gate  *		and fff is the function number.
3557c478bd9Sstevel@tonic-gate  *
3567c478bd9Sstevel@tonic-gate  *		Note that for PCI devices or any message where
3577c478bd9Sstevel@tonic-gate  *		the requester is unknown, this may be zero,
3587c478bd9Sstevel@tonic-gate  *		or the device-id of an intermediate bridge.
3597c478bd9Sstevel@tonic-gate  *
3607c478bd9Sstevel@tonic-gate  *		For intx messages, this field should be ignored.
3617c478bd9Sstevel@tonic-gate  *
3627c478bd9Sstevel@tonic-gate  *	  AA..AA is the MSI address. For MSI32, the upper 32-bits must be zero.
3637c478bd9Sstevel@tonic-gate  *	  (for data record type MSG or INTx, this field is ignored)
3647c478bd9Sstevel@tonic-gate  *
3657c478bd9Sstevel@tonic-gate  *	  DD..DD is the MSI/MSG data or INTx number
3667c478bd9Sstevel@tonic-gate  *
3677c478bd9Sstevel@tonic-gate  *		For MSI-X, bits 31..0 contain the data from the MSI packet
3687c478bd9Sstevel@tonic-gate  *		which is the msi-number. bits 63..32 shall be zero.
3697c478bd9Sstevel@tonic-gate  *
3707c478bd9Sstevel@tonic-gate  *		For MSI, bits 15..0 contain the data from the MSI message
3717c478bd9Sstevel@tonic-gate  *		which is the msi-number. bits 63..16 shall be zero
3727c478bd9Sstevel@tonic-gate  *
3737c478bd9Sstevel@tonic-gate  *		For MSG data, the message code and message routing code
3747c478bd9Sstevel@tonic-gate  *		are encoded as follows:
3757c478bd9Sstevel@tonic-gate  *
3767c478bd9Sstevel@tonic-gate  *		63:32 - 0000.0000.0000.0000.0000.0000.GGGG.GGGG
3777c478bd9Sstevel@tonic-gate  *		32:00 - 0000.0000.0000.0CCC.0000.0000.MMMM.MMMM
3787c478bd9Sstevel@tonic-gate  *
3797c478bd9Sstevel@tonic-gate  *			Where,
3807c478bd9Sstevel@tonic-gate  *
3817c478bd9Sstevel@tonic-gate  *			GG..GG is the target-id of the message in the
3827c478bd9Sstevel@tonic-gate  *			following form:
3837c478bd9Sstevel@tonic-gate  *
3847c478bd9Sstevel@tonic-gate  *				bbbbbbbb.dddddfff
3857c478bd9Sstevel@tonic-gate  *
3867c478bd9Sstevel@tonic-gate  *				where bb..bb is the target bus number.
3877c478bd9Sstevel@tonic-gate  *				ddddd is the target deviceid
3887c478bd9Sstevel@tonic-gate  *				fff is the target function number.
3897c478bd9Sstevel@tonic-gate  *
3907c478bd9Sstevel@tonic-gate  *			CCC is the message routing code as defined by [4]
3917c478bd9Sstevel@tonic-gate  *
3927c478bd9Sstevel@tonic-gate  *			MM..MM is the message code as defined by [4]
3937c478bd9Sstevel@tonic-gate  *
3947c478bd9Sstevel@tonic-gate  *		For INTx data, bits 63:2 must be zero and
3957c478bd9Sstevel@tonic-gate  *		the low order 2 bits are defined as follows:
3967c478bd9Sstevel@tonic-gate  *
3977c478bd9Sstevel@tonic-gate  *			00 - INTA
3987c478bd9Sstevel@tonic-gate  *			01 - INTB
3997c478bd9Sstevel@tonic-gate  *			10 - INTC
4007c478bd9Sstevel@tonic-gate  *			11 - INTD
4017c478bd9Sstevel@tonic-gate  *
4027c478bd9Sstevel@tonic-gate  *	cpuid - A unique opaque value which represents a target cpu.
4037c478bd9Sstevel@tonic-gate  *
4047c478bd9Sstevel@tonic-gate  *	devhandle - Device handle. The device handle uniquely identifies a
4057c478bd9Sstevel@tonic-gate  *	  SUN4V device. It consists of the the lower 28-bits of the hi-cell
4067c478bd9Sstevel@tonic-gate  *	  of the first entry of the SUN4V device's "reg" property as defined
4077c478bd9Sstevel@tonic-gate  *	  by the SUN4V Bus Binding to Open Firmware.
4087c478bd9Sstevel@tonic-gate  *
4097c478bd9Sstevel@tonic-gate  *	msinum	- A value defining which MSI is being used.
4107c478bd9Sstevel@tonic-gate  *
4117c478bd9Sstevel@tonic-gate  *	msiqhead - The index value of the current head index for a given
4127c478bd9Sstevel@tonic-gate  *	  MSI-EQ.
4137c478bd9Sstevel@tonic-gate  *
4147c478bd9Sstevel@tonic-gate  *	msiqtail - The index value of the current tail index for a given
4157c478bd9Sstevel@tonic-gate  *	  MSI-EQ.
4167c478bd9Sstevel@tonic-gate  *
4177c478bd9Sstevel@tonic-gate  *	msitype - Type specifier for MSI32 or MSI64
4187c478bd9Sstevel@tonic-gate  *		0 - type is MSI32
4197c478bd9Sstevel@tonic-gate  *		1 - type is MSI64
4207c478bd9Sstevel@tonic-gate  *
4217c478bd9Sstevel@tonic-gate  *	msiqid	- A number from 0 .. 'number of MSI-EQs - 1', defining
4227c478bd9Sstevel@tonic-gate  *	  which MSI EQ within the device is being used.
4237c478bd9Sstevel@tonic-gate  *
4247c478bd9Sstevel@tonic-gate  *	msiqstate - An unsigned integer containing one of the
4257c478bd9Sstevel@tonic-gate  *	  following values:
4267c478bd9Sstevel@tonic-gate  *
4277c478bd9Sstevel@tonic-gate  *		PCI_MSIQSTATE_IDLE		0	# idle (non-error) state
4287c478bd9Sstevel@tonic-gate  *		PCI_MSIQSTATE_ERROR		1	# error state
4297c478bd9Sstevel@tonic-gate  *
4307c478bd9Sstevel@tonic-gate  *	msiqvalid - An unsigned integer containing one of the
4317c478bd9Sstevel@tonic-gate  *		following values:
4327c478bd9Sstevel@tonic-gate  *
4337c478bd9Sstevel@tonic-gate  *		PCI_MSIQ_INVALID		0	# disabled/invalid
4347c478bd9Sstevel@tonic-gate  *		PCI_MSIQ_VALID			1	# enabled/valid
4357c478bd9Sstevel@tonic-gate  *
4367c478bd9Sstevel@tonic-gate  *	msistate - An unsigned integer containing one of the following
4377c478bd9Sstevel@tonic-gate  *	  values:
4387c478bd9Sstevel@tonic-gate  *
4397c478bd9Sstevel@tonic-gate  *		PCI_MSISTATE_IDLE		0	# idle/not enabled
4407c478bd9Sstevel@tonic-gate  *		PCI_MSISTATE_DELIVERED		1	# MSI Delivered
4417c478bd9Sstevel@tonic-gate  *
4427c478bd9Sstevel@tonic-gate  *	msivalid - An unsigned integer containing one of the
4437c478bd9Sstevel@tonic-gate  *		following values:
4447c478bd9Sstevel@tonic-gate  *
4457c478bd9Sstevel@tonic-gate  *		PCI_MSI_INVALID			0	# disabled/invalid
4467c478bd9Sstevel@tonic-gate  *		PCI_MSI_VALID			1	# enabled/valid
4477c478bd9Sstevel@tonic-gate  *
4487c478bd9Sstevel@tonic-gate  *	msgtype	- A value defining which MSG type is being used. An unsigned
4497c478bd9Sstevel@tonic-gate  *		integer containing one of the following values:
4507c478bd9Sstevel@tonic-gate  *		(as per PCIe spec 1.0a)
4517c478bd9Sstevel@tonic-gate  *
4527c478bd9Sstevel@tonic-gate  *		PCIE_PME_MSG			0x18	PME message
4537c478bd9Sstevel@tonic-gate  *		PCIE_PME_ACK_MSG		0x1b	PME ACK message
4547c478bd9Sstevel@tonic-gate  *		PCIE_CORR_MSG			0x30	Correctable message
4557c478bd9Sstevel@tonic-gate  *		PCIE_NONFATAL_MSG		0x31	Non fatal message
4567c478bd9Sstevel@tonic-gate  *		PCIE_FATAL_MSG			0x33	Fatal message
4577c478bd9Sstevel@tonic-gate  */
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate typedef uint32_t msinum_t;
4607c478bd9Sstevel@tonic-gate typedef uint32_t msiqid_t;
4617c478bd9Sstevel@tonic-gate typedef uint32_t msgcode_t;
4627c478bd9Sstevel@tonic-gate typedef	uint64_t msiqhead_t;
4637c478bd9Sstevel@tonic-gate typedef	uint64_t msiqtail_t;
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate /* MSIQ state */
4667c478bd9Sstevel@tonic-gate typedef enum pci_msiq_state {
4677c478bd9Sstevel@tonic-gate 	PCI_MSIQ_STATE_IDLE 	= (uint32_t)0,	/* idle (non-error) state */
4687c478bd9Sstevel@tonic-gate 	PCI_MSIQ_STATE_ERROR 	= (uint32_t)1	/* error state */
4697c478bd9Sstevel@tonic-gate } pci_msiq_state_t;
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate /* MSIQ valid */
4727c478bd9Sstevel@tonic-gate typedef enum pci_msiq_valid_state {
4737c478bd9Sstevel@tonic-gate 	PCI_MSIQ_INVALID	= (uint32_t)0,	/* disabled/invalid */
4747c478bd9Sstevel@tonic-gate 	PCI_MSIQ_VALID		= (uint32_t)1	/* enabled/valid */
4757c478bd9Sstevel@tonic-gate } pci_msiq_valid_state_t;
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate /* MSIQ Record data structure */
4787c478bd9Sstevel@tonic-gate typedef struct msiq_rec {
4797c478bd9Sstevel@tonic-gate 	uint64_t	msiq_rec_version : 32,	/* DW 0 - 63:32 */
4807c478bd9Sstevel@tonic-gate 			msiq_rec_rsvd0 : 24,	/* DW 0 - 31:09 */
4817c478bd9Sstevel@tonic-gate 			msiq_rec_type : 8;	/* DW 0 - 07:00 */
4827c478bd9Sstevel@tonic-gate 	uint64_t	msiq_rec_intx;		/* DW 1 */
4837c478bd9Sstevel@tonic-gate 	uint64_t	msiq_rec_rsvd1;		/* DW 2 */
4847c478bd9Sstevel@tonic-gate 	uint64_t	msiq_rec_timestamp;	/* DW 3 */
4857c478bd9Sstevel@tonic-gate 	uint64_t	msiq_rec_rsvd2 : 48,	/* DW 4 - 63:16 */
4867c478bd9Sstevel@tonic-gate 			msiq_rec_rid : 16;	/* DW 4 - 15:00 */
4877c478bd9Sstevel@tonic-gate 	uint64_t	msiq_rec_msi_addr;	/* DW 5 - 63:00 */
4887c478bd9Sstevel@tonic-gate 	union {
4897c478bd9Sstevel@tonic-gate 		struct {
4907c478bd9Sstevel@tonic-gate 			uint64_t	msix_rsvd0 : 32, /* DW 6 - 63:32 */
4917c478bd9Sstevel@tonic-gate 					msix_data : 32;	/* DW 6 - 31:00 */
4927c478bd9Sstevel@tonic-gate 		} msix;
4937c478bd9Sstevel@tonic-gate 		struct {
4947c478bd9Sstevel@tonic-gate 			uint64_t	msi_rsvd0 : 48,	/* DW 6 - 63:16 */
4957c478bd9Sstevel@tonic-gate 					msi_data: 16;	/* DW 6 - 15:00 */
4967c478bd9Sstevel@tonic-gate 		} msi;
4977c478bd9Sstevel@tonic-gate 		struct {
4987c478bd9Sstevel@tonic-gate 			uint64_t	msg_rsvd0: 24,	/* DW 6 - 63:40 */
4997c478bd9Sstevel@tonic-gate 					msg_targ: 8,	/* DW 6 - 39:32 */
5007c478bd9Sstevel@tonic-gate 					msg_rsvd1: 13,	/* DW 6 - 31:19 */
5017c478bd9Sstevel@tonic-gate 					msg_route: 3,	/* DW 6 - 18:16 */
5027c478bd9Sstevel@tonic-gate 					msg_rsvd2: 8,	/* DW 6 - 15:08 */
5037c478bd9Sstevel@tonic-gate 					msg_code: 8;	/* DW 6 - 07:00 */
5047c478bd9Sstevel@tonic-gate 		} msg;
5057c478bd9Sstevel@tonic-gate 	} msiq_rec_data;
5067c478bd9Sstevel@tonic-gate 	uint64_t	msiq_rec_rsvd3;			/* DW 7 */
5077c478bd9Sstevel@tonic-gate } msiq_rec_t;
5087c478bd9Sstevel@tonic-gate 
5097c478bd9Sstevel@tonic-gate /* MSIQ Record type */
5107c478bd9Sstevel@tonic-gate typedef enum msiq_rec_type {
5117c478bd9Sstevel@tonic-gate 	MSG_REC			= (uint32_t)1,	/* PCIe message record */
5127c478bd9Sstevel@tonic-gate 	MSI32_REC		= (uint32_t)2,	/* MSI32 record */
5137c478bd9Sstevel@tonic-gate 	MSI64_REC		= (uint32_t)3,	/* MSI64 record */
5147c478bd9Sstevel@tonic-gate 	INTX_REC		= (uint32_t)8	/* INTx record */
5157c478bd9Sstevel@tonic-gate } msiq_rec_type_t;
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate /* MSIQ Record type */
5187c478bd9Sstevel@tonic-gate typedef enum msi_type {
5197c478bd9Sstevel@tonic-gate 	MSI32_TYPE		= (uint32_t)0,	/* MSI32 type */
5207c478bd9Sstevel@tonic-gate 	MSI64_TYPE		= (uint32_t)1	/* MSI64 type */
5217c478bd9Sstevel@tonic-gate } msi_type_t;
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate /* MSI state */
5247c478bd9Sstevel@tonic-gate typedef enum pci_msi_state {
5257c478bd9Sstevel@tonic-gate 	PCI_MSI_STATE_IDLE	= (uint32_t)0,	/* idle/not enabled */
5267c478bd9Sstevel@tonic-gate 	PCI_MSI_STATE_DELIVERED	= (uint32_t)1	/* MSI delivered */
5277c478bd9Sstevel@tonic-gate } pci_msi_state_t;
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate /* MSI valid */
5307c478bd9Sstevel@tonic-gate typedef enum pci_msi_valid_state {
5317c478bd9Sstevel@tonic-gate 	PCI_MSI_INVALID		= (uint32_t)0,  /* disabled/invalid */
5327c478bd9Sstevel@tonic-gate 	PCI_MSI_VALID		= (uint32_t)1   /* enabled/valid */
5337c478bd9Sstevel@tonic-gate } pci_msi_valid_state_t;
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate /* MSG valid */
5367c478bd9Sstevel@tonic-gate typedef enum pcie_msg_valid_state {
5377c478bd9Sstevel@tonic-gate 	PCIE_MSG_INVALID	= (uint32_t)0,  /* disabled/invalid */
5387c478bd9Sstevel@tonic-gate 	PCIE_MSG_VALID		= (uint32_t)1   /* enabled/valid */
5397c478bd9Sstevel@tonic-gate } pcie_msg_valid_state_t;
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate /* PCIe MSG types */
5427c478bd9Sstevel@tonic-gate typedef enum pcie_msg_type {
5437c478bd9Sstevel@tonic-gate 	PCIE_PME_MSG		= (uint64_t)0x18, /* PME message */
5447c478bd9Sstevel@tonic-gate 	PCIE_PME_ACK_MSG	= (uint64_t)0x1b, /* PME ACK message */
5457c478bd9Sstevel@tonic-gate 	PCIE_CORR_MSG		= (uint64_t)0x30, /* Correctable message */
5467c478bd9Sstevel@tonic-gate 	PCIE_NONFATAL_MSG	= (uint64_t)0x31, /* Non fatal message */
5477c478bd9Sstevel@tonic-gate 	PCIE_FATAL_MSG		= (uint64_t)0x33  /* Fatal message */
5487c478bd9Sstevel@tonic-gate } pcie_msg_type_t;
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate #endif /* _ASM */
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
5537c478bd9Sstevel@tonic-gate }
5547c478bd9Sstevel@tonic-gate #endif
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate #endif	/* _SYS_PX_IOAPI_H */
557