Skip to content

Commit c25f839

Browse files
lipengfei28xiaoxiang781216
authored andcommitted
pci: add pci bus find capability interface
Signed-off-by: lipengfei28 <[email protected]>
1 parent 45f1597 commit c25f839

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

drivers/pci/pci.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,42 @@ int pci_register_controller(FAR struct pci_controller_s *ctrl)
13111311
return 0;
13121312
}
13131313

1314+
/****************************************************************************
1315+
* Name: pci_bus_find_capability
1316+
*
1317+
* Description:
1318+
* Query for devices' capabilities
1319+
*
1320+
* Tell if a device supports a given PCI capability.
1321+
*
1322+
* Input Parameters:
1323+
* bus - PCI device bus belong to
1324+
* devfn - PCI device number and function number
1325+
* cap - Capability code
1326+
*
1327+
* Returned Value:
1328+
* Returns the address of the requested capability structure within the
1329+
* device's PCI configuration space or 0 in case the device does not
1330+
* support it.
1331+
*
1332+
****************************************************************************/
1333+
1334+
uint8_t pci_bus_find_capability(FAR struct pci_bus_s *bus,
1335+
unsigned int devfn, int cap)
1336+
{
1337+
uint8_t type = 0;
1338+
uint8_t pos;
1339+
1340+
pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &type);
1341+
pos = pci_bus_find_start_cap(bus, devfn, type);
1342+
if (pos)
1343+
{
1344+
pos = pci_find_next_cap(bus, devfn, pos, cap);
1345+
}
1346+
1347+
return pos;
1348+
}
1349+
13141350
PCI_BUS_READ_CONFIG(byte, uint8_t, 1)
13151351
PCI_BUS_READ_CONFIG(word, uint16_t, 2)
13161352
PCI_BUS_READ_CONFIG(dword, uint32_t, 4)

include/nuttx/pci/pci.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,29 @@ int pci_unregister_device(FAR struct pci_device_s *dev);
599599

600600
int pci_register_controller(FAR struct pci_controller_s *ctrl);
601601

602+
/****************************************************************************
603+
* Name: pci_bus_find_capability
604+
*
605+
* Description:
606+
* Query for devices' capabilities
607+
*
608+
* Tell if a device supports a given PCI capability.
609+
*
610+
* Input Parameters:
611+
* bus - PCI device bus belong to
612+
* devfn - PCI device number and function number
613+
* cap - Capability code
614+
*
615+
* Returned Value:
616+
* Returns the address of the requested capability structure within the
617+
* device's PCI configuration space or 0 in case the device does not
618+
* support it.
619+
*
620+
****************************************************************************/
621+
622+
uint8_t pci_bus_find_capability(FAR struct pci_bus_s *bus,
623+
unsigned int devfn, int cap);
624+
602625
/****************************************************************************
603626
* Name: pci_bus_read_config_byte
604627
*

0 commit comments

Comments
 (0)