iPXE
Functions | Variables
pcicloud.c File Reference

Cloud VM PCI configuration space access. More...

#include <stdint.h>
#include <string.h>
#include <ipxe/pci.h>
#include <ipxe/pcicloud.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static struct pci_apipcicloud_find (uint32_t busdevfn, struct pci_range *range)
 Find PCI configuration space access API for address. More...
 
static void pcicloud_discover (uint32_t busdevfn, struct pci_range *range)
 Find next PCI bus:dev.fn address range in system. More...
 
static struct pci_apipcicloud_api (struct pci_device *pci)
 Find configuration space access API for PCI device. More...
 
static int pcicloud_can_probe (struct pci_device *pci)
 Check if PCI bus probing is allowed. More...
 
static int pcicloud_read_config_byte (struct pci_device *pci, unsigned int where, uint8_t *value)
 Read byte from PCI configuration space. More...
 
static int pcicloud_read_config_word (struct pci_device *pci, unsigned int where, uint16_t *value)
 Read 16-bit word from PCI configuration space. More...
 
static int pcicloud_read_config_dword (struct pci_device *pci, unsigned int where, uint32_t *value)
 Read 32-bit dword from PCI configuration space. More...
 
static int pcicloud_write_config_byte (struct pci_device *pci, unsigned int where, uint8_t value)
 Write byte to PCI configuration space. More...
 
static int pcicloud_write_config_word (struct pci_device *pci, unsigned int where, uint16_t value)
 Write 16-bit word to PCI configuration space. More...
 
static int pcicloud_write_config_dword (struct pci_device *pci, unsigned int where, uint32_t value)
 Write 32-bit dword to PCI configuration space. More...
 
static void * pcicloud_ioremap (struct pci_device *pci, unsigned long bus_addr, size_t len)
 Map PCI bus address as an I/O address. More...
 
 PROVIDE_PCIAPI (cloud, pci_can_probe, pcicloud_can_probe)
 
 PROVIDE_PCIAPI (cloud, pci_discover, pcicloud_discover)
 
 PROVIDE_PCIAPI (cloud, pci_read_config_byte, pcicloud_read_config_byte)
 
 PROVIDE_PCIAPI (cloud, pci_read_config_word, pcicloud_read_config_word)
 
 PROVIDE_PCIAPI (cloud, pci_read_config_dword, pcicloud_read_config_dword)
 
 PROVIDE_PCIAPI (cloud, pci_write_config_byte, pcicloud_write_config_byte)
 
 PROVIDE_PCIAPI (cloud, pci_write_config_word, pcicloud_write_config_word)
 
 PROVIDE_PCIAPI (cloud, pci_write_config_dword, pcicloud_write_config_dword)
 
 PROVIDE_PCIAPI (cloud, pci_ioremap, pcicloud_ioremap)
 

Variables

struct {
   struct pci_range   range
 PCI bus:dev.fn address range. More...
 
