iPXE
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.
static void pcicloud_discover (uint32_t busdevfn, struct pci_range *range)
 Find next PCI bus:dev.fn address range in system.
static struct pci_apipcicloud_api (struct pci_device *pci)
 Find configuration space access API for PCI device.
static int pcicloud_can_probe (struct pci_device *pci)
 Check if PCI bus probing is allowed.
static int pcicloud_read_config_byte (struct pci_device *pci, unsigned int where, uint8_t *value)
 Read byte from PCI configuration space.
static int pcicloud_read_config_word (struct pci_device *pci, unsigned int where, uint16_t *value)
 Read 16-bit word from PCI configuration space.
static int pcicloud_read_config_dword (struct pci_device *pci, unsigned int where, uint32_t *value)
 Read 32-bit dword from PCI configuration space.
static int pcicloud_write_config_byte (struct pci_device *pci, unsigned int where, uint8_t value)
 Write byte to PCI configuration space.
static int pcicloud_write_config_word (struct pci_device *pci, unsigned int where, uint16_t value)
 Write 16-bit word to PCI configuration space.
static int pcicloud_write_config_dword (struct pci_device *pci, unsigned int where, uint32_t value)
 Write 32-bit dword to PCI configuration space.
static void * pcicloud_ioremap (struct pci_device *pci, unsigned long bus_addr, size_t len)
 Map PCI bus address as an I/O address.
 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.

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()

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 NULL
NULL pointer (VOID *)
Definition Base.h:322
unsigned int uint32_t
Definition stdint.h:12
long index
Definition bigint.h:65
uint16_t busdevfn
PCI bus:dev.fn address.
Definition ena.h:17
#define DBGC(...)
Definition compiler.h:505
#define PCI_APIS
Runtime selectable PCI API table.
Definition pci_io.h:180
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint32_t first
First block in range.
Definition pccrr.h:1
#define PCI_FMT
PCI device debug message format.
Definition pci.h:312
#define PCI_SEG(busdevfn)
Definition pci.h:283
#define PCI_FUNC(busdevfn)
Definition pci.h:286
#define PCI_BUS(busdevfn)
Definition pci.h:284
#define PCI_SLOT(busdevfn)
Definition pci.h:285
struct pci_api * api
API for this bus:dev.fn address.
Definition pcicloud.c:42
static struct @164334221061242153220350147373067220175352131324 pcicloud
Cached PCI configuration space access API.
struct pci_range range
PCI bus:dev.fn address range.
Definition pcicloud.c:40
A runtime selectable PCI I/O API.
Definition pci_io.h:166
A PCI bus:dev.fn address range.
Definition pci_io.h:23
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386

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

Referenced by pcicloud_api(), and pcicloud_discover().

◆ pcicloud_discover()

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}
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.

Referenced by PROVIDE_PCIAPI().

◆ pcicloud_api()

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;
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}
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition pci.h:238
#define table_end(table)
Get end of linker table.
Definition tables.h:309

References api, pci_device::busdevfn, DBGC, first, PCI_APIS, PCI_BUS, PCI_FMT, PCI_FUNC, PCI_SEG, PCI_SLOT, pcicloud, pcicloud_find(), range, 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()

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

References api, and pcicloud_api().

Referenced by PROVIDE_PCIAPI().

◆ pcicloud_read_config_byte()

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}
pseudo_bit_t value[0x00020]
Definition arbel.h:2
static __always_inline int unsigned int where
Definition pcibios.h:57

References api, pcicloud_api(), value, and where.

Referenced by PROVIDE_PCIAPI().

◆ pcicloud_read_config_word()

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}

References api, pcicloud_api(), value, and where.

Referenced by PROVIDE_PCIAPI().

◆ pcicloud_read_config_dword()

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}

References api, pcicloud_api(), value, and where.

Referenced by PROVIDE_PCIAPI().

◆ pcicloud_write_config_byte()

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}

References api, pcicloud_api(), value, and where.

Referenced by PROVIDE_PCIAPI().

◆ pcicloud_write_config_word()

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}

References api, pcicloud_api(), value, and where.

Referenced by PROVIDE_PCIAPI().

◆ pcicloud_write_config_dword()

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}

References api, pcicloud_api(), value, and where.

Referenced by PROVIDE_PCIAPI().

◆ pcicloud_ioremap()

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}
ring len
Length.
Definition dwmac.h:226
static __always_inline void unsigned long bus_addr
Definition pcibios.h:156

References api, bus_addr, len, and pcicloud_api().

Referenced by PROVIDE_PCIAPI().

◆ 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() [4/9]

◆ PROVIDE_PCIAPI() [5/9]

◆ PROVIDE_PCIAPI() [6/9]

◆ PROVIDE_PCIAPI() [7/9]

◆ PROVIDE_PCIAPI() [8/9]

◆ PROVIDE_PCIAPI() [9/9]

PROVIDE_PCIAPI ( cloud ,
pci_ioremap ,
pcicloud_ioremap  )

Variable Documentation

◆ range

◆ api

◆ [struct]

struct { ... } pcicloud

Cached PCI configuration space access API.

Referenced by pcicloud_api(), and pcicloud_find().