UEFIStarter
a simple UEFI framework
Macros | Functions | Variables
pci.c File Reference

Functions for accessing PCI devices. More...

#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <UEFIStarter/pci.h>
#include <UEFIStarter/core/memory.h>
#include <UEFIStarter/core/files.h>
#include <UEFIStarter/core/string.h>
#include <UEFIStarter/core/logger.h>

Macros

#define MAX_PCI_DEVICES   100
 the highest number of PCI device entries supported
 

Functions

static CHAR8 hexdigita (UINT8 value)
 internal: converts a hexadecimal value into a printable hex character. More...
 
static void ui16tohexa (char *buffer, UINT16 value)
 internal: converts a UINT16 value to a printable lowercase hex string. More...
 
CHAR16 * find_pci_device_name (UINT16 vendor_id, UINT16 device_id, UINT16 subvendor_id, UINT16 subdevice_id)
 Looks up a PCI device's name by vendor ID and device ID. More...
 
CHAR16 * find_pci_class_name (UINT8 class_code[3])
 Finds a PCI class and subclass name by 3-byte class code. More...
 
void describe_pci_device (PCI_TYPE00 *config)
 Prints basic information about a PCI device. More...
 
int enumerate_pci_devices ()
 Assembles the internal list of PCI devices. More...
 
EFI_PCI_IO_PROTOCOL * find_pci_device (UINT16 vendor_id, UINT16 device_id)
 Fetches a PCI device's protocol handle. More...
 
void print_pci_devices ()
 Prints a short description of all connected PCI devices.
 
void print_known_pci_classes ()
 Prints a list of known PCI classes and subclasses. More...
 
void init_pci_lib ()
 Initializes the PCI library. More...
 
void shutdown_pci_lib ()
 Shuts down the PCI library. More...
 

Variables

static EFI_PCI_IO_PROTOCOL * _pci_protocols [MAX_PCI_DEVICES]
 the list of PCI UEFI protocol handlers
 
static EFI_HANDLE _pci_handles [MAX_PCI_DEVICES]
 the list of PCI device handles
 
static UINTN _pci_handle_count =0
 the amount of PCI device handles
 
static PCI_TYPE00 _pci_configs [MAX_PCI_DEVICES]
 the PCI device's TYPE00 headers
 
static file_contents_t_pci_id_file =NULL
 the pci.ids file contents
 
static pci_subclass_name_t PCI_CLASS01_SUBCLASSES []
 PCI subclasses for Mass Storage Controllers. More...
 
static pci_subclass_name_t PCI_CLASS02_SUBCLASSES []
 PCI subclasses for Network Controllers. More...
 
static pci_subclass_name_t PCI_CLASS03_SUBCLASSES []
 PCI subclasses for Display Controllers. More...
 
static pci_subclass_name_t PCI_CLASS04_SUBCLASSES []
 PCI subclasses for Multimedia devices. More...
 
static pci_subclass_name_t PCI_CLASS06_SUBCLASSES []
 PCI subclasses for Bridge Devices. More...
 
static pci_subclass_name_t PCI_CLASS08_SUBCLASSES []
 PCI subclasses for Base System Peripherals. More...
 
static pci_subclass_name_t PCI_CLASS0C_SUBCLASSES []
 PCI subclasses for Serial Bus Controllers. More...
 
static pci_class_names_t PCI_CLASSES []
 PCI classes. More...
 

Detailed Description

Functions for accessing PCI devices.

