blob: 2518f2002d776a15eedac1f478e1d9cc308668d4 [file] [log] [blame]
Eric Biederman5899fd82003-04-24 06:25:08 +00001#ifndef PCI_OPS_H
2#define PCI_OPS_H
3
4#include <stdint.h>
Eric Biederman7a5416a2003-06-12 19:23:51 +00005#include <device/device.h>
Eric Biederman018d8dd2004-11-04 11:04:33 +00006#include <arch/pci_ops.h>
Eric Biederman5899fd82003-04-24 06:25:08 +00007
Kyösti Mälkkief844012013-06-25 23:17:43 +03008#ifndef __SIMPLE_DEVICE__
Edward O'Callaghan016732f2014-10-29 03:04:40 +11009u8 pci_read_config8(struct device *dev, unsigned int where);
10u16 pci_read_config16(struct device *dev, unsigned int where);
11u32 pci_read_config32(struct device *dev, unsigned int where);
12void pci_write_config8(struct device *dev, unsigned int where, u8 val);
13void pci_write_config16(struct device *dev, unsigned int where, u16 val);
14void pci_write_config32(struct device *dev, unsigned int where, u32 val);
Eric Biederman7a5416a2003-06-12 19:23:51 +000015
Stefan Reinauer24d1d4b2013-03-21 11:51:41 -070016#endif
Stefan Reinauer43b29cf2009-03-06 19:11:52 +000017
Patrick Rudolphe56189c2018-04-18 10:11:59 +020018/*
19 * Use device_t here as the functions are to be used with either
20 * __SIMPLE_DEVICE__ defined or undefined.
21 */
22static inline __attribute__((always_inline))
23void pci_or_config8(device_t dev, unsigned int where, u8 ormask)
24{
25 u8 value = pci_read_config8(dev, where);
26 pci_write_config8(dev, where, value | ormask);
27}
28
29static inline __attribute__((always_inline))
30void pci_or_config16(device_t dev, unsigned int where, u16 ormask)
31{
32 u16 value = pci_read_config16(dev, where);
33 pci_write_config16(dev, where, value | ormask);
34}
35
36static inline __attribute__((always_inline))
37void pci_or_config32(device_t dev, unsigned int where, u32 ormask)
38{
39 u32 value = pci_read_config32(dev, where);
40 pci_write_config32(dev, where, value | ormask);
41}
42
43static inline __attribute__((always_inline))
44void pci_update_config8(device_t dev, int reg, u8 mask, u8 or)
45{
46 u8 reg8;
47
48 reg8 = pci_read_config8(dev, reg);
49 reg8 &= mask;
50 reg8 |= or;
51 pci_write_config8(dev, reg, reg8);
52}
53
54static inline __attribute__((always_inline))
55void pci_update_config16(device_t dev, int reg, u16 mask, u16 or)
56{
57 u16 reg16;
58
59 reg16 = pci_read_config16(dev, reg);
60 reg16 &= mask;
61 reg16 |= or;
62 pci_write_config16(dev, reg, reg16);
63}
64
65static inline __attribute__((always_inline))
66void pci_update_config32(device_t dev, int reg, u32 mask, u32 or)
67{
68 u32 reg32;
69
70 reg32 = pci_read_config32(dev, reg);
71 reg32 &= mask;
72 reg32 |= or;
73 pci_write_config32(dev, reg, reg32);
74}
75
Patrick Rudolphf5180a92018-04-18 10:31:19 +020076const struct pci_bus_operations *pci_bus_default_ops(struct device *dev);
77
Eric Biederman5899fd82003-04-24 06:25:08 +000078#endif /* PCI_OPS_H */