From owner-p4-projects@FreeBSD.ORG Fri Oct 26 02:21:20 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1BB9316A418; Fri, 26 Oct 2007 02:21:20 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B569F16A421 for ; Fri, 26 Oct 2007 02:21:19 +0000 (UTC) (envelope-from peter@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 9E6CA13C480 for ; Fri, 26 Oct 2007 02:21:19 +0000 (UTC) (envelope-from peter@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l9Q2LJ9Q023992 for ; Fri, 26 Oct 2007 02:21:19 GMT (envelope-from peter@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l9Q2LJIY023989 for perforce@freebsd.org; Fri, 26 Oct 2007 02:21:19 GMT (envelope-from peter@freebsd.org) Date: Fri, 26 Oct 2007 02:21:19 GMT Message-Id: <200710260221.l9Q2LJIY023989@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to peter@freebsd.org using -f From: Peter Wemm To: Perforce Change Reviews Cc: Subject: PERFORCE change 128103 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Oct 2007 02:21:20 -0000 http://perforce.freebsd.org/chv.cgi?CH=128103 Change 128103 by peter@peter_daintree on 2007/10/26 02:21:04 Make nvram a real device. Make it do checksums on write. (Check for a valid checksum before allowing writes or risk a 'press F1 to continue' bios boot problem if we dont understand the algorithm) Affected files ... .. //depot/projects/hammer/sys/amd64/conf/DEFAULTS#7 edit .. //depot/projects/hammer/sys/amd64/include/clock.h#24 edit .. //depot/projects/hammer/sys/amd64/isa/clock.c#65 edit .. //depot/projects/hammer/sys/conf/files.amd64#96 edit .. //depot/projects/hammer/sys/conf/files.i386#82 edit .. //depot/projects/hammer/sys/dev/nvram/nvram.c#1 add .. //depot/projects/hammer/sys/i386/conf/DEFAULTS#7 edit .. //depot/projects/hammer/sys/i386/include/clock.h#14 edit .. //depot/projects/hammer/sys/i386/isa/clock.c#39 edit Differences ... ==== //depot/projects/hammer/sys/amd64/conf/DEFAULTS#7 (text+ko) ==== @@ -11,6 +11,7 @@ # Pseudo devices. device mem # Memory and kernel memory devices device io # I/O device +device nvram # Access to rtc cmos via /dev/nvram # UART chips on this platform device uart_ns8250 ==== //depot/projects/hammer/sys/amd64/include/clock.h#24 (text+ko) ==== @@ -31,7 +31,8 @@ int acquire_timer2(int mode); int release_timer2(void); -int rtcin(int val); +int rtcin(int reg); +void writertc(int reg, unsigned char val); int sysbeep(int pitch, int period); void init_TSC(void); void init_TSC_tc(void); ==== //depot/projects/hammer/sys/amd64/isa/clock.c#65 (text+ko) ==== @@ -433,7 +433,7 @@ return (val); } -static void +void writertc(int reg, u_char val) { @@ -934,99 +934,4 @@ DRIVER_MODULE(attimer, isa, attimer_driver, attimer_devclass, 0, 0); DRIVER_MODULE(attimer, acpi, attimer_driver, attimer_devclass, 0, 0); -/* - * Linux-style /dev/nvram driver - * - * cmos ram starts at bytes 14 through 128, for a total of 114 bytes. - * bytes 16 through 31 are checksummed at byte 32. - * Unlike Linux, you have to take care of the checksums yourself. - * The driver exposes byte 14 as file offset 0. - */ - -#define NVRAM_FIRST RTC_DIAG /* 14 */ -#define NVRAM_LAST 128 - -static d_open_t nvram_open; -static d_read_t nvram_read; -static d_write_t nvram_write; - -static struct cdev *nvram_dev; - -static struct cdevsw nvram_cdevsw = { - .d_version = D_VERSION, - .d_flags = D_NEEDGIANT, - .d_open = nvram_open, - .d_read = nvram_read, - .d_write = nvram_write, - .d_name = "nvram", -}; - -static int -nvram_open(struct cdev *dev __unused, int flags, int fmt __unused, - struct thread *td) -{ - int error = 0; - - if (flags & FWRITE) - error = securelevel_gt(td->td_ucred, 0); - - return (error); -} - -static int -nvram_read(struct cdev *dev, struct uio *uio, int flags) -{ - int nv_off; - u_char v; - int error = 0; - - while (uio->uio_resid > 0 && error == 0) { - nv_off = uio->uio_offset + NVRAM_FIRST; - if (nv_off < NVRAM_FIRST || nv_off >= NVRAM_LAST) - return (0); /* Signal EOF */ - /* Single byte at a time */ - v = rtcin(nv_off); - error = uiomove(&v, 1, uio); - } - return (error); - -} - -static int -nvram_write(struct cdev *dev, struct uio *uio, int flags) -{ - int nv_off; - u_char v; - int error = 0; - - while (uio->uio_resid > 0 && error == 0) { - nv_off = uio->uio_offset + NVRAM_FIRST; - if (nv_off < NVRAM_FIRST || nv_off >= NVRAM_LAST) - return (0); /* Signal EOF */ - /* Single byte at a time */ - error = uiomove(&v, 1, uio); - writertc(nv_off, v); - } - return (error); -} - -static int -nvram_modevent(module_t mod __unused, int type, void *data __unused) -{ - switch (type) { - case MOD_LOAD: - nvram_dev = make_dev(&nvram_cdevsw, 0, - UID_ROOT, GID_KMEM, 0640, "nvram"); - break; - case MOD_UNLOAD: - case MOD_SHUTDOWN: - destroy_dev(nvram_dev); - break; - default: - return (EOPNOTSUPP); - } - return (0); -} -DEV_MODULE(nvram, nvram_modevent, NULL); - #endif /* DEV_ISA */ ==== //depot/projects/hammer/sys/conf/files.amd64#96 (text+ko) ==== @@ -185,6 +185,7 @@ dev/mem/memutil.c optional mem dev/nfe/if_nfe.c optional nfe pci dev/nve/if_nve.c optional nve pci +dev/nvram/nvram.c optional nvram isa dev/rr232x/os_bsd.c optional rr232x dev/rr232x/osm_bsd.c optional rr232x dev/rr232x/rr232x_config.c optional rr232x ==== //depot/projects/hammer/sys/conf/files.i386#82 (text+ko) ==== @@ -211,6 +211,7 @@ dev/mse/mse_isa.c optional mse isa dev/nfe/if_nfe.c optional nfe pci dev/nve/if_nve.c optional nve pci +dev/nvram/nvram.c optional nvram isa dev/pcf/pcf_isa.c optional pcf dev/random/nehemiah.c optional random dev/rr232x/os_bsd.c optional rr232x ==== //depot/projects/hammer/sys/i386/conf/DEFAULTS#7 (text+ko) ==== @@ -15,6 +15,7 @@ # Pseudo devices. device mem # Memory and kernel memory devices device io # I/O device +device nvram # Access to rtc cmos via /dev/nvram # UART chips on this platform device uart_ns8250 ==== //depot/projects/hammer/sys/i386/include/clock.h#14 (text+ko) ==== @@ -31,7 +31,8 @@ int acquire_timer2(int mode); int release_timer2(void); -int rtcin(int val); +int rtcin(int reg); +void writertc(int reg, unsigned char val); int sysbeep(int pitch, int period); void timer_restore(void); void init_TSC(void); ==== //depot/projects/hammer/sys/i386/isa/clock.c#39 (text+ko) ==== @@ -438,7 +438,7 @@ return (val); } -static void +void writertc(int reg, u_char val) { @@ -938,99 +938,4 @@ DRIVER_MODULE(attimer, isa, attimer_driver, attimer_devclass, 0, 0); DRIVER_MODULE(attimer, acpi, attimer_driver, attimer_devclass, 0, 0); -/* - * Linux-style /dev/nvram driver - * - * cmos ram starts at bytes 14 through 128, for a total of 114 bytes. - * bytes 16 through 31 are checksummed at byte 32. - * Unlike Linux, you have to take care of the checksums yourself. - * The driver exposes byte 14 as file offset 0. - */ - -#define NVRAM_FIRST RTC_DIAG /* 14 */ -#define NVRAM_LAST 128 - -static d_open_t nvram_open; -static d_read_t nvram_read; -static d_write_t nvram_write; - -static struct cdev *nvram_dev; - -static struct cdevsw nvram_cdevsw = { - .d_version = D_VERSION, - .d_flags = D_NEEDGIANT, - .d_open = nvram_open, - .d_read = nvram_read, - .d_write = nvram_write, - .d_name = "nvram", -}; - -static int -nvram_open(struct cdev *dev __unused, int flags, int fmt __unused, - struct thread *td) -{ - int error = 0; - - if (flags & FWRITE) - error = securelevel_gt(td->td_ucred, 0); - - return (error); -} - -static int -nvram_read(struct cdev *dev, struct uio *uio, int flags) -{ - int nv_off; - u_char v; - int error = 0; - - while (uio->uio_resid > 0 && error == 0) { - nv_off = uio->uio_offset + NVRAM_FIRST; - if (nv_off < NVRAM_FIRST || nv_off >= NVRAM_LAST) - return (0); /* Signal EOF */ - /* Single byte at a time */ - v = rtcin(nv_off); - error = uiomove(&v, 1, uio); - } - return (error); - -} - -static int -nvram_write(struct cdev *dev, struct uio *uio, int flags) -{ - int nv_off; - u_char v; - int error = 0; - - while (uio->uio_resid > 0 && error == 0) { - nv_off = uio->uio_offset + NVRAM_FIRST; - if (nv_off < NVRAM_FIRST || nv_off >= NVRAM_LAST) - return (0); /* Signal EOF */ - /* Single byte at a time */ - error = uiomove(&v, 1, uio); - writertc(nv_off, v); - } - return (error); -} - -static int -nvram_modevent(module_t mod __unused, int type, void *data __unused) -{ - switch (type) { - case MOD_LOAD: - nvram_dev = make_dev(&nvram_cdevsw, 0, - UID_ROOT, GID_KMEM, 0640, "nvram"); - break; - case MOD_UNLOAD: - case MOD_SHUTDOWN: - destroy_dev(nvram_dev); - break; - default: - return (EOPNOTSUPP); - } - return (0); -} -DEV_MODULE(nvram, nvram_modevent, NULL); - #endif /* DEV_ISA */