7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER START
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * The contents of this file are subject to the terms of the
5f25dc2aa25a1742246574b0899ea47f941f0fbcgavinm * Common Development and Distribution License (the "License").
5f25dc2aa25a1742246574b0899ea47f941f0fbcgavinm * You may not use this file except in compliance with the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * See the License for the specific language governing permissions
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and limitations under the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * When distributing Covered Code, include this CDDL HEADER in each
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * If applicable, add the following below this CDDL HEADER, with the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * fields enclosed by brackets "[]" replaced with your own identifying
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * information: Portions Copyright [yyyy] [name of copyright owner]
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER END
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
70818f5837509317d1f5dac4d82d7b5a2d547c29tsien * platform specific mem module
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int mem_enum(topo_mod_t *, tnode_t *, const char *, topo_instance_t,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_instance_t, void *, void *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int mem_nvl2str(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindistatic int mem_fmri_create(topo_mod_t *, tnode_t *, topo_version_t,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi { TOPO_METH_NVL2STR, TOPO_METH_NVL2STR_DESC, TOPO_METH_NVL2STR_VERSION,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi { TOPO_METH_FMRI, TOPO_METH_FMRI_DESC, TOPO_METH_FMRI_VERSION,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (topo_mod_register(mod, &mem_info, TOPO_VERSION) != 0) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindimem_enum(topo_mod_t *mod, tnode_t *pnode, const char *name,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_instance_t min, topo_instance_t max, void *notused1, void *notused2)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby if (isglobal && (nmp = topo_mod_load(mod, PLATFORM_MEM_NAME,
70818f5837509317d1f5dac4d82d7b5a2d547c29tsien * There is no platform specific mem module.
70818f5837509317d1f5dac4d82d7b5a2d547c29tsien return (0);
70818f5837509317d1f5dac4d82d7b5a2d547c29tsien /* Fail to load the module */
70818f5837509317d1f5dac4d82d7b5a2d547c29tsien return (-1);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby if (isglobal && topo_mod_enumerate(nmp, pnode, PLATFORM_MEM_NAME, name,
70818f5837509317d1f5dac4d82d7b5a2d547c29tsien return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh * Convert an input string to a URI escaped string and return the new string.
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh * RFC2396 Section 2.4 says that data must be escaped if it does not have a
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh * representation using an unreserved character, where an unreserved character
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh * is one that is either alphanumeric or one of the marks defined in S2.3.
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephhmem_fmri_uriescape(const char *s, const char *xmark, char *buf, size_t len)
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh const char *p;
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh char c, *q;
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh for (p = s; (c = *p) != '\0'; p++) {
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh if (isalnum(c) || strchr(rfc2396_mark, c) || strchr(xmark, c))
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh n++; /* represent c as itself */
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh return (n);
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh for (p = s, q = buf; (c = *p) != '\0' && q < buf + len; p++) {
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh if (isalnum(c) || strchr(rfc2396_mark, c) || strchr(xmark, c)) {
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh *q++ = '%';
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh q--; /* len is too small: truncate output string */
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh return (n);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindimem_nvl2str(topo_mod_t *mod, tnode_t *node, topo_version_t version,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_string(in, FM_FMRI_MEM_UNUM, &unum) != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * If we have a DIMM offset, include it in the string. If we have a
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * PA then use that. Otherwise just format the unum element.
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi if (nvlist_lookup_uint64(in, FM_FMRI_MEM_OFFSET, &val) == 0) {
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi } else if (nvlist_lookup_uint64(in, FM_FMRI_MEM_PHYSADDR, &val) == 0) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * If we have a well-formed unum we step over the hc:// and
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * authority prefix
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh (void) mem_fmri_uriescape(preunum, ":,/", escunum, i + 1);
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh len = snprintf(NULL, 0, format, prefix, escunum, val) + 1;
e5ba14ff435beeefdaa2e6649e175c74afe02c76stephh (void) snprintf(buf, len, format, prefix, escunum, val);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (err != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindimem_fmri(topo_mod_t *mod, uint64_t pa, uint64_t offset, char *unum, int flags)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (topo_mod_nvalloc(mod, &asru, NV_UNIQUE_NAME) != 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * If we have a well-formed unum we step over the hc:/// and
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * authority prefix
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi err = nvlist_add_uint8(asru, FM_VERSION, FM_MEM_SCHEME_VERSION);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi err |= nvlist_add_string(asru, FM_FMRI_SCHEME, FM_FMRI_SCHEME_MEM);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi err |= nvlist_add_string(asru, FM_FMRI_MEM_UNUM, unum);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi err |= nvlist_add_uint64(asru, FM_FMRI_MEM_PHYSADDR, pa);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi err |= nvlist_add_uint64(asru, FM_FMRI_MEM_OFFSET, offset);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (err != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
0eb822a1c0c2bea495647510b75f77f0e57633ebcindimem_fmri_create(topo_mod_t *mod, tnode_t *node, topo_version_t version,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (nvlist_lookup_uint64(in, FM_FMRI_MEM_PHYSADDR, &pa) == 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (nvlist_lookup_uint64(in, FM_FMRI_MEM_OFFSET, &offset) == 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (nvlist_lookup_string(in, FM_FMRI_MEM_UNUM, &unum) != 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (0);