[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
This commit is contained in:
parent
188aee740f
commit
37f530582d
@ -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
|
||||
|
@ -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 devtype, struct thread *td
|
||||
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 devtype, struct thread *td
|
||||
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, int ioflag)
|
||||
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, int ioflag)
|
||||
break;
|
||||
}
|
||||
}
|
||||
sx_xunlock(&sc->sc_lock);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -282,6 +301,8 @@ powermac_nvram_write(struct cdev *dev, struct uio *uio, int ioflag)
|
||||
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, int ioflag)
|
||||
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
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user