nvram.h revision 1.2 1 /* $NetBSD: nvram.h,v 1.2 2006/06/15 18:15:32 garbled Exp $ */
2
3 /*-
4 * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tim Rightnour
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Based on the PowerPC Reference Platform NVRAM Specification.
41 * Document Number: PPS-AR-FW0002
42 * Jan 22, 1996
43 * Version 0.3
44 */
45
46 #ifndef _MACHINE_NVRAM_H
47 #define _MACHINE_NVRAM_H
48
49 /* for the motorola machines */
50 #include <dev/ic/mk48txxvar.h>
51
52 #define MAX_PREP_NVRAM 0x8000 /* maxmum size of the nvram */
53
54 #define NVSIZE 4096 /* standard nvram size */
55 #define OSAREASIZE 512 /* size of OSArea space */
56 #define CONFSIZE 1024 /* guess at size of configuration area */
57
58 /*
59 * The security fields are maintained by the firmware, and should be
60 * considered read-only.
61 */
62 typedef struct _SECURITY {
63 uint32_t BootErrCnt; /* count of boot password errors */
64 uint32_t ConfigErrCnt; /* count of config password errors */
65 uint32_t BootErrorDT[2];/* Date&Time from RTC of last error in pw */
66 uint32_t ConfigErrorDT[2]; /* last config pw error */
67 uint32_t BootCorrectDT[2]; /* last correct boot pw */
68 uint32_t ConfigCorrectDT[2]; /* last correct config pw */
69 uint32_t BootSetDT[2]; /* last set of boot pw */
70 uint32_t ConfigSetDT[2]; /* last set of config pw */
71 uint8_t Serial[16]; /* Box serial number */
72 } SECURITY;
73
74 typedef enum _ERROR_STATUS {
75 Clear = 0, /* empty entry */
76 Pending = 1,
77 DiagnosedOK = 2,
78 DiagnosedFail = 3,
79 Overrun = 4,
80 Logged = 5,
81 } ERROR_STATUS;
82
83 typedef enum _OS_ID {
84 Unknown = 0,
85 Firmware = 1,
86 AIX = 2,
87 NT = 3,
88 WPOS2 = 4,
89 WPX = 5,
90 Taligent = 6,
91 Solaris = 7,
92 Netware = 8,
93 USL = 9,
94 Low_End_Client = 10,
95 SCO = 11,
96 MK = 12, /* from linux ?? */
97 } OS_ID;
98
99 /*
100 * According to IBM, if severity is severe, the OS should not boot. It should
101 * instead run diags. Umm.. whatever.
102 */
103
104 typedef struct _ERROR_LOG {
105 uint8_t Status; /* ERROR_STATUS */
106 uint8_t Os; /* OS_ID */
107 uint8_t Type; /* H=hardware S=software */
108 uint8_t Severity; /* S=servere E=Error */
109 uint32_t ErrDT[2]; /* date and time from RTC */
110 uint8_t code[8]; /* error code */
111 union {
112 uint8_t detail[20]; /* detail of error */
113 } data;
114 } ERROR_LOG;
115
116 typedef enum _BOOT_STATUS {
117 BootStarted = 0x01,
118 BootFinished = 0x02,
119 RestartStarted = 0x04,
120 RestartFinished = 0x08,
121 PowerFailStarted = 0x10,
122 PowerFailFinished = 0x20,
123 ProcessorReady = 0x40,
124 ProcessorRunning = 0x80,
125 ProcessorStart = 0x0100
126 } BOOT_STATUS;
127
128 /*
129 * If the OS decided to store data in the os area of NVRAM, this tells us
130 * the last user, so we can decide if we want to re-use it or nuke it.
131 * I'm not sure what all of these do yet.
132 */
133 typedef struct _RESTART_BLOCK {
134 uint16_t Version;
135 uint16_t Revision;
136 uint32_t BootMasterId;
137 uint32_t ProcessorId;
138 volatile uint32_t BootStatus;
139 uint32_t CheckSum; /* Checksum of RESTART_BLOCK */
140 void *RestartAddress;
141 void *SaveAreaAddr;
142 uint32_t SaveAreaLength;
143 } RESTART_BLOCK;
144
145 typedef enum _OSAREA_USAGE {
146 Empty = 0,
147 Used = 1,
148 } OSAREA_USAGE;
149
150 typedef enum _PM_MODE {
151 Suspend = 0x80, /* part of state is in memory */
152 DirtyBit = 0x01, /* used to decide if pushbutton needs to be checked */
153 Hibernate = 0, /* nothing is in memory */
154 } PMMODE;
155
156 typedef struct _HEADER {
157 uint16_t Size; /* NVRAM size in K(1024) */
158 uint8_t Version; /* Structure map different */
159 uint8_t Revision; /* Structure map same */
160 uint16_t Crc1; /* checksum from beginning of nvram to OSArea*/
161 uint16_t Crc2; /* cksum of config */
162 uint8_t LastOS; /* OS_ID */
163 uint8_t Endian; /* B if BE L if LE */
164 uint8_t OSAreaUSage; /* OSAREA_USAGE */
165 uint8_t PMMode; /* Shutdown mode */
166 RESTART_BLOCK RestartBlock;
167 SECURITY Security;
168 ERROR_LOG ErrorLog[2];
169
170 /* Global Environment info */
171 void *GEAddress;
172 uint32_t GELength;
173 uint32_t GELastWRiteDT[2]; /* last change to GE area */
174
175 /* Configuration info */
176 void *ConfigAddress;
177 uint32_t ConfigLength;
178 uint32_t ConfigLastWriteDT[2]; /* last change to config area */
179 uint32_t ConfigCount; /* count of entries in configuration */
180
181 /* OS Dependant temp area */
182 void *OSAreaAddress;
183 uint32_t OSAreaLength;
184 uint32_t OSAreaLastWriteDT[2]; /* last change to OSArea */
185 } HEADER;
186
187 typedef struct _NVRAM_MAP {
188 HEADER Header;
189 uint8_t GEArea[NVSIZE - CONFSIZE - OSAREASIZE - sizeof(HEADER)];
190 uint8_t OSArea[OSAREASIZE];
191 uint8_t ConfigArea[CONFSIZE];
192 } NVRAM_MAP;
193
194 struct pnviocdesc {
195 int pnv_namelen; /* len of pnv_name */
196 char *pnv_name; /* node name */
197 int pnv_buflen; /* len of pnv_bus */
198 char *pnv_buf; /* option value result */
199 int pnv_num; /* number of something */
200 };
201
202 struct prep_mk48txx_softc {
203 struct device sc_dev;
204 bus_space_tag_t sc_bst; /* bus tag & handle */
205 bus_space_handle_t sc_bsh; /* */
206
207 struct todr_chip_handle sc_handle; /* TODR handle */
208 const char *sc_model; /* chip model name */
209 bus_size_t sc_nvramsz; /* Size of NVRAM on the chip */
210 bus_size_t sc_clkoffset; /* Offset in NVRAM to clock bits */
211 u_int sc_year0; /* What year is represented on
212 the system by the chip's year
213 counter at 0 */
214 u_int sc_flag;
215 #define MK48TXX_NO_CENT_ADJUST 0x0001
216
217 mk48txx_nvrd_t sc_nvrd; /* NVRAM/RTC read function */
218 mk48txx_nvwr_t sc_nvwr; /* NVRAM/RTC write function */
219 bus_space_tag_t sc_data;
220 bus_space_handle_t sc_datah;
221 };
222
223 struct nvram_pnpbus_softc {
224 struct device sc_dev; /* base device */
225
226 bus_space_tag_t sc_iot; /* io space tag */
227 bus_space_tag_t sc_as; /* addr line */
228 bus_space_handle_t sc_ash;
229 bus_space_handle_t sc_ashs[2];
230
231 bus_space_tag_t sc_data; /* data line */
232 bus_space_handle_t sc_datah;
233
234 /* clock bits for mk48txx */
235 struct prep_mk48txx_softc sc_mksc; /* mk48txx softc */
236
237 u_char sc_open; /* single use device */
238 };
239
240 #define PNVIOCGET _IOWR('O', 1, struct pnviocdesc) /* get var contents */
241 #define PNVIOCGETNEXTNAME _IOWR('O', 2, struct pnviocdesc) /* get next var */
242
243 #endif /* _MACHINE_NVRAM_H */
244