iPXE
Functions
pciea.c File Reference

PCI Enhanced Allocation. More...

#include <stdint.h>
#include <errno.h>
#include <ipxe/pci.h>
#include <ipxe/pciea.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int pciea_offset (struct pci_device *pci, unsigned int bei)
 Locate PCI Enhanced Allocation BAR equivalent entry. More...
 
static unsigned long pciea_bar_value (struct pci_device *pci, unsigned int bei, unsigned int low_offset)
 Read PCI Enhanced Allocation BAR equivalent value. More...
 
unsigned long pciea_bar_start (struct pci_device *pci, unsigned int bei)
 Find the start of a PCI Enhanced Allocation BAR equivalent. More...
 
unsigned long pciea_bar_size (struct pci_device *pci, unsigned int bei)
 Find the size of a PCI Enhanced Allocation BAR equivalent. More...
 

Detailed Description

PCI Enhanced Allocation.

Definition in file pciea.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ pciea_offset()

static int pciea_offset ( struct pci_device pci,
unsigned int  bei 
)
static

Locate PCI Enhanced Allocation BAR equivalent entry.

Parameters
pciPCI device
beiBAR equivalent indicator
Return values
offsetPCI Enhanced Allocation entry offset, or negative error

Definition at line 44 of file pciea.c.

44  {
45  uint8_t entries;
46  uint32_t desc;
47  unsigned int i;
48  int offset;
49 
50  /* Locate Enhanced Allocation capability */
52  if ( offset < 0 )
53  return offset;
54 
55  /* Get number of entries */
56  pci_read_config_byte ( pci, ( offset + PCIEA_ENTRIES ), &entries );
57  entries &= PCIEA_ENTRIES_MASK;
58 
59  /* Locate first entry */
61 
62  /* Search for a matching entry */
63  for ( i = 0 ; i < entries ; i++ ) {
64 
65  /* Read entry descriptor */
66  pci_read_config_dword ( pci, offset, &desc );
67 
68  /* Check for a matching entry */
69  if ( ( desc & PCIEA_DESC_ENABLED ) &&
70  ( bei == PCIEA_DESC_BEI ( desc ) ) )
71  return offset;
72 
73  /* Move to next entry */
74  offset += ( ( PCIEA_DESC_SIZE ( desc ) + 1 ) << 2 );
75  }
76 
77  return -ENOENT;
78 }
int pci_find_capability(struct pci_device *pci, int cap)
Look for a PCI capability.
Definition: pciextra.c:36
#define PCIEA_DESC_BEI(desc)
BAR equivalent indicator.
Definition: pciea.h:28
#define ENOENT
No such file or directory.
Definition: errno.h:514
#define PCIEA_ENTRIES_MASK
Definition: pciea.h:16
#define PCIEA_FIRST
First entry.
Definition: pciea.h:19
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
#define PCIEA_ENTRIES
Number of entries.
Definition: pciea.h:15
#define PCI_CAP_ID_EA
Enhanced Allocation.
Definition: pci.h:98
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
#define PCIEA_DESC_ENABLED
Entry is enabled.
Definition: pciea.h:48
#define PCIEA_DESC_SIZE(desc)
Entry size.
Definition: pciea.h:25
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.

References ENOENT, offset, PCI_CAP_ID_EA, pci_find_capability(), pci_read_config_byte(), pci_read_config_dword(), PCIEA_DESC_BEI, PCIEA_DESC_ENABLED, PCIEA_DESC_SIZE, PCIEA_ENTRIES, PCIEA_ENTRIES_MASK, and PCIEA_FIRST.

Referenced by pciea_bar_value().

◆ pciea_bar_value()

static unsigned long pciea_bar_value ( struct pci_device pci,
unsigned int  bei,
unsigned int  low_offset 
)
static

Read PCI Enhanced Allocation BAR equivalent value.

Parameters
pciPCI device
beiBAR equivalent indicator
low_offsetOffset to low dword of value
Return values
valueBAR equivalent value

Definition at line 88 of file pciea.c.

