qdev/isa: convert ne2000

Also split the isa bits into a separate source file, so we don't drag in
a dependency for isa-bus.o for machines which want ne2k_pci only.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Gerd Hoffmann 2009-09-10 11:43:33 +02:00 committed by malc
parent 9df34396d5
commit 9453c5bc26
8 changed files with 170 additions and 93 deletions

View File

@ -189,13 +189,14 @@ obj-i386-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
obj-i386-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
obj-i386-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
obj-i386-y += ne2000-isa.o
# shared objects
obj-ppc-y = ppc.o ide/core.o ide/isa.o ide/pci.o ide/macio.o
obj-ppc-y += vga.o vga-pci.o $(sound-obj-y) dma.o isa-bus.o openpic.o
# PREP target
obj-ppc-y += pckbd.o serial.o i8259.o i8254.o fdc.o mc146818rtc.o
obj-ppc-y += prep_pci.o ppc_prep.o
obj-ppc-y += prep_pci.o ppc_prep.o ne2000-isa.o
# Mac shared devices
obj-ppc-y += macio.o cuda.o adb.o mac_nvram.o mac_dbdma.o
# OldWorld PowerMac
@ -217,7 +218,7 @@ obj-mips-y += g364fb.o jazz_led.o dp8393x.o
obj-mips-y += ide/core.o ide/isa.o ide/pci.o
obj-mips-y += gt64xxx.o pckbd.o fdc.o mc146818rtc.o usb-uhci.o acpi.o ds1225y.o
obj-mips-y += piix4.o parallel.o cirrus_vga.o isa-bus.o pcspk.o $(sound-obj-y)
obj-mips-y += mipsnet.o
obj-mips-y += mipsnet.o ne2000-isa.o
obj-mips-y += pflash_cfi01.o
obj-mips-y += vmware_vga.o

View File

@ -260,7 +260,7 @@ void mips_r4k_init (ram_addr_t ram_size,
isa_vga_init();
if (nd_table[0].vlan)
isa_ne2000_init(0x300, i8259[9], &nd_table[0]);
isa_ne2000_init(0x300, 9, &nd_table[0]);
if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
fprintf(stderr, "qemu: too many IDE bus\n");

111
hw/ne2000-isa.c Normal file
View File

@ -0,0 +1,111 @@
/*
* QEMU NE2000 emulation -- isa bus windup
*
* Copyright (c) 2003-2004 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "hw.h"
#include "pc.h"
#include "isa.h"
#include "qdev.h"
#include "net.h"
#include "ne2000.h"
typedef struct ISANE2000State {
ISADevice dev;
uint32_t iobase;
uint32_t isairq;
NE2000State ne2000;
} ISANE2000State;
static void isa_ne2000_cleanup(VLANClientState *vc)
{
NE2000State *s = vc->opaque;
ISANE2000State *isa = container_of(s, ISANE2000State, ne2000);
unregister_savevm("ne2000", s);
isa_unassign_ioport(isa->iobase, 16);
isa_unassign_ioport(isa->iobase + 0x10, 2);
isa_unassign_ioport(isa->iobase + 0x1f, 1);
qemu_free(s);
}
static int isa_ne2000_initfn(ISADevice *dev)
{
ISANE2000State *isa = DO_UPCAST(ISANE2000State, dev, dev);
NE2000State *s = &isa->ne2000;
register_ioport_write(isa->iobase, 16, 1, ne2000_ioport_write, s);
register_ioport_read(isa->iobase, 16, 1, ne2000_ioport_read, s);
register_ioport_write(isa->iobase + 0x10, 1, 1, ne2000_asic_ioport_write, s);
register_ioport_read(isa->iobase + 0x10, 1, 1, ne2000_asic_ioport_read, s);
register_ioport_write(isa->iobase + 0x10, 2, 2, ne2000_asic_ioport_write, s);
register_ioport_read(isa->iobase + 0x10, 2, 2, ne2000_asic_ioport_read, s);
register_ioport_write(isa->iobase + 0x1f, 1, 1, ne2000_reset_ioport_write, s);
register_ioport_read(isa->iobase + 0x1f, 1, 1, ne2000_reset_ioport_read, s);
isa_init_irq(dev, &s->irq, isa->isairq);
qdev_get_macaddr(&dev->qdev, s->macaddr);
ne2000_reset(s);
s->vc = qdev_get_vlan_client(&dev->qdev,
ne2000_can_receive, ne2000_receive, NULL,
isa_ne2000_cleanup, s);
qemu_format_nic_info_str(s->vc, s->macaddr);
register_savevm("ne2000", -1, 2, ne2000_save, ne2000_load, s);
return 0;
}
void isa_ne2000_init(int base, int irq, NICInfo *nd)
{
ISADevice *dev;
qemu_check_nic_model(nd, "ne2k_isa");
dev = isa_create("ne2k_isa");
dev->qdev.nd = nd; /* hack alert */
qdev_prop_set_uint32(&dev->qdev, "iobase", base);
qdev_prop_set_uint32(&dev->qdev, "irq", irq);
qdev_init(&dev->qdev);
}
static ISADeviceInfo ne2000_isa_info = {
.qdev.name = "ne2k_isa",
.qdev.size = sizeof(ISANE2000State),
.init = isa_ne2000_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300),
DEFINE_PROP_UINT32("irq", ISANE2000State, isairq, 9),
DEFINE_PROP_END_OF_LIST(),
},
};
static void ne2000_isa_register_devices(void)
{
isa_qdev_register(&ne2000_isa_info);
}
device_init(ne2000_isa_register_devices)

