Print this page
PSARC 2009/104 Hot-Plug Support for ACPI-based Systems
6846955 Device tree creation and acpi virtual nexus driver for acpi based x86 systems
6849408 device match rule in ppm.conf is not flexible
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/io/ppm/ppm_subr.c
+++ new/usr/src/uts/common/io/ppm/ppm_subr.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.
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
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 - * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
22 + * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 -#pragma ident "%Z%%M% %I% %E% SMI"
27 -
28 26 /*
29 27 * ppm driver subroutines
30 28 */
31 29
32 30 #include <sys/open.h>
33 31 #include <sys/file.h>
34 32 #include <sys/conf.h>
35 33 #include <sys/epm.h>
36 34 #include <sys/sunldi.h>
37 35 #include <sys/ppmvar.h>
38 36 #include <sys/ppmio.h>
39 37 #include <sys/promif.h>
40 38 #include <sys/ddi_impldefs.h>
41 39 #include <sys/ddi.h>
42 40 #include <sys/sunddi.h>
43 41 /*
44 42 * Append address to the device path, if it is set. Routine
45 43 * ddi_pathname does not look for device address if the node is in
46 44 * DS_INITIALIZED state.
47 45 */
48 46 #define PPM_GET_PATHNAME(dip, path) \
49 47 (void) ddi_pathname((dip), (path)); \
50 48 if ((i_ddi_node_state((dip)) < DS_INITIALIZED) && \
51 49 (ddi_get_name_addr((dip)) != NULL)) { \
52 50 (void) strcat((path), "@"); \
53 51 (void) strcat((path), ddi_get_name_addr((dip)));\
54 52 }
55 53
56 54 int ppm_parse_dc(char **, ppm_dc_t *);
57 55 int ppm_match_devs(char *, ppm_db_t *);
58 56 ppm_db_t *ppm_parse_pattern(struct ppm_db **, char *);
59 57 int ppm_count_char(char *, char);
60 58 int ppm_stoi(char *, uint_t *);
61 59 int ppm_convert(char *, uint_t *);
62 60 void ppm_prop_free(struct ppm_cdata **);
63 61
64 62 /*
65 63 * lookup string property from configuration file ppm.conf
66 64 */
67 65 static int
68 66 ppm_get_confdata(struct ppm_cdata **cdp, dev_info_t *dip)
69 67 {
70 68 #ifdef DEBUG
71 69 char *str = "ppm_get_confdata";
72 70 #endif
73 71 struct ppm_cdata *cinfo;
74 72 int err;
75 73
76 74 for (; (cinfo = *cdp) != NULL; cdp++) {
77 75 err = ddi_prop_lookup_string_array(
78 76 DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
79 77 cinfo->name, &cinfo->strings, &cinfo->cnt);
80 78 if (err != DDI_PROP_SUCCESS) {
81 79 PPMD(D_ERROR, ("%s: no %s found, err(%d)\n",
82 80 str, cinfo->name, err))
83 81 break;
84 82 }
85 83 }
86 84 return (err);
87 85 }
88 86
89 87 void
90 88 ppm_prop_free(struct ppm_cdata **cdp)
91 89 {
92 90 if (cdp) {
93 91 for (; *cdp; cdp++) {
94 92 if ((*cdp)->name) {
95 93 kmem_free((*cdp)->name,
96 94 strlen((*cdp)->name) + 1);
97 95 (*cdp)->name = NULL;
98 96 }
99 97 if ((*cdp)->strings) {
100 98 ddi_prop_free((*cdp)->strings);
101 99 (*cdp)->strings = NULL;
102 100 }
103 101 }
104 102 }
105 103 }
106 104
107 105
108 106 /*
109 107 * free ddi prop strings. Under error condition, free ppm_db_t lists as well.
110 108 */
111 109 static int
112 110 ppm_attach_err(struct ppm_cdata **cdp, int err)
113 111 {
114 112 ppm_domain_t *domp;
115 113 ppm_db_t *db, *tmp;
116 114
117 115 ppm_prop_free(cdp);
118 116 if (err != DDI_SUCCESS) {
119 117 for (domp = ppm_domain_p; domp; domp = domp->next) {
120 118 for (db = domp->conflist; (tmp = db) != NULL; ) {
121 119 db = db->next;
122 120 kmem_free(tmp->name, strlen(tmp->name) + 1);
123 121 kmem_free(tmp, sizeof (*tmp));
124 122 }
125 123 domp->conflist = NULL;
126 124 }
127 125 err = DDI_FAILURE;
128 126 }
129 127
130 128 return (err);
131 129 }
132 130
133 131
134 132 ppm_domain_t *
135 133 ppm_lookup_domain(char *dname)
136 134 {
137 135 ppm_domain_t *domp;
138 136
139 137 for (domp = ppm_domain_p; domp; domp = domp->next) {
140 138 if (strcmp(dname, domp->name) == 0)
141 139 break;
142 140 }
143 141 return (domp);
144 142 }
145 143
146 144
147 145 /*
148 146 * for the purpose of optimizing we search for identical dc->path
149 147 * that has been opened per previous visit here. If search results
150 148 * in a hit, copy the device handle, else open the device.
151 149 */
152 150 ppm_dc_t *
153 151 ppm_lookup_hndl(int model, ppm_dc_t *key_dc)
154 152 {
155 153 #ifdef DEBUG
156 154 char *str = "ppm_lookup_hndl";
157 155 #endif
158 156 char *key_path = key_dc->path;
159 157 ppm_domain_t *domp;
160 158 ppm_dc_t *dc;
161 159
162 160 /* search domain by domain.model */
163 161 for (domp = ppm_domain_p; domp; domp = domp->next) {
164 162 if (domp->model == model)
165 163 break;
166 164 }
167 165
168 166 /* lookup hndl from same domain model */
169 167 if (domp && PPM_DOMAIN_UP(domp)) {
170 168 for (dc = domp->dc; dc; dc = dc->next) {
171 169 if ((strcmp(dc->path, key_path) == 0) &&
172 170 (dc->lh != NULL)) {
173 171 PPMD(D_PPMDC, ("%s: Hit(dc_path:%s) from SAME "
174 172 "domain %s.\n", str, key_path, domp->name))
175 173 key_dc->lh = dc->lh;
176 174 return (key_dc);
177 175 }
178 176 }
179 177 }
180 178
181 179 /* otherwise, check other domains */
182 180 for (domp = ppm_domain_p;
183 181 domp && (domp->model != model); domp = domp->next) {
184 182 if (PPM_DOMAIN_UP(domp)) {
185 183 for (dc = domp->dc; dc; dc = dc->next) {
186 184 if ((strcmp(dc->path, key_path) == 0) &&
187 185 (dc->lh != NULL)) {
188 186 PPMD(D_PPMDC, ("%s: Hit(dc_path:%s) "
189 187 "from domain %s\n",
190 188 str, key_path, domp->name))
191 189 key_dc->lh = dc->lh;
192 190 return (key_dc);
193 191 }
194 192 }
195 193 }
196 194 }
197 195
198 196 PPMD(D_PPMDC, ("%s: Miss(dc_path:%s)\n", str, key_path))
199 197 return (NULL);
200 198 }
201 199
202 200
203 201 #define PPM_DOMAIN_PROP "ppm-domains"
204 202 #define PPM_DEV_PROP_SUFFIX "-devices"
205 203 #define PPM_MODEL_PROP_SUFFIX "-model"
206 204 #define PPM_PROPNAME_PROP_SUFFIX "-propname"
207 205 #define PPM_CTRL_PROP_SUFFIX "-control"
208 206
209 207 struct ppm_domit ppm_domit_data[] = {
210 208 "SX", PPMD_SX, 0, PPMD_ON,
211 209 "CPU", PPMD_CPU, PPMD_LOCK_ALL, PPMD_ON,
212 210 "FET", PPMD_FET, PPMD_LOCK_ONE, PPMD_ON,
213 211 "PCI", PPMD_PCI, PPMD_LOCK_ONE, PPMD_ON,
214 212 "PCI_PROP", PPMD_PCI_PROP, PPMD_LOCK_ONE, PPMD_ON,
215 213 "LED", PPMD_LED, 0, PPMD_ON,
216 214 "PCIE", PPMD_PCIE, PPMD_LOCK_ONE, PPMD_ON,
217 215 NULL
218 216 };
219 217
220 218 /*
221 219 * store up platform dependent information provided by ppm.conf file
222 220 * into private data base
223 221 */
224 222 int
225 223 ppm_create_db(dev_info_t *dip)
226 224 {
227 225 #ifdef DEBUG
228 226 char *str = "ppm_create_db";
229 227 #endif
230 228 ppm_domain_t *domp;
231 229 ppm_db_t *db;
232 230 ppm_dc_t *dc;
233 231 struct ppm_cdata domdata; /* hold "ppm-domains" property */
234 232 struct ppm_cdata modeldata; /* hold "domain_xy-model" property */
235 233 struct ppm_cdata propnamedata; /* hold "domain_xy-propname" property */
236 234 struct ppm_cdata devdata; /* hold "domain_xy-devices" property */
237 235 struct ppm_cdata dcdata; /* hold "domain_xy-control" property */
238 236 struct ppm_cdata *cdata[2];
239 237 char **dom_namep, **model_namep, **dev_namep, **dc_namep;
240 238 struct ppm_domit *domit_p;
241 239 int err;
242 240
243 241 /*
244 242 * get "ppm-domains" property
245 243 */
246 244 bzero(&domdata, sizeof (domdata));
247 245 domdata.name = kmem_zalloc(strlen(PPM_DOMAIN_PROP) + 1, KM_SLEEP);
248 246 (void) strcpy(domdata.name, PPM_DOMAIN_PROP);
249 247 cdata[0] = &domdata;
250 248 cdata[1] = NULL;
251 249 if (err = ppm_get_confdata(cdata, dip)) {
252 250 PPMD(D_CREATEDB, ("%s: failed to get prop \"%s\"!\n",
253 251 str, PPM_DOMAIN_PROP))
254 252 return (ppm_attach_err(cdata, err));
255 253 }
256 254
257 255 for (dom_namep = domdata.strings; *dom_namep; dom_namep++) {
258 256 domp = kmem_zalloc(sizeof (*domp), KM_SLEEP);
259 257 domp->name = kmem_zalloc(strlen(*dom_namep) + 1, KM_SLEEP);
260 258 (void) strcpy(domp->name, *dom_namep);
261 259 mutex_init(&domp->lock, NULL, MUTEX_DRIVER, NULL);
262 260 if (ppm_domain_p == NULL)
263 261 ppm_domain_p = domp;
264 262 else {
265 263 domp->next = ppm_domain_p;
266 264 ppm_domain_p = domp;
267 265 }
268 266 }
269 267 ppm_prop_free(cdata);
270 268
271 269 /*
272 270 * more per domain property strings in ppm.conf file tell us
273 271 * what the nature of domain, how to performe domain control, etc.
274 272 * Even the property names of those per domain properties are
275 273 * formed consisting its domain name string.
276 274 * Here we walk through our domain list, and fullfill the details.
277 275 */
278 276 for (domp = ppm_domain_p; domp; domp = domp->next) {
279 277 size_t plen;
280 278
281 279 /*
282 280 * get "domain_xy-model" property
283 281 */
284 282 bzero(&modeldata, sizeof (modeldata));
285 283 plen = strlen(domp->name) + strlen(PPM_MODEL_PROP_SUFFIX) + 1;
286 284 modeldata.name = kmem_zalloc(plen, KM_SLEEP);
287 285 (void) sprintf(modeldata.name, "%s%s",
288 286 domp->name, PPM_MODEL_PROP_SUFFIX);
289 287
290 288 cdata[0] = &modeldata;
291 289 cdata[1] = NULL;
292 290 if (err = ppm_get_confdata(cdata, dip)) {
293 291 PPMD(D_CREATEDB, ("%s: Can't read property %s!\n",
294 292 str, modeldata.name))
295 293 return (ppm_attach_err(cdata, err));
296 294 }
297 295
298 296 model_namep = modeldata.strings;
299 297 for (domit_p = ppm_domit_data; domit_p->name; domit_p++) {
300 298 if (strcmp(domit_p->name, *model_namep) == 0) {
301 299 domp->model = domit_p->model;
302 300 domp->dflags = domit_p->dflags;
303 301 domp->status = domit_p->status;
304 302 break;
305 303 }
306 304 }
307 305 ASSERT(domit_p);
308 306
309 307 ppm_prop_free(cdata);
310 308
311 309
312 310 /* get "domain_xy-propname" property */
313 311 bzero(&propnamedata, sizeof (propnamedata));
314 312 plen = strlen(domp->name) +
315 313 strlen(PPM_PROPNAME_PROP_SUFFIX) + 1;
316 314 propnamedata.name = kmem_zalloc(plen, KM_SLEEP);
317 315 (void) sprintf(propnamedata.name, "%s%s",
318 316 domp->name, PPM_PROPNAME_PROP_SUFFIX);
319 317
320 318 cdata[0] = &propnamedata;
321 319 cdata[1] = NULL;
322 320 if (ppm_get_confdata(cdata, dip) == DDI_PROP_SUCCESS) {
323 321 domp->propname = kmem_zalloc(
324 322 (strlen(*propnamedata.strings) + 1), KM_SLEEP);
325 323 (void) strcpy(domp->propname, *propnamedata.strings);
326 324 PPMD(D_CREATEDB, ("%s: %s has property name: %s\n",
327 325 str, domp->name, domp->propname))
328 326 }
329 327 ppm_prop_free(cdata);
330 328
331 329
332 330 /* get "domain_xy-devices" property */
333 331 bzero(&devdata, sizeof (devdata));
334 332 plen = strlen(domp->name) + strlen(PPM_DEV_PROP_SUFFIX) + 1;
335 333 devdata.name = kmem_zalloc(plen, KM_SLEEP);
336 334 (void) sprintf(devdata.name, "%s%s",
337 335 domp->name, PPM_DEV_PROP_SUFFIX);
338 336
339 337 cdata[0] = &devdata;
340 338 cdata[1] = NULL;
341 339 if (err = ppm_get_confdata(cdata, dip)) {
342 340 PPMD(D_CREATEDB, ("%s: Can't read property %s!\n",
343 341 str, devdata.name))
344 342 return (ppm_attach_err(cdata, err));
345 343 }
346 344
347 345 for (dev_namep = devdata.strings; *dev_namep; dev_namep++) {
348 346 if (!ppm_parse_pattern(&db, *dev_namep))
349 347 return (ppm_attach_err(cdata, err));
350 348 db->next = domp->conflist;
351 349 domp->conflist = db;
352 350 PPMD(D_CREATEDB, ("%s: %s add pattern: %s \n",
353 351 str, devdata.name, db->name))
354 352 }
355 353 PPMD(D_CREATEDB, ("\n"))
356 354 ppm_prop_free(cdata);
357 355
358 356
359 357 /* get "domain_xy-control" property */
360 358 bzero(&dcdata, sizeof (dcdata));
361 359 plen = strlen(domp->name) + strlen(PPM_CTRL_PROP_SUFFIX) + 1;
362 360 dcdata.name = kmem_zalloc(plen, KM_SLEEP);
363 361 (void) sprintf(dcdata.name, "%s%s",
364 362 domp->name, PPM_CTRL_PROP_SUFFIX);
365 363
366 364 cdata[0] = &dcdata;
367 365 cdata[1] = NULL;
368 366 if (ppm_get_confdata(cdata, dip) == DDI_PROP_SUCCESS) {
369 367 for (dc_namep = dcdata.strings; *dc_namep;
370 368 dc_namep++) {
371 369 dc = kmem_zalloc(sizeof (*dc), KM_SLEEP);
372 370 dc->next = domp->dc;
373 371 domp->dc = dc;
374 372 err = ppm_parse_dc(dc_namep, domp->dc);
375 373 if (err != DDI_SUCCESS)
376 374 return (ppm_attach_err(cdata, err));
377 375 }
378 376 }
379 377 ppm_prop_free(cdata);
380 378 #ifdef DEBUG
381 379 dc = domp->dc;
382 380 while (dc) {
383 381 ppm_print_dc(dc);
384 382 dc = dc->next;
385 383 }
386 384 #endif
387 385 }
388 386
389 387 return (DDI_SUCCESS);
390 388 }
391 389
|
↓ open down ↓ |
354 lines elided |
↑ open up ↑ |
392 390
393 391 /*
394 392 * scan conf devices within each domain for a matching device name
395 393 */
396 394 ppm_domain_t *
397 395 ppm_lookup_dev(dev_info_t *dip)
398 396 {
399 397 char path[MAXNAMELEN];
400 398 ppm_domain_t *domp;
401 399 ppm_db_t *dbp;
400 +#ifdef __x86
401 + char *devtype = NULL;
402 +#endif /* __x86 */
402 403
403 404 PPM_GET_PATHNAME(dip, path);
404 405 for (domp = ppm_domain_p; domp; domp = domp->next) {
405 406 if (PPM_DOMAIN_UP(domp)) {
406 407 for (dbp = domp->conflist; dbp; dbp = dbp->next) {
407 408 /*
408 409 * allow claiming root without knowing
409 410 * its full name
410 411 */
411 412 if (dip == ddi_root_node() &&
412 413 strcmp(dbp->name, "/") == 0)
413 414 return (domp);
415 +
416 +#ifdef __x86
417 + /*
418 + * Special rule to catch all CPU devices on x86.
419 + */
420 + if (domp->model == PPMD_CPU &&
421 + strcmp(dbp->name, "/") == 0 &&
422 + ddi_prop_lookup_string(DDI_DEV_T_ANY, dip,
423 + DDI_PROP_DONTPASS, "device_type",
424 + &devtype) == DDI_SUCCESS) {
425 + if (strcmp(devtype, "cpu") == 0) {
426 + ddi_prop_free(devtype);
427 + return (domp);
428 + } else {
429 + ddi_prop_free(devtype);
430 + }
431 + }
432 +#endif /* __x86 */
433 +
414 434 if (ppm_match_devs(path, dbp) == 0)
415 435 return (domp);
416 436 }
417 437 }
418 438 }
419 439
420 440 return (NULL);
421 441 }
422 442
423 443
424 444 /*
425 445 * check ppm.conf file domain device pathname syntax, if correct,
426 446 * create device match pattern.
427 447 * return 1 for good, -1 for bad.
428 448 */
429 449 ppm_db_t *
430 450 ppm_parse_pattern(struct ppm_db **dbpp, char *dev_path)
431 451 {
432 452 char path[MAXNAMELEN];
433 453 int wccnt, i;
434 454 int wcpos[2];
435 455 int pos;
436 456 char *cp;
437 457 ppm_db_t *dbp;
438 458
439 459 (void) strcpy(path, dev_path);
440 460 if ((wccnt = ppm_count_char(path, '*')) > 2)
441 461 return (NULL);
442 462
443 463 for (i = 0, cp = path, pos = 0; i < wccnt; i++, cp++, pos++) {
444 464 for (; *cp; cp++, pos++)
445 465 if (*cp == '*')
446 466 break;
447 467 wcpos[i] = pos;
448 468 PPMD(D_CREATEDB, (" wildcard #%d, pos %d\n",
449 469 (i + 1), wcpos[i]))
450 470 }
451 471
452 472 #ifdef DEBUG
453 473 /* first '*', if exists, don't go beyond the string */
454 474 if (wccnt > 0)
455 475 ASSERT(wcpos[0] < strlen(path));
456 476
457 477 /* second '*', if exists, better be the last character */
458 478 if (wccnt == 2)
459 479 ASSERT(wcpos[1] == (strlen(path) - 1));
460 480 #endif
461 481
462 482 /*
463 483 * first '*', if followed by any char, must be immediately
464 484 * followed by '@' and the rest better be bound by
465 485 * ['0-9', 'a-f', A-F'] until ended '0' or second '*''0'.
466 486 */
467 487 if ((wccnt > 0) && (wcpos[0] < (strlen(path) - 1))) {
468 488 cp = path + wcpos[0] + 1;
469 489 if (*cp != '@')
470 490 return (NULL);
471 491
472 492 if (!(((*(++cp) > '0') && (*cp < '9')) ||
473 493 ((*cp > 'a') && (*cp < 'f')) ||
474 494 ((*cp > 'A') && (*cp < 'F'))))
475 495 return (NULL);
476 496 }
477 497
478 498 dbp = kmem_zalloc(sizeof (struct ppm_db), KM_SLEEP);
479 499 dbp->name = kmem_zalloc((strlen(path) + 1), KM_SLEEP);
480 500 (void) strcpy(dbp->name, path);
481 501 dbp->wccnt = wccnt;
482 502 dbp->wcpos[0] = (wccnt > 0) ? wcpos[0] : -1;
483 503 dbp->wcpos[1] = (wccnt == 2) ? wcpos[1] : -1;
484 504
485 505 return (*dbpp = dbp);
486 506 }
487 507
488 508
489 509 /*
490 510 * match given device "path" to domain device pathname
491 511 * pattern dbp->name that contains one or two '*' character(s).
492 512 * Matching policy:
493 513 * 1). If one wildcard terminates match pattern, need exact match
494 514 * up to (but exclude) the wildcard;
495 515 * 2). If one wildcard does not terminate match pattern, it is to
496 516 * match driver name (terminates with '@') and must be followed
497 517 * by exact match of rest of pattern;
498 518 * 3). If two wildcards, first is to match driver name as in 2),
499 519 * second is to match fcnid (terminates with '/' or '\0') and
500 520 * must the last char of pattern.
501 521 *
502 522 * return 0 if match, and
503 523 * non 0 if mismatch
504 524 */
505 525 int
506 526 ppm_match_devs(char *dev_path, ppm_db_t *dbp)
507 527 {
508 528 char path[MAXNAMELEN];
509 529 char *cp; /* points into "path", real device pathname */
510 530 char *np; /* points into "dbp->name", the pattern */
511 531 int len;
512 532
513 533 if (dbp->wccnt == 0)
514 534 return (strcmp(dev_path, dbp->name));
515 535
516 536 (void) strcpy(path, dev_path);
517 537
518 538 /* match upto the first '*' regardless */
519 539 if (strncmp(path, dbp->name, dbp->wcpos[0]) != 0)
520 540 return (-1);
521 541
522 542
523 543 /* "<exact match>*" */
524 544 if (dbp->name[dbp->wcpos[0] + 1] == 0) {
525 545 cp = path + dbp->wcpos[0];
526 546 while (*cp && (*cp++ != '/'))
527 547 ;
528 548 return ((*cp == 0) ? 0 : -1);
529 549 }
530 550
531 551
532 552 /* locate '@' */
533 553 cp = path + dbp->wcpos[0] + 1;
534 554 while (*cp && *cp != '@')
535 555 cp++;
536 556
537 557 np = dbp->name + dbp->wcpos[0] + 1;
538 558
539 559 /* if one wildcard, match the rest in the pattern */
540 560 if (dbp->wccnt == 1)
541 561 return ((strcmp(cp, np) == 0) ? 0 : (-1));
542 562
543 563
544 564 /* must have exact match after first wildcard up to second */
545 565 ASSERT(dbp->wccnt == 2);
546 566 len = dbp->wcpos[1] - dbp->wcpos[0] - 1;
547 567 if (strncmp(cp, np, len) != 0)
548 568 return (-1);
549 569
550 570 /* second wildcard match terminates with '/' or '\0' */
551 571 /* but only termination with '\0' is a successful match */
552 572 cp += len;
553 573 while (*cp && (*cp != '/'))
554 574 cp++;
555 575 return ((*cp == 0) ? 0 : -1);
556 576 }
557 577
558 578
559 579 /*
560 580 * By claiming a device, ppm gets involved in its power change
561 581 * process: handles additional issues prior and/or post its
562 582 * power(9e) call.
563 583 *
564 584 * If 'dip' is a PCI device, this is the time to ask its parent
565 585 * what PCI bus speed it is running.
566 586 *
567 587 * returns 1 (claimed), 0 (not claimed)
568 588 */
569 589 int
570 590 ppm_claim_dev(dev_info_t *dip)
571 591 {
572 592 ppm_domain_t *domp;
573 593 dev_info_t *pdip;
574 594 uint_t pciclk;
575 595 int claimed = -1;
576 596
577 597 domp = ppm_lookup_dev(dip);
578 598 if (!domp)
579 599 claimed = 0;
580 600
581 601 if (domp && PPMD_IS_PCI(domp->model) &&
582 602 ! (domp->dflags & (PPMD_PCI33MHZ | PPMD_PCI66MHZ))) {
583 603 pdip = ddi_get_parent(dip);
584 604 ASSERT(pdip);
585 605 pciclk = ddi_prop_get_int(DDI_DEV_T_ANY, pdip,
586 606 DDI_PROP_DONTPASS, "clock-frequency", -1);
587 607
588 608 switch (pciclk) {
589 609 case 33000000:
590 610 domp->dflags |= PPMD_PCI33MHZ;
591 611 claimed = 1;
592 612 break;
593 613 case 66000000:
594 614 domp->dflags |= PPMD_PCI66MHZ;
595 615 claimed = 1;
596 616 break;
597 617 default:
598 618 claimed = 0;
599 619 break;
600 620 }
601 621 }
602 622
603 623 if (domp && (claimed == -1))
604 624 claimed = 1;
605 625
606 626 #ifdef DEBUG
607 627 if (claimed) {
608 628 char path[MAXNAMELEN];
609 629 PPMD(D_CLAIMDEV, ("ppm_claim_dev: %s into domain %s\n",
610 630 ddi_pathname(dip, path), domp->name))
611 631 }
612 632
613 633 #endif
614 634
615 635 return (claimed);
616 636 }
617 637
618 638 /*
619 639 * add a device to the list of domain's owned devices (if it is not already
620 640 * on the list).
621 641 */
622 642 ppm_owned_t *
623 643 ppm_add_owned(dev_info_t *dip, ppm_domain_t *domp)
624 644 {
625 645 char path[MAXNAMELEN];
626 646 ppm_owned_t *owned, *new_owned;
627 647
628 648 ASSERT(MUTEX_HELD(&domp->lock));
629 649 PPM_GET_PATHNAME(dip, path);
630 650 for (owned = domp->owned; owned; owned = owned->next)
631 651 if (strcmp(path, owned->path) == 0)
632 652 return (owned);
633 653
634 654 new_owned = kmem_zalloc(sizeof (*new_owned), KM_SLEEP);
635 655 new_owned->path = kmem_zalloc(strlen(path) + 1, KM_SLEEP);
636 656 (void) strcpy(new_owned->path, path);
637 657 new_owned->next = domp->owned;
638 658 domp->owned = new_owned;
639 659
640 660 return (domp->owned);
641 661 }
642 662
643 663 /*
644 664 * create/init a new ppm device and link into the domain
645 665 */
646 666 ppm_dev_t *
647 667 ppm_add_dev(dev_info_t *dip, ppm_domain_t *domp)
648 668 {
649 669 char path[MAXNAMELEN];
650 670 ppm_dev_t *new = NULL;
651 671 int cmpt;
652 672 ppm_owned_t *owned;
653 673
654 674 ASSERT(MUTEX_HELD(&domp->lock));
655 675 (void) ddi_pathname(dip, path);
656 676 /*
657 677 * For devs which have exported "pm-components" we want to create
658 678 * a data structure for each component. When a driver chooses not
659 679 * to export the prop we treat its device as having a single
660 680 * component and build a structure for it anyway. All other ppm
661 681 * logic will act as if this device were always up and can thus
662 682 * make correct decisions about it in relation to other devices
663 683 * in its domain.
664 684 */
665 685 for (cmpt = PM_GET_PM_INFO(dip) ? PM_NUMCMPTS(dip) : 1; cmpt--; ) {
666 686 new = kmem_zalloc(sizeof (*new), KM_SLEEP);
667 687 new->path = kmem_zalloc(strlen(path) + 1, KM_SLEEP);
668 688 (void) strcpy(new->path, path);
669 689 new->domp = domp;
670 690 new->dip = dip;
671 691 new->cmpt = cmpt;
672 692 ppm_dev_init(new);
673 693 new->next = domp->devlist;
674 694 domp->devlist = new;
675 695 PPMD(D_ADDDEV,
676 696 ("ppm_add_dev: %s to domain %s: ppm_dev(0x%p)\n",
677 697 new->path, domp->name, (void *)new))
678 698 }
679 699
680 700 ASSERT(new != NULL);
681 701 /*
682 702 * devi_pm_ppm_private should be set only after all
683 703 * ppm_dev s related to all components have been
684 704 * initialized and domain's pwr_cnt is incremented
685 705 * for each of them.
686 706 */
687 707 PPM_SET_PRIVATE(dip, new);
688 708
689 709 /* remember this device forever */
690 710 owned = ppm_add_owned(dip, domp);
691 711
692 712 /*
693 713 * Initializing flag is set for devices which have gone through
694 714 * PPM_PMR_INIT_CHILD ctlop. By this point, these devices have
695 715 * been added to ppm structures and could participate in pm
696 716 * decision making, so clear the initializing flag.
697 717 */
698 718 if (owned->initializing) {
699 719 owned->initializing = 0;
700 720 PPMD(D_ADDDEV, ("ppm_add_dev: cleared initializing flag "
701 721 "for %s@%s\n", PM_NAME(dip),
702 722 (PM_ADDR(dip) == NULL) ? "" : PM_ADDR(dip)))
703 723 }
704 724
705 725 return (new);
706 726 }
707 727
708 728
709 729 /*
710 730 * returns an existing or newly created ppm device reference
711 731 */
712 732 ppm_dev_t *
713 733 ppm_get_dev(dev_info_t *dip, ppm_domain_t *domp)
714 734 {
715 735 ppm_dev_t *pdp;
716 736
717 737 mutex_enter(&domp->lock);
718 738 pdp = PPM_GET_PRIVATE(dip);
719 739 if (pdp == NULL)
720 740 pdp = ppm_add_dev(dip, domp);
721 741 mutex_exit(&domp->lock);
722 742
723 743 return (pdp);
724 744 }
725 745
726 746
727 747 /*
728 748 * scan a domain's device list and remove those with .dip
729 749 * matching the arg *dip; we need to scan the entire list
730 750 * for the case of devices with multiple components
731 751 */
732 752 void
733 753 ppm_rem_dev(dev_info_t *dip)
734 754 {
735 755 ppm_dev_t *pdp, **devpp;
736 756 ppm_domain_t *domp;
737 757
738 758 pdp = PPM_GET_PRIVATE(dip);
739 759 ASSERT(pdp);
740 760 domp = pdp->domp;
741 761 ASSERT(domp);
742 762
743 763 mutex_enter(&domp->lock);
744 764 for (devpp = &domp->devlist; (pdp = *devpp) != NULL; ) {
745 765 if (pdp->dip != dip) {
746 766 devpp = &pdp->next;
747 767 continue;
748 768 }
749 769
750 770 PPMD(D_REMDEV, ("ppm_rem_dev: path \"%s\", ppm_dev 0x%p\n",
751 771 pdp->path, (void *)pdp))
752 772
753 773 PPM_SET_PRIVATE(dip, NULL);
754 774 *devpp = pdp->next;
755 775 ppm_dev_fini(pdp);
756 776 kmem_free(pdp->path, strlen(pdp->path) + 1);
757 777 kmem_free(pdp, sizeof (*pdp));
758 778 }
759 779 mutex_exit(&domp->lock);
760 780 }
761 781
762 782 /*
763 783 * prepare kernel ioctl calls:
764 784 */
765 785 void
766 786 ppm_init_cb(dev_info_t *dip)
767 787 {
768 788 char *str = "ppm_init_cb";
769 789 ppm_domain_t *domp;
770 790 ppm_dc_t *dc;
771 791
772 792 for (domp = ppm_domain_p; domp != NULL; domp = domp->next) {
773 793 for (dc = domp->dc; dc; dc = dc->next) {
774 794 /*
775 795 * Warning: This code is rather confusing.
776 796 *
777 797 * It intends to ensure that ppm_init_lyr() is only
778 798 * called ONCE for a device that may be associated
779 799 * with more than one domain control.
780 800 * So, what it does is first to check to see if
781 801 * there is a handle, and then if not it goes on
782 802 * to call the init_lyr() routine.
783 803 *
784 804 * The non-obvious thing is that the ppm_init_lyr()
785 805 * routine, in addition to opening the device
786 806 * associated with the dc (domain control) in
787 807 * question, has the side-effect of creating the
788 808 * handle for that dc as well.
789 809 */
790 810 if (ppm_lookup_hndl(domp->model, dc) != NULL)
791 811 continue;
792 812
793 813 if (ppm_init_lyr(dc, dip) != DDI_SUCCESS) {
794 814 domp->dflags |= PPMD_OFFLINE;
795 815 cmn_err(CE_WARN, "%s: ppm domain %s will "
796 816 "be offline.", str, domp->name);
797 817 break;
798 818 }
799 819 }
800 820 }
801 821 }
802 822
803 823
804 824 /*
805 825 * ppm_init_lyr - initializing layered ioctl
806 826 * Return:
807 827 * DDI_SUCCESS - succeeded
808 828 * DDI_FAILURE - failed
809 829 *
810 830 */
811 831 int
812 832 ppm_init_lyr(ppm_dc_t *dc, dev_info_t *dip)
813 833 {
814 834 char *str = "ppm_init_lyr";
815 835 int err = 0;
816 836 ldi_ident_t li;
817 837
818 838 ASSERT(dc && dc->path);
819 839
820 840 if (err = ldi_ident_from_dip(dip, &li)) {
821 841 cmn_err(CE_WARN, "%s: get ldi identifier "
822 842 "failed (err=%d)", str, err);
823 843 }
824 844
825 845 err = ldi_open_by_name(dc->path, FWRITE|FREAD, kcred, &(dc->lh), li);
826 846
827 847 (void) ldi_ident_release(li);
828 848
829 849 if (err != 0) {
830 850 cmn_err(CE_WARN, "Failed to open device(%s), rv(%d)",
831 851 dc->path, err);
832 852 return (err);
833 853 }
834 854
835 855 return (DDI_SUCCESS);
836 856 }
837 857
838 858 /*
839 859 * lock, unlock, or trylock for one power mutex
840 860 */
841 861 void
842 862 ppm_lock_one(ppm_dev_t *ppmd, power_req_t *reqp, int *iresp)
843 863 {
844 864 switch (reqp->request_type) {
845 865 case PMR_PPM_LOCK_POWER:
846 866 pm_lock_power_single(ppmd->dip,
847 867 reqp->req.ppm_lock_power_req.circp);
848 868 break;
849 869
850 870 case PMR_PPM_UNLOCK_POWER:
851 871 pm_unlock_power_single(ppmd->dip,
852 872 reqp->req.ppm_unlock_power_req.circ);
853 873 break;
854 874
855 875 case PMR_PPM_TRY_LOCK_POWER:
856 876 *iresp = pm_try_locking_power_single(ppmd->dip,
857 877 reqp->req.ppm_lock_power_req.circp);
858 878 break;
859 879 }
860 880 }
861 881
862 882
863 883 /*
864 884 * lock, unlock, or trylock for all power mutexes within a domain
865 885 */
866 886 void
867 887 ppm_lock_all(ppm_domain_t *domp, power_req_t *reqp, int *iresp)
868 888 {
869 889 /*
870 890 * To simplify the implementation we let all the devices
871 891 * in the domain be represented by a single device (dip).
872 892 * We use the first device in the domain's devlist. This
873 893 * is safe because we return with the domain lock held
874 894 * which prevents the list from changing.
875 895 */
876 896 if (reqp->request_type == PMR_PPM_LOCK_POWER) {
877 897 if (!MUTEX_HELD(&domp->lock))
878 898 mutex_enter(&domp->lock);
879 899 domp->refcnt++;
880 900 ASSERT(domp->devlist != NULL);
881 901 pm_lock_power_single(domp->devlist->dip,
882 902 reqp->req.ppm_lock_power_req.circp);
883 903 /* domain lock remains held */
884 904 return;
885 905 } else if (reqp->request_type == PMR_PPM_UNLOCK_POWER) {
886 906 ASSERT(MUTEX_HELD(&domp->lock));
887 907 ASSERT(domp->devlist != NULL);
888 908 pm_unlock_power_single(domp->devlist->dip,
889 909 reqp->req.ppm_unlock_power_req.circ);
890 910 if (--domp->refcnt == 0)
891 911 mutex_exit(&domp->lock);
892 912 return;
893 913 }
894 914
895 915 ASSERT(reqp->request_type == PMR_PPM_TRY_LOCK_POWER);
896 916 if (!MUTEX_HELD(&domp->lock))
897 917 if (!mutex_tryenter(&domp->lock)) {
898 918 *iresp = 0;
899 919 return;
900 920 }
901 921 *iresp = pm_try_locking_power_single(domp->devlist->dip,
902 922 reqp->req.ppm_lock_power_req.circp);
903 923 if (*iresp)
904 924 domp->refcnt++;
905 925 else
906 926 mutex_exit(&domp->lock);
907 927 }
908 928
909 929
910 930 /*
911 931 * return FALSE: if any detached device during its previous life exported
912 932 * the "no-involuntary-power-cycles" property and detached with its
913 933 * power level not at its lowest, or there is a device in the process
914 934 * of being installed/attached; if a PCI domain has devices that have not
915 935 * exported a property that it can tolerate clock off while bus is not
916 936 * quiescent; if a 66mhz PCI domain has devices that do not support stopping
917 937 * clock at D3; either one would count as a power holder.
918 938 * return TRUE: otherwise.
919 939 */
920 940 boolean_t
921 941 ppm_none_else_holds_power(ppm_domain_t *domp)
922 942 {
923 943 ppm_dev_t *ppmd;
924 944 ppm_owned_t *owned;
925 945 int i = 0;
926 946
927 947 if (PPMD_IS_PCI(domp->model)) {
928 948 for (ppmd = domp->devlist; ppmd; ppmd = ppmd->next) {
929 949 if ((domp->model == PPMD_PCI_PROP) &&
930 950 !(ppmd->flags & PPMDEV_PCI_PROP_CLKPM))
931 951 return (B_FALSE);
932 952 if ((domp->dflags & PPMD_PCI66MHZ) &&
933 953 !(ppmd->flags & PPMDEV_PCI66_D2))
934 954 return (B_FALSE);
935 955 }
936 956 }
937 957
938 958 for (owned = domp->owned; owned; owned = owned->next)
939 959 if (pm_noinvol_detached(owned->path) || owned->initializing)
940 960 i++;
941 961 return (i == 0);
942 962 }
943 963
944 964
945 965 /*
946 966 * return the number of char 'c' occurrences in string s
947 967 */
948 968 int
949 969 ppm_count_char(char *s, char c)
950 970 {
951 971 int i = 0;
952 972 char *cp = s;
953 973
954 974 while (*cp) {
955 975 if (*cp == c)
956 976 i++;
957 977 cp++;
958 978 }
959 979
960 980 return (i);
961 981 }
962 982
963 983
964 984 /*
965 985 * extract and convert a substring from input string "ss" in form of
966 986 * "name=value" into an hex or decimal integer
967 987 */
968 988 #define X_BASE 16
969 989 #define D_BASE 10
970 990 int
971 991 ppm_stoi(char *ss, uint_t *val)
972 992 {
973 993 char *cp;
974 994 int hex_ = 0, base = D_BASE;
975 995 int digit;
976 996
977 997 if ((cp = strchr(ss, '=')) == NULL)
978 998 return (*val = (uint_t)-1);
979 999
980 1000 cp++;
981 1001 if ((*cp == '0') && (*++cp == 'x')) {
982 1002 hex_++;
983 1003 cp++;
984 1004 base = X_BASE;
985 1005 }
986 1006
987 1007 for (digit = 0; *cp; cp++) {
988 1008 if (hex_ && ((*cp >= 'A') && (*cp <= 'F')))
989 1009 digit = (digit * base) + ((*cp - 'A') + D_BASE);
990 1010 else if (hex_ && ((*cp >= 'a') && (*cp <= 'f')))
991 1011 digit = (digit * base) + ((*cp - 'a') + D_BASE);
992 1012 else
993 1013 digit = (digit * base) + (*cp - '0');
994 1014 }
995 1015
996 1016 return (*val = digit);
997 1017 }
998 1018
999 1019 /*
1000 1020 * ppm_convert - convert a #define symbol to its integer value,
1001 1021 * only the #defines for ppm_dc.cmd and ppm_dc.method fields in
1002 1022 * ppmvar.h file are recognized.
1003 1023 */
1004 1024 struct ppm_confdefs {
1005 1025 char *sym;
1006 1026 int val;
1007 1027 } ppm_confdefs_table[] = {
1008 1028 "ENTER_S3", PPMDC_ENTER_S3,
1009 1029 "EXIT_S3", PPMDC_EXIT_S3,
1010 1030 "CPU_NEXT", PPMDC_CPU_NEXT,
1011 1031 "PRE_CHNG", PPMDC_PRE_CHNG,
1012 1032 "CPU_GO", PPMDC_CPU_GO,
1013 1033 "POST_CHNG", PPMDC_POST_CHNG,
1014 1034 "FET_ON", PPMDC_FET_ON,
1015 1035 "FET_OFF", PPMDC_FET_OFF,
1016 1036 "CLK_OFF", PPMDC_CLK_OFF,
1017 1037 "CLK_ON", PPMDC_CLK_ON,
1018 1038 "LED_ON", PPMDC_LED_ON,
1019 1039 "LED_OFF", PPMDC_LED_OFF,
1020 1040 "KIO", PPMDC_KIO,
1021 1041 "VCORE", PPMDC_VCORE,
1022 1042 #ifdef sun4u
1023 1043 "I2CKIO", PPMDC_I2CKIO,
1024 1044 #endif
1025 1045 "CPUSPEEDKIO", PPMDC_CPUSPEEDKIO,
1026 1046 "PRE_PWR_OFF", PPMDC_PRE_PWR_OFF,
1027 1047 "PRE_PWR_ON", PPMDC_PRE_PWR_ON,
1028 1048 "POST_PWR_ON", PPMDC_POST_PWR_ON,
1029 1049 "PWR_OFF", PPMDC_PWR_OFF,
1030 1050 "PWR_ON", PPMDC_PWR_ON,
1031 1051 "RESET_OFF", PPMDC_RESET_OFF,
1032 1052 "RESET_ON", PPMDC_RESET_ON,
1033 1053 NULL
1034 1054 };
1035 1055
1036 1056
1037 1057 /*
1038 1058 * convert a #define'd symbol to its integer value where
1039 1059 * input "symbol" is expected to be in form of "SYMBOL=value"
1040 1060 */
1041 1061 int
1042 1062 ppm_convert(char *symbol, uint_t *val)
1043 1063 {
1044 1064 char *s;
1045 1065 struct ppm_confdefs *pcfp;
1046 1066
1047 1067 if ((s = strchr(symbol, '=')) == NULL) {
1048 1068 cmn_err(CE_WARN, "ppm_convert: token \"%s\" syntax error in "
1049 1069 "ppm.conf file, line(%d)", symbol, __LINE__);
1050 1070 return (*val = (uint_t)-1);
1051 1071 }
1052 1072 s++;
1053 1073
1054 1074 for (pcfp = ppm_confdefs_table; (pcfp->sym != NULL); pcfp++) {
1055 1075 if (strcmp(s, pcfp->sym) == 0)
1056 1076 return (*val = pcfp->val);
1057 1077 }
1058 1078
1059 1079 cmn_err(CE_WARN, "ppm_convert: Unrecognizable token \"%s\" "
1060 1080 "in ppm.conf file, line %d", symbol, __LINE__);
1061 1081 return (*val = (uint_t)-1);
1062 1082 }
1063 1083
1064 1084
1065 1085 /*
1066 1086 * parse a domain control property string into data structure struct ppm_dc
1067 1087 */
1068 1088 int
1069 1089 ppm_parse_dc(char **dc_namep, ppm_dc_t *dc)
1070 1090 {
1071 1091 char *str = "ppm_parse_dc";
1072 1092 char *line;
1073 1093 char *f, *b;
1074 1094 char **dclist; /* list of ppm_dc_t fields */
1075 1095 int count; /* the # of '=' indicates the # of items */
1076 1096 size_t len; /* length of line being parsed */
1077 1097 boolean_t done;
1078 1098 int i;
1079 1099 int err;
1080 1100
1081 1101 len = strlen(*dc_namep);
1082 1102 line = kmem_alloc(len + 1, KM_SLEEP);
1083 1103 (void) strcpy(line, *dc_namep);
1084 1104
1085 1105 count = ppm_count_char(line, '=');
1086 1106 ASSERT((count - ppm_count_char(line, ' ')) == 1);
1087 1107
1088 1108 dclist = (char **)
1089 1109 kmem_zalloc((sizeof (char *) * (count + 1)), KM_SLEEP);
1090 1110 for (i = 0, f = b = line, done = B_FALSE; !done; i++, f = ++b) {
1091 1111 while (*b != ' ' && *b != 0)
1092 1112 b++;
1093 1113 if (*b == 0)
1094 1114 done = B_TRUE;
1095 1115 else
1096 1116 *b = 0;
1097 1117 dclist[i] = f;
1098 1118 }
1099 1119
1100 1120 for (i = 0; i < count; i++) {
1101 1121 if (strstr(dclist[i], "cmd=")) {
1102 1122 err = ppm_convert(dclist[i], &dc->cmd);
1103 1123 if (err == -1)
1104 1124 return (err);
1105 1125 continue;
1106 1126 }
1107 1127 if ((f = strstr(dclist[i], "path=")) != NULL) {
1108 1128 f += strlen("path=");
1109 1129 dc->path = kmem_zalloc((strlen(f) + 1), KM_SLEEP);
1110 1130 (void) strcpy(dc->path, f);
1111 1131 continue;
1112 1132 }
1113 1133 if (strstr(dclist[i], "method=")) {
1114 1134 err = ppm_convert(dclist[i], &dc->method);
1115 1135 if (err == -1)
1116 1136 return (err);
1117 1137 continue;
1118 1138 }
1119 1139 if (strstr(dclist[i], "iowr=")) {
1120 1140 (void) ppm_stoi(dclist[i], &dc->m_un.kio.iowr);
1121 1141 continue;
1122 1142 }
1123 1143 if (strstr(dclist[i], "iord=")) {
1124 1144 (void) ppm_stoi(dclist[i], &dc->m_un.kio.iord);
1125 1145 continue;
1126 1146 }
1127 1147 if (strstr(dclist[i], "val=")) {
1128 1148 (void) ppm_stoi(dclist[i], &dc->m_un.kio.val);
1129 1149 continue;
1130 1150 }
1131 1151 if (strstr(dclist[i], "speeds=")) {
1132 1152 ASSERT(dc->method == PPMDC_CPUSPEEDKIO);
1133 1153 (void) ppm_stoi(dclist[i], &dc->m_un.cpu.speeds);
1134 1154 continue;
1135 1155 }
1136 1156 #ifdef sun4u
1137 1157 if (strstr(dclist[i], "mask=")) {
1138 1158 (void) ppm_stoi(dclist[i], &dc->m_un.i2c.mask);
1139 1159 continue;
1140 1160 }
1141 1161 #endif
1142 1162 /* This must be before the if statement for delay */
1143 1163 if (strstr(dclist[i], "post_delay=")) {
1144 1164 #ifdef sun4u
1145 1165 ASSERT(dc->method == PPMDC_KIO ||
1146 1166 dc->method == PPMDC_I2CKIO);
1147 1167 #else
1148 1168 ASSERT(dc->method == PPMDC_KIO);
1149 1169 #endif
1150 1170 /*
1151 1171 * all delays are uint_t type instead of clock_t.
1152 1172 * If the delay is too long, it might get truncated.
1153 1173 * But, we don't expect delay to be too long.
1154 1174 */
1155 1175 switch (dc->method) {
1156 1176 case PPMDC_KIO:
1157 1177 (void) ppm_stoi(dclist[i],
1158 1178 &dc->m_un.kio.post_delay);
1159 1179 break;
1160 1180
1161 1181 #ifdef sun4u
1162 1182 case PPMDC_I2CKIO:
1163 1183 (void) ppm_stoi(dclist[i],
1164 1184 &dc->m_un.i2c.post_delay);
1165 1185 break;
1166 1186 #endif
1167 1187
1168 1188 default:
1169 1189 break;
1170 1190 }
1171 1191 continue;
1172 1192 }
1173 1193 if (strstr(dclist[i], "delay=")) {
1174 1194 #ifdef sun4u
1175 1195 ASSERT(dc->method == PPMDC_VCORE ||
1176 1196 dc->method == PPMDC_KIO ||
1177 1197 dc->method == PPMDC_I2CKIO);
1178 1198 #else
1179 1199 ASSERT(dc->method == PPMDC_VCORE ||
1180 1200 dc->method == PPMDC_KIO);
1181 1201 #endif
1182 1202
1183 1203 /*
1184 1204 * all delays are uint_t type instead of clock_t.
1185 1205 * If the delay is too long, it might get truncated.
1186 1206 * But, we don't expect delay to be too long.
1187 1207 */
1188 1208
1189 1209 switch (dc->method) {
1190 1210 case PPMDC_KIO:
1191 1211 (void) ppm_stoi(dclist[i], &dc->m_un.kio.delay);
1192 1212 break;
1193 1213
1194 1214 #ifdef sun4u
1195 1215 case PPMDC_I2CKIO:
1196 1216 (void) ppm_stoi(dclist[i], &dc->m_un.i2c.delay);
1197 1217 break;
1198 1218 #endif
1199 1219
1200 1220 case PPMDC_VCORE:
1201 1221 (void) ppm_stoi(dclist[i], &dc->m_un.cpu.delay);
1202 1222 break;
1203 1223
1204 1224 default:
1205 1225 break;
1206 1226 }
1207 1227 continue;
1208 1228 }
1209 1229
1210 1230 /* we encounted unrecognized field, flag error */
1211 1231 cmn_err(CE_WARN, "%s: Unrecognized token \"%s\" in ppm.conf "
1212 1232 "file, line(%d)!", str, dclist[i], __LINE__);
1213 1233 return (-1);
1214 1234 }
1215 1235
1216 1236 kmem_free(dclist, sizeof (char *) * (count + 1));
1217 1237 kmem_free(line, len + 1);
1218 1238
1219 1239 return (DDI_SUCCESS);
1220 1240 }
1221 1241
1222 1242
1223 1243 /*
1224 1244 * search for domain control handle for a claimed device coupled with a
1225 1245 * domain control command. NULL device may indicate LED domain.
1226 1246 */
1227 1247 ppm_dc_t *
1228 1248 ppm_lookup_dc(ppm_domain_t *domp, int cmd)
1229 1249 {
1230 1250 #ifdef DEBUG
1231 1251 char *str = "ppm_lookup_dc";
1232 1252 #endif
1233 1253 ppm_dc_t *dc;
1234 1254
1235 1255 /*
1236 1256 * For convenience, we accept 'domp' as NULL for searching
1237 1257 * LED domain control operation.
1238 1258 */
1239 1259 if ((cmd == PPMDC_LED_OFF) || (cmd == PPMDC_LED_ON)) {
1240 1260 for (domp = ppm_domain_p; domp; domp = domp->next)
1241 1261 if (domp->model == PPMD_LED)
1242 1262 break;
1243 1263 if (!domp || !domp->dc || !domp->dc->lh || !domp->dc->next) {
1244 1264 PPMD(D_LED, ("\tinsufficient led domain control "
1245 1265 "information.\n"))
1246 1266 return (NULL);
1247 1267 }
1248 1268 if (cmd == domp->dc->cmd)
1249 1269 return (domp->dc);
1250 1270 else
1251 1271 return (domp->dc->next);
1252 1272 }
1253 1273
1254 1274
1255 1275 /*
1256 1276 * for the rest of ppm domains, lookup ppm_dc starting from domp
1257 1277 */
1258 1278 ASSERT(domp != NULL);
1259 1279 switch (cmd) {
1260 1280 case PPMDC_CPU_NEXT:
1261 1281 case PPMDC_PRE_CHNG:
1262 1282 case PPMDC_CPU_GO:
1263 1283 case PPMDC_POST_CHNG:
1264 1284 case PPMDC_FET_OFF:
1265 1285 case PPMDC_FET_ON:
1266 1286 case PPMDC_CLK_OFF:
1267 1287 case PPMDC_CLK_ON:
1268 1288 case PPMDC_PRE_PWR_OFF:
1269 1289 case PPMDC_PRE_PWR_ON:
1270 1290 case PPMDC_POST_PWR_ON:
1271 1291 case PPMDC_PWR_OFF:
1272 1292 case PPMDC_PWR_ON:
1273 1293 case PPMDC_RESET_OFF:
1274 1294 case PPMDC_RESET_ON:
1275 1295 case PPMDC_ENTER_S3:
1276 1296 case PPMDC_EXIT_S3:
1277 1297 break;
1278 1298 default:
1279 1299 PPMD(D_PPMDC, ("%s: cmd(%d) unrecognized\n", str, cmd))
1280 1300 return (NULL);
1281 1301 }
1282 1302
1283 1303 for (dc = domp->dc; dc; dc = dc->next) {
1284 1304 if (dc->cmd == cmd) {
1285 1305 return (dc);
1286 1306 }
1287 1307 }
1288 1308
1289 1309 return (NULL);
1290 1310 }
1291 1311
1292 1312 #include <sys/esunddi.h>
1293 1313
1294 1314 ppm_domain_t *
1295 1315 ppm_get_domain_by_dev(const char *p)
1296 1316 {
1297 1317 dev_info_t *dip;
1298 1318 ppm_domain_t *domp;
1299 1319 ppm_dev_t *pdev;
1300 1320 boolean_t found = B_FALSE;
1301 1321
1302 1322 if ((dip = e_ddi_hold_devi_by_path((char *)p, 0)) == NULL)
1303 1323 return (NULL);
1304 1324
1305 1325 for (domp = ppm_domain_p; domp; domp = domp->next) {
1306 1326 for (pdev = domp->devlist; pdev; pdev = pdev->next) {
1307 1327 if (pdev->dip == dip) {
1308 1328 found = B_TRUE;
1309 1329 break;
1310 1330 }
1311 1331 }
1312 1332 if (found)
1313 1333 break;
1314 1334 }
1315 1335 ddi_release_devi(dip);
1316 1336 return (domp);
1317 1337 }
1318 1338
1319 1339
1320 1340 #ifdef DEBUG
1321 1341 #define FLINTSTR(flags, sym) { flags, sym, #sym }
1322 1342 #define PMR_UNKNOWN -1
1323 1343 /*
1324 1344 * convert a ctlop integer to a char string. this helps printing
1325 1345 * meaningful info when cltops are received from the pm framework.
1326 1346 * since some ctlops are so frequent, we use mask to limit output:
1327 1347 * a valid string is returned when ctlop is found and when
1328 1348 * (cmd.flags & mask) is true; otherwise NULL is returned.
1329 1349 */
1330 1350 char *
1331 1351 ppm_get_ctlstr(int ctlop, uint_t mask)
1332 1352 {
1333 1353 struct ctlop_cmd {
1334 1354 uint_t flags;
1335 1355 int ctlop;
1336 1356 char *str;
1337 1357 };
1338 1358
1339 1359 struct ctlop_cmd *ccp;
1340 1360 static struct ctlop_cmd cmds[] = {
1341 1361 FLINTSTR(D_SETPWR, PMR_SET_POWER),
1342 1362 FLINTSTR(D_CTLOPS2, PMR_SUSPEND),
1343 1363 FLINTSTR(D_CTLOPS2, PMR_RESUME),
1344 1364 FLINTSTR(D_CTLOPS2, PMR_PRE_SET_POWER),
1345 1365 FLINTSTR(D_CTLOPS2, PMR_POST_SET_POWER),
1346 1366 FLINTSTR(D_CTLOPS2, PMR_PPM_SET_POWER),
1347 1367 FLINTSTR(0, PMR_PPM_ATTACH),
1348 1368 FLINTSTR(0, PMR_PPM_DETACH),
1349 1369 FLINTSTR(D_CTLOPS1, PMR_PPM_POWER_CHANGE_NOTIFY),
1350 1370 FLINTSTR(D_CTLOPS1, PMR_REPORT_PMCAP),
1351 1371 FLINTSTR(D_CTLOPS1, PMR_CHANGED_POWER),
1352 1372 FLINTSTR(D_CTLOPS2, PMR_PPM_INIT_CHILD),
1353 1373 FLINTSTR(D_CTLOPS2, PMR_PPM_UNINIT_CHILD),
1354 1374 FLINTSTR(D_CTLOPS2, PMR_PPM_PRE_PROBE),
1355 1375 FLINTSTR(D_CTLOPS2, PMR_PPM_POST_PROBE),
1356 1376 FLINTSTR(D_CTLOPS2, PMR_PPM_PRE_ATTACH),
1357 1377 FLINTSTR(D_CTLOPS2, PMR_PPM_POST_ATTACH),
1358 1378 FLINTSTR(D_CTLOPS2, PMR_PPM_PRE_DETACH),
1359 1379 FLINTSTR(D_CTLOPS2, PMR_PPM_POST_DETACH),
1360 1380 FLINTSTR(D_CTLOPS1, PMR_PPM_UNMANAGE),
1361 1381 FLINTSTR(D_CTLOPS2, PMR_PPM_PRE_RESUME),
1362 1382 FLINTSTR(D_CTLOPS1, PMR_PPM_ALL_LOWEST),
1363 1383 FLINTSTR(D_LOCKS, PMR_PPM_LOCK_POWER),
1364 1384 FLINTSTR(D_LOCKS, PMR_PPM_UNLOCK_POWER),
1365 1385 FLINTSTR(D_LOCKS, PMR_PPM_TRY_LOCK_POWER),
1366 1386 FLINTSTR(D_LOCKS, PMR_PPM_POWER_LOCK_OWNER),
1367 1387 FLINTSTR(D_CTLOPS1 | D_CTLOPS2, PMR_PPM_ENTER_SX),
1368 1388 FLINTSTR(D_CTLOPS1 | D_CTLOPS2, PMR_UNKNOWN),
1369 1389 };
1370 1390
1371 1391 for (ccp = cmds; ccp->ctlop != PMR_UNKNOWN; ccp++)
1372 1392 if (ctlop == ccp->ctlop)
1373 1393 break;
1374 1394
1375 1395 if (ccp->flags & mask)
1376 1396 return (ccp->str);
1377 1397 return (NULL);
1378 1398 }
1379 1399
1380 1400 void
1381 1401 ppm_print_dc(ppm_dc_t *dc)
1382 1402 {
1383 1403 ppm_dc_t *d = dc;
1384 1404
1385 1405 PPMD(D_PPMDC, ("\nAdds ppm_dc: path(%s),\n cmd(%x), "
1386 1406 "method(%x), ", d->path, d->cmd, d->method))
1387 1407 if (d->method == PPMDC_KIO) {
1388 1408 PPMD(D_PPMDC, ("kio.iowr(%x), kio.val(0x%X)",
1389 1409 d->m_un.kio.iowr, d->m_un.kio.val))
1390 1410 #ifdef sun4u
1391 1411 } else if (d->method == PPMDC_I2CKIO) {
1392 1412 PPMD(D_PPMDC, ("i2c.iowr(%x), i2c.val(0x%X), "
1393 1413 "i2c.mask(0x%X)", d->m_un.i2c.iowr,
1394 1414 d->m_un.i2c.val, d->m_un.i2c.mask))
1395 1415 #endif
1396 1416 } else if (d->method == PPMDC_VCORE) {
1397 1417 PPMD(D_PPMDC, ("cpu: .iord(%x), .iowr(%x), .val(0x%X), "
1398 1418 ".delay(0x%x)",
1399 1419 d->m_un.cpu.iord, d->m_un.cpu.iowr, d->m_un.cpu.val,
1400 1420 d->m_un.cpu.delay))
1401 1421 } else if (d->method == PPMDC_CPUSPEEDKIO) {
1402 1422 PPMD(D_PPMDC, ("cpu.iowr(%x), cpu.speeds(0x%X)",
1403 1423 d->m_un.cpu.iowr, d->m_un.cpu.speeds))
1404 1424 }
1405 1425 PPMD(D_PPMDC, ("\n"))
1406 1426 }
1407 1427 #endif /* DEBUG */
|
↓ open down ↓ |
984 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX