Skip to content

Commit d21bf83

Browse files
committed
Convert to cbvideo
Use coreboot's framebuffer configuration interfcae so we can be less intrusive to SeaBIOS code base. Signed-off-by: Jiaxun Yang <[email protected]>
1 parent 433f08f commit d21bf83

File tree

7 files changed

+2849
-2496
lines changed

7 files changed

+2849
-2496
lines changed

bins/vgabios.h

Lines changed: 2390 additions & 2348 deletions
Large diffs are not rendered by default.

coreboot.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <uefi.h>
2+
#include "csmwrap.h"
3+
4+
static UINT16
5+
CbCheckSum16 (
6+
IN UINT16 *Buffer,
7+
IN UINTN Length
8+
)
9+
{
10+
UINT32 Sum;
11+
UINT32 TmpValue;
12+
UINTN Idx;
13+
UINT8 *TmpPtr;
14+
15+
Sum = 0;
16+
TmpPtr = (UINT8 *)Buffer;
17+
for (Idx = 0; Idx < Length; Idx++) {
18+
TmpValue = TmpPtr[Idx];
19+
if (Idx % 2 == 1) {
20+
TmpValue <<= 8;
21+
}
22+
23+
Sum += TmpValue;
24+
25+
// Wrap
26+
if (Sum >= 0x10000) {
27+
Sum = (Sum + (Sum >> 16)) & 0xFFFF;
28+
}
29+
}
30+
31+
return (UINT16)((~Sum) & 0xFFFF);
32+
}
33+
34+
int build_coreboot_table(struct csmwrap_priv *priv)
35+
{
36+
void *p = (void *)CB_TABLE_START;
37+
void *tables;
38+
uint32_t table_entries = 0;
39+
40+
struct cb_header *header = (struct cb_header *)p;
41+
memset(header, 0, sizeof(struct cb_header));
42+
header->signature = CB_HEADER_SIGNATURE;
43+
header->header_bytes = sizeof(struct cb_header);
44+
p += header->header_bytes;
45+
tables = p;
46+
47+
/* cb_framebuffer */
48+
struct cb_framebuffer *framebuffer = (struct cb_framebuffer *)p;
49+
memcpy(framebuffer, &priv->cb_fb, sizeof(struct cb_framebuffer));
50+
framebuffer->tag = CB_TAG_FRAMEBUFFER;
51+
framebuffer->size = sizeof(struct cb_framebuffer);
52+
p += framebuffer->size;
53+
table_entries++;
54+
55+
/* Last header stuff */
56+
header->table_entries = table_entries;
57+
header->table_bytes = (uint32_t)((uintptr_t)p - (uintptr_t)tables);
58+
header->table_checksum = CbCheckSum16((UINT16*)tables, header->table_bytes);
59+
header->header_checksum = CbCheckSum16((UINT16*)header, header->header_bytes);
60+
61+
return 0;
62+
}

csmwrap.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
// Generated by: xxd -i Csm16.bin >> Csm16.h
88
#include "bins/Csm16.h"
9+
910
// Generated by: xxd -i vgabios.bin >> vgabios.h
1011
#include "bins/vgabios.h"
1112

@@ -141,12 +142,6 @@ int main(int argc, char_t **argv)
141142
return -1;
142143
}
143144

144-
priv.vga_table = find_table(CSM_VGA_TABLE_SIGNATURE, vgabios_bin, sizeof(vgabios_bin));
145-
if (priv.vga_table == NULL) {
146-
printf("VGA Table not found\n");
147-
return -1;
148-
}
149-
150145
copy_rsdt(&priv);
151146

152147
Status = csmwrap_video_init(&priv);
@@ -188,6 +183,7 @@ int main(int argc, char_t **argv)
188183
priv.low_stub->vga_oprom_table.PciBus = priv.vga_pci_bus;
189184
priv.low_stub->vga_oprom_table.PciDeviceFunction = priv.vga_pci_devfn;
190185

186+
build_coreboot_table(&priv);
191187

192188
printf("CALL16 %x:%x\n", priv.csm_efi_table->Compatibility16CallSegment,
193189
priv.csm_efi_table->Compatibility16CallOffset);

csmwrap.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <uefi.h>
55
#include "edk2/Acpi20.h"
6+
#include "edk2/Coreboot.h"
67
#include "edk2/E820.h"
78
#include "edk2/LegacyBios.h"
89
#include "edk2/LegacyRegion2.h"
@@ -26,13 +27,13 @@ struct csmwrap_priv {
2627
EFI_PCI_IO_PROTOCOL *vga_pci_io;
2728
uint8_t vga_pci_bus;
2829
uint8_t vga_pci_devfn;
29-
30-
struct csm_vga_table *vga_table;
30+
struct cb_framebuffer cb_fb;
3131
};
3232

3333
extern int unlock_bios_region();
3434
extern int csmwrap_video_init(struct csmwrap_priv *priv);
3535
extern int csmwrap_video_fallback(struct csmwrap_priv *priv);
36+
extern int build_coreboot_table(struct csmwrap_priv *priv);
3637
extern int copy_rsdt(struct csmwrap_priv *priv);
3738
int build_e820_map(struct csmwrap_priv *priv);
3839

@@ -62,9 +63,10 @@ struct low_stub {
6263

6364
/* Memory map information */
6465
/* In low memory */
66+
#define CB_TABLE_START 0x00000500
6567
#define CONVEN_START 0x00007E00
6668
/* We may have some stack here */
67-
#define LOW_STUB_BASE 0x00020000
69+
#define LOW_STUB_BASE 0x00020000
6870
/* Thunk + PMM */
6971
#define CONVEN_END 0x00080000
7072
#define EBDA_BASE CONVEN_END
@@ -75,5 +77,14 @@ struct low_stub {
7577
/* End of low 1MiB */
7678
#define HIPMM_SIZE 0x400000 /* Allocated on runtime, can be anywhere in 32bit */
7779

80+
#ifndef ARRAY_SIZE
81+
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
82+
#endif
83+
84+
#define ALIGN(x, a) __ALIGN_MASK(x, (__typeof__(x))(a)-1UL)
85+
#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
86+
#define ALIGN_UP(x, a) ALIGN((x), (a))
87+
#define ALIGN_DOWN(x, a) ((x) & ~((__typeof__(x))(a)-1UL))
88+
#define IS_ALIGNED(x, a) (((x) & ((__typeof__(x))(a)-1UL)) == 0)
7889

7990
#endif

0 commit comments

Comments
 (0)