summaryrefslogtreecommitdiff
path: root/kernel/include/generic/vfs/devfs.hpp
blob: b59513e87b55755fbe58e38138345cda151c3eb1 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

#include <cstdint>
#include <generic/vfs/vfs.hpp>
#include <etc/list.hpp>

#pragma once

#define DEVFS_PACKET_CREATE_DEV 1
#define DEVFS_PACKET_READ_READRING 2
#define DEVFS_PACKET_WRITE_READRING 3 
#define DEVFS_PACKET_READ_WRITERING 4 
#define DEVFS_PACKET_WRITE_WRITERING 5
#define DEVFS_PACKET_CREATE_IOCTL 6 
#define DEVFS_PACKET_SIZE_IOCTL 7
#define DEVFS_PACKET_IOCTL 8
#define DEVFS_ENABLE_PIPE 9
#define DEVFS_SETUP_MMAP 10
#define DEVFS_PACKET_CREATE_PIPE_DEV 11
#define DEVFS_PACKET_ISATTY 12 
#define DEVFS_PACKET_SETUPTTY 13
#define DEVFS_GETSLAVE_BY_MASTER 14
#define DEVFS_PACKET_SETUP_RING_SIZE 15

struct	winsize {
 	unsigned short	 	ws_row;	 
 	unsigned short	 	ws_col;	 
 	unsigned short	 	ws_xpixel;	
/* unused */
 	unsigned short	 	ws_ypixel;	
/* unused */
};

#define TCGETS                   0x5401
#define TCSETS                   0x5402
#define TIOCGWINSZ               0x5413
#define TIOCSWINSZ               0x5414

namespace vfs {

    typedef struct {
        std::uint64_t is_pipe : 1;
        std::uint64_t is_pipe_rw : 1;
    } __attribute__((packed)) devfs_pipe_p_t;

    typedef struct {
        union {
            struct {
                std::uint8_t request;
                std::uint8_t* cycle;
                std::uint32_t* queue;
                std::uint32_t size;
                std::uint64_t value;
            };
            struct {
                std::uint8_t request;
                std::uint64_t ioctlreq;
                std::uint64_t arg;
            } ioctl;
            struct {
                std::uint8_t request;
                std::uint32_t writereg;
                std::uint32_t readreg;
                std::uint32_t size;
                std::uint64_t pointer;
            } create_ioctl;
            struct {
                std::uint8_t request;
                std::uint8_t pipe_target;
                std::uint64_t pipe_pointer;
            } enable_pipe;
            struct {
                std::uint8_t request;
                std::uint64_t dma_addr;
                std::uint64_t size;
                std::uint64_t flags;
            } setup_mmap;
        };
    } __attribute__((packed)) devfs_packet_t; /* User-Kernel interaction packet */

    typedef struct {
        std::uint32_t read_req;
        std::uint32_t write_req;
        std::uint32_t size;
        void* pointer_to_struct;
    } __attribute__((packed)) devfs_ioctl_packet_t;

    typedef struct devfs_node {
        devfs_pipe_p_t open_flags;
        union {
            struct {
                Lists::Ring* readring;
                Lists::Ring* writering;
            };
            struct {
                pipe* readpipe;
                pipe* writepipe;
            };
        };
        devfs_ioctl_packet_t ioctls[32];
        std::uint64_t pipe0;
        std::uint64_t mmap_base;
        std::uint64_t mmap_size;
        std::uint64_t mmap_flags;
        std::int32_t dev_num;
        std::int8_t is_tty;

        std::int64_t (*read)(userspace_fd_t* fd, void* buffer, std::uint64_t count);
        std::int64_t (*write)(userspace_fd_t* fd, void* buffer, std::uint64_t size);

        std::int64_t (*slave_write)(userspace_fd_t* fd, void* buffer, std::uint64_t size);

        std::int32_t (*ioctl)(userspace_fd_t* fd, unsigned long req, void *arg, int *res);
        std::int32_t (*open)(userspace_fd_t* fd, char* path);
        int mode;

        termios_t* term_flags;

        struct devfs_node* next;
        char masterpath[256];
        char slavepath[256];
    } devfs_node_t;

    static_assert(sizeof(devfs_node_t) < 4096,"devfs_node_t is higher than fucking page size");

    class devfs {
    public:
        static void mount(vfs_node_t* node);
        static std::int64_t send_packet(char* path,devfs_packet_t* packet);
    };
};