Merge master.kernel.org:/home/rmk/linux-2.6-arm
[linux/fpc-iii.git] / arch / ppc / syslib / prep_nvram.c
blob474dccbc4a8a9eff06be27bde3614e652e05e722
1 /*
2 * Copyright (C) 1998 Corey Minyard
4 * This reads the NvRAM on PReP compliant machines (generally from IBM or
5 * Motorola). Motorola kept the format of NvRAM in their ROM, PPCBUG, the
6 * same, long after they had stopped producing PReP compliant machines. So
7 * this code is useful in those cases as well.
9 */
10 #include <linux/init.h>
11 #include <linux/delay.h>
12 #include <linux/slab.h>
13 #include <linux/ioport.h>
15 #include <asm/sections.h>
16 #include <asm/io.h>
17 #include <asm/machdep.h>
18 #include <asm/prep_nvram.h>
20 static char nvramData[MAX_PREP_NVRAM];
21 static NVRAM_MAP *nvram=(NVRAM_MAP *)&nvramData[0];
23 unsigned char prep_nvram_read_val(int addr)
25 outb(addr, PREP_NVRAM_AS0);
26 outb(addr>>8, PREP_NVRAM_AS1);
27 return inb(PREP_NVRAM_DATA);
30 void prep_nvram_write_val(int addr,
31 unsigned char val)
33 outb(addr, PREP_NVRAM_AS0);
34 outb(addr>>8, PREP_NVRAM_AS1);
35 outb(val, PREP_NVRAM_DATA);
38 void __init init_prep_nvram(void)
40 unsigned char *nvp;
41 int i;
42 int nvramSize;
45 * The following could fail if the NvRAM were corrupt but
46 * we expect the boot firmware to have checked its checksum
47 * before boot
49 nvp = (char *) &nvram->Header;
50 for (i=0; i<sizeof(HEADER); i++)
52 *nvp = ppc_md.nvram_read_val(i);
53 nvp++;
57 * The PReP NvRAM may be any size so read in the header to
58 * determine how much we must read in order to get the complete
59 * GE area
61 nvramSize=(int)nvram->Header.GEAddress+nvram->Header.GELength;
62 if(nvramSize>MAX_PREP_NVRAM)
65 * NvRAM is too large
67 nvram->Header.GELength=0;
68 return;
72 * Read the remainder of the PReP NvRAM
74 nvp = (char *) &nvram->GEArea[0];
75 for (i=sizeof(HEADER); i<nvramSize; i++)
77 *nvp = ppc_md.nvram_read_val(i);
78 nvp++;
82 char *prep_nvram_get_var(const char *name)
84 char *cp;
85 int namelen;
87 namelen = strlen(name);
88 cp = prep_nvram_first_var();
89 while (cp != NULL) {
90 if ((strncmp(name, cp, namelen) == 0)
91 && (cp[namelen] == '='))
93 return cp+namelen+1;
95 cp = prep_nvram_next_var(cp);
98 return NULL;
101 char *prep_nvram_first_var(void)
103 if (nvram->Header.GELength == 0) {
104 return NULL;
105 } else {
106 return (((char *)nvram)
107 + ((unsigned int) nvram->Header.GEAddress));
111 char *prep_nvram_next_var(char *name)
113 char *cp;
116 cp = name;
117 while (((cp - ((char *) nvram->GEArea)) < nvram->Header.GELength)
118 && (*cp != '\0'))
120 cp++;
123 /* Skip over any null characters. */
124 while (((cp - ((char *) nvram->GEArea)) < nvram->Header.GELength)
125 && (*cp == '\0'))
127 cp++;
130 if ((cp - ((char *) nvram->GEArea)) < nvram->Header.GELength) {
131 return cp;
132 } else {
133 return NULL;