1 /* Simplistic PCI support.
3 Copyright (C) 2011 Richard Henderson
5 This file is part of QEMU PALcode.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the text
15 of the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* This header is intended to be compatible with the pci.h from SeaBIOS.
22 Their header, however, is too PC specific to be of use. */
27 extern void *pci_conf_base;
29 static inline void pci_config_writel(int bdf, uint8_t addr, uint32_t val)
31 *(volatile uint32_t *)(pci_conf_base + bdf * 256 + addr) = val;
34 static inline void pci_config_writew(int bdf, uint8_t addr, uint16_t val)
36 *(volatile uint16_t *)(pci_conf_base + bdf * 256 + addr) = val;
39 static inline void pci_config_writeb(int bdf, uint8_t addr, uint8_t val)
41 *(volatile uint8_t *)(pci_conf_base + bdf * 256 + addr) = val;
44 static inline uint32_t pci_config_readl(int bdf, uint8_t addr)
46 return *(volatile uint32_t *)(pci_conf_base + bdf * 256 + addr);
49 static inline uint16_t pci_config_readw(int bdf, uint8_t addr)
51 return *(volatile uint16_t *)(pci_conf_base + bdf * 256 + addr);
54 static inline uint8_t pci_config_readb(int bdf, uint8_t addr)
56 return *(volatile uint8_t *)(pci_conf_base + bdf * 256 + addr);
59 extern void pci_config_maskw(int bdf, int addr, uint16_t off, uint16_t on);
61 extern int pci_next(int bdf, int *pmax);
63 #define foreachpci(BDF, MAX) \
64 for (MAX = 0x0100, BDF = pci_next(0, &MAX); \
66 BDF = pci_next(BDF+1, &MAX))