From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eduard - Gabriel Munteanu Subject: Re: [Qemu-devel] [RFC] Getting specific device from qdev structs Date: Mon, 21 Jun 2010 17:32:37 +0300 Message-ID: <20100621143237.GA10604@localhost> References: <20100621134858.GA8275@localhost> <201006211507.13975.paul@codesourcery.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, joro@8bytes.org To: Paul Brook Return-path: Received: from mail-bw0-f46.google.com ([209.85.214.46]:33232 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752211Ab0FUOd1 (ORCPT ); Mon, 21 Jun 2010 10:33:27 -0400 Received: by bwz7 with SMTP id 7so968324bwz.19 for ; Mon, 21 Jun 2010 07:33:26 -0700 (PDT) Content-Disposition: inline In-Reply-To: <201006211507.13975.paul@codesourcery.com> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Jun 21, 2010 at 03:07:13PM +0100, Paul Brook wrote: > > So I've been looking for a way to obtain things like a PCIDevice from a > > more generic structure (say from hw/qdev.h), > > If you're having to figure out what kind of a device you have then I think > you're already doing something else wrong. I'd expect the bits of code that > needs to identify devices to be inherently bus specific. > > If you've got some sort of on-cpu IOMMU which is asking "did this come from an > ISA device, or a PCI device?", then I suspect you've got your abstraction > layers wrong. This should already have been handled by the pci/isa to cpu > bridge. > > Paul Hi, Thanks for your reply. This isn't about a specific IOMMU. Let me describe the situation better: 1. I'm implementing the AMD IOMMU, which is a PCI IOMMU (not in the CPU). 2. Devices need address translation and checking through this IOMMU. 3. But in the future there might be other IOMMU implementations, possibly for other bus types. Yes, I could (and have already done to test my code) modify device code to ask the AMD IOMMU for translation. But we have stuff like AIO, which isn't really bus-specific and would result in spagetti code if I add PCI-specific stuff, then somebody else does the same for other buses and so on. Moreover, even for PCI, it isn't really straightforward to obtain the bus-device-function number required to do translation from AIO code (e.g. I needed to add the devfn or a pointer to the actual PCIDevice to BMDMAState to get it working for PIIX). So I considered providing a generic IOMMU translation/checking API that could be used by all devices and all IOMMUs. Generally getting the {PCI,ISA,Whatever}Device should be enough, I think. If the IOMMU can't handle that specific bus, that's no problem, we can have generic code do identity mapping without any access checking. If somebody comes along and wants to implement another IOMMU emulation, all he needs is to provide implementations for those functions. Eduard