8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / uts / intel / io / mc-amd / mcamd_dimmcfg.c
blobd64fb793958426f0718024784e5c782a8fc7cb6c
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
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include <sys/types.h>
28 #include <sys/cmn_err.h>
29 #include <mcamd_dimmcfg_impl.h>
32 * We have built a list of the active csbase/csmask pairs, and now we want
33 * to associate those active chip-selects with actual dimms. To achieve this
34 * we must map the csbase/csmask pair to an associated logical DIMM and
35 * chip-select line.
37 * A logical DIMM comprises up to 2 physical dimms as follows:
39 * - in 64-bit mode without mismatched dimm support logical DIMMs are
40 * made up of just one physical dimm situated in a "lodimm" slot
41 * on channel A; the corresponding slot on channel B (if there is
42 * a channel B) must be empty or will be disabled if populated.
44 * - in 64-bit mode with mismatched dimm support a logical DIMM may
45 * be made up of 1 or 2 physical dimms - one on channel A and another
46 * in the corresponding slot on channel B. They are accessed
47 * independently.
49 * - in 128 bit mode a logical DIMM is made up of two physical dimms -
50 * a pair of one slot on channel A and its partner on channel B.
51 * The lodimm on channel A provides data [63:0] while the updimm
52 * on channel B provides data [127:64]. The two dimms must be
53 * identical in size and organisation (number of ranks etc).
55 * The following tables are derived from the corresponding
56 * "DRAM CS Base and DRAM CS Mask Registers" with and without mismatched
57 * dimm support tables of the BKDG (tables 5 and 6 of BKDG 3.31 for rev E
58 * and earlier; tables 8 and 9 of BKDG 3.01 for rev F and G). They could
59 * be implemented programatically, but are more readily reviewed for correctness
60 * presented as tables.
62 * When we observe a given chip-select base/mask pair to be enabled in a
63 * system configuration we lookup in the following tables to match on
64 * all of base register pair number, processor revision, socket type
65 * and dram configuration (e.g., quadrank registered or not); the remainder
66 * of the matched line provides the corresponding logical dimm (ldimm)
67 * number that the chip-select is to be associated with and details of
68 * which chip-select line is used to operate that chip-select (specified
69 * as a (channel, slot-number, rank-number) triple. With this
70 * information we determine the topology instance number of each physical
71 * DIMM. There are three distinct cases to consider:
73 * 128-bit MC mode:
75 * The lodimm (channel A) and updimm (channel B) dimm in a pair
76 * have instance numbers 2 * ldimm and 2 * ldimm + 1, i.e.
77 * 0/1, 2/3, 4/5, 5/6 for ldimm = 0, 1, 2, 3 (ldimms 2 and 3
78 * are only supported for socket 940 and socket F(1207).
80 * 64-bit MC mode, no mismatched dimm support:
82 * All dimms reside on channel A. If there is a channel B
83 * (anything other than socket 754) then any DIMMs on it will
84 * not be configured into the system. We number as for
85 * 128-bit mode but omiting the channel B DIMMs, i.e.
86 * 0, 2, 4, 6 for ldimm = 0, 1, 2, 3.
88 * 64-bit MC mode, mismatched dimm support enabled:
90 * Each rank of every DIMM is treated as a separate logical
91 * dimm, so while the package (939 or AM2) only supports two
92 * DIMMS per channel and normally logical dimms 2 and 3
93 * would not be supported they do spring into existence in this
94 * special mode.
96 * Because of the mismatched DIMM support case we cannot derive
97 * instance number from logical dimm number alone. For that case we use the
98 * slot number on the channel - that tracks the ldimm except in the
99 * mismatched case. This provides consistent instance numbering
100 * even for a system cycled through each of the above configurations -
101 * the instance dimm remains the same for a given channel and slot
102 * number.
104 * When quadrank DIMMs - quadrank registered or quadrank SODIMM - are in
105 * use we must always base the instance number off of the ldimm regardless
106 * of mismatched DIMM support.
109 #define MCAMD_TOPONUM(ldimm, cslp, quadrank, mod64mux) \
110 (((quadrank) || !(mod64mux)) ? \
111 2 * (ldimm) + ((cslp)->csl_chan == CH_B) : \
112 2 * (cslp)->csl_slot + ((cslp)->csl_chan == CH_B))
114 /* BEGIN CSTYLED */
117 * Revision E and earlier mapping with mismatched dimm support disabled.
119 static const struct mcdcfg_csmapline csmap_nomod64mux_preF[] = {
121 * Pkgs base dramconfig ldimm cs A cs B
123 * Base reg 0 (mask 0)
125 { SKT_ALL, 0, DCFG_ALL, 0, { { CH_A, 0, 0 }, { CH_B, 0, 0 } } },
127 * Base reg 1 (mask 1)
129 { SKT_ALL, 1, DCFG_ALL, 0, { { CH_A, 0, 1 }, { CH_B, 0, 1 } } },
131 * Base reg 2 (mask 2)
133 { SKT_ALL, 2, DCFG_ALL, 1, { { CH_A, 1, 0 }, { CH_B, 1, 0 } } },
135 * Base reg 3 (mask 3)
137 { SKT_ALL, 3, DCFG_ALL, 1, { { CH_A, 1, 1 }, { CH_B, 1, 1 } } },
139 * Base reg 4 (mask 4)
141 { SKT_754, 4, DCFG_N, 2, { { CH_A, 2, 0 } } },
142 { SKT_940, 4, DCFG_N, 2, { { CH_A, 2, 0 }, { CH_B, 2, 0 } } },
143 { SKT_940, 4, DCFG_R4, 0, { { CH_A, 2, 0 }, { CH_B, 2, 0 } } },
145 * Base reg 5 (mask 5)
147 { SKT_754, 5, DCFG_N, 2, { { CH_A, 2, 1 } } },
148 { SKT_940, 5, DCFG_N, 2, { { CH_A, 2, 1 }, { CH_B, 2, 1 } } },
149 { SKT_940, 5, DCFG_R4, 0, { { CH_A, 2, 1 }, { CH_B, 2, 1 } } },
151 * Base reg 6 (mask 6)
153 { SKT_754, 6, DCFG_N, 3, { { CH_A, 3, 0 } } },
154 { SKT_940, 6, DCFG_N, 3, { { CH_A, 3, 0 }, { CH_B, 3, 0 } } },
155 { SKT_940, 6, DCFG_R4, 1, { { CH_A, 3, 0 }, { CH_B, 3, 0 } } },
157 * Base reg 7 (mask 7)
159 { SKT_754, 7, DCFG_N, 3, { { CH_A, 3, 1 } } },
160 { SKT_940, 7, DCFG_N, 3, { { CH_A, 3, 1 }, { CH_B, 3, 1 } } },
161 { SKT_940, 7, DCFG_R4, 1, { { CH_A, 3, 1 }, { CH_B, 3, 1 } } }
165 * Revision E and earlier mapping with mismatched dimm support.
166 * Mismatched dimm support applies only to the socket 939 package.
167 * Socket 939 does not support registered dimms, so quadrank RDIMMs are
168 * not an issue here.
170 static const struct mcdcfg_csmapline csmap_mod64mux_preF[] = {
172 * Pkgs base dramconfig ldimm cs A cs B
174 * Base reg 0 (mask 0)
176 { SKT_939, 0, DCFG_N, 0, { { CH_A, 0, 0 } } },
178 * Base reg 1 (mask 1)
180 { SKT_939, 1, DCFG_N, 0, { { CH_A, 0, 1 } } },
182 * Base reg 2 (mask 2)
184 { SKT_939, 2, DCFG_N, 1, { { CH_A, 1, 0 } } },
186 * Base reg 3 (mask 3)
188 { SKT_939, 3, DCFG_N, 1, { { CH_A, 1, 1 } } },
190 * Base reg 4 (mask 4)
192 { SKT_939, 4, DCFG_N, 2, { { CH_B, 0, 0 } } },
194 * Base reg 5 (mask 5)
196 { SKT_939, 5, DCFG_N, 2, { { CH_B, 0, 1 } } },
198 * Base reg 6 (mask 6)
200 { SKT_939, 6, DCFG_N, 3, { { CH_B, 1, 0 } } },
202 * Base reg 7 (mask 7)
204 { SKT_939, 7, DCFG_N, 3, { { CH_B, 1, 1 } } }
208 * Rev F and G csbase/csmask to logical DIMM and cs line mappings.
210 * We can reduce the tables by a few lines by taking into account which
211 * DIMM types are supported by the different package types:
213 * Number of dimms of given type supported per dram channel
214 * Package Reg'd DIMM 4-rank reg'd Unbuffered SO-DIMMs
215 * F(1207) 4 2 0 0
216 * AM2 0 0 2 1
217 * S1g1 0 0 0 1
221 * NPT (rev F & G) mapping with mismatched dimm support disabled.
223 static const struct mcdcfg_csmapline csmap_nomod64mux_fg[] = {
225 * Pkgs base dramconfig ldimm cs A cs B
227 * Base reg 0 (mask 0)
229 { SKT_NPT, 0, DCFG_ALLNPT, 0, { { CH_A, 0, 0 }, { CH_B, 0, 0 } } },
231 * Base reg 1 (mask 0)
233 { SKT_NPT, 1, DCFG_ALLNPT, 0, { { CH_A, 0, 1 }, { CH_B, 0, 1 } } },
235 * Base reg 2 (mask 1)
237 { AM2F1207, 2, DCFG_N | DCFG_R4, 1, { { CH_A, 1, 0 }, { CH_B, 1, 0 } } },
238 { AM2, 2, DCFG_S4, 0, { { CH_A, 1, 0 }, { CH_B, 1, 0 } } },
239 { S1g1, 2, DCFG_N, 1, { { CH_A, 0, 2 }, { CH_B, 0, 2 } } },
240 { S1g1, 2, DCFG_S4, 0, { { CH_A, 0, 2 }, { CH_B, 0, 2 } } },
242 * Base reg 3 (mask 1)
244 { AM2F1207, 3, DCFG_N | DCFG_R4, 1, { { CH_A, 1, 1 }, { CH_B, 1, 1 } } },
245 { AM2, 3, DCFG_S4, 0, { { CH_A, 1, 1 }, { CH_B, 1, 1 } } },
246 { S1g1, 3, DCFG_N, 1, { { CH_A, 0, 3 }, { CH_B, 0, 3 } } },
247 { S1g1, 3, DCFG_S4, 0, { { CH_A, 0, 3 }, { CH_B, 0, 3 } } },
249 * Base reg 4 (mask 2)
251 { F1207, 4, DCFG_N, 2, { { CH_A, 2, 0 }, { CH_B, 2, 0 } } },
252 { F1207, 4, DCFG_R4, 0, { { CH_A, 2, 0 }, { CH_B, 2, 0 } } },
254 * Base reg 5 (mask 2)
256 { F1207, 5, DCFG_N, 2, { { CH_A, 2, 1 }, { CH_B, 2, 1 } } },
257 { F1207, 5, DCFG_R4, 0, { { CH_A, 2, 1 }, { CH_B, 2, 1 } } },
259 * Base reg 6 (mask 3)
261 { F1207, 6, DCFG_N, 3, { { CH_A, 3, 0 }, { CH_B, 3, 0 } } },
262 { F1207, 6, DCFG_R4, 1, { { CH_A, 3, 0 }, { CH_B, 3, 0 } } },
264 * Base reg 7 (mask 3)
266 { F1207, 7, DCFG_N, 3, { { CH_A, 3, 1 }, { CH_B, 3, 1 } } },
267 { F1207, 7, DCFG_R4, 1, { { CH_A, 3, 1 }, { CH_B, 3, 1 } } }
271 * NPT (rev F & G) mapping with mismatched dimm support.
272 * Mismatched dimm support applies only to the AM2 and S1g1 packages.
273 * AM2 and S1g1 do not support registered dimms.
275 static const struct mcdcfg_csmapline csmap_mod64mux_fg[] = {
277 * Pkgs base dramconfig ldimm cs A cs B
279 * Base reg 0 (mask 0)
281 { AM2S1g1, 0, DCFG_N | DCFG_S4, 0, { { CH_A, 0, 0 } } },
283 * Base reg 1 (mask 0)
285 { AM2S1g1, 1, DCFG_N | DCFG_S4, 0, { { CH_A, 0, 1 } } },
287 * Base reg 2 (mask 1)
289 { AM2, 2, DCFG_N, 1, { { CH_A, 1, 0 } } },
290 { AM2, 2, DCFG_S4, 0, { { CH_A, 1, 0 } } },
291 { S1g1, 2, DCFG_N, 1, { { CH_A, 0, 2 } } },
292 { S1g1, 2, DCFG_S4, 0, { { CH_A, 0, 2 } } },
294 * Base reg 3 (mask 1)
296 { AM2, 3, DCFG_N, 1, { { CH_A, 1, 1 } } },
297 { AM2, 3, DCFG_S4, 0, { { CH_A, 1, 1 } } },
298 { S1g1, 3, DCFG_N, 1, { { CH_A, 0, 3 } } },
299 { S1g1, 3, DCFG_S4, 0, { { CH_A, 0, 3 } } },
301 * Base reg 4 (mask 2)
303 { AM2S1g1, 4, DCFG_N, 2, { { CH_B, 0, 0 } } },
304 { AM2S1g1, 4, DCFG_S4, 1, { { CH_B, 0, 0 } } },
306 * Base reg 5 (mask 2)
308 { AM2S1g1, 5, DCFG_N, 2, { { CH_B, 0, 1 } } },
309 { AM2S1g1, 5, DCFG_S4, 1, { { CH_B, 0, 1 } } },
311 * Base reg 6 (mask 3)
313 { AM2, 6, DCFG_N, 3, { { CH_B, 1, 0 } } },
314 { AM2, 6, DCFG_S4, 1, { { CH_B, 1, 0 } } },
315 { S1g1, 6, DCFG_N, 3, { { CH_B, 0, 2 } } },
316 { S1g1, 6, DCFG_S4, 1, { { CH_B, 0, 2 } } },
318 * Base reg 7 (mask 3)
320 { AM2, 7, DCFG_N, 3, { { CH_B, 1, 1 } } },
321 { AM2, 7, DCFG_S4, 1, { { CH_B, 1, 1 } } },
322 { S1g1, 7, DCFG_N, 3, { { CH_B, 0, 3 } } },
323 { S1g1, 7, DCFG_S4, 1, { { CH_B, 0, 3 } } }
326 /* END CSTYLED */
328 #define DCFG_NTBL 4
330 static const struct {
331 uint32_t revmask; /* applicable chip revs */
332 int mod64mux; /* mismatched support or not */
333 const struct mcdcfg_csmapline *map;
334 int nmapents;
335 } csmap_tbls[DCFG_NTBL] = {
336 { MC_F_REVS_BCDE, 0, &csmap_nomod64mux_preF[0],
337 sizeof (csmap_nomod64mux_preF) / sizeof (struct mcdcfg_csmapline) },
338 { MC_F_REVS_BCDE, 1, &csmap_mod64mux_preF[0],
339 sizeof (csmap_mod64mux_preF) / sizeof (struct mcdcfg_csmapline) },
340 { MC_F_REVS_FG, 0, &csmap_nomod64mux_fg[0],
341 sizeof (csmap_nomod64mux_fg) / sizeof (struct mcdcfg_csmapline) },
342 { MC_F_REVS_FG, 1, &csmap_mod64mux_fg[0],
343 sizeof (csmap_mod64mux_fg) / sizeof (struct mcdcfg_csmapline) }
347 mcdcfg_lookup(uint32_t rev, int mod64mux, int accwidth, int basenum,
348 uint32_t pkg, int r4, int s4, mcdcfg_rslt_t *rsltp)
350 const struct mcdcfg_csmapline *csm = NULL;
351 int ismux = (mod64mux != 0);
352 int nmapents;
353 int ndimm = (accwidth == 128) ? 2 : 1;
354 int dcfg;
355 int i;
358 * Validate aspects that the table lookup won't.
360 if ((accwidth != 64 && accwidth != 128) || (r4 != 0 && s4 != 0))
361 return (-1);
363 for (i = 0; i < DCFG_NTBL; i++) {
364 if (MC_REV_MATCH(rev, csmap_tbls[i].revmask) &&
365 ismux == csmap_tbls[i].mod64mux) {
366 csm = csmap_tbls[i].map;
367 nmapents = csmap_tbls[i].nmapents;
368 break;
371 if (csm == NULL)
372 return (-1);
374 if (r4)
375 dcfg = DCFG_R4;
376 else if (s4)
377 dcfg = DCFG_S4;
378 else
379 dcfg = DCFG_N;
381 for (i = 0; i < nmapents; i++, csm++) {
382 if (X86_SOCKET_MATCH(pkg, csm->csm_pkg) &&
383 basenum == csm->csm_basereg &&
384 (dcfg & csm->csm_dimmcfg) != 0)
385 break;
387 if (i == nmapents)
388 return (-1);
391 * We return the dimm instance number here for the topology, based
392 * on the AMD Motherboard Design Guide.
394 rsltp->ldimm = csm->csm_ldimm;
395 rsltp->ndimm = ndimm;
396 for (i = 0; i < ndimm; i++) {
397 const struct mcdcfg_csl *cslp = &csm->csm_cs[i];
399 rsltp->dimm[i].toponum =
400 MCAMD_TOPONUM(rsltp->ldimm, cslp, r4 || s4, ismux);
401 rsltp->dimm[i].cslp = cslp;
404 return (0);
408 * Given a chip-select line and package type return the chip-select line
409 * pin label for that package type.
411 void
412 mcdcfg_csname(uint32_t pkg, const mcdcfg_csl_t *cslp, char *buf, int buflen)
414 int csnum;
416 switch (pkg) {
417 case X86_SOCKET_754:
419 * Format is: MEMCS_L[{0..7}]. There is only channel A.
421 csnum = 2 * cslp->csl_slot + cslp->csl_rank;
422 (void) snprintf(buf, buflen, "MEMCS_L%d", csnum);
423 break;
425 case X86_SOCKET_940:
427 * Format is: MEMCS_L[{0..7}]. That does not identify
428 * a single dimm (since a single chip-select is shared
429 * by both members of a dimm pair in socket 940) so
430 * we tack on some channel identification.
432 csnum = 2 * cslp->csl_slot + cslp->csl_rank;
433 (void) snprintf(buf, buflen, "MEMCS_L%d (channel %s)", csnum,
434 cslp->csl_chan == CH_A ? "A" : "B");
436 break;
438 case X86_SOCKET_939:
440 * Format is: MEMCS_{1,2}{L,H}_L[{1,0}]
441 * {1,2} - dimm pair
442 * {L,H} - lodimm or updimm
443 * {1,0} - rank
445 (void) snprintf(buf, buflen, "MEMCS_%d%s_L[%d]",
446 cslp->csl_slot + 1,
447 cslp->csl_chan == CH_A ? "A" : "B",
448 cslp->csl_rank);
449 break;
451 case X86_SOCKET_F1207:
452 case X86_SOCKET_AM2:
453 case X86_SOCKET_S1g1:
455 * Format is: M{B,A}{0,1,2,3}_CS_L[{0,1,2,3}]
456 * {B,A} - channel
457 * {0,1,2,3} - slot on channel
458 * {0,1,2,3} - rank
460 (void) snprintf(buf, buflen, "M%s%d_CS_L[%d]",
461 cslp->csl_chan == CH_A ? "A" : "B",
462 cslp->csl_slot,
463 cslp->csl_rank);
464 break;
466 default:
467 (void) snprintf(buf, buflen, "Unknown");
468 break;