diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2007-08-02 16:40:28 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2007-08-02 16:40:28 +0000 |
commit | 9c48339377231078f1eaa82139f37500ff376a22 (patch) | |
tree | 1327fc726630be5ec6676ea1f211ef3cf9ecb2f1 /sys | |
parent | 2794ce442a53f9230ad5cc9483dc35dae4beb4fc (diff) |
copy nvram code from i386, because amd64 can use it too. done by
tybollt@solace.miun.se, ok jcs
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/amd64/amd64/conf.c | 12 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/cpu.c | 4 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/machdep.c | 3 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/nvram.c | 153 | ||||
-rw-r--r-- | sys/arch/amd64/conf/GENERIC | 3 | ||||
-rw-r--r-- | sys/arch/amd64/conf/files.amd64 | 5 | ||||
-rw-r--r-- | sys/arch/amd64/isa/clock.c | 4 | ||||
-rw-r--r-- | sys/arch/amd64/isa/nvram.h | 93 |
8 files changed, 269 insertions, 8 deletions
diff --git a/sys/arch/amd64/amd64/conf.c b/sys/arch/amd64/amd64/conf.c index 0556949a6f5..c29ff624841 100644 --- a/sys/arch/amd64/amd64/conf.c +++ b/sys/arch/amd64/amd64/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.14 2007/07/25 18:45:25 todd Exp $ */ +/* $OpenBSD: conf.c,v 1.15 2007/08/02 16:40:27 deraadt Exp $ */ /* * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. @@ -103,6 +103,13 @@ int nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]); (dev_type_stop((*))) enodev, 0, dev_init(c,n,select), \ (dev_type_mmap((*))) enodev, 0 } +/* open, close, read */ +#define cdev_nvram_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + (dev_type_write((*))) enodev, (dev_type_ioctl((*))) enodev, \ + (dev_type_stop((*))) enodev, 0, seltrue, \ + (dev_type_mmap((*))) enodev, 0 } + #define mmread mmrw #define mmwrite mmrw @@ -161,6 +168,8 @@ cdev_decl(xfs_dev); #include "cz.h" cdev_decl(cztty); #include "radio.h" +#include "nvram.h" +cdev_decl(nvram); #include "wsdisplay.h" #include "wskbd.h" @@ -282,6 +291,7 @@ struct cdevsw cdevsw[] = cdev_hotplug_init(NHOTPLUG,hotplug), /* 82: devices hot plugging */ cdev_acpi_init(NACPI,acpi), /* 83: ACPI */ cdev_bthub_init(NBTHUB,bthub), /* 84: bthub */ + cdev_nvram_init(NNVRAM,nvram), /* 85: NVRAM interface */ }; int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]); diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c index 50b82f1b878..2cba6925e0a 100644 --- a/sys/arch/amd64/amd64/cpu.c +++ b/sys/arch/amd64/amd64/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.12 2007/01/15 23:19:05 jsg Exp $ */ +/* $OpenBSD: cpu.c,v 1.13 2007/08/02 16:40:27 deraadt Exp $ */ /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */ /*- @@ -107,7 +107,7 @@ #endif #include <dev/ic/mc146818reg.h> -#include <i386/isa/nvram.h> +#include <amd64/isa/nvram.h> #include <dev/isa/isareg.h> int cpu_match(struct device *, void *, void *); diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index f1aa836c45d..1ac80c8e823 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.59 2007/06/06 17:15:11 deraadt Exp $ */ +/* $OpenBSD: machdep.c,v 1.60 2007/08/02 16:40:27 deraadt Exp $ */ /* $NetBSD: machdep.c,v 1.3 2003/05/07 22:58:18 fvdl Exp $ */ /*- @@ -127,6 +127,7 @@ #include <dev/isa/isareg.h> #include <machine/isa_machdep.h> #include <dev/ic/i8042reg.h> +#include <amd64/isa/nvram.h> #ifdef DDB #include <machine/db_machdep.h> diff --git a/sys/arch/amd64/amd64/nvram.c b/sys/arch/amd64/amd64/nvram.c new file mode 100644 index 00000000000..4fba49dde93 --- /dev/null +++ b/sys/arch/amd64/amd64/nvram.c @@ -0,0 +1,153 @@ +/* $OpenBSD: nvram.c,v 1.1 2007/08/02 16:40:27 deraadt Exp $ */ + +/* + * Copyright (c) 2004 Joshua Stein <jcs@openbsd.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/uio.h> +#include <sys/fcntl.h> +#include <sys/conf.h> + +#include <dev/ic/mc146818reg.h> +#include <amd64/isa/nvram.h> + +/* checksum is calculated over bytes 2 to 31 and stored in byte 32 */ +#define NVRAM_CSUM_START (MC_NVRAM_START + 2) +#define NVRAM_CSUM_END (MC_NVRAM_START + 31) +#define NVRAM_CSUM_LOC (MC_NVRAM_START + 32) + +#define NVRAM_SIZE (128 - MC_NVRAM_START) + +/* #define NVRAM_DEBUG 1 */ + +void nvramattach(int); + +int nvramopen(dev_t dev, int flag, int mode, struct proc *p); +int nvramclose(dev_t dev, int flag, int mode, struct proc *p); +int nvramread(dev_t dev, struct uio *uio, int flags); + +int nvram_csum_valid(void); +int nvram_get_byte(int byteno); + +static int nvram_initialized; + +void +nvramattach(int num) +{ + if (num > 1) + return; + + if (nvram_initialized || nvram_csum_valid()) { +#ifdef NVRAM_DEBUG + printf("nvram: initialized\n"); +#endif + nvram_initialized = 1; + } else + printf("nvram: invalid checksum\n"); +} + +int +nvramopen(dev_t dev, int flag, int mode, struct proc *p) +{ + /* TODO: re-calc checksum on every open? */ + + if ((minor(dev) != 0) || (!nvram_initialized)) + return (ENXIO); + + if ((flag & FWRITE)) + return (EPERM); + + return (0); +} + +int +nvramclose(dev_t dev, int flag, int mode, struct proc *p) +{ + return (0); +} + +int +nvramread(dev_t dev, struct uio *uio, int flags) +{ + u_char buf[NVRAM_SIZE]; + u_int pos = uio->uio_offset; + u_char *tmp; + int count = min(sizeof(buf), uio->uio_resid); + int ret; + + if (!nvram_initialized) + return (ENXIO); + + if (uio->uio_resid == 0) + return (0); + +#ifdef NVRAM_DEBUG + printf("attempting to read %d bytes at offset %d\n", count, pos); +#endif + + for (tmp = buf; count-- > 0 && pos < NVRAM_SIZE; ++pos, ++tmp) + *tmp = nvram_get_byte(pos); + +#ifdef NVRAM_DEBUG + printf("nvramread read %d bytes (%s)\n", (tmp - buf), tmp); +#endif + + ret = uiomove((caddr_t)buf, (tmp - buf), uio); + + uio->uio_offset += uio->uio_resid; + + return (ret); +} + +int +nvram_get_byte(int byteno) +{ + if (!nvram_initialized) + return (ENXIO); + + return (mc146818_read(NULL, byteno + MC_NVRAM_START) & 0xff); +} + +int +nvram_csum_valid() +{ + u_short csum = 0; + u_short csumexpect; + int nreg; + + for (nreg = NVRAM_CSUM_START; nreg <= NVRAM_CSUM_END; nreg++) + csum += mc146818_read(NULL, nreg); + + csumexpect = mc146818_read(NULL, NVRAM_CSUM_LOC) << 8 | + mc146818_read(NULL, NVRAM_CSUM_LOC + 1); + +#ifdef NVRAM_DEBUG + printf("nvram: checksum is %x, expecting %x\n", (csum & 0xffff), + csumexpect); +#endif + + return ((csum & 0xffff) == csumexpect); +} diff --git a/sys/arch/amd64/conf/GENERIC b/sys/arch/amd64/conf/GENERIC index 6efa1d15ce0..9dee2884aa3 100644 --- a/sys/arch/amd64/conf/GENERIC +++ b/sys/arch/amd64/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.189 2007/07/02 14:29:37 dlg Exp $ +# $OpenBSD: GENERIC,v 1.190 2007/08/02 16:40:27 deraadt Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -525,6 +525,7 @@ owid* at onewire? # ID owsbm* at onewire? # Smart Battery Monitor owtemp* at onewire? # Temperature +pseudo-device nvram 1 pseudo-device sequencer 1 #pseudo-device raid 4 # RAIDframe disk driver pseudo-device hotplug 1 # devices hot plugging diff --git a/sys/arch/amd64/conf/files.amd64 b/sys/arch/amd64/conf/files.amd64 index b2d39fb9068..4ce1947ae75 100644 --- a/sys/arch/amd64/conf/files.amd64 +++ b/sys/arch/amd64/conf/files.amd64 @@ -1,4 +1,4 @@ -# $OpenBSD: files.amd64,v 1.32 2007/06/04 20:22:08 ckuethe Exp $ +# $OpenBSD: files.amd64,v 1.33 2007/08/02 16:40:27 deraadt Exp $ maxpartitions 16 maxusers 2 16 128 @@ -164,6 +164,9 @@ device fd: disk, isa_dma attach fd at fdc file dev/isa/fd.c fd needs-flag +pseudo-device nvram +file arch/amd64/amd64/nvram.c nvram needs-flag + # # USB # diff --git a/sys/arch/amd64/isa/clock.c b/sys/arch/amd64/isa/clock.c index 6430d247595..91b23087b03 100644 --- a/sys/arch/amd64/isa/clock.c +++ b/sys/arch/amd64/isa/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.12 2007/05/03 18:51:08 grange Exp $ */ +/* $OpenBSD: clock.c,v 1.13 2007/08/02 16:40:27 deraadt Exp $ */ /* $NetBSD: clock.c,v 1.1 2003/04/26 18:39:50 fvdl Exp $ */ /*- @@ -106,7 +106,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <dev/isa/isavar.h> #include <dev/ic/mc146818reg.h> #include <dev/ic/i8253reg.h> -#include <i386/isa/nvram.h> +#include <amd64/isa/nvram.h> #include <dev/clock_subr.h> #include <machine/specialreg.h> diff --git a/sys/arch/amd64/isa/nvram.h b/sys/arch/amd64/isa/nvram.h new file mode 100644 index 00000000000..b3ae74feb7a --- /dev/null +++ b/sys/arch/amd64/isa/nvram.h @@ -0,0 +1,93 @@ +/* $OpenBSD: nvram.h,v 1.1 2007/08/02 16:40:27 deraadt Exp $ */ +/* $NetBSD: nvram.h,v 1.5 1995/05/05 22:08:43 mycroft Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)rtc.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * The following information is found in the non-volatile RAM in the + * MC146818A (or DS1287A or other compatible) RTC on AT-compatible PCs. + */ + +/* NVRAM byte 0: bios diagnostic */ +#define NVRAM_DIAG (MC_NVRAM_START + 0) /* RTC offset 0xe */ + +#define NVRAM_DIAG_BITS "\020\010clock_battery\007ROM_cksum\006config_unit\005memory_size\004fixed_disk\003invalid_time" + +/* NVRAM byte 1: reset code */ +#define NVRAM_RESET (MC_NVRAM_START + 1) /* RTC offset 0xf */ + +#define NVRAM_RESET_RST 0x00 /* normal reset */ +#define NVRAM_RESET_LOAD 0x04 /* load system */ +#define NVRAM_RESET_JUMP 0x0a /* jump through 40:67 */ + +/* NVRAM byte 2: diskette drive type in upper/lower nibble */ +#define NVRAM_DISKETTE (MC_NVRAM_START + 2) /* RTC offset 0x10 */ + +#define NVRAM_DISKETTE_NONE 0 /* none present */ +#define NVRAM_DISKETTE_360K 0x10 /* 360K */ +#define NVRAM_DISKETTE_12M 0x20 /* 1.2M */ +#define NVRAM_DISKETTE_720K 0x30 /* 720K */ +#define NVRAM_DISKETTE_144M 0x40 /* 1.44M */ +#define NVRAM_DISKETTE_TYPE5 0x50 /* 2.88M, presumably */ +#define NVRAM_DISKETTE_TYPE6 0x60 /* 2.88M */ + +/* NVRAM byte 6: equipment type */ +#define NVRAM_EQUIPMENT (MC_NVRAM_START + 6) + +#define NVRAM_EQUIPMENT_FLOPPY 0x01 /* floppy installed */ +#define NVRAM_EQUIPMENT_FPU 0x02 /* FPU installed */ +#define NVRAM_EQUIPMENT_KBD 0x04 /* keyboard installed */ +#define NVRAM_EQUIPMENT_DISPLAY 0x08 /* display installed */ +#define NVRAM_EQUIPMENT_EGAVGA 0x00 /* EGA or VGA */ +#define NVRAM_EQUIPMENT_COLOR40 0x10 /* 40 column color */ +#define NVRAM_EQUIPMENT_COLOR80 0x20 /* 80 column color */ +#define NVRAM_EQUIPMENT_MONO80 0x30 /* 80 column mono */ +#define NVRAM_EQUIPMENT_MONITOR 0x30 /* mask for monitor type */ +#define MVRAM_EQUIPMENT_NFDS 0xC0 /* mask for # of floppies */ + +/* NVRAM bytes 7 & 8: base memory size */ +#define NVRAM_BASELO (MC_NVRAM_START + 7) /* low byte; RTC off. 0x15 */ +#define NVRAM_BASEHI (MC_NVRAM_START + 8) /* high byte; RTC off. 0x16 */ + +/* NVRAM bytes 9 & 10: extended memory size */ +#define NVRAM_EXTLO (MC_NVRAM_START + 9) /* low byte; RTC off. 0x17 */ +#define NVRAM_EXTHI (MC_NVRAM_START + 10) /* high byte; RTC off. 0x18 */ + +/* NVRAM bytes 34 and 35: extended memory POSTed size */ +#define NVRAM_PEXTLO (MC_NVRAM_START + 34) /* low byte; RTC off. 0x30 */ +#define NVRAM_PEXTHI (MC_NVRAM_START + 35) /* high byte; RTC off. 0x31 */ + +/* NVRAM byte 36: current century. (please increment in Dec99!) */ +#define NVRAM_CENTURY (MC_NVRAM_START + 36) /* RTC offset 0x32 */ |