[coreboot] New patch to review for coreboot: 2285d39 coreboot: Add utility to modify PCI register bitwise

Alexandru Gagniuc (mr.nuke.me@gmail.com) gerrit at coreboot.org
Thu Jul 12 02:00:50 CEST 2012


Alexandru Gagniuc (mr.nuke.me at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/1218

-gerrit

commit 2285d392e1ca544eb839d73ed98287aab42a3f40
Author: Alexandru Gagniuc <mr.nuke.me at gmail.com>
Date:   Wed Jul 11 18:41:04 2012 -0500

    coreboot: Add utility to modify PCI register bitwise
    
    Up until now, if we wanted to modify only a few bits from a PCI register,
    we'd have to do:
    
    u8 reg = pci_read_config8(dev, where);
    reg &= ~ clr_bits;
    reg |= set_bits;
    pci_write_config8(dev, where, reg);
    
    Add pci_mod_config[8,16,32] utility to simplify this process.
    The above example is simplified to a single line using:
    
    pci_mod_config8(dev, where, clr_bits, set_bits);
    
    Change-Id: I2cef2d028895d3408f152d3a18348fba3166047b
    Signed-off-by: Alexandru Gagniuc <mr.nuke.me at gmail.com>
---
 src/arch/x86/include/arch/romcc_io.h |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/src/arch/x86/include/arch/romcc_io.h b/src/arch/x86/include/arch/romcc_io.h
index 37fb7ab..8876b28 100644
--- a/src/arch/x86/include/arch/romcc_io.h
+++ b/src/arch/x86/include/arch/romcc_io.h
@@ -244,6 +244,34 @@ static inline __attribute__((always_inline)) void pci_write_config32(device_t de
 #endif
 }
 
+static inline __attribute__((always_inline))
+void pci_mod_config8(device_t dev, unsigned int where,
+		     uint8_t clr_mask, uint8_t set_mask)
+{
+	uint8_t reg8 = pci_read_config8(dev, where);
+	reg8 &= ~clr_mask;
+	reg8 |= set_mask;
+	pci_write_config8(dev, where, reg8);
+}
+static inline __attribute__((always_inline))
+void pci_mod_config16(device_t dev, unsigned int where,
+		      uint16_t clr_mask, uint16_t set_mask)
+{
+	uint16_t reg16 = pci_read_config16(dev, where);
+	reg16 &= ~clr_mask;
+	reg16 |= set_mask;
+	pci_write_config16(dev, where, reg16);
+}
+static inline __attribute__((always_inline))
+void pci_mod_config32(device_t dev, unsigned int where,
+		      uint32_t clr_mask, uint32_t set_mask)
+{
+	uint32_t reg32 = pci_read_config32(dev, where);
+	reg32 &= ~clr_mask;
+	reg32 |= set_mask;
+	pci_write_config32(dev, where, reg32);
+}
+
 #define PCI_DEV_INVALID (0xffffffffU)
 static inline device_t pci_io_locate_device(unsigned pci_id, device_t dev)
 {




More information about the coreboot mailing list