Skip to content

Commit 2a8d402

Browse files
palitrini
authored andcommitted
pci: Add standard PCI Config Address macros
Lot of PCI and PCIe controllers are using standard Config Address for PCI Configuration Mechanism #1 or its extended version. So add PCI_CONF1_ADDRESS() and PCI_CONF1_EXT_ADDRESS() macros into U-Boot's pci.h header file which can be suitable for most PCI and PCIe controller drivers. Drivers do not have to invent their own macros and can use these new U-Boot macros. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Simon Glass <sjg@chromium.org>
1 parent 95ab578 commit 2a8d402

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

include/pci.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,51 @@
522522

523523
#include <pci_ids.h>
524524

525+
/*
526+
* Config Address for PCI Configuration Mechanism #1
527+
*
528+
* See PCI Local Bus Specification, Revision 3.0,
529+
* Section 3.2.2.3.2, Figure 3-2, p. 50.
530+
*/
531+
532+
#define PCI_CONF1_BUS_SHIFT 16 /* Bus number */
533+
#define PCI_CONF1_DEV_SHIFT 11 /* Device number */
534+
#define PCI_CONF1_FUNC_SHIFT 8 /* Function number */
535+
536+
#define PCI_CONF1_BUS_MASK 0xff
537+
#define PCI_CONF1_DEV_MASK 0x1f
538+
#define PCI_CONF1_FUNC_MASK 0x7
539+
#define PCI_CONF1_REG_MASK 0xfc /* Limit aligned offset to a maximum of 256B */
540+
541+
#define PCI_CONF1_ENABLE BIT(31)
542+
#define PCI_CONF1_BUS(x) (((x) & PCI_CONF1_BUS_MASK) << PCI_CONF1_BUS_SHIFT)
543+
#define PCI_CONF1_DEV(x) (((x) & PCI_CONF1_DEV_MASK) << PCI_CONF1_DEV_SHIFT)
544+
#define PCI_CONF1_FUNC(x) (((x) & PCI_CONF1_FUNC_MASK) << PCI_CONF1_FUNC_SHIFT)
545+
#define PCI_CONF1_REG(x) ((x) & PCI_CONF1_REG_MASK)
546+
547+
#define PCI_CONF1_ADDRESS(bus, dev, func, reg) \
548+
(PCI_CONF1_ENABLE | \
549+
PCI_CONF1_BUS(bus) | \
550+
PCI_CONF1_DEV(dev) | \
551+
PCI_CONF1_FUNC(func) | \
552+
PCI_CONF1_REG(reg))
553+
554+
/*
555+
* Extension of PCI Config Address for accessing extended PCIe registers
556+
*
557+
* No standardized specification, but used on lot of non-ECAM-compliant ARM SoCs
558+
* or on AMD Barcelona and new CPUs. Reserved bits [27:24] of PCI Config Address
559+
* are used for specifying additional 4 high bits of PCI Express register.
560+
*/
561+
562+
#define PCI_CONF1_EXT_REG_SHIFT 16
563+
#define PCI_CONF1_EXT_REG_MASK 0xf00
564+
#define PCI_CONF1_EXT_REG(x) (((x) & PCI_CONF1_EXT_REG_MASK) << PCI_CONF1_EXT_REG_SHIFT)
565+
566+
#define PCI_CONF1_EXT_ADDRESS(bus, dev, func, reg) \
567+
(PCI_CONF1_ADDRESS(bus, dev, func, reg) | \
568+
PCI_CONF1_EXT_REG(reg))
569+
525570
/*
526571
* Enhanced Configuration Access Mechanism (ECAM)
527572
*

0 commit comments

Comments
 (0)