From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE424312831 for ; Fri, 12 Dec 2025 09:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.111 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765532245; cv=none; b=Arra3ixA5N5vC7wzh1M3TfnOeifwBKTHm6sEv0oocz7FUUMVvSKLUI15qMET9EeCxPTKZS8FZHdGV3OTx9BIXH0n5Dv2LxktgF0zEMeq+AIXx2Mb9YfzDRh5XXabM3xaO/X7dgd/GR3J00JS/AZpwvg6KiugRSpJx1hci9RO6tE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765532245; c=relaxed/simple; bh=RCz+f2Ds2GIA4HYZY0OhESWNqfL+y+oGECastnjHdRA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eK86dFsq64cAB3Xi3YbY7A3Veapzqy7cJbYJ7kIoeRYCx0z2r0m6YXTnI9aVpTkykzKl91r5ktzPiMtZwJxXPAAvjUQOKOhXqLc1Y+p1t+HCIOKz4/6DoHy5MYy4nTiuPDdakEy/VTdmu0JiCuuq+VVUDxNtJOfb9ODb5xkr61M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=mI/pLxZz; arc=none smtp.client-ip=115.124.30.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="mI/pLxZz" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1765532239; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=ofQqfXCkKnPZWIJEO2shHsgh5Po2glcAhbIHa6X9hKI=; b=mI/pLxZzEpgZnlcgQi7BQrlmjNl7VfzNY8X5Gm0QzBIwl9RpgL0mGSm5BXkTeUE3f9+oD4gnbg9YYDUcmTHQ1DYrbBVvDKXQoZlty/6VB41a3ykV9IJ0YxH2WepdPc+A64eqKcDuD7EaiLmqKIqQAp17WVTXyJjW5vI4EJTqf8g= Received: from localhost(mailfrom:kanie@linux.alibaba.com fp:SMTPD_---0Wuduu8x_1765532235 cluster:ay36) by smtp.aliyun-inc.com; Fri, 12 Dec 2025 17:37:18 +0800 From: Guixin Liu To: Bjorn Helgaas , Andy Shevchenko , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: linux-pci@vger.kernel.org Subject: [PATCH v10 1/2] PCI: Introduce named defines for pci rom Date: Fri, 12 Dec 2025 17:37:09 +0800 Message-ID: <20251212093711.36407-2-kanie@linux.alibaba.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251212093711.36407-1-kanie@linux.alibaba.com> References: <20251212093711.36407-1-kanie@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Convert the magic numbers associated with PCI ROM into named definitions. Some of these definitions will be used in the second fix patch. Signed-off-by: Guixin Liu --- drivers/pci/rom.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c index e18d3a4383ba..4f7641b93b4b 100644 --- a/drivers/pci/rom.c +++ b/drivers/pci/rom.c @@ -5,13 +5,28 @@ * (C) Copyright 2004 Jon Smirl * (C) Copyright 2004 Silicon Graphics, Inc. Jesse Barnes */ + +#include #include #include #include +#include #include #include "pci.h" +#define PCI_ROM_HEADER_SIZE 0x1A +#define PCI_ROM_POINTER_TO_DATA_STRUCT 0x18 +#define PCI_ROM_LAST_IMAGE_INDICATOR 0x15 +#define PCI_ROM_LAST_IMAGE_INDICATOR_BIT BIT(7) +#define PCI_ROM_IMAGE_LEN 0x10 +#define PCI_ROM_IMAGE_SECTOR_SIZE SZ_512 +#define PCI_ROM_IMAGE_SIGNATURE 0xAA55 + +/* Data structure signature is "PCIR" in ASCII representation */ +#define PCI_ROM_DATA_STRUCT_SIGNATURE 0x52494350 +#define PCI_ROM_DATA_STRUCT_LEN 0x0A + /** * pci_enable_rom - enable ROM decoding for a PCI device * @pdev: PCI device to enable @@ -91,26 +106,27 @@ static size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, do { void __iomem *pds; /* Standard PCI ROMs start out with these bytes 55 AA */ - if (readw(image) != 0xAA55) { - pci_info(pdev, "Invalid PCI ROM header signature: expecting 0xaa55, got %#06x\n", - readw(image)); + if (readw(image) != PCI_ROM_IMAGE_SIGNATURE) { + pci_info(pdev, "Invalid PCI ROM header signature: expecting %#06x, got %#06x\n", + PCI_ROM_IMAGE_SIGNATURE, readw(image)); break; } /* get the PCI data structure and check its "PCIR" signature */ - pds = image + readw(image + 24); - if (readl(pds) != 0x52494350) { - pci_info(pdev, "Invalid PCI ROM data signature: expecting 0x52494350, got %#010x\n", - readl(pds)); + pds = image + readw(image + PCI_ROM_POINTER_TO_DATA_STRUCT); + if (readl(pds) != PCI_ROM_DATA_STRUCT_SIGNATURE) { + pci_info(pdev, "Invalid PCI ROM data signature: expecting %#010x, got %#010x\n", + PCI_ROM_DATA_STRUCT_SIGNATURE, readl(pds)); break; } - last_image = readb(pds + 21) & 0x80; - length = readw(pds + 16); - image += length * 512; + last_image = readb(pds + PCI_ROM_LAST_IMAGE_INDICATOR) & + PCI_ROM_LAST_IMAGE_INDICATOR_BIT; + length = readw(pds + PCI_ROM_IMAGE_LEN); + image += length * PCI_ROM_IMAGE_SECTOR_SIZE; /* Avoid iterating through memory outside the resource window */ if (image >= rom + size) break; if (!last_image) { - if (readw(image) != 0xAA55) { + if (readw(image) != PCI_ROM_IMAGE_SIGNATURE) { pci_info(pdev, "No more image in the PCI ROM\n"); break; } -- 2.43.0