History log of /freebsd-current/sys/dev/iicbus/iic.c
Revision Date Author Comments
# 473c90ac 10-May-2024 John Baldwin <jhb@FreeBSD.org>

uio: Use switch statements when handling UIO_READ vs UIO_WRITE

This is mostly to reduce the diff with CheriBSD which adds additional
constants to enum uio_rw, but also matches the normal style used for
uio_segflg.

Reviewed by: kib, emaste
Obtained from: CheriBSD
Differential Revision: https://reviews.freebsd.org/D45142


# 682b069c 29-Nov-2023 Stephen J. Kiernan <stevek@FreeBSD.org>

iicbus: add compat32 support for I2C ioctls

Some of the I2C ioctl request structures contain pointers and need to
handle requests from 32-bit applications on 64-bit kernels.

Obtained from: Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D42836


# 95ee2897 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: two-line .h pattern

Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 3a866152 20-Apr-2022 John Baldwin <jhb@FreeBSD.org>

iicbus: Remove unused devclass arguments to DRIVER_MODULE.


# 718cf2cc 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/dev: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# 523a6367 19-May-2016 Jason A. Harmening <jah@FreeBSD.org>

iic_rdwr_data->nmsgs is uint32_t, so limit the allowable number of messages to prevent memory exhaustion and short allocations on 32-bit systems. Since iicrdwr is intended to be a workalike of a Linux i2c-dev call, use the same limit of 42 that Linux uses.

Also check the return value of copyin(9) to prevent unnecessary allocation in the failure case.

Submitted by: ngie
Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D5155


# d52f763c 30-Jan-2016 Enji Cooper <ngie@FreeBSD.org>

Use the correct type for i when iterating over `buf` to avoid unlikely
negative array indexing in iicrdwr(..)

Differential Revision: https://reviews.freebsd.org/D5132
Obtained from: HardenedBSD
PR: 206754
Reported by: CTurt <cturt@hardenedbsd.org>
Submitted by: Madhi Moktari <mokhi64@gmail.com>
Sponsored by: EMC / Isilon Storage Division


# 0afebee2 21-Apr-2015 Jason A. Harmening <jah@FreeBSD.org>

Fix numerous issues in iic(4) and iicbus(4):
--Allow multiple open iic fds by storing addressing state in cdevpriv
--Fix, as much as possible, the baked-in race conditions in the iic
ioctl interface by requesting bus ownership on I2CSTART, releasing it on
I2CSTOP/I2CRSTCARD, and requiring bus ownership by the current cdevpriv
to use the I/O ioctls
--Reduce internal iic buffer size and remove 1K read/write limit by
iteratively calling iicbus_read/iicbus_write
--Eliminate dynamic allocation in I2CWRITE/I2CREAD
--Move handling of I2CRDWR to separate function and improve error handling
--Add new I2CSADDR ioctl to store address in current cdevpriv so that
I2CSTART is not needed for read(2)/write(2) to work
--Redesign iicbus_request_bus() and iicbus_release_bus():
--iicbus_request_bus() no longer falls through if the bus is already
owned by the requesting device. Multiple threads on the same device may
want exclusive access. Also, iicbus_release_bus() was never
device-recursive anyway.
--Previously, if IICBUS_CALLBACK failed in iicbus_release_bus(), but
the following iicbus_poll() call succeeded, IICBUS_CALLBACK would not be
issued again
--Do not hold iicbus mtx during IICBUS_CALLBACK call. There are
several drivers that may sleep in IICBUS_CALLBACK, if IIC_WAIT is passed.
--Do not loop in iicbus_request_bus if IICBUS_CALLBACK returns
EWOULDBLOCK; instead pass that to the caller so that it can retry if so
desired.

Differential Revision: https://reviews.freebsd.org/D2140
Reviewed by: imp, jhb, loos
Approved by: kib (mentor)


# efce3748 12-Jul-2014 Rui Paulo <rpaulo@FreeBSD.org>

Revert r268543.

We should probably fix sys/gpio.h instead.


# bd08cbb8 11-Jul-2014 Rui Paulo <rpaulo@FreeBSD.org>

Move iic.h to sys/ so that it's automatically installed in /usr/include/sys.

This lets us call iic(4) ioctls without needing the kernel source code
and follows the same model of GPIO.

MFC after: 3 weeks


# 34aa2211 31-May-2014 Luiz Otavio O Souza <loos@FreeBSD.org>

Ignore IIC_ENOADDR from iicbus_reset() as it only means we have a
master-only controller.

This fixes the iic bus scan with i2c(8) (on supported controllers).

Tested with gpioiic(4).


# 72794e9e 12-Nov-2012 Kevin Lo <kevlo@FreeBSD.org>

Check the return value of uiomove(9).


# 04c45489 16-Oct-2011 Christian Brueffer <brueffer@FreeBSD.org>

Revert r226398 and instead move the allocation of usrbufs after the error check.

Suggested by: pjd
MFC after: 1 week


# 0ad684e7 15-Oct-2011 Christian Brueffer <brueffer@FreeBSD.org>

Properly free resources in an error case.

CID: 4203
Found with: Coverity Prevent(tm)
MFC after: 1 week


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 1aef11be 26-Jan-2009 Rafal Jaworowski <raj@FreeBSD.org>

Teach iic(4) the 'repeated start' I2C condition. This will be used by the
upcoming i2c(8) diag utility.

Reviewed by: bms, stas
Obtained from: Semihalf


# ee9db219 15-Jan-2009 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Revert revision 186833 and try a different strategy to allow this device to
work when the bus attaches its own children. Instead of hardcoding a unit
number and returning BUS_PROBE_NOWILDCARD, which will break multiple iicbus
systems, check in the probe routine whether the device address is 0. Real
I2C devices will never have this address, but devices added with
BUS_ADD_CHILD() will.

Requested by: jhb
Reviewed by: jhb


# 789c4b9d 06-Jan-2009 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Change the way I2C bus attachment works to allow firmware-assisted bus
subclasses as are available with PCI. Changes I2C device drivers without
real probe logic to return BUS_PROBE_NOWILDWARD to avoid interference with
firmware bus enumeration, and reduces the probe priority of the iicbus
base driver to allow subclass attachment at higher priority.

Discussed on: freebsd-arch


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 313f8941 04-Aug-2008 John Baldwin <jhb@FreeBSD.org>

Add locking to the core iicbus(4) drivers:
- Add an sx lock to the iic(4) driver to serialize open(), close(), read(),
and write and to protect sc_addr and sc_count in the softc.
- Use cdev->si_drv1 instead of using the minor number of the cdev to
lookup the softc via newbus in iic(4).
- Store the device_t in the softc to avoid a similar detour via minor
numbers in iic(4).
- Only add at most one instance of iic(4) and iicsmb(4) to each iicbus(4)
instance, and do it in the child driver.
- Add a mutex to the iicbus(4) softc to synchronize the request/release bus
stuff.
- Use __BUS_ACCESSOR() for IICBUS_ACCESSOR() instead of rolling our own.
- Add a mutex to the iicsmb(4) softc to protect softc state updated in the
interrupt handler.
- Remove Giant from all the smbus methods in iicsmb(4) now that all the
iicbus(4) backend is locked.


# d4fa6840 23-Mar-2007 Warner Losh <imp@FreeBSD.org>

MFp4: Make the iicbus fully hinted. We no longer automatically add
some devices (and not others). To get instances onto the iicbus, one
now needs hints or an identify routine. We also do not probe the bus
for devices because many iic devices cannot be safely probed (and when
they can, the probe order turns out to be somewhat difficult to get
right).

# I'm not 100% sure that the iicsmb removal is right. Please contact me if
# this causes difficulty.


# 64e04316 21-Nov-2006 Warner Losh <imp@FreeBSD.org>

<blush> copyout on read, not write.
Tweak a comment while I'm here.


# ec2b5cd8 06-Sep-2006 Warner Losh <imp@FreeBSD.org>

jhb points out that these mallocs don't need to be checked because
of M_WAITOK.


# 14ca3cd6 06-Sep-2006 Warner Losh <imp@FreeBSD.org>

MFp4: check the return value of malloc and report an error when invalid.


# d7fac973 14-Jul-2006 Warner Losh <imp@FreeBSD.org>

Allow iic bridges to support a generalized transfer, rather than
forcing all transfers to do the start read/write stop by hand. Some
smart bridges prefer this sort of operation, and this allows us to
support their features more easily. When bridges don't support it, we
fall back to using the old-style opertaions. Expand the ioctl
interface to expose this function. Unlike the old-style interface,
this interface is thread safe, even on old bridges.