View File

@ -25,6 +25,7 @@
#include "pci.h"
#include "pc.h"
#include "net.h"
#include "ne2000.h"
/* debug NE2000 card */
//#define DEBUG_NE2000
@ -116,42 +117,12 @@
#define ENTSR_CDH 0x40 /* The collision detect "heartbeat" signal was lost. */
#define ENTSR_OWC 0x80 /* There was an out-of-window collision. */
#define NE2000_PMEM_SIZE (32*1024)
#define NE2000_PMEM_START (16*1024)
#define NE2000_PMEM_END (NE2000_PMEM_SIZE+NE2000_PMEM_START)
#define NE2000_MEM_SIZE NE2000_PMEM_END
typedef struct NE2000State {
uint8_t cmd;
uint32_t start;
uint32_t stop;
uint8_t boundary;
uint8_t tsr;
uint8_t tpsr;
uint16_t tcnt;
uint16_t rcnt;
uint32_t rsar;
uint8_t rsr;
uint8_t rxcr;
uint8_t isr;
uint8_t dcfg;
uint8_t imr;
uint8_t phys[6]; /* mac address */
uint8_t curpag;
uint8_t mult[8]; /* multicast mask array */
qemu_irq irq;
int isa_io_base;
VLANClientState *vc;
uint8_t macaddr[6];
uint8_t mem[NE2000_MEM_SIZE];
} NE2000State;
typedef struct PCINE2000State {
PCIDevice dev;
NE2000State ne2000;
} PCINE2000State;
static void ne2000_reset(NE2000State *s)
void ne2000_reset(NE2000State *s)
{
int i;
@ -217,7 +188,7 @@ static int ne2000_buffer_full(NE2000State *s)
return 0;
}
static int ne2000_can_receive(VLANClientState *vc)
int ne2000_can_receive(VLANClientState *vc)
{
NE2000State *s = vc->opaque;
@ -228,7 +199,7 @@ static int ne2000_can_receive(VLANClientState *vc)
#define MIN_BUF_SIZE 60
static ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_)
ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_)
{
NE2000State *s = vc->opaque;
int size = size_;
@ -325,7 +296,7 @@ static ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t si
return size_;
}
static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
{
NE2000State *s = opaque;
int offset, page, index;
@ -422,7 +393,7 @@ static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
}
}
static uint32_t ne2000_ioport_read(void *opaque, uint32_t addr)
uint32_t ne2000_ioport_read(void *opaque, uint32_t addr)
{
NE2000State *s = opaque;
int offset, page, ret;
@ -572,7 +543,7 @@ static inline void ne2000_dma_update(NE2000State *s, int len)
}
}
static void ne2000_asic_ioport_write(void *opaque, uint32_t addr, uint32_t val)
void ne2000_asic_ioport_write(void *opaque, uint32_t addr, uint32_t val)
{
NE2000State *s = opaque;
@ -592,7 +563,7 @@ static void ne2000_asic_ioport_write(void *opaque, uint32_t addr, uint32_t val)
}
}
static uint32_t ne2000_asic_ioport_read(void *opaque, uint32_t addr)
uint32_t ne2000_asic_ioport_read(void *opaque, uint32_t addr)
{
NE2000State *s = opaque;
int ret;
@ -640,19 +611,19 @@ static uint32_t ne2000_asic_ioport_readl(void *opaque, uint32_t addr)
return ret;
}
static void ne2000_reset_ioport_write(void *opaque, uint32_t addr, uint32_t val)
void ne2000_reset_ioport_write(void *opaque, uint32_t addr, uint32_t val)
{
/* nothing to do (end of reset pulse) */
}
static uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr)
uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr)
{
NE2000State *s = opaque;
ne2000_reset(s);
return 0;
}
static void ne2000_save(QEMUFile* f, void* opaque)
void ne2000_save(QEMUFile* f, void* opaque)
{
NE2000State* s = opaque;
uint32_t tmp;
@ -680,7 +651,7 @@ static void ne2000_save(QEMUFile* f, void* opaque)
qemu_put_buffer(f, s->mem, NE2000_MEM_SIZE);
}
static int ne2000_load(QEMUFile* f, void* opaque, int version_id)
int ne2000_load(QEMUFile* f, void* opaque, int version_id)
{
NE2000State* s = opaque;
uint32_t tmp;
@ -741,52 +712,6 @@ static int pci_ne2000_load(QEMUFile* f, void* opaque, int version_id)
return ne2000_load(f, &s->ne2000, version_id);
}
static void isa_ne2000_cleanup(VLANClientState *vc)
{
NE2000State *s = vc->opaque;
unregister_savevm("ne2000", s);
isa_unassign_ioport(s->isa_io_base, 16);
isa_unassign_ioport(s->isa_io_base + 0x10, 2);
isa_unassign_ioport(s->isa_io_base + 0x1f, 1);
qemu_free(s);
}
void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
{
NE2000State *s;
qemu_check_nic_model(nd, "ne2k_isa");
s = qemu_mallocz(sizeof(NE2000State));
register_ioport_write(base, 16, 1, ne2000_ioport_write, s);
register_ioport_read(base, 16, 1, ne2000_ioport_read, s);
register_ioport_write(base + 0x10, 1, 1, ne2000_asic_ioport_write, s);
register_ioport_read(base + 0x10, 1, 1, ne2000_asic_ioport_read, s);
register_ioport_write(base + 0x10, 2, 2, ne2000_asic_ioport_write, s);
register_ioport_read(base + 0x10, 2, 2, ne2000_asic_ioport_read, s);
register_ioport_write(base + 0x1f, 1, 1, ne2000_reset_ioport_write, s);
register_ioport_read(base + 0x1f, 1, 1, ne2000_reset_ioport_read, s);
s->isa_io_base = base;
s->irq = irq;
memcpy(s->macaddr, nd->macaddr, 6);
ne2000_reset(s);
s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
ne2000_can_receive, ne2000_receive,
NULL, isa_ne2000_cleanup, s);
qemu_format_nic_info_str(s->vc, s->macaddr);
register_savevm("ne2000", -1, 2, ne2000_save, ne2000_load, s);
}
/***********************************************************/
/* PCI NE2000 definitions */

