Skip to content

Commit

Permalink
firmware: add hdmi2pcie firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Binkowski committed Jan 23, 2020
1 parent f026f84 commit 971d1cb
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 11 deletions.
1 change: 1 addition & 0 deletions firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ OBJECTS=\
tofe_eeprom.o \
uptime.o \
version.o \
pcie.o \
$(FIRMBUILD_DIRECTORY)/version_data.o \
$(FIRMBUILD_DIRECTORY)/hdmi_in1.o \
boot-helper-$(CPU).o
Expand Down
18 changes: 17 additions & 1 deletion firmware/ci.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ static void video_matrix_list(void)
#ifdef CSR_HDMI_IN1_BASE
wprintf("input1 (1): %s\n", HDMI_IN1_MNEMONIC);
wputs(HDMI_IN1_DESCRIPTION);
#endif
#ifdef CSR_PCIE_PHY_BASE
wprintf("pcie (x):\n");
wprintf(" PCIe buffer\n");
#endif
wprintf("pattern (p):\n");
wprintf(" Video pattern\n");
Expand All @@ -669,7 +673,7 @@ static void video_matrix_list(void)

static void video_matrix_connect(int source, int sink)
{
if(source >= 0 && source <= VIDEO_IN_PATTERN)
if(source >= 0 && source < VIDEO_IN_MAX)
{
if(sink >= 0 && sink <= VIDEO_OUT_HDMI_OUT1) {
wprintf("Connecting %s to output%d\n", processor_get_source_name(source), sink);
Expand All @@ -693,6 +697,12 @@ static void video_matrix_connect(int source, int sink)
processor_set_encoder_source(source);
processor_update();
}
#endif
#ifdef CSR_PCIE_PHY_BASE
else if(sink == VIDEO_OUT_PCIE) {
wprintf("Connecting %s to PCIe\n", processor_get_source_name(source));
processor_update();
}
#endif
}
}
Expand Down Expand Up @@ -1097,6 +1107,9 @@ void ci_service(void)
else if((strcmp(token, "pattern") == 0) || (strcmp(token, "p") == 0)) {
source = VIDEO_IN_PATTERN;
}
else if((strcmp(token, "pcie") == 0) || (strcmp(token, "x") == 0)){
source = VIDEO_IN_PCIE;
}
else {
wprintf("Unknown video source: '%s'\n", token);
}
Expand All @@ -1113,6 +1126,9 @@ void ci_service(void)
else if((strcmp(token, "encoder") == 0) || (strcmp(token, "e") == 0)) {
sink = VIDEO_OUT_ENCODER;
}
else if((strcmp(token, "pcie") == 0) || (strcmp(token, "x") == 0)) {
sink = VIDEO_OUT_PCIE;
}
else
wprintf("Unknown video sink: '%s'\n", token);

Expand Down
18 changes: 11 additions & 7 deletions firmware/framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
* Frame buffers must be aligned to XXX boundary.
*
* 0x01000000 - Pattern Buffer - Frame Buffer n
* 0x02000000 - PCIe Buffer - Frame Buffer n
*
* Each input then has 3 frame buffers spaced like this;
* // HDMI Input 0
* 0x02000000 - HDMI Input 0 - Frame Buffer n
* 0x02040000 - HDMI Input 0 - Frame Buffer n+1
* 0x02080000 - HDMI Input 0 - Frame Buffer n+2
* 0x03000000 - HDMI Input 0 - Frame Buffer n
* 0x03040000 - HDMI Input 0 - Frame Buffer n+1
* 0x03080000 - HDMI Input 0 - Frame Buffer n+2
* // HDMI Input 1
* 0x03000000 - HDMI Input 1 - Frame Buffer n
* 0x03040000 - HDMI Input 1 - Frame Buffer n+1
* 0x03080000 - HDMI Input 1 - Frame Buffer n+2
* 0x04000000 - HDMI Input 1 - Frame Buffer n
* 0x04040000 - HDMI Input 1 - Frame Buffer n+1
* 0x04080000 - HDMI Input 1 - Frame Buffer n+2
* ...
* // HDMI Input x
* 0x0.000000 - HDMI Input x - Frame Buffer n
Expand All @@ -41,14 +42,17 @@
*/
#define FRAMEBUFFER_OFFSET 0x01000000
#define FRAMEBUFFER_PATTERNS 1
#define FRAMEBUFFER_PCIE_BUFFERS 1

#define FRAMEBUFFER_PIXELS_X 1920 // pixels
#define FRAMEBUFFER_PIXELS_Y 1080 // pixels
#define FRAMEBUFFER_PIXELS_BYTES 2 // bytes

#define FRAMEBUFFER_BASE(x) ((x+1)*FRAMEBUFFER_OFFSET)
#define FRAMEBUFFER_BASE_PATTERN FRAMEBUFFER_BASE(0)
#define FRAMEBUFFER_BASE_HDMI_INPUT(x) FRAMEBUFFER_BASE(x+FRAMEBUFFER_PATTERNS)
#define FRAMEBUFFER_BASE_PCIE FRAMEBUFFER_BASE(FRAMEBUFFER_PATTERNS)
#define FRAMEBUFFER_BASE_HDMI_INPUT(x) FRAMEBUFFER_BASE(x+FRAMEBUFFER_PATTERNS+FRAMEBUFFER_PCIE_BUFFERS)


