aboutsummaryrefslogtreecommitdiffstats
path: root/include/litmus/fdso.h
blob: 1469c0fd0460d2080cf27a84a39e147454df0db6 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* fdso.h - file descriptor attached shared objects
 *
 * (c) 2007 B. Brandenburg, LITMUS^RT project
 */

#ifndef _LINUX_FDSO_H_
#define _LINUX_FDSO_H_

#include <linux/list.h>
#include <asm/atomic.h>

#include <linux/fs.h>
#include <linux/slab.h>

#define MAX_OBJECT_DESCRIPTORS 85

typedef enum  {
	MIN_OBJ_TYPE 	= 0,

	FMLP_SEM	= 0,
	SRP_SEM		= 1,

	MPCP_SEM	= 2,
	MPCP_VS_SEM	= 3,
	DPCP_SEM	= 4,

	PCP_SEM     = 5,

	RSM_MUTEX	= 6,
	IKGLP_SEM	= 7,
	KFMLP_SEM	= 8,

	IKGLP_SIMPLE_GPU_AFF_OBS	= 9,
	IKGLP_GPU_AFF_OBS			= 10,
	KFMLP_SIMPLE_GPU_AFF_OBS	= 11,
	KFMLP_GPU_AFF_OBS			= 12,

	MAX_OBJ_TYPE	= 12
} obj_type_t;

struct inode_obj_id {
	struct list_head	list;
	atomic_t		count;
	struct inode*		inode;

	obj_type_t 		type;
	void*			obj;
	unsigned int		id;
};

struct fdso_ops;

struct od_table_entry {
	unsigned int		used;

	struct inode_obj_id*	obj;
	const struct fdso_ops*	class;
};

struct fdso_ops {
	int   (*create)(void** obj_ref, obj_type_t type, void* __user);
	void  (*destroy)(obj_type_t type, void*);
	int   (*open)	(struct od_table_entry*, void* __user);
	int   (*close)	(struct od_table_entry*);
};

/* translate a userspace supplied od into the raw table entry
 * returns NULL if od is invalid
 */
struct od_table_entry* get_entry_for_od(int od);

/* translate a userspace supplied od into the associated object
 * returns NULL if od is invalid
 */
static inline void* od_lookup(int od, obj_type_t type)
{
	struct od_table_entry* e = get_entry_for_od(od);
	return e && e->obj->type == type ? e->obj->obj : NULL;
}

#define lookup_fmlp_sem(od)((struct pi_semaphore*)  od_lookup(od, FMLP_SEM))
#define lookup_kfmlp_sem(od)((struct pi_semaphore*)  od_lookup(od, KFMLP_SEM))
#define lookup_srp_sem(od) ((struct srp_semaphore*) od_lookup(od, SRP_SEM))
#define lookup_ics(od)     ((struct ics*)           od_lookup(od, ICS_ID))

#define lookup_rsm_mutex(od)((struct litmus_lock*)  od_lookup(od, FMLP_SEM))


#endif