2003-01-11 01:43:54 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-04-10 18:41:29 +04:00
|
|
|
// $Id: pcivga.cc,v 1.26 2009-04-10 14:41:29 vruppert Exp $
|
2003-01-11 01:43:54 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2002,2003 Mike Nordell
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2009-02-08 12:05:52 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-01-11 01:43:54 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// Experimental PCI VGA adapter
|
|
|
|
//
|
|
|
|
|
|
|
|
// Note: This "driver" was created for the SOLE PURPOSE of getting BeOS
|
|
|
|
// to boot. It currently does NOTHING more than presenting a generic VGA
|
|
|
|
// device on the PCI bus. ALL gfx in/out-put is still handled by the VGA code.
|
|
|
|
// Furthermore, almost all of the PCI registers are currently acting like RAM.
|
|
|
|
|
|
|
|
|
|
|
|
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
|
2008-01-27 01:24:03 +03:00
|
|
|
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
|
2003-01-11 01:43:54 +03:00
|
|
|
// is used to know when we are exporting symbols and when we are importing.
|
|
|
|
#define BX_PLUGGABLE
|
|
|
|
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev.h"
|
2008-12-29 23:16:08 +03:00
|
|
|
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_PCI && BX_SUPPORT_PCIVGA
|
2003-01-11 01:43:54 +03:00
|
|
|
|
2009-01-03 11:55:00 +03:00
|
|
|
#include "pci.h"
|
|
|
|
#include "pcivga.h"
|
|
|
|
|
2003-01-11 01:43:54 +03:00
|
|
|
#define LOG_THIS thePciVgaAdapter->
|
|
|
|
|
|
|
|
bx_pcivga_c* thePciVgaAdapter = 0;
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
int libpcivga_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[])
|
2003-01-11 01:43:54 +03:00
|
|
|
{
|
2006-09-10 21:18:44 +04:00
|
|
|
thePciVgaAdapter = new bx_pcivga_c();
|
2003-01-11 01:43:54 +03:00
|
|
|
BX_REGISTER_DEVICE_DEVMODEL(plugin, type, thePciVgaAdapter, BX_PLUGIN_PCIVGA);
|
|
|
|
return 0; // Success
|
|
|
|
}
|
|
|
|
|
2006-09-10 21:18:44 +04:00
|
|
|
void libpcivga_LTX_plugin_fini(void)
|
|
|
|
{
|
|
|
|
delete thePciVgaAdapter;
|
|
|
|
}
|
2003-01-11 01:43:54 +03:00
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
bx_pcivga_c::bx_pcivga_c()
|
2003-01-11 01:43:54 +03:00
|
|
|
{
|
|
|
|
put("PCIVGA");
|
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
bx_pcivga_c::~bx_pcivga_c()
|
2003-01-11 01:43:54 +03:00
|
|
|
{
|
2006-09-10 21:18:44 +04:00
|
|
|
BX_DEBUG(("Exit"));
|
2003-01-11 01:43:54 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_pcivga_c::init(void)
|
2003-01-11 01:43:54 +03:00
|
|
|
{
|
|
|
|
// called once when bochs initializes
|
|
|
|
|
2004-06-29 23:24:34 +04:00
|
|
|
Bit8u devfunc = 0x00;
|
2005-06-04 21:44:59 +04:00
|
|
|
unsigned i;
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
DEV_register_pci_handlers(this, &devfunc, BX_PLUGIN_PCIVGA,
|
2003-01-11 01:43:54 +03:00
|
|
|
"Experimental PCI VGA");
|
|
|
|
|
2005-06-04 21:44:59 +04:00
|
|
|
for (i=0; i<256; i++) {
|
2003-01-11 01:43:54 +03:00
|
|
|
BX_PCIVGA_THIS s.pci_conf[i] = 0x0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// readonly registers
|
|
|
|
static const struct init_vals_t {
|
|
|
|
unsigned addr;
|
|
|
|
unsigned char val;
|
|
|
|
} init_vals[] = {
|
|
|
|
// Note that the values for vendor and device id are selected at random!
|
|
|
|
// There might actually be "real" values for "experimental" vendor and
|
|
|
|
// device that should be used!
|
|
|
|
{ 0x00, 0x34 }, { 0x01, 0x12 }, // 0x1234 - experimental vendor
|
|
|
|
{ 0x02, 0x11 }, { 0x03, 0x11 }, // 0x1111 - experimental device
|
|
|
|
{ 0x0a, 0x00 }, // class_sub VGA controller
|
|
|
|
{ 0x0b, 0x03 }, // class_base display
|
|
|
|
{ 0x0e, 0x00 } // header_type_generic
|
|
|
|
};
|
2005-06-04 21:44:59 +04:00
|
|
|
for (i = 0; i < sizeof(init_vals) / sizeof(*init_vals); ++i) {
|
2003-01-11 01:43:54 +03:00
|
|
|
BX_PCIVGA_THIS s.pci_conf[init_vals[i].addr] = init_vals[i].val;
|
|
|
|
}
|
2009-04-10 15:10:32 +04:00
|
|
|
WriteHostDWordToLittleEndian(&BX_PCIVGA_THIS s.pci_conf[0x10], 0x08);
|
|
|
|
BX_PCIVGA_THIS s.base_address = 0;
|
2003-01-11 01:43:54 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_pcivga_c::reset(unsigned type)
|
2003-01-11 01:43:54 +03:00
|
|
|
{
|
|
|
|
static const struct reset_vals_t {
|
|
|
|
unsigned addr;
|
|
|
|
unsigned char val;
|
|
|
|
} reset_vals[] = {
|
2009-01-23 01:29:23 +03:00
|
|
|
{ 0x04, 0x03 }, { 0x05, 0x00 }, // command_io + command_mem
|
|
|
|
{ 0x06, 0x00 }, { 0x07, 0x02 } // status_devsel_medium
|
2003-01-11 01:43:54 +03:00
|
|
|
};
|
2003-01-23 22:31:28 +03:00
|
|
|
for (unsigned i = 0; i < sizeof(reset_vals) / sizeof(*reset_vals); ++i) {
|
2006-05-27 19:54:49 +04:00
|
|
|
BX_PCIVGA_THIS s.pci_conf[reset_vals[i].addr] = reset_vals[i].val;
|
2003-01-11 01:43:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-27 19:54:49 +04:00
|
|
|
void bx_pcivga_c::register_state(void)
|
|
|
|
{
|
2007-09-28 23:52:08 +04:00
|
|
|
bx_list_c *list = new bx_list_c(SIM->get_bochs_root(), "pcivga", "PCI VGA Adapter State", 1);
|
2007-02-03 20:56:35 +03:00
|
|
|
register_pci_state(list, BX_PCIVGA_THIS s.pci_conf);
|
2006-05-27 19:54:49 +04:00
|
|
|
}
|
|
|
|
|
2009-04-10 15:10:32 +04:00
|
|
|
void bx_pcivga_c::after_restore_state(void)
|
|
|
|
{
|
2009-04-10 18:41:29 +04:00
|
|
|
if (DEV_vbe_set_base_addr(&BX_PCIVGA_THIS s.base_address,
|
|
|
|
&BX_PCIVGA_THIS s.pci_conf[0x10])) {
|
2009-04-10 15:10:32 +04:00
|
|
|
BX_INFO(("new base address: 0x%08x", BX_PCIVGA_THIS s.base_address));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
// pci configuration space read callback handler
|
|
|
|
Bit32u bx_pcivga_c::pci_read_handler(Bit8u address, unsigned io_len)
|
2003-01-11 01:43:54 +03:00
|
|
|
{
|
|
|
|
Bit32u value = 0;
|
|
|
|
|
|
|
|
if (io_len > 4 || io_len == 0) {
|
|
|
|
BX_DEBUG(("Experimental PCIVGA read register 0x%02x, len=%u !",
|
|
|
|
(unsigned) address, (unsigned) io_len));
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* pszName = " ";
|
|
|
|
switch (address) {
|
|
|
|
case 0x00: if (io_len == 2) {
|
|
|
|
pszName = "(vendor id) ";
|
|
|
|
} else if (io_len == 4) {
|
|
|
|
pszName = "(vendor + device) ";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x04: if (io_len == 2) {
|
|
|
|
pszName = "(command) ";
|
|
|
|
} else if (io_len == 4) {
|
|
|
|
pszName = "(command+status) ";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x08: if (io_len == 1) {
|
|
|
|
pszName = "(revision id) ";
|
|
|
|
} else if (io_len == 4) {
|
|
|
|
pszName = "(rev.+class code) ";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x0c: pszName = "(cache line size) "; break;
|
2009-01-23 01:29:23 +03:00
|
|
|
case 0x10: pszName = "(base address #0) "; break;
|
2003-01-11 01:43:54 +03:00
|
|
|
case 0x28: pszName = "(cardbus cis) "; break;
|
|
|
|
case 0x2c: pszName = "(subsys. vendor+) "; break;
|
|
|
|
case 0x30: pszName = "(rom base) "; break;
|
|
|
|
case 0x3c: pszName = "(interrupt line+) "; break;
|
|
|
|
case 0x3d: pszName = "(interrupt pin) "; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This odd code is to display only what bytes actually were read.
|
|
|
|
char szTmp[9];
|
|
|
|
char szTmp2[3];
|
|
|
|
szTmp[0] = '\0';
|
|
|
|
szTmp2[0] = '\0';
|
|
|
|
for (unsigned i=0; i<io_len; i++) {
|
|
|
|
value |= (BX_PCIVGA_THIS s.pci_conf[address+i] << (i*8));
|
|
|
|
|
|
|
|
sprintf(szTmp2, "%02x", (BX_PCIVGA_THIS s.pci_conf[address+i]));
|
|
|
|
strrev(szTmp2);
|
|
|
|
strcat(szTmp, szTmp2);
|
|
|
|
}
|
|
|
|
strrev(szTmp);
|
|
|
|
BX_DEBUG(("Experimental PCIVGA read register 0x%02x %svalue 0x%s",
|
|
|
|
address, pszName, szTmp));
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
// static pci configuration space write callback handler
|
|
|
|
void bx_pcivga_c::pci_write_handler(Bit8u address, Bit32u value, unsigned io_len)
|
2003-01-11 01:43:54 +03:00
|
|
|
{
|
2009-01-23 01:29:23 +03:00
|
|
|
unsigned i;
|
|
|
|
unsigned write_addr;
|
|
|
|
Bit8u new_value, old_value;
|
|
|
|
bx_bool baseaddr_change = 0;
|
|
|
|
|
|
|
|
if ((address >= 0x14) && (address < 0x34))
|
2003-01-11 01:43:54 +03:00
|
|
|
return;
|
2009-01-23 01:29:23 +03:00
|
|
|
if (io_len <= 4) {
|
|
|
|
// This odd code is to display only what bytes actually were written.
|
|
|
|
char szTmp[9];
|
|
|
|
char szTmp2[3];
|
|
|
|
szTmp[0] = '\0';
|
|
|
|
szTmp2[0] = '\0';
|
|
|
|
for (i = 0; i < io_len; i++) {
|
|
|
|
write_addr = address + i;
|
|
|
|
old_value = BX_PCIVGA_THIS s.pci_conf[write_addr];
|
|
|
|
new_value = (Bit8u)(value & 0xff);
|
|
|
|
switch (write_addr) {
|
|
|
|
case 0x04: // disallowing write to command
|
|
|
|
case 0x06: // disallowing write to status lo-byte (is that expected?)
|
|
|
|
new_value = old_value;
|
|
|
|
strcpy(szTmp2, "..");
|
|
|
|
break;
|
|
|
|
case 0x10: // base address #0
|
|
|
|
new_value = (new_value & 0xf0) | (old_value & 0x0f);
|
|
|
|
case 0x11: case 0x12: case 0x13:
|
|
|
|
baseaddr_change |= (old_value != new_value);
|
|
|
|
default:
|
|
|
|
sprintf(szTmp2, "%02x", new_value);
|
|
|
|
}
|
|
|
|
BX_PCIVGA_THIS s.pci_conf[write_addr] = new_value;
|
|
|
|
value >>= 8;
|
|
|
|
strrev(szTmp2);
|
|
|
|
strcat(szTmp, szTmp2);
|
2003-01-11 01:43:54 +03:00
|
|
|
}
|
2009-01-23 01:29:23 +03:00
|
|
|
if (baseaddr_change) {
|
2009-04-10 18:41:29 +04:00
|
|
|
if (DEV_vbe_set_base_addr(&BX_PCIVGA_THIS s.base_address,
|
|
|
|
&BX_PCIVGA_THIS s.pci_conf[0x10])) {
|
2009-04-10 15:10:32 +04:00
|
|
|
BX_INFO(("new base address: 0x%08x", BX_PCIVGA_THIS s.base_address));
|
|
|
|
}
|
2009-01-23 01:29:23 +03:00
|
|
|
}
|
|
|
|
strrev(szTmp);
|
|
|
|
BX_DEBUG(("Experimental PCIVGA write register 0x%02x value 0x%s", address, szTmp));
|
2003-01-11 01:43:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-06 19:49:55 +04:00
|
|
|
#endif // BX_SUPPORT_PCI && BX_SUPPORT_PCIVGA
|