xref: /illumos-gate/usr/src/uts/sun4u/sys/pci/pci_var.h (revision 26947304)
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
500d0963fSdilpreet  * Common Development and Distribution License (the "License").
600d0963fSdilpreet  * 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 /*
22*26947304SEvan Yan  * 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_VAR_H
277c478bd9Sstevel@tonic-gate #define	_SYS_PCI_VAR_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * The following typedef is used to represent a
357c478bd9Sstevel@tonic-gate  * 1275 "reg" property of a PCI nexus.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate typedef struct pci_nexus_regspec {
387c478bd9Sstevel@tonic-gate 	uint64_t phys_addr;
397c478bd9Sstevel@tonic-gate 	uint64_t size;
407c478bd9Sstevel@tonic-gate } pci_nexus_regspec_t;
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate typedef enum { PSYCHO, SCHIZO } pci_bridge_t;
437c478bd9Sstevel@tonic-gate typedef enum { A, B } pci_side_t;
447c478bd9Sstevel@tonic-gate typedef enum { PCI_NEW, PCI_ATTACHED, PCI_DETACHED, PCI_SUSPENDED } pci_state_t;
457c478bd9Sstevel@tonic-gate typedef enum { PCI_PBM_OBJ, PCI_ECC_OBJ, PCI_CB_OBJ } pci_obj_t;
467c478bd9Sstevel@tonic-gate typedef enum { PCI_OBJ_INTR_ADD, PCI_OBJ_INTR_REMOVE } pci_obj_op_t;
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #define	PCI_ATTACH_RETCODE(obj, op, err) \
497c478bd9Sstevel@tonic-gate 	((err) ? (obj) << 8 | (op) << 4 | (err) & 0xf : DDI_SUCCESS)
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #define	PCI_OTHER_SIDE(side) ((side) ^ 1)
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * the sequence of the chip_type appearance is significant. There are code
557c478bd9Sstevel@tonic-gate  * depending on it: CHIP_TYPE(pci_p) < PCI_CHIP_SCHIZO.
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate typedef enum {
587c478bd9Sstevel@tonic-gate 	PCI_CHIP_UNIDENTIFIED = 0,
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 	PCI_CHIP_PSYCHO = 1,
617c478bd9Sstevel@tonic-gate 	PCI_CHIP_SABRE,
627c478bd9Sstevel@tonic-gate 	PCI_CHIP_HUMMINGBIRD,
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	PCI_CHIP_SCHIZO = 0x11,
657c478bd9Sstevel@tonic-gate 	PCI_CHIP_XMITS,
667c478bd9Sstevel@tonic-gate 	PCI_CHIP_TOMATILLO
677c478bd9Sstevel@tonic-gate } pci_chip_id_t;
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * [msb]				[lsb]
717c478bd9Sstevel@tonic-gate  * 0x00 <chip_type> <version#> <module-revision#>
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate #define	CHIP_ID(t, v, m) 	(((t) << 16) | ((v) << 8) | (m))
747c478bd9Sstevel@tonic-gate #define	ID_CHIP_TYPE(id) 	((id) >> 16)
757c478bd9Sstevel@tonic-gate #define	PCI_CHIP_ID(pci_p) 	((pci_p)->pci_common_p->pci_chip_id)
767c478bd9Sstevel@tonic-gate #define	CHIP_TYPE(pci_p) 	ID_CHIP_TYPE(PCI_CHIP_ID(pci_p))
777c478bd9Sstevel@tonic-gate #define	CHIP_REV(pci_p)		(PCI_CHIP_ID(pci_p) & 0xFF)
787c478bd9Sstevel@tonic-gate #define	CHIP_VER(pci_p)		((PCI_CHIP_ID(pci_p) >> 8) & 0xFF)
797c478bd9Sstevel@tonic-gate #define	CB_CHIP_TYPE(cb_p) 	((cb_p)->cb_pci_cmn_p->pci_chip_id >> 16)
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * pci common soft state structure:
837c478bd9Sstevel@tonic-gate  *
847c478bd9Sstevel@tonic-gate  * Each psycho or schizo is represented by a pair of pci nodes in the
857c478bd9Sstevel@tonic-gate  * device tree.  A single pci common soft state is allocated for each
867c478bd9Sstevel@tonic-gate  * pair.  The UPA (Safari) bus id of the psycho (schizo) is used for
877c478bd9Sstevel@tonic-gate  * the instance number.  The attach routine uses the existance of a
887c478bd9Sstevel@tonic-gate  * pci common soft state structure to determine if one node from the
897c478bd9Sstevel@tonic-gate  * pair has been attached.
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate struct pci_common {
927c478bd9Sstevel@tonic-gate 	uint_t pci_common_id;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	/* pointers & counters to facilitate attach/detach & suspend/resume */
957c478bd9Sstevel@tonic-gate 	ushort_t pci_common_refcnt;	/* # of sides suspended + attached */
967c478bd9Sstevel@tonic-gate 	ushort_t pci_common_attachcnt;	/* # of sides attached */
977c478bd9Sstevel@tonic-gate 	uint16_t pci_common_tsb_cookie;	/* IOMMU TSB allocation */
987c478bd9Sstevel@tonic-gate 	pci_t *pci_p[2];		/* pci soft states of both sides */
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	uint32_t pci_chip_id;		/* Bus bridge chip identification */
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	/* Links to functional blocks potentially shared between pci nodes */
1037c478bd9Sstevel@tonic-gate 	iommu_t *pci_common_iommu_p;
1047c478bd9Sstevel@tonic-gate 	cb_t *pci_common_cb_p;
1057c478bd9Sstevel@tonic-gate 	ib_t *pci_common_ib_p;
1067c478bd9Sstevel@tonic-gate 	ecc_t *pci_common_ecc_p;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	/*
1097c478bd9Sstevel@tonic-gate 	 * Performance counters kstat.
1107c478bd9Sstevel@tonic-gate 	 */
1117c478bd9Sstevel@tonic-gate 	pci_cntr_pa_t	pci_cmn_uks_pa;
1127c478bd9Sstevel@tonic-gate 	kstat_t	*pci_common_uksp;	/* ptr to upstream kstat */
1137c478bd9Sstevel@tonic-gate 	kmutex_t pci_fm_mutex;		/* per chip error handling mutex */
1147c478bd9Sstevel@tonic-gate };
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * pci soft state structure:
1187c478bd9Sstevel@tonic-gate  *
1197c478bd9Sstevel@tonic-gate  * Each pci node has a pci soft state structure.
1207c478bd9Sstevel@tonic-gate  */
1217c478bd9Sstevel@tonic-gate struct pci {
1227c478bd9Sstevel@tonic-gate 	/*
1237c478bd9Sstevel@tonic-gate 	 * State flags and mutex:
1247c478bd9Sstevel@tonic-gate 	 */
1257c478bd9Sstevel@tonic-gate 	pci_state_t pci_state;
1267c478bd9Sstevel@tonic-gate 	uint_t pci_soft_state;
1277c478bd9Sstevel@tonic-gate 	uint16_t pci_tsb_cookie;	/* IOMMU TSB allocation */
1287c478bd9Sstevel@tonic-gate 	kmutex_t pci_mutex;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	/*
1317c478bd9Sstevel@tonic-gate 	 * Links to other state structures:
1327c478bd9Sstevel@tonic-gate 	 */
1337c478bd9Sstevel@tonic-gate 	pci_common_t *pci_common_p;	/* pointer common soft state */
1347c478bd9Sstevel@tonic-gate 	dev_info_t *pci_dip;		/* devinfo structure */
1357c478bd9Sstevel@tonic-gate 	ib_t *pci_ib_p;			/* interrupt block */
1367c478bd9Sstevel@tonic-gate 	cb_t *pci_cb_p;			/* control block */
1377c478bd9Sstevel@tonic-gate 	pbm_t *pci_pbm_p;		/* PBM block */
1387c478bd9Sstevel@tonic-gate 	iommu_t	*pci_iommu_p;		/* IOMMU block */
1397c478bd9Sstevel@tonic-gate 	sc_t *pci_sc_p;			/* streaming cache block */
1407c478bd9Sstevel@tonic-gate 	ecc_t *pci_ecc_p;		/* ECC error block */
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	/*
1437c478bd9Sstevel@tonic-gate 	 * other state info:
1447c478bd9Sstevel@tonic-gate 	 */
1457c478bd9Sstevel@tonic-gate 	uint_t pci_id;			/* UPA (or Safari) device id */
1467c478bd9Sstevel@tonic-gate 	pci_side_t pci_side;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	/*
1497c478bd9Sstevel@tonic-gate 	 * pci device node properties:
1507c478bd9Sstevel@tonic-gate 	 */
1517c478bd9Sstevel@tonic-gate 	pci_bus_range_t pci_bus_range;	/* "bus-range" */
1527c478bd9Sstevel@tonic-gate 	pci_ranges_t *pci_ranges;	/* "ranges" data & length */
1537c478bd9Sstevel@tonic-gate 	int pci_ranges_length;
1547c478bd9Sstevel@tonic-gate 	uint32_t *pci_inos;		/* inos from "interrupts" prop */
1557c478bd9Sstevel@tonic-gate 	int pci_inos_len;		/* "interrupts" length */
1567c478bd9Sstevel@tonic-gate 	int pci_numproxy;		/* upa interrupt proxies */
1577c478bd9Sstevel@tonic-gate 	int pci_thermal_interrupt;	/* node has thermal interrupt */
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	/*
1607c478bd9Sstevel@tonic-gate 	 * register mapping:
1617c478bd9Sstevel@tonic-gate 	 */
1627c478bd9Sstevel@tonic-gate 	caddr_t pci_address[4];
1637c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t pci_ac[4];
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	/* Interrupt support */
1667c478bd9Sstevel@tonic-gate 	int intr_map_size;
1677c478bd9Sstevel@tonic-gate 	struct intr_map *intr_map;
1687c478bd9Sstevel@tonic-gate 	struct intr_map_mask *intr_map_mask;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	/* performance counters */
1717c478bd9Sstevel@tonic-gate 	pci_cntr_addr_t	pci_ks_addr;
1727c478bd9Sstevel@tonic-gate 	kstat_t	*pci_ksp;
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 	/* Hotplug information */
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	boolean_t	hotplug_capable;
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	/* Fault Management support */
1797c478bd9Sstevel@tonic-gate 	int pci_fm_cap;
1807c478bd9Sstevel@tonic-gate 	ddi_iblock_cookie_t pci_fm_ibc;
1817c478bd9Sstevel@tonic-gate };
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate /*
1847c478bd9Sstevel@tonic-gate  * PSYCHO and PBM soft state macros:
1857c478bd9Sstevel@tonic-gate  */
1867c478bd9Sstevel@tonic-gate #define	get_pci_soft_state(i)	\
1877c478bd9Sstevel@tonic-gate 	((pci_t *)ddi_get_soft_state(per_pci_state, (i)))
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate #define	alloc_pci_soft_state(i)	\
1907c478bd9Sstevel@tonic-gate 	ddi_soft_state_zalloc(per_pci_state, (i))
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate #define	free_pci_soft_state(i)	\
1937c478bd9Sstevel@tonic-gate 	ddi_soft_state_free(per_pci_state, (i))
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate #define	get_pci_common_soft_state(i)	\
1967c478bd9Sstevel@tonic-gate 	((pci_common_t *)ddi_get_soft_state(per_pci_common_state, (i)))
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate #define	alloc_pci_common_soft_state(i)	\
1997c478bd9Sstevel@tonic-gate 	ddi_soft_state_zalloc(per_pci_common_state, (i))
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate #define	free_pci_common_soft_state(i)	\
2027c478bd9Sstevel@tonic-gate 	ddi_soft_state_free(per_pci_common_state, (i))
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate #define	DEV_TO_SOFTSTATE(dev)	((pci_t *)ddi_get_soft_state(per_pci_state, \
2057c478bd9Sstevel@tonic-gate 	PCIHP_AP_MINOR_NUM_TO_INSTANCE(getminor(dev))))
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate extern void *per_pci_state;		/* per-pbm soft state pointer */
2087c478bd9Sstevel@tonic-gate extern void *per_pci_common_state;	/* per-psycho soft state pointer */
2097c478bd9Sstevel@tonic-gate extern kmutex_t pci_global_mutex;	/* attach/detach common struct lock */
2107c478bd9Sstevel@tonic-gate extern kmutex_t dvma_active_list_mutex;
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /*
2137c478bd9Sstevel@tonic-gate  * function prototypes for bus ops routines:
2147c478bd9Sstevel@tonic-gate  */
2157c478bd9Sstevel@tonic-gate extern int
2167c478bd9Sstevel@tonic-gate pci_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
2177c478bd9Sstevel@tonic-gate 	off_t offset, off_t len, caddr_t *addrp);
2187c478bd9Sstevel@tonic-gate extern int
2197c478bd9Sstevel@tonic-gate pci_dma_setup(dev_info_t *dip, dev_info_t *rdip,
2207c478bd9Sstevel@tonic-gate 	ddi_dma_req_t *dmareq, ddi_dma_handle_t *handlep);
2217c478bd9Sstevel@tonic-gate extern int
2227c478bd9Sstevel@tonic-gate pci_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attrp,
2237c478bd9Sstevel@tonic-gate 	int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep);
2247c478bd9Sstevel@tonic-gate extern int
2257c478bd9Sstevel@tonic-gate pci_dma_bindhdl(dev_info_t *dip, dev_info_t *rdip,
2267c478bd9Sstevel@tonic-gate 	ddi_dma_handle_t handle, ddi_dma_req_t *dmareq,
2277c478bd9Sstevel@tonic-gate 	ddi_dma_cookie_t *cookiep, uint_t *ccountp);
2287c478bd9Sstevel@tonic-gate extern int
2297c478bd9Sstevel@tonic-gate pci_dma_unbindhdl(dev_info_t *dip, dev_info_t *rdip,
2307c478bd9Sstevel@tonic-gate 	ddi_dma_handle_t handle);
2317c478bd9Sstevel@tonic-gate extern int
2327c478bd9Sstevel@tonic-gate pci_dma_flush(dev_info_t *dip, dev_info_t *rdip,
2337c478bd9Sstevel@tonic-gate 	ddi_dma_handle_t handle, off_t off, size_t len,
2347c478bd9Sstevel@tonic-gate 	uint_t cache_flags);
2357c478bd9Sstevel@tonic-gate extern int
2367c478bd9Sstevel@tonic-gate pci_dma_ctlops(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle,
2377c478bd9Sstevel@tonic-gate 	enum ddi_dma_ctlops cmd, off_t *offp, size_t *lenp, caddr_t *objp,
2387c478bd9Sstevel@tonic-gate 	uint_t cache_flags);
2397c478bd9Sstevel@tonic-gate extern int
2407c478bd9Sstevel@tonic-gate pci_ctlops(dev_info_t *dip, dev_info_t *rdip,
2417c478bd9Sstevel@tonic-gate 	ddi_ctl_enum_t op, void *arg, void *result);
2427c478bd9Sstevel@tonic-gate extern int
2437c478bd9Sstevel@tonic-gate pci_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
2447c478bd9Sstevel@tonic-gate 	ddi_intr_handle_impl_t *handle, void *result);
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2477c478bd9Sstevel@tonic-gate }
2487c478bd9Sstevel@tonic-gate #endif
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate #endif	/* _SYS_PCI_VAR_H */
251