From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: Re: [PATCH 7/9] kvm tools: Use dynamic IO port allocation in virtio-console driver Date: Wed, 25 May 2011 18:35:34 +0300 Message-ID: <1306337734.3079.15.camel@lappy> References: <1306333427-26186-1-git-send-email-levinsasha928@gmail.com> <1306333427-26186-7-git-send-email-levinsasha928@gmail.com> <20110525144250.GC29179@elte.hu> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: penberg@kernel.org, john@jfloren.net, kvm@vger.kernel.org, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com To: Ingo Molnar Return-path: Received: from mail-ww0-f44.google.com ([74.125.82.44]:39384 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755054Ab1EYPg2 (ORCPT ); Wed, 25 May 2011 11:36:28 -0400 Received: by wwa36 with SMTP id 36so8618882wwa.1 for ; Wed, 25 May 2011 08:36:27 -0700 (PDT) In-Reply-To: <20110525144250.GC29179@elte.hu> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, 2011-05-25 at 16:42 +0200, Ingo Molnar wrote: > * Sasha Levin wrote: > > > void virtio_console__init(struct kvm *kvm) > > { > > u8 dev, line, pin; > > + u16 console_base_addr; > > > > if (irq__register_device(VIRTIO_ID_CONSOLE, &dev, &pin, &line) < 0) > > return; > > > > virtio_console_pci_device.irq_pin = pin; > > virtio_console_pci_device.irq_line = line; > > + console_base_addr = ioport__find_free_range(); > > + virtio_console_pci_device.bar[0] = console_base_addr | PCI_BASE_ADDRESS_SPACE_IO; > > + cdev.base_addr = console_base_addr; > > pci__register(&virtio_console_pci_device, dev); > > - ioport__register(IOPORT_VIRTIO_CONSOLE, &virtio_console_io_ops, IOPORT_VIRTIO_CONSOLE_SIZE); > > + ioport__register(console_base_addr, &virtio_console_io_ops, IOPORT_SIZE); > > Why is the ioport registration done in two steps? > > Wouldnt a better sequence be something like: > > > + console_base_addr = ioport__register(&virtio_console_io_ops, IOPORT_SIZE); > > > > + virtio_console_pci_device.bar[0] = console_base_addr | PCI_BASE_ADDRESS_SPACE_IO; > > + cdev.base_addr = console_base_addr; > > pci__register(&virtio_console_pci_device, dev); > > I.e. first register the ioport range - this would also get a free > range for you, and then register the PCI driver? > > Or something even more compact could be done i suspect - all of the > drivers seem to be using the same registration sequence. Some drivers need explicit IO ports, such as the serial driver. It was a question of whether I create another registration function (which may be as simple as calling 'ioport__find_free_range()' before calling the real registration) but it would lead to two 'registration' functions behaving very differently - one returning a new port and one that just does nothing except registering. -- Sasha.