2004-06-10 00:55:58 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2004-06-10 00:55:58 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2009-12-04 22:50:29 +03:00
|
|
|
// Copyright (C) 2002-2009 The Bochs Project
|
2004-06-10 00:55:58 +04:00
|
|
|
//
|
|
|
|
// 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
|
2004-06-10 00:55:58 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// i440FX Support - PCI IDE controller (PIIX3)
|
|
|
|
//
|
|
|
|
|
|
|
|
// 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
|
2004-06-10 00:55:58 +04: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
|
2004-06-10 00:55:58 +04:00
|
|
|
|
2009-01-03 11:55:00 +03:00
|
|
|
#include "pci.h"
|
|
|
|
#include "pci_ide.h"
|
|
|
|
|
2004-06-10 00:55:58 +04:00
|
|
|
#define LOG_THIS thePciIdeController->
|
|
|
|
|
|
|
|
bx_pci_ide_c *thePciIdeController = NULL;
|
|
|
|
|
2005-02-06 16:05:20 +03:00
|
|
|
const Bit8u bmdma_iomask[16] = {1, 0, 1, 0, 4, 0, 0, 0, 1, 0, 1, 0, 4, 0, 0, 0};
|
2004-07-12 00:38:48 +04:00
|
|
|
|
2006-09-10 21:18:44 +04:00
|
|
|
int libpci_ide_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[])
|
2004-06-10 00:55:58 +04:00
|
|
|
{
|
2006-09-10 21:18:44 +04:00
|
|
|
thePciIdeController = new bx_pci_ide_c();
|
2004-06-10 00:55:58 +04:00
|
|
|
bx_devices.pluginPciIdeController = thePciIdeController;
|
|
|
|
BX_REGISTER_DEVICE_DEVMODEL(plugin, type, thePciIdeController, BX_PLUGIN_PCI_IDE);
|
|
|
|
return(0); // Success
|
|
|
|
}
|
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
void libpci_ide_LTX_plugin_fini(void)
|
2004-06-10 00:55:58 +04:00
|
|
|
{
|
2006-09-10 21:18:44 +04:00
|
|
|
delete thePciIdeController;
|
2004-06-10 00:55:58 +04:00
|
|
|
}
|
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
bx_pci_ide_c::bx_pci_ide_c()
|
2004-06-10 00:55:58 +04:00
|
|
|
{
|
|
|
|
put("PIDE");
|
2005-02-08 21:32:27 +03:00
|
|
|
s.bmdma[0].timer_index = BX_NULL_TIMER_HANDLE;
|
|
|
|
s.bmdma[1].timer_index = BX_NULL_TIMER_HANDLE;
|
2005-10-29 16:35:01 +04:00
|
|
|
s.bmdma[0].buffer = NULL;
|
|
|
|
s.bmdma[1].buffer = NULL;
|
2004-06-10 00:55:58 +04:00
|
|
|
}
|
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
bx_pci_ide_c::~bx_pci_ide_c()
|
2004-06-10 00:55:58 +04:00
|
|
|
{
|
2005-10-29 16:35:01 +04:00
|
|
|
if (s.bmdma[0].buffer != NULL) {
|
|
|
|
delete [] s.bmdma[0].buffer;
|
|
|
|
}
|
|
|
|
if (s.bmdma[1].buffer != NULL) {
|
|
|
|
delete [] s.bmdma[1].buffer;
|
|
|
|
}
|
2006-09-10 21:18:44 +04:00
|
|
|
BX_DEBUG(("Exit"));
|
2004-06-10 00:55:58 +04:00
|
|
|
}
|
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
void bx_pci_ide_c::init(void)
|
2004-06-10 00:55:58 +04:00
|
|
|
{
|
2005-02-08 21:32:27 +03:00
|
|
|
unsigned i;
|
2004-06-10 00:55:58 +04:00
|
|
|
|
2004-06-29 23:24:34 +04:00
|
|
|
Bit8u devfunc = BX_PCI_DEVICE(1,1);
|
2008-01-27 01:24:03 +03:00
|
|
|
DEV_register_pci_handlers(this, &devfunc,
|
2006-03-08 00:11:20 +03:00
|
|
|
BX_PLUGIN_PCI_IDE, "PIIX3 PCI IDE controller");
|
2004-06-10 00:55:58 +04:00
|
|
|
|
2005-02-08 21:32:27 +03:00
|
|
|
// register BM-DMA timer
|
|
|
|
for (i=0; i<2; i++) {
|
|
|
|
if (BX_PIDE_THIS s.bmdma[i].timer_index == BX_NULL_TIMER_HANDLE) {
|
|
|
|
BX_PIDE_THIS s.bmdma[i].timer_index =
|
|
|
|
DEV_register_timer(this, timer_handler, 1000, 0,0, "PIIX3 BM-DMA timer");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-16 23:59:03 +04:00
|
|
|
BX_PIDE_THIS s.bmdma[0].buffer = new Bit8u[0x20000];
|
|
|
|
BX_PIDE_THIS s.bmdma[1].buffer = new Bit8u[0x20000];
|
2005-10-29 16:35:01 +04:00
|
|
|
|
2005-02-08 21:32:27 +03:00
|
|
|
for (i=0; i<256; i++)
|
2011-06-23 19:56:02 +04:00
|
|
|
BX_PIDE_THIS pci_conf[i] = 0x0;
|
2004-06-10 00:55:58 +04:00
|
|
|
// readonly registers
|
2011-06-23 19:56:02 +04:00
|
|
|
BX_PIDE_THIS pci_conf[0x00] = 0x86;
|
|
|
|
BX_PIDE_THIS pci_conf[0x01] = 0x80;
|
|
|
|
BX_PIDE_THIS pci_conf[0x02] = 0x10;
|
|
|
|
BX_PIDE_THIS pci_conf[0x03] = 0x70;
|
|
|
|
BX_PIDE_THIS pci_conf[0x09] = 0x80;
|
|
|
|
BX_PIDE_THIS pci_conf[0x0a] = 0x01;
|
|
|
|
BX_PIDE_THIS pci_conf[0x0b] = 0x01;
|
|
|
|
BX_PIDE_THIS pci_conf[0x0e] = 0x00;
|
|
|
|
BX_PIDE_THIS pci_conf[0x20] = 0x01;
|
2011-06-25 16:43:27 +04:00
|
|
|
BX_PIDE_THIS pci_base_address[4] = 0;
|
2004-06-10 00:55:58 +04:00
|
|
|
}
|
|
|
|
|
2006-05-27 19:54:49 +04:00
|
|
|
void bx_pci_ide_c::reset(unsigned type)
|
2004-06-10 00:55:58 +04:00
|
|
|
{
|
2011-06-23 19:56:02 +04:00
|
|
|
BX_PIDE_THIS pci_conf[0x04] = 0x01;
|
|
|
|
BX_PIDE_THIS pci_conf[0x06] = 0x80;
|
|
|
|
BX_PIDE_THIS pci_conf[0x07] = 0x02;
|
2006-02-26 22:11:20 +03:00
|
|
|
if (SIM->get_param_bool(BXPN_ATA0_ENABLED)->get()) {
|
2011-06-23 19:56:02 +04:00
|
|
|
BX_PIDE_THIS pci_conf[0x40] = 0x00;
|
|
|
|
BX_PIDE_THIS pci_conf[0x41] = 0x80;
|
2004-06-10 00:55:58 +04:00
|
|
|
}
|
2006-02-26 22:11:20 +03:00
|
|
|
if (SIM->get_param_bool(BXPN_ATA1_ENABLED)->get()) {
|
2011-06-23 19:56:02 +04:00
|
|
|
BX_PIDE_THIS pci_conf[0x42] = 0x00;
|
|
|
|
BX_PIDE_THIS pci_conf[0x43] = 0x80;
|
2004-06-10 00:55:58 +04:00
|
|
|
}
|
2011-06-23 19:56:02 +04:00
|
|
|
BX_PIDE_THIS pci_conf[0x44] = 0x00;
|
2005-02-06 16:05:20 +03:00
|
|
|
for (unsigned i=0; i<2; i++) {
|
2005-02-08 21:32:27 +03:00
|
|
|
BX_PIDE_THIS s.bmdma[i].cmd_ssbm = 0;
|
|
|
|
BX_PIDE_THIS s.bmdma[i].cmd_rwcon = 0;
|
|
|
|
BX_PIDE_THIS s.bmdma[i].status = 0;
|
|
|
|
BX_PIDE_THIS s.bmdma[i].dtpr = 0;
|
|
|
|
BX_PIDE_THIS s.bmdma[i].prd_current = 0;
|
2005-10-29 16:35:01 +04:00
|
|
|
BX_PIDE_THIS s.bmdma[i].buffer_top = BX_PIDE_THIS s.bmdma[i].buffer;
|
|
|
|
BX_PIDE_THIS s.bmdma[i].buffer_idx = BX_PIDE_THIS s.bmdma[i].buffer;
|
2005-02-06 16:05:20 +03:00
|
|
|
}
|
2004-06-10 00:55:58 +04:00
|
|
|
}
|
|
|
|
|
2007-09-28 23:52:08 +04:00
|
|
|
// save/restore code begin
|
2006-05-27 19:54:49 +04:00
|
|
|
void bx_pci_ide_c::register_state(void)
|
|
|
|
{
|
|
|
|
char name[6];
|
|
|
|
|
2007-09-28 23:52:08 +04:00
|
|
|
bx_list_c *list = new bx_list_c(SIM->get_bochs_root(), "pci_ide", "PCI IDE Controller State", 5);
|
2006-05-28 22:14:05 +04:00
|
|
|
|
2011-06-23 19:56:02 +04:00
|
|
|
register_pci_state(list);
|
2006-05-28 22:14:05 +04:00
|
|
|
|
2009-08-16 23:59:03 +04:00
|
|
|
new bx_shadow_data_c(list, "buffer0", BX_PIDE_THIS s.bmdma[0].buffer, 0x20000);
|
|
|
|
new bx_shadow_data_c(list, "buffer1", BX_PIDE_THIS s.bmdma[1].buffer, 0x20000);
|
2006-05-28 22:14:05 +04:00
|
|
|
|
2007-02-03 20:56:35 +03:00
|
|
|
for (unsigned i=0; i<2; i++) {
|
2006-05-27 19:54:49 +04:00
|
|
|
sprintf(name, "%d", i);
|
2006-05-30 02:33:38 +04:00
|
|
|
bx_list_c *ctrl = new bx_list_c(list, name, 7);
|
2006-05-28 22:14:05 +04:00
|
|
|
BXRS_PARAM_BOOL(ctrl, cmd_ssbm, BX_PIDE_THIS s.bmdma[i].cmd_ssbm);
|
|
|
|
BXRS_PARAM_BOOL(ctrl, cmd_rwcon, BX_PIDE_THIS s.bmdma[i].cmd_rwcon);
|
|
|
|
BXRS_HEX_PARAM_FIELD(ctrl, status, BX_PIDE_THIS s.bmdma[i].status);
|
|
|
|
BXRS_HEX_PARAM_FIELD(ctrl, dtpr, BX_PIDE_THIS s.bmdma[i].dtpr);
|
|
|
|
BXRS_HEX_PARAM_FIELD(ctrl, prd_current, BX_PIDE_THIS s.bmdma[i].prd_current);
|
2008-01-27 01:24:03 +03:00
|
|
|
BXRS_PARAM_SPECIAL32(ctrl, buffer_top,
|
2006-05-28 22:14:05 +04:00
|
|
|
BX_PIDE_THIS param_save_handler, BX_PIDE_THIS param_restore_handler);
|
2008-01-27 01:24:03 +03:00
|
|
|
BXRS_PARAM_SPECIAL32(ctrl, buffer_idx,
|
2006-05-28 22:14:05 +04:00
|
|
|
BX_PIDE_THIS param_save_handler, BX_PIDE_THIS param_restore_handler);
|
2006-05-27 19:54:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_pci_ide_c::after_restore_state(void)
|
|
|
|
{
|
|
|
|
if (DEV_pci_set_base_io(BX_PIDE_THIS_PTR, read_handler, write_handler,
|
2011-06-25 16:43:27 +04:00
|
|
|
&BX_PIDE_THIS pci_base_address[4], &BX_PIDE_THIS pci_conf[0x20],
|
2006-05-28 22:14:05 +04:00
|
|
|
16, &bmdma_iomask[0], "PIIX3 PCI IDE controller"))
|
|
|
|
{
|
2011-06-25 16:43:27 +04:00
|
|
|
BX_INFO(("new BM-DMA address: 0x%04x", BX_PIDE_THIS pci_base_address[4]));
|
2006-05-27 19:54:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-16 22:29:45 +04:00
|
|
|
Bit64s bx_pci_ide_c::param_save_handler(void *devptr, bx_param_c *param)
|
2006-05-27 19:54:49 +04:00
|
|
|
{
|
|
|
|
#if !BX_USE_PIDE_SMF
|
|
|
|
bx_pci_ide_c *class_ptr = (bx_pci_ide_c *) devptr;
|
|
|
|
return class_ptr->param_save(param, val);
|
|
|
|
}
|
|
|
|
|
2009-10-16 22:29:45 +04:00
|
|
|
Bit64s bx_pci_ide_c::param_save(bx_param_c *param)
|
2006-05-27 19:54:49 +04:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(devptr);
|
|
|
|
#endif // !BX_USE_PIDE_SMF
|
|
|
|
int chan = atoi(param->get_parent()->get_name());
|
2009-10-16 22:29:45 +04:00
|
|
|
Bit64s val = 0;
|
2006-05-27 19:54:49 +04:00
|
|
|
if (!strcmp(param->get_name(), "buffer_top")) {
|
|
|
|
val = (Bit32u)(BX_PIDE_THIS s.bmdma[chan].buffer_top - BX_PIDE_THIS s.bmdma[chan].buffer);
|
|
|
|
} else if (!strcmp(param->get_name(), "buffer_idx")) {
|
|
|
|
val = (Bit32u)(BX_PIDE_THIS s.bmdma[chan].buffer_idx - BX_PIDE_THIS s.bmdma[chan].buffer);
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2009-10-16 22:29:45 +04:00
|
|
|
void bx_pci_ide_c::param_restore_handler(void *devptr, bx_param_c *param, Bit64s val)
|
2006-05-27 19:54:49 +04:00
|
|
|
{
|
|
|
|
#if !BX_USE_PIDE_SMF
|
|
|
|
bx_pci_ide_c *class_ptr = (bx_pci_ide_c *) devptr;
|
2009-10-16 22:29:45 +04:00
|
|
|
class_ptr->param_restore(param, val);
|
2006-05-27 19:54:49 +04:00
|
|
|
}
|
|
|
|
|
2009-10-16 22:29:45 +04:00
|
|
|
void bx_pci_ide_c::param_restore(bx_param_c *param, Bit64s val)
|
2006-05-27 19:54:49 +04:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(devptr);
|
|
|
|
#endif // !BX_USE_PIDE_SMF
|
|
|
|
int chan = atoi(param->get_parent()->get_name());
|
|
|
|
if (!strcmp(param->get_name(), "buffer_top")) {
|
|
|
|
BX_PIDE_THIS s.bmdma[chan].buffer_top = BX_PIDE_THIS s.bmdma[chan].buffer + val;
|
|
|
|
} else if (!strcmp(param->get_name(), "buffer_idx")) {
|
|
|
|
BX_PIDE_THIS s.bmdma[chan].buffer_idx = BX_PIDE_THIS s.bmdma[chan].buffer + val;
|
|
|
|
}
|
|
|
|
}
|
2007-09-28 23:52:08 +04:00
|
|
|
// save/restore code end
|
2006-05-27 19:54:49 +04:00
|
|
|
|
|
|
|
bx_bool bx_pci_ide_c::bmdma_present(void)
|
2005-02-08 21:32:27 +03:00
|
|
|
{
|
2011-06-25 16:43:27 +04:00
|
|
|
return (BX_PIDE_THIS pci_base_address[4] > 0);
|
2005-02-08 21:32:27 +03:00
|
|
|
}
|
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
void bx_pci_ide_c::bmdma_set_irq(Bit8u channel)
|
2005-09-05 22:32:23 +04:00
|
|
|
{
|
|
|
|
if (channel < 2) {
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].status |= 0x04;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
void bx_pci_ide_c::timer_handler(void *this_ptr)
|
2005-02-08 21:32:27 +03:00
|
|
|
{
|
|
|
|
bx_pci_ide_c *class_ptr = (bx_pci_ide_c *) this_ptr;
|
|
|
|
class_ptr->timer();
|
|
|
|
}
|
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
void bx_pci_ide_c::timer()
|
2005-02-08 21:32:27 +03:00
|
|
|
{
|
|
|
|
int timer_id, count;
|
|
|
|
Bit8u channel;
|
2008-07-06 18:15:41 +04:00
|
|
|
Bit32u size, sector_size;
|
2005-02-08 21:32:27 +03:00
|
|
|
struct {
|
2008-06-12 00:59:50 +04:00
|
|
|
Bit32u addr;
|
2005-02-08 21:32:27 +03:00
|
|
|
Bit32u size;
|
|
|
|
} prd;
|
|
|
|
|
|
|
|
timer_id = bx_pc_system.triggeredTimerID();
|
|
|
|
if (timer_id == BX_PIDE_THIS s.bmdma[0].timer_index) {
|
|
|
|
channel = 0;
|
|
|
|
} else {
|
|
|
|
channel = 1;
|
|
|
|
}
|
|
|
|
if (((BX_PIDE_THIS s.bmdma[channel].status & 0x01) == 0) ||
|
|
|
|
(BX_PIDE_THIS s.bmdma[channel].prd_current == 0)) {
|
|
|
|
return;
|
|
|
|
}
|
2008-12-03 00:38:51 +03:00
|
|
|
DEV_MEM_READ_PHYSICAL(BX_PIDE_THIS s.bmdma[channel].prd_current, 4, (Bit8u *)&prd.addr);
|
|
|
|
DEV_MEM_READ_PHYSICAL(BX_PIDE_THIS s.bmdma[channel].prd_current+4, 4, (Bit8u *)&prd.size);
|
2005-02-08 21:32:27 +03:00
|
|
|
size = prd.size & 0xfffe;
|
|
|
|
if (size == 0) {
|
|
|
|
size = 0x10000;
|
|
|
|
}
|
|
|
|
if (BX_PIDE_THIS s.bmdma[channel].cmd_rwcon) {
|
2005-10-29 16:35:01 +04:00
|
|
|
BX_DEBUG(("READ DMA to addr=0x%08x, size=0x%08x", prd.addr, size));
|
|
|
|
count = size - (BX_PIDE_THIS s.bmdma[channel].buffer_top - BX_PIDE_THIS s.bmdma[channel].buffer_idx);
|
|
|
|
while (count > 0) {
|
2008-07-06 18:15:41 +04:00
|
|
|
sector_size = count;
|
2005-10-30 17:14:03 +03:00
|
|
|
if (DEV_hd_bmdma_read_sector(channel, BX_PIDE_THIS s.bmdma[channel].buffer_top, §or_size)) {
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].buffer_top += sector_size;
|
|
|
|
count -= sector_size;
|
2005-02-08 21:32:27 +03:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2005-10-29 16:35:01 +04:00
|
|
|
};
|
2005-02-08 21:32:27 +03:00
|
|
|
if (count > 0) {
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].status &= ~0x01;
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].status |= 0x06;
|
|
|
|
return;
|
|
|
|
} else {
|
2011-12-02 23:41:54 +04:00
|
|
|
DEV_MEM_WRITE_PHYSICAL_DMA(prd.addr, size, BX_PIDE_THIS s.bmdma[channel].buffer_idx);
|
2005-10-29 16:35:01 +04:00
|
|
|
BX_PIDE_THIS s.bmdma[channel].buffer_idx += size;
|
2005-02-08 21:32:27 +03:00
|
|
|
}
|
|
|
|
} else {
|
2005-10-29 16:35:01 +04:00
|
|
|
BX_DEBUG(("WRITE DMA from addr=0x%08x, size=0x%08x", prd.addr, size));
|
2011-12-02 23:41:54 +04:00
|
|
|
DEV_MEM_READ_PHYSICAL_DMA(prd.addr, size, BX_PIDE_THIS s.bmdma[channel].buffer_top);
|
2005-10-29 16:35:01 +04:00
|
|
|
BX_PIDE_THIS s.bmdma[channel].buffer_top += size;
|
|
|
|
count = BX_PIDE_THIS s.bmdma[channel].buffer_top - BX_PIDE_THIS s.bmdma[channel].buffer_idx;
|
|
|
|
while (count > 511) {
|
|
|
|
if (DEV_hd_bmdma_write_sector(channel, BX_PIDE_THIS s.bmdma[channel].buffer_idx)) {
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].buffer_idx += 512;
|
2005-02-08 21:32:27 +03:00
|
|
|
count -= 512;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2005-10-29 16:35:01 +04:00
|
|
|
};
|
|
|
|
if (count > 511) {
|
2005-02-08 21:32:27 +03:00
|
|
|
BX_PIDE_THIS s.bmdma[channel].status &= ~0x01;
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].status |= 0x06;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (prd.size & 0x80000000) {
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].status &= ~0x01;
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].status |= 0x04;
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].prd_current = 0;
|
|
|
|
DEV_hd_bmdma_complete(channel);
|
|
|
|
} else {
|
2011-03-06 23:51:52 +03:00
|
|
|
// To avoid buffer overflow reset buffer pointers and copy data if necessary
|
|
|
|
count = BX_PIDE_THIS s.bmdma[channel].buffer_top - BX_PIDE_THIS s.bmdma[channel].buffer_idx;
|
|
|
|
if (count > 0) {
|
|
|
|
memcpy(BX_PIDE_THIS s.bmdma[channel].buffer, BX_PIDE_THIS s.bmdma[channel].buffer_idx, count);
|
|
|
|
}
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].buffer_top = BX_PIDE_THIS s.bmdma[channel].buffer + count;
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].buffer_idx = BX_PIDE_THIS s.bmdma[channel].buffer;
|
|
|
|
// Prepare for next PRD
|
2005-02-08 21:32:27 +03:00
|
|
|
BX_PIDE_THIS s.bmdma[channel].prd_current += 8;
|
2008-12-03 00:38:51 +03:00
|
|
|
DEV_MEM_READ_PHYSICAL(BX_PIDE_THIS s.bmdma[channel].prd_current, 4, (Bit8u *)&prd.addr);
|
|
|
|
DEV_MEM_READ_PHYSICAL(BX_PIDE_THIS s.bmdma[channel].prd_current+4, 4, (Bit8u *)&prd.size);
|
2005-10-30 22:18:59 +03:00
|
|
|
size = prd.size & 0xfffe;
|
|
|
|
if (size == 0) {
|
|
|
|
size = 0x10000;
|
|
|
|
}
|
|
|
|
bx_pc_system.activate_timer(BX_PIDE_THIS s.bmdma[channel].timer_index, (size >> 4) | 0x10, 0);
|
2005-02-08 21:32:27 +03:00
|
|
|
}
|
|
|
|
}
|
2004-06-10 00:55:58 +04:00
|
|
|
|
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
// static IO port read callback handler
|
|
|
|
// redirects to non-static class handler to avoid virtual functions
|
2004-06-10 00:55:58 +04:00
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
Bit32u bx_pci_ide_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len)
|
2004-06-10 00:55:58 +04:00
|
|
|
{
|
|
|
|
#if !BX_USE_PIDE_SMF
|
|
|
|
bx_pci_ide_c *class_ptr = (bx_pci_ide_c *) this_ptr;
|
2006-03-06 22:23:13 +03:00
|
|
|
return class_ptr->read(address, io_len);
|
2004-06-10 00:55:58 +04:00
|
|
|
}
|
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
Bit32u bx_pci_ide_c::read(Bit32u address, unsigned io_len)
|
2004-06-10 00:55:58 +04:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
#endif // !BX_USE_PIDE_SMF
|
2005-02-06 16:05:20 +03:00
|
|
|
Bit8u offset, channel;
|
|
|
|
Bit32u value = 0xffffffff;
|
|
|
|
|
2011-06-25 16:43:27 +04:00
|
|
|
offset = address - BX_PIDE_THIS pci_base_address[4];
|
2005-02-06 16:05:20 +03:00
|
|
|
channel = (offset >> 3);
|
|
|
|
offset &= 0x07;
|
|
|
|
switch (offset) {
|
|
|
|
case 0x00:
|
2005-02-08 21:32:27 +03:00
|
|
|
value = BX_PIDE_THIS s.bmdma[channel].cmd_ssbm |
|
|
|
|
(BX_PIDE_THIS s.bmdma[channel].cmd_rwcon << 3);
|
|
|
|
BX_DEBUG(("BM-DMA read command register, channel %d, value = 0x%02x", channel, value));
|
2005-02-06 16:05:20 +03:00
|
|
|
break;
|
|
|
|
case 0x02:
|
2005-02-08 21:32:27 +03:00
|
|
|
value = BX_PIDE_THIS s.bmdma[channel].status;
|
|
|
|
BX_DEBUG(("BM-DMA read status register, channel %d, value = 0x%02x", channel, value));
|
2005-02-06 16:05:20 +03:00
|
|
|
break;
|
|
|
|
case 0x04:
|
2005-02-08 21:32:27 +03:00
|
|
|
value = BX_PIDE_THIS s.bmdma[channel].dtpr;
|
|
|
|
BX_DEBUG(("BM-DMA read DTP register, channel %d, value = 0x%04x", channel, value));
|
2005-02-06 16:05:20 +03:00
|
|
|
break;
|
|
|
|
}
|
2004-06-10 00:55:58 +04:00
|
|
|
|
2005-02-06 16:05:20 +03:00
|
|
|
return value;
|
2004-06-10 00:55:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
// static IO port write callback handler
|
|
|
|
// redirects to non-static class handler to avoid virtual functions
|
2004-06-10 00:55:58 +04:00
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
void bx_pci_ide_c::write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len)
|
2004-06-10 00:55:58 +04:00
|
|
|
{
|
|
|
|
#if !BX_USE_PIDE_SMF
|
|
|
|
bx_pci_ide_c *class_ptr = (bx_pci_ide_c *) this_ptr;
|
|
|
|
|
|
|
|
class_ptr->write(address, value, io_len);
|
|
|
|
}
|
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
void bx_pci_ide_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
2004-06-10 00:55:58 +04:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
#endif // !BX_USE_PIDE_SMF
|
2005-02-06 16:05:20 +03:00
|
|
|
Bit8u offset, channel;
|
|
|
|
|
2011-06-25 16:43:27 +04:00
|
|
|
offset = address - BX_PIDE_THIS pci_base_address[4];
|
2005-02-06 16:05:20 +03:00
|
|
|
channel = (offset >> 3);
|
|
|
|
offset &= 0x07;
|
|
|
|
switch (offset) {
|
|
|
|
case 0x00:
|
2005-10-24 00:42:20 +04:00
|
|
|
BX_DEBUG(("BM-DMA write command register, channel %d, value = 0x%02x", channel, value));
|
2005-02-08 21:32:27 +03:00
|
|
|
BX_PIDE_THIS s.bmdma[channel].cmd_rwcon = (value >> 3) & 1;
|
|
|
|
if ((value & 0x01) && !BX_PIDE_THIS s.bmdma[channel].cmd_ssbm) {
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].cmd_ssbm = 1;
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].status |= 0x01;
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].prd_current = BX_PIDE_THIS s.bmdma[channel].dtpr;
|
2005-10-29 16:35:01 +04:00
|
|
|
BX_PIDE_THIS s.bmdma[channel].buffer_top = BX_PIDE_THIS s.bmdma[channel].buffer;
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].buffer_idx = BX_PIDE_THIS s.bmdma[channel].buffer;
|
2005-10-30 22:18:59 +03:00
|
|
|
bx_pc_system.activate_timer(BX_PIDE_THIS s.bmdma[channel].timer_index, 1000, 0);
|
2005-02-08 21:32:27 +03:00
|
|
|
} else if (!(value & 0x01) && BX_PIDE_THIS s.bmdma[channel].cmd_ssbm) {
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].cmd_ssbm = 0;
|
|
|
|
BX_PIDE_THIS s.bmdma[channel].status &= ~0x01;
|
|
|
|
}
|
2005-02-06 16:05:20 +03:00
|
|
|
break;
|
|
|
|
case 0x02:
|
2005-02-08 21:32:27 +03:00
|
|
|
BX_PIDE_THIS s.bmdma[channel].status = (value & 0x60)
|
|
|
|
| (BX_PIDE_THIS s.bmdma[channel].status & 0x01)
|
|
|
|
| (BX_PIDE_THIS s.bmdma[channel].status & (~value & 0x06));
|
2005-09-05 22:32:23 +04:00
|
|
|
BX_DEBUG(("BM-DMA write status register, channel %d, value = 0x%02x", channel, value));
|
2005-02-06 16:05:20 +03:00
|
|
|
break;
|
|
|
|
case 0x04:
|
2005-02-08 21:32:27 +03:00
|
|
|
BX_PIDE_THIS s.bmdma[channel].dtpr = value & 0xfffffffc;
|
2005-10-29 16:35:01 +04:00
|
|
|
BX_DEBUG(("BM-DMA write DTP register, channel %d, value = 0x%04x", channel, value));
|
2005-02-06 16:05:20 +03:00
|
|
|
break;
|
|
|
|
}
|
2004-06-10 00:55:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
// pci configuration space read callback handler
|
|
|
|
Bit32u bx_pci_ide_c::pci_read_handler(Bit8u address, unsigned io_len)
|
2004-06-10 00:55:58 +04:00
|
|
|
{
|
|
|
|
Bit32u value = 0;
|
|
|
|
|
2009-04-21 21:53:29 +04:00
|
|
|
for (unsigned i=0; i<io_len; i++) {
|
2011-06-23 19:56:02 +04:00
|
|
|
value |= (BX_PIDE_THIS pci_conf[address+i] << (i*8));
|
2005-09-23 01:12:26 +04:00
|
|
|
}
|
2009-04-22 22:37:06 +04:00
|
|
|
BX_DEBUG(("PIIX3 PCI IDE read register 0x%02x value 0x%08x", address, value));
|
2009-04-21 21:53:29 +04:00
|
|
|
return value;
|
2004-06-10 00:55:58 +04:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
// pci configuration space write callback handler
|
|
|
|
void bx_pci_ide_c::pci_write_handler(Bit8u address, Bit32u value, unsigned io_len)
|
2004-06-10 00:55:58 +04:00
|
|
|
{
|
|
|
|
Bit8u value8, oldval;
|
2005-02-06 16:05:20 +03:00
|
|
|
bx_bool bmdma_change = 0;
|
2004-06-10 00:55:58 +04:00
|
|
|
|
2005-09-18 13:01:05 +04:00
|
|
|
if (((address >= 0x10) && (address < 0x20)) ||
|
2005-11-15 20:19:28 +03:00
|
|
|
((address > 0x23) && (address < 0x40)))
|
2005-09-18 13:01:05 +04:00
|
|
|
return;
|
2009-04-21 21:53:29 +04:00
|
|
|
for (unsigned i=0; i<io_len; i++) {
|
2011-06-23 19:56:02 +04:00
|
|
|
oldval = BX_PIDE_THIS pci_conf[address+i];
|
2009-04-21 21:53:29 +04:00
|
|
|
value8 = (value >> (i*8)) & 0xFF;
|
|
|
|
switch (address+i) {
|
|
|
|
case 0x05:
|
|
|
|
case 0x06:
|
|
|
|
break;
|
|
|
|
case 0x04:
|
2011-06-23 19:56:02 +04:00
|
|
|
BX_PIDE_THIS pci_conf[address+i] = value8 & 0x05;
|
2009-04-21 21:53:29 +04:00
|
|
|
break;
|
|
|
|
case 0x20:
|
|
|
|
value8 = (value8 & 0xfc) | 0x01;
|
|
|
|
case 0x21:
|
|
|
|
case 0x22:
|
|
|
|
case 0x23:
|
|
|
|
bmdma_change |= (value8 != oldval);
|
|
|
|
default:
|
2011-06-23 19:56:02 +04:00
|
|
|
BX_PIDE_THIS pci_conf[address+i] = value8;
|
2009-04-21 21:53:29 +04:00
|
|
|
BX_DEBUG(("PIIX3 PCI IDE write register 0x%02x value 0x%02x", address+i,
|
|
|
|
value8));
|
2004-06-10 00:55:58 +04:00
|
|
|
}
|
2009-04-21 21:53:29 +04:00
|
|
|
}
|
|
|
|
if (bmdma_change) {
|
|
|
|
if (DEV_pci_set_base_io(BX_PIDE_THIS_PTR, read_handler, write_handler,
|
2011-06-25 16:43:27 +04:00
|
|
|
&BX_PIDE_THIS pci_base_address[4], &BX_PIDE_THIS pci_conf[0x20],
|
2009-04-21 21:53:29 +04:00
|
|
|
16, &bmdma_iomask[0], "PIIX3 PCI IDE controller")) {
|
2011-06-25 16:43:27 +04:00
|
|
|
BX_INFO(("new BM-DMA address: 0x%04x", BX_PIDE_THIS pci_base_address[4]));
|
2004-06-10 00:55:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-06 19:49:55 +04:00
|
|
|
#endif /* BX_SUPPORT_PCI */
|