Date: Fri, 19 Jun 2020 18:36:11 +0000 (UTC) From: Brandon Bergren <bdragon@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362406 - in head: share/man/man4/man4.powerpc sys/dev/powermac_nvram usr.sbin/nvram Message-ID: <202006191836.05JIaBmr068589@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bdragon Date: Fri Jun 19 18:36:10 2020 New Revision: 362406 URL: https://svnweb.freebsd.org/changeset/base/362406 Log: [PowerPC] De-giant powermac_nvram, update documentation * Remove the giant lock requirement from powermac_nvram. * Update manual pages to reflect current state. Reviewed by: bcr (manpages), jhibbits Sponsored by: Tag1 Consulting, Inc. Differential Revision: https://reviews.freebsd.org/D24812 Modified: head/share/man/man4/man4.powerpc/powermac_nvram.4 head/sys/dev/powermac_nvram/powermac_nvram.c head/sys/dev/powermac_nvram/powermac_nvramvar.h head/usr.sbin/nvram/nvram.8 Modified: head/share/man/man4/man4.powerpc/powermac_nvram.4 ============================================================================== --- head/share/man/man4/man4.powerpc/powermac_nvram.4 Fri Jun 19 18:34:27 2020 (r362405) +++ head/share/man/man4/man4.powerpc/powermac_nvram.4 Fri Jun 19 18:36:10 2020 (r362406) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 5, 2010 +.Dd June 19, 2020 .Dt POWERMAC_NVRAM 4 powerpc .Os .Sh NAME @@ -50,8 +50,10 @@ The .Nm driver provides access to the Open Firmware configuration NVRAM available on the Apple PowerPC-based machines. +.Pp +This driver currently supports "Core99" machines containing a Sharp, Micron, +or AMD NVRAM. .Sh SEE ALSO -.Xr eeprom 8 , .Xr nvram 8 .Sh HISTORY The Modified: head/sys/dev/powermac_nvram/powermac_nvram.c ============================================================================== --- head/sys/dev/powermac_nvram/powermac_nvram.c Fri Jun 19 18:34:27 2020 (r362405) +++ head/sys/dev/powermac_nvram/powermac_nvram.c Fri Jun 19 18:36:10 2020 (r362406) @@ -34,6 +34,8 @@ #include <sys/bus.h> #include <sys/conf.h> #include <sys/kernel.h> +#include <sys/lock.h> +#include <sys/sx.h> #include <sys/uio.h> #include <dev/ofw/openfirm.h> @@ -99,7 +101,6 @@ static d_write_t powermac_nvram_write; static struct cdevsw powermac_nvram_cdevsw = { .d_version = D_VERSION, - .d_flags = D_NEEDGIANT, .d_open = powermac_nvram_open, .d_close = powermac_nvram_close, .d_read = powermac_nvram_read, @@ -180,6 +181,8 @@ powermac_nvram_attach(device_t dev) "powermac_nvram"); sc->sc_cdev->si_drv1 = sc; + sx_init(&sc->sc_lock, "powermac_nvram"); + return 0; } @@ -195,6 +198,8 @@ powermac_nvram_detach(device_t dev) if (sc->sc_cdev != NULL) destroy_dev(sc->sc_cdev); + + sx_destroy(&sc->sc_lock); return 0; } @@ -203,11 +208,17 @@ static int powermac_nvram_open(struct cdev *dev, int flags, int fmt, struct thread *td) { struct powermac_nvram_softc *sc = dev->si_drv1; + int err; + err = 0; + sx_xlock(&sc->sc_lock); if (sc->sc_isopen) - return EBUSY; - sc->sc_isopen = 1; + err = EBUSY; + else + sc->sc_isopen = 1; sc->sc_rpos = sc->sc_wpos = 0; + sx_xunlock(&sc->sc_lock); + return 0; } @@ -218,10 +229,12 @@ powermac_nvram_close(struct cdev *dev, int fflag, int struct core99_header *header; vm_offset_t bank; + sx_xlock(&sc->sc_lock); if (sc->sc_wpos != sizeof(sc->sc_data)) { /* Short write, restore in-memory copy */ bcopy((void *)sc->sc_bank, (void *)sc->sc_data, NVRAM_SIZE); sc->sc_isopen = 0; + sx_xunlock(&sc->sc_lock); return 0; } @@ -242,10 +255,12 @@ powermac_nvram_close(struct cdev *dev, int fflag, int if (erase_bank(sc->sc_dev, (uint8_t *)bank) != 0 || write_bank(sc->sc_dev, (uint8_t *)bank, sc->sc_data) != 0) { sc->sc_isopen = 0; + sx_xunlock(&sc->sc_lock); return ENOSPC; } sc->sc_bank = bank; sc->sc_isopen = 0; + sx_xunlock(&sc->sc_lock); return 0; } @@ -256,6 +271,8 @@ powermac_nvram_read(struct cdev *dev, struct uio *uio, struct powermac_nvram_softc *sc = dev->si_drv1; rv = 0; + + sx_xlock(&sc->sc_lock); while (uio->uio_resid > 0) { data_available = sizeof(sc->sc_data) - sc->sc_rpos; if (data_available > 0) { @@ -269,6 +286,8 @@ powermac_nvram_read(struct cdev *dev, struct uio *uio, break; } } + sx_xunlock(&sc->sc_lock); + return rv; } @@ -282,6 +301,8 @@ powermac_nvram_write(struct cdev *dev, struct uio *uio return EINVAL; rv = 0; + + sx_xlock(&sc->sc_lock); while (uio->uio_resid > 0) { data_available = sizeof(sc->sc_data) - sc->sc_wpos; if (data_available > 0) { @@ -295,6 +316,8 @@ powermac_nvram_write(struct cdev *dev, struct uio *uio break; } } + sx_xunlock(&sc->sc_lock); + return rv; } @@ -500,6 +523,8 @@ erase_bank(device_t dev, uint8_t *bank) struct powermac_nvram_softc *sc; sc = device_get_softc(dev); + + sx_assert(&sc->sc_lock, SA_XLOCKED); if (sc->sc_type == FLASH_TYPE_AMD) return (erase_bank_amd(dev, bank)); else @@ -512,6 +537,8 @@ write_bank(device_t dev, uint8_t *bank, uint8_t *data) struct powermac_nvram_softc *sc; sc = device_get_softc(dev); + + sx_assert(&sc->sc_lock, SA_XLOCKED); if (sc->sc_type == FLASH_TYPE_AMD) return (write_bank_amd(dev, bank, data)); else Modified: head/sys/dev/powermac_nvram/powermac_nvramvar.h ============================================================================== --- head/sys/dev/powermac_nvram/powermac_nvramvar.h Fri Jun 19 18:34:27 2020 (r362405) +++ head/sys/dev/powermac_nvram/powermac_nvramvar.h Fri Jun 19 18:36:10 2020 (r362406) @@ -49,6 +49,7 @@ struct powermac_nvram_softc { device_t sc_dev; + struct sx sc_lock; phandle_t sc_node; vm_offset_t sc_bank; vm_offset_t sc_bank0; Modified: head/usr.sbin/nvram/nvram.8 ============================================================================== --- head/usr.sbin/nvram/nvram.8 Fri Jun 19 18:34:27 2020 (r362405) +++ head/usr.sbin/nvram/nvram.8 Fri Jun 19 18:36:10 2020 (r362406) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 1, 2006 +.Dd June 19, 2020 .Dt NVRAM 8 powerpc .Os .Sh NAME @@ -98,8 +98,7 @@ to .Pp .Dl "nvram -d foo -d bar baz=100" .Sh SEE ALSO -.Xr powermac_nvram 4 , -.Xr eeprom 8 +.Xr powermac_nvram 4 .Sh HISTORY The .Nm @@ -111,8 +110,3 @@ Darwin/Mac OS X utility. .Sh AUTHORS .An Maxim Sobolev Aq Mt sobomax@FreeBSD.org -.Sh BUGS -Currently, -.Nm -only supports systems equipped with AMD flash and is only tested on Apple -G4-based Mac Mini machines.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202006191836.05JIaBmr068589>