2 #include "../port/lib.h"
8 * Mailbox interface with videocore gpu
11 #define MAILBOX (VIRTIO+0xB880)
13 typedef struct Prophdr Prophdr;
14 typedef struct Fbinfo Fbinfo;
35 TagGetfwrev = 0x00000001,
36 TagGetbrdrev = 0x00010002,
37 TagGetmac = 0x00010003,
38 TagGetram = 0x00010005,
39 TagGetpower = 0x00020001,
40 TagSetpower = 0x00028001,
42 TagGetclkspd= 0x00030002,
43 TagFballoc = 0x00040001,
44 TagFbfree = 0x00048001,
45 TagFbblank = 0x00040002,
46 TagGetres = 0x00040003,
47 TagSetres = 0x00048003,
48 TagGetvres = 0x00040004,
49 TagSetvres = 0x00048004,
50 TagGetdepth = 0x00040005,
51 TagSetdepth = 0x00048005,
52 TagGetrgb = 0x00044006,
53 TagSetrgb = 0x00048006,
61 u32int pitch; /* returned by gpu */
65 u32int base; /* returned by gpu */
66 u32int screensize; /* returned by gpu */
80 vcwrite(uint chan, int val)
84 r = (u32int*)MAILBOX + NRegs;
89 r[Write] = val | chan;
100 while(r[Status]&Empty)
104 }while((x&ChanMask) != chan);
105 return x & ~ChanMask;
113 vcreq(int tag, void *buf, int vallen, int rsplen)
118 static uintptr base = BUSDRAM;
122 rsplen = (rsplen+3) & ~3;
123 prop = (Prophdr*)(VCBUFFER);
124 n = sizeof(Prophdr) + rsplen + 8;
129 prop->tagbuflen = rsplen;
130 prop->taglen = vallen;
132 memmove(prop->data, buf, vallen);
133 cachedwbinvse(prop, prop->len);
135 vcwrite(ChanProps, PADDR(prop) + base);
136 r = vcread(ChanProps);
137 if(r == PADDR(prop) + base)
143 if(prop->req == RspOk && prop->tag == tag && prop->taglen & TagResp) {
144 if((n = prop->taglen & ~TagResp) < rsplen)
146 memmove(buf, prop->data, rsplen);
158 fbdefault(int *width, int *height, int *depth)
162 if(vcreq(TagGetres, &buf[0], 0, 2*4) != 2*4 ||
163 vcreq(TagGetdepth, &buf[2], 0, 4) != 4)
172 fbinit(int set, int *width, int *height, int *depth)
178 fbdefault(width, height, depth);
179 /* Screen width must be a multiple of 16 */
181 fi = (Fbinfo*)(VCBUFFER);
182 memset(fi, 0, sizeof(*fi));
183 fi->xres = fi->xresvirtual = *width;
184 fi->yres = fi->yresvirtual = *height;
186 cachedwbinvse(fi, sizeof(*fi));
187 vcwrite(ChanFb, DMAADDR(fi));
188 if(vcread(ChanFb) != 0)
190 va = mmukmap(FRAMEBUFFER, PADDR(fi->base), fi->screensize);
192 memset((char*)va, 0x7F, fi->screensize);
202 if(vcreq(TagFbblank, buf, sizeof buf, sizeof buf) != sizeof buf)
211 setpower(int dev, int on)
216 buf[1] = Powerwait | (on? 1: 0);
217 vcreq(TagSetpower, buf, sizeof buf, sizeof buf);
227 if(vcreq(TagGetpower, buf, sizeof buf[0], sizeof buf) != sizeof buf)
233 * Get ethernet address (as hex string)
244 memset(ea, 0, sizeof ea);
245 vcreq(TagGetmac, ea, 0, sizeof ea);
247 for(i = 0; i < 6; i++)
248 p += sprint(p, "%.2x", ea[i]);
253 * Get firmware revision
260 if(vcreq(TagGetfwrev, buf, 0, sizeof buf) != sizeof buf)
269 if(vcreq(TagGetbrdrev, buf, 0, sizeof buf) != sizeof buf)
278 getramsize(Confmem *mem)
282 if(vcreq(TagGetram, buf, 0, sizeof buf) != sizeof buf)
292 getclkrate(int clkid)
297 if(vcreq(TagGetclkspd, buf, sizeof(buf[0]), sizeof(buf)) != sizeof buf)
307 if(vcreq(0x00030006, buf, sizeof(buf[0]), sizeof(buf)) != sizeof buf)