   struct pci_api *   api
 API for this bus:dev.fn address. More...
 
pcicloud
 Cached PCI configuration space access API. More...
 

Detailed Description

Cloud VM PCI configuration space access.

Definition in file pcicloud.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ pcicloud_find()

static struct pci_api* pcicloud_find ( uint32_t  busdevfn,
struct pci_range range 
)
static

Find PCI configuration space access API for address.

Parameters
busdevfnStarting PCI bus:dev.fn address
rangePCI bus:dev.fn address range to fill in
Return values
apiConfiguration space access API, or NULL

Definition at line 52 of file pcicloud.c.

53  {
54  struct pci_range candidate;
55  struct pci_api *api;
56  uint32_t best = 0;
59  uint32_t last;
60 
61  /* Return empty range on error */
62  range->count = 0;
63 
64  /* Try discovery via all known APIs */
66 
67  /* Discover via this API */
68  api->pci_discover ( busdevfn, &candidate );
69 
70  /* Check for a matching or new closest allocation */
71  index = ( busdevfn - candidate.start );
72  if ( ( index < candidate.count ) || ( index > best ) ) {
73  memcpy ( range, &candidate, sizeof ( *range ) );
74  best = index;
75  }
76 
77  /* Stop if this range contains the target bus:dev.fn address */
78  if ( index < candidate.count ) {
79  first = range->start;
80  last = ( range->start + range->count - 1 );
81  DBGC ( &pcicloud, "PCICLOUD [" PCI_FMT "," PCI_FMT ") "
82  "using %s API\n", PCI_SEG ( first ),
83  PCI_BUS ( first ), PCI_SLOT ( first ),
84  PCI_FUNC ( first ), PCI_SEG ( last ),
85  PCI_BUS ( last ), PCI_SLOT ( last ),
86  PCI_FUNC ( last ), api->name );
87  return api;
88  }
89  }
90 
91  return NULL;
92 }
#define PCI_FUNC(busdevfn)
Definition: pci.h:285
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:24
#define PCI_BUS(busdevfn)
Definition: pci.h:283
typeof() pci_discover * pci_discover
Definition: pci_io.h:168
struct pci_range range
PCI bus:dev.fn address range.
Definition: pcicloud.c:40
uint32_t first
First block in range.
Definition: pccrr.h:14
struct pci_api * api
API for this bus:dev.fn address.
Definition: pcicloud.c:42
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:62
#define PCI_APIS
Runtime selectable PCI API table.
Definition: pci_io.h:179
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
void * memcpy(void *dest, const void *src, size_t len) __nonnull
const char * name
Definition: pci_io.h:166
A PCI bus:dev.fn address range.
Definition: pci_io.h:22
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:311
#define PCI_SLOT(busdevfn)
Definition: pci.h:284
A runtime selectable PCI I/O API.
Definition: pci_io.h:165
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
unsigned int uint32_t
Definition: stdint.h:12
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:26
#define PCI_SEG(busdevfn)
Definition: pci.h:282
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static struct @8 pcicloud
Cached PCI configuration space access API.

References api, busdevfn, pci_range::count, DBGC, first, for_each_table_entry, index, memcpy(), pci_api::name, NULL, PCI_APIS, PCI_BUS, pci_api::pci_discover, PCI_FMT, PCI_FUNC, PCI_SEG, PCI_SLOT, pcicloud, range, and pci_range::start.

Referenced by pcicloud_api(), and pcicloud_discover().

◆ pcicloud_discover()

static void pcicloud_discover ( uint32_t  busdevfn,
struct pci_range range 
)
static

Find next PCI bus:dev.fn address range in system.

Parameters
busdevfnStarting PCI bus:dev.fn address
rangePCI bus:dev.fn address range to fill in

Definition at line 100 of file pcicloud.c.

100  {
101 
102  /* Find new range, if any */
104 }
struct pci_range range
PCI bus:dev.fn address range.
Definition: pcicloud.c:40
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
static struct pci_api * pcicloud_find(uint32_t busdevfn, struct pci_range *range)
Find PCI configuration space access API for address.
Definition: pcicloud.c:52

References busdevfn, pcicloud_find(), and range.

◆ pcicloud_api()

static struct pci_api* pcicloud_api ( struct pci_device pci)
static

Find configuration space access API for PCI device.

Parameters
pciPCI device
Return values
apiConfiguration space access API

Definition at line 112 of file pcicloud.c.

112  {
113  struct pci_range *range = &pcicloud.range;
114  struct pci_api *api;
115  uint32_t first;
116  uint32_t last;
117 
118  /* Reuse cached API if applicable */
119  if ( ( pci->busdevfn - range->start ) < range->count )
120  return pcicloud.api;
121 
122  /* Find highest priority API claiming this range */
123  api = pcicloud_find ( pci->busdevfn, range );
124 
125  /* Fall back to lowest priority API for any unclaimed gaps in ranges */
126  if ( ! api ) {
127  api = ( table_end ( PCI_APIS ) - 1 );
128  range->count = ( range->start - pci->busdevfn );
129  range->start = pci->busdevfn;
130  first = range->start;
131  last = ( range->start + range->count - 1 );
132  DBGC ( &pcicloud, "PCICLOUD [" PCI_FMT "," PCI_FMT ") falling "
133  "back to %s API\n", PCI_SEG ( first ),
134  PCI_BUS ( first ), PCI_SLOT ( first ),
135  PCI_FUNC ( first ), PCI_SEG ( last ), PCI_BUS ( last ),
136  PCI_SLOT ( last ), PCI_FUNC ( last ), api->name );
137  }
138 
139  /* Cache API for this range */
140  pcicloud.api = api;
141 
142  return api;
143 }
#define PCI_FUNC(busdevfn)
Definition: pci.h:285
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:24
#define PCI_BUS(busdevfn)
Definition: pci.h:283
struct pci_range range
PCI bus:dev.fn address range.
Definition: pcicloud.c:40
uint32_t first
First block in range.
Definition: pccrr.h:14
struct pci_api * api
API for this bus:dev.fn address.
Definition: pcicloud.c:42
#define DBGC(...)
Definition: compiler.h:505
#define PCI_APIS
Runtime selectable PCI API table.
Definition: pci_io.h:179
const char * name
Definition: pci_io.h:166
A PCI bus:dev.fn address range.
Definition: pci_io.h:22
static struct pci_api * pcicloud_find(uint32_t busdevfn, struct pci_range *range)
Find PCI configuration space access API for address.
Definition: pcicloud.c:52
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:311
#define PCI_SLOT(busdevfn)
Definition: pci.h:284
A runtime selectable PCI I/O API.
Definition: pci_io.h:165
unsigned int uint32_t
Definition: stdint.h:12
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:26
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:237
#define table_end(table)
Get end of linker table.
Definition: tables.h:308
#define PCI_SEG(busdevfn)
Definition: pci.h:282
static struct @8 pcicloud
Cached PCI configuration space access API.

References api, pci_device::busdevfn, pci_range::count, DBGC, first, pci_api::name, PCI_APIS, PCI_BUS, PCI_FMT, PCI_FUNC, PCI_SEG, PCI_SLOT, pcicloud, pcicloud_find(), range, pci_range::start, and table_end.

Referenced by pcicloud_can_probe(), pcicloud_ioremap(), pcicloud_read_config_byte(), pcicloud_read_config_dword(), pcicloud_read_config_word(), pcicloud_write_config_byte(), pcicloud_write_config_dword(), and pcicloud_write_config_word().

◆ pcicloud_can_probe()

static int pcicloud_can_probe ( struct pci_device pci)
static

Check if PCI bus probing is allowed.

Parameters
pciPCI device
Return values
okBus probing is allowed

Definition at line 151 of file pcicloud.c.

151  {
152  struct pci_api *api = pcicloud_api ( pci );
153 
154  return api->pci_can_probe ( pci );
155 }
static struct pci_api * pcicloud_api(struct pci_device *pci)
Find configuration space access API for PCI device.
Definition: pcicloud.c:112
struct pci_api * api
API for this bus:dev.fn address.
Definition: pcicloud.c:42
typeof() pci_can_probe * pci_can_probe
Definition: pci_io.h:167
A runtime selectable PCI I/O API.
Definition: pci_io.h:165

References api, pci_api::pci_can_probe, and pcicloud_api().

◆ pcicloud_read_config_byte()

static int pcicloud_read_config_byte ( struct pci_device pci,
unsigned int  where,
uint8_t value 
)
static

Read byte from PCI configuration space.

Parameters
pciPCI device
whereLocation within PCI configuration space
valueValue read
Return values
rcReturn status code

Definition at line 165 of file pcicloud.c.

166  {
167  struct pci_api *api = pcicloud_api ( pci );
168 
169  return api->pci_read_config_byte ( pci, where, value );
170 }
static struct pci_api * pcicloud_api(struct pci_device *pci)
Find configuration space access API for PCI device.
Definition: pcicloud.c:112
struct pci_api * api
API for this bus:dev.fn address.
Definition: pcicloud.c:42
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
A runtime selectable PCI I/O API.
Definition: pci_io.h:165
typeof() pci_read_config_byte * pci_read_config_byte
Definition: pci_io.h:169
static __always_inline int unsigned int where
Definition: pcibios.h:56

References api, pci_api::pci_read_config_byte, pcicloud_api(), value, and where.

◆ pcicloud_read_config_word()

