Skip to content

Commit 04341ff

Browse files
committed
vec dance works
1 parent 8043bb7 commit 04341ff

File tree

14 files changed

+238
-63
lines changed

14 files changed

+238
-63
lines changed

arch/vpu/intc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ void sleh_irq(vc4_saved_state_t* pcb, uint32_t tp) {
220220
switch (source) {
221221
case 64: // timer0
222222
case 73: // dwc2
223+
case 106: // pv2
223224
case 121: // uart
224225
assert(irq_handlers[source - 64].h);
225226
ret = irq_handlers[source - 64].h(irq_handlers[source - 64].arg);

arch/vpu/thread.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ static inline void push(thread_t *t, uint32_t val) {
2525
static void initial_thread_func(void) __NO_RETURN;
2626
static void initial_thread_func(void) {
2727
thread_t *ct = get_current_thread();
28-
uint32_t own_sp;
28+
//uint32_t own_sp;
2929

30-
__asm__ volatile ("mov %0, sp": "=r"(own_sp));
30+
//__asm__ volatile ("mov %0, sp": "=r"(own_sp));
3131
//dprintf(INFO, "thread %p(%s) starting with sp near 0x%x\n", ct, ct->name, own_sp);
32+
spin_unlock(&thread_lock);
33+
arch_enable_ints();
3234

3335
int ret = ct->entry(ct->arg);
3436

@@ -39,6 +41,8 @@ void arch_thread_initialize(thread_t *t) {
3941
//printf("thread %p(%s) has a stack of %p+0x%x\n", t, t->name, t->stack, t->stack_size);
4042
t->arch.sp = (uint32_t)((t->stack + t->stack_size) - 4);
4143
__asm__ volatile ("mov %0, sr": "=r"(t->arch.sr));
44+
t->arch.sr &= ~0x40000000; // disable irq in the new thread
45+
//printf("initial sr: 0x%x\n", t->arch.sr);
4246
push(t, (uint32_t)(&initial_thread_func)); // lr
4347
for (int i=6; i<=23; i++) {
4448
push(t, 0); // r${i}

dev/timer/vc4/rules.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ MODULE := $(LOCAL_DIR)
55
MODULE_SRCS += $(LOCAL_DIR)/timer.c
66

77
GLOBAL_DEFINES += PLATFORM_HAS_DYNAMIC_TIMER=1
8+
MODULE_CFLAGS := -O2
89

910
include make/module.mk

dev/timer/vc4/timer.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
#include <assert.h>
22
#include <lk/err.h>
3+
#include <lk/init.h>
34
#include <lk/reg.h>
45
#include <platform/bcm28xx.h>
56
#include <platform/interrupts.h>
67
#include <platform/timer.h>
78

89
static enum handler_return timer0_irq(void *arg);
10+
static void vc4_timer_init(uint level);
911

1012
static platform_timer_callback timer_cb = 0;;
1113
static void *timer_arg = 0;;
1214

15+
LK_INIT_HOOK(vc4_timer, &vc4_timer_init, LK_INIT_LEVEL_PLATFORM);
16+
1317
lk_bigtime_t current_time_hires(void) {
1418
//TODO, deal with rollover
1519
return ( ((lk_bigtime_t)*REG32(ST_CHI)) << 32) | *REG32(ST_CLO);
@@ -19,22 +23,30 @@ lk_time_t current_time(void) {
1923
return current_time_hires();
2024
}
2125

26+
static void vc4_timer_init(uint level) {
27+
#if VC4_TIMER_CHANNEL == 0
28+
// TODO, only register the interrupt handler once
29+
register_int_handler(0, timer0_irq, NULL);
30+
unmask_interrupt(0);
31+
#elif VC4_TIMER_CHANNEL == 1
32+
register_int_handler(1, timer0_irq, NULL);
33+
unmask_interrupt(1);
34+
#else
35+
#error unsupported timer channel
36+
#endif
37+
}
38+
2239
status_t platform_set_oneshot_timer (platform_timer_callback callback, void *arg, lk_time_t interval) {
2340
timer_cb = callback;
2441
timer_arg = arg;
2542
//printf("platform_set_oneshot_timer(..., ..., %d)\n", interval);
2643
#if VC4_TIMER_CHANNEL == 0
2744
*REG32(ST_C0) = *REG32(ST_CLO) + (interval * 1000);
28-
register_int_handler(0, timer0_irq, NULL);
29-
unmask_interrupt(0);
3045
#elif VC4_TIMER_CHANNEL == 1
3146
*REG32(ST_C1) = *REG32(ST_CLO) + (interval * 1000);
32-
register_int_handler(1, timer0_irq, NULL);
33-
unmask_interrupt(1);
3447
#else
3548
#error unsupported timer channel
3649
#endif
37-
3850
return NO_ERROR;
3951
}
4052

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include <lib/gfx.h>
4+
5+
void dance_start(gfx_surface* fbin, int hvs_channel);

platform/bcm28xx/hvs/hvs.c

Lines changed: 169 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#include <arch/ops.h>
2+
#include <assert.h>
23
#include <lk/console_cmd.h>
34
#include <lk/reg.h>
45
#include <platform/bcm28xx/hvs.h>
6+
#include <platform/interrupts.h>
57
#include <stdio.h>
68
#include <stdlib.h>
7-
#include <platform/interrupts.h>
89

910
// note, 4096 slots total
1011
volatile uint32_t* dlist_memory = REG32(SCALER_LIST_MEMORY);
@@ -33,6 +34,8 @@ static uint32_t gfx_to_hvs_pixel_format(gfx_format fmt) {
3334
}
3435

3536
void hvs_add_plane(gfx_surface *fb, int x, int y, bool hflip) {
37+
assert(fb);
38+
printf("rendering FB of size %dx%d at %dx%d\n", fb->width, fb->height, x, y);
3639
dlist_memory[display_slot++] = CONTROL_VALID
3740
| CONTROL_WORDS(7)
3841
| CONTROL_PIXEL_ORDER(HVS_PIXEL_ORDER_ABGR)
@@ -48,22 +51,66 @@ void hvs_add_plane(gfx_surface *fb, int x, int y, bool hflip) {
4851
dlist_memory[display_slot++] = fb->stride * fb->pixelsize;
4952
}
5053

51-
void hvs_add_plane_scaled(gfx_surface *fb, int x, int y, int width, int height, bool hflip) {
54+
enum scaling_mode {
55+
none,
56+
PPF, // upscaling?
57+
TPZ // downscaling?
58+
};
59+
60+
static void write_tpz(unsigned int source, unsigned int dest) {
61+
uint32_t scale = (1<<16) * source / dest;
62+
uint32_t recip = ~0 / scale;
63+
dlist_memory[display_slot++] = scale << 8;
64+
dlist_memory[display_slot++] = recip;
65+
}
66+
67+
void hvs_add_plane_scaled(gfx_surface *fb, int x, int y, unsigned int width, unsigned int height, bool hflip) {
68+
assert(fb);
69+
//printf("rendering FB of size %dx%d at %dx%d, scaled down to %dx%d\n", fb->width, fb->height, x, y, width, height);
70+
enum scaling_mode xmode, ymode;
71+
if (fb->width > width) xmode = TPZ;
72+
else if (fb->width < width) xmode = PPF;
73+
else xmode = none;
74+
75+
if (fb->height > height) ymode = TPZ;
76+
else if (fb->height < height) ymode = PPF;
77+
else ymode = none;
78+
79+
int scl0;
80+
switch ((xmode << 2) | ymode) {
81+
case (PPF << 2) | PPF:
82+
scl0 = SCALER_CTL0_SCL_H_PPF_V_PPF;
83+
break;
84+
case (TPZ << 2) | PPF:
85+
scl0 = SCALER_CTL0_SCL_H_TPZ_V_PPF;
86+
break;
87+
case (PPF << 2) | TPZ:
88+
scl0 = SCALER_CTL0_SCL_H_PPF_V_TPZ;
89+
break;
90+
case (TPZ << 2) | TPZ:
91+
scl0 = SCALER_CTL0_SCL_H_TPZ_V_TPZ;
92+
break;
93+
default:
94+
puts("unsupported scale combonation");
95+
}
96+
5297
int start = display_slot;
53-
dlist_memory[display_slot++] = CONTROL_VALID
54-
| CONTROL_WORDS(14)
98+
dlist_memory[display_slot++] = 0 // CONTROL_VALID
99+
// | CONTROL_WORDS(14)
55100
| CONTROL_PIXEL_ORDER(HVS_PIXEL_ORDER_ABGR)
56101
// | CONTROL0_VFLIP // makes the HVS addr count down instead, pointer word must be last line of image
57102
| (hflip ? CONTROL0_HFLIP : 0)
58-
| CONTROL_FORMAT(gfx_to_hvs_pixel_format(fb->format));
59-
dlist_memory[display_slot++] = POS0_X(x) | POS0_Y(y) | POS0_ALPHA(0xff);
60-
dlist_memory[display_slot++] = width | (height << 16);
61-
dlist_memory[display_slot++] = POS2_H(fb->height) | POS2_W(fb->width);
62-
dlist_memory[display_slot++] = 0xDEADBEEF; // dummy for HVS state
63-
dlist_memory[display_slot++] = (uint32_t)fb->ptr | 0xc0000000;
64-
dlist_memory[display_slot++] = 0xDEADBEEF; // dummy for HVS state
65-
dlist_memory[display_slot++] = fb->stride * fb->pixelsize;
66-
dlist_memory[display_slot++] = 0x100;
103+
| CONTROL_FORMAT(gfx_to_hvs_pixel_format(fb->format))
104+
| (scl0 << 5)
105+
| (scl0 << 8); // SCL1
106+
dlist_memory[display_slot++] = POS0_X(x) | POS0_Y(y) | POS0_ALPHA(0xff); // position word 0
107+
dlist_memory[display_slot++] = width | (height << 16); // position word 1
108+
dlist_memory[display_slot++] = POS2_H(fb->height) | POS2_W(fb->width); // position word 2
109+
dlist_memory[display_slot++] = 0xDEADBEEF; // position word 3, dummy for HVS state
110+
dlist_memory[display_slot++] = (uint32_t)fb->ptr | 0xc0000000; // pointer word 0
111+
dlist_memory[display_slot++] = 0xDEADBEEF; // pointer context word 0 dummy for HVS state
112+
dlist_memory[display_slot++] = fb->stride * fb->pixelsize; // pitch word 0
113+
dlist_memory[display_slot++] = 0x100; // LBM base addr
67114

68115
#if 0
69116
bool ppf = false;
@@ -76,19 +123,26 @@ void hvs_add_plane_scaled(gfx_surface *fb, int x, int y, int width, int height,
76123
dlist_memory[display_slot++] = 0xDEADBEEF; //scaling context
77124
}
78125
#endif
79-
bool tpz = true;
80-
if (tpz) {
81-
uint32_t xscale = (1<<16) * fb->width / width;
82-
uint32_t yscale = (1<<16) * fb->height / height;
83-
uint32_t xrecip = ~0 / xscale;
84-
uint32_t yrecip = ~0 / yscale;
85-
dlist_memory[display_slot++] = (xscale << 8);
86-
dlist_memory[display_slot++] = xrecip;
87-
dlist_memory[display_slot++] = (yscale << 8);
88-
dlist_memory[display_slot++] = yrecip;
89-
dlist_memory[display_slot++] = 0xDEADBEEF; //scaling context
126+
127+
if (xmode == PPF) {
128+
puts("unfinished");
129+
}
130+
131+
if (ymode == PPF) {
132+
puts("unfinished");
133+
}
134+
135+
if (xmode == TPZ) {
136+
write_tpz(fb->width, width);
90137
}
91-
printf("entry size: %d\n", display_slot - start);
138+
139+
if (ymode == TPZ) {
140+
write_tpz(fb->height, height);
141+
dlist_memory[display_slot++] = 0xDEADBEEF; // context for scaling
142+
}
143+
144+
//printf("entry size: %d, spans 0x%x-0x%x\n", display_slot - start, start, display_slot);
145+
dlist_memory[start] |= CONTROL_VALID | CONTROL_WORDS(display_slot - start);
92146
}
93147

94148
void hvs_terminate_list(void) {
@@ -138,6 +192,43 @@ void hvs_wipe_displaylist(void) {
138192
display_slot = 0;
139193
}
140194

195+
static bool bcm_host_is_model_pi4(void) {
196+
return false;
197+
}
198+
199+
void hvs_print_position0(uint32_t w) {
200+
printf("position0: 0x%x\n", w);
201+
if (bcm_host_is_model_pi4()) {
202+
printf(" x: %d y: %d\n", w & 0x3fff, (w >> 16) & 0x3fff);
203+
} else {
204+
printf(" x: %d y: %d\n", w & 0xfff, (w >> 12) & 0xfff);
205+
}
206+
}
207+
void hvs_print_control2(uint32_t w) {
208+
printf("control2: 0x%x\n", w);
209+
printf(" alpha: 0x%x\n", (w >> 4) & 0xffff);
210+
printf(" alpha mode: %d\n", (w >> 30) & 0x3);
211+
}
212+
void hvs_print_word1(uint32_t w) {
213+
printf(" word1: 0x%x\n", w);
214+
}
215+
void hvs_print_position2(uint32_t w) {
216+
printf("position2: 0x%x\n", w);
217+
printf(" width: %d height: %d\n", w & 0xffff, (w >> 16) & 0xfff);
218+
}
219+
void hvs_print_position3(uint32_t w) {
220+
printf("position3: 0x%x\n", w);
221+
}
222+
void hvs_print_pointer0(uint32_t w) {
223+
printf("pointer word: 0x%x\n", w);
224+
}
225+
void hvs_print_pointerctx0(uint32_t w) {
226+
printf("pointer context word: 0x%x\n", w);
227+
}
228+
void hvs_print_pitch0(uint32_t w) {
229+
printf("pitch word: 0x%x\n", w);
230+
}
231+
141232
static int cmd_hvs_dump(int argc, const cmd_args *argv) {
142233
printf("SCALER_DISPCTRL: 0x%x\n", *REG32(SCALER_DISPCTRL));
143234
printf("SCALER_DISPSTAT: 0x%x\n", *REG32(SCALER_DISPSTAT));
@@ -162,8 +253,60 @@ static int cmd_hvs_dump(int argc, const cmd_args *argv) {
162253
uint32_t base = hvs_channels[i].dispbase;
163254
printf("SCALER_DISPBASE%d: base 0x%x top 0x%x\n\n", i, base & 0xffff, base >> 16);
164255
}
165-
for (uint32_t i=list1; i<(list1+16); i++) {
256+
for (uint32_t i=list1; i<(list1+64); i++) {
166257
printf("dlist[%x]: 0x%x\n", i, dlist_memory[i]);
258+
if (dlist_memory[i] & BV(31)) {
259+
puts("(31)END");
260+
break;
261+
}
262+
if (dlist_memory[i] & BV(30)) {
263+
int x = i;
264+
int words = (dlist_memory[i] >> 24) & 0x3f;
265+
for (unsigned int index=i; index < (i+words); index++) {
266+
printf("raw dlist[%d] == 0x%x\n", index-i, dlist_memory[index]);
267+
}
268+
bool unity;
269+
printf(" (3:0)format: %d\n", dlist_memory[i] & 0xf);
270+
if (dlist_memory[i] & (1<<4)) puts(" (4)unity");
271+
printf(" (7:5)SCL0: %d\n", (dlist_memory[i] >> 5) & 0x7);
272+
printf(" (10:8)SCL1: %d\n", (dlist_memory[i] >> 8) & 0x7);
273+
if (false) { // is bcm2711
274+
if (dlist_memory[i] & (1<<11)) puts(" (11)rgb expand");
275+
if (dlist_memory[i] & (1<<12)) puts(" (12)alpha expand");
276+
} else {
277+
printf(" (12:11)rgb expand: %d\n", (dlist_memory[i] >> 11) & 0x3);
278+
}
279+
printf(" (14:13)pixel order: %d\n", (dlist_memory[i] >> 13) & 0x3);
280+
if (false) { // is bcm2711
281+
unity = dlist_memory[i] & (1<<15);
282+
} else {
283+
unity = dlist_memory[i] & (1<<4);
284+
if (dlist_memory[i] & (1<<15)) puts(" (15)vflip");
285+
if (dlist_memory[i] & (1<<16)) puts(" (16)hflip");
286+
}
287+
printf(" (18:17)key mode: %d\n", (dlist_memory[i] >> 17) & 0x3);
288+
if (dlist_memory[i] & (1<<19)) puts(" (19)alpha mask");
289+
printf(" (21:20)tiling mode: %d\n", (dlist_memory[i] >> 20) & 0x3);
290+
printf(" (29:24)words: %d\n", words);
291+
x++;
292+
hvs_print_position0(dlist_memory[x++]);
293+
if (bcm_host_is_model_pi4()) {
294+
hvs_print_control2(dlist_memory[x++]);
295+
}
296+
if (unity) {
297+
puts("unity scaling");
298+
} else {
299+
hvs_print_word1(dlist_memory[x++]);
300+
}
301+
hvs_print_position2(dlist_memory[x++]);
302+
hvs_print_position3(dlist_memory[x++]);
303+
hvs_print_pointer0(dlist_memory[x++]);
304+
hvs_print_pointerctx0(dlist_memory[x++]);
305+
hvs_print_pitch0(dlist_memory[x++]);
306+
if (words > 1) {
307+
i += words - 1;
308+
}
309+
}
167310
}
168311
return 0;
169312
}

platform/bcm28xx/hvs/include/platform/bcm28xx/hvs.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extern volatile struct hvs_channel *hvs_channels;
4949
#define CONTROL_FORMAT(n) (n & 0xf)
5050
#define CONTROL_END (1<<31)
5151
#define CONTROL_VALID (1<<30)
52-
#define CONTROL_WORDS(n) ((n & 0x3f) << 24)
52+
#define CONTROL_WORDS(n) (((n) & 0x3f) << 24)
5353
#define CONTROL0_FIXED_ALPHA (1<<19)
5454
#define CONTROL0_HFLIP (1<<16)
5555
#define CONTROL0_VFLIP (1<<15)
@@ -92,6 +92,15 @@ enum hvs_pixel_format {
9292
#define HVS_PIXEL_ORDER_XRGB 2
9393
#define HVS_PIXEL_ORDER_XBGR 3
9494

95+
#define SCALER_CTL0_SCL_H_PPF_V_PPF 0
96+
#define SCALER_CTL0_SCL_H_TPZ_V_PPF 1
97+
#define SCALER_CTL0_SCL_H_PPF_V_TPZ 2
98+
#define SCALER_CTL0_SCL_H_TPZ_V_TPZ 3
99+
#define SCALER_CTL0_SCL_H_PPF_V_NONE 4
100+
#define SCALER_CTL0_SCL_H_NONE_V_PPF 5
101+
#define SCALER_CTL0_SCL_H_NONE_V_TPZ 6
102+
#define SCALER_CTL0_SCL_H_TPZ_V_NONE 7
103+
95104
#define POS0_X(n) (n & 0xfff)
96105
#define POS0_Y(n) ((n & 0xfff) << 12)
97106
#define POS0_ALPHA(n) ((n & 0xff) << 24)
@@ -103,7 +112,7 @@ extern int display_slot;
103112
extern volatile uint32_t* dlist_memory;
104113

105114
void hvs_add_plane(gfx_surface *fb, int x, int y, bool hflip);
106-
void hvs_add_plane_scaled(gfx_surface *fb, int x, int y, int width, int height, bool hflip);
115+
void hvs_add_plane_scaled(gfx_surface *fb, int x, int y, unsigned int width, unsigned int height, bool hflip);
107116
void hvs_terminate_list(void);
108117
void hvs_wipe_displaylist(void);
109118
void hvs_initialize(void);

platform/bcm28xx/include/platform/bcm28xx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void print_timestamp(void);
1515
}
1616
#endif
1717

18+
#define BV(n) (1 << n)
1819
#define SDRAM_BASE 0
1920
#ifdef ARCH_VPU
2021
#define BCM_PERIPH_BASE_PHYS (0x7e000000U)

0 commit comments

Comments
 (0)