rtoss

Subversion Repositories:
Compare Path: Rev
With Path: Rev
/qemu-pc9821/qemu/hw/ne2000.c @ 78  →  /qemu-pc9821/qemu/hw/ne2000.c @ 79
/qemu-pc9821/qemu/hw/ne2000.c
@@ -25,6 +25,7 @@
#include "pci.h"
#include "net.h"
#include "ne2000.h"
#include "loader.h"
 
/* debug NE2000 card */
//#define DEBUG_NE2000
@@ -126,7 +127,7 @@
int i;
 
s->isr = ENISR_RESET;
memcpy(s->mem, s->macaddr, 6);
memcpy(s->mem, &s->c.macaddr, 6);
s->mem[14] = 0x57;
s->mem[15] = 0x57;
 
@@ -622,95 +623,58 @@
return 0;
}
 
void ne2000_save(QEMUFile* f, void* opaque)
static int ne2000_post_load(void* opaque, int version_id)
{
NE2000State* s = opaque;
uint32_t tmp;
NE2000State* s = opaque;
 
qemu_put_8s(f, &s->rxcr);
 
qemu_put_8s(f, &s->cmd);
qemu_put_be32s(f, &s->start);
qemu_put_be32s(f, &s->stop);
qemu_put_8s(f, &s->boundary);
qemu_put_8s(f, &s->tsr);
qemu_put_8s(f, &s->tpsr);
qemu_put_be16s(f, &s->tcnt);
qemu_put_be16s(f, &s->rcnt);
qemu_put_be32s(f, &s->rsar);
qemu_put_8s(f, &s->rsr);
qemu_put_8s(f, &s->isr);
qemu_put_8s(f, &s->dcfg);
qemu_put_8s(f, &s->imr);
qemu_put_buffer(f, s->phys, 6);
qemu_put_8s(f, &s->curpag);
qemu_put_buffer(f, s->mult, 8);
tmp = 0;
qemu_put_be32s(f, &tmp); /* ignored, was irq */
qemu_put_buffer(f, s->mem, NE2000_MEM_SIZE);
if (version_id < 2) {
s->rxcr = 0x0c;
}
return 0;
}
 
int ne2000_load(QEMUFile* f, void* opaque, int version_id)
{
NE2000State* s = opaque;
uint32_t tmp;
const VMStateDescription vmstate_ne2000 = {
.name = "ne2000",
.version_id = 2,
.minimum_version_id = 0,
.minimum_version_id_old = 0,
.post_load = ne2000_post_load,
.fields = (VMStateField []) {
VMSTATE_UINT8_V(rxcr, NE2000State, 2),
VMSTATE_UINT8(cmd, NE2000State),
VMSTATE_UINT32(start, NE2000State),
VMSTATE_UINT32(stop, NE2000State),
VMSTATE_UINT8(boundary, NE2000State),
VMSTATE_UINT8(tsr, NE2000State),
VMSTATE_UINT8(tpsr, NE2000State),
VMSTATE_UINT16(tcnt, NE2000State),
VMSTATE_UINT16(rcnt, NE2000State),
VMSTATE_UINT32(rsar, NE2000State),
VMSTATE_UINT8(rsr, NE2000State),
VMSTATE_UINT8(isr, NE2000State),
VMSTATE_UINT8(dcfg, NE2000State),
VMSTATE_UINT8(imr, NE2000State),
VMSTATE_BUFFER(phys, NE2000State),
VMSTATE_UINT8(curpag, NE2000State),
VMSTATE_BUFFER(mult, NE2000State),
VMSTATE_UNUSED(4), /* was irq */
VMSTATE_BUFFER(mem, NE2000State),
VMSTATE_END_OF_LIST()
}
};
 
if (version_id > 3)
return -EINVAL;
const VMStateDescription vmstate_pci_ne2000 = {
.name = "ne2000",
.version_id = 3,
.minimum_version_id = 3,
.minimum_version_id_old = 3,
.fields = (VMStateField []) {
VMSTATE_PCI_DEVICE(dev, PCINE2000State),
VMSTATE_STRUCT(ne2000, PCINE2000State, 0, vmstate_ne2000, NE2000State),
VMSTATE_END_OF_LIST()
}
};
 
if (version_id >= 2) {
qemu_get_8s(f, &s->rxcr);
} else {
s->rxcr = 0x0c;
}
 
qemu_get_8s(f, &s->cmd);
qemu_get_be32s(f, &s->start);
qemu_get_be32s(f, &s->stop);
qemu_get_8s(f, &s->boundary);
qemu_get_8s(f, &s->tsr);
qemu_get_8s(f, &s->tpsr);
qemu_get_be16s(f, &s->tcnt);
qemu_get_be16s(f, &s->rcnt);
qemu_get_be32s(f, &s->rsar);
qemu_get_8s(f, &s->rsr);
qemu_get_8s(f, &s->isr);
qemu_get_8s(f, &s->dcfg);
qemu_get_8s(f, &s->imr);
qemu_get_buffer(f, s->phys, 6);
qemu_get_8s(f, &s->curpag);
qemu_get_buffer(f, s->mult, 8);
qemu_get_be32s(f, &tmp); /* ignored */
qemu_get_buffer(f, s->mem, NE2000_MEM_SIZE);
 
return 0;
}
 