static int pcicloud_read_config_word ( struct pci_device pci,
unsigned int  where,
uint16_t value 
)
static

Read 16-bit word from PCI configuration space.

Parameters
pciPCI device
whereLocation within PCI configuration space
valueValue read
Return values
rcReturn status code

Definition at line 180 of file pcicloud.c.

181  {
182  struct pci_api *api = pcicloud_api ( pci );
183 
184  return api->pci_read_config_word ( pci, where, value );
185 }
typeof() pci_read_config_word * pci_read_config_word
Definition: pci_io.h:170
static struct pci_api * pcicloud_api(struct pci_device *pci)
Find configuration space access API for PCI device.
Definition: pcicloud.c:112
struct pci_api * api
API for this bus:dev.fn address.
Definition: pcicloud.c:42
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
A runtime selectable PCI I/O API.
Definition: pci_io.h:165
static __always_inline int unsigned int where
Definition: pcibios.h:56

References api, pci_api::pci_read_config_word, pcicloud_api(), value, and where.

◆ pcicloud_read_config_dword()

static int pcicloud_read_config_dword ( struct pci_device pci,
unsigned int  where,
uint32_t value 
)
static

Read 32-bit dword from PCI configuration space.

Parameters
pciPCI device
whereLocation within PCI configuration space
valueValue read
Return values
rcReturn status code

Definition at line 195 of file pcicloud.c.

196  {
197  struct pci_api *api = pcicloud_api ( pci );
198 
199  return api->pci_read_config_dword ( pci, where, value );
200 }
typeof() pci_read_config_dword * pci_read_config_dword
Definition: pci_io.h:171
static struct pci_api * pcicloud_api(struct pci_device *pci)
Find configuration space access API for PCI device.
Definition: pcicloud.c:112
struct pci_api * api
API for this bus:dev.fn address.
Definition: pcicloud.c:42
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
A runtime selectable PCI I/O API.
Definition: pci_io.h:165
static __always_inline int unsigned int where
Definition: pcibios.h:56

References api, pci_api::pci_read_config_dword, pcicloud_api(), value, and where.

◆ pcicloud_write_config_byte()

static int pcicloud_write_config_byte ( struct pci_device pci,
unsigned int  where,
uint8_t  value 
)
static

Write byte to PCI configuration space.

Parameters
pciPCI device
whereLocation within PCI configuration space
valueValue to be written
Return values
rcReturn status code

Definition at line 210 of file pcicloud.c.

211  {
212  struct pci_api *api = pcicloud_api ( pci );
213 
214  return api->pci_write_config_byte ( pci, where, value );
215 }
typeof() pci_write_config_byte * pci_write_config_byte
Definition: pci_io.h:172
static struct pci_api * pcicloud_api(struct pci_device *pci)
Find configuration space access API for PCI device.
Definition: pcicloud.c:112
struct pci_api * api
API for this bus:dev.fn address.
Definition: pcicloud.c:42
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
A runtime selectable PCI I/O API.
Definition: pci_io.h:165
static __always_inline int unsigned int where
Definition: pcibios.h:56

References api, pci_api::pci_write_config_byte, pcicloud_api(), value, and where.

◆ pcicloud_write_config_word()

static int pcicloud_write_config_word ( struct pci_device pci,
unsigned int  where,
uint16_t  value 
)
static

Write 16-bit word to PCI configuration space.

Parameters
pciPCI device
whereLocation within PCI configuration space
valueValue to be written
Return values
rcReturn status code

Definition at line 225 of file pcicloud.c.

226  {
227  struct pci_api *api = pcicloud_api ( pci );
228 
229  return api->pci_write_config_word ( pci, where, value );
230 }
static struct pci_api * pcicloud_api(struct pci_device *pci)
Find configuration space access API for PCI device.
Definition: pcicloud.c:112
struct pci_api * api
API for this bus:dev.fn address.
Definition: pcicloud.c:42
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
typeof() pci_write_config_word * pci_write_config_word
Definition: pci_io.h:173
A runtime selectable PCI I/O API.
Definition: pci_io.h:165
static __always_inline int unsigned int where
Definition: pcibios.h:56

