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