xref: /illumos-gate/usr/src/cmd/fm/schemes/mem/mem.h (revision e4b86885)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5b1c4bcc2Stsien  * Common Development and Distribution License (the "License").
6b1c4bcc2Stsien  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217aec1d6eScindi 
227c478bd9Sstevel@tonic-gate /*
23*d30c532dStsien  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _MEM_H
287c478bd9Sstevel@tonic-gate #define	_MEM_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
31d00f0155Sayznaga #include <sys/nvpair.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef __cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * FMRI plugin for the `mem' scheme.
397c478bd9Sstevel@tonic-gate  *
407c478bd9Sstevel@tonic-gate  * The mem scheme can be used to name individual memory modules, as well as
417c478bd9Sstevel@tonic-gate  * groups of memory modules, also known as banks.  The name `dimm' is used as a
427c478bd9Sstevel@tonic-gate  * synonym for individual memory modules, for no good reason.  Mem FMRIs can
437c478bd9Sstevel@tonic-gate  * be further refined with the addition of a member which identifies a
447c478bd9Sstevel@tonic-gate  * particular physical page within the bank or DIMM.  The named page is as
457c478bd9Sstevel@tonic-gate  * viewed by the VM system, and may thus span multiple memory modules.  It will,
467c478bd9Sstevel@tonic-gate  * however, be at least partially contained by the named bank or DIMM.
477c478bd9Sstevel@tonic-gate  *
487c478bd9Sstevel@tonic-gate  * Memory modules are identified by two things - their physical position, or
497c478bd9Sstevel@tonic-gate  * slot, in the machine, and their serial number.  DIMMs are identified by this
507c478bd9Sstevel@tonic-gate  * tuple on platforms which support the retrieval of serial numbers.  Platforms
517c478bd9Sstevel@tonic-gate  * which don't have this support rely on the slot number, with the corresponding
527c478bd9Sstevel@tonic-gate  * degradation in their ability to detect hardware changees.
537c478bd9Sstevel@tonic-gate  *
547c478bd9Sstevel@tonic-gate  * The physical location is embodied by the unum, which is highly specific to
557c478bd9Sstevel@tonic-gate  * each platform, and bears a passing resemblance to the name of the slot, as
567c478bd9Sstevel@tonic-gate  * printed on the actual hardware.  The unum is mapped to a DIMM-specific
577c478bd9Sstevel@tonic-gate  * device, which is then read to determine the serial number.  See mem_disc.c
587c478bd9Sstevel@tonic-gate  * for details of the process by which unums are mapped to devices, and
597c478bd9Sstevel@tonic-gate  * mem_read.c for the code which actually retrieves the serial number from the
607c478bd9Sstevel@tonic-gate  * device.
617c478bd9Sstevel@tonic-gate  *
627c478bd9Sstevel@tonic-gate  * Banks are also identified by unums, which must be broken apart into the
637c478bd9Sstevel@tonic-gate  * unums which identify each constituent memory module.  Serial numbers are
647c478bd9Sstevel@tonic-gate  * retrieved for banks - one per member module - in the same way as for
657c478bd9Sstevel@tonic-gate  * individual modules.  See mem_unum.c for the code which bursts bank unums.
667c478bd9Sstevel@tonic-gate  *
677c478bd9Sstevel@tonic-gate  * Serial number retrieval, on platforms which support it, is very expensive
687c478bd9Sstevel@tonic-gate  * (on the order of several tenths of a second, which adds up in a hurry on
697c478bd9Sstevel@tonic-gate  * larger machines).  So, while we pre-generate the list of DIMM device paths,
707c478bd9Sstevel@tonic-gate  * we only read their serial numbers when requested by plugin consumers.  To
717c478bd9Sstevel@tonic-gate  * further reduce the perceived cost, we don't re-read until/unless we detect
727c478bd9Sstevel@tonic-gate  * that a DR operation has taken place.
737c478bd9Sstevel@tonic-gate  *
747c478bd9Sstevel@tonic-gate  * Using the facilities described above, the plugin implements the following
757c478bd9Sstevel@tonic-gate  * entry points: (see mem.c)
767c478bd9Sstevel@tonic-gate  *
777c478bd9Sstevel@tonic-gate  *   - nvl2str: The printed representation of the named bank or DIMM is
787c478bd9Sstevel@tonic-gate  *     generated.  No attempt is made to determine whether or not the named
797c478bd9Sstevel@tonic-gate  *     item is still present in the system.
807c478bd9Sstevel@tonic-gate  *
81fbd1c0daSsd77468  *   - expand: For platforms which do not include bank or DIMM
82fbd1c0daSsd77468  *     serial numbers in their ereports, this entry point will read the
837c478bd9Sstevel@tonic-gate  *     serial number(s) for the named item, and will add it/them to the passed
847c478bd9Sstevel@tonic-gate  *     FMRI.  Errors will be returned if the FMRI (unum) was unparseable, or if
857c478bd9Sstevel@tonic-gate  *     the serial number could not be retrieved.
867c478bd9Sstevel@tonic-gate  *
877c478bd9Sstevel@tonic-gate  *   - present: Given a mem-schemed FMRI with a serial number, this entry
887c478bd9Sstevel@tonic-gate  *     point will attempt to determine whether the bank or module named in the
897c478bd9Sstevel@tonic-gate  *     FMRI is still present in the system at the same location.  Programmer
907c478bd9Sstevel@tonic-gate  *     errors (invalid FMRIs) will be signalled to the caller.  Warnings will
917c478bd9Sstevel@tonic-gate  *     be emitted for otherwise-valid FMRIs whose serial numbers could not be
927c478bd9Sstevel@tonic-gate  *     read, with the caller told that the FMRI is not present.
937c478bd9Sstevel@tonic-gate  *
947c478bd9Sstevel@tonic-gate  *   - contains: Used to determine whether a given bank contains a given DIMM.
957c478bd9Sstevel@tonic-gate  *     No attempt is made to determine whether the module named by the FMRIs are
967c478bd9Sstevel@tonic-gate  *     actually present in the system.  Programmer errors (invalidd FMRIs) will
977c478bd9Sstevel@tonic-gate  *     be returned to the caller.  Warnings will be emitted for otherwise-valid
987c478bd9Sstevel@tonic-gate  *     FMRIs whose relationship could not be determined, with the caller told
997c478bd9Sstevel@tonic-gate  *     that there is no relationship.
1007c478bd9Sstevel@tonic-gate  */
1017c478bd9Sstevel@tonic-gate 
1020cc8ae86Sav145390 /*
1030cc8ae86Sav145390  * 18+nul for SPD, 6+nul for SEEPROM, 15+nul max for Serengeti, Starcat, LW8.
1040cc8ae86Sav145390  * 18 for Sun Partnumber, 18 partner partnumber, 12 serialnumber for OPL.
1050cc8ae86Sav145390  */
1060cc8ae86Sav145390 #define	MEM_SERID_MAXLEN	64
107*d30c532dStsien #define	MAX_DIMMS_PER_BANK	4
108fbd1c0daSsd77468 
1097c478bd9Sstevel@tonic-gate typedef struct mem_dimm_map {
1107c478bd9Sstevel@tonic-gate 	struct mem_dimm_map *dm_next;	/* The next DIMM map */
1117c478bd9Sstevel@tonic-gate 	char *dm_label;			/* The UNUM for this DIMM */
1127c478bd9Sstevel@tonic-gate 	char *dm_device;		/* Path to I2C device for DIMM */
1137c478bd9Sstevel@tonic-gate 	char dm_serid[MEM_SERID_MAXLEN]; /* Cached serial number */
11414ea4bb7Ssd77468 	char *dm_part;			/* DIMM part number */
1157c478bd9Sstevel@tonic-gate 	uint64_t dm_drgen;		/* DR gen count for cached S/N */
1167c478bd9Sstevel@tonic-gate } mem_dimm_map_t;
1177c478bd9Sstevel@tonic-gate 
118*d30c532dStsien typedef struct mem_bank_map {
119*d30c532dStsien 	struct mem_bank_map *bm_next;	/* the next bank map overall */
120*d30c532dStsien 	struct mem_bank_map *bm_grp;	/* next bank map in group */
121*d30c532dStsien 	uint64_t	bm_mask;
122*d30c532dStsien 	uint64_t	bm_match;
123*d30c532dStsien 	uint16_t	bm_shift;	/* dimms-per-reference shift */
124*d30c532dStsien 	mem_dimm_map_t *bm_dimm[MAX_DIMMS_PER_BANK];
125*d30c532dStsien } mem_bank_map_t;
126*d30c532dStsien 
127*d30c532dStsien typedef struct mem_grp {
128*d30c532dStsien 	struct mem_grp *mg_next;
129*d30c532dStsien 	size_t		mg_size;
130*d30c532dStsien 	mem_bank_map_t *mg_bank;
131*d30c532dStsien } mem_grp_t;
132*d30c532dStsien 
133*d30c532dStsien typedef struct mem_seg_map {
134*d30c532dStsien 	struct mem_seg_map *sm_next;	/* the next segment map */
135*d30c532dStsien 	uint64_t	sm_base;	/* base address for this segment */
136*d30c532dStsien 	uint64_t	sm_size;	/* size for this segment */
137*d30c532dStsien 	mem_grp_t	*sm_grp;
138*d30c532dStsien } mem_seg_map_t;
139*d30c532dStsien 
140*d30c532dStsien 
1417c478bd9Sstevel@tonic-gate typedef struct mem {
1427c478bd9Sstevel@tonic-gate 	mem_dimm_map_t *mem_dm;		/* List supported DIMMs */
143822fb41dStsien 	uint64_t mem_memconfig;		/* HV memory-configuration-id# */
144fbd1c0daSsd77468 	mem_seg_map_t *mem_seg;		/* list of defined segments */
145*d30c532dStsien 	mem_bank_map_t *mem_bank;
146*d30c532dStsien 	mem_grp_t *mem_group;		/* groups of banks for a segment */
1477c478bd9Sstevel@tonic-gate } mem_t;
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate extern int mem_discover(void);
1507c478bd9Sstevel@tonic-gate extern int mem_get_serid(const char *, char *, size_t);
151fbd1c0daSsd77468 extern int mem_get_serids_by_unum(const char *, char ***, size_t *);
152fbd1c0daSsd77468 extern void mem_expand_opt(nvlist_t *, char *, char **);
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate extern int mem_unum_burst(const char *, char ***, size_t *);
1557c478bd9Sstevel@tonic-gate extern int mem_unum_contains(const char *, const char *);
1567aec1d6eScindi extern int mem_unum_rewrite(nvlist_t *, nvlist_t **);
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate extern void mem_strarray_free(char **, size_t);
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate extern mem_t mem;
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate #endif
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate #endif /* _MEM_H */
167