11 #define IOBASEADDR 0x20000000
13 #define IOBASEADDR 0x3f000000
16 #define phys2bus(addr) ((addr) | 0x40000000)
17 #define bus2phys(addr) ((addr) & 0x3fffffff)
19 #define IOREG_ADDR(x) (IOBASEADDR | (x))
20 #define REG_MB_READ *((volatile uint32_t*)IOREG_ADDR(0xb880))
21 #define REG_MB_STAT *((volatile uint32_t*)IOREG_ADDR(0xb898))
22 #define REG_MB_WRITE *((volatile uint32_t*)IOREG_ADDR(0xb8a0))
24 #define MB_STAT_FULL 0x80000000
25 #define MB_STAT_EMPTY 0x40000000
27 #define MB_CHAN_FRAMEBUF 1
28 #define MB_CHAN_PROP 8
30 #define PROP_CODE_REQ 0
31 #define PROP_RESP_OK 0x80000000
34 #define PROP_TAG_END 0
36 #define PROP_TAG_SET 0x08000
37 #define PROP_TAG_TEST 0x04000
38 #define PROP_TAG_GET 0
40 #define PROP_TAG_ALLOCBUF 0x40001
41 #define PROP_TAG_BLANKSCR 0x40002
42 #define PROP_TAG_PHYSRES 0x40003
43 #define PROP_TAG_VIRTRES 0x40004
44 #define PROP_TAG_DEPTH 0x40005
45 #define PROP_TAG_PIXEL_ORDER 0x40006
46 #define PROP_TAG_ALPHA_MODE 0x40007
47 #define PROP_TAG_PITCH 0x40008
48 #define PROP_TAG_VOFFS 0x40009
49 #define PROP_TAG_OVERSCAN 0x4000a
50 #define PROP_TAG_PALETTE 0x4000b
51 #define PROP_TAG_CUR_INFO 0x00010
52 #define PROP_TAG_CUR_STATE 0x00011
56 static int send_prop(uint32_t *buf);
57 int prop_blankscr(int onoff);
58 int prop_setres(int xsz, int ysz);
59 int prop_getres(int *xsz, int *ysz);
60 int prop_setvres(int xsz, int ysz);
61 int prop_getvres(int *xsz, int *ysz);
62 int prop_setdepth(int bpp);
63 int prop_getdepth(void);
64 int prop_getpitch(void);
65 void *prop_allocbuf(int *size);
67 uint32_t mb_read(int chan);
68 void mb_write(int chan, uint32_t val);
73 uint32_t propbuf[64] __attribute__((aligned(16)));
74 uint32_t premade[] __attribute__((aligned(16))) = {
77 0x00048003, 8, 0, WIDTH, HEIGHT, /* set phys */
78 0x00048004, 8, 0, WIDTH, HEIGHT, /* set virt */
79 0x00048005, 4, 0, BPP, /* set depth */
87 int i, j, bpp, fbsize, pitch, xsz, ysz;
91 unsigned char *fb, *fbptr;
99 ser_printstr("starting rpkern\n");
101 /*if(send_prop(premade) == -1) panic();*/
103 /*if(prop_setres(WIDTH, HEIGHT) == -1) panic();*/
104 if(prop_setvres(WIDTH, HEIGHT) == -1) panic();
105 if(prop_setdepth(BPP) == -1) panic();
106 if(!(fb = prop_allocbuf(&fbsize))) panic();
108 prop_getvres(&xsz, &ysz);
109 bpp = prop_getdepth();
110 pitch = prop_getpitch();
112 if(xsz != WIDTH || ysz != HEIGHT) panic();
113 if(bpp != BPP) panic();
116 for(i=0; i<HEIGHT; i++) {
117 for(j=0; j<WIDTH; j++) {
119 int r = (xor >> 1) & 0xff;
121 int b = (xor << 1) & 0xff;
124 *fbptr++ = ((r << 8) & 0xf800) | ((g << 3) & 0x7e0) | ((b >> 3) & 0x1f);
130 *fbptr++ = ((r << 16) & 0xff0000) | ((g << 8) & 0xff00) | (b & 0xff);
134 //fbptr += pitch / 2 - 640;
148 static int send_prop(uint32_t *buf)
151 mb_write(MB_CHAN_PROP, (uint32_t)buf >> 4);
152 mb_read(MB_CHAN_PROP);
154 return propbuf[1] == PROP_RESP_OK ? 0 : -1;
157 int prop_blankscr(int onoff)
159 uint32_t *pb = propbuf;
163 *pb++ = PROP_TAG_BLANKSCR;
164 *pb++ = 4; /* data size */
165 *pb++ = PROP_CODE_REQ;
166 *pb++ = onoff ? 1 : 0;
167 *pb++ = PROP_TAG_END;
168 *pb++ = 0; /* padding */
170 return send_prop(propbuf);
173 int prop_setres(int xsz, int ysz)
175 uint32_t *pb = propbuf;
179 *pb++ = PROP_TAG_PHYSRES | PROP_TAG_SET;
180 *pb++ = 8; /* data size */
181 *pb++ = PROP_CODE_REQ;
184 *pb++ = PROP_TAG_END;
186 return send_prop(propbuf);
189 int prop_getres(int *xsz, int *ysz)
191 uint32_t *pb = propbuf;
196 *pb++ = PROP_TAG_PHYSRES;
198 *pb++ = PROP_CODE_REQ;
202 *pb++ = PROP_TAG_END;
204 if(send_prop(propbuf) == -1) {
212 int prop_setvres(int xsz, int ysz)
214 uint32_t *pb = propbuf;
218 *pb++ = PROP_TAG_VIRTRES | PROP_TAG_SET;
219 *pb++ = 8; /* data size */
220 *pb++ = PROP_CODE_REQ;
223 *pb++ = PROP_TAG_END;
225 return send_prop(propbuf);
228 int prop_getvres(int *xsz, int *ysz)
230 uint32_t *pb = propbuf;
235 *pb++ = PROP_TAG_VIRTRES;
237 *pb++ = PROP_CODE_REQ;
241 *pb++ = PROP_TAG_END;
243 if(send_prop(propbuf) == -1) {
251 int prop_setdepth(int bpp)
253 uint32_t *pb = propbuf;
257 *pb++ = PROP_TAG_DEPTH | PROP_TAG_SET;
259 *pb++ = PROP_CODE_REQ;
261 *pb++ = PROP_TAG_END;
262 *pb++ = 0; /* padding */
264 return send_prop(propbuf);
267 int prop_getdepth(void)
269 uint32_t *pb = propbuf;
274 *pb++ = PROP_TAG_DEPTH;
275 *pb++ = 4; /* data size */
276 *pb++ = PROP_CODE_REQ;
279 *pb++ = PROP_TAG_END;
280 *pb++ = 0; /* padding */
282 if(send_prop(propbuf) == -1) {
288 int prop_getpitch(void)
290 uint32_t *pb = propbuf;
295 *pb++ = PROP_TAG_PITCH;
296 *pb++ = 4; /* data size */
297 *pb++ = PROP_CODE_REQ;
300 *pb++ = PROP_TAG_END;
301 *pb++ = 0; /* padding */
303 if(send_prop(propbuf) == -1) {
309 void *prop_allocbuf(int *size)
311 uint32_t *pb = propbuf;
316 *pb++ = PROP_TAG_ALLOCBUF;
317 *pb++ = 8; /* data size */
318 *pb++ = PROP_CODE_REQ;
320 *pb++ = 16; /* alignment */
322 *pb++ = PROP_TAG_END;
324 if(send_prop(propbuf) == -1) {
328 return (void*)bus2phys(data[0]);
331 uint32_t mb_read(int chan)
336 while(REG_MB_STAT & MB_STAT_EMPTY);
339 } while((val & 0xf) != chan);
343 void mb_write(int chan, uint32_t val)
346 while(REG_MB_STAT & MB_STAT_FULL) {
349 REG_MB_WRITE = (val << 4) | chan;