iPXE
Functions | Variables
pcibridge.c File Reference

PCI-to-PCI bridge. More...

#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/pci.h>
#include <ipxe/pcibridge.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static LIST_HEAD (pcibridges)
 List of all PCI bridges. More...
 
struct pci_bridgepcibridge_find (struct pci_device *pci)
 Find bridge attached to a PCI device. More...
 
static int pcibridge_probe (struct pci_device *pci)
 Probe PCI device. More...
 
static void pcibridge_remove (struct pci_device *pci)
 Remove PCI device. More...
 

Variables

static struct pci_device_id pcibridge_ids []
 Bridge PCI device IDs. More...
 
struct pci_driver pcibridge_driver __pci_driver
 Bridge PCI driver. More...
 

Detailed Description

PCI-to-PCI bridge.

Definition in file pcibridge.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ LIST_HEAD()

static LIST_HEAD ( pcibridges  )
static

List of all PCI bridges.

◆ pcibridge_find()

struct pci_bridge* pcibridge_find ( struct pci_device pci)

Find bridge attached to a PCI device.

Parameters
pciPCI device
Return values
bridgePCI bridge, or NULL

Definition at line 48 of file pcibridge.c.

48  {
49  unsigned int bus = PCI_BUS ( pci->busdevfn );
50  struct pci_bridge *bridge;
51 
52  /* Find matching bridge */
53  list_for_each_entry ( bridge, &pcibridges, list ) {
54  if ( bus == bridge->secondary )
55  return bridge;
56  }
57 
58  return NULL;
59 }
#define PCI_BUS(busdevfn)
Definition: pci.h:279
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
A PCI-to-PCI bridge.
Definition: pcibridge.h:17
uint8_t secondary
Secondary bus.
Definition: pcibridge.h:28
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:233
struct list_head list
List of bridges.
Definition: pcibridge.h:38
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
uint8_t bus
Bus.
Definition: edd.h:14

References bus, pci_device::busdevfn, pci_bridge::list, list_for_each_entry, NULL, pci_bridge::pci, PCI_BUS, and pci_bridge::secondary.

Referenced by ena_membase().

◆ pcibridge_probe()

static int pcibridge_probe ( struct pci_device pci)
static

Probe PCI device.

Parameters
pciPCI device
Return values
rcReturn status code

Definition at line 67 of file pcibridge.c.

67  {
68  struct pci_bridge *bridge;
69  uint16_t base;
71  int rc;
72 
73  /* Allocate and initialise structure */
74  bridge = zalloc ( sizeof ( *bridge ) );
75  if ( ! bridge ) {
76  rc = -ENOMEM;
77  goto err_alloc;
78  }
79  bridge->pci = pci;
80 
81  /* Read configuration */
83  cpu_to_le32s ( &buses );
85  bridge->membase = ( ( base & ~PCI_MEM_MASK ) << 16 );
87  bridge->memlimit = ( ( ( ( limit | PCI_MEM_MASK ) + 1 ) << 16 ) - 1 );
88  DBGC ( bridge, "BRIDGE " PCI_FMT " bus %02x to [%02x,%02x) mem "
89  "[%08x,%08x)\n", PCI_ARGS ( pci ), bridge->primary,
90  bridge->secondary, bridge->subordinate, bridge->membase,
91  bridge->memlimit );
92 
93  /* Add to list of PCI bridges */
94  list_add ( &bridge->list, &pcibridges );
95 
96  pci_set_drvdata ( pci, bridge );
97  return 0;
98 
99  free ( bridge );
100  err_alloc:
101  return rc;
102 }
#define PCI_MEM_BASE
Memory base and limit.
Definition: pci.h:152
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
uint8_t subordinate
Subordinate bus.
Definition: pcibridge.h:30
#define PCI_MEM_MASK
Definition: pci.h:154
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
#define PCI_MEM_LIMIT
Definition: pci.h:153
#define DBGC(...)
Definition: compiler.h:505
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
static const void * base
Base address.
Definition: crypto.h:335
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:359
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define PCI_PRIMARY
Primary bus number.
Definition: pci.h:143
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
struct pci_device * pci
PCI device.
Definition: pcibridge.h:19
#define cpu_to_le32s(ptr)
Definition: byteswap.h:119
uint16_t limit
Limit.
Definition: librm.h:250
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A PCI-to-PCI bridge.
Definition: pcibridge.h:17
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
uint8_t primary
Primary bus.
Definition: pcibridge.h:26
uint32_t memlimit
Memory limit.
Definition: pcibridge.h:36
uint8_t secondary
Secondary bus.
Definition: pcibridge.h:28
struct list_head list
List of bridges.
Definition: pcibridge.h:38
uint32_t buses
Raw dword.
Definition: pcibridge.h:23
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
uint32_t membase
Memory base.
Definition: pcibridge.h:34

References base, pci_bridge::buses, cpu_to_le32s, DBGC, ENOMEM, free, limit, pci_bridge::list, list_add, pci_bridge::membase, pci_bridge::memlimit, pci_bridge::pci, PCI_ARGS, PCI_FMT, PCI_MEM_BASE, PCI_MEM_LIMIT, PCI_MEM_MASK, PCI_PRIMARY, pci_read_config_dword(), pci_read_config_word(), pci_set_drvdata(), pci_bridge::primary, rc, pci_bridge::secondary, pci_bridge::subordinate, and zalloc().

◆ pcibridge_remove()

static void pcibridge_remove ( struct pci_device pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 109 of file pcibridge.c.

109  {
110  struct pci_bridge *bridge = pci_get_drvdata ( pci );
111 
112  /* Remove from list of bridges */
113  list_del ( &bridge->list );
114 
115  /* Free device */
116  free ( bridge );
117 }
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
struct pci_device * pci
PCI device.
Definition: pcibridge.h:19
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A PCI-to-PCI bridge.
Definition: pcibridge.h:17
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:369
struct list_head list
List of bridges.
Definition: pcibridge.h:38

References free, pci_bridge::list, list_del, pci_bridge::pci, and pci_get_drvdata().

Variable Documentation

◆ pcibridge_ids

struct pci_device_id pcibridge_ids[]
static
Initial value:
= {
PCI_ROM ( 0xffff, 0xffff, "bridge", "Bridge", 0 ),
}
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:303

Bridge PCI device IDs.

Definition at line 120 of file pcibridge.c.

◆ __pci_driver

struct pci_driver pcibridge_driver __pci_driver
Initial value:
= {
.ids = pcibridge_ids,
.id_count = ( sizeof ( pcibridge_ids ) / sizeof ( pcibridge_ids[0] ) ),
.probe = pcibridge_probe,
.remove = pcibridge_remove,
}
#define PCI_CLASS_ID(base, sub, progif)
Construct PCI class ID.
Definition: pci.h:198
static struct pci_device_id pcibridge_ids[]
Bridge PCI device IDs.
Definition: pcibridge.c:120
#define PCI_CLASS_BRIDGE
Definition: Pci22.h:183
#define PCI_CLASS_BRIDGE_PCI
PCI-to-PCI bridge.
Definition: pci.h:132
static int pcibridge_probe(struct pci_device *pci)
Probe PCI device.
Definition: pcibridge.c:67
static void pcibridge_remove(struct pci_device *pci)
Remove PCI device.
Definition: pcibridge.c:109
#define PCI_ANY_ID
Match-anything ID.
Definition: pci.h:182

Bridge PCI driver.

Definition at line 125 of file pcibridge.c.