/**\r
- * \file drv_bochsvbe.c\r
- * \brief BGA (Bochs Graphic Adapter) Driver for Acess2\r
- * \warning This driver does NOT support the Bochs PCI VGA driver\r
-*/\r
+ * Acess2 Bochs graphics adapter Driver\r
+ * - By John Hodge (thePowersGang)\r
+ *\r
+ * bochsvbe.c\r
+ * - Driver core\r
+ */\r
#define DEBUG 0\r
+#define VERSION VER2(0,10)\r
+\r
#include <acess.h>\r
#include <errno.h>\r
#include <modules.h>\r
#include <drv_pci.h>\r
#include <api_drv_video.h>\r
\r
-#define INT\r
-\r
// === TYPES ===\r
typedef struct sBGA_Mode {\r
Uint16 width;\r
VBE_DISPI_INDEX_Y_OFFSET\r
};\r
\r
+extern void MM_DumpTables(tVAddr Start, tVAddr End);\r
\r
// === PROTOTYPES ===\r
// Driver\r
int BGA_int_ModeInfo(tVideo_IOCtl_Mode *info);\r
int BGA_int_MapFB(void *Dest);\r
// Filesystem\r
-Uint64 BGA_Read(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer);\r
-Uint64 BGA_Write(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer);\r
- int BGA_Ioctl(tVFS_Node *node, int id, void *data);\r
+Uint64 BGA_Read(tVFS_Node *Node, Uint64 off, Uint64 len, void *buffer);\r
+Uint64 BGA_Write(tVFS_Node *Node, Uint64 off, Uint64 len, void *buffer);\r
+ int BGA_IOCtl(tVFS_Node *Node, int ID, void *Data);\r
\r
// === GLOBALS ===\r
-MODULE_DEFINE(0, 0x0032, BochsGA, BGA_Install, NULL, "PCI", NULL);\r
+MODULE_DEFINE(0, VERSION, BochsGA, BGA_Install, NULL, "PCI", NULL);\r
tDevFS_Driver gBGA_DriverStruct = {\r
NULL, "BochsGA",\r
{\r
.Read = BGA_Read,\r
.Write = BGA_Write,\r
- .IOCtl = BGA_Ioctl\r
+ .IOCtl = BGA_IOCtl\r
}\r
};\r
int giBGA_CurrentMode = -1;\r
{1024,768,32, 1024*768*4}\r
};\r
#define BGA_MODE_COUNT (sizeof(gBGA_Modes)/sizeof(gBGA_Modes[0]))\r
+tDrvUtil_Video_BufInfo gBGA_DrvUtil_BufInfo;\r
\r
// === CODE ===\r
/**\r
int BGA_Install(char **Arguments)\r
{\r
int version = 0;\r
+ tPAddr base;\r
+ tPCIDev dev;\r
\r
// Check BGA Version\r
version = BGA_int_ReadRegister(VBE_DISPI_INDEX_ID);\r
+ LOG("version = 0x%x", version);\r
\r
- // NOTE: This driver was written for 0xB0C4, but they seem to be backwards compatable\r
- if(version != 0xB0C0 && (version < 0xB0C4 || version > 0xB0C5)) {\r
+ // NOTE: This driver was written for later than 0xB0C2\r
+ // NOTE: Qemu is braindead and doesn't return the actual version\r
+ if( version != 0xB0C0 && ((version & 0xFFF0) != 0xB0C0 || version < 0xB0C2) ) {\r
Log_Warning("BGA", "Bochs Adapter Version is not 0xB0C4 or 0xB0C5, instead 0x%x", version);\r
return MODULE_ERR_NOTNEEDED;\r
}\r
- \r
+\r
+ // Get framebuffer base \r
+ dev = PCI_GetDevice(0x1234, 0x1111, 0);\r
+ if(dev == -1)\r
+ base = VBE_DISPI_LFB_PHYSICAL_ADDRESS;\r
+ else\r
+ base = PCI_GetBAR(dev, 0);\r
+\r
+ // Map Framebuffer to hardware address\r
+ gBGA_Framebuffer = (void *) MM_MapHWPages(base, 768); // 768 pages (3Mb)\r
+ MM_DumpTables(0, -1);\r
+\r
// Install Device\r
- if(DevFS_AddDevice( &gBGA_DriverStruct ) == -1) {\r
+ if( DevFS_AddDevice( &gBGA_DriverStruct ) == -1 )\r
+ {\r
Log_Warning("BGA", "Unable to register with DevFS, maybe already loaded?");\r
return MODULE_ERR_MISC;\r
}\r
- \r
- // Map Framebuffer to hardware address\r
- gBGA_Framebuffer = (void *) MM_MapHWPages(VBE_DISPI_LFB_PHYSICAL_ADDRESS, 768); // 768 pages (3Mb)\r
- \r
+ \r
return MODULE_ERR_OK;\r
}\r
\r
/**\r
- * \fn void BGA_Uninstall()\r
+ * \brief Clean up driver resources before destruction\r
*/\r
-void BGA_Uninstall()\r
+void BGA_Uninstall(void)\r
{\r
DevFS_DelDevice( &gBGA_DriverStruct );\r
MM_UnmapHWPages( VBE_DISPI_LFB_PHYSICAL_ADDRESS, 768 );\r
}\r
\r
/**\r
- * \fn Uint64 BGA_Write(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer)\r
* \brief Write to the framebuffer\r
*/\r
-Uint64 BGA_Write(tVFS_Node *node, Uint64 off, Uint64 len, void *Buffer)\r
-{ \r
- ENTER("xoff xlen", off, len);\r
- \r
- // Check Mode\r
- if(giBGA_CurrentMode == -1) {\r
- Log_Notice("BGA", "Setting video mode to #0 (640x480x32)");\r
- BGA_int_UpdateMode(0); // Mode Zero is 640x480\r
- }\r
- \r
- // Text Mode\r
- switch( giBGA_BufferFormat )\r
- {\r
- case VIDEO_BUFFMT_TEXT:\r
- {\r
- tVT_Char *chars = Buffer;\r
- int x, y; // Characters/Rows\r
- int widthInChars = gpBGA_CurrentMode->width/giVT_CharWidth;\r
- Uint32 *dest;\r
- \r
- off /= sizeof(tVT_Char);\r
- len /= sizeof(tVT_Char);\r
- \r
- x = (off % widthInChars);\r
- y = (off / widthInChars);\r
- \r
- // Sanity Check\r
- if(y > gpBGA_CurrentMode->height / giVT_CharHeight) {\r
- LEAVE('i', 0);\r
- return 0;\r
- }\r
- \r
- dest = (Uint32 *)gBGA_Framebuffer;\r
- dest += y * gpBGA_CurrentMode->width * giVT_CharHeight;\r
- while(len--)\r
- {\r
- VT_Font_Render(\r
- chars->Ch,\r
- dest + x*giVT_CharWidth, 32, gpBGA_CurrentMode->width*4,\r
- VT_Colour12to24(chars->BGCol),\r
- VT_Colour12to24(chars->FGCol)\r
- );\r
- \r
- chars ++;\r
- x ++;\r
- if( x >= widthInChars ) {\r
- x = 0;\r
- y ++; // Why am I keeping track of this?\r
- dest += gpBGA_CurrentMode->width*giVT_CharHeight;\r
- }\r
- }\r
- }\r
- break;\r
- \r
- case VIDEO_BUFFMT_FRAMEBUFFER:\r
- {\r
- Uint8 *destBuf = (Uint8*) ((Uint)gBGA_Framebuffer + (Uint)off);\r
- \r
- if( off + len > gpBGA_CurrentMode->fbSize ) {\r
- LEAVE('i', 0);\r
- return 0;\r
- }\r
- \r
- LOG("buffer = %p", Buffer);\r
- LOG("Updating Framebuffer (%p to %p)", destBuf, destBuf + (Uint)len);\r
- \r
- \r
- // Copy to Frambuffer\r
- memcpy(destBuf, Buffer, len);\r
- \r
- LOG("BGA Framebuffer updated");\r
- }\r
- break;\r
- default:\r
- LEAVE('i', -1);\r
- return -1;\r
- }\r
- \r
- LEAVE('i', len);\r
- return len;\r
+Uint64 BGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)\r
+{\r
+ if( giBGA_CurrentMode == -1 ) BGA_int_UpdateMode(0);\r
+ return DrvUtil_Video_WriteLFB(giBGA_BufferFormat, &gBGA_DrvUtil_BufInfo, Offset, Length, Buffer);\r
}\r
\r
+const char *csaBGA_IOCtls[] = {DRV_IOCTLNAMES, DRV_VIDEO_IOCTLNAMES, NULL};\r
/**\r
- * \fn int BGA_Ioctl(tVFS_Node *Node, int ID, void *Data)\r
* \brief Handle messages to the device\r
*/\r
-int BGA_Ioctl(tVFS_Node *Node, int ID, void *Data)\r
+int BGA_IOCtl(tVFS_Node *Node, int ID, void *Data)\r
{\r
int ret = -2;\r
ENTER("pNode iId pData", Node, ID, Data);\r
\r
switch(ID)\r
{\r
- case DRV_IOCTL_TYPE:\r
- ret = DRV_TYPE_VIDEO;\r
- break;\r
- case DRV_IOCTL_IDENT:\r
- memcpy(Data, "BGA1", 4);\r
- ret = 1;\r
- break;\r
- case DRV_IOCTL_VERSION:\r
- ret = 0x100;\r
- break;\r
- case DRV_IOCTL_LOOKUP: // TODO: Implement\r
- ret = 0;\r
- break;\r
- \r
+ BASE_IOCTLS(DRV_TYPE_VIDEO, "BochsGA", VERSION, csaBGA_IOCtls);\r
+\r
case VIDEO_IOCTL_GETSETMODE:\r
- if( Data )\r
- ret = BGA_int_UpdateMode(*(int*)(Data));\r
- else\r
- ret = giBGA_CurrentMode;\r
+ if( Data ) BGA_int_UpdateMode(*(int*)(Data));\r
+ ret = giBGA_CurrentMode;\r
break;\r
\r
case VIDEO_IOCTL_FINDMODE:\r
gBGA_CursorPos.y = ((tVideo_IOCtl_Pos*)Data)->y;\r
break;\r
\r
- // Request Access to LFB\r
-// case VIDEO_IOCTL_REQLFB:\r
-// ret = BGA_int_MapFB( *(void**)Data );\r
-// break;\r
- \r
default:\r
LEAVE('i', -2);\r
return -2;\r
\r
//== Internal Functions ==\r
/**\r
- * \fn void BGA_int_WriteRegister(Uint16 reg, Uint16 value)\r
* \brief Writes to a BGA register\r
*/\r
void BGA_int_WriteRegister(Uint16 reg, Uint16 value)\r
return inw(VBE_DISPI_IOPORT_DATA);\r
}\r
\r
-#if 0\r
-void BGA_int_SetBank(Uint16 bank)\r
-{\r
- BGA_int_WriteRegister(VBE_DISPI_INDEX_BANK, bank);\r
-}\r
-#endif\r
-\r
/**\r
- * \fn void BGA_int_SetMode(Uint16 width, Uint16 height, Uint16 bpp)\r
- * \brief Sets the video mode from the dimensions and bpp given\r
+ * \brief Sets the video mode (32bpp only)\r
*/\r
void BGA_int_SetMode(Uint16 Width, Uint16 Height)\r
{\r
- ENTER("iWidth iheight ibpp", Width, Height, bpp);\r
+ ENTER("iWidth iHeight", Width, Height);\r
BGA_int_WriteRegister(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_DISABLED);\r
- BGA_int_WriteRegister(VBE_DISPI_INDEX_XRES, Width);\r
- BGA_int_WriteRegister(VBE_DISPI_INDEX_YRES, Height);\r
- BGA_int_WriteRegister(VBE_DISPI_INDEX_BPP, 32);\r
- BGA_int_WriteRegister(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED | VBE_DISPI_NOCLEARMEM | VBE_DISPI_LFB_ENABLED);\r
+ BGA_int_WriteRegister(VBE_DISPI_INDEX_XRES, Width);\r
+ BGA_int_WriteRegister(VBE_DISPI_INDEX_YRES, Height);\r
+ BGA_int_WriteRegister(VBE_DISPI_INDEX_BPP, 32);\r
+ BGA_int_WriteRegister(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED | VBE_DISPI_NOCLEARMEM | VBE_DISPI_LFB_ENABLED);\r
+ MAGIC_BREAK();\r
LEAVE('-');\r
}\r
\r
gBGA_Modes[id].width,\r
gBGA_Modes[id].height);\r
\r
+ gBGA_DrvUtil_BufInfo.Framebuffer = gBGA_Framebuffer;\r
+ gBGA_DrvUtil_BufInfo.Pitch = gBGA_Modes[id].width * 4;\r
+ gBGA_DrvUtil_BufInfo.Width = gBGA_Modes[id].width;\r
+ gBGA_DrvUtil_BufInfo.Height = gBGA_Modes[id].height;\r
+ gBGA_DrvUtil_BufInfo.Depth = gBGA_Modes[id].bpp;\r
+\r
giBGA_CurrentMode = id;\r
gpBGA_CurrentMode = &gBGA_Modes[id];\r
return id;\r
{\r
int i;\r
int best = 0, bestFactor = 1000;\r
- int factor, tmp;\r
- int rqdProduct = info->width * info->height * info->bpp;\r
+ int tmp;\r
+ int rqdProduct = info->width * info->height;\r
\r
ENTER("pinfo", info);\r
LOG("info = {width:%i,height:%i,bpp:%i})\n", info->width, info->height, info->bpp);\r
for(i = 0; i < BGA_MODE_COUNT; i++)\r
{\r
#if DEBUG >= 2\r
- LogF("Mode %i (%ix%ix%i), ", i, gBGA_Modes[i].width, gBGA_Modes[i].height, gBGA_Modes[i].bpp);\r
+ LOG("Mode %i (%ix%i,%ibpp), ", i, gBGA_Modes[i].width, gBGA_Modes[i].height, gBGA_Modes[i].bpp);\r
#endif\r
+\r
+ if( gBGA_Modes[i].bpp != info->bpp )\r
+ continue ; \r
\r
// Ooh! A perfect match\r
- if(gBGA_Modes[i].width == info->width\r
- && gBGA_Modes[i].height == info->height\r
- && gBGA_Modes[i].bpp == info->bpp)\r
+ if(gBGA_Modes[i].width == info->width && gBGA_Modes[i].height == info->height)\r
{\r
#if DEBUG >= 2\r
- LogF("Perfect!\n");\r
+ LOG("Perfect");\r
#endif\r
best = i;\r
break;\r
}\r
- \r
+\r
+\r
// If not, how close are we?\r
- tmp = gBGA_Modes[i].width * gBGA_Modes[i].height * gBGA_Modes[i].bpp;\r
- tmp -= rqdProduct;\r
+ tmp = gBGA_Modes[i].width * gBGA_Modes[i].height - rqdProduct;\r
tmp = tmp < 0 ? -tmp : tmp; // tmp = ABS(tmp)\r
- factor = tmp * 100 / rqdProduct;\r
\r
#if DEBUG >= 2\r
- LogF("factor = %i\n", factor);\r
+ LOG("tmp = %i", tmp);\r
#endif\r
\r
- if(factor < bestFactor)\r
+ if(tmp < bestFactor)\r
{\r
- bestFactor = factor;\r
+ bestFactor = tmp;\r
best = i;\r
}\r
}\r
info->width = gBGA_Modes[best].width;\r
info->height = gBGA_Modes[best].height;\r
info->bpp = gBGA_Modes[best].bpp;\r
- \r
+\r
+ LEAVE('i', best); \r
return best;\r
}\r
\r
return 1;\r
}\r
\r
-/**\r
- * \fn int BGA_int_MapFB(void *Dest)\r
- * \brief Map the framebuffer into a process's space\r
- * \param Dest User address to load to\r
- */\r
-int BGA_int_MapFB(void *Dest)\r
-{\r
- Uint i;\r
- Uint pages;\r
- \r
- // Sanity Check\r
- if((Uint)Dest > 0xC0000000) return 0;\r
- if(gpBGA_CurrentMode->bpp < 15) return 0; // Only non-pallete modes are supported\r
- \r
- // Count required pages\r
- pages = (gpBGA_CurrentMode->fbSize + 0xFFF) >> 12;\r
- \r
- // Check if there is space\r
- for( i = 0; i < pages; i++ )\r
- {\r
- if(MM_GetPhysAddr( (Uint)Dest + (i << 12) ))\r
- return 0;\r
- }\r
- \r
- // Map\r
- for( i = 0; i < pages; i++ )\r
- MM_Map( (Uint)Dest + (i<<12), VBE_DISPI_LFB_PHYSICAL_ADDRESS + (i<<12) );\r
- \r
- return 1;\r
-}\r