From 05976c7e93ea64031f6bb3b1eee8120234d7202e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20V=C3=A1zquez=20Blanco?= Date: Sat, 19 Jul 2025 20:31:53 +0200 Subject: [PATCH] pcidev.h: Extract pcidev declarations to a separate header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch moves all the declarations relevant to PCI into their own header in include/pcidev.h This is a simple refactor that aims to simplify maintenance and to clarify file dependency inside the project. Currently, most of the declarations reside in programmer.h making it difficult to really understand file dependency. Change-Id: Ie7cefa012d43e03d2d3886f1567ad9b3fe1b148c Signed-off-by: Antonio Vázquez Blanco Reviewed-on: https://review.coreboot.org/c/flashrom/+/89094 Reviewed-by: Anastasia Klimchuk Tested-by: build bot (Jenkins) --- asm106x.c | 1 + atahpt.c | 2 +- atapromise.c | 2 +- atavia.c | 2 +- board_enable.c | 2 +- chipset_enable.c | 2 +- drkaiser.c | 2 +- gfxnvidia.c | 2 +- include/pcidev.h | 47 ++++++++++++++++++++++++++++++++++++++++++++ include/programmer.h | 26 +----------------------- internal.c | 2 +- it8212.c | 2 +- mcp6x_spi.c | 2 +- nic3com.c | 2 +- nicintel.c | 2 +- nicintel_eeprom.c | 1 + nicintel_spi.c | 2 +- nicnatsemi.c | 2 +- nicrealtek.c | 2 +- ogp_spi.c | 2 +- pcidev.c | 4 +++- satamv.c | 2 +- satasii.c | 2 +- sb600spi.c | 2 +- 24 files changed, 72 insertions(+), 45 deletions(-) create mode 100644 include/pcidev.h diff --git a/asm106x.c b/asm106x.c index 22a4942c7..cacbec3c7 100644 --- a/asm106x.c +++ b/asm106x.c @@ -18,6 +18,7 @@ #include "programmer.h" #include "platform/pci.h" #include "platform/udelay.h" +#include "pcidev.h" #define PCI_VENDOR_ID_ASMEDIA 0x1b21 diff --git a/atahpt.c b/atahpt.c index 71fd4d5b5..3a0ff92a4 100644 --- a/atahpt.c +++ b/atahpt.c @@ -19,7 +19,7 @@ #include "flash.h" #include "programmer.h" #include "hwaccess_x86_io.h" -#include "platform/pci.h" +#include "pcidev.h" #define BIOS_ROM_ADDR 0x90 #define BIOS_ROM_DATA 0x94 diff --git a/atapromise.c b/atapromise.c index 9beebf142..25c1072af 100644 --- a/atapromise.c +++ b/atapromise.c @@ -20,7 +20,7 @@ #include "programmer.h" #include "hwaccess_x86_io.h" #include "hwaccess_physmap.h" -#include "platform/pci.h" +#include "pcidev.h" #define MAX_ROM_DECODE (32 * 1024) #define ADDR_MASK (MAX_ROM_DECODE - 1) diff --git a/atavia.c b/atavia.c index ab63f2c89..0ce4901a8 100644 --- a/atavia.c +++ b/atavia.c @@ -20,8 +20,8 @@ #include #include "flash.h" #include "programmer.h" -#include "platform/pci.h" #include "platform/udelay.h" +#include "pcidev.h" #define PCI_VENDOR_ID_VIA 0x1106 diff --git a/board_enable.c b/board_enable.c index 6e48a6263..849f6b3e7 100644 --- a/board_enable.c +++ b/board_enable.c @@ -26,7 +26,7 @@ #include #include "flash.h" #include "programmer.h" -#include "platform/pci.h" +#include "pcidev.h" #if defined(__i386__) || defined(__x86_64__) diff --git a/chipset_enable.c b/chipset_enable.c index d9a275e85..e8f0ba119 100644 --- a/chipset_enable.c +++ b/chipset_enable.c @@ -33,7 +33,7 @@ #include "flash.h" #include "programmer.h" #include "hwaccess_physmap.h" -#include "platform/pci.h" +#include "pcidev.h" #define NOT_DONE_YET 1 diff --git a/drkaiser.c b/drkaiser.c index ebf511915..d8f333d9b 100644 --- a/drkaiser.c +++ b/drkaiser.c @@ -18,7 +18,7 @@ #include "flash.h" #include "programmer.h" #include "hwaccess_physmap.h" -#include "platform/pci.h" +#include "pcidev.h" #define PCI_VENDOR_ID_DRKAISER 0x1803 diff --git a/gfxnvidia.c b/gfxnvidia.c index 080c88546..ef43ae8ac 100644 --- a/gfxnvidia.c +++ b/gfxnvidia.c @@ -20,7 +20,7 @@ #include "flash.h" #include "programmer.h" #include "hwaccess_physmap.h" -#include "platform/pci.h" +#include "pcidev.h" #define PCI_VENDOR_ID_NVIDIA 0x10de diff --git a/include/pcidev.h b/include/pcidev.h new file mode 100644 index 000000000..8fa32347c --- /dev/null +++ b/include/pcidev.h @@ -0,0 +1,47 @@ +/* + * This file is part of the flashrom project. + * + * Copyright (C) 2025 Antonio Vázquez Blanco + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __PCIDEV_H__ +#define __PCIDEV_H__ + +#include "platform/pci.h" +#include "programmer.h" + +// FIXME: This needs to be local, not global(?) +extern struct pci_access *pacc; + +int pci_init_common(void); +uintptr_t pcidev_readbar(struct pci_dev *dev, int bar); +struct pci_dev *pcidev_init(const struct programmer_cfg *cfg, const struct dev_entry *devs, int bar); +struct pci_dev *pcidev_scandev(struct pci_filter *filter, struct pci_dev *start); +struct pci_dev *pcidev_getdevfn(struct pci_dev *dev, const int func); +struct pci_dev *pcidev_find_vendorclass(uint16_t vendor, uint16_t devclass); +struct pci_dev *pcidev_card_find(uint16_t vendor, uint16_t device, uint16_t card_vendor, uint16_t card_device); +struct pci_dev *pcidev_find(uint16_t vendor, uint16_t device); + +/* rpci_write_* are reversible writes. The original PCI config space register + * contents will be restored on shutdown. + * To clone the pci_dev instances internally, the `pacc` global + * variable has to reference a pci_access method that is compatible + * with the given pci_dev handle. The referenced pci_access (not + * the variable) has to stay valid until the shutdown handlers are + * finished. + */ +int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data); +int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data); +int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data); + +#endif diff --git a/include/programmer.h b/include/programmer.h index f7d2c4bd9..5951f6dce 100644 --- a/include/programmer.h +++ b/include/programmer.h @@ -120,33 +120,9 @@ struct bitbang_spi_master { unsigned int half_period; }; -struct pci_dev; -struct pci_filter; - -/* pcidev.c */ -// FIXME: This needs to be local, not global(?) -extern struct pci_access *pacc; -int pci_init_common(void); -uintptr_t pcidev_readbar(struct pci_dev *dev, int bar); -struct pci_dev *pcidev_init(const struct programmer_cfg *cfg, const struct dev_entry *devs, int bar); -struct pci_dev *pcidev_scandev(struct pci_filter *filter, struct pci_dev *start); -struct pci_dev *pcidev_getdevfn(struct pci_dev *dev, const int func); -struct pci_dev *pcidev_find_vendorclass(uint16_t vendor, uint16_t devclass); -struct pci_dev *pcidev_card_find(uint16_t vendor, uint16_t device, uint16_t card_vendor, uint16_t card_device); -struct pci_dev *pcidev_find(uint16_t vendor, uint16_t device); -/* rpci_write_* are reversible writes. The original PCI config space register - * contents will be restored on shutdown. - * To clone the pci_dev instances internally, the `pacc` global - * variable has to reference a pci_access method that is compatible - * with the given pci_dev handle. The referenced pci_access (not - * the variable) has to stay valid until the shutdown handlers are - * finished. - */ -int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data); -int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data); -int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data); #if CONFIG_INTERNAL == 1 +struct pci_dev; struct penable { uint16_t vendor_id; uint16_t device_id; diff --git a/internal.c b/internal.c index 1753c4450..6b1f018fb 100644 --- a/internal.c +++ b/internal.c @@ -21,7 +21,7 @@ #include "flash.h" #include "programmer.h" -#include "platform/pci.h" +#include "pcidev.h" #if defined(__i386__) || defined(__x86_64__) #include "hwaccess_x86_io.h" diff --git a/it8212.c b/it8212.c index 3c1161d60..bf04276e1 100644 --- a/it8212.c +++ b/it8212.c @@ -18,7 +18,7 @@ #include "flash.h" #include "programmer.h" #include "hwaccess_physmap.h" -#include "platform/pci.h" +#include "pcidev.h" struct it8212_data { struct pci_dev *dev; diff --git a/mcp6x_spi.c b/mcp6x_spi.c index 165bca50f..79c90632b 100644 --- a/mcp6x_spi.c +++ b/mcp6x_spi.c @@ -24,7 +24,7 @@ #include "flash.h" #include "programmer.h" #include "hwaccess_physmap.h" -#include "platform/pci.h" +#include "pcidev.h" /* Bit positions for each pin. */ diff --git a/nic3com.c b/nic3com.c index a578d4853..40cf9eaf1 100644 --- a/nic3com.c +++ b/nic3com.c @@ -18,7 +18,7 @@ #include "flash.h" #include "programmer.h" #include "hwaccess_x86_io.h" -#include "platform/pci.h" +#include "pcidev.h" #define BIOS_ROM_ADDR 0x04 #define BIOS_ROM_DATA 0x08 diff --git a/nicintel.c b/nicintel.c index feb07b663..aafb7e3f4 100644 --- a/nicintel.c +++ b/nicintel.c @@ -19,7 +19,7 @@ #include "flash.h" #include "programmer.h" #include "hwaccess_physmap.h" -#include "platform/pci.h" +#include "pcidev.h" struct nicintel_data { uint8_t *nicintel_bar; diff --git a/nicintel_eeprom.c b/nicintel_eeprom.c index 50e20e2db..8c39dff5d 100644 --- a/nicintel_eeprom.c +++ b/nicintel_eeprom.c @@ -36,6 +36,7 @@ #include "hwaccess_physmap.h" #include "platform/pci.h" #include "platform/udelay.h" +#include "pcidev.h" #define PCI_VENDOR_ID_INTEL 0x8086 #define MEMMAP_SIZE 0x1c /* Only EEC, EERD and EEWR are needed. */ diff --git a/nicintel_spi.c b/nicintel_spi.c index 2821d23a0..e3cdfb931 100644 --- a/nicintel_spi.c +++ b/nicintel_spi.c @@ -35,7 +35,7 @@ #include "flash.h" #include "programmer.h" #include "hwaccess_physmap.h" -#include "platform/pci.h" +#include "pcidev.h" #define PCI_VENDOR_ID_INTEL 0x8086 #define MEMMAP_SIZE getpagesize() diff --git a/nicnatsemi.c b/nicnatsemi.c index 65377dc6f..0da3c58d6 100644 --- a/nicnatsemi.c +++ b/nicnatsemi.c @@ -18,7 +18,7 @@ #include "flash.h" #include "programmer.h" #include "hwaccess_x86_io.h" -#include "platform/pci.h" +#include "pcidev.h" #define PCI_VENDOR_ID_NATSEMI 0x100b diff --git a/nicrealtek.c b/nicrealtek.c index 5937e35ba..5072ce5b0 100644 --- a/nicrealtek.c +++ b/nicrealtek.c @@ -18,7 +18,7 @@ #include "flash.h" #include "programmer.h" #include "hwaccess_x86_io.h" -#include "platform/pci.h" +#include "pcidev.h" #define PCI_VENDOR_ID_REALTEK 0x10ec #define PCI_VENDOR_ID_SMC1211 0x1113 diff --git a/ogp_spi.c b/ogp_spi.c index d85c82306..5c0c10d3e 100644 --- a/ogp_spi.c +++ b/ogp_spi.c @@ -19,7 +19,7 @@ #include "flash.h" #include "programmer.h" #include "hwaccess_physmap.h" -#include "platform/pci.h" +#include "pcidev.h" #define PCI_VENDOR_ID_OGP 0x1227 diff --git a/pcidev.c b/pcidev.c index 696510edc..43c7a596a 100644 --- a/pcidev.c +++ b/pcidev.c @@ -15,11 +15,13 @@ * GNU General Public License for more details. */ +#include "pcidev.h" + #include #include + #include "flash.h" #include "programmer.h" -#include "platform/pci.h" struct pci_access *pacc; diff --git a/satamv.c b/satamv.c index 1b8640a84..9adb35860 100644 --- a/satamv.c +++ b/satamv.c @@ -21,7 +21,7 @@ #include "programmer.h" #include "hwaccess_x86_io.h" #include "hwaccess_physmap.h" -#include "platform/pci.h" +#include "pcidev.h" struct satamv_data { uint8_t *bar; diff --git a/satasii.c b/satasii.c index ad872bfc9..414b6a686 100644 --- a/satasii.c +++ b/satasii.c @@ -19,7 +19,7 @@ #include #include "programmer.h" #include "hwaccess_physmap.h" -#include "platform/pci.h" +#include "pcidev.h" #define PCI_VENDOR_ID_SII 0x1095 diff --git a/sb600spi.c b/sb600spi.c index 37e45f108..3701d10b0 100644 --- a/sb600spi.c +++ b/sb600spi.c @@ -24,7 +24,7 @@ #include "programmer.h" #include "hwaccess_physmap.h" #include "spi.h" -#include "platform/pci.h" +#include "pcidev.h" /* This struct is unused, but helps visualize the SB600 SPI BAR layout. *struct sb600_spi_controller {