Home | History | Annotate | Line # | Download | only in include
nvram.h revision 1.1.6.2
      1 /* $NetBSD: nvram.h,v 1.1.6.2 2006/04/19 02:33:33 elad 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 #define MAX_PREP_NVRAM 0x8000	/* maxmum size of the nvram */
     50 
     51 #define NVSIZE 4096		/* standard nvram size */
     52 #define OSAREASIZE 512		/* size of OSArea space */
     53 #define CONFSIZE 1024		/* guess at size of configuration area */
     54 
     55 /*
     56  * The security fields are maintained by the firmware, and should be
     57  * considered read-only.
     58  */
     59 typedef struct _SECURITY {
     60 	uint32_t BootErrCnt;	/* count of boot password errors */
     61 	uint32_t ConfigErrCnt;	/* count of config password errors */
     62 	uint32_t BootErrorDT[2];/* Date&Time from RTC of last error in pw */
     63 	uint32_t ConfigErrorDT[2];	/* last config pw error */
     64 	uint32_t BootCorrectDT[2];	/* last correct boot pw */
     65 	uint32_t ConfigCorrectDT[2];	/* last correct config pw */
     66 	uint32_t BootSetDT[2];		/* last set of boot pw */
     67 	uint32_t ConfigSetDT[2];	/* last set of config pw */
     68 	uint8_t Serial[16];	/* Box serial number */
     69 } SECURITY;
     70 
     71 typedef enum _ERROR_STATUS {
     72 	Clear = 0,	/* empty entry */
     73 	Pending = 1,
     74 	DiagnosedOK = 2,
     75 	DiagnosedFail = 3,
     76 	Overrun = 4,
     77 	Logged = 5,
     78 } ERROR_STATUS;
     79 
     80 typedef enum _OS_ID {
     81 	Unknown = 0,
     82 	Firmware = 1,
     83 	AIX = 2,
     84 	NT = 3,
     85 	WPOS2 = 4,
     86 	WPX = 5,
     87 	Taligent = 6,
     88 	Solaris = 7,
     89 	Netware = 8,
     90 	USL = 9,
     91 	Low_End_Client = 10,
     92 	SCO = 11,
     93 	MK = 12, /* from linux ?? */
     94 } OS_ID;
     95 
     96 /*
     97  * According to IBM, if severity is severe, the OS should not boot.  It should
     98  * instead run diags.  Umm.. whatever.
     99  */
    100 
    101 typedef struct _ERROR_LOG {
    102 	uint8_t Status;		/* ERROR_STATUS */
    103 	uint8_t Os;		/* OS_ID */
    104 	uint8_t Type;		/* H=hardware S=software */
    105 	uint8_t Severity;	/* S=servere E=Error */
    106 	uint32_t ErrDT[2];	/* date and time from RTC */
    107 	uint8_t code[8];	/* error code */
    108 	union {
    109 		uint8_t detail[20]; /* detail of error */
    110 	} data;
    111 } ERROR_LOG;
    112 
    113 typedef enum _BOOT_STATUS {
    114 	BootStarted = 0x01,
    115 	BootFinished = 0x02,
    116 	RestartStarted = 0x04,
    117 	RestartFinished = 0x08,
    118 	PowerFailStarted = 0x10,
    119 	PowerFailFinished = 0x20,
    120 	ProcessorReady = 0x40,
    121 	ProcessorRunning = 0x80,
    122 	ProcessorStart = 0x0100
    123 } BOOT_STATUS;
    124 
    125 /*
    126  * If the OS decided to store data in the os area of NVRAM, this tells us
    127  * the last user, so we can decide if we want to re-use it or nuke it.
    128  * I'm not sure what all of these do yet.
    129  */
    130 typedef struct _RESTART_BLOCK {
    131 	uint16_t Version;
    132 	uint16_t Revision;
    133 	uint32_t BootMasterId;
    134 	uint32_t ProcessorId;
    135 	volatile uint32_t BootStatus;
    136 	uint32_t CheckSum; /* Checksum of RESTART_BLOCK */
    137 	void *RestartAddress;
    138 	void *SaveAreaAddr;
    139 	uint32_t SaveAreaLength;
    140 } RESTART_BLOCK;
    141 
    142 typedef enum _OSAREA_USAGE {
    143 	Empty = 0,
    144 	Used = 1,
    145 } OSAREA_USAGE;
    146 
    147 typedef enum _PM_MODE {
    148 	Suspend = 0x80, /* part of state is in memory */
    149 	DirtyBit = 0x01, /* used to decide if pushbutton needs to be checked */
    150 	Hibernate = 0, /* nothing is in memory */
    151 } PMMODE;
    152 
    153 typedef struct _HEADER {
    154 	uint16_t Size;		/* NVRAM size in K(1024) */
    155 	uint8_t Version;	/* Structure map different */
    156 	uint8_t Revision;	/* Structure map same */
    157 	uint16_t Crc1;		/* checksum from beginning of nvram to OSArea*/
    158 	uint16_t Crc2;		/* cksum of config */
    159 	uint8_t LastOS;		/* OS_ID */
    160 	uint8_t Endian;		/* B if BE L if LE */
    161 	uint8_t OSAreaUSage;	/* OSAREA_USAGE */
    162 	uint8_t PMMode;		/* Shutdown mode */
    163 	RESTART_BLOCK RestartBlock;
    164 	SECURITY Security;
    165 	ERROR_LOG ErrorLog[2];
    166 
    167 	/* Global Environment info */
    168 	void *GEAddress;
    169 	uint32_t GELength;
    170 	uint32_t GELastWRiteDT[2]; /* last change to GE area */
    171 
    172 	/* Configuration info */
    173 	void *ConfigAddress;
    174 	uint32_t ConfigLength;
    175 	uint32_t ConfigLastWriteDT[2]; /* last change to config area */
    176 	uint32_t ConfigCount;	/* count of entries in configuration */
    177 
    178 	/* OS Dependant temp area */
    179 	void *OSAreaAddress;
    180 	uint32_t OSAreaLength;
    181 	uint32_t OSAreaLastWriteDT[2]; /* last change to OSArea */
    182 } HEADER;
    183 
    184 typedef struct _NVRAM_MAP {
    185 	HEADER Header;
    186 	uint8_t GEArea[NVSIZE - CONFSIZE - OSAREASIZE - sizeof(HEADER)];
    187 	uint8_t OSArea[OSAREASIZE];
    188 	uint8_t ConfigArea[CONFSIZE];
    189 } NVRAM_MAP;
    190 
    191 struct pnviocdesc {
    192 	int	pnv_namelen;	/* len of pnv_name */
    193 	char	*pnv_name;	/* node name */
    194 	int	pnv_buflen;	/* len of pnv_bus */
    195 	char	*pnv_buf;	/* option value result */
    196 	int	pnv_num;	/* number of something */
    197 };
    198 
    199 struct nvram_pnpbus_softc {
    200 	struct device sc_dev;		/* base device */
    201 
    202 	bus_space_tag_t sc_iot;		/* io space tag */
    203 	bus_space_tag_t sc_as;		/* addr line */
    204 	bus_space_handle_t sc_ash;
    205 	bus_space_handle_t sc_ashs[2];
    206 
    207 	bus_space_tag_t sc_data;	/* data line */
    208 	bus_space_handle_t sc_datah;
    209 	u_char  sc_open;		/* single use device */
    210 };
    211 
    212 #define PNVIOCGET	_IOWR('O', 1, struct pnviocdesc) /* get var contents */
    213 #define PNVIOCGETNEXTNAME _IOWR('O', 2, struct pnviocdesc) /* get next var */
    214 
    215 #endif /* _MACHINE_NVRAM_H */
    216