Page MenuHomeFreeBSD

Create a mechanism for encoding a system errno into the IIC_Exxxxx space
ClosedPublic

Authored by ian on Jul 16 2019, 7:38 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Dec 22, 5:59 PM
Unknown Object (File)
Sun, Dec 15, 2:36 PM
Unknown Object (File)
Wed, Nov 27, 1:32 AM
Unknown Object (File)
Nov 17 2024, 2:08 PM
Unknown Object (File)
Nov 16 2024, 2:16 AM
Unknown Object (File)
Nov 14 2024, 12:44 AM
Unknown Object (File)
Oct 3 2024, 10:51 AM
Unknown Object (File)
Oct 2 2024, 8:22 PM
Subscribers

Details

Summary

Errors are communicated between the i2c controller layer and upper layers (iicbus and slave device drivers) using a set of IIC_Exxxxxx constants which effectively define a private number space separate from (and having values that conflict with) the system errno number space. Sometimes it is necessary to report a plain old system error (especially EINTR) from the controller or bus layer and have that value make it back across the syscall interface intact.

I initially considered replicating a few "crucial" errno values with similar names and new numbers, e.g., IIC_EINTR, IIC_ERESTART, etc. It seemed like that had the potential to grow over time until many of the errno names were duplicated into the IIC_Exxxxx space.

So instead, this defines a mechanism to "encode" an errno into the IIC_Exxxx space by setting the high bit and putting the errno into the lower-order bits; a new errno2iic() function does this. The existing iic2errno() recognizes the encoded values and extracts the original errno out of the encoded value. An interesting wrinkle occurs with the pseudo-error values such as ERESTART -- they aleady have the high bit set, and turning it off would be the wrong thing to do. Instead, iic2errno() recognizes that lots of high bits are on (i.e., it's a negative number near to zero) and just returns that value as-is.

Thus, existing drivers continue to work without needing any changes, and there is now a way to return errno values from the lower layers. The first use of that is in iicbus_poll() which does mtx_sleep() with the PCATCH flag, and needs to return the errno from that up the call chain.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable