mem_disc.c revision 6dfee4834394825da35b977ca71cdc965bc7b6a4
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* The map is constructed from PICL configuration files, which contain a map
* between a form of the unum and the device to be used for serial number
* retrieval. We massage the PICL unum into a form that matches the one used
* by mem FMRIs, creating a map entry from the munged version. As described
* below, two configuration files must be correlated to determine the correct
* device path, and thus to build the mem_dimm_map_t list. While platforms
* without PICL configuration files are acceptable (some platforms, like
* Serengeti and Starcat, don't have configuration files as of this writing),
* platforms with only one or the other aren't.
*
* On Sun4v platforms, we read the 'mdesc' machine description file in order
* to obtain the mapping between dimm unum+jnum strings (which denote slot
* names) and the serial numbers of the dimms occupying those slots.
*/
#include <mem.h>
#include <fm/fmd_fmri.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#define PICL_FRUTREE_PATH \
#define PICL_FRUDATA_PATH \
typedef struct mem_path_map {
struct mem_path_map *pm_next;
char *pm_path;
char *pm_fullpath;
typedef struct label_xlators {
const char *lx_infmt;
const char *lx_outfmt;
/*
* PICL configuration files use a different format for the DIMM name (unum)
* than that used in mem FMRIs. The following patterns and routine are used
* to convert between the PICL and unum formats.
*/
static const label_xlators_t label_xlators[] = {
{ "/system-board/mem-slot?Label=J%4d%5$n", 1,
"J%04d" },
{ "/system-board/mem-slot?Label=DIMM%1d%5$n", 1,
"DIMM%d" },
{ "/system-board/cpu-mem-slot?Label=%4$c/mem-slot?Label=J%1$4d%5$n", 2,
"Slot %4$c: J%1$4d" },
{ "/MB/system-board/mem-slot?Label=DIMM%1d%5$n", 1,
"DIMM%d" },
"MB/P%d/B%d/D%d" },
{ "/MB/system-board/DIMM%1d%5$n", 1,
{ NULL }
};
static int
label_xlate(char *buf)
{
const label_xlators_t *xlator;
return (0);
char a4;
return (0);
}
}
return (fmd_fmri_set_errno(EINVAL));
}
/*
* Match two paths taken from picl files. This is a normal component-based path
* comparison, but for the fact that components `foo' and `foo@1,2' are assumed
* to be equal. `foo@1,2' and `foo@3,4', however, are not assumed to be equal.
*/
static int
{
for (;;) {
if (*p1 == '\0')
return (1);
else {
p1++;
p2++;
continue;
}
}
p1++;
continue;
}
p2++;
continue;
}
return (0);
}
}
/*
* PICL paths begin with `/platform' instead of `/devices', as they are
* intended to reference points in the PICL tree, rather than places in the
* device tree. Furthermore, some paths use the construct `?UnitAddress=a,b'
* instead of `@a,b' to indicate unit number and address. This routine
* replaces both constructs with forms more appropriate for /devices path
* lookup.
*/
static void
path_depicl(char *path)
{
char *c;
if (len == 0)
continue;
*c = '@';
}
}
/*
* The libpiclfrudata configuration file contains a map between the generic
* data access.
*
* Entries are of the form:
*
* name:/platform/generic-path
* PROP FRUDevicePath string r 0 "full-path"
*
* Where `generic-path' is the path, sans minor name, to be used for DIMM
* data access, and `full-path' is the path with the minor name.
*/
static int
{
return (0);
return (1);
}
/*
* The piclfrutree configuration file contains a map between a form of the
* access.
*
* Entries are of the form:
*
* REFNODE mem-module fru WITH /platform/generic-path
*
* Where `picl-unum' is the PICL form of the unum, which we'll massage into
* the form compatible with FMRIs (see label_xlate), and `generic-path' is
* the minor-less path into the PICL tree for the device used to access the
* DIMM. It is this path that will be used as the key in the frudata
* configuration file to determine the proper /devices path.
*/
typedef struct dimm_map_arg {
static int
{
/* LINTED - sscanf cannot exceed sizeof (path) */
return (0);
if (label_xlate(label) < 0)
return (-1); /* errno is set for us */
break;
}
}
return (1);
}
/*
* Both configuration files use the same format, thus allowing us to use the
* same parser to process them.
*/
static int
void *arg)
{
char confpath[MAXPATHLEN];
return (-1); /* errno is set for us */
label[0] = '\0';
if (buf[0] == '#')
continue;
if (buf[0] == '\n') {
label[0] = '\0';
continue;
}
/* LINTED - label length cannot exceed length of buf */
continue;
if (label[0] != '\0') {
return (fmd_fmri_set_errno(err));
} else if (rc != 0) {
label[0] = '\0';
}
}
}
return (0);
}
static void
{
}
}
int
mem_discover_mdesc(void)
{
/*
* Find first 'memory' node -- there should only be one. Extract
* 'memory-generation-id#' value from it.
*/
&mem.mem_memconfig))
mem.mem_memconfig = 0;
unum = "";
serial = "";
}
return (0);
}
void
mem_destroy(void)
{
}
}
int
mem_discover_picl(void)
{
int rc;
return (-1); /* errno is set for us */
/*
* This platform doesn't support serial number retrieval via
* PICL mapping files. Unfortunate, but not an error.
*/
return (0);
}
if (rc < 0)
return (-1); /* errno is set for us */
/*
* This platform should support DIMM serial numbers, but we
* weren't able to derive the paths. Return an error.
*/
return (fmd_fmri_set_errno(EIO));
}
return (0);
}
/*
* Sun4v: if a valid 'mdesc' machine description file exists,
* read the mapping of dimm unum+jnum to serial number from it.
*/
int
mem_discover(void)
{
return (mem_discover_picl());
else
return (mem_discover_mdesc());
}