89  {
90  uint32_t low;
91  uint32_t high;
92  int offset;
93 
94  /* Locate Enhanced Allocation offset for this BEI */
95  offset = pciea_offset ( pci, bei );
96  if ( offset < 0 )
97  return 0;
98 
99  /* Read BAR equivalent */
100  offset += low_offset;
101  pci_read_config_dword ( pci, offset, &low );
102  if ( low & PCIEA_LOW_ATTR_64BIT ) {
104  pci_read_config_dword ( pci, offset, &high );
105  if ( high ) {
106  if ( sizeof ( unsigned long ) > sizeof ( uint32_t ) ) {
107  return ( ( ( uint64_t ) high << 32 ) | low );
108  } else {
109  DBGC ( pci, PCI_FMT " unhandled 64-bit EA BAR "
110  "%08x%08x\n",
111  PCI_ARGS ( pci ), high, low );
112  return 0;
113  }
114  }
115  }
116  return low;
117 }
#define PCIEA_LOW_HIGH
Offset to high dwords.
Definition: pciea.h:63
#define DBGC(...)
Definition: compiler.h:505
unsigned long long uint64_t
Definition: stdint.h:13
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
uint32_t low
Low 16 bits of address.
Definition: intel.h:21
static int pciea_offset(struct pci_device *pci, unsigned int bei)
Locate PCI Enhanced Allocation BAR equivalent entry.
Definition: pciea.c:44
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:287
unsigned int uint32_t
Definition: stdint.h:12
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:290
#define PCIEA_LOW_ATTR_64BIT
BAR is 64-bit.
Definition: pciea.h:57
uint32_t high
High 32 bits of address.
Definition: intel.h:22

References DBGC, high, low, offset, PCI_ARGS, PCI_FMT, pci_read_config_dword(), PCIEA_LOW_ATTR_64BIT, PCIEA_LOW_HIGH, and pciea_offset().

Referenced by pciea_bar_size(), and pciea_bar_start().

◆ pciea_bar_start()

unsigned long pciea_bar_start ( struct pci_device pci,
unsigned int  bei 
)

Find the start of a PCI Enhanced Allocation BAR equivalent.

Parameters
pciPCI device
beiBAR equivalent indicator
Return values
startBAR start address

If the address exceeds the size of an unsigned long (i.e. if a 64-bit BAR has a non-zero high dword on a 32-bit machine), the return value will be zero.

Definition at line 130 of file pciea.c.

130  {
131  unsigned long base;
132 
133  base = pciea_bar_value ( pci, bei, PCIEA_LOW_BASE );
134  return ( base & ~PCIEA_LOW_ATTR_MASK );
135 }
#define PCIEA_LOW_BASE
Base address low dword.
Definition: pciea.h:51
#define PCIEA_LOW_ATTR_MASK
Low dword attribute bit mask.
Definition: pciea.h:60
static unsigned long pciea_bar_value(struct pci_device *pci, unsigned int bei, unsigned int low_offset)
Read PCI Enhanced Allocation BAR equivalent value.
Definition: pciea.c:88
uint16_t base
Base address.
Definition: edd.h:14

References base, pciea_bar_value(), PCIEA_LOW_ATTR_MASK, and PCIEA_LOW_BASE.

Referenced by txnic_bgx_probe(), and txnic_pf_probe().

◆ pciea_bar_size()

unsigned long pciea_bar_size ( struct pci_device pci,
unsigned int  bei 
)

Find the size of a PCI Enhanced Allocation BAR equivalent.

Parameters
pciPCI device
beiBAR equivalent indicator
Return values
sizeBAR size

Definition at line 144 of file pciea.c.

144  {
145  unsigned long limit;
146 
147  limit = pciea_bar_value ( pci, bei, PCIEA_LOW_LIMIT );
148  return ( limit ? ( ( limit | PCIEA_LOW_ATTR_MASK ) + 1 ) : 0 );
149 }
#define PCIEA_LOW_ATTR_MASK
Low dword attribute bit mask.
Definition: pciea.h:60
static unsigned long pciea_bar_value(struct pci_device *pci, unsigned int bei, unsigned int low_offset)
Read PCI Enhanced Allocation BAR equivalent value.
Definition: pciea.c:88
uint16_t limit
Limit.
Definition: librm.h:250
#define PCIEA_LOW_LIMIT
Limit low dword.
Definition: pciea.h:54

References limit, pciea_bar_value(), PCIEA_LOW_ATTR_MASK, and PCIEA_LOW_LIMIT.

Referenced by txnic_pf_probe().