diff options
author | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2010-07-29 01:28:20 -0400 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2010-11-29 23:31:51 -0500 |
commit | 4e7c77a385efac81d6677a4a761b1b66cd2cb59e (patch) | |
tree | 1335c5cdf9529e656043fc6f92bffdb67e2f2532 /arch/powerpc | |
parent | 74d51d029818eca9d1aec22dd2895e269c0044b1 (diff) |
powerpc/nvram: More flexible nvram_create_partition()
Replace nvram_create_os_partition() with a variant that takes
the partition name, signature and size as arguments.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r-- | arch/powerpc/kernel/nvram_64.c | 46 | ||||
-rw-r--r-- | arch/powerpc/platforms/pseries/nvram.c | 6 |
2 files changed, 31 insertions, 21 deletions
diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c index a8154f1813df..9e133355f742 100644 --- a/arch/powerpc/kernel/nvram_64.c +++ b/arch/powerpc/kernel/nvram_64.c | |||
@@ -307,13 +307,15 @@ static int __init nvram_remove_os_partition(void) | |||
307 | return 0; | 307 | return 0; |
308 | } | 308 | } |
309 | 309 | ||
310 | /* nvram_create_os_partition | 310 | /** |
311 | * | 311 | * nvram_create_partition - Create a partition in nvram |
312 | * Create a OS linux partition to buffer error logs. | 312 | * @name: name of the partition to create |
313 | * Will create a partition starting at the first free | 313 | * @sig: signature of the partition to create |
314 | * space found if space has enough room. | 314 | * @req_size: size to allocate preferrably |
315 | * @min_size: minimum acceptable size (0 means req_size) | ||
315 | */ | 316 | */ |
316 | static int __init nvram_create_os_partition(void) | 317 | static int __init nvram_create_partition(const char *name, int sig, |
318 | int req_size, int min_size) | ||
317 | { | 319 | { |
318 | struct nvram_partition *part; | 320 | struct nvram_partition *part; |
319 | struct nvram_partition *new_part; | 321 | struct nvram_partition *new_part; |
@@ -322,20 +324,27 @@ static int __init nvram_create_os_partition(void) | |||
322 | loff_t tmp_index; | 324 | loff_t tmp_index; |
323 | long size = 0; | 325 | long size = 0; |
324 | int rc; | 326 | int rc; |
325 | 327 | ||
328 | /* If no minimum size specified, make it the same as the | ||
329 | * requested size | ||
330 | */ | ||
331 | if (min_size == 0) | ||
332 | min_size = req_size; | ||
333 | |||
326 | /* Find a free partition that will give us the maximum needed size | 334 | /* Find a free partition that will give us the maximum needed size |
327 | If can't find one that will give us the minimum size needed */ | 335 | If can't find one that will give us the minimum size needed */ |
328 | list_for_each_entry(part, &nvram_part->partition, partition) { | 336 | list_for_each_entry(part, &nvram_part->partition, partition) { |
329 | if (part->header.signature != NVRAM_SIG_FREE) | 337 | if (part->header.signature != NVRAM_SIG_FREE) |
330 | continue; | 338 | continue; |
331 | 339 | ||
332 | if (part->header.length >= NVRAM_MAX_REQ) { | 340 | if (part->header.length >= req_size) { |
333 | size = NVRAM_MAX_REQ; | 341 | size = req_size; |
334 | free_part = part; | 342 | free_part = part; |
335 | break; | 343 | break; |
336 | } | 344 | } |
337 | if (!size && part->header.length >= NVRAM_MIN_REQ) { | 345 | if (part->header.length > size && |
338 | size = NVRAM_MIN_REQ; | 346 | part->header.length >= min_size) { |
347 | size = part->header.length; | ||
339 | free_part = part; | 348 | free_part = part; |
340 | } | 349 | } |
341 | } | 350 | } |
@@ -350,9 +359,9 @@ static int __init nvram_create_os_partition(void) | |||
350 | } | 359 | } |
351 | 360 | ||
352 | new_part->index = free_part->index; | 361 | new_part->index = free_part->index; |
353 | new_part->header.signature = NVRAM_SIG_OS; | 362 | new_part->header.signature = sig; |
354 | new_part->header.length = size; | 363 | new_part->header.length = size; |
355 | strcpy(new_part->header.name, "ppc64,linux"); | 364 | strncpy(new_part->header.name, name, 12); |
356 | new_part->header.checksum = nvram_checksum(&new_part->header); | 365 | new_part->header.checksum = nvram_checksum(&new_part->header); |
357 | 366 | ||
358 | rc = nvram_write_header(new_part); | 367 | rc = nvram_write_header(new_part); |
@@ -451,10 +460,10 @@ static int __init nvram_setup_partition(void) | |||
451 | } | 460 | } |
452 | 461 | ||
453 | /* try creating a partition with the free space we have */ | 462 | /* try creating a partition with the free space we have */ |
454 | rc = nvram_create_partition("ppc64,linux", ); | 463 | rc = nvram_create_partition("ppc64,linux", NVRAM_SIG_OS, |
455 | if (!rc) { | 464 | NVRAM_MAX_REQ, NVRAM_MIN_REQ); |
465 | if (!rc) | ||
456 | return 0; | 466 | return 0; |
457 | } | ||
458 | 467 | ||
459 | /* need to free up some space */ | 468 | /* need to free up some space */ |
460 | rc = nvram_remove_os_partition(); | 469 | rc = nvram_remove_os_partition(); |
@@ -463,9 +472,10 @@ static int __init nvram_setup_partition(void) | |||
463 | } | 472 | } |
464 | 473 | ||
465 | /* create a partition in this new space */ | 474 | /* create a partition in this new space */ |
466 | rc = nvram_create_os_partition(); | 475 | rc = nvram_create_partition("ppc64,linux", NVRAM_SIG_OS, |
476 | NVRAM_MAX_REQ, NVRAM_MIN_REQ); | ||
467 | if (rc) { | 477 | if (rc) { |
468 | printk(KERN_ERR "nvram_create_os_partition: Could not find a " | 478 | printk(KERN_ERR "nvram_create_partition: Could not find a " |
469 | "NVRAM partition large enough\n"); | 479 | "NVRAM partition large enough\n"); |
470 | return rc; | 480 | return rc; |
471 | } | 481 | } |
diff --git a/arch/powerpc/platforms/pseries/nvram.c b/arch/powerpc/platforms/pseries/nvram.c index f4e4c06284b4..2a1ef5c25344 100644 --- a/arch/powerpc/platforms/pseries/nvram.c +++ b/arch/powerpc/platforms/pseries/nvram.c | |||
@@ -22,14 +22,14 @@ | |||
22 | #include <asm/prom.h> | 22 | #include <asm/prom.h> |
23 | #include <asm/machdep.h> | 23 | #include <asm/machdep.h> |
24 | 24 | ||
25 | /* Max bytes to read/write in one go */ | ||
26 | #define NVRW_CNT 0x20 | ||
27 | |||
25 | static unsigned int nvram_size; | 28 | static unsigned int nvram_size; |
26 | static int nvram_fetch, nvram_store; | 29 | static int nvram_fetch, nvram_store; |
27 | static char nvram_buf[NVRW_CNT]; /* assume this is in the first 4GB */ | 30 | static char nvram_buf[NVRW_CNT]; /* assume this is in the first 4GB */ |
28 | static DEFINE_SPINLOCK(nvram_lock); | 31 | static DEFINE_SPINLOCK(nvram_lock); |
29 | 32 | ||
30 | /* Max bytes to read/write in one go */ | ||
31 | #define NVRW_CNT 0x20 | ||
32 | |||
33 | static ssize_t pSeries_nvram_read(char *buf, size_t count, loff_t *index) | 33 | static ssize_t pSeries_nvram_read(char *buf, size_t count, loff_t *index) |
34 | { | 34 | { |
35 | unsigned int i; | 35 | unsigned int i; |