From patchwork Tue Apr 7 01:31:06 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 16699 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n371UE9n000873 for ; Tue, 7 Apr 2009 01:30:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752299AbZDGB36 (ORCPT ); Mon, 6 Apr 2009 21:29:58 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753975AbZDGB36 (ORCPT ); Mon, 6 Apr 2009 21:29:58 -0400 Received: from mga02.intel.com ([134.134.136.20]:54394 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752299AbZDGB35 (ORCPT ); Mon, 6 Apr 2009 21:29:57 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 06 Apr 2009 18:22:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.39,333,1235980800"; d="scan'208";a="504142840" Received: from yzhao-otc.sh.intel.com ([10.239.48.165]) by orsmga001.jf.intel.com with ESMTP; 06 Apr 2009 18:29:22 -0700 From: Yu Zhao To: jbarnes@virtuousgeek.org Cc: linux-pci@vger.kernel.org, Yu Zhao Subject: [PATCH] PCI: clean up the PCIe capability save/restore Date: Tue, 7 Apr 2009 09:31:06 +0800 Message-Id: <1239067866-15113-1-git-send-email-yu.zhao@intel.com> X-Mailer: git-send-email 1.6.1 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Signed-off-by: Yu Zhao --- drivers/pci/pci.c | 34 ++++++++++++++++------------------ 1 files changed, 16 insertions(+), 18 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index fe7ac2c..af4db4e 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -679,11 +679,19 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state) EXPORT_SYMBOL(pci_choose_state); -#define PCI_EXP_SAVE_REGS 7 +static const int pcie_save_regs[] = { + PCI_EXP_DEVCTL, + PCI_EXP_LNKCTL, + PCI_EXP_SLTCTL, + PCI_EXP_RTCTL, + PCI_EXP_DEVCTL2, + PCI_EXP_LNKCTL2, + PCI_EXP_SLTCTL2 +}; static int pci_save_pcie_state(struct pci_dev *dev) { - int pos, i = 0; + int i, pos; struct pci_cap_saved_state *save_state; u16 *cap; @@ -698,20 +706,15 @@ static int pci_save_pcie_state(struct pci_dev *dev) } cap = (u16 *)&save_state->data[0]; - pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &cap[i++]); - pci_read_config_word(dev, pos + PCI_EXP_LNKCTL, &cap[i++]); - pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]); - pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]); - pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &cap[i++]); - pci_read_config_word(dev, pos + PCI_EXP_LNKCTL2, &cap[i++]); - pci_read_config_word(dev, pos + PCI_EXP_SLTCTL2, &cap[i++]); + for (i = 0; i < ARRAY_SIZE(pcie_save_regs); i++) + pci_read_config_word(dev, pos + pcie_save_regs[i], &cap[i]); return 0; } static void pci_restore_pcie_state(struct pci_dev *dev) { - int i = 0, pos; + int i, pos; struct pci_cap_saved_state *save_state; u16 *cap; @@ -721,13 +724,8 @@ static void pci_restore_pcie_state(struct pci_dev *dev) return; cap = (u16 *)&save_state->data[0]; - pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, cap[i++]); - pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]); - pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]); - pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]); - pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, cap[i++]); - pci_write_config_word(dev, pos + PCI_EXP_LNKCTL2, cap[i++]); - pci_write_config_word(dev, pos + PCI_EXP_SLTCTL2, cap[i++]); + for (i = 0; i < ARRAY_SIZE(pcie_save_regs); i++) + pci_write_config_word(dev, pos + pcie_save_regs[i], cap[i]); } @@ -1413,7 +1411,7 @@ void pci_allocate_cap_save_buffers(struct pci_dev *dev) int error; error = pci_add_cap_save_buffer(dev, PCI_CAP_ID_EXP, - PCI_EXP_SAVE_REGS * sizeof(u16)); + ARRAY_SIZE(pcie_save_regs) * sizeof(u16)); if (error) dev_err(&dev->dev, "unable to preallocate PCI Express save buffer\n");