Deleted Added
full compact
kern_tc.c (246037) kern_tc.c (246845)
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 246037 2013-01-28 19:38:13Z jhb $");
17__FBSDID("$FreeBSD: head/sys/kern/kern_tc.c 246845 2013-02-15 18:30:32Z 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#ifdef FFCLOCK

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

1441
1442SYSCTL_PROC(_kern_timecounter, OID_AUTO, choice, CTLTYPE_STRING | CTLFLAG_RD,
1443 0, 0, sysctl_kern_timecounter_choice, "A", "Timecounter hardware detected");
1444
1445/*
1446 * RFC 2783 PPS-API implementation.
1447 */
1448
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#ifdef FFCLOCK

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

1441
1442SYSCTL_PROC(_kern_timecounter, OID_AUTO, choice, CTLTYPE_STRING | CTLFLAG_RD,
1443 0, 0, sysctl_kern_timecounter_choice, "A", "Timecounter hardware detected");
1444
1445/*
1446 * RFC 2783 PPS-API implementation.
1447 */
1448
1449static int
1450pps_fetch(struct pps_fetch_args *fapi, struct pps_state *pps)
1451{
1452 int err, timo;
1453 pps_seq_t aseq, cseq;
1454 struct timeval tv;
1455
1456 if (fapi->tsformat && fapi->tsformat != PPS_TSFMT_TSPEC)
1457 return (EINVAL);
1458
1459 /*
1460 * If no timeout is requested, immediately return whatever values were
1461 * most recently captured. If timeout seconds is -1, that's a request
1462 * to block without a timeout. WITNESS won't let us sleep forever
1463 * without a lock (we really don't need a lock), so just repeatedly
1464 * sleep a long time.
1465 */
1466 if (fapi->timeout.tv_sec || fapi->timeout.tv_nsec) {
1467 if (fapi->timeout.tv_sec == -1)
1468 timo = 0x7fffffff;
1469 else {
1470 tv.tv_sec = fapi->timeout.tv_sec;
1471 tv.tv_usec = fapi->timeout.tv_nsec / 1000;
1472 timo = tvtohz(&tv);
1473 }
1474 aseq = pps->ppsinfo.assert_sequence;
1475 cseq = pps->ppsinfo.clear_sequence;
1476 while (aseq == pps->ppsinfo.assert_sequence &&
1477 cseq == pps->ppsinfo.clear_sequence) {
1478 err = tsleep(pps, PCATCH, "ppsfch", timo);
1479 if (err == EWOULDBLOCK && fapi->timeout.tv_sec == -1) {
1480 continue;
1481 } else if (err != 0) {
1482 return (err);
1483 }
1484 }
1485 }
1486
1487 pps->ppsinfo.current_mode = pps->ppsparam.mode;
1488 fapi->pps_info_buf = pps->ppsinfo;
1489
1490 return (0);
1491}
1492
1449int
1450pps_ioctl(u_long cmd, caddr_t data, struct pps_state *pps)
1451{
1452 pps_params_t *app;
1453 struct pps_fetch_args *fapi;
1454#ifdef FFCLOCK
1455 struct pps_fetch_ffc_args *fapi_ffc;
1456#endif

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

1480 *app = pps->ppsparam;
1481 app->api_version = PPS_API_VERS_1;
1482 return (0);
1483 case PPS_IOC_GETCAP:
1484 *(int*)data = pps->ppscap;
1485 return (0);
1486 case PPS_IOC_FETCH:
1487 fapi = (struct pps_fetch_args *)data;
1493int
1494pps_ioctl(u_long cmd, caddr_t data, struct pps_state *pps)
1495{
1496 pps_params_t *app;
1497 struct pps_fetch_args *fapi;
1498#ifdef FFCLOCK
1499 struct pps_fetch_ffc_args *fapi_ffc;
1500#endif

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

1524 *app = pps->ppsparam;
1525 app->api_version = PPS_API_VERS_1;
1526 return (0);
1527 case PPS_IOC_GETCAP:
1528 *(int*)data = pps->ppscap;
1529 return (0);
1530 case PPS_IOC_FETCH:
1531 fapi = (struct pps_fetch_args *)data;
1488 if (fapi->tsformat && fapi->tsformat != PPS_TSFMT_TSPEC)
1489 return (EINVAL);
1490 if (fapi->timeout.tv_sec || fapi->timeout.tv_nsec)
1491 return (EOPNOTSUPP);
1492 pps->ppsinfo.current_mode = pps->ppsparam.mode;
1493 fapi->pps_info_buf = pps->ppsinfo;
1494 return (0);
1532 return (pps_fetch(fapi, pps));
1495#ifdef FFCLOCK
1496 case PPS_IOC_FETCH_FFCOUNTER:
1497 fapi_ffc = (struct pps_fetch_ffc_args *)data;
1498 if (fapi_ffc->tsformat && fapi_ffc->tsformat !=
1499 PPS_TSFMT_TSPEC)
1500 return (EINVAL);
1501 if (fapi_ffc->timeout.tv_sec || fapi_ffc->timeout.tv_nsec)
1502 return (EOPNOTSUPP);

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

1535 default:
1536 return (ENOIOCTL);
1537 }
1538}
1539
1540void
1541pps_init(struct pps_state *pps)
1542{
1533#ifdef FFCLOCK
1534 case PPS_IOC_FETCH_FFCOUNTER:
1535 fapi_ffc = (struct pps_fetch_ffc_args *)data;
1536 if (fapi_ffc->tsformat && fapi_ffc->tsformat !=
1537 PPS_TSFMT_TSPEC)
1538 return (EINVAL);
1539 if (fapi_ffc->timeout.tv_sec || fapi_ffc->timeout.tv_nsec)
1540 return (EOPNOTSUPP);

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

1573 default:
1574 return (ENOIOCTL);
1575 }
1576}
1577
1578void
1579pps_init(struct pps_state *pps)
1580{
1543 pps->ppscap |= PPS_TSFMT_TSPEC;
1581 pps->ppscap |= PPS_TSFMT_TSPEC | PPS_CANWAIT;
1544 if (pps->ppscap & PPS_CAPTUREASSERT)
1545 pps->ppscap |= PPS_OFFSETASSERT;
1546 if (pps->ppscap & PPS_CAPTURECLEAR)
1547 pps->ppscap |= PPS_OFFSETCLEAR;
1548#ifdef FFCLOCK
1549 pps->ppscap |= PPS_TSCLK_MASK;
1550#endif
1551}

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

