Skip to content

Commit 45f1597

Browse files
lipengfei28xiaoxiang781216
authored andcommitted
pci: add pci read/write config/io space interface
Signed-off-by: lipengfei28 <[email protected]>
1 parent d9c8838 commit 45f1597

File tree

2 files changed

+205
-5
lines changed

2 files changed

+205
-5
lines changed

drivers/pci/pci.c

Lines changed: 121 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
\
5454
if (!PCI_##len##_BAD) \
5555
{ \
56-
ret = bus->ctrl->ops->read(bus, devfn, where, size, &data); \
56+
ret = pci_bus_read_config(bus, devfn, where, size, &data); \
5757
} \
5858
\
5959
*value = (type)data; \
@@ -68,7 +68,7 @@
6868
\
6969
if (!PCI_##len##_BAD) \
7070
{ \
71-
ret = bus->ctrl->ops->write(bus, devfn, where, size, value); \
71+
ret = pci_bus_write_config(bus, devfn, where, size, value); \
7272
} \
7373
\
7474
return ret; \
@@ -83,7 +83,7 @@
8383
\
8484
if (!PCI_##len##_BAD) \
8585
{ \
86-
ret = bus->ctrl->ops->read_io(bus, where, size, &data); \
86+
ret = pci_bus_read_io(bus, where, size, &data); \
8787
} \
8888
\
8989
*value = (type)data; \
@@ -98,7 +98,7 @@
9898
\
9999
if (!PCI_##len##_BAD) \
100100
{ \
101-
ret = bus->ctrl->ops->write_io(bus, where, size, value); \
101+
ret = pci_bus_write_io(bus, where, size, value); \
102102
} \
103103
\
104104
return ret; \
@@ -782,6 +782,122 @@ static void pci_scan_bus(FAR struct pci_bus_s *bus)
782782
* Public Functions
783783
****************************************************************************/
784784

785+
/****************************************************************************
786+
* Name: pci_bus_read_config
787+
*
788+
* Description:
789+
* Read pci device config space
790+
*
791+
* Input Parameters:
792+
* bus - The PCI device belong to
793+
* devfn - The PCI device dev number and function number
794+
* where - The register address
795+
* size - The data length
796+
* val - The data buffer
797+
*
798+
* Returned Value:
799+
* Zero if success, otherwise nagative
800+
*
801+
****************************************************************************/
802+
803+
int pci_bus_read_config(FAR struct pci_bus_s *bus,
804+
unsigned int devfn, int where,
805+
int size, FAR uint32_t *val)
806+
{
807+
if (size != 1 && size != 2 && size != 4)
808+
{
809+
return -EINVAL;
810+
}
811+
812+
return bus->ctrl->ops->read(bus, devfn, where, size, val);
813+
}
814+
815+
/****************************************************************************
816+
* Name: pci_bus_write_config
817+
*
818+
* Description:
819+
* Read pci device config space
820+
*
821+
* Input Parameters:
822+
* bus - The PCI device belong to
823+
* devfn - The PCI device dev number and function number
824+
* where - The register address
825+
* size - The data length
826+
* val - The data
827+
*
828+
* Returned Value:
829+
* Zero if success, otherwise nagative
830+
*
831+
****************************************************************************/
832+
833+
int pci_bus_write_config(FAR struct pci_bus_s *bus,
834+
unsigned int devfn, int where,
835+
int size, uint32_t val)
836+
{
837+
if (size != 1 && size != 2 && size != 4)
838+
{
839+
return -EINVAL;
840+
}
841+
842+
return bus->ctrl->ops->write(bus, devfn, where, size, val);
843+
}
844+
845+
/****************************************************************************
846+
* Name: pci_bus_read_io
847+
*
848+
* Description:
849+
* Read pci device io space
850+
*
851+
* Input Parameters:
852+
* bus - The PCI device belong to
853+
* addr - The address to read
854+
* size - The data length
855+
* val - The data buffer
856+
*
857+
* Returned Value:
858+
* Zero if success, otherwise nagative
859+
*
860+
****************************************************************************/
861+
862+
int pci_bus_read_io(FAR struct pci_bus_s *bus, uintptr_t addr,
863+
int size, FAR uint32_t *val)
864+
{
865+
if (size != 1 && size != 2 && size != 4)
866+
{
867+
return -EINVAL;
868+
}
869+
870+
return bus->ctrl->ops->read_io(bus, addr, size, val);
871+
}
872+
873+
/****************************************************************************
874+
* Name: pci_bus_write_io
875+
*
876+
* Description:
877+
* Read pci device io space
878+
*
879+
* Input Parameters:
880+
* bus - The PCI device belong to
881+
* addr - The address to write
882+
* size - The data length
883+
* val - The data
884+
*
885+
* Returned Value:
886+
* Zero if success, otherwise nagative
887+
*
888+
****************************************************************************/
889+
890+
int pci_bus_write_io(FAR struct pci_bus_s *bus, uintptr_t addr,
891+
int size, uint32_t val)
892+
{
893+
if (size != 1 && size != 2 && size != 4)
894+
{
895+
return -EINVAL;
896+
}
897+
898+
return bus->ctrl->ops->write_io(bus, addr, size, val);
899+
}
900+
785901
/****************************************************************************
786902
* Name: pci_set_master
787903
*
@@ -1206,4 +1322,4 @@ PCI_BUS_READ_IO(word, uint16_t, 2)
12061322
PCI_BUS_READ_IO(dword, uint32_t, 4)
12071323
PCI_BUS_WRITE_IO(byte, uint8_t, 1)
12081324
PCI_BUS_WRITE_IO(word, uint16_t, 2)
1209-
PCI_BUS_WRITE_IO(dword, uint32_t, 4)
1325+
PCI_BUS_WRITE_IO(dword, uint32_t, 4)

include/nuttx/pci/pci.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,90 @@ struct pci_driver_s
302302
* Public Function Prototypes
303303
****************************************************************************/
304304

305+
/****************************************************************************
306+
* Name: pci_bus_read_config
307+
*
308+
* Description:
309+
* read pci device config space
310+
*
311+
* Input Parameters:
312+
* bus - The PCI device to belong to
313+
* devfn - The PCI device number and function number
314+
* where - The register address
315+
* size - The length data
316+
* val - The data buf
317+
*
318+
* Returned Value:
319+
* Zero if success, otherwise nagative
320+
*
321+
****************************************************************************/
322+
323+
int pci_bus_read_config(FAR struct pci_bus_s *bus,
324+
unsigned int devfn, int where,
325+
int size, FAR uint32_t *val);
326+
327+
/****************************************************************************
328+
* Name: pci_bus_write_config
329+
*
330+
* Description:
331+
* read pci device config space
332+
*
333+
* Input Parameters:
334+
* bus - The PCI device to belong to
335+
* devfn - The PCI device number and function number
336+
* where - The register address
337+
* size - The length data
338+
* val - The data
339+
*
340+
* Returned Value:
341+
* Zero if success, otherwise nagative
342+
*
343+
****************************************************************************/
344+
345+
int pci_bus_write_config(FAR struct pci_bus_s *bus,
346+
unsigned int devfn, int where,
347+
int size, uint32_t val);
348+
349+
/****************************************************************************
350+
* Name: pci_bus_read_io
351+
*
352+
* Description:
353+
* Read pci device io space
354+
*
355+
* Input Parameters:
356+
* bus - The PCI device belong to
357+
* addr - The address to read
358+
* size - The data length
359+
* val - The data buffer
360+
*
361+
* Returned Value:
362+
* Zero if success, otherwise nagative
363+
*
364+
****************************************************************************/
365+
366+
int pci_bus_read_io(FAR struct pci_bus_s *bus, uintptr_t addr,
367+
int size, FAR uint32_t *val);
368+
369+
/****************************************************************************
370+
* Name: pci_bus_write_io
371+
*
372+
* Description:
373+
* Read pci device io space
374+
*
375+
* Input Parameters:
376+
* bus - The PCI device belong to
377+
* addr - The address to write
378+
* size - The data length
379+
* val - The data
380+
*
381+
* Returned Value:
382+
* Zero if success, otherwise nagative
383+
*
384+
****************************************************************************/
385+
386+
int pci_bus_write_io(FAR struct pci_bus_s *bus, uintptr_t addr,
387+
int size, uint32_t val);
388+
305389
/****************************************************************************
306390
* Name: pci_set_master
307391
*

0 commit comments

Comments
 (0)