summaryrefslogtreecommitdiff
path: root/rtl/gfx/firmware/main.c
blob: efbf295912d388cb9cbf92281128c79993191072 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "ctrl_map.h"
#include "hostif.h"

unsigned boot_magic;
unsigned boot_hw_rev;

void host_read(struct hostif_ctrl *ctrl)
{
	struct hostif_ar ar;
	if (!(ar = HOSTIF_AR).valid)
		return;

	union ctrl_rdata rdata;
	rdata.word = 0xffffffff;

	switch (ar.addr & 0xff) {
		case CTRL_OFFSET_MAGIC:
			rdata.magic.value = boot_magic;
			break;

		case CTRL_OFFSET_HW_ID:
			rdata.word = boot_hw_rev;
			break;

		case CTRL_OFFSET_FW_ID: {
			rdata.fw_id.year = 0;
			for (unsigned i = 7; i <= 10; ++i) {
				rdata.fw_id.year *= 10;
				rdata.fw_id.year += (unsigned)(__DATE__[i] - '0');
			}

			rdata.fw_id.day = __DATE__[4] != ' ' ? (unsigned)(__DATE__[4] - '0') : 0;
			rdata.fw_id.day += (unsigned)(__DATE__[5] - '0');

			const char months[12][3] = {
				"Jan",
				"Feb",
				"Mar",
				"Apr",
				"May",
				"Jun",
				"Jul",
				"Aug",
				"Sep",
				"Oct",
				"Nov",
				"Dec",
			};

			rdata.fw_id.month = 0;
			for (unsigned i = 0; i < sizeof months / sizeof months[0]; ++i)
				if (__DATE__[0] == months[i][0]
				 && __DATE__[1] == months[i][1]
				 && __DATE__[2] == months[i][2]) {
					rdata.fw_id.month = i + 1;
					break;
				}

			rdata.fw_id.build = 1;
			rdata.fw_id.rsvd31 = 0;
			break;
		}

		case CTRL_OFFSET_HOSTIF_ID:
			rdata.hostif_id.rev = HOSTIF_REV_V1;
			break;
	}

	HOSTIF_R.data = rdata.word;
	while (!(*ctrl = HOSTIF_CTRL).rdone);
}

void host_write(struct hostif_ctrl *ctrl)
{
	struct hostif_aw aw;
	if (!(aw = HOSTIF_AW).valid)
		return;

	union ctrl_wdata wdata;
	wdata.word = HOSTIF_W.data;

	switch (aw.addr & 0xff) {
	}

	HOSTIF_B = (struct hostif_b){ .valid = 1, .rsvd1 = 0 };
	while (!(*ctrl = HOSTIF_CTRL).bdone);
}

int main(unsigned magic, unsigned hw_rev)
{
	boot_magic = magic;
	boot_hw_rev = hw_rev;

	while (1) {
		struct hostif_ctrl ctrl = HOSTIF_CTRL;

		if (ctrl.arvalid)
			host_read(&ctrl);

		if (ctrl.awvalid && ctrl.wvalid)
			host_write(&ctrl);
	}
}