1 /* $NetBSD: nvram.h,v 1.5 2008/03/29 09:16:19 tsutsui Exp $ */
4 * Copyright (c) 2006 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
33 * Based on the PowerPC Reference Platform NVRAM Specification.
34 * Document Number: PPS-AR-FW0002
39 #ifndef _MACHINE_NVRAM_H
40 #define _MACHINE_NVRAM_H
43 /* for the motorola machines */
44 #include <dev/ic/mk48txxvar.h>
47 #define MAX_PREP_NVRAM 0x8000 /* maxmum size of the nvram */
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 */
54 * The security fields are maintained by the firmware, and should be
55 * considered read-only.
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 */
69 typedef enum _ERROR_STATUS
{
70 Clear
= 0, /* empty entry */
91 MK
= 12, /* from linux ?? */
95 * According to IBM, if severity is severe, the OS should not boot. It should
96 * instead run diags. Umm.. whatever.
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 */
107 uint8_t detail
[20]; /* detail of error */
111 typedef enum _BOOT_STATUS
{
114 RestartStarted
= 0x04,
115 RestartFinished
= 0x08,
116 PowerFailStarted
= 0x10,
117 PowerFailFinished
= 0x20,
118 ProcessorReady
= 0x40,
119 ProcessorRunning
= 0x80,
120 ProcessorStart
= 0x0100
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.
128 typedef struct _RESTART_BLOCK
{
131 uint32_t BootMasterId
;
132 uint32_t ProcessorId
;
133 volatile uint32_t BootStatus
;
134 uint32_t CheckSum
; /* Checksum of RESTART_BLOCK */
135 void *RestartAddress
;
137 uint32_t SaveAreaLength
;
140 typedef enum _OSAREA_USAGE
{
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 */
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
;
163 ERROR_LOG ErrorLog
[2];
165 /* Global Environment info */
168 uint32_t GELastWRiteDT
[2]; /* last change to GE area */
170 /* Configuration info */
172 uint32_t ConfigLength
;
173 uint32_t ConfigLastWriteDT
[2]; /* last change to config area */
174 uint32_t ConfigCount
; /* count of entries in configuration */
176 /* OS Dependant temp area */
178 uint32_t OSAreaLength
;
179 uint32_t OSAreaLastWriteDT
[2]; /* last change to OSArea */
182 typedef struct _NVRAM_MAP
{
184 uint8_t GEArea
[NVSIZE
- CONFSIZE
- OSAREASIZE
- sizeof(HEADER
)];
185 uint8_t OSArea
[OSAREASIZE
];
186 uint8_t ConfigArea
[CONFSIZE
];
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 */
198 #define DEV_RESIDUAL 1
201 struct prep_mk48txx_softc
{
203 bus_space_tag_t sc_bst
; /* bus tag & handle */
204 bus_space_handle_t sc_bsh
; /* */
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
214 #define MK48TXX_NO_CENT_ADJUST 0x0001
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
;
222 struct nvram_pnpbus_softc
{
223 struct device sc_dev
; /* base device */
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];
230 bus_space_tag_t sc_data
; /* data line */
231 bus_space_handle_t sc_datah
;
233 /* clock bits for mk48txx */
234 struct prep_mk48txx_softc sc_mksc
; /* mk48txx softc */
236 u_char sc_open
; /* single use device */
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 */
246 #endif /* _MACHINE_NVRAM_H */