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