Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 3 | |
| 4 | #ifndef REG_SCRIPT_H |
| 5 | #define REG_SCRIPT_H |
| 6 | |
| 7 | #include <stdint.h> |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 8 | #include <device/device.h> |
Kyösti Mälkki | 3e6913b | 2019-03-02 16:26:10 +0200 | [diff] [blame] | 9 | #include <device/pci_type.h> |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 10 | #include <device/resource.h> |
| 11 | |
| 12 | /* |
| 13 | * The reg script library is a way to provide data-driven I/O accesses for |
| 14 | * initializing devices. It currently supports PCI, legacy I/O, |
| 15 | * memory-mapped I/O, and IOSF accesses. |
| 16 | * |
| 17 | * In order to simplify things for the developer the following features |
| 18 | * are employed: |
| 19 | * - Chaining of tables that allow runtime tables to chain to compile-time |
| 20 | * tables. |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 21 | * |
| 22 | * Note that when using REG_SCRIPT_COMMAND_NEXT there is an implicit push |
| 23 | * and pop of the context. A chained reg_script inherits the previous |
| 24 | * context (such as current device), but it does not impact the previous |
| 25 | * context in any way. |
| 26 | */ |
| 27 | |
| 28 | enum { |
| 29 | REG_SCRIPT_COMMAND_READ, |
| 30 | REG_SCRIPT_COMMAND_WRITE, |
| 31 | REG_SCRIPT_COMMAND_RMW, |
Lee Leahy | 6bcbe57 | 2016-04-23 07:58:27 -0700 | [diff] [blame] | 32 | REG_SCRIPT_COMMAND_RXW, |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 33 | REG_SCRIPT_COMMAND_POLL, |
| 34 | REG_SCRIPT_COMMAND_SET_DEV, |
| 35 | REG_SCRIPT_COMMAND_NEXT, |
Lee Leahy | 564dc9c | 2016-04-29 15:07:19 -0700 | [diff] [blame] | 36 | REG_SCRIPT_COMMAND_DISPLAY, |
| 37 | |
| 38 | /* Insert new types above this comment */ |
| 39 | |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 40 | REG_SCRIPT_COMMAND_END, |
| 41 | }; |
| 42 | |
| 43 | enum { |
| 44 | REG_SCRIPT_TYPE_PCI, |
| 45 | REG_SCRIPT_TYPE_IO, |
| 46 | REG_SCRIPT_TYPE_MMIO, |
| 47 | REG_SCRIPT_TYPE_RES, |
| 48 | REG_SCRIPT_TYPE_IOSF, |
Duncan Laurie | fd461e3 | 2013-11-08 23:00:24 -0800 | [diff] [blame] | 49 | REG_SCRIPT_TYPE_MSR, |
Lee Leahy | 9f5a5c5 | 2014-08-29 13:38:59 -0700 | [diff] [blame] | 50 | |
| 51 | /* Insert other platform independent values above this comment */ |
| 52 | |
Lee Leahy | efcee9f | 2016-04-29 17:26:36 -0700 | [diff] [blame] | 53 | REG_SCRIPT_TYPE_PLATFORM_BASE = 0x10000, |
| 54 | REG_SCRIPT_TYPE_SOC_BASE = REG_SCRIPT_TYPE_PLATFORM_BASE, |
| 55 | REG_SCRIPT_TYPE_MAINBOARD_BASE = 0x20000 |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | enum { |
| 59 | REG_SCRIPT_SIZE_8, |
| 60 | REG_SCRIPT_SIZE_16, |
| 61 | REG_SCRIPT_SIZE_32, |
Duncan Laurie | fd461e3 | 2013-11-08 23:00:24 -0800 | [diff] [blame] | 62 | REG_SCRIPT_SIZE_64, |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | struct reg_script { |
| 66 | uint32_t command; |
| 67 | uint32_t type; |
| 68 | uint32_t size; |
| 69 | uint32_t reg; |
Duncan Laurie | fd461e3 | 2013-11-08 23:00:24 -0800 | [diff] [blame] | 70 | uint64_t mask; |
| 71 | uint64_t value; |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 72 | uint32_t timeout; |
| 73 | union { |
| 74 | uint32_t id; |
| 75 | const struct reg_script *next; |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 76 | #ifdef __SIMPLE_DEVICE__ |
| 77 | pci_devfn_t dev; |
| 78 | #else |
| 79 | struct device *dev; |
| 80 | #endif |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 81 | unsigned int res_index; |
| 82 | }; |
| 83 | }; |
| 84 | |
Lee Leahy | 9f5a5c5 | 2014-08-29 13:38:59 -0700 | [diff] [blame] | 85 | struct reg_script_context { |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 86 | #ifdef __SIMPLE_DEVICE__ |
| 87 | pci_devfn_t dev; |
| 88 | #else |
| 89 | struct device *dev; |
| 90 | #endif |
Lee Leahy | 9f5a5c5 | 2014-08-29 13:38:59 -0700 | [diff] [blame] | 91 | struct resource *res; |
| 92 | const struct reg_script *step; |
Lee Leahy | 564dc9c | 2016-04-29 15:07:19 -0700 | [diff] [blame] | 93 | uint8_t display_state; /* Only modified by reg_script_run_step */ |
| 94 | uint8_t display_features; /* Step routine modifies to control display */ |
| 95 | const char *display_prefix; /* Prefix tag to display */ |
Lee Leahy | 9f5a5c5 | 2014-08-29 13:38:59 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
Lee Leahy | 9f5a5c5 | 2014-08-29 13:38:59 -0700 | [diff] [blame] | 98 | struct reg_script_bus_entry { |
Lee Leahy | efcee9f | 2016-04-29 17:26:36 -0700 | [diff] [blame] | 99 | uint32_t type; |
Lee Leahy | 9f5a5c5 | 2014-08-29 13:38:59 -0700 | [diff] [blame] | 100 | uint64_t (*reg_script_read)(struct reg_script_context *ctx); |
| 101 | void (*reg_script_write)(struct reg_script_context *ctx); |
| 102 | }; |
| 103 | |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 104 | #define REG_SCRIPT_TABLE_ATTRIBUTE __attribute__((used, section(".rsbe_init"))) |
Lee Leahy | 9f5a5c5 | 2014-08-29 13:38:59 -0700 | [diff] [blame] | 105 | |
Lee Leahy | efcee9f | 2016-04-29 17:26:36 -0700 | [diff] [blame] | 106 | #define REG_SCRIPT_BUS_ENTRY(bus_entry_) \ |
Lee Leahy | 84d20d0 | 2017-03-07 15:00:18 -0800 | [diff] [blame] | 107 | const struct reg_script_bus_entry *rsbe_ ## bus_entry_ \ |
Lee Leahy | efcee9f | 2016-04-29 17:26:36 -0700 | [diff] [blame] | 108 | REG_SCRIPT_TABLE_ATTRIBUTE = &bus_entry_; |
Lee Leahy | 9f5a5c5 | 2014-08-29 13:38:59 -0700 | [diff] [blame] | 109 | |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 110 | /* Internal helper Macros. */ |
| 111 | |
| 112 | #define _REG_SCRIPT_ENCODE_RAW(cmd_, type_, size_, reg_, \ |
| 113 | mask_, value_, timeout_, id_) \ |
| 114 | { .command = cmd_, \ |
| 115 | .type = type_, \ |
| 116 | .size = size_, \ |
| 117 | .reg = reg_, \ |
| 118 | .mask = mask_, \ |
| 119 | .value = value_, \ |
| 120 | .timeout = timeout_, \ |
| 121 | .id = id_, \ |
| 122 | } |
| 123 | |
| 124 | #define _REG_SCRIPT_ENCODE_RES(cmd_, type_, res_index_, size_, reg_, \ |
| 125 | mask_, value_, timeout_) \ |
| 126 | { .command = cmd_, \ |
| 127 | .type = type_, \ |
| 128 | .size = size_, \ |
| 129 | .reg = reg_, \ |
| 130 | .mask = mask_, \ |
| 131 | .value = value_, \ |
| 132 | .timeout = timeout_, \ |
| 133 | .res_index = res_index_, \ |
| 134 | } |
| 135 | |
Lee Leahy | 564dc9c | 2016-04-29 15:07:19 -0700 | [diff] [blame] | 136 | /* Display control */ |
| 137 | #define REG_SCRIPT_DISPLAY_ALL 0xff |
| 138 | #define REG_SCRIPT_DISPLAY_REGISTER 0x02 |
| 139 | #define REG_SCRIPT_DISPLAY_VALUE 0x01 |
| 140 | #define REG_SCRIPT_DISPLAY_NOTHING 0 |
| 141 | |
| 142 | #define REG_SCRIPT_DISPLAY_OFF \ |
| 143 | { .command = REG_SCRIPT_COMMAND_DISPLAY, \ |
| 144 | .value = REG_SCRIPT_DISPLAY_NOTHING, \ |
| 145 | } |
| 146 | #define REG_SCRIPT_DISPLAY_ON \ |
| 147 | { .command = REG_SCRIPT_COMMAND_DISPLAY, \ |
| 148 | .value = REG_SCRIPT_DISPLAY_ALL, \ |
| 149 | } |
| 150 | |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 151 | /* |
| 152 | * PCI |
| 153 | */ |
| 154 | |
| 155 | #define REG_SCRIPT_PCI(cmd_, bits_, reg_, mask_, value_, timeout_) \ |
| 156 | _REG_SCRIPT_ENCODE_RAW(REG_SCRIPT_COMMAND_##cmd_, \ |
| 157 | REG_SCRIPT_TYPE_PCI, \ |
| 158 | REG_SCRIPT_SIZE_##bits_, \ |
| 159 | reg_, mask_, value_, timeout_, 0) |
| 160 | #define REG_PCI_READ8(reg_) \ |
| 161 | REG_SCRIPT_PCI(READ, 8, reg_, 0, 0, 0) |
| 162 | #define REG_PCI_READ16(reg_) \ |
| 163 | REG_SCRIPT_PCI(READ, 16, reg_, 0, 0, 0) |
| 164 | #define REG_PCI_READ32(reg_) \ |
| 165 | REG_SCRIPT_PCI(READ, 32, reg_, 0, 0, 0) |
| 166 | #define REG_PCI_WRITE8(reg_, value_) \ |
| 167 | REG_SCRIPT_PCI(WRITE, 8, reg_, 0, value_, 0) |
| 168 | #define REG_PCI_WRITE16(reg_, value_) \ |
| 169 | REG_SCRIPT_PCI(WRITE, 16, reg_, 0, value_, 0) |
| 170 | #define REG_PCI_WRITE32(reg_, value_) \ |
| 171 | REG_SCRIPT_PCI(WRITE, 32, reg_, 0, value_, 0) |
| 172 | #define REG_PCI_RMW8(reg_, mask_, value_) \ |
| 173 | REG_SCRIPT_PCI(RMW, 8, reg_, mask_, value_, 0) |
| 174 | #define REG_PCI_RMW16(reg_, mask_, value_) \ |
| 175 | REG_SCRIPT_PCI(RMW, 16, reg_, mask_, value_, 0) |
| 176 | #define REG_PCI_RMW32(reg_, mask_, value_) \ |
| 177 | REG_SCRIPT_PCI(RMW, 32, reg_, mask_, value_, 0) |
Lee Leahy | 6bcbe57 | 2016-04-23 07:58:27 -0700 | [diff] [blame] | 178 | #define REG_PCI_RXW8(reg_, mask_, value_) \ |
| 179 | REG_SCRIPT_PCI(RXW, 8, reg_, mask_, value_, 0) |
| 180 | #define REG_PCI_RXW16(reg_, mask_, value_) \ |
| 181 | REG_SCRIPT_PCI(RXW, 16, reg_, mask_, value_, 0) |
| 182 | #define REG_PCI_RXW32(reg_, mask_, value_) \ |
| 183 | REG_SCRIPT_PCI(RXW, 32, reg_, mask_, value_, 0) |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 184 | #define REG_PCI_OR8(reg_, value_) \ |
| 185 | REG_SCRIPT_PCI(RMW, 8, reg_, 0xff, value_, 0) |
| 186 | #define REG_PCI_OR16(reg_, value_) \ |
| 187 | REG_SCRIPT_PCI(RMW, 16, reg_, 0xffff, value_, 0) |
| 188 | #define REG_PCI_OR32(reg_, value_) \ |
| 189 | REG_SCRIPT_PCI(RMW, 32, reg_, 0xffffffff, value_, 0) |
| 190 | #define REG_PCI_POLL8(reg_, mask_, value_, timeout_) \ |
| 191 | REG_SCRIPT_PCI(POLL, 8, reg_, mask_, value_, timeout_) |
| 192 | #define REG_PCI_POLL16(reg_, mask_, value_, timeout_) \ |
| 193 | REG_SCRIPT_PCI(POLL, 16, reg_, mask_, value_, timeout_) |
| 194 | #define REG_PCI_POLL32(reg_, mask_, value_, timeout_) \ |
| 195 | REG_SCRIPT_PCI(POLL, 32, reg_, mask_, value_, timeout_) |
Lee Leahy | 6bcbe57 | 2016-04-23 07:58:27 -0700 | [diff] [blame] | 196 | #define REG_PCI_XOR8(reg_, value_) \ |
| 197 | REG_SCRIPT_PCI(RXW, 8, reg_, 0xff, value_, 0) |
| 198 | #define REG_PCI_XOR16(reg_, value_) \ |
| 199 | REG_SCRIPT_PCI(RXW, 16, reg_, 0xffff, value_, 0) |
| 200 | #define REG_PCI_XOR32(reg_, value_) \ |
| 201 | REG_SCRIPT_PCI(RXW, 32, reg_, 0xffffffff, value_, 0) |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * Legacy IO |
| 205 | */ |
| 206 | |
| 207 | #define REG_SCRIPT_IO(cmd_, bits_, reg_, mask_, value_, timeout_) \ |
| 208 | _REG_SCRIPT_ENCODE_RAW(REG_SCRIPT_COMMAND_##cmd_, \ |
| 209 | REG_SCRIPT_TYPE_IO, \ |
| 210 | REG_SCRIPT_SIZE_##bits_, \ |
| 211 | reg_, mask_, value_, timeout_, 0) |
| 212 | #define REG_IO_READ8(reg_) \ |
| 213 | REG_SCRIPT_IO(READ, 8, reg_, 0, 0, 0) |
| 214 | #define REG_IO_READ16(reg_) \ |
| 215 | REG_SCRIPT_IO(READ, 16, reg_, 0, 0, 0) |
| 216 | #define REG_IO_READ32(reg_) \ |
| 217 | REG_SCRIPT_IO(READ, 32, reg_, 0, 0, 0) |
| 218 | #define REG_IO_WRITE8(reg_, value_) \ |
| 219 | REG_SCRIPT_IO(WRITE, 8, reg_, 0, value_, 0) |
| 220 | #define REG_IO_WRITE16(reg_, value_) \ |
| 221 | REG_SCRIPT_IO(WRITE, 16, reg_, 0, value_, 0) |
| 222 | #define REG_IO_WRITE32(reg_, value_) \ |
| 223 | REG_SCRIPT_IO(WRITE, 32, reg_, 0, value_, 0) |
| 224 | #define REG_IO_RMW8(reg_, mask_, value_) \ |
| 225 | REG_SCRIPT_IO(RMW, 8, reg_, mask_, value_, 0) |
| 226 | #define REG_IO_RMW16(reg_, mask_, value_) \ |
| 227 | REG_SCRIPT_IO(RMW, 16, reg_, mask_, value_, 0) |
| 228 | #define REG_IO_RMW32(reg_, mask_, value_) \ |
| 229 | REG_SCRIPT_IO(RMW, 32, reg_, mask_, value_, 0) |
Lee Leahy | 6bcbe57 | 2016-04-23 07:58:27 -0700 | [diff] [blame] | 230 | #define REG_IO_RXW8(reg_, mask_, value_) \ |
| 231 | REG_SCRIPT_IO(RXW, 8, reg_, mask_, value_, 0) |
| 232 | #define REG_IO_RXW16(reg_, mask_, value_) \ |
| 233 | REG_SCRIPT_IO(RXW, 16, reg_, mask_, value_, 0) |
| 234 | #define REG_IO_RXW32(reg_, mask_, value_) \ |
| 235 | REG_SCRIPT_IO(RXW, 32, reg_, mask_, value_, 0) |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 236 | #define REG_IO_OR8(reg_, value_) \ |
Duncan Laurie | 21fd2f4 | 2014-04-22 11:14:12 -0700 | [diff] [blame] | 237 | REG_IO_RMW8(reg_, 0xff, value_) |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 238 | #define REG_IO_OR16(reg_, value_) \ |
Duncan Laurie | 21fd2f4 | 2014-04-22 11:14:12 -0700 | [diff] [blame] | 239 | REG_IO_RMW16(reg_, 0xffff, value_) |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 240 | #define REG_IO_OR32(reg_, value_) \ |
Duncan Laurie | 21fd2f4 | 2014-04-22 11:14:12 -0700 | [diff] [blame] | 241 | REG_IO_RMW32(reg_, 0xffffffff, value_) |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 242 | #define REG_IO_POLL8(reg_, mask_, value_, timeout_) \ |
| 243 | REG_SCRIPT_IO(POLL, 8, reg_, mask_, value_, timeout_) |
| 244 | #define REG_IO_POLL16(reg_, mask_, value_, timeout_) \ |
| 245 | REG_SCRIPT_IO(POLL, 16, reg_, mask_, value_, timeout_) |
| 246 | #define REG_IO_POLL32(reg_, mask_, value_, timeout_) \ |
| 247 | REG_SCRIPT_IO(POLL, 32, reg_, mask_, value_, timeout_) |
Lee Leahy | 6bcbe57 | 2016-04-23 07:58:27 -0700 | [diff] [blame] | 248 | #define REG_IO_XOR8(reg_, value_) \ |
| 249 | REG_IO_RXW8(reg_, 0xff, value_) |
| 250 | #define REG_IO_XOR16(reg_, value_) \ |
| 251 | REG_IO_RXW16(reg_, 0xffff, value_) |
| 252 | #define REG_IO_XOR32(reg_, value_) \ |
| 253 | REG_IO_RXW32(reg_, 0xffffffff, value_) |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 254 | |
| 255 | /* |
| 256 | * Memory Mapped IO |
| 257 | */ |
| 258 | |
| 259 | #define REG_SCRIPT_MMIO(cmd_, bits_, reg_, mask_, value_, timeout_) \ |
| 260 | _REG_SCRIPT_ENCODE_RAW(REG_SCRIPT_COMMAND_##cmd_, \ |
| 261 | REG_SCRIPT_TYPE_MMIO, \ |
| 262 | REG_SCRIPT_SIZE_##bits_, \ |
| 263 | reg_, mask_, value_, timeout_, 0) |
| 264 | #define REG_MMIO_READ8(reg_) \ |
| 265 | REG_SCRIPT_MMIO(READ, 8, reg_, 0, 0, 0) |
| 266 | #define REG_MMIO_READ16(reg_) \ |
| 267 | REG_SCRIPT_MMIO(READ, 16, reg_, 0, 0, 0) |
| 268 | #define REG_MMIO_READ32(reg_) \ |
| 269 | REG_SCRIPT_MMIO(READ, 32, reg_, 0, 0, 0) |
| 270 | #define REG_MMIO_WRITE8(reg_, value_) \ |
| 271 | REG_SCRIPT_MMIO(WRITE, 8, reg_, 0, value_, 0) |
| 272 | #define REG_MMIO_WRITE16(reg_, value_) \ |
| 273 | REG_SCRIPT_MMIO(WRITE, 16, reg_, 0, value_, 0) |
| 274 | #define REG_MMIO_WRITE32(reg_, value_) \ |
| 275 | REG_SCRIPT_MMIO(WRITE, 32, reg_, 0, value_, 0) |
| 276 | #define REG_MMIO_RMW8(reg_, mask_, value_) \ |
| 277 | REG_SCRIPT_MMIO(RMW, 8, reg_, mask_, value_, 0) |
| 278 | #define REG_MMIO_RMW16(reg_, mask_, value_) \ |
| 279 | REG_SCRIPT_MMIO(RMW, 16, reg_, mask_, value_, 0) |
| 280 | #define REG_MMIO_RMW32(reg_, mask_, value_) \ |
| 281 | REG_SCRIPT_MMIO(RMW, 32, reg_, mask_, value_, 0) |
Lee Leahy | 6bcbe57 | 2016-04-23 07:58:27 -0700 | [diff] [blame] | 282 | #define REG_MMIO_RXW8(reg_, mask_, value_) \ |
| 283 | REG_SCRIPT_MMIO(RXW, 8, reg_, mask_, value_, 0) |
| 284 | #define REG_MMIO_RXW16(reg_, mask_, value_) \ |
| 285 | REG_SCRIPT_MMIO(RXW, 16, reg_, mask_, value_, 0) |
| 286 | #define REG_MMIO_RXW32(reg_, mask_, value_) \ |
| 287 | REG_SCRIPT_MMIO(RXW, 32, reg_, mask_, value_, 0) |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 288 | #define REG_MMIO_OR8(reg_, value_) \ |
| 289 | REG_MMIO_RMW8(reg_, 0xff, value_) |
| 290 | #define REG_MMIO_OR16(reg_, value_) \ |
| 291 | REG_MMIO_RMW16(reg_, 0xffff, value_) |
| 292 | #define REG_MMIO_OR32(reg_, value_) \ |
| 293 | REG_MMIO_RMW32(reg_, 0xffffffff, value_) |
| 294 | #define REG_MMIO_POLL8(reg_, mask_, value_, timeout_) \ |
| 295 | REG_SCRIPT_MMIO(POLL, 8, reg_, mask_, value_, timeout_) |
| 296 | #define REG_MMIO_POLL16(reg_, mask_, value_, timeout_) \ |
| 297 | REG_SCRIPT_MMIO(POLL, 16, reg_, mask_, value_, timeout_) |
| 298 | #define REG_MMIO_POLL32(reg_, mask_, value_, timeout_) \ |
| 299 | REG_SCRIPT_MMIO(POLL, 32, reg_, mask_, value_, timeout_) |
Lee Leahy | 6bcbe57 | 2016-04-23 07:58:27 -0700 | [diff] [blame] | 300 | #define REG_MMIO_XOR8(reg_, value_) \ |
| 301 | REG_MMIO_RXW8(reg_, 0xff, value_) |
| 302 | #define REG_MMIO_XOR16(reg_, value_) \ |
| 303 | REG_MMIO_RXW16(reg_, 0xffff, value_) |
| 304 | #define REG_MMIO_XOR32(reg_, value_) \ |
| 305 | REG_MMIO_RXW32(reg_, 0xffffffff, value_) |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 306 | |
| 307 | /* |
| 308 | * Access through a device's resource such as a Base Address Register (BAR) |
| 309 | */ |
| 310 | |
| 311 | #define REG_SCRIPT_RES(cmd_, bits_, bar_, reg_, mask_, value_, timeout_) \ |
| 312 | _REG_SCRIPT_ENCODE_RES(REG_SCRIPT_COMMAND_##cmd_, \ |
| 313 | REG_SCRIPT_TYPE_RES, bar_, \ |
| 314 | REG_SCRIPT_SIZE_##bits_, \ |
| 315 | reg_, mask_, value_, timeout_) |
| 316 | #define REG_RES_READ8(bar_, reg_) \ |
| 317 | REG_SCRIPT_RES(READ, 8, bar_, reg_, 0, 0, 0) |
| 318 | #define REG_RES_READ16(bar_, reg_) \ |
| 319 | REG_SCRIPT_RES(READ, 16, bar_, reg_, 0, 0, 0) |
| 320 | #define REG_RES_READ32(bar_, reg_) \ |
| 321 | REG_SCRIPT_RES(READ, 32, bar_, reg_, 0, 0, 0) |
| 322 | #define REG_RES_WRITE8(bar_, reg_, value_) \ |
| 323 | REG_SCRIPT_RES(WRITE, 8, bar_, reg_, 0, value_, 0) |
| 324 | #define REG_RES_WRITE16(bar_, reg_, value_) \ |
| 325 | REG_SCRIPT_RES(WRITE, 16, bar_, reg_, 0, value_, 0) |
| 326 | #define REG_RES_WRITE32(bar_, reg_, value_) \ |
| 327 | REG_SCRIPT_RES(WRITE, 32, bar_, reg_, 0, value_, 0) |
| 328 | #define REG_RES_RMW8(bar_, reg_, mask_, value_) \ |
| 329 | REG_SCRIPT_RES(RMW, 8, bar_, reg_, mask_, value_, 0) |
| 330 | #define REG_RES_RMW16(bar_, reg_, mask_, value_) \ |
| 331 | REG_SCRIPT_RES(RMW, 16, bar_, reg_, mask_, value_, 0) |
| 332 | #define REG_RES_RMW32(bar_, reg_, mask_, value_) \ |
| 333 | REG_SCRIPT_RES(RMW, 32, bar_, reg_, mask_, value_, 0) |
Lee Leahy | 6bcbe57 | 2016-04-23 07:58:27 -0700 | [diff] [blame] | 334 | #define REG_RES_RXW8(bar_, reg_, mask_, value_) \ |
| 335 | REG_SCRIPT_RES(RXW, 8, bar_, reg_, mask_, value_, 0) |
| 336 | #define REG_RES_RXW16(bar_, reg_, mask_, value_) \ |
| 337 | REG_SCRIPT_RES(RXW, 16, bar_, reg_, mask_, value_, 0) |
| 338 | #define REG_RES_RXW32(bar_, reg_, mask_, value_) \ |
| 339 | REG_SCRIPT_RES(RXW, 32, bar_, reg_, mask_, value_, 0) |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 340 | #define REG_RES_OR8(bar_, reg_, value_) \ |
| 341 | REG_RES_RMW8(bar_, reg_, 0xff, value_) |
| 342 | #define REG_RES_OR16(bar_, reg_, value_) \ |
| 343 | REG_RES_RMW16(bar_, reg_, 0xffff, value_) |
| 344 | #define REG_RES_OR32(bar_, reg_, value_) \ |
| 345 | REG_RES_RMW32(bar_, reg_, 0xffffffff, value_) |
| 346 | #define REG_RES_POLL8(bar_, reg_, mask_, value_, timeout_) \ |
| 347 | REG_SCRIPT_RES(POLL, 8, bar_, reg_, mask_, value_, timeout_) |
| 348 | #define REG_RES_POLL16(bar_, reg_, mask_, value_, timeout_) \ |
| 349 | REG_SCRIPT_RES(POLL, 16, bar_, reg_, mask_, value_, timeout_) |
| 350 | #define REG_RES_POLL32(bar_, reg_, mask_, value_, timeout_) \ |
| 351 | REG_SCRIPT_RES(POLL, 32, bar_, reg_, mask_, value_, timeout_) |
Lee Leahy | 6bcbe57 | 2016-04-23 07:58:27 -0700 | [diff] [blame] | 352 | #define REG_RES_XOR8(bar_, reg_, value_) \ |
| 353 | REG_RES_RXW8(bar_, reg_, 0xff, value_) |
| 354 | #define REG_RES_XOR16(bar_, reg_, value_) \ |
| 355 | REG_RES_RXW16(bar_, reg_, 0xffff, value_) |
| 356 | #define REG_RES_XOR32(bar_, reg_, value_) \ |
| 357 | REG_RES_RXW32(bar_, reg_, 0xffffffff, value_) |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 358 | |
Lee Leahy | 9f5a5c5 | 2014-08-29 13:38:59 -0700 | [diff] [blame] | 359 | |
Arthur Heymans | d980211 | 2019-11-19 18:46:44 +0100 | [diff] [blame] | 360 | #if CONFIG(SOC_INTEL_BAYTRAIL) |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 361 | /* |
| 362 | * IO Sideband Function |
| 363 | */ |
| 364 | |
| 365 | #define REG_SCRIPT_IOSF(cmd_, unit_, reg_, mask_, value_, timeout_) \ |
| 366 | _REG_SCRIPT_ENCODE_RAW(REG_SCRIPT_COMMAND_##cmd_, \ |
| 367 | REG_SCRIPT_TYPE_IOSF, \ |
| 368 | REG_SCRIPT_SIZE_32, \ |
| 369 | reg_, mask_, value_, timeout_, unit_) |
| 370 | #define REG_IOSF_READ(unit_, reg_) \ |
| 371 | REG_SCRIPT_IOSF(READ, unit_, reg_, 0, 0, 0) |
| 372 | #define REG_IOSF_WRITE(unit_, reg_, value_) \ |
| 373 | REG_SCRIPT_IOSF(WRITE, unit_, reg_, 0, value_, 0) |
| 374 | #define REG_IOSF_RMW(unit_, reg_, mask_, value_) \ |
| 375 | REG_SCRIPT_IOSF(RMW, unit_, reg_, mask_, value_, 0) |
Lee Leahy | 6bcbe57 | 2016-04-23 07:58:27 -0700 | [diff] [blame] | 376 | #define REG_IOSF_RXW(unit_, reg_, mask_, value_) \ |
| 377 | REG_SCRIPT_IOSF(RXW, unit_, reg_, mask_, value_, 0) |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 378 | #define REG_IOSF_OR(unit_, reg_, value_) \ |
| 379 | REG_IOSF_RMW(unit_, reg_, 0xffffffff, value_) |
| 380 | #define REG_IOSF_POLL(unit_, reg_, mask_, value_, timeout_) \ |
| 381 | REG_SCRIPT_IOSF(POLL, unit_, reg_, mask_, value_, timeout_) |
Lee Leahy | 6bcbe57 | 2016-04-23 07:58:27 -0700 | [diff] [blame] | 382 | #define REG_IOSF_XOR(unit_, reg_, value_) \ |
| 383 | REG_IOSF_RXW(unit_, reg_, 0xffffffff, value_) |
Arthur Heymans | d980211 | 2019-11-19 18:46:44 +0100 | [diff] [blame] | 384 | #endif /* CONFIG_SOC_INTEL_BAYTRAIL */ |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 385 | |
| 386 | /* |
Duncan Laurie | fd461e3 | 2013-11-08 23:00:24 -0800 | [diff] [blame] | 387 | * CPU Model Specific Register |
| 388 | */ |
| 389 | |
| 390 | #define REG_SCRIPT_MSR(cmd_, reg_, mask_, value_, timeout_) \ |
| 391 | _REG_SCRIPT_ENCODE_RAW(REG_SCRIPT_COMMAND_##cmd_, \ |
| 392 | REG_SCRIPT_TYPE_MSR, \ |
| 393 | REG_SCRIPT_SIZE_64, \ |
| 394 | reg_, mask_, value_, timeout_, 0) |
| 395 | #define REG_MSR_READ(reg_) \ |
| 396 | REG_SCRIPT_MSR(READ, reg_, 0, 0, 0) |
| 397 | #define REG_MSR_WRITE(reg_, value_) \ |
| 398 | REG_SCRIPT_MSR(WRITE, reg_, 0, value_, 0) |
| 399 | #define REG_MSR_RMW(reg_, mask_, value_) \ |
| 400 | REG_SCRIPT_MSR(RMW, reg_, mask_, value_, 0) |
Lee Leahy | 6bcbe57 | 2016-04-23 07:58:27 -0700 | [diff] [blame] | 401 | #define REG_MSR_RXW(reg_, mask_, value_) \ |
| 402 | REG_SCRIPT_MSR(RXW, reg_, mask_, value_, 0) |
Duncan Laurie | fd461e3 | 2013-11-08 23:00:24 -0800 | [diff] [blame] | 403 | #define REG_MSR_OR(reg_, value_) \ |
| 404 | REG_MSR_RMW(reg_, -1ULL, value_) |
| 405 | #define REG_MSR_POLL(reg_, mask_, value_, timeout_) \ |
| 406 | REG_SCRIPT_MSR(POLL, reg_, mask_, value_, timeout_) |
Lee Leahy | 6bcbe57 | 2016-04-23 07:58:27 -0700 | [diff] [blame] | 407 | #define REG_MSR_XOR(reg_, value_) \ |
| 408 | REG_MSR_RXW(reg_, -1ULL, value_) |
Duncan Laurie | fd461e3 | 2013-11-08 23:00:24 -0800 | [diff] [blame] | 409 | |
| 410 | /* |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 411 | * Chain to another table. |
| 412 | */ |
| 413 | #define REG_SCRIPT_NEXT(next_) \ |
| 414 | { .command = REG_SCRIPT_COMMAND_NEXT, \ |
| 415 | .next = next_, \ |
| 416 | } |
| 417 | |
| 418 | /* |
| 419 | * Set current device |
| 420 | */ |
| 421 | #define REG_SCRIPT_SET_DEV(dev_) \ |
| 422 | { .command = REG_SCRIPT_COMMAND_SET_DEV, \ |
| 423 | .dev = dev_, \ |
| 424 | } |
| 425 | |
| 426 | /* |
| 427 | * Last script entry. All tables need to end with REG_SCRIPT_END. |
| 428 | */ |
| 429 | #define REG_SCRIPT_END \ |
| 430 | _REG_SCRIPT_ENCODE_RAW(REG_SCRIPT_COMMAND_END, 0, 0, 0, 0, 0, 0, 0) |
| 431 | |
| 432 | void reg_script_run(const struct reg_script *script); |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 433 | #ifdef __SIMPLE_DEVICE__ |
| 434 | void reg_script_run_on_dev(pci_devfn_t dev, const struct reg_script *step); |
| 435 | #else |
| 436 | void reg_script_run_on_dev(struct device *dev, const struct reg_script *step); |
| 437 | #endif |
Duncan Laurie | 7274800 | 2013-10-31 08:26:23 -0700 | [diff] [blame] | 438 | |
| 439 | #endif /* REG_SCRIPT_H */ |