Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 1 | #ifndef PCI_OPS_H |
| 2 | #define PCI_OPS_H |
| 3 | |
| 4 | #include <stdint.h> |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 5 | #include <device/device.h> |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 6 | #include <arch/pci_ops.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 7 | |
Kyösti Mälkki | ef84401 | 2013-06-25 23:17:43 +0300 | [diff] [blame] | 8 | #ifndef __SIMPLE_DEVICE__ |
Edward O'Callaghan | 016732f | 2014-10-29 03:04:40 +1100 | [diff] [blame] | 9 | u8 pci_read_config8(struct device *dev, unsigned int where); |
| 10 | u16 pci_read_config16(struct device *dev, unsigned int where); |
| 11 | u32 pci_read_config32(struct device *dev, unsigned int where); |
| 12 | void pci_write_config8(struct device *dev, unsigned int where, u8 val); |
| 13 | void pci_write_config16(struct device *dev, unsigned int where, u16 val); |
| 14 | void pci_write_config32(struct device *dev, unsigned int where, u32 val); |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 15 | |
Stefan Reinauer | 24d1d4b | 2013-03-21 11:51:41 -0700 | [diff] [blame] | 16 | #endif |
Stefan Reinauer | 43b29cf | 2009-03-06 19:11:52 +0000 | [diff] [blame] | 17 | |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 18 | /* |
| 19 | * Use device_t here as the functions are to be used with either |
| 20 | * __SIMPLE_DEVICE__ defined or undefined. |
| 21 | */ |
| 22 | static inline __attribute__((always_inline)) |
| 23 | void 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 | |
| 29 | static inline __attribute__((always_inline)) |
| 30 | void 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 | |
| 36 | static inline __attribute__((always_inline)) |
| 37 | void 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 | |
| 43 | static inline __attribute__((always_inline)) |
| 44 | void 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 | |
| 54 | static inline __attribute__((always_inline)) |
| 55 | void 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 | |
| 65 | static inline __attribute__((always_inline)) |
| 66 | void 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 Rudolph | f5180a9 | 2018-04-18 10:31:19 +0200 | [diff] [blame] | 76 | const struct pci_bus_operations *pci_bus_default_ops(struct device *dev); |
| 77 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 78 | #endif /* PCI_OPS_H */ |