summaryrefslogtreecommitdiff
path: root/usr/src/cmd/fm/modules/sun4v/generic-mem/gmem_state.h
blob: 0f284a474ab6402ce1655e7853880a577b7aed40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * 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
 * or http://www.opensolaris.org/os/licensing.
 * 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.
 */

#ifndef _GMEM_STATE_H
#define	_GMEM_STATE_H

/*
 * Case management and saved state restoration
 */

#include <gmem_util.h>

#include <fm/fmd_api.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Our maximum persistent buffer name length, used to allocate fixed-size
 * arrays for name storage.
 */
/*
 * The current name DIMM_+serial number
 */
#define	GMEM_BUFNMLEN		48

/* gmem_evdisp_t, gmem_evdisp_stat_t, and gmem_evdisp_names must be in sync */
typedef enum gmem_evdisp {
	GMEM_EVD_OK,
	GMEM_EVD_BAD,
	GMEM_EVD_UNUSED,
	GMEM_EVD_REDUND
} gmem_evdisp_t;

/*
 * Each handled ereport type has four statistics, designed to indicate the
 * eventual disposition of the ereport.
 */
typedef struct gmem_evdisp_stat {
	fmd_stat_t evs_ok;		/* # of erpts processed successfully */
	fmd_stat_t evs_bad;		/* # of malformed ereports */
	fmd_stat_t evs_unused;		/* # of erpts unusable or not needed */
	fmd_stat_t evs_redund;		/* # of erpts already explained */
} gmem_evdisp_stat_t;

/* Must be in sync with gmem_case_restorers */
typedef enum gmem_nodetype {
	GMEM_NT_DIMM = 1,
	GMEM_NT_PAGE
} gmem_nodetype_t;

/*
 * Must be in sync with gmem_case_closers.  Additional types must be
 * appended to this enum otherwise interpretation of existing logs
 * and checkpoints will be confused.
 */
typedef enum gmem_ptrsubtype {
	GMEM_PTR_DIMM_CASE = 1,
	GMEM_PTR_PAGE_CASE
} gmem_ptrsubtype_t;

/*
 * There are three types of general-purpose buffers, used to track DIMMs,
 * and pages.  Created on-demand as ereports arrive, one buffer is created for
 * each thing tracked.  The general-purpose buffers are used to track common
 * state, and are used to support case-specific buffers.  Each open case has
 * a case-specific pointer buffer, used to aid in the rediscovery of the
 * associated general-purpose buffer.  When restoration begins, we iterate
 * through each of the open cases, restoring the case-specific pointer buffers
 * for each.  The pointer buffers are then used to restore the general-purpose
 * buffers.
 */

typedef	struct gmem_case_ptr {
	gmem_nodetype_t ptr_type;	/* The type of associated G.P. buffer */
	gmem_ptrsubtype_t ptr_subtype;	/* The case within the G.P. buffer */
	char ptr_name[GMEM_BUFNMLEN];	/* G.P. buffer name */
} gmem_case_ptr_t;

/*
 * All general-purpose buffers begin with a common header.  This header contains
 * identification information used in the construction of new cases.
 *
 * Note that versioned structs depend upon the size of
 * this struct remaining fixed.
 */
typedef struct gmem_header {
	gmem_list_t hdr_list;		/* List of G.P. structs of this type */
	gmem_nodetype_t hdr_nodetype;	/* Type of this G.P. struct */
	char hdr_bufname[GMEM_BUFNMLEN]; /* G.P. buffer name */
} gmem_header_t;

/*
 * Per-case-subtype case closing routines.  Stored in per-case state when the
 * case is generated, and regenerated from saved state upon restore.
 */
typedef void gmem_case_closer_f(fmd_hdl_t *, void *);
typedef void *gmem_case_restorer_f(fmd_hdl_t *, fmd_case_t *,
    gmem_case_ptr_t *);

typedef struct gmem_case_closer {
	gmem_case_closer_f *cl_func;
	void *cl_arg;
} gmem_case_closer_t;

typedef struct gmem_case {
	fmd_case_t *cc_cp;
	char *cc_serdnm;
} gmem_case_t;

/*
 * Utility functions which ease the management of cases.
 */
extern fmd_case_t *gmem_case_create(fmd_hdl_t *, gmem_header_t *,
    gmem_ptrsubtype_t, const char **);
extern void gmem_case_redirect(fmd_hdl_t *, fmd_case_t *, gmem_ptrsubtype_t);
extern void gmem_case_fini(fmd_hdl_t *, fmd_case_t *, int);
extern void gmem_case_restore(fmd_hdl_t *, gmem_case_t *, fmd_case_t *, char *);

extern int gmem_state_restore(fmd_hdl_t *);

#ifdef __cplusplus
}
#endif

#endif /* _GMEM_STATE_H */