interrupts, timers, under construction
[rpikern] / src / rpi.h
1 #ifndef RPI_H_
2 #define RPI_H_
3
4 #include <stdint.h>
5
6
7 #define RPI_MEM_BUS_COHERENT(addr)      (((uint32_t)addr) | 0x40000000)
8 #define RPI_MEM_BUS_UNCACHED(addr)      (((uint32_t)addr) | 0xc0000000)
9
10
11 #define RPI_MBOX_FRAMEBUF       1
12 #define RPI_MBOX_PROP           8
13
14 #define RPI_TAG_GETMODEL        0x010001
15 #define RPI_TAG_GETREV          0x010002
16 #define RPI_TAG_GETRAM          0x010005
17 #define RPI_TAG_GETVRAM         0x010006
18 #define RPI_TAG_SETCLOCK        0x038002
19
20 #define RPI_TAG_ALLOCFB         0x040001
21 #define RPI_TAG_RELEASEFB       0x048001
22 #define RPI_TAG_BLANKSCR        0x040002
23 #define RPI_TAG_SETFBPHYS       0x048003
24 #define RPI_TAG_SETFBVIRT       0x048004
25 #define RPI_TAG_SETFBDEPTH      0x048005
26 #define RPI_TAG_GETFBPITCH      0x040008
27 #define RPI_TAG_SETFBOFFS       0x048009
28 #define RPI_TAG_GETFBOFFS       0x040009
29 /* NOTE: for every new tag added, a new entry needs to be added to the tag
30  * buffer size struct in rpi.c
31  */
32
33 struct rpi_prop_header {
34         uint32_t size;
35         uint32_t res;
36 };
37
38 struct rpi_prop {
39         uint32_t id, size, res;
40         uint32_t data[1];
41 };
42
43 #define RPI_PROP_NEXT(p) \
44         ((struct rpi_prop*)((char*)((p) + 1) + ((p)->size - sizeof (p)->data)))
45
46 extern int rpi_model;
47 extern uint32_t rpi_iobase;
48 extern uint32_t rpi_mem_base, rpi_mem_size, rpi_vmem_base, rpi_vmem_size;
49
50 void rpi_init(void);
51 void rpi_reboot(void) __attribute__((noreturn));
52
53 void rpi_mbox_send(int chan, uint32_t msg);
54 uint32_t rpi_mbox_recv(int chan);
55 int rpi_mbox_pending(int chan);
56
57 /* usage:
58  * rpi_prop(RPI_TAG_WHATEVER, foo, bar);
59  * rpi_prop(RPI_TAG_XYZZY, 42);
60  * if(rpi_prop_send() != -1) {
61  *     struct rpi_prop *prop;
62  *     while((prop = rpi_prop_next())) {
63  *         ... process response tags ...
64  *     }
65  * }
66  */
67 void rpi_prop(int id, ...);
68 int rpi_prop_send(void);
69 struct rpi_prop *rpi_prop_next(void);
70 /* find specific tag in response */
71 struct rpi_prop *rpi_prop_find(int id);
72
73 #endif  /* RPI_H_ */