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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
/*
* 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 1998 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/ddi_impldefs.h>
#include <sys/obpdefs.h>
#include <sys/cmn_err.h>
#include <sys/errno.h>
#include <sys/kmem.h>
#include <sys/debug.h>
#include <sys/sysmacros.h>
#include <sys/machsystm.h>
#include <sys/machparam.h>
#include <sys/modctl.h>
#include <sys/fhc.h>
#include <sys/ac.h>
#include <sys/vm.h>
#include <sys/cpu_module.h>
#include <vm/hat_sfmmu.h>
#include <sys/mem_config.h>
#include <sys/mem_cage.h>
extern ac_err_t ac_kpm_err_cvt(int);
#ifdef DEBUG
static void query_checker(pfn_t, pgcnt_t, memquery_t *);
static int ac_do_query_check = 0;
#endif /* DEBUG */
int
ac_mem_stat(ac_cfga_pkt_t *pkt, int flag)
{
ac_stat_t *statp;
memquery_t memq;
struct ac_mem_info *mem_info;
struct bd_list *board;
struct ac_soft_state *ac;
uint64_t decode;
uint64_t base_pa;
uint64_t bank_size;
pfn_t base;
pgcnt_t npgs;
int ret;
int retval;
/*
* Is the specified bank present?
*/
board = fhc_bdlist_lock(pkt->softsp->board);
if (board == NULL || board->ac_softsp == NULL) {
fhc_bdlist_unlock();
AC_ERR_SET(pkt, AC_ERR_BD);
return (EINVAL);
}
/* verify the board is of the correct type */
switch (board->sc.type) {
case CPU_BOARD:
case MEM_BOARD:
break;
default:
fhc_bdlist_unlock();
AC_ERR_SET(pkt, AC_ERR_BD_TYPE);
return (EINVAL);
}
ASSERT(pkt->softsp == board->ac_softsp);
ac = pkt->softsp;
mem_info = &ac->bank[pkt->bank];
statp = kmem_zalloc(sizeof (ac_stat_t), KM_SLEEP);
statp->rstate = mem_info->rstate;
statp->ostate = mem_info->ostate;
statp->condition = mem_info->condition;
statp->status_time = mem_info->status_change;
statp->board = ac->board;
statp->real_size = mem_info->real_size;
statp->use_size = mem_info->use_size;
statp->ac_memctl = *(ac->ac_memctl);
statp->ac_decode0 = *(ac->ac_memdecode0);
statp->ac_decode1 = *(ac->ac_memdecode1);
statp->page_size = PAGESIZE;
/*
* Busy could also be set for fhc_bd_busy(ac->board)
* however, this is just advisory information so limit it
* to memory operation in progress.
*/
statp->busy = (mem_info->busy != FALSE);
/*
* Determine the physical location of the selected bank
*/
decode = (pkt->bank == Bank0) ?
*(ac->ac_memdecode0) : *(ac->ac_memdecode1);
base_pa = GRP_REALBASE(decode);
bank_size = GRP_UK2SPAN(decode);
base = base_pa >> PAGESHIFT;
npgs = bank_size >> PAGESHIFT;
if (mem_info->ostate == SYSC_CFGA_OSTATE_CONFIGURED) {
bzero(&memq, sizeof (memq));
ret = kphysm_del_span_query(base, npgs, &memq);
if (ret != KPHYSM_OK) {
fhc_bdlist_unlock();
AC_ERR_SET(pkt, ac_kpm_err_cvt(ret));
retval = EINVAL;
goto out;
}
#ifdef DEBUG
if (ac_do_query_check) {
query_checker(base, npgs, &memq);
if (memq.phys_pages != npgs) {
/*
* This can happen in normal concurrent
* operation.
*/
cmn_err(CE_WARN, "ac_mem_stat(): "
"memq.phys_pages != npgs (%ld != %ld)",
(u_long)memq.phys_pages, (u_long)npgs);
}
}
#endif /* DEBUG */
statp->phys_pages = memq.phys_pages;
statp->managed = memq.managed;
if (!kcage_on)
statp->nonrelocatable = memq.phys_pages;
else
statp->nonrelocatable = memq.nonrelocatable;
} else
if (mem_info->rstate == SYSC_CFGA_RSTATE_CONNECTED) {
/* Bank is in state Spare */
statp->phys_pages = npgs;
}
fhc_bdlist_unlock();
retval = DDI_SUCCESS;
/* return the information to the user */
#ifdef _MULTI_DATAMODEL
switch (ddi_model_convert_from(flag & FMODELS)) {
case DDI_MODEL_ILP32: {
ac_stat32_t *stat32p;
stat32p = kmem_zalloc(sizeof (ac_stat32_t), KM_SLEEP);
stat32p->rstate = statp->rstate;
stat32p->ostate = statp->ostate;
stat32p->condition = statp->condition;
stat32p->status_time = (time32_t)statp->status_time;
stat32p->board = statp->board;
stat32p->real_size = statp->real_size;
stat32p->use_size = statp->use_size;
stat32p->busy = statp->busy;
stat32p->page_size = statp->page_size;
stat32p->phys_pages = statp->phys_pages;
stat32p->managed = statp->managed;
stat32p->nonrelocatable = statp->nonrelocatable;
stat32p->ac_memctl = statp->ac_memctl;
stat32p->ac_decode0 = statp->ac_decode0;
stat32p->ac_decode1 = statp->ac_decode1;
if (ddi_copyout(stat32p, pkt->cmd_cfga.private,
sizeof (ac_stat32_t), flag) != 0) {
retval = EFAULT;
}
kmem_free(stat32p, sizeof (ac_stat32_t));
break;
}
case DDI_MODEL_NONE:
if (ddi_copyout(statp, pkt->cmd_cfga.private,
sizeof (ac_stat_t), flag) != 0) {
retval = EFAULT;
}
break;
}
#else /* _MULTI_DATAMODEL */
if (ddi_copyout(statp, pkt->cmd_cfga.private,
sizeof (ac_stat_t), flag) != 0) {
retval = EFAULT;
}
#endif /* _MULTI_DATAMODEL */
out:
kmem_free(statp, sizeof (ac_stat_t));
return (retval);
}
#ifdef DEBUG
static void
query_checker(
pfn_t base,
pgcnt_t npgs,
memquery_t *mqp)
{
memquery_t memq;
memquery_t amemq;
int done_first_nonreloc;
int all_pop;
pfn_t abase;
pgcnt_t n;
int ret;
all_pop = (mqp->phys_pages == npgs);
memq.phys_pages = 0;
memq.managed = 0;
memq.nonrelocatable = 0;
memq.first_nonrelocatable = 0;
memq.last_nonrelocatable = 0;
done_first_nonreloc = 0;
for (abase = base, n = npgs; n != 0; abase++, n--) {
ret = kphysm_del_span_query(abase, 1, &amemq);
if (ret != KPHYSM_OK) {
printf("%ld: ret = %d\n", abase, ret);
continue;
}
if (all_pop && amemq.phys_pages != 1) {
printf("%ld: phys_pages = %ld, expected 1\n",
abase, amemq.phys_pages);
} else
if (amemq.phys_pages != 0 && amemq.phys_pages != 1) {
printf("%ld: phys_pages = %ld, expected 0 or 1\n",
abase, amemq.phys_pages);
}
memq.phys_pages += amemq.phys_pages;
if (amemq.managed != 0 && amemq.managed != 1) {
printf("%ld: managed = %ld, expected 0 or 1\n",
abase, amemq.managed);
}
memq.managed += amemq.managed;
if (amemq.nonrelocatable != 0 && amemq.nonrelocatable != 1) {
printf("%ld: nonrelocatable = %ld, expected 0 or 1\n",
abase, amemq.nonrelocatable);
}
memq.nonrelocatable += amemq.nonrelocatable;
if (amemq.nonrelocatable != 0) {
if (amemq.first_nonrelocatable != abase) {
printf("%ld: first_nonrelocatable = %ld\n",
abase, amemq.first_nonrelocatable);
}
if (amemq.last_nonrelocatable != abase) {
printf("%ld: last_nonrelocatable = %ld\n",
abase, amemq.last_nonrelocatable);
}
if (!done_first_nonreloc) {
memq.first_nonrelocatable = abase;
done_first_nonreloc = 1;
}
memq.last_nonrelocatable = abase;
}
}
if (mqp->phys_pages != memq.phys_pages) {
printf("query phys_pages: %ld != %ld\n",
mqp->phys_pages, memq.phys_pages);
}
if (mqp->managed != memq.managed) {
printf("query managed: %ld != %ld\n",
mqp->managed, memq.managed);
}
if (mqp->nonrelocatable != memq.nonrelocatable) {
printf("query nonrelocatable: %ld != %ld\n",
mqp->nonrelocatable, memq.nonrelocatable);
}
if (mqp->first_nonrelocatable != memq.first_nonrelocatable) {
printf("query first_nonrelocatable: %ld != %ld\n",
mqp->first_nonrelocatable, memq.first_nonrelocatable);
}
if (mqp->last_nonrelocatable != memq.last_nonrelocatable) {
printf("query last_nonrelocatable: %ld != %ld\n",
mqp->last_nonrelocatable, memq.last_nonrelocatable);
}
}
#endif /* DEBUG */
|