Replace the xxx_acquire()/xxx_release() rwlocks with mutexes. There are
only RW_WRITERs for these, and no RW_READERs, so no need to incur the extra overhead of allowing for both. As discussed on tech-kern. For piixpm and ichsmb, the acquire/release protocol needs to be used, even if the request is I2C_F_POLL'd (or if the device supports only polled mode). Otherwise multiple requests can be running at the same time, and they stomp on each other and create anomolous results. Part 2 addresses my PR kern/45889 3 ACKs from releng
This commit is contained in:
parent
87c636f464
commit
f76013d4aa
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: amdpm_smbus.c,v 1.17 2011/11/19 02:39:14 christos Exp $ */
|
||||
/* $NetBSD: amdpm_smbus.c,v 1.18 2012/02/14 15:08:07 pgoyette Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 Anil Gopinath (anil_public@yahoo.com)
|
||||
@ -32,14 +32,14 @@
|
||||
* AMD-8111 HyperTransport I/O Hub
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: amdpm_smbus.c,v 1.17 2011/11/19 02:39:14 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: amdpm_smbus.c,v 1.18 2012/02/14 15:08:07 pgoyette Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/rnd.h>
|
||||
#include <sys/rwlock.h>
|
||||
#include <sys/mutex.h>
|
||||
|
||||
#include <dev/pci/pcireg.h>
|
||||
#include <dev/pci/pcivar.h>
|
||||
@ -83,7 +83,7 @@ amdpm_smbus_attach(struct amdpm_softc *sc)
|
||||
sc->sc_i2c.ic_write_byte = NULL;
|
||||
sc->sc_i2c.ic_exec = amdpm_smbus_exec;
|
||||
|
||||
rw_init(&sc->sc_rwlock);
|
||||
mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_NONE);
|
||||
|
||||
iba.iba_tag = &sc->sc_i2c;
|
||||
(void)config_found_ia(&sc->sc_dev, "i2cbus", &iba, iicbus_print);
|
||||
@ -94,7 +94,7 @@ amdpm_smbus_acquire_bus(void *cookie, int flags)
|
||||
{
|
||||
struct amdpm_softc *sc = cookie;
|
||||
|
||||
rw_enter(&sc->sc_rwlock, RW_WRITER);
|
||||
mutex_enter(&sc->sc_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ amdpm_smbus_release_bus(void *cookie, int flags)
|
||||
{
|
||||
struct amdpm_softc *sc = cookie;
|
||||
|
||||
rw_exit(&sc->sc_rwlock);
|
||||
mutex_exit(&sc->sc_mutex);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: amdpmvar.h,v 1.7 2011/11/19 22:51:23 tls Exp $ */
|
||||
/* $NetBSD: amdpmvar.h,v 1.8 2012/02/14 15:08:07 pgoyette Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
@ -32,7 +32,7 @@
|
||||
#ifndef _DEV_PCI_AMDPMVAR_H_
|
||||
#define _DEV_PCI_AMDPMVAR_H_
|
||||
|
||||
#include <sys/rwlock.h>
|
||||
#include <sys/mutex.h>
|
||||
|
||||
struct amdpm_softc {
|
||||
struct device sc_dev;
|
||||
@ -47,7 +47,7 @@ struct amdpm_softc {
|
||||
|
||||
i2c_addr_t sc_smbus_slaveaddr; /* address of smbus slave */
|
||||
struct i2c_controller sc_i2c; /* i2c controller info */
|
||||
krwlock_t sc_rwlock;
|
||||
kmutex_t sc_mutex;
|
||||
|
||||
void *sc_ih;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ichsmb.c,v 1.26 2012/01/30 19:41:19 drochner Exp $ */
|
||||
/* $NetBSD: ichsmb.c,v 1.27 2012/02/14 15:08:07 pgoyette Exp $ */
|
||||
/* $OpenBSD: ichiic.c,v 1.18 2007/05/03 09:36:26 dlg Exp $ */
|
||||
|
||||
/*
|
||||
@ -22,13 +22,13 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ichsmb.c,v 1.26 2012/01/30 19:41:19 drochner Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ichsmb.c,v 1.27 2012/02/14 15:08:07 pgoyette Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/rwlock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <sys/bus.h>
|
||||
@ -59,7 +59,7 @@ struct ichsmb_softc {
|
||||
int sc_poll;
|
||||
|
||||
struct i2c_controller sc_i2c_tag;
|
||||
krwlock_t sc_i2c_rwlock;
|
||||
kmutex_t sc_i2c_mutex;
|
||||
struct {
|
||||
i2c_op_t op;
|
||||
void * buf;
|
||||
@ -166,7 +166,7 @@ ichsmb_attach(device_t parent, device_t self, void *aux)
|
||||
}
|
||||
|
||||
/* Attach I2C bus */
|
||||
rw_init(&sc->sc_i2c_rwlock);
|
||||
mutex_init(&sc->sc_i2c_mutex, MUTEX_DEFAULT, IPL_NONE);
|
||||
sc->sc_i2c_tag.ic_cookie = sc;
|
||||
sc->sc_i2c_tag.ic_acquire_bus = ichsmb_i2c_acquire_bus;
|
||||
sc->sc_i2c_tag.ic_release_bus = ichsmb_i2c_release_bus;
|
||||
@ -186,10 +186,10 @@ ichsmb_i2c_acquire_bus(void *cookie, int flags)
|
||||
{
|
||||
struct ichsmb_softc *sc = cookie;
|
||||
|
||||
if (cold || sc->sc_poll || (flags & I2C_F_POLL))
|
||||
if (cold)
|
||||
return 0;
|
||||
|
||||
rw_enter(&sc->sc_i2c_rwlock, RW_WRITER);
|
||||
mutex_enter(&sc->sc_i2c_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -198,10 +198,10 @@ ichsmb_i2c_release_bus(void *cookie, int flags)
|
||||
{
|
||||
struct ichsmb_softc *sc = cookie;
|
||||
|
||||
if (cold || sc->sc_poll || (flags & I2C_F_POLL))
|
||||
if (cold)
|
||||
return;
|
||||
|
||||
rw_exit(&sc->sc_i2c_rwlock);
|
||||
mutex_exit(&sc->sc_i2c_mutex);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: nfsmb.c,v 1.22 2012/01/30 19:41:22 drochner Exp $ */
|
||||
/* $NetBSD: nfsmb.c,v 1.23 2012/02/14 15:08:07 pgoyette Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2007 KIYOHARA Takashi
|
||||
* All rights reserved.
|
||||
@ -26,13 +26,13 @@
|
||||
*
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfsmb.c,v 1.22 2012/01/30 19:41:22 drochner Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfsmb.c,v 1.23 2012/02/14 15:08:07 pgoyette Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/rwlock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <sys/bus.h>
|
||||
@ -73,7 +73,7 @@ struct nfsmb_softc {
|
||||
bus_space_handle_t sc_ioh;
|
||||
|
||||
struct i2c_controller sc_i2c; /* i2c controller info */
|
||||
krwlock_t sc_rwlock;
|
||||
kmutex_t sc_mutex;
|
||||
};
|
||||
|
||||
|
||||
@ -237,7 +237,7 @@ nfsmb_attach(device_t parent, device_t self, void *aux)
|
||||
sc->sc_i2c.ic_write_byte = NULL;
|
||||
sc->sc_i2c.ic_exec = nfsmb_exec;
|
||||
|
||||
rw_init(&sc->sc_rwlock);
|
||||
mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_NONE);
|
||||
|
||||
if (bus_space_map(sc->sc_iot, nfsmbcap->nfsmb_addr, NFORCE_SMBSIZE, 0,
|
||||
&sc->sc_ioh) != 0) {
|
||||
@ -261,7 +261,7 @@ nfsmb_acquire_bus(void *cookie, int flags)
|
||||
{
|
||||
struct nfsmb_softc *sc = cookie;
|
||||
|
||||
rw_enter(&sc->sc_rwlock, RW_WRITER);
|
||||
mutex_enter(&sc->sc_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -270,7 +270,7 @@ nfsmb_release_bus(void *cookie, int flags)
|
||||
{
|
||||
struct nfsmb_softc *sc = cookie;
|
||||
|
||||
rw_exit(&sc->sc_rwlock);
|
||||
mutex_exit(&sc->sc_mutex);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: piixpm.c,v 1.39 2012/01/30 19:41:22 drochner Exp $ */
|
||||
/* $NetBSD: piixpm.c,v 1.40 2012/02/14 15:08:07 pgoyette Exp $ */
|
||||
/* $OpenBSD: piixpm.c,v 1.20 2006/02/27 08:25:02 grange Exp $ */
|
||||
|
||||
/*
|
||||
@ -22,13 +22,13 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: piixpm.c,v 1.39 2012/01/30 19:41:22 drochner Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: piixpm.c,v 1.40 2012/02/14 15:08:07 pgoyette Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/rwlock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <sys/bus.h>
|
||||
@ -82,7 +82,7 @@ struct piixpm_softc {
|
||||
pcireg_t sc_id;
|
||||
|
||||
struct i2c_controller sc_i2c_tag;
|
||||
krwlock_t sc_i2c_rwlock;
|
||||
kmutex_t sc_i2c_mutex;
|
||||
struct {
|
||||
i2c_op_t op;
|
||||
void * buf;
|
||||
@ -251,7 +251,7 @@ nopowermanagement:
|
||||
|
||||
attach_i2c:
|
||||
/* Attach I2C bus */
|
||||
rw_init(&sc->sc_i2c_rwlock);
|
||||
mutex_init(&sc->sc_i2c_mutex, MUTEX_DEFAULT, IPL_NONE);
|
||||
sc->sc_i2c_tag.ic_cookie = sc;
|
||||
sc->sc_i2c_tag.ic_acquire_bus = piixpm_i2c_acquire_bus;
|
||||
sc->sc_i2c_tag.ic_release_bus = piixpm_i2c_release_bus;
|
||||
@ -331,6 +331,7 @@ piixpm_sb800_init(struct piixpm_softc *sc, struct pci_attach_args *pa)
|
||||
aprint_error_dev(sc->sc_dev, "can't map smbus I/O space\n");
|
||||
return EBUSY;
|
||||
}
|
||||
aprint_normal_dev(sc->sc_dev, "polling (SB800)\n");
|
||||
sc->sc_poll = 1;
|
||||
|
||||
return 0;
|
||||
@ -362,10 +363,9 @@ piixpm_i2c_acquire_bus(void *cookie, int flags)
|
||||
{
|
||||
struct piixpm_softc *sc = cookie;
|
||||
|
||||
if (cold || sc->sc_poll || (flags & I2C_F_POLL))
|
||||
return (0);
|
||||
if (!cold)
|
||||
mutex_enter(&sc->sc_i2c_mutex);
|
||||
|
||||
rw_enter(&sc->sc_i2c_rwlock, RW_WRITER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -374,10 +374,8 @@ piixpm_i2c_release_bus(void *cookie, int flags)
|
||||
{
|
||||
struct piixpm_softc *sc = cookie;
|
||||
|
||||
if (cold || sc->sc_poll || (flags & I2C_F_POLL))
|
||||
return;
|
||||
|
||||
rw_exit(&sc->sc_i2c_rwlock);
|
||||
if (!cold)
|
||||
mutex_exit(&sc->sc_i2c_mutex);
|
||||
}
|
||||
|
||||
static int
|
||||
|
Loading…
Reference in New Issue
Block a user