iPXE
pci.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * Based in part on pci.c from Etherboot 5.4, by Ken Yap and David
5  * Munro, in turn based on the Linux kernel's PCI implementation.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA.
21  *
22  * You can also choose to distribute this program under the terms of
23  * the Unmodified Binary Distribution Licence (as given in the file
24  * COPYING.UBDL), provided that you have satisfied its requirements.
25  */
26 
27 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
28 
29 #include <stdint.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <errno.h>
34 #include <ipxe/tables.h>
35 #include <ipxe/device.h>
36 #include <ipxe/pci.h>
37 
38 /** @file
39  *
40  * PCI bus
41  *
42  */
43 
44 static void pcibus_remove ( struct root_device *rootdev );
45 
46 /**
47  * Read PCI BAR
48  *
49  * @v pci PCI device
50  * @v reg PCI register number
51  * @ret bar Base address register
52  *
53  * Reads the specified PCI base address register, including the flags
54  * portion. 64-bit BARs will be handled automatically. If the value
55  * of the 64-bit BAR exceeds the size of an unsigned long (i.e. if the
56  * high dword is non-zero on a 32-bit platform), then the value
57  * returned will be zero plus the flags for a 64-bit BAR. Unreachable
58  * 64-bit BARs are therefore returned as uninitialised 64-bit BARs.
59  */
60 static unsigned long pci_bar ( struct pci_device *pci, unsigned int reg ) {
61  uint32_t low;
62  uint32_t high;
63 
64  pci_read_config_dword ( pci, reg, &low );
67  pci_read_config_dword ( pci, reg + 4, &high );
68  if ( high ) {
69  if ( sizeof ( unsigned long ) > sizeof ( uint32_t ) ) {
70  return ( ( ( uint64_t ) high << 32 ) | low );
71  } else {
72  DBGC ( pci, PCI_FMT " unhandled 64-bit BAR "
73  "%08x%08x\n",
74  PCI_ARGS ( pci ), high, low );
76  }
77  }
78  }
79  return low;
80 }
81 
82 /**
83  * Find the start of a PCI BAR
84  *
85  * @v pci PCI device
86  * @v reg PCI register number
87  * @ret start BAR start address
88  *
89  * Reads the specified PCI base address register, and returns the
90  * address portion of the BAR (i.e. without the flags).
91  *
92  * If the address exceeds the size of an unsigned long (i.e. if a
93  * 64-bit BAR has a non-zero high dword on a 32-bit machine), the
94  * return value will be zero.
95  */
96 unsigned long pci_bar_start ( struct pci_device *pci, unsigned int reg ) {
97  unsigned long bar;
98 
99  bar = pci_bar ( pci, reg );
100  if ( bar & PCI_BASE_ADDRESS_SPACE_IO ) {
101  return ( bar & ~PCI_BASE_ADDRESS_IO_MASK );
102  } else {
103  return ( bar & ~PCI_BASE_ADDRESS_MEM_MASK );
104  }
105 }
106 
107 /**
108  * Set the start of a PCI BAR
109  *
110  * @v pci PCI device
111  * @v reg PCI register number
112  * @v start BAR start address
113  */
114 void pci_bar_set ( struct pci_device *pci, unsigned int reg,
115  unsigned long start ) {
116  unsigned int type;
117  uint32_t low;
118  uint32_t high;
119  uint16_t cmd;
120 
121  /* Save the original command register and disable decoding */
124  ( cmd & ~( PCI_COMMAND_MEM |
125  PCI_COMMAND_IO ) ) );
126 
127  /* Check for a 64-bit BAR */
128  pci_read_config_dword ( pci, reg, &low );
131 
132  /* Write low 32 bits */
133  low = start;
134  pci_write_config_dword ( pci, reg, low );
135 
136  /* Write high 32 bits, if applicable */
138  if ( sizeof ( unsigned long ) > sizeof ( uint32_t ) ) {
139  high = ( ( ( uint64_t ) start ) >> 32 );
140  } else {
141  high = 0;
142  }
143  pci_write_config_dword ( pci, reg + 4, high );
144  }
145 
146  /* Restore the original command register */
148 }
149 
150 /**
151  * Get the size of a PCI BAR
152  *
153  * @v pci PCI device
154  * @v reg PCI register number
155  * @ret size BAR size
156  *
157  * Most drivers should not need to call this function. It is not
158  * necessary to map the whole PCI BAR, only the portion that will be
159  * used for register access. Since register offsets are almost always
160  * fixed by hardware design, the length of the mapped portion will
161  * almost always be a compile-time constant.
162  */
163 unsigned long pci_bar_size ( struct pci_device *pci, unsigned int reg ) {
164  unsigned long start;
165  unsigned long size;
166  uint16_t cmd;
167 
168  /* Save the original command register and disable decoding */
171  ( cmd & ~( PCI_COMMAND_MEM |
172  PCI_COMMAND_IO ) ) );
173 
174  /* Save the original start address */
175  start = pci_bar_start ( pci, reg );
176 
177  /* Set all possible bits */
178  pci_bar_set ( pci, reg, -1UL );
179 
180  /* Determine size by finding lowest set bit */
181  size = pci_bar_start ( pci, reg );
182  size &= ( -size );
183 
184  /* Restore the original start address */
185  pci_bar_set ( pci, reg, start );
186 
187  /* Restore the original command register */
189 
190  return size;
191 }
192 
193 /**
194  * Read membase and ioaddr for a PCI device
195  *
196  * @v pci PCI device
197  *
198  * This scans through all PCI BARs on the specified device. The first
199  * valid memory BAR is recorded as pci_device::membase, and the first
200  * valid IO BAR is recorded as pci_device::ioaddr.
201  *
202  * 64-bit BARs are handled automatically. On a 32-bit platform, if a
203  * 64-bit BAR has a non-zero high dword, it will be regarded as
204  * invalid.
205  */
206 static void pci_read_bases ( struct pci_device *pci ) {
207  unsigned long bar;
208  int reg;
209 
210  /* Clear any existing base addresses */
211  pci->ioaddr = 0;
212  pci->membase = 0;
213 
214  /* Get first memory and I/O BAR addresses */
215  for ( reg = PCI_BASE_ADDRESS_0; reg <= PCI_BASE_ADDRESS_5; reg += 4 ) {
216  bar = pci_bar ( pci, reg );
217  if ( bar & PCI_BASE_ADDRESS_SPACE_IO ) {
218  if ( ! pci->ioaddr )
219  pci->ioaddr =
220  ( bar & ~PCI_BASE_ADDRESS_IO_MASK );
221  } else {
222  if ( ! pci->membase )
223  pci->membase =
224  ( bar & ~PCI_BASE_ADDRESS_MEM_MASK );
225  /* Skip next BAR if 64-bit */
226  if ( bar & PCI_BASE_ADDRESS_MEM_TYPE_64 )
227  reg += 4;
228  }
229  }
230 }
231 
232 /**
233  * Enable PCI device
234  *
235  * @v pci PCI device
236  *
237  * Set device to be a busmaster in case BIOS neglected to do so. Also
238  * adjust PCI latency timer to a reasonable value, 32.
239  */
240 void adjust_pci_device ( struct pci_device *pci ) {
241  unsigned short new_command, pci_command;
242  unsigned char pci_latency;
243 
244  pci_read_config_word ( pci, PCI_COMMAND, &pci_command );
245  new_command = ( pci_command | PCI_COMMAND_MASTER |
247  if ( pci_command != new_command ) {
248  DBGC ( pci, PCI_FMT " device not enabled by BIOS! Updating "
249  "PCI command %04x->%04x\n",
250  PCI_ARGS ( pci ), pci_command, new_command );
251  pci_write_config_word ( pci, PCI_COMMAND, new_command );
252  }
253 
254  pci_read_config_byte ( pci, PCI_LATENCY_TIMER, &pci_latency);
255  if ( pci_latency < 32 ) {
256  DBGC ( pci, PCI_FMT " latency timer is unreasonably low at "
257  "%d. Setting to 32.\n", PCI_ARGS ( pci ), pci_latency );
259  }
260 }
261 
262 /**
263  * Read PCI device configuration
264  *
265  * @v pci PCI device
266  * @ret rc Return status code
267  */
268 int pci_read_config ( struct pci_device *pci ) {
270  uint8_t hdrtype;
271  uint32_t tmp;
272 
273  /* Ignore all but the first function on non-multifunction devices */
274  if ( PCI_FUNC ( pci->busdevfn ) != 0 ) {
275  busdevfn = pci->busdevfn;
276  pci->busdevfn = PCI_FIRST_FUNC ( pci->busdevfn );
277  pci_read_config_byte ( pci, PCI_HEADER_TYPE, &hdrtype );
278  pci->busdevfn = busdevfn;
279  if ( ! ( hdrtype & PCI_HEADER_TYPE_MULTI ) )
280  return -ENODEV;
281  }
282 
283  /* Check for physical device presence */
285  if ( ( tmp == 0xffffffff ) || ( tmp == 0 ) )
286  return -ENODEV;
287 
288  /* Populate struct pci_device */
289  pci->vendor = ( tmp & 0xffff );
290  pci->device = ( tmp >> 16 );
292  pci->class = ( tmp >> 8 );
295  pci_read_bases ( pci );
296 
297  /* Initialise generic device component */
298  snprintf ( pci->dev.name, sizeof ( pci->dev.name ), "%04x:%02x:%02x.%x",
299  PCI_SEG ( pci->busdevfn ), PCI_BUS ( pci->busdevfn ),
300  PCI_SLOT ( pci->busdevfn ), PCI_FUNC ( pci->busdevfn ) );
301  pci->dev.desc.bus_type = BUS_TYPE_PCI;
302  pci->dev.desc.location = pci->busdevfn;
303  pci->dev.desc.vendor = pci->vendor;
304  pci->dev.desc.device = pci->device;
305  pci->dev.desc.class = pci->class;
306  pci->dev.desc.ioaddr = pci->ioaddr;
307  pci->dev.desc.irq = pci->irq;
308  INIT_LIST_HEAD ( &pci->dev.siblings );
309  INIT_LIST_HEAD ( &pci->dev.children );
310 
311  return 0;
312 }
313 
314 /**
315  * Find next device on PCI bus
316  *
317  * @v pci PCI device to fill in
318  * @v busdevfn Starting bus:dev.fn address
319  * @ret busdevfn Bus:dev.fn address of next PCI device
320  * @ret rc Return status code
321  */
322 int pci_find_next ( struct pci_device *pci, uint32_t *busdevfn ) {
323  static struct pci_range range;
324  uint8_t hdrtype;
325  uint8_t sub;
326  uint32_t end;
327  unsigned int count;
328  int rc;
329 
330  /* Find next PCI device, if any */
331  do {
332  /* Find next PCI bus:dev.fn address range, if necessary */
333  if ( ( *busdevfn - range.start ) >= range.count ) {
334  pci_discover ( *busdevfn, &range );
335  if ( *busdevfn < range.start )
336  *busdevfn = range.start;
337  if ( ( *busdevfn - range.start ) >= range.count )
338  break;
339  }
340 
341  /* Check for PCI device existence */
342  memset ( pci, 0, sizeof ( *pci ) );
343  pci_init ( pci, *busdevfn );
344  if ( ( rc = pci_read_config ( pci ) ) != 0 )
345  continue;
346 
347  /* If device is a bridge, expand the PCI bus:dev.fn
348  * address range as needed.
349  */
350  pci_read_config_byte ( pci, PCI_HEADER_TYPE, &hdrtype );
351  hdrtype &= PCI_HEADER_TYPE_MASK;
352  if ( hdrtype == PCI_HEADER_TYPE_BRIDGE ) {
353  pci_read_config_byte ( pci, PCI_SUBORDINATE, &sub );
354  end = PCI_BUSDEVFN ( PCI_SEG ( *busdevfn ),
355  ( sub + 1 ), 0, 0 );
356  count = ( end - range.start );
357  if ( count > range.count ) {
358  DBGC ( pci, PCI_FMT " found subordinate bus "
359  "%#02x\n", PCI_ARGS ( pci ), sub );
360  range.count = count;
361  }
362  }
363 
364  /* Return this device */
365  return 0;
366 
367  } while ( ++(*busdevfn) );
368 
369  return -ENODEV;
370 }
371 
372 /**
373  * Find driver for PCI device
374  *
375  * @v pci PCI device
376  * @ret rc Return status code
377  */
378 int pci_find_driver ( struct pci_device *pci ) {
379  struct pci_driver *driver;
380  struct pci_device_id *id;
381  unsigned int i;
382 
383  for_each_table_entry ( driver, PCI_DRIVERS ) {
384  if ( ( driver->class.class ^ pci->class ) & driver->class.mask )
385  continue;
386  for ( i = 0 ; i < driver->id_count ; i++ ) {
387  id = &driver->ids[i];
388  if ( ( id->vendor != PCI_ANY_ID ) &&
389  ( id->vendor != pci->vendor ) )
390  continue;
391  if ( ( id->device != PCI_ANY_ID ) &&
392  ( id->device != pci->device ) )
393  continue;
394  pci_set_driver ( pci, driver, id );
395  return 0;
396  }
397  }
398  return -ENOENT;
399 }
400 
401 /**
402  * Probe a PCI device
403  *
404  * @v pci PCI device
405  * @ret rc Return status code
406  *
407  * Searches for a driver for the PCI device. If a driver is found,
408  * its probe() routine is called.
409  */
410 int pci_probe ( struct pci_device *pci ) {
411  int rc;
412 
413  DBGC ( pci, PCI_FMT " (%04x:%04x) has driver \"%s\"\n",
414  PCI_ARGS ( pci ), pci->vendor, pci->device, pci->id->name );
415  DBGC ( pci, PCI_FMT " has mem %lx io %lx irq %d\n",
416  PCI_ARGS ( pci ), pci->membase, pci->ioaddr, pci->irq );
417 
418  if ( ( rc = pci->driver->probe ( pci ) ) != 0 ) {
419  DBGC ( pci, PCI_FMT " probe failed: %s\n",
420  PCI_ARGS ( pci ), strerror ( rc ) );
421  return rc;
422  }
423 
424  return 0;
425 }
426 
427 /**
428  * Remove a PCI device
429  *
430  * @v pci PCI device
431  */
432 void pci_remove ( struct pci_device *pci ) {
433  pci->driver->remove ( pci );
434  DBGC ( pci, PCI_FMT " removed\n", PCI_ARGS ( pci ) );
435 }
436 
437 /**
438  * Probe PCI root bus
439  *
440  * @v rootdev PCI bus root device
441  *
442  * Scans the PCI bus for devices and registers all devices it can
443  * find.
444  */
445 static int pcibus_probe ( struct root_device *rootdev ) {
446  struct pci_device *pci = NULL;
447  uint32_t busdevfn = 0;
448  int rc;
449 
450  do {
451  /* Allocate struct pci_device */
452  if ( ! pci )
453  pci = malloc ( sizeof ( *pci ) );
454  if ( ! pci ) {
455  rc = -ENOMEM;
456  goto err;
457  }
458 
459  /* Find next PCI device, if any */
460  if ( ( rc = pci_find_next ( pci, &busdevfn ) ) != 0 )
461  break;
462 
463  /* Skip automatic probing if prohibited */
464  if ( ! pci_can_probe ( pci ) )
465  continue;
466 
467  /* Look for a driver */
468  if ( ( rc = pci_find_driver ( pci ) ) != 0 ) {
469  DBGC ( pci, PCI_FMT " (%04x:%04x class %06x) has no "
470  "driver\n", PCI_ARGS ( pci ), pci->vendor,
471  pci->device, pci->class );
472  continue;
473  }
474 
475  /* Add to device hierarchy */
476  pci->dev.parent = &rootdev->dev;
477  list_add ( &pci->dev.siblings, &rootdev->dev.children );
478 
479  /* Look for a driver */
480  if ( ( rc = pci_probe ( pci ) ) == 0 ) {
481  /* pcidev registered, we can drop our ref */
482  pci = NULL;
483  } else {
484  /* Not registered; re-use struct pci_device */
485  list_del ( &pci->dev.siblings );
486  }
487 
488  } while ( ++busdevfn );
489 
490  free ( pci );
491  return 0;
492 
493  err:
494  free ( pci );
495  pcibus_remove ( rootdev );
496  return rc;
497 }
498 
499 /**
500  * Remove PCI root bus
501  *
502  * @v rootdev PCI bus root device
503  */
504 static void pcibus_remove ( struct root_device *rootdev ) {
505  struct pci_device *pci;
506  struct pci_device *tmp;
507 
508  list_for_each_entry_safe ( pci, tmp, &rootdev->dev.children,
509  dev.siblings ) {
510  pci_remove ( pci );
511  list_del ( &pci->dev.siblings );
512  free ( pci );
513  }
514 }
515 
516 /** PCI bus root device driver */
517 static struct root_driver pci_root_driver = {
518  .probe = pcibus_probe,
519  .remove = pcibus_remove,
520 };
521 
522 /** PCI bus root device */
523 struct root_device pci_root_device __root_device = {
524  .dev = { .name = "PCI" },
525  .driver = &pci_root_driver,
526 };
527 
528 /* Drag in objects via pcibus_probe() */
530 
531 /* Drag in PCI configuration */
532 REQUIRE_OBJECT ( config_pci );
#define PCI_FUNC(busdevfn)
Definition: pci.h:285
#define PCI_HEADER_TYPE_BRIDGE
PCI-to-PCI bridge header.
Definition: pci.h:55
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:24
unsigned long membase
Memory base.
Definition: pci.h:219
uint8_t irq
Interrupt number.
Definition: pci.h:233
#define PCI_BUS(busdevfn)
Definition: pci.h:283
static struct root_driver pci_root_driver
PCI bus root device driver.
Definition: pci.c:517
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
uint32_t low
Low 16 bits of address.
Definition: myson.h:19
struct pci_class_id class
PCI class ID.
Definition: pci.h:257
struct pci_range range
PCI bus:dev.fn address range.
Definition: pcicloud.c:40
struct pci_driver * driver
Driver for this device.
Definition: pci.h:239
A PCI driver.
Definition: pci.h:251
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition: pci.c:378
static unsigned int unsigned int reg
Definition: myson.h:162
void(* remove)(struct pci_device *pci)
Remove device.
Definition: pci.h:270
uint32_t class
Device class.
Definition: pci.h:231
#define PCI_LATENCY_TIMER
PCI latency timer.
Definition: pci.h:50
int pci_can_probe(struct pci_device *pci)
Check if PCI bus probing is allowed.
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
unsigned long ioaddr
I/O address.
Definition: pci.h:225
unsigned int id_count
Number of entries in PCI ID table.
Definition: pci.h:255
Error codes.
struct pci_device_id * ids
PCI ID table.
Definition: pci.h:253
unsigned long ioaddr
I/O address.
Definition: device.h:37
uint32_t type
Operating system type.
Definition: ena.h:12
int pci_write_config_word(struct pci_device *pci, unsigned int where, uint16_t value)
Write 16-bit word to PCI configuration space.
#define PCI_INTERRUPT_LINE
PCI interrupt line.
Definition: pci.h:90
uint16_t size
Buffer size.
Definition: dwmac.h:14
static void pci_set_driver(struct pci_device *pci, struct pci_driver *driver, struct pci_device_id *id)
Set PCI driver.
Definition: pci.h:351
#define PCI_HEADER_TYPE_MASK
Header type mask.
Definition: pci.h:57
#define DBGC(...)
Definition: compiler.h:505
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Get the size of a PCI BAR.
Definition: pci.c:163
char name[40]
Name.
Definition: device.h:78
#define ENOENT
No such file or directory.
Definition: errno.h:514
unsigned long class
Device class.
Definition: device.h:35
A root device.
Definition: device.h:97
unsigned long long uint64_t
Definition: stdint.h:13
#define PCI_BASE_ADDRESS_0
Definition: pci.h:62
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
uint32_t mask
Class mask.
Definition: pci.h:193
#define PCI_COMMAND
PCI command.
Definition: pci.h:25
uint32_t class
Class.
Definition: pci.h:191
#define PCI_BASE_ADDRESS_5
Definition: pci.h:67
struct device dev
Device chain.
Definition: device.h:102
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:240
unsigned int vendor
Vendor ID.
Definition: device.h:31
struct device * parent
Bus device.
Definition: device.h:88
struct device dev
Generic device.
Definition: pci.h:212
#define PCI_HEADER_TYPE
PCI header type.
Definition: pci.h:53
void pci_bar_set(struct pci_device *pci, unsigned int reg, unsigned long start)
Set the start of a PCI BAR.
Definition: pci.c:114
uint32_t start
Starting offset.
Definition: netvsc.h:12
unsigned long tmp
Definition: linux_pci.h:64
#define PCI_COMMAND_MASTER
Bus master.
Definition: pci.h:28
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define PCI_BASE_ADDRESS_IO_MASK
I/O BAR mask.
Definition: pci.h:69
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define PCI_COMMAND_IO
I/O space.
Definition: pci.h:26
struct root_device pci_root_device __root_device
PCI bus root device.
Definition: pci.c:523
int pci_find_next(struct pci_device *pci, uint32_t *busdevfn)
Find next device on PCI bus.
Definition: pci.c:322
uint16_t device
Device ID.
Definition: pci.h:229
#define BUS_TYPE_PCI
PCI bus type.
Definition: device.h:43
static void pci_read_bases(struct pci_device *pci)
Read membase and ioaddr for a PCI device.
Definition: pci.c:206
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
unsigned int irq
IRQ.
Definition: device.h:39
#define PCI_FIRST_FUNC(busdevfn)
Definition: pci.h:286
static int pcibus_probe(struct root_device *rootdev)
Probe PCI root bus.
Definition: pci.c:445
A PCI bus:dev.fn address range.
Definition: pci_io.h:22
static unsigned int count
Number of entries.
Definition: dwmac.h:225
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition: pci.c:96
unsigned int location
Location.
Definition: device.h:29
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:458
uint8_t id
Request identifier.
Definition: ena.h:12
uint32_t high
High 32 bits of address.
Definition: myson.h:20
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:29
#define PCI_BASE_ADDRESS_MEM_MASK
Memory BAR mask.
Definition: pci.h:72
uint8_t hdrtype
Header type.
Definition: pci.h:235
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
#define PCI_BASE_ADDRESS_MEM_TYPE_64
64-bit memory
Definition: pci.h:70
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:311
#define PCI_SLOT(busdevfn)
Definition: pci.h:284
PCI bus.
struct list_head siblings
Devices on the same bus.
Definition: device.h:84
A PCI device.
Definition: pci.h:210
#define PCI_BASE_ADDRESS_MEM_TYPE_MASK
Memory type mask.
Definition: pci.h:71
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
Definition: pci.c:268
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
A root device driver.
Definition: device.h:110
#define ENODEV
No such device.
Definition: errno.h:509
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition: pci.c:432
#define PCI_VENDOR_ID
PCI vendor ID.
Definition: pci.h:19
unsigned char uint8_t
Definition: stdint.h:10
REQUIRE_OBJECT(config_pci)
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
A PCI device ID list entry.
Definition: pci.h:174
unsigned int uint32_t
Definition: stdint.h:12
int(* probe)(struct root_device *rootdev)
Add root device.
Definition: device.h:119
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:620
const char * name
Name.
Definition: pci.h:176
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:26
#define PCI_BASE_ADDRESS_SPACE_IO
I/O BAR.
Definition: pci.h:68
uint16_t vendor
Vendor ID.
Definition: pci.h:227
void pci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:237
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
unsigned int bus_type
Bus type.
Definition: device.h:24
static void pcibus_remove(struct root_device *rootdev)
Remove PCI root bus.
Definition: pci.c:504
int(* probe)(struct pci_device *pci)
Probe device.
Definition: pci.h:264
unsigned int device
Device ID.
Definition: device.h:33
struct list_head children
Devices attached to this device.
Definition: device.h:86
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:314
struct pci_device_id * id
Driver device ID.
Definition: pci.h:247
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
uint32_t end
Ending offset.
Definition: netvsc.h:18
#define PCI_REVISION
PCI revision.
Definition: pci.h:44
struct device_description desc
Device description.
Definition: device.h:82
Linker tables.
REQUIRING_SYMBOL(pcibus_probe)
Device model.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
#define PCI_COMMAND_MEM
Memory space.
Definition: pci.h:27
#define PCI_SUBORDINATE
Subordinate bus number.
Definition: pci.h:149
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:340
static unsigned long pci_bar(struct pci_device *pci, unsigned int reg)
Read PCI BAR.
Definition: pci.c:60
#define PCI_SEG(busdevfn)
Definition: pci.h:282
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29
int pci_probe(struct pci_device *pci)
Probe a PCI device.
Definition: pci.c:410
String functions.
#define PCI_HEADER_TYPE_MULTI
Multi-function device.
Definition: pci.h:58
#define PCI_ANY_ID
Match-anything ID.
Definition: pci.h:186
#define PCI_DRIVERS
PCI driver table.
Definition: pci.h:274
void * memset(void *dest, int character, size_t len) __nonnull
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.