From ba88eb2302157bfda87e8058bb9de340a19362e4 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Tue, 17 Aug 2010 06:17:06 +0200 Subject: [PATCH] Sync alpm(4) with FreeBSD. --- Makefile_upgrade.inc | 2 + share/man/man4/Makefile | 1 + share/man/man4/{man4.i386 => }/alpm.4 | 8 +- share/man/man4/man4.i386/Makefile | 2 +- sys/dev/powermng/alpm/alpm.c | 208 ++++++++++++++------------ 5 files changed, 123 insertions(+), 98 deletions(-) rename share/man/man4/{man4.i386 => }/alpm.4 (90%) diff --git a/Makefile_upgrade.inc b/Makefile_upgrade.inc index ca30ec0d14..edfa573fde 100644 --- a/Makefile_upgrade.inc +++ b/Makefile_upgrade.inc @@ -1494,6 +1494,8 @@ TO_REMOVE+=/usr/share/man/cat3/evdns_search_clear.3.gz TO_REMOVE+=/usr/share/man/cat3/evdns_search_add.3.gz TO_REMOVE+=/usr/share/man/cat3/evdns_search_ndots_set.3.gz TO_REMOVE+=/usr/share/man/cat3/evdns_set_log_fn.3.gz +TO_REMOVE+=/usr/share/man/cat4/i386/alpm.4.gz +TO_REMOVE+=/usr/share/man/man4/i386/alpm.4.gz # XXX Remove when adjusted to the new 802.11 framework TO_REMOVE+=/boot/modules/if_acx.ko diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile index 925b0a2365..46a751ad7c 100644 --- a/share/man/man4/Makefile +++ b/share/man/man4/Makefile @@ -25,6 +25,7 @@ MAN= aac.4 \ aibs.4 \ alc.4 \ ale.4 \ + alpm.4 \ altq.4 \ amd.4 \ amr.4 \ diff --git a/share/man/man4/man4.i386/alpm.4 b/share/man/man4/alpm.4 similarity index 90% rename from share/man/man4/man4.i386/alpm.4 rename to share/man/man4/alpm.4 index 901ae95e00..e2eada7aef 100644 --- a/share/man/man4/man4.i386/alpm.4 +++ b/share/man/man4/alpm.4 @@ -22,17 +22,17 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/share/man/man4/man4.i386/alpm.4,v 1.8.2.5 2001/08/17 13:08:45 ru Exp $ -.\" $DragonFly: src/share/man/man4/man4.i386/alpm.4,v 1.2 2003/06/17 04:36:59 dillon Exp $ +.\" $FreeBSD: src/share/man/man4/alpm.4,v 1.5 2010/02/08 23:30:28 gavin Exp $ .\" .Dd February 13, 1999 -.Dt ALPM 4 i386 +.Dt ALPM 4 .Os .Sh NAME .Nm alpm .Nd Acer Aladdin 15x3 Power Management controller driver .Sh SYNOPSIS .Cd device smbus +.Cd device smb .Cd device alpm .Sh DESCRIPTION This driver provides access to the @@ -52,7 +52,7 @@ monitoring chip of your mainboard. .Sh HISTORY The .Nm -manual page example first appeared in +manual page first appeared in .Fx 4.0 . .Sh AUTHORS This diff --git a/share/man/man4/man4.i386/Makefile b/share/man/man4/man4.i386/Makefile index 496cabc745..59e1846784 100644 --- a/share/man/man4/man4.i386/Makefile +++ b/share/man/man4/man4.i386/Makefile @@ -1,7 +1,7 @@ # $FreeBSD: src/share/man/man4/man4.i386/Makefile,v 1.122.2.12 2003/04/15 17:23:32 fjoe Exp $ # $DragonFly: src/share/man/man4/man4.i386/Makefile,v 1.15 2008/08/28 09:47:04 hasso Exp $ -MAN= aic.4 alpm.4 amdpm.4 apm.4 ar.4 asc.4 asr.4 \ +MAN= aic.4 amdpm.4 apm.4 ar.4 asc.4 asr.4 \ cs.4 cy.4 \ dgb.4 digi.4 el.4 en.4 ep.4 est.4 ex.4 fe.4 glxsb.4 gsc.4 \ ie.4 io.4 labpc.4 le.4 linux.4 lnc.4 longrun.4 \ diff --git a/sys/dev/powermng/alpm/alpm.c b/sys/dev/powermng/alpm/alpm.c index d363ec4ce0..f574d5ba0c 100644 --- a/sys/dev/powermng/alpm/alpm.c +++ b/sys/dev/powermng/alpm/alpm.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/pci/alpm.c,v 1.24 2005/05/29 04:42:29 nyan Exp $ + * $FreeBSD: src/sys/pci/alpm.c,v 1.26 2007/01/11 19:56:24 jhb Exp $ * */ @@ -31,17 +31,16 @@ * Power Management support for the Acer M15x3 chipsets */ #include +#include #include -#include +#include #include -#include -#include #include +#include #include #include -#include #include #include "smbus_if.h" @@ -55,10 +54,8 @@ static int alpm_debug = 0; #define ACER_M1543_PMU_ID 0x710110b9 -/* Uncomment this line to force another I/O base address for SMB */ -/* #define ALPM_SMBIO_BASE_ADDR 0x3a80 */ - -/* I/O registers offsets - the base address is programmed via the +/* + * I/O registers offsets - the base address is programmed via the * SMBBA PCI configuration register */ #define SMBSTS 0x0 /* SMBus host/slave status register */ @@ -70,6 +67,9 @@ static int alpm_debug = 0; #define SMBHBLOCK 0x6 /* block register for host controller */ #define SMBHCMD 0x7 /* command register for host controller */ +/* SMBHADDR mask. */ +#define LSB 0x1 /* XXX: Better name: Read/Write? */ + /* SMBSTS masks */ #define TERMINATE 0x80 #define BUS_COLLI 0x40 @@ -97,7 +97,7 @@ static int alpm_debug = 0; #define COM 0x4 #define COM_ENABLE_IO 0x1 -#define SMBBA 0x14 +#define SMBBA PCIR_BAR(1) #define ATPC 0x5b #define ATPC_SMBCTRL 0x04 /* XX linux has this as 0x6 */ @@ -122,44 +122,27 @@ struct alpm_softc { bus_space_tag_t smbst; bus_space_handle_t smbsh; device_t smbus; + struct lock lock; }; +#define ALPM_LOCK(alpm) lockmgr(&(alpm)->lock, LK_EXCLUSIVE) +#define ALPM_UNLOCK(alpm) lockmgr(&(alpm)->lock, LK_RELEASE) +#define ALPM_LOCK_ASSERT(alpm) KKASSERT(lockstatus(&(alpm)->lock, curthread) != 0) + #define ALPM_SMBINB(alpm,register) \ (bus_space_read_1(alpm->smbst, alpm->smbsh, register)) #define ALPM_SMBOUTB(alpm,register,value) \ (bus_space_write_1(alpm->smbst, alpm->smbsh, register, value)) +static int alpm_detach(device_t dev); + static int alpm_probe(device_t dev) { -#ifdef ALPM_SMBIO_BASE_ADDR - u_int32_t l; -#endif - if(pci_get_devid(dev) == ACER_M1543_PMU_ID) { + if (pci_get_devid(dev) == ACER_M1543_PMU_ID) { device_set_desc(dev, "AcerLabs M15x3 Power Management Unit"); -#ifdef ALPM_SMBIO_BASE_ADDR - if (bootverbose || alpm_debug) - device_printf(dev, "forcing base I/O at 0x%x\n", - ALPM_SMBIO_BASE_ADDR); - - /* disable I/O */ - l = pci_read_config(dev, COM, 2); - pci_write_config(dev, COM, l & ~COM_ENABLE_IO, 2); - - /* set the I/O base address */ - pci_write_config(dev, SMBBA, ALPM_SMBIO_BASE_ADDR | 0x1, 4); - - /* enable I/O */ - pci_write_config(dev, COM, l | COM_ENABLE_IO, 2); - - if (bus_set_resource(dev, SYS_RES_IOPORT, SMBBA, - ALPM_SMBIO_BASE_ADDR, 256)) { - device_printf(dev, "could not set bus resource\n"); - return (ENXIO); - } -#endif return (BUS_PROBE_DEFAULT); } @@ -184,7 +167,7 @@ alpm_attach(device_t dev) l = pci_read_config(dev, SMBHCBC, 1); l &= 0x1f; l |= SMBCLOCK_74K; - pci_write_config(dev, SMBHCBC, l, 1) + pci_write_config(dev, SMBHCBC, l, 1); */ if (bootverbose || alpm_debug) { @@ -230,9 +213,14 @@ alpm_attach(device_t dev) } alpm->smbst = rman_get_bustag(alpm->res); alpm->smbsh = rman_get_bushandle(alpm->res); + lockinit(&alpm->lock, "alpm", 0, LK_CANRECURSE); /* attach the smbus */ alpm->smbus = device_add_child(dev, "smbus", -1); + if (alpm->smbus == NULL) { + alpm_detach(dev); + return (EINVAL); + } bus_generic_attach(dev); return (0); @@ -247,6 +235,7 @@ alpm_detach(device_t dev) device_delete_child(dev, alpm->smbus); alpm->smbus = NULL; } + lockuninit(&alpm->lock); if (alpm->res) bus_release_resource(dev, SYS_RES_IOPORT, SMBBA, alpm->res); @@ -255,7 +244,7 @@ alpm_detach(device_t dev) } static int -alpm_callback(device_t dev, int index, caddr_t *data) +alpm_callback(device_t dev, int index, void *data) { int error = 0; @@ -313,7 +302,7 @@ alpm_wait(struct alpm_softc *sc) int error; /* wait for command to complete and SMBus controller is idle */ - while(count--) { + while (count--) { DELAY(10); sts = ALPM_SMBINB(sc, SMBSTS); if (sts & SMI_I_STS) @@ -348,9 +337,12 @@ alpm_quick(device_t dev, u_char slave, int how) struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev); int error; + ALPM_LOCK(sc); alpm_clear(sc); - if (!alpm_idle(sc)) + if (!alpm_idle(sc)) { + ALPM_UNLOCK(sc); return (EBUSY); + } switch (how) { case SMB_QWRITE: @@ -370,6 +362,7 @@ alpm_quick(device_t dev, u_char slave, int how) error = alpm_wait(sc); ALPM_DEBUG(kprintf(", error=0x%x\n", error)); + ALPM_UNLOCK(sc); return (error); } @@ -380,9 +373,12 @@ alpm_sendb(device_t dev, u_char slave, char byte) struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev); int error; + ALPM_LOCK(sc); alpm_clear(sc); - if (!alpm_idle(sc)) + if (!alpm_idle(sc)) { + ALPM_UNLOCK(sc); return (SMB_EBUSY); + } ALPM_SMBOUTB(sc, SMBHADDR, slave & ~LSB); ALPM_SMBOUTB(sc, SMBCMD, SMBSRBYTE); @@ -392,6 +388,7 @@ alpm_sendb(device_t dev, u_char slave, char byte) error = alpm_wait(sc); ALPM_DEBUG(kprintf("alpm: SENDB to 0x%x, byte=0x%x, error=0x%x\n", slave, byte, error)); + ALPM_UNLOCK(sc); return (error); } @@ -402,9 +399,12 @@ alpm_recvb(device_t dev, u_char slave, char *byte) struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev); int error; + ALPM_LOCK(sc); alpm_clear(sc); - if (!alpm_idle(sc)) + if (!alpm_idle(sc)) { + ALPM_UNLOCK(sc); return (SMB_EBUSY); + } ALPM_SMBOUTB(sc, SMBHADDR, slave | LSB); ALPM_SMBOUTB(sc, SMBCMD, SMBSRBYTE); @@ -414,6 +414,7 @@ alpm_recvb(device_t dev, u_char slave, char *byte) *byte = ALPM_SMBINB(sc, SMBHDATA); ALPM_DEBUG(kprintf("alpm: RECVB from 0x%x, byte=0x%x, error=0x%x\n", slave, *byte, error)); + ALPM_UNLOCK(sc); return (error); } @@ -424,9 +425,12 @@ alpm_writeb(device_t dev, u_char slave, char cmd, char byte) struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev); int error; + ALPM_LOCK(sc); alpm_clear(sc); - if (!alpm_idle(sc)) + if (!alpm_idle(sc)) { + ALPM_UNLOCK(sc); return (SMB_EBUSY); + } ALPM_SMBOUTB(sc, SMBHADDR, slave & ~LSB); ALPM_SMBOUTB(sc, SMBCMD, SMBWRBYTE); @@ -437,6 +441,7 @@ alpm_writeb(device_t dev, u_char slave, char cmd, char byte) error = alpm_wait(sc); ALPM_DEBUG(kprintf("alpm: WRITEB to 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, byte, error)); + ALPM_UNLOCK(sc); return (error); } @@ -447,9 +452,12 @@ alpm_readb(device_t dev, u_char slave, char cmd, char *byte) struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev); int error; + ALPM_LOCK(sc); alpm_clear(sc); - if (!alpm_idle(sc)) + if (!alpm_idle(sc)) { + ALPM_UNLOCK(sc); return (SMB_EBUSY); + } ALPM_SMBOUTB(sc, SMBHADDR, slave | LSB); ALPM_SMBOUTB(sc, SMBCMD, SMBWRBYTE); @@ -460,6 +468,7 @@ alpm_readb(device_t dev, u_char slave, char cmd, char *byte) *byte = ALPM_SMBINB(sc, SMBHDATA); ALPM_DEBUG(kprintf("alpm: READB from 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, *byte, error)); + ALPM_UNLOCK(sc); return (error); } @@ -470,9 +479,12 @@ alpm_writew(device_t dev, u_char slave, char cmd, short word) struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev); int error; + ALPM_LOCK(sc); alpm_clear(sc); - if (!alpm_idle(sc)) + if (!alpm_idle(sc)) { + ALPM_UNLOCK(sc); return (SMB_EBUSY); + } ALPM_SMBOUTB(sc, SMBHADDR, slave & ~LSB); ALPM_SMBOUTB(sc, SMBCMD, SMBWRWORD); @@ -484,6 +496,7 @@ alpm_writew(device_t dev, u_char slave, char cmd, short word) error = alpm_wait(sc); ALPM_DEBUG(kprintf("alpm: WRITEW to 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, word, error)); + ALPM_UNLOCK(sc); return (error); } @@ -495,9 +508,12 @@ alpm_readw(device_t dev, u_char slave, char cmd, short *word) int error; u_char high, low; + ALPM_LOCK(sc); alpm_clear(sc); - if (!alpm_idle(sc)) + if (!alpm_idle(sc)) { + ALPM_UNLOCK(sc); return (SMB_EBUSY); + } ALPM_SMBOUTB(sc, SMBHADDR, slave | LSB); ALPM_SMBOUTB(sc, SMBCMD, SMBWRWORD); @@ -512,6 +528,7 @@ alpm_readw(device_t dev, u_char slave, char cmd, short *word) } ALPM_DEBUG(kprintf("alpm: READW from 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, *word, error)); + ALPM_UNLOCK(sc); return (error); } @@ -520,82 +537,86 @@ static int alpm_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf) { struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev); - u_char remain, len, i; - int error = SMB_ENOERR; + u_char i; + int error; + + if (count < 1 || count > 32) + return (SMB_EINVAL); + ALPM_LOCK(sc); alpm_clear(sc); - if(!alpm_idle(sc)) + if(!alpm_idle(sc)) { + ALPM_UNLOCK(sc); return (SMB_EBUSY); + } - remain = count; - while (remain) { - len = min(remain, 32); - - ALPM_SMBOUTB(sc, SMBHADDR, slave & ~LSB); - - /* set the cmd and reset the - * 32-byte long internal buffer */ - ALPM_SMBOUTB(sc, SMBCMD, SMBWRBLOCK | SMB_BLK_CLR); - - ALPM_SMBOUTB(sc, SMBHDATA, len); + ALPM_SMBOUTB(sc, SMBHADDR, slave & ~LSB); - /* fill the 32-byte internal buffer */ - for (i=0; i 32) + return (SMB_EINVAL); + + ALPM_LOCK(sc); alpm_clear(sc); - if (!alpm_idle(sc)) + if (!alpm_idle(sc)) { + ALPM_UNLOCK(sc); return (SMB_EBUSY); + } - remain = count; - while (remain) { - ALPM_SMBOUTB(sc, SMBHADDR, slave | LSB); - - /* set the cmd and reset the - * 32-byte long internal buffer */ - ALPM_SMBOUTB(sc, SMBCMD, SMBWRBLOCK | SMB_BLK_CLR); + ALPM_SMBOUTB(sc, SMBHADDR, slave | LSB); - ALPM_SMBOUTB(sc, SMBHCMD, cmd); - ALPM_SMBOUTB(sc, SMBSTART, 0xff); + /* set the cmd and reset the + * 32-byte long internal buffer */ + ALPM_SMBOUTB(sc, SMBCMD, SMBWRBLOCK | SMB_BLK_CLR); - if ((error = alpm_wait(sc)) != SMB_ENOERR) - goto error; + ALPM_SMBOUTB(sc, SMBHCMD, cmd); + ALPM_SMBOUTB(sc, SMBSTART, 0xff); - len = ALPM_SMBINB(sc, SMBHDATA); + if ((error = alpm_wait(sc)) != SMB_ENOERR) + goto error; - /* read the 32-byte internal buffer */ - for (i=0; i