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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "../port/error.h"
#include "io.h"
enum {
Qdir = 0,
Qbase,
Qmax = 16,
};
typedef long Rdwrfn(Chan*, void*, long, vlong);
static Rdwrfn *readfn[Qmax];
static Rdwrfn *writefn[Qmax];
static Dirtab archdir[Qmax] = {
".", { Qdir, 0, QTDIR }, 0, 0555,
};
Lock archwlock; /* the lock is only for changing archdir */
int narchdir = Qbase;
/*
* Add a file to the #P listing. Once added, you can't delete it.
* You can't add a file with the same name as one already there,
* and you get a pointer to the Dirtab entry so you can do things
* like change the Qid version. Changing the Qid path is disallowed.
*/
Dirtab*
addarchfile(char *name, int perm, Rdwrfn *rdfn, Rdwrfn *wrfn)
{
int i;
Dirtab d;
Dirtab *dp;
memset(&d, 0, sizeof d);
strcpy(d.name, name);
d.perm = perm;
lock(&archwlock);
if(narchdir >= Qmax){
unlock(&archwlock);
return nil;
}
for(i=0; i<narchdir; i++)
if(strcmp(archdir[i].name, name) == 0){
unlock(&archwlock);
return nil;
}
d.qid.path = narchdir;
archdir[narchdir] = d;
readfn[narchdir] = rdfn;
writefn[narchdir] = wrfn;
dp = &archdir[narchdir++];
unlock(&archwlock);
return dp;
}
static Chan*
archattach(char* spec)
{
return devattach('P', spec);
}
Walkqid*
archwalk(Chan* c, Chan *nc, char** name, int nname)
{
return devwalk(c, nc, name, nname, archdir, narchdir, devgen);
}
static int
archstat(Chan* c, uchar* dp, int n)
{
return devstat(c, dp, n, archdir, narchdir, devgen);
}
static Chan*
archopen(Chan* c, int omode)
{
return devopen(c, omode, archdir, narchdir, devgen);
}
static void
archclose(Chan*)
{
}
static long
archread(Chan *c, void *a, long n, vlong offset)
{
Rdwrfn *fn;
switch((ulong)c->qid.path){
case Qdir:
return devdirread(c, a, n, archdir, narchdir, devgen);
default:
if(c->qid.path < narchdir && (fn = readfn[c->qid.path]))
return fn(c, a, n, offset);
error(Eperm);
break;
}
return 0;
}
static long
archwrite(Chan *c, void *a, long n, vlong offset)
{
Rdwrfn *fn;
if(c->qid.path < narchdir && (fn = writefn[c->qid.path]))
return fn(c, a, n, offset);
error(Eperm);
return 0;
}
void archinit(void);
Dev archdevtab = {
'P',
"arch",
devreset,
archinit,
devshutdown,
archattach,
archwalk,
archstat,
archopen,
devcreate,
archclose,
archread,
devbread,
archwrite,
devbwrite,
devremove,
devwstat,
};
static long
cputyperead(Chan*, void *a, long n, vlong offset)
{
char name[64], str[128];
cputype2name(name, sizeof name);
snprint(str, sizeof str, "ARM %s %d\n", name, m->cpumhz);
return readstr(offset, a, n, str);
}
static long
cputempread(Chan*, void *a, long n, vlong offset)
{
char str[32];
uint t = getcputemp();
snprint(str, sizeof str, "%ud.%ud\n", t/1000, t%1000);
return readstr(offset, a, n, str);
}
void
archinit(void)
{
addarchfile("cputype", 0444, cputyperead, nil);
addarchfile("cputemp", 0444, cputempread, nil);
}
void
uartconsinit(void)
{
extern PhysUart *physuart[];
char *p, *cmd;
Uart *uart;
int i, n;
if((p = getconf("console")) == nil)
return;
i = strtoul(p, &cmd, 0);
if(p == cmd)
return;
/* we only have two possible uarts, the pl011 and aux */
for(n = 0; physuart[n] != nil; n++)
;
if(i < 0 || i >= n)
return;
uart = physuart[i]->pnp();
if(!uart->enabled)
(*uart->phys->enable)(uart, 0);
uartctl(uart, "l8 pn s1");
if(*cmd != '\0')
uartctl(uart, cmd);
uart->console = 1;
consuart = uart;
uartputs(kmesg.buf, kmesg.n);
}
void
okay(int on)
{
static int first;
static int okled, polarity;
char *p;
if(!first++){
p = getconf("bcm2709.disk_led_gpio");
if(p == nil)
p = getconf("bcm2708.disk_led_gpio");
if(p != nil)
okled = strtol(p, 0, 0);
else
okled = 'v';
p = getconf("bcm2709.disk_led_active_low");
if(p == nil)
p = getconf("bcm2708.disk_led_active_low");
polarity = (p == nil || *p == '1');
if(okled != 'v')
gpiosel(okled, Output);
}
if(okled == 'v')
vgpset(0, on);
else if(okled != 0)
gpioout(okled, on^polarity);
}
|