Author
Richard Nusser
License
GPLv3 (see http://www.gnu.org/licenses/)
See also
https://github.com/rinusser/UEFIStarter
Todo:
read classes and subclasses from pci.ids

Function Documentation

◆ hexdigita()

static CHAR8 hexdigita ( UINT8  value)
static

internal: converts a hexadecimal value into a printable hex character.

Parameters
valuethe hex value (0-15) to format
Returns
the lowercase hexadecimal character, or '?' if the input was invalid

◆ ui16tohexa()

static void ui16tohexa ( char *  buffer,
UINT16  value 
)
static

internal: converts a UINT16 value to a printable lowercase hex string.

5 bytes of output will be written, starting where buffer points to. The last bytes is a binary zero for string termination.

Parameters
bufferwhere to write the string to (as ascii)
valuethe value to format

◆ find_pci_device_name()

CHAR16* find_pci_device_name ( UINT16  vendor_id,
UINT16  device_id,
UINT16  subvendor_id,
UINT16  subdevice_id 
)

Looks up a PCI device's name by vendor ID and device ID.

Subvendor and subdevice IDs are not implemented yet, they will be ignored.

Parameters
vendor_idthe device's vendor ID
device_idthe device's device ID
subvendor_idignored
subdevice_idignored
Returns
the device's name, as UTF-16; returns "(unknown)" if the requested device wasn't found
Todo:
later: implement sub IDs.

◆ find_pci_class_name()

CHAR16* find_pci_class_name ( UINT8  class_code[3])

Finds a PCI class and subclass name by 3-byte class code.

Parameters
class_codethe PCI class code to look up
Returns
the class name; uses "unknown" to replace unhandled classes or subclasses

◆ describe_pci_device()

void describe_pci_device ( PCI_TYPE00 *  config)

Prints basic information about a PCI device.

Parameters
configthe PCI's TYPE00 header

◆ enumerate_pci_devices()

int enumerate_pci_devices ( )

Assembles the internal list of PCI devices.

Returns
0 on success, -1 on failure.

◆ find_pci_device()

EFI_PCI_IO_PROTOCOL* find_pci_device ( UINT16  vendor_id,
UINT16  device_id 
)

Fetches a PCI device's protocol handle.

This is currently the easiest way to access a specific PCI device.

Parameters
vendor_idthe device's vendor ID
device_idthe device's device ID
Returns
the protocol handle if the device was found, NULL otherwise

◆ print_known_pci_classes()

void print_known_pci_classes ( )

Prints a list of known PCI classes and subclasses.

This is mostly for debugging.

◆ init_pci_lib()

void init_pci_lib ( )

Initializes the PCI library.

Call this before using the other library functions.

◆ shutdown_pci_lib()

void shutdown_pci_lib ( )

Shuts down the PCI library.

Call this when you're done with PCI functions.

Variable Documentation

◆ PCI_CLASS01_SUBCLASSES

pci_subclass_name_t PCI_CLASS01_SUBCLASSES[]
static
Initial value:
={
{0,L"SCSI Controller"},
{1,L"IDE Controller"},
{2,L"Floppy Disk Controller"},
{4,L"RAID Controller"},
{5,L"ATA Controller"},
{6,L"SATA Controller"},
{7,L"SAS Controller"},
{0x80,L"Other"},
{0,NULL}
}

PCI subclasses for Mass Storage Controllers.

◆ PCI_CLASS02_SUBCLASSES

pci_subclass_name_t PCI_CLASS02_SUBCLASSES[]
static
Initial value:
={
{0,L"Ethernet"},
{0,NULL}
}

PCI subclasses for Network Controllers.

◆ PCI_CLASS03_SUBCLASSES

pci_subclass_name_t PCI_CLASS03_SUBCLASSES[]
static
Initial value:
={
{0,L"VGA"},
{1,L"XGA"},
{0x80,L"Other"},
{0,NULL}
}

PCI subclasses for Display Controllers.

◆ PCI_CLASS04_SUBCLASSES

pci_subclass_name_t PCI_CLASS04_SUBCLASSES[]
static
Initial value:
={
{0,L"Video Device"},
{1,L"Audio Device"},
{0,NULL}
}

PCI subclasses for Multimedia devices.

◆ PCI_CLASS06_SUBCLASSES

pci_subclass_name_t PCI_CLASS06_SUBCLASSES[]
static
Initial value:
={
{0,L"Host/PCI"},
{1,L"PCI/ISA"},
{2,L"PCI/EISA"},
{3,L"PCI/Micro Channel"},
{4,L"PCI/PCI"},
{5,L"PCI/PCMCIA"},
{6,L"PCI/NuBus"},
{7,L"PCI/CardBus"},
{0x80,L"Other"},
{0,NULL}
}

PCI subclasses for Bridge Devices.

◆ PCI_CLASS08_SUBCLASSES

pci_subclass_name_t PCI_CLASS08_SUBCLASSES[]
static
Initial value:
={
{0x80,L"Other"},
{0,NULL}
}

PCI subclasses for Base System Peripherals.

◆ PCI_CLASS0C_SUBCLASSES

pci_subclass_name_t PCI_CLASS0C_SUBCLASSES[]
static
Initial value:
={
{0,L"IEEE 1394 Controller (FireWire)"},
{3,L"USB Controller"},
{0,NULL}
}

PCI subclasses for Serial Bus Controllers.

◆ PCI_CLASSES

pci_class_names_t PCI_CLASSES[]
static
Initial value:
={
{1,L"Mass Storage Controller",PCI_CLASS01_SUBCLASSES},
{2,L"Network Controller",PCI_CLASS02_SUBCLASSES},
{3,L"Display Controller",PCI_CLASS03_SUBCLASSES},
{4,L"Multimedia",PCI_CLASS04_SUBCLASSES},
{6,L"Bridge Device",PCI_CLASS06_SUBCLASSES},
{8,L"Base System Peripheral",PCI_CLASS08_SUBCLASSES},
{0xc,L"Serial Bus Controller",PCI_CLASS0C_SUBCLASSES},
{0,NULL,NULL}
}
static pci_subclass_name_t PCI_CLASS04_SUBCLASSES[]
PCI subclasses for Multimedia devices.
Definition: pci.c:61
static pci_subclass_name_t PCI_CLASS06_SUBCLASSES[]
PCI subclasses for Bridge Devices.
Definition: pci.c:68
static pci_subclass_name_t PCI_CLASS01_SUBCLASSES[]
PCI subclasses for Mass Storage Controllers.
Definition: pci.c:34
static pci_subclass_name_t PCI_CLASS08_SUBCLASSES[]
PCI subclasses for Base System Peripherals.
Definition: pci.c:82
static pci_subclass_name_t PCI_CLASS03_SUBCLASSES[]
PCI subclasses for Display Controllers.
Definition: pci.c:53
static pci_subclass_name_t PCI_CLASS0C_SUBCLASSES[]
PCI subclasses for Serial Bus Controllers.
Definition: pci.c:88
static pci_subclass_name_t PCI_CLASS02_SUBCLASSES[]
PCI subclasses for Network Controllers.
Definition: pci.c:47

PCI classes.