xref: /titanic_50/usr/src/common/mc/mc-amd/mcamd_rowcol_impl.h (revision 8a40a695ee676a322b094e9afe5375567bfb51e3)
17aec1d6eScindi /*
27aec1d6eScindi  * CDDL HEADER START
37aec1d6eScindi  *
47aec1d6eScindi  * The contents of this file are subject to the terms of the
5*8a40a695Sgavinm  * Common Development and Distribution License (the "License").
6*8a40a695Sgavinm  * You may not use this file except in compliance with the License.
77aec1d6eScindi  *
87aec1d6eScindi  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97aec1d6eScindi  * or http://www.opensolaris.org/os/licensing.
107aec1d6eScindi  * See the License for the specific language governing permissions
117aec1d6eScindi  * and limitations under the License.
127aec1d6eScindi  *
137aec1d6eScindi  * When distributing Covered Code, include this CDDL HEADER in each
147aec1d6eScindi  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157aec1d6eScindi  * If applicable, add the following below this CDDL HEADER, with the
167aec1d6eScindi  * fields enclosed by brackets "[]" replaced with your own identifying
177aec1d6eScindi  * information: Portions Copyright [yyyy] [name of copyright owner]
187aec1d6eScindi  *
197aec1d6eScindi  * CDDL HEADER END
207aec1d6eScindi  *
217aec1d6eScindi  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
227aec1d6eScindi  * Use is subject to license terms.
237aec1d6eScindi  */
247aec1d6eScindi 
257aec1d6eScindi #ifndef _MCAMD_ROWCOL_IMPL_H
267aec1d6eScindi #define	_MCAMD_ROWCOL_IMPL_H
277aec1d6eScindi 
287aec1d6eScindi #pragma ident	"%Z%%M%	%I%	%E% SMI"
297aec1d6eScindi 
307aec1d6eScindi #include <mcamd_api.h>
317aec1d6eScindi #include <sys/mc_amd.h>
327aec1d6eScindi 
337aec1d6eScindi #ifdef __cplusplus
347aec1d6eScindi extern "C" {
357aec1d6eScindi #endif
367aec1d6eScindi 
377aec1d6eScindi #define	MC_PC_COLADDRBIT	10	/* col address bit used for precharge */
387aec1d6eScindi #define	MC_PC_ALL		-1	/* marker used in tables */
397aec1d6eScindi 
407aec1d6eScindi #define	MC_CS_SCALE		(1024 * 1024)
417aec1d6eScindi #define	MC_CS_SIZE(bam, width) \
427aec1d6eScindi 	((size_t)bam->bam_sizemb * MC_CS_SCALE * ((width) == 128 ? 2 : 1))
437aec1d6eScindi 
447aec1d6eScindi #define	MC_CS_MODE(csbmap, csnum) \
457aec1d6eScindi 	(csbmap >> MC_CHIP_DIMMPAIR(csnum) * MC_DC_BAM_CSBANK_SHIFT & \
467aec1d6eScindi 	MC_DC_BAM_CSBANK_MASK)
477aec1d6eScindi 
487aec1d6eScindi #define	BIT(val, num) ((val) & 1ULL << num)
497aec1d6eScindi 
507aec1d6eScindi #define	BITS(val, high, low) \
517aec1d6eScindi 	((val) & (((2ULL << (high)) - 1) & ~((1ULL << (low)) - 1)))
527aec1d6eScindi 
537aec1d6eScindi #define	SETBIT(var, num) (var |= (1ULL << (num)))
547aec1d6eScindi 
557aec1d6eScindi #define	BITVAL(var, num) ((BIT(var, num) >> (num)) & 1ULL)
567aec1d6eScindi 
57*8a40a695Sgavinm #define	MC_RC_ROW_MAX		16	/* maximum number of row address bits */
587aec1d6eScindi #define	MC_RC_COL_MAX		12	/* maximum number of col address bits */
59*8a40a695Sgavinm #define	MC_RC_BANKBITS_MAX	3	/* number of internal banksel bits */
607aec1d6eScindi #define	MC_RC_CSMODES		16	/* max number of cs bankaddr modes */
61*8a40a695Sgavinm #define	MC_RC_SWZLBITS		2	/* number of row bits in swizzle */
627aec1d6eScindi 
63*8a40a695Sgavinm struct rct_bnkaddrmode {
647aec1d6eScindi 	int bam_sizemb;			/* DIMM size in MB */
657aec1d6eScindi 	int bam_nrows;			/* number of row address bits */
667aec1d6eScindi 	int bam_ncols;			/* number of column address bits */
677aec1d6eScindi 	int bam_ambig;			/* numbers are maximums; keep last */
687aec1d6eScindi };
697aec1d6eScindi 
70*8a40a695Sgavinm struct rct_rcbmap {
71*8a40a695Sgavinm 	int rcb_nbankbits;			/* # of bank address bits */
72*8a40a695Sgavinm 	int rcb_bankbit[MC_RC_BANKBITS_MAX];	/* bank address bits */
73*8a40a695Sgavinm 	int rcb_rowbit[MC_RC_ROW_MAX];
74*8a40a695Sgavinm 	int rcb_colbit[MC_RC_COL_MAX + 1];	/* one for MC_PC_ALL */
757aec1d6eScindi };
767aec1d6eScindi 
77*8a40a695Sgavinm struct rct_bnkswzlinfo {
78*8a40a695Sgavinm 	int bswz_rowbits[MC_RC_BANKBITS_MAX][MC_RC_SWZLBITS];
797aec1d6eScindi };
807aec1d6eScindi 
81*8a40a695Sgavinm struct rct_csintlv {
827aec1d6eScindi 	int csi_factor;			/* cs interleave factor */
837aec1d6eScindi 	int csi_hibit;			/* first non-offset bit in addr */
847aec1d6eScindi 	int csi_lobit;			/* first row bit in addr */
857aec1d6eScindi 	int csi_nbits;			/* number of bits to swap in mask */
867aec1d6eScindi };
877aec1d6eScindi 
887aec1d6eScindi #define	MC_RC_CSI_SWAPPED_BIT(csidp, n)				\
897aec1d6eScindi 	(csidp->csi_factor && n >= csidp->csi_lobit &&		\
907aec1d6eScindi 	n <= csidp->csi_lobit + csidp->csi_nbits - 1)
917aec1d6eScindi 
927aec1d6eScindi #define	MC_RC_CSI_BITSWAP(csidp, n)				\
937aec1d6eScindi 	(csidp->csi_hibit + n - csidp->csi_lobit)
947aec1d6eScindi 
95*8a40a695Sgavinm extern const struct rct_bnkaddrmode *rct_bnkaddrmode(uint_t, uint_t);
96*8a40a695Sgavinm extern const struct rct_rcbmap *rct_rcbmap(uint_t, int, uint_t);
97*8a40a695Sgavinm extern const struct rct_bnkswzlinfo *rct_bnkswzlinfo(uint_t, int);
98*8a40a695Sgavinm extern void rct_csintlv_bits(uint_t, int, uint_t, int, struct rct_csintlv *);
997aec1d6eScindi 
1007aec1d6eScindi #ifdef __cplusplus
1017aec1d6eScindi }
1027aec1d6eScindi #endif
1037aec1d6eScindi 
1047aec1d6eScindi #endif /* _MCAMD_ROWCOL_IMPL_H */
105