aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-09-10 11:43:33 +0200
committermalc <av1474@comtv.ru>2009-09-10 19:48:01 +0400
commit9453c5bc2634fdbdd05450034c21a58806d366a4 (patch)
treea0e3f729626cd1021d9c2086e47f4730ae6fd165 /hw
parent9df34396d5066678d13155eea2060f73a36b98a9 (diff)
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>
Diffstat (limited to 'hw')
-rw-r--r--hw/mips_r4k.c2
-rw-r--r--hw/ne2000-isa.c111
-rw-r--r--hw/ne2000.c99
-rw-r--r--hw/ne2000.h40
-rw-r--r--hw/pc.c2
-rw-r--r--hw/pc.h2
-rw-r--r--hw/ppc_prep.c2
7 files changed, 167 insertions, 91 deletions
diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c
index da5ca319c8..aacb256dcc 100644
--- a/hw/mips_r4k.c
+++ b/hw/mips_r4k.c
@@ -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");
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
new file mode 100644
index 0000000000..9d8f7aa561
--- /dev/null
+++ b/hw/ne2000-isa.c
@@ -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)
diff --git a/hw/ne2000.c b/hw/ne2000.c
index bdfc9ed260..82531d04ec 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -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 */
diff --git a/hw/ne2000.h b/hw/ne2000.h
new file mode 100644
index 0000000000..92a2ddb41f
--- /dev/null
+++ b/hw/ne2000.h
@@ -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_);
diff --git a/hw/pc.c b/hw/pc.c
index e1ffaa43d6..9497f71c67 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -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++;
}
diff --git a/hw/pc.h b/hw/pc.h
index ec5735b893..d80d3a5f95 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -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
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index 927d4040ab..cde235ae26 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -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);
}