Deleted Added
full compact
kern_tc.c (280012) kern_tc.c (282424)
1/*-
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
8 *
9 * Copyright (c) 2011 The FreeBSD Foundation
10 * All rights reserved.
11 *
12 * Portions of this software were developed by Julien Ridoux at the University
13 * of Melbourne under sponsorship from the FreeBSD Foundation.
14 */
15
16#include <sys/cdefs.h>
1/*-
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
8 *
9 * Copyright (c) 2011 The FreeBSD Foundation
10 * All rights reserved.
11 *
12 * Portions of this software were developed by Julien Ridoux at the University
13 * of Melbourne under sponsorship from the FreeBSD Foundation.
14 */
15
16#include <sys/cdefs.h>
17__FBSDID("$FreeBSD: head/sys/kern/kern_tc.c 280012 2015-03-14 23:16:12Z ian $");
17__FBSDID("$FreeBSD: head/sys/kern/kern_tc.c 282424 2015-05-04 17:59:39Z ian $");
18
19#include "opt_compat.h"
20#include "opt_ntp.h"
21#include "opt_ffclock.h"
22
23#include <sys/param.h>
24#include <sys/kernel.h>
25#include <sys/limits.h>

--- 1437 unchanged lines hidden (view full) ---

1463
1464SYSCTL_PROC(_kern_timecounter, OID_AUTO, choice, CTLTYPE_STRING | CTLFLAG_RD,
1465 0, 0, sysctl_kern_timecounter_choice, "A", "Timecounter hardware detected");
1466
1467/*
1468 * RFC 2783 PPS-API implementation.
1469 */
1470
18
19#include "opt_compat.h"
20#include "opt_ntp.h"
21#include "opt_ffclock.h"
22
23#include <sys/param.h>
24#include <sys/kernel.h>
25#include <sys/limits.h>

--- 1437 unchanged lines hidden (view full) ---

1463
1464SYSCTL_PROC(_kern_timecounter, OID_AUTO, choice, CTLTYPE_STRING | CTLFLAG_RD,
1465 0, 0, sysctl_kern_timecounter_choice, "A", "Timecounter hardware detected");
1466
1467/*
1468 * RFC 2783 PPS-API implementation.
1469 */
1470
1471/*
1472 * Return true if the driver is aware of the abi version extensions in the
1473 * pps_state structure, and it supports at least the given abi version number.
1474 */
1475static inline int
1476abi_aware(struct pps_state *pps, int vers)
1477{
1478
1479 return ((pps->kcmode & KCMODE_ABIFLAG) && pps->driver_abi >= vers);
1480}
1481
1471static int
1472pps_fetch(struct pps_fetch_args *fapi, struct pps_state *pps)
1473{
1474 int err, timo;
1475 pps_seq_t aseq, cseq;
1476 struct timeval tv;
1477
1478 if (fapi->tsformat && fapi->tsformat != PPS_TSFMT_TSPEC)

--- 13 unchanged lines hidden (view full) ---

1492 tv.tv_sec = fapi->timeout.tv_sec;
1493 tv.tv_usec = fapi->timeout.tv_nsec / 1000;
1494 timo = tvtohz(&tv);
1495 }
1496 aseq = pps->ppsinfo.assert_sequence;
1497 cseq = pps->ppsinfo.clear_sequence;
1498 while (aseq == pps->ppsinfo.assert_sequence &&
1499 cseq == pps->ppsinfo.clear_sequence) {
1482static int
1483pps_fetch(struct pps_fetch_args *fapi, struct pps_state *pps)
1484{
1485 int err, timo;
1486 pps_seq_t aseq, cseq;
1487 struct timeval tv;
1488
1489 if (fapi->tsformat && fapi->tsformat != PPS_TSFMT_TSPEC)

--- 13 unchanged lines hidden (view full) ---

1503 tv.tv_sec = fapi->timeout.tv_sec;
1504 tv.tv_usec = fapi->timeout.tv_nsec / 1000;
1505 timo = tvtohz(&tv);
1506 }
1507 aseq = pps->ppsinfo.assert_sequence;
1508 cseq = pps->ppsinfo.clear_sequence;
1509 while (aseq == pps->ppsinfo.assert_sequence &&
1510 cseq == pps->ppsinfo.clear_sequence) {
1500 if (pps->mtx != NULL)
1501 err = msleep(pps, pps->mtx, PCATCH, "ppsfch", timo);
1502 else
1511 if (abi_aware(pps, 1) && pps->driver_mtx != NULL) {
1512 if (pps->flags & PPSFLAG_MTX_SPIN) {
1513 err = msleep_spin(pps, pps->driver_mtx,
1514 "ppsfch", timo);
1515 } else {
1516 err = msleep(pps, pps->driver_mtx, PCATCH,
1517 "ppsfch", timo);
1518 }
1519 } else {
1503 err = tsleep(pps, PCATCH, "ppsfch", timo);
1520 err = tsleep(pps, PCATCH, "ppsfch", timo);
1521 }
1504 if (err == EWOULDBLOCK && fapi->timeout.tv_sec == -1) {
1505 continue;
1506 } else if (err != 0) {
1507 return (err);
1508 }
1509 }
1510 }
1511