static void pci_ne2000_save(QEMUFile* f, void* opaque)
{
PCINE2000State* s = opaque;
 
pci_device_save(&s->dev, f);
ne2000_save(f, &s->ne2000);
}
 
static int pci_ne2000_load(QEMUFile* f, void* opaque, int version_id)
{
PCINE2000State* s = opaque;
int ret;
 
if (version_id > 3)
return -EINVAL;
 
if (version_id >= 3) {
ret = pci_device_load(&s->dev, f);
if (ret < 0)
return ret;
}
 
return ne2000_load(f, &s->ne2000, version_id);
}
 
/***********************************************************/
/* PCI NE2000 definitions */
 
@@ -738,7 +702,7 @@
{
NE2000State *s = vc->opaque;
 
unregister_savevm("ne2000", s);
s->vc = NULL;
}
 
static int pci_ne2000_init(PCIDevice *pci_dev)
@@ -758,22 +722,46 @@
PCI_ADDRESS_SPACE_IO, ne2000_map);
s = &d->ne2000;
s->irq = d->dev.irq[0];
qdev_get_macaddr(&d->dev.qdev, s->macaddr);
 
qemu_macaddr_default_if_unset(&s->c.macaddr);
ne2000_reset(s);
s->vc = qdev_get_vlan_client(&d->dev.qdev,
s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, s->c.vlan, s->c.peer,
pci_dev->qdev.info->name, pci_dev->qdev.id,
ne2000_can_receive, ne2000_receive, NULL,
ne2000_cleanup, s);
NULL, ne2000_cleanup, s);
qemu_format_nic_info_str(s->vc, s->c.macaddr.a);
 
qemu_format_nic_info_str(s->vc, s->macaddr);
if (!pci_dev->qdev.hotplugged) {
static int loaded = 0;
if (!loaded) {
rom_add_option("pxe-ne2k_pci.bin");
loaded = 1;
}
}
 
register_savevm("ne2000", -1, 3, pci_ne2000_save, pci_ne2000_load, d);
vmstate_register(-1, &vmstate_pci_ne2000, d);
return 0;
}
 
static int pci_ne2000_exit(PCIDevice *pci_dev)
{
PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
NE2000State *s = &d->ne2000;
 
vmstate_unregister(&vmstate_pci_ne2000, s);
qemu_del_vlan_client(s->vc);
return 0;
}
 
static PCIDeviceInfo ne2000_info = {
.qdev.name = "ne2k_pci",
.qdev.size = sizeof(PCINE2000State),
.init = pci_ne2000_init,
.qdev.name = "ne2k_pci",
.qdev.size = sizeof(PCINE2000State),
.init = pci_ne2000_init,
.exit = pci_ne2000_exit,
.qdev.props = (Property[]) {
DEFINE_NIC_PROPERTIES(PCINE2000State, ne2000.c),
DEFINE_PROP_END_OF_LIST(),
}
};
 
static void ne2000_register_devices(void)