xref: /titanic_41/usr/src/uts/common/sys/pci_impl.h (revision a31148363f598def767ac48c5d82e1572e44b935)
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
544961713Sgirish  * Common Development and Distribution License (the "License").
644961713Sgirish  * 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 /*
22ffa17327SGuoli Shu  * 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_PCI_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_SYS_PCI_IMPL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
307c478bd9Sstevel@tonic-gate #include <sys/memlist.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef __cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * There are two ways to access the PCI configuration space on X86
407c478bd9Sstevel@tonic-gate  * 	Access method 2 is the older method
417c478bd9Sstevel@tonic-gate  *	Access method 1 is the newer method and is preferred because
427c478bd9Sstevel@tonic-gate  *	  of the problems in trying to lock the configuration space
437c478bd9Sstevel@tonic-gate  *	  for MP machines using method 2.  See PCI Local BUS Specification
447c478bd9Sstevel@tonic-gate  *	  Revision 2.0 section 3.6.4.1 for more details.
457c478bd9Sstevel@tonic-gate  *
467c478bd9Sstevel@tonic-gate  * In addition, on IBM Sandalfoot and a few related machines there's
477c478bd9Sstevel@tonic-gate  * still another mechanism.  See PReP 1.1 section 6.1.7.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	PCI_MECHANISM_UNKNOWN		-1
517c478bd9Sstevel@tonic-gate #define	PCI_MECHANISM_NONE		0
52c2e7b48dSkalai #if defined(__i386) || defined(__amd64)
537c478bd9Sstevel@tonic-gate #define	PCI_MECHANISM_1 		1
547c478bd9Sstevel@tonic-gate #define	PCI_MECHANISM_2			2
557c478bd9Sstevel@tonic-gate #else
567c478bd9Sstevel@tonic-gate #error "Unknown processor type"
577c478bd9Sstevel@tonic-gate #endif
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #ifndef FALSE
617c478bd9Sstevel@tonic-gate #define	FALSE   0
627c478bd9Sstevel@tonic-gate #endif
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #ifndef TRUE
657c478bd9Sstevel@tonic-gate #define	TRUE    1
667c478bd9Sstevel@tonic-gate #endif
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #define	PCI_FUNC_MASK			0x07
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /* these macros apply to Configuration Mechanism #1 */
717c478bd9Sstevel@tonic-gate #define	PCI_CONFADD		0xcf8
727c478bd9Sstevel@tonic-gate #define	PCI_PMC			0xcfb
737c478bd9Sstevel@tonic-gate #define	PCI_CONFDATA		0xcfc
747c478bd9Sstevel@tonic-gate #define	PCI_CONE		0x80000000
757c478bd9Sstevel@tonic-gate #define	PCI_CADDR1(bus, device, function, reg) \
767c478bd9Sstevel@tonic-gate 		(PCI_CONE | (((bus) & 0xff) << 16) | (((device & 0x1f)) << 11) \
777c478bd9Sstevel@tonic-gate 			    | (((function) & 0x7) << 8) | ((reg) & 0xfc))
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /* these macros apply to Configuration Mechanism #2 */
807c478bd9Sstevel@tonic-gate #define	PCI_CSE_PORT		0xcf8
817c478bd9Sstevel@tonic-gate #define	PCI_FORW_PORT		0xcfa
827c478bd9Sstevel@tonic-gate #define	PCI_CADDR2(device, indx) \
837c478bd9Sstevel@tonic-gate 		(0xc000 | (((device) & 0xf) <<  8) | (indx))
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate typedef struct 	pci_acc_cfblk {
867c478bd9Sstevel@tonic-gate 	uchar_t	c_busnum;		/* bus number */
877c478bd9Sstevel@tonic-gate 	uchar_t c_devnum;		/* device number */
887c478bd9Sstevel@tonic-gate 	uchar_t c_funcnum;		/* function number */
897c478bd9Sstevel@tonic-gate 	uchar_t c_fill;			/* reserve field */
907c478bd9Sstevel@tonic-gate } pci_acc_cfblk_t;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate struct pci_bus_resource {
932f283da5SDan Mick 	struct memlist *io_avail;	/* available free io res */
942f283da5SDan Mick 	struct memlist *io_used;	/* used io res */
952f283da5SDan Mick 	struct memlist *mem_avail;	/* available free mem res */
962f283da5SDan Mick 	struct memlist *mem_used;	/* used mem res */
972f283da5SDan Mick 	struct memlist *pmem_avail; /* available free prefetchable mem res */
982f283da5SDan Mick 	struct memlist *pmem_used; /* used prefetchable mem res */
992f283da5SDan Mick 	struct memlist *bus_avail;	/* available free bus res */
10005f867c3Sgs150176 			/* bus_space_used not needed; can read from regs */
1017c478bd9Sstevel@tonic-gate 	dev_info_t *dip;	/* devinfo node */
1027c478bd9Sstevel@tonic-gate 	void *privdata;		/* private data for configuration */
1037c478bd9Sstevel@tonic-gate 	uchar_t par_bus;	/* parent bus number */
1047c478bd9Sstevel@tonic-gate 	uchar_t sub_bus;	/* highest bus number beyond this bridge */
1057c478bd9Sstevel@tonic-gate 	uchar_t root_addr;	/* legacy peer bus address assignment */
10605f867c3Sgs150176 	uchar_t num_cbb;	/* # of CardBus Bridges on the bus */
10705f867c3Sgs150176 	boolean_t io_reprogram;	/* need io reprog on this bus */
10805f867c3Sgs150176 	boolean_t mem_reprogram;	/* need mem reprog on this bus */
10905f867c3Sgs150176 	boolean_t subtractive;	/* subtractive PPB */
110ffa17327SGuoli Shu 	uint_t mem_size;	/* existing children required MEM space size */
111ffa17327SGuoli Shu 	uint_t io_size;		/* existing children required I/O space size */
1127c478bd9Sstevel@tonic-gate };
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate extern struct pci_bus_resource *pci_bus_res;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * For now, x86-only to avoid conflicts with <sys/memlist_impl.h>
1187c478bd9Sstevel@tonic-gate  */
119*a3114836SGerry Liu #define	memlist_find		memlist_find_pci
120*a3114836SGerry Liu #define	memlist_insert		memlist_insert_pci
121*a3114836SGerry Liu 
1227c478bd9Sstevel@tonic-gate extern struct memlist *memlist_alloc(void);
1237c478bd9Sstevel@tonic-gate extern void memlist_free(struct memlist *);
12405f867c3Sgs150176 extern void memlist_free_all(struct memlist **);
1257c478bd9Sstevel@tonic-gate extern void memlist_insert(struct memlist **, uint64_t, uint64_t);
1267c478bd9Sstevel@tonic-gate extern int memlist_remove(struct memlist **, uint64_t, uint64_t);
1277c478bd9Sstevel@tonic-gate extern uint64_t memlist_find(struct memlist **, uint64_t, int);
12805f867c3Sgs150176 extern uint64_t memlist_find_with_startaddr(struct memlist **, uint64_t,
12905f867c3Sgs150176     uint64_t, int);
1307c478bd9Sstevel@tonic-gate extern void memlist_dump(struct memlist *);
1312f283da5SDan Mick extern void memlist_subsume(struct memlist **, struct memlist **);
13205f867c3Sgs150176 extern void memlist_merge(struct memlist **, struct memlist **);
1337c478bd9Sstevel@tonic-gate extern struct memlist *memlist_dup(struct memlist *);
1347c478bd9Sstevel@tonic-gate extern int memlist_count(struct memlist *);
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate #endif /* __i386 || __amd64 */
1377c478bd9Sstevel@tonic-gate 
13826947304SEvan Yan /* Definitions for minor numbers */
13926947304SEvan Yan #define	PCI_MINOR_NUM(x, y)		(((uint_t)(x) << 8) | ((y) & 0xFF))
14026947304SEvan Yan #define	PCI_MINOR_NUM_TO_PCI_DEVNUM(x)	((x) & 0xFF)
14126947304SEvan Yan #define	PCI_MINOR_NUM_TO_INSTANCE(x)	((x) >> 8)
14226947304SEvan Yan #define	PCI_DEVCTL_MINOR		0xFF
14326947304SEvan Yan 
14426947304SEvan Yan /*
14526947304SEvan Yan  * Minor numbers for dedicated pcitool nodes.
14626947304SEvan Yan  * Note that FF and FE minor numbers are used for other minor nodes.
14726947304SEvan Yan  */
14826947304SEvan Yan #define	PCI_TOOL_REG_MINOR_NUM		0xFD
14926947304SEvan Yan #define	PCI_TOOL_INTR_MINOR_NUM		0xFC
15026947304SEvan Yan 
15126947304SEvan Yan /* pci devctl soft state flag */
15226947304SEvan Yan #define	PCI_SOFT_STATE_CLOSED		0x0
15326947304SEvan Yan #define	PCI_SOFT_STATE_OPEN		0x1
15426947304SEvan Yan #define	PCI_SOFT_STATE_OPEN_EXCL	0x2
15526947304SEvan Yan 
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate  * PCI capability related definitions.
1587c478bd9Sstevel@tonic-gate  */
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate /*
1617c478bd9Sstevel@tonic-gate  * Minimum number of dwords to be saved.
1627c478bd9Sstevel@tonic-gate  */
1637c478bd9Sstevel@tonic-gate #define	PCI_MSI_MIN_WORDS	3
1647c478bd9Sstevel@tonic-gate #define	PCI_PCIX_MIN_WORDS	2
1657c478bd9Sstevel@tonic-gate #define	PCI_PCIE_MIN_WORDS	5
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate  * Total number of dwords to be saved.
1697c478bd9Sstevel@tonic-gate  */
1707c478bd9Sstevel@tonic-gate #define	PCI_PMCAP_NDWORDS	2
1717c478bd9Sstevel@tonic-gate #define	PCI_AGP_NDWORDS		3
1727c478bd9Sstevel@tonic-gate #define	PCI_SLOTID_NDWORDS	1
1737c478bd9Sstevel@tonic-gate #define	PCI_MSIX_NDWORDS	3
1747c478bd9Sstevel@tonic-gate #define	PCI_CAP_SZUNKNOWN	0
1757c478bd9Sstevel@tonic-gate 
176cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_SLPRI_NDWORDS		7
177cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_HOSTSEC_NDWORDS	6
178cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_INTCONF_NDWORDS	2
179cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_REVID_NDWORDS		1
180cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_UNITID_CLUMP_NDWORDS	3
181cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_ECFG_NDWORDS		3
182cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_ADDRMAP_NDWORDS	PCI_CAP_SZUNKNOWN	/* variable */
183cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_MSIMAP_NDWORDS	3
184cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_DIRROUTE_NDWORDS	3
185cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_VCSET_NDWORDS		3
186cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_RETRYMODE_NDWORDS	3
187cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_GEN3_NDWORDS		10
188cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_FUNCEXT_NDWORDS	PCI_CAP_SZUNKNOWN	/* variable */
189cb7ea99dSJimmy Vetayases #define	PCI_HTCAP_PM_NDWORDS		2
190cb7ea99dSJimmy Vetayases 
191cb7ea99dSJimmy Vetayases 
1927c478bd9Sstevel@tonic-gate #define	CAP_ID(confhdl, cap_ptr, xspace)		\
1937c478bd9Sstevel@tonic-gate 	((xspace) ? 0 : pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_ID))
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate #define	NEXT_CAP(confhdl, cap_ptr, xspace)	\
1967c478bd9Sstevel@tonic-gate 	((xspace) ? 0 :				\
1977c478bd9Sstevel@tonic-gate 	pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_NEXT_PTR))
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate extern int pci_resource_setup(dev_info_t *);
2007c478bd9Sstevel@tonic-gate extern void pci_resource_destroy(dev_info_t *);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2037c478bd9Sstevel@tonic-gate }
2047c478bd9Sstevel@tonic-gate #endif
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate #endif /* _SYS_PCI_IMPL_H */
207