xref: /titanic_52/usr/src/common/mc/mc-amd/mcamd_rowcol_impl.h (revision b6c3f7863936abeae522e48a13887dddeb691a45)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  *
21  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
22  * Use is subject to license terms.
23  */
24 
25 #ifndef _MCAMD_ROWCOL_IMPL_H
26 #define	_MCAMD_ROWCOL_IMPL_H
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #include <mcamd_api.h>
31 #include <sys/mc_amd.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #define	MC_PC_COLADDRBIT	10	/* col address bit used for precharge */
38 #define	MC_PC_ALL		-1	/* marker used in tables */
39 
40 #define	MC_CS_SCALE		(1024 * 1024)
41 #define	MC_CS_SIZE(bam, width) \
42 	((size_t)bam->bam_sizemb * MC_CS_SCALE * ((width) == 128 ? 2 : 1))
43 
44 #define	MC_CS_MODE(csbmap, csnum) \
45 	(csbmap >> MC_CHIP_DIMMPAIR(csnum) * MC_DC_BAM_CSBANK_SHIFT & \
46 	MC_DC_BAM_CSBANK_MASK)
47 
48 #define	BIT(val, num) ((val) & 1ULL << num)
49 
50 #define	BITS(val, high, low) \
51 	((val) & (((2ULL << (high)) - 1) & ~((1ULL << (low)) - 1)))
52 
53 #define	SETBIT(var, num) (var |= (1ULL << (num)))
54 
55 #define	BITVAL(var, num) ((BIT(var, num) >> (num)) & 1ULL)
56 
57 #define	MC_RC_ROW_MAX		16	/* maximum number of row address bits */
58 #define	MC_RC_COL_MAX		12	/* maximum number of col address bits */
59 #define	MC_RC_BANKBITS_MAX	3	/* number of internal banksel bits */
60 #define	MC_RC_CSMODES		16	/* max number of cs bankaddr modes */
61 #define	MC_RC_SWZLBITS		2	/* number of row bits in swizzle */
62 
63 struct rct_bnkaddrmode {
64 	int bam_sizemb;			/* DIMM size in MB */
65 	int bam_nrows;			/* number of row address bits */
66 	int bam_ncols;			/* number of column address bits */
67 	int bam_ambig;			/* numbers are maximums; keep last */
68 };
69 
70 struct rct_rcbmap {
71 	int rcb_nbankbits;			/* # of bank address bits */
72 	int rcb_bankbit[MC_RC_BANKBITS_MAX];	/* bank address bits */
73 	int rcb_rowbit[MC_RC_ROW_MAX];
74 	int rcb_colbit[MC_RC_COL_MAX + 1];	/* one for MC_PC_ALL */
75 };
76 
77 struct rct_bnkswzlinfo {
78 	int bswz_rowbits[MC_RC_BANKBITS_MAX][MC_RC_SWZLBITS];
79 };
80 
81 struct rct_csintlv {
82 	int csi_factor;			/* cs interleave factor */
83 	int csi_hibit;			/* first non-offset bit in addr */
84 	int csi_lobit;			/* first row bit in addr */
85 	int csi_nbits;			/* number of bits to swap in mask */
86 };
87 
88 #define	MC_RC_CSI_SWAPPED_BIT(csidp, n)				\
89 	(csidp->csi_factor && n >= csidp->csi_lobit &&		\
90 	n <= csidp->csi_lobit + csidp->csi_nbits - 1)
91 
92 #define	MC_RC_CSI_BITSWAP(csidp, n)				\
93 	(csidp->csi_hibit + n - csidp->csi_lobit)
94 
95 extern const struct rct_bnkaddrmode *rct_bnkaddrmode(uint_t, uint_t);
96 extern const struct rct_rcbmap *rct_rcbmap(uint_t, int, uint_t);
97 extern const struct rct_bnkswzlinfo *rct_bnkswzlinfo(uint_t, int);
98 extern void rct_csintlv_bits(uint_t, int, uint_t, int, struct rct_csintlv *);
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif /* _MCAMD_ROWCOL_IMPL_H */
105