2 #include "../port/lib.h"
6 #include "../port/error.h"
18 typedef long Rdwrfn(Chan*, void*, long, vlong);
20 static Rdwrfn *readfn[Qmax];
21 static Rdwrfn *writefn[Qmax];
23 static Dirtab archdir[Qmax] = {
24 ".", { Qdir, 0, QTDIR }, 0, 0555,
27 Lock archwlock; /* the lock is only for changing archdir */
31 * Add a file to the #P listing. Once added, you can't delete it.
32 * You can't add a file with the same name as one already there,
33 * and you get a pointer to the Dirtab entry so you can do things
34 * like change the Qid version. Changing the Qid path is disallowed.
37 addarchfile(char *name, int perm, Rdwrfn *rdfn, Rdwrfn *wrfn)
43 memset(&d, 0, sizeof d);
53 for(i=0; i<narchdir; i++)
54 if(strcmp(archdir[i].name, name) == 0){
59 d.qid.path = narchdir;
60 archdir[narchdir] = d;
61 readfn[narchdir] = rdfn;
62 writefn[narchdir] = wrfn;
63 dp = &archdir[narchdir++];
70 archattach(char* spec)
72 return devattach('P', spec);
76 archwalk(Chan* c, Chan *nc, char** name, int nname)
78 return devwalk(c, nc, name, nname, archdir, narchdir, devgen);
82 archstat(Chan* c, uchar* dp, int n)
84 return devstat(c, dp, n, archdir, narchdir, devgen);
88 archopen(Chan* c, int omode)
90 return devopen(c, omode, archdir, narchdir, devgen);
99 archread(Chan *c, void *a, long n, vlong offset)
103 switch((ulong)c->qid.path){
105 return devdirread(c, a, n, archdir, narchdir, devgen);
108 if(c->qid.path < narchdir && (fn = readfn[c->qid.path]))
109 return fn(c, a, n, offset);
118 archwrite(Chan *c, void *a, long n, vlong offset)
122 if(c->qid.path < narchdir && (fn = writefn[c->qid.path]))
123 return fn(c, a, n, offset);
152 /* convert AddrDevid register to a string in buf and return buf */
154 cputype2name(char *buf, int size)
156 ulong id, archid, rev;
157 char *manu, *arch, *socrev;
158 char unk[32], socnm[32], revname[32];
161 m->cputype = *(ulong *)soc.devid;
163 switch(m->cputype & 3) {
165 socnm = "88F6[12]80";
168 socnm = "88F619[02]";
178 /* strange way to get this information, but it's what u-boot does */
179 pci = (Pciex *)soc.pci;
180 snprint(socnm, sizeof socnm, "88F%ux", pci->devid);
181 /* stash rev for benefit of later usb initialisation */
182 m->socrev = rev = pci->revid & MASK(4);
185 if ((id >> 24) == 0x56 && pci->venid == 0x11ab)
189 archid = (id >> 16) & MASK(4);
195 snprint(unk, sizeof unk, "unknown (%ld)", archid);
199 if (pci->devid != 0x6281)
213 snprint(revname, sizeof revname, "unknown rev (%ld)",
218 seprint(buf, buf + size,
219 "%s %s %s; arm926ej-s arch %s rev %ld.%ld part %lux",
220 manu, socnm, socrev, arch, (id >> 20) & MASK(4),
221 id & MASK(4), (id >> 4) & MASK(12));
226 cputyperead(Chan*, void *a, long n, vlong offset)
228 char name[64], str[128];
230 cputype2name(name, sizeof name);
231 snprint(str, sizeof str, "ARM %s %llud\n", name, m->cpuhz / 1000000);
232 return readstr(offset, a, n, str);
236 tbread(Chan*, void *a, long n, vlong offset)
243 snprint(str, sizeof(str), "%16.16llux", tb);
244 return readstr(offset, a, n, str);
248 nsread(Chan*, void *a, long n, vlong offset)
255 snprint(str, sizeof(str), "%16.16llux", (tb/700)* 1000);
256 return readstr(offset, a, n, str);
262 addarchfile("cputype", 0444, cputyperead, nil);
263 addarchfile("timebase",0444, tbread, nil);
264 // addarchfile("nsec", 0444, nsread, nil);