]> Git Repo - qemu.git/blobdiff - hw/etraxfs_eth.c
Merge remote-tracking branch 'qemu-kvm/memory/urgent' into staging
[qemu.git] / hw / etraxfs_eth.c
index ade96f14ac02b17afd96713cff670ccb61ebe191..48de6dcd47d968d52dea92d987feb7558be2d5fd 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 #include <stdio.h>
-#include "hw.h"
+#include "sysbus.h"
 #include "net.h"
 #include "etraxfs.h"
 
@@ -319,6 +319,7 @@ static void mdio_cycle(struct qemu_mdio *bus)
 
 struct fs_eth
 {
+       SysBusDevice busdev;
        NICState *nic;
        NICConf conf;
        int ethregs;
@@ -327,8 +328,14 @@ struct fs_eth
        uint8_t macaddr[2][6];
        uint32_t regs[FS_ETH_MAX_REGS];
 
-       struct etraxfs_dma_client *dma_out;
-       struct etraxfs_dma_client *dma_in;
+       union {
+               void *vdma_out;
+               struct etraxfs_dma_client *dma_out;
+       };
+       union {
+               void *vdma_in;
+               struct etraxfs_dma_client *dma_in;
+       };
 
        /* MDIO bus.  */
        struct qemu_mdio mdio_bus;
@@ -562,8 +569,12 @@ static void eth_cleanup(VLANClientState *nc)
 
         cpu_unregister_io_memory(eth->ethregs);
 
-        qemu_free(eth->dma_out);
-        qemu_free(eth);
+       /* Disconnect the client.  */
+       eth->dma_out->client.push = NULL;
+       eth->dma_out->client.opaque = NULL;
+       eth->dma_in->client.opaque = NULL;
+       eth->dma_in->client.pull = NULL;
+        g_free(eth);
 }
 
 static NetClientInfo net_etraxfs_info = {
@@ -575,38 +586,50 @@ static NetClientInfo net_etraxfs_info = {
        .link_status_changed = eth_set_link,
 };
 
-void *etraxfs_eth_init(NICInfo *nd, target_phys_addr_t base, int phyaddr)
+static int fs_eth_init(SysBusDevice *dev)
 {
-       struct etraxfs_dma_client *dma = NULL;  
-       struct fs_eth *eth = NULL;
+       struct fs_eth *s = FROM_SYSBUS(typeof(*s), dev);
+       int eth_regs;
 
-       qemu_check_nic_model(nd, "fseth");
-
-       dma = qemu_mallocz(sizeof *dma * 2);
-       eth = qemu_mallocz(sizeof *eth);
-
-       dma[0].client.push = eth_tx_push;
-       dma[0].client.opaque = eth;
-       dma[1].client.opaque = eth;
-       dma[1].client.pull = NULL;
+       if (!s->dma_out || !s->dma_in) {
+               hw_error("Unconnected ETRAX-FS Ethernet MAC.\n");
+       }
 
-       eth->dma_out = dma;
-       eth->dma_in = dma + 1;
+       s->dma_out->client.push = eth_tx_push;
+       s->dma_out->client.opaque = s;
+       s->dma_in->client.opaque = s;
+       s->dma_in->client.pull = NULL;
 
-       /* Connect the phy.  */
-       eth->phyaddr = phyaddr & 0x1f;
-       tdk_init(&eth->phy);
-       mdio_attach(&eth->mdio_bus, &eth->phy, eth->phyaddr);
+       eth_regs = cpu_register_io_memory(eth_read, eth_write, s,
+                                         DEVICE_LITTLE_ENDIAN);
+       sysbus_init_mmio(dev, 0x5c, eth_regs);
 
-       eth->ethregs = cpu_register_io_memory(eth_read, eth_write, eth);
-       cpu_register_physical_memory (base, 0x5c, eth->ethregs);
+       qemu_macaddr_default_if_unset(&s->conf.macaddr);
+       s->nic = qemu_new_nic(&net_etraxfs_info, &s->conf,
+                             dev->qdev.info->name, dev->qdev.id, s);
+       qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
-       memcpy(eth->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr));
-       eth->conf.vlan = nd->vlan;
-       eth->conf.peer = nd->netdev;
+       tdk_init(&s->phy);
+       mdio_attach(&s->mdio_bus, &s->phy, s->phyaddr);
+       return 0;
+}
 
-       eth->nic = qemu_new_nic(&net_etraxfs_info, &eth->conf,
-                               nd->model, nd->name, eth);
+static SysBusDeviceInfo etraxfs_eth_info = {
+       .init = fs_eth_init,
+       .qdev.name  = "etraxfs-eth",
+       .qdev.size  = sizeof(struct fs_eth),
+       .qdev.props = (Property[]) {
+               DEFINE_PROP_UINT32("phyaddr", struct fs_eth, phyaddr, 1),
+               DEFINE_PROP_PTR("dma_out", struct fs_eth, vdma_out),
+               DEFINE_PROP_PTR("dma_in", struct fs_eth, vdma_in),
+               DEFINE_NIC_PROPERTIES(struct fs_eth, conf),
+               DEFINE_PROP_END_OF_LIST(),
+       }
+};
 
-       return dma;
+static void etraxfs_eth_register(void)
+{
+       sysbus_register_withprop(&etraxfs_eth_info);
 }
+
+device_init(etraxfs_eth_register)
This page took 0.029089 seconds and 4 git commands to generate.