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 #include <mcamd_api.h>
29 #include <sys/mc_amd.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #define	MC_PC_COLADDRBIT	10	/* col address bit used for precharge */
36 #define	MC_PC_ALL		-1	/* marker used in tables */
37 
38 #define	MC_CS_SCALE		(1024 * 1024)
39 #define	MC_CS_SIZE(bam, width) \
40 	((size_t)bam->bam_sizemb * MC_CS_SCALE * ((width) == 128 ? 2 : 1))
41 
42 #define	MC_CS_MODE(csbmap, csnum) \
43 	(csbmap >> MC_CHIP_DIMMPAIR(csnum) * MC_DC_BAM_CSBANK_SHIFT & \
44 	MC_DC_BAM_CSBANK_MASK)
45 
46 #define	BIT(val, num) ((val) & 1ULL << num)
47 
48 #define	BITS(val, high, low) \
49 	((val) & (((2ULL << (high)) - 1) & ~((1ULL << (low)) - 1)))
50 
51 #define	SETBIT(var, num) (var |= (1ULL << (num)))
52 
53 #define	BITVAL(var, num) ((BIT(var, num) >> (num)) & 1ULL)
54 
55 #define	MC_RC_ROW_MAX		16	/* maximum number of row address bits */
56 #define	MC_RC_COL_MAX		12	/* maximum number of col address bits */
57 #define	MC_RC_BANKBITS_MAX	3	/* number of internal banksel bits */
58 #define	MC_RC_CSMODES		16	/* max number of cs bankaddr modes */
59 #define	MC_RC_SWZLBITS		2	/* number of row bits in swizzle */
60 
61 struct rct_bnkaddrmode {
62 	int bam_sizemb;			/* DIMM size in MB */
63 	int bam_nrows;			/* number of row address bits */
64 	int bam_ncols;			/* number of column address bits */
65 	int bam_ambig;			/* numbers are maximums; keep last */
66 };
67 
68 struct rct_rcbmap {
69 	int rcb_nbankbits;			/* # of bank address bits */
70 	int rcb_bankbit[MC_RC_BANKBITS_MAX];	/* bank address bits */
71 	int rcb_rowbit[MC_RC_ROW_MAX];
72 	int rcb_colbit[MC_RC_COL_MAX + 1];	/* one for MC_PC_ALL */
73 };
74 
75 struct rct_bnkswzlinfo {
76 	int bswz_rowbits[MC_RC_BANKBITS_MAX][MC_RC_SWZLBITS];
77 };
78 
79 struct rct_csintlv {
80 	int csi_factor;			/* cs interleave factor */
81 	int csi_hibit;			/* first non-offset bit in addr */
82 	int csi_lobit;			/* first row bit in addr */
83 	int csi_nbits;			/* number of bits to swap in mask */
84 };
85 
86 #define	MC_RC_CSI_SWAPPED_BIT(csidp, n)				\
87 	(csidp->csi_factor && n >= csidp->csi_lobit &&		\
88 	n <= csidp->csi_lobit + csidp->csi_nbits - 1)
89 
90 #define	MC_RC_CSI_BITSWAP(csidp, n)				\
91 	(csidp->csi_hibit + n - csidp->csi_lobit)
92 
93 extern const struct rct_bnkaddrmode *rct_bnkaddrmode(uint_t, uint_t);
94 extern const struct rct_rcbmap *rct_rcbmap(uint_t, int, uint_t);
95 extern const struct rct_bnkswzlinfo *rct_bnkswzlinfo(uint_t, int);
96 extern void rct_csintlv_bits(uint_t, int, uint_t, int, struct rct_csintlv *);
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 
102 #endif /* _MCAMD_ROWCOL_IMPL_H */
103