char: nvram: disable on ARM
PATCH 1/1 char: nvram: disable on ARM
/dev/nvram was never meant to be used alongside the RTC CMOS driver from drivers/rtc as it already expose the NVRAM through another interface.. Anyway, the last defconfig to enable it properly was removed in 2010 so prevent ARM users from selecting it.
--- drivers/char/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/Kconfig +1 -1
@@ -264,7 +264,7 @@ source "drivers/char/hw_random/Kconfig" config NVRAM tristate "/dev/nvram support" - depends on ATARI || X86 || (ARM && RTC_DRV_CMOS) || GENERIC_NVRAM + depends on ATARI || X86 || GENERIC_NVRAM ---help--- If you say Y here and create a character special file /dev/nvram with major number 10 and minor number 144 using mknod ("man mknod"),
Signature · 1 line
2.15.1
Quoted 15 lines · Alexandre Belloni
/dev/nvramwas never meant to be used alongside the RTC CMOS driver fromdrivers/rtcas it already expose the NVRAM through another interface.. Anyway, the last defconfig to enable it properly was removed in 2010 so prevent ARM users from selecting it.Signed-off-by Alexandre Belloni <[email protected]>--- drivers/char/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/char/Kconfig +0
-0
drivers/char/Kconfig source "drivers/char/hw_random/Kconfig" · line 270
Quoted 8 lines
drivers/char/Kconfig +1
-1@@ -264,7 +264,7 @@ source "drivers/char/hw_random/Kconfig" config NVRAM tristate "/dev/nvram support" - depends on ATARI || X86 || (ARM && RTC_DRV_CMOS) || GENERIC_NVRAM + depends on ATARI || X86 || GENERIC_NVRAM ---help--- If you say Y here and create a character special file /dev/nvram with major number 10 and minor number 144 using mknod ("man mknod"),
The change looks good:
but taking a closer look raises a few other points:
* arch/arm/kernel/time.c has this code
#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || \
defined(CONFIG_NVRAM) || defined(CONFIG_NVRAM_MODULE)/* this needs a better home */DEFINE_SPINLOCK(rtc_lock);EXPORT_SYMBOL(rtc_lock);
#endif /* pc-style 'CMOS' RTC support */
That can be adapted now, or maybe we could move all definitions into a common place (that needs some more planning).
* similarly, this line in nvram.c can be simplified:
#if defined(CONFIG_ATARI)
# define MACH ATARI
#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) /* and ?? */ # define MACH PC
#else
# error Cannot build nvram driver for this machine configuration. #endif
* GENERIC_NVRAM is not really generic, instead this seems to be the chardev that is used for 32-bit powerpc (powermac, 85xx, 86xx), while 64-bit powerpc (cell, maple, opal, pseries) use code from arch/powerpc/kernel/nvram_64.c, with the same underlying arch hooks. The nvram_64 code appears to be mostly a superset of the 32-bit generic_nvram one.
* The code in drivers/char/nvram is not used at all when GENERIC_NVRAM is set, and half the code in there is different between x86 and atari.
* most of the external interface in include/linux/nvram.h is unused, the rest tends to be architecture specific
* The procfs file appears to be completely useless on any 64-bit x86 machine, this is what I see:
$ cat /proc/driver/nvram Checksum status: valid # floppies : 0 Floppy 0 type : none Floppy 1 type : none HD 0 type : none HD 1 type : none HD type 48 data: 0/0/0 C/H/S, precomp 0, lz 0 HD type 49 data: 156/0/0 C/H/S, precomp 0, lz 0 DOS base memory: 635 kB Extended memory: 65535 kB (configured), 65535 kB (tested) Gfx adapter : EGA, VGA, ... (with BIOS) FPU : not installed
Arnd
Quoted 4 lines · Arnd Bergmann
*
arch/arm/kernel/time.chas this code#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || \ defined(CONFIG_NVRAM) || defined(CONFIG_NVRAM_MODULE)
Quoted 8 lines
/* this needs a better home */
DEFINE_SPINLOCK(rtc_lock);EXPORT_SYMBOL(rtc_lock);
#endif /* pc-style 'CMOS' RTC support */That can be adapted now, or maybe we could move all definitions into a common place (that needs some more planning).
Yes, on arm, the rtc_lock is mostly there to please drivers/rtc/rtc-cmos.c. Maybe we could make the locking in this driver x86 and PPC specific.
If we can get rid of arch/powerpc/platforms/chrp/time.c and arch/powerpc/platforms/maple/time.c (so much duplicated code), then it is x86 only.
Quoted 26 lines
* similarly, this line in
nvram.ccan be simplified:
#ifdefined(CONFIG_ATARI)
# define MACH ATARI
#elifdefined(__i386__)||defined(__x86_64__)||defined(__arm__)/* and ?? */ # define MACH PC
#else
# error Cannot build nvram driver for this machine configuration. #endif*
GENERIC_NVRAMis not really generic, instead this seems to be the chardev that is used for 32-bit powerpc (powermac, 85xx, 86xx), while 64-bit powerpc (cell, maple, opal, pseries) use code fromarch/powerpc/kernel/nvram_64.c, with the same underlying arch hooks. Thenvram_64code appears to be mostly a superset of the 32-bitgeneric_nvramone.* The code in
drivers/char/nvramis not used at all whenGENERIC_NVRAMis set, and half the code in there is different between x86 and atari.* most of the external interface in
include/linux/nvram.his unused, the rest tends to be architecture specific* The procfs file appears to be completely useless on any 64-bit x86 machine, this is what I see:
Quoted 14 lines
$ cat /proc/driver/nvram Checksum status: valid # floppies : 0 Floppy 0 type : none Floppy 1 type : none HD 0 type : none HD 1 type : none HD type 48 data: 0/0/0 C/H/S, precomp 0, lz 0 HD type 49 data: 156/0/0 C/H/S, precomp 0, lz 0 DOS base memory: 635 kB Extended memory: 65535 kB (configured), 65535 kB (tested) Gfx adapter : EGA, VGA, ... (with BIOS) FPU : not installed
I really don't think anyone is using that but I don't really know much about x86 and the specification this may be part of.
I see the info may be used in drivers/video/fbdev/ and drivers/platform/x86/thinkpad_acpi.c
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering http://bootlin.com
Arnd Bergmann
maintainerQuoted 14 lines · Alexandre Belloni
Quoted 4 lines · Arnd Bergmann
*
arch/arm/kernel/time.chas this code#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || \ defined(CONFIG_NVRAM) || defined(CONFIG_NVRAM_MODULE)Quoted 8 lines
/* this needs a better home */
DEFINE_SPINLOCK(rtc_lock);EXPORT_SYMBOL(rtc_lock);
#endif /* pc-style 'CMOS' RTC support */That can be adapted now, or maybe we could move all definitions into a common place (that needs some more planning).
Quoted 7 lines
Yes, on arm, the
rtc_lockis mostly there to pleasedrivers/rtc/rtc-cmos.c. Maybe we could make the locking in this driver x86 and PPC specific.If we can get rid of
arch/powerpc/platforms/chrp/time.candarch/powerpc/platforms/maple/time.c(so much duplicated code), then it is x86 only.
What about these:
arch/alpha/kernel/rtc.c: spin_lock(&rtc_lock); arch/alpha/kernel/rtc.c: spin_unlock(&rtc_lock);
arch/alpha/kernel/time.c:DEFINE_SPINLOCK(rtc_lock); arch/alpha/kernel/time.c:EXPORT_SYMBOL(rtc_lock); arch/arm/kernel/time.c:DEFINE_SPINLOCK(rtc_lock); arch/arm/kernel/time.c:EXPORT_SYMBOL(rtc_lock); arch/m32r/kernel/time.c:DEFINE_SPINLOCK(rtc_lock); arch/m32r/kernel/time.c:EXPORT_SYMBOL(rtc_lock); arch/m68k/atari/time.c:DEFINE_SPINLOCK(rtc_lock); arch/m68k/atari/time.c:EXPORT_SYMBOL_GPL(rtc_lock); arch/mn10300/kernel/rtc.c:DEFINE_SPINLOCK(rtc_lock); arch/mn10300/kernel/rtc.c:EXPORT_SYMBOL(rtc_lock); arch/powerpc/kernel/time.c:DEFINE_SPINLOCK(rtc_lock); arch/powerpc/kernel/time.c:EXPORT_SYMBOL_GPL(rtc_lock); arch/sparc/kernel/time_32.c:DEFINE_SPINLOCK(rtc_lock); arch/sparc/kernel/time_32.c:EXPORT_SYMBOL(rtc_lock); arch/sparc/kernel/time_64.c:DEFINE_SPINLOCK(rtc_lock);
Are they all obsolete?
Quoted 41 lines
Quoted 26 lines
* similarly, this line in
nvram.ccan be simplified:
#ifdefined(CONFIG_ATARI)
# define MACH ATARI
#elifdefined(__i386__)||defined(__x86_64__)||defined(__arm__)/* and ?? */ # define MACH PC
#else
# error Cannot build nvram driver for this machine configuration. #endif*
GENERIC_NVRAMis not really generic, instead this seems to be the chardev that is used for 32-bit powerpc (powermac, 85xx, 86xx), while 64-bit powerpc (cell, maple, opal, pseries) use code fromarch/powerpc/kernel/nvram_64.c, with the same underlying arch hooks. Thenvram_64code appears to be mostly a superset of the 32-bitgeneric_nvramone.* The code in
drivers/char/nvramis not used at all whenGENERIC_NVRAMis set, and half the code in there is different between x86 and atari.* most of the external interface in
include/linux/nvram.his unused, the rest tends to be architecture specific* The procfs file appears to be completely useless on any 64-bit x86 machine, this is what I see:
Quoted 14 lines
$ cat /proc/driver/nvram Checksum status: valid # floppies : 0 Floppy 0 type : none Floppy 1 type : none HD 0 type : none HD 1 type : none HD type 48 data: 0/0/0 C/H/S, precomp 0, lz 0 HD type 49 data: 156/0/0 C/H/S, precomp 0, lz 0 DOS base memory: 635 kB Extended memory: 65535 kB (configured), 65535 kB (tested) Gfx adapter : EGA, VGA, ... (with BIOS) FPU : not installed
Quoted 5 lines
I really don't think anyone is using that but I don't really know much about x86 and the specification this may be part of.
I see the info may be used in
drivers/video/fbdev/anddrivers/platform/x86/thinkpad_acpi.c
The thinkpad_acpi driver seems to look at some other bytes in the nvram, which have a platform specific meaning.
For drivers/video/fbdev/, these appear to all be for pre-x86 Apple Macintosh (m68k or powerpc).
Arnd
Quoted 44 lines · Arnd Bergmann
Quoted 14 lines · Alexandre Belloni
Quoted 4 lines · Arnd Bergmann
*
arch/arm/kernel/time.chas this code#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || \ defined(CONFIG_NVRAM) || defined(CONFIG_NVRAM_MODULE)Quoted 8 lines
/* this needs a better home */
DEFINE_SPINLOCK(rtc_lock);EXPORT_SYMBOL(rtc_lock);
#endif /* pc-style 'CMOS' RTC support */That can be adapted now, or maybe we could move all definitions into a common place (that needs some more planning).
Quoted 7 lines
Yes, on arm, the
rtc_lockis mostly there to pleasedrivers/rtc/rtc-cmos.c. Maybe we could make the locking in this driver x86 and PPC specific.If we can get rid of
arch/powerpc/platforms/chrp/time.candarch/powerpc/platforms/maple/time.c(so much duplicated code), then it is x86 only.What about these:
arch/alpha/kernel/rtc.c: spin_lock(&rtc_lock); arch/alpha/kernel/rtc.c: spin_unlock(&rtc_lock);arch/alpha/kernel/time.c:DEFINE_SPINLOCK(rtc_lock); arch/alpha/kernel/time.c:EXPORT_SYMBOL(rtc_lock); arch/arm/kernel/time.c:DEFINE_SPINLOCK(rtc_lock); arch/arm/kernel/time.c:EXPORT_SYMBOL(rtc_lock); arch/m32r/kernel/time.c:DEFINE_SPINLOCK(rtc_lock); arch/m32r/kernel/time.c:EXPORT_SYMBOL(rtc_lock); arch/m68k/atari/time.c:DEFINE_SPINLOCK(rtc_lock); arch/m68k/atari/time.c:EXPORT_SYMBOL_GPL(rtc_lock); arch/mn10300/kernel/rtc.c:DEFINE_SPINLOCK(rtc_lock); arch/mn10300/kernel/rtc.c:EXPORT_SYMBOL(rtc_lock); arch/powerpc/kernel/time.c:DEFINE_SPINLOCK(rtc_lock); arch/powerpc/kernel/time.c:EXPORT_SYMBOL_GPL(rtc_lock); arch/sparc/kernel/time_32.c:DEFINE_SPINLOCK(rtc_lock); arch/sparc/kernel/time_32.c:EXPORT_SYMBOL(rtc_lock); arch/sparc/kernel/time_64.c:DEFINE_SPINLOCK(rtc_lock);
Quoted 2 lines
Are they all obsolete?
Yes and no. For those architecture, the spinlock is only used to make the driver compile. It is probably not actually needed or at least it can be made local to the driver.
For alpha, I just realized I never sent a patch removing the spinlock usage, I'll do that this cycle:
https://github.com/alexandrebelloni/linux/commit/e79e2a754a3a67f2d7e906bfda0042f9dcf66a0b
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
$ cat /proc/driver/nvram Checksum status: valid # floppies : 0 Floppy 0 type : none Floppy 1 type : none HD 0 type : none HD 1 type : none HD type 48 data: 0/0/0 C/H/S, precomp 0, lz 0 HD type 49 data: 156/0/0 C/H/S, precomp 0, lz 0 DOS base memory: 635 kB Extended memory: 65535 kB (configured), 65535 kB (tested) Gfx adapter : EGA, VGA, ... (with BIOS) FPU : not installed
Quoted 9 lines
Quoted 5 lines
I really don't think anyone is using that but I don't really know much about x86 and the specification this may be part of.
I see the info may be used in
drivers/video/fbdev/anddrivers/platform/x86/thinkpad_acpi.cThe
thinkpad_acpidriver seems to look at some other bytes in the nvram, which have a platform specific meaning.
Yeah, I was more concerned that they need drivers/char/nvram.c for nvram_read_byte so we can't simply remove the driver.
Quoted 3 lines
For
drivers/video/fbdev/, these appear to all be for pre-x86 Apple Macintosh (m68k or powerpc).
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering http://bootlin.com
Arnd Bergmann
maintainerQuoted 24 lines · Alexandre Belloni
Quoted 23 lines · Arnd Bergmann
On Wed, Feb 7, 2018 at 2:55 AM, Alexandre Belloni
Quoted 20 lines
Quoted 5 lines
$ cat /proc/driver/nvram Checksum status: valid # floppies : 0 Floppy 0 type : none Floppy 1 type : noneQuoted 9 lines
HD 0 type : none HD 1 type : none HD type 48 data: 0/0/0 C/H/S, precomp 0, lz 0 HD type 49 data: 156/0/0 C/H/S, precomp 0, lz 0 DOS base memory: 635 kB Extended memory: 65535 kB (configured), 65535 kB (tested) Gfx adapter : EGA, VGA, ... (with BIOS) FPU : not installedI really don't think anyone is using that but I don't really know much about x86 and the specification this may be part of.
I see the info may be used in
drivers/video/fbdev/anddrivers/platform/x86/thinkpad_acpi.c
Quoted 6 lines
Quoted 3 lines
The
thinkpad_acpidriver seems to look at some other bytes in the nvram, which have a platform specific meaning.Yeah, I was more concerned that they need
drivers/char/nvram.cfornvram_read_byteso we can't simply remove the driver.
Ok, so the procfs interface may be obsolete, but we still need an interface into the CMOS NVRAM data.
I see that the x86 version of nvram_read_byte is just a wrapper around CMOS_READ(14 + addr). We also have some drivers that call the low-level function directly:
arch/x86/include/asm/floppy.h: val = CMOS_READ(0x10) & 15; arch/x86/kernel/bootflag.c: v = CMOS_READ(sbf_port); drivers/char/mwave/smapi.c: usSmapiID = CMOS_READ(0x7C);
drivers/input/misc/wistron_btns.c: qlen = CMOS_READ(cmos_address);
I suppose we could make the thinkpad driver do the same, or provide a 'static inline' version of nvram_read_byte somewhere.
Arnd
Quoted 30 lines · Arnd Bergmann
Quoted 28 lines · Alexandre Belloni
Quoted 26 lines · Arnd Bergmann
On Wed, Feb 7, 2018 at 2:55 AM, Alexandre Belloni
Quoted 15 lines
Quoted 5 lines
$ cat /proc/driver/nvram Checksum status: valid # floppies : 0 Floppy 0 type : none Floppy 1 type : noneQuoted 9 lines
HD 0 type : none HD 1 type : none HD type 48 data: 0/0/0 C/H/S, precomp 0, lz 0 HD type 49 data: 156/0/0 C/H/S, precomp 0, lz 0 DOS base memory: 635 kB Extended memory: 65535 kB (configured), 65535 kB (tested) Gfx adapter : EGA, VGA, ... (with BIOS) FPU : not installedQuoted 5 lines
I really don't think anyone is using that but I don't really know much about x86 and the specification this may be part of.
I see the info may be used in
drivers/video/fbdev/anddrivers/platform/x86/thinkpad_acpi.cThe
thinkpad_acpidriver seems to look at some other bytes in the nvram, which have a platform specific meaning.
Quoted 6 lines
Quoted 2 lines
Yeah, I was more concerned that they need
drivers/char/nvram.cfornvram_read_byteso we can't simply remove the driver.Ok, so the procfs interface may be obsolete, but we still need an interface into the CMOS NVRAM data.
Actually, I just found
https://unix.stackexchange.com/questions/331419/is-dev-nvram-dangerous-to-write-to
So it seems to have real values for some people (even if they are wrong).
That also points to https://sourceforge.net/projects/nvram-wakeup/ but I don't think it is necessary. The RTC driver should be able to wakeup an x86 platform.
All the other uses of /dev/nvram I could find with a simple google search (i.e. saving and restoring CMOS settings) could just use /sys/class/rtc/rtc0/device/nvram
Quoted 4 lines
I see that the x86 version of
nvram_read_byteis just a wrapper aroundCMOS_READ(14 + addr). We also have some drivers that call the low-level function directly:
Quoted 8 lines
arch/x86/include/asm/floppy.h: val = CMOS_READ(0x10) & 15; arch/x86/kernel/bootflag.c: v = CMOS_READ(sbf_port); drivers/char/mwave/smapi.c: usSmapiID = CMOS_READ(0x7C);
drivers/input/misc/wistron_btns.c: qlen =CMOS_READ(cmos_address);I suppose we could make the thinkpad driver do the same, or provide a 'static inline' version of
nvram_read_bytesomewhere.
I guess we can do that, provided we take rtc_lock before using CMOS_READ.
Thinking of it, I think this means we don't need the lock for powerpc as nvram_read_byte doesn't take it. So I guess it is only needed on x86.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering http://bootlin.com
Quoted 23 lines · Alexandre Belloni
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
I really don't think anyone is using that but I don't really know much about x86 and the specification this may be part of.
I see the info may be used in
drivers/video/fbdev/anddrivers/platform/x86/thinkpad_acpi.cThe
thinkpad_acpidriver seems to look at some other bytes in the nvram, which have a platform specific meaning.Quoted 6 lines
Quoted 2 lines
Yeah, I was more concerned that they need
drivers/char/nvram.cfornvram_read_byteso we can't simply remove the driver.Ok, so the procfs interface may be obsolete, but we still need an interface into the CMOS NVRAM data.
Actually, I just found
https://unix.stackexchange.com/questions/331419/is-dev-nvram-dangerous-to-write-toSo it seems to have real values for some people (even if they are wrong).
Quoted 8 lines
That also points to https://sourceforge.net/projects/nvram-wakeup/ but I don't think it is necessary. The RTC driver should be able to wakeup an x86 platform.
All the other uses of
/dev/nvramI could find with a simple google search (i.e. saving and restoring CMOS settings) could just use/sys/class/rtc/rtc0/device/nvram
Ok, the chromeos guys are using it for verified boot it seems:
https://chromium.googlesource.com/chromiumos/platform/vboot_reference
I'm wondering whether they really care about the checksum though.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering http://bootlin.com