From: John Tsiombikas Date: Wed, 11 Nov 2020 21:58:08 +0000 (+0200) Subject: video initialization seems to work, further testing needed X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=rpikern;a=commitdiff_plain;h=203b43a75a028e9238307bd6e73768eb8e942071 video initialization seems to work, further testing needed --- diff --git a/Makefile b/Makefile index 3b12438..ac7afa8 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,5 @@ disasm: $(elf) $(toolprefix)objdump -d $< .PHONY: install -install: $(bin) $(elf) +install: $(bin) cp $(bin) /srv/tftp/$(bin) - cp $(elf) /srv/tftp/$(elf) diff --git a/doc/notes.md b/doc/notes.md new file mode 100644 index 0000000..0d4e804 --- /dev/null +++ b/doc/notes.md @@ -0,0 +1,18 @@ +Raspberry Pi2 notes +=================== +The following is not all confirmed. + +Memory map +---------- +RAM is mapped to 0, 40000000 (cache-coherent) and c0000000h (uncached) in VC +space. In the ARM address space is mapped to 0(?). + +I/O base is at 7e000000 in VC address space (rpi1?), and mapped to different +ranges for each model in ARM space. + +Memory map summary: + - load address: 8000h + - I/O base: + * rpi0/1: 20000000h + * rpi2/3: 3f000000h + * rpi4: fe000000h diff --git a/src/main.c b/src/main.c index e204820..0c8bdf5 100644 --- a/src/main.c +++ b/src/main.c @@ -5,6 +5,7 @@ #include #include "asm.h" #include "serial.h" +#include "video.h" void dbgled(int x); void exit(int x); @@ -18,8 +19,11 @@ int main(void) static int cmdend; init_serial(115200); - ser_printstr("starting rpikern\n"); + ser_printstr("Starting rpikern\n"); + video_init(); + + ser_printstr("Going interactive\n"); for(;;) { int c = ser_getchar(); diff --git a/src/mem.h b/src/mem.h new file mode 100644 index 0000000..8285c05 --- /dev/null +++ b/src/mem.h @@ -0,0 +1,7 @@ +#ifndef MEM_H_ +#define MEM_H_ + +#define MEM_BUS_COHERENT(addr) (((uint32_t)addr) | 0x40000000) +#define MEM_BUS_UNCACHED(addr) (((uint32_t)addr) | 0xc0000000) + +#endif /* MEM_H_ */ diff --git a/src/video.c b/src/video.c new file mode 100644 index 0000000..33b740f --- /dev/null +++ b/src/video.c @@ -0,0 +1,68 @@ +#include "config.h" +#include +#include +#include "video.h" +#include "serial.h" +#include "mem.h" + +#define MBOX_READ_REG (*(volatile uint32_t*)(IO_BASE | 0xb880)) +#define MBOX_POLL_REG (*(volatile uint32_t*)(IO_BASE | 0xb890)) +#define MBOX_SENDER_REG (*(volatile uint32_t*)(IO_BASE | 0xb894)) +#define MBOX_STATUS_REG (*(volatile uint32_t*)(IO_BASE | 0xb898)) +#define MBOX_CFG_REG (*(volatile uint32_t*)(IO_BASE | 0xb89c)) +#define MBOX_WRITE_REG (*(volatile uint32_t*)(IO_BASE | 0xb8a0)) + +#define MBOX_STAT_WRBUSY 0x80000000 +#define MBOX_STAT_RDBUSY 0x40000000 + +struct vc_fbinfo { + uint32_t phys_width, phys_height; + uint32_t virt_width, virt_height; + uint32_t pitch; /* filled by videocore */ + uint32_t depth; + uint32_t x, y; + void *addr; /* filled by videocore */ + uint32_t size; /* filled by videocore */ +}; + +void mbox_write(int mbox, uint32_t msg); +uint32_t mbox_read(int mbox); + +static struct vc_fbinfo fbinf __attribute__((aligned(16))); + +int video_init(void) +{ + memset(&fbinf, 0, sizeof fbinf); + fbinf.phys_width = fbinf.virt_width = 1024; + fbinf.phys_height = fbinf.virt_height = 600; + fbinf.depth = 32; + fbinf.x = fbinf.y = 0; + + mbox_write(1, MEM_BUS_COHERENT(&fbinf)); + if(mbox_read(1) != 0) { + ser_printstr("Failed to initialize display\n"); + return -1; + } + + ser_printstr("Video init successful\n"); + memset(fbinf.addr, 0, fbinf.size); + return 0; +} + +void mbox_write(int mbox, uint32_t msg) +{ + while(MBOX_STATUS_REG & MBOX_STAT_WRBUSY); + MBOX_WRITE_REG = (msg & 0xfffffff0) | mbox; +} + +uint32_t mbox_read(int mbox) +{ + uint32_t msg; + + do { + while(MBOX_STATUS_REG & MBOX_STAT_RDBUSY); + msg = MBOX_READ_REG; + } while((msg & 0xf) != mbox); + + return msg & 0xfffffff0; +} diff --git a/src/video.h b/src/video.h new file mode 100644 index 0000000..5c524b4 --- /dev/null +++ b/src/video.h @@ -0,0 +1,6 @@ +#ifndef VIDEO_H_ +#define VIDEO_H_ + +int video_init(void); + +#endif /* VIDEO_H_ */