Commit a5580466257337e74e48124c185e4db9d29325ec

Authored by Paul Brook
1 parent cf21e106

Stellaris ethernet qdev conversion

Signed-off-by: Paul Brook <paul@codesourcery.com>
hw/arm-misc.h
... ... @@ -41,7 +41,4 @@ void arm_load_kernel(CPUState *env, struct arm_boot_info *info);
41 41 extern int system_clock_scale;
42 42 qemu_irq *armv7m_nvic_init(CPUState *env);
43 43  
44   -/* stellaris_enent.c */
45   -void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq);
46   -
47 44 #endif /* !ARM_MISC_H */
... ...
hw/stellaris.c
... ... @@ -1356,8 +1356,17 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
1356 1356 pl022_init(0x40008000, pic[7], NULL, NULL);
1357 1357 }
1358 1358 }
1359   - if (board->dc4 & (1 << 28))
1360   - stellaris_enet_init(&nd_table[0], 0x40048000, pic[42]);
  1359 + if (board->dc4 & (1 << 28)) {
  1360 + DeviceState *enet;
  1361 +
  1362 + qemu_check_nic_model(&nd_table[0], "stellaris");
  1363 +
  1364 + enet = qdev_create(NULL, "stellaris_enet");
  1365 + qdev_set_netdev(enet, &nd_table[0]);
  1366 + qdev_init(enet);
  1367 + sysbus_mmio_map(sysbus_from_qdev(enet), 0, 0x40048000);
  1368 + sysbus_connect_irq(sysbus_from_qdev(enet), 0, pic[42]);
  1369 + }
1361 1370 if (board->peripherals & BP_GAMEPAD) {
1362 1371 qemu_irq gpad_irq[5];
1363 1372 static const int gpad_keycode[5] = { 0xc8, 0xd0, 0xcb, 0xcd, 0x1d };
... ...
hw/stellaris_enet.c
... ... @@ -6,8 +6,7 @@
6 6 *
7 7 * This code is licenced under the GPL.
8 8 */
9   -#include "hw.h"
10   -#include "arm-misc.h"
  9 +#include "sysbus.h"
11 10 #include "net.h"
12 11 #include <zlib.h>
13 12  
... ... @@ -44,6 +43,7 @@ do { fprintf(stderr, &quot;stellaris_enet: error: &quot; fmt , ## __VA_ARGS__);} while (0)
44 43 #define SE_TCTL_DUPLEX 0x08
45 44  
46 45 typedef struct {
  46 + SysBusDevice busdev;
47 47 uint32_t ris;
48 48 uint32_t im;
49 49 uint32_t rctl;
... ... @@ -394,28 +394,31 @@ static void stellaris_enet_cleanup(VLANClientState *vc)
394 394 qemu_free(s);
395 395 }
396 396  
397   -void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq)
  397 +static void stellaris_enet_init(SysBusDevice *dev)
398 398 {
399   - stellaris_enet_state *s;
  399 + stellaris_enet_state *s = FROM_SYSBUS(stellaris_enet_state, dev);
400 400  
401   - qemu_check_nic_model(nd, "stellaris");
402   -
403   - s = (stellaris_enet_state *)qemu_mallocz(sizeof(stellaris_enet_state));
404 401 s->mmio_index = cpu_register_io_memory(0, stellaris_enet_readfn,
405 402 stellaris_enet_writefn, s);
406   - cpu_register_physical_memory(base, 0x00001000, s->mmio_index);
407   - s->irq = irq;
408   - memcpy(s->macaddr, nd->macaddr, 6);
409   -
410   - if (nd->vlan) {
411   - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
412   - stellaris_enet_receive,
413   - stellaris_enet_can_receive,
414   - stellaris_enet_cleanup, s);
415   - qemu_format_nic_info_str(s->vc, s->macaddr);
416   - }
  403 + sysbus_init_mmio(dev, 0x1000, s->mmio_index);
  404 + sysbus_init_irq(dev, &s->irq);
  405 + qdev_get_macaddr(&dev->qdev, s->macaddr);
  406 +
  407 + s->vc = qdev_get_vlan_client(&dev->qdev,
  408 + stellaris_enet_receive,
  409 + stellaris_enet_can_receive,
  410 + stellaris_enet_cleanup, s);
  411 + qemu_format_nic_info_str(s->vc, s->macaddr);
417 412  
418 413 stellaris_enet_reset(s);
419 414 register_savevm("stellaris_enet", -1, 1,
420 415 stellaris_enet_save, stellaris_enet_load, s);
421 416 }
  417 +
  418 +static void stellaris_enet_register_devices(void)
  419 +{
  420 + sysbus_register_dev("stellaris_enet", sizeof(stellaris_enet_state),
  421 + stellaris_enet_init);
  422 +}
  423 +
  424 +device_init(stellaris_enet_register_devices)
... ...