From patchwork Fri Nov 27 02:51:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 549291 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id E67EF1401DA for ; Fri, 27 Nov 2015 13:56:18 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=JwZLt0E+; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F33484B903; Fri, 27 Nov 2015 03:56:16 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t90vekoD5kw0; Fri, 27 Nov 2015 03:56:16 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E58244B8FC; Fri, 27 Nov 2015 03:54:05 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 85A644B8FD for ; Fri, 27 Nov 2015 03:51:47 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ha0WJ2YSc-1j for ; Fri, 27 Nov 2015 03:51:47 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ob0-f172.google.com (mail-ob0-f172.google.com [209.85.214.172]) by theia.denx.de (Postfix) with ESMTPS id 31E404B8FC for ; Fri, 27 Nov 2015 03:51:42 +0100 (CET) Received: by obbww6 with SMTP id ww6so73691097obb.0 for ; Thu, 26 Nov 2015 18:51:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=aUZTvZ0o27e+o4Mnjoyay8S9lJSSUTMD/YpPufDLFQo=; b=JwZLt0E+TZjHY5Y9LRBef2f0wgVAZ1m07QZdwGpBZQaGSdIMsLAhC2jZar8Eh2XI4N /+hsXoeITZuwhPgscYiWsXYs6tC37R67/WOVi+remcGAVaJlPAajBCmje/VzmPIxHIxw XsVrMM9sHpJUpmnH+7Zv56zYkokFJGj8jeEs87y03OhRpvQsu+3u3fxNd9lzufZp4K/c UlMa6Ahf+sx1Q4Wzhr9mIOL9EiBd/6VF4BS3IsOJEGK56yzRtjuIoOMjGMy/hh8x5nIk rg1pnE4npzeumsVcaOcw9nV/kxrbs09j+i6D3F07qdr51E+HFto7eiuaHZEVeZyyUOvn Z18Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=aUZTvZ0o27e+o4Mnjoyay8S9lJSSUTMD/YpPufDLFQo=; b=iFyZ10MkGNulywOC2q37LnSoY91Dtz59y9SLVoyM2zhdT/hTu7ZKOKMLvr1Iatu0jo BsxuaM4AjfCrwT03P1nQuOIgTj91OsBsiZ+AISvU99M0gJLaqj0Ard46DKTFPtBNss8M IiTvv2cVQ7rVQKmE5ShpgSA07rK6AW1FGu8485bgIIaqiVBiCSWzUi7SaMmToqSq5hJn KiusUuktbAubMuh55h7R40tCUreEtHXNrTCDxiyA0l0fDP79BjyZVpKK2fCCCD5EzN9W cSE0VG0qBAN/fb99WIj9MbFaO+YsN4ddbIsfvI4F9h+5Vy6Yv0oWnZi4htw3Kfs5qO94 8uyA== X-Gm-Message-State: ALoCoQlsl+H9vL87yHNnAxBpqrZqGqPAqd3iT05d0i53QqOsoPf0l/ovsAUACZZJENunnZcoPXV9 X-Received: by 10.60.161.178 with SMTP id xt18mr30982990oeb.28.1448592701033; Thu, 26 Nov 2015 18:51:41 -0800 (PST) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by smtp.gmail.com with ESMTPSA id q188sm14293745oif.28.2015.11.26.18.51.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Nov 2015 18:51:39 -0800 (PST) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 3DBD2221313; Thu, 26 Nov 2015 19:51:37 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 26 Nov 2015 19:51:24 -0700 Message-Id: <1448592690-14911-8-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 In-Reply-To: <1448592690-14911-1-git-send-email-sjg@chromium.org> References: <1448592690-14911-1-git-send-email-sjg@chromium.org> Subject: [U-Boot] [PATCH v3 07/13] dm: pci: Reorder functions in cmd_pci.c X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Before converting this to driver model, reorder the code to avoid forward function declarations. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- Changes in v3: None Changes in v2: None common/cmd_pci.c | 216 +++++++++++++++++++++++++++---------------------------- 1 file changed, 106 insertions(+), 110 deletions(-) diff --git a/common/cmd_pci.c b/common/cmd_pci.c index 190e3b6..f8faa31 100644 --- a/common/cmd_pci.c +++ b/common/cmd_pci.c @@ -22,115 +22,6 @@ #include #include -/* - * Follows routines for the output of infos about devices on PCI bus. - */ - -void pci_header_show(pci_dev_t dev); -void pci_header_show_brief(pci_dev_t dev); - -/* - * Subroutine: pciinfo - * - * Description: Show information about devices on PCI bus. - * Depending on the define CONFIG_SYS_SHORT_PCI_LISTING - * the output will be more or less exhaustive. - * - * Inputs: bus_no the number of the bus to be scanned. - * - * Return: None - * - */ -void pciinfo(int BusNum, int ShortPCIListing) -{ - struct pci_controller *hose = pci_bus_to_hose(BusNum); - int Device; - int Function; - unsigned char HeaderType; - unsigned short VendorID; - pci_dev_t dev; - int ret; - - if (!hose) - return; - - printf("Scanning PCI devices on bus %d\n", BusNum); - - if (ShortPCIListing) { - printf("BusDevFun VendorId DeviceId Device Class Sub-Class\n"); - printf("_____________________________________________________________\n"); - } - - for (Device = 0; Device < PCI_MAX_PCI_DEVICES; Device++) { - HeaderType = 0; - VendorID = 0; - for (Function = 0; Function < PCI_MAX_PCI_FUNCTIONS; Function++) { - /* - * If this is not a multi-function device, we skip the rest. - */ - if (Function && !(HeaderType & 0x80)) - break; - - dev = PCI_BDF(BusNum, Device, Function); - - if (pci_skip_dev(hose, dev)) - continue; - - ret = pci_read_config_word(dev, PCI_VENDOR_ID, - &VendorID); - if (ret) - goto error; - if ((VendorID == 0xFFFF) || (VendorID == 0x0000)) - continue; - - if (!Function) pci_read_config_byte(dev, PCI_HEADER_TYPE, &HeaderType); - - if (ShortPCIListing) - { - printf("%02x.%02x.%02x ", BusNum, Device, Function); - pci_header_show_brief(dev); - } - else - { - printf("\nFound PCI device %02x.%02x.%02x:\n", - BusNum, Device, Function); - pci_header_show(dev); - } - } - } - - return; -error: - printf("Cannot read bus configuration: %d\n", ret); -} - - -/* - * Subroutine: pci_header_show_brief - * - * Description: Reads and prints the header of the - * specified PCI device in short form. - * - * Inputs: dev Bus+Device+Function number - * - * Return: None - * - */ -void pci_header_show_brief(pci_dev_t dev) -{ - u16 vendor, device; - u8 class, subclass; - - pci_read_config_word(dev, PCI_VENDOR_ID, &vendor); - pci_read_config_word(dev, PCI_DEVICE_ID, &device); - pci_read_config_byte(dev, PCI_CLASS_CODE, &class); - pci_read_config_byte(dev, PCI_CLASS_SUB_CODE, &subclass); - - printf("0x%.4x 0x%.4x %-23s 0x%.2x\n", - vendor, device, - pci_class_str(class), subclass); -} - struct pci_reg_info { const char *name; enum pci_size_t size; @@ -284,10 +175,10 @@ void pci_header_show(pci_dev_t dev) { u8 class, header_type; + pci_read_config_byte(dev, PCI_CLASS_CODE, &class); pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type); pci_show_regs(dev, regs_start); - pci_read_config_byte(dev, PCI_CLASS_CODE, &class); printf(" class code = 0x%.2x (%s)\n", class, pci_class_str(class)); pci_show_regs(dev, regs_rest); @@ -309,6 +200,111 @@ void pci_header_show(pci_dev_t dev) } } +/* + * Subroutine: pci_header_show_brief + * + * Description: Reads and prints the header of the + * specified PCI device in short form. + * + * Inputs: dev Bus+Device+Function number + * + * Return: None + * + */ +void pci_header_show_brief(pci_dev_t dev) +{ + u16 vendor, device; + u8 class, subclass; + + pci_read_config_word(dev, PCI_VENDOR_ID, &vendor); + pci_read_config_word(dev, PCI_DEVICE_ID, &device); + pci_read_config_byte(dev, PCI_CLASS_CODE, &class); + pci_read_config_byte(dev, PCI_CLASS_SUB_CODE, &subclass); + + printf("0x%.4x 0x%.4x %-23s 0x%.2x\n", + vendor, device, + pci_class_str(class), subclass); +} + +/* + * Subroutine: pciinfo + * + * Description: Show information about devices on PCI bus. + * Depending on the defineCONFIG_SYS_SHORT_PCI_LISTING + * the output will be more or less exhaustive. + * + * Inputs: bus_no the number of the bus to be scanned. + * + * Return: None + * + */ +void pciinfo(int bus_num, int short_pci_listing) +{ + struct pci_controller *hose = pci_bus_to_hose(bus_num); + int Device; + int Function; + unsigned char HeaderType; + unsigned short VendorID; + pci_dev_t dev; + int ret; + + if (!hose) + return; + + printf("Scanning PCI devices on bus %d\n", bus_num); + + if (short_pci_listing) { + printf("BusDevFun VendorId DeviceId Device Class Sub-Class\n"); + printf("_____________________________________________________________\n"); + } + + for (Device = 0; Device < PCI_MAX_PCI_DEVICES; Device++) { + HeaderType = 0; + VendorID = 0; + for (Function = 0; Function < PCI_MAX_PCI_FUNCTIONS; + Function++) { + /* + * If this is not a multi-function device, we skip + * the rest. + */ + if (Function && !(HeaderType & 0x80)) + break; + + dev = PCI_BDF(bus_num, Device, Function); + + if (pci_skip_dev(hose, dev)) + continue; + + ret = pci_read_config_word(dev, PCI_VENDOR_ID, + &VendorID); + if (ret) + goto error; + if ((VendorID == 0xFFFF) || (VendorID == 0x0000)) + continue; + + if (!Function) { + pci_read_config_byte(dev, PCI_HEADER_TYPE, + &HeaderType); + } + + if (short_pci_listing) { + printf("%02x.%02x.%02x ", bus_num, Device, + Function); + pci_header_show_brief(dev); + } else { + printf("\nFound PCI device %02x.%02x.%02x:\n", + bus_num, Device, Function); + pci_header_show(dev); + } + } + } + + return; +error: + printf("Cannot read bus configuration: %d\n", ret); +} + + /* Convert the "bus.device.function" identifier into a number. */ static pci_dev_t get_pci_dev(char* name)