move gic to new devtree interface
[lunaix-os.git] / lunaix-os / includes / hal / term.h
1 #ifndef __LUNAIX_TERM_H
2 #define __LUNAIX_TERM_H
3
4 #include <lunaix/device.h>
5 #include <lunaix/ds/rbuffer.h>
6 #include <lunaix/ds/waitq.h>
7 #include <lunaix/signal_defs.h>
8
9 #include <usr/lunaix/term.h>
10
11 struct term;
12
13 struct linebuffer
14 {
15     struct rbuffer* next;
16     struct rbuffer* current;
17     short sflags;
18     short sz_hlf;
19 };
20 #define LEVT_EOL (1)
21 #define LEVT_EOF (1 << 1)
22 #define LEVT_SIGRAISE (1 << 2)
23
24 typedef struct rbuffer** lbuf_ref_t;
25 #define ref_current(lbuf) (&(lbuf)->current)
26 #define ref_next(lbuf) (&(lbuf)->next)
27 #define deref(bref) (*(bref))
28
29 struct term;
30
31 struct termport_pot_ops
32 {
33     void (*set_speed)(struct device*, speed_t);
34     void (*set_clkbase)(struct device*, unsigned int);
35     void (*set_cntrl_mode)(struct device*, tcflag_t);
36 };
37
38 struct termport_potens
39 {
40     POTENS_META;
41     struct termport_pot_ops* ops;
42     struct term* term;
43 };
44
45 struct term
46 {
47     struct device* dev;
48     struct device* chdev;
49     struct linebuffer line_out;
50     struct linebuffer line_in;
51     char* scratch_pad;
52     pid_t fggrp;
53
54     struct termport_potens* tp_cap;
55     waitq_t line_in_event;
56
57     /* -- POSIX.1-2008 compliant fields -- */
58     tcflag_t iflags;
59     tcflag_t oflags;
60     tcflag_t lflags;
61     tcflag_t cflags;
62     cc_t cc[_NCCS];
63
64     /* -- END POSIX.1-2008 compliant fields -- */
65     speed_t iospeed;
66     speed_t clkbase;
67     tcflag_t tflags;    // temp flags
68 };
69
70 extern struct device* sysconsole;
71
72 struct termport_potens*
73 term_attach_potens(struct device* chardev, 
74                    struct termport_pot_ops* ops, char* suffix);
75
76 int
77 term_bind(struct term* tdev, struct device* chdev);
78
79 static inline void
80 line_flip(struct linebuffer* lbf)
81 {
82     struct rbuffer* tmp = lbf->current;
83     lbf->current = lbf->next;
84     lbf->next = tmp;
85 }
86
87 void
88 line_alloc(struct linebuffer* lbf, size_t sz_hlf);
89
90 void
91 line_free(struct linebuffer* lbf, size_t sz_hlf);
92
93 void
94 term_sendsig(struct term* tdev, int signal);
95
96 int
97 term_flush(struct term* tdev);
98
99 int
100 term_read(struct term* tdev);
101
102 int
103 lcntl_transform_inseq(struct term* tdev);
104
105 int
106 lcntl_transform_outseq(struct term* tdev);
107
108 void
109 term_notify_data_avaliable(struct termport_potens* cap);
110
111 #endif /* __LUNAIX_TERM_H */