1999-01-24 18:13:31 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998, 1999 Takanori Watanabe
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 06:34:30 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-01-24 18:13:31 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2007-01-11 19:56:24 +00:00
|
|
|
#include <sys/bus.h>
|
1999-01-24 18:13:31 +00:00
|
|
|
#include <sys/kernel.h>
|
2007-01-11 19:56:24 +00:00
|
|
|
#include <sys/lock.h>
|
1999-01-24 18:13:31 +00:00
|
|
|
#include <sys/module.h>
|
2007-01-11 19:56:24 +00:00
|
|
|
#include <sys/mutex.h>
|
1999-05-07 18:03:27 +00:00
|
|
|
#include <sys/rman.h>
|
2007-01-11 19:56:24 +00:00
|
|
|
#include <machine/bus.h>
|
1999-01-24 18:13:31 +00:00
|
|
|
#include <dev/smbus/smbconf.h>
|
|
|
|
|
|
|
|
#include "smbus_if.h"
|
|
|
|
|
2003-08-22 07:20:27 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
1999-01-24 18:13:31 +00:00
|
|
|
#include <pci/intpmreg.h>
|
|
|
|
|
|
|
|
#include "opt_intpm.h"
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
struct intsmb_softc {
|
|
|
|
device_t dev;
|
|
|
|
struct resource *io_res;
|
|
|
|
struct resource *irq_res;
|
|
|
|
void *irq_hand;
|
|
|
|
device_t smbus;
|
|
|
|
int isbusy;
|
|
|
|
struct mtx lock;
|
1999-01-24 18:13:31 +00:00
|
|
|
};
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
#define INTSMB_LOCK(sc) mtx_lock(&(sc)->lock)
|
|
|
|
#define INTSMB_UNLOCK(sc) mtx_unlock(&(sc)->lock)
|
|
|
|
#define INTSMB_LOCK_ASSERT(sc) mtx_assert(&(sc)->lock, MA_OWNED)
|
|
|
|
|
1999-01-24 18:13:31 +00:00
|
|
|
static int intsmb_probe(device_t);
|
|
|
|
static int intsmb_attach(device_t);
|
2007-01-11 19:56:24 +00:00
|
|
|
static int intsmb_detach(device_t);
|
|
|
|
static int intsmb_intr(struct intsmb_softc *sc);
|
|
|
|
static int intsmb_slvintr(struct intsmb_softc *sc);
|
|
|
|
static void intsmb_alrintr(struct intsmb_softc *sc);
|
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
|
|
|
static int intsmb_callback(device_t dev, int index, void *data);
|
1999-01-24 18:13:31 +00:00
|
|
|
static int intsmb_quick(device_t dev, u_char slave, int how);
|
|
|
|
static int intsmb_sendb(device_t dev, u_char slave, char byte);
|
|
|
|
static int intsmb_recvb(device_t dev, u_char slave, char *byte);
|
|
|
|
static int intsmb_writeb(device_t dev, u_char slave, char cmd, char byte);
|
|
|
|
static int intsmb_writew(device_t dev, u_char slave, char cmd, short word);
|
|
|
|
static int intsmb_readb(device_t dev, u_char slave, char cmd, char *byte);
|
|
|
|
static int intsmb_readw(device_t dev, u_char slave, char cmd, short *word);
|
|
|
|
static int intsmb_pcall(device_t dev, u_char slave, char cmd, short sdata, short *rdata);
|
|
|
|
static int intsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf);
|
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
|
|
|
static int intsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf);
|
2007-01-11 19:56:24 +00:00
|
|
|
static void intsmb_start(struct intsmb_softc *sc, u_char cmd, int nointr);
|
|
|
|
static int intsmb_stop(struct intsmb_softc *sc);
|
|
|
|
static int intsmb_stop_poll(struct intsmb_softc *sc);
|
|
|
|
static int intsmb_free(struct intsmb_softc *sc);
|
|
|
|
static void intsmb_rawintr(void *arg);
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
static int
|
|
|
|
intsmb_probe(device_t dev)
|
|
|
|
{
|
1999-01-24 18:13:31 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
switch (pci_get_devid(dev)) {
|
|
|
|
case 0x71138086: /* Intel 82371AB */
|
|
|
|
case 0x719b8086: /* Intel 82443MX */
|
|
|
|
#if 0
|
|
|
|
/* Not a good idea yet, this stops isab0 functioning */
|
|
|
|
case 0x02001166: /* ServerWorks OSB4 */
|
|
|
|
#endif
|
|
|
|
device_set_desc(dev, "Intel PIIX4 SMBUS Interface");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
static int
|
|
|
|
intsmb_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct intsmb_softc *sc = device_get_softc(dev);
|
|
|
|
int error, rid, value;
|
|
|
|
char *str;
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
mtx_init(&sc->lock, device_get_nameunit(dev), "intsmb", MTX_DEF);
|
1999-01-24 18:13:31 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
rid = PCI_BASE_ADDR_SMB;
|
|
|
|
sc->io_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
|
|
|
|
RF_ACTIVE);
|
|
|
|
if (sc->io_res == NULL) {
|
|
|
|
device_printf(dev, "Could not allocate I/O space\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NO_CHANGE_PCICONF
|
|
|
|
pci_write_config(dev, PCIR_INTLINE, 0x9, 1);
|
|
|
|
pci_write_config(dev, PCI_HST_CFG_SMB,
|
|
|
|
PCI_INTR_SMB_IRQ9 | PCI_INTR_SMB_ENABLE, 1);
|
|
|
|
#endif
|
|
|
|
value = pci_read_config(dev, PCI_HST_CFG_SMB, 1);
|
|
|
|
switch (value & 0xe) {
|
|
|
|
case PCI_INTR_SMB_SMI:
|
|
|
|
str = "SMI";
|
|
|
|
break;
|
|
|
|
case PCI_INTR_SMB_IRQ9:
|
|
|
|
str = "IRQ 9";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "BOGUS";
|
|
|
|
}
|
|
|
|
device_printf(dev, "intr %s %s ", str,
|
|
|
|
(value & 1) ? "enabled" : "disabled");
|
2007-04-19 17:14:06 +00:00
|
|
|
printf("revision %d\n", pci_read_config(dev, PCI_REVID_SMB, 1));
|
1999-01-24 18:13:31 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
if ((value & 0xe) != PCI_INTR_SMB_IRQ9) {
|
|
|
|
device_printf(dev, "Unsupported interrupt mode\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
1999-01-24 18:13:31 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
/* Force IRQ 9. */
|
|
|
|
rid = 0;
|
|
|
|
bus_set_resource(dev, SYS_RES_IRQ, rid, 9, 1);
|
|
|
|
sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
|
|
|
|
RF_SHAREABLE | RF_ACTIVE);
|
|
|
|
if (sc->irq_res == NULL) {
|
|
|
|
device_printf(dev, "Could not allocate irq\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
1999-05-07 18:03:27 +00:00
|
|
|
|
2007-02-23 12:19:07 +00:00
|
|
|
error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC, NULL,
|
|
|
|
intsmb_rawintr, sc, &sc->irq_hand);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "Failed to map intr\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
1999-01-24 18:13:31 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
value = pci_read_config(dev, PCI_BASE_ADDR_PM, 4);
|
|
|
|
device_printf(dev, "PM %s %x\n", (value & 1) ? "I/O mapped" : "Memory",
|
|
|
|
value & 0xfffe);
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
sc->isbusy = 0;
|
|
|
|
sc->smbus = device_add_child(dev, "smbus", -1);
|
|
|
|
if (sc->smbus == NULL) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
error = device_probe_and_attach(sc->smbus);
|
|
|
|
if (error)
|
|
|
|
goto fail;
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
#ifdef ENABLE_ALART
|
|
|
|
/* Enable Arart */
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBSLVCNT, PIIX4_SMBSLVCNT_ALTEN);
|
|
|
|
#endif
|
|
|
|
return (0);
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
fail:
|
|
|
|
intsmb_detach(dev);
|
|
|
|
return (error);
|
|
|
|
}
|
1999-01-24 18:13:31 +00:00
|
|
|
|
2006-09-13 18:56:39 +00:00
|
|
|
static int
|
2007-01-11 19:56:24 +00:00
|
|
|
intsmb_detach(device_t dev)
|
1999-01-24 18:13:31 +00:00
|
|
|
{
|
2006-09-13 18:56:39 +00:00
|
|
|
struct intsmb_softc *sc = device_get_softc(dev);
|
2007-01-11 19:56:24 +00:00
|
|
|
int error;
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
error = bus_generic_detach(dev);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
if (sc->smbus)
|
|
|
|
device_delete_child(dev, sc->smbus);
|
|
|
|
if (sc->irq_hand)
|
|
|
|
bus_teardown_intr(dev, sc->irq_res, sc->irq_hand);
|
|
|
|
if (sc->irq_res)
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
|
|
|
|
if (sc->io_res)
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, PCI_BASE_ADDR_SMB,
|
|
|
|
sc->io_res);
|
|
|
|
mtx_destroy(&sc->lock);
|
|
|
|
return (0);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
intsmb_rawintr(void *arg)
|
1999-01-24 18:13:31 +00:00
|
|
|
{
|
2007-01-11 19:56:24 +00:00
|
|
|
struct intsmb_softc *sc = arg;
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_LOCK(sc);
|
|
|
|
intsmb_intr(sc);
|
|
|
|
intsmb_slvintr(sc);
|
|
|
|
INTSMB_UNLOCK(sc);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
|
|
|
|
2006-09-13 18:56:39 +00:00
|
|
|
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
|
|
|
intsmb_callback(device_t dev, int index, void *data)
|
1999-01-24 18:13:31 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
2006-09-13 18:56:39 +00:00
|
|
|
|
1999-01-24 18:13:31 +00:00
|
|
|
switch (index) {
|
|
|
|
case SMB_REQUEST_BUS:
|
|
|
|
break;
|
|
|
|
case SMB_RELEASE_BUS:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
1999-01-24 18:13:31 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
|
|
|
/* Counterpart of smbtx_smb_free(). */
|
|
|
|
static int
|
2007-01-11 19:56:24 +00:00
|
|
|
intsmb_free(struct intsmb_softc *sc)
|
2006-09-13 18:56:39 +00:00
|
|
|
{
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_LOCK_ASSERT(sc);
|
|
|
|
if ((bus_read_1(sc->io_res, PIIX4_SMBHSTSTS) & PIIX4_SMBHSTSTAT_BUSY) ||
|
1999-01-24 18:13:31 +00:00
|
|
|
#ifdef ENABLE_ALART
|
2007-01-11 19:56:24 +00:00
|
|
|
(bus_read_1(sc->io_res, PIIX4_SMBSLVSTS) & PIIX4_SMBSLVSTS_BUSY) ||
|
1999-01-24 18:13:31 +00:00
|
|
|
#endif
|
2006-09-13 18:56:39 +00:00
|
|
|
sc->isbusy)
|
2007-01-11 19:56:24 +00:00
|
|
|
return (SMB_EBUSY);
|
|
|
|
|
2006-09-13 18:56:39 +00:00
|
|
|
sc->isbusy = 1;
|
|
|
|
/* Disable Interrupt in slave part. */
|
1999-01-24 18:13:31 +00:00
|
|
|
#ifndef ENABLE_ALART
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBSLVCNT, 0);
|
1999-01-24 18:13:31 +00:00
|
|
|
#endif
|
2006-09-13 18:56:39 +00:00
|
|
|
/* Reset INTR Flag to prepare INTR. */
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTSTS,
|
|
|
|
PIIX4_SMBHSTSTAT_INTR | PIIX4_SMBHSTSTAT_ERR |
|
|
|
|
PIIX4_SMBHSTSTAT_BUSC | PIIX4_SMBHSTSTAT_FAIL);
|
2006-09-13 18:56:39 +00:00
|
|
|
return (0);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-01-11 19:56:24 +00:00
|
|
|
intsmb_intr(struct intsmb_softc *sc)
|
1999-01-24 18:13:31 +00:00
|
|
|
{
|
2007-01-11 19:56:24 +00:00
|
|
|
int status, tmp;
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
status = bus_read_1(sc->io_res, PIIX4_SMBHSTSTS);
|
2006-09-13 18:56:39 +00:00
|
|
|
if (status & PIIX4_SMBHSTSTAT_BUSY)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
if (status & (PIIX4_SMBHSTSTAT_INTR | PIIX4_SMBHSTSTAT_ERR |
|
|
|
|
PIIX4_SMBHSTSTAT_BUSC | PIIX4_SMBHSTSTAT_FAIL)) {
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
tmp = bus_read_1(sc->io_res, PIIX4_SMBHSTCNT);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTCNT,
|
2006-09-13 18:56:39 +00:00
|
|
|
tmp & ~PIIX4_SMBHSTCNT_INTREN);
|
|
|
|
if (sc->isbusy) {
|
|
|
|
sc->isbusy = 0;
|
|
|
|
wakeup(sc);
|
1999-07-24 19:13:54 +00:00
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
return (0);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
return (1); /* Not Completed */
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
1999-01-24 18:13:31 +00:00
|
|
|
static int
|
2007-01-11 19:56:24 +00:00
|
|
|
intsmb_slvintr(struct intsmb_softc *sc)
|
1999-01-24 18:13:31 +00:00
|
|
|
{
|
2007-01-11 19:56:24 +00:00
|
|
|
int status;
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
status = bus_read_1(sc->io_res, PIIX4_SMBSLVSTS);
|
2006-09-13 18:56:39 +00:00
|
|
|
if (status & PIIX4_SMBSLVSTS_BUSY)
|
2007-01-11 19:56:24 +00:00
|
|
|
return (1);
|
|
|
|
if (status & PIIX4_SMBSLVSTS_ALART)
|
|
|
|
intsmb_alrintr(sc);
|
|
|
|
else if (status & ~(PIIX4_SMBSLVSTS_ALART | PIIX4_SMBSLVSTS_SDW2
|
2006-09-13 18:56:39 +00:00
|
|
|
| PIIX4_SMBSLVSTS_SDW1)) {
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
|
|
|
/* Reset Status Register */
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBSLVSTS,
|
2006-09-13 18:56:39 +00:00
|
|
|
PIIX4_SMBSLVSTS_ALART | PIIX4_SMBSLVSTS_SDW2 |
|
|
|
|
PIIX4_SMBSLVSTS_SDW1 | PIIX4_SMBSLVSTS_SLV);
|
2007-01-11 19:56:24 +00:00
|
|
|
return (0);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
|
|
|
|
2006-09-13 18:56:39 +00:00
|
|
|
static void
|
2007-01-11 19:56:24 +00:00
|
|
|
intsmb_alrintr(struct intsmb_softc *sc)
|
1999-01-24 18:13:31 +00:00
|
|
|
{
|
|
|
|
int slvcnt;
|
1999-01-27 18:36:49 +00:00
|
|
|
#ifdef ENABLE_ALART
|
|
|
|
int error;
|
2007-01-11 19:56:24 +00:00
|
|
|
uint8_t addr;
|
1999-01-27 18:36:49 +00:00
|
|
|
#endif
|
|
|
|
|
2006-09-13 18:56:39 +00:00
|
|
|
/* Stop generating INTR from ALART. */
|
2007-01-11 19:56:24 +00:00
|
|
|
slvcnt = bus_read_1(sc->io_res, PIIX4_SMBSLVCNT);
|
1999-01-24 18:13:31 +00:00
|
|
|
#ifdef ENABLE_ALART
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBSLVCNT,
|
2006-09-13 18:56:39 +00:00
|
|
|
slvcnt & ~PIIX4_SMBSLVCNT_ALTEN);
|
1999-01-24 18:13:31 +00:00
|
|
|
#endif
|
|
|
|
DELAY(5);
|
2006-09-13 18:56:39 +00:00
|
|
|
|
|
|
|
/* Ask bus who asserted it and then ask it what's the matter. */
|
1999-01-24 18:13:31 +00:00
|
|
|
#ifdef ENABLE_ALART
|
2007-01-11 19:56:24 +00:00
|
|
|
error = intsmb_free(sc);
|
|
|
|
if (error)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTADD, SMBALTRESP | LSB);
|
|
|
|
intsmb_start(sc, PIIX4_SMBHSTCNT_PROT_BYTE, 1);
|
|
|
|
error = intsmb_stop_poll(sc);
|
|
|
|
if (error)
|
|
|
|
device_printf(sc->dev, "ALART: ERROR\n");
|
|
|
|
else {
|
|
|
|
addr = bus_read_1(sc->io_res, PIIX4_SMBHSTDAT0);
|
|
|
|
device_printf(sc->dev, "ALART_RESPONSE: 0x%x\n", addr);
|
|
|
|
}
|
1999-01-24 18:13:31 +00:00
|
|
|
|
2006-09-13 18:56:39 +00:00
|
|
|
/* Re-enable INTR from ALART. */
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBSLVCNT,
|
2006-09-13 18:56:39 +00:00
|
|
|
slvcnt | PIIX4_SMBSLVCNT_ALTEN);
|
1999-01-24 18:13:31 +00:00
|
|
|
DELAY(5);
|
|
|
|
#endif
|
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
1999-01-24 18:13:31 +00:00
|
|
|
static void
|
2007-01-11 19:56:24 +00:00
|
|
|
intsmb_start(struct intsmb_softc *sc, unsigned char cmd, int nointr)
|
1999-01-24 18:13:31 +00:00
|
|
|
{
|
|
|
|
unsigned char tmp;
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_LOCK_ASSERT(sc);
|
|
|
|
tmp = bus_read_1(sc->io_res, PIIX4_SMBHSTCNT);
|
2006-09-13 18:56:39 +00:00
|
|
|
tmp &= 0xe0;
|
1999-01-24 18:13:31 +00:00
|
|
|
tmp |= cmd;
|
2006-09-13 18:56:39 +00:00
|
|
|
tmp |= PIIX4_SMBHSTCNT_START;
|
|
|
|
|
|
|
|
/* While not in autoconfiguration enable interrupts. */
|
|
|
|
if (!cold || !nointr)
|
|
|
|
tmp |= PIIX4_SMBHSTCNT_INTREN;
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTCNT, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
intsmb_error(int status)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
if (status & PIIX4_SMBHSTSTAT_ERR)
|
|
|
|
error |= SMB_EBUSERR;
|
|
|
|
if (status & PIIX4_SMBHSTSTAT_BUSC)
|
|
|
|
error |= SMB_ECOLLI;
|
|
|
|
if (status & PIIX4_SMBHSTSTAT_FAIL)
|
|
|
|
error |= SMB_ENOACK;
|
|
|
|
return (error);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
|
|
|
|
2006-09-13 18:56:39 +00:00
|
|
|
/*
|
|
|
|
* Polling Code.
|
|
|
|
*
|
|
|
|
* Polling is not encouraged because it requires waiting for the
|
|
|
|
* device if it is busy.
|
|
|
|
* (29063505.pdf from Intel) But during boot, interrupt cannot be used, so use
|
|
|
|
* polling code then.
|
1999-01-24 18:13:31 +00:00
|
|
|
*/
|
2006-09-13 18:56:39 +00:00
|
|
|
static int
|
2007-01-11 19:56:24 +00:00
|
|
|
intsmb_stop_poll(struct intsmb_softc *sc)
|
2006-09-13 18:56:39 +00:00
|
|
|
{
|
2007-01-11 19:56:24 +00:00
|
|
|
int error, i, status, tmp;
|
1999-01-24 18:13:31 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_LOCK_ASSERT(sc);
|
|
|
|
|
|
|
|
/* First, wait for busy to be set. */
|
2006-09-13 18:56:39 +00:00
|
|
|
for (i = 0; i < 0x7fff; i++)
|
2007-01-11 19:56:24 +00:00
|
|
|
if (bus_read_1(sc->io_res, PIIX4_SMBHSTSTS) &
|
2006-09-13 18:56:39 +00:00
|
|
|
PIIX4_SMBHSTSTAT_BUSY)
|
|
|
|
break;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
/* Wait for busy to clear. */
|
2006-09-13 18:56:39 +00:00
|
|
|
for (i = 0; i < 0x7fff; i++) {
|
2007-01-11 19:56:24 +00:00
|
|
|
status = bus_read_1(sc->io_res, PIIX4_SMBHSTSTS);
|
2006-09-13 18:56:39 +00:00
|
|
|
if (!(status & PIIX4_SMBHSTSTAT_BUSY)) {
|
|
|
|
sc->isbusy = 0;
|
2007-01-11 19:56:24 +00:00
|
|
|
error = intsmb_error(status);
|
2006-09-13 18:56:39 +00:00
|
|
|
if (error == 0 && !(status & PIIX4_SMBHSTSTAT_INTR))
|
2007-01-11 19:56:24 +00:00
|
|
|
device_printf(sc->dev, "unknown cause why?");
|
2006-09-13 18:56:39 +00:00
|
|
|
return (error);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
/* Timed out waiting for busy to clear. */
|
2006-09-13 18:56:39 +00:00
|
|
|
sc->isbusy = 0;
|
2007-01-11 19:56:24 +00:00
|
|
|
tmp = bus_read_1(sc->io_res, PIIX4_SMBHSTCNT);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTCNT, tmp & ~PIIX4_SMBHSTCNT_INTREN);
|
|
|
|
return (SMB_ETIMEOUT);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
1999-01-24 18:13:31 +00:00
|
|
|
/*
|
2006-09-13 18:56:39 +00:00
|
|
|
* Wait for completion and return result.
|
1999-01-24 18:13:31 +00:00
|
|
|
*/
|
2006-09-13 18:56:39 +00:00
|
|
|
static int
|
2007-01-11 19:56:24 +00:00
|
|
|
intsmb_stop(struct intsmb_softc *sc)
|
2006-09-13 18:56:39 +00:00
|
|
|
{
|
2007-01-11 19:56:24 +00:00
|
|
|
int error, status;
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_LOCK_ASSERT(sc);
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
if (cold)
|
|
|
|
/* So that it can use device during device probe on SMBus. */
|
|
|
|
return (intsmb_stop_poll(sc));
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-10-15 16:18:20 +00:00
|
|
|
error = msleep(sc, &sc->lock, PWAIT | PCATCH, "SMBWAI", hz / 8);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (error == 0) {
|
|
|
|
status = bus_read_1(sc->io_res, PIIX4_SMBHSTSTS);
|
2006-09-13 18:56:39 +00:00
|
|
|
if (!(status & PIIX4_SMBHSTSTAT_BUSY)) {
|
2007-01-11 19:56:24 +00:00
|
|
|
error = intsmb_error(status);
|
2006-09-13 18:56:39 +00:00
|
|
|
if (error == 0 && !(status & PIIX4_SMBHSTSTAT_INTR))
|
2007-01-11 19:56:24 +00:00
|
|
|
device_printf(sc->dev, "unknown cause why?\n");
|
1999-01-24 18:13:31 +00:00
|
|
|
#ifdef ENABLE_ALART
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBSLVCNT,
|
2006-09-13 18:56:39 +00:00
|
|
|
PIIX4_SMBSLVCNT_ALTEN);
|
1999-01-24 18:13:31 +00:00
|
|
|
#endif
|
2006-09-13 18:56:39 +00:00
|
|
|
return (error);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
|
|
|
/* Timeout Procedure. */
|
|
|
|
sc->isbusy = 0;
|
|
|
|
|
|
|
|
/* Re-enable supressed interrupt from slave part. */
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBSLVCNT, PIIX4_SMBSLVCNT_ALTEN);
|
|
|
|
if (error == EWOULDBLOCK)
|
|
|
|
return (SMB_ETIMEOUT);
|
|
|
|
else
|
|
|
|
return (SMB_EABORT);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
intsmb_quick(device_t dev, u_char slave, int how)
|
|
|
|
{
|
2006-09-13 18:56:39 +00:00
|
|
|
struct intsmb_softc *sc = device_get_softc(dev);
|
2007-01-11 19:56:24 +00:00
|
|
|
int error;
|
2006-09-13 18:56:39 +00:00
|
|
|
u_char data;
|
|
|
|
|
|
|
|
data = slave;
|
|
|
|
|
|
|
|
/* Quick command is part of Address, I think. */
|
|
|
|
switch(how) {
|
|
|
|
case SMB_QWRITE:
|
|
|
|
data &= ~LSB;
|
1999-01-24 18:13:31 +00:00
|
|
|
break;
|
2006-09-13 18:56:39 +00:00
|
|
|
case SMB_QREAD:
|
|
|
|
data |= LSB;
|
|
|
|
break;
|
|
|
|
default:
|
2007-01-11 19:56:24 +00:00
|
|
|
return (EINVAL);
|
2006-09-13 18:56:39 +00:00
|
|
|
}
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_LOCK(sc);
|
|
|
|
error = intsmb_free(sc);
|
|
|
|
if (error) {
|
|
|
|
INTSMB_UNLOCK(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTADD, data);
|
|
|
|
intsmb_start(sc, PIIX4_SMBHSTCNT_PROT_QUICK, 0);
|
|
|
|
error = intsmb_stop(sc);
|
|
|
|
INTSMB_UNLOCK(sc);
|
2006-09-13 18:56:39 +00:00
|
|
|
return (error);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
intsmb_sendb(device_t dev, u_char slave, char byte)
|
|
|
|
{
|
2006-09-13 18:56:39 +00:00
|
|
|
struct intsmb_softc *sc = device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_LOCK(sc);
|
|
|
|
error = intsmb_free(sc);
|
|
|
|
if (error) {
|
|
|
|
INTSMB_UNLOCK(sc);
|
|
|
|
return (error);
|
2006-09-13 18:56:39 +00:00
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTADD, slave & ~LSB);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTCMD, byte);
|
|
|
|
intsmb_start(sc, PIIX4_SMBHSTCNT_PROT_BYTE, 0);
|
|
|
|
error = intsmb_stop(sc);
|
|
|
|
INTSMB_UNLOCK(sc);
|
2006-09-13 18:56:39 +00:00
|
|
|
return (error);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
1999-01-24 18:13:31 +00:00
|
|
|
static int
|
|
|
|
intsmb_recvb(device_t dev, u_char slave, char *byte)
|
|
|
|
{
|
2006-09-13 18:56:39 +00:00
|
|
|
struct intsmb_softc *sc = device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_LOCK(sc);
|
|
|
|
error = intsmb_free(sc);
|
|
|
|
if (error) {
|
|
|
|
INTSMB_UNLOCK(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTADD, slave | LSB);
|
|
|
|
intsmb_start(sc, PIIX4_SMBHSTCNT_PROT_BYTE, 0);
|
|
|
|
error = intsmb_stop(sc);
|
|
|
|
if (error == 0) {
|
1999-01-24 18:13:31 +00:00
|
|
|
#ifdef RECV_IS_IN_CMD
|
2007-01-11 19:56:24 +00:00
|
|
|
/*
|
|
|
|
* Linux SMBus stuff also troubles
|
|
|
|
* Because Intel's datasheet does not make clear.
|
|
|
|
*/
|
|
|
|
*byte = bus_read_1(sc->io_res, PIIX4_SMBHSTCMD);
|
1999-01-24 18:13:31 +00:00
|
|
|
#else
|
2007-01-11 19:56:24 +00:00
|
|
|
*byte = bus_read_1(sc->io_res, PIIX4_SMBHSTDAT0);
|
1999-01-24 18:13:31 +00:00
|
|
|
#endif
|
2006-09-13 18:56:39 +00:00
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_UNLOCK(sc);
|
2006-09-13 18:56:39 +00:00
|
|
|
return (error);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
1999-01-24 18:13:31 +00:00
|
|
|
static int
|
|
|
|
intsmb_writeb(device_t dev, u_char slave, char cmd, char byte)
|
|
|
|
{
|
2006-09-13 18:56:39 +00:00
|
|
|
struct intsmb_softc *sc = device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_LOCK(sc);
|
|
|
|
error = intsmb_free(sc);
|
|
|
|
if (error) {
|
|
|
|
INTSMB_UNLOCK(sc);
|
|
|
|
return (error);
|
2006-09-13 18:56:39 +00:00
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTADD, slave & ~LSB);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTCMD, cmd);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTDAT0, byte);
|
|
|
|
intsmb_start(sc, PIIX4_SMBHSTCNT_PROT_BDATA, 0);
|
|
|
|
error = intsmb_stop(sc);
|
|
|
|
INTSMB_UNLOCK(sc);
|
2006-09-13 18:56:39 +00:00
|
|
|
return (error);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
1999-01-24 18:13:31 +00:00
|
|
|
static int
|
|
|
|
intsmb_writew(device_t dev, u_char slave, char cmd, short word)
|
|
|
|
{
|
2006-09-13 18:56:39 +00:00
|
|
|
struct intsmb_softc *sc = device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_LOCK(sc);
|
|
|
|
error = intsmb_free(sc);
|
|
|
|
if (error) {
|
|
|
|
INTSMB_UNLOCK(sc);
|
|
|
|
return (error);
|
2006-09-13 18:56:39 +00:00
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTADD, slave & ~LSB);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTCMD, cmd);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTDAT0, word & 0xff);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTDAT1, (word >> 8) & 0xff);
|
|
|
|
intsmb_start(sc, PIIX4_SMBHSTCNT_PROT_WDATA, 0);
|
|
|
|
error = intsmb_stop(sc);
|
|
|
|
INTSMB_UNLOCK(sc);
|
2006-09-13 18:56:39 +00:00
|
|
|
return (error);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
intsmb_readb(device_t dev, u_char slave, char cmd, char *byte)
|
|
|
|
{
|
2006-09-13 18:56:39 +00:00
|
|
|
struct intsmb_softc *sc = device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_LOCK(sc);
|
|
|
|
error = intsmb_free(sc);
|
|
|
|
if (error) {
|
|
|
|
INTSMB_UNLOCK(sc);
|
|
|
|
return (error);
|
2006-09-13 18:56:39 +00:00
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTADD, slave | LSB);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTCMD, cmd);
|
|
|
|
intsmb_start(sc, PIIX4_SMBHSTCNT_PROT_BDATA, 0);
|
|
|
|
error = intsmb_stop(sc);
|
|
|
|
if (error == 0)
|
|
|
|
*byte = bus_read_1(sc->io_res, PIIX4_SMBHSTDAT0);
|
|
|
|
INTSMB_UNLOCK(sc);
|
2006-09-13 18:56:39 +00:00
|
|
|
return (error);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
|
1999-01-24 18:13:31 +00:00
|
|
|
static int
|
|
|
|
intsmb_readw(device_t dev, u_char slave, char cmd, short *word)
|
|
|
|
{
|
2006-09-13 18:56:39 +00:00
|
|
|
struct intsmb_softc *sc = device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_LOCK(sc);
|
|
|
|
error = intsmb_free(sc);
|
|
|
|
if (error) {
|
|
|
|
INTSMB_UNLOCK(sc);
|
|
|
|
return (error);
|
2006-09-13 18:56:39 +00:00
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTADD, slave | LSB);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTCMD, cmd);
|
|
|
|
intsmb_start(sc, PIIX4_SMBHSTCNT_PROT_WDATA, 0);
|
|
|
|
error = intsmb_stop(sc);
|
|
|
|
if (error == 0) {
|
|
|
|
*word = bus_read_1(sc->io_res, PIIX4_SMBHSTDAT0);
|
|
|
|
*word |= bus_read_1(sc->io_res, PIIX4_SMBHSTDAT1) << 8;
|
|
|
|
}
|
|
|
|
INTSMB_UNLOCK(sc);
|
2006-09-13 18:56:39 +00:00
|
|
|
return (error);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
1999-01-24 18:13:31 +00:00
|
|
|
/*
|
|
|
|
* Data sheet claims that it implements all function, but also claims
|
|
|
|
* that it implements 7 function and not mention PCALL. So I don't know
|
|
|
|
* whether it will work.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
intsmb_pcall(device_t dev, u_char slave, char cmd, short sdata, short *rdata)
|
|
|
|
{
|
|
|
|
#ifdef PROCCALL_TEST
|
2006-09-13 18:56:39 +00:00
|
|
|
struct intsmb_softc *sc = device_get_softc(dev);
|
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_LOCK(sc);
|
|
|
|
error = intsmb_free(sc);
|
|
|
|
if (error) {
|
|
|
|
INTSMB_UNLOCK(sc);
|
|
|
|
return (error);
|
2006-09-13 18:56:39 +00:00
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTADD, slave & ~LSB);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTCMD, cmd);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTDAT0, sdata & 0xff);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTDAT1, (sdata & 0xff) >> 8);
|
|
|
|
intsmb_start(sc, PIIX4_SMBHSTCNT_PROT_WDATA, 0);
|
|
|
|
error = intsmb_stop(sc);
|
|
|
|
if (error == 0) {
|
|
|
|
*rdata = bus_read_1(sc->io_res, PIIX4_SMBHSTDAT0);
|
|
|
|
*rdata |= bus_read_1(sc->io_res, PIIX4_SMBHSTDAT1) << 8;
|
2006-09-13 18:56:39 +00:00
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_UNLOCK(sc);
|
2006-09-13 18:56:39 +00:00
|
|
|
return (error);
|
1999-01-24 18:13:31 +00:00
|
|
|
#else
|
2007-01-11 19:56:24 +00:00
|
|
|
return (SMB_ENOTSUPP);
|
1999-01-24 18:13:31 +00:00
|
|
|
#endif
|
|
|
|
}
|
2006-09-13 18:56:39 +00:00
|
|
|
|
1999-01-24 18:13:31 +00:00
|
|
|
static int
|
|
|
|
intsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf)
|
|
|
|
{
|
2006-09-13 18:56:39 +00:00
|
|
|
struct intsmb_softc *sc = device_get_softc(dev);
|
|
|
|
int error, i;
|
|
|
|
|
|
|
|
if (count > SMBBLOCKTRANS_MAX || count == 0)
|
2007-01-11 19:56:24 +00:00
|
|
|
return (SMB_EINVAL);
|
|
|
|
|
|
|
|
INTSMB_LOCK(sc);
|
|
|
|
error = intsmb_free(sc);
|
|
|
|
if (error) {
|
|
|
|
INTSMB_UNLOCK(sc);
|
|
|
|
return (error);
|
2006-09-13 18:56:39 +00:00
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
|
|
|
|
/* Reset internal array index. */
|
|
|
|
bus_read_1(sc->io_res, PIIX4_SMBHSTCNT);
|
|
|
|
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTADD, slave & ~LSB);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTCMD, cmd);
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBBLKDAT, buf[i]);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTDAT0, count);
|
|
|
|
intsmb_start(sc, PIIX4_SMBHSTCNT_PROT_BLOCK, 0);
|
|
|
|
error = intsmb_stop(sc);
|
|
|
|
INTSMB_UNLOCK(sc);
|
2006-09-13 18:56:39 +00:00
|
|
|
return (error);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
intsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf)
|
1999-01-24 18:13:31 +00:00
|
|
|
{
|
2006-09-13 18:56:39 +00:00
|
|
|
struct intsmb_softc *sc = device_get_softc(dev);
|
|
|
|
int error, i;
|
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, nread;
|
2006-09-13 18:56:39 +00:00
|
|
|
|
|
|
|
if (*count > SMBBLOCKTRANS_MAX || *count == 0)
|
2007-01-11 19:56:24 +00:00
|
|
|
return (SMB_EINVAL);
|
|
|
|
|
|
|
|
INTSMB_LOCK(sc);
|
|
|
|
error = intsmb_free(sc);
|
|
|
|
if (error) {
|
|
|
|
INTSMB_UNLOCK(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset internal array index. */
|
|
|
|
bus_read_1(sc->io_res, PIIX4_SMBHSTCNT);
|
|
|
|
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTADD, slave | LSB);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTCMD, cmd);
|
|
|
|
bus_write_1(sc->io_res, PIIX4_SMBHSTDAT0, *count);
|
|
|
|
intsmb_start(sc, PIIX4_SMBHSTCNT_PROT_BLOCK, 0);
|
|
|
|
error = intsmb_stop(sc);
|
|
|
|
if (error == 0) {
|
|
|
|
nread = bus_read_1(sc->io_res, PIIX4_SMBHSTDAT0);
|
|
|
|
if (nread != 0 && nread <= SMBBLOCKTRANS_MAX) {
|
|
|
|
for (i = 0; i < nread; i++) {
|
|
|
|
data = bus_read_1(sc->io_res, PIIX4_SMBBLKDAT);
|
|
|
|
if (i < *count)
|
|
|
|
buf[i] = data;
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
*count = nread;
|
|
|
|
} else
|
|
|
|
error = EIO;
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
INTSMB_UNLOCK(sc);
|
2006-09-13 18:56:39 +00:00
|
|
|
return (error);
|
1999-01-24 18:13:31 +00:00
|
|
|
}
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
static devclass_t intsmb_devclass;
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
static device_method_t intsmb_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, intsmb_probe),
|
|
|
|
DEVMETHOD(device_attach, intsmb_attach),
|
|
|
|
DEVMETHOD(device_detach, intsmb_detach),
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, bus_generic_print_child),
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
/* SMBus interface */
|
|
|
|
DEVMETHOD(smbus_callback, intsmb_callback),
|
|
|
|
DEVMETHOD(smbus_quick, intsmb_quick),
|
|
|
|
DEVMETHOD(smbus_sendb, intsmb_sendb),
|
|
|
|
DEVMETHOD(smbus_recvb, intsmb_recvb),
|
|
|
|
DEVMETHOD(smbus_writeb, intsmb_writeb),
|
|
|
|
DEVMETHOD(smbus_writew, intsmb_writew),
|
|
|
|
DEVMETHOD(smbus_readb, intsmb_readb),
|
|
|
|
DEVMETHOD(smbus_readw, intsmb_readw),
|
|
|
|
DEVMETHOD(smbus_pcall, intsmb_pcall),
|
|
|
|
DEVMETHOD(smbus_bwrite, intsmb_bwrite),
|
|
|
|
DEVMETHOD(smbus_bread, intsmb_bread),
|
1999-05-07 18:03:27 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
static driver_t intsmb_driver = {
|
|
|
|
"intsmb",
|
|
|
|
intsmb_methods,
|
|
|
|
sizeof(struct intsmb_softc),
|
|
|
|
};
|
2006-09-13 18:56:39 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
DRIVER_MODULE(intsmb, pci, intsmb_driver, intsmb_devclass, 0, 0);
|
2006-09-13 18:56:39 +00:00
|
|
|
DRIVER_MODULE(smbus, intsmb, smbus_driver, smbus_devclass, 0, 0);
|
2007-01-11 19:56:24 +00:00
|
|
|
MODULE_DEPEND(intsmb, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER);
|
|
|
|
MODULE_VERSION(intsmb, 1);
|