xref: /onnv-gate/usr/src/uts/common/sys/pci_impl.h (revision 9588:a4912846ca7d)
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
53156Sgirish  * Common Development and Distribution License (the "License").
63156Sgirish  * 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*9588SKerry.Shu@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _SYS_PCI_IMPL_H
270Sstevel@tonic-gate #define	_SYS_PCI_IMPL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <sys/dditypes.h>
310Sstevel@tonic-gate #include <sys/memlist.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #ifdef __cplusplus
340Sstevel@tonic-gate extern "C" {
350Sstevel@tonic-gate #endif
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate  * There are two ways to access the PCI configuration space on X86
410Sstevel@tonic-gate  * 	Access method 2 is the older method
420Sstevel@tonic-gate  *	Access method 1 is the newer method and is preferred because
430Sstevel@tonic-gate  *	  of the problems in trying to lock the configuration space
440Sstevel@tonic-gate  *	  for MP machines using method 2.  See PCI Local BUS Specification
450Sstevel@tonic-gate  *	  Revision 2.0 section 3.6.4.1 for more details.
460Sstevel@tonic-gate  *
470Sstevel@tonic-gate  * In addition, on IBM Sandalfoot and a few related machines there's
480Sstevel@tonic-gate  * still another mechanism.  See PReP 1.1 section 6.1.7.
490Sstevel@tonic-gate  */
500Sstevel@tonic-gate 
510Sstevel@tonic-gate #define	PCI_MECHANISM_UNKNOWN		-1
520Sstevel@tonic-gate #define	PCI_MECHANISM_NONE		0
53641Skalai #if defined(__i386) || defined(__amd64)
540Sstevel@tonic-gate #define	PCI_MECHANISM_1 		1
550Sstevel@tonic-gate #define	PCI_MECHANISM_2			2
560Sstevel@tonic-gate #else
570Sstevel@tonic-gate #error "Unknown processor type"
580Sstevel@tonic-gate #endif
590Sstevel@tonic-gate 
600Sstevel@tonic-gate 
610Sstevel@tonic-gate #ifndef FALSE
620Sstevel@tonic-gate #define	FALSE   0
630Sstevel@tonic-gate #endif
640Sstevel@tonic-gate 
650Sstevel@tonic-gate #ifndef TRUE
660Sstevel@tonic-gate #define	TRUE    1
670Sstevel@tonic-gate #endif
680Sstevel@tonic-gate 
690Sstevel@tonic-gate #define	PCI_FUNC_MASK			0x07
700Sstevel@tonic-gate 
710Sstevel@tonic-gate /* these macros apply to Configuration Mechanism #1 */
720Sstevel@tonic-gate #define	PCI_CONFADD		0xcf8
730Sstevel@tonic-gate #define	PCI_PMC			0xcfb
740Sstevel@tonic-gate #define	PCI_CONFDATA		0xcfc
750Sstevel@tonic-gate #define	PCI_CONE		0x80000000
760Sstevel@tonic-gate #define	PCI_CADDR1(bus, device, function, reg) \
770Sstevel@tonic-gate 		(PCI_CONE | (((bus) & 0xff) << 16) | (((device & 0x1f)) << 11) \
780Sstevel@tonic-gate 			    | (((function) & 0x7) << 8) | ((reg) & 0xfc))
790Sstevel@tonic-gate 
800Sstevel@tonic-gate /* these macros apply to Configuration Mechanism #2 */
810Sstevel@tonic-gate #define	PCI_CSE_PORT		0xcf8
820Sstevel@tonic-gate #define	PCI_FORW_PORT		0xcfa
830Sstevel@tonic-gate #define	PCI_CADDR2(device, indx) \
840Sstevel@tonic-gate 		(0xc000 | (((device) & 0xf) <<  8) | (indx))
850Sstevel@tonic-gate 
860Sstevel@tonic-gate typedef struct 	pci_acc_cfblk {
870Sstevel@tonic-gate 	uchar_t	c_busnum;		/* bus number */
880Sstevel@tonic-gate 	uchar_t c_devnum;		/* device number */
890Sstevel@tonic-gate 	uchar_t c_funcnum;		/* function number */
900Sstevel@tonic-gate 	uchar_t c_fill;			/* reserve field */
910Sstevel@tonic-gate } pci_acc_cfblk_t;
920Sstevel@tonic-gate 
930Sstevel@tonic-gate struct pci_bus_resource {
946095Sgs150176 	struct memlist *io_ports;	/* available free io res */
956095Sgs150176 	struct memlist *io_ports_used;	/* used io res */
966095Sgs150176 	struct memlist *mem_space;	/* available free mem res */
976095Sgs150176 	struct memlist *mem_space_used;	/* used mem res */
986095Sgs150176 	struct memlist *pmem_space; /* available free prefetchable mem res */
996095Sgs150176 	struct memlist *pmem_space_used; /* used prefetchable mem res */
1006095Sgs150176 	struct memlist *bus_space;	/* available free bus res */
1016095Sgs150176 			/* bus_space_used not needed; can read from regs */
1020Sstevel@tonic-gate 	dev_info_t *dip;	/* devinfo node */
1030Sstevel@tonic-gate 	void *privdata;		/* private data for configuration */
1040Sstevel@tonic-gate 	uchar_t par_bus;	/* parent bus number */
1050Sstevel@tonic-gate 	uchar_t sub_bus;	/* highest bus number beyond this bridge */
1060Sstevel@tonic-gate 	uchar_t root_addr;	/* legacy peer bus address assignment */
1076095Sgs150176 	uchar_t num_cbb;	/* # of CardBus Bridges on the bus */
1086095Sgs150176 	boolean_t io_reprogram;	/* need io reprog on this bus */
1096095Sgs150176 	boolean_t mem_reprogram;	/* need mem reprog on this bus */
1106095Sgs150176 	boolean_t subtractive;	/* subtractive PPB */
111*9588SKerry.Shu@Sun.COM 	uint_t mem_size;	/* existing children required MEM space size */
112*9588SKerry.Shu@Sun.COM 	uint_t io_size;		/* existing children required I/O space size */
1130Sstevel@tonic-gate };
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate extern struct pci_bus_resource *pci_bus_res;
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate /*
1180Sstevel@tonic-gate  * For now, x86-only to avoid conflicts with <sys/memlist_impl.h>
1190Sstevel@tonic-gate  */
1200Sstevel@tonic-gate extern struct memlist *memlist_alloc(void);
1210Sstevel@tonic-gate extern void memlist_free(struct memlist *);
1226095Sgs150176 extern void memlist_free_all(struct memlist **);
1230Sstevel@tonic-gate extern void memlist_insert(struct memlist **, uint64_t, uint64_t);
1240Sstevel@tonic-gate extern int memlist_remove(struct memlist **, uint64_t, uint64_t);
1250Sstevel@tonic-gate extern uint64_t memlist_find(struct memlist **, uint64_t, int);
1266095Sgs150176 extern uint64_t memlist_find_with_startaddr(struct memlist **, uint64_t,
1276095Sgs150176     uint64_t, int);
1280Sstevel@tonic-gate extern void memlist_dump(struct memlist *);
1296095Sgs150176 extern void memlist_merge(struct memlist **, struct memlist **);
1300Sstevel@tonic-gate extern struct memlist *memlist_dup(struct memlist *);
1310Sstevel@tonic-gate extern int memlist_count(struct memlist *);
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate #endif /* __i386 || __amd64 */
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate /*
1360Sstevel@tonic-gate  * PCI capability related definitions.
1370Sstevel@tonic-gate  */
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate /*
1400Sstevel@tonic-gate  * Minimum number of dwords to be saved.
1410Sstevel@tonic-gate  */
1420Sstevel@tonic-gate #define	PCI_MSI_MIN_WORDS	3
1430Sstevel@tonic-gate #define	PCI_PCIX_MIN_WORDS	2
1440Sstevel@tonic-gate #define	PCI_PCIE_MIN_WORDS	5
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate /*
1470Sstevel@tonic-gate  * Total number of dwords to be saved.
1480Sstevel@tonic-gate  */
1490Sstevel@tonic-gate #define	PCI_PMCAP_NDWORDS	2
1500Sstevel@tonic-gate #define	PCI_AGP_NDWORDS		3
1510Sstevel@tonic-gate #define	PCI_SLOTID_NDWORDS	1
1520Sstevel@tonic-gate #define	PCI_MSIX_NDWORDS	3
1530Sstevel@tonic-gate #define	PCI_CAP_SZUNKNOWN	0
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate #define	CAP_ID(confhdl, cap_ptr, xspace)		\
1560Sstevel@tonic-gate 	((xspace) ? 0 : pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_ID))
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate #define	NEXT_CAP(confhdl, cap_ptr, xspace)	\
1590Sstevel@tonic-gate 	((xspace) ? 0 :				\
1600Sstevel@tonic-gate 	pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_NEXT_PTR))
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate extern int pci_resource_setup(dev_info_t *);
1630Sstevel@tonic-gate extern void pci_resource_destroy(dev_info_t *);
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate #ifdef __cplusplus
1660Sstevel@tonic-gate }
1670Sstevel@tonic-gate #endif
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate #endif /* _SYS_PCI_IMPL_H */
170