2 * arch/ppc/kernel/prep_nvram.c
4 * Copyright (C) 1998 Corey Minyard
6 * This reads the NvRAM on PReP compliant machines (generally from IBM or
7 * Motorola). Motorola kept the format of NvRAM in their ROM, PPCBUG, the
8 * same, long after they had stopped producing PReP compliant machines. So
9 * this code is useful in those cases as well.
12 #include <linux/init.h>
13 #include <linux/delay.h>
14 #include <linux/slab.h>
15 #include <linux/ioport.h>
17 #include <asm/sections.h>
18 #include <asm/segment.h>
20 #include <asm/machdep.h>
21 #include <asm/prep_nvram.h>
23 static char nvramData[MAX_PREP_NVRAM];
24 static NVRAM_MAP *nvram=(NVRAM_MAP *)&nvramData[0];
26 unsigned char __prep prep_nvram_read_val(int addr)
28 outb(addr, PREP_NVRAM_AS0);
29 outb(addr>>8, PREP_NVRAM_AS1);
30 return inb(PREP_NVRAM_DATA);
33 void __prep prep_nvram_write_val(int addr,
36 outb(addr, PREP_NVRAM_AS0);
37 outb(addr>>8, PREP_NVRAM_AS1);
38 outb(val, PREP_NVRAM_DATA);
41 void __init init_prep_nvram(void)
48 * The following could fail if the NvRAM were corrupt but
49 * we expect the boot firmware to have checked its checksum
52 nvp = (char *) &nvram->Header;
53 for (i=0; i<sizeof(HEADER); i++)
55 *nvp = ppc_md.nvram_read_val(i);
60 * The PReP NvRAM may be any size so read in the header to
61 * determine how much we must read in order to get the complete
64 nvramSize=(int)nvram->Header.GEAddress+nvram->Header.GELength;
65 if(nvramSize>MAX_PREP_NVRAM)
70 nvram->Header.GELength=0;
75 * Read the remainder of the PReP NvRAM
77 nvp = (char *) &nvram->GEArea[0];
78 for (i=sizeof(HEADER); i<nvramSize; i++)
80 *nvp = ppc_md.nvram_read_val(i);
86 char __prep *prep_nvram_get_var(const char *name)
91 namelen = strlen(name);
92 cp = prep_nvram_first_var();
94 if ((strncmp(name, cp, namelen) == 0)
95 && (cp[namelen] == '='))
99 cp = prep_nvram_next_var(cp);
106 char __prep *prep_nvram_first_var(void)
108 if (nvram->Header.GELength == 0) {
111 return (((char *)nvram)
112 + ((unsigned int) nvram->Header.GEAddress));
117 char __prep *prep_nvram_next_var(char *name)
123 while (((cp - ((char *) nvram->GEArea)) < nvram->Header.GELength)
129 /* Skip over any null characters. */
130 while (((cp - ((char *) nvram->GEArea)) < nvram->Header.GELength)
136 if ((cp - ((char *) nvram->GEArea)) < nvram->Header.GELength) {