Skip to content

Commit 3250625

Browse files
lipengfei28xiaoxiang781216
authored andcommitted
pci: add find device from bus
Signed-off-by: lipengfei28 <[email protected]>
1 parent 9dc9500 commit 3250625

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

drivers/pci/pci.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,34 @@ static struct list_node g_pci_ctrl_list =
129129
* Private Functions
130130
****************************************************************************/
131131

132+
static FAR struct pci_device_s *
133+
pci_do_find_device_from_bus(FAR struct pci_bus_s *bus, uint8_t busno,
134+
unsigned int devfn)
135+
{
136+
FAR struct pci_bus_s *bus_tmp;
137+
FAR struct pci_device_s *dev;
138+
139+
list_for_every_entry(&bus->devices, dev, struct pci_device_s, node)
140+
{
141+
if (dev->bus->number == busno && devfn == dev->devfn)
142+
{
143+
return dev;
144+
}
145+
}
146+
147+
list_for_every_entry(&bus->children, bus_tmp,
148+
struct pci_bus_s, node)
149+
{
150+
dev = pci_find_device_from_bus(bus_tmp, busno, devfn);
151+
if (dev != NULL)
152+
{
153+
return dev;
154+
}
155+
}
156+
157+
return NULL;
158+
}
159+
132160
/****************************************************************************
133161
* Name: pci_change_master
134162
*
@@ -782,6 +810,41 @@ static void pci_scan_bus(FAR struct pci_bus_s *bus)
782810
* Public Functions
783811
****************************************************************************/
784812

813+
/****************************************************************************
814+
* Name: pci_find_device_from_bus
815+
*
816+
* Description:
817+
* To find a PCI device from the bus
818+
*
819+
* Input Parameters:
820+
* bus - pci bus
821+
* busno - bus number
822+
* devfn - device number and function number
823+
*
824+
* Returned Value:
825+
* Failed if return NULL, otherwise return pci devices
826+
*
827+
****************************************************************************/
828+
829+
FAR struct pci_device_s *
830+
pci_find_device_from_bus(FAR struct pci_bus_s *bus, uint8_t busno,
831+
unsigned int devfn)
832+
{
833+
FAR struct pci_device_s *dev;
834+
int ret;
835+
836+
ret = nxmutex_lock(&g_pci_lock);
837+
if (ret < 0)
838+
{
839+
return NULL;
840+
}
841+
842+
dev = pci_do_find_device_from_bus(bus, busno, devfn);
843+
nxmutex_unlock(&g_pci_lock);
844+
845+
return dev;
846+
}
847+
785848
/****************************************************************************
786849
* Name: pci_bus_read_config
787850
*

include/nuttx/pci/pci.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,26 @@ int pci_bus_write_config_word(FAR struct pci_bus_s *bus, unsigned int devfn,
742742
int pci_bus_write_config_dword(FAR struct pci_bus_s *bus, unsigned int devfn,
743743
int where, uint32_t val);
744744

745+
/****************************************************************************
746+
* Name: pci_find_device_from_bus
747+
*
748+
* Description:
749+
* To find a PCI device from the bus
750+
*
751+
* Input Parameters:
752+
* bus - pci bus
753+
* busno - bus number
754+
* devfn - device number and function number
755+
*
756+
* Returned Value:
757+
* Failed if return NULL, otherwise return pci devices
758+
*
759+
****************************************************************************/
760+
761+
FAR struct pci_device_s *
762+
pci_find_device_from_bus(FAR struct pci_bus_s *bus, uint8_t busno,
763+
unsigned int devfn);
764+
745765
/****************************************************************************
746766
* Name: pci_register_drivers
747767
*

0 commit comments

Comments
 (0)