1 /* SPDX-License-Identifier: GPL-2.0-only */
5 #include "pci-userspace.h"
9 static struct pci_access
*pacc
;
11 int pci_initialize(void)
19 for (dev
= pacc
->devices
; dev
; dev
= dev
->next
) {
20 pci_fill_info(dev
, PCI_FILL_IDENT
| PCI_FILL_BASES
);
31 u8
pci_read_config8(struct device
*dev
, unsigned int where
)
34 if ((d
= pci_get_dev(pacc
, 0, dev
->busno
, dev
->slot
, dev
->func
)))
35 return pci_read_byte(d
, where
);
37 printf("PCI: device not found while read byte (%x:%x.%x)\n",
38 dev
->busno
, dev
->slot
, dev
->func
);
43 u16
pci_read_config16(struct device
*dev
, unsigned int where
)
46 if ((d
= pci_get_dev(pacc
, 0, dev
->busno
, dev
->slot
, dev
->func
)))
47 return pci_read_word(d
, where
);
49 printf("PCI: device not found while read word (%x:%x.%x)\n",
50 dev
->busno
, dev
->slot
, dev
->func
);
55 u32
pci_read_config32(struct device
*dev
, unsigned int where
)
58 if ((d
= pci_get_dev(pacc
, 0, dev
->busno
, dev
->slot
, dev
->func
)))
59 return pci_read_long(d
, where
);
61 printf("PCI: device not found while read dword (%x:%x.%x)\n",
62 dev
->busno
, dev
->slot
, dev
->func
);
67 void pci_write_config8(struct device
*dev
, unsigned int where
, u8 val
)
70 if ((d
= pci_get_dev(pacc
, 0, dev
->busno
, dev
->slot
, dev
->func
)))
71 pci_write_byte(d
, where
, val
);
74 printf("PCI: device not found while write byte (%x:%x.%x)\n",
75 dev
->busno
, dev
->slot
, dev
->func
);
79 void pci_write_config16(struct device
*dev
, unsigned int where
, u16 val
)
82 if ((d
= pci_get_dev(pacc
, 0, dev
->busno
, dev
->slot
, dev
->func
)))
83 pci_write_word(d
, where
, val
);
86 printf("PCI: device not found while write word (%x:%x.%x)\n",
87 dev
->busno
, dev
->slot
, dev
->func
);
91 void pci_write_config32(struct device
*dev
, unsigned int where
, u32 val
)
94 if ((d
= pci_get_dev(pacc
, 0, dev
->busno
, dev
->slot
, dev
->func
)))
95 pci_write_long(d
, where
, val
);
98 printf("PCI: device not found while write dword (%x:%x.%x)\n",
99 dev
->busno
, dev
->slot
, dev
->func
);