Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 229328
b: refs/heads/master
c: edc79a2
h: refs/heads/master
v: v3
  • Loading branch information
Benjamin Herrenschmidt committed Nov 30, 2010
1 parent de88211 commit 65a9fcb
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 238 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d9626947f20b3dc0992e4ac28b477f7601f8f16e
refs/heads/master: edc79a2f3ee1c74d915f6a0ce3cb22bf468f5ad5
10 changes: 9 additions & 1 deletion trunk/arch/powerpc/include/asm/nvram.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -47,6 +48,13 @@ static inline int mmio_nvram_init(void)
}
#endif

extern int __init nvram_scan_partitions(void);
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 */
Expand Down
254 changes: 18 additions & 236 deletions trunk/arch/powerpc/kernel/nvram_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -451,75 +442,7 @@ 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_MAX_REQ, NVRAM_MIN_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_MAX_REQ, NVRAM_MIN_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)
int __init nvram_scan_partitions(void)
{
loff_t cur_index = 0;
struct nvram_header phead;
Expand All @@ -529,7 +452,15 @@ static int __init nvram_scan_partitions(void)
int total_size;
int err;

if (ppc_md.nvram_size == NULL)
/* Initialize our anchor for the nvram partition list */
nvram_part = kmalloc(sizeof(struct nvram_partition), GFP_KERNEL);
if (!nvram_part) {
printk(KERN_ERR "nvram_init: Failed kmalloc\n");
return -ENOMEM;
}
INIT_LIST_HEAD(&nvram_part->partition);

if (ppc_md.nvram_size == NULL || ppc_md.nvram_size() <= 0)
return -ENODEV;
total_size = ppc_md.nvram_size();

Expand Down Expand Up @@ -582,14 +513,17 @@ static int __init nvram_scan_partitions(void)
}
err = 0;

#ifdef DEBUG_NVRAM
nvram_print_partitions("NVRAM Partitions");
#endif

out:
kfree(header);
return err;
}

static int __init nvram_init(void)
{
int error;
int rc;

BUILD_BUG_ON(NVRAM_BLOCK_LEN != 16);
Expand All @@ -603,29 +537,6 @@ static int __init nvram_init(void)
return rc;
}

/* initialize our anchor for the nvram partition list */
nvram_part = kmalloc(sizeof(struct nvram_partition), GFP_KERNEL);
if (!nvram_part) {
printk(KERN_ERR "nvram_init: Failed kmalloc\n");
return -ENOMEM;
}
INIT_LIST_HEAD(&nvram_part->partition);

/* Get all the NVRAM partitions */
error = nvram_scan_partitions();
if (error) {
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");
#endif

return rc;
}

Expand All @@ -634,135 +545,6 @@ void __exit nvram_cleanup(void)
misc_deregister( &nvram_dev );
}


#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);
MODULE_LICENSE("GPL");
Loading

0 comments on commit 65a9fcb

Please sign in to comment.