property tags
[rpikern] / src / main.c
1 /* mailbox registers (MB 0: input  1: output)
2  * function | MB 0 | MB 1
3  *  rd/wr   | 00   | 20      ( upper 28: data, lower 4: channel )
4  *  peek    | 10   | 30
5  *  sender  | 14   | 34
6  *  status  | 18   | 38
7  *  config  | 1c   | 3c
8  *
9  * channel 1: framebuffer
10  * channel 8: request
11  *
12  * read: read status reg loop while empty flag is set
13  * write: read status loop while full flag is set
14  */
15 #include <string.h>
16 #include <stdint.h>
17
18 #ifdef RPI1
19 #define IOBASEADDR      0x20000000
20 #else
21 #define IOBASEADDR      0x3f000000
22 #endif
23
24 #define phys2bus(addr)  ((addr) | 0x40000000)
25 #define bus2phys(addr)  ((addr) & 0x3fffffff)
26
27 #define IOREG_ADDR(x)   (IOBASEADDR | (x))
28 #define REG_MB_READ             *((volatile uint32_t*)IOREG_ADDR(0xb880))
29 #define REG_MB_STAT             *((volatile uint32_t*)IOREG_ADDR(0xb898))
30 #define REG_MB_WRITE    *((volatile uint32_t*)IOREG_ADDR(0xb8a0))
31
32 #define MB_STAT_FULL    0x80000000
33 #define MB_STAT_EMPTY   0x40000000
34
35 #define MB_CHAN_FRAMEBUF        1
36 #define MB_CHAN_PROP            8
37
38 #define PROP_CODE_REQ   0
39 #define PROP_RESP_OK    0x80000000
40
41
42 #define PROP_TAG_END                    0
43
44 #define PROP_TAG_SET                    0x08000
45 #define PROP_TAG_TEST                   0x04000
46 #define PROP_TAG_GET                    0
47
48 #define PROP_TAG_ALLOCBUF               0x40001
49 #define PROP_TAG_BLANKSCR               0x40002
50 #define PROP_TAG_PHYSRES                0x40003
51 #define PROP_TAG_VIRTRES                0x40004
52 #define PROP_TAG_DEPTH                  0x40005
53 #define PROP_TAG_PIXEL_ORDER    0x40006
54 #define PROP_TAG_ALPHA_MODE             0x40007
55 #define PROP_TAG_PITCH                  0x40008
56 #define PROP_TAG_VOFFS                  0x40009
57 #define PROP_TAG_OVERSCAN               0x4000a
58 #define PROP_TAG_PALETTE                0x4000b
59 #define PROP_TAG_CUR_INFO               0x00010
60 #define PROP_TAG_CUR_STATE              0x00011
61
62
63 int prop_blankscr(int onoff);
64
65 uint32_t mb_read(int chan);
66 void mb_write(int chan, uint32_t val);
67
68 int main(void)
69 {
70         prop_blankscr(1);
71
72         return 0;
73 }
74
75 static uint32_t propbuf[64] __attribute__((aligned(16)));
76
77 int prop_blankscr(int onoff)
78 {
79         uint32_t *pb = propbuf;
80
81         *pb++ = 0;
82         *pb++ = 0;
83         *pb++ = PROP_TAG_BLANKSCR;
84         *pb++ = 4;      /* data size */
85         *pb++ = PROP_CODE_REQ;
86         *pb++ = onoff ? 1 : 0;
87         *pb++ = PROP_TAG_END;
88         *pb++ = 0;      /* padding */
89         propbuf[0] = (char*)pb - (char*)propbuf;
90
91         mb_write(MB_CHAN_PROP, (uint32_t)propbuf >> 4);
92         mb_read(MB_CHAN_PROP);
93
94         return propbuf[1] == PROP_RESP_OK ? 0 : -1;
95 }
96
97 uint32_t mb_read(int chan)
98 {
99         uint32_t val;
100         do {
101                 while(REG_MB_STAT & MB_STAT_EMPTY);
102                 val = REG_MB_READ;
103         } while((val & 0xf) != chan);
104         return val >> 4;
105 }
106
107 void mb_write(int chan, uint32_t val)
108 {
109         while(REG_MB_STAT & MB_STAT_FULL);
110         REG_MB_WRITE = (val << 4) | chan;
111 }