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
24 #include "qemu/osdep.h"
25 #include "hw/pci/pci.h"
27 #include "sysemu/sysemu.h"
29 typedef struct PCINE2000State
{
34 static const VMStateDescription vmstate_pci_ne2000
= {
37 .minimum_version_id
= 3,
38 .fields
= (VMStateField
[]) {
39 VMSTATE_PCI_DEVICE(dev
, PCINE2000State
),
40 VMSTATE_STRUCT(ne2000
, PCINE2000State
, 0, vmstate_ne2000
, NE2000State
),
45 static NetClientInfo net_ne2000_info
= {
46 .type
= NET_CLIENT_DRIVER_NIC
,
47 .size
= sizeof(NICState
),
48 .receive
= ne2000_receive
,
51 static void pci_ne2000_realize(PCIDevice
*pci_dev
, Error
**errp
)
53 PCINE2000State
*d
= DO_UPCAST(PCINE2000State
, dev
, pci_dev
);
57 pci_conf
= d
->dev
.config
;
58 pci_conf
[PCI_INTERRUPT_PIN
] = 1; /* interrupt pin A */
61 ne2000_setup_io(s
, DEVICE(pci_dev
), 0x100);
62 pci_register_bar(&d
->dev
, 0, PCI_BASE_ADDRESS_SPACE_IO
, &s
->io
);
63 s
->irq
= pci_allocate_irq(&d
->dev
);
65 qemu_macaddr_default_if_unset(&s
->c
.macaddr
);
68 s
->nic
= qemu_new_nic(&net_ne2000_info
, &s
->c
,
69 object_get_typename(OBJECT(pci_dev
)),
71 qemu_format_nic_info_str(qemu_get_queue(s
->nic
), s
->c
.macaddr
.a
);
74 static void pci_ne2000_exit(PCIDevice
*pci_dev
)
76 PCINE2000State
*d
= DO_UPCAST(PCINE2000State
, dev
, pci_dev
);
77 NE2000State
*s
= &d
->ne2000
;
80 qemu_free_irq(s
->irq
);
83 static void ne2000_instance_init(Object
*obj
)
85 PCIDevice
*pci_dev
= PCI_DEVICE(obj
);
86 PCINE2000State
*d
= DO_UPCAST(PCINE2000State
, dev
, pci_dev
);
87 NE2000State
*s
= &d
->ne2000
;
89 device_add_bootindex_property(obj
, &s
->c
.bootindex
,
90 "bootindex", "/ethernet-phy@0",
91 &pci_dev
->qdev
, NULL
);
94 static Property ne2000_properties
[] = {
95 DEFINE_NIC_PROPERTIES(PCINE2000State
, ne2000
.c
),
96 DEFINE_PROP_END_OF_LIST(),
99 static void ne2000_class_init(ObjectClass
*klass
, void *data
)
101 DeviceClass
*dc
= DEVICE_CLASS(klass
);
102 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
104 k
->realize
= pci_ne2000_realize
;
105 k
->exit
= pci_ne2000_exit
;
106 k
->romfile
= "efi-ne2k_pci.rom",
107 k
->vendor_id
= PCI_VENDOR_ID_REALTEK
;
108 k
->device_id
= PCI_DEVICE_ID_REALTEK_8029
;
109 k
->class_id
= PCI_CLASS_NETWORK_ETHERNET
;
110 dc
->vmsd
= &vmstate_pci_ne2000
;
111 dc
->props
= ne2000_properties
;
112 set_bit(DEVICE_CATEGORY_NETWORK
, dc
->categories
);
115 static const TypeInfo ne2000_info
= {
117 .parent
= TYPE_PCI_DEVICE
,
118 .instance_size
= sizeof(PCINE2000State
),
119 .class_init
= ne2000_class_init
,
120 .instance_init
= ne2000_instance_init
,
121 .interfaces
= (InterfaceInfo
[]) {
122 { INTERFACE_CONVENTIONAL_PCI_DEVICE
},
127 static void ne2000_register_types(void)
129 type_register_static(&ne2000_info
);
132 type_init(ne2000_register_types
)