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 | 92b5296 | 2019-03-01 08:08:28 +0200 | [diff] [blame^] | 8 | #ifdef __SIMPLE_DEVICE__ |
| 9 | |
| 10 | /* Avoid name collisions as different stages have different signature |
| 11 | * for these functions. The _s_ stands for simple, fundamental IO or |
| 12 | * MMIO variant. |
| 13 | */ |
| 14 | #define pci_read_config8 pci_s_read_config8 |
| 15 | #define pci_read_config16 pci_s_read_config16 |
| 16 | #define pci_read_config32 pci_s_read_config32 |
| 17 | #define pci_write_config8 pci_s_write_config8 |
| 18 | #define pci_write_config16 pci_s_write_config16 |
| 19 | #define pci_write_config32 pci_s_write_config32 |
| 20 | #else |
Edward O'Callaghan | 016732f | 2014-10-29 03:04:40 +1100 | [diff] [blame] | 21 | u8 pci_read_config8(struct device *dev, unsigned int where); |
| 22 | u16 pci_read_config16(struct device *dev, unsigned int where); |
| 23 | u32 pci_read_config32(struct device *dev, unsigned int where); |
| 24 | void pci_write_config8(struct device *dev, unsigned int where, u8 val); |
| 25 | void pci_write_config16(struct device *dev, unsigned int where, u16 val); |
| 26 | void pci_write_config32(struct device *dev, unsigned int where, u32 val); |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 27 | const struct pci_bus_operations *pci_bus_default_ops(struct device *dev); |
Stefan Reinauer | 24d1d4b | 2013-03-21 11:51:41 -0700 | [diff] [blame] | 28 | #endif |
Stefan Reinauer | 43b29cf | 2009-03-06 19:11:52 +0000 | [diff] [blame] | 29 | |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 30 | #ifdef __SIMPLE_DEVICE__ |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 31 | static __always_inline |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 32 | void pci_or_config8(pci_devfn_t dev, unsigned int where, u8 ormask) |
| 33 | #else |
| 34 | static __always_inline |
| 35 | void pci_or_config8(struct device *dev, unsigned int where, u8 ormask) |
| 36 | #endif |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 37 | { |
| 38 | u8 value = pci_read_config8(dev, where); |
| 39 | pci_write_config8(dev, where, value | ormask); |
| 40 | } |
| 41 | |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 42 | #ifdef __SIMPLE_DEVICE__ |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 43 | static __always_inline |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 44 | void pci_or_config16(pci_devfn_t dev, unsigned int where, u16 ormask) |
| 45 | #else |
| 46 | static __always_inline |
| 47 | void pci_or_config16(struct device *dev, unsigned int where, u16 ormask) |
| 48 | #endif |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 49 | { |
| 50 | u16 value = pci_read_config16(dev, where); |
| 51 | pci_write_config16(dev, where, value | ormask); |
| 52 | } |
| 53 | |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 54 | #ifdef __SIMPLE_DEVICE__ |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 55 | static __always_inline |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 56 | void pci_or_config32(pci_devfn_t dev, unsigned int where, u32 ormask) |
| 57 | #else |
| 58 | static __always_inline |
| 59 | void pci_or_config32(struct device *dev, unsigned int where, u32 ormask) |
| 60 | #endif |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 61 | { |
| 62 | u32 value = pci_read_config32(dev, where); |
| 63 | pci_write_config32(dev, where, value | ormask); |
| 64 | } |
| 65 | |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 66 | #ifdef __SIMPLE_DEVICE__ |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 67 | static __always_inline |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 68 | void pci_update_config8(pci_devfn_t dev, int reg, u8 mask, u8 or) |
| 69 | #else |
| 70 | static __always_inline |
| 71 | void pci_update_config8(struct device *dev, int reg, u8 mask, u8 or) |
| 72 | #endif |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 73 | { |
| 74 | u8 reg8; |
| 75 | |
| 76 | reg8 = pci_read_config8(dev, reg); |
| 77 | reg8 &= mask; |
| 78 | reg8 |= or; |
| 79 | pci_write_config8(dev, reg, reg8); |
| 80 | } |
| 81 | |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 82 | #ifdef __SIMPLE_DEVICE__ |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 83 | static __always_inline |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 84 | void pci_update_config16(pci_devfn_t dev, int reg, u16 mask, u16 or) |
| 85 | #else |
| 86 | static __always_inline |
| 87 | void pci_update_config16(struct device *dev, int reg, u16 mask, u16 or) |
| 88 | #endif |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 89 | { |
| 90 | u16 reg16; |
| 91 | |
| 92 | reg16 = pci_read_config16(dev, reg); |
| 93 | reg16 &= mask; |
| 94 | reg16 |= or; |
| 95 | pci_write_config16(dev, reg, reg16); |
| 96 | } |
| 97 | |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 98 | #ifdef __SIMPLE_DEVICE__ |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 99 | static __always_inline |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 100 | void pci_update_config32(pci_devfn_t dev, int reg, u32 mask, u32 or) |
| 101 | #else |
| 102 | static __always_inline |
| 103 | void pci_update_config32(struct device *dev, int reg, u32 mask, u32 or) |
| 104 | #endif |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 105 | { |
| 106 | u32 reg32; |
| 107 | |
| 108 | reg32 = pci_read_config32(dev, reg); |
| 109 | reg32 &= mask; |
| 110 | reg32 |= or; |
| 111 | pci_write_config32(dev, reg, reg32); |
| 112 | } |
| 113 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 114 | #endif /* PCI_OPS_H */ |