summaryrefslogtreecommitdiffstats
path: root/main.h
blob: ecc20b633bdc6d5e3c6e51e0c9197b0fc54892bc (plain)
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
#ifndef _HELLOMAIN_H_
#define _HELLOMAIN_H_

#include <linux/cdev.h>
#include <linux/list.h>

/*
 * Macros to aid with debugging
 */
#ifdef HELLO_DEBUG
  #define PDEBUG(fmt, args...) printk( KERN_DEBUG "[hello] " fmt, ##args)
  #define PRDEBUG(fmt, args...) if (printk_ratelimit()) \
                                    printk( KERN_DEBUG "[hello] " fmt, ##args)
#else
  /* not debugging: nothing */
  #define PDEBUG(fmt, args...)
  #define PRDEBUG(fmt, args...)
#endif

#ifndef HELLO_MAJOR
#define HELLO_MAJOR 0 /* let kernel choose, unless user really defined it */
#endif

/*
 * Allow user to define size of node using a #define, or passing -D compiler
 * flag
 */
#ifndef HELLO_NODE_CHUNK_SIZE
#define HELLO_NODE_CHUNK_SIZE 256
#endif

extern int hello_major;
extern int hello_minor;

extern char *magicstr;

/* node to be used with Linux api for circular linked lists */
struct hello_ll
{
    char *chunk;
    struct list_head list;
};

struct hello_dev {
    dev_t devnum;
    struct semaphore sem;
    struct cdev cdev; /* char device */

    /* for r/w operations */
    struct hello_ll *mylist;
    int chunk_sz;
    size_t ll_size;
};

/* function prototypes */
int hello_debugfs(void);

/*
 * Ioctl definitions
 */

/* Use 'x' as magic number */
#define HELLO_IOCTL_BASE 'x'

#define HELLO_IO(nr)         _IO(HELLO_IOCTL_BASE, nr)
#define HELLO_IOR(nr, type)  _IOR(HELLO_IOCTL_BASE, nr, type)
#define HELLO_IOW(nr, type)  _IOW(HELLO_IOCTL_BASE, nr, type)
#define HELLO_IOWR(nr, type) _IOWR(HELLO_IOCTL_BASE, nr, type)

#define HELLO_IOCTL_RESET    HELLO_IO(0x00)

#define HELLO_IOCTL_SCHUNK   HELLO_IOW(0x01, int) /* write to kernel */
#define HELLO_IOCTL_TCHUNK   HELLO_IO(0x02)
#define HELLO_IOCTL_GCHUNK   HELLO_IOR(0x03, int) /* write to user */
#define HELLO_IOCTL_QCHUNK   HELLO_IO(0x04)

#define HELLO_IOCTL_MAXNR    4

#endif