From owner-svn-src-all@freebsd.org Fri Jun 19 18:36:12 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 203BE335A79; Fri, 19 Jun 2020 18:36:12 +0000 (UTC) (envelope-from bdragon@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49pSDq75J3z4dPC; Fri, 19 Jun 2020 18:36:11 +0000 (UTC) (envelope-from bdragon@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EEB9C1F934; Fri, 19 Jun 2020 18:36:11 +0000 (UTC) (envelope-from bdragon@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 05JIaBi0068593; Fri, 19 Jun 2020 18:36:11 GMT (envelope-from bdragon@FreeBSD.org) Received: (from bdragon@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 05JIaBmr068589; Fri, 19 Jun 2020 18:36:11 GMT (envelope-from bdragon@FreeBSD.org) Message-Id: <202006191836.05JIaBmr068589@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdragon set sender to bdragon@FreeBSD.org using -f From: Brandon Bergren Date: Fri, 19 Jun 2020 18:36:11 +0000 (UTC) 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 X-SVN-Group: head X-SVN-Commit-Author: bdragon X-SVN-Commit-Paths: in head: share/man/man4/man4.powerpc sys/dev/powermac_nvram usr.sbin/nvram X-SVN-Commit-Revision: 362406 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jun 2020 18:36:12 -0000 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 #include #include +#include +#include #include #include @@ -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.