📄 svga.c
字号:
/* * Roadrunner/pk * Copyright (C) 1989-2002 Cornfed Systems, Inc. * * The Roadrunner/pk operating system is free software; you can * redistribute and/or modify it under the terms of the GNU General * Public License, version 2, as published by the Free Software * Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * More information about the Roadrunner/pk operating system of * which this file is a part is available on the World-Wide Web * at: http://www.cornfed.com. * */#include <bus/pci.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys.h>#include <sys/vm.h>#include <sys/vmware_svga.h>struct vmware_svga { u_long iobase; int id; u_long fb_start; u_long fb_size; u_long fb_offset; u_long mem_start; u_long mem_size; u_long cap; u_long max_width; u_long width; u_long max_height; u_long height; u_long host_bpp; u_long bpp; u_long bpl; u_long depth; u_long pseudocolor; u_long red_mask; u_long green_mask; u_long blue_mask;};static struct vmware_svga svga;static inline u_longsvga_read(u_long port){ outl(svga.iobase + SVGA_INDEX_PORT, port); return inl(svga.iobase + SVGA_VALUE_PORT);}static inline voidsvga_write(u_long port, u_long val){ outl(svga.iobase + SVGA_INDEX_PORT, port); outl(svga.iobase + SVGA_VALUE_PORT, val);}voidsvga_init(){ pci_func_t func; bzero(&svga, sizeof(struct vmware_svga)); svga.width = 800; svga.height = 600; /* Looking for 0405 VMware SVGA device */ func = pci_lookup(PCI_VENDOR_VMWARE, PCI_DEVICE_ID_VMWARE_SVGA2); if (func == NULL) return; svga.iobase = func->iobase; /* Get adapter parameters */ svga_write(SVGA_REG_ID, SVGA_ID_2); svga.id = svga_read(SVGA_REG_ID); if (svga.id != SVGA_ID_2) { svga_write(SVGA_REG_ID, SVGA_ID_1); svga.id = svga_read(SVGA_REG_ID); if (svga.id != SVGA_ID_1) { if (svga.id != SVGA_ID_0) {#if _DEBUG kprintf("svga_init: no supported VWware SVGA device\n");#endif return; } } } svga.fb_start = svga_read(SVGA_REG_FB_START); svga.fb_size = svga_read(SVGA_REG_FB_SIZE); svga.mem_start = svga_read(SVGA_REG_MEM_START); svga.mem_size = svga_read(SVGA_REG_MEM_SIZE); svga.cap = svga_read(SVGA_REG_CAPABILITIES); svga.max_width = svga_read(SVGA_REG_MAX_WIDTH); svga.max_height = svga_read(SVGA_REG_MAX_HEIGHT); svga.host_bpp = svga_read(SVGA_REG_HOST_BITS_PER_PIXEL); svga.bpp = svga_read(SVGA_REG_BITS_PER_PIXEL);#if _DEBUG kprintf("svga_init: 0405 VMware SVGA adapter iobase 0x%x\n", svga.iobase); kprintf("svga_init: VWware SVGA device version %d\n", svga.id & 0x0f); kprintf("svga_init: fb start %08x size %u mem start %08x size %u\n", svga.fb_start, svga.fb_size, svga.mem_start, svga.mem_size); kprintf("svga_init: capabilities:"); if (svga.cap & SVGA_CAP_RECT_FILL) kprintf(" RECT_FILL"); if (svga.cap & SVGA_CAP_RECT_COPY) kprintf(" RECT_COPY"); if (svga.cap & SVGA_CAP_RECT_PAT_FILL) kprintf(" RECT_PAT_FILL"); if (svga.cap & SVGA_CAP_OFFSCREEN) kprintf(" OFFSCREEN"); if (svga.cap & SVGA_CAP_RASTER_OP) kprintf(" RASTER_OP"); if (svga.cap & SVGA_CAP_CURSOR) kprintf(" CURSOR"); if (svga.cap & SVGA_CAP_CURSOR_BYPASS) kprintf(" CURSOR_BYPASS"); if (svga.cap & SVGA_CAP_CURSOR_BYPASS_2) kprintf(" CURSOR_BYPASS_2"); if (svga.cap & SVGA_CAP_8BIT_EMULATION) kprintf(" 8BIT_EMULATION"); if (svga.cap & SVGA_CAP_ALPHA_CURSOR) kprintf(" ALPHA_CURSOR"); kprintf("\n"); kprintf("svga_init: max width %u max height %u host bpp %u bpp %u\n", svga.max_width, svga.max_height, svga.host_bpp, svga.bpp);#endif /* Report guest OS */#define GUEST_OS_BASE 0x5000#define GUEST_OS_OTHER (GUEST_OS_BASE + 10) svga_write(SVGA_REG_GUEST_ID, GUEST_OS_OTHER); /* Set mode */ svga_write(SVGA_REG_WIDTH, svga.width); svga_write(SVGA_REG_HEIGHT, svga.height); svga_write(SVGA_REG_BITS_PER_PIXEL, svga.bpp); /* Read frame buffer offset and mode parameters */ svga.fb_offset = svga_read(SVGA_REG_FB_OFFSET); svga.bpl = svga_read(SVGA_REG_BYTES_PER_LINE); svga.depth = svga_read(SVGA_REG_DEPTH); svga.pseudocolor = svga_read(SVGA_REG_PSEUDOCOLOR); svga.red_mask = svga_read(SVGA_REG_RED_MASK); svga.green_mask = svga_read(SVGA_REG_GREEN_MASK); svga.blue_mask = svga_read(SVGA_REG_BLUE_MASK);#if _DEBUG kprintf("svga_init: fb offset %08x\n", svga.fb_offset); kprintf("svga_init: bytes per line %u depth %u pseudocolor %08x\n", svga.bpl, svga.depth, svga.pseudocolor); kprintf("svga_init: red mask %08x green mask %08x blue mask %08x\n", svga.red_mask, svga.green_mask, svga.blue_mask);#endif /* Map frame buffer and command FIFO memory */ { struct vm_kmap_entry entry; entry.start = svga.fb_start; entry.len = svga.fb_size; entry.attr = PTE_WRITE | PTE_PRESENT; vm_kmap_insert(&entry); entry.start = svga.mem_start; entry.len = svga.mem_size; entry.attr = PTE_WRITE | PTE_PRESENT; vm_kmap_insert(&entry); }#if 0 /* Enable SVGA */ svga_write(SVGA_REG_ENABLE, 1);#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -