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