-
Notifications
You must be signed in to change notification settings - Fork 2
/
rpi-mailbox-interface.c
175 lines (157 loc) · 4.94 KB
/
rpi-mailbox-interface.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "mailbox.h"
#include "rpi-mailbox-interface.h"
#include "systimer.h"
/* Make sure the property tag buffer is aligned to a 16-byte boundary because we only have 28-bits available in the property interface protocal to pass the address of the buffer to the VC. */
static int pt[8192] __attribute__((aligned(16)));
static int pt_index = 0;
void RPI_PropertyInit(void){
/* Fill in the size on-the-fly*/
pt[PT_OSIZE] = 12;
/*Process request( All other values are reserved!)*/
pt[PT_OREQUEST_OR_RESPONSE] = 0;
/*First available data slot*/
pt_index = 2;
/* NULL tag to terminate tag list*/
pt[pt_index] = 0;
}
/* Add a property tag to the current tag list. Data can be included. All data is uint32_t
* @param tag
*/
void RPI_PropertyAddTag(rpi_mailbox_tag_t tag, ... ){
va_list v1;
va_start( v1, tag);
pt[pt_index++] = tag;
switch(tag){
case TAG_GET_FIRMWARE_VERSION:
case TAG_GET_BOARD_MODEL:
case TAG_GET_BOARD_REVISION:
case TAG_GET_BOARD_MAC_ADDRESS:
case TAG_GET_BOARD_SERIAL:
case TAG_GET_ARM_MEMORY:
case TAG_GET_VC_MEMORY:
case TAG_GET_DMA_CHANNELS:
/* Provide an 8-byte buffer for the response */
pt[pt_index++] = 8;
pt[pt_index++] = 0; /* Request*/
pt_index += 2;
break;
case TAG_GET_CLOCKS:
case TAG_GET_COMMAND_LINE:
/* Provide a 256-byte buffer */
pt[pt_index++] = 256;
pt[pt_index++] = 0; /* Request*/
pt_index += 256 >> 2;
break;
case TAG_ALLOCATE_BUFFER:
case TAG_GET_MAX_CLOCK_RATE:
case TAG_GET_MIN_CLOCK_RATE:
case TAG_GET_CLOCK_RATE:
pt[pt_index++] = 8;
pt[pt_index++] = 0;
pt[pt_index++] = va_arg(v1, int);
pt[pt_index++] = 0;
break;
case TAG_SET_CLOCK_RATE:
pt[pt_index++] = 12;
pt[pt_index++] = 0; /* Request*/
pt[pt_index++] = va_arg(v1, int); /* Clock ID */
pt[pt_index++] = va_arg(v1, int); /* Rate (in Hz)*/
pt[pt_index++] = va_arg(v1, int); /* Skip the turbo setting if == 1 */
break;
case TAG_GET_PHYSICAL_SIZE:
case TAG_SET_PHYSICAL_SIZE:
case TAG_TEST_PHYSICAL_SIZE:
case TAG_GET_VIRTUAL_SIZE:
case TAG_SET_VIRTUAL_SIZE:
case TAG_TEST_VIRTUAL_SIZE:
case TAG_GET_VIRTUAL_OFFSET:
case TAG_SET_VIRTUAL_OFFSET:
pt[pt_index++] = 8;
pt[pt_index++] = 0; /* Request */
if( ( tag == TAG_SET_PHYSICAL_SIZE) || (tag == TAG_SET_VIRTUAL_SIZE) || (tag == TAG_SET_VIRTUAL_OFFSET) || (tag == TAG_TEST_PHYSICAL_SIZE) || (tag == TAG_TEST_VIRTUAL_SIZE)){
pt[pt_index++] = va_arg(v1, int); /* Width*/
pt[pt_index++] = va_arg(v1, int); /* Height */
}else{
pt_index += 2;
}break;
case TAG_GET_ALPHA_MODE:
case TAG_SET_ALPHA_MODE:
case TAG_GET_DEPTH:
case TAG_SET_DEPTH:
case TAG_GET_PIXEL_ORDER:
case TAG_SET_PIXEL_ORDER:
case TAG_GET_PITCH:
pt[pt_index++] = 4;
pt[pt_index++] = 0; /* Request */
if( (tag == TAG_SET_DEPTH) || (tag == TAG_SET_PIXEL_ORDER) || (tag == TAG_SET_ALPHA_MODE)){
/* Colour Depth*, bits-per-pixel \ Pixel Order State*/
pt[pt_index++] = va_arg(v1, int);
}else{
pt_index += 1;
}
break;
case TAG_GET_OVERSCAN:
case TAG_SET_OVERSCAN:
pt[pt_index++] = 16;
pt[pt_index++] = 0; /*Request*/
if( (tag == TAG_SET_OVERSCAN)){
pt[pt_index++] = va_arg(v1, int); /*Top pixels */
pt[pt_index++] = va_arg(v1, int); /* Bottom pixels */
pt[pt_index++] = va_arg(v1, int); /* Left pixels*/
pt[pt_index++] = va_arg(v1, int); /* Right pixels*/
}else{
pt_index += 4;
}break;
default:
/* Unsupported tags, just remove the tag from the list*/
pt_index--;
break;
}
/* Make sure the tags are 0 terminated to end the list and update the buffer size */
pt[pt_index] = 0;
va_end(v1);
}
int RPI_PropertyProcess(void){
int result;
#if(PRINT_PROP_DEBUG == 1)
printf( "%s Length: %d\r\n", __func__, pt[PT_OSIZE]);
#endif
/* Fill in the size of the buffer */
pt[PT_OSIZE] = (pt_index + 1 ) << 2;
pt[PT_OREQUEST_OR_RESPONSE] = 0;
#if(PRINT_PROP_DEBUG == 1)
for(i = 0; i < (pt[PT_OSIZE] >> 2); i++)
printf( "Request: %3d %8.8X\r\n", i, pt[i]);
#endif
Rpi_MailboxWrite(MB0_TAGS_ARM_TO_VC, (unsigned int)pt);
result = Rpi_MailboxRead(MB0_TAGS_ARM_TO_VC);
#if( PRINT_PROP_DEBUG == 1)
for(i = 0; i < (pt[PT_OSIZE] >> 2); i++)
printf( "Response: %3d %8.8X\r\n", i, pt[i]);
#endif
return result;
}
rpi_mailbox_property_t* RPI_PropertyGet( rpi_mailbox_tag_t tag){
static rpi_mailbox_property_t property;
int* tag_buffer = NULL;
property.tag = tag;
/*Get the tag from the buffer. Start at the first tag position */
int index = 2;
while( index < (pt[PT_OSIZE] >> 2 )){
/* printf("Test Tag: [%d] %8.8X\r\n", index, pt[index] ); */
if( pt[index] == tag){
tag_buffer = &pt[index];
break;
}
/* Progress to the next tag if we haven't yet discovered the tag */
index += ( pt[index + 1] >> 2 ) + 3;
}
if( tag_buffer == NULL )
return NULL;
property.byte_length = tag_buffer[T_ORESPONSE] & 0xFFFF;
memcpy( property.data.buffer_8, &tag_buffer[T_OVALUE], property.byte_length);
return &property;
}