--- 73 unchanged lines hidden (view full) ---

1585 kapi = (struct pps_kcbind_args *)data;
1586 /* XXX Only root should be able to do this */
1587 if (kapi->tsformat && kapi->tsformat != PPS_TSFMT_TSPEC)
1588 return (EINVAL);
1589 if (kapi->kernel_consumer != PPS_KC_HARDPPS)
1590 return (EINVAL);
1591 if (kapi->edge & ~pps->ppscap)
1592 return (EINVAL);
1522 if (err == EWOULDBLOCK && fapi->timeout.tv_sec == -1) {
1523 continue;
1524 } else if (err != 0) {
1525 return (err);
1526 }
1527 }
1528 }
1529

--- 73 unchanged lines hidden (view full) ---

1603 kapi = (struct pps_kcbind_args *)data;
1604 /* XXX Only root should be able to do this */
1605 if (kapi->tsformat && kapi->tsformat != PPS_TSFMT_TSPEC)
1606 return (EINVAL);
1607 if (kapi->kernel_consumer != PPS_KC_HARDPPS)
1608 return (EINVAL);
1609 if (kapi->edge & ~pps->ppscap)
1610 return (EINVAL);
1593 pps->kcmode = kapi->edge;
1611 pps->kcmode = (kapi->edge & KCMODE_EDGEMASK) |
1612 (pps->kcmode & KCMODE_ABIFLAG);
1594 return (0);
1595#else
1596 return (EOPNOTSUPP);
1597#endif
1598 default:
1599 return (ENOIOCTL);
1600 }
1601}

--- 4 unchanged lines hidden (view full) ---

1606 pps->ppscap |= PPS_TSFMT_TSPEC | PPS_CANWAIT;
1607 if (pps->ppscap & PPS_CAPTUREASSERT)
1608 pps->ppscap |= PPS_OFFSETASSERT;
1609 if (pps->ppscap & PPS_CAPTURECLEAR)
1610 pps->ppscap |= PPS_OFFSETCLEAR;
1611#ifdef FFCLOCK
1612 pps->ppscap |= PPS_TSCLK_MASK;
1613#endif
1613 return (0);
1614#else
1615 return (EOPNOTSUPP);
1616#endif
1617 default:
1618 return (ENOIOCTL);
1619 }
1620}

--- 4 unchanged lines hidden (view full) ---

1625 pps->ppscap |= PPS_TSFMT_TSPEC | PPS_CANWAIT;
1626 if (pps->ppscap & PPS_CAPTUREASSERT)
1627 pps->ppscap |= PPS_OFFSETASSERT;
1628 if (pps->ppscap & PPS_CAPTURECLEAR)
1629 pps->ppscap |= PPS_OFFSETCLEAR;
1630#ifdef FFCLOCK
1631 pps->ppscap |= PPS_TSCLK_MASK;
1632#endif
1633 pps->kcmode &= ~KCMODE_ABIFLAG;
1614}
1615
1616void
1634}
1635
1636void
1637pps_init_abi(struct pps_state *pps)
1638{
1639
1640 pps_init(pps);
1641 if (pps->driver_abi > 0) {
1642 pps->kcmode |= KCMODE_ABIFLAG;
1643 pps->kernel_abi = PPS_ABI_VERSION;
1644 }
1645}
1646
1647void
1617pps_capture(struct pps_state *pps)
1618{
1619 struct timehands *th;
1620
1621 KASSERT(pps != NULL, ("NULL pps pointer in pps_capture"));
1622 th = timehands;
1623 pps->capgen = th->th_generation;
1624 pps->capth = th;

--- 417 unchanged lines hidden ---
1648pps_capture(struct pps_state *pps)
1649{
1650 struct timehands *th;
1651
1652 KASSERT(pps != NULL, ("NULL pps pointer in pps_capture"));
1653 th = timehands;
1654 pps->capgen = th->th_generation;
1655 pps->capth = th;

--- 417 unchanged lines hidden ---