# dbafaeca 04-Apr-2006 Warner Losh <imp@FreeBSD.org>

newbus will zero softc, so no need to duplicate the zeroing here.
Plus a minor formatting nit in nearby code.


# b2f9074c 04-Apr-2006 Warner Losh <imp@FreeBSD.org>

Replace hard coded '0' with symbolic constant IIC_UNKNOWN to reflect what
we're actually doing.


# 89c9c53d 16-Jun-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Do the dreaded s/dev_t/struct cdev */
Bump __FreeBSD_version accordingly.


# 69271da4 16-May-2004 Joerg Wunsch <joerg@FreeBSD.org>

Another candidate that didn't use copyin/copyout for user<->kernel
transfers.

MFC after: 1 month


# dc08ffec 21-Feb-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Device megapatch 4/6:

Introduce d_version field in struct cdevsw, this must always be
initialized to D_VERSION.

Flip sense of D_NOGIANT flag to D_NEEDGIANT, this involves removing
four D_NOGIANT flags and adding 145 D_NEEDGIANT flags.


# c9c7976f 21-Feb-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Device megapatch 1/6:

Free approx 86 major numbers with a mostly automatically generated patch.

A number of strategic drivers have been left behind by caution, and a few
because they still (ab)use their major number.


# b08a61b0 10-Aug-2003 Bernd Walter <ticso@FreeBSD.org>

Don't hardcode unit numer '0'.
We can have multiple instances.


# 7ac40f5f 02-Mar-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Gigacommit to improve device-driver source compatibility between
branches:

Initialize struct cdevsw using C99 sparse initializtion and remove
all initializations to default values.

This patch is automatically generated and has been tested by compiling
LINT with all the fields in struct cdevsw in reverse order on alpha,
sparc64 and i386.

Approved by: re(scottl)


# 531facba 18-Sep-2002 Peter Wemm <peter@FreeBSD.org>

move <machine/iic.h> and <machine/smb.h> to <dev/iicbus/iic.h> and
<dev/smbus/smb.h> - there is nothing MD about these ioctl definitions.


# c17d4340 23-Mar-2002 Nicolas Souchu <nsouch@FreeBSD.org>

Major rework of the iicbus/smbus framework:

- VIA chipset SMBus controllers added
- alpm driver updated
- Support for dynamic modules added
- bktr FreeBSD smbus updated but not tested
- cleanup


# 6e551fb6 10-Dec-2001 David E. O'Brien <obrien@FreeBSD.org>

Update to C99, s/__FUNCTION__/__func__/,
also don't use ANSI string concatenation.


# b40ce416 12-Sep-2001 Julian Elischer <julian@FreeBSD.org>

KSE Milestone 2
Note ALL MODULES MUST BE RECOMPILED
make the kernel aware that there are smaller units of scheduling than the
process. (but only allow one thread per process at this time).
This is functionally equivalent to teh previousl -current except
that there is a thread associated with each process.

Sorry john! (your next MFC will be a doosie!)

Reviewed by: peter@freebsd.org, dillon@freebsd.org

X-MFC after: ha ha ha ha


# f8388051 25-Mar-2001 Poul-Henning Kamp <phk@FreeBSD.org>

Send the remains (such as I have located) of "block major numbers" to
the bit-bucket.


# db7e3af1 15-Oct-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Remove unneeded #include <machine/clock.h>


# 3389ae93 19-Apr-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Remove ~25 unneeded #include <sys/conf.h>
Remove ~60 unneeded #include <sys/malloc.h>


# ed6aff73 18-Apr-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Remove unneeded <sys/buf.h> includes.

Due to some interesting cpp tricks in lockmgr, the LINT kernel shrinks
by 924 bytes.


# 38703ed3 17-Nov-1999 Peter Wemm <peter@FreeBSD.org>

Convert iic to use make_dev() rather than cdevsw_add(). This stops the
annoying 'iic is usurping iic's cdevsw' type messages. (Yes, there are
other ways to fix cdevsw_add(), but that is a doomed api)


# 80855566 08-Nov-1999 Peter Wemm <peter@FreeBSD.org>

Use cdevsw_add() explicitly and DRIVER_MODULE().


# fb45ca12 04-Oct-1999 Peter Wemm <peter@FreeBSD.org>

Fix: WARNING: "iic" is usurping "iic"'s cdevsw[] - the DEV_DRIVER_MODULE()
takes care of the cdevsw_add() - it doesn't need to be done twice.


# d6a0e38a 25-Sep-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Remove five now unused fields from struct cdevsw. They should never
have been there in the first place. A GENERIC kernel shrinks almost 1k.

Add a slightly different safetybelt under nostop for tty drivers.

Add some missing FreeBSD tags


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 03016f42 04-Jul-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Remove cmaj and bmaj args from DEV_DRIVER_MODULE.


# 2447bec8 31-May-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Simplify cdevsw registration.

The cdevsw_add() function now finds the major number(s) in the
struct cdevsw passed to it. cdevsw_add_generic() is no longer
needed, cdevsw_add() does the same thing.

cdevsw_add() will print an message if the d_maj field looks bogus.

Remove nblkdev and nchrdev variables. Most places they were used
bogusly. Instead check a dev_t for validity by seeing if devsw()
or bdevsw() returns NULL.

Move bdevsw() and devsw() functions to kern/kern_conf.c

Bump __FreeBSD_version to 400006

This commit removes:
72 bogus makedev() calls
26 bogus SYSINIT functions

if_xe.c bogusly accessed cdevsw[], author/maintainer please fix.

I4b and vinum not changed. Patches emailed to authors. LINT
probably broken until they catch up.


# 4e2f199e 30-May-1999 Poul-Henning Kamp <phk@FreeBSD.org>

This commit should be a extensive NO-OP:

Reformat and initialize correctly all "struct cdevsw".

Initialize the d_maj and d_bmaj fields.

The d_reset field was not removed, although it is never used.

I used a program to do most of this, so all the files now use the
same consistent format. Please keep it that way.

Vinum and i4b not modified, patches emailed to respective authors.


# 52400704 09-May-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Unconfuse DEV_MODULE() and DEV_DRIVER_MODULE() about the difference between
a major number for a dev_t.


# 566643e3 08-May-1999 Doug Rabson <dfr@FreeBSD.org>

Move the declaration of the interrupt type from the driver structure
to the BUS_SETUP_INTR call.


# 46eede00 07-May-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Continue where Julian left off in July 1998:

Virtualize bdevsw[] from cdevsw. bdevsw() is now an (inline)
function.

Join CDEV_MODULE and BDEV_MODULE to DEV_MODULE (please pay attention
to the order of the cmaj/bmaj arguments!)

Join CDEV_DRIVER_MODULE and BDEV_DRIVER_MODULE to DEV_DRIVER_MODULE
(ditto!)

(Next step will be to convert all bdev dev_t's to cdev dev_t's
before they get to do any damage^H^H^H^H^H^Hwork in the kernel.)


# 67c13fce 13-Feb-1999 Nicolas Souchu <nsouch@FreeBSD.org>

Handle correctly iicbus request/release mechanism. Add iicbus allocation
to the general purpose i/o iic(4) driver.


# bf896bd0 09-Jan-1999 Nicolas Souchu <nsouch@FreeBSD.org>

Change /dev/smb and /dev/iic interface to allow user programs to interact with
devices dynamically. That means,

+ only one /dev/iic or /dev/smb device for each smb/iic bus to access
+ I2C/SMB device address must be given to any ioctl
+ new devices may be plugged and accessed after boot, which was
impossible previously (device addresses were hardcoded into
the kernel)


# f1d19042 07-Dec-1998 Archie Cobbs <archie@FreeBSD.org>

The "easy" fixes for compiling the kernel -Wunused: remove unreferenced static
and local variables, goto labels, and functions declared but not defined.


# 04f89a63 31-Oct-1998 Nicolas Souchu <nsouch@FreeBSD.org>

iicbb is generic support for I2C bit-banging.

Other files: timeout management added to the I2C framework.


# 7da75285 09-Sep-1998 Nicolas Souchu <nsouch@FreeBSD.org>

Major number allocated for generic I2C i/o -> 105


# c498ec5f 04-Sep-1998 Nicolas Souchu <nsouch@FreeBSD.org>

Device registration temporaly removed until major number allocation ok.


# c3e2dc6b 03-Sep-1998 Nicolas Souchu <nsouch@FreeBSD.org>

Submitted by: nsouch
Philips I2C bus generic support other new bus architecture.