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 /src/framebuffer.c | |
parent | 338bd46fb6dbcb8271102ddb6b896a335eb909dc (diff) |
Add MAIL_T macro; read framebuffer allocation response
Diffstat (limited to 'src/framebuffer.c')
-rw-r--r-- | src/framebuffer.c | 21 |
1 files changed, 19 insertions, 2 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; |