1675 scale *= 2;
1676 bt.sec = 0;
1677 bt.frac = 0;
1678 bintime_addx(&bt, scale * tcount);
1679 bintime2timespec(&bt, &ts);
1680 hardpps(tsp, ts.tv_nsec + 1000000000 * ts.tv_sec);
1681 }
1682#endif
1582 if (pps->ppscap & PPS_CAPTUREASSERT)
1583 pps->ppscap |= PPS_OFFSETASSERT;
1584 if (pps->ppscap & PPS_CAPTURECLEAR)
1585 pps->ppscap |= PPS_OFFSETCLEAR;
1586#ifdef FFCLOCK
1587 pps->ppscap |= PPS_TSCLK_MASK;
1588#endif
1589}

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

1713 scale *= 2;
1714 bt.sec = 0;
1715 bt.frac = 0;
1716 bintime_addx(&bt, scale * tcount);
1717 bintime2timespec(&bt, &ts);
1718 hardpps(tsp, ts.tv_nsec + 1000000000 * ts.tv_sec);
1719 }
1720#endif
1721
1722 /* Wakeup anyone sleeping in pps_fetch(). */
1723 wakeup(pps);
1683}
1684
1685/*
1686 * Timecounters need to be updated every so often to prevent the hardware
1687 * counter from overflowing. Updating also recalculates the cached values
1688 * used by the get*() family of functions, so their precision depends on
1689 * the update frequency.
1690 */

--- 240 unchanged lines hidden ---
1724}
1725
1726/*
1727 * Timecounters need to be updated every so often to prevent the hardware
1728 * counter from overflowing. Updating also recalculates the cached values
1729 * used by the get*() family of functions, so their precision depends on
1730 * the update frequency.
1731 */

--- 240 unchanged lines hidden ---