mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-19 00:46:31 +00:00
使用内核线程来刷新屏幕 (#57)
* 修改了test-idr的错误 * new: 修复切换双缓冲的时候的卡顿问题 Signed-off-by: guanjinquan <1666320330@qq.com> Co-authored-by: guanjinquan <1666320330@qq.com> Co-authored-by: fslongjin <longjin@RinGoTek.cn>
This commit is contained in:
@ -439,7 +439,8 @@ void pci_init()
|
||||
{
|
||||
if (ptr->Status & 0x10)
|
||||
{
|
||||
kinfo("[ pci device %d ] class code = %d\tsubclass=%d\tstatus=%#010lx\tcap_pointer=%#010lx\tbar5=%#010lx", i, ptr->Class_code, ptr->SubClass, ptr->Status, ((struct pci_device_structure_general_device_t *)ptr)->Capabilities_Pointer, ((struct pci_device_structure_general_device_t *)ptr)->BAR5);
|
||||
kinfo("[ pci device %d ] class code = %d\tsubclass=%d\tstatus=%#010lx\tcap_pointer=%#010lx\tbar5=%#010lx, vendor=%#08x, device id=%#08x", i, ptr->Class_code, ptr->SubClass, ptr->Status, ((struct pci_device_structure_general_device_t *)ptr)->Capabilities_Pointer, ((struct pci_device_structure_general_device_t *)ptr)->BAR5,
|
||||
ptr->Vendor_ID, ptr->Device_ID);
|
||||
uint32_t tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, ((struct pci_device_structure_general_device_t *)ptr)->Capabilities_Pointer);
|
||||
}
|
||||
else
|
||||
|
@ -1,17 +1,17 @@
|
||||
#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 <common/kthread.h>
|
||||
#include <common/printk.h>
|
||||
#include <common/spinlock.h>
|
||||
#include <common/time.h>
|
||||
#include <driver/multiboot2/multiboot2.h>
|
||||
#include <driver/uart/uart.h>
|
||||
#include <exception/softirq.h>
|
||||
#include <mm/mm.h>
|
||||
#include <mm/slab.h>
|
||||
#include <common/spinlock.h>
|
||||
#include <exception/softirq.h>
|
||||
#include <driver/uart/uart.h>
|
||||
#include <common/time.h>
|
||||
|
||||
|
||||
#include <process/process.h>
|
||||
#include <sched/sched.h>
|
||||
#include <time/timer.h>
|
||||
|
||||
uint64_t video_refresh_expire_jiffies = 0;
|
||||
uint64_t video_last_refresh_pid = -1;
|
||||
@ -19,10 +19,11 @@ uint64_t video_last_refresh_pid = -1;
|
||||
struct scm_buffer_info_t video_frame_buffer_info = {0};
|
||||
static struct multiboot_tag_framebuffer_info_t __fb_info;
|
||||
static struct scm_buffer_info_t *video_refresh_target = NULL;
|
||||
static struct process_control_block *video_daemon_pcb = NULL;
|
||||
static spinlock_t daemon_refresh_lock;
|
||||
|
||||
#define REFRESH_INTERVAL 15UL // 启动刷新帧缓冲区任务的时间间隔
|
||||
|
||||
|
||||
/**
|
||||
* @brief VBE帧缓存区的地址重新映射
|
||||
* 将帧缓存区映射到地址SPECIAL_MEMOEY_MAPPING_VIRT_ADDR_BASE处
|
||||
@ -37,22 +38,53 @@ void init_frame_buffer()
|
||||
int reserved;
|
||||
|
||||
video_frame_buffer_info.vaddr = SPECIAL_MEMOEY_MAPPING_VIRT_ADDR_BASE + FRAME_BUFFER_MAPPING_OFFSET;
|
||||
mm_map_proc_page_table(global_CR3, true, video_frame_buffer_info.vaddr, __fb_info.framebuffer_addr, video_frame_buffer_info.size, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false, true, false);
|
||||
mm_map_proc_page_table(global_CR3, true, video_frame_buffer_info.vaddr, __fb_info.framebuffer_addr,
|
||||
video_frame_buffer_info.size, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false, true, false);
|
||||
|
||||
flush_tlb();
|
||||
kinfo("VBE frame buffer successfully Re-mapped!");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 刷新帧缓冲区
|
||||
*
|
||||
* @brief video守护进程, 按时刷新帧缓冲区
|
||||
* @param unused
|
||||
* @return int
|
||||
*/
|
||||
int video_refresh_daemon(void *unused)
|
||||
{
|
||||
// 初始化锁, 这个锁只会在daemon中使用
|
||||
spin_init(&daemon_refresh_lock);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (clock() >= video_refresh_expire_jiffies)
|
||||
{
|
||||
video_refresh_expire_jiffies = cal_next_n_ms_jiffies(REFRESH_INTERVAL << 1);
|
||||
|
||||
if (likely(video_refresh_target != NULL))
|
||||
{
|
||||
spin_lock(&daemon_refresh_lock);
|
||||
memcpy((void *)video_frame_buffer_info.vaddr, (void *)video_refresh_target->vaddr,
|
||||
video_refresh_target->size);
|
||||
spin_unlock(&daemon_refresh_lock);
|
||||
}
|
||||
}
|
||||
video_daemon_pcb->flags &= ~PROC_RUNNING;
|
||||
sched();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 唤醒video的守护进程
|
||||
*/
|
||||
void video_refresh_framebuffer(void *data)
|
||||
{
|
||||
video_refresh_expire_jiffies = cal_next_n_ms_jiffies(REFRESH_INTERVAL << 1);
|
||||
if (unlikely(video_refresh_target == NULL))
|
||||
if (unlikely(video_daemon_pcb == NULL))
|
||||
return;
|
||||
memcpy((void *)video_frame_buffer_info.vaddr, (void *)video_refresh_target->vaddr, video_refresh_target->size);
|
||||
|
||||
process_wakeup(video_daemon_pcb);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,17 +94,22 @@ void video_refresh_framebuffer(void *data)
|
||||
* true ->高级初始化:增加double buffer的支持
|
||||
* @return int
|
||||
*/
|
||||
int video_reinitialize(bool level)
|
||||
int video_reinitialize(bool level) // 这个函数会在main.c调用, 保证 video_init() 先被调用
|
||||
{
|
||||
if (level == false)
|
||||
init_frame_buffer();
|
||||
else
|
||||
{
|
||||
// 计算开始时间
|
||||
video_refresh_expire_jiffies = cal_next_n_ms_jiffies(10 * REFRESH_INTERVAL);
|
||||
|
||||
// 创建video守护进程
|
||||
video_daemon_pcb = kthread_run(&video_refresh_daemon, NULL, CLONE_FS | CLONE_SIGNAL);
|
||||
video_daemon_pcb->virtual_runtime = 0; // 特殊情况, 最高优先级, 以后再改
|
||||
|
||||
// 启用屏幕刷新软中断
|
||||
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);
|
||||
}
|
||||
return 0;
|
||||
@ -88,12 +125,16 @@ int video_set_refresh_target(struct scm_buffer_info_t *buf)
|
||||
{
|
||||
|
||||
unregister_softirq(VIDEO_REFRESH_SIRQ);
|
||||
int counter = 100;
|
||||
while ((get_softirq_pending() & (1 << VIDEO_REFRESH_SIRQ)) && counter > 0)
|
||||
{
|
||||
--counter;
|
||||
usleep(1000);
|
||||
}
|
||||
// todo: 在completion实现后,在这里等待其他刷新任务完成,再进行下一步。
|
||||
|
||||
// int counter = 100;
|
||||
|
||||
// while ((get_softirq_pending() & (1 << VIDEO_REFRESH_SIRQ)) && counter > 0)
|
||||
// {
|
||||
// --counter;
|
||||
// usleep(1000);
|
||||
// }
|
||||
// kdebug("buf = %#018lx", buf);
|
||||
video_refresh_target = buf;
|
||||
register_softirq(VIDEO_REFRESH_SIRQ, &video_refresh_framebuffer, NULL);
|
||||
raise_softirq(VIDEO_REFRESH_SIRQ);
|
||||
@ -134,14 +175,17 @@ int video_init()
|
||||
video_frame_buffer_info.height = __fb_info.framebuffer_height;
|
||||
io_mfence();
|
||||
|
||||
video_frame_buffer_info.size = video_frame_buffer_info.width * video_frame_buffer_info.height * ((video_frame_buffer_info.bit_depth + 7) / 8);
|
||||
video_frame_buffer_info.size =
|
||||
video_frame_buffer_info.width * video_frame_buffer_info.height * ((video_frame_buffer_info.bit_depth + 7) / 8);
|
||||
// 先临时映射到该地址,稍后再重新映射
|
||||
video_frame_buffer_info.vaddr = 0xffff800003000000;
|
||||
mm_map_phys_addr(video_frame_buffer_info.vaddr, __fb_info.framebuffer_addr, video_frame_buffer_info.size, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false);
|
||||
mm_map_phys_addr(video_frame_buffer_info.vaddr, __fb_info.framebuffer_addr, video_frame_buffer_info.size,
|
||||
PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false);
|
||||
|
||||
io_mfence();
|
||||
char init_text2[] = "Video driver initialized.";
|
||||
for (int i = 0; i < sizeof(init_text2) - 1; ++i)
|
||||
uart_send(COM1, init_text2[i]);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user