2 * QEMU NE2000 emulation (PCI bus)
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
25 #include "qemu/osdep.h"
27 #include "hw/pci/pci_device.h"
28 #include "hw/qdev-properties.h"
29 #include "migration/vmstate.h"
31 #include "sysemu/sysemu.h"
33 typedef struct PCINE2000State
{
38 static const VMStateDescription vmstate_pci_ne2000
= {
41 .minimum_version_id
= 3,
42 .fields
= (const VMStateField
[]) {
43 VMSTATE_PCI_DEVICE(dev
, PCINE2000State
),
44 VMSTATE_STRUCT(ne2000
, PCINE2000State
, 0, vmstate_ne2000
, NE2000State
),
49 static NetClientInfo net_ne2000_info
= {
50 .type
= NET_CLIENT_DRIVER_NIC
,
51 .size
= sizeof(NICState
),
52 .receive
= ne2000_receive
,
55 static void pci_ne2000_realize(PCIDevice
*pci_dev
, Error
**errp
)
57 PCINE2000State
*d
= DO_UPCAST(PCINE2000State
, dev
, pci_dev
);
61 pci_conf
= d
->dev
.config
;
62 pci_conf
[PCI_INTERRUPT_PIN
] = 1; /* interrupt pin A */
65 ne2000_setup_io(s
, DEVICE(pci_dev
), 0x100);
66 pci_register_bar(&d
->dev
, 0, PCI_BASE_ADDRESS_SPACE_IO
, &s
->io
);
67 s
->irq
= pci_allocate_irq(&d
->dev
);
69 qemu_macaddr_default_if_unset(&s
->c
.macaddr
);
72 s
->nic
= qemu_new_nic(&net_ne2000_info
, &s
->c
,
73 object_get_typename(OBJECT(pci_dev
)),
75 &pci_dev
->qdev
.mem_reentrancy_guard
, s
);
76 qemu_format_nic_info_str(qemu_get_queue(s
->nic
), s
->c
.macaddr
.a
);
79 static void pci_ne2000_exit(PCIDevice
*pci_dev
)
81 PCINE2000State
*d
= DO_UPCAST(PCINE2000State
, dev
, pci_dev
);
82 NE2000State
*s
= &d
->ne2000
;
85 qemu_free_irq(s
->irq
);
88 static void ne2000_instance_init(Object
*obj
)
90 PCIDevice
*pci_dev
= PCI_DEVICE(obj
);
91 PCINE2000State
*d
= DO_UPCAST(PCINE2000State
, dev
, pci_dev
);
92 NE2000State
*s
= &d
->ne2000
;
94 device_add_bootindex_property(obj
, &s
->c
.bootindex
,
95 "bootindex", "/ethernet-phy@0",
99 static Property ne2000_properties
[] = {
100 DEFINE_NIC_PROPERTIES(PCINE2000State
, ne2000
.c
),
101 DEFINE_PROP_END_OF_LIST(),
104 static void ne2000_class_init(ObjectClass
*klass
, void *data
)
106 DeviceClass
*dc
= DEVICE_CLASS(klass
);
107 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
109 k
->realize
= pci_ne2000_realize
;
110 k
->exit
= pci_ne2000_exit
;
111 k
->romfile
= "efi-ne2k_pci.rom",
112 k
->vendor_id
= PCI_VENDOR_ID_REALTEK
;
113 k
->device_id
= PCI_DEVICE_ID_REALTEK_8029
;
114 k
->class_id
= PCI_CLASS_NETWORK_ETHERNET
;
115 dc
->vmsd
= &vmstate_pci_ne2000
;
116 device_class_set_props(dc
, ne2000_properties
);
117 set_bit(DEVICE_CATEGORY_NETWORK
, dc
->categories
);
120 static const TypeInfo ne2000_info
= {
122 .parent
= TYPE_PCI_DEVICE
,
123 .instance_size
= sizeof(PCINE2000State
),
124 .class_init
= ne2000_class_init
,
125 .instance_init
= ne2000_instance_init
,
126 .interfaces
= (InterfaceInfo
[]) {
127 { INTERFACE_CONVENTIONAL_PCI_DEVICE
},
132 static void ne2000_register_types(void)
134 type_register_static(&ne2000_info
);
137 type_init(ne2000_register_types
)