Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | d1130af | 2020-04-23 12:51:42 -0700 | [diff] [blame] | 3 | #include <assert.h> |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 4 | #include <string.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 5 | #include <acpi/acpi.h> |
| 6 | #include <acpi/acpi_device.h> |
| 7 | #include <acpi/acpigen.h> |
Tim Wawrzynczak | d40a4c2 | 2021-02-25 13:14:49 -0700 | [diff] [blame] | 8 | #include <acpi/acpigen_pci.h> |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 9 | #include <device/device.h> |
| 10 | #include <device/path.h> |
Elyes HAOUAS | 70a03dd | 2019-12-02 20:47:50 +0100 | [diff] [blame] | 11 | #include <stdlib.h> |
Elyes HAOUAS | a83a7db | 2020-07-22 11:42:53 +0200 | [diff] [blame] | 12 | #include <types.h> |
Patrick Rudolph | c83bab6 | 2019-12-13 12:16:06 +0100 | [diff] [blame] | 13 | #include <crc_byte.h> |
| 14 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 15 | #if CONFIG(GENERIC_GPIO_LIB) |
Duncan Laurie | cfb6ea7 | 2016-05-09 17:08:38 -0700 | [diff] [blame] | 16 | #include <gpio.h> |
| 17 | #endif |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 18 | |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 19 | #define ACPI_DP_UUID "daffd814-6eba-4d8c-8a91-bc9bbf4aa301" |
| 20 | #define ACPI_DP_CHILD_UUID "dbb8e3e6-5886-4ba6-8795-1319f52a966b" |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 21 | |
Duncan Laurie | 6b7c1f6 | 2016-05-09 15:38:36 -0700 | [diff] [blame] | 22 | /* Write empty word value and return pointer to it */ |
| 23 | static void *acpi_device_write_zero_len(void) |
| 24 | { |
| 25 | char *p = acpigen_get_current(); |
| 26 | acpigen_emit_word(0); |
| 27 | return p; |
| 28 | } |
| 29 | |
| 30 | /* Fill in length value from start to current at specified location */ |
| 31 | static void acpi_device_fill_from_len(char *ptr, char *start) |
| 32 | { |
| 33 | uint16_t len = acpigen_get_current() - start; |
| 34 | ptr[0] = len & 0xff; |
| 35 | ptr[1] = (len >> 8) & 0xff; |
| 36 | } |
| 37 | |
| 38 | /* |
| 39 | * Fill in the length field with the value calculated from after |
| 40 | * the 16bit field to acpigen current as this length value does |
| 41 | * not include the length field itself. |
| 42 | */ |
| 43 | static void acpi_device_fill_len(void *ptr) |
| 44 | { |
| 45 | acpi_device_fill_from_len(ptr, ptr + sizeof(uint16_t)); |
| 46 | } |
| 47 | |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 48 | /* Locate and return the ACPI name for this device */ |
Aamir Bohra | e825d3f | 2019-07-30 10:11:41 +0530 | [diff] [blame] | 49 | const char *acpi_device_name(const struct device *dev) |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 50 | { |
Aamir Bohra | e825d3f | 2019-07-30 10:11:41 +0530 | [diff] [blame] | 51 | const struct device *pdev = dev; |
Duncan Laurie | 4702914 | 2018-05-07 14:28:53 -0700 | [diff] [blame] | 52 | const char *name = NULL; |
| 53 | |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 54 | if (!dev) |
| 55 | return NULL; |
| 56 | |
| 57 | /* Check for device specific handler */ |
Duncan Laurie | 84fac41 | 2020-06-03 12:36:51 -0700 | [diff] [blame] | 58 | if (dev->ops && dev->ops->acpi_name) |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 59 | return dev->ops->acpi_name(dev); |
| 60 | |
Duncan Laurie | 4702914 | 2018-05-07 14:28:53 -0700 | [diff] [blame] | 61 | /* Walk up the tree to find if any parent can identify this device */ |
| 62 | while (pdev->bus) { |
| 63 | pdev = pdev->bus->dev; |
| 64 | if (!pdev) |
| 65 | break; |
| 66 | if (pdev->path.type == DEVICE_PATH_ROOT) |
| 67 | break; |
| 68 | if (pdev->ops && pdev->ops->acpi_name) |
| 69 | name = pdev->ops->acpi_name(dev); |
| 70 | if (name) |
| 71 | return name; |
| 72 | } |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 73 | |
| 74 | return NULL; |
| 75 | } |
| 76 | |
Patrick Rudolph | eeb8e74 | 2019-08-20 08:20:01 +0200 | [diff] [blame] | 77 | /* Locate and return the ACPI _HID (Hardware ID) for this device */ |
| 78 | const char *acpi_device_hid(const struct device *dev) |
| 79 | { |
| 80 | if (!dev) |
| 81 | return NULL; |
| 82 | |
| 83 | /* Check for device specific handler */ |
| 84 | if (dev->ops->acpi_hid) |
| 85 | return dev->ops->acpi_hid(dev); |
| 86 | |
| 87 | /* |
| 88 | * Don't walk up the tree to find any parent that can identify this device, as |
| 89 | * PNP devices are hard to identify. |
| 90 | */ |
| 91 | |
| 92 | return NULL; |
| 93 | } |
| 94 | |
Patrick Rudolph | c83bab6 | 2019-12-13 12:16:06 +0100 | [diff] [blame] | 95 | /* |
| 96 | * Generate unique ID based on the ACPI path. |
| 97 | * Collisions on the same _HID are possible but very unlikely. |
| 98 | */ |
Furquan Shaikh | d14d03a | 2020-04-24 21:27:29 -0700 | [diff] [blame] | 99 | uint32_t acpi_device_uid(const struct device *dev) |
Patrick Rudolph | c83bab6 | 2019-12-13 12:16:06 +0100 | [diff] [blame] | 100 | { |
| 101 | const char *path = acpi_device_path(dev); |
| 102 | if (!path) |
| 103 | return 0; |
| 104 | |
| 105 | return CRC(path, strlen(path), crc32_byte); |
| 106 | } |
| 107 | |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 108 | /* Recursive function to find the root device and print a path from there */ |
Aamir Bohra | e825d3f | 2019-07-30 10:11:41 +0530 | [diff] [blame] | 109 | static ssize_t acpi_device_path_fill(const struct device *dev, char *buf, |
Duncan Laurie | 4702914 | 2018-05-07 14:28:53 -0700 | [diff] [blame] | 110 | size_t buf_len, size_t cur) |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 111 | { |
| 112 | const char *name = acpi_device_name(dev); |
Duncan Laurie | 4702914 | 2018-05-07 14:28:53 -0700 | [diff] [blame] | 113 | ssize_t next = 0; |
| 114 | |
| 115 | if (!name) |
| 116 | return -1; |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 117 | |
| 118 | /* |
| 119 | * Make sure this name segment will fit, including the path segment |
| 120 | * separator and possible NUL terminator if this is the last segment. |
| 121 | */ |
Duncan Laurie | 4702914 | 2018-05-07 14:28:53 -0700 | [diff] [blame] | 122 | if (!dev || (cur + strlen(name) + 2) > buf_len) |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 123 | return cur; |
| 124 | |
| 125 | /* Walk up the tree to the root device */ |
| 126 | if (dev->path.type != DEVICE_PATH_ROOT && dev->bus && dev->bus->dev) |
| 127 | next = acpi_device_path_fill(dev->bus->dev, buf, buf_len, cur); |
Duncan Laurie | 4702914 | 2018-05-07 14:28:53 -0700 | [diff] [blame] | 128 | if (next < 0) |
| 129 | return next; |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 130 | |
| 131 | /* Fill in the path from the root device */ |
| 132 | next += snprintf(buf + next, buf_len - next, "%s%s", |
Timothy Pearson | aeb6101 | 2017-04-13 17:06:16 -0500 | [diff] [blame] | 133 | (dev->path.type == DEVICE_PATH_ROOT |
| 134 | || (strlen(name) == 0)) ? |
| 135 | "" : ".", name); |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 136 | |
| 137 | return next; |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * Warning: just as with dev_path() this uses a static buffer |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 142 | * so should not be called multiple times in one statement |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 143 | */ |
Aamir Bohra | e825d3f | 2019-07-30 10:11:41 +0530 | [diff] [blame] | 144 | const char *acpi_device_path(const struct device *dev) |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 145 | { |
| 146 | static char buf[DEVICE_PATH_MAX] = {}; |
| 147 | |
| 148 | if (!dev) |
| 149 | return NULL; |
| 150 | |
| 151 | if (acpi_device_path_fill(dev, buf, sizeof(buf), 0) <= 0) |
| 152 | return NULL; |
| 153 | |
| 154 | return buf; |
| 155 | } |
| 156 | |
| 157 | /* Return the path of the parent device as the ACPI Scope for this device */ |
Aamir Bohra | e825d3f | 2019-07-30 10:11:41 +0530 | [diff] [blame] | 158 | const char *acpi_device_scope(const struct device *dev) |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 159 | { |
Duncan Laurie | d02685b | 2016-06-30 14:37:37 -0700 | [diff] [blame] | 160 | static char buf[DEVICE_PATH_MAX] = {}; |
| 161 | |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 162 | if (!dev || !dev->bus || !dev->bus->dev) |
| 163 | return NULL; |
| 164 | |
Duncan Laurie | d02685b | 2016-06-30 14:37:37 -0700 | [diff] [blame] | 165 | if (acpi_device_path_fill(dev->bus->dev, buf, sizeof(buf), 0) <= 0) |
| 166 | return NULL; |
| 167 | |
| 168 | return buf; |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Elyes HAOUAS | 6716bab | 2020-01-09 21:29:25 +0100 | [diff] [blame] | 171 | /* Concatenate the device path and provided name suffix */ |
Aamir Bohra | e825d3f | 2019-07-30 10:11:41 +0530 | [diff] [blame] | 172 | const char *acpi_device_path_join(const struct device *dev, const char *name) |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 173 | { |
| 174 | static char buf[DEVICE_PATH_MAX] = {}; |
Jacob Garber | f2ba2d9 | 2019-07-02 10:50:10 -0600 | [diff] [blame] | 175 | ssize_t len; |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 176 | |
| 177 | if (!dev) |
| 178 | return NULL; |
| 179 | |
| 180 | /* Build the path of this device */ |
| 181 | len = acpi_device_path_fill(dev, buf, sizeof(buf), 0); |
| 182 | if (len <= 0) |
| 183 | return NULL; |
| 184 | |
| 185 | /* Ensure there is room for the added name, separator, and NUL */ |
| 186 | if ((len + strlen(name) + 2) > sizeof(buf)) |
| 187 | return NULL; |
| 188 | snprintf(buf + len, sizeof(buf) - len, ".%s", name); |
| 189 | |
| 190 | return buf; |
| 191 | } |
Duncan Laurie | 6b7c1f6 | 2016-05-09 15:38:36 -0700 | [diff] [blame] | 192 | |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 193 | int acpi_device_status(const struct device *dev) |
| 194 | { |
| 195 | if (!dev->enabled) |
| 196 | return ACPI_STATUS_DEVICE_ALL_OFF; |
| 197 | if (dev->hidden) |
| 198 | return ACPI_STATUS_DEVICE_HIDDEN_ON; |
| 199 | return ACPI_STATUS_DEVICE_ALL_ON; |
| 200 | } |
| 201 | |
Patrick Rudolph | c83bab6 | 2019-12-13 12:16:06 +0100 | [diff] [blame] | 202 | /* Write the unique _UID based on ACPI device path. */ |
Furquan Shaikh | d14d03a | 2020-04-24 21:27:29 -0700 | [diff] [blame] | 203 | void acpi_device_write_uid(const struct device *dev) |
Patrick Rudolph | c83bab6 | 2019-12-13 12:16:06 +0100 | [diff] [blame] | 204 | { |
| 205 | acpigen_write_name_integer("_UID", acpi_device_uid(dev)); |
| 206 | } |
| 207 | |
Duncan Laurie | 6b7c1f6 | 2016-05-09 15:38:36 -0700 | [diff] [blame] | 208 | /* ACPI 6.1 section 6.4.3.6: Extended Interrupt Descriptor */ |
| 209 | void acpi_device_write_interrupt(const struct acpi_irq *irq) |
| 210 | { |
| 211 | void *desc_length; |
| 212 | uint8_t flags; |
| 213 | |
| 214 | if (!irq || !irq->pin) |
| 215 | return; |
| 216 | |
| 217 | /* This is supported by GpioInt() but not Interrupt() */ |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 218 | if (irq->polarity == ACPI_IRQ_ACTIVE_BOTH) |
Duncan Laurie | 6b7c1f6 | 2016-05-09 15:38:36 -0700 | [diff] [blame] | 219 | return; |
| 220 | |
| 221 | /* Byte 0: Descriptor Type */ |
| 222 | acpigen_emit_byte(ACPI_DESCRIPTOR_INTERRUPT); |
| 223 | |
| 224 | /* Byte 1-2: Length (filled in later) */ |
| 225 | desc_length = acpi_device_write_zero_len(); |
| 226 | |
| 227 | /* |
| 228 | * Byte 3: Flags |
| 229 | * [7:5]: Reserved |
| 230 | * [4]: Wake (0=NO_WAKE 1=WAKE) |
| 231 | * [3]: Sharing (0=EXCLUSIVE 1=SHARED) |
| 232 | * [2]: Polarity (0=HIGH 1=LOW) |
| 233 | * [1]: Mode (0=LEVEL 1=EDGE) |
| 234 | * [0]: Resource (0=PRODUCER 1=CONSUMER) |
| 235 | */ |
| 236 | flags = 1 << 0; /* ResourceConsumer */ |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 237 | if (irq->mode == ACPI_IRQ_EDGE_TRIGGERED) |
Duncan Laurie | 6b7c1f6 | 2016-05-09 15:38:36 -0700 | [diff] [blame] | 238 | flags |= 1 << 1; |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 239 | if (irq->polarity == ACPI_IRQ_ACTIVE_LOW) |
Duncan Laurie | 6b7c1f6 | 2016-05-09 15:38:36 -0700 | [diff] [blame] | 240 | flags |= 1 << 2; |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 241 | if (irq->shared == ACPI_IRQ_SHARED) |
Duncan Laurie | 6b7c1f6 | 2016-05-09 15:38:36 -0700 | [diff] [blame] | 242 | flags |= 1 << 3; |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 243 | if (irq->wake == ACPI_IRQ_WAKE) |
Duncan Laurie | 6b7c1f6 | 2016-05-09 15:38:36 -0700 | [diff] [blame] | 244 | flags |= 1 << 4; |
| 245 | acpigen_emit_byte(flags); |
| 246 | |
| 247 | /* Byte 4: Interrupt Table Entry Count */ |
| 248 | acpigen_emit_byte(1); |
| 249 | |
| 250 | /* Byte 5-8: Interrupt Number */ |
| 251 | acpigen_emit_dword(irq->pin); |
| 252 | |
| 253 | /* Fill in Descriptor Length (account for len word) */ |
| 254 | acpi_device_fill_len(desc_length); |
| 255 | } |
Duncan Laurie | cfb6ea7 | 2016-05-09 17:08:38 -0700 | [diff] [blame] | 256 | |
| 257 | /* ACPI 6.1 section 6.4.3.8.1 - GPIO Interrupt or I/O */ |
| 258 | void acpi_device_write_gpio(const struct acpi_gpio *gpio) |
| 259 | { |
| 260 | void *start, *desc_length; |
| 261 | void *pin_table_offset, *vendor_data_offset, *resource_offset; |
| 262 | uint16_t flags = 0; |
| 263 | int pin; |
| 264 | |
| 265 | if (!gpio || gpio->type > ACPI_GPIO_TYPE_IO) |
| 266 | return; |
| 267 | |
| 268 | start = acpigen_get_current(); |
| 269 | |
| 270 | /* Byte 0: Descriptor Type */ |
| 271 | acpigen_emit_byte(ACPI_DESCRIPTOR_GPIO); |
| 272 | |
| 273 | /* Byte 1-2: Length (fill in later) */ |
| 274 | desc_length = acpi_device_write_zero_len(); |
| 275 | |
| 276 | /* Byte 3: Revision ID */ |
| 277 | acpigen_emit_byte(ACPI_GPIO_REVISION_ID); |
| 278 | |
| 279 | /* Byte 4: GpioIo or GpioInt */ |
| 280 | acpigen_emit_byte(gpio->type); |
| 281 | |
| 282 | /* |
| 283 | * Byte 5-6: General Flags |
| 284 | * [15:1]: 0 => Reserved |
| 285 | * [0]: 1 => ResourceConsumer |
| 286 | */ |
| 287 | acpigen_emit_word(1 << 0); |
| 288 | |
| 289 | switch (gpio->type) { |
| 290 | case ACPI_GPIO_TYPE_INTERRUPT: |
| 291 | /* |
| 292 | * Byte 7-8: GPIO Interrupt Flags |
| 293 | * [15:5]: 0 => Reserved |
| 294 | * [4]: Wake (0=NO_WAKE 1=WAKE) |
| 295 | * [3]: Sharing (0=EXCLUSIVE 1=SHARED) |
| 296 | * [2:1]: Polarity (0=HIGH 1=LOW 2=BOTH) |
| 297 | * [0]: Mode (0=LEVEL 1=EDGE) |
| 298 | */ |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 299 | if (gpio->irq.mode == ACPI_IRQ_EDGE_TRIGGERED) |
Duncan Laurie | cfb6ea7 | 2016-05-09 17:08:38 -0700 | [diff] [blame] | 300 | flags |= 1 << 0; |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 301 | if (gpio->irq.shared == ACPI_IRQ_SHARED) |
Duncan Laurie | cfb6ea7 | 2016-05-09 17:08:38 -0700 | [diff] [blame] | 302 | flags |= 1 << 3; |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 303 | if (gpio->irq.wake == ACPI_IRQ_WAKE) |
Duncan Laurie | cfb6ea7 | 2016-05-09 17:08:38 -0700 | [diff] [blame] | 304 | flags |= 1 << 4; |
| 305 | |
| 306 | switch (gpio->irq.polarity) { |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 307 | case ACPI_IRQ_ACTIVE_HIGH: |
Duncan Laurie | cfb6ea7 | 2016-05-09 17:08:38 -0700 | [diff] [blame] | 308 | flags |= 0 << 1; |
| 309 | break; |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 310 | case ACPI_IRQ_ACTIVE_LOW: |
Duncan Laurie | cfb6ea7 | 2016-05-09 17:08:38 -0700 | [diff] [blame] | 311 | flags |= 1 << 1; |
| 312 | break; |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 313 | case ACPI_IRQ_ACTIVE_BOTH: |
Duncan Laurie | cfb6ea7 | 2016-05-09 17:08:38 -0700 | [diff] [blame] | 314 | flags |= 2 << 1; |
| 315 | break; |
| 316 | } |
| 317 | break; |
| 318 | |
| 319 | case ACPI_GPIO_TYPE_IO: |
| 320 | /* |
| 321 | * Byte 7-8: GPIO IO Flags |
| 322 | * [15:4]: 0 => Reserved |
| 323 | * [3]: Sharing (0=EXCLUSIVE 1=SHARED) |
| 324 | * [2]: 0 => Reserved |
| 325 | * [1:0]: IO Restriction |
| 326 | * 0 => IoRestrictionNone |
| 327 | * 1 => IoRestrictionInputOnly |
| 328 | * 2 => IoRestrictionOutputOnly |
| 329 | * 3 => IoRestrictionNoneAndPreserve |
| 330 | */ |
| 331 | flags |= gpio->io_restrict & 3; |
| 332 | if (gpio->io_shared) |
| 333 | flags |= 1 << 3; |
| 334 | break; |
| 335 | } |
| 336 | acpigen_emit_word(flags); |
| 337 | |
| 338 | /* |
| 339 | * Byte 9: Pin Configuration |
| 340 | * 0x01 => Default (no configuration applied) |
| 341 | * 0x02 => Pull-up |
| 342 | * 0x03 => Pull-down |
| 343 | * 0x04-0x7F => Reserved |
| 344 | * 0x80-0xff => Vendor defined |
| 345 | */ |
| 346 | acpigen_emit_byte(gpio->pull); |
| 347 | |
| 348 | /* Byte 10-11: Output Drive Strength in 1/100 mA */ |
| 349 | acpigen_emit_word(gpio->output_drive_strength); |
| 350 | |
| 351 | /* Byte 12-13: Debounce Timeout in 1/100 ms */ |
| 352 | acpigen_emit_word(gpio->interrupt_debounce_timeout); |
| 353 | |
| 354 | /* Byte 14-15: Pin Table Offset, relative to start */ |
| 355 | pin_table_offset = acpi_device_write_zero_len(); |
| 356 | |
| 357 | /* Byte 16: Reserved */ |
| 358 | acpigen_emit_byte(0); |
| 359 | |
| 360 | /* Byte 17-18: Resource Source Name Offset, relative to start */ |
| 361 | resource_offset = acpi_device_write_zero_len(); |
| 362 | |
| 363 | /* Byte 19-20: Vendor Data Offset, relative to start */ |
| 364 | vendor_data_offset = acpi_device_write_zero_len(); |
| 365 | |
| 366 | /* Byte 21-22: Vendor Data Length */ |
| 367 | acpigen_emit_word(0); |
| 368 | |
| 369 | /* Fill in Pin Table Offset */ |
| 370 | acpi_device_fill_from_len(pin_table_offset, start); |
| 371 | |
| 372 | /* Pin Table, one word for each pin */ |
Duncan Laurie | 5b6c28c | 2016-06-29 10:47:22 -0700 | [diff] [blame] | 373 | for (pin = 0; pin < gpio->pin_count; pin++) { |
| 374 | uint16_t acpi_pin = gpio->pins[pin]; |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 375 | #if CONFIG(GENERIC_GPIO_LIB) |
Duncan Laurie | 5b6c28c | 2016-06-29 10:47:22 -0700 | [diff] [blame] | 376 | acpi_pin = gpio_acpi_pin(acpi_pin); |
| 377 | #endif |
| 378 | acpigen_emit_word(acpi_pin); |
| 379 | } |
Duncan Laurie | cfb6ea7 | 2016-05-09 17:08:38 -0700 | [diff] [blame] | 380 | |
| 381 | /* Fill in Resource Source Name Offset */ |
| 382 | acpi_device_fill_from_len(resource_offset, start); |
| 383 | |
| 384 | /* Resource Source Name String */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 385 | #if CONFIG(GENERIC_GPIO_LIB) |
Duncan Laurie | cfb6ea7 | 2016-05-09 17:08:38 -0700 | [diff] [blame] | 386 | acpigen_emit_string(gpio->resource ? : gpio_acpi_path(gpio->pins[0])); |
| 387 | #else |
| 388 | acpigen_emit_string(gpio->resource); |
| 389 | #endif |
| 390 | |
| 391 | /* Fill in Vendor Data Offset */ |
| 392 | acpi_device_fill_from_len(vendor_data_offset, start); |
| 393 | |
| 394 | /* Fill in GPIO Descriptor Length (account for len word) */ |
| 395 | acpi_device_fill_len(desc_length); |
| 396 | } |
Duncan Laurie | 1010b4a | 2016-05-09 20:10:47 -0700 | [diff] [blame] | 397 | |
| 398 | /* ACPI 6.1 section 6.4.3.8.2.1 - I2cSerialBus() */ |
| 399 | void acpi_device_write_i2c(const struct acpi_i2c *i2c) |
| 400 | { |
| 401 | void *desc_length, *type_length; |
| 402 | |
| 403 | /* Byte 0: Descriptor Type */ |
| 404 | acpigen_emit_byte(ACPI_DESCRIPTOR_SERIAL_BUS); |
| 405 | |
| 406 | /* Byte 1+2: Length (filled in later) */ |
| 407 | desc_length = acpi_device_write_zero_len(); |
| 408 | |
| 409 | /* Byte 3: Revision ID */ |
Elyes HAOUAS | 34564ed | 2019-04-16 08:12:10 +0200 | [diff] [blame] | 410 | acpigen_emit_byte(ACPI_I2C_SERIAL_BUS_REVISION_ID); |
Duncan Laurie | 1010b4a | 2016-05-09 20:10:47 -0700 | [diff] [blame] | 411 | |
| 412 | /* Byte 4: Resource Source Index is Reserved */ |
| 413 | acpigen_emit_byte(0); |
| 414 | |
| 415 | /* Byte 5: Serial Bus Type is I2C */ |
| 416 | acpigen_emit_byte(ACPI_SERIAL_BUS_TYPE_I2C); |
| 417 | |
| 418 | /* |
| 419 | * Byte 6: Flags |
| 420 | * [7:2]: 0 => Reserved |
| 421 | * [1]: 1 => ResourceConsumer |
| 422 | * [0]: 0 => ControllerInitiated |
| 423 | */ |
| 424 | acpigen_emit_byte(1 << 1); |
| 425 | |
| 426 | /* |
| 427 | * Byte 7-8: Type Specific Flags |
| 428 | * [15:1]: 0 => Reserved |
| 429 | * [0]: 0 => 7bit, 1 => 10bit |
| 430 | */ |
| 431 | acpigen_emit_word(i2c->mode_10bit); |
| 432 | |
| 433 | /* Byte 9: Type Specific Revision ID */ |
Elyes HAOUAS | 34564ed | 2019-04-16 08:12:10 +0200 | [diff] [blame] | 434 | acpigen_emit_byte(ACPI_I2C_TYPE_SPECIFIC_REVISION_ID); |
Duncan Laurie | 1010b4a | 2016-05-09 20:10:47 -0700 | [diff] [blame] | 435 | |
| 436 | /* Byte 10-11: I2C Type Data Length */ |
| 437 | type_length = acpi_device_write_zero_len(); |
| 438 | |
| 439 | /* Byte 12-15: I2C Bus Speed */ |
| 440 | acpigen_emit_dword(i2c->speed); |
| 441 | |
| 442 | /* Byte 16-17: I2C Slave Address */ |
| 443 | acpigen_emit_word(i2c->address); |
| 444 | |
| 445 | /* Fill in Type Data Length */ |
| 446 | acpi_device_fill_len(type_length); |
| 447 | |
| 448 | /* Byte 18+: ResourceSource */ |
| 449 | acpigen_emit_string(i2c->resource); |
| 450 | |
| 451 | /* Fill in I2C Descriptor Length */ |
| 452 | acpi_device_fill_len(desc_length); |
| 453 | } |
Duncan Laurie | 70c86d9 | 2016-05-10 07:26:34 -0700 | [diff] [blame] | 454 | |
| 455 | /* ACPI 6.1 section 6.4.3.8.2.2 - SpiSerialBus() */ |
| 456 | void acpi_device_write_spi(const struct acpi_spi *spi) |
| 457 | { |
| 458 | void *desc_length, *type_length; |
| 459 | uint16_t flags = 0; |
| 460 | |
| 461 | /* Byte 0: Descriptor Type */ |
| 462 | acpigen_emit_byte(ACPI_DESCRIPTOR_SERIAL_BUS); |
| 463 | |
| 464 | /* Byte 1+2: Length (filled in later) */ |
| 465 | desc_length = acpi_device_write_zero_len(); |
| 466 | |
| 467 | /* Byte 3: Revision ID */ |
Elyes HAOUAS | 34564ed | 2019-04-16 08:12:10 +0200 | [diff] [blame] | 468 | acpigen_emit_byte(ACPI_SPI_SERIAL_BUS_REVISION_ID); |
Duncan Laurie | 70c86d9 | 2016-05-10 07:26:34 -0700 | [diff] [blame] | 469 | |
| 470 | /* Byte 4: Resource Source Index is Reserved */ |
| 471 | acpigen_emit_byte(0); |
| 472 | |
| 473 | /* Byte 5: Serial Bus Type is SPI */ |
| 474 | acpigen_emit_byte(ACPI_SERIAL_BUS_TYPE_SPI); |
| 475 | |
| 476 | /* |
| 477 | * Byte 6: Flags |
| 478 | * [7:2]: 0 => Reserved |
| 479 | * [1]: 1 => ResourceConsumer |
| 480 | * [0]: 0 => ControllerInitiated |
| 481 | */ |
| 482 | acpigen_emit_byte(1 << 1); |
| 483 | |
| 484 | /* |
| 485 | * Byte 7-8: Type Specific Flags |
| 486 | * [15:2]: 0 => Reserved |
| 487 | * [1]: 0 => ActiveLow, 1 => ActiveHigh |
| 488 | * [0]: 0 => FourWire, 1 => ThreeWire |
| 489 | */ |
| 490 | if (spi->wire_mode == SPI_3_WIRE_MODE) |
| 491 | flags |= 1 << 0; |
| 492 | if (spi->device_select_polarity == SPI_POLARITY_HIGH) |
| 493 | flags |= 1 << 1; |
| 494 | acpigen_emit_word(flags); |
| 495 | |
| 496 | /* Byte 9: Type Specific Revision ID */ |
Elyes HAOUAS | 34564ed | 2019-04-16 08:12:10 +0200 | [diff] [blame] | 497 | acpigen_emit_byte(ACPI_SPI_TYPE_SPECIFIC_REVISION_ID); |
Duncan Laurie | 70c86d9 | 2016-05-10 07:26:34 -0700 | [diff] [blame] | 498 | |
| 499 | /* Byte 10-11: SPI Type Data Length */ |
| 500 | type_length = acpi_device_write_zero_len(); |
| 501 | |
| 502 | /* Byte 12-15: Connection Speed */ |
| 503 | acpigen_emit_dword(spi->speed); |
| 504 | |
| 505 | /* Byte 16: Data Bit Length */ |
| 506 | acpigen_emit_byte(spi->data_bit_length); |
| 507 | |
| 508 | /* Byte 17: Clock Phase */ |
| 509 | acpigen_emit_byte(spi->clock_phase); |
| 510 | |
| 511 | /* Byte 18: Clock Polarity */ |
| 512 | acpigen_emit_byte(spi->clock_polarity); |
| 513 | |
| 514 | /* Byte 19-20: Device Selection */ |
| 515 | acpigen_emit_word(spi->device_select); |
| 516 | |
| 517 | /* Fill in Type Data Length */ |
| 518 | acpi_device_fill_len(type_length); |
| 519 | |
| 520 | /* Byte 21+: ResourceSource String */ |
| 521 | acpigen_emit_string(spi->resource); |
| 522 | |
| 523 | /* Fill in SPI Descriptor Length */ |
| 524 | acpi_device_fill_len(desc_length); |
| 525 | } |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 526 | |
Duncan Laurie | dccef0d | 2020-05-27 12:29:51 -0700 | [diff] [blame] | 527 | /* UART Serial Bus - UARTSerialBusV2() */ |
| 528 | void acpi_device_write_uart(const struct acpi_uart *uart) |
| 529 | { |
| 530 | void *desc_length, *type_length; |
| 531 | uint16_t flags; |
| 532 | |
| 533 | /* Byte 0: Descriptor Type */ |
| 534 | acpigen_emit_byte(ACPI_DESCRIPTOR_SERIAL_BUS); |
| 535 | |
| 536 | /* Byte 1+2: Length (filled in later) */ |
| 537 | desc_length = acpi_device_write_zero_len(); |
| 538 | |
| 539 | /* Byte 3: Revision ID */ |
| 540 | acpigen_emit_byte(ACPI_UART_SERIAL_BUS_REVISION_ID); |
| 541 | |
| 542 | /* Byte 4: Resource Source Index is Reserved */ |
| 543 | acpigen_emit_byte(0); |
| 544 | |
| 545 | /* Byte 5: Serial Bus Type is UART */ |
| 546 | acpigen_emit_byte(ACPI_SERIAL_BUS_TYPE_UART); |
| 547 | |
| 548 | /* |
| 549 | * Byte 6: Flags |
| 550 | * [7:2]: 0 => Reserved |
| 551 | * [1]: 1 => ResourceConsumer |
| 552 | * [0]: 0 => ControllerInitiated |
| 553 | */ |
| 554 | acpigen_emit_byte(BIT(1)); |
| 555 | |
| 556 | /* |
| 557 | * Byte 7-8: Type Specific Flags |
| 558 | * [15:8]: 0 => Reserved |
| 559 | * [7]: 0 => Little Endian, 1 => Big Endian |
| 560 | * [6:4]: Data bits |
| 561 | * [3:2]: Stop bits |
| 562 | * [1:0]: Flow control |
| 563 | */ |
| 564 | flags = uart->flow_control & 3; |
| 565 | flags |= (uart->stop_bits & 3) << 2; |
| 566 | flags |= (uart->data_bits & 7) << 4; |
| 567 | flags |= (uart->endian & 1) << 7; |
| 568 | acpigen_emit_word(flags); |
| 569 | |
| 570 | /* Byte 9: Type Specific Revision ID */ |
| 571 | acpigen_emit_byte(ACPI_UART_TYPE_SPECIFIC_REVISION_ID); |
| 572 | |
| 573 | /* Byte 10-11: Type Data Length */ |
| 574 | type_length = acpi_device_write_zero_len(); |
| 575 | |
| 576 | /* Byte 12-15: Initial Baud Rate */ |
| 577 | acpigen_emit_dword(uart->initial_baud_rate); |
| 578 | |
| 579 | /* Byte 16-17: RX FIFO size */ |
| 580 | acpigen_emit_word(uart->rx_fifo_bytes); |
| 581 | |
| 582 | /* Byte 18-19: TX FIFO size */ |
| 583 | acpigen_emit_word(uart->tx_fifo_bytes); |
| 584 | |
| 585 | /* Byte 20: Parity */ |
| 586 | acpigen_emit_byte(uart->parity); |
| 587 | |
| 588 | /* Byte 21: Lines Enabled */ |
| 589 | acpigen_emit_byte(uart->lines_in_use); |
| 590 | |
| 591 | /* Fill in Type Data Length */ |
| 592 | acpi_device_fill_len(type_length); |
| 593 | |
| 594 | /* Byte 22+: ResourceSource */ |
| 595 | acpigen_emit_string(uart->resource); |
| 596 | |
| 597 | /* Fill in Descriptor Length */ |
| 598 | acpi_device_fill_len(desc_length); |
| 599 | } |
| 600 | |
Raul E Rangel | 6d2bc00 | 2021-05-27 15:04:21 -0600 | [diff] [blame] | 601 | #define ACPI_POWER_RESOURCE_STATUS_ON_OP ONE_OP |
| 602 | #define ACPI_POWER_RESOURCE_STATUS_OFF_OP ZERO_OP |
| 603 | |
| 604 | /** |
| 605 | * Writes an ACPI fragment that will check the GPIO and return 0 if the GPIO |
| 606 | * state does not match the active parameter. |
| 607 | */ |
| 608 | static void acpigen_write_gpio_STA(const struct acpi_gpio *gpio, bool active) |
| 609 | { |
| 610 | if (!gpio || !gpio->pin_count) |
| 611 | return; |
| 612 | |
| 613 | /* Read current GPIO status into Local0. */ |
| 614 | acpigen_get_tx_gpio(gpio); |
| 615 | |
| 616 | /* |
| 617 | * If (!Local0) |
| 618 | * { |
| 619 | * Return (Zero) |
| 620 | * } |
| 621 | */ |
| 622 | acpigen_write_if(); |
| 623 | if (active) |
| 624 | acpigen_emit_byte(LNOT_OP); |
| 625 | acpigen_emit_byte(LOCAL0_OP); |
| 626 | acpigen_write_return_op(ACPI_POWER_RESOURCE_STATUS_OFF_OP); |
| 627 | acpigen_write_if_end(); |
| 628 | } |
| 629 | |
| 630 | static void acpigen_write_power_res_STA(const struct acpi_power_res_params *params) |
| 631 | { |
| 632 | acpigen_write_method_serialized("_STA", 0); |
| 633 | |
| 634 | /* Verify all the GPIOs are in the ON state, otherwise return 0 */ |
| 635 | acpigen_write_gpio_STA(params->enable_gpio, true); |
| 636 | acpigen_write_gpio_STA(params->reset_gpio, false); |
| 637 | acpigen_write_gpio_STA(params->stop_gpio, false); |
| 638 | |
| 639 | /* All GPIOs are in the ON state */ |
| 640 | acpigen_write_return_op(ACPI_POWER_RESOURCE_STATUS_ON_OP); |
| 641 | |
| 642 | acpigen_pop_len(); /* Method */ |
| 643 | } |
| 644 | |
Duncan Laurie | bd73dbb | 2017-02-17 17:05:03 -0800 | [diff] [blame] | 645 | /* PowerResource() with Enable and/or Reset control */ |
Shelley Chen | a060339 | 2018-04-26 13:52:30 -0700 | [diff] [blame] | 646 | void acpi_device_add_power_res(const struct acpi_power_res_params *params) |
Duncan Laurie | bd73dbb | 2017-02-17 17:05:03 -0800 | [diff] [blame] | 647 | { |
Furquan Shaikh | d47946e | 2021-09-14 15:54:41 -0700 | [diff] [blame] | 648 | static uint8_t id; |
Furquan Shaikh | dc78275 | 2020-04-30 22:49:39 -0700 | [diff] [blame] | 649 | static const char * const power_res_dev_states[] = { "_PR0", "_PR3" }; |
Edward O'Callaghan | 7e26255 | 2020-01-23 10:32:33 +1100 | [diff] [blame] | 650 | unsigned int reset_gpio = params->reset_gpio ? params->reset_gpio->pins[0] : 0; |
| 651 | unsigned int enable_gpio = params->enable_gpio ? params->enable_gpio->pins[0] : 0; |
| 652 | unsigned int stop_gpio = params->stop_gpio ? params->stop_gpio->pins[0] : 0; |
Furquan Shaikh | d47946e | 2021-09-14 15:54:41 -0700 | [diff] [blame] | 653 | char pr_name[ACPI_NAME_BUFFER_SIZE]; |
Duncan Laurie | bd73dbb | 2017-02-17 17:05:03 -0800 | [diff] [blame] | 654 | |
Furquan Shaikh | edf459f | 2017-08-28 17:20:49 -0700 | [diff] [blame] | 655 | if (!reset_gpio && !enable_gpio && !stop_gpio) |
Duncan Laurie | bd73dbb | 2017-02-17 17:05:03 -0800 | [diff] [blame] | 656 | return; |
| 657 | |
Furquan Shaikh | d47946e | 2021-09-14 15:54:41 -0700 | [diff] [blame] | 658 | snprintf(pr_name, sizeof(pr_name), "PR%02X", id++); |
| 659 | |
| 660 | /* PowerResource (PR##, 0, 0) */ |
| 661 | acpigen_write_power_res(pr_name, 0, 0, power_res_dev_states, |
Duncan Laurie | bd73dbb | 2017-02-17 17:05:03 -0800 | [diff] [blame] | 662 | ARRAY_SIZE(power_res_dev_states)); |
| 663 | |
Raul E Rangel | 6d2bc00 | 2021-05-27 15:04:21 -0600 | [diff] [blame] | 664 | if (params->use_gpio_for_status) { |
| 665 | acpigen_write_power_res_STA(params); |
| 666 | } else { |
| 667 | /* Method (_STA, 0, NotSerialized) { Return (0x1) } */ |
| 668 | acpigen_write_STA(ACPI_POWER_RESOURCE_STATUS_ON_OP); |
| 669 | } |
Duncan Laurie | bd73dbb | 2017-02-17 17:05:03 -0800 | [diff] [blame] | 670 | |
| 671 | /* Method (_ON, 0, Serialized) */ |
| 672 | acpigen_write_method_serialized("_ON", 0); |
Tim Van Patten | 3d4665c | 2022-04-13 11:53:20 -0600 | [diff] [blame] | 673 | /* Call _STA and early return if the device is already enabled, since the Linux |
| 674 | kernel doesn't check the device status before calling _ON. This avoids |
| 675 | unnecessary delays while booting. */ |
| 676 | if (params->use_gpio_for_status) { |
| 677 | /* Local0 = _STA () */ |
| 678 | acpigen_write_store(); |
| 679 | acpigen_emit_namestring("_STA"); |
| 680 | acpigen_emit_byte(LOCAL0_OP); |
| 681 | /* If (( Local0 == ACPI_POWER_RESOURCE_STATUS_ON_OP)) */ |
| 682 | acpigen_write_if_lequal_op_op(LOCAL0_OP, ACPI_POWER_RESOURCE_STATUS_ON_OP); |
| 683 | acpigen_write_return_op(ZERO_OP); |
| 684 | acpigen_write_if_end(); |
| 685 | } |
Duncan Laurie | bd73dbb | 2017-02-17 17:05:03 -0800 | [diff] [blame] | 686 | if (reset_gpio) |
Shelley Chen | a060339 | 2018-04-26 13:52:30 -0700 | [diff] [blame] | 687 | acpigen_enable_tx_gpio(params->reset_gpio); |
Duncan Laurie | bd73dbb | 2017-02-17 17:05:03 -0800 | [diff] [blame] | 688 | if (enable_gpio) { |
Shelley Chen | a060339 | 2018-04-26 13:52:30 -0700 | [diff] [blame] | 689 | acpigen_enable_tx_gpio(params->enable_gpio); |
| 690 | if (params->enable_delay_ms) |
| 691 | acpigen_write_sleep(params->enable_delay_ms); |
Duncan Laurie | bd73dbb | 2017-02-17 17:05:03 -0800 | [diff] [blame] | 692 | } |
| 693 | if (reset_gpio) { |
Shelley Chen | a060339 | 2018-04-26 13:52:30 -0700 | [diff] [blame] | 694 | acpigen_disable_tx_gpio(params->reset_gpio); |
| 695 | if (params->reset_delay_ms) |
| 696 | acpigen_write_sleep(params->reset_delay_ms); |
Duncan Laurie | bd73dbb | 2017-02-17 17:05:03 -0800 | [diff] [blame] | 697 | } |
Furquan Shaikh | edf459f | 2017-08-28 17:20:49 -0700 | [diff] [blame] | 698 | if (stop_gpio) { |
Shelley Chen | a060339 | 2018-04-26 13:52:30 -0700 | [diff] [blame] | 699 | acpigen_disable_tx_gpio(params->stop_gpio); |
| 700 | if (params->stop_delay_ms) |
| 701 | acpigen_write_sleep(params->stop_delay_ms); |
Furquan Shaikh | edf459f | 2017-08-28 17:20:49 -0700 | [diff] [blame] | 702 | } |
Duncan Laurie | bd73dbb | 2017-02-17 17:05:03 -0800 | [diff] [blame] | 703 | acpigen_pop_len(); /* _ON method */ |
| 704 | |
| 705 | /* Method (_OFF, 0, Serialized) */ |
| 706 | acpigen_write_method_serialized("_OFF", 0); |
Shelley Chen | a060339 | 2018-04-26 13:52:30 -0700 | [diff] [blame] | 707 | if (stop_gpio) { |
| 708 | acpigen_enable_tx_gpio(params->stop_gpio); |
| 709 | if (params->stop_off_delay_ms) |
| 710 | acpigen_write_sleep(params->stop_off_delay_ms); |
| 711 | } |
| 712 | if (reset_gpio) { |
| 713 | acpigen_enable_tx_gpio(params->reset_gpio); |
| 714 | if (params->reset_off_delay_ms) |
| 715 | acpigen_write_sleep(params->reset_off_delay_ms); |
| 716 | } |
| 717 | if (enable_gpio) { |
| 718 | acpigen_disable_tx_gpio(params->enable_gpio); |
| 719 | if (params->enable_off_delay_ms) |
| 720 | acpigen_write_sleep(params->enable_off_delay_ms); |
| 721 | } |
Duncan Laurie | bd73dbb | 2017-02-17 17:05:03 -0800 | [diff] [blame] | 722 | acpigen_pop_len(); /* _OFF method */ |
| 723 | |
Furquan Shaikh | d47946e | 2021-09-14 15:54:41 -0700 | [diff] [blame] | 724 | acpigen_pop_len(); /* PowerResource PR## */ |
Duncan Laurie | bd73dbb | 2017-02-17 17:05:03 -0800 | [diff] [blame] | 725 | } |
| 726 | |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 727 | static void acpi_dp_write_array(const struct acpi_dp *array); |
| 728 | static void acpi_dp_write_value(const struct acpi_dp *prop) |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 729 | { |
| 730 | switch (prop->type) { |
| 731 | case ACPI_DP_TYPE_INTEGER: |
| 732 | acpigen_write_integer(prop->integer); |
| 733 | break; |
| 734 | case ACPI_DP_TYPE_STRING: |
Harsha Priya | 3a96ac4 | 2016-07-15 17:31:43 -0700 | [diff] [blame] | 735 | case ACPI_DP_TYPE_CHILD: |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 736 | acpigen_write_string(prop->string); |
| 737 | break; |
| 738 | case ACPI_DP_TYPE_REFERENCE: |
| 739 | acpigen_emit_namestring(prop->string); |
| 740 | break; |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 741 | case ACPI_DP_TYPE_ARRAY: |
| 742 | acpi_dp_write_array(prop->array); |
| 743 | break; |
| 744 | default: |
| 745 | break; |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 749 | /* Package (2) { "prop->name", VALUE } */ |
| 750 | static void acpi_dp_write_property(const struct acpi_dp *prop) |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 751 | { |
| 752 | acpigen_write_package(2); |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 753 | acpigen_write_string(prop->name); |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 754 | acpi_dp_write_value(prop); |
| 755 | acpigen_pop_len(); |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | /* Write array of Device Properties */ |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 759 | static void acpi_dp_write_array(const struct acpi_dp *array) |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 760 | { |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 761 | const struct acpi_dp *dp; |
| 762 | char *pkg_count; |
| 763 | |
| 764 | /* Package element count determined as it is populated */ |
| 765 | pkg_count = acpigen_write_package(0); |
| 766 | |
Furquan Shaikh | 35c01bc | 2016-10-03 23:30:14 -0700 | [diff] [blame] | 767 | /* |
| 768 | * Only acpi_dp of type DP_TYPE_TABLE is allowed to be an array. |
| 769 | * DP_TYPE_TABLE does not have a value to be written. Thus, start |
| 770 | * the loop from next type in the array. |
| 771 | */ |
| 772 | for (dp = array->next; dp; dp = dp->next) { |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 773 | acpi_dp_write_value(dp); |
| 774 | (*pkg_count)++; |
| 775 | } |
| 776 | |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 777 | acpigen_pop_len(); |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 780 | static void acpi_dp_free(struct acpi_dp *dp) |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 781 | { |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 782 | while (dp) { |
| 783 | struct acpi_dp *p = dp->next; |
| 784 | |
| 785 | switch (dp->type) { |
| 786 | case ACPI_DP_TYPE_CHILD: |
| 787 | acpi_dp_free(dp->child); |
| 788 | break; |
| 789 | case ACPI_DP_TYPE_ARRAY: |
| 790 | acpi_dp_free(dp->array); |
| 791 | break; |
| 792 | default: |
| 793 | break; |
| 794 | } |
| 795 | |
| 796 | free(dp); |
| 797 | dp = p; |
| 798 | } |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Duncan Laurie | 84fac41 | 2020-06-03 12:36:51 -0700 | [diff] [blame] | 801 | static bool acpi_dp_write_properties(struct acpi_dp *prop, const char *uuid) |
| 802 | { |
| 803 | struct acpi_dp *dp; |
| 804 | char *prop_count = NULL; |
| 805 | |
| 806 | /* Print base properties */ |
| 807 | for (dp = prop; dp; dp = dp->next) { |
| 808 | if (dp->type == ACPI_DP_TYPE_TABLE || |
| 809 | dp->type == ACPI_DP_TYPE_CHILD || |
| 810 | dp->type == ACPI_DP_TYPE_PACKAGE) |
| 811 | continue; |
| 812 | |
| 813 | /* |
| 814 | * The UUID and package is only added when |
| 815 | * we come across the first property. This |
| 816 | * is to avoid creating a zero-length package |
| 817 | * in situations where there are only children. |
| 818 | */ |
| 819 | if (!prop_count) { |
| 820 | /* ToUUID (dp->uuid) */ |
| 821 | acpigen_write_uuid(uuid); |
| 822 | /* |
| 823 | * Package (PROP), element count determined as |
| 824 | * it is populated |
| 825 | */ |
| 826 | prop_count = acpigen_write_package(0); |
| 827 | } |
| 828 | (*prop_count)++; |
| 829 | acpi_dp_write_property(dp); |
| 830 | } |
| 831 | if (prop_count) { |
| 832 | /* Package (PROP) length, if a package was written */ |
| 833 | acpigen_pop_len(); |
| 834 | return true; |
| 835 | } |
| 836 | return false; |
| 837 | } |
| 838 | |
Simon Glass | 8bfa51e | 2020-06-29 16:18:37 -0600 | [diff] [blame] | 839 | static void acpi_dp_write_(struct acpi_dp *table) |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 840 | { |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 841 | struct acpi_dp *dp, *prop; |
Duncan Laurie | 84fac41 | 2020-06-03 12:36:51 -0700 | [diff] [blame] | 842 | char *dp_count; |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 843 | int child_count = 0; |
| 844 | |
Duncan Laurie | c1adeb6 | 2020-04-29 00:04:14 -0700 | [diff] [blame] | 845 | if (!table || table->type != ACPI_DP_TYPE_TABLE || !table->next) |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 846 | return; |
| 847 | |
| 848 | /* Name (name) */ |
| 849 | acpigen_write_name(table->name); |
| 850 | |
| 851 | /* Device Property list starts with the next entry */ |
| 852 | prop = table->next; |
| 853 | |
Matt Delco | 0825888 | 2019-01-30 11:16:08 -0800 | [diff] [blame] | 854 | /* Package (DP), default to assuming no properties or children */ |
| 855 | dp_count = acpigen_write_package(0); |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 856 | |
| 857 | /* Print base properties */ |
Duncan Laurie | 84fac41 | 2020-06-03 12:36:51 -0700 | [diff] [blame] | 858 | if (acpi_dp_write_properties(prop, table->uuid)) |
| 859 | *dp_count += 2; |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 860 | |
Duncan Laurie | 84fac41 | 2020-06-03 12:36:51 -0700 | [diff] [blame] | 861 | /* Count child properties */ |
| 862 | for (dp = prop; dp; dp = dp->next) |
| 863 | if (dp->type == ACPI_DP_TYPE_CHILD) |
| 864 | child_count++; |
| 865 | |
| 866 | /* Add child properties to the base table */ |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 867 | if (child_count) { |
Duncan Laurie | 84fac41 | 2020-06-03 12:36:51 -0700 | [diff] [blame] | 868 | /* Update DP package count */ |
Matt Delco | 0825888 | 2019-01-30 11:16:08 -0800 | [diff] [blame] | 869 | *dp_count += 2; |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 870 | /* ToUUID (ACPI_DP_CHILD_UUID) */ |
| 871 | acpigen_write_uuid(ACPI_DP_CHILD_UUID); |
| 872 | |
| 873 | /* Print child pointer properties */ |
| 874 | acpigen_write_package(child_count); |
| 875 | |
| 876 | for (dp = prop; dp; dp = dp->next) |
| 877 | if (dp->type == ACPI_DP_TYPE_CHILD) |
| 878 | acpi_dp_write_property(dp); |
Matt Delco | 0825888 | 2019-01-30 11:16:08 -0800 | [diff] [blame] | 879 | /* Package (CHILD) length */ |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 880 | acpigen_pop_len(); |
| 881 | } |
| 882 | |
Duncan Laurie | 84fac41 | 2020-06-03 12:36:51 -0700 | [diff] [blame] | 883 | /* Write packages of properties with unique UUID */ |
| 884 | for (dp = prop; dp; dp = dp->next) |
| 885 | if (dp->type == ACPI_DP_TYPE_PACKAGE) |
| 886 | if (acpi_dp_write_properties(dp->child, dp->uuid)) |
| 887 | *dp_count += 2; |
| 888 | |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 889 | /* Package (DP) length */ |
| 890 | acpigen_pop_len(); |
| 891 | |
| 892 | /* Recursively parse children into separate tables */ |
| 893 | for (dp = prop; dp; dp = dp->next) |
| 894 | if (dp->type == ACPI_DP_TYPE_CHILD) |
Simon Glass | 8bfa51e | 2020-06-29 16:18:37 -0600 | [diff] [blame] | 895 | acpi_dp_write_(dp->child); |
| 896 | } |
| 897 | |
| 898 | void acpi_dp_write(struct acpi_dp *table) |
| 899 | { |
| 900 | acpi_dp_write_(table); |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 901 | |
| 902 | /* Clean up */ |
| 903 | acpi_dp_free(table); |
| 904 | } |
| 905 | |
| 906 | static struct acpi_dp *acpi_dp_new(struct acpi_dp *dp, enum acpi_dp_type type, |
| 907 | const char *name) |
| 908 | { |
| 909 | struct acpi_dp *new; |
| 910 | |
| 911 | new = malloc(sizeof(struct acpi_dp)); |
| 912 | if (!new) |
| 913 | return NULL; |
| 914 | |
| 915 | memset(new, 0, sizeof(*new)); |
| 916 | new->type = type; |
| 917 | new->name = name; |
Duncan Laurie | 84fac41 | 2020-06-03 12:36:51 -0700 | [diff] [blame] | 918 | new->uuid = ACPI_DP_UUID; |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 919 | |
| 920 | if (dp) { |
| 921 | /* Add to end of property list */ |
| 922 | while (dp->next) |
| 923 | dp = dp->next; |
| 924 | dp->next = new; |
| 925 | } |
| 926 | |
| 927 | return new; |
| 928 | } |
| 929 | |
| 930 | struct acpi_dp *acpi_dp_new_table(const char *name) |
| 931 | { |
| 932 | return acpi_dp_new(NULL, ACPI_DP_TYPE_TABLE, name); |
| 933 | } |
| 934 | |
Duncan Laurie | b3023b6 | 2017-08-29 08:26:50 -0700 | [diff] [blame] | 935 | size_t acpi_dp_add_property_list(struct acpi_dp *dp, |
| 936 | const struct acpi_dp *property_list, |
| 937 | size_t property_count) |
| 938 | { |
| 939 | const struct acpi_dp *prop; |
| 940 | size_t i, properties_added = 0; |
| 941 | |
Jacob Garber | c30e590 | 2019-05-23 14:34:58 -0600 | [diff] [blame] | 942 | if (!dp || !property_list) |
| 943 | return 0; |
| 944 | |
Duncan Laurie | b3023b6 | 2017-08-29 08:26:50 -0700 | [diff] [blame] | 945 | for (i = 0; i < property_count; i++) { |
| 946 | prop = &property_list[i]; |
| 947 | |
| 948 | if (prop->type == ACPI_DP_TYPE_UNKNOWN || !prop->name) |
| 949 | continue; |
| 950 | |
| 951 | switch (prop->type) { |
| 952 | case ACPI_DP_TYPE_INTEGER: |
| 953 | acpi_dp_add_integer(dp, prop->name, prop->integer); |
| 954 | break; |
| 955 | case ACPI_DP_TYPE_STRING: |
| 956 | acpi_dp_add_string(dp, prop->name, prop->string); |
| 957 | break; |
| 958 | case ACPI_DP_TYPE_REFERENCE: |
| 959 | acpi_dp_add_reference(dp, prop->name, prop->string); |
| 960 | break; |
| 961 | case ACPI_DP_TYPE_ARRAY: |
| 962 | acpi_dp_add_array(dp, prop->array); |
| 963 | break; |
| 964 | case ACPI_DP_TYPE_CHILD: |
| 965 | acpi_dp_add_child(dp, prop->name, prop->child); |
| 966 | break; |
| 967 | default: |
| 968 | continue; |
| 969 | } |
| 970 | |
| 971 | ++properties_added; |
| 972 | } |
| 973 | |
| 974 | return properties_added; |
| 975 | } |
| 976 | |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 977 | struct acpi_dp *acpi_dp_add_integer(struct acpi_dp *dp, const char *name, |
| 978 | uint64_t value) |
| 979 | { |
Jacob Garber | c30e590 | 2019-05-23 14:34:58 -0600 | [diff] [blame] | 980 | if (!dp) |
| 981 | return NULL; |
| 982 | |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 983 | struct acpi_dp *new = acpi_dp_new(dp, ACPI_DP_TYPE_INTEGER, name); |
| 984 | |
| 985 | if (new) |
| 986 | new->integer = value; |
| 987 | |
| 988 | return new; |
| 989 | } |
| 990 | |
| 991 | struct acpi_dp *acpi_dp_add_string(struct acpi_dp *dp, const char *name, |
| 992 | const char *string) |
| 993 | { |
Jacob Garber | c30e590 | 2019-05-23 14:34:58 -0600 | [diff] [blame] | 994 | if (!dp) |
| 995 | return NULL; |
| 996 | |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 997 | struct acpi_dp *new = acpi_dp_new(dp, ACPI_DP_TYPE_STRING, name); |
| 998 | |
| 999 | if (new) |
| 1000 | new->string = string; |
| 1001 | |
| 1002 | return new; |
| 1003 | } |
| 1004 | |
| 1005 | struct acpi_dp *acpi_dp_add_reference(struct acpi_dp *dp, const char *name, |
| 1006 | const char *reference) |
| 1007 | { |
Jacob Garber | c30e590 | 2019-05-23 14:34:58 -0600 | [diff] [blame] | 1008 | if (!dp) |
| 1009 | return NULL; |
| 1010 | |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 1011 | struct acpi_dp *new = acpi_dp_new(dp, ACPI_DP_TYPE_REFERENCE, name); |
| 1012 | |
| 1013 | if (new) |
| 1014 | new->string = reference; |
| 1015 | |
| 1016 | return new; |
| 1017 | } |
| 1018 | |
| 1019 | struct acpi_dp *acpi_dp_add_child(struct acpi_dp *dp, const char *name, |
| 1020 | struct acpi_dp *child) |
| 1021 | { |
| 1022 | struct acpi_dp *new; |
| 1023 | |
Jacob Garber | c30e590 | 2019-05-23 14:34:58 -0600 | [diff] [blame] | 1024 | if (!dp || !child || child->type != ACPI_DP_TYPE_TABLE) |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 1025 | return NULL; |
| 1026 | |
| 1027 | new = acpi_dp_new(dp, ACPI_DP_TYPE_CHILD, name); |
| 1028 | if (new) { |
| 1029 | new->child = child; |
| 1030 | new->string = child->name; |
| 1031 | } |
| 1032 | |
| 1033 | return new; |
| 1034 | } |
| 1035 | |
Duncan Laurie | 84fac41 | 2020-06-03 12:36:51 -0700 | [diff] [blame] | 1036 | struct acpi_dp *acpi_dp_add_package(struct acpi_dp *dp, struct acpi_dp *package) |
| 1037 | { |
| 1038 | struct acpi_dp *new; |
| 1039 | |
| 1040 | if (!dp || !package || package->type != ACPI_DP_TYPE_TABLE) |
| 1041 | return NULL; |
| 1042 | |
| 1043 | new = acpi_dp_new(dp, ACPI_DP_TYPE_PACKAGE, NULL); |
| 1044 | if (new) { |
| 1045 | new->uuid = package->name; |
| 1046 | new->child = package; |
| 1047 | } |
| 1048 | |
| 1049 | return new; |
| 1050 | } |
| 1051 | |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 1052 | struct acpi_dp *acpi_dp_add_array(struct acpi_dp *dp, struct acpi_dp *array) |
| 1053 | { |
| 1054 | struct acpi_dp *new; |
| 1055 | |
Jacob Garber | c30e590 | 2019-05-23 14:34:58 -0600 | [diff] [blame] | 1056 | if (!dp || !array || array->type != ACPI_DP_TYPE_TABLE) |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 1057 | return NULL; |
| 1058 | |
| 1059 | new = acpi_dp_new(dp, ACPI_DP_TYPE_ARRAY, array->name); |
| 1060 | if (new) |
| 1061 | new->array = array; |
| 1062 | |
| 1063 | return new; |
| 1064 | } |
| 1065 | |
| 1066 | struct acpi_dp *acpi_dp_add_integer_array(struct acpi_dp *dp, const char *name, |
Duncan Laurie | ed6eb27 | 2020-04-29 11:39:08 -0700 | [diff] [blame] | 1067 | const uint64_t *array, int len) |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 1068 | { |
| 1069 | struct acpi_dp *dp_array; |
| 1070 | int i; |
| 1071 | |
Jacob Garber | c30e590 | 2019-05-23 14:34:58 -0600 | [diff] [blame] | 1072 | if (!dp || len <= 0) |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 1073 | return NULL; |
| 1074 | |
| 1075 | dp_array = acpi_dp_new_table(name); |
| 1076 | if (!dp_array) |
| 1077 | return NULL; |
| 1078 | |
| 1079 | for (i = 0; i < len; i++) |
| 1080 | if (!acpi_dp_add_integer(dp_array, NULL, array[i])) |
| 1081 | break; |
| 1082 | |
| 1083 | acpi_dp_add_array(dp, dp_array); |
| 1084 | |
| 1085 | return dp_array; |
| 1086 | } |
| 1087 | |
Karthikeyan Ramasubramanian | 685dbe1 | 2020-10-05 10:44:50 -0600 | [diff] [blame] | 1088 | struct acpi_dp *acpi_dp_add_gpio_array(struct acpi_dp *dp, const char *name, |
| 1089 | const struct acpi_gpio_res_params *params, |
| 1090 | size_t param_count) |
| 1091 | { |
| 1092 | struct acpi_dp *gpio; |
| 1093 | uint32_t i; |
| 1094 | |
| 1095 | if (!dp || !param_count) |
| 1096 | return NULL; |
| 1097 | |
| 1098 | gpio = acpi_dp_new_table(name); |
| 1099 | if (!gpio) |
| 1100 | return NULL; |
| 1101 | |
| 1102 | /* |
| 1103 | * Generate ACPI identifiers as follows: |
| 1104 | * Package () { |
| 1105 | * name, // e.g. cs-gpios |
| 1106 | * Package() { |
| 1107 | * ref, index, pin, active_low, // GPIO-0 (params[0]) |
| 1108 | * ref, index, pin, active_low, // GPIO-1 (params[1]) |
| 1109 | * ... |
| 1110 | * } |
| 1111 | * } |
| 1112 | */ |
| 1113 | for (i = 0; i < param_count; i++, params++) { |
| 1114 | /* |
| 1115 | * If refs is NULL, leave a hole in the gpio array. This can be used in |
| 1116 | * conditions where some controllers use both GPIOs and native signals. |
| 1117 | */ |
| 1118 | if (!params->ref) { |
| 1119 | acpi_dp_add_integer(gpio, NULL, 0); |
| 1120 | continue; |
| 1121 | } |
| 1122 | |
| 1123 | /* The device that has _CRS containing GpioIO()/GpioInt() */ |
| 1124 | acpi_dp_add_reference(gpio, NULL, params->ref); |
| 1125 | |
| 1126 | /* Index of the GPIO resource in _CRS starting from zero */ |
| 1127 | acpi_dp_add_integer(gpio, NULL, params->index); |
| 1128 | |
| 1129 | /* Pin in the GPIO resource, typically zero */ |
| 1130 | acpi_dp_add_integer(gpio, NULL, params->pin); |
| 1131 | |
| 1132 | /* Set if pin is active low */ |
| 1133 | acpi_dp_add_integer(gpio, NULL, params->active_low); |
| 1134 | } |
| 1135 | acpi_dp_add_array(dp, gpio); |
| 1136 | |
| 1137 | return gpio; |
| 1138 | |
| 1139 | } |
| 1140 | |
| 1141 | |
Duncan Laurie | ffc9990 | 2016-07-02 19:56:06 -0700 | [diff] [blame] | 1142 | struct acpi_dp *acpi_dp_add_gpio(struct acpi_dp *dp, const char *name, |
| 1143 | const char *ref, int index, int pin, |
| 1144 | int active_low) |
| 1145 | { |
Karthikeyan Ramasubramanian | 685dbe1 | 2020-10-05 10:44:50 -0600 | [diff] [blame] | 1146 | struct acpi_gpio_res_params param = { |
| 1147 | .ref = ref, |
| 1148 | .index = index, |
| 1149 | .pin = pin, |
| 1150 | .active_low = active_low, |
| 1151 | }; |
Jacob Garber | c30e590 | 2019-05-23 14:34:58 -0600 | [diff] [blame] | 1152 | |
Karthikeyan Ramasubramanian | 685dbe1 | 2020-10-05 10:44:50 -0600 | [diff] [blame] | 1153 | return acpi_dp_add_gpio_array(dp, name, ¶m, 1); |
Duncan Laurie | 559e947 | 2016-05-10 13:18:17 -0700 | [diff] [blame] | 1154 | } |
Furquan Shaikh | d1130af | 2020-04-23 12:51:42 -0700 | [diff] [blame] | 1155 | |
| 1156 | /* |
| 1157 | * This function writes a PCI device with _ADR object: |
| 1158 | * Example: |
| 1159 | * Scope (\_SB.PCI0) |
| 1160 | * { |
| 1161 | * Device (IGFX) |
| 1162 | * { |
| 1163 | * Name (_ADR, 0x0000000000000000) |
| 1164 | * Method (_STA, 0, NotSerialized) { Return (status) } |
| 1165 | * } |
| 1166 | * } |
| 1167 | */ |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 1168 | void acpi_device_write_pci_dev(const struct device *dev) |
Furquan Shaikh | d1130af | 2020-04-23 12:51:42 -0700 | [diff] [blame] | 1169 | { |
| 1170 | const char *scope = acpi_device_scope(dev); |
| 1171 | const char *name = acpi_device_name(dev); |
| 1172 | |
| 1173 | assert(dev->path.type == DEVICE_PATH_PCI); |
| 1174 | assert(name); |
| 1175 | assert(scope); |
| 1176 | |
| 1177 | acpigen_write_scope(scope); |
| 1178 | acpigen_write_device(name); |
| 1179 | |
| 1180 | acpigen_write_ADR_pci_device(dev); |
| 1181 | acpigen_write_STA(acpi_device_status(dev)); |
| 1182 | |
| 1183 | acpigen_pop_len(); /* Device */ |
| 1184 | acpigen_pop_len(); /* Scope */ |
| 1185 | } |