Blame view

include/linux/posix-clock.h 3.91 KB
74ba9207e   Thomas Gleixner   treewide: Replace...
1
  /* SPDX-License-Identifier: GPL-2.0-or-later */
0606f422b   Richard Cochran   posix clocks: Int...
2
3
4
5
  /*
   * posix-clock.h - support for dynamic clock devices
   *
   * Copyright (C) 2010 OMICRON electronics GmbH
0606f422b   Richard Cochran   posix clocks: Int...
6
7
8
9
10
11
12
13
   */
  #ifndef _LINUX_POSIX_CLOCK_H_
  #define _LINUX_POSIX_CLOCK_H_
  
  #include <linux/cdev.h>
  #include <linux/fs.h>
  #include <linux/poll.h>
  #include <linux/posix-timers.h>
1791f8814   Richard Cochran   posix clocks: Rep...
14
  #include <linux/rwsem.h>
0606f422b   Richard Cochran   posix clocks: Int...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
  struct posix_clock;
  
  /**
   * struct posix_clock_operations - functional interface to the clock
   *
   * Every posix clock is represented by a character device. Drivers may
   * optionally offer extended capabilities by implementing the
   * character device methods. The character device file operations are
   * first handled by the clock device layer, then passed on to the
   * driver by calling these functions.
   *
   * @owner:          The clock driver should set to THIS_MODULE
   * @clock_adjtime:  Adjust the clock
   * @clock_gettime:  Read the current time
   * @clock_getres:   Get the clock resolution
   * @clock_settime:  Set the current time value
0606f422b   Richard Cochran   posix clocks: Int...
32
33
34
35
36
37
38
39
   * @open:           Optional character device open method
   * @release:        Optional character device release method
   * @ioctl:          Optional character device ioctl method
   * @read:           Optional character device read method
   * @poll:           Optional character device poll method
   */
  struct posix_clock_operations {
  	struct module *owner;
ead25417f   Deepa Dinamani   timex: use __kern...
40
  	int  (*clock_adjtime)(struct posix_clock *pc, struct __kernel_timex *tx);
0606f422b   Richard Cochran   posix clocks: Int...
41

d340266e1   Deepa Dinamani   time: Change posi...
42
  	int  (*clock_gettime)(struct posix_clock *pc, struct timespec64 *ts);
0606f422b   Richard Cochran   posix clocks: Int...
43

d340266e1   Deepa Dinamani   time: Change posi...
44
  	int  (*clock_getres) (struct posix_clock *pc, struct timespec64 *ts);
0606f422b   Richard Cochran   posix clocks: Int...
45
46
  
  	int  (*clock_settime)(struct posix_clock *pc,
d340266e1   Deepa Dinamani   time: Change posi...
47
  			      const struct timespec64 *ts);
0606f422b   Richard Cochran   posix clocks: Int...
48

0606f422b   Richard Cochran   posix clocks: Int...
49
50
51
  	/*
  	 * Optional character device methods:
  	 */
0606f422b   Richard Cochran   posix clocks: Int...
52
53
  	long    (*ioctl)   (struct posix_clock *pc,
  			    unsigned int cmd, unsigned long arg);
0606f422b   Richard Cochran   posix clocks: Int...
54
  	int     (*open)    (struct posix_clock *pc, fmode_t f_mode);
a3f8683bf   Al Viro   ->poll() methods ...
55
  	__poll_t (*poll)   (struct posix_clock *pc,
0606f422b   Richard Cochran   posix clocks: Int...
56
57
58
59
60
61
62
63
64
65
66
67
68
  			    struct file *file, poll_table *wait);
  
  	int     (*release) (struct posix_clock *pc);
  
  	ssize_t (*read)    (struct posix_clock *pc,
  			    uint flags, char __user *buf, size_t cnt);
  };
  
  /**
   * struct posix_clock - represents a dynamic posix clock
   *
   * @ops:     Functional interface to the clock
   * @cdev:    Character device instance for this clock
a33121e54   Vladis Dronov   ptp: fix the race...
69
   * @dev:     Pointer to the clock's device.
1791f8814   Richard Cochran   posix clocks: Rep...
70
   * @rwsem:   Protects the 'zombie' field from concurrent access.
0606f422b   Richard Cochran   posix clocks: Int...
71
   * @zombie:  If 'zombie' is true, then the hardware has disappeared.
0606f422b   Richard Cochran   posix clocks: Int...
72
73
74
75
   *
   * Drivers should embed their struct posix_clock within a private
   * structure, obtaining a reference to it during callbacks using
   * container_of().
a33121e54   Vladis Dronov   ptp: fix the race...
76
77
78
79
80
   *
   * Drivers should supply an initialized but not exposed struct device
   * to posix_clock_register(). It is used to manage lifetime of the
   * driver's private structure. It's 'release' field should be set to
   * a release function for this private structure.
0606f422b   Richard Cochran   posix clocks: Int...
81
82
83
84
   */
  struct posix_clock {
  	struct posix_clock_operations ops;
  	struct cdev cdev;
a33121e54   Vladis Dronov   ptp: fix the race...
85
  	struct device *dev;
1791f8814   Richard Cochran   posix clocks: Rep...
86
  	struct rw_semaphore rwsem;
0606f422b   Richard Cochran   posix clocks: Int...
87
  	bool zombie;
0606f422b   Richard Cochran   posix clocks: Int...
88
89
90
91
  };
  
  /**
   * posix_clock_register() - register a new clock
a33121e54   Vladis Dronov   ptp: fix the race...
92
93
94
   * @clk:   Pointer to the clock. Caller must provide 'ops' field
   * @dev:   Pointer to the initialized device. Caller must provide
   *         'release' field
0606f422b   Richard Cochran   posix clocks: Int...
95
96
97
98
99
100
101
102
   *
   * A clock driver calls this function to register itself with the
   * clock device subsystem. If 'clk' points to dynamically allocated
   * memory, then the caller must provide a 'release' function to free
   * that memory.
   *
   * Returns zero on success, non-zero otherwise.
   */
a33121e54   Vladis Dronov   ptp: fix the race...
103
  int posix_clock_register(struct posix_clock *clk, struct device *dev);
0606f422b   Richard Cochran   posix clocks: Int...
104
105
106
107
108
109
110
111
112
113
114
115
116
  
  /**
   * posix_clock_unregister() - unregister a clock
   * @clk: Clock instance previously registered via posix_clock_register()
   *
   * A clock driver calls this function to remove itself from the clock
   * device subsystem. The posix_clock itself will remain (in an
   * inactive state) until its reference count drops to zero, at which
   * point it will be deallocated with its 'release' method.
   */
  void posix_clock_unregister(struct posix_clock *clk);
  
  #endif