]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/sgi/uartarcs.c
pc/pmmc: check pci membar type
[plan9front.git] / sys / src / 9 / sgi / uartarcs.c
1 /*
2  * ARCS console.
3  */
4
5 #include "u.h"
6 #include "../port/lib.h"
7 #include "mem.h"
8 #include "dat.h"
9 #include "fns.h"
10 #include "../port/error.h"
11 #include "io.h"
12
13 extern PhysUart arcsphysuart;
14
15 static Uart arcsuart = {
16         .name = "arcs",
17         .freq = 1843200,
18         .phys = &arcsphysuart,
19 };
20
21 static Lock arcslock;
22
23 void
24 arcsputc(char c)
25 {
26         int r;
27
28         r = 0;
29         ilock(&arcslock);
30         arcs(0x6c, 1, &c, 1, &r);
31         iunlock(&arcslock);
32 }
33
34 int
35 arcsgetc(void)
36 {
37         int c, r;
38         uchar b;
39
40         r = 0;
41         c = -1;
42         ilock(&arcslock);
43         if(arcs(0x68, 0) == 0)
44         if(arcs(0x64, 0, &b, 1, &r) == 0)
45         if(r == 1)
46                 c = b;
47         iunlock(&arcslock);
48         return c;
49 }
50
51 void
52 arcsproc(void*)
53 {
54         int c;
55
56         while(waserror())
57                 ;
58         for(;;){
59                 tsleep(&up->sleep, return0, nil, 50);
60                 c = arcsgetc();
61                 if(c < 0)
62                         continue;
63                 uartrecv(&arcsuart, c);
64         }
65 }
66
67 /*
68  * Send queued output to console
69  */
70 static void
71 kick(Uart *uart)
72 {
73         int n;
74
75         for(n=0; uart->op < uart->oe || uartstageoutput(uart) > 0; uart->op += n){
76                 n = uart->oe - uart->op;
77                 if(n <= 0 || !canlock(&arcslock))
78                         break;
79                 if(arcs(0x6c, 1, uart->op, n, &n) != 0)
80                         n = -1;
81                 unlock(&arcslock);
82                 if(n <= 0)
83                         break;
84         }
85 }
86
87 static void
88 interrupt(Ureg*, void *)
89 {
90 }
91
92 static Uart*
93 pnp(void)
94 {
95         return &arcsuart;
96 }
97
98 static void
99 enable(Uart*, int)
100 {
101 }
102
103 static void
104 disable(Uart*)
105 {
106 }
107
108 static void
109 donothing(Uart*, int)
110 {
111 }
112
113 static int
114 donothingint(Uart*, int)
115 {
116         return 0;
117 }
118
119 static int
120 baud(Uart *uart, int n)
121 {
122         if(n <= 0)
123                 return -1;
124
125         uart->baud = n;
126         return 0;
127 }
128
129 static int
130 bits(Uart *uart, int n)
131 {
132         switch(n){
133         case 7:
134         case 8:
135                 break;
136         default:
137                 return -1;
138         }
139
140         uart->bits = n;
141         return 0;
142 }
143
144 static int
145 stop(Uart *uart, int n)
146 {
147         if(n != 1)
148                 return -1;
149         uart->stop = n;
150         return 0;
151 }
152
153 static int
154 parity(Uart *uart, int n)
155 {
156         if(n != 'n')
157                 return -1;
158         uart->parity = n;
159         return 0;
160 }
161
162 static long
163 status(Uart *, void *, long, long)
164 {
165         return 0;
166 }
167
168 void
169 uartarcsputc(Uart*, int c)
170 {
171         arcsputc(c);
172 }
173
174 int
175 uartarcsgetc(Uart*)
176 {
177         return arcsgetc();
178 }
179
180 PhysUart arcsphysuart = {
181         .name           = "arcsuart",
182
183         .pnp            = pnp,
184         .enable         = enable,
185         .disable        = disable,
186         .kick           = kick,
187         .dobreak        = donothing,
188         .baud           = baud,
189         .bits           = bits,
190         .stop           = stop,
191         .parity         = parity,
192         .modemctl       = donothing,
193         .rts            = donothing,
194         .dtr            = donothing,
195         .status         = status,
196         .fifo           = donothing,
197
198         .getc           = uartarcsgetc,
199         .putc           = uartarcsputc,
200 };
201
202 void
203 arcsconsinit(void)
204 {
205         consuart = &arcsuart;
206         consuart->console = 1;
207 }