// Largest frame size at 16bpp (ish)
#define FRAMEBUFFER_SIZE 0x400000 // bytes
Expand Down
10 changes: 10 additions & 0 deletions firmware/pcie.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "pcie.h"
#include "framebuffer.h"

// Last 4 bytes of the buffer area
volatile unsigned int * pcie_in_fb_index = (unsigned int*)(MAIN_RAM_BASE + FRAMEBUFFER_BASE_PCIE + 4 * FRAMEBUFFER_SIZE - sizeof(unsigned int));
volatile unsigned int * pcie_out_fb_index = (unsigned int*)(MAIN_RAM_BASE + FRAMEBUFFER_BASE_PCIE + 8 * FRAMEBUFFER_SIZE - sizeof(unsigned int));

unsigned int pcie_in_framebuffer_base(char n) {
return FRAMEBUFFER_BASE_PCIE + n * FRAMEBUFFER_SIZE;
}
8 changes: 8 additions & 0 deletions firmware/pcie.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __PCIE_H
#define __PCIE_H

extern volatile unsigned int * pcie_out_fb_index;
extern volatile unsigned int * pcie_in_fb_index;
unsigned int pcie_in_framebuffer_base(char);

#endif
22 changes: 22 additions & 0 deletions firmware/processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <generated/mem.h>
#include <hw/flags.h>
#include <time.h>
#include <system.h>
#include <time.h>

#include "hdmi_in0.h"
#include "hdmi_in1.h"
Expand All @@ -33,6 +35,7 @@
#include "mmcm.h"
#include "processor.h"
#include "heartbeat.h"
#include "pcie.h"

/*
----------------->>> Time ----------->>>
Expand Down Expand Up @@ -705,13 +708,18 @@ char * processor_get_source_name(int source) {
memset(processor_buffer, 0, 16);
if(source == VIDEO_IN_PATTERN)
sprintf(processor_buffer, "pattern");
else if(source == VIDEO_IN_PCIE)
sprintf(processor_buffer, "pcie");
else
sprintf(processor_buffer, "input%d", source);
return processor_buffer;
}

void processor_update(void)
{
#ifdef CSR_PCIE_PHY_BASE
unsigned int pcie_in_fb_idx = (*pcie_in_fb_index) >> 24;
#endif
#ifdef CSR_HDMI_OUT0_BASE
/* hdmi_out0 */
#ifdef CSR_HDMI_IN0_BASE
Expand All @@ -721,9 +729,14 @@ void processor_update(void)
#ifdef CSR_HDMI_IN1_BASE
if(processor_hdmi_out0_source == VIDEO_IN_HDMI_IN1)
hdmi_out0_core_initiator_base_write(hdmi_in1_framebuffer_base(hdmi_in1_fb_index));
#endif
#ifdef CSR_PCIE_PHY_BASE
if(processor_hdmi_out0_source == VIDEO_IN_PCIE)
hdmi_out0_core_initiator_base_write(pcie_in_framebuffer_base(pcie_in_fb_idx));
#endif
if(processor_hdmi_out0_source == VIDEO_IN_PATTERN)
hdmi_out0_core_initiator_base_write(pattern_framebuffer_base());

#endif

#ifdef CSR_HDMI_OUT1_BASE
Expand All @@ -735,6 +748,10 @@ void processor_update(void)
#ifdef CSR_HDMI_IN1_BASE
if(processor_hdmi_out1_source == VIDEO_IN_HDMI_IN1)
hdmi_out1_core_initiator_base_write(hdmi_in1_framebuffer_base(hdmi_in1_fb_index));
#endif
#ifdef CSR_PCIE_PHY_BASE
if(processor_hdmi_out0_source == VIDEO_IN_PCIE)
hdmi_out1_core_initiator_base_write(pcie_in_framebuffer_base(pcie_in_fb_idx));
#endif
if(processor_hdmi_out1_source == VIDEO_IN_PATTERN)
hdmi_out1_core_initiator_base_write(pattern_framebuffer_base());
Expand All @@ -757,6 +774,11 @@ void processor_update(void)
encoder_reader_base_write(pattern_framebuffer_base());
#endif

#ifdef CSR_PCIE_PHY_BASE
/* PCIe capture*/
/* FIXME: add code here when PCIe output starts to use DMA */
#endif

#ifdef CSR_HDMI_IN0_BASE
hb_service(hdmi_in0_framebuffer_base(hdmi_in0_fb_index));
#endif
Expand Down
9 changes: 6 additions & 3 deletions firmware/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ enum {
};

enum {
VIDEO_IN_HDMI_IN0=0,
VIDEO_IN_PATTERN=0,

This comment has been minimized.

Copy link
@micolous

micolous Mar 29, 2020

Contributor

This change caused #483

VIDEO_IN_HDMI_IN0,
VIDEO_IN_HDMI_IN1,
VIDEO_IN_PATTERN
VIDEO_IN_PCIE,
VIDEO_IN_MAX
};

enum {
VIDEO_OUT_HDMI_OUT0=0,
VIDEO_OUT_HDMI_OUT1,
VIDEO_OUT_ENCODER
VIDEO_OUT_ENCODER,
VIDEO_OUT_PCIE
};

extern int processor_mode;
Expand Down

0 comments on commit 971d1cb

Please sign in to comment.