File: /usr/src/linux/arch/ppc/kernel/prep_nvram.c
1 /*
2 * BK Id: SCCS/s.prep_nvram.c 1.12 09/08/01 15:47:42 paulus
3 */
4 /*
5 * linux/arch/ppc/kernel/prep_nvram.c
6 *
7 * Copyright (C) 1998 Corey Minyard
8 *
9 */
10 #include <linux/init.h>
11 #include <linux/delay.h>
12 #include <linux/slab.h>
13 #include <linux/ioport.h>
14
15 #include <asm/sections.h>
16 #include <asm/segment.h>
17 #include <asm/io.h>
18 #include <asm/processor.h>
19 #include <asm/machdep.h>
20 #include <asm/prep_nvram.h>
21
22 static char nvramData[MAX_PREP_NVRAM];
23 static NVRAM_MAP *nvram=(NVRAM_MAP *)&nvramData[0];
24
25 unsigned char __prep prep_nvram_read_val(int addr)
26 {
27 outb(addr, PREP_NVRAM_AS0);
28 outb(addr>>8, PREP_NVRAM_AS1);
29 return inb(PREP_NVRAM_DATA);
30 }
31
32 void __prep prep_nvram_write_val(int addr,
33 unsigned char val)
34 {
35 outb(addr, PREP_NVRAM_AS0);
36 outb(addr>>8, PREP_NVRAM_AS1);
37 outb(val, PREP_NVRAM_DATA);
38 }
39
40 void __init init_prep_nvram(void)
41 {
42 unsigned char *nvp;
43 int i;
44 int nvramSize;
45
46 /*
47 * The following could fail if the NvRAM were corrupt but
48 * we expect the boot firmware to have checked its checksum
49 * before boot
50 */
51 nvp = (char *) &nvram->Header;
52 for (i=0; i<sizeof(HEADER); i++)
53 {
54 *nvp = ppc_md.nvram_read_val(i);
55 nvp++;
56 }
57
58 /*
59 * The PReP NvRAM may be any size so read in the header to
60 * determine how much we must read in order to get the complete
61 * GE area
62 */
63 nvramSize=(int)nvram->Header.GEAddress+nvram->Header.GELength;
64 if(nvramSize>MAX_PREP_NVRAM)
65 {
66 /*
67 * NvRAM is too large
68 */
69 nvram->Header.GELength=0;
70 return;
71 }
72
73 /*
74 * Read the remainder of the PReP NvRAM
75 */
76 nvp = (char *) &nvram->GEArea[0];
77 for (i=sizeof(HEADER); i<nvramSize; i++)
78 {
79 *nvp = ppc_md.nvram_read_val(i);
80 nvp++;
81 }
82 }
83
84 __prep
85 char __prep *prep_nvram_get_var(const char *name)
86 {
87 char *cp;
88 int namelen;
89
90 namelen = strlen(name);
91 cp = prep_nvram_first_var();
92 while (cp != NULL) {
93 if ((strncmp(name, cp, namelen) == 0)
94 && (cp[namelen] == '='))
95 {
96 return cp+namelen+1;
97 }
98 cp = prep_nvram_next_var(cp);
99 }
100
101 return NULL;
102 }
103
104 __prep
105 char __prep *prep_nvram_first_var(void)
106 {
107 if (nvram->Header.GELength == 0) {
108 return NULL;
109 } else {
110 return (((char *)nvram)
111 + ((unsigned int) nvram->Header.GEAddress));
112 }
113 }
114
115 __prep
116 char __prep *prep_nvram_next_var(char *name)
117 {
118 char *cp;
119
120
121 cp = name;
122 while (((cp - ((char *) nvram->GEArea)) < nvram->Header.GELength)
123 && (*cp != '\0'))
124 {
125 cp++;
126 }
127
128 /* Skip over any null characters. */
129 while (((cp - ((char *) nvram->GEArea)) < nvram->Header.GELength)
130 && (*cp == '\0'))
131 {
132 cp++;
133 }
134
135 if ((cp - ((char *) nvram->GEArea)) < nvram->Header.GELength) {
136 return cp;
137 } else {
138 return NULL;
139 }
140 }
141
142
143
144