Gerd Hoffmann | 9453c5b | 2009-09-10 11:43:33 +0200 | [diff] [blame] | 1 | /* |
| 2 | * QEMU NE2000 emulation -- isa bus windup |
| 3 | * |
| 4 | * Copyright (c) 2003-2004 Fabrice Bellard |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
| 24 | #include "hw.h" |
| 25 | #include "pc.h" |
| 26 | #include "isa.h" |
| 27 | #include "qdev.h" |
| 28 | #include "net.h" |
| 29 | #include "ne2000.h" |
| 30 | |
| 31 | typedef struct ISANE2000State { |
| 32 | ISADevice dev; |
| 33 | uint32_t iobase; |
| 34 | uint32_t isairq; |
| 35 | NE2000State ne2000; |
| 36 | } ISANE2000State; |
| 37 | |
Mark McLoughlin | 1c2045b | 2009-11-25 18:49:14 +0000 | [diff] [blame] | 38 | static void isa_ne2000_cleanup(VLANClientState *nc) |
Gerd Hoffmann | 9453c5b | 2009-09-10 11:43:33 +0200 | [diff] [blame] | 39 | { |
Mark McLoughlin | 1c2045b | 2009-11-25 18:49:14 +0000 | [diff] [blame] | 40 | NE2000State *s = DO_UPCAST(NICState, nc, nc)->opaque; |
Gerd Hoffmann | 9453c5b | 2009-09-10 11:43:33 +0200 | [diff] [blame] | 41 | |
Mark McLoughlin | 1c2045b | 2009-11-25 18:49:14 +0000 | [diff] [blame] | 42 | s->nic = NULL; |
Gerd Hoffmann | 9453c5b | 2009-09-10 11:43:33 +0200 | [diff] [blame] | 43 | } |
| 44 | |
Mark McLoughlin | 1c2045b | 2009-11-25 18:49:14 +0000 | [diff] [blame] | 45 | static NetClientInfo net_ne2000_isa_info = { |
| 46 | .type = NET_CLIENT_TYPE_NIC, |
| 47 | .size = sizeof(NICState), |
| 48 | .can_receive = ne2000_can_receive, |
| 49 | .receive = ne2000_receive, |
| 50 | .cleanup = isa_ne2000_cleanup, |
| 51 | }; |
| 52 | |
Blue Swirl | d05ac8f | 2009-12-04 20:44:44 +0000 | [diff] [blame] | 53 | static const VMStateDescription vmstate_isa_ne2000 = { |
Juan Quintela | be73cfe | 2009-12-02 12:36:46 +0100 | [diff] [blame] | 54 | .name = "ne2000", |
| 55 | .version_id = 2, |
| 56 | .minimum_version_id = 0, |
| 57 | .minimum_version_id_old = 0, |
| 58 | .fields = (VMStateField []) { |
| 59 | VMSTATE_STRUCT(ne2000, ISANE2000State, 0, vmstate_ne2000, NE2000State), |
| 60 | VMSTATE_END_OF_LIST() |
| 61 | } |
| 62 | }; |
| 63 | |
Gerd Hoffmann | 9453c5b | 2009-09-10 11:43:33 +0200 | [diff] [blame] | 64 | static int isa_ne2000_initfn(ISADevice *dev) |
| 65 | { |
| 66 | ISANE2000State *isa = DO_UPCAST(ISANE2000State, dev, dev); |
| 67 | NE2000State *s = &isa->ne2000; |
| 68 | |
| 69 | register_ioport_write(isa->iobase, 16, 1, ne2000_ioport_write, s); |
| 70 | register_ioport_read(isa->iobase, 16, 1, ne2000_ioport_read, s); |
| 71 | |
| 72 | register_ioport_write(isa->iobase + 0x10, 1, 1, ne2000_asic_ioport_write, s); |
| 73 | register_ioport_read(isa->iobase + 0x10, 1, 1, ne2000_asic_ioport_read, s); |
| 74 | register_ioport_write(isa->iobase + 0x10, 2, 2, ne2000_asic_ioport_write, s); |
| 75 | register_ioport_read(isa->iobase + 0x10, 2, 2, ne2000_asic_ioport_read, s); |
| 76 | |
| 77 | register_ioport_write(isa->iobase + 0x1f, 1, 1, ne2000_reset_ioport_write, s); |
| 78 | register_ioport_read(isa->iobase + 0x1f, 1, 1, ne2000_reset_ioport_read, s); |
| 79 | |
| 80 | isa_init_irq(dev, &s->irq, isa->isairq); |
| 81 | |
Gerd Hoffmann | 93db668 | 2009-10-21 15:25:27 +0200 | [diff] [blame] | 82 | qemu_macaddr_default_if_unset(&s->c.macaddr); |
Gerd Hoffmann | 9453c5b | 2009-09-10 11:43:33 +0200 | [diff] [blame] | 83 | ne2000_reset(s); |
| 84 | |
Mark McLoughlin | 1c2045b | 2009-11-25 18:49:14 +0000 | [diff] [blame] | 85 | s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c, |
| 86 | dev->qdev.info->name, dev->qdev.id, s); |
| 87 | qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a); |
Gerd Hoffmann | 9453c5b | 2009-09-10 11:43:33 +0200 | [diff] [blame] | 88 | |
Gerd Hoffmann | 9453c5b | 2009-09-10 11:43:33 +0200 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | void isa_ne2000_init(int base, int irq, NICInfo *nd) |
| 93 | { |
| 94 | ISADevice *dev; |
| 95 | |
| 96 | qemu_check_nic_model(nd, "ne2k_isa"); |
| 97 | |
| 98 | dev = isa_create("ne2k_isa"); |
Gerd Hoffmann | 9453c5b | 2009-09-10 11:43:33 +0200 | [diff] [blame] | 99 | qdev_prop_set_uint32(&dev->qdev, "iobase", base); |
| 100 | qdev_prop_set_uint32(&dev->qdev, "irq", irq); |
Gerd Hoffmann | 93db668 | 2009-10-21 15:25:27 +0200 | [diff] [blame] | 101 | qdev_set_nic_properties(&dev->qdev, nd); |
Markus Armbruster | e23a1b3 | 2009-10-07 01:15:58 +0200 | [diff] [blame] | 102 | qdev_init_nofail(&dev->qdev); |
Gerd Hoffmann | 9453c5b | 2009-09-10 11:43:33 +0200 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static ISADeviceInfo ne2000_isa_info = { |
| 106 | .qdev.name = "ne2k_isa", |
| 107 | .qdev.size = sizeof(ISANE2000State), |
| 108 | .init = isa_ne2000_initfn, |
| 109 | .qdev.props = (Property[]) { |
| 110 | DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300), |
| 111 | DEFINE_PROP_UINT32("irq", ISANE2000State, isairq, 9), |
Gerd Hoffmann | 93db668 | 2009-10-21 15:25:27 +0200 | [diff] [blame] | 112 | DEFINE_NIC_PROPERTIES(ISANE2000State, ne2000.c), |
Gerd Hoffmann | 9453c5b | 2009-09-10 11:43:33 +0200 | [diff] [blame] | 113 | DEFINE_PROP_END_OF_LIST(), |
| 114 | }, |
| 115 | }; |
| 116 | |
| 117 | static void ne2000_isa_register_devices(void) |
| 118 | { |
| 119 | isa_qdev_register(&ne2000_isa_info); |
| 120 | } |
| 121 | |
| 122 | device_init(ne2000_isa_register_devices) |