Commit 418dcf5b7da0efefea33ad4e96434feff57524d5

Authored by Paul Brook
1 parent 6a824ec3

smc91c111 qdev conversion

Signed-off-by: Paul Brook <paul@codesourcery.com>
Showing 1 changed file with 31 additions and 10 deletions
hw/smc91c111.c
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 * This code is licenced under the GPL 7 * This code is licenced under the GPL
8 */ 8 */
9 9
10 -#include "hw.h" 10 +#include "sysbus.h"
11 #include "net.h" 11 #include "net.h"
12 #include "devices.h" 12 #include "devices.h"
13 /* For crc32 */ 13 /* For crc32 */
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 #define NUM_PACKETS 4 17 #define NUM_PACKETS 4
18 18
19 typedef struct { 19 typedef struct {
  20 + SysBusDevice busdev;
20 VLANClientState *vc; 21 VLANClientState *vc;
21 uint16_t tcr; 22 uint16_t tcr;
22 uint16_t rcr; 23 uint16_t rcr;
@@ -697,24 +698,44 @@ static void smc91c111_cleanup(VLANClientState *vc) @@ -697,24 +698,44 @@ static void smc91c111_cleanup(VLANClientState *vc)
697 qemu_free(s); 698 qemu_free(s);
698 } 699 }
699 700
700 -void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq) 701 +static void smc91c111_init1(SysBusDevice *dev)
701 { 702 {
702 - smc91c111_state *s;  
703 -  
704 - qemu_check_nic_model(nd, "smc91c111"); 703 + smc91c111_state *s = FROM_SYSBUS(smc91c111_state, dev);
705 704
706 - s = (smc91c111_state *)qemu_mallocz(sizeof(smc91c111_state));  
707 s->mmio_index = cpu_register_io_memory(0, smc91c111_readfn, 705 s->mmio_index = cpu_register_io_memory(0, smc91c111_readfn,
708 smc91c111_writefn, s); 706 smc91c111_writefn, s);
709 - cpu_register_physical_memory(base, 16, s->mmio_index);  
710 - s->irq = irq;  
711 - memcpy(s->macaddr, nd->macaddr, 6); 707 + sysbus_init_mmio(dev, 16, s->mmio_index);
  708 + sysbus_init_irq(dev, &s->irq);
  709 + qdev_get_macaddr(&dev->qdev, s->macaddr);
712 710
713 smc91c111_reset(s); 711 smc91c111_reset(s);
714 712
715 - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, 713 + s->vc = qdev_get_vlan_client(&dev->qdev,
716 smc91c111_receive, smc91c111_can_receive, 714 smc91c111_receive, smc91c111_can_receive,
717 smc91c111_cleanup, s); 715 smc91c111_cleanup, s);
718 qemu_format_nic_info_str(s->vc, s->macaddr); 716 qemu_format_nic_info_str(s->vc, s->macaddr);
719 /* ??? Save/restore. */ 717 /* ??? Save/restore. */
720 } 718 }
  719 +
  720 +static void smc91c111_register_devices(void)
  721 +{
  722 + sysbus_register_dev("smc91c111", sizeof(smc91c111_state), smc91c111_init1);
  723 +}
  724 +
  725 +/* Legacy helper function. Should go away when machine config files are
  726 + implemented. */
  727 +void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
  728 +{
  729 + DeviceState *dev;
  730 + SysBusDevice *s;
  731 +
  732 + qemu_check_nic_model(nd, "smc91c111");
  733 + dev = qdev_create(NULL, "smc91c111");
  734 + qdev_set_netdev(dev, nd);
  735 + qdev_init(dev);
  736 + s = sysbus_from_qdev(dev);
  737 + sysbus_mmio_map(s, 0, base);
  738 + sysbus_connect_irq(s, 0, irq);
  739 +}
  740 +
  741 +device_init(smc91c111_register_devices)