Simon Glass | 2ee1f6a | 2019-12-06 21:41:55 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Copyright 2019 Google LLC |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | */ |
| 6 | |
| 7 | #ifndef __p2sb_h |
| 8 | #define __p2sb_h |
| 9 | |
| 10 | /* Port Id lives in bits 23:16 and register offset lives in 15:0 of address */ |
| 11 | #define PCR_PORTID_SHIFT 16 |
| 12 | |
Simon Glass | 7aaa140 | 2020-09-22 12:45:18 -0600 | [diff] [blame] | 13 | #if !defined(__ACPI__) |
| 14 | |
| 15 | /* These registers contain IOAPIC and HPET devfn */ |
| 16 | #define PCH_P2SB_IBDF 0x6c |
| 17 | #define PCH_P2SB_HBDF 0x70 |
| 18 | |
Simon Glass | 2ee1f6a | 2019-12-06 21:41:55 -0700 | [diff] [blame] | 19 | /** |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 20 | * struct p2sb_child_plat - Information about each child of a p2sb device |
Simon Glass | 2ee1f6a | 2019-12-06 21:41:55 -0700 | [diff] [blame] | 21 | * |
| 22 | * @pid: Port ID for this child |
| 23 | */ |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 24 | struct p2sb_child_plat { |
Simon Glass | 2ee1f6a | 2019-12-06 21:41:55 -0700 | [diff] [blame] | 25 | uint pid; |
| 26 | }; |
| 27 | |
| 28 | /** |
| 29 | * struct p2sb_uc_priv - information for the uclass about each device |
| 30 | * |
| 31 | * This must be set up by the driver when it is probed |
| 32 | * |
| 33 | * @mmio_base: Base address of P2SB region |
| 34 | */ |
| 35 | struct p2sb_uc_priv { |
| 36 | uint mmio_base; |
| 37 | }; |
| 38 | |
| 39 | /** |
Simon Glass | 5e13b0f | 2020-07-07 21:32:30 -0600 | [diff] [blame] | 40 | * struct p2sb_ops - Operations for the P2SB |
Simon Glass | 2ee1f6a | 2019-12-06 21:41:55 -0700 | [diff] [blame] | 41 | */ |
| 42 | struct p2sb_ops { |
Simon Glass | 5e13b0f | 2020-07-07 21:32:30 -0600 | [diff] [blame] | 43 | /** |
| 44 | * set_hide() - Set/clear the 'hide' bit on the p2sb |
| 45 | * |
| 46 | * This device can be hidden from the PCI bus if needed. This method |
| 47 | * can be called before the p2sb is probed. |
| 48 | * |
| 49 | * @dev: P2SB device |
| 50 | * @hide: true to hide the device, false to show it |
| 51 | * @return 0 if OK, -ve on error |
| 52 | */ |
| 53 | int (*set_hide)(struct udevice *dev, bool hide); |
Simon Glass | 2ee1f6a | 2019-12-06 21:41:55 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | #define p2sb_get_ops(dev) ((struct p2sb_ops *)(dev)->driver->ops) |
| 57 | |
| 58 | /** |
Simon Glass | 5e13b0f | 2020-07-07 21:32:30 -0600 | [diff] [blame] | 59 | * p2sb_set_hide() - Set/clear the 'hide' bit on the p2sb |
| 60 | * |
| 61 | * This device can be hidden from the PCI bus if needed. This method |
| 62 | * can be called before the p2sb is probed. |
| 63 | * |
| 64 | * @dev: P2SB device |
| 65 | * @hide: true to hide the device, false to show it |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 66 | * Return: 0 if OK, -ve on error |
Simon Glass | 5e13b0f | 2020-07-07 21:32:30 -0600 | [diff] [blame] | 67 | */ |
| 68 | int p2sb_set_hide(struct udevice *dev, bool hide); |
| 69 | |
| 70 | /** |
Simon Glass | 2ee1f6a | 2019-12-06 21:41:55 -0700 | [diff] [blame] | 71 | * pcr_read32/16/8() - Read from a PCR device |
| 72 | * |
| 73 | * Reads data from a PCR device within the P2SB |
| 74 | * |
| 75 | * @dev: Device to read from |
| 76 | * @offset: Offset within device to read |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 77 | * Return: value read |
Simon Glass | 2ee1f6a | 2019-12-06 21:41:55 -0700 | [diff] [blame] | 78 | */ |
| 79 | uint pcr_read32(struct udevice *dev, uint offset); |
| 80 | uint pcr_read16(struct udevice *dev, uint offset); |
| 81 | uint pcr_read8(struct udevice *dev, uint offset); |
| 82 | |
| 83 | /** |
| 84 | * pcr_read32/16/8() - Write to a PCR device |
| 85 | * |
| 86 | * Writes data to a PCR device within the P2SB |
| 87 | * |
| 88 | * @dev: Device to write to |
| 89 | * @offset: Offset within device to write |
| 90 | * @data: Data to write |
| 91 | */ |
| 92 | void pcr_write32(struct udevice *dev, uint offset, uint data); |
| 93 | void pcr_write16(struct udevice *dev, uint offset, uint data); |
| 94 | void pcr_write8(struct udevice *dev, uint offset, uint data); |
| 95 | |
| 96 | /** |
| 97 | * pcr_clrsetbits32/16/8() - Update a PCR device |
| 98 | * |
| 99 | * Updates dat in a PCR device within the P2SB |
| 100 | * |
| 101 | * This reads from the device, clears and set bits, then writes back. |
| 102 | * |
| 103 | * new_data = (old_data & ~clr) | set |
| 104 | * |
| 105 | * @dev: Device to update |
| 106 | * @offset: Offset within device to update |
| 107 | * @clr: Bits to clear after reading |
| 108 | * @set: Bits to set before writing |
| 109 | */ |
| 110 | void pcr_clrsetbits32(struct udevice *dev, uint offset, uint clr, uint set); |
| 111 | void pcr_clrsetbits16(struct udevice *dev, uint offset, uint clr, uint set); |
| 112 | void pcr_clrsetbits8(struct udevice *dev, uint offset, uint clr, uint set); |
| 113 | |
| 114 | static inline void pcr_setbits32(struct udevice *dev, uint offset, uint set) |
| 115 | { |
| 116 | return pcr_clrsetbits32(dev, offset, 0, set); |
| 117 | } |
| 118 | |
| 119 | static inline void pcr_setbits16(struct udevice *dev, uint offset, uint set) |
| 120 | { |
| 121 | return pcr_clrsetbits16(dev, offset, 0, set); |
| 122 | } |
| 123 | |
| 124 | static inline void pcr_setbits8(struct udevice *dev, uint offset, uint set) |
| 125 | { |
| 126 | return pcr_clrsetbits8(dev, offset, 0, set); |
| 127 | } |
| 128 | |
| 129 | static inline void pcr_clrbits32(struct udevice *dev, uint offset, uint clr) |
| 130 | { |
| 131 | return pcr_clrsetbits32(dev, offset, clr, 0); |
| 132 | } |
| 133 | |
| 134 | static inline void pcr_clrbits16(struct udevice *dev, uint offset, uint clr) |
| 135 | { |
| 136 | return pcr_clrsetbits16(dev, offset, clr, 0); |
| 137 | } |
| 138 | |
| 139 | static inline void pcr_clrbits8(struct udevice *dev, uint offset, uint clr) |
| 140 | { |
| 141 | return pcr_clrsetbits8(dev, offset, clr, 0); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * p2sb_set_port_id() - Set the port ID for a p2sb child device |
| 146 | * |
| 147 | * This must be called in a device's bind() method when OF_PLATDATA is used |
| 148 | * since the uclass cannot access the device's of-platdata. |
| 149 | * |
| 150 | * @dev: Child device (whose parent is UCLASS_P2SB) |
| 151 | * @portid: Port ID of child device |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 152 | * Return: 0 if OK, -ENODEV is the p2sb device could not be found |
Simon Glass | 2ee1f6a | 2019-12-06 21:41:55 -0700 | [diff] [blame] | 153 | */ |
| 154 | int p2sb_set_port_id(struct udevice *dev, int portid); |
| 155 | |
| 156 | /** |
| 157 | * p2sb_get_port_id() - Get the port ID for a p2sb child device |
| 158 | * |
| 159 | * @dev: Child device (whose parent is UCLASS_P2SB) |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 160 | * Return: Port ID of that child |
Simon Glass | 2ee1f6a | 2019-12-06 21:41:55 -0700 | [diff] [blame] | 161 | */ |
| 162 | int p2sb_get_port_id(struct udevice *dev); |
| 163 | |
Simon Glass | 25f16c1 | 2020-07-07 21:32:19 -0600 | [diff] [blame] | 164 | /** |
| 165 | * pcr_reg_address() Convert an offset in p2sb space to an absolute address |
| 166 | * |
| 167 | * @dev: Child device (whose parent is UCLASS_P2SB) |
| 168 | * @offset: Offset within that child's address space |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 169 | * Return: pointer to that offset within the child's address space |
Simon Glass | 25f16c1 | 2020-07-07 21:32:19 -0600 | [diff] [blame] | 170 | */ |
| 171 | void *pcr_reg_address(struct udevice *dev, uint offset); |
| 172 | |
Simon Glass | 7aaa140 | 2020-09-22 12:45:18 -0600 | [diff] [blame] | 173 | #endif /* !__ACPI__ */ |
| 174 | |
Simon Glass | 2ee1f6a | 2019-12-06 21:41:55 -0700 | [diff] [blame] | 175 | #endif |