xref: /onnv-gate/usr/src/uts/sun4u/sys/pci/pci_var.h (revision 10923:df470fd79c3c)
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
51865Sdilpreet  * Common Development and Distribution License (the "License").
61865Sdilpreet  * 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*10923SEvan.Yan@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_VAR_H
270Sstevel@tonic-gate #define	_SYS_PCI_VAR_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifdef	__cplusplus
300Sstevel@tonic-gate extern "C" {
310Sstevel@tonic-gate #endif
320Sstevel@tonic-gate 
330Sstevel@tonic-gate /*
340Sstevel@tonic-gate  * The following typedef is used to represent a
350Sstevel@tonic-gate  * 1275 "reg" property of a PCI nexus.
360Sstevel@tonic-gate  */
370Sstevel@tonic-gate typedef struct pci_nexus_regspec {
380Sstevel@tonic-gate 	uint64_t phys_addr;
390Sstevel@tonic-gate 	uint64_t size;
400Sstevel@tonic-gate } pci_nexus_regspec_t;
410Sstevel@tonic-gate 
420Sstevel@tonic-gate typedef enum { PSYCHO, SCHIZO } pci_bridge_t;
430Sstevel@tonic-gate typedef enum { A, B } pci_side_t;
440Sstevel@tonic-gate typedef enum { PCI_NEW, PCI_ATTACHED, PCI_DETACHED, PCI_SUSPENDED } pci_state_t;
450Sstevel@tonic-gate typedef enum { PCI_PBM_OBJ, PCI_ECC_OBJ, PCI_CB_OBJ } pci_obj_t;
460Sstevel@tonic-gate typedef enum { PCI_OBJ_INTR_ADD, PCI_OBJ_INTR_REMOVE } pci_obj_op_t;
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #define	PCI_ATTACH_RETCODE(obj, op, err) \
490Sstevel@tonic-gate 	((err) ? (obj) << 8 | (op) << 4 | (err) & 0xf : DDI_SUCCESS)
500Sstevel@tonic-gate 
510Sstevel@tonic-gate #define	PCI_OTHER_SIDE(side) ((side) ^ 1)
520Sstevel@tonic-gate 
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate  * the sequence of the chip_type appearance is significant. There are code
550Sstevel@tonic-gate  * depending on it: CHIP_TYPE(pci_p) < PCI_CHIP_SCHIZO.
560Sstevel@tonic-gate  */
570Sstevel@tonic-gate typedef enum {
580Sstevel@tonic-gate 	PCI_CHIP_UNIDENTIFIED = 0,
590Sstevel@tonic-gate 
600Sstevel@tonic-gate 	PCI_CHIP_PSYCHO = 1,
610Sstevel@tonic-gate 	PCI_CHIP_SABRE,
620Sstevel@tonic-gate 	PCI_CHIP_HUMMINGBIRD,
630Sstevel@tonic-gate 
640Sstevel@tonic-gate 	PCI_CHIP_SCHIZO = 0x11,
650Sstevel@tonic-gate 	PCI_CHIP_XMITS,
660Sstevel@tonic-gate 	PCI_CHIP_TOMATILLO
670Sstevel@tonic-gate } pci_chip_id_t;
680Sstevel@tonic-gate 
690Sstevel@tonic-gate /*
700Sstevel@tonic-gate  * [msb]				[lsb]
710Sstevel@tonic-gate  * 0x00 <chip_type> <version#> <module-revision#>
720Sstevel@tonic-gate  */
730Sstevel@tonic-gate #define	CHIP_ID(t, v, m) 	(((t) << 16) | ((v) << 8) | (m))
740Sstevel@tonic-gate #define	ID_CHIP_TYPE(id) 	((id) >> 16)
750Sstevel@tonic-gate #define	PCI_CHIP_ID(pci_p) 	((pci_p)->pci_common_p->pci_chip_id)
760Sstevel@tonic-gate #define	CHIP_TYPE(pci_p) 	ID_CHIP_TYPE(PCI_CHIP_ID(pci_p))
770Sstevel@tonic-gate #define	CHIP_REV(pci_p)		(PCI_CHIP_ID(pci_p) & 0xFF)
780Sstevel@tonic-gate #define	CHIP_VER(pci_p)		((PCI_CHIP_ID(pci_p) >> 8) & 0xFF)
790Sstevel@tonic-gate #define	CB_CHIP_TYPE(cb_p) 	((cb_p)->cb_pci_cmn_p->pci_chip_id >> 16)
800Sstevel@tonic-gate 
810Sstevel@tonic-gate /*
820Sstevel@tonic-gate  * pci common soft state structure:
830Sstevel@tonic-gate  *
840Sstevel@tonic-gate  * Each psycho or schizo is represented by a pair of pci nodes in the
850Sstevel@tonic-gate  * device tree.  A single pci common soft state is allocated for each
860Sstevel@tonic-gate  * pair.  The UPA (Safari) bus id of the psycho (schizo) is used for
870Sstevel@tonic-gate  * the instance number.  The attach routine uses the existance of a
880Sstevel@tonic-gate  * pci common soft state structure to determine if one node from the
890Sstevel@tonic-gate  * pair has been attached.
900Sstevel@tonic-gate  */
910Sstevel@tonic-gate struct pci_common {
920Sstevel@tonic-gate 	uint_t pci_common_id;
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	/* pointers & counters to facilitate attach/detach & suspend/resume */
950Sstevel@tonic-gate 	ushort_t pci_common_refcnt;	/* # of sides suspended + attached */
960Sstevel@tonic-gate 	ushort_t pci_common_attachcnt;	/* # of sides attached */
970Sstevel@tonic-gate 	uint16_t pci_common_tsb_cookie;	/* IOMMU TSB allocation */
980Sstevel@tonic-gate 	pci_t *pci_p[2];		/* pci soft states of both sides */
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 	uint32_t pci_chip_id;		/* Bus bridge chip identification */
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	/* Links to functional blocks potentially shared between pci nodes */
1030Sstevel@tonic-gate 	iommu_t *pci_common_iommu_p;
1040Sstevel@tonic-gate 	cb_t *pci_common_cb_p;
1050Sstevel@tonic-gate 	ib_t *pci_common_ib_p;
1060Sstevel@tonic-gate 	ecc_t *pci_common_ecc_p;
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 	/*
1090Sstevel@tonic-gate 	 * Performance counters kstat.
1100Sstevel@tonic-gate 	 */
1110Sstevel@tonic-gate 	pci_cntr_pa_t	pci_cmn_uks_pa;
1120Sstevel@tonic-gate 	kstat_t	*pci_common_uksp;	/* ptr to upstream kstat */
1130Sstevel@tonic-gate 	kmutex_t pci_fm_mutex;		/* per chip error handling mutex */
1140Sstevel@tonic-gate };
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate /*
1170Sstevel@tonic-gate  * pci soft state structure:
1180Sstevel@tonic-gate  *
1190Sstevel@tonic-gate  * Each pci node has a pci soft state structure.
1200Sstevel@tonic-gate  */
1210Sstevel@tonic-gate struct pci {
1220Sstevel@tonic-gate 	/*
1230Sstevel@tonic-gate 	 * State flags and mutex:
1240Sstevel@tonic-gate 	 */
1250Sstevel@tonic-gate 	pci_state_t pci_state;
1260Sstevel@tonic-gate 	uint_t pci_soft_state;
1270Sstevel@tonic-gate 	uint16_t pci_tsb_cookie;	/* IOMMU TSB allocation */
1280Sstevel@tonic-gate 	kmutex_t pci_mutex;
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 	/*
1310Sstevel@tonic-gate 	 * Links to other state structures:
1320Sstevel@tonic-gate 	 */
1330Sstevel@tonic-gate 	pci_common_t *pci_common_p;	/* pointer common soft state */
1340Sstevel@tonic-gate 	dev_info_t *pci_dip;		/* devinfo structure */
1350Sstevel@tonic-gate 	ib_t *pci_ib_p;			/* interrupt block */
1360Sstevel@tonic-gate 	cb_t *pci_cb_p;			/* control block */
1370Sstevel@tonic-gate 	pbm_t *pci_pbm_p;		/* PBM block */
1380Sstevel@tonic-gate 	iommu_t	*pci_iommu_p;		/* IOMMU block */
1390Sstevel@tonic-gate 	sc_t *pci_sc_p;			/* streaming cache block */
1400Sstevel@tonic-gate 	ecc_t *pci_ecc_p;		/* ECC error block */
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	/*
1430Sstevel@tonic-gate 	 * other state info:
1440Sstevel@tonic-gate 	 */
1450Sstevel@tonic-gate 	uint_t pci_id;			/* UPA (or Safari) device id */
1460Sstevel@tonic-gate 	pci_side_t pci_side;
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate 	/*
1490Sstevel@tonic-gate 	 * pci device node properties:
1500Sstevel@tonic-gate 	 */
1510Sstevel@tonic-gate 	pci_bus_range_t pci_bus_range;	/* "bus-range" */
1520Sstevel@tonic-gate 	pci_ranges_t *pci_ranges;	/* "ranges" data & length */
1530Sstevel@tonic-gate 	int pci_ranges_length;
1540Sstevel@tonic-gate 	uint32_t *pci_inos;		/* inos from "interrupts" prop */
1550Sstevel@tonic-gate 	int pci_inos_len;		/* "interrupts" length */
1560Sstevel@tonic-gate 	int pci_numproxy;		/* upa interrupt proxies */
1570Sstevel@tonic-gate 	int pci_thermal_interrupt;	/* node has thermal interrupt */
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 	/*
1600Sstevel@tonic-gate 	 * register mapping:
1610Sstevel@tonic-gate 	 */
1620Sstevel@tonic-gate 	caddr_t pci_address[4];
1630Sstevel@tonic-gate 	ddi_acc_handle_t pci_ac[4];
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 	/* Interrupt support */
1660Sstevel@tonic-gate 	int intr_map_size;
1670Sstevel@tonic-gate 	struct intr_map *intr_map;
1680Sstevel@tonic-gate 	struct intr_map_mask *intr_map_mask;
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 	/* performance counters */
1710Sstevel@tonic-gate 	pci_cntr_addr_t	pci_ks_addr;
1720Sstevel@tonic-gate 	kstat_t	*pci_ksp;
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 	/* Hotplug information */
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate 	boolean_t	hotplug_capable;
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate 	/* Fault Management support */
1790Sstevel@tonic-gate 	int pci_fm_cap;
1800Sstevel@tonic-gate 	ddi_iblock_cookie_t pci_fm_ibc;
1810Sstevel@tonic-gate };
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate /*
1840Sstevel@tonic-gate  * PSYCHO and PBM soft state macros:
1850Sstevel@tonic-gate  */
1860Sstevel@tonic-gate #define	get_pci_soft_state(i)	\
1870Sstevel@tonic-gate 	((pci_t *)ddi_get_soft_state(per_pci_state, (i)))
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate #define	alloc_pci_soft_state(i)	\
1900Sstevel@tonic-gate 	ddi_soft_state_zalloc(per_pci_state, (i))
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate #define	free_pci_soft_state(i)	\
1930Sstevel@tonic-gate 	ddi_soft_state_free(per_pci_state, (i))
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate #define	get_pci_common_soft_state(i)	\
1960Sstevel@tonic-gate 	((pci_common_t *)ddi_get_soft_state(per_pci_common_state, (i)))
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate #define	alloc_pci_common_soft_state(i)	\
1990Sstevel@tonic-gate 	ddi_soft_state_zalloc(per_pci_common_state, (i))
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate #define	free_pci_common_soft_state(i)	\
2020Sstevel@tonic-gate 	ddi_soft_state_free(per_pci_common_state, (i))
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate #define	DEV_TO_SOFTSTATE(dev)	((pci_t *)ddi_get_soft_state(per_pci_state, \
2050Sstevel@tonic-gate 	PCIHP_AP_MINOR_NUM_TO_INSTANCE(getminor(dev))))
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate extern void *per_pci_state;		/* per-pbm soft state pointer */
2080Sstevel@tonic-gate extern void *per_pci_common_state;	/* per-psycho soft state pointer */
2090Sstevel@tonic-gate extern kmutex_t pci_global_mutex;	/* attach/detach common struct lock */
2100Sstevel@tonic-gate extern kmutex_t dvma_active_list_mutex;
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate /*
2130Sstevel@tonic-gate  * function prototypes for bus ops routines:
2140Sstevel@tonic-gate  */
2150Sstevel@tonic-gate extern int
2160Sstevel@tonic-gate pci_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
2170Sstevel@tonic-gate 	off_t offset, off_t len, caddr_t *addrp);
2180Sstevel@tonic-gate extern int
2190Sstevel@tonic-gate pci_dma_setup(dev_info_t *dip, dev_info_t *rdip,
2200Sstevel@tonic-gate 	ddi_dma_req_t *dmareq, ddi_dma_handle_t *handlep);
2210Sstevel@tonic-gate extern int
2220Sstevel@tonic-gate pci_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attrp,
2230Sstevel@tonic-gate 	int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep);
2240Sstevel@tonic-gate extern int
2250Sstevel@tonic-gate pci_dma_bindhdl(dev_info_t *dip, dev_info_t *rdip,
2260Sstevel@tonic-gate 	ddi_dma_handle_t handle, ddi_dma_req_t *dmareq,
2270Sstevel@tonic-gate 	ddi_dma_cookie_t *cookiep, uint_t *ccountp);
2280Sstevel@tonic-gate extern int
2290Sstevel@tonic-gate pci_dma_unbindhdl(dev_info_t *dip, dev_info_t *rdip,
2300Sstevel@tonic-gate 	ddi_dma_handle_t handle);
2310Sstevel@tonic-gate extern int
2320Sstevel@tonic-gate pci_dma_flush(dev_info_t *dip, dev_info_t *rdip,
2330Sstevel@tonic-gate 	ddi_dma_handle_t handle, off_t off, size_t len,
2340Sstevel@tonic-gate 	uint_t cache_flags);
2350Sstevel@tonic-gate extern int
2360Sstevel@tonic-gate pci_dma_ctlops(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle,
2370Sstevel@tonic-gate 	enum ddi_dma_ctlops cmd, off_t *offp, size_t *lenp, caddr_t *objp,
2380Sstevel@tonic-gate 	uint_t cache_flags);
2390Sstevel@tonic-gate extern int
2400Sstevel@tonic-gate pci_ctlops(dev_info_t *dip, dev_info_t *rdip,
2410Sstevel@tonic-gate 	ddi_ctl_enum_t op, void *arg, void *result);
2420Sstevel@tonic-gate extern int
2430Sstevel@tonic-gate pci_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
2440Sstevel@tonic-gate 	ddi_intr_handle_impl_t *handle, void *result);
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate #ifdef	__cplusplus
2470Sstevel@tonic-gate }
2480Sstevel@tonic-gate #endif
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate #endif	/* _SYS_PCI_VAR_H */
251