2005-12-21 15:49:51 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2007-01-11 19:56:24 +00:00
|
|
|
#include <sys/bus.h>
|
2005-12-21 15:49:51 +00:00
|
|
|
#include <sys/kernel.h>
|
2007-01-11 19:56:24 +00:00
|
|
|
#include <sys/lock.h>
|
2005-12-21 15:49:51 +00:00
|
|
|
#include <sys/module.h>
|
2007-01-11 19:56:24 +00:00
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/systm.h>
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
|
|
|
|
#include <dev/smbus/smbconf.h>
|
|
|
|
#include "smbus_if.h"
|
|
|
|
|
|
|
|
#define NFSMB_DEBUG(x) if (nfsmb_debug) (x)
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static int nfsmb_debug = 1;
|
|
|
|
#else
|
|
|
|
static int nfsmb_debug = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* NVIDIA nForce2/3/4 MCP */
|
|
|
|
#define NFSMB_VENDORID_NVIDIA 0x10de
|
|
|
|
#define NFSMB_DEVICEID_NF2_SMB 0x0064
|
|
|
|
#define NFSMB_DEVICEID_NF2_ULTRA_SMB 0x0084
|
|
|
|
#define NFSMB_DEVICEID_NF3_PRO150_SMB 0x00d4
|
|
|
|
#define NFSMB_DEVICEID_NF3_250GB_SMB 0x00e4
|
|
|
|
#define NFSMB_DEVICEID_NF4_SMB 0x0052
|
2006-08-18 19:56:40 +00:00
|
|
|
#define NFSMB_DEVICEID_NF4_04_SMB 0x0034
|
|
|
|
#define NFSMB_DEVICEID_NF4_51_SMB 0x0264
|
|
|
|
#define NFSMB_DEVICEID_NF4_55_SMB 0x0368
|
2007-11-10 17:12:08 +00:00
|
|
|
#define NFSMB_DEVICEID_NF4_61_SMB 0x03eb
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
/* PCI Configuration space registers */
|
|
|
|
#define NF2PCI_SMBASE_1 PCIR_BAR(4)
|
|
|
|
#define NF2PCI_SMBASE_2 PCIR_BAR(5)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPI 3.0, Chapter 12, SMBus Host Controller Interface.
|
|
|
|
*/
|
|
|
|
#define SMB_PRTCL 0x00 /* protocol */
|
|
|
|
#define SMB_STS 0x01 /* status */
|
|
|
|
#define SMB_ADDR 0x02 /* address */
|
|
|
|
#define SMB_CMD 0x03 /* command */
|
|
|
|
#define SMB_DATA 0x04 /* 32 data registers */
|
|
|
|
#define SMB_BCNT 0x24 /* number of data bytes */
|
|
|
|
#define SMB_ALRM_A 0x25 /* alarm address */
|
|
|
|
#define SMB_ALRM_D 0x26 /* 2 bytes alarm data */
|
|
|
|
|
|
|
|
#define SMB_STS_DONE 0x80
|
|
|
|
#define SMB_STS_ALRM 0x40
|
|
|
|
#define SMB_STS_RES 0x20
|
|
|
|
#define SMB_STS_STATUS 0x1f
|
|
|
|
#define SMB_STS_OK 0x00 /* OK */
|
|
|
|
#define SMB_STS_UF 0x07 /* Unknown Failure */
|
|
|
|
#define SMB_STS_DANA 0x10 /* Device Address Not Acknowledged */
|
|
|
|
#define SMB_STS_DED 0x11 /* Device Error Detected */
|
|
|
|
#define SMB_STS_DCAD 0x12 /* Device Command Access Denied */
|
|
|
|
#define SMB_STS_UE 0x13 /* Unknown Error */
|
|
|
|
#define SMB_STS_DAD 0x17 /* Device Access Denied */
|
|
|
|
#define SMB_STS_T 0x18 /* Timeout */
|
|
|
|
#define SMB_STS_HUP 0x19 /* Host Unsupported Protocol */
|
|
|
|
#define SMB_STS_B 0x1A /* Busy */
|
|
|
|
#define SMB_STS_PEC 0x1F /* PEC (CRC-8) Error */
|
|
|
|
|
|
|
|
#define SMB_PRTCL_WRITE 0x00
|
|
|
|
#define SMB_PRTCL_READ 0x01
|
|
|
|
#define SMB_PRTCL_QUICK 0x02
|
|
|
|
#define SMB_PRTCL_BYTE 0x04
|
|
|
|
#define SMB_PRTCL_BYTE_DATA 0x06
|
|
|
|
#define SMB_PRTCL_WORD_DATA 0x08
|
|
|
|
#define SMB_PRTCL_BLOCK_DATA 0x0a
|
|
|
|
#define SMB_PRTCL_PROC_CALL 0x0c
|
|
|
|
#define SMB_PRTCL_BLOCK_PROC_CALL 0x0d
|
|
|
|
#define SMB_PRTCL_PEC 0x80
|
|
|
|
|
|
|
|
struct nfsmb_softc {
|
|
|
|
int rid;
|
|
|
|
struct resource *res;
|
|
|
|
bus_space_tag_t smbst;
|
|
|
|
bus_space_handle_t smbsh;
|
|
|
|
device_t smbus;
|
|
|
|
device_t subdev;
|
2007-01-11 19:56:24 +00:00
|
|
|
struct mtx lock;
|
2005-12-21 15:49:51 +00:00
|
|
|
};
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
#define NFSMB_LOCK(nfsmb) mtx_lock(&(nfsmb)->lock)
|
|
|
|
#define NFSMB_UNLOCK(nfsmb) mtx_unlock(&(nfsmb)->lock)
|
|
|
|
#define NFSMB_LOCK_ASSERT(nfsmb) mtx_assert(&(nfsmb)->lock, MA_OWNED)
|
|
|
|
|
|
|
|
#define NFSMB_SMBINB(nfsmb, register) \
|
2005-12-21 15:49:51 +00:00
|
|
|
(bus_space_read_1(nfsmb->smbst, nfsmb->smbsh, register))
|
|
|
|
#define NFSMB_SMBOUTB(nfsmb, register, value) \
|
|
|
|
(bus_space_write_1(nfsmb->smbst, nfsmb->smbsh, register, value))
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
static int nfsmb_detach(device_t dev);
|
|
|
|
static int nfsmbsub_detach(device_t dev);
|
|
|
|
|
2005-12-21 15:49:51 +00:00
|
|
|
static int
|
|
|
|
nfsmbsub_probe(device_t dev)
|
|
|
|
{
|
|
|
|
|
|
|
|
device_set_desc(dev, "nForce2/3/4 MCP SMBus Controller");
|
|
|
|
return (BUS_PROBE_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmb_probe(device_t dev)
|
|
|
|
{
|
|
|
|
u_int16_t vid;
|
|
|
|
u_int16_t did;
|
|
|
|
|
|
|
|
vid = pci_get_vendor(dev);
|
|
|
|
did = pci_get_device(dev);
|
|
|
|
|
|
|
|
if (vid == NFSMB_VENDORID_NVIDIA) {
|
|
|
|
switch(did) {
|
|
|
|
case NFSMB_DEVICEID_NF2_SMB:
|
|
|
|
case NFSMB_DEVICEID_NF2_ULTRA_SMB:
|
|
|
|
case NFSMB_DEVICEID_NF3_PRO150_SMB:
|
|
|
|
case NFSMB_DEVICEID_NF3_250GB_SMB:
|
|
|
|
case NFSMB_DEVICEID_NF4_SMB:
|
2006-08-18 19:56:40 +00:00
|
|
|
case NFSMB_DEVICEID_NF4_04_SMB:
|
|
|
|
case NFSMB_DEVICEID_NF4_51_SMB:
|
|
|
|
case NFSMB_DEVICEID_NF4_55_SMB:
|
2007-11-10 17:12:08 +00:00
|
|
|
case NFSMB_DEVICEID_NF4_61_SMB:
|
2005-12-21 15:49:51 +00:00
|
|
|
device_set_desc(dev, "nForce2/3/4 MCP SMBus Controller");
|
|
|
|
return (BUS_PROBE_DEFAULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmbsub_attach(device_t dev)
|
|
|
|
{
|
|
|
|
device_t parent;
|
|
|
|
struct nfsmb_softc *nfsmbsub_sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
parent = device_get_parent(dev);
|
|
|
|
|
|
|
|
nfsmbsub_sc->rid = NF2PCI_SMBASE_2;
|
|
|
|
|
|
|
|
nfsmbsub_sc->res = bus_alloc_resource_any(parent, SYS_RES_IOPORT,
|
|
|
|
&nfsmbsub_sc->rid, RF_ACTIVE);
|
|
|
|
if (nfsmbsub_sc->res == NULL) {
|
2006-10-17 10:26:11 +00:00
|
|
|
/* Older incarnations of the device used non-standard BARs. */
|
|
|
|
nfsmbsub_sc->rid = 0x54;
|
|
|
|
nfsmbsub_sc->res = bus_alloc_resource_any(parent,
|
|
|
|
SYS_RES_IOPORT, &nfsmbsub_sc->rid, RF_ACTIVE);
|
|
|
|
if (nfsmbsub_sc->res == NULL) {
|
|
|
|
device_printf(dev, "could not map i/o space\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2005-12-21 15:49:51 +00:00
|
|
|
}
|
|
|
|
nfsmbsub_sc->smbst = rman_get_bustag(nfsmbsub_sc->res);
|
|
|
|
nfsmbsub_sc->smbsh = rman_get_bushandle(nfsmbsub_sc->res);
|
2007-01-11 19:56:24 +00:00
|
|
|
mtx_init(&nfsmbsub_sc->lock, device_get_nameunit(dev), "nfsmb",
|
|
|
|
MTX_DEF);
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
nfsmbsub_sc->smbus = device_add_child(dev, "smbus", -1);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (nfsmbsub_sc->smbus == NULL) {
|
|
|
|
nfsmbsub_detach(dev);
|
2005-12-21 15:49:51 +00:00
|
|
|
return (EINVAL);
|
2007-01-11 19:56:24 +00:00
|
|
|
}
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
bus_generic_attach(dev);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmb_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct nfsmb_softc *nfsmb_sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
/* Allocate I/O space */
|
|
|
|
nfsmb_sc->rid = NF2PCI_SMBASE_1;
|
|
|
|
|
|
|
|
nfsmb_sc->res = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
|
|
|
|
&nfsmb_sc->rid, RF_ACTIVE);
|
|
|
|
|
|
|
|
if (nfsmb_sc->res == NULL) {
|
2006-10-17 10:26:11 +00:00
|
|
|
/* Older incarnations of the device used non-standard BARs. */
|
|
|
|
nfsmb_sc->rid = 0x50;
|
|
|
|
nfsmb_sc->res = bus_alloc_resource_any(dev,
|
|
|
|
SYS_RES_IOPORT, &nfsmb_sc->rid, RF_ACTIVE);
|
|
|
|
if (nfsmb_sc->res == NULL) {
|
|
|
|
device_printf(dev, "could not map i/o space\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2005-12-21 15:49:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nfsmb_sc->smbst = rman_get_bustag(nfsmb_sc->res);
|
|
|
|
nfsmb_sc->smbsh = rman_get_bushandle(nfsmb_sc->res);
|
2007-01-11 19:56:24 +00:00
|
|
|
mtx_init(&nfsmb_sc->lock, device_get_nameunit(dev), "nfsmb", MTX_DEF);
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
/* Allocate a new smbus device */
|
|
|
|
nfsmb_sc->smbus = device_add_child(dev, "smbus", -1);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (!nfsmb_sc->smbus) {
|
|
|
|
nfsmb_detach(dev);
|
2005-12-21 15:49:51 +00:00
|
|
|
return (EINVAL);
|
2007-01-11 19:56:24 +00:00
|
|
|
}
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
nfsmb_sc->subdev = NULL;
|
|
|
|
switch (pci_get_device(dev)) {
|
|
|
|
case NFSMB_DEVICEID_NF2_SMB:
|
|
|
|
case NFSMB_DEVICEID_NF2_ULTRA_SMB:
|
|
|
|
case NFSMB_DEVICEID_NF3_PRO150_SMB:
|
|
|
|
case NFSMB_DEVICEID_NF3_250GB_SMB:
|
|
|
|
case NFSMB_DEVICEID_NF4_SMB:
|
2006-08-18 19:56:40 +00:00
|
|
|
case NFSMB_DEVICEID_NF4_04_SMB:
|
|
|
|
case NFSMB_DEVICEID_NF4_51_SMB:
|
|
|
|
case NFSMB_DEVICEID_NF4_55_SMB:
|
2007-11-10 17:12:08 +00:00
|
|
|
case NFSMB_DEVICEID_NF4_61_SMB:
|
2005-12-21 15:49:51 +00:00
|
|
|
/* Trying to add secondary device as slave */
|
|
|
|
nfsmb_sc->subdev = device_add_child(dev, "nfsmb", -1);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (!nfsmb_sc->subdev) {
|
|
|
|
nfsmb_detach(dev);
|
2005-12-21 15:49:51 +00:00
|
|
|
return (EINVAL);
|
2007-01-11 19:56:24 +00:00
|
|
|
}
|
2005-12-21 15:49:51 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_generic_attach(dev);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmbsub_detach(device_t dev)
|
|
|
|
{
|
|
|
|
device_t parent;
|
|
|
|
struct nfsmb_softc *nfsmbsub_sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
parent = device_get_parent(dev);
|
|
|
|
|
|
|
|
if (nfsmbsub_sc->smbus) {
|
|
|
|
device_delete_child(dev, nfsmbsub_sc->smbus);
|
|
|
|
nfsmbsub_sc->smbus = NULL;
|
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
mtx_destroy(&nfsmbsub_sc->lock);
|
2005-12-21 15:49:51 +00:00
|
|
|
if (nfsmbsub_sc->res) {
|
|
|
|
bus_release_resource(parent, SYS_RES_IOPORT, nfsmbsub_sc->rid,
|
|
|
|
nfsmbsub_sc->res);
|
|
|
|
nfsmbsub_sc->res = NULL;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmb_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct nfsmb_softc *nfsmb_sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
if (nfsmb_sc->subdev) {
|
|
|
|
device_delete_child(dev, nfsmb_sc->subdev);
|
|
|
|
nfsmb_sc->subdev = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nfsmb_sc->smbus) {
|
|
|
|
device_delete_child(dev, nfsmb_sc->smbus);
|
|
|
|
nfsmb_sc->smbus = NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
mtx_destroy(&nfsmb_sc->lock);
|
2005-12-21 15:49:51 +00:00
|
|
|
if (nfsmb_sc->res) {
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, nfsmb_sc->rid,
|
|
|
|
nfsmb_sc->res);
|
|
|
|
nfsmb_sc->res = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
nfsmb_callback(device_t dev, int index, void *data)
|
2005-12-21 15:49:51 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
case SMB_REQUEST_BUS:
|
|
|
|
case SMB_RELEASE_BUS:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmb_wait(struct nfsmb_softc *sc)
|
|
|
|
{
|
|
|
|
u_char sts;
|
|
|
|
int error, count;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_LOCK_ASSERT(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
if (NFSMB_SMBINB(sc, SMB_PRTCL) != 0)
|
|
|
|
{
|
|
|
|
count = 10000;
|
|
|
|
do {
|
|
|
|
DELAY(500);
|
|
|
|
} while (NFSMB_SMBINB(sc, SMB_PRTCL) != 0 && count--);
|
|
|
|
if (count == 0)
|
|
|
|
return (SMB_ETIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
sts = NFSMB_SMBINB(sc, SMB_STS) & SMB_STS_STATUS;
|
|
|
|
NFSMB_DEBUG(printf("nfsmb: STS=0x%x\n", sts));
|
|
|
|
|
|
|
|
switch (sts) {
|
|
|
|
case SMB_STS_OK:
|
|
|
|
error = SMB_ENOERR;
|
|
|
|
break;
|
|
|
|
case SMB_STS_DANA:
|
|
|
|
error = SMB_ENOACK;
|
|
|
|
break;
|
|
|
|
case SMB_STS_B:
|
|
|
|
error = SMB_EBUSY;
|
|
|
|
break;
|
|
|
|
case SMB_STS_T:
|
|
|
|
error = SMB_ETIMEOUT;
|
|
|
|
break;
|
|
|
|
case SMB_STS_DCAD:
|
|
|
|
case SMB_STS_DAD:
|
|
|
|
case SMB_STS_HUP:
|
|
|
|
error = SMB_ENOTSUPP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = SMB_EBUSERR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmb_quick(device_t dev, u_char slave, int how)
|
|
|
|
{
|
|
|
|
struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
|
|
|
|
u_char protocol;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
protocol = SMB_PRTCL_QUICK;
|
|
|
|
|
|
|
|
switch (how) {
|
|
|
|
case SMB_QWRITE:
|
|
|
|
protocol |= SMB_PRTCL_WRITE;
|
|
|
|
NFSMB_DEBUG(printf("nfsmb: QWRITE to 0x%x", slave));
|
|
|
|
break;
|
|
|
|
case SMB_QREAD:
|
|
|
|
protocol |= SMB_PRTCL_READ;
|
|
|
|
NFSMB_DEBUG(printf("nfsmb: QREAD to 0x%x", slave));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("%s: unknown QUICK command (%x)!", __func__, how);
|
|
|
|
}
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_LOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_PRTCL, protocol);
|
|
|
|
|
|
|
|
error = nfsmb_wait(sc);
|
|
|
|
|
|
|
|
NFSMB_DEBUG(printf(", error=0x%x\n", error));
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_UNLOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmb_sendb(device_t dev, u_char slave, char byte)
|
|
|
|
{
|
|
|
|
struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_LOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
NFSMB_SMBOUTB(sc, SMB_CMD, byte);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BYTE);
|
|
|
|
|
|
|
|
error = nfsmb_wait(sc);
|
|
|
|
|
|
|
|
NFSMB_DEBUG(printf("nfsmb: SENDB to 0x%x, byte=0x%x, error=0x%x\n", slave, byte, error));
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_UNLOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmb_recvb(device_t dev, u_char slave, char *byte)
|
|
|
|
{
|
|
|
|
struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_LOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_BYTE);
|
|
|
|
|
|
|
|
if ((error = nfsmb_wait(sc)) == SMB_ENOERR)
|
|
|
|
*byte = NFSMB_SMBINB(sc, SMB_DATA);
|
|
|
|
|
|
|
|
NFSMB_DEBUG(printf("nfsmb: RECVB from 0x%x, byte=0x%x, error=0x%x\n", slave, *byte, error));
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_UNLOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmb_writeb(device_t dev, u_char slave, char cmd, char byte)
|
|
|
|
{
|
|
|
|
struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_LOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
NFSMB_SMBOUTB(sc, SMB_CMD, cmd);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_DATA, byte);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BYTE_DATA);
|
|
|
|
|
|
|
|
error = nfsmb_wait(sc);
|
|
|
|
|
|
|
|
NFSMB_DEBUG(printf("nfsmb: WRITEB to 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, byte, error));
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_UNLOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmb_readb(device_t dev, u_char slave, char cmd, char *byte)
|
|
|
|
{
|
|
|
|
struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_LOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
NFSMB_SMBOUTB(sc, SMB_CMD, cmd);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_BYTE_DATA);
|
|
|
|
|
|
|
|
if ((error = nfsmb_wait(sc)) == SMB_ENOERR)
|
|
|
|
*byte = NFSMB_SMBINB(sc, SMB_DATA);
|
|
|
|
|
|
|
|
NFSMB_DEBUG(printf("nfsmb: READB from 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, (unsigned char)*byte, error));
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_UNLOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmb_writew(device_t dev, u_char slave, char cmd, short word)
|
|
|
|
{
|
|
|
|
struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_LOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
NFSMB_SMBOUTB(sc, SMB_CMD, cmd);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_DATA, word);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_DATA + 1, word >> 8);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_WORD_DATA);
|
|
|
|
|
|
|
|
error = nfsmb_wait(sc);
|
|
|
|
|
|
|
|
NFSMB_DEBUG(printf("nfsmb: WRITEW to 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, word, error));
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_UNLOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmb_readw(device_t dev, u_char slave, char cmd, short *word)
|
|
|
|
{
|
|
|
|
struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_LOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
NFSMB_SMBOUTB(sc, SMB_CMD, cmd);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_WORD_DATA);
|
|
|
|
|
|
|
|
if ((error = nfsmb_wait(sc)) == SMB_ENOERR)
|
|
|
|
*word = NFSMB_SMBINB(sc, SMB_DATA) |
|
|
|
|
(NFSMB_SMBINB(sc, SMB_DATA + 1) << 8);
|
|
|
|
|
|
|
|
NFSMB_DEBUG(printf("nfsmb: READW from 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, (unsigned short)*word, error));
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_UNLOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf)
|
|
|
|
{
|
|
|
|
struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
u_char i;
|
2005-12-21 15:49:51 +00:00
|
|
|
int error;
|
|
|
|
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
if (count < 1 || count > 32)
|
|
|
|
return (SMB_EINVAL);
|
2007-01-11 19:56:24 +00:00
|
|
|
|
|
|
|
NFSMB_LOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
NFSMB_SMBOUTB(sc, SMB_CMD, cmd);
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
NFSMB_SMBOUTB(sc, SMB_BCNT, count);
|
|
|
|
for (i = 0; i < count; i++)
|
2005-12-21 15:49:51 +00:00
|
|
|
NFSMB_SMBOUTB(sc, SMB_DATA + i, buf[i]);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BLOCK_DATA);
|
|
|
|
|
|
|
|
error = nfsmb_wait(sc);
|
|
|
|
|
|
|
|
NFSMB_DEBUG(printf("nfsmb: WRITEBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, count, cmd, error));
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_UNLOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
nfsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf)
|
2005-12-21 15:49:51 +00:00
|
|
|
{
|
|
|
|
struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
u_char data, len, i;
|
2005-12-21 15:49:51 +00:00
|
|
|
int error;
|
|
|
|
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
if (*count < 1 || *count > 32)
|
|
|
|
return (SMB_EINVAL);
|
2007-01-11 19:56:24 +00:00
|
|
|
|
|
|
|
NFSMB_LOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
NFSMB_SMBOUTB(sc, SMB_CMD, cmd);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
|
|
|
|
NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_BLOCK_DATA);
|
|
|
|
|
|
|
|
if ((error = nfsmb_wait(sc)) == SMB_ENOERR) {
|
|
|
|
len = NFSMB_SMBINB(sc, SMB_BCNT);
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
data = NFSMB_SMBINB(sc, SMB_DATA + i);
|
|
|
|
if (i < *count)
|
|
|
|
buf[i] = data;
|
|
|
|
}
|
|
|
|
*count = len;
|
2005-12-21 15:49:51 +00:00
|
|
|
}
|
|
|
|
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
NFSMB_DEBUG(printf("nfsmb: READBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, *count, cmd, error));
|
2007-01-11 19:56:24 +00:00
|
|
|
NFSMB_UNLOCK(sc);
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static device_method_t nfsmb_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, nfsmb_probe),
|
|
|
|
DEVMETHOD(device_attach, nfsmb_attach),
|
|
|
|
DEVMETHOD(device_detach, nfsmb_detach),
|
|
|
|
|
|
|
|
/* SMBus interface */
|
|
|
|
DEVMETHOD(smbus_callback, nfsmb_callback),
|
|
|
|
DEVMETHOD(smbus_quick, nfsmb_quick),
|
|
|
|
DEVMETHOD(smbus_sendb, nfsmb_sendb),
|
|
|
|
DEVMETHOD(smbus_recvb, nfsmb_recvb),
|
|
|
|
DEVMETHOD(smbus_writeb, nfsmb_writeb),
|
|
|
|
DEVMETHOD(smbus_readb, nfsmb_readb),
|
|
|
|
DEVMETHOD(smbus_writew, nfsmb_writew),
|
|
|
|
DEVMETHOD(smbus_readw, nfsmb_readw),
|
|
|
|
DEVMETHOD(smbus_bwrite, nfsmb_bwrite),
|
|
|
|
DEVMETHOD(smbus_bread, nfsmb_bread),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static device_method_t nfsmbsub_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, nfsmbsub_probe),
|
|
|
|
DEVMETHOD(device_attach, nfsmbsub_attach),
|
|
|
|
DEVMETHOD(device_detach, nfsmbsub_detach),
|
|
|
|
|
|
|
|
/* SMBus interface */
|
|
|
|
DEVMETHOD(smbus_callback, nfsmb_callback),
|
|
|
|
DEVMETHOD(smbus_quick, nfsmb_quick),
|
|
|
|
DEVMETHOD(smbus_sendb, nfsmb_sendb),
|
|
|
|
DEVMETHOD(smbus_recvb, nfsmb_recvb),
|
|
|
|
DEVMETHOD(smbus_writeb, nfsmb_writeb),
|
|
|
|
DEVMETHOD(smbus_readb, nfsmb_readb),
|
|
|
|
DEVMETHOD(smbus_writew, nfsmb_writew),
|
|
|
|
DEVMETHOD(smbus_readw, nfsmb_readw),
|
|
|
|
DEVMETHOD(smbus_bwrite, nfsmb_bwrite),
|
|
|
|
DEVMETHOD(smbus_bread, nfsmb_bread),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t nfsmb_devclass;
|
|
|
|
|
|
|
|
static driver_t nfsmb_driver = {
|
|
|
|
"nfsmb",
|
|
|
|
nfsmb_methods,
|
|
|
|
sizeof(struct nfsmb_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t nfsmbsub_driver = {
|
|
|
|
"nfsmb",
|
|
|
|
nfsmbsub_methods,
|
|
|
|
sizeof(struct nfsmb_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
DRIVER_MODULE(nfsmb, pci, nfsmb_driver, nfsmb_devclass, 0, 0);
|
|
|
|
DRIVER_MODULE(nfsmb, nfsmb, nfsmbsub_driver, nfsmb_devclass, 0, 0);
|
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
2006-09-11 20:52:41 +00:00
|
|
|
DRIVER_MODULE(smbus, nfsmb, smbus_driver, smbus_devclass, 0, 0);
|
2005-12-21 15:49:51 +00:00
|
|
|
|
|
|
|
MODULE_DEPEND(nfsmb, pci, 1, 1, 1);
|
|
|
|
MODULE_DEPEND(nfsmb, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER);
|
|
|
|
MODULE_VERSION(nfsmb, 1);
|