[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] hw: ne2000: make it more QOMconventional
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [Qemu-devel] [PATCH] hw: ne2000: make it more QOMconventional |
Date: |
Sat, 13 Oct 2018 22:36:24 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 |
Hi Li,
On 10/13/18 8:31 AM, Li Qiang wrote:
> Signed-off-by: Li Qiang <address@hidden>
> ---
> hw/net/ne2000.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/hw/net/ne2000.c b/hw/net/ne2000.c
> index 07d79e317f..ab71ad49cb 100644
> --- a/hw/net/ne2000.c
> +++ b/hw/net/ne2000.c
> @@ -33,6 +33,10 @@
>
> #define MAX_ETH_FRAME_SIZE 1514
>
> +#define TYPE_NE2000 "ne2k_pci"
> +#define NE2000(obj) \
> + OBJECT_CHECK(PCINE2000State, (obj), TYPE_NE2000)
If the NIC models are similar to the devices TYPE, you can move the
previous definitions in a new header "hw/net/ne2000.h", then you can
then use it in:
. hw/ppc/mac_newworld.c
. hw/ppc/mac_oldworld.c
. hw/ppc/prep.c
as:
- pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL);
+ pci_nic_init_nofail(&nd_table[i], pci_bus, TYPE_NE2000, NULL);
Let's see what Jason think about it first.
> +
> #define E8390_CMD 0x00 /* The command register (for all pages) */
> /* Page 0 register offsets. */
> #define EN0_CLDALO 0x01 /* Low byte of current local dma addr RD */
> @@ -720,7 +724,7 @@ static NetClientInfo net_ne2000_info = {
>
> static void pci_ne2000_realize(PCIDevice *pci_dev, Error **errp)
> {
> - PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
> + PCINE2000State *d = NE2000(pci_dev);
> NE2000State *s;
> uint8_t *pci_conf;
>
> @@ -742,7 +746,7 @@ static void pci_ne2000_realize(PCIDevice *pci_dev, Error
> **errp)
>
> static void pci_ne2000_exit(PCIDevice *pci_dev)
> {
> - PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
> + PCINE2000State *d = NE2000(pci_dev);
> NE2000State *s = &d->ne2000;
>
> qemu_del_nic(s->nic);
> @@ -751,13 +755,12 @@ static void pci_ne2000_exit(PCIDevice *pci_dev)
>
> static void ne2000_instance_init(Object *obj)
> {
> - PCIDevice *pci_dev = PCI_DEVICE(obj);
> - PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
> + PCINE2000State *d = NE2000(obj);
> NE2000State *s = &d->ne2000;
>
> device_add_bootindex_property(obj, &s->c.bootindex,
> "bootindex", "/address@hidden",
> - &pci_dev->qdev, NULL);
> + DEVICE(obj), NULL);
> }
>
> static Property ne2000_properties[] = {
> @@ -782,7 +785,7 @@ static void ne2000_class_init(ObjectClass *klass, void
> *data)
> }
>
> static const TypeInfo ne2000_info = {
> - .name = "ne2k_pci",
> + .name = TYPE_NE2000,
> .parent = TYPE_PCI_DEVICE,
> .instance_size = sizeof(PCINE2000State),
> .class_init = ne2000_class_init,
>