From patchwork Wed Jul 7 03:14:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 58077 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 063E9B6EF3 for ; Wed, 7 Jul 2010 13:20:06 +1000 (EST) Received: from localhost ([127.0.0.1]:54169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OWLB5-0000Po-7r for incoming@patchwork.ozlabs.org; Tue, 06 Jul 2010 23:20:03 -0400 Received: from [140.186.70.92] (port=56239 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OWL9A-0008FF-RP for qemu-devel@nongnu.org; Tue, 06 Jul 2010 23:18:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OWL99-0007l6-83 for qemu-devel@nongnu.org; Tue, 06 Jul 2010 23:18:04 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:58438) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OWL98-0007kX-PV for qemu-devel@nongnu.org; Tue, 06 Jul 2010 23:18:03 -0400 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id 1DE1A1076F5; Wed, 7 Jul 2010 12:18:00 +0900 (JST) Received: (nullmailer pid 4311 invoked by uid 1000); Wed, 07 Jul 2010 03:14:02 -0000 From: Isaku Yamahata To: seabios@seabios.org Date: Wed, 7 Jul 2010 12:14:01 +0900 Message-Id: <134ed9d1f3c6cbf5c6fe5d58b221f17be136b91a.1278472308.git.yamahata@valinux.co.jp> X-Mailer: git-send-email 1.7.1.1 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: yamahata@valinux.co.jp, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH v2 1/2] seabios: pci: introduce helper function to initialize a given device. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org introduce helper function to initialize a given device, This will be used later. Signed-off-by: Isaku Yamahata --- src/pci.c | 20 ++++++++++++++++++++ src/pci.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 0 deletions(-) diff --git a/src/pci.c b/src/pci.c index 1ab3c2c..c54b084 100644 --- a/src/pci.c +++ b/src/pci.c @@ -183,3 +183,23 @@ pci_find_class(u16 classid) } return -1; } + +int pci_init_device(const struct pci_device_id *ids, u16 bdf, void *arg) +{ + u16 vendor_id = pci_config_readw(bdf, PCI_VENDOR_ID); + u16 device_id = pci_config_readw(bdf, PCI_DEVICE_ID); + u16 class = pci_config_readw(bdf, PCI_CLASS_DEVICE); + + while (ids->vendid || ids->class_mask) { + if ((ids->vendid == PCI_ANY_ID || ids->vendid == vendor_id) && + (ids->devid == PCI_ANY_ID || ids->devid == device_id) && + !((ids->class ^ class) & ids->class_mask)) { + if (ids->func) { + ids->func(bdf, arg); + } + return 0; + } + ids++; + } + return -1; +} diff --git a/src/pci.h b/src/pci.h index e40e116..fa6a32d 100644 --- a/src/pci.h +++ b/src/pci.h @@ -60,6 +60,40 @@ int pci_next(int bdf, int *pmax); ; MAX = pci_bus_devfn_to_bdf(BUS, 0) + 0x0100, \ BDF = pci_next(BDF + 1, &MAX)) +#define PCI_ANY_ID (~0) +struct pci_device_id { + u32 vendid; + u32 devid; + u32 class; + u32 class_mask; + void (*func)(u16 bdf, void *arg); +}; + +#define PCI_DEVICE(vendor_id, device_id, init_func) \ + { \ + .vendid = (vendor_id), \ + .devid = (device_id), \ + .class = PCI_ANY_ID, \ + .class_mask = 0, \ + .func = (init_func) \ + } + +#define PCI_DEVICE_CLASS(vendor_id, device_id, class_code, init_func) \ + { \ + .vendid = (vendor_id), \ + .devid = (device_id), \ + .class = (class_code), \ + .class_mask = ~0, \ + .func = (init_func) \ + } + +#define PCI_DEVICE_END \ + { \ + .vendid = 0, \ + } + +int pci_init_device(const struct pci_device_id *table, u16 bdf, void *arg); + // pirtable.c void create_pirtable(void);