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.
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>
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,
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)
45 * The following could fail if the NvRAM were corrupt but
46 * we expect the boot firmware to have checked its checksum
49 nvp = (char *) &nvram->Header;
50 for (i=0; i<sizeof(HEADER); i++)
52 *nvp = ppc_md.nvram_read_val(i);
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
61 nvramSize=(int)nvram->Header.GEAddress+nvram->Header.GELength;
62 if(nvramSize>MAX_PREP_NVRAM)
67 nvram->Header.GELength=0;
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);
82 char *prep_nvram_get_var(const char *name)
87 namelen = strlen(name);
88 cp = prep_nvram_first_var();
90 if ((strncmp(name, cp, namelen) == 0)
91 && (cp[namelen] == '='))
95 cp = prep_nvram_next_var(cp);
101 char *prep_nvram_first_var(void)
103 if (nvram->Header.GELength == 0) {
106 return (((char *)nvram)
107 + ((unsigned int) nvram->Header.GEAddress));
111 char *prep_nvram_next_var(char *name)
117 while (((cp - ((char *) nvram->GEArea)) < nvram->Header.GELength)
123 /* Skip over any null characters. */
124 while (((cp - ((char *) nvram->GEArea)) < nvram->Header.GELength)
130 if ((cp - ((char *) nvram->GEArea)) < nvram->Header.GELength) {