Implement a mechanism for making changes in the kernel<->driver PPS
interface without breaking ABI or API compatibility with existing drivers. The existing data structures used to communicate between the kernel and driver portions of PPS processing contain no spare/padding fields and no flags field or other straightforward mechanism for communicating changes in the structures or behaviors of the code. This makes it difficult to MFC new features added to the PPS facility. ABI compatibility is important; out-of-tree drivers in module form are known to exist. (Note that the existing api_version field in the pps_params structure must contain the value mandated by RFC 2783 and any RFCs that come along after.) These changes introduce a pair of abi-version fields which are filled in by the driver and the kernel respectively to indicate the interface version. The driver sets its version field before calling the new pps_init_abi() function. That lets the kernel know how much of the pps_state structure is understood by the driver and it can avoid using newer fields at the end of the structure that it knows about if the driver is a lower version. The kernel fills in its version field during the init call, letting the driver know what features and data the kernel supports. To implement the new version information in a way that is backwards compatible with code from before these changes, the high bit of the lightly-used 'kcmode' field is repurposed as a flag bit that indicates the driver is aware of the abi versioning scheme. Basically if this bit is clear that indicates a "version 0" driver and if it is set the driver_abi field indicates the version. These changes also move the recently-added 'mtx' field of pps_state from the middle to the end of the structure, and make the kernel code that uses this field conditional on the driver being abi version 1 or higher. It changes the only driver currently supplying the mtx field, usb_serial, to use pps_init_abi(). Reviewed by: hselasky@
This commit is contained in:
parent
dd354955d4
commit
28315e27a7
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=282424
@ -415,8 +415,9 @@ ucom_attach_tty(struct ucom_super_softc *ssc, struct ucom_softc *sc)
|
||||
sc->sc_tty = tp;
|
||||
|
||||
sc->sc_pps.ppscap = PPS_CAPTUREBOTH;
|
||||
sc->sc_pps.mtx = sc->sc_mtx;
|
||||
pps_init(&sc->sc_pps);
|
||||
sc->sc_pps.driver_abi = PPS_ABI_VERSION;
|
||||
sc->sc_pps.driver_mtx = sc->sc_mtx;
|
||||
pps_init_abi(&sc->sc_pps);
|
||||
|
||||
DPRINTF("ttycreate: %s\n", buf);
|
||||
|
||||
|
@ -1468,6 +1468,17 @@ SYSCTL_PROC(_kern_timecounter, OID_AUTO, choice, CTLTYPE_STRING | CTLFLAG_RD,
|
||||
* RFC 2783 PPS-API implementation.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Return true if the driver is aware of the abi version extensions in the
|
||||
* pps_state structure, and it supports at least the given abi version number.
|
||||
*/
|
||||
static inline int
|
||||
abi_aware(struct pps_state *pps, int vers)
|
||||
{
|
||||
|
||||
return ((pps->kcmode & KCMODE_ABIFLAG) && pps->driver_abi >= vers);
|
||||
}
|
||||
|
||||
static int
|
||||
pps_fetch(struct pps_fetch_args *fapi, struct pps_state *pps)
|
||||
{
|
||||
@ -1497,10 +1508,17 @@ pps_fetch(struct pps_fetch_args *fapi, struct pps_state *pps)
|
||||
cseq = pps->ppsinfo.clear_sequence;
|
||||
while (aseq == pps->ppsinfo.assert_sequence &&
|
||||
cseq == pps->ppsinfo.clear_sequence) {
|
||||
if (pps->mtx != NULL)
|
||||
err = msleep(pps, pps->mtx, PCATCH, "ppsfch", timo);
|
||||
else
|
||||
if (abi_aware(pps, 1) && pps->driver_mtx != NULL) {
|
||||
if (pps->flags & PPSFLAG_MTX_SPIN) {
|
||||
err = msleep_spin(pps, pps->driver_mtx,
|
||||
"ppsfch", timo);
|
||||
} else {
|
||||
err = msleep(pps, pps->driver_mtx, PCATCH,
|
||||
"ppsfch", timo);
|
||||
}
|
||||
} else {
|
||||
err = tsleep(pps, PCATCH, "ppsfch", timo);
|
||||
}
|
||||
if (err == EWOULDBLOCK && fapi->timeout.tv_sec == -1) {
|
||||
continue;
|
||||
} else if (err != 0) {
|
||||
@ -1590,7 +1608,8 @@ pps_ioctl(u_long cmd, caddr_t data, struct pps_state *pps)
|
||||
return (EINVAL);
|
||||
if (kapi->edge & ~pps->ppscap)
|
||||
return (EINVAL);
|
||||
pps->kcmode = kapi->edge;
|
||||
pps->kcmode = (kapi->edge & KCMODE_EDGEMASK) |
|
||||
(pps->kcmode & KCMODE_ABIFLAG);
|
||||
return (0);
|
||||
#else
|
||||
return (EOPNOTSUPP);
|
||||
@ -1611,6 +1630,18 @@ pps_init(struct pps_state *pps)
|
||||
#ifdef FFCLOCK
|
||||
pps->ppscap |= PPS_TSCLK_MASK;
|
||||
#endif
|
||||
pps->kcmode &= ~KCMODE_ABIFLAG;
|
||||
}
|
||||
|
||||
void
|
||||
pps_init_abi(struct pps_state *pps)
|
||||
{
|
||||
|
||||
pps_init(pps);
|
||||
if (pps->driver_abi > 0) {
|
||||
pps->kcmode |= KCMODE_ABIFLAG;
|
||||
pps->kernel_abi = PPS_ABI_VERSION;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -135,6 +135,13 @@ struct pps_kcbind_args {
|
||||
|
||||
struct mtx;
|
||||
|
||||
#define KCMODE_EDGEMASK 0x03
|
||||
#define KCMODE_ABIFLAG 0x80000000 /* Internal use: abi-aware driver. */
|
||||
|
||||
#define PPS_ABI_VERSION 1
|
||||
|
||||
#define PPSFLAG_MTX_SPIN 0x01 /* Driver mtx is MTX_SPIN type. */
|
||||
|
||||
struct pps_state {
|
||||
/* Capture information. */
|
||||
struct timehands *capth;
|
||||
@ -142,9 +149,6 @@ struct pps_state {
|
||||
unsigned capgen;
|
||||
unsigned capcount;
|
||||
|
||||
/* pointer to mutex protecting this state, if any */
|
||||
struct mtx *mtx;
|
||||
|
||||
/* State information. */
|
||||
pps_params_t ppsparam;
|
||||
pps_info_t ppsinfo;
|
||||
@ -153,11 +157,19 @@ struct pps_state {
|
||||
int ppscap;
|
||||
struct timecounter *ppstc;
|
||||
unsigned ppscount[3];
|
||||
/*
|
||||
* The following fields are valid if the driver calls pps_init_abi().
|
||||
*/
|
||||
uint16_t driver_abi; /* Driver sets before pps_init_abi(). */
|
||||
uint16_t kernel_abi; /* Kernel sets during pps_init_abi(). */
|
||||
struct mtx *driver_mtx; /* Optional, valid if non-NULL. */
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
void pps_capture(struct pps_state *pps);
|
||||
void pps_event(struct pps_state *pps, int event);
|
||||
void pps_init(struct pps_state *pps);
|
||||
void pps_init_abi(struct pps_state *pps);
|
||||
int pps_ioctl(unsigned long cmd, caddr_t data, struct pps_state *pps);
|
||||
void hardpps(struct timespec *tsp, long nsec);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user