aboutsummaryrefslogtreecommitdiffstats
path: root/include/litmus/ftdev.h
blob: 348387e9adf94cde662658c33a427c40eb563674 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef _LITMUS_FTDEV_H_
#define	_LITMUS_FTDEV_H_

#include <litmus/feather_trace.h>
#include <litmus/feather_buffer.h>
#include <linux/mutex.h>
#include <linux/cdev.h>

#define FTDEV_ENABLE_CMD 	0
#define FTDEV_DISABLE_CMD 	1

struct ftdev;

/* return 0 if buffer can be opened, otherwise -$REASON */
typedef int  (*ftdev_can_open_t)(struct ftdev* dev, unsigned int buf_no);
/* return 0 on success, otherwise -$REASON */
typedef int  (*ftdev_alloc_t)(struct ftdev* dev, unsigned int buf_no);
typedef void (*ftdev_free_t)(struct ftdev* dev, unsigned int buf_no);


struct ftdev_event;

struct ftdev_minor {
	struct ft_buffer*	buf;
	unsigned int		readers;
	struct mutex		lock;
	/* FIXME: filter for authorized events */
	struct ftdev_event*	events;
	struct device*		device;
};

struct ftdev {
	dev_t			major;
	struct cdev		cdev;
	struct class*		class;
	const char*		name;
	struct ftdev_minor*	minor;
	unsigned int		minor_cnt;
	ftdev_alloc_t		alloc;
	ftdev_free_t		free;
	ftdev_can_open_t	can_open;
};

struct ft_buffer* alloc_ft_buffer(unsigned int count, size_t size);
void free_ft_buffer(struct ft_buffer* buf);

int ftdev_init(	struct ftdev* ftdev, struct module* owner,
		const int minor_cnt, const char* name);
void ftdev_exit(struct ftdev* ftdev);
int register_ftdev(struct ftdev* ftdev);

#endif