diff options
author | 3gg <3gg@shellblade.net> | 2025-10-14 17:54:17 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-10-14 17:54:17 -0700 |
commit | c099bcb7402421985e6e8c025e8cde591eaa073a (patch) | |
tree | b78e46d44406909bb8f93fc655f1417fc9666c3c | |
parent | 338bd46fb6dbcb8271102ddb6b896a335eb909dc (diff) |
Add MAIL_T macro; read framebuffer allocation response
-rw-r--r-- | src/framebuffer.c | 21 | ||||
-rw-r--r-- | src/mailbox.h | 12 | ||||
-rw-r--r-- | src/uart.c | 2 |
3 files changed, 29 insertions, 6 deletions
diff --git a/src/framebuffer.c b/src/framebuffer.c index e3303b6..c3845b1 100644 --- a/src/framebuffer.c +++ b/src/framebuffer.c | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | #include <mailbox.h> | 3 | #include <mailbox.h> |
4 | 4 | ||
5 | #include <stddef.h> | ||
5 | #include <stdint.h> | 6 | #include <stdint.h> |
6 | 7 | ||
7 | #define WIDTH 640 | 8 | #define WIDTH 640 |
@@ -9,8 +10,15 @@ | |||
9 | #define DEPTH 32 | 10 | #define DEPTH 32 |
10 | #define ALIGNMENT 16 // Framebuffer byte alignment. | 11 | #define ALIGNMENT 16 // Framebuffer byte alignment. |
11 | 12 | ||
13 | typedef struct Framebuffer { | ||
14 | volatile void* pixels; | ||
15 | size_t size; | ||
16 | } Framebuffer; | ||
17 | |||
18 | static Framebuffer framebuffer = {}; | ||
19 | |||
12 | bool framebuffer_init(uint32_t* error) { | 20 | bool framebuffer_init(uint32_t* error) { |
13 | volatile __attribute__((aligned(MAIL_ALIGN))) uint32_t ConfigureScreen[20] = { | 21 | MAIL_T uint32_t ConfigureScreen[20] = { |
14 | 80, // Size in bytes, aligned to MAIL_ALIGN. | 22 | 80, // Size in bytes, aligned to MAIL_ALIGN. |
15 | MAILBOX_REQUEST, | 23 | MAILBOX_REQUEST, |
16 | TAG_FRAMEBUFFER_SET_PHYSICAL_SCREEN_SIZE, 8, MAILBOX_REQUEST, WIDTH, HEIGHT, | 24 | TAG_FRAMEBUFFER_SET_PHYSICAL_SCREEN_SIZE, 8, MAILBOX_REQUEST, WIDTH, HEIGHT, |
@@ -25,7 +33,7 @@ bool framebuffer_init(uint32_t* error) { | |||
25 | goto end; | 33 | goto end; |
26 | } | 34 | } |
27 | 35 | ||
28 | volatile __attribute__((aligned(MAIL_ALIGN))) uint32_t InitFramebuffer[8] = { | 36 | MAIL_T uint32_t InitFramebuffer[8] = { |
29 | 32, // Size in bytes, aligned to MAIL_ALIGN. | 37 | 32, // Size in bytes, aligned to MAIL_ALIGN. |
30 | MAILBOX_REQUEST, | 38 | MAILBOX_REQUEST, |
31 | TAG_FRAMEBUFFER_ALLOCATE, 8, MAILBOX_REQUEST, ALIGNMENT, 0, | 39 | TAG_FRAMEBUFFER_ALLOCATE, 8, MAILBOX_REQUEST, ALIGNMENT, 0, |
@@ -33,6 +41,15 @@ bool framebuffer_init(uint32_t* error) { | |||
33 | }; | 41 | }; |
34 | mbox_write(PROPERTY_CHANNEL, InitFramebuffer); | 42 | mbox_write(PROPERTY_CHANNEL, InitFramebuffer); |
35 | response = mbox_read(PROPERTY_CHANNEL); | 43 | response = mbox_read(PROPERTY_CHANNEL); |
44 | if (response->code != MAILBOX_SUCCESS) { | ||
45 | goto end; | ||
46 | } | ||
47 | |||
48 | // The input mail is overwritten with the response. | ||
49 | // u32 fb base address | ||
50 | // u32 fb size | ||
51 | framebuffer.pixels = (void*)(uintptr_t)InitFramebuffer[5]; | ||
52 | framebuffer.size = InitFramebuffer[6]; | ||
36 | 53 | ||
37 | end: | 54 | end: |
38 | *error = response->code; | 55 | *error = response->code; |
diff --git a/src/mailbox.h b/src/mailbox.h index b35c7a6..2104265 100644 --- a/src/mailbox.h +++ b/src/mailbox.h | |||
@@ -1,3 +1,9 @@ | |||
1 | /* | ||
2 | References: | ||
3 | https://github-wiki-see.page/m/raspberrypi/firmware/wiki/Mailbox-property-interface | ||
4 | https://jsandler18.github.io/extra/prop-channel.html | ||
5 | https://jsandler18.github.io/extra/mailbox.html | ||
6 | */ | ||
1 | #pragma once | 7 | #pragma once |
2 | 8 | ||
3 | #include <stdint.h> | 9 | #include <stdint.h> |
@@ -6,6 +12,9 @@ | |||
6 | // must be aligned to a 16-byte boundary. | 12 | // must be aligned to a 16-byte boundary. |
7 | #define MAIL_ALIGN 16 | 13 | #define MAIL_ALIGN 16 |
8 | 14 | ||
15 | // Type prefix for data arrays used as mail. | ||
16 | #define MAIL_T volatile __attribute__((aligned(MAIL_ALIGN))) | ||
17 | |||
9 | enum | 18 | enum |
10 | { | 19 | { |
11 | PROPERTY_CHANNEL = 8, | 20 | PROPERTY_CHANNEL = 8, |
@@ -55,9 +64,6 @@ typedef struct __attribute__((aligned(MAIL_ALIGN))) Mail { | |||
55 | Tag tags[]; // Variable quantity. | 64 | Tag tags[]; // Variable quantity. |
56 | } Mail; | 65 | } Mail; |
57 | 66 | ||
58 | // TODO: Remove? Unused. | ||
59 | #define MAIL_SIZE(TYPE) (sizeof(TYPE) + (2 * sizeof(uint32_t))) | ||
60 | |||
61 | void mbox_init(); | 67 | void mbox_init(); |
62 | const Mail* mbox_read(uint8_t channel); | 68 | const Mail* mbox_read(uint8_t channel); |
63 | void mbox_write(uint8_t channel, volatile const void* mail); | 69 | void mbox_write(uint8_t channel, volatile const void* mail); |
@@ -35,7 +35,7 @@ enum | |||
35 | }; | 35 | }; |
36 | 36 | ||
37 | // A mailbox message with set clock rate of PL011 to 3MHz tag. | 37 | // A mailbox message with set clock rate of PL011 to 3MHz tag. |
38 | static const uint32_t __attribute__((aligned(MAIL_ALIGN))) UART_SET_CLK[9] = { | 38 | static const MAIL_T uint32_t UART_SET_CLK[9] = { |
39 | 9*4, 0, 0x38002, 12, 8, 2, 3000000, 0, 0 | 39 | 9*4, 0, 0x38002, 12, 8, 2, 3000000, 0, 0 |
40 | }; | 40 | }; |
41 | 41 | ||