-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathchardev.txt
93 lines (69 loc) · 2.55 KB
/
chardev.txt
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
90
91
92
print_hex_dump_bytes - need dev_dbg_print_hex_dump_bytes()
What we have today:
extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *);
extern int register_chrdev_region(dev_t, unsigned, const char *);
extern int __register_chrdev(unsigned int major, unsigned int baseminor,
unsigned int count, const char *name,
const struct file_operations *fops);
extern void __unregister_chrdev(unsigned int major, unsigned int baseminor,
unsigned int count, const char *name);
extern void unregister_chrdev_region(dev_t, unsigned);
extern void chrdev_show(struct seq_file *,off_t);
static inline int register_chrdev(unsigned int major, const char *name,
const struct file_operations *fops)
{
return __register_chrdev(major, 0, 256, name, fops);
}
static inline void unregister_chrdev(unsigned int major, const char *name)
{
__unregister_chrdev(major, 0, 256, name);
}
Then there is the whole cdev.h stuff:
cdev_init(struct cdev *, const struct file_operations)
cdev_alloc(void)
cdev_del(struct cdev *)
cdev_add(struct cdev *, dev_t, unsigned)
What we want:
Register a char dev for a region and assign it a file operations.
Unregister the region.
That's it.
Need:
fops
owner of module (different at times from fops)
major/minor range, or dynamic
name (for /proc)
Watch out, i_cdev is a cdev in the inode, and it can be embedded within
something else that grabs it when open() is called, so we need to know
the size of struct cdev in drivers, it can't just be a "token".
Today:
register needs:
cdev_init
cdev_add
register_chrdev_region, with same options as cdev_add() had
unregister:
cdev_del
unregister_chrdev_region
register_chrdev() and unregister_chrdev() are the "simple" ones, need to
combine cdev with those somehow to make things easier for poeple to keep
from the cdev_init/add/del mess.
Unless we really want to force everyone to do this? It might be nicer...
Proposal:
cdev * cdev_create(major, minor, fops, name, private);
cdev_destroy(* cdev);
Can break cdev_create() into two parts:
cdev_init()
cdev_register()
then after cdev_init(), can do "special" things if needed:
- different module owner
- different private
- anything else?
TODO - talk with Kay about better names
set inode pointer to be cdev *.
once have cdev *:
void *cdev_private(cdev *)
gets private back
- can get anything else back with accessor function, not
direct as we don't want to expose structure to
anything outside of the cdev core to prevent people
from poking with things directly. But is this really
good?