1 /*
2  * Copyright (c) 2017 Eric Holland
3  * Use of this source code is governed by a MIT-style
4  * license that can be found in the LICENSE file or at
5  * https://opensource.org/licenses/MIT
6  */
7 
8 #pragma once
9 
10 #include <platform/bcm28xx.h>
11 
12 
13 #define VCORE_MAILBOX_PHYSICAL_ADDRESS (ARMCTRL_0_SBM_BASE + 0x80)
14 
15 
16 #define VCORE_TAG_REQUEST 0x00000000
17 #define VCORE_ENDTAG      0x00000000
18 
19 #define VCORE_TAG_GET_FIRMWARE_REV          0x00000001
20 #define VCORE_TAG_GET_FIRMWARE_REV_REQ_LEN  0x00000000
21 #define VCORE_TAG_GET_FIRMWARE_REV_RSP_LEN  0x00000004
22 
23 #define VCORE_MAILBOX_FULL  0x80000000
24 #define VCORE_MAILBOX_EMPTY 0x40000000
25 
26 #define VC_FB_CHANNEL 0x01
27 #define ARM_TO_VC_CHANNEL 0x08
28 #define VC_TO_ARM_CHANNEL 0x09
29 
30 #define VCORE_SUCCESS           0
31 #define VCORE_ERR_MBOX_FULL     1
32 #define VCORE_ERR_MBOX_TIMEOUT  2
33 
34 #define VCORE_READ_ATTEMPTS 0xffffffff
35 
36 
37 #define MAILBOX_READ               0
38 #define MAILBOX_PEEK               2
39 #define MAILBOX_CONDIG             4
40 #define MAILBOX_STATUS             6
41 #define MAILBOX_WRITE              8
42 
43 
44 #define MAILBOX_FULL               0x80000000
45 #define MAILBOX_EMPTY              0x40000000
46 
47 #define MAX_MAILBOX_READ_ATTEMPTS  8
48 
49 enum mailbox_channel {
50     ch_power               = 0,
51     ch_framebuffer         = 1,
52     ch_vuart               = 2,
53     ch_vchic               = 3,
54     ch_leds                = 4,
55     ch_buttons             = 5,
56     ch_touchscreen         = 6,
57     ch_unused              = 7,
58     ch_propertytags_tovc   = 8,
59     ch_propertytags_fromvc = 9,
60 };
61 
62 typedef struct {
63     uint32_t phys_width;    //request
64     uint32_t phys_height;   //request
65     uint32_t virt_width;    //request
66     uint32_t virt_height;   //request
67     uint32_t pitch;         //response
68     uint32_t depth;         //request
69     uint32_t virt_x_offs;   //request
70     uint32_t virt_y_offs;   //request
71     uint32_t fb_p;          //response
72     uint32_t fb_size;       //response
73 } fb_mbox_t;
74 
75 uint32_t get_vcore_framebuffer(fb_mbox_t *fb_mbox);
76 status_t init_framebuffer(void);
77 uint32_t _get_vcore_single(uint32_t tag, uint32_t req_len, uint8_t *rsp, uint32_t rsp_len);
78 
79