10 #include "gfx/intel.h"
11 #include "net/endianess.h"
20 size_t igfx_width = 0;
21 size_t igfx_height = 0;
23 #define IGFX_READ(reg) (*(volatile uint32_t*)(igfx_addr + reg))
24 #define IGFX_WRITE(reg, val) (*(volatile uint32_t*)(igfx_addr + reg) = (uint32_t)val)
26 #define IGFX_READ8(reg) (*(volatile uint8_t*)(igfx_addr + reg))
27 #define IGFX_WRITE8(reg, val) (*(volatile uint8_t*)(igfx_addr + reg) = (uint8_t)val)
30 volatile size_t igfx_edid_buffer[32] = {0};
32 void igfx_gmbus_reset() {
33 IGFX_WRITE(IGFX_GMBUS1, 0x80000000);
34 IGFX_WRITE(IGFX_GMBUS1, 0);
36 while(IGFX_READ(IGFX_GMBUS2) & (1 << 9))
41 while (!(IGFX_READ(IGFX_GMBUS2) & (1 << 11)))
49 if(igfx_bus == 0xFF) {
50 qemu_err(
"NO INTEL GFX!");
51 tty_printf(
"NO INTEL GFX!\n");
55 qemu_ok(
"INTEL GFX!");
56 tty_printf(
"INTEL GFX!\n");
59 pci_enable_bus_mastering(igfx_bus, igfx_slot, igfx_func);
61 igfx_addr =
pci_read32(igfx_bus, igfx_slot, igfx_func, PCI_BAR0) & ~0xF;
64 get_kernel_page_directory(),
68 PAGE_WRITEABLE | PAGE_CACHE_DISABLE
71 tty_printf(
"IGFX: %d.%d.%d AT %x\n", igfx_bus, igfx_slot, igfx_func, igfx_addr);
76 size_t gmbus1 = (1 << 30)
83 tty_printf(
"RESETTING\n");
89 IGFX_WRITE(IGFX_GMBUS0, 3);
90 IGFX_WRITE(IGFX_GMBUS1, gmbus1);
92 tty_printf(
"Sent READ to controller!\n");
94 for(
int i = 0; i < 32; i++) {
97 uint32_t our_dword = IGFX_READ(IGFX_GMBUS3);
99 igfx_edid_buffer[i] = our_dword;
107 tty_printf(
"\nSTOPPING TRANSACTIONS\n");
109 IGFX_WRITE(IGFX_GMBUS1, (1 << 30) | (1 << 27));
111 tty_printf(
"\nOKAY!\n");
115 uint8_t* data = (uint8_t*)igfx_edid_buffer;
117 igfx_width = ((data[0x3a] >> 4) << 8) | (data[0x38]);
118 igfx_height = ((data[0x3d] >> 4) << 8) | (data[0x3b]);
120 tty_printf(
"WIDTH: %d; HEIGHT: %d\n", igfx_width, igfx_height);
127 IGFX_WRITE(0x70080, IGFX_READ(0x70080) & ~0x27);
128 IGFX_WRITE(0x70084, 0);
130 IGFX_WRITE(0x700c0, IGFX_READ(0x700c0) & ~0x27);
131 IGFX_WRITE(0x700c4, 0);
133 IGFX_WRITE(0x70180, IGFX_READ(0x70180) & ~(1 << 31));
134 IGFX_WRITE(0x70184, 0);
136 IGFX_WRITE(0x71180, IGFX_READ(0x71180) & ~(1 << 31));
137 IGFX_WRITE(0x71184, 0);
141 IGFX_WRITE(0x70024, IGFX_READ(0x70024) | 0x2);
142 IGFX_WRITE(0x71024, IGFX_READ(0x71024) | 0x2);
144 IGFX_WRITE(0x70008, IGFX_READ(0x70008) & ~(1 << 31));
145 IGFX_WRITE(0x71008, IGFX_READ(0x71008) & ~(1 << 31));
147 while(IGFX_READ(0x70008) & (1 << 30)) {}
148 while(IGFX_READ(0x71008) & (1 << 30)) {}
150 size_t xaddr = 0x60000;
152 if((IGFX_READ(0x61180) & (1 << 30))) {
156 uint32_t command = (igfx_width - 1);
158 command |= (igfx_height - 1);
162 IGFX_WRITE(xaddr + 0x1C, command);
165 uint32_t scanline_w = ((igfx_width + 15) & ~15) << 2;
167 IGFX_WRITE(xaddr + 0x10188, scanline_w);
168 IGFX_WRITE(xaddr + 0x10184, 0);
169 IGFX_WRITE(xaddr + 0x1019c, (uint32_t)framebuffer_addr);
170 IGFX_WRITE(xaddr + 0x10184, 0);
173 IGFX_WRITE(0x61230, IGFX_READ(0x61230) & ~(1 << 31));
174 IGFX_WRITE(xaddr + 0x10008, IGFX_READ(xaddr + 0x10008) | (1 << 31));
175 IGFX_WRITE(xaddr + 0x10180, IGFX_READ(xaddr + 0x10180) | (1 << 31));
200 graphics_update(igfx_width, igfx_height, scanline_w);
204 tty_printf(
"Screen now tuned to: %dx%d; Size: %d; BackFB: %x\n", igfx_width, igfx_height, framebuffer_size, back_framebuffer_addr);
void pci_find_device(uint16_t vendor, uint16_t device, uint8_t *bus_ret, uint8_t *slot_ret, uint8_t *func_ret)
[PCI] Поиск устройства по ID-поставшика и устройства
uint32_t pci_read32(uint8_t bus, uint8_t slot, uint8_t function, uint8_t offset)
Чтение данных из шины PCI.