dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / common / mc / mc-amd / mcamd_rowcol_tbl.c
blobf12c59b7468f15000020d6c8a23b0bc0fcfa889b
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
24 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include <mcamd_api.h>
31 #include <mcamd_err.h>
32 #include <mcamd_rowcol_impl.h>
35 * =========== Chip-Select Bank Address Mode Encodings =======================
38 /* Individual table declarations */
39 static const struct rct_bnkaddrmode bnkaddr_tbls_pre_d[];
40 static const struct rct_bnkaddrmode bnkaddr_tbls_d_e[];
41 static const struct rct_bnkaddrmode bnkaddr_tbls_f[];
43 /* Managing bank address mode tables */
44 static const struct _bnkaddrmode_tbldesc {
45 uint_t revmask;
46 int nmodes;
47 const struct rct_bnkaddrmode *modetbl;
48 } bnkaddr_tbls[] = {
49 { MC_F_REVS_BC, 7, bnkaddr_tbls_pre_d },
50 { MC_F_REVS_DE, 11, bnkaddr_tbls_d_e },
51 { MC_F_REVS_FG, 12, bnkaddr_tbls_f },
55 * =========== DRAM Address Mappings for bank/row/column =====================
59 /* Individual table declarations */
60 struct _rcbmap_tbl {
61 uint_t mt_revmask; /* revision to which this applies */
62 int mt_width; /* MC mode (64 or 128) */
63 const struct rct_rcbmap mt_csmap[MC_RC_CSMODES];
66 static const struct _rcbmap_tbl dram_addrmap_pre_d_64;
67 static const struct _rcbmap_tbl dram_addrmap_pre_d_128;
68 static const struct _rcbmap_tbl dram_addrmap_d_e_64;
69 static const struct _rcbmap_tbl dram_addrmap_d_e_128;
70 static const struct _rcbmap_tbl dram_addrmap_f_64;
71 static const struct _rcbmap_tbl dram_addrmap_f_128;
73 /* Managing row/column/bank tables */
74 static const struct _rcbmap_tbldesc {
75 int nmodes;
76 const struct _rcbmap_tbl *rcbmap;
77 } rcbmap_tbls[] = {
78 { 7, &dram_addrmap_pre_d_64 },
79 { 7, &dram_addrmap_pre_d_128 },
80 { 11, &dram_addrmap_d_e_64 },
81 { 11, &dram_addrmap_d_e_128 },
82 { 12, &dram_addrmap_f_64 },
83 { 12, &dram_addrmap_f_128 },
87 * =========== Bank swizzling information ====================================
90 /* Individual table declarations */
91 struct _bnkswzl_tbl {
92 uint_t swzt_revmask; /* revision to which this applies */
93 int swzt_width; /* MC mode (64 or 128) */
94 const struct rct_bnkswzlinfo swzt_bits;
97 static const struct _bnkswzl_tbl bnswzl_info_e_64;
98 static const struct _bnkswzl_tbl bnswzl_info_e_128;
99 static const struct _bnkswzl_tbl bnswzl_info_f_64;
100 static const struct _bnkswzl_tbl bnswzl_info_f_128;
102 /* Managing bank swizzle tables */
103 static const struct _bnkswzl_tbl *bnkswzl_tbls[] = {
104 &bnswzl_info_e_64,
105 &bnswzl_info_e_128,
106 &bnswzl_info_f_64,
107 &bnswzl_info_f_128,
111 * ======================================================================
112 * | Tables reflecting those in the BKDG |
113 * ======================================================================
117 * DRAM Address Mapping in Interleaving Mode
119 * Chip-select interleave is performed by addressing across the columns
120 * of the first row of internal bank-select 0 on a chip-select, then the
121 * next row on internal bank-select 1, then 2 then 3; instead of then
122 * moving on to the next row of this chip-select we then rotate across
123 * other chip-selects in the interleave. The row/column/bank mappings
124 * described elsewhere in this file show that a DRAM InputAddr breaks down
125 * as follows, using an example for CS Mode 0000 revision CG and earlier 64-bit
126 * mode; the cs size is 32MB, requiring 25 bits to address all of it.
128 * chip-selection bits | offset within chip-select bits |
129 * | row bits | bank bits | column bits | - |
130 * 24 13 12 11 10 3 2 0
132 * The high-order chip-selection bits select the chip-select and the
133 * offset bits offset within the chosen chip-select.
135 * To establish say a 2-way interleave in which we consume all of one
136 * row number and all internal bank numbers on one cs before moving on
137 * to the next to do the same we will target the first row bit - bit 13;
138 * a 4-way interleave would use bits 14 and 13, and an 8-way interleave
139 * bits 15, 14 and 13. We swap the chosen bits with the least significant
140 * high order chip-selection bits.
142 * The BKDG interleave tables really just describe the above. Working
143 * out the high-order bits to swap is easy since that is derived directly
144 * from the chip-select size. The low-order bits depend on the device
145 * parameters since we need to target the least significant row address bits -
146 * but we have that information from the rcbmap_tbls since the first row bit
147 * simply follows the last bank address bit.
151 * General notes for CS Bank Address Mode Encoding tables.
153 * These are indexed by chip-select mode. Where the numbers of rows and
154 * columns is ambiguous (as it is for a number of rev CG and earlier cases)
155 * the bam_config should be initialized to 1 and the numbers of rows
156 * and columns should be the maximums.
160 * Chip Select Bank Address Mode Encoding for rev CG and earlier.
162 static const struct rct_bnkaddrmode bnkaddr_tbls_pre_d[] = {
163 { /* 000 */
164 32, 12, 8
166 { /* 001 */
167 64, 12, 9
169 { /* 010 */
170 128, 13, 10, 1 /* AMBIG */
172 { /* 011 */
173 256, 13, 11, 1 /* AMBIG */
175 { /* 100 */
176 512, 14, 11, 1 /* AMBIG */
178 { /* 101 */
179 1024, 14, 12, 1 /* AMBIG */
181 { /* 110 */
182 2048, 14, 12
187 * Chip Select Bank Address Mode Encoding for revs D and E.
189 static const struct rct_bnkaddrmode bnkaddr_tbls_d_e[] = {
190 { /* 0000 */
191 32, 12, 8
193 { /* 0001 */
194 64, 12, 9
196 { /* 0010 */
197 128, 13, 9
199 { /* 0011 */
200 128, 12, 10
202 { /* 0100 */
203 256, 13, 10
205 { /* 0101 */
206 512, 14, 10
208 { /* 0110 */
209 256, 12, 11
211 { /* 0111 */
212 512, 13, 11
214 { /* 1000 */
215 1024, 14, 11
217 { /* 1001 */
218 1024, 13, 12
220 { /* 1010 */
221 2048, 14, 12
226 * Chip Select Bank Address Mode Encoding for rev F
228 static const struct rct_bnkaddrmode bnkaddr_tbls_f[] = {
229 { /* 0000 */
230 128, 13, 9
232 { /* 0001 */
233 256, 13, 10
235 { /* 0010 */
236 512, 14, 10
238 { /* 0011 */
239 512, 13, 11
241 { /* 0100 */
242 512, 13, 10
244 { /* 0101 */
245 1024, 14, 10
247 { /* 0110 */
248 1024, 14, 11
250 { /* 0111 */
251 2048, 15, 10
253 { /* 1000 */
254 2048, 14, 11
256 { /* 1001 */
257 4096, 15, 11
259 { /* 1010 */
260 4096, 16, 10
262 { /* 1011 */
263 8192, 16, 11
269 * General notes on Row/Column/Bank table initialisation.
271 * These are the tables 7, 8, 9, 10, 11 and 12 of BKDG 3.29 section 3.5.6.1.
272 * They apply in non-interleave (node or cs) mode and describe how for
273 * a given revision, access width, bank-swizzle mode, and current chip-select
274 * mode the row, column and internal sdram bank are derived from the
275 * normalizied InputAddr presented to the DRAM controller.
277 * The mt_csmap array is indexed by chip-select mode. Within it the
278 * bankargs, rowbits and colbits arrays are indexed by bit number, so
279 * match the BKDG tables if the latter are read right-to-left.
281 * The bankargs list up to three bit numbers per bank bit. For revisions
282 * CG and earlier there is no bank swizzling, so just a single number
283 * should be listed. Revisions D and E have the same row/column/bank mapping,
284 * but rev E has the additional feature of being able to xor two row bits
285 * into each bank bit. The consumer will know whether they are using bank
286 * swizzling - if so then they should xor the bankargs bits together.
287 * The first argument must be the bit number not already used in forming
288 * part of the row address - eg in table 12 for csmode 0000b bank address
289 * bit 0 is bit 12 xor bit 18 xor bit 21, and 18 and 21 are also mentioned in
290 * the row address (bits 10 and 1) so we must list bit 12 first. We will
291 * use this information in chip-select interleave decoding in which we need
292 * to know which is the first bit after column and bank address bits.
294 * Column address A10 is always used for the Precharge All signal. Where
295 * "PC" appears in the BKDG tables we will include MC_PC_ALL in the
296 * corresponding bit position.
298 * For some rev CG and earlier chipselect modes the number of rows and columns
299 * is ambiguous. This is reflected in these tables by some bit being
300 * duplicated between row and column address. In practice we will follow
301 * the convention of always assigning the floating bit to the row address.
305 * Row/Column/Bank address mappings for rev CG in 64-bit mode, no interleave.
306 * See BKDG 3.29 3.5.6 Table 7.
308 static const struct _rcbmap_tbl dram_addrmap_pre_d_64 = {
309 MC_F_REVS_BC,
312 { /* 000 */
313 2, { 11, 12 },
314 { 19, 20, 21, 22, 23, 24, 13, 14, 15, 16, 17, 18 },
315 { 3, 4, 5, 6, 7, 8, 9, 10 }
317 { /* 001 */
318 2, { 13, 12 },
319 { 19, 20, 21, 22, 23, 24, 25, 14, 15, 16, 17, 18 },
320 { 3, 4, 5, 6, 7, 8, 9, 10, 11 }
322 { /* 010 */
323 2, { 13, 12 },
324 { 19, 20, 21, 22, 23, 24, 25, 14, 15, 16, 17, 18, 26 },
325 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 26 }
327 { /* 011 */
328 2, { 13, 14 },
329 { 19, 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 27 },
330 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 27 }
332 { /* 100 */
333 2, { 13, 14 },
334 { 19, 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 27, 28 },
335 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 28 }
337 { /* 101 */
338 2, { 15, 14 },
339 { 19, 20, 21, 22, 23, 24, 25, 26, 29, 16, 17, 18, 27, 28 },
340 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 13, 28 }
342 { /* 110 */
343 2, { 15, 14 },
344 { 19, 20, 21, 22, 23, 24, 25, 26, 29, 16, 17, 18, 27, 28 },
345 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 13, 30 }
348 * remainder unused
355 * Row/Column/Bank address mappings for rev CG in 128-bit mode, no interleave.
356 * See BKDG 3.29 3.5.6 Table 8.
358 static const struct _rcbmap_tbl dram_addrmap_pre_d_128 = {
359 MC_F_REVS_BC,
360 128,
362 { /* 000 */
363 2, { 12, 13 },
364 { 20, 21, 22, 23, 24, 25, 14, 15, 16, 17, 18, 19 },
365 { 4, 5, 6, 7, 8, 9, 10, 11 }
367 { /* 001 */
368 2, { 14, 13 },
369 { 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19 },
370 { 4, 5, 6, 7, 8, 9, 10, 11, 12 }
372 { /* 010 */
373 2, { 14, 13 },
374 { 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 27 },
375 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 27 }
377 { /* 011 */
378 2, { 14, 15 },
379 { 20, 21, 22, 23, 24, 25, 26, 27, 16, 17, 18, 19, 28 },
380 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 28 }
382 { /* 100 */
383 2, { 14, 15 },
384 { 20, 21, 22, 23, 24, 25, 26, 27, 16, 17, 18, 19, 28, 29 },
385 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 29 }
387 { /* 101 */
388 2, { 16, 15 },
389 { 20, 21, 22, 23, 24, 25, 26, 27, 30, 17, 18, 19, 28, 29 },
390 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 14, 29 }
392 { /* 110 */
393 2, { 16, 15 },
394 { 20, 21, 22, 23, 24, 25, 26, 27, 30, 17, 18, 19, 28, 29 },
395 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 14, 31 }
398 * remainder unused
404 * Row/Column/Bank address mappings for rev D/E in 64-bit mode, no interleave.
405 * See BKDG 3.29 3.5.6 Table 9.
407 static const struct _rcbmap_tbl dram_addrmap_d_e_64 = {
408 MC_F_REVS_DE,
411 { /* 0000 */
412 2, { 11, 12 },
413 { 19, 20, 21, 22, 23, 24, 13, 14, 15, 16, 17, 18 },
414 { 3, 4, 5, 6, 7, 8, 9, 10 }
416 { /* 0001 */
417 2, { 12, 13 },
418 { 19, 20, 21, 22, 23, 24, 25, 14, 15, 16, 17, 18, 26 },
419 { 3, 4, 5, 6, 7, 8, 9, 10, 11 }
421 { /* 0010 */
422 2, { 12, 13 },
423 { 19, 20, 21, 22, 23, 24, 25, 14, 15, 16, 17, 18, 26 },
424 { 3, 4, 5, 6, 7, 8, 9, 10, 11 }
426 { /* 0011 */
427 2, { 13, 14 },
428 { 19, 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 27, 28 },
429 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
431 { /* 0100 */
432 2, { 13, 14 },
433 { 19, 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 27, 28 },
434 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
436 { /* 0101 */
437 2, { 13, 14 },
438 { 19, 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 27, 28 },
439 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
441 { /* 0110 */
442 2, { 14, 15 },
443 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 16, 17, 18, 28, 29 },
444 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 13 }
446 { /* 0111 */
447 2, { 14, 15 },
448 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 16, 17, 18, 28, 29 },
449 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 13 }
451 { /* 1000 */
452 2, { 14, 15 },
453 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 16, 17, 18, 28, 29 },
454 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 13 }
456 { /* 1001 */
457 2, { 15, 16 },
458 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 17, 18, 29, 30 },
459 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 13, 14 }
461 { /* 1010 */
462 2, { 15, 16 },
463 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 17, 18, 29, 30 },
464 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 13, 14 }
467 * remainder unused
473 * Row/Column/Bank address mappings for rev D/E in 128-bit mode, no interleave.
474 * See BKDG 3.29 3.5.6 Table 9.
476 static const struct _rcbmap_tbl dram_addrmap_d_e_128 = {
477 MC_F_REVS_DE,
478 128,
480 { /* 0000 */
481 2, { 12, 13 },
482 { 20, 21, 22, 23, 24, 25, 14, 15, 16, 17, 18, 19 },
483 { 4, 5, 6, 7, 8, 9, 10, 11 }
485 { /* 0001 */
486 2, { 13, 14 },
487 { 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 27 },
488 { 4, 5, 6, 7, 8, 9, 10, 11, 12 }
490 { /* 0010 */
491 2, { 13, 14 },
492 { 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 27 },
493 { 4, 5, 6, 7, 8, 9, 10, 11, 12 }
495 { /* 0011 */
496 2, { 14, 15 },
497 { 20, 21, 22, 23, 24, 25, 26, 27, 16, 17, 18, 19, 28, 29 },
498 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }
500 { /* 0100 */
501 2, { 14, 15 },
502 { 20, 21, 22, 23, 24, 25, 26, 27, 16, 17, 18, 19, 28, 29 },
503 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }
505 { /* 0101 */
506 2, { 14, 15 },
507 { 20, 21, 22, 23, 24, 25, 26, 27, 16, 17, 18, 19, 28, 29 },
508 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }
510 { /* 0110 */
511 2, { 15, 16 },
512 { 20, 21, 22, 23, 24, 25, 26, 27, 28, 17, 18, 19, 29, 30 },
513 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 14 }
515 { /* 0111 */
516 2, { 15, 16 },
517 { 20, 21, 22, 23, 24, 25, 26, 27, 28, 17, 18, 19, 29, 30 },
518 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 14 }
520 { /* 1000 */
521 2, { 15, 16 },
522 { 20, 21, 22, 23, 24, 25, 26, 27, 28, 17, 18, 19, 29, 30 },
523 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 14 }
525 { /* 1001 */
526 2, { 16, 17 },
527 { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 18, 19, 30, 31 },
528 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 14, 15 }
530 { /* 1010 */
531 2, { 16, 17 },
532 { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 18, 19, 30, 31 },
533 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 14, 15 }
536 * remainder unused
542 * Row/Column/Bank address mappings for revs F/G in 64-bit mode, no interleave.
544 static const struct _rcbmap_tbl dram_addrmap_f_64 = {
545 MC_F_REVS_FG,
548 { /* 0000 */
549 2, { 12, 13 },
550 { 18, 19, 20, 21, 22, 23, 24, 25, 26, 14, 15, 16, 17 },
551 { 3, 4, 5, 6, 7, 8, 9, 10, 11 },
553 { /* 0001 */
554 2, { 13, 14 },
555 { 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 15, 16, 17 },
556 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 },
558 { /* 0010 */
559 2, { 13, 14 },
560 { 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 15, 16, 17 },
561 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 },
563 { /* 0011 */
564 2, { 14, 15 },
565 { 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 16, 17 },
566 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 13 },
568 { /* 0100 */
569 3, { 13, 14, 15 },
570 { 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 16, 17 },
571 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 13 },
573 { /* 0101 */
574 3, { 13, 14, 15 },
575 { 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 16, 17 },
576 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
578 { /* 0110 */
579 2, { 14, 15 },
580 { 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 16, 17 },
581 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 13 },
583 { /* 0111 */
584 3, { 13, 14, 15 },
585 { 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 16, 17 },
586 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
588 { /* 1000 */
589 3, { 14, 15, 16 },
590 { 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 17 },
591 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 13 },
593 { /* 1001 */
594 3, { 14, 15, 16 },
595 { 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 17 },
596 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 13 },
598 { /* 1010 */
599 3, { 13, 14, 15 },
600 { 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
601 16, 17 },
602 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
604 { /* 1011 */
605 3, { 14, 15, 16 },
606 { 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
607 17 },
608 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, MC_PC_ALL, 13 },
611 * remainder unused
617 * Row/Column/Bank address mappings for revs F/G in 128-bit mode, no interleave.
619 static const struct _rcbmap_tbl dram_addrmap_f_128 = {
620 MC_F_REVS_FG,
621 128,
623 { /* 0000 */
624 2, { 13, 14 },
625 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 15, 16, 17, 18 },
626 { 4, 5, 6, 7, 8, 9, 10, 11, 12 },
628 { /* 0001 */
629 2, { 14, 15 },
630 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 16, 17, 18 },
631 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 },
633 { /* 0010 */
634 2, { 14, 15 },
635 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 16, 17, 18 },
636 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 },
638 { /* 0011 */
639 2, { 15, 16 },
640 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 17, 18 },
641 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 14 },
643 { /* 0100 */
644 3, { 14, 15, 16 },
645 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 17, 18 },
646 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 },
648 { /* 0101 */
649 3, { 14, 15, 16 },
650 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 17, 18 },
651 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 },
653 { /* 0110 */
654 2, { 15, 16 },
655 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 17, 18 },
656 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 14 },
658 { /* 0111 */
659 3, { 14, 15, 16 },
660 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
661 17, 18 },
662 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 },
664 { /* 1000 */
665 3, { 15, 16, 17 },
666 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
667 18 },
668 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 14 },
670 { /* 1001 */
671 3, { 15, 16, 17 },
672 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
673 18 },
674 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 14 },
676 { /* 1010 */
677 3, { 14, 15, 16 },
678 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
679 17, 18 },
680 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 },
682 { /* 1011 */
683 3, { 15, 16, 17 },
684 { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
685 18 },
686 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, MC_PC_ALL, 14 },
689 * remainder unused
695 * Bank swizzling is an option in revisions E and later. Each internal-bank-
696 * select address bit is xor'd with two row address bits. Which row
697 * address bits to use is not dependent on bank address mode but on
698 * revision and dram controller width alone.
700 * While rev E only supports 2 bank address bits, rev F supports 3 but not
701 * all chip-select bank address modes use all 3. These tables will list
702 * the row bits to use in swizzling for the maximum number of supported
703 * bank address bits - the consumer musr determine how many should be
704 * applied (listed in the above row/col/bank tables).
707 static const struct _bnkswzl_tbl bnswzl_info_e_64 = {
708 MC_F_REV_E,
712 { 17, 20 }, /* rows bits to swizzle with BA0 */
713 { 18, 21 }, /* rows bits to swizzle with BA1 */
714 /* only 2 bankaddr bits on rev E */
719 static const struct _bnkswzl_tbl bnswzl_info_e_128 = {
720 MC_F_REV_E,
721 128,
724 { 18, 21 }, /* rows bits to swizzle with BA0 */
725 { 19, 22 }, /* rows bits to swizzle with BA1 */
726 /* only 2 bankaddr bits on rev E */
731 static const struct _bnkswzl_tbl bnswzl_info_f_64 = {
732 MC_F_REVS_FG,
736 { 17, 22 }, /* rows bits to swizzle with BA0 */
737 { 18, 23 }, /* rows bits to swizzle with BA1 */
738 { 19, 24 }, /* rows bits to swizzle with BA2 */
743 static const struct _bnkswzl_tbl bnswzl_info_f_128 = {
744 MC_F_REVS_FG,
745 128,
748 { 18, 23 }, /* rows bits to swizzle with BA0 */
749 { 19, 24 }, /* rows bits to swizzle with BA1 */
750 { 20, 25 }, /* rows bits to swizzle with BA2 */
756 * Yet another highbit function. This really needs to go to common source.
757 * Returns range 0 to 64 inclusive;
759 static int
760 topbit(uint64_t i)
762 int h = 1;
764 if (i == 0)
765 return (0);
767 if (i & 0xffffffff00000000ULL) {
768 h += 32;
769 i >>= 32;
772 if (i & 0xffff0000) {
773 h += 16;
774 i >>= 16;
777 if (i & 0xff00) {
778 h += 8;
779 i >>= 8;
782 if (i & 0xf0) {
783 h += 4;
784 i >>= 4;
787 if (i & 0xc) {
788 h += 2;
789 i >>= 2;
792 if (i & 0x2)
793 h += 1;
795 return (h);
799 * Lookup the Chip-Select Bank Address Mode Encoding table for a given
800 * chip revision and chip-select mode.
802 const struct rct_bnkaddrmode *
803 rct_bnkaddrmode(uint_t mcrev, uint_t csmode)
805 int i;
806 const struct _bnkaddrmode_tbldesc *bdp = bnkaddr_tbls;
808 for (i = 0; i < sizeof (bnkaddr_tbls) /
809 sizeof (struct _bnkaddrmode_tbldesc);
810 i++, bdp++) {
811 if (MC_REV_MATCH(mcrev, bdp->revmask) && csmode < bdp->nmodes)
812 return (&bdp->modetbl[csmode]);
816 return (NULL);
820 * Lookup the DRAM Address Mapping table for a given chip revision, access
821 * width, bank-swizzle and chip-select mode.
823 const struct rct_rcbmap *
824 rct_rcbmap(uint_t mcrev, int width, uint_t csmode)
826 const struct _rcbmap_tbl *rcbm;
827 int i;
829 for (i = 0; i < sizeof (rcbmap_tbls) /
830 sizeof (struct _rcbmap_tbldesc); i++) {
831 rcbm = rcbmap_tbls[i].rcbmap;
832 if (MC_REV_MATCH(mcrev, rcbm->mt_revmask) &&
833 rcbm->mt_width == width && csmode < rcbmap_tbls[i].nmodes)
834 return (&rcbm->mt_csmap[csmode]);
837 return (NULL);
841 * Lookup the bank swizzling information for a given chip revision and
842 * access width.
844 const struct rct_bnkswzlinfo *
845 rct_bnkswzlinfo(uint_t mcrev, int width)
847 int i;
848 const struct _bnkswzl_tbl *swztp;
850 for (i = 0; i < sizeof (bnkswzl_tbls) /
851 sizeof (struct rcb_bnkswzl_tbl *); i++) {
852 swztp = bnkswzl_tbls[i];
853 if (MC_REV_MATCH(mcrev, swztp->swzt_revmask) &&
854 swztp->swzt_width == width)
855 return (&swztp->swzt_bits);
858 return (NULL);
861 void
862 rct_csintlv_bits(uint_t mcrev, int width, uint_t csmode, int factor,
863 struct rct_csintlv *csid)
865 int i, lstbnkbit;
866 size_t csz;
867 const struct rct_bnkaddrmode *bam;
868 const struct rct_rcbmap *rcm;
871 * 8-way cs interleave for some large cs sizes in 128-bit mode is
872 * not implemented prior to rev F.
874 if (factor == 8 && width == 128 &&
875 ((MC_REV_MATCH(mcrev, MC_F_REVS_BC) && csmode == 0x6) ||
876 (MC_REV_MATCH(mcrev, MC_F_REVS_DE) &&
877 (csmode == 0x9 || csmode == 0xa)))) {
878 csid->csi_factor = 0;
879 return;
882 if ((bam = rct_bnkaddrmode(mcrev, csmode)) == NULL ||
883 (rcm = rct_rcbmap(mcrev, width, csmode)) == NULL) {
884 csid->csi_factor = 0;
885 return;
888 csz = MC_CS_SIZE(bam, width);
890 switch (factor) {
891 case 2:
892 csid->csi_nbits = 1;
893 break;
894 case 4:
895 csid->csi_nbits = 2;
896 break;
897 case 8:
898 csid->csi_nbits = 3;
899 break;
900 default:
901 csid->csi_factor = 0;
902 return;
905 csid->csi_hibit = topbit(csz) - 1;
908 * The first row bit is immediately after the last bank bit.
910 lstbnkbit = 0;
911 for (i = 0; i < rcm->rcb_nbankbits; i++)
912 if (rcm->rcb_bankbit[i] > lstbnkbit)
913 lstbnkbit = rcm->rcb_bankbit[i];
915 csid->csi_lobit = lstbnkbit + 1;
917 csid->csi_factor = factor;