mipsnet: convert to qdev

Move mipsnet_init() function to mipssim machine

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
Hervé Poussineau 2011-09-04 22:29:26 +02:00 committed by Blue Swirl
parent f64e02b6cc
commit d118d64a92
3 changed files with 69 additions and 40 deletions

View File

@ -8,9 +8,6 @@ PCIBus *gt64120_register(qemu_irq *pic);
/* bonito.c */ /* bonito.c */
PCIBus *bonito_init(qemu_irq *pic); PCIBus *bonito_init(qemu_irq *pic);
/* mipsnet.c */
void mipsnet_init(int base, qemu_irq irq, NICInfo *nd);
/* jazz_led.c */ /* jazz_led.c */
void jazz_led_init(target_phys_addr_t base); void jazz_led_init(target_phys_addr_t base);

View File

@ -35,6 +35,8 @@
#include "mips-bios.h" #include "mips-bios.h"
#include "loader.h" #include "loader.h"
#include "elf.h" #include "elf.h"
#include "sysbus.h"
#include "exec-memory.h"
static struct _loaderparams { static struct _loaderparams {
int ram_size; int ram_size;
@ -112,6 +114,22 @@ static void main_cpu_reset(void *opaque)
} }
} }
static void mipsnet_init(int base, qemu_irq irq, NICInfo *nd)
{
DeviceState *dev;
SysBusDevice *s;
dev = qdev_create(NULL, "mipsnet");
qdev_set_nic_properties(dev, nd);
qdev_init_nofail(dev);
s = sysbus_from_qdev(dev);
sysbus_connect_irq(s, 0, irq);
memory_region_add_subregion(get_system_io(),
base,
sysbus_mmio_get_region(s, 0));
}
static void static void
mips_mipssim_init (ram_addr_t ram_size, mips_mipssim_init (ram_addr_t ram_size,
const char *boot_device, const char *boot_device,

View File

@ -1,7 +1,6 @@
#include "hw.h" #include "hw.h"
#include "mips.h"
#include "net.h" #include "net.h"
#include "isa.h" #include "sysbus.h"
//#define DEBUG_MIPSNET_SEND //#define DEBUG_MIPSNET_SEND
//#define DEBUG_MIPSNET_RECEIVE //#define DEBUG_MIPSNET_RECEIVE
@ -25,6 +24,8 @@
#define MAX_ETH_FRAME_SIZE 1514 #define MAX_ETH_FRAME_SIZE 1514
typedef struct MIPSnetState { typedef struct MIPSnetState {
SysBusDevice busdev;
uint32_t busy; uint32_t busy;
uint32_t rx_count; uint32_t rx_count;
uint32_t rx_read; uint32_t rx_read;
@ -33,7 +34,7 @@ typedef struct MIPSnetState {
uint32_t intctl; uint32_t intctl;
uint8_t rx_buffer[MAX_ETH_FRAME_SIZE]; uint8_t rx_buffer[MAX_ETH_FRAME_SIZE];
uint8_t tx_buffer[MAX_ETH_FRAME_SIZE]; uint8_t tx_buffer[MAX_ETH_FRAME_SIZE];
int io_base; MemoryRegion io;
qemu_irq irq; qemu_irq irq;
NICState *nic; NICState *nic;
NICConf conf; NICConf conf;
@ -103,7 +104,8 @@ static ssize_t mipsnet_receive(VLANClientState *nc, const uint8_t *buf, size_t s
return size; return size;
} }
static uint32_t mipsnet_ioport_read(void *opaque, uint32_t addr) static uint64_t mipsnet_ioport_read(void *opaque, target_phys_addr_t addr,
unsigned int size)
{ {
MIPSnetState *s = opaque; MIPSnetState *s = opaque;
int ret = 0; int ret = 0;
@ -150,7 +152,8 @@ static uint32_t mipsnet_ioport_read(void *opaque, uint32_t addr)
return ret; return ret;
} }
static void mipsnet_ioport_write(void *opaque, uint32_t addr, uint32_t val) static void mipsnet_ioport_write(void *opaque, target_phys_addr_t addr,
uint64_t val, unsigned int size)
{ {
MIPSnetState *s = opaque; MIPSnetState *s = opaque;
@ -224,11 +227,7 @@ static void mipsnet_cleanup(VLANClientState *nc)
{ {
MIPSnetState *s = DO_UPCAST(NICState, nc, nc)->opaque; MIPSnetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
vmstate_unregister(NULL, &vmstate_mipsnet, s); s->nic = NULL;
isa_unassign_ioport(s->io_base, 36);
g_free(s);
} }
static NetClientInfo net_mipsnet_info = { static NetClientInfo net_mipsnet_info = {
@ -239,35 +238,50 @@ static NetClientInfo net_mipsnet_info = {
.cleanup = mipsnet_cleanup, .cleanup = mipsnet_cleanup,
}; };
void mipsnet_init (int base, qemu_irq irq, NICInfo *nd) static MemoryRegionOps mipsnet_ioport_ops = {
.read = mipsnet_ioport_read,
.write = mipsnet_ioport_write,
.impl.min_access_size = 1,
.impl.max_access_size = 4,
};
static int mipsnet_sysbus_init(SysBusDevice *dev)
{ {
MIPSnetState *s; MIPSnetState *s = DO_UPCAST(MIPSnetState, busdev, dev);
qemu_check_nic_model(nd, "mipsnet"); memory_region_init_io(&s->io, &mipsnet_ioport_ops, s, "mipsnet-io", 36);
sysbus_init_mmio_region(dev, &s->io);
sysbus_init_irq(dev, &s->irq);
s = g_malloc0(sizeof(MIPSnetState)); s->nic = qemu_new_nic(&net_mipsnet_info, &s->conf,
dev->qdev.info->name, dev->qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
register_ioport_write(base, 36, 1, mipsnet_ioport_write, s); return 0;
register_ioport_read(base, 36, 1, mipsnet_ioport_read, s);
register_ioport_write(base, 36, 2, mipsnet_ioport_write, s);
register_ioport_read(base, 36, 2, mipsnet_ioport_read, s);
register_ioport_write(base, 36, 4, mipsnet_ioport_write, s);
register_ioport_read(base, 36, 4, mipsnet_ioport_read, s);
s->io_base = base;
s->irq = irq;
if (nd) {
s->conf.macaddr = nd->macaddr;
s->conf.vlan = nd->vlan;
s->conf.peer = nd->netdev;
s->nic = qemu_new_nic(&net_mipsnet_info, &s->conf,
nd->model, nd->name, s);
qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
}
mipsnet_reset(s);
vmstate_register(NULL, 0, &vmstate_mipsnet, s);
} }
static void mipsnet_sysbus_reset(DeviceState *dev)
{
MIPSnetState *s = DO_UPCAST(MIPSnetState, busdev.qdev, dev);
mipsnet_reset(s);
}
static SysBusDeviceInfo mipsnet_info = {
.init = mipsnet_sysbus_init,
.qdev.name = "mipsnet",
.qdev.desc = "MIPS Simulator network device",
.qdev.size = sizeof(MIPSnetState),
.qdev.vmsd = &vmstate_mipsnet,
.qdev.reset = mipsnet_sysbus_reset,
.qdev.props = (Property[]) {
DEFINE_NIC_PROPERTIES(MIPSnetState, conf),
DEFINE_PROP_END_OF_LIST(),
}
};
static void mipsnet_register_devices(void)
{
sysbus_register_withprop(&mipsnet_info);
}
device_init(mipsnet_register_devices)