Clean up ppc64 nvram code
This series is a first go at cleaning up some cruft in nvram_64.c for handling nvram partitions. The current ppc64,linux partition is really pseries specific, so we change the code for finding/creating it gets turned into a more generic API for manipulating nvram partitions, and the specifics to that partition are moved to pseries. We also rename it to better represent what it's for
PATCH 1/11 powerpc/nvram: Move things out of asm/nvram.h
This moves a bunch of definitions out of asm/nvram.h to the files that use them or just outright remove completely unused stuff.
We leave the partition signatures definitions, they will be useful
--- arch/powerpc/include/asm/nvram.h | 42 +------------------------------ arch/powerpc/kernel/nvram_64.c | 21 +++++++++++++++- arch/powerpc/platforms/chrp/time.c | 4 +++ arch/powerpc/platforms/pseries/nvram.c | 2 + 4 files changed, 28 insertions(+), 41 deletions(-)
arch/powerpc/include/asm/nvram.h +2 -40
@@ -10,31 +10,7 @@#ifndef _ASM_POWERPC_NVRAM_H#define _ASM_POWERPC_NVRAM_H -#include <linux/errno.h> - -#define NVRW_CNT 0x20 -#define NVRAM_HEADER_LEN 16/* sizeof(struct nvram_header) */ -#define NVRAM_BLOCK_LEN 16 -#define NVRAM_MAX_REQ (2080/NVRAM_BLOCK_LEN) -#define NVRAM_MIN_REQ (1056/NVRAM_BLOCK_LEN) - -#define NVRAM_AS0 0x74 -#define NVRAM_AS1 0x75 -#define NVRAM_DATA 0x77 - - -/* RTC Offsets */ - -#define MOTO_RTC_SECONDS 0x1FF9 -#define MOTO_RTC_MINUTES 0x1FFA -#define MOTO_RTC_HOURS 0x1FFB -#define MOTO_RTC_DAY_OF_WEEK 0x1FFC -#define MOTO_RTC_DAY_OF_MONTH 0x1FFD -#define MOTO_RTC_MONTH 0x1FFE -#define MOTO_RTC_YEAR 0x1FFF -#define MOTO_RTC_CONTROLA 0x1FF8 -#define MOTO_RTC_CONTROLB 0x1FF9 - +/* Signatures for nvram partitions */ #define NVRAM_SIG_SP 0x02/* support processor */ #define NVRAM_SIG_OF 0x50/* open firmware config */ #define NVRAM_SIG_FW 0x51/* general firmware */
@@ -49,25 +25,11 @@#define NVRAM_SIG_OS 0xa0/* OS defined */ #define NVRAM_SIG_PANIC 0xa1/* Apple OSX "panic" */ -/* If change this size, then change the size of NVNAME_LEN */ -struct nvram_header { -unsigned char signature; -unsigned char checksum; -unsigned short length; -char name[12 ]; -}; -#ifdef __KERNEL__ +#include <linux/errno.h> #include <linux/list.h> -struct nvram_partition { -struct list_head partition; -struct nvram_header header; -unsigned int index; -}; - -extern int nvram_write_error_log (char * buff,int length,unsigned int err_type,unsigned int err_seq); extern int nvram_read_error_log(char * buff, int length,
arch/powerpc/kernel/nvram_64.c +20 -1
@@ -34,6 +34,25 @@#undef DEBUG_NVRAM +#define NVRAM_HEADER_LEN 16/* sizeof(struct nvram_header) */ +#define NVRAM_BLOCK_LEN 16 +#define NVRAM_MAX_REQ (2080/NVRAM_BLOCK_LEN) +#define NVRAM_MIN_REQ (1056/NVRAM_BLOCK_LEN) + +/* If change this size, then change the size of NVNAME_LEN */ +struct nvram_header { +unsigned char signature; +unsigned char checksum; +unsigned short length; +char name[12 ]; +}; + +struct nvram_partition { +struct list_head partition; +struct nvram_header header; +unsigned int index; +}; +static struct nvram_partition * nvram_part;static long nvram_error_log_index =-1 ;static long nvram_error_log_size =0 ;
@@ -432,7 +451,7 @@ static int __init nvram_setup_partition(void) }/* try creating a partition with the free space we have */ - rc =nvram_create_os_partition (); + rc = nvram_create_partition("ppc64,linux", );if (!rc) {return 0 ; }
arch/powerpc/platforms/chrp/time.c +4 -0
@@ -29,6 +29,10 @@extern spinlock_t rtc_lock; +#define NVRAM_AS0 0x74 +#define NVRAM_AS1 0x75 +#define NVRAM_DATA 0x77 +static int nvram_as1 =NVRAM_AS1 ;static int nvram_as0 =NVRAM_AS0 ;static int nvram_data =NVRAM_DATA ;
arch/powerpc/platforms/pseries/nvram.c +2 -0
@@ -27,6 +27,8 @@ static int nvram_fetch, nvram_store;static char nvram_buf[NVRW_CNT ];/* assume this is in the first 4GB */ static DEFINE_SPINLOCK (nvram_lock); +/* Max bytes to read/write in one go */ +#define NVRW_CNT 0x20static ssize_t pSeries_nvram_read (char *buf,size_t count,loff_t *index) {
Signature · 1 line
1.6.3.3
PATCH 2/11 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.
--- arch/powerpc/kernel/nvram_64.c | 46 +++++++++++++++++++------------ arch/powerpc/platforms/pseries/nvram.c | 6 ++-- 2 files changed, 31 insertions(+), 21 deletions(-)
arch/powerpc/kernel/nvram_64.c +28 -18
@@ -307,13 +307,15 @@ static int __init nvram_remove_os_partition(void)return 0 ; } -/* nvram_create_os_partition -* -* Create a OS linux partition to buffer error logs. -* Will create a partition starting at the first free -* space found if space has enough room. +/** +* nvram_create_partition - Create a partition in nvram +* @name: name of the partition to create +* @sig: signature of the partition to create +* @req_size: size to allocate preferrably +* @min_size: minimum acceptable size (0 means req_size) */ -static int __init nvram_create_os_partition (void ) +static int __init nvram_create_partition (const char *name,int sig, +int req_size,int min_size) {struct nvram_partition *part;struct nvram_partition *new_part;
@@ -322,20 +324,27 @@ static int __init nvram_create_os_partition(void)loff_t tmp_index;long size =0 ;int rc; - + +/* If no minimum size specified, make it the same as the +* requested size +*/ +if (min_size ==0 ) + min_size = req_size; +/* Find a free partition that will give us the maximum needed size If can't find one that will give us the minimum size needed */ list_for_each_entry (part, &nvram_part->partition, partition) {if (part->header.signature !=NVRAM_SIG_FREE )continue ; -if (part->header.length >=NVRAM_MAX_REQ ) { - size =NVRAM_MAX_REQ ; +if (part->header.length >= req_size) { + size = req_size; free_part = part;break ; } -if (!size && part->header.length >=NVRAM_MIN_REQ ) { - size =NVRAM_MIN_REQ ; +if (part->header.length > size && + part->header.length >= min_size) { + size = part->header.length; free_part = part; } }
@@ -350,9 +359,9 @@ static int __init nvram_create_os_partition(void) } new_part->index = free_part->index; - new_part->header.signature =NVRAM_SIG_OS ; + new_part->header.signature = sig; new_part->header.length = size; -strcpy (new_part->header.name,"ppc64,linux" ); +strncpy (new_part->header.name, name,12 ); new_part->header.checksum =nvram_checksum (&new_part->header); rc =nvram_write_header (new_part);
@@ -451,10 +460,10 @@ static int __init nvram_setup_partition(void) }/* try creating a partition with the free space we have */ - rc = nvram_create_partition("ppc64,linux", ); -if (!rc) { + rc =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , +NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); +if (!rc)return 0 ; - }/* need to free up some space */ rc =nvram_remove_os_partition ();
@@ -463,9 +472,10 @@ static int __init nvram_setup_partition(void) }/* create a partition in this new space */ - rc =nvram_create_os_partition (); + rc =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , +NVRAM_MIN_REQ ,NVRAM_MAX_REQ );if (rc) { -printk (KERN_ERR "nvram_create_os_partition: Could not find a " +printk (KERN_ERR "nvram_create_partition: Could not find a " "NVRAM partition large enough\n" );return rc; }
arch/powerpc/platforms/pseries/nvram.c +3 -3
@@ -22,14 +22,14 @@#include <asm/prom.h> #include <asm/machdep.h> +/* Max bytes to read/write in one go */ +#define NVRW_CNT 0x20 +static unsigned int nvram_size;static int nvram_fetch, nvram_store;static char nvram_buf[NVRW_CNT ];/* assume this is in the first 4GB */ static DEFINE_SPINLOCK (nvram_lock); -/* Max bytes to read/write in one go */ -#define NVRW_CNT 0x20 -static ssize_t pSeries_nvram_read (char *buf,size_t count,loff_t *index) {unsigned int i;
Signature · 1 line
1.6.3.3
PATCH 3/11 powerpc/nvram: nvram_create_partitions() now uses bytes
This converts nvram_create_partition() to use a size in bytes rather than blocks. It does the appropriate alignment internally
The size passed is also the data size (ie. doesn't include the header anymore).
--- arch/powerpc/kernel/nvram_64.c | 20 ++++++++++++++------ 1 files changed, 14 insertions(+), 6 deletions(-)
arch/powerpc/kernel/nvram_64.c +14 -6
@@ -34,10 +34,10 @@#undef DEBUG_NVRAM -#define NVRAM_HEADER_LEN 16/* sizeof(struct nvram_header) */ -#define NVRAM_BLOCK_LEN 16 -#define NVRAM_MAX_REQ (2080/NVRAM_BLOCK_LEN) -#define NVRAM_MIN_REQ (1056/NVRAM_BLOCK_LEN) +#define NVRAM_HEADER_LEN sizeof(struct nvram_header) +#define NVRAM_BLOCK_LEN NVRAM_HEADER_LEN +#define NVRAM_MAX_REQ 2079 +#define NVRAM_MIN_REQ 1055/* If change this size, then change the size of NVNAME_LEN */ struct nvram_header {
@@ -311,7 +311,7 @@ static int __init nvram_remove_os_partition(void)* nvram_create_partition - Create a partition in nvram * @name: name of the partition to create * @sig: signature of the partition to create -* @req_size: size to allocate preferrably +* @req_size: size of data to allocate in bytes * @min_size: minimum acceptable size (0 means req_size) */ static int __init nvram_create_partition(const char *name, int sig,
@@ -325,12 +325,20 @@ static int __init nvram_create_partition(const char *name, int sig,long size =0 ;int rc; +/* Convert sizes from bytes to blocks */ + req_size =_ALIGN_UP (req_size,NVRAM_BLOCK_LEN ) /NVRAM_BLOCK_LEN ; + min_size =_ALIGN_UP (min_size,NVRAM_BLOCK_LEN ) /NVRAM_BLOCK_LEN ; +/* If no minimum size specified, make it the same as the * requested size */ if (min_size ==0 ) min_size = req_size; +/* Now add one block to each for the header */ + req_size +=1 ; + min_size +=1 ; +/* Find a free partition that will give us the maximum needed size If can't find one that will give us the minimum size needed */ list_for_each_entry (part, &nvram_part->partition, partition) {
@@ -450,7 +458,7 @@ static int __init nvram_setup_partition(void)if (strcmp (part->header.name,"ppc64,linux" ))continue ; -if (part->header.length >=NVRAM_MIN_REQ ) { +if ((part->header.length -1 ) *NVRAM_BLOCK_LEN >=NVRAM_MIN_REQ ) {/* found our partition */ nvram_error_log_index = part->index +NVRAM_HEADER_LEN ; nvram_error_log_size = ((part->header.length - 1) *
Signature · 1 line
1.6.3.3
PATCH 4/11 powerpc/nvram: Ensure that the partition header/block size is right
Use BUILD_BUG_ON to ensure the structure representing a partition header have the right size.
--- arch/powerpc/kernel/nvram_64.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
arch/powerpc/kernel/nvram_64.c +2 -0
@@ -565,6 +565,8 @@ static int __init nvram_init(void)int error;int rc; +BUILD_BUG_ON (NVRAM_BLOCK_LEN !=16 ); +if (ppc_md.nvram_size ==NULL || ppc_md.nvram_size () <=0 )return -ENODEV ;
Signature · 1 line
1.6.3.3
PATCH 5/11 powerpc/nvram: Completely clear a new partition
When creating a partition, we clear it entirely rather than just the first two words since the previous code was rather specific to the pseries log partition format.
--- arch/powerpc/kernel/nvram_64.c | 19 ++++++++++--------- 1 files changed, 10 insertions(+), 9 deletions(-)
arch/powerpc/kernel/nvram_64.c +10 -9
@@ -320,7 +320,7 @@ static int __init nvram_create_partition(const char *name, int sig,struct nvram_partition *part;struct nvram_partition *new_part;struct nvram_partition *free_part =NULL ; -int seq_init[2 ] = {0 ,0 }; +static char nv_init_vals[16 ];loff_t tmp_index;long size =0 ;int rc;
@@ -379,14 +379,15 @@ static int __init nvram_create_partition(const char *name, int sig,return rc; } -/* make sure and initialize to zero the sequence number and the error -type logged */ - tmp_index = new_part->index +NVRAM_HEADER_LEN ; - rc = ppc_md.nvram_write ((char *)&seq_init,sizeof (seq_init), &tmp_index); -if (rc <=0 ) { -printk (KERN_ERR "nvram_create_os_partition: nvram_write " -"failed (%d)\n" , rc); -return rc; +/* Clear the partition */ +for (tmp_index = new_part->index +NVRAM_HEADER_LEN ; + tmp_index < ((size -1 ) *NVRAM_BLOCK_LEN ); + tmp_index +=NVRAM_BLOCK_LEN ) { + rc = ppc_md.nvram_write (nv_init_vals,NVRAM_BLOCK_LEN , &tmp_index); +if (rc <=0 ) { +pr_err ("nvram_create_partition: nvram_write failed (%d)\n" , rc); +return rc; + } } nvram_error_log_index = new_part->index +NVRAM_HEADER_LEN ;
Signature · 1 line
1.6.3.3
PATCH 6/11 powerpc/nvram: Shuffle code around in nvram_create_partition()
This error log stuff is really pseries specific. As a first step we move the initialization of these variables to the caller of nvram_create_partition(), which is also slightly reorganized so we setup the free partition before we clear the new partition, so the chance of an error during clear leaving us with invalid headers is lessened.
--- arch/powerpc/kernel/nvram_64.c | 107 +++++++++++++++++++++++----------------- 1 files changed, 62 insertions(+), 45 deletions(-)
arch/powerpc/kernel/nvram_64.c +62 -45
@@ -313,9 +313,15 @@ static int __init nvram_remove_os_partition(void)* @sig: signature of the partition to create * @req_size: size of data to allocate in bytes * @min_size: minimum acceptable size (0 means req_size) +* +* Returns a negative error code or a positive nvram index +* of the beginning of the data area of the newly created +* partition. If you provided a min_size smaller than req_size +* you need to query for the actual size yourself after the +* call using nvram_partition_get_size(). */ -static int __init nvram_create_partition (const char *name,int sig, -int req_size,int min_size) +static loff_t __init nvram_create_partition (const char *name,int sig, +int req_size,int min_size) {struct nvram_partition *part;struct nvram_partition *new_part;
@@ -334,6 +340,8 @@ static int __init nvram_create_partition(const char *name, int sig,*/ if (min_size ==0 ) min_size = req_size; +if (min_size > req_size) +return -EINVAL ;/* Now add one block to each for the header */ req_size +=1 ;
@@ -362,7 +370,7 @@ static int __init nvram_create_partition(const char *name, int sig,/* Create our OS partition */ new_part =kmalloc (sizeof (*new_part),GFP_KERNEL );if (!new_part) { -printk (KERN_ERR "nvram_create_os_partition: kmalloc failed\n" ); +pr_err ("nvram_create_os_partition: kmalloc failed\n" );return -ENOMEM ; }
@@ -374,12 +382,29 @@ static int __init nvram_create_partition(const char *name, int sig, rc =nvram_write_header (new_part);if (rc <=0 ) { -printk (KERN_ERR "nvram_create_os_partition: nvram_write_header " -"failed (%d)\n" , rc); +pr_err ("nvram_create_os_partition: nvram_write_header " +"failed (%d)\n" , rc);return rc; } +list_add_tail (&new_part->partition, &free_part->partition); -/* Clear the partition */ +/* Adjust or remove the partition we stole the space from */ +if (free_part->header.length > size) { + free_part->index += size *NVRAM_BLOCK_LEN ; + free_part->header.length -= size; + free_part->header.checksum =nvram_checksum (&free_part->header); + rc =nvram_write_header (free_part); +if (rc <=0 ) { +pr_err ("nvram_create_os_partition: nvram_write_header " +"failed (%d)\n" , rc); +return rc; + } + }else { +list_del (&free_part->partition); +kfree (free_part); + } + +/* Clear the new partition */ for (tmp_index = new_part->index +NVRAM_HEADER_LEN ; tmp_index < ((size -1 ) *NVRAM_BLOCK_LEN ); tmp_index +=NVRAM_BLOCK_LEN ) {
@@ -390,31 +415,24 @@ static int __init nvram_create_partition(const char *name, int sig, } } - nvram_error_log_index = new_part->index +NVRAM_HEADER_LEN ; - nvram_error_log_size = ((part->header.length -1 ) * -NVRAM_BLOCK_LEN ) -sizeof (struct err_log_info ); - -list_add_tail (&new_part->partition, &free_part->partition); - -if (free_part->header.length <= size) { -list_del (&free_part->partition); -kfree (free_part); -return 0 ; - } +return new_part->index +NVRAM_HEADER_LEN ; +} -/* Adjust the partition we stole the space from */ - free_part->index += size *NVRAM_BLOCK_LEN ; - free_part->header.length -= size; - free_part->header.checksum =nvram_checksum (&free_part->header); +/** +* nvram_get_partition_size - Get the data size of an nvram partition +* @data_index: This is the offset of the start of the data of +* the partition. The same value that is returned by +* nvram_create_partition(). +*/ +static int nvram_get_partition_size (loff_t data_index) +{ +struct nvram_partition *part; - rc =nvram_write_header (free_part); -if (rc <=0 ) { -printk (KERN_ERR "nvram_create_os_partition: nvram_write_header " -"failed (%d)\n" , rc); -return rc; +list_for_each_entry (part, &nvram_part->partition, partition) { +if (part->index +NVRAM_HEADER_LEN == data_index) +return (part->header.length -1 ) *NVRAM_BLOCK_LEN ; } - -return 0 ; +return -1 ; }
@@ -469,30 +487,29 @@ static int __init nvram_setup_partition(void) }/* try creating a partition with the free space we have */ - rc =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , + rc =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS ,NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); -if (!rc) -return 0 ; - -/* need to free up some space */ - rc =nvram_remove_os_partition (); -if (rc) { -return rc; +if (rc <0 ) { +/* need to free up some space */ + rc =nvram_remove_os_partition (); +if (rc) +return rc; +/* create a partition in this new space */ + rc =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , +NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); +if (rc <0 ) { +pr_err ("nvram_create_partition: Could not find" +" enough space in NVRAM for partition\n" ); +return rc; + } } -/* create a partition in this new space */ - rc =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , -NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); -if (rc) { -printk (KERN_ERR "nvram_create_partition: Could not find a " -"NVRAM partition large enough\n" ); -return rc; - } + nvram_error_log_index = rc; + nvram_error_log_size =nvram_get_partition_size (rc) -sizeof (struct err_log_info );return 0 ; } -static int __init nvram_scan_partitions (void ) {loff_t cur_index =0 ;
Signature · 1 line
1.6.3.3
PATCH 7/11 powerpc/nvram: Improve partition removal
Existing code is nasty, has bugs etc... rewrite the function more simply, and make it take the signature and optional name of the partitions to remove as arguments, thus making it a more generic utility.
We also try to remove a log partition that we find and is too small rather than creating a duplicate.
--- arch/powerpc/kernel/nvram_64.c | 91 +++++++++++++++++++--------------------- 1 files changed, 43 insertions(+), 48 deletions(-)
arch/powerpc/kernel/nvram_64.c +43 -48
@@ -247,61 +247,54 @@ static unsigned char __init nvram_checksum(struct nvram_header *p)return c_sum; } -static int __init nvram_remove_os_partition (void ) +/** +* nvram_remove_partition - Remove one or more partitions in nvram +* @name: name of the partition to remove, or NULL for a +* signature only match +* @sig: signature of the partition(s) to remove +*/ + +static int __init nvram_remove_partition (const char *name,int sig) { -struct list_head *i; -struct list_head *j; -struct nvram_partition * part; -struct nvram_partition * cur_part; +struct nvram_partition *part, *prev, *tmp;int rc; -list_for_each (i, &nvram_part->partition) { - part = list_entry(i, struct nvram_partition, partition); -if (part->header.signature !=NVRAM_SIG_OS ) +list_for_each_entry (part, &nvram_part->partition, partition) { +if (part->header.signature != sig)continue ; - -/* Make os partition a free partition */ +if (name &&strncmp (name, part->header.name,12 )) +continue ; + +/* Make partition a free partition */ part->header.signature =NVRAM_SIG_FREE ;sprintf (part->header.name,"wwwwwwwwwwww" ); part->header.checksum =nvram_checksum (&part->header); - -/* Merge contiguous free partitions backwards */ -list_for_each_prev (j, &part->partition) { - cur_part = list_entry(j, struct nvram_partition, partition); -if (cur_part == nvram_part || cur_part->header.signature !=NVRAM_SIG_FREE ) { -break ; - } - - part->header.length += cur_part->header.length; - part->header.checksum =nvram_checksum (&part->header); - part->index = cur_part->index; - -list_del (&cur_part->partition); -kfree (cur_part); - j = &part->partition;/* fixup our loop */ - } - -/* Merge contiguous free partitions forwards */ -list_for_each (j, &part->partition) { - cur_part = list_entry(j, struct nvram_partition, partition); -if (cur_part == nvram_part || cur_part->header.signature !=NVRAM_SIG_FREE ) { -break ; - } - - part->header.length += cur_part->header.length; - part->header.checksum =nvram_checksum (&part->header); - -list_del (&cur_part->partition); -kfree (cur_part); - j = &part->partition;/* fixup our loop */ - } - rc =nvram_write_header (part);if (rc <=0 ) { -printk (KERN_ERR "nvram_remove_os_partition: nvram_write failed (%d)\n" , rc); +printk (KERN_ERR "nvram_remove_partition: nvram_write failed (%d)\n" , rc);return rc; } + } +/* Merge contiguous ones */ + prev =NULL ; +list_for_each_entry_safe (part, tmp, &nvram_part->partition, partition) { +if (part->header.signature !=NVRAM_SIG_FREE ) { + prev =NULL ; +continue ; + } +if (prev) { + prev->header.length += part->header.length; + prev->header.checksum =nvram_checksum (&part->header); + rc =nvram_write_header (part); +if (rc <=0 ) { +printk (KERN_ERR "nvram_remove_partition: nvram_write failed (%d)\n" , rc); +return rc; + } +list_del (&part->partition); +kfree (part); + }else + prev = part; }return 0 ;
@@ -484,17 +477,19 @@ static int __init nvram_setup_partition(void) NVRAM_BLOCK_LEN) - sizeof(struct err_log_info);return 0 ; } + +/* Found one but it's too small, remove it */ +nvram_remove_partition ("ppc64,linux" ,NVRAM_SIG_OS ); }/* try creating a partition with the free space we have */ rc =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS ,NVRAM_MIN_REQ ,NVRAM_MAX_REQ );if (rc <0 ) { -/* need to free up some space */ - rc =nvram_remove_os_partition (); -if (rc) -return rc; -/* create a partition in this new space */ +/* need to free up some space, remove any "OS" partition */ +nvram_remove_partition (NULL ,NVRAM_SIG_OS ); + +/* Try again */ rc =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS ,NVRAM_MIN_REQ ,NVRAM_MAX_REQ );if (rc <0 ) {
Signature · 1 line
1.6.3.3
PATCH 8/11 powerpc/nvram: Add nvram_find_partition()
--- arch/powerpc/kernel/nvram_64.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)
arch/powerpc/kernel/nvram_64.c +22 -0
@@ -429,6 +429,28 @@ static int nvram_get_partition_size(loff_t data_index) } +/** +* nvram_find_partition - Find an nvram partition by signature and name +* @name: Name of the partition or NULL for any name +* @sig: Signature to test against +* @out_size: if non-NULL, returns the size of the data part of the partition +*/ +loff_t nvram_find_partition (const char *name,int sig,int *out_size) +{ +struct nvram_partition *p; + +list_for_each_entry (p, &nvram_part->partition, partition) { +if (p->header.signature == sig && + (!name || !strncmp (p->header.name, name,12 ))) { +if (out_size) + *out_size = (p->header.length -1 ) * +NVRAM_BLOCK_LEN ; +return p->index +NVRAM_HEADER_LEN ; + } + } +return 0 ; +} +/* nvram_setup_partition * * This will setup the partition we need for buffering the
Signature · 1 line
1.6.3.3
PATCH 9/11 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.
--- arch/powerpc/kernel/nvram_64.c | 72 ++++++++++++++++++---------------------- 1 files changed, 32 insertions(+), 40 deletions(-)
arch/powerpc/kernel/nvram_64.c +32 -40
@@ -469,9 +469,8 @@ loff_t nvram_find_partition(const char *name, int sig, int *out_size)*/ static int __init nvram_setup_partition (void ) { -struct list_head * p; -struct nvram_partition * part; -int rc; +loff_t p; +int size;/* For now, we don't do any of this on pmac, until I * have figured out if it's worth killing some unused stuffs
@@ -481,48 +480,41 @@ static int __init nvram_setup_partition(void)if (machine_is (powermac))return -ENOSPC ; -/* see if we have an OS partition that meets our needs. -will try getting the max we need. If not we'll delete -partitions and try again. */ -list_for_each (p, &nvram_part->partition) { - part = list_entry(p, struct nvram_partition, partition); -if (part->header.signature !=NVRAM_SIG_OS ) -continue ; - -if (strcmp (part->header.name,"ppc64,linux" )) -continue ; - -if ((part->header.length -1 ) *NVRAM_BLOCK_LEN >=NVRAM_MIN_REQ ) { -/* found our partition */ - nvram_error_log_index = part->index +NVRAM_HEADER_LEN ; - nvram_error_log_size = ((part->header.length -1 ) * -NVRAM_BLOCK_LEN ) -sizeof (struct err_log_info ); -return 0 ; - } + p =nvram_find_partition ("ppc64,linux" ,NVRAM_SIG_OS , &size); -/* Found one but it's too small, remove it */ +/* Found one but too small, remove it */ +if (p && size <NVRAM_MIN_REQ ) { +pr_info ("nvram: Found too small ppc64,linux partition" +",removing it..." );nvram_remove_partition ("ppc64,linux" ,NVRAM_SIG_OS ); + p =0 ; } - -/* try creating a partition with the free space we have */ - rc =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , -NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); -if (rc <0 ) { -/* need to free up some space, remove any "OS" partition */ -nvram_remove_partition (NULL ,NVRAM_SIG_OS ); - -/* Try again */ - rc =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , -NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); -if (rc <0 ) { -pr_err ("nvram_create_partition: Could not find" -" enough space in NVRAM for partition\n" ); -return rc; + +/* Create one if we didn't find */ +if (!p) { + p =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , +NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); +/* No room for it, try to get rid of any OS partition +* and try again +*/ +if (p == -ENOSPC ) { +pr_info ("nvram: No room to create ppc64,linux" +" partition, deleting all OS partitions..." ); +nvram_remove_partition (NULL ,NVRAM_SIG_OS ); + p =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , +NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); } } - - nvram_error_log_index = rc; - nvram_error_log_size =nvram_get_partition_size (rc) -sizeof (struct err_log_info ); + +if (p <=0 ) { +pr_err ("nvram: Failed to find or create ppc64,linux" +" partition, err %d\n" , (int )p); +return 0 ; + } + + nvram_error_log_index = p; + nvram_error_log_size =nvram_get_partition_size (p) - +sizeof (struct err_log_info );return 0 ; }
Signature · 1 line
1.6.3.3
PATCH 10/11 powerpc/nvram: Move the log partition stuff to pseries
The nvram log partition stuff currently in nvram_64.c is really pseries specific. It isn't actually used on anything else (despite the fact that we ran the code to setup the partition on anything except powermac) and the log format is specific to pseries RTAS implementation. So move it where it belongs
--- arch/powerpc/include/asm/nvram.h | 9 ++- arch/powerpc/kernel/nvram_64.c | 216 +------------------------------- arch/powerpc/platforms/pseries/nvram.c | 196 +++++++++++++++++++++++++++++ 3 files changed, 208 insertions(+), 213 deletions(-)
arch/powerpc/include/asm/nvram.h +8 -1
@@ -30,13 +30,14 @@#include <linux/errno.h> #include <linux/list.h> +#ifdef CONFIG_PPC_PSERIES extern int nvram_write_error_log (char * buff,int length,unsigned int err_type,unsigned int err_seq);extern int nvram_read_error_log (char * buff,int length,unsigned int * err_type,unsigned int *err_seq);extern int nvram_clear_error_log (void ); -extern int pSeries_nvram_init (void ); +#endif /* CONFIG_PPC_PSERIES */ #ifdef CONFIG_MMIO_NVRAM extern int mmio_nvram_init (void );
@@ -47,6 +48,12 @@ static inline int mmio_nvram_init(void) }#endif +extern loff_t nvram_create_partition (const char *name,int sig, +int req_size,int min_size); +extern int nvram_remove_partition (const char *name,int sig); +extern int nvram_get_partition_size (loff_t data_index); +extern loff_t nvram_find_partition (const char *name,int sig,int *out_size); +#endif /* __KERNEL__ */ /* PowerMac specific nvram stuffs */
arch/powerpc/kernel/nvram_64.c +4 -212
264 lines not on this page · raw message
arch/powerpc/platforms/pseries/nvram.c +196 -0
208 lines not on this page · raw message
Signature · 1 line
1.6.3.3
PATCH 11/11 powerpc/nvram: Rename ppc64, linux partition to ibm, rtas-log
I'm not aware of any userspace tool accessing it by its name anyways, it's read back by the kernel itself on the next boot to get back older log entries
--- arch/powerpc/platforms/pseries/nvram.c | 23 +++++++++++++---------- 1 files changed, 13 insertions(+), 10 deletions(-)
arch/powerpc/platforms/pseries/nvram.c +13 -10
@@ -40,6 +40,8 @@ struct err_log_info {#define NVRAM_MAX_REQ 2079#define NVRAM_MIN_REQ 1055 +#define NVRAM_LOG_PART_NAME "ibm,rtas-log" +static ssize_t pSeries_nvram_read (char *buf,size_t count,loff_t *index) {unsigned int i;
@@ -262,8 +264,8 @@ int nvram_clear_error_log(void)* error logs and cleanup partitions if needed. * * The general strategy is the following: -* 1.) If there is ppc64,linux partition large enough then use it. -* 2.) If there is not a ppc64,linux partition large enough, search +* 1.) If there is log partition large enough then use it. +* 2.) If there is none large enough, search * for a free partition that is large enough. * 3.) If there is not a free partition large enough remove * _all_ OS partitions and consolidate the space.
@@ -277,34 +279,35 @@ static int __init pseries_nvram_init_log_partition(void)loff_t p;int size; - p =nvram_find_partition ("ppc64,linux" ,NVRAM_SIG_OS , &size); + p =nvram_find_partition (NVRAM_LOG_PART_NAME ,NVRAM_SIG_OS , &size);/* Found one but too small, remove it */ if (p && size <NVRAM_MIN_REQ ) { -pr_info ("nvram: Found too small ppc64,linux partition" +pr_info ("nvram: Found too small " NVRAM_LOG_PART_NAME " partition" ",removing it..." ); -nvram_remove_partition ("ppc64,linux" ,NVRAM_SIG_OS ); +nvram_remove_partition (NVRAM_LOG_PART_NAME ,NVRAM_SIG_OS ); p =0 ; }/* Create one if we didn't find */ if (!p) { - p =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , + p =nvram_create_partition (NVRAM_LOG_PART_NAME ,NVRAM_SIG_OS ,NVRAM_MIN_REQ ,NVRAM_MAX_REQ );/* No room for it, try to get rid of any OS partition * and try again */ if (p == -ENOSPC ) { -pr_info ("nvram: No room to create ppc64,linux" +pr_info ("nvram: No room to create " NVRAM_LOG_PART_NAME " partition, deleting all OS partitions..." );nvram_remove_partition (NULL ,NVRAM_SIG_OS ); - p =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , -NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); + p =nvram_create_partition (NVRAM_LOG_PART_NAME , +NVRAM_SIG_OS ,NVRAM_MIN_REQ , +NVRAM_MAX_REQ ); } }if (p <=0 ) { -pr_err ("nvram: Failed to find or create ppc64,linux" +pr_err ("nvram: Failed to find or create " NVRAM_LOG_PART_NAME " partition, err %d\n" , (int )p);return 0 ; }
Signature · 1 line
1.6.3.3
Re: [PATCH 10/11] powerpc/nvram: Move the log partition stuff to pseries
In reply to Benjamin HerrenschmidtQuoted 5 lines · Benjamin Herrenschmidt
The nvram log partition stuff currently in
nvram_64.cis really pseries specific. It isn't actually used on anything else (despite the fact that we ran the code to setup the partition on anything except powermac) and the log format is specific to pseries RTAS implementation. So move it where it belongs
Some glitches in this one, like the wrong init order. I'll move the nvram scan to be explicitely called by archs who want that stuff.
In fact, I might move the whole partition handling to a separate file to be selected by archs who want it, and try to merge that with powermac, but at least we have a first step here.
I'll send an updated patch later, in case there are other comments.
Cheers,
Ben.
Quoted 530 lines
Signed-off-by Benjamin Herrenschmidt <[email protected]>--- arch/powerpc/include/asm/nvram.h | 9 ++- arch/powerpc/kernel/nvram_64.c | 216 +------------------------------- arch/powerpc/platforms/pseries/nvram.c | 196 +++++++++++++++++++++++++++++ 3 files changed, 208 insertions(+), 213 deletions(-)arch/powerpc/include/asm/nvram.h +8
-1@@ -30,13 +30,14 @@#include <linux/errno.h> #include <linux/list.h> +#ifdef CONFIG_PPC_PSERIES extern int nvram_write_error_log (char * buff,int length,unsigned int err_type,unsigned int err_seq);extern int nvram_read_error_log (char * buff,int length,unsigned int * err_type,unsigned int *err_seq);extern int nvram_clear_error_log (void ); -extern int pSeries_nvram_init (void ); +#endif /* CONFIG_PPC_PSERIES */ #ifdef CONFIG_MMIO_NVRAM extern int mmio_nvram_init (void );@@ -47,6 +48,12 @@ static inline int mmio_nvram_init(void) }#endif +extern loff_t nvram_create_partition (const char *name,int sig, +int req_size,int min_size); +extern int nvram_remove_partition (const char *name,int sig); +extern int nvram_get_partition_size (loff_t data_index); +extern loff_t nvram_find_partition (const char *name,int sig,int *out_size); +#endif /* __KERNEL__ */ /* PowerMac specific nvram stuffs */ arch/powerpc/kernel/nvram_64.c +4
-212@@ -36,8 +36,6 @@#define NVRAM_HEADER_LEN sizeof(struct nvram_header)#define NVRAM_BLOCK_LEN NVRAM_HEADER_LEN -#define NVRAM_MAX_REQ 2079 -#define NVRAM_MIN_REQ 1055/* If change this size, then change the size of NVNAME_LEN */ struct nvram_header {@@ -54,13 +52,6 @@ struct nvram_partition { };static struct nvram_partition * nvram_part; -static long nvram_error_log_index =-1 ; -static long nvram_error_log_size =0 ; - -struct err_log_info { -int error_type; -unsigned int seq_num; -};static loff_t dev_nvram_llseek (struct file *file,loff_t offset,int origin) {@@ -254,7 +245,7 @@ static unsigned char __init nvram_checksum(struct nvram_header *p)* @sig: signature of the partition(s) to remove */ -static int __init nvram_remove_partition (const char *name,int sig) +int __init nvram_remove_partition (const char *name,int sig) {struct nvram_partition *part, *prev, *tmp;int rc;@@ -313,8 +304,8 @@ static int __init nvram_remove_partition(const char *name, int sig)* you need to query for the actual size yourself after the * call using nvram_partition_get_size(). */ -static loff_t __init nvram_create_partition (const char *name,int sig, -int req_size,int min_size) +loff_t __init nvram_create_partition (const char *name,int sig, +int req_size,int min_size) {struct nvram_partition *part;struct nvram_partition *new_part;@@ -417,7 +408,7 @@ static loff_t __init nvram_create_partition(const char *name, int sig,* the partition. The same value that is returned by * nvram_create_partition(). */ -static int nvram_get_partition_size (loff_t data_index) +int nvram_get_partition_size (loff_t data_index) {struct nvram_partition *part;@@ -451,74 +442,6 @@ loff_t nvram_find_partition(const char *name, int sig, int *out_size)return 0 ; } -/* nvram_setup_partition -* -* This will setup the partition we need for buffering the -* error logs and cleanup partitions if needed. -* -* The general strategy is the following: -* 1.) If there is ppc64,linux partition large enough then use it. -* 2.) If there is not a ppc64,linux partition large enough, search -* for a free partition that is large enough. -* 3.) If there is not a free partition large enough remove -* _all_ OS partitions and consolidate the space. -* 4.) Will first try getting a chunk that will satisfy the maximum -* error log size (NVRAM_MAX_REQ). -* 5.) If the max chunk cannot be allocated then try finding a chunk -* that will satisfy the minum needed (NVRAM_MIN_REQ). -*/ -static int __init nvram_setup_partition (void ) -{ -loff_t p; -int size; - -/* For now, we don't do any of this on pmac, until I -* have figured out if it's worth killing some unused stuffs -* in our nvram, as Apple defined partitions use pretty much -* all of the space -*/ -if (machine_is (powermac)) -return -ENOSPC ; - - p =nvram_find_partition ("ppc64,linux" ,NVRAM_SIG_OS , &size); - -/* Found one but too small, remove it */ -if (p && size <NVRAM_MIN_REQ ) { -pr_info ("nvram: Found too small ppc64,linux partition" -",removing it..." ); -nvram_remove_partition ("ppc64,linux" ,NVRAM_SIG_OS ); - p =0 ; - } - -/* Create one if we didn't find */ -if (!p) { - p =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , -NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); -/* No room for it, try to get rid of any OS partition -* and try again -*/ -if (p == -ENOSPC ) { -pr_info ("nvram: No room to create ppc64,linux" -" partition, deleting all OS partitions..." ); -nvram_remove_partition (NULL ,NVRAM_SIG_OS ); - p =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , -NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); - } - } - -if (p <=0 ) { -pr_err ("nvram: Failed to find or create ppc64,linux" -" partition, err %d\n" , (int )p); -return 0 ; - } - - nvram_error_log_index = p; - nvram_error_log_size =nvram_get_partition_size (p) - -sizeof (struct err_log_info ); - -return 0 ; -} -static int __init nvram_scan_partitions (void ) {loff_t cur_index =0 ;@@ -617,10 +540,6 @@ static int __init nvram_init(void)printk (KERN_ERR "nvram_init: Failed nvram_scan_partitions\n" );return error; } - -if (nvram_setup_partition ()) -printk (KERN_WARNING "nvram_init: Could not find nvram partition" -" for nvram buffered error logging.\n" );#ifdef DEBUG_NVRAM nvram_print_partitions ("NVRAM Partitions" );@@ -635,133 +554,6 @@ void __exit nvram_cleanup(void) } -#ifdef CONFIG_PPC_PSERIES - -/* nvram_write_error_log -* -* We need to buffer the error logs into nvram to ensure that we have -* the failure information to decode. If we have a severe error there -* is no way to guarantee that the OS or the machine is in a state to -* get back to user land and write the error to disk. For example if -* the SCSI device driver causes a Machine Check by writing to a bad -* IO address, there is no way of guaranteeing that the device driver -* is in any state that is would also be able to write the error data -* captured to disk, thus we buffer it in NVRAM for analysis on the -* next boot. -* -* In NVRAM the partition containing the error log buffer will looks like: -* Header (in bytes): -* +-----------+----------+--------+------------+------------------+ -* | signature | checksum | length | name | data | -* |0 |1 |2 3|4 15|16 length-1| -* +-----------+----------+--------+------------+------------------+ -* -* The 'data' section would look like (in bytes): -* +--------------+------------+-----------------------------------+ -* | event_logged | sequence # | error log | -* |0 3|4 7|8 nvram_error_log_size-1| -* +--------------+------------+-----------------------------------+ -* -* event_logged: 0 if event has not been logged to syslog, 1 if it has -* sequence #: The unique sequence # for each event. (until it wraps) -* error log: The error log from event_scan -*/ -int nvram_write_error_log (char * buff,int length, -unsigned int err_type,unsigned int error_log_cnt) -{ -int rc; -loff_t tmp_index; -struct err_log_info info; - -if (nvram_error_log_index ==-1 ) { -return -ESPIPE ; - } - -if (length > nvram_error_log_size) { - length = nvram_error_log_size; - } - - info.error_type = err_type; - info.seq_num = error_log_cnt; - - tmp_index = nvram_error_log_index; - - rc = ppc_md.nvram_write ((char *)&info,sizeof (struct err_log_info ), &tmp_index); -if (rc <=0 ) { -printk (KERN_ERR "nvram_write_error_log: Failed nvram_write (%d)\n" , rc); -return rc; - } - - rc = ppc_md.nvram_write (buff, length, &tmp_index); -if (rc <=0 ) { -printk (KERN_ERR "nvram_write_error_log: Failed nvram_write (%d)\n" , rc); -return rc; - } - -return 0 ; -} - -/* nvram_read_error_log -* -* Reads nvram for error log for at most 'length' -*/ -int nvram_read_error_log (char * buff,int length, -unsigned int * err_type,unsigned int * error_log_cnt) -{ -int rc; -loff_t tmp_index; -struct err_log_info info; - -if (nvram_error_log_index ==-1 ) -return -1 ; - -if (length > nvram_error_log_size) - length = nvram_error_log_size; - - tmp_index = nvram_error_log_index; - - rc = ppc_md.nvram_read ((char *)&info,sizeof (struct err_log_info ), &tmp_index); -if (rc <=0 ) { -printk (KERN_ERR "nvram_read_error_log: Failed nvram_read (%d)\n" , rc); -return rc; - } - - rc = ppc_md.nvram_read (buff, length, &tmp_index); -if (rc <=0 ) { -printk (KERN_ERR "nvram_read_error_log: Failed nvram_read (%d)\n" , rc); -return rc; - } - - *error_log_cnt = info.seq_num; - *err_type = info.error_type; - -return 0 ; -} - -/* This doesn't actually zero anything, but it sets the event_logged -* word to tell that this event is safely in syslog. -*/ -int nvram_clear_error_log (void ) -{ -loff_t tmp_index; -int clear_word =ERR_FLAG_ALREADY_LOGGED ; -int rc; - -if (nvram_error_log_index ==-1 ) -return -1 ; - - tmp_index = nvram_error_log_index; - - rc = ppc_md.nvram_write ((char *)&clear_word,sizeof (int ), &tmp_index); -if (rc <=0 ) { -printk (KERN_ERR "nvram_clear_error_log: Failed nvram_write (%d)\n" , rc); -return rc; - } - -return 0 ; -} - -#endif /* CONFIG_PPC_PSERIES */ module_init (nvram_init);module_exit (nvram_cleanup);arch/powerpc/platforms/pseries/nvram.c +196
-0@@ -30,6 +30,16 @@ static int nvram_fetch, nvram_store;static char nvram_buf[NVRW_CNT ];/* assume this is in the first 4GB */ static DEFINE_SPINLOCK (nvram_lock); +static long nvram_error_log_index =-1 ; +static long nvram_error_log_size =0 ; + +struct err_log_info { +int error_type; +unsigned int seq_num; +}; +#define NVRAM_MAX_REQ 2079 +#define NVRAM_MIN_REQ 1055 +static ssize_t pSeries_nvram_read (char *buf,size_t count,loff_t *index) {unsigned int i;@@ -121,6 +131,192 @@ static ssize_t pSeries_nvram_get_size(void)return nvram_size ? nvram_size : -ENODEV ; } + +/* nvram_write_error_log +* +* We need to buffer the error logs into nvram to ensure that we have +* the failure information to decode. If we have a severe error there +* is no way to guarantee that the OS or the machine is in a state to +* get back to user land and write the error to disk. For example if +* the SCSI device driver causes a Machine Check by writing to a bad +* IO address, there is no way of guaranteeing that the device driver +* is in any state that is would also be able to write the error data +* captured to disk, thus we buffer it in NVRAM for analysis on the +* next boot. +* +* In NVRAM the partition containing the error log buffer will looks like: +* Header (in bytes): +* +-----------+----------+--------+------------+------------------+ +* | signature | checksum | length | name | data | +* |0 |1 |2 3|4 15|16 length-1| +* +-----------+----------+--------+------------+------------------+ +* +* The 'data' section would look like (in bytes): +* +--------------+------------+-----------------------------------+ +* | event_logged | sequence # | error log | +* |0 3|4 7|8 nvram_error_log_size-1| +* +--------------+------------+-----------------------------------+ +* +* event_logged: 0 if event has not been logged to syslog, 1 if it has +* sequence #: The unique sequence # for each event. (until it wraps) +* error log: The error log from event_scan +*/ +int nvram_write_error_log (char * buff,int length, +unsigned int err_type,unsigned int error_log_cnt) +{ +int rc; +loff_t tmp_index; +struct err_log_info info; + +if (nvram_error_log_index ==-1 ) { +return -ESPIPE ; + } + +if (length > nvram_error_log_size) { + length = nvram_error_log_size; + } + + info.error_type = err_type; + info.seq_num = error_log_cnt; + + tmp_index = nvram_error_log_index; + + rc = ppc_md.nvram_write ((char *)&info,sizeof (struct err_log_info ), &tmp_index); +if (rc <=0 ) { +printk (KERN_ERR "nvram_write_error_log: Failed nvram_write (%d)\n" , rc); +return rc; + } + + rc = ppc_md.nvram_write (buff, length, &tmp_index); +if (rc <=0 ) { +printk (KERN_ERR "nvram_write_error_log: Failed nvram_write (%d)\n" , rc); +return rc; + } + +return 0 ; +} + +/* nvram_read_error_log +* +* Reads nvram for error log for at most 'length' +*/ +int nvram_read_error_log (char * buff,int length, +unsigned int * err_type,unsigned int * error_log_cnt) +{ +int rc; +loff_t tmp_index; +struct err_log_info info; + +if (nvram_error_log_index ==-1 ) +return -1 ; + +if (length > nvram_error_log_size) + length = nvram_error_log_size; + + tmp_index = nvram_error_log_index; + + rc = ppc_md.nvram_read ((char *)&info,sizeof (struct err_log_info ), &tmp_index); +if (rc <=0 ) { +printk (KERN_ERR "nvram_read_error_log: Failed nvram_read (%d)\n" , rc); +return rc; + } + + rc = ppc_md.nvram_read (buff, length, &tmp_index); +if (rc <=0 ) { +printk (KERN_ERR "nvram_read_error_log: Failed nvram_read (%d)\n" , rc); +return rc; + } + + *error_log_cnt = info.seq_num; + *err_type = info.error_type; + +return 0 ; +} + +/* This doesn't actually zero anything, but it sets the event_logged +* word to tell that this event is safely in syslog. +*/ +int nvram_clear_error_log (void ) +{ +loff_t tmp_index; +int clear_word =ERR_FLAG_ALREADY_LOGGED ; +int rc; + +if (nvram_error_log_index ==-1 ) +return -1 ; + + tmp_index = nvram_error_log_index; + + rc = ppc_md.nvram_write ((char *)&clear_word,sizeof (int ), &tmp_index); +if (rc <=0 ) { +printk (KERN_ERR "nvram_clear_error_log: Failed nvram_write (%d)\n" , rc); +return rc; + } + +return 0 ; +} + +/* pseries_nvram_init_log_partition +* +* This will setup the partition we need for buffering the +* error logs and cleanup partitions if needed. +* +* The general strategy is the following: +* 1.) If there is ppc64,linux partition large enough then use it. +* 2.) If there is not a ppc64,linux partition large enough, search +* for a free partition that is large enough. +* 3.) If there is not a free partition large enough remove +* _all_ OS partitions and consolidate the space. +* 4.) Will first try getting a chunk that will satisfy the maximum +* error log size (NVRAM_MAX_REQ). +* 5.) If the max chunk cannot be allocated then try finding a chunk +* that will satisfy the minum needed (NVRAM_MIN_REQ). +*/ +static int __init pseries_nvram_init_log_partition (void ) +{ +loff_t p; +int size; + + p =nvram_find_partition ("ppc64,linux" ,NVRAM_SIG_OS , &size); + +/* Found one but too small, remove it */ +if (p && size <NVRAM_MIN_REQ ) { +pr_info ("nvram: Found too small ppc64,linux partition" +",removing it..." ); +nvram_remove_partition ("ppc64,linux" ,NVRAM_SIG_OS ); + p =0 ; + } + +/* Create one if we didn't find */ +if (!p) { + p =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , +NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); +/* No room for it, try to get rid of any OS partition +* and try again +*/ +if (p == -ENOSPC ) { +pr_info ("nvram: No room to create ppc64,linux" +" partition, deleting all OS partitions..." ); +nvram_remove_partition (NULL ,NVRAM_SIG_OS ); + p =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , +NVRAM_MIN_REQ ,NVRAM_MAX_REQ ); + } + } + +if (p <=0 ) { +pr_err ("nvram: Failed to find or create ppc64,linux" +" partition, err %d\n" , (int )p); +return 0 ; + } + + nvram_error_log_index = p; + nvram_error_log_size =nvram_get_partition_size (p) - +sizeof (struct err_log_info ); + +return 0 ; +} +machine_arch_initcall (pseries, pseries_nvram_init_log_partition); +int __init pSeries_nvram_init (void ) {struct device_node *nvram;
Re: [PATCH 05/11] powerpc/nvram: Completely clear a new partition
In reply to Benjamin HerrenschmidtQuoted 14 lines · Benjamin Herrenschmidt
When creating a partition, we clear it entirely rather than just the first two words since the previous code was rather specific to the pseries log partition format.
Signed-off-by Benjamin Herrenschmidt <[email protected]>--- arch/powerpc/kernel/nvram_64.c | 19 ++++++++++--------- 1 files changed, 10 insertions(+), 9 deletions(-)arch/powerpc/kernel/nvram_64.c +0
-0
arch/powerpc/kernel/nvram_64.c static int __init nvram_create_partition(const char *name, int sig, · line 323
Quoted 5 lines
arch/powerpc/kernel/nvram_64.c +1
-1@@ -320,7 +320,7 @@ static int __init nvram_create_partition(const char *name, int sig,struct nvram_partition *part;struct nvram_partition *new_part;struct nvram_partition *free_part =NULL ; -int seq_init[2 ] = {0 ,0 }; +static char nv_init_vals[16 ];
Or should we just grab a zeroed page?
Quoted 8 lines
arch/powerpc/kernel/nvram_64.c +0
-1loff_t tmp_index;long size =0 ;int rc;@@ -379,14 +379,15 @@ static int __init nvram_create_partition(const char *name, int sig,return rc; } -/* make sure and initialize to zero the sequence number and the error
arch/powerpc/kernel/nvram_64.c static int __init nvram_create_partition(const char *name, int sig, · line 384
Quoted 10 lines
arch/powerpc/kernel/nvram_64.c +3
-7-type logged */ - tmp_index = new_part->index +NVRAM_HEADER_LEN ; - rc = ppc_md.nvram_write ((char *)&seq_init,sizeof (seq_init), &tmp_index); -if (rc <=0 ) { -printk (KERN_ERR "nvram_create_os_partition: nvram_write " -"failed (%d)\n" , rc); -return rc; +/* Clear the partition */ + for (tmp_index = new_part->index + NVRAM_HEADER_LEN; + tmp_index < ((size - 1) * NVRAM_BLOCK_LEN);
^
Extra whitespace |
cheers
Re: [PATCH 03/11] powerpc/nvram: nvram_create_partitions() now uses bytes
In reply to Benjamin HerrenschmidtQuoted 17 lines · Benjamin Herrenschmidt
This converts
nvram_create_partition()to use a size in bytes rather than blocks. It does the appropriate alignment internallyThe size passed is also the data size (ie. doesn't include the header anymore).
Signed-off-by Benjamin Herrenschmidt <[email protected]>--- arch/powerpc/kernel/nvram_64.c | 20 ++++++++++++++------ 1 files changed, 14 insertions(+), 6 deletions(-)arch/powerpc/kernel/nvram_64.c +0
-0@@ -34,10 +34,10 @@
arch/powerpc/kernel/nvram_64.c line 40
Quoted 10 lines
arch/powerpc/kernel/nvram_64.c +4
-4#undef DEBUG_NVRAM -#define NVRAM_HEADER_LEN 16/* sizeof(struct nvram_header) */ -#define NVRAM_BLOCK_LEN 16 -#define NVRAM_MAX_REQ (2080/NVRAM_BLOCK_LEN) -#define NVRAM_MIN_REQ (1056/NVRAM_BLOCK_LEN) +#define NVRAM_HEADER_LEN sizeof(struct nvram_header) +#define NVRAM_BLOCK_LEN NVRAM_HEADER_LEN +#define NVRAM_MAX_REQ 2079 +#define NVRAM_MIN_REQ 1055
You don't change any callers, but that's because they use these #defines right.
cheers
Re: [PATCH 02/11] powerpc/nvram: More flexible nvram_create_partition()
In reply to Benjamin HerrenschmidtQuoted 57 lines · Benjamin Herrenschmidt
Replace
nvram_create_os_partition()with a variant that takes the partition name, signature and size as arguments.Signed-off-by Benjamin Herrenschmidt <[email protected]>--- arch/powerpc/kernel/nvram_64.c | 46 +++++++++++++++++++------------ arch/powerpc/platforms/pseries/nvram.c | 6 ++-- 2 files changed, 31 insertions(+), 21 deletions(-)arch/powerpc/kernel/nvram_64.c +17
-9@@ -307,13 +307,15 @@ static int __init nvram_remove_os_partition(void)return 0 ; } -/* nvram_create_os_partition -* -* Create a OS linux partition to buffer error logs. -* Will create a partition starting at the first free -* space found if space has enough room. +/** +* nvram_create_partition - Create a partition in nvram +* @name: name of the partition to create +* @sig: signature of the partition to create +* @req_size: size to allocate preferrably +* @min_size: minimum acceptable size (0 means req_size) */ -static int __init nvram_create_os_partition (void ) +static int __init nvram_create_partition (const char *name,int sig, +int req_size,int min_size) {struct nvram_partition *part;struct nvram_partition *new_part;@@ -322,20 +324,27 @@ static int __init nvram_create_os_partition(void)loff_t tmp_index;long size =0 ;int rc; - + +/* If no minimum size specified, make it the same as the +* requested size +*/ +if (min_size ==0 ) + min_size = req_size; +/* Find a free partition that will give us the maximum needed size If can't find one that will give us the minimum size needed */ list_for_each_entry (part, &nvram_part->partition, partition) {if (part->header.signature !=NVRAM_SIG_FREE )continue ; -if (part->header.length >=NVRAM_MAX_REQ ) { - size =NVRAM_MAX_REQ ; +if (part->header.length >= req_size) { + size = req_size;
arch/powerpc/kernel/nvram_64.c static int __init nvram_create_os_partition(void) · line 349
Quoted 10 lines
arch/powerpc/kernel/nvram_64.c +3
-2free_part = part;break ; } -if (!size && part->header.length >=NVRAM_MIN_REQ ) { - size =NVRAM_MIN_REQ ; +if (part->header.length > size && + part->header.length >= min_size) { + size = part->header.length; free_part = part; }
I can't quite convince myself that this is right, but perhaps I just need a coffee.
arch/powerpc/kernel/nvram_64.c static int __init nvram_create_os_partition(void) · line 364
Quoted 9 lines
arch/powerpc/kernel/nvram_64.c +2
-2@@ -350,9 +359,9 @@ static int __init nvram_create_os_partition(void) } new_part->index = free_part->index; - new_part->header.signature =NVRAM_SIG_OS ; + new_part->header.signature = sig; new_part->header.length = size; -strcpy (new_part->header.name,"ppc64,linux" ); +strncpy (new_part->header.name, name,12 );
Should we be checking the name fits?
arch/powerpc/kernel/nvram_64.c static int __init nvram_setup_partition(void) · line 454
Quoted 8 lines
arch/powerpc/kernel/nvram_64.c +0
-1new_part->header.checksum =nvram_checksum (&new_part->header); rc =nvram_write_header (new_part);@@ -451,10 +460,10 @@ static int __init nvram_setup_partition(void) }/* try creating a partition with the free space we have */ - rc = nvram_create_partition("ppc64,linux", );
That looks odd? Trailing comma.
arch/powerpc/kernel/nvram_64.c static int __init nvram_setup_partition(void) · line 464
Quoted 3 lines
arch/powerpc/kernel/nvram_64.c +2
-1-if (!rc) { + rc =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , +NVRAM_MIN_REQ ,NVRAM_MAX_REQ );
Odd whitespace.
arch/powerpc/kernel/nvram_64.c static int __init nvram_setup_partition(void) · line 476
Quoted 13 lines
arch/powerpc/kernel/nvram_64.c +3
-2+if (!rc)return 0 ; - }/* need to free up some space */ rc =nvram_remove_os_partition ();@@ -463,9 +472,10 @@ static int __init nvram_setup_partition(void) }/* create a partition in this new space */ - rc =nvram_create_os_partition (); + rc =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , +NVRAM_MIN_REQ ,NVRAM_MAX_REQ );
And again.
arch/powerpc/kernel/nvram_64.c static int __init nvram_setup_partition(void) · line 479
Quoted 4 lines
arch/powerpc/kernel/nvram_64.c +1
-1if (rc) { -printk (KERN_ERR "nvram_create_os_partition: Could not find a " +printk (KERN_ERR "nvram_create_partition: Could not find a " "NVRAM partition large enough\n" );
pr_err("%s: ..", __func__, ..) if you're touching it anyway?
Quoted 9 lines
arch/powerpc/platforms/pseries/nvram.c +1
-0@@ -22,14 +22,14 @@#include <asm/prom.h> #include <asm/machdep.h> +/* Max bytes to read/write in one go */
arch/powerpc/platforms/pseries/nvram.c line 32
Quoted 10 lines
arch/powerpc/platforms/pseries/nvram.c +2
-3+#define NVRW_CNT 0x20 +static unsigned int nvram_size;static int nvram_fetch, nvram_store;static char nvram_buf[NVRW_CNT ];/* assume this is in the first 4GB */ static DEFINE_SPINLOCK (nvram_lock); -/* Max bytes to read/write in one go */ -#define NVRW_CNT 0x20 -
Churn alert, you just moved that hunk there in the previous patch.
cheers
Re: [PATCH 02/11] powerpc/nvram: More flexible nvram_create_partition()
Quoted 5 lines · Michael Ellerman
arch/powerpc/kernel/nvram_64.c static int __init nvram_setup_partition(void) · line 454
Quoted 3 lines
arch/powerpc/kernel/nvram_64.c +0
-1/* try creating a partition with the free space we have */ - rc = nvram_create_partition("ppc64,linux", );That looks odd? Trailing comma.
Yeah, that and...
Quoted 16 lines
Quoted 16 lines
arch/powerpc/platforms/pseries/nvram.c +3
-0@@ -22,14 +22,14 @@#include <asm/prom.h> #include <asm/machdep.h> +/* Max bytes to read/write in one go */ +#define NVRW_CNT 0x20 +static unsigned int nvram_size;static int nvram_fetch, nvram_store;static char nvram_buf[NVRW_CNT ];/* assume this is in the first 4GB */ static DEFINE_SPINLOCK (nvram_lock);
Quoted 5 lines
arch/powerpc/platforms/pseries/nvram.c line 32
Quoted 3 lines
arch/powerpc/platforms/pseries/nvram.c +0
-3-/* Max bytes to read/write in one go */ -#define NVRW_CNT 0x20 -Churn alert, you just moved that hunk there in the previous patch.
... that are local rebasing fu*kage.
I'll sort all that out in the next version.
Thanks,
Ben.
Re: [PATCH 02/11] powerpc/nvram: More flexible nvram_create_partition()
In reply to Benjamin HerrenschmidtQuoted 23 lines · Benjamin Herrenschmidt
Replace
nvram_create_os_partition()with a variant that takes the partition name, signature and size as arguments.Signed-off-by Benjamin Herrenschmidt <[email protected]>--- arch/powerpc/kernel/nvram_64.c | 46 +++++++++++++++++++------------ arch/powerpc/platforms/pseries/nvram.c | 6 ++-- 2 files changed, 31 insertions(+), 21 deletions(-)arch/powerpc/kernel/nvram_64.c +1
-5@@ -307,13 +307,15 @@ static int __init nvram_remove_os_partition(void)return 0 ; } -/* nvram_create_os_partition -* -* Create a OS linux partition to buffer error logs. -* Will create a partition starting at the first free -* space found if space has enough room. +/**
arch/powerpc/kernel/nvram_64.c static int __init nvram_remove_os_partition(void) · line 319
Quoted 10 lines
arch/powerpc/kernel/nvram_64.c +7
-1+* nvram_create_partition - Create a partition in nvram +* @name: name of the partition to create +* @sig: signature of the partition to create +* @req_size: size to allocate preferrably +* @min_size: minimum acceptable size (0 means req_size) */ -static int __init nvram_create_os_partition (void ) +static int __init nvram_create_partition (const char *name,int sig, +int req_size,int min_size) {
Order of args is req , min but...
arch/powerpc/kernel/nvram_64.c static int __init nvram_setup_partition(void) · line 477
Quoted 3 lines
arch/powerpc/kernel/nvram_64.c +2
-0+ rc =nvram_create_partition ("ppc64,linux" ,NVRAM_SIG_OS , +NVRAM_MIN_REQ ,NVRAM_MAX_REQ );if (rc) {
I call it the other way around :-)
I should have tested this more before sending for RFC :-) Anyways, I found more crap, like the way the list head is allocated etc...
I'll do another pass this week after I've dealt with the merge window.
Cheers,
Ben.