2 * This file is part of the coreboot project.
4 * Copyright (C) 2016 Google Inc
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
18 #include "pci-userspace.h"
22 static struct pci_access
*pacc
;
24 int pci_initialize(void)
32 for (dev
= pacc
->devices
; dev
; dev
= dev
->next
) {
33 pci_fill_info(dev
, PCI_FILL_IDENT
| PCI_FILL_BASES
);
44 u8
pci_read_config8(struct device
*dev
, unsigned int where
)
47 if ((d
= pci_get_dev(pacc
, 0, dev
->busno
, dev
->slot
, dev
->func
)))
48 return pci_read_byte(d
, where
);
50 printf("PCI: device not found while read byte (%x:%x.%x)\n",
51 dev
->busno
, dev
->slot
, dev
->func
);
56 u16
pci_read_config16(struct device
*dev
, unsigned int where
)
59 if ((d
= pci_get_dev(pacc
, 0, dev
->busno
, dev
->slot
, dev
->func
)))
60 return pci_read_word(d
, where
);
62 printf("PCI: device not found while read word (%x:%x.%x)\n",
63 dev
->busno
, dev
->slot
, dev
->func
);
68 u32
pci_read_config32(struct device
*dev
, unsigned int where
)
71 if ((d
= pci_get_dev(pacc
, 0, dev
->busno
, dev
->slot
, dev
->func
)))
72 return pci_read_long(d
, where
);
74 printf("PCI: device not found while read dword (%x:%x.%x)\n",
75 dev
->busno
, dev
->slot
, dev
->func
);
80 void pci_write_config8(struct device
*dev
, unsigned int where
, u8 val
)
83 if ((d
= pci_get_dev(pacc
, 0, dev
->busno
, dev
->slot
, dev
->func
)))
84 pci_write_byte(d
, where
, val
);
87 printf("PCI: device not found while write byte (%x:%x.%x)\n",
88 dev
->busno
, dev
->slot
, dev
->func
);
92 void pci_write_config16(struct device
*dev
, unsigned int where
, u16 val
)
95 if ((d
= pci_get_dev(pacc
, 0, dev
->busno
, dev
->slot
, dev
->func
)))
96 pci_write_word(d
, where
, val
);
99 printf("PCI: device not found while write word (%x:%x.%x)\n",
100 dev
->busno
, dev
->slot
, dev
->func
);
104 void pci_write_config32(struct device
*dev
, unsigned int where
, u32 val
)
107 if ((d
= pci_get_dev(pacc
, 0, dev
->busno
, dev
->slot
, dev
->func
)))
108 pci_write_long(d
, where
, val
);
111 printf("PCI: device not found while write dword (%x:%x.%x)\n",
112 dev
->busno
, dev
->slot
, dev
->func
);