aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2010-08-01 20:13:56 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2010-11-29 23:35:08 -0500
commitd9626947f20b3dc0992e4ac28b477f7601f8f16e (patch)
tree8ba2e79713cf16a0a51ee6639b634ffed337bb92 /arch
parentcf5cbf9f8085eb45316d6e3c888a77cc50696701 (diff)
powerpc/nvram: Change nvram_setup_partition() to use new helper
This changes the function to use nvram_find_partition() instead of doing the lookup "by hand". It also makes some of the logic clearer and prints out more useful diagnostic information. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/powerpc/kernel/nvram_64.c71
1 files changed, 32 insertions, 39 deletions
diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c
index 01e6844be8d7..76f546b9944d 100644
--- a/arch/powerpc/kernel/nvram_64.c
+++ b/arch/powerpc/kernel/nvram_64.c
@@ -469,9 +469,8 @@ loff_t nvram_find_partition(const char *name, int sig, int *out_size)
469 */ 469 */
470static int __init nvram_setup_partition(void) 470static int __init nvram_setup_partition(void)
471{ 471{
472 struct list_head * p; 472 loff_t p;
473 struct nvram_partition * part; 473 int size;
474 int rc;
475 474
476 /* For now, we don't do any of this on pmac, until I 475 /* For now, we don't do any of this on pmac, until I
477 * have figured out if it's worth killing some unused stuffs 476 * have figured out if it's worth killing some unused stuffs
@@ -481,48 +480,42 @@ static int __init nvram_setup_partition(void)
481 if (machine_is(powermac)) 480 if (machine_is(powermac))
482 return -ENOSPC; 481 return -ENOSPC;
483 482
484 /* see if we have an OS partition that meets our needs. 483 p = nvram_find_partition("ppc64,linux", NVRAM_SIG_OS, &size);
485 will try getting the max we need. If not we'll delete
486 partitions and try again. */
487 list_for_each(p, &nvram_part->partition) {
488 part = list_entry(p, struct nvram_partition, partition);
489 if (part->header.signature != NVRAM_SIG_OS)
490 continue;
491
492 if (strcmp(part->header.name, "ppc64,linux"))
493 continue;
494
495 if ((part->header.length - 1) * NVRAM_BLOCK_LEN >= NVRAM_MIN_REQ) {
496 /* found our partition */
497 nvram_error_log_index = part->index + NVRAM_HEADER_LEN;
498 nvram_error_log_size = ((part->header.length - 1) *
499 NVRAM_BLOCK_LEN) - sizeof(struct err_log_info);
500 return 0;
501 }
502 484
503 /* Found one but it's too small, remove it */ 485 /* Found one but too small, remove it */
486 if (p && size < NVRAM_MIN_REQ) {
487 pr_info("nvram: Found too small ppc64,linux partition"
488 ",removing it...");
504 nvram_remove_partition("ppc64,linux", NVRAM_SIG_OS); 489 nvram_remove_partition("ppc64,linux", NVRAM_SIG_OS);
490 p = 0;
505 } 491 }
506 492
507 /* try creating a partition with the free space we have */ 493 /* Create one if we didn't find */
508 rc = nvram_create_partition("ppc64,linux", NVRAM_SIG_OS, 494 if (!p) {
509 NVRAM_MAX_REQ, NVRAM_MIN_REQ); 495 p = nvram_create_partition("ppc64,linux", NVRAM_SIG_OS,
510 if (rc < 0) { 496 NVRAM_MAX_REQ, NVRAM_MIN_REQ);
511 /* need to free up some space, remove any "OS" partition */ 497 /* No room for it, try to get rid of any OS partition
512 nvram_remove_partition(NULL, NVRAM_SIG_OS); 498 * and try again
513 499 */
514 /* Try again */ 500 if (p == -ENOSPC) {
515 rc = nvram_create_partition("ppc64,linux", NVRAM_SIG_OS, 501 pr_info("nvram: No room to create ppc64,linux"
516 NVRAM_MAX_REQ, NVRAM_MIN_REQ); 502 " partition, deleting all OS partitions...");
517 if (rc < 0) { 503 nvram_remove_partition(NULL, NVRAM_SIG_OS);
518 pr_err("nvram_create_partition: Could not find" 504 p = nvram_create_partition("ppc64,linux", NVRAM_SIG_OS,
519 " enough space in NVRAM for partition\n"); 505 NVRAM_MAX_REQ, NVRAM_MIN_REQ);
520 return rc;
521 } 506 }
522 } 507 }
508
509 if (p <= 0) {
510 pr_err("nvram: Failed to find or create ppc64,linux"
511 " partition, err %d\n", (int)p);
512 return 0;
513 }
514
515 nvram_error_log_index = p;
516 nvram_error_log_size = nvram_get_partition_size(p) -
517 sizeof(struct err_log_info);
523 518
524 nvram_error_log_index = rc;
525 nvram_error_log_size = nvram_get_partition_size(rc) - sizeof(struct err_log_info);
526 return 0; 519 return 0;
527} 520}
528 521