Print this page
patch tsoome-feedback
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/fm/libfmd_agent/i386/fmd_agent_i386.c
+++ new/usr/src/lib/fm/libfmd_agent/i386/fmd_agent_i386.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 #include <stdlib.h>
28 28 #include <errno.h>
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
29 29 #include <sys/types.h>
30 30 #include <libnvpair.h>
31 31 #include <sys/fcntl.h>
32 32 #include <sys/devfm.h>
33 33 #include <fmd_agent_impl.h>
34 34
35 35 static int
36 36 cleanup_set_errno(fmd_agent_hdl_t *hdl, nvlist_t *innvl, nvlist_t *outnvl,
37 37 int err)
38 38 {
39 - if (innvl != NULL)
40 - nvlist_free(innvl);
41 - if (outnvl != NULL)
42 - nvlist_free(outnvl);
39 + nvlist_free(innvl);
40 + nvlist_free(outnvl);
43 41 return (fmd_agent_seterrno(hdl, err));
44 42 }
45 43
46 44 static int
47 45 fmd_agent_physcpu_info_v1(fmd_agent_hdl_t *hdl, nvlist_t ***cpusp,
48 46 uint_t *ncpup)
49 47 {
50 48 int err;
51 49 nvlist_t *nvl, **nvl_array, **cpus;
52 50 uint_t i, n;
53 51
54 52 if ((err = fmd_agent_nvl_ioctl(hdl, FM_IOC_PHYSCPU_INFO, 1,
55 53 NULL, &nvl)) != 0)
56 54 return (cleanup_set_errno(hdl, NULL, NULL, err));
57 55 if ((err = nvlist_lookup_nvlist_array(nvl, FM_PHYSCPU_INFO_CPUS,
58 56 &cpus, &n)) != 0)
59 57 return (cleanup_set_errno(hdl, NULL, nvl, err));
60 58
61 59 if ((nvl_array = umem_alloc(sizeof (nvlist_t *) * n, UMEM_DEFAULT))
62 60 == NULL)
63 61 return (cleanup_set_errno(hdl, NULL, nvl, errno));
64 62 for (i = 0; i < n; i++) {
65 63 if ((err = nvlist_dup(cpus[i], nvl_array + i, 0)) != 0) {
66 64 while (i > 0)
67 65 nvlist_free(nvl_array[--i]);
68 66 umem_free(nvl_array, sizeof (nvlist_t *) * n);
69 67 return (cleanup_set_errno(hdl, NULL, nvl, err));
70 68 }
71 69 }
72 70
73 71 nvlist_free(nvl);
74 72 *cpusp = nvl_array;
75 73 *ncpup = n;
76 74 return (0);
77 75 }
78 76
79 77 int
80 78 fmd_agent_physcpu_info(fmd_agent_hdl_t *hdl, nvlist_t ***cpusp, uint_t *ncpu)
81 79 {
82 80 uint32_t ver;
83 81
84 82 if (fmd_agent_version(hdl, FM_CPU_INFO_VERSION, &ver) == -1)
85 83 return (fmd_agent_seterrno(hdl, errno));
86 84
87 85 switch (ver) {
88 86 case 1:
89 87 return (fmd_agent_physcpu_info_v1(hdl, cpusp, ncpu));
90 88
91 89 default:
92 90 return (fmd_agent_seterrno(hdl, ENOTSUP));
93 91 }
94 92 }
95 93
96 94 static int
97 95 fmd_agent_cpuop_v1(fmd_agent_hdl_t *hdl, int cmd, int chipid, int coreid,
98 96 int strandid, int *old_status)
99 97 {
100 98 int err;
101 99 nvlist_t *nvl = NULL, *outnvl = NULL;
102 100 int32_t status;
103 101
104 102 if ((err = nvlist_alloc(&nvl, NV_UNIQUE_NAME_TYPE, 0)) != 0 ||
105 103 (err = nvlist_add_int32(nvl, FM_CPU_RETIRE_CHIP_ID, chipid)) != 0 ||
106 104 (err = nvlist_add_int32(nvl, FM_CPU_RETIRE_CORE_ID, coreid)) != 0 ||
107 105 (err = nvlist_add_int32(nvl, FM_CPU_RETIRE_STRAND_ID, strandid))
108 106 != 0 || (err = fmd_agent_nvl_ioctl(hdl, cmd, 1, nvl, &outnvl)) != 0)
109 107 return (cleanup_set_errno(hdl, nvl, NULL, err));
110 108
111 109 nvlist_free(nvl);
112 110 if (outnvl != NULL) {
113 111 if (old_status != NULL) {
114 112 (void) nvlist_lookup_int32(outnvl,
115 113 FM_CPU_RETIRE_OLDSTATUS, &status);
116 114 *old_status = status;
117 115 }
118 116 nvlist_free(outnvl);
119 117 }
120 118
121 119 return (0);
122 120 }
123 121
124 122 static int
125 123 fmd_agent_cpuop(fmd_agent_hdl_t *hdl, int cmd, int chipid, int coreid,
126 124 int strandid, int *old_status)
127 125 {
128 126 uint32_t ver;
129 127
130 128 if (fmd_agent_version(hdl, FM_CPU_OP_VERSION, &ver) == -1)
131 129 return (cleanup_set_errno(hdl, NULL, NULL, errno));
132 130
133 131 switch (ver) {
134 132 case 1:
135 133 return (fmd_agent_cpuop_v1(hdl, cmd, chipid, coreid, strandid,
136 134 old_status));
137 135
138 136 default:
139 137 return (fmd_agent_seterrno(hdl, ENOTSUP));
140 138 }
141 139 }
142 140
143 141 int
144 142 fmd_agent_cpu_retire(fmd_agent_hdl_t *hdl, int chipid, int coreid, int strandid)
145 143 {
146 144 int ret;
147 145
148 146 ret = fmd_agent_cpuop(hdl, FM_IOC_CPU_RETIRE, chipid, coreid, strandid,
149 147 NULL);
150 148
151 149 return (ret == 0 ? FMD_AGENT_RETIRE_DONE : FMD_AGENT_RETIRE_FAIL);
152 150 }
153 151
154 152 int
155 153 fmd_agent_cpu_isretired(fmd_agent_hdl_t *hdl, int chipid, int coreid,
156 154 int strandid)
157 155 {
158 156 int ret, status;
159 157
160 158 ret = fmd_agent_cpuop(hdl, FM_IOC_CPU_STATUS, chipid, coreid, strandid,
161 159 &status);
162 160
163 161 return (ret == 0 && status != P_ONLINE ?
164 162 FMD_AGENT_RETIRE_DONE : FMD_AGENT_RETIRE_FAIL);
165 163 }
166 164
167 165 int
168 166 fmd_agent_cpu_unretire(fmd_agent_hdl_t *hdl, int chipid, int coreid,
169 167 int strandid)
170 168 {
171 169 int ret;
172 170
173 171 ret = fmd_agent_cpuop(hdl, FM_IOC_CPU_UNRETIRE, chipid, coreid,
174 172 strandid, NULL);
175 173
176 174 return (ret == 0 ? FMD_AGENT_RETIRE_DONE : FMD_AGENT_RETIRE_FAIL);
177 175 }
↓ open down ↓ |
125 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX