diff mbox

[v2,7/9] usb-ehci: add ehci-pci device exit function

Message ID 1401792864-4656-8-git-send-email-arei.gonglei@huawei.com
State New
Headers show

Commit Message

Gonglei (Arei) June 3, 2014, 10:54 a.m. UTC
From: Gonglei <arei.gonglei@huawei.com>

clean up ehci resource when ehci pci device exit.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/hcd-ehci-pci.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Comments

Gerd Hoffmann June 4, 2014, 6:09 a.m. UTC | #1
On Di, 2014-06-03 at 18:54 +0800, arei.gonglei@huawei.com wrote:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> clean up ehci resource when ehci pci device exit.
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/hcd-ehci-pci.c | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
> index 505741a..115d9b5 100644
> --- a/hw/usb/hcd-ehci-pci.c
> +++ b/hw/usb/hcd-ehci-pci.c
> @@ -84,6 +84,38 @@ static void usb_ehci_pci_init(Object *obj)
>      usb_ehci_init(s, DEVICE(obj));
>  }
>  
> +static void usb_ehci_pci_exit(PCIDevice *dev)
> +{

Too much non-pci stuff in here.  I think we should create a
usb_ehci_unrealize function and do the cleanup there, then just call
this from usb_ehci_pci_exit.  You also don't need patch #6 then.

cheers,
  Gerd
Gonglei (Arei) June 4, 2014, 6:22 a.m. UTC | #2
> -----Original Message-----

> From: Gerd Hoffmann [mailto:kraxel@redhat.com]

> Sent: Wednesday, June 04, 2014 2:10 PM

> To: Gonglei (Arei)

> Cc: qemu-devel@nongnu.org; Luonengjun; Huangweidong (C); Huangpeng

> (Peter)

> Subject: Re: [PATCH v2 7/9] usb-ehci: add ehci-pci device exit function

> 

> On Di, 2014-06-03 at 18:54 +0800, arei.gonglei@huawei.com wrote:

> > From: Gonglei <arei.gonglei@huawei.com>

> >

> > clean up ehci resource when ehci pci device exit.

> >

> > Signed-off-by: Gonglei <arei.gonglei@huawei.com>

> > ---

> >  hw/usb/hcd-ehci-pci.c | 33 +++++++++++++++++++++++++++++++++

> >  1 file changed, 33 insertions(+)

> >

> > diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c

> > index 505741a..115d9b5 100644

> > --- a/hw/usb/hcd-ehci-pci.c

> > +++ b/hw/usb/hcd-ehci-pci.c

> > @@ -84,6 +84,38 @@ static void usb_ehci_pci_init(Object *obj)

> >      usb_ehci_init(s, DEVICE(obj));

> >  }

> >

> > +static void usb_ehci_pci_exit(PCIDevice *dev)

> > +{

> 

> Too much non-pci stuff in here.  I think we should create a

> usb_ehci_unrealize function and do the cleanup there, then just call

> this from usb_ehci_pci_exit.  You also don't need patch #6 then.

> 

Good idea! I will do it in v3, Thanks!


Best regards,
-Gonglei
diff mbox

Patch

diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
index 505741a..115d9b5 100644
--- a/hw/usb/hcd-ehci-pci.c
+++ b/hw/usb/hcd-ehci-pci.c
@@ -84,6 +84,38 @@  static void usb_ehci_pci_init(Object *obj)
     usb_ehci_init(s, DEVICE(obj));
 }
 
+static void usb_ehci_pci_exit(PCIDevice *dev)
+{
+    EHCIPCIState *i = PCI_EHCI(dev);
+    EHCIState *s = &i->ehci;
+
+    if (s->frame_timer) {
+        timer_del(s->frame_timer);
+        timer_free(s->frame_timer);
+        s->frame_timer = NULL;
+    }
+    if (s->async_bh) {
+        qemu_bh_delete(s->async_bh);
+    }
+
+    ehci_queues_rip_all(s, 0);
+    ehci_queues_rip_all(s, 1);
+
+    memory_region_del_subregion(&s->mem, &s->mem_caps);
+    memory_region_del_subregion(&s->mem, &s->mem_opreg);
+    memory_region_del_subregion(&s->mem, &s->mem_ports);
+    memory_region_destroy(&s->mem_caps);
+    memory_region_destroy(&s->mem_opreg);
+    memory_region_destroy(&s->mem_ports);
+    memory_region_destroy(&s->mem);
+
+    usb_bus_release(&s->bus);
+
+    if (s->vmstate) {
+        qemu_del_vm_change_state_handler(s->vmstate);
+    }
+}
+
 static void usb_ehci_pci_write_config(PCIDevice *dev, uint32_t addr,
                                       uint32_t val, int l)
 {
@@ -121,6 +153,7 @@  static void ehci_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->init = usb_ehci_pci_initfn;
+    k->exit = usb_ehci_pci_exit;
     k->class_id = PCI_CLASS_SERIAL_USB;
     k->config_write = usb_ehci_pci_write_config;
     dc->hotpluggable = false;