40
hw/ne2000.h Normal file
View File

@ -0,0 +1,40 @@
#define NE2000_PMEM_SIZE (32*1024)
#define NE2000_PMEM_START (16*1024)
#define NE2000_PMEM_END (NE2000_PMEM_SIZE+NE2000_PMEM_START)
#define NE2000_MEM_SIZE NE2000_PMEM_END
typedef struct NE2000State {
uint8_t cmd;
uint32_t start;
uint32_t stop;
uint8_t boundary;
uint8_t tsr;
uint8_t tpsr;
uint16_t tcnt;
uint16_t rcnt;
uint32_t rsar;
uint8_t rsr;
uint8_t rxcr;
uint8_t isr;
uint8_t dcfg;
uint8_t imr;
uint8_t phys[6]; /* mac address */
uint8_t curpag;
uint8_t mult[8]; /* multicast mask array */
qemu_irq irq;
VLANClientState *vc;
uint8_t macaddr[6];
uint8_t mem[NE2000_MEM_SIZE];
} NE2000State;
void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val);
uint32_t ne2000_ioport_read(void *opaque, uint32_t addr);
void ne2000_asic_ioport_write(void *opaque, uint32_t addr, uint32_t val);
uint32_t ne2000_asic_ioport_read(void *opaque, uint32_t addr);
void ne2000_reset_ioport_write(void *opaque, uint32_t addr, uint32_t val);
uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr);
void ne2000_save(QEMUFile* f, void* opaque);
int ne2000_load(QEMUFile* f, void* opaque, int version_id);
void ne2000_reset(NE2000State *s);
int ne2000_can_receive(VLANClientState *vc);
ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_);

View File

@ -1052,7 +1052,7 @@ static void pc_init_ne2k_isa(NICInfo *nd)
if (nb_ne2k == NE2000_NB_MAX)
return;
isa_ne2000_init(ne2000_io[nb_ne2k],
isa_reserve_irq(ne2000_irq[nb_ne2k]), nd);
ne2000_irq[nb_ne2k], nd);
nb_ne2k++;
}

View File

@ -148,7 +148,7 @@ void isa_cirrus_vga_init(void);
/* ne2000.c */
void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd);
void isa_ne2000_init(int base, int irq, NICInfo *nd);
int cpu_is_bsp(CPUState *env);
#endif

View File

@ -691,7 +691,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
nd_table[i].model = "ne2k_isa";
}
if (strcmp(nd_table[i].model, "ne2k_isa") == 0) {
isa_ne2000_init(ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]);
isa_ne2000_init(ne2000_io[i], ne2000_irq[i], &nd_table[i]);
} else {
pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
}