HomeFreeBSD

Fix numerous issues in iic(4) and iicbus(4):

Description

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)

Event Timeline