xref: /onnv-gate/usr/src/uts/sparc/io/devfm_machdep.c (revision 7532:bb6372f778bb)
1*7532SSean.Ye@Sun.COM /*
2*7532SSean.Ye@Sun.COM  * CDDL HEADER START
3*7532SSean.Ye@Sun.COM  *
4*7532SSean.Ye@Sun.COM  * The contents of this file are subject to the terms of the
5*7532SSean.Ye@Sun.COM  * Common Development and Distribution License (the "License").
6*7532SSean.Ye@Sun.COM  * You may not use this file except in compliance with the License.
7*7532SSean.Ye@Sun.COM  *
8*7532SSean.Ye@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7532SSean.Ye@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*7532SSean.Ye@Sun.COM  * See the License for the specific language governing permissions
11*7532SSean.Ye@Sun.COM  * and limitations under the License.
12*7532SSean.Ye@Sun.COM  *
13*7532SSean.Ye@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*7532SSean.Ye@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7532SSean.Ye@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*7532SSean.Ye@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*7532SSean.Ye@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*7532SSean.Ye@Sun.COM  *
19*7532SSean.Ye@Sun.COM  * CDDL HEADER END
20*7532SSean.Ye@Sun.COM  */
21*7532SSean.Ye@Sun.COM /*
22*7532SSean.Ye@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*7532SSean.Ye@Sun.COM  * Use is subject to license terms.
24*7532SSean.Ye@Sun.COM  */
25*7532SSean.Ye@Sun.COM 
26*7532SSean.Ye@Sun.COM #include <sys/stat.h>
27*7532SSean.Ye@Sun.COM #include <sys/types.h>
28*7532SSean.Ye@Sun.COM #include <sys/time.h>
29*7532SSean.Ye@Sun.COM #include <sys/systm.h>
30*7532SSean.Ye@Sun.COM 
31*7532SSean.Ye@Sun.COM #include <sys/fm/protocol.h>
32*7532SSean.Ye@Sun.COM #include <sys/devfm.h>
33*7532SSean.Ye@Sun.COM 
34*7532SSean.Ye@Sun.COM extern int cpu_get_mem_addr(char *, char *, uint64_t, uint64_t *);
35*7532SSean.Ye@Sun.COM 
36*7532SSean.Ye@Sun.COM int
fm_get_paddr(nvlist_t * nvl,uint64_t * paddr)37*7532SSean.Ye@Sun.COM fm_get_paddr(nvlist_t *nvl, uint64_t *paddr)
38*7532SSean.Ye@Sun.COM {
39*7532SSean.Ye@Sun.COM 	uint8_t version;
40*7532SSean.Ye@Sun.COM 	uint64_t pa;
41*7532SSean.Ye@Sun.COM 	char *scheme;
42*7532SSean.Ye@Sun.COM 	int err;
43*7532SSean.Ye@Sun.COM 	uint64_t offset;
44*7532SSean.Ye@Sun.COM 	char *unum;
45*7532SSean.Ye@Sun.COM 	char **serids;
46*7532SSean.Ye@Sun.COM 	uint_t nserids;
47*7532SSean.Ye@Sun.COM 
48*7532SSean.Ye@Sun.COM 	/* Verify FMRI scheme name and version number */
49*7532SSean.Ye@Sun.COM 	if ((nvlist_lookup_string(nvl, FM_FMRI_SCHEME, &scheme) != 0) ||
50*7532SSean.Ye@Sun.COM 	    (strcmp(scheme, FM_FMRI_SCHEME_MEM) != 0) ||
51*7532SSean.Ye@Sun.COM 	    (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0) ||
52*7532SSean.Ye@Sun.COM 	    version > FM_MEM_SCHEME_VERSION) {
53*7532SSean.Ye@Sun.COM 		return (EINVAL);
54*7532SSean.Ye@Sun.COM 	}
55*7532SSean.Ye@Sun.COM 
56*7532SSean.Ye@Sun.COM 	/*
57*7532SSean.Ye@Sun.COM 	 * There are two ways a physical address can be  obtained from a mem
58*7532SSean.Ye@Sun.COM 	 * scheme FMRI.  One way is to use the "offset" and  "serial"
59*7532SSean.Ye@Sun.COM 	 * members, if they are present, together with the "unum" member to
60*7532SSean.Ye@Sun.COM 	 * calculate a physical address.  This is the preferred way since
61*7532SSean.Ye@Sun.COM 	 * it is independent of possible changes to the programming of
62*7532SSean.Ye@Sun.COM 	 * underlying hardware registers that may change the physical address.
63*7532SSean.Ye@Sun.COM 	 * If the "offset" member is not present, then the address is
64*7532SSean.Ye@Sun.COM 	 * retrieved from the "physaddr" member.
65*7532SSean.Ye@Sun.COM 	 */
66*7532SSean.Ye@Sun.COM 	if (nvlist_lookup_uint64(nvl, FM_FMRI_MEM_OFFSET, &offset) != 0) {
67*7532SSean.Ye@Sun.COM 		if (nvlist_lookup_uint64(nvl, FM_FMRI_MEM_PHYSADDR, &pa) !=
68*7532SSean.Ye@Sun.COM 		    0) {
69*7532SSean.Ye@Sun.COM 			return (EINVAL);
70*7532SSean.Ye@Sun.COM 		}
71*7532SSean.Ye@Sun.COM 	} else if (nvlist_lookup_string(nvl, FM_FMRI_MEM_UNUM, &unum) != 0 ||
72*7532SSean.Ye@Sun.COM 	    nvlist_lookup_string_array(nvl, FM_FMRI_MEM_SERIAL_ID, &serids,
73*7532SSean.Ye@Sun.COM 	    &nserids) != 0) {
74*7532SSean.Ye@Sun.COM 		return (EINVAL);
75*7532SSean.Ye@Sun.COM 	} else {
76*7532SSean.Ye@Sun.COM 		err = cpu_get_mem_addr(unum, serids[0], offset, &pa);
77*7532SSean.Ye@Sun.COM 		if (err != 0) {
78*7532SSean.Ye@Sun.COM 			if (err == ENOTSUP) {
79*7532SSean.Ye@Sun.COM 				/* Fall back to physaddr */
80*7532SSean.Ye@Sun.COM 				if (nvlist_lookup_uint64(nvl,
81*7532SSean.Ye@Sun.COM 				    FM_FMRI_MEM_PHYSADDR, &pa) != 0)
82*7532SSean.Ye@Sun.COM 					return (EINVAL);
83*7532SSean.Ye@Sun.COM 			} else
84*7532SSean.Ye@Sun.COM 				return (err);
85*7532SSean.Ye@Sun.COM 		}
86*7532SSean.Ye@Sun.COM 	}
87*7532SSean.Ye@Sun.COM 
88*7532SSean.Ye@Sun.COM 	*paddr = pa;
89*7532SSean.Ye@Sun.COM 	return (0);
90*7532SSean.Ye@Sun.COM }
91