123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #include "video.h"
- #include <mm/mm.h>
- #include <common/printk.h>
- #include <driver/multiboot2/multiboot2.h>
- #include <time/timer.h>
- #include <common/kprint.h>
- #include <mm/mm.h>
- #include <mm/slab.h>
- #include <process/spinlock.h>
- #include <exception/softirq.h>
- spinlock_t video_timer_func_add_lock;
- uint64_t video_refresh_expire_jiffies = 0;
- uint64_t video_last_refresh_pid = -1;
- #define REFRESH_INTERVAL 15UL
- ul VBE_FB_phys_addr;
- struct screen_info_t
- {
- int width, height;
- uint64_t length;
- uint64_t fb_vaddr, fb_paddr;
- uint64_t double_fb_vaddr;
- } sc_info;
- void init_frame_buffer(bool level)
- {
- kinfo("Re-mapping VBE frame buffer...");
- uint64_t global_CR3 = (uint64_t)get_CR3();
- if (level == false)
- {
- struct multiboot_tag_framebuffer_info_t info;
- int reserved;
- multiboot2_iter(multiboot2_get_Framebuffer_info, &info, &reserved);
- sc_info.fb_vaddr = SPECIAL_MEMOEY_MAPPING_VIRT_ADDR_BASE + FRAME_BUFFER_MAPPING_OFFSET;
- sc_info.fb_paddr = info.framebuffer_addr;
- sc_info.width = info.framebuffer_width;
- sc_info.height = info.framebuffer_height;
- sc_info.length = 1UL * sc_info.width * sc_info.height;
- mm_map_proc_page_table(global_CR3, true, sc_info.fb_vaddr, sc_info.fb_paddr, get_VBE_FB_length() << 2, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false, true, false);
- set_pos_VBE_FB_addr((uint *)sc_info.fb_vaddr);
- }
- else
- {
-
- struct Page *p = alloc_pages(ZONE_NORMAL, PAGE_2M_ALIGN(sc_info.length << 2) / PAGE_2M_SIZE, 0);
- sc_info.double_fb_vaddr = (uint64_t)phys_2_virt(p->addr_phys);
- mm_map_proc_page_table(global_CR3, true, sc_info.double_fb_vaddr, p->addr_phys, PAGE_2M_ALIGN(sc_info.length << 2), PAGE_KERNEL_PAGE, false, true, false);
-
- memcpy((void *)sc_info.double_fb_vaddr, (void *)sc_info.fb_vaddr, sc_info.length << 2);
- set_pos_VBE_FB_addr((uint *)sc_info.double_fb_vaddr);
- }
- flush_tlb();
- kinfo("VBE frame buffer successfully Re-mapped!");
- }
- void video_refresh_framebuffer(void *data)
- {
- video_refresh_expire_jiffies = cal_next_n_ms_jiffies(REFRESH_INTERVAL << 1);
- memcpy((void *)sc_info.fb_vaddr, (void *)sc_info.double_fb_vaddr, (sc_info.length << 2));
- }
- int video_init(bool level)
- {
- init_frame_buffer(level);
- if (level)
- {
- spin_init(&video_timer_func_add_lock);
-
-
-
-
-
-
- register_softirq(VIDEO_REFRESH_SIRQ, &video_refresh_framebuffer, NULL);
- video_refresh_expire_jiffies = cal_next_n_ms_jiffies(10 * REFRESH_INTERVAL);
- raise_softirq(VIDEO_REFRESH_SIRQ);
- }
- }
|