xref: /titanic_41/usr/src/uts/sun4u/serengeti/os/sg_unum.c (revision 10db1377dafab8ba3feedef26db9c5d8539a5cd1)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/serengeti.h>
31 #include <sys/errno.h>
32 #include <sys/systm.h>
33 #include <sys/cmn_err.h>
34 
35 /*
36  * When an ECC error occurs on an E$ DIMM, the error handling code requests a
37  * unum to provide a human-readable physical location to the part that
38  * experienced the error.
39  *
40  * Previously, on Serengeti and LW8, a prom call was made to get this
41  * information.  However, calling COBP to do a simple string format is
42  * inefficient.  All the necessary information is now kept here.
43  *
44  * Since this data is now kept in two places (COBP and here), care must be
45  * taken so that the two locations are kept the same.  Any changes to the
46  * jnumber array will require a change to COBP code so that the two arrays
47  * match.  Any changes to the unum string format will require changes in both
48  * the COBP code (to match the code here) and plat_ecc_unum.c (to read the
49  * new format).  These changes should not be necessary, except to reflect a
50  * new cpu or board type.
51  */
52 
53 /*
54  * The following array holds the jnumbers for Ecache DIMMs.  The first index
55  * is the proc position on the board (0 through 3) and the second index is
56  * the DIMM number (0 or 1).
57  */
58 static int sg_j_number[SG_MAX_CMPS_PER_BD][SG_NUM_ECACHE_DIMMS_PER_CPU] = {
59 	{ 4400, 4300 },
60 	{ 5400, 5300 },
61 	{ 6400, 6300 },
62 	{ 7400, 7300 }
63 };
64 
65 /*
66  * Generate the unum for the specified cpuid and physical address.  Put the
67  * unum in buf, which is of size buflen.  Return the length of the string in
68  * lenp.
69  *
70  * Return 0 if successful, and an error number otherwise.
71  */
72 int
73 sg_get_ecacheunum(int cpuid, uint64_t physaddr, char *buf, uint_t buflen,
74     int *lenp)
75 {
76 	int node = SG_PORTID_TO_NODEID(cpuid);
77 	int board = SG_CPU_BD_PORTID_TO_BD_NUM(cpuid);
78 	int proc = SG_PORTID_TO_CPU_POSN(cpuid);
79 	int dimm = (physaddr & SG_ECACHE_DIMM_MASK) >> SG_ECACHE_DIMM_SHIFT;
80 
81 	/*
82 	 * node and dimm will always be valid.  board and proc may be -1 if
83 	 * an invalid cpuid is passed in.
84 	 */
85 	if ((board == -1) || (proc == -1)) {
86 		return (EINVAL);
87 	}
88 
89 	*lenp = snprintf(buf, buflen, "/N%d/SB%d/P%d/E%d J%d",
90 	    node, board, proc, dimm, sg_j_number[proc][dimm]);
91 
92 	return (0);
93 }
94