References api, pci_api::pci_write_config_word, pcicloud_api(), value, and where.

◆ pcicloud_write_config_dword()

static int pcicloud_write_config_dword ( struct pci_device pci,
unsigned int  where,
uint32_t  value 
)
static

Write 32-bit dword to PCI configuration space.

Parameters
pciPCI device
whereLocation within PCI configuration space
valueValue to be written
Return values
rcReturn status code

Definition at line 240 of file pcicloud.c.

241  {
242  struct pci_api *api = pcicloud_api ( pci );
243 
244  return api->pci_write_config_dword ( pci, where, value );
245 }
static struct pci_api * pcicloud_api(struct pci_device *pci)
Find configuration space access API for PCI device.
Definition: pcicloud.c:112
struct pci_api * api
API for this bus:dev.fn address.
Definition: pcicloud.c:42
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
A runtime selectable PCI I/O API.
Definition: pci_io.h:165
static __always_inline int unsigned int where
Definition: pcibios.h:56
typeof() pci_write_config_dword * pci_write_config_dword
Definition: pci_io.h:174

References api, pci_api::pci_write_config_dword, pcicloud_api(), value, and where.

◆ pcicloud_ioremap()

static void* pcicloud_ioremap ( struct pci_device pci,
unsigned long  bus_addr,
size_t  len 
)
static

Map PCI bus address as an I/O address.

Parameters
bus_addrPCI bus address
lenLength of region
Return values
io_addrI/O address, or NULL on error

Definition at line 254 of file pcicloud.c.

255  {
256  struct pci_api *api = pcicloud_api ( pci );
257 
258  return api->pci_ioremap ( pci, bus_addr, len );
259 }
static struct pci_api * pcicloud_api(struct pci_device *pci)
Find configuration space access API for PCI device.
Definition: pcicloud.c:112
struct pci_api * api
API for this bus:dev.fn address.
Definition: pcicloud.c:42
static __always_inline void unsigned long bus_addr
Definition: pcibios.h:155
ring len
Length.
Definition: dwmac.h:231
A runtime selectable PCI I/O API.
Definition: pci_io.h:165
typeof() pci_ioremap * pci_ioremap
Definition: pci_io.h:175

References api, bus_addr, len, pci_api::pci_ioremap, and pcicloud_api().

◆ PROVIDE_PCIAPI() [1/9]

PROVIDE_PCIAPI ( cloud  ,
pci_can_probe  ,
pcicloud_can_probe   
)

◆ PROVIDE_PCIAPI() [2/9]

PROVIDE_PCIAPI ( cloud  ,
pci_discover  ,
pcicloud_discover   
)

◆ PROVIDE_PCIAPI() [3/9]

PROVIDE_PCIAPI ( cloud  ,
pci_read_config_byte  ,
pcicloud_read_config_byte   
)

◆ PROVIDE_PCIAPI() [4/9]

PROVIDE_PCIAPI ( cloud  ,
pci_read_config_word  ,
pcicloud_read_config_word   
)

◆ PROVIDE_PCIAPI() [5/9]

PROVIDE_PCIAPI ( cloud  ,
pci_read_config_dword  ,
pcicloud_read_config_dword   
)

◆ PROVIDE_PCIAPI() [6/9]

PROVIDE_PCIAPI ( cloud  ,
pci_write_config_byte  ,
pcicloud_write_config_byte   
)

◆ PROVIDE_PCIAPI() [7/9]

PROVIDE_PCIAPI ( cloud  ,
pci_write_config_word  ,
pcicloud_write_config_word   
)

◆ PROVIDE_PCIAPI() [8/9]

PROVIDE_PCIAPI ( cloud  ,
pci_write_config_dword  ,
pcicloud_write_config_dword   
)

◆ PROVIDE_PCIAPI() [9/9]

PROVIDE_PCIAPI ( cloud  ,
pci_ioremap  ,
pcicloud_ioremap   
)

Variable Documentation

◆ range

struct pci_range range

◆ api

struct pci_api* api

◆ pcicloud

struct { ... } pcicloud

Cached PCI configuration space access API.

Referenced by pcicloud_api(), and pcicloud_find().