[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 2/7] hw/net/eepro100: Introduce TYPE_EEPRO100 QOM abstract par
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v2 2/7] hw/net/eepro100: Introduce TYPE_EEPRO100 QOM abstract parent |
Date: |
Mon, 13 Feb 2023 11:10:43 +0100 |
Have all the EEPRO100-based devices share a common (abstract)
QOM parent.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/net/eepro100.c | 58 +++++++++++++++++++++++++++++++++--------------
1 file changed, 41 insertions(+), 17 deletions(-)
diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c
index dce75039ec..4b5d45576b 100644
--- a/hw/net/eepro100.c
+++ b/hw/net/eepro100.c
@@ -235,8 +235,20 @@ typedef enum {
ru_ready = 4
} ru_state_t;
-typedef struct {
+#define TYPE_EEPRO100 "eepro100"
+OBJECT_DECLARE_TYPE(EEPRO100State, EEPRO100Class, EEPRO100)
+
+struct EEPRO100Class {
+ /*< private >*/
+ PCIDeviceClass parent_class;
+ /*< public >*/
+};
+
+struct EEPRO100State {
+ /*< private >*/
PCIDevice dev;
+ /*< public >*/
+
/* Hash register (multicast mask array, multiple individual addresses). */
uint8_t mult[8];
MemoryRegion mmio_bar;
@@ -279,7 +291,7 @@ typedef struct {
/* Quasi static device properties (no need to save them). */
uint16_t stats_size;
bool has_extended_tcb_support;
-} EEPRO100State;
+};
/* Word indices in EEPROM. */
typedef enum {
@@ -2055,43 +2067,55 @@ static Property e100_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
-static void eepro100_class_init(ObjectClass *klass, void *data)
+static void eepro100_base_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
E100PCIDeviceInfo *info;
- info = eepro100_get_class_by_name(object_class_get_name(klass));
set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
device_class_set_props(dc, e100_properties);
- dc->desc = info->desc;
k->vendor_id = PCI_VENDOR_ID_INTEL;
k->class_id = PCI_CLASS_NETWORK_ETHERNET;
k->romfile = "pxe-eepro100.rom";
k->realize = e100_nic_realize;
k->exit = pci_nic_uninit;
+
+ info = eepro100_get_class_by_name(object_class_get_name(klass));
+ if (!info) {
+ /* base class */
+ return;
+ }
+ dc->desc = info->desc;
k->device_id = info->device_id;
k->revision = info->revision;
k->subsystem_vendor_id = info->subsystem_vendor_id;
k->subsystem_id = info->subsystem_id;
}
+static const TypeInfo eepro100_base_info = {
+ .name = TYPE_EEPRO100,
+ .parent = TYPE_PCI_DEVICE,
+ .abstract = true,
+ .class_init = eepro100_base_class_init,
+ .class_size = sizeof(EEPRO100Class),
+ .instance_size = sizeof(EEPRO100State),
+ .instance_init = eepro100_instance_init,
+ .interfaces = (InterfaceInfo[]) {
+ { INTERFACE_CONVENTIONAL_PCI_DEVICE },
+ { },
+ },
+};
+
static void eepro100_register_types(void)
{
- size_t i;
- for (i = 0; i < ARRAY_SIZE(e100_devices); i++) {
- TypeInfo type_info = {};
- E100PCIDeviceInfo *info = &e100_devices[i];
+ type_register_static(&eepro100_base_info);
- type_info.name = info->name;
- type_info.parent = TYPE_PCI_DEVICE;
- type_info.class_init = eepro100_class_init;
- type_info.instance_size = sizeof(EEPRO100State);
- type_info.instance_init = eepro100_instance_init;
- type_info.interfaces = (InterfaceInfo[]) {
- { INTERFACE_CONVENTIONAL_PCI_DEVICE },
- { },
+ for (size_t i = 0; i < ARRAY_SIZE(e100_devices); i++) {
+ TypeInfo type_info = {
+ .name = e100_devices[i].name,
+ .parent = TYPE_EEPRO100,
};
type_register(&type_info);
--
2.38.1
- [PATCH v2 0/7] hw/net/eepro100: Finish QDev conversion, Philippe Mathieu-Daudé, 2023/02/13
- [PATCH v2 1/7] hw/net/eepro100: Abort if pci_add_capability() ever fail, Philippe Mathieu-Daudé, 2023/02/13
- [PATCH v2 2/7] hw/net/eepro100: Introduce TYPE_EEPRO100 QOM abstract parent,
Philippe Mathieu-Daudé <=
- [PATCH v2 3/7] hw/net/eepro100: Convert reset handler to DeviceReset, Philippe Mathieu-Daudé, 2023/02/13
- [PATCH v2 4/7] hw/net/eepro100: Pass E100PCIDeviceInfo as class init data, Philippe Mathieu-Daudé, 2023/02/13
- [PATCH v2 5/7] hw/net/eepro100: Remove instance EEPRO100State::has_extended_tcb_support, Philippe Mathieu-Daudé, 2023/02/13
- [PATCH v2 6/7] hw/net/eepro100: Remove instance's EEPRO100State::device, Philippe Mathieu-Daudé, 2023/02/13
- [PATCH v2 7/7] hw/net/eepro100: Replace DO_UPCAST(EEPRO100State) by EEPRO100(), Philippe Mathieu-Daudé, 2023/02/13
- Re: [PATCH v2 0/7] hw/net/eepro100: Finish QDev conversion, Philippe Mathieu-Daudé, 2023/02/23