2 * QEMU NE2000 emulation -- isa bus windup
4 * Copyright (c) 2003-2004 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
31 typedef struct ISANE2000State
{
38 static void isa_ne2000_cleanup(VLANClientState
*vc
)
40 NE2000State
*s
= vc
->opaque
;
41 ISANE2000State
*isa
= container_of(s
, ISANE2000State
, ne2000
);
43 unregister_savevm("ne2000", s
);
45 isa_unassign_ioport(isa
->iobase
, 16);
46 isa_unassign_ioport(isa
->iobase
+ 0x10, 2);
47 isa_unassign_ioport(isa
->iobase
+ 0x1f, 1);
52 static int isa_ne2000_initfn(ISADevice
*dev
)
54 ISANE2000State
*isa
= DO_UPCAST(ISANE2000State
, dev
, dev
);
55 NE2000State
*s
= &isa
->ne2000
;
57 register_ioport_write(isa
->iobase
, 16, 1, ne2000_ioport_write
, s
);
58 register_ioport_read(isa
->iobase
, 16, 1, ne2000_ioport_read
, s
);
60 register_ioport_write(isa
->iobase
+ 0x10, 1, 1, ne2000_asic_ioport_write
, s
);
61 register_ioport_read(isa
->iobase
+ 0x10, 1, 1, ne2000_asic_ioport_read
, s
);
62 register_ioport_write(isa
->iobase
+ 0x10, 2, 2, ne2000_asic_ioport_write
, s
);
63 register_ioport_read(isa
->iobase
+ 0x10, 2, 2, ne2000_asic_ioport_read
, s
);
65 register_ioport_write(isa
->iobase
+ 0x1f, 1, 1, ne2000_reset_ioport_write
, s
);
66 register_ioport_read(isa
->iobase
+ 0x1f, 1, 1, ne2000_reset_ioport_read
, s
);
68 isa_init_irq(dev
, &s
->irq
, isa
->isairq
);
70 qdev_get_macaddr(&dev
->qdev
, s
->macaddr
);
73 s
->vc
= qdev_get_vlan_client(&dev
->qdev
,
74 ne2000_can_receive
, ne2000_receive
, NULL
,
75 isa_ne2000_cleanup
, s
);
76 qemu_format_nic_info_str(s
->vc
, s
->macaddr
);
78 register_savevm("ne2000", -1, 2, ne2000_save
, ne2000_load
, s
);
82 void isa_ne2000_init(int base
, int irq
, NICInfo
*nd
)
86 qemu_check_nic_model(nd
, "ne2k_isa");
88 dev
= isa_create("ne2k_isa");
89 dev
->qdev
.nd
= nd
; /* hack alert */
90 qdev_prop_set_uint32(&dev
->qdev
, "iobase", base
);
91 qdev_prop_set_uint32(&dev
->qdev
, "irq", irq
);
92 qdev_init(&dev
->qdev
);
95 static ISADeviceInfo ne2000_isa_info
= {
96 .qdev
.name
= "ne2k_isa",
97 .qdev
.size
= sizeof(ISANE2000State
),
98 .init
= isa_ne2000_initfn
,
99 .qdev
.props
= (Property
[]) {
100 DEFINE_PROP_HEX32("iobase", ISANE2000State
, iobase
, 0x300),
101 DEFINE_PROP_UINT32("irq", ISANE2000State
, isairq
, 9),
102 DEFINE_PROP_END_OF_LIST(),
106 static void ne2000_isa_register_devices(void)
108 isa_qdev_register(&ne2000_isa_info
);
111 device_init(ne2000_isa_register_devices
)