1999-02-13 17:51:46 +00:00
|
|
|
/*-
|
2001-01-02 21:19:32 +00:00
|
|
|
* Copyright (c) 1998, 1999, 2001 Nicolas Souchu
|
1999-02-13 17:51:46 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Power Management support for the Acer M15x3 chipsets
|
|
|
|
*/
|
2003-06-11 06:34:30 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-02-13 17:51:46 +00:00
|
|
|
#include <sys/param.h>
|
2007-01-11 19:56:24 +00:00
|
|
|
#include <sys/bus.h>
|
1999-02-13 17:51:46 +00:00
|
|
|
#include <sys/kernel.h>
|
2007-01-11 19:56:24 +00:00
|
|
|
#include <sys/lock.h>
|
1999-02-13 17:51:46 +00:00
|
|
|
#include <sys/module.h>
|
2007-01-11 19:56:24 +00:00
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/systm.h>
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
2001-01-02 21:19:32 +00:00
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
1999-02-13 17:51:46 +00:00
|
|
|
|
2003-08-22 07:20:27 +00:00
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
#include <dev/smbus/smbconf.h>
|
|
|
|
#include "smbus_if.h"
|
|
|
|
|
|
|
|
#define ALPM_DEBUG(x) if (alpm_debug) (x)
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static int alpm_debug = 1;
|
|
|
|
#else
|
|
|
|
static int alpm_debug = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ACER_M1543_PMU_ID 0x710110b9
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
/*
|
|
|
|
* I/O registers offsets - the base address is programmed via the
|
1999-02-13 17:51:46 +00:00
|
|
|
* SMBBA PCI configuration register
|
|
|
|
*/
|
|
|
|
#define SMBSTS 0x0 /* SMBus host/slave status register */
|
|
|
|
#define SMBCMD 0x1 /* SMBus host/slave command register */
|
|
|
|
#define SMBSTART 0x2 /* start to generate programmed cycle */
|
|
|
|
#define SMBHADDR 0x3 /* host address register */
|
|
|
|
#define SMBHDATA 0x4 /* data A register for host controller */
|
|
|
|
#define SMBHDATB 0x5 /* data B register for host controller */
|
|
|
|
#define SMBHBLOCK 0x6 /* block register for host controller */
|
|
|
|
#define SMBHCMD 0x7 /* command register for host controller */
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
/* SMBHADDR mask. */
|
|
|
|
#define LSB 0x1 /* XXX: Better name: Read/Write? */
|
|
|
|
|
1999-02-13 17:51:46 +00:00
|
|
|
/* SMBSTS masks */
|
|
|
|
#define TERMINATE 0x80
|
|
|
|
#define BUS_COLLI 0x40
|
|
|
|
#define DEVICE_ERR 0x20
|
|
|
|
#define SMI_I_STS 0x10
|
|
|
|
#define HST_BSY 0x08
|
|
|
|
#define IDL_STS 0x04
|
|
|
|
#define HSTSLV_STS 0x02
|
|
|
|
#define HSTSLV_BSY 0x01
|
|
|
|
|
|
|
|
/* SMBCMD masks */
|
|
|
|
#define SMB_BLK_CLR 0x80
|
|
|
|
#define T_OUT_CMD 0x08
|
|
|
|
#define ABORT_HOST 0x04
|
|
|
|
|
|
|
|
/* SMBus commands */
|
|
|
|
#define SMBQUICK 0x00
|
|
|
|
#define SMBSRBYTE 0x10 /* send/receive byte */
|
|
|
|
#define SMBWRBYTE 0x20 /* write/read byte */
|
|
|
|
#define SMBWRWORD 0x30 /* write/read word */
|
|
|
|
#define SMBWRBLOCK 0x40 /* write/read block */
|
|
|
|
|
|
|
|
/* PCI configuration registers and masks
|
|
|
|
*/
|
|
|
|
#define COM 0x4
|
|
|
|
#define COM_ENABLE_IO 0x1
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
#define SMBBA PCIR_BAR(1)
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
#define ATPC 0x5b
|
2001-01-02 21:19:32 +00:00
|
|
|
#define ATPC_SMBCTRL 0x04 /* XX linux has this as 0x6 */
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
#define SMBHSI 0xe0
|
|
|
|
#define SMBHSI_SLAVE 0x2
|
|
|
|
#define SMBHSI_HOST 0x1
|
|
|
|
|
|
|
|
#define SMBHCBC 0xe2
|
|
|
|
#define SMBHCBC_CLOCK 0x70
|
|
|
|
|
|
|
|
#define SMBCLOCK_149K 0x0
|
|
|
|
#define SMBCLOCK_74K 0x20
|
|
|
|
#define SMBCLOCK_37K 0x40
|
|
|
|
#define SMBCLOCK_223K 0x80
|
|
|
|
#define SMBCLOCK_111K 0xa0
|
|
|
|
#define SMBCLOCK_55K 0xc0
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
struct alpm_softc {
|
1999-02-13 17:51:46 +00:00
|
|
|
int base;
|
2002-03-23 15:49:15 +00:00
|
|
|
struct resource *res;
|
1999-02-13 17:51:46 +00:00
|
|
|
bus_space_tag_t smbst;
|
|
|
|
bus_space_handle_t smbsh;
|
|
|
|
device_t smbus;
|
2007-01-11 19:56:24 +00:00
|
|
|
struct mtx lock;
|
1999-02-13 17:51:46 +00:00
|
|
|
};
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
#define ALPM_LOCK(alpm) mtx_lock(&(alpm)->lock)
|
|
|
|
#define ALPM_UNLOCK(alpm) mtx_unlock(&(alpm)->lock)
|
|
|
|
#define ALPM_LOCK_ASSERT(alpm) mtx_assert(&(alpm)->lock, MA_OWNED)
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
#define ALPM_SMBINB(alpm,register) \
|
|
|
|
(bus_space_read_1(alpm->smbst, alpm->smbsh, register))
|
|
|
|
#define ALPM_SMBOUTB(alpm,register,value) \
|
|
|
|
(bus_space_write_1(alpm->smbst, alpm->smbsh, register, value))
|
1999-02-13 17:51:46 +00:00
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
static int alpm_detach(device_t dev);
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
static int
|
|
|
|
alpm_probe(device_t dev)
|
|
|
|
{
|
1999-02-13 17:51:46 +00:00
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
if (pci_get_devid(dev) == ACER_M1543_PMU_ID) {
|
|
|
|
device_set_desc(dev, "AcerLabs M15x3 Power Management Unit");
|
1999-02-13 17:51:46 +00:00
|
|
|
|
2005-02-24 21:32:56 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
2001-01-02 21:19:32 +00:00
|
|
|
}
|
2002-03-23 15:49:15 +00:00
|
|
|
|
|
|
|
return (ENXIO);
|
1999-02-13 17:51:46 +00:00
|
|
|
}
|
|
|
|
|
2001-01-02 21:19:32 +00:00
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_attach(device_t dev)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
2003-05-31 20:04:19 +00:00
|
|
|
int rid;
|
2001-01-02 21:19:32 +00:00
|
|
|
u_int32_t l;
|
2002-03-23 15:49:15 +00:00
|
|
|
struct alpm_softc *alpm;
|
1999-02-13 17:51:46 +00:00
|
|
|
|
2001-01-02 21:19:32 +00:00
|
|
|
alpm = device_get_softc(dev);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
/* Unlock SMBIO base register access */
|
2001-01-02 21:19:32 +00:00
|
|
|
l = pci_read_config(dev, ATPC, 1);
|
|
|
|
pci_write_config(dev, ATPC, l & ~ATPC_SMBCTRL, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XX linux sets clock to 74k, should we?
|
|
|
|
l = pci_read_config(dev, SMBHCBC, 1);
|
|
|
|
l &= 0x1f;
|
|
|
|
l |= SMBCLOCK_74K;
|
|
|
|
pci_write_config(dev, SMBHCBC, l, 1);
|
|
|
|
*/
|
1999-02-13 17:51:46 +00:00
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
if (bootverbose || alpm_debug) {
|
2001-01-02 21:19:32 +00:00
|
|
|
l = pci_read_config(dev, SMBHSI, 1);
|
2002-03-23 15:49:15 +00:00
|
|
|
device_printf(dev, "%s/%s",
|
1999-02-13 17:51:46 +00:00
|
|
|
(l & SMBHSI_HOST) ? "host":"nohost",
|
|
|
|
(l & SMBHSI_SLAVE) ? "slave":"noslave");
|
|
|
|
|
2001-01-02 21:19:32 +00:00
|
|
|
l = pci_read_config(dev, SMBHCBC, 1);
|
1999-02-13 17:51:46 +00:00
|
|
|
switch (l & SMBHCBC_CLOCK) {
|
|
|
|
case SMBCLOCK_149K:
|
|
|
|
printf(" 149K");
|
|
|
|
break;
|
|
|
|
case SMBCLOCK_74K:
|
|
|
|
printf(" 74K");
|
|
|
|
break;
|
|
|
|
case SMBCLOCK_37K:
|
|
|
|
printf(" 37K");
|
|
|
|
break;
|
|
|
|
case SMBCLOCK_223K:
|
|
|
|
printf(" 223K");
|
|
|
|
break;
|
|
|
|
case SMBCLOCK_111K:
|
|
|
|
printf(" 111K");
|
|
|
|
break;
|
|
|
|
case SMBCLOCK_55K:
|
|
|
|
printf(" 55K");
|
|
|
|
break;
|
2002-03-23 15:49:15 +00:00
|
|
|
default:
|
2016-05-03 03:41:25 +00:00
|
|
|
printf("unknown");
|
2002-03-23 15:49:15 +00:00
|
|
|
break;
|
1999-02-13 17:51:46 +00:00
|
|
|
}
|
2002-03-23 15:49:15 +00:00
|
|
|
printf("\n");
|
1999-02-13 17:51:46 +00:00
|
|
|
}
|
|
|
|
|
2001-01-02 21:19:32 +00:00
|
|
|
rid = SMBBA;
|
2004-03-17 17:50:55 +00:00
|
|
|
alpm->res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
|
|
|
|
RF_ACTIVE);
|
2002-03-23 15:49:15 +00:00
|
|
|
|
|
|
|
if (alpm->res == NULL) {
|
2001-01-02 21:19:32 +00:00
|
|
|
device_printf(dev,"Could not allocate Bus space\n");
|
2002-03-23 15:49:15 +00:00
|
|
|
return (ENXIO);
|
2001-01-02 21:19:32 +00:00
|
|
|
}
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm->smbst = rman_get_bustag(alpm->res);
|
|
|
|
alpm->smbsh = rman_get_bushandle(alpm->res);
|
2007-01-11 19:56:24 +00:00
|
|
|
mtx_init(&alpm->lock, device_get_nameunit(dev), "alpm", MTX_DEF);
|
2001-01-02 21:19:32 +00:00
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
/* attach the smbus */
|
|
|
|
alpm->smbus = device_add_child(dev, "smbus", -1);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (alpm->smbus == NULL) {
|
|
|
|
alpm_detach(dev);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2002-03-23 15:49:15 +00:00
|
|
|
bus_generic_attach(dev);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_detach(device_t dev)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
2002-03-23 15:49:15 +00:00
|
|
|
struct alpm_softc *alpm = device_get_softc(dev);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
if (alpm->smbus) {
|
|
|
|
device_delete_child(dev, alpm->smbus);
|
|
|
|
alpm->smbus = NULL;
|
|
|
|
}
|
2007-01-11 19:56:24 +00:00
|
|
|
mtx_destroy(&alpm->lock);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
if (alpm->res)
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, SMBBA, alpm->res);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
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
|
|
|
alpm_callback(device_t dev, int index, void *data)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
case SMB_REQUEST_BUS:
|
|
|
|
case SMB_RELEASE_BUS:
|
|
|
|
/* ok, bus allocation accepted */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_clear(struct alpm_softc *sc)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
|
|
|
ALPM_SMBOUTB(sc, SMBSTS, 0xff);
|
|
|
|
DELAY(10);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_abort(struct alpm_softc *sc)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
|
|
|
ALPM_SMBOUTB(sc, SMBCMD, T_OUT_CMD | ABORT_HOST);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_idle(struct alpm_softc *sc)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
|
|
|
u_char sts;
|
|
|
|
|
|
|
|
sts = ALPM_SMBINB(sc, SMBSTS);
|
|
|
|
|
|
|
|
ALPM_DEBUG(printf("alpm: idle? STS=0x%x\n", sts));
|
|
|
|
|
|
|
|
return (sts & IDL_STS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Poll the SMBus controller
|
|
|
|
*/
|
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_wait(struct alpm_softc *sc)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
|
|
|
int count = 10000;
|
2001-01-02 21:19:32 +00:00
|
|
|
u_char sts = 0;
|
1999-02-13 17:51:46 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
/* wait for command to complete and SMBus controller is idle */
|
2007-01-11 19:56:24 +00:00
|
|
|
while (count--) {
|
1999-02-13 17:51:46 +00:00
|
|
|
DELAY(10);
|
|
|
|
sts = ALPM_SMBINB(sc, SMBSTS);
|
|
|
|
if (sts & SMI_I_STS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALPM_DEBUG(printf("alpm: STS=0x%x\n", sts));
|
|
|
|
|
|
|
|
error = SMB_ENOERR;
|
|
|
|
|
|
|
|
if (!count)
|
|
|
|
error |= SMB_ETIMEOUT;
|
|
|
|
|
|
|
|
if (sts & TERMINATE)
|
|
|
|
error |= SMB_EABORT;
|
|
|
|
|
|
|
|
if (sts & BUS_COLLI)
|
|
|
|
error |= SMB_ENOACK;
|
|
|
|
|
|
|
|
if (sts & DEVICE_ERR)
|
|
|
|
error |= SMB_EBUSERR;
|
|
|
|
|
|
|
|
if (error != SMB_ENOERR)
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_clear(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_quick(device_t dev, u_char slave, int how)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
2002-03-23 15:49:15 +00:00
|
|
|
struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev);
|
1999-02-13 17:51:46 +00:00
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
ALPM_LOCK(sc);
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_clear(sc);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (!alpm_idle(sc)) {
|
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
return (EBUSY);
|
2007-01-11 19:56:24 +00:00
|
|
|
}
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
switch (how) {
|
|
|
|
case SMB_QWRITE:
|
|
|
|
ALPM_DEBUG(printf("alpm: QWRITE to 0x%x", slave));
|
|
|
|
ALPM_SMBOUTB(sc, SMBHADDR, slave & ~LSB);
|
|
|
|
break;
|
|
|
|
case SMB_QREAD:
|
|
|
|
ALPM_DEBUG(printf("alpm: QREAD to 0x%x", slave));
|
|
|
|
ALPM_SMBOUTB(sc, SMBHADDR, slave | LSB);
|
|
|
|
break;
|
|
|
|
default:
|
2001-12-10 08:09:49 +00:00
|
|
|
panic("%s: unknown QUICK command (%x)!", __func__,
|
1999-02-13 17:51:46 +00:00
|
|
|
how);
|
|
|
|
}
|
|
|
|
ALPM_SMBOUTB(sc, SMBCMD, SMBQUICK);
|
|
|
|
ALPM_SMBOUTB(sc, SMBSTART, 0xff);
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
error = alpm_wait(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
ALPM_DEBUG(printf(", error=0x%x\n", error));
|
2007-01-11 19:56:24 +00:00
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_sendb(device_t dev, u_char slave, char byte)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
2002-03-23 15:49:15 +00:00
|
|
|
struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev);
|
1999-02-13 17:51:46 +00:00
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
ALPM_LOCK(sc);
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_clear(sc);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (!alpm_idle(sc)) {
|
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
return (SMB_EBUSY);
|
2007-01-11 19:56:24 +00:00
|
|
|
}
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
ALPM_SMBOUTB(sc, SMBHADDR, slave & ~LSB);
|
|
|
|
ALPM_SMBOUTB(sc, SMBCMD, SMBSRBYTE);
|
|
|
|
ALPM_SMBOUTB(sc, SMBHDATA, byte);
|
|
|
|
ALPM_SMBOUTB(sc, SMBSTART, 0xff);
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
error = alpm_wait(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
ALPM_DEBUG(printf("alpm: SENDB to 0x%x, byte=0x%x, error=0x%x\n", slave, byte, error));
|
2007-01-11 19:56:24 +00:00
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_recvb(device_t dev, u_char slave, char *byte)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
2002-03-23 15:49:15 +00:00
|
|
|
struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev);
|
1999-02-13 17:51:46 +00:00
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
ALPM_LOCK(sc);
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_clear(sc);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (!alpm_idle(sc)) {
|
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
return (SMB_EBUSY);
|
2007-01-11 19:56:24 +00:00
|
|
|
}
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
ALPM_SMBOUTB(sc, SMBHADDR, slave | LSB);
|
|
|
|
ALPM_SMBOUTB(sc, SMBCMD, SMBSRBYTE);
|
|
|
|
ALPM_SMBOUTB(sc, SMBSTART, 0xff);
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
if ((error = alpm_wait(sc)) == SMB_ENOERR)
|
1999-02-13 17:51:46 +00:00
|
|
|
*byte = ALPM_SMBINB(sc, SMBHDATA);
|
|
|
|
|
|
|
|
ALPM_DEBUG(printf("alpm: RECVB from 0x%x, byte=0x%x, error=0x%x\n", slave, *byte, error));
|
2007-01-11 19:56:24 +00:00
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_writeb(device_t dev, u_char slave, char cmd, char byte)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
2002-03-23 15:49:15 +00:00
|
|
|
struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev);
|
1999-02-13 17:51:46 +00:00
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
ALPM_LOCK(sc);
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_clear(sc);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (!alpm_idle(sc)) {
|
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
return (SMB_EBUSY);
|
2007-01-11 19:56:24 +00:00
|
|
|
}
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
ALPM_SMBOUTB(sc, SMBHADDR, slave & ~LSB);
|
|
|
|
ALPM_SMBOUTB(sc, SMBCMD, SMBWRBYTE);
|
|
|
|
ALPM_SMBOUTB(sc, SMBHDATA, byte);
|
|
|
|
ALPM_SMBOUTB(sc, SMBHCMD, cmd);
|
|
|
|
ALPM_SMBOUTB(sc, SMBSTART, 0xff);
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
error = alpm_wait(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
ALPM_DEBUG(printf("alpm: 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
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_readb(device_t dev, u_char slave, char cmd, char *byte)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
2002-03-23 15:49:15 +00:00
|
|
|
struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev);
|
1999-02-13 17:51:46 +00:00
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
ALPM_LOCK(sc);
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_clear(sc);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (!alpm_idle(sc)) {
|
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
return (SMB_EBUSY);
|
2007-01-11 19:56:24 +00:00
|
|
|
}
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
ALPM_SMBOUTB(sc, SMBHADDR, slave | LSB);
|
|
|
|
ALPM_SMBOUTB(sc, SMBCMD, SMBWRBYTE);
|
|
|
|
ALPM_SMBOUTB(sc, SMBHCMD, cmd);
|
|
|
|
ALPM_SMBOUTB(sc, SMBSTART, 0xff);
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
if ((error = alpm_wait(sc)) == SMB_ENOERR)
|
1999-02-13 17:51:46 +00:00
|
|
|
*byte = ALPM_SMBINB(sc, SMBHDATA);
|
|
|
|
|
|
|
|
ALPM_DEBUG(printf("alpm: READB from 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, *byte, error));
|
2007-01-11 19:56:24 +00:00
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_writew(device_t dev, u_char slave, char cmd, short word)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
2002-03-23 15:49:15 +00:00
|
|
|
struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev);
|
1999-02-13 17:51:46 +00:00
|
|
|
int error;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
ALPM_LOCK(sc);
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_clear(sc);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (!alpm_idle(sc)) {
|
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
return (SMB_EBUSY);
|
2007-01-11 19:56:24 +00:00
|
|
|
}
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
ALPM_SMBOUTB(sc, SMBHADDR, slave & ~LSB);
|
|
|
|
ALPM_SMBOUTB(sc, SMBCMD, SMBWRWORD);
|
|
|
|
ALPM_SMBOUTB(sc, SMBHDATA, word & 0x00ff);
|
|
|
|
ALPM_SMBOUTB(sc, SMBHDATB, (word & 0xff00) >> 8);
|
|
|
|
ALPM_SMBOUTB(sc, SMBHCMD, cmd);
|
|
|
|
ALPM_SMBOUTB(sc, SMBSTART, 0xff);
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
error = alpm_wait(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
ALPM_DEBUG(printf("alpm: 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
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_readw(device_t dev, u_char slave, char cmd, short *word)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
2002-03-23 15:49:15 +00:00
|
|
|
struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev);
|
1999-02-13 17:51:46 +00:00
|
|
|
int error;
|
|
|
|
u_char high, low;
|
|
|
|
|
2007-01-11 19:56:24 +00:00
|
|
|
ALPM_LOCK(sc);
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_clear(sc);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (!alpm_idle(sc)) {
|
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
return (SMB_EBUSY);
|
2007-01-11 19:56:24 +00:00
|
|
|
}
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
ALPM_SMBOUTB(sc, SMBHADDR, slave | LSB);
|
|
|
|
ALPM_SMBOUTB(sc, SMBCMD, SMBWRWORD);
|
|
|
|
ALPM_SMBOUTB(sc, SMBHCMD, cmd);
|
|
|
|
ALPM_SMBOUTB(sc, SMBSTART, 0xff);
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
if ((error = alpm_wait(sc)) == SMB_ENOERR) {
|
1999-02-13 17:51:46 +00:00
|
|
|
low = ALPM_SMBINB(sc, SMBHDATA);
|
|
|
|
high = ALPM_SMBINB(sc, SMBHDATB);
|
|
|
|
|
|
|
|
*word = ((high & 0xff) << 8) | (low & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
ALPM_DEBUG(printf("alpm: READW from 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, *word, error));
|
2007-01-11 19:56:24 +00:00
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
2002-03-23 15:49:15 +00:00
|
|
|
struct alpm_softc *sc = (struct alpm_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;
|
|
|
|
int error;
|
1999-02-13 17:51:46 +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
|
|
|
if (count < 1 || count > 32)
|
|
|
|
return (SMB_EINVAL);
|
2007-01-11 19:56:24 +00:00
|
|
|
|
|
|
|
ALPM_LOCK(sc);
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_clear(sc);
|
2007-01-11 19:56:24 +00:00
|
|
|
if(!alpm_idle(sc)) {
|
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
return (SMB_EBUSY);
|
2007-01-11 19:56:24 +00:00
|
|
|
}
|
1999-02-13 17:51:46 +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
|
|
|
ALPM_SMBOUTB(sc, SMBHADDR, slave & ~LSB);
|
1999-02-13 17:51:46 +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
|
|
|
/* set the cmd and reset the
|
|
|
|
* 32-byte long internal buffer */
|
|
|
|
ALPM_SMBOUTB(sc, SMBCMD, SMBWRBLOCK | SMB_BLK_CLR);
|
1999-02-13 17:51:46 +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
|
|
|
ALPM_SMBOUTB(sc, SMBHDATA, count);
|
1999-02-13 17:51:46 +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
|
|
|
/* fill the 32-byte internal buffer */
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
ALPM_SMBOUTB(sc, SMBHBLOCK, buf[i]);
|
|
|
|
DELAY(2);
|
1999-02-13 17:51:46 +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
|
|
|
ALPM_SMBOUTB(sc, SMBHCMD, cmd);
|
|
|
|
ALPM_SMBOUTB(sc, SMBSTART, 0xff);
|
|
|
|
|
|
|
|
error = alpm_wait(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
ALPM_DEBUG(printf("alpm: 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
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +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
|
|
|
alpm_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf)
|
1999-02-13 17:51:46 +00:00
|
|
|
{
|
2002-03-23 15:49:15 +00:00
|
|
|
struct alpm_softc *sc = (struct alpm_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;
|
|
|
|
int error;
|
1999-02-13 17:51:46 +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
|
|
|
if (*count < 1 || *count > 32)
|
|
|
|
return (SMB_EINVAL);
|
2007-01-11 19:56:24 +00:00
|
|
|
|
|
|
|
ALPM_LOCK(sc);
|
2002-03-23 15:49:15 +00:00
|
|
|
alpm_clear(sc);
|
2007-01-11 19:56:24 +00:00
|
|
|
if (!alpm_idle(sc)) {
|
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
return (SMB_EBUSY);
|
2007-01-11 19:56:24 +00:00
|
|
|
}
|
1999-02-13 17:51:46 +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
|
|
|
ALPM_SMBOUTB(sc, SMBHADDR, slave | LSB);
|
1999-02-13 17:51:46 +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
|
|
|
/* set the cmd and reset the
|
|
|
|
* 32-byte long internal buffer */
|
|
|
|
ALPM_SMBOUTB(sc, SMBCMD, SMBWRBLOCK | SMB_BLK_CLR);
|
1999-02-13 17:51:46 +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
|
|
|
ALPM_SMBOUTB(sc, SMBHCMD, cmd);
|
|
|
|
ALPM_SMBOUTB(sc, SMBSTART, 0xff);
|
1999-02-13 17:51:46 +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
|
|
|
if ((error = alpm_wait(sc)) != SMB_ENOERR)
|
1999-02-13 17:51:46 +00:00
|
|
|
goto 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
|
|
|
len = ALPM_SMBINB(sc, SMBHDATA);
|
1999-02-13 17:51:46 +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
|
|
|
/* read the 32-byte internal buffer */
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
data = ALPM_SMBINB(sc, SMBHBLOCK);
|
|
|
|
if (i < *count)
|
|
|
|
buf[i] = data;
|
|
|
|
DELAY(2);
|
1999-02-13 17:51:46 +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
|
|
|
*count = len;
|
|
|
|
|
1999-02-13 17:51:46 +00:00
|
|
|
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
|
|
|
ALPM_DEBUG(printf("alpm: 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
|
|
|
ALPM_UNLOCK(sc);
|
1999-02-13 17:51:46 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-03-23 15:49:15 +00:00
|
|
|
static devclass_t alpm_devclass;
|
|
|
|
|
|
|
|
static device_method_t alpm_methods[] = {
|
|
|
|
/* device interface */
|
|
|
|
DEVMETHOD(device_probe, alpm_probe),
|
|
|
|
DEVMETHOD(device_attach, alpm_attach),
|
|
|
|
DEVMETHOD(device_detach, alpm_detach),
|
|
|
|
|
|
|
|
/* smbus interface */
|
|
|
|
DEVMETHOD(smbus_callback, alpm_callback),
|
|
|
|
DEVMETHOD(smbus_quick, alpm_quick),
|
|
|
|
DEVMETHOD(smbus_sendb, alpm_sendb),
|
|
|
|
DEVMETHOD(smbus_recvb, alpm_recvb),
|
|
|
|
DEVMETHOD(smbus_writeb, alpm_writeb),
|
|
|
|
DEVMETHOD(smbus_readb, alpm_readb),
|
|
|
|
DEVMETHOD(smbus_writew, alpm_writew),
|
|
|
|
DEVMETHOD(smbus_readw, alpm_readw),
|
|
|
|
DEVMETHOD(smbus_bwrite, alpm_bwrite),
|
|
|
|
DEVMETHOD(smbus_bread, alpm_bread),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t alpm_driver = {
|
|
|
|
"alpm",
|
|
|
|
alpm_methods,
|
|
|
|
sizeof(struct alpm_softc)
|
|
|
|
};
|
|
|
|
|
|
|
|
DRIVER_MODULE(alpm, pci, alpm_driver, alpm_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, alpm, smbus_driver, smbus_devclass, 0, 0);
|
2003-04-15 06:37:30 +00:00
|
|
|
MODULE_DEPEND(alpm, pci, 1, 1, 1);
|
2002-03-23 15:49:15 +00:00
|
|
|
MODULE_DEPEND(alpm, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER);
|
|
|
|
MODULE_VERSION(alpm, 1);
|