mem_disc.c revision d30c532def6a53800f4c4926a0b726cb23b1e6df
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2008 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 <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <time.h>
extern ldom_hdl_t *mem_scheme_lhp;
#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/C%1d/cpu-module/P0/cpu/B%1d/bank/D%1d%5$n", 3,
{ "/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
{
}
}
{
uint16_t i;
for (i = 0; v > 1; i++) {
v = v >> 1;
}
return (i);
}
static mem_dimm_map_t *
get_dimm_by_sn(char *sn)
{
return (dp);
}
return (NULL);
}
size_t i, j;
int err;
err = 0;
for (j = 0; j < mem_bank_count; j++) {
break;
}
}
}
else
err++;
if (err == 0)
return (mg);
}
return (NULL);
}
size_t i, j;
for (i = 0; i < n; i++) {
for (j = 0; j < mem_bank_count; j++) {
}
}
}
return (mg);
}
#define MEM_BYTES_PER_CACHELINE 64
static void
{
int idx, mdesc_dimm_count;
mem_dimm_map_t *dm, *d;
char s[20];
/*
* 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) < 0)
serial = "";
&part) < 0)
part = "";
MEM_SERID_MAXLEN - 1);
}
/* N1 (MD) specific segment initialization */
dimms = 0;
min_chan = 99;
max_chan = -1;
min_rank = 99;
max_rank = -1;
return;
dimms++;
}
listp);
sysmem_size = 0;
sysmem_size += size;
}
;
rank_mask = i >> 1;
} else {
rank_mask = 0;
}
if (chans > 2)
chan_step = 1;
else
idx = 0;
}
}
}
}
static void
{
int n;
mdesc_dimm_count = 0;
continue;
&nac) < 0)
nac = "";
&jnum) < 0)
jnum = "";
"serial_number", &serial) < 0)
serial = "";
"part_number", &part) < 0)
part = "";
"dash_number", &dash) < 0)
dash = "";
jnum);
} else {
unum = "";
}
MEM_SERID_MAXLEN - 1);
}
}
/* N2 (PRI) specific segment initialization occurs here */
listp);
/*
* banklist and bclist will be parallel arrays. For a given bank,
* bclist[i] will be the PRI node id, and *banklist+i will point to the
* mem_bank_map_t for that bank.
*/
sizeof (mem_bank_map_t *));
sizeof (mde_cookie_t));
mask = 0;
match = 0;
/* link this bank to its dimms */
dl);
for (i = 0; i < n; i++) {
"serial_number", &serial) < 0)
continue;
continue;
}
}
listp);
base = 0;
size = 0;
bl);
else
}
}
int
{
int num_nodes;
int num_comps = 0;
listp);
if (num_comps == 0)
else
return (0);
}
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);
}
/*
* Initialize sun4v machine descriptor file for subsequent use.
* If the open fails (most likely because file doesn't exist), or if
* initialization fails, return NULL.
*
* If the open succeeds and initialization also succeeds, the returned value is
* a pointer to an md_impl_t, whose 1st element points to the buffer where
* the full mdesc has been read in. The size of this buffer is returned
* as 'bufsiz'. Caller is responsible for deallocating BOTH of these objects.
*/
static md_t *
{
}
return (NULL);
}
/*
* 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
}
int
mem_update_mdesc(void)
{
return (1);
} else {
}
}
}
/*
* Retry values for handling the case where the kernel is not yet ready
* to provide DIMM serial ids. Some platforms acquire DIMM serial id
* information from their System Controller via a mailbox interface.
* The values chosen are for 10 retries 3 seconds apart to approximate the
* possible 30 second timeout length of a mailbox message request.
*/
#define MAX_MEM_SID_RETRIES 10
#define MEM_SID_RETRY_WAIT 3
/*
* The comparison is asymmetric. It compares up to the length of the
* argument unum.
*/
static mem_dimm_map_t *
{
return (dm);
}
return (NULL);
}
/*
* Returns 0 with serial numbers if found, -1 (with errno set) for errors. If
* the unum (or a component of same) wasn't found, -1 is returned with errno
* set to ENOENT. If the kernel doesn't have support for serial numbers,
* -1 is returned with errno set to ENOTSUP.
*/
static int
{
int i, rc = 0;
int fd;
int retries = MAX_MEM_SID_RETRIES;
return (-1);
return (-1); /* errno is set for us */
}
for (i = 0; i < ndimms; i++) {
do {
break;
if (retries == 0) {
break;
}
/*
* EAGAIN indicates the kernel is
* not ready to provide DIMM serial
* ids. Sleep MEM_SID_RETRY_WAIT seconds
* and try again.
* nanosleep() is used instead of sleep()
* to avoid interfering with fmd timers.
*/
} while (retries--);
if (rc < 0) {
/*
* ENXIO can happen if the kernel memory driver
* doesn't have the MEM_SID ioctl (e.g. if the
* kernel hasn't been patched to provide the
* support).
*
* If the MEM_SID ioctl is available but the
* particular platform doesn't support providing
* serial ids, ENOTSUP will be returned by the ioctl.
*/
return (-1);
}
}
return (0);
}
/*
* Returns 0 with serial numbers if found, -1 (with errno set) for errors. If
* the unum (or a component of same) wasn't found, -1 is returned with errno
* set to ENOENT.
*/
static int
{
int i, rc = 0;
return (-1); /* errno is set for us */
for (i = 0; i < ndimms; i++) {
break;
}
/*
* We don't have a cached copy, or the copy we've got is
* out of date. Look it up again.
*/
break;
}
}
}
if (rc == 0) {
} else {
}
return (rc);
}
/*
* Returns 0 with serial numbers if found, -1 (with errno set) for errors. If
* the unum (or a component of same) wasn't found, -1 is returned with errno
* set to ENOENT.
*/
static int
{
int i, rc = 0;
return (-1); /* errno is set for us */
/*
* first go through dimms and see if dm_drgen entries are outdated
*/
for (i = 0; i < ndimms; i++) {
break;
}
if (i < ndimms && mem_update_mdesc() != 0) {
return (-1);
}
/*
* get to this point if an up-to-date mdesc (and corresponding
* entries in the global mem list) exists
*/
for (i = 0; i < ndimms; i++) {
break;
}
/*
* mdesc and dm entry was updated by an earlier call to
* mem_update_mdesc, so we go ahead and dup the serid
*/
}
if (rc == 0) {
} else {
}
return (rc);
}
/*
* Returns 0 with part numbers if found, returns -1 for errors.
*/
static int
{
int i, rc = 0;
return (-1); /* errno is set for us */
/*
* first go through dimms and see if dm_drgen entries are outdated
*/
for (i = 0; i < ndimms; i++) {
break;
}
if (i < ndimms && mem_update_mdesc() != 0) {
return (-1);
}
/*
* get to this point if an up-to-date mdesc (and corresponding
* entries in the global mem list) exists
*/
for (i = 0; i < ndimms; i++) {
break;
}
/*
* mdesc and dm entry was updated by an earlier call to
* mem_update_mdesc, so we go ahead and dup the part
*/
rc = -1;
break;
}
}
if (rc == 0) {
} else {
}
return (rc);
}
static int
{
return (-1);
else
}
/*
* Niagara-1, Niagara-2, and Victoria Falls all have physical address
* spaces of 40 bits.
*/
#define MEM_PHYS_ADDRESS_LIMIT 0x10000000000ULL
/*
* The 'mask' argument to extract_bits has 1's in those bit positions of
* the physical address used to select the DIMM (or set of DIMMs) which will
* store the contents of the physical address. If we extract those bits, ie.
* remove them and collapse the holes, the result is the 'address' within the
* DIMM or set of DIMMs where the contents are stored.
*/
static uint64_t
{
to = 1;
to <<= 1;
}
}
return (result);
}
/*
* insert_bits is the reverse operation to extract_bits. Where extract_bits
* removes from the physical address those bits which select a DIMM or set
* of DIMMs, insert_bits reconstitutes a physical address given the DIMM
* selection 'mask' and the 'value' for the address bits denoted by 1s in
* the 'mask'.
*/
static uint64_t
{
from = 1;
from <<= 1;
} else {
}
}
return (result);
}
int
{
/*
* Some platforms do not support the caching of serial ids by the
* mem scheme plugin but instead support making serial ids available
* via the kernel.
*/
return (0);
else
}
{
size_t i;
for (i = 0; i < MAX_DIMMS_PER_BANK &&
}
}
return ((uint64_t)-1);
}
void
{
char **parts;
/*
* The following additional expansions are all optional.
* Failure to retrieve a data value, or failure to add it
* successfully to the FMRI, does NOT cause a failure of
* fmd_fmri_expand. All optional expansions will be attempted
* once expand_opt is entered.
*/
(void) nvlist_add_uint64(nvl,
}
}
} else if (nvlist_lookup_uint64(nvl,
FM_FMRI_MEM_PHYSADDR, &physaddr) == 0) {
/*
* The mask & shift values for all banks in a
* segment are always the same; only the match
* values differ, in order to specify a
* dimm-pair. But we already have a full unum.
*/
(void) (nvlist_add_uint64(nvl,
}
}
}
(void) nvlist_add_string_array(nvl,
}
}
}