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/*
22 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#pragma ident	"%Z%%M%	%I%	%E% SMI"
27
28#include <sys/types.h>
29#include <sys/serengeti.h>
30#include <sys/errno.h>
31#include <sys/systm.h>
32#include <sys/cmn_err.h>
33#include <sys/cheetahregs.h>
34#include <sys/cpuvar.h>
35
36/*
37 * When an ECC error occurs on an E$ DIMM, the error handling code requests a
38 * unum to provide a human-readable physical location to the part that
39 * experienced the error.
40 *
41 * Previously, on Serengeti and LW8, a prom call was made to get this
42 * information.  However, calling COBP to do a simple string format is
43 * inefficient.  All the necessary information is now kept here.
44 *
45 * Since this data is now kept in two places (COBP and here), care must be
46 * taken so that the two locations are kept the same.  Any changes to the
47 * jnumber array will require a change to COBP code so that the two arrays
48 * match.  Any changes to the unum string format will require changes in both
49 * the COBP code (to match the code here) and plat_ecc_unum.c (to read the
50 * new format).  These changes should not be necessary, except to reflect a
51 * new cpu or board type.
52 */
53
54/*
55 * The following array holds the jnumbers for Ecache DIMMs.  The first index
56 * is the proc position on the board (0 through 3) and the second index is
57 * the DIMM number (0 or 1).
58 */
59static int sg_j_number[SG_MAX_CMPS_PER_BD][SG_NUM_ECACHE_DIMMS_PER_CPU] = {
60	{ 4400, 4300 },
61	{ 5400, 5300 },
62	{ 6400, 6300 },
63	{ 7400, 7300 }
64};
65
66/*
67 * Generate the unum for the specified cpuid and physical address.  Put the
68 * unum in buf, which is of size buflen.  Return the length of the string in
69 * lenp.
70 *
71 * Return 0 if successful, and an error number otherwise.
72 */
73int
74sg_get_ecacheunum(int cpuid, uint64_t physaddr, char *buf, uint_t buflen,
75    int *lenp)
76{
77	int node = SG_PORTID_TO_NODEID(cpuid);
78	int board = SG_CPU_BD_PORTID_TO_BD_NUM(cpuid);
79	int proc = SG_PORTID_TO_CPU_POSN(cpuid);
80	int dimm;
81
82	/*
83	 * node and dimm will always be valid.  board and proc may be -1 if
84	 * an invalid cpuid is passed in.
85	 */
86	if ((board == -1) || (proc == -1)) {
87		return (EINVAL);
88	}
89
90	/* Find the DIMM number (0 or 1) based on the value of physaddr bit 4 */
91	if (IS_PANTHER(cpunodes[CPU->cpu_id].implementation) ||
92	    IS_JAGUAR(cpunodes[CPU->cpu_id].implementation))
93		dimm = (physaddr & SG_ECACHE_DIMM_MASK) ? 0 : 1;
94	else
95		dimm = (physaddr & SG_ECACHE_DIMM_MASK) ? 1 : 0;
96
97	*lenp = snprintf(buf, buflen, "/N%d/SB%d/P%d/E%d J%d",
98	    node, board, proc, dimm, sg_j_number[proc][dimm]);
99
100	return (0);
101}
102